public function actionCheck()
 {
     session_write_close();
     Yii::$app->get('hiart')->disableAuth();
     $fqdn = Yii::$app->request->post('domain');
     list($domain, $zone) = explode('.', $fqdn, 2);
     $line = ['fqdn' => $fqdn, 'domain' => $domain, 'zone' => $zone, 'resource' => null];
     if ($fqdn) {
         $check = Domain::perform('Check', ['domains' => [$fqdn]], true);
         //            $check = [$domain => mt_rand(0,1)]; // todo: remove this line
         if ($check[$fqdn] === 0) {
             $line['isAvailable'] = false;
         } else {
             $tariff = $this->getDomainTariff();
             $zones = $this->getDomainZones($tariff, DomainResource::TYPE_DOMAIN_REGISTRATION);
             foreach ($zones as $resource) {
                 if ($resource->zone === $zone) {
                     $line['resource'] = $resource;
                     break;
                 }
             }
             $line['isAvailable'] = true;
         }
         return $this->renderAjax('_checkDomainLine', ['line' => $line]);
     } else {
         Yii::$app->end();
     }
 }
 /**
  * @return mixed
  */
 public function actionIndex()
 {
     $model = new Domain();
     $model->scenario = 'transfer';
     $transferDataProvider = null;
     if (Yii::$app->request->isPost) {
         $post = Yii::$app->request->post($model->formName(), []);
         if (!empty($post[0]['domains'])) {
             $domains = [];
             foreach (StringHelper::explode($post[0]['domains'], "\n") as $line) {
                 preg_match('/^([a-z0-9][0-9a-z.-]+)(?:[,;\\s]+)(.*)/i', $line, $matches);
                 if ($matches) {
                     $domain = strtolower($matches[1]);
                     $password = $matches[2];
                     $domains[] = compact('domain', 'password');
                 }
             }
             $post = $domains;
         }
         $collection = (new Collection(['model' => $model]))->load($post);
         $models = $collection->getModels();
         foreach ($models as $model) {
             try {
                 Domain::perform('CheckTransfer', $model->getAttributes(['domain', 'password']));
             } catch (ErrorResponseException $e) {
                 $model->addError('password', $e->getMessage());
             }
         }
         Yii::$app->session->setFlash('transferGrid', 1);
         $transferDataProvider = new ArrayDataProvider(['models' => $models]);
     }
     return $this->render('index', ['model' => $model, 'transferDataProvider' => $transferDataProvider]);
 }
 public function actionGetContactsByAjax($id)
 {
     if (Yii::$app->request->isAjax) {
         $domainContactInfo = Domain::perform('GetContactsInfo', ['id' => $id]);
         return $this->renderAjax('_contactsTables', ['domainContactInfo' => $domainContactInfo]);
     } else {
         Yii::$app->end();
     }
 }
 public function actionChangeContact($contactId = null, $contactType = null, $domainId = null, $domainName = null)
 {
     if (!Yii::$app->request->isPost) {
         $model = $this->findModel($contactId);
         $model->scenario = 'change-contact';
         return $this->render('changeContact', ['countries' => $this->getRefs('country_code', 'hipanel'), 'askPincode' => Client::perform('HasPincode'), 'model' => $model, 'domainId' => $domainId, 'domainName' => $domainName, 'contactType' => $contactType]);
     } else {
         $model = new Contact(['scenario' => 'create']);
         if ($model->load(Yii::$app->request->post())) {
             $domainContactInfo = Domain::perform('GetContactsInfo', ['id' => $model->domainId]);
             $setContactOptions = ['domain' => $model->domainName, 'id' => $model->domainId];
             if ($model->save()) {
                 foreach (Domain::$contactOptions as $contact) {
                     $setContactOptions[$contact] = $contact === $model->contactType ? $model->id : $domainContactInfo[$contact]['id'];
                 }
                 Domain::perform('SetContacts', $setContactOptions);
                 $this->redirect(['@domain/view', 'id' => $model->domainId]);
             }
         }
     }
 }
 /**
  * Sends API request to check whether domain is available and sets result to [[isAvailable]]
  *
  * @return bool whether domain is available
  */
 public function checkIsAvailable()
 {
     try {
         $check = Domain::perform('Check', ['domains' => [$this->fqdn]], true);
         $this->isAvailable = $check[$this->fqdn] === 1;
     } catch (ErrorResponseException $e) {
         $this->isAvailable = false;
     }
     return $this->isAvailable;
 }