1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49:
50: class AlphaRendererProviderHTML implements AlphaRendererProviderInterface {
51: 52: 53: 54: 55: 56:
57: private static $logger = null;
58:
59: 60: 61: 62: 63: 64:
65: private $BO;
66:
67: 68: 69: 70: 71:
72: public function __construct() {
73: self::$logger = new Logger('AlphaRendererProviderHTML');
74: self::$logger->debug('>>__construct()');
75:
76: self::$logger->debug('<<__construct');
77: }
78:
79: 80: 81: 82:
83: public function setBO($BO) {
84: $this->BO = $BO;
85: }
86:
87: 88: 89: 90:
91: public function createView($fields=array()) {
92: self::$logger->debug('>>createView(fields=['.var_export($fields, true).'])');
93:
94: global $config;
95:
96:
97: $fields['formAction'] = $_SERVER['REQUEST_URI'];
98:
99:
100: $fields['formID'] = get_class($this->BO).'_'.$this->BO->getOID();
101:
102:
103: $fields['formFields'] = $this->renderAllFields('create');
104:
105:
106: $button = new Button('submit', 'Create', 'createBut');
107: $fields['createButton'] = $button->render();
108:
109: $button = new Button("document.location.replace('".FrontController::generateSecureURL('act=ListBusinessObjects')."')", 'Cancel', 'cancelBut');
110: $fields['cancelButton'] = $button->render();
111:
112:
113: $fields['formSecurityFields'] = self::renderSecurityFields();
114:
115: self::$logger->debug('<<createView [HTML]');
116: return AlphaView::loadTemplate($this->BO, 'create', $fields);
117: }
118:
119: 120: 121: 122:
123: public function editView($fields=array()) {
124: self::$logger->debug('>>editView(fields=['.var_export($fields, true).'])');
125:
126: global $config;
127:
128:
129: $fields['formAction'] = $_SERVER['REQUEST_URI'];
130:
131:
132: $fields['formID'] = get_class($this->BO).'_'.$this->BO->getOID();
133:
134:
135: $fields['formFields'] = $this->renderAllFields('edit');
136:
137:
138: $button = new Button('submit', 'Save', 'saveBut');
139: $fields['saveButton'] = $button->render();
140:
141: $js = "if(window.jQuery) {
142: BootstrapDialog.show({
143: title: 'Confirmation',
144: message: 'Are you sure you wish to delete this item?',
145: buttons: [
146: {
147: icon: 'glyphicon glyphicon-remove',
148: label: 'Cancel',
149: cssClass: 'btn btn-default btn-xs',
150: action: function(dialogItself){
151: dialogItself.close();
152: }
153: },
154: {
155: icon: 'glyphicon glyphicon-ok',
156: label: 'Okay',
157: cssClass: 'btn btn-default btn-xs',
158: action: function(dialogItself) {
159: $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('deleteOID')) : 'deleteOID')."\"]').attr('value', '".$this->BO->getOID()."');
160: $('#deleteForm').submit();
161: dialogItself.close();
162: }
163: }
164: ]
165: });
166: }";
167: $button = new Button($js, "Delete", "deleteBut");
168: $fields['deleteButton'] = $button->render();
169:
170: $button = new Button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'", "Back to List", "cancelBut");
171: $fields['cancelButton'] = $button->render();
172:
173:
174: $fields['formSecurityFields'] = self::renderSecurityFields();
175:
176:
177: $fields['version_num'] = $this->BO->getVersionNumber();
178:
179: self::$logger->debug('<<editView [HTML]');
180: return AlphaView::loadTemplate($this->BO, 'edit', $fields);
181: }
182:
183: 184: 185: 186:
187: public function listView($fields=array()) {
188: self::$logger->debug('>>listView(fields=['.var_export($fields, true).'])');
189:
190: global $config;
191:
192:
193: $fields['formAction'] = $_SERVER['REQUEST_URI'];
194:
195:
196: $reflection = new ReflectionClass(get_class($this->BO));
197: $properties = array_keys($reflection->getDefaultProperties());
198: $fields['colCount'] = 1+count(array_diff($properties, $this->BO->getDefaultAttributes(), $this->BO->getTransientAttributes()));
199:
200:
201: $properties = $reflection->getProperties();
202:
203: $html = '';
204:
205: $html .= '<tr>';
206: foreach($properties as $propObj) {
207: $propName = $propObj->name;
208:
209:
210: $property = $this->BO->getPropObject($propName);
211: if(!($property instanceof String && $property->checkIsPassword())) {
212: if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $this->BO->getTransientAttributes())) {
213: $html .= ' <th>'.$this->BO->getDataLabel($propName).'</th>';
214: }
215: if ($propName == 'OID')
216: $html .= ' <th>'.$this->BO->getDataLabel($propName).'</th>';
217: }else{
218: $fields['colCount'] = $fields['colCount']-1;
219: }
220: }
221: $html .= '</tr><tr>';
222:
223: $fields['formHeadings'] = $html;
224:
225: $html = '';
226:
227:
228: foreach($properties as $propObj) {
229: $propName = $propObj->name;
230:
231: $property = $this->BO->getPropObject($propName);
232: if(!($property instanceof String && $property->checkIsPassword())) {
233: if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $this->BO->getTransientAttributes())) {
234: $propClass = get_class($this->BO->getPropObject($propName));
235:
236: if ($propClass == 'Text') {
237: $text = htmlentities($this->BO->get($propName), ENT_COMPAT, 'utf-8');
238: if(mb_strlen($text) > 70)
239: $html .= ' <td> '.mb_substr($text, 0, 70).'...</td>';
240: else
241: $html .= ' <td> '.$text.'</td>';
242: }elseif($propClass == 'DEnum') {
243: $html .= ' <td> '.$this->BO->getPropObject($propName)->getDisplayValue().'</td>';
244: }else{
245: $html .= ' <td> '.$this->BO->get($propName).'</td>';
246: }
247: }
248: if ($propName == 'OID')
249: $html .= ' <td> '.$this->BO->getOID().'</td>';
250: }
251: }
252: $html .= '</tr>';
253:
254: $fields['formFields'] = $html;
255:
256:
257: if(mb_strpos($_SERVER['REQUEST_URI'], '/tk/') !== false) {
258: $button = new Button("document.location = '".FrontController::generateSecureURL('act=Detail&bo='.get_class($this->BO).'&oid='.$this->BO->getOID())."';", 'View', 'view'.$this->BO->getOID().'But');
259: $fields['viewButton'] = $button->render();
260: }else{
261: if($this->BO->hasAttribute('URL'))
262: $button = new Button("document.location = '".$this->BO->get('URL')."';", 'View', 'view'.$this->BO->getOID().'But');
263: else
264: $button = new Button("document.location = '".$config->get('app.url')."Detail/bo/".get_class($this->BO)."/oid/".$this->BO->getOID()."';", 'View', 'view'.$this->BO->getOID().'But');
265:
266: $fields['viewButton'] = $button->render();
267: }
268:
269: $html = '';
270:
271: if (isset($_SESSION['currentUser']) && $_SESSION['currentUser']->inGroup('Admin')) {
272: $html .= ' ';
273: $button = new Button("document.location = '".FrontController::generateSecureURL('act=Edit&bo='.get_class($this->BO)."&oid=".$this->BO->getOID())."'", "Edit", "edit".$this->BO->getOID()."But");
274: $html .= $button->render();
275: $html .= ' ';
276:
277: $js = "if(window.jQuery) {
278: BootstrapDialog.show({
279: title: 'Confirmation',
280: message: 'Are you sure you wish to delete this item?',
281: buttons: [
282: {
283: icon: 'glyphicon glyphicon-remove',
284: label: 'Cancel',
285: cssClass: 'btn btn-default btn-xs',
286: action: function(dialogItself){
287: dialogItself.close();
288: }
289: },
290: {
291: icon: 'glyphicon glyphicon-ok',
292: label: 'Okay',
293: cssClass: 'btn btn-default btn-xs',
294: action: function(dialogItself) {
295: $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('deleteOID')) : 'deleteOID')."\"]').attr('value', '".$this->BO->getOID()."');
296: $('#deleteForm').submit();
297: dialogItself.close();
298: }
299: }
300: ]
301: });
302: }";
303:
304: $button = new Button($js, "Delete", "delete".$this->BO->getOID()."But");
305: $html .= $button->render();
306: }
307: $fields['adminButtons'] = $html;
308:
309:
310: $fields['formSecurityFields'] = self::renderSecurityFields();
311:
312: self::$logger->debug('<<listView [HTML]');
313: return AlphaView::loadTemplate($this->BO, 'list', $fields);
314: }
315:
316: 317: 318: 319:
320: public function detailedView($fields=array()) {
321: self::$logger->debug('>>detailedView(fields=['.var_export($fields, true).'])');
322:
323: global $config;
324:
325:
326: $fields['OIDLabel'] = $this->BO->getDataLabel('OID');
327: $fields['OID'] = $this->BO->getOID();
328:
329:
330: $fields['formFields'] = $this->renderAllFields('view');
331:
332:
333: $button = new Button('history.back()', 'Back', 'backBut');
334: $fields['backButton'] = $button->render();
335:
336: $html = '';
337:
338: if (isset($_SESSION['currentUser']) && $_SESSION['currentUser']->inGroup('Admin')) {
339:
340: $button = new Button("document.location = '".FrontController::generateSecureURL('act=Edit&bo='.get_class($this->BO)."&oid=".$this->BO->getOID())."'", "Edit", "editBut");
341: $html .= $button->render();
342:
343: $js = "if(window.jQuery) {
344: BootstrapDialog.show({
345: title: 'Confirmation',
346: message: 'Are you sure you wish to delete this item?',
347: buttons: [
348: {
349: icon: 'glyphicon glyphicon-remove',
350: label: 'Cancel',
351: cssClass: 'btn btn-default btn-xs',
352: action: function(dialogItself){
353: dialogItself.close();
354: }
355: },
356: {
357: icon: 'glyphicon glyphicon-ok',
358: label: 'Okay',
359: cssClass: 'btn btn-default btn-xs',
360: action: function(dialogItself) {
361: $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('deleteOID')) : 'deleteOID')."\"]').attr('value', '".$this->BO->getOID()."');
362: $('#deleteForm').submit();
363: dialogItself.close();
364: }
365: }
366: ]
367: });
368: }";
369:
370: $button = new Button($js, "Delete", "deleteBut");
371: $html .= $button->render();
372: }
373: $fields['adminButtons'] = $html;
374:
375: self::$logger->debug('<<detailedView [HTML]');
376: return AlphaView::loadTemplate($this->BO, 'detail', $fields);
377: }
378:
379: 380: 381: 382:
383: public function adminView($fields=array()) {
384: self::$logger->debug('>>adminView(fields=['.var_export($fields, true).'])');
385:
386: global $config;
387:
388:
389: $fields['formAction'] = $_SERVER['REQUEST_URI'];
390:
391:
392: $fields['className'] = get_class($this->BO);
393:
394:
395: $fields['tableName'] = $this->BO->getTableName();
396:
397:
398: $fields['count'] = ($this->BO->checkTableExists() ? $this->BO->getCount() : '<span class="warning">unavailable</span>');
399:
400:
401: $fields['tableExists'] = ($this->BO->checkTableExists() ? '<span class="success">Yes</span>' : '<span class="warning">No</span>');
402:
403: if($this->BO->getMaintainHistory())
404: $fields['tableExists'] = ($this->BO->checkTableExists(true) ? '<span class="success">Yes</span>' : '<span class="warning">No history table</span>');
405:
406:
407: $fields['tableNeedsUpdate'] = ($this->BO->checkTableNeedsUpdate() ? '<span class="warning">Yes</span>' : '<span class="success">No</span>');
408:
409:
410: if($this->BO->checkTableExists()) {
411: $button = new Button("document.location = '".FrontController::generateSecureURL('act=Create&bo='.get_class($this->BO))."'", "Create New", "create".get_class($this->BO)."But");
412: $fields['createButton'] = $button->render();
413: }else{
414: $fields['createButton'] = '';
415: }
416:
417:
418: if($this->BO->checkTableExists()) {
419: $button = new Button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'", "List All", "list".get_class($this->BO)."But");
420: $fields['listButton'] = $button->render();
421: }else{
422: $fields['listButton'] = '';
423: }
424:
425:
426: $html = '';
427:
428: if (!$this->BO->checkTableExists()) {
429: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('createTableBut')) : 'createTableBut');
430: $button = new Button('submit', 'Create Table', $fieldname);
431: $html .= $button->render();
432:
433: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('createTableClass')) : 'createTableClass');
434: $html .= '<input type="hidden" name="'.$fieldname.'" value="'.get_class($this->BO).'"/>';
435: }
436:
437: if ($html == '' && $this->BO->getMaintainHistory() && !$this->BO->checkTableExists(true)) {
438: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('createHistoryTableBut')) : 'createHistoryTableBut');
439: $button = new Button('submit', 'Create History Table', $fieldname);
440: $html .= $button->render();
441:
442: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('createTableClass')) : 'createTableClass');
443: $html .= '<input type="hidden" name="'.$fieldname.'" value="'.get_class($this->BO).'"/>';
444: }
445: $fields['createTableButton'] = $html;
446:
447:
448: $html = '';
449: if ($this->BO->checkTableNeedsUpdate() && $this->BO->checkTableExists()) {
450:
451: $js = "if(window.jQuery) {
452: BootstrapDialog.show({
453: title: 'Confirmation',
454: message: 'Are you sure you wish to recreate this class table (all data will be lost)?',
455: buttons: [
456: {
457: icon: 'glyphicon glyphicon-remove',
458: label: 'Cancel',
459: cssClass: 'btn btn-default btn-xs',
460: action: function(dialogItself){
461: dialogItself.close();
462: }
463: },
464: {
465: icon: 'glyphicon glyphicon-ok',
466: label: 'Okay',
467: cssClass: 'btn btn-default btn-xs',
468: action: function(dialogItself) {
469: $('[Id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('admin_'.get_class($this->BO).'_button_pressed')) : 'admin_'.get_class($this->BO).'_button_pressed')."\"]').attr('value', 'recreateTableBut');
470: $('#admin_".get_class($this->BO)."').submit();
471: dialogItself.close();
472: }
473: }
474: ]
475: });
476: }";
477:
478: $button = new Button($js , "Recreate Table", "recreateTableBut");
479: $html .= $button->render();
480:
481: $html .= '<input type="hidden" name="recreateTableClass" value="'.get_class($this->BO).'"/>';
482: $html .= ' ';
483:
484: $js = "if(window.jQuery) {
485: BootstrapDialog.show({
486: title: 'Confirmation',
487: message: 'Are you sure you wish to attempt to modify this class table by adding new attributes?',
488: buttons: [
489: {
490: icon: 'glyphicon glyphicon-remove',
491: label: 'Cancel',
492: cssClass: 'btn btn-default btn-xs',
493: action: function(dialogItself){
494: dialogItself.close();
495: }
496: },
497: {
498: icon: 'glyphicon glyphicon-ok',
499: label: 'Okay',
500: cssClass: 'btn btn-default btn-xs',
501: action: function(dialogItself) {
502: $('[Id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('admin_'.get_class($this->BO).'_button_pressed')) : 'admin_'.get_class($this->BO).'_button_pressed')."\"]').attr('value', 'updateTableBut');
503: $('#admin_".get_class($this->BO)."').submit();
504: dialogItself.close();
505: }
506: }
507: ]
508: });
509: }";
510:
511: $button = new Button($js , "Update Table", "updateTableBut");
512: $html .= $button->render();
513:
514: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('updateTableClass')) : 'updateTableClass');
515: $html .= '<input type="hidden" name="'.$fieldname.'" value="'.get_class($this->BO).'"/>';
516:
517: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('admin_'.get_class($this->BO).'_button_pressed')) : 'admin_'.get_class($this->BO).'_button_pressed');
518: $html .= '<input type="hidden" id="'.$fieldname.'" name="'.$fieldname.'" value=""/>';
519: }
520: $fields['recreateOrUpdateButtons'] = $html;
521:
522:
523: $fields['formSecurityFields'] = self::renderSecurityFields();
524:
525: self::$logger->debug('<<adminView [HTML]');
526: return AlphaView::loadTemplate($this->BO, 'admin', $fields);
527: }
528:
529: 530: 531: 532:
533: public static function displayPageHead($controller) {
534: if(self::$logger == null)
535: self::$logger = new Logger('AlphaRendererProviderHTML');
536:
537: self::$logger->debug('>>displayPageHead(controller=['.var_export($controller, true).'])');
538:
539: global $config;
540:
541: if(!AlphaController::checkControllerDefExists(get_class($controller)))
542: throw new IllegalArguementException('The controller provided ['.get_class($controller).'] is not defined anywhere!');
543:
544: $allowCSSOverrides = true;
545:
546: if (isset($_SESSION['currentUser']) && AlphaDAO::isInstalled() && $_SESSION['currentUser']->inGroup('Admin') && mb_strpos($_SERVER['REQUEST_URI'], '/tk/') !== false) {
547: $allowCSSOverrides = false;
548: }
549:
550: $html = AlphaView::loadTemplateFragment('html', 'head.phtml', array('title' => $controller->getTitle(), 'description' => $controller->getDescription(), 'allowCSSOverrides' => $allowCSSOverrides));
551:
552: if(method_exists($controller, 'during_displayPageHead_callback'))
553: $html.= $controller->during_displayPageHead_callback();
554:
555: $html.= '</head>';
556:
557: try {
558: if($controller->getBO() != null)
559: $html.= '<body'.($controller->getBO()->get('bodyOnload') != '' ? ' onload="'.$controller->getBO()->get('bodyOnload').'"' : '').'>';
560: else
561: $html.= '<body>';
562: } catch (AlphaException $e) {
563: $html.= '<body>';
564: }
565:
566: $html .= '<div class="container">';
567:
568: if(method_exists($controller, 'insert_CMSDisplayStandardHeader_callback'))
569: $html.= $controller->insert_CMSDisplayStandardHeader_callback();
570:
571:
572: self::$logger->debug('<<displayPageHead [HTML]');
573: return $html;
574: }
575:
576: 577: 578: 579:
580: public static function ($controller) {
581: if(self::$logger == null)
582: self::$logger = new Logger('AlphaRendererProviderHTML');
583:
584: self::$logger->debug('>>displayPageFoot(controller=['.get_class($controller).'])');
585:
586:
587: $html = AlphaView::loadTemplateFragment('html', 'footer.phtml', array());
588:
589: self::$logger->debug('<<displayPageFoot ['.$html.']');
590: return $html;
591: }
592:
593: 594: 595: 596:
597: public static function displayUpdateMessage($message) {
598: if(self::$logger == null)
599: self::$logger = new Logger('AlphaRendererProviderHTML');
600: self::$logger->debug('>>displayUpdateMessage(message=['.$message.'])');
601:
602: $html = '<div class="alert alert-success alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>'.$message.'</div>';
603:
604: self::$logger->debug('<<displayUpdateMessage ['.$html.']');
605: return $html;
606: }
607:
608: 609: 610: 611:
612: public static function displayErrorMessage($message) {
613: if(self::$logger == null)
614: self::$logger = new Logger('AlphaRendererProviderHTML');
615: self::$logger->debug('>>displayErrorMessage(message=['.$message.'])');
616:
617: $html = '<div class="alert alert-danger">'.$message.'</div>';
618:
619: self::$logger->debug('<<displayErrorMessage ['.$html.']');
620: return $html;
621: }
622:
623: 624: 625: 626:
627: public static function renderErrorPage($code, $message) {
628: global $config;
629:
630: $html = '<html><head>';
631: $html .= '<link rel="StyleSheet" type="text/css" href="'.$config->get('app.url').'alpha/lib/jquery/ui/themes/'.$config->get('app.css.theme').'/jquery.ui.all.css">';
632: $html .= '<link rel="StyleSheet" type="text/css" href="'.$config->get('app.url').'alpha/css/alpha.css">';
633: $html .= '<title>'.$code.' - '.$message.'</title></head>';
634: $html .= '<body>';
635: $html .= self::displayErrorMessage('<strong>'.$code.':</strong> '.$message);
636: $html .= '</body></html>';
637:
638: return $html;
639: }
640:
641: 642: 643: 644:
645: public static function renderDeleteForm() {
646: if(self::$logger == null)
647: self::$logger = new Logger('AlphaRendererProviderHTML');
648: self::$logger->debug('>>renderDeleteForm()');
649:
650: global $config;
651:
652: $html = '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST" id="deleteForm" accept-charset="UTF-8">';
653: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('deleteOID')) : 'deleteOID');
654: $html .= '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value=""/>';
655: $html .= self::renderSecurityFields();
656: $html .= '</form>';
657:
658: self::$logger->debug('<<renderDeleteForm ['.$html.']');
659: return $html;
660: }
661:
662: 663: 664: 665:
666: public static function renderSecurityFields() {
667: if(self::$logger == null)
668: self::$logger = new Logger('AlphaRendererProviderHTML');
669:
670: self::$logger->debug('>>renderSecurityFields()');
671:
672: global $config;
673:
674: $html = '';
675:
676: $fields = AlphaController::generateSecurityFields();
677:
678: if($config->get('security.encrypt.http.fieldnames'))
679: $fieldname = base64_encode(AlphaSecurityUtils::encrypt('var1'));
680: else
681: $fieldname = 'var1';
682:
683: $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$fields[0].'"/>';
684:
685: if($config->get('security.encrypt.http.fieldnames'))
686: $fieldname = base64_encode(AlphaSecurityUtils::encrypt('var2'));
687: else
688: $fieldname = 'var2';
689:
690: $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$fields[1].'"/>';
691:
692: self::$logger->debug('<<renderSecurityFields ['.$html.']');
693: return $html;
694: }
695:
696: 697: 698: 699: 700:
701: public function renderIntegerField($name, $label, $mode, $value='') {
702: self::$logger->debug('>>renderIntegerField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'])');
703:
704: global $config;
705:
706: if($config->get('security.encrypt.http.fieldnames'))
707: $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
708: else
709: $fieldname = $name;
710:
711: $html = '<div class="form-group">';
712: $html .= ' <label for="'.$fieldname.'">'.$label.'</label>';
713:
714: if ($mode == 'create') {
715: $html .= '<input type="text" style="width:100%;" name="'.$fieldname.'" value="'. (isset ($_POST[$name]) ? $_POST[$name] : '').'"/>';
716: }
717:
718: if ($mode == 'edit') {
719: $html .= '<input type="text" style="width:100%;" name="'.$fieldname.'" value="'.$value.'"/>';
720: }
721:
722: $html .= '</div>';
723:
724: self::$logger->debug('<<renderIntegerField ['.$html.']');
725: return $html;
726: }
727:
728: 729: 730: 731: 732:
733: public function renderDoubleField($name, $label, $mode, $value='') {
734: self::$logger->debug('>>renderDoubleField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'])');
735:
736: global $config;
737:
738: if($config->get('security.encrypt.http.fieldnames'))
739: $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
740: else
741: $fieldname = $name;
742:
743: $html = '<div class="form-group">';
744: $html .= ' <label for="'.$fieldname.'">'.$label.'</label>';
745:
746: if ($mode == 'create') {
747: $html .= '<input type="text" size="13" name="'.$fieldname.'" value="'. (isset ($_POST[$name]) ? $_POST[$name] : '').'"/>';
748: }
749:
750: if ($mode == 'edit') {
751: $html .= '<input type="text" size="13" name="'.$fieldname.'" value="'.$value.'"/>';
752: }
753:
754: $html .= '</div>';
755:
756: self::$logger->debug('<<renderDoubleField ['.$html.']');
757: return $html;
758: }
759:
760: 761: 762: 763:
764: public function renderBooleanField($name, $label, $mode, $value='') {
765: self::$logger->debug('>>renderBooleanField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'])');
766:
767: global $config;
768:
769: if($config->get('security.encrypt.http.fieldnames'))
770: $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
771: else
772: $fieldname = $name;
773:
774: $html = '<div class="checkbox">';
775: $html .= ' <label>';
776:
777: if ($mode == 'create') {
778: $html .= ' <input type="hidden" name="'.$fieldname.'" value="0">';
779: $html .= ' <input type="checkbox" name="'.$fieldname.'" id="'.$fieldname.'">';
780: $html .= ' '.$label;
781:
782: }
783:
784: if ($mode == 'edit') {
785: $html .= ' <input type="hidden" name="'.$fieldname.'" value="0">';
786: $html .= ' <input type="checkbox" name="'.$fieldname.'" id="'.$fieldname.'"'.($value == '1'? ' checked':'').' />';
787: $html .= ' '.$label;
788: }
789:
790: $html .= ' </label>';
791: $html .= '</div>';
792:
793: self::$logger->debug('<<renderBooleanField ['.$html.']');
794: return $html;
795: }
796:
797: 798: 799: 800:
801: public function renderEnumField($name, $label, $mode, $options, $value='') {
802: self::$logger->debug('>>renderEnumField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'])');
803:
804: global $config;
805:
806: if($config->get('security.encrypt.http.fieldnames'))
807: $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
808: else
809: $fieldname = $name;
810:
811: $html = '<div class="form-group">';
812: $html .= ' <label for="'.$fieldname.'">'.$label.'</label>';
813:
814: if ($mode == 'create') {
815: $html .= ' <select name="'.$fieldname.'" id="'.$fieldname.'" class="form-control"/>';
816: foreach ($options as $val) {
817: $html .= ' <option value="'.$val.'">'.$val.'</option>';
818: }
819: $html .= ' </select>';
820: }
821:
822: if ($mode == 'edit') {
823: $html .= ' <select name="'.$fieldname.'" id="'.$fieldname.'" class="form-control"/>';
824: foreach ($options as $val) {
825: if ($value == $val)
826: $html .= ' <option value="'.$val.'" selected>'.$val.'</option>';
827: else
828: $html .= ' <option value="'.$val.'">'.$val.'</option>';
829: }
830: $html .= ' </select>';
831: }
832:
833: $html .= '</div>';
834:
835: self::$logger->debug('<<renderEnumField ['.$html.']');
836: return $html;
837: }
838:
839: 840: 841: 842:
843: public function renderDEnumField($name, $label, $mode, $options, $value='') {
844: self::$logger->debug('>>renderDEnumField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'])');
845:
846: global $config;
847:
848: if($config->get('security.encrypt.http.fieldnames'))
849: $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
850: else
851: $fieldname = $name;
852:
853: $html = '<div class="form-group">';
854: $html .= ' <label for="'.$fieldname.'">'.$label.'</label>';
855:
856: if ($mode == 'create') {
857: $html .= ' <select name="'.$fieldname.'" id="'.$fieldname.'" class="form-control"/>';
858: foreach (array_keys($options) as $index) {
859: $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
860: }
861: $html .= ' </select>';
862: }
863:
864: if ($mode == 'edit') {
865: $html .= ' <select name="'.$fieldname.'" id="'.$fieldname.'" class="form-control"/>';
866: foreach (array_keys($options) as $index) {
867: if ($value == $index)
868: $html .= '<option value="'.$index.'" selected>'.$options[$index].'</option>';
869: else
870: $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
871: }
872: $html .= ' </select>';
873: }
874:
875: $html .= '</div>';
876:
877: self::$logger->debug('<<renderDEnumField ['.$html.']');
878: return $html;
879: }
880:
881: 882: 883: 884:
885: public function renderDefaultField($name, $label, $mode, $value='') {
886: self::$logger->debug('>>renderDefaultField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'])');
887:
888: global $config;
889:
890: if($config->get('security.encrypt.http.fieldnames'))
891: $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
892: else
893: $fieldname = $name;
894:
895: $html = '';
896:
897: if ($mode == 'create') {
898: $html .= '<textarea cols="100" rows="3" name="'.$fieldname.'">'. (isset ($_POST[$name]) ? $_POST[$name] : '').'</textarea>';
899: }
900:
901: if ($mode == 'edit') {
902: $html .= '<textarea cols="100" rows="3" name="'.$fieldname.'">'.$value.'</textarea>';
903: }
904:
905: if ($mode == 'view') {
906: $html .= '<p><strong>'.$label.':</strong> '.$value.'</p>';
907: }
908:
909: self::$logger->debug('<<renderDefaultField ['.$html.']');
910: return $html;
911: }
912:
913: 914: 915: 916:
917: public function renderTextField($name, $label, $mode, $value='') {
918: self::$logger->debug('>>renderTextField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'])');
919:
920: global $config;
921:
922: $html = '';
923:
924: if ($mode == 'create') {
925:
926: if($name == 'content')
927: $text = new TextBox($this->BO->getPropObject($name), $label, $name, 10);
928: else
929: $text = new TextBox($this->BO->getPropObject($name), $label, $name);
930: $html .= $text->render();
931: }
932:
933: if ($mode == 'edit') {
934:
935: if($name == 'content') {
936: $viewState = ViewState::getInstance();
937:
938: if($viewState->get('markdownTextBoxRows') == '')
939: $text = new TextBox($this->BO->getPropObject($name), $label, $name, 10);
940: else
941: $text = new TextBox($this->BO->getPropObject($name), $label, $name, (integer)$viewState->get('markdownTextBoxRows'));
942:
943: $html .= $text->render();
944: }else{
945: $text = new TextBox($this->BO->getPropObject($name), $label, $name);
946: $html .= $text->render();
947: }
948: }
949:
950: if ($mode == 'view') {
951: $html .= '<p><strong>';
952:
953: $html .= $label;
954:
955: $html .= ':</strong>';
956:
957:
958: $value = InputFilter::encode($value);
959:
960:
961: $value = str_replace("\n", '<br>', $value);
962:
963: $html .= ' ';
964:
965: $html .= $value;
966:
967: $html .= '</p>';
968: }
969:
970: self::$logger->debug('<<renderTextField ['.$html.']');
971: return $html;
972: }
973:
974: 975: 976: 977:
978: public function renderStringField($name, $label, $mode, $value='') {
979: self::$logger->debug('>>renderStringField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'])');
980:
981: global $config;
982:
983: $html = '';
984:
985: if ($mode == 'create' || $mode == 'edit') {
986: $string = new StringBox($this->BO->getPropObject($name), $label, $name);
987: $html .= $string->render();
988: }
989:
990: if ($mode == 'view') {
991: $html .= '<p><strong>'.$label.':</strong> '.$value.'</p>';
992: }
993:
994: self::$logger->debug('<<renderStringField ['.$html.']');
995: return $html;
996: }
997:
998: 999: 1000: 1001:
1002: public function renderRelationField($name, $label, $mode, $value='', $expanded=false, $buttons=true) {
1003: self::$logger->debug('>>renderRelationField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], expanded=['.$expanded.'], buttons=['.$buttons.'])');
1004:
1005: global $config;
1006:
1007: $html = '';
1008:
1009: $rel = $this->BO->getPropObject($name);
1010:
1011: if ($mode == 'create' || $mode == 'edit') {
1012: if($rel->getRelationType() == 'MANY-TO-MANY') {
1013: try{
1014:
1015: $rel->getSide(get_class($this->BO));
1016: $widget = new RecordSelector($rel, $label, $name, get_class($this->BO));
1017: $html .= $widget->render($expanded, $buttons);
1018: }catch (IllegalArguementException $iae) {
1019:
1020: $parentClassName = ucfirst($this->BO->getTableName()).'Object';
1021: $widget = new RecordSelector($rel, $label, $name, $parentClassName);
1022: $html .= $widget->render($expanded, $buttons);
1023: }
1024: }else{
1025: $rel = new RecordSelector($rel, $label, $name);
1026: $html .= $rel->render($expanded, $buttons);
1027: }
1028: }
1029:
1030: if ($mode == 'view') {
1031: if($rel->getRelationType() == 'MANY-TO-ONE') {
1032: $html .= $this->renderDefaultField($name, $label, 'view', $rel->getRelatedClassDisplayFieldValue());
1033: }elseif($rel->getRelationType() == 'MANY-TO-MANY') {
1034: try{
1035:
1036: $rel->getSide(get_class($this->BO));
1037: $html .= $this->renderDefaultField($name, $label, 'view', $rel->getRelatedClassDisplayFieldValue(get_class($this->BO)));
1038: }catch (IllegalArguementException $iae) {
1039:
1040: $parentClassName = ucfirst($this->BO->getTableName()).'Object';
1041: $html .= $this->renderDefaultField($name, $label, 'view', $rel->getRelatedClassDisplayFieldValue($parentClassName));
1042: }
1043: }else{
1044: $rel = new RecordSelector($rel, $label, $name);
1045: $html .= $rel->render($expanded, $buttons);
1046: }
1047: }
1048:
1049: self::$logger->debug('<<renderRelationField ['.$html.']');
1050: return $html;
1051: }
1052:
1053: 1054: 1055: 1056:
1057: public function renderAllFields($mode, $filterFields=array(), $readOnlyFields=array()) {
1058: self::$logger->debug('>>renderAllFields(mode=['.$mode.'], filterFields=['.var_export($filterFields, true).'], readOnlyFields=['.var_export($readOnlyFields, true).'])');
1059:
1060: $html = '';
1061:
1062:
1063: $properties = array_keys($this->BO->getDataLabels());
1064:
1065: $orignalMode = $mode;
1066:
1067: foreach($properties as $propName) {
1068: if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $filterFields)) {
1069:
1070: if(in_array($propName, $readOnlyFields))
1071: $mode = 'view';
1072: else
1073: $mode = $orignalMode;
1074:
1075: if(!is_object($this->BO->getPropObject($propName)))
1076: continue;
1077:
1078: $propClass = get_class($this->BO->getPropObject($propName));
1079:
1080:
1081: if($propClass != 'Relation' && ($mode == 'edit' || $mode == 'create') && in_array($propName, $this->BO->getTransientAttributes())) {
1082: continue;
1083: }
1084:
1085: switch (mb_strtoupper($propClass)) {
1086: case 'INTEGER' :
1087: if($mode == 'view') {
1088: $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName));
1089: }else{
1090: $html .= $this->renderIntegerField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
1091: }
1092: break;
1093: case 'DOUBLE' :
1094: if($mode == 'view') {
1095: $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName));
1096: }else{
1097: $html .= $this->renderDoubleField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
1098: }
1099: break;
1100: case 'DATE' :
1101: if($mode == 'view') {
1102: $value = $this->BO->get($propName);
1103: if ($value == '0000-00-00')
1104: $value = '';
1105: $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $value);
1106: }else{
1107: $date = new DateBox($this->BO->getPropObject($propName), $this->BO->getDataLabel($propName), $propName);
1108: $html .= $date->render();
1109: }
1110: break;
1111: case 'TIMESTAMP' :
1112: if($mode == 'view') {
1113: $value = $this->BO->get($propName);
1114: if ($value == '0000-00-00 00:00:00')
1115: $value = '';
1116: $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $value);
1117: }else{
1118: $timestamp = new DateBox($this->BO->getPropObject($propName), $this->BO->getDataLabel($propName), $propName);
1119: $html .= $timestamp->render();
1120: }
1121: break;
1122: case 'STRING' :
1123: $html .= $this->renderStringField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
1124: break;
1125: case 'TEXT' :
1126: $html .= $this->renderTextField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
1127: break;
1128: case 'BOOLEAN' :
1129: if($mode == 'view') {
1130: $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName));
1131: }else{
1132: $html .= $this->renderBooleanField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
1133: }
1134: break;
1135: case 'ENUM' :
1136: if($mode == 'view') {
1137: $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName));
1138: }else{
1139: $enum = $this->BO->getPropObject($propName);
1140: $html .= $this->renderEnumField($propName, $this->BO->getDataLabel($propName), $mode, $enum->getOptions(), $this->BO->get($propName));
1141: }
1142: break;
1143: case 'DENUM' :
1144: if($mode == 'view') {
1145: $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->getPropObject($propName)->getDisplayValue());
1146: }else{
1147: $denum = $this->BO->getPropObject($propName);
1148: $html .= $this->renderDEnumField($propName, $this->BO->getDataLabel($propName), $mode, $denum->getOptions(), $this->BO->get($propName));
1149: }
1150: break;
1151: case 'RELATION' :
1152: $html .= $this->renderRelationField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
1153: break;
1154: default :
1155: $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
1156: break;
1157: }
1158: }
1159: }
1160:
1161: self::$logger->debug('<<renderAllFields ['.$html.']');
1162: return $html;
1163: }
1164: }
1165:
1166: ?>