remove old readme
[atutor.git] / docs / 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$\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 $savant->assign('types', $types);\r
101 $savant->display('instructor/groups/create_manual.tmpl.php');\r
102 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>