Show
Ignore:
Timestamp:
09/03/06 18:54:01 (6 years ago)
Author:
max-horvath
Message:

"2006-09-03 Max Horvath <max.horvath@…>

  • The term SPLASH_ONLY_USER displayed to people visiting the portal has been replaced by the more meaningful term \"anonymous user\" (fixes #106)
  • When creating a new node and choosing an existing node_id there will be shown an error message (fixes #223)
  • If one or more nodes aren't monitored they now will be announced on the front page (instead of just showing the number of monitored online nodes) (fixes #100)
  • Display more meaningful error messages if required user permissions are missing (fixes #242)
  • Refactored Network->getAdminUI() to match look and feel of Node->getAdminUI (fixes #140)
  • Show descriptive status of node (fixes #241)"
Files:
1 modified

Legend:

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

    r1088 r1089  
    5151require_once('classes/DateTime.php'); 
    5252require_once('classes/InterfaceElements.php'); 
     53require_once('classes/MainUI.php'); 
    5354 
    5455/** 
     
    6869        private $id; 
    6970        private static $current_node_id = null; 
     71 
     72        /** 
     73         * List of deployment statuses 
     74         * 
     75         * @var array 
     76         * @access private 
     77         */ 
     78        private $_deploymentStatuses = array(); 
    7079 
    7180        /** 
     
    187196        } 
    188197 
    189         /** Create a new Node in the database 
    190          * @param $node_id The id to be given to the new node.  If not present, a 
    191          * guid will be assigned. 
    192          * @param $network Network object.  The node's network.  If not present, 
    193          * the current Network will be assigned 
    194          * 
    195          * @return the newly created Node object, or null if there was an error 
    196          */ 
    197         static function createNewObject($node_id = null, $network = null) 
    198         { 
    199                 global $db; 
    200                 if (empty ($node_id)) 
    201                 { 
     198        /** 
     199         * Create a new Node in the database 
     200         * 
     201         * @param string $node_id The Id to be given to the new node.  If not 
     202         *                        present, guid will be assigned. 
     203         * @param object $network Network object.  The node's network.  If not 
     204         *                        present, the current Network will be assigned 
     205         * 
     206         * @return mixed The newly created Node object, or null if there was 
     207         *               an error 
     208         * 
     209         * @static 
     210         * @access public 
     211         */ 
     212        public static function createNewObject($node_id = null, $network = null) 
     213        { 
     214            // Define globals 
     215                global $db; 
     216 
     217                if (empty ($node_id)) { 
    202218                        $node_id = get_guid(); 
    203219                } 
     220 
    204221                $node_id = $db->escapeString($node_id); 
    205222 
    206                 if (empty ($network)) 
    207                 { 
    208                         $network = Network :: getCurrentNetwork(); 
    209                 } 
     223                if (empty ($network)) { 
     224                        $network = Network::getCurrentNetwork(); 
     225                } 
     226 
    210227                $network_id = $db->escapeString($network->getId()); 
    211228 
    212229                $node_deployment_status = $db->escapeString("IN_PLANNING"); 
    213230                $node_name = _("New node"); 
    214                 if (Node :: nodeExists($node_id)) 
    215                         throw new Exception(_('This node already exists.')); 
    216  
    217                 $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')"; 
    218  
    219                 if (!$db->execSqlUpdate($sql, false)) 
    220                 { 
    221                         throw new Exception(_('Unable to insert new node into database!')); 
    222                 } 
    223                 $object = new self($node_id); 
    224                 return $object; 
     231 
     232                try { 
     233            if (Node::nodeExists($node_id)) { 
     234                throw new Exception(_('This node already exists.')); 
     235            } 
     236 
     237            $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')"; 
     238 
     239            if (!$db->execSqlUpdate($sql, false)) { 
     240                throw new Exception(_('Unable to insert new node into database!')); 
     241            } 
     242 
     243            $object = new self($node_id); 
     244 
     245            return $object; 
     246        } catch (Exception $e) { 
     247            $ui = new MainUI(); 
     248            $ui->setToolSection('ADMIN'); 
     249            $ui->displayError($e->getMessage(), false); 
     250            exit; 
     251        } 
    225252        } 
    226253 
     
    235262                $html = ''; 
    236263                $name = "{$user_prefix}"; 
     264 
     265        $_deploymentStatuses = array( 
     266            "DEPLOYED" => _("Deployed"), 
     267            "IN_PLANNING" => _("In planning"), 
     268            "IN_TESTING" => _("In testing"), 
     269            "NON_WIFIDOG_NODE" => _("Non-Wifidog node"), 
     270            "PERMANENTLY_CLOSED" => _("Permanently closed"), 
     271            "TEMPORARILY_CLOSED" => _("Temporarily closed") 
     272            ); 
     273 
    237274                $sql = "SELECT node_id, name, node_deployment_status, is_splash_only_node from nodes WHERE 1=1 $sql_additional_where ORDER BY lower(node_id)"; 
    238275                $node_rows = null; 
    239276                $db->execSql($sql, $node_rows, false); 
    240                 if ($node_rows != null) 
    241                 { 
     277 
     278                if ($node_rows != null) { 
    242279                        Utils :: natsort2d($node_rows, "node_id"); 
    243280                        if ($type_interface != "table") { 
     
    267304                                { 
    268305                                        $href = GENERIC_OBJECT_ADMIN_ABS_HREF."?object_id={$node_row['node_id']}&object_class=Node&action=edit"; 
    269                                         $html .= "\t\t\t\t<tr class='row' onclick=\"javascript:location.href='{$href}'\">\n\t\t\t\t\t<td>{$node_row['name']}<noscript>(<a href='{$href}'>edit</a>)</noscript></td>\n\t\t\t\t\t<td>{$node_row['node_id']}</td>\n\t\t\t\t\t<td>{$node_row['node_deployment_status']}</td>\n\t\t\t\t</tr>\n"; 
     306                                        $_deployStatusNode = $node_row['node_deployment_status']; 
     307                                        $html .= "\t\t\t\t<tr class='row' onclick=\"javascript:location.href='{$href}'\">\n\t\t\t\t\t<td>{$node_row['name']}<noscript>(<a href='{$href}'>edit</a>)</noscript></td>\n\t\t\t\t\t<td>{$node_row['node_id']}</td>\n\t\t\t\t\t<td>{$_deploymentStatuses[$_deployStatusNode]}</td>\n\t\t\t\t</tr>\n"; 
    270308                                } 
    271309                                $html .= "\t\t\t</tbody>\n\t\t</table>\n"; 
     
    317355        } 
    318356 
    319         /** Process the new object interface. 
    320          *  Will return the new object if the user has the credentials and the form was fully filled. 
     357        /** 
     358         * Process the new object interface. 
     359         * 
     360         * Will return the new object if the user has the credentials and the form was fully filled. 
    321361         * @return the node object or null if no new node was created. 
    322362         */ 
    323         static function processCreateNewObjectUI() 
    324         { 
     363        public static function processCreateNewObjectUI() 
     364        { 
     365            // Init values 
    325366                $retval = null; 
    326367                $name = "new_node_id"; 
    327                 if (!empty ($_REQUEST[$name])) 
    328                 { 
     368 
     369                if (!empty ($_REQUEST[$name])) { 
    329370                        $node_id = $_REQUEST[$name]; 
    330371                        $name = "new_node_network_id"; 
    331                         if (!empty ($_REQUEST[$name])) 
    332                         { 
    333                                 $network = Network :: getObject($_REQUEST[$name]); 
     372 
     373                        if (!empty ($_REQUEST[$name])) { 
     374                                $network = Network::getObject($_REQUEST[$name]); 
     375                        } else { 
     376                                $network = Network::processSelectNetworkUI('new_node'); 
    334377                        } 
    335                         else 
    336                         { 
    337                                 $network = Network :: processSelectNetworkUI('new_node'); 
     378 
     379                        if ($node_id && $network) { 
     380                            try { 
     381                                if (!$network->hasAdminAccess(User :: getCurrentUser())) { 
     382                                        throw new Exception(_("Access denied")); 
     383                                } 
     384                } catch (Exception $e) { 
     385                    $ui = new MainUI(); 
     386                    $ui->setToolSection('ADMIN'); 
     387                    $ui->displayError($e->getMessage(), false); 
     388                    exit; 
     389                } 
     390 
     391                                $retval = self::createNewObject($node_id, $network); 
    338392                        } 
    339                         if ($node_id && $network) 
    340                         { 
    341                                 if (!$network->hasAdminAccess(User :: getCurrentUser())) 
    342                                 { 
    343                                         throw new Exception(_("Access denied")); 
    344                                 } 
    345                                 $retval = self :: createNewObject($node_id, $network); 
    346                         } 
    347                 } 
     393                } 
     394 
    348395                return $retval; 
    349396        } 
     
    377424 
    378425                foreach ($status_list as $status) { 
    379                         $tab[] = array($status['node_deployment_status'], $status['node_deployment_status']); 
     426                    $_statusvalue = $status['node_deployment_status']; 
     427                        $tab[] = array($_statusvalue, $this->_deploymentStatuses["$_statusvalue"]); 
    380428                } 
    381429 
     
    385433        } 
    386434 
    387         /** Get the selected deployment status 
    388          * @param $user_prefix A identifier provided by the programmer to recognise it's generated form 
    389          * @return the deployment status 
     435        /** 
     436         * Get the selected deployment status 
     437         * 
     438         * @param string $user_prefix An identifier provided by the programmer to 
     439         *                            recognise it's generated form 
     440         * 
     441         * @return string The deployment status 
     442         * 
     443         * @access public 
    390444         */ 
    391445        public function processSelectDeploymentStatus($user_prefix) 
     
    410464                        throw new Exception(sprintf(_("The node %s could not be found in the database!"), $node_id_str)); 
    411465                } 
     466 
     467        $this->_deploymentStatuses = array( 
     468            "DEPLOYED" => _("Deployed"), 
     469            "IN_PLANNING" => _("In planning"), 
     470            "IN_TESTING" => _("In testing"), 
     471            "NON_WIFIDOG_NODE" => _("Non-Wifidog node"), 
     472            "PERMANENTLY_CLOSED" => _("Permanently closed"), 
     473            "TEMPORARILY_CLOSED" => _("Temporarily closed") 
     474            ); 
     475 
    412476                $this->mRow = $row; 
    413477                $this->id = $row['node_id']; 
     
    744808         * Retrieves the admin interface of this object 
    745809         * 
    746          * @return The HTML fragment for this interface 
     810         * @return string The HTML fragment for this interface 
    747811         * 
    748812         * @access public 
     
    756820                $html = ''; 
    757821 
    758                 if (!User::getCurrentUser()) { 
    759                         throw new Exception(_('Access denied!')); 
    760                 } 
     822                try { 
     823                if (!User::getCurrentUser()) { 
     824                        throw new Exception(_('Access denied!')); 
     825                } 
     826        } catch (Exception $e) { 
     827            $ui = new MainUI(); 
     828            $ui->setToolSection('ADMIN'); 
     829            $ui->displayError($e->getMessage(), false); 
     830            exit; 
     831        } 
    761832 
    762833                // Get information about the network 
     
    9961067        } 
    9971068 
    998         /** Process admin interface of this object. 
    999         */ 
     1069        /** 
     1070         * Process admin interface of this object. 
     1071         * 
     1072         * @return void 
     1073         * 
     1074         * @access public 
     1075         */ 
    10001076        public function processAdminUI() 
    10011077        { 
    1002                 $user = User :: getCurrentUser(); 
    1003  
    1004                 if (!$this->isOwner($user) && !$user->isSuperAdmin()) 
    1005                 { 
    1006                         throw new Exception(_('Access denied!')); 
    1007                 } 
     1078                $user = User::getCurrentUser(); 
     1079 
     1080                try { 
     1081                if (!$this->isOwner($user) && !$user->isSuperAdmin()) { 
     1082                        throw new Exception(_('Access denied!')); 
     1083                } 
     1084        } catch (Exception $e) { 
     1085            $ui = new MainUI(); 
     1086            $ui->setToolSection('ADMIN'); 
     1087            $ui->displayError($e->getMessage(), false); 
     1088            exit; 
     1089        } 
    10081090 
    10091091                // Check if user is a admin 
     
    12881370        } 
    12891371 
    1290         /** The list of users online at this node 
    1291          * @return An array of User object, or en empty array */ 
    1292         function getOnlineUsers() 
    1293         { 
    1294                 global $db; 
    1295                 $retval = array (); 
     1372        /** 
     1373         * The list of users online at this node 
     1374         * 
     1375         * @return array An array of User object, or an empty array 
     1376         * 
     1377         * @access public 
     1378         */ 
     1379        public function getOnlineUsers() 
     1380        { 
     1381            // Define globals 
     1382                global $db; 
     1383 
     1384                // Init values 
     1385                $retval = array(); 
    12961386                $users = null; 
     1387                $anonUsers = 0; 
     1388 
    12971389                $db->execSql("SELECT users.user_id FROM users,connections WHERE connections.token_status='".TOKEN_INUSE."' AND users.user_id=connections.user_id AND connections.node_id='{$this->id}'", $users, false); 
    1298                 if ($users != null) 
    1299                 { 
    1300                         foreach ($users as $user_row) 
    1301                         { 
    1302                                 $retval[] = User :: getObject($user_row['user_id']); 
     1390 
     1391                if ($users != null) { 
     1392                        foreach ($users as $user_row) { 
     1393                            if ($this->isConfiguredSplashOnly()) { 
     1394                                if (User::getObject($user_row['user_id']) == "SPLASH_ONLY_USER") { 
     1395                                    $anonUsers++; 
     1396                                } else { 
     1397                                        $retval[] = User::getObject($user_row['user_id']); 
     1398                                } 
     1399                            } else { 
     1400                                    $retval[] = User::getObject($user_row['user_id']); 
     1401                            } 
    13031402                        } 
    1304                 } 
     1403 
     1404                    if ($this->isConfiguredSplashOnly() && $anonUsers == 1) { 
     1405                            $retval[] = "One anonymous user"; 
     1406                    } else if ($this->isConfiguredSplashOnly() && $anonUsers > 1) { 
     1407                            $retval[] = sprintf("%d anonymous users", $anonUsers); 
     1408                    } 
     1409                } 
     1410 
    13051411                return $retval; 
    13061412        } 
    13071413 
    1308         /** Find out how many users are online this specific Node 
    1309          * @return Number of online users 
    1310          */ 
    1311         function getNumOnlineUsers() 
    1312         { 
    1313                 global $db; 
     1414        /** 
     1415         * Find out how many users are online this specific Node 
     1416         * 
     1417         * @return int Number of online users 
     1418         * 
     1419         * @access public 
     1420         */ 
     1421        public function getNumOnlineUsers() 
     1422        { 
     1423            // Define globals 
     1424                global $db; 
     1425 
     1426                // Init values 
    13141427                $retval = array (); 
    13151428                $row = null; 
    1316                 if(!$this->isConfiguredSplashOnly()) 
     1429 
     1430                if (!$this->isConfiguredSplashOnly()) { 
    13171431                        $db->execSqlUniqueRes("SELECT COUNT(DISTINCT users.user_id) as count FROM users,connections WHERE connections.token_status='".TOKEN_INUSE."' AND users.user_id=connections.user_id AND connections.node_id='{$this->id}'", $row, false); 
    1318                 else 
     1432                } else { 
    13191433                        $db->execSqlUniqueRes("SELECT COUNT(DISTINCT connections.user_mac) as count FROM connections WHERE connections.token_status='".TOKEN_INUSE."' AND connections.node_id='{$this->id}'", $row, false); 
     1434                } 
     1435 
    13201436                return $row['count']; 
    13211437        }