remove old readme
[atutor.git] / docs / mods / _standard / tests / edit_test.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
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 $page = 'tests';
16 define('AT_INCLUDE_PATH', '../../../include/');
17 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/test_result_functions.inc.php');
19
20 authenticate(AT_PRIV_TESTS);
21
22 $tid = intval($_REQUEST['tid']);
23
24 if (isset($_POST['cancel'])) {
25         $msg->addFeedback('CANCELLED');
26         header('Location: index.php');
27         exit;
28 } else if (isset($_POST['submit'])) {
29         $missing_fields             = array();
30         $_POST['title']                         = $addslashes(trim($_POST['title']));
31         $_POST['description']  = $addslashes(trim($_POST['description']));
32         $_POST['format']                        = intval($_POST['format']);
33         $_POST['randomize_order']       = intval($_POST['randomize_order']);
34         $_POST['num_questions']         = intval($_POST['num_questions']);
35         $_POST['passpercent']   = intval($_POST['passpercent']);
36         $_POST['passscore']     = intval($_POST['passscore']);
37         $_POST['passfeedback']  = $addslashes(trim($_POST['passfeedback']));
38         $_POST['failfeedback']  = $addslashes(trim($_POST['failfeedback']));
39         $_POST['num_takes']                     = intval($_POST['num_takes']);
40         $_POST['anonymous']                     = intval($_POST['anonymous']);
41         $_POST['display']                       = intval($_POST['display']);
42         $_POST['allow_guests']      = $_POST['allow_guests'] ? 1 : 0;
43         $_POST['show_guest_form']   = $_POST['show_guest_form'] ? 1 : 0;
44         $_POST['instructions']      = $addslashes($_POST['instructions']);
45         $_POST['result_release']        = intval($_POST['result_release']); 
46
47         /* this doesn't actually get used: */
48         $_POST['difficulty'] = intval($_POST['difficulty']);
49         if ($_POST['difficulty'] == '') {
50                 $_POST['difficulty'] = 0;
51         }
52
53         $_POST['content_id'] = intval($_POST['content_id']);
54         if ($_POST['content_id'] == '') {
55                 $_POST['content_id'] = 0;
56         }
57
58
59         $_POST['instructions'] = trim($_POST['instructions']);
60
61         if ($_POST['title'] == '') {
62                 $missing_fields[] = _AT('title');
63         }
64
65         if ($_POST['random'] && !$_POST['num_questions']) {
66                 $missing_fields[] = _AT('num_questions_per_test');
67         }
68
69         if ($_POST['pass_score']==1 && !$_POST['passpercent']) {
70                 $missing_fields[] = _AT('percentage_score');
71         }
72
73         if ($_POST['pass_score']==2 && !$_POST['passscore']) {
74                 $missing_fields[] = _AT('points_score');
75         }
76
77
78         /* 
79          * If test is anonymous and have submissions, then we don't permit changes.
80          * This addresses the following issue: http://www.atutor.ca/atutor/mantis/view.php?id=3268
81          * TODO:        Add an extra column in test_results to remember the state of anonymous submissions.
82          *                      make changes accordingly on line 255 as well.
83          */
84         $sql = "SELECT t.test_id, anonymous FROM ".TABLE_PREFIX."tests_results r NATURAL JOIN ".TABLE_PREFIX."tests t WHERE r.test_id = t.test_id AND r.test_id=$tid";
85         $result = mysql_query($sql, $db);
86         if ($row = mysql_fetch_assoc($result)) {
87                 //If there are submission(s) for this test, anonymous field will not be altered.
88                 $_POST['anonymous'] = $row['anonymous'];
89         }
90
91         if ($missing_fields) {
92                 $missing_fields = implode(', ', $missing_fields);
93                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
94         }
95
96         $day_start      = intval($_POST['day_start']);
97         $month_start= intval($_POST['month_start']);
98         $year_start     = intval($_POST['year_start']);
99         $hour_start     = intval($_POST['hour_start']);
100         $min_start      = intval($_POST['min_start']);
101
102         $day_end        = intval($_POST['day_end']);
103         $month_end      = intval($_POST['month_end']);
104         $year_end       = intval($_POST['year_end']);
105         $hour_end       = intval($_POST['hour_end']);
106         $min_end        = intval($_POST['min_end']);
107
108         if (!checkdate($month_start, $day_start, $year_start)) {
109                 $msg->addError('START_DATE_INVALID');
110         }
111
112         if (!checkdate($month_end, $day_end, $year_end)) {
113                 $msg->addError('END_DATE_INVALID');
114         }
115
116         if (mktime($hour_end,   $min_end,   0, $month_end,   $day_end,   $year_end) < 
117                 mktime($hour_start, $min_start, 0, $month_start, $day_start, $year_start)) {
118                         $msg->addError('END_DATE_INVALID');
119         }
120
121         if (strlen($month_start) == 1){
122                 $month_start = "0$month_start";
123         }
124         if (strlen($day_start) == 1){
125                 $day_start = "0$day_start";
126         }
127         if (strlen($hour_start) == 1){
128                 $hour_start = "0$hour_start";
129         }
130         if (strlen($min_start) == 1){
131                 $min_start = "0$min_start";
132         }
133         if (strlen($month_end) == 1){
134                 $month_end = "0$month_end";
135         }
136         if (strlen($day_end) == 1){
137                 $day_end = "0$day_end";
138         }
139         if (strlen($hour_end) == 1){
140                 $hour_end = "0$hour_end";
141         }
142         if (strlen($min_end) == 1){
143                 $min_end = "0$min_end";
144         }
145
146         $start_date = "$year_start-$month_start-$day_start $hour_start:$min_start:00";
147         $end_date       = "$year_end-$month_end-$day_end $hour_end:$min_end:00";
148
149         if (!$msg->containsErrors()) {
150                 // just to make sure we own this test:
151                 $sql    = "SELECT * FROM ".TABLE_PREFIX."tests WHERE test_id=$tid AND course_id=$_SESSION[course_id]";
152                 $result = mysql_query($sql, $db);
153
154                 if ($row = mysql_fetch_assoc($result)) {
155                         if ($_POST['random']) {
156                                 $total_weight = get_total_weight($tid, $_POST['num_questions']);
157                         } else {
158                                 $total_weight = get_total_weight($tid);
159                         }
160                         //If title exceeded database defined length, truncate it.
161                         $_POST['title'] = validate_length($_POST['title'], 100);
162
163                         $sql = "UPDATE ".TABLE_PREFIX."tests " . 
164                                "SET title='$_POST[title]', 
165                                     description='$_POST[description]', 
166                                     format=$_POST[format], 
167                                     start_date='$start_date', 
168                                     end_date='$end_date', 
169                                     randomize_order=$_POST[randomize_order], 
170                                     num_questions=$_POST[num_questions], 
171                                     instructions='$_POST[instructions]', 
172                                     content_id=$_POST[content_id],  
173                                     passscore=$_POST[passscore], 
174                               passpercent=$_POST[passpercent], 
175                               passfeedback='$_POST[passfeedback]', 
176                               failfeedback='$_POST[failfeedback]', 
177                                     result_release=$_POST[result_release], 
178                                     random=$_POST[random], 
179                                     difficulty=$_POST[difficulty], 
180                                     num_takes=$_POST[num_takes], 
181                                     anonymous=$_POST[anonymous], 
182                                     guests=$_POST[allow_guests], 
183                                     show_guest_form=$_POST[show_guest_form],
184                                     out_of=$total_weight, 
185                                     display=$_POST[display] 
186                                 WHERE test_id=$tid 
187                                 AND course_id=$_SESSION[course_id]";
188                                 
189                         $result = mysql_query($sql, $db);
190
191                         $sql = "DELETE FROM ".TABLE_PREFIX."tests_groups WHERE test_id=$tid";
192                         $result = mysql_query($sql, $db);       
193                         
194                         if (isset($_POST['groups'])) {
195                                 $sql = "INSERT INTO ".TABLE_PREFIX."tests_groups VALUES ";
196                                 foreach ($_POST['groups'] as $group) {
197                                         $group = intval($group);
198                                         $sql .= "($tid, $group),";
199                                 }
200                                 $sql = substr($sql, 0, -1);
201                                 $result = mysql_query($sql, $db);
202                         }
203                 }
204                 
205                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');             
206                 
207                 header('Location: index.php');
208                 exit;
209         }
210 }
211
212 $onload = 'document.form.title.focus();';
213
214 require(AT_INCLUDE_PATH.'header.inc.php');
215
216 if (!isset($_POST['submit'])) {
217         $sql    = "SELECT *, DATE_FORMAT(start_date, '%Y-%m-%d %H:%i:00') AS start_date, DATE_FORMAT(end_date, '%Y-%m-%d %H:%i:00') AS end_date FROM ".TABLE_PREFIX."tests WHERE test_id=$tid AND course_id=$_SESSION[course_id]";
218         $result = mysql_query($sql, $db);
219
220         if (!($row = mysql_fetch_assoc($result))){
221                 $msg->printErrors('ITEM_NOT_FOUND');
222                 require (AT_INCLUDE_PATH.'footer.inc.php');
223                 exit;
224         }
225
226         $_POST  = $row;
227         $_POST['allow_guests'] = $row['guests'];
228 } else {
229         $_POST['start_date'] = $start_date;
230         $_POST['end_date']       = $end_date;
231 }
232         
233 $msg->printErrors();
234
235 ?>
236
237 <script language="javascript" type="text/javascript">
238 function disable_texts (name) {
239         if (name == 'both')
240         {
241                 document.form['passpercent'].disabled=true;
242                 document.form['passscore'].disabled=true;
243                 document.form['passpercent'].value=0;
244                 document.form['passscore'].value=0;
245         }
246         else if (name == 'percentage')
247         {
248                 document.form['passpercent'].disabled=true;
249                 document.form['passpercent'].value=0;
250                 document.form['passscore'].disabled=false;
251         }
252         else if (name == 'points')
253         {
254                 document.form['passpercent'].disabled=false;
255                 document.form['passscore'].disabled=true;
256                 document.form['passscore'].value=0;
257         }
258 }
259 </script>
260
261 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
262 <input type="hidden" name="tid" value="<?php echo $tid; ?>" />
263 <input type="hidden" name="randomize_order" value="1" />
264 <input type="hidden" name="instructions" value="" />
265 <input type="hidden" name="difficulty" value="0" />
266
267 <div class="input-form">
268         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('edit_test'); ?></legend>
269         <div class="row">
270                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php echo _AT('title'); ?></label><br />
271                 <input type="text" name="title" id="title" size="40" value="<?php echo stripslashes(htmlspecialchars($_POST['title'])); ?>" />
272         </div>
273         
274         <div class="row">
275                 <label for="description"><?php echo _AT('test_description'); ?></label><br />
276                 <textarea name="description" cols="35" rows="3" id="description"><?php echo htmlspecialchars($_POST['description']); ?></textarea>
277         </div>
278
279         <div class="row">       
280                 <label for="num_t"><?php echo _AT('num_takes_test'); ?></label><br />
281                 <select name="num_takes" id="num_t">
282                         <option value="<?php echo AT_TESTS_TAKE_UNLIMITED; ?>" <?php if ($_POST['num_takes'] == AT_TESTS_TAKE_UNLIMITED) { echo 'selected="selected"'; } ?>><?php echo _AT('unlimited'); ?></option>
283                 
284                         <option value="1"<?php if ($_POST['num_takes'] == 1) { echo ' selected="selected"'; } ?>>1</option>
285                         <option value="2"<?php if ($_POST['num_takes'] == 2) { echo ' selected="selected"'; } ?>>2</option>
286                         <option value="3"<?php if ($_POST['num_takes'] == 3) { echo ' selected="selected"'; } ?>>3</option>
287                         <option value="4"<?php if ($_POST['num_takes'] == 4) { echo ' selected="selected"'; } ?>>4</option>
288                         <option value="5"<?php if ($_POST['num_takes'] == 5) { echo ' selected="selected"'; } ?>>5</option>
289                         <option value="6"<?php if ($_POST['num_takes'] == 6) { echo ' selected="selected"'; } ?>>6</option>
290                         <option value="7"<?php if ($_POST['num_takes'] == 7) { echo ' selected="selected"'; } ?>>7</option>
291                         <option value="8"<?php if ($_POST['num_takes'] == 8) { echo ' selected="selected"'; } ?>>8</option>
292                         <option value="9"<?php if ($_POST['num_takes'] == 9) { echo ' selected="selected"'; } ?>>9</option>
293                         <option value="10"<?php if ($_POST['num_takes'] == 10) { echo ' selected="selected"'; } ?>>10</option>
294                         <option value="15"<?php if ($_POST['num_takes'] == 15) { echo ' selected="selected"'; } ?>>15</option>
295                         <option value="20"<?php if ($_POST['num_takes'] >= 20) { echo ' selected="selected"'; } ?>>20</option>
296                 </select>
297         </div>
298         
299         <div class="row">
300                 <?php echo _AT('available_on_my_courses'); ?><br />
301                 <?php 
302                         if ($_POST['format'] == 1) {
303                                 $y = 'checked="checked"';
304                                 $n = '';
305                         } else {
306                                 $y = '';
307                                 $n = 'checked="checked"';
308                         }
309                 ?>
310                 <input type="radio" name="format" id="formatN" value="0" <?php echo $n; ?> /><label for="formatN"><?php echo _AT('no'); ?></label> 
311                 <input type="radio" name="format" id="formatY" value="1" <?php echo $y; ?> /><label for="formatY"><?php echo _AT('yes'); ?></label>
312         </div>
313
314         <div class="row">
315                 <?php echo _AT('anonymous_test'); ?><br />
316                 <?php 
317                         if ($_POST['anonymous'] == 1) {
318                                 $y = 'checked="checked"';
319                                 $n = '';
320                         } else {
321                                 $y = '';
322                                 $n = 'checked="checked"';
323                         }
324                 ?>
325                 <?php
326                         // This addresses the following issue: http://www.atutor.ca/atutor/mantis/view.php?id=3268
327                         // Ref: line 64
328                         $sql = "SELECT t.test_id, anonymous FROM ".TABLE_PREFIX."tests_results r NATURAL JOIN ".TABLE_PREFIX."tests t WHERE r.test_id = t.test_id AND r.test_id=$tid";
329                         $result = mysql_query($sql, $db);
330                         $anonymous_disabled = '';
331                         if ($row = mysql_fetch_assoc($result)) {
332                                 //If there are submission(s) for this test, anonymous field will not be altered.
333                                 $anonymous_disabled = 'disabled';
334                         }
335                 ?>
336                 <input type="radio" name="anonymous" id="anonN" value="0" <?php echo $n; ?> <?php echo $anonymous_disabled; ?> /><label for="anonN"><?php echo _AT('no'); ?></label>
337                 <input type="radio" name="anonymous" value="1" id="anonY" <?php echo $y; ?> <?php echo $anonymous_disabled; ?> /><label for="anonY"><?php echo _AT('yes'); ?></label>
338                 <?php
339                         if ($anonymous_disabled != ""){
340                                 echo '('._AT('disabled').')';
341                         }
342                 ?>
343         </div>
344
345
346         <div class="row">
347                 <?php echo _AT('allow_guests'); ?><br />
348                 <?php 
349                         if ($_POST['allow_guests'] == 1) {
350                                 $y = 'checked="checked"';
351                                 $n = '';
352                                 $disable_show_guest_form = '';
353                         } else {
354                                 $y = '';
355                                 $n = 'checked="checked"';
356                                 $disable_show_guest_form = 'disabled="disabled"';
357                         }
358                 ?>
359
360                 <input type="radio" name="allow_guests" id="allow_guestsN" value="0" <?php echo $n; ?> onfocus="document.form.show_guest_form.checked=false; document.form.show_guest_form.disabled=true;" /><label for="allow_guestsN"><?php echo _AT('no'); ?></label> 
361                 <input type="radio" name="allow_guests" value="1" id="allow_guestsY" <?php echo $y; ?> onfocus="document.form.show_guest_form.disabled=false;" /><label for="allow_guestsY"><?php echo _AT('yes'); ?></label>
362     <br />
363                 <?php 
364                         if ($_POST['show_guest_form'] == 1)
365                                 $y = 'checked="checked"';
366                         else
367                                 $y = '';
368                 ?>
369
370                 <input type="checkbox" name="show_guest_form" id="show_guest_form" value="1" <?php echo $y . ' '. $disable_show_guest_form; ?> /><label for="show_guest_form"><?php echo _AT('show_guest_form'); ?></label> 
371         </div>
372
373         <div class="row">
374                 <?php echo _AT('display'); ?><br />
375                 <?php 
376                         if ($_POST['display'] == 1) {
377                                 $y = 'checked="checked"';
378                                 $n = '';
379                         } else {
380                                 $y = '';
381                                 $n = 'checked="checked"';
382                         }
383                 ?>
384
385                 <input type="radio" name="display" id="displayN" value="0" <?php echo $n; ?> /><label for="displayN"><?php echo _AT('all_questions_on_page'); ?></label> 
386                 <input type="radio" name="display" id="displayY" value="1" <?php echo $y; ?> /><label for="displayY"><?php echo _AT('one_question_per_page'); ?></label>
387         </div>
388
389         <div class="row">
390                 <?php echo _AT('pass_score'); ?><br />
391                 <input type="radio" name="pass_score" value="0" id="no" <?php if ($_POST['passpercent'] == 0 && $_POST['passscore'] == 0){echo 'checked="true"';} ?> 
392                  onfocus="disable_texts('both');" />
393
394                 <label for="no" title="<?php echo _AT('pass_score'). ': '. _AT('no_pass_score');  ?>"><?php echo _AT('no_pass_score'); ?></label><br />
395
396                 <input type="radio" name="pass_score" value="1" id="percentage"  <?php if ($_POST['passpercent'] <> 0){echo 'checked="true"';} ?>
397                  onfocus="disable_texts('points');" />
398
399                 <input type="text" name="passpercent" id="passpercent" size="2" value="<?php echo $_POST['passpercent']; ?>" 
400                  <?php if ($_POST['passpercent'] == 0){echo 'disabled="true"';} ?> /> 
401                 <label for="percentage" title="<?php echo _AT('pass_score'). ': '. _AT('percentage_score');  ?>"><?php  echo '% ' . _AT('percentage_score'); ?></label><br />
402
403                 <input type="radio" name="pass_score" value="2" id="points"  <?php if ($_POST['passscore'] <> 0){echo 'checked="true"';} ?>
404                  onfocus="disable_texts('percentage');" />
405
406                 <input type="text" name="passscore" id="passscore" size="2" value="<?php echo $_POST['passscore']; ?>" 
407                  <?php if ($_POST['passscore'] == 0){echo 'disabled="true"';} ?>/> 
408                 <label for="points" title="<?php echo _AT('pass_score'). ': '. _AT('points_score');  ?>"><?php  echo _AT('points_score'); ?></label>
409         </div>
410
411         <div class="row">
412                 <label for="passfeedback"><?php echo _AT('pass_feedback'); ?></label><br />
413                 <textarea name="passfeedback" cols="35" rows="1" id="passfeedback"><?php echo htmlspecialchars($_POST['passfeedback']); ?></textarea>
414         </div>
415
416         <div class="row">
417                 <label for="failfeedback"><?php echo _AT('fail_feedback'); ?></label><br />
418                 <textarea name="failfeedback" cols="35" rows="1" id="failfeedback"><?php echo htmlspecialchars($_POST['failfeedback']); ?></textarea>
419         </div>
420
421         <div class="row">
422                 <?php echo _AT('result_release'); ?><br />
423                 <?php 
424                         if ($_POST['result_release'] == AT_RELEASE_IMMEDIATE) {
425                                 $check_marked = $check_never = '';
426                                 $check_immediate = 'checked="checked"';
427
428                         } else if ($_POST['result_release'] == AT_RELEASE_MARKED) {
429                                 $check_immediate = $check_never = '';
430                                 $check_marked = 'checked="checked"';
431
432                         } else if ($_POST['result_release'] == AT_RELEASE_NEVER) {
433                                 $check_immediate = $check_marked = '';
434                                 $check_never = 'checked="checked"';
435                         }
436                 ?>
437
438                 <input type="radio" name="result_release" id="release1" value="<?php echo AT_RELEASE_IMMEDIATE; ?>" <?php echo $check_immediate; ?> /><label for="release1"><?php echo _AT('release_immediate'); ?></label><br />
439                 <input type="radio" name="result_release" id="release2" value="<?php echo AT_RELEASE_MARKED; ?>" <?php echo $check_marked; ?> /><label for="release2"><?php echo _AT('release_marked'); ?></label><br />
440                 <input type="radio" name="result_release" id="release3" value="<?php echo AT_RELEASE_NEVER; ?>" <?php echo $check_never; ?>/><label for="release3"><?php echo _AT('release_never'); ?></label>
441         </div>
442
443         <div class="row">
444                 <?php echo _AT('randomize_questions'); ?><br />
445                 <?php 
446                         if ($_POST['random'] == 1) {
447                                 $y = 'checked="checked"';
448                                 $n = $disabled = '';
449                         } else {
450                                 $y = '';
451                                 $n = 'checked="checked"';
452                                 $disabled = 'disabled="disabled" ';
453                         }
454                 ?>
455                 <input type="radio" name="random" id="random" value="0" checked="checked" onfocus="document.form.num_questions.disabled=true;" /><label for="random"><?php echo _AT('no'); ?></label>. <input type="radio" name="random" value="1" id="ry" onfocus="document.form.num_questions.disabled=false;" <?php echo $y; ?> /><label for="ry"><?php echo _AT('yes'); ?></label>, <input type="text" name="num_questions" id="num_questions" size="2" value="<?php echo $_POST['num_questions']; ?>" <?php echo $disabled . $n; ?> /> <label for="num_questions"><?php echo _AT('num_questions_per_test'); ?></label>
456         </div>
457
458         <div class="row">
459                 <?php echo _AT('start_date'); ?><br />
460                 <?php
461                         $today_day   = substr($_POST['start_date'], 8, 2);
462                         $today_mon   = substr($_POST['start_date'], 5, 2);
463                         $today_year  = substr($_POST['start_date'], 0, 4);
464
465                         $today_hour  = substr($_POST['start_date'], 11, 2);
466                         $today_min   = substr($_POST['start_date'], 14, 2);
467
468                         $name = '_start';
469                         require(AT_INCLUDE_PATH.'html/release_date.inc.php');
470                 ?>
471         </div>
472         <div class="row">
473                 <?php echo _AT('end_date'); ?><br />
474                 <?php
475                         $today_day   = substr($_POST['end_date'], 8, 2);
476                         $today_mon   = substr($_POST['end_date'], 5, 2);
477                         $today_year  = substr($_POST['end_date'], 0, 4);
478
479                         $today_hour  = substr($_POST['end_date'], 11, 2);
480                         $today_min   = substr($_POST['end_date'], 14, 2);
481
482                         $name = '_end';
483                         require(AT_INCLUDE_PATH.'html/release_date.inc.php');
484                 ?>
485         </div>
486
487         <div class="row">
488                 <label for="inst"><?php echo _AT('limit_to_group'); ?></label><br />
489                 <?php
490                         //show groups
491                         //get groups currently allowed
492                         $current_groups = array();
493                         $sql    = "SELECT group_id FROM ".TABLE_PREFIX."tests_groups WHERE test_id=$tid";
494                         $result = mysql_query($sql, $db);
495                         while ($row = mysql_fetch_assoc($result)) {
496                                 $current_groups[] = $row['group_id'];
497                         }
498
499                         //show groups
500                         $sql    = "SELECT * FROM ".TABLE_PREFIX."groups_types WHERE course_id=$_SESSION[course_id] ORDER BY title";
501                         $result = mysql_query($sql, $db);
502                         if (mysql_num_rows($result)) {
503                                 while ($row = mysql_fetch_assoc($result)) {
504                                         echo '<strong>'.$row['title'].'</strong><br />';
505
506                                         $sql    = "SELECT * FROM ".TABLE_PREFIX."groups WHERE type_id=$row[type_id] ORDER BY title";
507                                         $g_result = mysql_query($sql, $db);
508                                         while ($grow = mysql_fetch_assoc($g_result)) {
509                                                 echo '&nbsp;<label><input type="checkbox" value="'.$grow['group_id'].'" name="groups['.$grow['group_id'].']" '; 
510                                                 if (is_array($current_groups) && in_array($grow['group_id'], $current_groups)) {
511                                                         echo 'checked="checked"';
512                                                 }
513                                                 echo '/>'.$grow['title'].'</label><br />';
514                                         }
515                                 }
516                         } else {
517                                 echo _AT('none_found');
518                         }
519                 ?>
520         </div>
521
522         <div class="row">
523                 <label for="inst"><?php echo _AT('instructions'); ?></label><br />
524                 <textarea name="instructions" cols="35" rows="3" id="inst"><?php echo htmlspecialchars($_POST['instructions']); ?></textarea>
525         </div>
526
527
528         <div class="row buttons">
529                 <input type="submit" value="<?php echo _AT('save');  ?>"  name="submit" accesskey="s" />
530                 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
531         </div>
532         </fieldset>
533 </div>
534 </form>
535
536 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>