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

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

Re-design of caching (new database table added\!); some bugfixes; Postgres support

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