/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { $client = new Client(); $vehicle = new VehicleClient(); $technicaldate = new TechnicalDate(); $concessioners = Concessioner::model()->findAll(); $criteria = new CDbCriteria(); //$criteria->condition = 'id != 32 AND id != 33 AND id != 34 AND id != 36 AND id != 37 AND id != 38 AND id != 39 AND id != 40 AND id != 41 AND id != 42'; //$criteria->order=name; $criteria = new CDbCriteria(); //$criteria->condition = 'id != 36'; $criteria->order = "name"; $versions = VehicleVersion::model()->with('vehicle')->findAllbyAttributes(array(), $criteria); //$versions= VehicleVersion::model()->findAllbyAttributes(array('status'=>'ACTIVE'),$criteria); if (isset($_POST['ajax']) && $_POST['ajax'] === 'client-form') { echo CActiveForm::validate($client); Yii::app()->end(); } if (isset($_POST['siguiente'])) { // die("hola"); if (isset($_POST['Client']) && isset($_POST['TechnicalDate']) && isset($_POST['VehicleClient'])) { //die("hola"); $client = new Client(); $client->attributes = $_POST['Client']; $client->save(); $vehicle = new VehicleClient(); $vehicle->attributes = $_POST['VehicleClient']; $vehicle->save(); $technicaldate = new TechnicalDate(); $technicaldate->attributes = $_POST['TechnicalDate']; $technicaldate->client_id = $client->primaryKey; $technicaldate->vehicle_id = $vehicle->primaryKey; if ($technicaldate->save()) { $message = new YiiMailMessage(); $message->view = 'agendamiento'; $message->setSubject('Prospecto agendamiento de Cita'); $message->setBody(array("client" => $client, "vehicle" => $vehicle, "technicaldate" => $technicaldate), 'text/html'); $message->setFrom(array(Yii::app()->params['adminEmail'] => 'El Equipo Nissan Ecuador')); foreach ($technicaldate->concessioner->emails as $email) { if ($email->type == "TECHNICAL_DATE") { $message->addTo($email->description); } } //$message->addTo("*****@*****.**"); Yii::app()->mail->send($message); $this->render('result', array("client" => $client, "vehicle" => $vehicle, "technicaldate" => $technicaldate)); } else { $this->render('error'); } } //$this->render('index',array('concessioners'=>$concessioners,"client"=>$client,"vehicle"=>$vehicle,"technicaldate"=>$technicaldate)); } else { $this->render('index', array('concessioners' => $concessioners, "client" => $client, "vehicle" => $vehicle, "technicaldate" => $technicaldate, "versions" => $versions)); } }