00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class HtmlHelper extends Helper {
00036
00037
00038
00039
00040
00041
00042 var $base = null;
00043
00044
00045
00046
00047
00048
00049 var $here = null;
00050
00051
00052
00053
00054
00055
00056 var $params = array();
00057
00058
00059
00060
00061
00062
00063 var $action = null;
00064
00065
00066
00067
00068
00069
00070 var $data = null;
00071
00072
00073
00074
00075
00076
00077 var $model = null;
00078
00079
00080
00081
00082
00083 var $field = null;
00084
00085
00086
00087
00088
00089
00090 var $_crumbs = array();
00091
00092
00093
00094
00095
00096
00097
00098
00099 function addCrumb($name, $link) {
00100 $this->_crumbs[] = array($name, $link);
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110 function charset($charset = null, $return = false) {
00111 if (is_null($charset)) {
00112 $charset = 'utf-8';
00113 }
00114 return $this->output(sprintf($this->tags['charset'], $charset), $return);
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 function url($url = null, $return = false) {
00131 if (isset($this->plugin)) {
00132 $base = strip_plugin($this->base, $this->plugin);
00133 } else {
00134 $base = $this->base;
00135 }
00136
00137 if (empty($url)) {
00138 return $this->here;
00139 } elseif ($url{0} == '/') {
00140 $output = $base . $url;
00141 } else {
00142 $output = $base . '/' . Inflector::underscore($this->params['controller']) . '/' . $url;
00143 }
00144
00145 return $this->output($output, $return);
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true, $return = false) {
00166 if ($escapeTitle === true) {
00167 $title = htmlspecialchars($title, ENT_QUOTES);
00168 } elseif (is_string($escapeTitle)) {
00169 $title = htmlentities($title, ENT_QUOTES);
00170 }
00171 $url = $url ? $url : $title;
00172
00173 if ($confirmMessage) {
00174 $confirmMessage = str_replace("'", "\'", $confirmMessage);
00175 $confirmMessage = str_replace('"', '\"', $confirmMessage);
00176 $htmlAttributes['onclick']="return confirm('{$confirmMessage}');";
00177 }
00178
00179 if (((strpos($url, ':
00180 $output = sprintf($this->tags['link'], $url, $this->_parseAttributes($htmlAttributes), $title);
00181 } else {
00182 $output = sprintf($this->tags['link'], $this->url($url, true), $this->_parseAttributes($htmlAttributes), $title);
00183 }
00184 return $this->output($output, $return);
00185 }
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 function submit($caption = 'Submit', $htmlAttributes = array(), $return = false) {
00196 $htmlAttributes['value'] = $caption;
00197 return $this->output(sprintf($this->tags['submit'], $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
00198 }
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 function password($fieldName, $htmlAttributes = array(), $return = false) {
00209 $this->setFormTag($fieldName);
00210 if (!isset($htmlAttributes['value'])) {
00211 $htmlAttributes['value'] = $this->tagValue($fieldName);
00212 }
00213 if (!isset($htmlAttributes['id'])) {
00214 $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
00215 }
00216
00217 if ($this->tagIsInvalid($this->model, $this->field)) {
00218 if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") {
00219 $htmlAttributes['class'] .= ' form_error';
00220 } else {
00221 $htmlAttributes['class'] = 'form_error';
00222 }
00223 }
00224 return $this->output(sprintf($this->tags['password'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return);
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 function textarea($fieldName, $htmlAttributes = array(), $return = false) {
00236 $this->setFormTag($fieldName);
00237 $value = $this->tagValue($fieldName);
00238 if (!empty($htmlAttributes['value'])) {
00239 $value = $htmlAttributes['value'];
00240 unset($htmlAttributes['value']);
00241 }
00242 if (!isset($htmlAttributes['id'])) {
00243 $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
00244 }
00245
00246 if ($this->tagIsInvalid($this->model, $this->field)) {
00247 if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") {
00248 $htmlAttributes['class'] .= ' form_error';
00249 } else {
00250 $htmlAttributes['class'] = 'form_error';
00251 }
00252 }
00253 return $this->output(sprintf($this->tags['textarea'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' '), $value), $return);
00254 }
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 function checkbox($fieldName, $title = null, $htmlAttributes = array(), $return = false) {
00266 $value = $this->tagValue($fieldName);
00267 $notCheckedValue = 0;
00268
00269 if (!isset($htmlAttributes['id'])) {
00270 $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
00271 }
00272
00273 if (isset($htmlAttributes['checked'])) {
00274 if ($htmlAttributes['checked'] == 'checked' || intval($htmlAttributes['checked']) === 1 || $htmlAttributes['checked'] === true) {
00275 $htmlAttributes['checked'] = 'checked';
00276 } else {
00277 $htmlAttributes['checked'] = null;
00278 $notCheckedValue = -1;
00279 }
00280 } else {
00281 if (isset($htmlAttributes['value']) || (!class_exists($this->model) && !loadModel($this->model))) {
00282 $htmlAttributes['checked'] = ($htmlAttributes['value'] == $value) ? 'checked' : null;
00283
00284 if ($htmlAttributes['value'] == '0') {
00285 $notCheckedValue = -1;
00286 }
00287 } else {
00288 $model = new $this->model;
00289 $db =& ConnectionManager::getDataSource($model->useDbConfig);
00290 $value = $db->boolean($value);
00291 $htmlAttributes['checked'] = $value ? 'checked' : null;
00292 $htmlAttributes['value'] = 1;
00293 }
00294 }
00295
00296 $output = $this->hidden($fieldName, array('value' => $notCheckedValue, 'id' => $htmlAttributes['id'] . '_'), true);
00297 $output .= sprintf($this->tags['checkbox'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, '', ' '));
00298 return $this->output($output, $return);
00299 }
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 function css($path, $rel = 'stylesheet', $htmlAttributes = array(), $return = false) {
00311 $url = "{$this->webroot}" . (COMPRESS_CSS ? 'c' : '') . $this->themeWeb . CSS_URL . $path . ".css";
00312
00313 if ($rel == 'import') {
00314 return $this->output(sprintf($this->tags['style'], $this->parseHtmlOptions($htmlAttributes, null, '', ' '), '@import url(' . $url . ');'), $return);
00315 } else {
00316 return $this->output(sprintf($this->tags['css'], $rel, $url, $this->parseHtmlOptions($htmlAttributes, null, '', ' ')), $return);
00317 }
00318 }
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328 function file($fieldName, $htmlAttributes = array(), $return = false) {
00329 if (strpos($fieldName, '/')) {
00330 $this->setFormTag($fieldName);
00331 if (!isset($htmlAttributes['id'])) {
00332 $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
00333 }
00334 return $this->output(sprintf($this->tags['file'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
00335 }
00336 return $this->output(sprintf($this->tags['file_no_model'], $fieldName, $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
00337 }
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347 function getCrumbs($separator = '»', $startText = false, $return = false) {
00348 if (count($this->_crumbs)) {
00349 $out = array();
00350 if ($startText) {
00351 $out[] = $this->link($startText, '/');
00352 }
00353
00354 foreach ($this->_crumbs as $crumb) {
00355 $out[] = $this->link($crumb[0], $crumb[1]);
00356 }
00357 return $this->output(join($separator, $out), $return);
00358 } else {
00359 return null;
00360 }
00361 }
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 function hidden($fieldName, $htmlAttributes = array(), $return = false) {
00372 $this->setFormTag($fieldName);
00373 if (!isset($htmlAttributes['value'])) {
00374 $htmlAttributes['value'] = $this->tagValue($fieldName);
00375 }
00376 if (!isset($htmlAttributes['id'])) {
00377 $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
00378 }
00379 return $this->output(sprintf($this->tags['hidden'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return);
00380 }
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390 function image($path, $htmlAttributes = array(), $return = false) {
00391 if (strpos($path, ':
00392 $url = $path;
00393 } else {
00394 $url = $this->webroot . $this->themeWeb . IMAGES_URL . $path;
00395 }
00396 return $this->output(sprintf($this->tags['image'], $url, $this->parseHtmlOptions($htmlAttributes, null, '', ' ')), $return);
00397 }
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407 function input($fieldName, $htmlAttributes = array(), $return = false) {
00408 $this->setFormTag($fieldName);
00409 if (!isset($htmlAttributes['value'])) {
00410 $htmlAttributes['value'] = $this->tagValue($fieldName);
00411 }
00412
00413 if (!isset($htmlAttributes['type'])) {
00414 $htmlAttributes['type'] = 'text';
00415 }
00416
00417 if (!isset($htmlAttributes['id'])) {
00418 $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
00419 }
00420
00421 if ($this->tagIsInvalid($this->model, $this->field)) {
00422 if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") {
00423 $htmlAttributes['class'] .= ' form_error';
00424 } else {
00425 $htmlAttributes['class'] = 'form_error';
00426 }
00427 }
00428 return $this->output(sprintf($this->tags['input'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return);
00429 }
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 function selectTag($fieldName, $optionElements, $selected = null, $selectAttr = array(), $optionAttr = null, $showEmpty = true, $return = false) {
00444 $this->setFormTag($fieldName);
00445 if ($this->tagIsInvalid($this->model, $this->field)) {
00446 if (isset($selectAttr['class']) && trim($selectAttr['class']) != "") {
00447 $selectAttr['class'] .= ' form_error';
00448 } else {
00449 $selectAttr['class'] = 'form_error';
00450 }
00451 }
00452 if (!isset($selectAttr['id'])) {
00453 $selectAttr['id'] = $this->model . Inflector::camelize($this->field);
00454 }
00455
00456 if (!is_array($optionElements)) {
00457 return null;
00458 }
00459
00460 if (!isset($selected)) {
00461 $selected = $this->tagValue($fieldName);
00462 }
00463
00464 if (isset($selectAttr) && array_key_exists("multiple", $selectAttr)) {
00465 $select[] = sprintf($this->tags['selectmultiplestart'], $this->model, $this->field, $this->parseHtmlOptions($selectAttr));
00466 } else {
00467 $select[] = sprintf($this->tags['selectstart'], $this->model, $this->field, $this->parseHtmlOptions($selectAttr));
00468 }
00469
00470 if ($showEmpty == true) {
00471 $select[] = sprintf($this->tags['selectempty'], $this->parseHtmlOptions($optionAttr));
00472 }
00473
00474 foreach ($optionElements as $name => $title) {
00475 $optionsHere = $optionAttr;
00476
00477 if (($selected != null) && ($selected == $name)) {
00478 $optionsHere['selected'] = 'selected';
00479 } elseif (is_array($selected) && in_array($name, $selected)) {
00480 $optionsHere['selected'] = 'selected';
00481 }
00482
00483 $select[] = sprintf($this->tags['selectoption'], $name, $this->parseHtmlOptions($optionsHere), h($title));
00484 }
00485
00486 $select[] = sprintf($this->tags['selectend']);
00487 return $this->output(implode("\n", $select), $return);
00488 }
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500 function radio($fieldName, $options, $inbetween = null, $htmlAttributes = array(), $return = false) {
00501
00502 $this->setFormTag($fieldName);
00503 $value = isset($htmlAttributes['value']) ? $htmlAttributes['value'] : $this->tagValue($fieldName);
00504 $out = array();
00505
00506 foreach ($options as $optValue => $optTitle) {
00507 $optionsHere = array('value' => $optValue);
00508 if ($value !== false && $optValue == $value) {
00509 $optionsHere['checked'] = 'checked';
00510 }
00511 $parsedOptions = $this->parseHtmlOptions(array_merge($htmlAttributes, $optionsHere), null, '', ' ');
00512 $individualTagName = "{$this->field}_{$optValue}";
00513 $out[] = sprintf($this->tags['radio'], $this->model, $this->field, $individualTagName, $parsedOptions, $optTitle);
00514 }
00515
00516 $out = join($inbetween, $out);
00517 return $this->output($out ? $out : null, $return);
00518 }
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530 function dayOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00531 if (empty($selected) && $this->tagValue($tagName)) {
00532 $selected = date('d', strtotime($this->tagValue($tagName)));
00533 }
00534 $dayValue = empty($selected) ? ($showEmpty == true ? NULL : date('d')) : $selected;
00535 $days = array('01' => '1', '02' => '2', '03' => '3', '04' => '4', '05' => '5', '06' => '6', '07' => '7', '08' => '8', '09' => '9', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27', '28' => '28', '29' => '29', '30' => '30', '31' => '31');
00536 $option = $this->selectTag($tagName . "_day", $days, $dayValue, $selectAttr, $optionAttr, $showEmpty);
00537 return $option;
00538 }
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552 function yearOptionTag($tagName, $value = null, $minYear = null, $maxYear = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00553 if (empty($selected) && ($this->tagValue($tagName))) {
00554 $selected = date('Y', strtotime($this->tagValue($tagName)));
00555 }
00556
00557 $yearValue = empty($selected) ? ($showEmpty ? NULL : date('Y')) : $selected;
00558 $currentYear = date('Y');
00559 $maxYear = is_null($maxYear) ? $currentYear + 11 : $maxYear + 1;
00560 $minYear = is_null($minYear) ? $currentYear - 60 : $minYear;
00561
00562 if ($minYear > $maxYear) {
00563 $tmpYear = $minYear;
00564 $minYear = $maxYear;
00565 $maxYear = $tmpYear;
00566 }
00567
00568 $minYear = $currentYear < $minYear ? $currentYear : $minYear;
00569 $maxYear = $currentYear > $maxYear ? $currentYear : $maxYear;
00570
00571 for ($yearCounter = $minYear; $yearCounter < $maxYear; $yearCounter++) {
00572 $years[$yearCounter] = $yearCounter;
00573 }
00574
00575 return $this->selectTag($tagName . "_year", $years, $yearValue, $selectAttr, $optionAttr, $showEmpty);
00576 }
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588 function monthOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00589 if (empty($selected) && ($this->tagValue($tagName))) {
00590 $selected = date('m', strtotime($this->tagValue($tagName)));
00591 }
00592 $monthValue = empty($selected) ? ($showEmpty ? NULL : date('m')) : $selected;
00593 $months = array('01' => 'January', '02' => 'February', '03' => 'March', '04' => 'April', '05' => 'May', '06' => 'June', '07' => 'July', '08' => 'August', '09' => 'September', '10' => 'October', '11' => 'November', '12' => 'December');
00594
00595 return $this->selectTag($tagName . "_month", $months, $monthValue, $selectAttr, $optionAttr, $showEmpty);
00596 }
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608 function hourOptionTag($tagName, $value = null, $format24Hours = false, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00609 if (empty($selected) && ($this->tagValue($tagName))) {
00610 if ($format24Hours) {
00611 $selected = date('H', strtotime($this->tagValue($tagName)));
00612 } else {
00613 $selected = date('g', strtotime($this->tagValue($tagName)));
00614 }
00615 }
00616 if ($format24Hours) {
00617 $hourValue = empty($selected) ? ($showEmpty ? NULL : date('H')) : $selected;
00618 } else {
00619 $hourValue = empty($selected) ? ($showEmpty ? NULL : date('g')) : $selected;
00620 if (isset($selected) && intval($hourValue) == 0 && !$showEmpty) {
00621 $hourValue = 12;
00622 }
00623 }
00624
00625 if ($format24Hours) {
00626 $hours = array('00' => '00', '01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23');
00627 } else {
00628 $hours = array('01' => '1', '02' => '2', '03' => '3', '04' => '4', '05' => '5', '06' => '6', '07' => '7', '08' => '8', '09' => '9', '10' => '10', '11' => '11', '12' => '12');
00629 }
00630
00631 $option = $this->selectTag($tagName . "_hour", $hours, $hourValue, $selectAttr, $optionAttr, $showEmpty);
00632 return $option;
00633 }
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644 function minuteOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00645 if (empty($selected) && ($this->tagValue($tagName))) {
00646 $selected = date('i', strtotime($this->tagValue($tagName)));
00647 }
00648 $minValue = empty($selected) ? ($showEmpty ? NULL : date('i')) : $selected;
00649
00650 for ($minCount = 0; $minCount < 60; $minCount++) {
00651 $mins[sprintf('%02d', $minCount)] = sprintf('%02d', $minCount);
00652 }
00653 $option = $this->selectTag($tagName . "_min", $mins, $minValue, $selectAttr, $optionAttr, $showEmpty);
00654 return $option;
00655 }
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667 function meridianOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00668 if (empty($selected) && ($this->tagValue($tagName))) {
00669 $selected = date('a', strtotime($this->tagValue($tagName)));
00670 }
00671 $merValue = empty($selected) ? ($showEmpty ? NULL : date('a')) : $selected;
00672 $meridians = array('am' => 'am', 'pm' => 'pm');
00673
00674 $option = $this->selectTag($tagName . "_meridian", $meridians, $merValue, $selectAttr, $optionAttr, $showEmpty);
00675 return $option;
00676 }
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688 function dateTimeOptionTag($tagName, $dateFormat = 'DMY', $timeFormat = '12', $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {
00689 $day = null;
00690 $month = null;
00691 $year = null;
00692 $hour = null;
00693 $min = null;
00694 $meridian = null;
00695
00696 if (empty($selected)) {
00697 $selected = $this->tagValue($tagName);
00698 }
00699
00700 if (!empty($selected)) {
00701
00702 if (is_int($selected)) {
00703 $selected = strftime('%Y-%m-%d %H:%M:%S', $selected);
00704 }
00705
00706 $meridian = 'am';
00707 $pos = strpos($selected, '-');
00708 if ($pos !== false) {
00709 $date = explode('-', $selected);
00710 $days = explode(' ', $date[2]);
00711 $day = $days[0];
00712 $month = $date[1];
00713 $year = $date[0];
00714 } else {
00715 $days[1] = $selected;
00716 }
00717
00718 if ($timeFormat != 'NONE' && !empty($timeFormat)) {
00719 $time = explode(':', $days[1]);
00720 $check = str_replace(':', '', $days[1]);
00721
00722 if (($check > 115959) && $timeFormat == '12') {
00723 $time[0] = $time[0] - 12;
00724 $meridian = 'pm';
00725 } elseif ($time[0] > 12) {
00726 $meridian = 'pm';
00727 }
00728
00729 $hour = $time[0];
00730 $min = $time[1];
00731 }
00732 }
00733
00734 $elements = array('Day','Month','Year','Hour','Minute','Meridian');
00735 if (isset($selectAttr['id'])) {
00736 if (is_string($selectAttr['id'])) {
00737
00738 foreach ($elements as $element) {
00739 $selectAttrName = 'select' . $element . 'Attr';
00740 ${$selectAttrName} = $selectAttr;
00741 ${$selectAttrName}['id'] = $selectAttr['id'] . $element;
00742 }
00743 } elseif (is_array($selectAttr['id'])) {
00744
00745 foreach ($elements as $element) {
00746 $selectAttrName = 'select' . $element . 'Attr';
00747 ${$selectAttrName} = $selectAttr;
00748 ${$selectAttrName}['id'] = $selectAttr['id'][strtolower($element)];
00749 }
00750 }
00751 } else {
00752
00753 foreach ($elements as $element) {
00754 $selectAttrName = 'select' . $element . 'Attr';
00755 ${$selectAttrName} = $selectAttr;
00756 }
00757 }
00758
00759 switch($dateFormat) {
00760 case 'DMY':
00761 $opt = $this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty) . '-' .
00762 $this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' . $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty);
00763 break;
00764 case 'MDY':
00765 $opt = $this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' .
00766 $this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty) . '-' . $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty);
00767 break;
00768 case 'YMD':
00769 $opt = $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty) . '-' .
00770 $this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' .
00771 $this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty);
00772 break;
00773 case 'Y':
00774 $opt = $this->yearOptionTag($tagName, null, null, null, $selected, $selectYearAttr, $optionAttr, $showEmpty);
00775 break;
00776 case 'NONE':
00777 default:
00778 $opt = '';
00779 break;
00780 }
00781
00782 switch($timeFormat) {
00783 case '24':
00784 $opt .= $this->hourOptionTag($tagName, null, true, $hour, $selectHourAttr, $optionAttr, $showEmpty) . ':' .
00785 $this->minuteOptionTag($tagName, null, $min, $selectMinuteAttr, $optionAttr, $showEmpty);
00786 break;
00787 case '12':
00788 $opt .= $this->hourOptionTag($tagName, null, false, $hour, $selectHourAttr, $optionAttr, $showEmpty) . ':' .
00789 $this->minuteOptionTag($tagName, null, $min, $selectMinuteAttr, $optionAttr, $showEmpty) . ' ' .
00790 $this->meridianOptionTag($tagName, null, $meridian, $selectMeridianAttr, $optionAttr, $showEmpty);
00791 break;
00792 case 'NONE':
00793 default:
00794 $opt .= '';
00795 break;
00796 }
00797 return $opt;
00798 }
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809 function tableHeaders($names, $trOptions = null, $thOptions = null, $return = false) {
00810 $out = array();
00811 foreach ($names as $arg) {
00812 $out[] = sprintf($this->tags['tableheader'], $this->parseHtmlOptions($thOptions), $arg);
00813 }
00814
00815 $data = sprintf($this->tags['tablerow'], $this->parseHtmlOptions($trOptions), join(' ', $out));
00816 return $this->output($data, $return);
00817 }
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828 function tableCells($data, $oddTrOptions = null, $evenTrOptions = null, $return = false) {
00829 if (empty($data[0]) || !is_array($data[0])) {
00830 $data = array($data);
00831 }
00832 static $count = 0;
00833
00834 foreach ($data as $line) {
00835 $count++;
00836 $cellsOut = array();
00837
00838 foreach ($line as $cell) {
00839 $cellsOut[] = sprintf($this->tags['tablecell'], null, $cell);
00840 }
00841 $options = $this->parseHtmlOptions($count % 2 ? $oddTrOptions : $evenTrOptions);
00842 $out[] = sprintf($this->tags['tablerow'], $options, join(' ', $cellsOut));
00843 }
00844 return $this->output(join("\n", $out), $return);
00845 }
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857 function guiListTree($data, $htmlAttributes = array(), $bodyKey = 'body', $childrenKey = 'children', $return = false) {
00858 $out="<ul" . $this->_parseAttributes($htmlAttributes) . ">\n";
00859 foreach ($data as $item) {
00860 $out .= "<li>{$item[$bodyKey]}\n";
00861 if (isset($item[$childrenKey]) && is_array($item[$childrenKey]) && count($item[$childrenKey])) {
00862 $out .= $this->guiListTree($item[$childrenKey], $htmlAttributes, $bodyKey, $childrenKey);
00863 }
00864 $out .= "</li>\n";
00865 }
00866 $out .= "</ul>\n";
00867 return $this->output($out, $return);
00868 }
00869
00870
00871
00872
00873
00874
00875
00876 function tagValue($fieldName, $escape = false) {
00877 $this->setFormTag($fieldName);
00878 if (isset($this->params['data'][$this->model][$this->field])) {
00879 return ife($escape, h($this->params['data'][$this->model][$this->field]), $this->params['data'][$this->model][$this->field]);
00880 } elseif (isset($this->data[$this->model][$this->field])) {
00881 return ife($escape, h($this->data[$this->model][$this->field]), $this->data[$this->model][$this->field]);
00882 }
00883 return false;
00884 }
00885
00886
00887
00888
00889
00890
00891
00892
00893 function tagIsInvalid($model, $field) {
00894 return empty($this->validationErrors[$model][$field]) ? 0 : $this->validationErrors[$model][$field];
00895 }
00896
00897
00898
00899
00900
00901
00902 function validate() {
00903 $args = func_get_args();
00904 $errors = call_user_func_array(array(&$this, 'validateErrors'), $args);
00905 return count($errors);
00906 }
00907
00908
00909
00910
00911
00912
00913 function validateErrors() {
00914 $objects = func_get_args();
00915 if (!count($objects)) {
00916 return false;
00917 }
00918
00919 $errors = array();
00920 foreach ($objects as $object) {
00921 $errors = array_merge($errors, $object->invalidFields($object->data));
00922 }
00923 return $this->validationErrors = (count($errors) ? $errors : false);
00924 }
00925
00926
00927
00928
00929
00930
00931
00932
00933 function tagErrorMsg($field, $text) {
00934 $error = 1;
00935 $this->setFormTag($field);
00936 if ($error == $this->tagIsInvalid($this->model, $this->field)) {
00937 return sprintf('<div class="error_message">%s</div>', is_array($text) ? (empty($text[$error - 1]) ? 'Error in field' : $text[$error - 1]) : $text);
00938 } else {
00939 return null;
00940 }
00941 }
00942
00943
00944
00945
00946
00947
00948
00949 function setFormTag($tagValue) {
00950 return list($this->model, $this->field) = explode("/", $tagValue);
00951 }
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984 function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
00985 if (is_array($options)) {
00986 $default = array (
00987 'escape' => true
00988 );
00989 $options = am($default, $options);
00990 if (!is_array($exclude)) {
00991 $exclude = array();
00992 }
00993 $exclude = am($exclude, array('escape'));
00994 $keys = array_diff(array_keys($options), $exclude);
00995 $values = array_intersect_key(array_values($options), $keys);
00996 $escape = $options['escape'];
00997 $attributes = array();
00998 foreach ($keys as $index => $key) {
00999 $attributes[] = $this->__formatAttribute($key, $values[$index], $escape);
01000 }
01001 $out = implode(' ', $attributes);
01002 } else {
01003 $out = $options;
01004 }
01005 return $out ? $insertBefore . $out . $insertAfter : '';
01006 }
01007
01008
01009
01010
01011
01012
01013 function __formatAttribute($key, $value, $escape = true) {
01014 $attribute = '';
01015 $attributeFormat = '%s="%s"';
01016 $minimizedAttributes = array('compact', 'checked', 'declare', 'readonly', 'disabled', 'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize');
01017
01018 if (in_array($key, $minimizedAttributes)) {
01019 if ($value === 1 || $value === true || $value === 'true' || $value == $key) {
01020 $attribute = sprintf($attributeFormat, $key, $key);
01021 }
01022 } else {
01023 $attribute = sprintf($attributeFormat, $key, ife($escape, h($value), $value));
01024 }
01025 return $attribute;
01026 }
01027
01028
01029
01030
01031 function areaTag($tagName, $cols = 60, $rows = 10, $htmlAttributes = array(), $return = false) {
01032 $htmlAttributes['cols']=$cols;
01033 $htmlAttributes['rows']=$rows;
01034 return $this->textarea($tagName, $htmlAttributes, $return);
01035 }
01036
01037
01038
01039
01040 function charsetTag($charset, $return = false) {
01041 return $this->charset($charset, $return);
01042 }
01043
01044
01045
01046
01047 function checkboxTag($fieldName, $title = null, $htmlAttributes = array(), $return = false) {
01048 return $this->checkbox($fieldName, $title, $htmlAttributes, $return);
01049 }
01050
01051
01052
01053
01054 function cssTag($path, $rel = 'stylesheet', $htmlAttributes = array(), $return = false) {
01055 return $this->css($path, $rel, $htmlAttributes, $return);
01056 }
01057
01058
01059
01060
01061 function fileTag($fieldName, $htmlAttributes = array(), $return = false) {
01062 return $this->file($fieldName, $htmlAttributes, $return);
01063 }
01064
01065
01066
01067
01068 function hiddenTag($tagName, $value = null, $htmlOptions = null) {
01069 $this->setFormTag($tagName);
01070 $htmlOptions['value'] = $value ? $value : $this->tagValue($tagName);
01071 return $this->output(sprintf($this->tags['hidden'], $this->model, $this->field, $this->parseHtmlOptions($htmlOptions, null, '', ' ')));
01072 }
01073
01074
01075
01076
01077 function imageTag($path, $alt = null, $htmlAttributes = array(), $return = false) {
01078 $htmlAttributes['alt'] = $alt;
01079 return $this->image($path, $htmlAttributes, $return);
01080 }
01081
01082
01083
01084
01085 function inputTag($tagName, $size = 20, $htmlOptions = null) {
01086 $this->setFormTag($tagName);
01087 $htmlOptions['value'] = isset($htmlOptions['value']) ? $htmlOptions['value'] : $this->tagValue($tagName);
01088 $this->tagIsInvalid($this->model, $this->field) ? $htmlOptions['class'] = 'form_error' : null;
01089 return $this->output(sprintf($this->tags['input'], $this->model, $this->field, $this->parseHtmlOptions($htmlOptions, null, '', ' ')));
01090 }
01091
01092
01093
01094
01095 function linkOut($title, $url = null, $htmlAttributes = array(), $escapeTitle = true, $return = false) {
01096 return $this->link($title, $url, $htmlAttributes, false, $escapeTitle, $return);
01097 }
01098
01099
01100
01101
01102 function linkTo($title, $url, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true, $return = false) {
01103 return $this->link($title, $url, $htmlAttributes, $confirmMessage, $escapeTitle, $return);
01104 }
01105
01106
01107
01108
01109 function parseHtmlOptions($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
01110 if (!is_array($exclude))
01111 $exclude=array();
01112
01113 if (is_array($options)) {
01114 $out=array();
01115
01116 foreach ($options as $k => $v) {
01117 if (!in_array($k, $exclude)) {
01118 $out[] = "{$k}=\"{$v}\"";
01119 }
01120 }
01121 $out = join(' ', $out);
01122 return $out ? $insertBefore . $out . $insertAfter : null;
01123 } else {
01124 return $options ? $insertBefore . $options . $insertAfter : null;
01125 }
01126 }
01127
01128
01129
01130
01131 function passwordTag($fieldName, $size = 20, $htmlAttributes = array(), $return = false) {
01132 $args = func_get_args();
01133 return call_user_func_array(array(&$this,
01134 "password"), $args);
01135 }
01136
01137
01138
01139
01140 function radioTags($fieldName, $options, $inbetween = null, $htmlAttributes = array(), $return = false) {
01141 return $this->radio($fieldName, $options, $inbetween, $htmlAttributes, $return);
01142 }
01143
01144
01145
01146
01147 function urlFor($url) {
01148 return $this->url($url);
01149 }
01150
01151
01152
01153
01154 function submitTag() {
01155 $args = func_get_args();
01156 return call_user_func_array(array(&$this, "submit"), $args);
01157 }
01158
01159
01160
01161
01162
01163
01164 function trim() {
01165 die("Method HtmlHelper::trim() was moved to TextHelper::trim().");
01166 }
01167
01168
01169
01170 function javascriptIncludeTag($url) {
01171 die("Method HtmlHelper::javascriptIncludeTag() was moved to JavascriptHelper::link().");
01172 }
01173
01174
01175
01176 function javascriptTag($script) {
01177 die("Method HtmlHelper::javascriptTag() was moved to JavascriptHelper::codeBlock().");
01178 }
01179
01180
01181
01182
01183
01184 function formTag($target = null, $type = 'post', $htmlAttributes = array()) {
01185 $htmlAttributes['action']=$this->urlFor ($target);
01186 $htmlAttributes['method']=$type == 'get' ? 'get' : 'post';
01187 $type == 'file' ? $htmlAttributes['enctype'] = 'multipart/form-data' : null;
01188
01189 $append = '';
01190
01191 if (isset($this->params['_Token']) && !empty($this->params['_Token'])) {
01192 $append .= '<p style="display: inline; margin: 0px; padding: 0px;">';
01193 $append .= $this->hidden('_Token/key', array('value' => $this->params['_Token']['key'], 'id' => '_TokenKey' . mt_rand()), true);
01194 $append .= '</p>';
01195 }
01196
01197 return sprintf($this->tags['form'], $this->parseHtmlOptions($htmlAttributes, null, '')) . $append;
01198 }
01199
01200
01201
01202
01203 function linkEmail($title, $email = null, $options = null) {
01204
01205 if (empty($email))
01206 $email=$title;
01207
01208 $match=array();
01209
01210
01211 preg_match('!^(.*)(\?.*)$!', $email, $match);
01212
01213
01214 if (empty($options['encode']) || !empty($match[2])) {
01215 return sprintf($this->tags['mailto'], $email, $this->parseHtmlOptions($options), $title);
01216 }
01217
01218 else {
01219 $email_encoded=null;
01220
01221 for ($ii = 0; $ii < strlen($email); $ii++) {
01222 if (preg_match('!\w!', $email[$ii])) {
01223 $email_encoded .= '%' . bin2hex($email[$ii]);
01224 } else {
01225 $email_encoded .= $email[$ii];
01226 }
01227 }
01228
01229 $title_encoded=null;
01230
01231 for ($ii = 0; $ii < strlen($title); $ii++) {
01232 $title_encoded .= preg_match('/^[A-Za-z0-9]$/', $title[$ii])
01233 ? '&#x' . bin2hex($title[$ii]) . ';' : $title[$ii];
01234 }
01235
01236 return sprintf($this->tags['mailto'], $email_encoded,
01237 $this->parseHtmlOptions($options, array('encode')), $title_encoded);
01238 }
01239 }
01240
01241
01242
01243
01244 function tag($name, $options = null, $open = false) {
01245 $tag = "<$name " . $this->parseHtmlOptions($options);
01246 $tag .= $open ? ">" : " />";
01247 return $tag;
01248 }
01249
01250
01251
01252 function contentTag($name, $content, $options = null) {
01253 return "<$name " . $this->parseHtmlOptions($options) . ">$content</$name>";
01254 }
01255
01256 }
01257 ?>