Example #1
0
 public function create(Request $req)
 {
     $record = new Record();
     $record->location_id = $req->get("location_id");
     $staff = Staff::where("staff_nr", "=", $req->get("staff_id"))->first();
     if ($staff == null) {
         return "oh fuk";
     }
     $record->staff_id = $staff->id;
     $record->particularities = $req->get("particularities");
     $record->save();
 }
 /**
  * Handles registration process of new volunteer.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return  JSON  array of status
  */
 public function addUserAccount(Request $request)
 {
     Volunteer::create(['nric' => $request->get('nric'), 'name' => $request->get('name'), 'email' => $request->get('email'), 'password' => $request->get('password'), 'gender' => $request->get('gender'), 'date_of_birth' => $request->get('dob'), 'contact_no' => $request->get('phone'), 'occupation' => $request->get('occupation'), 'has_car' => $request->get('haveCar'), 'minutes_volunteered' => '0', 'area_of_preference_1' => $request->get('preferences1'), 'area_of_preference_2' => $request->get('preferences2'), 'image_nric_front' => $request->get('frontIC'), 'image_nric_back' => $request->get('backIC'), 'rank_id' => Rank::where('min', 0)->first()->rank_id]);
     $volunteer = Volunteer::where('email', $request->get('email'))->first();
     $mailingList = Staff::where('is_admin', 'TRUE')->lists('email')->toArray();
     if ($volunteer == null) {
         $status = ["error"];
         return response()->json(compact('status'));
     } else {
         Mail::send('emails.volunteer_registration', compact('volunteer'), function ($message) use($mailingList) {
             $message->subject('New Volunteer Registration');
             $message->bcc($mailingList);
         });
         $status = ["Created successfully"];
         return response()->json(compact('status'));
     }
 }
 public function postReset(Request $request)
 {
     $this->validate($request, ['token' => 'required', 'email' => 'required|email', 'password' => 'required|confirmed|min:6']);
     $flag = Staff::where('email', $request->email)->get()->first();
     if ($flag->active == 0) {
         return redirect()->back()->with('message', 'Account is not active!');
     }
     $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:
             return redirect($this->redirectPath())->with('status', trans($response));
         default:
             return redirect()->back()->withInput($request->only('email'))->withErrors(['email' => trans($response)]);
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $sort = $request->get('sort');
     $sort = max($sort, 1);
     $qty = $request->get('show');
     $qty = max($qty, 10);
     $dep = (int) $request->get('dep');
     $sorts = array(1 => ['name' => 'asc'], ['name' => 'desc']);
     $department = '';
     // is manager
     // show all staff
     if (Gate::allows('check-manager')) {
         $staff = Staff::where('level_id', '!=', 6)->orderBy(key($sorts[$sort]), current($sorts[$sort]))->paginate($qty);
         if (isset($dep) && !empty($dep)) {
             $staff = Staff::where('level_id', '!=', 6)->where('department_id', $dep)->orderBy(key($sorts[$sort]), current($sorts[$sort]))->paginate($qty);
         }
         $department = Department::where('active', 1)->get();
     }
     // is leader
     // show staff in department
     if (Gate::allows('check-leader')) {
         $staff = Staff::where('level_id', '!=', 6)->where('department_id', Auth::user()->department_id)->orderBy(key($sorts[$sort]), current($sorts[$sort]))->paginate($qty);
     }
     // is admin
     // show all staff
     if (Gate::allows('check-admin')) {
         $staff = Level::where('active', 1)->where('role_id', 2)->orWhere('role_id', 3)->get();
     }
     // is developer
     // denied
     if (Gate::allows('check-developer')) {
         return redirect()->route('admin.department.index');
     }
     if (Auth::user()->level->role_id == 2 || Auth::user()->level->role_id == 3) {
         $staff->setPath('staff');
         $staff->appends('show', $qty);
         if (!empty($dep)) {
             $staff->appends('dep', $dep);
         }
     }
     return view('admin.staff.list', compact('staff', 'department'));
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $staff_team = '';
     $leader = '';
     $pie_leader = '';
     $department = '';
     $department = Department::leftJoin('staff', 'department.id', '=', 'staff.department_id')->join('level', 'staff.level_id', '=', 'level.id')->join('role', 'level.role_id', '=', 'role.id')->select(DB::raw('department.name as name_dep,role.name,count(*) as num'))->groupBy('department.name', 'role.name')->get()->toArray();
     $num_staff = $department;
     $pie = array();
     foreach ($department as $value) {
         $pie[$value['name_dep']][] = array($value['name'], (int) $value['num']);
     }
     // is Leader
     if (Gate::allows('check-leader')) {
         $department = Department::leftJoin('staff', 'department.id', '=', 'staff.department_id')->join('level', 'staff.level_id', '=', 'level.id')->join('role', 'level.role_id', '=', 'role.id')->select(DB::raw('department.name as name_dep,role.name,count(*) as num'))->where(['department.id' => Auth::user()->department_id, 'department.active' => 1])->groupBy('department.name', 'role.name')->get()->toArray();
         $num_staff = $department;
         $pie = array();
         foreach ($department as $value) {
             $pie[$value['name_dep']][] = array($value['name'], (int) $value['num']);
         }
     }
     // is Developer
     // if is manager / != department / yourself
     // denied
     if (Gate::allows('check-developer')) {
         // get team of staff
         $staff = StaffTeam::where('staff_id', Auth::user()->id)->get()->first();
         if (isset($staff) && !empty($staff)) {
             $staff_team = StaffTeam::where('team_id', $staff->team_id)->where('staff_id', '!=', Auth::user()->id)->get();
             $team = Team::where('id', $staff->team_id)->get()->first();
             $leader = Staff::find($team->creator);
         }
         // staff in department
         $staff_department = Staff::where(['active' => 1, 'department_id' => Auth::user()->department_id])->get();
     }
     return view('admin.department.home', compact('pie', 'staff_team', 'leader', 'num_staff', 'staff_department'));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $slug)
 {
     // Validation
     $this->validate($request, ['first_name' => 'required|min:2|max:20', 'last_name' => 'required|min:2|max:30', 'age' => 'required|integer|between:0,130', 'profile_image' => 'image|between:0,2000']);
     // Find the user or staff member to edit
     $staffMember = Staff::where('slug', $slug)->firstOrFail();
     $staffMember->first_name = $request->first_name;
     $staffMember->last_name = $request->last_name;
     $staffMember->age = $request->age;
     // Insert a slug into the request
     $staffMember->slug = str_slug($request->first_name . ' ' . $request->last_name);
     // If the user provided a new image
     if ($request->hasFile('profile_image')) {
         // Generare a new file name
         $fileExtension = $request->file('profile_image')->getClientOriginalExtension();
         $fileName = 'staff-' . uniqid() . '.' . $fileExtension;
         $request->file('profile_image')->move('img/staff', $fileName);
         \Image::make('img/staff/' . $fileName)->resize(240, null, function ($constraint) {
             $constraint->aspectRatio();
         })->save('img/staff/' . $fileName);
         // Delete the old image
         \File::Delete('img/staff/' . $staffMember->profile_image);
         // Tell  database
         $staffMember->profile_image = $fileName;
     }
     // Update the database
     $staffMember->save();
     return redirect('about/' . $staffMember->slug);
 }
Example #7
0
 public function exists(Request $req)
 {
     return ['exists' => Staff::where('staff_nr', '=', $req->get('staff_nr'))->get()->count() > 0];
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $findPosition = Staff::where('position_id', $id)->get()->toArray();
     if (!empty($findPosition)) {
         return redirect()->route('admin.position.index')->with('message', 'Can\'t delete position !');
     }
     $position = Position::find($id);
     $position->delete();
     return redirect()->route('admin.position.index')->with('message', 'Delete position success!');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $slug)
 {
     // Validation
     $this->validate($request, ['first_name' => 'required|min:2|max:20', 'last_name' => 'required|min:2|max:30', 'age' => 'required|between:0,130|integer', 'profile_image' => 'image|between:0,2000']);
     // Find the user or staff member to edit where slug is equal to whatever came back from the form
     $staffMember = Staff::where('slug', $slug)->firstOrFail();
     // Makes changes to the database
     $staffMember->first_name = $request->first_name;
     $staffMember->last_name = $request->last_name;
     $staffMember->age = $request->age;
     // Referencing the existing slug and assigning to it the new slug based on changes made to the staff members name
     $staffMember->slug = str_slug($request->first_name . ' ' . $request->last_name);
     // If the user provided a new image then save that image
     if ($request->hasFile('profile_image')) {
         // Change the image file name, move the image file and resize the image
         // Grab the file extension of the image
         $fileExtension = $request->file('profile_image')->getClientOriginalExtension();
         // Generate a new profile image name to avoid duplication and join the two together
         //                            ^ ^
         $fileName = 'staff-' . uniqid() . '.' . $fileExtension;
         //                             -
         $request->file('profile_image')->move('img/staff', $fileName);
         // Grabbed the profile image and resized it
         \Image::make('img/staff/' . $fileName)->resize(240, null, function ($constrait) {
             $constrait->aspectRatio();
         })->save('img/staff/' . $fileName);
         // Delete the old image
         \File::Delete('img/staff/' . $staffMember->profile_image);
         // Tell the database of the new image
         $staffMember->profile_image = $fileName;
     }
     // Save the changes to the database
     $staffMember->save();
     // Redirect user to the staff members page with the updated changes
     return redirect('about/' . $staffMember->slug);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $type, $id)
 {
     if ($type == 'event' || $type == 'page') {
         try {
             $event = Event::where('slug', $id)->where('type', $type)->firstOrFail();
         } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return view('errors.pageNotFound');
         }
         if ($type == 'event') {
             $this->validate($request, ['title' => 'required|max:50', 'content' => 'required|max:10000', 'start_date' => 'required|date|before:end_date', 'end_date' => 'required|date|after:start_date', 'start_time' => 'date_format:H:i|before:end_time', 'end_time' => 'date_format:H:i|after:start_time', 'number' => 'max:12', 'street' => 'max:40', 'suburb' => 'max:40', 'area' => 'max:40', 'country' => 'max:30', 'image[]' => 'image']);
             if ($request->status == 0 || $request->status == 1) {
                 $event->status = $request->status;
             } elseif ($request->status == 2) {
                 foreach ($event->images as $image) {
                     $original = 'img/site/original/';
                     $sliderPath = 'img/site/slider/';
                     $galleryThumbPath = 'img/site/gallery/thumbnail/';
                     $galleryPrevPath = 'img/site/gallery/preview/';
                     $thumbnail = 'img/site/thumbnail/';
                     $imagedb = Image::where('id', $image->id)->first();
                     \File::delete([$sliderPath . $imagedb->image, $galleryPrevPath . $imagedb->image, $galleryThumbPath . $imagedb->image, $thumbnail . $imagedb->image, $original . $imagedb->image]);
                     EventImage::where('event_id', $event->id)->where('image_id', $image->id)->delete();
                     $imagedb->delete();
                 }
                 $event->delete();
                 return redirect('/admin/' . $type . '/');
             }
             $event->title = $request->title;
             $event->content = $request->content;
             $event->start_date = str_replace('-', '/', $request->start_date);
             $event->end_date = str_replace('-', '/', $request->end_date);
             $event->start_time = $request->start_time;
             $event->end_time = $request->end_time;
             $event->save();
             $event->locations->number = $request->number;
             $event->locations->street = $request->street;
             $event->locations->suburb = $request->suburb;
             $event->locations->area = $request->area;
             $event->locations->country = $request->country;
             $event->locations->location_map = $request->number . '+' . $request->street . ',+' . $request->suburb . ',+' . $request->area . ',+' . $request->country;
             $event->locations->location_map = str_replace(' ', '+', $event->locations->location_map);
             $event->locations->save();
             $original = 'img/site/original/';
             $sliderPath = 'img/site/slider/';
             $galleryThumbPath = 'img/site/gallery/thumbnail/';
             $galleryPrevPath = 'img/site/gallery/preview/';
             $thumbnail = 'img/site/thumbnail/';
             if ($request->hasFile('image')) {
                 $counter = 0;
                 foreach ($request->file('image') as $image) {
                     $fileName = uniqid() . '.' . $request->file('image')[$counter]->getClientOriginalName();
                     $imageSource = \Image::make($request->file('image')[$counter]);
                     $imageSource->save($original . $fileName);
                     \Image::make($request->file('image')[$counter])->resize(1000, null, function ($constraint) {
                         $constraint->aspectRatio();
                     })->save($galleryPrevPath . $fileName, 80);
                     \Image::make($request->file('image')[$counter])->resize(1000, null, function ($constraint) {
                         $constraint->aspectRatio();
                     })->crop(1000, 400, 0, 0)->save($sliderPath . $fileName, 80);
                     \Image::make($request->file('image')[$counter])->fit(100, 100)->save($galleryThumbPath . $fileName, 80);
                     \Image::make($request->file('image')[$counter])->fit(250, 150)->save($thumbnail . $fileName, 80);
                     $imagedb = new Image();
                     $eventImage = new EventImage();
                     $imagedb->image = $fileName;
                     $imagedb->save();
                     $eventImage->image_id = $imagedb->id;
                     $eventImage->event_id = $event->id;
                     $eventImage->save();
                     $counter++;
                 }
             }
             if (count($request->currentImage) > 0) {
                 foreach ($request->currentImage as $checked) {
                     $imagedb = Image::where('id', $checked)->first();
                     \File::delete([$sliderPath . $imagedb->image, $galleryPrevPath . $imagedb->image, $galleryThumbPath . $imagedb->image, $thumbnail . $imagedb->image, $original . $imagedb->image]);
                     EventImage::where('event_id', $event->id)->where('image_id', $checked)->delete();
                     $imagedb->delete();
                 }
             }
         } elseif ($type == 'page') {
             $event->content = $request->content;
             $event->save();
         }
     } elseif ($type == 'staff') {
         try {
             $event = Staff::where('slug', $id)->firstOrFail();
         } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return view('errors.pageNotFound');
         }
         $event->title = $request->title;
         $event->name = $request->name;
         $event->slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $event->name)));
         $original = 'img/site/original/';
         $staff = 'img/site/staff/';
         if ($request->hasFile('photo')) {
             if ($event->image != 'default.png') {
                 \File::delete([$original . $event->image, $staff . $event->image]);
             }
             $fileName = uniqid() . '.' . $request->file('photo')->getClientOriginalName();
             $imageSource = \Image::make($request->file('photo'));
             $imageSource->save($original . $fileName);
             \Image::make($request->file('photo'))->fit(190, 190)->save($staff . $fileName, 80);
             $event->image = $fileName;
         }
         $event->save();
         return redirect('/admin/' . $type . '/');
     } elseif ($type == 'video') {
         try {
             $event = Video::where('slug', $id)->firstOrFail();
         } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return view('errors.pageNotFound');
         }
         $event->title = $request->title;
         $event->description = $request->description;
         $event->player = $request->player;
         if ($request->player == 'youtube') {
             $event->video = substr($request->video, -11);
         } elseif ($request->player == 'vimeo') {
             $event->video = substr($request->video, -9);
         }
         $event->slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $event->title)));
         $event->save();
         return redirect('/admin/' . $type . '/');
     } else {
         return view('errors.404');
     }
     if (isset($request->preview)) {
         return redirect('/' . $type . '/' . $event->slug);
     } else {
         return redirect('/admin/' . $type . '/' . $event->slug . '/edit');
     }
 }
 public function getuserinfodelete($uid)
 {
     $deleteUserInfo = Staff::where('institute_code', '=', Auth::user()->institute_id)->Where('id', '=', $uid)->delete();
     //$deleteUserInfo=Staff::where('institute_code', '=', Auth::user()->institute_id)->Where('id', '=', $uid)->delete();
     return Redirect::to('user/index');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $slug)
 {
     //validation
     $this->validate($request, ['first_name' => 'required|min:2|max:20', 'last_name' => 'required|min:2|max:30', 'age' => 'required|between:0,130|integer', 'profile_image' => 'image|between:1,2000']);
     //Find the staff member to edit
     $staffMember = \App\Staff::where('slug', $slug)->firstOrFail();
     $staffMember->first_name = $request->first_name;
     $staffMember->last_name = $request->last_name;
     $staffMember->age = $request->age;
     $staffMember->slug = str_slug($request->first_name . ' ' . $request->last_name);
     //if the user provided the new image
     if ($request->hasFile('profile_image')) {
         //generate a new file name and extention
         $fileExtension = $request->file('profile_image')->getClientOriginalExtension();
         $fileName = 'staff-' . uniqid() . '.' . $fileExtension;
         //move file in to its destination
         $request->file('profile_image')->move('img/staff/', $fileName);
         \Image::make('img/staff/' . $fileName)->resize(240, null, function ($constraint) {
             $constraint->aspectRatio();
         })->save('img/staff/' . $fileName);
         //delete the old image
         \File::Delete('img/staff/' . $staffMember->profile_image);
         //tell the database of the new image
         $staffMember->profile_image = $fileName;
     }
     $staffMember->save();
     return redirect('about/' . $staffMember->slug);
 }
 /**
  * Handles the withdrawal of activity from user.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return  JSON  array with Status
  */
 public function withdraw(Request $request)
 {
     if ($request->get('volunteer_id') == null || $request->get('activity_id') == null) {
         $status = ["Missing parameter"];
         return response()->json(compact('status'));
     } else {
         $volunteer_id = $request->get('volunteer_id');
         $activity_id = $request->get('activity_id');
         $volunteer = Volunteer::findOrFail($volunteer_id);
         $withdrawnActivity = Activity::findOrFail($activity_id);
         $task = Task::where('volunteer_id', $volunteer_id)->where('activity_id', $activity_id)->update(['approval' => 'withdrawn']);
         $mailingList = Staff::where('is_admin', 'TRUE')->lists('email')->toArray();
         $status = ["Withdrawn from activity"];
         Mail::send('emails.volunteer_withdraw', compact('volunteer', 'withdrawnActivity'), function ($message) use($mailingList) {
             $message->subject('A volunteer has withdrawn from an activity');
             $message->to($mailingList);
         });
         return response()->json(compact('status'));
     }
 }
Example #14
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $staff = Staff::where('user_id', '=', $id)->firstOrFail();
     $title = $staff->firstname . "" . $staff->lastname;
     return view('admin.show')->with('staff', $staff)->with('title', $title);
 }