Beispiel #1
0
 function dbsave()
 {
     $db = new ConexionBd();
     if (!empty($this->id)) {
         $update = "UPDATE `" . $this->tabla . "` SET ";
         $arrayCampos = array();
         foreach ($this->campos as $c => $nombre) {
             $arrayCampos[] = "`" . $c . "` = '" . $this->{$c} . "'";
         }
         $update .= implode(', ', $arrayCampos);
         $update .= " WHERE id = '" . $this->id . "'";
         $db->query($update);
         return $this->id;
     } else {
         $insert = "INSERT INTO `" . $this->tabla . "`\n\t\t\t\t\t\t\tVALUES(";
         $arrayCampos = array();
         foreach ($this->campos as $c => $nombre) {
             if ($c != 'id') {
                 $arrayCampos[] = "'" . $this->{$c} . "'";
             } else {
                 $arrayCampos[] = '0';
             }
         }
         $insert .= implode(', ', $arrayCampos);
         $insert .= ");";
         $db->query($insert);
         return $db->insertId();
     }
 }
Beispiel #2
0
 public static function getLinks($id = 0)
 {
     if (!isset($_SESSION)) {
         session_start();
     }
     $db = new ConexionBd();
     $sql = "SELECT *\n\t\t\t\t\tFROM links AS l\n\t\t\t\t\tLEFT JOIN user_link AS ul ON(l.id = ul.id_link)\n\t\t\t\t\tWHERE ul.id_user = " . $_SESSION['idusuario'];
     return $db->query($sql);
 }
<?php

require_once "head.php";
if (isset($_POST['accion'])) {
    //Crear nuevo link
    if (strtolower($_POST['accion']) == 'crear') {
        $enlace = filter_var($_POST['enlace'], FILTER_SANITIZE_URL);
        $descripcion = filter_var($_POST['descripcion'], FILTER_SANITIZE_STRING);
        if (!empty($enlace) && !empty($descripcion)) {
            $link = new Link();
            $link->crear($enlace, $descripcion);
            //debug($link);
            $id_new_link = $link->dbsave();
            if (!empty($id_new_link)) {
                $insert = "INSERT INTO user_link VALUES(0, " . $_SESSION['idusuario'] . ", " . $id_new_link . ")";
                $db = new ConexionBd();
                $db->execute($insert);
                header("Location: index.php");
            } else {
                echo "Error al crear el enlace";
            }
        }
    }
    //Guardar link despues de editar
    if (strtolower($_POST['accion']) == 'doedit') {
        $id_link = filter_var($_POST['id_link'], FILTER_SANITIZE_URL);
        $enlace = filter_var($_POST['enlace'], FILTER_SANITIZE_URL);
        $descripcion = filter_var($_POST['descripcion'], FILTER_SANITIZE_STRING);
        $link = new Link($_GET['id_link']);
        $link->setDescription($descripcion);
        $link->setUrl($enlace);
Beispiel #4
0
 public function getAccesos()
 {
     $sql = "SELECT * FROM clicks WHERE id_link = " . $this->id;
     $db = new ConexionBd();
     return $db->query($sql, FALSE);
 }