Esempio n. 1
0
 /**
  *
  * Edit a question
  *
  * @param $id selects the question to edit.
  *
  */
 public function editAction($id, $redirect = '')
 {
     $redirect = $this->url->create('question/view/' . $id);
     $formundo = new \Anax\HTMLForm\CFormCommentUndo($redirect);
     $formundo->setDI($this->di);
     $formundo->check();
     $undourl = $formundo->getHTML();
     $controller = 'question';
     $question = $this->question->findQuestion(null, $id);
     $question = is_object($question[0]) ? get_object_vars($question[0]) : $question;
     if ($_SESSION['user']->name != $question['name']) {
         header('Location: ' . $this->url->create('users/message/wronguser'));
         die("Du har inte tillstånd att gå in på den här sidan!");
     }
     $form = new \Anax\HTMLForm\CFormQuestionEdit($id, $question['tag'], $question['tagslug'], $question['title'], $question['userid'], $question['content'], $redirect);
     $form->setDI($this->di);
     $form->check();
     $this->theme->setTitle("Redigera fråga");
     $this->di->views->add('default/page', ['title' => "Redigera fråga", 'content' => '<h4>Fråga #' . $id . '</h4>' . $form->getHTML() . $undourl], 'main');
 }
 public function updateAction($id)
 {
     $userId = isset($_SESSION['userId']) ? $_SESSION['userId'] : null;
     //ADD SO JUST THE USER WHO CREATED CAN EDIT
     if ($userId) {
         $res = $this->questions->getUserFromQuestion($id);
         $questioncreator = $res[0]->userId;
         //            var_dump($questioncreator);
         if ($userId == $questioncreator) {
             //Ser om den som försöker redigera är den som skapat frågan
             $user = $this->users->find($userId);
             $acronym = $user->acronym;
             $question = $this->questions->find($id);
             $questionTitle = $question->questionTitle;
             $questionText = $question->questiontext;
             $tagsres = $this->questions->getQuestionTags($id);
             foreach ($tagsres as $tag) {
                 $tagsarray[] = $tag->tagName;
             }
             $tags1 = implode(",", $tagsarray);
             $form = new \Anax\HTMLForm\CFormQuestionEdit($this->questions, $this->tags, $userId, $tags1, $questionTitle, $questionText, $acronym, $id);
             $form->setDI($this->di);
             $form->check();
             $this->di->theme->setTitle("Ställ en fråga");
             $this->di->views->add('default/page', ['title' => "Ställ en fråga", 'content' => $form->getHTML()]);
         } else {
             $this->response->redirect($this->url->create('questions/id/' . $id), 'Du kan inte redigera en fråga som du inte har skapat', 'error');
         }
     } else {
         $this->response->redirect($this->url->create('users/login/'), 'Du måste vara inloggad för att redigera en fråga', 'error');
     }
 }
Esempio n. 3
0
 /**
  * Used to edit an existing question
  *
  * @return void
  */
 public function editAction($id = null)
 {
     // Get the content from the existing question
     $question = $this->questions->find($id);
     if ($question) {
         $id = $question->getProperties()['id'];
         $values = array('title' => $question->getProperties()['title'], 'content' => $question->getProperties()['content']);
         // Get tags
         $tags = $this->tags->findAll();
         $tagArray = array();
         foreach ($tags as $tag) {
             $tagArray[] = $tag->getProperties()['name'];
         }
         // Get tags association
         $this->questiontags = new \KGW\Discussion\QuestionTag();
         $this->questiontags->setDI($this->di);
         $checkedTags = $this->questiontags->findTagByQuestionId($id, 'project_');
         $checked = array();
         foreach ($checkedTags as $tag) {
             $checked[] = $tag->getProperties()['name'];
         }
         if ($this->user->isAuthenticated() && ($this->user->isCurrentUser($question->getProperties()['userId']) || $this->user->isAdmin())) {
             $form = new \Anax\HTMLForm\CFormQuestionEdit($id, $values, $tagArray, $checked);
             $form->setDI($this->di);
             $status = $form->check();
             $this->theme->setTitle("Uppdatera frågan");
             $this->views->add('questions/form', ['title' => "Uppdatera frågan", 'content' => $form->getHTML()], 'main');
         } else {
             $this->theme->setTitle('Du har inte behörighet att utföra detta');
             $this->views->add('questions/403', [], 'main');
         }
     }
 }
Esempio n. 4
0
 /**
  *
  * Edit a question
  *
  * @param $id selects the question to edit.
  *
  */
 public function editAction($id, $redirect = '')
 {
     $redirect = 'question/view/' . $id;
     $formundo = new \Anax\HTMLForm\CFormCommentUndo($redirect);
     $formundo->setDI($this->di);
     $formundo->check();
     $undourl = $formundo->getHTML();
     $controller = 'question';
     $question = $this->question->findQuestion(null, $id);
     $question = is_object($question[0]) ? get_object_vars($question[0]) : $question;
     if ($_SESSION['user']->acronym != $question['acronym']) {
         header('Location: ' . $this->url->create('users/message/wronguser'));
         die("You don't have permission to enter this page!");
     }
     $form = new \Anax\HTMLForm\CFormQuestionEdit($id, $question['tag'], $question['tagslug'], $question['title'], $question['userid'], $question['content'], $redirect);
     $form->setDI($this->di);
     $form->check();
     $this->theme->setTitle("Edit question");
     $this->di->views->add('default/page', ['title' => "Edit question", 'content' => '<h4>Question #' . $id . '</h4>' . $form->getHTML() . $undourl], 'main');
 }