made a copy
[atutor.git] / tools / polls / index.php
1 <?php
2 /****************************************************************************/
3 /* ATutor                                                                                                                                       */
4 /****************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton        */
6 /* Adaptive Technology Resource Centre / University of Toronto                          */
7 /* http://atutor.ca                                                                                                                     */
8 /*                                                                                                                                                      */
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 // $Id$
14
15 define('AT_INCLUDE_PATH', '../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17
18 authenticate(AT_PRIV_POLLS);
19
20 if (isset($_POST['edit'], $_POST['poll'])) {
21         header('Location: edit.php?poll_id=' . $_POST['poll']);
22         exit;
23 } else if (isset($_POST['delete'], $_POST['poll'])) { 
24         header('Location: delete.php?pid=' . $_POST['poll'] );
25         exit;
26 } else if (!empty($_POST)) {
27         $msg->addError('NO_ITEM_SELECTED');
28 }
29
30 require(AT_INCLUDE_PATH.'header.inc.php'); 
31
32 $orders = array('asc' => 'desc', 'desc' => 'asc');
33 $cols   = array('question' => 1, 'created_date' => 1, 'total' => 1);
34
35 if (isset($_GET['asc'])) {
36         $order = 'asc';
37         $col   = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'created_date';
38 } else if (isset($_GET['desc'])) {
39         $order = 'desc';
40         $col   = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'created_date';
41 } else {
42         // no order set
43         $order = 'desc';
44         $col   = 'created_date';
45 }
46
47 $sql    = "SELECT poll_id, question, created_date, total FROM ".TABLE_PREFIX."polls WHERE course_id=$_SESSION[course_id] ORDER BY $col $order";
48 $result = mysql_query($sql, $db);
49
50
51 ?>
52 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
53 <table class="data" summary="" rules="cols">
54 <colgroup>
55         <?php if ($col == 'question'): ?>
56                 <col />
57                 <col class="sort" />
58                 <col span="2" />
59         <?php elseif($col == 'created_date'): ?>
60                 <col span="2" />
61                 <col class="sort" />
62                 <col />
63         <?php elseif($col == 'total'): ?>
64                 <col span="3" />
65                 <col class="sort" />
66         <?php endif; ?>
67 </colgroup>
68 <thead>
69 <tr>
70         <th scope="col">&nbsp;</th>
71         <th scope="col"><a href="tools/polls/index.php?<?php echo $orders[$order]; ?>=question"><?php echo _AT('question'); ?></a></th>
72         <th scope="col"><a href="tools/polls/index.php?<?php echo $orders[$order]; ?>=created_date"><?php echo _AT('created'); ?></a></th>
73         <th scope="col"><a href="tools/polls/index.php?<?php echo $orders[$order]; ?>=total"><?php echo _AT('total_votes'); ?></a></th>
74 </tr>
75 </thead>
76 <tfoot>
77 <tr>
78         <td colspan="4">
79                 <input type="submit" name="edit"   value="<?php echo _AT('edit'); ?>" />
80                 <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" />
81         </td>
82 </tr>
83 </tfoot>
84 <tbody>
85 <?php if ($row = mysql_fetch_assoc($result)) : ?>
86         <?php do { ?>
87                 <tr onmousedown="document.form['p_<?php echo $row['poll_id']; ?>'].checked = true; rowselect(this);" id="r_<?php echo $row['poll_id']; ?>">
88                         <td><input type="radio" id="p_<?php echo $row['poll_id']; ?>" name="poll" value="<?php echo $row['poll_id']; ?>" /></td>
89                         <td><label for="p_<?php echo $row['poll_id']; ?>"><?php echo AT_print($row['question'], 'polls.question'); ?></label></td>
90                         <td><?php echo AT_DATE(_AT("server_date_format"), $row['created_date']); ?></td>
91                         <td><?php echo $row['total']; ?></td>
92                 </tr>
93         <?php } while($row = mysql_fetch_assoc($result)); ?>
94 <?php else: ?>
95         <tr>
96                 <td colspan="4"><?php echo _AT('none_found'); ?></td>
97         </tr>
98 <?php endif; ?>
99 </tbody>
100 </table>
101 </form>
102
103 <?php require(AT_INCLUDE_PATH.'footer.inc.php');  ?>