function modify()
 {
     if (!isset($_POST['submit_modify'])) {
         //Mostrar plantilla vac�a
         //pasarle a la plantilla los modulos y grupos con sus respectivos checkbox a checked false
         /*$this->checkbox=new permissions_modules();
         			$modules=new modules();
         			$num_modules = $modules->get_list_modules();
         		
         			$k=0;
         			for($i=0;$i<$num_modules;$i++)
         			{
         				if($_SESSION['super'])
         				{
         					$this->checkbox->per_modules[$i]=new permissions_modules;
         					$this->checkbox->per_modules[$i]->id_module=$modules->modules_list[$i]['id_module'];
         					$this->checkbox->per_modules[$i]->module_name=$modules->modules_list[$i]['name_web'];
         					$this->checkbox->per_modules[$i]->validate_per_module_without_groups($this->id_user);
         				}
         				else
         				{
         					if(($modules->modules_list[$i]['name']!='modules')&&($modules->modules_list[$i]['name']!='methods'))
         					{
         						$this->checkbox->per_modules[$k]=new permissions_modules;
         						$this->checkbox->per_modules[$k]->id_module=$modules->modules_list[$i]['id_module'];
         						$this->checkbox->per_modules[$k]->module_name=$modules->modules_list[$i]['name_web'];
         						$this->checkbox->per_modules[$k]->validate_per_module_without_groups($this->id_user);
         						
         						if($modules->modules_list[$i]['name']=='corps')
         						{
         							//Si es admin y el modulo es empresas s�lo puede otorgar permisos en el m�todo Ver, 
         							//por lo que todos los dem�s m�todos no le ser�n accesibles
         							$j=0;
         							$salir = false;
         							while(($j<$this->checkbox->per_modules[$k]->num_methods)&&($salir==false))
         							{
         								if($this->checkbox->per_modules[$k]->per_methods[$j]->method_name == 'view')
         								{
         									$name = $this->checkbox->per_modules[$k]->per_methods[$j]->method_name; 
         									$id_method = $this->checkbox->per_modules[$k]->per_methods[$j]->id_method;
         									$name_web = $this->checkbox->per_modules[$k]->per_methods[$j]->method_name_web;
         									$permiso = $this->checkbox->per_modules[$k]->per_methods[$j]->per;
         									
         									$this->checkbox->per_modules[$k]->per_methods = null;								
         									$this->checkbox->per_modules[$k]->per_methods[0] = new permissions_methods();
         									$this->checkbox->per_modules[$k]->per_methods[0]->id_method = $id_method;
         									$this->checkbox->per_modules[$k]->per_methods[0]->method_name_web = $name_web;
         									$this->checkbox->per_modules[$k]->per_methods[0]->method_name == $name; 
         									$this->checkbox->per_modules[$k]->per_methods[0]->per = $permiso;
         
         									$this->checkbox->per_modules[$k]->num_methods = 1;
         									$salir = true;
         								}
         								$j++;
         							}
         						}
         						
         						$k++;
         					}
         				}
         			}
         			
         			$groups=new groups();
         			$groups->get_list_groups();
         	
         			$this->get_groups($this->id_user);
         			
         			$k=0;
         			for($i=0;$i<$groups->num;$i++)
         			{
         				if($_SESSION['super'])
         				{
         					$this->checkbox_groups[$i]= new groups();
         					$this->checkbox_groups[$i]->read($groups->groups_list[$i][$groups->ddbb_id_group]);	
         					
         					if ($this->checkbox_groups[$i]->verify_user($this->id_user)!=0)
         					{
         						$this->checkbox_groups[$i]->belong=1;
         					}
         				}
         				else
         				{
         					if(($groups->groups_list[$i][$groups->ddbb_name] != 'superadmin')&&($groups->groups_list[$i][$groups->ddbb_name] != 'admin'))
         					{
         						$this->checkbox_groups[$k]= new groups();
         						$this->checkbox_groups[$k]->read($groups->groups_list[$i][$groups->ddbb_id_group]);				
         						if ($this->checkbox_groups[$k]->verify_user($this->id_user)!=0)
         						{
         							$this->checkbox_groups[$k]->belong=1;
         						}
         						$k++;
         					}
         				}
         			}
         			//$tpl->assign('usuarios',$this->per_module_methods);
         			*/
         //Modulos
         $this->get_checkbox_modules_from_bbdd();
         //Grupos
         $this->get_checkbox_groups_from_bbdd();
         return 0;
     } else {
         /*************
          * 
          *OJO!!! ANTES DE COGER LOS DATOS DEL FORMULARIO ASIGNAR EL LOGIN
          *
          */
         $login = $this->login;
         $passwd = $this->passwd;
         //Introducir los datos de post.
         $this->get_fields_from_post();
         //Validacion
         $this->fields_list->modify_value($this->ddbb_id_user, $this->id_user);
         $this->fields_list->modify_value($this->ddbb_login, $this->login);
         $this->fields_list->modify_value($this->ddbb_passwd, $this->passwd);
         $this->fields_list->modify_value($this->ddbb_name, $this->name);
         $this->fields_list->modify_value($this->ddbb_last_name, $this->last_name);
         $this->fields_list->modify_value($this->ddbb_last_name2, $this->last_name2);
         //validamos
         $return = $this->fields_list->validate();
         //Si la contrase�a es igual a la introducida entonces no ha habido cambios y no hace falta reescribirla y por tanto no hace falta una comprobacion.
         if ($passwd != $this->passwd) {
             $return = $return && $this->fields_list->compare_passwd($this->passwd, $this->retype);
         }
         //Se cogen los logins para comprobar que no se introduzca un login igual
         $array = $this->take_logins();
         $return_login = $this->fields_list->validate_login($this->login, $array, $login);
         $return = $return && $return_login;
         //En caso de que la validacion haya sido fallida se muestra la plantilla
         //con los campos erroneos marcados con un *
         if (!$return) {
             //Mostrar plantilla con datos erroneos
             return -1;
         } else {
             $ADODB_FETCH_MODE = ADODB_FETCH_BOTH;
             //crea una nueva conexi�n con una bbdd (mysql)
             $this->db = NewADOConnection($this->db_type);
             //le dice que no salgan los errores de conexi�n de la ddbb por pantalla
             $this->db->debug = false;
             //realiza una conexi�n permanente con la bbdd
             $this->db->Connect($this->db_ip, $this->db_user, $this->db_passwd, $this->db_name);
             //mete la consulta para coger los campos de la bbdd
             $this->sql = "SELECT * FROM " . $this->table_prefix . $this->table_name . " WHERE " . $this->ddbb_id_user . " = \"" . $this->id_user . "\"";
             //la ejecuta y guarda los resultados
             $this->result = $this->db->Execute($this->sql);
             //si falla
             if ($this->result === false) {
                 $this->error = 1;
                 $this->db->close();
                 return 0;
             }
             //rellenamos el array con los datos de los atributos de la clase
             $record = array();
             $record[$this->ddbb_id_user] = $this->id_user;
             $record[$this->ddbb_login] = $this->login;
             $record[$this->ddbb_passwd] = $this->passwd;
             $record[$this->ddbb_name] = $this->name;
             $record[$this->ddbb_last_name] = $this->last_name;
             $record[$this->ddbb_last_name2] = $this->last_name2;
             $record[$this->ddbb_full_name] = $this->full_name;
             $record[$this->ddbb_internal] = $this->internal;
             $record[$this->ddbb_active] = $this->active;
             //calculamos la sql de inserci�n respecto a los atributos
             $this->sql = $this->db->GetUpdateSQL($this->result, $record);
             //insertamos el registro
             $this->db->Execute($this->sql);
             //si se ha insertado una fila
             if ($this->db->Affected_Rows() == 1 || $this->sql == "") {
                 //capturammos el id de la linea insertada
                 $this->modify_group_users();
                 $this->modify_module_methods();
                 $this->db->close();
                 //Se hace nueva imagen de las tablas de permiso para usuarios
                 $permisos = new permissions();
                 $_SESSION['permisos_user_modules'] = $permisos->get_per_user_modules();
                 $_SESSION['permisos_user_methods'] = $permisos->get_per_user_methods();
                 //devolvemos el id de la tabla ya que todo ha ido bien
                 return $this->id_user;
             } else {
                 //devolvemos 0 ya que no se ha insertado el registro
                 $this->error = -1;
                 $this->db->close();
                 return 0;
             }
         }
     }
 }
 function modify()
 {
     $this->user_changed = 0;
     if (!isset($_POST['submit_modify'])) {
         if (!isset($_POST['existUser']) || $_POST['existUser'] == "new" || $_POST['existUser'] == "modify") {
             if ($_POST['existUser'] == "new" || $this->id_user == 0 || $this->id_user == "") {
                 $this->obj_user = new users();
                 $this->obj_user->get_list_users();
                 $this->obj_user->is_emps = true;
                 $user_changed = $this->obj_user->add();
             }
             if ($_POST['existUser'] == "modify" || $this->id_user != 0) {
                 $this->obj_user = new users();
                 $this->obj_user->get_list_users();
                 $this->obj_user->is_emps = true;
                 $this->obj_user->read_fields($this->id_user);
                 $user_changed = $this->obj_user->modify();
             }
         }
         return 0;
     } else {
         //Introducir los datos de post.
         $this->get_fields_from_post();
         //Validacion
         //$return=validate_fields();
         $this->fields_list->modify_value($this->ddbb_id_emp, $this->id_emp);
         $this->fields_list->modify_value($this->ddbb_id_user, $this->id_user);
         $this->fields_list->modify_value($this->ddbb_id_corp, $this->id_corp);
         $this->fields_list->modify_value($this->ddbb_name, $this->name);
         $this->fields_list->modify_value($this->ddbb_last_name, $this->last_name);
         $this->fields_list->modify_value($this->ddbb_last_name2, $this->last_name2);
         $this->fields_list->modify_value($this->ddbb_birthday, $this->birthday);
         $this->fields_list->modify_value($this->ddbb_license, $this->license);
         $this->fields_list->modify_value($this->ddbb_phone, $this->phone);
         $this->fields_list->modify_value($this->ddbb_mobile_phone, $this->mobile_phone);
         $this->fields_list->modify_value($this->ddbb_fax, $this->fax);
         $this->fields_list->modify_value($this->ddbb_mail, $this->mail);
         $this->fields_list->modify_value($this->ddbb_address, $this->address);
         $this->fields_list->modify_value($this->ddbb_city, $this->city);
         $this->fields_list->modify_value($this->ddbb_state, $this->state);
         $this->fields_list->modify_value($this->ddbb_country, $this->country);
         $this->fields_list->modify_value($this->ddbb_postal_code, $this->postal_code);
         $return = $this->fields_list->validate();
         //Validamos la fecha de alta.
         $cadena = $this->fields_list->validate_date($this->come, 1);
         if (!is_int($cadena)) {
             array_push($this->fields_list->array_error, 'come', $cadena);
             $return = false;
         }
         if (!isset($_POST['user']) || $_POST['user'] == "new") {
             $this->obj_user = new users();
             $this->obj_user->get_list_users();
             $this->obj_user->is_emps = true;
             $this->obj_user->return_validate_emps = $return;
             $this->user_changed = $this->obj_user->add();
             $this->radiobutton = "new";
         } elseif ($_POST['user'] == "modify" || $this->id_user != 0) {
             $this->obj_user = new users();
             $this->obj_user->get_list_users();
             $this->obj_user->is_emps = true;
             $this->obj_user->read_fields($this->id_user);
             $this->user_changed = $this->obj_user->modify();
             $this->radiobutton = "modify";
         } else {
             $this->obj_user = new users();
             $this->obj_user->get_list_users();
             $this->obj_user->is_emps = true;
             $this->obj_user->get_checkbox_modules_from_bbdd();
             $this->obj_user->get_checkbox_groups_from_bbdd();
             $this->radiobutton = "exist";
         }
         //En caso de que la validacion haya sido fallida se muestra la plantilla
         //con los campos erroneos marcados con un *
         if (!$return || $this->user_changed == -1) {
             //Mostrar plantilla con datos erroneos
             return -1;
         } else {
             //$this->come=$this->fields_list->change_date($this->come,"en");
             $this->birthday = $this->fields_list->change_date($this->birthday, "en");
             $this->license = $this->fields_list->change_date($this->license, "en");
             $ADODB_FETCH_MODE = ADODB_FETCH_BOTH;
             //crea una nueva conexin con una bbdd (mysql)
             $this->db = NewADOConnection($this->db_type);
             //le dice que no salgan los errores de conexin de la ddbb por pantalla
             $this->db->debug = false;
             //realiza una conexin permanente con la bbdd
             $this->db->Connect($this->db_ip, $this->db_user, $this->db_passwd, $this->db_name);
             //mete la consulta para coger los campos de la bbdd
             $this->sql = "SELECT * FROM " . $this->table_prefix . $this->table_name . " WHERE " . $this->ddbb_id_emp . " = \"" . $this->id_emp . "\"";
             //la ejecuta y guarda los resultados
             $this->result = $this->db->Execute($this->sql);
             //si falla
             if ($this->result === false) {
                 $this->error = 1;
                 $this->db->close();
                 return 0;
             }
             //rellenamos el array con los datos de los atributos de la clase
             $record = array();
             $record[$this->ddbb_id_emp] = $this->id_emp;
             $record[$this->ddbb_name] = $this->name;
             $record[$this->ddbb_last_name] = $this->last_name;
             $record[$this->ddbb_last_name2] = $this->last_name2;
             $record[$this->ddbb_birthday] = $this->birthday;
             $record[$this->ddbb_license] = $this->license;
             $record[$this->ddbb_address] = $this->address;
             $record[$this->ddbb_id_corp] = $this->id_corp;
             $record[$this->ddbb_city] = $this->city;
             $record[$this->ddbb_state] = $this->state;
             $record[$this->ddbb_country] = $this->country;
             $record[$this->ddbb_postal_code] = $this->postal_code;
             $record[$this->ddbb_phone] = $this->phone;
             $record[$this->ddbb_mobile_phone] = $this->mobile_phone;
             $record[$this->ddbb_fax] = $this->fax;
             $record[$this->ddbb_mail] = $this->mail;
             if ($_POST["user"] == "new") {
                 $this->id_user = $this->obj_user->id_user;
             }
             $record[$this->ddbb_id_user] = $this->id_user;
             //calculamos la sql de insercin respecto a los atributos
             $this->sql = $this->db->GetUpdateSQL($this->result, $record);
             //insertamos el registro
             $this->db->Execute($this->sql);
             //si se ha insertado una fila
             $Affected_Rows = $this->db->Affected_Rows();
             /*Al hacer la modificacion de categorias y vacaciones antes del siguiente "if"
             		 se debe de guardar en una variable el contenido de las filas afectadas y hacer
             		 la condicion del if con esa variable ya que al hacer las modificaciones ese valor var�a.
             		*/
             $return_category = $this->modify_category($this->id_emp);
             $return_holyday = $this->modify_holyday($this->id_emp);
             if ($Affected_Rows == 1 || $this->user_changed != 0 || $this->sql == "" || $return_category != 0 || $return_holyday != 0) {
                 //capturammos el id de la linea insertada
                 $this->db->close();
                 //Modificar variable de sesi�n con tabla de permisos
                 $permisos = new permissions();
                 $_SESSION['permisos_user_modules'] = $permisos->get_per_user_modules();
                 $_SESSION['permisos_user_methods'] = $permisos->get_per_user_methods();
                 //devolvemos el id de la tabla ya que todo ha ido bien
                 return $this->id_emp;
             } else {
                 //devolvemos 0 ya que no se ha insertado el registro
                 $this->error = -1;
                 $this->db->close();
                 return 0;
             }
         }
     }
 }
예제 #3
0
     		 $afor = explode(",", $for);
     		 print trim($afor[0]);
   		}
   		 else
    		{
 			print "aqu� tamos";
      		print getenv('REMOTE_ADDR');
    		}
 */
 //Al iniciar sesi�n no ha podido expirar esta a�n
 $_SESSION['expire'] = 0;
 $permisos = new permissions();
 $_SESSION['permisos_group_methods'] = $permisos->get_per_group_methods();
 $_SESSION['permisos_group_modules'] = $permisos->get_per_group_modules();
 $_SESSION['permisos_user_modules'] = $permisos->get_per_user_modules();
 $_SESSION['permisos_user_methods'] = $permisos->get_per_user_methods();
 /*
 Para acceder a cualquier tabla se hace de la siguiente manera
 $_SESSION['nombre_tabla'][id_user/id_group][id_module/id_method]
 
 Comprobar en el caso de que no est� en la lista y escribir en su caso un 0
 if(!isset($_SESSION['permisos_group_methods'][9][21]))
 	print "permisos 0";
 else
 	print "permisos ".$_SESSION['permisos_group_methods'][9][21];
 	
 Ahora siempre que se necesite buscar algo se puede acceder de esta manera o creando un bucle 
 que recorra los identificadores y compruebe si est� o no en la lista y su valor
 */
 //Se crea el men� de usuario
 $_SESSION['modules_list'] = $menu->table_modules(-2);