ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilGeneralSettings.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2009 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
25 {
26  private static $_instance;
27 
28  var $db;
29  var $settings;
30 
31  public static function _getInstance()
32  {
33  if(!isset(self::$_instance))
34  {
35  self::$_instance = new ilGeneralSettings();
36  }
37 
38  return self::$_instance;
39  }
40 
41  function ilGeneralSettings()
42  {
43  global $ilDB;
44 
45  $this->db =& $ilDB;
46 
47  $this->__getSettings();
48  }
49 
55  private function fetchSettingsId()
56  {
57  $result = $this->db->query('SELECT settings_id FROM payment_settings');
58  while($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
59  {
60  $this->setSettingsId($row->settings_id);
61  }
62  }
63 
64  public function setSettingsId($a_settings_id = 0)
65  {
66  $this->settings_id = $a_settings_id;
67 
68  }
69  public function getSettingsId()
70  {
71  return $this->settings_id;
72  }
73 
74  function get($a_type)
75  {
76  return $this->settings[$a_type];
77  }
78 
79  function getAll()
80  {
81  return $this->settings;
82  }
83 
84  function clearAll()
85  {
86  $statement = $this->db->manipulateF('
87  UPDATE payment_settings
88  SET currency_unit = %s,
89  currency_subunit = %s,
90  address = %s,
91  bank_data = %s,
92  add_info = %s,
93  pdf_path = %s,
94  topics_sorting_type = %s,
95  topics_sorting_direction = %s,
96  topics_allow_custom_sorting = %s,
97  max_hits = %s,
98  shop_enabled = %s,
99  hide_advanced_search = %s,
100  hide_filtering = %s,
101  hide_coupons = %s,
102  hide_news = %s
103  WHERE settings_id = %s',
104  array( 'text',
105  'text',
106  'text',
107  'text',
108  'text',
109  'text',
110  'integer',
111  'integer',
112  'text',
113  'integer',
114  'integer',
115  'integer',
116  'integer',
117  'integer',
118  'integer',
119  'integer'),
120  array( NULL,
121  NULL,
122  NULL,
123  NULL,
124  NULL,
125  NULL,
126  '1',
127  'asc',
128  '0',
129  '20',
130  '0',
131  '0',
132  '0',
133  '0',
134  '0',
135  $this->getSettingsId())
136  );
137 
138  return true;
139  }
140 
141  function setAll($a_values)
142  {
143  global $ilDB;
144 
145  if ($this->getSettingsId())
146  {
147 
148  if(!$a_values['currency_unit']) $a_values['currency_unit'] = NULL;
149  if(!$a_values['currency_subunit']) $a_values['currency_subunit'] = NULL;
150  if(!$a_values['address']) $a_values['address'] = NULL;
151  if(!$a_values['bank_data']) $a_values['bank_data'] = NULL;
152  if(!$a_values['add_info']) $a_values['add_info'] = NULL;
153  if(!$a_values['pdf_path']) $a_values['pdf_path'] = NULL;
154 
155  if(!$a_values['topics_allow_custom_sorting']) $a_values['topics_allow_custom_sorting'] = 0;
156  if(!$a_values['topics_sorting_type']) $a_values['topics_sorting_type'] = 0;
157  if(!$a_values['topics_sorting_direction']) $a_values['topics_sorting_direction'] = NULL;
158  if(!$a_values['shop_enabled']) $a_values['shop_enabled'] = 0;
159  if(!$a_values['max_hits']) $a_values['max_hits'] = 0;
160  if(!$a_values['hide_advanced_search']) $a_values['hide_advanced_search'] = 0;
161  if(!$a_values['hide_filtering']) $a_values['hide_filtering'] = 0;
162  if(!$a_values['hide_coupons']) $a_values['hide_coupons'] = 0;
163  if(!$a_values['hide_news']) $a_values['hide_news'] = 0;
164 
165 
166  $statement = $this->db->manipulateF('
167  UPDATE payment_settings
168  SET currency_unit = %s,
169  currency_subunit = %s,
170  address = %s,
171  bank_data = %s,
172  add_info = %s,
173  pdf_path = %s,
174  topics_sorting_type = %s,
175  topics_sorting_direction = %s,
176  topics_allow_custom_sorting = %s,
177  max_hits = %s,
178  shop_enabled = %s,
179  hide_advanced_search = %s,
180  hide_filtering = %s,
181  hide_coupons = %s,
182  hide_news = %s
183  WHERE settings_id = %s',
184  array( 'text',
185  'text',
186  'text',
187  'text',
188  'text',
189  'text',
190  'integer',
191  'text',
192  'integer',
193  'integer',
194  'integer',
195  'integer',
196  'integer',
197  'integer',
198  'integer',
199  'integer'),
200  array(
201  $a_values['currency_unit'],
202  $a_values['currency_subunit'],
203  $a_values['address'],
204  $a_values['bank_data'],
205  $a_values['add_info'],
206  $a_values['pdf_path'],
207  $a_values['topics_sorting_type'],
208  $a_values['topics_sorting_direction'],
209  $a_values['topics_allow_custom_sorting'],
210  $a_values['max_hits'],
211  $a_values['shop_enabled'],
212  $a_values['hide_advanced_search'],
213  $a_values['hide_filtering'],
214  $a_values['hide_coupons'],
215  $a_values['hide_news'],
216  $this->getSettingsId())
217  );
218  }
219  else
220  {
221 
222 
223  if(!$a_values['currency_unit']) $a_values['currency_unit'] = NULL;
224  if(!$a_values['currency_subunit']) $a_values['currency_subunit'] = NULL;
225  if(!$a_values['address']) $a_values['address'] = NULL;
226  if(!$a_values['bank_data']) $a_values['bank_data'] = NULL;
227  if(!$a_values['add_info']) $a_values['add_info'] = NULL;
228 
229  if(!$a_values['pdf_path']) $a_values['pdf_path'] = NULL;
230 
231  if(!$a_values['topics_allow_custom_sorting']) $a_values['topics_allow_custom_sorting'] = 0;
232  if(!$a_values['topics_sorting_type']) $a_values['topics_sorting_type'] = 0;
233  if(!$a_values['topics_sorting_direction']) $a_values['topics_sorting_direction'] = NULL;
234  if(!$a_values['shop_enabled']) $a_values['shop_enabled'] = 0;
235  if(!$a_values['max_hits']) $a_values['max_hits'] = 0;
236  if(!$a_values['hide_advanced_search']) $a_values['hide_advanced_search'] = 0;
237  if(!$a_values['hide_filtering']) $a_values['hide_filtering'] = 0;
238  if(!$a_values['hide_coupons']) $a_values['hide_coupons'] = 0;
239  if(!$a_values['hide_news']) $a_values['hide_news'] = 0;
240 
241 
242  $next_id = $ilDB->nextId('payment_settings');
243  $statement = $this->db->manipulateF('
244  INSERT INTO payment_settings
245  ( settings_id,
246  currency_unit,
247  currency_subunit,
248  address,
249  bank_data,
250  add_info,
251  pdf_path,
252  topics_allow_custom_sorting,
253  topics_sorting_type,
254  topics_sorting_direction,
255  shop_enabled,
256  max_hits,
257  hide_advanced_search,
258  hide_filtering,
259  hide_coupons,
260  hide_news
261  )
262  VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
263  array( 'integer',
264  'text',
265  'text',
266  'text',
267  'text',
268  'text',
269  'text',
270  'integer',
271  'integer',
272  'text',
273  'integer',
274  'integer',
275  'integer',
276  'integer',
277  'integer',
278  'integer'),
279  array(
280  $next_id,
281  $a_values['currency_unit'],
282  $a_values['currency_subunit'],
283  $a_values['address'],
284  $a_values['bank_data'],
285  $a_values['add_info'],
286  $a_values['pdf_path'],
287  $a_values['topics_allow_custom_sorting'],
288  $a_values['topics_sorting_type'],
289  $a_values['topics_sorting_direction'],
290  $a_values['shop_enabled'],
291  $a_values['max_hits'],
292  $a_values['hide_advanced_search'],
293  $a_values['hide_filtering'],
294  $a_values['hide_coupons'],
295  $a_values['hide_news']
296  )
297  );
298  }
299 
300  $this->__getSettings();
301 
302  return true;
303  }
304 
305  function __getSettings()
306  {
307  $this->fetchSettingsId();
308 
309  $result = $this->db->query('SELECT * FROM payment_settings');
310 
311  $data = array();
312  while($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
313  {
314  $data['currency_unit'] = $row->currency_unit;
315  $data['currency_subunit'] = $row->currency_subunit;
316  $data['address'] = $row->address;
317  $data['bank_data'] = $row->bank_data;
318  $data['add_info'] = $row->add_info;
319  $data['pdf_path'] = $row->pdf_path;
320  $data['topics_allow_custom_sorting'] = $row->topics_allow_custom_sorting;
321  $data['topics_sorting_type'] = $row->topics_sorting_type;
322  $data['topics_sorting_direction'] = $row->topics_sorting_direction;
323  $data['max_hits'] = $row->max_hits;
324  $data['shop_enabled'] = $row->shop_enabled;
325  $data['hide_advanced_search'] = $row->hide_advanced_search;
326  $data['hide_filtering'] = $row->hide_filtering;
327  $data['hide_coupons'] = $row->hide_coupons;
328  $data['hide_news'] = $row->hide_news;
329  }
330  $this->settings = $data;
331  }
332 }
333 ?>