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