Subversion Repositories eFlore/Applications.cel

Rev

Rev 419 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
419 aurelien 1
<?php
2
 
3
/*
4
 * phpMyEdit - instant MySQL table editor and code generator
5
 *
6
 * extensions/phpMyEdit-mce-cal.class.php - phpMyEdit html area & calendar popup extension
7
 * ____________________________________________________________
8
 *
9
 * Contribution of Adam Hammond <php@pixolet.co.uk>, London, UK
10
 * Contribution of Ezudin Kurtowich <ekurtovic@ieee.org>, Sarajevo
11
 * Copyright (c) 2003-2006 Platon Group, http://platon.sk/
12
 * All rights reserved.
13
 *
14
 * Updated 28th Jul 2005
15
 *
16
 * Updated to use TinyMCE instead of HTMLArea
17
 * Updated to handle multiple tabs and to use PME prefixes.
18
 * Updated to include sub-form patch
19
 *
20
 *
21
 *
22
 * See README file for more information about this software.
23
 * See COPYING file for license information.
24
 *
25
 * Download the latest version from
26
 * http://platon.sk/projects/phpMyEdit/
27
 */
28
 
29
/* $Platon: phpMyEdit/extensions/phpMyEdit-mce-cal.class.php,v 1.6 2006-09-16 18:43:47 nepto Exp $ */
30
 
31
/*
32
    OVERVIEW
33
    --------
34
 
35
    mce_cal extends the standard phpMyEdit class to allow
36
    a calendar popup helper to be put on any text field and for any textarea
37
	field to turned into an HTML editor.
38
    This extension uses the free jsCalendar from http://dynarch.com/mishoo
39
	and the TinyMCE code from http://tinymce.moxiecode.com/
40
 
41
    REQUIREMENTS
42
    ------------
43
 
44
    The requirement is a properly installed jsCalendar and TinyMCE script.
45
    All browsers supported by these scripts are supported by this
46
    extension. Note that version 1.44 or later for TinyMCE is required.
47
 
48
    USAGE
49
    -----
50
 
51
	For both features:
52
 
53
    1. Call to phpMyEdit-mce-cal.class.php instead
54
       of phpMyEdit.class.php.
55
 
56
       Example:
57
 
58
       require_once 'extensions/phpMyEdit-mce-cal.class.php';
59
       new phpMyEdit_mce_cal($opts);
60
 
61
 
62
 
63
	HTML TextArea
64
 
65
    This enables WYSIWYG editing of a textarea field.
66
    In order to use it, you should:
67
 
68
    1. 	Load TinyMCE script in the <head>...</head> section of your
69
       	phpMyEdit calling program as described in the htmlarea manual.
70
 
71
       	<!-- tinyMCE -->
72
		<script language="javascript" type="text/javascript" src="js/<path to TinyMCE>"></script>
73
		<script language="javascript" type="text/javascript">
74
   		tinyMCE.init({
75
      		mode : "specific_textareas",
76
      		auto_reset_designmode : true
77
   		});
78
		</script>
79
		<!-- /tinyMCE -->
80
 
81
      	where 'js/<path to TinyMCE>' is the path to the javascript code
82
 
83
		NOTES:
84
		A.  The PME implementation uses the "specific_textareas" mode - this
85
		    must always be set
86
 
87
		B.	Due to a bug in Mozilla, if any of the textareas being used as HTML
88
			editors are in tabs and are initially hidden, the width and height
89
			need to be specified in the tinyMCE initialization and
90
			'auto_reset_designmode' must be set to 'true':
91
 
92
			tinyMCE.init({
93
      			mode : "specific_textareas",
94
      			auto_reset_designmode : true,
95
      			width: "800",
96
      			height: "200"
97
   			});
98
 
99
    2. 	Add 'html'=>true parameter to the textarea field definition
100
       	in your phpMyEdit calling program.
101
 
102
       	Example:
103
 
104
       	$opts['fdd']['col_name'] = array(
105
         	'name'     => 'Column',
106
         	'select'   => 'T',
107
         	'options'  => 'ACPVD',
108
         	'required' => true,
109
         	'textarea' => array(
110
           		'html' => true,
111
           		'rows' => 11,
112
           		'cols' => 81)
113
       	);
114
 
115
	3.  It is also possible to have multiple text area formats on the same
116
		form. This is done by specifying a text tag for the textarea:
117
 
118
       	$opts['fdd']['col_name'] = array(
119
         	'name'     => 'Column',
120
         	'select'   => 'T',
121
         	'options'  => 'ACPVD',
122
         	'required' => true,
123
         	'textarea' => array(
124
           		'html' => 'format1',
125
           		'rows' => 11,
126
           		'cols' => 81)
127
       	);
128
 
129
		You then need to initialize TinyMCE in the header to recognize all of
130
		the tags used in the textareas.
131
 
132
		EXAMPLE
133
		In the following, two formats of tinyMCE editor are defined.
134
 
135
		This example is the default, and will be used for any fields where
136
		'html' is set to true.
137
 
138
				tinyMCE.init({
139
   					mode : "specific_textareas",
140
   					auto_reset_designmode : true
141
				});
142
 
143
		This second example has an extra parameter, 'textarea_trigger', which is
144
		set to the text tag given to the textarea in PME with 'mce_' prepended
145
		to it.
146
 
147
			tinyMCE.init({
148
   				mode : "specific_textareas",
149
   				auto_reset_designmode : true,
150
				textarea_trigger : "mce_format1",
151
   				theme : "advanced",
152
   				width: "800",
153
   				height: "200",
154
   				plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print",
155
				theme_advanced_buttons1_add_before : "save,separator",
156
				theme_advanced_buttons1_add : "fontselect,fontsizeselect",
157
				theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
158
				theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator",
159
				theme_advanced_buttons3_add_before : "tablecontrols,separator",
160
				theme_advanced_buttons3_add : "emotions,iespell,flash,advhr,separator,print",
161
				theme_advanced_toolbar_location : "top",
162
				theme_advanced_toolbar_align : "left",
163
				theme_advanced_path_location : "bottom",
164
				content_css : "example_full.css",
165
	    		plugin_insertdate_dateFormat : "%Y-%m-%d",
166
	    		plugin_insertdate_timeFormat : "%H:%M:%S",
167
				extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]"
168
 
169
		});
170
 
171
		So:
172
			'html' => 'format1'     maps to     textarea_trigger : "mce_format1"
173
			'html' => 'foo'     	maps to     textarea_trigger : "mce_foo"
174
            'html' => 'bar'		    maps to     textarea_trigger : "mce_bar"
175
 
176
		You can initialize TinyMCE as many times as you need to give you as many
177
		editor formats as you need.
178
 
179
	CALENDAR
180
 
181
    This extension enables the display of a popup calendar selection
182
    against selected fields.
183
 
184
    In order to use it, you should:
185
 
186
    1. Load the jsCalendar scripts in the <head>...</head> section of
187
       your phpMyEdit calling program, substituting the correct paths:
188
 
189
       <script type="text/javascript" src="js/jscalendar/calendar.js"></script>
190
       <script type="text/javascript" src="js/jscalendar/lang/calendar-en.js"></script>
191
       <script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script>
192
 
193
    2. Choose your preferred jsCalendar CSS file (see jsCalendar
194
       documentation) and add the following in the <head>...</head>
195
       section of your phpMyEdit calling program, substituting the
196
       correct path:
197
 
198
        <link rel="stylesheet" type="text/css" media="screen"
199
                href="js/jscalendar/calendar-system.css">
200
 
201
    3. Add 'calendar' parameter to the field definitions where you
202
       want a calendar popup in your phpMyEdit calling program.
203
 
204
       Example:
205
 
206
       $opts['fdd']['col_name'] = array(
207
         'name'     => 'Column',
208
         'select'   => 'T',
209
         'options'  => 'ACPVD',
210
         'required' => true,
211
         'calendar' => true
212
       );
213
 
214
       This is will display a button next to the field which pops up
215
       a calendar when clicked. If that field has a 'strftimemask'
216
       parameter set, it will use this for the date format.
217
 
218
       For more advanced usage, you can set the 'calendar' parameter
219
       to an array of valid jsCalendar Calendar.setup options
220
       (see jSCalendar document for details). Note that not all
221
       of these options make sense to use in phpMyEdit, and some
222
       of them will actively break the function.
223
 
224
       Example:
225
 
226
       $opts['fdd']['col_name'] = array(
227
         'name'     => 'Column',
228
         'select'   => 'T',
229
         'options'  => 'ACPVD',
230
         'required' => true,
231
         'calendar' => array(
232
           'ifFormat'    => '%Y/%m/%d', // defaults to the ['strftimemask']
233
           'firstDay'    => 1,          // 0 = Sunday, 1 = Monday
234
           'singleClick' => true,       // single or double click to close
235
           'weekNumbers' => true,       // Show week numbers
236
           'showsTime'   => false,      // Show time as well as date
237
           'timeFormat'  => '24',       // 12 or 24 hour clock
238
           'button'      => true,       // Display button (rather then clickable area)
239
		   'label'       => '...',      // button label (used by phpMyEdit)
240
           'date'        => '2003-12-19 10:00' // Initial date/time for popup
241
                                               // (see notes below)
242
         )
243
       );
244
 
245
    NOTES
246
    -----
247
 
248
    1. The popup will normally set the initial value to the current
249
       field value or to current date/time. 'date' option will always
250
       override this, even if there is a current date/time value
251
       in the field. If you want a default value only if the field
252
       is currently empty, use the phpMyEdit 'default' option.
253
 
254
    2. Only the options listed above may be set by the user, any other
255
       options will be ignored.
256
 
257
	3. The 'label' option can contain HTML markup which will be displayed as
258
	   the button/clickable area to pull up the calendar
259
 
260
    SEARCH KEYWORD
261
    --------------
262
 
263
	Search for "htmlcal" string in this source code,
264
	to find all extension related modifications.
265
*/
266
 
267
require_once dirname(__FILE__).'/../phpMyEdit.class.php';
268
 
269
class phpMyEdit_mce_cal extends phpMyEdit
270
{
271
	/* calendar mod start */
272
 
273
	var $calendars; // Array for collecting list of fields with calendar popups
274
 
275
	/* Array of valid options for passing to Calendar.setup */
276
	var $valid_opts = array(
277
			'button','ifFormat','singleClick','firstDay',
278
			'weekNumbers','showsTime','timeFormat','date'
279
			);
280
 
281
	/**
282
	 * Checks to see if the calendar parameter is set on the field
283
	 *
284
	 * @param	k			current field name
285
	 * @param	curval		current value of field (set to null for default)
286
	 *
287
	 * If the calendar parameter is set on the field, this function displays
288
	 * the button. It then pushes the Calendar.setup parameters into an array,
289
	 * including the user specified ones in the calling program is they exist.
290
	 * This array is then added to the $calendars array indexed by the field
291
	 * name. This allows for multiple fields with calendar popups.
292
	 */
293
	function calPopup_helper($k, $curval) /* {{{ */
294
	{
295
		if (@$this->fdd[$k]['calendar']) {
296
			$cal_ar['ifFormat']    = '%Y-%m-%d %H:%M';
297
			$cal_ar['showsTime']   = true;
298
			$cal_ar['singleClick'] = false;
299
			if (isset($curval)) {
300
				if (substr($curval, 0, 4) != '0000')
301
					$cal_ar['date'] = $curval;
302
			}
303
			if (isset($this->fdd[$k]['strftimemask'])) {
304
				$cal_ar['ifFormat'] = $this->fdd[$k]['strftimemask'];
305
			}
306
			if (is_array($this->fdd[$k]['calendar'])) {
307
				foreach($this->fdd[$k]['calendar'] as $ck => $cv) {
308
					$cal_ar[$ck] = $cv;
309
				}
310
			}
311
			$cal_ar['button'] = $this->dhtml['prefix'].'calbutton_'.$this->fds[$k];
312
			$this->calendars[$this->fds[$k]] = $cal_ar;
313
 
314
			$label = @$this->fdd[$k]['calendar']['label'];
315
			strlen($label) || $label = '...';
316
 
317
			$do_button = true;
318
			if (isset($this->fdd[$k]['calendar']['button'])) {
319
				$do_button = $this->fdd[$k]['calendar']['button'];
320
			};
321
 
322
   			if ($do_button) {
323
            	echo '<button id="',$cal_ar['button'],'">',$label,'</button>';
324
   			} else {
325
				echo '<span style="cursor: pointer" id="',$cal_ar['button'],'">',$label,'</span>';
326
			}
327
		}
328
	} /* }}} */
329
 
330
	/* calendar mod end */
331
 
332
	function display_add_record() /* {{{ */
333
	{
334
		for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) {
335
			if (isset($this->fdd[$k]['tab']) && $this->tabs_enabled() && $k > 0) {
336
				$tab++;
337
				echo '</table>',"\n";
338
				echo '</div>',"\n";
339
				echo '<div id="'.$this->dhtml['prefix'].'tab',$tab,'">',"\n";
340
				echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
341
			}
342
			if (! $this->displayed[$k]) {
343
				continue;
344
			}
345
			if ($this->hidden($k)) {
346
				echo $this->htmlHiddenData($this->fds[$k], $this->fdd[$k]['default']);
347
				continue;
348
			}
349
			$css_postfix    = @$this->fdd[$k]['css']['postfix'];
350
			$css_class_name = $this->getCSSclass('input', null, 'next', $css_postfix);
351
			echo '<tr class="',$this->getCSSclass('row', null, true, $css_postfix),'">',"\n";
352
			echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">';
353
			echo $this->fdd[$k]['name'],'</td>',"\n";
354
			echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
355
			echo $this->getColAttributes($k),">\n";
356
			if ($this->col_has_values($k)) {
357
				$vals       = $this->set_values($k);
358
				$selected   = @$this->fdd[$k]['default'];
359
				$multiple   = $this->col_has_multiple_select($k);
360
				$readonly   = $this->readonly($k);
361
				$strip_tags = true;
362
				$escape     = true;
363
				echo $this->htmlSelect($this->cgi['prefix']['data'].$this->fds[$k], $css_class_name,
364
						$vals, $selected, $multiple, $readonly, $strip_tags, $escape);
365
			} elseif (isset ($this->fdd[$k]['textarea'])) {
366
				echo '<textarea class="',$css_class_name,'" name="',$this->cgi['prefix']['data'].$this->fds[$k],'"';
367
				echo ($this->readonly($k) ? ' disabled' : '');
368
				if (intval($this->fdd[$k]['textarea']['rows']) > 0) {
369
					echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"';
370
				}
371
				if (intval($this->fdd[$k]['textarea']['cols']) > 0) {
372
					echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"';
373
				}
374
				if (isset($this->fdd[$k]['textarea']['wrap'])) {
375
					echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"';
376
				} else {
377
					echo ' wrap="virtual"';
378
				};
379
				// mce mod start
380
				if (isset($this->fdd[$k]['textarea']['html'])) {
381
				    $mce_tag = 'editable';
382
				    if (is_string($this->fdd[$k]['textarea']['html'])) {
383
				        $mce_tag = $this->fdd[$k]['textarea']['html'];
384
				    };
385
					echo ' mce_'.$mce_tag.'=true ';
386
                };
387
                // mce mod end
388
				echo '>',htmlspecialchars($this->fdd[$k]['default']),'</textarea>',"\n";
389
			} else {
390
				// Simple edit box required
391
				$size_ml_props = '';
392
				$maxlen = intval($this->fdd[$k]['maxlen']);
393
				$size   = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60);
394
				$size   && $size_ml_props .= ' size="'.$size.'"';
395
				$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"';
396
				echo '<input class="',$css_class_name,'" ';
397
				echo ($this->password($k) ? 'type="password"' : 'type="text"');
398
				echo ($this->readonly($k) ? ' disabled' : '');
399
				/* calendar mod start */
400
				echo ' id="',$this->dhtml['prefix'].'fld_'.$this->fds[$k],'"';
401
				/* calendar mod end */
402
				echo ' name="',$this->cgi['prefix']['data'].$this->fds[$k],'"';
403
				echo $size_ml_props,' value="';
404
				echo htmlspecialchars($this->fdd[$k]['default']),'">';
405
                /* calendar mod start */
406
				/* Call htmlcal helper function */
407
				$this->calPopup_helper($k, null);
408
				/* calendar mod end */
409
			}
410
			echo '</td>',"\n";
411
			if ($this->guidance) {
412
				$css_class_name = $this->getCSSclass('help', null, true, $css_postfix);
413
				$cell_value     = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : '&nbsp;';
414
				echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n";
415
			}
416
			echo '</tr>',"\n";
417
		}
418
	} /* }}} */
419
 
420
	function display_change_field($row, $k) /* {{{ */
421
	{
422
		$css_postfix    = @$this->fdd[$k]['css']['postfix'];
423
		$css_class_name = $this->getCSSclass('input', null, true, $css_postfix);
424
		echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
425
		echo $this->getColAttributes($k),">\n";
426
		if ($this->col_has_values($k)) {
427
			$vals       = $this->set_values($k);
428
			$multiple   = $this->col_has_multiple_select($k);
429
			$readonly   = $this->readonly($k);
430
			$strip_tags = true;
431
			$escape     = true;
432
			echo $this->htmlSelect($this->cgi['prefix']['data'].$this->fds[$k], $css_class_name,
433
					$vals, $row["qf$k"], $multiple, $readonly, $strip_tags, $escape);
434
		} elseif (isset($this->fdd[$k]['textarea'])) {
435
			echo '<textarea class="',$css_class_name,'" name="',$this->cgi['prefix']['data'].$this->fds[$k],'"';
436
			echo ($this->readonly($k) ? ' disabled' : '');
437
			if (intval($this->fdd[$k]['textarea']['rows']) > 0) {
438
				echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"';
439
			}
440
			if (intval($this->fdd[$k]['textarea']['cols']) > 0) {
441
				echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"';
442
			}
443
			if (isset($this->fdd[$k]['textarea']['wrap'])) {
444
				echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"';
445
			} else {
446
				echo ' wrap="virtual"';
447
			};
448
			// mce mod start
449
			if (isset($this->fdd[$k]['textarea']['html'])) {
450
				$mce_tag = 'editable';
451
				if (is_string($this->fdd[$k]['textarea']['html'])) {
452
				    $mce_tag = $this->fdd[$k]['textarea']['html'];
453
				};
454
				echo ' mce_'.$mce_tag.'=true ';
455
            };
456
            // mce mod end
457
			echo '>',htmlspecialchars($row["qf$k"]),'</textarea>',"\n";
458
		} else {
459
			$size_ml_props = '';
460
			$maxlen = intval($this->fdd[$k]['maxlen']);
461
			$size   = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60);
462
			$size   && $size_ml_props .= ' size="'.$size.'"';
463
			$maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"';
464
			echo '<input class="',$css_class_name,'" type="text" ';
465
			echo ($this->readonly($k) ? 'disabled ' : '');
466
			/* calendar mod start */
467
			echo ' id="',$this->dhtml['prefix'].'fld_'.$this->fds[$k],'"';
468
			/* calendar mod end */
469
			echo 'name="',$this->cgi['prefix']['data'].$this->fds[$k],'" value="';
470
			echo htmlspecialchars($row["qf$k"]),'" ',$size_ml_props,'>',"\n";
471
            /* calendar mod start */
472
			/* Call calPopup helper function */
473
			$this->calPopup_helper($k, htmlspecialchars($row["qf$k"]));
474
			/* calendar mod end */
475
		}
476
		echo '</td>',"\n";
477
	} /* }}} */
478
 
479
	function form_end() /* {{{ */
480
	{
481
		if ($this->display['form']) {
482
			echo '</form>',"\n";
483
 
484
			/* calendar mod start */
485
 
486
			/* Add script calls to the end of the form for all fields
487
			   with calendar popups. */
488
			if (isset($this->calendars)) {
489
				echo '<script type="text/javascript"><!--',"\n";
490
				foreach($this->calendars as $ck => $cv) {
491
					echo 'Calendar.setup({',"\n";
492
					foreach ($cv as $ck1 => $cv1) {
493
						if (in_array($ck1, $this->valid_opts)) {
494
							echo "\t",str_pad($ck1, 15),' : "',$cv1,'",',"\n";
495
						}
496
					}
497
					echo "\t",str_pad('inputField', 15),' : "',$this->dhtml['prefix'].'fld_'.$ck,'"',"\n";
498
					echo '});',"\n";
499
				};
500
				echo '// -->',"\n";
501
				echo '</script>',"\n";
502
			};
503
			/* calendar mod end */
504
		};
505
	} /* }}} */
506
 
507
}
508
 
509
?>