actives = getJSON('active.php'); } ////////////////////////////////////////////////////////////////// // List User's Active Files ////////////////////////////////////////////////////////////////// public function ListActive(){ $active_list = array(); $tainted = FALSE; if($this->actives){ foreach($this->actives as $active=>$data){ if($data['username']==$this->username){ if (file_exists(dirname(__FILE__)."/../../workspace".$data['path'])) { $focused = isset($data['focused']) ? $data['focused'] : false; $active_list[] = array('path'=>$data['path'], 'focused'=>$focused); } else { unset($this->actives[$active]); $tainted = TRUE; } } } } if ($tainted){ saveJSON('active.php',$this->actives); } echo formatJSEND("success",$active_list); } ////////////////////////////////////////////////////////////////// // Check File ////////////////////////////////////////////////////////////////// public function Check(){ $cur_users = array(); foreach($this->actives as $active=>$data){ if($data['username']!=$this->username && $data['path']==$this->path){ $cur_users[] = $data['username']; } } if(count($cur_users)!=0){ echo formatJSEND("error","Warning: File Currently Opened By: " . implode(", ",$cur_users)); }else{ echo formatJSEND("success"); } } ////////////////////////////////////////////////////////////////// // Add File ////////////////////////////////////////////////////////////////// public function Add(){ $process_add = true; foreach($this->actives as $active=>$data){ if($data['username']==$this->username && $data['path']==$this->path){ $process_add = false; } } if($process_add){ $this->actives[] = array("username"=>$this->username,"path"=>$this->path); saveJSON('active.php',$this->actives); echo formatJSEND("success"); } } ////////////////////////////////////////////////////////////////// // Rename File ////////////////////////////////////////////////////////////////// public function Rename(){ $revised_actives = array(); foreach($this->actives as $active=>$data){ $revised_actives[] = array("username"=>$data['username'],"path"=>str_replace($this->path,$this->new_path,$data['path'])); } saveJSON('active.php',$revised_actives); echo formatJSEND("success"); } ////////////////////////////////////////////////////////////////// // Remove File ////////////////////////////////////////////////////////////////// public function Remove(){ foreach($this->actives as $active=>$data){ if($this->username==$data['username'] && $this->path==$data['path']){ unset($this->actives[$active]); } } saveJSON('active.php',$this->actives); echo formatJSEND("success"); } ////////////////////////////////////////////////////////////////// // Mark File As Focused // All other files will be marked as non-focused. ////////////////////////////////////////////////////////////////// public function MarkFileAsFocused(){ foreach($this->actives as $active=>$data){ if($this->username==$data['username']){ $this->actives[$active]['focused']=false; if($this->path==$data['path']){ $this->actives[$active]['focused']=true; } } } saveJSON('active.php',$this->actives); echo formatJSEND("success"); } }