2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg */
6 /* Adaptive Technology Resource Centre / University of Toronto */
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');
66 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
67 <input type="hidden" name="add_poll" value="true" />
69 <div class="input-form">
70 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('add_poll'); ?></legend>
72 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="question"><?php echo _AT('question'); ?></label><br />
73 <textarea name="question" cols="45" rows="3" id="question" style="width:90%;"><?php if (isset ($_POST['question'])) echo htmlspecialchars($_POST['question']); ?></textarea>
76 <?php for ($i=1; $i<= AT_NUM_POLL_CHOICES; $i++): ?>
78 <?php if (($i==1) || ($i==2)) { ?>
79 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div>
81 <label for="c<?php echo $i; ?>"><?php echo _AT('choice'); ?> <?php echo $i; ?></label><br />
82 <input type="text" name="c<?php echo $i; ?>" value="<?php if (isset($_POST['c' . $i])) echo htmlspecialchars($_POST['c' . $i]); ?>" size="50" id="c<?php echo $i; ?>" />
86 <div class="row buttons">
87 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
88 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
94 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>