Advertisement
H_Josue

gradebook_flatview

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