issue.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. require_once(realpath(dirname(__FILE__)).'/config.php');
  3. require_once(PATH_PHP.'database.php');
  4. require_once(PATH_PHP.'messages.php');
  5. require_once(PATH_PHP.'activity.php');
  6. function issueObj($id){
  7. if($res = query("SELECT i.id,i.title,i.description,i.s_id,u.name as user, p.name as priority, s.name as status,p.color FROM `issues` i JOIN `users` u ON u.id = i.u_id LEFT JOIN `priorities` p ON p.id = i.pr_id LEFT JOIN `statuses` s ON s.id = i.st_id WHERE i.id='%d'",array($id))){
  8. if($res->num_rows == 1){
  9. $issue = $res->fetch_assoc();
  10. $issue['user'] = userObj($issue['user']);
  11. $issue['comments'] = messages($issue['id'],'issue');
  12. $issue['statuses'] = possibleStatuses();
  13. $issue['priorities'] = possiblePriorities();
  14. return $issue;
  15. }
  16. }
  17. return false;
  18. }
  19. function newIssue($title,$description,$user=null,$sid=null){
  20. global $LOGGEDIN;
  21. if($LOGGEDIN){
  22. if(is_null($user)){
  23. $user = $_SESSION['username'];
  24. }
  25. $user = userId($user);
  26. if(false != $user){
  27. if($res = query("SELECT id FROM `issues` WHERE title = '%s' AND u_id = %d",array($title,$user,$sid))){
  28. if($res->num_rows){
  29. return false;
  30. }
  31. }
  32. if(is_null($sid)){
  33. $sid = 'null';
  34. }else{
  35. $sid = intval($sid);
  36. }
  37. if(query("INSERT INTO `issues` (title,description,u_id,s_id,st_id) VALUES ('%s','%s',%d,%s,1)",array($title,$description,$user,$sid))){
  38. $id = mysqli_insert_id(get_sql());
  39. project_comment($id,'Issue created');
  40. alog('i',$id,"Issue created");
  41. return true;
  42. }
  43. }
  44. }
  45. return false;
  46. }
  47. function possibleStatuses(){
  48. $ret = array();
  49. if($res = query("SELECT id,name FROM `statuses` ORDER BY id")){
  50. while($status = $res->fetch_assoc()){
  51. array_push($ret,$status);
  52. }
  53. }
  54. return $ret;
  55. }
  56. function possiblePriorities(){
  57. $ret = array();
  58. if($res = query("SELECT id,name,color FROM `priorities` ORDER BY id")){
  59. while($priority = $res->fetch_assoc()){
  60. array_push($ret,$priority);
  61. }
  62. }
  63. return $ret;
  64. }
  65. function setStatus($id,$sid){
  66. return query("UPDATE `issues` SET st_id = %d WHERE id = %d",array($sid,$id)) !== false;
  67. }
  68. function setPriority($id,$pid){
  69. return query("UPDATE `issues` SET pr_id = %d WHERE id = %d",array($pid,$id)) !== false;
  70. }
  71. function statusName($id){
  72. if($res = query("SELECT name FROM `statuses` WHERE id = %d",array($id))){
  73. $res = $res->fetch_assoc();
  74. return $res['name'];
  75. }
  76. return '(none)';
  77. }
  78. function priorityName($id){
  79. if($res = query("SELECT name FROM `proiorities` WHERE id = %d",array($id))){
  80. $res = $res->fetch_assoc();
  81. return $res['name'];
  82. }
  83. return '(none)';
  84. }
  85. ?>