diff --git a/main/document/create_document.php b/main/document/create_document.php
index 875f119106..88fe1985bf 100755
--- a/main/document/create_document.php
+++ b/main/document/create_document.php
@@ -664,7 +664,7 @@ if ($form->validate()) {
//api_display_tool_title($nameTools);
// actions
if (isset($_REQUEST['certificate'])) {
- $all_information_by_create_certificate=DocumentManager::get_all_info_to_certificate();
+ $all_information_by_create_certificate=DocumentManager::get_all_info_to_certificate(api_get_user_id());
$str_info='';
foreach ($all_information_by_create_certificate[0] as $info_value) {
$str_info.=$info_value.'
';
diff --git a/main/document/document.php b/main/document/document.php
index eeea4a639b..4ab683554b 100755
--- a/main/document/document.php
+++ b/main/document/document.php
@@ -99,7 +99,7 @@ $current_folder_id = $document_id;
if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isset($_GET['set_preview']) && $_GET['set_preview'] == strval(intval($_GET['set_preview']))) {
if (isset($_GET['set_preview'])) {
// Generate document HTML
- $content_html = DocumentManager::replace_user_info_into_html(api_get_course_id(), true);
+ $content_html = DocumentManager::replace_user_info_into_html(api_get_user_id(), api_get_course_id(), true);
$new_content_html = $content_html;
diff --git a/main/document/edit_document.php b/main/document/edit_document.php
index 1374c162ee..2326512d31 100755
--- a/main/document/edit_document.php
+++ b/main/document/edit_document.php
@@ -490,7 +490,7 @@ if ($owner_id == api_get_user_id() || api_is_platform_admin() || $is_allowed_to_
$form->addElement('html', '
' . get_lang('Print') . '';
-
- //add header
- $new_content_html=$new_content[0].$print.''.$new_content_html;
+ if (!empty($data)) {
+ $new_content_html = get_user_certificate_content($user_id, false);
if ($cat_id = strval(intval($cat_id))) {
$my_path_certificate = $path_directory_user_certificate.$name;
@@ -700,12 +685,12 @@ if (isset ($_GET['studentoverview'])) {
} else {
$my_new_content_html=$new_content_html;
$my_new_content_html=mb_convert_encoding($my_new_content_html,'UTF-8',$charset);
- //Creating new name
- $user_id = api_get_user_id();
+
+ //Creating new name
$name = md5($user_id.$category_id).'.html';
$my_path_certificate = $path_directory_user_certificate.$name;
- file_put_contents($my_path_certificate, $my_new_content_html);
+ @file_put_contents($my_path_certificate, $my_new_content_html);
header('Content-Type: text/html; charset='. $charset);
echo $new_content_html;
diff --git a/main/gradebook/lib/fe/gradebooktable.class.php b/main/gradebook/lib/fe/gradebooktable.class.php
index a99433b4ad..8d6adc9278 100755
--- a/main/gradebook/lib/fe/gradebooktable.class.php
+++ b/main/gradebook/lib/fe/gradebooktable.class.php
@@ -248,7 +248,7 @@ class GradebookTable extends SortableTable
Display::display_warning_message($warning_message,false);
}
- $content_html=DocumentManager::replace_user_info_into_html($course_code);
+ $content_html=DocumentManager::replace_user_info_into_html(api_get_user_id(), $course_code);
$new_content=explode('',$content_html);
diff --git a/main/gradebook/lib/gradebook_functions.inc.php b/main/gradebook/lib/gradebook_functions.inc.php
index a0ef6f90c2..8f73df96cb 100755
--- a/main/gradebook/lib/gradebook_functions.inc.php
+++ b/main/gradebook/lib/gradebook_functions.inc.php
@@ -454,136 +454,164 @@ function parse_xml_data($file) {
xml_parser_free($parser);
return $users;
}
+
/**
- * update user info about certificate
- * @param int The category id
- * @param int The user id
- * @param string the path name of the certificate
- * @return void()
- */
- function update_user_info_about_certificate ($cat_id,$user_id,$path_certificate) {
- $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
- 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);
- }
- }
-
- /**
- * register user info about certificate
- * @param int The category id
- * @param int The user id
- * @param float The score obtained for certified
- * @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) {
- $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).'" ';
- $rs_exist=Database::query($sql_exist);
- $row=Database::fetch_array($rs_exist);
- 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);
- }
+* update user info about certificate
+* @param int The category id
+* @param int The user id
+* @param string the path name of the certificate
+* @return void()
+*/
+function update_user_info_about_certificate ($cat_id,$user_id,$path_certificate) {
+ $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
+ 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);
+ }
+}
+
+/**
+* register user info about certificate
+* @param int The category id
+* @param int The user id
+* @param float The score obtained for certified
+* @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) {
+ $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).'" ';
+ $rs_exist=Database::query($sql_exist);
+ $row=Database::fetch_array($rs_exist);
+ 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);
+ }
+}
+
+/**
+* Get date of user certificate
+* @param int The category id
+* @param int The user id
+* @return Datetime The date when you obtained the certificate
+*/
+function get_certificate_by_user_id ($cat_id,$user_id) {
+ $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
+ $sql_get_date='SELECT * FROM '.$table_certificate.' WHERE cat_id="'.intval($cat_id).'" AND user_id="'.intval($user_id).'"';
+ $rs_get_date=Database::query($sql_get_date);
+ $row =Database::fetch_array($rs_get_date,'ASSOC');
+ return $row;
+}
- }
- /**
- * Get date of user certificate
- * @param int The category id
- * @param int The user id
- * @return Datetime The date when you obtained the certificate
- */
- function get_certificate_by_user_id ($cat_id,$user_id) {
- $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
- $sql_get_date='SELECT * FROM '.$table_certificate.' WHERE cat_id="'.intval($cat_id).'" AND user_id="'.intval($user_id).'"';
- $rs_get_date=Database::query($sql_get_date);
- $row =Database::fetch_array($rs_get_date,'ASSOC');
- return $row;
- }
-
- /**
- * Get list of users certificates
- * @param int The category id
- * @return array
- */
- function get_list_users_certificates ($cat_id=null) {
+/**
+* Get list of users certificates
+* @param int The category id
+* @return array
+*/
+function get_list_users_certificates ($cat_id=null) {
$table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
- $sql='SELECT DISTINCT u.user_id,u.lastname,u.firstname,u.username FROM '.$table_user.' u INNER JOIN '.$table_certificate.' gc
- ON u.user_id=gc.user_id ';
- if (!is_null($cat_id) && $cat_id>0) {
- $sql.=' WHERE cat_id='.Database::escape_string($cat_id);
- }
- $sql.=' ORDER BY u.firstname';
- $rs=Database::query($sql);
- $list_users=array();
- while ($row=Database::fetch_array($rs)) {
- $list_users[]=$row;
- }
- return $list_users;
- }
-
- /**
- *Gets the certificate list by user id
- *@param int The user id
- *@param int The category id
- *@retun array
- */
- 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
- 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);
- }
-
- $rs = Database::query($sql);
- $list_certificate=array();
- while ($row=Database::fetch_array($rs)) {
- $list_certificate[]=$row;
- }
- 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) {
+ $sql='SELECT DISTINCT u.user_id,u.lastname,u.firstname,u.username FROM '.$table_user.' u INNER JOIN '.$table_certificate.' gc
+ ON u.user_id=gc.user_id ';
+ if (!is_null($cat_id) && $cat_id>0) {
+ $sql.=' WHERE cat_id='.Database::escape_string($cat_id);
+ }
+ $sql.=' ORDER BY u.firstname';
+ $rs=Database::query($sql);
+ $list_users=array();
+ while ($row=Database::fetch_array($rs)) {
+ $list_users[]=$row;
+ }
+ return $list_users;
+}
+
+/**
+*Gets the certificate list by user id
+*@param int The user id
+*@param int The category id
+*@retun array
+*/
+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
+ 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);
+ }
+
+ $rs = Database::query($sql);
+ $list_certificate=array();
+ while ($row=Database::fetch_array($rs)) {
+ $list_certificate[]=$row;
+ }
+ 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;
- }
+ $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;
- }
- }
\ No newline at end of file
+ }
+ 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, $is_preview = false) {
+ //generate document HTML
+ $course_id = api_get_course_id();
+ $content_html = DocumentManager::replace_user_info_into_html($user_id, $course_id, $is_preview);
+
+ $new_content = explode('', $content_html);
+ $new_content_html = $new_content[1];
+ $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);
+
+ $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);
+
+ //add print header
+ $print = '';
+ $print .= '
' . get_lang('Print') . '';
+
+ //add header
+ $new_content_html = $new_content[0].$print.''.$new_content_html;
+ return $new_content_html;
+}
+
+
+
+
diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php
index 01ef3a8ad6..0eb2a7e0cb 100755
--- a/main/inc/lib/document.lib.php
+++ b/main/inc/lib/document.lib.php
@@ -1195,7 +1195,8 @@ return 'application/octet-stream';
* @param string The course id
* @return string The html content of the certificate
*/
- function replace_user_info_into_html($course_id, $is_preview = false) {
+ function replace_user_info_into_html($user_id, $course_id, $is_preview = false) {
+ $user_id = intval($user_id);
$course_info = api_get_course_info($course_id);
$tbl_document=Database::get_course_table(TABLE_DOCUMENT, $course_info['dbName']);
$document_id=self::get_default_certificate_id($course_id);
@@ -1211,7 +1212,7 @@ return 'application/octet-stream';
if (is_file($filepath)) {
$my_content_html=file_get_contents($filepath);
}
- $all_user_info=self::get_all_info_to_certificate($is_preview);
+ $all_user_info=self::get_all_info_to_certificate($user_id, $is_preview);
$info_to_be_replaced_in_content_html=$all_user_info[0];
$info_to_replace_in_content_html=$all_user_info[1];
$new_content=str_replace($info_to_be_replaced_in_content_html,$info_to_replace_in_content_html, $my_content_html);
@@ -1222,9 +1223,9 @@ return 'application/octet-stream';
/**
* return all content to replace and all content to be replace
*/
- function get_all_info_to_certificate($is_preview = false) {
+ function get_all_info_to_certificate($user_id, $is_preview = false) {
$info_list = array();
- $user_id = api_get_user_id();
+ $user_id = intval($user_id);
$course_id = api_get_course_id();
//info portal