skala
Julio Montoya 14 years ago
commit a193aafda9
  1. 8
      main/admin/add_courses_to_session.php
  2. 10
      main/admin/add_users_to_session.php
  3. 11
      main/admin/index.php
  4. 6
      main/admin/resume_session.php
  5. 5
      main/admin/settings.php
  6. 2
      main/admin/usergroups.php
  7. 16
      main/course_info/infocours.php
  8. 2
      main/coursecopy/copy_course_session.php
  9. 4
      main/document/create_document.php
  10. 8
      main/document/document.inc.php
  11. 3
      main/exercice/multiple_answer_combination.class.php
  12. 3
      main/exercice/multiple_answer_combination_true_false.class.php
  13. 548
      main/inc/lib/certificate.lib.php
  14. 2
      main/inc/lib/display.lib.php
  15. 6
      main/inc/lib/document.lib.php
  16. 33
      main/inc/lib/main_api.lib.php
  17. 22
      main/inc/lib/template.lib.php
  18. 14
      main/install/configuration.dist.php
  19. 3
      main/template/default/layout/head.tpl
  20. 85
      tests/wipe-out.php

@ -48,14 +48,6 @@ if(isset($_GET['add_type']) && $_GET['add_type']!=''){
$add_type = Security::remove_XSS($_REQUEST['add_type']);
}
if (!api_is_platform_admin()) {
$sql = 'SELECT session_admin_id FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
$rs = Database::query($sql);
if (Database::result($rs,0,0)!=$_user['user_id']) {
api_not_allowed(true);
}
}
$xajax -> processRequests();
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');

@ -49,14 +49,6 @@ if(isset($_REQUEST['add_type']) && $_REQUEST['add_type']!=''){
$add_type = Security::remove_XSS($_REQUEST['add_type']);
}
if (!api_is_platform_admin()) {
$sql = 'SELECT session_admin_id FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
$rs = Database::query($sql);
if(Database::result($rs,0,0)!=$_user['user_id']) {
api_not_allowed(true);
}
}
//checking for extra field with filter on
$extra_field_list= UserManager::get_extra_fields();
@ -685,4 +677,4 @@ function makepost(select){
</script>
<?php
/* FOOTER */
Display::display_footer();
Display::display_footer();

@ -194,12 +194,13 @@ if (api_get_setting('use_session_mode') == 'true') {
}
$items[] = array('url'=>'session_export.php', 'label' => get_lang('ExportSessionListXMLCSV'));
$items[] = array('url'=>'../coursecopy/copy_course_session.php', 'label' => get_lang('CopyFromCourseInSessionToAnotherSession'));
$items[] = array('url'=>'session_list.php', 'label' => get_lang('ListSession'));
if (is_dir(api_get_path(SYS_TEST_PATH).'datafiller/')) { // option only visible in development mode. Enable through code if required
$items[] = array('url'=>'user_move_stats.php', 'label' => get_lang('MoveUserStats'));
}
$items[] = array('url'=>'career_dashboard.php', 'label' => get_lang('CareersAndPromotions'));
if (api_is_platform_admin()) {
if (is_dir(api_get_path(SYS_TEST_PATH).'datafiller/')) { // option only visible in development mode. Enable through code if required
$items[] = array('url'=>'user_move_stats.php', 'label' => get_lang('MoveUserStats'));
}
$items[] = array('url'=>'career_dashboard.php', 'label' => get_lang('CareersAndPromotions'));
}
$items[] = array('url'=>'usergroups.php', 'label' => get_lang('Classes'));
$blocks['sessions']['items'] = $items;

@ -45,10 +45,6 @@ $rs = Database::query($sql);
$session = Database::store_result($rs);
$session = $session[0];
if(!api_is_platform_admin() && $session['session_admin_id'] != $_user['user_id']) {
api_not_allowed(true);
}
$sql = 'SELECT name FROM '.$tbl_session_category.' WHERE id = "'.intval($session['session_category_id']).'"';
$rs = Database::query($sql);
$session_category = '';
@ -342,4 +338,4 @@ if ($session['nbr_users']==0) {
</table>
<?php
// footer
Display :: display_footer();
Display :: display_footer();

@ -219,6 +219,7 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
foreach ($values as $key => $value) {
if (in_array($key, $settings_to_avoid)) { continue; }
if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') { continue; }
$key = Database::escape_string($key);
$sql = "UPDATE $table_settings_current SET selected_value = 'false' WHERE variable = '".$key."' AND access_url = ".intval($url_id)." AND type IN ('checkbox', 'radio') ";
$res = Database::query($sql);
@ -233,6 +234,8 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
foreach ($values as $key => $value) {
if (in_array($key, $settings_to_avoid)) { continue; }
// Avoid form elements which have nothing to do with settings
if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') { continue; }
//
// Treat gradebook values in separate function.
//if (strpos($key, 'gradebook_score_display_custom_values') === false) {
@ -493,4 +496,4 @@ if (!empty($_GET['category'])) {
}
/* FOOTER */
Display :: display_footer();
Display :: display_footer();

@ -12,7 +12,7 @@ $cidReset = true;
require_once '../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
api_protect_admin_script(true);
//Add the JS needed to use the jqgrid
$htmlHeadXtra[] = api_get_jqgrid_js();

@ -328,13 +328,15 @@ $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class=
$form->addElement('html', '</div></div>');
// Certificate settings
$form->addElement('html', '<div><h3>'.Display::return_icon('certificate.png', Security::remove_XSS(get_lang('Certificates')),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('Certificates')).'</h3><div>');
if (api_get_setting('allow_public_certificates')=='true') {
// Certificate settings
$form->addElement('html', '<div><h3>'.Display::return_icon('certificate.png', Security::remove_XSS(get_lang('Certificates')),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('Certificates')).'</h3><div>');
$group = array();
$group[]=$form->createElement('radio', 'allow_public_certificates', get_lang('AllowPublicCertificates'), get_lang('Yes'), 1);
$group[]=$form->createElement('radio', 'allow_public_certificates', null, get_lang('No'), 0);
$form->addGroup($group, '', array(get_lang("AllowPublicCertificates")), '');
}
$group = array();
$group[]=$form->createElement('radio', 'allow_public_certificates', get_lang('AllowPublicCertificates'), get_lang('Yes'), 1);
$group[]=$form->createElement('radio', 'allow_public_certificates', null, get_lang('No'), 0);
$form->addGroup($group, '', array(get_lang("AllowPublicCertificates")), '');
$form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"');
$form->addElement('html', '</div></div>');
@ -478,4 +480,4 @@ echo '<div id="course_settings">';
$form->display();
echo '</div>';
Display::display_footer();
Display::display_footer();

@ -18,7 +18,7 @@ $language_file = array('coursebackup', 'admin');
$cidReset = true;
require_once '../inc/global.inc.php';
$current_course_tool = TOOL_COURSE_MAINTENANCE;
api_protect_course_script(true);
api_protect_course_script(true, true);
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'xajax/xajax.inc.php';

@ -541,6 +541,10 @@ if ($form->validate()) {
$selectcat = "&selectcat=".Security::remove_XSS($_REQUEST['selectcat']);
$certificate_condition = '';
if ($is_certificate_mode) {
$df = DocumentManager::get_default_certificate_id($_course['code']);
if (!isset($df)) {
DocumentManager::attach_gradebook_certificate ($_course['code'],$document_id);
}
$certificate_condition = '&certificate=true';
}
header('Location: document.php?id='.$folder_id.$selectcat.$certificate_condition);

@ -605,7 +605,7 @@ function build_edit_icons($document_data, $id, $is_template, $is_read_only = 0,
if ($type == 'file' && ($extension == 'html' || $extension == 'htm')) {
if ($is_template == 0) {
if ((isset($_GET['curdirpath']) && $_GET['curdirpath'] != '/certificates') || !isset($_GET['curdirpath'])) {
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;add_as_template='.$id.$req_gid.'&amp;'.$sort_params.'">'.Display::return_icon('wizard.png', get_lang('AddAsTemplate'),array(), ICON_SIZE_SMALL).'</a>';
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;add_as_template='.$id.$req_gid.'&amp;'.$sort_params.'">'.Display::return_icon('wizard.png', get_lang('AddAsTemplate'),array(), ICON_SIZE_SMALL).'</a>';
}
if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates') {//allow attach certificate to course
$visibility_icon_certificate='nocertificate';
@ -619,9 +619,9 @@ function build_edit_icons($document_data, $id, $is_template, $is_read_only = 0,
$certificate=get_lang('NoDefaultCertificate');
}
if (isset($_GET['selectcat'])) {
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;selectcat='.Security::remove_XSS($_GET['selectcat']).'&amp;set_certificate='.$id.$req_gid.'&amp;'.$sort_params.'"><img src="../img/'.$visibility_icon_certificate.'.png" border="0" title="'.$certificate.'" alt="" /></a>';
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;selectcat='.Security::remove_XSS($_GET['selectcat']).'&amp;set_certificate='.$id.$req_gid.'&amp;'.$sort_params.'"><img src="../img/'.$visibility_icon_certificate.'.png" border="0" title="'.$certificate.'" alt="" /></a>';
if ($is_preview) {
$modify_icons .= '&nbsp;<a target="_blank" href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;set_preview='.$id.$req_gid.'&amp;'.$sort_params.'" >'.
$modify_icons .= '&nbsp;<a target="_blank" href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;set_preview='.$id.$req_gid.'&amp;'.$sort_params.'" >'.
Display::return_icon('preview_view.png', $preview,'',ICON_SIZE_SMALL).'</a>';
}
}
@ -918,4 +918,4 @@ function is_browser_viewable($file_extension) {
return api_browser_support('webm');
}
return $result;
}
}

@ -9,7 +9,7 @@
/**
* Code
*/
if(!class_exists('MultipleAnswerCombination')):
if(class_exists('MultipleAnswerCombination')) { return true; }
/**
CLASS MultipleAnswer
@ -229,5 +229,4 @@ class MultipleAnswerCombination extends Question {
}
endif;
?>

@ -9,7 +9,7 @@
/**
* Code
*/
if(!class_exists('MultipleAnswerCombinationTrueFalse')):
if(class_exists('MultipleAnswerCombinationTrueFalse')) { return true; }
require 'multiple_answer_combination.class.php';
/**
CLASS MultipleAnswer
@ -36,4 +36,3 @@ class MultipleAnswerCombinationTrueFalse extends MultipleAnswerCombination {
$this->options = array('1'=>get_lang('True'),'0' =>get_lang('False'), '2' =>get_lang('DontKnow'));
}
}
endif;

@ -1,211 +1,221 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.library
*/
* The certificates class is used to generate certificates from inside the
* gradebook tool.
* @package chamilo.library.certificates
*/
class Certificate extends Model {
var $table;
var $columns = array('id','cat_id','score_certificate','created_at','path_certificate');
/**
* Certification data
* */
*/
var $certificate_data = array();
/**
* Student's certification path
* */
*/
var $certification_user_path = null;
var $certification_web_user_path = null;
var $html_file = null;
var $qr_file = null;
var $html_file = null;
var $qr_file = null;
var $user_id;
//If true every time we enter to the certificate URL we would generate a new certificate
// (good thing because we can edit the certificate and all users will have the latest certificate bad because we load everytime)
var $force_certificate_generation = true; //default true
public function __construct($certificate_id = null) {
$this->table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
/**
* Constructor
* @param int ID of the certificate. If no ID given, take user_id and try to generate one
*/
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'];
$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();
//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();
//To force certification generation
if ($this->force_certificate_generation) {
$this->generate();
}
if (isset($this->certificate_data) && $this->certificate_data) {
if (empty($this->certificate_data['path_certificate'])) {
$this->generate();
}
}
//Need to be called before any operation
$this->check_certificate_path();
//To force certification generation
if ($this->force_certificate_generation) {
$this->generate();
}
if (isset($this->certificate_data) && $this->certificate_data) {
if (empty($this->certificate_data['path_certificate'])) {
$this->generate();
}
}
}
//Setting the qr and html variables
if (isset($certificate_id) && !empty($this->certification_user_path)) {
$pathinfo = pathinfo($this->certificate_data['path_certificate']);
$this->html_file = $this->certification_user_path.basename($this->certificate_data['path_certificate']);
$this->qr_file = $this->certification_user_path.$pathinfo['filename'].'_qr.png';
$pathinfo = pathinfo($this->certificate_data['path_certificate']);
$this->html_file = $this->certification_user_path.basename($this->certificate_data['path_certificate']);
$this->qr_file = $this->certification_user_path.$pathinfo['filename'].'_qr.png';
}
}
/**
* Checks if the certificate user path directory is created
*/
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);
$web_path_info = UserManager::get_user_picture_path_by_id($this->user_id, 'web', true);
if (!empty($path_info) && isset($path_info['dir'])) {
$this->certification_user_path = $path_info['dir'].'certificate/';
$this->certification_web_user_path = $web_path_info['dir'].'certificate/';
if (!is_dir($path_info['dir'])) {
mkdir($path_info['dir'], 0777, true);
}
if (!is_dir($this->certification_user_path)) {
mkdir($this->certification_user_path, 0777);
}
}
}
/**
* Checks if the certificate user path directory is created
*/
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);
$web_path_info = UserManager::get_user_picture_path_by_id($this->user_id, 'web', true);
if (!empty($path_info) && isset($path_info['dir'])) {
$this->certification_user_path = $path_info['dir'].'certificate/';
$this->certification_web_user_path = $web_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);
}
}
}
public function delete() {
if (!empty($this->certificate_data)) {
if (!is_null($this->html_file) || $this->html_file!='' || strlen($this->html_file)) {
//Deleting HTML file
if (is_file($this->html_file)) {
@unlink($this->html_file);
if (is_file($this->html_file) === false) {
$delete_db = true;
} else {
$delete_db = false;
}
}
//Deleting QR code PNG image file
if (is_file($this->qr_file)) {
@unlink($this->qr_file);
}
if ($delete_db) {
return parent::delete($this->certificate_data['id']);
}
} else {
return parent::delete($this->certificate_data['id']);
}
}
return false;
}
/**
* Generates an HTML Certificate and fills the path_certificate field in the DB
* */
public function generate() {
//The user directory should be set
if (empty($this->certification_user_path) && $this->force_certificate_generation == false) {
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']);
}
/**
* Deletes the current certificate object. This is generally triggered by
* the teacher from the gradebook tool to re-generate the certificate because
* the original version wa flawed.
*/
public function delete() {
if (!empty($this->certificate_data)) {
if (!is_null($this->html_file) || $this->html_file!='' || strlen($this->html_file)) {
//Deleting HTML file
if (is_file($this->html_file)) {
@unlink($this->html_file);
if (is_file($this->html_file) === false) {
$delete_db = true;
} else {
$delete_db = false;
}
}
//Deleting QR code PNG image file
if (is_file($this->qr_file)) {
@unlink($this->qr_file);
}
if ($delete_db) {
return parent::delete($this->certificate_data['id']);
}
} else {
return parent::delete($this->certificate_data['id']);
}
}
return false;
}
/**
* Generates an HTML Certificate and fills the path_certificate field in the DB
* */
public function generate() {
//The user directory should be set
if (empty($this->certification_user_path) && $this->force_certificate_generation == false) {
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 (isset($my_category[0]) && $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);
if (isset($my_category[0]) && $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());
//$date = date('d/m/Y', time());
//If the gradebook is related to skills we added the skills to the user
$skill = new Skill();
$skill->add_skill_to_user($this->user_id, $this->certificate_data['cat_id']);
if (is_dir($this->certification_user_path)) {
if (!empty($this->certificate_data)) {
$new_content_html = get_user_certificate_content($this->user_id, $my_category[0]->get_course_code(), false);
if (is_dir($this->certification_user_path)) {
if (!empty($this->certificate_data)) {
$new_content_html = get_user_certificate_content($this->user_id, $my_category[0]->get_course_code(), false);
if ($my_category[0]->get_id() == strval(intval($this->certificate_data['cat_id']))) {
$name = $this->certificate_data['path_certificate'];
$my_path_certificate = $this->certification_user_path.basename($name);
if (file_exists($my_path_certificate) && !empty($name) && !is_dir($my_path_certificate) && $this->force_certificate_generation == false) {
//Seems that the file was already generated
return true;
} else {
//Creating new name
$name = md5($this->user_id.$this->certificate_data['cat_id']).'.html';
$my_path_certificate = $this->certification_user_path.$name;
$path_certificate ='/'.$name;
//Getting QR filename
$file_info = pathinfo($path_certificate);
$qr_code_filename = $this->certification_user_path.$file_info['filename'].'_qr.png';
if ($my_category[0]->get_id() == strval(intval($this->certificate_data['cat_id']))) {
$name = $this->certificate_data['path_certificate'];
$my_path_certificate = $this->certification_user_path.basename($name);
if (file_exists($my_path_certificate) && !empty($name) && !is_dir($my_path_certificate) && $this->force_certificate_generation == false) {
//Seems that the file was already generated
return true;
} else {
//Creating new name
$name = md5($this->user_id.$this->certificate_data['cat_id']).'.html';
$my_path_certificate = $this->certification_user_path.$name;
$path_certificate ='/'.$name;
//Getting QR filename
$file_info = pathinfo($path_certificate);
$qr_code_filename = $this->certification_user_path.$file_info['filename'].'_qr.png';
$new_content_html['content'] = str_replace('((certificate_barcode))', Display::img($this->certification_web_user_path.$file_info['filename'].'_qr.png', 'QR'), $new_content_html['content']);
$my_new_content_html = $new_content_html['content'];
$my_new_content_html = mb_convert_encoding($my_new_content_html,'UTF-8', api_get_system_encoding());
$result = @file_put_contents($my_path_certificate, $my_new_content_html);
if ($result) {
$new_content_html['content'] = str_replace('((certificate_barcode))', Display::img($this->certification_web_user_path.$file_info['filename'].'_qr.png', 'QR'), $new_content_html['content']);
$my_new_content_html = $new_content_html['content'];
$my_new_content_html = mb_convert_encoding($my_new_content_html,'UTF-8', api_get_system_encoding());
$result = @file_put_contents($my_path_certificate, $my_new_content_html);
if ($result) {
//Updating the path
self::update_user_info_about_certificate($this->certificate_data['cat_id'], $this->user_id, $path_certificate);
$this->certificate_data['path_certificate'] = $path_certificate;
if ($this->html_file_is_generated()) {
if (!empty($file_info)) {
$text = $this->parse_certificate_variables($new_content_html['variables']);
$this->generate_qr($text, $qr_code_filename);
}
}
}
return $result;
}
}
}
}
}
return false;
}
self::update_user_info_about_certificate($this->certificate_data['cat_id'], $this->user_id, $path_certificate);
$this->certificate_data['path_certificate'] = $path_certificate;
if ($this->html_file_is_generated()) {
if (!empty($file_info)) {
$text = $this->parse_certificate_variables($new_content_html['variables']);
$this->generate_qr($text, $qr_code_filename);
}
}
}
return $result;
}
}
}
}
}
return false;
}
/**
* update user info about certificate
@ -223,53 +233,60 @@ class Certificate extends Model {
}
}
/**
*
* Check if the file was generated
*
* @return boolean
*/
function html_file_is_generated() {
if (empty($this->certification_user_path)) {
return false;
}
if (!empty($this->certificate_data) && isset($this->certificate_data['path_certificate']) && !empty($this->certificate_data['path_certificate'])) {
return true;
}
return false;
}
/**
* @param string Text to be added in the QR code
* @param string file path of the image
* */
public function generate_qr($text, $path) {
//Make sure HTML certificate is generated
if (!empty($text) && !empty($path)) {
require_once api_get_path(LIBRARY_PATH).'phpqrcode/qrlib.php';
//L low, M - Medium, L large error correction
$return = QRcode::png($text, $path, 'M', 2, 2);
}
}
private function parse_certificate_variables($array) {
$text = '';
$headers = $array[0];
$content = $array[1];
$final_content = array();
/**
*
* Check if the file was generated
*
* @return boolean
*/
function html_file_is_generated() {
if (empty($this->certification_user_path)) {
return false;
}
if (!empty($this->certificate_data) && isset($this->certificate_data['path_certificate']) && !empty($this->certificate_data['path_certificate'])) {
return true;
}
return false;
}
/**
* Generates a QR code for the certificate. The QR code embeds the text given
* @param string Text to be added in the QR code
* @param string file path of the image
* */
public function generate_qr($text, $path) {
//Make sure HTML certificate is generated
if (!empty($text) && !empty($path)) {
require_once api_get_path(LIBRARY_PATH).'phpqrcode/qrlib.php';
//L low, M - Medium, L large error correction
$return = QRcode::png($text, $path, 'M', 2, 2);
}
}
/**
* Transforms certificate tags into text values. This function is very static
* (it doesn't allow for much flexibility in terms of what tags are printed).
* @param array Contains two array entris: first are the headers, second is an array of contents
* @return string The translated string
*/
private function parse_certificate_variables($array) {
$text = '';
$headers = $array[0];
$content = $array[1];
$final_content = array();
if (!empty($content)) {
foreach($content as $key => $value) {
$my_header = $headers[$key];
$my_header = str_replace(array('((', '))') , '', $my_header);
$final_content[$my_header] = $value;
}
if (!empty($content)) {
foreach($content as $key => $value) {
$my_header = $headers[$key];
$my_header = str_replace(array('((', '))') , '', $my_header);
$final_content[$my_header] = $value;
}
}
/* Certificate tags
*
0 => string '((user_firstname))' (length=18)
/* Certificate tags
*
0 => string '((user_firstname))' (length=18)
1 => string '((user_lastname))' (length=17)
2 => string '((gradebook_institution))' (length=25)
3 => string '((gradebook_sitename))' (length=22)
@ -283,52 +300,71 @@ class Certificate extends Model {
11 => string '((certificate_link))' (length=20)
12 => string '((certificate_link_html))' (length=25)
13 => string '((certificate_barcode))' (length=23)
*/
$break_space = " \n\r ";
$text = $final_content['gradebook_institution'].' - '.$final_content['gradebook_sitename'].' - '.get_lang('Certification').$break_space.
get_lang('Student'). ': '.$final_content['user_firstname'].' '.$final_content['user_lastname'].$break_space.
get_lang('Teacher'). ': '.$final_content['teacher_firstname'].' '.$final_content['teacher_lastname'].$break_space.
get_lang('Date'). ': '.$final_content['date_certificate'].$break_space.
get_lang('Score'). ': '.$final_content['gradebook_grade'].$break_space.
'URL'. ': '.$final_content['certificate_link'];
return $text;
}
/**
* Shows the student's certificate (HTML file)
*/
public function show() {
*/
$break_space = " \n\r ";
$text = $final_content['gradebook_institution'].' - '.$final_content['gradebook_sitename'].' - '.get_lang('Certification').$break_space.
get_lang('Student'). ': '.$final_content['user_firstname'].' '.$final_content['user_lastname'].$break_space.
get_lang('Teacher'). ': '.$final_content['teacher_firstname'].' '.$final_content['teacher_lastname'].$break_space.
get_lang('Date'). ': '.$final_content['date_certificate'].$break_space.
get_lang('Score'). ': '.$final_content['gradebook_grade'].$break_space.
'URL'. ': '.$final_content['certificate_link'];
return $text;
}
/**
* Shows the student's certificate (HTML file). If the global setting
* allow_public_certificates is set to 'false', no certificate can be printed.
* If the global allow_public_certificates is set to 'true' and the course
* setting allow_public_certificates is set to 0, no certificate *in this
* course* can be printed (for anonymous users). Connected users can always
* print them.
*/
public function show() {
// Special rules for anonymous users
$failed = false;
if (api_is_anonymous()) {
if (api_get_setting('allow_public_certificates') != 'true') {
return false;
}
if (isset($this->certificate_data) && isset($this->certificate_data['cat_id'])) {
$gradebook = new Gradebook();
$gradebook_info = $gradebook->get($this->certificate_data['cat_id']);
if (!empty($gradebook_info['course_code'])) {
$allow_public_certificates = api_get_course_setting('allow_public_certificates', $gradebook_info['course_code']);
if ($allow_public_certificates == 0) {
return false;
// The "non-public" setting is set, so do not print
$failed = true;
} else {
// Check the course-level setting to make sure the certificate
// can be printed publicly
if (isset($this->certificate_data) && isset($this->certificate_data['cat_id'])) {
$gradebook = new Gradebook();
$gradebook_info = $gradebook->get($this->certificate_data['cat_id']);
if (!empty($gradebook_info['course_code'])) {
$allow_public_certificates = api_get_course_setting('allow_public_certificates', $gradebook_info['course_code']);
if ($allow_public_certificates == 0) {
// Printing not allowed
$failed = true;
}
} else {
// No course ID defined (should never get here)
Display :: display_reduced_header();
Display :: display_warning_message(get_lang('NoCertificateAvailable'));
exit;
}
} else {
return false;
}
}
}
//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;
}
}
if ($failed) {
Display :: display_reduced_header();
Display :: display_warning_message(get_lang('CertificateExistsButNotPublic'));
exit;
}
//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;
}
}

@ -577,7 +577,7 @@ class Display {
//Checking the img/ folder
$icon = $w_code_path.'img/'.$image;
}
$icon = api_get_cdn_path($icon);
if ($return_only_path) {
return $icon;
}

@ -1326,6 +1326,10 @@ class DocumentManager {
}
$sql = 'SELECT document_id FROM '.$tbl_category.' WHERE course_code="'.Database::escape_string($course_id).'" '.$sql_session;
$rs = Database::query($sql);
$num = Database::num_rows($rs);
if ($num == 0) {
return null;
}
$row = Database::fetch_array($rs);
return $row['document_id'];
}
@ -3018,4 +3022,4 @@ class DocumentManager {
return array('ods', 'odt');
}
}
//end class DocumentManager
//end class DocumentManager

@ -631,6 +631,31 @@ function api_get_path($path_type, $path = null) {
return null;
}
/**
* Gets a modified version of the path for the CDN, if defined in
* configuration.php
* @param string The path of the resource without CDN
* @return string The path of the resource converted to CDN
* @author Yannick Warnier <ywarnier@beeznst.org>
*/
function api_get_cdn_path($web_path) {
global $_configuration;
$web_root = api_get_path(WEB_PATH);
$ext = substr($web_path,strrpos($web_path,'.'));
if (isset($ext[2])) { // faster version of strlen to check if len>2
// Check for CDN definitions
if (!empty($_configuration['cdn_enable']) && !empty($ext)) {
foreach ($_configuration['cdn'] as $host => $exts) {
if (in_array($ext,$exts)) {
//Use host as defined in $_configuration['cdn'], without
// trailing slash
return str_replace($web_root,$host.'/',$web_path);
}
}
}
}
return $web_path;
}
/**
* @return bool Return true if CAS authentification is activated
@ -769,14 +794,15 @@ function api_valid_email($address) {
*
* This is only the first proposal, test and improve!
* @param boolean Option to print headers when displaying error message. Default: false
* @param boolean Whether session admins should be allowed or not.
* @return boolean True if the user has access to the current course or is out of a course context, false otherwise
* @todo replace global variable
* @author Roan Embrechts
*/
function api_protect_course_script($print_headers = false) {
function api_protect_course_script($print_headers = false, $allow_session_admins = false) {
global $is_allowed_in_course;
$is_visible = false;
if (api_is_platform_admin()) {
if (api_is_platform_admin($allow_session_admins)) {
return true;
}
$course_info = api_get_course_info();
@ -2048,6 +2074,7 @@ function api_get_self() {
/**
* Checks whether current user is a platform administrator
* @param boolean Whether session admins should be considered admins or not
* @return boolean True if the user has platform admin rights,
* false otherwise.
* @see usermanager::is_admin(user_id) for a user-id specific function
@ -5898,4 +5925,4 @@ function api_get_locked_settings() {
'login_is_email',
'chamilo_database_version'
);
}
}

@ -327,10 +327,10 @@ class Template {
}
//Base CSS
$style_html = '@import "'.api_get_path(WEB_CSS_PATH).'base.css";'."\n";
$style_html = '@import "'.api_get_cdn_path(api_get_path(WEB_CSS_PATH).'base.css').'";'."\n";
//Default theme CSS
$style_html .= '@import "'.api_get_path(WEB_CSS_PATH).$this->theme.'/default.css";'."\n";
$style_html .= '@import "'.api_get_cdn_path(api_get_path(WEB_CSS_PATH).$this->theme.'/default.css').'";'."\n";
$navigator_info = api_get_navigator();
@ -338,12 +338,12 @@ class Template {
$style_html .= 'img, div { behavior: url('.api_get_path(WEB_LIBRARY_PATH).'javascript/iepngfix/iepngfix.htc) } '."\n";
}
$style_html .= '@import "'.api_get_path(WEB_CSS_PATH).'bootstrap-responsive.css";'."\n";
$style_html .= '@import "'.api_get_path(WEB_CSS_PATH).'responsive.css";'."\n";
$style_html .= '@import "'.api_get_cdn_path(api_get_path(WEB_CSS_PATH).'bootstrap-responsive.css').'";'."\n";
$style_html .= '@import "'.api_get_cdn_path(api_get_path(WEB_CSS_PATH).'responsive.css').'";'."\n";
$this->assign('css_style', $style_html);
$style_print = '@import "'.api_get_path(WEB_CSS_PATH).$this->theme.'/print.css";'."\n";
$style_print = '@import "'.api_get_cdn_path(api_get_path(WEB_CSS_PATH).$this->theme.'/print.css').'";'."\n";
$this->assign('css_style_print', $style_print);
@ -481,11 +481,21 @@ class Template {
}
</style>';
}
// Implementation of prefetch.
// See http://cdn.chamilo.org/main/img/online.png for details
$prefetch = '';
if (!empty($_configuration['cdn_enable'])) {
$prefetch .= '<meta http-equiv="x-dns-prefetch-control" content="on">';
foreach ($_configuration['cdn'] as $host => $exts) {
$prefetch .= '<link rel="dns-prefetch" href="'.$host.'">';
}
}
global $this_section;
//@todo minify CSS and JS
$this->assign('prefetch', $prefetch);
$this->assign('css_file_to_string', $css_file_to_string);
$this->assign('js_file_to_string', $js_file_to_string);
@ -670,4 +680,4 @@ class Template {
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null) {
echo $this->twig->render($template, $this->params);
}
}
}

@ -128,19 +128,17 @@ $_configuration[1]['hosting_limit_disk_space'] = 0;
* server to serve your static data. If you don't know what a CDN is, you
* don't need it. These settings are for simple Origin Pull CDNs and are
* experimental. Enable only if you really know what you're doing.
* This might conflict with multiple-access urls.
*/
// Set the following setting to true to start using the CDN
$_configuration['cdn_enable'] = false;
// The following setting will be ignored if the previous one is set to false
$_configuration['cdn'] = array(
// you can define several CDNs and split them by extensions
0 => array(
//replace the following by your full CDN URL, which should point to
// your Chamilo's root directory, including the final slash
'url' => 'http://cdn.chamilo.org/',
'ext' => array('.css','.js','.jpg','.jpeg','.png','.gif','.avi','.flv'),
),
// copy the section above and modify following your needs
//You can define several CDNs and split them by extensions
//Replace the following by your full CDN URL, which should point to
// your Chamilo's root directory. DO NOT INCLUDE a final slash! (won't work)
'http://cdn.chamilo.org' => array('.css','.js','.jpg','.jpeg','.png','.gif','.avi','.flv'),
// copy the line above and modify following your needs
);
/**

@ -2,6 +2,7 @@
<link href="http://www.chamilo.org/documentation.php" rel="help" />
<link href="http://www.chamilo.org/team.php" rel="author" />
<link href="http://www.chamilo.org" rel="copyright" />
{{ prefetch}}
{{ favico }}
<link rel="apple-touch-icon" href="{{ _p.web}}apple-touch-icon.png" />
<meta name="apple-mobile-web-app-capable" content="yes" />
@ -254,4 +255,4 @@ $(function() {
});*/
});
</script>
{{ header_extra_content }}
{{ header_extra_content }}

@ -0,0 +1,85 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This script wipes out your Chamilo installation completely: databases,
* courses directories, configuration files and all other temp directories.
* It only works when launched from the command line and requires Chamilo to
* be installed (otherwise it will not find the references as to the paths and
* databases to delete). It only wipes out stuff and directories it knows are
* created by Chamilo though, so don't worry about your own files if you didn't
* store them in variable Chamilo directories.
* Requires Chamilo LMS 1.9 or greater
* @chamilo.tests.scripts
*/
/**
* Security checks
*/
if (PHP_SAPI != 'cli') {
echo "For security reasons, this script can only be launched from the command line, sorry.";
exit;
}
if (!isset($argv[1]) || $argv[1] != '--i-am-sure') {
echo " This script will completely erase all Chamilo installations based on this\n",
" directory. There will be no way to recover it. If you really are sure you\n",
" want to do this, please launch this script again using the\n --i-am-sure\n",
" parameter. You've been warned. Don't come complaining!\n";
exit;
}
if (!file_exists(dirname(__FILE__).'/../main/inc/global.inc.php')) {
echo " This script needs to be run from the tests/ directory inside a Chamilo\n", " installation. Please make sure main/inc/global.inc.php exists, then run this\n", " script again.\n";
}
if (!is_file(dirname(__FILE__).'/../main/inc/conf/configuration.php')) {
echo " This script will only work on an already installed version of Chamilo. The \n", "main/inc/conf/configuration.php file could not be found, which is understood\n", "as Chamilo not being installed.\n";
}
/**
* Preparing vars
*/
ini_set('track_errors',1);
$_SERVER['SERVER_NAME'] = '';
$_SERVER['HTTP_HOST'] = 'localhost';
$root = dirname(__FILE__).'/../';
require $root.'main/inc/global.inc.php';
$courses = api_get_path(SYS_COURSE_PATH);
$main = api_get_path(SYS_CODE_PATH).'inc/conf/';
$global_db = Database::get_main_database();
$users = api_get_path(SYS_CODE_PATH).'upload/users/';
$arch = api_get_path(SYS_ARCHIVE_PATH);
$webpath = api_get_path(WEB_PATH);
$homepath = api_get_path(SYS_PATH).'home';
// With all this, we will still be missing custom languages and CSS dirs
/**
* Running the cleanup
*/
echo "Assuming ".api_get_path(SYS_PATH)." as Chamilo directory\n";
foreach (array($courses, $users, $arch, $homepath, $main) as $dir) {
$list = scandir($dir);
echo "Cleaning $dir\n";
foreach ($list as $entry) {
if (substr($entry,0,1) == '.' or strcmp($entry,'htaccess')===0 or strcmp($entry,'index.html')===0 or substr($entry,-9,9)=='.dist.php') {
//skip files that are part of the Chamilo installation
} else {
if ($dir == $homepath and
((is_dir($homepath.$entry) and $entry == 'default_platform_document')
or (!is_dir($homepath.$entry) and substr($entry,-5)=='.html') and strlen($entry)<=17)
) {
//skip
} else {
if (is_dir($dir.$entry)) {
//echo "Removing ".$dir.$entry."\n";
rmdirr($dir.$entry);
} else {
//echo "Removing ".$dir.$entry."\n";
unlink($dir.$entry);
}
}
}
}
}
echo "Dropping database ".$global_db."\n";
$sql = "DROP DATABASE $global_db";
$res = Database::query($sql);
if ($res === false) {
echo "Failed dropping database. Please check manually.\n";
} else {
echo "All clean! Load $webpath to run install again.\n";
}
Loading…
Cancel
Save