       1: <?php
       2:
       3: /**
       4:  * HTML renderer.  Will invoke widgets from the alpha::view::widgets package
       5:  * automatically for the correct data type.  Templates from ./templates/html
       6:  * loaded by default, but these can be overridden on a per-DAO level in
       7:  * the application when required (consider the default ones to be scaffolding).
       8:  *
       9:  * @package alpha::view::renderers
      10:  * @since 1.2
      11:  * @author John Collins <dev@alphaframework.org>
      12:  * @version $Id: AlphaRendererProviderInterface.inc 1499 2012-02-16 19:29:16Z alphadev $
      13:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
      14:  * @copyright Copyright (c) 2014, John Collins (founder of Alpha Framework).
      15:  * All rights reserved.
      16:  *
      17:  * <pre>
      18:  * Redistribution and use in source and binary forms, with or
      19:  * without modification, are permitted provided that the
      20:  * following conditions are met:
      21:  *
      22:  * * Redistributions of source code must retain the above
      23:  *   copyright notice, this list of conditions and the
      24:  *   following disclaimer.
      25:  * * Redistributions in binary form must reproduce the above
      26:  *   copyright notice, this list of conditions and the
      27:  *   following disclaimer in the documentation and/or other
      28:  *   materials provided with the distribution.
      29:  * * Neither the name of the Alpha Framework nor the names
      30:  *   of its contributors may be used to endorse or promote
      31:  *   products derived from this software without specific
      32:  *   prior written permission.
      33:  *
      34:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
      35:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
      36:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      37:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      38:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
      39:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      40:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      41:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      42:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      43:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      44:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
      45:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
      46:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      47:  * </pre>
      48:  *
      49:  */
      50: class AlphaRendererProviderHTML implements AlphaRendererProviderInterface {
      51:     /**
      52:      * Trace logger
      53:      *
      54:      * @var Logger
      55:      * @since 1.2
      56:      */
      57:     private static $logger = null;
      58:
      59:     /**
      60:      * The business object that we are renderering
      61:      *
      62:      * @var AlphaDAO
      63:      * @since 1.2
      64:      */
      65:     private $BO;
      66:
      67:     /**
      68:      * The constructor
      69:      *
      70:      * @since 1.2
      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:      * (non-PHPdoc)
      81:      * @see alpha/view/renderers/AlphaRendererProvider::setBO()
      82:      */
      83:     public function setBO($BO) {
      84:         $this->BO = $BO;
      85:     }
      86:
      87:     /**
      88:      * (non-PHPdoc)
      89:      * @see alpha/view/renderers/AlphaRendererProviderInterface::createView()
      90:      */
      91:     public function createView($fields=array()) {
      92:         self::$logger->debug('>>createView(fields=['.var_export($fields, true).'])');
      93:
      94:         global $config;
      95:
      96:         // the form action
      97:         $fields['formAction'] = $_SERVER['REQUEST_URI'];
      98:
      99:         // the form ID
     100:         $fields['formID'] = get_class($this->BO).'_'.$this->BO->getOID();
     101:
     102:         // buffer form fields to $formFields
     103:         $fields['formFields'] = $this->renderAllFields('create');
     104:
     105:         // buffer HTML output for Create and Cancel buttons
     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:         // buffer security fields to $formSecurityFields variable
     113:         $fields['formSecurityFields'] = self::renderSecurityFields();
     114:
     115:         self::$logger->debug('<<createView [HTML]');
     116:         return AlphaView::loadTemplate($this->BO, 'create', $fields);
     117:     }
     118:
     119:     /**
     120:      * (non-PHPdoc)
     121:      * @see alpha/view/renderers/AlphaRendererProviderInterface::editView()
     122:      */
     123:     public function editView($fields=array()) {
     124:         self::$logger->debug('>>editView(fields=['.var_export($fields, true).'])');
     125:
     126:         global $config;
     127:
     128:         // the form action
     129:         $fields['formAction'] = $_SERVER['REQUEST_URI'];
     130:
     131:         // the form ID
     132:         $fields['formID'] = get_class($this->BO).'_'.$this->BO->getOID();
     133:
     134:         // buffer form fields to $formFields
     135:         $fields['formFields'] = $this->renderAllFields('edit');
     136:
     137:         // buffer HTML output for Create and Cancel buttons
     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:         // buffer security fields to $formSecurityFields variable
     174:         $fields['formSecurityFields'] = self::renderSecurityFields();
     175:
     176:         // OID will need to be posted for optimistic lock checking
     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:      * (non-PHPdoc)
     185:      * @see alpha/view/renderers/AlphaRendererProviderInterface::listView()
     186:      */
     187:     public function listView($fields=array()) {
     188:         self::$logger->debug('>>listView(fields=['.var_export($fields, true).'])');
     189:
     190:         global $config;
     191:
     192:         // the form action
     193:         $fields['formAction'] = $_SERVER['REQUEST_URI'];
     194:
     195:         // work out how many columns will be in the table
     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:         // get the class attributes
     201:         $properties = $reflection->getProperties();
     202:
     203:         $html = '';
     204:
     205:         $html .= '<tr>';
     206:         foreach($properties as $propObj) {
     207:             $propName = $propObj->name;
     208:
     209:             // skip over password fields
     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:         // and now the values
     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>&nbsp;'.mb_substr($text, 0, 70).'...</td>';
     240:                         else
     241:                             $html .= '  <td>&nbsp;'.$text.'</td>';
     242:                     }elseif($propClass == 'DEnum') {
     243:                         $html .= '  <td>&nbsp;'.$this->BO->getPropObject($propName)->getDisplayValue().'</td>';
     244:                     }else{
     245:                         $html .= '  <td>&nbsp;'.$this->BO->get($propName).'</td>';
     246:                     }
     247:                 }
     248:                 if ($propName == 'OID')
     249:                     $html .= '  <td>&nbsp;'.$this->BO->getOID().'</td>';
     250:             }
     251:         }
     252:         $html .= '</tr>';
     253:
     254:         $fields['formFields'] = $html;
     255:
     256:         // View button
     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:         // render edit and delete buttons for admins only
     271:         if (isset($_SESSION['currentUser']) && $_SESSION['currentUser']->inGroup('Admin')) {
     272:             $html .= '&nbsp;&nbsp;';
     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 .= '&nbsp;&nbsp;';
     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:         // buffer security fields to $formSecurityFields variable
     310:         $fields['formSecurityFields'] = self::renderSecurityFields();
     311:
     312:         self::$logger->debug('<<listView [HTML]');
     313:         return AlphaView::loadTemplate($this->BO, 'list', $fields);
     314:     }
     315:
     316:     /**
     317:      * (non-PHPdoc)
     318:      * @see alpha/view/renderers/AlphaRendererProviderInterface::detailedView()
     319:      */
     320:     public function detailedView($fields=array()) {
     321:         self::$logger->debug('>>detailedView(fields=['.var_export($fields, true).'])');
     322:
     323:         global $config;
     324:
     325:         // we may want to display the OID regardless of class
     326:         $fields['OIDLabel'] = $this->BO->getDataLabel('OID');
     327:         $fields['OID'] = $this->BO->getOID();
     328:
     329:         // buffer form fields to $formFields
     330:         $fields['formFields'] = $this->renderAllFields('view');
     331:
     332:         // Back button
     333:         $button = new Button('history.back()', 'Back', 'backBut');
     334:         $fields['backButton'] = $button->render();
     335:
     336:         $html = '';
     337:         // render edit and delete buttons for admins only
     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:      * (non-PHPdoc)
     381:      * @see alpha/view/renderers/AlphaRendererProviderInterface::adminView()
     382:      */
     383:     public function adminView($fields=array()) {
     384:         self::$logger->debug('>>adminView(fields=['.var_export($fields, true).'])');
     385:
     386:         global $config;
     387:
     388:         // the form action
     389:         $fields['formAction'] = $_SERVER['REQUEST_URI'];
     390:
     391:         // the class name of the BO
     392:         $fields['className'] = get_class($this->BO);
     393:
     394:         // the table name in the DB for the BO
     395:         $fields['tableName'] = $this->BO->getTableName();
     396:
     397:         // record count for the BO in the DB
     398:         $fields['count'] = ($this->BO->checkTableExists() ? $this->BO->getCount() : '<span class="warning">unavailable</span>');
     399:
     400:         // table exists in the DB?
     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:         // table schema needs to be updated in the DB?
     407:         $fields['tableNeedsUpdate'] = ($this->BO->checkTableNeedsUpdate() ? '<span class="warning">Yes</span>' : '<span class="success">No</span>');
     408:
     409:         // create button
     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:         // list all button
     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:         // the create table button (if required)
     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:             // hidden field so that we know which class to create the table for
     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:             // hidden field so that we know which class to create the table for
     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:         // recreate and update table buttons (if required)
     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:             // hidden field so that we know which class to recreate the table for
     481:             $html .= '<input type="hidden" name="recreateTableClass" value="'.get_class($this->BO).'"/>';
     482:             $html .= '&nbsp;&nbsp;';
     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:             // hidden field so that we know which class to update the table for
     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:             // hidden field to tell us which button was pressed
     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:         // buffer security fields to $formSecurityFields variable
     523:         $fields['formSecurityFields'] = self::renderSecurityFields();
     524:
     525:         self::$logger->debug('<<adminView [HTML]');
     526:         return AlphaView::loadTemplate($this->BO, 'admin', $fields);
     527:     }
     528:
     529:     /**
     530:      * (non-PHPdoc)
     531:      * @see alpha/view/renderers/AlphaRendererProviderInterface::displayPageHead()
     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:         $html = AlphaView::loadTemplateFragment('html', 'head.phtml', array('title' => $controller->getTitle(), 'description' => $controller->getDescription()));
     545:
     546:         if(method_exists($controller, 'during_displayPageHead_callback'))
     547:             $html.= $controller->during_displayPageHead_callback();
     548:
     549:         $html.= '</head>';
     550:
     551:         try {
     552:             if($controller->getBO() != null)
     553:                 $html.= '<body'.($controller->getBO()->get('bodyOnload') != '' ? ' onload="'.$controller->getBO()->get('bodyOnload').'"' : '').'>';
     554:             else
     555:                 $html.= '<body>';
     556:         } catch (AlphaException $e) {
     557:             $html.= '<body>';
     558:         }
     559:
     560:         $html .= '<div class="container">';
     561:
     562:         if(method_exists($controller, 'insert_CMSDisplayStandardHeader_callback'))
     563:             $html.= $controller->insert_CMSDisplayStandardHeader_callback();
     564:
     565:
     566:         self::$logger->debug('<<displayPageHead [HTML]');
     567:         return $html;
     568:     }
     569:
     570:     /**
     571:      * (non-PHPdoc)
     572:      * @see alpha/view/renderers/AlphaRendererProviderInterface::displayPageFoot()
     573:      */
     574:     public static function displayPageFoot($controller) {
     575:         if(self::$logger == null)
     576:             self::$logger = new Logger('AlphaRendererProviderHTML');
     577:
     578:         self::$logger->debug('>>displayPageFoot(controller=['.get_class($controller).'])');
     579:
     580:
     581:         $html = AlphaView::loadTemplateFragment('html', 'footer.phtml', array());
     582:
     583:         self::$logger->debug('<<displayPageFoot ['.$html.']');
     584:         return $html;
     585:     }
     586:
     587:     /**
     588:      * (non-PHPdoc)
     589:      * @see alpha/view/renderers/AlphaRendererProviderInterface::displayUpdateMessage()
     590:      */
     591:     public static function displayUpdateMessage($message) {
     592:         if(self::$logger == null)
     593:             self::$logger = new Logger('AlphaRendererProviderHTML');
     594:         self::$logger->debug('>>displayUpdateMessage(message=['.$message.'])');
     595:
     596:         $html = '<div class="alert alert-success">'.$message.'</div>';
     597:
     598:         self::$logger->debug('<<displayUpdateMessage ['.$html.']');
     599:         return $html;
     600:     }
     601:
     602:     /**
     603:      * (non-PHPdoc)
     604:      * @see alpha/view/renderers/AlphaRendererProviderInterface::displayErrorMessage()
     605:      */
     606:     public static function displayErrorMessage($message) {
     607:         if(self::$logger == null)
     608:             self::$logger = new Logger('AlphaRendererProviderHTML');
     609:         self::$logger->debug('>>displayErrorMessage(message=['.$message.'])');
     610:
     611:         $html = '<div class="alert alert-danger">'.$message.'</div>';
     612:
     613:         self::$logger->debug('<<displayErrorMessage ['.$html.']');
     614:         return $html;
     615:     }
     616:
     617:     /**
     618:      * (non-PHPdoc)
     619:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderErrorPage()
     620:      */
     621:     public static function renderErrorPage($code, $message) {
     622:         global $config;
     623:
     624:         $html = '<html><head>';
     625:         $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">';
     626:         $html .= '<link rel="StyleSheet" type="text/css" href="'.$config->get('app.url').'alpha/css/alpha.css">';
     627:         $html .= '<title>'.$code.' - '.$message.'</title></head>';
     628:         $html .= '<body>';
     629:         $html .= '<div class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em;">
     630:                 <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>
     631:                 <strong>'.$code.':</strong> '.$message.'</p>
     632:                 </div>';
     633:         $html .= '</body></html>';
     634:
     635:         return $html;
     636:     }
     637:
     638:     /**
     639:      * (non-PHPdoc)
     640:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderDeleteForm()
     641:      */
     642:     public static function renderDeleteForm() {
     643:         if(self::$logger == null)
     644:             self::$logger = new Logger('AlphaRendererProviderHTML');
     645:         self::$logger->debug('>>renderDeleteForm()');
     646:
     647:         global $config;
     648:
     649:         $html = '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST" id="deleteForm" accept-charset="UTF-8">';
     650:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('deleteOID')) : 'deleteOID');
     651:         $html .= '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value=""/>';
     652:         $html .= self::renderSecurityFields();
     653:         $html .= '</form>';
     654:
     655:         self::$logger->debug('<<renderDeleteForm ['.$html.']');
     656:         return $html;
     657:     }
     658:
     659:     /**
     660:      * (non-PHPdoc)
     661:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderSecurityFields()
     662:      */
     663:     public static function renderSecurityFields() {
     664:         if(self::$logger == null)
     665:             self::$logger = new Logger('AlphaRendererProviderHTML');
     666:
     667:         self::$logger->debug('>>renderSecurityFields()');
     668:
     669:         global $config;
     670:
     671:         $html = '';
     672:
     673:         $fields = AlphaController::generateSecurityFields();
     674:
     675:         if($config->get('security.encrypt.http.fieldnames'))
     676:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt('var1'));
     677:         else
     678:             $fieldname = 'var1';
     679:
     680:         $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$fields[0].'"/>';
     681:
     682:         if($config->get('security.encrypt.http.fieldnames'))
     683:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt('var2'));
     684:         else
     685:             $fieldname = 'var2';
     686:
     687:         $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$fields[1].'"/>';
     688:
     689:         self::$logger->debug('<<renderSecurityFields ['.$html.']');
     690:         return $html;
     691:     }
     692:
     693:     /**
     694:      * (non-PHPdoc)
     695:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderIntegerField()
     696:      * @todo remove table tags and use Bootstrap CSS
     697:      */
     698:     public function renderIntegerField($name, $label, $mode, $value='', $tableTags=true) {
     699:         self::$logger->debug('>>renderIntegerField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
     700:
     701:         global $config;
     702:
     703:         if($config->get('security.encrypt.http.fieldnames'))
     704:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
     705:         else
     706:             $fieldname = $name;
     707:
     708:         $html = '';
     709:
     710:         if ($mode == 'create') {
     711:             if($tableTags) {
     712:                 $html .= '<tr><th style="width:25%;">';
     713:                 $html .= $label;
     714:                 $html .= '</th>';
     715:
     716:                 $html .= '<td>';
     717:                 $html .= '<input type="text" style="width:100%;" name="'.$fieldname.'" value="'. (isset ($_POST[$name]) ? $_POST[$name] : '').'"/><br>';
     718:                 $html .= '</td></tr>';
     719:             }else{
     720:                 $html .= '<input type="text" style="width:100%;" name="'.$fieldname.'" value="'. (isset ($_POST[$name]) ? $_POST[$name] : '').'"/><br>';
     721:             }
     722:         }
     723:
     724:         if ($mode == 'edit') {
     725:             if($tableTags) {
     726:                 $html .= '<tr><th style="width:25%;">';
     727:                 $html .= $label;
     728:                 $html .= '</th>';
     729:
     730:                 $html .= '<td>';
     731:                 $html .= '<input type="text" style="width:100%;" name="'.$fieldname.'" value="'.$value.'"/><br>';
     732:                 $html .= '</td></tr>';
     733:             }else{
     734:                 $html .= '<input type="text" style="width:100%;" name="'.$fieldname.'" value="'.$value.'"/>';
     735:             }
     736:         }
     737:
     738:         self::$logger->debug('<<renderIntegerField ['.$html.']');
     739:         return $html;
     740:     }
     741:
     742:     /**
     743:      * (non-PHPdoc)
     744:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderDoubleField()
     745:      * @todo remove table tags and use Bootstrap CSS
     746:      */
     747:     public function renderDoubleField($name, $label, $mode, $value='', $tableTags=true) {
     748:         self::$logger->debug('>>renderDoubleField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
     749:
     750:         global $config;
     751:
     752:         if($config->get('security.encrypt.http.fieldnames'))
     753:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
     754:         else
     755:             $fieldname = $name;
     756:
     757:         $html = '';
     758:
     759:         if ($mode == 'create') {
     760:             if($tableTags) {
     761:                 $html .= '<tr><th style="width:25%;">';
     762:                 $html .= $label;
     763:                 $html .= '</th>';
     764:
     765:                 $html .= '<td>';
     766:                 $html .= '<input type="text" size="13" name="'.$fieldname.'" value="'. (isset ($_POST[$name]) ? $_POST[$name] : '').'"/><br>';
     767:                 $html .= '</td></tr>';
     768:             }else{
     769:                 $html .= '<input type="text" size="13" name="'.$fieldname.'" value="'. (isset ($_POST[$name]) ? $_POST[$name] : '').'"/>';
     770:             }
     771:         }
     772:
     773:         if ($mode == 'edit') {
     774:             if($tableTags) {
     775:                 $html .= '<tr><th style="width:25%;">';
     776:                 $html .= $label;
     777:                 $html .= '</th>';
     778:
     779:                 $html .= '<td>';
     780:                 $html .= '<input type="text" size="13" name="'.$fieldname.'" value="'.$value.'"/><br>';
     781:                 $html .= '</td></tr>';
     782:             }else{
     783:                 $html .= '<input type="text" size="13" name="'.$fieldname.'" value="'.$value.'"/>';
     784:             }
     785:         }
     786:
     787:         self::$logger->debug('<<renderDoubleField ['.$html.']');
     788:         return $html;
     789:     }
     790:
     791:     /**
     792:      * (non-PHPdoc)
     793:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderBooleanField()
     794:      */
     795:     public function renderBooleanField($name, $label, $mode, $value='') {
     796:         self::$logger->debug('>>renderBooleanField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'])');
     797:
     798:         global $config;
     799:
     800:         if($config->get('security.encrypt.http.fieldnames'))
     801:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
     802:         else
     803:             $fieldname = $name;
     804:
     805:         $html = '<div class="checkbox">';
     806:         $html .= '  <label>';
     807:
     808:         if ($mode == 'create') {
     809:             $html .= '      <input type="hidden" name="'.$fieldname.'" value="0">';
     810:             $html .= '      <input type="checkbox" name="'.$fieldname.'" id="'.$fieldname.'">';
     811:             $html .= '          '.$label;
     812:
     813:         }
     814:
     815:         if ($mode == 'edit') {
     816:             $html .= '      <input type="hidden" name="'.$fieldname.'" value="0">';
     817:             $html .= '      <input type="checkbox" name="'.$fieldname.'" id="'.$fieldname.'"'.($value == '1'? ' checked':'').' />';
     818:             $html .= '          '.$label;
     819:         }
     820:
     821:         $html .= '  </label>';
     822:         $html .= '</div>';
     823:
     824:         self::$logger->debug('<<renderBooleanField ['.$html.']');
     825:         return $html;
     826:     }
     827:
     828:     /**
     829:      * (non-PHPdoc)
     830:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderEnumField()
     831:      */
     832:     public function renderEnumField($name, $label, $mode, $options, $value='') {
     833:         self::$logger->debug('>>renderEnumField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'])');
     834:
     835:         global $config;
     836:
     837:         if($config->get('security.encrypt.http.fieldnames'))
     838:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
     839:         else
     840:             $fieldname = $name;
     841:
     842:         $html = '<div class="form-group">';
     843:         $html .= '  <label for="'.$fieldname.'">'.$label.'</label>';
     844:
     845:         if ($mode == 'create') {
     846:             $html .= '  <select name="'.$fieldname.'" id="'.$fieldname.'" class="form-control"/>';
     847:             foreach ($options as $val) {
     848:                 $html .= '      <option value="'.$val.'">'.$val.'</option>';
     849:             }
     850:             $html .= '  </select>';
     851:         }
     852:
     853:         if ($mode == 'edit') {
     854:             $html .= '  <select name="'.$fieldname.'" id="'.$fieldname.'" class="form-control"/>';
     855:             foreach ($options as $val) {
     856:                 if ($value == $val)
     857:                     $html .= '      <option value="'.$val.'" selected>'.$val.'</option>';
     858:                 else
     859:                     $html .= '      <option value="'.$val.'">'.$val.'</option>';
     860:             }
     861:             $html .= '  </select>';
     862:         }
     863:
     864:         $html .= '</div>';
     865:
     866:         self::$logger->debug('<<renderEnumField ['.$html.']');
     867:         return $html;
     868:     }
     869:
     870:     /**
     871:      * (non-PHPdoc)
     872:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderDEnumField()
     873:      */
     874:     public function renderDEnumField($name, $label, $mode, $options, $value='', $tableTags=true) {
     875:         self::$logger->debug('>>renderDEnumField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
     876:
     877:         global $config;
     878:
     879:         if($config->get('security.encrypt.http.fieldnames'))
     880:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
     881:         else
     882:             $fieldname = $name;
     883:
     884:         $html = '<div class="form-group">';
     885:         $html .= '  <label for="'.$fieldname.'">'.$label.'</label>';
     886:
     887:         if ($mode == 'create') {
     888:             $html .= '  <select name="'.$fieldname.'" id="'.$fieldname.'" class="form-control"/>';
     889:             foreach (array_keys($options) as $index) {
     890:                 $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
     891:             }
     892:             $html .= '  </select>';
     893:         }
     894:
     895:         if ($mode == 'edit') {
     896:             $html .= '  <select name="'.$fieldname.'" id="'.$fieldname.'" class="form-control"/>';
     897:             foreach (array_keys($options) as $index) {
     898:                 if ($value == $index)
     899:                     $html .= '<option value="'.$index.'" selected>'.$options[$index].'</option>';
     900:                 else
     901:                     $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
     902:             }
     903:             $html .= '  </select>';
     904:         }
     905:
     906:         $html .= '</div>';
     907:
     908:         self::$logger->debug('<<renderDEnumField ['.$html.']');
     909:         return $html;
     910:     }
     911:
     912:     /**
     913:      * (non-PHPdoc)
     914:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderDefaultField()
     915:      */
     916:     public function renderDefaultField($name, $label, $mode, $value='') {
     917:         self::$logger->debug('>>renderDefaultField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'])');
     918:
     919:         global $config;
     920:
     921:         if($config->get('security.encrypt.http.fieldnames'))
     922:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
     923:         else
     924:             $fieldname = $name;
     925:
     926:         $html = '';
     927:
     928:         if ($mode == 'create') {
     929:             $html .= '<textarea cols="100" rows="3" name="'.$fieldname.'">'. (isset ($_POST[$name]) ? $_POST[$name] : '').'</textarea>';
     930:         }
     931:
     932:         if ($mode == 'edit') {
     933:             $html .= '<textarea cols="100" rows="3" name="'.$fieldname.'">'.$value.'</textarea>';
     934:         }
     935:
     936:         if ($mode == 'view') {
     937:             $html .= '<p><strong>'.$label.':</strong> '.$value.'</p>';
     938:         }
     939:
     940:         self::$logger->debug('<<renderDefaultField ['.$html.']');
     941:         return $html;
     942:     }
     943:
     944:     /**
     945:      * (non-PHPdoc)
     946:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderTextField()
     947:      */
     948:     public function renderTextField($name, $label, $mode, $value='', $tableTags=true) {
     949:         self::$logger->debug('>>renderTextField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
     950:
     951:         global $config;
     952:
     953:         if($config->get('security.encrypt.http.fieldnames'))
     954:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
     955:         else
     956:             $fieldname = $name;
     957:
     958:         $html = '';
     959:
     960:         if ($mode == 'create') {
     961:             // give 10 rows for content fields (other 5 by default)
     962:             if($name == 'content')
     963:                 $text = new TextBox($this->BO->getPropObject($name), $label, $fieldname, 10);
     964:             else
     965:                 $text = new TextBox($this->BO->getPropObject($name), $label, $fieldname);
     966:             $html .= $text->render($tableTags);
     967:         }
     968:
     969:         if ($mode == 'edit') {
     970:             // give 10 rows for content fields (other 5 by default)
     971:             if($name == 'content') {
     972:                 $viewState = ViewState::getInstance();
     973:
     974:                 if($viewState->get('markdownTextBoxRows') == '')
     975:                     $text = new TextBox($this->BO->getPropObject($name), $label, $fieldname, 10);
     976:                 else
     977:                     $text = new TextBox($this->BO->getPropObject($name), $label, $fieldname, (integer)$viewState->get('markdownTextBoxRows'));
     978:
     979:                 $html .= $text->render($tableTags, true);
     980:             }else{
     981:                 $text = new TextBox($this->BO->getPropObject($name), $label, $fieldname);
     982:                 $html .= $text->render($tableTags);
     983:             }
     984:         }
     985:
     986:         if ($mode == 'view') {
     987:             if($tableTags)
     988:                 $html .= '<tr><th>';
     989:
     990:             $html .= $label;
     991:
     992:             if($tableTags)
     993:                 $html .= '</th>';
     994:
     995:             // filter ouput to prevent malicious injection
     996:             $value = InputFilter::encode($value);
     997:
     998:             // ensures that line returns are rendered
     999:             $value = str_replace("\n", '<br>', $value);
    1000:
    1001:             if($tableTags)
    1002:                 $html .= '<td>&nbsp;';
    1003:
    1004:             $html .= $value;
    1005:
    1006:             if($tableTags)
    1007:                 $html .= '</td></tr>';
    1008:         }
    1009:
    1010:         self::$logger->debug('<<renderTextField ['.$html.']');
    1011:         return $html;
    1012:     }
    1013:
    1014:     /**
    1015:      * (non-PHPdoc)
    1016:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderStringField()
    1017:      */
    1018:     public function renderStringField($name, $label, $mode, $value='') {
    1019:         self::$logger->debug('>>renderStringField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'])');
    1020:
    1021:         global $config;
    1022:
    1023:         $html = '';
    1024:
    1025:         if ($mode == 'create' || $mode == 'edit') {
    1026:             $string = new StringBox($this->BO->getPropObject($name), $label, $name);
    1027:             $html .= $string->render();
    1028:         }
    1029:
    1030:         if ($mode == 'view') {
    1031:             $html .= '<p><strong>'.$label.':</strong> '.$value.'</p>';
    1032:         }
    1033:
    1034:         self::$logger->debug('<<renderStringField ['.$html.']');
    1035:         return $html;
    1036:     }
    1037:
    1038:     /**
    1039:      * (non-PHPdoc)
    1040:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderRelationField()
    1041:      */
    1042:     public function renderRelationField($name, $label, $mode, $value='', $tableTags=true, $expanded=false, $buttons=true) {
    1043:         self::$logger->debug('>>renderRelationField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'], expanded=['.$expanded.'], buttons=['.$buttons.'])');
    1044:
    1045:         global $config;
    1046:
    1047:         $html = '';
    1048:
    1049:         $rel = $this->BO->getPropObject($name);
    1050:
    1051:         if ($mode == 'create' || $mode == 'edit') {
    1052:             if($rel->getRelationType() == 'MANY-TO-MANY') {
    1053:                 try{
    1054:                     // check to see if the rel is on this class
    1055:                     $rel->getSide(get_class($this->BO));
    1056:                     $widget = new RecordSelector($rel, $label, $name, get_class($this->BO));
    1057:                     $html .= $widget->render($tableTags, $expanded, $buttons);
    1058:                 }catch (IllegalArguementException $iae) {
    1059:                     // the rel may be on a parent class
    1060:                     $parentClassName = ucfirst($this->BO->getTableName()).'Object';
    1061:                     $widget = new RecordSelector($rel, $label, $name, $parentClassName);
    1062:                     $html .= $widget->render($tableTags, $expanded, $buttons);
    1063:                 }
    1064:             }else{
    1065:                 $rel = new RecordSelector($rel, $label, $name);
    1066:                 $html .= $rel->render($tableTags, $expanded, $buttons);
    1067:             }
    1068:         }
    1069:
    1070:         if ($mode == 'view') {
    1071:             if($rel->getRelationType() == 'MANY-TO-ONE') {
    1072:                 $html .= $this->renderDefaultField($name, $label, 'view', $rel->getRelatedClassDisplayFieldValue());
    1073:             }elseif($rel->getRelationType() == 'MANY-TO-MANY') {
    1074:                 try{
    1075:                     // check to see if the rel is on this class
    1076:                     $rel->getSide(get_class($this->BO));
    1077:                     $html .= $this->renderDefaultField($name, $label, 'view', $rel->getRelatedClassDisplayFieldValue(get_class($this->BO)));
    1078:                 }catch (IllegalArguementException $iae) {
    1079:                     // the rel may be on a parent class
    1080:                     $parentClassName = ucfirst($this->BO->getTableName()).'Object';
    1081:                     $html .= $this->renderDefaultField($name, $label, 'view', $rel->getRelatedClassDisplayFieldValue($parentClassName));
    1082:                 }
    1083:             }else{
    1084:                 $rel = new RecordSelector($rel, $label, $name);
    1085:                 $html .= $rel->render($tableTags, $expanded, $buttons);
    1086:             }
    1087:         }
    1088:
    1089:         self::$logger->debug('<<renderRelationField ['.$html.']');
    1090:         return $html;
    1091:     }
    1092:
    1093:     /**
    1094:      * (non-PHPdoc)
    1095:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderAllFields()
    1096:      */
    1097:     public function renderAllFields($mode, $filterFields=array(), $readOnlyFields=array()) {
    1098:         self::$logger->debug('>>renderAllFields(mode=['.$mode.'], filterFields=['.var_export($filterFields, true).'], readOnlyFields=['.var_export($readOnlyFields, true).'])');
    1099:
    1100:         $html = '';
    1101:
    1102:         // get the class attributes
    1103:         $properties = array_keys($this->BO->getDataLabels());
    1104:
    1105:         $orignalMode = $mode;
    1106:
    1107:         foreach($properties as $propName) {
    1108:             if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $filterFields)) {
    1109:                 // render readonly fields in the supplied array
    1110:                 if(in_array($propName, $readOnlyFields))
    1111:                     $mode = 'view';
    1112:                 else
    1113:                     $mode = $orignalMode;
    1114:
    1115:                 if(!is_object($this->BO->getPropObject($propName)))
    1116:                     continue;
    1117:
    1118:                 $propClass = get_class($this->BO->getPropObject($propName));
    1119:
    1120:                 // exclude non-Relation transient attributes from create and edit screens
    1121:                 if($propClass != 'Relation' && ($mode == 'edit' || $mode == 'create') && in_array($propName, $this->BO->getTransientAttributes())) {
    1122:                     continue;
    1123:                 }
    1124:
    1125:                 switch (mb_strtoupper($propClass)) {
    1126:                     case 'INTEGER' :
    1127:                         if($mode == 'view') {
    1128:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName));
    1129:                         }else{
    1130:                             $html .= $this->renderIntegerField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1131:                         }
    1132:                     break;
    1133:                     case 'DOUBLE' :
    1134:                         if($mode == 'view') {
    1135:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName));
    1136:                         }else{
    1137:                             $html .= $this->renderDoubleField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1138:                         }
    1139:                     break;
    1140:                     case 'DATE' :
    1141:                         if($mode == 'view') {
    1142:                             $value = $this->BO->get($propName);
    1143:                             if ($value == '0000-00-00')
    1144:                                 $value = '';
    1145:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $value);
    1146:                         }else{
    1147:                             $date = new DateBox($this->BO->getPropObject($propName), $this->BO->getDataLabel($propName), $propName);
    1148:                             $html .= $date->render();
    1149:                         }
    1150:                     break;
    1151:                     case 'TIMESTAMP' :
    1152:                         if($mode == 'view') {
    1153:                             $value = $this->BO->get($propName);
    1154:                             if ($value == '0000-00-00 00:00:00')
    1155:                                 $value = '';
    1156:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $value);
    1157:                         }else{
    1158:                             $timestamp = new DateBox($this->BO->getPropObject($propName), $this->BO->getDataLabel($propName), $propName);
    1159:                             $html .= $timestamp->render();
    1160:                         }
    1161:                     break;
    1162:                     case 'STRING' :
    1163:                         $html .= $this->renderStringField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1164:                     break;
    1165:                     case 'TEXT' :
    1166:                         $html .= $this->renderTextField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1167:                     break;
    1168:                     case 'BOOLEAN' :
    1169:                         if($mode == 'view') {
    1170:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName));
    1171:                         }else{
    1172:                             $html .= $this->renderBooleanField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1173:                         }
    1174:                     break;
    1175:                     case 'ENUM' :
    1176:                         if($mode == 'view') {
    1177:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName));
    1178:                         }else{
    1179:                             $enum = $this->BO->getPropObject($propName);
    1180:                             $html .= $this->renderEnumField($propName, $this->BO->getDataLabel($propName), $mode, $enum->getOptions(), $this->BO->get($propName));
    1181:                         }
    1182:                     break;
    1183:                     case 'DENUM' :
    1184:                         if($mode == 'view') {
    1185:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->getPropObject($propName)->getDisplayValue());
    1186:                         }else{
    1187:                             $denum = $this->BO->getPropObject($propName);
    1188:                             $html .= $this->renderDEnumField($propName, $this->BO->getDataLabel($propName), $mode, $denum->getOptions(), $this->BO->get($propName));
    1189:                         }
    1190:                     break;
    1191:                     case 'RELATION' :
    1192:                         $html .= $this->renderRelationField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1193:                     break;
    1194:                     default :
    1195:                         $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1196:                     break;
    1197:                 }
    1198:             }
    1199:         }
    1200:
    1201:         self::$logger->debug('<<renderAllFields ['.$html.']');
    1202:         return $html;
    1203:     }
    1204: }
    1205:
    1206: ?>