Providers/AppServiceProvider.php000064400000000623150247674230013021 0ustar00configureRateLimiting(); $this->routes(function () { Route::middleware('api') ->prefix('api') ->group(base_path('routes/api.php')); Route::middleware('web') ->group(base_path('routes/web.php')); }); } /** * Configure the rate limiters for the application. * * @return void */ protected function configureRateLimiting() { RateLimiter::for('api', function (Request $request) { return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()); }); } } Providers/BroadcastServiceProvider.php000064400000000574150247674230014210 0ustar00 */ protected $policies = [ // 'App\Models\Model' => 'App\Policies\ModelPolicy', ]; /** * Register any authentication / authorization services. * * @return void */ public function boot() { $this->registerPolicies(); // } } Providers/EventServiceProvider.php000064400000001636150247674230013367 0ustar00> */ protected $listen = [ Registered::class => [ SendEmailVerificationNotification::class, ], ]; /** * Register any events for your application. * * @return void */ public function boot() { // } /** * Determine if events and listeners should be automatically discovered. * * @return bool */ public function shouldDiscoverEvents() { return false; } } Console/Kernel.php000064400000001251150247674230010110 0ustar00command('inspire')->hourly(); } /** * Register the commands for the application. * * @return void */ protected function commands() { $this->load(__DIR__.'/Commands'); require base_path('routes/console.php'); } } Http/Middleware/TrustProxies.php000064400000001211150247674230012751 0ustar00|string|null */ protected $proxies; /** * The headers that should be used to detect proxies. * * @var int */ protected $headers = Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB; } Http/Middleware/Authenticate.php000064400000000732150247674230012703 0ustar00expectsJson()) { return route('auth.index'); } } } Http/Middleware/VerifyCsrfToken.php000064400000000500150247674230013341 0ustar00 */ protected $except = [ // ]; } Http/Middleware/TrimStrings.php000064400000000575150247674230012557 0ustar00 */ protected $except = [ 'current_password', 'password', 'password_confirmation', ]; } Http/Middleware/RedirectIfAuthenticated.php000064400000001555150247674230015014 0ustar00check()) { return redirect(RouteServiceProvider::HOME); } } return $next($request); } } Http/Middleware/PreventRequestsDuringMaintenance.php000064400000000556150247674230016764 0ustar00 */ protected $except = [ // ]; } Http/Middleware/TrustHosts.php000064400000000564150247674230012432 0ustar00 */ public function hosts() { return [ $this->allSubdomainsOfApplicationUrl(), ]; } } Http/Middleware/EncryptCookies.php000064400000000463150247674230013227 0ustar00 */ protected $except = [ // ]; } Http/Middleware/ValidateSignature.php000064400000000714150247674230013700 0ustar00 */ protected $except = [ // 'fbclid', // 'utm_campaign', // 'utm_content', // 'utm_medium', // 'utm_source', // 'utm_term', ]; } Http/Kernel.php000064400000005041150247674230007426 0ustar00 */ protected $middleware = [ // \App\Http\Middleware\TrustHosts::class, \App\Http\Middleware\TrustProxies::class, \Illuminate\Http\Middleware\HandleCors::class, \App\Http\Middleware\PreventRequestsDuringMaintenance::class, \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, \App\Http\Middleware\TrimStrings::class, \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, ]; /** * The application's route middleware groups. * * @var array> */ protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, ], 'api' => [ // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, 'throttle:api', \Illuminate\Routing\Middleware\SubstituteBindings::class, ], ]; /** * The application's route middleware. * * These middleware may be assigned to groups or used individually. * * @var array */ protected $routeMiddleware = [ 'auth' => \App\Http\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class, 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class, 'signed' => \App\Http\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, ]; } Http/Controllers/TemplateController.php000064400000017024150247674230014337 0ustar00template = new Template(); } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { if(Bouncer::can('view-template')){ $page_title = "Templates"; return view('admin.templates.index')->with(['page_title' => $page_title]); } else { abort(403,'Unauthorized'); } } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $questions = Questions::where('status',"=",1)->get()->all(); $page_title = "Create Template"; return view('admin.templates.create',compact('questions'))->with(['page_title' => $page_title]); } public function fetchall(Request $request){ $array_data['search_keyword'] = $request->search['value']; if(empty($request->search_type)){ $array_data['search_type'] = ""; } else { $array_data['search_type'] = json_decode($request->search_type,true)[0]; } // dd($array_data['search_type']); $array_data['sort'] = $request->order[0]['dir']; $array_data['order'] = $request->columns[$request->order[0]['column']]['data']; $array_data['offset'] = $request->start; $array_data['limit'] = $request->length; $array_data['offset_limit'] = " LIMIT {$array_data['offset']},{$array_data['limit']}"; $array_data['sort'] = " ORDER BY {$array_data['order']} {$array_data['sort']} "; $array_data['search'] = ""; // dd($request->search_type); if (!empty($array_data['search_keyword'])) { // $array_data['search_keyword'] = "1"; // $array_data['search'] = " AND ? "; // } else { switch ($array_data['search_type']) { // case "ID": // $array_data['search'] = " AND id = {$array_data['search_keyword']} "; // break; case "Template Name": $array_data['search'] = " AND title LIKE '%{$array_data['search_keyword']}%' "; break; } } // dd($array_data['search']); $array_data['where'] = ""; $data = $request->data; if(!empty($data['active'])){ $array_data['where'] .= " AND active = {$data['active']} "; } $results = $this->template->getTemplates($array_data); // dd($results); $result['data'] = array(); foreach($results as $row){ // dd($row); $result['data'][] = array( "id" => $row->id, "title" => $row->title ); } // dd($system); $result['draw'] = $request->draw; $result['recordsTotal'] = $this->template->getTemplatesCount($array_data)[0]->Count; $result['recordsFiltered'] = $this->template->getTemplatesFilteredCount($array_data)[0]->FilteredCount; // dd($result); return response()->json($result); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $request->validate([ 'title' => 'required', 'questionArr' => 'required' ],[ 'title.required' => "Please provide a Template Name", 'questionArr.required' => "Please provide a list of questions" ]); $questions = explode(",",$request->questionArr); $result = $this->template; $result->title = $request->title; $result->q_id = json_encode($questions); $result->active = 1; $result->status = 1; $result->save(); $array_data = [ "id" => Auth::user()->id, "action" => "create", "message" => Auth::user()->id . " has created a template." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(["message"=>"Success","result"=>$result],200); } public function select2fetchAll(){ $template = DB::table('templates') ->select('id','title')->get(); $data['results'] = []; foreach($template as $row){ $data['results'][] = [ "id" => $row->id, "text" => $row->title ]; } return response()->json($data); } public function fetchTemplate(){ $template = Template::all(); dd($template); } /** * Display the specified resource. * * @param \App\Models\Template $template * @return \Illuminate\Http\Response */ public function show(Template $template) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\Template $template * @return \Illuminate\Http\Response */ public function edit($id) { $template = Template::findOrFail($id); $questions = Questions::select('id','title')->where('status',"=",1)->get(); $page_title = "Edit Template"; return view('admin.templates.edit',compact('template','questions'))->with(['page_title' => $page_title]); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\Template $template * @return \Illuminate\Http\Response */ public function update(Request $request) { // dd($request->all()); $questions = explode(",",$request->questionArr); $result = Template::where('id', $request->id) ->update([ 'title' => $request->title, 'q_id' => json_encode($questions) ]); $array_data = [ "id" => Auth::user()->id, "action" => "update", "message" => Auth::user()->id . " has updated a template." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(["message"=>"Success", "result"=>$result],200); } /** * Remove the specified resource from storage. * * @param \App\Models\Template $template * @return \Illuminate\Http\Response */ public function destroy(Request $request) { $res = Questionnaire::where('t_id', $request->id)->count(); if($res > 0){ return response()->json(['message'=>"This template is already in use. Deletion is not possible"], 400); } else { $result = Template::where('id', $request->id) ->update([ 'active' => null, 'status' => null ]); $array_data = [ "id" => Auth::user()->id, "action" => "destroy", "message" => Auth::user()->id . " has deleted a template." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(["message"=>"Success", "result"=>$result]); } } } Http/Controllers/QuestionnaireController.php000064400000022445150247674230015415 0ustar00questionnaire = new Questionnaire(); } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { if(Bouncer::can('view-questionnaire')){ $page_title = "Survey Forms"; return view('admin.questionnaires.index')->with(['page_title' => $page_title]); } else { abort(403,'Unauthorized'); } } public function getQs(Request $request){ $id = $request->id; $tmp = Template::select('q_id')->where('id',$id)->get(); if(!empty($tmp[0]->q_id)){ $q_id = array_map('intval',json_decode($tmp[0]->q_id)); foreach($q_id as $row){ $result = (new QuestionsController)->getQs($row); $array['questions'][] = [ $result[0]->title ]; } return response()->json($array); } } public function fetchall(Request $request){ $array_data['search_keyword'] = $request->search['value']; if(empty($request->search_type)){ $array_data['search_type'] = ""; } else { $array_data['search_type'] = json_decode($request->search_type,true)[0]; } $array_data['sort'] = $request->order[0]['dir']; $array_data['order'] = $request->columns[$request->order[0]['column']]['data']; $array_data['offset'] = $request->start; $array_data['limit'] = $request->length; $array_data['offset_limit'] = " LIMIT {$array_data['offset']},{$array_data['limit']}"; $array_data['sort'] = " ORDER BY {$array_data['order']} {$array_data['sort']} "; $array_data['search'] = ""; if (!empty($array_data['search_keyword'])) { switch ($array_data['search_type']) { case "System Name": $array_data['search'] = " AND `system_name` LIKE '%{$array_data['search_keyword']}%' "; break; case "Template Name": $array_data['search'] = " AND `title` LIKE '%{$array_data['search_keyword']}%' "; break; } } $array_data['where'] = ""; $data = $request->data; if(!empty($data['active'])){ $array_data['where'] .= " AND active = {$data['active']} "; } $results = $this->questionnaire->getQuestionnaires($array_data); $result['data'] = array(); $count = 0; foreach($results as $row){ $result['data'][] = array( "q_id" => $row->q_id, "tmp_id" => $row->tmp_id, "q_count" => $row->q_count, "title" => $row->title, "sys_id" => $row->sys_id, "system_name" =>$row->system_name, "created_at" => date('Y-m-d',strtotime($row->created_at)) ); } $result['draw'] = $request->draw; $result['recordsTotal'] = $this->questionnaire->getQuestionnairesCount($array_data)[0]->Count; $result['recordsFiltered'] = $this->questionnaire->getQuestionnairesFilteredCount($array_data)[0]->FilteredCount; return response()->json($result); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $page_title = "Create Survey Form"; return view('admin.questionnaires.create')->with(['page_title' => $page_title]); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $url = $request->url(); $base_url = explode("/",$url); if($request->t_id == "null"){ return response()->json(["message"=>"Please provide a template name"],402); } if($request->s_id == "null"){ return response()->json(["message"=>"Please choose a system"],402); } $check = Questionnaire::select('id') ->where([['s_id',"=",$request->s_id],['t_id',"=",$request->t_id]]) ->get(); if(empty($check[0])){ DB::table('questionnaires') ->insert([ 's_id' => $request->s_id, 't_id' => $request->t_id, 'instruction' => $request->instruction, 'status' => 1, 'active' => 1 ]); $link = new Link; $link->sys_id = $request->s_id; $link->tmp_id = $request->t_id; $link->link = url('/')."/search/s/".$request->s_id."/tid/".$request->t_id; $link->active = 1; $link->status = 1; $link->save(); $array_data = [ "id" => Auth::user()->id, "action" => "create", "message" => Auth::user()->id . " has created a questionnaire." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(["message"=>"Success"],200); } else { return response()->json(["message"=>"Either template or system is already in use. \n Please edit the template or create new one"],403); } } /** * Display the specified resource. * * @param \App\Models\Questionnaire $questionnaire * @return \Illuminate\Http\Response */ public function show(Questionnaire $questionnaire) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\Questionnaire $questionnaire * @return \Illuminate\Http\Response */ public function edit($tmp_id,$sys_id) { $page_title = "Survery Form View"; $instruction = Questionnaire::select('instruction')->where([['t_id',$tmp_id],['s_id',$sys_id]])->first(); return view('admin.questionnaires.edit',compact('tmp_id','sys_id','instruction'))->with(['page_title' => $page_title]); } public function getQuestions(Request $request){ $q_title = []; $t_name = Template::select('title','q_id') ->where('id',"=",$request->t_id) ->get(); $s_name = System::select('system_name') ->where('id',"=",$request->s_id) ->get(); $questions = array_map('intval',json_decode($t_name[0]->q_id)); foreach($questions as $row){ $q = Questions::select('title')->where('id',$row)->get(); $q_title[] = [ $q[0]->title, ]; } $link = Link::select('link')->where([ ['tmp_id',"=",$request->t_id], ['sys_id',"=",$request->s_id], ])->get(); return response()->json([ "questions"=>$q_title, "template"=>$t_name[0]->title, "system"=>$s_name, "link"=>$link]); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\Questionnaire $questionnaire * @return \Illuminate\Http\Response */ public function update(Request $request) { // dd($request->all()); $result = Questionnaire::where([ ['t_id',"=",$request->t_id], ['s_id',"=",$request->s_id] ])->get(); $questionnaire = Questionnaire::findOrFail($result[0]->id); $questionnaire->instruction = $request->instruction; $questionnaire->save(); $array_data = [ "id" => Auth::user()->id, "action" => "update", "message" => Auth::user()->id . " has updated a questionnaire." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(["message"=>"Success"],200); } /** * Remove the specified resource from storage. * * @param \App\Models\Questionnaire $questionnaire * @return \Illuminate\Http\Response */ public function destroy(Request $request) { $result = Questionnaire::where([ ['t_id',"=",$request->tmp_id], ['s_id',"=",$request->sys_id] ])->update([ 'status' => null, ]); $array_data = [ "id" => Auth::user()->id, "action" => "delete", "message" => Auth::user()->id . " has deleted a questionnaire." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(["message"=>"Success"],200); } } Http/Controllers/ProfileController.php000064400000004206150247674230014162 0ustar00with(['page_title'=>$page_title]); } public function updateProfile(Request $request){ $id = Auth::user()->id; $user = User::findOrFail($id); $request->validate([ 'user_first_name' => 'required', 'user_last_name' => 'required', 'user_email' => 'required' ],[ ]); if(!$request->password || !$request->password_confirmation){ $user->f_name = $request->user_first_name; $user->l_name = $request->user_last_name; $user->email = $request->user_email; $user->save(); $array_data = [ "id" => Auth::user()->id, "action" => "update", "message" => Auth::user()->id . " has updated their profile." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(['message'=>'profile updated'],200); } else { if($request->password !== $request->password_confirmation){ return response()->json(['password does not match'], 403); } else { $user->f_name = $request->user_first_name; $user->l_name = $request->user_last_name; $user->email = $request->user_email; $user->password = bcrypt($request->password); $user->save(); $array_data = [ "id" => Auth::user()->id, "action" => "update", "message" => Auth::user()->id . " has updated their password." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(['message'=>'profile updated'],200); } } } } Http/Controllers/Controller.php000064400000000551150247674230012640 0ustar00select('content')->first(); // $request->validate([ // 'f_name' => 'required', // 'l_name' => 'required', // 'email' => 'required', // 'comp_id' => 'required', // ],[ // ]); if(Auth::check()){ $questionsArr = []; $url = $request->url(); $url = explode("/",$url); // dd($url); $conditions = [ ['sys_id',$url[5]], ['tmp_id',$url[7]] ]; $conditions2 = [ ['s_id',$url[5]], ['t_id',$url[7]], ['status',1], ['active',1] ]; $conditions3 = [ ['user_id',Auth::user()->id], ['tmpt_id',$url[7]], ['syst_id',$url[5]] ]; $check = Link::where($conditions)->get(); $checkIfAlreadyResponded = Answer::where($conditions3)->first(); $qstnn_id = Questionnaire::select('id','instruction')->where([['s_id',$url[5]],['t_id',$url[7]]])->first(); if(!empty($check[0])){ if(!$checkIfAlreadyResponded){ $questions = Template::select('q_id')->where('id',$url[7])->get(); $questionnaire = array_map('intval',json_decode($questions[0]->q_id)); $system_title = System::select('system_name')->where('id',"=",$url[5])->get(); foreach($questionnaire as $row){ $questions = Questions::select('title')->where('id',$row)->get(); $questionsArr['questions'][] = [ 'title' => $questions[0]->title, 'qst_id' => $row ]; } $s_id = $url[5]; $t_id = $url[7]; $q_id = $qstnn_id->id; $instruction = $qstnn_id->instruction; return view('users.verify',compact('questionsArr','t_id','s_id','q_id','system_title','instruction'))->with(['page_title' => $page_title]); } else { return view()->make('message.error',['message' => '

You responded already!

'])->with(['page_title' => $page_title]); } } else { abort(404); } } else { session(['url.intended' => url()->current()]); return redirect('userlogin')->with(['disclaimer'=>$disclaimer]); } } public function getAnswer(Request $request){ $arr = json_decode($request->stars); $result = []; foreach ($arr as $subArr) { $index0 = $subArr[0]; if (!isset($result[$index0])) { $result[$index0] = $subArr; } else { $result[$index0] = $subArr; } } $result = array_values($result); usort($result, function($a, $b) { return $a[0] - $b[0]; }); $result = array_values($result); // dd($result); $qst = []; $ans = []; // dd($result); foreach($result as $row){ $qsts = $row[0]; $qst[] = $qsts; } foreach($result as $row){ $ansr = $row[1]; $ans[] = $ansr; } // foreach($result as $row){ $answer = Answer::insertGetId([ 'user_id' => Auth::user()->id, 'tmpt_id' => $request->t_id, 'syst_id' => $request->s_id, 'qstnn_id' => $request->q_id, 'qst_id' => json_encode($qst), 'rating' => json_encode($ans), 'comment' => $request->comment ]); // } $agent = new Agent(); if($agent->isDesktop()){ DB::table('device_access')->where('id',1) ->increment('pc',1); } if($agent->isMobile()){ DB::table('device_access')->where('id',1) ->increment('mobile',1); } if($agent->isTablet()){ DB::table('device_access')->where('id',1) ->increment('tablet',1); } $email = $this->emailResponse($answer); return response()->json(['message'=>"Success"],200); // if($email == 1){ // return response()->json(['message'=>"success"],200); // } else { // return response()->json(['message'=>"error"],403); // } } public function employeeLogin(Request $request){ // dd($request->all()); $request['type'] = "ratee"; $request->validate([ 'f_name' => 'required|string|max:20', 'l_name' => 'required|string|max:20', 'email' => 'required|string|max:35|ends_with:@autohubgroup.com', 'comp_id' => 'required|integer' ],[ 'f_name.required' => "First Name is required", 'f_name.string' => "First Name should not contain any integer value", 'l_name.required' => "Last Name is required", 'l_name.string' => "Last Name should not contain any integer value", 'email.required' => "Email is required", 'comp_id.integer' => "Please choose a company" ]); $user = User::select('id')->where([['f_name',"=",$request->f_name],['l_name',"=",$request->l_name], ['email',"=",$request->email]])->first(); if(empty($user)){ $request->validate([ 'f_name' => 'required|string|max:20', 'l_name' => 'required|string|max:20', 'email' => 'required|string|max:35|ends_with:@autohubgroup.com|unique:users,email', 'comp_id' => 'required|integer' ],[ 'f_name.required' => "First Name is required", 'f_name.string' => "First Name should not contain any integer value", 'l_name.required' => "Last Name is required", 'l_name.string' => "Last Name should not contain any integer value", 'email.required' => "Email is required", 'email.unique' => "This email has been registered already", 'comp_id.integer' => "Please choose a company" ]); $user = User::create([ 'f_name' => ucfirst(strtolower($request->f_name)), 'l_name' => ucfirst(strtolower($request->l_name)), 'email' => $request->email, 'comp_id' => $request->comp_id, 'password' => " ", 'type' => "ratee" ]); Auth::login($user); } else { Auth::login($user); } $rdr = explode("/",session('url.intended')); $link = "/".$rdr[3]."/".$rdr[4]."/".$rdr[5]."/".$rdr[6]."/".$rdr[7]; return response()->json($link); } public function emailResponse($answer){ $result = Answer::findOrFail($answer); $questions = json_decode($result->qst_id); $qs = []; $template = Template::findOrFail($result->tmpt_id); $user = Auth::user()->l_name . ", " . Auth::user()->f_name; $info = [ 'template' => $template['title'], 'user' => $user, 'email' => Auth::user()->email ]; foreach($questions as $key => $id){ $title = Questions::select('title')->where('id',$id)->first(); $ans = json_decode($result->rating); // dd($ans); $qs[] = [$title['title'],$ans[$key]]; } $to = Auth::user()->email; $subject = "Survey Response"; $headers = "From: Autohub Group of Companies Inc.\r\n"; $headers .= "Content-Type: text/html\r\n"; $message = view('mail.response',['qs' => $qs,'info' => $info, 'comment' => $result->comment])->render(); try { $emailResponse = mail($to, $subject, $message, $headers); if ($emailResponse) { // Email sent successfully $this->emailResponseManagement(Auth::user()->id, $result->id, Auth::user()->email, NOW(), 1); return 1; } else { // Email failed to send $this->emailResponseManagement(Auth::user()->id, $result->id, Auth::user()->email, NOW(), 0); return 0; } } catch (\Exception $e) { // Handle the exception $errorMessage = $e->getMessage(); $this->emailResponseManagement(Auth::user()->id, $result->id, Auth::user()->email, NOW(), 0); return 0; } } public function emailResponseManagement($id,$answer,$email,$created_at,$status){ DB::table('email_responses')->insert([ 'user' => $id, 'ans' => $answer, 'email' => $email, 'created_at' => $created_at, 'status' => $status ]); } public function resendEmail(Request $request){ $result = DB::table('email_responses')->where('id',$request->id)->first(); //get the info of the failed email response // dd($result); $res = Answer::findOrFail($result->ans); $questions = json_decode($res->qst_id); $qs = []; $template = Template::findOrFail($res->tmpt_id); $user = User::where('id',$res->user_id)->first(); $info = [ 'template' => $template['title'], 'user' => $user->f_name . " " . $user->l_name, 'email' => $request->email ]; foreach($questions as $key => $id){ $title = Questions::select('title')->where('id',$id)->first(); $ans = json_decode($res->rating); // dd($ans); $qs[] = [$title['title'],$ans[$key]]; } $to = $request->email; $subject = "Survey Response"; $headers = "From: Autohub Group of Companies Inc.\r\n"; $headers .= "Content-Type: text/html\r\n"; $message = view('mail.response',['qs' => $qs,'info' => $info, 'comment' => $res->comment])->render(); try { $emailResponse = mail($to, $subject, $message, $headers); if ($emailResponse) { // Email sent successfully $this->emailResponseManagement($user->id, $res->id, $request->email, NOW(), 1); return 1; } else { // Email failed to send $this->emailResponseManagement($user->id, $res->id, $request->email, NOW(), 0); return 0; } } catch (\Exception $e) { // Handle the exception $errorMessage = $e->getMessage(); $this->emailResponseManagement($user->id, $res->id, $request->email, NOW(), 0); return 0; } } }Http/Controllers/AuthController.php000064400000155154150247674230013474 0ustar00auth = new ModelsAuth; $this->quest = new Questions; $this->tmp = new Template; $this->sys = new System; $this->qst = new Questionnaire; $this->ans = new Answer; $this->user = new User; } public function disclaimer(){ $page_title = "Disclaimer"; return view('admin.disclaimer.index')->with(['page_title'=>$page_title]); } public function updateDisclaimer(Request $request){ DB::table('disclaimer')->where('id',1) ->update([ 'content' => $request->disclaimer ]); return response()->json(['message'=>"Success"],200); } public function getCompany(Request $request){ $data = []; $term = $request->search; $response = DB::table('companies') ->where(function($query) use ($term){ $query->orWhere('comp_name', 'like', '%'.$term.'%') ->orWhere('comp_code','like',''.$term.''); }) ->get(); foreach($response as $item){ $data['results'][] = [ 'id' => $item->id, 'text' => $item->comp_name . "( " .$item->comp_code .")", ]; }; return response()->json($data); } public function roles(){ $page_title = "User Management"; return view('admin.user_management.roles')->with(['page_title' => $page_title]); } public function fetchRoles(Request $request){ $array_data['search_keyword'] = $request->search['value']; if(empty($request->search_type)){ $array_data['search_type'] = ""; } else { $array_data['search_type'] = json_decode($request->search_type,true)[0]; } $array_data['sort'] = $request->order[0]['dir']; $array_data['order'] = $request->columns[$request->order[0]['column']]['data']; $array_data['offset'] = $request->start; $array_data['limit'] = $request->length; $array_data['offset_limit'] = " LIMIT {$array_data['offset']},{$array_data['limit']}"; $array_data['sort'] = " ORDER BY {$array_data['order']} {$array_data['sort']} "; $array_data['search'] = ""; if (!empty($array_data['search_keyword'])) { switch ($array_data['search_type']) { case "ID": $array_data['search'] = " AND id = {$array_data['search_keyword']} "; break; } } $array_data['where'] = ""; $data = $request->data; if(!empty($data['active'])){ $array_data['where'] .= " AND active = {$data['active']} "; } $results = $this->auth->getRoles($array_data); $result['data'] = array(); foreach($results as $row){ $result['data'][] = array( "id" => $row->id, "name" => $row->name, "title" => $row->title ); } $result['draw'] = $request->draw; $result['recordsTotal'] = $this->auth->getRolesCount($array_data)[0]->Count; $result['recordsFiltered'] = $this->auth->getRolesFilteredCount($array_data)[0]->FilteredCount; return response()->json($result); } public function addRole(){ $page_title = "Create Role"; return view('admin.user_management.add_role')->with(['page_title'=>$page_title]); } public function addNewRole(Request $request){ // dd($request->all()); $role = Bouncer::role()->firstOrCreate([ 'name' => Str::slug($request->name,'-'), 'title' => $request->title, // 'status' => $request->stat ]); if($role){ $selectedAbilities = $request->abilities; $abilities = []; foreach($selectedAbilities as $ability){ $abilities[] = $ability['nodeId']; } $role->allow($abilities); // if($request->stat == 1){ // $role->status = 1; // $role->save(); // } return response()->json(['message'=>"Success"],201); } } public function editRole($id){ $role = Bouncer::role()->where('id',$id)->firstOrFail(); $page_title = "Edit ".$role->title; return view('admin.user_management.edit_role')->with(['page_title'=>$page_title]); } public function fetchUsers(Request $request){ $array_data['search_keyword'] = $request->search['value']; if(empty($request->search_type)){ $array_data['search_type'] = ""; } else { $array_data['search_type'] = json_decode($request->search_type,true)[0]; } $array_data['sort'] = $request->order[0]['dir']; $array_data['order'] = $request->columns[$request->order[0]['column']]['data']; $array_data['offset'] = $request->start; $array_data['limit'] = $request->length; $array_data['offset_limit'] = " LIMIT {$array_data['offset']},{$array_data['limit']}"; $array_data['sort'] = " ORDER BY {$array_data['order']} {$array_data['sort']} "; $array_data['search'] = ""; if (!empty($array_data['search_keyword'])) { switch ($array_data['search_type']) { case "ID": $array_data['search'] = " AND id = {$array_data['search_keyword']} "; break; } } $array_data['where'] = ""; $data = $request->data; if(!empty($data['active'])){ $array_data['where'] .= " AND active = {$data['active']} "; } $results = $this->user->getUsers($array_data); $result['data'] = array(); foreach($results as $row){ $result['data'][] = array( "id" => $row->id, "name" => $row->f_name . " " . $row->l_name, ); } $result['draw'] = $request->draw; $result['recordsTotal'] = $this->user->getUsersCount($array_data)[0]->Count; $result['recordsFiltered'] = $this->user->getUsersFilteredCount($array_data)[0]->FilteredCount; return response()->json($result); } public function userIndex(){ if(Bouncer::can('update-user')){ $page_title = "User Access Management"; return view('admin.user_management.user_management')->with(['page_title' => $page_title]); } else { abort(403,'Unauthorized'); } } public function system_setup(){ return view('admin.user_management.system_setup')->with(['page_title'=>"System Setup"]); } public function email_response(){ return view('admin.user_management.email_responses')->with(['page_title'=>"Email Responses"]); } public function userEdit($id){ if(Bouncer::can('update-user')){ $name = User::where('id',$id)->first(); $page_title = $name->f_name . " " . $name->l_name; return view('admin.user_management.edit_user')->with(['page_title' => $page_title]); } else { abort(403,'Unauthorized'); } } public function getRole(){ $role = Roles::get(); // dd($role); } public function getAbilities($id){ $role = Bouncer::role()->where('id', $id)->firstOrFail(); $abilities = $role->getAbilities()->pluck('title'); $availableAbilities = Ability::whereNot('name','*')->get(); foreach($availableAbilities as $row){ $formattedAbility[] = [ 'id' => $row->id, 'text' => $row->title ]; } return response()->json(['abilities'=>$abilities,'availableAbilities'=>$formattedAbility]); } public function getAllAbilities(){ $abilities = Ability::get(); foreach($abilities as $item){ $formattedAbilities[] = [ 'id' => $item->id, 'text' => $item->title ]; } return response()->json(['abilities'=>$formattedAbilities]); } public function assignRoleToUser($id){ $usersCollection = []; $userWithRole = []; $role = Bouncer::role()->where('id', $id)->firstOrFail(); $title_page = "Assign ". $role->title; $usersWithRole = User::whereHas('roles', function ($query) use ($id) { $query->where('role_id', $id); })->get(); foreach($usersWithRole as $user){ $userWithRole[] = [ 'id' => $user->id, 'text'=> $user->f_name . " " . $user->l_name ]; } $users = User::select('id',DB::raw('concat(`f_name`," ",`l_name`) as name')) ->where('type',"!=","ratee")->get(); foreach($users as $user){ $usersCollection[] = [ 'id' => $user->id, 'text'=>$user->name ]; } return view('admin.user_management.assign_role')->with(['page_title'=>$title_page,'usersWithRole'=>$userWithRole,'users'=>$usersCollection]); } // public function updateUserAbilities(Request $request){ // $selectedAbilities = $request->abilities; // $user = User::find($request->id); // // $user->type = "admin"; // Bouncer::sync($user)->abilities([]); // foreach($selectedAbilities as $ability){ // Bouncer::allow($user)->to(strtolower(str_replace(' ','-', $ability['nodeText']))); // } // $user->save(); // return response()->json(['message'=>'success']); // } public function updateRoleAbilities(Request $request){ $abilities = $request->input('abilities'); if (!$abilities || !is_array($abilities) || empty($abilities)) { return response()->json(['message' => "Please select at least one ability"], 400); } $role = Bouncer::role()->where('id', $request->id)->first(); if (!$role) { return response()->json(['message' => "Role not found"], 404); } // Reset existing abilities // Bouncer::disallow($role)->everything(); $role->abilities()->detach(); // dd($role->getAbilities()); // Extract ability IDs $abilityIds = array_column($abilities, 'nodeId'); // Allow selected abilities $role->allow($abilityIds); return response()->json(['message' => 'Abilities updated successfully']); // if(!($request->abilities)){ // return response()->json(['message'=>"Please Select at least one ability"],403); // } // $role = Bouncer::role()->where('id',$request->id)->firstOrFail(); // if($role){ // $bouncer = Bouncer::disallow($role)->everything(); // } // $selectedAbilities = $request->abilities; // $abilities = []; // foreach($selectedAbilities as $ability){ // $abilities[] = $ability['nodeId']; // } // $role->allow($abilities); // return response()->json(['message'=>'success']); } public function updateUserRole(Request $request, $id){ $role = Roles::findOrFail($id); foreach($request->selectedUsers as $user){ $userEntity = User::findOrFail($user['nodeId']); $userEntity->roles()->detach(); // Detach existing roles $userEntity->roles()->attach($role); // Assign the new role to the user } return response()->json(['message'=>"Success"],200); } public function companies(Request $request){ $array_data['search_keyword'] = $request->search['value']; if(empty($request->search_type)){ $array_data['search_type'] = ""; } else { $array_data['search_type'] = json_decode($request->search_type,true)[0]; } // dd($array_data['search_type']); $array_data['sort'] = $request->order[0]['dir']; $array_data['order'] = $request->columns[$request->order[0]['column']]['data']; $array_data['offset'] = $request->start; $array_data['limit'] = $request->length; $array_data['offset_limit'] = " LIMIT {$array_data['offset']},{$array_data['limit']}"; $array_data['sort'] = " ORDER BY {$array_data['order']} {$array_data['sort']} "; $array_data['search'] = ""; // dd($request->search_type); if (!empty($array_data['search_keyword'])) { // $array_data['search_keyword'] = "1"; // $array_data['search'] = " AND ? "; // } else { switch ($array_data['search_type']) { // case "ID": // $array_data['search'] = " AND id = {$array_data['search_keyword']} "; // break; case "Code": $array_data['search'] = " AND comp_code LIKE '%{$array_data['search_keyword']}%' "; break; case "Company": $array_data['search'] = " AND comp_name LIKE '%{$array_data['search_keyword']}%' "; break; } } // dd($array_data['search']); $array_data['where'] = ""; $data = $request->data; if(!empty($data['active'])){ $array_data['where'] .= " AND active = {$data['active']} "; } $results = $this->auth->getCompanies($array_data); // dd($results); $result['data'] = array(); foreach($results as $row){ // dd($row); $result['data'][] = array( "id" => $row->id, "code" => $row->comp_code, "name" => $row->comp_name ); } // dd($system); $result['draw'] = $request->draw; $result['recordsTotal'] = $this->auth->getCompaniesCount($array_data)[0]->Count; $result['recordsFiltered'] = $this->auth->getCompaniesFilteredCount($array_data)[0]->FilteredCount; // dd($result); return response()->json($result); } public function dashBoard(){ $questions = $this->auth->getQuestions(); $templates = $this->auth->getTemplates(); $system = $this->auth->getSystems(); $qst = $this->auth->getQuestionnaires(); $devices = DB::table('device_access') ->first(); $rating = []; $res = []; $conditions = [ ['status',"=",1], ['active',"=",1] ]; $page_title = "Home"; // dd($topThreePerGroup); return view('index')->with(['questions'=>$questions,'templates'=>$templates,'systems'=>$system, 'qst'=>$qst, 'devices' => $devices, 'page_title' => $page_title]); } // public function default(){ // $averages = DB::table('answers') // ->select('tmpt_id','syst_id',DB::raw('AVG(JSON_EXTRACT(rating, "$[0]")) as average_rating')) // ->groupBy('syst_id','tmpt_id') // ->get(); // $data = []; // foreach($averages as $row){ // $templateTitle = Template::select('title')->where('id',$row->tmpt_id)->first(); // $systemTitle = System::select('system_name')->where('id',$row->syst_id)->first(); // $data['data'][] = [ // "template" => $templateTitle->title, // "system" => $systemTitle->system_name, // "average" => $row->average_rating // ]; // } // $groups = collect($data['data'])->groupBy('template'); // $topFivePerTemplate = []; // foreach ($groups as $template => $group) { // $topFive = $group->sortByDesc('average')->take(5)->shuffle()->toArray(); // $topFivePerTemplate[$template] = $topFive; // } // return response()->json($topFivePerTemplate); // } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // } /** * Display the specified resource. * * @param \App\Models\Auth $auth * @return \Illuminate\Http\Response */ public function show(Request $request) { // dd($request->all()); $start = null; $end = null; switch ($request->start_date) { case "weekly": $start = Carbon::now()->subWeek(1); $end = Carbon::now(); break; case "monthly": $start = Carbon::now()->subMonth(1); $end = Carbon::now(); break; case "yearly": $start = Carbon::now()->subYear(1); $end = Carbon::now(); break; default: $start = $request->start_date; $end = $request->end_date; break; } $id = $request->id; if(!($request->start_date) || !($request->end_date)){ // $start = $request->start_date; // $end = $request->end_date; // } else { $start = "1990-01-01"; $end = Carbon::now(); } // dd([$start,$end]); if(empty($id)){ $record = Template::inRandomOrder()->first(); $id = $record->id; } $averages = DB::table('answers') ->select('tmpt_id','syst_id',DB::raw('AVG(JSON_EXTRACT(rating, "$[0]")) as average_rating')) ->where('tmpt_id',"=",$id) ->whereBetween('created_at',[$start,$end]) ->groupBy('syst_id','tmpt_id') ->get(); $data = []; foreach($averages as $row){ $templateTitle = Template::select('title')->where('id',$row->tmpt_id)->first(); $systemTitle = System::select('system_name')->where('id',$row->syst_id)->first(); $data['data'][] = [ "template" => $templateTitle->title, "system" => $systemTitle->system_name, "average" => $row->average_rating ]; } $groups = collect($data['data'])->groupBy('template'); // dd($groups); // $topThreePerGroup = collect(); // foreach ($groups as $template => $group) { // $topThree = $group->sortByDesc('average')->take(5)->shuffle(); // $topThreePerGroup = $topThreePerGroup->merge($topThree); // } // $topThreePerGroup = $topThreePerGroup->toArray(); $topFivePerTemplate = []; foreach ($groups as $template => $group) { $topFive = $group->sortByDesc('average')->take(5)->shuffle()->toArray(); $topFivePerTemplate['result'] = $topFive; } $respondents = $this->getRespondents($id); $respondentsPerCompany = $this->getRespondentsPerCompany($id); // dd($respondentsPerCompany); return response()->json(['topFivePerTemplate' => $topFivePerTemplate, 'respondents' => $respondents, 'perCompany'=>$respondentsPerCompany]); } // public function passId($id){ // return $id; // } public function getRespondents($id){ $count = []; $data = DB::table('answers') ->select('syst_id', DB::raw('count(distinct user_id) as count')) ->where('tmpt_id',$id) ->groupBy('syst_id') ->get(); // dd($data->syst_id); foreach($data as $row){ $sys = System::select('system_name')->where('id',$row->syst_id)->first(); $count[] = [ 'system' => $sys->system_name, 'respondents' => $row->count ]; } return $count; } public function getRespondentsPerCompany($id){ $count = []; $data = DB::table('answers') ->select('companies.comp_code', DB::raw('count(distinct user_id) as count')) ->join('users','answers.user_id',"=",'users.id') ->join('companies','users.comp_id',"=",'companies.id') ->where('tmpt_id',$id) ->groupBy('companies.comp_code') ->get(); // dd($data); // return $data; foreach($data as $row){ $count[] = [ 'company' => $row->comp_code, 'respondents' => $row->count ]; } return $count; } /** * Show the form for editing the specified resource. * * @param \App\Models\Auth $auth * @return \Illuminate\Http\Response */ public function edit(Auth $auth) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\Auth $auth * @return \Illuminate\Http\Response */ public function update(Request $request, Auth $auth) { // } /** * Remove the specified resource from storage. * * @param \App\Models\Auth $auth * @return \Illuminate\Http\Response */ public function destroy(Auth $auth) { // } // public function login(Request $request){ // $request->validate([ // 'email' => 'required', // 'password' => 'required' // ]); // $credentials = $request->only('email','password'); // if(Auth::attempt($credentials)){ // return response()->json(["message"=>"success"],200); // } // return redirect('signup')->withSuccess('Data not valid'); // } public function login(Request $request){ $user = null; $request->validate([ 'email' => 'required', 'password' => 'required' ]); $url = 'https://autohub.ph/connect/api/v1/asa/api.php'; $parameters = array( 'key'=>"99797807845605376", 'username' => $request->email, 'password'=>$request->password, ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parameters)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $op = curl_exec ($ch); $err = curl_error($ch); //if you need curl_close ($ch); $response = json_decode($op,true); // dd($response); if((!$response) || $response['status'] != 1){ $info = User::where('asa_id',"=",$request->email)->first(); if($info && password_verify($request->password,$info->password)){ Auth::login($info); $array_data = [ "id" => $info->id, "action" => "login", "message" => $info->id . " " . "has logged in." ]; $this->auditTrail($array_data); return response()->json(['message'=>"Success"]); } else { abort(419,"Invalid Credentials"); } } else { $user = User::where('asa_id',"=",$response['employee_id'])->first(); } if($user){ $user->update( [ 'f_name' => $response['u_fname'], 'l_name' => $response['u_lname'], 'email' => $response['email'], 'position' => $response['u_position'], 'password' => bcrypt($request->password) ] ); } else { $user = new User; $user->asa_id = $response['employee_id']; $user->f_name = $response['u_fname']; $user->l_name = $response['u_lname']; $user->email = $response['email']; $user->password = bcrypt($request->password); $user->type = "admin"; $user->save(); } $array_data = [ "id" => $user->id, "action" => "login", "message" => $user->id . " has logged in." ]; $this->auditTrail($array_data); Auth::login($user); return response()->json(["message"=>$user]); } public function register(Request $request){ $validator = Validator::make($request->all(),[ 'f_name' => ['required'], 'l_name' => ['required'], 'email' => ['required','email','unique:App\Models\User,email','ends_with:autohubgroup.com','regex:/^(?!test|t3st)[a-zA-Z0-9._-]+@/',], 'password' => 'required|confirmed|min:8', 'comp_id' => 'required' ],[ 'f_name.required' => "First Name is required", // 'f_name.regex' => "First Name is invalid", 'l_name.required' => "Last Name is required", // 'l_name.regex' => "Last Name is invalid" ]); if ($validator->passes()) { $user = new User(); $user->f_name = ucfirst(strtolower($request->f_name)); $user->l_name = ucfirst(strtolower($request->l_name)); $user->email = $request->email; $user->password = bcrypt($request->password); $user->type = "admin"; $user->comp_id = $request->comp_id; $user->save(); Auth::login($user); return response()->json(["message"=>"Success"],200); } return response()->json(["message"=>$validator->errors()],500); } public function importComp(){ $url = "https://autohub.ph/connect/api/v1/asa/api.php"; $params = [ 'key' => ' 99799116300681217', ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $op = curl_exec ($ch); $err = curl_error($ch); //if you need curl_close ($ch); $response = json_decode($op,true); $inserted = 0; $ignored = 0; foreach($response as $item){ $result = DB::table('companies')->insertOrIgnore([ 'id' => $item['comp_id'], 'comp_code' => $item['comp_code'], 'comp_name' => $item['comp_name'], 'created_at' => NOW(), 'active' => $item['comp_status'], 'status' => $item['comp_status'], ]); if($result){ $inserted++; }else{ $ignored++; } } if($inserted > 0){ return response()->json(['message' => $inserted.' rows inserted.']); }else{ return response()->json(['message' => 'Records up to date. '.$ignored.' rows ignored.']); } } public function customLogout(Request $request){ $user = Auth::user(); // dd($user); if($user){ Auth::logout($user); Session::invalidate(); Session::flush(); return redirect('/'); } } public function reportDashboard(){ return view('admin.reports.blank'); } public function qstDashboard(){ return view('admin.reports.qst_masterfile'); } public function qstnDashboard(){ return view('admin.reports.qstn_masterfile'); } public function avgperQstDashboard(){ return view('admin.reports.avg_per_qstn'); } public function qsttmpDashboard(){ return view('admin.reports.qstn_tmp_masterfile'); } public function sysDashboard(){ return view('admin.reports.sys_masterfile'); } public function tmpDashboard(){ return view('admin.reports.tmp_masterfile'); } public function tmpqstnDashboard(){ return view('admin.reports.tmpqstn_masterfile'); } public function rvwDashboard(){ return view('admin.reports.reviews'); } public function countSystem(){ return view('admin.reports.count_per_system'); } public function commentSummary(){ return view('admin.reports.comment_summary'); } public function qstReport(Request $request){ $array_data['type'] = $request->type; $array_data['search'] = ""; $array_data['where'] = ""; if(!empty($request->from_date) && !empty($request->to_date)){ $from = Carbon::parse($request->from_date); $to = Carbon::parse($request->to_date); $fromdate = $from->toDateString(); $todate = $to->toDateString(); $array_data['where'] .= " AND DATE(`questionnaires`.`created_at`) BETWEEN '$fromdate' AND '$todate' "; } $filter_data = [ $request->from_date ?? "", $request->to_date ?? "", ]; $results = $this->qst->reports($array_data); $response = $this->qst->pdf($results,'view',$filter_data); $pdf = App::make('dompdf.wrapper'); $pdf->loadView('layouts.reports.questionnaire',$response)->setPaper('long','landscape'); switch($array_data['type']){ case('view'): return $pdf->stream(); break; case('pdf'): return $pdf->download("SurveyForm_Masterfile"."-".date('Y-m-d').'.pdf'); break; case('csv'): $this->qst->csv($results); break; } } public function qstnReport(Request $request){ $array_data['type'] = $request->type; $array_data['search'] = ""; $array_data['where'] = ""; if(!empty($request->from_date) && !empty($request->to_date)){ $from = Carbon::parse($request->from_date); $to = Carbon::parse($request->to_date); $fromdate = $from->toDateString(); $todate = $to->toDateString(); $array_data['where'] .= " AND DATE(`created_at`) BETWEEN '$fromdate' AND '$todate' "; } $results = $this->quest->reports($array_data); $response = $this->quest->pdf($results,'view'); $pdf = App::make('dompdf.wrapper'); $pdf->loadView('layouts.reports.questions',$response); switch($array_data['type']){ case('view'): return $pdf->stream(); break; case('pdf'): return $pdf->download("Questions_Masterfile"."-". date('Y-m-d').'.pdf'); break; case('csv'): $this->quest->csv($results); break; } } public function avgPerQuestion(Request $request){ $array_data['type'] = $request->type; $array_data['search'] = ""; $array_data['where'] = ""; // if(empty($request->qst_id)){ // return response()->json(['message'=>'No Questionnaire Chosen!'],403); // } if(!empty($request->from_date) && !empty($request->to_date)){ $from = Carbon::parse($request->from_date); $to = Carbon::parse($request->to_date); $fromdate = $from->toDateString(); $todate = $to->toDateString(); $array_data['where'] .= " AND DATE(`answers`.`created_at`) BETWEEN '$fromdate' AND '$todate' "; } $data = $request->qst_id; // dd($data); if(!empty($data)){ $array_data['where'] .= " AND `answers`.`qstnn_id` = {$data}"; } if(!empty($request->comp_id)){ $array_data['where'] .= " AND `users`.`comp_id` = {$request->comp_id}"; } $comp = DB::table('companies')->where('id',$request->comp_id)->first(); $results = $this->ans->reports($array_data); $result = []; foreach($results as $row){ $qst_ids = json_decode($row->qst_id, true); $question_titles = []; $question_ids = []; foreach($qst_ids as $qst_id){ $question = Questions::select('id','title')->where('id',$qst_id)->first(); $question_ids[] = $question->id; $question_titles[] = $question->title; } $ratings = json_decode($row->rating); $paired_items = []; for ($i=0; $i < count($question_titles) ; $i++) { $paired_items[] = [ 'id' => $question_ids[$i], 'questions' => $question_titles[$i], 'rating' => $ratings[$i], ]; } // $paired_items[] = [ // array_sum($ratings)/count($ratings) // ]; // $result[] = [ // 'user_name' => $row->user_name, // 'template_title' => $row->template_title, // 'system_name' => $row->system_name, // // 'questions' => $question_titles, // 'ratings' => $paired_items, // ]; $paired_items_copy = array_map(function ($item) { return array_merge([], $item); }, $paired_items); $result[] = [ 'user_name' => $row->user_name, 'template_title' => $row->template_title, 'system_name' => $row->system_name, 'ratings' => $paired_items_copy, // Use the copy, not the original array ]; } // Calculate the average rating for each question $questionAverages = []; foreach ($result as $item) { $ratings = $item['ratings']; foreach ($ratings as $rating) { $questionId = $rating['id']; $ratingValue = $rating['rating']; if (!isset($questionAverages[$questionId])) { $questionAverages[$questionId] = [ 'id' => $rating['id'], 'question' => $rating['questions'], 'sum' => 0, 'count' => 0, 'average' => 0, ]; } $questionAverages[$questionId]['sum'] += $ratingValue; $questionAverages[$questionId]['count']++; } } // Calculate the average for each question foreach ($questionAverages as &$average) { $average['average'] = $average['count'] > 0 ? $average['sum'] / $average['count'] : 0; } // dd($questionAverages); // dd($result); $response = $this->ans->avgPerQstpdf($questionAverages,$result,$comp); $pdf = App::make('dompdf.wrapper'); $pdf->loadView('layouts.reports.average_per_question',$response); switch($array_data['type']){ case('view'): return $pdf->stream(); break; case('pdf'): return $pdf->download("Average-Per-Question-Masterfile".date('Y-m-d').'.pdf'); break; case('csv'): $this->ans->avgPerQstcsv($questionAverages,$result,$comp); break; } } public function qstntmpReport(Request $request){ $array_data['type'] = $request->type; $array_data['search'] = ""; $array_data['where'] = ""; if(!empty($request->from_date) && !empty($request->to_date)){ $from = Carbon::parse($request->from_date); $to = Carbon::parse($request->to_date); $fromdate = $from->toDateString(); $todate = $to->toDateString(); $array_data['where'] .= " AND DATE(`created_at`) BETWEEN '$fromdate' AND '$todate' "; } $results = $this->quest->reports($array_data); // Loop through each question // foreach($results as $question) { // // Retrieve the template titles that are related to this question // $pattern = '/(?<=\")(\d+)(?=\")/'; // // Get the template titles for this question // $templateTitles = Template::select('title') // ->whereRaw('JSON_CONTAINS(q_id, \'["' . $question->id . '"]\')') // ->where('status',1) // ->pluck('title') // ->toArray(); // // Add the template titles to the question object // $question->templateTitles = $templateTitles; // } // dd($results); $response = $this->quest->pdf2($results,'view'); $pdf = App::make('dompdf.wrapper'); $pdf->loadView('layouts.reports.questions_template',$response); switch($array_data['type']){ case('view'): return $pdf->stream(); break; case('pdf'): return $pdf->download("Questions_per_Template_Masterfile"."-". date('Y-m-d').'.pdf'); break; case('csv'): $this->quest->csv2($results); break; } } public function sysReport(Request $request){ $array_data['type'] = $request->type; $array_data['search'] = ""; $array_data['where'] = ""; if(!empty($request->from_date) && !empty($request->to_date)){ $from = Carbon::parse($request->from_date); $to = Carbon::parse($request->to_date); $fromdate = $from->toDateString(); $todate = $to->toDateString(); $array_data['where'] .= " AND DATE(`created_at`) BETWEEN '$fromdate' AND '$todate' "; } $results = $this->sys->reports($array_data); $response = $this->sys->pdf($results); $pdf = App::make('dompdf.wrapper'); $pdf->loadView('layouts.reports.systems',$response); switch($array_data['type']){ case('view'): return $pdf->stream(); break; case('pdf'): return $pdf->download("Systems_Masterfile"."-". date('Y-m-d').'.pdf'); break; case('csv'): $this->sys->csv($results); break; } } public function tmpReport(Request $request){ // dd($request->all()); $array_data['type'] = $request->type; $array_data['search'] = ""; $array_data['where'] = ""; if(!empty($request->from_date) && !empty($request->to_date)){ $from = Carbon::parse($request->from_date); $to = Carbon::parse($request->to_date); $fromdate = $from->toDateString(); $todate = $to->toDateString(); $array_data['where'] .= " AND DATE(`created_at`) BETWEEN '$fromdate' AND '$todate' "; } $results = $this->tmp->reports($array_data); $response = $this->tmp->pdf($results); $pdf = App::make('dompdf.wrapper'); $pdf->loadView('layouts.reports.templates',$response); switch($array_data['type']){ case('view'): return $pdf->stream(); break; case('pdf'): return $pdf->download("Templates_Masterfile." . date('Y-m-d H-i-sA').'.pdf'); break; case('csv'): $this->tmp->csv($results); break; } } public function tmpqstn(Request $request){ $array_data['type'] = $request->type; $array_data['search'] = ""; $array_data['where'] = ""; if(!empty($request->from_date) && !empty($request->to_date)){ $from = Carbon::parse($request->from_date); $to = Carbon::parse($request->to_date); $fromdate = $from->toDateString(); $todate = $to->toDateString(); $array_data['where'] .= " AND DATE(`created_at`) BETWEEN '$fromdate' AND '$todate' "; } $array_data['where'] .= "AND `id` = '{$request->tmp_id}'"; $results = $this->tmp->reportsTmpQstn($array_data); $q_id = json_decode($results[0]->q_id); foreach($q_id as $item){ $questions_title[] = Questions::select('title','created_at')->where('id',$item)->first() ->toArray(); } $results[0]->questions = $questions_title; $response = $this->tmp->pdfTmpQstn($results); $pdf = App::make('dompdf.wrapper'); $pdf->loadView('layouts.reports.templates_questions',$response) ->setPaper('legal','landscape'); switch($array_data['type']){ case('view'): return $pdf->stream(); break; case('pdf'): return $pdf->download("Templates_Masterfile." . date('Y-m-d H-i-sA').'.pdf'); break; case('csv'): $this->tmp->csvTmpQstn($results); break; } } public function rvwReport(Request $request){ $array_data['type'] = $request->type; $array_data['search'] = ""; $array_data['where'] = ""; // if(empty($request->qst_id)){ // return response()->json(['message'=>'No Questionnaire Chosen!'],403); // } if(!empty($request->from_date) && !empty($request->to_date)){ $from = Carbon::parse($request->from_date); $to = Carbon::parse($request->to_date); $fromdate = $from->toDateString(); $todate = $to->toDateString(); $array_data['where'] .= " AND DATE(`answers`.`created_at`) BETWEEN '$fromdate' AND '$todate' "; } $data = $request->qst_id; // dd($data); if(!empty($data)){ $array_data['where'] .= " AND `answers`.`qstnn_id` = {$data}"; } if(!empty($request->comp_id)){ $array_data['where'] .= " AND `users`.`comp_id` = {$request->comp_id}"; } $comp = DB::table('companies')->where('id',$request->comp_id)->first(); $results = $this->ans->reports($array_data); $result = []; foreach($results as $row){ $qst_ids = json_decode($row->qst_id, true); $question_titles = []; $question_ids = []; foreach($qst_ids as $qst_id){ $question = Questions::select('id','title')->where('id',$qst_id)->first(); $question_ids[] = $question->id; $question_titles[] = $question->title; } $ratings = json_decode($row->rating); $paired_items = []; for ($i=0; $i < count($question_titles) ; $i++) { $paired_items[] = [ 'id' => $question_ids[$i], 'questions' => $question_titles[$i], 'rating' => $ratings[$i], ]; } // $paired_items[] = [ // array_sum($ratings)/count($ratings) // ]; $result[] = [ 'user_name' => $row->user_name, 'template_title' => $row->template_title, 'system_name' => $row->system_name, // 'questions' => $question_titles, 'ratings' => $paired_items, ]; } $response = $this->ans->pdf($result,'view',$comp); $pdf = App::make('dompdf.wrapper'); // $optionsArr = [ // 'isHtml5ParserEnabled' => true, // 'isRemoteEnabled' => true, // 'defaultPaperSize' => 'letter', // // add more options here as needed // ]; // $pdf->setOptions($optionsArr); $pdf->loadView('layouts.reports.reviews ',$response); switch($array_data['type']){ case('view'): return $pdf->stream(); break; case('pdf'): return $pdf->download(($result[0]->system_name ?? ' ') . " Respondents_Count-".date('Y-m-d').'.pdf'); break; case('csv'): $this->ans->csv($result); break; } } public function cprReport(Request $request){ $array_data['type'] = $request->type; $array_data['search'] = ""; $array_data['where'] = ""; $array_data['where2'] = ""; if(!empty($request->from_date) && !empty($request->to_date)){ $from = Carbon::parse($request->from_date); $to = Carbon::parse($request->to_date); $fromdate = $from->toDateString(); $todate = $to->toDateString(); $array_data['where'] .= " AND DATE(`ans`.`created_at`) BETWEEN '$fromdate' AND '$todate' "; } $data = $request->qstnn_id; if(!empty($data)){ $array_data['where'] .= " AND `ans`.`qstnn_id` = {$data}"; } $results = $this->ans->reports2($array_data); $id = $array_data['where2'] .= " AND `qstnn`.`id` = {$data}"; $titles = $this->ans->getTitles($id); // dd($titles); // dd($results); $newResults = array(); foreach($results as $row){ $ave = collect(json_decode($row->average)); $average = $ave->avg(); $newResults[] = [ 'user_name' => $row->user_name, 'template_title' => $row->title, 'system_name' => $row->system_name, 'rating' => round($average) ]; } $response = $this->ans->pdf2($newResults,$titles); $pdf = App::make('dompdf.wrapper'); $pdf->loadView('layouts.reports.counts',$response); switch($array_data['type']){ case('view'): return $pdf->stream(); break; case('pdf'): return $pdf->download(($results[0]->system_name ?? ' ') . " Respondents_Count-".date('Y-m-d').'.pdf'); break; case('csv'): $this->ans->csv2($results); break; } } public function commentsReport(Request $request){ // dd($request->all()); $array_data['type'] = $request->type; $array_data['search'] = ""; $array_data['where'] = ""; $array_data['where2'] = ""; if(!empty($request->from_date) && !empty($request->to_date)){ $from = Carbon::parse($request->from_date); $to = Carbon::parse($request->to_date); $fromdate = $from->toDateString(); $todate = $to->toDateString(); $array_data['where'] .= " AND DATE(`ans`.`created_at`) BETWEEN '$fromdate' AND '$todate' "; } $data = $request->qstnn_id; if(!empty($data)){ $array_data['where'] .= " AND ans.qstnn_id = {$data}"; } $results = $this->ans->reports3($array_data); $id = $array_data['where2'] .= " AND `qstnn`.`id` = {$data}"; $titles = $this->ans->getTitles($id); $pdfResult = []; foreach($results as $row){ $pdfResult[] = [ 'user_name' => $row->user_name, 'template_title' => $row->title, 'system_name' => $row->system_name, 'comment' => $row->comment ]; } $response = $this->ans->pdf3($pdfResult, $titles); $pdf = App::make('dompdf.wrapper'); $pdf->loadView('layouts.reports.comment_summary',$response); switch($array_data['type']){ case('view'): return $pdf->stream(); break; case('pdf'): return $pdf->download($titles[0]->system_name . "Comment_Summary-".date('Y-m-d').'.pdf'); break; case('csv'): $this->ans->csv3($results, $titles); break; } } public function fetchQst(){ $qst = Questionnaire::where([['status',"=",1],['active',"=",1]])->get(); $data['results'] = []; foreach($qst as $row){ $template_name = Template::select('title')->where('id',$row->t_id)->first(); $system_name = System::select('system_name')->where('id',$row->s_id)->first(); $data['results'][] = [ "id" => $row->id, "text" => $template_name->title. " " . "(". $system_name->system_name .")" ]; } return response()->json($data); } public function fetchTMP(){ $template = Template::where([['status',"=",1],['active',"=",1]])->get(); // dd($template); $data['results'] = []; foreach($template as $row){ $data['results'][] = [ "id" => $row->id, "text" => $row->title ]; } return response()->json($data); } public function forget(){ return view('auth.forget'); } public function forgetPassword(Request $request){ if($request->validate([ 'email' => ['required','email','ends_with:autohubgroup.com'], ])){ $message = $this->getEmail($request->email); if($message == "success"){ return response()->json(['message' => "we have sent a reset link on your email."],200); } else { return response()->json(['message' => $message],403); } } else { // return response()->json(['error' => $errors], 422); } } public function getEmail($email){ $user = User::where([['email',"=",$email]])->first(); $token = uniqid() . Str::random(8); $link = url('/')."/password-forget/".$email."/".$token; if(!empty($user)){ DB::table('forget_password')->insert([ "email" => $email, "token" => $token, "link" => $link, ]); $data = ['link' => $link]; $to = $email; $subject = "Reset Password"; $headers = "From: Autohub Group of Companies Inc.\r\n"; $headers .= "Content-Type: text/html\r\n"; $message = view('mail.reset-password',$data)->render(); mail($to, $subject, $message, $headers); // Mail::send('mail.reset-password',$data, function($message) use ($email){ // $message->to($email,$email)->subject('Reset Password'); // $message->from('ahub56702@gmail.com','AutoHub Group of Companies, Inc.'); // }); return "success"; } else { return "no user found"; } } public function renderResetPassword(){ $url = url()->full(); $token = explode('/',$url); // dd($token[5]); $check = DB::table('forget_password')->where([['link','like','%'.$url.'%'],['token',$token[5]]])->first(); // dd($check); if(empty($check->token)){ abort(419); } else { $id = User::select('id')->where('email','like','%'.$check->email.'%')->first(); return view('auth.reset-password')->with(['id' => $id]); } } public function resetPassword(Request $request){ $url = $request->url; $token = explode('/',$url); // dd($token[5]); if($request->validate([ 'password' => 'required|confirmed', ])){ User::where('id',$request->id) ->update([ 'password' => bcrypt($request->password) ]); DB::table('forget_password')->where([['link','like','%'.$url.'%'],['token',$token[5]]]) ->update(['token'=>null,'deleted_at' => now()]); return response()->json(['message'=>'Success'],200); } else { return response()->json(['message'=>'Error'],403); } } public function emails(Request $request){ $array_data['search_keyword'] = $request->search['value']; if(empty($request->search_type)){ $array_data['search_type'] = ""; } else { $array_data['search_type'] = json_decode($request->search_type,true)[0]; } $array_data['sort'] = $request->order[0]['dir']; $array_data['order'] = $request->columns[$request->order[0]['column']]['data']; $array_data['offset'] = $request->start; $array_data['limit'] = $request->length; $array_data['offset_limit'] = " LIMIT {$array_data['offset']},{$array_data['limit']}"; $array_data['sort'] = " ORDER BY {$array_data['order']} {$array_data['sort']} "; $array_data['search'] = ""; $array_data['where'] = ""; $data = $request->data; if(($data['status']) !== "NULL"){ $array_data['where'] .= " AND `email_responses`.`status` = {$data['status']} "; } $results = $this->auth->getEmails($array_data); $result['data'] = array(); foreach($results as $row){ $result['data'][] = array( "id" => $row->id, "user_name" => $row->user_name, "email" => $row->email, "created_at" => $row->created_at, "status" => $row->status ); } $result['draw'] = $request->draw; $result['recordsTotal'] = $this->auth->getEmailsCount($array_data)[0]->Count; $result['recordsFiltered'] = $this->auth->getEmailsFilteredCount($array_data)[0]->FilteredCount; return response()->json($result); } public function auditTrail($array_data){ $type = $array_data['id']; $action = $array_data['action']; $message = $array_data['message']; $result = DB::table('audit_trail') ->insert([ 'usr' => $type, 'action' => $message ]); } public function templateSelect2fetchAll(){ $template = DB::table('templates') ->select('id','title')->get(); $data['results'] = []; foreach($template as $row){ $data['results'][] = [ "id" => $row->id, "text" => $row->title ]; } return response()->json($data); } }Http/Controllers/QuestionsController.php000064400000014647150247674230014566 0ustar00question = new Questions(); } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { if(Bouncer::can('view-question')){ $page_title = "Questions"; return view('admin.questions.questions')->with(['page_title' => $page_title]); } else { abort(403,'Unauthorized'); } } public function getQs($val){ return Questions::select('title')->where('id',$val)->get(); } public function fetchall(Request $request){ $array_data['search_keyword'] = $request->search['value']; if(empty($request->search_type)){ $array_data['search_type'] = ""; } else { $array_data['search_type'] = json_decode($request->search_type,true)[0]; } $array_data['sort'] = $request->order[0]['dir']; $array_data['order'] = $request->columns[$request->order[0]['column']]['data']; $array_data['offset'] = $request->start; $array_data['limit'] = $request->length; $array_data['offset_limit'] = " LIMIT {$array_data['offset']},{$array_data['limit']}"; $array_data['sort'] = " ORDER BY {$array_data['order']} {$array_data['sort']} "; $array_data['search'] = ""; if (!empty($array_data['search_keyword'])) { switch ($array_data['search_type']) { // case "ID": // $array_data['search'] = " AND id = {$array_data['search_keyword']} "; // break; case "Question": $array_data['search'] = " AND title LIKE '%{$array_data['search_keyword']}%' "; break; } } $array_data['where'] = ""; $data = $request->data; if(!empty($data['active'])){ $array_data['where'] .= " AND active = {$data['active']} "; } $results = $this->question->getQuestions($array_data); $result['data'] = array(); foreach($results as $row){ $result['data'][] = array( "id" => $row->id, "title" => $row->title ); } $result['draw'] = $request->draw; $result['recordsTotal'] = $this->question->getQuestionsCount($array_data)[0]->Count; $result['recordsFiltered'] = $this->question->getQuestionsFilteredCount($array_data)[0]->FilteredCount; return response()->json($result); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // dd($request->all()); $request->validate([ 'title' => 'required' ],[ 'title.required'=>"Please provide a question title" ]); $result = $this->question; $result->title = $request->title; $result->active = 1; $result->status = 1; $result->save(); $array_data = [ "id" => Auth::user()->id, "action" => "create", "message" => Auth::user()->id . " has created a question." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(["message"=>"Success","result"=>$result],200); } /** * Display the specified resource. * * @param \App\Models\Questions $questions * @return \Illuminate\Http\Response */ public function show(Questions $questions) { } /** * Show the form for editing the specified resource. * * @param \App\Models\Questions $questions * @return \Illuminate\Http\Response */ public function edit(Request $request) { $result = Questions::findOrFail($request->id); return response()->json($result); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\Questions $questions * @return \Illuminate\Http\Response */ public function update(Request $request) { $result = Questions::where('id',$request->id) ->update([ 'title' => $request->title ]); $array_data = [ "id" => Auth::user()->id, "action" => "updated", "message" => Auth::user()->id . " has updated a question." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(["message"=>"Success", "result"=>$result]); } /** * Remove the specified resource from storage. * * @param \App\Models\Questions $questions * @return \Illuminate\Http\Response */ public function destroy(Request $request) { $res = Template::where('q_id', 'like', '%"'.$request->id.'"%')->count(); if($res > 0){ return response()->json(['message'=>"This question is already in use. Deletion is not possible"], 400); } else { $result = Questions::where('id',$request->id) ->update([ 'active' => null, 'status' => null ]); // foreach($res as $row){ // $data = json_decode($row->q_id); // $index = array_search($result, $data); // if($index !== false){ // array_splice($data, $index, 1); // $row->q_id = json_encode($data); // $row->save(); // } // } $array_data = [ "id" => Auth::user()->id, "action" => "destroy", "message" => Auth::user()->id . " has deleted a question." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(["message"=>"Success", "result"=>$result]); } } }Http/Controllers/SystemController.php000064400000015143150247674230014050 0ustar00system = new System(); } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { if(Bouncer::can('view-system')){ $page_title = "Systems"; return view('admin.systems.system')->with(['page_title' => $page_title]); } else { abort(403,'Unauthorized'); } } public function fetchall(Request $request){ $array_data['search_keyword'] = $request->search['value']; if(empty($request->search_type)){ $array_data['search_type'] = ""; } else { $array_data['search_type'] = json_decode($request->search_type,true)[0]; } // dd($array_data['search_type']); $array_data['sort'] = $request->order[0]['dir']; $array_data['order'] = $request->columns[$request->order[0]['column']]['data']; $array_data['offset'] = $request->start; $array_data['limit'] = $request->length; $array_data['offset_limit'] = " LIMIT {$array_data['offset']},{$array_data['limit']}"; $array_data['sort'] = " ORDER BY {$array_data['order']} {$array_data['sort']} "; $array_data['search'] = ""; // dd($request->search_type); if (!empty($array_data['search_keyword'])) { // $array_data['search_keyword'] = "1"; // $array_data['search'] = " AND ? "; // } else { switch ($array_data['search_type']) { case "ID": $array_data['search'] = " AND id = {$array_data['search_keyword']} "; break; case "System Name": $array_data['search'] = " AND system_name LIKE '%{$array_data['search_keyword']}%' "; break; } } // dd($array_data['search']); $array_data['where'] = ""; $data = $request->data; if(!empty($data['active'])){ $array_data['where'] .= " AND active = {$data['active']} "; } $results = $this->system->getSystems($array_data); // dd($results); $result['data'] = array(); foreach($results as $row){ // dd($row); $result['data'][] = array( "id" => $row->id, "system_name" => $row->system_name ); } // dd($system); $result['draw'] = $request->draw; $result['recordsTotal'] = $this->system->getSystemsCount($array_data)[0]->Count; $result['recordsFiltered'] = $this->system->getSystemsFilteredCount($array_data)[0]->FilteredCount; // dd($result); return response()->json($result); } public function select2fetchAll(){ $system = System::select('id','system_name')->get(); $data['results'] = []; foreach($system as $row){ $data['results'][] = [ "id" => $row->id, "text" => $row->system_name ]; } return response()->json($data); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $request->validate([ 'name' => 'required' ],[ 'name.required' => "Please provide a System Name" ]); $result = $this->system; $result->system_name = $request->name; $result->active = 1; $result->status = 1; $result->save(); $array_data = [ "id" => Auth::user()->id, "action" => "create", "message" => Auth::user()->id . " has created a system." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(["message"=>"Success","result"=>$result],200); } /** * Display the specified resource. * * @param \App\Models\System $system * @return \Illuminate\Http\Response */ public function show(System $system) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\System $system * @return \Illuminate\Http\Response */ public function edit(Request $request) { $result = System::findOrFail($request->id); return response()->json($result); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\System $system * @return \Illuminate\Http\Response */ public function update(Request $request) { $result = System::where('id',$request->id) ->update([ 'system_name' => $request->name ]); $array_data = [ "id" => Auth::user()->id, "action" => "update", "message" => Auth::user()->id . " has updated a system." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(["message"=>"Success", "result"=>$result]); } /** * Remove the specified resource from storage. * * @param \App\Models\System $system * @return \Illuminate\Http\Response */ public function destroy(Request $request) { $systemInTemplate = Questionnaire::where('s_id',$request->id)->count(); if($systemInTemplate > 0){ return response()->json(['message'=>"The system is already in use. Deletion is not possible"], 400); } else { $result = System::where('id',$request->id) ->update([ 'active' => null, 'status' => null ]); $array_data = [ "id" => Auth::user()->id, "action" => "destroy", "message" => Auth::user()->id . " has deleted a system." ]; $result = (new AuthController)->auditTrail($array_data); return response()->json(["message"=>"Success", "result"=>$result]); } } } Exceptions/Handler.php000064400000002032150247674230010762 0ustar00, \Psr\Log\LogLevel::*> */ protected $levels = [ // ]; /** * A list of the exception types that are not reported. * * @var array> */ protected $dontReport = [ // ]; /** * A list of the inputs that are never flashed to the session on validation exceptions. * * @var array */ protected $dontFlash = [ 'current_password', 'password', 'password_confirmation', ]; /** * Register the exception handling callbacks for the application. * * @return void */ public function register() { $this->reportable(function (Throwable $e) { // }); } } Models/System.php000064400000006735150247674230010011 0ustar00getSystemQuery(), $fields, $array_data['search'], $array_data['where'], $array_data['sort'], $array_data['offset_limit'] ); return DB::select($query); } public function getSystemsCount($array_data){ $fields = " COUNT(1) as Count "; $query = sprintf( $this->getSystemQuery(), $fields, '', $array_data['where'], '', '' ); return DB::select($query); } public function getSystemsFilteredCount($array_data){ $fields = " COUNT(1) as FilteredCount "; $query = sprintf( $this->getSystemQuery(), $fields, $array_data['search'], $array_data['where'], '', '' ); return DB::select($query); } public function getSystemsReportQuery(){ return "SELECT %s FROM systems WHERE 1 AND `status` = 1 AND active = 1 %s "; } public function reports($array_data){ $fields = " system_name, DATE_FORMAT(`created_at`,'%M %e, %Y') as created_at "; $query = sprintf( $this->getSystemsReportQuery(), $fields, $array_data['where'], ); // dd($query); return DB::select($query); } public function pdf($results){ $data = []; $grpData = new \stdClass(); $grpData->list = $results; $grpData->total = sizeOf($results); array_push($data, $grpData); $report_title = "Systems Masterfile"; $reportData = [ 'data' => $data, 'webpage_title' => "Systems Report", 'report_title' => $report_title, 'table_headers' => ['No.','System Name', 'Date Created'], 'table_body' => ['system_name','created_at'] ]; return $reportData; } public function csv($results){ // dd($results); $systems = []; $systems[] = ['No.','System Name', 'Date Created']; $inc = 0; foreach($results as $row){ $systems[] = [ $inc+=1, $row->system_name, $row->created_at ]; } $filename = "Systems_Masterfile"."-". date('Y-m-d').'.csv'; header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$filename.'"'); $f = fopen('php://output', 'wb'); if ($f === false) { die('Error opening the file ' .$filename); } if(empty($systems[1])){ $arr = [ "No data to show" ]; fputcsv($f, $arr); } else { foreach ($systems as $row) { fputcsv($f, $row, ','); } } fclose($f); } } Models/Questionnaire.php000064400000012211150247674230011335 0ustar00getQuestionnaireQuery(), $fields, $array_data['search'], $array_data['where'], $array_data['sort'], $array_data['offset_limit'] ); // dd($query); return DB::select($query); } public function getQuestionnairesCount($array_data){ // $fields = " tmp.id "; $fields = " COUNT(1) as Count "; $query = sprintf( $this->getQuestionnaireQuery(), $fields, '', $array_data['where'], '', '' ); //dd($query); // return DB::select("SELECT COUNT(1) as Count FROM (".$query.") foo"); return DB::select($query); } public function getQuestionnairesFilteredCount($array_data){ // $fields = " tmp.id "; $fields = " COUNT(1) as FilteredCount "; $query = sprintf( $this->getQuestionnaireQuery(), $fields, $array_data['search'], $array_data['where'], '', '' ); return DB::select($query); } public function getQuestionnairesReportQuery(){ return "SELECT %s FROM questionnaires INNER JOIN templates ON questionnaires.t_id = templates.id INNER JOIN systems ON questionnaires.s_id = systems.id INNER JOIN links ON templates.id = links.tmp_id AND systems.id = links.sys_id WHERE 1 AND `questionnaires`.`status` = 1 AND questionnaires.active = 1 %s "; } public function reports($array_data){ $fields = " CONCAT(templates.title,' (',JSON_LENGTH(templates.q_id),' question/s)') as title, systems.system_name,questionnaires.*,links.link "; $query = sprintf( $this->getQuestionnairesReportQuery(), $fields, $array_data['where'], ); // dd($query); return DB::select($query); } public function pdf($results, $type, $filter_data){ $data = []; $grpData = new \stdClass(); $grpData->list = $results; $grpData->total = sizeOf($results); array_push($data, $grpData); $report_title = "Survey Form Masterfile"; $reportData = [ 'data' => $data, 'date_from' => $filter_data[0], 'date_to' => $filter_data[1], 'webpage_title' => "Survey Form Report", 'report_title' => $report_title, 'table_headers' => ['No.','Template','System','Date Created','Link','Instruction'], 'table_body' => ['title','system_name','created_at','link','instruction'] ]; return $reportData; } public function csv($results){ $questionnaire = []; $questionnaire[] = ['No.','Template','System','Date Created','Link','Instruction']; $inc = 0; foreach($results as $row){ $questionnaire[] = [ $inc+=1, $row->title, $row->system_name, $row->created_at, $row->link, $row->instruction ]; } $filename = "SurveyForm_Masterfile"."-".date('Y-m-d').'.csv'; // $filename = "Questions_Masterfile"."-". date('Y-m-d').'.csv'; // dd($questions); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$filename.'"'); $f = fopen('php://output', 'wb'); if ($f === false) { die('Error opening the file ' .$filename); } if(empty($questionnaire[1])){ $arr = [ "No data to show" ]; fputcsv($f,$arr); } else { foreach($questionnaire as $row){ fputcsv($f, $row, ','); } } fclose($f); } } Models/Answer.php000064400000033457150247674230007765 0ustar00getQuestionnairesReportQuery(), $fields, $array_data['where'] ); // dd($query); return DB::select($query); } public function countsQuery(){ return "SELECT %s FROM answers `ans` INNER JOIN `systems` `s` on `s`.`id` = `ans`.`syst_id` INNER JOIN `templates` `t` on `t`.`id` = `ans`.`tmpt_id` INNER JOIN `users` `u` on `u`.`id` = `ans`.`user_id` WHERE 1 %s -- GROUP BY qstnn_id, syst_id, tmpt_id, user_name "; } public function reports2($array_data){ // dd($array_data); // $fields = " qstnn_id, syst_id, tmpt_id, CONCAT(users.f_name,' ',users.l_name) as user_name, systems.system_name, templates.title, AVG(SUBSTRING(answers.rating, 2, LENGTH(answers.rating)-2)) as average"; $fields = " `t`.`title`, `s`.`system_name`,CONCAT(`u`.`f_name`,' ',`u`.`l_name`) as `user_name`, `ans`.`rating` as `average`, `ans`.`created_at` "; $query = sprintf( $this->countsQuery(), $fields, $array_data['where'] ); // dd($query); return DB::select($query); } public function commentsQuery(){ return "SELECT %s FROM answers `ans` INNER JOIN `systems` `s` on `s`.`id` = `ans`.`syst_id` INNER JOIN `templates` `t` on `t`.`id` = `ans`.`tmpt_id` INNER JOIN `users` `u` on `u`.`id` = `ans`.`user_id` WHERE 1 %s "; } public function reports3($array_data){ // dd("dito"); $fields = " `t`.`title`, `s`.`system_name`, CONCAT(`u`.`f_name`,' ',`u`.`l_name`) as `user_name`, `ans`.`comment`, `ans`.`created_at` "; $query = sprintf( $this->commentsQuery(), $fields, $array_data['where'] ); return DB::select($query); } public function pdf($results,$type,$comp){ $data = []; $grpData = new \stdClass(); $grpData->list = $results; $grpData->total = sizeOf($results); array_push($data,$grpData); // dd($results[0]['template_title']); $report_title = "Rating Summary"; // ,'Template','System' // ,'template_title','system_name' $reportData = [ 'data' => $data, 'webpage_title' => "Reviews Report", 'company' => $comp->comp_name ?? "", 'template_name' => $results[0]['template_title'] ?? "", 'system_name' => $results[0]['system_name'] ?? "", 'report_title' => $report_title, 'table_headers' => ['No.','User','Response'], 'table_body' => ['user_name'] ]; // dd($data); return $reportData; } public function avgPerQstpdf($results,$result,$comp){ $data = []; // dd($results); $grpData = new \stdClass(); $grpData->list = $results; $grpData->total = sizeOf($results); array_push($data,$grpData); // dd($results[0]['template_title']); $report_title = "Average per Question Summary"; $table_body = []; foreach ($results as $average) { $table_body[] = [ $average['id'], // Question Id $average['question'], // Question $average['count'], // Count number_format($average['average'], 2), // Average ]; } $reportData = [ 'data' => $data, 'webpage_title' => "Reviews Report", 'company' => $comp->comp_name ?? "", 'template_name' => $result[0]['template_title'] ?? "", 'system_name' => $result[0]['system_name'] ?? "", 'report_title' => $report_title, 'table_headers' => ['No.','Question Id', 'Question', 'Count', 'Average'], // 'table_body' => ['id','question','count','average'] 'table_body' => $table_body ]; // dd($reportData); return $reportData; } public function pdf2($results,$titles){ // dd($titles); $data = []; $grpData = new \stdClass(); $grpData->list = $results; $grpData->total = sizeOf($results); array_push($data,$grpData); $report_title = ($results[0]['system_name'] ?? ' ') . " Respondents Count"; $reportData = [ 'data' => $data, 'webpage_title' => "Reviews Report", 'report_title' => $report_title, 'system_name' => $titles[0]->system_name, 'template_name' => $titles[0]->title, 'table_headers' => ['No.','Name','Average'], 'table_body' => ['user_name','rating'] ]; return $reportData; } public function pdf3($results,$titles){ $data = []; $grpData = new \stdClass(); $grpData->list = $results; $grpData->total = sizeOf($results); array_push($data,$grpData); $report_title = ($results[0]['system_name'] ?? ' ') . " Comment Summary Report"; $reportData = [ 'data' => $data, 'webpage_title' => "Comments Summary Report", 'report_title' => $report_title, 'system_name' => $titles[0]->system_name, 'template_name' => $titles[0]->title, 'table_headers' => ['No.','Name','Comment'], 'table_body' => ['user_name','comment'] ]; return $reportData; } // public function csv($result){ // // dd($result); // $inc = 0; // $response = []; // $response[] = [ // 'No.','User','Template Name','System Name', 'Question', 'Rating' // ]; // foreach($result as $key => $row){ // for($i=0; $i < count($row['ratings']); $i++){ // // print_r($row['ratings'][$i]['questions']); // // exit; // $response[] = [ // $inc+=1, // $row['user_name'], // $row['template_title'], // $row['system_name'], // $row['ratings'][$i]['questions'], // $row['ratings'][$i]['rating'] // ]; // } // // foreach($row['ratings'] as $r => $question){ // } // // dd($response); // $file_name = ($result[0]->system_name ?? ' ') . " Respondents_Count-".date('Y-m-d').'.csv'; // // dd($file_name); // header('Content-Type: text/csv'); // header('Content-Disposition: attachment; filename="'.$file_name.'"'); // $f = fopen('php://output', 'wb'); // if($f === false){ // die('Error opening the file '.$file_name); // } // if(empty($response[1])){ // $arr = [ // "No data to show" // ]; // fputcsv($f,$arr); // } else { // foreach($response as $row){ // fputcsv($f, $row, ','); // } // } // fclose($f); // } public function csv($result){ $inc = 0; $response = []; $response[] = [ 'No.','User','Template Name','System Name', 'Question', 'Rating' ]; $totalRatings = 0; $totalCount = 0; foreach($result as $key => $row){ for($i=0; $i < count($row['ratings']); $i++){ $rating = $row['ratings'][$i]['rating']; $totalRatings += $rating; $totalCount++; $response[] = [ $inc+=1, $row['user_name'], $row['template_title'], $row['system_name'], $row['ratings'][$i]['questions'], $rating ]; } } // Calculate average rating $averageRating = ($totalCount > 0) ? ($totalRatings / $totalCount) : 0; // Add row for average rating $response[] = [ '', '', '', '', 'Average Rating', round($averageRating,0) ]; $file_name = ($result[0]->system_name ?? ' ') . " Respondents_Count-".date('Y-m-d').'.csv'; header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$file_name.'"'); $f = fopen('php://output', 'wb'); if($f === false){ die('Error opening the file '.$file_name); } if(empty($response[1])){ $arr = [ "No data to show" ]; fputcsv($f,$arr); } else { foreach($response as $row){ fputcsv($f, $row, ','); } } fclose($f); } public function csv2($results){ // dd($results); $response = []; $response[] = [ 'No.','User','Average' ]; foreach($results as $key => $result){ $ave = json_decode($result->average); $average = array_reduce($ave, function($carry, $number) { return $carry + $number; }, 0) / count($ave); $round = round($average,0); $response[] = [ $key+=1, $result->user_name, $round ]; } $file_name = ($results[0]->system_name ?? ' ') . " Respondents_Count-".date('Y-m-d').'.csv'; header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$file_name.'"'); $f = fopen('php://output', 'wb'); if($f === false){ die('Error opening the file '.$file_name); } if(empty($response[1])){ $arr = [ "No data to show" ]; fputcsv($f,$arr); } else { foreach($response as $row){ fputcsv($f, $row, ','); } } fclose($f); } public function csv3($results, $titles){ $response = []; $response[] = [ 'No.','User','Comment' ]; foreach($results as $key => $row){ $response[] = [ $key+=1, $row->user_name, $row->comment ]; } $file_name = "Comment_Summary-".date('Y-m-d').'.csv'; header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$file_name.'"'); $f = fopen('php://output', 'wb'); if($f === false){ die('Error opening the file '.$file_name); } if(empty($response[1])){ $arr = [ "No data to show" ]; fputcsv($f,$arr); } else { foreach($response as $row){ fputcsv($f, $row, ','); } } fclose($f); } public function avgPerQstcsv($array_data,$result,$comp){ // dd($array_data); $response = []; $response[] = ['No.','Question Id', 'Question', 'Count', 'Average']; $inc = 0; foreach($array_data as $key => $row){ $inc++; $response[] = [ $inc, $row['id'], $row['question'], $row['count'], number_format($row['average'],2), ]; } $file_name = "Average_Per_Question_Summary-".date('Y-m-d').'.csv'; header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$file_name.'"'); $f = fopen('php://output', 'wb'); if($f === false){ die('Error opening the file '.$file_name); } fputcsv($f,["Template Name:","System Name:","Company:"],','); fputcsv($f,[$result[0]['template_title'],$result[0]['system_name'],$comp->comp_name ?? "None"],','); if(empty($response[1])){ $arr = [ "No data to show" ]; fputcsv($f,$arr); } else { foreach($response as $row){ fputcsv($f, $row, ','); } } fclose($f); } } Models/Auth.php000064400000010631150247674230007414 0ustar00getCompanyQuery(), $fields, $array_data['search'], $array_data['where'], $array_data['sort'], $array_data['offset_limit'] ); return DB::select($query); } public function getCompaniesCount($array_data){ $fields = " COUNT(1) as Count "; $query = sprintf( $this->getCompanyQuery(), $fields, '', $array_data['where'], '', '' ); return DB::select($query); } public function getCompaniesFilteredCount($array_data){ $fields = " COUNT(1) as FilteredCount "; $query = sprintf( $this->getCompanyQuery(), $fields, $array_data['search'], $array_data['where'], '', '' ); return DB::select($query); } public function getEmailsQuery(){ return "SELECT %s FROM email_responses INNER JOIN users `u` on `u`.`id` = email_responses.user WHERE 1 %s %s %s %s "; } public function getEmails($array_data){ // dd($array_data); $fields = " `email_responses`.`id`, CONCAT(`u`.`f_name`, ' ', `u`.`l_name`) as `user_name`, `email_responses`.`email`, `email_responses`.`created_at`, `email_responses`.`status` "; $query = sprintf( $this->getEmailsQuery(), $fields, $array_data['search'], $array_data['where'], $array_data['sort'], $array_data['offset_limit'] ); return DB::select($query); } public function getEmailsCount($array_data){ $fields = " COUNT(1) as Count "; $query = sprintf( $this->getEmailsQuery(), $fields, '', $array_data['where'], '', '' ); return DB::select($query); } public function getEmailsFilteredCount($array_data){ $fields = " COUNT(1) as FilteredCount "; $query = sprintf( $this->getEmailsQuery(), $fields, $array_data['search'], $array_data['where'], '', '' ); return DB::select($query); } public function getRolesQuery(){ return "SELECT %s FROM `roles` WHERE 1 %s %s %s %s "; } public function getRoles($array_data){ $fields = " `roles`.`id`, `roles`.`name`, `roles`.`title` "; $query = sprintf( $this->getRolesQuery(), $fields, $array_data['search'], $array_data['where'], $array_data['sort'], $array_data['offset_limit'] ); return DB::select($query); } public function getRolesCount($array_data){ $fields = " COUNT(1) as Count "; $query = sprintf( $this->getRolesQuery(), $fields, '', $array_data['where'], '', '' ); return DB::select($query); } public function getRolesFilteredCount($array_data){ $fields = " COUNT(1) as FilteredCount "; $query = sprintf( $this->getRolesQuery(), $fields, $array_data['search'], $array_data['where'], '', '' ); return DB::select($query); } } Models/Questions.php000064400000013164150247674230010511 0ustar00getQuestionsQuery(), $fields, $array_data['search'], $array_data['where'], $array_data['sort'], $array_data['offset_limit'] ); return DB::select($query); } public function getQuestionsCount($array_data){ $fields = " COUNT(1) as Count "; $query = sprintf( $this->getQuestionsQuery(), $fields, '', $array_data['where'], '', '' ); return DB::select($query); } public function getQuestionsFilteredCount($array_data){ $fields = " COUNT(1) as FilteredCount "; $query = sprintf( $this->getQuestionsQuery(), $fields, $array_data['search'], $array_data['where'], '', '' ); return DB::select($query); } public function getQuestionsReportQuery(){ return "SELECT %s FROM questions WHERE 1 AND `status` = 1 AND active = 1 %s "; } public function reports($array_data){ $fields = " id, title, DATE_FORMAT(`created_at`,'%M %e, %Y') as created_at "; $query = sprintf( $this->getQuestionsReportQuery(), $fields, $array_data['where'], ); // dd($query); return DB::select($query); } public function pdf($results,$type){ $data = []; $grpData = new \stdClass(); $grpData->list = $results; $grpData->total = sizeOf($results); array_push($data, $grpData); $report_title = "Questions Masterfile"; $reportData = [ 'data' => $data, 'webpage_title' => "Questions Report", 'report_title' => $report_title, 'table_headers' => ['No.','Question', 'Date Created'], 'table_body' => ['title','created_at'], // 'img' => $base64 ]; return $reportData; } public function pdf2($results){ $data = []; $grpData = new \stdClass(); $grpData->list = $results; $grpData->total = sizeOf($results); array_push($data, $grpData); $report_title = "Question per Template Masterfile"; $reportData = [ 'data' => $data, 'webpage_title' => "Questions Report", 'report_title' => $report_title, // 'table_headers' => ['No.','Question','Templates', 'Date Created'], // 'table_body' => ['title','templateTitles','created_at'], 'table_headers' => ['No.','Question', 'Date Created'], 'table_body' => ['title','created_at'], // 'img' => $base64 ]; return $reportData; } public function csv($results){ // dd($results); $questions = []; $questions[] = ['No.','Question','Date Created']; $inc = 0; foreach ($results as $row) { $questions[] = [ $inc+=1, $row->title, $row->created_at ]; } $filename = "Questions_Masterfile"."-". date('Y-m-d').'.csv'; // dd($questions); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$filename.'"'); $f = fopen('php://output', 'wb'); if ($f === false) { die('Error opening the file ' .$filename); } if(empty($questions[1])){ $arr = [ "No data to show" ]; fputcsv($f, $arr); } else { foreach ($questions as $row) { fputcsv($f, $row, ','); } } fclose($f); } public function csv2($results){ // dd($results); $questions = []; $questions[] = ['No.','Question Title', 'Template', 'Date Created']; $inc = 0; foreach ($results as $row) { $templateTitles = implode(', ', $row->templateTitles); $questions[] = [ $inc+=1, $row->title, $templateTitles, $row->created_at ]; } $filename = "Questions_per_Template_Masterfile"."-". date('Y-m-d').'.csv'; // dd($questions); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$filename.'"'); $f = fopen('php://output', 'wb'); if ($f === false) { die('Error opening the file ' .$filename); } if(empty($questions[1])){ $arr = [ "No data to show" ]; fputcsv($f, $arr); } else { foreach ($questions as $row) { fputcsv($f, $row, ','); } } fclose($f); } } Models/User.php000064400000004531150247674230007433 0ustar00 */ protected $fillable = [ 'asa_id', 'f_name', 'l_name', 'email', 'password', 'comp_id', 'type' ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ]; public function getUsersQuery(){ $id = Auth::user()->id; return "SELECT %s FROM `users` WHERE 1 AND `id` != $id %s %s %s %s "; } public function getUsers($array_data){ $fields = " `users`.`id`, `users`.`f_name`, `users`.`l_name` "; $query = sprintf( $this->getUsersQuery(), $fields, $array_data['search'], $array_data['where'], $array_data['sort'], $array_data['offset_limit'] ); return DB::select($query); } public function getUsersCount($array_data){ $fields = " COUNT(1) as Count "; $query = sprintf( $this->getUsersQuery(), $fields, '', $array_data['where'], '', '' ); return DB::select($query); } public function getUsersFilteredCount($array_data){ $fields = " COUNT(1) as FilteredCount "; $query = sprintf( $this->getUsersQuery(), $fields, $array_data['search'], $array_data['where'], '', '' ); return DB::select($query); } } Models/Template.php000064400000014267150247674230010277 0ustar00getTemplateQuery(), $fields, $array_data['search'], $array_data['where'], $array_data['sort'], $array_data['offset_limit'] ); return DB::select($query); } public function getTemplatesCount($array_data){ $fields = " COUNT(1) as Count "; $query = sprintf( $this->getTemplateQuery(), $fields, '', $array_data['where'], '', '' ); return DB::select($query); } public function getTemplatesFilteredCount($array_data){ $fields = " COUNT(1) as FilteredCount "; $query = sprintf( $this->getTemplateQuery(), $fields, $array_data['search'], $array_data['where'], '', '' ); return DB::select($query); } public function getTemplatesReportQuery(){ return "SELECT %s FROM templates WHERE 1 AND `status` = 1 AND active = 1 %s "; } public function reports($array_data){ $fields = " * "; $query = sprintf( $this->getTemplatesReportQuery(), $fields, $array_data['where'] ); return DB::select($query); } public function pdf($results){ $data = []; $grpData = new \stdClass(); $grpData->list = $results; $grpData->total = sizeOf($results); array_push($data,$grpData); $report_title = "Templates Masterfile"; $reportData = [ 'data' => $data, 'webpage_title' => "Templates Report", 'report_title' => $report_title, 'table_headers' => ['No.', 'Template Name', 'Date Created'], 'table_body' => ['title','created_at'] ]; return $reportData; } public function csv($results){ $templates = []; $templates[] = ['No.','Title', 'Date Created']; $inc = 0; foreach($results as $row){ $templates[] = [ $inc+=1, $row->title, $row->created_at, ]; } $filename = "Templates_Masterfile." . date('Y-m-d H-i-sA').'.csv'; header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$filename.'"'); $f = fopen('php://output', 'wb'); if ($f === false) { die('Error opening the file ' .$filename); } if(empty($templates[1])){ $arr = [ "No data to show" ]; fputcsv($f, $arr); } else { foreach ($templates as $row) { fputcsv($f, $row, ','); } } fclose($f); } public function reportsTmpQstn($array_data){ $fields = " * "; $query = sprintf( $this->getTemplatesReportQuery(), $fields, $array_data['where'] ); return DB::select($query); } // public function pdfTmpQstn($results){ // // dd($results); // $data = []; // $grpData = new \stdClass(); // $grpData->list = $results; // $grpData->total = sizeOf($results); // array_push($data,$grpData); // $report_title = "Templates Masterfile"; // $reportData = [ // 'data' => $data, // 'webpage_title' => "Templates Report", // 'report_title' => $report_title, // 'table_headers' => ['No.', 'Questions', 'Date Created'], // 'table_body' => ['title','created_at'] // ]; // return $reportData; // } public function pdfTmpQstn($results) { $data = []; $grpData = new \stdClass(); // $grpData->no = 1; $grpData->list = $results; $grpData->total = sizeOf($results); array_push($data,$grpData); // $grpData->title = $results[0]->title; // $grpData->created_at = $results[0]->created_at; // $grpData->questions = $results[0]->questions; // array_push($data, $grpData); $report_title = "Template Questions Masterfile"; $reportData = [ 'data' => $data, 'webpage_title' => "Template Questions Masterfile", 'template_title' => $results[0]->title, 'report_title' => $report_title, 'table_headers' => ['No.', 'Questions', 'Date Created'], 'table_body' => ['title', 'created_at'], ]; return $reportData; } public function csvTmpQstn($results){ $templates = []; $templates[] = ['No.','Questions','Date Created']; $inc = 0; foreach($results as $row){ $templates[] = [ $inc+=1, $row->title, $row->created_at ]; } $filename = "Template_Questions_Masterfile"."-".date('Y-m-d').'.csv'; header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$filename.'"'); $f = fopen('php://output', 'wb'); if ($f === false) { die('Error opening the file ' .$filename); } if(empty($templates[1])){ $arr = [ "No data to show" ]; fputcsv($f,$arr); } else { foreach($templates as $row){ fputcsv($f, $row, ','); } // fputcsv($f,$templates[0]->title,','); } fclose($f); } } Models/Link.php000064400000000257150247674230007413 0ustar00