1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12:
13: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
14:
15: 16: 17: 18: 19: 20:
21: class PifaFieldCollection extends ItemCollection {
22:
23: 24: 25: 26: 27:
28: public function __construct($where = false) {
29: parent::__construct(cRegistry::getDbTableName('pifa_field'), 'idfield');
30: $this->_setItemClass('PifaField');
31: if (false !== $where) {
32: $this->select($where);
33: }
34: }
35:
36: 37: 38: 39: 40: 41:
42: public static function reorder($idform, $idfields) {
43: $sql = "-- PifaFieldCollection::reorder()
44: UPDATE
45: " . cRegistry::getDbTableName('pifa_field') . "
46: SET
47: field_rank = FIND_IN_SET(idfield, '$idfields')
48: WHERE
49: idform = $idform
50: ;";
51:
52: cRegistry::getDb()->query($sql);
53: }
54: }
55:
56: 57: 58: 59: 60: 61:
62: class PifaField extends Item {
63:
64: 65: 66: 67: 68: 69: 70: 71: 72:
73: const VARCHAR_SIZE = 255;
74:
75: 76: 77: 78: 79:
80: const INPUTTEXT = 1;
81:
82: 83: 84: 85: 86:
87: const TEXTAREA = 2;
88:
89: 90: 91: 92: 93:
94: const INPUTPASSWORD = 3;
95:
96: 97: 98: 99: 100:
101: const INPUTRADIO = 4;
102:
103: 104: 105: 106: 107:
108: const INPUTCHECKBOX = 5;
109:
110: 111: 112: 113: 114:
115: const SELECT = 6;
116:
117: 118: 119: 120: 121:
122: const SELECTMULTI = 7;
123:
124: 125: 126: 127: 128:
129: const DATEPICKER = 8;
130:
131: 132: 133: 134: 135:
136: const INPUTFILE = 9;
137:
138: 139: 140: 141: 142:
143: const PROCESSBAR = 10;
144:
145: 146: 147: 148: 149:
150: const SLIDER = 11;
151:
152: 153: 154: 155: 156:
157: const CAPTCHA = 12;
158:
159: 160: 161: 162: 163:
164: const BUTTONSUBMIT = 13;
165:
166: 167: 168: 169: 170:
171: const BUTTONRESET = 14;
172:
173: 174: 175: 176: 177: 178:
179: const BUTTONBACK = 15;
180:
181: 182: 183: 184: 185:
186: const BUTTON = 15;
187:
188: 189: 190: 191:
192: const MATRIX = 16;
193:
194: 195: 196: 197: 198: 199:
200: const PARA = 17;
201:
202: 203: 204: 205: 206:
207: const INPUTHIDDEN = 18;
208:
209: 210: 211: 212: 213:
214: const FIELDSET_BEGIN = 19;
215:
216: 217: 218: 219: 220:
221: const FIELDSET_END = 20;
222:
223: 224: 225: 226: 227:
228: const BUTTONIMAGE = 21;
229:
230: 231: 232: 233: 234:
235: private $_value = NULL;
236:
237: 238: 239: 240: 241:
242: private $_file = NULL;
243:
244: 245: 246: 247: 248:
249: public function __construct($id = false) {
250: parent::__construct(cRegistry::getDbTableName('pifa_field'), 'idfield');
251: $this->setFilters(array(), array());
252: if (false !== $id) {
253: $this->loadByPrimaryKey($id);
254: }
255: }
256:
257: 258: 259: 260: 261: 262:
263: function getField($field, $bSafe = true) {
264: $value = parent::getField($field, $bSafe);
265: if ('rule' === $field) {
266: $value = stripslashes($value);
267: }
268: return $value;
269: }
270:
271: 272: 273:
274: public function getLastError() {
275: return $this->lasterror;
276: }
277:
278: 279: 280: 281: 282:
283: public function getValue() {
284: return $this->_value;
285: }
286:
287: 288: 289: 290:
291: public function setValue($value) {
292: $this->_value = $value;
293: }
294:
295: 296: 297: 298: 299:
300: public function getFile() {
301: return $this->_file;
302: }
303:
304: 305: 306: 307:
308: public function setFile(array $_file) {
309: $this->_file = $_file;
310: }
311:
312: 313: 314: 315:
316: public function validate() {
317:
318:
319: $values = $this->getValue();
320: if (NULL === $values) {
321: $values = $this->get('default_value');
322: }
323:
324:
325:
326: if (!is_array($values)) {
327: $values = array(
328: $values
329: );
330: }
331:
332: foreach ($values as $value) {
333: if (self::CAPTCHA == $this->get('field_type')) {
334:
335: $secret = getEffectiveSetting('pifa-recaptcha', 'secret', '');
336:
337: if (cString::getStringLength($secret) === 0 || !isset($_POST['g-recaptcha-response']) || empty($_POST['g-recaptcha-response'])) {
338: $isValid = false;
339: } else {
340:
341: $response = urlencode($_POST['g-recaptcha-response']);
342: $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $response);
343: $responseData = json_decode($verifyResponse);
344:
345: $isValid = $responseData->success ? true : false;
346: }
347: } else if (1 === cSecurity::toInteger($this->get('obligatory')) && 0 === cString::getStringLength($value)) {
348:
349: $isValid = false;
350: } else if (0 < cString::getStringLength($this->get('rule')) && in_array(preg_match($this->get('rule'), $value), array(
351: false,
352: 0
353: ))) {
354:
355: $isValid = false;
356: } else {
357: $isValid = true;
358: }
359:
360:
361: if (true !== $isValid) {
362: $error_message = $this->get('error_message');
363: if (NULL === $error_message) {
364:
365: $error_message = '';
366: }
367: throw new PifaValidationException(array(
368: $this->get('idfield') => $error_message
369: ));
370: }
371: }
372: }
373:
374: 375: 376: 377: 378: 379:
380: public function toHtml(array $errors = NULL) {
381: $out = '';
382: switch (cSecurity::toInteger($this->get('field_type'))) {
383:
384: case self::FIELDSET_BEGIN:
385:
386:
387: if (0 < cString::getStringLength(trim($this->get('css_class')))) {
388: $class = ' class="' . implode(' ', explode(',', $this->get('css_class'))) . '"';
389: }
390: $out .= "\n\t<fieldset$class>";
391:
392: if (1 === cSecurity::toInteger($this->get('display_label'))) {
393: $label = $this->get('label');
394: $out .= "\n\t<legend>$label</legend>";
395: }
396:
397: return $out;
398: break;
399:
400: case self::FIELDSET_END:
401:
402: return "\n\t</fieldset>";
403: break;
404:
405: default:
406:
407:
408: $content = array();
409: try {
410: $content[] = $this->_getElemLabel();
411: $content[] = $this->_getElemField();
412: $content[] = $this->_getElemHelp();
413: $content[] = $this->_getElemScript();
414:
415: if (isset($errors[$this->get('idfield')])) {
416: $error = $errors[$this->get('idfield')];
417: if (0 < cString::getStringLength($error)) {
418: $content[] = new cHTMLParagraph($error, 'pifa-error-message');
419: }
420: }
421: } catch (PifaNotImplementedException $e) {
422: return NULL;
423: }
424:
425: $content = array_filter($content);
426: if (empty($content)) {
427: return NULL;
428: }
429:
430:
431: $class = 'pifa-field-' . $this->get('field_type');
432:
433: if (0 < cString::getStringLength(trim($this->get('css_class')))) {
434: $class .= ' ' . implode(' ', explode(',', $this->get('css_class')));
435: }
436:
437: if (true === (bool) $this->get('obligatory')) {
438: $class .= ' pifa-obligatory';
439: }
440:
441: if (NULL !== $error) {
442: $class .= ' pifa-error';
443: }
444:
445:
446: $id = 'pifa-field-' . $this->get('idfield');
447:
448:
449: $div = new cHTMLDiv($content, $class, $id);
450:
451: return "\n\t" . $div->render();
452: break;
453: }
454: }
455:
456: 457: 458: 459: 460:
461: public function _getElemLabel() {
462: if (1 !== cSecurity::toInteger($this->get('display_label'))) {
463: return '';
464: }
465:
466:
467: $idfield = cSecurity::toInteger($this->get('idfield'));
468: $fieldType = cSecurity::toInteger($this->get('field_type'));
469: $label = strip_tags($this->get('label'));
470:
471: if (NULL === $label) {
472: return NULL;
473: }
474:
475:
476:
477: if (in_array($fieldType, array(
478: self::BUTTONSUBMIT,
479: self::BUTTONRESET,
480: self::BUTTON,
481: self::BUTTONIMAGE
482: ))) {
483: return NULL;
484: }
485:
486:
487: if (true === (bool) $this->get('obligatory')) {
488: $label .= ' *';
489: }
490:
491: $elemLabel = new cHTMLLabel($label, 'pifa-field-elm-' . $idfield, 'pifa-field-lbl');
492: if (self::INPUTRADIO === $fieldType) {
493: $elemLabel->removeAttribute('for');
494: }
495:
496: $elemLabel->removeAttribute('id');
497:
498: return $elemLabel;
499: }
500:
501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512:
513: public function _getElemField() {
514:
515:
516: $idfield = cSecurity::toInteger($this->get('idfield'));
517:
518: $fieldType = cSecurity::toInteger($this->get('field_type'));
519:
520: $columnName = $this->get('column_name');
521:
522: $label = strip_tags($this->get('label'));
523:
524: $uri = $this->get('uri');
525:
526:
527:
528: $optionClass = $this->get('option_class');
529: if (0 === cString::getStringLength(trim($optionClass))) {
530: $optionLabels = $this->get('option_labels');
531: if (NULL !== $optionLabels) {
532: $optionLabels = explode(',', $optionLabels);
533: }
534: $optionValues = $this->get('option_values');
535: if (NULL !== $optionValues) {
536: $optionValues = explode(',', $optionValues);
537: }
538: } else {
539: $filename = Pifa::fromCamelCase($optionClass);
540: $filename = "extensions/class.pifa.$filename.php";
541: if (false === file_exists(Pifa::getPath() . $filename)) {
542: $msg = Pifa::i18n('MISSING_EOD_FILE');
543: $msg = sprintf($msg, $filename);
544: throw new PifaException($msg);
545: }
546: plugin_include(Pifa::getName(), $filename);
547: if (false === class_exists($optionClass)) {
548: $msg = Pifa::i18n('MISSING_EOD_CLASS');
549: $msg = sprintf($msg, $optionClass);
550: throw new PifaException($msg);
551: }
552: $dataSource = new $optionClass();
553: $optionLabels = $dataSource->getOptionLabels();
554: $optionValues = $dataSource->getOptionValues();
555: }
556:
557:
558: $id = 'pifa-field-elm-' . $idfield;
559:
560:
561: $value = $this->getValue();
562:
563:
564: if (NULL === $value) {
565:
566: $value = $this->get('default_value');
567:
568: if (array_key_exists($columnName, $_GET)) {
569: $value = $_GET[$columnName];
570: }
571: }
572:
573:
574: if ( is_array($value) ) {
575: foreach ($value as $key => $val) {
576: $value[$key] = conHtmlentities($val, ENT_COMPAT | ENT_HTML401, 'UTF-8');
577: }
578: } else {
579: $value = conHtmlentities($value, ENT_COMPAT | ENT_HTML401, 'UTF-8');
580: }
581:
582: switch ($fieldType) {
583:
584: case self::INPUTTEXT:
585:
586: $elemField = new cHTMLTextbox($columnName);
587:
588: $elemField->removeAttribute('id')->setID($id);
589:
590: if (!is_null($this->get('default_value'))) {
591: $elemField->setAttribute('title', $this->get('default_value'));
592: }
593: if (!is_null($value)) {
594: $elemField->setValue($value);
595: }
596: break;
597:
598: case self::TEXTAREA:
599:
600: $elemField = new cHTMLTextarea($columnName);
601:
602: $elemField->removeAttribute('id')->setID($id);
603: if (!is_null($this->get('default_value'))) {
604: $elemField->setAttribute('title', $this->get('default_value'));
605: }
606: if (!is_null($value)) {
607: $elemField->setValue($value);
608: }
609: break;
610:
611: case self::INPUTPASSWORD:
612:
613: $elemField = new cHTMLPasswordbox($columnName);
614:
615: $elemField->removeAttribute('id')->setID($id);
616: if (!is_null($this->get('default_value'))) {
617: $elemField->setAttribute('title', $this->get('default_value'));
618: }
619: if (!is_null($value)) {
620: $elemField->setValue($value);
621: }
622: break;
623:
624: case self::INPUTRADIO:
625: case self::INPUTCHECKBOX:
626:
627: $count = min(array(
628: count($optionLabels),
629: count($optionValues)
630: ));
631: $tmpHtml = '';
632: for ($i = 0; $i < $count; $i++) {
633: if (self::INPUTRADIO === $fieldType) {
634: $elemField = new cHTMLRadiobutton($columnName, $optionValues[$i]);
635: } else if (self::INPUTCHECKBOX === $fieldType) {
636: $elemField = new cHTMLCheckbox($columnName . '[]', $optionValues[$i]);
637: }
638: if (!is_array($value)) {
639: $value = explode(',', $value);
640: }
641: $elemField->setChecked(in_array($optionValues[$i], $value));
642: $elemField->setLabelText($optionLabels[$i]);
643: $tmpHtml .= $elemField->render();
644: }
645: $elemField = new cHTMLSpan($tmpHtml);
646: break;
647:
648: case self::SELECT:
649: case self::SELECTMULTI:
650:
651: $elemField = new cHTMLSelectElement($columnName);
652:
653:
654: $elemField->removeAttribute('id')->setID($id);
655: $autofill = array();
656: $count = min(array(
657: count($optionLabels),
658: count($optionValues)
659: ));
660:
661: for ($i = 0; $i < $count; $i++) {
662: $autofill[$optionValues[$i]] = $optionLabels[$i];
663: }
664:
665: $elemField->autoFill($autofill);
666: $elemField->setDefault($value);
667:
668: break;
669:
670: case self::DATEPICKER:
671:
672:
673: $hiddenField = new cHTMLHiddenField($columnName);
674: $hiddenField->removeAttribute('id')->setID($id . '-hidden');
675: if (!is_null($value)) {
676: $hiddenField->setValue($value);
677: }
678:
679:
680: $textbox = new cHTMLTextbox($columnName . '_visible');
681:
682: $textbox->removeAttribute('id')->setID($id);
683:
684:
685: $elemField = new cHTMLDiv(array(
686: $hiddenField,
687: $textbox
688: ));
689:
690: break;
691:
692: case self::INPUTFILE:
693:
694: $elemField = new cHTMLUpload($columnName);
695:
696: $elemField->removeAttribute('id')->setID($id);
697: break;
698:
699: case self::PROCESSBAR:
700:
701: $elemField = NULL;
702:
703:
704: break;
705:
706: case self::SLIDER:
707:
708: $elemField = NULL;
709:
710:
711: break;
712:
713: case self::CAPTCHA:
714:
715: $elemField = new cHTMLTextbox($columnName);
716:
717: $elemField->removeAttribute('id')->setID($id);
718: if (null !== $value) {
719: $elemField->setValue($value);
720: }
721:
722:
723: $sitekey = getEffectiveSetting('pifa-recaptcha', 'sitekey', '');
724:
725: $elemScript = new cHTMLScript();
726: $elemScript->setAttribute("src", "https://www.google.com/recaptcha/api.js");
727: $elemDiv = new cHTMLDiv('<div class="g-recaptcha" data-sitekey="' . $sitekey . '"></div>');
728: $elemField = $elemScript . PHP_EOL . $elemDiv;
729:
730: break;
731:
732: case self::BUTTONSUBMIT:
733: case self::BUTTONRESET:
734: case self::BUTTON:
735: case self::BUTTONIMAGE:
736: $modes = array(
737: self::BUTTONSUBMIT => 'submit',
738: self::BUTTONRESET => 'reset',
739: self::BUTTON => 'button',
740: self::BUTTONIMAGE => 'image'
741: );
742: $mode = $modes[$fieldType];
743: $elemField = new cHTMLButton($columnName);
744:
745: $elemField->removeAttribute('id')->setID($id);
746: $elemField->setMode($mode);
747: if ('image' === $mode) {
748: $elemField->setAttribute('src', $uri);
749: $elemField->removeAttribute('value');
750: } else {
751:
752: $elemField->setTitle($label? $label : $mode);
753: }
754: break;
755:
756: case self::MATRIX:
757:
758: $elemField = NULL;
759:
760:
761: break;
762:
763: case self::PARA:
764: $elemField = NULL;
765:
766:
767: break;
768:
769: case self::INPUTHIDDEN:
770: $elemField = new cHTMLHiddenField($columnName);
771:
772: $elemField->removeAttribute('id')->setID($id);
773: if (NULL !== $value) {
774: $elemField->setValue($value);
775: }
776: break;
777:
778: default:
779: $msg = Pifa::i18n('NOT_IMPLEMENTED_FIELDTYPE');
780: $msg = sprintf($msg, $fieldType);
781: throw new PifaNotImplementedException($msg);
782: }
783:
784: return $elemField;
785: }
786:
787: 788: 789: 790: 791:
792: public function _getElemHelp() {
793: $helpText = $this->get('help_text');
794:
795: $p = NULL;
796: if (0 < cString::getStringLength($helpText)) {
797: $p = new cHTMLParagraph($helpText, 'pifa-field-help');
798: }
799:
800: return $p;
801: }
802:
803: 804: 805: 806: 807:
808: public function _getElemScript() {
809:
810:
811: $idfield = cSecurity::toInteger($this->get('idfield'));
812: $fieldType = cSecurity::toInteger($this->get('field_type'));
813:
814: switch ($fieldType) {
815: case self::DATEPICKER:
816: $sel = '#pifa-field-elm-' . $idfield;
817:
818:
819: $script = "if (typeof jQuery == \"function\") {
820: jQuery(function(){ jQuery('$sel').datepicker({
821: altFormat: 'yy-mm-dd',
822: altField: '$sel-hidden'
823: });});
824: }";
825: break;
826: default:
827: $script = '';
828: }
829:
830: $elemScript = NULL;
831: if (0 < cString::getStringLength($script)) {
832: $elemScript = new cHTMLScript();
833: $elemScript->setContent($script);
834: }
835:
836: return $elemScript;
837: }
838:
839: 840: 841: 842: 843:
844: public static function getFieldTypeIds() {
845: return array_keys(self::getFieldTypeNames());
846: }
847:
848: 849: 850: 851: 852: 853: 854: 855:
856: public static function getFieldTypeNames() {
857: return array(
858: self::INPUTTEXT => Pifa::i18n('INPUTTEXT'),
859: self::TEXTAREA => Pifa::i18n('TEXTAREA'),
860: self::INPUTPASSWORD => Pifa::i18n('INPUTPASSWORD'),
861: self::INPUTRADIO => Pifa::i18n('INPUTRADIO'),
862: self::INPUTCHECKBOX => Pifa::i18n('INPUTCHECKBOX'),
863: self::SELECT => Pifa::i18n('SELECT'),
864: self::SELECTMULTI => Pifa::i18n('SELECTMULTI'),
865: self::DATEPICKER => Pifa::i18n('DATEPICKER'),
866: self::INPUTFILE => Pifa::i18n('INPUTFILE'),
867: self::PROCESSBAR => Pifa::i18n('PROCESSBAR'),
868: self::SLIDER => Pifa::i18n('SLIDER'),
869: self::CAPTCHA => Pifa::i18n('CAPTCHA'),
870:
871: self::PARA => Pifa::i18n('PARAGRAPH'),
872: self::INPUTHIDDEN => Pifa::i18n('INPUTHIDDEN'),
873: self::FIELDSET_BEGIN => Pifa::i18n('FIELDSET_BEGIN'),
874: self::FIELDSET_END => Pifa::i18n('FIELDSET_END'),
875: self::BUTTONSUBMIT => Pifa::i18n('BUTTONSUBMIT'),
876: self::BUTTONRESET => Pifa::i18n('BUTTONRESET'),
877: self::BUTTON => Pifa::i18n('BUTTON'),
878: self::BUTTONIMAGE => Pifa::i18n('BUTTONIMAGE')
879: );
880: }
881:
882: 883: 884: 885: 886: 887:
888: public static function getFieldTypeName($fieldTypeId) {
889: $fieldTypeId = cSecurity::toInteger($fieldTypeId);
890: $fieldTypeNames = self::getFieldTypeNames();
891:
892: if (array_key_exists($fieldTypeId, $fieldTypeNames)) {
893: $fieldTypeName = $fieldTypeNames[$fieldTypeId];
894: } else {
895: $fieldTypeName = Pifa::i18n('UNKNOWN');
896: }
897:
898: return $fieldTypeName;
899: }
900:
901: 902: 903: 904: 905:
906: public function getMyFieldTypeName() {
907: return self::getFieldTypeName($this->get('field_type'));
908: }
909:
910: 911: 912: 913: 914: 915: 916:
917: public function getDbDataType() {
918: if (!$this->isLoaded()) {
919: $msg = Pifa::i18n('FIELD_LOAD_ERROR');
920: throw new PifaException($msg);
921: }
922:
923: $fieldType = cSecurity::toInteger($this->get('field_type'));
924:
925: switch ($fieldType) {
926:
927:
928:
929:
930:
931: case self::INPUTTEXT:
932: case self::INPUTPASSWORD:
933: case self::INPUTHIDDEN:
934: case self::INPUTFILE:
935:
936: return 'VARCHAR(' . self::VARCHAR_SIZE . ')';
937:
938:
939:
940: case self::INPUTCHECKBOX:
941:
942: return 'VARCHAR(' . self::VARCHAR_SIZE . ')';
943:
944:
945:
946: case self::TEXTAREA:
947:
948: return 'TEXT';
949:
950:
951:
952:
953: case self::INPUTRADIO:
954: case self::SELECT:
955: case self::SELECTMULTI:
956:
957:
958:
959:
960:
961:
962:
963:
964:
965:
966:
967:
968: return 'VARCHAR(' . self::VARCHAR_SIZE . ')';
969:
970:
971:
972:
973:
974: case self::DATEPICKER:
975:
976: return 'DATETIME';
977:
978:
979: case self::BUTTONSUBMIT:
980: case self::BUTTONRESET:
981: case self::BUTTON:
982: case self::BUTTONIMAGE:
983:
984: return NULL;
985:
986:
987:
988: case self::PROCESSBAR:
989: case self::SLIDER:
990: case self::CAPTCHA:
991: case self::MATRIX:
992: case self::PARA:
993: case self::FIELDSET_BEGIN:
994: case self::FIELDSET_END:
995:
996: return NULL;
997:
998: default:
999: $msg = Pifa::i18n('NOT_IMPLEMENTED_FIELDTYPE');
1000: $msg = sprintf($msg, $fieldType);
1001:
1002: throw new PifaException($msg);
1003: }
1004: }
1005:
1006: 1007: 1008: 1009:
1010: public function delete() {
1011: $cfg = cRegistry::getConfig();
1012: $db = cRegistry::getDb();
1013:
1014: if (!$this->isLoaded()) {
1015: $msg = Pifa::i18n('FIELD_LOAD_ERROR');
1016: throw new PifaException($msg);
1017: }
1018:
1019:
1020: $sql = "-- PifaField->delete()
1021: UPDATE
1022: " . cRegistry::getDbTableName('pifa_field') . "
1023: SET
1024: field_rank = field_rank - 1
1025: WHERE
1026: idform = " . cSecurity::toInteger($this->get('idform')) . "
1027: AND field_rank > " . cSecurity::toInteger($this->get('field_rank')) . "
1028: ;";
1029: if (false === $db->query($sql)) {
1030:
1031:
1032: }
1033:
1034:
1035: $sql = "-- PifaField->delete()
1036: DELETE FROM
1037: " . cRegistry::getDbTableName('pifa_field') . "
1038: WHERE
1039: idfield = " . cSecurity::toInteger($this->get('idfield')) . "
1040: ;";
1041: if (false === $db->query($sql)) {
1042: $msg = Pifa::i18n('FIELD_DELETE_ERROR');
1043: throw new PifaException($msg);
1044: }
1045:
1046:
1047: if (0 < cString::getStringLength(trim($this->get('column_name')))) {
1048: $pifaForm = new PifaForm($this->get('idform'));
1049:
1050: if (0 < cString::getStringLength(trim($pifaForm->get('data_table')))) {
1051: $sql = "-- PifaField->delete()
1052: ALTER TABLE
1053: `" . cSecurity::toString($pifaForm->get('data_table')) . "`
1054: DROP COLUMN
1055: `" . cSecurity::toString($this->get('column_name')) . "`
1056: ;";
1057: if (false === $db->query($sql)) {
1058: $msg = Pifa::i18n('COLUMN_DROP_ERROR');
1059: throw new PifaException($msg);
1060: }
1061: }
1062: }
1063: }
1064:
1065: 1066: 1067: 1068: 1069: 1070:
1071: public function showField($columnName) {
1072: $fieldType = $this->get('field_type');
1073: $fieldType = cSecurity::toInteger($fieldType);
1074:
1075: switch ($columnName) {
1076:
1077: case 'idfield':
1078: case 'idform':
1079: case 'field_rank':
1080: case 'field_type':
1081:
1082: return false;
1083:
1084: case 'column_name':
1085: return in_array($fieldType, array(
1086: self::INPUTTEXT,
1087: self::TEXTAREA,
1088: self::INPUTPASSWORD,
1089: self::INPUTRADIO,
1090: self::INPUTCHECKBOX,
1091: self::SELECT,
1092: self::SELECTMULTI,
1093: self::DATEPICKER,
1094: self::INPUTFILE,
1095: self::PROCESSBAR,
1096: self::SLIDER,
1097: self::CAPTCHA,
1098:
1099:
1100:
1101:
1102: self::MATRIX,
1103: self::INPUTHIDDEN
1104: 1105: 1106: 1107:
1108: ));
1109:
1110: case 'label':
1111: case 'display_label':
1112: return in_array($fieldType, array(
1113: self::INPUTTEXT,
1114: self::TEXTAREA,
1115: self::INPUTPASSWORD,
1116: self::INPUTRADIO,
1117: self::INPUTCHECKBOX,
1118: self::SELECT,
1119: self::SELECTMULTI,
1120: self::DATEPICKER,
1121: self::INPUTFILE,
1122: self::PROCESSBAR,
1123: self::SLIDER,
1124: self::CAPTCHA,
1125: self::BUTTONSUBMIT,
1126: self::BUTTONRESET,
1127: self::BUTTON,
1128:
1129: self::MATRIX,
1130: self::PARA,
1131:
1132: self::FIELDSET_BEGIN
1133: 1134: 1135:
1136: ));
1137:
1138: case 'default_value':
1139: return in_array($fieldType, array(
1140: self::INPUTTEXT,
1141: self::TEXTAREA,
1142: self::INPUTPASSWORD,
1143: self::INPUTRADIO,
1144: self::INPUTCHECKBOX,
1145: self::SELECT,
1146: self::SELECTMULTI,
1147: self::DATEPICKER,
1148: self::INPUTFILE,
1149: self::PROCESSBAR,
1150: self::SLIDER,
1151: self::CAPTCHA,
1152: self::BUTTONSUBMIT,
1153: self::BUTTONRESET,
1154: self::BUTTON,
1155:
1156: self::MATRIX,
1157: self::INPUTHIDDEN
1158: ));
1159:
1160: case 'option_labels':
1161: case 'option_values':
1162: case 'option_class':
1163: return in_array($fieldType, array(
1164: self::INPUTRADIO,
1165: self::INPUTCHECKBOX,
1166: self::SELECT,
1167: self::SELECTMULTI
1168: ));
1169:
1170: case 'help_text':
1171: return in_array($fieldType, array(
1172: self::INPUTTEXT,
1173: self::TEXTAREA,
1174: self::INPUTPASSWORD,
1175: self::INPUTRADIO,
1176: self::INPUTCHECKBOX,
1177: self::SELECT,
1178: self::SELECTMULTI,
1179: self::DATEPICKER,
1180: self::INPUTFILE,
1181: self::PROCESSBAR,
1182: self::SLIDER,
1183: self::CAPTCHA,
1184: self::BUTTONSUBMIT,
1185: self::BUTTONRESET,
1186: self::BUTTON,
1187: self::BUTTONIMAGE,
1188: self::MATRIX,
1189: self::PARA,
1190: self::FIELDSET_BEGIN
1191: ));
1192:
1193: case 'obligatory':
1194: return in_array($fieldType, array(
1195: self::INPUTTEXT,
1196: self::TEXTAREA,
1197: self::INPUTPASSWORD,
1198: self::INPUTRADIO,
1199: self::INPUTCHECKBOX,
1200: self::SELECT,
1201: self::SELECTMULTI,
1202: self::DATEPICKER,
1203: self::INPUTFILE,
1204: self::PROCESSBAR,
1205: self::SLIDER,
1206: self::CAPTCHA,
1207:
1208:
1209:
1210:
1211: self::MATRIX,
1212: self::INPUTHIDDEN
1213: ));
1214:
1215: case 'rule':
1216: return in_array($fieldType, array(
1217: self::INPUTTEXT,
1218: self::TEXTAREA,
1219: self::INPUTPASSWORD,
1220: self::INPUTRADIO,
1221: self::INPUTCHECKBOX,
1222: self::SELECT,
1223: self::SELECTMULTI,
1224: self::DATEPICKER,
1225: self::INPUTFILE,
1226: self::PROCESSBAR,
1227: self::SLIDER,
1228: self::CAPTCHA,
1229:
1230:
1231:
1232:
1233: self::MATRIX,
1234: self::INPUTHIDDEN
1235: ));
1236:
1237: case 'error_message':
1238: return in_array($fieldType, array(
1239: self::INPUTTEXT,
1240: self::TEXTAREA,
1241: self::INPUTPASSWORD,
1242: self::INPUTRADIO,
1243: self::INPUTCHECKBOX,
1244: self::SELECT,
1245: self::SELECTMULTI,
1246: self::DATEPICKER,
1247: self::INPUTFILE,
1248: self::PROCESSBAR,
1249: self::SLIDER,
1250: self::CAPTCHA,
1251:
1252:
1253:
1254:
1255: self::MATRIX,
1256: self::INPUTHIDDEN
1257: ));
1258:
1259: case 'css_class':
1260: return in_array($fieldType, array(
1261: self::INPUTTEXT,
1262: self::TEXTAREA,
1263: self::INPUTPASSWORD,
1264: self::INPUTRADIO,
1265: self::INPUTCHECKBOX,
1266: self::SELECT,
1267: self::SELECTMULTI,
1268: self::DATEPICKER,
1269: self::INPUTFILE,
1270: self::PROCESSBAR,
1271: self::SLIDER,
1272: self::CAPTCHA,
1273: self::BUTTONSUBMIT,
1274: self::BUTTONRESET,
1275: self::BUTTON,
1276: self::BUTTONIMAGE,
1277: self::MATRIX,
1278: self::PARA,
1279: self::FIELDSET_BEGIN
1280: 1281: 1282:
1283: ));
1284:
1285: case 'uri':
1286: return in_array($fieldType, array(
1287: 1288: 1289: 1290: 1291: 1292: 1293: 1294: 1295: 1296: 1297: 1298: 1299: 1300: 1301: 1302: 1303:
1304: self::BUTTONIMAGE,
1305: 1306: 1307: 1308: 1309: 1310:
1311: ));
1312:
1313: default:
1314: $msg = Pifa::i18n('NOT_IMPLEMENTED_FIELDPROP');
1315: $msg = sprintf($msg, $columnName);
1316: throw new PifaException($msg);
1317: }
1318: }
1319:
1320: 1321: 1322: 1323:
1324: public function getOptions() {
1325: $option_labels = $this->get('option_labels');
1326: $option_values = $this->get('option_values');
1327:
1328: $out = array();
1329: if (0 < cString::getStringLength($option_labels . $option_values)) {
1330: $option_labels = explode(',', $option_labels);
1331: $option_values = explode(',', $option_values);
1332:
1333:
1334:
1335:
1336:
1337:
1338: $func = function($v) {
1339: return str_replace(',', ',', $v);
1340: };
1341: $option_labels = array_map($func, $option_labels);
1342: $option_values = array_map($func, $option_values);
1343:
1344: foreach (array_keys($option_labels) as $key) {
1345: $out[] = array(
1346: 'label' => $option_labels[$key],
1347: 'value' => $option_values[$key]
1348: );
1349: }
1350: }
1351:
1352: return $out;
1353: }
1354: }
1355:
1356: ?>
1357: