/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { die; $model = new Customer(); // $jaspers_franchise = JaspersFranchise::model()->findAll(); $jaspers_companies = JaspersCompanies::model()->findAllByAttributes(array('franchise_id' => Yii::app()->user->franchise)); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $bannerImg = Banner::model()->findByAttributes(array('isactive' => 1, 'loc' => 1)); $curUser = User::model()->findByPk(Yii::app()->user->uid); if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; $model->jaspers_franchise = Yii::app()->user->franchise; $curUser->name = $model->contact; $curUser->save(); if (Yii::app()->user->isUser()) { $model->attendee = Yii::app()->user->uid; $model->franchise = Yii::app()->user->franchise; } if ($model->save()) { Yii::app()->session['last_created_user'] = $model->attributes; $istApp = new CustAppoint(); $istApp->app_id = 1; $istApp->cus_id = getCurCusId(); $istApp->status = 0; $istApp->save(); if (isset($_GET['back'])) { $this->redirect(array('site/index')); } //$this->redirect(array('site/getstarted', 'id' => getCurCusId())); $this->redirect(array('workingwell/create', 'id' => getCurCusId())); } } $this->render('create', array('model' => $model, 'bannerImg' => $bannerImg, 'curUser' => $curUser, 'jaspers_companies' => $jaspers_companies)); }
public function actionAddAjax() { if (!isset(Yii::app()->user->storeID)) { $data['message'] = '<div class="alert alert-success">Store not found. </div>'; echo json_encode($data); exit; } $model = new Customer(); if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; $data = array(); $mss = ''; if (count($data) == 0) { $model->pk_s_id = '-1'; $model->i_flag_sync = 1; $model->i_flag_deleted = 0; $model->i_disable = 0; if ($model->save()) { $model->pk_s_id = 'SV' . $model->id; if ($model->save()) { $data['option'] = '<option selected="selected" value ="' . $model->pk_s_id . '">' . $model->s_name . '</option>'; $data['message'] = '<div class="alert alert-success">Success! Customer created. </div>'; } else { $model->delete(); $data['message'] = '<div class="alert alert-danger">Error! Please try again later.</div>'; } } else { $data['message'] = json_encode($model->errors); //'<div class="alert alert-danger">Error! Please try again later2.</div>'; } } echo json_encode($data); } }
public function postAddCustomer() { $validator = Validator::make(Input::all(), array('name' => 'required|max:100', 'address' => 'required|max:200', 'number' => 'required|max:100', 'web' => 'required|max:500')); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } else { $email = '*****@*****.**'; $name = Input::get('name'); $address = Input::get('address'); $number = Input::get('number'); $web = Input::get('web'); $customer = new Customer(); $customer->company_name = $name; $customer->address = $address; $customer->b_reg_number = $number; $customer->website = $web; $insertedToCustomer = $customer->save(); if ($insertedToCustomer) { $data = array('email' => $email); Mail::send('email.email', $data, function ($message) use($data) { $message->to($data['email'])->subject('New Customer Added to the System!'); }); return Redirect::route('dashboard'); } else { return Redirect::route('customer-add'); } } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // $rules = array("customerId" => "required", "firstAddress" => "required", "secondAddress" => "required", "thirdAddress" => "required", "fourthAddress" => "required", "area" => "required", "region" => "required", "customerPhone" => "required|numeric", "customerFax" => "required|numeric", "customerEmail" => "required|email", "customerContact" => "required", "poBirth" => "required|date", "doBirth" => "required|date", "customerReligion" => "required", "customerPosition" => "required", "customerStatus" => "required", "customerChildren" => "required|integer", "customerPhoneHome" => "required|numeric", "customerMobile" => "required|numeric", "customerPinBB" => "required"); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/customer/create')->withErrors($validator); } // $customer = new Customer(); $customer->customerID = Input::get('customerId'); $customer->customerAddress1 = Input::get('firstAddress'); $customer->customerAddress2 = Input::get('secondAddress'); $customer->customerAddress3 = Input::get('thirdAddress'); $customer->customerAddress4 = Input::get('fourthAddress'); $customer->areaID = Input::get('area'); $customer->regionID = Input::get('region'); $customer->customerPhone = Input::get('customerPhone'); $customer->customerFax = Input::get('customerFax'); $customer->customerEmail = Input::get('customerEmail'); $customer->customerContact = Input::get('customerContact'); $customer->POBirth = Input::get('poBirth'); $customer->DOBirth = Input::get('doBirth'); $customer->customerReligion = Input::get('customerReligion'); $customer->customerPosition = Input::get('customerPosition'); $customer->customerStatus = Input::get('customerStatus'); $customer->customerChildren = Input::get('customerChildren'); $customer->customerPhoneHome = Input::get('customerPhoneHome'); $customer->customerMobile = Input::get('customerMobile'); $customer->customerPinBB = Input::get('customerPinBB'); $customer->save(); return Redirect::to('/customer'); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Customer(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; if ($model->save()) { // Comprobamos si existe la lista de envio de todos los clientes if (count(Mailist::model()->findByAttributes(array('Name' => 'Todos los clientes', 'UserID' => Yii::app()->user->ID)))) { // Si existe la lista añadimos el nuevo cliente $ListID = Mailist::model()->findByAttributes(array('Name' => 'Todos los clientes'))->ID; $modelCustomerList = new CustomerList(); $modelCustomerList->UserID = Yii::app()->user->ID; $modelCustomerList->ListID = $ListID; $modelCustomerList->CustomerID = $model->ID; $modelCustomerList->save(); } else { // Si no existe la lista la creamos y añadimos el cliente nuevo $modelMailist = new Mailist(); $modelMailist->Name = "Todos los clientes"; $modelMailist->UserID = Yii::app()->user->ID; if ($modelMailist->save()) { $modelCustomerList = new CustomerList(); $modelCustomerList->UserID = Yii::app()->user->ID; $modelCustomerList->ListID = $modelMailist->ID; $modelCustomerList->CustomerID = $model->ID; $modelCustomerList->save(); } } $this->redirect(array('admin')); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Invoice(); $modelCustomer = new Customer(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Invoice'])) { $model->attributes = $_POST['Invoice']; // Si creamos un nuevo Customer hay que guardarlo if (strlen($model->CustomerID) == 0) { $modelCustomer->attributes = $_POST['Customer']; if ($modelCustomer->save()) { $model->CustomerID = $modelCustomer->ID; } } else { $modelCustomer = Customer::model()->findByPK($model->CustomerID); $modelCustomer->attributes = $_POST['Customer']; $modelCustomer->save(); } if ($model->save()) { $this->redirect(array('admin')); } } $this->render('create', array('model' => $model, 'modelCustomer' => $modelCustomer)); }
public function actionCreate() { if ($model = Shop::getCustomer()) { $address = $model->address; } else { $model = new Customer(); } if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; if (isset($_POST['Address'])) { $address = new Address(); $address->attributes = $_POST['Address']; if ($address->save()) { $model->address_id = $address->id; } } if (!Yii::app()->user->isGuest) { $model->user_id = Yii::app()->user->id; } if ($model->save()) { Yii::app()->user->setState('customer_id', $model->customer_id); $this->redirect(array('//shop/order/create', 'customer' => $model->customer_id)); } } $this->render('create', array('customer' => $model, 'address' => isset($address) ? $address : new Address())); }
public function createCustomer() { // $dbcustomer = new Customer($customer); $rule = array('first_name' => 'required', 'email' => 'email|required'); $cust = Input::all(); $valid = Validator::make($cust, $rule); if ($valid->fails()) { return Redirect::to('add-customer'); } else { $customer = new Customer(); $customer->first_name = Input::get('first_name'); $customer->last_name = Input::get('last_name'); $customer->email = Input::get('email'); $customer->phone_no = Input::get('phone_no'); $customer->address_1 = Input::get('address_1'); $customer->address_2 = Input::get('address_2'); $customer->city = Input::get('city'); $customer->state = Input::get('state'); $customer->zip = Input::get('zip'); $customer->country = Input::get('country'); $customer->comment = Input::get('comment'); $customer->account = Input::get('account'); $customer->save(); return Redirect::to('all-customers'); } }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param ConnectionInterface $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(ConnectionInterface $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aCustomer !== null) { if ($this->aCustomer->isModified() || $this->aCustomer->isNew()) { $affectedRows += $this->aCustomer->save($con); } $this->setCustomer($this->aCustomer); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }
public function actionCreate() { // if some data has been entered before or the user is already logged in, // take the already existing data and prefill the input form if ($model = Shop::getCustomer()) { $address = $model->address; } else { $model = new Customer(); } if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; if (isset($_POST['Address'])) { $address = new Address(); $address->attributes = $_POST['Address']; if ($address->save()) { $model->address_id = $address->id; } } if (!Yii::app()->user->isGuest) { $model->user_id = Yii::app()->user->id; } $model->validate(); if (Shop::module()->useWithYum && isset($_POST['register']) && ($_POST['register'] = true)) { if (isset($_POST['Customer']['password']) && isset($_POST['Customer']['passwordRepeat'])) { if ($_POST['Customer']['password'] != $_POST['Customer']['passwordRepeat']) { $model->addError('password', Shop::t('Passwords do not match')); } else { if ($_POST['Customer']['password'] == '') { $model->addError('password', Shop::t('Password is empty')); } else { $user = new YumUser(); $profile = new YumProfile(); $profile->attributes = $_POST['Customer']; $profile->attributes = $_POST['Address']; if ($user->register(strtr($model->email, array('@' => '_', '.' => '_')), $_POST['Customer']['password'], $profile)) { $user->status = YumUser::STATUS_ACTIVE; $user->save(false, array('status')); $model->user_id = $user->id; Shop::setFlash(Shop::t('Successfully registered user')); } else { $model->addErrors($user->getErrors()); $model->addErrors($profile->getErrors()); Shop::setFlash(Shop::t('Error while registering user')); } } } } } if (!$model->hasErrors()) { if ($model->save()) { Yii::app()->user->setState('customer_id', $model->customer_id); $this->redirect(array('//shop/order/create', 'customer' => $model->customer_id)); } } } $this->render('create', array('customer' => $model, 'address' => isset($address) ? $address : new Address())); }
public function actionRegister() { $model = new Customer(); if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; if ($model->save()) { $this->redirect(array('account/')); } } $this->render('register', array("model" => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Customer(); $contact = new Contact(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation(array($model, $contact)); if ($model->save(false)) { $this->redirect(array('update', 'id' => $model->id)); } $this->render('create', array('model' => $model, 'contact' => $contact)); }
public function action_do_create() { $v = Customer::validate(Input::all()); if ($v->fails()) { return Redirect::to_route('create_customer')->with('user', Auth::user())->with_errors($v)->with_input(); } $new_customer = array('name' => Input::get('name'), 'description' => Input::get('description'), 'organization_id' => Auth::user()->organization->id); $customer = new Customer($new_customer); $customer->save(); return Redirect::to_route('customers'); }
/** Override __construct() because we're not passing user/pass */ public function __construct() { $user = new Customer(); $user->record_type = Customer::GUEST; $user->last_login = new CDbExpression('NOW()'); if ($user->save() === false) { print_r($user->getErrors()); } $this->setState('fullname', 'Guest'); $this->setState('firstname', 'Guest'); $this->_id = $user->id; }
public function actionAddCustomer() { $data = CJSON::decode(file_get_contents('php://input')); $customer = new Customer(); $customer->attributes = $data; if ($customer->save()) { $this->renderJSON($customer); } else { $response = array('success' => false, 'message' => 'Couldn\'t save customer'); $this->renderJSON($response); } }
/** * @param $email * @param $password * @param $company * @param $firstname * @param $lastname * @param $street * @param $zip * @param $city * @param $country * @param int $level * @return Customer * @throws \Propel\Runtime\Exception\PropelException */ public function createLogin($email, $password, $company, $firstname, $lastname, $street, $zip, $city, $country, $level = 0) { $user = new User(); $user->setEmail($email)->setPassword(hash("sha256", $password)); $user->save(); $country_query = new CountryQuery(); $country = $country_query::create()->findOneByCode($country); $customer = new Customer(); $customer->setFirstname($firstname)->setLastname($lastname)->setCompany($company)->setAddress($street)->setZip(intval($zip))->setCity($city)->setCountry($country)->addUser($user); $customer->save(); return $user; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Customer(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->customer_id)); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Book(); $modelCustomer = new Customer(); if ($_GET["id"] != "" && $_GET["d"] != "") { $model->RoomID = $_GET["id"]; $model->Start = date("Y-m-d", $_GET["d"]); } // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Book'])) { $model->attributes = $_POST['Book']; // Check if the Room is booked if (strtotime($model->Finish) - strtotime($model->Start) > 86400) { // More than 1 day $j = (strtotime($model->Finish) - strtotime($model->Start)) / 86400; for ($i = 0; $i < $j; $i++) { $theDate = strtotime($model->Start) + $i * 86400; $criteria = new CDbCriteria(); $criteria->condition = "(:start BETWEEN Start AND Finish) AND RoomID = :roomid AND UserID = :userid"; $criteria->params = array(':start' => date("Y-m-d", $theDate), ':roomid' => $model->RoomID, ':userid' => Yii::app()->user->ID); if (count(Book::model()->find($criteria)) > 0) { $model->addError('Name', 'Ya existe una reserva para el rango de fechas en esta misma habitación.'); $this->render('create', array('model' => $model, 'modelCustomer' => $modelCustomer)); exit; } } } else { // One day booking } // Room is not booked then... // Si creamos un nuevo Customer hay que guardarlo if (strlen($model->CustomerID) == 0) { $modelCustomer->attributes = $_POST['Customer']; $modelCustomer->UserID = Yii::app()->user->ID; if ($modelCustomer->save()) { $model->CustomerID = $modelCustomer->ID; } } else { $modelCustomer = Customer::model()->findByPK($model->CustomerID); $modelCustomer->attributes = $_POST['Customer']; $modelCustomer->UserID = Yii::app()->user->ID; $modelCustomer->save(); } $model->SeasonID = Book::model()->getSeason($model->Start); if ($model->save()) { $this->redirect(array('update', 'id' => $model->ID)); } } $this->render('create', array('model' => $model, 'modelCustomer' => $modelCustomer)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'show' page. */ public function actionCreate() { $model = new Customer(); if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; $model->companyId = Yii::app()->user->getState('selectedCompanyId'); if ($model->save()) { ChangeLog::addLog('ADD', 'Customer', $model->toString()); $this->redirect(array('admin', 'id' => $model->id)); } } $model->dateChanged = User::getDateFormatted(date('Y-m-d')); $this->render('create', array('model' => $model)); }
/** * Authenticate user * @return type */ public function authenticate() { $user = Customer::model()->findByAttributes(array('facebook' => $this->password)); if ($user instanceof Customer) { $this->loginHousekeeping($user); } else { //We didn't find the Facebook ID in the database, but let's see if the user has an account already $user = Customer::model()->findByAttributes(array('email' => $this->username)); if ($user instanceof Customer) { //We found an existing account under this email if (is_null($user->facebook)) { //We found an account, merge them $user->facebook = $this->password; $user->save(); $this->loginHousekeeping($user); } else { //Somehow we've found an existing account with an email from facebook but not the same ID //Clear Facebook ID and bail, this is a serious conflict $user->facebook = $this->password; $user->save(); $this->redirect(Yii::app()->homeUrl); } } else { //New user to our site using Facebook, so set up an account $model = new Customer(); $model->scenario = 'createfb'; $results = Yii::app()->facebook->api('/me'); $model->first_name = $results['first_name']; $model->last_name = $results['last_name']; $model->email = $results['email']; $model->email_repeat = $results['email']; $model->record_type = Customer::REGISTERED; $model->newsletter_subscribe = 1; $model->facebook = $results['id']; if (_xls_get_conf('MODERATE_REGISTRATION', 0) == 1) { $this->errorCode = self::ERROR_NOT_APPROVED; $model->allow_login = Customer::UNAPPROVED_USER; } else { $model->allow_login = Customer::NORMAL_USER; if (!$model->save()) { Yii::log("Error creating Facebook account " . print_r($model->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); die("A serious error has occurred creating a Facebook account"); } $this->loginHousekeeping($model); } } } return $this->errorCode; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Customer(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; if ($model->save()) { $this->audit->logAudit(Yii::app()->user->id, new DateTime(), Constants::AUDITORIA_OBJETO_CLIENTE, Constants::AUDITORIA_OPERACION_ALTA, $model->id); $this->render('/site/successfullOperation', array('header' => 'Cliente creado con éxito', 'message' => 'Haga click en volver para regresar a la gestión de clientes', 'returnUrl' => Yii::app()->createUrl('customer/admin'), 'viewUrl' => Yii::app()->createUrl("customer/view", array("id" => $model->id)))); return; } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $model = new Customer(); if (isset($_POST['Customer'])) { $model->setAttributes($_POST['Customer']); if ($model->save()) { if (Yii::app()->getRequest()->getIsAjaxRequest()) { Yii::app()->end(); } else { $this->redirect(array('view', 'id' => $model->customer_id)); } } } $this->render('create', array('model' => $model)); }
public function postIndex() { if (Input::has('first_name', 'last_name', 'email')) { $input = Input::all(); if ($input['first_name'] == '' || $input['last_name'] == '' || $input['email'] == '') { return Response::make('You need to fill all of the input fields', 400); $customer = new Customer(); $customer->first_name = $input['first_name']; $customer->last_name = $input['last_name']; $customer->email = $input['email']; $customer->save(); return $customer; } else { return Response::make('You need to fill all of the input fields', 400); } } }
/** * * @param <type> $request * @return <type> */ public function execute($request) { $this->setLayout(false); sfConfig::set('sf_web_debug', false); sfConfig::set('sf_debug', false); if ($this->getRequest()->isXmlHttpRequest()) { $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8'); } $customerName = $request->getParameter('customerName'); $description = $request->getParameter('description'); $customer = new Customer(); $customer->setName($customerName); $customer->setDescription($description); $customer->save(); $array = array('id' => $customer->getCustomerId()); return $this->renderText(json_encode($array)); }
public function save() { $this->resultArray = array(); $customerId = $this->getValue('customerId'); if ($customerId > 0) { $service = $this->getCustomerService(); $customer = $service->getCustomerById($customerId); $this->resultArray['messageType'] = 'success'; $this->resultArray['message'] = __(TopLevelMessages::UPDATE_SUCCESS); } else { $customer = new Customer(); $this->resultArray['messageType'] = 'success'; $this->resultArray['message'] = __(TopLevelMessages::SAVE_SUCCESS); } $customer->setName(trim($this->getValue('customerName'))); $customer->setDescription($this->getValue('description')); $customer->save(); return $this->resultArray; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param ConnectionInterface $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(ConnectionInterface $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aCustomer !== null) { if ($this->aCustomer->isModified() || $this->aCustomer->isNew()) { $affectedRows += $this->aCustomer->save($con); } $this->setCustomer($this->aCustomer); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } if ($this->creditAmountHistoriesScheduledForDeletion !== null) { if (!$this->creditAmountHistoriesScheduledForDeletion->isEmpty()) { \CreditAccount\Model\CreditAmountHistoryQuery::create()->filterByPrimaryKeys($this->creditAmountHistoriesScheduledForDeletion->getPrimaryKeys(false))->delete($con); $this->creditAmountHistoriesScheduledForDeletion = null; } } if ($this->collCreditAmountHistories !== null) { foreach ($this->collCreditAmountHistories as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
/** * Lists all models. */ public function actionIndex() { $model = new Customer(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; $model->wlabel_id = Yii::app()->user->getWhiteLabelId(); $model->status = UserStatus::STATUS_PENDING; $model->date_created = date("Y-m-d h:i:s"); if ($model->save()) { $this->redirect(array('index')); } } if (isset($_GET['Customer'])) { $model->attributes = $_GET['Customer']; } $this->render('index', array('model' => $model)); }
public function registerNewCustomer() { $customer = new Customer(); $customer->name = $name = Input::get('name'); $customer->phone = Input::get('phone'); $customer->email = Input::get('email'); $customer->birthday = sqldate(Input::get('birthday')); $customer->mode_id = (int) Input::get('customer_type'); $customer->token = $token = Makehash::random('number', 6); $customer->createdby = Auth::user()->username; if (!$customer->save()) { $data = $customer->validatorStatus; } else { $message = "<p>Registration successful!</p>\n\t\t\t\t\t<p>" . $name . " token is: <span class='label label-large label-info new-token'>" . $token . "</span>\n\t\t\t\t\t</p>"; $data['status'] = 'success'; $data['message'] = $message; $data['detail'] = "Name: {$name} | Token-ID: {$token}"; } return Response::json($data); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { if (CustomerType::model()->count('active=1') == 0) { throw new CHttpException(412, 'No hay tipos de clientes activos. Para crear un cliente, primero debe ' . CHtml::link('crear un tipo de cliente', array('customerType/create')) . '.'); } $model = new Customer(); $model->contact = new Contact(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; $model->dependence_id = $model->dependence_id == '' ? NULL : $model->dependence_id; $model->contact->active = $model->active; if (isset($_POST['Contact'])) { $model->contact->attributes = $_POST['Contact']; $successful = $model->contact->validate(); } $successful = $model->validate() && $successful; if ($successful) { $transaction = Yii::app()->db->beginTransaction(); try { if ($model->save(false)) { $model->contact->customer_id = $model->id; if ($model->contact->save(false)) { $transaction->commit(); if (!empty($_POST['yt1'])) { Yii::app()->user->setFlash('customer-created', "¡El cliente <b><i>"{$model->name}"</i></b> fue creado exitosamente!"); $this->redirect(array('create')); } else { $this->redirect(array('view', 'id' => $model->id)); } } } $transaction->rollBack(); } catch (Exception $e) { $transaction->rollBack(); } } } $this->render('create', array('model' => $model)); }
public function store() { $i = Input::all(); $customer = new Customer(); $customer->membership_id = $this->generateCustomerId(); $customer->pin = Carbon::now()->year; $customer->firstname = $i['firstname']; $customer->lastname = $i['lastname']; $customer->address = $i['address']; if (isset($i['email'])) { $customer->email = $i['email']; } $customer->contact_no = $i['contact_no']; try { if ($customer->save()) { return Redirect::to('adminsite/customer')->with('success_create', 'true'); } } catch (Illuminate\Database\QueryException $e) { return Redirect::to('adminsite/customer')->with('error', $e->errorInfo[2]); } }