4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/edit.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Show edit form for a contact entry or to add a new one |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: edit.inc 2755 2009-07-15 09:49:35Z thomasb $
23 if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true)))
24 $OUTPUT->set_env('cid', $record['ID']);
26 // adding not allowed here
27 if ($CONTACTS->readonly)
29 $OUTPUT->show_message('sourceisreadonly');
30 rcmail_overwrite_action('show');
34 function rcmail_contact_editform($attrib)
36 global $RCMAIL, $CONTACTS, $OUTPUT;
38 // check if we have a valid result
39 if ($RCMAIL->action != 'add' && !(($result = $CONTACTS->get_result()) && ($record = $result->first())))
41 $OUTPUT->show_message('contactnotfound');
45 // add some labels to client
46 $OUTPUT->add_label('noemailwarning', 'nonamewarning');
48 list($form_start, $form_end) = get_form_tags($attrib);
49 unset($attrib['form']);
51 // a specific part is requested
55 $out .= rcmail_get_edit_field($attrib['part'], $record[$attrib['part']], $attrib);
60 // return the complete address edit form as table
61 $out = "$form_start<table>\n\n";
63 $a_show_cols = array('name', 'firstname', 'surname', 'email');
64 foreach ($a_show_cols as $col)
66 $attrib['id'] = 'rcmfd_'.$col;
67 $value = rcmail_get_edit_field($col, $record[$col], $attrib);
68 $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
74 $out .= "\n</table>$form_end";
79 $OUTPUT->add_handler('contacteditform', 'rcmail_contact_editform');
82 // similar function as in /steps/settings/edit_identity.inc
83 function get_form_tags($attrib)
85 global $CONTACTS, $EDIT_FORM, $RCMAIL;
87 $form_start = $form_end = '';
89 if (empty($EDIT_FORM)) {
90 $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
92 if (($result = $CONTACTS->get_result()) && ($record = $result->first()))
93 $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
95 $form_start = $RCMAIL->output->request_form(array('name' => "form", 'method' => "post", 'task' => $RCMAIL->task, 'action' => 'save', 'request' => 'save.'.intval($record['ID']), 'noclose' => true) + $attrib, $hiddenfields->show());
96 $form_end = !strlen($attrib['form']) ? '</form>' : '';
98 $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form';
99 $RCMAIL->output->add_gui_object('editform', $EDIT_FORM);
102 return array($form_start, $form_end);
107 if (!$CONTACTS->get_result() && $OUTPUT->template_exists('addcontact'))
108 $OUTPUT->send('addcontact');
110 // this will be executed if no template for addcontact exists
111 $OUTPUT->send('editcontact');