/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $teachUpload = new Upload(); if (Request::hasFile('upload')) { $file = Request::file('upload'); $file = $file->move(public_path() . '/uploads/dates', time() . '-' . $file->getClientOriginalName()); $teachUpload->file_path = $file->getRealPath(); $teachUpload->save(); $csvPath = $teachUpload->file_path; $reader = Reader::createFromPath($csvPath); $reader->setFlags(SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY); $reader->setOffset(1); $pattern = '/([(A-Z)|A-Z]* - .+)/'; $courses = DB::table('courses')->get(); foreach ($reader as $index => $row) { if ($index != 0) { $courseNo = $row[1]; $teachDate = $row[5]; $startTime = $row[6]; $endTime = $row[7]; foreach ($courses as $course) { if ($courseNo == $course->course_no) { DB::table('dates')->insert(array('course_id' => $course->id, 'teach_date' => $teachDate, 'session_start' => $startTime, 'session_end' => $endTime)); } } } } } $teachUpload->save(); return redirect()->route('admin_dates_index')->with('status', 'Teach dates uploaded'); }
/** * Upload the file and store * the file path in the DB. */ public function store() { // Rules $rules = array('name' => 'required', 'file' => 'required|max:20000'); $messages = array('max' => 'Please make sure the file size is not larger then 20MB'); // Create validation $validator = Validator::make(Input::all(), $rules, $messages); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $directory = "uploads/files/"; // Before anything let's make sure a file was uploaded if (Input::hasFile('file') && Request::file('file')->isValid()) { $current_file = Input::file('file'); $filename = Auth::id() . '_' . $current_file->getClientOriginalName(); $current_file->move($directory, $filename); $file = new Upload(); $file->user_id = Auth::id(); $file->project_id = Input::get('project_id'); $file->name = Input::get('name'); $file->path = $directory . $filename; $file->save(); return Redirect::back(); } $upload = new Upload(); $upload->user_id = Auth::id(); $upload->project_id = Input::get('project_id'); $upload->name = Input::get('name'); $upload->path = $directory . $filename; $upload->save(); return Redirect::back(); }
protected function saveLogo($_user_id, $_file, $_base64_data = false) { $uid = intval($_user_id); if ($uid <= 0) { xplog('Invalid user id given', __METHOD__); return false; } $user_company_details = $this->getDetailsByUserId($uid); // If logo already exists then delete the file first // if (!!$user_company_details && trim($user_company_details->logo) !== '') { if (App\Files::isFile($this->logo_dir . '/' . $user_company_details->logo)) { App\Cb\Files::deleteAllInstance($this->logo_dir . '/' . $user_company_details->logo); } } if (!$_base64_data) { $uploaded_image_details = App\Upload::save($_file, ['destination' => $this->logo_dir . '/']); } else { $uploaded_image_details = App\Upload::saveBase64($_file->base64, ['destination' => $this->logo_dir . '/', 'extension' => $_file->extension]); } if (!is_object($uploaded_image_details)) { xplog('Unable to save logo', __METHOD__); return false; } // Save in the database // $res = DB::table('user_company_details')->where('users_id', $uid)->update(['logo' => $uploaded_image_details->coded_name]); if ($res === false) { xplog('Unable to save logo in the database', __METHOD__); return false; } return $uploaded_image_details->coded_name; }
/** * Generate unique name based on the * uniqid() function * * @param $file requested file to upload */ public static function put($file) { if ($file->isValid()) { $name = uniqid() . '.' . $file->guessExtension(); $fileInfo = ['name' => $name, 'type' => $file->getMimeType(), 'size' => $file->getClientSize()]; $file->move(public_path() . '/uploads', $name); $upload = new Upload(); $upload->name = $fileInfo['name']; $upload->type = $fileInfo['type']; $upload->size = $fileInfo['size']; $upload->save($fileInfo); //dd($upload->id); return [$upload->id]; } else { return $file->getErrorMessage(); } }
public function run() { DB::table('uploads')->delete(); $collection = [['loan_id' => 1, 'user_id' => 3, 'document' => 'Drivers License', 'filename' => 'driversLicense', 'path' => 'driversLicense', 'filetype' => 'pdf', 'original_filename' => 'driversLicense.pdf']]; foreach ($collection as $record) { Upload::create($record); } }
public function update($id) { // save updated $record = $this->records->find($id); if (!$record) { Upload::create(Input::all()); return $this->respond($record); } $record->fill(Input::all())->save(); return $this->respond($record); }
public function video(VideoRequest $request) { $file = $request->file('video'); $data['name'] = $file->getClientOriginalName(); $data['path'] = base_path() . '\\public\\videos'; $data['slug'] = Str::slug($file->getClientOriginalName(), '_'); $data['type'] = "video"; Upload::create($data); $file->move($data['path'], $data['name']); // return back()->with('message', 'file saved!'); }
public function delete($id) { $file = Upload::findOrFail($id); $request = Request::find($file->request_id); if ($request->submitted_by != Auth::User()->id && !Auth::User()->hasRole(['administrator', 'approver'])) { return view('security.401'); } if (unlink('D:\\www\\lccb\\uploads\\lccbRequests\\' . $request->id . '\\' . $file->file_name)) { Upload::destroy($id); return $id; } else { return "error"; } }
protected function save($_property_id, $_files_array = [], $_type = 'doc') { $pid = intval($_property_id); $type = trim(strtolower($_type)); if ($pid <= 0) { xplog('Invalid property id given', __METHOD__); return false; } $insert_data = []; $uploaded_file_details = []; $destination_dir = $type === 'doc' ? $this->docs_dir . '/' : $this->images_dir . '/'; foreach ($_files_array as $file) { $file = (array) $file; $name = isset($file['filename']) ? $file['filename'] : $file['name']; if (trim($name) === '') { continue; } if (!isset($file['base64'])) { // Web $uploaded_file_details = App\Upload::save($file, ['destination' => $destination_dir]); } else { // Mobile $uploaded_file_details = App\Upload::saveBase64($file['base64'], ['destination' => $destination_dir, 'extension' => $file['extension']]); } if (!is_object($uploaded_file_details)) { xplog('Unable to save file "' . $name . '" for property "' . $pid . '"', __METHOD__); continue; } // Gather details for the database // $insert_data[] = ['properties_id' => $pid, 'type' => $type === 'doc' ? 'doc' : 'image', 'codedname' => $uploaded_file_details->coded_name, 'filename' => $uploaded_file_details->filename, 'extension' => $uploaded_file_details->extension]; } if (count($insert_data)) { // Make sure that their are data to save. return is_numeric(DB::table('property_files')->insert($insert_data)); // Insert the file data to the database } return true; }
public static function getUploadsFromUserId($user_id) { return Upload::where('userId', '=', $user_id)->get(); }
public function postCreate(Request $request) { $validator = Validator::make($request->all(), array('firstName' => 'required', 'lastName' => 'required', 'username' => 'required|max:20|min:3|unique:users', 'password' => 'required|min:6', 'email' => 'required|max:50|email|unique:users', 'roleId' => 'integer|min:1')); if ($validator->fails()) { return redirect()->route('admin-users-create')->withErrors($validator)->withInput(); } else { $user = User::create(array('firstName' => $request->get('firstName'), 'lastName' => $request->get('lastName'), 'username' => $request->get('username'), 'password' => Hash::make($request->get('password')), 'email' => $request->get('email'), 'active' => $request->has('active') ? true : false, 'mobile' => $request->get('mobile'), 'roleId' => $request->get('roleId'))); $arr = array('id' => $user->id, 'firstName' => $user->firstName, 'lastName' => $user->lastName, 'username' => $user->username, 'email' => $user->email, 'active' => $user->active, 'mobile' => $user->mobile); if ($user) { //$message = trans('language.USER-CREATED'); $message = 'User has been created.'; //Logging::created('User', $arr); } else { //$message = trans('language.USER-NOT-CREATED'); $message = 'User can not be created, please try again.'; //Logging::not_created('User', $arr); } $copy1 = copy('output/crops.xlsx', 'uploads/' . $user->id . '$crops.xlsx'); $result = Upload::uploadInputFile(Config::getUploadBaseDirectory() . 'uploads/' . $user->id . '$crops.xlsx', 'crop', $user->id); if ($copy1 == true and strpos($result, 'Uploaded') !== false) { $state = '1'; } else { $state = '0'; } $copy2 = copy('output/soils.xlsx', 'uploads/' . $user->id . '$soils.xlsx'); $result = Upload::uploadInputFile(Config::getUploadBaseDirectory() . 'uploads/' . $user->id . '$soils.xlsx', 'soil', $user->id); if ($copy2 == true and strpos($result, 'Uploaded') !== false) { $state .= '-1'; } else { $state .= '-0'; } $copy3 = copy('output/efficiency.xlsx', 'uploads/' . $user->id . '$efficiency.xlsx'); $result = Upload::uploadInputFile(Config::getUploadBaseDirectory() . 'uploads/' . $user->id . '$efficiency.xlsx', 'efficiency', $user->id); if ($copy3 == true and strpos($result, 'Uploaded') !== false) { $state .= '-1'; } else { $state .= '-0'; } $copy4 = copy('output/yield.xlsx', 'uploads/' . $user->id . '$yield.xlsx'); $result = Upload::uploadInputFile(Config::getUploadBaseDirectory() . 'uploads/' . $user->id . '$yield.xlsx', 'yield', $user->id); if ($copy4 == true and strpos($result, 'Uploaded') !== false) { $state .= '-1'; } else { $state .= '-0'; } $state .= '-0-0-0-0-0-0'; $upload = Upload::create(array('userId' => $user->id, 'state' => $state)); if ($copy1 == true) { $upload->crop = 'crops.xlsx'; $upload->crop_at = date('Y-m-d H:i:s'); $upload->save(); } if ($copy2 == true) { $upload->soil = 'soils.xlsx'; $upload->soil_at = date('Y-m-d H:i:s'); $upload->save(); } if ($copy3 == true) { $upload->efficiency = 'efficiency.xlsx'; $upload->efficiency_at = date('Y-m-d H:i:s'); $upload->save(); } if ($copy4 == true) { $upload->yield = 'yield.xlsx'; $upload->yield_at = date('Y-m-d H:i:s'); $upload->save(); } } return redirect()->route('admin-users-list')->with('global', $message); }
public function uploads($requestId) { $uploads = Upload::where('request_id', $requestId)->get(); $output = '<li class="list-group-item text-center"><h4>Current Uploaded Files</h4></li>'; foreach ($uploads as $upload) { $output .= '<li class="list-group-item" id="file-' . $upload->id . '"> <a href="/download/' . $upload->id . '/direct" title="Download File"><span class="badge"><i class="fa fa-download"></i></span></a> <a href="#" data-fileid="' . $upload->id . '" title="Delete File" class="delete-file"><span class="badge"><i class="fa fa-trash-o"></i></span></a> <a class="pdf cboxElement" href="/download/' . $upload->id . '" title="View File">' . str_limit($upload->file_name, $limit = 35, $end = '...') . '</a> </li>'; } return $output; }
public function addProperty(Request $request) { if (!Auth::check()) { return redirect(route('logout')); } if (!$request->session()->has('current_user')) { return redirect(route('logout')); } $current_user = $request->session()->get('current_user'); $data = []; view()->share(['title' => 'Add Property', 'CB_PAGE_JS' => [url('/js/mods/Cb.Notify.js')]]); $p = ['property_street' => '', 'property_state' => 'ACT', 'property_city' => '', 'property_postcode' => '', 'property_phone' => '', 'property_short_desc' => '', 'property_description' => '', 'property_type' => '', 'property_bedrooms' => '0', 'property_bathrooms' => '0', 'property_landarea' => '', 'property_floorarea' => '', 'property_garage' => '0', 'property_lat' => '00000', 'property_lng' => '00000', 'property_terms' => '1']; $data['aus_states'] = config('cleverbons.aus_states'); $data['property_types'] = App\Cb\Properties::getTypes(); if ($request->isMethod('post') && $request->has('submit')) { $p = $request->all(); // See: https://github.com/Respect/Validation/blob/master/docs/VALIDATORS.md $checks = []; $checks['property_street'] = Valid::string()->notEmpty()->validate($p['property_street']); $checks['property_state'] = Valid::string()->notEmpty()->validate($p['property_state']); $checks['property_city'] = Valid::string()->notEmpty()->validate($p['property_city']); $checks['property_postcode'] = Valid::string()->notEmpty()->validate($p['property_postcode']); $checks['property_phone'] = Valid::string()->notEmpty()->validate($p['property_phone']); $checks['property_short_desc'] = Valid::string()->notEmpty()->validate($p['property_short_desc']); $checks['property_description'] = Valid::string()->notEmpty()->validate($p['property_description']); $checks['property_type'] = Valid::string()->notEmpty()->validate($p['property_type']); $checks['property_bedrooms'] = Valid::int()->notEmpty()->validate($p['property_bedrooms']); $checks['property_bathrooms'] = Valid::int()->notEmpty()->validate($p['property_bathrooms']); $checks['property_landarea'] = Valid::string()->notEmpty()->validate($p['property_landarea']); $checks['property_floorarea'] = Valid::string()->notEmpty()->validate($p['property_floorarea']); $checks['property_garage'] = Valid::int()->notEmpty()->validate($p['property_garage']); $checks['property_lat'] = Valid::string()->notEmpty()->validate($p['property_lat']); $checks['property_lng'] = Valid::string()->notEmpty()->validate($p['property_lng']); $checks['property_terms'] = isset($p['property_terms']); try { if (in_array(false, $checks)) { throw new Exception('Some required field(s) have invalid values.'); } // Floorplan Files // if (isset($_FILES['property_floorplan_files']['name'])) { $floorplan_file_arr = App\Upload::reArrayFiles($_FILES['property_floorplan_files']); if (!App\Cb\Properties\Docs::isAllowed($floorplan_file_arr)) { throw new Exception('One or more of the floor plan files are supported'); } } // Property Images // if (isset($_FILES['property_images']['name'])) { $images_file_arr = App\Upload::reArrayFiles($_FILES['property_images']); if (!App\Cb\Properties\Images::isAllowed($images_file_arr)) { throw new Exception('One or more of the images is not supported'); } } $property_id = App\Cb\Properties::add($current_user->id, ['short_desc' => $p['property_short_desc'], 'description' => $p['property_description'], 'street' => $p['property_street'], 'city' => $p['property_city'], 'state' => $p['property_state'], 'postcode' => $p['property_postcode'], 'lat' => $p['property_lat'], 'lng' => $p['property_lng'], 'num_bedrooms' => $p['property_bedrooms'], 'num_bathrooms' => $p['property_bathrooms'], 'num_garage' => $p['property_garage'], 'landarea' => $p['property_landarea'], 'floorarea' => $p['property_floorarea'], 'type' => $p['property_type']]); if (!$property_id) { throw new Exception('Unable to add property. Please check your connection and try again.'); } // Save the floorplan docs // if (isset($floorplan_file_arr) && !App\Cb\Properties\Docs::save($property_id, $floorplan_file_arr)) { xplog('Unable to save some floor plan files for property "' . $property_id . '"', __METHOD__); } // Save the images // if (isset($images_file_arr) && !App\Cb\Properties\Images::save($property_id, $images_file_arr)) { xplog('Unable to save some images for property "' . $property_id . '"', __METHOD__); } cb_set_message('Successfully added property to your account', 1); return redirect(route('my_properties')); } catch (Exception $err) { cb_set_message($err->getMessage(), 0); } } $data['post'] = $p; return View::make('add_property', $data)->render(); }
public function store(LCCBRequest $request) { $request->request->add(['submitted_by' => Auth::user()->id]); if (is_string($request->equipment_id)) { $newEquip = Equipment::firstOrNew(['name' => $request->equipment_id]); $newEquip->user_id = Auth::user()->id; $newEquip->save(); $request->request->set('equipment_id', $newEquip->id); } $newRequest = Request::create($request->all()); if (!is_null($request->file('files'))) { foreach ($request->file('files') as $file) { Upload::create(['request_id' => $newRequest->id, 'file_name' => $file->getClientOriginalName()]); $destinationPath = 'D:\\www\\lccb\\uploads\\lccbRequests\\' . $newRequest->id; $file->move($destinationPath, $file->getClientOriginalName()); } } Event::fire(new RequestWasSubmitted($newRequest)); $json['success'] = 1; $json['message'] = "Request saved"; $json['redirect'] = "/lccb/" . $newRequest->id . "/edit"; return json_encode($json); }
public function runModel() { $uploads = Upload::getUploads(); $upload = $uploads->first(); $state_arr = explode('-', $upload->state); /* for($i=0; $i<=7; $i++) { if($i==5) continue; else if($state_arr[$i]==0) { switch ($i) { case 0: return json_encode(array('type'=>'Crop', 'state'=>$state_arr[$i])); break; case 1: return json_encode(array('type'=>'Soil', 'state'=>$state_arr[$i])); break; case 2: return json_encode(array('type'=>'Irrigation Efficiency', 'state'=>$state_arr[$i])); break; case 3: return json_encode(array('type'=>'Crop Yield', 'state'=>$state_arr[$i])); break; case 4: return json_encode(array('type'=>'Climate Model', 'state'=>$state_arr[$i])); break; case 5: return json_encode(array('type'=>'Weather Data', 'state'=>$state_arr[$i])); break; case 6: return json_encode(array('type'=>'Model Type', 'state'=>$state_arr[$i])); break; case 7: return json_encode(array('type'=>'Model Type', 'state'=>$state_arr[$i])); break; } } }*/ for ($i = 0; $i <= 7; $i++) { if ($i == 5 && $upload->climate_model != 'SelfSuppliedStation') { continue; } else { if ($state_arr[$i] == 0) { switch ($i) { case 0: return json_encode(array('type' => 'Crop', 'state' => $state_arr[$i])); break; case 1: return json_encode(array('type' => 'Soil', 'state' => $state_arr[$i])); break; case 2: return json_encode(array('type' => 'Irrigation Efficiency', 'state' => $state_arr[$i])); break; case 3: return json_encode(array('type' => 'Crop Yield', 'state' => $state_arr[$i])); break; case 4: return json_encode(array('type' => 'Climate Model', 'state' => $state_arr[$i])); break; case 5: return json_encode(array('type' => 'Weather Data', 'state' => $state_arr[$i])); break; case 6: return json_encode(array('type' => 'Model Type', 'state' => $state_arr[$i])); break; case 7: return json_encode(array('type' => 'Model Type', 'state' => $state_arr[$i])); break; } } } } $state_arr[8] = 1; $state = $state_arr[0]; for ($j = 1; $j < count($state_arr); $j++) { $state .= '-' . $state_arr[$j]; } $upload->state = $state; $upload->save(); $result = Upload::uploadInputFile(Config::getUploadBaseDirectory() . 'uploads/' . User::getSignedInUserId() . "\$" . "IC_ClimIn.txt", 'run_model', User::getSignedInUserId()); return json_encode(array('state' => -1)); }
public function storeAll() { $upload = new Upload(); if (Request::hasFile('upload')) { // Gets uploaded file move to courses directory store contents in $reader $file = Request::file('upload'); $file = $file->move(public_path() . '/uploads/courses', time() . '-' . $file->getClientOriginalName()); $upload->file_path = $file->getRealPath(); $upload->save(); $csvPath = $upload->file_path; $reader = Reader::createFromPath($csvPath); $reader->setFlags(SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY); $reader->setOffset(1); /** * Get data from Centres / Qualifications / Sittings / Papers tables * Regex CSV data with exising table data - create new row in Courses * */ $pattern = '/([(A-Z)|A-Z]* - .+)/'; $qualPattern = '/\\b(ACCA|CIMA)\\b/'; $paperPattern = '/(.)(\\d)/'; $elementPattern = '/(Tuition|QB Day|QB Evening|Revision|Full Time Short|Full Time Long)/i'; $methodPattern = '/(Classroom|Live Online|Distance Learning)/i'; $levelPattern = '/(Skills|Essentials|Options)/i'; $weekPattern = '/(Weekday|Weekend)/i'; $centres = DB::table('centres')->get(); $courses = DB::table('courses')->get(); $qualifications = DB::table('qualifications')->get(); $sittings = DB::table('sittings')->get(); $papers = DB::table('papers')->get(); foreach ($reader as $index => $row) { if ($index != 0) { $centreCode = $row[0]; $courseNo = $row[1]; $courseName = $row[2]; $sittingDate = $row[3]; $startDate = $row[5]; $courseMethod = $row[8]; $status = $row[9]; $price = $row[10]; $centreId; $sittingId; //Get Course title $courseTitle = preg_match($pattern, $courseName, $courseMatch); //Get qualification Id $courseQual = preg_match($qualPattern, $courseName, $qualMatch); $qual = DB::table('qualifications')->where('qualification_name', $qualMatch[0])->get(); $qualId = $qual[0]->id; // Get Paper Id $coursePaper = preg_match($paperPattern, $courseName, $paperMatch); $paper = DB::table('papers')->where('paper_name', $paperMatch[0])->get(); $paperId = $paper[0]->id; // Get Method Id $courseMethod = preg_match($methodPattern, $courseMethod, $methodMatch); $method = DB::table('methods')->where('method_name', $methodMatch[0])->get(); $methodId = $method[0]->id; // Get Element Id $courseElement = preg_match($elementPattern, $courseName, $elementMatch); $element = DB::table('elements')->where('element_name', $elementMatch[0])->get(); $elementId = $element[0]->id; //Get Level Id $courseLevel = preg_match($levelPattern, $courseName, $levelMatch); $level = DB::table('levels')->where('level_name', $levelMatch[0])->get(); $levelId = $level[0]->id; //Get Week Id $courseWeek = preg_match($weekPattern, $courseName, $weekMatch); if ($courseWeek != 0) { $week = DB::table('weektimes')->where('name', $weekMatch[0])->get(); $weekId = $week[0]->id; } else { $weekId = null; } //Get centre Id foreach ($centres as $centre) { if ($centreCode == $centre->centre_code) { $centreId = $centre->id; } } // Get Sitting Id foreach ($sittings as $sitting) { $sittingVal = $sitting->year . $sitting->month; if ($sittingDate == $sittingVal) { $sittingId = $sitting->id; } } // Insert data into Courses DB::table('courses')->insert(array('course_no' => $courseNo, 'name' => $courseMatch[0], 'start_date' => $startDate, 'price' => $price, 'status' => $status, 'qualification_id' => $qualId, 'centre_id' => $centreId, 'sitting_id' => $sittingId, 'paper_id' => $paperId, 'method_id' => $methodId, 'level_id' => $levelId, 'element_id' => $elementId, 'weektime_id' => $weekId)); } } } $upload->save(); }
private function getFileUpload($filetypes, $application_id) { $upload = []; for ($j = 0; $j < count($filetypes); $j++) { $file = Upload::where('application_id', $application_id)->where('filetype', $filetypes[$j])->first(); if ($file) { if ($file->status != 'Reject') { if ($file->status == 'Approve') { $file->html = '<label class="control-label icon-check"> <b>Approved</b></label>'; } else { $file->html = '<label class="control-label icon-hourglass"> <b>Pending</b></label>'; } } array_push($upload, $file); } } return $upload; }
public function fileUploadUpdate($uploadId, $status) { $statusObject = array("applied" => array("approve" => "approved", "reject" => "rejected"), "signed_agreement" => array("approve" => "approved_agreement", "reject" => "rejected_agreement"), "first_payment" => array("approve" => "approved_first_payment", "reject" => "rejected_first_payment"), "second_payment" => array("approve" => "approved_second_payment", "reject" => "rejected_second_payment"), "second_progress_report" => array("approve" => "approved_second_progress_report", "reject" => "rejected_second_progress_report"), "request_extend" => array("approve" => "approved_extend", "reject" => "rejected_extend"), "finalized" => array("approve" => "approved_finalized", "reject" => "rejected_finalized"), "project_finished" => array("approve" => "approved_project_finished", "reject" => "rejected_project_finished")); $upload = Upload::find($uploadId); $upload->status = $status; $upload->save(); $application = Application::find($upload->application_id); $appStatus = $application->status; $rejectList = ["rejected", "rejected_agreement", "rejected_first_payment", "rejected_second_payment", "rejected_second_progress_report", "rejected_extend", "rejected_finalized", "rejected_project_finished"]; if (in_array($appStatus, $rejectList)) { // Application status = reject force return return redirect()->route('fund_user_request', array('id' => $application->fund)); } $checkReject = Upload::where('application_id', $upload->application_id)->where('status', 'Reject')->count(); if ($checkReject != 0) { $this->applicationUpdate($upload->application_id, $statusObject[$appStatus]['reject']); } else { $allUploadFile = Upload::where('application_id', $upload->application_id)->count(); $allUploadApprove = Upload::where('application_id', $upload->application_id)->where('status', 'Approve')->count(); if ($allUploadFile == $allUploadApprove) { $this->applicationUpdate($upload->application_id, $statusObject[$appStatus]['approve']); } } return redirect()->route('fund_user_request', array('id' => $application->fund)); }
public function myAccount(Request $request, $uid) { if (!Auth::check()) { return redirect(route('logout')); } // Make sure user is already logged in $uid = intval(App\Crypt::urldecode($uid)); if ($uid < 1) { abort(404); } // Redirect to 404 page if user id is unknown $user_details = App\Cb\Users::getDetailsById($uid); if (!$user_details) { abort(404); } // Make sure user details is available $p = ['fname' => $user_details->fname, 'lname' => $user_details->lname, 'email' => $user_details->email, 'phone' => $user_details->phone, 'cell' => $user_details->cellphone, 'company_name' => '', 'company_street' => '', 'company_state' => '', 'company_phone' => '', 'company_abn' => '', 'company_city' => '', 'company_postcode' => '', 'company_color' => '']; $company_details = App\Cb\Users\Company::getDetailsByUserId($user_details->id); if ($company_details) { $company_info = ['company_name' => $company_details->name, 'company_street' => $company_details->street, 'company_state' => $company_details->state, 'company_phone' => $company_details->phone, 'company_abn' => $company_details->abn, 'company_city' => $company_details->city, 'company_postcode' => $company_details->postcode, 'company_color' => $company_details->primary_color, 'company_logo_filename' => $company_details->logo]; $p = array_merge($p, $company_info); } //_pr($company_details); $data = []; view()->share(['title' => 'My Account', 'CB_PAGE_JS' => [url('/js/mods/Cb.Notify.js')], 'CB_JS_TRANSPORT' => ['testing' => [1, 2, 3]]]); $data['aus_states'] = config('cleverbons.aus_states'); if ($request->isMethod('post') && $request->has('submit')) { $p = $request->all(); // See: https://github.com/Respect/Validation/blob/master/docs/VALIDATORS.md $checks = []; $checks['fname'] = Valid::string()->notEmpty()->validate($p['fname']); $checks['lname'] = Valid::string()->notEmpty()->validate($p['lname']); //$checks['email'] = Valid::email()->notEmpty()->validate($p['email']); $checks['phone'] = Valid::string()->notEmpty()->validate($p['phone']); $checks['cell'] = Valid::string()->notEmpty()->validate($p['cell']); if (isset($p['company_name']) && trim($p['company_name']) !== '') { $checks['company_name'] = Valid::string()->notEmpty()->validate($p['company_name']); $checks['company_street'] = Valid::string()->notEmpty()->validate($p['company_street']); $checks['company_state'] = Valid::string()->notEmpty()->validate($p['company_state']); $checks['company_phone'] = Valid::string()->notEmpty()->validate($p['company_phone']); $checks['company_abn'] = Valid::string()->notEmpty()->validate($p['company_abn']); $checks['company_city'] = Valid::string()->notEmpty()->validate($p['company_city']); $checks['company_postcode'] = Valid::string()->notEmpty()->validate($p['company_postcode']); $checks['company_color'] = Valid::string()->notEmpty()->validate($p['company_color']); } try { if (in_array(false, $checks)) { throw new Exception('Some required field(s) have invalid values.'); } if (trim($p['email']) !== $user_details->email) { if (App\Cb\Users::emailExists($p['email'])) { throw new Exception('Sorry the email address your provided is already registered in our system.'); } } if (isset($_FILES['company_logo']['name']) && trim($_FILES['company_logo']['name']) !== '') { $uploaded_image_ext = App\Upload::getExtension($_FILES['company_logo']); // Check if file is a valid image // if (!in_array($uploaded_image_ext, config('cleverbons.files.allowed_images'))) { throw new Exception('Please upload a valid logo.'); } $has_uploaded_a_logo = true; } // Update user details // $updated_user_details = App\Cb\Users::update($user_details->id, ['fname' => $p['fname'], 'lname' => $p['lname'], 'phone' => $p['phone'], 'cellphone' => $p['cell']]); if (!$updated_user_details) { throw new Exception('Unable to save your details. Please reload your page and try again.'); } // Update user company details // $updated_company_details = App\Cb\Users\Company::update($user_details->id, ['name' => $p['company_name'], 'abn' => $p['company_abn'], 'street' => $p['company_street'], 'city' => $p['company_city'], 'state' => $p['company_state'], 'postcode' => $p['company_postcode'], 'phone' => $p['company_phone'], 'primary_color' => $p['company_color']]); if (!$updated_company_details) { throw new Exception('Unable to save your company details. Please reload your page and try again.'); } // Update the user's logo file here // if (isset($has_uploaded_a_logo)) { // Save the uploaded logo for his/her company // $logo_filename = App\Cb\Users\Company::saveLogo($user_details->id, $_FILES['company_logo']); if (!$logo_filename) { xplog('Unable to save logo file for user "' . $user_details->id . '"', __METHOD__); } $p['company_logo_filename'] = $logo_filename; } // Successfully updated everything // cb_set_message('Successfully updated your details', 1); } catch (Exception $err) { cb_set_message($err->getMessage(), 0); } } $data['logo_dir'] = App\Cb\Users\Company::getLogoDirBaseUri(); $data['post'] = $p; return View::make('myaccount', $data)->render(); }