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

Last change on this file since 58 was 58, checked in by sparc, 8 years ago

more pear/mdb2 integration

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