Alpha Framework alpha--view
[ class tree: alpha--view ] [ index: alpha--view ] [ all elements ]

Source for file AlphaView.inc

Documentation is available at AlphaView.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/util/AlphaErrorHandlers.inc';
  4. require_once $config->get('sysRoot').'alpha/util/Logger.inc';
  5. require_once $config->get('sysRoot').'alpha/model/types/Date.inc';
  6. require_once $config->get('sysRoot').'alpha/model/types/Timestamp.inc';
  7. require_once $config->get('sysRoot').'alpha/model/types/Double.inc';
  8. require_once $config->get('sysRoot').'alpha/model/types/Integer.inc';
  9. require_once $config->get('sysRoot').'alpha/model/types/String.inc';
  10. require_once $config->get('sysRoot').'alpha/model/types/Text.inc';
  11. require_once $config->get('sysRoot').'alpha/model/types/Enum.inc';
  12. require_once $config->get('sysRoot').'alpha/model/types/Boolean.inc';
  13. require_once $config->get('sysRoot').'alpha/view/widgets/Button.inc';
  14. require_once $config->get('sysRoot').'alpha/view/widgets/StringBox.inc';
  15. require_once $config->get('sysRoot').'alpha/view/widgets/DateBox.inc';
  16. require_once $config->get('sysRoot').'alpha/view/widgets/TextBox.inc';
  17. require_once $config->get('sysRoot').'alpha/view/widgets/RecordSelector.inc';
  18. require_once $config->get('sysRoot').'alpha/model/AlphaDAO.inc';
  19. require_once $config->get('sysRoot').'alpha/view/ViewState.inc';
  20.  
  21. /**
  22.  *
  23.  * The master rendering view class for the Alpha Framework.
  24.  * 
  25.  * @package alpha::view
  26.  * @since 1.0
  27.  * @author John Collins <dev@alphaframework.org>
  28.  * @version $Id: AlphaView.inc 1453 2011-12-04 15:12:54Z johnc $
  29.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  30.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  31.  *  All rights reserved.
  32.  * 
  33.  *  <pre>
  34.  *  Redistribution and use in source and binary forms, with or
  35.  *  without modification, are permitted provided that the
  36.  *  following conditions are met:
  37.  * 
  38.  *  * Redistributions of source code must retain the above
  39.  *    copyright notice, this list of conditions and the
  40.  *    following disclaimer.
  41.  *  * Redistributions in binary form must reproduce the above
  42.  *    copyright notice, this list of conditions and the
  43.  *    following disclaimer in the documentation and/or other
  44.  *    materials provided with the distribution.
  45.  *  * Neither the name of the Alpha Framework nor the names
  46.  *    of its contributors may be used to endorse or promote
  47.  *    products derived from this software without specific
  48.  *    prior written permission.
  49.  *   
  50.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  51.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  52.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  53.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  54.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  55.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  56.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  57.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  58.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  59.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  60.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  61.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  62.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63.  *  </pre>
  64.  *  
  65.  */
  66. class AlphaView {
  67.     /**
  68.      * The business object that will be rendered
  69.      * 
  70.      * @var AlphaDAO 
  71.      * @since 1.0
  72.      */
  73.     protected $BO;
  74.     
  75.     /**
  76.      * Trace logger
  77.      * 
  78.      * @var Logger 
  79.      * @since 1.0
  80.      */
  81.     private static $logger null;
  82.  
  83.     /**
  84.      * Constructor for the AlphaView.  As this is protected, use the AlphaView::getInstance method from a public scope.
  85.      * 
  86.      * @param AlphaDAO $BO 
  87.      * @throws IllegalArguementException
  88.      * @since 1.0
  89.      */
  90.     protected function __construct($BO{
  91.         self::$logger new Logger('AlphaView');
  92.         self::$logger->debug('>>__construct(BO=['.var_export($BOtrue).'])');
  93.         
  94.         if(AlphaDAO::checkClassDefExists(get_class($BO)))
  95.             $this->BO = $BO;
  96.         else
  97.             throw new IllegalArguementException('The BO provided ['.get_class($BO).'] is not defined anywhere!');
  98.         
  99.         self::$logger->debug('<<__construct');
  100.     }
  101.     
  102.     /**
  103.      * Static method which returns a AlphaView object or a custom child view for the BO specified
  104.      * if one exists
  105.      * 
  106.      * @param AlphaDAO $BO The main business object that this view is going to render
  107.      * @param boolean $returnParent Flag to enforce the return of this object instead of a child (defaults to false)
  108.      * @return AlphaView Returns a AlphaView object, or a child view object from the /view directory if one exists for this BO
  109.      * @since 1.0
  110.      */
  111.     public static function getInstance($BO$returnParent=false{
  112.         if(self::$logger == null)
  113.             self::$logger new Logger('AlphaView');
  114.         self::$logger->debug('>>getInstance(BO=['.var_export($BOtrue).'], returnParent=['.$returnParent.'])');
  115.         
  116.         global $config;
  117.         
  118.         $filename get_class($BO);
  119.         // remove the Object part
  120.         $filename str_replace('Object'''$filename);
  121.         // replace _ with space, then uppercase words
  122.         $filename str_replace('_'' '$filename);
  123.         $filename ucwords($filename).'View';
  124.         // finally, remove spaces
  125.         $filename str_replace(' '''$filename);        
  126.  
  127.         // Check to see if a custom view exists for this BO, and if it does return that view instead        
  128.         if (!$returnParent{
  129.             if (file_exists($config->get('sysRoot').'view/'.$filename.'.inc')) {
  130.                 require_once $config->get('sysRoot').'view/'.$filename.'.inc';
  131.  
  132.                 self::$logger->debug('<<getInstance [new '.$filename.'('.get_class($BO).')]');
  133.                 return new $filename($BO);
  134.             }elseif (file_exists($config->get('sysRoot').'alpha/view/'.$filename.'.inc')) {
  135.                 require_once $config->get('sysRoot').'alpha/view/'.$filename.'.inc';
  136.  
  137.                 self::$logger->debug('<<getInstance [new '.$filename.'('.get_class($BO).')]');
  138.                 return new $filename($BO);
  139.             }else{
  140.                 self::$logger->debug('<<getInstance [new AlphaView('.get_class($BO).', true)]');
  141.                 return new AlphaView($BOtrue);
  142.             }
  143.         }else{
  144.             self::$logger->debug('<<getInstance [new AlphaView('.get_class($BO).', true)]');
  145.             return new AlphaView($BOtrue);
  146.         }
  147.     }
  148.  
  149.     /**
  150.      * Simple setter for the view business object
  151.      * 
  152.      * @param AlphaDAO $BO 
  153.      * @throws IllegalArguementException
  154.      * @since 1.0
  155.      */
  156.     public function setBO($BO{        
  157.         self::$logger->debug('>>setBO(BO=['.var_export($BOtrue).'])');
  158.         
  159.         if(AlphaDAO::checkClassDefExists(get_class($BO)))
  160.             $this->BO = $BO;
  161.         else
  162.             throw new IllegalArguementException('The BO provided ['.get_class($BO).'] is not defined anywhere!');
  163.         
  164.         self::$logger->debug('<<setBO');
  165.     }
  166.     
  167.     /**
  168.      * Gets the BO attached to this view (if any)
  169.      * 
  170.      * @return AlphaDAO 
  171.      * @since 1.0
  172.      */
  173.     public function getBO({
  174.         return $this->BO;
  175.     }
  176.  
  177.     /**
  178.      * Renders the default create view to standard output
  179.      * 
  180.      * @param array $fields Hash array of HTML fields to pass to the template
  181.      * @since 1.0
  182.      */
  183.     public function createView($fields=array()) {        
  184.         self::$logger->debug('>>createView(fields=['.var_export($fieldstrue).'])');
  185.         
  186.         if(method_exists($this'before_createView_callback'))
  187.             $this->before_createView_callback();
  188.         
  189.         global $config;
  190.         
  191.         // the form action
  192.         $fields['formAction'$_SERVER['REQUEST_URI'];
  193.         
  194.         // the form ID
  195.         $fields['formID'get_class($this->BO).'_'.$this->BO->getOID();
  196.         
  197.         // buffer form fields to $formFields
  198.         $fields['formFields'$this->renderAllFields('create');
  199.         
  200.         // buffer HTML output for Create and Cancel buttons        
  201.         $button new Button('submit''Create''createBut');
  202.         $fields['createButton'$button->render();
  203.         
  204.         $button new Button("document.location.replace('".FrontController::generateSecureURL('act=ListBusinessObjects')."')"'Cancel''cancelBut');
  205.         $fields['cancelButton'$button->render();        
  206.         
  207.         // buffer security fields to $formSecurityFields variable        
  208.         $fields['formSecurityFields'$this->renderSecurityFields();        
  209.  
  210.         $this->loadTemplate($this->BO'create'$fields);
  211.         
  212.         if(method_exists($this'after_createView_callback'))
  213.             $this->after_createView_callback();
  214.             
  215.         self::$logger->debug('<<createView');
  216.     }
  217.  
  218.     /**
  219.      * Renders a form to enable object editing to standard output
  220.      * 
  221.      * @param array $fields Hash array of HTML fields to pass to the template
  222.      * @since 1.0
  223.      */
  224.     public function editView($fields=array()) {
  225.         self::$logger->debug('>>editView(fields=['.var_export($fieldstrue).'])');
  226.         
  227.         if(method_exists($this'before_editView_callback'))
  228.             $this->before_editView_callback();
  229.         
  230.         global $config;
  231.  
  232.         // the form action
  233.         $fields['formAction'$_SERVER['REQUEST_URI'];
  234.         
  235.         // the form ID
  236.         $fields['formID'get_class($this->BO).'_'.$this->BO->getOID();
  237.         
  238.         // buffer form fields to $formFields
  239.         $fields['formFields'$this->renderAllFields('edit');
  240.         
  241.         // buffer HTML output for Create and Cancel buttons        
  242.         $button new Button('submit''Save''saveBut');
  243.         $fields['saveButton'$button->render();
  244.         
  245.         $js "$('#dialogDiv').text('Are you sure you wish to delete this item?');
  246.                 $('#dialogDiv').dialog({
  247.                 buttons: {
  248.                     'OK': function(event, ui) {                        
  249.                         $('#deleteOID').attr('value', '".$this->BO->getOID()."');
  250.                         $('#deleteForm').submit();
  251.                     },
  252.                     'Cancel': function(event, ui) {
  253.                         $(this).dialog('close');
  254.                     }
  255.                 }
  256.             })
  257.             $('#dialogDiv').dialog('open');
  258.             return false;";
  259.         $button new Button($js"Delete""deleteBut");
  260.         $fields['deleteButton'$button->render();
  261.         
  262.         $button new Button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'""Back to List""cancelBut");
  263.         $fields['cancelButton'$button->render();        
  264.                 
  265.         // buffer security fields to $formSecurityFields variable        
  266.         $fields['formSecurityFields'$this->renderSecurityFields();
  267.  
  268.         // OID will need to be posted for optimistic lock checking
  269.         $fields['version_num'$this->BO->getVersionNumber();
  270.  
  271.         $this->loadTemplate($this->BO'edit'$fields);
  272.         
  273.         if(method_exists($this'after_editView_callback'))
  274.             $this->after_editView_callback();
  275.             
  276.         self::$logger->debug('<<editView');
  277.     }
  278.  
  279.     /**
  280.      * Renders the list view to standard output
  281.      * 
  282.      * @param array $fields Hash array of HTML fields to pass to the template
  283.      * @since 1.0
  284.      */
  285.     public function listView($fields=array()) {
  286.         self::$logger->debug('>>listView(fields=['.var_export($fieldstrue).'])');
  287.         
  288.         if(method_exists($this'before_listView_callback'))
  289.             $this->before_listView_callback();
  290.         
  291.         global $config;
  292.         
  293.         // the form action
  294.         $fields['formAction'$_SERVER['REQUEST_URI'];
  295.         
  296.         // work out how many columns will be in the table
  297.         $reflection new ReflectionClass(get_class($this->BO));
  298.         $properties array_keys($reflection->getDefaultProperties());        
  299.         $fields['colCount'1+count(array_diff($properties$this->BO->getDefaultAttributes()$this->BO->getTransientAttributes()));
  300.         
  301.         // get the class attributes
  302.         $properties $reflection->getProperties();
  303.         
  304.         $html '';
  305.         
  306.         $html .= '<tr>';
  307.         foreach($properties as $propObj{
  308.             $propName $propObj->name;
  309.             
  310.             // skip over password fields
  311.             $property $this->BO->getPropObject($propName);
  312.             if(!($property instanceof String && $property->checkIsPassword())) {            
  313.                 if (!in_array($propName$this->BO->getDefaultAttributes()) && !in_array($propName$this->BO->getTransientAttributes())) {
  314.                     $html .= '    <th>'.$this->BO->getDataLabel($propName).'</th>';                
  315.                 }
  316.                 if ($propName == 'OID')
  317.                     $html .= '    <th>'.$this->BO->getDataLabel($propName).'</th>';
  318.             }else{
  319.                 $fields['colCount'$fields['colCount']-1;
  320.             }
  321.         }
  322.         $html .= '</tr><tr>';
  323.         
  324.         $fields['formHeadings'$html;
  325.         
  326.         $html '';
  327.  
  328.         // and now the values
  329.         foreach($properties as $propObj{
  330.             $propName $propObj->name;
  331.             
  332.             $property $this->BO->getPropObject($propName);
  333.             if(!($property instanceof String && $property->checkIsPassword())) {
  334.                 if (!in_array($propName$this->BO->getDefaultAttributes()) && !in_array($propName$this->BO->getTransientAttributes())) {
  335.                     $propClass get_class($this->BO->getPropObject($propName));
  336.                     
  337.                     if ($propClass == 'Text'{
  338.                         $text htmlentities($this->BO->get($propName));
  339.                         if(strlen($text70)
  340.                             $html .= '    <td>&nbsp;'.substr($text070).'...</td>';
  341.                         else
  342.                             $html .= '    <td>&nbsp;'.$text.'</td>';
  343.                     }elseif($propClass == 'DEnum'{
  344.                         $html .= '    <td>&nbsp;'.$this->BO->getPropObject($propName)->getDisplayValue().'</td>';
  345.                     }else{
  346.                         $html .= '    <td>&nbsp;'.$this->BO->get($propName).'</td>';
  347.                     }
  348.                 }
  349.                 if ($propName == 'OID')
  350.                     $html .= '    <td>&nbsp;'.$this->BO->getOID().'</td>';
  351.             }
  352.         }
  353.         $html .= '</tr>';
  354.         
  355.         $fields['formFields'$html;
  356.         
  357.         // View button
  358.         if(strpos($_SERVER['REQUEST_URI']'/tk/'!== false{
  359.             $button new Button("document.location = '".FrontController::generateSecureURL('act=Detail&bo='.get_class($this->BO).'&oid='.$this->BO->getOID())."';"'View''view'.$this->BO->getOID().'But');
  360.             $fields['viewButton'$button->render();
  361.         }else{
  362.             if($this->BO->hasAttribute('URL'))
  363.                 $button new Button("document.location = '".$this->BO->get('URL')."';"'View''view'.$this->BO->getOID().'But');
  364.             else
  365.                 $button new Button("document.location = '".$config->get('sysURL')."Detail/bo/".get_class($this->BO)."/oid/".$this->BO->getOID()."';"'View''view'.$this->BO->getOID().'But');
  366.             
  367.             $fields['viewButton'$button->render();
  368.         }
  369.  
  370.         $html '';
  371.         // render edit and delete buttons for admins only
  372.         if (isset($_SESSION['currentUser']&& $_SESSION['currentUser']->inGroup('Admin')) {
  373.             $html .= '&nbsp;&nbsp;';
  374.             $button new Button("document.location = '".FrontController::generateSecureURL('act=Edit&bo='.get_class($this->BO)."&oid=".$this->BO->getOID())."'""Edit""edit".$this->BO->getOID()."But");
  375.             $html .= $button->render();
  376.             $html .= '&nbsp;&nbsp;';
  377.             $js "$('#dialogDiv').text('Are you sure you wish to delete this item?');
  378.                 $('#dialogDiv').dialog({
  379.                 buttons: {
  380.                     'OK': function(event, ui) {                        
  381.                         $('#deleteOID').attr('value', '".$this->BO->getOID()."');
  382.                         $('#deleteForm').submit();
  383.                     },
  384.                     'Cancel': function(event, ui) {
  385.                         $(this).dialog('close');
  386.                     }
  387.                 }
  388.             })
  389.             $('#dialogDiv').dialog('open');
  390.             return false;";
  391.             $button new Button($js"Delete""delete".$this->BO->getOID()."But");
  392.             $html .= $button->render();
  393.         }
  394.         $fields['adminButtons'$html;
  395.  
  396.         // buffer security fields to $formSecurityFields variable
  397.         $fields['formSecurityFields'$this->renderSecurityFields();
  398.  
  399.         $this->loadTemplate($this->BO'list'$fields);
  400.         
  401.         if(method_exists($this'after_listView_callback'))
  402.             $this->after_listView_callback();
  403.             
  404.         self::$logger->debug('<<listView');
  405.     }
  406.  
  407.     /**
  408.      * Displays a detailed view of the object (read-only) to standard output
  409.      * 
  410.      * @param array $fields Hash array of HTML fields to pass to the template
  411.      * @since 1.0
  412.      */
  413.     public function detailedView($fields=array()) {
  414.         self::$logger->debug('>>detailedView(fields=['.var_export($fieldstrue).'])');
  415.         
  416.         if(method_exists($this'before_detailedView_callback'))
  417.             $this->before_detailedView_callback();
  418.         
  419.         global $config;
  420.         
  421.         // we may want to display the OID regardless of class
  422.         $fields['OIDLabel'$this->BO->getDataLabel('OID');        
  423.         $fields['OID'$this->BO->getOID();        
  424.         
  425.         // buffer form fields to $formFields
  426.         $fields['formFields'$this->renderAllFields('view');
  427.         
  428.         // Back button
  429.         $button new Button('history.back()''Back''backBut');
  430.         $fields['backButton'$button->render();
  431.         
  432.         $html '';
  433.         // render edit and delete buttons for admins only
  434.         if (isset($_SESSION['currentUser']&& $_SESSION['currentUser']->inGroup('Admin')) {
  435.             $html .= '&nbsp;&nbsp;';
  436.             $button new Button("document.location = '".FrontController::generateSecureURL('act=Edit&bo='.get_class($this->BO)."&oid=".$this->BO->getOID())."'""Edit""editBut");
  437.             $html .= $button->render();
  438.             $html .= '&nbsp;&nbsp;';
  439.             $js "$('#dialogDiv').text('Are you sure you wish to delete this item?');
  440.                 $('#dialogDiv').dialog({
  441.                 buttons: {
  442.                     'OK': function(event, ui) {                        
  443.                         $('#deleteOID').attr('value', '".$this->BO->getOID()."');
  444.                         $('#deleteForm').submit();
  445.                     },
  446.                     'Cancel': function(event, ui) {
  447.                         $(this).dialog('close');
  448.                     }
  449.                 }
  450.             })
  451.             $('#dialogDiv').dialog('open');
  452.             return false;";
  453.             $button new Button($js"Delete""deleteBut");
  454.             $html .= $button->render();
  455.         }
  456.         $fields['adminButtons'$html;
  457.         
  458.         $this->loadTemplate($this->BO'detail'$fields);
  459.         
  460.         if(method_exists($this'after_detailedView_callback'))
  461.             $this->after_detailedView_callback();
  462.             
  463.         self::$logger->debug('<<detailedView');
  464.     }
  465.  
  466.     /**
  467.      * Renders the admin view for the business object screen to standard output
  468.      * 
  469.      * @param array $fields Hash array of HTML fields to pass to the template
  470.      * @since 1.0
  471.      */
  472.     public function adminView($fields=array()) {
  473.         self::$logger->debug('>>adminView(fields=['.var_export($fieldstrue).'])');
  474.         
  475.         if(method_exists($this'before_adminView_callback'))
  476.             $this->before_adminView_callback();
  477.         
  478.         global $config;
  479.         
  480.         // the form action
  481.         $fields['formAction'$_SERVER['REQUEST_URI'];
  482.         
  483.         // the class name of the BO
  484.         $fields['className'get_class($this->BO);
  485.         
  486.         // the table name in the DB for the BO
  487.         $fields['tableName'$this->BO->getTableName();
  488.         
  489.         // record count for the BO in the DB
  490.         $fields['count'($this->BO->checkTableExists($this->BO->getCount('<span class="warning">unavailable</span>');
  491.  
  492.         // table exists in the DB?
  493.         $fields['tableExists'($this->BO->checkTableExists('<span class="success">Yes</span>' '<span class="warning">No</span>');
  494.         
  495.         // table schema needs to be updated in the DB?
  496.         $fields['tableNeedsUpdate'($this->BO->checkTableNeedsUpdate('<span class="warning">Yes</span>' '<span class="success">No</span>');
  497.  
  498.         // create button
  499.         if($this->BO->checkTableExists()) {
  500.             $button new Button("document.location = '".FrontController::generateSecureURL('act=Create&bo='.get_class($this->BO))."'""Create New""create".get_class($this->BO)."But");
  501.             $fields['createButton'$button->render();
  502.         }else{
  503.             $fields['createButton''';
  504.         }
  505.         
  506.         // list all button
  507.         if($this->BO->checkTableExists()) {
  508.             $button new Button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'""List All""list".get_class($this->BO)."But");
  509.             $fields['listButton'$button->render();
  510.         }else{
  511.             $fields['listButton''';
  512.         }
  513.         
  514.         // the create table button (if required)
  515.         $html '';
  516.         if (!$this->BO->checkTableExists()) {            
  517.             $button new Button("submit""Create Table""createTableBut");
  518.             $html .= $button->render();
  519.             // hidden field so that we know which class to create the table for
  520.             $html .= '<input type="hidden" name="createTableClass" value="'.get_class($this->BO).'"/>';
  521.         }
  522.         $fields['createTableButton'$html;
  523.         
  524.         // recreate and update table buttons (if required)
  525.         $html '';
  526.         if ($this->BO->checkTableNeedsUpdate(&& $this->BO->checkTableExists()) {            
  527.             $js "$('#dialogDiv').text('Are you sure you wish to recreate this class table (all data will be lost)?');
  528.                 $('#dialogDiv').dialog({
  529.                 buttons: {
  530.                     'OK': function(event, ui) {
  531.                         $('#admin_".get_class($this->BO)."_button_pressed').attr('value', 'recreateTableBut');
  532.                         $('#admin_".get_class($this->BO)."').submit();
  533.                     },
  534.                     'Cancel': function(event, ui) {
  535.                         $(this).dialog('close');
  536.                     }
  537.                 }
  538.             })
  539.             $('#dialogDiv').dialog('open');
  540.             return false;";
  541.             $button new Button($js "Recreate Table""recreateTableBut");
  542.             $html .= $button->render();
  543.             // hidden field so that we know which class to recreate the table for
  544.             $html .= '<input type="hidden" name="recreateTableClass" value="'.get_class($this->BO).'"/>';
  545.             $html .= '&nbsp;&nbsp;';
  546.             $js "$('#dialogDiv').text('Are you sure you wish to attempt to modify this class table by adding new attributes?');
  547.                 $('#dialogDiv').dialog({
  548.                 buttons: {
  549.                     'OK': function(event, ui) {
  550.                         $('#admin_".get_class($this->BO)."_button_pressed').attr('value', 'updateTableBut');
  551.                         $('#admin_".get_class($this->BO)."').submit();
  552.                     },
  553.                     'Cancel': function(event, ui) {
  554.                         $(this).dialog('close');
  555.                     }
  556.                 }
  557.             })
  558.             $('#dialogDiv').dialog('open');
  559.             return false;";
  560.             $button new Button($js "Update Table""updateTableBut");
  561.             $html .= $button->render();
  562.             // hidden field so that we know which class to update the table for
  563.             $html .= '<input type="hidden" name="updateTableClass" value="'.get_class($this->BO).'"/>';
  564.             // hidden field to tell us which button was pressed
  565.             $html .= '<input type="hidden" id="admin_'.get_class($this->BO).'_button_pressed" name="admin_'.get_class($this->BO).'_button_pressed" value=""/>';
  566.         }
  567.         $fields['recreateOrUpdateButtons'$html;
  568.         
  569.         // buffer security fields to $formSecurityFields variable
  570.         $fields['formSecurityFields'$this->renderSecurityFields();
  571.         
  572.         $this->loadTemplate($this->BO'admin'$fields);
  573.         
  574.         if(method_exists($this'after_adminView_callback'))
  575.             $this->after_adminView_callback();
  576.             
  577.         self::$logger->debug('<<adminView');
  578.     }
  579.     
  580.     /**
  581.      * Method to render the page header HTML content
  582.      * 
  583.      * @param AlphaController $controller 
  584.      * @param bool $renderMenu Set to false to hide the default menu (default value is true)
  585.      * @param bool $renderStatus Set to false to hide the status message from the session (if any, default value is true)
  586.      * @return string 
  587.      * @throws IllegalArguementException
  588.      * @since 1.0
  589.      */
  590.     public static function displayPageHead($controller$renderMenu true$renderStatus true{
  591.         if(self::$logger == null)
  592.             self::$logger new Logger('AlphaView');
  593.         self::$logger->debug('>>displayPageHead(controller=['.var_export($controllertrue).'], renderMenu=['.$renderMenu.'], renderStatus=['.$renderStatus.'])');
  594.         
  595.         if(method_exists($controller'before_displayPageHead_callback'))
  596.             $controller->before_displayPageHead_callback();
  597.         
  598.         global $config;
  599.         
  600.         if(!AlphaController::checkControllerDefExists(get_class($controller)))
  601.             throw new IllegalArguementException('The controller provided ['.get_class($controller).'] is not defined anywhere!');
  602.         
  603.         $html '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
  604.         
  605.         $html.= '<html>';
  606.         $html.= '<head>';
  607.         $html.= '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
  608.         $html.= '<title>'.$controller->getTitle().'</title>';
  609.         if($controller->getKeywords(!= '')
  610.             $html.= '<meta name="Keywords" content="'.$controller->getKeywords().'">';
  611.         if($controller->getDescription(!= '')
  612.             $html.= '<meta name="Description" content="'.$controller->getDescription().'">';
  613.         $html.= '<meta name="title" content="'.$controller->getTitle().'">';
  614.         $html.= '<meta name="robots" content="index,follow,NOODP">';
  615.         if ($controller->getBO(!= null && $controller->getBO()->hasAttribute('URL')) {
  616.             $URL $controller->getBO()->get('URL');
  617.             if($URL != '')
  618.                 $html.= '<link rel="canonical" href="'.$URL.'" />';
  619.         }
  620.         $html.= '<meta http-equiv="imagetoolbar" content="no">';
  621.  
  622.         $html.= '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'alpha/lib/jquery/ui/themes/'.$config->get('sysTheme').'/jquery.ui.all.css">';
  623.         $html.= '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'alpha/css/alpha.css">';
  624.         $html.= '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'config/css/overrides.css">';
  625.         
  626.         $html.= '<script type="text/javascript" src="'.$config->get('sysURL').'alpha/lib/jquery/jquery-1.5.1.min.js"></script>';
  627.         $html.= '<script type="text/javascript" src="'.$config->get('sysURL').'alpha/scripts/validation.js"></script>';
  628.         $html.= '<script type="text/javascript" src="'.$config->get('sysURL').'alpha/lib/jquery/contextMenu/jquery.contextMenu.js"></script>';
  629.         
  630.         $html.= '<script type="text/javascript" src="'.$config->get('sysURL').'alpha/lib/jquery/ui/jquery.ui.potato.menu.js"></script>';
  631.         
  632.         $html.= '<script type="text/javascript" src="'.$config->get('sysURL').'alpha/lib/jquery/ui/jquery-ui-1.8.11.custom.min.js"></script>';
  633.         
  634.         // handle force-frames
  635.         if($config->get('sysForceFrame')) {
  636.             // if no-forceframe=true or we are in the admin backend, don't force frame
  637.             if(!isset($_GET['no-forceframe']&& strpos($_SERVER['REQUEST_URI']'/tk/'=== false{
  638.                 $html.= '<script type="text/javascript">';
  639.                 $html.= 'pageLoc = self.location;';
  640.                 $html.= 'pageAdd = top.location;';
  641.          
  642.                 $html.= 'if (pageLoc == pageAdd) {';
  643.                 $html.= '    contentSrc = escape(pageLoc);';
  644.                 $html.= '    contPage = \''.$config->get('sysURL').'?\' + contentSrc;';
  645.                 $html.= '    top.location.href = contPage;';
  646.                 $html.= '}';
  647.                 $html.= '</script>';
  648.             }
  649.         }
  650.         
  651.         if (isset($_SESSION['currentUser']&& AlphaDAO::isInstalled(&& $_SESSION['currentUser']->inGroup('Admin'&& strpos($_SERVER['REQUEST_URI']'/tk/'!== false{
  652.             $html.= '<script type="text/javascript">';
  653.             $html.= '    (function($) {';
  654.             $html.= '        $(document).ready(function(){';
  655.             $html.= '        $("#adminmenu").ptMenu();';
  656.             $html.= '    });';
  657.             $html.= '})(jQuery);';
  658.             $html.= '</script>';
  659.         }
  660.         
  661.         // general dialog defaults
  662.         $html.= '<script type="text/javascript">';
  663.         $html.= '    (function($) {';
  664.         $html.= '        var dialogCoords = [(screen.width/2)-200, (screen.height/2)-200];';
  665.         $html.= '        $(document).ready(function(){';
  666.         $html.= '            $.extend($.ui.dialog.prototype.options, {';
  667.         $html.= '                modal: true,';
  668.         $html.= '                resizable: false,';
  669.         $html.= '                draggable: false,';
  670.         $html.= '                autoOpen: false,';
  671.         $html.= '                height: 200,';
  672.         $html.= '                width: 400,';
  673.         $html.= '                position: dialogCoords,';
  674.         $html.= '                buttons: {';
  675.         $html.= '                    "Cancel": function() {';
  676.         $html.= '                        $(this).dialog("close");';
  677.         $html.= '                    }';
  678.         $html.= '                }';
  679.         $html.= '            });';
  680.         $html.= '        });';
  681.         $html.= '    })(jQuery);';
  682.         $html.= '</script>';
  683.         
  684.         // record selector JS
  685.         $html.= '<script type="text/javascript">';
  686.         $html.= '    (function($) {';
  687.         $html.= '        $(document).ready(function(){';
  688.         $html.= '            var dialogOpts = {';
  689.         $html.= '                title: "Record selector",';
  690.         $html.= '                modal: true,';
  691.         $html.= '                resizable: false,';
  692.         $html.= '                draggable: false,';
  693.         $html.= '                autoOpen: false,';
  694.         $html.= '                height: 300,';
  695.         $html.= '                width: 600';
  696.         $html.= '            };';
  697.         $html.= '            $("#recordSelector").dialog(dialogOpts);';
  698.         $html.= '        });';
  699.         $html.= '    })(jQuery);';
  700.         $html.= '</script>';
  701.         
  702.         if(method_exists($controller'during_displayPageHead_callback'))
  703.             $html.= $controller->during_displayPageHead_callback();
  704.  
  705.         $html.= '</head>';
  706.         try {
  707.             if($controller->getBO(!= null)
  708.                 $html.= '<body'.($controller->getBO()->get('bodyOnload'!= '' ' onload="'.$controller->getBO()->get('bodyOnload').'"' '').'>';
  709.             else
  710.                 $html.= '<body>';
  711.         catch (AlphaException $e{
  712.             $html.= '<body>';
  713.         }
  714.         
  715.         if(method_exists($controller'insert_CMSDisplayStandardHeader_callback'))
  716.             $html.= $controller->insert_CMSDisplayStandardHeader_callback();
  717.         
  718.         $html .= '<div id="recordSelector"></div>';
  719.             
  720.         if($controller->getTitle(!= '')
  721.             $html.= '<h1>'.$controller->getTitle().'</h1>';
  722.         
  723.         if ($renderMenu && isset($_SESSION['currentUser']&& AlphaDAO::isInstalled(&& $_SESSION['currentUser']->inGroup('Admin'&& strpos($_SERVER['REQUEST_URI']'/tk/'!== false{
  724.             $html .= '<ul id="adminmenu" class="potato-menu">
  725.                         <li><a href="'.$config->get('sysURL').'">Home</a></li>
  726.                         <li><a href="'.FrontController::generateSecureURL('act=ListBusinessObjects').'">Admin Home</a></li>
  727.                         <li><a href="#">Logs &raquo;</a>            
  728.                             <ul>
  729.                                 <li><a href="'.FrontController::generateSecureURL('act=ViewLog&logPath='.$config->get('sysLogFile')).'">System Log</a></li>
  730.                                 <li><a href="'.FrontController::generateSecureURL('act=ViewLog&logPath='.$config->get('sysRoot').'logs/search.log').'">Search Log</a></li>
  731.                                 <li><a href="'.FrontController::generateSecureURL('act=ViewLog&logPath='.$config->get('sysRoot').'logs/feeds.log').'">Feed Log</a></li>
  732.                                 <li><a href="'.FrontController::generateSecureURL('act=ViewLog&logPath='.$config->get('sysRoot').'logs/tasks.log').'">Cron Tasks Log</a></li>
  733.                             </ul>
  734.                         </li>
  735.                         <li><a href="'.FrontController::generateSecureURL('act=GenSecureQueryStrings').'">Generate Secure URL</a></li>
  736.                         <li><a href="'.FrontController::generateSecureURL('act=ViewMetrics').'">Software Metrics</a></li>
  737.                         <li><a href="'.FrontController::generateSecureURL('act=CacheManager').'">Manage Cache</a></li>
  738.                         <li><a href="'.FrontController::generateSecureURL('act=TagManager').'">Manage Tags</a></li>
  739.                         <li><a href="'.FrontController::generateSecureURL('act=ListDEnums').'">Manage DEnums</a></li>
  740.                         <li><a href="'.FrontController::generateSecureURL('act=ListSequences').'">Manage Sequences</a></li>
  741.                         <li><a href="'.FrontController::generateSecureURL('act=ViewTestResults').'">Unit Tests</a></li>
  742.                     </ul>';
  743.         }
  744.         
  745.         if(method_exists($controller'after_displayPageHead_callback'))
  746.             $html.= $controller->after_displayPageHead_callback();
  747.  
  748.         if($renderStatus{
  749.             // render a status message if there is any
  750.             $message $controller->getStatusMessage();
  751.             if(!empty($message))
  752.                 $html .= $message;
  753.         }
  754.             
  755.         self::$logger->debug('<<displayPageHead ['.$html.']');
  756.         return $html;
  757.     }
  758.     
  759.     /**
  760.      * Method to render the page footer HTML
  761.      * 
  762.      * @param AlphaController $controller 
  763.      * @return string 
  764.      * @since 1.0
  765.      */
  766.     public static function displayPageFoot($controller{
  767.         if(self::$logger == null)        
  768.             self::$logger new Logger('AlphaView');
  769.         
  770.         self::$logger->debug('>>displayPageFoot(controller=['.get_class($controller).'])');
  771.         $html '';
  772.         
  773.         if(method_exists($controller'before_displayPageFoot_callback'))
  774.             $html .= $controller->before_displayPageFoot_callback();
  775.         
  776.         $html .= '<div id="dialogDiv"></div>';
  777.         $html .= '</body>';
  778.         $html .= '</html>';
  779.         
  780.         if(method_exists($controller'after_displayPageFoot_callback'))
  781.             $this->after_displayPageFoot_callback();
  782.             
  783.         self::$logger->debug('<<displayPageFoot ['.$html.']');
  784.         return $html;
  785.     }
  786.     
  787.     /**
  788.      * Renders the HTML for an update (e.g. successful save) message
  789.      * 
  790.      * @param string $message 
  791.      * @return string 
  792.      * @since 1.0
  793.      */
  794.     public static function displayUpdateMessage($message{
  795.         if(self::$logger == null)
  796.             self::$logger new Logger('AlphaView');
  797.         self::$logger->debug('>>displayUpdateMessage(message=['.$message.'])');
  798.         
  799.         $html '<div class="ui-state-highlight ui-corner-all" style="padding: 0pt 0.7em;"> 
  800.                 <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: 0.3em;"></span> 
  801.                 <strong>Update:</strong> '.$message.'</p></div>';
  802.         
  803.         self::$logger->debug('<<displayUpdateMessage ['.$html.']');
  804.         return $html;
  805.     }
  806.     
  807.     /**
  808.      * Renders the HTML for an error (e.g. save failed) message
  809.      * 
  810.      * @param string $message 
  811.      * @return string 
  812.      * @since 1.0
  813.      */
  814.     public static function displayErrorMessage($message{
  815.         if(self::$logger == null)
  816.             self::$logger new Logger('AlphaView');
  817.         self::$logger->debug('>>displayErrorMessage(message=['.$message.'])');
  818.         
  819.         $html '<div class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em;"> 
  820.                 <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span> 
  821.                 <strong>Error:</strong> '.$message.'</p></div>';
  822.         
  823.         self::$logger->debug('<<displayErrorMessage ['.$html.']');
  824.         return $html;
  825.     }
  826.     
  827.     /**
  828.      * Renders a HTML error page with the supplied error code (typlically a HTTP code) and a message
  829.      * 
  830.      * @param string $code 
  831.      * @param string $message 
  832.      * @return string 
  833.      * @since 1.0
  834.      */
  835.     public static function renderErrorPage($code$message{
  836.         global $config;        
  837.         
  838.         $html '<html><head>';
  839.         $html .= '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'alpha/lib/jquery/ui/themes/'.$config->get('sysTheme').'/jquery.ui.all.css">';
  840.         $html .= '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'alpha/css/alpha.css">';
  841.         $html .= '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'config/css/overrides.css">';
  842.         $html .= '<title>'.$code.' - '.$message.'</title></head>';
  843.         $html .= '<body>';
  844.         $html .= '<div class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em;"> 
  845.                 <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span> 
  846.                 <strong>'.$code.':</strong> '.$message.'</p>
  847.                 </div>';
  848.         $html .= '</body></html>';
  849.         
  850.         return $html;
  851.     }
  852.     
  853.     /**
  854.      * Method to render a hidden form for posting the OID of an object to be deleted
  855.      * 
  856.      * @return string 
  857.      * @since 1.0
  858.      */
  859.     public static function renderDeleteForm({
  860.         if(self::$logger == null)
  861.             self::$logger new Logger('AlphaView');
  862.         self::$logger->debug('>>renderDeleteForm()');
  863.         
  864.         $html '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST" id="deleteForm">';        
  865.         $html .= '<input type="hidden" name="deleteOID" id="deleteOID" value=""/>';
  866.         $html .= self::renderSecurityFields();
  867.         $html .= '</form>';
  868.         
  869.         self::$logger->debug('<<renderDeleteForm ['.$html.']');
  870.         return $html;
  871.     }
  872.     
  873.     /**
  874.      * Method to render a HTML form with two hidden, hashed (MD5) form fields to be used as
  875.      * a check to ensure that a post to the controller is being sent from the same server
  876.      * as hosting it.
  877.      * 
  878.      * @return string 
  879.      * @since 1.0
  880.      */
  881.     public static function renderSecurityFields({
  882.         if(self::$logger == null)
  883.             self::$logger new Logger('AlphaView');
  884.         self::$logger->debug('>>renderSecurityFields()');
  885.         
  886.         $html '';
  887.         
  888.         $fields AlphaController::generateSecurityFields();
  889.         
  890.         $html .= '<input type="hidden" name="var1" value="'.$fields[0].'"/>';
  891.         $html .= '<input type="hidden" name="var2" value="'.$fields[1].'"/>';
  892.         
  893.         self::$logger->debug('<<renderSecurityFields ['.$html.']');
  894.         return $html;
  895.     }
  896.     
  897.     /**
  898.      * Method to render the default Integer HTML
  899.      *
  900.      * @param string $name The field name
  901.      * @param string $label The label to apply to the field
  902.      * @param string $mode The field mode (create/edit/view)
  903.      * @param string $value The field value (optional)
  904.      * @param bool $tableTags Include table tags and label (optional)
  905.      * @return string 
  906.      * @since 1.0
  907.      */
  908.     public function renderIntegerField($name$label$mode$value=''$tableTags=true{
  909.         self::$logger->debug('>>renderIntegerField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  910.         
  911.         $html '';
  912.         
  913.         if ($mode == 'create'{
  914.             if($tableTags{
  915.                 $html .= '<tr><th style="width:25%;">';
  916.                 $html .= $label;
  917.                 $html .= '</th>';
  918.         
  919.                 $html .= '<td>';
  920.                 $html .= '<input type="text" style="width:100%;" name="'.$name.'" value="'(isset ($_POST[$name]$_POST[$name'').'"/><br>';
  921.                 $html .= '</td></tr>';
  922.             }else{
  923.                 $html .= '<input type="text" style="width:100%;" name="'.$name.'" value="'(isset ($_POST[$name]$_POST[$name'').'"/><br>';
  924.             }
  925.         }
  926.         
  927.         if ($mode == 'edit'{
  928.             if($tableTags{
  929.                 $html .= '<tr><th style="width:25%;">';
  930.                 $html .= $label;
  931.                 $html .= '</th>';
  932.     
  933.                 $html .= '<td>';
  934.                 $html .= '<input type="text" style="width:100%;" name="'.$name.'" value="'.$value.'"/><br>';
  935.                 $html .= '</td></tr>';
  936.             }else{
  937.                 $html .= '<input type="text" style="width:100%;" name="'.$name.'" value="'.$value.'"/>';
  938.             }
  939.         }
  940.                 
  941.         self::$logger->debug('<<renderIntegerField ['.$html.']');
  942.         return $html;
  943.     }
  944.     
  945.     /**
  946.      * Method to render the default Double HTML
  947.      *
  948.      * @param string $name The field name
  949.      * @param string $label The label to apply to the field
  950.      * @param string $mode The field mode (create/edit/view)
  951.      * @param string $value The field value (optional)
  952.      * @param bool $tableTags Include table tags and label (optional)
  953.      * @return string 
  954.      * @since 1.0
  955.      */
  956.     public static function renderDoubleField($name$label$mode$value=''$tableTags=true{
  957.         self::$logger->debug('>>renderDoubleField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  958.         
  959.         $html '';
  960.         
  961.         if ($mode == 'create'{
  962.             if($tableTags{
  963.                 $html .= '<tr><th style="width:25%;">';
  964.                 $html .= $label;
  965.                 $html .= '</th>';
  966.         
  967.                 $html .= '<td>';
  968.                 $html .= '<input type="text" size="13" name="'.$name.'" value="'(isset ($_POST[$name]$_POST[$name'').'"/><br>';
  969.                 $html .= '</td></tr>';
  970.             }else{
  971.                 $html .= '<input type="text" size="13" name="'.$name.'" value="'(isset ($_POST[$name]$_POST[$name'').'"/>';
  972.             }
  973.         }
  974.         
  975.         if ($mode == 'edit'{
  976.             if($tableTags{
  977.                 $html .= '<tr><th style="width:25%;">';
  978.                 $html .= $label;
  979.                 $html .= '</th>';
  980.     
  981.                 $html .= '<td>';
  982.                 $html .= '<input type="text" size="13" name="'.$name.'" value="'.$value.'"/><br>';
  983.                 $html .= '</td></tr>';
  984.             }else{
  985.                 $html .= '<input type="text" size="13" name="'.$name.'" value="'.$value.'"/>';
  986.             }
  987.         }
  988.                 
  989.         self::$logger->debug('<<renderDoubleField ['.$html.']');
  990.         return $html;
  991.     }
  992.     
  993.     /**
  994.      * Method to render the default Boolean HTML
  995.      *
  996.      * @param string $name The field name
  997.      * @param string $label The label to apply to the field
  998.      * @param string $mode The field mode (create/edit/view)
  999.      * @param string $value The field value (optional)
  1000.      * @param bool $tableTags Include table tags and label (optional)
  1001.      * @return string 
  1002.      * @since 1.0
  1003.      */
  1004.     public function renderBooleanField($name$label$mode$value=''$tableTags=true{
  1005.         self::$logger->debug('>>renderBooleanField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  1006.         
  1007.         $html '';
  1008.         
  1009.         if ($mode == 'create'{
  1010.             if($tableTags{
  1011.                 $html .= '<tr><th style="width:25%;">';
  1012.                 $html .= $label;
  1013.                 $html .= '</th>';
  1014.         
  1015.                 $html .= '<td>';
  1016.                 $html .= '<select size="1" name="'.$name.'"/>';
  1017.                 $html .= '<option value="0" selected>N</option>';
  1018.                 $html .= '<option value="1">Y</option>';
  1019.                 $html .= '</select><br>';
  1020.                 $html .= '</td></tr>';
  1021.             }else{
  1022.                 $html .= '<select size="1" name="'.$name.'"/>';
  1023.                 $html .= '<option value="0" selected>N</option>';
  1024.                 $html .= '<option value="1">Y</option>';
  1025.                 $html .= '</select>';
  1026.             }
  1027.         }
  1028.         
  1029.         if ($mode == 'edit'{
  1030.             if($tableTags{
  1031.                 $html .= '<tr><th>';
  1032.                 $html .= $label;
  1033.                 $html .= '</th>';
  1034.     
  1035.                 $html .= '<td>';
  1036.                 $html .= '<select size="1" name="'.$name.'"/>';
  1037.                 $html .= '<option value="0" '.($value == '0''selected':'').'>N</option>';
  1038.                 $html .= '<option value="1" '.($value == '1''selected':'').'>Y</option>';
  1039.                 $html .= '</select><br>';
  1040.                 $html .= '</td></tr>';
  1041.             }else{
  1042.                 $html .= '<select size="1" name="'.$name.'"/>';
  1043.                 $html .= '<option value="0" '.($value == '0''selected':'').'>N</option>';
  1044.                 $html .= '<option value="1" '.($value == '1''selected':'').'>Y</option>';
  1045.                 $html .= '</select>';
  1046.             }
  1047.         }
  1048.                 
  1049.         self::$logger->debug('<<renderBooleanField ['.$html.']');
  1050.         return $html;
  1051.     }
  1052.     
  1053.     /**
  1054.      * Method to render the default Enum HTML
  1055.      *
  1056.      * @param string $name The field name
  1057.      * @param string $label The label to apply to the field
  1058.      * @param string $mode The field mode (create/edit/view)
  1059.      * @param array $options The Enum options
  1060.      * @param string $value The field value (optional)
  1061.      * @param bool $tableTags Include table tags and label (optional)
  1062.      * @return string 
  1063.      * @since 1.0
  1064.      */
  1065.     public static function renderEnumField($name$label$mode$options$value=''$tableTags=true{
  1066.         self::$logger->debug('>>renderEnumField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  1067.         
  1068.         $html '';
  1069.         
  1070.         if ($mode == 'create'{
  1071.             if ($tableTags{
  1072.                 $html .= '<tr><th style="width:25%;">';
  1073.                 $html .= $label;
  1074.                 $html .= '</th>';
  1075.                 $html .= '<td>';
  1076.                 $html .= '<select name="'.$name.'"/>';            
  1077.                 foreach ($options as $val{
  1078.                     $html .= '<option value="'.$val.'">'.$val.'</option>';
  1079.                 }
  1080.                 $html .= '</select><br>';
  1081.                 $html .= '</td></tr>';
  1082.             }else{
  1083.                 $html .= '<select name="'.$name.'"/>';            
  1084.                 foreach ($options as $val{
  1085.                     $html .= '<option value="'.$val.'">'.$val.'</option>';
  1086.                 }
  1087.                 $html .= '</select>';
  1088.             }
  1089.         }
  1090.         
  1091.         if ($mode == 'edit'{
  1092.             if ($tableTags{
  1093.                 $html .= '<tr><th style="width:25%;">';
  1094.                 $html .= $label;
  1095.                 $html .= '</th>';
  1096.                 $html .= '<td>';
  1097.                 $html .= '<select name="'.$name.'"/>';            
  1098.                 foreach ($options as $val{
  1099.                     if ($value == $val)
  1100.                         $html .= '<option value="'.$val.'" selected>'.$val.'</option>';
  1101.                     else
  1102.                         $html .= '<option value="'.$val.'">'.$val.'</option>';
  1103.                 }
  1104.                 $html .= '</select><br>';
  1105.                 $html .= '</td></tr>';
  1106.             }else{
  1107.                 $html .= '<select name="'.$name.'"/>';            
  1108.                 foreach ($options as $val{
  1109.                     if ($value == $val)
  1110.                         $html .= '<option value="'.$val.'" selected>'.$val.'</option>';
  1111.                     else
  1112.                         $html .= '<option value="'.$val.'">'.$val.'</option>';
  1113.                 }
  1114.                 $html .= '</select>';
  1115.             }
  1116.         }
  1117.                 
  1118.         self::$logger->debug('<<renderEnumField ['.$html.']');
  1119.         return $html;
  1120.     }
  1121.     
  1122.     /**
  1123.      * Method to render the default DEnum HTML
  1124.      *
  1125.      * @param string $name The field name
  1126.      * @param string $label The label to apply to the field
  1127.      * @param string $mode The field mode (create/edit/view)
  1128.      * @param array $options The DEnum options
  1129.      * @param string $value The field value (optional)
  1130.      * @param bool $tableTags Include table tags and label (optional)
  1131.      * @return string 
  1132.      * @since 1.0
  1133.      */
  1134.     public static function renderDEnumField($name$label$mode$options$value=''$tableTags=true{
  1135.         self::$logger->debug('>>renderDEnumField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  1136.         
  1137.         $html '';
  1138.         
  1139.         if ($mode == 'create'{
  1140.             if($tableTags{
  1141.                 $html .= '<tr><th style="width:25%;">';
  1142.                 $html .= $label;
  1143.                 $html .= '</th>';
  1144.                 $html .= '<td>';
  1145.                 $html .= '<select name="'.$name.'"/>';
  1146.                 foreach (array_keys($optionsas $index{
  1147.                     $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
  1148.                 }
  1149.                 $html .= '</select><br>';
  1150.                 $html .= '</td></tr>';
  1151.             }else{
  1152.                 $html .= '<select name="'.$name.'"/>';
  1153.                 foreach (array_keys($optionsas $index{
  1154.                     $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
  1155.                 }
  1156.                 $html .= '</select>';
  1157.             }
  1158.         }
  1159.         
  1160.         if ($mode == 'edit'{
  1161.             if($tableTags{
  1162.                 $html .= '<tr><th style="width:25%;">';
  1163.                 $html .= $label;
  1164.                 $html .= '</th>';
  1165.                 $html .= '<td>';
  1166.                 $html .= '<select name="'.$name.'"/>';            
  1167.                 foreach (array_keys($optionsas $index{
  1168.                     if ($value == $index)
  1169.                         $html .= '<option value="'.$index.'" selected>'.$options[$index].'</option>';
  1170.                     else
  1171.                         $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
  1172.                 }
  1173.                 $html .= '</select><br>';
  1174.                 $html .= '</td></tr>';
  1175.             }else{
  1176.                 $html .= '<select name="'.$name.'"/>';            
  1177.                 foreach (array_keys($optionsas $index{
  1178.                     if ($value == $index)
  1179.                         $html .= '<option value="'.$index.'" selected>'.$options[$index].'</option>';
  1180.                     else
  1181.                         $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
  1182.                 }
  1183.                 $html .= '</select>';
  1184.             }
  1185.         }        
  1186.         
  1187.         self::$logger->debug('<<renderDEnumField ['.$html.']');
  1188.         return $html;
  1189.     }
  1190.     
  1191.     /**
  1192.      * Method to render the default field HTML when type is not known
  1193.      *
  1194.      * @param string $name The field name
  1195.      * @param string $label The label to apply to the field
  1196.      * @param string $mode The field mode (create/edit/view)
  1197.      * @param string $value The field value (optional)
  1198.      * @param bool $tableTags Include table tags and label (optional)
  1199.      * @return string 
  1200.      * @since 1.0
  1201.      */
  1202.     public function renderDefaultField($name$label$mode$value=''$tableTags=true{
  1203.         self::$logger->debug('>>renderDefaultField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  1204.         
  1205.         $html '';
  1206.         
  1207.         if ($mode == 'create'{
  1208.             if($tableTags{
  1209.                 $html .= '<tr><th colspan="2">';
  1210.                 $html .= $label;
  1211.                 $html .= '</th></tr>';
  1212.         
  1213.                 $html .= '<tr><td colspan="2">';
  1214.                 $html .= '<textarea cols="100" rows="3" name="'.$name.'">'(isset ($_POST[$name]$_POST[$name'').'</textarea><br>';
  1215.                 $html .= '</td></tr>';
  1216.             }else{
  1217.                 $html .= '<textarea cols="100" rows="3" name="'.$name.'">'(isset ($_POST[$name]$_POST[$name'').'</textarea>';
  1218.             }
  1219.         }
  1220.         
  1221.         if ($mode == 'edit'{
  1222.             if($tableTags{        
  1223.                 $html .= '<tr><th colspan="2">';
  1224.                 $html .= $label;
  1225.                 $html .= '</th></tr>';
  1226.     
  1227.                 $html .= '<tr><td colspan="2">';
  1228.                 $html .= '<textarea cols="100" rows="3" name="'.$name.'">'.$value.'</textarea><br>';
  1229.                 $html .= '</td></tr>';
  1230.             }else{
  1231.                 $html .= '<textarea cols="100" rows="3" name="'.$name.'">'.$value.'</textarea>';
  1232.             }
  1233.         }
  1234.         
  1235.         if ($mode == 'view'{
  1236.             if($tableTags{
  1237.                 $html .= '<tr><th>';
  1238.                 $html .= $label;
  1239.                 $html .= '</th>';
  1240.     
  1241.                 $html .= '<td>&nbsp;';
  1242.                 if(method_exists($this'during_renderDefaultField_callback'))
  1243.                     $html .= $this->during_renderDefaultField_callback($name$mode$value);
  1244.                 else
  1245.                     $html .= $value;
  1246.                 $html .= '</td></tr>';
  1247.             }else{
  1248.                 $html .= $value;
  1249.             }
  1250.         }
  1251.         
  1252.         self::$logger->debug('<<renderDefaultField ['.$html.']');
  1253.         return $html;
  1254.     }
  1255.     
  1256.     /**
  1257.      * render the default Text HTML
  1258.      *
  1259.      * @param string $name The field name
  1260.      * @param string $label The label to apply to the field
  1261.      * @param string $mode The field mode (create/edit/view)
  1262.      * @param string $value The field value (optional)
  1263.      * @param bool $tableTags Include table tags and label (optional)
  1264.      * @return string 
  1265.      * @since 1.0
  1266.      */
  1267.     public function renderTextField($name$label$mode$value=''$tableTags=true{
  1268.         self::$logger->debug('>>renderTextField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  1269.         
  1270.         $html '';
  1271.         
  1272.         if ($mode == 'create'{
  1273.             // give 10 rows for content fields (other 5 by default)
  1274.             if($name == 'content')
  1275.                 $text new TextBox($this->BO->getPropObject($name)$label$name10);
  1276.             else
  1277.                 $text new TextBox($this->BO->getPropObject($name)$label$name);
  1278.             $html .= $text->render($tableTags);
  1279.         }
  1280.         
  1281.         if ($mode == 'edit'{
  1282.             // give 10 rows for content fields (other 5 by default)
  1283.             if($name == 'content'{
  1284.                 $viewState ViewState::getInstance();
  1285.                 
  1286.                 if($viewState->get('markdownTextBoxRows'== '')
  1287.                     $text new TextBox($this->BO->getPropObject($name)$label$name10);
  1288.                 else
  1289.                     $text new TextBox($this->BO->getPropObject($name)$label$name(integer)$viewState->get('markdownTextBoxRows'));
  1290.                     
  1291.                 $html .= $text->render($tableTagstrue);
  1292.             }else{
  1293.                 $text new TextBox($this->BO->getPropObject($name)$label$name);
  1294.                 $html .= $text->render($tableTags);
  1295.             }
  1296.         }
  1297.         
  1298.         if ($mode == 'view'{
  1299.             if($tableTags)
  1300.                 $html .= '<tr><th>';
  1301.                 
  1302.             $html .= $label;
  1303.             
  1304.             if($tableTags)
  1305.                 $html .= '</th>';
  1306.             
  1307.             // filter ouput to prevent malicious injection
  1308.             $value InputFilter::encode($value);
  1309.  
  1310.             // ensures that line returns are rendered
  1311.             $value str_replace("\n"'<br>'$value);
  1312.             
  1313.             if($tableTags)
  1314.                 $html .= '<td>&nbsp;';
  1315.                 
  1316.             $html .= $value;
  1317.             
  1318.             if($tableTags)
  1319.                 $html .= '</td></tr>';
  1320.         }
  1321.         
  1322.         self::$logger->debug('<<renderTextField ['.$html.']');
  1323.         return $html;
  1324.     }
  1325.     
  1326.     /**
  1327.      * render the default Relation HTML
  1328.      *
  1329.      * @param string $name The field name
  1330.      * @param string $label The label to apply to the field
  1331.      * @param string $mode The field mode (create/edit/view)
  1332.      * @param string $value The field value (optional)
  1333.      * @param bool $tableTags Include table tags and label (optional)
  1334.      * @param bool $expanded Render the related fields in expanded format or not (optional)
  1335.      * @param bool $buttons Render buttons for expanding/contacting the related fields (optional)
  1336.      * @return string 
  1337.      * @since 1.0
  1338.      */
  1339.     public function renderRelationField($name$label$mode$value=''$tableTags=true$expanded=false$buttons=true{
  1340.         self::$logger->debug('>>renderRelationField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'], expanded=['.$expanded.'], buttons=['.$buttons.'])');
  1341.         
  1342.         $html '';
  1343.         
  1344.         $rel $this->BO->getPropObject($name);
  1345.         
  1346.         if ($mode == 'create' || $mode == 'edit'{
  1347.             if($rel->getRelationType(== 'MANY-TO-MANY'{
  1348.                 try{
  1349.                     // check to see if the rel is on this class
  1350.                     $rel->getSide(get_class($this->BO));
  1351.                     $widget new RecordSelector($rel$label$nameget_class($this->BO));
  1352.                     $html .= $widget->render($tableTags$expanded$buttons);
  1353.                 }catch (IllegalArguementException $iae{
  1354.                     // the rel may be on a parent class
  1355.                     $parentClassName ucfirst($this->BO->getTableName()).'Object';
  1356.                     $widget new RecordSelector($rel$label$name$parentClassName);
  1357.                     $html .= $widget->render($tableTags$expanded$buttons);
  1358.                 }
  1359.             }else{
  1360.                 $rel new RecordSelector($rel$label$name);
  1361.                 $html .= $rel->render($tableTags$expanded$buttons);
  1362.             }
  1363.         }
  1364.         
  1365.         if ($mode == 'view'{
  1366.             if($rel->getRelationType(== 'MANY-TO-ONE'{
  1367.                 $html .= $this->renderDefaultField($name$label'view'$rel->getRelatedClassDisplayFieldValue());
  1368.             }elseif($rel->getRelationType(== 'MANY-TO-MANY'{
  1369.                 try{
  1370.                     // check to see if the rel is on this class
  1371.                     $rel->getSide(get_class($this->BO));
  1372.                     $html .= $this->renderDefaultField($name$label'view'$rel->getRelatedClassDisplayFieldValue(get_class($this->BO)));
  1373.                 }catch (IllegalArguementException $iae{
  1374.                     // the rel may be on a parent class
  1375.                     $parentClassName ucfirst($this->BO->getTableName()).'Object';
  1376.                     $html .= $this->renderDefaultField($name$label'view'$rel->getRelatedClassDisplayFieldValue($parentClassName));
  1377.                 }
  1378.             }else{
  1379.                 $rel new RecordSelector($rel$label$name);
  1380.                 $html .= $rel->render($tableTags$expanded$buttons);
  1381.             }
  1382.         }
  1383.         
  1384.         self::$logger->debug('<<renderRelationField ['.$html.']');
  1385.         return $html;
  1386.     }
  1387.     
  1388.     /**
  1389.      * Renders all fields for the current BO in edit/create/view mode
  1390.      *
  1391.      * @param string $mode (view|edit|create)
  1392.      * @param array $filterFields Optional list of field names to exclude from rendering
  1393.      * @param array $readOnlyFields Optional list of fields to render in a readonly fashion when rendering in create or edit mode
  1394.      * @return string 
  1395.      * @since 1.0
  1396.      */
  1397.     public function renderAllFields($mode$filterFields=array()$readOnlyFields=array()) {
  1398.         self::$logger->debug('>>renderAllFields(mode=['.$mode.'], filterFields=['.var_export($filterFieldstrue).'], readOnlyFields=['.var_export($readOnlyFieldstrue).'])');
  1399.         
  1400.         $html '';
  1401.                 
  1402.         // get the class attributes        
  1403.         $properties array_keys($this->BO->getDataLabels());
  1404.         
  1405.         $orignalMode $mode;
  1406.         
  1407.         foreach($properties as $propName{            
  1408.             if (!in_array($propName$this->BO->getDefaultAttributes()) && !in_array($propName$filterFields)) {
  1409.                 // render readonly fields in the supplied array
  1410.                 if(in_array($propName$readOnlyFields))
  1411.                     $mode 'view';
  1412.                 else
  1413.                     $mode $orignalMode;
  1414.                     
  1415.                 if(!is_object($this->BO->getPropObject($propName)))
  1416.                     continue;
  1417.                     
  1418.                 $propClass get_class($this->BO->getPropObject($propName));
  1419.                 
  1420.                 // exclude non-Relation transient attributes from create and edit screens
  1421.                 if($propClass != 'Relation' && ($mode == 'edit' || $mode == 'create'&& in_array($propName$this->BO->getTransientAttributes())) {
  1422.                     continue;
  1423.                 }
  1424.                 
  1425.                 switch (strtoupper($propClass)) {
  1426.                     case 'INTEGER' :
  1427.                         if($mode == 'view'{
  1428.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$this->BO->get($propName));
  1429.                         }else{
  1430.                             $html .= $this->renderIntegerField($propName$this->BO->getDataLabel($propName)$mode$this->BO->get($propName));
  1431.                         }                
  1432.                     break;
  1433.                     case 'DOUBLE' :
  1434.                         if($mode == 'view'{
  1435.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$this->BO->get($propName));
  1436.                         }else{
  1437.                             $html .= $this->renderDoubleField($propName$this->BO->getDataLabel($propName)$mode$this->BO->get($propName));
  1438.                         }
  1439.                     break;
  1440.                     case 'DATE' :
  1441.                         if($mode == 'view'{
  1442.                             $value $this->BO->get($propName);
  1443.                             if ($value == '0000-00-00')
  1444.                                 $value '';
  1445.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$value);
  1446.                         }else{
  1447.                             $date new DateBox($this->BO->getPropObject($propName)$this->BO->getDataLabel($propName)$propName);
  1448.                             $html .= $date->render();
  1449.                         }
  1450.                     break;
  1451.                     case 'TIMESTAMP' :
  1452.                         if($mode == 'view'{
  1453.                             $value $this->BO->get($propName);
  1454.                             if ($value == '0000-00-00 00:00:00')
  1455.                                 $value '';
  1456.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$value);
  1457.                         }else{
  1458.                             $timestamp new DateBox($this->BO->getPropObject($propName)$this->BO->getDataLabel($propName)$propName);
  1459.                             $html .= $timestamp->render();
  1460.                         }
  1461.                     break;
  1462.                     case 'STRING' :
  1463.                         if($mode == 'view'{
  1464.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$this->BO->get($propName));
  1465.                         }else{
  1466.                             $string new StringBox($this->BO->getPropObject($propName)$this->BO->getDataLabel($propName)$propName);
  1467.                             $html .= $string->render();
  1468.                         }
  1469.                     break;
  1470.                     case 'TEXT' :
  1471.                         $html .= $this->renderTextField($propName$this->BO->getDataLabel($propName)$mode$this->BO->get($propName));
  1472.                     break;
  1473.                     case 'BOOLEAN' :
  1474.                         if($mode == 'view'{
  1475.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$this->BO->get($propName));
  1476.                         }else{
  1477.                             $html .= $this->renderBooleanField($propName$this->BO->getDataLabel($propName)$mode$this->BO->get($propName));
  1478.                         }
  1479.                     break;
  1480.                     case 'ENUM' :
  1481.                         if($mode == 'view'{
  1482.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$this->BO->get($propName));
  1483.                         }else{
  1484.                             $enum $this->BO->getPropObject($propName);
  1485.                             $html .= $this->renderEnumField($propName$this->BO->getDataLabel($propName)$mode$enum->getOptions()$this->BO->get($propName));
  1486.                         }
  1487.                     break;
  1488.                     case 'DENUM' :
  1489.                         if($mode == 'view'{
  1490.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$this->BO->getPropObject($propName)->getDisplayValue());
  1491.                         }else{
  1492.                             $denum $this->BO->getPropObject($propName);
  1493.                             $html .= $this->renderDEnumField($propName$this->BO->getDataLabel($propName)$mode$denum->getOptions()$this->BO->get($propName));
  1494.                         }
  1495.                     break;
  1496.                     case 'RELATION' :
  1497.                         $html .= $this->renderRelationField($propName$this->BO->getDataLabel($propName)$mode$this->BO->get($propName));
  1498.                     break;
  1499.                     default :
  1500.                         $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)$mode$this->BO->get($propName));
  1501.                     break;
  1502.                 }
  1503.             }
  1504.         }
  1505.         
  1506.         self::$logger->debug('<<renderAllFields ['.$html.']');
  1507.         return $html;
  1508.     }
  1509.     
  1510.     /**
  1511.      * Loads a .phtml template for the BO specified if one exists.  Lower level custom templates
  1512.      * take precedence.
  1513.      * 
  1514.      * @param AlphaDAO $BO 
  1515.      * @param string $mode 
  1516.      * @param array $fields 
  1517.      * @since 1.0
  1518.      * @throws IllegalArguementException
  1519.      */
  1520.     public function loadTemplate($BO$mode$fields{
  1521.         self::$logger->debug('>>loadTemplate(BO=['.var_export($BOtrue).'], mode=['.$mode.'], fields=['.var_export($fieldstrue).'])');
  1522.         
  1523.         global $config;
  1524.         
  1525.         // for each BO property, create a local variable holding its value        
  1526.         $reflection new ReflectionClass(get_class($this->BO));
  1527.         $properties $reflection->getProperties();
  1528.         
  1529.         foreach($properties as $propObj{
  1530.             $propName $propObj->name;
  1531.             
  1532.             if($propName != 'logger' && !$propObj->isPrivate()) {
  1533.                 $prop $BO->getPropObject($propName);
  1534.                 if($prop instanceof DEnum{                    
  1535.                     ${$propName$BO->getPropObject($propName)->getDisplayValue();
  1536.                 }else{
  1537.                     ${$propName$BO->get($propName);
  1538.                 }
  1539.             }
  1540.         }
  1541.         
  1542.         // loop over the $fields array and create a local variable for each key value
  1543.         foreach (array_keys($fieldsas $fieldName)
  1544.             ${$fieldName$fields[$fieldName];
  1545.             
  1546.         $filename $mode.'.phtml';
  1547.         $classTemplateDir get_class($BO);
  1548.  
  1549.         $customPath $config->get('sysRoot').'view/templates/'.$classTemplateDir.'/'.$filename;
  1550.         $defaultPath1 $config->get('sysRoot').'alpha/view/templates/'.$classTemplateDir.'/'.$filename;
  1551.         $defaultPath2 $config->get('sysRoot').'alpha/view/templates/'.$filename;
  1552.  
  1553.         // Check to see if a custom template exists for this BO, and if it does load that        
  1554.         if (file_exists($customPath)) {
  1555.             self::$logger->debug('Loading template ['.$customPath.']');
  1556.             require $customPath;                
  1557.         }elseif (file_exists($defaultPath1)) {
  1558.             self::$logger->debug('Loading template ['.$defaultPath1.']');
  1559.             require $defaultPath1;
  1560.         }elseif (file_exists($defaultPath2)) {
  1561.             self::$logger->debug('Loading template ['.$defaultPath2.']');
  1562.             require $defaultPath2;    
  1563.         }else{
  1564.             throw new IllegalArguementException('No ['.$mode.'] HTML template found for class ['.get_class($BO).']');
  1565.         }
  1566.         
  1567.         self::$logger->debug('<<loadTemplate');
  1568.     }
  1569. }
  1570. ?>

Documentation generated on Tue, 13 Dec 2011 20:26:22 +0000 by phpDocumentor 1.4.3