| 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 |
/**
|
|
|
24 |
* Class defines all functions for managing user API
|
|
|
25 |
*
|
|
|
26 |
* @author Seo panel
|
|
|
27 |
*
|
|
|
28 |
*/
|
|
|
29 |
class UserAPI extends Seopanel{
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* the main controller to get details for api
|
|
|
33 |
* @var Object
|
|
|
34 |
*/
|
|
|
35 |
var $ctrler;
|
|
|
36 |
|
|
|
37 |
function __construct() {
|
|
|
38 |
include_once(SP_CTRLPATH . "/user.ctrl.php");
|
|
|
39 |
$this->ctrler = new UserController();
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* function to get user information
|
|
|
44 |
* @param Array $info The input details to process the api
|
|
|
45 |
* $info['id'] The id of the user - Mandatory
|
|
|
46 |
* @return Array $returnInfo Contains informations about user
|
|
|
47 |
*/
|
|
|
48 |
function getUserInfo($info) {
|
|
|
49 |
$userId = intval($info['id']);
|
|
|
50 |
$returnInfo = array();
|
|
|
51 |
|
|
|
52 |
// validate the user ifd and user info
|
|
|
53 |
if (!empty($userId)) {
|
|
|
54 |
if ($userInfo = $this->ctrler->__getUserInfo($userId)) {
|
|
|
55 |
$userInfo['password'] = '';
|
|
|
56 |
$returnInfo['response'] = 'success';
|
|
|
57 |
$returnInfo['result'] = $userInfo;
|
|
|
58 |
return $returnInfo;
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
$returnInfo['response'] = 'Error';
|
|
|
63 |
$returnInfo['error_msg'] = "The invalid user id provided";
|
|
|
64 |
return $returnInfo;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* function to create user
|
|
|
69 |
* @param Array $info The input details to process the api
|
|
|
70 |
* $info['username'] The username of the user - Mandatory
|
|
|
71 |
* $info['password'] The password of the user - Mandatory
|
|
|
72 |
* $info['first_name'] The first name f the user - Mandatory
|
|
|
73 |
* $info['last_name'] The last name of user - Optional
|
|
|
74 |
* $info['email'] The user email - Mandatory
|
|
|
75 |
* $info['type_id'] The user type id of user - default[2] - Optional
|
|
|
76 |
* $info['status'] The status of the user - default[1] - Optional
|
|
|
77 |
* @return Array $returnInfo Contains details about the operation succes or not
|
|
|
78 |
*/
|
|
|
79 |
function createUser($info) {
|
|
|
80 |
$userInfo = $info;
|
|
|
81 |
$userInfo['userName'] = $info['username'];
|
|
|
82 |
$userInfo['firstName'] = $info['first_name'];
|
|
|
83 |
$userInfo['lastName'] = $info['last_name'];
|
|
|
84 |
$userInfo['confirmPassword'] = $userInfo['password'];
|
|
|
85 |
$return = $this->ctrler->createUser($userInfo, false);
|
|
|
86 |
|
|
|
87 |
// if user creation is success
|
|
|
88 |
if ($return[0] == 'success') {
|
|
|
89 |
$returnInfo['response'] = 'success';
|
|
|
90 |
$returnInfo['result'] = $return[1];
|
|
|
91 |
$returnInfo['user_id'] = $this->ctrler->db->getMaxId('users');
|
|
|
92 |
} else {
|
|
|
93 |
$returnInfo['response'] = 'Error';
|
|
|
94 |
$returnInfo['error_msg'] = $return[1];
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
return $returnInfo;
|
|
|
98 |
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
/**
|
|
|
102 |
* function to update user
|
|
|
103 |
* @param Array $info The input details to process the api
|
|
|
104 |
* $info['id'] The id of the user - Mandatory
|
|
|
105 |
* $info['username'] The username of the user - Optional
|
|
|
106 |
* $info['password'] The password of the user - Optional
|
|
|
107 |
* $info['first_name'] The first name f the user - Optional
|
|
|
108 |
* $info['last_name'] The last name of user - Optional
|
|
|
109 |
* $info['email'] The user email - Optional
|
|
|
110 |
* $info['type_id'] The user type id of user - Optional
|
|
|
111 |
* $info['status'] The status of the user - Optional
|
|
|
112 |
* @return Array $returnInfo Contains details about the operation succes or not
|
|
|
113 |
*/
|
|
|
114 |
function updateUser($info) {
|
|
|
115 |
|
|
|
116 |
$userId = intval($info['id']);
|
|
|
117 |
|
|
|
118 |
// if user exists
|
|
|
119 |
if ($userInfo = $this->ctrler->__getUserInfo($userId)) {
|
|
|
120 |
|
|
|
121 |
$userInfo['oldName'] = $userInfo['username'];
|
|
|
122 |
$userInfo['oldEmail'] = $userInfo['email'];
|
|
|
123 |
|
|
|
124 |
// loop through inputs
|
|
|
125 |
foreach ($info as $key => $val) {
|
|
|
126 |
$userInfo[$key] = $val;
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
// updte user info
|
|
|
130 |
$userInfo['userName'] = $userInfo['username'];
|
|
|
131 |
$userInfo['firstName'] = $userInfo['first_name'];
|
|
|
132 |
$userInfo['lastName'] = $userInfo['last_name'];
|
|
|
133 |
$userInfo['confirmPassword'] = $userInfo['password'];
|
|
|
134 |
$return = $this->ctrler->updateUser($userInfo, false);
|
|
|
135 |
|
|
|
136 |
// if user creation is success
|
|
|
137 |
if ($return[0] == 'success') {
|
|
|
138 |
$returnInfo['response'] = 'success';
|
|
|
139 |
$returnInfo['result'] = $return[1];
|
|
|
140 |
} else {
|
|
|
141 |
$returnInfo['response'] = 'Error';
|
|
|
142 |
$returnInfo['error_msg'] = $return[1];
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
} else {
|
|
|
146 |
|
|
|
147 |
$returnInfo['response'] = 'Error';
|
|
|
148 |
$returnInfo['error_msg'] = "The invalid user id provided";
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
return $returnInfo;
|
|
|
152 |
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
/**
|
|
|
156 |
* function to delete user
|
|
|
157 |
* @param Array $info The input details to process the api
|
|
|
158 |
* $info['id'] The id of the user - Mandatory
|
|
|
159 |
* @return Array $returnInfo Contains details about the operation success or not
|
|
|
160 |
*/
|
|
|
161 |
function deleteUser($info) {
|
|
|
162 |
|
|
|
163 |
$userId = intval($info['id']);
|
|
|
164 |
|
|
|
165 |
// if user exists
|
|
|
166 |
if ( ($userId != 1) && $userInfo = $this->ctrler->__getUserInfo($userId)) {
|
|
|
167 |
|
|
|
168 |
// update user call as api call
|
|
|
169 |
$this->ctrler->__deleteUser($userId);
|
|
|
170 |
$returnInfo['response'] = 'success';
|
|
|
171 |
$returnInfo['result'] = "Successfully deleted user";
|
|
|
172 |
|
|
|
173 |
} else {
|
|
|
174 |
|
|
|
175 |
$returnInfo['response'] = 'Error';
|
|
|
176 |
$returnInfo['error_msg'] = "The invalid user id provided";
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
return $returnInfo;
|
|
|
180 |
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
/**
|
|
|
184 |
* function added by Rex, 2020Media.com
|
|
|
185 |
* function to get user id from username
|
|
|
186 |
* @param Array $info The input details to process the api
|
|
|
187 |
* $info['username'] The username of the user - Mandatory
|
|
|
188 |
* @return Array $returnInfo Contains id of user
|
|
|
189 |
*/
|
|
|
190 |
function getUserName($info) {
|
|
|
191 |
|
|
|
192 |
$username = $info['username'];
|
|
|
193 |
$returnInfo = array();
|
|
|
194 |
|
|
|
195 |
// validate the user ifd and user info
|
|
|
196 |
if (!empty($username)) {
|
|
|
197 |
if ($userInfo = $this->ctrler->__checkUserName($username)) {
|
|
|
198 |
$returnInfo['response'] = 'success';
|
|
|
199 |
$returnInfo['result'] = $userInfo;
|
|
|
200 |
return $returnInfo;
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
$returnInfo['response'] = 'Error';
|
|
|
205 |
$returnInfo['error_msg'] = "Invalid username provided";
|
|
|
206 |
return $returnInfo;
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
}
|
|
|
210 |
?>
|