Location: PHPKode > scripts > Outsourcing management tool > outsourcing-management-tool/main.php
<?php
class main{
	private $host = ""; 
	private $user = "";
	private $db = "";
	private $pass = ""; 
	private $query; 
	private $error = NULL; 
	private $numrow; 
	private $numfield;
	private $twoD; 
	
	private function connect_easy()
	{
	    if(!$connect = mysql_connect($this->host,$this->user,$this->pass)){ 
	        $this->error = mysql_error($connect);
	    }
	    if(!mysql_select_db($this->db)){ 
	        $this->error = mysql_error($connect);
	    }
	    if(!($result = mysql_query($this->query))){ 
	        $this->error = mysql_error($connect);
	    }
	    $this->numrow = mysql_num_rows($result); 
	    $this->numfield = mysql_num_fields($result); 
	    for($x=0;$x<$this->numrow;$x++)
	    {
	        $oneD = mysql_fetch_array($result, MYSQL_NUM); 
	            for($i = 0;$i<$this->numfield;$i++)
	            {
	                $this->twoD[$x][$i] = $oneD[$i]; 
	            }
	    }
	    return $this->twoD;
	} 
	
	public function list_projects($limit = 100)
	{
		$this->query = "select id,project,startdate from projects order by startdate DESC limit $limit";
		$data = $this->connect_easy();
		return $data;
	}
	
	public function list_tasks($project = 0,$limit = 100)
	{
		if($project > 0){
			$where = "and project_id = ".$project;
		}else{
			$where = "";
		}
		$this->query = "select id,task,priority,percent,hours,startdate,enddate from tasks where done = 0 $where order by startdate DESC limit $limit";
		$data = $this->connect_easy();
		return $data;
	}
	
	public function list_developers($limit = 100)
	{
		$this->query = "select id,firstname,lastname,email from developers order by firstname,lastname ASC limit $limit";
		$data = $this->connect_easy();
		return $data;
	}
	
	public function add_task($project_id,$task_name,$desc,$enddate,$hours,$priority){
		$this->query = "INSERT INTO `tasks` ( `id` , `task` , `project_id` , `description` , `startdate` , `enddate` , `hours` , `priority` ) VALUES ( NULL , '$task_name', '$project_id', '$desc', NOW(), '$enddate', '$hours', '$priority')";
		$this->connect_easy();
		if($this->error == NULL){
			return true;
		}else{
			return false;
		}
	}
	
	public function add_project($project_name){
		$this->query = "INSERT INTO `projects` ( `id` , `project` , `startdate` ) VALUES ( NULL , '$project_name', NOW())";
		$this->connect_easy();
		if($this->error == NULL){
			return true;
		}else{
			return false;
		}
	}
	
	public function add_developer($firstname,$lastname,$email){
		$this->query = "INSERT INTO `developers` ( `id` , `firstname` , `lastname` , `email` ) VALUES ( NULL , '$firstname', '$lastname', '$email' )";
		$this->connect_easy();
		if($this->error == NULL){
			return true;
		}else{
			return false;
		}
	}
	
	public function assign_task_developer($developer_id,$task_id){
		$this->query = "INSERT INTO `devtask` ( `id` , `taskid` , `devid` ) VALUES ( NULL , '$task_id', '$developer_id' )";
		$this->connect_easy();
		if($this->error == NULL){
			return true;
		}else{
			return false;
		}
	}
	
	public function delete_project($project_id){
		$this->query = "DELETE FROM `projects` WHERE id = $project_id";
		$this->connect_easy();
		$this->query = "SELECT * FROM `tasks` WHERE project_id = $project_id";
		$data = $this->connect_easy();
		$this->query = "DELETE FROM `tasks` WHERE project_id = $project_id";
		$this->connect_easy();
		for($i=0;$i<count($data);$i++){
			$this->query = "DELETE FROM `devtask` WHERE taskid = ".$data[$i][0];
			$this->connect_easy();
		}
		if($this->error == NULL){
			return true;
		}else{
			return false;
		}
	}
	
	public function delete_task($task_id){
		$this->query = "DELETE FROM `tasks` WHERE id = $task_id";
		$this->connect_easy();
		$this->query = "DELETE FROM `devtask` WHERE taskid = $task_id";
		$this->connect_easy();
		if($this->error == NULL){
			return true;
		}else{
			return false;
		}
	}
	
	public function remove_assignment($task_id,$developer_id){
		$this->query = "DELETE FROM `devtask` WHERE taskid = $task_id and devid = $developer_id";
		$this->connect_easy();
		if($this->error == NULL){
			return true;
		}else{
			return false;
		}
	}
	
	public function update($data,$table,$id){
		foreach($data as $key => $val){
			$query = "UPDATE `$table` SET  `$key` = '$val' WHERE `id` = $id";
			$this->connect_easy();	
		}
		if($this->error == NULL){
			return true;
		}else{
			return false;
		}
	}	
}
?>
Return current item: Outsourcing management tool