Buenas amigos tengo rato matandome tratando de ver que tiene este codigo (o interpretarlo), les cuento me pasaron una web para hacerle unos cambios y en mi intento de agregar cosas sale un error que no entiendo el porque del mismo, estos son mis archivos (pasare solo las lineas que veo que importan)
El error: Notice: Undefined offset: 0 in C:\xampp\htdocs\indicadores\admin\clases\usuarios. class.php on line 41
index.php
Código PHP:
Ver originalinclude_once("../../clases/usuarios.class.php");
$user = new usuarios();
$valido = $user->validar($_POST['username'], $_POST['pass']);
if($valido){
$_SESSION['admin_log'] = true;
$_SESSION['nom_usu'] = $valido['nom_usu'];
$_SESSION['id_usu'] = $valido['id_usu'];
echo 1;
}else{
echo 0;
}
usuarios.class.php
Código PHP:
Ver original<?php
class usuarios{
private $db;
private $modulo;
private $modulos;
public $table;
public $tId;
public function __construct(){
include('consultas.class.php');
$this->table = "usuarios";
$this->tId = "id_usu";
$this->db = new Consultas($this->table, $this->tId);
$this->db->fields = array ( array ('private', 'id_usu', "''"), array ('public', 'nom_usu'), array ('public', 'log_usu'), array ('public', 'pas_usu'), array ('public', 'mail_usu'), array ('public', 'id_franq'), array ('private', 'fec_usu', 'now()') );
$this->modulos = new Consultas('per_mod_usu', 'id_per');
$this->modulos->fields = array ( array ('private', 'id_per', "''"), array ('public', 'id_mod'), array ('public', 'id_usu'), array ('public', 'visible'), array ('system', '(SELECT nom_mod FROM modulos WHERE id_mod=per_mod_usu.id_mod) AS nom_mod') );
$this->modulo = new Consultas('modulos', 'id_mod');
$this->modulo->fields = array ( array ('private', 'id_mod', "''"), array ('public', 'nom_mod'), array ('public', 'url_mod'), array ('public', 'img_mod') );
}
public function validar($log, $pass){
$where = "`log_usu` = '$log'";
$user = $this->db->getRecords($where);
if($user[0]['pas_usu'] == md5($pass)){ return $user[0];
}else{
return false;
}
}
public function listar($where = false){
return $this->db->getRecords($where);
}
public function agregar($nom, $log, $pas, $mail, $franq, $permisos){
$data[] = $nom;
$data[] = $log;
$data[] = $mail;
$data[] = $franq;
$this->db->insertRecord($data);
$id_usu = $this->db->return_id();
for ($i=0;$i<count($permisos);$i++){ $per[] = $permisos[$i];
$per[] = $id_usu;
$per[] = '1';
$this->modulos->insertRecord($per);
$per = "";
}
return $id_usu;
}
public function consultar($id){
$result = $this->db->getRecord($id);
$permisos = $this->modulos->getRecords("id_usu = $id AND visible=1");
$result[1] = $permisos;
return $result;
}
public function editar($id, $nom, $log, $pas, $mail, $franq, $permisos){
$data[] = $nom;
$data[] = $log;
if($pas){$pas = md5($pas);} $data[] = $pas;
$data[] = $mail;
$data[] = $franq;
$this->db->updateRecord($id,$data);
$data = "";
$mod = $this->modulo->getRecords();
foreach($mod as $clave=>$valor){
$temp = true;
$per = $this->modulos->getRecords("id_usu = $id AND id_mod = ".$valor['id_mod']);
foreach($per as $clv=>$vlr){
foreach($permisos as $c=>$v){
if($v == $valor['id_mod']){
$activar[] = $v;
$data[] = '';
$data[] = '';
$data[] = "1";
$this->modulos->updateRecord($vlr['id_per'],$data);
$data = "";
$temp = false;
}
}
if($temp){
$desactivar[] = $vlr['id_mod'];
$data[] = '';
$data[] = '';
$data[] = "0";
$this->modulos->updateRecord($vlr['id_per'],$data);
$data = "";
}
}
}
foreach($permisos as $clv=>$vlr){
$temp = true;
foreach($activar as $c=>$v){
if($v == $vlr){
$temp = false;
}
}
if($temp){
$nuevo[] = $vlr;
$data[] = $vlr;
$data[] = $id;
$data[] = "1";
$this->modulos->insertRecord($data);
$data = "";
}
}
}
public function borrar($id){
$this->db->deleteRecord($id);
$this->modulos->deleteRecords("id_usu=$id");
}
public function cambiar_pass($id, $pass){
$data[] = '';
$data[] = '';
$data[] = '';
$data[] = '';
$this->db->updateRecord($id,$data);
}
}
?>
La Linea: if($user[0]['pas_usu'] == md5($pass)){
Consultas.class.php
Código PHP:
Ver original<?php
include("mysql.php");
class Consultas {
private $link;
public $table;
public $fields;
public $campoId;
private $returnSQLResult =true;
public function __construct ($table, $campoId){
$this->table =$table;
$this->campoId =$campoId;
}
public function getRecords ($where_str=false, $order_str=false, $count=false, $start=0){
$where =$where_str ? "WHERE $where_str" : "";
$order =$order_str ? "ORDER BY $order_str" : "";
$limit = $count ? "LIMIT $start, $count" : "";
$campos =$this->getAllFields ();
$query ="SELECT $campos FROM {$this->table} $where $order $limit";
return $resultado;
}
public function getRecord ($id){
return $this->getRecords ("{$this->campoId}=$id", false, 1);
}
public function insertRecord ($data){
$campos =$this->getTableFields ();
$sysData =$this->getDefaultValues ();
if($sysData){
$sysData .= ",";
}
$query ="INSERT INTO {$this->table} ($campos) VALUES ($sysData '$data')";
return $this->validateOperation();
}
public function return_id(){
}
public function updateRecord ($id, $data){
$campos =$this->getEditableFields (true);
foreach ($campos as $ind => $campo){
$current_data =$data[$ind];
if($current_data != ""){
}
}
$query = "UPDATE {$this->table} SET $datos WHERE {$this->campoId}=$id";
return $this->validateOperation ();
}
public function deleteRecord ($id){
mysql_query ("DELETE FROM {$this->table} WHERE {$this->campoId}=$id"); return $this->validateOperation ();
}
public function deleteRecords ($where){
mysql_query ("DELETE FROM {$this->table} WHERE $where"); return $this->validateOperation ();
}
public function numPag ($where_str=false, $count=0){
$where =$where_str ? "WHERE $where_str" : "";
$query ="SELECT COUNT({$this->campoId}) FROM {$this->table} $where";
$resultado = ceil($row[0] / $count); return $resultado;
}
public function sql_direct($consulta){
return $resultado;
}
private function getFieldsByType ($type=''){
foreach ($this->fields as $field){
$includeField =false;
foreach ($types as $t){
if ($field[0] == $t){
}
}
}
return $return;
}
private function getNameFields ($type){
$fields =$this->getFieldsByType ($type);
foreach ($fields as $field){
}
return $return;
}
private function getEditableFields ($asArray=false){
$return =$this->getNameFields ('public');
return $asArray ?
$return : implode (', ', $return); }
private function getTableFields ($asArray=false){
$temp =$this->getNameFields ('private');
foreach($temp as $r)$return[] = $r;
$temp =$this->getNameFields ('public');
foreach($temp as $r)$return[] = $r;
return $asArray ?
$return : implode (', ', $return); }
private function getAllFields ($asArray=false){
$return =$this->getNameFields ('public|private|system');
return $asArray ?
$return : implode (', ', $return); }
private function getDefaultValues ($asArray=false){
$fields =$this->getFieldsByType ('private');
foreach ($fields as $field){
}
return $asArray ?
$return : implode (', ', $return); }
private function validateOperation (){
}
private function sql ($consulta){
if ($consQ){
}
return $resultado;
}
}?>
Que puede Estar pasando?