~ubuntu-branches/ubuntu/vivid/php-horde-nag/vivid-proposed

« back to all changes in this revision

Viewing changes to nag-4.1.3/lib/Ui/VarRenderer/Nag.php

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2014-03-11 21:27:39 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140311212739-m6rbihspu5zjpvaq
Tags: 4.1.4-1
New upstream version 4.1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * This file contains all Horde_Core_Ui_VarRenderer extensions required for
4
 
 * editing tasks.
5
 
 *
6
 
 * See the enclosed file COPYING for license information (GPL). If you
7
 
 * did not receive this file, see http://www.horde.org/licenses/gpl.
8
 
 *
9
 
 * @package Nag
10
 
 */
11
 
 
12
 
/**
13
 
 * The Horde_Core_Ui_VarRenderer_Nag class provides additional methods for
14
 
 * rendering Nag specific fields.
15
 
 *
16
 
 * @todo    Clean this hack up with Horde_Form/H4
17
 
 * @author  Jan Schneider <jan@horde.org>
18
 
 * @package Nag
19
 
 */
20
 
class Horde_Core_Ui_VarRenderer_Nag extends Horde_Core_Ui_VarRenderer_Html
21
 
{
22
 
    protected function _renderVarInput_NagMethod($form, $var, $vars)
23
 
    {
24
 
        $varname = htmlspecialchars($var->getVarName());
25
 
        $varvalue = $var->getValue($vars);
26
 
        $on = !empty($varvalue) &&
27
 
            (!isset($varvalue['on']) || !empty($varvalue['on']));
28
 
 
29
 
        printf('<input id="%soff" type="radio" class="radio" name="%s[on]" value="0"%s %s/><label for="%soff">&nbsp;%s</label><br />',
30
 
               $varname,
31
 
               $varname,
32
 
               $on ? '' : ' checked="checked"',
33
 
               $this->_getActionScripts($form, $var),
34
 
               $varname,
35
 
               _("Use default notification method"));
36
 
        printf('<input type="radio" class="radio" name="%s[on]" value="1"%s %s/><label for="%soff">&nbsp;%s</label>',
37
 
               $varname,
38
 
               $on ? ' checked="checked"' : '',
39
 
               $this->_getActionScripts($form, $var),
40
 
               $varname,
41
 
               _("Use custom notification method"));
42
 
 
43
 
        if ($on) {
44
 
            echo '<br />';
45
 
            Horde_Core_Prefs_Ui_Widgets::alarmInit();
46
 
            $params = array('pref' => 'task_alarms', 'label' => '');
47
 
            if ((!empty($varvalue) && !isset($varvalue['on'])) ||
48
 
                $form->isSubmitted()) {
49
 
                $params['value'] = $varvalue;
50
 
            }
51
 
            echo Horde_Core_Prefs_Ui_Widgets::alarm($params);
52
 
        }
53
 
    }
54
 
 
55
 
    protected function _renderVarInput_NagStart($form, $var, $vars)
56
 
    {
57
 
        $var->type->getInfo($vars, $var, $task_start);
58
 
        $start_dt = ($task_start == 0)
59
 
            // About a week from now
60
 
            ? time() + 604800
61
 
            : $task_start;
62
 
 
63
 
        $start_date = strftime('%x', $start_dt);
64
 
 
65
 
        /* Set up the radio buttons. */
66
 
        $no_start_checked = ($task_start == 0) ? 'checked="checked" ' : '';
67
 
        $specified_start_checked = ($task_start > 0) ? 'checked="checked" ' : '';
68
 
?>
69
 
<input id="start_date_none" name="start_date" type="radio" class="radio" value="none" <?php echo $no_start_checked ?> />
70
 
<?php echo Horde::label('start_date_none', _("No delay")) ?>
71
 
<br />
72
 
 
73
 
<input id="start_date_specified" name="start_date" type="radio" class="radio" value="specified" <?php echo $specified_start_checked ?> />
74
 
<label for="start_date_specified" class="hidden"><?php echo _("Start date specified.") ?></label>
75
 
<label for="start_date" class="hidden"><?php echo _("Date") ?></label>
76
 
<input type="text" name="start[date]" id="start_date" size="10" value="<?php echo htmlspecialchars($start_date) ?>">
77
 
<?php
78
 
        if ($GLOBALS['browser']->hasFeature('javascript')) {
79
 
            Horde_Core_Ui_JsCalendar::init(array(
80
 
                'full_weekdays' => true
81
 
            ));
82
 
            $GLOBALS['page_output']->addScriptFile('calendar.js');
83
 
            echo '<span id="start_wday"></span>' .
84
 
                Horde::img('calendar.png', _("Calendar"), 'id="startimg"');
85
 
        }
86
 
    }
87
 
 
88
 
    protected function _renderVarInput_NagDue($form, $var, $vars)
89
 
    {
90
 
        $var->type->getInfo($vars, $var, $task_due);
91
 
        if ($task_due == 0) {
92
 
            $date = '+' . (int)$GLOBALS['prefs']->getValue('default_due_days') . ' days';
93
 
            $time = $GLOBALS['prefs']->getValue('default_due_time');
94
 
            if ($time == 'now') {
95
 
                $time = '';
96
 
            } else {
97
 
                $time = ' ' . $time;
98
 
            }
99
 
            $due_dt = strtotime($date . $time);
100
 
 
101
 
            // Default to having a due date for new tasks if the
102
 
            // default_due preference is set.
103
 
            if (!$vars->exists('task_id') && $GLOBALS['prefs']->getValue('default_due')) {
104
 
                $task_due = strtotime($date . $time);
105
 
            }
106
 
        } else {
107
 
            $due_dt = $task_due;
108
 
        }
109
 
 
110
 
        $due_date = strftime('%x', $due_dt);
111
 
        $time_format = $GLOBALS['prefs']->getValue('twentyFour') ? 'H:i' : 'h:i a';
112
 
        $due_time = date($time_format, $due_dt);
113
 
 
114
 
        /* Set up the radio buttons. */
115
 
        $none_checked = ($task_due == 0) ? 'checked="checked" ' : '';
116
 
        $specified_checked = ($task_due > 0) ? 'checked="checked" ' : '';
117
 
?>
118
 
<input id="due_type_none" name="due_type" type="radio" class="radio" value="none" <?php echo $none_checked ?> />
119
 
<?php echo Horde::label('due_type_none', _("No due date.")) ?>
120
 
<br />
121
 
 
122
 
<input id="due_type_specified" name="due_type" type="radio" class="radio" value="specified" <?php echo $specified_checked ?> />
123
 
<label for="due_type_specified" class="hidden"><?php echo _("Due date specified.") ?></label>
124
 
<label for="due_date" class="hidden"><?php echo _("Date") ?></label>
125
 
<input type="text" name="due[date]" id="due_date" size="10" value="<?php echo htmlspecialchars($due_date) ?>">
126
 
 
127
 
<?php
128
 
        if ($GLOBALS['browser']->hasFeature('javascript')) {
129
 
            Horde_Core_Ui_JsCalendar::init(array(
130
 
                'full_weekdays' => true
131
 
            ));
132
 
            $GLOBALS['page_output']->addScriptFile('calendar.js');
133
 
            echo '<span id="due_wday"></span>' .
134
 
                Horde::img('calendar.png', _("Calendar"), 'id="dueimg"');
135
 
        }
136
 
?>
137
 
 
138
 
<?php echo _("at") ?>
139
 
<label for="due_time" class="hidden"><?php echo _("Time") ?></label>
140
 
<input type="text" name="due[time]" id="due_time" size="8" value="<?php echo htmlspecialchars($due_time) ?>">
141
 
 
142
 
<?php
143
 
    }
144
 
 
145
 
    protected function _renderVarInput_NagAlarm($form, $var, $vars)
146
 
    {
147
 
        $varname = htmlspecialchars($var->getVarName());
148
 
        $value = $var->getValue($vars);
149
 
        if (!is_array($value)) {
150
 
            if ($value) {
151
 
                if ($value % 10080 == 0) {
152
 
                    $value = array('value' => $value / 10080, 'unit' => 10080);
153
 
                } elseif ($value % 1440 == 0) {
154
 
                    $value = array('value' => $value / 1440, 'unit' => 1440);
155
 
                } elseif ($value % 60 == 0) {
156
 
                    $value = array('value' => $value / 60, 'unit' => 60);
157
 
                } else {
158
 
                    $value = array('value' => $value, 'unit' => 1);
159
 
                }
160
 
                $value['on'] = true;
161
 
            }
162
 
        }
163
 
        $units = array(1 => _("Minute(s)"), 60 => _("Hour(s)"),
164
 
                       1440 => _("Day(s)"), 10080 => _("Week(s)"));
165
 
        $options = '';
166
 
        foreach ($units as $unit => $label) {
167
 
            $options .= '<option value="' . $unit;
168
 
            if ($value && $value['on'] && $value['unit'] == $unit) {
169
 
                $options .= '" selected="selected';
170
 
            }
171
 
            $options .= '">' . $label . '</option>';
172
 
        }
173
 
 
174
 
        return sprintf('<input id="%soff" type="radio" class="radio" name="%s[on]" value="0"%s /><label for="%soff">&nbsp;%s</label><br />',
175
 
                       $varname,
176
 
                       $varname,
177
 
                       $value['on'] ? '' : ' checked="checked"',
178
 
                       $varname,
179
 
                       _("None"))
180
 
            . sprintf('<input id="%son" type="radio" class="radio" name="%s[on]" value="1"%s />',
181
 
                      $varname,
182
 
                      $varname,
183
 
                      $value['on'] ? ' checked="checked"' : '')
184
 
            . sprintf('<input type="text" size="2" name="%s[value]" id="%s_value" value="%s" />',
185
 
                      $varname,
186
 
                      $varname,
187
 
                      $value['on'] ? htmlspecialchars($value['value']) : 15)
188
 
            . sprintf(' <select name="%s[unit]" id="%s_unit">%s</select>',
189
 
                      $varname,
190
 
                      $varname,
191
 
                      $options);
192
 
    }
193
 
 
194
 
    /**
195
 
     * Render tag field.
196
 
     */
197
 
    protected function _renderVarInput_NagTags($form, $var, $vars)
198
 
    {
199
 
        $varname = htmlspecialchars($var->getVarName());
200
 
        $value = $var->getValue($vars);
201
 
 
202
 
        $html = sprintf('<input id="%s" type="text" name="%s" value="%s" />', $varname, $varname, $value);
203
 
        $html .= sprintf('<span id="%s_loading_img" style="display:none;">%s</span>',
204
 
            $varname,
205
 
            Horde::img('loading.gif', _("Loading...")));
206
 
 
207
 
        $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create('Nag_Ajax_Imple_TagAutoCompleter', array('id' => $varname));
208
 
        return $html;
209
 
    }
210
 
 
211
 
    /**
212
 
     * Render the search due date fields
213
 
     */
214
 
    public function _renderVarInput_NagSearchDue($form, $var, $vars)
215
 
    {
216
 
        $html = sprintf(
217
 
            _("%s %s days of %s"),
218
 
            Horde::label('due_within', _("Is due within")),
219
 
            '<input id="due_within" name="due_within" type="number" size="2" value="' . $vars->get('due_within') . '" />',
220
 
            '<input id="due_of" name="due_of" type="text" value="' . $vars->get('due_of') . '" />')
221
 
            . '<div class="horde-form-field-description">' . _("E.g., Is due within 2 days of today") . '</div>';
222
 
 
223
 
        return $html;
224
 
    }
225
 
 
226
 
}