dataform.class.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 __construct($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(
  68. 'radio',
  69. 'file_type',
  70. Display::return_icon('info3.gif', get_lang('ToExportMustLockEvaluation')),
  71. 'PDF (Portable Document Format)',
  72. 'pdf',
  73. array('disabled')
  74. );
  75. $this->addButtonExport(get_lang('Export'));
  76. $this->setDefaults(array(
  77. 'file_type' => 'csv'
  78. ));
  79. }
  80. protected function build_import_form()
  81. {
  82. $this->addElement('hidden', 'formSent');
  83. $this->addElement('header', get_lang('ImportFileLocation'));
  84. $this->addElement('file', 'import_file', get_lang('Location'));
  85. $allowed_file_types = array(
  86. 'xml',
  87. 'csv'
  88. );
  89. //$this->addRule('file', get_lang('InvalidExtension') . ' (' . implode(',', $allowed_file_types) . ')', 'filetype', $allowed_file_types);
  90. $this->addElement('radio', 'file_type', get_lang('FileType'), 'CSV (<a href="docs/example_csv.html" target="_blank">'.get_lang('ExampleCSVFile').'</a>)', 'csv');
  91. $this->addElement('radio', 'file_type', null, 'XML (<a href="docs/example_xml.html" target="_blank">'.get_lang('ExampleXMLFile').'</a>)', 'xml');
  92. $this->addElement('checkbox', 'overwrite', null, get_lang('OverwriteScores'));
  93. $this->addElement('checkbox', 'ignoreerrors', null, get_lang('IgnoreErrors'));
  94. $this->addButtonImport(get_lang('Ok'));
  95. $this->setDefaults(array(
  96. 'formSent' => '1',
  97. 'file_type' => 'csv'
  98. ));
  99. }
  100. public function display()
  101. {
  102. parent::display();
  103. }
  104. public function setDefaults($defaults = array(), $filter = null)
  105. {
  106. parent::setDefaults($defaults, $filter);
  107. }
  108. }