PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/fsn-site-central/application/Form/Fsn/Import.php

https://gitlab.com/team_fsn/fsn-php
PHP | 226 lines | 159 code | 27 blank | 40 comment | 5 complexity | 014e1b676547d2e96251bd2eff271bd2 MD5 | raw file
  1. <?php
  2. class Form_Fsn_Import extends Yab_Form {
  3. public function __construct(Model_Fsn_Historique $fsn_historique) {
  4. $registry = Yab_Loader::getInstance() -> getRegistry();
  5. // $request = Yab_Loader::getInstance()->getRequest() ;
  6. // appel fichier internationalisation
  7. $i18n = $registry -> get('i18n');
  8. // gestion des accentuations / date / ....
  9. $session = Yab_Loader::getInstance()->getSession();
  10. $session->set('format','%d/%m/%Y') ;
  11. $filter_html = new Yab_Filter_NoHtml();
  12. $db = Yab_Loader::getInstance() -> getRegistry() -> get('db');
  13. $user_info = $session -> get('session');
  14. $login = $user_info['login'];
  15. $entiteadmin_id = !empty($user_info['entiteadmin_id']) ? $user_info['entiteadmin_id'] : 1 ; // jfb 2016-04-22
  16. $date = date('d/m/Y H:i:s');
  17. $action = 'import';
  18. $post_html = '';
  19. $this -> set('method', 'post') -> set('action', '') -> set('name', 'FormFreeRequest') -> set('id', 'FormFreeRequest') -> set('role', 'form') -> set('class', 'form-horizontal');
  20. /* module fonctiopnnel - */
  21. $list_modules = $db -> prepare('
  22. SELECT
  23. categorie_key,
  24. categorie_value
  25. FROM fsn_categorie
  26. WHERE categorie_type = "categorie_object"
  27. AND categorie_key NOT IN ("categorie_object", "categorie_type")
  28. AND visible = 1
  29. ORDER BY ordre
  30. ') -> setKey('categorie_key') -> setValue('categorie_value');
  31. $this -> setElement('module', array(
  32. 'type' => 'select',
  33. 'id' => 'module',
  34. 'label' => $filter_html->filter( $i18n -> say('module') ),
  35. 'placeholder' => $filter_html->filter( $i18n -> say('module') ),
  36. 'value' => $fsn_historique -> has('module') ? $fsn_historique -> get('module') : null,
  37. 'options' => array(
  38. // jfb 2016-04-22 début
  39. 'association_er' => 'Association élément recueilli',
  40. 'fai_us' => 'Association FAI / US',
  41. 'conteneur' => 'Conteneur',
  42. 'contour_fai' => 'Contour FAI',
  43. 'contour_sitefouille' => 'Contour site de fouille',
  44. 'contour_us' => 'Contour US',
  45. 'elementrecueilli' => 'Elément recueilli',
  46. 'emplacement' => 'Emplacement',
  47. 'fai' => 'Fait archéologique',
  48. 'inclusion' => 'Inclusion des US',
  49. 'intervenant' => 'Intervenant',
  50. 'intervention_us' => 'Intervention',
  51. 'interfait' => 'Lien inter FAI',
  52. 'oa' => 'Opération archéologique',
  53. 'fsn_organisme' => 'Organisme',
  54. 'participation' => 'Participation',
  55. 'phasechrono' => 'Phase chronologique',
  56. 'fsn_categorie' => 'Référence',
  57. 'fsn_categorie_relation' => 'Relation entre références',
  58. 'sitefouille' => 'Site de fouille',
  59. 'superposition' => 'Superposition des US',
  60. 'synchronisation' => 'Synchronisation des US',
  61. 'traitement' => 'Traitement élément recueilli',
  62. 'us' => 'Unité Stratigraphique'
  63. //'fsn_entiteadmin' => 'Entité administrative',
  64. // jfb 2016-04-22 fin
  65. ),
  66. // 'options' => $list_modules,
  67. 'fake_options' => array('' => '-- ' . $i18n -> say('make_a_choice') . ' un module ', ),
  68. 'tooltip' => '',
  69. //'onchange' => 'submit();',
  70. //'validators' => array('NotEmpty'),
  71. 'errors' => array(),
  72. ));
  73. /* Choix du module fonctionnel - pr�alable */
  74. if (!$this -> getElement('module') -> getValue()) {
  75. $upload_max_filesize = ini_get('upload_max_filesize');
  76. $tooltip = 'importfile_tooltip';
  77. $this -> setElement('importfile', array(
  78. 'type' => 'file',
  79. 'label' => $filter_html->filter( $i18n -> say('importfile')),
  80. 'placeholder' => $filter_html->filter( $i18n -> say('importfile')),
  81. 'id' => 'importfile',
  82. 'tooltip' => $filter_html->filter( $i18n -> say($tooltip, array($upload_max_filesize)) ),
  83. 'value' => $fsn_historique -> has('importfile') ? $fsn_historique -> get('importfile') : null,
  84. 'validators' => array(
  85. 'Upload' => array(
  86. 'destination' => dirname(YAB_PATH) . DIRECTORY_SEPARATOR . 'tmp',
  87. 'override' => true),
  88. ),
  89. ));
  90. return $this;
  91. } else {
  92. $module = $this -> getElement('module') -> getValue();
  93. // $post_html .= '<label class="col-lg-2 control-label" for="'.$module.'"></label>';
  94. // $post_html .= '<div class="col-lg-9">';
  95. // $post_html .= '<div class="alert alert-warning" >';
  96. // $post_html .= $i18n->say('importfile_'.$module);
  97. // $post_html .= '</div></div>';
  98. // $post_html = '<div style="margin:0 5%; padding: 5px ; background-color: #FFEEC7; ">'.$i18n->say('importfile_'.$module).'</div>' ;
  99. $this -> getElement('module') -> set('type', 'text') -> set('readonly', 'readonly') -> rem('tooltip') -> set('post_html', $post_html);
  100. }
  101. $upload_max_filesize = ini_get('upload_max_filesize');
  102. $tooltip = 'importfile_tooltip';
  103. $this -> setElement('importfile', array(
  104. 'type' => 'file',
  105. 'label' => $filter_html->filter( $i18n -> say('importfile')),
  106. 'placeholder' => $filter_html->filter( $i18n -> say('importfile')),
  107. 'id' => 'importfile',
  108. 'tooltip' => $filter_html->filter( $i18n -> say($tooltip, array($upload_max_filesize)) ),
  109. 'value' => $fsn_historique -> has('importfile') ? $fsn_historique -> get('importfile') : null,
  110. 'validators' => array(
  111. 'Upload' => array(
  112. 'destination' => dirname(YAB_PATH) . DIRECTORY_SEPARATOR . 'tmp',
  113. 'override' => true),
  114. ),
  115. ));
  116. /* Chargement du fichier - pr�alable �tape 2
  117. if (!$this->getElement('importfile')->getValue()) {
  118. return $this ;
  119. } else {
  120. $importfile = $this->getElement('importfile')->getValue() ;
  121. $this->getElement('importfile')->set('type', 'text')->set('readonly', 'readonly');
  122. }
  123. */
  124. $this -> setElement('firstlineheader', array(
  125. 'type' => 'checkbox',
  126. 'label' => $filter_html->filter( $i18n -> say('firstlineheader')),
  127. 'placeholder' => $filter_html->filter( $i18n -> say('firstlineheader')),
  128. 'class' => 'text-justify',
  129. 'value' => $fsn_historique -> has('firstlineheader') ? $fsn_historique -> get('firstlineheader') : 1,
  130. 'needed' => false,
  131. ));
  132. $this -> setElement('type_action', array(
  133. 'type' => 'text',
  134. 'label' => $filter_html->filter( $i18n -> say('type_action')),
  135. 'placeholder' => $filter_html->filter( $i18n -> say('type_action')),
  136. 'value' => $fsn_historique -> has('type_action') ? $fsn_historique -> get('type_action') : $action,
  137. 'validators' => array('NotEmpty'),
  138. 'readonly' => 'readonly',
  139. 'errors' => array(),
  140. ));
  141. $this -> setElement('date_historique', array(
  142. 'type' => 'text',
  143. 'label' => $filter_html->filter( $i18n -> say('date_historique')),
  144. 'placeholder' => $filter_html->filter( $i18n -> say('date_historique')),
  145. 'value' => $fsn_historique -> has('date_historique') ? $fsn_historique -> get('date_historique', 'Date') : $date,
  146. 'validators' => array('NotEmpty'),
  147. 'readonly' => 'readonly',
  148. 'errors' => array(),
  149. ));
  150. $this -> setElement('login', array(
  151. 'type' => 'text',
  152. 'label' => $filter_html->filter( $i18n -> say('login')),
  153. 'placeholder' => $filter_html->filter( $i18n -> say('login')),
  154. 'value' => $fsn_historique -> has('login') ? $fsn_historique -> get('login') : $login,
  155. 'validators' => array('NotEmpty'),
  156. 'readonly' => 'readonly',
  157. 'errors' => array(),
  158. ));
  159. /*
  160. $this->setElement('data_modify', array(
  161. 'type' => 'hidden',
  162. 'label' => 'data_modify',
  163. 'rows' => '10',
  164. 'value' => $fsn_historique->has('data_modify') ? $fsn_historique->get('data_modify') : 'No info',
  165. 'validators' => array('NotEmpty'),
  166. 'readonly' => 'readonly',
  167. 'errors' => array(),
  168. ));
  169. */
  170. $this -> setElement('description', array(
  171. 'type' => 'textarea',
  172. 'rows' => '3',
  173. 'label' => $i18n -> say('description'),
  174. 'placeholder' => $i18n -> say('description'),
  175. 'rows' => '5',
  176. 'value' => $fsn_historique -> has('description') ? $fsn_historique -> get('description') : null,
  177. ));
  178. // jfb 2016-04-22 début
  179. $this->setElement('entiteadmin', array(
  180. 'type' => 'text',
  181. 'label' => $filter_html->filter( $i18n -> say('entiteadmin_id')),
  182. 'placeholder' => $filter_html->filter( $i18n -> say('entiteadmin_id')),
  183. 'value' => $fsn_historique -> has('entiteadmin_id') ? $fsn_historique -> get('entiteadmin_id') : $entiteadmin_id,
  184. 'validators' => array('NotEmpty'),
  185. 'readonly' => 'readonly',
  186. 'errors' => array(),
  187. ));
  188. // jfb 2016-04-22 fin
  189. /* Personnalisation des champs suivant le module */
  190. foreach ($this->getElements() as $element) {
  191. if ($element -> get('name') == 'module' && $fsn_historique -> has('module')) {
  192. $element -> set('type', 'text');
  193. $element -> set('readonly', 'readonly');
  194. }
  195. }
  196. }
  197. }