diff options
Diffstat (limited to 'program/steps')
33 files changed, 862 insertions, 1441 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 diff --git a/program/steps/error.inc b/program/steps/error.inc index 2eb50eb7b..dd533060a 100644 --- a/program/steps/error.inc +++ b/program/steps/error.inc @@ -64,7 +64,7 @@ EOF; } // database connection error -else if ($ERROR_CODE==0x01f4) +else if ($ERROR_CODE==603) { $__error_title = "DATABASE ERROR: CONNECTION FAILED!"; $__error_text = <<<EOF diff --git a/program/steps/mail/addcontact.inc b/program/steps/mail/addcontact.inc index b040581aa..484b0d4ba 100644 --- a/program/steps/mail/addcontact.inc +++ b/program/steps/mail/addcontact.inc @@ -5,7 +5,7 @@ | program/steps/mail/addcontact.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,49 +19,37 @@ */ -$REMOTE_REQUEST = TRUE; +require_once('include/rcube_contacts.inc'); -if (!empty($_GET['_address'])) - { - $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_GET, TRUE)); - if (sizeof($contact_arr)) - { - $contact = $contact_arr[1]; - - if ($contact['mailto']) - $sql_result = $DB->query("SELECT 1 FROM ".get_table_name('contacts')." - WHERE user_id=? - AND email=? - AND del<>1", - $_SESSION['user_id'],$contact['mailto']); - - // contact entry with this mail address exists - if ($sql_result && $DB->num_rows($sql_result)) - $existing_contact = TRUE; - - else if ($contact['mailto']) - { - $DB->query("INSERT INTO ".get_table_name('contacts')." - (user_id, changed, del, name, email) - VALUES (?, ".$DB->now().", 0, ?, ?)", - $_SESSION['user_id'], - $contact['name'], - $contact['mailto']); +$done = false; - $added = $DB->insert_id(get_sequence_name('contacts')); - } - } - - if ($added) - $commands = show_message('addedsuccessfully', 'confirmation'); - else if ($existing_contact) - $commands = show_message('contactexists', 'warning'); +if (!empty($_POST['_address'])) +{ + $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']); + $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_POST, true), 1, false); + + if (!empty($contact_arr[1]['mailto'])) + { + $contact = array( + 'email' => $contact_arr[1]['mailto'], + 'name' => $contact_arr[1]['name'] + ); + + // use email address part for name + if (empty($contact['name']) || $contact['name'] == $contact['email']) + $contact['name'] = ucfirst(preg_replace('/[\.\-]/', ' ', substr($contact['email'], 0, strpos($contact['email'], '@')))); + + // check for existing contacts + $existing = $CONTACTS->search('email', $contact['email'], false); + if ($done = $existing->count) + $OUTPUT->show_message('contactexists', 'warning'); + else if ($done = $CONTACTS->insert($contact)) + $OUTPUT->show_message('addedsuccessfully', 'confirmation'); } +} +if (!$done) + $OUTPUT->show_message('errorsavingcontact', 'warning'); -if (!$commands) - $commands = show_message('errorsavingcontact', 'warning'); - -rcube_remote_response($commands); -exit; +$OUTPUT->send(); ?>
\ No newline at end of file diff --git a/program/steps/mail/check_recent.inc b/program/steps/mail/check_recent.inc index ca35725ea..119d481ab 100644 --- a/program/steps/mail/check_recent.inc +++ b/program/steps/mail/check_recent.inc @@ -5,7 +5,7 @@ | program/steps/mail/check_recent.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,8 +19,6 @@ */ -$REMOTE_REQUEST = TRUE; - $a_mailboxes = $IMAP->list_mailboxes(); foreach ($a_mailboxes as $mbox_name) @@ -32,10 +30,10 @@ foreach ($a_mailboxes as $mbox_name) $count = $IMAP->messagecount(NULL, 'ALL', TRUE); $unread_count = $IMAP->messagecount(NULL, 'UNSEEN', TRUE); - $commands .= sprintf("this.set_unread_count('%s', %d);\n", addslashes($mbox_name), $unread_count); - $commands .= sprintf("this.set_env('messagecount', %d);\n", $count); - $commands .= sprintf("this.set_rowcount('%s');\n", rcmail_get_messagecount_text($count)); - $commands .= sprintf("this.set_quota('%s');\n", $IMAP->get_quota()); + $OUTPUT->set_env('messagecount', $count); + $OUTPUT->command('set_unread_count', $mbox_name, $unread_count); + $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text()); + $OUTPUT->command('set_quota', $IMAP->get_quota()); // add new message headers to list $a_headers = array(); @@ -46,15 +44,16 @@ foreach ($a_mailboxes as $mbox_name) $a_headers[] = $header; } - $commands .= rcmail_js_message_list($a_headers, TRUE); + rcmail_js_message_list($a_headers, TRUE); } } else { if ($IMAP->messagecount($mbox_name, 'RECENT')) - $commands .= sprintf("this.set_unread_count('%s', %d);\n", addslashes($mbox_name), $IMAP->messagecount($mbox_name, 'UNSEEN')); + $OUTPUT->command('set_unread_count', $mbox_name, $IMAP->messagecount($mbox_name, 'UNSEEN')); } } -rcube_remote_response($commands); +$OUTPUT->send(); + ?> diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index 24057a224..4e73b4ba1 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -36,8 +36,8 @@ if ($_action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_f { @unlink($_SESSION['compose']['attachments'][$id]['path']); $_SESSION['compose']['attachments'][$id] = NULL; - $commands = sprintf("parent.%s.remove_from_attachment_list('rcmfile%d');\n", $JS_OBJECT_NAME, $id); - rcube_remote_response($commands); + $OUTPUT->command('remove_from_attachment_list', "rcmfile$id"); + $OUTPUT->send(); exit; } } @@ -61,7 +61,7 @@ if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_v rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved', 'converting'); // add config parameter to client script -$OUTPUT->add_script(sprintf("%s.set_env('draft_autosave', %d);", $JS_OBJECT_NAME, !empty($CONFIG['drafts_mbox']) ? $CONFIG['draft_autosave'] : 0)); +$OUTPUT->set_env('draft_autosave', !empty($CONFIG['drafts_mbox']) ? $CONFIG['draft_autosave'] : 0); // get reference message and set compose mode @@ -125,24 +125,10 @@ function rcmail_compose_headers($attrib) case 'to': $fname = '_to'; $header = 'to'; - - // we have contact id's as get parameters - if (!empty($_GET['_to']) && preg_match('/^[0-9]+(,[0-9]+)*$/', $_GET['_to'])) - { - $a_recipients = array(); - $sql_result = $DB->query("SELECT name, email - FROM ".get_table_name('contacts')." - WHERE user_id=? - AND del<>1 - AND contact_id IN (".$_GET['_to'].")", - $_SESSION['user_id']); - - while ($sql_arr = $DB->fetch_assoc($sql_result)) - $a_recipients[] = format_email_recipient($sql_arr['email'], $sql_arr['name']); - - if (sizeof($a_recipients)) - $fvalue = join(', ', $a_recipients); - } + + // we have a set of recipients stored is session + if (($mailto_id = get_input_value('_mailto', RCUBE_INPUT_GET)) && $_SESSION['mailto'][$mailto_id]) + $fvalue = $_SESSION['mailto'][$mailto_id]; else if (!empty($_GET['_to'])) $fvalue = get_input_value('_to', RCUBE_INPUT_GET); @@ -246,7 +232,7 @@ function rcmail_compose_headers($attrib) function rcmail_compose_header_from($attrib) { - global $IMAP, $MESSAGE, $DB, $OUTPUT, $JS_OBJECT_NAME, $compose_mode; + global $IMAP, $MESSAGE, $DB, $OUTPUT, $compose_mode; // pass the following attributes to the form class $field_attrib = array('name' => '_from'); @@ -291,7 +277,7 @@ function rcmail_compose_header_from($attrib) $from_id = 0; $a_signatures = array(); - $field_attrib['onchange'] = "$JS_OBJECT_NAME.change_identity(this)"; + $field_attrib['onchange'] = JS_OBJECT_NAME.".change_identity(this)"; $select_from = new select($field_attrib); while ($sql_arr = $DB->fetch_assoc($sql_result)) @@ -330,7 +316,7 @@ function rcmail_compose_header_from($attrib) $out = $select_from->show($from_id); // add signatures to client - $OUTPUT->add_script(sprintf("%s.set_env('signatures', %s);", $JS_OBJECT_NAME, array2js($a_signatures))); + $OUTPUT->set_env('signatures', $a_signatures); } else { @@ -348,7 +334,7 @@ function rcmail_compose_header_from($attrib) function rcmail_compose_body($attrib) { - global $CONFIG, $OUTPUT, $MESSAGE, $JS_OBJECT_NAME, $compose_mode; + global $CONFIG, $OUTPUT, $MESSAGE, $compose_mode; list($form_start, $form_end) = get_form_tags($attrib); unset($attrib['form']); @@ -470,7 +456,7 @@ function rcmail_compose_body($attrib) $lang_set, substr($_SESSION['user_lang'], 0, 2), $attrib['id'], - $JS_OBJECT_NAME), 'foot'); + JS_OBJECT_NAME), 'foot'); rcube_add_label('checking'); } @@ -666,7 +652,7 @@ function rcmail_compose_subject($attrib) function rcmail_compose_attachment_list($attrib) { - global $OUTPUT, $JS_OBJECT_NAME, $CONFIG; + global $OUTPUT, $CONFIG; // add ID if not given if (!$attrib['id']) @@ -690,14 +676,14 @@ function rcmail_compose_attachment_list($attrib) foreach ($_SESSION['compose']['attachments'] as $id => $a_prop) $out .= sprintf('<li id="rcmfile%d"><a href="#delete" onclick="return %s.command(\'remove-attachment\',\'rcmfile%d\', this)" title="%s">%s</a>%s</li>', $id, - $JS_OBJECT_NAME, + JS_OBJECT_NAME, $id, Q(rcube_label('delete')), $button, Q($a_prop['name'])); } - $OUTPUT->add_script(sprintf("%s.gui_object('attachmentlist', '%s');", $JS_OBJECT_NAME, $attrib['id'])); + $OUTPUT->add_gui_object('attachmentlist', $attrib['id']); $out .= '</ul>'; return $out; @@ -707,7 +693,7 @@ function rcmail_compose_attachment_list($attrib) function rcmail_compose_attachment_form($attrib) { - global $OUTPUT, $JS_OBJECT_NAME, $SESS_HIDDEN_FIELD; + global $OUTPUT, $SESS_HIDDEN_FIELD; // add ID if not given if (!$attrib['id']) @@ -718,6 +704,7 @@ function rcmail_compose_attachment_form($attrib) $input_field = rcmail_compose_attachment_field(array()); $label_send = rcube_label('upload'); $label_close = rcube_label('close'); + $js_instance = JS_OBJECT_NAME; $out = <<<EOF <div$attrib_str> @@ -725,13 +712,13 @@ function rcmail_compose_attachment_form($attrib) $SESS_HIDDEN_FIELD $input_field<br /> <input type="button" value="$label_close" class="button" onclick="document.getElementById('$attrib[id]').style.visibility='hidden'" /> -<input type="button" value="$label_send" class="button" onclick="$JS_OBJECT_NAME.command('send-attachment', this.form)" /> +<input type="button" value="$label_send" class="button" onclick="$js_instance.command('send-attachment', this.form)" /> </form> </div> EOF; - $OUTPUT->add_script(sprintf("%s.gui_object('uploadbox', '%s');", $JS_OBJECT_NAME, $attrib['id'])); + $OUTPUT->add_gui_object('uploadbox', $attrib['id']); return $out; } @@ -829,7 +816,7 @@ function rcmail_editor_selector($attrib) $attrib['id'] = '_' . $value; $rb = new radiobutton($attrib); - $selector .= sprintf("<td>%s</td><td class=\"title\"><label for=\"%s\">%s</label></td>", + $selector .= sprintf("%s<label for=\"%s\">%s</label>", $rb->show($value), $attrib['id'], rcube_label($text)); @@ -841,7 +828,7 @@ function rcmail_editor_selector($attrib) function get_form_tags($attrib) { - global $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $MESSAGE_FORM, $SESS_HIDDEN_FIELD; + global $CONFIG, $OUTPUT, $MESSAGE_FORM, $SESS_HIDDEN_FIELD; $form_start = ''; if (!strlen($MESSAGE_FORM)) @@ -858,7 +845,7 @@ function get_form_tags($attrib) $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form'; if (!strlen($MESSAGE_FORM)) - $OUTPUT->add_script("$JS_OBJECT_NAME.gui_object('messageform', '$form_name');"); + $OUTPUT->add_gui_object('messageform', $form_name); $MESSAGE_FORM = $form_name; @@ -866,38 +853,35 @@ function get_form_tags($attrib) } -function format_email_recipient($email, $name='') - { - if ($name && $name != $email) - return sprintf('%s <%s>', strpos($name, ",") ? '"'.$name.'"' : $name, $email); - else - return $email; - } - - -function rcmail_charset_pulldown($selected='ISO-8859-1') - { - $select = new select(); - - - return $select->show($selected); - } +// register UI objects +$OUTPUT->add_handlers(array( + 'composeheaders' => 'rcmail_compose_headers', + 'composesubject' => 'rcmail_compose_subject', + 'composebody' => 'rcmail_compose_body', + 'composeattachmentlist' => 'rcmail_compose_attachment_list', + 'composeattachmentform' => 'rcmail_compose_attachment_form', + 'composeattachment' => 'rcmail_compose_attachment_field', + 'priorityselector' => 'rcmail_priority_selector', + 'editorselector' => 'rcmail_editor_selector', + 'receiptcheckbox' => 'rcmail_receipt_checkbox', +)); /****** get contacts for this user and add them to client scripts ********/ -$sql_result = $DB->query("SELECT name, email - FROM ".get_table_name('contacts')." WHERE user_id=? - AND del<>1",$_SESSION['user_id']); +require_once('include/rcube_contacts.inc'); + +$CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']); +$CONTACTS->set_pagesize(1000); -if ($DB->num_rows($sql_result)) +if ($result = $CONTACTS->list_records()) { $a_contacts = array(); - while ($sql_arr = $DB->fetch_assoc($sql_result)) + while ($sql_arr = $result->iterate()) if ($sql_arr['email']) $a_contacts[] = format_email_recipient($sql_arr['email'], JQ($sql_arr['name'])); - $OUTPUT->add_script(sprintf("$JS_OBJECT_NAME.set_env('contacts', %s);", array2js($a_contacts))); + $OUTPUT->set_env('contacts', $a_contacts); } diff --git a/program/steps/mail/folders.inc b/program/steps/mail/folders.inc index 1b7007c39..a97057e2c 100644 --- a/program/steps/mail/folders.inc +++ b/program/steps/mail/folders.inc @@ -18,44 +18,40 @@ $Id$ */ -$REMOTE_REQUEST = TRUE; $mbox_name = $IMAP->get_mailbox_name(); - // send EXPUNGE command if ($_action=='expunge') - { +{ $success = $IMAP->expunge(get_input_value('_mbox', RCUBE_INPUT_GET)); // reload message list if current mailbox if ($success && !empty($_GET['_reload'])) - { - rcube_remote_response('this.message_list.clear();', TRUE); + { + $OUTPUT->command('message_list.clear'); $_action = 'list'; return; - } + } else $commands = "// expunged: $success\n"; - } +} // clear mailbox else if ($_action=='purge') - { +{ $success = $IMAP->clear_mailbox(get_input_value('_mbox', RCUBE_INPUT_GET)); if ($success && !empty($_GET['_reload'])) - { - $commands = "this.message_list.clear();\n"; - $commands .= "this.set_env('messagecount', 0);\n"; - $commands .= "this.set_env('pagecount', 0);\n"; - $commands .= sprintf("this.set_rowcount('%s');\n", rcmail_get_messagecount_text()); - $commands .= sprintf("this.set_unread_count('%s', 0);\n", addslashes($mbox_name)); - } + { + $OUTPUT->set_env('messagecount', 0); + $OUTPUT->set_env('pagecount', 0); + $OUTPUT->command('message_list.clear'); + $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text()); + $OUTPUT->command('set_unread_count', $mbox_name, 0); + } else $commands = "// purged: $success"; - } - - +} -rcube_remote_response($commands); +$OUTPUT->send($commands); ?>
\ No newline at end of file diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index a0bdf0995..7416fb5d4 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -5,7 +5,7 @@ | program/steps/mail/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: | @@ -25,9 +25,8 @@ require_once('lib/enriched.inc'); $EMAIL_ADDRESS_PATTERN = '/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/i'; -if (empty($_SESSION['mbox'])){ +if (empty($_SESSION['mbox'])) $_SESSION['mbox'] = $IMAP->get_mailbox_name(); -} // set imap properties and session vars if ($mbox = get_input_value('_mbox', RCUBE_INPUT_GPC)) @@ -63,21 +62,24 @@ if (strlen($_GET['_uid'])) // set current mailbox in client environment -$OUTPUT->add_script(sprintf("%s.set_env('mailbox', '%s');", $JS_OBJECT_NAME, $IMAP->get_mailbox_name())); +$OUTPUT->set_env('mailbox', $IMAP->get_mailbox_name()); +//$OUTPUT->set_pagetitle(rcube_charset_convert($IMAP->get_mailbox_name(), 'UTF-7', 'UTF-8')); if ($CONFIG['trash_mbox']) - $OUTPUT->add_script(sprintf("%s.set_env('trash_mailbox', '%s');", $JS_OBJECT_NAME, $CONFIG['trash_mbox'])); - + $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']); if ($CONFIG['drafts_mbox']) - $OUTPUT->add_script(sprintf("%s.set_env('drafts_mailbox', '%s');", $JS_OBJECT_NAME, $CONFIG['drafts_mbox'])); - + $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']); if ($CONFIG['junk_mbox']) - $OUTPUT->add_script(sprintf("%s.set_env('junk_mailbox', '%s');", $JS_OBJECT_NAME, $CONFIG['junk_mbox'])); + $OUTPUT->set_env('junk_mailbox', $CONFIG['junk_mbox']); + +if (!$OUTPUT->ajax_call) + rcube_add_label('checkingmail'); + // return the mailboxlist in HTML function rcmail_mailbox_list($attrib) { - global $IMAP, $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $COMM_PATH; + global $IMAP, $CONFIG, $OUTPUT, $COMM_PATH; static $s_added_script = FALSE; static $a_mailboxes; @@ -136,7 +138,7 @@ function rcmail_mailbox_list($attrib) if ($type=='ul') - $OUTPUT->add_script(sprintf("%s.gui_object('mailboxlist', '%s');", $JS_OBJECT_NAME, $attrib['id'])); + $OUTPUT->add_gui_object('mailboxlist', $attrib['id']); return $out . "</$type>"; } @@ -176,7 +178,7 @@ function rcmail_build_folder_tree(&$arrFolders, $folder, $delm='/', $path='') // return html for a structured list <ul> for the mailbox tree function rcmail_render_folder_tree_html(&$arrFolders, &$special, &$mbox_name, $maxlength, $nestLevel=0) { - global $JS_OBJECT_NAME, $COMM_PATH, $IMAP, $CONFIG, $OUTPUT; + global $COMM_PATH, $IMAP, $CONFIG, $OUTPUT; $idx = 0; $out = ''; @@ -207,7 +209,8 @@ function rcmail_render_folder_tree_html(&$arrFolders, &$special, &$mbox_name, $m $foldername .= sprintf(' (%d)', $unread_count); // make folder name safe for ids and class names - $folder_css = $class_name = preg_replace('/[^a-z0-9\-_]/', '', $folder_lc); + $folder_id = preg_replace('/[^A-Za-z0-9\-_]/', '', $folder['id']); + $class_name = preg_replace('/[^a-z0-9\-_]/', '', $folder_lc); // set special class for Sent, Drafts, Trash and Junk if ($folder['id']==$CONFIG['sent_mbox']) @@ -220,25 +223,24 @@ function rcmail_render_folder_tree_html(&$arrFolders, &$special, &$mbox_name, $m $class_name = 'junk'; $js_name = htmlspecialchars(JQ($folder['id'])); - $out .= sprintf('<li id="rcmbx%s" class="mailbox %s %s%s%s"><a href="%s&_mbox=%s"'. - ' onclick="return %s.command(\'list\',\'%s\')"'. - ' onmouseover="return %s.focus_mailbox(\'%s\')"' . - ' onmouseout="return %s.unfocus_mailbox(\'%s\')"' . - ' onmouseup="return %s.mbox_mouse_up(\'%s\')"%s>%s</a>', - $folder_css, + $out .= sprintf('<li id="rcmli%s" class="mailbox %s %s%s%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>%s</a>', + $folder_id, $class_name, $zebra_class, $unread_count ? ' unread' : '', $folder['id']==$mbox_name ? ' selected' : '', - $COMM_PATH, - urlencode($folder['id']), - $JS_OBJECT_NAME, + Q(rcmail_self_url('', array('_mbox' => $folder['id']))), + JS_OBJECT_NAME, $js_name, - $JS_OBJECT_NAME, + JS_OBJECT_NAME, $js_name, - $JS_OBJECT_NAME, + JS_OBJECT_NAME, $js_name, - $JS_OBJECT_NAME, + JS_OBJECT_NAME, $js_name, $title, Q($foldername)); @@ -293,7 +295,7 @@ function rcmail_render_folder_tree_select(&$arrFolders, &$special, &$mbox_name, // return the message list as HTML table function rcmail_message_list($attrib) { - global $IMAP, $CONFIG, $COMM_PATH, $OUTPUT, $JS_OBJECT_NAME; + global $IMAP, $CONFIG, $COMM_PATH, $OUTPUT; $skin_path = $CONFIG['skin_path']; $image_tag = '<img src="%s%s" alt="%s" border="0" />'; @@ -358,28 +360,30 @@ function rcmail_message_list($attrib) // asc link if (!empty($attrib['sortascbutton'])) { - $sort .= rcube_button(array('command' => 'sort', - 'prop' => $col.'_ASC', - 'image' => $attrib['sortascbutton'], - 'align' => 'absmiddle', - 'title' => 'sortasc')); + $sort .= $OUTPUT->button(array( + 'command' => 'sort', + 'prop' => $col.'_ASC', + 'image' => $attrib['sortascbutton'], + 'align' => 'absmiddle', + 'title' => 'sortasc')); } // desc link if (!empty($attrib['sortdescbutton'])) { - $sort .= rcube_button(array('command' => 'sort', - 'prop' => $col.'_DESC', - 'image' => $attrib['sortdescbutton'], - 'align' => 'absmiddle', - 'title' => 'sortdesc')); + $sort .= $OUTPUT->button(array( + 'command' => 'sort', + 'prop' => $col.'_DESC', + 'image' => $attrib['sortdescbutton'], + 'align' => 'absmiddle', + 'title' => 'sortdesc')); } } // just add a link tag to the header else { $col_name = sprintf('<a href="./#sort" onclick="return %s.command(\'sort\',\'%s\',this)" title="%s">%s</a>', - $JS_OBJECT_NAME, + JS_OBJECT_NAME, $col, rcube_label('sortby'), $col_name); @@ -430,7 +434,7 @@ function rcmail_message_list($attrib) else if ($attrib['messageicon']) $message_icon = $attrib['messageicon']; - // set attachment icon + // set attachment icon if ($attrib['attachmenticon'] && preg_match("/multipart\/[mr]/i", $header->ctype)) $attach_icon = $attrib['attachmenticon']; @@ -441,7 +445,7 @@ function rcmail_message_list($attrib) $zebra_class); $out .= sprintf("<td class=\"icon\">%s</td>\n", $message_icon ? sprintf($image_tag, $skin_path, $message_icon, '') : ''); - + // format each col foreach ($a_show_cols as $col) { @@ -449,15 +453,13 @@ function rcmail_message_list($attrib) $cont = Q(rcmail_address_string($header->$col, 3, $attrib['addicon']), 'show'); else if ($col=='subject') { - $cont = Q($IMAP->decode_header($header->$col)); - if (!$cont) $cont = Q(rcube_label('nosubject')); - // firefox/mozilla temporary workaround to pad subject with content so that whitespace in rows responds to drag+drop - $cont .= '<img src="./program/blank.gif" height="5" width="1000" alt="" />'; + $cont = Q(rcube_imap::decode_mime_string($header->$col, $header->charset)); + if (empty($cont)) $cont = Q(rcube_label('nosubject')); } else if ($col=='size') $cont = show_bytes($header->$col); else if ($col=='date') - $cont = format_date($header->date); //date('m.d.Y G:i:s', strtotime($header->date)); + $cont = format_date($header->date); else $cont = Q($header->$col); @@ -478,50 +480,46 @@ function rcmail_message_list($attrib) $message_count = $IMAP->messagecount(); // set client env - $javascript .= sprintf("%s.gui_object('mailcontframe', '%s');\n", $JS_OBJECT_NAME, 'mailcontframe'); - $javascript .= sprintf("%s.gui_object('messagelist', '%s');\n", $JS_OBJECT_NAME, $attrib['id']); - $javascript .= sprintf("%s.set_env('messagecount', %d);\n", $JS_OBJECT_NAME, $message_count); - $javascript .= sprintf("%s.set_env('current_page', %d);\n", $JS_OBJECT_NAME, $IMAP->list_page); - $javascript .= sprintf("%s.set_env('pagecount', %d);\n", $JS_OBJECT_NAME, ceil($message_count/$IMAP->page_size)); - $javascript .= sprintf("%s.set_env('sort_col', '%s');\n", $JS_OBJECT_NAME, $sort_col); - $javascript .= sprintf("%s.set_env('sort_order', '%s');\n", $JS_OBJECT_NAME, $sort_order); + $OUTPUT->add_gui_object('mailcontframe', 'mailcontframe'); + $OUTPUT->add_gui_object('messagelist', $attrib['id']); + $OUTPUT->set_env('messagecount', $message_count); + $OUTPUT->set_env('current_page', $IMAP->list_page); + $OUTPUT->set_env('pagecount', ceil($message_count/$IMAP->page_size)); + $OUTPUT->set_env('sort_col', $sort_col); + $OUTPUT->set_env('sort_order', $sort_order); if ($attrib['messageicon']) - $javascript .= sprintf("%s.set_env('messageicon', '%s%s');\n", $JS_OBJECT_NAME, $skin_path, $attrib['messageicon']); + $OUTPUT->set_env('messageicon', $skin_path . $attrib['messageicon']); if ($attrib['deletedicon']) - $javascript .= sprintf("%s.set_env('deletedicon', '%s%s');\n", $JS_OBJECT_NAME, $skin_path, $attrib['deletedicon']); + $OUTPUT->set_env('deletedicon', $skin_path . $attrib['deletedicon']); if ($attrib['unreadicon']) - $javascript .= sprintf("%s.set_env('unreadicon', '%s%s');\n", $JS_OBJECT_NAME, $skin_path, $attrib['unreadicon']); + $OUTPUT->set_env('unreadicon', $skin_path . $attrib['unreadicon']); if ($attrib['repliedicon']) - $javascript .= sprintf("%s.set_env('repliedicon', '%s%s');\n", $JS_OBJECT_NAME, $skin_path, $attrib['repliedicon']); + $OUTPUT->set_env('repliedicon', $skin_path . $attrib['repliedicon']); if ($attrib['attachmenticon']) - $javascript .= sprintf("%s.set_env('attachmenticon', '%s%s');\n", $JS_OBJECT_NAME, $skin_path, $attrib['attachmenticon']); - - $javascript .= sprintf("%s.set_env('messages', %s);", $JS_OBJECT_NAME, array2js($a_js_message_arr)); + $OUTPUT->set_env('attachmenticon', $skin_path . $attrib['attachmenticon']); + + $OUTPUT->set_env('messages', array2js($a_js_message_arr)); - $OUTPUT->add_script($javascript); $OUTPUT->include_script('list.js'); return $out; } - - // return javascript commands to add rows to the message list function rcmail_js_message_list($a_headers, $insert_top=FALSE) { - global $CONFIG, $IMAP; + global $CONFIG, $IMAP, $OUTPUT; - $commands = ''; $a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject'); // show 'to' instead of from in sent messages - if (($IMAP->get_mailbox_name()==$CONFIG['sent_mbox'] || $IMAP->get_mailbox_name()==$CONFIG['drafts_mbox']) - && ($f = array_search('from', $a_show_cols)) && !array_search('to', $a_show_cols)) + if (($IMAP->get_mailbox_name() == $CONFIG['sent_mbox'] || $IMAP->get_mailbox_name() == $CONFIG['drafts_mbox']) + && (($f = array_search('from', $a_show_cols)) !== false) && array_search('to', $a_show_cols) === false) $a_show_cols[$f] = 'to'; - $commands .= sprintf("this.set_message_coltypes(%s);\n", array2js($a_show_cols)); + $OUTPUT->command('set_message_coltypes', $a_show_cols); // loop through message headers for ($n=0; $a_headers[$n]; $n++) @@ -529,7 +527,7 @@ function rcmail_js_message_list($a_headers, $insert_top=FALSE) $header = $a_headers[$n]; $a_msg_cols = array(); $a_msg_flags = array(); - + // format each col; similar as in rcmail_message_list() foreach ($a_show_cols as $col) { @@ -537,13 +535,13 @@ function rcmail_js_message_list($a_headers, $insert_top=FALSE) $cont = Q(rcmail_address_string($header->$col, 3), 'show'); else if ($col=='subject') { - $cont = Q($IMAP->decode_header($header->$col)); + $cont = Q(rcube_imap::decode_mime_string($header->$col, $header->charset)); if (!$cont) $cont = Q(rcube_label('nosubject')); } else if ($col=='size') $cont = show_bytes($header->$col); else if ($col=='date') - $cont = format_date($header->date); //date('m.d.Y G:i:s', strtotime($header->date)); + $cont = format_date($header->date); else $cont = Q($header->$col); @@ -553,22 +551,20 @@ function rcmail_js_message_list($a_headers, $insert_top=FALSE) $a_msg_flags['deleted'] = $header->deleted ? 1 : 0; $a_msg_flags['unread'] = $header->seen ? 0 : 1; $a_msg_flags['replied'] = $header->answered ? 1 : 0; - $commands .= sprintf("this.add_message_row(%s, %s, %s, %b, %b);\n", - $header->uid, - array2js($a_msg_cols), - array2js($a_msg_flags), - preg_match("/multipart\/m/i", $header->ctype), - $insert_top); + $OUTPUT->command('add_message_row', + $header->uid, + $a_msg_cols, + $a_msg_flags, + preg_match("/multipart\/m/i", $header->ctype), + $insert_top); } - - return $commands; } // return an HTML iframe for loading mail content function rcmail_messagecontent_frame($attrib) { - global $OUTPUT, $JS_OBJECT_NAME; + global $OUTPUT; if (empty($attrib['id'])) $attrib['id'] = 'rcmailcontentwindow'; @@ -581,52 +577,21 @@ function rcmail_messagecontent_frame($attrib) $framename, $attrib_str); - $OUTPUT->add_script("$JS_OBJECT_NAME.set_env('contentframe', '$framename');"); + $OUTPUT->set_env('contentframe', $framename); + $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif'); return $out; } -// return code for search function -function rcmail_search_form($attrib) - { - global $OUTPUT, $JS_OBJECT_NAME; - - // add some labels to client - rcube_add_label('searching'); - - $attrib['name'] = '_q'; - - if (empty($attrib['id'])) - $attrib['id'] = 'rcmqsearchbox'; - - $input_q = new textfield($attrib); - $out = $input_q->show(); - - $OUTPUT->add_script(sprintf("%s.gui_object('qsearchbox', '%s');", - $JS_OBJECT_NAME, - $attrib['id'])); - - // add form tag around text field - if (empty($attrib['form'])) - $out = sprintf('<form name="rcmqsearchform" action="./" '. - 'onsubmit="%s.command(\'search\');return false" style="display:inline;">%s</form>', - $JS_OBJECT_NAME, - $out); - - return $out; - } - function rcmail_messagecount_display($attrib) { - global $IMAP, $OUTPUT, $JS_OBJECT_NAME; + global $IMAP, $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')); @@ -641,12 +606,12 @@ function rcmail_messagecount_display($attrib) function rcmail_quota_display($attrib) { - global $OUTPUT, $JS_OBJECT_NAME, $COMM_PATH; + global $OUTPUT, $COMM_PATH; if (!$attrib['id']) $attrib['id'] = 'rcmquotadisplay'; - $OUTPUT->add_script(sprintf("%s.gui_object('quotadisplay', '%s');", $JS_OBJECT_NAME, $attrib['id'])); + $OUTPUT->add_gui_object('quotadisplay', $attrib['id']); // allow the following attributes to be added to the <span> tag $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id')); @@ -675,8 +640,7 @@ function rcmail_quota_content($display) if ($display == 'image' && function_exists('imagegif')) { $attrib = array('width' => 100, 'height' => 14); - $quota_text = sprintf('<img src="%s&_action=quotaimg&u=%s&q=%d&w=%d&h=%d" width="%d" height="%d" alt="%s" title="%s / %s" />', - $COMM_PATH, + $quota_text = sprintf('<img src="./bin/quotaimg.php?u=%s&q=%d&w=%d&h=%d" width="%d" height="%d" alt="%s" title="%s / %s" />', $quota['used'], $quota['total'], $attrib['width'], $attrib['height'], $attrib['width'], $attrib['height'], @@ -723,7 +687,7 @@ function rcmail_get_messagecount_text($count=NULL, $page=NULL) function rcmail_print_body($part, $safe=FALSE, $plain=FALSE) { - global $IMAP, $REMOTE_OBJECTS, $JS_OBJECT_NAME; + global $IMAP, $REMOTE_OBJECTS; $body = is_array($part->replaces) ? strtr($part->body, $part->replaces) : $part->body; @@ -795,7 +759,7 @@ function rcmail_print_body($part, $safe=FALSE, $plain=FALSE) $convert_replaces[] = "rcmail_str_replacement('\\1<a href=\"http://\\2\\3\" target=\"_blank\">\\2\\3</a>', \$replace_strings)"; $convert_patterns[] = '/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/ie'; - $convert_replaces[] = "rcmail_str_replacement('<a href=\"mailto:\\1\" onclick=\"return $JS_OBJECT_NAME.command(\'compose\',\'\\1\',this)\">\\1</a>', \$replace_strings)"; + $convert_replaces[] = "rcmail_str_replacement('<a href=\"mailto:\\1\" onclick=\"return ".JS_OBJECT_NAME.".command(\'compose\',\'\\1\',this)\">\\1</a>', \$replace_strings)"; if ($part->ctype_parameters['format'] != 'flowed') $body = wordwrap(trim($body), 80); @@ -1052,7 +1016,7 @@ function rcmail_message_headers($attrib, $headers=NULL) // get associative array of headers object if (!$headers) $headers = is_object($MESSAGE['headers']) ? get_object_vars($MESSAGE['headers']) : $MESSAGE['headers']; - + $header_count = 0; // allow the following attributes to be added to the <table> tag @@ -1072,7 +1036,7 @@ function rcmail_message_headers($attrib, $headers=NULL) else if (in_array($hkey, array('from', 'to', 'cc', 'bcc', 'reply-to'))) $header_value = Q(rcmail_address_string($headers[$hkey], NULL, $attrib['addicon']), 'show'); else - $header_value = Q($IMAP->decode_header($headers[$hkey])); + $header_value = Q(rcube_imap::decode_mime_string($headers[$hkey], $headers['charset'])); $out .= "\n<tr>\n"; $out .= '<td class="header-title">'.Q(rcube_label($hkey)).": </td>\n"; @@ -1089,7 +1053,7 @@ function rcmail_message_headers($attrib, $headers=NULL) function rcmail_message_body($attrib) { - global $CONFIG, $OUTPUT, $MESSAGE, $IMAP, $GET_URL, $REMOTE_OBJECTS, $JS_OBJECT_NAME; + global $CONFIG, $OUTPUT, $MESSAGE, $IMAP, $GET_URL, $REMOTE_OBJECTS; if (!is_array($MESSAGE['parts']) && !$MESSAGE['body']) return ''; @@ -1169,7 +1133,7 @@ function rcmail_message_body($attrib) // tell client that there are blocked remote objects if ($REMOTE_OBJECTS && !$safe_mode) - $OUTPUT->add_script(sprintf("%s.set_env('blockedobjects', true);", $JS_OBJECT_NAME)); + $OUTPUT->set_env('blockedobjects', true); $out .= "\n</div>"; return $out; @@ -1261,7 +1225,7 @@ function rcmail_alter_html_link($in) if (stristr((string)$attrib['href'], 'mailto:')) $attrib['onclick'] = sprintf("return %s.command('compose','%s',this)", - $GLOBALS['JS_OBJECT_NAME'], + JS_OBJECT_NAME, JQ(substr($attrib['href'], 7))); else if (!empty($attrib['href']) && $attrib['href']{0}!='#') $attrib['target'] = '_blank'; @@ -1383,7 +1347,7 @@ function rcmail_first_text_part($message_struct) // decode address string and re-format it as HTML links function rcmail_address_string($input, $max=NULL, $addicon=NULL) { - global $IMAP, $PRINT_MODE, $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $EMAIL_ADDRESS_PATTERN; + global $IMAP, $PRINT_MODE, $CONFIG, $OUTPUT, $EMAIL_ADDRESS_PATTERN; $a_parts = $IMAP->decode_address_list($input); @@ -1403,14 +1367,14 @@ function rcmail_address_string($input, $max=NULL, $addicon=NULL) { $out .= sprintf('<a href="mailto:%s" onclick="return %s.command(\'compose\',\'%s\',this)" class="rcmContactAddress" title="%s">%s</a>', Q($part['mailto']), - $JS_OBJECT_NAME, + JS_OBJECT_NAME, JQ($part['mailto']), Q($part['mailto']), Q($part['name'])); if ($addicon) $out .= sprintf(' <a href="#add" onclick="return %s.command(\'add-contact\',\'%s\',this)" title="%s"><img src="%s%s" alt="add" border="0" /></a>', - $JS_OBJECT_NAME, + JS_OBJECT_NAME, urlencode($part['string']), rcube_label('addtoaddressbook'), $CONFIG['skin_path'], @@ -1500,6 +1464,20 @@ function rcmail_compose_cleanup() unset($_SESSION['compose']); } - - + + +// register UI objects +$OUTPUT->add_handlers(array( + 'mailboxlist' => 'rcmail_mailbox_list', + 'messages' => 'rcmail_message_list', + 'messagecountdisplay' => 'rcmail_messagecount_display', + 'quotadisplay' => 'rcmail_quota_display', + 'messageheaders' => 'rcmail_message_headers', + 'messagebody' => 'rcmail_message_body', + 'messagecontentframe' => 'rcmail_messagecontent_frame', + 'messagepartframe' => 'rcmail_message_part_frame', + 'messagepartcontrols' => 'rcmail_message_part_controls', + 'searchform' => 'rcmail_search_form' +)); + ?>
\ No newline at end of file diff --git a/program/steps/mail/getunread.inc b/program/steps/mail/getunread.inc index ed4a5fb77..e6b3843e4 100644 --- a/program/steps/mail/getunread.inc +++ b/program/steps/mail/getunread.inc @@ -19,18 +19,13 @@ */ -$REMOTE_REQUEST = TRUE; - $a_folders = $IMAP->list_mailboxes(); if (!empty($a_folders)) - { +{ foreach ($a_folders as $mbox_row) - { - $commands = sprintf("this.set_unread_count('%s', %d);\n", addslashes($mbox_row), $IMAP->messagecount($mbox_row, 'UNSEEN')); - rcube_remote_response($commands, TRUE); - } - } + $OUTPUT->command('set_unread_count', $mbox_row, $IMAP->messagecount($mbox_row, 'UNSEEN')); +} -exit; +$OUTPUT->send(); ?> diff --git a/program/steps/mail/list.inc b/program/steps/mail/list.inc index 6e0637441..162624c36 100644 --- a/program/steps/mail/list.inc +++ b/program/steps/mail/list.inc @@ -19,25 +19,23 @@ */ -$REMOTE_REQUEST = TRUE; $OUTPUT_TYPE = 'js'; - // is there a sort type for this request? if ($sort = get_input_value('_sort', RCUBE_INPUT_GET)) - { +{ // yes, so set the sort vars list($sort_col, $sort_order) = explode('_', $sort); // set session vars for sort (so next page and task switch know how to sort) $_SESSION['sort_col'] = $sort_col; $_SESSION['sort_order'] = $sort_order; - } +} else - { +{ // use session settings if set, defaults if not $sort_col = isset($_SESSION['sort_col']) ? $_SESSION['sort_col'] : $CONFIG['message_sort_col']; $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order']; - } +} // fetch message headers @@ -48,22 +46,20 @@ $unseen = $IMAP->messagecount($mbox_name, 'UNSEEN', !empty($_GET['_refresh']) ? // update message count display $pages = ceil($count/$IMAP->page_size); -$commands = sprintf("this.set_env('messagecount', %d);\n", $count); -$commands .= sprintf("this.set_env('pagecount', %d);\n", $pages); -$commands .= sprintf("this.set_rowcount('%s');\n", rcmail_get_messagecount_text($count)); +$OUTPUT->set_env('messagecount', $count); +$OUTPUT->set_env('pagecount', $pages); +$OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count)); // update mailboxlist -$mbox_name = $IMAP->get_mailbox_name(); -$commands .= sprintf("this.set_unread_count('%s', %d);\n", addslashes($mbox_name), $unseen); +$OUTPUT->command('set_unread_count', $IMAP->get_mailbox_name(), $unseen); // add message rows if (isset($a_headers) && count($a_headers)) - $commands .= rcmail_js_message_list($a_headers); + rcmail_js_message_list($a_headers); // send response -rcube_remote_response($commands); +$OUTPUT->send(); -exit; ?>
\ No newline at end of file diff --git a/program/steps/mail/mark.inc b/program/steps/mail/mark.inc index 780bf5c6e..0dd781e08 100644 --- a/program/steps/mail/mark.inc +++ b/program/steps/mail/mark.inc @@ -4,7 +4,7 @@ | program/steps/mail/mark.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: | @@ -18,24 +18,24 @@ */ -$REMOTE_REQUEST = TRUE; - -$a_flags_map = array('undelete' => 'UNDELETED', - 'delete' => 'DELETED', - 'read' => 'SEEN', - 'unread' => 'UNSEEN'); +$a_flags_map = array( + 'undelete' => 'UNDELETED', + 'delete' => 'DELETED', + 'read' => 'SEEN', + 'unread' => 'UNSEEN'); if (($uids = get_input_value('_uid', RCUBE_INPUT_GET)) && ($flag = get_input_value('_flag', RCUBE_INPUT_GET))) - { +{ $flag = $a_flags_map[$flag] ? $a_flags_map[$flag] : strtoupper($flag); $marked = $IMAP->set_flag($uids, $flag); + if ($marked != -1) - { + { $mbox_name = $IMAP->get_mailbox_name(); - $commands = sprintf("this.set_unread_count('%s', %d);\n", $mbox_name, $IMAP->messagecount($mbox_name, 'UNSEEN')); - rcube_remote_response($commands); - } + $OUTPUT->command('set_unread_count', $mbox_name, $IMAP->messagecount($mbox_name, 'UNSEEN')); + $OUTPUT->send(); } +} exit; ?>
\ No newline at end of file diff --git a/program/steps/mail/move_del.inc b/program/steps/mail/move_del.inc index 8d31e3aa5..fb8a0af4c 100644 --- a/program/steps/mail/move_del.inc +++ b/program/steps/mail/move_del.inc @@ -5,7 +5,7 @@ | program/steps/mail/move_del.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,46 +19,42 @@ */ -$REMOTE_REQUEST = TRUE; - // move messages if ($_action=='moveto' && !empty($_GET['_uid']) && !empty($_GET['_target_mbox'])) - { +{ $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_GET)))); $target = get_input_value('_target_mbox', RCUBE_INPUT_GET); $moved = $IMAP->move_message($uids, $target, get_input_value('_mbox', RCUBE_INPUT_GET)); if (!$moved) - { + { // send error message - $commands = "this.list_mailbox();\n"; - $commands .= show_message('errormoving', 'error'); - rcube_remote_response($commands); + $OUTPUT->command('list_mailbox'); + $OUTPUT->show_message('errormoving', 'error'); + $OUTPUT->send(); exit; - } } +} // delete messages else if ($_action=='delete' && !empty($_GET['_uid'])) - { +{ $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_GET)))); $del = $IMAP->delete_message($uids, get_input_value('_mbox', RCUBE_INPUT_GET)); if (!$del) - { + { // send error message - $commands = "this.list_mailbox();\n"; - $commands .= show_message('errordeleting', 'error'); - rcube_remote_response($commands); + $OUTPUT->command('list_mailbox'); + $OUTPUT->show_message('errordeleting', 'error'); + $OUTPUT->send(); exit; - } } +} // unknown action or missing query param else - { exit; - } // refresh saved seach set after moving some messages if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) @@ -68,34 +64,33 @@ if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->se // update message count display $msg_count = $IMAP->messagecount(); $pages = ceil($msg_count / $IMAP->page_size); -$commands = sprintf("this.set_rowcount('%s');\n", rcmail_get_messagecount_text($msg_count)); -$commands .= sprintf("this.set_env('pagecount', %d);\n", $pages); +$OUTPUT->set_env('pagecount', $pages); +$OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count)); // update mailboxlist $mbox = $IMAP->get_mailbox_name(); -$commands .= sprintf("this.set_unread_count('%s', %d);\n", $mbox, $IMAP->messagecount($mbox, 'UNSEEN')); +$OUTPUT->command('set_unread_count', $mbox, $IMAP->messagecount($mbox, 'UNSEEN')); if ($_action=='moveto' && $target) - $commands .= sprintf("this.set_unread_count('%s', %d);\n", $target, $IMAP->messagecount($target, 'UNSEEN')); + $OUTPUT->command('set_unread_count', $target, $IMAP->messagecount($target, 'UNSEEN')); -$commands .= sprintf("this.set_quota('%s');\n", $IMAP->get_quota()); +$OUTPUT->command('set_quota', $IMAP->get_quota()); // add new rows from next page (if any) if ($_GET['_from']!='show' && $pages>1 && $IMAP->list_page < $pages) - { +{ $sort_col = isset($_SESSION['sort_col']) ? $_SESSION['sort_col'] : $CONFIG['message_sort_col']; $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order']; $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order); $a_headers = array_slice($a_headers, -$count, $count); - $commands .= rcmail_js_message_list($a_headers); - } + rcmail_js_message_list($a_headers); +} // send response -rcube_remote_response($commands); +$OUTPUT->send(); -exit; ?> diff --git a/program/steps/mail/quotadisplay.inc b/program/steps/mail/quotadisplay.inc index c96a7a7ee..accecdb91 100644 --- a/program/steps/mail/quotadisplay.inc +++ b/program/steps/mail/quotadisplay.inc @@ -22,8 +22,7 @@ $display = isset($_GET['_display']) ? $_GET['_display'] : 'text'; $id = isset($_GET['_id']) ? $_GET['_id'] : 'rcmquotadisplay'; $quota = rcmail_quota_content($display); -$command = sprintf("this.gui_objects.%s.innerHTML = '%s';\n", $id, $quota); -rcube_remote_response($command); +$OUTPUT->remote_response(sprintf("this.gui_objects.%s.innerHTML = '%s';\n", $id, $quota)); exit; ?> diff --git a/program/steps/mail/quotaimg.inc b/program/steps/mail/quotaimg.inc deleted file mode 100644 index 643ae1c55..000000000 --- a/program/steps/mail/quotaimg.inc +++ /dev/null @@ -1,172 +0,0 @@ -<?php - -/* - +-----------------------------------------------------------------------+ - | program/steps/mail/quotaimg.inc | - | | - | This file is part of the RoundCube Webmail client | - | Copyright (C) 2005, RoundCube Dev. - Switzerland | - | Licensed under the GNU GPL | - | | - | PURPOSE: | - | Create a GIF image showing the mailbox quot as bar | - | | - +-----------------------------------------------------------------------+ - | Author: Brett Patterson <brett2@umbc.edu> | - +-----------------------------------------------------------------------+ - - $Id: $ - -*/ - -$used = ((isset($_GET['u']) && !empty($_GET['u'])) || $_GET['u']=='0')?(int)$_GET['u']:'??'; -$quota = ((isset($_GET['q']) && !empty($_GET['q'])) || $_GET['q']=='0')?(int)$_GET['q']:'??'; -$width = empty($_GET['w']) ? 100 : (int)$_GET['w']; -$height = empty($_GET['h']) ? 14 : (int)$_GET['h']; - -function genQuota($used, $total, $width, $height) -{ - /** - * Quota Display - * - * Modify the following few elements to change the display of the image. - * Modifiable attributes are: - * bool border :: Defines whether you want to show a border around it or not. - * bool unknown :: Leave default; Defines whether quota is "unknown" - * - * int height :: Defines height of the image - * int width :: Defines width of the image - * int font :: Changes the font size & font used in the GD library. - * Available values are from 1 to 5. - * int padding :: Changes the offset (in pixels) from the top of the image to - * where the top of the text will be aligned. User greater than - * 0 to ensure text is off the border. - * array limit :: Holds the integer values of in an associative array as to what - * defines the upper and lower levels for quota display. - * High - Quota is nearing capacity. - * Mid - Quota is around the middle - * Low - Currently not used. - * array color :: An associative array of strings of comma separated values (R,G,B) - * for use in color creation. Define the RGB values you'd like to - * use. A list of colors (and their RGB values) can be found here: - * http://www.december.com/html/spec/colorcodes.html - **/ - - $unknown = false; - $border = 0; - - $font = 2; - $padding = 0; - - $limit['high'] = 70; - $limit['mid'] = 45; - $limit['low'] = 0; - - // Fill Colors - $color['fill']['high'] = '215, 13, 13'; // Near quota fill color - $color['fill']['mid'] = '126, 192, 238';// Mid-area of quota fill color - $color['fill']['low'] = '147, 225, 100'; // Far from quota fill color - - // Background colors - $color['bg']['OL'] = '215, 13, 13'; // Over limit bbackground - $color['bg']['Unknown'] = '238, 99, 99';// Unknown background - $color['bg']['quota'] = '255, 255, 255';// Normal quota background - - // Misc. Colors - $color['border'] = '0, 0, 0'; - $color['text'] = '102, 102, 102'; - - - /**************************** - ***** DO NOT EDIT BELOW HERE ***** - ****************************/ - - if(ereg("^[^0-9?]*$", $used) || ereg("^[^0-9?]*$", $total)) - { - return false; - } - if(strpos($used, '?')!==false || strpos($total, '?')!==false && $used != 0) - { - $unknown = true; - } - - $im = imagecreate($width, $height); - - if($border) - { - list($r, $g, $b) = explode(',', $color['border']); - $borderc = imagecolorallocate($im, $r, $g, $b); - imageline($im, 0, 0, $width, 0, $borderc); - imageline($im, 0, $height-$border, 0, 0, $borderc); - imageline($im, $width-1, 0, $width-$border, $height, $borderc); - imageline($im, $width, $height-$border, 0, $height-$border, $borderc); - } - - list($r, $g, $b) = explode(',', $color['text']); - $text = imagecolorallocate($im, $r, $g, $b); - - if($unknown) - { - list($r, $g, $b) = explode(',', $color['bg']['Unknown']); - $background = imagecolorallocate($im, $r, $g, $b); - imagefilledrectangle($im, 0, 0, $width, $height, $background); - - $string = 'Unknown'; - $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1; - imagestring($im, $font, $mid, $padding, $string, $text); - } - else if($used > $total) - { - list($r, $g, $b) = explode(',', $color['bg']['OL']); - $background = imagecolorallocate($im, $r, $g, $b); - imagefilledrectangle($im, 0, 0, $width, $height, $background); - - $string = 'Over Limit'; - $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1; - imagestring($im, $font, $mid, $padding, $string, $text); - } - else - { - list($r, $g, $b) = explode(',', $color['bg']['quota']); - $background = imagecolorallocate($im, $r, $b, $g); - imagefilledrectangle($im, 0, 0, $width, $height, $background); - - $quota = ($used==0)?0:(round($used/$total, 2)*100); - - if($quota >= $limit['high']) - { - list($r, $g, $b) = explode(',', $color['fill']['high']); - $fill = imagecolorallocate($im, $r, $g, $b); - } - elseif($quota >= $limit['mid']) - { - list($r, $g, $b) = explode(',', $color['fill']['mid']); - $fill = imagecolorallocate($im, $r, $g, $b); - } - else // if($quota >= $limit['low']) - { - list($r, $g, $b) = explode(',', $color['fill']['low']); - $fill = imagecolorallocate($im, $r, $g, $b); - } - - $quota_width = $quota / 100 * $width; - imagefilledrectangle($im, $border, 0, $quota, $height-2*$border, $fill); - - $string = $quota.'%'; - $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1; - imagestring($im, $font, $mid, $padding, $string, $text); // Print percent in black - } - - header('Content-Type: image/gif'); - header("Expires: ".gmdate("D, d M Y H:i:s", mktime()+86400)." GMT"); - header("Cache-Control: "); - header("Pragma: "); - - imagegif($im); - imagedestroy($im); -} - - -genQuota($used, $quota, $width, $height); -exit; -?>
\ No newline at end of file diff --git a/program/steps/mail/search.inc b/program/steps/mail/search.inc index c4b843b55..bef821b40 100644 --- a/program/steps/mail/search.inc +++ b/program/steps/mail/search.inc @@ -25,7 +25,7 @@ $_SESSION['page'] = 1; $imap_charset = 'UTF-8'; // get search string -$str = get_input_value('_search', RCUBE_INPUT_GET); +$str = get_input_value('_q', RCUBE_INPUT_GET); $mbox = get_input_value('_mbox', RCUBE_INPUT_GET); $search_request = md5($mbox.$str); @@ -71,16 +71,14 @@ else // execute IMAP search $result = $IMAP->search($mbox, $subject, $search, $imap_charset); - -$commands = ''; $count = 0; // Make sure our $result is legit.. if (is_array($result) && $result[0] != '') - { +{ // Get the headers $result_h = $IMAP->list_header_set($mbox, $result, 1, $_SESSION['sort_col'], $_SESSION['sort_order']); - $count = count($result); + $count = count($result_h); // save search results in session if (!is_array($_SESSION['search'])) @@ -88,24 +86,24 @@ if (is_array($result) && $result[0] != '') // Make sure we got the headers if ($result_h != NULL) - { + { $_SESSION['search'][$search_request] = $IMAP->get_search_set(); - $commands = rcmail_js_message_list($result_h); - $commands .= show_message('searchsuccessful', 'confirmation', array('nr' => $count)); - } + rcmail_js_message_list($result_h); + $OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $count)); } +} else - { - $commands = show_message('searchnomatch', 'warning'); +{ + $OUTPUT->show_message('searchnomatch', 'warning'); $search_request = -1; - } +} // update message count display $pages = ceil($count/$IMAP->page_size); -$commands .= sprintf("\nthis.set_env('search_request', '%s')\n", $search_request); -$commands .= sprintf("this.set_env('messagecount', %d);\n", $count); -$commands .= sprintf("this.set_env('pagecount', %d);\n", $pages); -$commands .= sprintf("this.set_rowcount('%s');\n", rcmail_get_messagecount_text($count, 1)); -rcube_remote_response($commands); +$OUTPUT->set_env('search_request', $search_request); +$OUTPUT->set_env('messagecount', $count); +$OUTPUT->set_env('pagecount', $pages); +$OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count, 1)); +$OUTPUT->send(); ?>
\ No newline at end of file diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc index 4a65ee390..bc454b309 100644 --- a/program/steps/mail/sendmail.inc +++ b/program/steps/mail/sendmail.inc @@ -5,7 +5,7 @@ | program/steps/mail/sendmail.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: | @@ -39,7 +39,7 @@ if (!isset($_SESSION['compose']['id'])) function rcmail_get_identity($id) { - global $DB, $CHARSET, $OUTPUT; + global $DB, $OUTPUT; // get identity record $sql_result = $DB->query("SELECT *, email AS mailto @@ -55,7 +55,7 @@ function rcmail_get_identity($id) $out = $sql_arr; $name = strpos($sql_arr['name'], ",") ? '"'.$sql_arr['name'].'"' : $sql_arr['name']; $out['string'] = sprintf('%s <%s>', - rcube_charset_convert($name, $CHARSET, $OUTPUT->get_charset()), + rcube_charset_convert($name, RCMAIL_CHARSET, $OUTPUT->get_charset()), $sql_arr['mailto']); return $out; } @@ -110,9 +110,8 @@ function rcmail_attach_emoticons(&$mime_message) // add the image to the MIME message $img_file = $INSTALL_PATH . '/' . $searchstr . $image_name; if(! $mime_message->addHTMLImage($img_file, 'image/gif', '', true, '_' . $image_name)) - { - show_message("emoticonerror", 'error'); - } + $OUTPUT->show_message("emoticonerror", 'error'); + array_push($included_images, $image_name); } @@ -132,7 +131,7 @@ $savedraft = !empty($_POST['_draft']) ? TRUE : FALSE; // remove all scripts and act as called in frame $OUTPUT->reset(); -$_framed = TRUE; +$OUTPUT->framed = TRUE; /****** check submission and compose message ********/ @@ -140,8 +139,8 @@ $_framed = TRUE; if (!$savedraft && empty($_POST['_to']) && empty($_POST['_subject']) && $_POST['_message']) { - show_message("sendingfailed", 'error'); - rcube_iframe_response(); + $OUTPUT->show_message("sendingfailed", 'error'); + $OUTPUT->send('iframe'); return; } @@ -168,7 +167,7 @@ if (empty($identity_arr['string'])) // compose headers array $headers = array('Date' => date('D, j M Y H:i:s O'), - 'From' => rcube_charset_convert($identity_arr['string'], $CHARSET, $message_charset), + 'From' => rcube_charset_convert($identity_arr['string'], RCMAIL_CHARSET, $message_charset), 'To' => $mailto); // additional recipients @@ -304,7 +303,7 @@ if ($MBSTRING && function_exists("mb_encode_mimeheader")) { mb_internal_encoding($message_charset); $mb_subject = mb_encode_mimeheader($headers['Subject'], $message_charset, 'Q'); - mb_internal_encoding($CHARSET); + mb_internal_encoding(RCMAIL_CHARSET); } // Begin SMTP Delivery Block @@ -334,13 +333,8 @@ if (!$savedraft) { // log error if (!$sent) - { - raise_error(array('code' => 800, - 'type' => 'smtp', - 'line' => __LINE__, - 'file' => __FILE__, + raise_error(array('code' => 800, 'type' => 'smtp', 'line' => __LINE__, 'file' => __FILE__, 'message' => "SMTP error: ".join("\n", $smtp_response)), TRUE, FALSE); - } } // send mail using PHP's mail() function @@ -368,8 +362,8 @@ if (!$savedraft) { // return to compose page if sending failed if (!$sent) { - show_message("sendingfailed", 'error'); - rcube_iframe_response(); + $OUTPUT->show_message("sendingfailed", 'error'); + $OUTPUT->send('iframe'); return; } @@ -409,13 +403,11 @@ if ($CONFIG[$store_target]) // raise error if saving failed if (!$saved) { - raise_error(array('code' => 800, - 'type' => 'imap', - 'file' => __FILE__, + raise_error(array('code' => 800, 'type' => 'imap', 'file' => __FILE__, 'message' => "Could not save message in $CONFIG[$store_target]"), TRUE, FALSE); - show_message('errorsaving', 'error'); - rcube_iframe_response($errorout); + $OUTPUT->show_message('errorsaving', 'error'); + $OUTPUT->send('iframe'); } if ($olddraftmessageid) @@ -426,41 +418,36 @@ if ($CONFIG[$store_target]) // raise error if deletion of old draft failed if (!$deleted) - raise_error(array('code' => 800, - 'type' => 'imap', - 'file' => __FILE__, + raise_error(array('code' => 800, 'type' => 'imap', 'file' => __FILE__, 'message' => "Could not delete message from ".$CONFIG['drafts_mbox']), TRUE, FALSE); } } if ($savedraft) { - // clear the "saving message" busy status, and display success - show_message('messagesaved', 'confirmation'); - - // update "_draft_saveid" on the page, which is used to delete a previous draft - $frameout = "var foundid = parent.rcube_find_object('_draft_saveid', parent.document);\n"; - $frameout .= sprintf("foundid.value = '%s';\n", str_replace(array('<','>'), "", $message_id)); + // display success + $OUTPUT->show_message('messagesaved', 'confirmation'); - // update the "cmp_hash" to prevent "Unsaved changes" warning - $frameout .= sprintf("parent.%s.cmp_hash = parent.%s.compose_field_hash();\n", $JS_OBJECT_NAME, $JS_OBJECT_NAME); + // update "_draft_saveid" and the "cmp_hash" to prevent "Unsaved changes" warning + $OUTPUT->command('set_draft_id', str_replace(array('<','>'), "", $message_id)); + $OUTPUT->command('compose_field_hash', true); // start the auto-save timer again - $frameout .= sprintf("parent.%s.auto_save_start();", $JS_OBJECT_NAME); + $OUTPUT->command('auto_save_start'); - // send html page with JS calls as response - rcube_iframe_response($frameout); + $OUTPUT->send('iframe'); } else { if ($CONFIG['smtp_log']) { - $log_entry = sprintf("[%s] User: %d on %s; Message for %s; %s\n", - date("d-M-Y H:i:s O", mktime()), - $_SESSION['user_id'], - $_SERVER['REMOTE_ADDR'], - $mailto, - !empty($smtp_response) ? join('; ', $smtp_response) : ''); + $log_entry = sprintf( + "[%s] User: %d on %s; Message for %s; %s\n", + date("d-M-Y H:i:s O", mktime()), + $_SESSION['user_id'], + $_SERVER['REMOTE_ADDR'], + $mailto, + !empty($smtp_response) ? join('; ', $smtp_response) : ''); if ($fp = @fopen($CONFIG['log_dir'].'/sendmail', 'a')) { @@ -470,8 +457,8 @@ else } rcmail_compose_cleanup(); - rcube_iframe_response(sprintf("parent.$JS_OBJECT_NAME.sent_successfully('%s');", - JQ(rcube_label('messagesent')))); + $OUTPUT->command('sent_successfully', rcube_label('messagesent')); + $OUTPUT->send('iframe'); } diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc index 19e6e56a9..6c247aea9 100644 --- a/program/steps/mail/show.inc +++ b/program/steps/mail/show.inc @@ -5,7 +5,7 @@ | program/steps/mail/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: | @@ -32,7 +32,7 @@ if ($_GET['_uid']) // go back to list if message not found (wrong UID) if (!$MESSAGE['headers']) { - show_message('messageopenerror', 'error'); + $OUTPUT->show_message('messageopenerror', 'error'); if ($_action=='preview' && template_exists('messagepreview')) parse_template('messagepreview'); else @@ -51,8 +51,8 @@ if ($_GET['_uid']) else send_modified_header($_SESSION['login_time'], $etag); - - $MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['headers']->subject); + $MESSAGE['subject'] = rcube_imap::decode_mime_string($MESSAGE['headers']->subject, $MESSAGE['headers']->charset); + $OUTPUT->set_pagetitle($MESSAGE['subject']); if ($MESSAGE['structure'] = $IMAP->get_structure($MESSAGE['UID'])) list($MESSAGE['parts'], $MESSAGE['attachments']) = rcmail_parse_message( @@ -70,8 +70,8 @@ if ($_GET['_uid']) $IMAP->set_flag($MESSAGE['UID'], 'SEEN'); // give message uid to the client - $javascript = sprintf("%s.set_env('uid', '%s');\n", $JS_OBJECT_NAME, $MESSAGE['UID']); - $javascript .= sprintf("%s.set_env('safemode', '%b');", $JS_OBJECT_NAME, $_GET['_safe']); + $OUTPUT->set_env('uid', $MESSAGE['UID']); + $OUTPUT->set_env('safemode', (bool)$_GET['_safe']); $next = $prev = -1; // get previous, first, next and last message UID @@ -99,22 +99,20 @@ if ($_GET['_uid']) } if ($prev > 0) - $javascript .= sprintf("\n%s.set_env('prev_uid', '%s');", $JS_OBJECT_NAME, $prev); + $OUTPUT->set_env('prev_uid', $prev); if ($first >0) - $javascript .= sprintf("\n%s.set_env('first_uid', '%s');", $JS_OBJECT_NAME, $first); + $OUTPUT->set_env('first_uid', $first); if ($next > 0) - $javascript .= sprintf("\n%s.set_env('next_uid', '%s');", $JS_OBJECT_NAME, $next); + $OUTPUT->set_env('next_uid', $next); if ($last >0) - $javascript .= sprintf("\n%s.set_env('last_uid', '%s');", $JS_OBJECT_NAME, $last); - - $OUTPUT->add_script($javascript); + $OUTPUT->set_env('last_uid', $last); } function rcmail_message_attachments($attrib) { - global $CONFIG, $OUTPUT, $PRINT_MODE, $MESSAGE, $GET_URL, $JS_OBJECT_NAME; + global $CONFIG, $OUTPUT, $PRINT_MODE, $MESSAGE, $GET_URL; if (sizeof($MESSAGE['attachments'])) { @@ -132,7 +130,7 @@ function rcmail_message_attachments($attrib) $out .= sprintf('<li><a href="%s&_part=%s" onclick="return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)">%s</a></li>'."\n", htmlspecialchars($GET_URL), $attach_prop->mime_id, - $JS_OBJECT_NAME, + JS_OBJECT_NAME, $attach_prop->mime_id, $attach_prop->mimetype, $attach_prop->filename); @@ -147,7 +145,7 @@ function rcmail_message_attachments($attrib) function rcmail_remote_objects_msg($attrib) { - global $CONFIG, $OUTPUT, $JS_OBJECT_NAME; + global $CONFIG, $OUTPUT; if (!$attrib['id']) $attrib['id'] = 'rcmremoteobjmsg'; @@ -158,16 +156,21 @@ function rcmail_remote_objects_msg($attrib) $out .= sprintf('%s <a href="#loadimages" onclick="%s.command(\'load-images\')">%s</a>', Q(rcube_label('blockedimages')), - $JS_OBJECT_NAME, + JS_OBJECT_NAME, Q(rcube_label('showimages'))); $out .= '</div>'; - $OUTPUT->add_script(sprintf("%s.gui_object('remoteobjectsmsg', '%s');", $JS_OBJECT_NAME, $attrib['id'])); + $OUTPUT->add_gui_object('remoteobjectsmsg', $attrib['id']); return $out; } +$OUTPUT->add_handlers(array( + 'messageattachments' => 'rcmail_message_attachments', + 'blockedobjects' => 'rcmail_remote_objects_msg')); + + if ($_action=='print' && template_exists('printmessage')) parse_template('printmessage'); else if ($_action=='preview' && template_exists('messagepreview')) diff --git a/program/steps/mail/upload.inc b/program/steps/mail/upload.inc index 06ed26591..a28c3e8e2 100644 --- a/program/steps/mail/upload.inc +++ b/program/steps/mail/upload.inc @@ -47,23 +47,22 @@ foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) 'path' => $tmpfname); if (is_file($CONFIG['skin_path'] . '/images/icons/remove-attachment.png')) - $button = sprintf('<img src="%s/images/icons/remove-attachment.png" alt="%s" border="0" style="padding-right:2px;vertical-align:middle" />', - $CONFIG['skin_path'], - Q(rcube_label('delete'))); + $button = sprintf( + '<img src="%s/images/icons/remove-attachment.png" alt="%s" border="0" style="padding-right:2px;vertical-align:middle" />', + $CONFIG['skin_path'], + Q(rcube_label('delete'))); else $button = Q(rcube_label('delete')); - $content = sprintf('<a href="#delete" onclick="return %s.command(\\\'remove-attachment\\\', \\\'rcmfile%d\\\', this)" title="%s">%s</a>%s', - $JS_OBJECT_NAME, - $id, - Q(rcube_label('delete')), - $button, - Q($_FILES['_attachments']['name'][$i])); - - $response .= sprintf('parent.%s.add2attachment_list(\'rcmfile%d\',\'%s\');', - $JS_OBJECT_NAME, - $id, - $content); + $content = sprintf( + '<a href="#delete" onclick="return %s.command(\'remove-attachment\', \'rcmfile%d\', this)" title="%s">%s</a>%s', + JS_OBJECT_NAME, + $id, + Q(rcube_label('delete')), + $button, + Q($_FILES['_attachments']['name'][$i])); + + $OUTPUT->command('add2attachment_list', "rcmfile$id", $content); } else // upload failed { @@ -73,18 +72,14 @@ foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) else $msg = rcube_label('fileuploaderror'); - $response = sprintf("parent.%s.display_message('%s', 'error');", $JS_OBJECT_NAME, JQ($msg)); + $OUTPUT->command('display_message', $msg, 'error'); } } // send html page with JS calls as response -$frameout = <<<EOF -$response -parent.$JS_OBJECT_NAME.show_attachment_form(false); -parent.$JS_OBJECT_NAME.auto_save_start(); -EOF; - -rcube_iframe_response($frameout); +$OUTPUT->command('show_attachment_form', false); +$OUTPUT->command('auto_save_start', false); +$OUTPUT->send('iframe'); ?> diff --git a/program/steps/settings/delete_identity.inc b/program/steps/settings/delete_identity.inc index 560a2b10b..3614a3e96 100644 --- a/program/steps/settings/delete_identity.inc +++ b/program/steps/settings/delete_identity.inc @@ -5,7 +5,7 @@ | program/steps/settings/delete_identity.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,32 +20,29 @@ */ if (($ids = get_input_value('_iid', RCUBE_INPUT_GET)) && preg_match('/^[0-9]+(,[0-9]+)*$/', $ids)) - { - $DB->query("UPDATE ".get_table_name('identities')." - SET del=1 - WHERE user_id=? - AND identity_id IN (".$ids.")", - $_SESSION['user_id']); +{ + $DB->query( + "UPDATE ".get_table_name('identities')." + SET del=1 + WHERE user_id=? + AND identity_id IN (".$ids.")", + $_SESSION['user_id']); $count = $DB->affected_rows(); if ($count) - { - $commands = show_message('deletedsuccessfully', 'confirmation'); - } + $OUTPUT->show_message('deletedsuccessfully', 'confirmation'); // send response - if ($REMOTE_REQUEST) - rcube_remote_response($commands); - } + if ($OUTPUT->ajax_call) + $OUTPUT->send(); +} -if ($REMOTE_REQUEST) +if ($OUTPUT->ajax_call) exit; // go to identities page -$_action = 'identities'; +rcmail_overwrite_action('identities'); -// overwrite action variable -$OUTPUT->add_script(sprintf("\n%s.set_env('action', '%s');", $JS_OBJECT_NAME, $_action)); ?> diff --git a/program/steps/settings/edit_identity.inc b/program/steps/settings/edit_identity.inc index 5fa531a11..51a0cd0a0 100644 --- a/program/steps/settings/edit_identity.inc +++ b/program/steps/settings/edit_identity.inc @@ -5,7 +5,7 @@ | program/steps/settings/edit_identity.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: | @@ -31,12 +31,12 @@ if (($_GET['_iid'] || $_POST['_iid']) && $_action=='edit-identity') $IDENTITY_RECORD = $DB->fetch_assoc(); if (is_array($IDENTITY_RECORD)) - $OUTPUT->add_script(sprintf("%s.set_env('iid', '%s');", $JS_OBJECT_NAME, $IDENTITY_RECORD['identity_id'])); - - $PAGE_TITLE = rcube_label('edititem'); + $OUTPUT->set_env('iid', $IDENTITY_RECORD['identity_id']); + + $OUTPUT->set_pagetitle(rcube_label('edititem')); } else - $PAGE_TITLE = rcube_label('newitem'); + $OUTPUT->set_pagetitle(rcube_label('newitem')); $OUTPUT->include_script('list.js'); @@ -44,7 +44,7 @@ $OUTPUT->include_script('list.js'); function rcube_identity_form($attrib) { - global $IDENTITY_RECORD, $JS_OBJECT_NAME, $OUTPUT; + global $IDENTITY_RECORD, $OUTPUT; $OUTPUT->include_script('tiny_mce/tiny_mce_src.js'); $OUTPUT->add_script("tinyMCE.init({ mode : 'specific_textareas'," . @@ -63,8 +63,7 @@ function rcube_identity_form($attrib) return rcube_label('notfound'); // add some labels to client - rcube_add_label('noemailwarning'); - rcube_add_label('nonamewarning'); + rcube_add_label('noemailwarning', 'nonamewarning'); list($form_start, $form_end) = get_form_tags($attrib, 'save-identity', array('name' => '_iid', 'value' => $IDENTITY_RECORD['identity_id'])); @@ -136,7 +135,7 @@ function rcube_identity_form($attrib) return $out; } - +$OUTPUT->add_handler('identityform', 'rcube_identity_form'); if ($_action=='add-identity' && template_exists('addidentity')) parse_template('addidentity'); diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc index e51f6838e..91212e174 100644 --- a/program/steps/settings/func.inc +++ b/program/steps/settings/func.inc @@ -5,7 +5,7 @@ | program/steps/settings/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: | @@ -26,7 +26,7 @@ $sql_result = $DB->query("SELECT username, mail_host FROM ".get_table_name('user $_SESSION['user_id']); if ($USER_DATA = $DB->fetch_assoc($sql_result)) - $PAGE_TITLE = sprintf('%s %s@%s', rcube_label('settingsfor'), $USER_DATA['username'], $USER_DATA['mail_host']); + $OUTPUT->set_pagetitle(sprintf('%s %s@%s', rcube_label('settingsfor'), $USER_DATA['username'], $USER_DATA['mail_host'])); @@ -202,7 +202,7 @@ function rcmail_user_prefs_form($attrib) function rcmail_identities_list($attrib) { - global $DB, $CONFIG, $OUTPUT, $JS_OBJECT_NAME; + global $DB, $CONFIG, $OUTPUT; // get contacts from DB @@ -224,8 +224,7 @@ function rcmail_identities_list($attrib) $out = rcube_table_output($attrib, $sql_result, $a_show_cols, 'identity_id'); // set client env - $javascript = sprintf("%s.gui_object('identitieslist', '%s');\n", $JS_OBJECT_NAME, $attrib['id']); - $OUTPUT->add_script($javascript); + $OUTPUT->add_gui_object('identitieslist', $attrib['id']); return $out; } @@ -235,7 +234,7 @@ function rcmail_identities_list($attrib) // similar function as in /steps/addressbook/edit.inc function get_form_tags($attrib, $action, $add_hidden=array()) { - global $OUTPUT, $JS_OBJECT_NAME, $EDIT_FORM, $SESS_HIDDEN_FIELD; + global $OUTPUT, $EDIT_FORM, $SESS_HIDDEN_FIELD; $form_start = ''; if (!strlen($EDIT_FORM)) @@ -258,7 +257,7 @@ function get_form_tags($attrib, $action, $add_hidden=array()) $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; @@ -266,4 +265,11 @@ function get_form_tags($attrib, $action, $add_hidden=array()) } +// register UI objects +$OUTPUT->add_handlers(array( + 'userprefs' => 'rcmail_user_prefs_form', + 'itentitieslist' => 'rcmail_identities_list' +)); + + ?>
\ No newline at end of file diff --git a/program/steps/settings/identities.inc b/program/steps/settings/identities.inc index caaa45342..9284e525d 100644 --- a/program/steps/settings/identities.inc +++ b/program/steps/settings/identities.inc @@ -5,7 +5,7 @@ | program/steps/settings/identities.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,7 +20,7 @@ */ if ($USER_DATA = $DB->fetch_assoc($sql_result)) - $PAGE_TITLE = sprintf('%s (%s@%s)', rcube_label('identities'), $USER_DATA['username'], $USER_DATA['mail_host']); + $OUTPUT->set_pagetitle(sprintf('%s (%s@%s)', rcube_label('identities'), $USER_DATA['username'], $USER_DATA['mail_host'])); $OUTPUT->include_script('list.js'); @@ -28,14 +28,14 @@ $OUTPUT->include_script('list.js'); // similar function as /steps/addressbook/func.inc::rcmail_contact_frame() function rcmail_identity_frame($attrib) { - global $OUTPUT, $JS_OBJECT_NAME; + global $OUTPUT; if (!$attrib['id']) $attrib['id'] = 'rcmIdentityFrame'; $attrib['name'] = $attrib['id']; - $OUTPUT->add_script(sprintf("%s.set_env('contentframe', '%s');", $JS_OBJECT_NAME, $attrib['name'])); + $OUTPUT->set_env('contentframe', $attrib['name']); $attrib_str = create_attrib_string($attrib, array('name', 'id', 'class', 'style', 'src', 'width', 'height', 'frameborder')); $out = '<iframe'. $attrib_str . '></iframe>'; @@ -43,7 +43,7 @@ function rcmail_identity_frame($attrib) return $out; } - +$OUTPUT->add_handler('identityframe', 'rcmail_identity_frame'); parse_template('identities'); ?>
\ No newline at end of file diff --git a/program/steps/settings/manage_folders.inc b/program/steps/settings/manage_folders.inc index 8dd898d26..7499fe3d4 100644 --- a/program/steps/settings/manage_folders.inc +++ b/program/steps/settings/manage_folders.inc @@ -5,7 +5,7 @@ | program/steps/settings/manage_folders.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: | @@ -29,8 +29,8 @@ if ($_action=='subscribe') if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_GET)) $IMAP->subscribe(array($mboxes)); - if ($REMOTE_REQUEST) - rcube_remote_response('// subscribed'); + if ($OUTPUT->ajax_call) + $OUTPUT->remote_response('// subscribed'); } // unsubscribe one or more mailboxes @@ -39,8 +39,8 @@ else if ($_action=='unsubscribe') if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_GET)) $IMAP->unsubscribe(array($mboxes)); - if ($REMOTE_REQUEST) - rcube_remote_response('// unsubscribed'); + if ($OUTPUT->ajax_call) + $OUTPUT->remote_response('// unsubscribed'); } // create a new mailbox @@ -49,47 +49,40 @@ else if ($_action=='create-folder') if (!empty($_GET['_name'])) $create = $IMAP->create_mailbox(trim(get_input_value('_name', RCUBE_INPUT_GET, FALSE, 'UTF-7')), TRUE); - if ($create && $REMOTE_REQUEST) + if ($create && $OUTPUT->ajax_call) { - $commands = sprintf("this.add_folder_row('%s','%s')", - JQ($create), - JQ(rcube_charset_convert($create, 'UTF-7'))); - rcube_remote_response($commands); + $OUTPUT->command('add_folder_row', $create, rcube_charset_convert($create, 'UTF-7')); + $OUTPUT->send(); } - else if (!$create && $REMOTE_REQUEST) + else if (!$create && $OUTPUT->ajax_call) { - $commands = show_message('errorsaving', 'error'); - rcube_remote_response($commands); + $OUTPUT->show_message('errorsaving', 'error'); + $OUTPUT->remote_response(); } else if (!$create) - show_message('errorsaving', 'error'); + $OUTPUT->show_message('errorsaving', 'error'); } // rename a mailbox else if ($_action=='rename-folder') { if (!empty($_GET['_folder_oldname']) && !empty($_GET['_folder_newname'])) - $rename = $IMAP->rename_mailbox(get_input_value('_folder_oldname', RCUBE_INPUT_GET), trim(get_input_value('_folder_newname', RCUBE_INPUT_GET, FALSE, 'UTF-7'))); + $rename = $IMAP->rename_mailbox(($oldname = get_input_value('_folder_oldname', RCUBE_INPUT_GET)), trim(get_input_value('_folder_newname', RCUBE_INPUT_GET, FALSE, 'UTF-7'))); - if ($rename && $REMOTE_REQUEST) + if ($rename && $OUTPUT->ajax_call) { - $commands = sprintf("this.replace_folder_row('%s','%s','%s');\n", - JQ(get_input_value('_folder_oldname', RCUBE_INPUT_GET)), - JQ($rename), - JQ(rcube_charset_convert($rename, 'UTF-7'))); - - $commands .= "this.reset_folder_rename();\n"; - - rcube_remote_response($commands); + $OUTPUT->command('replace_folder_row', $oldname, $rename, rcube_charset_convert($rename, 'UTF-7')); + $OUTPUT->command('reset_folder_rename'); + $OUTPUT->send(); } - else if (!$rename && $REMOTE_REQUEST) + else if (!$rename && $OUTPUT->ajax_call) { - $commands = "this.reset_folder_rename();\n"; - $commands .= show_message('errorsaving', 'error'); - rcube_remote_response($commands); + $OUTPUT->command('reset_folder_rename'); + $OUTPUT->show_message('errorsaving', 'error'); + $OUTPUT->send(); } else if (!$rename) - show_message('errorsaving', 'error'); + $OUTPUT->show_message('errorsaving', 'error'); } // delete an existing IMAP mailbox @@ -98,16 +91,16 @@ else if ($_action=='delete-folder') if ($mboxes = get_input_value('_mboxes', RCUBE_INPUT_GET)) $deleted = $IMAP->delete_mailbox(array($mboxes)); - if ($REMOTE_REQUEST && $deleted) + if ($OUTPUT->ajax_call && $deleted) { - $commands = sprintf("this.remove_folder_row('%s');\n", JQ(get_input_value('_mboxes', RCUBE_INPUT_GET))); - $commands .= show_message('folderdeleted', 'confirmation'); - rcube_remote_response($commands); + $OUTPUT->command('remove_folder_row', get_input_value('_mboxes', RCUBE_INPUT_GET)); + $OUTPUT->show_message('folderdeleted', 'confirmation'); + $OUTPUT->send(); } - else if ($REMOTE_REQUEST) + else if ($OUTPUT->ajax_call) { - $commands = show_message('errorsaving', 'error'); - rcube_remote_response($commands); + $OUTPUT->show_message('errorsaving', 'error'); + $OUTPUT->send(); } } @@ -116,7 +109,7 @@ else if ($_action=='delete-folder') // build table with all folders listed by server function rcube_subscription_form($attrib) { - global $IMAP, $CONFIG, $OUTPUT, $JS_OBJECT_NAME; + global $IMAP, $CONFIG, $OUTPUT; list($form_start, $form_end) = get_form_tags($attrib, 'folders'); unset($attrib['form']); @@ -147,7 +140,7 @@ function rcube_subscription_form($attrib) $a_subscribed = $IMAP->list_mailboxes(); $a_js_folders = array(); - $checkbox_subscribe = new checkbox(array('name' => '_subscribed[]', 'onclick' => "$JS_OBJECT_NAME.command(this.checked?'subscribe':'unsubscribe',this.value)")); + $checkbox_subscribe = new checkbox(array('name' => '_subscribed[]', 'onclick' => JS_OBJECT_NAME.".command(this.checked?'subscribe':'unsubscribe',this.value)")); if (!empty($attrib['deleteicon'])) $del_button = sprintf('<img src="%s%s" alt="%s" border="0" />', $CONFIG['skin_path'], $attrib['deleteicon'], rcube_label('delete')); @@ -166,11 +159,10 @@ function rcube_subscription_form($attrib) $protected = ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders'])); $zebra_class = $i%2 ? 'even' : 'odd'; $folder_js = JQ($folder); - $folder_js_enc = JQ(rcube_charset_convert($folder, 'UTF-7')); $folder_html = $CONFIG['protect_default_folders'] && in_array($folder, $CONFIG['default_imap_folders']) ? rcube_label(strtolower($folder)) : rcube_charset_convert($folder, 'UTF-7'); if (!$protected) - $a_js_folders['rcmrow'.($i+1)] = array($folder_js, $folder_js_enc); + $a_js_folders['rcmrow'.($i+1)] = array($folder, rcube_charset_convert($folder, 'UTF-7')); $out .= sprintf('<tr id="rcmrow%d" class="%s"><td>%s</td>', $i+1, @@ -186,11 +178,11 @@ function rcube_subscription_form($attrib) if (!$protected) $out .= sprintf('<td><a href="#rename" onclick="%s.command(\'rename-folder\',\'%s\')" title="%s">%s</a>'. '<td><a href="#delete" onclick="%s.command(\'delete-folder\',\'%s\')" title="%s">%s</a></td>', - $JS_OBJECT_NAME, + JS_OBJECT_NAME, $folder_js, rcube_label('renamefolder'), $edit_button, - $JS_OBJECT_NAME, + JS_OBJECT_NAME, $folder_js, rcube_label('deletefolder'), $del_button); @@ -203,10 +195,8 @@ function rcube_subscription_form($attrib) $out .= "</tbody>\n</table>"; $out .= "\n$form_end"; - - $javascript = sprintf("%s.gui_object('subscriptionlist', '%s');\n", $JS_OBJECT_NAME, $attrib['id']); - $javascript .= sprintf("%s.set_env('subscriptionrows', %s);", $JS_OBJECT_NAME, array2js($a_js_folders)); - $OUTPUT->add_script($javascript); + $OUTPUT->add_gui_object('subscriptionlist', $attrib['id']); + $OUTPUT->set_env('subscriptionrows', $a_js_folders); return $out; } @@ -214,8 +204,6 @@ function rcube_subscription_form($attrib) function rcube_create_folder_form($attrib) { - global $JS_OBJECT_NAME; - list($form_start, $form_end) = get_form_tags($attrib, 'create-folder'); unset($attrib['form']); @@ -230,7 +218,7 @@ function rcube_create_folder_form($attrib) { $button = new input_field(array('type' => 'button', 'value' => rcube_label('create'), - 'onclick' => "$JS_OBJECT_NAME.command('create-folder',this.form)")); + 'onclick' => JS_OBJECT_NAME.".command('create-folder',this.form)")); $out .= $button->show(); } @@ -241,7 +229,7 @@ function rcube_create_folder_form($attrib) function rcube_rename_folder_form($attrib) { - global $CONFIG, $IMAP, $JS_OBJECT_NAME; + global $CONFIG, $IMAP; list($form_start, $form_end) = get_form_tags($attrib, 'rename-folder'); unset($attrib['form']); @@ -270,7 +258,7 @@ function rcube_rename_folder_form($attrib) { $button = new input_field(array('type' => 'button', 'value' => rcube_label('rename'), - 'onclick' => "$JS_OBJECT_NAME.command('rename-folder',this.form)")); + 'onclick' => JS_OBJECT_NAME.".command('rename-folder',this.form)")); $out .= $button->show(); } @@ -280,9 +268,15 @@ function rcube_rename_folder_form($attrib) } +// register UI objects +$OUTPUT->add_handlers(array( + 'foldersubscription' => 'rcube_subscription_form', + 'createfolder' => 'rcube_create_folder_form', + 'renamefolder' => 'rcube_rename_folder_form' +)); + // add some labels to client rcube_add_label('deletefolderconfirm'); - -parse_template('managefolders'); +$OUTPUT->send('managefolders'); ?> diff --git a/program/steps/settings/save_identity.inc b/program/steps/settings/save_identity.inc index ce1c6f6b4..8079b589a 100644 --- a/program/steps/settings/save_identity.inc +++ b/program/steps/settings/save_identity.inc @@ -27,7 +27,7 @@ $updated = $default_id = false; // check input if (empty($_POST['_name']) || empty($_POST['_email'])) { - show_message('formincomplete', 'warning'); + $OUTPUT->show_message('formincomplete', 'warning'); rcmail_overwrite_action('edit-identitiy'); return; } @@ -72,7 +72,7 @@ if ($_POST['_iid']) if ($updated) { - show_message('successfullysaved', 'confirmation'); + $OUTPUT->show_message('successfullysaved', 'confirmation'); if (!empty($_POST['_standard'])) $default_id = get_input_value('_iid', RCUBE_INPUT_POST); @@ -86,7 +86,7 @@ if ($_POST['_iid']) else if ($DB->is_error()) { // show error message - show_message('errorsaving', 'error'); + $OUTPUT->show_message('errorsaving', 'error'); rcmail_overwrite_action('edit-identitiy'); return; } @@ -133,7 +133,7 @@ else else { // show error message - show_message('errorsaving', 'error'); + $OUTPUT->show_message('errorsaving', 'error'); rcmail_overwrite_action('edit-identity'); return; } @@ -152,6 +152,6 @@ if ($default_id) $default_id); // go to next step -rcmail_overwrite_action($_POST['_framed'] ? 'edit-identity' : 'identities'); +rcmail_overwrite_action($_framed ? 'edit-identity' : 'identities'); ?>
\ No newline at end of file diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc index fd254f9f3..4945a4fff 100644 --- a/program/steps/settings/save_prefs.inc +++ b/program/steps/settings/save_prefs.inc @@ -5,7 +5,7 @@ | program/steps/settings/save_prefs.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: | @@ -43,13 +43,10 @@ if (isset($_POST['_language'])) } if (rcmail_save_user_prefs($a_user_prefs)) - show_message('successfullysaved', 'confirmation'); + $OUTPUT->show_message('successfullysaved', 'confirmation'); // go to next step -$_action = 'preferences'; - -// overwrite action variable -$OUTPUT->add_script(sprintf("\n%s.set_env('action', '%s');", $JS_OBJECT_NAME, $_action)); +rcmail_overwrite_action('preferences'); ?> |