source: branches/1.2/workflow/inc/engine/class.ajax_config.inc.php @ 1349

Revision 1349, 5.0 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

  • Property svn:executable set to *
Line 
1<?php
2  /**
3   * Realiza operações com os dados de configuração do workflow
4   *
5   * @author  viani
6   * @version 1.0
7   * @license http://www.gnu.org/copyleft/gpl.html GPL
8   * @package Galaxia
9   */
10class ajax_config
11{       
12        /**             
13        * @var object $db database
14        * @access public
15        */
16        var $db;
17        /**             
18        * @var string $appname Application (module) to config
19        * @access public
20        */
21        var $appname;
22        /**             
23        * @var array $config_data Actual config-data
24        * @access public
25        */
26        var $config_data;       
27        /**             
28        * @var array $read_data Config-data as read from db
29        * @access public
30        */
31        var $read_data;         
32
33        /**
34        * Set appname and db for ajax config
35        *
36        * @param string $appname Which application to config. Default workflow.
37        * @return void
38        * @access public
39        */
40        function ajax_config($appname = '')
41        {
42                if (! $appname)
43                {
44                        $appname = 'workflow';
45                }
46
47                $this->db      = &$GLOBALS['workflow']['workflowObjects']->getDBExpresso();
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        * @return array the whole config-array for that app
55        * @access public
56        */
57        function read_repository()
58        {
59                $this->config_data = array();
60
61                $this->db->query("select * from phpgw_config where config_app='" . $this->appname . "'",__LINE__,__FILE__);
62                while ($this->db->next_record())                       
63                {
64                        $test = @unserialize($this->db->f('config_value'));
65                        if($test)
66                        {
67                                $this->config_data[$this->db->f('config_name')] = $test;
68                        }
69                        else
70                        {
71                                $this->config_data[$this->db->f('config_name')] = $this->db->f('config_value');
72                        }
73                }
74                return $this->read_data = $this->config_data;
75        }
76
77        /**
78        * Updates the whole repository for $this->appname, you have to call read_repository() before (!)
79        * @access public       
80        * @return void
81        */
82        function save_repository()
83        {
84                if (is_array($this->config_data))
85                {
86                        $this->db->lock(array('phpgw_config','phpgw_app_sessions'));
87                        if($this->appname == 'phpgwapi')
88                        {
89                                $this->db->query("delete from phpgw_app_sessions where sessionid = '0' and loginid = '0' and app = '".$this->appname."' and location = 'config'",__LINE__,__FILE__);
90                        }
91                        foreach($this->config_data as $name => $value)
92                        {
93                                $this->save_value($name,$value);
94                        }
95                        foreach($this->read_data as $name => $value)
96                        {
97                                if (!isset($this->config_data[$name]))  // has been deleted
98                                {
99                                        $this->db->query("DELETE FROM phpgw_config WHERE config_app='$this->appname' AND config_name='$name'",__LINE__,__FILE__);
100                                }
101                        }
102                        $this->db->unlock();
103                }
104                $this->read_data = $this->config_data;
105        }
106
107        /**
108        * Updates or insert a single config-value
109        *
110        * @param string $name name of the config-value
111        * @param mixed $value content
112        * @param string $app app-name, defaults to $this->appname set via the constructor
113        * @return array
114        * @access public
115        */
116        function save_value($name,$value,$app=False)
117        {
118                //echo "<p>config::save_value('$name','".print_r($value,True)."','$app')</p>\n";
119                if (!$app || $app == $this->appname)
120                {
121                        $app = $this->appname;
122                        $this->config_data[$name] = $value;
123                }
124                $name = $this->db->db_addslashes($name);
125
126                if ($app == $this->appname && $this->read_data[$name] == $value)
127                {
128                        return True;    // no change ==> exit
129                }
130                $this->db->query($sql="select * from phpgw_config where config_app='$app' AND config_name='$name'",__LINE__,__FILE__);
131                if ($this->db->next_record())
132                {
133                        $value_read = @unserialize($this->db->f('config_value'));
134                        if (!$value_read)
135                        {
136                                $value_read = $this->db->f('config_value');
137                        }
138                        if ($value_read == $value)
139                        {
140                                return True;    // no change ==> exit
141                        }
142                        $update = True;
143                }
144                //echo "<p>config::save_value('$name','".print_r($value,True)."','$app')</p>\n";
145
146                if(is_array($value))
147                {
148                        $value = serialize($value);
149                }
150                $value = $this->db->db_addslashes($value);
151
152                $query = $update ? "UPDATE phpgw_config SET config_value='$value' WHERE config_app='$app' AND config_name='$name'" :
153                                "INSERT INTO phpgw_config (config_app,config_name,config_value) VALUES ('$app','$name','$value')";
154
155                return $this->db->query($query,__LINE__,__FILE__);
156        }
157
158        /**
159        * Deletes the whole repository for $this->appname, appname has to be set via the constructor
160        *
161        * @access public
162        * @return void         
163        */     
164        function delete_repository()
165        {
166                $this->db->query("delete from phpgw_config where config_app='" . $this->appname . "'",__LINE__,__FILE__);
167        }
168
169        /**
170        * Deletes a single value from the repository, you need to call save_repository after
171        *
172        * @param string $variable_name name of the config
173        * @return void
174        * @access public
175        */
176        function delete_value($variable_name)
177        {
178                unset($this->config_data[$variable_name]);
179        }
180        /**
181        * Sets a single value in the repository, you need to call save_repository after
182        *
183        * @param string $variable_name name of the config
184        * @param mixed $variable_data the content
185        * @return void
186        * @access public
187        */
188        function value($variable_name,$variable_data)
189        {
190                $this->config_data[$variable_name] = $variable_data;
191        }
192       
193}
194?>
Note: See TracBrowser for help on using the repository browser.