diff --git a/main/document/document.php b/main/document/document.php index 236a8d7a25..eeea4a639b 100755 --- a/main/document/document.php +++ b/main/document/document.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']); diff --git a/main/gradebook/gradebook_display_certificate.php b/main/gradebook/gradebook_display_certificate.php index 79f741ebdc..e988502f23 100755 --- a/main/gradebook/gradebook_display_certificate.php +++ b/main/gradebook/gradebook_display_certificate.php @@ -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')); 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'));
- +
$value_certificate) { ?> - - + + 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('',$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= ' - '; - $print .='' . get_lang('Print') . ' ' . get_lang('Print') . ''; - - //add header - $new_content_html=$new_content[0].$print.''.$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('',$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 = ''; + $print .='' . get_lang('Print') . ' ' . get_lang('Print') . ''; + + //add header + $new_content_html=$new_content[0].$print.''.$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= ''.get_lang('Weight').''.': '.((intval($cats[0]->get_weight())>0) ? $cats[0]->get_weight() : 0); + $op_cat_weight= ''.get_lang('TotalWeight').''.': '.((intval($cats[0]->get_weight())>0) ? $cats[0]->get_weight() : 0); $opt_cat_cert_min= ''.get_lang('CertificateMinScore').''.': '.(intval($cats[0]->get_certificate_min_score()>0) ? $cats[0]->get_certificate_min_score() : 0); $opt_cat_descrip= ''.get_lang('GradebookDescriptionLog').''.': '.(($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= ''.Display::return_icon('edit.png', get_lang('EditCategory'),'','22').''; $modify_icons .= ' '.Display::return_icon('delete.png', get_lang('DeleteAll'),'','22').''; $modify_icons .= ' '.Display::return_icon($visibility_icon.'.png', get_lang('Visible'),'','22').''; - $opt_cat_descrip1 = strip_tags($opt_cat_descrip); - echo '
'.Display::return_icon('info.png', $opt_cat_descrip1,'','22').''.$op_cat_weight.' '.'  '.$opt_cat_cert_min.'  '.$opt_cat_descrip.'
'; + $opt_cat_descrip1 = strip_tags($opt_cat_descrip); + echo '
'.Display::return_icon('info.png', $opt_cat_descrip1,'','22').''; + echo $op_cat_weight.' '.'  '.$opt_cat_cert_min.'  '.$opt_cat_descrip.'
'; echo $modify_icons; echo ''; } 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.= ''.get_lang('Certificates').' '.get_lang('Total').': '.$scoretotal_display.''; $certificates = Display::url(Display::return_icon('certificate.png', get_lang('Certificates'), array(), 48), $url, array('target'=>'_blank')); + echo '
'; echo $certificates; echo '
'; @@ -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); + } } } } diff --git a/main/gradebook/lib/fe/catform.class.php b/main/gradebook/lib/fe/catform.class.php index b7110a0d08..2037ffa7da 100755 --- a/main/gradebook/lib/fe/catform.class.php +++ b/main/gradebook/lib/fe/catform.class.php @@ -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, ''.get_lang('TheTotalOfActivitiesWeight').''); + $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'); diff --git a/main/gradebook/lib/gradebook_functions.inc.php b/main/gradebook/lib/gradebook_functions.inc.php index 8d3677ea1c..a0ef6f90c2 100755 --- a/main/gradebook/lib/gradebook_functions.inc.php +++ b/main/gradebook/lib/gradebook_functions.inc.php @@ -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; diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 099a7621c1..16bda9f047 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -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 {
+ '_blank')); + echo $certificates; + ?> + +