Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/08/2013, 17:55
Avatar de JuJoGuAl
JuJoGuAl
 
Fecha de Ingreso: julio-2009
Ubicación: Venezuela
Mensajes: 754
Antigüedad: 14 años, 9 meses
Puntos: 19
Notice: Undefined offset: 0 in ... Error con Class

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 original
  1. include_once("../../clases/usuarios.class.php");
  2.     $user = new usuarios();
  3.     $valido = $user->validar($_POST['username'], $_POST['pass']);
  4.     if($valido){
  5.         $_SESSION['admin_log'] = true;
  6.         $_SESSION['nom_usu'] = $valido['nom_usu'];     
  7.         $_SESSION['id_usu'] = $valido['id_usu'];   
  8.         echo 1;
  9.     }else{
  10.         echo 0;    
  11.     }

usuarios.class.php

Código PHP:
Ver original
  1. <?php
  2. class usuarios{
  3.     private $db;
  4.     private $modulo;
  5.     private $modulos;
  6.     public $table;
  7.     public $tId;   
  8.     public function __construct(){
  9.         include('consultas.class.php');
  10.         $this->table = "usuarios";
  11.         $this->tId = "id_usu";
  12.         $this->db = new Consultas($this->table, $this->tId);
  13.         $this->db->fields = array (
  14.             array ('private',   'id_usu', "''"),
  15.             array ('public',    'nom_usu'),
  16.             array ('public',    'log_usu'),
  17.             array ('public',    'pas_usu'),
  18.             array ('public',    'mail_usu'),
  19.             array ('public',    'id_franq'),
  20.             array ('private',   'fec_usu',  'now()')
  21.         );
  22.         $this->modulos = new Consultas('per_mod_usu', 'id_per');
  23.         $this->modulos->fields = array (
  24.             array ('private',   'id_per', "''"),
  25.             array ('public',    'id_mod'),
  26.             array ('public',    'id_usu'),
  27.             array ('public',    'visible'),
  28.             array ('system',   '(SELECT nom_mod FROM modulos WHERE id_mod=per_mod_usu.id_mod) AS nom_mod')
  29.         );
  30.         $this->modulo = new Consultas('modulos', 'id_mod');
  31.         $this->modulo->fields = array (
  32.             array ('private',   'id_mod', "''"),
  33.             array ('public',    'nom_mod'),
  34.             array ('public',    'url_mod'),
  35.             array ('public',    'img_mod')
  36.         );
  37.     }  
  38.     public function validar($log, $pass){
  39.         $where = "`log_usu` = '$log'";
  40.         $user = $this->db->getRecords($where);
  41.         if($user[0]['pas_usu'] == md5($pass)){
  42.             return $user[0];
  43.         }else{
  44.             return false;
  45.         }
  46.     }  
  47.     public function listar($where = false){
  48.         return $this->db->getRecords($where);
  49.     }  
  50.     public function agregar($nom, $log, $pas, $mail, $franq, $permisos){
  51.         $data[] = $nom;
  52.         $data[] = $log;
  53.         $data[] = md5($pas);
  54.         $data[] = $mail;
  55.         $data[] = $franq;
  56.         $this->db->insertRecord($data);
  57.         $id_usu = $this->db->return_id();
  58.         for ($i=0;$i<count($permisos);$i++){    
  59.             $per[] = $permisos[$i];
  60.             $per[] = $id_usu;
  61.             $per[] = '1';
  62.             $this->modulos->insertRecord($per);
  63.             $per = "";
  64.         }
  65.         return $id_usu;
  66.     }  
  67.     public function consultar($id){
  68.         $result = $this->db->getRecord($id);
  69.         $permisos = $this->modulos->getRecords("id_usu = $id AND visible=1");
  70.         $result[1] = $permisos;
  71.         return $result;
  72.     }  
  73.     public function editar($id, $nom, $log, $pas, $mail, $franq, $permisos){
  74.         $data[] = $nom;
  75.         $data[] = $log;
  76.         if($pas){$pas = md5($pas);}
  77.         $data[] = $pas;
  78.         $data[] = $mail;
  79.         $data[] = $franq;
  80.         $this->db->updateRecord($id,$data);
  81.         $data = "";
  82.         $mod = $this->modulo->getRecords();
  83.         $activar = array();
  84.         foreach($mod as $clave=>$valor){
  85.             $temp = true;
  86.             $per = $this->modulos->getRecords("id_usu = $id AND id_mod = ".$valor['id_mod']);
  87.             foreach($per as $clv=>$vlr){
  88.                 foreach($permisos as $c=>$v){
  89.                     if($v == $valor['id_mod']){
  90.                         $activar[] = $v;
  91.                         $data[] = '';
  92.                         $data[] = '';
  93.                         $data[] = "1";
  94.                         $this->modulos->updateRecord($vlr['id_per'],$data);
  95.                         $data = "";
  96.                         $temp = false;
  97.                     }
  98.                 }
  99.                 if($temp){
  100.                     $desactivar[] = $vlr['id_mod'];
  101.                     $data[] = '';
  102.                     $data[] = '';
  103.                     $data[] = "0";
  104.                     $this->modulos->updateRecord($vlr['id_per'],$data);
  105.                     $data = "";
  106.                 }
  107.             }
  108.         }
  109.         foreach($permisos as $clv=>$vlr){
  110.             $temp = true;
  111.             foreach($activar as $c=>$v){
  112.                 if($v == $vlr){
  113.                     $temp = false;
  114.                 }
  115.             }
  116.             if($temp){
  117.                 $nuevo[] = $vlr;
  118.                 $data[] = $vlr;
  119.                 $data[] = $id;
  120.                 $data[] = "1";
  121.                 $this->modulos->insertRecord($data);
  122.                 $data = "";
  123.             }
  124.         }
  125.     }
  126.    
  127.     public function borrar($id){
  128.         $this->db->deleteRecord($id);
  129.         $this->modulos->deleteRecords("id_usu=$id");
  130.     }
  131.    
  132.     public function cambiar_pass($id, $pass){
  133.         $data[] = '';
  134.         $data[] = '';
  135.         $data[] = md5($pass);
  136.         $data[] = '';
  137.         $data[] = '';
  138.         $this->db->updateRecord($id,$data);
  139.     }
  140. }
  141. ?>
La Linea: if($user[0]['pas_usu'] == md5($pass)){

Consultas.class.php
Código PHP:
Ver original
  1. <?php
  2. include("mysql.php");
  3. class Consultas {
  4.     private $link;
  5.     public $table;
  6.     public $fields;
  7.     public $campoId;
  8.     private $returnSQLResult =true;
  9.     public function __construct ($table, $campoId){
  10.         $this->table =$table;
  11.         $this->campoId =$campoId;
  12.         $this->fields =array ();
  13.         $this->link = conect();
  14.     }
  15.    
  16.     public function getRecords ($where_str=false, $order_str=false, $count=false, $start=0){
  17.         $where =$where_str ? "WHERE $where_str" : "";
  18.         $order =$order_str ? "ORDER BY $order_str" : "";
  19.         $limit = $count ? "LIMIT $start, $count" : "";
  20.         $campos =$this->getAllFields ();
  21.         $query ="SELECT $campos FROM {$this->table} $where $order $limit";
  22.         $consQ =mysql_query ($query);
  23.         $resultado =array ();
  24.         while (@$consF =mysql_fetch_assoc ($consQ))
  25.             array_push ($resultado, $consF);
  26.         return $resultado;
  27.     }
  28.     public function getRecord ($id){
  29.         return $this->getRecords ("{$this->campoId}=$id", false, 1);
  30.     }
  31.     public function insertRecord ($data){
  32.         $campos =$this->getTableFields ();
  33.         $sysData =$this->getDefaultValues ();
  34.         if($sysData){
  35.             $sysData .= ",";
  36.         }
  37.         $data =implode ("', '", $data);
  38.         $query ="INSERT INTO {$this->table} ($campos) VALUES ($sysData '$data')";
  39.         mysql_query ($query);
  40.         return $this->validateOperation();
  41.     }
  42.     public function return_id(){
  43.         return mysql_insert_id($this->link);
  44.     }
  45.    
  46.     public function updateRecord ($id, $data){
  47.         $campos =$this->getEditableFields (true);
  48.         $datos =array ();
  49.         foreach ($campos as $ind => $campo){
  50.             $current_data =$data[$ind];
  51.             if($current_data != ""){
  52.                 array_push ($datos, "$campo='$current_data'");
  53.             }
  54.         }
  55.         $datos =implode (", ", $datos);
  56.         $query = "UPDATE {$this->table} SET $datos WHERE {$this->campoId}=$id";
  57.         mysql_query ( $query );
  58.         return $this->validateOperation ();
  59.     }
  60.     public function deleteRecord ($id){
  61.         mysql_query ("DELETE FROM {$this->table} WHERE {$this->campoId}=$id");
  62.         return $this->validateOperation ();
  63.     }
  64.    
  65.     public function deleteRecords ($where){
  66.         mysql_query ("DELETE FROM {$this->table} WHERE $where");
  67.         return $this->validateOperation ();
  68.     }  
  69.     public function numPag ($where_str=false, $count=0){
  70.         $where =$where_str ? "WHERE $where_str" : "";
  71.         $query ="SELECT COUNT({$this->campoId}) FROM {$this->table} $where";
  72.         $consQ =mysql_query ($query);
  73.         $row = mysql_fetch_array($consQ);
  74.         $resultado = ceil($row[0] / $count);
  75.         return $resultado;
  76.     }
  77.     public function sql_direct($consulta){
  78.         $consQ =mysql_query ($consulta);
  79.         $resultado =array ();
  80.         while ($consF =mysql_fetch_assoc ($consQ))
  81.             array_push ($resultado, $consF);
  82.         return $resultado;
  83.     }
  84.  
  85.     private function getFieldsByType ($type=''){
  86.         $return =array ();
  87.         $types =explode ('|', $type);
  88.         foreach ($this->fields as $field){
  89.             $includeField =false;
  90.             foreach ($types as $t){
  91.                 if ($field[0] == $t){
  92.                     array_push ($return, $field);
  93.                 }
  94.             }
  95.         }
  96.         return $return;
  97.     }
  98.     private function getNameFields ($type){
  99.         $return =array ();
  100.         $fields =$this->getFieldsByType ($type);
  101.         foreach ($fields as $field){
  102.             array_push ($return, $field[1]);
  103.         }
  104.         return $return;
  105.     }
  106.     private function getEditableFields ($asArray=false){
  107.         $return =$this->getNameFields ('public');
  108.         return $asArray ? $return : implode (', ', $return);
  109.     }
  110.     private function getTableFields ($asArray=false){
  111.         $temp =$this->getNameFields ('private');
  112.         foreach($temp as $r)$return[] = $r;
  113.         $temp =$this->getNameFields ('public');
  114.         foreach($temp as $r)$return[] = $r;
  115.         return $asArray ? $return : implode (', ', $return);
  116.     }
  117.     private function getAllFields ($asArray=false){
  118.         $return =$this->getNameFields ('public|private|system');
  119.         return $asArray ? $return : implode (', ', $return);
  120.     }
  121.     private function getDefaultValues ($asArray=false){
  122.         $return =array ();
  123.         $fields =$this->getFieldsByType ('private');
  124.         foreach ($fields as $field){
  125.             array_push ($return, $field[2]);
  126.         }
  127.         return $asArray ? $return : implode (', ', $return);
  128.     }
  129.     private function validateOperation (){
  130.         return mysql_error()=='' ? true : false;
  131.     }
  132.     private function sql ($consulta){
  133.         $consQ =mysql_query (mysql_real_escape_string ($consulta));
  134.         $resultado =array ();
  135.         if ($consQ){
  136.             while ($consF =mysql_fetch_assoc ($consQ))
  137.                 array_push ($resultado, $consF);
  138.         }
  139.         return $resultado;
  140.     }
  141. }?>
Que puede Estar pasando?