ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 ?>