/**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $location = $this->location->find($id);
     $cities = City::orderBy('city_name')->lists('city_name', 'id');
     if (is_null($location)) {
         return Redirect::route('locations.index');
     }
     return View::make('locations.edit', compact('location', 'cities'));
 }
 public function showCitySelect()
 {
     $cities = City::orderBy('name', 'asc')->get();
     return View::make('city.city-select')->with('cities', $cities);
 }
 /**
  *  Edit / Update User Profile
  */
 public function getEdit($id)
 {
     try {
         //Get the current user's id.
         Sentry::check();
         $currentUser = Sentry::getUser();
         //Do they have admin access?
         if ($currentUser->hasAccess('admin')) {
             $group = User::find($id);
             $skills = Skill::all();
             $assigned = $group->skills->lists('id');
             $user_object = User::find($id);
             $locations = Location::all();
             $location_assigned = $group->locations->lists('id');
             $cities = City::orderBy('city_name')->lists('city_name', 'city_name');
             $data['user'] = Sentry::getUserProvider()->findById($id);
             $data['userGroups'] = $data['user']->getGroups();
             $data['allGroups'] = Sentry::getGroupProvider()->findAll();
             return View::make('users.edit')->with($data)->with('cities', $cities)->with('skills', $skills)->with('assigned', $assigned)->with('locations', $locations)->with('location_assigned', $location_assigned);
         } elseif ($currentUser->getId() == $id) {
             $group = User::find($id);
             $skills = Skill::all();
             $assigned = $group->skills->lists('id');
             $user_object = User::find($id);
             $locations = Location::all();
             $location_assigned = $group->locations->lists('id');
             $cities = City::orderBy('city_name')->lists('city_name', 'city_name');
             $data['user'] = Sentry::getUserProvider()->findById($id);
             $data['userGroups'] = $data['user']->getGroups();
             return View::make('users.edit')->with($data)->with('cities', $cities)->with('skills', $skills)->with('group', $group)->with('assigned', $assigned)->with('locations', $locations)->with('location_assigned', $location_assigned);
         } else {
             Session::flash('error', 'You don\'t have access to that user.');
             return Redirect::to('/');
         }
     } catch (Cartalyst\Sentry\UserNotFoundException $e) {
         Session::flash('error', 'There was a problem accessing your account.');
         return Redirect::to('/');
     }
 }
 public function test()
 {
     $output = '<table>';
     foreach (Centre::all() as $centre) {
         $output .= '<tr><td>' . $centre->name . '</td><td>' . $centre->address . '</td><td>' . $centre->city->name . '</td><td>' . $centre->city->state->name . '</td><td>' . $centre->pincode . '</td></tr>';
     }
     $output .= '</table>';
     return $output;
     return PDF::loadView('admin.certi')->stream('certi_final.pdf');
     //        return View::make('admin.centrecerti');
     //        $pdf = PDF::loadView('admin.centrecerti');
     //        return $pdf->stream('certi.pdf');
     $out = '<table>';
     $out .= '<tr><td>Name</td><td>Address</td><td>City</td><td>Pincode</td></tr>';
     $count = 0;
     foreach (Centre::orderBy('city_id')->get() as $centre) {
         $out .= '<tr><td>' . $centre->name . '</td><td>' . $centre->address . '</td><td>' . $centre->city->name . '</td><td>' . $centre->pincode . '</td></tr>';
     }
     //        foreach (DB::table('results_2015')->where('rank','<','51')->where('kv',1)->get() as $user)
     //        {
     //            if(User::where('roll',$user->roll)->count()) {
     //                $users = User::where('roll',$user->roll)->first();
     //                if($users->status == 3 || $users->status == 5) {
     ////                    dd($users);
     //                    $out .= '<tr><td>'.$user->rank.'</td><td>'.$user->roll.'</td><td>'.$user->mobile.'</td><td>'.$users->name1.'</td><td>'.$users->name2.'</td><td>'.$user->path.'</td><td></td><td></td><td></td><td></td><td></td><td></td><td>'.$users->squad.'</td></tr>';
     //                }
     //                else {
     //                    try {
     //                        $out .= '<tr><td>'.$user->rank.'</td><td>'.$user->roll.'</td><td>'.$user->mobile.'</td><td>'.$users->name1.'</td><td>'.$users->name2.'</td><td>'.$users->school->name.'</td><td>'.$users->city->name.'</td><td>'.$users->school->address.'</td><td>'.$users->school->pincode.'</td><td>'.$users->school->contact.'</td><td>'.$users->contact1.'</td><td>'.$users->contact2.'</td><td>'.$users->squad.'</td></tr>';
     //                    }catch (Exception $e) {
     //                        return var_dump($users);
     //                    }
     //                }
     ////                $count++;
     //            }
     //        }
     //        return $count;
     return $out . '</table>';
     $pdf = PDF::loadView('admin.certi');
     return $pdf->stream('certi.pdf');
     $det = '<table>';
     foreach (City::orderBy('state_id')->get() as $city) {
         $count = User::whereCityId($city->id)->count();
         if ($count) {
             $det .= '<tr><td>' . $city->name . '</td><td>' . $city->state->name . '</td><td>' . $count . '</td></tr>';
         }
     }
     $det .= '</table>';
     return $det;
     //        $list = '<table>';
     //        foreach(DB::table('results_2015')->where('rank','<','27')->where('kv','!=',1)->where('roll','LIKE',"H%")->get() as $res)
     //        {
     //            $user = User::whereRoll($res->roll)->first();
     //            if(!$user) {
     //                $name1 = 'User1';
     //                $name2 = 'User2';
     //            }
     //            else {
     //                $name1 = $user->name1;
     //                $name2 = $user->name2;
     //            }
     //            $list .= '<tr><td>'.$res->rank.'</td><td>'.$res->roll.'</td><td>'.$name1.'</td><td>'.$name2.'</td><td>'.$res->mobile.'</td><td>'.$res->path.'</td></tr>';
     //        }
     //        $list .= '</table>';
     //        return $list;
     //        $rolls = array('HE53600040','HE53600004','HE53600027','HE53600022','HE53600023','HE53600002','HE53600005','HE53600003','HE53600006','HE53600034','HE53600033','HE53600037','HE53600001','HE53600039','HE53600038','HE53600018','HE53600011','HE53600010','HE53600009','HE53600008','HE53600007','HE53600025','HE53600026','HE53600020','HE53600019','HE53600016','HE53600017','HE53600015','HE53600014','HE53600013','HE53600012');
     //        $list = '';
     //        foreach($rolls as $roll)
     //        {
     //            $old = User::whereRoll($roll)->first();
     //            $user = $old->replicate();
     //            $user->squad = 'JUNIOR';
     //            $lastroll = User::withTrashed()->where('roll', 'LIKE', "%JE5360%")->count();
     //            $roll = 'JE5360'.str_pad(strval($lastroll + 1), 4, "0", STR_PAD_LEFT);
     //            $user->roll = $roll;
     //            $user->comments = 'Change squad';
     //            $user->push();
     //            $list .= $old->roll.'  '.$user->roll.'<br>';
     //        }
     //        return $list;
     $user = User::whereRoll('HE52530018')->first();
     return $user->roll . '<br>' . Crypt::decrypt($user->result_pass) . '<br>' . $user->name1 . '<br>' . $user->name2;
     foreach (User::where('city_id', 21)->where('paid', 1)->get() as $user) {
         $password = str_random(6);
         $school = $user->school;
         $user->password = Hash::make($password);
         $user->save();
         if ($user->email1 !== "") {
             Queue::push(function ($job) use($user, $password, $school) {
                 Mail::send('emails.offline', array('user' => $user, 'school' => $school, 'password' => $password, 'name' => $user->name1), function ($message) use($user) {
                     $message->to($user->email1, $user->name1)->subject('Technothlon Registration Details');
                 });
                 $job->delete;
             });
         }
         if ($user->email1 !== "") {
             Queue::push(function ($job) use($user, $password, $school) {
                 Mail::send('emails.offline', array('user' => $user, 'school' => $school, 'password' => $password, 'name' => $user->name2), function ($message) use($user) {
                     $message->to($user->email2, $user->name2)->subject('Technothlon Registration Details');
                 });
                 $job->delete;
             });
         }
     }
     return View::make('emails.kvroll');
     return $pdf = PDF::loadView('technopedia.onlineadmitcard')->stream('admit-cards/users/' . Auth::user()->get()->roll . '.pdf');
     return View::make('technopedia.onlineadmitcard');
     $schools = '';
     foreach (Centre::all() as $centre) {
         $count = User::where('centre_id', $centre->id)->count();
         $schools .= $count . ' ' . ($centre->strength - $centre->left) . ' ' . $centre->id;
     }
     return $schools;
     foreach (School::where('verified', 2)->get() as $school) {
         $junior = User::where('school_id', $school->id)->where('squad', 'JUNIOR')->count();
         $hauts = User::where('school_id', $school->id)->where('squad', 'HAUTS')->count();
         $schools .= $school->name . '<br>' . $school->address . '<br>' . $school->city->name . ' Pin: ' . $school->pincode . '<br>' . $school->city->state->name . '<br>Ph.: ' . $school->contact . '<br>Junior:' . $junior . ' Hauts: ' . $hauts . '<br><br>';
     }
     return $schools;
     //        return View::make('admin.test');
 }