upload_file_form.class.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. }