upload_file_form.class.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Link upload file form class definition
  5. * @package chamilo.link
  6. */
  7. /**
  8. * Init
  9. */
  10. namespace Link;
  11. use Chamilo;
  12. /**
  13. * Form to upload a file.
  14. *
  15. * @license /licence.txt
  16. * @author Laurent Opprecht <laurent@opprecht.info>
  17. */
  18. class UploadFileForm extends \FormValidator
  19. {
  20. function __construct($form_name = 'upload_file', $method = 'post', $action = '', $target = '', $attributes = null, $track_submit = true)
  21. {
  22. parent::__construct($form_name, $method, $action, $target, $attributes, $track_submit);
  23. }
  24. /**
  25. *
  26. *
  27. */
  28. function init()
  29. {
  30. $form_name = get_lang('UploadFile');
  31. $this->add_header($form_name);
  32. $label = get_lang('File');
  33. $this->add_file('file', $label);
  34. $this->addRule('file', get_lang('ThisFieldIsRequired'), 'required');
  35. //$this->add_checkbox('replace', '', get_lang('ReplaceExistingEntries'));
  36. $this->add_button('save', get_lang('Save'), array('class' => 'btn save'));
  37. $label = get_lang('CSVMustLookLike');
  38. $label = "<h4>$label</h4>";
  39. $help = '<pre>
  40. <strong>"url"</strong>;"title";"description";"target";"category_title";"category_description"
  41. "http://chamilo.org";"Chamilo";"";"_self";"";""
  42. "http://google.com";"Google";"";"_self";"Google";""
  43. "http://mail.google.com";"Google";"";"_self";"Google";""
  44. </pre>';
  45. $this->add_html($label . $help);
  46. }
  47. /**
  48. *
  49. * @return array
  50. */
  51. public function get_file()
  52. {
  53. $result = Request::file('file', array());
  54. if (empty($result)) {
  55. return array();
  56. }
  57. $error = isset($result['error']) ? (bool) $result['error'] : false;
  58. if ($error) {
  59. return array();
  60. }
  61. return $result;
  62. }
  63. public function validate()
  64. {
  65. $result = (bool) parent::validate();
  66. if ($result == false) {
  67. return false;
  68. }
  69. $file = $this->get_file();
  70. if (empty($file)) {
  71. return false;
  72. }
  73. return true;
  74. }
  75. // public function get_update_existing_entries(){
  76. // return (bool)$this->exportValue('replace');
  77. // }
  78. }