ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPaypalSettings.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14  private $db;
15 
16  private $settings;
17  private $settings_id;
18 
19  private $server_host;
20  private $server_path;
21  private $vendor;
22  private $auth_token;
23  private $page_style;
24  private $ssl;
25 
26  static private $instance = null;
27 
34  static public function getInstance()
35  {
36  if (!self::$instance)
37  {
38  self::$instance = new ilPaypalSettings();
39  }
40 
41  return self::$instance;
42  }
43 
49  private function ilPaypalSettings()
50  {
51  global $ilDB;
52 
53  $this->db = $ilDB;
54 
55  $this->getSettings();
56  }
57 
63  private function getSettings()
64  {
65  $this->fetchSettingsId();
66 
67  $res = $this->db->queryf('
68  SELECT paypal FROM payment_settings WHERE settings_id = %s',
69  array('integer'), array($this->getSettingsId()));
70 
71  $result = $this->db->fetchObject($res);
72 
73  $data = array();
74  if (is_object($result))
75  {
76  if ($result->paypal != "") $data = unserialize($result->paypal);
77  else $data = array();
78  }
79 
80  $this->setServerHost($data["server_host"]);
81  $this->setServerPath($data["server_path"]);
82  $this->setVendor($data["vendor"]);
83  $this->setAuthToken($data["auth_token"]);
84  $this->setPageStyle($data["page_style"]);
85  $this->setSsl($data["ssl"]);
86  }
87 
93  private function fetchSettingsId()
94  {
95 
96  $res = $this->db->query('SELECT * FROM payment_settings');
97 
98  $result = $this->db->fetchObject($res);
99 
100  $this->setSettingsId($result->settings_id);
101  }
102 
103  public function setSettingsId($a_settings_id = 0)
104  {
105  $this->settings_id = $a_settings_id;
106  }
107 
108  public function getSettingsId()
109  {
110  return $this->settings_id;
111  }
112 
113  public function setServerHost($a_server_host)
114  {
115  $this->server_host = $a_server_host;
116  }
117 
118  public function getServerHost()
119  {
120  return $this->server_host;
121  }
122 
123  public function setServerPath($a_server_path)
124  {
125  $this->server_path = $a_server_path;
126  }
127 
128  public function getServerPath()
129  {
130  return $this->server_path;
131  }
132 
133  public function setVendor($a_vendor)
134  {
135  $this->vendor = $a_vendor;
136  }
137 
138  public function getVendor()
139  {
140  return $this->vendor;
141  }
142 
143  public function setAuthToken($a_auth_token)
144  {
145  $this->auth_token = $a_auth_token;
146  }
147 
148  public function getAuthToken()
149  {
150  return $this->auth_token;
151  }
152 
153  public function setPageStyle($a_page_style)
154  {
155  $this->page_style = $a_page_style;
156  }
157 
158  public function getPageStyle()
159  {
160  return $this->page_style;
161  }
162 
163  public function setSsl($a_ssl)
164  {
165  $this->ssl = $a_ssl;
166  }
167 
168  public function getSsl()
169  {
170  return $this->ssl;
171  }
172 
179  function getAll()
180  {
181  $values = array(
182  "server_host" => $this->getServerHost(),
183  "server_path" => $this->getServerPath(),
184  "vendor" => $this->getVendor(),
185  "auth_token" => $this->getAuthToken(),
186  "page_style" => $this->getPageStyle(),
187  "ssl" => $this->getSsl()
188  );
189 
190  return $values;
191  }
192 
198  function clearAll()
199  {
200  $statement = $this->db->manipulateF('
201  UPDATE payment_settings
202  SET paypal = %s
203  WHERE settings_id = %s',
204  array('text', 'integer'),
205  array('NULL', $this->getSettingsId()));
206 
207 
208  $this->settings = array();
209  }
210 
216  public function save()
217  {
218  global $ilDB;
219 
220  $values = array(
221  "server_host" => $this->getServerHost(),
222  "server_path" => $this->getServerPath(),
223  "vendor" => $this->getVendor(),
224  "auth_token" => $this->getAuthToken(),
225  "page_style" => $this->getPageStyle(),
226  "ssl" => $this->getSsl()
227  );
228 
229  if ($this->getSettingsId())
230  {
231  $statement = $ilDB->manipulateF('
232  UPDATE payment_settings
233  SET paypal = %s
234  WHERE settings_id = %s',
235  array('text', 'integer'),
236  array(serialize($values), $this->getSettingsId()));
237 
238  }
239  else
240  {
241  $next_id = $ilDB->nextId('payment_settings');
242  $statement = $ilDB->manipulateF('
243  INSERT INTO payment_settings
244  ( settings_id,
245  paypal)
246  VALUES (%s, %s)',
247  array('integer','text'), array($next_id, serialize($values)));
248 
249  $this->setSettingsId($next_id);
250 
251  }
252  }
253 }
254 ?>