]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/addressbook/edit.inc
Imported Upstream version 0.3
[roundcube.git] / program / steps / addressbook / edit.inc
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: edit.inc 2755 2009-07-15 09:49:35Z thomasb $
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   $OUTPUT->add_label('noemailwarning', 'nonamewarning');
47
48   list($form_start, $form_end) = get_form_tags($attrib);
49   unset($attrib['form']);
50
51   // a specific part is requested
52   if ($attrib['part'])
53   {
54     $out = $form_start;
55     $out .= rcmail_get_edit_field($attrib['part'], $record[$attrib['part']], $attrib); 
56     return $out;
57   }
58
59
60   // return the complete address edit form as table
61   $out = "$form_start<table>\n\n";
62
63   $a_show_cols = array('name', 'firstname', 'surname', 'email');
64   foreach ($a_show_cols as $col)
65   {
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",
69                     $attrib['id'],
70                     Q(rcube_label($col)),
71                     $value);
72   }
73
74   $out .= "\n</table>$form_end";
75
76   return $out;  
77 }
78
79 $OUTPUT->add_handler('contacteditform', 'rcmail_contact_editform');
80
81
82 // similar function as in /steps/settings/edit_identity.inc
83 function get_form_tags($attrib)
84 {
85   global $CONTACTS, $EDIT_FORM, $RCMAIL;
86
87   $form_start = $form_end = '';
88   
89   if (empty($EDIT_FORM)) {
90     $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
91     
92     if (($result = $CONTACTS->get_result()) && ($record = $result->first()))
93       $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
94     
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>' : '';
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
107 if (!$CONTACTS->get_result() && $OUTPUT->template_exists('addcontact'))
108   $OUTPUT->send('addcontact');
109
110 // this will be executed if no template for addcontact exists
111 $OUTPUT->send('editcontact');
112 ?>