2 define('AT_INCLUDE_PATH', '../../include/');
3 require (AT_INCLUDE_PATH.'vitals.inc.php');
4 authenticate(AT_PRIV_CERTIFY);
7 if (isset($_POST['certify_id'])) {
8 $certify_id = $addslashes($_POST['certify_id']);
9 } else if (isset($_GET['certify_id'])) {
10 $certify_id = $addslashes($_GET['certify_id']);
13 $templatefile = AT_CONTENT_DIR .'certify/template_'.$certify_id.'.pdf';
14 $templatepresent = file_exists($templatefile);
16 function let_to_num($v){ //This function transforms the php.ini notation for numbers (like '2M') to an integer (2*1024*1024 in this case)
18 $ret = substr($v, 0, -1);
19 switch(strtoupper($l)){
34 $max_upload_size = min(let_to_num(ini_get('post_max_size')), let_to_num(ini_get('upload_max_filesize')));
37 $certify_description = '';
39 if (isset($_POST['submit'])) { // Incoming changes
41 $certify_title = $addslashes($_POST['certify_title']);
42 $certify_description = $addslashes($_POST['certify_description']);
44 if (strlen($certify_id) > 0) {
48 $sql = "UPDATE ".TABLE_PREFIX."certify
50 title = '$certify_title',
51 description = '$certify_description'
53 certify_id = $certify_id
56 $result = mysql_query($sql, $db) or die(mysql_error());
58 if (file_exists($templatefile))
59 unlink($templatefile);
60 if ($_FILES['certify_file']['size'] > 0 && $_FILES['certify_file']['error'] == 0) {
61 if (move_uploaded_file($_FILES['certify_file']['tmp_name'], $templatefile)) {
64 unlink($templatefile);
67 $templatepresent = file_exists($templatefile);
69 //write_to_log(AT_ADMIN_LOG_UPDATE, 'certify', mysql_affected_rows($db), $sql);
71 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
73 header('Location: index_instructor.php');
80 $sql = "INSERT INTO ".TABLE_PREFIX."certify
84 VALUES (". $_SESSION['course_id'] .",
85 '". $certify_title ."',
86 '". $certify_description ."')";
88 $result = mysql_query($sql, $db) or die(mysql_error());
90 if ($_FILES['certify_file']['size'] > 0 && $_FILES['certify_file']['error'] == 0) {
91 if (move_uploaded_file($_FILES['certify_file']['tmp_name'], $templatefile)) {
94 unlink($templatefile);
97 $templatepresent = file_exists($templatefile);
99 $certify_id = mysql_insert_id($db);
100 write_to_log(AT_ADMIN_LOG_INSERT, 'certify', mysql_affected_rows($db), $sql);
102 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
104 header('Location: index_instructor.php');
110 } else if (isset($_POST['cancel'])) { // Cancelled
114 $msg->addFeedback('CANCELLED');
115 header('Location: index_instructor.php');
118 } else if (strlen($certify_id) > 0) {
123 $sql = "SELECT * from ".TABLE_PREFIX."certify where certify_id=".$certify_id;
124 $result = mysql_query($sql, $db) or die(mysql_error());
125 $row = mysql_fetch_assoc($result);
128 exit; // TODO: Invalid id - how to handle?
130 $certify_title = $row['title'];
131 $certify_description = $row['description'];
135 require(AT_INCLUDE_PATH.'header.inc.php');
140 <p>For instructor to add new certificate
143 <form enctype="multipart/form-data" name="certifydetails" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
144 <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_upload_size; ?>"> <!-- We have no real need to restrict the upload here -->
145 <?php if (strlen($certify_id) > 0) { ?>
146 <input type="hidden" name="certify_id" value="<?php echo $certify_id; ?>">
149 <dt><label for="certify_title"><?php echo _AT('certify_title'); ?></label></dt>
150 <dd><input type="text" name="certify_title" maxlength="60" value="<?php echo $certify_title; ?>"></dd>
151 <dt><label for="certify_description"><?php echo _AT('certify_description'); ?></label></dt>
152 <dd><textarea name="certify_description" cols="40" rows="5"><?php echo $certify_description; ?></textarea></dd>
153 <dt><label for="certify_file"><?php echo _AT('certify_file'); ?></label></dt>
154 <dd><input type="file" name="certify_file"></dd>
156 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>">
157 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
160 <!-- TODO: Download link for existing template -->
163 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>