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 /****************************************************************/
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');
84 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
85 <input type="hidden" name="edit_poll" value="true" />
86 <input type="hidden" name="poll_id" value="<?php echo $row['poll_id']; ?>" />
88 <div class="input-form">
89 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('edit_poll'); ?></legend>
91 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="question"><?php echo _AT('question'); ?>:</label><br />
92 <textarea name="question" cols="55" rows="3" id="question"><?php if (isset ($_POST['question'])) { echo htmlspecialchars($_POST['question']); } else { echo htmlspecialchars($row['question']); } ?></textarea>
96 for ($i=1; $i<= AT_NUM_POLL_CHOICES; $i++): ?>
98 <?php if (($i==1) || ($i==2)) { ?>
99 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div>
101 <label for="c<?php echo $i; ?>"><?php echo _AT('choice'); ?> <?php echo $i; ?>:</label><br />
102 <input type="text" name="c<?php echo $i; ?>" id="c<?php echo $i; ?>" value="<?php if (isset ($_POST['c' . $i])) { echo htmlspecialchars($_POST['c' . $i]); } else { echo htmlspecialchars($row['choice' . $i]); }?>" size="40" />
106 <div class="row buttons">
107 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
108 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?> " />
113 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>