Annotation of FreeBSD/tinderbox/webui/module/moduleConfig.php, revision 1.1.1.1.2.2

1.1       as          1: <?php
                      2: #-
                      3: # Copyright (c) 2005 Oliver Lehmann <oliver@FreeBSD.org>
                      4: # All rights reserved.
                      5: #
                      6: # Redistribution and use in source and binary forms, with or without
                      7: # modification, are permitted provided that the following conditions
                      8: # are met:
                      9: # 1. Redistributions of source code must retain the above copyright
                     10: #      notice, this list of conditions and the following disclaimer
                     11: # 2. Redistributions in binary form must reproduce the above copyright
                     12: #      notice, this list of conditions and the following disclaimer in the
                     13: #      documentation and/or other materials provided with the distribution.
                     14: #
                     15: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     16: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     17: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     18: # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     19: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     20: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     21: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     22: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     23: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     24: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     25: # SUCH DAMAGE.
                     26: #
1.1.1.1.2.2! as         27: # $Paefchen: FreeBSD/tinderbox/webui/module/moduleConfig.php,v 1.1.1.1.2.1 2007/11/13 07:36:19 as Exp $
1.1       as         28: # $MCom: portstools/tinderbox/webui/module/moduleConfig.php,v 1.4 2007/10/13 02:28:47 ade Exp $
                     29: #
                     30: 
                     31: class moduleConfig extends module {
1.1.1.1.2.1  as         32:        private $moduleUsers = null;
1.1       as         33: 
1.1.1.1.2.2! as         34:        public function __construct() {
1.1.1.1.2.1  as         35:                parent::__construct();
                     36:                $this->moduleUsers = new moduleUsers;
1.1       as         37:        }
                     38: 
1.1.1.1.2.1  as         39:        private function _array_sort_and_assign( $sort_me, $tpl_key ) {
1.1       as         40:                if( is_array( $sort_me ) && count( $sort_me ) > 0 ) {
                     41:                        foreach( $sort_me as $res )
                     42:                                $sort[] = $res[$tpl_key.'_name'];
                     43:                        array_multisort( $sort, SORT_ASC, $sort_me );
                     44:                        $this->template_assign( $tpl_key.'_data',    $sort_me );
                     45:                        $this->template_assign( 'no_'.$tpl_key.'_list', false );
                     46:                } else {
                     47:                        $this->template_assign( 'no_'.$tpl_key.'_list', true );
                     48:                }
                     49:        }
                     50: 
1.1.1.1.2.1  as         51:        public function display_config() {
1.1       as         52:               if( !$this->moduleUsers->is_logged_in() ) {
                     53:                       return $this->template_parse( 'please_login.tpl' );
                     54:               } else if( ! $this->moduleUsers->checkWwwAdmin() ) {
                     55:                       $this->TinderboxDS->addError( permission_denied );
                     56:                       return $this->template_parse( 'config.tpl' );
                     57:               }
                     58:                $builds          = $this->TinderboxDS->getAllBuilds();
                     59:                $jails           = $this->TinderboxDS->getAllJails();
                     60:                $ports_trees     = $this->TinderboxDS->getAllPortsTrees();
                     61:                $config_options  = $this->TinderboxDS->getAllConfig();
                     62: 
                     63:                foreach( $jails as $jail ) {
                     64:                        $jail_id = $jail->getId();
                     65:                        $all_jails[$jail_id] = array( 'jail_name'        => $jail->getName(),
                     66:                                                       'jail_arch'        => $jail->getArch(),
                     67:                                                      'jail_tag'         => $jail->getTag(),
                     68:                                                      'jail_last_built'  => prettyDatetime($jail->getLastBuilt()),
                     69:                                                      'jail_update_cmd'  => $jail->getUpdateCmd(),
                     70:                                                      'jail_description' => $jail->getDescription(),
                     71:                                                      'jail_src_mount'   => $jail->getSrcMount() );
1.1.1.1.2.1  as         72:                }
1.1       as         73: 
                     74:                foreach( $ports_trees as $ports_tree ) {
                     75:                        $ports_tree_id = $ports_tree->getId();
                     76:                        $all_ports_trees[$ports_tree_id] = array( 'ports_tree_name'        => $ports_tree->getName(),
                     77:                                                                  'ports_tree_last_built'  => prettyDatetime( $ports_tree->getLastBuilt() ),
                     78:                                                                  'ports_tree_update_cmd'  => $ports_tree->getUpdateCmd(),
                     79:                                                                  'ports_tree_description' => $ports_tree->getDescription(),
                     80:                                                                  'ports_tree_cvsweb_url'  => $ports_tree->getCVSwebURL(),
                     81:                                                                  'ports_tree_ports_mount' => $ports_tree->getPortsMount() );
1.1.1.1.2.1  as         82:                }
1.1       as         83: 
                     84:                foreach( $builds as $build ) {
                     85:                        $build_id = $build->getId();
                     86:                        $all_builds[$build_id] = array( 'build_name'        => $build->getName(),
                     87:                                                        'build_description' => $build->getDescription(),
                     88:                                                        'jail_name'         => $all_jails[$build->getJailId()]['jail_name'],
                     89:                                                        'ports_tree_name'   => $all_ports_trees[$build->getPortsTreeId()]['ports_tree_name'] );
1.1.1.1.2.1  as         90:                }
1.1       as         91: 
                     92:                foreach( $config_options as $config_option ) {
                     93:                        $all_config_options[] = array( 'config_option_name'  => $config_option->getName(),
                     94:                                                       'config_option_value' => $config_option->getValue() );
1.1.1.1.2.1  as         95:                }
1.1       as         96: 
                     97:                $this->_array_sort_and_assign( $all_jails,          'jail'          );
                     98:                $this->_array_sort_and_assign( $all_ports_trees,    'ports_tree'    );
                     99:                $this->_array_sort_and_assign( $all_builds,         'build'         );
                    100:                $this->_array_sort_and_assign( $all_config_options, 'config_option' );
                    101: 
                    102:                return $this->template_parse( 'config.tpl' );
                    103:        }
                    104: }
1.1.1.1.2.1  as        105: 
1.1       as        106: ?>