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 1347 2011-03-17 16:36:06Z 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''viewBut');
  360.             $fields['viewButton'$button->render();
  361.         }else{
  362.             if($this->BO->hasAttribute('URL'))
  363.                 $button new Button("document.location = '".$this->BO->get('URL')."';"'View''viewBut');
  364.             else
  365.                 $button new Button("document.location = '".$config->get('sysURL')."Detail/bo/".get_class($this->BO)."/oid/".$this->BO->getOID()."';"'View''viewBut');
  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""editBut");
  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""deleteBut");
  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""createBut");
  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""listBut");
  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.      * @return string 
  586.      * @throws IllegalArguementException
  587.      * @since 1.0
  588.      */
  589.     public static function displayPageHead($controller$renderMenu true{
  590.         if(self::$logger == null)
  591.             self::$logger new Logger('AlphaView');
  592.         self::$logger->debug('>>displayPageHead(controller=['.var_export($controllertrue).'])');
  593.         
  594.         if(method_exists($controller'before_displayPageHead_callback'))
  595.             $controller->before_displayPageHead_callback();
  596.         
  597.         global $config;
  598.         
  599.         if(!AlphaController::checkControllerDefExists(get_class($controller)))
  600.             throw new IllegalArguementException('The controller provided ['.get_class($controller).'] is not defined anywhere!');
  601.         
  602.         $html '';
  603.         
  604.         $html.= '<html>';
  605.         $html.= '<head>';
  606.         $html.= '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
  607.         $html.= '<title>'.$controller->getTitle().'</title>';
  608.         if($controller->getKeywords(!= '')
  609.             $html.= '<meta name="Keywords" content="'.$controller->getKeywords().'">';
  610.         if($controller->getDescription(!= '')
  611.             $html.= '<meta name="Description" content="'.$controller->getDescription().'">';
  612.         $html.= '<meta name="title" content="'.$controller->getTitle().'">';
  613.         $html.= '<meta name="robots" content="index,follow,NOODP">';
  614.         if ($controller->getBO(!= null && $controller->getBO()->hasAttribute('URL')) {
  615.             $URL $controller->getBO()->get('URL');
  616.             if($URL != '')
  617.                 $html.= '<link rel="canonical" href="'.$URL.'" />';
  618.         }
  619.         $html.= '<meta http-equiv="imagetoolbar" content="no">';
  620.  
  621.         $html.= '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'alpha/lib/jquery/ui/themes/'.$config->get('sysTheme').'/ui.all.css">';
  622.         $html.= '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'alpha/css/alpha.css">';
  623.         $html.= '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'config/css/overrides.css">';
  624.  
  625.         $html.= '<script language="JavaScript" src="'.$config->get('sysURL').'alpha/scripts/addOnloadEvent.js"></script>';
  626.         
  627.         $html.= '<script type="text/javascript" src="'.$config->get('sysURL').'alpha/lib/jquery/jquery-1.3.2.min.js"></script>';
  628.         $html.= '<script language="JavaScript" src="'.$config->get('sysURL').'alpha/scripts/validation.js"></script>';
  629.         $html.= '<script type="text/javascript" src="'.$config->get('sysURL').'alpha/lib/jquery/contextMenu/jquery.contextMenu.js"></script>';
  630.         
  631.         $html.= '<script type="text/javascript" src="'.$config->get('sysURL').'alpha/lib/jquery/ui/jquery.ui.potato.menu.js"></script>';
  632.         
  633.         $html.= '<script type="text/javascript" src="'.$config->get('sysURL').'alpha/lib/jquery/ui/jquery-ui-1.7.2.custom.min.js"></script>';
  634.         $html.= '<script type="text/javascript" src="'.$config->get('sysURL').'alpha/lib/jquery/ui/ui.datepicker.js"></script>';
  635.         
  636.         // handle force-frames
  637.         if($config->get('sysForceFrame')) {
  638.             // if no-forceframe=true or we are in the admin backend, don't force frame
  639.             if(!isset($_GET['no-forceframe']&& strpos($_SERVER['REQUEST_URI']'/tk/'=== false{
  640.                 $html.= '<script type="text/javascript">';
  641.                 $html.= 'pageLoc = self.location;';
  642.                 $html.= 'pageAdd = top.location;';
  643.          
  644.                 $html.= 'if (pageLoc == pageAdd) {';
  645.                 $html.= '    contentSrc = escape(pageLoc);';
  646.                 $html.= '    contPage = \''.$config->get('sysURL').'?\' + contentSrc;';
  647.                 $html.= '    top.location.href = contPage;';
  648.                 $html.= '}';
  649.                 $html.= '</script>';
  650.             }
  651.         }
  652.                 
  653.         $html.= '<script type="text/javascript">';
  654.         $html .= Button::renderJavascript();
  655.         $html.= '</script>';
  656.         
  657.         if (isset($_SESSION['currentUser']&& AlphaDAO::isInstalled(&& $_SESSION['currentUser']->inGroup('Admin'&& strpos($_SERVER['REQUEST_URI']'/tk/'!== false{
  658.             $html.= '<script type="text/javascript">';
  659.             $html.= '    (function($) {';
  660.             $html.= '        $(document).ready(function(){';
  661.             $html.= '        $("#adminmenu").ptMenu();';
  662.             $html.= '    });';
  663.             $html.= '})(jQuery);';
  664.             $html.= '</script>';
  665.         }
  666.         
  667.         // general dialog defaults
  668.         $html.= '<script type="text/javascript">';
  669.         $html.= '    (function($) {';
  670.         $html.= '        var dialogCoords = [(screen.width/2)-200, (screen.height/2)-200];';
  671.         $html.= '        $(document).ready(function(){';
  672.         $html.= '            $.extend($.ui.dialog.defaults, {';
  673.         $html.= '                modal: true,';
  674.         $html.= '                resizable: false,';
  675.         $html.= '                draggable: false,';
  676.         $html.= '                autoOpen: false,';
  677.         $html.= '                height: 200,';
  678.         $html.= '                width: 400,';
  679.         $html.= '                position: dialogCoords,';
  680.         $html.= '                buttons: {';
  681.         $html.= '                    "Cancel": function() {';
  682.         $html.= '                        $(this).dialog("close");';
  683.         $html.= '                    }';
  684.         $html.= '                }';
  685.         $html.= '            });';
  686.         $html.= '        });';
  687.         $html.= '    })(jQuery);';
  688.         $html.= '</script>';
  689.         
  690.         // record selector JS
  691.         $html.= '<script type="text/javascript">';
  692.         $html.= '    (function($) {';
  693.         $html.= '        $(document).ready(function(){';
  694.         $html.= '            var dialogOpts = {';
  695.         $html.= '                title: "Record selector",';
  696.         $html.= '                modal: true,';
  697.         $html.= '                resizable: false,';
  698.         $html.= '                draggable: false,';
  699.         $html.= '                autoOpen: false,';
  700.         $html.= '                height: 300,';
  701.         $html.= '                width: 600';
  702.         $html.= '            };';
  703.         $html.= '            $("#recordSelector").dialog(dialogOpts);';
  704.         $html.= '        });';
  705.         $html.= '    })(jQuery);';
  706.         $html.= '</script>';
  707.         
  708.         if(method_exists($controller'during_displayPageHead_callback'))
  709.             $html.= $controller->during_displayPageHead_callback();
  710.         
  711.         $html.= '</head>';
  712.         try {
  713.             if($controller->getBO(!= null)
  714.                 $html.= '<body'.($controller->getBO()->get('bodyOnload'!= '' ' onload="'.$controller->getBO()->get('bodyOnload').'"' '').'>';
  715.             else
  716.                 $html.= '<body>';
  717.         catch (AlphaException $e{
  718.             $html.= '<body>';
  719.         }
  720.         
  721.         if(method_exists($controller'insert_CMSDisplayStandardHeader_callback'))
  722.             $html.= $controller->insert_CMSDisplayStandardHeader_callback();
  723.         
  724.         $html .= '<div id="recordSelector"></div>';
  725.             
  726.         if($controller->getTitle(!= '')
  727.             $html.= '<h1>'.$controller->getTitle().'</h1>';
  728.         
  729.         if (isset($_SESSION['currentUser'])) {    
  730.             $html.= '<p>You are logged in as '.$_SESSION['currentUser']->getDisplayname().'.  <a href="'.FrontController::generateSecureURL('act=Logout').'">Logout</a></p>';
  731.         }
  732.         
  733.         if ($renderMenu && isset($_SESSION['currentUser']&& AlphaDAO::isInstalled(&& $_SESSION['currentUser']->inGroup('Admin'&& strpos($_SERVER['REQUEST_URI']'/tk/'!== false{
  734.             $html .= '<ul id="adminmenu" class="potato-menu">
  735.                         <li><a href="'.$config->get('sysURL').'">Home</a></li>
  736.                         <li><a href="'.FrontController::generateSecureURL('act=ListBusinessObjects').'">Admin Home</a></li>
  737.                         <li><a href="#">Logs &raquo;</a>            
  738.                             <ul>
  739.                                 <li><a href="'.FrontController::generateSecureURL('act=ViewLog&logPath='.$config->get('sysLogFile')).'">System Log</a></li>
  740.                                 <li><a href="'.FrontController::generateSecureURL('act=ViewLog&logPath='.$config->get('sysRoot').'logs/search.log').'">Search Log</a></li>
  741.                                 <li><a href="'.FrontController::generateSecureURL('act=ViewLog&logPath='.$config->get('sysRoot').'logs/feeds.log').'">Feed Log</a></li>
  742.                                 <li><a href="'.FrontController::generateSecureURL('act=ViewLog&logPath='.$config->get('sysRoot').'logs/tasks.log').'">Cron Tasks Log</a></li>
  743.                             </ul>
  744.                         </li>
  745.                         <li><a href="'.FrontController::generateSecureURL('act=GenSecureQueryStrings').'">Generate Secure URL</a></li>
  746.                         <li><a href="'.FrontController::generateSecureURL('act=ViewMetrics').'">Software Metrics</a></li>
  747.                         <li><a href="'.FrontController::generateSecureURL('act=CacheManager').'">Manage Cache</a></li>
  748.                         <li><a href="'.FrontController::generateSecureURL('act=TagManager').'">Manage Tags</a></li>
  749.                         <li><a href="'.FrontController::generateSecureURL('act=ListDEnums').'">Manage DEnums</a></li>
  750.                         <li><a href="'.FrontController::generateSecureURL('act=ListSequences').'">Manage Sequences</a></li>
  751.                         <li><a href="'.FrontController::generateSecureURL('act=ViewTestResults').'">Unit Tests</a></li>
  752.                     </ul>';
  753.         }
  754.         
  755.         if(method_exists($controller'after_displayPageHead_callback'))
  756.             $html.= $controller->after_displayPageHead_callback();
  757.             
  758.         // render a status message if there is any
  759.         $message $controller->getStatusMessage();
  760.         if(!empty($message))
  761.             $html .= $message;
  762.             
  763.         self::$logger->debug('<<displayPageHead ['.$html.']');
  764.         return $html;
  765.     }
  766.     
  767.     /**
  768.      * Method to render the page footer HTML
  769.      * 
  770.      * @param AlphaController $controller 
  771.      * @return string 
  772.      * @since 1.0
  773.      */
  774.     public static function displayPageFoot($controller{
  775.         if(self::$logger == null)        
  776.             self::$logger new Logger('AlphaView');
  777.         
  778.         self::$logger->debug('>>displayPageFoot(controller=['.get_class($controller).'])');
  779.         $html '';
  780.         
  781.         if(method_exists($controller'before_displayPageFoot_callback'))
  782.             $html .= $controller->before_displayPageFoot_callback();
  783.         
  784.         $html .= '<div id="dialogDiv"></div>';
  785.         $html .= '</body>';
  786.         $html .= '</html>';
  787.         
  788.         if(method_exists($controller'after_displayPageFoot_callback'))
  789.             $this->after_displayPageFoot_callback();
  790.             
  791.         self::$logger->debug('<<displayPageFoot ['.$html.']');
  792.         return $html;
  793.     }
  794.     
  795.     /**
  796.      * Renders the HTML for an update (e.g. successful save) message
  797.      * 
  798.      * @param string $message 
  799.      * @return string 
  800.      * @since 1.0
  801.      */
  802.     public static function displayUpdateMessage($message{
  803.         if(self::$logger == null)
  804.             self::$logger new Logger('AlphaView');
  805.         self::$logger->debug('>>displayUpdateMessage(message=['.$message.'])');
  806.         
  807.         $html '<div class="ui-state-highlight ui-corner-all" style="padding: 0pt 0.7em;"> 
  808.                 <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: 0.3em;"></span> 
  809.                 <strong>Update:</strong> '.$message.'</p></div>';
  810.         
  811.         self::$logger->debug('<<displayUpdateMessage ['.$html.']');
  812.         return $html;
  813.     }
  814.     
  815.     /**
  816.      * Renders the HTML for an error (e.g. save failed) message
  817.      * 
  818.      * @param string $message 
  819.      * @return string 
  820.      * @since 1.0
  821.      */
  822.     public static function displayErrorMessage($message{
  823.         if(self::$logger == null)
  824.             self::$logger new Logger('AlphaView');
  825.         self::$logger->debug('>>displayErrorMessage(message=['.$message.'])');
  826.         
  827.         $html '<div class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em;"> 
  828.                 <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span> 
  829.                 <strong>Error:</strong> '.$message.'</p></div>';
  830.         
  831.         self::$logger->debug('<<displayErrorMessage ['.$html.']');
  832.         return $html;
  833.     }
  834.     
  835.     /**
  836.      * Renders a HTML error page with the supplied error code (typlically a HTTP code) and a message
  837.      * 
  838.      * @param string $code 
  839.      * @param string $message 
  840.      * @return string 
  841.      * @since 1.0
  842.      */
  843.     public static function renderErrorPage($code$message{
  844.         global $config;        
  845.         
  846.         $html '<html><head>';
  847.         $html .= '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'alpha/lib/jquery/ui/themes/'.$config->get('sysTheme').'/ui.all.css">';
  848.         $html .= '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'alpha/css/alpha.css">';
  849.         $html .= '<link rel="StyleSheet" type="text/css" href="'.$config->get('sysURL').'config/css/overrides.css">';
  850.         $html .= '<title>'.$code.' - '.$message.'</title></head>';
  851.         $html .= '<body>';
  852.         $html .= '<div class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em;"> 
  853.                 <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span> 
  854.                 <strong>'.$code.':</strong> '.$message.'</p>
  855.                 </div>';
  856.         $html .= '</body></html>';
  857.         
  858.         return $html;
  859.     }
  860.     
  861.     /**
  862.      * Method to render a hidden form for posting the OID of an object to be deleted
  863.      * 
  864.      * @return string 
  865.      * @since 1.0
  866.      */
  867.     public static function renderDeleteForm({
  868.         if(self::$logger == null)
  869.             self::$logger new Logger('AlphaView');
  870.         self::$logger->debug('>>renderDeleteForm()');
  871.         
  872.         $html '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST" id="deleteForm">';        
  873.         $html .= '<input type="hidden" name="deleteOID" id="deleteOID" value=""/>';
  874.         $html .= self::renderSecurityFields();
  875.         $html .= '</form>';
  876.         
  877.         self::$logger->debug('<<renderDeleteForm ['.$html.']');
  878.         return $html;
  879.     }
  880.     
  881.     /**
  882.      * Method to render a HTML form with two hidden, hashed (MD5) form fields to be used as
  883.      * a check to ensure that a post to the controller is being sent from the same server
  884.      * as hosting it.
  885.      * 
  886.      * @return string 
  887.      * @since 1.0
  888.      */
  889.     public static function renderSecurityFields({
  890.         if(self::$logger == null)
  891.             self::$logger new Logger('AlphaView');
  892.         self::$logger->debug('>>renderSecurityFields()');
  893.         
  894.         $html '';
  895.         
  896.         $fields AlphaController::generateSecurityFields();
  897.         
  898.         $html .= '<input type="hidden" name="var1" value="'.$fields[0].'"/>';
  899.         $html .= '<input type="hidden" name="var2" value="'.$fields[1].'"/>';
  900.         
  901.         self::$logger->debug('<<renderSecurityFields ['.$html.']');
  902.         return $html;
  903.     }
  904.     
  905.     /**
  906.      * Method to render the default Integer HTML
  907.      *
  908.      * @param string $name The field name
  909.      * @param string $label The label to apply to the field
  910.      * @param string $mode The field mode (create/edit/view)
  911.      * @param string $value The field value (optional)
  912.      * @param bool $tableTags Include table tags and label (optional)
  913.      * @return string 
  914.      * @since 1.0
  915.      */
  916.     public function renderIntegerField($name$label$mode$value=''$tableTags=true{
  917.         self::$logger->debug('>>renderIntegerField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  918.         
  919.         $html '';
  920.         
  921.         if ($mode == 'create'{
  922.             if($tableTags{
  923.                 $html .= '<tr><th style="width:25%;">';
  924.                 $html .= $label;
  925.                 $html .= '</th>';
  926.         
  927.                 $html .= '<td>';
  928.                 $html .= '<input type="text" style="width:100%;" name="'.$name.'" value="'(isset ($_POST[$name]$_POST[$name'').'"/><br>';
  929.                 $html .= '</td></tr>';
  930.             }else{
  931.                 $html .= '<input type="text" style="width:100%;" name="'.$name.'" value="'(isset ($_POST[$name]$_POST[$name'').'"/><br>';
  932.             }
  933.         }
  934.         
  935.         if ($mode == 'edit'{
  936.             if($tableTags{
  937.                 $html .= '<tr><th style="width:25%;">';
  938.                 $html .= $label;
  939.                 $html .= '</th>';
  940.     
  941.                 $html .= '<td>';
  942.                 $html .= '<input type="text" style="width:100%;" name="'.$name.'" value="'.$value.'"/><br>';
  943.                 $html .= '</td></tr>';
  944.             }else{
  945.                 $html .= '<input type="text" style="width:100%;" name="'.$name.'" value="'.$value.'"/>';
  946.             }
  947.         }
  948.                 
  949.         self::$logger->debug('<<renderIntegerField ['.$html.']');
  950.         return $html;
  951.     }
  952.     
  953.     /**
  954.      * Method to render the default Double HTML
  955.      *
  956.      * @param string $name The field name
  957.      * @param string $label The label to apply to the field
  958.      * @param string $mode The field mode (create/edit/view)
  959.      * @param string $value The field value (optional)
  960.      * @param bool $tableTags Include table tags and label (optional)
  961.      * @return string 
  962.      * @since 1.0
  963.      */
  964.     public static function renderDoubleField($name$label$mode$value=''$tableTags=true{
  965.         self::$logger->debug('>>renderDoubleField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  966.         
  967.         $html '';
  968.         
  969.         if ($mode == 'create'{
  970.             if($tableTags{
  971.                 $html .= '<tr><th style="width:25%;">';
  972.                 $html .= $label;
  973.                 $html .= '</th>';
  974.         
  975.                 $html .= '<td>';
  976.                 $html .= '<input type="text" size="13" name="'.$name.'" value="'(isset ($_POST[$name]$_POST[$name'').'"/><br>';
  977.                 $html .= '</td></tr>';
  978.             }else{
  979.                 $html .= '<input type="text" size="13" name="'.$name.'" value="'(isset ($_POST[$name]$_POST[$name'').'"/>';
  980.             }
  981.         }
  982.         
  983.         if ($mode == 'edit'{
  984.             if($tableTags{
  985.                 $html .= '<tr><th style="width:25%;">';
  986.                 $html .= $label;
  987.                 $html .= '</th>';
  988.     
  989.                 $html .= '<td>';
  990.                 $html .= '<input type="text" size="13" name="'.$name.'" value="'.$value.'"/><br>';
  991.                 $html .= '</td></tr>';
  992.             }else{
  993.                 $html .= '<input type="text" size="13" name="'.$name.'" value="'.$value.'"/>';
  994.             }
  995.         }
  996.                 
  997.         self::$logger->debug('<<renderDoubleField ['.$html.']');
  998.         return $html;
  999.     }
  1000.     
  1001.     /**
  1002.      * Method to render the default Boolean HTML
  1003.      *
  1004.      * @param string $name The field name
  1005.      * @param string $label The label to apply to the field
  1006.      * @param string $mode The field mode (create/edit/view)
  1007.      * @param string $value The field value (optional)
  1008.      * @param bool $tableTags Include table tags and label (optional)
  1009.      * @return string 
  1010.      * @since 1.0
  1011.      */
  1012.     public function renderBooleanField($name$label$mode$value=''$tableTags=true{
  1013.         self::$logger->debug('>>renderBooleanField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  1014.         
  1015.         $html '';
  1016.         
  1017.         if ($mode == 'create'{
  1018.             if($tableTags{
  1019.                 $html .= '<tr><th style="width:25%;">';
  1020.                 $html .= $label;
  1021.                 $html .= '</th>';
  1022.         
  1023.                 $html .= '<td>';
  1024.                 $html .= '<select size="1" name="'.$name.'"/>';
  1025.                 $html .= '<option value="0" selected>N</option>';
  1026.                 $html .= '<option value="1">Y</option>';
  1027.                 $html .= '</select><br>';
  1028.                 $html .= '</td></tr>';
  1029.             }else{
  1030.                 $html .= '<select size="1" name="'.$name.'"/>';
  1031.                 $html .= '<option value="0" selected>N</option>';
  1032.                 $html .= '<option value="1">Y</option>';
  1033.                 $html .= '</select>';
  1034.             }
  1035.         }
  1036.         
  1037.         if ($mode == 'edit'{
  1038.             if($tableTags{
  1039.                 $html .= '<tr><th>';
  1040.                 $html .= $label;
  1041.                 $html .= '</th>';
  1042.     
  1043.                 $html .= '<td>';
  1044.                 $html .= '<select size="1" name="'.$name.'"/>';
  1045.                 $html .= '<option value="0" '.($value == '0''selected':'').'>N</option>';
  1046.                 $html .= '<option value="1" '.($value == '1''selected':'').'>Y</option>';
  1047.                 $html .= '</select><br>';
  1048.                 $html .= '</td></tr>';
  1049.             }else{
  1050.                 $html .= '<select size="1" name="'.$name.'"/>';
  1051.                 $html .= '<option value="0" '.($value == '0''selected':'').'>N</option>';
  1052.                 $html .= '<option value="1" '.($value == '1''selected':'').'>Y</option>';
  1053.                 $html .= '</select>';
  1054.             }
  1055.         }
  1056.                 
  1057.         self::$logger->debug('<<renderBooleanField ['.$html.']');
  1058.         return $html;
  1059.     }
  1060.     
  1061.     /**
  1062.      * Method to render the default Enum HTML
  1063.      *
  1064.      * @param string $name The field name
  1065.      * @param string $label The label to apply to the field
  1066.      * @param string $mode The field mode (create/edit/view)
  1067.      * @param array $options The Enum options
  1068.      * @param string $value The field value (optional)
  1069.      * @param bool $tableTags Include table tags and label (optional)
  1070.      * @return string 
  1071.      * @since 1.0
  1072.      */
  1073.     public function renderEnumField($name$label$mode$options$value=''$tableTags=true{
  1074.         self::$logger->debug('>>renderEnumField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  1075.         
  1076.         $html '';
  1077.         
  1078.         if ($mode == 'create'{
  1079.             if ($tableTags{
  1080.                 $html .= '<tr><th style="width:25%;">';
  1081.                 $html .= $label;
  1082.                 $html .= '</th>';
  1083.                 $html .= '<td>';
  1084.                 $html .= '<select name="'.$name.'"/>';            
  1085.                 foreach ($options as $val{
  1086.                     $html .= '<option value="'.$val.'">'.$val.'</option>';
  1087.                 }
  1088.                 $html .= '</select><br>';
  1089.                 $html .= '</td></tr>';
  1090.             }else{
  1091.                 $html .= '<select name="'.$name.'"/>';            
  1092.                 foreach ($options as $val{
  1093.                     $html .= '<option value="'.$val.'">'.$val.'</option>';
  1094.                 }
  1095.                 $html .= '</select>';
  1096.             }
  1097.         }
  1098.         
  1099.         if ($mode == 'edit'{
  1100.             if ($tableTags{
  1101.                 $html .= '<tr><th style="width:25%;">';
  1102.                 $html .= $label;
  1103.                 $html .= '</th>';
  1104.                 $html .= '<td>';
  1105.                 $html .= '<select name="'.$name.'"/>';            
  1106.                 foreach ($options as $val{
  1107.                     if ($value == $val)
  1108.                         $html .= '<option value="'.$val.'" selected>'.$val.'</option>';
  1109.                     else
  1110.                         $html .= '<option value="'.$val.'">'.$val.'</option>';
  1111.                 }
  1112.                 $html .= '</select><br>';
  1113.                 $html .= '</td></tr>';
  1114.             }else{
  1115.                 $html .= '<select name="'.$name.'"/>';            
  1116.                 foreach ($options as $val{
  1117.                     if ($value == $val)
  1118.                         $html .= '<option value="'.$val.'" selected>'.$val.'</option>';
  1119.                     else
  1120.                         $html .= '<option value="'.$val.'">'.$val.'</option>';
  1121.                 }
  1122.                 $html .= '</select>';
  1123.             }
  1124.         }
  1125.                 
  1126.         self::$logger->debug('<<renderEnumField ['.$html.']');
  1127.         return $html;
  1128.     }
  1129.     
  1130.     /**
  1131.      * Method to render the default DEnum HTML
  1132.      *
  1133.      * @param string $name The field name
  1134.      * @param string $label The label to apply to the field
  1135.      * @param string $mode The field mode (create/edit/view)
  1136.      * @param array $options The DEnum options
  1137.      * @param string $value The field value (optional)
  1138.      * @param bool $tableTags Include table tags and label (optional)
  1139.      * @return string 
  1140.      * @since 1.0
  1141.      */
  1142.     public function renderDEnumField($name$label$mode$options$value=''$tableTags=true{
  1143.         self::$logger->debug('>>renderDEnumField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  1144.         
  1145.         $html '';
  1146.         
  1147.         if ($mode == 'create'{
  1148.             if($tableTags{
  1149.                 $html .= '<tr><th style="width:25%;">';
  1150.                 $html .= $label;
  1151.                 $html .= '</th>';
  1152.                 $html .= '<td>';
  1153.                 $html .= '<select name="'.$name.'"/>';
  1154.                 foreach (array_keys($optionsas $index{
  1155.                     $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
  1156.                 }
  1157.                 $html .= '</select><br>';
  1158.                 $html .= '</td></tr>';
  1159.             }else{
  1160.                 $html .= '<select name="'.$name.'"/>';
  1161.                 foreach (array_keys($optionsas $index{
  1162.                     $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
  1163.                 }
  1164.                 $html .= '</select>';
  1165.             }
  1166.         }
  1167.         
  1168.         if ($mode == 'edit'{
  1169.             if($tableTags{
  1170.                 $html .= '<tr><th style="width:25%;">';
  1171.                 $html .= $label;
  1172.                 $html .= '</th>';
  1173.                 $html .= '<td>';
  1174.                 $html .= '<select name="'.$name.'"/>';            
  1175.                 foreach (array_keys($optionsas $index{
  1176.                     if ($value == $index)
  1177.                         $html .= '<option value="'.$index.'" selected>'.$options[$index].'</option>';
  1178.                     else
  1179.                         $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
  1180.                 }
  1181.                 $html .= '</select><br>';
  1182.                 $html .= '</td></tr>';
  1183.             }else{
  1184.                 $html .= '<select name="'.$name.'"/>';            
  1185.                 foreach (array_keys($optionsas $index{
  1186.                     if ($value == $index)
  1187.                         $html .= '<option value="'.$index.'" selected>'.$options[$index].'</option>';
  1188.                     else
  1189.                         $html .= '<option value="'.$index.'">'.$options[$index].'</option>';
  1190.                 }
  1191.                 $html .= '</select>';
  1192.             }
  1193.         }        
  1194.         
  1195.         self::$logger->debug('<<renderDEnumField ['.$html.']');
  1196.         return $html;
  1197.     }
  1198.     
  1199.     /**
  1200.      * Method to render the default field HTML when type is not known
  1201.      *
  1202.      * @param string $name The field name
  1203.      * @param string $label The label to apply to the field
  1204.      * @param string $mode The field mode (create/edit/view)
  1205.      * @param string $value The field value (optional)
  1206.      * @param bool $tableTags Include table tags and label (optional)
  1207.      * @return string 
  1208.      * @since 1.0
  1209.      */
  1210.     public function renderDefaultField($name$label$mode$value=''$tableTags=true{
  1211.         self::$logger->debug('>>renderDefaultField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  1212.         
  1213.         $html '';
  1214.         
  1215.         if ($mode == 'create'{
  1216.             if($tableTags{
  1217.                 $html .= '<tr><th colspan="2">';
  1218.                 $html .= $label;
  1219.                 $html .= '</th></tr>';
  1220.         
  1221.                 $html .= '<tr><td colspan="2">';
  1222.                 $html .= '<textarea cols="100" rows="3" name="'.$name.'">'(isset ($_POST[$name]$_POST[$name'').'</textarea><br>';
  1223.                 $html .= '</td></tr>';
  1224.             }else{
  1225.                 $html .= '<textarea cols="100" rows="3" name="'.$name.'">'(isset ($_POST[$name]$_POST[$name'').'</textarea>';
  1226.             }
  1227.         }
  1228.         
  1229.         if ($mode == 'edit'{
  1230.             if($tableTags{        
  1231.                 $html .= '<tr><th colspan="2">';
  1232.                 $html .= $label;
  1233.                 $html .= '</th></tr>';
  1234.     
  1235.                 $html .= '<tr><td colspan="2">';
  1236.                 $html .= '<textarea cols="100" rows="3" name="'.$name.'">'.$value.'</textarea><br>';
  1237.                 $html .= '</td></tr>';
  1238.             }else{
  1239.                 $html .= '<textarea cols="100" rows="3" name="'.$name.'">'.$value.'</textarea>';
  1240.             }
  1241.         }
  1242.         
  1243.         if ($mode == 'view'{
  1244.             if($tableTags{
  1245.                 $html .= '<tr><th>';
  1246.                 $html .= $label;
  1247.                 $html .= '</th>';
  1248.     
  1249.                 $html .= '<td>&nbsp;';
  1250.                 if(method_exists($this'during_renderDefaultField_callback'))
  1251.                     $html .= $this->during_renderDefaultField_callback($name$mode$value);
  1252.                 else
  1253.                     $html .= $value;
  1254.                 $html .= '</td></tr>';
  1255.             }else{
  1256.                 $html .= $value;
  1257.             }
  1258.         }
  1259.         
  1260.         self::$logger->debug('<<renderDefaultField ['.$html.']');
  1261.         return $html;
  1262.     }
  1263.     
  1264.     /**
  1265.      * render the default Text HTML
  1266.      *
  1267.      * @param string $name The field name
  1268.      * @param string $label The label to apply to the field
  1269.      * @param string $mode The field mode (create/edit/view)
  1270.      * @param string $value The field value (optional)
  1271.      * @param bool $tableTags Include table tags and label (optional)
  1272.      * @return string 
  1273.      * @since 1.0
  1274.      */
  1275.     public function renderTextField($name$label$mode$value=''$tableTags=true{
  1276.         self::$logger->debug('>>renderTextField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'])');
  1277.         
  1278.         $html '';
  1279.         
  1280.         if ($mode == 'create'{
  1281.             // give 10 rows for content fields (other 5 by default)
  1282.             if($name == 'content')
  1283.                 $text new TextBox($this->BO->getPropObject($name)$label$name10);
  1284.             else
  1285.                 $text new TextBox($this->BO->getPropObject($name)$label$name);
  1286.             $html .= $text->render($tableTags);
  1287.         }
  1288.         
  1289.         if ($mode == 'edit'{
  1290.             // give 10 rows for content fields (other 5 by default)
  1291.             if($name == 'content'{
  1292.                 $viewState ViewState::getInstance();
  1293.                 
  1294.                 if($viewState->get('markdownTextBoxRows'== '')
  1295.                     $text new TextBox($this->BO->getPropObject($name)$label$name10);
  1296.                 else
  1297.                     $text new TextBox($this->BO->getPropObject($name)$label$name(integer)$viewState->get('markdownTextBoxRows'));
  1298.                     
  1299.                 $html .= $text->render($tableTagstrue);
  1300.             }else{
  1301.                 $text new TextBox($this->BO->getPropObject($name)$label$name);
  1302.                 $html .= $text->render($tableTags);
  1303.             }
  1304.         }
  1305.         
  1306.         if ($mode == 'view'{
  1307.             $html .= '<tr><th>';
  1308.             $html .= $label;
  1309.             $html .= '</th>';
  1310.  
  1311.             // ensures that line returns are rendered
  1312.             $value str_replace("\n"'<br>'$value);
  1313.             
  1314.             $html .= '<td>&nbsp;';
  1315.             $html .= $value;
  1316.             $html .= '</td></tr>';
  1317.         }
  1318.         
  1319.         self::$logger->debug('<<renderTextField ['.$html.']');
  1320.         return $html;
  1321.     }
  1322.     
  1323.     /**
  1324.      * render the default Relation HTML
  1325.      *
  1326.      * @param string $name The field name
  1327.      * @param string $label The label to apply to the field
  1328.      * @param string $mode The field mode (create/edit/view)
  1329.      * @param string $value The field value (optional)
  1330.      * @param bool $tableTags Include table tags and label (optional)
  1331.      * @param bool $expanded Render the related fields in expanded format or not (optional)
  1332.      * @param bool $buttons Render buttons for expanding/contacting the related fields (optional)
  1333.      * @return string 
  1334.      * @since 1.0
  1335.      */
  1336.     public function renderRelationField($name$label$mode$value=''$tableTags=true$expanded=false$buttons=true{
  1337.         self::$logger->debug('>>renderRelationField(name=['.$name.'], label=['.$label.'], mode=['.$mode.'], value=['.$value.'], tableTags=['.$tableTags.'], expanded=['.$expanded.'], buttons=['.$buttons.'])');
  1338.         
  1339.         $html '';
  1340.         
  1341.         $rel $this->BO->getPropObject($name);
  1342.         
  1343.         if ($mode == 'create' || $mode == 'edit'{
  1344.             if($rel->getRelationType(== 'MANY-TO-MANY'{
  1345.                 try{
  1346.                     // check to see if the rel is on this class
  1347.                     $rel->getSide(get_class($this->BO));
  1348.                     $widget new RecordSelector($rel$label$nameget_class($this->BO));
  1349.                     $html .= $widget->render($tableTags$expanded$buttons);
  1350.                 }catch (IllegalArguementException $iae{
  1351.                     // the rel may be on a parent class
  1352.                     $parentClassName ucfirst($this->BO->getTableName()).'Object';
  1353.                     $widget new RecordSelector($rel$label$name$parentClassName);
  1354.                     $html .= $widget->render($tableTags$expanded$buttons);
  1355.                 }
  1356.             }else{
  1357.                 $rel new RecordSelector($rel$label$name);
  1358.                 $html .= $rel->render($tableTags$expanded$buttons);
  1359.             }
  1360.         }
  1361.         
  1362.         if ($mode == 'view'{
  1363.             if($rel->getRelationType(== 'MANY-TO-ONE'{
  1364.                 $html .= $this->renderDefaultField($name$label'view'$rel->getRelatedClassDisplayFieldValue());
  1365.             }elseif($rel->getRelationType(== 'MANY-TO-MANY'{
  1366.                 try{
  1367.                     // check to see if the rel is on this class
  1368.                     $rel->getSide(get_class($this->BO));
  1369.                     $html .= $this->renderDefaultField($name$label'view'$rel->getRelatedClassDisplayFieldValue(get_class($this->BO)));
  1370.                 }catch (IllegalArguementException $iae{
  1371.                     // the rel may be on a parent class
  1372.                     $parentClassName ucfirst($this->BO->getTableName()).'Object';
  1373.                     $html .= $this->renderDefaultField($name$label'view'$rel->getRelatedClassDisplayFieldValue($parentClassName));
  1374.                 }
  1375.             }else{
  1376.                 $rel new RecordSelector($rel$label$name);
  1377.                 $html .= $rel->render($tableTags$expanded$buttons);
  1378.             }
  1379.         }
  1380.         
  1381.         self::$logger->debug('<<renderRelationField ['.$html.']');
  1382.         return $html;
  1383.     }
  1384.     
  1385.     /**
  1386.      * Renders all fields for the current BO in edit/create/view mode
  1387.      *
  1388.      * @param string $mode (view|edit|create)
  1389.      * @param array $filterFields Optional list of field names to exclude from rendering
  1390.      * @param array $readOnlyFields Optional list of fields to render in a readonly fashion when rendering in create or edit mode
  1391.      * @return string 
  1392.      * @since 1.0
  1393.      */
  1394.     public function renderAllFields($mode$filterFields=array()$readOnlyFields=array()) {
  1395.         self::$logger->debug('>>renderAllFields(mode=['.$mode.'], filterFields=['.var_export($filterFieldstrue).'], readOnlyFields=['.var_export($readOnlyFieldstrue).'])');
  1396.         
  1397.         $html '';
  1398.                 
  1399.         // get the class attributes        
  1400.         $properties array_keys($this->BO->getDataLabels());
  1401.         
  1402.         $orignalMode $mode;
  1403.         
  1404.         foreach($properties as $propName{            
  1405.             if (!in_array($propName$this->BO->getDefaultAttributes()) && !in_array($propName$filterFields)) {
  1406.                 // render readonly fields in the supplied array
  1407.                 if(in_array($propName$readOnlyFields))
  1408.                     $mode 'view';
  1409.                 else
  1410.                     $mode $orignalMode;
  1411.                     
  1412.                 $propClass get_class($this->BO->getPropObject($propName));
  1413.                 
  1414.                 // exclude non-Relation transient attributes from create and edit screens
  1415.                 if($propClass != 'Relation' && ($mode == 'edit' || $mode == 'create'&& in_array($propName$this->BO->getTransientAttributes())) {
  1416.                     continue;
  1417.                 }
  1418.                 
  1419.                 switch (strtoupper($propClass)) {
  1420.                     case 'INTEGER' :
  1421.                         if($mode == 'view'{
  1422.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$this->BO->get($propName));
  1423.                         }else{
  1424.                             $html .= $this->renderIntegerField($propName$this->BO->getDataLabel($propName)$mode$this->BO->get($propName));
  1425.                         }                
  1426.                     break;
  1427.                     case 'DOUBLE' :
  1428.                         if($mode == 'view'{
  1429.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$this->BO->get($propName));
  1430.                         }else{
  1431.                             $html .= $this->renderDoubleField($propName$this->BO->getDataLabel($propName)$mode$this->BO->get($propName));
  1432.                         }
  1433.                     break;
  1434.                     case 'DATE' :
  1435.                         if($mode == 'view'{
  1436.                             $value $this->BO->get($propName);
  1437.                             if ($value == '0000-00-00')
  1438.                                 $value '';
  1439.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$value);
  1440.                         }else{
  1441.                             $date new DateBox($this->BO->getPropObject($propName)$this->BO->getDataLabel($propName)$propName);
  1442.                             $html .= $date->render();
  1443.                         }
  1444.                     break;
  1445.                     case 'TIMESTAMP' :
  1446.                         if($mode == 'view'{
  1447.                             $value $this->BO->get($propName);
  1448.                             if ($value == '0000-00-00 00:00:00')
  1449.                                 $value '';
  1450.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$value);
  1451.                         }else{
  1452.                             $timestamp new DateBox($this->BO->getPropObject($propName)$this->BO->getDataLabel($propName)$propName);
  1453.                             $html .= $timestamp->render();
  1454.                         }
  1455.                     break;
  1456.                     case 'STRING' :
  1457.                         if($mode == 'view'{
  1458.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$this->BO->get($propName));
  1459.                         }else{
  1460.                             $string new StringBox($this->BO->getPropObject($propName)$this->BO->getDataLabel($propName)$propName);
  1461.                             $html .= $string->render();
  1462.                         }
  1463.                     break;
  1464.                     case 'TEXT' :
  1465.                         $html .= $this->renderTextField($propName$this->BO->getDataLabel($propName)$mode$this->BO->get($propName));
  1466.                     break;
  1467.                     case 'BOOLEAN' :
  1468.                         if($mode == 'view'{
  1469.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$this->BO->get($propName));
  1470.                         }else{
  1471.                             $html .= $this->renderBooleanField($propName$this->BO->getDataLabel($propName)$mode$this->BO->get($propName));
  1472.                         }
  1473.                     break;
  1474.                     case 'ENUM' :
  1475.                         if($mode == 'view'{
  1476.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$this->BO->get($propName));
  1477.                         }else{
  1478.                             $enum $this->BO->getPropObject($propName);
  1479.                             $html .= $this->renderEnumField($propName$this->BO->getDataLabel($propName)$mode$enum->getOptions()$this->BO->get($propName));
  1480.                         }
  1481.                     break;
  1482.                     case 'DENUM' :
  1483.                         if($mode == 'view'{
  1484.                             $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)'view'$this->BO->getPropObject($propName)->getDisplayValue());
  1485.                         }else{
  1486.                             $denum $this->BO->getPropObject($propName);
  1487.                             $html .= $this->renderDEnumField($propName$this->BO->getDataLabel($propName)$mode$denum->getOptions()$this->BO->get($propName));
  1488.                         }
  1489.                     break;
  1490.                     case 'RELATION' :
  1491.                         $html .= $this->renderRelationField($propName$this->BO->getDataLabel($propName)$mode$this->BO->get($propName));
  1492.                     break;
  1493.                     default :
  1494.                         $html .= $this->renderDefaultField($propName$this->BO->getDataLabel($propName)$mode$this->BO->get($propName));
  1495.                     break;
  1496.                 }
  1497.             }
  1498.         }
  1499.         
  1500.         self::$logger->debug('<<renderAllFields ['.$html.']');
  1501.         return $html;
  1502.     }
  1503.     
  1504.     /**
  1505.      * Loads a .phtml template for the BO specified if one exists.  Lower level custom templates
  1506.      * take precedence.
  1507.      * 
  1508.      * @param AlphaDAO $BO 
  1509.      * @param string $mode 
  1510.      * @param array $fields 
  1511.      * @since 1.0
  1512.      * @throws IllegalArguementException
  1513.      */
  1514.     public function loadTemplate($BO$mode$fields{
  1515.         self::$logger->debug('>>loadTemplate(BO=['.var_export($BOtrue).'], mode=['.$mode.'], fields=['.var_export($fieldstrue).'])');
  1516.         
  1517.         global $config;
  1518.         
  1519.         // for each BO property, create a local variable holding its value        
  1520.         $reflection new ReflectionClass(get_class($this->BO));
  1521.         $properties $reflection->getProperties();
  1522.         
  1523.         foreach($properties as $propObj{
  1524.             $propName $propObj->name;
  1525.             
  1526.             if($propName != 'logger' && !$propObj->isPrivate()) {
  1527.                 if(get_class($BO->getPropObject($propName)) == 'DEnum'{                    
  1528.                     ${$propName$BO->getPropObject($propName)->getDisplayValue();
  1529.                 }else{
  1530.                     ${$propName$BO->get($propName);
  1531.                 }
  1532.             }
  1533.         }
  1534.         
  1535.         // loop over the $fields array and create a local variable for each key value
  1536.         foreach (array_keys($fieldsas $fieldName)
  1537.             ${$fieldName$fields[$fieldName];
  1538.             
  1539.         $filename $mode.'.phtml';
  1540.         $classTemplateDir get_class($BO);
  1541.  
  1542.         $customPath $config->get('sysRoot').'view/templates/'.$classTemplateDir.'/'.$filename;
  1543.         $defaultPath1 $config->get('sysRoot').'alpha/view/templates/'.$classTemplateDir.'/'.$filename;
  1544.         $defaultPath2 $config->get('sysRoot').'alpha/view/templates/'.$filename;
  1545.  
  1546.         // Check to see if a custom template exists for this BO, and if it does load that        
  1547.         if (file_exists($customPath)) {
  1548.             self::$logger->debug('Loading template ['.$customPath.']');
  1549.             require $customPath;                
  1550.         }elseif (file_exists($defaultPath1)) {
  1551.             self::$logger->debug('Loading template ['.$defaultPath1.']');
  1552.             require $defaultPath1;
  1553.         }elseif (file_exists($defaultPath2)) {
  1554.             self::$logger->debug('Loading template ['.$defaultPath2.']');
  1555.             require $defaultPath2;    
  1556.         }else{
  1557.             throw new IllegalArguementException('No ['.$mode.'] HTML template found for class ['.get_class($BO).']');
  1558.         }
  1559.         
  1560.         self::$logger->debug('<<loadTemplate');
  1561.     }
  1562. }
  1563. ?>

Documentation generated on Thu, 17 Mar 2011 16:43:47 +0000 by phpDocumentor 1.4.3