ILIAS  Release_3_10_x_branch Revision 61812
 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  $query = "SELECT paypal FROM payment_settings WHERE settings_id = '" . $this->getSettingsId() . "'";
88  $result = $this->db->getrow($query);
89 
90  $data = array();
91  if (is_object($result))
92  {
93  if ($result->paypal != "") $data = unserialize($result->paypal);
94  else $data = array();
95  }
96 
97  $this->setServerHost($data["server_host"]);
98  $this->setServerPath($data["server_path"]);
99  $this->setVendor($data["vendor"]);
100  $this->setAuthToken($data["auth_token"]);
101  $this->setPageStyle($data["page_style"]);
102  $this->setSsl($data["ssl"]);
103  }
104 
110  private function fetchSettingsId()
111  {
112  $query = "SELECT * FROM payment_settings";
113  $result = $this->db->getrow($query);
114 
115  $this->setSettingsId($result->settings_id);
116  }
117 
118  public function setSettingsId($a_settings_id = 0)
119  {
120  $this->settings_id = $a_settings_id;
121  }
122  public function getSettingsId()
123  {
124  return $this->settings_id;
125  }
126  public function setServerHost($a_server_host)
127  {
128  $this->server_host = $a_server_host;
129  }
130  public function getServerHost()
131  {
132  return $this->server_host;
133  }
134  public function setServerPath($a_server_path)
135  {
136  $this->server_path = $a_server_path;
137  }
138  public function getServerPath()
139  {
140  return $this->server_path;
141  }
142  public function setVendor($a_vendor)
143  {
144  $this->vendor = $a_vendor;
145  }
146  public function getVendor()
147  {
148  return $this->vendor;
149  }
150  public function setAuthToken($a_auth_token)
151  {
152  $this->auth_token = $a_auth_token;
153  }
154  public function getAuthToken()
155  {
156  return $this->auth_token;
157  }
158  public function setPageStyle($a_page_style)
159  {
160  $this->page_style = $a_page_style;
161  }
162  public function getPageStyle()
163  {
164  return $this->page_style;
165  }
166  public function setSsl($a_ssl)
167  {
168  $this->ssl = $a_ssl;
169  }
170  public function getSsl()
171  {
172  return $this->ssl;
173  }
174 
181  function getAll()
182  {
183  $values = array(
184  "server_host" => $this->getServerHost(),
185  "server_path" => $this->getServerPath(),
186  "vendor" => $this->getVendor(),
187  "auth_token" => $this->getAuthToken(),
188  "page_style" => $this->getPageStyle(),
189  "ssl" => $this->getSsl()
190  );
191 
192  return $values;
193  }
194 
200  function clearAll()
201  {
202  $query = "UPDATE payment_settings "
203  ."SET paypal = '' "
204  ."WHERE settings_id = '" . $this->settings_id . "'";
205  $this->db->query($query);
206 
207  $this->settings = array();
208  }
209 
215  public function save()
216  {
217  global $ilDB;
218 
219  $values = array(
220  "server_host" => $this->getServerHost(),
221  "server_path" => $this->getServerPath(),
222  "vendor" => $this->getVendor(),
223  "auth_token" => $this->getAuthToken(),
224  "page_style" => $this->getPageStyle(),
225  "ssl" => $this->getSsl()
226  );
227 
228  if ($this->getSettingsId())
229  {
230  $query = "UPDATE payment_settings "
231  ."SET paypal = " . $ilDB->quote(serialize($values)). " "
232  ."WHERE settings_id = '" . $this->getSettingsId() . "'";
233  $this->db->query($query);
234  }
235  else
236  {
237  $query = "INSERT INTO payment_settings (paypal) VALUES (" . $ilDB->quote(serialize($values)). ") ";
238 
239  $this->db->query($query);
240 
241  $this->setSettingsId($this->db->getLastInsertId());
242  }
243  }
244 }
245 ?>