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

Last change on this file since 3 was 3, checked in by roundcube, 8 years ago

Initial revision

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