remove old readme
[atutor.git] / docs / mods / _core / groups / index.php
1 <?php\r
2 /************************************************************************/\r
3 /* ATutor                                                                                                                               */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2002-2010                                              */\r
6 /* Inclusive Design Institute                                           */\r
7 /* http://atutor.ca                                                                                                             */\r
8 /*                                                                                                                                              */\r
9 /* This program is free software. You can redistribute it and/or        */\r
10 /* modify it under the terms of the GNU General Public License          */\r
11 /* as published by the Free Software Foundation.                        */\r
12 /************************************************************************/\r
13 // $Id$\r
14 \r
15 define('AT_INCLUDE_PATH', '../../../include/');\r
16 require(AT_INCLUDE_PATH.'vitals.inc.php');\r
17 authenticate(AT_PRIV_GROUPS);\r
18 \r
19 if (isset($_GET['edit'], $_GET['id'])) {\r
20         $parts = explode('_', $_GET['id'], 2);\r
21         if (isset($parts[1]) && $parts[1]) {\r
22                 header('Location: edit_group.php?id='.$parts[1]);\r
23                 exit;\r
24         } else if ($parts[0]) {\r
25                 header('Location: edit_type.php?id='.$parts[0]);\r
26                 exit;\r
27         }\r
28 } else if (isset($_GET['delete'], $_GET['id'])) {\r
29         $parts = explode('_', $_GET['id'], 2);\r
30         if (isset($parts[1]) && $parts[1]) {\r
31                 header('Location: delete_group.php?id='.$parts[1]);\r
32                 exit;\r
33         } else if ($parts[0]) {\r
34                 header('Location: delete_type.php?id='.$parts[0]);\r
35                 exit;\r
36         }\r
37 } else if (isset($_GET['members'])) {\r
38         $parts = explode('_', $_GET['id'], 2);\r
39         if (isset($parts[1]) && $parts[1]) {\r
40                 header('Location: members.php?id='.$parts[0].SEP.'gid='.$parts[1]);\r
41                 exit;\r
42         } else if ($parts[0]) {\r
43                 header('Location: members.php?id='.$parts[0]);\r
44                 exit;\r
45         } else {\r
46                 $msg->addError('NO_ITEM_SELECTED');\r
47         }\r
48 } else if (isset($_GET['members']) || isset($_GET['delete']) || isset($_GET['edit'])) {\r
49         $msg->addError('NO_ITEM_SELECTED');\r
50 }\r
51 \r
52 require(AT_INCLUDE_PATH.'header.inc.php');\r
53 \r
54 $sql = "SELECT type_id, title FROM ".TABLE_PREFIX."groups_types WHERE course_id=$_SESSION[course_id] ORDER BY title";\r
55 $result = mysql_query($sql, $db);\r
56 ?>\r
57 <div class="input-form">\r
58 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get" name="form">\r
59 <fieldset class="group_form" margin:auto;"><legend class="group_form"><?php echo _AT('groups'); ?></legend>\r
60 <table class="data" summary="" rules="cols" style="width: 80%">\r
61 <tfoot>\r
62 <tr>\r
63         <td>\r
64                 <input type="submit" name="edit"    value="<?php echo _AT('edit'); ?>" />\r
65                 <input type="submit" name="members" value="<?php echo _AT('members'); ?>" />\r
66                 <input type="submit" name="delete"  value="<?php echo _AT('delete'); ?>" />\r
67         </td>\r
68 </tr>\r
69 </tfoot>\r
70 <tbody>\r
71 <?php if ($row = mysql_fetch_assoc($result)): ?>\r
72         <?php do { ?>\r
73 \r
74                 <?php \r
75                         $sql = "SELECT group_id, title FROM ".TABLE_PREFIX."groups WHERE type_id=$row[type_id] ORDER BY title";\r
76                         $group_result = mysql_query($sql, $db);\r
77                         $num_groups = mysql_num_rows($group_result);\r
78                 ?>\r
79                 <tr onmousedown="document.form['g<?php echo $row['type_id']; ?>'].checked = true; rowselect(this);" id="r_<?php echo $row['type_id']; ?>">\r
80                         <th>\r
81                                 <input type="radio" id="g<?php echo $row['type_id']; ?>" name="id" value="<?php echo $row['type_id']; ?>" />\r
82                                 <label for="g<?php echo $row['type_id']; ?>"><?php echo AT_print($row['title'], 'groups.title'); ?></label> (<?php echo $num_groups.' '._AT('groups'); ?>)</td>\r
83                         </th>\r
84                 </tr>\r
85                 <?php if ($num_groups) : ?>\r
86                         <?php while ($group_row = mysql_fetch_assoc($group_result)): ?>\r
87                                 <?php\r
88                                         $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."groups_members WHERE group_id=$group_row[group_id]";\r
89                                         $group_cnt_result = mysql_query($sql, $db);\r
90                                         $group_cnt = mysql_fetch_assoc($group_cnt_result);\r
91                                 ?>\r
92                                 <tr onmousedown="document.form['g<?php echo $row['type_id'].'_'.$group_row['group_id']; ?>'].checked = true; rowselect(this);" id="r_<?php echo $row['type_id'].'_'.$group_row['group_id']; ?>">\r
93                                         <td class="indent"><input type="radio" id="g<?php echo $row['type_id'].'_'.$group_row['group_id']; ?>" name="id" value="<?php echo $row['type_id'].'_'.$group_row['group_id']; ?>" /> <label for="g<?php echo $row['type_id'].'_'.$group_row['group_id']; ?>"><?php echo AT_print($group_row['title'], 'groups.title'); ?></label> (<?php echo $group_cnt['cnt'].' '._AT('members'); ?>)</td>\r
94                                 </tr>\r
95                         <?php endwhile; ?>\r
96                 <?php else: ?>\r
97                         <tr>\r
98                                 <td class="indent"><strong><?php echo _AT('none_found'); ?></strong></td>\r
99                         </tr>\r
100                 <?php endif; ?>\r
101 \r
102         <?php } while ($row = mysql_fetch_assoc($result)); ?>\r
103 <?php else: ?>\r
104         <tr>\r
105                 <td><strong><?php echo _AT('none_found'); ?></strong></td>\r
106         </tr>\r
107 <?php endif; ?>\r
108 </tbody>\r
109 </table>\r
110 </fieldset>\r
111 </form><br />\r
112 </div>\r
113 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>