@@ -119,12 +122,13 @@ echo Display::tag('h3', get_lang('GradebookListOfStudentsCertificates'));
|
'_blank'));
echo $certificates;
?>
-
+
+
|
$_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)) {
diff --git a/main/gradebook/lib/fe/displaygradebook.php b/main/gradebook/lib/fe/displaygradebook.php
index 8d2afccd7a..5d635ef0be 100755
--- a/main/gradebook/lib/fe/displaygradebook.php
+++ b/main/gradebook/lib/fe/displaygradebook.php
@@ -337,18 +337,17 @@ class DisplayGradebook
$my_course_id=api_get_course_id();
$my_file= substr($_SESSION['gradebook_dest'],0,5);
- $header .= ''.Display::return_icon('stats.png', get_lang('FlatView'),'','32').'';
-
- $header .= ' | '.
- Display::return_icon('certificate.png', get_lang('AttachCertificate'),'','32').
- '';
-
+ $header .= ' | '.Display::return_icon('stats.png', get_lang('FlatView'),'','32').'';
$header .= ' | '.Display::return_icon('certificate_list.png', get_lang('GradebookSeeListOfStudentsCertificates'),'','32').'';
$visibility_icon = ($catobj->is_visible() == 0) ? 'invisible' : 'visible';
$visibility_command = ($catobj->is_visible() == 0) ? 'set_visible' : 'set_invisible';
-
+
+ //Right icons
$modify_icons = ''.Display::return_icon('edit.png', get_lang('Edit'),'','32').'';
+ $modify_icons .= ''.
+ Display::return_icon('certificate.png', get_lang('AttachCertificate'),'','32').'';
+
$modify_icons .= ''.Display::return_icon('percentage.png', get_lang('EditAllWeights'),'','32').'';
$modify_icons .= ''.Display::return_icon('ranking.png', get_lang('ScoreEdit'),'','32').'';
diff --git a/main/gradebook/lib/fe/gradebooktable.class.php b/main/gradebook/lib/fe/gradebooktable.class.php
index fe459dbe69..beff22e98f 100755
--- a/main/gradebook/lib/fe/gradebooktable.class.php
+++ b/main/gradebook/lib/fe/gradebooktable.class.php
@@ -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') ? '' : '';
@@ -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 = '
- '.$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;
}
diff --git a/main/gradebook/lib/gradebook_functions.inc.php b/main/gradebook/lib/gradebook_functions.inc.php
index df91dbf389..b06bcbe0f9 100755
--- a/main/gradebook/lib/gradebook_functions.inc.php
+++ b/main/gradebook/lib/gradebook_functions.inc.php
@@ -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);
diff --git a/main/img/icons/32/certificate_list.png b/main/img/icons/32/certificate_list.png
index 6bc75cdf6d..bc2bb81edf 100644
Binary files a/main/img/icons/32/certificate_list.png and b/main/img/icons/32/certificate_list.png differ
diff --git a/main/inc/lib/certificate.lib.php b/main/inc/lib/certificate.lib.php
index ebde4b5594..b3d5b2afea 100644
--- a/main/inc/lib/certificate.lib.php
+++ b/main/inc/lib/certificate.lib.php
@@ -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;
}
}
\ No newline at end of file
| |