Teachers can always preview user certificates

skala
Julio Montoya 15 years ago
parent 211ab5fbf8
commit a1aef06b02
  1. 2
      main/document/create_document.php
  2. 2
      main/document/document.php
  3. 2
      main/document/edit_document.php
  4. 45
      main/gradebook/index.php
  5. 2
      main/gradebook/lib/fe/gradebooktable.class.php
  6. 280
      main/gradebook/lib/gradebook_functions.inc.php
  7. 9
      main/inc/lib/document.lib.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.'<br/>';

@ -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;

@ -490,7 +490,7 @@ 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') {
$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.'<br/>';

@ -623,22 +623,27 @@ if (isset ($_GET['studentoverview'])) {
$data = get_certificate_by_user_id($category, $user_id);
if (api_is_allowed_to_edit(true, true)) {
//Read file or preview file
if (!empty($data['path_certificate'])) {
$user_certificate = $path_directory_user_certificate.basename($data['path_certificate']);
if (file_exists($user_certificate)) {
header('Content-Type: text/html; charset='. $charset);
echo @file_get_contents($user_certificate);
exit;
}
} else {
$new_content_html = get_user_certificate_content($user_id, true);
if (empty($new_content_html)) {
Display :: display_reduced_header();
Display :: display_warning_message(get_lang('NoCertificateAvailable'));
} else {
echo $new_content_html ;
}
}
Display :: display_reduced_header();
Display :: display_warning_message(get_lang('NoCertificateAvailable'));
exit;
} else {
$user= get_user_info_from_id($user_id);
$user = get_user_info_from_id($user_id);
$scoredisplay = ScoreDisplay :: instance();
$scorecourse = $my_category[0]->calc_score($user_id);
$scorecourse = $my_category[0]->calc_score($user_id);
$scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
@ -669,28 +674,8 @@ if (isset ($_GET['studentoverview'])) {
$cat_id = intval($_GET['cat_id']);
$name = $data['path_certificate'];
//generate document HTML
$course_id = api_get_course_id();
$content_html = DocumentManager::replace_user_info_into_html($course_id);
$new_content=explode('</head>',$content_html);
if ($new_content[0]!='' && !empty($data)) {
$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 = '<style media="print" type="text/css">#imprimir {visibility:hidden;}</style>';
$print .='<a href="javascript:window.print();" style="float:right; padding:4px;" id="imprimir"><img src="'.api_get_path(WEB_CODE_PATH).'img/printmgr.gif" alt="' . get_lang('Print') . '" /> ' . get_lang('Print') . '</a>';
//add header
$new_content_html=$new_content[0].$print.'</head>'.$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();
$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;

@ -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('</head>',$content_html);

@ -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 list of users certificates
* @param int The category id
* @return array
*/
function get_list_users_certificates ($cat_id=null) {
/**
* 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) {
$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_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='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;
}
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;
}
}
}
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('</head>', $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 = '<style media="print" type="text/css">#print_div {visibility:hidden;}</style>';
$print .= '<a href="javascript:window.print();" style="float:right; padding:4px;" id="print_div"><img src="'.api_get_path(WEB_CODE_PATH).'img/printmgr.gif" alt="' . get_lang('Print') . '" /> ' . get_lang('Print') . '</a>';
//add header
$new_content_html = $new_content[0].$print.'</head>'.$new_content_html;
return $new_content_html;
}

@ -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

Loading…
Cancel
Save