/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Customer(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; if ($model->save()) { // Comprobamos si existe la lista de envio de todos los clientes if (count(Mailist::model()->findByAttributes(array('Name' => 'Todos los clientes', 'UserID' => Yii::app()->user->ID)))) { // Si existe la lista añadimos el nuevo cliente $ListID = Mailist::model()->findByAttributes(array('Name' => 'Todos los clientes'))->ID; $modelCustomerList = new CustomerList(); $modelCustomerList->UserID = Yii::app()->user->ID; $modelCustomerList->ListID = $ListID; $modelCustomerList->CustomerID = $model->ID; $modelCustomerList->save(); } else { // Si no existe la lista la creamos y añadimos el cliente nuevo $modelMailist = new Mailist(); $modelMailist->Name = "Todos los clientes"; $modelMailist->UserID = Yii::app()->user->ID; if ($modelMailist->save()) { $modelCustomerList = new CustomerList(); $modelCustomerList->UserID = Yii::app()->user->ID; $modelCustomerList->ListID = $modelMailist->ID; $modelCustomerList->CustomerID = $model->ID; $modelCustomerList->save(); } } $this->redirect(array('admin')); } } $this->render('create', array('model' => $model)); }
public function actionDeleteCustomer() { $model = CustomerList::model()->findByAttributes(array("CustomerID" => $_POST["newEmail"], "ListID" => $_POST["listID"])); $modelList = Mailist::model()->findByPK($model->ListID); if ($model->delete()) { echo "<p class='jqueryOk'>Cliente borrado de la lista.</p>"; $this->renderPartial('_emailist', array('model' => $modelList)); } else { echo "<p class='jqueryError'>Error borrando el cliente. Intentalo de nuevo por favor.</p>"; $this->renderPartial('_emailist', array('model' => $modelList)); } }
<div class="row"> <?php echo $form->hiddenField($model, 'UserID'); ?> <?php echo CHtml::hiddenField('Enviar', '0'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'ListID'); ?> <?php echo $form->dropDownList($model, 'ListID', CHtml::listData(Mailist::model()->findAll($criteria), 'ID', 'Name'), array('empty' => '-- Selecciona una lista de envio --', 'style' => 'width: 50%;')); ?> <?php echo $form->error($model, 'ListID'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'Name'); ?> <?php echo $form->textField($model, 'Name', array('style' => 'width: 98%;', 'maxlength' => 100, 'placeholder' => 'Este sera el asunto del mensaje')); ?> <?php echo $form->error($model, 'Name');