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

Last change on this file since 330 was 330, checked in by thomasb, 7 years ago

Improved message parsing and HTML validation

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 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');
23$a_html_cols = array('signature');
24
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  if (sizeof($a_write_sql))
52    {
53    $DB->query("UPDATE ".get_table_name('identities')."
54                SET ".join(', ', $a_write_sql)."
55                WHERE  identity_id=?
56                AND    user_id=?
57                AND    del<>1",
58                get_input_value('_iid', RCUBE_INPUT_POST),
59                $_SESSION['user_id']);
60                       
61    $updated = $DB->affected_rows();
62    }
63       
64  if ($updated)
65    {
66    show_message('successfullysaved', 'confirmation');
67
68    // mark all other identities as 'not-default'
69    if (!empty($_POST['_standard']))
70      $DB->query("UPDATE ".get_table_name('identities')."
71                  SET ".$DB->quoteIdentifier('standard')."='0'
72                  WHERE  user_id=?
73                  AND    identity_id<>?
74                  AND    del<>1",
75                  $_SESSION['user_id'],
76                  get_input_value('_iid', RCUBE_INPUT_POST));
77   
78    if ($_POST['_framed'])
79      {
80      // update the changed col in list
81      // ...     
82      }
83    }
84  else if ($DB->is_error())
85    {
86    // show error message
87    show_message('errorsaving', 'error');
88    rcmail_overwrite_action('edit-identitiy');
89    }
90  }
91
92// insert a new contact
93else
94  {
95  $a_insert_cols = $a_insert_values = array();
96
97  foreach ($a_save_cols as $col)
98    {
99    $fname = '_'.$col;
100    if (!isset($_POST[$fname]))
101      continue;
102   
103    $a_insert_cols[] = $DB->quoteIdentifier($col);
104    $a_insert_values[] = $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols)));
105    }
106   
107  if (sizeof($a_insert_cols))
108    {
109    $DB->query("INSERT INTO ".get_table_name('identities')."
110                (user_id, ".join(', ', $a_insert_cols).")
111                VALUES (?, ".join(', ', $a_insert_values).")",
112                $_SESSION['user_id']);
113
114    $insert_id = $DB->insert_id(get_sequence_name('identities'));
115    }
116   
117  if ($insert_id)
118    {
119    $_GET['_iid'] = $insert_id;
120
121    if ($_POST['_framed'])
122      {
123      // add contact row or jump to the page where it should appear
124      // ....
125      }
126    }
127  else
128    {
129    // show error message
130    show_message('errorsaving', 'error');
131    rcmail_overwrite_action('edit-identitiy');
132    }
133  }
134
135
136// go to next step
137rcmail_overwrite_action($_POST['_framed'] ? 'edit-identitiy' : 'identities');
138
139?>
Note: See TracBrowser for help on using the repository browser.