/** * create new client * @return avoid */ public function actionCreate() { $client = new Client(); $groups = new Group(); $groups_clients = new GroupClient(); if ($client->load(Yii::$app->request->post()) && $client->validate()) { // get post variable of GroupClient $list_groups = Yii::$app->request->post()['Group']['id']; // groups is required if (!empty($list_groups)) { // save client table first $client->save(); // each group will be saved with a corresponding client which be saved before foreach ($list_groups as $key => $group) { $groups_clients = new GroupClient(); $groups_clients->clients_id = $client->id; $groups_clients->groups_id = $group; $groups_clients->save(); } // everything is ok, redirect to clients list page $errors = $groups_clients->getErrors(); if (empty($errors)) { return $this->redirect(['/clients']); } } else { $groups->addError('id', 'Groups can not blank'); } } return $this->render('create', ['client' => $client, 'groups' => $groups, 'groups_clients' => $groups_clients]); }
/** * Creates a new Order model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $modelClient = new Client(); $modelsOrder = [new Order()]; if ($modelClient->load(Yii::$app->request->post())) { $modelsOrder = Model::createMultiple(Order::classname()); Model::loadMultiple($modelsOrder, Yii::$app->request->post()); // validate all models $valid = $modelClient->validate(); $valid = Model::validateMultiple($modelsOrder) && $valid; if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $modelClient->save(false)) { foreach ($modelsOrder as $modelOrder) { $modelOrder->id_client = $modelClient->id; if (!($flag = $modelOrder->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $modelClient->id]); } } catch (Exception $e) { $transaction->rollBack(); } } } return $this->render('create', ['modelClient' => $modelClient, 'modelsOrder' => empty($modelsOrder) ? [new Order()] : $modelsOrder]); }
public function testAge() { $testObj = new Client(); $testObj->name = "Berta"; $testObj->age = 10; $this->assertFalse($testObj->save()); $this->assertArraySubset(["age" => "Age must be greater than \"18\"."], $testObj->firstErrors); }
/** * Creates a new Client model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Client(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'direction' => Direction::find()->all()]); } }
protected function fakeClient() { $fakeClient = new Client(); $fakeClient->serial_number = "C241874"; $fakeClient->primary_name = "Fake Client"; $fakeClient->client_type_id = $this->fakeClientType()->client_type_id; $fakeClient->save(); return $fakeClient; }
/** * Creates a new Client model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Client(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->clientNumber]); } else { return $this->render('create', ['model' => $model]); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $this->validate($request, ['client' => 'required|unique:projects|max:255', 'image' => 'required']); $image = ImageuploadFacade::upload($request->file('image')); $project = new Client(); $project->client = $request->input('client'); $project->image = $image['basename']; $project->image_ext = $image['original_extension']; $project->save(); return back(); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { /* | | Validate input data | */ $rules = array('id' => 'unique:clients,id', 'spamOrClient' => 'required', 'firstName' => 'required', 'state' => 'required|max:6', 'birthDate' => 'required|max:5', 'mobNum' => 'required|max:13'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { /*return redirect('clients/add')->withErrors([ 'Необходимые данные не введены, либо введены некорректно. Попробуйте еще раз!' ]);*/ return redirect('clients/create')->withErrors($validator)->withInput(Input::all()); } else { /* | | Create new client | */ $newClient = new Client(); $newClient->id = Input::get('cardID'); $newClient->spamOrClient = Input::get('spamOrClient'); $newClient->lastName = Input::get('lastName'); $newClient->firstName = Input::get('firstName'); $newClient->surName = Input::get('surName'); $newClient->nickName = Input::get('nickName'); $newClient->state = Input::get('state'); $newClient->birthDate = Input::get('birthDate'); $newClient->mobNum = Input::get('mobNum'); $newClient->photo = Input::get('photo'); $newClient->save(); /* | | Putting activity into log | */ $activityToLog = new ActivityLog(); $activityToLog->activity = "New client created! Card №" . $newClient->id . ". Name: " . $newClient->lastName . " " . $newClient->firstName . " " . $newClient->surName; $activityToLog->user = \Auth::user()->name; $activityToLog->save(); \Session::flash('messageClientCreated', 'Клиент создан!'); return redirect('send/single'); } }
public function anyAdd() { $data = Request::all(); if (count($data) > 0) { $UserDetails = new Client(); $UserDetails->fullname = $data['fullname']; $UserDetails->email = $data['email']; $UserDetails->order_number = $data['order_number']; $UserDetails->product_id = $data['product_id']; $UserDetails->note = $data['note']; if ($UserDetails->save()) { $email = $data['email']; $subject = 'Demo mail'; // subject you want for you email Session::flash('flash_message', 'successfully saved.'); return redirect('/warranty'); } } }
public function postSignUp(Request $request, PublicForms $publicForms, User $user, CommonCode $cCode, Client $client, Role_user $roleUser, Role $role) { $validation_rules = $publicForms->getValidationRulesSignUp(); $this->validate($request, $validation_rules); $arr_request = $publicForms->getRequestArraySignup($request); // $arr_request = $admin->getRequestArray($request); $user->email = $arr_request['email']; $user->password = $arr_request['password']; $user->name = ''; $user->save(); $client->cloaked_client_id = $client->getNewCloakedClientId($user->id); $client->user_id = $user->id; $client->first_name = $arr_request['first_name']; $client->last_name = $arr_request['last_name']; $client->company = $arr_request['company']; $client->client_url = $arr_request['client_url']; $client->save(); $bool_role_assigned = $roleUser->add_role_by_name($user->id, 'client', $role); $data = $publicForms->getDataArrayPostSignUp($arr_request, $user->id, $client->cloaked_client_id, $bool_role_assigned); return view('public/sign_up_results')->with('data', $data); }
public function post_add_user(Request $request, Admin $admin, User $user, Client $client, CommonCode $cCode) { $validation_rules = $admin->getValidationRules(); $this->validate($request, $validation_rules); $arr_request = $admin->getRequestArray($request); $user->email = $arr_request['email']; $user->password = $arr_request['password']; $user->name = ''; $user->save(); $client->cloaked_client_id = $client->getNewCloakedClientId($user->id); $client->user_id = $user->id; $client->first_name = $arr_request['first_name']; $client->last_name = $arr_request['last_name']; $client->company = $arr_request['company']; $client->save(); // $user_id = $user->id; // return to raw password for view $arr_request['password'] = $request->password; $data = $admin->getDataArray($arr_request, $user->id, $client->cloaked_client_id, $this->arr_logged_in_user); return view('admin/add_user_results_admin')->with('data', $data); }
/** * Enregister à la base de donnée le nouveau client enregistré. * * @return \Illuminate\Http\Response */ public function store() { try { $input = Input::all(); $client = new Client(); $client->prenom = $input['prenom']; $client->nom = $input['nom']; $client->adresse = $input['adresse']; $client->ville = $input['ville']; $client->noTel = $input['noTel']; $client->courriel = $input['courriel']; $client->relation = $input['relation']; $client->actif = 1; } catch (ModelNotFoundException $e) { App::abort(404); } if ($client->save()) { return Redirect::action('ClientsController@index'); } else { return Redirect::back()->withInput()->withErrors($client->validationMessages()); } }
public function getNinjaClient($account) { $account->load('users'); $ninjaAccount = $this->getNinjaAccount(); $ninjaUser = $ninjaAccount->getPrimaryUser(); $client = Client::whereAccountId($ninjaAccount->id)->wherePublicId($account->id)->first(); $clientExists = $client ? true : false; if (!$client) { $client = new Client(); $client->public_id = $account->id; $client->account_id = $ninjaAccount->id; $client->user_id = $ninjaUser->id; $client->currency_id = 1; } foreach (['name', 'address1', 'address2', 'city', 'state', 'postal_code', 'country_id', 'work_phone', 'language_id', 'vat_number'] as $field) { $client->{$field} = $account->{$field}; } $client->save(); if ($clientExists) { $contact = $client->getPrimaryContact(); } else { $contact = new Contact(); $contact->user_id = $ninjaUser->id; $contact->account_id = $ninjaAccount->id; $contact->public_id = $account->id; $contact->is_primary = true; } $user = $account->getPrimaryUser(); foreach (['first_name', 'last_name', 'email', 'phone'] as $field) { $contact->{$field} = $user->{$field}; } $client->contacts()->save($contact); return $client; }
public function jqgrid(Request $request) { // return dd($request->all()); if (Auth::check()) { if (in_array('ADD_EDIT_CLIENT', $this->permission)) { $validate = \Validator::make($request->all(), ['name' => 'required']); if ($validate->passes()) { switch ($request->input('oper')) { case 'add': $audit = new AuditsController(); $active = 'Inactive'; if ($request->input('active') == 'true') { $active = 'Active'; } $client = new Client(); $client->name = $request->input('name'); $client->status = $active; $client->user_id = Auth::user()->id; $client->save(); $audit->store('client', $client->id, null, 'add'); return $msg = ['success' => true, 'msg' => "your Client:cl{$client->id} Added successfully"]; break; case 'edit': $client_id = $request->input('id'); if (User::isSuperAdmin()) { $client = Client::find($client_id); } else { $usr_company = $this->user_company(); $client = Client::whereIn('user_id', $usr_company)->find($client_id); } if ($client) { $data = array(); $audit = new AuditsController(); if ($client->name != $request->input('name')) { array_push($data, 'Name'); array_push($data, $client->name); array_push($data, $request->input('name')); $client->name = $request->input('name'); } $audit->store('client', $client_id, $data, 'edit'); $client->save(); return $msg = ['success' => true, 'msg' => "your Client:cl{$client_id} Saved saved successfully"]; } return $msg = ['success' => false, 'msg' => "please Select your Client"]; break; } return $msg = ['success' => false, 'msg' => "Are U kidding me?"]; } return $msg = ['success' => false, 'msg' => "please fill all fields"]; } return $msg = ['success' => false, 'msg' => "you don\\'t have permission"]; } return Redirect::to(url('user/login')); }
public function upload() { if ($this->validate()) { $isValidFormat = true; $isValidEncoding = true; if (($handle = fopen($this->csvFile->tempName, "r")) !== FALSE) { if (($firstLine = fgetcsv($handle)) !== FALSE) { if (count($firstLine) >= 2) { if (mb_detect_encoding($firstLine[0]) !== 'ASCII') { $isValidEncoding = false; $firstLine = $this->convert_to_ASCII($firstLine); } } else { $isValidFormat = false; } if ($isValidFormat) { if ($firstLine[0] !== 'client_id' || $firstLine[1] !== 'full_name' || $firstLine[2] !== 'client_type_id' || $firstLine[3] !== 'discipline_id' || $firstLine[4] !== 'active') { $isValidFormat = false; } } } if ($isValidFormat) { $success = true; $row = 1; while (($data = fgetcsv($handle)) !== FALSE) { if (!$isValidEncoding) { $data = $this->convert_to_ASCII($data); } $row++; $model = new Client(); $model->client_id = $data[0]; $model->full_name = $data[1]; $model->client_type_id = $data[2]; $model->discipline_id = $data[3]; $model->active = $data[4]; if (!$model->save()) { $idClient = Client::find()->where(['client_id' => $model->client_id])->exists(); $typeClient = ClientType::find()->where(['id' => $model->client_type_id])->exists(); $idDiscipline = Discipline::find()->where(['id' => $model->discipline_id])->exists(); $activo = Client::find()->where(['active' => $model->active])->exists(); if ($idClient == true) { Yii::$app->session->addFlash("error-upload", "Error en línea: [" . $row . "] ----- El cliente con id: [" . $model->client_id . "] ya se encuentra registrado."); } else { if ($typeClient == false || $idDiscipline == false || $activo == false) { if ($typeClient == false) { $typeClient = "[client_type_id] No Válido. "; } else { $typeClient = ""; } if ($idDiscipline == false) { $idDiscipline = "[discipline_id] No Válido. "; } else { $idDiscipline = ""; } if ($activo == false) { $activo = "[active] No Válido."; } else { $activo = ""; } Yii::$app->session->addFlash("error-upload", "Error en línea: [" . $row . "] ----- " . $typeClient . "" . $idDiscipline . "" . $activo . ""); } } } } if (!feof($handle)) { $success = false; Yii::$app->session->setFlash('error', Yii::t('app', 'Unexpected error.')); } } else { Yii::$app->session->setFlash('error', Yii::t('app', 'El formato del archivo No es válido. El formato válido es: ') . "<div class=\"panel panel-default\">\n\t\t\t\t\t\t\t<div class=\"panel-body\">\n\t\t\t\t\t\t\t\t<p>client_id,full_name,client_type_id,discipline_id,active</p>\n\t\t\t\t\t\t\t\t<p>98341245,Pedro Salazar Dos,1,5,1</p>\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>"); } fclose($handle); } return $isValidFormat && $success; } else { return false; } }
public function postSubmit($url_cat) { $check = $this->checkUrlCategory($url_cat); if (!$check) { return Redirect::route('admin.client', array('url_category' => 'entertainer')); } if (Input::get('_action') == 'addProcess') { $validator = Validator::make(array('name' => Input::get('name'), 'logo' => Input::file('image')), array('name' => 'required|unique:client,name', 'logo' => 'image')); if ($validator->fails()) { return Redirect::route('admin.client.add', array('url_category' => $url_cat))->withErrors($validator)->withInput(); } $client = new Client(); $client->name = Input::get('name'); $client->category = Input::get('category'); if (!file_exists($this->upload_path)) { mkdir($this->upload_path, 0775, true); } if (!is_null(Input::file('image'))) { $file = Input::file('image'); if ($file->isValid()) { $extension = $file->getClientOriginalExtension(); $img = Image::make($file->getRealPath()); $img->resize(null, 75, function ($constraint) { $constraint->aspectRatio(); }); $img->interlace(); $name = $client->name . '_' . uniqid(); $fileName = $this->upload_path . Str::slug($name) . '.' . $extension; $img->save($fileName); $client->logo = $fileName; } } $client->save(); if (!$client->id) { throw new \Exception('Client insert error'); } $this->clearCache(); } elseif (Input::get('_action') == 'editProcess') { if (Input::has('id')) { $validator = Validator::make(array('name' => Input::get('name'), 'logo' => Input::file('image')), array('name' => 'required|unique:client,name,' . Input::get('id'), 'logo' => 'image')); if ($validator->fails()) { return Redirect::route('admin.client.edit', array('url_category' => $url_cat, 'id' => Input::get('id')))->withErrors($validator)->withInput(); } $client = Client::find(Input::get('id')); $client->name = Input::get('name'); if (!file_exists($this->upload_path)) { mkdir($this->upload_path, 0775, true); } if (!is_null(Input::file('image'))) { $file = Input::file('image'); if ($file->isValid()) { if (!empty($client->logo)) { File::delete($client->logo); } $extension = $file->getClientOriginalExtension(); $img = Image::make($file->getRealPath()); $img->resize(null, 75, function ($constraint) { $constraint->aspectRatio(); }); $img->interlace(); $name = $client->name . '_' . uniqid(); $fileName = $this->upload_path . Str::slug($name) . '.' . $extension; $img->save($fileName); $client->logo = $fileName; } } $client->save(); $this->clearCache(); } } return Redirect::route('admin.client', array('url_category' => $url_cat)); }
public function actionCreateFromAssignation() { $model = new Client(); $model->active = true; $this->layout = '/main2'; //$newClient = $model->id; //var_dump($newClient); die(); if ($model->load(Yii::$app->request->post()) && $model->save()) { //var_dump($model->id); die(); return $this->redirect(['assignation/create3', 'id' => $model->id]); } else { return $this->render('create2', ['model' => $model]); } }