root / trunk / actions / AddQuestion.php @ 1112

View | Annotate | Download (1.4 KB)

1
<?php
2
3
/*
4
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
5
* @license http://creativecommons.org/licenses/BSD/ BSD License
6
* @author Keyboard Monkeys Ltd.
7
* @since Sciret 1.2
8
* @package Sciret
9
* @packager Keyboard Monkeys
10
*/
11
12
require 'actions/Action.php';
13
14
class AddQuestion extends Action {
15
16
    function dispatch() {
17
        if (!$this->configuration->getConfigValue('questionsEnabled')) {
18
            die('The questions functionalities have been disabled');
19
        }
20
21
        if ($_POST['username'] == '') {
22
            $_SESSION['message'] = $this->translate('You must enter your name');
23
            Library::redirect(Library::getLink(array('view' => 'AddQuestion')));
24
        }
25
        if ($_POST['contents'] == '') {
26
            $_SESSION['message'] = $this->translate('Your question was empty');
27
            Library::redirect(Library::getLink(array('view' => 'AddQuestion')));
28
        }
29
30
        $question = new Kb_Model_Question;
31
        $question->setUserName($_POST['username']);
32
        $question->setContents($_POST['contents']);
33
        $question->setCategoryId($_POST['category']);
34
        $question->setPublished($this->configuration->getConfigValue('publishQuestionsAuto') == '1');
35
        $question->save();
36
37
        $_SESSION['message'] = $this->translate('Your question was added successfully');
38
        Library::redirect(Library::getLink());
39
    }
40
}
41
42
?>
43