Пример #1
0
 public function getContacts()
 {
     $contacts = UserContact::get()->_disableLogging()->selectAllByUserIdAndStatusOrderByDescIsPrimary($this->user_id, UserContact::ACTIVE);
     if (empty($contacts)) {
         $contacts = array();
     }
     $this->_contacts = $contacts;
 }
 private function getUserContacts($user_id, $type)
 {
     $contacts_list = array();
     $contacts = UserContact::listUserContact("user_id={$user_id} AND contact_type='{$type}'");
     foreach ($contacts as $contact) {
         $name = $contact->get_contact_name();
         $email = $contact->get_contact_email();
         $contact_extra = unserialize($contact->get_contact_extra());
         $contacts_list[] = array('cont_id' => $contact->get_id(), 'name' => $name, 'email' => $email, 'picture' => $this->getContactPicture($contact_extra), 'general' => !empty($contact_extra['general']) ? $contact_extra['general'] : null, 'personal' => !empty($contact_extra['personal']) ? $contact_extra['personal'] : null, 'professional' => !empty($contact_extra['professional']) ? $contact_extra['professional'] : null, 'extra' => !empty($contact_extra['extra']) ? $contact_extra['extra'] : null);
     }
     return $contacts_list;
 }
 /**
  * Retrieved list of objects base on a given parameters - dynamic method: list_UserContact()
  *
  *
  * Generated with the DalClassGenerator created by:
  * Zoran Hron <*****@*****.**>
  *
  * @param conditionalStatement = null
  * @param orderby = null
  * @param sort = null
  * @param limit = 0
  * @param fetchmode = DB_FETCHMODE_OBJECT
  * @result array of objects: UserContact
  **/
 public function list_UserContact($conditionalStatement = null, $orderby = null, $sort = null, $limit = 0, $fetchmode = DB_FETCHMODE_OBJECT)
 {
     // build MySQL query
     $sql = "SELECT * FROM { user_contact } ";
     if ($conditionalStatement) {
         $sql .= "WHERE {$conditionalStatement}";
     }
     if ($orderby) {
         $sql .= " ORDER BY {$orderby}";
     }
     if ($sort) {
         $sql .= " {$sort}";
     }
     if ($limit) {
         $sql .= " LIMIT {$limit}";
     }
     $sql .= ";";
     // execute query
     $res = Dal::query($sql);
     $objects = array();
     // data found?
     if ($res->numRows() > 0) {
         // retrieve data objects
         while ($row = $res->fetchRow($fetchmode)) {
             if ($fetchmode == DB_FETCHMODE_OBJECT) {
                 $obj = new UserContact();
                 $obj->populateFromObject($row);
                 $objects[] = $obj;
             } else {
                 $objects[] = $row;
             }
         }
     }
     return $objects;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $company = \Input::get('company_id');
     $contact = \Input::get('contact_id');
     if ($company) {
         $updateCompany = \Company::findOrFail($company);
         $updateCompany->company_name = \Input::get('company_name');
         $updateCompany->company_address = \Input::get('company_address');
         $updateCompany->company_city = \Input::get('company_city');
         $updateCompany->company_state = \Input::get('company_state');
         $updateCompany->company_pin = \Input::get('company_pin');
         $updateCompany->company_phone = \Input::get('company_land_line');
         $updateCompany->company_alt_phone = \Input::get('company_alt_land_line');
         $updateCompany->company_fax = \Input::get('company_fax');
         $updateCompany->company_website = \Input::get('company_website');
         if ($updateCompany->save()) {
             \Session::flash('success', 'Successfully updated');
             return;
         }
     }
     if ($contact) {
         $uId = \Input::get('user_id');
         $displayname = \Input::get('displayname');
         // user display name update
         $user = \User::findorFail($uId);
         $user->displayname = $displayname;
         // user contact
         //user contact detail
         $updateContact = \UserContact::findOrFail($contact);
         $updateContact->mobile = \Input::get('mobile');
         $updateContact->alt_mobile = \Input::get('alt_mobile');
         $updateContact->alt_email = \Input::get('alt_email');
         if ($updateContact->save() && $user->save()) {
             \Session::flash('success', 'Successfully updated');
             return;
         }
     }
 }
Пример #5
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     // validate the info, create rules for the inputs
     $rules = array('user_firstname' => 'required', 'user_gender' => 'required', 'user_joined_date' => 'required|date_format:"' . DATE_FORMAT_2, 'user_left_date' => 'date_format:"' . DATE_FORMAT_2, 'user_email' => 'required|email|unique:user,user_email,' . $id . ',user_key,deleted_at,NULL', 'country_key1' => 'required', 'user_contact_phone_number1' => 'required', 'user_status' => 'required');
     // run the validation rules on the inputs from the form
     $validator = Validator::make(Input::all(), $rules);
     // if the validator fails, redirect back to the form
     if ($validator->fails()) {
         // redirect to list page
         Session::flash('danger', UNABLE_TO_SAVE);
         return Redirect::back()->withErrors($validator)->withInput();
     } else {
         // where condition
         $user = User::userKey($id)->first();
         // check if the record can be updated
         if (empty($user->id)) {
             // redirect to list page
             Session::flash('danger', SOMETHING_WENT_WRONG);
             return Redirect::to(strtolower(USER_TITLE));
         }
         // fields to be updated
         $user->user_firstname = $this->getInput('user_firstname', '');
         $user->user_middlename = $this->getInput('user_middlename', '');
         $user->user_lastname = $this->getInput('user_lastname', '');
         $user->user_alias = $this->getInput('user_alias', '');
         $user->user_gender = $this->getInput('user_gender', '');
         $user->user_civil_status = $this->getInput('user_civil_status', '');
         $user->user_birth_date = \Carbon\Carbon::createFromFormat(DATE_FORMAT_1, $this->getInput('user_birth_date', DEFAULT_DATE))->format(DB_DATE_FORMAT);
         $user->user_joined_date = $this->getInput('user_joined_date', '');
         $user->user_left_date = $this->getInput('user_left_date', '');
         $user->user_email = $this->getInput('user_email', '');
         $user->user_hometown_address = $this->getInput('user_hometown_address', '');
         $user->user_overseas_address = $this->getInput('user_overseas_address', '');
         if (Session::has('user_photo')) {
             $user->user_photo = Session::get('user_photo');
             Session::forget('user_photo');
         }
         $user->user_status = $this->getInput('user_status', '');
         $user->updated_by = Auth::user()->id;
         // update record
         $user->save();
         for ($cnt = 1; $cnt <= $this->getInput('hdn_increment', ''); $cnt++) {
             if ($this->getInput('hdn_index' . $cnt, '') == YES && $this->getInput('country_key' . $cnt, '') != EMPTY_STRING && $this->getInput('user_contact_phone_number' . $cnt, '') != EMPTY_STRING) {
                 if ($this->getInput('user_contact_key' . $cnt, '') == EMPTY_STRING) {
                     $data = array();
                     $data['user_contact_key'] = generateRandomID();
                     $data['user_id'] = $user->id;
                     $data['country_id'] = Country::countryKey($this->getInput('country_key' . $cnt, ''))->pluck('id');
                     $data['user_contact_phone_number'] = $this->getInput('user_contact_phone_number' . $cnt, '');
                     $data['created_by'] = Auth::user()->id;
                     // create record
                     UserContact::create($data);
                 } else {
                     // where condition
                     $user_contact = UserContact::UserContactKey($this->getInput('user_contact_key' . $cnt, ''))->first();
                     // check if the record can be updated
                     if (isset($user_contact->id)) {
                         $user_contact->country_id = Country::countryKey($this->getInput('country_key' . $cnt, ''))->pluck('id');
                         $user_contact->user_contact_phone_number = $this->getInput('user_contact_phone_number' . $cnt, '');
                         $user_contact->updated_by = Auth::user()->id;
                         // update record
                         $user_contact->save();
                     }
                 }
             }
         }
         // where condition
         $user_emergency = UserEmergency::userId($user->id)->first();
         // check if the record can be updated
         if (!empty($user_emergency->id)) {
             // fields to be updated
             $user_emergency->user_emergency_name = $this->getInput('user_emergency_name', '');
             $user_emergency->user_emergency_relation = $this->getInput('user_emergency_relation', '');
             $user_emergency->user_emergency_address = $this->getInput('user_emergency_address', '');
             $user_emergency->country_id = Country::countryKey($this->getInput('emergency_country_key', ''))->pluck('id');
             $user_emergency->user_emergency_phone = $this->getInput('user_emergency_phone', '');
             $user_emergency->updated_by = Auth::user()->id;
             // update record
             $user_emergency->save();
         }
         // flag all approver template records
         AccessUser::userId($user->id)->update(array('access_user_flag' => YES));
         // create access record
         if (is_array($this->getInput('access_user', array()))) {
             foreach ($this->getInput('access_user', array()) as $access_id) {
                 $access_user = AccessUser::accessId($access_id)->userId($user->id)->first();
                 if (isset($access_user->id) && !empty($access_user->id)) {
                     // update record
                     $access_user->user_id = $user->id;
                     $access_user->access_id = $access_id;
                     $access_user->access_user_flag = NO;
                     $access_user->updated_by = Auth::user()->id;
                     $access_user->save();
                 } else {
                     // create record
                     $data = array();
                     $data['user_id'] = $user->id;
                     $data['access_id'] = $access_id;
                     $data['access_user_flag'] = NO;
                     $data['created_by'] = Auth::user()->id;
                     AccessUser::create($data);
                 }
             }
             // delete records set to yes
             AccessUser::AccessUserFlag(YES)->UserId($user->id)->delete();
         }
         // redirect to list page
         Session::flash('success', SUCCESS_UPDATE);
         return Redirect::to($this->getPreviousListURL());
     }
 }
Пример #6
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $old_password = Input::get('old_password');
     if (!$old_password) {
         $displayname = Input::get('displayname');
         $dob = implode('-', array_reverse(explode('/', Input::get('dob'))));
         $gender = Input::get('gender');
         $alt_email = Input::get('alt_email');
         $phone = Input::get('phone');
         $mobile = Input::get('mobile');
         $alt_mobile = Input::get('alt_mobile');
         $address = Input::get('address');
         $city = Input::get('city');
         $state = Input::get('state');
         $country = Input::get('country');
         $image = Input::file('image');
         $signature = Input::file('signature');
         $user = User::where('id', '=', $id)->first();
         $contact = UserContact::where('user_id', '=', $id)->first();
         $user->displayname = $displayname;
         if (!$user->save()) {
             return Redirect::back()->with('error', 'Failed to update');
         }
         $contact->dob = $dob;
         $contact->gender = $gender;
         $contact->alt_email = $alt_email;
         $contact->phone = $phone;
         $contact->mobile = $mobile;
         $contact->alt_mobile = $alt_mobile;
         $contact->address = $address;
         $contact->city = $city;
         $contact->state = $state;
         $contact->country = $country;
         if ($image) {
             //unique name of file
             $image_name = '_' . Date('dmyihs') . str_replace(' ', '', Input::file('image')->getClientOriginalName());
             //upload file to destination
             $fileupload = Input::file('image')->move('public/img/', $image_name);
             if ($fileupload) {
                 // Delete existing image
                 File::delete('public/img/' . $contact->image);
                 $contact->image = $image_name;
             }
         }
         if ($signature) {
             //unique name of file
             $sign_name = '_' . Date('idmyhs') . str_replace(' ', '', Input::file('signature')->getClientOriginalName());
             //upload file to destination
             $sign_upload = Input::file('signature')->move('public/img/', $sign_name);
             if ($sign_upload) {
                 // Delete existing image
                 File::delete('public/img/' . $contact->signature);
                 $contact->signature = $sign_name;
             }
         }
         if ($contact->save()) {
             return Redirect::back()->with('success', 'Successfully update');
         } else {
             return Redirect::back()->with('error', 'Failed to update');
         }
     } elseif ($old_password) {
         $new_password = Input::get('new_password');
         $confirm_password = Input::get('confirm_password');
         $data = array('old_password' => $old_password, 'new_password' => $new_password, 'confirm_password' => $confirm_password);
         $validator = Validator::make($data, array('old_password' => 'required', 'new_password' => 'required', 'confirm_password' => 'required|same:new_password'));
         if ($validator->fails()) {
             return Redirect::back()->withInput()->withErrors($validator);
         } else {
             $user = User::find(Auth::user()->id);
             if (Hash::check($old_password, $user->getAuthPassword())) {
                 $user->password = Hash::make($new_password);
                 if ($user->save()) {
                     return Redirect::back()->with('success', 'Your password has been changed.');
                 } else {
                     return Redirect::back()->with('error', 'Your password could not change')->with('tab', 'changePassword');
                 }
             } else {
                 return Redirect::back()->with('error', 'Your old password incorrect')->with('tab', 'changePassword');
             }
         }
     } else {
         return Redirect::back();
     }
 }
 public function postImportEmp()
 {
     if (\Request::ajax()) {
         $efile = \Input::file('upload');
         /* Validation of file */
         $validate = \Validator::make(array('file' => $efile), array('file' => 'required|mimes:xls,csv|max:2000|min:1'));
         if ($validate->fails()) {
             $error = array('error' => $validate->messages()->first());
             echo json_encode($error);
             return;
         } else {
             $handle = file($efile->getRealPath());
             /* Call Excel Class */
             $objPHPExcel = \PHPExcel_IOFactory::load($efile->getRealPath());
             $mainArr = array();
             foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
                 // Sheet names
                 switch ($worksheet->getTitle()) {
                     case 'User':
                         $index = 'users';
                         break;
                     case 'PersonalDetails':
                         $index = 'PersonalDetails';
                         break;
                     case 'ContactInfo':
                         $index = 'ContactInfo';
                         break;
                     case 'IdentificationandBankInfo':
                         $index = 'IdentificationandBankInfo';
                         break;
                     case 'PFandESIInformation':
                         $index = 'PFandESIInformation';
                         break;
                     case 'JobDetails':
                         $index = 'JobDetails';
                         break;
                     case 'EducationalBackground':
                         $index = 'EducationalBackground';
                         break;
                     case 'WorkExperience':
                         $index = 'WorkExperience';
                         break;
                 }
                 // Getting all cells
                 $subArr = array();
                 $rows = $worksheet->getRowIterator();
                 foreach ($rows as $row) {
                     $cells = $row->getCellIterator();
                     // cells store into data array
                     $data = array();
                     foreach ($cells as $cell) {
                         $data[] = $cell->getCalculatedValue();
                     }
                     if ($data) {
                         // one set of row stored in indexed array
                         $arr[$index] = $data;
                         // indexed array store into subarr
                         $subArr[] = $arr;
                         // remove indexd array for optimiced douplicated
                         unset($arr);
                     }
                 }
                 // every sheet of array store in main Arr
                 $mainArr[$index] = $subArr;
                 unset($subArr);
             }
             $emails = array_fetch($mainArr['users'], 'users.1');
             // Validate emails
             foreach ($emails as $value) {
                 if (preg_match("/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}\$/", $value)) {
                 } else {
                     $error = array('error' => "{$value} InValid Email");
                     echo json_encode($error);
                     return;
                 }
             }
             // validation email unique from excel
             if (count($emails) != count(array_unique($emails))) {
                 $error = array('error' => "Douplicate emails are available");
                 echo json_encode($error);
                 return;
             }
             //end email unique in excel
             //Check Email Id is unique or not
             $user = \User::withTrashed()->whereIn('email', $emails)->first();
             if ($user) {
                 $error = array('error' => "{$user->email} already registered");
                 echo json_encode($error);
                 return;
             }
             // Database insertion starts here
             $users = $mainArr['users'];
             $PersonalDetails = $mainArr['PersonalDetails'];
             $ContactInfo = $mainArr['ContactInfo'];
             $IdentificationandBankInfo = $mainArr['IdentificationandBankInfo'];
             $PFandESIInformation = $mainArr['PFandESIInformation'];
             $JobDetails = $mainArr['JobDetails'];
             $EducationalBackground = $mainArr['EducationalBackground'];
             $WorkExperience = $mainArr['WorkExperience'];
             // Create UserId
             $userID = \Auth::user()->id;
             $branch = \Branch::where('user_id', '=', $userID)->first();
             $prifix = $branch->branch_code;
             // branch prifix code
             $count = \BranchEmp::withTrashed()->where('branch_id', '=', $userID)->count();
             // count all registered user of this branch
             $i = 0;
             foreach ($users as $val) {
                 \DB::beginTransaction();
                 $temp = $count + 1;
                 // increase one
                 $count++;
                 $postfix = sprintf('%04d', $temp);
                 // manupulate 000$temp
                 $username = $prifix . $postfix;
                 $password = str_random(10);
                 $hashPassword = \Hash::make($password);
                 $email = $val['users'][1];
                 $uId = \User::insertGetId(array('username' => $username, 'password' => $hashPassword, 'displayname' => $val['users'][0], 'email' => $val['users'][1], 'profilesId' => 4, 'active' => 'Y'));
                 //create branch employee
                 $branchEmployee = \BranchEmp::insertGetId(array('branch_id' => $userID, 'emp_id' => $uId));
                 // Insert Personal detail
                 $empId = \Employee::insertGetId(array('user_id' => $uId, 'firstname' => $PersonalDetails[$i]['PersonalDetails'][0], 'lastname' => $PersonalDetails[$i]['PersonalDetails'][2], 'middlename' => $PersonalDetails[$i]['PersonalDetails'][1], 'fathername' => $PersonalDetails[$i]['PersonalDetails'][3], 'mothermaiden' => $PersonalDetails[$i]['PersonalDetails'][8], 'dateofbirth' => $PersonalDetails[$i]['PersonalDetails'][4], 'maritialstatus' => $PersonalDetails[$i]['PersonalDetails'][5], 'spousename' => $PersonalDetails[$i]['PersonalDetails'][6], 'sibling' => $PersonalDetails[$i]['PersonalDetails'][8], 'bloodgroup' => $PersonalDetails[$i]['PersonalDetails'][9]));
                 // Contact Information
                 $contact = \UserContact::insertGetId(array('user_id' => $uId, 'address' => $ContactInfo[$i]['ContactInfo'][0], 'city' => $ContactInfo[$i]['ContactInfo'][1], 'state' => $ContactInfo[$i]['ContactInfo'][2], 'pin' => $ContactInfo[$i]['ContactInfo'][3], 'p_address' => $ContactInfo[$i]['ContactInfo'][4], 'p_city' => $ContactInfo[$i]['ContactInfo'][5], 'p_state' => $ContactInfo[$i]['ContactInfo'][6], 'p_pin' => $ContactInfo[$i]['ContactInfo'][7], 'mobile' => $ContactInfo[$i]['ContactInfo'][8], 'phone' => $ContactInfo[$i]['ContactInfo'][9], 'alt_mobile' => $ContactInfo[$i]['ContactInfo'][10], 'alt_email' => $ContactInfo[$i]['ContactInfo'][11]));
                 //IdentificationandBankInfo
                 $identification = \EmpIdentification::insertGetId(array('user_id' => $uId, 'pan' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][0], 'passport_no' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][1], 'adhar_no' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][2], 'voter_id' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][3], 'driving_licence' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][4]));
                 // Bank Detail
                 $bankDetails = \EmpBankDetail::insertGetId(array('user_id' => $uId, 'account_no' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][5], 'bank_name' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][6], 'branch' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][7], 'IFSC' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][8], 'micrno' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][9]));
                 // Esi and PF Detail
                 $PfEsi = \PfEsi::insertGetId(array('user_id' => $uId, 'isPF' => $PFandESIInformation[$i]['PFandESIInformation'][0], 'pfno' => $PFandESIInformation[$i]['PFandESIInformation'][1], 'pfenno' => $PFandESIInformation[$i]['PFandESIInformation'][2], 'epfno' => $PFandESIInformation[$i]['PFandESIInformation'][3], 'relationship' => $PFandESIInformation[$i]['PFandESIInformation'][4], 'isESI' => $PFandESIInformation[$i]['PFandESIInformation'][5], 'esino' => $PFandESIInformation[$i]['PFandESIInformation'][6]));
                 // Job details
                 $jobdetailsId = \JobDetails::insertGetId(array('user_id' => $uId, 'joining_date' => $JobDetails[$i]['JobDetails'][0], 'job_type' => $JobDetails[$i]['JobDetails'][1], 'designation' => $JobDetails[$i]['JobDetails'][2], 'department' => $JobDetails[$i]['JobDetails'][3], 'reporting_manager' => $JobDetails[$i]['JobDetails'][4], 'payment_mode' => $JobDetails[$i]['JobDetails'][5], 'hr_verification' => $JobDetails[$i]['JobDetails'][6], 'police_verification' => $JobDetails[$i]['JobDetails'][7], 'emp_type' => $JobDetails[$i]['JobDetails'][8], 'client_id' => $JobDetails[$i]['JobDetails'][9]));
                 //EducationalBackground
                 $eduction = \EmpEducation::insertGetId(array('user_id' => $uId, 'school_name' => $EducationalBackground[$i]['EducationalBackground'][0], 'school_location' => $EducationalBackground[$i]['EducationalBackground'][1], 'school_percentage' => $EducationalBackground[$i]['EducationalBackground'][2], 'puc_name' => $EducationalBackground[$i]['EducationalBackground'][3], 'puc_location' => $EducationalBackground[$i]['EducationalBackground'][4], 'puc_percentage' => $EducationalBackground[$i]['EducationalBackground'][5], 'diploma_name' => $EducationalBackground[$i]['EducationalBackground'][6], 'diploma_location' => $EducationalBackground[$i]['EducationalBackground'][7], 'diploma_percentage' => $EducationalBackground[$i]['EducationalBackground'][8], 'degree_name' => $EducationalBackground[$i]['EducationalBackground'][9], 'degree_location' => $EducationalBackground[$i]['EducationalBackground'][10], 'degree_percentage' => $EducationalBackground[$i]['EducationalBackground'][11], 'master_name' => $EducationalBackground[$i]['EducationalBackground'][12], 'master_location' => $EducationalBackground[$i]['EducationalBackground'][13], 'master_percentage' => $EducationalBackground[$i]['EducationalBackground'][14]));
                 // Experiance
                 $companyDetails = \WorkExperiance::insertGetId(array('user_id' => $uId, 'company_name' => $WorkExperience[$i]['WorkExperience'][0], 'location' => $WorkExperience[$i]['WorkExperience'][1], 'designation' => $WorkExperience[$i]['WorkExperience'][2], 'last_ctc' => $WorkExperience[$i]['WorkExperience'][3], 'join_date' => $WorkExperience[$i]['WorkExperience'][4], 'leaving_date' => $WorkExperience[$i]['WorkExperience'][5]));
                 \DB::commit();
                 \Mail::send('emails.user_credential', array('name' => $val['users'][0], 'username' => $username, 'password' => $password), function ($message) use($email, $username) {
                     $message->to($email, $username)->subject('User Credential');
                 });
                 $i++;
             }
             // end foreach of database insertion
             // success message
             $success = array('success' => "Successfully uploaded your Employees");
             echo json_encode($success);
             return;
         }
         // end else part
     }
     // end ajax condition
 }
Пример #8
0
 /**
  * @param $id
  * @param string $tab
  */
 public function actionMyEdit($id, $tab = 'personal')
 {
     $model = UserInfo::model()->findByAttributes(['user_id' => $id]);
     $user = UserModel::model()->findByPk($id);
     $contact = UserContact::model()->findByAttributes(['user_id' => $id]);
     if ($contact === null) {
         $contact = new UserContact();
     }
     $schooling = UserSchooling::model()->findByAttributes(['user_id' => $id]);
     if ($schooling === null) {
         $schooling = new UserSchooling();
     }
     if ($model) {
         if (isset($_POST['UserInfo']) && !empty($_POST['UserInfo'])) {
             $model->setAttributes($_POST['UserInfo']);
             if ($model->city_id == 0) {
                 $model->city_id = null;
             }
             if ($model->specialization == 0) {
                 $model->specialization = null;
             }
             $model->save(false);
             Yii::app()->user->setFlash('success', 'Информация сохранена');
         }
         if (isset($_POST['UserModel']) && !empty($_POST['UserModel'])) {
             $user->email = $_POST['UserModel']['email'];
             $user->save(false);
             if (isset($_POST['newPassword']) && !empty($_POST['newPassword']) && (isset($_POST['reNewPassword']) && !empty($_POST['reNewPassword']))) {
                 if ($_POST['reNewPassword'] != $_POST['newPassword'] || $_POST['newPassword'] != $_POST['reNewPassword']) {
                     Yii::app()->user->setFlash('error', 'Пароли не совпадают');
                 } else {
                     $identity = new UserIdentity($user->email, $_POST['password']);
                     if ($identity->authenticate()) {
                         $user->password = UserModel::model()->cryptPass($_POST['newPassword']);
                         if ($user->save(false)) {
                             Yii::app()->user->setFlash('success', 'Данные сохранены');
                         }
                     } else {
                         Yii::app()->user->setFlash('error', 'Введён не правельный пароль от аккаунта ' . $user->email);
                     }
                 }
             }
             Yii::app()->user->setFlash('success', 'Информация сохранена');
         }
         if (isset($_POST['UserContact']) && !empty($_POST['UserContact'])) {
             $contact->setAttributes($_POST['UserContact']);
             $contact->user_id = $id;
             $contact->save();
             Yii::app()->user->setFlash('success', 'Информация сохранена');
         }
         if (isset($_POST['UserSchooling']) && !empty($_POST['UserSchooling'])) {
             $schooling->setAttributes($_POST['UserSchooling']);
             $schooling->user_id = $id;
             $schooling->save(false);
             Yii::app()->user->setFlash('success', 'Информация сохранена');
             $image = CUploadedFile::getInstanceByName('education_scan');
             if (!is_dir('uploads/educationScan/images')) {
                 mkdir('uploads/educationScan/images', 0777, true);
             }
             if ($image) {
                 $ext = explode('.', $image->name);
                 $schooling->image = $id . '.' . $ext[1];
                 $image->saveAs('uploads/educationScan/images/' . $schooling->image);
                 $schooling->save(false);
             }
         }
         if ($tab == 'info') {
             $model->setScenario('info');
             if (isset($_POST['UserInfo']) && !empty($_POST['UserInfo'])) {
                 $model->setAttributes($_POST['UserInfo']);
                 $model->user_id = $id;
                 $model->save(false);
                 Yii::app()->user->setFlash('success', 'Информация сохранена');
             }
         }
         $file = CUploadedFile::getInstanceByName('photo');
         if (!is_dir('uploads/profile/images')) {
             mkdir('uploads/profile/images', 0777, true);
         }
         if ($file) {
             $model->setScenario('image');
             $ext = explode('.', $file->name);
             $model->avatar = $id . '.' . $ext[1];
             $file->saveAs('uploads/profile/images/' . $model->avatar);
             $model->save(false);
         }
     }
     $this->render('myEdit', ['model' => $model, 'user' => $user, 'tab' => $tab, 'contact' => $contact, 'schooling' => $schooling]);
 }