ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilShopUtils.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
14 {
23 public static function _formatVAT($a_vat)
24 {
25 return ((float)$a_vat != floor((float)$a_vat) ?
26 self::_formatFloat((float)$a_vat) :
27 (int)$a_vat).' %';
28 }
29
38 public static function _formatFloat($a_float, $a_num_decimals = 2)
39 {
40 global $lng;
41
42 return number_format((float)$a_float, $a_num_decimals, $lng->txt('lang_sep_decimal'), $lng->txt('lang_sep_thousand'));
43 }
44
53 public static function _checkVATRate($a_vat_rate)
54 {
55 $reg = '/^([0]|([1-9][0-9]*))([\.,][0-9][0-9]*)?$/';
56 return preg_match($reg, $a_vat_rate);
57 }
58
66 public static function _sendNotificationToVATAdministration($oPaymentObject)
67 {
68 global $ilSetting, $lng, $ilClientIniFile;
69
70 $payment_vat_admins = $ilSetting->get('payment_vat_admins');
71 $users = explode(',', $payment_vat_admins);
72
73 $subject = $lng->txt('payment_vat_assignment_notification_subject');
74 $tmp_obj = ilObjectFactory::getInstanceByRefId($oPaymentObject->getRefId());
75 $message = sprintf($lng->txt('payment_vat_assignment_notification_body'), $tmp_obj->getTitle())."\n\n";
76 $message .= "------------------------------------------------------------\n";
77 $message .= sprintf($lng->txt('payment_vat_assignment_notification_intro'),
78 $ilClientIniFile->readVariable('client', 'name'),
79 ILIAS_HTTP_PATH.'/?client_id='.CLIENT_ID);
80
81 include_once 'Services/Mail/classes/class.ilMail.php';
82 $mail_obj = new ilMail(ANONYMOUS_USER_ID);
83 foreach((array)$users as $login)
84 {
85 if(strlen(trim($login)) &&
86 (int)ilObjUser::_lookupId(trim($login)))
87 {
88 $success = $mail_obj->sendMail(trim($login), '', '',
89 $subject, $message,
90 array(),array("system"));
91 }
92 }
93 }
94
95 public static function _createRandomUserAccount($keyarray)
96 {
97 global $ilDB, $ilUser, $ilSetting, $rbacadmin;
98
99 if($_SESSION['create_user_account'] != NULL)
100 {
101
102 $obj_user = new ilObjUser($_SESSION['create_user_account']);
103 return $obj_user;
104 }
105 else
106 {
107 $userLogin = array();
108 $res = $ilDB->query('SELECT sequence FROM object_data_seq');
109 $row = $ilDB->fetchAssoc($res);
110
111 $temp_user_id = (int)$row['sequence'] + 1;
112
113 $userLogin['login'] = 'shop_user_'.$temp_user_id;
114
115 $userLogin['passwd'] = ilUtil::generatePasswords(1);
116
117 require_once 'Services/User/classes/class.ilObjUser.php';
118 include_once("Services/Mail/classes/class.ilAccountMail.php");
119
120 $obj_user = new ilObjUser();
121 $obj_user->setId($temp_user_id);
122
123 $obj_user->setLogin($userLogin['login']);
124 $obj_user->setPasswd((string)$userLogin['passwd'][0], IL_PASSWD_PLAIN);
125
126 $_SESSION['tmp_user_account']['login'] = $userLogin['login'];
127 $_SESSION['tmp_user_account']['passwd'] = $userLogin['passwd'];
128
129 $obj_user->setFirstname($keyarray['first_name']);
130 $obj_user->setLastname($keyarray['last_name']);
131 $obj_user->setEmail($keyarray['payer_email']);
132 # $obj_user->setEmail('nkrzywon@databay.de');
133
134 $obj_user->setGender('f');
135 $obj_user->setLanguage( $ilSetting->get("language"));
136 $obj_user->setActive(true);
137 $obj_user->setTimeLimitUnlimited(true);
138
139 $obj_user->setTitle($obj_user->getFullname());
140 $obj_user->setDescription($obj_user->getEmail());
141 $obj_user->setTimeLimitOwner(7);
142 $obj_user->setTimeLimitUnlimited(1);
143 $obj_user->setTimeLimitMessage(0);
144 $obj_user->setApproveDate(date("Y-m-d H:i:s"));
145
146 // Set default prefs
147 $obj_user->setPref('hits_per_page',$ilSetting->get('hits_per_page',30));
148 $obj_user->setPref('show_users_online',$ilSetting->get('show_users_online','y'));
149 $obj_user->writePrefs();
150
151 // at the first login the user must complete profile
152 $obj_user->setProfileIncomplete(true);
153 $obj_user->create();
154 $obj_user->saveAsNew();
155
156 $user_role = ilObject::_exists(4, false);
157
158 if(!$user_role)
159 {
160 include_once("./Services/AccessControl/classes/class.ilObjRole.php");
161 $reg_allowed = ilObjRole::_lookupRegisterAllowed();
162 $user_role = $reg_allowed[0]['id'];
163
164 }
165 else $user_role = 4;
166
167 $rbacadmin->assignUser((int)$user_role, $obj_user->getId(), true);
168
169 include_once "Services/Mail/classes/class.ilMimeMail.php";
170 global $ilias, $lng;
171
172 $settings = $ilias->getAllSettings();
173 $mmail = new ilMimeMail();
174 $mmail->autoCheck(false);
175 $mmail->From($settings["admin_email"]);
176 $mmail->To($obj_user->getEmail());
177
178 // mail subject
179 $subject = $lng->txt("reg_mail_subject");
180
181 // mail body
182 $body = $lng->txt("reg_mail_body_salutation")." ".$obj_user->getFullname().",\n\n".
183 $lng->txt("reg_mail_body_text1")."\n\n".
184 $lng->txt("reg_mail_body_text2")."\n".
185 ILIAS_HTTP_PATH."/login.php?client_id=".$ilias->client_id."\n";
186 $body .= $lng->txt("login").": ".$obj_user->getLogin()."\n";
187
188
189 $body.= $lng->txt("passwd").": ".$userLogin['passwd'][0]."\n";
190
191 $body.= "\n";
192
193 $body .= ($lng->txt("reg_mail_body_text3")."\n\r");
194 $body .= $obj_user->getProfileAsString($lng);
195 $mmail->Subject($subject);
196 $mmail->Body($body);
197 $mmail->Send();
198
199 $_SESSION['create_user_account'] = $obj_user->getId();
200 return $obj_user;
201 }
202
203 }
204 public static function _assignTransactionToCustomerId($a_old_user_id, $a_new_user_id, $a_transaction_extern)
205 {
206 global $ilDB;
207
208 $res = $ilDB->manipulateF('
209 UPDATE payment_statistic
210 SET customer_id = %s
211 WHERE customer_id = %s
212 AND transaction_extern = %s',
213 array('integer', 'integer', 'text'),
214 array($a_new_user_id, $a_old_user_id, $a_transaction_extern));
215 }
216
217 public static function _addPurchasedObjToDesktop($oPaymentObject, $a_user_id = 0)
218 {
219 global $ilUser;
220
221 $type = ilObject::_lookupType($oPaymentObject->getRefId(),true);
222
223 if($a_user_id > 0)
224 {
225 // administrator added a selling process to statistics
226 $tmp_usr = new ilObjUser($a_user_id);
227 $tmp_usr->addDesktopItem($oPaymentObject->getRefId(),$type);
228 }
229 else
230 {
231 // user purchased object
232 $ilUser->addDesktopItem($oPaymentObject->getRefId(),$type);
233 }
234 }
235
236 public static function _assignPurchasedCourseMemberRole($oPaymentObject, $a_user_id = 0)
237 {
238 global $ilUser;
239 include_once './Modules/Course/classes/class.ilCourseParticipants.php';
240 $obj_id = ilObject::_lookupObjectId($oPaymentObject->getRefId());
241
242 $participants = ilCourseParticipants::_getInstanceByObjId($obj_id);
243
244 if($a_user_id > 0)
245 {
246 // administrator added a selling process to statistics
247 $res = $participants->add($a_user_id, IL_CRS_MEMBER);
248 }
249 else
250 {
251 $res = $participants->add($ilUser->getId(),IL_CRS_MEMBER);
252 }
253 }
254
255 public static function _addToShoppingCartSymbol($a_ref_id)
256 {
257 global $ilCtrl;
258
259 $detail_link = $ilCtrl->getLinkTargetByClass("ilShopPurchaseGUI", "showDetails").'&ref_id='.$a_ref_id;
260 $img = ilUtil::img('./templates/default/images/payment/shopcart_add.svg');
261
262 $link = '<a href="'.$detail_link.'">'.$img.'</a>';
263
264 return $link;
265 }
266
267 public static function _getSpecialObjectSymbol()
268 {
269 return $img = ilUtil::img('./templates/default/images/icon_rate_10.svg','', '24px', '24px');
270 }
271
272 public static function _getPaymethodSymbol($a_paymethod)
273 {
274 switch($a_paymethod)
275 {
276 case '1':
277 case 'pm_bill':
278 case 'bill':
279 case 'PAY_METHOD_BILL': return '';
280 break;
281
282 case '2':
283 case 'pm_bmf':
284 case 'bmf':
285 case 'PAY_METHOD_BMF': return '';
286 break;
287
288 case '3':
289 case 'pm_paypal':
290 case 'paypal':
291 case 'PAY_METHOD_PAYPAL': return ilUtil::img('./templates/default/images/payment/paypal.svg');
292 break;
293
294 case '4':
295 case 'pm_epay':
296 case 'epay':
297 case 'PAY_METHOD_EPAY': return '';
298 break;
299 case 'PAY_METHOD_NOT_SPECIFIED': return '';
300 break;
301 default:
302
303 break;
304 }
305 }
306 public static function _deassignPurchasedCourseMemberRole($a_ref_id, $a_user_id)
307 {
308 include_once './Modules/Course/classes/class.ilCourseParticipants.php';
309 $obj_id = ilObject::_lookupObjectId($a_ref_id);
310
311 $participants = ilCourseParticipants::_getInstanceByObjId($obj_id);
312 $res = $participants->delete($a_user_id, IL_CRS_MEMBER);
313 }
314}
$success
Definition: Utf8Test.php:87
$_SESSION["AccountId"]
const IL_PASSWD_PLAIN
const IL_CRS_MEMBER
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Class Mail this class handles base functions for mail handling.
this class encapsulates the PHP mail() function.
_lookupRegisterAllowed()
get all roles that are activated in user registration
static _lookupId($a_user_str)
Lookup id by login.
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjectId($a_ref_id)
lookup object id
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilShopUtils.
static _assignPurchasedCourseMemberRole($oPaymentObject, $a_user_id=0)
static _getSpecialObjectSymbol()
static _addPurchasedObjToDesktop($oPaymentObject, $a_user_id=0)
static _getPaymethodSymbol($a_paymethod)
static _checkVATRate($a_vat_rate)
Checks if the passed vat rate is valid.
static _formatVAT($a_vat)
Formats a vat rate for gui output.
static _createRandomUserAccount($keyarray)
static _sendNotificationToVATAdministration($oPaymentObject)
Sends a notification message to all users responsible for vat assignment.
static _addToShoppingCartSymbol($a_ref_id)
static _assignTransactionToCustomerId($a_old_user_id, $a_new_user_id, $a_transaction_extern)
static _formatFloat($a_float, $a_num_decimals=2)
Formats a float value for gui output.
static _deassignPurchasedCourseMemberRole($a_ref_id, $a_user_id)
static img($a_src, $a_alt="", $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static generatePasswords($a_number)
Generate a number of passwords.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40
global $ilSetting
Definition: privfeed.php:40
global $ilDB
global $ilUser
Definition: imgupload.php:15