Example #1
0
 /**
  * Devulve la condicion de consulta normal para un registro.
  * IMPORTANTE: consulta un registro aunque se haya eliminado logicamente (campos de control)
  * Ultima revision: 2012-03-15
  * Reviso: Martin Tlapa
  * @return type 
  */
 function get_condicion()
 {
     if ($this->_condicion) {
         return $this->_condicion;
     } else {
         if (!$this->get_tabla()) {
             die("DB_info.get_condicion dice:<br />No se ha seteado el nombre de la tabla.");
         }
         $identifier = DB_Structure::get_identifier($this->get_tabla());
         //strtolower( substr( $this->_campos_consultados[$this->get_tabla()][0], 0, 3 ) );
         if ($this->get_custom_id()) {
             return $this->get_custom_id() . " = '" . $this->get_id() . "'";
         }
         //                return $this->get_custom_id() . " = '" . $this->get_id() . "'" . (($this->get_ignorar_campos_control())?(""):" AND " . $identifier . "_eliminado IS NULL");
         return DB_Structure::get_id($this->get_tabla()) . " = '" . $this->get_id() . "'";
         //            return DB_Structure::get_id($this->get_tabla()) . " = '" . $this->get_id() . "'" . (($this->get_ignorar_campos_control())?(""):" AND " . $identifier . "_eliminado IS NULL");
     }
 }
Example #2
0
 /**
  * Permite establecer los datos que se van a guardar en un INSERT
  * Ultima revision: 2012-03-13
  * Reviso: Martin Tlapa
  * @param type $nombre_campos
  * @param type $datos
  * @return type 
  */
 public function prepara_datos_insert($nombre_campos, $datos)
 {
     foreach ($nombre_campos as $nombre_campo) {
         if ($datos[$nombre_campo] || $datos[$nombre_campo] == 0) {
             $campos[] = $nombre_campo;
             //                if( $datos[$nombre_campo]==null && $datos[$nombre_campo]!=0 )
             if (!$datos[$nombre_campo]) {
                 $request[] = "NULL";
             } elseif ($datos[$nombre_campo] === 0) {
                 echo $nombre_campo . "<br />";
                 $request[] = "0";
             } elseif (stristr($datos[$nombre_campo], "NOW()") || stristr($datos[$nombre_campo], "NULL") && strtoupper($datos[$nombre_campo]) == "NULL" || stristr($datos[$nombre_campo], "MD5(RAND())") || stristr($datos[$nombre_campo], "DATE_ADD(")) {
                 $request[] = $datos[$nombre_campo];
             } else {
                 $request[] = "\"" . stripslashes(addslashes($this->get_capital_letters() ? strtoupper($this->get_utf8_string($datos[$nombre_campo])) : $this->get_utf8_string($datos[$nombre_campo]))) . "\"";
             }
             //                    $request[] = "'" . mysql_escape_string( ($this->get_capital_letters())?strtoupper($this->get_utf8_string($datos[$nombre_campo])):$this->get_utf8_string($datos[$nombre_campo]) ) . "'";
         }
     }
     if (!$this->get_ignorar_campos_control()) {
         $identifier = DB_Structure::get_identifier($this->get_tabla());
         $campos[] = $identifier . "_creado";
         $request[] = "'" . $_SESSION[$this->__auth_nombre_id_usuario] . "'";
         $campos[] = $identifier . "_fecha_creado";
         $request[] = "NOW()";
     }
     return array($campos, $request);
 }
Example #3
0
 /**
  * Permite actualizar el registro de una tabla
  * Ultima revision: 2012-03-28
  * Reviso: Martin Tlapa
  * @param type $id
  * @return boolean 
  */
 function actualiza()
 {
     if (!$this->get_tabla()) {
         die('DB_Crud.actualiza() dice:<br />Falta definir el nombre de la tabla');
     }
     $sql = "";
     if ($this->valida_datos(true)) {
         $this->set_cmd("updated");
         $campos = $this->get_total_campos();
         if ($this->get_custom_id()) {
             $id = $this->get_custom_id();
         } else {
             $id = DB_Structure::get_id($this->get_tabla());
         }
         $this->set_opciones($this);
         list($updates, $identifier) = DB::get_cnx()->prepara_datos_update($campos, $this->campos_consultados["datos"]);
         if (!$identifier && $this->get_permitir_update_sin_datos() && !$this->get_ignorar_campos_control()) {
             $identifier = DB_Structure::get_identifier($this->get_tabla());
             foreach ($updates as $update) {
                 $arreglo[] = $identifier . $update;
             }
             $updates = $arreglo;
         }
         if (!$this->get_id()) {
             die("TE FALTA SETEAR EL VALOR DEL ID");
         }
         $sql = "UPDATE " . $this->get_tabla() . " SET " . implode(", ", $updates) . " WHERE {$id} = '" . $this->get_id() . "'" . ($this->get_ignorar_campos_control() ? "" : " AND " . $identifier . "_eliminado IS NULL;");
         $this->execute($sql);
         return true;
     }
     $error = "";
     if ($this->get_error() && DB::$_file_log_name && DB::$_path_log || $this->get_error() && $this->get_debug_mode()) {
         $error = "ERROR - DB_CRUD.actualiza() dice: " . $this->get_error() . "\n" . $this->get_more_info();
         if ($sql) {
             $error .= "<p>" . $sql . "</p>";
         }
         if ($this->get_debug_mode()) {
             die($error);
         } else {
             $this->save_log($error);
         }
     }
     return false;
 }