       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) 2012, 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:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('createBut')) : 'createBut');
     107:         $button = new Button('submit', 'Create', $fieldname);
     108:         $fields['createButton'] = $button->render();
     109:
     110:         $button = new Button("document.location.replace('".FrontController::generateSecureURL('act=ListBusinessObjects')."')", 'Cancel', 'cancelBut');
     111:         $fields['cancelButton'] = $button->render();
     112:
     113:         // buffer security fields to $formSecurityFields variable
     114:         $fields['formSecurityFields'] = self::renderSecurityFields();
     115:
     116:         self::$logger->debug('<<createView [HTML]');
     117:         return AlphaView::loadTemplate($this->BO, 'create', $fields);
     118:     }
     119:
     120:     /**
     121:      * (non-PHPdoc)
     122:      * @see alpha/view/renderers/AlphaRendererProviderInterface::editView()
     123:      */
     124:     public function editView($fields=array()) {
     125:         self::$logger->debug('>>editView(fields=['.var_export($fields, true).'])');
     126:
     127:         global $config;
     128:
     129:         // the form action
     130:         $fields['formAction'] = $_SERVER['REQUEST_URI'];
     131:
     132:         // the form ID
     133:         $fields['formID'] = get_class($this->BO).'_'.$this->BO->getOID();
     134:
     135:         // buffer form fields to $formFields
     136:         $fields['formFields'] = $this->renderAllFields('edit');
     137:
     138:         // buffer HTML output for Create and Cancel buttons
     139:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('saveBut')) : 'saveBut');
     140:         $button = new Button('submit', 'Save', $fieldname);
     141:         $fields['saveButton'] = $button->render();
     142:
     143:         $js = "$('#dialogDiv').text('Are you sure you wish to delete this item?');
     144:                 $('#dialogDiv').dialog({
     145:                 buttons: {
     146:                     'OK': function(event, ui) {
     147:                         $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('deleteOID')) : 'deleteOID')."\"]').attr('value', '".$this->BO->getOID()."');
     148:                         $('#deleteForm').submit();
     149:                     },
     150:                     'Cancel': function(event, ui) {
     151:                         $(this).dialog('close');
     152:                     }
     153:                 }
     154:             })
     155:             $('#dialogDiv').dialog('open');
     156:             return false;";
     157:         $button = new Button($js, "Delete", "deleteBut");
     158:         $fields['deleteButton'] = $button->render();
     159:
     160:         $button = new Button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'", "Back to List", "cancelBut");
     161:         $fields['cancelButton'] = $button->render();
     162:
     163:         // buffer security fields to $formSecurityFields variable
     164:         $fields['formSecurityFields'] = self::renderSecurityFields();
     165:
     166:         // OID will need to be posted for optimistic lock checking
     167:         $fields['version_num'] = $this->BO->getVersionNumber();
     168:
     169:         self::$logger->debug('<<editView [HTML]');
     170:         return AlphaView::loadTemplate($this->BO, 'edit', $fields);
     171:     }
     172:
     173:     /**
     174:      * (non-PHPdoc)
     175:      * @see alpha/view/renderers/AlphaRendererProviderInterface::listView()
     176:      */
     177:     public function listView($fields=array()) {
     178:         self::$logger->debug('>>listView(fields=['.var_export($fields, true).'])');
     179:
     180:         global $config;
     181:
     182:         // the form action
     183:         $fields['formAction'] = $_SERVER['REQUEST_URI'];
     184:
     185:         // work out how many columns will be in the table
     186:         $reflection = new ReflectionClass(get_class($this->BO));
     187:         $properties = array_keys($reflection->getDefaultProperties());
     188:         $fields['colCount'] = 1+count(array_diff($properties, $this->BO->getDefaultAttributes(), $this->BO->getTransientAttributes()));
     189:
     190:         // get the class attributes
     191:         $properties = $reflection->getProperties();
     192:
     193:         $html = '';
     194:
     195:         $html .= '<tr>';
     196:         foreach($properties as $propObj) {
     197:             $propName = $propObj->name;
     198:
     199:             // skip over password fields
     200:             $property = $this->BO->getPropObject($propName);
     201:             if(!($property instanceof String && $property->checkIsPassword())) {
     202:                 if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $this->BO->getTransientAttributes())) {
     203:                     $html .= '  <th>'.$this->BO->getDataLabel($propName).'</th>';
     204:                 }
     205:                 if ($propName == 'OID')
     206:                     $html .= '  <th>'.$this->BO->getDataLabel($propName).'</th>';
     207:             }else{
     208:                 $fields['colCount'] = $fields['colCount']-1;
     209:             }
     210:         }
     211:         $html .= '</tr><tr>';
     212:
     213:         $fields['formHeadings'] = $html;
     214:
     215:         $html = '';
     216:
     217:         // and now the values
     218:         foreach($properties as $propObj) {
     219:             $propName = $propObj->name;
     220:
     221:             $property = $this->BO->getPropObject($propName);
     222:             if(!($property instanceof String && $property->checkIsPassword())) {
     223:                 if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $this->BO->getTransientAttributes())) {
     224:                     $propClass = get_class($this->BO->getPropObject($propName));
     225:
     226:                     if ($propClass == 'Text') {
     227:                         $text = htmlentities($this->BO->get($propName));
     228:                         if(strlen($text) > 70)
     229:                             $html .= '  <td>&nbsp;'.substr($text, 0, 70).'...</td>';
     230:                         else
     231:                             $html .= '  <td>&nbsp;'.$text.'</td>';
     232:                     }elseif($propClass == 'DEnum') {
     233:                         $html .= '  <td>&nbsp;'.$this->BO->getPropObject($propName)->getDisplayValue().'</td>';
     234:                     }else{
     235:                         $html .= '  <td>&nbsp;'.$this->BO->get($propName).'</td>';
     236:                     }
     237:                 }
     238:                 if ($propName == 'OID')
     239:                     $html .= '  <td>&nbsp;'.$this->BO->getOID().'</td>';
     240:             }
     241:         }
     242:         $html .= '</tr>';
     243:
     244:         $fields['formFields'] = $html;
     245:
     246:         // View button
     247:         if(strpos($_SERVER['REQUEST_URI'], '/tk/') !== false) {
     248:             $button = new Button("document.location = '".FrontController::generateSecureURL('act=Detail&bo='.get_class($this->BO).'&oid='.$this->BO->getOID())."';", 'View', 'view'.$this->BO->getOID().'But');
     249:             $fields['viewButton'] = $button->render();
     250:         }else{
     251:             if($this->BO->hasAttribute('URL'))
     252:                 $button = new Button("document.location = '".$this->BO->get('URL')."';", 'View', 'view'.$this->BO->getOID().'But');
     253:             else
     254:                 $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');
     255:
     256:             $fields['viewButton'] = $button->render();
     257:         }
     258:
     259:         $html = '';
     260:         // render edit and delete buttons for admins only
     261:         if (isset($_SESSION['currentUser']) && $_SESSION['currentUser']->inGroup('Admin')) {
     262:             $html .= '&nbsp;&nbsp;';
     263:             $button = new Button("document.location = '".FrontController::generateSecureURL('act=Edit&bo='.get_class($this->BO)."&oid=".$this->BO->getOID())."'", "Edit", "edit".$this->BO->getOID()."But");
     264:             $html .= $button->render();
     265:             $html .= '&nbsp;&nbsp;';
     266:             $js = "$('#dialogDiv').text('Are you sure you wish to delete this item?');
     267:                 $('#dialogDiv').dialog({
     268:                 buttons: {
     269:                     'OK': function(event, ui) {
     270:                         $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('deleteOID')) : 'deleteOID')."\"]').attr('value', '".$this->BO->getOID()."');
     271:                         $('#deleteForm').submit();
     272:                     },
     273:                     'Cancel': function(event, ui) {
     274:                         $(this).dialog('close');
     275:                     }
     276:                 }
     277:             })
     278:             $('#dialogDiv').dialog('open');
     279:             return false;";
     280:             $button = new Button($js, "Delete", "delete".$this->BO->getOID()."But");
     281:             $html .= $button->render();
     282:         }
     283:         $fields['adminButtons'] = $html;
     284:
     285:         // buffer security fields to $formSecurityFields variable
     286:         $fields['formSecurityFields'] = self::renderSecurityFields();
     287:
     288:         self::$logger->debug('<<listView [HTML]');
     289:         return AlphaView::loadTemplate($this->BO, 'list', $fields);
     290:     }
     291:
     292:     /**
     293:      * (non-PHPdoc)
     294:      * @see alpha/view/renderers/AlphaRendererProviderInterface::detailedView()
     295:      */
     296:     public function detailedView($fields=array()) {
     297:         self::$logger->debug('>>detailedView(fields=['.var_export($fields, true).'])');
     298:
     299:         global $config;
     300:
     301:         // we may want to display the OID regardless of class
     302:         $fields['OIDLabel'] = $this->BO->getDataLabel('OID');
     303:         $fields['OID'] = $this->BO->getOID();
     304:
     305:         // buffer form fields to $formFields
     306:         $fields['formFields'] = $this->renderAllFields('view');
     307:
     308:         // Back button
     309:         $button = new Button('history.back()', 'Back', 'backBut');
     310:         $fields['backButton'] = $button->render();
     311:
     312:         $html = '';
     313:         // render edit and delete buttons for admins only
     314:         if (isset($_SESSION['currentUser']) && $_SESSION['currentUser']->inGroup('Admin')) {
     315:             $html .= '&nbsp;&nbsp;';
     316:             $button = new Button("document.location = '".FrontController::generateSecureURL('act=Edit&bo='.get_class($this->BO)."&oid=".$this->BO->getOID())."'", "Edit", "editBut");
     317:             $html .= $button->render();
     318:             $html .= '&nbsp;&nbsp;';
     319:             $js = "$('#dialogDiv').text('Are you sure you wish to delete this item?');
     320:                 $('#dialogDiv').dialog({
     321:                 buttons: {
     322:                     'OK': function(event, ui) {
     323:                         $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('deleteOID')) : 'deleteOID')."\"]').attr('value', '".$this->BO->getOID()."');
     324:                         $('#deleteForm').submit();
     325:                     },
     326:                     'Cancel': function(event, ui) {
     327:                         $(this).dialog('close');
     328:                     }
     329:                 }
     330:             })
     331:             $('#dialogDiv').dialog('open');
     332:             return false;";
     333:             $button = new Button($js, "Delete", "deleteBut");
     334:             $html .= $button->render();
     335:         }
     336:         $fields['adminButtons'] = $html;
     337:
     338:         self::$logger->debug('<<detailedView [HTML]');
     339:         return AlphaView::loadTemplate($this->BO, 'detail', $fields);
     340:     }
     341:
     342:     /**
     343:      * (non-PHPdoc)
     344:      * @see alpha/view/renderers/AlphaRendererProviderInterface::adminView()
     345:      */
     346:     public function adminView($fields=array()) {
     347:         self::$logger->debug('>>adminView(fields=['.var_export($fields, true).'])');
     348:
     349:         global $config;
     350:
     351:         // the form action
     352:         $fields['formAction'] = $_SERVER['REQUEST_URI'];
     353:
     354:         // the class name of the BO
     355:         $fields['className'] = get_class($this->BO);
     356:
     357:         // the table name in the DB for the BO
     358:         $fields['tableName'] = $this->BO->getTableName();
     359:
     360:         // record count for the BO in the DB
     361:         $fields['count'] = ($this->BO->checkTableExists() ? $this->BO->getCount() : '<span class="warning">unavailable</span>');
     362:
     363:         // table exists in the DB?
     364:         $fields['tableExists'] = ($this->BO->checkTableExists() ? '<span class="success">Yes</span>' : '<span class="warning">No</span>');
     365:
     366:         if($this->BO->getMaintainHistory())
     367:             $fields['tableExists'] = ($this->BO->checkTableExists(true) ? '<span class="success">Yes</span>' : '<span class="warning">No history table</span>');
     368:
     369:         // table schema needs to be updated in the DB?
     370:         $fields['tableNeedsUpdate'] = ($this->BO->checkTableNeedsUpdate() ? '<span class="warning">Yes</span>' : '<span class="success">No</span>');
     371:
     372:         // create button
     373:         if($this->BO->checkTableExists()) {
     374:             $button = new Button("document.location = '".FrontController::generateSecureURL('act=Create&bo='.get_class($this->BO))."'", "Create New", "create".get_class($this->BO)."But");
     375:             $fields['createButton'] = $button->render();
     376:         }else{
     377:             $fields['createButton'] = '';
     378:         }
     379:
     380:         // list all button
     381:         if($this->BO->checkTableExists()) {
     382:             $button = new Button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'", "List All", "list".get_class($this->BO)."But");
     383:             $fields['listButton'] = $button->render();
     384:         }else{
     385:             $fields['listButton'] = '';
     386:         }
     387:
     388:         // the create table button (if required)
     389:         $html = '';
     390:
     391:         if (!$this->BO->checkTableExists()) {
     392:             $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('createTableBut')) : 'createTableBut');
     393:             $button = new Button('submit', 'Create Table', $fieldname);
     394:             $html .= $button->render();
     395:             // hidden field so that we know which class to create the table for
     396:             $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('createTableClass')) : 'createTableClass');
     397:             $html .= '<input type="hidden" name="'.$fieldname.'" value="'.get_class($this->BO).'"/>';
     398:         }
     399:
     400:         if ($html == '' && $this->BO->getMaintainHistory() && !$this->BO->checkTableExists(true)) {
     401:             $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('createHistoryTableBut')) : 'createHistoryTableBut');
     402:             $button = new Button('submit', 'Create History Table', $fieldname);
     403:             $html .= $button->render();
     404:             // hidden field so that we know which class to create the table for
     405:             $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('createTableClass')) : 'createTableClass');
     406:             $html .= '<input type="hidden" name="'.$fieldname.'" value="'.get_class($this->BO).'"/>';
     407:         }
     408:         $fields['createTableButton'] = $html;
     409:
     410:         // recreate and update table buttons (if required)
     411:         $html = '';
     412:         if ($this->BO->checkTableNeedsUpdate() && $this->BO->checkTableExists()) {
     413:             $js = "$('#dialogDiv').text('Are you sure you wish to recreate this class table (all data will be lost)?');
     414:                 $('#dialogDiv').dialog({
     415:                 buttons: {
     416:                     'OK': function(event, ui) {
     417:                         //$('#admin_".get_class($this->BO)."_button_pressed').attr('value', 'recreateTableBut');
     418:                         $('[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');
     419:                         $('#admin_".get_class($this->BO)."').submit();
     420:                     },
     421:                     'Cancel': function(event, ui) {
     422:                         $(this).dialog('close');
     423:                     }
     424:                 }
     425:             })
     426:             $('#dialogDiv').dialog('open');
     427:             return false;";
     428:
     429:             $button = new Button($js , "Recreate Table", "recreateTableBut");
     430:             $html .= $button->render();
     431:             // hidden field so that we know which class to recreate the table for
     432:             $html .= '<input type="hidden" name="recreateTableClass" value="'.get_class($this->BO).'"/>';
     433:             $html .= '&nbsp;&nbsp;';
     434:             $js = "$('#dialogDiv').text('Are you sure you wish to attempt to modify this class table by adding new attributes?');
     435:                 $('#dialogDiv').dialog({
     436:                 buttons: {
     437:                     'OK': function(event, ui) {
     438:                         //$('#admin_".get_class($this->BO)."_button_pressed').attr('value', 'updateTableBut');
     439:                         $('[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');
     440:                         $('#admin_".get_class($this->BO)."').submit();
     441:                     },
     442:                     'Cancel': function(event, ui) {
     443:                         $(this).dialog('close');
     444:                     }
     445:                 }
     446:             })
     447:             $('#dialogDiv').dialog('open');
     448:             return false;";
     449:             $button = new Button($js , "Update Table", "updateTableBut");
     450:             $html .= $button->render();
     451:             // hidden field so that we know which class to update the table for
     452:             $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('updateTableClass')) : 'updateTableClass');
     453:             $html .= '<input type="hidden" name="'.$fieldname.'" value="'.get_class($this->BO).'"/>';
     454:             // hidden field to tell us which button was pressed
     455:             $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');
     456:             $html .= '<input type="hidden" id="'.$fieldname.'" name="'.$fieldname.'" value=""/>';
     457:         }
     458:         $fields['recreateOrUpdateButtons'] = $html;
     459:
     460:         // buffer security fields to $formSecurityFields variable
     461:         $fields['formSecurityFields'] = self::renderSecurityFields();
     462:
     463:         self::$logger->debug('<<adminView [HTML]');
     464:         return AlphaView::loadTemplate($this->BO, 'admin', $fields);
     465:     }
     466:
     467:     /**
     468:      * (non-PHPdoc)
     469:      * @see alpha/view/renderers/AlphaRendererProviderInterface::displayPageHead()
     470:      */
     471:     public static function displayPageHead($controller) {
     472:         if(self::$logger == null)
     473:             self::$logger = new Logger('AlphaRendererProviderHTML');
     474:
     475:         self::$logger->debug('>>displayPageHead(controller=['.var_export($controller, true).'])');
     476:
     477:         global $config;
     478:
     479:         if(!AlphaController::checkControllerDefExists(get_class($controller)))
     480:             throw new IllegalArguementException('The controller provided ['.get_class($controller).'] is not defined anywhere!');
     481:
     482:         $html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
     483:
     484:         $html.= '<html>';
     485:         $html.= '<head>';
     486:         $html.= '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
     487:         $html.= '<title>'.$controller->getTitle().'</title>';
     488:         if($controller->getKeywords() != '')
     489:             $html.= '<meta name="Keywords" content="'.$controller->getKeywords().'">';
     490:         if($controller->getDescription() != '')
     491:             $html.= '<meta name="Description" content="'.$controller->getDescription().'">';
     492:         $html.= '<meta name="title" content="'.$controller->getTitle().'">';
     493:         $html.= '<meta name="robots" content="index,follow,NOODP">';
     494:         if ($controller->getBO() != null && $controller->getBO()->hasAttribute('URL')) {
     495:             $URL = $controller->getBO()->get('URL');
     496:             if($URL != '')
     497:                 $html.= '<link rel="canonical" href="'.$URL.'" />';
     498:         }
     499:         $html.= '<meta http-equiv="imagetoolbar" content="no">';
     500:
     501:         $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">';
     502:         $html.= '<link rel="StyleSheet" type="text/css" href="'.$config->get('app.url').'alpha/css/alpha.css">';
     503:         $html.= '<link rel="StyleSheet" type="text/css" href="'.$config->get('app.url').'config/css/overrides.css">';
     504:
     505:         $html.= '<script type="text/javascript" src="'.$config->get('app.url').'alpha/lib/jquery/jquery-1.5.1.min.js"></script>';
     506:         $html.= '<script type="text/javascript" src="'.$config->get('app.url').'alpha/scripts/validation.js"></script>';
     507:         $html.= '<script type="text/javascript" src="'.$config->get('app.url').'alpha/lib/jquery/contextMenu/jquery.contextMenu.js"></script>';
     508:
     509:         $html.= '<script type="text/javascript" src="'.$config->get('app.url').'alpha/lib/jquery/ui/jquery-ui-1.8.11.custom.min.js"></script>';
     510:
     511:         $html.= '<script type="text/javascript" src="'.$config->get('app.url').'alpha/lib/jquery/ui/jquery.ui.potato.menu.js"></script>';
     512:
     513:         $html.= '<script type="text/javascript" src="'.$config->get('app.url').'alpha/lib/jquery/ui/jquery.ui.checkbox.js"></script>';
     514:
     515:         // handle force-frames
     516:         if($config->get('app.force.frame')) {
     517:             // if no-forceframe=true or we are in the admin backend, don't force frame
     518:             if(!isset($_GET['no-forceframe']) && strpos($_SERVER['REQUEST_URI'], '/tk/') === false) {
     519:                 $html.= '<script type="text/javascript">';
     520:                 $html.= 'pageLoc = self.location;';
     521:                 $html.= 'pageAdd = top.location;';
     522:
     523:                 $html.= 'if (pageLoc == pageAdd) {';
     524:                 $html.= '    contentSrc = escape(pageLoc);';
     525:                 $html.= '    contPage = \''.$config->get('app.url').'?\' + contentSrc;';
     526:                 $html.= '    top.location.href = contPage;';
     527:                 $html.= '}';
     528:                 $html.= '</script>';
     529:             }
     530:         }
     531:
     532:         if (isset($_SESSION['currentUser']) && AlphaDAO::isInstalled() && $_SESSION['currentUser']->inGroup('Admin') && strpos($_SERVER['REQUEST_URI'], '/tk/') !== false) {
     533:             $html.= '<script type="text/javascript">';
     534:             $html.= '   (function($) {';
     535:             $html.= '       $(document).ready(function(){';
     536:             $html.= '       $("#adminmenu").ptMenu();';
     537:             $html.= '   });';
     538:             $html.= '})(jQuery);';
     539:             $html.= '</script>';
     540:         }
     541:
     542:         // general dialog defaults
     543:         $html.= '<script type="text/javascript">';
     544:         $html.= '   (function($) {';
     545:         $html.= '       var dialogCoords = [(screen.width/2)-200, (screen.height/2)-200];';
     546:         $html.= '       $(document).ready(function(){';
     547:         $html.= '           $.extend($.ui.dialog.prototype.options, {';
     548:         $html.= '               modal: true,';
     549:         $html.= '               resizable: false,';
     550:         $html.= '               draggable: false,';
     551:         $html.= '               autoOpen: false,';
     552:         $html.= '               height: 200,';
     553:         $html.= '               width: 400,';
     554:         $html.= '               position: dialogCoords,';
     555:         $html.= '               buttons: {';
     556:         $html.= '                   "Cancel": function() {';
     557:         $html.= '                       $(this).dialog("close");';
     558:         $html.= '                   }';
     559:         $html.= '               }';
     560:         $html.= '           });';
     561:         $html.= '       });';
     562:         $html.= '   })(jQuery);';
     563:         $html.= '</script>';
     564:
     565:         // record selector JS
     566:         $html.= '<script type="text/javascript">';
     567:         $html.= '   (function($) {';
     568:         $html.= '       $(document).ready(function(){';
     569:         $html.= '           var dialogOpts = {';
     570:         $html.= '               title: "Record selector",';
     571:         $html.= '               modal: true,';
     572:         $html.= '               resizable: false,';
     573:         $html.= '               draggable: false,';
     574:         $html.= '               autoOpen: false,';
     575:         $html.= '               height: 300,';
     576:         $html.= '               width: 600';
     577:         $html.= '           };';
     578:         $html.= '           $("#recordSelector").dialog(dialogOpts);';
     579:         $html.= '       });';
     580:         $html.= '   })(jQuery);';
     581:         $html.= '</script>';
     582:
     583:         // checkbox JS
     584:         $html.= '<script type="text/javascript">';
     585:         $html.= '   (function($) {';
     586:         $html.= '       $(document).ready(function(){';
     587:         $html .= '          $(":checkbox").checkbox();';
     588:         $html.= '       });';
     589:         $html.= '   })(jQuery);';
     590:         $html.= '</script>';
     591:
     592:         if(method_exists($controller, 'during_displayPageHead_callback'))
     593:             $html.= $controller->during_displayPageHead_callback();
     594:
     595:         $html.= '</head>';
     596:         try {
     597:             if($controller->getBO() != null)
     598:                 $html.= '<body'.($controller->getBO()->get('bodyOnload') != '' ? ' onload="'.$controller->getBO()->get('bodyOnload').'"' : '').'>';
     599:             else
     600:                 $html.= '<body>';
     601:         } catch (AlphaException $e) {
     602:             $html.= '<body>';
     603:         }
     604:
     605:         if(method_exists($controller, 'insert_CMSDisplayStandardHeader_callback'))
     606:             $html.= $controller->insert_CMSDisplayStandardHeader_callback();
     607:
     608:         $html .= '<div id="recordSelector"></div>';
     609:
     610:         // TODO need to move this elsewhere as the $renderStatus param is no longer provided
     611:         /*if($renderStatus) {
     612:             // render a status message if there is any
     613:             $message = $controller->getStatusMessage();
     614:             if(!empty($message))
     615:                 $html .= $message;
     616:         }*/
     617:
     618:         self::$logger->debug('<<displayPageHead [HTML]');
     619:         return $html;
     620:     }
     621:
     622:     /**
     623:      * (non-PHPdoc)
     624:      * @see alpha/view/renderers/AlphaRendererProviderInterface::displayPageFoot()
     625:      */
     626:     public static function displayPageFoot($controller) {
     627:         if(self::$logger == null)
     628:             self::$logger = new Logger('AlphaRendererProviderHTML');
     629:
     630:         self::$logger->debug('>>displayPageFoot(controller=['.get_class($controller).'])');
     631:
     632:         $html = '';
     633:
     634:         $html .= '<div id="dialogDiv"></div>';
     635:         $html .= '</body>';
     636:         $html .= '</html>';
     637:
     638:         self::$logger->debug('<<displayPageFoot ['.$html.']');
     639:         return $html;
     640:     }
     641:
     642:     /**
     643:      * (non-PHPdoc)
     644:      * @see alpha/view/renderers/AlphaRendererProviderInterface::displayUpdateMessage()
     645:      */
     646:     public static function displayUpdateMessage($message) {
     647:         if(self::$logger == null)
     648:             self::$logger = new Logger('AlphaRendererProviderHTML');
     649:         self::$logger->debug('>>displayUpdateMessage(message=['.$message.'])');
     650:
     651:         $html = '<div class="ui-state-highlight ui-corner-all" style="padding: 0pt 0.7em;">
     652:                 <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: 0.3em;"></span>
     653:                 '.$message.'</p></div>';
     654:
     655:         self::$logger->debug('<<displayUpdateMessage ['.$html.']');
     656:         return $html;
     657:     }
     658:
     659:     /**
     660:      * (non-PHPdoc)
     661:      * @see alpha/view/renderers/AlphaRendererProviderInterface::displayErrorMessage()
     662:      */
     663:     public static function displayErrorMessage($message) {
     664:         if(self::$logger == null)
     665:             self::$logger = new Logger('AlphaRendererProviderHTML');
     666:         self::$logger->debug('>>displayErrorMessage(message=['.$message.'])');
     667:
     668:         $html = '<div class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em;">
     669:                 <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>
     670:                 '.$message.'</p></div>';
     671:
     672:         self::$logger->debug('<<displayErrorMessage ['.$html.']');
     673:         return $html;
     674:     }
     675:
     676:     /**
     677:      * (non-PHPdoc)
     678:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderErrorPage()
     679:      */
     680:     public static function renderErrorPage($code, $message) {
     681:         global $config;
     682:
     683:         $html = '<html><head>';
     684:         $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">';
     685:         $html .= '<link rel="StyleSheet" type="text/css" href="'.$config->get('app.url').'alpha/css/alpha.css">';
     686:         $html .= '<link rel="StyleSheet" type="text/css" href="'.$config->get('app.url').'config/css/overrides.css">';
     687:         $html .= '<title>'.$code.' - '.$message.'</title></head>';
     688:         $html .= '<body>';
     689:         $html .= '<div class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em;">
     690:                 <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>
     691:                 <strong>'.$code.':</strong> '.$message.'</p>
     692:                 </div>';
     693:         $html .= '</body></html>';
     694:
     695:         return $html;
     696:     }
     697:
     698:     /**
     699:      * (non-PHPdoc)
     700:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderDeleteForm()
     701:      */
     702:     public static function renderDeleteForm() {
     703:         if(self::$logger == null)
     704:             self::$logger = new Logger('AlphaRendererProviderHTML');
     705:         self::$logger->debug('>>renderDeleteForm()');
     706:
     707:         global $config;
     708:
     709:         $html = '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST" id="deleteForm">';
     710:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('deleteOID')) : 'deleteOID');
     711:         $html .= '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value=""/>';
     712:         $html .= self::renderSecurityFields();
     713:         $html .= '</form>';
     714:
     715:         self::$logger->debug('<<renderDeleteForm ['.$html.']');
     716:         return $html;
     717:     }
     718:
     719:     /**
     720:      * (non-PHPdoc)
     721:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderSecurityFields()
     722:      */
     723:     public static function renderSecurityFields() {
     724:         if(self::$logger == null)
     725:             self::$logger = new Logger('AlphaRendererProviderHTML');
     726:
     727:         self::$logger->debug('>>renderSecurityFields()');
     728:
     729:         global $config;
     730:
     731:         $html = '';
     732:
     733:         $fields = AlphaController::generateSecurityFields();
     734:
     735:         if($config->get('security.encrypt.http.fieldnames'))
     736:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt('var1'));
     737:         else
     738:             $fieldname = 'var1';
     739:
     740:         $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$fields[0].'"/>';
     741:
     742:         if($config->get('security.encrypt.http.fieldnames'))
     743:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt('var2'));
     744:         else
     745:             $fieldname = 'var2';
     746:
     747:         $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$fields[1].'"/>';
     748:
     749:         self::$logger->debug('<<renderSecurityFields ['.$html.']');
     750:         return $html;
     751:     }
     752:
     753:     /**
     754:      * (non-PHPdoc)
     755:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderIntegerField()
     756:      */
     757:     public function renderIntegerField($name, $label, $mode, $value='', $tableTags=true) {
     758:         self::$logger->debug('>>renderIntegerField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
     759:
     760:         global $config;
     761:
     762:         if($config->get('security.encrypt.http.fieldnames'))
     763:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
     764:         else
     765:             $fieldname = $name;
     766:
     767:         $html = '';
     768:
     769:         if ($mode == 'create') {
     770:             if($tableTags) {
     771:                 $html .= '<tr><th style="width:25%;">';
     772:                 $html .= $label;
     773:                 $html .= '</th>';
     774:
     775:                 $html .= '<td>';
     776:                 $html .= '<input type="text" style="width:100%;" name="'.$fieldname.'" value="'. (isset ($_POST[$name]) ? $_POST[$name] : '').'"/><br>';
     777:                 $html .= '</td></tr>';
     778:             }else{
     779:                 $html .= '<input type="text" style="width:100%;" name="'.$fieldname.'" value="'. (isset ($_POST[$name]) ? $_POST[$name] : '').'"/><br>';
     780:             }
     781:         }
     782:
     783:         if ($mode == 'edit') {
     784:             if($tableTags) {
     785:                 $html .= '<tr><th style="width:25%;">';
     786:                 $html .= $label;
     787:                 $html .= '</th>';
     788:
     789:                 $html .= '<td>';
     790:                 $html .= '<input type="text" style="width:100%;" name="'.$fieldname.'" value="'.$value.'"/><br>';
     791:                 $html .= '</td></tr>';
     792:             }else{
     793:                 $html .= '<input type="text" style="width:100%;" name="'.$fieldname.'" value="'.$value.'"/>';
     794:             }
     795:         }
     796:
     797:         self::$logger->debug('<<renderIntegerField ['.$html.']');
     798:         return $html;
     799:     }
     800:
     801:     /**
     802:      * (non-PHPdoc)
     803:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderDoubleField()
     804:      */
     805:     public function renderDoubleField($name, $label, $mode, $value='', $tableTags=true) {
     806:         self::$logger->debug('>>renderDoubleField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
     807:
     808:         global $config;
     809:
     810:         if($config->get('security.encrypt.http.fieldnames'))
     811:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
     812:         else
     813:             $fieldname = $name;
     814:
     815:         $html = '';
     816:
     817:         if ($mode == 'create') {
     818:             if($tableTags) {
     819:                 $html .= '<tr><th style="width:25%;">';
     820:                 $html .= $label;
     821:                 $html .= '</th>';
     822:
     823:                 $html .= '<td>';
     824:                 $html .= '<input type="text" size="13" name="'.$fieldname.'" value="'. (isset ($_POST[$name]) ? $_POST[$name] : '').'"/><br>';
     825:                 $html .= '</td></tr>';
     826:             }else{
     827:                 $html .= '<input type="text" size="13" name="'.$fieldname.'" value="'. (isset ($_POST[$name]) ? $_POST[$name] : '').'"/>';
     828:             }
     829:         }
     830:
     831:         if ($mode == 'edit') {
     832:             if($tableTags) {
     833:                 $html .= '<tr><th style="width:25%;">';
     834:                 $html .= $label;
     835:                 $html .= '</th>';
     836:
     837:                 $html .= '<td>';
     838:                 $html .= '<input type="text" size="13" name="'.$fieldname.'" value="'.$value.'"/><br>';
     839:                 $html .= '</td></tr>';
     840:             }else{
     841:                 $html .= '<input type="text" size="13" name="'.$fieldname.'" value="'.$value.'"/>';
     842:             }
     843:         }
     844:
     845:         self::$logger->debug('<<renderDoubleField ['.$html.']');
     846:         return $html;
     847:     }
     848:
     849:     /**
     850:      * (non-PHPdoc)
     851:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderBooleanField()
     852:      */
     853:     public function renderBooleanField($name, $label, $mode, $value='', $tableTags=true) {
     854:         self::$logger->debug('>>renderBooleanField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
     855:
     856:         global $config;
     857:
     858:         if($config->get('security.encrypt.http.fieldnames'))
     859:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
     860:         else
     861:             $fieldname = $name;
     862:
     863:         $html = '';
     864:
     865:         if ($mode == 'create') {
     866:             if($tableTags) {
     867:                 $html .= '<tr><th style="width:25%;">';
     868:                 $html .= '<label for="'.$fieldname.'">'.$label.'</label>';
     869:                 $html .= '</th>';
     870:
     871:                 $html .= '<td>';
     872:                 $html .= '<input type="hidden" name="'.$fieldname.'" value="0">';
     873:                 $html .= '<input type="checkbox" name="'.$fieldname.'" id="'.$fieldname.'" />';
     874:                 $html .= '</td></tr>';
     875:             }else{
     876:                 $html .= $label.'<select size="1" name="'.$fieldname.'"/>';
     877:                 $html .= '<option value="0" selected>No</option>';
     878:                 $html .= '<option value="1">Yes</option>';
     879:                 $html .= '</select>';
     880:             }
     881:         }
     882:
     883:         if ($mode == 'edit') {
     884:             if($tableTags) {
     885:                 $html .= '<tr><th style="width:25%;">';
     886:                 $html .= '<label for="'.$fieldname.'">'.$label.'</label>';
     887:                 $html .= '</th>';
     888:
     889:                 $html .= '<td>';
     890:                 $html .= '<input type="hidden" name="'.$fieldname.'" value="0">';
     891:                 $html .= '<input type="checkbox" name="'.$fieldname.'" id="'.$fieldname.'"'.($value == '1'? ' checked':'').' />';
     892:                 $html .= '</td></tr>';
     893:             }else{
     894:                 $html .= '<label for="'.$fieldname.'">'.$label.'</label>';
     895:                 $html .= '<input type="hidden" name="'.$fieldname.'" value="0">';
     896:                 $html .= '<input type="checkbox" name="'.$fieldname.'" id="'.$fieldname.'"'.($value == '1'? ' checked':'').' />';
     897:             }
     898:         }
     899:
     900:         self::$logger->debug('<<renderBooleanField ['.$html.']');
     901:         return $html;
     902:     }
     903:
     904:     /**
     905:      * (non-PHPdoc)
     906:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderEnumField()
     907:      */
     908:     public function renderEnumField($name, $label, $mode, $options, $value='', $tableTags=true) {
     909:         self::$logger->debug('>>renderEnumField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
     910:
     911:         global $config;
     912:
     913:         if($config->get('security.encrypt.http.fieldnames'))
     914:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
     915:         else
     916:             $fieldname = $name;
     917:
     918:         $html = '';
     919:
     920:         if ($mode == 'create') {
     921:             if ($tableTags) {
     922:                 $html .= '<tr><th style="width:25%;">';
     923:                 $html .= $label;
     924:                 $html .= '</th>';
     925:                 $html .= '<td>';
     926:                 $html .= '<select name="'.$fieldname.'"/>';
     927:                 foreach ($options as $val) {
     928:                     $html .= '<option value="'.$val.'">'.$val.'</option>';
     929:                 }
     930:                 $html .= '</select><br>';
     931:                 $html .= '</td></tr>';
     932:             }else{
     933:                 $html .= '<select name="'.$fieldname.'"/>';
     934:                 foreach ($options as $val) {
     935:                     $html .= '<option value="'.$val.'">'.$val.'</option>';
     936:                 }
     937:                 $html .= '</select>';
     938:             }
     939:         }
     940:
     941:         if ($mode == 'edit') {
     942:             if ($tableTags) {
     943:                 $html .= '<tr><th style="width:25%;">';
     944:                 $html .= $label;
     945:                 $html .= '</th>';
     946:                 $html .= '<td>';
     947:                 $html .= '<select name="'.$fieldname.'"/>';
     948:                 foreach ($options as $val) {
     949:                     if ($value == $val)
     950:                         $html .= '<option value="'.$val.'" selected>'.$val.'</option>';
     951:                     else
     952:                         $html .= '<option value="'.$val.'">'.$val.'</option>';
     953:                 }
     954:                 $html .= '</select><br>';
     955:                 $html .= '</td></tr>';
     956:             }else{
     957:                 $html .= '<select name="'.$fieldname.'"/>';
     958:                 foreach ($options as $val) {
     959:                     if ($value == $val)
     960:                         $html .= '<option value="'.$val.'" selected>'.$val.'</option>';
     961:                     else
     962:                         $html .= '<option value="'.$val.'">'.$val.'</option>';
     963:                 }
     964:                 $html .= '</select>';
     965:             }
     966:         }
     967:
     968:         self::$logger->debug('<<renderEnumField ['.$html.']');
     969:         return $html;
     970:     }
     971:
     972:     /**
     973:      * (non-PHPdoc)
     974:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderDEnumField()
     975:      */
     976:     public function renderDEnumField($name, $label, $mode, $options, $value='', $tableTags=true) {
     977:         self::$logger->debug('>>renderDEnumField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
     978:
     979:         global $config;
     980:
     981:         if($config->get('security.encrypt.http.fieldnames'))
     982:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
     983:         else
     984:             $fieldname = $name;
     985:
     986:         $html = '';
     987:
     988:         if ($mode == 'create') {
     989:             if($tableTags) {
     990:                 $html .= '<tr><th style="width:25%;">';
     991:                 $html .= $label;
     992:                 $html .= '</th>';
     993:                 $html .= '<td>';
     994:                 $html .= '<select name="'.$fieldname.'"/>';
     995:                 foreach (array_keys($options) as $index) {
     996:                     $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
     997:                 }
     998:                 $html .= '</select><br>';
     999:                 $html .= '</td></tr>';
    1000:             }else{
    1001:                 $html .= '<select name="'.$fieldname.'"/>';
    1002:                 foreach (array_keys($options) as $index) {
    1003:                     $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
    1004:                 }
    1005:                 $html .= '</select>';
    1006:             }
    1007:         }
    1008:
    1009:         if ($mode == 'edit') {
    1010:             if($tableTags) {
    1011:                 $html .= '<tr><th style="width:25%;">';
    1012:                 $html .= $label;
    1013:                 $html .= '</th>';
    1014:                 $html .= '<td>';
    1015:                 $html .= '<select name="'.$fieldname.'"/>';
    1016:                 foreach (array_keys($options) as $index) {
    1017:                     if ($value == $index)
    1018:                         $html .= '<option value="'.$index.'" selected>'.$options[$index].'</option>';
    1019:                     else
    1020:                         $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
    1021:                 }
    1022:                 $html .= '</select><br>';
    1023:                 $html .= '</td></tr>';
    1024:             }else{
    1025:                 $html .= '<select name="'.$fieldname.'"/>';
    1026:                 foreach (array_keys($options) as $index) {
    1027:                     if ($value == $index)
    1028:                         $html .= '<option value="'.$index.'" selected>'.$options[$index].'</option>';
    1029:                     else
    1030:                         $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
    1031:                 }
    1032:                 $html .= '</select>';
    1033:             }
    1034:         }
    1035:
    1036:         self::$logger->debug('<<renderDEnumField ['.$html.']');
    1037:         return $html;
    1038:     }
    1039:
    1040:     /**
    1041:      * (non-PHPdoc)
    1042:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderDefaultField()
    1043:      */
    1044:     public function renderDefaultField($name, $label, $mode, $value='', $tableTags=true) {
    1045:         self::$logger->debug('>>renderDefaultField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
    1046:
    1047:         global $config;
    1048:
    1049:         if($config->get('security.encrypt.http.fieldnames'))
    1050:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
    1051:         else
    1052:             $fieldname = $name;
    1053:
    1054:         $html = '';
    1055:
    1056:         if ($mode == 'create') {
    1057:             if($tableTags) {
    1058:                 $html .= '<tr><th colspan="2">';
    1059:                 $html .= $label;
    1060:                 $html .= '</th></tr>';
    1061:
    1062:                 $html .= '<tr><td colspan="2">';
    1063:                 $html .= '<textarea cols="100" rows="3" name="'.$fieldname.'">'. (isset ($_POST[$name]) ? $_POST[$name] : '').'</textarea><br>';
    1064:                 $html .= '</td></tr>';
    1065:             }else{
    1066:                 $html .= '<textarea cols="100" rows="3" name="'.$fieldname.'">'. (isset ($_POST[$name]) ? $_POST[$name] : '').'</textarea>';
    1067:             }
    1068:         }
    1069:
    1070:         if ($mode == 'edit') {
    1071:             if($tableTags) {
    1072:                 $html .= '<tr><th colspan="2">';
    1073:                 $html .= $label;
    1074:                 $html .= '</th></tr>';
    1075:
    1076:                 $html .= '<tr><td colspan="2">';
    1077:                 $html .= '<textarea cols="100" rows="3" name="'.$fieldname.'">'.$value.'</textarea><br>';
    1078:                 $html .= '</td></tr>';
    1079:             }else{
    1080:                 $html .= '<textarea cols="100" rows="3" name="'.$fieldname.'">'.$value.'</textarea>';
    1081:             }
    1082:         }
    1083:
    1084:         if ($mode == 'view') {
    1085:             if($tableTags) {
    1086:                 $html .= '<tr><th>';
    1087:                 $html .= $label;
    1088:                 $html .= '</th>';
    1089:
    1090:                 $html .= '<td>&nbsp;';
    1091:                 if(method_exists($this, 'during_renderDefaultField_callback'))
    1092:                     $html .= $this->during_renderDefaultField_callback($name, $mode, $value);
    1093:                 else
    1094:                     $html .= $value;
    1095:                 $html .= '</td></tr>';
    1096:             }else{
    1097:                 $html .= $value;
    1098:             }
    1099:         }
    1100:
    1101:         self::$logger->debug('<<renderDefaultField ['.$html.']');
    1102:         return $html;
    1103:     }
    1104:
    1105:     /**
    1106:      * (non-PHPdoc)
    1107:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderTextField()
    1108:      */
    1109:     public function renderTextField($name, $label, $mode, $value='', $tableTags=true) {
    1110:         self::$logger->debug('>>renderTextField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
    1111:
    1112:         global $config;
    1113:
    1114:         if($config->get('security.encrypt.http.fieldnames'))
    1115:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
    1116:         else
    1117:             $fieldname = $name;
    1118:
    1119:         $html = '';
    1120:
    1121:         if ($mode == 'create') {
    1122:             // give 10 rows for content fields (other 5 by default)
    1123:             if($name == 'content')
    1124:                 $text = new TextBox($this->BO->getPropObject($name), $label, $fieldname, 10);
    1125:             else
    1126:                 $text = new TextBox($this->BO->getPropObject($name), $label, $fieldname);
    1127:             $html .= $text->render($tableTags);
    1128:         }
    1129:
    1130:         if ($mode == 'edit') {
    1131:             // give 10 rows for content fields (other 5 by default)
    1132:             if($name == 'content') {
    1133:                 $viewState = ViewState::getInstance();
    1134:
    1135:                 if($viewState->get('markdownTextBoxRows') == '')
    1136:                     $text = new TextBox($this->BO->getPropObject($name), $label, $fieldname, 10);
    1137:                 else
    1138:                     $text = new TextBox($this->BO->getPropObject($name), $label, $fieldname, (integer)$viewState->get('markdownTextBoxRows'));
    1139:
    1140:                 $html .= $text->render($tableTags, true);
    1141:             }else{
    1142:                 $text = new TextBox($this->BO->getPropObject($name), $label, $fieldname);
    1143:                 $html .= $text->render($tableTags);
    1144:             }
    1145:         }
    1146:
    1147:         if ($mode == 'view') {
    1148:             if($tableTags)
    1149:                 $html .= '<tr><th>';
    1150:
    1151:             $html .= $label;
    1152:
    1153:             if($tableTags)
    1154:                 $html .= '</th>';
    1155:
    1156:             // filter ouput to prevent malicious injection
    1157:             $value = InputFilter::encode($value);
    1158:
    1159:             // ensures that line returns are rendered
    1160:             $value = str_replace("\n", '<br>', $value);
    1161:
    1162:             if($tableTags)
    1163:                 $html .= '<td>&nbsp;';
    1164:
    1165:             $html .= $value;
    1166:
    1167:             if($tableTags)
    1168:                 $html .= '</td></tr>';
    1169:         }
    1170:
    1171:         self::$logger->debug('<<renderTextField ['.$html.']');
    1172:         return $html;
    1173:     }
    1174:
    1175:     /**
    1176:      * (non-PHPdoc)
    1177:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderStringField()
    1178:      */
    1179:     public function renderStringField($name, $label, $mode, $value='', $tableTags=true) {
    1180:         self::$logger->debug('>>renderStringField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
    1181:
    1182:         global $config;
    1183:
    1184:         if($config->get('security.encrypt.http.fieldnames'))
    1185:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
    1186:         else
    1187:             $fieldname = $name;
    1188:
    1189:         $html = '';
    1190:
    1191:         if ($mode == 'create' || $mode == 'edit') {
    1192:             $string = new StringBox($this->BO->getPropObject($name), $this->BO->getDataLabel($name), $fieldname);
    1193:             $html .= $string->render($tableTags);
    1194:         }
    1195:
    1196:         if ($mode == 'view') {
    1197:             if($tableTags) {
    1198:                 $html .= '<tr><th>';
    1199:                 $html .= $label;
    1200:                 $html .= '</th>';
    1201:
    1202:                 $html .= '<td>&nbsp;';
    1203:                 $html .= $value;
    1204:                 $html .= '</td></tr>';
    1205:             }else{
    1206:                 $html .= $value;
    1207:             }
    1208:         }
    1209:
    1210:         self::$logger->debug('<<renderStringField ['.$html.']');
    1211:         return $html;
    1212:     }
    1213:
    1214:     /**
    1215:      * (non-PHPdoc)
    1216:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderRelationField()
    1217:      */
    1218:     public function renderRelationField($name, $label, $mode, $value='', $tableTags=true, $expanded=false, $buttons=true) {
    1219:         self::$logger->debug('>>renderRelationField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'], expanded=['.$expanded.'], buttons=['.$buttons.'])');
    1220:
    1221:         global $config;
    1222:
    1223:         if($config->get('security.encrypt.http.fieldnames'))
    1224:             $fieldname = base64_encode(AlphaSecurityUtils::encrypt($name));
    1225:         else
    1226:             $fieldname = $name;
    1227:
    1228:         $html = '';
    1229:
    1230:         $rel = $this->BO->getPropObject($name);
    1231:
    1232:         if ($mode == 'create' || $mode == 'edit') {
    1233:             if($rel->getRelationType() == 'MANY-TO-MANY') {
    1234:                 try{
    1235:                     // check to see if the rel is on this class
    1236:                     $rel->getSide(get_class($this->BO));
    1237:                     $widget = new RecordSelector($rel, $label, $fieldname, get_class($this->BO));
    1238:                     $html .= $widget->render($tableTags, $expanded, $buttons);
    1239:                 }catch (IllegalArguementException $iae) {
    1240:                     // the rel may be on a parent class
    1241:                     $parentClassName = ucfirst($this->BO->getTableName()).'Object';
    1242:                     $widget = new RecordSelector($rel, $label, $fieldname, $parentClassName);
    1243:                     $html .= $widget->render($tableTags, $expanded, $buttons);
    1244:                 }
    1245:             }else{
    1246:                 $rel = new RecordSelector($rel, $label, $name);
    1247:                 $html .= $rel->render($tableTags, $expanded, $buttons);
    1248:             }
    1249:         }
    1250:
    1251:         if ($mode == 'view') {
    1252:             if($rel->getRelationType() == 'MANY-TO-ONE') {
    1253:                 $html .= $this->renderDefaultField($name, $label, 'view', $rel->getRelatedClassDisplayFieldValue());
    1254:             }elseif($rel->getRelationType() == 'MANY-TO-MANY') {
    1255:                 try{
    1256:                     // check to see if the rel is on this class
    1257:                     $rel->getSide(get_class($this->BO));
    1258:                     $html .= $this->renderDefaultField($name, $label, 'view', $rel->getRelatedClassDisplayFieldValue(get_class($this->BO)));
    1259:                 }catch (IllegalArguementException $iae) {
    1260:                     // the rel may be on a parent class
    1261:                     $parentClassName = ucfirst($this->BO->getTableName()).'Object';
    1262:                     $html .= $this->renderDefaultField($name, $label, 'view', $rel->getRelatedClassDisplayFieldValue($parentClassName));
    1263:                 }
    1264:             }else{
    1265:                 $rel = new RecordSelector($rel, $label, $name);
    1266:                 $html .= $rel->render($tableTags, $expanded, $buttons);
    1267:             }
    1268:         }
    1269:
    1270:         self::$logger->debug('<<renderRelationField ['.$html.']');
    1271:         return $html;
    1272:     }
    1273:
    1274:     /**
    1275:      * (non-PHPdoc)
    1276:      * @see alpha/view/renderers/AlphaRendererProviderInterface::renderAllFields()
    1277:      */
    1278:     public function renderAllFields($mode, $filterFields=array(), $readOnlyFields=array()) {
    1279:         self::$logger->debug('>>renderAllFields(mode=['.$mode.'], filterFields=['.var_export($filterFields, true).'], readOnlyFields=['.var_export($readOnlyFields, true).'])');
    1280:
    1281:         $html = '';
    1282:
    1283:         // get the class attributes
    1284:         $properties = array_keys($this->BO->getDataLabels());
    1285:
    1286:         $orignalMode = $mode;
    1287:
    1288:         foreach($properties as $propName) {
    1289:             if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $filterFields)) {
    1290:                 // render readonly fields in the supplied array
    1291:                 if(in_array($propName, $readOnlyFields))
    1292:                     $mode = 'view';
    1293:                 else
    1294:                     $mode = $orignalMode;
    1295:
    1296:                 if(!is_object($this->BO->getPropObject($propName)))
    1297:                     continue;
    1298:
    1299:                 $propClass = get_class($this->BO->getPropObject($propName));
    1300:
    1301:                 // exclude non-Relation transient attributes from create and edit screens
    1302:                 if($propClass != 'Relation' && ($mode == 'edit' || $mode == 'create') && in_array($propName, $this->BO->getTransientAttributes())) {
    1303:                     continue;
    1304:                 }
    1305:
    1306:                 switch (strtoupper($propClass)) {
    1307:                     case 'INTEGER' :
    1308:                         if($mode == 'view') {
    1309:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName));
    1310:                         }else{
    1311:                             $html .= $this->renderIntegerField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1312:                         }
    1313:                     break;
    1314:                     case 'DOUBLE' :
    1315:                         if($mode == 'view') {
    1316:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName));
    1317:                         }else{
    1318:                             $html .= $this->renderDoubleField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1319:                         }
    1320:                     break;
    1321:                     case 'DATE' :
    1322:                         if($mode == 'view') {
    1323:                             $value = $this->BO->get($propName);
    1324:                             if ($value == '0000-00-00')
    1325:                                 $value = '';
    1326:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $value);
    1327:                         }else{
    1328:                             $date = new DateBox($this->BO->getPropObject($propName), $this->BO->getDataLabel($propName), $propName);
    1329:                             $html .= $date->render();
    1330:                         }
    1331:                     break;
    1332:                     case 'TIMESTAMP' :
    1333:                         if($mode == 'view') {
    1334:                             $value = $this->BO->get($propName);
    1335:                             if ($value == '0000-00-00 00:00:00')
    1336:                                 $value = '';
    1337:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $value);
    1338:                         }else{
    1339:                             $timestamp = new DateBox($this->BO->getPropObject($propName), $this->BO->getDataLabel($propName), $propName);
    1340:                             $html .= $timestamp->render();
    1341:                         }
    1342:                     break;
    1343:                     case 'STRING' :
    1344:                         $html .= $this->renderStringField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1345:                     break;
    1346:                     case 'TEXT' :
    1347:                         $html .= $this->renderTextField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1348:                     break;
    1349:                     case 'BOOLEAN' :
    1350:                         if($mode == 'view') {
    1351:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName));
    1352:                         }else{
    1353:                             $html .= $this->renderBooleanField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1354:                         }
    1355:                     break;
    1356:                     case 'ENUM' :
    1357:                         if($mode == 'view') {
    1358:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName));
    1359:                         }else{
    1360:                             $enum = $this->BO->getPropObject($propName);
    1361:                             $html .= $this->renderEnumField($propName, $this->BO->getDataLabel($propName), $mode, $enum->getOptions(), $this->BO->get($propName));
    1362:                         }
    1363:                     break;
    1364:                     case 'DENUM' :
    1365:                         if($mode == 'view') {
    1366:                             $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->getPropObject($propName)->getDisplayValue());
    1367:                         }else{
    1368:                             $denum = $this->BO->getPropObject($propName);
    1369:                             $html .= $this->renderDEnumField($propName, $this->BO->getDataLabel($propName), $mode, $denum->getOptions(), $this->BO->get($propName));
    1370:                         }
    1371:                     break;
    1372:                     case 'RELATION' :
    1373:                         $html .= $this->renderRelationField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1374:                     break;
    1375:                     default :
    1376:                         $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName));
    1377:                     break;
    1378:                 }
    1379:             }
    1380:         }
    1381:
    1382:         self::$logger->debug('<<renderAllFields ['.$html.']');
    1383:         return $html;
    1384:     }
    1385: }
    1386:
    1387: ?>