Show
Ignore:
Timestamp:
07/12/07 16:05:42 (6 years ago)
Author:
benoitg
Message:

-This is a behemoth "the road to 1.0" commit. I've been working on this for 6 months,
and it's reached the point where others can help. Those are very far reaching changes, please
notify me if anything isn't working right (and im sure I can't have caught everything).

Mostly complete. Missing parts are Content stakeholders, system roles and "su" functionnality.
I need help replacing all the DEPRECATED* methods. Please read the wiki page above for instructions.

  • generic_object_admin.php: More work towards making it generic once again.
  • GenericDataObject?: New class. Eventually, most classes should extend this, instead of directly implementing GenericObject?
  • Menu.php: Finally a uniform Menuing system to replace the mismatch of links that made wifidog impossible to navigate. It's not very sophisticated yet, but it IS permission aware Loosely inspired from Drupal's menuing system. HTML is slightly modified "Son of suckerfish", so will be easy to style (althouh I haven't had time yet). Actual menus are added in the hook_menu methods of each class.
  • VirtualHost.php: Finally properly split off Virtual Hosts, and make Server a singleton.
  • install.php: Do the bare minimum changes so it's still possible to setup a wifidog auth server. However, install.php still needs 1- A good overhaull, 2- A way to install sample databases instead of the minimal one. -Other changes
  • Unbreak signup link for non-javascript enabled devices
  • AbstractDb?: Improve debuging features
  • *:getObject(): Hopefully improve performance of class caching by making sure that we do not manipulate different objects. Otherwise copies would be generated as soon as we change properties, wasting much memory.
    • Add dependency check for XSL module for hotspot_status.php.
    • Some work towards respecting the coding style: http://dev.wifidog.org/wiki/doc/developer/CodingStandard
    • wifidog/admin/index.php: Delete admin page. There is no longuer a concept of a separate admin section. Menu will depend on your access level.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/wifidog/classes/ProfileTemplate.php

    r1194 r1249  
    4343 * @link       http://www.wifidog.org/ 
    4444 */ 
    45   
     45 
    4646require_once ('classes/ProfileTemplateField.php'); 
    4747require_once ('classes/ContentTypeFilter.php'); 
     
    5252     
    5353    private $id = null; 
    54     private $mRow; 
     54    private $_row; 
    5555     
    5656    private function __construct($profile_template_id) 
     
    6969                } 
    7070 
    71                 $this->mRow = $row; 
     71                $this->_row = $row; 
    7272                $this->id = $db->escapeString($row['profile_template_id']); 
    7373        } 
     
    8585     * @access public 
    8686     */ 
    87     public static function getObject($id) 
     87    public static function &getObject($id) 
    8888    { 
    8989        if(!isset(self::$instanceArray[$id])) 
     
    141141    public function getLabel() 
    142142    { 
    143         return $this->mRow['profile_template_label']; 
     143        return $this->_row['profile_template_label']; 
    144144    } 
    145145 
     
    177177    public function getCreationDate() 
    178178    { 
    179         return $this->mRow['creation_date']; 
     179        return $this->_row['creation_date']; 
    180180    } 
    181181 
     
    251251         
    252252        /** 
    253          * Get an interface to pick a ContentTypeFilter 
     253         * Get an interface to pick an object of this class 
    254254         * 
    255255         * If there is only one server available, no interface is actually shown 
     
    258258     *                                    programmer to recognise it's generated 
    259259     *                                    html form 
    260      * @param object $pre_content_type_filter An optional ContenTypeFilter object 
    261      *  
    262      * @param string $additional_where    Additional SQL conditions for the 
    263      *                                    servers to select 
    264      * 
     260     *  @param string $userData=null Array of contextual data optionally sent to the method. 
     261     *  The function must still function if none of it is present. 
     262     * 
     263     * This method understands: 
     264     *  $userData['preSelectedId'] An optional ProfileTemplate object id. 
     265     *  $userData['additionalWhere'] Additional SQL conditions for the 
     266     *                                    objects to select 
     267     *  $userData['typeInterface'] 'select' or 'add'.  'select' is the default 
    265268     * @return string HTML markup 
    266269 
    267270     */ 
    268     public static function getSelectProfileTemplateUI($user_prefix, $pre_selected_profile_template = null, $additional_where = null, $type_interface = "select") 
     271    public static function getSelectUI($user_prefix, $userData=null) 
    269272    {  
    270273                $db = AbstractDb::getObject(); 
     
    274277                $_profile_template_rows = null; 
    275278                 
    276                 if ($pre_selected_profile_template) { 
    277                         $_selectedId = $pre_selected_profile_template->getId(); 
    278                 } else { 
    279                         $_selectedId = null; 
    280                 } 
    281  
    282                 $_sql = "SELECT * FROM profile_templates WHERE 1=1 $additional_where ORDER BY profile_template_label ASC"; 
    283                 $db->execSql($_sql, $_profile_template_rows, false); 
     279                !empty($userData['preSelectedId'])?$selectedId=$userData['preSelectedId']:$selectedId=null; 
     280                !empty($userData['additionalWhere'])?$additional_where=$userData['additionalWhere']:$additional_where=null; 
     281                !empty($userData['typeInterface'])?$type_interface=$userData['typeInterface']:$type_interface=null; 
     282                 
     283                $sql = "SELECT * FROM profile_templates WHERE 1=1 $additional_where ORDER BY profile_template_label ASC"; 
     284                $db->execSql($sql, $_profile_template_rows, false); 
    284285 
    285286                if ($_profile_template_rows != null) { 
     
    295296                        } 
    296297 
    297                         $_html .= FormSelectGenerator::generateFromArray($_tab, $_selectedId, $_name, null, false); 
     298                        $_html .= FormSelectGenerator::generateFromArray($_tab, $selectedId, $_name, null, false); 
    298299                         
    299300                        if ($type_interface == "add") { 
     
    377378        $html .= "<td colspan ='2'>\n"; 
    378379        $name = "{$user_prefix}_new_existing"; 
    379         $profileTemplateSelector = self :: getSelectProfileTemplateUI($name, null, "AND profile_template_id NOT IN (SELECT profile_template_id FROM $link_table WHERE $link_table_obj_key_col='$link_table_obj_key')", "add"); 
     380        $profileTemplateSelector = self :: getSelectUI($name, Array('additionalWhere' => "AND profile_template_id NOT IN (SELECT profile_template_id FROM $link_table WHERE $link_table_obj_key_col='$link_table_obj_key')", 'typeInterface' => "add")); 
    380381        $html .= $profileTemplateSelector; 
    381382        $html .= "</td>\n"; 
     
    448449        public function getAdminUI() 
    449450        { 
     451            Security::requirePermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer()); 
    450452            $db = AbstractDb::getObject(); 
    451453            $sql = "SELECT COUNT(*) as num_used_profiles FROM profile_templates JOIN profiles USING (profile_template_id) WHERE profile_template_id = '" . $this->getId() . "'"; 
     
    453455              
    454456            // Init values 
    455                 $_html = ''; 
    456  
    457                 $_html .= "<fieldset class='admin_container ".get_class($this)."'>\n"; 
    458                 $_html .= "<legend>"._("Profile template management")."</legend>\n"; 
    459         $_html .= "<ul class='admin_element_list'>\n"; 
     457                $html = ''; 
     458 
     459                $html .= "<fieldset class='admin_container ".get_class($this)."'>\n"; 
     460                $html .= "<legend>"._("Profile template management")."</legend>\n"; 
     461        $html .= "<ul class='admin_element_list'>\n"; 
    460462         
    461463                // profile_template_id 
    462464                $_value = htmlspecialchars($this->getId(), ENT_QUOTES); 
    463465 
    464                 $_html .= "<li class='admin_element_item_container'>\n"; 
    465                 $_html .= "<div class='admin_element_label'>" . _("ProfileTemplate ID") . ":</div>\n"; 
    466                 $_html .= "<div class='admin_element_data'>\n"; 
    467                 $_html .= $_value; 
    468                 $_html .= "</div>\n"; 
    469                 $_html .= "</li>\n"; 
     466                $html .= "<li class='admin_element_item_container'>\n"; 
     467                $html .= "<div class='admin_element_label'>" . _("ProfileTemplate ID") . ":</div>\n"; 
     468                $html .= "<div class='admin_element_data'>\n"; 
     469                $html .= $_value; 
     470                $html .= "</div>\n"; 
     471                $html .= "</li>\n"; 
    470472 
    471473                // label 
     
    473475                $_value = htmlspecialchars($this->getLabel(), ENT_QUOTES); 
    474476 
    475                 $_html .= "<li class='admin_element_item_container'>\n"; 
    476                 $_html .= "<div class='admin_element_label'>" . _("Label") . ":</div>\n"; 
    477                 $_html .= "<div class='admin_element_data'>\n"; 
    478                 $_html .= "<input type='text' size='50' value='$_value' name='$_name'>\n"; 
    479                 $_html .= "</div>\n"; 
    480                 $_html .= "</li>\n"; 
     477                $html .= "<li class='admin_element_item_container'>\n"; 
     478                $html .= "<div class='admin_element_label'>" . _("Label") . ":</div>\n"; 
     479                $html .= "<div class='admin_element_data'>\n"; 
     480                $html .= "<input type='text' size='50' value='$_value' name='$_name'>\n"; 
     481                $html .= "</div>\n"; 
     482                $html .= "</li>\n"; 
    481483 
    482484                // creation date 
    483485                $_value = htmlspecialchars($this->getCreationDate(), ENT_QUOTES); 
    484486 
    485                 $_html .= "<li class='admin_element_item_container'>\n"; 
    486                 $_html .= "<div class='admin_element_label'>" . _("Creation date") . ":</div>\n"; 
    487                 $_html .= "<div class='admin_element_data'>\n"; 
    488                 $_html .= $_value; 
    489                 $_html .= "</div>\n"; 
    490                 $_html .= "</li>\n"; 
     487                $html .= "<li class='admin_element_item_container'>\n"; 
     488                $html .= "<div class='admin_element_label'>" . _("Creation date") . ":</div>\n"; 
     489                $html .= "<div class='admin_element_data'>\n"; 
     490                $html .= $_value; 
     491                $html .= "</div>\n"; 
     492                $html .= "</li>\n"; 
    491493 
    492494                // profile template fields 
    493                 $_html .= "<li class='admin_element_item_container'>\n"; 
    494         $_html .= "<fieldset class='admin_element_group'>\n"; 
    495         $_html .= "<legend>"._("Profile template fields")."</legend>\n"; 
    496          
    497         $_html .= "<ul class='admin_element_list'>\n"; 
     495                $html .= "<li class='admin_element_item_container'>\n"; 
     496        $html .= "<fieldset class='admin_element_group'>\n"; 
     497        $html .= "<legend>"._("Profile template fields")."</legend>\n"; 
     498         
     499        $html .= "<ul class='admin_element_list'>\n"; 
    498500        foreach ($this->getFields() as $field) { 
    499             $_html .= "<li class='admin_element_item_container'>\n"; 
    500             $_html .= $field->getAdminUI(null, sprintf(_("%s %d"), get_class($field), $field->getDisplayOrder())); 
    501             $_html .= "<div class='admin_element_tools'>\n"; 
     501            $html .= "<li class='admin_element_item_container'>\n"; 
     502            $html .= $field->getAdminUI(null, sprintf(_("%s %d"), get_class($field), $field->getDisplayOrder())); 
     503            $html .= "<div class='admin_element_tools'>\n"; 
    502504            $sql = "SELECT COUNT(*) as num_used_fields FROM profile_template_fields JOIN profile_fields USING (profile_template_field_id) WHERE profile_template_field_id = '" . $field->getId() . "'"; 
    503505            $db->execSqlUniqueRes($sql, $num_used_fields_row, false); 
    504506            $name = "profile_template_" . $this->id . "_field_" . $field->GetId() . "_erase"; 
    505             $_html .= "<input type='submit' class='submit' name='$name' value='" . sprintf(_("Delete %s %d, used in %d/%d profiles"), get_class($field), $field->getDisplayOrder(), $num_used_fields_row['num_used_fields'], $num_used_profiles['num_used_profiles']) . "'>"; 
    506             $_html .= "</div>\n"; 
    507             $_html .= "</li>\n"; 
    508         } 
    509         $_html .= "<li class='admin_element_item_container'>\n"; 
    510         $_html .= ProfileTemplateField :: getCreateFieldUI("profile_template_{$this->id}_new_field"); 
    511         $_html .= "</li>\n"; 
    512         $_html .= "</ul>\n"; 
    513         $_html .= "</fieldset>\n"; 
    514         $_html .= "</li>\n"; 
    515          
    516         $_html .= "</ul>\n"; 
    517         $_html .= "</fieldset>\n"; 
    518                 return $_html; 
     507            $html .= "<input type='submit' class='submit' name='$name' value='" . sprintf(_("Delete %s %d, used in %d/%d profiles"), get_class($field), $field->getDisplayOrder(), $num_used_fields_row['num_used_fields'], $num_used_profiles['num_used_profiles']) . "'>"; 
     508            $html .= "</div>\n"; 
     509            $html .= "</li>\n"; 
     510        } 
     511        $html .= "<li class='admin_element_item_container'>\n"; 
     512        $html .= ProfileTemplateField :: getCreateFieldUI("profile_template_{$this->id}_new_field"); 
     513        $html .= "</li>\n"; 
     514        $html .= "</ul>\n"; 
     515        $html .= "</fieldset>\n"; 
     516        $html .= "</li>\n"; 
     517         
     518        $html .= "</ul>\n"; 
     519        $html .= "</fieldset>\n"; 
     520                return $html; 
    519521        } 
    520522 
     
    526528        public function processAdminUI() 
    527529        { 
     530                    Security::requirePermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer()); 
    528531        require_once('classes/User.php'); 
    529  
    530         try { 
    531                 if (!User::getCurrentUser()->isSuperAdmin()) { 
    532                         throw new Exception(_('Access denied!')); 
    533                 } 
    534         } catch (Exception $e) { 
    535             $ui = MainUI::getObject(); 
    536             $ui->setToolSection('ADMIN'); 
    537             $ui->displayError($e->getMessage(), false); 
    538             exit; 
    539         } 
    540532         
    541533        $errmsg = ""; 
     
    573565                $_retVal = false; 
    574566 
    575                 if (!User::getCurrentUser()->isSuperAdmin()) { 
    576                         $errmsg = _('Access denied (must have super admin access)'); 
     567                if (Security::hasPermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer())) { 
     568                        $errmsg = _('Access denied'); 
    577569                } else { 
    578570                        $_id = $db->escapeString($this->getId()); 
     
    600592        } 
    601593     
     594    /** Menu hook function */ 
     595    static public function hookMenu() { 
     596        $items = array(); 
     597        $server = Server::getServer(); 
     598        if(Security::hasPermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), $server)) 
     599        { 
     600            $items[] = array('path' => 'server/profile_templates', 
     601            'title' => _("Profile templates"), 
     602            'url' => BASE_URL_PATH."admin/generic_object_admin.php?object_class=ProfileTemplate&action=list" 
     603                );             
     604        } 
     605        return $items; 
     606    } 
    602607} //end class 
    603608/*