| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace App\Http\Controllers; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-16 14:43:33 +10:00
										 |  |  | use App\Models\Home; | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  | use App\Models\IPs; | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | use App\Models\Labels; | 
					
						
							|  |  |  | use App\Models\Pricing; | 
					
						
							|  |  |  | use App\Models\Shared; | 
					
						
							|  |  |  | use Illuminate\Http\Request; | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  | use Illuminate\Support\Facades\Cache; | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | use Illuminate\Support\Str; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SharedController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public function index() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-07-19 15:21:13 +10:00
										 |  |  |         $shared = Shared::allSharedHosting(); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         return view('shared.index', compact(['shared'])); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function create() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-05-15 12:01:48 +10:00
										 |  |  |         return view('shared.create'); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function store(Request $request) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $request->validate([ | 
					
						
							|  |  |  |             'domain' => 'required|min:4', | 
					
						
							| 
									
										
										
										
											2022-10-20 11:06:44 +11:00
										 |  |  |             'shared_type' => 'required|string', | 
					
						
							|  |  |  |             'disk' => 'integer', | 
					
						
							|  |  |  |             'os_id' => 'integer', | 
					
						
							|  |  |  |             'provider_id' => 'integer', | 
					
						
							|  |  |  |             'location_id' => 'integer', | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |             'price' => 'numeric', | 
					
						
							| 
									
										
										
										
											2022-10-20 11:06:44 +11:00
										 |  |  |             'payment_term' => 'integer', | 
					
						
							|  |  |  |             'was_promo' => 'integer', | 
					
						
							|  |  |  |             'owned_since' => 'sometimes|nullable|date', | 
					
						
							|  |  |  |             'domains' => 'integer', | 
					
						
							|  |  |  |             'sub_domains' => 'integer', | 
					
						
							|  |  |  |             'bandwidth' => 'integer', | 
					
						
							|  |  |  |             'email' => 'integer', | 
					
						
							|  |  |  |             'ftp' => 'integer', | 
					
						
							|  |  |  |             'db' => 'integer', | 
					
						
							|  |  |  |             'next_due_date' => 'required|date', | 
					
						
							|  |  |  |             'label1' => 'sometimes|nullable|string', | 
					
						
							|  |  |  |             'label2' => 'sometimes|nullable|string', | 
					
						
							|  |  |  |             'label3' => 'sometimes|nullable|string', | 
					
						
							|  |  |  |             'label4' => 'sometimes|nullable|string', | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $shared_id = Str::random(8); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $pricing = new Pricing(); | 
					
						
							| 
									
										
										
										
											2022-08-30 23:37:05 +10:00
										 |  |  |         $pricing->insertPricing(2, $shared_id, $request->currency, $request->price, $request->payment_term, $request->next_due_date); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-09 14:35:07 +10:00
										 |  |  |         Labels::deleteLabelsAssignedTo($shared_id); | 
					
						
							|  |  |  |         Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $shared_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         IPs::deleteIPsAssignedTo($shared_id); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  |         if (!is_null($request->dedicated_ip)) { | 
					
						
							| 
									
										
										
										
											2022-05-09 14:35:07 +10:00
										 |  |  |             IPs::insertIP($shared_id, $request->dedicated_ip); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-09 14:35:07 +10:00
										 |  |  |         Shared::create([ | 
					
						
							|  |  |  |             'id' => $shared_id, | 
					
						
							|  |  |  |             'main_domain' => $request->domain, | 
					
						
							|  |  |  |             'shared_type' => $request->shared_type, | 
					
						
							|  |  |  |             'provider_id' => $request->provider_id, | 
					
						
							|  |  |  |             'location_id' => $request->location_id, | 
					
						
							|  |  |  |             'disk' => $request->disk, | 
					
						
							|  |  |  |             'disk_type' => 'GB', | 
					
						
							|  |  |  |             'disk_as_gb' => $request->disk, | 
					
						
							|  |  |  |             'owned_since' => $request->owned_since, | 
					
						
							|  |  |  |             'bandwidth' => $request->bandwidth, | 
					
						
							|  |  |  |             'was_promo' => $request->was_promo, | 
					
						
							|  |  |  |             'domains_limit' => $request->domains, | 
					
						
							|  |  |  |             'subdomains_limit' => $request->sub_domains, | 
					
						
							|  |  |  |             'email_limit' => $request->email, | 
					
						
							|  |  |  |             'ftp_limit' => $request->ftp, | 
					
						
							|  |  |  |             'db__limit' => $request->db | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-19 15:21:13 +10:00
										 |  |  |         Cache::forget('all_shared'); | 
					
						
							| 
									
										
										
										
											2022-05-16 14:43:33 +10:00
										 |  |  |         Home::homePageCacheForget(); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         return redirect()->route('shared.index') | 
					
						
							|  |  |  |             ->with('success', 'Shared hosting created Successfully.'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function show(Shared $shared) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-09-22 13:20:23 +10:00
										 |  |  |         $shared = Shared::sharedHosting($shared->id); | 
					
						
							| 
									
										
										
										
											2022-07-19 15:21:13 +10:00
										 |  |  |         return view('shared.show', compact(['shared'])); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function edit(Shared $shared) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-09-22 13:20:23 +10:00
										 |  |  |         $shared = Shared::sharedHosting($shared->id); | 
					
						
							| 
									
										
										
										
											2022-07-19 15:21:13 +10:00
										 |  |  |         return view('shared.edit', compact(['shared'])); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function update(Request $request, Shared $shared) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $request->validate([ | 
					
						
							|  |  |  |             'domain' => 'required|min:4', | 
					
						
							| 
									
										
										
										
											2022-10-20 11:06:44 +11:00
										 |  |  |             'shared_type' => 'required|string', | 
					
						
							|  |  |  |             'disk' => 'integer', | 
					
						
							|  |  |  |             'os_id' => 'integer', | 
					
						
							|  |  |  |             'provider_id' => 'integer', | 
					
						
							|  |  |  |             'location_id' => 'integer', | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |             'price' => 'numeric', | 
					
						
							| 
									
										
										
										
											2022-10-20 11:06:44 +11:00
										 |  |  |             'payment_term' => 'integer', | 
					
						
							|  |  |  |             'was_promo' => 'integer', | 
					
						
							|  |  |  |             'owned_since' => 'sometimes|nullable|date', | 
					
						
							|  |  |  |             'domains' => 'integer', | 
					
						
							|  |  |  |             'sub_domains' => 'integer', | 
					
						
							|  |  |  |             'bandwidth' => 'integer', | 
					
						
							|  |  |  |             'email' => 'integer', | 
					
						
							|  |  |  |             'ftp' => 'integer', | 
					
						
							|  |  |  |             'db' => 'integer', | 
					
						
							|  |  |  |             'next_due_date' => 'required|date', | 
					
						
							|  |  |  |             'label1' => 'sometimes|nullable|string', | 
					
						
							|  |  |  |             'label2' => 'sometimes|nullable|string', | 
					
						
							|  |  |  |             'label3' => 'sometimes|nullable|string', | 
					
						
							|  |  |  |             'label4' => 'sometimes|nullable|string', | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         ]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-20 11:06:44 +11:00
										 |  |  |         $shared->update([ | 
					
						
							|  |  |  |             'main_domain' => $request->domain, | 
					
						
							|  |  |  |             'shared_type' => $request->shared_type, | 
					
						
							|  |  |  |             'provider_id' => $request->provider_id, | 
					
						
							|  |  |  |             'location_id' => $request->location_id, | 
					
						
							|  |  |  |             'disk' => $request->disk, | 
					
						
							|  |  |  |             'disk_type' => 'GB', | 
					
						
							|  |  |  |             'disk_as_gb' => $request->disk, | 
					
						
							|  |  |  |             'owned_since' => $request->owned_since, | 
					
						
							|  |  |  |             'bandwidth' => $request->bandwidth, | 
					
						
							|  |  |  |             'was_promo' => $request->was_promo, | 
					
						
							|  |  |  |             'domains_limit' => $request->domains, | 
					
						
							|  |  |  |             'subdomains_limit' => $request->sub_domains, | 
					
						
							|  |  |  |             'email_limit' => $request->email, | 
					
						
							|  |  |  |             'ftp_limit' => $request->ftp, | 
					
						
							|  |  |  |             'db_limit' => $request->db | 
					
						
							|  |  |  |         ]); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $pricing = new Pricing(); | 
					
						
							| 
									
										
										
										
											2022-10-31 16:00:00 +11:00
										 |  |  |         $pricing->updatePricing($shared->id, $request->currency, $request->price, $request->payment_term, $request->next_due_date); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 16:00:00 +11:00
										 |  |  |         Labels::deleteLabelsAssignedTo($shared->id); | 
					
						
							|  |  |  |         Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $shared->id); | 
					
						
							|  |  |  |         Cache::forget("labels_for_service.{$shared->id}"); | 
					
						
							| 
									
										
										
										
											2022-05-15 12:01:48 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 16:00:00 +11:00
										 |  |  |         IPs::deleteIPsAssignedTo($shared->id); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  |         if (isset($request->dedicated_ip)) { | 
					
						
							| 
									
										
										
										
											2022-10-31 16:00:00 +11:00
										 |  |  |             IPs::insertIP($shared->id, $request->dedicated_ip); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 16:00:00 +11:00
										 |  |  |         Cache::forget("shared_hosting.{$shared->id}"); | 
					
						
							| 
									
										
										
										
											2022-07-19 15:21:13 +10:00
										 |  |  |         Cache::forget('all_shared'); | 
					
						
							| 
									
										
										
										
											2022-05-16 14:43:33 +10:00
										 |  |  |         Home::homePageCacheForget(); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         return redirect()->route('shared.index') | 
					
						
							|  |  |  |             ->with('success', 'Shared hosting updated Successfully.'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function destroy(Shared $shared) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |         if ($shared->delete()) { | 
					
						
							|  |  |  |             $p = new Pricing(); | 
					
						
							|  |  |  |             $p->deletePricing($shared->id); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |             Labels::deleteLabelsAssignedTo($shared->id); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |             IPs::deleteIPsAssignedTo($shared->id); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |             Cache::forget("shared_hosting.$shared->id"); | 
					
						
							|  |  |  |             Cache::forget('all_shared'); | 
					
						
							|  |  |  |             Home::homePageCacheForget(); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |             return redirect()->route('shared.index') | 
					
						
							|  |  |  |                 ->with('success', 'Shared hosting was deleted Successfully.'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-03-06 02:58:25 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |         return redirect()->route('shared.index') | 
					
						
							| 
									
										
										
										
											2022-11-09 15:18:25 +11:00
										 |  |  |             ->with('error', 'Shared was not deleted.'); | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |