]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/addressbook/edit.inc
Imported Upstream version 0.1~rc1~dfsg
[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 543 2007-04-28 18:07:12Z 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 $CONTACTS, $OUTPUT;
37
38   // check if we have a valid result
39   if ($GLOBALS['_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, $OUTPUT, $EDIT_FORM, $SESS_HIDDEN_FIELD;  
87
88   $result = $CONTACTS->get_result();
89   $form_start = '';
90   if (!strlen($EDIT_FORM))
91     {
92     $hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_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']) ? '<form name="form" action="./" method="post">' : '';
99     $form_start .= "\n$SESS_HIDDEN_FIELD\n";
100     $form_start .= $hiddenfields->show();
101     }
102     
103   $form_end = (strlen($EDIT_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
104   $form_name = strlen($attrib['form']) ? $attrib['form'] : 'form';
105   
106   if (!strlen($EDIT_FORM))
107     $OUTPUT->add_gui_object('editform', $form_name);
108   
109   $EDIT_FORM = $form_name;
110
111   return array($form_start, $form_end);  
112   }
113
114
115
116 if (!$CONTACTS->get_result() && template_exists('addcontact'))
117   parse_template('addcontact');
118
119 // this will be executed if no template for addcontact exists
120 parse_template('editcontact');
121 ?>