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 /****************************************************************/
14 define('AT_INCLUDE_PATH', '../../../../include/');
15 require (AT_INCLUDE_PATH.'vitals.inc.php');
17 authenticate(AT_PRIV_POLLS);
20 if ($_POST['cancel']) {
21 $msg->addFeedback('CANCELLED');
22 header('Location: index.php');
26 if (isset($_GET['poll_id'])) {
27 $poll_id = intval($_GET['poll_id']);
29 $poll_id = intval($_POST['poll_id']);
32 if ($_POST['edit_poll']) {
33 if (trim($_POST['question']) == '') {
34 $msg->addError(array('EMPTY_FIELDS', _AT('question')));
37 if ((trim($_POST['c1']) == '') || (trim($_POST['c2']) == '')) {
38 $msg->addError('POLL_QUESTION_MINIMUM');
41 if (!$msg->containsErrors()) {
42 $_POST['question'] = $addslashes($_POST['question']);
43 //Check if the question has exceeded the words amount - 100, decided in the db
44 $_POST['question'] = validate_length($_POST['question'], 100);
46 for ($i=1; $i<= AT_NUM_POLL_CHOICES; $i++) {
47 $trimmed_word = validate_length($_POST['c' . $i], 100);
48 $trimmed_word = $addslashes($trimmed_word);
49 $choices .= "choice$i = '" . $trimmed_word . "',";
51 $choices = substr($choices, 0, -1);
53 $sql = "UPDATE ".TABLE_PREFIX."polls SET question='$_POST[question]', created_date=created_date, $choices WHERE poll_id=$poll_id AND course_id=$_SESSION[course_id]";
54 $result = mysql_query($sql,$db);
56 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
57 Header('Location: index.php');
60 for ($i=1; $i<= AT_NUM_POLL_CHOICES; $i++) {
61 $_POST['c' . $i] = $stripslashes($_POST['c' . $i]);
63 $_POST['question'] = $stripslashes($_POST['question']);
66 require(AT_INCLUDE_PATH.'header.inc.php');
69 $msg->printErrors('ITEM_NOT_FOUND');
70 require (AT_INCLUDE_PATH.'footer.inc.php');
74 $sql = "SELECT * FROM ".TABLE_PREFIX."polls WHERE poll_id=$poll_id AND course_id=$_SESSION[course_id]";
75 $result = mysql_query($sql,$db);
76 if (!($row = mysql_fetch_assoc($result))) {
77 $msg->printErrors('ITEM_NOT_FOUND');
78 require (AT_INCLUDE_PATH.'footer.inc.php');
82 $savant->assign('row', $row);
83 $savant->display('instructor/polls/edit.tmpl.php');
84 require (AT_INCLUDE_PATH.'footer.inc.php'); ?>