public function setStateAttribute($value) { if (strlen($value) == 2) { $this->attributes['state_a2'] = strtoupper($value); } else { $operator = \Config::get('database.default') == 'pgsql' ? 'ilike' : 'like'; $state = State::where('name', $operator, $value)->first(); if ($state) { $this->attributes['state_a2'] = $state->a2; } } if (!empty($this->attributes['state_a2'])) { $this->attributes['state_name'] = Addresses::stateName($this->attributes['state_a2']); } }
public function load_states() { $country_id = $_POST['country_id']; $states = new State(); if ($country_id > 0) { $states->where('country_id', $country_id); } $states->get(); echo '<select name="state_id" class="form-control">'; echo '<option value="">-- select state --</option>'; foreach ($states as $key => $state_item) { echo '<option value="' . $state_item->id . '">' . $state_item->state_name . '</option>'; } echo '</select>'; }
public function sendEmails() { $colonia = Session::get("colonia"); $coloniaName = Colony::find($colonia); $urbanism = Urbanism::where('colony_id', '=', $colonia)->first(); $state = State::where('id', $coloniaName->City->state_id)->first()->name; $ciudad = $coloniaName->City->name; $contenido = Input::get('contenido'); $user_id = Input::get('email'); $asunto = Input::get('asunto'); $admin_colonia = Neighbors::where('user_id', '=', Auth::user()->id)->first(); $optGroup = Input::get('optGroup'); if ($user_id == 'Todos' && $optGroup == NULL) { $neighbors = NeighborProperty::with('Neighbors')->where('urbanism_id', '=', $urbanism->id)->where('neighbors_id', '!=', $admin_colonia->id)->get(); foreach ($neighbors as $neighbor) { $email = $neighbor->Neighbors->User->email; $data = array('email' => $email, 'link' => 'ConfirmationController@confirm', 'code' => "jhhjdhsdhhdsjhdsh", 'name_inv' => $admin_colonia->name, 'lname_inv' => $admin_colonia->last_name, 'urbanism' => $urbanism->name, 'contenido' => $contenido, 'asunto' => $asunto, 'coloniaName' => $coloniaName, 'estado' => $state, 'ciudad' => $ciudad); Mail::send('emails.email_masivos', $data, function ($message) use($email, $asunto) { $message->subject($asunto); $message->to($email); }); } } if ($optGroup == 'Vecinos') { $email = User::findOrFail($user_id)->email; $data = array('email' => $email, 'link' => 'ConfirmationController@confirm', 'code' => "jhhjdhsdhhdsjhdsh", 'name_inv' => $admin_colonia->name, 'lname_inv' => $admin_colonia->last_name, 'urbanism' => $urbanism->name, 'contenido' => $contenido, 'asunto' => $asunto, 'coloniaName' => $coloniaName, 'estado' => $state, 'ciudad' => $ciudad); Mail::send('emails.email_masivos', $data, function ($message) use($email, $asunto) { $message->subject($asunto); $message->to($email); }); } if ($optGroup == 'Roles') { $neighbors = NeighborProperty::join('neighbors', 'neighbors.id', '=', 'neighbors_properties.neighbors_id')->join('assigned_roles', 'neighbors.user_id', '=', 'assigned_roles.user_id')->where('assigned_roles.colony_id', '=', $colonia)->where('urbanism_id', '=', $urbanism->id)->where('assigned_roles.role_id', '=', $user_id)->get(); foreach ($neighbors as $neighbor) { $email = $neighbor->Neighbors->User->email; $data = array('email' => $email, 'link' => 'ConfirmationController@confirm', 'code' => "jhhjdhsdhhdsjhdsh", 'name_inv' => $admin_colonia->name, 'lname_inv' => $admin_colonia->last_name, 'urbanism' => $urbanism->name, 'contenido' => $contenido, 'asunto' => $asunto, 'coloniaName' => $coloniaName, 'estado' => $state, 'ciudad' => $ciudad); Mail::send('emails.email_masivos', $data, function ($message) use($email, $asunto) { $message->subject($asunto); $message->to($email); }); } } }
/** * Return collection of all states/provinces within a country * TODO: caching to make this fetch speedy speedy * * @param string 2 letter country alpha-code * @return Collection */ public static function getStates($countryA2 = 'CA') { if (strlen($countryA2) != 2) { throw new InvalidValueException(); } return Cache::rememberForever('addresses.' . $countryA2 . '.states', function () use($countryA2) { return State::where('country_a2', $countryA2)->orderBy('name', 'ASC')->get(); }); }
public function postCreate() { $postdata = file_get_contents("php://input"); if (!empty($postdata)) { $userName = Input::get('userName'); $userEmail = Input::get('userEmail'); $userMobile = Input::get('userMobile'); $userAddress1 = Input::get('userAddress1'); $userAddress2 = Input::get('userAddress2'); $userCity = Input::get('userCity'); $userState = Input::get('userState'); $userPincode = Input::get('userPincode'); $userType = Input::get('userType'); $currentUserId = Input::get('currentUserId'); $currentUserIdPk = Input::get('currentUserIdPk'); $parentId = Input::get('parentId'); $parentIdPk = Input::get('parentIdPk'); $lockbalance = Input::get('lock_balance'); $mainbalance = Input::get('main_balance'); $usercount = Input::get('user_count'); $userStatus = Input::get('userStatus'); $products = Input::get('products'); $createdat = Commonmodel::dateandtime(); $clientIp = Input::get('clientIp'); if ($userEmail != "" && $userMobile != "" && $userAddress1 != "" && $userAddress2 != "" && $userCity != "" && $userState != "" && $userPincode != "" && $userType != "" && $currentUserId != "" && $currentUserIdPk != "" && $parentIdPk != "" && $userStatus != "" && $products != "" && $userName != '') { if (empty($lockbalance)) { $checkbalancedetection = Balancedetection::where('bal_usr_roll', '=', $userType)->get(); if (count($checkbalancedetection) > 0) { $lockbalance = Balancedetection::where('bal_usr_roll', '=', $userType)->pluck('bal_detn_amt'); } else { $lockbalance = 0; } } if (empty($mainbalance)) { $mainbalance = 0; } $checklockbalance = Userfinance::where('ufin_user_id', '=', $currentUserId)->pluck('ufin_lock_balance'); $checkmainbalance = Userfinance::where('ufin_user_id', '=', $currentUserId)->pluck('ufin_main_balance'); if ($checkmainbalance < $checklockbalance) { return Response::json(array('status' => 'failure', 'message' => 'Your lock balance is too low to create this user with mentioned amount')); } else { $checkbalancecreate = $checkmainbalance - $checklockbalance; if ($checkbalancecreate < $mainbalance) { return Response::json(array('status' => 'failure', 'message' => 'You have Insufficient Balance ')); } else { $newbalance = $checkmainbalance - $mainbalance; if (!empty($products)) { $emailcheck = User::where('UD_USER_EMAIL', $userEmail)->get(); if (count($emailcheck) > 0) { return Response::json(array('status' => 'failure', 'message' => 'Email ID Already Exist')); } else { $mobilenumcheck = User::where('UD_USER_MOBILE', $userMobile)->get(); if (count($mobilenumcheck) > 0) { return Response::json(array('status' => 'failure', 'message' => 'Phone Number Already Exist')); } else { if ($userType != 'SP') { $getusercount = count(User::where('UD_USER_TYPE', '=', $userType)->get()); $checkstatedetailsf = Balancedetection::where('bal_usr_roll', '=', $userType)->pluck('user_reg_count'); $checkindiviudalcount = User::where('UD_ID_PK', '=', $parentIdPk)->pluck('UD_USER_CREATE_COUNT'); if ($getusercount <= $checkstatedetailsf) { if ($userType == 'SAS') { $currentcountcheck = Balancedetection::where('bal_usr_roll', '=', 'SA')->pluck('user_reg_count'); } elseif ($userType == 'SP') { $currentcountcheck = Balancedetection::where('bal_usr_roll', '=', 'SA')->pluck('user_reg_count'); } elseif ($userType == 'SPS') { $currentcountcheck = Balancedetection::where('bal_usr_roll', '=', 'SP')->pluck('user_reg_count'); } elseif ($userType == 'SD') { $currentcountcheck = Balancedetection::where('bal_usr_roll', '=', 'SP')->pluck('user_reg_count'); } elseif ($userType == 'SDS') { $currentcountcheck = Balancedetection::where('bal_usr_roll', '=', 'SD')->pluck('user_reg_count'); } elseif ($userType == 'D') { $currentcountcheck = Balancedetection::where('bal_usr_roll', '=', 'SD')->pluck('user_reg_count'); } elseif ($userType == 'DS') { $currentcountcheck = Balancedetection::where('bal_usr_roll', '=', 'D')->pluck('user_reg_count'); } elseif ($userType == 'FR') { $currentcountcheck = Balancedetection::where('bal_usr_roll', '=', 'D')->pluck('user_reg_count'); } elseif ($userType == 'FRS') { $currentcountcheck = Balancedetection::where('bal_usr_roll', '=', 'FR')->pluck('user_reg_count'); } elseif ($userType == 'SFR') { $currentcountcheck = Balancedetection::where('bal_usr_roll', '=', 'FR')->pluck('user_reg_count'); } elseif ($userType == 'SFRS') { $currentcountcheck = Balancedetection::where('bal_usr_roll', '=', 'FR')->pluck('user_reg_count'); } $usercountdetails = count(User::where('UD_USER_TYPE', '=', $userType)->get()); } elseif ($getusercount <= $checkindiviudalcount) { $usercountdetails = count(User::where('UD_USER_TYPE', '=', $userType)->get()); $currentcountcheck = $checkindiviudalcount; } else { return Response::json(array('status' => 'failure', 'message' => 'You Reached Limit for creating Sub Role')); } } else { $getusercount = Balancedetection::where('bal_usr_roll', '=', 'SP')->pluck('user_reg_count'); $checkstatedetailsf = count(User::where('UD_USER_TYPE', '=', $userType)->where('UD_USER_STATE', '=', $userState)->get()); $stateusercountdetails = count(State::where('adt_state_name', '=', $userState)->get()); if (count($checkstatedetailsf) > $getusercount) { $usercountdetails = count(User::where('UD_USER_TYPE', '=', $userType)->where('UD_USER_STATE', '=', $userState)->get()); $currentcountcheck = State::where('adt_state_name', '=', $userState)->pluck('adt_state_count'); $statpatuserid = State::where('adt_state_name', '=', $userState)->pluck('adt_state_code'); } elseif (count($checkstatedetailsf) <= $getusercount) { $usercountdetails = count(User::where('UD_USER_TYPE', '=', $userType)->where('UD_USER_STATE', '=', $userState)->get()); $currentcountcheck = Balancedetection::where('bal_usr_roll', '=', $userType)->pluck('user_reg_count'); $statpatuserid = State::where('adt_state_name', '=', $userState)->pluck('adt_state_code'); } else { return Response::json(array('status' => 'failure', 'message' => 'You Exceed the limit for creating State Partner')); } } if ($usercountdetails > $currentcountcheck) { return Response::json(array('status' => 'failure', 'message' => 'You Reached Limit for creating Sub Role')); } else { if (empty($usercount)) { if ($userType == 'SAS') { $usercount = Balancedetection::where('bal_usr_roll', '=', 'SA')->pluck('user_reg_count'); } elseif ($userType == 'SP') { $usercount = Balancedetection::where('bal_usr_roll', '=', 'SD')->pluck('user_reg_count'); } elseif ($userType == 'SPS') { $usercount = Balancedetection::where('bal_usr_roll', '=', 'SP')->pluck('user_reg_count'); } elseif ($userType == 'SD') { $usercount = Balancedetection::where('bal_usr_roll', '=', 'D')->pluck('user_reg_count'); } elseif ($userType == 'SDS') { $usercount = Balancedetection::where('bal_usr_roll', '=', 'SD')->pluck('user_reg_count'); } elseif ($userType == 'D') { $usercount = Balancedetection::where('bal_usr_roll', '=', 'FR')->pluck('user_reg_count'); } elseif ($userType == 'DS') { $usercount = Balancedetection::where('bal_usr_roll', '=', 'D')->pluck('user_reg_count'); } elseif ($userType == 'FR') { $usercount = Balancedetection::where('bal_usr_roll', '=', 'SFR')->pluck('user_reg_count'); } elseif ($userType == 'FRS') { $usercount = Balancedetection::where('bal_usr_roll', '=', 'FR')->pluck('user_reg_count'); } elseif ($userType == 'SFR') { $usercount = Balancedetection::where('bal_usr_roll', '=', 'SFRS')->pluck('user_reg_count'); } else { } } $usernameforpass = preg_replace('/\\s+/', '', $userName); $userkeysend = $userType . $usernameforpass . str_random(2); $userkey = md5($userkeysend); $input = array('UD_USER_ID' => 0, 'UD_USER_KEY' => $userkey, 'UD_USER_NAME' => Input::get('userName'), 'UD_PARENT_ID' => Input::get('parentIdPk'), 'UD_USER_TYPE' => Input::get('userType'), 'UD_USER_EMAIL' => Input::get('userEmail'), 'UD_USER_MOBILE' => Input::get('userMobile'), 'UD_USER_ADDRESS1' => Input::get('userAddress1'), 'UD_USER_ADDRESS2' => Input::get('userAddress2'), 'UD_USER_CITY' => Input::get('userCity'), 'UD_USER_STATE' => Input::get('userState'), 'UD_USER_PINCODE' => Input::get('userPincode'), 'UD_USER_STATUS' => Input::get('userStatus'), 'UD_CREATED_AT' => $createdat, 'UD_CREATED_BY' => Input::get('currentUserId'), 'UD_USER_LINK' => Input::get('UD_USER_LINK'), 'UD_USER_CREATE_COUNT' => $usercount); $userid = DB::table('adt_user_details')->insertGetId($input); if ($userType != 'SP') { $useridgen = $userType . $userid; } else { $useridgen = $statpatuserid . $userid; } $useridupdate = array('UD_USER_ID' => $useridgen); User::where('UD_ID_PK', $userid)->update($useridupdate); $len = count($products); for ($j = 0; $j < $len; $j++) { $productinput = array('upa_prod_code' => $products[$j]['prodCode'], 'upa_ud_user_id' => $useridgen, 'upa_access_status' => $products[$j]['prodStatus'], 'upa_created_at' => $createdat, 'upa_created_by' => $currentUserId); $newproduct = new Userproductaccess(); $newproduct->create($productinput); } $userfinance = array('ufin_user_id_pk_fk' => $userid, 'ufin_user_id' => $useridgen, 'ufin_main_balance' => $mainbalance, 'ufin_comm_earned' => 0, 'ufin_total_credited' => 0, 'ufin_total_used' => 0, 'ufin_total_comm' => 0, 'ufin_fee_perc' => 0, 'ufin_lock_balance' => $lockbalance); $objfinance = new Userfinance(); $objfinance->create($userfinance); $balanceupdate = array('ufin_main_balance' => $newbalance); Userfinance::where('ufin_user_id', $parentId)->update($balanceupdate); Mail::send('users.mails.welcome', array('userid' => $useridgen, 'password' => $userkeysend), function ($message) { $message->to(Input::get('userEmail'), Input::get('userName'))->subject('Reg: User ID and Password For you AppanDUkan Account'); }); return Response::json(array('status' => 'success', 'message' => 'User have Been Created Successfully')); } } } } else { return Response::json(array('status' => 'failure', 'message' => 'Atlease Fill Once Product to Register the User')); } } } } else { return Response::json(array('status' => 'failure', 'message' => 'Fill All Manditary Fields')); } } }
public function postregister() { $rules = array('state' => 'required', 'city' => 'required', 'other_city' => 'required_if:city,other', 'centre' => 'required_if:city,other', 'school' => 'required', 'name' => "required_if:school,other|string", 'addr1' => 'required_if:school,other', 'pincode' => 'required_if:school,other|digits:6', 'contact' => 'required_if:school,other', 'squad' => 'required', 'language' => 'required', 'name1' => "required|Regex:/^[\\p{L} .'-]+\$/", 'email1' => 'required|email', 'contact1' => 'required|numeric', 'name2' => "required|Regex:/^[\\p{L} .'-]+\$/", 'email2' => 'required|email', 'contact2' => 'required|numeric'); $messages = array('name.regex' => 'School name can have words, commas, dashes, single quotes and dots.', 'pincode.digits' => 'Pincode can have exactly 6 digits.', 'contact.numeric' => 'School contact can have only digits.', 'name1.regex' => 'Name of Particpant 1 can have words, commas, dashes, single quotes and dots.', 'contact1.numeric' => 'Contact of Participant 1 can have only digits.', 'email1.email' => 'Email ID of Participant 1 has to be a valid email address.', 'name2.regex' => 'Name of Particpant 2 can have words, commas, dashes, single quotes and dots.', 'contact2.numeric' => 'Contact of Participant 2 can have only digits.', 'email2.email' => 'Email ID of Participant 2 has to be a valid email address.'); $validator = Validator::make(Input::all(), $rules, $messages); if ($validator->fails()) { Input::flash(); return Redirect::to('register')->withErrors($validator)->withInput(); } else { if (Input::get('city') === 'other') { $city = new City(); $city->name = ucwords(strtolower(Input::get('other_city'))); $city->state_id = Input::get('state'); $state = State::where('id', Input::get('state'))->first(); $city->region = $state->region; // $code=City::where('region', $state->region)->orderBy('code', 'desc')->first(); // $city->code=($code->code) + 1; $city->save(); $cities = City::where('name', Input::get('other_city'))->orderBy('id', 'desc')->first(); $city = $cities->id; } else { $city = Input::get('city'); } if (Input::get('centre') !== "") { $centre = Input::get('centre') * 10; } else { $centre = $city * 10; } if (Input::get('school') === 'other') { $school = new School(); $school->name = strtoupper(Input::get('name')); $school->address = strtoupper(Input::get('addr1') . ', ' . Input::get('addr2')); $school->pincode = Input::get('pincode'); $school->contact = Input::get('contact'); $school->email = Input::get('email'); $school->city_id = $city; $school->save(); $schools = School::where('name', Input::get('name'))->orderBy('id', 'desc')->first(); $school = $schools->id; } else { $school = Input::get('school'); } $user = new User(); $user->name1 = strtoupper(Input::get('name1')); $user->email1 = Input::get('email1'); $user->contact1 = Input::get('contact1'); $user->name2 = strtoupper(Input::get('name2')); $user->email2 = Input::get('email2'); $user->contact2 = Input::get('contact2'); $user->squad = Input::get('squad'); $user->school_id = $school; $user->language = Input::get('language'); $user->city_id = $city; $user->centre_id = $centre; $roll = ""; if (Input::get('squad') === 'JUNIOR') { $roll = "J"; } else { $roll = "H"; } if (Input::get('language') === 'en') { $roll .= "E"; } else { $roll .= "H"; } $centre_id = City::where('id', $centre / 10)->orderBy('id')->first(); // $code=$centre_id->id; $roll .= $centre_id->code; $roll .= 1; $lastroll = User::withTrashed()->where('roll', 'LIKE', "%{$roll}%")->count(); $roll .= str_pad(strval($lastroll + 1), 4, "0", STR_PAD_LEFT); $user->roll = $roll; $user->year = 2015; $password = str_random(6); $user->password = Hash::make($password); $user->save(); $school = School::find($user->school_id); $city = City::find($user->city_id); $state = State::find($city->state_id); Mail::send('emails.registered', array('user' => $user, 'school' => $school, 'city' => $city, 'state' => $state, 'password' => $password, 'name' => $user->name1), function ($message) use($user) { $message->to($user->email1, $user->name1)->subject('Technothlon Registration Details'); }); Mail::send('emails.registered', array('user' => $user, 'school' => $school, 'city' => $city, 'state' => $state, 'password' => $password, 'name' => $user->name2), function ($message) use($user) { $message->to($user->email2, $user->name2)->subject('Technothlon Registration Details'); }); Input::flush(); // return Redirect::route('home'); return View::make('layouts.registersuccess')->with('user', $user); } }