Changeset 4151 in subversion


Ignore:
Timestamp:
Oct 28, 2010 3:10:11 AM (3 years ago)
Author:
alec
Message:
  • Plugin API: added 'contact_form' hook
  • Re-designed contact frame using Tabs
Location:
trunk/roundcubemail
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r4142 r4151  
    5353- Don't list subscribed but non-existent folders (#1486225) 
    5454- Fix handling of URLs with tilde (~) or semicolon (;) character (#1487087, #1487088) 
     55- Plugin API: added 'contact_form' hook 
    5556 
    5657RELEASE 0.4.2 
  • trunk/roundcubemail/program/steps/addressbook/edit.inc

    r3989 r4151  
    2222 
    2323if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true))) 
    24   $OUTPUT->set_env('cid', $record['ID']); 
     24    $OUTPUT->set_env('cid', $record['ID']); 
    2525 
    2626// adding not allowed here 
    27 if ($CONTACTS->readonly) 
    28 { 
    29   $OUTPUT->show_message('sourceisreadonly'); 
    30   rcmail_overwrite_action('show'); 
    31   return; 
     27if ($CONTACTS->readonly) { 
     28    $OUTPUT->show_message('sourceisreadonly'); 
     29    rcmail_overwrite_action('show'); 
     30    return; 
    3231} 
     32 
    3333 
    3434function rcmail_contact_editform($attrib) 
    3535{ 
    36   global $RCMAIL, $CONTACTS, $OUTPUT; 
     36   global $RCMAIL, $CONTACTS, $OUTPUT; 
    3737 
    38   // check if we have a valid result 
    39   if ($RCMAIL->action != 'add' && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))) 
    40   { 
    41     $OUTPUT->show_message('contactnotfound'); 
    42     return false; 
    43   } 
     38    // check if we have a valid result 
     39    if ($RCMAIL->action != 'add' 
     40        && !(($result = $CONTACTS->get_result()) && ($record = $result->first())) 
     41    ) { 
     42        $OUTPUT->show_message('contactnotfound'); 
     43        return false; 
     44    } 
    4445 
    45   // add some labels to client 
    46   $OUTPUT->add_label('noemailwarning', 'nonamewarning'); 
     46    // add some labels to client 
     47    $OUTPUT->add_label('noemailwarning', 'nonamewarning'); 
    4748 
    48   list($form_start, $form_end) = get_form_tags($attrib); 
    49   unset($attrib['form']); 
     49    $i_size = !empty($attrib['size']) ? $attrib['size'] : 40; 
     50    $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 6; 
     51    $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40; 
    5052 
    51   // a specific part is requested 
    52   if ($attrib['part']) 
    53   { 
    54     $out = $form_start; 
    55     $out .= rcmail_get_edit_field($attrib['part'], $record[$attrib['part']], $attrib);  
    56     return $out; 
    57   } 
     53    $form = array( 
     54        'info' => array( 
     55            'name'    => rcube_label('contactproperties'), 
     56            'content' => array( 
     57                'name' => array('type' => 'text', 'size' => $i_size), 
     58                'firstname' => array('type' => 'text', 'size' => $i_size), 
     59                'surname' => array('type' => 'text', 'size' => $i_size), 
     60                'email' => array('type' => 'text', 'size' => $i_size), 
     61            ), 
     62        ), 
     63    ); 
    5864 
    5965 
    60   // return the complete address edit form as table 
    61   $out = "$form_start<table>\n\n"; 
     66    list($form_start, $form_end) = get_form_tags($attrib); 
     67    unset($attrib['form']); 
    6268 
    63   $a_show_cols = array('name', 'firstname', 'surname', 'email'); 
    64   foreach ($a_show_cols as $col) 
    65   { 
    66     $attrib['id'] = 'rcmfd_'.$col; 
    67     $value = rcmail_get_edit_field($col, $record[$col], $attrib); 
    68     $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n", 
    69                     $attrib['id'], 
    70                     Q(rcube_label($col)), 
    71                     $value); 
    72   } 
     69    // return the complete address edit form as table 
     70    $out = rcmail_contact_form($form, $record); 
    7371 
    74   $out .= "\n</table>$form_end"; 
    75  
    76   return $out;   
     72    return $form_start . $out . $form_end; 
    7773} 
    78  
    79 $OUTPUT->add_handler('contacteditform', 'rcmail_contact_editform'); 
    8074 
    8175 
     
    8377function get_form_tags($attrib) 
    8478{ 
    85   global $CONTACTS, $EDIT_FORM, $RCMAIL; 
     79    global $CONTACTS, $EDIT_FORM, $RCMAIL; 
    8680 
    87   $form_start = $form_end = ''; 
     81    $form_start = $form_end = ''; 
    8882   
    89   if (empty($EDIT_FORM)) { 
    90     $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC))); 
    91     $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id)); 
     83    if (empty($EDIT_FORM)) { 
     84        $hiddenfields = new html_hiddenfield(array( 
     85            'name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC))); 
     86        $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id)); 
    9287     
    93     if (($result = $CONTACTS->get_result()) && ($record = $result->first())) 
    94       $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID'])); 
     88        if (($result = $CONTACTS->get_result()) && ($record = $result->first())) 
     89            $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID'])); 
    9590     
    96     $form_start = $RCMAIL->output->request_form(array('name' => "form", 'method' => "post", 'task' => $RCMAIL->task, 'action' => 'save', 'request' => 'save.'.intval($record['ID']), 'noclose' => true) + $attrib, $hiddenfields->show()); 
    97     $form_end = !strlen($attrib['form']) ? '</form>' : ''; 
     91        $form_start = $RCMAIL->output->request_form(array( 
     92            'name' => "form", 'method' => "post", 
     93            'task' => $RCMAIL->task, 'action' => 'save', 
     94            'request' => 'save.'.intval($record['ID']), 
     95            'noclose' => true) + $attrib, $hiddenfields->show()); 
     96        $form_end = !strlen($attrib['form']) ? '</form>' : ''; 
    9897 
    99     $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form'; 
    100     $RCMAIL->output->add_gui_object('editform', $EDIT_FORM); 
    101   } 
     98        $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form'; 
     99        $RCMAIL->output->add_gui_object('editform', $EDIT_FORM); 
     100    } 
    102101 
    103   return array($form_start, $form_end);  
     102    return array($form_start, $form_end);  
    104103} 
    105104 
    106105 
     106$OUTPUT->add_handler('contacteditform', 'rcmail_contact_editform'); 
    107107 
    108108if (!$CONTACTS->get_result() && $OUTPUT->template_exists('addcontact')) 
    109   $OUTPUT->send('addcontact'); 
     109    $OUTPUT->send('addcontact'); 
    110110 
    111111// this will be executed if no template for addcontact exists 
    112112$OUTPUT->send('editcontact'); 
    113  
  • trunk/roundcubemail/program/steps/addressbook/func.inc

    r3989 r4151  
    2828// if source is not set use first directory 
    2929if (empty($source)) 
    30   $source = $js_list[key($js_list)]['id']; 
     30    $source = $js_list[key($js_list)]['id']; 
    3131 
    3232// instantiate a contacts object according to the given source 
     
    3737// set list properties and session vars 
    3838if (!empty($_GET['_page'])) 
    39   $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page']))); 
     39    $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page']))); 
    4040else 
    41   $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1); 
     41    $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1); 
    4242   
    4343if (!empty($_REQUEST['_gid'])) 
    44   $CONTACTS->set_group(get_input_value('_gid', RCUBE_INPUT_GPC)); 
     44    $CONTACTS->set_group(get_input_value('_gid', RCUBE_INPUT_GPC)); 
    4545 
    4646// set message set for search result 
    4747if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']])) 
    48   $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]); 
     48    $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]); 
    4949 
    5050// set data source env 
    5151$OUTPUT->set_env('source', $source ? $source : '0'); 
    5252$OUTPUT->set_env('readonly', $CONTACTS->readonly, false); 
    53 if(! $OUTPUT->ajax_call) { 
    54   $OUTPUT->set_env('address_sources', $js_list); 
    55   $OUTPUT->set_pagetitle(rcube_label('addressbook')); 
    56 } 
     53if (!$OUTPUT->ajax_call) { 
     54    $OUTPUT->set_env('address_sources', $js_list); 
     55    $OUTPUT->set_pagetitle(rcube_label('addressbook')); 
     56} 
     57 
    5758 
    5859function rcmail_directory_list($attrib) 
    5960{ 
    60   global $RCMAIL, $OUTPUT; 
    61    
    62   if (!$attrib['id']) 
    63     $attrib['id'] = 'rcmdirectorylist'; 
    64  
    65   $out = ''; 
    66   $local_id = '0'; 
    67   $jsdata = array(); 
    68   $current = get_input_value('_source', RCUBE_INPUT_GPC); 
    69   $line_templ = html::tag('li', array('id' => 'rcmli%s', 'class' => 'addressbook %s'), 
    70     html::a(array('href' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s')); 
    71  
    72   if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') { 
    73     $current = '0'; 
    74   } 
    75   else if (!$current) { 
    76     // DB address book not used, see if a source is set, if not use the 
    77     // first LDAP directory. 
    78     $current = key((array)$RCMAIL->config->get('ldap_public', array())); 
    79   } 
    80  
    81   foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) { 
    82     $id = $source['id'] ? $source['id'] : $j; 
    83     $js_id = JQ($id); 
    84     $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id); 
    85     $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''), 
    86       Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id))); 
    87     $groupdata = rcmail_contact_groups(array('out' => $out, 'jsdata' => $jsdata, 'source' => $id)); 
    88     $jsdata = $groupdata['jsdata']; 
    89     $out = $groupdata['out']; 
    90   } 
    91  
    92   $OUTPUT->set_env('contactgroups', $jsdata);  
    93   $OUTPUT->add_gui_object('folderlist', $attrib['id']); 
    94    
    95   return html::tag('ul', $attrib, $out, html::$common_attrib); 
     61    global $RCMAIL, $OUTPUT; 
     62 
     63    if (!$attrib['id']) 
     64        $attrib['id'] = 'rcmdirectorylist'; 
     65 
     66    $out = ''; 
     67    $local_id = '0'; 
     68    $jsdata = array(); 
     69    $current = get_input_value('_source', RCUBE_INPUT_GPC); 
     70    $line_templ = html::tag('li', array( 
     71        'id' => 'rcmli%s', 'class' => 'addressbook %s'), 
     72        html::a(array('href' => '%s', 
     73            'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s')); 
     74 
     75    if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') { 
     76        $current = '0'; 
     77    } 
     78    else if (!$current) { 
     79        // DB address book not used, see if a source is set, if not use the 
     80        // first LDAP directory. 
     81        $current = key((array)$RCMAIL->config->get('ldap_public', array())); 
     82    } 
     83 
     84    foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) { 
     85        $id = $source['id'] ? $source['id'] : $j; 
     86        $js_id = JQ($id); 
     87        $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id); 
     88        $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''), 
     89            Q(rcmail_url(null, array('_source' => $id))), 
     90            $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id))); 
     91        $groupdata = rcmail_contact_groups(array('out' => $out, 'jsdata' => $jsdata, 'source' => $id)); 
     92        $jsdata = $groupdata['jsdata']; 
     93        $out = $groupdata['out']; 
     94    } 
     95 
     96    $OUTPUT->set_env('contactgroups', $jsdata);  
     97    $OUTPUT->add_gui_object('folderlist', $attrib['id']); 
     98 
     99    return html::tag('ul', $attrib, $out, html::$common_attrib); 
    96100} 
    97101 
     
    99103function rcmail_contact_groups($args) 
    100104{ 
    101   global $RCMAIL; 
    102  
    103   $groups = $RCMAIL->get_address_book($args['source'])->list_groups(); 
    104  
    105   if (!empty($groups)) { 
    106     $line_templ = html::tag('li', array('id' => 'rcmliG%s%s', 'class' => 'contactgroup'), 
    107       html::a(array('href' => '#', 'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s')); 
    108  
    109     $jsdata = array(); 
    110     foreach ($groups as $group) { 
    111       $args['out'] .= sprintf($line_templ, $args['source'], $group['ID'], $args['source'], $group['ID'], Q($group['name'])); 
    112       $args['jsdata']['G'.$args['source'].$group['ID']] = array( 
    113         'source' => $args['source'], 'id' => $group['ID'], 'name' => $group['name'], 'type' => 'group'); 
    114     } 
    115   } 
    116  
    117   return $args; 
     105    global $RCMAIL; 
     106 
     107    $groups = $RCMAIL->get_address_book($args['source'])->list_groups(); 
     108 
     109    if (!empty($groups)) { 
     110        $line_templ = html::tag('li', array( 
     111            'id' => 'rcmliG%s%s', 'class' => 'contactgroup'), 
     112            html::a(array('href' => '#', 
     113                'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s')); 
     114 
     115        $jsdata = array(); 
     116        foreach ($groups as $group) { 
     117            $args['out'] .= sprintf($line_templ, $args['source'], $group['ID'], $args['source'], $group['ID'], Q($group['name'])); 
     118            $args['jsdata']['G'.$args['source'].$group['ID']] = array( 
     119                'source' => $args['source'], 'id' => $group['ID'], 
     120                'name' => $group['name'], 'type' => 'group'); 
     121        } 
     122    } 
     123 
     124    return $args; 
    118125} 
    119126 
     
    121128// return the message list as HTML table 
    122129function rcmail_contacts_list($attrib) 
    123   { 
    124   global $CONTACTS, $OUTPUT; 
    125    
    126   // count contacts for this user 
    127   $result = $CONTACTS->list_records(); 
    128    
    129   // add id to message list table if not specified 
    130   if (!strlen($attrib['id'])) 
    131     $attrib['id'] = 'rcmAddressList'; 
    132    
    133   // define list of cols to be displayed 
    134   $a_show_cols = array('name'); 
    135  
    136   // create XHTML table 
    137   $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key); 
    138    
    139   // set client env 
    140   $OUTPUT->add_gui_object('contactslist', $attrib['id']); 
    141   $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page); 
    142   $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size)); 
    143   $OUTPUT->include_script('list.js'); 
    144    
    145   // add some labels to client 
    146   $OUTPUT->add_label('deletecontactconfirm'); 
    147    
    148   return $out; 
    149   } 
     130{ 
     131    global $CONTACTS, $OUTPUT; 
     132 
     133    // count contacts for this user 
     134    $result = $CONTACTS->list_records(); 
     135 
     136    // add id to message list table if not specified 
     137    if (!strlen($attrib['id'])) 
     138        $attrib['id'] = 'rcmAddressList'; 
     139 
     140    // define list of cols to be displayed 
     141    $a_show_cols = array('name'); 
     142 
     143    // create XHTML table 
     144    $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key); 
     145 
     146    // set client env 
     147    $OUTPUT->add_gui_object('contactslist', $attrib['id']); 
     148    $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page); 
     149    $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size)); 
     150    $OUTPUT->include_script('list.js'); 
     151 
     152    // add some labels to client 
     153    $OUTPUT->add_label('deletecontactconfirm'); 
     154 
     155    return $out; 
     156} 
    150157 
    151158 
    152159function rcmail_js_contacts_list($result, $prefix='') 
    153   { 
    154   global $OUTPUT; 
    155  
    156   if (empty($result) || $result->count == 0) 
    157     return; 
    158  
    159   // define list of cols to be displayed 
    160   $a_show_cols = array('name'); 
    161    
    162   while ($row = $result->next()) 
    163     { 
    164     $a_row_cols = array(); 
     160{ 
     161    global $OUTPUT; 
     162 
     163    if (empty($result) || $result->count == 0) 
     164        return; 
     165 
     166    // define list of cols to be displayed 
     167    $a_show_cols = array('name'); 
     168   
     169    while ($row = $result->next()) { 
     170        $a_row_cols = array(); 
    165171     
    166     // format each col 
    167     foreach ($a_show_cols as $col) 
    168       $a_row_cols[$col] = Q($row[$col]); 
    169      
    170     $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols); 
    171     } 
    172   } 
     172        // format each col 
     173        foreach ($a_show_cols as $col) 
     174            $a_row_cols[$col] = Q($row[$col]); 
     175 
     176        $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols); 
     177    } 
     178} 
    173179 
    174180 
    175181// similar function as /steps/settings/identities.inc::rcmail_identity_frame() 
    176182function rcmail_contact_frame($attrib) 
    177   { 
    178   global $OUTPUT; 
    179  
    180   if (!$attrib['id']) 
    181     $attrib['id'] = 'rcmcontactframe'; 
     183{ 
     184    global $OUTPUT; 
     185 
     186    if (!$attrib['id']) 
     187        $attrib['id'] = 'rcmcontactframe'; 
    182188     
    183   $attrib['name'] = $attrib['id']; 
    184  
    185   $OUTPUT->set_env('contentframe', $attrib['name']); 
    186   $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif'); 
    187  
    188   return html::iframe($attrib); 
    189   } 
     189    $attrib['name'] = $attrib['id']; 
     190 
     191    $OUTPUT->set_env('contentframe', $attrib['name']); 
     192    $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif'); 
     193 
     194    return html::iframe($attrib); 
     195} 
    190196 
    191197 
    192198function rcmail_rowcount_display($attrib) 
    193   { 
    194   global $OUTPUT; 
    195    
    196   if (!$attrib['id']) 
    197     $attrib['id'] = 'rcmcountdisplay'; 
    198  
    199   $OUTPUT->add_gui_object('countdisplay', $attrib['id']); 
    200  
    201   return html::span($attrib, rcmail_get_rowcount_text()); 
    202   } 
    203  
     199{ 
     200    global $OUTPUT; 
     201 
     202    if (!$attrib['id']) 
     203        $attrib['id'] = 'rcmcountdisplay'; 
     204 
     205    $OUTPUT->add_gui_object('countdisplay', $attrib['id']); 
     206 
     207    return html::span($attrib, rcmail_get_rowcount_text()); 
     208} 
    204209 
    205210 
    206211function rcmail_get_rowcount_text() 
    207   { 
    208   global $CONTACTS; 
    209    
    210   // read nr of contacts 
    211   $result = $CONTACTS->get_result(); 
    212   if (!$result) 
    213     $result = $CONTACTS->count(); 
    214    
    215   if ($result->count == 0) 
    216     $out = rcube_label('nocontactsfound'); 
    217   else 
    218     $out = rcube_label(array( 
    219       'name' => 'contactsfromto', 
    220       'vars' => array( 
    221         'from'  => $result->first + 1, 
    222         'to'    => min($result->count, $result->first + $CONTACTS->page_size), 
    223         'count' => $result->count) 
    224       )); 
    225  
    226   return $out; 
    227   } 
    228    
     212{ 
     213    global $CONTACTS; 
     214   
     215    // read nr of contacts 
     216    $result = $CONTACTS->get_result(); 
     217    if (!$result) { 
     218        $result = $CONTACTS->count(); 
     219    } 
     220 
     221    if ($result->count == 0) 
     222        $out = rcube_label('nocontactsfound'); 
     223    else 
     224        $out = rcube_label(array( 
     225            'name'  => 'contactsfromto', 
     226            'vars'  => array( 
     227            'from'  => $result->first + 1, 
     228            'to'    => min($result->count, $result->first + $CONTACTS->page_size), 
     229            'count' => $result->count) 
     230        )); 
     231 
     232    return $out; 
     233} 
     234 
     235 
     236function rcmail_contact_form($form, $record) 
     237{ 
     238    global $RCMAIL; 
     239 
     240    // Allow plugins to modify contact form content 
     241    $plugin = $RCMAIL->plugins->exec_hook('contact_form', array( 
     242        'form' => $form, 'record' => $record)); 
     243 
     244    $form = $plugin['form']; 
     245    $record = $plugin['record']; 
     246    $out = ''; 
     247 
     248    foreach ($form as $fieldset) { 
     249        if (empty($fieldset['content'])) 
     250            continue; 
     251 
     252        $content = ''; 
     253        if (is_array($fieldset['content'])) { 
     254            $table = new html_table(array('cols' => 2)); 
     255 
     256            foreach ($fieldset['content'] as $col => $colprop) { 
     257                $colprop['id'] = 'rcmfd_'.$col; 
     258 
     259                $label = !empty($colprop['label']) ? $colprop['label'] : rcube_label($col); 
     260 
     261                if (!empty($colprop['value'])) { 
     262                    $value = $colprop['value']; 
     263                } 
     264                else if ($RCMAIL->action == 'show') { 
     265                    $value = $record[$col]; 
     266                } 
     267                else { 
     268                    $value = rcmail_get_edit_field($col, $record[$col], $colprop, $colprop['type']); 
     269                } 
     270 
     271                $table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label))); 
     272                $table->add(null, $value); 
     273            } 
     274            $content = $table->show(); 
     275        } 
     276        else { 
     277            $content = $fieldset['content']; 
     278        } 
     279 
     280        $out .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $content) ."\n"; 
     281    } 
     282   
     283    return $out; 
     284} 
     285 
     286 
    229287// register UI objects 
    230288$OUTPUT->add_handlers(array( 
    231   'directorylist' => 'rcmail_directory_list', 
     289    'directorylist' => 'rcmail_directory_list', 
    232290//  'groupslist' => 'rcmail_contact_groups', 
    233   'addresslist' => 'rcmail_contacts_list', 
    234   'addressframe' => 'rcmail_contact_frame', 
    235   'recordscountdisplay' => 'rcmail_rowcount_display', 
    236   'searchform' => array($OUTPUT, 'search_form') 
     291    'addresslist' => 'rcmail_contacts_list', 
     292    'addressframe' => 'rcmail_contact_frame', 
     293    'recordscountdisplay' => 'rcmail_rowcount_display', 
     294    'searchform' => array($OUTPUT, 'search_form') 
    237295)); 
    238  
  • trunk/roundcubemail/program/steps/addressbook/show.inc

    r4121 r4151  
    2323// read contact record 
    2424if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true))) { 
    25   $OUTPUT->set_env('cid', $record['ID']); 
     25    $OUTPUT->set_env('cid', $record['ID']); 
    2626} 
    27  
    28 $GROUPS = $CONTACTS->list_groups(); 
    29 $OUTPUT->set_env('groups', !empty($GROUPS)); 
    3027 
    3128 
    3229function rcmail_contact_details($attrib) 
    3330{ 
    34   global $CONTACTS, $OUTPUT; 
     31    global $CONTACTS, $RCMAIL; 
    3532 
    36   // check if we have a valid result 
    37   if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) { 
    38     $OUTPUT->show_message('contactnotfound'); 
    39     return false; 
    40   } 
    41    
    42   // a specific part is requested 
    43   if ($attrib['part']) { 
    44     return Q($record[$attrib['part']]); 
    45   } 
     33    // check if we have a valid result 
     34    if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) { 
     35        $RCMAIL->output->show_message('contactnotfound'); 
     36        return false; 
     37    } 
    4638 
    47   // return the complete address record as table 
    48   $table = new html_table(array('cols' => 2)); 
     39    $i_size = !empty($attrib['size']) ? $attrib['size'] : 40; 
     40    $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 6; 
     41    $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40; 
    4942 
    50   $a_show_cols = array('name', 'firstname', 'surname', 'email'); 
    51   $microformats = array('name' => 'fn', 'email' => 'email'); 
     43    $microformats = array('name' => 'fn', 'email' => 'email'); 
    5244 
    53   foreach ($a_show_cols as $col) { 
    54     if ($col == 'email' && !empty($record[$col])) { 
    55       $value = html::a(array( 
    56         'href' => 'mailto:' . $record[$col], 
    57         'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($record[$col])), 
    58         'title' => rcube_label('composeto'), 
    59         'class' => $microformats[$col], 
    60       ), Q($record[$col])); 
     45    $form = array( 
     46        'info' => array( 
     47            'name'    => rcube_label('contactproperties'), 
     48            'content' => array( 
     49                'name' => array('type' => 'text', 'size' => $i_size), 
     50                'firstname' => array('type' => 'text', 'size' => $i_size), 
     51                'surname' => array('type' => 'text', 'size' => $i_size), 
     52                'email' => array('type' => 'text', 'size' => $i_size), 
     53            ), 
     54        ), 
     55        'groups' => array( 
     56            'name'    => rcube_label('groups'), 
     57            'content' => '', 
     58        ), 
     59    ); 
     60 
     61    // Get content of groups fieldset 
     62    if ($groups = rcmail_contact_record_groups($record['ID'])) { 
     63        $form['groups']['content'] = $groups;     
    6164    } 
    62     else if (!empty($record[$col])) { 
    63       $value = html::span($microformats[$col], Q($record[$col])); 
     65    else { 
     66        unset($form['groups']); 
    6467    } 
    65     else 
    66       $value = ''; 
    67      
    68     $table->add('title', Q(rcube_label($col))); 
    69     $table->add(null, $value); 
    70   } 
    71    
    72   return $table->show($attrib + array('class' => 'vcard')); 
     68 
     69    if (!empty($record['email'])) { 
     70        $form['info']['content']['email']['value'] = html::a(array( 
     71            'href' => 'mailto:' . $record['email'], 
     72            'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($record['email'])), 
     73            'title' => rcube_label('composeto'), 
     74            'class' => $microformats['email'], 
     75        ), Q($record['email'])); 
     76    } 
     77    foreach (array('name', 'firstname', 'surname') as $col) { 
     78        if ($record[$col]) { 
     79            $form['info']['content'][$col]['value'] = html::span($microformats[$col], Q($record[$col])); 
     80        } 
     81    } 
     82 
     83    return rcmail_contact_form($form, $record); 
    7384} 
    7485 
    7586 
    76 function rcmail_contact_record_groups($attrib) 
     87function rcmail_contact_record_groups($contact_id) 
    7788{ 
    78   global $RCMAIL, $CONTACTS, $GROUPS; 
     89    global $RCMAIL, $CONTACTS, $GROUPS; 
     90 
     91    $GROUPS = $CONTACTS->list_groups(); 
     92 
     93    if (empty($GROUPS)) { 
     94        return ''; 
     95    } 
     96 
     97    $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0)); 
     98 
     99    $members = $CONTACTS->get_record_groups($contact_id); 
     100    $checkbox = new html_checkbox(array('name' => '_gid[]', 
     101        'class' => 'groupmember', 'disabled' => $CONTACTS->readonly)); 
     102 
     103    foreach ($GROUPS as $group) { 
     104        $gid = $group['ID']; 
     105        $table->add(null, $checkbox->show($members[$gid] ? $gid : null, 
     106            array('value' => $gid, 'id' => 'ff_gid' . $gid))); 
     107        $table->add(null, html::label('ff_gid' . $gid, Q($group['name']))); 
     108    } 
     109 
     110    $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC))); 
     111    $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID'])); 
     112 
     113    $form_start = $RCMAIL->output->request_form(array( 
     114        'name' => "form", 'method' => "post", 
     115        'task' => $RCMAIL->task, 'action' => 'save', 
     116        'request' => 'save.'.intval($contact_id), 
     117        'noclose' => true), $hiddenfields->show()); 
     118    $form_end = '</form>'; 
     119 
     120    $RCMAIL->output->add_gui_object('editform', 'form'); 
    79121   
    80   // check if we have a valid result 
    81   if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) 
    82     return false; 
    83    
    84   $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0)); 
    85    
    86   $members = $CONTACTS->get_record_groups($record['ID']); 
    87   $checkbox = new html_checkbox(array('name' => '_gid[]', 'class' => 'groupmember', 'disabled' => $CONTACTS->readonly)); 
    88   foreach ($GROUPS as $group) { 
    89     $gid = $group['ID']; 
    90     $table->add(null, $checkbox->show($members[$gid] ? $gid : null, array('value' => $gid, 'id' => 'ff_gid' . $gid))); 
    91     $table->add(null, html::label('ff_gid' . $gid, Q($group['name']))); 
    92   } 
    93    
    94   $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC))); 
    95   $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID'])); 
    96    
    97   $form_start = $RCMAIL->output->request_form(array('name' => "form", 'method' => "post", 'task' => $RCMAIL->task, 'action' => 'save', 'request' => 'save.'.intval($record['ID']), 'noclose' => true) + $attrib, $hiddenfields->show()); 
    98   $form_end = !strlen($attrib['form']) ? '</form>' : ''; 
    99  
    100   $RCMAIL->output->add_gui_object('editform', !empty($attrib['form']) ? $attrib['form'] : 'form'); 
    101    
    102   return $form_start . $table->show($attrib) . $form_end; 
     122    return $form_start . $table->show() . $form_end; 
    103123} 
    104124 
     
    106126//$OUTPUT->framed = $_framed; 
    107127$OUTPUT->add_handler('contactdetails', 'rcmail_contact_details'); 
    108 $OUTPUT->add_handler('contactgroups', 'rcmail_contact_record_groups'); 
     128 
    109129$OUTPUT->send('showcontact'); 
  • trunk/roundcubemail/skins/default/templates/addcontact.html

    r3023 r4151  
    44<title><roundcube:object name="pagetitle" /></title> 
    55<roundcube:include file="/includes/links.html" /> 
     6<script type="text/javascript" src="/functions.js"></script> 
    67</head> 
    78<body class="iframe"> 
    89 
    910<div id="contact-title" class="boxtitle"><roundcube:label name="addcontact" /></div> 
    10  
    1111<div id="contact-details" class="boxcontent"> 
    12 <roundcube:object name="contacteditform" size="40" /> 
    13  
    14 <p><br /> 
    15 <input type="button" value="<roundcube:label name="cancel" />" class="button" onclick="history.back()" />&nbsp; 
    16 <roundcube:button command="save" type="input" class="button mainaction" label="save" /> 
    17 </p> 
    18  
     12  <roundcube:object name="contacteditform" size="40" /> 
     13  <p> 
     14    <input type="button" value="<roundcube:label name="cancel" />" class="button" onclick="history.back()" />&nbsp; 
     15    <roundcube:button command="save" type="input" class="button mainaction" label="save" /> 
     16  </p> 
    1917</form> 
    2018</div> 
     19<script type="text/javascript">rcube_init_tabs('contact-details')</script> 
    2120 
    2221</body> 
  • trunk/roundcubemail/skins/default/templates/editcontact.html

    r3023 r4151  
    44<title><roundcube:object name="pagetitle" /></title> 
    55<roundcube:include file="/includes/links.html" /> 
     6<script type="text/javascript" src="/functions.js"></script> 
    67</head> 
    78<body class="iframe"> 
    89 
    910<div id="contact-title" class="boxtitle"><roundcube:label name="editcontact" /></div> 
    10  
    1111<div id="contact-details" class="boxcontent"> 
    12 <roundcube:object name="contacteditform" size="40" /> 
    13  
    14 <p><br /> 
    15 <roundcube:button command="show" type="input" class="button" label="cancel" />&nbsp; 
    16 <roundcube:button command="save" type="input" class="button mainaction" label="save" /> 
    17 </p> 
    18  
     12  <roundcube:object name="contacteditform" size="40" /> 
     13  <p> 
     14    <roundcube:button command="show" type="input" class="button" label="cancel" />&nbsp; 
     15    <roundcube:button command="save" type="input" class="button mainaction" label="save" /> 
     16  </p> 
    1917</form> 
    2018</div> 
     19<script type="text/javascript">rcube_init_tabs('contact-details')</script> 
    2120 
    2221</body> 
  • trunk/roundcubemail/skins/default/templates/showcontact.html

    r4121 r4151  
    44<title><roundcube:object name="pagetitle" /></title> 
    55<roundcube:include file="/includes/links.html" /> 
     6<script type="text/javascript" src="/functions.js"></script> 
    67</head> 
    78<body class="iframe"> 
    89 
    9 <div id="contact-title" class="boxtitle"><roundcube:object name="contactdetails" part="name" /></div> 
    10  
     10<div id="contact-title" class="boxtitle"><roundcube:label name="contactproperties" /></div> 
    1111<div id="contact-details" class="boxcontent"> 
    12 <fieldset> 
    13   <legend><roundcube:label name="contactproperties" /></legend> 
    1412  <roundcube:object name="contactdetails" /> 
    15  
    16   <p><br /><roundcube:button command="edit" type="input" class="button" label="editcontact" condition="!ENV:readonly" /></p> 
    17 </fieldset> 
    18  
    19 <roundcube:if condition="ENV:groups" /> 
    20 <fieldset> 
    21   <legend><roundcube:label name="groups" /></legend> 
    22   <roundcube:object name="contactgroups" /> 
    23 </fieldset> 
    24 <roundcube:endif /> 
    25  
     13  <p> 
     14    <roundcube:button command="edit" type="input" class="button" label="editcontact" condition="!ENV:readonly" /> 
     15  </p> 
    2616</div> 
     17<script type="text/javascript">rcube_init_tabs('contact-details')</script> 
    2718 
    2819</body> 
Note: See TracChangeset for help on using the changeset viewer.