Пример #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Noticia();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Noticia'])) {
         $model->attributes = $_POST['Noticia'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->NO_ID));
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Noticia();
     $foto = new UploadPhoto();
     date_default_timezone_set("America/Monterrey");
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Noticia'])) {
         $usuarioActual = Usuario::model()->obtenerUsuarioActual();
         if (isset($_GET["tipo"]) && $_GET["tipo"] == "not") {
             $model->attributes = $_POST["Noticia"];
             $model->fecha_f = date("Y-d-m H:i:s");
             $model->tipo = 0;
             $model->usuario_did = $usuarioActual->id;
             $model->estatus_did = 2;
             $foto->attributes = $_POST['UploadPhoto'];
             $foto->foto = CUploadedFile::getInstance($foto, 'foto');
             $documento = str_replace(" ", "_", $foto->foto);
             $documento = date("Ymd_Gi") . "__" . $documento;
             $fileDocumento = dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . 'administracion/images' . DIRECTORY_SEPARATOR . 'noticias' . DIRECTORY_SEPARATOR . $documento;
             $foto->foto->saveAs($fileDocumento);
             $model->ruta = $documento;
         } else {
             if (isset($_GET["tipo"]) && $_GET["tipo"] == "pub") {
                 $model->attributes = $_POST["Noticia"];
                 $model->fecha_f = date("Y-d-m H:i:s");
                 $model->tipo = 1;
                 $model->usuario_did = $usuarioActual->id;
                 $model->mensaje = CHtml::encode($model->mensaje);
                 $model->estatus_did = 2;
                 $foto->attributes = $_POST['UploadPhoto'];
                 $foto->foto = CUploadedFile::getInstance($foto, 'foto');
                 $documento = str_replace(" ", "_", $foto->foto);
                 $documento = date("Ymd_Gi") . "__" . $documento;
                 $fileDocumento = dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . 'administracion/images' . DIRECTORY_SEPARATOR . 'noticias' . DIRECTORY_SEPARATOR . $documento;
                 $foto->foto->saveAs($fileDocumento);
                 $model->ruta = $documento;
             }
         }
         if ($model->save()) {
             Yii::app()->user->setFlash("info", "Se ha enviado la publicación, una vez haya sido revisada se publicará.");
             $this->redirect(array('publicacion'));
         }
     }
     $this->render('create', array('model' => $model, 'foto' => $foto));
 }
Пример #3
0
 function form_agregar()
 {
     $this->form_validation->set_rules('titulo', 'Título', 'trim|required');
     //$this->form_validation->set_rules('resumen', 'Resumen', 'trim|required');
     $this->form_validation->set_rules('contenido', 'Contenido', 'trim|required');
     if ($this->form_validation->run() == TRUE) {
         $noticia = new Noticia();
         $noticia->titulo = $this->input->post('titulo');
         $noticia->alias = url_title(convert_accented_characters($this->input->post('titulo')), 'underscore', TRUE);
         //$noticia->resumen = $this->input->post('resumen');
         $noticia->contenido = $this->input->post('contenido');
         $noticia->publicado = $this->input->post('publicado') ? 1 : 0;
         $noticia->foto_descripcion = $this->input->post('foto_descripcion');
         $config['upload_path'] = 'assets/uploads/noticias/';
         $config['allowed_types'] = 'gif|jpg|png';
         $config['max_size'] = '1000';
         $config['max_width'] = '1024';
         $config['max_height'] = '768';
         $config['overwrite'] = TRUE;
         $config['file_name'] = date('YmdHis') . '.' . substr($_FILES['imagen']['name'], -3);
         $this->load->library('upload', $config);
         $msg = 'La noticia <strong>' . $noticia->titulo . '</strong> se creó correctamente';
         $url = 'backend/noticias/index';
         if ($_FILES['imagen']['size'] > 0 && !$this->upload->do_upload('imagen')) {
             $msg = 'Error: ' . $this->upload->display_errors();
             $url = 'backend/noticias/agregar';
         } else {
             if ($_FILES['imagen']['size'] > 0 && $noticia->foto) {
                 unlink('./uploads/noticias/' . $noticia->foto);
                 $noticia->foto = $config['file_name'];
             }
             if ($_FILES['imagen']['size'] > 0) {
                 $noticia->foto = $config['file_name'];
             }
             $noticia->save();
         }
         $this->session->set_flashdata('message', $msg);
         redirect($url);
     }
     $data['title'] = 'Backend - Agregar Noticias';
     $data['content'] = 'backend/noticias/agregar';
     $this->load->view('backend/template', $data);
 }
Пример #4
0
 /**
 	Recibe una id noticia y una id foto y las relaciona
 	**/
 public function asignarFoto($idnoticia, $idfoto)
 {
     $noticia = new Noticia($idnoticia);
     $foto = new Foto($idfoto);
     $noticia->save($foto);
     redirect('admin/noticias/edicion/' . $noticia->id);
 }
Пример #5
0
    $reglas = array('txtTitulo' => 'required|min:5|max:100', 'fImagen' => 'required', "txtContenido" => "required|min:10");
    //mensajes
    $mensajes = array('required' => 'El campo <b>:attribute</b> es obligatorio.', 'min' => 'El campo <b>:attribute</b> no puede tener menos de :min carácteres.', 'max' => 'El campo <b>:attribute</b> no puede tener más de :min carácteres.');
    $validacion = Validator::make(Input::all(), $reglas, $mensajes);
    $validacion->setAttributeNames($friendly_names);
    if ($validacion->fails()) {
        return Redirect::to('admin/noticias/add')->withErrors($validacion)->withInput();
    } else {
        $noticia = new Noticia();
        $noticia->tituloNoticia = $datos['txtTitulo'];
        $noticia->fechaNoticia = date("Y-m-d H:i:s");
        $noticia->textoNoticia = $datos["txtContenido"];
        $aux = User::where("email", "=", Session::get("email"))->firstOrFail();
        $noticia->fkidUsuario = $aux->id;
        //$n->imagenUrl = "/img/hola.png";
        if ($noticia->save()) {
            $noticia->imagenUrl = 'imgsnoticias/' . $noticia->id . "." . $imagen->getClientOriginalExtension();
            //guardamos la imagen en public/imgs con el nombre original
            $imagen->move("imgsnoticias", $noticia->id . "." . $imagen->getClientOriginalExtension());
            $noticia->save();
            //redirigimos con un mensaje flash
            return Redirect::to('admin')->with(array('confirm' => 'Noticia publicada correctamente.'));
        } else {
            return Redirect::to('admin/noticias/add')->with(array('error' => 'Error. No se pudo publicar la noticia.'));
        }
    }
}));
Route::get("login", function () {
    if (Auth::check()) {
        return Redirect::to("admin");
    } else {