dataform.class.php 3.9 KB

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