exportgradebook.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos Latinoamerica SAC
  6. Copyright (c) 2006 Dokeos SPRL
  7. Copyright (c) 2006 Ghent University (UGent)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. * Prints an HTML page with a table containing the gradebook data
  22. * @param array Array containing the data to be printed in the table
  23. * @param array Table headers
  24. * @param string View to print as a title for the table
  25. * @param string Course name to print as title for the table
  26. */
  27. function print_table ($data_array,$header_names,$view,$coursename) {
  28. $printdata= '<!DOCTYPE html
  29. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  30. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  31. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  32. <head>
  33. <title>'.get_lang('Print').'</title>
  34. <style type="text/css">
  35. body {
  36. font-size: 12px;
  37. color: #000;
  38. margin: 10px;
  39. padding: 0;
  40. }
  41. a:link {text-decoration: none; font-weight : bold; color : black;}
  42. a:visited {text-decoration: none; font-weight : bold; color : black;}
  43. a:active {text-decoration: none; font-weight : bold; color : black;}
  44. .data_table{
  45. border-collapse: collapse;
  46. width: 100%;
  47. padding: 5px;
  48. border: 1px;
  49. }
  50. .data_table th{
  51. padding: 5px;
  52. vertical-align: top;
  53. border-top: 1px solid black;
  54. border-bottom: 1px solid black;
  55. border-right: 1px solid black;
  56. border-left: 1px solid black;
  57. }
  58. .data_table tr.row_odd{
  59. background-color: #fafafa;
  60. }
  61. .data_table tr.row_even{
  62. background-color: #fff;
  63. }
  64. .data_table td{
  65. padding: 5px;
  66. vertical-align: top;
  67. border-bottom: 1px solid black;
  68. border-right: 1px solid black;
  69. border-left: 1px solid black;
  70. }
  71. </style>
  72. </head>
  73. <body><div id="main">';
  74. $printdata .= '<h2>'.$view.' : '.$coursename.'</h2>';
  75. $printdata .= '<h3>'.get_lang('Date').' : '.date('j/n/Y g:i').'</h3>';
  76. $printdata .= '<table border="1" width="90%" cellspacing="1" cellpadding="1">';
  77. foreach ($header_names as $header) {
  78. $printdata .= '<th>'.$header.'</th>';
  79. }
  80. foreach ($data_array as $data) {
  81. $printdata .= '<tr>';
  82. foreach ($data as $rowdata) {
  83. $printdata .= '<td>'.$rowdata.'</td>';
  84. }
  85. $printdata .= '</tr>';
  86. }
  87. $printdata .= '</table></div></body></html>';
  88. return $printdata;
  89. }
  90. /**
  91. * Exports the data as a table on a PDF page
  92. * @param resource The PDF object (ezpdf class) used to generate the file
  93. * @param array The data array
  94. * @param array Table headers
  95. * @param string Format (portrait or landscape)
  96. */
  97. function export_pdf($pdf,$newarray,$header_names,$format) {
  98. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  99. $pdf->ezSetCmMargins(0,0,0,0);
  100. $pdf->ezSetY(($format=='portrait')?'820':'570');
  101. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  102. $pdf->ezText(get_lang('FlatView').' ('. date('j/n/Y g:i') .')',12,array('justification'=>'center'));
  103. if ($format=='portrait') {
  104. $pdf->line(40,790,540,790);
  105. $pdf->line(40,40,540,40);
  106. } else {
  107. $pdf->line(40,540,790,540);
  108. $pdf->line(40,40,790,40);
  109. }
  110. $pdf->ezSetY(($format=='portrait')?'750':'520');
  111. $pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=>(($format=='portrait')?'500':'750')));
  112. $pdf->ezStream();
  113. }