2024-06-26 12:28:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use App\Models\Ticket;
|
|
|
|
|
use App\Models\Company;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2024-07-01 11:17:16 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2024-10-08 12:30:49 +00:00
|
|
|
use App\Models\CompanyMeta;
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
use Illuminate\Support\Str;
|
2024-06-26 12:28:46 +00:00
|
|
|
|
|
|
|
|
class DashboardController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function dashboard()
|
|
|
|
|
{
|
2024-06-28 06:58:04 +00:00
|
|
|
$tickets = get_current_company_tickets(['type' => 'inbox']);
|
2024-09-12 11:56:53 +00:00
|
|
|
$companyId = getSelectedCompany();
|
|
|
|
|
$tags = getCompanyTags($companyId);
|
2024-10-08 12:30:49 +00:00
|
|
|
$canned_response = $this->get_canned_responses();
|
|
|
|
|
return view('index', ['tickets' => $tickets, 'tags' => $tags, 'canned_response' => $canned_response]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function get_canned_responses(){
|
|
|
|
|
$companyId = getSelectedCompany();
|
|
|
|
|
return CompanyMeta::where('company_id', $companyId)->where('key', 'canned_responses')->get();
|
2024-06-26 12:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function profile()
|
|
|
|
|
{
|
2024-07-01 11:17:16 +00:00
|
|
|
$company = getSelectedCompany();
|
2024-10-08 12:30:49 +00:00
|
|
|
$user = Auth::user();
|
2024-07-01 11:17:16 +00:00
|
|
|
$users = $users = User::where('role_id', '!=', 1)
|
|
|
|
|
//->where('id', '!=', Auth::id())
|
|
|
|
|
->join('company_users', 'users.id', '=', 'company_users.user_id')
|
|
|
|
|
->where('company_users.company_id', $company)
|
|
|
|
|
->select('users.*')
|
|
|
|
|
->get();
|
2024-10-08 12:30:49 +00:00
|
|
|
return view('profile', ['users' => $users, 'user' => $user]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateProfile(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$request->validate([
|
|
|
|
|
'name' => 'required|string',
|
|
|
|
|
'profile_image' => 'nullable|image|mimes:jpg,jpeg,png|max:2048',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$user = Auth::user();
|
|
|
|
|
|
|
|
|
|
if($request->hasFile('profile_image')) {
|
|
|
|
|
|
|
|
|
|
//Remove Old Image
|
|
|
|
|
if ($user->profile_image) {
|
|
|
|
|
$oldImagePath = str_replace('/storage/', '', $user->profile_image);
|
|
|
|
|
Storage::disk('public')->delete($oldImagePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Store New Image
|
|
|
|
|
$file = $request->file('profile_image');
|
|
|
|
|
$extension = $file->getClientOriginalExtension();
|
|
|
|
|
$filename = time() . '_' . Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)) . '.' . $extension;
|
|
|
|
|
$path = $file->storeAs('profile_images', $filename, 'public');
|
|
|
|
|
|
|
|
|
|
$user->profile_image = Storage::url($path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//update user
|
|
|
|
|
$user->name = $request->name;
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
|
|
return back()->with('success', 'Profile Updated Successfully');
|
2024-06-26 12:28:46 +00:00
|
|
|
}
|
|
|
|
|
}
|