ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPaypalSettings.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
33 {
34  private $db;
35 
36  private $settings;
37  private $settings_id;
38 
39  private $server_host;
40  private $server_path;
41  private $vendor;
42  private $auth_token;
43  private $page_style;
44  private $ssl;
45 
46  static private $instance = null;
47 
54  static public function getInstance()
55  {
56  if (!self::$instance)
57  {
58  self::$instance = new ilPaypalSettings();
59  }
60 
61  return self::$instance;
62  }
63 
69  private function ilPaypalSettings()
70  {
71  global $ilDB;
72 
73  $this->db =& $ilDB;
74 
75  $this->getSettings();
76  }
77 
83  private function getSettings()
84  {
85  $this->fetchSettingsId();
86 
87  $res = $this->db->queryf('
88  SELECT paypal FROM payment_settings WHERE settings_id = %s',
89  array('integer'), array($this->getSettingsId()));
90 
91  $result = $this->db->fetchObject($res);
92 
93  $data = array();
94  if (is_object($result))
95  {
96  if ($result->paypal != "") $data = unserialize($result->paypal);
97  else $data = array();
98  }
99 
100  $this->setServerHost($data["server_host"]);
101  $this->setServerPath($data["server_path"]);
102  $this->setVendor($data["vendor"]);
103  $this->setAuthToken($data["auth_token"]);
104  $this->setPageStyle($data["page_style"]);
105  $this->setSsl($data["ssl"]);
106  }
107 
113  private function fetchSettingsId()
114  {
115 
116  $res = $this->db->query('SELECT * FROM payment_settings');
117 
118  $result = $this->db->fetchObject($res);
119 
120  $this->setSettingsId($result->settings_id);
121  }
122 
123  public function setSettingsId($a_settings_id = 0)
124  {
125  $this->settings_id = $a_settings_id;
126  }
127 
128  public function getSettingsId()
129  {
130  return $this->settings_id;
131  }
132 
133  public function setServerHost($a_server_host)
134  {
135  $this->server_host = $a_server_host;
136  }
137 
138  public function getServerHost()
139  {
140  return $this->server_host;
141  }
142 
143  public function setServerPath($a_server_path)
144  {
145  $this->server_path = $a_server_path;
146  }
147 
148  public function getServerPath()
149  {
150  return $this->server_path;
151  }
152 
153  public function setVendor($a_vendor)
154  {
155  $this->vendor = $a_vendor;
156  }
157 
158  public function getVendor()
159  {
160  return $this->vendor;
161  }
162 
163  public function setAuthToken($a_auth_token)
164  {
165  $this->auth_token = $a_auth_token;
166  }
167 
168  public function getAuthToken()
169  {
170  return $this->auth_token;
171  }
172 
173  public function setPageStyle($a_page_style)
174  {
175  $this->page_style = $a_page_style;
176  }
177 
178  public function getPageStyle()
179  {
180  return $this->page_style;
181  }
182 
183  public function setSsl($a_ssl)
184  {
185  $this->ssl = $a_ssl;
186  }
187 
188  public function getSsl()
189  {
190  return $this->ssl;
191  }
192 
199  function getAll()
200  {
201  $values = array(
202  "server_host" => $this->getServerHost(),
203  "server_path" => $this->getServerPath(),
204  "vendor" => $this->getVendor(),
205  "auth_token" => $this->getAuthToken(),
206  "page_style" => $this->getPageStyle(),
207  "ssl" => $this->getSsl()
208  );
209 
210  return $values;
211  }
212 
218  function clearAll()
219  {
220  $statement = $this->db->manipulateF('
221  UPDATE payment_settings
222  SET paypal = %s
223  WHERE settings_id = %s',
224  array('text', 'integer'),
225  array('NULL', $this->getSettingsId()));
226 
227 
228  $this->settings = array();
229  }
230 
236  public function save()
237  {
238  global $ilDB;
239 
240  $values = array(
241  "server_host" => $this->getServerHost(),
242  "server_path" => $this->getServerPath(),
243  "vendor" => $this->getVendor(),
244  "auth_token" => $this->getAuthToken(),
245  "page_style" => $this->getPageStyle(),
246  "ssl" => $this->getSsl()
247  );
248 
249  if ($this->getSettingsId())
250  {
251  $statement = $ilDB->manipulateF('
252  UPDATE payment_settings
253  SET paypal = %s
254  WHERE settings_id = %s',
255  array('text', 'integer'),
256  array(serialize($values), $this->getSettingsId()));
257 
258  }
259  else
260  {
261  $next_id = $ilDB->nextId('payment_settings');
262  $statement = $ilDB->manipulateF('
263  INSERT INTO payment_settings
264  ( settings_id,
265  paypal)
266  VALUES (%s, %s)',
267  array('integer','text'), array($next_id, serialize($values)));
268 
269  //$this->setSettingsId($this->db->getLastInsertId());
270  $this->setSettingsId($next_id);
271 
272  }
273  }
274 }
275 ?>