source: subversion/trunk/roundcubemail/program/steps/settings/save_identity.inc @ 344

Last change on this file since 344 was 344, checked in by estadtherr, 7 years ago

Initial TinyMCE editor support (still need to work on spellcheck and skins)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/settings/save_identity.inc                              |
6 |                                                                       |
7 | This file is part of the RoundCube Webmail client                     |
8 | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
11 | PURPOSE:                                                              |
12 |   Save an identity record or to add a new one                         |
13 |                                                                       |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 +-----------------------------------------------------------------------+
17
18 $Id$
19
20*/
21
22$a_save_cols = array('name', 'email', 'organization', 'reply-to', 'bcc', 'standard', 'signature', 'html_signature');
23$a_html_cols = array('signature');
24$a_boolean_cols = array('standard', 'html_signature');
25
26// check input
27if (empty($_POST['_name']) || empty($_POST['_email']))
28  {
29  show_message('formincomplete', 'warning');
30  rcmail_overwrite_action('edit-identitiy');
31  return;
32  }
33
34
35// update an existing contact
36if ($_POST['_iid'])
37  {
38  $a_write_sql = array();
39
40  foreach ($a_save_cols as $col)
41    {
42    $fname = '_'.$col;
43    if (!isset($_POST[$fname]))
44      continue;
45
46    $a_write_sql[] = sprintf("%s=%s",
47                             $DB->quoteIdentifier($col),
48                             $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols))));
49    }
50
51  // set "off" values for checkboxes that were not checked, and therefore
52  // not included in the POST body.
53  foreach ($a_boolean_cols as $col)
54    {
55    $fname = '_' . $col;
56    if (!isset($_POST[$fname]))
57      {
58      $a_write_sql[] = sprintf("%s=0", $DB->quoteIdentifier($col));
59      }
60    }
61
62  if (sizeof($a_write_sql))
63    {
64    $DB->query("UPDATE ".get_table_name('identities')."
65                SET ".join(', ', $a_write_sql)."
66                WHERE  identity_id=?
67                AND    user_id=?
68                AND    del<>1",
69                get_input_value('_iid', RCUBE_INPUT_POST),
70                $_SESSION['user_id']);
71                       
72    $updated = $DB->affected_rows();
73    }
74       
75  if ($updated)
76    {
77    show_message('successfullysaved', 'confirmation');
78
79    // mark all other identities as 'not-default'
80    if (!empty($_POST['_standard']))
81      $DB->query("UPDATE ".get_table_name('identities')."
82                  SET ".$DB->quoteIdentifier('standard')."='0'
83                  WHERE  user_id=?
84                  AND    identity_id<>?
85                  AND    del<>1",
86                  $_SESSION['user_id'],
87                  get_input_value('_iid', RCUBE_INPUT_POST));
88   
89    if ($_POST['_framed'])
90      {
91      // update the changed col in list
92      // ...     
93      }
94    }
95  else if ($DB->is_error())
96    {
97    // show error message
98    show_message('errorsaving', 'error');
99    rcmail_overwrite_action('edit-identitiy');
100    }
101  }
102
103// insert a new contact
104else
105  {
106  $a_insert_cols = $a_insert_values = array();
107
108  foreach ($a_save_cols as $col)
109    {
110    $fname = '_'.$col;
111    if (!isset($_POST[$fname]))
112      continue;
113   
114    $a_insert_cols[] = $DB->quoteIdentifier($col);
115    $a_insert_values[] = $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols)));
116    }
117   
118  if (sizeof($a_insert_cols))
119    {
120    $DB->query("INSERT INTO ".get_table_name('identities')."
121                (user_id, ".join(', ', $a_insert_cols).")
122                VALUES (?, ".join(', ', $a_insert_values).")",
123                $_SESSION['user_id']);
124
125    $insert_id = $DB->insert_id(get_sequence_name('identities'));
126    }
127   
128  if ($insert_id)
129    {
130    $_GET['_iid'] = $insert_id;
131
132    if ($_POST['_framed'])
133      {
134      // add contact row or jump to the page where it should appear
135      // ....
136      }
137    }
138  else
139    {
140    // show error message
141    show_message('errorsaving', 'error');
142    rcmail_overwrite_action('edit-identitiy');
143    }
144  }
145
146
147// go to next step
148rcmail_overwrite_action($_POST['_framed'] ? 'edit-identitiy' : 'identities');
149
150?>
Note: See TracBrowser for help on using the repository browser.