[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare API - Application configuration in a centralized location * 4 * This file written by Joseph Engo <jengo@phpgroupware.org> * 5 * Copyright (C) 2000, 2001 Joseph Engo * 6 * -------------------------------------------------------------------------* 7 * This library is part of the eGroupWare API * 8 * http://www.egroupware.org/api * 9 * ------------------------------------------------------------------------ * 10 * This library is free software; you can redistribute it and/or modify it * 11 * under the terms of the GNU Lesser General Public License as published by * 12 * the Free Software Foundation; either version 2.1 of the License, * 13 * or any later version. * 14 * This library is distributed in the hope that it will be useful, but * 15 * WITHOUT ANY WARRANTY; without even the implied warranty of * 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 17 * See the GNU Lesser General Public License for more details. * 18 * You should have received a copy of the GNU Lesser General Public License * 19 * along with this library; if not, write to the Free Software Foundation, * 20 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 21 \**************************************************************************/ 22 23 /* $Id: class.config.inc.php 20295 2006-02-15 12:31:25Z $ */ 24 25 class config 26 { 27 var $db; 28 var $appname; 29 var $config_data; // actual config-data 30 var $read_data; // config-data as read from db 31 var $table = 'egw_config'; 32 33 function config($appname = '') 34 { 35 if (! $appname) 36 { 37 $appname = $GLOBALS['egw_info']['flags']['currentapp']; 38 } 39 if (is_object($GLOBALS['egw']->db)) 40 { 41 $this->db = clone($GLOBALS['egw']->db); 42 } 43 else 44 { 45 $this->db = clone($GLOBALS['egw_setup']->db); 46 } 47 $this->db->set_app('phpgwapi'); 48 $this->appname = $appname; 49 } 50 51 /** 52 * reads the whole repository for $this->appname, appname has to be set via the constructor 53 * 54 * the whole config-array for that app 55 */ 56 function read_repository() 57 { 58 $this->config_data = array(); 59 60 $this->db->select($this->table,'*',array('config_app'=>$this->appname),__LINE__,__FILE__); 61 while ($this->db->next_record()) 62 { 63 $test = @unserialize($this->db->f('config_value')); 64 if(is_array($test)) 65 { 66 $this->config_data[$this->db->f('config_name')] = $test; 67 } 68 else 69 { 70 $this->config_data[$this->db->f('config_name')] = $this->db->f('config_value'); 71 } 72 } 73 return $this->read_data = $this->config_data; 74 } 75 76 /** 77 * updates the whole repository for $this->appname, you have to call read_repository() before (!) 78 */ 79 function save_repository() 80 { 81 if (is_array($this->config_data)) 82 { 83 $this->db->lock(array($this->table)); 84 foreach($this->config_data as $name => $value) 85 { 86 $this->save_value($name,$value); 87 } 88 foreach($this->read_data as $name => $value) 89 { 90 if (!isset($this->config_data[$name])) // has been deleted 91 { 92 $this->db->delete($this->table,array('config_app'=>$this->appname,'config_name'=>$name),__LINE__,__FILE__); 93 } 94 } 95 $this->db->unlock(); 96 97 if ($this->appname == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited 98 { 99 $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) 100 } 101 } 102 $this->read_data = $this->config_data; 103 } 104 105 /** 106 * updates or insert a single config-value 107 * 108 * @param $name string name of the config-value 109 * @param $value mixed content 110 * @param $app string app-name, defaults to $this->appname set via the constructor 111 */ 112 function save_value($name,$value,$app=False) 113 { 114 //echo "<p>config::save_value('$name','".print_r($value,True)."','$app')</p>\n"; 115 if (!$app || $app == $this->appname) 116 { 117 $app = $this->appname; 118 $this->config_data[$name] = $value; 119 } 120 if ($app == $this->appname && $this->read_data[$name] == $value) 121 { 122 return True; // no change ==> exit 123 } 124 //echo "<p>config::save_value('$name','".print_r($value,True)."','$app')</p>\n"; 125 126 if(is_array($value)) 127 { 128 $value = serialize($value); 129 } 130 return $this->db->insert($this->table,array('config_value'=>$value),array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__); 131 } 132 133 /** 134 * deletes the whole repository for $this->appname, appname has to be set via the constructor 135 * 136 */ 137 function delete_repository() 138 { 139 $this->db->delete($this->table,array('config_app' => $this->appname),__LINE__,__FILE__); 140 } 141 142 /** 143 * deletes a single value from the repository, you need to call save_repository after 144 * 145 * @param $variable_name string name of the config 146 */ 147 function delete_value($variable_name) 148 { 149 unset($this->config_data[$variable_name]); 150 } 151 152 /** 153 * sets a single value in the repositry, you need to call save_repository after 154 * 155 * @param $variable_name string name of the config 156 * @param $variable_data mixed the content 157 */ 158 function value($variable_name,$variable_data) 159 { 160 $this->config_data[$variable_name] = $variable_data; 161 } 162 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |