source: subversion/branches/devel-vnext/program/steps/addressbook/edit.inc @ 623

Last change on this file since 623 was 623, checked in by till, 6 years ago

+ switch from global to rc_registry is complete
+ more logging/debugging
+ many CS changes
+ put different functions into their own file

# todo: fix JS inclusion (probably in template class)

File size: 4.6 KB
Line 
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
23if (($cid = rc_main::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
27if ($CONTACTS->readonly) {
28    $OUTPUT->show_message('sourceisreadonly');
29    rcmail_overwrite_action('show');
30    return;
31}
32
33function rcmail_contact_editform($attrib)
34{
35    $registry = rc_registry::getInstance();
36    $CONTACTS = $registry->get('CONTACTS', 'core');
37    $OUTPUT   = $registry->get('OUTPUT', 'core');
38
39    // check if we have a valid result
40    if ($GLOBALS['_action'] != 'add' && !(($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    rcube_add_label('noemailwarning');
48    rcube_add_label('nonamewarning');
49
50    list($form_start, $form_end) = get_form_tags($attrib);
51    unset($attrib['form']);
52
53    // a specific part is requested
54    if ($attrib['part']) {
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        $attrib['id'] = 'rcmfd_'.$col;
67        $value = rcmail_get_edit_field($col, $record[$col], $attrib);
68        $out .= sprintf(
69                    "<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
70                    $attrib['id'],
71                    rc_main::Q(rcube_label($col)),
72                    $value
73        );
74    }
75    $out .= "\n</table>$form_end";
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
83function get_form_tags($attrib)
84{
85    $registry          = rc_registry::getInstance();
86    $CONTACTS          = $registry->get('CONTACTS', 'core');
87    $OUTPUT            = $registry->get('OUTPUT', 'core');
88    $EDIT_FORM         = $registry->get('EDIT_FORM', 'core');
89    $SESS_HIDDEN_FIELD = $registry->get('SESS_HIDDEN_FIELD', 'core');
90
91    $result = $CONTACTS->get_result();
92    $form_start = '';
93    if (!strlen($EDIT_FORM)) {
94        $hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task']));
95        $hiddenfields->add(
96                        array(
97                            'name' => '_action',
98                            'value' => 'save',
99                            'source' => rc_main::get_input_value('_source', RCUBE_INPUT_GPC)
100                        )
101        );
102   
103        if (($result = $CONTACTS->get_result()) && ($record = $result->first())) {
104            $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
105        }
106        $form_start  = !strlen($attrib['form']) ? '<form name="form" action="./" method="post">' : '';
107        $form_start .= "\n$SESS_HIDDEN_FIELD\n";
108        $form_start .= $hiddenfields->show();
109    }
110   
111    $form_end  = (strlen($EDIT_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
112    $form_name = strlen($attrib['form']) ? $attrib['form'] : 'form';
113 
114    if (!strlen($EDIT_FORM)) {
115        $OUTPUT->add_gui_object('editform', $form_name);
116    }
117    $EDIT_FORM = $form_name;
118    $registry->set('EDIT_FORM', $EDIT_FORM, 'core');
119
120    return array($form_start, $form_end); 
121}
122
123
124
125if (!$CONTACTS->get_result() && template_exists('addcontact')) {
126    rc_main::parse_template('addcontact');
127}
128// this will be executed if no template for addcontact exists
129rc_main::parse_template('editcontact');
130?>
Note: See TracBrowser for help on using the repository browser.