public function dashboard() { // $this->middleware('auth'); $researchs = Research::count(); $funds = Fund::count(); $translations = Translation::count(); $users = User::count(); return view('dashboard', ['researchs' => $researchs, 'funds' => $funds, 'translations' => $translations, 'users' => $users]); }
public function showAbout(Request $r) { $var = $this->getVars(); $content = array(); $content["members"] = Member::get(); $content["tools"] = Content::where('type', '=', 'tools')->orderBy("date_created", "desc")->take(3)->get(); $content["researches"] = Research::where('external', '=', false)->take(2)->get(); $content["researchereas"] = explode('#', $var["research"]["body"]); $content["researchesours"] = Content::where('type', '=', 'researches')->whereHas('research', function ($query) { $query->where('external', 0); })->orderBy("date_created", "desc")->take(2)->get(); $lang = $r->session()->get("lang", "fa"); if ($lang == "en") { return view("test.about", ["content" => $content, "var" => $var, "lang" => $lang]); } return view('about', ["content" => $content, "var" => $var, "lang" => $lang]); }
public function insertQuery(Request $request) { $type = $request->input('type'); $tag = $request->input('tags'); $id = $request->input('id'); $mode = $request->input('mode'); //////////////////////////////////// //mode = 0 edit , mode = 1 insert/// //////////////////////////////////// if ($type == 'events') { $validator = Validator::make($request->all(), ['title' => 'required', 'address' => 'required', 'body' => 'required', 'tags' => 'required|array']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput()->with(array('errorcode' => 'events', 'tags' => $this->returnTags())); } else { if ($mode == 1) { $event = new Event(); $content = new Content(); } else { $event = Event::find($id); $content = $event->content; } $content->title = $request->input('title'); $event->address = $request->input('address'); $content->body = $request->input('body'); $content->type = $type; $content->save(); $start = $request->input('start-day') . "|" . $request->input('start-month') . "|" . $request->input('start-year') . "|" . $request->input('start-hour') . ":" . $request->input('start-minute'); $end = $request->input('end-day') . "|" . $request->input('end-month') . "|" . $request->input('end-year') . "|" . $request->input('end-hour') . ":" . $request->input('end-minute'); $event->start = $start; $event->end = $end; $event->highlight = $request->input('highlight') == NULL ? 0 : 1; $files = $request->file('img'); foreach ($files as $file) { if ($file->isValid()) { $photo = new Photo(); $tempName = $file->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . "-" . time() . "." . $extension[1]; $destination = 'upload'; $file->move($destination, $name); $photo->path = $destination . "/" . $name; $content->photos()->save($photo); } } if (!empty($tag)) { foreach ($tag as $insertTag) { $row = Tag::where('title', '=', $insertTag)->first(); $content->tags()->save($row); } } $cat = Category::where('title', '=', $request->input('category'))->first(); if ($cat != null) { $content->categories()->attach($cat->id); } $content->event()->save($event); return redirect('admin'); } } elseif ($type == 'members') { $validator = Validator::make($request->all(), ['firstname' => 'required', 'lastname' => 'required', 'email' => 'required']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput()->with(array('errorcode' => 'members', 'tags' => $this->returnTags())); } else { if ($mode == 1) { $member = new Member(); } else { $member = Member::find($id); } $member->firstname = $request->input('firstname'); $member->lastname = $request->input('lastname'); $member->email = $request->input('email'); //$member->password = $request->input('password'); $member->researchareas = $request->input('researchareas') == NULL ? NULL : $request->input('researchareas'); $member->industrialareas = $request->input('intery') == NULL ? NULL : $request->input('industry'); $member->tel = $request->input('telephone') == NULL ? NULL : $request->input('telephone'); $member->mobile = $request->input('mobile') == NULL ? NULL : $request->input('mobile'); $member->position = $request->input('position') == NULL ? NULL : $request->input('position'); $member->googleplus = $request->input('googleplus') == NULL ? NULL : $request->input('pinterest'); $member->facebook = $request->input('facebook') == NULL ? NULL : $request->input('facebook'); $member->twitter = $request->input('twitter') == NULL ? NULL : $request->input('instagram'); $member->linkedin = $request->input('linkedin') == NULL ? NULL : $request->input('linkedin'); if ($request->hasFile('img')) { $file = $request->file('img'); if ($file->isValid()) { $photo = new Photo(); $tempName = $file->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . "-" . time() . "." . $extension[1]; $destination = 'upload'; $file->move($destination, $name); //$photo->title = $request->input('photoTitle'); $photo->path = $destination . "/" . $name; Photo::where("member_id", $member->id)->delete(); $member->photo()->save($photo); } } if ($request->hasFile('cv')) { $file = $request->file('cv'); if ($file->isValid()) { $tempName = $file->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . "-" . time() . "." . $extension[count($extension) - 1]; $destination = 'upload'; $file->move($destination, $name); $member->cv = $destination . "/" . $name; } } $member->save(); if ($mode == 0) { $record = Member::find($id)->records; foreach ($record as $rec) { $rec->delete(); } } $recordArray = $request->input('rec'); if (!empty($recordArray)) { foreach ($recordArray as $key) { if (empty($key['delete'])) { $key['delete'] = 'off'; } if ($key['delete'] != "on" && $key['institute'] != "") { $record = new Record(); $record->institute = $key['institute']; $record->position = $key['position']; $record->start = $key['start']; $record->end = $key['end']; $record->type = $key['type']; $member->records()->save($record); } } } // $cat = Category::where('title', '=', $request->input('category'))->first(); return redirect('admin'); } } elseif ($type == 'researches') { $validator = Validator::make($request->all(), ['author' => 'required', 'title' => 'required', 'abstract' => 'required']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput()->with(array('errorcode' => 'researches', 'tags' => $this->returnTags())); } else { if ($mode == 1) { $research = new Research(); $content = new Content(); } else { $research = Research::find($id); $content = $research->content; } $content->title = $request->input('title'); $content->body = $request->input('abstract'); $content->type = $type; $content->save(); $research->author = $request->input('author'); $research->publisher = $request->input('publisher') == NULL ? NULL : $request->input('publisher'); $date = $request->input('date-year') . "|" . $request->input('date-month') . "|" . $request->input('date-day') . "|" . $request->input('date-hour') . ":" . $request->input('date-minute'); $research->date = $date; $research->external = $request->input("external") == NULL ? true : false; $research->pages = $request->input('pages') == NULL ? NULL : $request->input('pages'); // $research->abstract = $request->input('abstract') == NULL ? NULL : $request->input('abstract'); $research->keywords = $request->input('keywords') == NULL ? NULL : $request->input('keywords'); $research->link = $request->input('link') == NULL ? NULL : $request->input('link'); $path = $request->file('path'); if (!empty($path) && $path->isValid()) { $tempName = $path->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . time() . "." . $extension[count($extension) - 1]; $destination = 'upload'; $path->move($destination, $name); $research->path = $destination . "/" . $name; } if (!empty($tag)) { foreach ($tag as $insertTag) { $row = Tag::where('title', '=', $insertTag)->first(); $content->tags()->save($row); } } $research->content()->associate($content); $research->save(); $cat = Category::where('title', '=', $request->input('category'))->first(); if ($cat != null) { $content->categories()->attach($cat->id); } return redirect('admin'); } } elseif ($type == 'galleries') { $validator = Validator::make($request->all(), ['title' => 'required', 'body' => 'required']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput()->with(array('errorcode' => 'galleries', 'tags' => $this->returnTags())); } else { if ($mode == 1) { $content = new Content(); } else { $content = Content::find($id); } $content->title = $request->input('title'); $content->body = $request->input('body'); $content->type = $type; $content->save(); if ($request->hasFile('img')) { $file = $request->file('img'); for ($i = 0; $i < count($file); $i++) { if ($file[$i]->isValid()) { $photo = new Photo(); $tempName = $file[$i]->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . "-" . time() . (string) $i . "." . $extension[count($extension) - 1]; $destination = 'upload'; $file[$i]->move($destination, $name); $photo->title = $request->input('imgtitle')[$i]; $photo->path = $destination . "/" . $name; $photo->highlight = $request->input("highlight")[$i] == "true" ? 1 : 0; $content->photos()->save($photo); } } } if ($mode != 1) { if (!empty($request->input('oldimg'))) { foreach ($request->input('oldimg') as $img) { if (empty($img['delete'])) { $img['delete'] = "off"; $image = Photo::find($img['id']); $image->title = $img['title']; $image->highlight = $img['highlight'] == "true" ? 1 : 0; $image->save(); } if ($img['delete'] == "on") { $temp = Photo::find($img['id']); $temp->delete(); } } } } if (!empty($tag)) { foreach ($tag as $insertTag) { $row = Tag::where('title', '=', $insertTag)->first(); $content->tags()->save($row); } } $cat = Category::where('title', '=', $request->input('category'))->first(); if ($cat != null) { $content->categories()->attach($cat->id); } return redirect('admin'); } } elseif ($type == 'tags') { $input = $request->all(); $split = explode("#", $input['body']); for ($i = 0; $i < count($split); $i++) { if (!empty($split[$i]) && $split[$i] != '') { $tag = new Tag(); $tag->title = trim($split[$i]); $tag->save(); } } return redirect('admin'); } elseif ($type == 'categories') { $cat = new Category(); $cat->title = $request->input("title"); $cat->parent = $request->input("cat-id"); if ($cat->parent == 0) { $cat->parent = null; } $cat->save(); return redirect('admin'); } elseif ($type == "variables") { $var = Variable::find($id); $var->title = $request->input("title"); $var->subtitle = $request->input("subtitle"); $var->body = $request->input("body"); if ($request->hasFile('img')) { $file = $request->file('img'); if ($file->isValid()) { $tempName = $file->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . "-" . time() . "." . $extension[count($extension) - 1]; $destination = 'upload'; $file->move($destination, $name); //$photo->title = $request->input('photoTitle'); $var->body = $destination . "/" . $name; } } $var->save(); return redirect('admin'); } else { $validator = Validator::make($request->all(), ['title' => 'required', 'body' => 'required', 'tags' => 'required|array']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput()->with(array('errorcode' => 'news', 'tags' => $this->returnTags())); } else { if ($mode == 1) { $news = new Content(); } else { $news = Content::find($id); } $news->title = $request->input('title'); $news->body = $request->input('body'); $news->type = $type; $news->save(); if ($request->hasFile('img')) { $files = $request->file('img'); if ($mode == 0) { $oldphoto = Photo::where("content_id", $id)->first(); $oldphoto->delete(); } foreach ($files as $file) { if ($file->isValid()) { $photo = new Photo(); $tempName = $file->getClientOriginalName(); $extension = explode(".", $tempName); $name = $extension[0] . "-" . time() . "." . $extension[count($extension) - 1]; $destination = 'upload'; $file->move($destination, $name); //$photo->title = $request->input('photoTitle'); $photo->path = $destination . "/" . $name; $news->photos()->save($photo); } } } if (!empty($tag)) { foreach ($tag as $insertTag) { $row = Tag::where('title', '=', $insertTag)->first(); $news->tags()->save($row); } } $cat = Category::find($request->input('cat-id')); if ($cat != null) { $news->categories()->attach($cat->id); } return redirect('admin'); } } }
public function add(Request $request) { //$this->middleware('auth'); $this->validate($request, ['title' => 'required|max:200', 'keywords' => 'max:200']); // die(print_r($request->input('authors_firstname'),true)); $authors_name = ""; $i = 0; foreach ($request->input('authors_firstname') as $firstname) { $authors_name = $authors_name . $firstname . " " . $request->input('authors_lastname')[$i] . ","; $i++; } $request->merge(array('authors' => $authors_name)); $request->merge(array('authors_firstname' => implode(',', $request->input('authors_firstname')))); $request->merge(array('authors_lastname' => implode(',', $request->input('authors_lastname')))); if ($request->hasFile('fulltext_file')) { $fulltext_file = $request->file('fulltext_file'); $fulltext_filename = md5(microtime()) . "." . $fulltext_file->getClientOriginalExtension(); // $request->merge(array('full_text_file' =>$fulltext_filename)); } if ($request->hasFile('abstract_file')) { $abstract_file = $request->file('abstract_file'); $abstract_filename = md5(microtime()) . "." . $abstract_file->getClientOriginalExtension(); // $request->merge(array('full_text_file' =>$fulltext_filename)); } if ($request->hasFile('article_file')) { $article_file = $request->file('article_file'); $article_filename = md5(microtime()) . "." . $article_file->getClientOriginalExtension(); // $request->merge(array('article_file' =>$article_filename)); } if ($request->hasFile('cover_file')) { $cover_file = $request->file('cover_file'); $cover_filename = md5(microtime()) . "." . $cover_file->getClientOriginalExtension(); // $request->merge(array('cover_file' =>$cover_filename)); } $request->merge(array('creator' => Auth::user()->id)); if (count($request->input('article_level')) > 0) { $request->merge(array('article_level' => implode(',', $request->input('article_level')))); } if ($request->input('research_id', null)) { $research = Research::find($request->input('research_id', null)); $research->update(array_merge($request->all())); } else { $research = Research::create(array_merge($request->all())); } $research_id = $research->id; $destinationPath = 'uploads/' . $research_id . '/'; if ($request->hasFile('fulltext_file')) { $fulltext_file->move($destinationPath, $fulltext_filename); $research->full_text_file = $fulltext_filename; $research->save(); } if ($request->hasFile('abstract_file')) { $abstract_file->move($destinationPath, $abstract_filename); $research->abstract_file = $abstract_filename; $research->save(); } if ($request->hasFile('article_file')) { $article_file->move($destinationPath, $article_filename); $research->article_file = $article_filename; $research->save(); } if ($request->hasFile('cover_file')) { $cover_file->move($destinationPath, $cover_filename); $research->cover_file = $cover_filename; $research->save(); } if ($research) { $fields = Researchfield::all(); if ($request->input('research_id')) { return view('researchcenter.new_research', ['fields' => $fields, 'alert_type' => 'success', 'msg' => 'Successfully update research data.']); } else { return view('researchcenter.new_research', ['fields' => $fields, 'alert_type' => 'success', 'msg' => 'Successfully insert new research.']); } } }