ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilERP.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 
31 define("ERP_NONE", 0);
32 define("ERP_ECONOMIC", 1);
33 
34 require_once './Services/Payment/exceptions/class.ilERPException.php';
35 
36 abstract class ilERP
37 {
38  protected $username;
39  protected $password;
40  protected $use_ean; // Danish public sector only.
41  protected $save_copy;
42 
43  private $erps_id =0; // future support for several settings
44  private static $erp_id = ERP_NONE;
45 
46  const preview_pre = "invoice_";
47  const preview_ext = ".pdf";
48  //abstract erp_id;
49 
50  abstract public function getName();
51  abstract public function loadSettings($erps_id=0);
52  //abstract public function saveSettings($settings);
53  abstract public function looksValid();
54  abstract public function connect();
55  abstract public function disconnect();
56 
57 
58 
63  private static function _getFilename()
64  {
65  global $ilias;
66  return self::preview_pre . $ilias->client_id . self::preview_ext;
67  }
68 
69  public static function getPreviewFile()
70  {
71  global $ilias;
72  return $ilias->ini_ilias->GROUPS['server']['absolute_path'] . '/' . self::_getFilename();
73  }
74 
75  public static function getPreviewUrl()
76  {
77  global $ilias;
78  return $ilias->ini_ilias->GROUPS['server']['http_path'] . '/' . self::_getFilename() ;
79  }
80  public static function getPreviewLink()
81  {
82  return self::getPreviewUrl . self::_getFilename() ;
83  }
84  public static function getSaveDirectory()
85  {
86  global $ilias;
87  return $ilias->ini_ilias->GROUPS['clients']['datadir'] . '/' . $ilias->client_id .'/invoices/';
88  }
89 
90  public static function preview_exists()
91  {
92  return file_exists( self::getPreviewFile() );
93  }
94  public static function preview_delete()
95  {
96  if (self::preview_exists())
97  unlink (self::getPreviewFile());
98  }
103  public static function getAllERPs()
104  {
105  global $ilDB;
106  $res = $ilDB->query('SELECT * FROM payment_erp ORDER BY erp_id' );
107  $a = array();
108  while ( $result = $res->fetchRow(MDB2_FETCHMODE_ASSOC) ) $a[$result['erp_id']] = $result;
109  return $a;
110  }
111 
115  public function setSettings($a)
116  {
117  $this->setUsername( $a['username'] );
118  $this->setPassword( $a['passsword'] );
119  $this->setSaveCopy( $a['save_copy'] );
120  $this->setUseEAN( $a['use_ean'] );
121  }
122 
123  public function saveSettings($settings)
124  {
125  global $ilDB;
126  unset( $settings['url']);
127  unset( $settings['description']);
128  unset( $settings['erp_short']);
129  unset( $settings['name']);
130 
131  $settings['save_copy'] = (int) $settings['save_copy'];
132  $settings['use_ean'] = (int) $settings['use_ean'];
133 
134  if ($settings['erp_id'] == 0)
135  {
136  unset($settings);
137  $settings['erp_id'] = 0;
138  }
139 
140  $ilDB->manipulateF("
141  UPDATE payment_erp SET save_copy=%s, use_ean=%s WHERE erp_id=%s",
142  array("integer", "integer", "integer"),
143  array($settings['save_copy'], $settings['use_ean'], $settings['erp_id'])
144  );
145 
146  unset($settings['save_copy']);
147  unset($settings['use_ean']);
148 
149  $ilDB->manipulateF("
150  UPDATE payment_erps SET settings=%s WHERE erps_id=%s AND erp_id=%s",
151  array("text", "integer", "integer"),
152  array( serialize($settings), $this->erps_id, $settings['erp_id']));
153  return true;
154  }
155 
156 
157 
162  protected function setUsername( $v )
163  {
164  $this->username = $v;
165  }
166 
171  protected function setPassword($v )
172  {
173  $this->password = $v;
174  }
175 
180  protected function setSaveCopy( $v )
181  {
182  $this->save_copy = (int) $v;
183  }
184 
185  protected function setUseEAN( $v )
186  {
187  $this->use_ean = (int) $v;
188  }
189 
190 
191 
197  public function setActive($erp_system = 0, $erp_settings = 0)
198  {
199  global $ilDB;
200  $ilDB->query('UPDATE payment_erps SET active=0');
201  $ilDB->query('UPDATE payment_erps SET active=1 WHERE erp_id=' . $erp_system . ' AND erps_id=' . $erp_settings);
202  }
203 
208  public static function getActive()
209  {
210  global $ilDB;
211  $row = $ilDB->query('SELECT payment_erps.erp_id, payment_erps.erps_id, payment_erp.erp_short,payment_erp.use_ean, payment_erp.save_copy FROM payment_erps,payment_erp WHERE payment_erps.active=1 AND payment_erps.erp_id=payment_erp.erp_id LIMIT 1');
212  $values = $row->fetchRow(MDB2_FETCHMODE_ASSOC);
213  return $values;
214  }
215 
216 
217 
218 
219 
220 
221 
222 
228  public function getSettings($elvis_is_alive = 0)
229  {
230  $system = $this->getERPConstants(self::$erp_id);
231  $a['username'] = $this->username;
232  $a['password'] = $this->password;
233  $a['use_ean'] = $this->use_ean;
234  $a['save_copy'] = $this->save_copy;
235  return array_merge($system, $a);
236  }
237 
238 
239 
240 
246  public function getERPconstants($erp_system = 0)
247  {
248  global $ilDB;
249  $res = $ilDB->query('SELECT * FROM payment_erp WHERE erp_id=' . $erp_system);
250  $result = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
251  return $result;
252  }
253 
254 
255 }
256 ?>