/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postCreate()
 {
     // Declare the rules for the form validation
     $rules = array('name' => 'required|min:3', 'description' => 'required|min:3', 'email' => 'required|min:3', 'callback' => 'required|min:3', 'website' => 'required|min:3');
     // Validate the inputs
     $validator = Validator::make(Input::all(), $rules);
     // Check if the form validates with success
     if ($validator->passes()) {
         // Create a new blog post
         $user = Auth::user();
         // Update the blog post data
         $this->client->name = Input::get('name');
         $this->client->id = $this->keygen();
         $this->client->secret = $this->keygen();
         //$this->client->user_id          = $user->id;
         // Was the blog post created?
         if ($this->client->save()) {
             //Create Endpoint Object
             $endpoint = new ClientEndpoint(array('redirect_uri' => Input::get('callback')));
             $metadata = array(new ClientMetadata(array('key' => 'slug', 'value' => Str::slug(Input::get('name')))), new ClientMetadata(array('key' => 'description', 'value' => Str::slug(Input::get('description')))), new ClientMetadata(array('key' => 'email', 'value' => Str::slug(Input::get('email')))), new ClientMetadata(array('key' => 'website', 'value' => Str::slug(Input::get('website')))));
             if (!$this->client->endpoint()->save($endpoint)) {
                 //delete client
                 $id = $this->client->id;
                 $this->client->delete();
                 // Was the blog post deleted?
                 $client = Client::find($id);
                 if (empty($client)) {
                     // Redirect to the blog post create page
                     return Redirect::to('admin/clients/create')->with('error', Lang::get('admin/clients/messages.create.endpoint_error'));
                 }
             }
             if (!$this->client->metadata()->saveMany($metadata)) {
                 //delete client
                 $id = $this->client->id;
                 $this->client->delete();
                 // Was the blog post deleted?
                 $client = Client::find($id);
                 if (empty($client)) {
                     // Redirect to the blog post create page
                     return Redirect::to('admin/clients/create')->with('error', Lang::get('admin/clients/messages.create.metadata_error'));
                 }
             }
             // Redirect to the new blog post page
             return Redirect::to('admin/clients/' . $this->client->id . '/edit')->with('success', Lang::get('admin/clients/messages.create.success'));
         }
         // Redirect to the blog post create page
         return Redirect::to('admin/clients/create')->with('error', Lang::get('admin/clients/messages.create.error'));
     }
     // Form validation failed
     return Redirect::to('admin/clients/create')->withInput()->withErrors($validator);
 }
 public function actionCompleteRegistrationAjax()
 {
     $client = new Client();
     $client->attributes = $_POST['Client'];
     if ($client->save()) {
         $drive = new Drive();
         $drive->attributes = $_POST['Drive'];
         $drive->client_id = $client->primaryKey;
         $drive->creation_date = date("Y-m-d H:i:s");
         if ($drive->save()) {
             $driv = Drive::model()->findByPk($drive->primaryKey);
             $message = new YiiMailMessage();
             $message->view = 'pruebamanejo';
             $message->setBody(array("client" => $client, "drive" => $driv), 'text/html');
             $message->setSubject('Solicitud Prueba de Manejo');
             foreach ($driv->concessioner->emails as $email) {
                 // if($email->type=="DRIVE"){
                 if ($email->type == "QUOTATION") {
                     $message->addTo($email->description);
                 }
             }
             //          		$message->addTo("*****@*****.**");
             //				$message->addTo("*****@*****.**");
             $message->addTo("*****@*****.**");
             $message->addTo("*****@*****.**");
             $message->setFrom(array(Yii::app()->params['adminEmail'] => 'El Equipo Nissan Ecuador'));
             Yii::app()->mail->send($message);
             echo json_encode(true);
         } else {
             echo json_encode(false);
         }
     }
 }
 /**
  * Save Client
  * 
  * @param Client $client
  * @throws DaoException 
  */
 public function saveClient(Client $client)
 {
     try {
         $client->save();
     } catch (Exception $e) {
         throw new DaoException($e->getMessage(), $e->getCode(), $e);
     }
 }
 public function save($con = null)
 {
     $c = new Client();
     $c->setName($this->getValue("name"));
     $c->setDepartment($this->getValue("department"));
     $c->setAddress($this->getValue("address"));
     $c->setEmail($this->getValue("email"));
     $c->setPhone($this->getValue("phone"));
     $c->save();
 }
Example #5
0
 public static function Create($name, $telephone, $idno, $email, $address, $bal, $details)
 {
     $type = new PartyType('Client');
     $client = new Client($type, $name, $telephone, $idno, $email, $address, $bal, $details);
     if ($client->save()) {
         return $client;
     } else {
         return false;
     }
 }
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndex()
 {
     $client = new Client();
     $vehicle = new VehicleClient();
     $technicaldate = new TechnicalDate();
     $concessioners = Concessioner::model()->findAll();
     $criteria = new CDbCriteria();
     //$criteria->condition = 'id != 32 AND id != 33 AND id != 34  AND id != 36 AND id != 37 AND id != 38 AND id != 39 AND id != 40 AND id != 41 AND id != 42';
     //$criteria->order=name;
     $criteria = new CDbCriteria();
     //$criteria->condition = 'id != 36';
     $criteria->order = "name";
     $versions = VehicleVersion::model()->with('vehicle')->findAllbyAttributes(array(), $criteria);
     //$versions= VehicleVersion::model()->findAllbyAttributes(array('status'=>'ACTIVE'),$criteria);
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'client-form') {
         echo CActiveForm::validate($client);
         Yii::app()->end();
     }
     if (isset($_POST['siguiente'])) {
         // die("hola");
         if (isset($_POST['Client']) && isset($_POST['TechnicalDate']) && isset($_POST['VehicleClient'])) {
             //die("hola");
             $client = new Client();
             $client->attributes = $_POST['Client'];
             $client->save();
             $vehicle = new VehicleClient();
             $vehicle->attributes = $_POST['VehicleClient'];
             $vehicle->save();
             $technicaldate = new TechnicalDate();
             $technicaldate->attributes = $_POST['TechnicalDate'];
             $technicaldate->client_id = $client->primaryKey;
             $technicaldate->vehicle_id = $vehicle->primaryKey;
             if ($technicaldate->save()) {
                 $message = new YiiMailMessage();
                 $message->view = 'agendamiento';
                 $message->setSubject('Prospecto agendamiento de Cita');
                 $message->setBody(array("client" => $client, "vehicle" => $vehicle, "technicaldate" => $technicaldate), 'text/html');
                 $message->setFrom(array(Yii::app()->params['adminEmail'] => 'El Equipo Nissan Ecuador'));
                 foreach ($technicaldate->concessioner->emails as $email) {
                     if ($email->type == "TECHNICAL_DATE") {
                         $message->addTo($email->description);
                     }
                 }
                 //$message->addTo("*****@*****.**");
                 Yii::app()->mail->send($message);
                 $this->render('result', array("client" => $client, "vehicle" => $vehicle, "technicaldate" => $technicaldate));
             } else {
                 $this->render('error');
             }
         }
         //$this->render('index',array('concessioners'=>$concessioners,"client"=>$client,"vehicle"=>$vehicle,"technicaldate"=>$technicaldate));
     } else {
         $this->render('index', array('concessioners' => $concessioners, "client" => $client, "vehicle" => $vehicle, "technicaldate" => $technicaldate, "versions" => $versions));
     }
 }
Example #7
0
 public function postSaveclient()
 {
     $client = new Client();
     $client->name = Input::get('name');
     $client->email = Input::get('email');
     $client->mobile = Input::get('mobile');
     $client->city = Input::get('city');
     $client->address1 = Input::get('address1');
     $client->address2 = Input::get('address2');
     $client->save();
     return Response::json($client);
 }
 public function up()
 {
     (new \Lrs())->get()->each(function ($lrs) {
         if (isset($lrs->api) && isset($lrs->api['basic_key']) && isset($lrs->api['basic_secret'])) {
             $client = new \Client();
             $client->api = $lrs->api;
             $client->lrs_id = $lrs->_id;
             $client->authority = ['name' => $lrs->title, 'mbox' => 'mailto:hello@learninglocker.net'];
             $client->save();
         }
     });
 }
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     if (!empty($_POST['RegistrationForm'])) {
         $model->attributes = $_POST['RegistrationForm'];
         if ($model->validate()) {
             if (User::model()->exists('email=:email and status!=:status', array(':email' => $model->email, ':status' => L::r_item('userStatus', 'not_active')))) {
                 $model->addError('email', 'Пользователь с таким почтовым адресом уже зарегестрирован в нашей системе.');
             } else {
                 // регистрация пошла, отпраляю почту и создаю пользователя со статусом "не активен"
                 Yii::import('ext.yii-mail.*');
                 $message = new YiiMailMessage();
                 $message->view = 'email_confirmation';
                 $message->setBody(array('hash' => sha1($model->email . Yii::app()->params['salt']), 'email' => $model->email, 'date' => date('YmdHis')), 'text/html');
                 $message->subject = Yii::app()->name . ' - Подтверждение почтового адреса/E-mail confirmation';
                 $message->addTo($model->email);
                 $message->from = Yii::app()->params['registrationEmail'];
                 if (Yii::app()->mail->send($message)) {
                     if (!($user = User::model()->find('email=:email', array(':email' => $model->email)))) {
                         $user = new User();
                     } else {
                         # надо удалить потеряного клиента
                         Client::model()->deleteByPk($user->username);
                     }
                     $user->username = $model->username;
                     $user->password = $model->password;
                     $user->password_confirm = $model->password_confirm;
                     $user->created = date('Y-m-d H:i:s');
                     $user->email = $model->email;
                     $user->city = $model->city;
                     $user->name = $model->name;
                     $user->status = L::r_item('userStatus', 'not_active');
                     if ($user->save()) {
                         if (!($client = Client::model()->find('username=:username', array(':username' => $user->username)))) {
                             $client = new Client();
                         }
                         # Добавляю клиента
                         $client->attributes = $model->attributes;
                         $client->card = Client::model()->find(array('select' => 'max(card) as maxCardNumber'))->maxCardNumber + 1;
                         $client->save();
                         Yii::app()->user->setFlash('registration', 'На указанный Вами e-mail было отправленно письмо с кодом подтверждения. Введите его.');
                         $this->redirect(array('users/confirmation'));
                     }
                 } else {
                     $model->addError('email', 'Мы не можем отправить почту на указаный Вами адрес.');
                 }
             }
         }
     }
     $model->password = null;
     $model->password_confirm = null;
     $this->render('registration', array('registration_form' => $model));
 }
Example #10
0
 /**
  * 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      PropelPDO $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(PropelPDO $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 coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aElement !== null) {
             if ($this->aElement->isModified() || $this->aElement->isNew()) {
                 $affectedRows += $this->aElement->save($con);
             }
             $this->setElement($this->aElement);
         }
         if ($this->aOrderStatus !== null) {
             if ($this->aOrderStatus->isModified() || $this->aOrderStatus->isNew()) {
                 $affectedRows += $this->aOrderStatus->save($con);
             }
             $this->setOrderStatus($this->aOrderStatus);
         }
         if ($this->aClient !== null) {
             if ($this->aClient->isModified() || $this->aClient->isNew()) {
                 $affectedRows += $this->aClient->save($con);
             }
             $this->setClient($this->aClient);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = OrderPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = OrderPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += OrderPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Client();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Client'])) {
         $model->attributes = $_POST['Client'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->username));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $client = new Client();
     $client->company = Input::get('company');
     $client->street_address = Input::get('street_address');
     $client->city = Input::get('city');
     $client->state = Input::get('state');
     $client->zip = Input::get('zip');
     $client->website = Input::get('website');
     $client->notes = Input::get('notes');
     $client->save();
     Flash::message('Client Added!');
     return Redirect::route('add_client')->with('flash_message', 'Client Added!');
 }
 public function setUp()
 {
     Yii::app()->db->createCommand()->truncateTable('link_client_to_instruction');
     Yii::app()->db->createCommand()->truncateTable('property');
     Yii::app()->db->createCommand()->truncateTable('deal');
     Yii::app()->db->createCommand()->truncateTable('client');
     Yii::app()->db->createCommand()->truncateTable('currentPropertyOwner');
     Yii::app()->db->createCommand()->truncateTable('cli2off');
     Yii::app()->db->createCommand()->truncateTable('offer');
     $this->migration = new m121127_103823_populate_currentPropertyOwners_table();
     $this->migration->down();
     $this->property = new Property();
     $this->property->save(false);
     $this->assertInstanceOf('Property', $this->property);
     $this->owner1 = new Client();
     $this->owner1->save(false);
     $this->owner2 = new Client();
     $this->owner2->save(false);
     $this->owner3 = new Client();
     $this->owner3->save(false);
     $this->owner4 = new Client();
     $this->owner4->save(false);
 }
 /**
  * Store a newly created client in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Client::$rules);
     $user = Auth::user();
     if ($validator->passes()) {
         // store the client data
         $this->client->name = Input::get('name');
         $this->client->address_1 = Input::get('address_1');
         $this->client->address_2 = Input::get('address_2');
         $this->client->city = Input::get('city');
         $this->client->zip = Input::get('zip');
         $this->client->state = Input::get('state');
         $this->client->country_id = Input::get('country_id');
         $this->client->phone = Input::get('phone');
         $this->client->mobile = Input::get('mobile');
         $this->client->fax = Input::get('fax');
         $this->client->email = Input::get('email');
         $this->client->web = Input::get('web');
         $this->client->user_id = $user->id;
         if (Input::hasFile('logo')) {
             $file = Input::file('logo');
             $thumbnail = Image::make($file->getRealPath())->crop(200, 80);
             $destinationPath = 'uploads/' . $user->username . "/clients/";
             $filename_string = sha1(time() . time() . $file->getClientOriginalName());
             $filename = $filename_string . "." . $file->getClientOriginalExtension();
             $filename_thumb = $filename_string . "_thumb" . "." . $file->getClientOriginalExtension();
             if (!File::exists($destinationPath)) {
                 mkdir($destinationPath, 0777, true);
             }
             $upload_success = Input::file('logo')->move($destinationPath, $filename) && $thumbnail->save($destinationPath . "/" . $filename_thumb);
             if ($upload_success) {
                 $this->client->image_name = $file->getClientOriginalName();
                 $this->client->image_path = $destinationPath . $filename;
                 $this->client->image_path_thumbnail = $destinationPath . $filename_thumb;
             }
         }
         if ($this->client->save()) {
             $this->client->user_id = $user->id;
             if (Request::ajax()) {
                 return Response::json(array('status' => 'success'));
             }
             return Redirect::to('clients/' . $this->client->id . '/edit')->with('success', Lang::get('client.message.success.create'));
         }
     }
     if (Request::ajax()) {
         return Response::json(array('status' => 'error', 'errors' => $validator->errors()->toArray()));
     }
     return Redirect::back()->withErrors($validator)->withInput();
 }
Example #15
0
 function save()
 {
     $id = $this->input->post("id");
     if ($id == 0) {
         $clientObject = new Client();
     } else {
         $clientObject = new Client($id);
     }
     $clientObject->name = $this->input->post("name", TRUE);
     $clientObject->address = $this->input->post("address", TRUE);
     $clientObject->number = $this->input->post("number", TRUE);
     $clientObject->email = $this->input->post("email", TRUE);
     $clientObject->save();
     echo $clientObject->id;
 }
 public function postCreate()
 {
     $rules = array('name' => 'required|unique:clients', 'uuid' => 'required|unique:clients');
     $validation = Validator::make(Input::all(), $rules);
     if ($validation->fails()) {
         return Redirect::to('client/create')->withErrors($validation->messages());
     }
     $client = new Client();
     $client->name = Input::get('name');
     $client->uuid = Input::get('uuid');
     $client->save();
     /* Immediately clear the cache */
     Cache::forget('clients');
     return Redirect::to('client/list')->with('success', 'Client added!');
 }
 public function actionCompleteRegistrationAjax()
 {
     if (isset($_POST['vehicle_id']) && isset($_POST['km']) && isset($_POST['Client'])) {
         $client = new Client();
         $client->attributes = $_POST['Client'];
         $client->preference_contact = '-';
         if ($client->save()) {
             $maintainance = Maintainance::model()->findByAttributes(array('vehicle_id' => $_POST['vehicle_id'], 'km' => $_POST['km']));
             if ($maintainance) {
                 $clientMaintainance = new ClientMaintainance();
                 $clientMaintainance->client_id = $client->id;
                 $clientMaintainance->maintainance_id = $maintainance->id;
                 $clientMaintainance->creation_date = date('Y-m-d H:i:s');
                 if ($clientMaintainance->save()) {
                     /*$quot= Quotation::model()->findByPk( $quotation->primaryKey);
                                $message = new YiiMailMessage;
                                $message->view = 'cotizador';
                                $message->setBody(array("client"=>$client,"quotation"=>$quot),'text/html');
                     		$message->setSubject('Prospecto para Cotización');
                                 	foreach($quot->concessioner->emails as $email){
                                     if($email->type=="QUOTATION"){
                                     $message->addTo($email->description);
                                }
                               	}
                     	    // $message->addTo("*****@*****.**");
                                $message->setFrom(array(Yii::app()->params['adminEmail']=>'El Equipo Nissan Ecuador'));
                                Yii::app()->mail->send($message);*/
                     $rutines = Rutine::model()->findAllByAttributes(array('km' => $_POST['km']));
                     $return = [];
                     $return['pdf'] = $maintainance->vehicle->pdf;
                     foreach ($rutines as $i => $rutine) {
                         $return[] = $rutine->description;
                     }
                     echo json_encode($return);
                 } else {
                     echo "no save clientMaintainance";
                 }
             } else {
                 echo "no maintainance";
             }
         } else {
             echo "no save client";
             echo json_encode($client->getErrors());
         }
     } else {
         echo 'no post';
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $client = new Client();
     $data = Input::all();
     // Revisamos si la data es válido
     if ($client->isValid($data)) {
         // Si la data es valida se la asignamos al client
         $client->fill($data);
         // Guardamos el client
         $client->save();
         return Redirect::to('admin/client')->with('success_message', 'El registro ha sido ingresado correctamente.')->withInput();
     } else {
         // En caso de error regresa a la acción create con los datos y los errores encontrados
         return Redirect::back()->withInput()->withErrors($client->errors);
     }
 }
 /**
  * Show the form for creating a new resource.
  * GET /clients/create
  *
  * @return Response
  */
 public function create()
 {
     $pTitle = "Clients";
     $name = Input::get('name');
     $user_id = Auth::id();
     // Validation
     $validator = Validator::make(array('name' => $name), array('name' => 'required|unique:clients'));
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator);
     }
     $client = new Client();
     $client->name = $name;
     $client->user_id = $user_id;
     $client->save();
     return Redirect::back()->with('success', $name . " is now a new client.");
 }
Example #20
0
 function test_getClients()
 {
     $name = "Megan";
     $id = null;
     $test_stylist = new Stylist($name, $id);
     $test_stylist->save();
     $stylist_id = $test_stylist->getId();
     $client_name = "Shawnee";
     $test_client = new Client($id, $client_name, $stylist_id);
     $test_client->save();
     $client_name2 = "Katie";
     $test_client2 = new Client($id, $client_name, $stylist_id);
     $test_client2->save();
     $result = $test_stylist->getClients();
     $this->assertEquals([$test_client, $test_client2], $result);
 }
Example #21
0
 function test_getAll()
 {
     //Arrange
     $client_name = "Ted";
     $stylist_id = 1;
     $test_client = new Client($client_name, $stylist_id);
     $test_client->save();
     $client_name2 = "Mae";
     $stylist_id2 = 2;
     $test_client2 = new Client($client_name2, $stylist_id2);
     $test_client2->save();
     //Act
     $result = Client::getAll();
     //Assert
     $this->assertEquals([$test_client, $test_client2], $result);
 }
 public function actionCompleteRegistrationAjax()
 {
     if (isset($_POST['selection']) && isset($_POST['Client'])) {
         $client = new Client();
         $client->attributes = $_POST['Client'];
         $client->preference_contact = '-';
         if ($client->save()) {
             $error = false;
             $selection = preg_split('/,/', $_POST['selection']);
             foreach ($selection as $i => $s) {
                 $cc = new ClientCatalog();
                 $cc->client_id = $client->id;
                 $cc->catalog_id = $s;
                 $cc->creation_date = date("Y-m-d H:i:s");
                 $cc->isNewRecord = true;
                 if (!$cc->save()) {
                     $error = true;
                     break;
                 }
                 unset($cc);
             }
             if (!$error) {
                 /*$quot= Quotation::model()->findByPk( $quotation->primaryKey);
                            $message = new YiiMailMessage;
                            $message->view = 'cotizador';
                            $message->setBody(array("client"=>$client,"quotation"=>$quot),'text/html');
                 		$message->setSubject('Prospecto para Cotización');
                             	foreach($quot->concessioner->emails as $email){
                                 if($email->type=="QUOTATION"){
                                 $message->addTo($email->description);
                            }
                           	}
                 	    // $message->addTo("*****@*****.**");
                            $message->setFrom(array(Yii::app()->params['adminEmail']=>'El Equipo Nissan Ecuador'));
                            Yii::app()->mail->send($message);*/
                 echo json_encode(true);
             } else {
                 echo json_encode(false);
             }
         } else {
             echo "no save client";
             echo json_encode($client->getErrors());
         }
     } else {
         echo 'no post';
     }
 }
Example #23
0
 public static function createClient($input)
 {
     $input = $input;
     $rules = array('name' => 'Required', 'description' => 'Required', 'email' => '|Between:3,64|Email');
     $v = Validator::make($input, $rules);
     if ($v->passes()) {
         $client = new Client();
         $client->name = Input::get('name');
         $client->description = Input::get('description');
         $client->phone_number = Input::get('phone');
         $client->address = Input::get('address');
         $client->email = Input::get('email');
         $client->save();
         return Redirect::to('clients');
     } else {
         return Redirect::to('new_client')->withErrors($v);
     }
 }
Example #24
0
 /**
  * Store a newly created client in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Client::$rules, Client::$messages);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $client = new Client();
     $client->name = Input::get('name');
     $client->contact_person = Input::get('cname');
     $client->email = Input::get('email_office');
     $client->contact_person_email = Input::get('email_personal');
     $client->contact_person_phone = Input::get('mobile_phone');
     $client->phone = Input::get('office_phone');
     $client->address = Input::get('address');
     $client->type = Input::get('type');
     $client->save();
     return Redirect::route('clients.index')->withFlashMessage('Client successfully created!');
 }
 public static function store()
 {
     $params = $_POST;
     $attributes = array('firstName' => $params['firstName'], 'lastName' => $params['lastName'], 'username' => $params['username'], 'password' => $params['password']);
     $client = new Client($attributes);
     $client->save();
     //        if (count($errors) == 0) {
     //            $employee->save();
     //            foreach ($services as $serv) {
     //                if (isset($_POST[$serv->id])) {
     //                    OfferedServicesController::create($employee->id, $serv->id);
     //                }
     //            }
     Redirect::to('/asiakkaat/omattiedot', array('message' => 'Uusi tunnus luotu!'));
     //        } else {
     //            View::make('employee/new.html', array('errors' => $errors, 'attributes' => $attributes));
     //        }
 }
 public function store()
 {
     $rules = array('name' => 'required', 'country' => 'required', 'state' => 'required', 'city' => 'required', 'zip' => 'required', 'address' => 'required', 'contact' => 'required', 'phone' => 'required', 'email' => 'required|email', 'website' => 'url');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->passes()) {
         $store = new Client();
         $store->fill(Input::all());
         $store->save();
     } else {
         if (Request::ajax()) {
             $data = array('errors' => $validator->errors(), 'inputs' => Input::all());
             return View::make('clients.create', $data);
         }
         return 0;
     }
     $data = array('clients' => Client::orderBy('id', 'desc')->get(), 'refresh' => true);
     return View::make('clients.table', $data);
 }
Example #27
0
 protected function _checkUser()
 {
     if (fnGet($this->input, 'access_token') == '') {
         $this->_ajaxReturn(array('error_code' => '600020', 'error_msg' => '参数[access_token]不能为空'), 400);
     }
     // 设置当前用户和客户端
     $this->session->setUser($user = new User())->setClient($client = new Client());
     $passportConfig = $this->config->get("api.passport");
     // 尝试从缓存获取 userInfo
     if ($this->_userInfo = S($cacheKey = 'access_token_info.' . fnGet($this->input, 'access_token'))) {
         $user->find(fnGet($this->_userInfo, 'user_id'));
         $client->find(fnGet($this->_userInfo, 'client_id'));
         return;
     }
     // 向 passport 请求 userInfo
     $time = time();
     $url = str_replace('internal-resource/user-info?', '', $passportConfig->passportUrl) . 'internal-resource/user-info';
     $params = array('access_token' => fnGet($this->input, 'access_token'), 'app' => $passportConfig->passportApp, 'time' => $time);
     $sign = md5(implode('', $params) . $passportConfig->passportSecret);
     $params['sign'] = $sign;
     $http = new HttpClient();
     $response = $http->request($url, $params);
     $data = json_decode($response, true);
     if (fnGet($data, 'id')) {
         //检测用户是否已经保存
         $user->getByUsername($username = fnGet($data, 'username'));
         if (!($userId = $user->getId()) || !$user->getData('passport_id') || $user->getData('mobile') != fnGet($data, 'mobile')) {
             $user->addData(array('username' => $username, 'email' => fnGet($data, 'email'), 'mobile' => fnGet($data, 'mobile'), 'passport_id' => fnGet($data, 'passport_id'), 'avatar' => fnGet($data, 'avatar'), 'nickname' => fnGet($data, 'nickname')));
             $user->save();
             $userId = $user->getId();
         }
         //检测客户端是否已经保存
         $client->getByAppId($appId = fnGet($data, 'client_info/id'));
         if (!($clientId = $client->getId()) || $client->getScopes() != fnGet($data, 'client_info/scopes')) {
             $client->addData(array('client' => $appId, 'name' => fnGet($data, 'client_info/name'), 'app_secret' => fnGet($data, 'client_info/secret'), 'developerurl' => fnGet($data, 'client_info/endpoint'), 'scopes' => fnGet($data, 'client_info/scopes')));
             $client->save();
             $clientId = $client->getId();
         }
         $this->_userInfo = array('user_id' => $userId, 'client_id' => $clientId, 'username' => $username, 'session_data' => fnGet($data, 'session_data'));
         S($cacheKey, $this->_userInfo, 3600);
         return;
     }
     $this->_ajaxReturn(array('error_code' => '600020', 'error_msg' => '用户无效'), 400);
 }
Example #28
0
 function test_GetClients()
 {
     //Arrange
     $name = "Becky";
     $id = null;
     $test_stylist = new Stylist($name, $id);
     $test_stylist->save();
     $name = "Sam";
     $phone = "123-456-7890";
     $stylist_id = $test_stylist->getId();
     $id = 1;
     $test_client = new Client($name, $phone, $stylist_id, $id);
     $test_client->save();
     $name2 = "Sammy";
     $phone2 = "345-567-9812";
     $stylist_id2 = $test_stylist->getId();
     $id = 2;
     $test_client2 = new Client($name, $phone, $stylist_id, $id);
     $test_client2->save();
     //Act
     $result = $test_stylist->getClients();
     //Assert
     $this->assertEquals([$test_client, $test_client2], $result);
 }
Example #29
0
 function test_deleteAll()
 {
     $name = "Megan";
     $id = null;
     $test_stylist = new Stylist($name, $id);
     $test_stylist->save();
     $client_name = "Shawnee";
     $stylist_id = $test_stylist->getId();
     $test_client = new Client($id, $client_name, $stylist_id);
     $test_client->save();
     $client_name2 = "Katie";
     $stylist_id = $test_stylist->getId();
     $test_client2 = new Client($id, $client_name, $stylist_id);
     $test_client2->save();
     Client::deleteAll();
     $result = Client::getAll();
     $this->assertEquals([], $result);
 }
Example #30
0
         // TO DO: affiché une réussite
     } else {
         // TO DO: gestion des erreurs
     }
     break;
 case $ACTION_clientView:
     if (isset($_GET["client"])) {
         $_SESSION["client"] = $_GET["client"];
     }
     break;
 case $ACTION_clientSave:
     if (isset($_POST["client"])) {
         $_SESSION["client"] = $_POST["client"];
     }
     $tempClient = new Client($_POST["client"], $_POST["client_name_field"], $_POST["client_address_field"]);
     $tempClient->save();
     break;
 case $ACTION_clientCreate:
     $tempClient = new Client($_POST["client_name_field"], $_POST["client_address_field"]);
     $tempClient->create();
     break;
 case $ACTION_clientDelete:
     $tempClient = new Client($_GET["client"]);
     $tempClient->delete();
     $_SESSION["client"] = -1;
     break;
 case $ACTION_changeRole:
     // besoin des faire des verif savoir si l'utilisateur a bien le droit de change de ce role
     if (isset($_GET["role"])) {
         $_SESSION["systemData"]->setUserRole($_GET["role"]);
     }