From c17dc6aa31aaa6e7f61bd25993be55354e428996 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sat, 20 Sep 2008 13:21:15 -0400
Subject: [PATCH] #1485385: fix missing close form tag

---
 program/steps/addressbook/func.inc |   94 ++++++++++++++++++-----------------------------
 1 files changed, 36 insertions(+), 58 deletions(-)

diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index 397b0a1..98cf29f 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -19,23 +19,14 @@
 
 */
 
-require_once('include/rcube_contacts.inc');
-require_once('include/rcube_ldap.inc');
-
 // instantiate a contacts object according to the given source
-if (($source = get_input_value('_source', RCUBE_INPUT_GPC)) && isset($CONFIG['ldap_public'][$source]))
-  $CONTACTS = new rcube_ldap($CONFIG['ldap_public'][$source]);
-else
-  $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
+$CONTACTS = $RCMAIL->get_address_book(($source = get_input_value('_source', RCUBE_INPUT_GPC)));
 
 $CONTACTS->set_pagesize($CONFIG['pagesize']);
 
 // set list properties and session vars
 if (!empty($_GET['_page']))
-  {
-  $CONTACTS->set_page(intval($_GET['_page']));
-  $_SESSION['page'] = $_GET['_page'];
-  }
+  $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
 else
   $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
 
@@ -47,6 +38,18 @@
 $OUTPUT->set_env('source', $source ? $source : '0');
 $OUTPUT->set_env('readonly', $CONTACTS->readonly, false);
 
+// add list of address sources to client env
+$js_list = array();
+if (strtolower($CONFIG['address_book_type']) != 'ldap') {
+  // We are using the DB address book, add it.
+  $js_list = array("0" => array('id' => 0, 'readonly' => false));
+}
+if (is_array($CONFIG['ldap_public'])) {
+  foreach ($CONFIG['ldap_public'] as $id => $prop)
+    $js_list[$id] = array('id' => $id, 'readonly' => !$prop['writable']);
+}
+$OUTPUT->set_env('address_sources', $js_list);
+
 
 function rcmail_directory_list($attrib)
 {
@@ -55,60 +58,34 @@
   if (!$attrib['id'])
     $attrib['id'] = 'rcmdirectorylist';
 
+  $out = '';
   $local_id = '0';
   $current = get_input_value('_source', RCUBE_INPUT_GPC);
-  $line_templ = '<li id="%s" class="%s"><a href="%s"' .
-    ' onclick="return %s.command(\'list\',\'%s\',this)"' .
-    ' onmouseover="return %s.focus_folder(\'%s\')"' .
-    ' onmouseout="return %s.unfocus_folder(\'%s\')"' .
-    ' onmouseup="return %s.folder_mouse_up(\'%s\')">%s'.
-    "</a></li>\n";
+  $line_templ = html::tag('li', array('id' => 'rcmli%s', 'class' => '%s'),
+    html::a(array('href' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s'));
     
-  $js_list = array("$local_id" => array('id' => $local_id, 'readonly' => false));
-
-  // allow the following attributes to be added to the <ul> tag
-  $out = '<ul' . create_attrib_string($attrib, array('style', 'class', 'id')) . ">\n";
-  $out .= sprintf($line_templ,
-    'rcmli'.$local_id,
-    !$current ? 'selected' : '',
-    Q(rcmail_url('list', array('_source' => 0))),
-    JS_OBJECT_NAME,
-    $local_id,
-    JS_OBJECT_NAME,
-    $local_id,
-    JS_OBJECT_NAME,
-    $local_id,
-    JS_OBJECT_NAME,
-    $local_id,
-    rcube_label('personaladrbook'));
+  if (strtolower($CONFIG['address_book_type']) != 'ldap') {
+    $out .= sprintf($line_templ, $local_id, (!$current ? 'selected' : ''),
+      Q(rcmail_url(null, array('_source' => $local_id))), $local_id, rcube_label('personaladrbook'));
+  } // end if
+  else {
+    // DB address book not used, see if a source is set, if not use the
+    // first LDAP directory.
+    if (!$current) {
+      $current = key((array)$CONFIG['ldap_public']);
+    } // end if
+  } // end else
   
-  foreach ((array)$CONFIG['ldap_public'] as $id => $prop)
-  {
+  foreach ((array)$CONFIG['ldap_public'] as $id => $prop) {
     $js_id = JQ($id);
     $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
-    $out .= sprintf($line_templ,
-      'rcmli'.$dom_id,
-      $current == $id ? 'selected' : '',
-      Q(rcmail_url('list', array('_source' => $id))),
-      JS_OBJECT_NAME,
-      $js_id,
-      JS_OBJECT_NAME,
-      $js_id,
-      JS_OBJECT_NAME,
-      $js_id,
-      JS_OBJECT_NAME,
-      $js_id,
-      !empty($prop['name']) ? Q($prop['name']) : Q($id));
-      
-    $js_list[$id] = array('id' => $id, 'readonly' => !$prop['writeable']);
+    $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''),
+      Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($prop['name']) ? Q($prop['name']) : Q($id)));
   }
   
-  $out .= '</ul>';
-
   $OUTPUT->add_gui_object('folderlist', $attrib['id']);
-  $OUTPUT->set_env('address_sources', $js_list);
   
-  return $out;
+  return html::tag('ul', $attrib, $out, html::$common_attrib);
 }
 
 
@@ -159,7 +136,7 @@
     
     // format each col
     foreach ($a_show_cols as $col)
-      $a_row_cols[$col] = $row[$col];
+      $a_row_cols[$col] = Q($row[$col]);
     
     $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
     }
@@ -225,7 +202,8 @@
 
   return $out;
   }
-  
+
+$OUTPUT->set_pagetitle(rcube_label('addressbook'));
   
 // register UI objects
 $OUTPUT->add_handlers(array(
@@ -233,7 +211,7 @@
   'addresslist' => 'rcmail_contacts_list',
   'addressframe' => 'rcmail_contact_frame',
   'recordscountdisplay' => 'rcmail_rowcount_display',
-  'searchform' => 'rcmail_search_form'
+  'searchform' => array($OUTPUT, 'search_form')
 ));
 
 ?>

--
Gitblit v1.9.1