public function changeStatus($id, $type)
 {
     $user = User::find($id);
     if ($user) {
         $status = $user->is_logged_in;
         $departmentId = $type == 'self' ? Auth::user()->current_department : Session::get('deptIdForPC');
         if ($user->departments->contains($departmentId)) {
             if ($status) {
                 // Is Logged In
                 $user->is_logged_in = 0;
                 $outtime = date('H:i:s');
                 $log = Models\Log::find($user->current_log);
                 $log->out_time = $outtime;
                 $log->save();
                 $user->current_log = NULL;
                 $img = $type == 'self' ? HTML::image('img/clockout.png') : HTML::image('img/red_ball.png');
                 $intime = '';
                 $outtime = date('h:i:s A', strtotime($outtime));
             } else {
                 // Is Not Logged In
                 $user->is_logged_in = 1;
                 $intime = date('H:i:s');
                 $log = new Models\Log();
                 $log->date = date('Y-m-d');
                 $log->in_time = $intime;
                 $log->user_id = $user->id;
                 $log->department_id = $departmentId;
                 $log->save();
                 $user->current_log = $log->id;
                 $img = $type == 'self' ? HTML::image('img/clockin.png') : HTML::image('img/green_ball.png');
                 $outtime = '';
                 $intime = date('h:i:s A', strtotime($intime));
             }
             $user->save();
             return Response::json(array('img' => $img, 'intime' => $intime, 'outtime' => $outtime));
         }
     }
 }
 public function addTime()
 {
     $timeRules = array('date' => 'required|date_format:"Y-m-d"', 'in_time' => 'required|date_format:"H:i:s"', 'out_time' => 'required|date_format:"H:i:s"');
     $validator = Validator::make(Input::all(), $timeRules);
     if (!$validator->fails()) {
         $in_time = Input::get('in_time');
         $out_time = Input::get('out_time');
         if (strtotime($out_time) > strtotime($in_time)) {
             $user = Auth::user();
             $log = new Models\Log();
             $log->date = Input::get('date');
             $log->in_time = Input::get('in_time');
             $log->out_time = Input::get('out_time');
             $log->user_id = $user->id;
             $log->department_id = $user->current_department;
             $log->save();
             return 'success';
         }
     }
     return 'invalid';
 }