thomascube
2005-11-06 10a699759d4f106f29c077a6d65d3b8d212825e5
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/addressbook/edit.inc                                    |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8  | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
30233b 9  | Licensed under the GNU GPL                                            |
4e17e6 10  |                                                                       |
T 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 (($_GET['_cid'] || $_POST['_cid']) && $_action=='edit')
24   {
25   $cid = $_POST['_cid'] ? $_POST['_cid'] : $_GET['_cid'];
d7cb77 26   $DB->query("SELECT * FROM ".get_table_name('contacts')."
S 27              WHERE  contact_id=?
28              AND    user_id=?
29              AND    del<>'1'",
30              $cid,
31              $_SESSION['user_id']);
4e17e6 32   
T 33   $CONTACT_RECORD = $DB->fetch_assoc();
10a699 34
4e17e6 35   if (is_array($CONTACT_RECORD))
T 36     $OUTPUT->add_script(sprintf("%s.set_env('cid', '%s');", $JS_OBJECT_NAME, $CONTACT_RECORD['contact_id']));
37   }
38
39
40
41 function rcmail_contact_editform($attrib)
42   {
43   global $CONTACT_RECORD, $JS_OBJECT_NAME;
44
45   if (!$CONTACT_RECORD && $GLOBALS['_action']!='add')
46     return rcube_label('contactnotfound');
47
10a699 48   // add some labels to client
T 49   rcube_add_label('noemailwarning');
50   rcube_add_label('nonamewarning');
51
4e17e6 52   list($form_start, $form_end) = get_form_tags($attrib);
T 53   unset($attrib['form']);
54   
55
56   // a specific part is requested
57   if ($attrib['part'])
58     {
59     $out = $form_start;
60     $out .= rcmail_get_edit_field($attrib['part'], $CONTACT_RECORD[$attrib['part']], $attrib); 
61     return $out;
62     }
63
64
65   // return the complete address edit form as table
66   $out = "$form_start<table>\n\n";
67
68   $a_show_cols = array('name', 'firstname', 'surname', 'email');
69   foreach ($a_show_cols as $col)
70     {
71     $attrib['id'] = 'rcmfd_'.$col;
72     $title = rcube_label($col);
73     $value = rcmail_get_edit_field($col, $CONTACT_RECORD[$col], $attrib);
74     $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
75                     $attrib['id'],
76                     $title,
77                     $value);
78     }
79
80   $out .= "\n</table>$form_end";
81
82   return $out;  
83   }
84
85
86 // similar function as in /steps/settings/edit_identity.inc
87 function get_form_tags($attrib)
88   {
89   global $CONTACT_RECORD, $OUTPUT, $JS_OBJECT_NAME, $EDIT_FORM, $SESS_HIDDEN_FIELD;  
90
91   $form_start = '';
92   if (!strlen($EDIT_FORM))
93     {
94     $hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task']));
95     $hiddenfields->add(array('name' => '_action', 'value' => 'save'));
96     
97     if ($_GET['_framed'] || $_POST['_framed'])
98       $hiddenfields->add(array('name' => '_framed', 'value' => 1));
99     
100     if ($CONTACT_RECORD['contact_id'])
101       $hiddenfields->add(array('name' => '_cid', 'value' => $CONTACT_RECORD['contact_id']));
102     
103     $form_start = !strlen($attrib['form']) ? '<form name="form" action="./" method="post">' : '';
104     $form_start .= "\n$SESS_HIDDEN_FIELD\n";
105     $form_start .= $hiddenfields->show();
106     }
107     
108   $form_end = (strlen($EDIT_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
109   $form_name = strlen($attrib['form']) ? $attrib['form'] : 'form';
110   
111   if (!strlen($EDIT_FORM))
112     $OUTPUT->add_script("$JS_OBJECT_NAME.gui_object('editform', '$form_name');");
113   
114   $EDIT_FORM = $form_name;
115
116   return array($form_start, $form_end);  
117   }
118
119
120
121 if (!$CONTACT_RECORD && template_exists('addcontact'))
122   parse_template('addcontact');
123
124 // this will be executed if no template for addcontact exists
125 parse_template('editcontact');
126 ?>