Lots of fixes in the Gradebook certification: QR code size, certificate actions menu, certifications generations

skala
Julio Montoya 15 years ago
parent 61e837227d
commit bea42935ff
  1. 27
      main/document/create_document.php
  2. 20
      main/document/edit_document.php
  3. 42
      main/gradebook/gradebook_display_certificate.php
  4. 21
      main/gradebook/index.php
  5. 13
      main/gradebook/lib/fe/displaygradebook.php
  6. 77
      main/gradebook/lib/fe/gradebooktable.class.php
  7. 45
      main/gradebook/lib/gradebook_functions.inc.php
  8. BIN
      main/img/icons/32/certificate_list.png
  9. 98
      main/inc/lib/certificate.lib.php

@ -621,7 +621,8 @@ if ($form->validate()) {
}
}
}
*/
*/
get_list_gradebook_certificates_by_user_id()
// Interbreadcrumb for the current directory root path
if (empty($document_data['parents'])) {
@ -632,27 +633,29 @@ if ($form->validate()) {
}
}
Display :: display_header($nameTools, "Doc");
//api_display_tool_title($nameTools);
// actions
// actions
echo '<div class="actions">';
// link back to the documents overview
if ($is_certificate_mode)
echo '<a href="document.php?certificate=true&id='.$folder_id.'&selectcat=' . Security::remove_XSS($_GET['selectcat']).'">'.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview'),'','32').'</a>';
else
echo '<a href="document.php?curdirpath='.Security::remove_XSS($dir).'">'.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('DocumentsOverview'),'','32').'</a>';
echo '</div>';
if ($is_certificate_mode) {
$all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate(api_get_user_id(), api_get_course_id());
$str_info = '';
foreach ($all_information_by_create_certificate[0] as $info_value) {
$str_info.=$info_value.'<br/>';
}
$create_certificate=get_lang('CreateCertificateWithTags');
$create_certificate = get_lang('CreateCertificateWithTags');
Display::display_normal_message($create_certificate.': <br /><br/>'.$str_info,false);
}
echo '<div class="actions">';
// link back to the documents overview
if ($is_certificate_mode)
echo '<a href="document.php?curdirpath='.Security::remove_XSS($dir).'&selectcat=' . Security::remove_XSS($_GET['selectcat']).'">'.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview'),'','32').'</a>';
else
echo '<a href="document.php?curdirpath='.Security::remove_XSS($dir).'">'.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('DocumentsOverview'),'','32').'</a>';
echo '</div>';
$form->display();
Display :: display_footer();
}

@ -82,7 +82,6 @@ require_once $lib_path.'document.lib.php';
require_once $lib_path.'groupmanager.lib.php';
require_once $lib_path.'formvalidator/FormValidator.class.php';
require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php';
/* Constants & Variables */
if (api_is_in_group()) {
$group_properties = GroupManager::get_group_properties($_SESSION['_gid']);
@ -108,8 +107,12 @@ if (isset($_GET['id'])) {
$file = $_GET['file'];
$doc = basename($file);
}
/*
//I'm in the certification module?
if (isset($_REQUEST['certificate']) && $_REQUEST['certificate'] == 'true') {
$is_certificate_mode = true;
}*/
$is_certificate_mode = DocumentManager::is_certificate_mode($dir);
//Call from
@ -381,8 +384,6 @@ if (file_exists($filepath.$doc)) {
$nameTools = get_lang('EditDocument') . ': '.$oldTitle;
Display::display_header($nameTools, 'Doc');
// Display the tool title
//api_display_tool_title($nameTools);
if (isset($msgError)) {
Display::display_error_message($msgError);
@ -396,6 +397,7 @@ if (isset($info_message)) {
}
}
// Readonly
$sql = 'SELECT id, readonly FROM '.$dbTable.' WHERE path LIKE BINARY "'.$dir.$doc.'"';
$rs = Database::query($sql);
@ -492,7 +494,9 @@ if ($owner_id == api_get_user_id() || api_is_platform_admin() || $is_allowed_to_
/*
$form->addElement('html', '<div id="frmModel" style="display:block; height:525px; width:240px; position:absolute; top:115px; left:1px;"></div>');
*/
if (isset($_REQUEST['curdirpath']) && $dir =='/certificates') {
show_return($parent_id, $dir_original, $call_from_tool, $slide_id, $is_certificate_mode);
if ($is_certificate_mode) {
$all_information_by_create_certificate=DocumentManager::get_all_info_to_certificate(api_get_user_id(), api_get_course_id());
$str_info='';
foreach ($all_information_by_create_certificate[0] as $info_value) {
@ -500,9 +504,9 @@ if ($owner_id == api_get_user_id() || api_is_platform_admin() || $is_allowed_to_
}
$create_certificate=get_lang('CreateCertificateWithTags');
Display::display_normal_message($create_certificate.': <br /><br />'.$str_info,false);
}
show_return($parent_id, $dir_original, $call_from_tool, $slide_id, $is_certificate_mode);
if($extension=='svg' && !api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true'){
}
if ($extension=='svg' && !api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true'){
Display::display_warning_message(get_lang('BrowserDontSupportsSVG'));
}
$form->display();

@ -14,7 +14,9 @@ require_once '../inc/global.inc.php';
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).'usermanager.lib.php';
require_once api_get_path(LIBRARY_PATH).'certificate.lib.php';
//extra javascript functions for in html head:
$htmlHeadXtra[] =
@ -32,31 +34,30 @@ if (!api_is_allowed_to_edit()) {
api_not_allowed(true);
}
$interbreadcrumb[] = array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?', 'name' => get_lang('Gradebook'));
//$interbreadcrumb[] = array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.Security::remove_XSS($_GET['cat_id']),'name' => get_lang('Details'));
//$interbreadcrumb[] = array ('url' => 'gradebook_display_certificate.php?cat_id='.Security::remove_XSS($_GET['cat_id']),'name' => get_lang('GradebookListOfStudentsCertificates'));
$interbreadcrumb[] = array ('url' => '#','name' => get_lang('GradebookListOfStudentsCertificates'));
$this_section = SECTION_COURSES;
Display::display_header('');
if (isset($_GET['user_id']) && $_GET['user_id']==strval(intval($_GET['user_id'])) && isset($_GET['cat_id']) && $_GET['cat_id']==strval(intval($_GET['cat_id']))) {
if($_GET['action'] == 'delete') {
$info=delete_certificate($_GET['cat_id'],$_GET['user_id']);
if ($info===true) {
Display::display_confirmation_message(get_lang('CertificateRemoved'));
} else {
Display::display_error_message(get_lang('CertificateNotRemoved'));
}
}
if ($_GET['action'] == 'delete') {
$certificate = new Certificate($_GET['certificate_id']);
$result = $certificate->delete();
if ($result ==true) {
Display::display_confirmation_message(get_lang('CertificateRemoved'));
} else {
Display::display_error_message(get_lang('CertificateNotRemoved'));
}
}
echo Display::tag('h3', get_lang('GradebookListOfStudentsCertificates'));
?>
<table class="data_table" border="0" width="100%" >
<?php
$cat_id=isset($_GET['cat_id']) ? (int)$_GET['cat_id'] : null;
$cat_id = isset($_GET['cat_id']) ? (int)$_GET['cat_id'] : null;
//@todo replace all this code with something like get_total_weight()
$cats = Category :: load ($cat_id, null, null, null, null, null, false);
if (!empty($cats)) {
@ -79,6 +80,7 @@ echo Display::tag('h3', get_lang('GradebookListOfStudentsCertificates'));
$total_resource_weight = 0;
if (!empty($datagen)) {
$data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
if (!empty($data_array)) {
$newarray = array();
foreach ($data_array as $data) {
@ -89,7 +91,8 @@ echo Display::tag('h3', get_lang('GradebookListOfStudentsCertificates'));
$total_resource_weight = $total_resource_weight + $item['2'];
}
}
}
}
if ($total_resource_weight != $total_weight) {
Display::display_warning_message(get_lang('SumOfActivitiesWeightMustBeEqualToTotalWeight'));
}
@ -103,10 +106,10 @@ echo Display::tag('h3', get_lang('GradebookListOfStudentsCertificates'));
} else {
foreach ($certificate_list as $index=>$value) {
?>
<tr>
<tr>
<td width="100%" class="actions"><?php echo get_lang('Student').' : '.api_get_person_name($value['firstname'], $value['lastname']) ?>
</td>
</tr>
</tr>
<tr>
<td>
<table class="data_table" width="100%" >
@ -119,12 +122,13 @@ echo Display::tag('h3', get_lang('GradebookListOfStudentsCertificates'));
<td width="30%"><?php echo get_lang('Date').' : '.api_convert_and_format_date($value_certificate['created_at']) ?></td>
<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=';
//$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(), 22), $url, array('target'=>'_blank'));
echo $certificates;
?>
<a onclick="return confirmation();" href="gradebook_display_certificate.php?action=delete&<?php echo 'user_id='.$value_certificate['user_id'].'&amp;cat_id='.$value_certificate['cat_id'] ?>"><?php echo Display::return_icon('delete.png',get_lang('Delete')); ?></a>
<a onclick="return confirmation();" href="gradebook_display_certificate.php?action=delete&cat_id=<?php echo $cat_id; ?>&certificate_id=<?php echo $value_certificate['id'] ?>">
<?php echo Display::return_icon('delete.png',get_lang('Delete')); ?></a>
</td>
</tr>
<?php

@ -466,7 +466,7 @@ if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
// DISPLAY HEADERS AND MESSAGES
if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) {
if (!isset($_GET['exportpdf'])) {
if (isset ($_GET['studentoverview'])) {
$interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('ToolGradebook'));
Display :: display_header(get_lang('FlatView'));
@ -671,11 +671,7 @@ if (isset ($_GET['studentoverview'])) {
// add params to the future links (in the table shown)
$addparams = array ('selectcat' => $cats[0]->get_id());
/*
if (isset($_GET['search'])) {
$addparams['search'] = $keyword;
}
*/
if (isset ($_GET['studentoverview'])) {
$addparams['studentoverview'] = '';
}
@ -735,11 +731,15 @@ if ($category != '0') {
$certificate_min_score = $cats[0]->get_certificate_min_score();
$scoredisplay = ScoreDisplay :: instance();
$scoretotal_display = $scoredisplay->display_score($scoretotal,SCORE_DIV_PERCENT); //a student always sees only the teacher's repartition
//$score_compare = ($scoretotal[0] / $scoretotal[1]) * 100; //build the total percentage obtained in order to compare it to the minimum certification percentage
if (isset($certificate_min_score) && $item_value >= $certificate_min_score) {
$url = api_get_path(WEB_CODE_PATH) .'gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']).'?export_certificate=yes&cat_id='.$cats[0]->get_id();
$my_certificate = get_certificate_by_user_id($cats[0]->get_id(), api_get_user_id());
if (empty($my_certificate)) {
register_user_info_about_certificate($category_id, api_get_user_id(), $my_score_in_gradebook, api_get_utc_datetime());
$my_certificate = get_certificate_by_user_id($cats[0]->get_id(), api_get_user_id());
}
if (!empty($my_certificate)) {
$url = api_get_path(WEB_PATH) .'certificates/?id='.$my_certificate['id'];
$certificates = Display::url(Display::return_icon('certificate.png', get_lang('Certificates'), array(), 48), $url, array('target'=>'_blank'));
@ -753,9 +753,6 @@ if ($category != '0') {
DisplayGradebook::display_header_gradebook($cats[0], 0, $category_id, $is_course_admin, $is_platform_admin, $simple_search_form, false, true);
}
} else {
//this is the root category
//DisplayGradebook :: display_header_gradebook($cats[0], 0, 0, $is_course_admin, $is_platform_admin, $simple_search_form, false, false);
}
if (api_is_allowed_to_edit(null, true)) {

@ -337,18 +337,17 @@ class DisplayGradebook
$my_course_id=api_get_course_id();
$my_file= substr($_SESSION['gradebook_dest'],0,5);
$header .= '<td style="vertical-align: top;"><a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() . '">'.Display::return_icon('stats.png', get_lang('FlatView'),'','32').'</a>';
$header .= '<td style="vertical-align: top;"><a href="../document/document.php?curdirpath=/certificates&'.$my_api_cidreq.'&origin=gradebook&selectcat=' . $catobj->get_id() . '">'.
Display::return_icon('certificate.png', get_lang('AttachCertificate'),'','32').
'</a>';
$header .= '<td style="vertical-align: top;"><a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() . '">'.Display::return_icon('stats.png', get_lang('FlatView'),'','32').'</a>';
$header .= '<td style="vertical-align: top;"><a href="gradebook_display_certificate.php?'.$my_api_cidreq.'&amp;cat_id='.(int)$_GET['selectcat'].'">'.Display::return_icon('certificate_list.png', get_lang('GradebookSeeListOfStudentsCertificates'),'','32').'</a>';
$visibility_icon = ($catobj->is_visible() == 0) ? 'invisible' : 'visible';
$visibility_command = ($catobj->is_visible() == 0) ? 'set_visible' : 'set_invisible';
//Right icons
$modify_icons = '<a href="gradebook_edit_cat.php?editcat=' . $catobj->get_id() . ' &amp;cidReq='.$catobj->get_course_code().'">'.Display::return_icon('edit.png', get_lang('Edit'),'','32').'</a>';
$modify_icons .= '<a href="../document/document.php?curdirpath=/certificates&'.$my_api_cidreq.'&origin=gradebook&selectcat=' . $catobj->get_id() . '">'.
Display::return_icon('certificate.png', get_lang('AttachCertificate'),'','32').'</a>';
$modify_icons .= '<a href="gradebook_edit_all.php?id_session='.intval($_SESSION['id_session']).'&amp;'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() . '">'.Display::return_icon('percentage.png', get_lang('EditAllWeights'),'','32').'</a>';
$modify_icons .= '<a href="gradebook_scoring_system.php?'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() .'">'.Display::return_icon('ranking.png', get_lang('ScoreEdit'),'','32').'</a>';

@ -133,14 +133,7 @@ class GradebookTable extends SortableTable {
// list of items inside the gradebook (exercises, lps, fora, etc)
$row = array ();
$item = $data[0];
$id = $item->get_id();
//the following condition seems strange to me - YW 20110421
//GET['selectcat'] is the main gradebook. When defined, it means we are looking at the whole stuff instead of one sub-element (or something like that?)
//if (empty($_GET['selectcat']) ) { //if not particular gradebook item was selected, take the certificate score for the current item
//$certificate_min_score = $this->build_certificate_min_score($item);
//}
//$_GET['selectcat'] is never empty jm 20110426
$id = $item->get_id();
//if the item is invisible, wrap it in a span with class invisible
$invisibility_span_open = (api_is_allowed_to_create_course() && $item->is_visible() == '0') ? '<span class="invisible">' : '';
@ -157,40 +150,16 @@ class GradebookTable extends SortableTable {
$row[] = $invisibility_span_open . $data[3] . $invisibility_span_close;
$weight_total_links += intval($data[3]);
} else {
// is never empty
/*if (empty($_GET['selectcat'])) {
// generating the total score for a course
$stud_id= api_get_user_id();
$cats_course = Category::load($id, null, null, null, null, null, false);
$alleval_course= $cats_course[0]->get_evaluations($stud_id,true);
$alllink_course= $cats_course[0]->get_links($stud_id,true);
$evals_links = array_merge($alleval_course, $alllink_course);
$item_value=0;
$item_total=0;
for ($count=0; $count < count($evals_links); $count++) {
$item = $evals_links[$count];
$score = $item->calc_score($stud_id);
$score_denom=($score[1]==0) ? 1 : $score[1];
$item_value+=$score[0]/$score_denom*$item->get_weight();
$item_total+=$item->get_weight();
}
$item_value = number_format($item_value, 2, '.', ' ');
$cattotal = Category :: load($id);
$scoretotal= $cattotal[0]->calc_score(api_get_user_id());
$scoretotal_display = (isset($scoretotal)? round($scoretotal[0],2).'/'.round($scoretotal[1],2).' ('.round(($scoretotal[0] / $scoretotal[1]) * 100,2) . ' %)': '-');
$row[] = $item_value;
} else {*/
$cattotal = Category :: load($_GET['selectcat']);
$scoretotal = $cattotal[0]->calc_score(api_get_user_id());
$item_value = $scoretotal[0];
$item_value = number_format($item_value, 2, '.', ' ');
$row[] = $invisibility_span_open . $data[3] . $invisibility_span_close;
//}
$cattotal = Category :: load($_GET['selectcat']);
$scoretotal = $cattotal[0]->calc_score(api_get_user_id());
$item_value = $scoretotal[0];
$item_value = number_format($item_value, 2, '.', ' ');
$row[] = $invisibility_span_open . $data[3] . $invisibility_span_close;
}
$row[] = $invisibility_span_open.$data[4].$invisibility_span_close;
//admins get an edit column
//Admins get an edit column
if (api_is_allowed_to_edit(null, true)) {
$cat = new Category();
$show_message = $cat->show_message_resource_delete($item->get_course_code());
@ -204,35 +173,7 @@ class GradebookTable extends SortableTable {
if (!is_null($value_data)) {
$row[] = $value_data;
}
}
/*if (empty($_GET['selectcat'])) {
if (isset($certificate_min_score) && $item_value >= $certificate_min_score) {
$certificates = '<a href="'.api_get_path(WEB_CODE_PATH) .'gradebook/'.$_SESSION['gradebook_dest'].'?export_certificate=yes&cat_id='.$id.'" target="_blank">
<img src="'.api_get_path(WEB_CODE_PATH) . 'img/logo.gif" /></a>&nbsp;'.$scoretotal_display;
//register gradebook certificate
$current_user_id=api_get_user_id();
register_user_info_about_certificate($id,$current_user_id, $my_score_in_gradebook, api_get_utc_datetime());
} else {
$certificates = '-';
}
//show certificate date
$get_date=get_certificate_date_by_user_id($id,$current_user_id);
if ($get_date=='' || is_null($get_date)) {
$row[4]='-';
} else {
$row[4] = api_convert_and_format_date($get_date);
}
$row[] = $certificates;
} else {*/
if (isset($certificate_min_score) && $item_value >= $certificate_min_score) {
//register gradebook certificate
$current_user_id = api_get_user_id();
register_user_info_about_certificate($_GET['selectcat'], $current_user_id, $my_score_in_gradebook, api_get_utc_datetime());
}
//}
}
}
$sortable_data[] = $row;
}

@ -488,7 +488,7 @@ function update_user_info_about_certificate ($cat_id,$user_id,$path_certificate)
* @param Datetime The date when you obtained the certificate
* @return void()
*/
function register_user_info_about_certificate ($cat_id,$user_id,$score_certificate, $date_certificate) {
function register_user_info_about_certificate ($cat_id, $user_id, $score_certificate, $date_certificate) {
$table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$sql_exist='SELECT COUNT(*) as count FROM '.$table_certificate.' gc
WHERE gc.cat_id="'.intval($cat_id).'" AND user_id="'.intval($user_id).'" ';
@ -497,7 +497,7 @@ function register_user_info_about_certificate ($cat_id,$user_id,$score_certifica
if ($row['count']==0) {
$sql='INSERT INTO '.$table_certificate.' (cat_id,user_id,score_certificate,created_at)
VALUES("'.intval($cat_id).'","'.intval($user_id).'","'.Database::escape_string($score_certificate).'","'.Database::escape_string($date_certificate).'")';
$rs=Database::query($sql);
$rs = Database::query($sql);
}
}
@ -545,7 +545,7 @@ function get_list_users_certificates ($cat_id=null) {
*/
function get_list_gradebook_certificates_by_user_id ($user_id,$cat_id=null) {
$table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$sql='SELECT gc.score_certificate,gc.created_at,gc.path_certificate,gc.cat_id,gc.user_id FROM '.$table_certificate.' gc
$sql='SELECT gc.score_certificate, gc.created_at, gc.path_certificate, gc.cat_id, gc.user_id, gc.id FROM '.$table_certificate.' gc
WHERE gc.user_id="'.Database::escape_string($user_id).'" ';
if (!is_null($cat_id) && $cat_id>0) {
$sql.=' AND cat_id='.Database::escape_string($cat_id);
@ -559,45 +559,6 @@ function get_list_gradebook_certificates_by_user_id ($user_id,$cat_id=null) {
return $list_certificate;
}
/**
* Deletes a certificate
* @param int The category id
* @param int The user id
* @return boolean
*/
function delete_certificate($cat_id, $user_id) {
$table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$sql_verified='SELECT count(*) AS count,path_certificate as path,user_id FROM '.$table_certificate.' gc WHERE cat_id="'.Database::escape_string($cat_id).'" AND user_id="'.Database::escape_string($user_id).'" GROUP BY user_id,cat_id';
$rs_verified=Database::query($sql_verified);
$path=Database::result($rs_verified,0,'path');
$user_id=Database::result($rs_verified,0,'user_id');
if (!is_null($path) || $path!='' || strlen($path)) {
$path_info= UserManager::get_user_picture_path_by_id($user_id,'system',true);
$path_directory_user_certificate=$path_info['dir'].'certificate'.$path;
if (is_file($path_directory_user_certificate)) {
@unlink($path_directory_user_certificate);
if (is_file($path_directory_user_certificate)===false) {
$delete_db=true;
} else {
$delete_db=false;
}
}
if (Database::result($rs_verified,0,'count')==1 && $delete_db===true) {
$sql_delete='DELETE FROM '.$table_certificate.' WHERE cat_id="'.Database::escape_string($cat_id).'" AND user_id="'.Database::escape_string($user_id).'" ';
$rs_delete=Database::query($sql_delete);
return true;
} else {
return false;
}
} else {
//path is not generate delete only the DB record
$sql_delete='DELETE FROM '.$table_certificate.' WHERE cat_id="'.Database::escape_string($cat_id).'" AND user_id="'.Database::escape_string($user_id).'" ';
$rs_delete=Database::query($sql_delete);
return true;
}
}
function get_user_certificate_content($user_id, $course_code, $is_preview = false) {
//generate document HTML
$content_html = DocumentManager::replace_user_info_into_html($user_id, $course_code, $is_preview);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

@ -15,6 +15,8 @@ class Certificate extends Model {
* */
var $certification_user_path = null;
var $certification_web_user_path = null;
var $html_file = null;
var $qr_file = null;
var $user_id;
var $force_certificate_generation = false; //If true every time we enter to the certificate URL we would generate a new certificate
@ -25,7 +27,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();
@ -47,25 +49,15 @@ class Certificate extends Model {
}
}
}
//Setting the qr and html variables
if (isset($certificate_id) && !empty($this->certification_user_path)) {
$pathinfo = pathinfo($this->certificate_data['path_certificate']);
$this->html_file = $this->certification_user_path.basename($this->certificate_data['path_certificate']);
$this->qr_file = $this->certification_user_path.$pathinfo['filename'].'_qr.png';
}
}
/**
* Shows the student's certificate (HTML file)
*/
public function show() {
//Read file or preview file
if (!empty($this->certificate_data['path_certificate'])) {
$user_certificate = $this->certification_user_path.basename($this->certificate_data['path_certificate']);
if (file_exists($user_certificate)) {
header('Content-Type: text/html; charset='. api_get_system_encoding());
echo @file_get_contents($user_certificate);
}
} else {
Display :: display_reduced_header();
Display :: display_warning_message(get_lang('NoCertificateAvailable'));
}
exit;
}
/**
* Checks if the certificate user path directory is created
@ -81,8 +73,7 @@ class Certificate extends Model {
if (!empty($path_info) && isset($path_info['dir'])) {
$this->certification_user_path = $path_info['dir'].'certificate/';
$this->certification_web_user_path = $web_path_info['dir'].'certificate/';
$this->certification_web_user_path = $web_path_info['dir'].'certificate/';
if (!is_dir($path_info['dir'])) {
mkdir($path_info['dir'],0777);
@ -91,8 +82,35 @@ class Certificate extends Model {
if (!is_dir($this->certification_user_path)) {
mkdir($this->certification_user_path, 0777);
}
}
}
}
public function delete() {
if (!empty($this->certificate_data)) {
if (!is_null($this->html_file) || $this->html_file!='' || strlen($this->html_file)) {
//Deleting HTML file
if (is_file($this->html_file)) {
@unlink($this->html_file);
if (is_file($this->html_file) === false) {
$delete_db = true;
} else {
$delete_db = false;
}
}
//Deleting QR code PNG image file
if (is_file($this->qr_file)) {
@unlink($this->qr_file);
}
if ($delete_db) {
return parent::delete($this->certificate_data['id']);
}
} else {
return parent::delete($this->certificate_data['id']);
}
}
return false;
}
/**
@ -171,8 +189,7 @@ class Certificate extends Model {
$text = $this->parse_certificate_variables($new_content_html['variables']);
$this->generate_qr($text, $qr_code_filename);
}
}
}
}
return $result;
}
@ -199,11 +216,16 @@ class Certificate extends Model {
return false;
}
/**
* @param string Text to be added in the QR code
* @param string file path of the image
* */
public function generate_qr($text, $path) {
//Make sure HTML certificate is generated
if (!empty($text) && !empty($path)) {
require_once api_get_path(LIBRARY_PATH).'phpqrcode/qrlib.php';
$return = QRcode::png($text, $path, 'L', 4, 2);
require_once api_get_path(LIBRARY_PATH).'phpqrcode/qrlib.php';
//L low, M - Medium, L large
$return = QRcode::png($text, $path, 'L', 1, 2);
}
}
@ -219,7 +241,7 @@ class Certificate extends Model {
$final_content[$my_header] = $value;
}
/*
/* Certificate tags
*
0 => string '((user_firstname))' (length=18)
1 => string '((user_lastname))' (length=17)
@ -234,22 +256,36 @@ class Certificate extends Model {
10 => string '((gradebook_grade))' (length=19)
11 => string '((certificate_link))' (length=20)
12 => string '((certificate_link_html))' (length=25)
13 => string '((certificate_barcode))' (length=23)
13 => string '((certificate_barcode))' (length=23)
*/
$break_space = " \n\r ";
$text = $final_content['gradebook_institution'].' - '.$final_content['gradebook_sitename'].' - '.get_lang('Certification').$break_space.
get_lang('Student'). ': '.$final_content['user_firstname'].' '.$final_content['user_lastname'].$break_space.
//get_lang('Portal'). ': '.$final_content['gradebook_sitename'].$break_space.
get_lang('Teacher'). ': '.$final_content['teacher_firstname'].' '.$final_content['teacher_lastname'].$break_space.
get_lang('Date'). ': '.$final_content['date_certificate'].$break_space.
get_lang('Score'). ': '.$final_content['gradebook_grade'].$break_space.
'URL'. ': '.$final_content['certificate_link'];
return $text;
}
/**
* Shows the student's certificate (HTML file)
*/
public function show() {
//Read file or preview file
if (!empty($this->certificate_data['path_certificate'])) {
$user_certificate = $this->certification_user_path.basename($this->certificate_data['path_certificate']);
if (file_exists($user_certificate)) {
header('Content-Type: text/html; charset='. api_get_system_encoding());
echo @file_get_contents($user_certificate);
}
} else {
Display :: display_reduced_header();
Display :: display_warning_message(get_lang('NoCertificateAvailable'));
}
exit;
}
}
Loading…
Cancel
Save