/** * Show the application dashboard to the user. * * @return Response */ public function index(Request $request) { if (!isset($_SESSION["timer"])) { $_SESSION["timer"] = time(); } $user_id = Auth::user()->id; if (is_null($user_id)) { return redirect("/auth/login")->withErrors(["Access not allowed, you must login"]); } $notes = Notes::where('user_id', $user_id)->first()->mynotes; $tbd = Tbd::where('user_id', $user_id)->first()->mytbd; $linksArray = Websites::where('user_id', $user_id)->first()->mylink; $email = Auth::user()->email; $website = explode(',', $linksArray); $image = DB::table('myimages')->where('user_id', $user_id)->lists('myimage'); Cookie::queue(Cookie::make('loginEmail', $email, 42 * 60)); return view('home', compact('notes', 'tbd', 'website', 'image')); }
/** * Update the notes table */ public function updateNotes($user_id) { $getNotes = Input::get('notes'); $getTBD = Input::get('tbd'); $getLinks = Input::get('website'); $imageFile = $_FILES['image']['name']; $fileErrors = array(); if (isset($_POST['delete'])) { $getImageToDelete = Input::get('delete'); foreach ($getImageToDelete as $imgValue) { DB::table('myimages')->where('id', '=', $imgValue)->delete(); } } if ($imageFile) { //if no errors... if (!$_FILES['image']['error']) { $images = DB::table('myimages')->where('user_id', $user_id)->lists('myimage', 'id'); $valid_file = true; if (preg_match('/\\.(jpg|jpeg|gif)(?:[\\?\\#].*)?$/i', $imageFile, $matches) == 0) { $valid_file = false; $fileErrors[] = "image type not allowed, accepts only jpg or gif"; } if (sizeof($images) == 4) { $valid_file = false; $fileErrors[] = "cannot add more than 4 images"; } if (!exif_imagetype($_FILES['image']['tmp_name'])) { $valid_file = false; $fileErrors[] = "not a valid image file"; } //if the file has passed the test if ($valid_file) { $image = addslashes($_FILES['image']['tmp_name']); $name = addslashes($_FILES['image']['name']); $image = file_get_contents($image); $image = base64_encode($image); $this->saveimage($name, $image, $user_id); } } return $fileErrors; } $linksString = implode(',', array_filter($getLinks)); $websites = Websites::where('user_id', $user_id)->first(); $notes = Notes::where('user_id', '=', $user_id)->first(); $tbd = Tbd::where('user_id', '=', $user_id)->first(); $notes->mynotes = $getNotes; $tbd->mytbd = $getTBD; $websites->mylink = $linksString; $notes->save(); $tbd->save(); $websites->save(); }