Teacher can preview the qr code see #5015

skala
Julio Montoya 13 years ago
parent 0737d389bb
commit a9b188cfb9
  1. 21
      main/document/document.php
  2. 14
      main/gradebook/gradebook_display_certificate.php
  3. 33
      main/inc/lib/certificate.lib.php
  4. 12
      main/inc/lib/document.lib.php

@ -323,7 +323,19 @@ if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isse
if (isset($_GET['set_preview'])) {
// Generate document HTML
$content_html = DocumentManager::replace_user_info_into_html(api_get_user_id(), api_get_course_id(), true);
$filename = 'certificate_preview/'.api_get_unique_id().'.png';
$qr_code_filename = api_get_path(SYS_ARCHIVE_PATH).$filename;
$temp_folder = api_get_path(SYS_ARCHIVE_PATH).'certificate_preview';
if (!is_dir($temp_folder)) mkdir($temp_folder, api_get_permissions_for_new_directories());
$qr_code_web_filename = api_get_path(WEB_ARCHIVE_PATH).$filename;
$certificate = new Certificate();
$text = $certificate->parse_certificate_variables($content_html['variables']);
$result = $certificate->generate_qr($text, $qr_code_filename);
$new_content_html = $content_html['content'];
$path_image = api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/images/gallery';
$new_content_html = str_replace('../images/gallery', $path_image, $new_content_html);
@ -331,9 +343,14 @@ if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isse
$path_image_in_default_course = api_get_path(WEB_CODE_PATH) . 'default_course_document';
$new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html);
$new_content_html = str_replace('/main/img/', api_get_path(WEB_IMG_PATH), $new_content_html);
Display::display_reduced_header();
echo '<style>body {background:none;}</style><style media="print" type="text/css"> #print_div { visibility:hidden; } </style>';
echo '<a href="javascript:window.print();" style="float:right; padding:4px;" id="print_div"><img src="../img/printmgr.gif" alt="' . get_lang('Print') . '" /> ' . get_lang('Print') . '</a>';
echo '<a href="javascript:window.print();" style="float:right; padding:4px;" id="print_div"><img src="../img/printmgr.gif" alt="'.get_lang('Print').'"/>'.get_lang('Print').'</a>';
if (is_file($qr_code_filename) && is_readable($qr_code_filename)) {
$new_content_html = str_replace('((certificate_barcode))', Display::img($qr_code_web_filename), $new_content_html);
}
print_r($new_content_html);
exit;
}

@ -19,12 +19,10 @@ require_once 'lib/gradebook_functions.inc.php';
require_once 'lib/be.inc.php';
require_once 'lib/gradebook_data_generator.class.php';
require_once api_get_path(LIBRARY_PATH).'certificate.lib.php';
//extra javascript functions for in html head:
$htmlHeadXtra[] =
"<script language='javascript' type='text/javascript'>
"<script>
function confirmation() {
if (confirm(\" ".trim(get_lang('AreYouSureToDelete'))." ?\"))
{return true;}
@ -52,10 +50,10 @@ if ($_GET['action'] == 'delete') {
}
}
echo Display::tag('h3', get_lang('GradebookListOfStudentsCertificates'));
echo Display::page_header(get_lang('GradebookListOfStudentsCertificates'));
?>
<table class="data_table" border="0" width="100%" >
<table class="data_table">
<?php
$cat_id = isset($_GET['cat_id']) ? (int)$_GET['cat_id'] : null;
@ -114,7 +112,7 @@ echo Display::tag('h3', get_lang('GradebookListOfStudentsCertificates'));
</tr>
<tr>
<td>
<table class="data_table" width="100%" >
<table class="data_table">
<?php
$list_certificate = get_list_gradebook_certificates_by_user_id ($value['user_id'], $cat_id);
foreach ($list_certificate as $value_certificate) {
@ -125,8 +123,8 @@ echo Display::tag('h3', get_lang('GradebookListOfStudentsCertificates'));
<td width="20%">
<?php
//$url = "index.php?export_certificate=yes&cat_id=".$cat_id."&user=".$value['user_id'];
$url = api_get_path(WEB_PATH).'certificates/?id='.$value_certificate['id'];
$certificates = Display::url(Display::return_icon('certificate.png', get_lang('Certificates'), array(), ICON_SIZE_SMALL), $url, array('target'=>'_blank'));
$url = api_get_path(WEB_PATH).'certificates/index.php?id='.$value_certificate['id'];
$certificates = Display::url(get_lang('Certificate'), $url, array('target'=>'_blank', 'class' => 'btn'));
echo $certificates;
?>
<a onclick="return confirmation();" href="gradebook_display_certificate.php?action=delete&cat_id=<?php echo $cat_id; ?>&certificate_id=<?php echo $value_certificate['id'] ?>">

@ -23,8 +23,9 @@ class Certificate extends Model {
var $user_id;
//If true every time we enter to the certificate URL we would generate a new certificate
// (good thing because we can edit the certificate and all users will have the latest certificate bad because we load everytime)
// (good thing because we can edit the certificate and all users will have the latest certificate bad because we load the certificate everytime)
var $force_certificate_generation = true; //default true
/**
* Constructor
* @param int ID of the certificate. If no ID given, take user_id and try to generate one
@ -35,7 +36,7 @@ class Certificate extends Model {
if (isset($certificate_id)) {
$this->certificate_data = $this->get($certificate_id);
$this->user_id = $this->certificate_data['user_id'];
$this->user_id = $this->certificate_data['user_id'];
} else {
//Try with the current user
$this->user_id = api_get_user_id();
@ -98,7 +99,7 @@ class Certificate extends Model {
* the teacher from the gradebook tool to re-generate the certificate because
* the original version wa flawed.
*/
public function delete() {
public function delete($id = null) {
if (!empty($this->certificate_data)) {
@ -148,10 +149,7 @@ class Certificate extends Model {
$scorecourse = $my_category[0]->calc_score($this->user_id);
$scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
//$cattotal = Category :: load($this->certificate_data['cat_id']);
//$scoretotal= $cattotal[0]->calc_score($this->user_id);
//$scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal,SCORE_PERCENT) : get_lang('NoResultsAvailable'));
//Prepare all necessary variables:
$organization_name = api_get_setting('Institution');
//$portal_name = api_get_setting('siteName');
@ -162,8 +160,6 @@ class Certificate extends Model {
$certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'), $organization_name, $stud_fn.' '.$stud_ln, $my_category[0]->get_name(), $scorecourse_display);
$certif_text = str_replace("\\n","\n", $certif_text);
//$date = date('d/m/Y', time());
//If the gradebook is related to skills we added the skills to the user
$skill = new Skill();
@ -188,11 +184,8 @@ class Certificate extends Model {
//Getting QR filename
$file_info = pathinfo($path_certificate);
$qr_code_filename = $this->certification_user_path.$file_info['filename'].'_qr.png';
$new_content_html['content'] = str_replace('((certificate_barcode))', Display::img($this->certification_web_user_path.$file_info['filename'].'_qr.png', 'QR'), $new_content_html['content']);
$my_new_content_html = $new_content_html['content'];
$my_new_content_html = str_replace('((certificate_barcode))', Display::img($this->certification_web_user_path.$file_info['filename'].'_qr.png', 'QR'), $new_content_html['content']);
$my_new_content_html = mb_convert_encoding($my_new_content_html,'UTF-8', api_get_system_encoding());
$result = @file_put_contents($my_path_certificate, $my_new_content_html);
@ -202,7 +195,7 @@ class Certificate extends Model {
$this->certificate_data['path_certificate'] = $path_certificate;
if ($this->html_file_is_generated()) {
if (!empty($file_info)) {
if (!empty($file_info)) {
$text = $this->parse_certificate_variables($new_content_html['variables']);
$this->generate_qr($text, $qr_code_filename);
}
@ -229,7 +222,7 @@ class Certificate extends Model {
if (!UserManager::is_user_certified($cat_id,$user_id)) {
$sql='UPDATE '.$table_certificate.' SET path_certificate="'.Database::escape_string($path_certificate).'"
WHERE cat_id="'.intval($cat_id).'" AND user_id="'.intval($user_id).'" ';
$rs = Database::query($sql);
Database::query($sql);
}
}
@ -260,8 +253,9 @@ class Certificate extends Model {
if (!empty($text) && !empty($path)) {
require_once api_get_path(LIBRARY_PATH).'phpqrcode/qrlib.php';
//L low, M - Medium, L large error correction
$return = QRcode::png($text, $path, 'M', 2, 2);
return QRcode::png($text, $path, 'M', 2, 2);
}
return false;
}
/**
@ -270,16 +264,15 @@ class Certificate extends Model {
* @param array Contains two array entris: first are the headers, second is an array of contents
* @return string The translated string
*/
private function parse_certificate_variables($array) {
public function parse_certificate_variables($array) {
$text = '';
$headers = $array[0];
$content = $array[1];
$final_content = array();
if (!empty($content)) {
foreach($content as $key => $value) {
$my_header = $headers[$key];
$my_header = str_replace(array('((', '))') , '', $my_header);
foreach($content as $key => $value) {
$my_header = str_replace(array('((', '))') , '', $headers[$key]);
$final_content[$my_header] = $value;
}
}

@ -1327,7 +1327,7 @@ class DocumentManager {
if ($num == 0) {
return null;
}
$row = Database::fetch_array($rs);
$row = Database::fetch_array($rs);
return $row['document_id'];
}
@ -1336,7 +1336,7 @@ class DocumentManager {
* @param string The course code
* @return string The html content of the certificate
*/
function replace_user_info_into_html($user_id, $course_code, $is_preview = false) {
static function replace_user_info_into_html($user_id, $course_code, $is_preview = false) {
$user_id = intval($user_id);
$course_info = api_get_course_info($course_code);
$tbl_document = Database::get_course_table(TABLE_DOCUMENT);
@ -1349,7 +1349,7 @@ class DocumentManager {
$new_content = '';
$all_user_info = array();
if (Database::num_rows($rs)) {
$row=Database::fetch_array($rs);
$row = Database::fetch_array($rs);
$filepath = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document'.$row['path'];
if (is_file($filepath)) {
$my_content_html = file_get_contents($filepath);
@ -1405,7 +1405,9 @@ class DocumentManager {
$date_long_certificate = api_convert_and_format_date(api_get_utc_datetime());
}
$url = api_get_path(WEB_PATH).'certificates/?id='.$info_grade_certificate['id'];
$url = api_get_path(WEB_PATH).'certificates/index.php?id='.$info_grade_certificate['id'];
//replace content
$info_to_replace_in_content_html = array($first_name,
$last_name,
@ -1422,6 +1424,7 @@ class DocumentManager {
'<a href="'.$url.'" target="_blank">'.get_lang('CertificateOnlineLink').'</a>',
'((certificate_barcode))',
);
$info_to_be_replaced_in_content_html = array('((user_firstname))',
'((user_lastname))',
'((gradebook_institution))',
@ -1444,6 +1447,7 @@ class DocumentManager {
$info_to_replace_in_content_html[]=$value_extra;
}
}
$info_list[]=$info_to_be_replaced_in_content_html;
$info_list[]=$info_to_replace_in_content_html;
return $info_list;

Loading…
Cancel
Save