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

Language PHP Lines 65
MD5 Hash 7b91450661110bfb7eaf0e510dde5bb6
Repository https://github.com/joechrysler/Campsite.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

// Make sure that this script is loaded from the admin interface.
if(!defined("PHORUM_ADMIN")) return;

// Save settings in case this script is run after posting
// the settings form.
if(count($_POST)) 
{
    // Create the settings array for this module.
    $PHORUM["mod_example_settings"] = array(
        "displaytext"  => $_POST["displaytext"],
        "displaycount" => $_POST["displaycount"],
    );

    // Force the displaycount to be an integer value. 
    settype($PHORUM["mod_example_settings"]["displaycount"], "int");

    if(! phorum_db_update_settings(array("mod_example_settings"=>$PHORUM["mod_example_settings"]))) {
        $error="Database error while updating settings.";
    } else {
        echo "Settings Updated<br />";
    }
}

// Apply default values for the settings.
if (!isset($PHORUM["mod_example_settings"]["displaytext"]))
    $PHORUM["mod_example_settings"]["displaytext"] = "";
if (!isset($PHORUM["mod_example_settings"]["displaycount"]))
    $PHORUM["mod_example_settings"]["displaycount"] = 1;

// We build the settings form by using the PhorumInputForm object. When
// creating your own settings screen, you'll only have to change the
// "mod" hidden parameter to the name of your own module.
include_once "./include/admin/PhorumInputForm.php";
$frm = new PhorumInputForm ("", "post", "Save");
$frm->hidden("module", "modsettings");
$frm->hidden("mod", "example_settings"); 

// Here we display an error in case one was set by saving 
// the settings before.
if (!empty($error)) {
    echo "$error<br />";
}

// This adds a break line to your form, with a description on it.
// You can use this to separate your form into multiple sections.
$frm->addbreak("Edit settings for the example_settings module");

// This adds a text message to your form. You can use this to 
// explain things to the user.
$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.");

// This adds a row with a form field for entering the display text.
$frm->addrow("Text to display (default: Hello, world!)", $frm->text_box('displaytext', $PHORUM["mod_example_settings"]["displaytext"], 50));

// This adds another row with a form field for entering the display count.
$frm->addrow("Number of times to display", $frm->text_box('displaycount', $PHORUM["mod_example_settings"]["displaycount"], 5));

// We are done building the settings screen.
// By calling show(), the screen will be displayed.
$frm->show();

?>
Back to Top