summaryrefslogtreecommitdiff
path: root/program/steps/addressbook
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2007-04-28 18:07:12 +0000
committerthomascube <thomas@roundcube.net>2007-04-28 18:07:12 +0000
commitf1154163b0a9efb21d722bc658352739040ffd61 (patch)
tree28ccaa50bc27fa2c3d10eb8650a9862710668494 /program/steps/addressbook
parent9e5d051e97441794d765b094ed46d8cc732c3944 (diff)
Merged branch devel-addressbook from r443 back to trunk
Diffstat (limited to 'program/steps/addressbook')
-rw-r--r--program/steps/addressbook/copy.inc44
-rw-r--r--program/steps/addressbook/delete.inc73
-rw-r--r--program/steps/addressbook/edit.inc75
-rw-r--r--program/steps/addressbook/func.inc247
-rw-r--r--program/steps/addressbook/ldapsearchform.inc277
-rw-r--r--program/steps/addressbook/list.inc37
-rw-r--r--program/steps/addressbook/mailto.inc48
-rw-r--r--program/steps/addressbook/save.inc260
-rw-r--r--program/steps/addressbook/search.inc53
-rw-r--r--program/steps/addressbook/show.inc61
10 files changed, 431 insertions, 744 deletions
diff --git a/program/steps/addressbook/copy.inc b/program/steps/addressbook/copy.inc
new file mode 100644
index 000000000..e6d917e92
--- /dev/null
+++ b/program/steps/addressbook/copy.inc
@@ -0,0 +1,44 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | program/steps/addressbook/copy.inc |
+ | |
+ | This file is part of the RoundCube Webmail client |
+ | Copyright (C) 2007, RoundCube Dev. - Switzerland |
+ | Licensed under the GNU GPL |
+ | |
+ | PURPOSE: |
+ | Copy a contact record from one direcotry to another |
+ | |
+ +-----------------------------------------------------------------------+
+ | Author: Thomas Bruederli <roundcube@gmail.com> |
+ +-----------------------------------------------------------------------+
+
+ $Id: copy.inc 471 2007-02-09 21:25:50Z thomasb $
+
+*/
+
+$cid = get_input_value('_cid', RCUBE_INPUT_POST);
+$target = get_input_value('_to', RCUBE_INPUT_POST);
+if ($cid && preg_match('/^[a-z0-9\-_=]+(,[a-z0-9\-_=]+)*$/i', $cid) && strlen($target) && $target != $source)
+{
+ if ($target != '0')
+ $TARGET = new rcube_ldap($CONFIG['ldap_public'][$target]);
+ else
+ $TARGET = new rcube_contacts($DB, $_SESSION['user_id']);
+
+ $success = false;
+ if ($TARGET && $TARGET->ready && !$TARGET->readonly)
+ $success = $TARGET->insert($CONTACTS->search($CONTACTS->primary_key, $cid), true);
+
+ if (empty($success))
+ $OUTPUT->show_message('copyerror', 'error');
+ else
+ $OUTPUT->show_message('copysuccess', 'notice', array('nr' => count($success)));
+}
+
+// send response
+$OUTPUT->send();
+
+?> \ No newline at end of file
diff --git a/program/steps/addressbook/delete.inc b/program/steps/addressbook/delete.inc
index 3e33cd864..e5c762844 100644
--- a/program/steps/addressbook/delete.inc
+++ b/program/steps/addressbook/delete.inc
@@ -5,7 +5,7 @@
| program/steps/addressbook/delete.inc |
| |
| This file is part of the RoundCube Webmail client |
- | Copyright (C) 2005, RoundCube Dev. - Switzerland |
+ | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
| Licensed under the GNU GPL |
| |
| PURPOSE: |
@@ -19,80 +19,29 @@
*/
-$REMOTE_REQUEST = TRUE;
-
-if ($_GET['_cid'] && preg_match('/^[0-9]+(,[0-9]+)*$/',$_GET['_cid']))
+if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && preg_match('/^[0-9]+(,[0-9]+)*$/', $cid))
{
- $DB->query("UPDATE ".get_table_name('contacts')."
- SET del=1
- WHERE user_id=?
- AND contact_id IN (".$_GET['_cid'].")",
- $_SESSION['user_id']);
-
- $count = $DB->affected_rows();
- if (!$count)
+ $deleted = $CONTACTS->delete($cid);
+ if (!$deleted)
{
// send error message
exit;
}
-
// count contacts for this user
- $sql_result = $DB->query("SELECT COUNT(contact_id) AS rows
- FROM ".get_table_name('contacts')."
- WHERE del<>1
- AND user_id=?",
- $_SESSION['user_id']);
-
- $sql_arr = $DB->fetch_assoc($sql_result);
- $rowcount = $sql_arr['rows'];
+ $result = $CONTACTS->count();
// update message count display
- $pages = ceil($rowcount/$CONFIG['pagesize']);
- $commands = sprintf("this.set_rowcount('%s');\n", rcmail_get_rowcount_text($rowcount));
- $commands .= sprintf("this.set_env('pagecount', %d);\n", $pages);
-
+ $OUTPUT->set_env('pagecount', ceil($result->count / $CONTACTS->page_size));
+ $OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result->count));
// add new rows from next page (if any)
- if ($_GET['_from']!='show' && $pages>1 && $_SESSION['page'] < $pages)
- {
- $start_row = ($_SESSION['page'] * $CONFIG['pagesize']) - $count;
-
- // get contacts from DB
- $sql_result = $DB->limitquery("SELECT * FROM ".get_table_name('contacts')."
- WHERE del<>1
- AND user_id=?
- ORDER BY name",
- $start_row,
- $count,
- $_SESSION['user_id']);
-
- $commands .= rcmail_js_contacts_list($sql_result);
-
-/*
- // define list of cols to be displayed
- $a_show_cols = array('name', 'email');
-
- while ($sql_arr = $DB->fetch_assoc($sql_result))
- {
- $a_row_cols = array();
-
- // format each col
- foreach ($a_show_cols as $col)
- {
- $cont = rep_specialchars_output($sql_arr[$col]);
- $a_row_cols[$col] = $cont;
- }
-
- $commands .= sprintf("this.add_contact_row(%s, %s);\n",
- $sql_arr['contact_id'],
- array2js($a_row_cols));
- }
-*/
- }
+ $pages = ceil(($result->count + $deleted) / $CONTACTS->page_size);
+ if ($_GET['_from'] != 'show' && $pages > 1 && $CONTACTS->list_page < $pages)
+ rcmail_js_contacts_list($CONTACTS->list_records(null, -$deleted));
// send response
- rcube_remote_response($commands);
+ $OUTPUT->send();
}
exit;
diff --git a/program/steps/addressbook/edit.inc b/program/steps/addressbook/edit.inc
index 245c02409..47db7197d 100644
--- a/program/steps/addressbook/edit.inc
+++ b/program/steps/addressbook/edit.inc
@@ -5,7 +5,7 @@
| program/steps/addressbook/edit.inc |
| |
| This file is part of the RoundCube Webmail client |
- | Copyright (C) 2005, RoundCube Dev. - Switzerland |
+ | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
| Licensed under the GNU GPL |
| |
| PURPOSE: |
@@ -20,30 +20,27 @@
*/
-if (($_GET['_cid'] || $_POST['_cid']) && $_action=='edit')
- {
- $cid = $_POST['_cid'] ? $_POST['_cid'] : $_GET['_cid'];
- $DB->query("SELECT * FROM ".get_table_name('contacts')."
- WHERE contact_id=?
- AND user_id=?
- AND del<>1",
- $cid,
- $_SESSION['user_id']);
-
- $CONTACT_RECORD = $DB->fetch_assoc();
-
- if (is_array($CONTACT_RECORD))
- $OUTPUT->add_script(sprintf("%s.set_env('cid', '%s');", $JS_OBJECT_NAME, $CONTACT_RECORD['contact_id']));
- }
-
+if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true)))
+ $OUTPUT->set_env('cid', $record['ID']);
+// adding not allowed here
+if ($CONTACTS->readonly)
+{
+ $OUTPUT->show_message('sourceisreadonly');
+ rcmail_overwrite_action('show');
+ return;
+}
function rcmail_contact_editform($attrib)
- {
- global $CONTACT_RECORD, $JS_OBJECT_NAME;
+{
+ global $CONTACTS, $OUTPUT;
- if (!$CONTACT_RECORD && $GLOBALS['_action']!='add')
- return rcube_label('contactnotfound');
+ // check if we have a valid result
+ if ($GLOBALS['_action'] != 'add' && !(($result = $CONTACTS->get_result()) && ($record = $result->first())))
+ {
+ $OUTPUT->show_message('contactnotfound');
+ return false;
+ }
// add some labels to client
rcube_add_label('noemailwarning');
@@ -51,15 +48,14 @@ function rcmail_contact_editform($attrib)
list($form_start, $form_end) = get_form_tags($attrib);
unset($attrib['form']);
-
// a specific part is requested
if ($attrib['part'])
- {
+ {
$out = $form_start;
- $out .= rcmail_get_edit_field($attrib['part'], $CONTACT_RECORD[$attrib['part']], $attrib);
+ $out .= rcmail_get_edit_field($attrib['part'], $record[$attrib['part']], $attrib);
return $out;
- }
+ }
// return the complete address edit form as table
@@ -67,38 +63,37 @@ function rcmail_contact_editform($attrib)
$a_show_cols = array('name', 'firstname', 'surname', 'email');
foreach ($a_show_cols as $col)
- {
+ {
$attrib['id'] = 'rcmfd_'.$col;
- $title = rcube_label($col);
- $value = rcmail_get_edit_field($col, $CONTACT_RECORD[$col], $attrib);
+ $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'],
- $title,
+ Q(rcube_label($col)),
$value);
- }
+ }
$out .= "\n</table>$form_end";
return $out;
- }
+}
+
+$OUTPUT->add_handler('contacteditform', 'rcmail_contact_editform');
// similar function as in /steps/settings/edit_identity.inc
function get_form_tags($attrib)
{
- global $CONTACT_RECORD, $OUTPUT, $JS_OBJECT_NAME, $EDIT_FORM, $SESS_HIDDEN_FIELD;
+ global $CONTACTS, $OUTPUT, $EDIT_FORM, $SESS_HIDDEN_FIELD;
+ $result = $CONTACTS->get_result();
$form_start = '';
if (!strlen($EDIT_FORM))
{
$hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task']));
- $hiddenfields->add(array('name' => '_action', 'value' => 'save'));
-
- if ($GLOBALS['_framed'])
- $hiddenfields->add(array('name' => '_framed', 'value' => 1));
+ $hiddenfields->add(array('name' => '_action', 'value' => 'save', 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
- if ($CONTACT_RECORD['contact_id'])
- $hiddenfields->add(array('name' => '_cid', 'value' => $CONTACT_RECORD['contact_id']));
+ if (($result = $CONTACTS->get_result()) && ($record = $result->first()))
+ $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
$form_start = !strlen($attrib['form']) ? '<form name="form" action="./" method="post">' : '';
$form_start .= "\n$SESS_HIDDEN_FIELD\n";
@@ -109,7 +104,7 @@ function get_form_tags($attrib)
$form_name = strlen($attrib['form']) ? $attrib['form'] : 'form';
if (!strlen($EDIT_FORM))
- $OUTPUT->add_script("$JS_OBJECT_NAME.gui_object('editform', '$form_name');");
+ $OUTPUT->add_gui_object('editform', $form_name);
$EDIT_FORM = $form_name;
@@ -118,7 +113,7 @@ function get_form_tags($attrib)
-if (!$CONTACT_RECORD && template_exists('addcontact'))
+if (!$CONTACTS->get_result() && template_exists('addcontact'))
parse_template('addcontact');
// this will be executed if no template for addcontact exists
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index 1f993a9d3..5329270c2 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -5,7 +5,7 @@
| program/steps/addressbook/func.inc |
| |
| This file is part of the RoundCube Webmail client |
- | Copyright (C) 2005, RoundCube Dev. - Switzerland |
+ | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
| Licensed under the GNU GPL |
| |
| PURPOSE: |
@@ -19,152 +19,182 @@
*/
-$CONTACTS_LIST = array();
+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->set_pagesize($CONFIG['pagesize']);
// set list properties and session vars
-if (strlen($_GET['_page']))
+if (!empty($_GET['_page']))
{
- $CONTACTS_LIST['page'] = $_GET['_page'];
+ $CONTACTS->set_page(intval($_GET['_page']));
$_SESSION['page'] = $_GET['_page'];
}
else
- $CONTACTS_LIST['page'] = $_SESSION['page'] ? $_SESSION['page'] : 1;
+ $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
+
+// set message set for search result
+if (!empty($_REQUEST['_search']) && isset($_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);
+
+
+function rcmail_directory_list($attrib)
+{
+ global $CONFIG, $OUTPUT;
+
+ if (!$attrib['id'])
+ $attrib['id'] = 'rcmdirectorylist';
+
+ $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";
+
+ $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_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)
+ {
+ $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 .= '</ul>';
-// disable the ldap public search button if there's no servers configured
-$enable_ldap = 'true';
-if (!$CONFIG['ldap_public'])
- $enable_ldap = 'false';
+ $OUTPUT->add_gui_object('folderlist', $attrib['id']);
+ $OUTPUT->set_env('address_sources', $js_list);
-$OUTPUT->add_script("$JS_OBJECT_NAME.set_env('ldappublicsearch', $enable_ldap);");
+ return $out;
+}
+
// return the message list as HTML table
function rcmail_contacts_list($attrib)
{
- global $DB, $CONFIG, $OUTPUT, $CONTACTS_LIST, $JS_OBJECT_NAME;
-
- //$skin_path = $CONFIG['skin_path'];
- //$image_tag = '<img src="%s%s" alt="%s" border="0" />';
+ global $CONTACTS, $OUTPUT;
// count contacts for this user
- $sql_result = $DB->query("SELECT COUNT(contact_id) AS rows
- FROM ".get_table_name('contacts')."
- WHERE del<>1
- AND user_id=?",
- $_SESSION['user_id']);
-
- $sql_arr = $DB->fetch_assoc($sql_result);
- $rowcount = $sql_arr['rows'];
-
- if ($rowcount)
- {
- $start_row = ($CONTACTS_LIST['page']-1) * $CONFIG['pagesize'];
-
- // get contacts from DB
- $sql_result = $DB->limitquery("SELECT * FROM ".get_table_name('contacts')."
- WHERE del<>1
- AND user_id= ?
- ORDER BY name",
- $start_row,
- $CONFIG['pagesize'],
- $_SESSION['user_id']);
- }
- else
- $sql_result = NULL;
-
-
+ $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', 'email');
-
- // create XHTML table
- $out = rcube_table_output($attrib, $sql_result, $a_show_cols, 'contact_id');
+ $a_show_cols = array('name');
- // set client env
- $javascript = sprintf("%s.gui_object('contactslist', '%s');\n", $JS_OBJECT_NAME, $attrib['id']);
- $javascript .= sprintf("%s.set_env('current_page', %d);\n", $JS_OBJECT_NAME, $CONTACTS_LIST['page']);
- $javascript .= sprintf("%s.set_env('pagecount', %d);\n", $JS_OBJECT_NAME, ceil($rowcount/$CONFIG['pagesize']));
- $javascript .= "rcmail.set_env('newcontact', '" . rcube_label('newcontact') . "');";
- //$javascript .= sprintf("%s.set_env('contacts', %s);", $JS_OBJECT_NAME, array2js($a_js_message_arr));
+ // create XHTML table
+ $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
- $OUTPUT->add_script($javascript);
+ // set client env
+ $OUTPUT->add_gui_object('contactslist', $attrib['id']);
+ $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
+ $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
$OUTPUT->include_script('list.js');
-
+
// add some labels to client
rcube_add_label('deletecontactconfirm');
-
+
return $out;
}
-
-function rcmail_js_contacts_list($sql_result, $obj_name='this')
+function rcmail_js_contacts_list($result, $prefix='')
{
- global $DB;
+ global $OUTPUT;
- $commands = '';
-
- if (!$sql_result)
- return '';
+ if (empty($result) || $result->count == 0)
+ return;
// define list of cols to be displayed
- $a_show_cols = array('name', 'email');
-
- while ($sql_arr = $DB->fetch_assoc($sql_result))
+ $a_show_cols = array('name');
+
+ while ($row = $result->next())
{
$a_row_cols = array();
-
+
// format each col
foreach ($a_show_cols as $col)
- {
- $cont = Q($sql_arr[$col]);
- $a_row_cols[$col] = $cont;
- }
-
- $commands .= sprintf("%s.add_contact_row(%s, %s);\n",
- $obj_name,
- $sql_arr['contact_id'],
- array2js($a_row_cols));
- }
+ $a_row_cols[$col] = $row[$col];
- return $commands;
+ $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
+ }
}
// similar function as /steps/settings/identities.inc::rcmail_identity_frame()
function rcmail_contact_frame($attrib)
{
- global $OUTPUT, $JS_OBJECT_NAME;
+ global $OUTPUT;
if (!$attrib['id'])
$attrib['id'] = 'rcmcontactframe';
$attrib['name'] = $attrib['id'];
-
- $OUTPUT->add_script(sprintf("%s.set_env('contentframe', '%s');", $JS_OBJECT_NAME, $attrib['name']));
-
$attrib_str = create_attrib_string($attrib, array('name', 'id', 'class', 'style', 'src', 'width', 'height', 'frameborder'));
- $out = '<iframe'. $attrib_str . '></iframe>';
-
- return $out;
+
+ $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>';
}
function rcmail_rowcount_display($attrib)
{
- global $OUTPUT, $JS_OBJECT_NAME;
+ global $OUTPUT;
if (!$attrib['id'])
$attrib['id'] = 'rcmcountdisplay';
- $OUTPUT->add_script(sprintf("%s.gui_object('countdisplay', '%s');", $JS_OBJECT_NAME, $attrib['id']));
+ $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>';
@@ -173,32 +203,37 @@ function rcmail_rowcount_display($attrib)
-function rcmail_get_rowcount_text($max=NULL)
+function rcmail_get_rowcount_text()
{
- global $CONTACTS_LIST, $CONFIG, $DB;
+ global $CONTACTS;
- $start_row = ($CONTACTS_LIST['page']-1) * $CONFIG['pagesize'] + 1;
-
- // get nr of contacts
- if ($max===NULL)
- {
- $sql_result = $DB->query("SELECT 1 FROM ".get_table_name('contacts')."
- WHERE del<>1
- AND user_id=?",
- $_SESSION['user_id']);
-
- $max = $DB->num_rows($sql_result);
- }
-
- if ($max==0)
+ // read nr of contacts
+ $result = $CONTACTS->get_result();
+ if (!$result)
+ $result = $CONTACTS->count();
+
+ if ($result->count == 0)
$out = rcube_label('nocontactsfound');
else
- $out = rcube_label(array('name' => 'contactsfromto',
- 'vars' => array('from' => $start_row,
- 'to' => min($max, $start_row + $CONFIG['pagesize'] - 1),
- 'count' => $max)));
+ $out = rcube_label(array(
+ 'name' => 'contactsfromto',
+ 'vars' => array(
+ 'from' => $result->first + 1,
+ 'to' => min($result->count, $result->first + $CONTACTS->page_size),
+ 'count' => $result->count)
+ ));
return $out;
}
+
+
+// register UI objects
+$OUTPUT->add_handlers(array(
+ 'directorylist' => 'rcmail_directory_list',
+ 'addresslist' => 'rcmail_contacts_list',
+ 'addressframe' => 'rcmail_contact_frame',
+ 'recordscountdisplay' => 'rcmail_rowcount_display',
+ 'searchform' => 'rcmail_search_form'
+));
?>
diff --git a/program/steps/addressbook/ldapsearchform.inc b/program/steps/addressbook/ldapsearchform.inc
deleted file mode 100644
index a4e08dcdc..000000000
--- a/program/steps/addressbook/ldapsearchform.inc
+++ /dev/null
@@ -1,277 +0,0 @@
-<?php
-
-/*
- +-----------------------------------------------------------------------+
- | program/steps/addressbook/ldapsearch.inc |
- | |
- | This file is part of the RoundCube Webmail client |
- | Copyright (C) 2005, RoundCube Dev. - Switzerland |
- | Licensed under the GNU GPL |
- | |
- | PURPOSE: |
- | Show an ldap search form in the addressbook |
- | |
- +-----------------------------------------------------------------------+
- | Author: Justin Randell <justin.randell@gmail.com> |
- +-----------------------------------------------------------------------+
-
- $Id$
-
-*/
-require_once 'include/rcube_ldap.inc';
-
-/**
- * draw the ldap public search form
- */
-function rcmail_ldap_public_search_form($attrib)
- {
- global $CONFIG, $JS_OBJECT_NAME, $OUTPUT;
- if (!isset($CONFIG['ldap_public']))
- {
- // no ldap servers to search
- show_message('noldapserver', 'warning');
- rcmail_overwrite_action('add');
- return false;
- }
- else
- {
- // store some information in the session
- $_SESSION['ldap_public']['server_count'] = $server_count = count($CONFIG['ldap_public']);
- $_SESSION['ldap_public']['server_names'] = $server_names = array_keys($CONFIG['ldap_public']);
- }
-
- list($form_start, $form_end) = get_form_tags($attrib);
- $out = "$form_start<table id=\"ldap_public_search_table\">\n\n";
-
- // search name field
- $search_name = new textfield(array('name' => '_ldap_public_search_name',
- 'id' => 'rcmfd_ldap_public_search_name'));
- $out .= "<tr><td class=\"title\"><label for=\"rcmfd_ldap_public_search_name\">" .
- rep_specialchars_output(rcube_label('ldappublicsearchname')) .
- "</label></td><td>" . $search_name->show() . "</td></tr>\n";
-
-
- // there's more than one server to search for, show a dropdown menu
- if ($server_count > 1)
- {
- $select_server = new select(array('name' => '_ldap_public_servers',
- 'id' => 'rcfmd_ldap_public_servers'));
-
- $select_server->add($server_names, $server_names);
-
- $out .= '<tr><td class="title"><label for="rcfmd_ldap_public_servers">' .
- rep_specialchars_output(rcube_label('ldappublicserverselect')) .
- "</label></td><td>" . $select_server->show() . "</td></tr>\n";
- }
-
- // foreach configured ldap server, set up the search fields
- for ($i = 0; $i < $server_count; $i++)
- {
- $server = $CONFIG['ldap_public'][$server_names[$i]];
-
- // only display one search fields select - js takes care of the rest
- if (!$i)
- {
- $field_name = '_ldap_public_search_field';
- $field_id = 'rcfmd_ldap_public_search_field';
-
- $search_fields = new select(array('name' => $field_name,
- 'id' => $field_id));
-
- $search_fields->add(array_keys($server['search_fields']), array_values($server['search_fields']));
- $out .= '<tr><td class="title"><label for="' . $field_id . '">' .
- rep_specialchars_output(rcube_label('ldappublicsearchfield')) .
- "</label></td><td>" . $search_fields->show() . "</td></tr>\n";
-
- $attributes = array('name' => '_ldap_public_search_type',
- 'id' => 'rcmfd_ldap_public_search_type');
-
- // if there's only one server, and it doesn't accept fuzzy searches,
- // then check and disable the check box - thanks pieter
- if ($server_count == 1 && !$server['fuzzy_search'])
- {
- $attributes['CHECKED'] = 'CHECKED';
- $attributes['disabled'] = 'disabled';
- }
-
- $search_type = new checkbox($attributes);
-
- $out .= '<tr id="ldap_fuzzy_search"><td class="title"><label for="rcmfd_ldap_public_search_type">' .
- rep_specialchars_output(rcube_label('ldappublicsearchtype')) .
- "</label></td><td>" . $search_type->show() . "</td></tr>\n";
- }
-
- if ($server_count > 1)
- {
- // store the search fields in a js array for each server
- $js = '';
- foreach ($server['search_fields'] as $search_name => $search_value)
- $js .= "['$search_name', '$search_value'], ";
-
- // store whether this server accepts fuzzy search as last item in array
- $js .= $server['fuzzy_search'] ? "'fuzzy'" : "'exact'";
- $OUTPUT->add_script("rcmail.set_env('{$server_names[$i]}_search_fields', new Array($js));");
- }
- }
-
- // add contact button label text
- $OUTPUT->add_script("rcmail.set_env('addcontact', '" . rcube_label('addcontact') . "');");
-
- $out .= "\n</table>$form_end";
- return $out;
- }
-
-/**
- * get search values and return ldap contacts
- */
-function rcmail_ldap_public_list()
- {
- // just return if we are not being called from a search form
- if (!isset($_POST['_action']))
- return null;
-
- global $CONFIG, $OUTPUT, $JS_OBJECT_NAME;
-
- // show no search name warning and exit
- if (empty($_POST['_ldap_public_search_name']) || trim($_POST['_ldap_public_search_name']) == '')
- {
- show_message('nosearchname', 'warning');
- return false;
- }
-
- // set up ldap server(s) array or bail
- if ($_SESSION['ldap_public']['server_count'] > 1)
- // show no ldap server warning and exit
- if (empty($_POST['_ldap_public_servers']))
- {
- show_message('noldappublicserver', 'warning');
- return false;
- }
- else
- $server_name = $_POST['_ldap_public_servers'];
- else if ($_SESSION['ldap_public']['server_count'] == 1)
- $server_name = $_SESSION['ldap_public']['server_names'][0];
- else
- return false;
-
- // get search parameters
- $search_value = $_POST['_ldap_public_search_name'];
- $search_field = $_POST['_ldap_public_search_field'];
-
- // only use the post var for search type if the ldap server allows 'like'
- $exact = true;
- if ($CONFIG['ldap_public'][$server_name]['fuzzy_search'])
- $exact = isset($_POST['_ldap_public_search_type']) ? true : false;
-
- // perform an ldap search
- $contacts = rcmail_ldap_contact_search($search_value,
- $search_field,
- $CONFIG['ldap_public'][$server_name],
- $exact);
-
- // if no results, show a warning and return
- if (!$contacts)
- {
- show_message('nocontactsreturned', 'warning');
- return false;
- }
-
- // add id to message list table if not specified
- if (!strlen($attrib['id']))
- $attrib['id'] = 'ldapAddressList';
-
- // define table class
- $attrib['class'] = 'records-table';
- $attrib['cellspacing'] = 0;
-
- // define list of cols to be displayed
- $a_show_cols = array('name', 'email');
-
- // create XHTML table
- $out = rcube_table_output($attrib, $contacts, $a_show_cols, 'row_id');
-
- // set client env
- $javascript = "$JS_OBJECT_NAME.gui_object('ldapcontactslist', '{$attrib['id']}');\n";
- $OUTPUT->add_script($javascript);
-
- return $out;
- }
-
-/**
- * perform search for contacts from given public ldap server
- */
-function rcmail_ldap_contact_search($search_value, $search_field, $server, $exact=true)
- {
- global $CONFIG;
-
- $attributes = array($server['name_field'], $server['mail_field']);
-
- $LDAP = new rcube_ldap();
- if ($LDAP->connect($server['hosts'], $server['port'], $server['protocol']))
- {
- $filter = "$search_field=" . ($exact ? $search_value : "*$search_value*");
- $result = $LDAP->search($server['base_dn'],
- $filter,
- $attributes,
- $server['scope'],
- $sort=null);
-
- // add any results to contact array
- if ($result['count'])
- {
- for ($n = 0; $n < $result['count']; $n++)
- {
- $contacts[$n]['name'] = $result[$n][$server['name_field']][0];
- $contacts[$n]['email'] = $result[$n][$server['mail_field']][0];
- $contacts[$n]['row_id'] = $n + 1;
- }
- }
- }
- else
- return false;
-
- // cleanup
- $LDAP->close();
-
- if (!$result['count'])
- return false;
-
- // weed out duplicate emails
- for ($n = 0; $n < $result['count']; $n++)
- for ($i = 0; $i < $result['count']; $i++)
- if ($contacts[$i]['email'] == $contacts[$n]['email'] && $i != $n)
- unset($contacts[$n]);
-
- return $contacts;
- }
-
-function get_form_tags($attrib)
- {
- global $OUTPUT, $JS_OBJECT_NAME, $EDIT_FORM, $SESS_HIDDEN_FIELD;
-
- $form_start = '';
- if (!strlen($EDIT_FORM))
- {
- $hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task']));
- $hiddenfields->add(array('name' => '_action', 'value' => 'ldappublicsearch'));
-
- if ($_framed)
- $hiddenfields->add(array('name' => '_framed', 'value' => 1));
-
- $form_start .= !strlen($attrib['form']) ? '<form name="form" action="./" method="post">' : '';
- $form_start .= "\n$SESS_HIDDEN_FIELD\n";
- $form_start .= $hiddenfields->show();
- }
-
- $form_end = (strlen($EDIT_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
- $form_name = strlen($attrib['form']) ? $attrib['form'] : 'form';
-
- $OUTPUT->add_script("$JS_OBJECT_NAME.gui_object('ldappublicsearchform', '$form_name');");
-
- $EDIT_FORM = $form_name;
-
- return array($form_start, $form_end);
- }
-
-parse_template('ldappublicsearch');
-?>
diff --git a/program/steps/addressbook/list.inc b/program/steps/addressbook/list.inc
index 0aa4873b3..71b9379b1 100644
--- a/program/steps/addressbook/list.inc
+++ b/program/steps/addressbook/list.inc
@@ -5,7 +5,7 @@
| program/steps/addressbook/list.inc |
| |
| This file is part of the RoundCube Webmail client |
- | Copyright (C) 2005, RoundCube Dev. - Switzerland |
+ | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
| Licensed under the GNU GPL |
| |
| PURPOSE: |
@@ -19,38 +19,17 @@
*/
-$REMOTE_REQUEST = TRUE;
-
-// count contacts for this user
-$sql_result = $DB->query("SELECT COUNT(contact_id) AS rows
- FROM ".get_table_name('contacts')."
- WHERE del<>1
- AND user_id=?",
- $_SESSION['user_id']);
-
-$sql_arr = $DB->fetch_assoc($sql_result);
-$rowcount = $sql_arr['rows'];
+// get contacts for this user
+$result = $CONTACTS->list_records();
// update message count display
-$pages = ceil($rowcount/$CONFIG['pagesize']);
-$commands = sprintf("this.set_rowcount('%s');\n", rcmail_get_rowcount_text($rowcount));
-$commands .= sprintf("this.set_env('pagecount', %d);\n", $pages);
-
-$start_row = ($CONTACTS_LIST['page']-1) * $CONFIG['pagesize'];
+$OUTPUT->set_env('pagecount', ceil($result->count / $CONTACTS->page_size));
+$OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($rowcount));
-// get contacts from DB
-$sql_result = $DB->limitquery("SELECT * FROM ".get_table_name('contacts')."
- WHERE del<>1
- AND user_id=?
- ORDER BY name",
- $start_row,
- $CONFIG['pagesize'],
- $_SESSION['user_id']);
-
-$commands .= rcmail_js_contacts_list($sql_result);
+// create javascript list
+rcmail_js_contacts_list($result);
// send response
-rcube_remote_response($commands);
+$OUTPUT->send();
-exit;
?> \ No newline at end of file
diff --git a/program/steps/addressbook/mailto.inc b/program/steps/addressbook/mailto.inc
new file mode 100644
index 000000000..ddbec30d0
--- /dev/null
+++ b/program/steps/addressbook/mailto.inc
@@ -0,0 +1,48 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | program/steps/addressbook/mailto.inc |
+ | |
+ | This file is part of the RoundCube Webmail client |
+ | Copyright (C) 2007, RoundCube Dev. - Switzerland |
+ | Licensed under the GNU GPL |
+ | |
+ | PURPOSE: |
+ | Compose a recipient list with all selected contacts |
+ | |
+ +-----------------------------------------------------------------------+
+ | Author: Thomas Bruederli <roundcube@gmail.com> |
+ +-----------------------------------------------------------------------+
+
+ $Id: copy.inc 471 2007-02-09 21:25:50Z thomasb $
+
+*/
+
+$cid = get_input_value('_cid', RCUBE_INPUT_GET);
+$recipients = null;
+$mailto = array();
+
+if ($cid && preg_match('/^[a-z0-9\-_=]+(,[a-z0-9\-_=]+)*$/i', $cid) && $CONTACTS->ready)
+{
+ $recipients = $CONTACTS->search($CONTACTS->primary_key, $cid);
+
+ while (is_object($recipients) && ($rec = $recipients->iterate()))
+ $mailto[] = format_email_recipient($rec['email'], $rec['name']);
+}
+
+if (!empty($mailto))
+{
+ $mailto_str = join(', ', $mailto);
+ $mailto_id = substr(md5($mailto_str), 0, 16);
+ $_SESSION['mailto'][$mailto_id] = $mailto_str;
+ $OUTPUT->command('redirect', rcmail_self_url('compose', array('_mailto' => $mailto_id), 'mail'));
+}
+else
+ $OUTPUT->show_message('nocontactsfound', 'warning');
+
+
+// send response
+$OUTPUT->send();
+
+?> \ No newline at end of file
diff --git a/program/steps/addressbook/save.inc b/program/steps/addressbook/save.inc
index a50d0388a..72e54b173 100644
--- a/program/steps/addressbook/save.inc
+++ b/program/steps/addressbook/save.inc
@@ -5,7 +5,7 @@
| program/steps/addressbook/save.inc |
| |
| This file is part of the RoundCube Webmail client |
- | Copyright (C) 2005, RoundCube Dev. - Switzerland |
+ | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
| Licensed under the GNU GPL |
| |
| PURPOSE: |
@@ -19,240 +19,108 @@
*/
+// cannot edit record
+if ($CONTACTS->readonly)
+{
+ $OUTPUT->show_message('contactreadonly', 'error');
+ rcmail_overwrite_action(empty($_POST['_cid']) ? 'add' : 'show');
+ return;
+}
+
// check input
-if ((empty($_POST['_name']) || empty($_POST['_email'])) && empty($_GET['_framed']))
- {
- show_message('formincomplete', 'warning');
+if ((!get_input_value('_name', RCUBE_INPUT_POST) || !get_input_value('_email', RCUBE_INPUT_POST)) && $_framed)
+{
+ $OUTPUT->show_message('formincomplete', 'warning');
rcmail_overwrite_action(empty($_POST['_cid']) ? 'add' : 'show');
return;
- }
+}
+
// setup some vars we need
$a_save_cols = array('name', 'firstname', 'surname', 'email');
-$contacts_table = get_table_name('contacts');
+$a_record = array();
+$cid = get_input_value('_cid', RCUBE_INPUT_POST);
+
+// read POST values into hash array
+foreach ($a_save_cols as $col)
+{
+ $fname = '_'.$col;
+ if (isset($_POST[$fname]))
+ $a_record[$col] = get_input_value($fname, RCUBE_INPUT_POST);
+}
// update an existing contact
-if (!empty($_POST['_cid']))
+if (!empty($cid))
+{
+ if ($CONTACTS->update($cid, $a_record))
{
- $a_write_sql = array();
-
- foreach ($a_save_cols as $col)
- {
- $fname = '_'.$col;
- if (!isset($_POST[$fname]))
- continue;
-
- $a_write_sql[] = sprintf("%s=%s",
- $DB->quoteIdentifier($col),
- $DB->quote(get_input_value($fname, RCUBE_INPUT_POST)));
- }
-
- if (sizeof($a_write_sql))
- {
- $DB->query("UPDATE $contacts_table
- SET changed=".$DB->now().", ".join(', ', $a_write_sql)."
- WHERE contact_id=?
- AND user_id=?
- AND del<>1",
- $_POST['_cid'],
- $_SESSION['user_id']);
-
- $updated = $DB->affected_rows();
- }
-
- if ($updated)
- {
if ($_framed)
- {
+ {
// define list of cols to be displayed
- $a_show_cols = array('name', 'email');
$a_js_cols = array();
-
- $sql_result = $DB->query("SELECT * FROM $contacts_table
- WHERE contact_id=?
- AND user_id=?
- AND del<>1",
- $_POST['_cid'],
- $_SESSION['user_id']);
-
- $sql_arr = $DB->fetch_assoc($sql_result);
- foreach ($a_show_cols as $col)
- $a_js_cols[] = (string)$sql_arr[$col];
+ $record = $CONTACTS->get_record($cid, true);
- // update the changed col in list
- $OUTPUT->add_script(sprintf("if(parent.%s)parent.%s.update_contact_row('%d', %s);",
- $JS_OBJECT_NAME,
- $JS_OBJECT_NAME,
- $_POST['_cid'],
- array2js($a_js_cols)));
+ foreach (array('name', 'email') as $col)
+ $a_js_cols[] = (string)$record[$col];
- }
+ // update the changed col in list
+ $OUTPUT->command('parent.update_contact_row', $cid, $a_js_cols);
+ }
// show confirmation
- show_message('successfullysaved', 'confirmation');
+ $OUTPUT->show_message('successfullysaved', 'confirmation');
rcmail_overwrite_action('show');
- }
+ }
else
- {
+ {
// show error message
- show_message('errorsaving', 'error');
+ $OUTPUT->show_message('errorsaving', 'error');
rcmail_overwrite_action('show');
- }
}
+}
// insert a new contact
else
- {
- $a_insert_cols = $a_insert_values = array();
-
+{
// check for existing contacts
- $sql = "SELECT 1 FROM $contacts_table
- WHERE user_id = {$_SESSION['user_id']}
- AND del <> '1' ";
-
- // get email and name, build sql for existing user check
- if (isset($_GET['_emails']) && isset($_GET['_names']))
- {
- $sql .= "AND email IN (";
- $emails = explode(',', get_input_value('_emails', RCUBE_INPUT_GET));
- $names = explode(',', get_input_value('_names', RCUBE_INPUT_GET));
- $count = count($emails);
- $n = 0;
- foreach ($emails as $email)
- {
- $end = (++$n == $count) ? '' : ',';
- $sql .= $DB->quote($email) . $end;
- }
- $sql .= ")";
- $ldap_form = true;
- }
- else if (isset($_POST['_email']))
- $sql .= "AND email = " . $DB->quote(get_input_value('_email', RCUBE_INPUT_POST));
-
- $sql_result = $DB->query($sql);
-
+ $existing = $CONTACTS->search('email', $a_record['email'], false);
+
// show warning message
- if ($DB->num_rows($sql_result))
- {
- show_message('contactexists', 'warning');
-
- if ($ldap_form)
- rcmail_overwrite_action('ldappublicsearch');
- else
- rcmail_overwrite_action('add');
-
+ if ($existing->count)
+ {
+ $OUTPUT->show_message('contactexists', 'warning');
+ rcmail_overwrite_action('add');
return;
- }
+ }
- if ($ldap_form)
- {
- $n = 0;
- foreach ($emails as $email)
- {
- $DB->query("INSERT INTO $contacts_table
- (user_id, name, email)
- VALUES ({$_SESSION['user_id']}," . $DB->quote($names[$n++]) . "," .
- $DB->quote($email) . ")");
- $insert_id[] = $DB->insert_id();
- }
- }
- else
- {
- foreach ($a_save_cols as $col)
- {
- $fname = '_'.$col;
- if (!isset($_POST[$fname]))
- continue;
-
- $a_insert_cols[] = $col;
- $a_insert_values[] = $DB->quote(get_input_value($fname, RCUBE_INPUT_POST));
- }
-
- if (sizeof($a_insert_cols))
- {
- $DB->query("INSERT INTO $contacts_table
- (user_id, changed, del, ".join(', ', $a_insert_cols).")
- VALUES (?, ".$DB->now().", 0, ".join(', ', $a_insert_values).")",
- $_SESSION['user_id']);
-
- $insert_id = $DB->insert_id(get_sequence_name('contacts'));
- }
- }
-
- if ($insert_id)
+ // insert record and send response
+ if ($insert_id = $CONTACTS->insert($a_record))
+ {
+ if ($_framed)
{
- if (!$ldap_form)
- {
- if ($_framed)
- {
- // add contact row or jump to the page where it should appear
- $commands = sprintf("if(parent.%s)parent.", $JS_OBJECT_NAME);
- $sql_result = $DB->query("SELECT * FROM $contacts_table
- WHERE contact_id=?
- AND user_id=?",
- $insert_id,
- $_SESSION['user_id']);
- $commands .= rcmail_js_contacts_list($sql_result, $JS_OBJECT_NAME);
-
- $commands .= sprintf("if(parent.%s)parent.%s.contact_list.select('%d');\n",
- $JS_OBJECT_NAME,
- $JS_OBJECT_NAME,
- $insert_id);
-
- // update record count display
- $commands .= sprintf("if(parent.%s)parent.%s.set_rowcount('%s');\n",
- $JS_OBJECT_NAME,
- $JS_OBJECT_NAME,
- rcmail_get_rowcount_text());
-
- $OUTPUT->add_script($commands);
- }
-
- // show confirmation
- show_message('successfullysaved', 'confirmation');
- $_GET['_cid'] = $insert_id;
- }
- else
- {
// add contact row or jump to the page where it should appear
- $commands = '';
- foreach ($insert_id as $id)
- {
- $sql_result = $DB->query("SELECT * FROM $contacts_table
- WHERE contact_id = $id
- AND user_id = {$_SESSION['user_id']}");
-
- $commands .= sprintf("if(parent.%s)parent.", $JS_OBJECT_NAME);
- $commands .= rcmail_js_contacts_list($sql_result, $JS_OBJECT_NAME);
- $last_id = $id;
- }
+ $CONTACTS->reset();
+ $result = $CONTACTS->search($CONTACTS->primary_key, $insert_id);
- // display the last insert id
- $commands .= sprintf("if(parent.%s)parent.%s.contact_list.select('%d');\n",
- $JS_OBJECT_NAME,
- $JS_OBJECT_NAME,
- $last_id);
+ rcmail_js_contacts_list($result, 'parent.');
+ $OUTPUT->command('parent.contact_list.select', $insert_id);
// update record count display
- $commands .= sprintf("if(parent.%s)parent.%s.set_rowcount('%s');\n",
- $JS_OBJECT_NAME,
- $JS_OBJECT_NAME,
- rcmail_get_rowcount_text());
-
- $OUTPUT->add_script($commands);
- rcmail_overwrite_action('ldappublicsearch');
- }
+ $CONTACTS->reset();
+ $OUTPUT->command('parent.set_rowcount', rcmail_get_rowcount_text());
+ }
// show confirmation
- show_message('successfullysaved', 'confirmation');
+ $OUTPUT->show_message('successfullysaved', 'confirmation');
rcmail_overwrite_action('show');
- }
+ $_GET['_cid'] = $insert_id;
+ }
else
- {
+ {
// show error message
- show_message('errorsaving', 'error');
+ $OUTPUT->show_message('errorsaving', 'error');
rcmail_overwrite_action('add');
- }
}
+}
?>
diff --git a/program/steps/addressbook/search.inc b/program/steps/addressbook/search.inc
new file mode 100644
index 000000000..01233a0bd
--- /dev/null
+++ b/program/steps/addressbook/search.inc
@@ -0,0 +1,53 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | program/steps/addressbook/search.inc |
+ | |
+ | This file is part of the RoundCube Webmail client |
+ | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
+ | Licensed under the GNU GPL |
+ | |
+ | PURPOSE: |
+ | Search step for address book contacts |
+ | |
+ +-----------------------------------------------------------------------+
+ | Author: Thomas Bruederli <roundcube@gmail.com> |
+ +-----------------------------------------------------------------------+
+
+ $Id: search.inc 456 2007-01-10 12:34:33Z thomasb $
+
+*/
+
+$CONTACTS->set_page(1);
+$_SESSION['page'] = 1;
+
+$search = trim(get_input_value('_q', RCUBE_INPUT_GET));
+$search_request = md5('addr'.$search);
+
+// get contacts for this user
+$result = $CONTACTS->search(array('name','email'), $search);
+
+if ($result->count > 0)
+{
+ // save search settings in session
+ $_SESSION['search'][$search_request] = $CONTACTS->get_search_set();
+
+ // create javascript list
+ rcmail_js_contacts_list($result);
+}
+else
+{
+ $OUTPUT->show_message('nocontactsfound', 'warning');
+ $search_request = -1;
+}
+
+// update message count display
+$OUTPUT->set_env('search_request', $search_request);
+$OUTPUT->set_env('pagecount', ceil($result->count / $CONTACTS->page_size));
+$OUTPUT->command('set_rowcount', rcmail_get_rowcount_text());
+
+// send response
+$OUTPUT->send();
+
+?> \ No newline at end of file
diff --git a/program/steps/addressbook/show.inc b/program/steps/addressbook/show.inc
index 960ea1c45..75f1e7452 100644
--- a/program/steps/addressbook/show.inc
+++ b/program/steps/addressbook/show.inc
@@ -5,7 +5,7 @@
| program/steps/addressbook/show.inc |
| |
| This file is part of the RoundCube Webmail client |
- | Copyright (C) 2005, RoundCube Dev. - Switzerland |
+ | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
| Licensed under the GNU GPL |
| |
| PURPOSE: |
@@ -20,35 +20,25 @@
*/
-if ($_GET['_cid'] || $_POST['_cid'])
- {
- $cid = $_POST['_cid'] ? $_POST['_cid'] : $_GET['_cid'];
- $DB->query("SELECT * FROM ".get_table_name('contacts')."
- WHERE contact_id=?
- AND user_id=?
- AND del<>1",
- $cid,
- $_SESSION['user_id']);
-
- $CONTACT_RECORD = $DB->fetch_assoc();
-
- if (is_array($CONTACT_RECORD))
- $OUTPUT->add_script(sprintf("%s.set_env('cid', '%s');", $JS_OBJECT_NAME, $CONTACT_RECORD['contact_id']));
- }
-
+// read contact record
+if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true)))
+ $OUTPUT->set_env('cid', $record['ID']);
function rcmail_contact_details($attrib)
{
- global $CONTACT_RECORD, $JS_OBJECT_NAME;
+ global $CONTACTS, $OUTPUT;
- if (!$CONTACT_RECORD)
- return show_message('contactnotfound');
+ // check if we have a valid result
+ if (!(($result = $CONTACTS->get_result()) && ($record = $result->first())))
+ {
+ $OUTPUT->show_message('contactnotfound');
+ return false;
+ }
// a specific part is requested
if ($attrib['part'])
- return rep_specialchars_output($CONTACT_RECORD[$attrib['part']]);
-
+ return Q($record[$attrib['part']]);
// return the complete address record as table
$out = "<table>\n\n";
@@ -56,25 +46,28 @@ function rcmail_contact_details($attrib)
$a_show_cols = array('name', 'firstname', 'surname', 'email');
foreach ($a_show_cols as $col)
{
- if ($col=='email' && $CONTACT_RECORD[$col])
- $value = sprintf('<a href="#compose" onclick="%s.command(\'compose\', %d)" title="%s">%s</a>',
- $JS_OBJECT_NAME,
- $CONTACT_RECORD['contact_id'],
- rcube_label('composeto'),
- $CONTACT_RECORD[$col]);
+ if ($col=='email' && !empty($record[$col]))
+ $value = sprintf(
+ '<a href="#compose" onclick="%s.command(\'compose\', \'%s\')" title="%s">%s</a>',
+ JS_OBJECT_NAME,
+ JQ($record[$col]),
+ rcube_label('composeto'),
+ Q($record[$col]));
else
- $value = rep_specialchars_output($CONTACT_RECORD[$col]);
+ $value = Q($record[$col]);
- $title = rcube_label($col);
- $out .= sprintf("<tr><td class=\"title\">%s</td><td>%s</td></tr>\n", $title, $value);
+ $out .= sprintf("<tr><td class=\"title\">%s</td><td>%s</td></tr>\n",
+ Q(rcube_label($col)),
+ $value);
}
-
-
+
$out .= "\n</table>";
return $out;
}
-parse_template('showcontact');
+//$OUTPUT->framed = $_framed;
+$OUTPUT->add_handler('contactdetails', 'rcmail_contact_details');
+$OUTPUT->send('showcontact');
?> \ No newline at end of file