upload_file_form.class.php 2.2 KB

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