2 /************************************************************************/
\r
4 /************************************************************************/
\r
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
\r
6 /* Adaptive Technology Resource Centre / University of Toronto */
\r
7 /* http://atutor.ca */
\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
15 define('AT_INCLUDE_PATH', '../../include/');
\r
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
\r
17 authenticate(AT_PRIV_GROUPS);
\r
19 if (isset($_POST['cancel'])) {
\r
20 $msg->addFeedback('CANCELLED');
\r
21 header('Location: index.php');
\r
23 } else if (isset($_POST['submit'])) {
\r
25 if (isset($_POST['modules'])) {
\r
26 $modules = implode('|', $_POST['modules']);
\r
29 $_POST['type'] = abs($_POST['type']);
\r
30 $_POST['prefix'] = trim($_POST['prefix']);
\r
31 $_POST['new_type'] = trim($_POST['new_type']);
\r
33 $missing_fields = array();
\r
35 if (!$_POST['type'] && !$_POST['new_type']) {
\r
36 $missing_fields[] = _AT('groups_type');
\r
38 if (!$_POST['prefix']) {
\r
39 $missing_fields[] = _AT('title');
\r
41 if ($missing_fields) {
\r
42 $missing_fields = implode(', ', $missing_fields);
\r
43 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
\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
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
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
65 $sql = "INSERT INTO ".TABLE_PREFIX."groups VALUES (NULL, $type_id, '$_POST[prefix]', '$_POST[description]', '$modules')";
\r
66 $result = mysql_query($sql, $db);
\r
68 $group_id = mysql_insert_id($db);
\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
80 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
82 header('Location: index.php');
\r
85 $_POST['new_type'] = $stripslashes($_POST['new_type']);
\r
86 $_POST['prefix'] = $stripslashes($_POST['prefix']);
\r
87 $_POST['description'] = $stripslashes($_POST['description']);
\r
91 require(AT_INCLUDE_PATH.'header.inc.php');
\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']] = $row['title'];
\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
106 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><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
114 <em><?php echo _AT('or'); ?></em>
\r
116 <label for="new"><?php echo _AT('new_type'); ?></label> <input type="text" name="new_type" value="<?php echo htmlspecialchars($_POST['new_type']); ?>" id="new" size="30" maxlength="40" />
\r
120 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="prefix"><?php echo _AT('title'); ?></label><br />
\r
121 <input type="text" name="prefix" id="prefix" value="<?php echo htmlspecialchars($_POST['prefix']); ?>" size="20" maxlength="40" />
\r
125 <label for="description"><?php echo _AT('description'); ?></label><br />
\r
126 <textarea name="description" id="description" cols="10" rows="2"><?php echo htmlspecialchars($_POST['description']); ?></textarea>
\r
130 <?php echo _AT('tools'); ?><br />
\r
132 $modules = $moduleFactory->getModules(AT_MODULE_STATUS_ENABLED, 0, TRUE);
\r
133 $keys = array_keys($modules);
\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
141 <?php endforeach; ?>
\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
151 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>