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

Last change on this file since 147 was 147, checked in by roundcube, 7 years ago

Fixed some charset bugs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 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
24
25// check input
26if (empty($_POST['_name']) || empty($_POST['_email']))
27  {
28  show_message('formincomplete', 'warning');
29  rcmail_overwrite_action('edit-identitiy');
30  return;
31  }
32
33
34// update an existing contact
35if ($_POST['_iid'])
36  {
37  $a_write_sql = array();
38
39  foreach ($a_save_cols as $col)
40    {
41    $fname = '_'.$col;
42    if (!isset($_POST[$fname]))
43      continue;
44
45    $a_write_sql[] = sprintf("%s=%s",
46                             $DB->quoteIdentifier($col),
47                             $DB->quote(rcube_charset_convert(strip_tags($_POST[$fname]), $OUTPUT->get_charset())));
48    }
49
50  if (sizeof($a_write_sql))
51    {
52    $DB->query("UPDATE ".get_table_name('identities')."
53                SET ".join(', ', $a_write_sql)."
54                WHERE  identity_id=?
55                AND    user_id=?
56                AND    del<>1",
57                $_POST['_iid'],
58                $_SESSION['user_id']);
59                       
60    $updated = $DB->affected_rows();
61    }
62       
63  if ($updated)
64    {
65    show_message('successfullysaved', 'confirmation');
66
67    // mark all other identities as 'not-default'
68    $DB->query("UPDATE ".get_table_name('identities')."
69                SET ".$DB->quoteIdentifier('standard')."='0'
70                WHERE  user_id=?
71                AND    identity_id<>?
72                AND    del<>1",
73                $_SESSION['user_id'],
74                $_POST['_iid']);
75   
76    if ($_POST['_framed'])
77      {
78      // update the changed col in list
79      // ...     
80      }
81    }
82  else
83    {
84    // show error message
85    show_message('errorsaving', 'error');
86    rcmail_overwrite_action('edit-identitiy');
87    }
88  }
89
90// insert a new contact
91else
92  {
93  $a_insert_cols = $a_insert_values = array();
94
95  foreach ($a_save_cols as $col)
96    {
97    $fname = '_'.$col;
98    if (!isset($_POST[$fname]))
99      continue;
100   
101    $a_insert_cols[] = $DB->quoteIdentifier($col);
102    $a_insert_values[] = $DB->quote(rcube_charset_convert(strip_tags($_POST[$fname]), $OUTPUT->get_charset()));
103    }
104   
105  if (sizeof($a_insert_cols))
106    {
107    $DB->query("INSERT INTO ".get_table_name('identities')."
108                (user_id, ".join(', ', $a_insert_cols).")
109                VALUES (?, ".join(', ', $a_insert_values).")",
110                $_SESSION['user_id']);
111
112    $insert_id = $DB->insert_id(get_sequence_name('identities'));
113    }
114   
115  if ($insert_id)
116    {
117    $_GET['_iid'] = $insert_id;
118
119    if ($_POST['_framed'])
120      {
121      // add contact row or jump to the page where it should appear
122      // ....
123      }
124    }
125  else
126    {
127    // show error message
128    show_message('errorsaving', 'error');
129    rcmail_overwrite_action('edit-identitiy');
130    }
131  }
132
133
134// go to next step
135rcmail_overwrite_action($_POST['_framed'] ? 'edit-identitiy' : 'identities');
136
137?>
Note: See TracBrowser for help on using the repository browser.