Viewing file: IndexController.php (20.06 KB) -rwxrwxrwx Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php namespace Modules\Frontend\Controllers;
require_once(dirname(dirname(dirname(__DIR__)))."/library/PHPMailer/PHPMailerAutoload.php"); use Modules\Models\CdCitas; use Modules\Models\Vinmueble; use Modules\Models\CdCharacteristics; use Modules\Models\CdPrice; use Modules\Models\CdDimensions; use Modules\Models\CdServices; use Modules\Models\CdAmenities; use Modules\Models\CdEquipment; use Modules\Models\CdGallery; use Modules\Models\CdEstados; use Modules\Models\CdMunicipios; use Modules\Models\CdSchedule; use Modules\Models\CdForm; use Modules\Models\Vhorario; use Phalcon\Http\Request; use Phalcon\Mvc\Model\Query;
class IndexController extends ControllerBase { public $whatsapp = "front/media-demo/banner/M5.jpg"; public function indexAction(){ $this->response->redirect('login'); $this->header("index"); $title = "Bienes Raices"; $url = ""; $image = "front/media-demo/banner/M5.jpg"; $description = "Una gran variedad de casas, departamentos, oficinas, terrenos, bodegas, fraccionamientos y más. ¡Encuentra tu próximo inmueble!"; $this->metaHome($title,$url,$image,$this->whatsapp,$description);
$destacadas = Vinmueble::find("(featured='SI' and main_image is not null) and status='ACTIVO' order by type asc")->toArray();
foreach ($destacadas as $key => $val) { $gallery = CdGallery::find("imid=".$val['imid']." Order By position ASC limit 10")->toArray(); $destacadas[$key] += [ "gallery" => $gallery]; }
$news = Vinmueble::find("(featured!='SI' and type is not null and main_image is not null) and status='ACTIVO' order by imid desc limit 6")->toArray();
foreach ($news as $key => $val) { $gallery = CdGallery::find("imid=".$val['imid']." Order By position ASC limit 10")->toArray(); $news[$key] += [ "gallery" => $gallery]; }
$house = Vinmueble::find("(featured!='SI' and type='CASA' and main_image is not null) and status='ACTIVO' order by imid asc limit 3")->toArray();
foreach ($house as $key => $val) { $gallery = CdGallery::find("imid=".$val['imid']." Order By position ASC limit 10")->toArray(); $house[$key] += [ "gallery" => $gallery]; } $this->view->setVar("news",$news); $this->view->setVar("destacadas",$destacadas); $this->view->setVar("houses",$house); } public function asesorAction(){ header("Location: http://asesor.mercotab.mx"); exit(); } public function fichaAction(){ $title = "Mercotab | Bienes Raices en Tabasco"; $url = "ficha"; $image = "front/media-demo/banner/M5.jpg"; $description = "Una gran variedad de casas, departamentos, oficinas, terrenos, bodegas, fraccionamientos y más. ¡Encuentra tu próximo inmueble!"; $this->metaHome($title,$url,$image,$this->whatsapp,$description); } public function desarrollosAction(){ $title = "Mercotab | Bienes Raices en Tabasco"; $url = "desarrollos"; $image = "front/media-demo/banner/M5.jpg"; $description = "Una gran variedad de casas, departamentos, oficinas, terrenos, bodegas, fraccionamientos y más. ¡Encuentra tu próximo inmueble!"; $this->metaHome($title,$url,$image,$this->whatsapp,$description); } public function contactAction(){ $title = "Mercotab | Bienes Raices en Tabasco"; $url = "contacto"; $image = "front/media-demo/banner/M5.jpg"; $description = "Una gran variedad de casas, departamentos, oficinas, terrenos, bodegas, fraccionamientos y más. ¡Encuentra tu próximo inmueble!"; $this->metaHome($title,$url,$image,$this->whatsapp,$description); } public function inmuebleAction(){ $permalink = $this->dispatcher->getParam("permalink"); $consulta = Vinmueble::findFirst("permalink='$permalink'"); if($consulta->getStatus() == "INACTIVO"){ $this->response->redirect("404/".$consulta->getPermalink()); } $id = $consulta->getImid(); $gallery = CdGallery::find("imid=".$consulta->getImid()." Order By position ASC"); $gallerymosaic = CdGallery::find("imid=".$consulta->getImid()." Order By position ASC limit 15"); //$viewgallery = CdGallery::find("imid=".$consulta->getImid()." Order By position ASC limit 1"); $title = ucwords(strtolower("MercoTab | ".$consulta->getType()." en ".$consulta->getOperation()." | ".$consulta->getNameFraccionamiento())); $url = "inmueble/".$permalink; $image = "dash/assets/inmuebles/chico/".$consulta->getMainImage(); $whatsapp = "dash/assets/inmuebles/chico/".$consulta->getMainImage(); $description = $consulta->getDescription(); $this->metaHome($title,$url,$image,$whatsapp,$description); $similar = Vinmueble::find("permalink!='$permalink' and status='ACTIVO' and type='{$consulta->getType()}' limit 4")->toArray();
foreach ($similar as $key => $val) { $other_gallery = CdGallery::find("imid=".$val['imid']." Order By position ASC limit 10")->toArray(); $similar[$key] += [ "gallery" => $other_gallery]; }
$caracteristicas = CdCharacteristics::findFirst("imid=".$id); $price=CdPrice::findFirst("imid=".$id); $dimensiones=CdDimensions::findFirst("imid=".$id); $servicios=CdServices::findFirst("imid=".$id); $amenidades=CdAmenities::findFirst("imid=".$id); $equipamiento= CdEquipment::findFirst("imid=".$id); $this->view->setVar("equipamiento",$equipamiento); $this->view->setVar("amenidades",$amenidades); $this->view->setVar("servicios",$servicios); $this->view->setVar("dimensiones",$dimensiones); $this->view->setVar("price",$price); $this->view->setVar("caracteristicas",$caracteristicas); $this->view->setVar("inmueble",$consulta); $this->view->setVar("gallery",$gallery->toArray()); $this->view->setVar("gallerymosaic",$gallerymosaic); //$this->view->setVar("viewgallery",$viewgallery); $this->view->setVar("similar",$similar); $this->view->setVar("estados",CdEstados::find()); } public function getAscDescInmueble($value,$order){ $rent = $value['rent']; $new_rent = array_column($rent, 'rent'); $result_rent = array_multisort($new_rent, SORT_ASC, $rent);
$vent = $value['vent']; $new_vent = array_column($vent, 'rent'); $result_vent = array_multisort($new_vent, SORT_ASC, $vent);
foreach($rent as $k => $v){ $rent[$k]["cost"] = $v['rent']; } foreach($vent as $k => $v){ $vent[$k]["cost"] = $v['vent']; $rent[] = $vent[$k]; } $total = array_column($rent, 'total'); $sort = $order=="ass"?SORT_ASC:SORT_DESC; $result_rent = array_multisort($total, $SORT_ASC, $rent); return $rent; } public function busquedaAction(){ $request = new Request(); $title = "Mercotab | Bienes Raices en Tabasco"; $url = "busqueda"; $image = "front/media-demo/banner/M5.jpg"; $description = "Una gran variedad de casas, departamentos, oficinas, terrenos, bodegas, fraccionamientos y más. ¡Encuentra tu próximo inmueble!"; $this->metaHome($title,$url,$image,$this->whatsapp,$description); if(!$this->isSearch()){ $inmuebles_rent = Vinmueble::find("(main_image is not null and operation='RENTA') and status='ACTIVO' order by rent asc"); $inmuebles_vent = Vinmueble::find("(main_image is not null and operation='VENTA') and status='ACTIVO' order by vent asc"); $values = 0; $inmuebles = $this->getAscDescInmueble(array("rent"=>$inmuebles_rent->toArray(),"vent"=>$inmuebles_vent->toArray()),"asc"); }elseif($request->get("folio")){ $inmueble = Vinmueble::findFirst("imid=".$request->get("folio")); if($inmueble){ if($inmueble->getStatus() == "INACTIVO"){ $this->response->redirect("404/".$inmueble->getPermalink()); }else{ $this->response->redirect("inmueble/".$inmueble->getPermalink()); } }else{ echo "<script type='text/javascript'> alert('No existe este folio'); window.location.replace('/'); </script>"; exit(); } }else if($request->get("operacion")=="general"){ $inmuebles = "type='{$request->get("inmueble")}'"; $ubicacion = $request->get("ubicacion")=="general"?'':" and mpid={$request->get("ubicacion")}"; $query = $inmuebles.$ubicacion;
$inmuebles_rent = Vinmueble::find("($query and main_image is not null and operation='RENTA') and status='ACTIVO' order by rent asc"); $inmuebles_vent = Vinmueble::find("($query and main_image is not null and operation='VENTA') and status='ACTIVO' order by vent asc"); $values = 0; $inmuebles = $this->getAscDescInmueble(array("rent"=>$inmuebles_rent->toArray(),"vent"=>$inmuebles_vent->toArray()),"asc"); } else{ $inmuebles = "type='{$request->get("inmueble")}'"; $operacion = $request->get("operacion")=="general"?'':" and operation='{$request->get("operacion")}'"; $ubicacion = $request->get("ubicacion")=="general"?'':" and mpid={$request->get("ubicacion")}"; $query = $inmuebles.$operacion.$ubicacion;
$ordeR = $request->get("operacion")=="RENTA"?" order by rent asc ":" order by vent asc ";
$inmuebles = Vinmueble::find("($query and main_image is not null) and status='ACTIVO' $ordeR"); $inmuebles = $inmuebles->toArray(); $values = $request->get(); } foreach ($inmuebles as $key => $val) { $gallery = CdGallery::find("imid=".$val['imid']." Order By position ASC limit 10")->toArray(); $inmuebles[$key] += [ "gallery" => $gallery]; } $inmuebles_sort = array_column($inmuebles,"precio"); array_multisort($inmuebles_sort, SORT_ASC, $inmuebles); $this->view->setVar("inmuebles",$inmuebles); $this->view->setVar("values",$values); }
public function shareAction(){ $request = new Request(); if(!($request->isAjax() && $request->isPost())) $this->response(array("code"=>"404","Not Found"),404);
$permalink = $request->getPost("permalink"); $cd_inmueble = Vinmueble::findFirst("permalink='$permalink'");
$this->response(array("code"=>200,"data"=>$cd_inmueble),200); } public function listapropiedadesAction(){ $title = "Mercotab | Bienes Raices en Tabasco"; $url = "lista-propiedades"; $image = "front/media-demo/banner/M5.jpg"; $description = "Una gran variedad de casas, departamentos, oficinas, terrenos, bodegas, fraccionamientos y más. ¡Encuentra tu próximo inmueble!"; $this->metaHome($title,$url,$image,$this->whatsapp,$description); if(!$this->isSearch()){ $consulta= Vinmueble::find("status='ACTIVO'"); }else{ $consulta= $this->filtro(); } $this->view->setVar("consulta",$consulta); $this->view->setVar("estados",CdEstados::find()); } public function planoAction(){}
/* ========================================Actions de guardados y otras acciones de consulta a la base de datos================================================ */
public function extrasoperationsAction(){ $request = new Request(); if(!($request->isPost() and $request->isAjax()))$this->response(array("message"=>"error"),404); if($request->getPost("nombreEstado")){ $nombre = $request->getPost("nombreEstado"); $estado = CdEstados::findFirst("nombre='$nombre'")->getEid(); $municipio = CdMunicipios::find("eid=".$estado); $html=array(); $html[]="<option value=''>Ciudad</option>"; foreach ($municipio as $key) { $html[]="<option value=".$key->getNombre().">".$key->getNombre()."</option>"; } $this->response(array("message"=>"correcto","html"=>$html),200); }elseif($request->getPost("dateCita")){ $html = $this->fechasReservadas($request->getPost("dateCita")); $this->response(array("message"=>"todo bien","html"=>$html),200); }elseif($request->getPost("email")){ $email = $request->getPost("email"); $consulta = CdForm::findFirst("email='$email'"); if(!$consulta){ $this->response(array("valid"=>true),200); }else{ $this->response(array("valid"=>false),200); } } $this->response(array("message"=>"No ha llegado ni un dato"),200); }
public function emailAction(){
}
public function saveformAction(){ $request = new Request(); if(!($request->isAjax() and $request->isPost()))$this->response(array("message"=>"error"),404); $nombreCompleto=explode(" ",$request->getPost('name')); $nombre =""; $apellidos =""; $numeroNombre=count($nombreCompleto); if($numeroNombre>2){ for($i=0;$i<$numeroNombre-2;$i++){ $nombre.=$nombreCompleto[$i]." "; } $apellidos = $nombreCompleto[$numeroNombre-2]." ".$nombreCompleto[$numeroNombre-1]; }elseif($numeroNombre==1){ $nombre =$request->getPost('name'); $apellidos=""; }else{ $nombre = $nombreCompleto[0]; $apellidos = $nombreCompleto[1]; } $formulario = new CdForm(); $formulario->setName($nombre); $formulario->setLastName($apellidos); $formulario->setEmail($request->getPost('email')); $formulario->setDate($request->getPost('date')); $formulario->setDateCreation(date("Y:m:d H:i:s")); $formulario->setSchid($request->getPost("horario")); if($formulario->save()){ if($this->sendmail($request->getPost())){ $this->response(array("message"=>"correcto","code"=>"200"),200); }else{ $this->response(array("message"=>"Datos guardados pero no se envio el correo","code"=>"302"),200); } }else{ $this->response(array("message"=>"error","code"=>"505"),200); } }
/* =================================FUNCIONES PARA LAS DIFERENTES PROBLEMATICAS QUE SE PRESENTAN========================================================================== */ private function preciosBajos($preciosBajos){ $query = "SELECT IF(operation='VENTA',vent,rent) as precio, main_image,operation,estado,municipio,postal_code,ground_area,ground_superface,bathrooms,garage,name_fraccionamiento,folio FROM vinmueble"; $arrayBajos = $preciosBajos->getReadConnection()->query($query)->fetchAll(); $filtro = array(); for($i=0;$i<count($arrayBajos);$i++){ if($arrayBajos[$i]['precio']<40000){ $filtro[]=$arrayBajos[$i]; } } return $filtro; }
private function propiedadesNuevas($propiedades){ $query = "SELECT IF(operation='VENTA',vent,rent) as precio, main_image,operation,estado,municipio,postal_code,ground_area,ground_superface,bathrooms,garage,name_fraccionamiento,folio FROM vinmueble ORDER BY folio DESC"; $arrayNuevos = $propiedades->getReadConnection()->query($query)->fetchAll(); $filtro = array(); for($i=0;$i<count($arrayNuevos);$i++){ $filtro[]=$arrayNuevos[$i]; if($i==7){ break; } } return $filtro; }
private function isSearch(){ if(isset($_GET['inmueble']) or isset($_GET['operacion']) or isset($_GET['ubicacion'])){ return true; }else{ return false; } }
private function filtro(){ $type=$_GET['type']; $city=$_GET['city']; $property =$_GET["property-type"]; if(empty($_GET['type'])){ if(empty($_GET['city']) AND empty($_GET['property-type'])){ return Vinmueble::find(); }elseif(empty($_GET['city'])){ return Vinmueble::find("type='$property'"); }elseif(empty($_GET['property-type'])){ return Vinmueble::find("municipio='$city'"); }else{ return Vinmueble::find("municipio='$city' and type='$property'"); } }else{ if(empty($_GET['city']) AND empty($_GET['property-type'])){ return Vinmueble::find("operation='$type'"); }elseif(empty($_GET['city'])){ return Vinmueble::find("operation='$type' and type='$property'"); }elseif(empty($_GET['property-type'])){ return Vinmueble::find("operation='$type' and municipio='$city'"); }else{ return Vinmueble::find("operation='$type' and municipio='$city' and type='$property'"); } } } public function sendcontactAction(){ $request = new Request(); if(!($request->isPost() and $request->isAjax()))$this->response(array("message"=>"error"),404); if($request->getPost('type') && $request->getPost('type') == "contact"){ if($this->sendmailContact($request->getPost())){ $this->response(array("message"=>"¡Mensaje enviado correctamente!","code"=>200),200); }else{ $this->response(array("message"=>"correo no enviado","code"=>404),200); } }else{ if($this->sendmail($request->getPost())){ $this->response(array("message"=>"¡Mensaje enviado correctamente!","code"=>200),200); }else{ $this->response(array("message"=>"correo no enviado","code"=>404),200); } } } private function fechasReservadas($fecha){ $horariosReservados=array(); $horarios = Vhorario::find("date='$fecha'"); foreach ($horarios as $key) { $horariosReservados[]=$key->getSchid(); }
$consulta = CdSchedule::find(); $html = array(); $isRepeat = false; foreach ($consulta as $cnv) { for($i=0;$i<count($horariosReservados);$i++){ if($cnv->getSchid()==$horariosReservados[$i]){ $isRepeat=true; } } if(!$isRepeat){ $html[]="<option id='opcion_".$cnv->getSchid()."' value=".$cnv->getSchid().">".$cnv->getSchedule()."</option>"; } $isRepeat=false; } return $html; }
private function sendmail($values){ $email = $this->initializePHPMailer();
$email->setFrom("info@mercotab.com",'Mercotab'); $email->addReplyTo($values['email'],$values['name']); $email->addAddress("info@mercotab.com"); $email->addAddress("alex@atura.mx"); $email->WordWrap =100; $email->isHTML(true); $url = $values['url']?"<p><a href='{$values['url']}'>Ver inmueble</a></p>":"";
$email->Subject = "Contacto página web de Mercotab"; $email->msgHTML("<p style='text-align: center;'><strong>Hola este es un mensaje de la página web Mercotab</strong></p><strong>Nombre: </strong>{$values['name']}</p><p><strong>Email: </strong>{$values['email']}</p><p><strong>Telefono: </strong>{$values['phone']}</p><p><strong>Mensaje: </strong>{$values['message']}</p> $url"); if(!$email->send()) { // echo 'Message could not be sent.'; // echo 'Mailer Error: ' . $email->ErrorInfo; return false; } else { return true; } }
private function sendmailContact($values){ $email = $this->initializePHPMailer();
$email->setFrom("info@mercotab.com",'Mercotab'); $email->addReplyTo($values['email'],$values['name']); $email->addAddress($values['email']); $email->WordWrap =100; $email->isHTML(true);
$email->Subject = "Contacto página web de Mercotab"; $html = $this->curl_get_contents($this->url->get('email')); $email->msgHTML($html); if(!$email->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $email->ErrorInfo; return false; } else { return true; } } private function initializePHPMailer(){ $mail = new \PHPMailer(); $mail->isSMTP(); $mail->CharSet = 'UTF-8'; $mail->Host = "mx68.hostgator.mx"; $mail->Port=465; $mail->SMTPSecure="ssl"; $mail->SMTPAuth =true; $mail->Username = "hola@mercotab.mx"; $mail->Password = 'd8c9%ViGhF'; $mail->isHTML(true);
return $mail; } }
|