3 define('AT_INCLUDE_PATH', '../../include/');
4 require (AT_INCLUDE_PATH.'vitals.inc.php');
5 authenticate(AT_PRIV_CERTIFY);
8 if (isset($_POST['certify_id'])) {
9 $certify_id = $addslashes($_POST['certify_id']);
10 } else if (isset($_GET['certify_id'])) {
11 $certify_id = $addslashes($_GET['certify_id']);
14 if (isset($_POST['edit'])) { // Commit edit
18 $certify_selected = $_POST['selected'];
20 $update_remove = array();
21 $update_add = array();
23 $certify_tests = fetchTestList($certify_id);
24 foreach ($certify_tests as $test_id => $test) {
25 if ($test['selected'] and !isset($certify_selected[$test_id])) {
26 $update_remove[] = $test_id;
27 } else if (!$test['selected'] and isset($certify_selected[$test_id])) {
28 $update_add[] = $test_id;
33 if (count($update_add) > 0) {
35 foreach ($update_add as $testid) {
36 $sqlrows[] = '('.$certify_id.",".$testid.')';
38 $sql = "INSERT INTO ".TABLE_PREFIX."certify_tests
41 VALUES ".implode(',',$sqlrows);
43 $result = mysql_query($sql, $db) or die(mysql_error());
44 write_to_log(AT_ADMIN_LOG_INSERT, 'certify', mysql_affected_rows($db), $sql);
48 if (count($update_remove) > 0) {
49 $sql = "DELETE FROM ".TABLE_PREFIX."certify_tests
50 WHERE certify_id = $certify_id
51 AND test_id IN (".implode(",",$update_remove).")";
53 $result = mysql_query($sql, $db) or die(mysql_error());
54 write_to_log(AT_ADMIN_LOG_DELETE, 'certify', mysql_affected_rows($db), $sql);
58 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
61 } else if (isset($_POST['cancel']) || strlen($certify_id) == 0) {
65 // FIXME: Is really a "return" function - need a new text for the button?
67 $msg->addFeedback('CANCELLED');
68 header('Location: index_instructor.php');
74 // FETCH INFO FOR VIEW
76 $certify_tests = fetchTestList($certify_id);
78 require(AT_INCLUDE_PATH.'header.inc.php');
85 For instructor to edit certificate
87 <form name="certifydetails" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
88 <input type="hidden" name="certify_id" value="<?php echo $certify_id; ?>">
90 <table class="data" summary="" rules="cols">
95 <th scope="col"><?php echo _AT('certify_title'); ?></a></th>
102 <input type="submit" name="edit" value="<?php echo _AT('save'); ?>" />
103 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
109 <?php foreach ($certify_tests as $id => $test) { ?>
111 <td><input type="checkbox" <?php if ($test['selected']) { echo 'checked="checked" '; } ?> name="selected[<?= $id ?>]" value="1"></td>
113 <td><label for=""><?php echo $test['title']; ?></label></td>
118 <?php if (count($certify_tests)==0) { ?>
121 <td colspan="2"><?php echo _AT('none_found'); ?></td>
136 require (AT_INCLUDE_PATH.'footer.inc.php');
138 function fetchTestList($certify_id) {
139 global $db, $_SESSION;
141 // Fetch all tests for course
142 // FIXME: Need to filter out tests that doesn't have a pass criteria
143 $sql = "SELECT test_id, title FROM ".TABLE_PREFIX."tests WHERE course_id=".$_SESSION['course_id'];
144 $result = mysql_query($sql, $db) or die(mysql_error() . $sql);
146 $certify_tests = array();
148 while( $row = mysql_fetch_assoc($result) ) {
149 $this_test = array();
150 $this_test['title'] = $row['title'];
151 $this_test['selected'] = false;
152 $certify_tests[$row['test_id']] = $this_test;
155 // Fetch associated tests
156 $sql = "SELECT test_id FROM ".TABLE_PREFIX."certify_tests ";
157 $sql .= "WHERE ".TABLE_PREFIX."certify_tests.certify_id=".$certify_id;
158 $result = mysql_query($sql, $db) or die(mysql_error() . $sql);
160 while( $row = mysql_fetch_assoc($result) ) {
161 $certify_tests[$row['test_id']]['selected'] = true;
163 return $certify_tests;