[Svn] r4151 - in trunk/roundcubemail: . program/steps/addressbook skins/default/templates

trac at roundcube.net trac at roundcube.net
Thu Oct 28 09:10:11 CEST 2010


Author: alec
Date: 2010-10-28 02:10:11 -0500 (Thu, 28 Oct 2010)
New Revision: 4151

Modified:
   trunk/roundcubemail/CHANGELOG
   trunk/roundcubemail/program/steps/addressbook/edit.inc
   trunk/roundcubemail/program/steps/addressbook/func.inc
   trunk/roundcubemail/program/steps/addressbook/show.inc
   trunk/roundcubemail/skins/default/templates/addcontact.html
   trunk/roundcubemail/skins/default/templates/editcontact.html
   trunk/roundcubemail/skins/default/templates/showcontact.html
Log:
- Plugin API: added 'contact_form' hook
- Re-designed contact frame using Tabs


Modified: trunk/roundcubemail/CHANGELOG
===================================================================
--- trunk/roundcubemail/CHANGELOG	2010-10-27 12:45:51 UTC (rev 4150)
+++ trunk/roundcubemail/CHANGELOG	2010-10-28 07:10:11 UTC (rev 4151)
@@ -52,6 +52,7 @@
 - Add support for selection options from LIST-EXTENDED extension (RFC 5258)
 - Don't list subscribed but non-existent folders (#1486225)
 - Fix handling of URLs with tilde (~) or semicolon (;) character (#1487087, #1487088)
+- Plugin API: added 'contact_form' hook
 
 RELEASE 0.4.2
 -------------

Modified: trunk/roundcubemail/program/steps/addressbook/edit.inc
===================================================================
--- trunk/roundcubemail/program/steps/addressbook/edit.inc	2010-10-27 12:45:51 UTC (rev 4150)
+++ trunk/roundcubemail/program/steps/addressbook/edit.inc	2010-10-28 07:10:11 UTC (rev 4151)
@@ -21,93 +21,92 @@
 
 
 if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true)))
-  $OUTPUT->set_env('cid', $record['ID']);
+    $OUTPUT->set_env('cid', $record['ID']);
 
 // adding not allowed here
-if ($CONTACTS->readonly)
-{
-  $OUTPUT->show_message('sourceisreadonly');
-  rcmail_overwrite_action('show');
-  return;
+if ($CONTACTS->readonly) {
+    $OUTPUT->show_message('sourceisreadonly');
+    rcmail_overwrite_action('show');
+    return;
 }
 
+
 function rcmail_contact_editform($attrib)
 {
-  global $RCMAIL, $CONTACTS, $OUTPUT;
+   global $RCMAIL, $CONTACTS, $OUTPUT;
 
-  // check if we have a valid result
-  if ($RCMAIL->action != 'add' && !(($result = $CONTACTS->get_result()) && ($record = $result->first())))
-  {
-    $OUTPUT->show_message('contactnotfound');
-    return false;
-  }
+    // check if we have a valid result
+    if ($RCMAIL->action != 'add'
+        && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))
+    ) {
+        $OUTPUT->show_message('contactnotfound');
+        return false;
+    }
 
-  // add some labels to client
-  $OUTPUT->add_label('noemailwarning', 'nonamewarning');
+    // add some labels to client
+    $OUTPUT->add_label('noemailwarning', 'nonamewarning');
 
-  list($form_start, $form_end) = get_form_tags($attrib);
-  unset($attrib['form']);
+    $i_size = !empty($attrib['size']) ? $attrib['size'] : 40;
+    $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 6;
+    $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40;
 
-  // a specific part is requested
-  if ($attrib['part'])
-  {
-    $out = $form_start;
-    $out .= rcmail_get_edit_field($attrib['part'], $record[$attrib['part']], $attrib); 
-    return $out;
-  }
+    $form = array(
+        'info' => array(
+            'name'    => rcube_label('contactproperties'),
+            'content' => array(
+                'name' => array('type' => 'text', 'size' => $i_size),
+                'firstname' => array('type' => 'text', 'size' => $i_size),
+                'surname' => array('type' => 'text', 'size' => $i_size),
+                'email' => array('type' => 'text', 'size' => $i_size),
+            ),
+        ),
+    );
 
 
-  // return the complete address edit form as table
-  $out = "$form_start<table>\n\n";
+    list($form_start, $form_end) = get_form_tags($attrib);
+    unset($attrib['form']);
 
-  $a_show_cols = array('name', 'firstname', 'surname', 'email');
-  foreach ($a_show_cols as $col)
-  {
-    $attrib['id'] = 'rcmfd_'.$col;
-    $value = rcmail_get_edit_field($col, $record[$col], $attrib);
-    $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
-                    $attrib['id'],
-                    Q(rcube_label($col)),
-                    $value);
-  }
+    // return the complete address edit form as table
+    $out = rcmail_contact_form($form, $record);
 
-  $out .= "\n</table>$form_end";
-
-  return $out;  
+    return $form_start . $out . $form_end;
 }
 
-$OUTPUT->add_handler('contacteditform', 'rcmail_contact_editform');
 
-
 // similar function as in /steps/settings/edit_identity.inc
 function get_form_tags($attrib)
 {
-  global $CONTACTS, $EDIT_FORM, $RCMAIL;
+    global $CONTACTS, $EDIT_FORM, $RCMAIL;
 
-  $form_start = $form_end = '';
+    $form_start = $form_end = '';
   
-  if (empty($EDIT_FORM)) {
-    $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
-    $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id));
+    if (empty($EDIT_FORM)) {
+        $hiddenfields = new html_hiddenfield(array(
+            'name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
+        $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id));
     
-    if (($result = $CONTACTS->get_result()) && ($record = $result->first()))
-      $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
+        if (($result = $CONTACTS->get_result()) && ($record = $result->first()))
+            $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
     
-    $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());
-    $form_end = !strlen($attrib['form']) ? '</form>' : '';
+        $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());
+        $form_end = !strlen($attrib['form']) ? '</form>' : '';
 
-    $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form';
-    $RCMAIL->output->add_gui_object('editform', $EDIT_FORM);
-  }
+        $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form';
+        $RCMAIL->output->add_gui_object('editform', $EDIT_FORM);
+    }
 
-  return array($form_start, $form_end); 
+    return array($form_start, $form_end); 
 }
 
 
+$OUTPUT->add_handler('contacteditform', 'rcmail_contact_editform');
 
 if (!$CONTACTS->get_result() && $OUTPUT->template_exists('addcontact'))
-  $OUTPUT->send('addcontact');
+    $OUTPUT->send('addcontact');
 
 // this will be executed if no template for addcontact exists
 $OUTPUT->send('editcontact');
-

Modified: trunk/roundcubemail/program/steps/addressbook/func.inc
===================================================================
--- trunk/roundcubemail/program/steps/addressbook/func.inc	2010-10-27 12:45:51 UTC (rev 4150)
+++ trunk/roundcubemail/program/steps/addressbook/func.inc	2010-10-28 07:10:11 UTC (rev 4151)
@@ -27,7 +27,7 @@
 
 // if source is not set use first directory
 if (empty($source))
-  $source = $js_list[key($js_list)]['id'];
+    $source = $js_list[key($js_list)]['id'];
 
 // instantiate a contacts object according to the given source
 $CONTACTS = $RCMAIL->get_address_book($source);
@@ -36,203 +36,260 @@
 
 // set list properties and session vars
 if (!empty($_GET['_page']))
-  $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
+    $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
 else
-  $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
+    $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
   
 if (!empty($_REQUEST['_gid']))
-  $CONTACTS->set_group(get_input_value('_gid', RCUBE_INPUT_GPC));
+    $CONTACTS->set_group(get_input_value('_gid', RCUBE_INPUT_GPC));
 
 // set message set for search result
 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
-  $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
+    $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
 
 // set data source env
 $OUTPUT->set_env('source', $source ? $source : '0');
 $OUTPUT->set_env('readonly', $CONTACTS->readonly, false);
-if(! $OUTPUT->ajax_call) {
-  $OUTPUT->set_env('address_sources', $js_list);
-  $OUTPUT->set_pagetitle(rcube_label('addressbook'));
+if (!$OUTPUT->ajax_call) {
+    $OUTPUT->set_env('address_sources', $js_list);
+    $OUTPUT->set_pagetitle(rcube_label('addressbook'));
 }
 
+
 function rcmail_directory_list($attrib)
 {
-  global $RCMAIL, $OUTPUT;
-  
-  if (!$attrib['id'])
-    $attrib['id'] = 'rcmdirectorylist';
+    global $RCMAIL, $OUTPUT;
 
-  $out = '';
-  $local_id = '0';
-  $jsdata = array();
-  $current = get_input_value('_source', RCUBE_INPUT_GPC);
-  $line_templ = html::tag('li', array('id' => 'rcmli%s', 'class' => 'addressbook %s'),
-    html::a(array('href' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s'));
+    if (!$attrib['id'])
+        $attrib['id'] = 'rcmdirectorylist';
 
-  if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') {
-    $current = '0';
-  }
-  else if (!$current) {
-    // DB address book not used, see if a source is set, if not use the
-    // first LDAP directory.
-    $current = key((array)$RCMAIL->config->get('ldap_public', array()));
-  }
+    $out = '';
+    $local_id = '0';
+    $jsdata = array();
+    $current = get_input_value('_source', RCUBE_INPUT_GPC);
+    $line_templ = html::tag('li', array(
+        'id' => 'rcmli%s', 'class' => 'addressbook %s'),
+        html::a(array('href' => '%s',
+            'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s'));
 
-  foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) {
-    $id = $source['id'] ? $source['id'] : $j;
-    $js_id = JQ($id);
-    $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
-    $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''),
-      Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id)));
-    $groupdata = rcmail_contact_groups(array('out' => $out, 'jsdata' => $jsdata, 'source' => $id));
-    $jsdata = $groupdata['jsdata'];
-    $out = $groupdata['out'];
-  }
+    if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') {
+        $current = '0';
+    }
+    else if (!$current) {
+        // DB address book not used, see if a source is set, if not use the
+        // first LDAP directory.
+        $current = key((array)$RCMAIL->config->get('ldap_public', array()));
+    }
 
-  $OUTPUT->set_env('contactgroups', $jsdata); 
-  $OUTPUT->add_gui_object('folderlist', $attrib['id']);
-  
-  return html::tag('ul', $attrib, $out, html::$common_attrib);
+    foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) {
+        $id = $source['id'] ? $source['id'] : $j;
+        $js_id = JQ($id);
+        $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
+        $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''),
+            Q(rcmail_url(null, array('_source' => $id))),
+            $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id)));
+        $groupdata = rcmail_contact_groups(array('out' => $out, 'jsdata' => $jsdata, 'source' => $id));
+        $jsdata = $groupdata['jsdata'];
+        $out = $groupdata['out'];
+    }
+
+    $OUTPUT->set_env('contactgroups', $jsdata); 
+    $OUTPUT->add_gui_object('folderlist', $attrib['id']);
+
+    return html::tag('ul', $attrib, $out, html::$common_attrib);
 }
 
 
 function rcmail_contact_groups($args)
 {
-  global $RCMAIL;
+    global $RCMAIL;
 
-  $groups = $RCMAIL->get_address_book($args['source'])->list_groups();
+    $groups = $RCMAIL->get_address_book($args['source'])->list_groups();
 
-  if (!empty($groups)) {
-    $line_templ = html::tag('li', array('id' => 'rcmliG%s%s', 'class' => 'contactgroup'),
-      html::a(array('href' => '#', 'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s'));
+    if (!empty($groups)) {
+        $line_templ = html::tag('li', array(
+            'id' => 'rcmliG%s%s', 'class' => 'contactgroup'),
+            html::a(array('href' => '#',
+                'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s'));
 
-    $jsdata = array();
-    foreach ($groups as $group) {
-      $args['out'] .= sprintf($line_templ, $args['source'], $group['ID'], $args['source'], $group['ID'], Q($group['name']));
-      $args['jsdata']['G'.$args['source'].$group['ID']] = array(
-        'source' => $args['source'], 'id' => $group['ID'], 'name' => $group['name'], 'type' => 'group');
+        $jsdata = array();
+        foreach ($groups as $group) {
+            $args['out'] .= sprintf($line_templ, $args['source'], $group['ID'], $args['source'], $group['ID'], Q($group['name']));
+            $args['jsdata']['G'.$args['source'].$group['ID']] = array(
+                'source' => $args['source'], 'id' => $group['ID'],
+                'name' => $group['name'], 'type' => 'group');
+        }
     }
-  }
 
-  return $args;
+    return $args;
 }
 
 
 // return the message list as HTML table
 function rcmail_contacts_list($attrib)
-  {
-  global $CONTACTS, $OUTPUT;
-  
-  // count contacts for this user
-  $result = $CONTACTS->list_records();
-  
-  // add id to message list table if not specified
-  if (!strlen($attrib['id']))
-    $attrib['id'] = 'rcmAddressList';
-  
-  // define list of cols to be displayed
-  $a_show_cols = array('name');
+{
+    global $CONTACTS, $OUTPUT;
 
-  // create XHTML table
-  $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
-