Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 23.54 KB | None | 0 0
  1. <?php
  2. require_once("ObjectChat.php");
  3. require_once("ObjectGraphic.php");
  4. require_once("ObjectLocation.php");
  5. require_once("Common_Functions.php");
  6. require_once("Constants.php");
  7. //define("AMFPHP_BASE", "../../core/");
  8. //require_once("../../core/shared/util/Authenticate.php");
  9.  
  10.  
  11. class ProteanObject {
  12.  
  13.     var $methodTable = array(
  14.         "pushObject" => array("description" => "Pushes a protean object to the server db","access" => "remote","roles" => "admin,user"),
  15.         "getNewObjects" => array("description" => "Fetches new protean objects from the server db","access" => "remote","roles" => "admin,user,guest"),
  16.         "deleteObject" => array("description" => "Deletes a protean object from the server db","access" => "remote","roles" => "admin,user"),
  17.         "getNewChats" => array("description" => "Gets new chats from the server db","access" => "remote","roles" => "admin,user,guest"),
  18.         "pushNewMessage" => array("description" => "Pushes a chat message into the server db","access" => "remote","roles" => "admin,user,guest"),
  19.         "getNewFiles" => array("description" => "Fetches new files' info from the server db","access" => "remote","roles" => "admin,user,guest"),
  20.         "getProjectDetails" => array("description" => "Gets project details for the project logged into","access" => "remote","roles" => "admin,user,guest"),
  21.         "pushNewFile" => array("description" => "Pushes a file's info to the server db","access" => "remote","roles" => "admin"),
  22.         "deleteFile" => array("description" => "Deletes a files' info from the server db","access" => "remote","roles" => "admin"),
  23.         "registerCbr" => array("description" => "Registers a collaborator into a project - also logs them into the project if registered","access" => "remote","roles" => "admin,user,guest"),
  24.         "getUpdates" => array("description" => "Get updates from the updation timeline","access" => "remote","roles" => "admin,user,guest"),
  25.         "unregCbr" => array("description" => "Logs out a collaborator from a project","access" => "remote","roles" => "admin,user,guest"),
  26.         "getUsers" => array("description" => "Get a list of all collaborators for the project presently logged into","access" => "remote","roles" => "admin,user,guest"),
  27.         "getAllChats" => array("description" => "Gets all chats for the present project","access" => "remote","roles" => "admin,user,guest"),
  28.         "getProjects" => array("description" => "Gets all projects for which the present user is registered","access" => "remote","roles" => "admin,user,guest"),
  29.         "addProject" => array("description" => "Adds a new project","access" => "remote","roles" => "admin"),
  30.         "deleteProject" => array("description" => "Deletes a project","access" => "remote","roles" => "admin"),
  31.         "addUserAndCbr" => array("description" => "Adds a new user and then calls addCbr","access" => "remote","roles" => "admin"),
  32.         "addCbr" => array("description" => "Adds a collaborator to a project","access" => "remote","roles" => "admin"),
  33.         "getFilesForProjects" => array("description" => "Gets all files for an array of Project Ids","access" => "remote","roles" => "admin")
  34.     );
  35.  
  36.     public $id;
  37.     public $file_id;
  38.     public $project_id;
  39.     public $creator;
  40.     public $objChat;
  41.     public $objGraphic;
  42.     public $objLocation;
  43.    
  44.     function beforeFilter($function_called) {
  45.         if(array_key_exists($function_called,$this->methodTable)) {
  46.             if(Authenticate::isUserInRole($this->methodTable[$function_called]["roles"])==true) {
  47.                 return true;
  48.             }
  49.             else {
  50.                 return false;
  51.             }
  52.         }
  53.         else {
  54.             return true;
  55.         }
  56.     }
  57.        
  58.     public function pushObject($pobj=NULL) {
  59.         $this->file_id = $pobj['file_id'];
  60.         $this->project_id = $pobj['project_id'];
  61.         $this->creator = $pobj['creator'];
  62.         $this->objChat = $pobj['objChat'];
  63.         $this->objGraphic = $pobj['objGraphic'];
  64.         $this->objGraphic['created'] = getLocalTime();
  65.         $this->objLocation = $pobj['objLocation'];
  66.  
  67.         $loc = serialize($this->objLocation);
  68.         $gra = serialize($this->objGraphic);
  69.         $cha = serialize($this->objChat);
  70. /*      $myFile = "log1.txt";
  71.         $fh = fopen($myFile, 'w');
  72.         fwrite($fh, $loc);
  73.         fclose($fh);*/
  74.        
  75.         $sql_connection = connect_to_db();
  76.         $query = "INSERT INTO project".$this->project_id."
  77.                     (`object_file_id`,`object_creator`,`object_location`,`object_graphic`,`object_chat`)
  78.                     VALUES ({$this->file_id},'{$this->creator}','{$loc}','{$gra}','{$cha}')";
  79.         $result_set = mysql_query($query);
  80.         confirm_query($result_set);
  81.         $this->id = mysql_insert_id();
  82.         mysql_close($sql_connection);
  83.         $this->serverUpdate($this->project_id,"newmarkup",$this->file_id,4);
  84.     }
  85.    
  86.     public function getLocationsByFileId($f_id,$p_id) {
  87.         $sql_connection = connect_to_db();
  88.         $query = "SELECT object_location
  89.                     FROM project".$p_id."
  90.                     WHERE object_file_id={$f_id}";
  91.         $result_set = mysql_query($query,$sql_connection);
  92.         confirm_query($result_set);
  93.         $loc_set = array();
  94.         while($result = mysql_fetch_array($result_set)) {
  95.             $loc_set[] = unserialize($result['object_location']);
  96.         }
  97.         mysql_close($sql_connection);
  98.         return $loc_set;
  99.     }
  100.    
  101.     public function getGraphicsByLocation($loc,$f_id,$p_id) {
  102.         //$objl = new ObjectLocation;
  103.         //$objl->type = $loc['type'];
  104.         //$objl->value = $loc['value'];
  105.         //$sloc = serialize($objl);
  106.         $this->objLocation = $loc;
  107.         $sloc = serialize($this->objLocation);
  108.         $myFile = "log2.txt";
  109.         $fh = fopen($myFile, 'w');
  110.         fwrite($fh, $sloc);
  111.         fclose($fh);
  112.         $sql_connection = connect_to_db();
  113.         $query = "SELECT object_graphic
  114.                     FROM project".$p_id."
  115.                     WHERE object_file_id={$f_id}
  116.                     AND object_location='".$sloc."'";
  117.         $result_set = mysql_query($query,$sql_connection);
  118.         confirm_query($result_set);
  119.         $gra_set = array();
  120.         while($result = mysql_fetch_array($result_set)) {
  121.             $gra_set[] = unserialize($result['object_graphic']);
  122.         }
  123.         mysql_close($sql_connection);
  124.         return $gra_set;
  125.     }
  126.  
  127.     public function getNewObjects($f_id,$p_id,$latest_object_id) {
  128.         $sql_connection = connect_to_db();
  129.         $query = "SELECT *
  130.                     FROM project".$p_id."
  131.                     WHERE object_file_id={$f_id}
  132.                     AND object_id>{$latest_object_id}";
  133.         $result_set = mysql_query($query,$sql_connection);
  134.         confirm_query($result_set);
  135.         $poArray = array();
  136.         while($result = mysql_fetch_array($result_set)) {
  137.  
  138.             $pobj = new ProteanObject;
  139.             $pobj->id = $result['object_id'];
  140.             $pobj->project_id = $p_id;
  141.             $pobj->file_id = $f_id;
  142.             $pobj->creator = $result['object_creator'];
  143.             $pobj->objLocation = unserialize($result['object_location']);
  144.             $pobj->objGraphic = unserialize($result['object_graphic']);
  145.             $pobj->objChat = unserialize($result['object_chat']);
  146.  
  147.             $poArray[] = $pobj;
  148.         }
  149.         mysql_close($sql_connection);
  150.         return $poArray;
  151.     }
  152.     public function deleteObject($f_id,$p_id,$object_id) {
  153.         $sql_connection = connect_to_db();
  154.         $query = "DELETE FROM project".$p_id."
  155.                     WHERE object_file_id=".$f_id."
  156.                     AND object_id=".$object_id."
  157.                     LIMIT 1";
  158.         $result_set = mysql_query($query,$sql_connection);
  159.         confirm_query($result_set);
  160.         mysql_close($sql_connection);
  161.         return $result_set;
  162.     }
  163.    
  164.     public function getAllChats($p_id) {
  165.         $sql_connection = connect_to_db();
  166.         $query = "SELECT *
  167.                     FROM chats
  168.                     WHERE chat_project_id={$p_id}";
  169.         $result_set = mysql_query($query,$sql_connection);
  170.         confirm_query($result_set);
  171.         $resultArray = array();
  172.         while($result = mysql_fetch_array($result_set)) {
  173.             $resultArray[] = $result;
  174.         }
  175.         mysql_close($sql_connection);
  176.         return $resultArray;
  177.     }
  178.    
  179.     public function getNewChats($p_id,$chat_id) {
  180.         $sql_connection = connect_to_db();
  181.         $query = "SELECT *
  182.                     FROM chats
  183.                     WHERE chat_project_id={$p_id}
  184.                     AND chat_id>{$chat_id}";
  185.         $result_set = mysql_query($query,$sql_connection);
  186.         confirm_query($result_set);
  187.         $resultArray = array();
  188.         while($result = mysql_fetch_array($result_set)) {
  189.             $resultArray[] = $result;
  190.         }
  191.         mysql_close($sql_connection);
  192.        
  193.         return $resultArray;
  194.     }
  195.    
  196.     public function pushNewMessage($p_id,$creator,$text) {
  197.         $created = getLocalTime();
  198.         $sql_connection = connect_to_db();
  199.         $query = "INSERT INTO chats
  200.                     (`chat_project_id`,`chat_creator`,`chat_created`,`chat_text`)
  201.                     VALUES ('{$p_id}','{$creator}','{$created}','{$text}')";
  202.         $result_set = mysql_query($query);
  203.         confirm_query($result_set);
  204.         mysql_close($sql_connection);
  205.         $this->serverUpdate($p_id,"newchat",$creator,3);
  206.     }
  207.    
  208.     public function getNewFiles($p_id,$file_id) {
  209.         $sql_connection = connect_to_db();
  210.         $query = "SELECT file_id,file_name,file_link,file_type
  211.                     FROM files
  212.                     WHERE file_project_id={$p_id}
  213.                     AND file_id>{$file_id}";
  214.         $result_set = mysql_query($query,$sql_connection);
  215.         confirm_query($result_set);
  216.         $resultArray = array();
  217.         while($result = mysql_fetch_array($result_set)) {
  218.             $resultArray[] = $result;
  219.         }
  220.         mysql_close($sql_connection);
  221.         return $resultArray;
  222.     }
  223.    
  224.     public function getProjectDetails($p_id) {
  225.         $sql_connection = connect_to_db();
  226.         $query = "SELECT project_name, project_create_date
  227.                     FROM projects
  228.                     WHERE project_id={$p_id}
  229.                     LIMIT 1";
  230.         $result_set = mysql_query($query,$sql_connection);
  231.         confirm_query($result_set);
  232.         $result = mysql_fetch_array($result_set);
  233.         mysql_close($sql_connection);
  234.         return $result;
  235.     }
  236.    
  237.     public function pushNewFile($f_pid,$f_name,$f_link,$f_type,$f_uploader) {
  238.         $sql_connection = connect_to_db();
  239.         $query = "SELECT file_id
  240.                     FROM files
  241.                     WHERE file_name='{$f_name}'
  242.                     AND file_project_id={$f_pid}";
  243.         $result_set = mysql_query($query);
  244.         confirm_query($result_set);
  245.         if($r = mysql_fetch_array($result_set)) {
  246.             return false;
  247.         }
  248.         $query = "INSERT INTO files
  249.                     (`file_project_id`,`file_name`,`file_uploader`,`file_link`,`file_type`)
  250.                     VALUES ('{$f_pid}','{$f_name}','{$f_uploader}','{$f_link}',{$f_type})";
  251.         $result_set = mysql_query($query);
  252.         confirm_query($result_set);
  253.         mysql_close($sql_connection);
  254.         $this->serverUpdate($f_pid,"newfileadded",$f_uploader,1);
  255.         return true;
  256.     }
  257.    
  258.     public function deleteFile($f_pid,$f_name,$cbr_name) {
  259.         $sql_connection = connect_to_db();
  260.         $query = "DELETE FROM files
  261.                     WHERE `file_project_id`=".$f_pid."
  262.                     AND file_name='".$f_name."'
  263.                     LIMIT 1";
  264.         $result_set = mysql_query($query);
  265.         confirm_query($result_set);
  266.         mysql_close($sql_connection);
  267.         $this->serverUpdate($f_pid,"filedeleted",$cbr_name,1);
  268.         return $result_set;
  269.     }
  270.    
  271.     public function getUsers($project_id) {
  272.         $sql_connection = connect_to_db();
  273.         $query = "SELECT * FROM collaborators
  274.                     WHERE collaborator_project_id={$project_id}";
  275.         $result_set = mysql_query($query);
  276.         confirm_query($result_set);
  277.         mysql_close($sql_connection);
  278.         return $result_set;
  279.     }
  280.    
  281.     public function registerCbr($project_id,$cbr_name,$cbr_email="") {
  282.         $sql_connection = connect_to_db();
  283.         $query = "SELECT * FROM collaborators
  284.                     WHERE collaborator_name='{$cbr_name}'
  285.                     AND collaborator_project_id={$project_id}
  286.                     AND collaborator_status='offline'";
  287.         $cbr_result_set = mysql_query($query);
  288.         confirm_query($cbr_result_set);
  289.         $time = getLocalTime();
  290.         if(mysql_num_rows($cbr_result_set)>0) {
  291.             $query = "UPDATE collaborators
  292.                         SET collaborator_status='online'
  293.                         WHERE collaborator_name='{$cbr_name}'
  294.                         AND collaborator_project_id={$project_id}";
  295.             $result_set = mysql_query($query);
  296.             confirm_query($result_set);
  297.         }
  298.         else {
  299.             return false;
  300.         }
  301.         $query = "SELECT update_id
  302.                     FROM updates
  303.                     WHERE update_time<'{$time}'
  304.                     ORDER BY update_id DESC
  305.                     LIMIT 1";
  306.         $result_set = mysql_query($query);
  307.         confirm_query($result_set);
  308.         if($result = mysql_fetch_array($result_set)) {
  309.             $latest_update_id=$result['update_id']+1;
  310.         }
  311.         else {
  312.             $latest_update_id=0;
  313.         }
  314.         mysql_close($sql_connection);
  315.         $this->serverUpdate($project_id,"useronline",$cbr_name,2);
  316.         return array($latest_update_id);
  317.     }
  318.    
  319.     public function getUpdates($project_id,$latest_update_id,$cbr_name) {
  320.         $sql_connection = connect_to_db();
  321.         $time = getLocalTime();
  322.         $query = "UPDATE collaborators
  323.                     SET collaborator_pinged='{$time}'
  324.                     WHERE collaborator_project_id={$project_id}
  325.                     AND collaborator_name='{$cbr_name}'";
  326.         $result_set = mysql_query($query);
  327.         confirm_query($result_set);
  328.         $query = "SELECT update_id,update_header,update_body
  329.                     FROM updates
  330.                     WHERE update_project_id={$project_id}
  331.                     AND update_id>{$latest_update_id}";
  332.         $result_set = mysql_query($query);
  333.         confirm_query($result_set);
  334.         //return $result_set;
  335.         $resultArray = array();
  336.         while($result = mysql_fetch_array($result_set)) {
  337.             //$updateLine = new Array();
  338.             $updateLine['update_id']=$result['update_id'];
  339.             $updateLine['update_header']=$result['update_header'];
  340.             $updateLine['update_body']=unserialize($result['update_body']);
  341.             $updateLine['update_level']=$result['update_level'];
  342.             $resultArray[] = $updateLine;
  343.         }
  344.         mysql_close($sql_connection);
  345.         return $resultArray;
  346.     }
  347.    
  348.     public function serverUpdate($project_id,$header,$body,$level) {
  349.         $sql_connection = connect_to_db();
  350.         $time = getLocalTime();
  351.         $newBody = serialize($body);                                    // body is serialized
  352.         $query = "INSERT INTO updates
  353.                     (`update_project_id`,`update_header`,`update_body`,`update_level`,`update_time`)
  354.                     VALUES ({$project_id},'{$header}','{$newBody}',{$level},'{$time}')";
  355.         $result_set = mysql_query($query);
  356.         confirm_query($result_set);
  357.         mysql_close($sql_connection);
  358.     }
  359.    
  360.     public function unregCbr($project_id,$cbr_name) {
  361.         $sql_connection = connect_to_db();
  362.         $query = "UPDATE collaborators
  363.             SET collaborator_status = 'offline'
  364.             WHERE collaborator_project_id={$project_id}
  365.             AND collaborator_name='{$cbr_name}'";
  366.         $result_set = mysql_query($query);
  367.         confirm_query($result_set);
  368.         mysql_close($sql_connection);
  369.         $this->serverUpdate($project_id,"useroffline",$cbr_name,2);
  370.     }
  371.    
  372.     public function userLogin($username,$pass) {
  373.         $sql_connection = connect_to_db();
  374.         $hashed_pass = sha1($pass);
  375.         $query = "SELECT user_roles
  376.                     FROM users
  377.                     WHERE user_name='".$username."'
  378.                     AND user_pass='".$hashed_pass."'
  379.                     LIMIT 1";
  380.         $result_set = mysql_query($query);
  381.         confirm_query($result_set);
  382.         if($result=mysql_fetch_array($result_set)) {
  383.             $query = "SELECT collaborator_project_id
  384.                         FROM collaborators
  385.                         WHERE collaborator_name='{$username}'
  386.                         AND collaborator_status='online'
  387.                         LIMIT 1";
  388.             $rs = mysql_query($query);
  389.             confirm_query($rs);
  390.             if($r = mysql_fetch_array($rs)) {
  391.                 return false;
  392.             }
  393.             Authenticate::login($username,$result['user_roles']);
  394.             mysql_close($sql_connection);
  395.             return $result['user_roles'];
  396.         }
  397.         mysql_close($sql_connection);
  398.         return false;
  399.     }
  400.     public function check_if_logged_in() {
  401.         return Authenticate::isAuthenticated();
  402.     }
  403.     public function getProjects($username) {
  404.         $sql_connection = connect_to_db();
  405.         $query = "SELECT project_id,project_name
  406.                     FROM projects
  407.                     WHERE project_id IN
  408.                     (SELECT collaborator_project_id FROM collaborators WHERE collaborator_name='{$username}')";
  409.         $result_set = mysql_query($query);
  410.         confirm_query($result_set);
  411.         $resultArray = array();
  412.         while($result = mysql_fetch_array($result_set)) {
  413.             $resultArray[]=array("project_id"=>$result['project_id'],"project_name"=>$result['project_name']);
  414.         }
  415.         mysql_close($sql_connection);
  416.         return $resultArray;
  417.     }
  418.    
  419.     public function addProject($pname,$cname) {
  420.         $created = getLocalTime();
  421.         $sql_connection = connect_to_db();
  422.         $query = "SELECT project_id
  423.                     FROM projects
  424.                     WHERE project_name='{$pname}'";
  425.         $result_set = mysql_query($query);
  426.         confirm_query($result_set);
  427.         if($result = mysql_fetch_array($result_set)) {
  428.             return false;
  429.         }
  430.         $query = "INSERT INTO projects
  431.                     (project_name,project_create_date)
  432.                     VALUES ('{$pname}','{$created}')";
  433.         $result_set = mysql_query($query);
  434.         confirm_query($result_set);
  435.         $pid = mysql_insert_id();
  436.         $query = "CREATE TABLE `project".$pid."` (
  437.                     `object_id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  438.                     `object_file_id` BIGINT( 20 ) NOT NULL ,
  439.                     `object_creator` VARCHAR( 20 ) NOT NULL ,
  440.                     `object_location` BLOB NOT NULL ,
  441.                     `object_graphic` BLOB NOT NULL ,
  442.                     `object_chat` BLOB NOT NULL
  443.                     ) ENGINE = MYISAM ;";
  444.         $result_set = mysql_query($query);
  445.         confirm_query($result_set);
  446.         $query = "INSERT INTO collaborators
  447.                     (collaborator_project_id,collaborator_name,collaborator_status)
  448.                     VALUES ({$pid},'{$cname}','offline')";
  449.         $result_set = mysql_query($query);
  450.         confirm_query($result_set);
  451.         mysql_close($sql_connection);
  452.         $this->serverUpdate($pid,"newprojectadded",$pname,1);
  453.         return true;
  454.     }
  455.     public function deleteProject($pid) {
  456.         $sql_connection = connect_to_db();
  457.         $query = "DELETE FROM projects
  458.                     WHERE project_id={$pid}
  459.                     LIMIT 1";
  460.         $result_set = mysql_query($query);
  461.         confirm_query($result_set);
  462.        
  463.         $query = "DROP TABLE project{$pid}";
  464.         $result_set = mysql_query($query);
  465.         confirm_query($result_set);
  466.        
  467.         $query = "DELETE FROM collaborators
  468.                     WHERE collaborator_project_id={$pid}";
  469.         $result_set = mysql_query($query);
  470.         confirm_query($result_set);
  471.        
  472.         $query = "DELETE FROM chats
  473.                     WHERE chat_project_id={$pid}";
  474.         $result_set = mysql_query($query);
  475.         confirm_query($result_set);
  476.        
  477.         $query = "DELETE FROM files
  478.                     WHERE file_project_id={$pid}";
  479.         $result_set = mysql_query($query);
  480.         confirm_query($result_set);
  481.         mysql_close($sql_connection);
  482.     }
  483.    
  484.     public function getAllUsers() {
  485.         $sql_connection = connect_to_db();
  486.         $query = "SELECT user_id,user_name
  487.                     FROM users";
  488.         $result_set = mysql_query($query);
  489.         confirm_query($result_set);
  490.         $resultArray = array();
  491.         while($result = mysql_fetch_array($result_set)) {
  492.             $resultArray[] = array("user_id" => $result['user_id'],"user_name" => $result['user_name']);
  493.         }
  494.         mysql_close($sql_connection);
  495.         return $resultArray;
  496.     }
  497.    
  498.     public function addUserAndCbr($uname,$umail,$ulevel,$msg,$pid) {
  499.         switch($ulevel) {
  500.             case '2':
  501.                 $urole = "user";
  502.                 break;
  503.             case '3':
  504.                 $urole = "guest";
  505.                 break;
  506.             default:
  507.                 return false;
  508.         }
  509.         $upass = createRandomPassword();
  510.         $hpass = sha1($upass);
  511.         $sql_connection = connect_to_db();
  512.         $query = "INSERT INTO users
  513.                     (user_name,user_pass,user_email,user_roles)
  514.                     VALUES ('{$uname}','{$hpass}','{$umail}','{$urole}')";
  515.         $result_set = mysql_query($query);
  516.         confirm_query($result_set);
  517.         $uid = mysql_insert_id();
  518.         mysql_close($sql_connection);
  519.         $sub = "Welcome to Protean by Krayon";
  520.         $body = "Hi.\n\nYou have been added as a {$urole} on Protean - Multimedia Collaboration Suite. All you need to do now is install Protean Desktop client and login using the following details:\nUsername: {$uname}\nPassword: {$upass}\n\nYou will shortly receive a message telling you about the project you have been invited to.\n\n";
  521.         //echo $body;
  522.         $to = "<".$umail.">";
  523.         mail($to,$sub,$body,"FROM: Krayon - ProteanMail <proteanmail.krayon@gmail.com>");
  524.         $this->addCbr($pid,$uid,$msg);
  525.     }
  526.    
  527.     public function addCbr($pid,$uid,$msg) {
  528.         $sql_connection = connect_to_db();
  529.         $query = "SELECT user_name,user_email
  530.                     FROM users
  531.                     WHERE user_id={$uid}
  532.                     LIMIT 1";
  533.         $result_set = mysql_query($query);
  534.         confirm_query($result_set);
  535.         if($result = mysql_fetch_array($result_set)) {
  536.             $uname = $result['user_name'];
  537.             $umail = $result['user_email'];
  538.             $query = "INSERT INTO collaborators
  539.                         (collaborator_project_id,collaborator_name,collaborator_email,collaborator_status)
  540.                         VALUES ({$pid},'{$uname}','{$umail}','offline')";
  541.             $cresult_set = mysql_query($query);
  542.             confirm_query($cresult_set);
  543.             $query = "SELECT project_name
  544.                         FROM projects
  545.                         WHERE project_id={$pid}
  546.                         LIMIT 1";
  547.             $presult_set = mysql_query($query);
  548.             confirm_query($presult_set);
  549.             $presult = mysql_fetch_array($presult_set);
  550.             mysql_close($sql_connection);
  551.             $sub = "You have been invited to a new project on Protean";
  552.             $body = "Hi,\nYou have been invited to the project \"{$presult['project_name']}\"";
  553.             if($msg!="") {
  554.                 $body .= " with the message:\n\n".$msg."\n\n";
  555.             }
  556.             $body .= "The next time you log into protean, you can see that this project has been added to your list of projects.";
  557.             //echo $body;
  558.             $to = "<".$umail.">";
  559.             mail($to,$sub,$body,"FROM: Krayon - ProteanMail <proteanmail.krayon@gmail.com>");
  560.             $this->serverUpdate($pid,"newcollaboratoradded",null,1);
  561.             return true;
  562.         }
  563.         mysql_close($sql_connection);
  564.         return false;
  565.     }
  566.    
  567.     public function getFilesForProjects($p_ids_array,$p_names_array) {
  568.         if($p_ids_array==null || $p_names_array==null) {
  569.             return;
  570.         }
  571.         $sql_connection = connect_to_db();
  572.         $result_array = array();
  573.         $len = count($p_ids_array);
  574.         for ($i=0;$i<$len;$i++) {
  575.             $pid = $p_ids_array[$i];
  576.             $pname = $p_names_array[$i];
  577.             $query = "SELECT file_name,file_link
  578.                         FROM files
  579.                         WHERE file_project_id={$pid}";
  580.             $result_set = mysql_query($query);
  581.             confirm_query($result_set);
  582.             $files = array();
  583.             while($result = mysql_fetch_array($result_set)) {
  584.                 $files[] = array("name" => $result['file_name'],"link" => $result['file_link']);
  585.             }
  586.             $result_array[] = array("pname" => $pname, "pfiles" => $files);
  587.         }
  588.         mysql_close($sql_connection);
  589.         return $result_array;
  590.     }
  591.     public function startSync($pid,$uname) {                        // access - only admin
  592.         $sql_connection = connect_to_db();
  593.         $query = "UPDATE settings
  594.                     SET setting_value='{$uname}'
  595.                     WHERE setting_name='sync_status'";
  596.         $result_set = mysql_query($query);
  597.         confirm_query($result_set);
  598.         $query = "UPDATE settings
  599.                     SET setting_value={$pid}
  600.                     WHERE setting_name='sync_project'";
  601.         $result_set = mysql_query($query);
  602.         confirm_query($result_set);
  603.         $this->serverUpdate($pid,"syncstart",array("project_id" => $pid,"sync_head" => $uname),5);
  604.     }
  605.     public function endSync($p_id) {                                    // access - admin
  606.         $sql_connection = connect_to_db();
  607.         $query = "UPDATE settings
  608.                     SET setting_value=-1
  609.                     WHERE setting_name='sync_status'";
  610.         $result_set = mysql_query($query);
  611.         confirm_query($result_set);
  612.         $query = "UPDATE settings
  613.                     SET setting_value=-1
  614.                     WHERE setting_name='sync_project'";
  615.         $result_set = mysql_query($query);
  616.         confirm_query($result_set);
  617.         $this->serverUpdate($p_id,"syncend",null,5);
  618.     }
  619.    
  620.     public function syncFileUpdate($uname,$p_id,$f_id) {                // access - all
  621.         $sql_connection = connect_to_db();
  622.         $query = "SELECT setting_value
  623.                     FROM settings
  624.                     WHERE setting_name='sync_status'";
  625.         $result_set = mysql_query($query);
  626.         confirm_query($result_set);
  627.         $sync_head = mysql_fetch_array($result_set);
  628.         if($sync_head == -1) { 
  629.             return;
  630.         }
  631.         else if($sync_head==$uname) {
  632.             $this->serverUpdate($p_id,"syncfile",$f_id,5);
  633.         }
  634.         else {
  635.             return;
  636.         }
  637.     }
  638.     public function syncPositionUpdate($uname,$p_id,$pos) {         // access - all
  639.         $sql_connection = connect_to_db();
  640.         $query = "SELECT setting_value
  641.                     FROM settings
  642.                     WHERE setting_name='sync_status'";
  643.         $result_set = mysql_query($query);
  644.         confirm_query($result_set);
  645.         $sync_head = mysql_fetch_array($result_set);
  646.         if($sync_head == -1) { 
  647.             return;
  648.         }
  649.         else if($sync_head==$uname) {
  650.             $this->serverUpdate($p_id,"syncposition",$pos,5);
  651.         }
  652.         else {
  653.             return;
  654.         }
  655.     }
  656.    
  657.     public function getSyncStatus() {                           //  access - all
  658.         $sql_connection = connect_to_db();
  659.         $query = "SELECT setting_value
  660.                     FROM settings
  661.                     WHERE setting_name='sync_status'";
  662.         $result_set = mysql_query($query);
  663.         confirm_query($result_set);
  664.         $sync_head = mysql_fetch_array($result_set);
  665.         if($sync_head = -1) {
  666.             return false;
  667.         }
  668.         else {
  669.             $query = "SELECT setting_value
  670.                         FROM settings
  671.                         WHERE setting_name='sync_project'";
  672.             $result_set = mysql_query($query);
  673.             confirm_query($result_set);
  674.             $sync_project = mysql_fetch_array($result_set);
  675.            
  676.             $query = "SELECT update_body
  677.                         FROM updates
  678.                         WHERE update_header='syncfile'
  679.                         ORDER BY update_time DESC
  680.                         LIMIT 1";
  681.             $result_set = mysql_query($query);
  682.             confirm_query($result_set);
  683.             $sync_file = mysql_fetch_array($result_set);
  684.             /*
  685.             $query = "SELECT update_body
  686.                         FROM updates
  687.                         WHERE update_header='syncposition'
  688.                         ORDER BY update_time DESC
  689.                         LIMIT 1";
  690.             $result_set = mysql_query($query);
  691.             confirm_query($result_set);
  692.             $sync_position = mysql_fetch_array($result_set);*/
  693.             return array("sync_head"=>$sync_head,"sync_project"=>$sync_project,"sync_file"=>$sync_file/*,"sync_position"=>$sync_position*/);
  694.         }
  695.     }
  696. }
  697. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement