      1: <?php
      2:
      3: /**
      4:  *
      5:  * The rendering class for the DEnum class
      6:  *
      7:  * @package alpha::view
      8:  * @since 1.0
      9:  * @author John Collins <dev@alphaframework.org>
     10:  * @version $Id: DEnumView.inc 1673 2013-10-19 12:36:29Z alphadevx $
     11:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
     12:  * @copyright Copyright (c) 2012, John Collins (founder of Alpha Framework).
     13:  * All rights reserved.
     14:  *
     15:  * <pre>
     16:  * Redistribution and use in source and binary forms, with or
     17:  * without modification, are permitted provided that the
     18:  * following conditions are met:
     19:  *
     20:  * * Redistributions of source code must retain the above
     21:  *   copyright notice, this list of conditions and the
     22:  *   following disclaimer.
     23:  * * Redistributions in binary form must reproduce the above
     24:  *   copyright notice, this list of conditions and the
     25:  *   following disclaimer in the documentation and/or other
     26:  *   materials provided with the distribution.
     27:  * * Neither the name of the Alpha Framework nor the names
     28:  *   of its contributors may be used to endorse or promote
     29:  *   products derived from this software without specific
     30:  *   prior written permission.
     31:  *
     32:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
     33:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
     34:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     35:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     36:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
     37:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     38:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     39:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     40:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     41:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     42:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     43:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     44:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     45:  * </pre>
     46:  *
     47:  */
     48: class DEnumView extends AlphaView {
     49:     /**
     50:      * Custom list view
     51:      *
     52:      * @return string
     53:      * @since 1.0
     54:      */
     55:     public function listView() {
     56:         global $config;
     57:
     58:         $reflection = new ReflectionClass(get_class($this->BO));
     59:         $properties = $reflection->getProperties();
     60:         $labels = $this->BO->getDataLabels();
     61:         $colCount = 1;
     62:
     63:         $html = '<table class="list_view">';
     64:         $html .= '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST">';
     65:         // first render all of the table headers
     66:         $html .= '<tr>';
     67:         foreach($properties as $propObj) {
     68:             $prop = $propObj->name;
     69:             if (!in_array($prop, $this->BO->getDefaultAttributes()) && !in_array($prop, $this->BO->getTransientAttributes())) {
     70:                 if (get_class($this->BO->getPropObject($prop)) != 'Text') {
     71:                     $colCount ++;
     72:                     $html .= '  <th>'.$labels[$prop].'</th>';
     73:                 }
     74:             }
     75:             if ($prop == 'OID')
     76:                 $html .= '  <th>'.$labels[$prop].'</th>';
     77:         }
     78:         // render the count
     79:         $html .= '  <th>Item count</th>';
     80:
     81:         $html .= '</tr><tr>';
     82:
     83:         // and now the values
     84:         foreach($properties as $propObj) {
     85:             $prop = $propObj->name;
     86:             if (!in_array($prop, $this->BO->getDefaultAttributes()) && !in_array($prop, $this->BO->getTransientAttributes())) {
     87:                 if (get_class($this->BO->getPropObject($prop)) != 'Text') {
     88:                     $html .= '  <td>&nbsp;'.$this->BO->get($prop).'</td>';
     89:                 }
     90:             }
     91:             if ($prop == 'OID')
     92:                 $html .= '  <td>&nbsp;'.$this->BO->getID().'</td>';
     93:         }
     94:         // render the count
     95:         $html .= '  <td>&nbsp;'.$this->BO->getItemCount().'</td>';
     96:
     97:         $html .= '</tr>';
     98:
     99:         $html .= '<tr><td colspan="'.($colCount+1).'" align="center">';
    100:         // render edit buttons for admins only
    101:         if (isset($_SESSION['currentUser']) && $_SESSION['currentUser']->inGroup('Admin')) {
    102:             $html .= '&nbsp;&nbsp;';
    103:             $button = new Button("document.location = '".FrontController::generateSecureURL('act=EditDEnum&oid='.$this->BO->getOID())."'", "Edit", "edit".$this->BO->getOID()."But");
    104:             $html .= $button->render();
    105:         }
    106:         $html .= '</td></tr>';
    107:
    108:         $html .= '</form>';
    109:         $html .= '</table>';
    110:
    111:         return $html;
    112:     }
    113:
    114:     /**
    115:      * Custom edit view
    116:      *
    117:      * @return string
    118:      * @since 1.0
    119:      */
    120:     public function editView() {
    121:         global $config;
    122:
    123:         $labels = $this->BO->getDataLabels();
    124:         $obj_type = '';
    125:
    126:         $html = '<table cols="2" class="edit_view">';
    127:         $html .= '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST">';
    128:
    129:         $temp = new StringBox($this->BO->getPropObject('name'), $labels['name'], 'name', '', 0, true, true);
    130:         $html .= $temp->render();
    131:
    132:         $html .= '<tr><td colspan="2"><h3>DEnum display values:</h3></td></tr>';
    133:
    134:         // now get all of the options for the enum and render
    135:         $denum = $this->BO;
    136:         $tmp = new DEnumItem();
    137:         $denumItems = $tmp->loadItems($denum->getID());
    138:
    139:         foreach ($denumItems as $item) {
    140:             $labels = $item->getDataLabels();
    141:             $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('value_'.$item->getID())) : 'value_'.$item->getID());
    142:             $temp = new StringBox($item->getPropObject('value'), $labels['value'], $fieldname, '');
    143:             $html .= $temp->render();
    144:         }
    145:
    146:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('version_num')) : 'version_num');
    147:
    148:         $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->BO->getVersion().'"/>';
    149:
    150:         $html .= '<tr><td colspan="2"><h3>Add a new value to the DEnum dropdown list:</h3></td></tr>';
    151:
    152:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('new_value')) : 'new_value');
    153:         $temp = new StringBox(new String(), 'Dropdown value', $fieldname, '');
    154:         $html .= $temp->render();
    155:
    156:         $html .= '<tr><td colspan="2">';
    157:
    158:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('saveBut')) : 'saveBut');
    159:         $temp = new Button('submit', 'Save', $fieldname);
    160:         $html .= $temp->render();
    161:         $html .= '&nbsp;&nbsp;';
    162:         $temp = new Button("document.location = '".FrontController::generateSecureURL('act=ListDEnums')."'", 'Back to List', 'cancelBut');
    163:         $html .= $temp->render();
    164:         $html .= '</td></tr>';
    165:
    166:         $html .= AlphaView::renderSecurityFields();
    167:
    168:         $html .= '</form></table>';
    169:
    170:         return $html;
    171:     }
    172: }
    173:
    174: ?>