Commit 33a779503cc8e77fbf405d6a72fe6fbe30e58e39

Authored by Edmar Moretti
1 parent 7d68acf3

Reformulação do código para permitir o uso de múltiplos perfis na inicialização.…

… Incluida a função array_in_array
Showing 1 changed file with 29 additions and 13 deletions   Show diff stats
classesphp/classe_menutemas.php
... ... @@ -75,7 +75,7 @@ $map_file - string $map_file Endereço do mapfile no servidor.
75 75 */
76 76 function __construct($map_file="",$perfil="",$locsistemas="")
77 77 {
78   - $this->perfil = $perfil;
  78 + $this->perfil = explode(",",$perfil);
79 79 $this->xmlsistemas = "";
80 80 if ($locsistemas != "")
81 81 $this->xmlsistemas = simplexml_load_file($locsistemas);
... ... @@ -113,7 +113,7 @@ array
113 113 {
114 114 $ps = mb_convert_encoding($s->PERFIL,"HTML-ENTITIES","auto");
115 115 $perfis = explode(",",$ps);
116   - if ((in_array($this->perfil,$perfis)) || ($ps == ""))
  116 + if (($this->array_in_array($this->perfil,$perfis)) || ($ps == ""))
117 117 {
118 118 $n = mb_convert_encoding($s->NOME,"HTML-ENTITIES","auto");
119 119 $i = mb_convert_encoding($s->IMAGEM,"HTML-ENTITIES","auto");
... ... @@ -193,7 +193,7 @@ array
193 193 {
194 194 $incluigrupo = FALSE;
195 195 $perfis = explode(",",$temp);
196   - if (in_array($this->perfil,$perfis))
  196 + if ($this->array_in_array($this->perfil,$perfis))
197 197 {$incluigrupo = TRUE;}
198 198 }
199 199 //verifica se existem temas no nível de grupo
... ... @@ -223,7 +223,7 @@ array
223 223 {
224 224 $incluisgrupo = FALSE;
225 225 $perfis = explode(",",$temp);
226   - if (in_array($this->perfil,$perfis))
  226 + if ($this->array_in_array($this->perfil,$perfis))
227 227 {$incluisgrupo = TRUE;}
228 228 }
229 229 if ($incluisgrupo == TRUE)
... ... @@ -257,7 +257,7 @@ array
257 257 $nomesis = mb_convert_encoding($s->NOMESIS,"HTML-ENTITIES","auto");
258 258 $ps = mb_convert_encoding($s->PERFIL,"HTML-ENTITIES","auto");
259 259 $perfis = explode(",",$ps);
260   - if ((in_array($this->perfil,$perfis)) || ($ps == ""))
  260 + if (($this->array_in_array($this->perfil,$perfis)) || ($ps == ""))
261 261 {
262 262 $funcoes = array();
263 263 foreach($s->FUNCAO as $f)
... ... @@ -267,7 +267,7 @@ array
267 267 $w = mb_convert_encoding($f->JANELAW,"HTML-ENTITIES","auto");
268 268 $h = mb_convert_encoding($f->JANELAH,"HTML-ENTITIES","auto");
269 269 $p = mb_convert_encoding($f->PERFIL,"HTML-ENTITIES","auto");
270   - if ((in_array($this->perfil,$perfis)) || ($p == ""))
  270 + if (($this->array_in_array($this->perfil,$perfis)) || ($p == ""))
271 271 {$funcoes[] = array("NOME"=>$n,"ABRIR"=>$a,"W"=>$w,"H"=>$h);}
272 272 }
273 273 $sistemas[] = array("NOME"=>$nomesis,"FUNCOES"=>$funcoes);
... ... @@ -320,7 +320,7 @@ array
320 320 {
321 321 $incluigrupo = FALSE;
322 322 $perfis = explode(",",mb_convert_encoding($g->PERFIL,"HTML-ENTITIES","auto"));
323   - if (in_array($this->perfil,$perfis))
  323 + if ($this->array_in_array($this->perfil,$perfis))
324 324 {$incluigrupo = TRUE;}
325 325 }
326 326 if ($incluigrupo == TRUE)
... ... @@ -335,7 +335,7 @@ array
335 335 {
336 336 $incluisgrupo = FALSE;
337 337 $perfis = explode(",",mb_convert_encoding($s->PERFIL,"HTML-ENTITIES","auto"));
338   - if (in_array($this->perfil,$perfis))
  338 + if ($this->array_in_array($this->perfil,$perfis))
339 339 {$incluisgrupo = TRUE;}
340 340 }
341 341 if ($incluisgrupo == TRUE)
... ... @@ -350,7 +350,7 @@ array
350 350  
351 351 $inclui = FALSE;
352 352 $perfis = explode(",",mb_convert_encoding($tema->PERFIL,"HTML-ENTITIES","auto"));
353   - if (in_array($this->perfil,$perfis))
  353 + if ($this->array_in_array($this->perfil,$perfis))
354 354 {$inclui = TRUE;}
355 355 }
356 356 if ($inclui == TRUE)
... ... @@ -406,7 +406,7 @@ $procurar - String que será procurada.
406 406 {
407 407 $incluigrupo = FALSE;
408 408 $perfis = explode(",",$temp);
409   - if (in_array($this->perfil,$perfis))
  409 + if ($this->array_in_array($this->perfil,$perfis))
410 410 {$incluigrupo = TRUE;}
411 411 }
412 412 if ($incluigrupo == TRUE)
... ... @@ -418,7 +418,7 @@ $procurar - String que será procurada.
418 418 {
419 419 $temp = mb_convert_encoding($sgrupo->PERFIL,"HTML-ENTITIES","auto");
420 420 $perfis = explode(",",$temp);
421   - if (!in_array($this->perfil,$perfis))
  421 + if (!$this->array_in_array($this->perfil,$perfis))
422 422 {$incluisgrupo = FALSE;}
423 423 }
424 424 if ($incluisgrupo == TRUE)
... ... @@ -430,7 +430,7 @@ $procurar - String que será procurada.
430 430 {
431 431 $temp = mb_convert_encoding($tema->PERFIL,"HTML-ENTITIES","auto");
432 432 $perfis = explode(",",$temp);
433   - if (!in_array($this->perfil,$perfis))
  433 + if (!$this->array_in_array($this->perfil,$perfis))
434 434 {$inclui = FALSE;}
435 435 }
436 436 if ($inclui == TRUE)
... ... @@ -495,6 +495,22 @@ $procurar - String que será procurada.
495 495 $s = str_replace("Ç","C",$s);
496 496 //$s = ereg_replace(" ","",$s);
497 497 return $s;
498   - }
  498 + }
  499 + /*
  500 + Function: array_in_array
  501 +
  502 + Procura ocorrências de um array em outro array
  503 + */
  504 + function array_in_array($needle, $haystack)
  505 + {
  506 + //Make sure $needle is an array for foreach
  507 + if(!is_array($needle)) $needle = array($needle);
  508 + //For each value in $needle, return TRUE if in $haystack
  509 + foreach($needle as $pin)
  510 + if(in_array($pin, $haystack)) return TRUE;
  511 + //Return FALSE if none of the values from $needle are found in $haystack
  512 + return FALSE;
  513 + }
  514 +
499 515 }
500 516 ?>
501 517 \ No newline at end of file
... ...