1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1, ]; /** * Constructor for the class */ public function __construct() { $this->middleware('auth'); $this->middleware('role:Admin'); } /** * Function to display moon requests */ public function displayMoonRequests() { $requests = AllianceMoonRequest::where([ 'status' => 'Pending', ])->get(); return view('moons.admin.moonrequest')->with('requests', $requests); } /** * Function to approve a moon request */ public function storeApprovedMoonRequest(Request $request) { //Validate the input request $this->validate($request, [ 'id' => 'required', 'status' => 'required', 'system' => 'required', 'planet' => 'required', 'moon' => 'required', ]); //Get the request data which holds all of the information for the request user $moon = AllianceMoonRequest::where([ 'id' => $request->id, ])->first(); //Get the configuration data to use later in the function $config = config('esi'); //If the request is approved, then update everything. if($request->status == 'Approved') { //Update the alliance moon request to either approved or denied AllianceMoonRequest::where([ 'id' => $request->id, ])->update([ 'status' => $request->status, 'approver_name' => auth()->user()->getName(), 'approver_id' => auth()->user()->getId(), ]); //Update the alliance moon in the table to the correct status AllianceMoon::where([ 'System' => $request->system, 'Planet' => $request->planet, 'Moon' => $request->moon, ])->update([ 'Corporation' => $moon->corporation_ticker, 'Availability' => 'Deployed', ]); //Send an eve mail to the requestor stating they can set a moon up. //Setup the mail body $body = 'The moon request for ' . $request->system . ' - ' . $request->planet . ' - ' . $request->moon . ' has changed status.
'; $body .= 'The request has been ' . $request->status . '.
'; $body .= 'Please contact the FC Team should it be necessary to arrange a fleet to cover the structure drop.
'; $body .= 'Sincerely,
'; $body .= 'Warped Intentions Leadership
'; } else { //If the status was Denied, then update the request, and mark the moon available again. AllianceMoonRequest::where([ 'id' => $request->id, ])->update([ 'status' => $request->status, 'approver_name' => auth()->user()->getName(), 'approver_id' => auth()->user()->getId(), ]); //Update the alliance moon in the table to the correct status AllianceMoon::where([ 'System' => (string)$request->system, 'Planet' => (string)$request->planet, 'Moon' => (string)$request->moon, ])->update([ 'Availability' => 'Available', ]); //Send an eve mail to the requestor stating they can set a moon up. //Setup the mail body $body = 'The moon request for ' . $moon->System . ' - ' . $moon->Planet . ' - ' . $moon->Moon . ' has changed status.
'; $body .= 'The request has been ' . $request->status . '.
'; $body .= 'Should you have questions please contact alliance leadership for further clarification.
'; $body .= 'Sincerely,
'; $body .= 'Warped Intentions Leadership
'; } //Setup the mail model ProcessSendEveMailJob::dispatch($body, (int)$moon->requestor_id, 'character', 'Warped Intentions Moon Request', $config['primary'])->onQueue('mail')->delay(Carbon::now()->addSeconds(30)); return redirect('/moons/admin/display/request')->with('success', 'Moon has been processed, and mail has been sent out.'); } /** * Function to display the ability for the admins to update moons with who is renting, * and when it ends */ public function updateMoon() { $this->middleware('role:Admin'); //Declare the variables we need $system = null; $planet = null; $moon = null; $name = null; $spmnTemp = array(); $spmn = array(); //Get the moons and put in order by System, Planet, Moon number $moons = AllianceRentalMoon::orderBy('System', 'ASC') ->orderBy('Planet', 'ASC') ->orderBy('Moon', 'ASC') ->get(); //Push our default value onto the stack array_push($spmn, 'N/A'); //Form our array of strings for each system, planet, and moon combination foreach($moons as $m) { $temp = $m->system . " - " . $m->planet . " - " . $m->moon . " - " . $m->structure_name; array_push($spmnTemp, $temp); } //From the temporary array, build the final array foreach($spmnTemp as $key => $value) { $spmn[$value] = $value; } //Pass the data to the blade display return view('moons.admin.updatemoon')->with('spmn', $spmn); } /** * Function to remove a renter from a moon * New function based on new table. Will * update description in a future update. */ public function storeMoonRemoval(Request $request) { //Check for the correct role for the user to utilize this function $this->middleware('role:Admin'); //Validate the request $this->validate($request, [ 'remove' => 'required', ]); //Explode the remove request to an array of strings $str_array = explode(" - ", $request->remove); //Decode the value for the SPM into a system, planet, and moon $system = $str_array[0]; $planet = $str_array[1]; $moon = $str_array[2]; //Update the moon rental AllianceRentalMoon::where([ 'system' => $system, 'planet' => $planet, 'moon' => $moon, ])->update([ 'rental_type' => 'Not Rented', 'rental_until' => null, 'rental_contact_id' => 0, 'rental_contact_type' => 'Not Rented', 'paid' => 'Not Rented', 'paid_until' => null, 'alliance_use_until' => null, ]); //Once the action is completed, redirect to the original page return redirect('/moons/admin/display/rentals')->with('success', 'Renter removed from the moon.'); } /** * Function to display the moons to admins * New function based on new table. Will * update description in a future update. */ public function displayRentalMoonsAdmin() { //Declare variables for the function $lookupHelper = new LookupHelper; $moonCalc = new MoonCalc; $contactId = null; $contactType = null; $paid = null; $paidUntil = null; $corpTicker = null; $table = array(); //Setup the carbon date using Carbon\Carbon $lastMonth = Carbon::now()->subMonth(); $today = Carbon::now(); //Get the moon rentals from the database $rentalMoons = AllianceRentalMoon::orderBy('system', 'asc')->get(); //For each of the moons compile different data for the view for formatting foreach($rentalMoons as $moon) { //Check if a current rental for the moon is on going if(($moon->rental_type == 'In Alliance' || $moon->rental_type == 'Out of Alliance')) { $paid = $moon->paid; $paidUntil = new Carbon($moon->paid_until); $paidUntil = $paidUntil->format('m-d'); //Set the rental date up $rentalTemp = new Carbon($moon->rental_until); $rentalEnd = $rentalTemp->format('m-d'); //Set the correct color for the table if($rentalTemp->diffInDays(Carbon::now()) < 3 && $today->lessThan($rentalTemp)) { $color = 'table-warning'; } else if($today->lessThan($rentalTemp)) { $color = 'table-danger'; } else { $color = 'table-primary'; } //Set the contact name based on the contact type if($moon->rental_contact_type == 'Alliance') { $allianceInfo = $lookupHelper->GetAllianceInfo($moon->rental_contact_id); //Set the contact name and ticker $contact = $allianceInfo->name; $ticker = $allianceInfo->ticker; } else if($moon->rental_contact_type == 'Corporation') { $corporationInfo = $lookupHelper->GetCorporationInfo($moon->rental_contact_id); //Set the contact name and ticker $contact = $corporationInfo->name; $ticker = $corporationInfo->ticker; } else if($moon->rental_contact_type == 'Character') { $characterInfo = $lookupHelper->GetCharacterInfo($moon->rental_contact_id); //Set the contact name $contact = $characterInfo->name; //Get the ticker for the character from the corporation he belongs to $corpInfo = $lookupHelper->GetCorporationInfo($characterInfo->corporation_id); $ticker = $corpInfo->ticker; } else { $contact = 'N/A'; $ticker = 'N/A'; $type = 'N/A'; $color = 'table-primary'; } //Check if the moon is currently being utilized by the alliance } else if($moon->rental_type == 'Alliance') { //If the moon is in use by the alliance then the moon isn't paid for $paid = 'No'; //Setup the rental end time as the end of the month $rentalTemp = Carbon::now()->endOfMonth(); $rentalEnd = $rentalTemp->format('m-d'); //Set the color of the table $color = 'table-info'; //Setup the paid time as the same as the rental end $paidUntiltemp = $rentalTemp; $paidUntil = $rentalEnd; //Set the other information for the spreadsheet $contact = 'Spatial Forces'; $renter = 'SP3C'; $ticker = 'SP3C'; $type = 'Alliance'; //The last case is the moon is not utilized by the Alliance or is not being rented } else { //If the moon is not being rented, or being utilized by the alliance then set paid to No $paid = 'No'; //Setup the rental time to end as last month to show it's free $rentalTemp = $lastMonth; $rentalEnd = $rentalTemp->format('m-d'); //Setup the paid until as last month to show it's free $paidUntilTemp = $lastMonth; $paidUntil = $lastMonth->format('m-d'); //Setup the other variables with the correct information $contact = 'None'; $renter = 'None'; $ticker = 'N/A'; $type = 'N/A'; //Set the color of the table $color = 'table-primary'; } //Set up the moon rental type if($moon->rental_type == 'In Alliance') { $type = 'IA'; //Setup the row color if($rentalTemp->diffInDays(Carbon::now()) < 3 && $today->lessThan($rentalTemp)) { $color = 'table-warning'; } else if($today->lessThan($rentalTemp)) { $color = 'table-danger'; } else { $color = 'table-primary'; } } else if($moon->rental_type == 'Out of Alliance') { $type = 'OOA'; //Setup the row color if($rentalTemp->diffInDays(Carbon::now()) < 3 && $today->lessThan($rentalTemp)) { $color = 'table-warning'; } else if($today->lessThan($rentalTemp)) { $color = 'table-danger'; } else { $color = 'table-primary'; } } else if($moon->rental_type == 'Alliance') { $type = 'W4RP'; //Set the row color $color = 'table-info'; } else { $type = 'N/A'; //Set the row color $color = 'table-primary'; } //Add the data to the html string to be passed to the view array_push($table, [ 'SPM' => $moon->system . " - " . $moon->planet . " - " . $moon->moon, 'StructureName' => $moon->structure_name, 'AlliancePrice' => $moon->alliance_rental_price, 'OutOfAlliancePrice' => $moon->out_of_alliance_rental_price, 'RentalEnd' => $rentalEnd, 'RowColor' => $color, 'Paid' => $moon->paid, 'PaidUntil' => $paidUntil, 'Contact' => $contact, 'Type' => $moon->rental_type, 'Renter' => $type, ]); } return view('moons.admin.adminmoon')->with('table', $table); } /** * Function to store the updates from the moons. * New function based on new table. Will update * the description in a future update */ public function storeUpdateMoon(Request $request) { //Require the site administration role $this->middleware('role:Admin'); //Declare some variables we will need $moonCalc = new MoonCalc; $lookup = new LookupHelper; $paid = false; $system = null; $planet = null; $mn = null; //Validate our request from the html form $this->validate($request, [ 'spmn' => 'required', 'contact' => 'required', 'contact_type' => 'required', 'paid_until' => 'required', 'rental_end' => 'required', ]); //Decode the spmn $str_array = explode(" - ", $request->spmn); $system = $str_array[0]; $planet = $str_array[1]; $mn = $str_array[2]; $name = $str_array[3]; //Update the paid value from the request value if($request->paid == 'Yes') { $paid = 'Yes'; } else { $paid = 'No'; } //Setup the rental end and paid until variables $rentalEnd = $request->rental_end . " 23:59:59"; $paidUntil = $request->paid_until . " 23:59:59"; //Check if the alliance is renting the moon for itself if($request->contact_type == 'Corporation' && $request->contact == 'Spatial Forces') { AllianceRentalMoon::where([ 'system' => $str_array[0], 'planet' => $str_array[1], 'moon' => $str_array[2], ])->update([ 'rental_type' => 'Alliance', 'rental_until' => $request->rental_end . " 23:59:59", 'rental_contact_id' => 98287666, 'rental_contact_type' => 'Alliance', 'paid' => 'No', 'paid_until' => null, 'alliance_use_until' => $request->rental_end . " 23:59:59", ]); } else if($request->contact_type == 'Character') { //Get the character id from the lookup helper $charId = $lookup->CharacterNameToId($request->contact); //Get the character information including the corporation from the lookup tables $char = $lookup->GetCharacterInfo($charId); //Get the corporation id from the lookup helper, followed by the alliance id //so we can determine if it's in alliance or out of alliance $corp = $lookup->GetCorporationInfo($char->corporation_id); if($corp->alliance_id == 99004116) { $type = 'In Alliance'; } else { $type = 'Out of Alliance'; } AllianceRentalMoon::where([ 'system' => $str_array[0], 'planet' => $str_array[1], 'moon' => $str_array[2], ])->update([ 'rental_type' => $type, 'rental_until' => $request->rental_end . " 23:59:59", 'rental_contact_id' => $charId, 'rental_contact_type' => 'Character', 'paid' => $paid, 'paid_until' => $request->paid_until . " 23:59:59", 'alliance_use_until' => null, ]); } else if($request->contact_type == 'Corporation') { //Get the corporation id from the lookup helper $corpId = $lookup->CorporationNameToId($request->contact); //Get the corporation information to determine if they are in Warped Intentions or not. $corporation = $lookup->GetCorporationInfo($request->contact); if($corp->alliance_id == 99004116) { $type = 'In Alliance'; } else { $type = 'Out of Alliance'; } AllianceMoonRental::where([ 'system' => $str_array[0], 'planet' => $str_array[1], 'moon' => $str_array[2], ])->update([ 'rental_type' => $type, 'rental_until' => $request->rental_end . " 23:59:59", 'rental_contact_id' => $corpId, 'rental_contact_type' => 'Corporation', 'paid' => $paid, 'paid_until' => $request->paid_until . " 23:59:59", 'alliance_use_until' => null, ]); } //Redirect to the previous screen. return redirect('/moons/admin/updatemoon')->with('success', 'Moon Rental updated.'); } public function ImportMoonSurveyData(Request $request) { //Declare variables $added = 0; $updated = 0; $moon = null; $newMoon = false; $num = 0; $planet = null; $moonNumber = null; foreach(explode("\n", $request->input('data')) as $row) { $cols = explode("\t", $row); dd($cols); } return redirect('/admin/dashboard')->with('success', 'Import done: ' . $added . ' moons added ' . $updated . ' moons updated.'); } private function romanNumberToInteger($roman) { $result = 0; foreach($this->romans as $key => $value) { while(strpos($roman, $key) === 0) { $result += $value; $roman = substr($roman, strlen($key)); } } return $result; } private function integerToRomanNumber($number) { $returnValue = ''; while($number > 0) { foreach($this->romans as $roman => $int) { if($number >= $int) { $number -= $int; $returnValue .= $roman; break; } } } return $returnValue; } private function arrayToCsv(array $rows) { //Declare needed variable as text null $result = ''; //Open the temp file $fp = fopen('php://temp', 'w'); //Process the file foreach($rows as $fields) { fputcsv($fp, $fields, ';', '"'); } //Go back to the beginning of the file rewind($fp); //Continue through the buffer until the end while(($buffer = fgets($fp, 4096)) !== false) { $result .= $buffer; } //Close the temp file fclose($fp); //Return the result return $result; } }