Gradebook: Adding certification preview for teachers, adding some get_lang in order to avoid errors while saving the Activities (exercises, forums, etc ), adding more security to the certification

skala
Julio Montoya 14 years ago
parent 1a038e534f
commit 211ab5fbf8
  1. 1
      main/document/document.php
  2. 55
      main/gradebook/gradebook_display_certificate.php
  3. 241
      main/gradebook/index.php
  4. 5
      main/gradebook/lib/fe/catform.class.php
  5. 11
      main/gradebook/lib/gradebook_functions.inc.php
  6. 6
      main/inc/lib/usermanager.lib.php

@ -397,6 +397,7 @@ $docs_and_folders = DocumentManager::get_all_document_data($_course, $curdirpath
$file_list = $format_list = '';
$count = 1;
if (!empty($docs_and_folders))
foreach ($docs_and_folders as $file) {
if ($file['filetype'] == 'file') {
$path_info = pathinfo($file['path']);

@ -5,6 +5,8 @@ $language_file = 'gradebook';
//$cidReset = true;
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';
//extra javascript functions for in html head:
@ -43,7 +45,45 @@ 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)) {
//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());
} else {
$stud_id= api_get_user_id();
}
$total_weight = $cats[0]->get_weight();
$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);
$datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
$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) {
$newarray[] = array_slice($data, 1);
}
foreach($newarray as $item) {
$total_resource_weight = $total_resource_weight + $item['2'];
}
}
}
if ($total_resource_weight != $total_weight) {
Display::display_warning_message(get_lang('TheActivitiesWeightMustBeEqualTheTotalWeight'));
}
}
$certificate_list = get_list_users_certificates($cat_id);
if (count($certificate_list)==0) {
@ -57,15 +97,22 @@ echo Display::tag('h3', get_lang('GradebookListOfStudentsCertificates'));
</tr>
<tr>
<td>
<table class="data_table" width="100%" >
<table class="data_table" width="100%" >
<?php
$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.png',get_lang('Delete')); ?></a></td>
<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'];
$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>
</td>
</tr>
<?php
}

@ -588,7 +588,6 @@ if (isset ($_GET['studentoverview'])) {
$header_names = array(get_lang('Name'),get_lang('Description'),get_lang('Weight'),get_lang('Date'),get_lang('Results'));
$data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
$newarray = array();
foreach ($data_array as $data) {
$newarray[] = array_slice($data, 1);
}
@ -604,102 +603,122 @@ if (isset ($_GET['studentoverview'])) {
$pdf->ezStream();
exit;
}
} elseif (!empty($_GET['export_certificate'])) {
} 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();
$user_id = api_get_user_id();
} else {
$user_id = strval(intval($_GET['user']));
}
if (empty($user_id)) {
api_not_allowed();
}
$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);
$scoredisplay = ScoreDisplay :: instance();
$scorecourse = $category[0]->calc_score($user_id);
$scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
$cattotal = Category :: load($_GET['cat_id']);
$scoretotal= $cattotal[0]->calc_score($user_id);
$scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal,SCORE_PERCENT) : get_lang('NoResultsAvailable'));
global $charset;
//prepare all necessary variables:
$organization_name = api_get_setting('Institution');
$portal_name = api_get_setting('siteName');
$stud_fn = $user['firstname'];
$stud_ln = $user['lastname'];
$certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'),$organization_name,$stud_fn.' '.$stud_ln,$category[0]->get_name(),$scorecourse_display);
$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_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);
//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_html=$new_content[1];
$my_path_certificate=$path_directory_user_certificate.$name.'.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);
$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 ($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 {
Display :: display_reduced_header();
Display :: display_warning_message(get_lang('NoCertificateAvailable'));
}
$my_category = Category :: load($category); //hack replace $category = Category :: load ($_GET['cat_id']); to get de course name in certificates
global $charset;
if ($my_category[0]->is_certificate_available($user_id)) {
$path_info = UserManager::get_user_picture_path_by_id($user_id,'system',true);
$path_directory_user_certificate = $path_info['dir'].'certificate/';
$data = get_certificate_by_user_id($category, $user_id);
if (api_is_allowed_to_edit(true, true)) {
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;
}
}
Display :: display_reduced_header();
Display :: display_warning_message(get_lang('NoCertificateAvailable'));
exit;
} else {
$user= get_user_info_from_id($user_id);
$scoredisplay = ScoreDisplay :: instance();
$scorecourse = $my_category[0]->calc_score($user_id);
$scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
$cattotal = Category :: load($_GET['cat_id']);
$scoretotal= $cattotal[0]->calc_score($user_id);
$scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal,SCORE_PERCENT) : get_lang('NoResultsAvailable'));
//prepare all necessary variables:
$organization_name = api_get_setting('Institution');
$portal_name = api_get_setting('siteName');
$stud_fn = $user['firstname'];
$stud_ln = $user['lastname'];
$certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'),$organization_name,$stud_fn.' '.$stud_ln,$my_category[0]->get_name(),$scorecourse_display);
$certif_text = str_replace("\\n","\n",$certif_text);
$date = date('d/m/Y',time());
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 = $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 ($cat_id = strval(intval($cat_id))) {
$my_path_certificate = $path_directory_user_certificate.$name;
if (file_exists($my_path_certificate) && !empty($name)&& !is_dir($my_path_certificate) ) {
header('Content-Type: text/html; charset='. $charset);
echo $new_content_html;
} 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);
header('Content-Type: text/html; charset='. $charset);
echo $new_content_html;
$path_certificate='/'.$name;
update_user_info_about_certificate($cat_id, $user_id, $path_certificate);
}
exit;
}
} else {
Display :: display_reduced_header();
Display :: display_warning_message(get_lang('NoCertificateAvailable'));
}
}
}
}
exit;
@ -800,18 +819,16 @@ if (( count($allcat) == 0) && ( count($alleval) == 0 ) && ( count($alllink) == 0
}
//here we are in a sub category
if ($category != '0') {
$cat=new Category();
//$dblib=new Database();
$category_id = intval($_GET['selectcat']);
$course_id=Database::get_course_by_category($category_id);
$cat = new Category();
$category_id = intval($_GET['selectcat']);
$course_id = Database::get_course_by_category($category_id);
$show_message=$cat->show_message_resource_delete($course_id);
if ($show_message=='') {
//hack for inside courses menu cat
if (api_is_allowed_to_edit()) {
$op_cat_weight= '<strong>'.get_lang('Weight').'</strong>'.': '.((intval($cats[0]->get_weight())>0) ? $cats[0]->get_weight() : 0);
$op_cat_weight= '<strong>'.get_lang('TotalWeight').'</strong>'.': '.((intval($cats[0]->get_weight())>0) ? $cats[0]->get_weight() : 0);
$opt_cat_cert_min= '<strong>'.get_lang('CertificateMinScore').'</strong>'.': '.(intval($cats[0]->get_certificate_min_score()>0) ? $cats[0]->get_certificate_min_score() : 0);
$opt_cat_descrip= '<strong>'.get_lang('GradebookDescriptionLog').'</strong>'.': '.(($cats[0]->get_description() == "" || is_null($cats[0]->get_description())) ? get_lang('None') : $cats[0]->get_description());
@ -821,16 +838,17 @@ if ($category != '0') {
$modify_icons= '<a href="gradebook_edit_cat.php?editcat=' . $cats[0]->get_id() . ' &amp;cidReq='.$cats[0]->get_course_code().'">'.Display::return_icon('edit.png', get_lang('EditCategory'),'','22').'</a>';
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deletecat=' . $cats[0]->get_id() . '&amp;selectcat=0&amp;cidReq='.$cats[0]->get_course_code().'" onclick="return confirmation();">'.Display::return_icon('delete.png', get_lang('DeleteAll'),'','22').'</a>';
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?visiblecat=' . $cats[0]->get_id() . '&amp;' . $visibility_command . '=&amp;selectcat=0 ">'.Display::return_icon($visibility_icon.'.png', get_lang('Visible'),'','22').'</a>';
$opt_cat_descrip1 = strip_tags($opt_cat_descrip);
echo '<div align="left" style="float:left">'.Display::return_icon('info.png', $opt_cat_descrip1,'','22').'</a>'.$op_cat_weight.' '.'&nbsp;&nbsp;'.$opt_cat_cert_min.'&nbsp;&nbsp;'.$opt_cat_descrip.'</div>';
$opt_cat_descrip1 = strip_tags($opt_cat_descrip);
echo '<div align="left" style="float:left">'.Display::return_icon('info.png', $opt_cat_descrip1,'','22').'</a>';
echo $op_cat_weight.' '.'&nbsp;&nbsp;'.$opt_cat_cert_min.'&nbsp;&nbsp;'.$opt_cat_descrip.'</div>';
echo $modify_icons;
echo '</div>';
} else {
// generating the total score for a course
$stud_id= api_get_user_id();
$cats_course = Category :: load ($category_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);
$cats_course = Category :: load ($category_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;
@ -839,7 +857,7 @@ if ($category != '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();
@ -866,6 +884,7 @@ if ($category != '0') {
$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>';
$certificates = Display::url(Display::return_icon('certificate.png', get_lang('Certificates'), array(), 48), $url, array('target'=>'_blank'));
echo '<div class="actions" align="right">';
echo $certificates;
echo '</div>';
@ -889,11 +908,11 @@ if (api_is_allowed_to_edit(null, true)) {
if ( (isset ($_GET['selectcat']) && $_GET['selectcat']<>0) ) {
//
} else {
if ( ((isset ($_GET['selectcat']) && $_GET['selectcat']==0) || ((isset($_GET['cidReq']) && $_GET['cidReq']!==''))) || isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') {
$cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
if(!$first_time=1) {
DisplayGradebook :: display_reduce_header_gradebook($cats[0],$is_course_admin, $is_platform_admin, $simple_search_form, false, false);
}
if (((isset ($_GET['selectcat']) && $_GET['selectcat']==0) || ((isset($_GET['cidReq']) && $_GET['cidReq']!==''))) || isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') {
$cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
if (!$first_time=1) {
DisplayGradebook :: display_reduce_header_gradebook($cats[0],$is_course_admin, $is_platform_admin, $simple_search_form, false, false);
}
}
}
}

@ -121,7 +121,10 @@ class CatForm extends FormValidator {
private function build_basic_form() {
$this->addElement('hidden', 'zero', 0);
$this->add_textfield('name', get_lang('CategoryName'),true,array('size'=>'54','maxlength'=>'50'));
$this->add_textfield('weight', get_lang('Weight'),true,array('size'=>'4','maxlength'=>'5'));
$this->add_textfield('weight', get_lang('TotalWeight'),true,array('size'=>'4','maxlength'=>'5'));
$this->addElement('static', null, null, '<i>'.get_lang('TheTotalOfActivitiesWeight').'</i>');
$this->add_textfield('certif_min_score', get_lang('CertificateMinScore'),false,array('size'=>'4','maxlength'=>'5'));
$this->addElement('hidden','hid_user_id');
$this->addElement('hidden','hid_parent_id');

@ -497,12 +497,12 @@ function parse_xml_data($file) {
* @param int The user id
* @return Datetime The date when you obtained the certificate
*/
function get_certificate_date_by_user_id ($cat_id,$user_id) {
function get_certificate_by_user_id ($cat_id,$user_id) {
$table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$sql_get_date='SELECT created_at FROM '.$table_certificate.' WHERE cat_id="'.intval($cat_id).'" AND user_id="'.intval($user_id).'"';
$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_get_date=Database::fetch_array($rs_get_date,'ASSOC');
return $row_get_date['created_at'];
$row =Database::fetch_array($rs_get_date,'ASSOC');
return $row;
}
/**
@ -554,13 +554,14 @@ function parse_xml_data($file) {
* @param int The user id
* @return boolean
*/
function delete_certificate ($cat_id,$user_id) {
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;

@ -3211,9 +3211,9 @@ class UserManager
*/
public function is_user_certified($cat_id,$user_id) {
$table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$sql='SELECT path_certificate FROM '.$table_certificate.' WHERE cat_id="'.Database::escape_string($cat_id).'" AND user_id="'.Database::escape_string($user_id).'" ';
$rs=Database::query($sql);
$row=Database::fetch_array($rs);
$sql = 'SELECT path_certificate FROM '.$table_certificate.' WHERE cat_id="'.Database::escape_string($cat_id).'" AND user_id="'.Database::escape_string($user_id).'" ';
$rs = Database::query($sql);
$row = Database::fetch_array($rs);
if ($row['path_certificate']=='' || is_null($row['path_certificate'])) {
return false;
} else {

Loading…
Cancel
Save