dataform.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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(
  23. $form_type,
  24. $form_name,
  25. $method = 'post',
  26. $action = null,
  27. $target = '',
  28. $locked_status
  29. ) {
  30. parent:: __construct($form_name, $method, $action, $target);
  31. $this->form_type = $form_type;
  32. if ($this->form_type == self::TYPE_IMPORT) {
  33. $this->build_import_form();
  34. } elseif ($this->form_type == self::TYPE_EXPORT) {
  35. if ($locked_status == 0) {
  36. $this->build_export_form_option(false);
  37. } else {
  38. $this->build_export_form();
  39. }
  40. } elseif ($this->form_type == self::TYPE_EXPORT_PDF) {
  41. $this->build_pdf_export_form();
  42. }
  43. $this->setDefaults();
  44. }
  45. protected function build_pdf_export_form()
  46. {
  47. $renderer = & $this->defaultRenderer();
  48. $renderer->setCustomElementTemplate('<span>{element}</span>');
  49. $this->addElement('header', get_lang('ChooseOrientation'));
  50. $this->addElement('radio', 'orientation', null, get_lang('Portrait'), 'portrait');
  51. $this->addElement('radio', 'orientation', null, get_lang('Landscape'), 'landscape');
  52. $this->addButtonExport(get_lang('Export'));
  53. $this->setDefaults(array(
  54. 'orientation' => 'portrait'
  55. ));
  56. }
  57. protected function build_export_form()
  58. {
  59. $this->addElement('header', get_lang('ChooseFormat'));
  60. $this->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV (Comma-Separated Values)', 'csv');
  61. $this->addElement('radio', 'file_type', null, 'XML (Extensible Markup Language)', 'xml');
  62. $this->addElement('radio', 'file_type', null, 'PDF (Portable Document Format)', 'pdf');
  63. $this->addButtonExport(get_lang('Export'));
  64. $this->setDefaults(array(
  65. 'file_type' => 'csv'
  66. ));
  67. }
  68. protected function build_export_form_option($show_pdf = true)
  69. {
  70. $this->addElement('header', get_lang('ChooseFormat'));
  71. $this->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV (Comma-Separated Values)', 'csv');
  72. $this->addElement('radio', 'file_type', null, 'XML (Extensible Markup Language)', 'xml');
  73. $this->addElement(
  74. 'radio',
  75. 'file_type',
  76. Display::return_icon('info3.gif', get_lang('ToExportMustLockEvaluation')),
  77. 'PDF (Portable Document Format)',
  78. 'pdf',
  79. array('disabled')
  80. );
  81. $this->addButtonExport(get_lang('Export'));
  82. $this->setDefaults(array(
  83. 'file_type' => 'csv'
  84. ));
  85. }
  86. protected function build_import_form()
  87. {
  88. $this->addElement('hidden', 'formSent');
  89. $this->addElement('header', get_lang('ImportFileLocation'));
  90. $this->addElement('file', 'import_file', get_lang('Location'));
  91. $allowed_file_types = array(
  92. 'xml',
  93. 'csv'
  94. );
  95. //$this->addRule('file', get_lang('InvalidExtension') . ' (' . implode(',', $allowed_file_types) . ')', 'filetype', $allowed_file_types);
  96. $this->addElement('radio', 'file_type', get_lang('FileType'), 'CSV (<a href="docs/example_csv.html" target="_blank">'.get_lang('ExampleCSVFile').'</a>)', 'csv');
  97. $this->addElement('radio', 'file_type', null, 'XML (<a href="docs/example_xml.html" target="_blank">'.get_lang('ExampleXMLFile').'</a>)', 'xml');
  98. $this->addElement('checkbox', 'overwrite', null, get_lang('OverwriteScores'));
  99. $this->addElement('checkbox', 'ignoreerrors', null, get_lang('IgnoreErrors'));
  100. $this->addButtonImport(get_lang('Ok'));
  101. $this->setDefaults(array(
  102. 'formSent' => '1',
  103. 'file_type' => 'csv'
  104. ));
  105. }
  106. public function display()
  107. {
  108. parent::display();
  109. }
  110. public function setDefaults($defaults = array(), $filter = null)
  111. {
  112. parent::setDefaults($defaults, $filter);
  113. }
  114. }