commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/addressbook/edit.inc | |
|
6 |
| | |
|
7 |
| This file is part of the RoundCube Webmail client | |
f11541
|
8 |
| Copyright (C) 2005-2007, RoundCube Dev. - Switzerland | |
30233b
|
9 |
| Licensed under the GNU GPL | |
4e17e6
|
10 |
| | |
T |
11 |
| PURPOSE: | |
|
12 |
| Show edit form for 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 |
|
f11541
|
23 |
if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true))) |
T |
24 |
$OUTPUT->set_env('cid', $record['ID']); |
10a699
|
25 |
|
f11541
|
26 |
// adding not allowed here |
T |
27 |
if ($CONTACTS->readonly) |
|
28 |
{ |
|
29 |
$OUTPUT->show_message('sourceisreadonly'); |
|
30 |
rcmail_overwrite_action('show'); |
|
31 |
return; |
|
32 |
} |
4e17e6
|
33 |
|
T |
34 |
function rcmail_contact_editform($attrib) |
f11541
|
35 |
{ |
197601
|
36 |
global $RCMAIL, $CONTACTS, $OUTPUT; |
4e17e6
|
37 |
|
f11541
|
38 |
// check if we have a valid result |
197601
|
39 |
if ($RCMAIL->action != 'add' && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))) |
f11541
|
40 |
{ |
T |
41 |
$OUTPUT->show_message('contactnotfound'); |
|
42 |
return false; |
|
43 |
} |
4e17e6
|
44 |
|
10a699
|
45 |
// add some labels to client |
T |
46 |
rcube_add_label('noemailwarning'); |
|
47 |
rcube_add_label('nonamewarning'); |
|
48 |
|
4e17e6
|
49 |
list($form_start, $form_end) = get_form_tags($attrib); |
T |
50 |
unset($attrib['form']); |
|
51 |
|
|
52 |
// a specific part is requested |
|
53 |
if ($attrib['part']) |
f11541
|
54 |
{ |
4e17e6
|
55 |
$out = $form_start; |
f11541
|
56 |
$out .= rcmail_get_edit_field($attrib['part'], $record[$attrib['part']], $attrib); |
4e17e6
|
57 |
return $out; |
f11541
|
58 |
} |
4e17e6
|
59 |
|
T |
60 |
|
|
61 |
// return the complete address edit form as table |
|
62 |
$out = "$form_start<table>\n\n"; |
|
63 |
|
64009e
|
64 |
$a_show_cols = array('name', 'firstname', 'surname', 'email'); |
4e17e6
|
65 |
foreach ($a_show_cols as $col) |
f11541
|
66 |
{ |
4e17e6
|
67 |
$attrib['id'] = 'rcmfd_'.$col; |
f11541
|
68 |
$value = rcmail_get_edit_field($col, $record[$col], $attrib); |
4e17e6
|
69 |
$out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n", |
T |
70 |
$attrib['id'], |
f11541
|
71 |
Q(rcube_label($col)), |
4e17e6
|
72 |
$value); |
f11541
|
73 |
} |
4e17e6
|
74 |
|
T |
75 |
$out .= "\n</table>$form_end"; |
|
76 |
|
|
77 |
return $out; |
f11541
|
78 |
} |
T |
79 |
|
|
80 |
$OUTPUT->add_handler('contacteditform', 'rcmail_contact_editform'); |
4e17e6
|
81 |
|
T |
82 |
|
|
83 |
// similar function as in /steps/settings/edit_identity.inc |
|
84 |
function get_form_tags($attrib) |
|
85 |
{ |
197601
|
86 |
global $CONTACTS, $EDIT_FORM, $RCMAIL; |
4e17e6
|
87 |
|
f11541
|
88 |
$result = $CONTACTS->get_result(); |
4e17e6
|
89 |
$form_start = ''; |
T |
90 |
if (!strlen($EDIT_FORM)) |
|
91 |
{ |
197601
|
92 |
$hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task)); |
f92aba
|
93 |
$hiddenfields->add(array('name' => '_action', 'value' => 'save')); |
4f9c83
|
94 |
$hiddenfields->add(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC))); |
0339e3
|
95 |
$hiddenfields->add(array('name' => '_framed', 'value' => (empty($_REQUEST['_framed']) ? 0 : 1))); |
4e17e6
|
96 |
|
f11541
|
97 |
if (($result = $CONTACTS->get_result()) && ($record = $result->first())) |
T |
98 |
$hiddenfields->add(array('name' => '_cid', 'value' => $record['ID'])); |
4e17e6
|
99 |
|
197601
|
100 |
$form_start = !strlen($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : ''; |
4e17e6
|
101 |
$form_start .= $hiddenfields->show(); |
T |
102 |
} |
|
103 |
|
|
104 |
$form_end = (strlen($EDIT_FORM) && !strlen($attrib['form'])) ? '</form>' : ''; |
|
105 |
$form_name = strlen($attrib['form']) ? $attrib['form'] : 'form'; |
|
106 |
|
|
107 |
if (!strlen($EDIT_FORM)) |
197601
|
108 |
$RCMAIL->output->add_gui_object('editform', $form_name); |
4e17e6
|
109 |
|
T |
110 |
$EDIT_FORM = $form_name; |
|
111 |
|
197601
|
112 |
return array($form_start, $form_end); |
4e17e6
|
113 |
} |
T |
114 |
|
|
115 |
|
|
116 |
|
e58df3
|
117 |
if (!$CONTACTS->get_result() && $OUTPUT->template_exists('addcontact')) |
47124c
|
118 |
$OUTPUT->send('addcontact'); |
4e17e6
|
119 |
|
T |
120 |
// this will be executed if no template for addcontact exists |
47124c
|
121 |
$OUTPUT->send('editcontact'); |
4f9c83
|
122 |
?> |