Advertisement
kevin2458

course_home.php

Oct 16th, 2017
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.88 KB | None | 0 0
  1. <?php
  2.  
  3. ##################################################################################################################
  4. ##################################################################################################################
  5. /*                 VERIFICANDO CREANDO EL COMBOBOX DE LOS TIPOS DE EXAMEN                                       */
  6. /*                 AUTOR: HENRRY JOSUE LOPEZ                                                                    */
  7. /*                 EDITADO 07/06/2017                                                                           */
  8. /*                -VALIDANDO LOS EXAMENES EMPEZADOS Y FINALIZANDO SI ES CATEDRATICO    LINEA   370              */
  9. ##################################################################################################################
  10. ##################################################################################################################
  11.  
  12.  
  13. /* For licensing terms, see /license.txt */
  14.  
  15. use ChamiloSession as Session;
  16.  
  17. /**
  18.         HOME PAGE FOR EACH COURSE
  19. *
  20. *   This page, included in every course's index.php is the home
  21. *   page. To make administration simple, the teacher edits his
  22. *   course from the home page. Only the login detects that the
  23. *   visitor is allowed to activate, deactivate home page links,
  24. *   access to the teachers tools (statistics, edit forums...).
  25. *
  26. * Edit visibility of tools
  27. *
  28. *   visibility = 1 - everybody
  29. *   visibility = 0 - course admin (teacher) and platform admin
  30. *
  31. * Who can change visibility ?
  32. *
  33. *   admin = 0 - course admin (teacher) and platform admin
  34. *   admin = 1 - platform admin
  35. *
  36. * Show message to confirm that a tools must be hide from available tools
  37. *
  38. *   visibility 0,1
  39. *
  40. *
  41. *   @package chamilo.course_home
  42. */
  43.  
  44. $use_anonymous = true;
  45.  
  46. require_once __DIR__.'/../inc/global.inc.php';
  47.  
  48. /*****************************************************************************************************************************************************/
  49. /**************************************        CODIGO TEMPORAL PARA LLENAR ENCUESTA      ************************************************************/
  50. /*****************************************************************************************************************************************************/
  51. /*
  52. $encuesta="https://docs.google.com/forms/d/e/1FAIpQLSfgP-x2yfvyjVlF3UiAL7RftVxDBtk-us_pqfee7BPaYxUzBg/viewform?c=0&w=1";
  53. //Script para verificar si hay un examen activo y redireccionar.
  54. if(api_is_allowed_to_edit()){
  55. }
  56. else{
  57.     $script_encuentas= "
  58.     <script type='text/javascript'>
  59.                 var mensaje = confirm('¡Necesitamos que llene una encuesta, presione aceptar para llenarla, cancelar para continuar en el curso!');
  60.                 if(mensaje){
  61.                     //Mostrar la encuesta
  62.                     window.location='$encuesta';
  63.                 }
  64.                 else{
  65.                 }
  66.     </script> ";
  67.     echo($script_encuentas);
  68. }
  69. */
  70. /*****************************************************************************************************************************************************/
  71. /* Ubicado en:          .../main/course_home/course_home.php                    //despues de:   require_once __DIR__.'/../inc/global.inc.php'        */
  72. /*****************************************************************************************************************************************************/
  73.  
  74.  
  75.  
  76. $htmlHeadXtra[] ='<script>
  77. /* option show/hide thematic-block */
  78. $(document).ready(function(){
  79.    $("#thematic-show").click(function(){
  80.        $(".btn-hide-thematic").hide();
  81.        $(".btn-show-thematic").show(); //show using class
  82.        $("#pross").fadeToggle(); //Not working collapse for Chrome
  83.    });
  84.    $("#thematic-hide").click(function(){
  85.        $(".btn-show-thematic").hide(); //show using class
  86.        $(".btn-hide-thematic").show();
  87.        $("#pross").fadeToggle(); //Not working collapse for Chrome
  88.    });
  89. });
  90.  
  91. $(document).ready(function() {
  92.     $(".make_visible_and_invisible").attr("href", "javascript:void(0);");
  93.     $(".make_visible_and_invisible > img").click(function () {
  94.  
  95.         make_visible = "visible.gif";
  96.         make_invisible = "invisible.gif";
  97.         path_name = $(this).attr("src");
  98.         list_path_name = path_name.split("/");
  99.         image_link = list_path_name[list_path_name.length - 1];
  100.         tool_id = $(this).attr("id");
  101.         tool_info = tool_id.split("_");
  102.         my_tool_id = tool_info[1];
  103.        $("#id_normal_message").attr("class", "normal-message alert alert-success");
  104.  
  105.         $.ajax({
  106.             contentType: "application/x-www-form-urlencoded",
  107.             beforeSend: function(objeto) {
  108.                 $(".normal-message").show();
  109.                 $("#id_confirmation_message").hide();
  110.             },
  111.             type: "GET",
  112.             url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?'.api_get_cidreq().'&a=set_visibility",
  113.             data: "id=" + my_tool_id + "&sent_http_request=1",
  114.             success: function(data) {
  115.                 eval("var info=" + data);
  116.                 new_current_tool_image = info.image;
  117.                 new_current_view       = "'.api_get_path(WEB_IMG_PATH).'" + info.view;
  118.                 //eyes
  119.                 $("#" + tool_id).attr("src", new_current_view);
  120.                 //tool
  121.                 $("#toolimage_" + my_tool_id).attr("src", new_current_tool_image);
  122.                 //clase
  123.                 $("#tooldesc_" + my_tool_id).attr("class", info.tclass);
  124.                 $("#istooldesc_" + my_tool_id).attr("class", info.tclass);
  125.  
  126.                 if (image_link == "visible.gif") {
  127.                     $("#" + tool_id).attr("alt", "'.get_lang('Activate', '').'");
  128.                     $("#" + tool_id).attr("title", "'.get_lang('Activate', '').'");
  129.                 } else {
  130.                     $("#" + tool_id).attr("alt", "'.get_lang('Deactivate', '').'");
  131.                     $("#" + tool_id).attr("title", "'.get_lang('Deactivate', '').'");
  132.                 }
  133.                 if (info.message == "is_active") {
  134.                     message = "'.get_lang('ToolIsNowVisible', '').'";
  135.                 } else {
  136.                     message = "'.get_lang('ToolIsNowHidden', '').'";
  137.                 }
  138.                 $(".normal-message").hide();
  139.                 $("#id_confirmation_message").html(message);
  140.                 $("#id_confirmation_message").show();
  141.             }
  142.         });
  143.     });
  144. });
  145.  
  146. </script>';
  147.  
  148. // The section for the tabs
  149. $this_section = SECTION_COURSES;
  150.  
  151. /*  Constants */
  152.  
  153. define('TOOL_PUBLIC', 'Public');
  154. define('TOOL_PUBLIC_BUT_HIDDEN', 'PublicButHide');
  155. define('TOOL_COURSE_ADMIN', 'courseAdmin');
  156. define('TOOL_PLATFORM_ADMIN', 'platformAdmin');
  157. define('TOOL_AUTHORING', 'toolauthoring');
  158. define('TOOL_INTERACTION', 'toolinteraction');
  159. define('TOOL_COURSE_PLUGIN', 'toolcourseplugin'); //all plugins that can be enabled in courses
  160. define('TOOL_ADMIN', 'tooladmin');
  161. define('TOOL_ADMIN_PLATFORM', 'tooladminplatform');
  162. define('TOOL_DRH', 'tool_drh');
  163. define('TOOL_STUDENT_VIEW', 'toolstudentview');
  164. define('TOOL_ADMIN_VISIBLE', 'tooladminvisible');
  165.  
  166. $user_id = api_get_user_id();
  167. $course_code = api_get_course_id();
  168. $courseId = api_get_course_int_id();
  169. $sessionId = api_get_session_id();
  170. $show_message = '';
  171.  
  172. if (api_is_invitee()) {
  173.     $isInASession = $sessionId > 0;
  174.     $isSubscribed = CourseManager::is_user_subscribed_in_course(
  175.         $user_id,
  176.         $course_code,
  177.         $isInASession,
  178.         $sessionId
  179.     );
  180.  
  181.     if (!$isSubscribed) {
  182.         api_not_allowed(true);
  183.     }
  184. }
  185.  
  186. // Deleting group session
  187. Session::erase('toolgroup');
  188. Session::erase('_gid');
  189.  
  190. $isSpecialCourse = CourseManager::isSpecialCourse($courseId);
  191.  
  192. if ($isSpecialCourse) {
  193.     if (isset($_GET['autoreg'])) {
  194.         $autoRegistration = Security::remove_XSS($_GET['autoreg']);
  195.         if ($autoRegistration == 1) {
  196.             if (CourseManager::subscribe_user($user_id, $course_code, STUDENT)) {
  197.                 Session::write('is_allowed_in_course', true);
  198.             }
  199.         }
  200.     }
  201. }
  202.  
  203. if (isset($_GET['action']) && $_GET['action'] == 'subscribe') {
  204.     if (Security::check_token('get')) {
  205.         Security::clear_token();
  206.         $auth = new Auth();
  207.         $msg = $auth->subscribe_user($course_code);
  208.         if (CourseManager::is_user_subscribed_in_course($user_id, $course_code)) {
  209.             Session::write('is_allowed_in_course', true);
  210.         }
  211.         if (!empty($msg)) {
  212.             $show_message .= Display::return_message(
  213.                 get_lang($msg['message']),
  214.                 'info',
  215.                 false
  216.             );
  217.         }
  218.     }
  219. }
  220.  
  221. /*  Is the user allowed here? */
  222. api_protect_course_script(true);
  223.  
  224. /*  STATISTICS */
  225.  
  226. if (!isset($coursesAlreadyVisited[$course_code])) {
  227.     Event::accessCourse();
  228.     $coursesAlreadyVisited[$course_code] = 1;
  229.     Session::write('coursesAlreadyVisited', $coursesAlreadyVisited);
  230. }
  231.  
  232. /*Auto launch code */
  233. $show_autolaunch_lp_warning = false;
  234. $auto_launch = api_get_course_setting('enable_lp_auto_launch');
  235. $session_id = api_get_session_id();
  236. if (!empty($auto_launch)) {
  237.     if ($auto_launch == 2) { //LP list
  238.         if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  239.             $show_autolaunch_lp_warning = true;
  240.         } else {
  241.             $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  242.             if (!isset($_SESSION[$session_key])) {
  243.                 //redirecting to the LP
  244.                 $url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?' . api_get_cidreq() . '&id_session=' . $session_id;
  245.                 $_SESSION[$session_key] = true;
  246.                 header("Location: $url");
  247.                 exit;
  248.             }
  249.         }
  250.     } else {
  251.         $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  252.         $course_id = api_get_course_int_id();
  253.         $condition = '';
  254.         if (!empty($session_id)) {
  255.             $condition =  api_get_session_condition($session_id);
  256.             $sql = "SELECT id FROM $lp_table
  257.                    WHERE c_id = $course_id AND autolaunch = 1 $condition
  258.                    LIMIT 1";
  259.             $result = Database::query($sql);
  260.             //If we found nothing in the session we just called the session_id =  0 autolaunch
  261.             if (Database::num_rows($result) ==  0) {
  262.                 $condition = '';
  263.             } else {
  264.                 //great, there is an specific auto launch for this session we leave the $condition
  265.             }
  266.         }
  267.  
  268.         $sql = "SELECT id FROM $lp_table
  269.                WHERE c_id = $course_id AND autolaunch = 1 $condition
  270.                LIMIT 1";
  271.         $result = Database::query($sql);
  272.         if (Database::num_rows($result) >  0) {
  273.             $lp_data = Database::fetch_array($result,'ASSOC');
  274.             if (!empty($lp_data['id'])) {
  275.                 if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  276.                     $show_autolaunch_lp_warning = true;
  277.                 } else {
  278.                     $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  279.                     if (!isset($_SESSION[$session_key])) {
  280.                         //redirecting to the LP
  281.                         $url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?' . api_get_cidreq() . '&action=view&lp_id=' . $lp_data['id'];
  282.  
  283.                         $_SESSION[$session_key] = true;
  284.                         header("Location: $url");
  285.                         exit;
  286.                     }
  287.                 }
  288.             }
  289.         }
  290.     }
  291. }
  292.  
  293. $forumAutoLaunch = api_get_course_setting('enable_forum_auto_launch');
  294. if ($forumAutoLaunch == 1) {
  295.     if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  296.         Display::addFlash(Display::return_message(
  297.             get_lang('TheForumAutoLaunchSettingIsOnStudentsWillBeRedirectToTheForumTool'),
  298.             'warning'
  299.         ));
  300.     } else {
  301.         //$forumKey = 'forum_auto_launch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
  302.         //if (!isset($_SESSION[$forumKey])) {
  303.             //redirecting to the LP
  304.             $url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&id_session='.$session_id;
  305.           //  $_SESSION[$forumKey] = true;
  306.             header("Location: $url");
  307.             exit;
  308.         //}
  309.     }
  310. }
  311.  
  312.  
  313. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  314. $temps = time();
  315. $reqdate = "&reqdate=$temps";
  316.  
  317. /*  MAIN CODE */
  318.  
  319. /*  Introduction section (editable by course admins) */
  320. $content = Display::return_introduction_section(
  321.     TOOL_COURSE_HOMEPAGE,
  322.     array(
  323.         'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  324.         'CreateDocumentDir' => 'document/',
  325.         'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/',
  326.     )
  327. );
  328.  
  329. /*  SWITCH TO A DIFFERENT HOMEPAGE VIEW
  330.     the setting homepage_view is adjustable through
  331.     the platform administration section */
  332.  
  333. if ($show_autolaunch_lp_warning) {
  334.     $show_message .= Display::return_message(
  335.         get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'),
  336.         'warning'
  337.     );
  338. }
  339.  
  340. if (api_get_setting('homepage_view') === 'activity' || api_get_setting('homepage_view') === 'activity_big') {
  341.     require 'activity.php';
  342. } elseif (api_get_setting('homepage_view') === '2column') {
  343.     require '2column.php';
  344. } elseif (api_get_setting('homepage_view') === '3column') {
  345.     require '3column.php';
  346. } elseif (api_get_setting('homepage_view') === 'vertical_activity') {
  347.     require 'vertical_activity.php';
  348. }
  349.  
  350. $content = '<div id="course_tools">'.$content.'</div>';
  351.  
  352. $tpl = new Template(null);
  353. $tpl->assign('message', $show_message);
  354. $tpl->assign('content', $content);
  355.  
  356. // Direct login to course
  357. $tpl->assign('course_code', $course_code);
  358.  
  359. $tpl->display_one_col_template();
  360. // Deleting the objects
  361.  
  362.  
  363. Session::erase('_gid');
  364. Session::erase('oLP');
  365. Session::erase('lpobject');
  366. api_remove_in_gradebook();
  367. DocumentManager::removeGeneratedAudioTempFile();
  368.  
  369.  
  370. ################################################################################
  371. /*INCLUYENDO LA VALIDACION DE EXAMENES EN CADA CURSO,
  372. *E INHABILITANDO LAS ENTRADAS MANIPULANDO LA URL
  373. *
  374. * Autor: HENRRY JOSUE LOPEZ LOPEZ
  375. *
  376. * 27/02/2017
  377. */
  378. ################################################################################
  379. require_once __DIR__.'/../inc/global_validacion.inc.php';
  380. $is_allowedToEdit = api_is_allowed_to_edit(null,true);
  381.  
  382.  
  383. if ($is_allowedToEdit) {
  384.     finalizar_examenes_iniciados();
  385. }else{
  386.     if (verificar_examenes_iniciados()==1) {
  387.         //echo "<script>alert('HOLA')</script>";
  388.         //$titulo_mensaje="Examen Alerta";
  389.         //$contenido_mensaje="Examen sin finalzar";
  390.         //ShowAlert($titulo_mensaje,$contenido_mensaje,);
  391.        
  392.         /*echo '<script type="text/javascript">
  393.                 $("#banner").fadeIn(1000);
  394.                 $(document).ready(function(){
  395.                     $("#btn_aceptar_dialogo").click(function(){
  396.                         $("#banner").show(300);
  397.                      });
  398.                     $("#btn_aceptar_dialogo").click(function(){
  399.                         $("#banner").fadeOut(1000);                
  400.                      });
  401.                 });
  402.             </script>';*/
  403.     }
  404.  
  405. }
  406. ################################################################################
  407. ################################################################################
  408.  
  409.  
  410. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement