ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilERP_eco.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 require_once './Services/Payment/classes/class.ilERP.php';
34 
35 class ilERP_eco extends ilERP
36 {
37  private $agreement;
38  private $product;
39  private $terms;
40  private $layout;
41  private $code;
42 
43  private static $instance = null;
44 
45  public $client;
46 
47  const wsdl = "https://www.e-conomic.com/secure/api1/EconomicWebservice.asmx?WSDL";
48  private static $erp_id = ERP_ECONOMIC;
49  const name = "E-conomic";
50 
51  public function __construct()
52  {
53  //parent::__construct();
54  $this->loadSettings(0);
55  }
56 
57 
58 
65  public static function _getInstance()
66  {
67  if (isset(self::$instance) and self::$instance)
68  {
69  return self::$instance;
70  }
71  return self::$instance = new ilERP_eco();
72 
73  }
74 
75 
82  public function getSettings($erps_id = 0)
83  {
84  $this->loadSettings($erps_id);
85  $ap = parent::getSettings();
86  $ret = array();
87  $ret['agreement'] = $this->agreement;
88  $ret['product'] = $this->product;
89  $ret['terms'] = $this->terms;
90  $ret['layout'] = $this->layout;
91  $ret['code'] = $this->code;
92 
93  return array_merge($ap, $ret);
94  }
95 
96  public function connect()
97  {
98  if ($this->connection_ok) return;
99  try
100  {
101  $this->client = new SoapClient(self::wsdl, array("trace" => 1, "exceptions" => 1));
102  $this->client->Connect(array(
103  'agreementNumber' => $this->agreement,
104  'userName' => $this->username,
105  'password' => $this->password)
106  );
107  }
108  catch (Exception $e)
109  {
110  $this->connection_ok = false;
111  throw new ilERPException(__FILE__ . ":" . __LINE__ . " " . $e->getMessage());
112  }
113  $this->connection_ok = true;
114  }
115  public function disconnect()
116  {
117  unset($this->client);
118  $this->connection_ok = false;
119  }
120 
121  public function getName()
122  {
123  return "E-conomic";
124  }
125 
126 
131  private function setAgreement( $v )
132  {
133  $this->agreement = (int) $v;
134  }
135  private function setProduct( $v )
136  {
137  $this->product = (int) $v;
138  }
139  private function setTerms( $v )
140  {
141  $this->terms = (int) $v;
142  }
143  private function setLayout( $v )
144  {
145  $this->layout = (int) $v;
146  }
147  private function setCode( $v )
148  {
149  $this->code = $v;
150  }
151 
152 
153 
159  public function setSettings( $a )
160  {
161  $this->setAgreement( $a['agreement'] );
162  $this->setProduct( $a['product'] );
163  $this->setTerms( $a['terms'] );
164  $this->setLayout( $a['layout'] );
165  $this->setCode( $a['code'] );
167 
168  }
169 
176  public function looksValid()
177  {
178  //if (!parent::looksValid()) return false;
179 
180  $s = $this->getSettings();
181  $ok = true;
182  return true;
183  if ($s['agreement'] == 0) $ok = false;
184  if (($s['product']==0) || ($s['terms']==0) || ($s['layout']==0) ) $ok = false;
185  return $ok;
186  }
187 
193  public function loadSettings($erps_id = 0)
194  {
195  global $ilDB;
196 
197  $res = $ilDB->queryf('SELECT * FROM payment_erps WHERE erps_id=%s AND erp_id=%s',
198  array("integer", "integer"),
199  array($erps_id, ERP_ECONOMIC));
200 
201  $result = $res->fetchRow(DB_FETCHMODE_OBJECT);
202 
203  if (is_object($result))
204  {
205  if ($result->settings != "") $data = unserialize($result->settings);
206  else
207  {
208  // set some defaults
209  $data['agreement']=0;
210  $data['username']='erpuser';
211  $data['password']='pasword1234';
212  $data['product']=0;
213  $data['terms']=0;
214  $data['layout']=0;
215  $data['code']='EUR';
216  }
217  }
218  $this->setAgreement( $data['agreement'] );
219  $this->setUsername( $data['username'] );
220  $this->setPassword( $data['password'] );
221  $this->setProduct( $data['product']);
222  $this->setTerms( $data['terms']);
223  $this->setLayout( $data['layout']);
224  $this->setCode( $data['code']);
225  }
226 }
227 ?>