public function taskpagecall($id)
 {
     $user_id = Auth::User()->id;
     $taskd = TaskDetails::find($id);
     $task = Task::find($taskd->task_id);
     $desig = UserHasDesignation::where('users_id', $user_id)->where('designation_id', $task->designation_id)->count();
     if ($taskd->status == "Done") {
         return Redirect::to("task/active");
     }
     if ($taskd->status == "New") {
         if ($desig == 0) {
             return Redirect::to('/');
         } else {
             Session::put('taskdetails_id', $id);
             return View::make('tasks.task');
         }
     } else {
         if ($taskd->assignee_id == $user_id) {
             Session::put('taskdetails_id', $id);
             return View::make('tasks.task');
         } else {
             return Redirect::to('/');
         }
     }
 }
 public function save_members()
 {
     $members_selected = Input::get('members_selected');
     $members = explode(",", $members_selected);
     $designation_id = Input::get('designation_id');
     UserHasDesignation::where('designation_id', '=', $designation_id)->delete();
     foreach ($members as $key) {
         if ($key != 0) {
             $uhd = new UserHasDesignation();
             $uhd->users_id = $key;
             $uhd->designation_id = $designation_id;
             $uhd->save();
             if ($designation_id == 0) {
                 $tasks = Task::where('designation_id', $designation_id)->get();
                 foreach ($tasks as $task) {
                     DB::table('taskdetails')->where('task_id', $task->id)->where('assignee_id', $key)->update(array('status' => 'New'));
                 }
             }
         }
     }
     $designation_name = Designation::find($designation_id);
     $name = $designation_name->designation;
     $message = "Successfully updated the members in {$name}.";
     Session::put('success_members', $message);
     return Redirect::to('designation');
 }
 public function run()
 {
     UserHasDesignation::truncate();
     UserHasDesignation::create(['users_id' => '1', 'designation_id' => '0']);
 }
 public function store()
 {
     $user = new User();
     $user->username = trim(Input::get('username'));
     $checkusername = User::where('username', $user->username)->first();
     if (Input::get('role') == 1 && Input::get('email') == NULL) {
         // $user->email = "*****@*****.**";
     } else {
         $user->email = trim(Input::get('email'));
     }
     $user->password = trim(Input::get('password'));
     $user->firstname = trim(Input::get('firstname'));
     $user->lastname = trim(Input::get('lastname'));
     $user->office_id = Input::get('office');
     // The password confirmation will be removed from model
     // before saving. This field will be used in Ardent's
     // auto validation.
     $user->password_confirmation = Input::get('password_confirmation');
     // Save if valid. Password field will be hashed before save
     $errorcheck = 0;
     $checkusername = 0;
     $users = new User();
     $users = DB::table('users')->get();
     foreach ($users as $userx) {
         if (strtoupper($userx->username) == strtoupper($user->username)) {
             $checkusername = 1;
             $errorcheck = 1;
         }
     }
     if ($checkusername != 0) {
         Session::put('username_error', 'Username is already in use.');
     }
     $checkemail = 0;
     $users = new User();
     $users = DB::table('users')->get();
     foreach ($users as $userx) {
         if (strtoupper($userx->email) == strtoupper($user->email)) {
             $checkemail = 1;
             $errorcheck = 1;
         }
     }
     if (Input::get('role') == 1 && Input::get('email') == NULL) {
     } else {
         if ($checkemail != 0) {
             Session::put('email_error', 'Email is already in use.');
         }
     }
     //Validations
     if (ctype_alnum($user->username) && strlen($user->username) >= 6) {
     } else {
         $errorcheck = 1;
         Session::put('username_error', 'Invalid username.');
     }
     if (ctype_alpha(str_replace(array(' ', '-', '.'), '', $user->firstname))) {
     } else {
         $errorcheck = 1;
         Session::put('firstname_error', 'Invalid first name.');
     }
     if (ctype_alpha(str_replace(array(' ', '-', '.'), '', $user->lastname))) {
     } else {
         $errorcheck = 1;
         Session::put('lastname_error', 'Invalid last name.');
     }
     if (filter_var($user->email, FILTER_VALIDATE_EMAIL)) {
     } else {
         if (Input::get('role') == 1 && Input::get('email') == NULL) {
         } else {
             $errorcheck = 1;
             Session::put('email_error', 'Invalid email.');
         }
     }
     if (ctype_alnum($user->password)) {
         if ($user->password != $user->password_confirmation) {
             $errorcheck = 1;
             Session::put('password_error', 'Password did not match with confirm password.');
         }
     } else {
         $errorcheck = 1;
         Session::put('password_error', 'Invalid password.');
     }
     if ($errorcheck == 0) {
         $user->save();
         $username = $user->username;
         $assign = new Assigned();
         $assign->role_id = Input::get('role');
         $assign->user_id = $user->id;
         $assign->save();
         $desig = new UserHasDesignation();
         $desig->users_id = $user->id;
         $desig->designation_id = 0;
         $desig->save();
         $notice = "User created successfully. ";
         // Redirect with success message, You may replace "Lang::get(..." for your custom message.
         return Redirect::action('UserController@viewUser')->with('notice', $notice);
     } else {
         Session::put('msg', 'Failed to create user.');
         return Redirect::action('UserController@create')->withInput(Input::except('password'));
     }
 }