[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: Leads.php
<?php /** -------------------------------------------------------------------------------- * This controller manages all the business logic for leads settings * * @package Grow CRM * @author NextLoop *----------------------------------------------------------------------------------*/ namespace App\Http\Controllers\Settings; use App\Http\Controllers\Controller; use App\Http\Responses\Settings\Leads\CreateStatusResponse; use App\Http\Responses\Settings\Leads\DestroyStatusResponse; use App\Http\Responses\Settings\Leads\EditStatusResponse; use App\Http\Responses\Settings\Leads\IndexResponse; use App\Http\Responses\Settings\Leads\moveResponse; use App\Http\Responses\Settings\Leads\MoveUpdateResponse; use App\Http\Responses\Settings\Leads\StatusesResponse; use App\Http\Responses\Settings\Leads\StoreStatusResponse; use App\Http\Responses\Settings\Leads\UpdateResponse; use App\Http\Responses\Settings\Leads\UpdateStatusResponse; use App\Repositories\LeadStatusRepository; use App\Repositories\SettingsRepository; use Illuminate\Http\Request; use Validator; class Leads extends Controller { /** * The settings repository instance. */ protected $settingsrepo; /** * The lead statuses repository instance. */ protected $statusrepo; public function __construct(SettingsRepository $settingsrepo, LeadStatusRepository $statusrepo) { //parent parent::__construct(); //authenticated $this->middleware('auth'); //settings general $this->middleware('settingsMiddlewareIndex'); $this->settingsrepo = $settingsrepo; $this->statusrepo = $statusrepo; } /** * Display general settings * * @return \Illuminate\Http\Response */ public function general() { //crumbs, page data & stats $page = $this->pageSettings(); $settings = \App\Models\Settings::find(1); $settings2 = \App\Models\Settings2::find(1); //reponse payload $payload = [ 'page' => $page, 'settings' => $settings, 'settings2' => $settings2, ]; //show the view return new IndexResponse($payload); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function updateGeneral() { $settings = \App\Models\Settings::find(1); $settings2 = \App\Models\Settings2::find(1); //update if (!$this->settingsrepo->updateLeads()) { abort(409); } //update other settings $settings2->settings2_importing_leads_duplicates_name = request('settings2_importing_leads_duplicates_name') == 'on' ? 'yes' : 'no'; $settings2->settings2_importing_leads_duplicates_email = request('settings2_importing_leads_duplicates_email') == 'on' ? 'yes' : 'no'; $settings2->settings2_importing_leads_duplicates_telephone = request('settings2_importing_leads_duplicates_telephone') == 'on' ? 'yes' : 'no'; $settings2->settings2_importing_leads_duplicates_company = request('settings2_importing_leads_duplicates_company') == 'on' ? 'yes' : 'no'; $settings2->save(); //reponse payload $payload = []; //generate a response return new UpdateResponse($payload); } /** * Display general settings * * @return \Illuminate\Http\Response */ public function statuses() { //crumbs, page data & stats $page = $this->pageSettings('statuses'); $statuses = $this->statusrepo->search(); //reponse payload $payload = [ 'page' => $page, 'statuses' => $statuses, ]; //show the view return new StatusesResponse($payload); } /** * Show the form for editing the specified resource. * @url baseusr/items/1/edit * @param int $id resource id * @return \Illuminate\Http\Response */ public function editStatus($id) { //page settings $page = $this->pageSettings('edit'); //client leadsources $statuses = $this->statusrepo->search($id); //not found if (!$status = $statuses->first()) { abort(409, __('lang.error_loading_item')); } //reponse payload $payload = [ 'page' => $page, 'status' => $status, ]; //response return new EditStatusResponse($payload); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id resource id * @return \Illuminate\Http\Response */ public function updateStatus($id) { //custom error messages $messages = []; //validate $validator = Validator::make(request()->all(), [ 'leadstatus_title' => [ 'required', function ($attribute, $value, $fail) { if (\App\Models\LeadStatus::where('leadstatus_title', $value) ->where('leadstatus_id', '!=', request()->route('id')) ->exists()) { return $fail(__('lang.status_already_exists')); } }], ], $messages); //errors if ($validator->fails()) { $errors = $validator->errors(); $messages = ''; foreach ($errors->all() as $message) { $messages .= "<li>$message</li>"; } abort(409, $messages); } //update the resource if (!$this->statusrepo->update($id)) { abort(409); } //get the category object (friendly for rendering in blade template) $statuses = $this->statusrepo->search($id); //reponse payload $payload = [ 'statuses' => $statuses, ]; //process reponse return new UpdateStatusResponse($payload); } /** * Show the form for creating a new resource. * @return \Illuminate\Http\Response */ public function createStatus() { //page settings $page = $this->pageSettings(); $page['default_color'] = 'checked'; //reponse payload $payload = [ 'page' => $page, ]; //show the form return new CreateStatusResponse($payload); } /** * Store a newly created resource in storage. * @return \Illuminate\Http\Response */ public function storeStatus() { //custom error messages $messages = []; //validate $validator = Validator::make(request()->all(), [ 'leadstatus_title' => [ 'required', function ($attribute, $value, $fail) { if (\App\Models\LeadStatus::where('leadstatus_title', $value) ->exists()) { return $fail(__('lang.status_already_exists')); } }], ], $messages); //errors if ($validator->fails()) { $errors = $validator->errors(); $messages = ''; foreach ($errors->all() as $message) { $messages .= "<li>$message</li>"; } abort(409, $messages); } //get the last row (order by position - desc) if ($last = \App\Models\LeadStatus::orderBy('leadstatus_position', 'desc')->first()) { $position = $last->leadstatus_position + 1; } else { //default position $position = 2; } //create the source if (!$leadstatus_id = $this->statusrepo->create($position)) { abort(409, __('lang.error_request_could_not_be_completed')); } //get the source object (friendly for rendering in blade template) $statuses = $this->statusrepo->search($leadstatus_id); //reponse payload $payload = [ 'statuses' => $statuses, ]; //process reponse return new StoreStatusResponse($payload); } /** * Show the form for editing the specified resource. * @param int $id resource id * @return \Illuminate\Http\Response */ public function move($id) { //page settings $page = $this->pageSettings(); //client leadsources $statuses = \App\Models\LeadStatus::get(); //reponse payload $payload = [ 'page' => $page, 'statuses' => $statuses, ]; //response return new moveResponse($payload); } /** * Move leads from one category to another * @param int $id resource id * @return \Illuminate\Http\Response */ public function updateMove($id) { //page settings $page = $this->pageSettings(); //move the leads \App\Models\Lead::where('lead_status', $id)->update(['lead_status' => request('leads_status')]); //client leadsources $statuses = $this->statusrepo->search(); //reponse payload $payload = [ 'page' => $page, 'statuses' => $statuses, ]; //response return new MoveUpdateResponse($payload); } /** * Update a stages position * @param int $id resource id * @return \Illuminate\Http\Response */ public function updateStagePositions() { //reposition each lead status $i = 1; foreach (request('sort-stages') as $key => $id) { if (is_numeric($id)) { \App\Models\LeadStatus::where('leadstatus_id', $id)->update(['leadstatus_position' => $i]); } $i++; } //retun simple success json return response()->json('success', 200); } /** * Remove the specified resource from storage. * * @param int $id resource id * @return \Illuminate\Http\Response */ public function destroyStatus($id) { //get record if (!\App\Models\LeadStatus::find($id)) { abort(409, __('lang.error_request_could_not_be_completed')); } //get it in useful format $statuses = $this->statusrepo->search($id); $status = $statuses->first(); //validation: default if ($status->leadstatus_system_default == 'yes') { abort(409, __('lang.you_cannot_delete_system_default_item')); } //validation: default if ($status->count_leads != 0) { abort(409, __('lang.stage_not_empty')); } //delete the category $status->delete(); //reponse payload $payload = [ 'status_id' => $id, ]; //process reponse return new DestroyStatusResponse($payload); } /** * basic page setting for this section of the app * @param string $section page section (optional) * @param array $data any other data (optional) * @return array */ private function pageSettings($section = '', $data = []) { $page = [ 'crumbs' => [ __('lang.settings'), __('lang.leads'), ], 'crumbs_special_class' => 'main-pages-crumbs', 'page' => 'settings', 'meta_title' => __('lang.settings'), 'heading' => __('lang.settings'), 'settingsmenu_general' => 'active', ]; //default modal settings (modify for sepecif sections) $page += [ 'add_modal_title' => __('lang.add_new_lead_status'), 'add_modal_create_url' => url('settings/leads/statuses/create'), 'add_modal_action_url' => url('settings/leads/statuses/create'), 'add_modal_action_ajax_class' => '', 'add_modal_action_ajax_loading_target' => 'commonModalBody', 'add_modal_action_method' => 'POST', ]; config([ //visibility - add project buttton 'visibility.list_page_actions_add_button' => true, ]); //create new resource if ($section == 'statuses') { $page['crumbs'] = [ __('lang.settings'), __('lang.leads'), __('lang.lead_stages'), ]; } return $page; } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.69 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002