|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Agent\helpdesk; |
|
4
|
|
|
|
|
5
|
|
|
// controllers |
|
6
|
|
|
use App\Http\Controllers\Common\PhpMailController; |
|
7
|
|
|
use App\Http\Controllers\Controller; |
|
8
|
|
|
// requests |
|
9
|
|
|
/* Include Sys_user Model */ |
|
10
|
|
|
use App\Http\Requests\helpdesk\ChangepasswordRequest; |
|
11
|
|
|
/* For validation include Sys_userRequest in create */ |
|
12
|
|
|
use App\Http\Requests\helpdesk\OtpVerifyRequest; |
|
13
|
|
|
/* For validation include Sys_userUpdate in update */ |
|
14
|
|
|
use App\Http\Requests\helpdesk\ProfilePassword; |
|
15
|
|
|
/* include guest_note model */ |
|
16
|
|
|
use App\Http\Requests\helpdesk\ProfileRequest; |
|
17
|
|
|
use App\Http\Requests\helpdesk\Sys_userRequest; |
|
18
|
|
|
// change password request |
|
19
|
|
|
use App\Http\Requests\helpdesk\Sys_userUpdate; |
|
20
|
|
|
// models |
|
21
|
|
|
use App\Model\helpdesk\Agent\Assign_team_agent; |
|
22
|
|
|
use App\Model\helpdesk\Agent_panel\Organization; |
|
23
|
|
|
use App\Model\helpdesk\Agent_panel\User_org; |
|
24
|
|
|
use App\Model\helpdesk\Notification\Notification; |
|
25
|
|
|
use App\Model\helpdesk\Notification\UserNotification; |
|
26
|
|
|
use App\Model\helpdesk\Settings\CommonSettings; |
|
27
|
|
|
use App\Model\helpdesk\Settings\Email; |
|
28
|
|
|
use App\Model\helpdesk\Ticket\Ticket_Thread; |
|
29
|
|
|
use App\Model\helpdesk\Ticket\Tickets; |
|
30
|
|
|
use App\Model\helpdesk\Utility\CountryCode; |
|
31
|
|
|
use App\Model\helpdesk\Utility\Otp; |
|
32
|
|
|
use App\User; |
|
33
|
|
|
// classes |
|
34
|
|
|
use Auth; |
|
35
|
|
|
use Datatables; |
|
36
|
|
|
use DateTime; |
|
37
|
|
|
use DB; |
|
38
|
|
|
use Exception; |
|
39
|
|
|
use GeoIP; |
|
40
|
|
|
use Hash; |
|
41
|
|
|
use Illuminate\Http\Request; |
|
42
|
|
|
use Input; |
|
43
|
|
|
use Lang; |
|
44
|
|
|
use Redirect; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* UserController |
|
48
|
|
|
* This controller is used to CRUD an User details, and proile management of an agent. |
|
49
|
|
|
* |
|
50
|
|
|
* @author Ladybird <[email protected]> |
|
51
|
|
|
*/ |
|
52
|
|
|
class UserController extends Controller |
|
53
|
|
|
{ |
|
54
|
|
|
/** |
|
55
|
|
|
* Create a new controller instance. |
|
56
|
|
|
* constructor to check |
|
57
|
|
|
* 1. authentication |
|
58
|
|
|
* 2. user roles |
|
59
|
|
|
* 3. roles must be agent. |
|
60
|
|
|
* |
|
61
|
|
|
* @return void |
|
|
|
|
|
|
62
|
|
|
*/ |
|
63
|
|
|
public function __construct(PhpMailController $PhpMailController) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->PhpMailController = $PhpMailController; |
|
|
|
|
|
|
66
|
|
|
// checking authentication |
|
67
|
|
|
$this->middleware('auth'); |
|
68
|
|
|
// checking if role is agent |
|
69
|
|
|
$this->middleware('role.agent'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Display all list of the users. |
|
74
|
|
|
* |
|
75
|
|
|
* @param type User $user |
|
76
|
|
|
* |
|
77
|
|
|
* @return type view |
|
78
|
|
|
*/ |
|
79
|
|
View Code Duplication |
public function index() |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
try { |
|
82
|
|
|
/* get all values in Sys_user */ |
|
83
|
|
|
|
|
84
|
|
|
$table = \ Datatable::table() |
|
85
|
|
|
->addColumn(Lang::get('lang.name'), |
|
86
|
|
|
Lang::get('lang.email'), |
|
87
|
|
|
Lang::get('lang.phone'), |
|
88
|
|
|
Lang::get('lang.status'), |
|
89
|
|
|
Lang::get('lang.last_login'), |
|
90
|
|
|
Lang::get('lang.role'), |
|
91
|
|
|
Lang::get('lang.action')) // these are the column headings to be shown |
|
92
|
|
|
->noScript(); |
|
93
|
|
|
|
|
94
|
|
|
return view('themes.default1.agent.helpdesk.user.index', compact('table')); |
|
95
|
|
|
} catch (Exception $e) { |
|
96
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function deletedUser() |
|
101
|
|
|
{ |
|
102
|
|
|
try { |
|
103
|
|
|
// dd('here'); |
|
|
|
|
|
|
104
|
|
|
/* get all values in Sys_user */ |
|
105
|
|
|
return view('themes.default1.agent.helpdesk.user.deleteduser'); |
|
106
|
|
|
} catch (Exception $e) { |
|
107
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* This function is used to display the list of users using chumper datatables. |
|
113
|
|
|
* |
|
114
|
|
|
* @return datatable |
|
115
|
|
|
*/ |
|
116
|
|
|
public function user_list(Request $request) |
|
117
|
|
|
{ |
|
118
|
|
|
$type = $request->input('profiletype'); |
|
119
|
|
|
$search = $request->input('searchTerm'); |
|
120
|
|
|
|
|
121
|
|
|
if ($type === 'agents') { |
|
122
|
|
|
$users = User::where('role', '=', 'agent')->where('is_delete', '=', 0); |
|
123
|
|
|
} elseif ($type === 'users') { |
|
124
|
|
|
$users = User::where('role', '=', 'user')->where('is_delete', '=', 0); |
|
125
|
|
|
} elseif ($type === 'active-users') { |
|
126
|
|
|
$users = User::where('role', '!=', 'admin')->where('active', '=', 1); |
|
127
|
|
|
} elseif ($type === 'inactive') { |
|
128
|
|
|
$users = User::where('role', '!=', 'admin')->where('active', '=', 0); |
|
129
|
|
|
} elseif ($type === 'deleted') { |
|
130
|
|
|
$users = User::where('role', '!=', 'admin')->where('is_delete', '=', 1); |
|
131
|
|
|
} elseif ($type === 'banned') { |
|
132
|
|
|
$users = User::where('role', '!=', 'admin')->where('ban', '=', 1); |
|
133
|
|
|
} else { |
|
134
|
|
|
$users = User::where('role', '!=', 'admin')->where('is_delete', '=', 0); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
$users = $users->select('user_name', 'email', 'mobile', 'active', 'updated_at', 'role', 'id', 'last_name', 'country_code', 'phone_number'); |
|
138
|
|
|
|
|
139
|
|
|
if ($search !== '') { |
|
140
|
|
|
$users = $users->where(function ($query) use ($search) { |
|
141
|
|
|
$query->where('user_name', 'LIKE', '%'.$search.'%'); |
|
142
|
|
|
$query->orWhere('email', 'LIKE', '%'.$search.'%'); |
|
143
|
|
|
$query->orWhere('first_name', 'LIKE', '%'.$search.'%'); |
|
144
|
|
|
$query->orWhere('last_name', 'LIKE', '%'.$search.'%'); |
|
145
|
|
|
$query->orWhere('mobile', 'LIKE', '%'.$search.'%'); |
|
146
|
|
|
$query->orWhere('updated_at', 'LIKE', '%'.$search.'%'); |
|
147
|
|
|
$query->orWhere('country_code', 'LIKE', '%'.$search.'%'); |
|
148
|
|
|
}); |
|
149
|
|
|
} |
|
150
|
|
|
// displaying list of users with chumper datatables |
|
151
|
|
|
// return \Datatable::collection(User::where('role', "!=", "admin")->get()) |
|
|
|
|
|
|
152
|
|
|
return \Datatables::of($users) |
|
153
|
|
|
/* column username */ |
|
154
|
|
|
->removeColumn('id', 'last_name', 'country_code', 'phone_number') |
|
155
|
|
|
->addColumn('user_name', function ($model) { |
|
156
|
|
|
if ($model->first_name) { |
|
157
|
|
|
$string = strip_tags($model->first_name.' '.$model->last_name); |
|
158
|
|
|
} else { |
|
159
|
|
|
$string = strip_tags($model->user_name); |
|
160
|
|
|
} |
|
161
|
|
|
if (strlen($string) > 30) { |
|
162
|
|
|
// truncate string |
|
163
|
|
|
$stringCut = mb_substr($string, 0, 30, 'UTF-8').'...'; |
|
164
|
|
|
} else { |
|
165
|
|
|
$stringCut = $string; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
return "<a href='".route('user.show', $model->id)."' title='".$string."''>".$stringCut.'</a>'; |
|
169
|
|
|
}) |
|
170
|
|
|
/* column email */ |
|
171
|
|
|
->addColumn('email', function ($model) { |
|
172
|
|
|
$email = "<a href='".route('user.show', $model->id)."'>".$model->email.'</a>'; |
|
173
|
|
|
|
|
174
|
|
|
return $email; |
|
175
|
|
|
}) |
|
176
|
|
|
/* column phone */ |
|
177
|
|
View Code Duplication |
->addColumn('mobile', function ($model) { |
|
|
|
|
|
|
178
|
|
|
$phone = ''; |
|
179
|
|
|
if ($model->phone_number) { |
|
180
|
|
|
$phone = $model->ext.' '.$model->phone_number; |
|
181
|
|
|
} |
|
182
|
|
|
$mobile = ''; |
|
183
|
|
|
if ($model->mobile) { |
|
184
|
|
|
$mobile = $model->mobile; |
|
185
|
|
|
} |
|
186
|
|
|
$phone = $phone.' '.$mobile; |
|
187
|
|
|
|
|
188
|
|
|
return $phone; |
|
189
|
|
|
}) |
|
190
|
|
|
/* column account status */ |
|
191
|
|
View Code Duplication |
->addColumn('active', function ($model) { |
|
|
|
|
|
|
192
|
|
|
$status = $model->active; |
|
193
|
|
|
if ($status == 1) { |
|
194
|
|
|
$stat = '<button class="btn btn-success btn-xs">Active</button>'; |
|
195
|
|
|
} else { |
|
196
|
|
|
$stat = '<button class="btn btn-danger btn-xs">Inactive</button>'; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
return $stat; |
|
200
|
|
|
}) |
|
201
|
|
|
/* column last login date */ |
|
202
|
|
|
->addColumn('updated_at', function ($model) { |
|
203
|
|
|
$t = $model->updated_at; |
|
204
|
|
|
|
|
205
|
|
|
return TicketController::usertimezone($t); |
|
206
|
|
|
}) |
|
207
|
|
|
/* column Role */ |
|
208
|
|
|
->addColumn('role', function ($model) { |
|
209
|
|
|
$role = $model->role; |
|
210
|
|
|
|
|
211
|
|
|
return $role; |
|
212
|
|
|
}) |
|
213
|
|
|
/* column actions */ |
|
214
|
|
|
->addColumn('Actions', function ($model) { |
|
215
|
|
|
if ($model->is_delete == 0) { |
|
216
|
|
|
return '<a href="'.route('user.edit', $model->id).'" class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a> <a href="'.route('user.show', $model->id).'" class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>'; |
|
217
|
|
|
} else { |
|
218
|
|
View Code Duplication |
if (Auth::user()->role == 'admin') { |
|
|
|
|
|
|
219
|
|
|
// @if(Auth::user()->role == 'admin') |
|
|
|
|
|
|
220
|
|
|
|
|
221
|
|
|
return '<a href="'.route('user.show', $model->id).'" class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>'; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
View Code Duplication |
if (Auth::user()->role == 'agent') { |
|
|
|
|
|
|
225
|
|
|
// @if(Auth::user()->role == 'admin') |
|
|
|
|
|
|
226
|
|
|
if ($model->role == 'user') { |
|
227
|
|
|
return '<a href="'.route('user.show', $model->id).'" class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>'; |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
}) |
|
232
|
|
|
->make(); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
public function restoreUser($id) |
|
236
|
|
|
{ |
|
237
|
|
|
// dd($id); |
|
|
|
|
|
|
238
|
|
|
// $delete_all = Input::get('delete_all'); |
|
|
|
|
|
|
239
|
|
|
$users = User::where('id', '=', $id)->first(); |
|
240
|
|
|
$users->is_delete = 0; |
|
241
|
|
|
$users->active = 1; |
|
242
|
|
|
$users->ban = 0; |
|
243
|
|
|
$users->save(); |
|
244
|
|
|
|
|
245
|
|
|
return redirect('user')->with('success', Lang::get('lang.user_restore_successfully')); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Show the form for creating a new users. |
|
250
|
|
|
* |
|
251
|
|
|
* @return type view |
|
252
|
|
|
*/ |
|
253
|
|
|
public function create(CountryCode $code) |
|
254
|
|
|
{ |
|
255
|
|
|
try { |
|
256
|
|
|
$settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); |
|
257
|
|
|
$email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first(); |
|
258
|
|
|
$location = GeoIP::getLocation(); |
|
259
|
|
|
$phonecode = $code->where('iso', '=', $location->iso_code)->first(); |
|
|
|
|
|
|
260
|
|
|
$org = Organization::lists('name', 'id')->toArray(); |
|
261
|
|
|
|
|
262
|
|
|
return view('themes.default1.agent.helpdesk.user.create', compact('org', 'settings', 'email_mandatory'))->with('phonecode', $phonecode->phonecode); |
|
|
|
|
|
|
263
|
|
|
} catch (Exception $e) { |
|
264
|
|
|
return redirect()->back()->with('fails', $e->errorInfo[2]); |
|
|
|
|
|
|
265
|
|
|
} |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* Store a newly created users in storage. |
|
270
|
|
|
* |
|
271
|
|
|
* @param type User $user |
|
272
|
|
|
* @param type Sys_userRequest $request |
|
273
|
|
|
* |
|
274
|
|
|
* @return type redirect |
|
275
|
|
|
*/ |
|
276
|
|
|
public function store(User $user, Sys_userRequest $request) |
|
277
|
|
|
{ |
|
278
|
|
|
/* insert the input request to sys_user table */ |
|
279
|
|
|
/* Check whether function success or not */ |
|
280
|
|
View Code Duplication |
if ($request->input('email') != '') { |
|
|
|
|
|
|
281
|
|
|
$user->email = $request->input('email'); |
|
|
|
|
|
|
282
|
|
|
} else { |
|
283
|
|
|
$user->email = null; |
|
|
|
|
|
|
284
|
|
|
} |
|
285
|
|
|
$user->first_name = $request->input('first_name'); |
|
|
|
|
|
|
286
|
|
|
$user->last_name = $request->input('last_name'); |
|
|
|
|
|
|
287
|
|
|
$user->user_name = $request->input('user_name'); |
|
|
|
|
|
|
288
|
|
View Code Duplication |
if ($request->input('mobile') != '') { |
|
|
|
|
|
|
289
|
|
|
$user->mobile = $request->input('mobile'); |
|
|
|
|
|
|
290
|
|
|
} else { |
|
291
|
|
|
$user->mobile = null; |
|
|
|
|
|
|
292
|
|
|
} |
|
293
|
|
|
$user->ext = $request->input('ext'); |
|
|
|
|
|
|
294
|
|
|
$user->phone_number = $request->input('phone_number'); |
|
|
|
|
|
|
295
|
|
|
$user->country_code = $request->input('country_code'); |
|
|
|
|
|
|
296
|
|
|
$user->active = $request->input('active'); |
|
|
|
|
|
|
297
|
|
|
$user->internal_note = $request->input('internal_note'); |
|
|
|
|
|
|
298
|
|
|
$password = $this->generateRandomString(); |
|
299
|
|
|
$user->password = Hash::make($password); |
|
|
|
|
|
|
300
|
|
|
$user->role = 'user'; |
|
|
|
|
|
|
301
|
|
|
try { |
|
302
|
|
|
if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) { |
|
303
|
|
|
return redirect()->back()->with(['fails' => Lang::get('lang.country-code-required-error'), 'country_code_error' => 1])->withInput(); |
|
304
|
|
|
} else { |
|
305
|
|
|
$code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get(); |
|
306
|
|
|
if (!count($code)) { |
|
307
|
|
|
return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput(); |
|
308
|
|
|
} |
|
309
|
|
|
} |
|
310
|
|
|
// save user credentails |
|
311
|
|
|
if ($user->save() == true) { |
|
|
|
|
|
|
312
|
|
|
if ($request->input('org_id') != '') { |
|
313
|
|
|
$orgid = $request->input('org_id'); |
|
314
|
|
|
$this->storeUserOrgRelation($user->id, $orgid); |
|
|
|
|
|
|
315
|
|
|
} |
|
316
|
|
|
// fetch user credentails to send mail |
|
317
|
|
|
$name = $user->first_name; |
|
|
|
|
|
|
318
|
|
|
$email = $user->email; |
|
|
|
|
|
|
319
|
|
View Code Duplication |
if ($request->input('send_email')) { |
|
|
|
|
|
|
320
|
|
|
try { |
|
321
|
|
|
// send mail on registration |
|
322
|
|
|
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => null, 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]); |
|
323
|
|
|
} catch (Exception $e) { |
|
324
|
|
|
// returns if try fails |
|
325
|
|
|
return redirect('user')->with('warning', Lang::get('lang.user_send_mail_error_on_user_creation')); |
|
326
|
|
|
} |
|
327
|
|
|
} |
|
328
|
|
|
// returns for the success case |
|
329
|
|
|
// returns for the success case |
|
330
|
|
|
$email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first(); |
|
331
|
|
|
if (($request->input('active') == '0' || $request->input('active') == 0) || ($email_mandatory->status == '0') || $email_mandatory->status == 0) { |
|
332
|
|
|
\Event::fire(new \App\Events\LoginEvent($request)); |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
return redirect('user')->with('success', Lang::get('lang.User-Created-Successfully')); |
|
336
|
|
|
} |
|
337
|
|
|
// $user->save(); |
|
|
|
|
|
|
338
|
|
|
/* redirect to Index page with Success Message */ |
|
339
|
|
|
return redirect('user')->with('success', Lang::get('lang.User-Created-Successfully')); |
|
340
|
|
|
} catch (Exception $e) { |
|
341
|
|
|
/* redirect to Index page with Fails Message */ |
|
342
|
|
|
return redirect('user')->with('fails', $e->getMessage()); |
|
343
|
|
|
} |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* Random Password Genetor for users. |
|
348
|
|
|
* |
|
349
|
|
|
* @param type int $id |
|
350
|
|
|
* @param type User $user |
|
351
|
|
|
* |
|
352
|
|
|
* @return type view |
|
353
|
|
|
*/ |
|
354
|
|
|
public function randomPassword() |
|
355
|
|
|
{ |
|
356
|
|
|
try { |
|
357
|
|
|
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*(){}[]'; |
|
358
|
|
|
$pass = []; //remember to declare $pass as an array |
|
359
|
|
|
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache |
|
360
|
|
|
for ($i = 0; $i < 10; $i++) { |
|
361
|
|
|
$n = rand(0, $alphaLength); |
|
362
|
|
|
$pass[] = $alphabet[$n]; |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
return implode($pass); |
|
366
|
|
|
} catch (Exception $e) { |
|
367
|
|
|
/* redirect to Index page with Fails Message */ |
|
368
|
|
|
return redirect('user')->with('fails', $e->getMessage()); |
|
369
|
|
|
} |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
/** |
|
373
|
|
|
* Random Password Genetor for users. |
|
374
|
|
|
* |
|
375
|
|
|
* @param type int $id |
|
376
|
|
|
* @param type User $user |
|
377
|
|
|
* |
|
378
|
|
|
* @return type view |
|
379
|
|
|
*/ |
|
380
|
|
|
public function randomPostPassword($id, ChangepasswordRequest $request) |
|
381
|
|
|
{ |
|
382
|
|
|
try { |
|
383
|
|
|
$changepassword = $request->change_password; |
|
|
|
|
|
|
384
|
|
|
$user = User::whereId($id)->first(); |
|
385
|
|
|
$password = $request->change_password; |
|
386
|
|
|
$user->password = Hash::make($password); |
|
387
|
|
|
$user->save(); |
|
388
|
|
|
$name = $user->first_name; |
|
389
|
|
|
$email = $user->email; |
|
390
|
|
|
|
|
391
|
|
|
$this->PhpMailController->sendmail($from = $this->PhpMailController |
|
392
|
|
|
->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => null, 'scenario' => 'reset_new_password'], $template_variables = ['user' => $name, 'user_password' => $password]); |
|
393
|
|
|
|
|
394
|
|
|
return redirect('user')->with('success', Lang::get('lang.password_change_successfully')); |
|
395
|
|
|
} catch (Exception $e) { |
|
396
|
|
|
return redirect('user')->with('fails', $e->getMessage()); |
|
397
|
|
|
} |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
/** |
|
401
|
|
|
* @param type $id |
|
402
|
|
|
* @param Request $request |
|
403
|
|
|
* |
|
404
|
|
|
* @return type |
|
405
|
|
|
*/ |
|
406
|
|
View Code Duplication |
public function changeRoleAdmin($id, Request $request) |
|
|
|
|
|
|
407
|
|
|
{ |
|
408
|
|
|
try { |
|
409
|
|
|
$user = User::whereId($id)->first(); |
|
410
|
|
|
$user->role = 'admin'; |
|
411
|
|
|
$user->assign_group = $request->group; |
|
412
|
|
|
$user->primary_dpt = $request->primary_department; |
|
413
|
|
|
$user->save(); |
|
414
|
|
|
|
|
415
|
|
|
return redirect('user')->with('success', Lang::get('lang.role_change_successfully')); |
|
416
|
|
|
} catch (Exception $e) { |
|
417
|
|
|
/* redirect to Index page with Fails Message */ |
|
418
|
|
|
return redirect('user')->with('fails', $e->getMessage()); |
|
419
|
|
|
} |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
/** |
|
423
|
|
|
* @param type $id |
|
424
|
|
|
* @param Request $request |
|
425
|
|
|
* |
|
426
|
|
|
* @return type |
|
427
|
|
|
*/ |
|
428
|
|
View Code Duplication |
public function changeRoleAgent($id, Request $request) |
|
|
|
|
|
|
429
|
|
|
{ |
|
430
|
|
|
try { |
|
431
|
|
|
$user = User::whereId($id)->first(); |
|
432
|
|
|
$user->role = 'agent'; |
|
433
|
|
|
$user->assign_group = $request->group; |
|
434
|
|
|
$user->primary_dpt = $request->primary_department; |
|
435
|
|
|
$user->save(); |
|
436
|
|
|
|
|
437
|
|
|
return redirect('user')->with('success', Lang::get('lang.role_change_successfully')); |
|
438
|
|
|
} catch (Exception $e) { |
|
439
|
|
|
/* redirect to Index page with Fails Message */ |
|
440
|
|
|
return redirect('user')->with('fails', $e->getMessage()); |
|
441
|
|
|
} |
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
/** |
|
445
|
|
|
* @param type $id |
|
446
|
|
|
* |
|
447
|
|
|
* @return type |
|
448
|
|
|
*/ |
|
449
|
|
|
public function changeRoleUser($id) |
|
450
|
|
|
{ |
|
451
|
|
|
try { |
|
452
|
|
|
$ticket = Tickets::where('assigned_to', '=', $id)->where('status', '=', '1')->get(); |
|
453
|
|
|
if ($ticket) { |
|
454
|
|
|
$ticket = Tickets::where('assigned_to', '=', $id)->update(['assigned_to' => null]); |
|
|
|
|
|
|
455
|
|
|
} |
|
456
|
|
|
$user = User::whereId($id)->first(); |
|
457
|
|
|
$user->role = 'user'; |
|
458
|
|
|
$user->assign_group = null; |
|
459
|
|
|
$user->primary_dpt = null; |
|
460
|
|
|
$user->remember_token = null; |
|
461
|
|
|
$user->save(); |
|
462
|
|
|
|
|
463
|
|
|
return redirect('user')->with('success', Lang::get('lang.role_change_successfully')); |
|
464
|
|
|
} catch (Exception $e) { |
|
465
|
|
|
/* redirect to Index page with Fails Message */ |
|
466
|
|
|
return redirect('user')->with('fails', $e->getMessage()); |
|
467
|
|
|
} |
|
468
|
|
|
// return 'Agent Role Successfully Change to User'; |
|
469
|
|
|
} |
|
470
|
|
|
|
|
471
|
|
|
/** |
|
472
|
|
|
* @param type $id |
|
473
|
|
|
* |
|
474
|
|
|
* @return type |
|
475
|
|
|
*/ |
|
476
|
|
|
public function deleteAgent($id) |
|
477
|
|
|
{ |
|
478
|
|
|
// try { |
|
479
|
|
|
$delete_all = Input::get('delete_all'); |
|
|
|
|
|
|
480
|
|
|
|
|
481
|
|
|
$delete_all = Input::get('delete_all'); |
|
482
|
|
|
$users = User::where('id', '=', $id)->first(); |
|
483
|
|
|
if ($users->role == 'user') { |
|
484
|
|
|
$users = User::where('id', '=', $id)->first(); |
|
485
|
|
|
$users->is_delete = 1; |
|
486
|
|
|
$users->active = 0; |
|
487
|
|
|
$users->ban = 1; |
|
488
|
|
|
$users->save(); |
|
489
|
|
|
|
|
490
|
|
|
return redirect('user')->with('success', Lang::get('lang.user_delete_successfully')); |
|
491
|
|
|
} |
|
492
|
|
|
// } |
|
493
|
|
|
|
|
494
|
|
|
if ($users->role == 'agent') { |
|
495
|
|
|
if ($delete_all == null) { |
|
496
|
|
|
$UserEmail = Input::get('assign_to'); |
|
497
|
|
|
$assign_to = explode('_', $UserEmail); |
|
498
|
|
|
$ticket = Tickets::where('assigned_to', '=', $id)->get(); |
|
499
|
|
|
if ($assign_to[0] == 'user') { |
|
500
|
|
|
if ($users->id == $assign_to[1]) { |
|
501
|
|
|
return redirect('user')->with('warning', Lang::get('lang.select_another_agent')); |
|
502
|
|
|
} |
|
503
|
|
|
// $user_detail = User::where('id', '=', $assign_to[1])->first(); |
|
|
|
|
|
|
504
|
|
|
// $assignee = $user_detail->first_name.' '.$user_detail->last_name; |
|
|
|
|
|
|
505
|
|
|
// $ticket_logic1 = Tickets::where('assigned_to', '=', $id) |
|
|
|
|
|
|
506
|
|
|
// ->update(['assigned_to' => $assign_to[1]]); |
|
|
|
|
|
|
507
|
|
|
// if ($ticket_logic2 = Tickets::where('user_id', '=', $id)->get()) { |
|
|
|
|
|
|
508
|
|
|
// $ticket_logic2 = Tickets::where('user_id', '=', $id)->update(['user_id' => $assign_to[1]]); |
|
|
|
|
|
|
509
|
|
|
// } |
|
510
|
|
|
// if ($ticket_logic3 = Ticket_Thread::where('user_id', '=', $id)->get()) { |
|
|
|
|
|
|
511
|
|
|
// $ticket_logic3 = Ticket_Thread::where('user_id', '=', $id)->update(['user_id' => $assign_to[1]]); |
|
|
|
|
|
|
512
|
|
|
// } |
|
513
|
|
|
// if ($ticket_logic4 = User_org::where('user_id', '=', $id)->get()) { |
|
|
|
|
|
|
514
|
|
|
// $ticket_logic4 = User_org::where('user_id', '=', $id)->update(['user_id' => $assign_to[1]]); |
|
|
|
|
|
|
515
|
|
|
// } |
|
516
|
|
|
|
|
517
|
|
|
// $thread2 = Ticket_Thread::where('ticket_id', '=', $ticket->id)->first(); |
|
|
|
|
|
|
518
|
|
|
// $thread2->body = 'This Ticket have been Reassigned to' .' '. $assignee; |
|
|
|
|
|
|
519
|
|
|
// $thread2->save(); |
|
|
|
|
|
|
520
|
|
|
// UserNotification::where('notification_id', '=', $ticket->id)->delete(); |
|
|
|
|
|
|
521
|
|
|
// $users = User::where('id', '=', $id)->get(); |
|
|
|
|
|
|
522
|
|
|
// $organization = User_org::where('user_id', '=', $id)->delete(); |
|
|
|
|
|
|
523
|
|
|
// Assign_team_agent::where('agent_id', '=', $id)->update(['agent_id' => $assign_to[1]]); |
|
|
|
|
|
|
524
|
|
|
$tickets = Tickets::where('assigned_to', '=', $id)->get(); |
|
525
|
|
|
|
|
526
|
|
|
foreach ($tickets as $ticket) { |
|
527
|
|
|
// code... |
|
528
|
|
|
|
|
529
|
|
|
$ticket->assigned_to = $assign_to[1]; |
|
530
|
|
|
$user_detail = User::where('id', '=', $assign_to[1])->first(); |
|
531
|
|
|
$assignee = $user_detail->first_name.' '.$user_detail->last_name; |
|
532
|
|
|
$ticket_number = $ticket->ticket_number; |
|
|
|
|
|
|
533
|
|
|
$ticket->save(); |
|
534
|
|
|
|
|
535
|
|
|
$thread = new Ticket_Thread(); |
|
536
|
|
|
$thread->ticket_id = $ticket->id; |
|
|
|
|
|
|
537
|
|
|
$thread->user_id = Auth::user()->id; |
|
|
|
|
|
|
538
|
|
|
$thread->is_internal = 1; |
|
|
|
|
|
|
539
|
|
|
$thread->body = 'This Ticket has been assigned to '.$assignee; |
|
|
|
|
|
|
540
|
|
|
$thread->save(); |
|
541
|
|
|
} |
|
542
|
|
|
$user = User::find($id); |
|
|
|
|
|
|
543
|
|
|
$users->is_delete = 1; |
|
544
|
|
|
$users->active = 0; |
|
545
|
|
|
$users->ban = 1; |
|
546
|
|
|
$users->save(); |
|
547
|
|
|
|
|
548
|
|
|
return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully_and_ticket_assign_to_another_agent')); |
|
549
|
|
|
} |
|
550
|
|
|
|
|
551
|
|
|
// if (User_org::where('user_id', '=', $id)) { |
|
|
|
|
|
|
552
|
|
|
// DB::table('user_assign_organization')->where('user_id', '=', $id)->delete(); |
|
|
|
|
|
|
553
|
|
|
// } |
|
554
|
|
|
$user = User::find($id); |
|
|
|
|
|
|
555
|
|
|
$users->is_delete = 1; |
|
556
|
|
|
$users->active = 0; |
|
557
|
|
|
$users->ban = 1; |
|
558
|
|
|
$users->save(); |
|
559
|
|
|
|
|
560
|
|
|
return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully')); |
|
561
|
|
|
} elseif ($delete_all == 1) { |
|
562
|
|
|
if ($delete_all) { |
|
563
|
|
|
// dd('here'); |
|
|
|
|
|
|
564
|
|
|
$tickets = Tickets::where('assigned_to', '=', $id)->get(); |
|
565
|
|
|
// dd($tickets); |
|
|
|
|
|
|
566
|
|
|
foreach ($tickets as $ticket) { |
|
567
|
|
|
$ticket->assigned_to = null; |
|
568
|
|
|
$ticket_number = $ticket->ticket_number; |
|
|
|
|
|
|
569
|
|
|
$ticket->save(); |
|
570
|
|
|
|
|
571
|
|
|
$thread = new Ticket_Thread(); |
|
572
|
|
|
$thread->ticket_id = $ticket->id; |
|
|
|
|
|
|
573
|
|
|
$thread->user_id = Auth::user()->id; |
|
|
|
|
|
|
574
|
|
|
$thread->is_internal = 1; |
|
|
|
|
|
|
575
|
|
|
$thread->body = 'This Ticket has been unassigned '; |
|
|
|
|
|
|
576
|
|
|
$thread->save(); |
|
577
|
|
|
} |
|
578
|
|
|
// $users = User::where('id', '=', $id)->get(); |
|
|
|
|
|
|
579
|
|
|
$user = User::find($id); |
|
|
|
|
|
|
580
|
|
|
$users->is_delete = 1; |
|
581
|
|
|
$users->active = 0; |
|
582
|
|
|
$users->save(); |
|
583
|
|
|
|
|
584
|
|
|
return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully')); |
|
585
|
|
|
} else { |
|
586
|
|
|
// Assign_team_agent::where('agent_id', '=', $id)->delete(); |
|
|
|
|
|
|
587
|
|
|
// User_org::where('user_id', '=', $id)->delete(); |
|
|
|
|
|
|
588
|
|
|
$user = User::find($id); |
|
|
|
|
|
|
589
|
|
|
$users->is_delete = 1; |
|
590
|
|
|
$users->active = 0; |
|
591
|
|
|
$users->save(); |
|
592
|
|
|
|
|
593
|
|
|
return redirect('user')->with('success', Lang::get('lang.agent_delete_successfully')); |
|
594
|
|
|
} |
|
595
|
|
|
} else { |
|
|
|
|
|
|
596
|
|
|
} |
|
597
|
|
|
} |
|
598
|
|
|
// } catch (Exception $e) { |
|
|
|
|
|
|
599
|
|
|
/* redirect to Index page with Fails Message */ |
|
600
|
|
|
// return redirect('user')->with('fails', $e->getMessage()); |
|
|
|
|
|
|
601
|
|
|
// } |
|
602
|
|
|
} |
|
603
|
|
|
|
|
604
|
|
|
/** |
|
605
|
|
|
* Display the specified users. |
|
606
|
|
|
* |
|
607
|
|
|
* @param type int $id |
|
608
|
|
|
* @param type User $user |
|
609
|
|
|
* |
|
610
|
|
|
* @return type view |
|
611
|
|
|
*/ |
|
612
|
|
|
public function show($id) |
|
613
|
|
|
{ |
|
614
|
|
|
try { |
|
615
|
|
|
$users = User::where('id', '=', $id)->first(); |
|
616
|
|
|
if (count($users) > 0) { |
|
617
|
|
|
return view('themes.default1.agent.helpdesk.user.show', compact('users')); |
|
618
|
|
|
} else { |
|
619
|
|
|
return redirect()->back()->with('fails', Lang::get('lang.user-not-found')); |
|
620
|
|
|
} |
|
621
|
|
|
} catch (Exception $e) { |
|
622
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
|
623
|
|
|
} |
|
624
|
|
|
} |
|
625
|
|
|
|
|
626
|
|
|
/** |
|
627
|
|
|
* Show the form for editing the specified resource. |
|
628
|
|
|
* |
|
629
|
|
|
* @param type int $id |
|
630
|
|
|
* @param type User $user |
|
631
|
|
|
* |
|
632
|
|
|
* @return type Response |
|
633
|
|
|
*/ |
|
634
|
|
|
public function edit($id, CountryCode $code) |
|
635
|
|
|
{ |
|
636
|
|
|
try { |
|
637
|
|
|
|
|
638
|
|
|
// dd('here'); |
|
|
|
|
|
|
639
|
|
|
$settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); |
|
|
|
|
|
|
640
|
|
|
$email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first(); |
|
|
|
|
|
|
641
|
|
|
|
|
642
|
|
|
$user = new User(); |
|
643
|
|
|
/* select the field where id = $id(request Id) */ |
|
644
|
|
|
$users = $user->whereId($id)->first(); |
|
|
|
|
|
|
645
|
|
|
$location = GeoIP::getLocation(); |
|
646
|
|
|
$phonecode = $code->where('iso', '=', $location->iso_code)->first(); |
|
|
|
|
|
|
647
|
|
|
$orgs = Organization::all(); |
|
648
|
|
|
// dd($org); |
|
|
|
|
|
|
649
|
|
|
$organization_id = User_org::where('user_id', '=', $id)->lists('org_id')->first(); |
|
650
|
|
|
|
|
651
|
|
|
// $org_name=Organization::where('id','=',$org_id)->lists('name')->first(); |
|
|
|
|
|
|
652
|
|
|
// dd($org_name); |
|
|
|
|
|
|
653
|
|
|
|
|
654
|
|
|
return view('themes.default1.agent.helpdesk.user.edit', compact('users', 'orgs', '$settings', '$email_mandatory', 'organization_id'))->with('phonecode', $phonecode->phonecode); |
|
|
|
|
|
|
655
|
|
|
} catch (Exception $e) { |
|
656
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
|
657
|
|
|
} |
|
658
|
|
|
} |
|
659
|
|
|
|
|
660
|
|
|
/** |
|
661
|
|
|
* Update the specified user in storage. |
|
662
|
|
|
* |
|
663
|
|
|
* @param type int $id |
|
664
|
|
|
* @param type User $user |
|
665
|
|
|
* @param type Sys_userUpdate $request |
|
666
|
|
|
* |
|
667
|
|
|
* @return type Response |
|
668
|
|
|
*/ |
|
669
|
|
|
public function update($id, Sys_userUpdate $request) |
|
670
|
|
|
{ |
|
671
|
|
|
$user = new User(); |
|
672
|
|
|
/* select the field where id = $id(request Id) */ |
|
673
|
|
|
$users = $user->whereId($id)->first(); |
|
|
|
|
|
|
674
|
|
|
/* Update the value by selected field */ |
|
675
|
|
|
/* Check whether function success or not */ |
|
676
|
|
|
try { |
|
677
|
|
View Code Duplication |
if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) { |
|
|
|
|
|
|
678
|
|
|
return redirect()->back()->with(['fails' => Lang::get('lang.country-code-required-error'), 'country_code_error' => 1])->withInput(); |
|
679
|
|
|
} else { |
|
680
|
|
|
$code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get(); |
|
681
|
|
|
if (!count($code)) { |
|
682
|
|
|
return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput(); |
|
683
|
|
|
} else { |
|
684
|
|
|
$users->country_code = $request->country_code; |
|
|
|
|
|
|
685
|
|
|
} |
|
686
|
|
|
} |
|
687
|
|
|
$users->mobile = ($request->input('mobile') == '') ? null : $request->input('mobile'); |
|
688
|
|
|
$users->fill($request->except('mobile')); |
|
689
|
|
|
$users->save(); |
|
690
|
|
|
if ($request->input('org_id') != '') { |
|
691
|
|
|
$orgid = $request->input('org_id'); |
|
692
|
|
|
|
|
693
|
|
|
$this->storeUserOrgRelation($id, $orgid); |
|
694
|
|
|
} |
|
695
|
|
|
/* redirect to Index page with Success Message */ |
|
696
|
|
|
return redirect('user')->with('success', Lang::get('lang.User-profile-Updated-Successfully')); |
|
697
|
|
|
} catch (Exception $e) { |
|
698
|
|
|
/* redirect to Index page with Fails Message */ |
|
699
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
|
700
|
|
|
} |
|
701
|
|
|
} |
|
702
|
|
|
|
|
703
|
|
|
/** |
|
704
|
|
|
* get agent profile page. |
|
705
|
|
|
* |
|
706
|
|
|
* @return type view |
|
707
|
|
|
*/ |
|
708
|
|
View Code Duplication |
public function getProfile() |
|
|
|
|
|
|
709
|
|
|
{ |
|
710
|
|
|
$user = Auth::user(); |
|
711
|
|
|
try { |
|
712
|
|
|
return view('themes.default1.agent.helpdesk.user.profile', compact('user')); |
|
713
|
|
|
} catch (Exception $e) { |
|
714
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
|
715
|
|
|
} |
|
716
|
|
|
} |
|
717
|
|
|
|
|
718
|
|
|
/** |
|
719
|
|
|
* get profile edit page. |
|
720
|
|
|
* |
|
721
|
|
|
* @return type view |
|
722
|
|
|
*/ |
|
723
|
|
|
public function getProfileedit(CountryCode $code) |
|
724
|
|
|
{ |
|
725
|
|
|
$user = Auth::user(); |
|
726
|
|
|
$location = GeoIP::getLocation(); |
|
727
|
|
|
$phonecode = $code->where('iso', '=', $location->iso_code)->first(); |
|
|
|
|
|
|
728
|
|
|
$settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); |
|
729
|
|
|
$status = $settings->status; |
|
730
|
|
|
try { |
|
731
|
|
|
return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user')) |
|
|
|
|
|
|
732
|
|
|
->with(['phonecode' => $phonecode->phonecode, |
|
733
|
|
|
'verify' => $status, ]); |
|
734
|
|
|
} catch (Exception $e) { |
|
735
|
|
|
return redirect()->back()->with('fails', $e->getMessage()); |
|
736
|
|
|
} |
|
737
|
|
|
} |
|
738
|
|
|
|
|
739
|
|
|
/** |
|
740
|
|
|
* post profile edit. |
|
741
|
|
|
* |
|
742
|
|
|
* @param type int $id |
|
743
|
|
|
* @param type ProfileRequest $request |
|
744
|
|
|
* |
|
745
|
|
|
* @return type Redirect |
|
746
|
|
|
*/ |
|
747
|
|
|
public function postProfileedit(ProfileRequest $request) |
|
748
|
|
|
{ |
|
749
|
|
|
try { |
|
750
|
|
|
// geet authenticated user details |
|
751
|
|
|
$user = Auth::user(); |
|
752
|
|
View Code Duplication |
if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) { |
|
|
|
|
|
|
753
|
|
|
return redirect()->back()->with(['fails' => Lang::get('lang.country-code-required-error'), 'country_code_error' => 1])->withInput(); |
|
754
|
|
|
} else { |
|
755
|
|
|
$code = CountryCode::select('phonecode')->where('phonecode', '=', $request->get('country_code'))->get(); |
|
756
|
|
|
if (!count($code)) { |
|
757
|
|
|
return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput(); |
|
758
|
|
|
} |
|
759
|
|
|
$user->country_code = $request->country_code; |
|
|
|
|
|
|
760
|
|
|
} |
|
761
|
|
|
$user->fill($request->except('profile_pic', 'mobile')); |
|
762
|
|
|
$user->gender = $request->input('gender'); |
|
763
|
|
|
$user->save(); |
|
764
|
|
|
if (Input::file('profile_pic')) { |
|
765
|
|
|
// fetching picture name |
|
766
|
|
|
$name = Input::file('profile_pic')->getClientOriginalName(); |
|
767
|
|
|
// fetching upload destination path |
|
768
|
|
|
$destinationPath = 'uploads/profilepic'; |
|
769
|
|
|
// adding a random value to profile picture filename |
|
770
|
|
|
$fileName = rand(0000, 9999).'.'.$name; |
|
771
|
|
|
// moving the picture to a destination folder |
|
772
|
|
|
Input::file('profile_pic')->move($destinationPath, $fileName); |
|
773
|
|
|
// saving filename to database |
|
774
|
|
|
$user->profile_pic = $fileName; |
|
775
|
|
|
} |
|
776
|
|
|
if ($request->get('mobile')) { |
|
777
|
|
|
$user->mobile = $request->get('mobile'); |
|
778
|
|
|
} else { |
|
779
|
|
|
$user->mobile = null; |
|
780
|
|
|
} |
|
781
|
|
|
if ($user->save()) { |
|
782
|
|
|
return Redirect::route('profile')->with('success', Lang::get('lang.Profile-Updated-sucessfully')); |
|
783
|
|
|
} else { |
|
784
|
|
|
return Redirect::route('profile')->with('fails', Lang::get('lang.Profile-Updated-sucessfully')); |
|
785
|
|
|
} |
|
786
|
|
|
} catch (Exception $e) { |
|
787
|
|
|
return Redirect::route('profile')->with('fails', $e->getMessage()); |
|
788
|
|
|
} |
|
789
|
|
|
} |
|
790
|
|
|
|
|
791
|
|
|
/** |
|
792
|
|
|
* Post profile password. |
|
793
|
|
|
* |
|
794
|
|
|
* @param type int $id |
|
795
|
|
|
* @param type ProfilePassword $request |
|
796
|
|
|
* |
|
797
|
|
|
* @return type Redirect |
|
798
|
|
|
*/ |
|
799
|
|
|
public function postProfilePassword($id, ProfilePassword $request) |
|
|
|
|
|
|
800
|
|
|
{ |
|
801
|
|
|
// get authenticated user |
|
802
|
|
|
$user = Auth::user(); |
|
803
|
|
|
// checking if the old password matches the new password |
|
804
|
|
|
if (Hash::check($request->input('old_password'), $user->getAuthPassword())) { |
|
805
|
|
|
$user->password = Hash::make($request->input('new_password')); |
|
806
|
|
|
try { |
|
807
|
|
|
$user->save(); |
|
808
|
|
|
|
|
809
|
|
|
return redirect('profile-edit')->with('success1', Lang::get('lang.password_updated_sucessfully')); |
|
810
|
|
|
} catch (Exception $e) { |
|
811
|
|
|
return redirect('profile-edit')->with('fails', $e->getMessage()); |
|
812
|
|
|
} |
|
813
|
|
|
} else { |
|
814
|
|
|
return redirect('profile-edit')->with('fails1', Lang::get('lang.password_was_not_updated_incorrect_old_password')); |
|
815
|
|
|
} |
|
816
|
|
|
} |
|
817
|
|
|
|
|
818
|
|
|
/** |
|
819
|
|
|
* Assigning an user to an organization. |
|
820
|
|
|
* |
|
821
|
|
|
* @param type $id |
|
822
|
|
|
* |
|
823
|
|
|
* @return type boolean |
|
824
|
|
|
*/ |
|
825
|
|
|
public function UserAssignOrg($id) |
|
826
|
|
|
{ |
|
827
|
|
|
$org_name = Input::get('org'); |
|
828
|
|
|
|
|
829
|
|
|
if ($org_name) { |
|
830
|
|
|
$org = Organization::where('name', '=', $org_name)->lists('id')->first(); |
|
831
|
|
|
if ($org) { |
|
832
|
|
|
$user_org = new User_org(); |
|
833
|
|
|
$user_org->org_id = $org; |
|
|
|
|
|
|
834
|
|
|
$user_org->user_id = $id; |
|
|
|
|
|
|
835
|
|
|
$user_org->save(); |
|
836
|
|
|
|
|
837
|
|
|
return 1; |
|
838
|
|
|
} else { |
|
839
|
|
|
return 0; |
|
840
|
|
|
} |
|
841
|
|
|
} else { |
|
842
|
|
|
return 2; |
|
843
|
|
|
} |
|
844
|
|
|
} |
|
845
|
|
|
|
|
846
|
|
View Code Duplication |
public function UsereditAssignOrg($id) |
|
|
|
|
|
|
847
|
|
|
{ |
|
848
|
|
|
$org_name = Input::get('org'); |
|
849
|
|
|
|
|
850
|
|
|
if ($org_name) { |
|
851
|
|
|
$org = Organization::where('name', '=', $org_name)->lists('id')->first(); |
|
852
|
|
|
if ($org) { |
|
853
|
|
|
$user_org = User_org::where('user_id', '=', $id)->first(); |
|
854
|
|
|
$user_org->org_id = $org; |
|
855
|
|
|
$user_org->user_id = $id; |
|
856
|
|
|
$user_org->save(); |
|
857
|
|
|
|
|
858
|
|
|
return 1; |
|
859
|
|
|
} else { |
|
860
|
|
|
return 0; |
|
861
|
|
|
} |
|
862
|
|
|
} else { |
|
863
|
|
|
return 2; |
|
864
|
|
|
} |
|
865
|
|
|
} |
|
866
|
|
|
|
|
867
|
|
View Code Duplication |
public function orgAssignUser($id) |
|
|
|
|
|
|
868
|
|
|
{ |
|
869
|
|
|
$org = Input::get('org'); |
|
870
|
|
|
$user_org = new User_org(); |
|
871
|
|
|
$user_org->org_id = $id; |
|
|
|
|
|
|
872
|
|
|
$user_org->user_id = $org; |
|
|
|
|
|
|
873
|
|
|
$user_org->save(); |
|
874
|
|
|
|
|
875
|
|
|
return 1; |
|
876
|
|
|
} |
|
877
|
|
|
|
|
878
|
|
|
public function removeUserOrg($id) |
|
879
|
|
|
{ |
|
880
|
|
|
$user_org = User_org::where('org_id', '=', $id)->first(); |
|
881
|
|
|
$user_org->delete(); |
|
882
|
|
|
|
|
883
|
|
|
return redirect()->back()->with('success1', Lang::get('lang.the_user_has_been_removed_from_this_organization')); |
|
884
|
|
|
} |
|
885
|
|
|
|
|
886
|
|
|
/** |
|
887
|
|
|
* creating an organization in user profile page via modal popup. |
|
888
|
|
|
* |
|
889
|
|
|
* @param type $id |
|
890
|
|
|
* |
|
891
|
|
|
* @return type |
|
892
|
|
|
*/ |
|
893
|
|
View Code Duplication |
public function User_Create_Org($id) |
|
|
|
|
|
|
894
|
|
|
{ |
|
895
|
|
|
// checking if the entered value for website is available in database |
|
896
|
|
|
if (Input::get('website') != null) { |
|
897
|
|
|
// checking website |
|
898
|
|
|
$check = Organization::where('website', '=', Input::get('website'))->first(); |
|
899
|
|
|
} else { |
|
900
|
|
|
$check = null; |
|
901
|
|
|
} |
|
902
|
|
|
// checking if the name is unique |
|
903
|
|
|
$check2 = Organization::where('name', '=', Input::get('name'))->first(); |
|
904
|
|
|
// if any of the fields is not available then return false |
|
905
|
|
|
if (\Input::get('name') == null) { |
|
906
|
|
|
return 'Name is required'; |
|
907
|
|
|
} elseif ($check2 != null) { |
|
908
|
|
|
return 'Name should be Unique'; |
|
909
|
|
|
} elseif ($check != null) { |
|
910
|
|
|
return 'Website should be Unique'; |
|
911
|
|
|
} else { |
|
912
|
|
|
// storing organization details and assigning the current user to that organization |
|
913
|
|
|
$org = new Organization(); |
|
914
|
|
|
$org->name = Input::get('name'); |
|
|
|
|
|
|
915
|
|
|
$org->phone = Input::get('phone'); |
|
|
|
|
|
|
916
|
|
|
$org->website = Input::get('website'); |
|
|
|
|
|
|
917
|
|
|
$org->address = Input::get('address'); |
|
|
|
|
|
|
918
|
|
|
$org->internal_notes = Input::get('internal'); |
|
|
|
|
|
|
919
|
|
|
$org->save(); |
|
920
|
|
|
|
|
921
|
|
|
$user_org = new User_org(); |
|
922
|
|
|
$user_org->org_id = $org->id; |
|
|
|
|
|
|
923
|
|
|
$user_org->user_id = $id; |
|
|
|
|
|
|
924
|
|
|
$user_org->save(); |
|
925
|
|
|
// for success return 0 |
|
|
|
|
|
|
926
|
|
|
return 0; |
|
927
|
|
|
} |
|
928
|
|
|
} |
|
929
|
|
|
|
|
930
|
|
|
/** |
|
931
|
|
|
* Generate a random string for password. |
|
932
|
|
|
* |
|
933
|
|
|
* @param type $length |
|
934
|
|
|
* |
|
935
|
|
|
* @return string |
|
936
|
|
|
*/ |
|
937
|
|
View Code Duplication |
public function generateRandomString($length = 10) |
|
|
|
|
|
|
938
|
|
|
{ |
|
939
|
|
|
// list of supported characters |
|
940
|
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
941
|
|
|
// character length checked |
|
942
|
|
|
$charactersLength = strlen($characters); |
|
943
|
|
|
// creating an empty variable for random string |
|
944
|
|
|
$randomString = ''; |
|
945
|
|
|
// fetching random string |
|
946
|
|
|
for ($i = 0; $i < $length; $i++) { |
|
947
|
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)]; |
|
948
|
|
|
} |
|
949
|
|
|
// return random string |
|
950
|
|
|
return $randomString; |
|
951
|
|
|
} |
|
952
|
|
|
|
|
953
|
|
|
public function storeUserOrgRelation($userid, $orgid) |
|
954
|
|
|
{ |
|
955
|
|
|
$org_relations = new User_org(); |
|
956
|
|
|
$org_relation = $org_relations->where('user_id', $userid)->first(); |
|
|
|
|
|
|
957
|
|
|
if ($org_relation) { |
|
958
|
|
|
$org_relation->delete(); |
|
959
|
|
|
} |
|
960
|
|
|
$org_relations->create([ |
|
961
|
|
|
'user_id' => $userid, |
|
962
|
|
|
'org_id' => $orgid, |
|
963
|
|
|
]); |
|
964
|
|
|
} |
|
965
|
|
|
|
|
966
|
|
|
public function getExportUser() |
|
967
|
|
|
{ |
|
968
|
|
|
try { |
|
969
|
|
|
return view('themes.default1.agent.helpdesk.user.export'); |
|
970
|
|
|
} catch (Exception $ex) { |
|
971
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
972
|
|
|
} |
|
973
|
|
|
} |
|
974
|
|
|
|
|
975
|
|
View Code Duplication |
public function exportUser(Request $request) |
|
|
|
|
|
|
976
|
|
|
{ |
|
977
|
|
|
try { |
|
978
|
|
|
$date = $request->input('date'); |
|
979
|
|
|
$date = str_replace(' ', '', $date); |
|
980
|
|
|
$date_array = explode(':', $date); |
|
981
|
|
|
$first = $date_array[0].' 00:00:00'; |
|
982
|
|
|
$second = $date_array[1].' 23:59:59'; |
|
983
|
|
|
$first_date = $this->convertDate($first); |
|
984
|
|
|
$second_date = $this->convertDate($second); |
|
985
|
|
|
$users = $this->getUsers($first_date, $second_date); |
|
986
|
|
|
$excel_controller = new \App\Http\Controllers\Common\ExcelController(); |
|
987
|
|
|
$filename = 'users'.$date; |
|
988
|
|
|
$excel_controller->export($filename, $users); |
|
989
|
|
|
} catch (Exception $ex) { |
|
990
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
991
|
|
|
} |
|
992
|
|
|
} |
|
993
|
|
|
|
|
994
|
|
|
public function convertDate($date) |
|
995
|
|
|
{ |
|
996
|
|
|
$converted_date = date('Y-m-d H:i:s', strtotime($date)); |
|
997
|
|
|
|
|
998
|
|
|
return $converted_date; |
|
999
|
|
|
} |
|
1000
|
|
|
|
|
1001
|
|
|
public function getUsers($first, $last) |
|
1002
|
|
|
{ |
|
1003
|
|
|
$user = new User(); |
|
1004
|
|
|
$users = $user->leftJoin('user_assign_organization', 'users.id', '=', 'user_assign_organization.user_id') |
|
|
|
|
|
|
1005
|
|
|
->leftJoin('organization', 'user_assign_organization.org_id', '=', 'organization.id') |
|
1006
|
|
|
->whereBetween('users.created_at', [$first, $last]) |
|
1007
|
|
|
->where('role', 'user') |
|
1008
|
|
|
->where('active', 1) |
|
1009
|
|
|
->select('users.user_name as Username', 'users.email as Email', 'users.first_name as Fisrtname', 'users.last_name as Lastname', 'organization.name as Organization') |
|
1010
|
|
|
->get() |
|
1011
|
|
|
->toArray(); |
|
1012
|
|
|
|
|
1013
|
|
|
return $users; |
|
1014
|
|
|
} |
|
1015
|
|
|
|
|
1016
|
|
View Code Duplication |
public function resendOTP(OtpVerifyRequest $request) |
|
|
|
|
|
|
1017
|
|
|
{ |
|
1018
|
|
|
if (\Schema::hasTable('sms')) { |
|
1019
|
|
|
$sms = DB::table('sms')->get(); |
|
1020
|
|
|
if (count($sms) > 0) { |
|
1021
|
|
|
\Event::fire(new \App\Events\LoginEvent($request)); |
|
1022
|
|
|
|
|
1023
|
|
|
return 1; |
|
1024
|
|
|
} |
|
1025
|
|
|
} else { |
|
1026
|
|
|
return 'Plugin has not been setup successfully.'; |
|
1027
|
|
|
} |
|
1028
|
|
|
} |
|
1029
|
|
|
|
|
1030
|
|
View Code Duplication |
public function verifyOTP() |
|
|
|
|
|
|
1031
|
|
|
{ |
|
1032
|
|
|
// dd(Input::all()); |
|
|
|
|
|
|
1033
|
|
|
// $user = User::select('id', 'mobile', 'user_name')->where('email', '=', $request->input('email'))->first(); |
|
|
|
|
|
|
1034
|
|
|
$otp = Otp::select('otp', 'updated_at')->where('user_id', '=', Input::get('u_id')) |
|
1035
|
|
|
->first(); |
|
1036
|
|
|
if ($otp != null) { |
|
1037
|
|
|
$otp_length = strlen(Input::get('otp')); |
|
1038
|
|
|
if (($otp_length == 6 && !preg_match('/[a-z]/i', Input::get('otp')))) { |
|
1039
|
|
|
$otp2 = Hash::make(Input::get('otp')); |
|
|
|
|
|
|
1040
|
|
|
$date1 = date_format($otp->updated_at, 'Y-m-d h:i:sa'); |
|
1041
|
|
|
$date2 = date('Y-m-d h:i:sa'); |
|
1042
|
|
|
$time1 = new DateTime($date2); |
|
1043
|
|
|
$time2 = new DateTime($date1); |
|
1044
|
|
|
$interval = $time1->diff($time2); |
|
1045
|
|
|
if ($interval->i > 10 || $interval->h > 0) { |
|
1046
|
|
|
$message = Lang::get('lang.otp-expired'); |
|
1047
|
|
|
|
|
1048
|
|
|
return $message; |
|
1049
|
|
|
} else { |
|
1050
|
|
|
if (Hash::check(Input::get('otp'), $otp->otp)) { |
|
1051
|
|
|
Otp::where('user_id', '=', Input::get('u_id')) |
|
1052
|
|
|
->update(['otp' => '']); |
|
1053
|
|
|
// User::where('id', '=', $user->id) |
|
|
|
|
|
|
1054
|
|
|
// ->update(['active' => 1]); |
|
|
|
|
|
|
1055
|
|
|
// $this->openTicketAfterVerification($user->id); |
|
|
|
|
|
|
1056
|
|
|
return 1; |
|
1057
|
|
|
} else { |
|
1058
|
|
|
$message = Lang::get('lang.otp-not-matched'); |
|
1059
|
|
|
|
|
1060
|
|
|
return $message; |
|
1061
|
|
|
} |
|
1062
|
|
|
} |
|
1063
|
|
|
} else { |
|
1064
|
|
|
$message = Lang::get('lang.otp-invalid'); |
|
1065
|
|
|
|
|
1066
|
|
|
return $message; |
|
1067
|
|
|
} |
|
1068
|
|
|
} else { |
|
1069
|
|
|
$message = Lang::get('lang.otp-not-matched'); |
|
1070
|
|
|
|
|
1071
|
|
|
return $message; |
|
1072
|
|
|
} |
|
1073
|
|
|
} |
|
1074
|
|
|
|
|
1075
|
|
|
public function getAgentDetails() |
|
1076
|
|
|
{ |
|
1077
|
|
|
$users = User::where('role', '<>', 'user')->where('active', '=', 1)->orderBy('first_name')->get(); |
|
1078
|
|
|
foreach ($users as $user) { |
|
1079
|
|
|
echo "<option value='user_$user->id'>".$user->name().'</option>'; |
|
1080
|
|
|
} |
|
1081
|
|
|
} |
|
1082
|
|
|
} |
|
1083
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.