source: github/program/steps/addressbook/save.inc @ 69f18a09

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 69f18a09 was 69f18a09, checked in by thomascube <thomas@…>, 4 years ago

Add plugin hooks for creating/saving/deleting identities and contacts

  • Property mode set to 100644
File size: 3.9 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/save.inc                                    |
6 |                                                                       |
7 | This file is part of the RoundCube Webmail client                     |
8 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
11 | PURPOSE:                                                              |
12 |   Save a contact entry or to add a new one                            |
13 |                                                                       |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 +-----------------------------------------------------------------------+
17
18 $Id$
19
20*/
21
22// cannot edit record
23if ($CONTACTS->readonly)
24{
25  $OUTPUT->show_message('contactreadonly', 'error');
26  rcmail_overwrite_action(empty($_POST['_cid']) ? 'add' : 'show');
27  return;
28}
29
30// check input
31if ((!get_input_value('_name', RCUBE_INPUT_POST) || !get_input_value('_email', RCUBE_INPUT_POST)))
32{
33  $OUTPUT->show_message('formincomplete', 'warning');
34  rcmail_overwrite_action(empty($_POST['_cid']) ? 'add' : 'show');
35  return;
36}
37
38
39// setup some vars we need
40$a_save_cols = array('name', 'firstname', 'surname', 'email');
41$a_record = array();
42$cid = get_input_value('_cid', RCUBE_INPUT_POST);
43
44// read POST values into hash array
45foreach ($a_save_cols as $col)
46{
47  $fname = '_'.$col;
48  if (isset($_POST[$fname]))
49    $a_record[$col] = get_input_value($fname, RCUBE_INPUT_POST);
50}
51
52// update an existing contact
53if (!empty($cid))
54{
55  $plugin = $RCMAIL->plugins->exec_hook('save_contact', array('id' => $cid, 'record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
56  $a_record = $plugin['record'];
57 
58  if (!$plugin['abort'] && $CONTACTS->update($cid, $a_record))
59  {
60    // define list of cols to be displayed
61    $a_js_cols = array();
62    $record = $CONTACTS->get_record($cid, true);
63
64    foreach (array('name', 'email') as $col)
65      $a_js_cols[] = (string)$record[$col];
66
67    // update the changed col in list
68    $OUTPUT->command('parent.update_contact_row', $cid, $a_js_cols);
69     
70    // show confirmation
71    $OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
72    rcmail_overwrite_action('show');
73  }
74  else
75  {
76    // show error message
77    $OUTPUT->show_message('errorsaving', 'error', null, false);
78    rcmail_overwrite_action('show');
79  }
80}
81
82// insert a new contact
83else
84{
85  // check for existing contacts
86  $existing = $CONTACTS->search('email', $a_record['email'], true, false);
87 
88  // show warning message
89  if ($existing->count)
90  {
91    $OUTPUT->show_message('contactexists', 'warning', null, false);
92    rcmail_overwrite_action('add');
93    return;
94  }
95
96  $plugin = $RCMAIL->plugins->exec_hook('create_contact', array('record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
97  $a_record = $plugin['record'];
98
99  // insert record and send response
100  if (!$plugin['abort'] && ($insert_id = $CONTACTS->insert($a_record)))
101  {
102    // add contact row or jump to the page where it should appear
103    $CONTACTS->reset();
104    $result = $CONTACTS->search($CONTACTS->primary_key, $insert_id);
105
106    rcmail_js_contacts_list($result, 'parent.');
107    $OUTPUT->command('parent.contact_list.select', $insert_id);
108
109    // update record count display
110    $CONTACTS->reset();
111    $OUTPUT->command('parent.set_rowcount', rcmail_get_rowcount_text());
112
113    // show confirmation
114    $OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
115    rcmail_overwrite_action('show');
116    $_GET['_cid'] = $insert_id;
117  }
118  else
119  {
120    // show error message
121    $OUTPUT->show_message('errorsaving', 'error', null, false);
122    rcmail_overwrite_action('add');
123  }
124}
125
126?>
Note: See TracBrowser for help on using the repository browser.