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