project.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 projectObj($id){
  7. if($res = query("SELECT p.title,p.id,p.description,u.name as user FROM `projects` p JOIN `users` u ON u.id = p.u_id WHERE p.id='%d'",array($id))){
  8. if($res->num_rows == 1){
  9. $project = $res->fetch_assoc();
  10. $project['user'] = userObj($project['user']);
  11. $project['comments'] = messages($project['id'],'project');
  12. $project['scrums'] = scrums($project['id']);
  13. return $project;
  14. }
  15. }
  16. return false;
  17. }
  18. function newProject($title,$description,$user=null){
  19. global $LOGGEDIN;
  20. if($LOGGEDIN){
  21. if(is_null($user)){
  22. $user = $_SESSION['username'];
  23. }
  24. $user = userId($user);
  25. if(false != $user){
  26. if($res = query("SELECT id FROM `projects` WHERE title = '%s' AND u_id = %d",array($title,$user))){
  27. if($res->num_rows){
  28. return false;
  29. }
  30. }
  31. if(query("INSERT INTO `projects` (title,description,u_id) VALUES ('%s','%s',%d)",array($title,$description,$user))){
  32. $id = mysqli_insert_id(get_sql());
  33. project_comment($id,'Project created');
  34. alog('p',$id,"Project created");
  35. return $id;
  36. }
  37. }
  38. }
  39. return false;
  40. }
  41. ?>