PageRenderTime 61ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/view/mteForm.class.php

https://github.com/pabloeuy/motte
PHP | 817 lines | 359 code | 70 blank | 388 comment | 31 complexity | 9711a15e699928a4d5acc23a2dacdb92 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. *
  4. *
  5. * @filesource
  6. * @package motte
  7. * @subpackage view
  8. * @version 1.0
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public license
  10. * @author Pedro Gauna (pgauna@gmail.com)
  11. * Carlos Gagliardi (carlosgag@gmail.com)
  12. * GBoksar/Perro (gustavo@boksar.info)
  13. * Mauro Dodero (maurodo@gmail.com)
  14. * Pablo Erartes (pabloeuy@gmail.com)
  15. *
  16. */
  17. class mteForm extends mteTemplate{
  18. /**
  19. *
  20. * @access private
  21. * @var array
  22. */
  23. private $_fields;
  24. /**
  25. *
  26. * @access private
  27. * @var array
  28. */
  29. private $_templates;
  30. /**
  31. *
  32. * @access private
  33. * @var array
  34. */
  35. private $_dirTemplates;
  36. /**
  37. *
  38. * @access public
  39. */
  40. public function __construct($compileDir, $templateDir = '', $template = ''){
  41. parent:: __construct($compileDir, $templateDir, $template);
  42. $this->setUrlPost();
  43. $this->_clearFields();
  44. $this->_clearTemplates();
  45. $this->needConfirmation(false);
  46. }
  47. /**
  48. * Destructor
  49. *
  50. * @access public
  51. */
  52. public function __destruct(){
  53. }
  54. /**
  55. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  56. * P R O P E R T I E S
  57. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  58. */
  59. /**
  60. * Setea el titulo para el formulario
  61. * @param string $value
  62. * @access public
  63. */
  64. public function setTitle($value = ''){
  65. $this->setVar('TITLE', $value);
  66. }
  67. /**
  68. *
  69. * @param string $value
  70. * @access public
  71. */
  72. public function needConfirmation($value = false){
  73. $this->setVar('CONFIRMATION', $value);
  74. }
  75. /**
  76. *
  77. * @param string $value
  78. * @access public
  79. */
  80. public function confirmationMsg($value = ''){
  81. $this->setVar('CONFIRMATION_MSG', $value);
  82. }
  83. /**
  84. * Setea el subtitulo para el formulario
  85. *
  86. * @param string $value
  87. * @access public
  88. */
  89. public function setSubtitle($value = ''){
  90. $this->setVar('SUBTITLE', $value);
  91. }
  92. /**
  93. * Setea el nombre para el formulario
  94. *
  95. * @param string $value
  96. * @access public
  97. */
  98. public function setName($value = 'mteForm_'){
  99. $this->setVar('NAME', $value);
  100. }
  101. /**
  102. * Setea el la url para el post
  103. *
  104. * @param string $value
  105. * @access public
  106. */
  107. public function setUrlPost($value = '#'){
  108. $this->setVar('POST', $value);
  109. }
  110. /**
  111. * Setea el link para cerrar el formulario
  112. *
  113. * @param string $value
  114. * @access public
  115. */
  116. public function setUrlClose($value = ''){
  117. $this->setVar('CLOSE', $value);
  118. $this->setVar('CLOSETAG', __('Close'));
  119. }
  120. /**
  121. * Coloca un mensaje de aviso
  122. *
  123. * @param string $value
  124. * @access public
  125. */
  126. public function setNotify($value = ''){
  127. if(!empty($value)){
  128. $this->setVar('NOTIFY', $value);
  129. }
  130. }
  131. /**
  132. * Coloca un mensaje de alerta
  133. *
  134. * @param string $value
  135. * @access public
  136. */
  137. public function setWarning($value = ''){
  138. if(!empty($value)){
  139. $this->setVar('WARNING', $value);
  140. }
  141. }
  142. /**
  143. * Coloca un mensaje de leyenda
  144. *
  145. * @param string $value
  146. * @access public
  147. */
  148. public function setLegend($value = ''){
  149. if(!empty($value)){
  150. $this->setVar('LEGEND', $value);
  151. }
  152. }
  153. /**
  154. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  155. * T E M P L A T E M A N A G E M E N T M E T H O D S
  156. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  157. */
  158. /**
  159. *
  160. * @access private
  161. */
  162. private function _clearTemplates(){
  163. $this->setTemplateField(mteConst::MTE_FIELD_TEXT, MTE_TEMPLATE, 'mteFormText.html');
  164. $this->setTemplateField(mteConst::MTE_FIELD_NUMBER, MTE_TEMPLATE, 'mteFormNumber.html');
  165. $this->setTemplateField(mteConst::MTE_FIELD_TEXTAREA, MTE_TEMPLATE, 'mteFormTextArea.html');
  166. $this->setTemplateField(mteConst::MTE_FIELD_CHECKBOX, MTE_TEMPLATE, 'mteFormCheckBox.html');
  167. $this->setTemplateField(mteConst::MTE_FIELD_SELECT, MTE_TEMPLATE, 'mteFormSelect.html');
  168. $this->setTemplateField(mteConst::MTE_FIELD_MULTISELECT, MTE_TEMPLATE, 'mteFormTMultiSelect.html');
  169. $this->setTemplateField(mteConst::MTE_FIELD_FILE, MTE_TEMPLATE, 'mteFormFile.html');
  170. $this->setTemplateField(mteConst::MTE_FIELD_IMAGE, MTE_TEMPLATE, 'mteFormImage.html');
  171. $this->setTemplateField(mteConst::MTE_FIELD_HIDDEN, MTE_TEMPLATE, 'mteFormHidden.html');
  172. $this->setTemplateField(mteConst::MTE_FIELD_PASSWORD, MTE_TEMPLATE, 'mteFormPassword.html');
  173. $this->setTemplateField(mteConst::MTE_FIELD_SUBMIT, MTE_TEMPLATE, 'mteFormSubmit.html');
  174. $this->setTemplateField(mteConst::MTE_FIELD_DATE, MTE_TEMPLATE, 'mteFormDate.html');
  175. $this->setTemplateField(mteConst::MTE_FIELD_TIME, MTE_TEMPLATE, 'mteFormTime.html');
  176. $this->setTemplateField(mteConst::MTE_FIELD_CODE, MTE_TEMPLATE, 'mteFormCode.html');
  177. $this->setTemplateField(mteConst::MTE_FIELD_SUBTITLE, MTE_TEMPLATE, 'mteFormSubtitle.html');
  178. $this->setTemplateField(mteConst::MTE_FIELD_CAPTCHATEXT, MTE_TEMPLATE, 'mteFormCaptchaText.html');
  179. $this->setTemplateField(mteConst::MTE_FIELD_DESCRIPTION, MTE_TEMPLATE, 'mteFormDescription.html');
  180. }
  181. /**
  182. *
  183. * @access public
  184. * @param string $fieldType
  185. * @param string $template
  186. */
  187. public function setTemplateField($fieldType, $dirTemplate = '', $template = ''){
  188. $this->_templates[$fieldType] = $template;
  189. $this->_dirTemplates[$fieldType] = $dirTemplate;
  190. }
  191. /**
  192. *
  193. * @access public
  194. * @param string $fieldType
  195. * @return string
  196. */
  197. public function getTemplateField($fieldType){
  198. return $this->_templates[$fieldType];
  199. }
  200. /**
  201. *
  202. * @access public
  203. * @param string $fieldType
  204. * @return string
  205. */
  206. public function getDirTemplateField($fieldType){
  207. return $this->_dirTemplates[$fieldType];
  208. }
  209. /**
  210. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  211. * F I E L D M A N A G E M E N T M E T H O D S
  212. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  213. */
  214. /**
  215. *
  216. * @access private
  217. * @param string $name
  218. * @param object $field
  219. */
  220. private function _addField($name, $field){
  221. $this->_fields[$name] = $field;
  222. }
  223. /**
  224. *
  225. * @access private
  226. */
  227. private function _clearFields(){
  228. $this->_fields = array();
  229. }
  230. /**
  231. *
  232. * @access public
  233. * @param string $name
  234. */
  235. public function removeFormField($name){
  236. unset($this->_fields[$name]);
  237. }
  238. /**
  239. * Add field text
  240. * @access public
  241. *
  242. * @param <type> $name
  243. * @param <type> $title
  244. * @param <type> $value
  245. * @param <type> $size
  246. * @param <type> $max
  247. * @param <type> $validate
  248. * @param <type> $readOnly
  249. * @param <type> $help
  250. */
  251. public function addFieldText($name, $title = '', $value = '', $size = 30, $max = 100, $validate = 0, $readOnly = 0, $help = ''){
  252. if (!empty($name)){
  253. $field = new mteFormField(mteConst::MTE_FIELD_TEXT, $this->getCompileDir());
  254. $field->setName($name);
  255. $field->setTitle((empty($title))?$name:$title);
  256. $field->setValue($value);
  257. $field->setSize($size);
  258. $field->setMaxSize($max);
  259. $field->setHaveConstrains($validate);
  260. $field->setHelp($help);
  261. $field->setIsReadOnly($readOnly);
  262. $this->_addField($name, $field);
  263. }
  264. }
  265. /**
  266. *
  267. * @access public
  268. *
  269. * @param <type> $title
  270. * @param <type> $value
  271. * @param <type> $size
  272. * @param <type> $max
  273. * @param <type> $help
  274. */
  275. public function addFieldCaptchaText($title = '', $value = '', $size = 30, $max = 100, $help = ''){
  276. $field = new mteFormField(mteConst::MTE_FIELD_CAPTCHATEXT, $this->getCompileDir());
  277. $field->setName('captchaText');
  278. $field->setTitle((empty($title))?'2 + 2 =':$title);
  279. $field->setValue((empty($value))?'cuatro:4':$value);
  280. $field->setSize($size);
  281. $field->setMaxSize($max);
  282. $field->setHaveConstrains(true);
  283. $field->setHelp($help);
  284. $field->setIsReadOnly(false);
  285. $this->_addField('captchatext', $field);
  286. }
  287. /**
  288. *
  289. *
  290. * @access public
  291. * @param <type> $name
  292. * @param <type> $title
  293. * @param <type> $value
  294. * @param <type> $size
  295. * @param <type> $max
  296. * @param <type> $validate
  297. * @param <type> $readOnly
  298. * @param <type> $help
  299. */
  300. public function addFieldDate($name, $title = '', $value = '', $size = 30, $max = 100, $validate = 0, $readOnly = 0, $help = '', $format = ''){
  301. if (!empty($name)){
  302. $field = new mteFormField(mteConst::MTE_FIELD_DATE, $this->getCompileDir());
  303. $field->setName($name);
  304. $field->setTitle((empty($title))?$name:$title);
  305. $field->setValue($value);
  306. $field->setSpecialProperties('START_YEAR', !empty($startYear)?$startYear:1930);
  307. $field->setSpecialProperties('END_YEAR', !empty($startYear)?$startYear:date('Y') + 1);
  308. $field->setSize($size);
  309. $field->setMaxSize($max);
  310. $field->setHaveConstrains($validate);
  311. $field->setHelp($help);
  312. $field->setIsReadOnly($readOnly);
  313. $field->setFormat( ($format == '')?MTE_DATE_FORMAT:$format );
  314. $this->_addField($name, $field);
  315. }
  316. }
  317. /**
  318. *
  319. *
  320. * @access public
  321. * @param <type> $name
  322. * @param <type> $title
  323. * @param <type> $value
  324. * @param <type> $size
  325. * @param <type> $max
  326. * @param <type> $validate
  327. * @param <type> $readOnly
  328. * @param <type> $help
  329. */
  330. public function addFieldTime($name, $title = '', $value = '', $size = 30, $max = 100, $validate = 0, $readOnly = 0, $help = ''){
  331. if (!empty($name)){
  332. $field = new mteFormField(mteConst::MTE_FIELD_TIME, $this->getCompileDir());
  333. $field->setName($name);
  334. $field->setTitle((empty($title))?$name:$title);
  335. $field->setValue($value);
  336. $field->setSize($size);
  337. $field->setMaxSize($max);
  338. $field->setHaveConstrains($validate);
  339. $field->setHelp($help);
  340. $field->setIsReadOnly($readOnly);
  341. $this->_addField($name, $field);
  342. }
  343. }
  344. /**
  345. *
  346. *
  347. * @access public
  348. * @param <type> $name
  349. * @param <type> $title
  350. * @param <type> $value
  351. * @param <type> $size
  352. * @param <type> $max
  353. * @param <type> $validate
  354. * @param <type> $readOnly
  355. * @param <type> $help
  356. */
  357. public function addFieldCode($name, $title = '', $value = '', $valueSearch = '', $size = 30, $max = 100, $validate = 0, $readOnly = 0, $help = ''){
  358. if (!empty($name)){
  359. $field = new mteFormField(mteConst::MTE_FIELD_CODE, $this->getCompileDir());
  360. $field->setName($name);
  361. $field->setTitle((empty($title))?$name:$title);
  362. $field->setValue($value);
  363. $field->setSpecialProperties('VALUE_SEARCH', $valueSearch);
  364. $field->setSize($size);
  365. $field->setMaxSize($max);
  366. $field->setHaveConstrains($validate);
  367. $field->setHelp($help);
  368. $field->setIsReadOnly($readOnly);
  369. $this->_addField($name, $field);
  370. }
  371. }
  372. /**
  373. *
  374. *
  375. * @access public
  376. * @param <type> $name
  377. * @param <type> $title
  378. * @param <type> $value
  379. * @param <type> $size
  380. * @param <type> $max
  381. * @param <type> $validate
  382. * @param <type> $readOnly
  383. * @param <type> $help
  384. */
  385. public function addFieldPassword($name, $title = '', $value = '', $size = 30, $max = 100, $validate = 0, $readOnly = 0, $help = ''){
  386. if (!empty($name)){
  387. $field = new mteFormField(mteConst::MTE_FIELD_PASSWORD, $this->getCompileDir());
  388. $field->setName($name);
  389. $field->setTitle((empty($title))?$name:$title);
  390. $field->setValue($value);
  391. $field->setSize($size);
  392. $field->setMaxSize($max);
  393. $field->setHaveConstrains($validate);
  394. $field->setHelp($help);
  395. $field->setIsReadOnly($readOnly);
  396. $this->_addField($name, $field);
  397. }
  398. }
  399. /**
  400. *
  401. *
  402. * @access public
  403. * @param <type> $name
  404. * @param <type> $title
  405. * @param <type> $value
  406. * @param <type> $size
  407. * @param <type> $max
  408. * @param <type> $validate
  409. * @param <type> $readOnly
  410. * @param <type> $help
  411. */
  412. public function addFieldNumber($name, $title = '', $value = '', $size = 30, $max = 100, $validate = 0, $readOnly = 0, $help = ''){
  413. if (!empty($name)){
  414. $field = new mteFormField(mteConst::MTE_FIELD_NUMBER, $this->getCompileDir());
  415. $field->setName($name);
  416. $field->setTitle((empty($title))?$name:$title);
  417. $field->setValue($value);
  418. $field->setSize($size);
  419. $field->setMaxSize($max);
  420. $field->setHaveConstrains($validate);
  421. $field->setHelp($help);
  422. $field->setIsReadOnly($readOnly);
  423. $this->_addField($name, $field);
  424. }
  425. }
  426. /**
  427. *
  428. *
  429. * @access public
  430. * @param <type> $name
  431. * @param <type> $title
  432. * @param <type> $value
  433. * @param <type> $cols
  434. * @param <type> $rows
  435. * @param <type> $validate
  436. * @param <type> $readOnly
  437. * @param <type> $help
  438. */
  439. public function addFieldTextArea($name, $title = '', $value = '', $cols = 30, $rows = 3, $validate = 0, $readOnly = 0, $help = ''){
  440. if (!empty($name)){
  441. $field = new mteFormField(mteConst::MTE_FIELD_TEXTAREA, $this->getCompileDir());
  442. $field->setName($name);
  443. $field->setTitle((empty($title))?$name:$title);
  444. $field->setValue($value);
  445. $field->setHaveConstrains($validate);
  446. $field->setHelp($help);
  447. $field->setIsReadOnly($readOnly);
  448. $field->setSpecialProperties('COLS', $cols);
  449. $field->setSpecialProperties('ROWS', $rows);
  450. $this->_addField($name, $field);
  451. }
  452. }
  453. /**
  454. *
  455. *
  456. * @access public
  457. * @param <type> $name
  458. * @param <type> $title
  459. * @param <type> $checked
  460. * @param <type> $labelChecked
  461. * @param <type> $labelUnChecked
  462. * @param <type> $readOnly
  463. * @param <type> $help
  464. */
  465. public function addFieldCheckBox($name, $title = '', $checked = '0', $labelChecked = 1, $labelUnChecked = 0, $readOnly = 0, $help = ''){
  466. if (!empty($name)){
  467. $field = new mteFormField(mteConst::MTE_FIELD_CHECKBOX, $this->getCompileDir());
  468. $field->setName($name);
  469. $field->setValue($checked);
  470. $field->setTitle((empty($title))?$name:$title);
  471. $field->setIsReadOnly($readOnly);
  472. $field->setHelp($help);
  473. $field->setSpecialProperties('LABEL_CHECKED', $labelChecked);
  474. $field->setSpecialProperties('LABEL_UNCHECKED', $labelUnChecked);
  475. $this->_addField($name, $field);
  476. }
  477. }
  478. /**
  479. *
  480. *
  481. * @access public
  482. * @param <type> $name
  483. * @param <type> $title
  484. * @param <type> $value
  485. * @param <type> $options
  486. * @param <type> $readOnly
  487. * @param <type> $help
  488. */
  489. public function addFieldSelect($name, $title = '', $value = '', $options = '', $readOnly = 0, $help = ''){
  490. if (!empty($name)){
  491. $field = new mteFormField(mteConst::MTE_FIELD_SELECT, $this->getCompileDir());
  492. $field->setName($name);
  493. $field->setTitle((empty($title))?$name:$title);
  494. $field->setValue($value);
  495. $field->setOptions($options);
  496. $field->setHelp($help);
  497. $field->setIsReadOnly($readOnly);
  498. $this->_addField($name, $field);
  499. }
  500. }
  501. /**
  502. *
  503. *
  504. * @access public
  505. * @param <type> $name
  506. * @param <type> $title
  507. * @param <type> $value
  508. * @param <type> $options
  509. * @param <type> $size
  510. * @param <type> $readOnly
  511. * @param <type> $help
  512. */
  513. public function addFieldMultiSelect($name, $title = '', $value = '', $options = '', $size = 4, $readOnly = 0, $help = ''){
  514. if (!empty($name)){
  515. $field = new mteFormField(mteConst::MTE_FIELD_MULTSELECT, $this->getCompileDir());
  516. $field->setName($name);
  517. $field->setTitle((empty($title))?$name:$title);
  518. $field->setValue($value);
  519. $field->setOptions($options);
  520. $field->setSize($size);
  521. $field->setMaxSize($max);
  522. $field->setHelp($help);
  523. $field->setIsReadOnly($readOnly);
  524. $this->_addField($name, $field);
  525. }
  526. }
  527. /**
  528. *
  529. *
  530. * @access public
  531. * @param <type> $name
  532. * @param <type> $title
  533. * @param <type> $value
  534. * @param <type> $maxKb
  535. * @param <type> $size
  536. * @param <type> $validate
  537. * @param <type> $readOnly
  538. * @param <type> $help
  539. */
  540. public function addFieldFile($name, $title = '', $value = '', $maxKb = 0, $size = '50', $validate = 0, $readOnly = 0, $help = ''){
  541. if (!empty($name)){
  542. $field = new mteFormField(mteConst::MTE_FIELD_FILE, $this->getCompileDir());
  543. $field->setName($name);
  544. $field->setTitle((empty($title))?$name:$title);
  545. $field->setSize($size);
  546. $field->setMaxSize((!empty($maxKb))?$maxKb:mteConst::MTE_MAX_SIZE * 1024);
  547. $field->setHaveConstrains($validate);
  548. $field->setHelp($help);
  549. $field->setIsReadOnly($readOnly);
  550. $field->setSpecialProperties('URL', $value);
  551. $field->setSpecialProperties('FILE_NAME', (!empty($value))?substr($value, strrpos($value, '/') + 1, strlen($value)):'');
  552. $this->_addField($name, $field);
  553. }
  554. }
  555. /**
  556. *
  557. *
  558. * @access public
  559. * @param <type> $name
  560. * @param <type> $title
  561. * @param <type> $thumb
  562. * @param <type> $maxKb
  563. * @param <type> $size
  564. * @param <type> $validate
  565. * @param <type> $readOnly
  566. * @param <type> $help
  567. */
  568. public function addFieldImage($name, $title = '', $thumb = '', $maxKb = 0, $size = '10', $validate = 0, $readOnly = 0, $help = ''){
  569. if (!empty($name)){
  570. $field = new mteFormField(mteConst::MTE_FIELD_IMAGE, $this->getCompileDir());
  571. $field->setName($name);
  572. $field->setTitle((empty($title))?$name:$title);
  573. $field->setValue($thumb);
  574. $field->setSize($size);
  575. $field->setMaxSize((!empty($maxKb))?$maxKb:mteConst::MTE_MAX_SIZE * 1024);
  576. $field->setHelp($help);
  577. $field->setIsReadOnly($readOnly);
  578. $this->_addField($name, $field);
  579. }
  580. }
  581. /**
  582. *
  583. *
  584. * @access public
  585. * @param string $name
  586. * @param string $value = ''
  587. */
  588. public function addFieldHidden($name, $value = ''){
  589. if (!empty($name)){
  590. $field = new mteFormField(mteConst::MTE_FIELD_HIDDEN, $this->getCompileDir());
  591. $field->setName($name);
  592. $field->setValue($value);
  593. $this->_addField($name, $field);
  594. }
  595. }
  596. /**
  597. *
  598. *
  599. * @access public
  600. * @param string $name
  601. * @param string $value = ''
  602. */
  603. public function addFieldSubtitle($name, $value = ''){
  604. if (!empty($name)){
  605. $field = new mteFormField(mteConst::MTE_FIELD_SUBTITLE, $this->getCompileDir());
  606. $field->setName($name);
  607. $field->setValue($value);
  608. $this->_addField($name, $field);
  609. }
  610. }
  611. /**
  612. *
  613. *
  614. * @access public
  615. * @param <type> $name
  616. * @param <type> $value
  617. */
  618. public function addFieldDescription($name, $value = ''){
  619. if (!empty($name)){
  620. $field = new mteFormField(mteConst::MTE_FIELD_DESCRIPTION, $this->getCompileDir());
  621. $field->setName($name);
  622. $field->setValue($value);
  623. $this->_addField($name, $field);
  624. }
  625. }
  626. /**
  627. *
  628. *
  629. * @access public
  630. * @param string $name = ''
  631. * @param string $title = ''
  632. * @param string $help = ''
  633. */
  634. public function addFieldSubmit($name = '', $title = '', $help = ''){
  635. if (!empty($name)){
  636. $field = new mteFormField(mteConst::MTE_FIELD_SUBMIT, $this->getCompileDir());
  637. $field->setName($name);
  638. $field->setHelp($help);
  639. $field->setTitle((empty($title))?$name:$title);
  640. $this->_addField($name, $field);
  641. }
  642. }
  643. /**
  644. *
  645. *
  646. * @param string $fieldName
  647. * @param variant $value
  648. */
  649. private function setFieldData($fieldName, $value = ''){
  650. if (array_key_exists($fieldName, $this->_fields)) {
  651. if (method_exists($this->_fields[$fieldName],'setValue')){
  652. $this->_fields[$fieldName]->setValue($value);
  653. }
  654. }
  655. }
  656. /**
  657. *
  658. *
  659. * @param string $fieldName
  660. * @param boolean $value
  661. */
  662. public function setFieldIsReadOnly($fieldName, $value = 0){
  663. if (array_key_exists($fieldName, $this->_fields)) {
  664. if (method_exists($this->_fields[$fieldName],'setIsReadOnly')){
  665. $this->_fields[$fieldName]->setIsReadOnly($value);
  666. }
  667. }
  668. }
  669. /**
  670. *
  671. *
  672. * @param string $fieldName
  673. * @param array $value
  674. */
  675. private function setFieldOptions($fieldName, $value = ''){
  676. if (array_key_exists($fieldName, $this->_fields)) {
  677. if (method_exists($this->_fields[$fieldName],'setOptions')){
  678. $this->_fields[$fieldName]->setOptions($value);
  679. }
  680. }
  681. }
  682. /**
  683. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  684. * F O R M M A N A G E M E N T M E T H O D S
  685. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  686. */
  687. /**
  688. *
  689. *
  690. * @param boolean $value
  691. */
  692. public function setIsReadOnly($value = 0){
  693. foreach ($this->_fields as $name => $field){
  694. $this->setFieldIsReadOnly($name, $value);
  695. }
  696. }
  697. /**
  698. *
  699. *
  700. * @param array $data
  701. */
  702. public function setFormData($data){
  703. if (is_array($data)){
  704. foreach ($this->_fields as $fieldName => $field){
  705. if (array_key_exists($fieldName, $data)){
  706. $this->setFieldData($fieldName, $data[$fieldName]);
  707. }
  708. }
  709. }
  710. }
  711. /**
  712. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  713. * G U I M E T H O D S
  714. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  715. */
  716. /**
  717. *
  718. *
  719. * @access public
  720. * @return string
  721. */
  722. public function fetchHtmlFields(){
  723. $htmlFields = '';
  724. foreach ($this->_fields as $fieldName => $field){
  725. if (method_exists($this->_fields[$fieldName],'fetchHtml')){
  726. $this->_fields[$fieldName]->setTemplateDir($this->getDirTemplateField($this->_fields[$fieldName]->getType()));
  727. $this->_fields[$fieldName]->setTemplate($this->getTemplateField($this->_fields[$fieldName]->getType()));
  728. $htmlFields .= $this->_fields[$fieldName]->fetchHtml();
  729. }
  730. }
  731. return $htmlFields;
  732. }
  733. /**
  734. *
  735. * @access public
  736. * @return string
  737. */
  738. public function fetchHtml(){
  739. if ($this->getTemplate() == ''){
  740. $this->setTemplateDir(MTE_TEMPLATE);
  741. $this->setTemplate('mteForm.html');
  742. }
  743. $this->setVar('FIELDS', $this->fetchHtmlFields());
  744. return $this->getHtml();
  745. }
  746. }
  747. ?>