/**
  * Update the data for the University
  * 
  * @return View
  */
 public function update()
 {
     $flag = false;
     $university = University::find(Auth::id());
     $university->name = ucfirst(trim(Input::get('university_name')));
     $email = trim(strtolower(Input::get('university_email')));
     if (strlen(Input::get('current_password')) > 0) {
         if (!Hash::check(Input::get('current_password'), Auth::user()->password)) {
             return Redirect::back()->withErrors(array('error' => Lang::get('register_university.error_password')));
         } else {
             Auth::user()->password = Hash::make(Input::get('new_password'));
         }
     }
     if (strcmp($email, $university->email) !== 0) {
         Auth::user()->last_activity = new MongoDate();
         Auth::user()->user = $email;
         try {
             Auth::user()->save();
         } catch (MongoDuplicateKeyException $e) {
             return Redirect::back()->withErrors(array('error' => Lang::get('register_university.email_duplicated')));
         }
         $flag = true;
         $university->email = $email;
     } else {
         if (strlen(Input::get('current_password')) > 0) {
             Auth::user()->save();
         }
     }
     $university->acronym = strtoupper(trim(Input::get('university_acronym')));
     if (Input::hasFile('avatar_file')) {
         $data = Input::get('avatar_data');
         if (is_null($university->profile_image)) {
             $image = new CropImage(null, $data, $_FILES['avatar_file']);
             $university->profile_image = $image->getURL();
         } else {
             new CropImage($university->profile_image, $data, $_FILES['avatar_file']);
         }
     }
     $university->save();
     if ($flag) {
         Auth::logout();
         return Redirect::to('/')->with('message', Lang::get('university_profile.relogin'));
     } else {
         return Redirect::to(Lang::get('routes.university_profile'))->with('message', Lang::get('university_profile.update_message'));
     }
 }
 public function updateStudent()
 {
     $flag = false;
     $student = Student::find(Auth::id());
     $student->name = ucfirst(trim(Input::get('name')));
     $student->last_name = ucfirst(trim(Input::get('last_name')));
     $student->genre = strtolower(trim(Input::get('genre')));
     $student->has_a_job = strtolower(trim(Input::get('job')));
     $email = trim(strtolower(Input::get('email')));
     $student->university_id = trim(Input::get('nip'));
     if (strcmp($email, $student->email) !== 0) {
         Auth::user()->user = $email;
         try {
             Auth::user()->save();
         } catch (MongoDuplicateKeyException $e) {
             return Redirect::back()->withErrors(array('error' => Lang::get('register_student.email_duplicated')));
         }
         $flag = true;
         $student->email = $email;
     }
     if (Input::hasFile('avatar_file')) {
         $data = Input::get('avatar_data');
         if (is_null($student->profile_image)) {
             $image = new CropImage(null, $data, $_FILES['avatar_file']);
             $student->profile_image = $image->getURL();
         } else {
             new CropImage($student->profile_image, $data, $_FILES['avatar_file']);
         }
     }
     $student->save();
     if ($flag) {
         Auth::logout();
         return Redirect::to('/')->with('message', Lang::get('student_profile.relogin'));
     } else {
         return Redirect::to(Lang::get('routes.student_profile'))->with('message', Lang::get('student_profile.update_true'));
     }
 }
 public function update()
 {
     $group = Group::find(Input::get('group_id'));
     if (isset($group->_id)) {
         $group->name = trim(ucfirst(Input::get('name')));
         $group->project_name = trim(strtolower(Input::get('project_name')));
         if (Input::hasFile('avatar_file')) {
             $data = Input::get('avatar_data');
             if (is_null($group->logo)) {
                 $image = new CropImage(null, $data, $_FILES['avatar_file']);
                 $group->logo = $image->getURL();
             } else {
                 new CropImage($group->logo, $data, $_FILES['avatar_file']);
             }
         }
         try {
             $group->save();
         } catch (MongoDuplicateKeyException $e) {
             return Redirect::back()->withErrors(array('error' => Lang::get('register_group.duplicated')));
         }
         return Redirect::to(Lang::get('routes.student'))->with('message', Lang::get('register_group.update'));
     }
 }
 /**
  * Function that update the teacher profile information include the password.
  *
  * @return view
  */
 public function updateTeacher()
 {
     $teacher = Teacher::find(Auth::id());
     $teacher->name = ucfirst(trim(Input::get('teacher_name')));
     $teacher->last_name = ucfirst(trim(Input::get('teacher_last_name')));
     $teacher->phone = trim(Input::get('teacher_phone'));
     $teacher->cellphone = trim(Input::get('teacher_cellphone'));
     if (strlen(Input::get('current_password')) > 0) {
         if (!Hash::check(Input::get('current_password'), Auth::user()->password)) {
             return Redirect::back()->withErrors(array('error' => Lang::get('teacher_profile.error_password')));
         } else {
             Auth::user()->password = Hash::make(Input::get('new_password'));
             Auth::user()->save();
         }
     }
     // Check for teacher profile picture
     if (Input::hasFile('avatar_file')) {
         $data = Input::get('avatar_data');
         if (is_null($teacher->profile_image)) {
             $image = new CropImage(null, $data, $_FILES['avatar_file']);
             $teacher->profile_image = $image->getURL();
         } else {
             new CropImage($teacher->profile_image, $data, $_FILES['avatar_file']);
         }
     }
     $teacher->save();
     return Redirect::to(Lang::get('routes.teacher_profile'))->with('message', Lang::get('teacher_profile.update_message'));
 }