commit
This commit is contained in:
2025-08-09 04:43:00 +07:00
parent e075da48fd
commit 95bb93afa6
10 changed files with 17014 additions and 563 deletions

View File

@@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
// models
use App\Model\helpdesk\Priority;
use App\Model\helpdesk\Ticket_Thread;
use App\Model\helpdesk\Agent\Location;
// classes
use Exception;

View File

@@ -83,15 +83,15 @@ class UserController extends Controller
/* get all values in Sys_user */
$table = \Datatable::table()
->addColumn(
Lang::get('lang.name'),
Lang::get('lang.email'),
Lang::get('lang.phone'),
Lang::get('lang.status'),
Lang::get('lang.last_login'),
Lang::get('lang.role'),
Lang::get('lang.action')
) // these are the column headings to be shown
->addColumn(
Lang::get('lang.name'),
Lang::get('lang.email'),
Lang::get('lang.phone'),
Lang::get('lang.status'),
Lang::get('lang.last_login'),
Lang::get('lang.role'),
Lang::get('lang.action')
) // these are the column headings to be shown
->noScript();
return view('themes.default1.agent.helpdesk.user.index', compact('table'));
@@ -141,100 +141,100 @@ class UserController extends Controller
if ($search !== '') {
$users = $users->where(function ($query) use ($search) {
$query->where('user_name', 'LIKE', '%'.$search.'%');
$query->orWhere('email', 'LIKE', '%'.$search.'%');
$query->orWhere('first_name', 'LIKE', '%'.$search.'%');
$query->orWhere('last_name', 'LIKE', '%'.$search.'%');
$query->orWhere('mobile', 'LIKE', '%'.$search.'%');
$query->orWhere('updated_at', 'LIKE', '%'.$search.'%');
$query->orWhere('country_code', 'LIKE', '%'.$search.'%');
$query->where('user_name', 'LIKE', '%' . $search . '%');
$query->orWhere('email', 'LIKE', '%' . $search . '%');
$query->orWhere('first_name', 'LIKE', '%' . $search . '%');
$query->orWhere('last_name', 'LIKE', '%' . $search . '%');
$query->orWhere('mobile', 'LIKE', '%' . $search . '%');
$query->orWhere('updated_at', 'LIKE', '%' . $search . '%');
$query->orWhere('country_code', 'LIKE', '%' . $search . '%');
});
}
// displaying list of users with chumper datatables
// return \Datatable::collection(User::where('role', "!=", "admin")->get())
return \Yajra\DataTables\Facades\DataTables::of($users)
/* column username */
->removeColumn('id', 'last_name', 'country_code', 'phone_number')
->addColumn('user_name', function ($model) {
if ($model->first_name) {
$string = strip_tags($model->first_name.' '.$model->last_name);
} else {
$string = strip_tags($model->user_name);
}
if (strlen($string) > 30) {
// truncate string
$stringCut = mb_substr($string, 0, 30, 'UTF-8').'...';
} else {
$stringCut = $string;
}
/* column username */
->removeColumn('id', 'last_name', 'country_code', 'phone_number')
->addColumn('user_name', function ($model) {
if ($model->first_name) {
$string = strip_tags($model->first_name . ' ' . $model->last_name);
} else {
$string = strip_tags($model->user_name);
}
if (strlen($string) > 30) {
// truncate string
$stringCut = mb_substr($string, 0, 30, 'UTF-8') . '...';
} else {
$stringCut = $string;
}
return "<a href='".route('user.show', $model->id)."' title='".$string."''>".$stringCut.'</a>';
})
/* column email */
->addColumn('email', function ($model) {
$email = "<a href='".route('user.show', $model->id)."'>".e($model->email).'</a>';
return "<a href='" . route('user.show', $model->id) . "' title='" . $string . "''>" . $stringCut . '</a>';
})
/* column email */
->addColumn('email', function ($model) {
$email = "<a href='" . route('user.show', $model->id) . "'>" . e($model->email) . '</a>';
return $email;
})
/* column phone */
->addColumn('mobile', function ($model) {
$phone = '';
if ($model->phone_number) {
$phone = htmlspecialchars($model->ext.' '.$model->phone_number, ENT_QUOTES, 'UTF-8');
}
$mobile = '';
if ($model->mobile) {
$mobile = htmlspecialchars($model->mobile, ENT_QUOTES, 'UTF-8');
}
$phone = $phone.'&nbsp;&nbsp;&nbsp;'.$mobile;
return $email;
})
/* column phone */
->addColumn('mobile', function ($model) {
$phone = '';
if ($model->phone_number) {
$phone = htmlspecialchars($model->ext . ' ' . $model->phone_number, ENT_QUOTES, 'UTF-8');
}
$mobile = '';
if ($model->mobile) {
$mobile = htmlspecialchars($model->mobile, ENT_QUOTES, 'UTF-8');
}
$phone = $phone . '&nbsp;&nbsp;&nbsp;' . $mobile;
return $phone;
})
/* column account status */
->addColumn('active', function ($model) {
$status = $model->active;
if ($status == 1) {
$stat = '<button class="btn btn-success btn-xs">Active</button>';
} else {
$stat = '<button class="btn btn-danger btn-xs">Inactive</button>';
}
return $phone;
})
/* column account status */
->addColumn('active', function ($model) {
$status = $model->active;
if ($status == 1) {
$stat = '<button class="btn btn-success btn-xs">Active</button>';
} else {
$stat = '<button class="btn btn-danger btn-xs">Inactive</button>';
}
return $stat;
})
/* column last login date */
->addColumn('updated_at', function ($model) {
$t = $model->updated_at;
return $stat;
})
/* column last login date */
->addColumn('updated_at', function ($model) {
$t = $model->updated_at;
return TicketController::usertimezone($t);
})
/* column Role */
->addColumn('role', function ($model) {
$role = $model->role;
return TicketController::usertimezone($t);
})
/* column Role */
->addColumn('role', function ($model) {
$role = $model->role;
return $role;
})
/* column actions */
->addColumn('Actions', function ($model) {
if ($model->is_delete == 0) {
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>';
} else {
if (Auth::user()->role == 'admin') {
// @if(Auth::user()->role == 'admin')
return $role;
})
/* column actions */
->addColumn('Actions', function ($model) {
if ($model->is_delete == 0) {
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>';
} else {
if (Auth::user()->role == 'admin') {
// @if(Auth::user()->role == 'admin')
return '<a href="'.route('user.show', $model->id).'" class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>';
}
return '<a href="' . route('user.show', $model->id) . '" class="btn btn-primary btn-xs">' . \Lang::get('lang.view') . '</a>';
}
if (Auth::user()->role == 'agent') {
// @if(Auth::user()->role == 'admin')
if ($model->role == 'user') {
return '<a href="'.route('user.show', $model->id).'" class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>';
}
}
}
})
->rawColumns(['user_name', 'email', 'mobile', 'active', 'updated_at', 'role', 'Actions'])
->make();
if (Auth::user()->role == 'agent') {
// @if(Auth::user()->role == 'admin')
if ($model->role == 'user') {
return '<a href="' . route('user.show', $model->id) . '" class="btn btn-primary btn-xs">' . \Lang::get('lang.view') . '</a>';
}
}
}
})
->rawColumns(['user_name', 'email', 'mobile', 'active', 'updated_at', 'role', 'Actions'])
->make();
}
public function restoreUser($id)
@@ -341,7 +341,7 @@ class UserController extends Controller
return redirect('user')->with('success', Lang::get('lang.User-Created-Successfully'));
}
// $user->save();
// $user->save();
/* redirect to Index page with Success Message */
return redirect('user')->with('success', Lang::get('lang.User-Created-Successfully'));
} catch (Exception $e) {
@@ -396,7 +396,7 @@ class UserController extends Controller
$email = $user->email;
$this->PhpMailController->sendmail($from = $this->PhpMailController
->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => null, 'scenario' => 'reset_new_password'], $template_variables = ['user' => $name, 'user_password' => $password]);
->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => null, 'scenario' => 'reset_new_password'], $template_variables = ['user' => $name, 'user_password' => $password]);
return redirect('user')->with('success', Lang::get('lang.password_change_successfully'));
} catch (Exception $e) {
@@ -535,7 +535,7 @@ class UserController extends Controller
$ticket->assigned_to = $assign_to[1];
$user_detail = User::where('id', '=', $assign_to[1])->first();
$assignee = $user_detail->first_name.' '.$user_detail->last_name;
$assignee = $user_detail->first_name . ' ' . $user_detail->last_name;
$ticket_number = $ticket->ticket_number;
$ticket->save();
@@ -543,7 +543,7 @@ class UserController extends Controller
$thread->ticket_id = $ticket->id;
$thread->user_id = Auth::user()->id;
$thread->is_internal = 1;
$thread->body = 'This Ticket has been assigned to '.$assignee;
$thread->body = 'This Ticket has been assigned to ' . $assignee;
$thread->save();
}
$user = User::find($id);
@@ -646,6 +646,7 @@ class UserController extends Controller
// dd('here');
$settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first();
$email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first();
$departments = Department::all();
$user = new User();
/* select the field where id = $id(request Id) */
@@ -659,7 +660,7 @@ class UserController extends Controller
// $org_name=Organization::where('id','=',$org_id)->pluck('name')->first();
// dd($org_name);
return view('themes.default1.agent.helpdesk.user.edit', compact('users', 'orgs', 'settings', 'email_mandatory', 'organization_id'))->with('phonecode', $phonecode->phonecode);
return view('themes.default1.agent.helpdesk.user.edit', compact('users', 'orgs', 'settings', 'email_mandatory', 'organization_id', 'departments'))->with('phonecode', $phonecode->phonecode);
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->getMessage());
}
@@ -740,11 +741,11 @@ class UserController extends Controller
$status = $settings->status;
$departments = Department::all();
try {
return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user', 'departments'))
->with([
'phonecode' => $phonecode->phonecode,
'verify' => $status,
]);
return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user', 'departments'))
->with([
'phonecode' => $phonecode->phonecode,
'verify' => $status,
]);
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->getMessage());
}
@@ -783,7 +784,7 @@ class UserController extends Controller
// fetching upload destination path
$destinationPath = 'uploads/profilepic';
// adding a random value to profile picture filename
$fileName = rand(0000, 9999).'.'.str_replace(' ', '_', $name);
$fileName = rand(0000, 9999) . '.' . str_replace(' ', '_', $name);
// moving the picture to a destination folder
Input::file('profile_pic')->move($destinationPath, $fileName);
// saving filename to database
@@ -997,13 +998,13 @@ class UserController extends Controller
$date = $request->input('date');
$date = str_replace(' ', '', $date);
$date_array = explode(':', $date);
$first = $date_array[0].' 00:00:00';
$second = $date_array[1].' 23:59:59';
$first = $date_array[0] . ' 00:00:00';
$second = $date_array[1] . ' 23:59:59';
$first_date = $this->convertDate($first);
$second_date = $this->convertDate($second);
$users = $this->getUsers($first_date, $second_date);
$excel_controller = new \App\Http\Controllers\Common\ExcelController();
$filename = 'users'.$date;
$filename = 'users' . $date;
return $excel_controller->export($filename, $users);
} catch (Exception $ex) {
@@ -1022,13 +1023,13 @@ class UserController extends Controller
{
$user = new User();
$users = $user->leftJoin('user_assign_organization', 'users.id', '=', 'user_assign_organization.user_id')
->leftJoin('organization', 'user_assign_organization.org_id', '=', 'organization.id')
->whereBetween('users.created_at', [$first, $last])
->where('role', 'user')
->where('active', 1)
->select('users.user_name as Username', 'users.email as Email', 'users.first_name as Fisrtname', 'users.last_name as Lastname', 'organization.name as Organization')
->get()
->toArray();
->leftJoin('organization', 'user_assign_organization.org_id', '=', 'organization.id')
->whereBetween('users.created_at', [$first, $last])
->where('role', 'user')
->where('active', 1)
->select('users.user_name as Username', 'users.email as Email', 'users.first_name as Fisrtname', 'users.last_name as Lastname', 'organization.name as Organization')
->get()
->toArray();
return $users;
}
@@ -1052,7 +1053,7 @@ class UserController extends Controller
// dd(Input::all());
// $user = User::select('id', 'mobile', 'user_name')->where('email', '=', $request->input('email'))->first();
$otp = Otp::select('otp', 'updated_at')->where('user_id', '=', Input::get('u_id'))
->first();
->first();
if ($otp != null) {
$otp_length = strlen(Input::get('otp'));
if ($otp_length == 6 && !preg_match('/[a-z]/i', Input::get('otp'))) {
@@ -1069,7 +1070,7 @@ class UserController extends Controller
} else {
if (Hash::check(Input::get('otp'), $otp->otp)) {
Otp::where('user_id', '=', Input::get('u_id'))
->update(['otp' => '']);
->update(['otp' => '']);
// User::where('id', '=', $user->id)
// ->update(['active' => 1]);
@@ -1097,7 +1098,7 @@ class UserController extends Controller
{
$users = User::where('role', '<>', 'user')->where('active', '=', 1)->orderBy('first_name')->get();
foreach ($users as $user) {
echo "<option value='user_$user->id'>".$user->name().'</option>';
echo "<option value='user_$user->id'>" . $user->name() . '</option>';
}
}
}