Show
Ignore:
Timestamp:
09/10/05 20:05:18 (8 years ago)
Author:
benoitg
Message:

2005-09-10 Benoit Gr�goire <bock@…>

  • Add UI to add a new Network
  • Improve UI to add a new Node and new Content
Files:
1 modified

Legend:

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

    r733 r742  
    11<?php 
     2 
     3 
    24/********************************************************************\ 
    35 * This program is free software; you can redistribute it and/or    * 
     
    128130                $user = User :: getCurrentUser(); 
    129131                if ($this->isOwner($user) || $user->isSuperAdmin()) 
    130                 { 
    131                         $errmsg = _('Access denied!'); 
    132                 } 
    133  
     132{ 
    134133                global $db; 
    135134                $id = $db->EscapeString($this->getId()); 
     
    142141                        $retval = true; 
    143142                } 
     143} 
     144else 
     145                { 
     146                        $errmsg = _('Access denied!'); 
     147                } 
    144148 
    145149                return $retval; 
    146150        } 
    147151 
    148         /** Create a new Node in the database 
    149          * @param $id The id to be given to the new node 
     152        /** Create a new Node in the database  
     153         * @param $node_id The id to be given to the new node.  If not present, a 
     154         * guid will be assigned. 
     155         * @param $network Network object.  The node's network.  If not present, 
     156         * the current Network will be assigned 
     157         *  
    150158         * @return the newly created Node object, or null if there was an error 
    151159         */ 
    152         static function createNewObject() 
    153         { 
    154                 global $db; 
    155  
    156                 $node_id = $db->EscapeString(get_guid()); 
    157                 $object = self::createNewNode($node_id, Network::getCurrentNetwork()); 
    158                 return $object; 
    159         } 
    160  
    161         /** Create a new Node in the database  
    162          * @param $node_id The id to be given to the new node 
    163          * @param $network Network object.  The node's network  
    164          * @todo Implement network  
    165          * @return the newly created Node object, or null if there was an error 
    166          */ 
    167         static function createNewNode($node_id, Network $network) 
    168         { 
    169                 global $db; 
     160        static function createNewObject($node_id = null, $network = null) 
     161        { 
     162                global $db; 
     163                if(empty($node_id)) 
     164                { 
     165                        $node_id = get_guid(); 
     166                } 
    170167                $node_id = $db->EscapeString($node_id); 
     168                 
     169                if(empty($network)) 
     170                { 
     171                        $network = Network :: getCurrentNetwork(); 
     172                } 
     173                $network_id = $db->EscapeString($network->getId()); 
     174                 
    171175                $node_deployment_status = $db->EscapeString("IN_PLANNING"); 
    172176                $node_name = _("New node"); 
     
    174178                        throw new Exception(_('This node already exists.')); 
    175179 
    176                 $sql = "INSERT INTO nodes (node_id, creation_date, node_deployment_status, name) VALUES ('$node_id', NOW(),'$node_deployment_status', '$node_name')"; 
     180                $sql = "INSERT INTO nodes (node_id, network_id, creation_date, node_deployment_status, name) VALUES ('$node_id', '$network_id', NOW(),'$node_deployment_status', '$node_name')"; 
    177181 
    178182                if (!$db->ExecSqlUpdate($sql, false)) 
     
    222226        } 
    223227 
     228        /** Get an interface to create a new node. 
     229        * @param $network Optional:  The network to which the new node will belong, 
     230        * if absent, the user will be prompted. 
     231        * @return html markup 
     232        */ 
     233        public static function getCreateNewObjectUI($network = null) 
     234        { 
     235                $html = ''; 
     236                $html .= _("Create new node with id")." \n"; 
     237                $name = "new_node_id"; 
     238                $html .= "<input type='text' size='10' name='{$name}'>\n"; 
     239                if ($network) 
     240                { 
     241                        $name = "new_node_network_id"; 
     242                        $html .= "<input type='hidden' name='{$name}' value='{$network->getId()}'>\n"; 
     243                } 
     244                else 
     245                { 
     246                        $html .= " "._("in network:")." \n"; 
     247                        $html .= Network :: getSelectNetworkUI('new_node'); 
     248                } 
     249                return $html; 
     250 
     251        } 
     252 
     253        /** Process the new object interface.  
     254         *  Will return the new object if the user has the credentials and the form was fully filled. 
     255         * @return the node object or null if no new node was created. 
     256         */ 
     257        static function processCreateNewObjectUI() 
     258        { 
     259                $retval = null; 
     260                $name = "new_node_id"; 
     261                if (!empty ($_REQUEST[$name])) 
     262                { 
     263                        $node_id = $_REQUEST[$name]; 
     264                        $name = "new_node_network_id"; 
     265                        if (!empty ($_REQUEST[$name])) 
     266                        { 
     267                                $network = Network :: getObject($_REQUEST[$name]); 
     268                        } 
     269                        else 
     270                        { 
     271                                $network = Network :: processSelectNetworkUI('new_node'); 
     272                        } 
     273                        if ($node_id && $network) 
     274                        { 
     275                                if (!$network->hasAdminAccess(User :: getCurrentUser())) 
     276                                { 
     277                                        throw new Exception(_("Access denied")); 
     278                                } 
     279                                $retval = self :: createNewObject($node_id, $network); 
     280                        } 
     281                } 
     282                return $retval; 
     283        } 
     284 
    224285        /** Get an interface to select the deployment status 
    225286        * @param $user_prefix A identifier provided by the programmer to recognise it's generated html form 
     
    258319                global $db; 
    259320                $this->mDb = & $db; 
    260                  
     321 
    261322                $node_id_str = $db->EscapeString($node_id); 
    262323                $sql = "SELECT * FROM nodes WHERE node_id='$node_id_str'"; 
     
    280341        public function getNetwork() 
    281342        { 
    282                         return Network::getObject($this->mRow['network_id']); 
     343                return Network :: getObject($this->mRow['network_id']); 
    283344        } 
    284345 
     
    320381        } 
    321382 
    322     function getCreationDate() 
    323     { 
    324         return $this->mRow['creation_date']; 
    325     } 
     383        function getCreationDate() 
     384        { 
     385                return $this->mRow['creation_date']; 
     386        } 
    326387 
    327388        function getHomePageURL() 
     
    527588        public function isConfiguredSplashOnly() 
    528589        { 
    529                 return (($this->mRow['is_splash_only_node']=='t') ? true : false); 
     590                return (($this->mRow['is_splash_only_node'] == 't') ? true : false); 
    530591        } 
    531592 
     
    539600                { 
    540601                        global $db; 
    541                         $value?$value='TRUE':$value='FALSE'; 
     602                        $value ? $value = 'TRUE' : $value = 'FALSE'; 
    542603                        $retval = $db->ExecSqlUpdate("UPDATE nodes SET is_splash_only_node = {$value} WHERE node_id = '{$this->getId()}'", false); 
    543604                        $this->refresh(); 
    544605                } 
    545606                return $retval; 
    546         }                
    547          
    548          
     607        } 
     608 
    549609        /** The url to show instead of the portal.  If empty, the portal is shown 
    550610         Must be enabled in the Network configuration to have any effect 
     
    554614                return $this->mRow['custom_portal_redirect_url']; 
    555615        } 
    556          
     616 
    557617        /** The url to show instead of the portal.  If empty, the portal is shown 
    558618         Must be enabled in the Network configuration to have any effect 
     
    570630                return $retval; 
    571631        } 
    572          
     632 
    573633        /** Retrieves the admin interface of this object. 
    574634         * @return The HTML fragment for this interface */ 
     
    577637                //TODO: Most of this code will be moved to Hotspot class when the abtraction will be completed 
    578638 
    579 //pretty_print_r($_REQUEST); 
    580 //pretty_print_r($this->mRow); 
     639                //pretty_print_r($_REQUEST); 
     640                //pretty_print_r($this->mRow); 
    581641                $html = ''; 
    582642                $html .= "<div class='admin_container'>\n"; 
     
    600660                // Hashed node_id (this is a workaround since PHP auto-converts HTTP vars var periods, spaces or underscores ) 
    601661                $hashed_node_id = md5($this->getId()); 
    602                  
     662 
    603663                // Name 
    604664                $html .= "<div class='admin_section_container'>\n"; 
     
    794854                $html .= "<div class='admin_section_container'>\n"; 
    795855                $html .= "<div class='admin_section_title'>"._("Node configuration:")."</div>\n"; 
    796                  
     856 
    797857                $network = $this->getNetwork(); 
    798                  
     858 
    799859                // Deployment status 
    800860                $html .= "<div class='admin_section_container'>\n"; 
     
    807867 
    808868                //  is_splash_only_node 
    809                 if($network->getSplashOnlyNodesAllowed()) 
    810                 { 
    811                 $html .= "<div class='admin_section_container'>\n"; 
    812                 $html .= "<div class='admin_section_title'>"._("Is this node splash-only (no login)?")." : </div>\n"; 
    813                 $html .= "<div class='admin_section_data'>\n"; 
    814                 $name = "node_".$hashed_node_id."_is_splash_only_node"; 
    815                 $this->isConfiguredSplashOnly()? $checked='CHECKED': $checked=''; 
    816                 $html .= "<input type='checkbox' name='$name' $checked>\n"; 
    817                 $html .= "</div>\n"; 
    818                 $html .= "</div>\n"; 
    819                 } 
    820                  
    821                                 // custom_portal_redirect_url 
    822                 if($network->getCustomPortalRedirectAllowed()) 
     869                if ($network->getSplashOnlyNodesAllowed()) 
    823870                { 
    824871                        $html .= "<div class='admin_section_container'>\n"; 
    825                 $html .= "<div class='admin_section_title'>"._("URL to show instead of the portal (if this is not empty, the portal will be disabled and this URL will be shown instead)")." : </div>\n"; 
    826                 $html .= "<div class='admin_section_data'>\n"; 
    827                 $name = "node_".$hashed_node_id."_custom_portal_redirect_url"; 
    828                 $value = htmlspecialchars($this->getCustomPortalRedirectUrl(), ENT_QUOTES); 
    829                 $html .= "<input type='text' size ='50' value='$value' name='$name'>\n"; 
    830                 $html .= "</div>\n"; 
    831                 $html .= "</div>\n"; 
     872                        $html .= "<div class='admin_section_title'>"._("Is this node splash-only (no login)?")." : </div>\n"; 
     873                        $html .= "<div class='admin_section_data'>\n"; 
     874                        $name = "node_".$hashed_node_id."_is_splash_only_node"; 
     875                        $this->isConfiguredSplashOnly() ? $checked = 'CHECKED' : $checked = ''; 
     876                        $html .= "<input type='checkbox' name='$name' $checked>\n"; 
     877                        $html .= "</div>\n"; 
     878                        $html .= "</div>\n"; 
     879                } 
     880 
     881                // custom_portal_redirect_url 
     882                if ($network->getCustomPortalRedirectAllowed()) 
     883                { 
     884                        $html .= "<div class='admin_section_container'>\n"; 
     885                        $html .= "<div class='admin_section_title'>"._("URL to show instead of the portal (if this is not empty, the portal will be disabled and this URL will be shown instead)")." : </div>\n"; 
     886                        $html .= "<div class='admin_section_data'>\n"; 
     887                        $name = "node_".$hashed_node_id."_custom_portal_redirect_url"; 
     888                        $value = htmlspecialchars($this->getCustomPortalRedirectUrl(), ENT_QUOTES); 
     889                        $html .= "<input type='text' size ='50' value='$value' name='$name'>\n"; 
     890                        $html .= "</div>\n"; 
     891                        $html .= "</div>\n"; 
    832892                } 
    833893                // End Node configuration section 
    834894                $html .= "</div>\n"; 
    835                  
     895 
    836896                // Owners management 
    837897                $html .= "<div class='admin_section_container'>\n"; 
     
    936996 
    937997                // Information about the node 
    938                  
     998 
    939999                // Hashed node_id (this is a workaround since PHP auto-converts HTTP vars var periods, spaces or underscores ) 
    9401000                $hashed_node_id = md5($this->getId()); 
    941                  
     1001 
    9421002                // Name 
    9431003                $name = "node_".$hashed_node_id."_name"; 
     
    10291089 
    10301090                // Node configuration section 
    1031                  
     1091 
    10321092                $network = $this->getNetwork(); 
    10331093 
     
    10371097 
    10381098                //  is_splash_only_node 
    1039                 if($network->getSplashOnlyNodesAllowed()) 
    1040                 { 
    1041                 $name = "node_".$hashed_node_id."_is_splash_only_node"; 
    1042                 $this->setIsConfiguredSplashOnly(empty($_REQUEST[$name])?false:true);    
    1043                 } 
    1044                  
     1099                if ($network->getSplashOnlyNodesAllowed()) 
     1100                { 
     1101                        $name = "node_".$hashed_node_id."_is_splash_only_node"; 
     1102                        $this->setIsConfiguredSplashOnly(empty ($_REQUEST[$name]) ? false : true); 
     1103                } 
     1104 
    10451105                // custom_portal_redirect_url 
    1046                 if($network->getCustomPortalRedirectAllowed()) 
    1047                 { 
    1048                 $name = "node_".$hashed_node_id."_custom_portal_redirect_url"; 
    1049                 $this->setCustomPortalRedirectUrl($_REQUEST[$name]); 
    1050                 } 
    1051                  
     1106                if ($network->getCustomPortalRedirectAllowed()) 
     1107                { 
     1108                        $name = "node_".$hashed_node_id."_custom_portal_redirect_url"; 
     1109                        $this->setCustomPortalRedirectUrl($_REQUEST[$name]); 
     1110                } 
     1111 
    10521112                // End Node configuration section 
    10531113 
     
    10651125                        } 
    10661126                } 
    1067                  
     1127 
    10681128                $name = "node_{$this->getId()}_new_owner_submit"; 
    10691129                if (!empty ($_REQUEST[$name])) 
     
    14051465                $sql = "SELECT * FROM nodes WHERE node_id='{$id_str}'"; 
    14061466                $db->ExecSqlUniqueRes($sql, $row, false); 
    1407                 if($row!=null) 
     1467                if ($row != null) 
    14081468                { 
    14091469                        $retval = true; 
     
    14301490} // End class 
    14311491?> 
     1492 
     1493