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
13 // $Id: certificate_edit.php 7208 2008-02-20 16:07:24Z cindy $
\r
15 define('AT_INCLUDE_PATH', '../../include/');
\r
16 require (AT_INCLUDE_PATH.'vitals.inc.php');
\r
17 authenticate(AT_PRIV_CERTIFICATE);
\r
20 // Initialize default vars
\r
21 require_once("common.inc.php");
\r
22 initialize_default_vars();
\r
24 $is_passscore_in_basetable = is_pass_score_defined_in_base_table();
\r
26 if (isset($_POST["certificate_id"])) $certificate_id = $_POST["certificate_id"];
\r
27 else $certificate_id = $_REQUEST["certificate_id"];
\r
29 if (isset($_POST['submit']))
\r
31 $missing_fields = array();
\r
33 /* insert or update a category */
\r
34 if ($_POST["test_id"] == -1)
\r
35 $missing_fields[] = _AT("choose_test");
\r
37 if ($is_passscore_in_basetable)
\r
39 if ($_POST["test_id"]>0)
\r
41 $sql = "SELECT passscore, passpercent from ".TABLE_PREFIX."tests where test_id=".$_POST["test_id"];
\r
42 $result = mysql_query($sql, $db) or die(mysql_error());
\r
43 $row=mysql_fetch_assoc($result);
\r
45 if ($row["passpercent"]==0 && $row["passscore"]==0)
\r
47 $missing_fields[] = _AT("pass_score"). "<br>". _AT("define_pass_score", $_base_href."tools/tests/edit_test.php?tid=".$_POST["test_id"]);
\r
51 else if ((!isset($_POST["pass_score"]) || ($_POST["passpercent"] == 0 && $_POST["passscore"] == 0)))
\r
53 $missing_fields[] = _AT("pass_score");
\r
56 if ($missing_fields) {
\r
57 $missing_fields = implode(', ', $missing_fields);
\r
58 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
\r
61 if (!$msg->containsErrors())
\r
63 if (isset($_POST["passscore"]))
\r
64 $passscore = $_POST["passscore"];
\r
68 if (isset($_POST["passpercent"]))
\r
69 $passpercent = $_POST["passpercent"];
\r
73 $sql = "UPDATE ".TABLE_PREFIX."certificate
\r
74 SET test_id=". $_POST["test_id"] .",
\r
75 passscore=". $passscore .",
\r
76 passpercent=". $passpercent .",
\r
77 organization='". $_POST["organization"]."',
\r
78 enable_download=". $_POST["enable_download"] ."
\r
79 WHERE certificate_id = ". $certificate_id;
\r
81 $result = mysql_query($sql, $db) or die(mysql_error());
\r
82 write_to_log(AT_ADMIN_LOG_UPDATE, 'certificate', mysql_affected_rows($db), $sql);
\r
84 for ($i = 0; $i < count($_POST["text_id_init"]); $i++)
\r
86 $sql = "UPDATE ".TABLE_PREFIX."certificate_text
\r
87 SET field_value='". $_POST["fields_value"][$i] ."'
\r
88 WHERE certificate_text_id = " . $_POST["text_id_init"][$i];
\r
90 $result = mysql_query($sql, $db) or die(mysql_error());
\r
91 write_to_log(AT_ADMIN_LOG_UPDATE, 'certificate_text', mysql_affected_rows($db), $sql);
\r
94 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
96 header('Location: index_instructor.php');
\r
100 else if (isset($_POST['cancel']))
\r
102 $msg->addFeedback('CANCELLED');
\r
103 header('Location: index_instructor.php');
\r
107 require(AT_INCLUDE_PATH.'header.inc.php');
\r
110 // existing auto enrollment
\r
111 if ($certificate_id > 0)
\r
113 $sql = "SELECT * FROM ".TABLE_PREFIX."certificate
\r
114 WHERE certificate_id = " . $certificate_id;
\r
116 $result = mysql_query($sql, $db) or die(mysql_error());
\r
117 $row_certificate = mysql_fetch_assoc($result);
\r
121 <form action ="<?php echo $_SERVER['PHP_SELF']; ?>?certificate_id=<?php echo $certificate_id; ?>" method="post" name="form">
\r
123 <input type="hidden" name="certificate_id" value="<?php echo $certificate_id; ?>">
\r
125 <div class="input-form">
\r
127 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="test_id"><?php echo _AT('choose_test'); ?></label><br>
\r
128 <select name="test_id" id="test_id">
\r
130 // display test title linked with current $certificate_id
\r
131 $sql = "SELECT c.test_id, t.title FROM ".TABLE_PREFIX."certificate c, ".TABLE_PREFIX."tests t WHERE c.certificate_id=".$certificate_id." AND c.test_id = t.test_id";
\r
133 $result = mysql_query($sql, $db) or die(mysql_error());
\r
134 $row=mysql_fetch_assoc($result);
\r
136 <option value='<?php echo $row["test_id"];?>'><?php echo $row["title"]; ?></option>
\r
138 // display other test titles that don't have certificate yet
\r
139 $sql = "SELECT * FROM ".TABLE_PREFIX."tests WHERE course_id=$_SESSION[course_id] AND test_id not in (SELECT distinct test_id FROM ".TABLE_PREFIX."certificate) ORDER BY start_date DESC";
\r
140 $result = mysql_query($sql, $db) or die(mysql_error());
\r
142 while ($row=mysql_fetch_assoc($result))
\r
144 echo ' <option value="'. $row["test_id"] . '>'. $row["title"] .'</option>';
\r
152 if (!$is_passscore_in_basetable)
\r
154 // set radio button / text properties and value for pass score
\r
155 if (isset($_POST['passscore']))
\r
157 if ($_POST['passscore'] <> 0)
\r
159 $value_passscore = $_POST['passscore'];
\r
160 $checked_passscore = 'checked="true"';
\r
163 $disabled_passscore = 'disabled="true"';
\r
167 if ($row_certificate["passscore"]<>0)
\r
169 $value_passscore = $row_certificate["passscore"];
\r
170 $checked_passscore = 'checked="true"';
\r
173 $disabled_passscore = 'disabled="true"';
\r
176 // set radio button / text properties and value for pass percentage
\r
177 if (isset($_POST['passpercent']))
\r
179 if ($_POST['passpercent'] <> 0)
\r
181 $value_passpercent = $_POST['passpercent'];
\r
182 $checked_passpercent = 'checked="true"';
\r
185 $disabled_passpercent = 'disabled="true"';
\r
189 if ($row_certificate["passpercent"]<>0)
\r
191 $value_passpercent = $row_certificate["passpercent"];
\r
192 $checked_passpercent = 'checked="true"';
\r
195 $disabled_passpercent = 'disabled="true"';
\r
199 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><?php echo _AT('pass_score'); ?><br />
\r
200 <input type="radio" name="pass_score" value="1" id="percentage" <?php echo $checked_passpercent; ?>
\r
201 onfocus="disable_texts('points');" />
\r
203 <input type="text" name="passpercent" id="passpercent" size="2" value="<?php echo $value_passpercent;?>" <?php echo $disabled_passpercent;?> />
\r
204 <label for="percentage" title="<?php echo _AT('pass_score'). ': '. _AT('percentage_score'); ?>"><?php echo '% ' . _AT('percentage_score'); ?></label><br />
\r
206 <input type="radio" name="pass_score" value="2" id="points" <?php echo $checked_passscore; ?>
\r
207 onfocus="disable_texts('percentage');" />
\r
209 <input type="text" name="passscore" id="passscore" size="2" value="<?php echo $value_passscore;?>" <?php echo $disabled_passscore;?> />
\r
210 <label for="points" title="<?php echo _AT('pass_score'). ': '. _AT('points_score'); ?>"><?php echo _AT('points_score'); ?></label>
\r
217 <label for="certificate_template"><?php echo _AT('certificate_template'). ":"; ?></label>
\r
218 <?php echo $default_certificate; ?>
\r
222 <label for="organization"><?php echo _AT('organization_name'); ?></label><br>
\r
223 <input type="text" name="organization" id="organization" size="50" value='<?php if (!isset($_POST["organization"])) echo $row_certificate["organization"]; else echo $_POST["organization"]; ?>' />
\r
227 <label for="enable_download"><?php echo _AT('enable_download_certificate'); ?></label><br>
\r
229 <input type="radio" name="enable_download" value="0" id="no"
\r
231 if (!isset($_POST['enable_download']))
\r
233 if ($row_certificate["enable_download"] == 0) echo 'checked="true"';
\r
235 else if ($_POST['enable_download'] == 0) echo 'checked="true"';
\r
237 <label for="no"><?php echo _AT('no'); ?></label><br />
\r
239 <input type="radio" name="enable_download" value="1" id="ok"
\r
241 if (!isset($_POST['enable_download']))
\r
243 if ($row_certificate["enable_download"] == 1) echo 'checked="true"';
\r
245 else if ($_POST['enable_download'] == 1) echo 'checked="true"';
\r
248 <label for="ok"><?php echo _AT('issue_certificate'); ?></label><br />
\r
252 <label for="certificate_text"><?php echo _AT('certificate_text'); ?></label><br>
\r
253 <table summary="" class="data" rules="cols" align="center" style="width: 100%;">
\r
256 <th scope="col"><?php echo _AT('field_name'); ?></th>
\r
257 <th scope="col"><?php echo _AT('field_value'); ?></th>
\r
263 $sql = "SELECT * FROM ".TABLE_PREFIX."certificate_text c WHERE c.certificate_id=".$certificate_id;
\r
264 $result = mysql_query($sql, $db) or die(mysql_error());
\r
265 while ($row_text=mysql_fetch_assoc($result))
\r
267 $text_id_init[]=$row_text["certificate_text_id"];
\r
268 $fields_name_init[]=$row_text["field_name"];
\r
269 $fields_value_init[]=$row_text["field_value"];
\r
272 for($i=0; $i<mysql_num_rows($result); $i++)
\r
276 <input type="hidden" name="text_id_init[]" value="<?php echo $text_id_init[$i]; ?>">
\r
277 <input type="hidden" name="fileds_name[]" value="<?php echo $fields_name_init[$i]; ?>">
\r
278 <td style="width:20%"><?php echo $fields_name_init[$i]; ?></td>
\r
279 <td style="width:80%"><textarea name="fields_value[]" rows="1" cols="120" style="max-width:100%"><?php if (isset($_POST["fields_value"][$i])) echo $_POST["fields_value"][$i]; else echo $fields_value_init[$i]; ?></textarea></td>
\r
286 <small>· <?php echo _AT('certificate_tokens'); ?></small>
\r
289 <div class="row buttons">
\r
290 <input type="submit" name="submit" value=" <?php echo _AT('save'); ?> " accesskey="s" />
\r
291 <input type="submit" name="cancel" value=" <?php echo _AT('cancel'); ?> " />
\r
297 <script language="javascript" type="text/javascript">
\r
298 function disable_texts (name) {
\r
299 if (name == 'both')
\r
301 document.form['passpercent'].disabled=true;
\r
302 document.form['passscore'].disabled=true;
\r
303 document.form['passpercent'].value=0;
\r
304 document.form['passscore'].value=0;
\r
306 else if (name == 'percentage')
\r
308 document.form['passpercent'].disabled=true;
\r
309 document.form['passpercent'].value=0;
\r
310 document.form['passscore'].disabled=false;
\r
312 else if (name == 'points')
\r
314 document.form['passpercent'].disabled=false;
\r
315 document.form['passscore'].disabled=true;
\r
316 document.form['passscore'].value=0;
\r
321 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>
\r