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

/horde-3.3.13/lib/Horde/Form.php

#
PHP | 4908 lines | 3112 code | 652 blank | 1144 comment | 469 complexity | f4355879d9388b0d21ca68251e904d7e MD5 | raw file
Possible License(s): LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * @package Horde_Form
  4. */
  5. /** String */
  6. include_once 'Horde/String.php';
  7. /**
  8. * Horde_Form Master Class.
  9. *
  10. * The Horde_Form:: package provides form rendering, validation, and
  11. * other functionality for the Horde Application Framework.
  12. *
  13. * $Horde: framework/Form/Form.php,v 1.306.2.81 2012/02/03 15:17:31 jan Exp $
  14. *
  15. * Copyright 2001-2007 Robert E. Coyle <robertecoyle@hotmail.com>
  16. * Copyright 2001-2009 The Horde Project (http://www.horde.org/)
  17. *
  18. * See the enclosed file COPYING for license information (LGPL). If you
  19. * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  20. *
  21. * @author Robert E. Coyle <robertecoyle@hotmail.com>
  22. * @author Chuck Hagenbuch <chuck@horde.org>
  23. * @since Horde 3.0
  24. * @package Horde_Form
  25. */
  26. class Horde_Form {
  27. var $_name = '';
  28. var $_title = '';
  29. var $_extra = '';
  30. var $_vars;
  31. var $_submit = array();
  32. var $_reset = false;
  33. var $_errors = array();
  34. var $_submitted = null;
  35. var $_sections = array();
  36. var $_open_section = null;
  37. var $_currentSection = array();
  38. var $_variables = array();
  39. var $_hiddenVariables = array();
  40. var $_useFormToken = true;
  41. var $_autofilled = false;
  42. var $_enctype = null;
  43. var $_help = false;
  44. function Horde_Form(&$vars, $title = '', $name = null)
  45. {
  46. if (empty($name)) {
  47. $name = String::lower(get_class($this));
  48. }
  49. $this->_vars = &$vars;
  50. $this->_title = $title;
  51. $this->_name = $name;
  52. }
  53. function __construct($vars, $title = '', $name = null)
  54. {
  55. $this->Horde_Form($vars, $title, $name);
  56. }
  57. function &singleton($form, &$vars, $title = '', $name = null)
  58. {
  59. static $instances = array();
  60. $signature = serialize(array($form, $vars, $title, $name));
  61. if (!isset($instances[$signature])) {
  62. if (class_exists($form)) {
  63. $instances[$signature] = new $form($vars, $title, $name);
  64. } else {
  65. $instances[$signature] = new Horde_Form($vars, $title, $name);
  66. }
  67. }
  68. return $instances[$signature];
  69. }
  70. function setVars(&$vars)
  71. {
  72. $this->_vars = &$vars;
  73. }
  74. function getTitle()
  75. {
  76. return $this->_title;
  77. }
  78. function setTitle($title)
  79. {
  80. $this->_title = $title;
  81. }
  82. function getExtra()
  83. {
  84. return $this->_extra;
  85. }
  86. function setExtra($extra)
  87. {
  88. $this->_extra = $extra;
  89. }
  90. function getName()
  91. {
  92. return $this->_name;
  93. }
  94. /**
  95. * Sets or gets whether the form should be verified by tokens.
  96. * Tokens are used to verify that a form is only submitted once.
  97. *
  98. * @param boolean $token If specified, sets whether to use form tokens.
  99. *
  100. * @return boolean Whether form tokens are being used.
  101. */
  102. function useToken($token = null)
  103. {
  104. if (!is_null($token)) {
  105. $this->_useFormToken = $token;
  106. }
  107. return $this->_useFormToken;
  108. }
  109. /**
  110. * Get the renderer for this form, either a custom renderer or the
  111. * standard one.
  112. *
  113. * To use a custom form renderer, your form class needs to
  114. * override this function:
  115. * <code>
  116. * function &getRenderer()
  117. * {
  118. * $r = new CustomFormRenderer();
  119. * return $r;
  120. * }
  121. * </code>
  122. *
  123. * ... where CustomFormRenderer is the classname of the custom
  124. * renderer class, which should extend Horde_Form_Renderer.
  125. *
  126. * @param array $params A hash of renderer-specific parameters.
  127. *
  128. * @return object Horde_Form_Renderer The form renderer.
  129. */
  130. function &getRenderer($params = array())
  131. {
  132. require_once 'Horde/Form/Renderer.php';
  133. $renderer = new Horde_Form_Renderer($params);
  134. return $renderer;
  135. }
  136. function &getType($type, $params = array())
  137. {
  138. $type_class = 'Horde_Form_Type_' . $type;
  139. if (!class_exists($type_class)) {
  140. require_once 'PEAR.php';
  141. Horde::fatal(PEAR::raiseError(sprintf('Nonexistant class "%s" for field type "%s"', $type_class, $type)), __FILE__, __LINE__);
  142. }
  143. $type_ob = new $type_class();
  144. if (!$params) {
  145. $params = array();
  146. }
  147. call_user_func_array(array(&$type_ob, 'init'), $params);
  148. return $type_ob;
  149. }
  150. function setSection($section = '', $desc = '', $image = '', $expanded = true)
  151. {
  152. $this->_currentSection = $section;
  153. if (!count($this->_sections) && !$this->getOpenSection()) {
  154. $this->setOpenSection($section);
  155. }
  156. $this->_sections[$section]['desc'] = $desc;
  157. $this->_sections[$section]['expanded'] = $expanded;
  158. $this->_sections[$section]['image'] = $image;
  159. }
  160. function getSectionDesc($section)
  161. {
  162. return $this->_sections[$section]['desc'];
  163. }
  164. function getSectionImage($section)
  165. {
  166. return $this->_sections[$section]['image'];
  167. }
  168. function setOpenSection($section)
  169. {
  170. $this->_vars->set('__formOpenSection', $section);
  171. }
  172. function getOpenSection()
  173. {
  174. return $this->_vars->get('__formOpenSection');
  175. }
  176. function getSectionExpandedState($section, $boolean = false)
  177. {
  178. if ($boolean) {
  179. /* Only the boolean value is required. */
  180. return $this->_sections[$section]['expanded'];
  181. }
  182. /* Need to return the values for use in styles. */
  183. if ($this->_sections[$section]['expanded']) {
  184. return 'block';
  185. } else {
  186. return 'none';
  187. }
  188. }
  189. /**
  190. * TODO
  191. */
  192. function &addVariable($humanName, $varName, $type, $required,
  193. $readonly = false, $description = null,
  194. $params = array())
  195. {
  196. return $this->insertVariableBefore(null, $humanName, $varName, $type,
  197. $required, $readonly, $description,
  198. $params);
  199. }
  200. /**
  201. * TODO
  202. */
  203. function &insertVariableBefore($before, $humanName, $varName, $type,
  204. $required, $readonly = false,
  205. $description = null, $params = array())
  206. {
  207. $type = &$this->getType($type, $params);
  208. $var = new Horde_Form_Variable($humanName, $varName, $type,
  209. $required, $readonly, $description);
  210. /* Set the form object reference in the var. */
  211. $var->setFormOb($this);
  212. if ($var->getTypeName() == 'enum' &&
  213. !strlen($type->getPrompt()) &&
  214. count($var->getValues()) == 1) {
  215. $vals = array_keys($var->getValues());
  216. $this->_vars->add($var->varName, $vals[0]);
  217. $var->_autofilled = true;
  218. } elseif ($var->getTypeName() == 'file' ||
  219. $var->getTypeName() == 'image') {
  220. $this->_enctype = 'multipart/form-data';
  221. }
  222. if (empty($this->_currentSection)) {
  223. $this->_currentSection = '__base';
  224. }
  225. if (is_null($before)) {
  226. $this->_variables[$this->_currentSection][] = &$var;
  227. } else {
  228. $num = 0;
  229. while (isset($this->_variables[$this->_currentSection][$num]) &&
  230. $this->_variables[$this->_currentSection][$num]->getVarName() != $before) {
  231. $num++;
  232. }
  233. if (!isset($this->_variables[$this->_currentSection][$num])) {
  234. $this->_variables[$this->_currentSection][] = &$var;
  235. } else {
  236. $this->_variables[$this->_currentSection] = array_merge(
  237. array_slice($this->_variables[$this->_currentSection], 0, $num),
  238. array(&$var),
  239. array_slice($this->_variables[$this->_currentSection], $num));
  240. }
  241. }
  242. return $var;
  243. }
  244. /**
  245. * Removes a variable from the form.
  246. *
  247. * As only variables can be passed by reference, you need to call this
  248. * method this way if want to pass a variable name:
  249. * <code>
  250. * $form->removeVariable($var = 'varname');
  251. * </code>
  252. *
  253. * @param Horde_Form_Variable|string $var Either the variable's name or
  254. * the variable to remove from the
  255. * form.
  256. *
  257. * @return boolean True if the variable was found (and deleted).
  258. */
  259. function removeVariable(&$var)
  260. {
  261. foreach (array_keys($this->_variables) as $section) {
  262. foreach (array_keys($this->_variables[$section]) as $i) {
  263. if ((is_a($var, 'Horde_Form_Variable') && $this->_variables[$section][$i] === $var) ||
  264. ($this->_variables[$section][$i]->getVarName() == $var)) {
  265. // Slice out the variable to be removed.
  266. $this->_variables[$this->_currentSection] = array_merge(
  267. array_slice($this->_variables[$this->_currentSection], 0, $i),
  268. array_slice($this->_variables[$this->_currentSection], $i + 1));
  269. return true;
  270. }
  271. }
  272. }
  273. return false;
  274. }
  275. /**
  276. * TODO
  277. */
  278. function &addHidden($humanName, $varName, $type, $required,
  279. $readonly = false, $description = null,
  280. $params = array())
  281. {
  282. $type = &$this->getType($type, $params);
  283. $var = new Horde_Form_Variable($humanName, $varName, $type,
  284. $required, $readonly, $description);
  285. $var->hide();
  286. $this->_hiddenVariables[] = &$var;
  287. return $var;
  288. }
  289. function &getVariables($flat = true, $withHidden = false)
  290. {
  291. if ($flat) {
  292. $vars = array();
  293. foreach ($this->_variables as $section) {
  294. foreach ($section as $var) {
  295. $vars[] = $var;
  296. }
  297. }
  298. if ($withHidden) {
  299. foreach ($this->_hiddenVariables as $var) {
  300. $vars[] = $var;
  301. }
  302. }
  303. return $vars;
  304. } else {
  305. return $this->_variables;
  306. }
  307. }
  308. function setButtons($submit, $reset = false)
  309. {
  310. if ($submit === true || is_null($submit) || empty($submit)) {
  311. /* Default to 'Submit'. */
  312. $submit = array(_("Submit"));
  313. } elseif (!is_array($submit)) {
  314. /* Default to array if not passed. */
  315. $submit = array($submit);
  316. }
  317. /* Only if $reset is strictly true insert default 'Reset'. */
  318. if ($reset === true) {
  319. $reset = _("Reset");
  320. }
  321. $this->_submit = $submit;
  322. $this->_reset = $reset;
  323. }
  324. function appendButtons($submit)
  325. {
  326. if (!is_array($submit)) {
  327. $submit = array($submit);
  328. }
  329. $this->_submit = array_merge($this->_submit, $submit);
  330. }
  331. function preserveVarByPost(&$vars, $varname, $alt_varname = '')
  332. {
  333. $value = $vars->getExists($varname, $wasset);
  334. /* If an alternate name is given under which to preserve use that. */
  335. if ($alt_varname) {
  336. $varname = $alt_varname;
  337. }
  338. if ($wasset) {
  339. $this->_preserveVarByPost($varname, $value);
  340. }
  341. }
  342. /**
  343. * @access private
  344. */
  345. function _preserveVarByPost($varname, $value)
  346. {
  347. if (is_array($value)) {
  348. foreach ($value as $id => $val) {
  349. $this->_preserveVarByPost($varname . '[' . $id . ']', $val);
  350. }
  351. } else {
  352. $varname = htmlspecialchars($varname);
  353. $value = htmlspecialchars($value);
  354. printf('<input type="hidden" name="%s" value="%s" />' . "\n",
  355. $varname,
  356. $value);
  357. }
  358. }
  359. function open(&$renderer, &$vars, $action, $method = 'get', $enctype = null)
  360. {
  361. if (is_null($enctype) && !is_null($this->_enctype)) {
  362. $enctype = $this->_enctype;
  363. }
  364. $renderer->open($action, $method, $this->_name, $enctype);
  365. $renderer->listFormVars($this);
  366. if (!empty($this->_name)) {
  367. $this->_preserveVarByPost('formname', $this->_name);
  368. }
  369. if ($this->_useFormToken) {
  370. require_once 'Horde/Token.php';
  371. $token = Horde_Token::generateId($this->_name);
  372. $_SESSION['horde_form_secrets'][$token] = true;
  373. $this->_preserveVarByPost($this->_name . '_formToken', $token);
  374. }
  375. /* Loop through vars and check for any special cases to preserve. */
  376. $variables = $this->getVariables();
  377. foreach ($variables as $var) {
  378. /* Preserve value if change has to be tracked. */
  379. if ($var->getOption('trackchange')) {
  380. $varname = $var->getVarName();
  381. $this->preserveVarByPost($vars, $varname, '__old_' . $varname);
  382. }
  383. }
  384. foreach ($this->_hiddenVariables as $var) {
  385. $this->preserveVarByPost($vars, $var->getVarName());
  386. }
  387. }
  388. function close($renderer)
  389. {
  390. $renderer->close();
  391. }
  392. /**
  393. * Renders the form for editing.
  394. *
  395. * @param Horde_Form_Renderer $renderer A renderer instance, optional
  396. * since Horde 3.2.
  397. * @param Variables $vars A Variables instance, optional
  398. * since Horde 3.2.
  399. * @param string $action The form action (url).
  400. * @param string $method The form method, usually either
  401. * 'get' or 'post'.
  402. * @param string $enctype The form encoding type. Determined
  403. * automatically if null.
  404. * @param boolean $focus Focus the first form field?
  405. */
  406. function renderActive($renderer = null, $vars = null, $action = '',
  407. $method = 'get', $enctype = null, $focus = true)
  408. {
  409. if (is_null($renderer)) {
  410. $renderer = $this->getRenderer();
  411. }
  412. if (is_null($vars)) {
  413. $vars = $this->_vars;
  414. }
  415. if (is_null($enctype) && !is_null($this->_enctype)) {
  416. $enctype = $this->_enctype;
  417. }
  418. $renderer->open($action, $method, $this->getName(), $enctype);
  419. $renderer->listFormVars($this);
  420. if (!empty($this->_name)) {
  421. $this->_preserveVarByPost('formname', $this->_name);
  422. }
  423. if ($this->_useFormToken) {
  424. require_once 'Horde/Token.php';
  425. $token = Horde_Token::generateId($this->_name);
  426. $_SESSION['horde_form_secrets'][$token] = true;
  427. $this->_preserveVarByPost($this->_name . '_formToken', $token);
  428. }
  429. if (count($this->_sections)) {
  430. $this->_preserveVarByPost('__formOpenSection', $this->getOpenSection());
  431. }
  432. /* Loop through vars and check for any special cases to
  433. * preserve. */
  434. $variables = $this->getVariables();
  435. foreach ($variables as $var) {
  436. /* Preserve value if change has to be tracked. */
  437. if ($var->getOption('trackchange')) {
  438. $varname = $var->getVarName();
  439. $this->preserveVarByPost($vars, $varname, '__old_' . $varname);
  440. }
  441. }
  442. foreach ($this->_hiddenVariables as $var) {
  443. $this->preserveVarByPost($vars, $var->getVarName());
  444. }
  445. $renderer->beginActive($this->getTitle(), $this->getExtra());
  446. $renderer->renderFormActive($this, $vars);
  447. $renderer->submit($this->_submit, $this->_reset);
  448. $renderer->end();
  449. $renderer->close($focus);
  450. }
  451. /**
  452. * Renders the form for displaying.
  453. *
  454. * @param Horde_Form_Renderer $renderer A renderer instance, optional
  455. * since Horde 3.2.
  456. * @param Variables $vars A Variables instance, optional
  457. * since Horde 3.2.
  458. */
  459. function renderInactive($renderer = null, $vars = null)
  460. {
  461. if (is_null($renderer)) {
  462. $renderer = $this->getRenderer();
  463. }
  464. if (is_null($vars)) {
  465. $vars = $this->_vars;
  466. }
  467. $renderer->_name = $this->_name;
  468. $renderer->beginInactive($this->getTitle(), $this->getExtra());
  469. $renderer->renderFormInactive($this, $vars);
  470. $renderer->end();
  471. }
  472. function preserve($vars)
  473. {
  474. if ($this->_useFormToken) {
  475. require_once 'Horde/Token.php';
  476. $token = Horde_Token::generateId($this->_name);
  477. $_SESSION['horde_form_secrets'][$token] = true;
  478. $this->_preserveVarByPost($this->_name . '_formToken', $token);
  479. }
  480. $variables = $this->getVariables();
  481. foreach ($variables as $var) {
  482. $varname = $var->getVarName();
  483. /* Save value of individual components. */
  484. switch ($var->getTypeName()) {
  485. case 'passwordconfirm':
  486. case 'emailconfirm':
  487. $this->preserveVarByPost($vars, $varname . '[original]');
  488. $this->preserveVarByPost($vars, $varname . '[confirm]');
  489. break;
  490. case 'monthyear':
  491. $this->preserveVarByPost($vars, $varname . '[month]');
  492. $this->preserveVarByPost($vars, $varname . '[year]');
  493. break;
  494. case 'monthdayyear':
  495. $this->preserveVarByPost($vars, $varname . '[month]');
  496. $this->preserveVarByPost($vars, $varname . '[day]');
  497. $this->preserveVarByPost($vars, $varname . '[year]');
  498. break;
  499. }
  500. $this->preserveVarByPost($vars, $varname);
  501. }
  502. foreach ($this->_hiddenVariables as $var) {
  503. $this->preserveVarByPost($vars, $var->getVarName());
  504. }
  505. }
  506. function unsetVars(&$vars)
  507. {
  508. foreach ($this->getVariables() as $var) {
  509. $vars->remove($var->getVarName());
  510. }
  511. }
  512. /**
  513. * Validates the form, checking if it really has been submitted by calling
  514. * isSubmitted() and if true does any onSubmit() calls for variable types
  515. * in the form. The _submitted variable is then rechecked.
  516. *
  517. * @param Variables $vars A Variables instance, optional since Horde
  518. * 3.2.
  519. * @param boolean $canAutofill Can the form be valid without being
  520. * submitted?
  521. *
  522. * @return boolean True if the form is valid.
  523. */
  524. function validate($vars = null, $canAutoFill = false)
  525. {
  526. if (is_null($vars)) {
  527. $vars = $this->_vars;
  528. }
  529. /* Get submitted status. */
  530. if ($this->isSubmitted() || $canAutoFill) {
  531. /* Form was submitted or can autofill; check for any variable
  532. * types' onSubmit(). */
  533. $this->onSubmit($vars);
  534. /* Recheck submitted status. */
  535. if (!$this->isSubmitted() && !$canAutoFill) {
  536. return false;
  537. }
  538. } else {
  539. /* Form has not been submitted; return false. */
  540. return false;
  541. }
  542. $message = '';
  543. $this->_autofilled = true;
  544. if ($this->_useFormToken) {
  545. global $conf;
  546. require_once 'Horde/Token.php';
  547. if (isset($conf['token'])) {
  548. /* If there is a configured token system, set it up. */
  549. $tokenSource = &Horde_Token::singleton($conf['token']['driver'], Horde::getDriverConfig('token', $conf['token']['driver']));
  550. } else {
  551. /* Default to the file system if no config. */
  552. $tokenSource = &Horde_Token::singleton('file');
  553. }
  554. $passedToken = $vars->get($this->_name . '_formToken');
  555. if (!empty($passedToken) && !$tokenSource->verify($passedToken)) {
  556. $this->_errors['_formToken'] = _("This form has already been processed.");
  557. }
  558. if (empty($_SESSION['horde_form_secrets'][$passedToken])) {
  559. $this->_errors['_formSecret'] = _("Required secret is invalid - potentially malicious request.");
  560. }
  561. }
  562. foreach ($this->getVariables() as $var) {
  563. $this->_autofilled = $var->_autofilled && $this->_autofilled;
  564. if (!$var->validate($vars, $message)) {
  565. $this->_errors[$var->getVarName()] = $message;
  566. }
  567. }
  568. if ($this->_autofilled) {
  569. unset($this->_errors['_formToken']);
  570. }
  571. foreach ($this->_hiddenVariables as $var) {
  572. if (!$var->validate($vars, $message)) {
  573. $this->_errors[$var->getVarName()] = $message;
  574. }
  575. }
  576. return $this->isValid();
  577. }
  578. function clearValidation()
  579. {
  580. $this->_errors = array();
  581. }
  582. function getError($var)
  583. {
  584. if (is_a($var, 'Horde_Form_Variable')) {
  585. $name = $var->getVarName();
  586. } else {
  587. $name = $var;
  588. }
  589. return isset($this->_errors[$name]) ? $this->_errors[$name] : null;
  590. }
  591. function setError($var, $message)
  592. {
  593. if (is_a($var, 'Horde_Form_Variable')) {
  594. $name = $var->getVarName();
  595. } else {
  596. $name = $var;
  597. }
  598. $this->_errors[$name] = $message;
  599. }
  600. function clearError($var)
  601. {
  602. if (is_a($var, 'Horde_Form_Variable')) {
  603. $name = $var->getVarName();
  604. } else {
  605. $name = $var;
  606. }
  607. unset($this->_errors[$name]);
  608. }
  609. function isValid()
  610. {
  611. return ($this->_autofilled || count($this->_errors) == 0);
  612. }
  613. function execute()
  614. {
  615. Horde::logMessage('Warning: Horde_Form::execute() called, should be overridden', __FILE__, __LINE__, PEAR_LOG_DEBUG);
  616. }
  617. /**
  618. * Fetch the field values of the submitted form.
  619. *
  620. * @param Variables $vars A Variables instance, optional since Horde 3.2.
  621. * @param array $info Array to be filled with the submitted field
  622. * values.
  623. */
  624. function getInfo($vars, &$info)
  625. {
  626. if (is_null($vars)) {
  627. $vars = $this->_vars;
  628. }
  629. $this->_getInfoFromVariables($this->getVariables(), $vars, $info);
  630. $this->_getInfoFromVariables($this->_hiddenVariables, $vars, $info);
  631. }
  632. /**
  633. * Fetch the field values from a given array of variables.
  634. *
  635. * @access private
  636. *
  637. * @param array $variables An array of Horde_Form_Variable objects to
  638. * fetch from.
  639. * @param object $vars The Variables object.
  640. * @param array $info The array to be filled with the submitted
  641. * field values.
  642. */
  643. function _getInfoFromVariables($variables, &$vars, &$info)
  644. {
  645. foreach ($variables as $var) {
  646. if ($var->isArrayVal()) {
  647. $var->getInfo($vars, $values);
  648. if (is_array($values)) {
  649. $varName = str_replace('[]', '', $var->getVarName());
  650. foreach ($values as $i => $val) {
  651. $info[$i][$varName] = $val;
  652. }
  653. }
  654. } else {
  655. require_once 'Horde/Array.php';
  656. if (Horde_Array::getArrayParts($var->getVarName(), $base, $keys)) {
  657. if (!isset($info[$base])) {
  658. $info[$base] = array();
  659. }
  660. $pointer = &$info[$base];
  661. while (count($keys)) {
  662. $key = array_shift($keys);
  663. if (!isset($pointer[$key])) {
  664. $pointer[$key] = array();
  665. }
  666. $pointer = &$pointer[$key];
  667. }
  668. $var->getInfo($vars, $pointer);
  669. } else {
  670. $var->getInfo($vars, $info[$var->getVarName()]);
  671. }
  672. }
  673. }
  674. }
  675. function hasHelp()
  676. {
  677. return $this->_help;
  678. }
  679. /**
  680. * Determines if this form has been submitted or not. If the class
  681. * var _submitted is null then it will check for the presence of
  682. * the formname in the form variables.
  683. *
  684. * Other events can explicitly set the _submitted variable to
  685. * false to indicate a form submit but not for actual posting of
  686. * data (eg. onChange events to update the display of fields).
  687. *
  688. * @return boolean True or false indicating if the form has been
  689. * submitted.
  690. */
  691. function isSubmitted()
  692. {
  693. if (is_null($this->_submitted)) {
  694. if ($this->_vars->get('formname') == $this->getName()) {
  695. $this->_submitted = true;
  696. } else {
  697. $this->_submitted = false;
  698. }
  699. }
  700. return $this->_submitted;
  701. }
  702. /**
  703. * Checks if there is anything to do on the submission of the form by
  704. * looping through each variable's onSubmit() function.
  705. *
  706. * @param Horde_Variables $vars
  707. */
  708. function onSubmit(&$vars)
  709. {
  710. /* Loop through all vars and check if there's anything to do on
  711. * submit. */
  712. $variables = $this->getVariables();
  713. foreach ($variables as $var) {
  714. $var->type->onSubmit($var, $vars);
  715. /* If changes to var being tracked don't register the form as
  716. * submitted if old value and new value differ. */
  717. if ($var->getOption('trackchange')) {
  718. $varname = $var->getVarName();
  719. if (!is_null($vars->get('formname')) &&
  720. $vars->get($varname) != $vars->get('__old_' . $varname)) {
  721. $this->_submitted = false;
  722. }
  723. }
  724. }
  725. }
  726. /**
  727. * Explicitly sets the state of the form submit.
  728. *
  729. * An event can override the automatic determination of the submit state
  730. * in the isSubmitted() function.
  731. *
  732. * @param boolean $state Whether to set the state of the form as being
  733. * submitted.
  734. */
  735. function setSubmitted($state = true)
  736. {
  737. $this->_submitted = $state;
  738. }
  739. }
  740. /**
  741. * Horde_Form_Type Class
  742. *
  743. * @author Robert E. Coyle <robertecoyle@hotmail.com>
  744. * @package Horde_Form
  745. */
  746. class Horde_Form_Type {
  747. function Horde_Form_Type()
  748. {
  749. }
  750. function getProperty($property)
  751. {
  752. $prop = '_' . $property;
  753. return isset($this->$prop) ? $this->$prop : null;
  754. }
  755. function __get($property)
  756. {
  757. return $this->getProperty($property);
  758. }
  759. function setProperty($property, $value)
  760. {
  761. $prop = '_' . $property;
  762. $this->$prop = $value;
  763. }
  764. function __set($property, $value)
  765. {
  766. return $this->setProperty($property, $value);
  767. }
  768. function init()
  769. {
  770. }
  771. function onSubmit()
  772. {
  773. }
  774. function isValid(&$var, &$vars, $value, &$message)
  775. {
  776. $message = '<strong>Error:</strong> Horde_Form_Type::isValid() called - should be overridden<br />';
  777. return false;
  778. }
  779. function getTypeName()
  780. {
  781. return str_replace('horde_form_type_', '', String::lower(get_class($this)));
  782. }
  783. function getValues()
  784. {
  785. return null;
  786. }
  787. function getInfo(&$vars, &$var, &$info)
  788. {
  789. $info = $var->getValue($vars);
  790. }
  791. }
  792. class Horde_Form_Type_spacer extends Horde_Form_Type {
  793. function isValid(&$var, &$vars, $value, &$message)
  794. {
  795. return true;
  796. }
  797. /**
  798. * Return info about field type.
  799. */
  800. function about()
  801. {
  802. return array('name' => _("Spacer"));
  803. }
  804. }
  805. class Horde_Form_Type_header extends Horde_Form_Type {
  806. function isValid(&$var, &$vars, $value, &$message)
  807. {
  808. return true;
  809. }
  810. /**
  811. * Return info about field type.
  812. */
  813. function about()
  814. {
  815. return array('name' => _("Header"));
  816. }
  817. }
  818. class Horde_Form_Type_description extends Horde_Form_Type {
  819. function isValid(&$var, &$vars, $value, &$message)
  820. {
  821. return true;
  822. }
  823. /**
  824. * Return info about field type.
  825. */
  826. function about()
  827. {
  828. return array('name' => _("Description"));
  829. }
  830. }
  831. /**
  832. * Simply renders its raw value in both active and inactive rendering.
  833. */
  834. class Horde_Form_Type_html extends Horde_Form_Type {
  835. function isValid(&$var, &$vars, $value, &$message)
  836. {
  837. return true;
  838. }
  839. /**
  840. * Return info about field type.
  841. */
  842. function about()
  843. {
  844. return array('name' => _("HTML"));
  845. }
  846. }
  847. class Horde_Form_Type_number extends Horde_Form_Type {
  848. var $_fraction;
  849. function init($fraction = null)
  850. {
  851. $this->_fraction = $fraction;
  852. }
  853. function isValid(&$var, &$vars, $value, &$message)
  854. {
  855. if ($var->isRequired() && empty($value) && ((string)(double)$value !== $value)) {
  856. $message = _("This field is required.");
  857. return false;
  858. } elseif (empty($value)) {
  859. return true;
  860. }
  861. /* If matched, then this is a correct numeric value. */
  862. if (preg_match($this->_getValidationPattern(), $value)) {
  863. return true;
  864. }
  865. $message = _("This field must be a valid number.");
  866. return false;
  867. }
  868. function _getValidationPattern()
  869. {
  870. static $pattern = '';
  871. if (!empty($pattern)) {
  872. return $pattern;
  873. }
  874. /* Get current locale information. */
  875. $linfo = NLS::getLocaleInfo();
  876. /* Build the pattern. */
  877. $pattern = '(-)?';
  878. /* Only check thousands separators if locale has any. */
  879. if (!empty($linfo['mon_thousands_sep'])) {
  880. /* Regex to check for correct thousands separators (if any). */
  881. $pattern .= '((\d+)|((\d{0,3}?)([' . $linfo['mon_thousands_sep'] . ']\d{3})*?))';
  882. } else {
  883. /* No locale thousands separator, check for only digits. */
  884. $pattern .= '(\d+)';
  885. }
  886. /* If no decimal point specified default to dot. */
  887. if (empty($linfo['mon_decimal_point'])) {
  888. $linfo['mon_decimal_point'] = '.';
  889. }
  890. /* Regex to check for correct decimals (if any). */
  891. if (empty($this->_fraction)) {
  892. $fraction = '*';
  893. } else {
  894. $fraction = '{0,' . $this->_fraction . '}';
  895. }
  896. $pattern .= '([' . $linfo['mon_decimal_point'] . '](\d' . $fraction . '))?';
  897. /* Put together the whole regex pattern. */
  898. $pattern = '/^' . $pattern . '$/';
  899. return $pattern;
  900. }
  901. function getInfo(&$vars, &$var, &$info)
  902. {
  903. $value = $vars->get($var->getVarName());
  904. $linfo = NLS::getLocaleInfo();
  905. $value = str_replace($linfo['mon_thousands_sep'], '', $value);
  906. $info = str_replace($linfo['mon_decimal_point'], '.', $value);
  907. }
  908. /**
  909. * Return info about field type.
  910. */
  911. function about()
  912. {
  913. return array('name' => _("Number"));
  914. }
  915. }
  916. class Horde_Form_Type_int extends Horde_Form_Type {
  917. function isValid(&$var, &$vars, $value, &$message)
  918. {
  919. if ($var->isRequired() && empty($value) && ((string)(int)$value !== $value)) {
  920. $message = _("This field is required.");
  921. return false;
  922. }
  923. if (empty($value) || preg_match('/^[0-9]+$/', $value)) {
  924. return true;
  925. }
  926. $message = _("This field may only contain integers.");
  927. return false;
  928. }
  929. /**
  930. * Return info about field type.
  931. */
  932. function about()
  933. {
  934. return array('name' => _("Integer"));
  935. }
  936. }
  937. class Horde_Form_Type_octal extends Horde_Form_Type {
  938. function isValid(&$var, &$vars, $value, &$message)
  939. {
  940. if ($var->isRequired() && empty($value) && ((string)(int)$value !== $value)) {
  941. $message = _("This field is required.");
  942. return false;
  943. }
  944. if (empty($value) || preg_match('/^[0-7]+$/', $value)) {
  945. return true;
  946. }
  947. $message = _("This field may only contain octal values.");
  948. return false;
  949. }
  950. /**
  951. * Return info about field type.
  952. */
  953. function about()
  954. {
  955. return array('name' => _("Octal"));
  956. }
  957. }
  958. class Horde_Form_Type_intlist extends Horde_Form_Type {
  959. function isValid(&$var, &$vars, $value, &$message)
  960. {
  961. if (empty($value) && $var->isRequired()) {
  962. $message = _("This field is required.");
  963. return false;
  964. }
  965. if (empty($value) || preg_match('/^[0-9 ,]+$/', $value)) {
  966. return true;
  967. }
  968. $message = _("This field must be a comma or space separated list of integers");
  969. return false;
  970. }
  971. /**
  972. * Return info about field type.
  973. */
  974. function about()
  975. {
  976. return array('name' => _("Integer list"));
  977. }
  978. }
  979. class Horde_Form_Type_text extends Horde_Form_Type {
  980. var $_regex;
  981. var $_size;
  982. var $_maxlength;
  983. /**
  984. * The initialisation function for the text variable type.
  985. *
  986. * @access private
  987. *
  988. * @param string $regex Any valid PHP PCRE pattern syntax that
  989. * needs to be matched for the field to be
  990. * considered valid. If left empty validity
  991. * will be checked only for required fields
  992. * whether they are empty or not.
  993. * If using this regex test it is advisable
  994. * to enter a description for this field to
  995. * warn the user what is expected, as the
  996. * generated error message is quite generic
  997. * and will not give any indication where
  998. * the regex failed.
  999. * @param integer $size The size of the input field.
  1000. * @param integer $maxlength The max number of characters.
  1001. */
  1002. function init($regex = '', $size = 40, $maxlength = null)
  1003. {
  1004. $this->_regex = $regex;
  1005. $this->_size = $size;
  1006. $this->_maxlength = $maxlength;
  1007. }
  1008. function isValid(&$var, &$vars, $value, &$message)
  1009. {
  1010. $valid = true;
  1011. if (!empty($this->_maxlength) && String::length($value) > $this->_maxlength) {
  1012. $valid = false;
  1013. $message = sprintf(_("Value is over the maximum length of %d."), $this->_maxlength);
  1014. } elseif ($var->isRequired() && empty($this->_regex)) {
  1015. $valid = strlen(trim($value)) > 0;
  1016. if (!$valid) {
  1017. $message = _("This field is required.");
  1018. }
  1019. } elseif (!empty($this->_regex)) {
  1020. $valid = preg_match($this->_regex, $value);
  1021. if (!$valid) {
  1022. $message = _("You must enter a valid value.");
  1023. }
  1024. }
  1025. return $valid;
  1026. }
  1027. function getSize()
  1028. {
  1029. return $this->_size;
  1030. }
  1031. function getMaxLength()
  1032. {
  1033. return $this->_maxlength;
  1034. }
  1035. /**
  1036. * Return info about field type.
  1037. */
  1038. function about()
  1039. {
  1040. return array(
  1041. 'name' => _("Text"),
  1042. 'params' => array(
  1043. 'regex' => array('label' => _("Regex"),
  1044. 'type' => 'text'),
  1045. 'size' => array('label' => _("Size"),
  1046. 'type' => 'int'),
  1047. 'maxlength' => array('label' => _("Maximum length"),
  1048. 'type' => 'int')));
  1049. }
  1050. }
  1051. class Horde_Form_Type_stringlist extends Horde_Form_Type_text {
  1052. /**
  1053. * Return info about field type.
  1054. */
  1055. function about()
  1056. {
  1057. return array(
  1058. 'name' => _("String list"),
  1059. 'params' => array(
  1060. 'regex' => array('label' => _("Regex"),
  1061. 'type' => 'text'),
  1062. 'size' => array('label' => _("Size"),
  1063. 'type' => 'int'),
  1064. 'maxlength' => array('label' => _("Maximum length"),
  1065. 'type' => 'int')),
  1066. );
  1067. }
  1068. }
  1069. /**
  1070. * @since Horde 3.3
  1071. */
  1072. class Horde_Form_Type_stringarray extends Horde_Form_Type_stringlist {
  1073. function getInfo(&$vars, &$var, &$info)
  1074. {
  1075. $info = array_map('trim', explode(',', $vars->get($var->getVarName())));
  1076. }
  1077. /**
  1078. * Return info about field type.
  1079. */
  1080. function about()
  1081. {
  1082. return array(
  1083. 'name' => _("String list returning an array"),
  1084. 'params' => array(
  1085. 'regex' => array('label' => _("Regex"),
  1086. 'type' => 'text'),
  1087. 'size' => array('label' => _("Size"),
  1088. 'type' => 'int'),
  1089. 'maxlength' => array('label' => _("Maximum length"),
  1090. 'type' => 'int')),
  1091. );
  1092. }
  1093. }
  1094. /**
  1095. * @since Horde 3.2
  1096. */
  1097. class Horde_Form_Type_phone extends Horde_Form_Type {
  1098. function isValid(&$var, &$vars, $value, &$message)
  1099. {
  1100. if (!strlen(trim($value))) {
  1101. if ($var->isRequired()) {
  1102. $message = _("This field is required.");
  1103. return false;
  1104. }
  1105. } elseif (!preg_match('/^\+?[\d()\-\/. ]*$/', $value)) {
  1106. $message = _("You must enter a valid phone number, digits only with an optional '+' for the international dialing prefix.");
  1107. return false;
  1108. }
  1109. return true;
  1110. }
  1111. /**
  1112. * Return info about field type.
  1113. */
  1114. function about()
  1115. {
  1116. return array('name' => _("Phone number"));
  1117. }
  1118. }
  1119. class Horde_Form_Type_cellphone extends Horde_Form_Type_phone {
  1120. /**
  1121. * Return info about field type.
  1122. */
  1123. function about()
  1124. {
  1125. return array('name' => _("Mobile phone number"));
  1126. }
  1127. }
  1128. class Horde_Form_Type_ipaddress extends Horde_Form_Type_text {
  1129. function isValid(&$var, &$vars, $value, &$message)
  1130. {
  1131. $valid = true;
  1132. if (strlen(trim($value)) > 0) {
  1133. $ip = explode('.', $value);
  1134. $valid = (count($ip) == 4);
  1135. if ($valid) {
  1136. foreach ($ip as $part) {
  1137. if (!is_numeric($part) ||
  1138. $part > 255 ||
  1139. $part < 0) {
  1140. $valid = false;
  1141. break;
  1142. }
  1143. }
  1144. }
  1145. if (!$valid) {
  1146. $message = _("Please enter a valid IP address.");
  1147. }
  1148. } elseif ($var->isRequired()) {
  1149. $valid = false;
  1150. $message = _("This field is required.");
  1151. }
  1152. return $valid;
  1153. }
  1154. /**
  1155. * Return info about field type.
  1156. */
  1157. function about()
  1158. {
  1159. return array('name' => _("IP address"));
  1160. }
  1161. }
  1162. class Horde_Form_Type_longtext extends Horde_Form_Type_text {
  1163. var $_rows;
  1164. var $_cols;
  1165. var $_helper = array();
  1166. function init($rows = 8, $cols = 80, $helper = array())
  1167. {
  1168. if (!is_array($helper)) {
  1169. $helper = array($helper);
  1170. }
  1171. $this->_rows = $rows;
  1172. $this->_cols = $cols;
  1173. $this->_helper = $helper;
  1174. }
  1175. function getRows()
  1176. {
  1177. return $this->_rows;
  1178. }
  1179. function getCols()
  1180. {
  1181. return $this->_cols;
  1182. }
  1183. function hasHelper($option = '')
  1184. {
  1185. if (empty($option)) {
  1186. /* No option specified, check if any helpers have been
  1187. * activated. */
  1188. return !empty($this->_helper);
  1189. } elseif (empty($this->_helper)) {
  1190. /* No helpers activated at all, return false. */
  1191. return false;
  1192. } else {
  1193. /* Check if given helper has been activated. */
  1194. return in_array($option, $this->_helper);
  1195. }
  1196. }
  1197. /**
  1198. * Return info about field type.
  1199. */
  1200. function about()
  1201. {
  1202. return array(
  1203. 'name' => _("Long text"),
  1204. 'params' => array(
  1205. 'rows' => array('label' => _("Number of rows"),
  1206. 'type' => 'int'),
  1207. 'cols' => array('label' => _("Number of columns"),
  1208. 'type' => 'int'),
  1209. 'helper' => array('label' => _("Helpers"),
  1210. 'type' => 'stringarray')));
  1211. }
  1212. }
  1213. class Horde_Form_Type_countedtext extends Horde_Form_Type_longtext {
  1214. var $_chars;
  1215. function init($rows = null, $cols = null, $chars = 1000)
  1216. {
  1217. parent::init($rows, $cols);
  1218. $this->_chars = $chars;
  1219. }
  1220. function isValid(&$var, &$vars, $value, &$message)
  1221. {
  1222. $valid = true;
  1223. $length = String::length(trim($value));
  1224. if ($var->isRequired() && $length <= 0) {
  1225. $valid = false;
  1226. $message = _("This field is required.");
  1227. } elseif ($length > $this->_chars) {
  1228. $valid = false;
  1229. $message = sprintf(ngettext("There are too many characters in this field. You have entered %d character; ", "There are too many characters in this field. You have entered %d characters; ", $length), $length)
  1230. . sprintf(_("you must enter less than %d."), $this->_chars);
  1231. }
  1232. return $valid;
  1233. }
  1234. function getChars()
  1235. {
  1236. return $this->_chars;
  1237. }
  1238. /**
  1239. * Return info about field type.
  1240. */
  1241. function about()
  1242. {
  1243. return array(
  1244. 'name' => _("Counted text"),
  1245. 'params' => array(
  1246. 'rows' => array('label' => _("Number of rows"),
  1247. 'type' => 'int'),
  1248. 'cols' => array('label' => _("Number of columns"),
  1249. 'type' => 'int'),
  1250. 'chars' => array('label' => _("Number of characters"),
  1251. 'type' => 'int')));
  1252. }
  1253. }
  1254. class Horde_Form_Type_address extends Horde_Form_Type_longtext {
  1255. function parse($address)
  1256. {
  1257. $info = array();
  1258. $aus_state_regex = '(?:ACT|NSW|NT|QLD|SA|TAS|VIC|WA)';
  1259. if (preg_match('/(?s)(.*?)(?-s)\r?\n(?:(.*?)\s+)?((?:A[BL]|B[ABDHLNRST]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[CHNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTWY]?|T[ADFNQRSW]|UB|W[ACDFNRSV]?|YO|ZE)\d(?:\d|[A-Z])? \d[A-Z]{2})/', $address, $addressParts)) {
  1260. /* UK postcode detected. */
  1261. $info = array('country' => 'uk', 'zip' => $addressParts[3]);
  1262. if (!empty($addressParts[1])) {
  1263. $info['street'] = $addressParts[1];
  1264. }
  1265. if (!empty($addressParts[2])) {
  1266. $info['city'] = $addressParts[2];
  1267. }
  1268. } elseif (preg_match('/\b' . $aus_state_regex . '\b/', $address)) {
  1269. /* Australian state detected. */
  1270. /* Split out the address, line-by-line. */
  1271. $addressLines = preg_split('/\r?\n/', $address);
  1272. $info = array('country' => 'au');
  1273. for ($i = 0; $i < count($addressLines); $i++) {
  1274. /* See if it's the street number & name. */
  1275. if (preg_match('/(\d+\s*\/\s*)?(\d+|\d+[a-zA-Z])\s+([a-zA-Z ]*)/', $addressLines[$i], $lineParts)) {
  1276. $info['street'] = $addressLines[$i];
  1277. $info['streetNumber'] = $lineParts[2];
  1278. $info['streetName'] = $lineParts[3];
  1279. }
  1280. /* Look for "Suburb, State". */
  1281. if (preg_match('/([a-zA-Z ]*),?\s+(' . $aus_state_regex . ')/', $addressLines[$i], $lineParts)) {
  1282. $info['city'] = $lineParts[1];
  1283. $info['state'] = $lineParts[2];
  1284. }
  1285. /* Look for "State <4 digit postcode>". */
  1286. if (preg_match('/(' . $aus_state_regex . ')\s+(\d{4})/', $addressLines[$i], $lineParts)) {
  1287. $info['state'] = $lineParts[1];
  1288. $info['zip'] = $lineParts[2];
  1289. }
  1290. }
  1291. } elseif (preg_match('/(?s)(.*?)(?-s)\r?\n(.*)\s*,\s*(\w+)\.?\s+(\d+|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d)/', $address, $addressParts)) {
  1292. /* American/Canadian address style. */
  1293. $info = array('country' => 'us');
  1294. if (!empty($addressParts[4]) &&
  1295. preg_match('|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d|', $addressParts[4])) {
  1296. $info['country'] = 'ca';
  1297. }
  1298. if (!empty($addressParts[1])) {
  1299. $info['street'] = $addressParts[1];
  1300. }
  1301. if (!empty($addressParts[2])) {
  1302. $info['city'] = $addressParts[2];
  1303. }
  1304. if (!empty($addressParts[3])) {
  1305. $info['state'] = $addressParts[3];
  1306. }
  1307. if (!empty($addressParts[4])) {
  1308. $info['zip'] = $addressParts[4];
  1309. }
  1310. } elseif (preg_match('/(?:(?s)(.*?)(?-s)(?:\r?\n|,\s*))?(?:([A-Z]{1,3})-)?(\d{4,5})\s+(.*)(?:\r?\n(.*))?/i', $address, $addressParts)) {
  1311. /* European address style. */
  1312. $info = array();
  1313. if (!empty($addressParts[1])) {
  1314. $info['street'] = $addressParts[1];
  1315. }
  1316. if (!empty($addressParts[2])) {
  1317. include 'Horde/NLS/carsigns.php';
  1318. $country = array_search(String::upper($addressParts[2]), $carsigns);
  1319. if ($country) {
  1320. $info['country'] = $country;
  1321. }
  1322. }
  1323. if (!empty($addressParts[5])) {
  1324. include 'Horde/NLS/countries.php';
  1325. $country = array_search($addressParts[5], $countries);
  1326. if ($country) {
  1327. $info['country'] = String::lower($country);
  1328. } elseif (!isset($info['street'])) {
  1329. $info['street'] = trim($addressParts[5]);
  1330. } else {
  1331. $info['street'] .= "\n" . $addressParts[5];
  1332. }
  1333. }
  1334. if (!empty($addressParts[3])) {
  1335. $info['zip'] = $addressParts[3];
  1336. }
  1337. if (!empty($addressParts[4])) {
  1338. $info['city'] = trim($addressParts[4]);
  1339. }
  1340. }
  1341. return $info;
  1342. }
  1343. /**
  1344. * Return info about field type.
  1345. */
  1346. function about()
  1347. {
  1348. return array(
  1349. 'name' => _("Address"),
  1350. 'params' => array(
  1351. 'rows' => array('label' => _("Number of rows"),
  1352. 'type' => 'int'),
  1353. 'cols' => array('label' => _("Number of columns"),
  1354. 'type' => 'int')));
  1355. }
  1356. }
  1357. class Horde_Form_Type_addresslink extends Horde_Form_Type_address {
  1358. function isValid(&$var, &$vars, $value, &$message)
  1359. {
  1360. return true;
  1361. }
  1362. /**
  1363. * Return info about field type.
  1364. */
  1365. function about()
  1366. {
  1367. return array('name' => _("Address Link"));
  1368. }
  1369. }
  1370. /**
  1371. * @since Horde 3.3
  1372. */
  1373. class Horde_Form_Type_pgp extends Horde_Form_Type_longtext {
  1374. /**
  1375. * Path to the GnuPG binary.
  1376. *
  1377. * @var string
  1378. */
  1379. var $_gpg;
  1380. /**
  1381. * A temporary directory.
  1382. *
  1383. * @var string
  1384. */
  1385. var $_temp;
  1386. function init($gpg, $temp_dir = null, $rows = null, $cols = null)
  1387. {
  1388. $this->_gpg = $gpg;
  1389. $this->_temp = $temp_dir;
  1390. parent::init($rows, $cols);
  1391. }
  1392. /**
  1393. * Returns a parameter hash for the Horde_Crypt_pgp constructor.
  1394. *
  1395. * @return array A parameter hash.
  1396. */
  1397. function getPGPParams()
  1398. {
  1399. return array('program' => $this->_gpg, 'temp' => $this->_temp);
  1400. }
  1401. /**
  1402. * Return info about field type.
  1403. */
  1404. function about()
  1405. {
  1406. return array(
  1407. 'name' => _("PGP Key"),
  1408. 'params' => array(
  1409. 'gpg' => array('label' => _("Path to the GnuPG binary"),
  1410. 'type' => 'string'),
  1411. 'temp_dir' => array('label' => _("A temporary directory"),
  1412. 'type' => 'string'),
  1413. 'rows' => array('label' => _("Number of rows"),
  1414. 'type' => 'int'),
  1415. 'cols' => array('label' => _("Number of columns"),
  1416. 'type' => 'int')));
  1417. }
  1418. }
  1419. /**
  1420. * @since Horde 3.3
  1421. */
  1422. class Horde_Form_Type_smime extends Horde_Form_Type_longtext {
  1423. /**
  1424. * A temporary directory.
  1425. *
  1426. * @var string
  1427. */
  1428. var $_temp;
  1429. function init($temp_dir = null, $rows = null, $cols = null)
  1430. {
  1431. $this->_temp = $temp_dir;
  1432. parent::init($rows, $cols);
  1433. }
  1434. /**
  1435. * Returns a parameter hash for the Horde_Crypt_smime constructor.
  1436. *
  1437. * @return array A parameter hash.
  1438. */
  1439. function getSMIMEParams()
  1440. {
  1441. return array('temp' => $this->_temp);
  1442. }
  1443. /**
  1444. * Return info about field type.
  1445. */
  1446. function about()
  1447. {
  1448. return array(
  1449. 'name' => _("S/MIME Key"),
  1450. 'params' => array(
  1451. 'temp_dir' => array('label' => _("A temporary directory"),
  1452. 'type' => 'string'),
  1453. 'rows' => array('label' => _("Number of rows"),

Large files files are truncated, but you can click here to view the full file