2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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');
16 authenticate(AT_PRIV_POLLS);
18 if ($_POST['cancel']) {
19 $msg->addFeedback('CANCELLED');
20 Header('Location: index.php');
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')));
29 if ((trim($_POST['c1']) == '') || (trim($_POST['c2']) == '')) {
30 $msg->addError('POLL_QUESTION_MINIMUM');
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);
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);
45 $choices .= "'" . $trimmed_word . "',0,";
47 $choices = substr($choices, 0, -1); //Remove the last comma.
49 $sql = "INSERT INTO ".TABLE_PREFIX."polls VALUES (NULL, $_SESSION[course_id], '$_POST[question]', NOW(), 0, $choices)";
50 $result = mysql_query($sql,$db);
52 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
53 header('Location: index.php');
56 for ($i=1; $i<= AT_NUM_POLL_CHOICES; $i++) {
57 $_POST['c' . $i] = $stripslashes($_POST['c' . $i]);
59 $_POST['question'] = $stripslashes($_POST['question']);
62 require(AT_INCLUDE_PATH.'header.inc.php');
63 $savant->display('instructor/polls/add.tmpl.php');
64 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>