Fixing certificates in order to work well with sessions (partial) see CT#2295

skala
Julio Montoya 15 years ago
parent 6cdbf6e2b1
commit cfd98fbc0a
  1. 19
      main/gradebook/gradebook_display_certificate.php
  2. 155
      main/gradebook/index.php
  3. 6
      main/inc/lib/usermanager.lib.php

@ -10,8 +10,7 @@ require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
//extra javascript functions for in html head:
$htmlHeadXtra[] =
"<script language='javascript' type='text/javascript'>
function confirmation()
{
function confirmation() {
if (confirm(\" ".trim(get_lang('AreYouSureToDelete'))." ?\"))
{return true;}
else
@ -26,12 +25,9 @@ if (!api_is_allowed_to_edit()) {
$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'));
$this_section = SECTION_COURSES;
Display::display_header('');
?>
<?php
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']);
@ -42,8 +38,8 @@ if (isset($_GET['user_id']) && $_GET['user_id']==strval(intval($_GET['user_id'])
}
}
}
echo Display::tag('h3', get_lang('GradebookListOfStudentsCertificates'));
?>
<h3 class="actions" ><?php echo get_lang('GradebookListOfStudentsCertificates'); ?></h3>
<table class="data_table" border="0" width="100%" >
<?php
@ -56,20 +52,20 @@ if (isset($_GET['user_id']) && $_GET['user_id']==strval(intval($_GET['user_id'])
foreach ($certificate_list as $index=>$value) {
?>
<tr>
<td width="100%" class="actions"><?php echo get_lang('Student').' : '. $value['firstname'].' '.$value['lastname'] ?>
<td width="100%" class="actions"><?php echo get_lang('Student').' : '.api_get_person_name($value['firstname'], $value['lastname']) ?>
</td>
</tr>
<tr>
<td>
<table class="data_table" width="100%" >
<?php
$list_certificate = get_list_gradebook_certificates_by_user_id ($value['user_id'],$cat_id);
$list_certificate = get_list_gradebook_certificates_by_user_id ($value['user_id'],$cat_id);
foreach ($list_certificate as $index_certificate=>$value_certificate) {
?>
<tr >
<td width="50%"><?php echo get_lang('Score').' : '.$value_certificate['score_certificate'] ?></td>
<td width="30%"><?php echo get_lang('Date').' : '.api_convert_and_format_date($value_certificate['created_at']) ?></td>
<td width="20%"><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.gif',get_lang('Delete')); ?></a></td>
<td width="20%"><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></td>
</tr>
<?php
}
@ -83,5 +79,4 @@ if (isset($_GET['user_id']) && $_GET['user_id']==strval(intval($_GET['user_id'])
?>
</table>
<?php
Display::display_footer();
?>
Display::display_footer();

@ -558,10 +558,8 @@ if (!empty($keyword))
else
*/
if (isset ($_GET['studentoverview'])) {
//@todo this code also seems to be deprecated ...
if (isset ($_GET['studentoverview'])) {
//@todo this code also seems to be deprecated ...
$cats= Category :: load($category);
$stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
$allcat= array ();
@ -588,13 +586,14 @@ if (isset ($_GET['studentoverview'])) {
$pdf->ezStream();
exit;
}
} elseif (!empty($_GET['export_certificate'])) {
$user_id = strval(intval($_GET['user']));
if (!api_is_allowed_to_edit(true,true)) {
$user_id = api_get_user_id();
}
} elseif (!empty($_GET['export_certificate'])) {
$user_id = strval(intval($_GET['user']));
if (!api_is_allowed_to_edit(true,true)) {
$user_id = api_get_user_id();
}
$category = Category :: load($category); //hack replace $category = Category :: load ($_GET['cat_id']); to get de course name in certificates
$category = Category :: load($category); //hack replace $category = Category :: load ($_GET['cat_id']); to get de course name in certificates
if ($category[0]->is_certificate_available($user_id)) {
$user= get_user_info_from_id($user_id);
@ -616,77 +615,74 @@ if (isset ($_GET['studentoverview'])) {
$certif_text = str_replace("\\n","\n",$certif_text);
$date = date('d/m/Y',time());
$path_info= UserManager::get_user_picture_path_by_id($user_id,'system',true);
$path_info= UserManager::get_user_picture_path_by_id($user_id,'system',true);
$path_directory_user_certificate=$path_info['dir'].'certificate/';
$path_directory_user_certificate=$path_info['dir'].'certificate/';
if (!is_dir($path_info['dir'])) {
mkdir($path_info['dir'],0777);
}
if (!is_dir($path_directory_user_certificate)) {
mkdir($path_directory_user_certificate,0777);
}
if (is_dir($path_directory_user_certificate)) {
$user_id = api_get_user_id();
$cat_id = intval($_GET['cat_id']);
$name=md5($user_id.$cat_id);
if (!is_dir($path_info['dir'])) {
mkdir($path_info['dir'],0777);
}
if (!is_dir($path_directory_user_certificate)) {
mkdir($path_directory_user_certificate,0777);
}
if (is_dir($path_directory_user_certificate)) {
$user_id = api_get_user_id();
$cat_id = intval($_GET['cat_id']);
$name=md5($user_id.$cat_id);
//generate document HTML
$course_id = api_get_course_id();
$content_html = DocumentManager::replace_user_info_into_html($course_id);
//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]!='') {
$new_content=explode('</head>',$content_html);
$new_content_html=$new_content[1];
$my_path_certificate=$path_directory_user_certificate.$name.'.html';
if ($new_content[0]!='') {
$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);
$new_content_html=$new_content[1];
$my_path_certificate=$path_directory_user_certificate.$name.'.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);
$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);
//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>';
$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);
//add header
$new_content_html=$new_content[0].$print.'</head>'.$new_content_html;
$new_content_html = str_replace('/main/img/', api_get_path(WEB_IMG_PATH), $new_content_html);
if ($cat_id=strval(intval($cat_id))) {
if (UserManager::is_user_certified($cat_id,$user_id)===true){
header('Content-Type: text/html; charset='. $charset);
echo $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 ($cat_id=strval(intval($cat_id))) {
if (UserManager::is_user_certified($cat_id,$user_id)===true){
header('Content-Type: text/html; charset='. $charset);
echo $new_content_html;
exit;
} else {
$my_new_content_html=$new_content_html;
$my_new_content_html=mb_convert_encoding($my_new_content_html,'UTF-8',$charset);
file_put_contents($my_path_certificate,$my_new_content_html);
header('Content-Type: text/html; charset='. $charset);
echo $new_content_html;
}
$path_certificate='/'.$name.'.html';
update_user_info_about_certificate($cat_id,$user_id,$path_certificate);
exit;
} else {
$my_new_content_html=$new_content_html;
$my_new_content_html=mb_convert_encoding($my_new_content_html,'UTF-8',$charset);
file_put_contents($my_path_certificate,$my_new_content_html);
header('Content-Type: text/html; charset='. $charset);
echo $new_content_html;
}
} else {
Display :: display_reduced_header();
Display :: display_warning_message(get_lang('NoCertificateAvailable'));
$path_certificate='/'.$name.'.html';
update_user_info_about_certificate($cat_id,$user_id,$path_certificate);
exit;
}
} else {
Display :: display_reduced_header();
Display :: display_warning_message(get_lang('NoCertificateAvailable'));
}
}
/*$pdf= new Cezpdf('a4','landscape');
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
@ -708,7 +704,10 @@ if (isset ($_GET['studentoverview'])) {
$pdf->ezStream();*/
}
exit;
} else { //in any other case (no search, no pdf), print the available gradebooks
} else {
//Student view
//in any other case (no search, no pdf), print the available gradebooks
// Important note: loading a category will actually load the *contents* of
// this category. This means that, to show the categories of a course,
// we have to show the root category and show its subcategories that
@ -727,8 +726,7 @@ if (isset ($_GET['studentoverview'])) {
//hack for delete a gradebook from inside course
$clean_deletecat=Security::remove_XSS($_GET['deletecat']);
if (!empty($clean_deletecat))
{
if (!empty($clean_deletecat)) {
exit;
}
//end hack
@ -766,13 +764,13 @@ if (isset ($_GET['studentoverview'])) {
//with this fix the teacher only can view 1 gradebook
//$stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
if (api_is_platform_admin()) {
$stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
$stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
} else {
$stud_id= api_get_user_id();
}
$allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
$alleval= $cats[0]->get_evaluations($stud_id);
$alllink= $cats[0]->get_links($stud_id);
$allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
$alleval = $cats[0]->get_evaluations($stud_id);
$alllink = $cats[0]->get_links($stud_id);
//whether we found a category or not, we now have a category object with
// empty or full subcats
}
@ -848,21 +846,22 @@ if ($category != '0') {
$item_total+=$item->get_weight();
}
$item_value = number_format($item_value, 2, '.', ' ');
/*
$cattotal = Category :: load($category_id);
$scoretotal= $cattotal[0]->calc_score(api_get_user_id());
/*
//Overwritten the old total with the real total of the gradebook if the line below is deleted, then when a user doesn't finish a test the total will be different from the real total
$scoretotal[1] = $item_total;
$scoretotal[1] = $item_total;
//$scoretotal_display = (isset($scoretotal)? round($scoretotal[0],2).'/'.round($scoretotal[1],2).' ('.round(($scoretotal[0] / $scoretotal[1]) * 100,2) . ' %)': '-');
*/
//$scoretotal_display = (isset($scoretotal)? round($scoretotal[0],2).'/'.round($scoretotal[1],2).' ('.round(($scoretotal[0] / $scoretotal[1]) * 100,2) . ' %)': '-');
//Do not remove this the gradebook/lib/fe/gradebooktable.class.php file load this variable as a global
$my_score_in_gradebook = round($scoretotal[0],2);
*/
//Show certificate
$certificate_min_score=$cats[0]->get_certificate_min_score();
$scoredisplay = ScoreDisplay :: instance();
$scoretotal_display = $scoredisplay->display_score($scoretotal,SCORE_DIV_PERCENT);
$scoretotal_display = $scoredisplay->display_score($scoretotal,SCORE_DIV_PERCENT);
if (isset($certificate_min_score) && (int)$item_value >= (int)$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();
//$certificates.= '<img src="'.api_get_path(WEB_CODE_PATH) . 'img/logo.gif" />'.get_lang('Certificates').'</a>&nbsp;<strong>'.get_lang('Total').': '.$scoretotal_display.'</strong>';

@ -3225,9 +3225,11 @@ class UserManager
public function get_info_gradebook_certificate($course_code,$user_id) {
$tbl_grade_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$tbl_grade_category = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql='SELECT * FROM '.$tbl_grade_certificate.' WHERE cat_id= (SELECT id FROM '.$tbl_grade_category.' WHERE course_code = "'.Database::escape_string($course_code).'" ) AND user_id="'.Database::escape_string($user_id).'" ';
$session_id = api_get_session_id();
$sql='SELECT * FROM '.$tbl_grade_certificate.' WHERE cat_id= (SELECT id FROM '.$tbl_grade_category.' WHERE course_code = "'.Database::escape_string($course_code).'" AND session_id = '.$session_id.' LIMIT 1 ) AND user_id='.Database::escape_string($user_id);
$rs = Database::query($sql);
$row= Database::fetch_array($rs);
$row= Database::fetch_array($rs,'ASSOC');
if (Database::num_rows($rs) > 0)
return $row;
else

Loading…
Cancel
Save