commit
7c9cd4ba7b
@ -0,0 +1,25 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Show specified user certificate |
||||
* @package chamilo.certificate |
||||
*/ |
||||
|
||||
/** |
||||
* Initialization |
||||
*/ |
||||
|
||||
$language_file= 'gradebook'; |
||||
|
||||
require_once '../main/inc/global.inc.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'certificate.lib.php'; |
||||
|
||||
/** |
||||
* Retrieve certificate |
||||
*/ |
||||
$certificate = new Certificate($_GET['id']); |
||||
|
||||
/** |
||||
* Show results |
||||
*/ |
||||
$certificate->show(); |
||||
@ -0,0 +1,104 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* @author jmontoya |
||||
* |
||||
* @package chamilo.document |
||||
*/ |
||||
/** |
||||
* Code |
||||
*/ |
||||
/* INITIALIZATION */ |
||||
|
||||
$language_file[] = 'document'; |
||||
require_once '../inc/global.inc.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'document.lib.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'glossary.lib.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php'; |
||||
|
||||
// Protection |
||||
api_protect_course_script(); |
||||
|
||||
$noPHP_SELF = true; |
||||
$header_file = Security::remove_XSS($_GET['file']); |
||||
$document_id = intval($_GET['id']); |
||||
|
||||
$course_info = api_get_course_info(); |
||||
$course_code = api_get_course_id(); |
||||
|
||||
if (empty($course_info)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
//Generate path |
||||
if (!$document_id) { |
||||
$document_id = DocumentManager::get_document_id($course_info, $header_file); |
||||
} |
||||
$document_data = DocumentManager::get_document_data_by_id($document_id, $course_code); |
||||
|
||||
if (empty($document_data)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$header_file = $document_data['path']; |
||||
$name_to_show = cut($header_file, 80); |
||||
|
||||
$path_array = explode('/', str_replace('\\', '/', $header_file)); |
||||
$path_array = array_map('urldecode', $path_array); |
||||
$header_file = implode('/', $path_array); |
||||
|
||||
$file = Security::remove_XSS(urldecode($document_data['path'])); |
||||
|
||||
$file_root = $course_info['path'].'/document'.str_replace('%2F', '/', $file); |
||||
$file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root; |
||||
$file_url_web = api_get_path(WEB_COURSE_PATH).$file_root; |
||||
|
||||
if (!file_exists($file_url_sys)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
if (is_dir($file_url_sys)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
//fix the screen when you try to access a protected course through the url |
||||
$is_allowed_in_course = $_SESSION ['is_allowed_in_course']; |
||||
|
||||
if ($is_allowed_in_course == false) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
//Check user visibility |
||||
//$is_visible = DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id()); |
||||
$is_visible = DocumentManager::check_visibility_tree($document_id, api_get_course_id(), api_get_session_id(), api_get_user_id()); |
||||
if (!api_is_allowed_to_edit() && !$is_visible) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
//TODO:clean all code |
||||
|
||||
/* Main section */ |
||||
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT'); |
||||
//header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); |
||||
header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT'); |
||||
header('Cache-Control: no-cache, must-revalidate'); |
||||
header('Pragma: no-cache'); |
||||
$browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file; |
||||
|
||||
$file_url_web = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$header_file.'?'.api_get_cidreq(); |
||||
|
||||
$pathinfo = pathinfo($header_file); |
||||
if ($pathinfo['extension']=='wav' && api_get_setting('enable_nanogong') == 'true'){ |
||||
echo '<div align="center">'; |
||||
echo '<br/>'; |
||||
echo '<applet id="applet" archive="../inc/lib/nanogong/nanogong.jar" code="gong.NanoGong" width="160" height="40" >'; |
||||
echo '<param name="SoundFileURL" value="'.$file_url_web.'" />'; |
||||
echo '<param name="ShowSaveButton" value="false" />'; |
||||
echo '<param name="ShowTime" value="true" />'; |
||||
echo '<param name="ShowRecordButton" value="false" />'; |
||||
echo '</applet>'; |
||||
echo '</div>'; |
||||
} else { |
||||
if ($pathinfo['extension']=='swf') { $width='83%'; $height='83%';} else {$width='100%'; $height='100%';} |
||||
echo '<iframe border="0" frameborder="0" scrolling="no" style="width:'.$width.'; height:'.$height.';background-color:#ffffff;" id="mainFrame" name="mainFrame" src="'.$file_url_web.'?'.api_get_cidreq().'&rand='.mt_rand(1, 10000).'"></iframe>'; |
||||
} |
||||
@ -0,0 +1,151 @@ |
||||
<?php |
||||
/** |
||||
* @package chamilo.library |
||||
*/ |
||||
class Certificate extends Model { |
||||
var $table; |
||||
var $columns = array('id','cat_id','score_certificate','created_at','path_certificate'); |
||||
var $certificate_data; |
||||
|
||||
var $certification_user_path; |
||||
var $user_id; |
||||
|
||||
public function __construct($certificate_id = null) { |
||||
$this->table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); |
||||
$this->certificate_data = null; |
||||
|
||||
if (isset($certificate_id)) { |
||||
$this->certificate_data = $this->get($certificate_id); |
||||
$this->user_id = $this->certificate_data['user_id']; |
||||
} else { |
||||
//Try with the current user |
||||
$this->user_id = api_get_user_id(); |
||||
} |
||||
|
||||
if ($this->user_id) { |
||||
//Need to be called before any operation |
||||
$this->check_certificate_path(); |
||||
|
||||
if (isset($this->certificate_data) && $this->certificate_data) { |
||||
if (empty($this->certificate_data['path_certificate'])) { |
||||
$this->generate(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Show an 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 the certificate user path directories |
||||
* Enter description here ... |
||||
*/ |
||||
public function check_certificate_path() { |
||||
$this->certification_user_path = null; |
||||
|
||||
//Setting certification path |
||||
$path_info = UserManager::get_user_picture_path_by_id($this->user_id, 'system', true); |
||||
|
||||
if (isset($path_info['dir']) && !empty($path_info)) { |
||||
|
||||
$this->certification_user_path = $path_info['dir'].'certificate/'; |
||||
|
||||
if (!is_dir($path_info['dir'])) { |
||||
mkdir($path_info['dir'],0777); |
||||
} |
||||
|
||||
if (!is_dir($this->certification_user_path)) { |
||||
mkdir($this->certification_user_path, 0777); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Generates a certificate |
||||
* */ |
||||
|
||||
public function generate() { |
||||
|
||||
if (empty($this->certification_user_path)) { |
||||
return false; |
||||
} |
||||
|
||||
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be.inc.php'; |
||||
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php'; |
||||
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/scoredisplay.class.php'; |
||||
|
||||
$my_category = Category :: load($this->certificate_data['cat_id']); |
||||
if ($my_category[0]->is_certificate_available($this->user_id)) { |
||||
|
||||
$user = api_get_user_info($this->user_id); |
||||
$scoredisplay = ScoreDisplay :: instance(); |
||||
$scorecourse = $my_category[0]->calc_score($this->user_id); |
||||
|
||||
$scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable')); |
||||
$cattotal = Category :: load($this->certificate_data['cat_id']); |
||||
$scoretotal= $cattotal[0]->calc_score($this->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']; |
||||
|
||||
//@todo this code is not needed |
||||
$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($this->certification_user_path)) { |
||||
$name = $this->certificate_data['path_certificate']; |
||||
if (!empty($this->certificate_data)) { |
||||
$new_content_html = get_user_certificate_content($this->user_id, $my_category[0]->get_course_code(), false); |
||||
|
||||
if ($cat_id = strval(intval($this->certificate_data['cat_id']))) { |
||||
$my_path_certificate = $this->certification_user_path.$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; |
||||
//Seems that the file was already generated |
||||
return true; |
||||
} else { |
||||
$my_new_content_html = $new_content_html; |
||||
$my_new_content_html = mb_convert_encoding($my_new_content_html,'UTF-8', api_get_system_encoding()); |
||||
|
||||
//Creating new name |
||||
$name = md5($this->user_id.$this->certificate_data['cat_id']).'.html'; |
||||
$my_path_certificate = $this->certification_user_path.$name; |
||||
|
||||
$result = @file_put_contents($my_path_certificate, $my_new_content_html); |
||||
$path_certificate='/'.$name; |
||||
//@todo move function in this class |
||||
update_user_info_about_certificate($this->certificate_data['cat_id'], $this->user_id, $path_certificate); |
||||
$this->certificate_data['path_certificate'] = $path_certificate; |
||||
return $result; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue