alecpl
2012-01-01 3a992ee8b89433d6d45dc81d9830751d0194d9fe
program/steps/addressbook/func.inc
@@ -56,6 +56,10 @@
  // TODO: define fields for vcards like GEO, KEY
);
$PAGE_SIZE = $RCMAIL->config->get('addressbook_pagesize');
if (!$PAGE_SIZE) {
    $PAGE_SIZE = $RCMAIL->config->get('pagesize', 50);
}
// Addressbook UI
if (!$RCMAIL->action && !$OUTPUT->ajax_call) {
@@ -108,7 +112,7 @@
// instantiate a contacts object according to the given source
function rcmail_contact_source($source=null, $init_env=false, $writable=false)
{
    global $RCMAIL, $OUTPUT, $CONFIG, $CONTACT_COLTYPES;
    global $RCMAIL, $OUTPUT, $CONTACT_COLTYPES, $PAGE_SIZE;
    if (!strlen($source)) {
        $source = get_input_value('_source', RCUBE_INPUT_GPC);
@@ -116,7 +120,7 @@
    // Get object
    $CONTACTS = $RCMAIL->get_address_book($source, $writable);
    $CONTACTS->set_pagesize($CONFIG['pagesize']);
    $CONTACTS->set_pagesize($PAGE_SIZE);
    // set list properties and session vars
    if (!empty($_GET['_page']))
@@ -140,8 +144,13 @@
        $CONTACT_COLTYPES = array_intersect_key($CONTACT_COLTYPES, $contact_cols);
        // add associative coltypes definition
        if (!$CONTACTS->coltypes[0]) {
            foreach ($CONTACTS->coltypes as $col => $colprop)
            foreach ($CONTACTS->coltypes as $col => $colprop) {
                if (is_array($colprop['childs'])) {
                    foreach ($colprop['childs'] as $childcol => $childprop)
                        $colprop['childs'][$childcol] = array_merge((array)$CONTACT_COLTYPES[$col]['childs'][$childcol], $childprop);
                }
                $CONTACT_COLTYPES[$col] = $CONTACT_COLTYPES[$col] ? array_merge($CONTACT_COLTYPES[$col], $colprop) : $colprop;
            }
        }
    }
@@ -377,13 +386,16 @@
    $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
    if ($attrib['label'])
      $_SESSION['contactcountdisplay'] = $attrib['label'];
    return html::span($attrib, rcube_label('loading'));
}
function rcmail_get_rowcount_text($result=null)
{
    global $CONTACTS, $CONFIG;
    global $CONTACTS, $PAGE_SIZE;
    // read nr of contacts
    if (!$result) {
@@ -394,10 +406,10 @@
        $out = rcube_label('nocontactsfound');
    else
        $out = rcube_label(array(
            'name'  => 'contactsfromto',
            'name'  => $_SESSION['contactcountdisplay'] ? $_SESSION['contactcountdisplay'] : 'contactsfromto',
            'vars'  => array(
            'from'  => $result->first + 1,
            'to'    => min($result->count, $result->first + $CONFIG['pagesize']),
            'to'    => min($result->count, $result->first + $PAGE_SIZE),
            'count' => $result->count)
        ));
@@ -422,7 +434,6 @@
function rcmail_contact_form($form, $record, $attrib = null)
{
    global $RCMAIL, $CONFIG;
    static $jqueryui_loaded = 0;
    // Allow plugins to modify contact form content
    $plugin = $RCMAIL->plugins->exec_hook('contact_form', array(
@@ -597,7 +608,7 @@
                        $coltypes[$field] += (array)$colprop;
                        $coltypes[$field]['count']++;
                        $val = strtr($template, $composite);
                        $val = preg_replace('/\{\w+\}/', '', strtr($template, $composite));
                    }
                    else if ($edit_mode) {
                        // call callback to render/format value
@@ -611,15 +622,8 @@
                        // load jquery UI datepickert for date fields
                        if ($colprop['type'] == 'date') {
                            if (!$jqueryui_loaded++) {
                                $RCMAIL->plugins->load_plugin('jqueryui');
                                $RCMAIL->output->set_env('date_format', strtr($RCMAIL->config->get('date_format', 'Y-m-d'), array('y'=>'y', 'Y'=>'yy', 'm'=>'mm', 'n'=>'m', 'd'=>'dd', 'j'=>'d')));
                                foreach (array('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec') as $month)
                                    $month_names[] = rcube_label($month);
                                $RCMAIL->output->set_env('month_names', $month_names);
                            }
                            $colprop['class'] .= ($colprop['class'] ? ' ' : '') . 'datepicker';
                            $val = format_date($val, $RCMAIL->config->get('date_format', 'Y-m-d'));
                            $val = rcmail_format_date_col($val);
                        }
                        $val = rcmail_get_edit_field($col, $val, $colprop, $colprop['type']);
@@ -657,10 +661,15 @@
                }
                // wrap rows in fieldgroup container
                $content .= html::tag('fieldset', array('class' => 'contactfieldgroup ' . ($colprop['subtypes'] ? 'contactfieldgroupmulti ' : '') . 'contactcontroller' . $col, 'style' => ($rows ? null : 'display:none')),
                  ($colprop['subtypes'] ? html::tag('legend', null, Q($colprop['label'])) : ' ') .
                  $rows);
                if ($rows) {
                    $content .= html::tag('fieldset', array('class' => 'contactfieldgroup ' . ($colprop['subtypes'] ? 'contactfieldgroupmulti ' : '') . 'contactcontroller' . $col, 'style' => ($rows ? null : 'display:none')),
                      ($colprop['subtypes'] ? html::tag('legend', null, Q($colprop['label'])) : ' ') .
                      $rows);
                }
            }
            if (!$content)
                continue;
            // also render add-field selector
            if ($edit_mode)
@@ -672,7 +681,8 @@
            $content = $fieldset['content'];
        }
        $out .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $content) ."\n";
        if ($content)
            $out .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $content) ."\n";
    }
    if ($edit_mode) {
@@ -689,9 +699,6 @@
{
    global $SOURCE_ID, $CONTACTS, $CONTACT_COLTYPES, $RCMAIL, $CONFIG;
    if (!$CONTACT_COLTYPES['photo'])
        return '';
    if ($result = $CONTACTS->get_result())
        $record = $result->first();
@@ -699,7 +706,7 @@
    $RCMAIL->output->set_env('photo_placeholder', $photo_img);
    unset($attrib['placeholder']);
    if (strpos($record['photo'], 'http:') === 0)
    if (preg_match('!^https?://!i', $record['photo']))
        $photo_img = $record['photo'];
    else if ($record['photo'])
        $photo_img = $RCMAIL->url(array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $SOURCE_ID));
@@ -709,7 +716,7 @@
    $img = html::img(array('src' => $photo_img, 'border' => 1, 'alt' => ''));
    $content = html::div($attrib, $img);
    if ($RCMAIL->action == 'edit' || $RCMAIL->action == 'add') {
    if ($CONTACT_COLTYPES['photo'] && ($RCMAIL->action == 'edit' || $RCMAIL->action == 'add')) {
        $RCMAIL->output->add_gui_object('contactphoto', $attrib['id']);
        $hidden = new html_hiddenfield(array('name' => '_photo', 'id' => 'ff_photo', 'value' => $ff_value));
        $content .= $hidden->show();
@@ -722,7 +729,7 @@
function rcmail_format_date_col($val)
{
    global $RCMAIL;
    return format_date($val, $RCMAIL->config->get('date_format', 'Y-m-d'));
    return format_date($val, $RCMAIL->config->get('date_format', 'Y-m-d'), false);
}
@@ -752,9 +759,12 @@
    foreach ($cid as $id) {
        // if _source is not specified we'll find it from decoded ID
        if (!$got_source) {
            list ($c, $s) = explode('-', $id, 2);
            if (strlen($s)) {
                $result[(string)$s][] = $c;
            if ($sep = strrpos($id, '-')) {
                $contact_id = substr($id, 0, $sep);
                $source_id  = substr($id, $sep+1);
                if (strlen($source_id)) {
                    $result[(string)$source_id][] = $contact_id;
                }
            }
        }
        else {