c87f604d630914eade45aa5aee104ce472c8f982
[diogenes.git] / include / Barrel / Options.php
1 <?php
2 /*
3 * Copyright (C) 2003-2004 Polytechnique.org
4 * http://opensource.polytechnique.org/
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21
22 /**
23 * This class is used to handle the preferences for a barrel.
24 *
25 * Upon construction these preferences are read from database. It is also
26 * possible to update the value of the preferences and write the new value
27 * to database.
28 *
29 * @see Diogenes_Barrel
30 */
31 class Diogenes_Barrel_Options
32 {
33 /** The barrel we are operating on */
34 var $barrel;
35
36 /** The table holding the options */
37 var $table_option = 'diogenes_option';
38
39 /** The site's title */
40 var $title = "";
41
42 /** The site's description */
43 var $description = "";
44
45 /** The relative url to the site's favicon (PNG) */
46 var $favicon = "";
47
48 /** The site's keywords */
49 var $keywords = "";
50
51 /** Hide the Diogenes-generated menu entries */
52 var $menu_hide_diogenes = 0;
53
54 /** Minimum menu level (0 means fully expanded) */
55 var $menu_min_level = 0;
56
57 /** Menu style (0=classical, 1=phpLayersMenu) */
58 var $menu_style = 0;
59
60 /** Menu theme */
61 var $menu_theme = "gorilla";
62
63 /** Site-wide default template */
64 var $template = "";
65
66 /** Directory that hold the site's template */
67 var $template_dir = "";
68
69 /** The constructor, reads the current preferences from database.
70 */
71 function Diogenes_Barrel_Options($alias)
72 {
73 $this->barrel = $alias;
74 $this->readOptions();
75 }
76
77
78 /** Read options from database.
79 */
80 function readOptions() {
81 global $globals;
82
83 // we only accept options which already exist in this class
84 $res = $globals->db->query("select name,value from {$this->table_option} where barrel='{$this->barrel}'");
85 while (list($key,$value) = mysql_fetch_row($res)) {
86 if (isset($this->$key) && ($key != "table_option"))
87 $this->$key = $value;
88 }
89 mysql_free_result($res);
90
91 }
92
93
94 /** Update an option's value and write the new value to database.
95 */
96 function updateOption($name, $value) {
97 global $globals;
98
99 $this->$name = stripslashes($value);
100 $globals->db->query("replace into {$this->table_option} set barrel='{$this->barrel}',name='$name',value='$value'");
101 }
102
103 }
104
105 ?>