PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/campsite/src/include/phorum/docs/example_mods/example_settings/settings.php

https://github.com/joechrysler/Campsite
PHP | 64 lines | 32 code | 13 blank | 19 comment | 13 complexity | 7b91450661110bfb7eaf0e510dde5bb6 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, LGPL-2.1, Apache-2.0
  1. <?php
  2. // Make sure that this script is loaded from the admin interface.
  3. if(!defined("PHORUM_ADMIN")) return;
  4. // Save settings in case this script is run after posting
  5. // the settings form.
  6. if(count($_POST))
  7. {
  8. // Create the settings array for this module.
  9. $PHORUM["mod_example_settings"] = array(
  10. "displaytext" => $_POST["displaytext"],
  11. "displaycount" => $_POST["displaycount"],
  12. );
  13. // Force the displaycount to be an integer value.
  14. settype($PHORUM["mod_example_settings"]["displaycount"], "int");
  15. if(! phorum_db_update_settings(array("mod_example_settings"=>$PHORUM["mod_example_settings"]))) {
  16. $error="Database error while updating settings.";
  17. } else {
  18. echo "Settings Updated<br />";
  19. }
  20. }
  21. // Apply default values for the settings.
  22. if (!isset($PHORUM["mod_example_settings"]["displaytext"]))
  23. $PHORUM["mod_example_settings"]["displaytext"] = "";
  24. if (!isset($PHORUM["mod_example_settings"]["displaycount"]))
  25. $PHORUM["mod_example_settings"]["displaycount"] = 1;
  26. // We build the settings form by using the PhorumInputForm object. When
  27. // creating your own settings screen, you'll only have to change the
  28. // "mod" hidden parameter to the name of your own module.
  29. include_once "./include/admin/PhorumInputForm.php";
  30. $frm = new PhorumInputForm ("", "post", "Save");
  31. $frm->hidden("module", "modsettings");
  32. $frm->hidden("mod", "example_settings");
  33. // Here we display an error in case one was set by saving
  34. // the settings before.
  35. if (!empty($error)) {
  36. echo "$error<br />";
  37. }
  38. // This adds a break line to your form, with a description on it.
  39. // You can use this to separate your form into multiple sections.
  40. $frm->addbreak("Edit settings for the example_settings module");
  41. // This adds a text message to your form. You can use this to
  42. // explain things to the user.
  43. $frm->addmessage("This is the settings screen for the example_settings module. This module is only written for demonstrating the use of a settings screen for you own modules. The module itself will display a configurable text for a configurable number of times on screen.");
  44. // This adds a row with a form field for entering the display text.
  45. $frm->addrow("Text to display (default: Hello, world!)", $frm->text_box('displaytext', $PHORUM["mod_example_settings"]["displaytext"], 50));
  46. // This adds another row with a form field for entering the display count.
  47. $frm->addrow("Number of times to display", $frm->text_box('displaycount', $PHORUM["mod_example_settings"]["displaycount"], 5));
  48. // We are done building the settings screen.
  49. // By calling show(), the screen will be displayed.
  50. $frm->show();
  51. ?>