[Openfirst-cvscommit] base/includes settings.php,NONE,1.1
Brought to you by:
xtimg
From: Jamie <ast...@us...> - 2005-08-24 02:34:55
|
Update of /cvsroot/openfirst/base/includes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3224/includes Added Files: settings.php Log Message: Objects to store settings. --- NEW FILE: settings.php --- <?php /* * openFIRST.base - includes/settings.php * * Copyright (C) 2003, * openFIRST Project * Original Author: Jamie Bliss <ja...@op...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ // Purpose: Define functions for modules to load and save settings /** Handles storing, retrieving, and deleting per-module, site-wide settings. */ class SiteSettings { /*private*/ var $mod; function SiteSettings($module=false) { if ($module == false) { global $ogCurrentModule; $this->mod = $ogCurrentModule->getDir(); } else if (is_object($module) && is_a($module, Module)) { $this->mod = $module->getDir(); } else { $this->mod = $module; } } function get($name, $default=null) { $modname = $this->mod; global $ogDB; $res = $ogDB->select( 'sitesettings', 'ss_value', array( 'ss_module' => $modname, 'ss_setting' => $name) ); $row = $ogDB->fetchObject($res); if (isset($row->ss_value)) return unserialize($row->ss_value); else return $default; } function set($name, $value) { $modname = $this->mod; global $ogDB; $res = $ogDB->replace( 'sitesettings', array( 'ss_module' => $modname, 'ss_setting' => $name, 'ss_value' => serialize($value) ) ); } /* function del($name) { # }*/ } //User settings /** Handles storing, retrieving, and deleting per-module, site-wide settings. */ class UserSettings { /*private*/ var $mod, $user; function UserSettings($module=false,$user=false) { if ($module == false) { global $ogCurrentModule; $this->mod = $ogCurrentModule->getDir(); } else if (is_object($module) && is_a($module, Module)) { global $ogModuleManager; $this->mod = $module->getDir(); } else { $this->mod = $module; } if ($user == false) { $this->user = $GLOBALS['user']->user; } else if (is_object($user)) { $this->user = $user->user; } else { $this->user = $user; } } function get($name, $default=null) { $modname = $this->mod; $username = $this->user; global $ogDB; $res = $ogDB->select( 'usersettings', 'us_value', array( 'us_user' => $username, 'us_module' => $modname, 'us_setting' => $name) ); $row = $ogDB->fetchObject($res); if (isset($row->ss_value)) return unserialize($row->ss_value); else return $default; } function set($name, $value) { $modname = $this->mod; $username = $this->user; global $ogDB; $ogDB->replace( 'usersettings', array( 'us_user' => $username, 'us_module' => $modname, 'us_setting' => $name, 'us_value' => serialize($value) ) ); } /* function del($name) { # }*/ } ?> |