| 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 | $OUTPUT->show_message('sourceisreadonly'); |
|---|
| 29 | rcmail_overwrite_action('show'); |
|---|
| 30 | return; |
|---|
| 31 | } |
|---|
| 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' |
|---|
| 40 | && !(($result = $CONTACTS->get_result()) && ($record = $result->first())) |
|---|
| 41 | ) { |
|---|
| 42 | $OUTPUT->show_message('contactnotfound'); |
|---|
| 43 | return false; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | // add some labels to client |
|---|
| 47 | $OUTPUT->add_label('noemailwarning', 'nonamewarning'); |
|---|
| 48 | |
|---|
| 49 | $i_size = !empty($attrib['size']) ? $attrib['size'] : 40; |
|---|
| 50 | $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 6; |
|---|
| 51 | $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40; |
|---|
| 52 | |
|---|
| 53 | $form = array( |
|---|
| 54 | 'info' => array( |
|---|
| 55 | 'name' => rcube_label('contactproperties'), |
|---|
| 56 | 'content' => array( |
|---|
| 57 | 'name' => array('type' => 'text', 'size' => $i_size), |
|---|
| 58 | 'firstname' => array('type' => 'text', 'size' => $i_size), |
|---|
| 59 | 'surname' => array('type' => 'text', 'size' => $i_size), |
|---|
| 60 | 'email' => array('type' => 'text', 'size' => $i_size), |
|---|
| 61 | ), |
|---|
| 62 | ), |
|---|
| 63 | ); |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | list($form_start, $form_end) = get_form_tags($attrib); |
|---|
| 67 | unset($attrib['form']); |
|---|
| 68 | |
|---|
| 69 | // return the complete address edit form as table |
|---|
| 70 | $out = rcmail_contact_form($form, $record); |
|---|
| 71 | |
|---|
| 72 | return $form_start . $out . $form_end; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | // similar function as in /steps/settings/edit_identity.inc |
|---|
| 77 | function get_form_tags($attrib) |
|---|
| 78 | { |
|---|
| 79 | global $CONTACTS, $EDIT_FORM, $RCMAIL; |
|---|
| 80 | |
|---|
| 81 | $form_start = $form_end = ''; |
|---|
| 82 | |
|---|
| 83 | if (empty($EDIT_FORM)) { |
|---|
| 84 | $hiddenfields = new html_hiddenfield(array( |
|---|
| 85 | 'name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC))); |
|---|
| 86 | $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id)); |
|---|
| 87 | |
|---|
| 88 | if (($result = $CONTACTS->get_result()) && ($record = $result->first())) |
|---|
| 89 | $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID'])); |
|---|
| 90 | |
|---|
| 91 | $form_start = $RCMAIL->output->request_form(array( |
|---|
| 92 | 'name' => "form", 'method' => "post", |
|---|
| 93 | 'task' => $RCMAIL->task, 'action' => 'save', |
|---|
| 94 | 'request' => 'save.'.intval($record['ID']), |
|---|
| 95 | 'noclose' => true) + $attrib, $hiddenfields->show()); |
|---|
| 96 | $form_end = !strlen($attrib['form']) ? '</form>' : ''; |
|---|
| 97 | |
|---|
| 98 | $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form'; |
|---|
| 99 | $RCMAIL->output->add_gui_object('editform', $EDIT_FORM); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | return array($form_start, $form_end); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | $OUTPUT->add_handler('contacteditform', 'rcmail_contact_editform'); |
|---|
| 107 | |
|---|
| 108 | if (!$CONTACTS->get_result() && $OUTPUT->template_exists('addcontact')) |
|---|
| 109 | $OUTPUT->send('addcontact'); |
|---|
| 110 | |
|---|
| 111 | // this will be executed if no template for addcontact exists |
|---|
| 112 | $OUTPUT->send('editcontact'); |
|---|