public function profileupdate($data = Null) { //$data = Auth::user()->ID; $editid = $data; $GeneralData = Input::except(array('_token', 'status', 'pagename', 'profilepicture', 'profileimgedithidden', 'interest', 'update_profile')); $newimg = Input::file('profilepicture'); if ($newimg != '') { $destinationPath = 'public/assets/upload/profile'; $filename = Input::file('profilepicture')->getClientOriginalName(); $Image = str_random(8) . '_' . $filename; $GeneralData['profilepicture'] = $Image; $uploadSuccess = Input::file('profilepicture')->move($destinationPath, $Image); } $interest = Input::get('interest'); $interest_length = sizeof(Input::get('interest')); if ($interest_length > 0) { userinterestModel::whereNotIn('interest_id', $interest)->where('user_id', '=', $data)->delete(); for ($i = 0; $i < $interest_length; $i++) { $interes['user_id'] = $data; $interes['interest_id'] = $interest[$i]; $userInterest = userinterestModel::where('user_id', $data)->where('interest_id', $interest[$i])->lists('interest_id'); if (count($userInterest) < 1) { userinterestModel::create($interes); } unset($interes); } } else { userinterestModel::where('user_id', '=', $data)->delete(); } $cur_date = date('Y-m-d'); $updaterules = array('username' => 'required|unique:user,username,' . $data, 'password' => 'confirmed|min:5', 'email' => 'required|email|unique:user,email,' . $data, 'dateofbirth' => 'required', 'timezone' => 'required|min:2'); $validation = Validator::make($GeneralData, $updaterules); $newpassword = Input::get('password'); if ($newpassword != "") { $GeneralData['password'] = Hash::make(Input::get('password')); } else { unset($GeneralData["password"]); } unset($GeneralData["password_confirmation"]); $updatedata = $GeneralData; $lantyp = Session::get('language'); if ($lantyp == "") { $lantyp = "value_en"; } if (!isset($updatedata['maritalstatus'])) { $updatedata['maritalstatus'] = 0; } if ($validation->passes()) { $affectedRows = ProfileModel::where('ID', $data)->update($updatedata); $lantyp = Session::get('language'); $labelname = ['txt_user_update_msg']; $languageDetails = languageModel::select($lantyp)->whereIn('ctrlCaptionId', $labelname)->get()->toArray(); $user_id = $data; $profileData = ProfileModel::where('ID', $user_id)->first(); $interestList = InterestCategoryModel::lists('Interest_name', 'Interest_id'); $userInterest = userinterestModel::where('user_id', $user_id)->lists('interest_id'); $er_data['Message'] = "<span id='txt_user_update_msg'>" . $languageDetails[0][$lantyp] . "</span>"; return Redirect::to('/edit_profile/' . $data)->with('er_data', $er_data)->with('user_id', $user_id); } else { $languageDetails = languageModel::select($lantyp, 'ctrlCaptionId')->whereIn('value_en', [$validation->messages()->first('username'), $validation->messages()->first('password'), $validation->messages()->first('email'), $validation->messages()->first('dateofbirth'), $validation->messages()->first('timezone')])->get()->toArray(); foreach ($languageDetails as $key => $val) { if (in_array($val['ctrlCaptionId'], ['alert_enterusername', 'alert_alreadyuser'])) { $er_data['username'] = "******" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>"; } elseif (in_array($val['ctrlCaptionId'], ['alert_enterpassword', 'alert_minpass5', 'alert_passconfnotmatch'])) { $er_data['password'] = "******" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>"; } elseif (in_array($val['ctrlCaptionId'], ['alert_enteremail', 'alert_validemail', 'alertr_emailalready'])) { $er_data['email'] = "<span id='" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>"; } elseif (in_array($val['ctrlCaptionId'], ['alert_enterdob'])) { $er_data['dateofbirth'] = "<span id='" . $val['ctrlCaptionId'] . "'>" . $val[$lantyp] . "</span>"; } elseif (in_array($val['ctrlCaptionId'], ['txt_timezone_required'])) { $er_data['timezone'] = "<span id='" . $val['ctrlCaptionId'] . "'>Timezone is required</span>"; } } return Redirect::to('/edit_profile/' . $data)->with('er_data', $er_data)->with('old_data', $updatedata); } }
public function editmyprofile() { $GeneralData = array_filter(Input::except(array('_token', 'passwordhidden', 'profilepicture', 'interest_id', 'userid', 'timezone', 'dateofbirth'))); $timezone = Input::get('timezone'); $GeneralData['dateofbirth'] = timezoneModel::convert(Input::get('dateofbirth'), $timezone, 'UTC', 'Y-m-d'); $newimg = Input::file('profilepicture'); if ($newimg != '') { $destinationPath = 'public/assets/upload/profile'; $filename = Input::file('profilepicture')->getClientOriginalName(); $Image = str_random(8) . '_' . $filename; $GeneralData['profilepicture'] = $Image; $uploadSuccess = Input::file('profilepicture')->move($destinationPath, $Image); } else { //$GeneralData['profilepicture']=Input::get('profileimgedithidden'); } $GeneralData['status'] = 1; $data = Input::get('userid'); $newpassword = Input::get('password'); $updaterules = array('username' => 'required|unique:user,username,' . $data, 'password' => 'confirmed:min:5', 'email' => 'required|email|unique:user,email,' . $data); $validation = Validator::make($GeneralData, $updaterules); if ($validation->passes()) { if ($newpassword != "") { $GeneralData['password'] = Hash::make(Input::get('password')); } unset($GeneralData["password_confirmation"]); $affectedRows = ProfileModel::where('ID', $data)->update($GeneralData); $interest_id = Input::get('interest_id'); $interestid = explode(',', $interest_id); $interestidcount = count($interestid); $interest['user_id'] = Input::get('userid'); $affectedRows = userinterestModel::where('user_id', $data)->delete(); for ($i = 0; $i < $interestidcount; $i++) { $interest['interest_id'] = $interestid[$i]; $validationinterest = Validator::make($interest, userinterestModel::$rules); if ($validationinterest->passes()) { $userregister = userinterestModel::create($interest); } } $Response = array('success' => '1', 'message' => 'Record Updated successfully', 'msgcode' => "c109"); $final = array("response" => $Response); return json_encode($final); } else { $Response = array('success' => '0', 'message' => $validation->messages()->first(), 'msgcode' => "c110"); $final = array("response" => $Response); return json_encode($final); } }