/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Clients(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Clients'])) { $model->attributes = $_POST['Clients']; if ($model->save()) { $cid = $model->id; foreach ($_FILES['afiles']['tmp_name'] as $key => $tmp_name) { $afilesdesc = $_POST['afilesdesc'][$key]; $file_name = $_FILES['afiles']['name'][$key]; $file_tmp = $_FILES['afiles']['tmp_name'][$key]; if (!empty($file_name)) { $nx = explode(".", $file_name); $pname = $nx[0] . rand(1000, 999999999) . "." . pathinfo($file_name, PATHINFO_EXTENSION); $file = Yii::app()->basePath . '/../uploads/images/' . $pname; move_uploaded_file($file_tmp, $file); $ca = new ClientAssessments(); $ca->client_id = $cid; $ca->url = $pname; $ca->description = $afilesdesc; $ca->save(); } } $this->redirect(array('index')); } } $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 Clients(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Clients'])) { $model->attributes = $_POST['Clients']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->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 Clients(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Clients'])) { $model->attributes = $_POST['Clients']; if ($model->save()) { $msg = 'Клиент #' . $model->id . ' - ' . $model->name . ' создан'; Yii::app()->user->setFlash('success', $msg); Yii::app()->logger->write($msg); $this->redirect(array('view', 'id' => $model->id)); } else { Yii::app()->user->setFlash('error', 'Клиент НЕ создан'); } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $model = new Clients(); $account = new Accounts(); $preference = new Preferences(); if (isset($_POST['Clients'], $_POST['Accounts'], $_POST['Preferences'])) { $model->attributes = $_POST['Clients']; $account->attributes = $_POST['Accounts']; $preference->attributes = $_POST['Preferences']; $model->login_name = $account->login_name; $model->client_code = RandomGenerator::generateString(AdminGlobals::CLIENT_CODE_LENGTH); $model->subscription_status = "active"; $preference->prepaid_passwd = RandomGenerator::generateString(AdminGlobals::PREPAID_PASSWD_LENGTH); $account->account_name = $model->client_name; $account->email = $model->email; $account->is_visible = 0; $valid = $model->validate(); $valid = $account->validate() && $valid; $valid = $preference->validate() && $valid; if ($valid) { $transaction = Yii::app()->db->beginTransaction(); $success = $model->save(false); if ($success) { $account->client_id = $preference->client_id = $model->id; } $success = $success && $account->save(false); $success = $success && $preference->save(false); if ($success) { $transaction->commit(); if (Yii::app()->request->isAjaxRequest) { $this->renderPartial('view', array('model' => $this->loadModel($model->id), 'account' => $account, 'preference' => $preference), false, true); Yii::app()->end(); } $this->redirect(array('view', 'id' => $model->id)); } $transaction->rollBack(); } } if (Yii::app()->request->isAjaxRequest) { $this->renderPartial('create', array('model' => $model, 'account' => $account, 'preference' => $preference), false, true); Yii::app()->end(); } $this->render('create', array('model' => $model, 'account' => $account, 'preference' => $preference)); }
/** * Create Empty company without users * @param $fedId * @param $newCompanyName * @param $impVendorInfo * @return Clients */ public static function createEmptyCompany($fedId, $newCompanyName, $impVendorInfo = null) { $client = new Clients; // begin transaction $transaction = Yii::app()->db->beginTransaction(); try { $company = new Companies; $project = new Projects; $companyAdreses = new CompanyAddresses; //$usersClientList = new UsersClientList; $company->Company_Name = $newCompanyName; $company->Company_Fed_ID = $fedId; if (preg_match('/^(\d{2}\-\d{7})|(\d{3}\-\d{2}\-\d{4})$/', $company->Company_Fed_ID)) { //usual w9 do nothing } if (preg_match('/^(IN[-]\d{7})$/', $company->Company_Fed_ID)) { //international w9 $company->Temp_Fed_ID_Flag = 'N'; } if (preg_match('/^(T0[-]\d{7})$/', $company->Company_Fed_ID)) { //international w9 $company->Temp_Fed_ID_Flag = 'T'; } $company->Auth_Code = Helper::generatePassword(); $company->save(); $company_adress = new Addresses; if ($impVendorInfo) { $company_adress = new Addresses; $company_adress->Address1 = $impVendorInfo['address']; $company_adress->City = $impVendorInfo['city']; $company_adress->State = $impVendorInfo['state']; $company_adress->ZIP = $impVendorInfo['zip']; if ($company_adress->validate()) { $company_adress->save(); } else { $company_adress = new Addresses; $company_adress->save(); } } $company_adress->save(); $companyAdreses->Company_ID = $company->Company_ID; $companyAdreses->Address_ID = $company_adress->Address_ID ? $company_adress->Address_ID : 0; $companyAdreses->save(); $client->Company_ID = $company->Company_ID; $client->Client_Type = 1; $client->Client_Number = 1; $client->save(); //create client project $project->Client_ID = $client->Client_ID; $project->Project_Name = "Corporate"; $project->Project_Description = "Description of the Project"; $project->PO_Starting_Number = Projects::DEFAULT_PO_STARTING_NUMBER; $project->Ck_Req_Starting_Numb = Projects::DEFAULT_CKRQ_STARTING_NUMBER; $project->save(); $transaction->commit(); } catch(Exception $e) { $transaction->rollback(); } return $client; }
/** * Creates a new model. * @return create view */ public function actionCreate() { // check if user has permissions to createClients if (Yii::app()->user->checkAccess('createClients')) { // create Users object model $modelUsers = new Users(); // create Address object model $address = new Address(); // if Users and Address form exist and was sent if (isset($_POST['Users']) && isset($_POST['Address'])) { // set form elements to Users model attributes $modelUsers->attributes = $_POST['Users']; // set form elements to Address model attributes $address->attributes = $_POST['Address']; $modelUsers->user_admin = 0; $modelUsers->account_id = Yii::app()->user->Accountid; // validate both models $valid = $address->validate(); $valid = $modelUsers->validate() && $valid; if ($valid) { // save address $address->save(false); $modelUsers->address_id = $address->primaryKey; // temporary variable with user password $passBeforeMD5 = $modelUsers->user_password; // hashed user password $modelUsers->user_password = md5($modelUsers->user_password); // save user if ($modelUsers->save(false)) { // create clients object $model = new Clients(); $model->user_id = $modelUsers->user_id; // validate and save if ($model->save()) { // save log $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'ClientCreated', 'log_resourceid' => $model->primaryKey, 'log_type' => Logs::LOG_CREATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id); Logs::model()->saveLog($attributes); // prepare to send email template to new user $str = $this->renderPartial('//templates/users/invitation', array('userCreateInvitation' => Yii::app()->user->CompleteName, 'user_email' => $modelUsers->user_email, 'user_password' => $passBeforeMD5, 'userInvited' => $modelUsers->CompleteName, 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true); $subject = Yii::t('email', 'UserInvitation'); Yii::import('application.extensions.phpMailer.yiiPhpMailer'); $mailer = new yiiPhpMailer(); $mailer->pushMail($subject, $str, array('email' => $modelUsers->user_email, 'name' => $modelUsers->CompleteName), Emails::PRIORITY_NORMAL); // to prevent F5 keypress, redirect to view detail page $this->redirect(array('view', 'id' => $model->client_id)); } } } } $this->render('create', array('model' => $modelUsers, 'address' => $address)); } else { throw new CHttpException(403, Yii::t('site', '403_Error')); } }