Subversion Repositories Applications.bazar

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
468 mathias 1
<?php
2
 
3
/*
4
 * phpMyEdit - instant MySQL table editor and code generator
5
 *
6
 * extensions/phpMyEdit-calpopup.class.php - phpMyEdit calendar popup extension
7
 * ____________________________________________________________
8
 *
9
 * Contribution of Adam Hammond <php@pixolet.co.uk>, London, UK
10
 * Copyright (c) 2003-2006 Platon Group, http://platon.sk/
11
 * All rights reserved.
12
 *
13
 * See README file for more information about this software.
14
 * See COPYING file for license information.
15
 *
16
 * Download the latest version from
17
 * http://platon.sk/projects/phpMyEdit/
18
 */
19
 
20
/* $Platon: phpMyEdit/extensions/phpMyEdit-calpopup.class.php,v 1.9 2006-01-22 21:44:17 nepto Exp $ */
21
 
22
/*
23
    OVERVIEW
24
    --------
25
 
26
	NOTE...This extension will not work with the CVS version of PME
27
 
28
    calPopup extends the standard phpMyEdit class to allow
29
    a calendar popup helper to be put on any text field.
30
    This extension uses the free jsCalendar code from
31
    http://dynarch.com/mishoo/calendar.epl website.
32
 
33
    REQUIREMENTS
34
    ------------
35
 
36
    The requirement is a properly installed jsCalendar script.
37
    All browsers supported by jsCalendar are supported by this
38
    extension.
39
 
40
    USAGE
41
    -----
42
 
43
    This extension enables the display of a popup calendar selection
44
    against selected fields.
45
 
46
    In order to use it, you should:
47
 
48
    1. Load the jsCalendar scripts in the <head>...</head> section of
49
       your phpMyEdit calling program, substituting the correct paths:
50
 
51
       <script type="text/javascript" src="js/calendar.js"></script>
52
       <script type="text/javascript" src="js/lang/calendar-en.js"></script>
53
       <script type="text/javascript" src="js/calendar-setup.js"></script>
54
 
55
    2. Choose your preferred jsCalendar CSS file (see jsCalendar
56
       documentation) and add the following in the <head>...</head>
57
       section of your phpMyEdit calling program, substituting the
58
       correct path:
59
 
60
        <link rel="stylesheet" type="text/css" media="screen"
61
                href="css/calendar-system.css">
62
 
63
       NOTE: To avoid an unwanted side effect in the CSS style
64
       produced by phpMyEditSetup.php, add a 'width:auto' property
65
       into the '.calendar table' entry in your selected jsCalendar
66
       style sheet.
67
 
68
    3. Call to phpMyEdit-calPopup.class.php instead
69
       of phpMyEdit.class.php.
70
 
71
       Example:
72
 
73
       require_once 'extensions/phpMyEdit-calpopup.class.php';
74
       new phpMyEdit_calpopup($opts);
75
 
76
    4. Add 'calendar' parameter to the field definitions where you
77
       want a calendar popup in your phpMyEdit calling program.
78
 
79
       Example:
80
 
81
       $opts['fdd']['col_name'] = array(
82
         'name'     => 'Column',
83
         'select'   => 'T',
84
         'options'  => 'ACPVD',
85
         'required' => true,
86
         'calendar' => true
87
       );
88
 
89
       This is will display a button next to the field which pops up
90
       a calendar when clicked. If that field has a 'strftimemask'
91
       parameter set, it will use this for the date format.
92
 
93
       For more advanced usage, you can set the 'calendar' parameter
94
       to an array of valid jsCalendar Calendar.setup options
95
       (see jSCalendar document for details). Note that not all
96
       of these options make sense to use in phpMyEdit, and some
97
       of them will actively break the function.
98
 
99
       Example:
100
 
101
       $opts['fdd']['col_name'] = array(
102
         'name'     => 'Column',
103
         'select'   => 'T',
104
         'options'  => 'ACPVD',
105
         'required' => true,
106
         'calendar' => array(
107
           'ifFormat'    => '%Y/%m/%d', // defaults to the ['strftimemask']
108
           'firstDay'    => 1,          // 0 = Sunday, 1 = Monday
109
           'singleClick' => true,       // single or double click to close
110
           'weekNumbers' => true,       // Show week numbers
111
           'showsTime'   => false,      // Show time as well as date
112
           'timeFormat'  => '24',       // 12 or 24 hour clock
113
		   'label'       => '...',      // button label (used by phpMyEdit)
114
           'date'        => '2003-12-19 10:00' // Initial date/time for popup
115
                                               // (see notes below)
116
         )
117
       );
118
 
119
    NOTES
120
    -----
121
 
122
    1. The popup will normally set the initial value to the current
123
       field value or to current date/time. 'date' option will always
124
       override this, even if there is a current date/time value
125
       in the field. If you want a default value only if the field
126
       is currently empty, use the phpMyEdit 'default' option.
127
 
128
    2. Only the options listed above may be set by the user, any other
129
       options will be ignored.
130
 
131
    SEARCH KEYWORD
132
    --------------
133
 
134
	Search for "CalPopup" string in this source code,
135
	to find all extension related modifications.
136
*/
137
 
138
require_once dirname(__FILE__).'/../phpMyEdit.class.php';
139
 
140
class phpMyEdit_calpopup extends phpMyEdit
141
{
142
	/* CalPopup mod start */
143
 
144
	/* Array for collecting list of fields with calendar popups */
145
	var $calendars;
146
 
147
	/* Array of valid options for passing to Calendar.setup */
148
	var $valid_opts = array(
149
			'button','ifFormat','singleClick','firstDay',
150
			'weekNumbers','showsTime','timeFormat','date'
151
			);
152
 
153
	/**
154
	 * Checks to see if the calendar parameter is set on the field
155
	 *
156
	 * @param	k			current field name
157
	 * @param	curval		current value of field (set to null for default)
158
	 *
159
	 * If the calendar parameter is set on the field, this function displays
160
	 * the button. It then pushes the Calendar.setup parameters into an array,
161
	 * including the user specified ones in the calling program is they exist.
162
	 * This array is then added to the $calendars array indexed by the field
163
	 * name. This allows for multiple fields with calendar popups.
164
	 */
165
	function CalPopup_helper($k, $curval) /* {{{ */
166
	{
167
		if (@$this->fdd[$k]['calendar']) {
168
			$cal_ar['ifFormat']    = '%Y-%m-%d %H:%M';
169
			$cal_ar['showsTime']   = true;
170
			$cal_ar['singleClick'] = false;
171
			if (isset($curval)) {
172
				if (substr($curval, 0, 4) != '0000')
173
					$cal_ar['date'] = $curval;
174
			}
175
			if (isset($this->fdd[$k]['strftimemask'])) {
176
				$cal_ar['ifFormat'] = $this->fdd[$k]['strftimemask'];
177
			}
178
			if (is_array($this->fdd[$k]['calendar'])) {
179
				foreach($this->fdd[$k]['calendar'] as $ck => $cv) {
180
					$cal_ar[$ck] = $cv;
181
				}
182
			}
183
			$cal_ar['button'] = 'pme_calpopup_button_'.$this->fds[$k];
184
			$this->calendars[$this->fds[$k]] = $cal_ar;
185
			$label = @$this->fdd[$k]['calendar']['label'];
186
			strlen($label) || $label = '...';
187
			echo '<button id="',$cal_ar['button'],'">',$label,'</button>';
188
		}
189
	} /* }}} */
190
 
191
	/* CalPopup mod end */
192
 
193
	function display_add_record() /* {{{ */
194
	{
195
		for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) {
196
			if (isset($this->fdd[$k]['tab']) && $this->tabs_enabled() && $k > 0) {
197
				$tab++;
198
				echo '</table>',"\n";
199
				echo '</div>',"\n";
200
				echo '<div id="phpMyEdit_tab',$tab,'">',"\n";
201
				echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
202
			}
203
			if (! $this->displayed[$k]) {
204
				continue;
205
			}
206
			if ($this->hidden($k)) {
207
				echo $this->htmlHidden($this->fds[$k], $row["qf$k"]);
208
				continue;
209
			}
210
			$css_postfix    = @$this->fdd[$k]['css']['postfix'];
211
			$css_class_name = $this->getCSSclass('input', null, 'next', $css_postfix);
212
			echo '<tr class="',$this->getCSSclass('row', null, true, $css_postfix),'">',"\n";
213
			echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">',$this->fdd[$k]['name'],'</td>',"\n";
214
			echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
215
			echo $this->getColAttributes($k),">\n";
216
			if ($this->col_has_values($k)) {
217
				$vals       = $this->set_values($k);
218
				$selected   = @$this->fdd[$k]['default'];
219
				$multiple   = $this->col_has_multiple_select($k);
220
				$readonly   = $this->readonly($k);
221
				$strip_tags = true;
222
				$escape     = true;
223
				echo $this->htmlSelect($this->fds[$k], $css_class_name, $vals, $selected,
224
						$multiple, $readonly, $strip_tags, $escape);
225
			} elseif (isset ($this->fdd[$k]['textarea'])) {
226
				echo '<textarea class="',$css_class_name,'" name="',$this->fds[$k],'"';
227
				echo ($this->readonly($k) ? ' disabled' : '');
228
				if (intval($this->fdd[$k]['textarea']['rows']) > 0) {
229
					echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"';
230
				}
231
				if (intval($this->fdd[$k]['textarea']['cols']) > 0) {
232
					echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"';
233
				}
234
				if (isset($this->fdd[$k]['textarea']['wrap'])) {
235
					echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"';
236
				} else {
237
					echo ' wrap="virtual"';
238
				}
239
				echo '>',htmlspecialchars($this->fdd[$k]['default']),'</textarea>',"\n";
240
			} else {
241
				// Simple edit box required
242
				$size_ml_props = '';
243
				$maxlen = intval($this->fdd[$k]['maxlen']);
244
				$size   = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60);
245
				$size   && $size_ml_props .= ' size="'.$size.'"';
246
				$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"';
247
 
248
				/* CalPopup mod start */
249
				if (@$this->fdd[$k]['calendar']) {
250
					$size_ml_props .= ' id="pme_calpopup_input_'.$this->fds[$k].'"';
251
				}
252
				/* CalPopup mod end */
253
 
254
				echo '<input class="',$css_class_name,'" type="text" ';
255
				echo ($this->readonly($k) ? 'disabled ' : ''),' name="',$this->fds[$k],'"';
256
				echo $size_ml_props,' value="';
257
				echo htmlspecialchars($this->fdd[$k]['default']),'">';
258
 
259
                /* CalPopup mod start */
260
				/* Call CalPopup helper function */
261
				$this->CalPopup_helper($k, null);
262
				/* CalPopup mod end */
263
    		}
264
			echo '</td>',"\n";
265
			if ($this->guidance) {
266
				$css_class_name = $this->getCSSclass('help', null, true, $css_postfix);
267
				$cell_value     = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : '&nbsp;';
268
				echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n";
269
			}
270
			echo '</tr>',"\n";
271
		}
272
	} /* }}} */
273
 
274
	function display_change_field($row, $k) /* {{{ */
275
	{
276
		$css_postfix    = @$this->fdd[$k]['css']['postfix'];
277
		$css_class_name = $this->getCSSclass('input', null, true, $css_postfix);
278
		echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
279
		echo $this->getColAttributes($k),">\n";
280
		if ($this->col_has_values($k)) {
281
			$vals       = $this->set_values($k);
282
			$multiple   = $this->col_has_multiple_select($k);
283
			$readonly   = $this->readonly($k);
284
			$strip_tags = true;
285
			$escape     = true;
286
			echo $this->htmlSelect($this->fds[$k], $css_class_name, $vals, $row["qf$k"],
287
					$multiple, $readonly, $strip_tags, $escape);
288
		} elseif (isset($this->fdd[$k]['textarea'])) {
289
			echo '<textarea class="',$css_class_name,'" name="',$this->fds[$k],'"';
290
			echo ($this->readonly($k) ? ' disabled' : '');
291
			if (intval($this->fdd[$k]['textarea']['rows']) > 0) {
292
				echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"';
293
			}
294
			if (intval($this->fdd[$k]['textarea']['cols']) > 0) {
295
				echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"';
296
			}
297
			if (isset($this->fdd[$k]['textarea']['wrap'])) {
298
				echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"';
299
			} else {
300
				echo ' wrap="virtual"';
301
			}
302
			echo '>',htmlspecialchars($row["qf$k"]),'</textarea>',"\n";
303
		} else {
304
			$size_ml_props = '';
305
			$maxlen = intval($this->fdd[$k]['maxlen']);
306
			$size   = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60);
307
			$size   && $size_ml_props .= ' size="'.$size.'"';
308
			$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"';
309
 
310
			/* CalPopup mod start */
311
			if (@$this->fdd[$k]['calendar']) {
312
				$size_ml_props .= ' id="pme_calpopup_input_'.$this->fds[$k].'"';
313
			}
314
			/* CalPopup mod end */
315
 
316
			echo '<input class="',$css_class_name,'" type="text" ';
317
			echo ($this->readonly($k) ? 'disabled ' : ''),'name="',$this->fds[$k],'" value="';
318
			echo htmlspecialchars($row["qf$k"]),'" ',$size_ml_props,'>',"\n";
319
 
320
            /* CalPopup mod start */
321
			/* Call CalPopup helper function */
322
			$this->CalPopup_helper($k, htmlspecialchars($row["qf$k"]));
323
			/* CalPopup mod end */
324
		}
325
		echo '</td>',"\n";
326
	} /* }}} */
327
 
328
	function form_end() /* {{{ */
329
	{
330
		if ($this->display['form']) {
331
			echo '</form>',"\n";
332
 
333
			/* CalPopup mod start */
334
 
335
			/* Add script calls to the end of the form for all fields
336
			   with calendar popups. */
337
			if (isset($this->calendars)) {
338
				echo '<script type="text/javascript"><!--',"\n";
339
				foreach($this->calendars as $ck => $cv) {
340
					echo 'Calendar.setup({',"\n";
341
					foreach ($cv as $ck1 => $cv1) {
342
						if (in_array($ck1, $this->valid_opts)) {
343
							echo "\t",str_pad($ck1, 15),' : "',$cv1,'",',"\n";
344
						}
345
					}
346
					echo "\t",str_pad('inputField', 15),' : "pme_calpopup_input_',$ck,'"',"\n";
347
					echo '});',"\n";
348
				};
349
				echo '// --></script>',"\n";
350
			};
351
 
352
			/* CalPopup mod end */
353
		};
354
	} /* }}} */
355
}
356
 
357
?>