project.php 1.3 KB

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