Source for file configuration-defs.php

Documentation is available at configuration-defs.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: configuration-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Definitions for generic config maintenance */
  24. /* */
  25. /* ******************************************************************** */
  26. /** @package config */* Configuration
  27. * This is for accessing generic configuration files which store
  28. * useful crappola like GST rate, file paths etc. This object features
  29. * dynamically creatable/deletable configuration fields.
  30. *
  31. * Eg. Usage (single-level configuration):
  32. * $conf = new configuration("myconfigname");
  33. * $avar = $conf->value("gstrate");
  34.  
  35. * Eg. Usage (dual-level config, user preferences example):
  36. * $conf = new configuration("userprefs", "matthew");
  37. * $avar = $conf->value("background_colour");
  38. * // Example of changing it..
  39. * $conf->set_value("background_colour", "#fefefe");
  40. * $conf->put();
  41. * @package config
  42. */
  43. class configuration extends RenderableObject {
  44. // Public
  45. /** The name of the current configuration */
  46.  
  47. var $config_name = "default";
  48. /** Identity if the current configuration */
  49.  
  50. var $config_id = "default";
  51. /** Array of configfield objects for the config */
  52.  
  53. var $fields;
  54. /** Set of configuration fields/values in this configuration set */
  55.  
  56. var $set;
  57.  
  58. // Private
  59. /** Mode to display the configuration in a form
  60. @access private */
  61. var $form_mode = "edit";
  62. /** Whether config definition exists in database or not
  63. @access private */
  64. var $db_config_exists = false;
  65. /** Whether the configuration exists in database or not
  66. @access private */
  67. var $db_configuration_exists = false;
  68. /** Whether field definitions have changed or not
  69. @access private */
  70. var $fieldschanged = false;
  71. /** Whether configuration data has changed or not
  72. @access private */
  73. var $setchanged = false;
  74. /** Whether to show buttons on forms and auto-process POST or not
  75. @access private */
  76. var $autoconfigurate = false;
  77. // ....................................................................
  78. /**
  79. * Constructor
  80. * Create a new configuration object. Sets basic field attributes.
  81. * @param string $name The name of the config.
  82. * @param string $id The identity of the configuration set in the config
  83. * @param bool $auto If true, put the configuration object into autoconfigure mode
  84. */
  85. function configuration($name="default", $id="default", $auto=false) {
  86. // Read it all from disk..
  87. $this->get($name, $id);
  88. if ($auto) {
  89. $this->autoconfigurate = true;
  90. // Check for POSTings..
  91. $this->POSTprocess();
  92. }
  93. } // configuration
  94. // ....................................................................
  95. /**
  96. * Get the configuration set.
  97. * Retreives the specified configuration set from database.
  98. * @param string $name The name of the config.
  99. * @param string $id The identity of the configuration set in the config
  100. */
  101. function get($name, $id) {
  102. $this->config_name = $name;
  103. $this->config_id = $id;
  104. // Try and find it..
  105. $q = "SELECT * FROM ax_config";
  106. $q .= " WHERE config_name='" . escape_string($name) . "'";
  107. $stq = dbrecordset($q);
  108. if ($stq->hasdata) {
  109. $this->fields = unserialize($stq->field("config_fields"));
  110. $this->db_config_exists = true;
  111. // Retrieve possible set..sys_control
  112. $q = "SELECT * FROM ax_configuration";
  113. $q .= " WHERE config_name='" . escape_string($name) . "'";
  114. $q .= " AND config_id='" . escape_string($id) . "'";
  115. $ssq = dbrecordset($q);
  116. if ($ssq->hasdata) {
  117. $this->set = unserialize($ssq->field("config_set"));
  118. $this->db_configuration_exists = true;
  119. }
  120. else {
  121. $this->db_configuration_exists = false;
  122. if ($this->field_count() > 0) {
  123. // Re-create bogus empty set from scratch..
  124. foreach($this->fields as $field) {
  125. $this->set_value($field->name, $field->defaultvalue());
  126. }
  127. }
  128. }
  129. }
  130. else {
  131. $this->db_config_exists = false;
  132. }
  133. // Return true if at least the config exists..
  134. return $this->db_config_exists;
  135. } // get
  136. // ....................................................................
  137. /**
  138. * Save the config.
  139. * Save this config to the database. Create a new one if it
  140. * doesn't already exist.
  141. */
  142. function put() {
  143. // Deal with brand new config..
  144. if (!$this->db_config_exists) {
  145. $sq = new dbinsert("ax_config");
  146. $sq->set("config_name", $this->config_name);
  147. $sq->set("config_fields", serialize($this->fields));
  148. $sq->execute();
  149. $this->fieldschanged = false;
  150. $this->db_config_exists = true;
  151. }
  152. // Deal with brand new configuration..
  153. if (!$this->db_configuration_exists) {
  154. $sq = new dbinsert("ax_configuration");
  155. $sq->set("config_name", $this->config_name);
  156. $sq->set("config_id", $this->config_id);
  157. $sq->set("config_set", serialize($this->set));
  158. $sq->execute();
  159. $this->setchanged = false;
  160. $this->db_configuration_exists = true;
  161. }
  162.  
  163. // Save updates to database copy..
  164. if ($this->fieldschanged) {
  165. $sq = new dbupdate("ax_config");
  166. $sq->set("config_fields", serialize($this->fields));
  167. $sq->where("config_name='" . escape_string($this->config_name) . "'");
  168. $sq->execute();
  169. $this->fieldschanged = false;
  170. }
  171. if ($this->setchanged) {
  172. $sq = new dbupdate("ax_configuration");
  173. $sq->set("config_set", serialize($this->set));
  174. $sq->where("config_name='" . escape_string($this->config_name) . "'");
  175. $sq->where("and config_id='" . escape_string($this->config_id) . "'");
  176. $sq->execute();
  177. $this->setchanged = false;
  178. }
  179. } // put
  180. // ....................................................................
  181. /**
  182. * Delete the whole config.
  183. * Delete this config from the database.
  184. */
  185. function delete() {
  186. // RI wil delete the sets of this config..
  187. $del = new dbdelete("ax_config");
  188. $del->where("config_name='" . escape_string($this->config_name) . "'");
  189. $del->execute();
  190. } // delete
  191. // ....................................................................
  192. /**
  193. * Return fields present count.
  194. * @return integer Count of fields current defined in this config
  195. */
  196. function field_count() {
  197. $res = 0;
  198. if (isset($this->fields)) {
  199. $res = count($this->fields);
  200. }
  201. return $res;
  202. } // field_count
  203. // ....................................................................
  204. /**
  205. * Check if field exists
  206. * @param string $fname The name of the field to check.
  207. * @return bool True if named field exists in this configuration
  208. */
  209. function field_exists($fname) {
  210. $fname = str_replace(" ", "_", $fname);
  211. return (isset($this->fields) && isset($this->fields[$fname]));
  212. } // field_exists
  213. // ....................................................................
  214. /**
  215. * Insert a new field into this config.
  216. * This is just a raw routine for inserting a field in this config set.
  217. * @param string $fname Name of the new field
  218. * @param string $ftype Var type: 'text','numeric','bool', or 'datetime'
  219. * @param string $flist List of allowed values, if any
  220. * @param string $default Default value, if any
  221. * @access private
  222. */
  223. function field_insert($fname, $ftype="text", $flist="", $default="???") {
  224. $fname = str_replace(" ", "_", $fname);
  225. if (!$this->field_exists($fname)) {
  226. $this->fields[$fname] = new configfield($fname, $ftype, $flist, $default);
  227. $this->fieldschanged = true;
  228. }
  229. } // field_insert
  230. // ....................................................................
  231. /**
  232. * Delete a field from this config set.
  233. * @param string $fname Name of the field to delete.
  234. * @access private
  235. */
  236. function field_delete($fname) {
  237. $fname = str_replace(" ", "_", $fname);
  238. if ($this->field_exists($fname)) {
  239. // Get rid of local variable..
  240. if (isset($this->set[$fname])) {
  241. unset($this->set[$fname]);
  242. $this->setchanged = true;
  243. }
  244. // Get rid of the field..
  245. if (isset($this->fields[$fname])) {
  246. unset($this->fields[$fname]);
  247. $this->fieldschanged = true;
  248. }
  249. }
  250. } // field_delete
  251. // ....................................................................
  252. /**
  253. * Create a new field for all configurations
  254. * This retro-fits all sets of this config with the new field, and
  255. * will assign the default value to each one.
  256. * @param string $fname Name of the new field
  257. * @param string $ftype Var type: 'text','numeric','bool', or 'datetime'
  258. * @param string $flist List of allowed values, if any
  259. * @param string $default Default value, if any
  260. */
  261. function field_create($fname, $ftype="text", $flist="", $default="???") {
  262. if ($fname != "") {
  263. // Insert the field locally..
  264. $fname = str_replace(" ", "_", $fname);
  265. $this->field_insert($fname, $ftype, $flist, $default);
  266.  
  267. // Insert it for all other configurations..
  268. $f = $this->fields[$fname];
  269. $initialval = $f->defaultvalue();
  270. $this->set_value($fname, $initialval);
  271. $q = "SELECT * FROM ax_configuration";
  272. $q .= " WHERE config_name='" . escape_string($this->config_name) . "'";
  273. $q .= " AND config_id <> '" . escape_string($this->config_id) . "'";
  274. $sets = dbrecordset($q);
  275. if ($sets->hasdata) {
  276. start_transaction();
  277. do {
  278. $configid = $sets->field("config_id");
  279. $configuration = new configuration($this->config_name, $configid);
  280. $configuration->field_insert($fname, $ftype, $flist, $default);
  281. $configuration->set_value($fname, $initialval);
  282. $configuration->put();
  283. } while ($sets->get_next());
  284. commit();
  285. }
  286. }
  287. } // field_create
  288. // ....................................................................
  289. /**
  290. * Remove a field from all sets of this config.
  291. * @param string $fname Name of the field to remove from all configurations
  292. */
  293. function field_remove($fname) {
  294. $fname = str_replace(" ", "_", $fname);
  295. if ($this->field_exists($fname)) {
  296. // Delete it locally..
  297. $this->field_delete($fname);
  298. $this->put();
  299.  
  300. // Delete it for all other sets in the configuration..
  301. $q = "SELECT * FROM ax_configuration";
  302. $q .= " WHERE config_name='" . escape_string($this->config_name) . "'";
  303. $q .= " AND config_id <> '" . escape_string($this->config_id) . "'";
  304. $sets = dbrecordset($q);
  305. if ($sets->hasdata) {
  306. start_transaction();
  307. do {
  308. $configid = $sets->field("config_id");
  309. $configuration = new configuration($this->config_name, $configid);
  310. $configuration->field_delete($fname);
  311. $configuration->put();
  312. } while ($sets->get_next());
  313. commit();
  314. }
  315. }
  316. } // field_remove
  317. // ....................................................................
  318. /**
  319. * Put a value in a field, in a set of the config.
  320. * @param string $name Name of the field
  321. * @param string $value Value to assign to the variable
  322. */
  323. function set_value($fname, $fvalue="") {
  324. $fname = str_replace(" ", "_", $fname);
  325. if ($this->field_exists($fname)) {
  326. $field = $this->fields[$fname];
  327. switch ($field->type) {
  328. case "text":
  329. break;
  330. case "textarea":
  331. break;
  332. case "numeric":
  333. if (!is_numeric($fvalue)) {
  334. $fvalue = 0;
  335. }
  336. break;
  337. case "bool":
  338. if ($fvalue) {
  339. $fvalue = true;
  340. }
  341. else {
  342. $fvalue = false;
  343. }
  344. break;
  345. case "datetime":
  346. if ($fvalue == "") {
  347. $fvalue = timestamp_to_datetime(); // Now
  348. }
  349. else {
  350. $fvalue = displaydate_to_datetime($fvalue);
  351. }
  352. break;
  353. } // switch
  354. // Set the value now..
  355. $this->set[$fname] = $fvalue;
  356. $this->setchanged = true;
  357. }
  358. } // set_value
  359. // ....................................................................
  360. /**
  361. * Get value from a field in a set of the config.
  362. * @param string $name Name of the field to get value of
  363. * @return mixed The value of the given field in the given set
  364. */
  365. function value($fname) {
  366. $fname = str_replace(" ", "_", $fname);
  367. if ($this->field_exists($fname)) {
  368. $field = $this->fields[$fname];
  369. switch ($field->type) {
  370. case "datetime":
  371. $fvalue = datetime_to_displaydate(POSTGRES_STD_FORMAT, $this->set[$fname]);
  372. break;
  373. default:
  374. $fvalue = $this->set[$fname];
  375. } // switch
  376. return $fvalue;
  377. }
  378. return "";
  379. } // value
  380. // ....................................................................
  381. /**
  382. * Render a set of the config as a subform.
  383. * Render all the values of the given set of the config as stacked form
  384. * elements in a table. Since this is a subform the form tags are
  385. * not rendered.
  386. * @return string The HTML
  387. * @access private
  388. */
  389. function editform() {
  390. global $LIBDIR;
  391. global $RESPONSE;
  392. $s = "";
  393. $editForm = new subform();
  394. if ($this->field_count() > 0) {
  395. reset($this->fields);
  396. foreach ($this->fields as $field) {
  397. $fvalue = $this->value($field->name);
  398. $fdispname = str_replace("_", " ", $field->name);
  399. if (isset($f)) unset($f);
  400. switch ($field->type) {
  401. case "text":
  402. case "numeric":
  403. if ($field->list != "") {
  404. $options = explode(",", $field->list);
  405. $f = new form_combofield($field->name, $fdispname, $fvalue);
  406. $f->setclass("axcombo");
  407. foreach ($options as $option) {
  408. $f->additem($option);
  409. }
  410. }
  411. else {
  412. $f = new form_textfield($field->name, $fdispname, $fvalue);
  413. if ($field->type == "text") {
  414. $f->setclass("axtxtbox");
  415. }
  416. else {
  417. $f->setclass("axnumbox");
  418. }
  419. }
  420. break;
  421. case "textarea":
  422. $f = new form_memofield($field->name, $fdispname, $fvalue);
  423. $f->setclass("axmemo");
  424. break;
  425. case "bool":
  426. $f = new form_checkbox($field->name, $fdispname);
  427. $f->checked = $fvalue;
  428. $f->setclass("axchkbox");
  429. break;
  430. case "datetime":
  431. $f = new form_textfield($field->name, $fdispname, datetime_to_displaydate(DISPLAY_DATE_FORMAT, $fvalue));
  432. $f->setclass("axdatetime");
  433. break;
  434. } // switch
  435. // Add form field to our form..
  436. if (isset($f)) $editForm->add($f);
  437. } // foreach
  438. }
  439. else {
  440. $s .= "<p>There are currently no data fields defined.</p>";
  441. }
  442. $editForm->add(new form_hiddenfield("_configaction", "edit"));
  443. if ($this->autoconfigurate) {
  444. if ($this->field_count() > 0) {
  445. $editForm->add_button(new image_button("_cfgsave","","","", "$LIBDIR/img/_save.gif",57,15,"Save",0));
  446. }
  447. if (!isset($RESPONSE) || $RESPONSE->ismemberof_group("Admin")) {
  448. $editForm->add_button(new image_button("_cfgadd","","","", "$LIBDIR/img/_add.gif",57,15,"Add",0));
  449. if ($this->field_count() > 0) {
  450. $editForm->add_button(new image_button("_cfgdelete","","","", "$LIBDIR/img/_delete.gif",57,15,"Add",0));
  451. }
  452. }
  453. }
  454.  
  455. // Render the form..
  456. $s .= $editForm->render();
  457.  
  458. // Return the html..
  459. return $s;
  460. } // editform
  461. // ....................................................................
  462. /**
  463. * Return a create configfield subform
  464. * Returns the HTML for a subform which will allow the user to
  465. * specify a new configfield.
  466. * @return string The HTML of the subform to create a new config field
  467. * @access private
  468. */
  469. function addform() {
  470. global $LIBDIR;
  471. global $RESPONSE;
  472. $addForm = new subform();
  473. $addForm->add_text("<b>Add new configuration field:</b>");
  474. $addForm->add(new form_textfield("new_fname", "Field name"));
  475. $f = new form_combofield("new_ftype", "Field type", "text");
  476. $f->additem("text", "Text");
  477. $f->additem("textarea", "Textarea");
  478. $f->additem("numeric", "Numeric");
  479. $f->additem("bool", "Boolean");
  480. $f->additem("datetime", "Date/time");
  481. $addForm->add($f);
  482. $addForm->add(new form_textfield("new_fvalue", "Initial value", "", EDITABLE, "axtxtbox"));
  483. $addForm->add(new form_textfield("new_allowed_values", "Allowed values", "", EDITABLE, "axtxtbox"));
  484. $addForm->add(new form_labelfield("", "<small><em>(optional list of comma-delimited values)</em></small>"));
  485. $addForm->add(new form_textfield("new_fdefault", "Default value", "", EDITABLE, "axtxtbox"));
  486. $addForm->add(new form_hiddenfield("_configaction", "add"));
  487. if ($this->autoconfigurate) {
  488. if (!isset($RESPONSE) || $RESPONSE->ismemberof_group("Admin")) {
  489. $addForm->add_button(new image_button("_cfgaddit","","","", "$LIBDIR/img/_add.gif",57,15,"Add",0));
  490. }
  491. $addForm->add_button(new image_button("_cfgcancel","","","", "$LIBDIR/img/_cancel.gif",57,15,"Cancel",0));
  492. }
  493. return $addForm->render();
  494. } // addform
  495. // ....................................................................
  496. /**
  497. * Return a delete configfield subform
  498. * Returns the HTML for a subform which will allow the user to
  499. * specify a field to remove from the configuration set.
  500. * @return string The HTML of the subform to specify config field to delete
  501. * @access private
  502. */
  503. function deleteform() {
  504. global $LIBDIR;
  505. $delForm = new subform();
  506. $delForm->add_text("<b>Delete configuration field:</b>");
  507. $delcombo = new form_combofield("delete_fname", "Field name to delete");
  508. reset($this->fields);
  509. foreach($this->fields as $field) {
  510. $fdispname = str_replace("_", " ", $field->name);
  511. $delcombo->additem($field->name, $fdispname);
  512. }
  513. $delForm->add($delcombo);
  514. $delForm->add(new form_hiddenfield("_configaction", "delete"));
  515. if ($this->autoconfigurate) {
  516. if (!isset($RESPONSE) || $RESPONSE->ismemberof_group("Admin")) {
  517. $delForm->add_button(new image_button("_cfgdeleteit","","","", "$LIBDIR/img/_delete.gif",57,15,"Delete",0));
  518. }
  519. $delForm->add_button(new image_button("_cfgcancel","","","", "$LIBDIR/img/_cancel.gif",57,15,"Cancel",0));
  520. }
  521. return $delForm->render();
  522. } // deleteform
  523. // ....................................................................
  524. /**
  525. * Render this configuration.
  526. * depending on which form_mode we are in, we render the configuration
  527. * as an edit form, an add form, or a delete form.
  528. * @return string The HTML of the subform for this configuration action
  529. */
  530. function html() {
  531. // If we are debugging then dump the raw stuff out
  532. // of our config out at this point in DBG_DUMP mode..
  533. switch($this->form_mode) {
  534. case "add":
  535. return $this->addform();
  536. break;
  537. case "delete":
  538. return $this->deleteform();
  539. break;
  540. default:
  541. return $this->editform();
  542. } // switch
  543. } // html
  544. // ....................................................................
  545. /**
  546. * Process a subform POST.
  547. * Assume that the fields have been submitted in a form as named
  548. * in the config, and grab the POSTed values.
  549. * @param text $id The identity of the set to update from POST
  550. * @access private
  551. */
  552. function POSTprocess() {
  553. global $HTTP_POST_VARS;
  554. global $_cfgsave_x, $_cfgadd_x, $_cfgdelete_x, $_cfgcancel_x;
  555. global $_cfgaddit_x, $_cfgdeleteit_x;
  556. $postingaction = false;
  557. if (isset($HTTP_POST_VARS["_configaction"])) {
  558. $action = $HTTP_POST_VARS["_configaction"];
  559. switch($action) {
  560. case "add":
  561. if (!$this->autoconfigurate || isset($_cfgaddit_x)) {
  562. $fname = $HTTP_POST_VARS["new_fname"];
  563. if ($fname != "") {
  564. debugbr("Adding new element '$fname' !");
  565. $this->field_create(
  566. $fname,
  567. $HTTP_POST_VARS["new_ftype"],
  568. $HTTP_POST_VARS["new_allowed_values"],
  569. $HTTP_POST_VARS["new_fdefault"]
  570. );
  571. $this->set_value(
  572. $HTTP_POST_VARS["new_fname"],
  573. $HTTP_POST_VARS["new_fvalue"]
  574. );
  575. $postingaction = true;
  576. }
  577. }
  578. $this->form_mode = "edit";
  579. break;
  580.  
  581. case "delete":
  582. if (!$this->autoconfigurate || isset($_cfgdeleteit_x)) {
  583. $fname = $HTTP_POST_VARS["delete_fname"];
  584. if ($fname != "") {
  585. debugbr("Deleting element '$delete_fname' !");
  586. $this->field_remove($fname);
  587. $postingaction = true;
  588. }
  589. }
  590. $this->form_mode = "edit";
  591. break;
  592.  
  593. case "edit":
  594. if (!$this->autoconfigurate || isset($_cfgsave_x)) {
  595. if (isset($this->fields)) {
  596. reset($this->fields);
  597. foreach ($this->fields as $field) {
  598. $fname = $field->name;
  599. debugbr("POSTprocess: checking field '$fname'");
  600. switch ($field->type) {
  601. case "bool":
  602. if (isset($HTTP_POST_VARS[$fname])) $fvalue = true;
  603. else $fvalue = false;
  604. break;
  605. default:
  606. $fvalue = $HTTP_POST_VARS[$fname];
  607. } // switch
  608. $this->set_value($fname, $fvalue);
  609. $postingaction = true;
  610. } // foreach
  611. }
  612. $this->form_mode = "edit";
  613. }
  614. elseif (isset($_cfgdelete_x)) {
  615. $this->form_mode = "delete";
  616. }
  617. elseif (isset($_cfgadd_x)) {
  618. $this->form_mode = "add";
  619. }
  620. break;
  621. } // switch
  622. }
  623. // Save the thing if we changed something..
  624. if ($postingaction) {
  625. $this->put();
  626. }
  627. } // POSTprocess
  628.  
  629.  
  630.  
  631. } // configuration class
  632. // ----------------------------------------------------------------------
  633.  
  634. /**
  635. * The configurator class is simply a descendant class of configuration
  636. * which sets the parent class into 'autoconfigure' mode. In this mode
  637. * the forms have buttons supplied, and the instantiation of the class
  638. * automatically processes form POSTs.
  639. * @package config
  640. */
  641. class configurator extends configuration {
  642. /**
  643. * Constructor
  644. *
  645. * Create a new configurator object.
  646. * @param string $name The name of the config.
  647. * @param string $id The identity of the configuration set in the config
  648. */
  649. function configurator($name="default", $id="default") {
  650. $this->configuration($name, $id, true);
  651. } // configurator
  652.  
  653.  
  654.  
  655. } // configurator class
  656. // ----------------------------------------------------------------------
  657.  
  658. /**
  659. ** A Configuration field.
  660. * @package config
  661. */
  662. class configfield {
  663. var $name;
  664. var $type;
  665. var $list;
  666. var $default;
  667. /** Constructor.
  668. * Create a config field.
  669. * @param string $fname Name of the field
  670. * @param string $ftype Type of field: 'text', 'numeric', 'bool', or 'datetime'
  671. * @param string $flist List of permitted values, if appropriate
  672. */
  673. function configfield($fname, $ftype="text", $flist="", $default="???") {
  674. $this->name = $fname;
  675. $this->type = $ftype;
  676. $this->list = $flist;
  677. if ($default != "???") {
  678. if ($ftype == "bool") {
  679. $this->default = ($default == "true" || $default == "t" || $default == "1");
  680. }
  681. else $this->default = $default;
  682. }
  683. else {
  684. switch ($ftype) {
  685. case "text":
  686. case "textarea":
  687. $this->default = "";
  688. break;
  689. case "numeric":
  690. $this->default = 0;
  691. break;
  692. case "bool":
  693. $this->default = false;
  694. break;
  695. } // switch
  696. }
  697. }
  698. /** Return the default field value */
  699.  
  700. function defaultvalue() {
  701. if (isset($this->default)) {
  702. return $this->default;
  703. }
  704. elseif ($this->type == "datetime") {
  705. return timestamp_to_datetime();
  706. }
  707. return "";
  708. }
  709. }
  710.  
  711. // ----------------------------------------------------------------------
  712. ?>

Documentation generated by phpDocumentor 1.3.0RC3