File: class.settings.php

package info (click to toggle)
collabtive 2.0%2Bdfsg-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,708 kB
  • ctags: 27,425
  • sloc: php: 100,872; sh: 72; makefile: 50
file content (160 lines) | stat: -rw-r--r-- 5,481 bytes parent folder | download | duplicates (2)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/*
 * The class 'settings' provides methods to deal with the global system settings
 *
 * @author Open Dynamics <info@o-dyn.de>
 * @name settings
 * @package Collabtive
 * @version 0.7.5
 * @link http://www.o-dyn.de
 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v3 or later
 */
class settings {
    public $mylog;

    /*
     * Constructor
     */
    function __construct()
    {
    }

    /*
     * Returns all global settings
     *
     * @return array $settings Global system settings
     */
    function getSettings()
    {
        global $conn;
        $selStmt = $conn->prepare("SELECT settingsKey,settingsValue FROM settings");
        $sel = $selStmt->execute(array());

        $settings = array();
        while ($selStmt and $selSettings = $selStmt->fetch()) {
            // Create a key/value array
            $settings[$selSettings["settingsKey"]] = $selSettings["settingsValue"];
        }
        if (!empty($settings)) {
            return $settings;
        } else {
            return false;
        }
    }

    /*
     * Edits the global system settings
     *
     * @param string $name System name
     * @param string $subtitle Subtitle is displayed under the system name
     * @param string $locale Standard locale
     * @param string $timezone Standard timezone
     * @param string $templ Template
     * @param string $rssuser Username for RSS Feed access
     * @param string $rsspass Password for RSS Feed access
     * @return bool
     */
    function editSettings($name, $subtitle, $locale, $timezone, $dateformat, $templ, $theme, $rssuser, $rsspass)
    {
        global $conn;
        // This is an artifact of refactoring to a key/value table for the settings
        // Create an arrray containing the settings fields as keys and new values from the user as values
        $theSettings = array("name" => $name, "subtitle" => $subtitle, "locale" => $locale, "timezone" => $timezone, "dateformat" => $dateformat, "template" => $templ, "theme" => $theme, "rssuser" => $rssuser, "rsspass" => $rsspass);
        // Now prepare a statement to edit one settings row
        $updStmt = $conn->prepare("UPDATE settings SET `settingsValue` = ? WHERE `settingsKey` = ?");
        // Loop through the array containing the key/value pairs, writing the database field to $setKey and the value to $setVal
        foreach($theSettings as $setKey => $setVal) {
            // Execute the prepared statement by binding the current settings field and values
            $upd = $updStmt->execute(array($setVal, $setKey));
        }

        if ($upd) {
            return true;
        } else {
            return false;
        }
    }

    /*
     * Edits the global mail notification settings
     *
     * @param int $onoff 1 = nofitications on, 0 = notifications off
     * @param string $mailfrom Sender
     * @param string $mailfromname Name of the sender
     * @param string $method Method (e.g. SMTP)
     * @param string $mailhost Host
     * @param string $mailuser User
	 * @param string $mailpass Password
     * @return bool
     */
    function editMailsettings($onoff, $mailfrom, $mailfromname, $method, $mailhost, $mailuser, $mailpass)
    {
        global $conn;
        // This is an artifact of refactoring to a key/value table for the settings
        $theSettings = array("mailnotify" => $onoff, "mailfrom" => $mailfrom, "mailfromname" => $mailfromname, "mailmethod" => $method, "mailhost" => $mailhost, "mailuser" => $mailuser, "mailpass" => $mailpass);
        $updStmt = $conn->prepare("UPDATE settings SET `settingsValue` = ? WHERE `settingsKey` = ?");

        foreach($theSettings as $setKey => $setVal) {
            $upd = $updStmt->execute(array($setVal, $setKey));
        }
        if ($upd) {
            return true;
        } else {
            return false;
        }
    }

    /*
     * Returns all available templates
     *
     * @return array $templates
     */
    function getTemplates()
    {
        $handle = opendir(CL_ROOT . "/templates");
        $templates = array();
        // Iterate through the templates directory and count each subdirectory within it as a template
        while (false !== ($file = readdir($handle))) {
            $type = filetype(CL_ROOT . "/templates/" . $file);

            if (($type == "dir" or $type == "link") and $file != "." and $file != "..") {
                $template = $file;
                array_push($templates, $template);
            }
        }

        if (!empty($templates)) {
            return $templates;
        } else {
            return false;
        }
    }

    /*
	   * Returns all available themes for a given template
	   *
	   * @param string $template The template whose themes get fetched
	   *
	   * @return array $templates
	*/
    function getThemes($template)
    {
        $handle = opendir(CL_ROOT . "/templates/$template/theme");
        $themes = array();
        // Iterate through the templates directory and count each subdirectory within it as a template
        while (false !== ($file = readdir($handle))) {
            $type = filetype(CL_ROOT . "/templates/$template/theme/" . $file);

            if ($type == "dir" and $file != "." and $file != "..") {
                $theme = $file;
                array_push($themes, $theme);
            }
        }

        if (!empty($themes)) {
            return $themes;
        } else {
            return false;
        }
    }
}