2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 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']);
44 for ($i=1; $i<= AT_NUM_POLL_CHOICES; $i++) {
45 $choices .= "choice$i = '" . $addslashes($_POST['c' . $i]) . "',";
47 $choices = substr($choices, 0, -1);
49 $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]";
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');
65 $msg->printErrors('ITEM_NOT_FOUND');
66 require (AT_INCLUDE_PATH.'footer.inc.php');
70 $sql = "SELECT * FROM ".TABLE_PREFIX."polls WHERE poll_id=$poll_id AND course_id=$_SESSION[course_id]";
71 $result = mysql_query($sql,$db);
72 if (!($row = mysql_fetch_assoc($result))) {
73 $msg->printErrors('ITEM_NOT_FOUND');
74 require (AT_INCLUDE_PATH.'footer.inc.php');
80 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
81 <input type="hidden" name="edit_poll" value="true" />
82 <input type="hidden" name="poll_id" value="<?php echo $row['poll_id']; ?>" />
84 <div class="input-form">
86 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="question"><?php echo _AT('question'); ?>:</label><br />
87 <textarea name="question" cols="55" rows="3" id="question"><?php if (isset ($_POST['question'])) { echo htmlspecialchars($_POST['question']); } else { echo htmlspecialchars($row['question']); } ?></textarea>
91 for ($i=1; $i<= AT_NUM_POLL_CHOICES; $i++): ?>
93 <?php if (($i==1) || ($i==2)) { ?>
94 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div>
96 <label for="c<?php echo $i; ?>"><?php echo _AT('choice'); ?> <?php echo $i; ?>:</label><br />
97 <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" />
101 <div class="row buttons">
102 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
103 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?> " />
108 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>