/**
  * Override setting the user_id attribute to automatically adjust user roles.
  * @param $value
  */
 public function setUserIdAttribute($value)
 {
     // Only process the change in permissions
     // if the assigned user has changed
     $old_id = $this->getAttributeValue('user_id');
     if ($old_id != $value) {
         // Don't allow self-unassignment
         if ($old_id == Auth::user()->id) {
             Flash::warning('You can\'t remove yourself from the committee');
             return;
         }
         // Get the necessary roles
         $committee = Role::where('name', 'committee')->first();
         $member = Role::where('name', 'member')->first();
         // Look through the database for any other committee roles for
         // the old user. If they exist then we don't want to remove
         // their committee permissions.
         $old_user = User::find($old_id);
         if ($old_user && $old_user->hasRole($committee->name)) {
             if (CommitteeRole::where('user_id', '=', $old_user->id)->where('id', '<>', $this->id)->get()->count() == 0) {
                 $old_user->detachRole($committee);
                 $old_user->attachRole($member);
             }
         }
         // Always give the new user committee permissions
         $new_user = User::find($value);
         if ($new_user && !$new_user->hasRole($committee->name)) {
             $new_user->attachRole($committee);
             $new_user->detachRole($member);
         }
     }
     // Set the new id
     $this->attributes['user_id'] = $value;
 }
 /**
  * Delete a category.
  * @param                                   $id
  * @param \App\Http\Requests\GenericRequest $request
  * @return mixed
  */
 public function destroy($id, GenericRequest $request)
 {
     // Require ajax
     $this->requireAjax($request);
     // Get the category
     $category = ResourceCategory::find($id);
     if (!$category) {
         return $this->ajaxError("Couldn't find that category", 404);
     }
     // Delete
     $category->delete();
     Flash::success('Category deleted');
     return Response::json(true);
 }
 /**
  * Delete a quote.
  * @param \Illuminate\Http\Request $request
  * @return string
  */
 public function destroy(Request $request)
 {
     $quote = Quote::find($request->get('deleteQuote'));
     if ($quote) {
         if ($quote->delete()) {
             Flash::success("Quote deleted");
         } else {
             Flash::error("Oops", "Something went wrong when trying to delete that quote.");
         }
     } else {
         Flash::warning("Oops", "The selected quote couldn't be found; perhaps it's been deleted?");
     }
     return redirect()->back();
 }
 /**
  * Process the accident report form.
  * @param ContactAccidentRequest $request
  * @return \Illuminate\Http\Request
  */
 public function postAccident(ContactAccidentRequest $request)
 {
     // Get data for emails
     $data = $request->stripped('location', 'date', 'time', 'details', 'severity', 'absence_details', 'injured_name', 'contact_name', 'contact_email', 'contact_phone', 'person_type', 'person_type_other');
     // Send the email
     Mail::queue('emails.contact.accident', $data, function ($message) use($data) {
         $message->to('*****@*****.**')->to('*****@*****.**')->to('*****@*****.**')->to('*****@*****.**')->subject('** BTS Accident Report **')->from($data['contact_email'], $data['contact_name']);
     });
     // Send the receipt
     Mail::queue('emails.contact.accident_receipt', $data, function ($message) use($data) {
         $message->to($data['contact_email'], $data['contact_name'])->from('*****@*****.**', 'Backstage')->subject('** BTS Accident Report Receipt **');
     });
     // Flash
     Flash::success('Accident report sent', 'You should receive a receipt shortly.');
     return redirect(route('home'));
 }
Esempio n. 5
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $order_id = $this->getNewOrderId();
     $pick_id = 'P' . $this->getRandomRackNo();
     $warning = array();
     $error = array();
     $totalPrice = 0;
     $totaProducts = count($request->input('products'));
     foreach ($request->input('products') as $selected_id) {
         //GET Product Price
         $productPrice = $this->dbgetProductPrice($selected_id);
         //GET Bin Location
         $bin = $this->dbgetProductBinLoc($selected_id);
         //GET Distance
         //$psd = $this->dbcalculatePickDistance($bin[0]->bin_location);
         $remarks = $this->dbcalculatePickDistance($bin[0]->bin_location, $totaProducts);
         $finalPrice = $productPrice->price;
         $totalPrice += $finalPrice;
         //QUERY STOCK LEVEL
         $results = $this->dbStockLevel($selected_id);
         if ($results[0]->stock_level != 0) {
             //Prepare to insert data in orders table
             $new_order = array('order_id' => $order_id, 'customer_id' => $request->input('customers'), 'product_id' => $selected_id, 'product_price' => $productPrice->price, 'remarks' => '', 'picking_station' => $bin[0]->picking_id, 'picking_station_distance' => $remarks['value'] . 'm');
             $post = new Orders($new_order);
             $post->save();
             // Saves Warning Message for Low Level Stock
             if ($results[0]->stock == 0) {
                 array_push($warning, $results[0]->product_name);
             }
             //DECREMENT STOCK
             $this->dbUpdateStock($selected_id);
         } else {
             if ($results[0]->stock_level == 0) {
                 array_push($error, $results[0]->product_name);
             }
         }
     }
     //SHOW IF THERE IS ANY WARNING MESSAGES
     $res = count($warning);
     if ($res > 0) {
         foreach ($warning as $re) {
             Flash::warning('Low on stock on: ' . $re);
         }
     }
     //SHOW IF THERE IS ANY ERROR MESSAGES
     $res_e = count($error);
     if ($res_e > 0) {
         foreach ($error as $er) {
             Flash::error('No stock available on: ' . $er);
         }
     }
     //ADD Optimum route to database when empty values
     $order = $this->dbQueryOrders($order_id);
     if (!empty($order) || $order[0]->remarks == '') {
         $add_remarks = $this->getOptimumDistance($order_id);
         DB::table('orders')->where('order_id', $order_id)->update(array('remarks' => $add_remarks));
     }
     #FLASH CLASS
     //Flash::message('Your order has been created!'); //blue
     //Flash::warning('Your order has been created!'); //brown
     //Flash::error('Your order has been created!');  //red
     //Flash::success('Your order has been created!');  //green
     //Flash::info('Your order has been created!');  //light blue
     Flash::success('Your order has been created!');
     return redirect('orders');
 }
 /**
  * Update the specified user in storage.
  * @param  string        $username
  * @param GenericRequest $request
  * @return \Illuminate\Http\Response
  */
 public function update($username, GenericRequest $request)
 {
     $user = User::where('username', $username)->firstOrFail();
     $ownAccount = $user->id == $this->user->id;
     // If performing a general save then validate the inputs and perform the
     // update, setting the account type as necessary. If updating the active
     // user, the restricted attributes will be set to their current values.
     if ($request->get('action') == 'save') {
         $data = $request->stripped('name', 'username', 'nickname', 'email', 'phone', 'dob', 'address', 'tool_colours', 'type') + ['show_email' => $request->has('show_email'), 'show_phone' => $request->has('show_phone'), 'show_address' => $request->has('show_address'), 'show_age' => $request->has('show_age')];
         $data['dob'] = $data['dob'] ?: null;
         if ($ownAccount) {
             $data['username'] = $user->username;
             $data['type'] = $user->type;
         }
         $validator = Validator::make($data, $user->getProfileValidationRules(), $user->getProfileValidationMessages());
         if ($validator->fails()) {
             return redirect()->back()->withInput($data)->withErrors($validator);
         } else {
             if ($user->update($data)) {
                 Flash::success('User updated');
                 return redirect(route('user.index'));
             } else {
                 Flash::error('Something went wrong while updating the user');
                 return redirect(route('user.edit', $username));
             }
         }
     } else {
         if ($request->get('action') == 'archive') {
             if ($ownAccount) {
                 Flash::warning('You cannot archive your own account');
             } else {
                 if ($user->archive()) {
                     Flash::success('User archived');
                 } else {
                     Flash::error('Something went wrong when archiving the user');
                 }
             }
             return redirect(route('user.edit', $username));
         } else {
             if ($request->get('action') == 'unarchive') {
                 if ($user->update(['status' => true])) {
                     Flash::success('User unarchived');
                 } else {
                     Flash::error('Something went wrong when unarchiving the user');
                 }
                 return redirect(route('user.edit', $username));
             } else {
                 if ($request->get('action') == 'change-pic') {
                     $file = $request->file('avatar');
                     if (!$file) {
                         Flash::warning('Please select an image to use');
                     } else {
                         $user->setAvatar($file);
                         Flash::success('Profile picture changed');
                     }
                     return redirect(route('user.edit', $username));
                 } else {
                     if ($request->get('action') == 'remove-pic') {
                         if ($user->hasAvatar()) {
                             $path = base_path('public') . $user->getAvatarUrl();
                             if (is_writeable($path)) {
                                 unlink($path);
                                 Flash::success("Profile picture removed");
                             } else {
                                 Flash::error("The user's picture is not writeable");
                             }
                         }
                         return redirect(route('user.edit', $username));
                     } else {
                         if ($request->get('action') == 'reset-password') {
                             $password = str_random(15);
                             $user->update(['password' => bcrypt($password)]);
                             Flash::success('New password sent');
                             Mail::queue('emails.users.reset_password', ['name' => $user->forename, 'password' => $password], function ($message) use($user) {
                                 $message->subject('Your new password')->to($user->email, $user->name);
                             });
                             return redirect(route('user.edit', $username));
                         } else {
                             return redirect(route('user.edit', $username));
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * @param $page
  */
 private function unpublishedFlash($page)
 {
     Flash::warning('Page not published', "The page '{$page->title}' is not visible to the public as it isn't published. <a href=\"" . route('page.edit', $page->slug) . "#published\">Edit the page</a>.");
 }
 /**
  * Delete a poll
  * @param int $id
  * @return Response
  */
 public function delete($id)
 {
     $poll = Poll::find($id);
     if ($poll) {
         $poll->delete();
         Flash::success('Poll deleted');
     }
     return redirect(route('polls.index'));
 }
 /**
  * Delete a resource.
  * @param                                   $id
  * @param \App\Http\Requests\GenericRequest $request
  * @return mixed
  */
 public function destroy($id, GenericRequest $request)
 {
     $request->requireAjax();
     $resource = Resource::find($id);
     if (!$resource) {
         return $this->ajaxError('Couldn\'t find that resource', 404);
     }
     $resource->delete();
     if ($resource->isFile()) {
         File::delete($resource->getFilePath());
     }
     Flash::success('Resource deleted');
     return Response::json(true);
 }
 /**
  * Delete a tag.
  * @param                                   $id
  * @param \App\Http\Requests\GenericRequest $request
  * @return mixed
  */
 public function destroy($id, GenericRequest $request)
 {
     // Require ajax
     $this->requireAjax($request);
     // Get the tag
     $tag = ResourceTag::find($id);
     if (!$tag) {
         return $this->ajaxError("Couldn't find that tag", 404);
     }
     // Delete
     $tag->delete();
     Flash::success('Tag deleted');
     return Response::json(true);
 }
 /**
  * Process the form for updating a repair's details.
  * @param                                   $id
  * @param \App\Http\Requests\GenericRequest $request
  * @return \Illuminate\Http\Response
  */
 public function update($id, GenericRequest $request)
 {
     // Get the breakage entry
     $breakage = EquipmentBreakage::findOrFail($id);
     // Updating the event's details
     if ($request->get('action') == 'update') {
         // Validate
         $this->validate($request, ['status' => 'required|in:' . implode(',', array_keys(EquipmentBreakage::$status))], ['status.required' => 'Please choose a status for the breakage', 'status.in' => 'Please choose a valid status']);
         // Update, message and redirect
         $breakage->update($request->stripped('comment', 'status') + ['closed' => $request->get('status') == EquipmentBreakage::STATUS_RESOLVED]);
         Flash::success('Breakage updated');
     } else {
         if ($request->get('action') == 'close') {
             $breakage->update(['closed' => true]);
             Flash::success('Breakage closed');
         }
     }
     return redirect(route('equipment.repairs'));
 }
 /**
  * Send an email to an event's crew.
  * @param                                   $id
  * @param \App\Http\Requests\GenericRequest $request
  * @return Response
  */
 public function emailCrew($id, GenericRequest $request)
 {
     // Get the event
     $event = Event::find($id);
     if (!$event) {
         return $this->ajaxError('Couldn\'t find that event', 404);
     }
     // Validate the input
     $this->validate($request, ['subject' => 'required', 'message' => 'required'], ['subject.required' => 'Please enter the subject', 'message.required' => 'Please enter the message']);
     // Add the event email
     $event->emails()->create(['sender_id' => $this->user->id, 'header' => $request->stripped('subject'), 'body' => $request->stripped('body')]);
     // Send the email
     $subject = $request->stripped('subject');
     Mail::queue('emails.events.crew_email', ['body' => $request->stripped('message'), 'name' => $event->em ? $event->em->name : ''], function ($message) use($event, $subject) {
         $message->subject($subject);
         if ($event->em_id) {
             $message->from($event->em->email, $event->em->name);
         }
         foreach ($event->crew as $crew) {
             $message->to($crew->user->email, $crew->user->name);
         }
     });
     Flash::success('Email sent');
     return Response::json(true);
 }
Esempio n. 13
0
 /**
  * Make the user an associate
  * @return bool
  */
 public function makeAssociate()
 {
     if ($this->id == Auth::user()->id) {
         Flash::warning('You cannot make yourself an associate');
         return false;
     }
     $this->roles()->sync([Role::where('name', 'associate')->first()->id]);
     return true;
 }
 /**
  * @param \App\Http\Requests\GenericRequest $request
  * @return mixed
  */
 public function updatePassword(GenericRequest $request)
 {
     // Validate the input
     $this->validate($request, ['password' => 'required|min:5|confirmed'], ['password.required' => 'Please enter your new password', 'password.min' => 'Please use at least 5 characters', 'password.confirmed' => 'The password confirmation doesn\'t match']);
     // Update
     $this->user->update(['password' => bcrypt($request->get('password'))]);
     Flash::success('Password updated');
     return \Illuminate\Support\Facades\Response::json(true);
 }
 /**
  * Override the default method to provide a flash message on success.
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function postReset(Request $request)
 {
     $this->validate($request, ['token' => 'required', 'email' => 'required|email', 'password' => 'required|confirmed']);
     $credentials = $request->only('email', 'password', 'password_confirmation', 'token');
     $response = Password::reset($credentials, function ($user, $password) {
         $this->resetPassword($user, $password);
     });
     switch ($response) {
         case Password::PASSWORD_RESET:
             Flash::success('Success', 'Your password was changed successfully and you are now logged in.');
             return redirect($this->redirectPath());
         default:
             return redirect()->back()->withInput($request->only('email'))->withErrors(['summary' => trans($response)]);
     }
 }
 /**
  * Delete a committee role.
  * @param \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request)
 {
     // Require ajax
     $this->requireAjax($request);
     // Check that a role exists for the given ID
     $role = CommitteeRole::find($request->get('id'));
     if (!$role) {
         return response("Could not find the committee role.", 422);
     }
     // Delete the role
     if ($role->delete()) {
         Flash::success('Committee role deleted');
         return response(['success' => true]);
     } else {
         return response("An error occurred when deleting the role.", 422);
     }
 }
 /**
  * Set the elected committee members.
  * @param $id
  * @param $request
  * @return mixed
  */
 public function elect($id, GenericRequest $request)
 {
     // Make sure AJAX
     $this->requireAjax($request);
     // Get the election
     $election = Election::find($id);
     if (!$election) {
         return $this->ajaxError('Couldn\'t find that election', 404);
     }
     // Check that voting has closed
     if (!$election->hasVotingClosed()) {
         return $this->ajaxError('Voting has not yet closed', 405);
     }
     // Validate the request
     $this->validate($request, ['elected' => 'array|each:required'], ['elected.array' => 'Please select the elected members', 'elected.each.required' => 'Please select the elected members']);
     // Set those elected
     $elected = $request->get('elected') ?: [];
     foreach ($election->nominations as $nomination) {
         $nomination->update(['elected' => in_array($nomination->id, $elected)]);
     }
     Flash::success('Saved');
     return Response::json(true);
 }