gestor = $usuario; $this->locale = $locale; } /** * Busca y devuelve todas las empresas clientes del gerente. */ function getEmpresas(){ //PERMISOS: /* * Gestor (3) - Los suyos y los públicos. * Otro - Excepción */ $estado = $this->tipo; if($this->empresas == null){ //Recogemos todas las empresas públicas y las que tienen de gerente al usuario activo. if($this->gestor->tieneRol(3)){ if($this->gestor->tieneRol(1)){ $consulta = "SELECT * from clientes"; }else{ $consulta = "SELECT * from clientes WHERE privado = 0 || gerente = ".$this->gestor->getValor("oid"); } }else{ $error = $this->locale['2209']; throw new Exception($error); return false; exit; } $bd=new BD(); $resultado = $bd->execQuery($consulta); //Procesamos los pedidos. if(mysql_num_rows($resultado) == 0){ $this->empresas = array(); }else{ while($rows = mysql_fetch_array($resultado)){ $p = new Empresa($this->gestor, $rows["oid"], $this->locale); $this->empresas[] = $p; } } } return $this->empresas; } /** * Añade una empresa a la bd. * @param campos - campos de la nueva empresa. */ function addEmpresa($campos){ if(!$this->gestor->tieneRol(3)){ $error = $this->locale['2204']; throw new Exception($error); return false; exit; } $inserto = ""; $valores = ""; //Procesamos los datos foreach($campos as $key => $value){ $inserto .= "$key,"; $valores .= "'$value',"; } if ($inserto{strlen($inserto) - 1} == ",") $inserto = substr($inserto,0,strlen($inserto) - 1); if ($valores{strlen($valores) - 1} == ",") $valores = substr($valores,0,strlen($valores) - 1); //Insertamos en la BD $consulta = "INSERT INTO clientes ($inserto) VALUES ($valores)"; $bd = new BD(); if(!$bd->execQuery($consulta)){ $error = $this->locale['bd']; throw new Exception($error); return false; exit; }else{ $id = mysql_insert_id(); } return $id; } } ?>