public function testNewPhoneSavesOrdNumIFItIsSetExternaly()
 {
     $phone = new Telephone();
     $phone->tel_cli = 9999;
     $phone->tel_number = 1234567890;
     $phone->tel_ord = 1000;
     $phone->save();
     $this->assertEquals(1000, $phone->tel_ord, 'New phone doesnt save its order num');
 }
 public function actionUpdate()
 {
     if (!Yii::app()->request->isPostRequest) {
         throw new CHttpException(400, 'must be a post request');
     }
     if (isset($_POST['tel_id']) && $_POST['tel_id']) {
         $model = Telephone::model()->findByPk($_POST['tel_id']);
     } else {
         $model = new Telephone();
     }
     $model->attributes = $_POST;
     if ($model->save()) {
         echo json_encode($model->attributes);
     } else {
         echo json_encode(['errors' => $model->getErrors()]);
     }
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTelephones()
 {
     return $this->hasMany(Telephone::className(), ['contact_id' => 'id']);
 }
 public function register()
 {
     if ($this->validate()) {
         $address = new Address();
         $lines = explode("\n", $this->address);
         $postcode = '';
         if (count($lines) > 1) {
             $postcode = array_pop($lines);
         }
         for ($i = 0; $i < count($lines) && $i < 5; $i++) {
             $t = 'line' . ($i + 1);
             $address->{$t} = $lines[$i];
         }
         $address->postcode = strtoupper($postcode);
         $address->save();
         $client = new Client();
         $client->cli_fname = $this->name;
         $client->cli_sname = $this->surname;
         $client->cli_email = $this->email;
         $client->cli_branch = $this->branch;
         $client->cli_neg = 0;
         $client->cli_status = 'Active';
         $client->cli_salemin = $this->minPrice;
         $client->cli_salemax = $this->maxPrice;
         $client->cli_salebed = $this->bedrooms;
         $client->cli_sales = 'Yes';
         $client->cli_saleemail = 'Yes';
         $client->cli_salestatus = $this->currentPosition;
         $client->addressID = $address->id;
         if ($client->save(false)) {
             $telephone = new Telephone();
             $telephone->tel_type = 'Other';
             $telephone->tel_number = $this->telephone;
             $telephone->tel_cli = $client->cli_id;
             $telephone->tel_ord = 1;
             $telephone->save();
         }
         return true;
     }
 }
 public function actionCallback($email = '', $telephone = '', $message = '')
 {
     $this->layout = '/layouts/popup-iframe';
     if (isset($_POST['Callback']) && $_POST['Callback']) {
         $callback = $_POST['Callback'];
         $email = $callback['email'];
         $telephone = $callback['telephone'];
         $criteria = new CDbCriteria();
         $criteria->compare('cli_email', $email);
         $criteria->with = ['telephones'];
         $client = Client::model()->find($criteria);
         if ($client) {
             if (!$telephone) {
                 $telephone = $client->telephones[0]->tel_number;
             } else {
                 if ($client->telephones[0]->tel_number != $telephone) {
                     $telExist = false;
                     $tels = $client->telephones;
                     foreach ($tels as $tel) {
                         if ($tel->tel_number == $telephone) {
                             $telExist = true;
                             break;
                         }
                     }
                     if (!$telExist) {
                         $telephone = new Telephone();
                         $telephone->tel_type = 'Other';
                         $telephone->tel_number = $telephone;
                         $telephone->tel_cli = $client->cli_id;
                         $telephone->save();
                     }
                 }
             }
         }
         $message = $this->sendEmailForRegisteredClient($email, $telephone);
         echo json_encode($message);
     } else {
         $this->render('_callbackForm', ['email' => $email, 'telephone' => $telephone, 'message' => $message]);
     }
 }
Example #6
0
if ($model->address) {
    ?>
		<div class="control-group"><label class="control-label">Secondary Address:</label></div>
		<?php 
    $this->renderPartial('application.modules.admin4.views.address.formInline', array('fieldName' => 'secondAddress', 'confirm' => false, 'noAddressMessage' => 'Correspondence address is not selected', 'model' => $model->secondAddress));
    ?>
	<?php 
}
?>
</div>

<script type="text/phone-template" id="phone-template">
	<input type="text" name="telephones[number][]" class="input-small">
	<input type="hidden" name="telephones[id][]" value="">
	<?php 
echo CHtml::dropDownList('telephones[type][]', key(Telephone::getTypes()), Telephone::getTypes(), ['class' => 'input-xsmall']);
?>
	<br>
</script>

<script type="text/javascript">
	(function ()
	{
		$("#addPhoneButton").on('click', function ()
		{
			var tpl = $('#phone-template').html();
			$('#phones .controls').append(tpl);
		});
	})();

</script>
 private function saveClient(Client $model)
 {
     $this->prepareModel($model);
     if (isset($_POST['Client']) && $_POST['Client']) {
         $_POST['Client']['propertyTypesIds'] = isset($_POST['Client']['propertyTypesIds']) ? $_POST['Client']['propertyTypesIds'] : [];
         $_POST['Client']['propertyCategoryIds'] = isset($_POST['Client']['propertyCategoryIds']) ? $_POST['Client']['propertyCategoryIds'] : [];
         $model->attributes = $_POST['Client'];
         if ($model->isNewRecord) {
             $model->scenario = 'validPhoneOnInsert';
         }
         $generalNoteIds = isset($_POST['noteId-' . Note::TYPE_CLIENT_GENERAL]) ? $_POST['noteId-' . Note::TYPE_CLIENT_GENERAL] : [];
         $generalNote = isset($_POST[Note::TYPE_CLIENT_GENERAL]) ? $_POST[Note::TYPE_CLIENT_GENERAL] : [];
         $reqNoteIds = isset($_POST['noteId-' . Note::TYPE_CLIENT_REQ]) ? $_POST['noteId-' . Note::TYPE_CLIENT_REQ] : [];
         $reqNote = isset($_POST[Note::TYPE_CLIENT_REQ]) ? $_POST[Note::TYPE_CLIENT_REQ] : [];
         $telephones = isset($_POST['telephones']) ? $_POST['telephones'] : [];
         $existingPhones = Telephone::model()->findAllByPk(array_filter($telephones['id']), ['index' => 'tel_id']);
         if (isset($telephones['number'][0]) && $telephones['number'][0]) {
             $phone = new Telephone();
             $phone->tel_number = $telephones['number'][0];
             $phone->tel_type = $telephones['type'][0];
             $model->_newPhones = [$phone];
         }
         $model->addressID = isset($_POST['primaryAddress']['id']) ? $_POST['primaryAddress']['id'] : 0;
         $model->secondAddressID = isset($_POST['secondAddress']['id']) ? $_POST['secondAddress']['id'] : 0;
         if ($model->save()) {
             /** @var $existingPhones Telephone */
             foreach ($telephones['number'] as $key => $number) {
                 $phoneId = $telephones['id'][$key];
                 $type = $telephones['type'][$key];
                 if (isset($existingPhones[$phoneId])) {
                     $phone = $existingPhones[$phoneId];
                 } else {
                     $phone = new Telephone();
                 }
                 if ($number) {
                     $phone->tel_cli = $model->cli_id;
                     $phone->tel_number = $number;
                     $phone->tel_type = $type;
                     $phone->save();
                 } else {
                     if (!$phone->isNewRecord) {
                         $phone->delete();
                     }
                 }
             }
             $model->saveAreas(isset($_POST['Client']['matchingPostcode']) ? $_POST['Client']['matchingPostcode'] : []);
             $model->saveFeatures(isset($_POST['Client']['feature']) ? $_POST['Client']['feature'] : []);
             if ($generalNoteIds) {
                 Note::model()->saveNoteTypeIds($generalNoteIds, $model->cli_id);
             }
             if ($reqNoteIds) {
                 Note::model()->saveNoteTypeIds($reqNoteIds, $model->cli_id);
             }
             if ($generalNote) {
                 $generalNote['not_type'] = Note::TYPE_CLIENT_GENERAL;
                 Note::model()->saveNote($generalNote, $model->cli_id);
             }
             if ($reqNote) {
                 $reqNote['not_type'] = Note::TYPE_CLIENT_REQ;
                 Note::model()->saveNote($reqNote, $model->cli_id);
             }
             if (isset($_POST['Client']['saveProceed']) && $_POST['Client']['saveProceed']) {
                 $this->redirect([$this->createUrl('appointmentBuilder/clientSelected', ['clientId' => $model->cli_id])]);
             } else {
                 Yii::app()->user->setFlash('client-update-success', 'Updated Successfully');
                 $this->redirect(array('Update', 'id' => $model->cli_id, 'useClient' => isset($_GET['useClient']) && $_GET['useClient'] ? 1 : 0));
             }
         }
     }
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Telephone the loaded model
  * @throws CHttpException
  */
 public function loadModel($id, $idTree)
 {
     if (!(Yii::app()->user->admin || Access::model()->checkAccessUserForTree($idTree)) || !Tree::model()->checkParentRight($idTree)) {
         throw new CHttpException(403, 'Доступ запрещен.');
     }
     $criteria = new CDbCriteria();
     $criteria->compare('id', $id);
     $criteria->addInCondition('ifns_code', CHtml::listData(Telephone::model()->listOrganizations($idTree), 'code', 'code'));
     $model = Telephone::model()->find($criteria);
     //$model=Telephone::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'Страница не найдена.');
     }
     return $model;
 }
 public function actionConfirm($app)
 {
     /** @var Appointment $model */
     $model = Appointment::model()->findByPk($app);
     if (!$model) {
         throw new CHttpException(404, 'Appointment [id: ' . $app . '] not found');
     }
     if ($_POST) {
         /** @var Telephone[] $phones */
         $phones = [];
         // mapping phones for fast access
         foreach (Telephone::model()->findAllByPk($_POST['phones']) as $value) {
             $phones[$value->tel_id] = $value;
         }
         /** @var Deal[] $instructions */
         $instructions = [];
         foreach ($model->instructions as $instruction) {
             $instructions[$instruction->dea_id] = $instruction;
             // mapping iinstructions
         }
         /** @var Client[] $clients */
         $clients = [];
         $clientKeys = array_merge(isset($_POST['vendors']) ? array_keys($_POST['vendors']) : [], isset($_POST['clients']) ? array_keys($_POST['clients']) : []);
         foreach (Client::model()->findAllByPk($clientKeys) as $key => $value) {
             $clients[$value->cli_id] = $value;
         }
         $sendMessage = function ($clientId, $data) use($phones, $instructions, $clients, $model) {
             if (!$data['send'] || !$data['send_to'] || !isset($phones[$data['send_to']])) {
                 return;
             }
             $sms = new Sms();
             $sms->toNumber = $phones[$data['send_to']]->tel_number;
             $sms->clientId = $clientId;
             $sms->text = $data['text'];
             $sms->send();
             $model->addTextMessage($sms);
         };
         $errors = [];
         if (isset($_POST['vendors'])) {
             foreach ($_POST['vendors'] as $vendorId => $data) {
                 try {
                     $sendMessage($vendorId, $data);
                 } catch (Exception $e) {
                     $errors[] = $e;
                 }
             }
         }
         if (isset($_POST['clients'])) {
             foreach ($_POST['clients'] as $vendorId => $data) {
                 try {
                     $sendMessage($vendorId, $data);
                 } catch (Exception $e) {
                     $errors[] = $e;
                 }
             }
         }
         $model->saveTextMessages();
         if (!$errors) {
             Yii::app()->user->setFlash('messages-sent', 'Text messages successfully sent.');
         }
     }
     $this->render('confirm', compact('model'));
 }
Example #10
0
        <strong>Информация</strong><br />
        Для изменения данных кроме файла справочника поле &laquo;Файл справочника&raquo;         
        следует оставить пустыми.
    </div>
    <?php 
}
?>
    
    <p class="help-block">Поля обозначенные <span class="required">*</span> обязательны для заполнения.</p>
    
    <?php 
echo $form->errorSummary($model);
?>
    
    <?php 
echo $form->dropDownListRow($model, 'ifns_code', CHtml::listData(Telephone::model()->listOrganizations($idTree), 'code', 'name'), array('class' => 'span8', 'maxlength' => 50));
?>
            
    <br />Файл справочника
    <?php 
echo $form->fileField($model, 'tel_file');
?>
    
    
    <?php 
echo $form->textAreaRow($model, 'dop_text', array('rows' => 6, 'cols' => 50, 'class' => 'span8'));
?>
    
    <?php 
echo $form->textFieldRow($model, 'sort', array('class' => 'span5'));
?>