get_node_commanders goes to backend
[mirrors/Kyberia-bloodline.git] / wwwroot / backend / mysql / backend.inc
index c85a43fd44de2327e7d30424befed6ffc7cecf00..a9b4915417abd60e12e7265ce3bba71c90957fa4 100644 (file)
@@ -276,10 +276,24 @@ node_parent='$node_handle' order by node_created $orderby LIMIT $offset,$limit";
 public static function GetUserSubmissionsChildren($user_id,$limit=23,$offset=0,$orderby='') {
   global $db;
 
-         $q="select users.*,nodes.* from nodes
-left join users on users.user_id=nodes.node_creator where
-node_creator='$user_id' order by node_created $orderby LIMIT $offset,$limit";
-       //$q="select * from nodes LIMIT 10,10";
+       if (!is_numeric($user_id)) {
+               return -1;
+       }
+       if (!is_numeric($limit)) {
+               return -1;
+       }
+       if (!is_numeric($offset)) {
+               return -1;
+       }
+
+       // XXX orderby mysql escape
+
+       $q = "select child.*, users.login as login, parent.node_name as parent_name from nodes as child join 
+               (select node_id,node_name,node_creator from nodes where node_creator='$user_id')
+               as parent on child.node_parent=parent.node_id and child.node_creator <> '$user_id'
+               join users as users on users.user_id=child.node_creator order by node_created desc
+               $orderby LIMIT $offset,$limit";
+
   #echo $q;
   $result=$db->query($q);
 
@@ -343,6 +357,47 @@ public static function setParent($node_id,$parent_id) {
        return 0;
 }
 
+// Get last submissions of all users on kyberia.
+// XXX ad permission checking
+// XXX remove constants
+
+public static function getLast($params) {
+       global $db,$node,$error,$error_messages;
+
+       if ($params['listing_amount']=='all') $listing_amount='-1';
+       else $listing_amount=addslashes($params['listing_amount']);
+       if (empty($params['offset'])) $offset=0;
+       else $offset=addslashes($params['offset']);
+
+       global $db,$node;
+       if ($node['node_id']==DEF_LAST_NODE)  {
+               $interval=" nodes.node_created>NOW()-INTERVAL 65 HOUR and";
+               $vector="00";
+       }       else {
+
+               $vector=$node['node_vector'];
+               $interval=" nodes.node_created>NOW()-INTERVAL 42 DAY and";
+       }
+
+       $node_id=$node['node_id'];
+       $user_id=$_SESSION['user_id'];
+               $q="select parent.node_name as parent_name,users.*,nodes.* from nodes
+               left join nodes as parent on parent.node_id=nodes.node_parent
+               left  join users on users.user_id=nodes.node_creator where $interval
+               nodes.node_vector like '$vector%'  and
+               nodes.node_system_access!='private' order by nodes.node_id desc LIMIT $offset,$listing_amount ";
+
+       $set=$db->query($q);
+
+       while ($set->next()) {
+               $last[]=$set->getRecord();
+       }
+
+       return $last;
+
+}
+
+
 // Get nodes sorted by weight_k specific to user
 
 public static function getKNeurons($user_id,$interval) {
@@ -427,8 +482,48 @@ public static function getSynapseWeight($user_id,$node_id){
        if (! ($synapse_weight) ) { $synapse_weight = 1;}       
 
        return $synapse_weight;
-
 }
+
+// getNodeUserlist
+
+// Get list of users currently viewing specified node.
+// Secure.
+// Returns list of (login, user_id)
+
+public static function getNodeUserlist($node_id) {
+
+       global $db;
+       if (!is_numeric($node_id))
+                { return -1; }
+               
+
+       $set=$db->query("select login,user_id from users where user_action_id='$node_id'");
+       while ($set->next()) {
+               $userlist[]=$set->getRecord();
+       }
+
+       return $userlist;
 }
 
+// getNodeCommanders
+
+// Get logins of all node commanders (used in configure)
+// Secure.
+// Returns list of (node_permission, login)
+
+
+public static function getNodeCommanders($node_id) {
+       global $db;
+       $set=$db->query("select node_permission,users.login from node_access 
+                       left join users on node_access.user_id=users.user_id where 
+                       node_id='$node_id' and node_permission!='' order by node_permission");
+
+       while ($set->next()) {
+               $commanders[$set->getString('node_permission')].=$set->getString('login').";";
+       }
+
+       return $commanders;
+}
+       
+}
 ?>
This page took 0.153311 seconds and 4 git commands to generate.