options.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. <?php
  2. /**
  3. * options.php
  4. *
  5. * Functions needed to display the options pages.
  6. *
  7. * @copyright &copy; 1999-2007 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id$
  10. * @package squirrelmail
  11. * @subpackage prefs
  12. */
  13. /**********************************************/
  14. /* Define constants used in the options code. */
  15. /**********************************************/
  16. /* Define constants for the various option types. */
  17. define('SMOPT_TYPE_STRING', 0);
  18. define('SMOPT_TYPE_STRLIST', 1);
  19. define('SMOPT_TYPE_TEXTAREA', 2);
  20. define('SMOPT_TYPE_INTEGER', 3);
  21. define('SMOPT_TYPE_FLOAT', 4);
  22. define('SMOPT_TYPE_BOOLEAN', 5);
  23. define('SMOPT_TYPE_HIDDEN', 6);
  24. define('SMOPT_TYPE_COMMENT', 7);
  25. define('SMOPT_TYPE_FLDRLIST', 8);
  26. define('SMOPT_TYPE_FLDRLIST_MULTI', 9);
  27. define('SMOPT_TYPE_EDIT_LIST', 10);
  28. define('SMOPT_TYPE_STRLIST_MULTI', 11);
  29. /* Define constants for the options refresh levels. */
  30. define('SMOPT_REFRESH_NONE', 0);
  31. define('SMOPT_REFRESH_FOLDERLIST', 1);
  32. define('SMOPT_REFRESH_ALL', 2);
  33. /* Define constants for the options size. */
  34. define('SMOPT_SIZE_TINY', 0);
  35. define('SMOPT_SIZE_SMALL', 1);
  36. define('SMOPT_SIZE_MEDIUM', 2);
  37. define('SMOPT_SIZE_LARGE', 3);
  38. define('SMOPT_SIZE_HUGE', 4);
  39. define('SMOPT_SIZE_NORMAL', 5);
  40. define('SMOPT_SAVE_DEFAULT', 'save_option');
  41. define('SMOPT_SAVE_NOOP', 'save_option_noop');
  42. /**
  43. * SquirrelOption: An option for SquirrelMail.
  44. *
  45. * @package squirrelmail
  46. * @subpackage prefs
  47. */
  48. class SquirrelOption {
  49. /**
  50. * The name of this setting
  51. * @var string
  52. */
  53. var $name;
  54. /**
  55. * The text that prefaces setting on the preferences page
  56. * @var string
  57. */
  58. var $caption;
  59. /**
  60. * The type of INPUT element
  61. *
  62. * See SMOPT_TYPE_* defines
  63. * @var integer
  64. */
  65. var $type;
  66. /**
  67. * Indicates if a link should be shown to refresh part
  68. * or all of the window
  69. *
  70. * See SMOPT_REFRESH_* defines
  71. * @var integer
  72. */
  73. var $refresh_level;
  74. /**
  75. * Specifies the size of certain input items
  76. *
  77. * See SMOPT_SIZE_* defines
  78. * @var integer
  79. */
  80. var $size;
  81. /**
  82. * Text that follows a text input or
  83. * select list input on the preferences page
  84. *
  85. * useful for indicating units, meanings of special values, etc.
  86. * @var string
  87. */
  88. var $trailing_text;
  89. /**
  90. * text displayed to the user
  91. *
  92. * Used with SMOPT_TYPE_COMMENT options
  93. * @var string
  94. */
  95. var $comment;
  96. /**
  97. * additional javascript or other widget attributes added to the
  98. * user input; must be an array where keys are attribute names
  99. * ("onclick", etc) and values are the attribute values.
  100. * @var array
  101. */
  102. var $aExtraAttribs;
  103. /**
  104. * script (usually Javascript) that will be placed after (outside of)
  105. * the INPUT tag
  106. * @var string
  107. */
  108. var $post_script;
  109. /**
  110. * The name of the Save Function for this option.
  111. * @var string
  112. */
  113. var $save_function;
  114. /* The various 'values' for this options. */
  115. /**
  116. * default/preselected value for this option
  117. * @var mixed
  118. */
  119. var $value;
  120. /**
  121. * new option value
  122. * @var mixed
  123. */
  124. var $new_value;
  125. /**
  126. * associative array, where each key is an actual input value
  127. * and the corresponding value is what is displayed to the user
  128. * for that list item in the drop-down list
  129. * @var array
  130. */
  131. var $possible_values;
  132. /**
  133. * disables html sanitizing.
  134. *
  135. * WARNING - don't use it, if user input is possible in option
  136. * or use own sanitizing functions. Currently only works for SMOPT_TYPE_STRLIST.
  137. * @var bool
  138. */
  139. var $htmlencoded=false;
  140. /**
  141. * Controls folder list limits in SMOPT_TYPE_FLDRLIST and
  142. * SMOPT_TYPE_FLDRLIST_MULTI widgets.
  143. * See $flag argument in sqimap_mailbox_option_list() function.
  144. * @var string
  145. * @since 1.5.1
  146. */
  147. var $folder_filter='noselect';
  148. /**
  149. * Constructor function
  150. * @param string $name
  151. * @param string $caption
  152. * @param integer $type
  153. * @param integer $refresh_level
  154. * @param mixed $initial_value
  155. * @param array $possible_values
  156. * @param bool $htmlencoded
  157. */
  158. function SquirrelOption
  159. ($name, $caption, $type, $refresh_level, $initial_value = '', $possible_values = '', $htmlencoded = false) {
  160. /* Set the basic stuff. */
  161. $this->name = $name;
  162. $this->caption = $caption;
  163. $this->type = $type;
  164. $this->refresh_level = $refresh_level;
  165. $this->possible_values = $possible_values;
  166. $this->htmlencoded = $htmlencoded;
  167. $this->size = SMOPT_SIZE_MEDIUM;
  168. $this->trailing_text = '';
  169. $this->comment = '';
  170. $this->aExtraAttribs = array();
  171. $this->post_script = '';
  172. //Check for a current value.
  173. if (isset($GLOBALS[$name])) {
  174. $this->value = $GLOBALS[$name];
  175. } else if (!empty($initial_value)) {
  176. $this->value = $initial_value;
  177. } else {
  178. $this->value = '';
  179. }
  180. /* Check for a new value. */
  181. if ( !sqgetGlobalVar("new_$name", $this->new_value, SQ_POST ) ) {
  182. $this->new_value = '';
  183. }
  184. /* Set the default save function. */
  185. if (($type != SMOPT_TYPE_HIDDEN) && ($type != SMOPT_TYPE_COMMENT)) {
  186. $this->save_function = SMOPT_SAVE_DEFAULT;
  187. } else {
  188. $this->save_function = SMOPT_SAVE_NOOP;
  189. }
  190. }
  191. /**
  192. * Set the value for this option.
  193. * @param mixed $value
  194. */
  195. function setValue($value) {
  196. $this->value = $value;
  197. }
  198. /**
  199. * Set the new value for this option.
  200. * @param mixed $new_value
  201. */
  202. function setNewValue($new_value) {
  203. $this->new_value = $new_value;
  204. }
  205. /**
  206. * Set the size for this option.
  207. * @param integer $size
  208. */
  209. function setSize($size) {
  210. $this->size = $size;
  211. }
  212. /**
  213. * Set the trailing_text for this option.
  214. * @param string $trailing_text
  215. */
  216. function setTrailingText($trailing_text) {
  217. $this->trailing_text = $trailing_text;
  218. }
  219. /**
  220. * Set the comment for this option.
  221. * @param string $comment
  222. */
  223. function setComment($comment) {
  224. $this->comment = $comment;
  225. }
  226. /**
  227. * Set the extra attributes for this option.
  228. * @param array $aExtraAttribs
  229. */
  230. function setExtraAttributes($aExtraAttribs) {
  231. $this->aExtraAttribs = $aExtraAttribs;
  232. }
  233. /**
  234. * Set the "post script" for this option.
  235. * @param string $post_script
  236. */
  237. function setPostScript($post_script) {
  238. $this->post_script = $post_script;
  239. }
  240. /**
  241. * Set the save function for this option.
  242. * @param string $save_function
  243. */
  244. function setSaveFunction($save_function) {
  245. $this->save_function = $save_function;
  246. }
  247. /**
  248. * Set the trailing_text for this option.
  249. * @param string $folder_filter
  250. * @since 1.5.1
  251. */
  252. function setFolderFilter($folder_filter) {
  253. $this->folder_filter = $folder_filter;
  254. }
  255. /**
  256. * Creates fields on option pages according to option type
  257. *
  258. * This is the function that calls all other createWidget* functions.
  259. *
  260. * @return string The formated option field
  261. *
  262. */
  263. function createWidget() {
  264. global $color;
  265. // Use new value if available
  266. if (!empty($this->new_value)) {
  267. $tempValue = $this->value;
  268. $this->value = $this->new_value;
  269. }
  270. /* Get the widget for this option type. */
  271. switch ($this->type) {
  272. case SMOPT_TYPE_STRING:
  273. $result = $this->createWidget_String();
  274. break;
  275. case SMOPT_TYPE_STRLIST:
  276. $result = $this->createWidget_StrList();
  277. break;
  278. case SMOPT_TYPE_TEXTAREA:
  279. $result = $this->createWidget_TextArea();
  280. break;
  281. case SMOPT_TYPE_INTEGER:
  282. $result = $this->createWidget_Integer();
  283. break;
  284. case SMOPT_TYPE_FLOAT:
  285. $result = $this->createWidget_Float();
  286. break;
  287. case SMOPT_TYPE_BOOLEAN:
  288. $result = $this->createWidget_Boolean();
  289. break;
  290. case SMOPT_TYPE_HIDDEN:
  291. $result = $this->createWidget_Hidden();
  292. break;
  293. case SMOPT_TYPE_COMMENT:
  294. $result = $this->createWidget_Comment();
  295. break;
  296. case SMOPT_TYPE_FLDRLIST:
  297. $result = $this->createWidget_FolderList();
  298. break;
  299. case SMOPT_TYPE_FLDRLIST_MULTI:
  300. $result = $this->createWidget_FolderList(TRUE);
  301. break;
  302. case SMOPT_TYPE_EDIT_LIST:
  303. $result = $this->createWidget_EditList();
  304. break;
  305. case SMOPT_TYPE_STRLIST_MULTI:
  306. $result = $this->createWidget_StrList(TRUE);
  307. break;
  308. default:
  309. error_box (
  310. sprintf(_("Option Type '%s' Not Found"), $this->type)
  311. );
  312. }
  313. /* Add the "post script" for this option. */
  314. $result .= $this->post_script;
  315. // put correct value back if need be
  316. if (!empty($this->new_value)) {
  317. $this->value = $tempValue;
  318. }
  319. /* Now, return the created widget. */
  320. return $result;
  321. }
  322. /**
  323. * Create string field
  324. * @return string html formated option field
  325. */
  326. function createWidget_String() {
  327. switch ($this->size) {
  328. case SMOPT_SIZE_TINY:
  329. $width = 5;
  330. break;
  331. case SMOPT_SIZE_SMALL:
  332. $width = 12;
  333. break;
  334. case SMOPT_SIZE_LARGE:
  335. $width = 38;
  336. break;
  337. case SMOPT_SIZE_HUGE:
  338. $width = 50;
  339. break;
  340. case SMOPT_SIZE_NORMAL:
  341. default:
  342. $width = 25;
  343. }
  344. return addInput('new_' . $this->name, $this->value, $width, 0, $this->aExtraAttribs) . htmlspecialchars($this->trailing_text);
  345. }
  346. /**
  347. * Create selection box
  348. *
  349. * When $this->htmlencoded is TRUE, the keys and values in
  350. * $this->possible_values are assumed to be display-safe.
  351. * Use with care!
  352. *
  353. * @param boolean $multiple_select When TRUE, the select widget
  354. * will allow multiple selections
  355. * (OPTIONAL; default is FALSE
  356. * (single select list))
  357. *
  358. * @return string html formated selection box
  359. *
  360. */
  361. function createWidget_StrList($multiple_select=FALSE) {
  362. //FIXME: Currently, $this->htmlencoded is ignored here -- was removed when changing to template-based output; a fix is available as part of proposed centralized sanitizing patch
  363. switch ($this->size) {
  364. //FIXME: not sure about these sizes... seems like we could add another on the "large" side...
  365. case SMOPT_SIZE_TINY:
  366. $height = 3;
  367. break;
  368. case SMOPT_SIZE_SMALL:
  369. $height = 8;
  370. break;
  371. case SMOPT_SIZE_LARGE:
  372. $height = 15;
  373. break;
  374. case SMOPT_SIZE_HUGE:
  375. $height = 25;
  376. break;
  377. case SMOPT_SIZE_NORMAL:
  378. default:
  379. $height = 5;
  380. }
  381. return addSelect('new_' . $this->name, $this->possible_values, $this->value, TRUE, $this->aExtraAttribs, $multiple_select, $height, !$this->htmlencoded) . htmlspecialchars($this->trailing_text);
  382. }
  383. /**
  384. * Create folder selection box
  385. *
  386. * @param boolean $multiple_select When TRUE, the select widget
  387. * will allow multiple selections
  388. * (OPTIONAL; default is FALSE
  389. * (single select list))
  390. *
  391. * @return string html formated selection box
  392. *
  393. */
  394. function createWidget_FolderList($multiple_select=FALSE) {
  395. switch ($this->size) {
  396. //FIXME: not sure about these sizes... seems like we could add another on the "large" side...
  397. case SMOPT_SIZE_TINY:
  398. $height = 3;
  399. break;
  400. case SMOPT_SIZE_SMALL:
  401. $height = 8;
  402. break;
  403. case SMOPT_SIZE_LARGE:
  404. $height = 15;
  405. break;
  406. case SMOPT_SIZE_HUGE:
  407. $height = 25;
  408. break;
  409. case SMOPT_SIZE_NORMAL:
  410. default:
  411. $height = 5;
  412. }
  413. // possible values might include a nested array of
  414. // possible values (list of folders)
  415. //
  416. $option_list = array();
  417. foreach ($this->possible_values as $value => $text) {
  418. // list of folders (boxes array)
  419. //
  420. if (is_array($text)) {
  421. $option_list = array_merge($option_list, sqimap_mailbox_option_array(0, 0, $text, $this->folder_filter));
  422. // just one option here
  423. //
  424. } else {
  425. $option_list = array_merge($option_list, array($value => $text));
  426. }
  427. }
  428. if (empty($option_list))
  429. $option_list = array('ignore' => _("unavailable"));
  430. return addSelect('new_' . $this->name, $option_list, $this->value, TRUE, $this->aExtraAttribs, $multiple_select, $height) . htmlspecialchars($this->trailing_text);
  431. }
  432. /**
  433. * Creates textarea
  434. * @return string html formated textarea field
  435. */
  436. function createWidget_TextArea() {
  437. switch ($this->size) {
  438. case SMOPT_SIZE_TINY: $rows = 3; $cols = 10; break;
  439. case SMOPT_SIZE_SMALL: $rows = 4; $cols = 30; break;
  440. case SMOPT_SIZE_LARGE: $rows = 10; $cols = 60; break;
  441. case SMOPT_SIZE_HUGE: $rows = 20; $cols = 80; break;
  442. case SMOPT_SIZE_NORMAL:
  443. default: $rows = 5; $cols = 50;
  444. }
  445. return addTextArea('new_' . $this->name, $this->value, $cols, $rows, $this->aExtraAttribs);
  446. }
  447. /**
  448. * Creates field for integer
  449. *
  450. * Difference from createWidget_String is visible only when javascript is enabled
  451. * @return string html formated option field
  452. */
  453. function createWidget_Integer() {
  454. // add onChange javascript handler to a regular string widget
  455. // which will strip out all non-numeric chars
  456. if (checkForJavascript())
  457. $this->aExtraAttribs['onchange'] = 'origVal=this.value; newVal=\'\'; '
  458. . 'for (i=0;i<origVal.length;i++) { if (origVal.charAt(i)>=\'0\' '
  459. . '&& origVal.charAt(i)<=\'9\') newVal += origVal.charAt(i); } '
  460. . 'this.value=newVal;';
  461. return $this->createWidget_String();
  462. }
  463. /**
  464. * Creates field for floating number
  465. * Difference from createWidget_String is visible only when javascript is enabled
  466. * @return string html formated option field
  467. */
  468. function createWidget_Float() {
  469. // add onChange javascript handler to a regular string widget
  470. // which will strip out all non-numeric (period also OK) chars
  471. if (checkForJavascript())
  472. $this->aExtraAttribs['onchange'] = 'origVal=this.value; newVal=\'\'; '
  473. . 'for (i=0;i<origVal.length;i++) { if ((origVal.charAt(i)>=\'0\' '
  474. . '&& origVal.charAt(i)<=\'9\') || origVal.charAt(i)==\'.\') '
  475. . 'newVal += origVal.charAt(i); } this.value=newVal;';
  476. return $this->createWidget_String();
  477. }
  478. /**
  479. * Creates radio field (yes/no)
  480. * @return string html formated radio field
  481. */
  482. function createWidget_Boolean() {
  483. global $oTemplate, $nbsp;
  484. /* Build the yes choice. */
  485. $yes_option = addRadioBox('new_' . $this->name, ($this->value != SMPREF_NO), SMPREF_YES, array_merge(array('id' => 'new_' . $this->name . '_yes'), $this->aExtraAttribs)) . $nbsp . create_label(_("Yes"), 'new_' . $this->name . '_yes');
  486. /* Build the no choice. */
  487. $no_option = addRadioBox('new_' . $this->name, ($this->value == SMPREF_NO), SMPREF_NO, array_merge(array('id' => 'new_' . $this->name . '_no'), $this->aExtraAttribs)) . $nbsp . create_label(_("No"), 'new_' . $this->name . '_no');
  488. /* Build and return the combined "boolean widget". */
  489. $result = "$yes_option$nbsp$nbsp$nbsp$nbsp$no_option";
  490. return ($result);
  491. }
  492. /**
  493. * Creates hidden field
  494. * @return string html formated hidden input field
  495. */
  496. function createWidget_Hidden() {
  497. return addHidden('new_' . $this->name, $this->value, $this->aExtraAttribs);
  498. }
  499. /**
  500. * Creates comment
  501. * @return string comment
  502. */
  503. function createWidget_Comment() {
  504. $result = $this->comment;
  505. return ($result);
  506. }
  507. /**
  508. * Creates an edit list
  509. * @return string html formated list of edit fields and
  510. * their associated controls
  511. */
  512. function createWidget_EditList() {
  513. global $oTemplate;
  514. switch ($this->size) {
  515. //FIXME: not sure about these sizes... seems like we could add another on the "large" side...
  516. case SMOPT_SIZE_TINY:
  517. $height = 3;
  518. break;
  519. case SMOPT_SIZE_SMALL:
  520. $height = 8;
  521. break;
  522. case SMOPT_SIZE_LARGE:
  523. $height = 15;
  524. break;
  525. case SMOPT_SIZE_HUGE:
  526. $height = 25;
  527. break;
  528. case SMOPT_SIZE_NORMAL:
  529. default:
  530. $height = 5;
  531. }
  532. if (empty($this->possible_values)) $this->possible_values = array();
  533. //FIXME: $this->aExtraAttribs probably should only be used in one place
  534. $oTemplate->assign('input_widget', addInput('add_' . $this->name, '', 38, 0, $this->aExtraAttribs));
  535. $oTemplate->assign('trailing_text', $this->trailing_text);
  536. $oTemplate->assign('select_widget', addSelect('new_' . $this->name, $this->possible_values, $this->value, FALSE, !checkForJavascript() ? $this->aExtraAttribs : array_merge(array('onchange' => 'if (typeof(window.addinput) == \'undefined\') { var f = document.forms.length; var i = 0; var pos = -1; while( pos == -1 && i < f ) { var e = document.forms[i].elements.length; var j = 0; while( pos == -1 && j < e ) { if ( document.forms[i].elements[j].type == \'text\' && document.forms[i].elements[j].name == \'add_' . $this->name . '\' ) { pos = j; } j++; } i++; } if( pos >= 0 ) { window.addinput = document.forms[i-1].elements[pos]; } } for (x = 0; x < this.length; x++) { if (this.options[x].selected) { window.addinput.value = this.options[x].value; break; } }'), $this->aExtraAttribs), TRUE, $height));
  537. $oTemplate->assign('checkbox_widget', addCheckBox('delete_' . $this->name, FALSE, SMPREF_YES, array_merge(array('id' => 'delete_' . $this->name), $this->aExtraAttribs)));
  538. $oTemplate->assign('name', $this->name);
  539. return $oTemplate->fetch('edit_list_widget.tpl');
  540. }
  541. /**
  542. *
  543. */
  544. function save() {
  545. $function = $this->save_function;
  546. $function($this);
  547. }
  548. /**
  549. *
  550. */
  551. function changed() {
  552. // edit lists have a lot going on, so we'll always process them
  553. //
  554. if ($this->type == SMOPT_TYPE_EDIT_LIST) return TRUE;
  555. return ($this->value != $this->new_value);
  556. }
  557. } /* End of SquirrelOption class*/
  558. /**
  559. * Saves the option value (this is the default save function
  560. * unless overridden by the user)
  561. *
  562. * @param object $option object that holds option name and new_value
  563. */
  564. function save_option($option) {
  565. // Can't save the pref if we don't have the username
  566. //
  567. if ( !sqgetGlobalVar('username', $username, SQ_SESSION ) ) {
  568. return;
  569. }
  570. global $data_dir;
  571. // edit lists: first add new elements to list, then
  572. // remove any selected ones (note that we must add
  573. // before deleting because the javascript that populates
  574. // the "add" textbox when selecting items in the list
  575. // (for deletion))
  576. //
  577. if ($option->type == SMOPT_TYPE_EDIT_LIST) {
  578. // add element if given
  579. //
  580. if (sqGetGlobalVar('add_' . $option->name, $new_element, SQ_POST)) {
  581. $new_element = trim($new_element);
  582. if (!empty($new_element)
  583. && !in_array($new_element, $option->possible_values))
  584. $option->possible_values[] = $new_element;
  585. }
  586. // delete selected elements if needed
  587. //
  588. if (is_array($option->new_value)
  589. && sqGetGlobalVar('delete_' . $option->name, $ignore, SQ_POST))
  590. $option->possible_values = array_diff($option->possible_values, $option->new_value);
  591. // save full list (stored in "possible_values")
  592. //
  593. setPref($data_dir, $username, $option->name, serialize($option->possible_values));
  594. // Certain option types need to be serialized because
  595. // they are not scalar
  596. //
  597. } else if ($option->type == SMOPT_TYPE_FLDRLIST_MULTI
  598. || $option->type == SMOPT_TYPE_STRLIST_MULTI)
  599. setPref($data_dir, $username, $option->name, serialize($option->new_value));
  600. else
  601. setPref($data_dir, $username, $option->name, $option->new_value);
  602. }
  603. /**
  604. * save function that does not save
  605. * @param object $option
  606. */
  607. function save_option_noop($option) {
  608. /* Do nothing here... */
  609. }
  610. /**
  611. * Create hidden 'optpage' input field with value set by argument
  612. * @param string $optpage identification of option page
  613. * @return string html formated hidden input field
  614. */
  615. function create_optpage_element($optpage) {
  616. return addHidden('optpage', $optpage);
  617. }
  618. /**
  619. * Create hidden 'optmode' input field with value set by argument
  620. * @param string $optmode
  621. * @return string html formated hidden input field
  622. */
  623. function create_optmode_element($optmode) {
  624. return addHidden('optmode', $optmode);
  625. }
  626. /**
  627. * @param array $optgrps
  628. * @param array $optvals
  629. * @return array
  630. */
  631. function create_option_groups($optgrps, $optvals) {
  632. /* Build a simple array with which to start. */
  633. $result = array();
  634. /* Create option group for each option group name. */
  635. foreach ($optgrps as $grpkey => $grpname) {
  636. $result[$grpkey] = array();
  637. $result[$grpkey]['name'] = $grpname;
  638. $result[$grpkey]['options'] = array();
  639. }
  640. /* Create a new SquirrelOption for each set of option values. */
  641. foreach ($optvals as $grpkey => $grpopts) {
  642. foreach ($grpopts as $optset) {
  643. /* Create a new option with all values given. */
  644. $next_option = new SquirrelOption(
  645. $optset['name'],
  646. $optset['caption'],
  647. $optset['type'],
  648. (isset($optset['refresh']) ? $optset['refresh'] : SMOPT_REFRESH_NONE),
  649. (isset($optset['initial_value']) ? $optset['initial_value'] : ''),
  650. (isset($optset['posvals']) ? $optset['posvals'] : ''),
  651. (isset($optset['htmlencoded']) ? $optset['htmlencoded'] : false)
  652. );
  653. /* If provided, set the size for this option. */
  654. if (isset($optset['size'])) {
  655. $next_option->setSize($optset['size']);
  656. }
  657. /* If provided, set the trailing_text for this option. */
  658. if (isset($optset['trailing_text'])) {
  659. $next_option->setTrailingText($optset['trailing_text']);
  660. }
  661. /* If provided, set the comment for this option. */
  662. if (isset($optset['comment'])) {
  663. $next_option->setComment($optset['comment']);
  664. }
  665. /* If provided, set the save function for this option. */
  666. if (isset($optset['save'])) {
  667. $next_option->setSaveFunction($optset['save']);
  668. }
  669. /* If provided, set the extra attributes for this option. */
  670. if (isset($optset['extra_attributes'])) {
  671. $next_option->setExtraAttributes($optset['extra_attributes']);
  672. }
  673. /* If provided, set the "post script" for this option. */
  674. if (isset($optset['post_script'])) {
  675. $next_option->setPostScript($optset['post_script']);
  676. }
  677. /* If provided, set the folder_filter for this option. */
  678. if (isset($optset['folder_filter'])) {
  679. $next_option->setFolderFilter($optset['folder_filter']);
  680. }
  681. /* Add this option to the option array. */
  682. $result[$grpkey]['options'][] = $next_option;
  683. }
  684. }
  685. /* Return our resulting array. */
  686. return ($result);
  687. }