dataform.class.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. /**
  8. * Init
  9. */
  10. require_once dirname(__FILE__).'/../../../inc/global.inc.php';
  11. require_once dirname(__FILE__).'/../be.inc.php';
  12. require_once dirname(__FILE__).'/../gradebook_functions.inc.php';
  13. /**
  14. * Extends formvalidator with import and export forms
  15. * @author Stijn Konings
  16. * @package chamilo.gradebook
  17. */
  18. class DataForm extends FormValidator {
  19. const TYPE_IMPORT = 1;
  20. const TYPE_EXPORT = 2;
  21. const TYPE_EXPORT_PDF = 3;
  22. /**
  23. * Builds a form containing form items based on a given parameter
  24. * @param int form_type 1=import, 2=export
  25. * @param obj cat_obj the category object
  26. * @param obj res_obj the result object
  27. * @param string form name
  28. * @param method
  29. * @param action
  30. */
  31. function DataForm($form_type, $form_name, $method = 'post', $action = null, $target='', $locked_status) {
  32. parent :: __construct($form_name, $method, $action,$target);
  33. $this->form_type = $form_type;
  34. if ($this->form_type == self :: TYPE_IMPORT) {
  35. $this->build_import_form();
  36. }
  37. elseif ($this->form_type == self :: TYPE_EXPORT) {
  38. if ($locked_status == 0) {
  39. $this->build_export_form_option(false);
  40. } else {
  41. $this->build_export_form();
  42. }
  43. }
  44. elseif ($this->form_type == self :: TYPE_EXPORT_PDF) {
  45. $this->build_pdf_export_form();
  46. }
  47. $this->setDefaults();
  48. }
  49. protected function build_pdf_export_form() {
  50. $renderer =& $this->defaultRenderer();
  51. $renderer->setElementTemplate('<span>{element}</span>');
  52. $this->addElement('header', get_lang('ChooseOrientation'));
  53. $this->addElement('radio', 'orientation', null, get_lang('Portrait'), 'portrait');
  54. $this->addElement('radio', 'orientation', null, get_lang('Landscape'), 'landscape');
  55. $this->addElement('style_submit_button', 'submit', get_lang('Export'), 'class="upload"');
  56. $this->setDefaults(array (
  57. 'orientation' => 'portrait'
  58. ));
  59. }
  60. protected function build_export_form() {
  61. $this->addElement('header', get_lang('ChooseFormat'));
  62. $this->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV (Comma-Separated Values)', 'csv');
  63. $this->addElement('radio', 'file_type', null, 'XML (Extensible Markup Language)', 'xml');
  64. $this->addElement('radio', 'file_type', null, 'PDF (Portable Document Format)', 'pdf');
  65. $this->addElement('style_submit_button', 'submit', get_lang('Export'), 'class="upload"');
  66. $this->setDefaults(array (
  67. 'file_type' => 'csv'
  68. ));
  69. }
  70. protected function build_export_form_option($show_pdf=true) {
  71. $this->addElement('header', get_lang('ChooseFormat'));
  72. $this->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV (Comma-Separated Values)', 'csv');
  73. $this->addElement('radio', 'file_type', null, 'XML (Extensible Markup Language)', 'xml');
  74. $this->addElement('radio', 'file_type', Display::return_icon('info3.gif',get_lang('ToExportMustLockEvaluation')), 'PDF (Portable Document Format)', 'pdf', array('disabled'));
  75. $this->addElement('style_submit_button', 'submit', get_lang('Export'), 'class="upload"');
  76. $this->setDefaults(array (
  77. 'file_type' => 'csv'
  78. ));
  79. }
  80. protected function build_import_form() {
  81. $this->addElement('hidden', 'formSent');
  82. $this->addElement('header', get_lang('ImportFileLocation'));
  83. $this->addElement('file', 'import_file',get_lang('Location'));
  84. $allowed_file_types = array (
  85. 'xml',
  86. 'csv'
  87. );
  88. //$this->addRule('file', get_lang('InvalidExtension') . ' (' . implode(',', $allowed_file_types) . ')', 'filetype', $allowed_file_types);
  89. $this->addElement('radio', 'file_type', get_lang('FileType'), 'CSV (<a href="docs/example_csv.html" target="_blank">' . get_lang('ExampleCSVFile') . '</a>)', 'csv');
  90. $this->addElement('radio', 'file_type', null, 'XML (<a href="docs/example_xml.html" target="_blank">' . get_lang('ExampleXMLFile') . '</a>)', 'xml');
  91. $this->addElement('checkbox','overwrite', null,get_lang('OverwriteScores'));
  92. $this->addElement('checkbox','ignoreerrors',null,get_lang('IgnoreErrors'));
  93. $this->addElement('style_submit_button', 'submit', get_lang('Ok'));
  94. $this->setDefaults(array(
  95. 'formSent' => '1',
  96. 'file_type' => 'csv'
  97. ));
  98. }
  99. function display() {
  100. parent :: display();
  101. }
  102. function setDefaults($defaults = array(), $filter = null) {
  103. parent :: setDefaults($defaults, $filter);
  104. }
  105. }