/** * Install */ protected function install($request) { // Modify env $dir = base_path(); $ret = true; /* $ret = copy( $dir . '/.env.example', $dir . '/.env' ); */ if ($ret) { modifyEnv(['DB_HOST' => $request->get('db_host'), 'DB_DATABASE' => $request->get('db_name'), 'DB_USERNAME' => $request->get('db_user'), 'DB_PASSWORD' => $request->get('db_password')]); } // Migration try { $exitCode = Artisan::call('migrate'); } catch (Exception $e) { $messageBag = new \Illuminate\Support\MessageBag(); $messageBag->add('db_name', ' '); $messageBag->add('db_connect', 'Mysql database fail'); Flash::error(trans('app.Operation failed')); $request->flash(); return redirect()->back()->withErrors($messageBag); } // Initialize data $this->initializeData($request); // install.lock touch(base_path() . '/install.lock'); return redirect()->route('home'); }
/** * Show the form for creating a new resource. * * @return Response */ public function save() { $rules = ['firstname' => 'required', 'lastname' => 'required', 'login' => 'required', 'address' => 'required', 'cpassword' => 'required', 'npassword' => 'required', 'cnpassword' => 'required']; $validator = \Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/settings')->withinput(Input::all())->withErrors($validator); } else { if (Input::get('npassword') == Input::get('cnpassword')) { // $u = User::select('*')->where('password',Hash::make(Input::get('cpassword')))->first(); //return Hash::make(Input::get('cpassword')); //if(count($u)>0) { $user = User::find(Input::get('id')); $user->firstname = Input::get('firstname'); $user->lastname = Input::get('lastname'); // $user->login = Input::get('login'); $user->address = Input::get('address'); // $user->email = Input::get('email'); $user->password = Hash::make(Input::get('npassword')); $user->save(); return Redirect::to('/settings')->with('success', 'Settings is changed please relogin the site.'); /*} else { $errorMessages = new Illuminate\Support\MessageBag; $errorMessages->add('notmatch', 'Current Password did not match!'); return Redirect::to('/settings')->withErrors($errorMessages); }*/ } else { $errorMessages = new Illuminate\Support\MessageBag(); $errorMessages->add('notmatch', 'New Password and confirm password did not match!'); return Redirect::to('/settings')->withErrors($errorMessages); } } }
/** * Show the form for creating a new resource. * * @return Response */ public function create() { $rules = ['name' => 'required', 'code' => 'required', 'type' => 'required', 'subgroup' => 'required', 'stdgroup' => 'required', 'class' => 'required', 'totalfull' => 'required', 'wfull' => 'required', 'mfull' => 'required', 'sfull' => 'required', 'pfull' => 'required']; $validator = \Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/subject/create')->withErrors($validator); } else { $exsubject = Subject::select('*')->where('class', Input::get('class'))->where('code', Input::get('code'))->get(); if (count($exsubject) > 0) { $errorMessages = new Illuminate\Support\MessageBag(); $errorMessages->add('deplicate', 'subject all ready exists for this class!!'); return Redirect::to('/subject/create')->withErrors($errorMessages); } else { $subject = new Subject(); $subject->name = Input::get('name'); $subject->code = Input::get('code'); $subject->class = Input::get('class'); $subject->type = Input::get('type'); $subject->subgroup = Input::get('subgroup'); $subject->stdgroup = Input::get('stdgroup'); $subject->totalfull = Input::get('totalfull'); $subject->totalpass = Input::get('totalpass'); $subject->wfull = Input::get('wfull'); $subject->wpass = Input::get('wpass'); $subject->mfull = Input::get('mfull'); $subject->mpass = Input::get('mpass'); $subject->sfull = Input::get('sfull'); $subject->spass = Input::get('spass'); $subject->pfull = Input::get('pfull'); $subject->ppass = Input::get('ppass'); $subject->save(); return Redirect::to('/subject/create')->with("success", "Subject Created Succesfully."); } } }
public function postStore() { $sid = \Input::get('id'); /* * Validate */ $rules = array('email' => 'required|unique:mailinglists,email' . (isset($sid) ? ',' . $sid : ''), 'first_name' => 'required', 'last_name' => 'required'); $validation = \Validator::make(\Input::all(), $rules); if ($validation->passes()) { $email = \Input::get('email'); $first_name = \Input::get('first_name'); $last_name = \Input::get('last_name'); $active = \Input::get('active') == '' ? false : true; $mailinglist = isset($sid) ? Mailinglist::find($sid) : new Mailinglist(); // No such id if ($mailinglist == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('storeError', "We are having problem editing this entry. It may have already been deleted."); return redirect('admin/mailinglists')->withErrors($errors); } $mailinglist->email = $email; $mailinglist->first_name = $first_name; $mailinglist->last_name = $last_name; $mailinglist->active = $active; $mailinglist->save(); } else { if (isset($sid)) { return redirect('admin/mailinglists/edit/' . $sid)->withErrors($validation)->withInput(); } else { return redirect('admin/mailinglists/create')->withErrors($validation)->withInput(); } } return redirect('admin/mailinglists'); }
public function postOrders() { $input_start_date = \Input::get('start_date'); if ($input_start_date == "") { $input_start_date = "01/01/1900"; } $start_date = \DateTime::createFromFormat('d/m/Y', $input_start_date); $input_end_date = \Input::get('end_date'); if ($input_end_date == "") { $end_date = new \DateTime("NOW"); } else { $end_date = \DateTime::createFromFormat('d/m/Y', $input_end_date); } $data = Order::where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->orderBy('created_at', 'desc')->get(); if (count($data) == 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('downloadError', "There's no data within the dates specified."); return \Redirect::to('admin/orders')->withErrors($errors); } \Excel::create('Redmin_Orders_Report', function ($excel) use($data) { $excel->sheet('Orders Report', function ($sheet) use($data) { $sheet->loadView('redminportal::reports/orders')->with('data', $data); }); })->download('xlsx'); }
public function postLogin() { /* * Validate */ $rules = array('email' => 'required|email', 'password' => 'required'); $validation = \Validator::make(\Input::all(), $rules); if ($validation->passes()) { $email = \Input::get('email'); $password = \Input::get('password'); try { $credentials = array('email' => $email, 'password' => $password); // Authenticate the user $user = \Sentry::authenticate($credentials, false); } catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('invalid', "This user hasn't been activated. Please contact us for support."); return \Redirect::to('admin')->withErrors($errors)->withInput(); } catch (\Exception $e) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('invalid', "Oops, your email or password is incorrect."); return \Redirect::to('admin')->withErrors($errors)->withInput(); } return \Redirect::to('admin'); } return \Redirect::to('admin')->withErrors($validation)->withInput(); }
/** * @return mixed */ public function postLogin() { // If the user is logged in, they don't need to see this if ($this->user->isLoggedIn()) { return Redirect::to(Coanda::adminUrl('/')); } try { $this->user->login(Input::get('email'), Input::get('password')); if (Session::has('pre_auth_path')) { $redirect_path = Session::pull('pre_auth_path'); if (Session::has('pre_auth_query_string')) { $redirect_path .= '?' . Session::pull('pre_auth_query_string'); } return Redirect::to($redirect_path); } return Redirect::to(Coanda::adminUrl('/')); } catch (MissingInput $exception) { $errors = new \Illuminate\Support\MessageBag(); foreach ($exception->getMissingFields() as $missing_field) { $errors->add($missing_field, Lang::get('coanda::errors.missing_' . $missing_field)); } return Redirect::to(Coanda::adminUrl('login'))->withInput()->withErrors($errors); } catch (AuthenticationFailed $exception) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('username', Lang::get('coanda::errors.invalid_username')); return Redirect::to(Coanda::adminUrl('login'))->withInput()->withErrors($errors); } }
public function doLogin() { if (Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password'), 'active' => 1))) { return Redirect::intended('dashboard'); } $errors = new Illuminate\Support\MessageBag(); $errors->add('error', 'An error occurred while logging in. Check your username/password and try again.'); return Redirect::to('login')->withInput(Input::except('password'))->withErrors($errors); }
public function getDelete($sid) { $purchase = UserPricelist::find($sid); if ($purchase == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('userError', "The purchase record may have already been deleted."); return redirect('admin/purchases')->withErrors($errors); } $purchase->delete(); return redirect('admin/purchases'); }
public function getDeletediscount($id) { $discount = Discount::find($id); // No such id if ($discount == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The discount may have been deleted."); return \Redirect::to('admin/pricelists')->withErrors($errors)->withInput(); } $discount->delete(); return \Redirect::to('admin/pricelists'); }
public function getDelete($id) { // Find the mailinglist using the user id $mailinglist = Mailinglist::find($id); // Delete the mailinglist if ($mailinglist == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "We are having problem deleting this entry. It may have already been deleted."); return \Redirect::to('admin/mailinglists')->withErrors($errors); } $mailinglist->delete(); return \Redirect::to('admin/mailinglists'); }
public function postLogin() { $validator = Validator::make(Input::all(), array('username' => 'required'), array('password' => 'required')); if ($validator->fails()) { return Redirect::back()->withErrors($validator); } else { if (Auth::attempt(['username' => Input::get('username'), 'password' => Input::get('password')])) { return Redirect::to('admin/dashboard'); } else { $errors = new \Illuminate\Support\MessageBag(); $errors->add('error', 'Credenciais inválidas.'); return \Redirect::back()->withErrors($errors); } } }
public function postLogin() { $validator = Validator::make(Input::all(), array('id' => 'required'), array('birthday' => 'required')); if ($validator->fails()) { return Redirect::back()->withErrors($validator); } else { $voter = Voter::where(['id' => Input::get('id'), 'birthday' => Input::get('birthday')])->first(); if ($voter) { Session::put('voter_logged_in', 1); Session::put('voter_id', $voter->id); return Redirect::to('voter/dashboard'); } else { $errors = new \Illuminate\Support\MessageBag(); $errors->add('error', 'Credenciais inválidas.'); return Redirect::back()->withErrors($errors); } } }
public function postStore() { $sid = \Input::get('id'); $rules = array('pricelist_id' => 'required|integer', 'transaction_id' => 'required', 'payment_status' => 'required', 'paid' => 'numeric', 'email' => 'required|email'); $validation = \Validator::make(\Input::all(), $rules); $redirect_url = isset($sid) ? 'admin/purchases/edit/' . $sid : 'admin/purchases/create'; if ($validation->fails()) { return redirect($redirect_url)->withErrors($validation)->withInput(); } $pricelist_id = \Input::get('pricelist_id'); $transaction_id = \Input::get('transaction_id'); $payment_status = \Input::get('payment_status'); $paid = \Input::get('paid'); $email = \Input::get('email'); $pricelist = Pricelist::find($pricelist_id); // No such pricelist if ($pricelist == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('pricelistError', "The Module/Membership may have been deleted. Please try again."); return redirect($redirect_url)->withErrors($errors)->withInput(); } $user = User::where('email', $email)->first(); if ($user == null) { // No such user $errors = new \Illuminate\Support\MessageBag(); $errors->add('userError', "The user may have been deleted. Please try again."); return redirect($redirect_url)->withErrors($errors)->withInput(); } // Check if user_pricelist already exist $existing = UserPricelist::join('order_pricelist', 'orders.id', '=', 'order_pricelist.id')->where('orders.user_id', $user->id)->where('order_pricelist.pricelist_id', $pricelist->id)->count(); if ($existing > 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('userpricelistError', $email . " has already purchased " . $pricelist->module->name . " (" . $pricelist->membership->name . ")."); return redirect($redirect_url)->withErrors($errors)->withInput(); } $new_purchase = new UserPricelist(); $new_purchase->user_id = $user->id; $new_purchase->pricelist_id = $pricelist->id; $new_purchase->paid = $paid; $new_purchase->transaction_id = $transaction_id; $new_purchase->payment_status = $payment_status; $new_purchase->save(); return redirect('admin/purchases'); }
public function postLogin() { if (Auth::check()) { return redirect('/'); } $rules = array('email' => 'required|email', 'password' => 'required'); $validation = \Validator::make(\Input::all(), $rules); if ($validation->fails()) { return redirect('login')->withErrors($validation)->withInput(); } $email = \Input::get('email'); $password = \Input::get('password'); if (Auth::attempt(['email' => $email, 'password' => $password, 'activated' => 1])) { return redirect()->intended('admin/dashboard'); } $errors = new \Illuminate\Support\MessageBag(); $errors->add('invalid', "Oops, your email or password is incorrect."); return redirect('login')->withErrors($errors)->withInput(); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $response = $next($request); $user = \Auth::user(); if ($user != null && $user->enabled == 0) { \Auth::logout(); $error = new \Illuminate\Support\MessageBag(); $error->add('Disalbed', 'User is not enabled.'); return redirect('auth/login')->with(['errors' => $error]); } else { if ($user != null && isAdmin()) { return redirect('admin/dashboard'); } else { if ($user != null && isCustomer()) { return redirect('members/dashboard'); } } } return $response; }
public function getDelete($id) { // Find the membership using the user id $membership = Membership::find($id); if ($membership == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The membership cannot be found. It could have already been deleted."); return \Redirect::to('/admin/memberships')->withErrors($errors); } // Cannot delete if in use $modMediaMembership = ModuleMediaMembership::where('membership_id', $id)->get(); if (count($modMediaMembership) > 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The membership cannot be deleted because it is in used."); return \Redirect::to('/admin/memberships')->withErrors($errors); } // Delete the membership $membership->delete(); return \Redirect::to('admin/memberships'); }
public function update() { $rules = ['firstname' => 'required', 'lastname' => 'required', 'email' => 'required|email', 'group' => 'required', 'address' => 'required', 'login' => 'required', 'password' => 'required']; $validator = \Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/usersedit/' . Input::get('id'))->withErrors($validator); } else { $uexits = User::select('*')->where('email', '=', Input::get('email'))->first(); if (count($uexits) > 0) { if ($uexits->id != Input::get('id')) { $errorMessages = new Illuminate\Support\MessageBag(); $errorMessages->add('deplicate', 'User all ready exists with this email'); return Redirect::to('/users')->withInput(Input::all())->withErrors($errorMessages); } else { $user = User::find(Input::get('id')); $user->firstname = Input::get('firstname'); $user->lastname = Input::get('lastname'); // $user->login = Input::get('login'); $user->address = Input::get('address'); $user->email = Input::get('email'); $user->group = Input::get('group'); $user->password = Hash::make(Input::get('password')); $user->save(); return Redirect::to('/users')->with("success", "User Updated Succesfully."); } } else { $user = User::find(Input::get('id')); $user->firstname = Input::get('firstname'); $user->lastname = Input::get('lastname'); // $user->login = Input::get('login'); $user->address = Input::get('address'); $user->email = Input::get('email'); $user->group = Input::get('group'); $user->password = Hash::make(Input::get('password')); $user->save(); return Redirect::to('/users')->with("success", "User Updated Succesfully."); } } }
/** * Show the form for creating a new resource. * * @return Response */ public function create() { $rules = ['name' => 'required', 'code' => 'required|max:20', 'description' => 'required']; $validator = \Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/class/create')->withErrors($validator); } else { $clcode = 'cl' . Input::get('code'); $cexists = ClassModel::select('*')->where('code', '=', $clcode)->get(); if (count($cexists) > 0) { $errorMessages = new Illuminate\Support\MessageBag(); $errorMessages->add('deplicate', 'Class all ready exists!!'); return Redirect::to('/class/create')->withErrors($errorMessages); } else { $class = new ClassModel(); $class->name = Input::get('name'); $class->code = $clcode; $class->description = Input::get('description'); $class->save(); return Redirect::to('/class/create')->with("success", "Class Created Succesfully."); } } }
protected function addError($var, $description) { $this->errors->add($var, $description); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $rules = ['nclass' => 'required', 'nsection' => 'required', 'nshift' => 'required', 'nsession' => 'required']; $validator = \Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/promotion')->withInput(Input::all())->withErrors($validator); } else { if (Input::get('class') == Input::get('nclass')) { $errorMessages = new Illuminate\Support\MessageBag(); $errorMessages->add('validation', 'Promotion From and Promotion To class shouldn not be same!'); return Redirect::to('/promotion')->withInput(Input::all())->withErrors($errorMessages); } else { $promotion = Input::get('promot'); $promotion = array_keys($promotion); $newrollNo = Input::get('newrollNo'); $ids = array_keys($newrollNo); if (count($promotion) < 1) { $errorMessages = new Illuminate\Support\MessageBag(); $errorMessages->add('validation', 'Select Student!'); return Redirect::to('/promotion')->withInput(Input::all())->withErrors($errorMessages); } $realPromot = array(); for ($i = 0; $i < count($promotion); $i++) { $rollnumber = $this->checkRollno($promotion[$i], $ids, $newrollNo); if ($rollnumber == '') { $errorMessages = new Illuminate\Support\MessageBag(); $errorMessages->add('validation', 'New Roll number can not be empty!'); return Redirect::to('/promotion')->withInput(Input::all())->withErrors($errorMessages); } if ($rollnumber != 'No') { $foo = array($promotion[$i], $rollnumber); array_push($realPromot, $foo); } } //get new regiNo and student info foreach ($realPromot as $rpromt) { $studentIno = Student::select('*')->where('regiNo', $rpromt[0])->first(); $newStudent = new Student(); if (Input::get('nclass') == "cl10" || Input::get('nclass') == "cl12") { $newStudent->regiNo = $rpromt[0]; } else { $newRegNo = $this->getRegi(Input::get('nclass'), Input::get('nsession'), Input::get('nsection')); $newStudent->regiNo = $newRegNo[0]; } $newStudent->rollNo = $rpromt[1]; $newStudent->session = trim(Input::get('nsession')); $newStudent->class = Input::get('nclass'); $newStudent->section = Input::get('nsection'); $newStudent->shift = Input::get('nshift'); $newStudent->group = $studentIno->group; $newStudent->firstName = $studentIno->firstName; $newStudent->middleName = $studentIno->middleName; $newStudent->lastName = $studentIno->lastName; $newStudent->gender = $studentIno->gender; $newStudent->religion = $studentIno->religion; $newStudent->bloodgroup = $studentIno->bloodgroup; $newStudent->nationality = $studentIno->nationality; $newStudent->dob = $studentIno->dob; $newStudent->photo = $studentIno->photo; $newStudent->extraActivity = $studentIno->extraActivity; $newStudent->remarks = $studentIno->remarks; $newStudent->fatherName = $studentIno->fatherName; $newStudent->fatherCellNo = $studentIno->fatherCellNo; $newStudent->motherName = $studentIno->motherName; $newStudent->motherCellNo = $studentIno->motherCellNo; $newStudent->localGuardian = $studentIno->localGuardian; $newStudent->localGuardianCell = $studentIno->localGuardianCell; $newStudent->presentAddress = $studentIno->presentAddress; $newStudent->parmanentAddress = $studentIno->parmanentAddress; $newStudent->isActive = "Yes"; $newStudent->save(); } return Redirect::to('/promotion')->with('success', count($realPromot) . ' Students Promoted.'); } } }
public function getImgremove($id) { $image = Image::find($id); if ($image == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The image cannot be deleted at this time."); return \Redirect::to('/admin/announcements')->withErrors($errors); } $announcement_id = $image->imageable_id; $image->remove(); return \Redirect::to('admin/announcements/edit/' . $announcement_id); }
/** * Monta a view para editar um objeto * * @return void */ public function getEdit($id) { $target = (new $this->model())->find($id); if ($target) { $models = []; foreach ($this->properties as $pop => $val) { if ($val['type'] == 'relationship') { $models[$val['model']] = (new $val['model']())->lists($val['model_desc'], 'id'); } } return View::make('admin.scaffolding.new', ['uri' => $this->uri, 'title' => $this->title, 'properties' => $this->properties, 'target' => $target, 'models' => $models]); } else { $bag = new \Illuminate\Support\MessageBag(); $bag->add('error', 'Código inválido.'); return Redirect::to("admin/{$this->uri}")->withErrors($bag); } }
public function getDelete($id) { // Find the product using the user id $product = Product::find($id); if ($product == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "We are having problem deleting this entry. Please try again."); return \Redirect::to('admin/products')->withErrors($errors); } // Delete all images first $product->deleteAllImages(); // Delete all tags $product->deleteAllTags(); // Delete the product $product->delete(); return Redirect::to('admin/products'); }
public function loginCandidate() { // return Redirect::to('')->withInfo('Your details weren’t accepted – please register for access to a candidate portal'); $validator = Validator::make(Input::all(), array('email' => 'required|email', 'password' => 'required')); if ($validator->fails()) { return Redirect::back()->withErrors($validator->messages()); } $email = Input::get('email'); $password = Input::get('password'); if ($candidate = Candidate::where('email', '=', $email)->first()) { if (Hash::check($password, $candidate->password)) { if ($candidate->active == 1) { $candidate->last_login = new Datetime(); $candidate->save(); Session::put('candidate', $candidate); // take them back to the page they just logged in from, now with a session to their name return Redirect::to('candidate'); } else { Candidate::sendActivation($candidate->id); return Redirect::back()->withInfo('You must activate your account before logging in. We have resent the email for your convenience.'); } } } $messageBag = new Illuminate\Support\MessageBag(); $messageBag->add('candidateLogin', "The username and password did not match"); return Redirect::back()->withErrors($messageBag); }
/** * Add coupons to order * * @param array $coupons * @param object $new_order Order * * @return array **/ private function addCouponToOrder($coupons, $new_order) { $errors = new \Illuminate\Support\MessageBag(); if (count($coupons) > 0) { foreach ($coupons as $item) { $model = Coupon::find($item); if ($model != null) { try { $new_order->addCoupon($model); } catch (Exception $exp) { $errors->add('couponError', "Coupon " . $model->code . " cannot be added because: " . $exp->getMessage()); } } } // Set coupon discount $new_order->setDiscounts(); } return $errors; }
public function postStore() { $sid = \Input::get('id'); if (isset($sid)) { $url = 'admin/coupons/edit/' . $sid; } else { $url = 'admin/coupons/create'; } $rules = array('code' => 'required', 'amount' => 'required', 'start_date' => 'required', 'end_date' => 'required', 'amount' => 'numeric', 'min_spent' => 'numeric', 'max_spent' => 'numeric'); $validation = \Validator::make(\Input::all(), $rules); if ($validation->fails()) { return redirect($url)->withErrors($validation)->withInput(); } // If id is set, check that it exists if (isset($sid)) { $coupon = Coupon::find($sid); if ($coupon == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('couponError', "The coupon does not exist or may have been deleted."); return redirect('admin/coupons')->withErrors($errors); } } $code = \Input::get('code'); $description = \Input::get('description'); $amount = \Input::get('amount'); $is_percent = \Input::get('is_percent') == '' ? false : true; $start_date = \DateTime::createFromFormat('d/m/Y h:i A', \Input::get('start_date')); $end_date = \DateTime::createFromFormat('d/m/Y h:i A', \Input::get('end_date')); $max_spent = \Input::get('max_spent'); $min_spent = \Input::get('min_spent'); $limit_per_coupon = \Input::get('usage_limit_per_coupon'); $limit_per_user = \Input::get('usage_limit_per_user'); $multiple_coupons = \Input::get('multiple_coupons') == '' ? false : true; $exclude_sale_item = \Input::get('exclude_sale_item') == '' ? false : true; $automatically_apply = \Input::get('automatically_apply') == '' ? false : true; // Check that end date is after start date if ($end_date <= $start_date) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('dateRangeError', "Please enter an End date later than Start date."); return redirect($url)->withErrors($errors)->withInput(); } // Check if max spent is less than min spent, only if both not null if ($max_spent and $min_spent) { if ((double) $max_spent < (double) $min_spent) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('spentRangeError', "Max spent cannot be less than Min spent."); return redirect($url)->withErrors($errors)->withInput(); } } $apply_to_models = array(); $categories = \Input::get('category_id'); if (count($categories) > 0) { foreach ($categories as $item) { $model = Category::find($item); if ($model != null) { $apply_to_models[] = $model; } } } $products = \Input::get('product_id'); if (count($products) > 0) { foreach ($products as $item) { $model = Product::find($item); if ($model != null) { $apply_to_models[] = $model; } } } $pricelists = \Input::get('pricelist_id'); if (count($pricelists) > 0) { foreach ($pricelists as $item) { $model = Pricelist::find($item); if ($model != null) { $apply_to_models[] = $model; } } } $bundles = \Input::get('bundle_id'); if (count($bundles) > 0) { foreach ($bundles as $item) { $model = Bundle::find($item); if ($model != null) { $apply_to_models[] = $model; } } } // In the worst scenario, all select items have been deleted if (count($apply_to_models) == 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('applyToError', "You have not selected any Category, Product or Membership/Module under Restricted To."); return redirect($url)->withErrors($errors)->withInput(); } $newCoupon = isset($sid) ? $coupon : new Coupon(); $newCoupon->code = $code; $newCoupon->description = $description; $newCoupon->amount = $amount; $newCoupon->is_percent = $is_percent; $newCoupon->start_date = $start_date; $newCoupon->end_date = $end_date; $newCoupon->max_spent = $max_spent == 0 ? null : $max_spent; $newCoupon->min_spent = $min_spent == 0 ? null : $min_spent; $newCoupon->usage_limit_per_coupon = $limit_per_coupon == 0 ? null : $limit_per_coupon; $newCoupon->usage_limit_per_user = $limit_per_user == 0 ? null : $limit_per_user; $newCoupon->multiple_coupons = $multiple_coupons; $newCoupon->exclude_sale_item = $exclude_sale_item; $newCoupon->automatically_apply = $automatically_apply; $newCoupon->save(); // Remove all existing relationships first if (isset($sid)) { $coupon->categories()->detach(); $coupon->pricelists()->detach(); $coupon->products()->detach(); $coupon->bundles()->detach(); } foreach ($apply_to_models as $apply_to_model) { $apply_to_model->coupons()->save($newCoupon); } return redirect('admin/coupons'); }
/** * Validate and process asset edit form. * * @author [A. Gianotto] [<*****@*****.**>] * @param int $assetId * @since [v1.0] * @return Redirect */ public function postEdit(AssetRequest $request, $assetId = null) { // Check if the asset exists if (!($asset = Asset::find($assetId))) { // Redirect to the asset management page with error return redirect()->to('hardware')->with('error', trans('admin/hardware/message.does_not_exist')); } elseif (!Company::isCurrentUserHasAccess($asset)) { return redirect()->to('hardware')->with('error', trans('general.insufficient_permissions')); } if ($request->has('status_id')) { $asset->status_id = e($request->input('status_id')); } else { $asset->status_id = null; } if ($request->has('warranty_months')) { $asset->warranty_months = e($request->input('warranty_months')); } else { $asset->warranty_months = null; } if ($request->has('purchase_cost')) { $asset->purchase_cost = e(Helper::formatCurrencyOutput($request->input('purchase_cost'))); } else { $asset->purchase_cost = null; } if ($request->has('purchase_date')) { $asset->purchase_date = e($request->input('purchase_date')); } else { $asset->purchase_date = null; } if ($request->has('supplier_id')) { $asset->supplier_id = e($request->input('supplier_id')); } else { $asset->supplier_id = null; } // If the box isn't checked, it's not in the request at all. $asset->requestable = $request->has('requestable'); if ($request->has('rtd_location_id')) { $asset->rtd_location_id = e($request->input('rtd_location_id')); } else { $asset->rtd_location_id = null; } if ($request->has('image_delete')) { unlink(public_path() . '/uploads/assets/' . $asset->image); $asset->image = ''; } // Update the asset data $asset->name = e($request->input('name')); $asset->serial = e($request->input('serial')); $asset->company_id = Company::getIdForCurrentUser(e($request->input('company_id'))); $asset->model_id = e($request->input('model_id')); $asset->order_number = e($request->input('order_number')); $asset->asset_tag = e($request->input('asset_tag')); $asset->notes = e($request->input('notes')); $asset->physical = '1'; // Update the image if (Input::has('image')) { $image = $request->input('image'); // See postCreate for more explaination of the following. $header = explode(';', $image, 2)[0]; $extension = substr($header, strpos($header, '/') + 1); $image = substr($image, strpos($image, ',') + 1); $directory = public_path('uploads/assets/'); // Check if the uploads directory exists. If not, try to create it. if (!file_exists($directory)) { mkdir($directory, 0755); } $file_name = str_random(25) . "." . $extension; $path = public_path('uploads/assets/' . $file_name); try { Image::make($image)->resize(500, 500, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->save($path); $asset->image = $file_name; } catch (\Exception $e) { \Input::flash(); $messageBag = new \Illuminate\Support\MessageBag(); $messageBag->add('image', $e->getMessage()); \Session()->flash('errors', \Session::get('errors', new \Illuminate\Support\ViewErrorBag())->put('default', $messageBag)); return response()->json(['image' => $e->getMessage()], 422); } $asset->image = $file_name; } // Update custom fields in the database. // Validation for these fields is handlded through the AssetRequest form request // FIXME: No idea why this is returning a Builder error on db_column_name. // Need to investigate and fix. Using static method for now. $model = AssetModel::find($request->get('model_id')); if ($model->fieldset) { foreach ($model->fieldset->fields as $field) { if ($field->field_encrypted == '1') { if (Gate::allows('admin')) { $asset->{\App\Models\CustomField::name_to_db_name($field->name)} = \Crypt::encrypt(e($request->input(\App\Models\CustomField::name_to_db_name($field->name)))); } } else { $asset->{\App\Models\CustomField::name_to_db_name($field->name)} = e($request->input(\App\Models\CustomField::name_to_db_name($field->name))); } } } if ($asset->save()) { // Redirect to the new asset page \Session::flash('success', trans('admin/hardware/message.update.success')); return response()->json(['redirect_url' => route("view/hardware", $assetId)]); } \Input::flash(); \Session::flash('errors', $asset->getErrors()); return response()->json(['errors' => $asset->getErrors()], 500); }
public function getImgremove($sid) { $image = Image::find($sid); if ($image == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The image cannot be deleted at this time."); return redirect('/admin/products')->withErrors($errors); } $model_id = $image->imageable_id; $image->delete(); return redirect('admin/products/edit/' . $model_id); }
public function getDelete($sid) { $coupon = Coupon::find($sid); // No such id if ($coupon == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The coupon may have been deleted."); return redirect('admin/coupons')->withErrors($errors)->withInput(); } $coupon->delete(); return redirect('admin/coupons'); }