update v1.0.5

This commit is contained in:
sujitprasad
2016-01-25 20:45:35 +05:30
parent 0b8ebb9c70
commit e7149e34e4
252 changed files with 9008 additions and 3152 deletions

View File

@@ -1,6 +1,7 @@
<?php namespace App\Http\Controllers\Agent\helpdesk;
// controllers
use App\Http\Controllers\Controller;
// requests
/* Include Sys_user Model */
use App\Http\Requests\helpdesk\ProfilePassword;
@@ -10,26 +11,22 @@ use App\Http\Requests\helpdesk\ProfileRequest;
use App\Http\Requests\helpdesk\Sys_userRequest;
/* include guest_note model */
use App\Http\Requests\helpdesk\Sys_userUpdate;
// models
use App\Model\helpdesk\Agent_panel\Organization;
use App\Model\helpdesk\Agent_panel\User_org;
/* include User Model */
/* include Help_topic Model */
/* Profile validator */
/* Profile Password validator */
use App\User;
// classes
/* include ticket_thred model */
use Auth;
/* include tickets model */
use Hash;
/* TicketRequest to validate the ticket response */
/* Validate post check ticket */
use Input;
use Redirect;
use Exception;
/**
* UserController
* This controller is used to CRUD an User details, and proile management of an agent
*
* @package Controllers
* @subpackage Controller
@@ -43,45 +40,50 @@ class UserController extends Controller {
* 1. authentication
* 2. user roles
* 3. roles must be agent
*
* @return void
*/
public function __construct() {
// checking authentication
$this->middleware('auth');
// checking if role is agent
$this->middleware('role.agent');
// $this->middleware('roles');
}
/**
* Display a listing of the resource.
* Display all list of the users.
* @param type User $user
* @return type Response
* @return type view
*/
public function index() {
try {
/* get all values in Sys_user */
return view('themes.default1.agent.helpdesk.user.index');
} catch (Exception $e) {
return view('404');
return redirect()->back()->with('fails',$e->errorInfo[2]);
}
}
/**
* This function is used to display the list of users
* This function is used to display the list of users using chumper datatables
* @return datatable
*/
public function user_list() {
// displaying list of users with chumper datatables
return \Datatable::collection(User::where('role','!=','admin')->where('role','!=','agent')->get())
/* searchable column username */
->searchColumns('user_name')
/* order column username and email */
->orderColumns('user_name', 'email')
/* column username */
->addColumn('user_name', function ($model) {
return $model->user_name;
})
/* column email */
->addColumn('email', function ($model) {
$email = $model->email;
return $email;
})
/* column phone */
->addColumn('phone', function ($model) {
$phone = "";
if($model->phone_number) {
@@ -94,6 +96,7 @@ class UserController extends Controller {
$phone = $phone ."&nbsp;&nbsp;&nbsp;". $mobile;
return $phone;
})
/* column status */
->addColumn('status', function ($model) {
$status = $model->active;
if($status == 1) {
@@ -103,55 +106,37 @@ class UserController extends Controller {
}
return $stat;
})
/* column last login date */
->addColumn('lastlogin', function ($model) {
$t = $model->updated_at;
return TicketController::usertimezone($t);
})
/* column actions */
->addColumn('Actions', function ($model) {
//return '<a href=article/delete/ ' . $model->id . ' class="btn btn-danger btn-flat" onclick="myFunction()">Delete</a>&nbsp;<a href=article/' . $model->id . '/edit class="btn btn-warning btn-flat">Edit</a>&nbsp;<a href=show/' . $model->id . ' class="btn btn-warning btn-flat">View</a>';
//return '<form action="article/delete/ ' . $model->id . '" method="post" onclick="alert()"><button type="sumbit" value="Delete"></button></form><a href=article/' . $model->id . '/edit class="btn btn-warning btn-flat">Edit</a>&nbsp;<a href=show/' . $model->id . ' class="btn btn-warning btn-flat">View</a>';
return '<span data-toggle="modal" data-target="#deletearticle'.$model->id .'"><a href="#" ><button class="btn btn-danger btn-xs"></a> ' . \Lang::get('lang.delete') . ' </button></span>&nbsp;<a href="'.route('user.edit', $model->id).'" class="btn btn-warning btn-xs">' . \Lang::get('lang.edit') . '</a>&nbsp;<a href="'.route('user.show', $model->id).'" class="btn btn-primary btn-xs">' . \Lang::get('lang.view') . '</a>
<div class="modal fade" id="deletearticle'.$model->id .'">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Are You Sure ?</h4>
</div>
<div class="modal-body">
'.$model->user_name.'
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">Close</button>
<a href="'.route('user.delete',$model->id).'"><button class="btn btn-danger">delete</button></a>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>';
return '<a href="'.route('user.edit', $model->id).'" class="btn btn-warning btn-xs">' . \Lang::get('lang.edit') . '</a>&nbsp; <a href="'.route('user.show', $model->id).'" class="btn btn-primary btn-xs">' . \Lang::get('lang.view') . '</a>';
})
->make();
}
/**
* Show the form for creating a new resource.
* @return type Response
* Show the form for creating a new users.
* @return type view
*/
public function create() {
try {
return view('themes.default1.agent.helpdesk.user.create');
} catch (Exception $e) {
return view('404');
return redirect()->back()->with('fails',$e->errorInfo[2]);
}
}
/**
* Store a newly created resource in storage.
* Store a newly created users in storage.
* @param type User $user
* @param type Sys_userRequest $request
* @return type Response
* @return type redirect
*/
public function store(User $user, Sys_userRequest $request) {
try {
/* insert the input request to sys_user table */
/* Check whether function success or not */
$user->email = $request->input('email');
@@ -162,24 +147,21 @@ class UserController extends Controller {
$user->active = $request->input('active');
$user->internal_note = $request->input('internal_note');
$user->role = 'user';
if ($user->save() == true) {
try {
$user->save();
/* redirect to Index page with Success Message */
return redirect('user')->with('success', 'User Created Successfully');
} else {
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('user')->with('fails', 'User can not Create');
}
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('user')->with('fails', 'User can not Create');
}
return redirect('user')->with('fails', $e->errorInfo[2]);
}
}
/**
* Display the specified resource.
* Display the specified users.
* @param type int $id
* @param type User $user
* @return type Response
* @return type view
*/
public function show($id, User $user) {
try {
@@ -203,89 +185,71 @@ class UserController extends Controller {
$users = $user->whereId($id)->first();
return view('themes.default1.agent.helpdesk.user.edit', compact('users'));
} catch (Exception $e) {
return view('404');
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* Update the specified resource in storage.
* Update the specified user in storage.
* @param type int $id
* @param type User $user
* @param type Sys_userUpdate $request
* @return type Response
*/
public function update($id, User $user, Sys_userUpdate $request) {
try {
/* select the field where id = $id(request Id) */
$users = $user->whereId($id)->first();
/* Update the value by selected field */
/* Check whether function success or not */
if ($users->fill($request->input())->save() == true) {
try{
$users->fill($request->input())->save();
/* redirect to Index page with Success Message */
return redirect('user')->with('success', 'User Updated Successfully');
} else {
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('user')->with('fails', 'User can not Update');
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('user')->with('fails', 'User can not Update');
}
}
/**
* Remove the specified resource from storage.
* @param type int $id
* @param type User $user
* @return type Response
*/
public function destroy($id, User $user) {
try {
/* select the field where id = $id(request Id) */
$users = $user->whereId($id)->first();
/* delete the selected field */
/* Check whether function success or not */
if ($users->delete() == true) {
/* redirect to Index page with Success Message */
return redirect('user')->with('success', 'User Deleted Successfully');
} else {
/* redirect to Index page with Fails Message */
return redirect('user')->with('fails', 'User can not Delete');
}
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('user')->with('fails', 'User can not Delete');
}
}
/**
* get profile page
* @return type Response
* get agent profile page
* @return type view
*/
public function getProfile() {
$user = Auth::user();
return view('themes.default1.agent.helpdesk.user.profile', compact('user'));
}
try {
return view('themes.default1.agent.helpdesk.user.profile', compact('user'));
} catch(Exception $e) {
return redirect()->back()->with('fails',$e->errorInfo[2]);
}
}
/**
* get profile edit page
* @return type Response
* @return type view
*/
public function getProfileedit() {
$user = Auth::user();
return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user'));
try {
return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user'));
} catch (Exception $e) {
return redirect()->back()->with('fails',$e->errorInfo[2]);
}
}
/**
* post profile page
* post profile edit
* @param type int $id
* @param type ProfileRequest $request
* @return type Response
* @return type Redirect
*/
public function postProfileedit(ProfileRequest $request) {
// geet authenticated user details
$user = Auth::user();
$user->gender = $request->input('gender');
$user->save();
// checking availability of agent profile ppicture
if ($user->profile_pic == 'avatar5.png' || $user->profile_pic == 'avatar2.png') {
if ($request->input('gender') == 1) {
$name = 'avatar5.png';
@@ -297,17 +261,26 @@ class UserController extends Controller {
$user->profile_pic = $name;
}
}
// checking if the post system includes agent profile picture upload
if (Input::file('profile_pic')) {
//$extension = Input::file('profile_pic')->getClientOriginalExtension();
// fetching picture name
$name = Input::file('profile_pic')->getClientOriginalName();
// fetching upload destination path
$destinationPath = 'lb-faveo/profilepic';
// adding a random value to profile picture filename
$fileName = rand(0000, 9999) . '.' . $name;
//echo $fileName;
// moving the picture to a destination folder
Input::file('profile_pic')->move($destinationPath, $fileName);
// saving filename to database
$user->profile_pic = $fileName;
} else {
$user->fill($request->except('profile_pic', 'gender'))->save();
return Redirect::route('profile')->with('success', 'Profile Updated sucessfully');
try{
$user->fill($request->except('profile_pic', 'gender'))->save();
return Redirect::route('profile')->with('success', 'Profile Updated sucessfully');
} catch (Exception $e){
return Redirect::route('profile')->with('success', $e->errorInfo[2]);
}
}
if ($user->fill($request->except('profile_pic'))->save()) {
return Redirect::route('profile')->with('success', 'Profile Updated sucessfully');
@@ -318,22 +291,27 @@ class UserController extends Controller {
* Post profile password
* @param type int $id
* @param type ProfilePassword $request
* @return type Response
* @return type Redirect
*/
public function postProfilePassword($id, ProfilePassword $request) {
// get authenticated user
$user = Auth::user();
//echo $user->password;
// checking if the old password matches the new password
if (Hash::check($request->input('old_password'), $user->getAuthPassword())) {
$user->password = Hash::make($request->input('new_password'));
$user->save();
return redirect('profile-edit')->with('success1', 'Password Updated sucessfully');
try{
$user->save();
return redirect('profile-edit')->with('success1', 'Password Updated sucessfully');
} catch (Exception $e) {
return redirect('profile-edit')->with('fails', $e->errorInfo[2]);
}
} else {
return redirect('profile-edit')->with('fails1', 'Password was not Updated. Incorrect old password');
}
}
/**
* User Assign Org
* Assigning an user to an organization
* @param type $id
* @return type boolean
*/
@@ -347,21 +325,21 @@ class UserController extends Controller {
}
/**
* user create organisation
* @return type value
* creating an organization in user profile page via modal popup
* @param type $id
* @return type
*/
public function User_Create_Org($id) {
// checking if the entered value for website is available in database
if(Input::get('website')!=null) {
// checking website
$check = Organization::where('website','=',Input::get('website'))->first();
} else {
$check = null;
}
// checking name
// checking if the name is unique
$check2 = Organization::where('name','=',Input::get('name'))->first();
// if any of the fields is not available then return false
if (\Input::get('name') == null) {
return "Name is required";
} elseif($check2 != null) {
@@ -369,6 +347,7 @@ class UserController extends Controller {
} elseif($check != null) {
return "Website should be Unique";
} else {
// storing organization details and assigning the current user to that organization
$org = new Organization;
$org->name = Input::get('name');
$org->phone = Input::get('phone');
@@ -381,7 +360,7 @@ class UserController extends Controller {
$user_org->org_id = $org->id;
$user_org->user_id = $id;
$user_org->save();
// for success return 0
return 0;
}
}