move code up one directory
[atutor.git] / mods / _standard / polls / tools / add.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License  */
11 /* as published by the Free Software Foundation.                                */
12 /****************************************************************/
13 define('AT_INCLUDE_PATH', '../../../../include/');
14 require (AT_INCLUDE_PATH.'vitals.inc.php');
15
16 authenticate(AT_PRIV_POLLS);
17
18 if ($_POST['cancel']) {
19         $msg->addFeedback('CANCELLED');
20         Header('Location: index.php');
21         exit;
22 }
23
24 if ($_POST['add_poll'] && (authenticate(AT_PRIV_POLLS, AT_PRIV_RETURN))) {
25         if (trim($_POST['question']) == '') {
26                 $msg->addError(array('EMPTY_FIELDS', _AT('question')));
27         }
28
29         if ((trim($_POST['c1']) == '') || (trim($_POST['c2']) == '')) {
30                 $msg->addError('POLL_QUESTION_MINIMUM');
31         }
32
33         if (!$msg->containsErrors()) {
34                 $_POST['question'] = $addslashes($_POST['question']);
35                 //Check if the question has exceeded the words amount - 100, decided in the db
36                 if ($strlen($_POST['question']) > 100){
37                         $_POST['question'] = $substr($_POST['question'], 0, 100);
38                 }
39
40                 for ($i=1; $i<= AT_NUM_POLL_CHOICES; $i++) {
41                         $trimmed_word = $addslashes($_POST['c' . $i]);
42                         if ($strlen($trimmed_word) > 100){
43                                 $trimmed_word = $substr($trimmed_word, 0, 100);
44                         }
45                         $choices .= "'" . $trimmed_word . "',0,";
46                 }
47                 $choices = substr($choices, 0, -1);     //Remove the last comma.
48
49                 $sql    = "INSERT INTO ".TABLE_PREFIX."polls VALUES (NULL, $_SESSION[course_id], '$_POST[question]', NOW(), 0, $choices)";
50                 $result = mysql_query($sql,$db);
51                 
52                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
53                 header('Location: index.php');
54                 exit;
55         }
56         for ($i=1; $i<= AT_NUM_POLL_CHOICES; $i++) {
57                 $_POST['c' . $i] = $stripslashes($_POST['c' . $i]);
58         }
59         $_POST['question'] = $stripslashes($_POST['question']);
60 }
61
62 require(AT_INCLUDE_PATH.'header.inc.php');
63 $savant->display('instructor/polls/add.tmpl.php');
64 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>