SubmitNewTopicController.inc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. class SubmitNewTopicController implements IController {
  3. public function execute() {
  4. $session = new Session();
  5. $logger = new Logger();
  6. $userId = $session->getValue("logged_in");
  7. if ($userId) {
  8. $form = new Form();
  9. $newTopicName = $form->post("name");
  10. $displayName = $newTopicName;
  11. $newTopicName = strtolower($newTopicName);
  12. $database = new Database();
  13. $sql = "SELECT topic_id FROM topics WHERE display_name LIKE '".$newTopicName."'";
  14. $result = $database->query($sql);
  15. if($result == array()) {
  16. $sql = sprintf("INSERT INTO topics (display_name, url_name) VALUES ('%s', '%s')"
  17. , $displayName
  18. , $this->cleanName($newTopicName)
  19. );
  20. $topicId = $database->write($sql);
  21. $sql = sprintf("INSERT INTO user_topic_acl (user_id, topic_id, rank_id) VALUES ('%s', '%s', '%s')",
  22. $userId,
  23. $topicId,
  24. 2
  25. );
  26. $database->write($sql);
  27. } else {
  28. //topic already claimed
  29. }
  30. $header = new Header();
  31. $header->redirect("/?a=topicmanagement&id=".$topicId);
  32. } else {
  33. //not logged in
  34. }
  35. }
  36. private function cleanName($newTopicName) {
  37. $webWrapper = new WebWrapper();
  38. return $webWrapper->urlEncode($newTopicName);
  39. }
  40. }