Example #1
0
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndex()
 {
     // renders the view file 'protected/views/site/index.php'
     // using the default layout 'protected/views/layouts/main.php'
     $flag = 0;
     $correo = false;
     if (isset($_POST['Correo'])) {
         $correos = OkoCorreos::model()->findAll();
         if (count($correos) > 0) {
             foreach ($correos as $data) {
                 if ($data->correo == $_POST['correoC']) {
                     $flag = 1;
                     $correo = $_POST['correoC'];
                 }
             }
         }
         if ($flag == 0) {
             $columnas = array('nombre' => $_POST['nombreC'], 'correo' => $_POST['correoC']);
             $insert = Yii::app()->db->createCommand()->insert('oko_correos', $columnas);
             $flag = 2;
         }
     }
     if (isset($_POST['Contacto'])) {
         //                $baseUrl = Yii::app()->baseUrl;
         $to = Yii::app()->params['adminEmail'];
         $headers = 'From: ' . $_POST['correo'];
         mail($to, 'Contacto', $_POST['mensaje'], $headers);
         //                Yii::app()->controller->widget
         //                (
         //                    'ext.easy-mail.Mail',array
         //                    (
         //                        'view' => $baseUrl.'/index.php',
         //                        'params' => array
         //                        (
         //                            'to' => array
         //                            (
         //                                '*****@*****.**' => $_POST['nombre']
         //                            ),
         //                            'content' => array
         //                            (
         //                                'message' => $_POST['mensaje'],
         //                                'from' => $_POST['correo']
         //                            ),
         //                            'subject' => 'Contacto'
         //                        )
         //                    )
         //                );
     }
     $this->render('index', array('flag' => $flag, 'correo' => $correo));
 }
Example #2
0
 public function extraPhpAfterSaveValidate($model = '', $post = '', $paths = '', $module = '')
 {
     if ($paths != null && $paths != '') {
         for ($i = 0; $i < count($paths); $i++) {
             if (!isset($post['x'], $post['y'], $post['w'], $post['h'])) {
                 throw new CHttpException(400, "No fue posible recortar la imagen, los parametros de recorte son invalidos");
             }
             //revisa que la imagen funte exista en el servidor
             if (!file_exists($paths[$i])) {
                 throw new CHttpException(500, "La imagen no ha sido cargada correctamente");
             }
             //si no trae el ancho y el largo intenta mover $imagen a la ruta de $nuevaImagen
             //tal cual sin recortar devido a que los parametros de recorte no son suficientes
             if (empty($post['w']) || empty($post['h'])) {
                 return move_uploaded_file($paths[$i], $paths[$i]);
             }
             //width y height que tendra la imagen generada
             $width = $post["divwidth"];
             $height = $post["divheight"];
             //crea una copia de la imagen en memoria
             $_SESSION["tipo"] = '';
             $_SESSION["creado"] = '';
             $ext = pathinfo($paths[$i], PATHINFO_EXTENSION);
             $type = strtolower($ext);
             if ($type === 'jpeg') {
                 $type = 'jpg';
             }
             switch ($type) {
                 case 'bmp':
                     $img_r = imagecreatefromwbmp($paths[$i]);
                     break;
                 case 'gif':
                     $img_r = imagecreatefromgif($paths[$i]);
                     break;
                 case 'jpg':
                     $img_r = imagecreatefromjpeg($paths[$i]);
                     break;
                 case 'png':
                     $img_r = imagecreatefrompng($paths[$i]);
                     break;
                 default:
                     return "Unsupported picture type!, Please use one of the following: bmp, gif, jpg, jpeg or png";
             }
             $_SESSION["tipo"] = $type;
             //crea una nueva imagen en memoria del tamaƱo definido por width y height
             $dst_r = imagecreatetruecolor((int) $width, (int) $height);
             //calidad de la imagen final
             $calidad = 100;
             // intentamos preservar la transparencia
             if ($type == "gif" || $type == "png") {
                 $r = imagecolortransparent($dst_r, imagecolorallocatealpha($img_r, 0, 0, 0, 127));
                 $_SESSION["creado"] = $r;
                 imagealphablending($dst_r, false);
                 imagesavealpha($dst_r, true);
             }
             //crea una imagen en memoria en base a la imagen fuente con los datos de recorte
             $retorno = imagecopyresampled($dst_r, $img_r, 0, 0, (int) $post['x'], (int) $post['y'], (int) $width, (int) $height, (int) $post['w'], (int) $post['h']);
             //si no logro crear la co[ia de la imagen en memoria
             if ($retorno === false) {
                 return false;
             }
             $n = strpos($paths[$i], "imagen");
             //variable de imagen
             $new_path = substr($paths[$i], 0, $n);
             //si la imagen es cambiada con un update, toma la imagen anterior y la intenta borrar
             /* Nuevo PATH */
             //                $new_path = $module->getAttributePath(__CLASS__,'logo').DIRECTORY_SEPARATOR.'cutted_image'.DIRECTORY_SEPARATOR;
             $new_path = $module->getAttributePath(__CLASS__, 'imagen') . DIRECTORY_SEPARATOR;
             if ($nombre_anterior2 != null) {
                 $baseUrl = Yii::app()->baseUrl;
                 $targetFile = $baseUrl . "uploads/okomuebles/imagen/{$nombre_anterior2}";
                 unlink(realpath($targetFile));
             }
             $new_path = $new_path . $model->imagen;
             $nuevaImagen = $model->imagen;
             //intenta guardar la imagen resultante en el servidor
             switch ($type) {
                 case 'bmp':
                     $retorno = imagewbmp($dst_r, $new_path);
                     break;
                 case 'gif':
                     $retorno = imagegif($dst_r, $new_path);
                     break;
                 case 'jpg':
                     $retorno = imagejpeg($dst_r, $new_path, $calidad);
                     break;
                 case 'png':
                     $retorno = imagepng($dst_r, $new_path);
                     break;
             }
             if ($retorno === false) {
                 return false;
             }
         }
     } else {
         $columnas = array('imagen' => $model->nombre_anterior);
         $nuevaImagen = $model->nombre_anterior;
         $update = Yii::app()->db->createCommand()->update('oko_muebles', $columnas, "id = " . (int) $model->id);
     }
     $correso = OkoCorreos::model()->findAll();
     foreach ($correso as $data) {
         $to = $data->correo;
         $headers = 'From: ' . Yii::app()->params['adminEmail'];
         $mensaje = "Estimado {$data->nombre}, le informamos que hay un \n            nuevo mueble disponible en nuestro catalogo, lo invitamos a revisarlo\n            <img width='150px' height='150px' src='{$baseUrl}uploads/okomuebles/imagen/{$nuevaImagen}'>";
         mail($to, 'Contacto', $mensaje, $headers);
     }
 }