| 103 |
- |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/***************************************************************************
|
|
|
4 |
* Copyright (C) 2009-2011 by Geo Varghese(www.seopanel.in) *
|
|
|
5 |
* sendtogeo@gmail.com *
|
|
|
6 |
* *
|
|
|
7 |
* This program is free software; you can redistribute it and/or modify *
|
|
|
8 |
* it under the terms of the GNU General Public License as published by *
|
|
|
9 |
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
10 |
* (at your option) any later version. *
|
|
|
11 |
* *
|
|
|
12 |
* This program is distributed in the hope that it will be useful, *
|
|
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
15 |
* GNU General Public License for more details. *
|
|
|
16 |
* *
|
|
|
17 |
* You should have received a copy of the GNU General Public License *
|
|
|
18 |
* along with this program; if not, write to the *
|
|
|
19 |
* Free Software Foundation, Inc., *
|
|
|
20 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
21 |
***************************************************************************/
|
|
|
22 |
|
|
|
23 |
# class defines all user controller functions
|
|
|
24 |
class UserController extends Controller{
|
|
|
25 |
|
|
|
26 |
# index function
|
|
|
27 |
function index($info=''){
|
|
|
28 |
|
|
|
29 |
if(!isset($info['referer'])) {
|
|
|
30 |
$info['red_referer'] = isValidReferer($_SERVER['HTTP_REFERER']);
|
|
|
31 |
$this->set('post', $info);
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
$this->render('common/login');
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
# function to set login session items
|
|
|
38 |
function setLoginSession($userInfo) {
|
|
|
39 |
@Session::setSession('userInfo', $userInfo);
|
|
|
40 |
@Session::setSession('lang_code', $userInfo['lang_code']);
|
|
|
41 |
@Session::setSession('text', '');
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
# login function
|
|
|
45 |
function login(){
|
|
|
46 |
|
|
|
47 |
$_POST['userName'] = sanitizeData($_POST['userName']);
|
|
|
48 |
$this->set('post', $_POST);
|
|
|
49 |
$errMsg['userName'] = formatErrorMsg($this->validate->checkBlank($_POST['userName']));
|
|
|
50 |
$errMsg['password'] = formatErrorMsg($this->validate->checkBlank($_POST['password']));
|
|
|
51 |
if(!$this->validate->flagErr){
|
|
|
52 |
$sql = "select u.*,ut.user_type from users u,usertypes ut where u.utype_id=ut.id and u.username='".addslashes($_POST['userName'])."'";
|
|
|
53 |
$userInfo = $this->db->select($sql, true);
|
|
|
54 |
if(!empty($userInfo['id'])){
|
|
|
55 |
if($userInfo['password'] == md5($_POST['password'])){
|
|
|
56 |
|
|
|
57 |
// get user type spec details and verify whether to check activation or not
|
|
|
58 |
$activationStatus = true;
|
|
|
59 |
$userTypeCtrler = new UserTypeController();
|
|
|
60 |
if ($userTypeCtrler->isEmailActivationEnabledForUserType($userInfo['utype_id'])) {
|
|
|
61 |
if ($userInfo['confirm'] == 0) {
|
|
|
62 |
$activationStatus = false;
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
// check for user status and activation
|
|
|
67 |
if($userInfo['status'] && $activationStatus){
|
|
|
68 |
|
|
|
69 |
// if login after first installation
|
|
|
70 |
if (!empty($_POST['lang_code']) && ($_POST['lang_code'] != 'en')) {
|
|
|
71 |
$_POST['lang_code'] = addslashes($_POST['lang_code']);
|
|
|
72 |
$sql = "UPDATE `settings` SET set_val='".addslashes($_POST['lang_code'])."' WHERE set_name='SP_DEFAULTLANG'";
|
|
|
73 |
$this->db->query($sql);
|
|
|
74 |
|
|
|
75 |
$sql = "UPDATE users SET lang_code='".addslashes($_POST['lang_code'])."' WHERE id=1";
|
|
|
76 |
$this->db->query($sql);
|
|
|
77 |
|
|
|
78 |
$userInfo['lang_code'] = $_POST['lang_code'];
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
// update timezone
|
|
|
82 |
if (!empty($_POST['time_zone'])) {
|
|
|
83 |
$sql = "UPDATE `settings` SET set_val='".addslashes($_POST['time_zone'])."' WHERE set_name='SP_TIME_ZONE'";
|
|
|
84 |
$this->db->query($sql);
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
$uInfo['userId'] = $userInfo['id'];
|
|
|
88 |
$uInfo['userType'] = $userInfo['user_type'];
|
|
|
89 |
$uInfo['userTypeId'] = $userInfo['utype_id'];
|
|
|
90 |
$uInfo['lang_code'] = $userInfo['lang_code'];
|
|
|
91 |
$this->setLoginSession($uInfo);
|
|
|
92 |
|
|
|
93 |
if ($referer = isValidReferer($_POST['red_referer'])) {
|
|
|
94 |
redirectUrl($referer);
|
|
|
95 |
} else {
|
|
|
96 |
redirectUrl(SP_WEBPATH."/");
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
}else{
|
|
|
100 |
$msgTxt = $activationStatus ? $_SESSION['text']['login']["User inactive"] : $_SESSION['text']['login']["user_not_activated_msg"];
|
|
|
101 |
$errMsg['userName'] = formatErrorMsg($msgTxt);
|
|
|
102 |
}
|
|
|
103 |
}else{
|
|
|
104 |
$errMsg['password'] = formatErrorMsg($_SESSION['text']['login']["Password incorrect"]);
|
|
|
105 |
}
|
|
|
106 |
}else{
|
|
|
107 |
$errMsg['userName'] = formatErrorMsg($_SESSION['text']['login']["Login incorrect"]);
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
$this->set('errMsg', $errMsg);
|
|
|
111 |
$this->index($_POST);
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
# func to confirm the user registration
|
|
|
115 |
function confirmUser($confirmCode) {
|
|
|
116 |
$confirmCode = addslashes($confirmCode);
|
|
|
117 |
$sql = "select id from users where confirm_code='$confirmCode'";
|
|
|
118 |
$userInfo = $this->db->select($sql, true);
|
|
|
119 |
$error = "";
|
|
|
120 |
|
|
|
121 |
if(!empty($userInfo['id'])){
|
|
|
122 |
|
|
|
123 |
$sql = "update users set confirm=1,status=1 where id=".$userInfo['id'];
|
|
|
124 |
if($this->db->query($sql)){
|
|
|
125 |
$this->set('confirm', true);
|
|
|
126 |
}else{
|
|
|
127 |
$error = showErrorMsg($this->spTextRegister['user_confirm_content_1'], false, true);
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
} else {
|
|
|
131 |
$error = showErrorMsg($this->spTextRegister['user_confirm_content_1'], false, true);
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
$this->set('error', $error);
|
|
|
135 |
$this->render('common/registerconfirm');
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
# register function
|
|
|
139 |
function register($info = ""){
|
|
|
140 |
|
|
|
141 |
$seopluginCtrler = new SeoPluginsController();
|
|
|
142 |
$subscriptionActive = false;
|
|
|
143 |
$utypeCtrler = new UserTypeController();
|
|
|
144 |
$this->set('post', $info);
|
|
|
145 |
|
|
|
146 |
// check whetehr plugin installed or not
|
|
|
147 |
if ($seopluginCtrler->isPluginActive("Subscription")) {
|
|
|
148 |
$subscriptionActive = true;
|
|
|
149 |
$userTypeList = $utypeCtrler->getAllUserTypes();
|
|
|
150 |
$this->set('userTypeList', $userTypeList);
|
|
|
151 |
|
|
|
152 |
// include available payment gateways
|
|
|
153 |
include SP_PLUGINPATH . "/Subscription/paymentgateway.ctrl.php";
|
|
|
154 |
$pgCtrler = new PaymentGateway();
|
|
|
155 |
$pgList = $pgCtrler->__getAllPaymentGateway();
|
|
|
156 |
$this->set('pgList', $pgList);
|
|
|
157 |
$this->set('defaultPgId', $pgCtrler->__getDefaultPaymentGateway());
|
|
|
158 |
$this->set('spTextSubscription', $this->getLanguageTexts('subscription', $_SESSION['lang_code']));
|
|
|
159 |
|
|
|
160 |
$currencyCtrler = new CurrencyController();
|
|
|
161 |
$this->set('currencyList', $currencyCtrler->getCurrencyCodeMapList());
|
|
|
162 |
|
|
|
163 |
} else {
|
|
|
164 |
$this->set('defaultUserTypeId', $utypeCtrler->getDefaultUserTypeId());
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
$this->set('subscriptionActive', $subscriptionActive);
|
|
|
168 |
$this->render('common/register');
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
# function to show pricing
|
|
|
172 |
function showPricing(){
|
|
|
173 |
|
|
|
174 |
$seopluginCtrler = new SeoPluginsController();
|
|
|
175 |
$utypeCtrler = new UserTypeController();
|
|
|
176 |
|
|
|
177 |
// check whetehr plugin installed or not
|
|
|
178 |
if ($seopluginCtrler->isPluginActive("Subscription")) {
|
|
|
179 |
$userSpecFields = $utypeCtrler->userSpecFields;
|
|
|
180 |
$userTypeList = $utypeCtrler->getAllUserTypes();
|
|
|
181 |
$list = array();
|
|
|
182 |
foreach ($userTypeList as $userType) $list[$userType['id']] = $userType;
|
|
|
183 |
$this->set('list', $list);
|
|
|
184 |
|
|
|
185 |
$spTextSubscription = $this->getLanguageTexts('subscription', $_SESSION['lang_code']);
|
|
|
186 |
$spTextTools = $this->getLanguageTexts('seotools', $_SESSION['lang_code']);
|
|
|
187 |
$this->set('spTextSubscription', $spTextSubscription);
|
|
|
188 |
|
|
|
189 |
// get all plugin access list
|
|
|
190 |
$pluginAccessList = $utypeCtrler->getPluginAccessSettings();
|
|
|
191 |
$pluginNameList = array();
|
|
|
192 |
foreach ($pluginAccessList as $pluginAccessInfo) {
|
|
|
193 |
if ($pluginAccessInfo['status'] == 0) continue;
|
|
|
194 |
$pluginNameList[$pluginAccessInfo['name']] = $pluginAccessInfo['label'];
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
// get all seo tool access list
|
|
|
198 |
$toolAccessList = $utypeCtrler->getSeoToolAccessSettings();
|
|
|
199 |
$toolNameList = array();
|
|
|
200 |
foreach ($toolAccessList as $toolAccessInfo) {
|
|
|
201 |
if ($toolAccessInfo['status'] == 0) continue;
|
|
|
202 |
$toolNameList[$toolAccessInfo['name']] = $spTextTools[$toolAccessInfo['url_section']];
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
$utypeSpecList = array();
|
|
|
206 |
$spText = $_SESSION['text'];
|
|
|
207 |
foreach ($userSpecFields as $specName) {
|
|
|
208 |
|
|
|
209 |
if (in_array($specName, array('enable_email_activation'))) continue;
|
|
|
210 |
|
|
|
211 |
if (stristr($specName, 'plugin_')) {
|
|
|
212 |
if (empty($pluginNameList[$specName])) continue;
|
|
|
213 |
$utypeSpecList[$specName] = $pluginNameList[$specName];
|
|
|
214 |
continue;
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
if (stristr($specName, 'seotool_')) {
|
|
|
218 |
if (empty($toolNameList[$specName])) continue;
|
|
|
219 |
$utypeSpecList[$specName] = $toolNameList[$specName];
|
|
|
220 |
continue;
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
switch ($specName) {
|
|
|
224 |
case "price":
|
|
|
225 |
$utypeSpecList[$specName] = $spText['common']['Price'];
|
|
|
226 |
break;
|
|
|
227 |
case "keywordcount":
|
|
|
228 |
$utypeSpecList[$specName] = $spText['common']['Keywords Count'];
|
|
|
229 |
break;
|
|
|
230 |
case "websitecount":
|
|
|
231 |
$utypeSpecList[$specName] = $spText['common']['Websites Count'];
|
|
|
232 |
break;
|
|
|
233 |
case "searchengine_count":
|
|
|
234 |
$utypeSpecList[$specName] = $spText['common']['Search Engine Count'];
|
|
|
235 |
break;
|
|
|
236 |
case "directory_submit_limit":
|
|
|
237 |
$utypeSpecList[$specName] = $spTextSubscription['Directory Submit Limit'];
|
|
|
238 |
break;
|
|
|
239 |
case "directory_submit_daily_limit":
|
|
|
240 |
$utypeSpecList[$specName] = $spTextSubscription['Directory Submit Daily Limit'];
|
|
|
241 |
break;
|
|
|
242 |
case "social_media_link_count":
|
|
|
243 |
$utypeSpecList[$specName] = $spTextSubscription['Social Media Link Count'];
|
|
|
244 |
break;
|
|
|
245 |
default:
|
|
|
246 |
$utypeSpecList[$specName] = $spTextSubscription[$specName];
|
|
|
247 |
|
|
|
248 |
}
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
$this->set('utypeSpecList', $utypeSpecList);
|
|
|
252 |
$currencyCtrler = new CurrencyController();
|
|
|
253 |
$this->set('currencyList', $currencyCtrler->getCurrencyCodeMapList());
|
|
|
254 |
$this->render('common/pricing');
|
|
|
255 |
} else {
|
|
|
256 |
redirectUrl(SP_WEBPATH . "/register.php");
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
# function to start registration
|
|
|
262 |
function startRegistration(){
|
|
|
263 |
$utypeCtrler = New UserTypeController();
|
|
|
264 |
$_POST = sanitizeData($_POST);
|
|
|
265 |
$this->set('post', $_POST);
|
|
|
266 |
$userInfo = $_POST;
|
|
|
267 |
$subscriptionActive = false;
|
|
|
268 |
$userStatus = 1;
|
|
|
269 |
|
|
|
270 |
$errMsg['userName'] = formatErrorMsg($this->validate->checkUname($userInfo['userName']));
|
|
|
271 |
$errMsg['password'] = formatErrorMsg($this->validate->checkPasswords($userInfo['password'], $userInfo['confirmPassword']));
|
|
|
272 |
$errMsg['firstName'] = formatErrorMsg($this->validate->checkBlank($userInfo['firstName']));
|
|
|
273 |
$errMsg['lastName'] = formatErrorMsg($this->validate->checkBlank($userInfo['lastName']));
|
|
|
274 |
$errMsg['email'] = formatErrorMsg($this->validate->checkEmail($userInfo['email']));
|
|
|
275 |
$errMsg['code'] = formatErrorMsg($this->validate->checkCaptcha($userInfo['code']));
|
|
|
276 |
$errMsg['utype_id'] = formatErrorMsg($this->validate->checkNumber($userInfo['utype_id']));
|
|
|
277 |
|
|
|
278 |
// if admin user type selected, show error
|
|
|
279 |
$adminTypeId = $utypeCtrler->getAdminUserTypeId();
|
|
|
280 |
if ($adminTypeId == $userInfo['utype_id']) {
|
|
|
281 |
$this->validate->flagErr = true;
|
|
|
282 |
$errMsg['userName'] = formatErrorMsg("You can not register as admin!!");
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
// if payment plugin installed check whether valid payment gateway found
|
|
|
286 |
$seopluginCtrler = new SeoPluginsController();
|
|
|
287 |
if ($seopluginCtrler->isPluginActive("Subscription")) {
|
|
|
288 |
$subscriptionActive = true;
|
|
|
289 |
$errMsg['pg_id'] = formatErrorMsg($this->validate->checkNumber($userInfo['pg_id']));
|
|
|
290 |
$userStatus = 0;
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
if(!$this->validate->flagErr){
|
|
|
294 |
if (!$this->__checkUserName($userInfo['userName'])) {
|
|
|
295 |
if (!$this->__checkEmail($userInfo['email'])) {
|
|
|
296 |
$utypeId = intval($userInfo['utype_id']);
|
|
|
297 |
$sql = "insert into users
|
|
|
298 |
(utype_id,username,password,first_name,last_name,email,created,status)
|
|
|
299 |
values ($utypeId,'".addslashes($userInfo['userName'])."','".md5($userInfo['password'])."',
|
|
|
300 |
'".addslashes($userInfo['firstName'])."','".addslashes($userInfo['lastName'])."',
|
|
|
301 |
'".addslashes($userInfo['email'])."',UNIX_TIMESTAMP(),$userStatus)";
|
|
|
302 |
$this->db->query($sql);
|
|
|
303 |
|
|
|
304 |
// get user id created
|
|
|
305 |
$userId = $this->db->getMaxId('users');
|
|
|
306 |
$error = 0;
|
|
|
307 |
|
|
|
308 |
// check whether subscription is active
|
|
|
309 |
if ($subscriptionActive and $userId) {
|
|
|
310 |
$utypeInfo = $utypeCtrler->__getUserTypeInfo($utypeId);
|
|
|
311 |
|
|
|
312 |
// if it is paid subscription, proceed with payment
|
|
|
313 |
if ($utypeInfo['price'] > 0) {
|
|
|
314 |
$paymentPluginId = intval($userInfo['pg_id']);
|
|
|
315 |
@Session::setSession('payment_plugin_id', $paymentPluginId);
|
|
|
316 |
$quantity = intval($userInfo['quantity']);
|
|
|
317 |
$pluginCtrler = $seopluginCtrler->createPluginObject("Subscription");
|
|
|
318 |
$paymentForm = $pluginCtrler->pgCtrler->getPaymentForm($paymentPluginId, $userId, $utypeInfo, $quantity);
|
|
|
319 |
$this->set('paymentForm', $paymentForm);
|
|
|
320 |
} else {
|
|
|
321 |
$this->__changeStatus($userId, 1);
|
|
|
322 |
|
|
|
323 |
// if trial period is set for user type
|
|
|
324 |
if (!empty($utypeInfo['free_trial_period'])) {
|
|
|
325 |
$totalDays = intval($utypeInfo['free_trial_period']);
|
|
|
326 |
$day = date('d') + $totalDays;
|
|
|
327 |
$expiryTimeStamp = mktime(23, 59, 59, date('m'), $day, date('Y'));
|
|
|
328 |
$expiryDate = date('Y-m-d', $expiryTimeStamp);
|
|
|
329 |
$this->updateUserInfo($userId, 'expiry_date', $expiryDate);
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
}
|
|
|
333 |
}
|
|
|
334 |
|
|
|
335 |
# get confirm code
|
|
|
336 |
if ($utypeCtrler->isEmailActivationEnabledForUserType($utypeId)) {
|
|
|
337 |
$this->__changeStatus($userId, 0);
|
|
|
338 |
$cfm = str_shuffle($userId . $userInfo['userName']);
|
|
|
339 |
$sql = "update users set confirm_code='$cfm' where id=$userId";
|
|
|
340 |
$this->db->query($sql);
|
|
|
341 |
$this->set('confirmLink', SP_WEBPATH . "/register.php?sec=confirm&code=$cfm");
|
|
|
342 |
|
|
|
343 |
// get mail details
|
|
|
344 |
$adminInfo = $this->__getAdminInfo();
|
|
|
345 |
$adminName = $adminInfo['first_name']." ".$adminInfo['last_name'];
|
|
|
346 |
$this->set('name', $userInfo['firstName']." ".$userInfo['lastName']);
|
|
|
347 |
$subject = SP_COMPANY_NAME . " " . $this->spTextRegister['Registration'];
|
|
|
348 |
$content = $this->getViewContent('email/accountconfirmation');
|
|
|
349 |
|
|
|
350 |
if(!sendMail($adminInfo['email'], $adminName, $userInfo['email'], $subject, $content)){
|
|
|
351 |
$error = showErrorMsg(
|
|
|
352 |
'An internal error occured while sending confirmation mail! Please <a href="'.SP_CONTACT_LINK.'">contact</a> seo panel team.',
|
|
|
353 |
false
|
|
|
354 |
);
|
|
|
355 |
}
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
$this->set('error', $error);
|
|
|
359 |
$this->render('common/registerconfirm');
|
|
|
360 |
return True;
|
|
|
361 |
|
|
|
362 |
}else{
|
|
|
363 |
$errMsg['email'] = formatErrorMsg($_SESSION['text']['login']['emailexist']);
|
|
|
364 |
}
|
|
|
365 |
}else{
|
|
|
366 |
$errMsg['userName'] = formatErrorMsg($_SESSION['text']['login']['usernameexist']);
|
|
|
367 |
}
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
$this->set('errMsg', $errMsg);
|
|
|
371 |
$this->register($userInfo);
|
|
|
372 |
}
|
|
|
373 |
|
|
|
374 |
# function for logout
|
|
|
375 |
function logout(){
|
|
|
376 |
Session::destroySession();
|
|
|
377 |
redirectUrl(SP_WEBPATH."/login.php");
|
|
|
378 |
}
|
|
|
379 |
|
|
|
380 |
# func to show users
|
|
|
381 |
function listUsers($info=''){
|
|
|
382 |
|
|
|
383 |
$info['pageno'] = intval($info['pageno']);
|
|
|
384 |
$pageScriptPath = 'users.php?stscheck=';
|
|
|
385 |
$pageScriptPath .= isset($info['stscheck']) ? $info['stscheck'] : "select";
|
|
|
386 |
$sql = "select * from users where utype_id!=1";
|
|
|
387 |
|
|
|
388 |
// if status set
|
|
|
389 |
if (isset($info['stscheck']) && $info['stscheck'] != 'select') {
|
|
|
390 |
$info['stscheck'] = intval($info['stscheck']);
|
|
|
391 |
$sql .= " and status='{$info['stscheck']}'";
|
|
|
392 |
}
|
|
|
393 |
|
|
|
394 |
// search for user name
|
|
|
395 |
if (!empty($info['user_name'])) {
|
|
|
396 |
$sql .= " and (username like '%".addslashes($info['user_name'])."%'
|
|
|
397 |
or first_name like '%".addslashes($info['user_name'])."%'
|
|
|
398 |
or last_name like '%".addslashes($info['user_name'])."%')";
|
|
|
399 |
$pageScriptPath .= "&user_name=" . $info['user_name'];
|
|
|
400 |
}
|
|
|
401 |
|
|
|
402 |
$sql .= " order by username";
|
|
|
403 |
|
|
|
404 |
# pagination setup
|
|
|
405 |
$this->db->query($sql, true);
|
|
|
406 |
$this->paging->setDivClass('pagingdiv');
|
|
|
407 |
$this->paging->loadPaging($this->db->noRows, SP_PAGINGNO);
|
|
|
408 |
$pagingDiv = $this->paging->printPages($pageScriptPath, '', 'scriptDoLoad', 'content', 'layout=ajax');
|
|
|
409 |
$this->set('pagingDiv', $pagingDiv);
|
|
|
410 |
$sql .= " limit ".$this->paging->start .",". $this->paging->per_page;
|
|
|
411 |
|
|
|
412 |
$statusList = array(
|
|
|
413 |
$_SESSION['text']['common']['Active'] => 1,
|
|
|
414 |
$_SESSION['text']['common']['Inactive'] => 0,
|
|
|
415 |
);
|
|
|
416 |
|
|
|
417 |
$this->set('statusList', $statusList);
|
|
|
418 |
$this->set('info', $info);
|
|
|
419 |
|
|
|
420 |
$userList = $this->db->select($sql);
|
|
|
421 |
$this->set('userList', $userList);
|
|
|
422 |
$this->set('pageNo', $info['pageno']);
|
|
|
423 |
$this->render('user/list', 'ajax');
|
|
|
424 |
}
|
|
|
425 |
|
|
|
426 |
# func to change status
|
|
|
427 |
function __changeStatus($userId, $status){
|
|
|
428 |
|
|
|
429 |
$userId = intval($userId);
|
|
|
430 |
$sql = "update users set status=$status where id=$userId";
|
|
|
431 |
$this->db->query($sql);
|
|
|
432 |
|
|
|
433 |
# deaactivate all websites under this user
|
|
|
434 |
if(empty($status)){
|
|
|
435 |
$websiteCtrler = New WebsiteController();
|
|
|
436 |
$websiteList = $websiteCtrler->__getAllWebsites($userId);
|
|
|
437 |
foreach ($websiteList as $websiteInfo){
|
|
|
438 |
$websiteCtrler->__changeStatus($websiteInfo['id'], 0);
|
|
|
439 |
}
|
|
|
440 |
}
|
|
|
441 |
}
|
|
|
442 |
|
|
|
443 |
# func to change status
|
|
|
444 |
function __deleteUser($userId){
|
|
|
445 |
|
|
|
446 |
$userId = intval($userId);
|
|
|
447 |
$sql = "delete from users where id=$userId";
|
|
|
448 |
$this->db->query($sql);
|
|
|
449 |
|
|
|
450 |
$sql = "select id from websites where user_id=$userId";
|
|
|
451 |
$webisteList = $this->db->select($sql);
|
|
|
452 |
$webisteCtrler = New WebsiteController();
|
|
|
453 |
foreach($webisteList as $webisteInfo){
|
|
|
454 |
$webisteCtrler->__deleteWebsite($webisteInfo['id']);
|
|
|
455 |
}
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
function newUser(){
|
|
|
459 |
|
|
|
460 |
// Get the user types
|
|
|
461 |
$userTypeCtlr = new UserTypeController();
|
|
|
462 |
$userTypeList = $userTypeCtlr->getAllUserTypes();
|
|
|
463 |
$this->set('userTypeList', $userTypeList);
|
|
|
464 |
$this->render('user/new', 'ajax');
|
|
|
465 |
}
|
|
|
466 |
|
|
|
467 |
function __checkUserName($username){
|
|
|
468 |
$sql = "select id from users where username='$username'";
|
|
|
469 |
$userInfo = $this->db->select($sql, true);
|
|
|
470 |
return empty($userInfo['id']) ? false : $userInfo['id'];
|
|
|
471 |
}
|
|
|
472 |
|
|
|
473 |
function __checkEmail($email){
|
|
|
474 |
|
|
|
475 |
$sql = "select id from users where email='".addslashes($email)."'";
|
|
|
476 |
$userInfo = $this->db->select($sql, true);
|
|
|
477 |
return empty($userInfo['id']) ? false : $userInfo['id'];
|
|
|
478 |
}
|
|
|
479 |
|
|
|
480 |
function __getUserInfo($userId){
|
|
|
481 |
|
|
|
482 |
$userId = intval($userId);
|
|
|
483 |
$sql = "select * from users where id=$userId";
|
|
|
484 |
$userInfo = $this->db->select($sql, true);
|
|
|
485 |
return empty($userInfo['id']) ? false : $userInfo;
|
|
|
486 |
}
|
|
|
487 |
|
|
|
488 |
# get admin user details
|
|
|
489 |
function __getAdminInfo(){
|
|
|
490 |
$sql = "select * from users where utype_id=1";
|
|
|
491 |
$userInfo = $this->db->select($sql, true);
|
|
|
492 |
return empty($userInfo['id']) ? false : $userInfo;
|
|
|
493 |
}
|
|
|
494 |
|
|
|
495 |
#function to get all users
|
|
|
496 |
function __getAllUsers($active=1,$admin=true, $orderByCol = "username"){
|
|
|
497 |
$sql = "select * from users where status=$active";
|
|
|
498 |
$sql .= $admin ? "" : " and utype_id!=1";
|
|
|
499 |
$sql .= " order by " . addslashes($orderByCol);
|
|
|
500 |
$userList = $this->db->select($sql);
|
|
|
501 |
return $userList;
|
|
|
502 |
}
|
|
|
503 |
|
|
|
504 |
#function to get all users having website
|
|
|
505 |
function __getAllUsersHavingWebsite($active=1,$admin=true){
|
|
|
506 |
$sql = "select u.* from users u,websites w where w.user_id=u.id and u.status=$active and w.status=1";
|
|
|
507 |
$sql .= $admin ? "" : " and utype_id!=1";
|
|
|
508 |
$sql .= " group by u.id order by username";
|
|
|
509 |
$userList = $this->db->select($sql);
|
|
|
510 |
return $userList;
|
|
|
511 |
}
|
|
|
512 |
|
|
|
513 |
function createUser($userInfo, $renderResults = true){
|
|
|
514 |
$userInfo = sanitizeData($userInfo);
|
|
|
515 |
$this->set('post', $userInfo);
|
|
|
516 |
$errMsg['userName'] = formatErrorMsg($this->validate->checkUname($userInfo['userName']));
|
|
|
517 |
$errMsg['password'] = formatErrorMsg($this->validate->checkPasswords($userInfo['password'], $userInfo['confirmPassword']));
|
|
|
518 |
$errMsg['firstName'] = formatErrorMsg($this->validate->checkBlank($userInfo['firstName']));
|
|
|
519 |
$errMsg['lastName'] = formatErrorMsg($this->validate->checkBlank($userInfo['lastName']));
|
|
|
520 |
$errMsg['email'] = formatErrorMsg($this->validate->checkEmail($userInfo['email']));
|
|
|
521 |
$userTypeId = empty($userInfo['userType']) ? 2 : intval($userInfo['userType']);
|
|
|
522 |
$userStatus = isset($userInfo['status']) ? intval($userInfo['status']) : 1;
|
|
|
523 |
|
|
|
524 |
// if expiry date is not empty
|
|
|
525 |
if (!empty($userInfo['expiry_date'])) {
|
|
|
526 |
$errMsg['expiry_date'] = formatErrorMsg($this->validate->checkDate($userInfo['expiry_date']));
|
|
|
527 |
$userInfo['expiry_date'] = "'".addslashes($userInfo['expiry_date'])."'";
|
|
|
528 |
} else {
|
|
|
529 |
$userInfo['expiry_date'] = "NULL";
|
|
|
530 |
}
|
|
|
531 |
|
|
|
532 |
// check error flag is on
|
|
|
533 |
if(!$this->validate->flagErr){
|
|
|
534 |
if (!$this->__checkUserName($userInfo['userName'])) {
|
|
|
535 |
if (!$this->__checkEmail($userInfo['email'])) {
|
|
|
536 |
$sql = "insert into users(utype_id,username,password,first_name,last_name,email,created,status, expiry_date)
|
|
|
537 |
values($userTypeId,'".addslashes($userInfo['userName'])."','".md5($userInfo['password'])."'
|
|
|
538 |
,'".addslashes($userInfo['firstName'])."', '".addslashes($userInfo['lastName'])."'
|
|
|
539 |
,'".addslashes($userInfo['email'])."',UNIX_TIMESTAMP(),$userStatus, {$userInfo['expiry_date']})";
|
|
|
540 |
$this->db->query($sql);
|
|
|
541 |
|
|
|
542 |
// if render results
|
|
|
543 |
if ($renderResults) {
|
|
|
544 |
$this->listUsers('ajax');
|
|
|
545 |
exit;
|
|
|
546 |
} else {
|
|
|
547 |
return array('success', 'Successfully created user');
|
|
|
548 |
}
|
|
|
549 |
}else{
|
|
|
550 |
$errMsg['email'] = formatErrorMsg($_SESSION['text']['login']['emailexist']);
|
|
|
551 |
}
|
|
|
552 |
}else{
|
|
|
553 |
$errMsg['userName'] = formatErrorMsg($_SESSION['text']['login']['usernameexist']);
|
|
|
554 |
}
|
|
|
555 |
}
|
|
|
556 |
|
|
|
557 |
// if render results
|
|
|
558 |
if ($renderResults) {
|
|
|
559 |
$this->set('errMsg', $errMsg);
|
|
|
560 |
$this->newUser();
|
|
|
561 |
} else {
|
|
|
562 |
return array('error', $errMsg);
|
|
|
563 |
}
|
|
|
564 |
}
|
|
|
565 |
|
|
|
566 |
function editUser($userId, $userInfo=''){
|
|
|
567 |
|
|
|
568 |
if(!empty($userId)){
|
|
|
569 |
if(empty($userInfo)){
|
|
|
570 |
$userInfo = $this->__getUserInfo($userId);
|
|
|
571 |
$userInfo['userName'] = $userInfo['username'];
|
|
|
572 |
$userInfo['firstName'] = $userInfo['first_name'];
|
|
|
573 |
$userInfo['lastName'] = $userInfo['last_name'];
|
|
|
574 |
$userInfo['oldName'] = $userInfo['username'];
|
|
|
575 |
$userInfo['oldEmail'] = $userInfo['email'];
|
|
|
576 |
$userInfo['userType'] = $userInfo['utype_id'];
|
|
|
577 |
$userInfo['expiry_date'] = formatDate($userInfo['expiry_date']);
|
|
|
578 |
}
|
|
|
579 |
|
|
|
580 |
// Get the user types
|
|
|
581 |
$userTypeCtlr = new UserTypeController();
|
|
|
582 |
$userTypeList = $userTypeCtlr->getAllUserTypes();
|
|
|
583 |
|
|
|
584 |
$userInfo['password'] = '';
|
|
|
585 |
$this->set('post', $userInfo);
|
|
|
586 |
$this->set('userTypeList', $userTypeList);
|
|
|
587 |
$this->render('user/edit', 'ajax');
|
|
|
588 |
exit;
|
|
|
589 |
}
|
|
|
590 |
$this->listUsers('ajax');
|
|
|
591 |
}
|
|
|
592 |
|
|
|
593 |
function updateUser($userInfo, $renderResults = true){
|
|
|
594 |
$userInfo = sanitizeData($userInfo);
|
|
|
595 |
$userInfo['id'] = intval($userInfo['id']);
|
|
|
596 |
$this->set('post', $userInfo);
|
|
|
597 |
$errMsg['userName'] = formatErrorMsg($this->validate->checkUname($userInfo['userName']));
|
|
|
598 |
|
|
|
599 |
// if expiry date is not empty
|
|
|
600 |
if (!empty($userInfo['expiry_date'])) {
|
|
|
601 |
$errMsg['expiry_date'] = formatErrorMsg($this->validate->checkDate($userInfo['expiry_date']));
|
|
|
602 |
$expiryStr = "expiry_date='".addslashes($userInfo['expiry_date'])."',";
|
|
|
603 |
} else {
|
|
|
604 |
$expiryStr = "expiry_date=NULL,";
|
|
|
605 |
}
|
|
|
606 |
|
|
|
607 |
// if password needs to be reset
|
|
|
608 |
if(!empty($userInfo['password'])){
|
|
|
609 |
$errMsg['password'] = formatErrorMsg($this->validate->checkPasswords($userInfo['password'], $userInfo['confirmPassword']));
|
|
|
610 |
$passStr = "password = '".md5($userInfo['password'])."',";
|
|
|
611 |
}
|
|
|
612 |
|
|
|
613 |
// if change status of user
|
|
|
614 |
if (isset($userInfo['status'])) {
|
|
|
615 |
$activeStr = "status = '".intval($userInfo['status'])."',";
|
|
|
616 |
}
|
|
|
617 |
|
|
|
618 |
$errMsg['firstName'] = formatErrorMsg($this->validate->checkBlank($userInfo['firstName']));
|
|
|
619 |
$errMsg['lastName'] = formatErrorMsg($this->validate->checkBlank($userInfo['lastName']));
|
|
|
620 |
$errMsg['email'] = formatErrorMsg($this->validate->checkEmail($userInfo['email']));
|
|
|
621 |
if(!$this->validate->flagErr){
|
|
|
622 |
|
|
|
623 |
if($userInfo['userName'] != $userInfo['oldName']){
|
|
|
624 |
if ($this->__checkUserName($userInfo['userName'])) {
|
|
|
625 |
$errMsg['userName'] = formatErrorMsg($_SESSION['text']['login']['usernameexist']);
|
|
|
626 |
$this->validate->flagErr = true;
|
|
|
627 |
}
|
|
|
628 |
}
|
|
|
629 |
|
|
|
630 |
if($userInfo['email'] != $userInfo['oldEmail']){
|
|
|
631 |
if ($this->__checkEmail($userInfo['email'])) {
|
|
|
632 |
$errMsg['email'] = formatErrorMsg($_SESSION['text']['login']['emailexist']);
|
|
|
633 |
$this->validate->flagErr = true;
|
|
|
634 |
}
|
|
|
635 |
}
|
|
|
636 |
|
|
|
637 |
// if no error to inputs
|
|
|
638 |
if (!$this->validate->flagErr) {
|
|
|
639 |
$sql = "update users set
|
|
|
640 |
username = '".addslashes($userInfo['userName'])."',
|
|
|
641 |
first_name = '".addslashes($userInfo['firstName'])."',
|
|
|
642 |
last_name = '".addslashes($userInfo['lastName'])."',
|
|
|
643 |
$passStr
|
|
|
644 |
$activeStr
|
|
|
645 |
$expiryStr
|
|
|
646 |
email = '".addslashes($userInfo['email'])."',
|
|
|
647 |
utype_id = ".addslashes($userInfo['userType'])."
|
|
|
648 |
where id={$userInfo['id']}";
|
|
|
649 |
$this->db->query($sql);
|
|
|
650 |
|
|
|
651 |
// if render results
|
|
|
652 |
if ($renderResults) {
|
|
|
653 |
$this->listUsers('ajax');
|
|
|
654 |
exit;
|
|
|
655 |
} else {
|
|
|
656 |
return array('success', 'Successfully updated user');
|
|
|
657 |
}
|
|
|
658 |
|
|
|
659 |
}
|
|
|
660 |
}
|
|
|
661 |
|
|
|
662 |
if ($renderResults) {
|
|
|
663 |
$this->set('errMsg', $errMsg);
|
|
|
664 |
$this->editUser($userInfo['id'], $userInfo);
|
|
|
665 |
} else {
|
|
|
666 |
return array('error', $errMsg);
|
|
|
667 |
}
|
|
|
668 |
|
|
|
669 |
|
|
|
670 |
}
|
|
|
671 |
|
|
|
672 |
function showMyProfile($info = ''){
|
|
|
673 |
$userId = isLoggedIn();
|
|
|
674 |
if(!empty($userId)){
|
|
|
675 |
$userInfo = $this->__getUserInfo($userId);
|
|
|
676 |
$this->set('userInfo', $userInfo);
|
|
|
677 |
$userTypeCtrler = new UserTypeController();
|
|
|
678 |
$userTypeInfo = $userTypeCtrler->__getUserTypeInfo($userInfo['utype_id']);
|
|
|
679 |
$this->set('userTypeInfo', $userTypeInfo);
|
|
|
680 |
$seopluginCtrler = new SeoPluginsController();
|
|
|
681 |
$this->set('subscriptionActive', $seopluginCtrler->isPluginActive("Subscription"));
|
|
|
682 |
$spTextSubscription = $this->getLanguageTexts('subscription', $_SESSION['lang_code']);
|
|
|
683 |
$this->set('spTextSubscription', $spTextSubscription);
|
|
|
684 |
$this->render('user/showmyprofile', 'ajax');
|
|
|
685 |
}
|
|
|
686 |
}
|
|
|
687 |
|
|
|
688 |
# function to renew membership subscription
|
|
|
689 |
function renewMyProfile($info = ''){
|
|
|
690 |
$userId = isLoggedIn();
|
|
|
691 |
$seopluginCtrler = new SeoPluginsController();
|
|
|
692 |
|
|
|
693 |
// if logged in and plugin is active
|
|
|
694 |
if(!empty($userId) && $seopluginCtrler->isPluginActive("Subscription") && !isAdmin()){
|
|
|
695 |
$userInfo = $this->__getUserInfo($userId);
|
|
|
696 |
$this->set('userInfo', $userInfo);
|
|
|
697 |
|
|
|
698 |
$userTypeCtrler = new UserTypeController();
|
|
|
699 |
$userTypeInfo = $userTypeCtrler->__getUserTypeInfo($userInfo['utype_id']);
|
|
|
700 |
$this->set('userTypeInfo', $userTypeInfo);
|
|
|
701 |
|
|
|
702 |
$spTextSubscription = $this->getLanguageTexts('subscription', $_SESSION['lang_code']);
|
|
|
703 |
$this->set('spTextSubscription', $spTextSubscription);
|
|
|
704 |
include_once(SP_PLUGINPATH . "/Subscription/paymentgateway.ctrl.php");
|
|
|
705 |
|
|
|
706 |
$userTypeList = $userTypeCtrler->getRenewUserTypeList($userInfo['utype_id']);
|
|
|
707 |
$this->set('userTypeList', $userTypeList);
|
|
|
708 |
|
|
|
709 |
$currencyCtrler = new CurrencyController();
|
|
|
710 |
$this->set('currencyList', $currencyCtrler->getCurrencyCodeMapList());
|
|
|
711 |
|
|
|
712 |
// include available payment gateways
|
|
|
713 |
$pgCtrler = new PaymentGateway();
|
|
|
714 |
$pgList = $pgCtrler->__getAllPaymentGateway();
|
|
|
715 |
$this->set('pgList', $pgList);
|
|
|
716 |
$this->set('defaultPgId', $pgCtrler->__getDefaultPaymentGateway());
|
|
|
717 |
$this->render('user/renewmyprofile', 'ajax');
|
|
|
718 |
} else {
|
|
|
719 |
redirectUrlByScript(SP_WEBPATH . "/admin-panel.php?sec=myprofile");
|
|
|
720 |
}
|
|
|
721 |
}
|
|
|
722 |
|
|
|
723 |
# function to update membership subscription
|
|
|
724 |
function updateSubscription($userInfo = ''){
|
|
|
725 |
$userId = isLoggedIn();
|
|
|
726 |
$seopluginCtrler = new SeoPluginsController();
|
|
|
727 |
|
|
|
728 |
// if logged in and plugin is active
|
|
|
729 |
if(!empty($userId) && $seopluginCtrler->isPluginActive("Subscription") && !isAdmin()){
|
|
|
730 |
$utypeCtrler = New UserTypeController();
|
|
|
731 |
$_POST = sanitizeData($_POST);
|
|
|
732 |
$errMsg['utype_id'] = formatErrorMsg($this->validate->checkNumber($userInfo['utype_id']));
|
|
|
733 |
$errMsg['pg_id'] = formatErrorMsg($this->validate->checkNumber($userInfo['pg_id']));
|
|
|
734 |
|
|
|
735 |
// if admin user type selected, show error
|
|
|
736 |
$adminTypeId = $utypeCtrler->getAdminUserTypeId();
|
|
|
737 |
if ($adminTypeId == $userInfo['utype_id']) {
|
|
|
738 |
$this->validate->flagErr = true;
|
|
|
739 |
$errMsg['utype_id'] = formatErrorMsg("You can not register as admin.");
|
|
|
740 |
}
|
|
|
741 |
|
|
|
742 |
// get renew usertype list
|
|
|
743 |
$userTypeList = $utypeCtrler->getRenewUserTypeList($userInfo['utype_id']);
|
|
|
744 |
if (!in_array($userInfo['utype_id'], array_keys($userTypeList))) {
|
|
|
745 |
$this->validate->flagErr = true;
|
|
|
746 |
$errMsg['utype_id'] = formatErrorMsg("You are not allowed to upgrade to this plan.");
|
|
|
747 |
}
|
|
|
748 |
|
|
|
749 |
// if all form inputs are valid
|
|
|
750 |
if (!$this->validate->flagErr) {
|
|
|
751 |
$utypeId = intval($userInfo['utype_id']);
|
|
|
752 |
$userId = isLoggedIn();
|
|
|
753 |
$utypeInfo = $utypeCtrler->__getUserTypeInfo($utypeId);
|
|
|
754 |
|
|
|
755 |
// if it is paid subscription, proceed with payment
|
|
|
756 |
if ($utypeInfo['price'] > 0) {
|
|
|
757 |
$paymentPluginId = intval($userInfo['pg_id']);
|
|
|
758 |
@Session::setSession('payment_plugin_id', $paymentPluginId);
|
|
|
759 |
$quantity = intval($userInfo['quantity']);
|
|
|
760 |
$pluginCtrler = $seopluginCtrler->createPluginObject("Subscription");
|
|
|
761 |
$paymentForm = $pluginCtrler->pgCtrler->getPaymentForm($paymentPluginId, $userId, $utypeInfo, $quantity, "renew");
|
|
|
762 |
$this->set('paymentForm', $paymentForm);
|
|
|
763 |
} else {
|
|
|
764 |
$this->updateUserInfo($userId, 'utype_id', $userInfo['utype_id']);
|
|
|
765 |
$expiryDate = $this->calculateUserExpiryDate($userInfo['quantity']);
|
|
|
766 |
$this->updateUserInfo($userId, 'expiry_date', $expiryDate);
|
|
|
767 |
redirectUrlByScript(SP_WEBPATH . "/admin-panel.php?sec=myprofile");
|
|
|
768 |
exit;
|
|
|
769 |
}
|
|
|
770 |
|
|
|
771 |
$this->render('user/renewmyprofile', 'ajax');
|
|
|
772 |
|
|
|
773 |
} else {
|
|
|
774 |
$this->set('errMsg', $errMsg);
|
|
|
775 |
$this->renewMyProfile($_POST);
|
|
|
776 |
}
|
|
|
777 |
|
|
|
778 |
} else {
|
|
|
779 |
redirectUrlByScript(SP_WEBPATH . "/admin-panel.php?sec=myprofile");
|
|
|
780 |
}
|
|
|
781 |
}
|
|
|
782 |
|
|
|
783 |
function editMyProfile($userInfo=''){
|
|
|
784 |
$userId = isLoggedIn();
|
|
|
785 |
if(!empty($userId)){
|
|
|
786 |
if(empty($userInfo)){
|
|
|
787 |
$userInfo = $this->__getUserInfo($userId);
|
|
|
788 |
|
|
|
789 |
$userInfo['userName'] = $userInfo['username'];
|
|
|
790 |
$userInfo['firstName'] = $userInfo['first_name'];
|
|
|
791 |
$userInfo['lastName'] = $userInfo['last_name'];
|
|
|
792 |
$userInfo['oldName'] = $userInfo['username'];
|
|
|
793 |
$userInfo['oldEmail'] = $userInfo['email'];
|
|
|
794 |
}
|
|
|
795 |
|
|
|
796 |
$userInfo['password'] = '';
|
|
|
797 |
$this->set('post', $userInfo);
|
|
|
798 |
$this->render('user/editmyprofile', 'ajax');
|
|
|
799 |
exit;
|
|
|
800 |
}
|
|
|
801 |
}
|
|
|
802 |
|
|
|
803 |
function updateMyProfile($userInfo){
|
|
|
804 |
$userInfo = sanitizeData($userInfo);
|
|
|
805 |
$userId = isLoggedIn();
|
|
|
806 |
$this->set('post', $userInfo);
|
|
|
807 |
$errMsg['userName'] = formatErrorMsg($this->validate->checkUname($userInfo['userName']));
|
|
|
808 |
if(!empty($userInfo['password'])){
|
|
|
809 |
$errMsg['password'] = formatErrorMsg($this->validate->checkPasswords($userInfo['password'], $userInfo['confirmPassword']));
|
|
|
810 |
$passStr = "password = '".md5($userInfo['password'])."',";
|
|
|
811 |
}
|
|
|
812 |
$errMsg['firstName'] = formatErrorMsg($this->validate->checkBlank($userInfo['firstName']));
|
|
|
813 |
$errMsg['lastName'] = formatErrorMsg($this->validate->checkBlank($userInfo['lastName']));
|
|
|
814 |
$errMsg['email'] = formatErrorMsg($this->validate->checkEmail($userInfo['email']));
|
|
|
815 |
if(!$this->validate->flagErr){
|
|
|
816 |
|
|
|
817 |
if($userInfo['userName'] != $userInfo['oldName']){
|
|
|
818 |
if ($this->__checkUserName($userInfo['userName'])) {
|
|
|
819 |
$errMsg['userName'] = formatErrorMsg($_SESSION['text']['login']['usernameexist']);
|
|
|
820 |
$this->validate->flagErr = true;
|
|
|
821 |
}
|
|
|
822 |
}
|
|
|
823 |
|
|
|
824 |
if($userInfo['email'] != $userInfo['oldEmail']){
|
|
|
825 |
if ($this->__checkEmail($userInfo['email'])) {
|
|
|
826 |
$errMsg['email'] = formatErrorMsg($_SESSION['text']['login']['emailexist']);
|
|
|
827 |
$this->validate->flagErr = true;
|
|
|
828 |
}
|
|
|
829 |
}
|
|
|
830 |
|
|
|
831 |
if (!$this->validate->flagErr) {
|
|
|
832 |
$sql = "update users set
|
|
|
833 |
username = '".addslashes($userInfo['userName'])."',
|
|
|
834 |
first_name = '".addslashes($userInfo['firstName'])."',
|
|
|
835 |
last_name = '".addslashes($userInfo['lastName'])."',
|
|
|
836 |
$passStr
|
|
|
837 |
email = '".addslashes($userInfo['email'])."'
|
|
|
838 |
where id=$userId";
|
|
|
839 |
$this->db->query($sql);
|
|
|
840 |
$this->set('msg', $this->spTextUser['Saved My Profile Details']);
|
|
|
841 |
$this->showMyProfile();
|
|
|
842 |
exit;
|
|
|
843 |
}
|
|
|
844 |
}
|
|
|
845 |
|
|
|
846 |
$this->set('errMsg', $errMsg);
|
|
|
847 |
$this->editMyProfile($userInfo);
|
|
|
848 |
}
|
|
|
849 |
|
|
|
850 |
# forgot password function
|
|
|
851 |
function forgotPasswordForm(){
|
|
|
852 |
$this->render('common/forgot');
|
|
|
853 |
}
|
|
|
854 |
|
|
|
855 |
# reset password of user
|
|
|
856 |
function requestPassword($userEmail) {
|
|
|
857 |
|
|
|
858 |
$errMsg['email'] = formatErrorMsg($this->validate->checkEmail($userEmail));
|
|
|
859 |
$errMsg['code'] = formatErrorMsg($this->validate->checkCaptcha($userInfo['code']));
|
|
|
860 |
$this->set('post', $_POST);
|
|
|
861 |
if(!$this->validate->flagErr){
|
|
|
862 |
$userId = $this->__checkEmail($userEmail);
|
|
|
863 |
if(!empty($userId)){
|
|
|
864 |
$userInfo = $this->__getUserInfo($userId);
|
|
|
865 |
$rand = str_shuffle(rand().$userInfo['username']);
|
|
|
866 |
|
|
|
867 |
// get admin details
|
|
|
868 |
$adminInfo = $this->__getAdminInfo();
|
|
|
869 |
|
|
|
870 |
# send password to user
|
|
|
871 |
$error = 0;
|
|
|
872 |
$this->set('rand', $rand);
|
|
|
873 |
$name = $userInfo['first_name']." ".$userInfo['last_name'];
|
|
|
874 |
$this->set('name', $name);
|
|
|
875 |
$this->set('userName', $userInfo['username']);
|
|
|
876 |
$content = $this->getViewContent('email/passwordreset');
|
|
|
877 |
$subject = "Seo panel password reset";
|
|
|
878 |
|
|
|
879 |
if(!sendMail($adminInfo["email"], $name, $userEmail, $subject, $content)){
|
|
|
880 |
$error = $_SESSION['text']['login']['internal_error_mail_send'];
|
|
|
881 |
} else {
|
|
|
882 |
|
|
|
883 |
// update password in DB
|
|
|
884 |
$sql = "update users set password=md5('$rand') where id={$userInfo['id']}";
|
|
|
885 |
$this->db->query($sql);
|
|
|
886 |
|
|
|
887 |
}
|
|
|
888 |
|
|
|
889 |
$this->set('error', $error);
|
|
|
890 |
$this->render('common/forgotconfirm');
|
|
|
891 |
exit;
|
|
|
892 |
}else{
|
|
|
893 |
$errMsg['email'] = formatErrorMsg($_SESSION['text']['login']['user_email_not_exist']);
|
|
|
894 |
}
|
|
|
895 |
}
|
|
|
896 |
$this->set('errMsg', $errMsg);
|
|
|
897 |
$this->forgotPasswordForm();
|
|
|
898 |
}
|
|
|
899 |
|
|
|
900 |
# function to check whether user expired
|
|
|
901 |
function isUserExpired($userId) {
|
|
|
902 |
$excludeSecList = array("myprofile", "renew-profile", "update-subscription");
|
|
|
903 |
|
|
|
904 |
// if not admin user and not in section pages
|
|
|
905 |
if (!isAdmin() && !in_array($_REQUEST['sec'], $excludeSecList)) {
|
|
|
906 |
$userInfo = $this->__getUserInfo($userId);
|
|
|
907 |
$userInfo['expiry_date'] = formatDate($userInfo['expiry_date']);
|
|
|
908 |
|
|
|
909 |
// if expiry date set for user
|
|
|
910 |
if (!empty($userInfo['expiry_date'])) {
|
|
|
911 |
$today = date("Y-m-d");
|
|
|
912 |
$todayTime = strtotime($today);
|
|
|
913 |
$expireTime = strtotime($userInfo['expiry_date']);
|
|
|
914 |
|
|
|
915 |
// current date greater than expiry date
|
|
|
916 |
if ($todayTime > $expireTime) {
|
|
|
917 |
return false;
|
|
|
918 |
}
|
|
|
919 |
}
|
|
|
920 |
}
|
|
|
921 |
|
|
|
922 |
return true;
|
|
|
923 |
|
|
|
924 |
}
|
|
|
925 |
|
|
|
926 |
# function to get admin user id
|
|
|
927 |
function getAdminUserId() {
|
|
|
928 |
$userTypeCtrlr = new UserTypeController();
|
|
|
929 |
$adminUserTypeId = $userTypeCtrlr->getAdminUserTypeId();
|
|
|
930 |
$sql = "select * from users where utype_id=" . $adminUserTypeId;
|
|
|
931 |
$userInfo = $this->db->select($sql, true);
|
|
|
932 |
return $userInfo['id'];
|
|
|
933 |
}
|
|
|
934 |
|
|
|
935 |
# function to check passed user id is admin user id
|
|
|
936 |
function isAdminUserId($userId) {
|
|
|
937 |
$adminUserId = $this->getAdminUserId();
|
|
|
938 |
|
|
|
939 |
// if admin user id return true
|
|
|
940 |
if ($userId == $adminUserId) {
|
|
|
941 |
return true;
|
|
|
942 |
} else {
|
|
|
943 |
return false;
|
|
|
944 |
}
|
|
|
945 |
|
|
|
946 |
}
|
|
|
947 |
|
|
|
948 |
# function to update user info
|
|
|
949 |
function updateUserInfo($userId, $col, $value) {
|
|
|
950 |
$sql = "update users set $col='".addslashes($value)."' where id=" . intval($userId);
|
|
|
951 |
$this->db->query($sql);
|
|
|
952 |
}
|
|
|
953 |
|
|
|
954 |
# function to calculate user expiry date
|
|
|
955 |
function calculateUserExpiryDate($quantity) {
|
|
|
956 |
$month = date('m') + $quantity;
|
|
|
957 |
$expiryTimeStamp = mktime(23, 59, 59, $month, date('d'), date('Y'));
|
|
|
958 |
$expiryDate = date('Y-m-d', $expiryTimeStamp);
|
|
|
959 |
return $expiryDate;
|
|
|
960 |
}
|
|
|
961 |
|
|
|
962 |
function manageWebsiteAccessManager($info = "") {
|
|
|
963 |
$userList = $this->__getAllUsers(1, false);
|
|
|
964 |
$userId = isset($info['wam_user']) ? intval($info['wam_user']) : $userList[0]['id'];
|
|
|
965 |
|
|
|
966 |
if (isset($info['action'])) {
|
|
|
967 |
$sql = "delete from user_website_access where user_id=" . $info['wam_user'];
|
|
|
968 |
$this->db->query($sql);
|
|
|
969 |
|
|
|
970 |
foreach($info['check_ws'] as $key => $val) {
|
|
|
971 |
$sql = "insert into user_website_access(user_id,website_id) values(". $userId . ", " . intval($val) . ")";
|
|
|
972 |
$this->db->query($sql);
|
|
|
973 |
}
|
|
|
974 |
$this->set("msg", formatSuccessMsg("Updated user website access!"));
|
|
|
975 |
}
|
|
|
976 |
|
|
|
977 |
$loggedinUserId = isLoggedIn();
|
|
|
978 |
$sql = "select w.*,uwa.id as uwa_id,uwa.access from websites w left join user_website_access uwa on w.id=uwa.website_id and uwa.user_id=$userId and w.user_id=$loggedinUserId";
|
|
|
979 |
$userWebsiteList = $this->db->select($sql);
|
|
|
980 |
$this->set("userWebsiteList", $userWebsiteList);
|
|
|
981 |
$this->set("userId", $userId);
|
|
|
982 |
$this->set("userList", $userList);
|
|
|
983 |
$this->render('user/websiteAccessManager');
|
|
|
984 |
}
|
|
|
985 |
|
|
|
986 |
function getUserWebsiteAccessList($userId) {
|
|
|
987 |
$accessList = array();
|
|
|
988 |
$cond = "user_id=".intval($userId);
|
|
|
989 |
$list = $this->dbHelper->getAllRows("user_website_access", $cond);
|
|
|
990 |
foreach ($list as $listInfo) {
|
|
|
991 |
$accessList[$listInfo['website_id']] = $listInfo;
|
|
|
992 |
}
|
|
|
993 |
|
|
|
994 |
return $accessList;
|
|
|
995 |
}
|
|
|
996 |
|
|
|
997 |
function getUserWebsiteAccessCount($userId) {
|
|
|
998 |
$cond = "user_id=".intval($userId);
|
|
|
999 |
$info = $this->dbHelper->getRow("user_website_access", $cond, "count(*) count");
|
|
|
1000 |
return $info['count'];
|
|
|
1001 |
}
|
|
|
1002 |
|
|
|
1003 |
}
|
|
|
1004 |
?>
|