diff options
author | thomascube <thomas@roundcube.net> | 2007-12-10 15:27:19 +0000 |
---|---|---|
committer | thomascube <thomas@roundcube.net> | 2007-12-10 15:27:19 +0000 |
commit | fba1f5ab813f2eb4bedc5d9c4a75e77bbaa90131 (patch) | |
tree | cebde4edb06ac3a87eb2306b0c0125610a1bd5ce /program/steps/settings | |
parent | d39eecad6db1caee97624b80634587d98a75e701 (diff) |
New class rcube_user + send message disposition notification
Diffstat (limited to 'program/steps/settings')
-rw-r--r-- | program/steps/settings/delete_identity.inc | 11 | ||||
-rw-r--r-- | program/steps/settings/edit_identity.inc | 9 | ||||
-rw-r--r-- | program/steps/settings/func.inc | 24 | ||||
-rw-r--r-- | program/steps/settings/save_identity.inc | 107 | ||||
-rw-r--r-- | program/steps/settings/save_prefs.inc | 7 |
5 files changed, 40 insertions, 118 deletions
diff --git a/program/steps/settings/delete_identity.inc b/program/steps/settings/delete_identity.inc index 3614a3e96..06fdd94f4 100644 --- a/program/steps/settings/delete_identity.inc +++ b/program/steps/settings/delete_identity.inc @@ -21,15 +21,8 @@ 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']); - - $count = $DB->affected_rows(); - if ($count) + + if ($USER->delete_identity($ids)) $OUTPUT->show_message('deletedsuccessfully', 'confirmation'); // send response diff --git a/program/steps/settings/edit_identity.inc b/program/steps/settings/edit_identity.inc index 51a0cd0a0..4d89f7cbc 100644 --- a/program/steps/settings/edit_identity.inc +++ b/program/steps/settings/edit_identity.inc @@ -21,14 +21,7 @@ if (($_GET['_iid'] || $_POST['_iid']) && $_action=='edit-identity') { - $DB->query("SELECT * FROM ".get_table_name('identities')." - WHERE identity_id=? - AND user_id=? - AND del<>1", - get_input_value('_iid', RCUBE_INPUT_GPC), - $_SESSION['user_id']); - - $IDENTITY_RECORD = $DB->fetch_assoc(); + $IDENTITY_RECORD = $USER->get_identity(get_input_value('_iid', RCUBE_INPUT_GPC)); if (is_array($IDENTITY_RECORD)) $OUTPUT->set_env('iid', $IDENTITY_RECORD['identity_id']); diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc index ecdbcbd76..e63f01620 100644 --- a/program/steps/settings/func.inc +++ b/program/steps/settings/func.inc @@ -20,15 +20,8 @@ */ -// get user record -$sql_result = $DB->query("SELECT username, mail_host FROM ".get_table_name('users')." - WHERE user_id=?", - $_SESSION['user_id']); - -if ($USER_DATA = $DB->fetch_assoc($sql_result)) -{ - $OUTPUT->set_pagetitle(rcube_label('settingsfor') . " ". $USER_DATA['username'] . (!strpos($USER_DATA['username'], '@') ? '@'.$USER_DATA['mail_host'] : '')); -} +if ($USER->ID) + $OUTPUT->set_pagetitle(rcube_label('settingsfor') . " ". $USER->get_username()); @@ -204,16 +197,7 @@ function rcmail_user_prefs_form($attrib) function rcmail_identities_list($attrib) { - global $DB, $CONFIG, $OUTPUT; - - - // get contacts from DB - $sql_result = $DB->query("SELECT * FROM ".get_table_name('identities')." - WHERE del<>1 - AND user_id=? - ORDER BY standard DESC, name ASC", - $_SESSION['user_id']); - + global $OUTPUT, $USER; // add id to message list table if not specified if (!strlen($attrib['id'])) @@ -223,7 +207,7 @@ function rcmail_identities_list($attrib) $a_show_cols = array('name', 'email', 'organization', 'reply-to'); // create XHTML table - $out = rcube_table_output($attrib, $sql_result, $a_show_cols, 'identity_id'); + $out = rcube_table_output($attrib, $USER->list_identities(), $a_show_cols, 'identity_id'); // set client env $OUTPUT->add_gui_object('identitieslist', $attrib['id']); diff --git a/program/steps/settings/save_identity.inc b/program/steps/settings/save_identity.inc index 8079b589a..2c2a55e49 100644 --- a/program/steps/settings/save_identity.inc +++ b/program/steps/settings/save_identity.inc @@ -33,123 +33,78 @@ if (empty($_POST['_name']) || empty($_POST['_email'])) } +$save_data = array(); +foreach ($a_save_cols as $col) +{ + $fname = '_'.$col; + if (isset($_POST[$fname])) + $save_data[$col] = get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols)); +} + +// set "off" values for checkboxes that were not checked, and therefore +// not included in the POST body. +foreach ($a_boolean_cols as $col) +{ + $fname = '_' . $col; + if (!isset($_POST[$fname])) + $save_data[$col] = 0; +} + + // update an existing contact if ($_POST['_iid']) +{ + if ($updated = $USER->update_identity(get_input_value('_iid', RCUBE_INPUT_POST), $save_data)) { - $a_write_sql = array(); - - foreach ($a_save_cols as $col) - { - $fname = '_'.$col; - if (isset($_POST[$fname])) - $a_write_sql[] = sprintf("%s=%s", - $DB->quoteIdentifier($col), - $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols)))); - } - - // set "off" values for checkboxes that were not checked, and therefore - // not included in the POST body. - foreach ($a_boolean_cols as $col) - { - $fname = '_' . $col; - if (!isset($_POST[$fname])) - $a_write_sql[] = sprintf("%s=0", $DB->quoteIdentifier($col)); - } - - if (sizeof($a_write_sql)) - { - $DB->query( - "UPDATE ".get_table_name('identities')." - SET ".join(', ', $a_write_sql)." - WHERE identity_id=? - AND user_id=? - AND del<>1", - get_input_value('_iid', RCUBE_INPUT_POST), - $_SESSION['user_id']); - - $updated = $DB->affected_rows(); - } - - if ($updated) - { $OUTPUT->show_message('successfullysaved', 'confirmation'); if (!empty($_POST['_standard'])) $default_id = get_input_value('_iid', RCUBE_INPUT_POST); if ($_POST['_framed']) - { + { // update the changed col in list // ... - } } + } else if ($DB->is_error()) - { + { // show error message $OUTPUT->show_message('errorsaving', 'error'); rcmail_overwrite_action('edit-identitiy'); return; - } } +} // insert a new contact else +{ + if ($insert_id = $USER->insert_identity($save_data)) { - $a_insert_cols = $a_insert_values = array(); - - foreach ($a_save_cols as $col) - { - $fname = '_'.$col; - if (!isset($_POST[$fname])) - continue; - - $a_insert_cols[] = $DB->quoteIdentifier($col); - $a_insert_values[] = $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols))); - } - - if (sizeof($a_insert_cols)) - { - $DB->query("INSERT INTO ".get_table_name('identities')." - (user_id, ".join(', ', $a_insert_cols).") - VALUES (?, ".join(', ', $a_insert_values).")", - $_SESSION['user_id']); - - $insert_id = $DB->insert_id(get_sequence_name('identities')); - } - - if ($insert_id) - { $_GET['_iid'] = $insert_id; if (!empty($_POST['_standard'])) $default_id = $insert_id; if ($_POST['_framed']) - { + { // add contact row or jump to the page where it should appear // .... - } } + } else - { + { // show error message $OUTPUT->show_message('errorsaving', 'error'); rcmail_overwrite_action('edit-identity'); return; - } } +} // mark all other identities as 'not-default' if ($default_id) - $DB->query( - "UPDATE ".get_table_name('identities')." - SET ".$DB->quoteIdentifier('standard')."='0' - WHERE user_id=? - AND identity_id<>? - AND del<>1", - $_SESSION['user_id'], - $default_id); + $USER->set_default($default_id); // go to next step rcmail_overwrite_action($_framed ? 'edit-identity' : 'identities'); diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc index 0565260f0..caa4a49e5 100644 --- a/program/steps/settings/save_prefs.inc +++ b/program/steps/settings/save_prefs.inc @@ -44,15 +44,12 @@ if (isset($_POST['_language'])) // force min size if ($a_user_prefs['pagesize'] < 1) - { $a_user_prefs['pagesize'] = 10; - } + if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['pagesize'] > $CONFIG['max_pagesize'])) - { $a_user_prefs['pagesize'] = (int) $CONFIG['max_pagesize']; - } -if (rcmail_save_user_prefs($a_user_prefs)) +if ($USER->save_prefs($a_user_prefs)) $OUTPUT->show_message('successfullysaved', 'confirmation'); |