Changeset 1339

Show
Ignore:
Timestamp:
03/24/08 16:28:20 (4 years ago)
Author:
benoitg
Message:
  • generic_object_admin.php (and others): Fix bug reported by Jerry DeFoe? (ProfileTemplates? couldn't be created) + some UI tweaks.
Location:
trunk/wifidog-auth
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/CHANGELOG

    r1338 r1339  
    11# $Id$ 
     22008-03-21 Benoit Grégoire  <bock@step.polymtl.ca> 
     3        * generic_object_admin.php (and others):  Fix bug reported by  Jerry DeFoe (ProfileTemplates couldn't be created) + some UI tweaks. 
     4         
    252008-03-21 Benoit Grégoire  <bock@step.polymtl.ca> 
    36        * hotspot_status.php:  Fix bug in XSLT procesing. 
  • trunk/wifidog-auth/wifidog/admin/generic_object_admin.php

    r1316 r1339  
    274274                $userData['typeInterface'] = "table"; 
    275275                $displayEditButton = false; 
    276             case "Network" : 
    277                 $disableCreateNewButton = true; 
    278276            default : 
    279277                $newLongText = $addLongText; 
     
    284282                , $userData); 
    285283                break; 
    286         } 
    287  
    288         if($disableCreateNewButton == false && method_exists($_REQUEST['object_class'],'getCreateNewObjectUI')) { 
    289             $html .= "<form action='" . GENERIC_OBJECT_ADMIN_ABS_HREF . "' method='post'>"; 
    290             $html .= "<input type='hidden' name='object_class' value='$class'>"; 
    291             $html .= "<input type='hidden' name='action' value='new_ui'>"; 
    292             $html .= "<input type='submit' name='new_submit' value='$newLongText'>\n"; 
    293             $html .= '</form>'; 
    294284        } 
    295285 
     
    321311            } 
    322312        } 
     313         
     314        if($disableCreateNewButton == false  
     315        && method_exists($_REQUEST['object_class'],'getCreateNewObjectUI')  
     316        && null != $newUi = call_user_func(array ($_REQUEST['object_class'], 'getCreateNewObjectUI'))) { 
     317            $html .= "<form action='" . GENERIC_OBJECT_ADMIN_ABS_HREF . "' method='post'>\n"; 
     318            $html .= "<input type='hidden' name='object_class' value='$class'>\n"; 
     319            $html .= $newUi; 
     320            $html .= "<input type='hidden' name='action' value='process_new_ui'>\n"; 
     321            $html .= "<input type='submit' name='new_submit' value='$newLongText'>\n"; 
     322            $html .= "</form>\n"; 
     323        } 
    323324        break; 
    324325 
  • trunk/wifidog-auth/wifidog/classes/ContentTypeFilter.php

    r1308 r1339  
    218218                $name = "new_content_type_filter_rules"; 
    219219 
    220                 $html .= "<b>"._("Add a new content type filter with these rules") . ": </b><br/>"; 
     220                $html .= "<p><b>"._("Add a new content type filter with these rules") . ": </b></p>"; 
     221                $html .= _("Example:")."<br/>"; 
    221222                $html .= "<pre>array (\r\n\tarray('isContentType',\r\n\t\tarray (\r\n\t\t\tarray (\r\n\t\t\t\t'SimplePicture'\r\n\t)\r\n\t\t)\r\n\t)\r\n)</pre><br/>"; 
    222223                $html .= "<textarea cols='50' rows='10' name='{$name}'></textarea><br/>"; 
  • trunk/wifidog-auth/wifidog/classes/ProfileTemplate.php

    r1308 r1339  
    4040 * @subpackage ContentClasses 
    4141 * @author     François Proulx <francois.proulx@gmail.com> 
    42  * @copyright  2007 François Proulx 
     42 * @copyright  2007 François Proulx, 2008 Technologies Coeus inc. 
    4343 * @link       http://www.wifidog.org/ 
    4444 */ 
     
    4747require_once ('classes/ContentTypeFilter.php'); 
    4848 
    49 class ProfileTemplate implements GenericObject { 
    50         /** Object cache for the object factory (getObject())*/ 
     49class ProfileTemplate extends GenericDataObject { 
     50    /** Object cache for the object factory (getObject())*/ 
    5151    private static $instanceArray = array(); 
    52      
     52 
    5353    private $id = null; 
    5454    private $_row; 
    55      
     55 
    5656    private function __construct($profile_template_id) 
    57         { 
    58                 $db = AbstractDb::getObject(); 
    59  
    60                 // Init values 
    61                 $row = null; 
    62  
    63                 $profile_template_id = $db->escapeString($profile_template_id); 
    64                 $sql = "SELECT * FROM profile_templates WHERE profile_template_id = '{$profile_template_id}';"; 
    65                 $db->execSqlUniqueRes($sql, $row, false); 
    66  
    67                 if ($row == null) { 
    68                         throw new Exception("The profile template with id {$profile_template_id} could not be found in the database!"); 
    69                 } 
    70  
    71                 $this->_row = $row; 
    72                 $this->id = $db->escapeString($row['profile_template_id']); 
    73         } 
     57    { 
     58        $db = AbstractDb::getObject(); 
     59 
     60        // Init values 
     61        $row = null; 
     62 
     63        $profile_template_id = $db->escapeString($profile_template_id); 
     64        $sql = "SELECT * FROM profile_templates WHERE profile_template_id = '{$profile_template_id}';"; 
     65        $db->execSqlUniqueRes($sql, $row, false); 
     66 
     67        if ($row == null) { 
     68            throw new Exception("The profile template with id {$profile_template_id} could not be found in the database!"); 
     69        } 
     70 
     71        $this->_row = $row; 
     72        $this->id = $db->escapeString($row['profile_template_id']); 
     73    } 
    7474 
    7575    /** 
     
    8787    public static function &getObject($id) 
    8888    { 
    89         if(!isset(self::$instanceArray[$id])) 
     89        if(!isset(self::$instanceArray[$id])) 
    9090        { 
    91                 self::$instanceArray[$id] = new self($id); 
     91            self::$instanceArray[$id] = new self($id); 
    9292        } 
    9393        return self::$instanceArray[$id]; 
    9494    } 
    95      
    96      
     95 
     96 
    9797    /** 
    9898     * Get all profile templates ( can be restricted to a network ) 
     
    100100     */ 
    101101    public static function getAllProfileTemplates($network = null) { 
    102         $db = AbstractDb :: getObject(); 
    103  
    104         // Init values 
    105         $whereClause = ""; 
    106         $rows = null; 
    107         $objects = array (); 
    108  
    109         if (!empty ($network) && get_class($network) == "Network") { 
    110                 $db->execSql("SELECT profile_template_id FROM network_has_profile_templates WHERE network_id = '{$network->getId()}'", $rows, false); 
    111         } else { 
    112                 $db->execSql("SELECT profile_template_id FROM profile_templates", $rows, false); 
    113         } 
    114  
    115         if ($rows) { 
    116                 foreach ($rows as $row) { 
    117                         $objects[] = self :: getObject($row['profile_template_id']); 
    118                 } 
    119         } 
    120  
    121         return $objects; 
    122     } 
    123      
     102        $db = AbstractDb :: getObject(); 
     103 
     104        // Init values 
     105        $whereClause = ""; 
     106        $rows = null; 
     107        $objects = array (); 
     108 
     109        if (!empty ($network) && get_class($network) == "Network") { 
     110            $db->execSql("SELECT profile_template_id FROM network_has_profile_templates WHERE network_id = '{$network->getId()}'", $rows, false); 
     111        } else { 
     112            $db->execSql("SELECT profile_template_id FROM profile_templates", $rows, false); 
     113        } 
     114 
     115        if ($rows) { 
     116            foreach ($rows as $row) { 
     117                $objects[] = self :: getObject($row['profile_template_id']); 
     118            } 
     119        } 
     120 
     121        return $objects; 
     122    } 
     123 
    124124    /** 
    125125     * Retreives the Id of the object 
     
    127127     * @return string The Id 
    128128     */ 
    129         public function getId() 
    130         { 
    131                 return $this->id; 
    132         } 
    133          
    134         /** 
     129    public function getId() 
     130    { 
     131        return $this->id; 
     132    } 
     133 
     134    /** 
    135135     * Retrieves the profile template's label 
    136136     * 
     
    153153    public function setLabel($value) 
    154154    { 
    155          
     155 
    156156        $db = AbstractDb::getObject(); 
    157157 
     
    167167        return $_retVal; 
    168168    } 
    169          
     169 
    170170    /** 
    171171     * Retrieves the profile template's creation date 
     
    189189    public function setCreationDate($value) 
    190190    { 
    191          
     191 
    192192        $db = AbstractDb::getObject(); 
    193193 
     
    203203        return $_retVal; 
    204204    } 
    205      
     205 
    206206    /* Create a new ProfileTemplate object in the database 
    207         * 
    208         * @param string $profile_template_id The id of the new object. If absent, 
    209         * will be assigned a guid. 
    210         * 
    211         * @return mixed The newly created object, or null if there was an error 
    212         * 
    213         * @see GenericObject 
    214         * 
    215         * @static 
    216         * @access public 
    217         */ 
    218         public static function createNewObject($profile_template_id = null) 
     207    * 
     208    * @param string $profile_template_id The id of the new object. If absent, 
     209    * will be assigned a guid. 
     210    * 
     211    * @return mixed The newly created object, or null if there was an error 
     212    * 
     213    * @see GenericObject 
     214    * 
     215    * @static 
     216    * @access public 
     217    */ 
     218    public static function createNewObject($profile_template_id = null) 
    219219    { 
    220220        $db = AbstractDb::getObject(); 
     
    232232        return $object; 
    233233    } 
    234          
    235         /* Get an interface to create a new ProfileTemplate 
     234 
     235    /* Get an interface to create a new ProfileTemplate 
    236236     * @return string HTML markup 
    237237     */ 
    238         public static function getCreateNewObjectUI() {} 
    239          
    240          
     238    public static function getCreateNewObjectUI() { 
     239        $html = ''; 
     240        $html .= _("Add a new profile template with ID")." \n"; 
     241        $name = "new_profile_template_id"; 
     242        $html .= "<input type='text' size='30' name='{$name}'>\n"; 
     243        return $html; 
     244    } 
     245 
     246 
    241247    /** 
    242248     * Process the new object interface. 
     
    248254 
    249255     */ 
    250         public static function processCreateNewObjectUI() {} 
    251          
    252         /** 
    253          * Get an interface to pick an object of this class 
    254          * 
    255          * If there is only one server available, no interface is actually shown 
    256          * 
     256    public static function processCreateNewObjectUI() 
     257    { 
     258        // Init values 
     259        $retval = null; 
     260        $name = "new_profile_template_id"; 
     261 
     262        if (!empty ($_REQUEST[$name])) { 
     263            $newId = $_REQUEST[$name]; 
     264        } 
     265        else 
     266        { 
     267            $newId = null; 
     268        } 
     269        Security::requirePermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer()); 
     270        $retval = self::createNewObject($newId); 
     271 
     272        return $retval; 
     273    } 
     274 
     275 
     276    /** 
     277     * Get an interface to pick an object of this class 
     278     * 
     279     * If there is only one server available, no interface is actually shown 
     280     * 
    257281     * @param string $user_prefix         A identifier provided by the 
    258282     *                                    programmer to recognise it's generated 
     
    270294     */ 
    271295    public static function getSelectUI($user_prefix, $userData=null) 
    272     {  
    273                 $db = AbstractDb::getObject(); 
    274  
    275         // Init values 
    276                 $_html = ""; 
    277                 $_profile_template_rows = null; 
    278                  
    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); 
    285  
    286                 if ($_profile_template_rows != null) { 
    287                         $_name = $user_prefix; 
    288  
    289                         $_html .= _("Profile template").": \n"; 
    290          
    291                         $_i = 0; 
    292                         foreach ($_profile_template_rows as $_profile_template_row) { 
    293                                 $_tab[$_i][0] = $_profile_template_row['profile_template_id']; 
    294                                 $_tab[$_i][1] = empty($_profile_template_row['profile_template_label']) ? "["._("No label")."] - ".$_profile_template_row['profile_template_id'] : $_profile_template_row['profile_template_label']; 
    295                                 $_i ++; 
    296                         } 
    297  
    298                         $_html .= FormSelectGenerator::generateFromArray($_tab, $selectedId, $_name, null, false); 
    299                          
    300                         if ($type_interface == "add") { 
    301                         if (isset ($_tab)) { 
    302                                 $name = "{$user_prefix}_add"; 
    303                                 $value = _("Add"); 
    304                                 $_html .= "<div class='admin_element_tools'>"; 
    305                                 $_html .= '<input type="submit" class="submit" name="' . $name . '" value="' . $value . '">'; 
    306                                 $_html .= "</div>"; 
    307                         } 
    308                 } 
    309                 } 
    310                  
    311                 return $_html; 
    312         } 
    313          
    314          
     296    { 
     297        $db = AbstractDb::getObject(); 
     298 
     299        // Init values 
     300        $_html = ""; 
     301        $_profile_template_rows = null; 
     302 
     303        !empty($userData['preSelectedId'])?$selectedId=$userData['preSelectedId']:$selectedId=null; 
     304        !empty($userData['additionalWhere'])?$additional_where=$userData['additionalWhere']:$additional_where=null; 
     305        !empty($userData['typeInterface'])?$type_interface=$userData['typeInterface']:$type_interface=null; 
     306 
     307        $sql = "SELECT * FROM profile_templates WHERE 1=1 $additional_where ORDER BY profile_template_label ASC"; 
     308        $db->execSql($sql, $_profile_template_rows, false); 
     309 
     310        if ($_profile_template_rows != null) { 
     311            $_name = $user_prefix; 
     312 
     313            $_html .= _("Profile template").": \n"; 
     314 
     315            $_i = 0; 
     316            foreach ($_profile_template_rows as $_profile_template_row) { 
     317                $_tab[$_i][0] = $_profile_template_row['profile_template_id']; 
     318                $_tab[$_i][1] = empty($_profile_template_row['profile_template_label']) ? "["._("No label")."] - ".$_profile_template_row['profile_template_id'] : $_profile_template_row['profile_template_label']; 
     319                $_i ++; 
     320            } 
     321 
     322            $_html .= FormSelectGenerator::generateFromArray($_tab, $selectedId, $_name, null, false); 
     323              
     324            if ($type_interface == "add") { 
     325                if (isset ($_tab)) { 
     326                    $name = "{$user_prefix}_add"; 
     327                    $value = _("Add"); 
     328                    $_html .= "<div class='admin_element_tools'>"; 
     329                    $_html .= '<input type="submit" class="submit" name="' . $name . '" value="' . $value . '">'; 
     330                    $_html .= "</div>"; 
     331                } 
     332            } 
     333        } 
     334 
     335        return $_html; 
     336    } 
     337 
     338 
    315339    /** Get the selected ProfileTemplate object. 
    316340     * @param $user_prefix A identifier provided by the programmer to recognise it's generated form 
     
    318342     */ 
    319343    static function processSelectProfileTemplateUI($user_prefix) { 
    320         $name = "{$user_prefix}"; 
    321         if (!empty ($_REQUEST[$name])) 
    322                 return ProfileTemplate :: getObject($_REQUEST[$name]); 
    323         else 
    324                 return null; 
    325     } 
    326          
    327         /** 
     344        $name = "{$user_prefix}"; 
     345        if (!empty ($_REQUEST[$name])) 
     346        return ProfileTemplate :: getObject($_REQUEST[$name]); 
     347        else 
     348        return null; 
     349    } 
     350 
     351    /** 
    328352     * Get a flexible interface to manage a profile template linked to a node, a network 
    329353     * or anything else 
     
    338362     * @param string $default_display_area 
    339363     * @return string HTML markup 
    340      
     364 
    341365     */ 
    342366    public static function getLinkedProfileTemplateUI($user_prefix, $link_table, $link_table_obj_key_col, $link_table_obj_key) { 
    343367 
    344         $db = AbstractDb :: getObject(); 
    345  
    346         // Init values 
    347         $html = ""; 
    348  
    349         $link_table = $db->escapeString($link_table); 
    350         $link_table_obj_key_col = $db->escapeString($link_table_obj_key_col); 
    351         $link_table_obj_key = $db->escapeString($link_table_obj_key); 
    352  
    353         /* Profile templates already linked */ 
    354         $current_profile_templates_sql = "SELECT * FROM $link_table WHERE $link_table_obj_key_col = '$link_table_obj_key'"; 
    355         $rows = null; 
    356         $db->execSql($current_profile_templates_sql, $rows, false); 
    357  
    358         $html .= "<table class='content_management_tools'>\n"; 
    359         $html .= "<th>" . _('Profile template label') . '</th><th>' . _('Actions') . '</th>' . "\n"; 
    360         if ($rows) 
    361         foreach ($rows as $row) { 
    362                 $profile_template = self :: getObject($row['profile_template_id']); 
    363                 $html .= "<tr class='already_linked_content'>\n"; 
    364                 $html .= "<td>\n"; 
    365                 $html .= $profile_template->getLabel(); 
    366                 $html .= "</td>\n"; 
    367                 $html .= "<td>\n"; 
    368                 $name = "{$user_prefix}_" . $profile_template->GetId() . "_edit"; 
    369                 $html .= "<input type='button' class='submit' name='$name' value='" . _("Edit") . "' onClick='window.open(\"" . GENERIC_OBJECT_ADMIN_ABS_HREF . "?object_class=ProfileTemplate&action=edit&object_id=" . $profile_template->GetId() . "\");'>\n"; 
    370                 $name = "{$user_prefix}_" . $profile_template->GetId() . "_erase"; 
    371                 $html .= "<input type='submit' class='submit' name='$name' value='" . _("Remove") . "'>"; 
    372                 $html .= "</td>\n"; 
    373                 $html .= "</tr>\n"; 
    374         } 
    375  
    376         /* Add a profile template */ 
    377         $html .= "<tr class='add_existing_content'>\n"; 
    378         $html .= "<td colspan ='2'>\n"; 
    379         $name = "{$user_prefix}_new_existing"; 
    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")); 
    381         $html .= $profileTemplateSelector; 
    382         $html .= "</td>\n"; 
    383         $html .= "</tr>\n"; 
    384  
    385         $html .= "</table>\n"; 
    386         return $html; 
    387     } 
    388      
     368        $db = AbstractDb :: getObject(); 
     369 
     370        // Init values 
     371        $html = ""; 
     372 
     373        $link_table = $db->escapeString($link_table); 
     374        $link_table_obj_key_col = $db->escapeString($link_table_obj_key_col); 
     375        $link_table_obj_key = $db->escapeString($link_table_obj_key); 
     376 
     377        /* Profile templates already linked */ 
     378        $current_profile_templates_sql = "SELECT * FROM $link_table WHERE $link_table_obj_key_col = '$link_table_obj_key'"; 
     379        $rows = null; 
     380        $db->execSql($current_profile_templates_sql, $rows, false); 
     381 
     382        $html .= "<table class='content_management_tools'>\n"; 
     383        $html .= "<th>" . _('Profile template label') . '</th><th>' . _('Actions') . '</th>' . "\n"; 
     384        if ($rows) 
     385        foreach ($rows as $row) { 
     386            $profile_template = self :: getObject($row['profile_template_id']); 
     387            $html .= "<tr class='already_linked_content'>\n"; 
     388            $html .= "<td>\n"; 
     389            $html .= $profile_template->getLabel(); 
     390            $html .= "</td>\n"; 
     391            $html .= "<td>\n"; 
     392            $name = "{$user_prefix}_" . $profile_template->GetId() . "_edit"; 
     393            $html .= "<input type='button' class='submit' name='$name' value='" . _("Edit") . "' onClick='window.open(\"" . GENERIC_OBJECT_ADMIN_ABS_HREF . "?object_class=ProfileTemplate&action=edit&object_id=" . $profile_template->GetId() . "\");'>\n"; 
     394            $name = "{$user_prefix}_" . $profile_template->GetId() . "_erase"; 
     395            $html .= "<input type='submit' class='submit' name='$name' value='" . _("Remove") . "'>"; 
     396            $html .= "</td>\n"; 
     397            $html .= "</tr>\n"; 
     398        } 
     399 
     400        /* Add a profile template */ 
     401        $html .= "<tr class='add_existing_content'>\n"; 
     402        $html .= "<td colspan ='2'>\n"; 
     403        $name = "{$user_prefix}_new_existing"; 
     404        $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")); 
     405        $html .= $profileTemplateSelector; 
     406        $html .= "</td>\n"; 
     407        $html .= "</tr>\n"; 
     408 
     409        $html .= "</table>\n"; 
     410        return $html; 
     411    } 
     412 
    389413    /** Get the selected ProfileTemplate object 
    390414     * @param $user_prefix A identifier provided by the programmer to recognise it's generated form 
     
    392416     */ 
    393417    static function processLinkedProfileTemplateUI($user_prefix, $link_table, $link_table_obj_key_col, $link_table_obj_key) { 
    394         $db = AbstractDb :: getObject(); 
    395         $link_table = $db->escapeString($link_table); 
    396         $link_table_obj_key_col = $db->escapeString($link_table_obj_key_col); 
    397         $link_table_obj_key = $db->escapeString($link_table_obj_key); 
    398          
    399         // Profile templates already linked 
    400         $current_content_sql = "SELECT * FROM $link_table WHERE $link_table_obj_key_col='$link_table_obj_key'"; 
    401         $rows = null; 
    402         $db->execSql($current_content_sql, $rows, false); 
    403         if ($rows) 
    404         foreach ($rows as $row) { 
    405                 $profile_template = ProfileTemplate :: getObject($row['profile_template_id']); 
    406                 $profile_template_id = $db->escapeString($profile_template->getId()); 
    407                 $name = "{$user_prefix}_" . $profile_template->GetId() . "_erase"; 
    408                 if (!empty ($_REQUEST[$name])) { 
    409                         $sql = "DELETE FROM $link_table WHERE $link_table_obj_key_col='$link_table_obj_key' AND profile_template_id = '$profile_template_id';\n"; 
    410                         $db->execSqlUpdate($sql, false); 
    411                 } 
    412         } 
    413         // Link an existing profile template 
    414         $name = "{$user_prefix}_new_existing_add"; 
    415         if (!empty ($_REQUEST[$name])) { 
    416                 $name = "{$user_prefix}_new_existing"; 
    417                 $profile_template = ProfileTemplate :: processSelectProfileTemplateUI($name); 
    418                 if ($profile_template) { 
    419                         $profile_template_id = $db->escapeString($profile_template->getId()); 
    420                         $sql = "INSERT INTO $link_table (profile_template_id, $link_table_obj_key_col) VALUES ('$profile_template_id', '$link_table_obj_key');\n"; 
    421                         $db->execSqlUpdate($sql, false); 
    422                 } 
    423         } 
    424     } 
    425          
    426         /**Get all fields 
     418        $db = AbstractDb :: getObject(); 
     419        $link_table = $db->escapeString($link_table); 
     420        $link_table_obj_key_col = $db->escapeString($link_table_obj_key_col); 
     421        $link_table_obj_key = $db->escapeString($link_table_obj_key); 
     422          
     423        // Profile templates already linked 
     424        $current_content_sql = "SELECT * FROM $link_table WHERE $link_table_obj_key_col='$link_table_obj_key'"; 
     425        $rows = null; 
     426        $db->execSql($current_content_sql, $rows, false); 
     427        if ($rows) 
     428        foreach ($rows as $row) { 
     429            $profile_template = ProfileTemplate :: getObject($row['profile_template_id']); 
     430            $profile_template_id = $db->escapeString($profile_template->getId()); 
     431            $name = "{$user_prefix}_" . $profile_template->GetId() . "_erase"; 
     432            if (!empty ($_REQUEST[$name])) { 
     433                $sql = "DELETE FROM $link_table WHERE $link_table_obj_key_col='$link_table_obj_key' AND profile_template_id = '$profile_template_id';\n"; 
     434                $db->execSqlUpdate($sql, false); 
     435            } 
     436        } 
     437        // Link an existing profile template 
     438        $name = "{$user_prefix}_new_existing_add"; 
     439        if (!empty ($_REQUEST[$name])) { 
     440            $name = "{$user_prefix}_new_existing"; 
     441            $profile_template = ProfileTemplate :: processSelectProfileTemplateUI($name); 
     442            if ($profile_template) { 
     443                $profile_template_id = $db->escapeString($profile_template->getId()); 
     444                $sql = "INSERT INTO $link_table (profile_template_id, $link_table_obj_key_col) VALUES ('$profile_template_id', '$link_table_obj_key');\n"; 
     445                $db->execSqlUpdate($sql, false); 
     446            } 
     447        } 
     448    } 
     449 
     450    /**Get all fields 
    427451     * @return an array of ProfileTemplateField or an empty arrray */ 
    428452    function getFields($additional_where = null) { 
     
    441465        return $retval; 
    442466    } 
    443          
     467 
    444468    /** 
    445469     * Retreives the admin interface of this object 
     
    447471     * @return string The HTML fragment for this interface 
    448472     */ 
    449         public function getAdminUI() 
    450         { 
    451             Security::requirePermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer()); 
    452             $db = AbstractDb::getObject(); 
    453             $sql = "SELECT COUNT(*) as num_used_profiles FROM profile_templates JOIN profiles USING (profile_template_id) WHERE profile_template_id = '" . $this->getId() . "'"; 
    454             $db->execSqlUniqueRes($sql, $num_used_profiles, false); 
    455               
    456             // Init values 
    457                 $html = ''; 
    458  
    459                 $html .= "<fieldset class='admin_container ".get_class($this)."'>\n"; 
    460                 $html .= "<legend>"._("Profile template management")."</legend>\n"; 
     473    public function getAdminUI() 
     474    { 
     475        Security::requirePermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer()); 
     476        $db = AbstractDb::getObject(); 
     477        $sql = "SELECT COUNT(*) as num_used_profiles FROM profile_templates JOIN profiles USING (profile_template_id) WHERE profile_template_id = '" . $this->getId() . "'"; 
     478        $db->execSqlUniqueRes($sql, $num_used_profiles, false); 
     479 
     480        // Init values 
     481        $html = ''; 
     482 
     483        $html .= "<fieldset class='admin_container ".get_class($this)."'>\n"; 
     484        $html .= "<legend>"._("Profile template management")."</legend>\n"; 
    461485        $html .= "<ul class='admin_element_list'>\n"; 
    462          
    463                 // profile_template_id 
    464                 $_value = htmlspecialchars($this->getId(), ENT_QUOTES); 
    465  
    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"; 
    472  
    473                 // label 
    474                 $_name = "profile_template_" . $this->getId() . "_label"; 
    475                 $_value = htmlspecialchars($this->getLabel(), ENT_QUOTES); 
    476  
    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"; 
    483  
    484                 // creation date 
    485                 $_value = htmlspecialchars($this->getCreationDate(), ENT_QUOTES); 
    486  
    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"; 
    493  
    494                 // profile template fields 
    495                 $html .= "<li class='admin_element_item_container'>\n"; 
     486 
     487        // profile_template_id 
     488        $_value = htmlspecialchars($this->getId(), ENT_QUOTES); 
     489 
     490        $html .= "<li class='admin_element_item_container'>\n"; 
     491        $html .= "<div class='admin_element_label'>" . _("ProfileTemplate ID") . ":</div>\n"; 
     492        $html .= "<div class='admin_element_data'>\n"; 
     493        $html .= $_value; 
     494        $html .= "</div>\n"; 
     495        $html .= "</li>\n"; 
     496 
     497        // label 
     498        $_name = "profile_template_" . $this->getId() . "_label"; 
     499        $_value = htmlspecialchars($this->getLabel(), ENT_QUOTES); 
     500 
     501        $html .= "<li class='admin_element_item_container'>\n"; 
     502        $html .= "<div class='admin_element_label'>" . _("Label") . ":</div>\n"; 
     503        $html .= "<div class='admin_element_data'>\n"; 
     504        $html .= "<input type='text' size='50' value='$_value' name='$_name'>\n"; 
     505        $html .= "</div>\n"; 
     506        $html .= "</li>\n"; 
     507 
     508        // creation date 
     509        $_value = htmlspecialchars($this->getCreationDate(), ENT_QUOTES); 
     510 
     511        $html .= "<li class='admin_element_item_container'>\n"; 
     512        $html .= "<div class='admin_element_label'>" . _("Creation date") . ":</div>\n"; 
     513        $html .= "<div class='admin_element_data'>\n"; 
     514        $html .= $_value; 
     515        $html .= "</div>\n"; 
     516        $html .= "</li>\n"; 
     517 
     518        // profile template fields 
     519        $html .= "<li class='admin_element_item_container'>\n"; 
    496520        $html .= "<fieldset class='admin_element_group'>\n"; 
    497521        $html .= "<legend>"._("Profile template fields")."</legend>\n"; 
    498          
     522 
    499523        $html .= "<ul class='admin_element_list'>\n"; 
    500524        foreach ($this->getFields() as $field) { 
     
    515539        $html .= "</fieldset>\n"; 
    516540        $html .= "</li>\n"; 
    517          
     541 
    518542        $html .= "</ul>\n"; 
    519543        $html .= "</fieldset>\n"; 
    520                 return $html; 
    521         } 
     544        return $html; 
     545    } 
    522546 
    523547    /** 
     
    526550     * @return void 
    527551     */ 
    528         public function processAdminUI() 
    529         { 
    530                     Security::requirePermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer()); 
     552    public function processAdminUI() 
     553    { 
     554        Security::requirePermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer()); 
    531555        require_once('classes/User.php'); 
    532          
     556 
    533557        $errmsg = ""; 
    534          
    535                 // label 
    536                 $_name = "profile_template_" . $this->getId() . "_label"; 
    537                 $this->setLabel($_REQUEST[$_name]);      
    538                  
    539                 foreach ($this->getFields() as $field) { 
     558 
     559        // label 
     560        $_name = "profile_template_" . $this->getId() . "_label"; 
     561        $this->setLabel($_REQUEST[$_name]); 
     562 
     563        foreach ($this->getFields() as $field) { 
    540564            $name = "profile_template_" . $this->id . "_field_" . $field->GetId() . "_erase"; 
    541565            if (!empty ($_REQUEST[$name]) && $_REQUEST[$name] == true) { 
     
    547571 
    548572        ProfileTemplateField :: processCreateFieldUI("profile_template_{$this->id}_new_field", $this); 
    549         } 
     573    } 
    550574 
    551575    /** 
     
    556580     * @return bool True on success, false on failure or access denied 
    557581     */ 
    558         public function delete(&$errmsg) 
    559         { 
    560             require_once('classes/User.php'); 
    561          
    562                 $db = AbstractDb::getObject(); 
    563  
    564             // Init values 
    565                 $_retVal = false; 
    566  
    567                 if (Security::hasPermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer())) { 
    568                         $errmsg = _('Access denied'); 
    569                 } else { 
    570                         $_id = $db->escapeString($this->getId()); 
    571  
    572                         if (!$db->execSqlUpdate("DELETE FROM profile_templates WHERE profile_template_id = '{$_id}'", false)) { 
    573                                 $errmsg = _('Could not delete ProfileTemplate!'); 
    574                         } else { 
    575                                 $_retVal = true; 
    576                         } 
    577                 } 
    578  
    579                 return $_retVal; 
    580         } 
    581          
    582          
     582    public function delete(&$errmsg) 
     583    { 
     584        require_once('classes/User.php'); 
     585 
     586        $db = AbstractDb::getObject(); 
     587 
     588        // Init values 
     589        $_retVal = false; 
     590 
     591        if (Security::hasPermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer())) { 
     592            $_id = $db->escapeString($this->getId()); 
     593 
     594            if (!$db->execSqlUpdate("DELETE FROM profile_templates WHERE profile_template_id = '{$_id}'", false)) { 
     595                $errmsg = _('Could not delete ProfileTemplate!'); 
     596            } 
     597            else { 
     598                $_retVal = true; 
     599            } 
     600        } 
     601        else { 
     602            $errmsg = _('Access denied'); 
     603        } 
     604 
     605        return $_retVal; 
     606    } 
     607 
     608 
    583609    /** 
    584610     * Reloads the object from the database 
     
    587613     * 
    588614     * @return void     */ 
    589         protected function refresh() 
    590         { 
    591                 $this->__construct($this->getId()); 
    592         } 
    593      
     615    protected function refresh() 
     616    { 
     617        $this->__construct($this->getId()); 
     618    } 
     619 
    594620    /** Menu hook function */ 
    595621    static public function hookMenu() { 
     
    601627            'title' => _("Profile templates"), 
    602628            'url' => BASE_URL_PATH.htmlspecialchars("admin/generic_object_admin.php?object_class=ProfileTemplate&action=list") 
    603                 );             
     629            ); 
    604630        } 
    605631        return $items; 
  • trunk/wifidog-auth/wifidog/classes/ProfileTemplateField.php

    r1249 r1339  
    4848require_once ('classes/Content.php'); 
    4949 
    50 class ProfileTemplateField implements GenericObject { 
     50class ProfileTemplateField extends GenericDataObject { 
    5151        private static $instanceArray = array(); 
    5252         
     
    8585        return self::$instanceArray[$id]; 
    8686    } 
    87      
    88     /** 
    89      * Retreives the Id of the object 
    90      * 
    91      * @return string The Id 
    92      */ 
    93         public function getId() 
    94         { 
    95                 return $this->id; 
    96         } 
    9787     
    9888    public static function createNewObject() {} 
  • trunk/wifidog-auth/wifidog/classes/Role.php

    r1316 r1339  
    231231        $stakeholderTypeSelect = StakeholderType::getSelectUI($name); 
    232232        $name = "new_role_id"; 
    233         $idInput = "<input type='text' name='{$name}'/><br/>"; 
     233        $idInput = "<input type='text' name='{$name}'/>\n"; 
    234234        $html .= sprintf(_("Add a new role of type %s with id %s"),$stakeholderTypeSelect,$idInput); 
    235235        return $html;