alecpl
2010-06-23 b25dfd0913f2ca5666124740c30156fa0a6abaef
program/steps/addressbook/func.inc
@@ -19,25 +19,29 @@
*/
require_once('include/rcube_contacts.inc');
require_once('include/rcube_ldap.inc');
// add list of address sources to client env
$js_list = $RCMAIL->get_address_sources();
// select source
$source = get_input_value('_source', RCUBE_INPUT_GPC);
// if source is not set use first directory
if (empty($source))
  $source = $js_list[key($js_list)]['id'];
// 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);
$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);
if (!empty($_REQUEST['_gid']))
  $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']]))
@@ -46,69 +50,71 @@
// 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'));
}
function rcmail_directory_list($attrib)
{
  global $CONFIG, $OUTPUT;
  global $RCMAIL, $OUTPUT;
  
  if (!$attrib['id'])
    $attrib['id'] = 'rcmdirectorylist';
  $out = '';
  $local_id = '0';
  $jsdata = array();
  $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";
  $js_list = array("$local_id" => array('id' => $local_id, 'readonly' => false));
  $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'));
  // 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_self_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'));
  foreach ((array)$CONFIG['ldap_public'] as $id => $prop)
  {
  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()));
  }
  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,
      'rcmli'.$dom_id,
      $current == $id ? 'selected' : '',
      Q(rcmail_self_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($source['name']) ? Q($source['name']) : Q($id)));
    $groupdata = rcmail_contact_groups(array('out' => $out, 'jsdata' => $jsdata, 'source' => $id));
    $jsdata = $groupdata['jsdata'];
    $out = $groupdata['out'];
  }
  $out .= '</ul>';
  $OUTPUT->set_env('contactgroups', $jsdata);
  $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);
}
function rcmail_contact_groups($args)
{
  global $RCMAIL;
  $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'));
    $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;
}
@@ -137,7 +143,7 @@
  $OUTPUT->include_script('list.js');
  
  // add some labels to client
  rcube_add_label('deletecontactconfirm');
  $OUTPUT->add_label('deletecontactconfirm');
  
  return $out;
  }
@@ -159,7 +165,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);
    }
@@ -175,11 +181,11 @@
    $attrib['id'] = 'rcmcontactframe';
    
  $attrib['name'] = $attrib['id'];
  $attrib_str = create_attrib_string($attrib, array('name', 'id', 'class', 'style', 'src', 'width', 'height', 'frameborder'));
  $OUTPUT->set_env('contentframe', $attrib['name']);
  $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
  return '<iframe'. $attrib_str . '></iframe>';
  return html::iframe($attrib);
  }
@@ -192,13 +198,7 @@
  $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
  // allow the following attributes to be added to the <span> tag
  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
  $out = '<span' . $attrib_str . '>';
  $out .= rcmail_get_rowcount_text();
  $out .= '</span>';
  return $out;
  return html::span($attrib, rcmail_get_rowcount_text());
  }
@@ -226,14 +226,13 @@
  return $out;
  }
  
// register UI objects
$OUTPUT->add_handlers(array(
  'directorylist' => 'rcmail_directory_list',
//  'groupslist' => 'rcmail_contact_groups',
  'addresslist' => 'rcmail_contacts_list',
  'addressframe' => 'rcmail_contact_frame',
  'recordscountdisplay' => 'rcmail_rowcount_display',
  'searchform' => 'rcmail_search_form'
  'searchform' => array($OUTPUT, 'search_form')
));
?>