kevin2458

gradebook_flatview.php

Jul 23rd, 2017
146
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3.  
  4. /**
  5.  * Script
  6.  * @package chamilo.gradebook
  7.  */
  8.  
  9. $num_row_table=isset($_GET['flatviewlist_per_page']) ? 36 : 0;
  10. if ($num_row_table==0) {
  11.     $data_send="&flatviewlist_per_page=36";
  12.     echo "<script>
  13.            var UrlActual = window.location;
  14.            location.href =UrlActual+'".$data_send."';
  15.            window.close();
  16.        </script>";    
  17.     exit();
  18. }
  19.  
  20. require_once '../inc/global.inc.php';
  21. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/fe/exportgradebook.php';
  22.  
  23. $current_course_tool  = TOOL_GRADEBOOK;
  24.  
  25. api_protect_course_script(true);
  26.  
  27. api_block_anonymous_users();
  28. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  29.     api_get_user_id(),
  30.     api_get_course_info()
  31. );
  32.  
  33. if (!$isDrhOfCourse) {
  34.     GradebookUtils::block_students();
  35. }
  36.  
  37. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  38.     header('Location: '.api_get_self().'?selectcat='.intval($_GET['selectcat']).'&search='.Security::remove_XSS($_POST['keyword']));
  39.     exit;
  40. }
  41.  
  42. $interbreadcrumb[] = array(
  43.     'url' => $_SESSION['gradebook_dest'].'?selectcat=1',
  44.     'name' => get_lang('ToolGradebook')
  45. );
  46.  
  47. $showeval = isset($_POST['showeval']) ? '1' : '0';
  48. $showlink = isset($_POST['showlink']) ? '1' : '0';
  49. if (($showlink == '0') && ($showeval == '0')) {
  50.     $showlink = '1';
  51.     $showeval = '1';
  52. }
  53.  
  54. $cat = Category::load($_REQUEST['selectcat']);
  55.  
  56. if (isset($_GET['userid'])) {
  57.     $userid = Security::remove_XSS($_GET['userid']);
  58. } else {
  59.     $userid = '';
  60. }
  61.  
  62. if ($showeval) {
  63.     $alleval = $cat[0]->get_evaluations($userid, true);
  64. } else {
  65.     $alleval = null;
  66. }
  67.  
  68. if ($showlink) {
  69.     $alllinks = $cat[0]->get_links($userid, true);
  70. } else {
  71.     $alllinks = null;
  72. }
  73.  
  74. if (isset($export_flatview_form) && (!$file_type == 'pdf')) {
  75.     Display :: display_normal_message($export_flatview_form->toHtml(), false);
  76. }
  77.  
  78. if (isset($_GET['selectcat'])) {
  79.     $category_id = (int) $_GET['selectcat'];
  80. } else {
  81.     $category_id = '';
  82. }
  83.  
  84. $simple_search_form = new UserForm(
  85.     UserForm :: TYPE_SIMPLE_SEARCH,
  86.     null,
  87.     'simple_search_form',
  88.     null,
  89.     api_get_self() . '?selectcat=' . $category_id
  90. );
  91. $values = $simple_search_form->exportValues();
  92.  
  93. $keyword = '';
  94. if (isset($_GET['search']) && !empty($_GET['search'])) {
  95.     $keyword = Security::remove_XSS($_GET['search']);
  96. }
  97. if ($simple_search_form->validate() && (empty($keyword))) {
  98.     $keyword = $values['keyword'];
  99. }
  100.  
  101. if (!empty($keyword)) {
  102.     $users = GradebookUtils::find_students($keyword);
  103. } else {
  104.     if (isset($alleval) && isset($alllinks)) {
  105.         $users = GradebookUtils::get_all_users($alleval, $alllinks);
  106.     } else {
  107.         $users = null;
  108.     }
  109. }
  110. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  111.  
  112. $addparams = array('selectcat' => $cat[0]->get_id());
  113. if (isset($_GET['search'])) {
  114.     $addparams['search'] = $keyword;
  115. }
  116.  
  117. // Main course category
  118. $mainCourseCategory = Category::load(
  119.     null,
  120.     null,
  121.     api_get_course_id(),
  122.     null,
  123.     null,
  124.     api_get_session_id()
  125. );
  126.  
  127. $flatviewtable = new FlatViewTable(
  128.     $cat[0],
  129.     $users,
  130.     $alleval,
  131.     $alllinks,
  132.     true,
  133.     $offset,
  134.     $addparams,
  135.     $mainCourseCategory[0]
  136. );
  137.  
  138. $flatviewtable->setAutoFill(false);
  139.  
  140. $parameters = array('selectcat' => intval($_GET['selectcat']));
  141. $flatviewtable->set_additional_parameters($parameters);
  142.  
  143. $params = array();
  144. if (isset($_GET['export_pdf']) && $_GET['export_pdf'] == 'category') {
  145.     $params['only_total_category'] = true;
  146.     $params['join_firstname_lastname'] = true;
  147.     $params['show_official_code'] = true;
  148.     $params['export_pdf'] = true;
  149.     if ($cat[0]->is_locked() == true || api_is_platform_admin()) {
  150.         Display :: set_header(null, false, false);
  151.         GradebookUtils::export_pdf_flatview(
  152.             $flatviewtable,
  153.             $cat,
  154.             $users,
  155.             $alleval,
  156.             $alllinks,
  157.             $params,
  158.             $mainCourseCategory[0]
  159.         );
  160.     }
  161. }
  162.  
  163. if (isset($_GET['exportpdf']))  {
  164.     $interbreadcrumb[] = array (
  165.         'url' => api_get_self().'?selectcat=' . Security::remove_XSS($_GET['selectcat']).'&'.api_get_cidreq(),
  166.         'name' => get_lang('FlatView')
  167.     );
  168.  
  169.     $pageNum = isset($_GET['flatviewlist_page_nr']) ? intval($_GET['flatviewlist_page_nr']) : null;
  170.     $perPage = isset($_GET['flatviewlist_per_page']) ? intval($_GET['flatviewlist_per_page']) : null;
  171.     $url = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
  172.         'exportpdf' => '',
  173.         'offset' => $offset,
  174.         'selectcat' => intval($_GET['selectcat']),
  175.         'flatviewlist_page_nr' => $pageNum,
  176.         'flatviewlist_per_page' => $perPage
  177.     ]);
  178.  
  179.     $export_pdf_form = new DataForm(
  180.         DataForm::TYPE_EXPORT_PDF,
  181.         'export_pdf_form',
  182.         null,
  183.         $url,
  184.         '_blank',
  185.         ''
  186.     );
  187.  
  188.     if ($export_pdf_form->validate()) {
  189.         $params = $export_pdf_form->exportValues();
  190.         Display :: set_header(null, false, false);
  191.         $params['join_firstname_lastname'] = true;
  192.         $params['show_official_code'] = true;
  193.         $params['export_pdf'] = true;
  194.         $params['only_total_category'] = false;
  195.         GradebookUtils::export_pdf_flatview(
  196.             $flatviewtable,
  197.             $cat,
  198.             $users,
  199.             $alleval,
  200.             $alllinks,
  201.             $params,
  202.             $mainCourseCategory[0]
  203.         );
  204.  
  205.     } else {
  206.         Display :: display_header(get_lang('ExportPDF'));
  207.     }
  208. }
  209.  
  210. if (isset($_GET['print']))  {
  211.     $printable_data = GradebookUtils::get_printable_data(
  212.         $cat[0],
  213.         $users,
  214.         $alleval,
  215.         $alllinks,
  216.         $params,
  217.         $mainCourseCategory[0]
  218.     );
  219.     echo print_table(
  220.         $printable_data[1],
  221.         $printable_data[0],
  222.         get_lang('FlatView'),
  223.         $cat[0]->get_name()
  224.     );
  225.     exit;
  226. }
  227.  
  228. if (!empty($_GET['export_report']) &&
  229.     $_GET['export_report'] == 'export_report'
  230. ) {
  231.     if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach() || $isDrhOfCourse) {
  232.         $user_id = null;
  233.  
  234.         if (empty($_SESSION['export_user_fields'])) {
  235.             $_SESSION['export_user_fields'] = false;
  236.         }
  237.         if (!api_is_allowed_to_edit(false, false) and !api_is_course_tutor()) {
  238.             $user_id = api_get_user_id();
  239.         }
  240.         $printable_data = GradebookUtils::get_printable_data(
  241.             $cat[0],
  242.             $users,
  243.             $alleval,
  244.             $alllinks,
  245.             $params,
  246.             $mainCourseCategory[0]
  247.         );
  248.  
  249.         switch ($_GET['export_format']) {
  250.             case 'xls':
  251.                 ob_start();
  252.                 $export = new GradeBookResult();
  253.                 $export->exportCompleteReportXLS($printable_data);
  254.                 $content = ob_get_contents();
  255.                 ob_end_clean();
  256.                 echo $content;
  257.                 break;
  258.             case 'doc':
  259.                 ob_start();
  260.                 $export = new GradeBookResult();
  261.                 $export->exportCompleteReportDOC($printable_data);
  262.                 $content = ob_get_contents();
  263.                 ob_end_clean();
  264.                 echo $content;
  265.                 break;
  266.             case 'csv':
  267.             default:
  268.                 ob_start();
  269.                 $export = new GradeBookResult();
  270.                 $export->exportCompleteReportCSV($printable_data);
  271.                 $content = ob_get_contents();
  272.                 ob_end_clean();
  273.                 echo $content;
  274.                 exit;
  275.                 break;
  276.         }
  277.     } else {
  278.         api_not_allowed(true);
  279.     }
  280. }
  281.  
  282. $this_section = SECTION_COURSES;
  283.  
  284. if (isset($_GET['exportpdf'])) {
  285.     $export_pdf_form->display();
  286. } else {
  287.     Display :: display_header(get_lang('FlatView'));
  288. }
  289.  
  290. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
  291.     DisplayGradebook:: display_header_reduce_flatview(
  292.         $cat[0],
  293.         $showeval,
  294.         $showlink,
  295.         $simple_search_form
  296.     );
  297.     $flatviewtable->display();
  298. } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) {
  299.  
  300.     DisplayGradebook:: display_header_reduce_flatview(
  301.         $cat[0],
  302.         $showeval,
  303.         $showlink,
  304.         $simple_search_form
  305.     );
  306.  
  307.     // Table
  308.     $flatviewtable->display();
  309.     //@todo load images with jquery
  310.     echo '<div id="contentArea" style="text-align: center;" >';
  311.     $flatviewtable->display_graph_by_resource();
  312.     echo '</div>';
  313. }
  314.  
  315. Display :: display_footer();
  316. ?>
  317. <script type="text/javascript">
  318.     //Henrry Josue Lopez
  319.     /*
  320.     var show_10_element=document.getElementsByTagName('option')[0];
  321.     var show_20_element=document.getElementsByTagName('option')[1];
  322.     var show_30_element=document.getElementsByTagName('option')[2];
  323.  
  324.     var show_all_element=document.getElementsByTagName('option')[3];
  325.    
  326.     //$(element3).addSelected('selected');
  327.    
  328.     if (document.getElementsByName("flatviewlist_per_page")[0].value=="20") {
  329.         $(show_all_element).attr('selected','selected');
  330.         $(show_20_element).removeAttr('selected');
  331.         document.getElementsByName("flatviewlist_per_page")[0].onchange();
  332.     }*/
  333.    
  334. </script>
RAW Paste Data