From: <mo...@us...> - 2005-01-30 19:58:23
|
Update of /cvsroot/tikiwiki/tiki/lib/tasks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4491/tikiwiki/lib/tasks Modified Files: Tag: BRANCH-1-9 tasklib.php Log Message: Changes on user-tasks Index: tasklib.php =================================================================== RCS file: /cvsroot/tikiwiki/tiki/lib/tasks/tasklib.php,v retrieving revision 1.9.2.28 retrieving revision 1.9.2.29 diff -u -d -r1.9.2.28 -r1.9.2.29 --- tasklib.php 27 Jan 2005 16:29:31 -0000 1.9.2.28 +++ tasklib.php 30 Jan 2005 19:58:13 -0000 1.9.2.29 @@ -20,60 +20,50 @@ } - function get_task($user, $taskId, $user_check = true) { - if($user_check){ + function get_task($user, $taskId, $task_version = null, $admin_mode = false) { + if($admin_mode){ + $query = "select distinct `t_head`.`*`, `t_history`.* FROM "; + $query .= "`tiki_user_tasks_history` AS `t_history`, `tiki_user_tasks` AS `t_head` "; + $query .= "WHERE "; + $query .= "`t_head`.`taskId` = `t_history`.`belongs_to` AND"; + if($task_version == null){ + $query .= "`t_history`.`task_version` = `t_head`.`last_version` AND "; + } else { + $query .= "`t_history`.`task_version` = $task_version AND "; + } + $query .= "`t_head`.`taskId`= ? "; + $value = array((int)$taskId); + } else { $query = "select distinct `t_head`.*, `t_history`.* FROM "; $query .= "`tiki_user_tasks_history` AS `t_history`, `tiki_user_tasks` AS `t_head`, "; $query .= "`users_users`, `users_usergroups` "; $query .= "WHERE "; $query .= "`t_head`.`taskId` = `t_history`.`belongs_to` AND"; - $query .= "`t_head`.`task_version` = `t_history`.`task_version` AND "; + if($task_version == null){ + $query .= "`t_history`.`task_version` = `t_head`.`last_version` AND "; + } else { + $query .= "`t_history`.`task_version` = $task_version AND "; + } $query .= "`t_head`.`taskId`= ? AND "; $query .= "((`t_head`.`user`=? or `t_head`.`creator` = ? ) or "; $query .= "(`users_users`.`login` = ? and "; $query .= "`users_users`.`userId` = `users_usergroups`.`userId` and "; $query .= "`users_usergroups`.`groupName` = `t_head`.`public_for_group`))"; $value = array((int)$taskId, $user, $user, $user); - } else { - $query = "select distinct `t_head`.*, `t_history`.* FROM "; - $query .= "`tiki_user_tasks_history` AS `t_history`, `tiki_user_tasks` AS `t_head` "; - $query .= "WHERE "; - $query .= "`t_head`.`taskId` = `t_history`.`belongs_to` AND"; - $query .= "`t_head`.`task_version` = `t_history`.`task_version` AND "; - $query .= "`t_head`.`taskId`= ? "; - $value = array((int)$taskId); } $result = $this->query($query,$value); - $res = $result->fetchRow(); - if(($res['user'] == $user and $res['rights_by_creator'] == NULL) or ($res['creator'] == $user)){ - $res['disabled'] = false; - } else { - $res['disabled'] = true; + if($res = $result->fetchRow()){ + if(($res['user'] == $user and $res['rights_by_creator'] == NULL) or ($res['creator'] == $user)){ + $res['disabled'] = false; + } else { + $res['disabled'] = true; + } + if($res['percentage'] == NULL) $res['percentage_null'] = true; else $res['percentage_null'] = false; } - if($res['percentage'] == NULL) $res['percentage_null'] = true; else $res['percentage_null'] = false; return $res; } - - function check_right_on_task($user, $task){ - if($task['deleted'] != null) { - return 'view'; - } else if(($task['user'] == $user) and ($task['creator'] == $user) and ($task['taskId'] == 0)){ - return 'new'; - } else - if(($task['user'] == $user) and ($task['creator'] == $user)){ - return 'private'; - } else - if(($task['user'] == $user) and ($task['creator'])){ - if($task['rights_by_creator'] == 'y') return 'user'; - else return 'creator'; - } else - if(($task['user'] != $user) and ($task['creator'] == $user)){ - return 'creator'; - } else - return 'view'; - } - + function get_default_new_task($user) { $task = array(); $task['taskId'] = 0; @@ -92,6 +82,7 @@ $task['accepted_user'] = NULL; /*--history --*/ $task['belongs_to'] = 0; + $task['last_version'] = 0; $task['title'] = NULL; $task['description'] = NULL; $task['start'] = NULL; @@ -100,6 +91,7 @@ $task['lastchanges'] = date("U"); /*--*/ $task['percentage_null'] = true; + return $task; } @@ -112,173 +104,133 @@ $this->query($query, array($value,$user,(int)$taskId)); } - function write_taks_history_in_db($belongs_to, $task_version, $title, $description, $start, $end, $lasteditor, $lastchanges){ - $query = "insert into `tiki_user_tasks_history` set "; - $query .= "`belongs_to` = ?, "; - $query .= "`task_version`= ?, "; - $query .= "`title`= ?, "; - $query .= "`description`= ?, "; - $query .= "`start`= ?, "; - $query .= "`end`= ?, "; - $query .= "`lasteditor`= ?, "; - $query .= "`lastchanges` = ? "; - $values = array($belongs_to, $task_version, $title, $description, $start, $end, $lasteditor, $lastchanges); - $this->query($query,$values); - $query = "select max(`task_version`) from `tiki_user_tasks_history` where `belongs_to` = ?"; - $version = $this->getOne($query, array((int)$belongs_to)); - return $version; - } - function write_task_in_db( $taskId, - $task_version, - $task_user, - $creator, - $public_for_group, - $rights_by_creator, - $priority, - $completed, - $deleted, - $created, - $status, - $percentage, - $accepted_creator, - $accepted_user, - /*--history --*/ - $title, - $description, - $start, - $end, - $lasteditor, - $lastchanges, - $user_check = true){ - if($taskId == 0 and $task_version == 0){ - //new task - $query = "insert into `tiki_user_tasks` set "; - $query .= "`user` = ?, "; - $query .= "`creator` = ?, "; - $query .= "`public_for_group` = ?, "; - $query .= "`rights_by_creator` = ?, "; - $query .= "`priority` = ?, "; - $query .= "`completed` = ?, "; - $query .= "`deleted` = ?, "; - $query .= "`created` = ?, "; - $query .= "`status` = ?, "; - $query .= "`percentage` = ?, "; - $query .= "`accepted_creator` = ?, "; - $query .= "`accepted_user` = ? "; - $values = array( $task_user, - $creator, - $public_for_group, - $rights_by_creator, - $priority, - $completed, - $deleted, - $created, - $status, - $percentage, - $accepted_creator, - $accepted_user); - $this->query($query,$values); - $query = "select `taskId` from `tiki_user_tasks` where `user` = ? and `created` = ?"; - $taskId = $this->getOne($query, array($task_user, $created)); - $this->write_taks_history_in_db($taskId, $task_version, $title, $description, $start, $end, $lasteditor, $lastchanges); - } else { - $task_version = $task_version + 1; - $version = $this->write_taks_history_in_db($taskId, $task_version, $title, $description, $start, $end, $lasteditor, $lastchanges); - $this->update_task_version($taskId, $lasteditor, $version); - $this->update_task_public_for_group($taskId, $lasteditor, $public_for_group); - $this->update_task_priority($taskId, $lasteditor, $priority); - $this->update_task_completed($taskId, $lasteditor, $completed); - $this->update_task_deleted($taskId, $lasteditor, $deleted); - $this->update_task_deleted($taskId, $lasteditor, $deleted); - $this->update_task_status($taskId, $lasteditor, $status); - $this->update_task_percentage($taskId, $lasteditor, $percentage); - $this->update_task_rights_by_creator($taskId, $lasteditor, $rights_by_creator); + function new_task($task_user, $creator, $public_for_group, $rights_by_creator, $created, $values){ + $query = "INSERT INTO `tiki_user_tasks` SET "; + $query .= "`last_version` = ?, "; + $query .= "`user` = ?, "; + $query .= "`creator` = ?, "; + $query .= "`public_for_group` = ?, "; + $query .= "`rights_by_creator` = ?, "; + $query .= "`created` = ? "; + $this->query($query,array((int) 0, $task_user, $creator, $public_for_group, $rights_by_creator, (int)$created)); + $query = "select `taskId` from `tiki_user_tasks` where `creator` = ? AND `created` = ?"; + $taskId = $this->getOne($query, array($creator, (int)$created)); + $values['belongs_to'] = $taskId; + $values['lasteditor'] = $creator; + $values['lastchanges'] = $created; + $values['task_version'] = (int) 0; + if($task_user != $creator) $values['accepted_creator'] = 'y'; + $query = "INSERT INTO `tiki_user_tasks_history` SET "; + $comma = ''; + foreach ($values as $key => $value) { + $query .= "$comma `$key` = ? "; + $comma = ', '; } + $this->query($query,$values); return $taskId; } - - function update_task_public_for_group($taskId, $user, $groupName){ - $query = "update `tiki_user_tasks` set `public_for_group`= ? "; - $query .= "where ((`user`=? and `rights_by_creator` IS NULL) or `creator` = ?) and `taskId`=?"; - $this->query($query,array($groupName, $user, $user, (int)$taskId)); - } - - function update_task_rights_by_creator($taskId, $user, $rights_by_creator){ - $query = "update `tiki_user_tasks` set `rights_by_creator`= ? "; - $query .= "where `creator` = ? and `taskId`=?"; - $this->query($query,array($rights_by_creator, $user, (int)$taskId)); - } - - function update_task_priority($taskId, $user, $priority){ - $query = "update `tiki_user_tasks` set `priority`= ? "; - $query .= "where ((`user`=? and `rights_by_creator` IS NULL) or `creator` = ?) and `taskId`=?"; - $this->query($query,array($priority, $user, $user, (int)$taskId)); - } - - function update_task_percentage($taskId, $user, $percentage){ - $query = "update `tiki_user_tasks` set `percentage`= ? "; - $query .= "where (`user`=? or `creator` = ?) and `taskId`=?"; - $this->query($query,array($percentage, $user, $user, (int)$taskId)); - } - - function update_task_completed($taskId, $user, $completed) { - $query = "update `tiki_user_tasks` set `completed`= ? "; - $query .= "where (`user`=? or `creator` = ?) and `taskId`=?"; - $this->query($query,array($completed, $user, $user, (int)$taskId)); - } - function update_task_deleted($taskId, $user, $deleted) { - $query = "update `tiki_user_tasks` set `deleted`= ? "; - $query .= "where ((`user`=? and `rights_by_creator` IS NULL) or `creator` = ?) and `taskId`=?"; - $this->query($query,array($deleted, $user, $user, (int)$taskId)); - } - - function update_task_status($taskId, $user, $status) { - $query = "update `tiki_user_tasks` set `status`= ? "; - $query .= "where (`user`=? or `creator` = ?) and `taskId`=?"; - $this->query($query,array($status, $user, $user, (int)$taskId)); - } - - - function update_task_version($taskId, $user, $task_version) { - $query = "update `tiki_user_tasks` set `task_version`= ? "; - $query .= "where (`user`=? or `creator` = ?) and `taskId`=?"; - $this->query($query,array($task_version, $user, $user, (int)$taskId)); + function update_task($taskId, $user, $values, $values_head = null, $admin_mode = false){ + $query = "SELECT `tiki_user_tasks_history`.* "; + $query .= "FROM `tiki_user_tasks`, `tiki_user_tasks_history` WHERE "; + $query .= "`tiki_user_tasks`.`taskId` = ? AND "; + $query .= "`tiki_user_tasks`.`taskId` = `tiki_user_tasks_history`.`belongs_to` AND "; + $query .= "`tiki_user_tasks`.`last_version` = `tiki_user_tasks_history`.`task_version` "; + $values_select = array((int) $taskId); + if(!$admin_mode){ + $values_select[] = $user; + $values_select[] = $user; + $query .= " AND (`user` = ? OR `creator` = ?) "; + } + $result = $this->query($query,$values_select); + $entries = $result->fetchRow(); + + $query = "INSERT INTO `tiki_user_tasks_history` SET "; + + + $count_values = 0; + foreach ($values as $key => $value) { + $entries[$key] = $value; + $count_values++; + echo("$key: $value <br />"); + } + + if($count_values > 0){ + $count_entries = 0; + $entries['task_version'] = $entries['task_version'] + 1; + $entries['lasteditor'] = $user; + $entries['lastchanges'] = date('U'); + foreach ($entries as $key => $value) { + if($count_entries > 0) $query .= ', '; + $query .= "`$key` = ? "; + $count_entries++; + } + $this->query($query,$entries); + } + + $insert_values = array(); + $query = "UPDATE `tiki_user_tasks` SET `last_version`= ? "; + $insert_values['last_version'] = (int)$entries['task_version']; + $count_values_head = 0; + if($values_head != null) { + foreach ($values_head as $key => $value) { + $query .= ", `$key` = ? "; + $insert_values[$key] = $value; + $count_values_head++; + } + } + $insert_values['taskId'] = (int)$taskId; + $query .= "WHERE `taskId`=? "; + if($count_values > 0 or $count_values_head > 0) $this->query($query,$insert_values); } - function mark_task_as_trash($taskId, $user) { - $this->update_task_deleted($taskId, $user, date("U")); + function mark_task_as_trash($taskId, $user, $admin_mode = false) { + $result = $this->query("SELECT * FROM `tiki_user_tasks` WHERE taskId = ?",array($taskId)); + $res = $result->fetchRow(); + if($user == $res['creator'] or ($user == $res['user'] and $res['rights_by_creator'] == null) or $admin_mode){ + $values = array('deleted' => (int)date('U')); + $this->update_task($taskId, $user, $values, null, $admin_mode); + } } - function unmark_task_as_trash($taskId, $user) { - $this->update_task_deleted($taskId, $user, NULL); + function unmark_task_as_trash($taskId, $user, $admin_mode = false) { + $result = $this->query("SELECT * FROM `tiki_user_tasks` WHERE taskId = ?",array($taskId)); + $res = $result->fetchRow(); + if($user == $res['creator'] or ($user == $res['user'] and $res['rights_by_creator'] == NULL) or $admin_mode){ + $values = array('deleted' => NULL); + $this->update_task($taskId, $user, $values, null, $admin_mode); + } } function open_task($taskId, $user) { - $this->update_task_completed($taskId, $user, NULL); - $this->update_task_status($taskId, $user, 'o'); - $this->update_task_percentage($taskId, $user, 0); + $values = array('percentage' => (int) 0, 'status' => 'o', 'completed' => NULL); + $this->update_task($taskId, $user, $values); } function mark_complete_task($taskId, $user) { - $this->update_task_completed($taskId, $user, date("U")); - $this->update_task_status($taskId, $user, 'c'); - $this->update_task_percentage($taskId, $user, 100); - + $values = array('percentage' => (int) 100, 'status' => 'c', 'completed' => (int)date('U')); + $this->update_task($taskId, $user, $values); } - + function update_task_percentage($taskId, $user, $percentage){ + $values = array('percentage' => $percentage); + $this->update_task($taskId, $user, $values); + } function emty_trash($user) { - $query = "select `taskId` from `tiki_user_tasks` where `creator` = ? and `deleted` IS NOT NULL"; + $query = "SELECT `tiki_user_tasks`.`taskId` FROM `tiki_user_tasks`, `tiki_user_tasks_history` "; + $query .= "WHERE `tiki_user_tasks`.`creator` = ? AND "; + $query .= "`tiki_user_tasks`.`taskId` = `tiki_user_tasks_history`.`belongs_to` AND "; + $query .= "`tiki_user_tasks`.`last_version` = `tiki_user_tasks_history`.`task_version` AND "; + $query .= "`tiki_user_tasks_history`.`deleted` IS NOT NULL"; $result = $this->query($query,array($user)); while ($res = $result->fetchRow()) { - $query = "delete from `tiki_user_tasks_history` where `belongs_to` = ?"; + $query = "DELETE FROM `tiki_user_tasks_history` WHERE `belongs_to` = ?"; + $this->query($query,$res); + $query = "DELETE FROM `tiki_user_tasks` WHERE `taskId` = ?"; $this->query($query,$res); } - $query = "delete from `tiki_user_tasks` where `creator` = ? and `deleted` IS NOT NULL"; - $this->query($query,array($user)); } /** @@ -318,13 +270,13 @@ $query = "FROM `tiki_user_tasks_history` AS `t_history`, `tiki_user_tasks` AS `t_head` "; $query .= "WHERE `t_head`.`public_for_group` IS NOT NULL "; $query .= "AND `t_head`.`taskId` = `t_history`.`belongs_to` "; - $query .= "AND `t_head`.`task_version` = `t_history`.`task_version` "; + $query .= "AND `t_head`.`last_version` = `t_history`.`task_version` "; } else { $query = "FROM `tiki_user_tasks_history` AS `t_history`, `tiki_user_tasks` AS `t_head`, "; $query .= "`users_users`, `users_usergroups` "; $query .= "WHERE "; $query .= "`t_head`.`taskId` = `t_history`.`belongs_to` AND "; - $query .= "`t_head`.`task_version` = `t_history`.`task_version` AND "; + $query .= "`t_head`.`last_version` = `t_history`.`task_version` AND "; $query .= "( "; $query .= "( `t_head`.`taskId` = -1) "; //Dummy if($use_show_shared_for_group){ @@ -383,23 +335,16 @@ } if($show_trash == false){ $query .= " AND "; - $query .= "( `t_head`.`deleted` IS NULL) "; + $query .= "( `t_history`.`deleted` IS NULL) "; } if($show_completed == false){ $query .= " AND "; - $query .= "( `t_head`.`completed` IS NULL) "; + $query .= "( `t_history`.`completed` IS NULL) "; } } if(isset($sort_mode) and strlen($sort_mode) > 1){ - if((strncmp ($sort_mode, 'start', strlen('start')) == 0) or - (strncmp ($sort_mode, 'end', strlen('end')) == 0)or - (strncmp ($sort_mode, 'title', strlen('title')) == 0)or - (strncmp ($sort_mode, 'description', strlen('description')) == 0)){ - $order_str = "`t_history`.".$this->convert_sortmode($sort_mode) . ", "; - } else { - $order_str = "`t_head`.".$this->convert_sortmode($sort_mode) . ", "; - } + $order_str = "`t_history`.".$this->convert_sortmode($sort_mode) . ", "; } else $order_str = ''; $query .= "ORDER BY $order_str `t_head`.`taskId` desc"; @@ -417,7 +362,7 @@ $query_tasklist = "select distinct `t_head`.*, `t_history`.* $query"; $result = $this->query($query_tasklist, $values, $maxRecords, $offset); while ($res = $result->fetchRow()) { - if(($res['user'] == $user and $res['rights_by_creator'] == NULL) or ($res['creator'] == $user)){ + if(($res['user'] == $user) or ($res['creator'] == $user)){ $res['disabled'] = false; } else { $res['disabled'] = true; |