Changeset 742 for trunk/wifidog-auth/wifidog/classes/Node.php
- Timestamp:
- 09/10/05 20:05:18 (8 years ago)
- Files:
-
- 1 modified
-
trunk/wifidog-auth/wifidog/classes/Node.php (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/wifidog/classes/Node.php
r733 r742 1 1 <?php 2 3 2 4 /********************************************************************\ 3 5 * This program is free software; you can redistribute it and/or * … … 128 130 $user = User :: getCurrentUser(); 129 131 if ($this->isOwner($user) || $user->isSuperAdmin()) 130 { 131 $errmsg = _('Access denied!'); 132 } 133 132 { 134 133 global $db; 135 134 $id = $db->EscapeString($this->getId()); … … 142 141 $retval = true; 143 142 } 143 } 144 else 145 { 146 $errmsg = _('Access denied!'); 147 } 144 148 145 149 return $retval; 146 150 } 147 151 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 * 150 158 * @return the newly created Node object, or null if there was an error 151 159 */ 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 } 170 167 $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 171 175 $node_deployment_status = $db->EscapeString("IN_PLANNING"); 172 176 $node_name = _("New node"); … … 174 178 throw new Exception(_('This node already exists.')); 175 179 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')"; 177 181 178 182 if (!$db->ExecSqlUpdate($sql, false)) … … 222 226 } 223 227 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 224 285 /** Get an interface to select the deployment status 225 286 * @param $user_prefix A identifier provided by the programmer to recognise it's generated html form … … 258 319 global $db; 259 320 $this->mDb = & $db; 260 321 261 322 $node_id_str = $db->EscapeString($node_id); 262 323 $sql = "SELECT * FROM nodes WHERE node_id='$node_id_str'"; … … 280 341 public function getNetwork() 281 342 { 282 return Network::getObject($this->mRow['network_id']);343 return Network :: getObject($this->mRow['network_id']); 283 344 } 284 345 … … 320 381 } 321 382 322 function getCreationDate()323 {324 return $this->mRow['creation_date'];325 }383 function getCreationDate() 384 { 385 return $this->mRow['creation_date']; 386 } 326 387 327 388 function getHomePageURL() … … 527 588 public function isConfiguredSplashOnly() 528 589 { 529 return (($this->mRow['is_splash_only_node'] =='t') ? true : false);590 return (($this->mRow['is_splash_only_node'] == 't') ? true : false); 530 591 } 531 592 … … 539 600 { 540 601 global $db; 541 $value ?$value='TRUE':$value='FALSE';602 $value ? $value = 'TRUE' : $value = 'FALSE'; 542 603 $retval = $db->ExecSqlUpdate("UPDATE nodes SET is_splash_only_node = {$value} WHERE node_id = '{$this->getId()}'", false); 543 604 $this->refresh(); 544 605 } 545 606 return $retval; 546 } 547 548 607 } 608 549 609 /** The url to show instead of the portal. If empty, the portal is shown 550 610 Must be enabled in the Network configuration to have any effect … … 554 614 return $this->mRow['custom_portal_redirect_url']; 555 615 } 556 616 557 617 /** The url to show instead of the portal. If empty, the portal is shown 558 618 Must be enabled in the Network configuration to have any effect … … 570 630 return $retval; 571 631 } 572 632 573 633 /** Retrieves the admin interface of this object. 574 634 * @return The HTML fragment for this interface */ … … 577 637 //TODO: Most of this code will be moved to Hotspot class when the abtraction will be completed 578 638 579 //pretty_print_r($_REQUEST);580 //pretty_print_r($this->mRow);639 //pretty_print_r($_REQUEST); 640 //pretty_print_r($this->mRow); 581 641 $html = ''; 582 642 $html .= "<div class='admin_container'>\n"; … … 600 660 // Hashed node_id (this is a workaround since PHP auto-converts HTTP vars var periods, spaces or underscores ) 601 661 $hashed_node_id = md5($this->getId()); 602 662 603 663 // Name 604 664 $html .= "<div class='admin_section_container'>\n"; … … 794 854 $html .= "<div class='admin_section_container'>\n"; 795 855 $html .= "<div class='admin_section_title'>"._("Node configuration:")."</div>\n"; 796 856 797 857 $network = $this->getNetwork(); 798 858 799 859 // Deployment status 800 860 $html .= "<div class='admin_section_container'>\n"; … … 807 867 808 868 // 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()) 823 870 { 824 871 $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"; 832 892 } 833 893 // End Node configuration section 834 894 $html .= "</div>\n"; 835 895 836 896 // Owners management 837 897 $html .= "<div class='admin_section_container'>\n"; … … 936 996 937 997 // Information about the node 938 998 939 999 // Hashed node_id (this is a workaround since PHP auto-converts HTTP vars var periods, spaces or underscores ) 940 1000 $hashed_node_id = md5($this->getId()); 941 1001 942 1002 // Name 943 1003 $name = "node_".$hashed_node_id."_name"; … … 1029 1089 1030 1090 // Node configuration section 1031 1091 1032 1092 $network = $this->getNetwork(); 1033 1093 … … 1037 1097 1038 1098 // 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 1045 1105 // 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 1052 1112 // End Node configuration section 1053 1113 … … 1065 1125 } 1066 1126 } 1067 1127 1068 1128 $name = "node_{$this->getId()}_new_owner_submit"; 1069 1129 if (!empty ($_REQUEST[$name])) … … 1405 1465 $sql = "SELECT * FROM nodes WHERE node_id='{$id_str}'"; 1406 1466 $db->ExecSqlUniqueRes($sql, $row, false); 1407 if ($row!=null)1467 if ($row != null) 1408 1468 { 1409 1469 $retval = true; … … 1430 1490 } // End class 1431 1491 ?> 1492 1493
