ATutor 2.0
[atutor.git] / mods / _core / groups / create_manual.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: create_manual.php 7482 2008-05-06 17:44:49Z greg $\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($_POST['cancel'])) {\r
20         $msg->addFeedback('CANCELLED');\r
21         header('Location: index.php');\r
22         exit;\r
23 } else if (isset($_POST['submit'])) {\r
24         $modules = '';\r
25         if (isset($_POST['modules'])) {\r
26                 $modules = implode('|', $_POST['modules']);\r
27         }\r
28 \r
29         $_POST['type']   = abs($_POST['type']);\r
30         $_POST['prefix'] = trim($_POST['prefix']);\r
31         $_POST['new_type'] = trim($_POST['new_type']);\r
32 \r
33         $missing_fields = array();\r
34 \r
35         if (!$_POST['type'] && !$_POST['new_type']) {\r
36                 $missing_fields[] = _AT('groups_type');\r
37         }\r
38         if (!$_POST['prefix']) {\r
39                 $missing_fields[] = _AT('title');\r
40         }\r
41         if ($missing_fields) {\r
42                 $missing_fields = implode(', ', $missing_fields);\r
43                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));\r
44         }\r
45 \r
46         if (!$msg->containsErrors()) {\r
47                 $_POST['new_type'] = $addslashes($_POST['new_type']);\r
48                 $_POST['prefix']      = $addslashes($_POST['prefix']);\r
49                 $_POST['description'] = $addslashes($_POST['description']);\r
50 \r
51                 if ($_POST['new_type']) {\r
52                         $sql = "INSERT INTO ".TABLE_PREFIX."groups_types VALUES (NULL, $_SESSION[course_id], '$_POST[new_type]')";\r
53                         $result = mysql_query($sql, $db);\r
54                         $type_id = mysql_insert_id($db);\r
55                 } else {\r
56                         $sql = "SELECT type_id FROM ".TABLE_PREFIX."groups_types WHERE course_id=$_SESSION[course_id] AND type_id=$_POST[type]";\r
57                         $result = mysql_query($sql, $db);\r
58                         if ($row = mysql_fetch_assoc($result)) {\r
59                                 $type_id = $row['type_id'];\r
60                         } else {\r
61                                 $type_id = FALSE;\r
62                         }\r
63                 }\r
64                 if ($type_id) {\r
65                         $sql = "INSERT INTO ".TABLE_PREFIX."groups VALUES (NULL, $type_id, '$_POST[prefix]', '$_POST[description]', '$modules')";\r
66                         $result = mysql_query($sql, $db);\r
67 \r
68                         $group_id = mysql_insert_id($db);\r
69 \r
70                         $_SESSION['groups'][$group_id] = $group_id;\r
71                         // call module init scripts:\r
72                         if (isset($_POST['modules'])) {\r
73                                 foreach ($_POST['modules'] as $mod) {\r
74                                         $module =& $moduleFactory->getModule($mod);\r
75                                         $module->createGroup($group_id);\r
76                                 }\r
77                         }\r
78                 }\r
79 \r
80                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');\r
81 \r
82                 header('Location: index.php');\r
83                 exit;\r
84         } else {\r
85                 $_POST['new_type']    = $stripslashes($_POST['new_type']);\r
86                 $_POST['prefix']      = $stripslashes($_POST['prefix']);\r
87                 $_POST['description'] = $stripslashes($_POST['description']);\r
88         }\r
89 }\r
90 \r
91 require(AT_INCLUDE_PATH.'header.inc.php');\r
92 \r
93 $types = array();\r
94 $sql = "SELECT type_id, title FROM ".TABLE_PREFIX."groups_types WHERE course_id=$_SESSION[course_id] ORDER BY title";\r
95 $result = mysql_query($sql, $db);\r
96 while ($row = mysql_fetch_assoc($result)) {\r
97         $types[$row['type_id']] = htmlentities_utf8($row['title']);\r
98 }\r
99 \r
100 ?>\r
101 \r
102 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">\r
103         <div class="input-form">\r
104         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('groups_create_manual'); ?></legend>\r
105                 <div class="row">\r
106                         <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="type"><?php echo _AT('groups_type'); ?></label><br />\r
107                         <?php if ($types): ?>\r
108                                 <?php echo _AT('existing_type'); ?>\r
109                                 <select name="type" id="type">\r
110                                 <?php foreach ($types as $type_id => $type_title): ?>\r
111                                         <option value="<?php echo $type_id; ?>"><?php echo $type_title; ?></option>\r
112                                 <?php endforeach; ?>\r
113                                 </select>\r
114                                 <em><?php echo _AT('or'); ?></em>\r
115                         <?php endif; ?>\r
116                         <label for="new"><?php echo _AT('new_type'); ?></label> <input type="text" name="new_type" value="<?php echo htmlentities_utf8($_POST['new_type']); ?>" id="new" size="30" maxlength="40" />\r
117                 </div>\r
118 \r
119                 <div class="row">\r
120                         <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="prefix"><?php echo _AT('title'); ?></label><br />\r
121                         <input type="text" name="prefix" id="prefix" value="<?php echo htmlentities_utf8($_POST['prefix']); ?>" size="20" maxlength="40" />\r
122                 </div>\r
123 \r
124                 <div class="row">\r
125                         <label for="description"><?php echo _AT('description'); ?></label><br />\r
126                         <textarea name="description" id="description" cols="10" rows="2"><?php echo htmlentities_utf8($_POST['description']); ?></textarea>\r
127                 </div>\r
128 \r
129                 <div class="row">\r
130                         <?php echo _AT('tools'); ?><br />\r
131                                 <?php\r
132                                 $modules = $moduleFactory->getModules(AT_MODULE_STATUS_ENABLED, 0, TRUE);\r
133                                 $keys = array_keys($modules);\r
134                                 $i=0;\r
135                                 ?>\r
136                                 <?php foreach($keys as $module_name): ?>\r
137                                         <?php $module =& $modules[$module_name]; ?>\r
138                                         <?php if ($module->getGroupTool() && (in_array($module->getGroupTool(),$_pages[AT_NAV_HOME]) || in_array($module->getGroupTool(),$_pages[AT_NAV_COURSE])) ): ?>\r
139                                                 <input type="checkbox" value="<?php echo $module_name; ?>" name="modules[]" id="m<?php echo ++$i; ?>" /><label for="m<?php echo $i; ?>"><?php echo $module->getName(); ?></label><br />\r
140                                         <?php endif; ?>\r
141                                 <?php endforeach; ?>\r
142                 </div>\r
143 \r
144                 <div class="row buttons">\r
145                         <input type="submit" name="submit" value="<?php echo _AT('create'); ?>" accesskey="s" />\r
146                         <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />\r
147                 </div>\r
148                 </fieldset>\r
149         </div>\r
150 </form>\r
151 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>