1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
function bloquer($type=0){
$i=0;
$arr=explode("/",$this->url);
$this->nom=$arr[count($arr)-1];
if ($type){
if ($this->permis1 || $this->permis) return true;
$this->a->del('nom="'.$this->nom.'" and date<'.(time()-10),"block");
$this->code=rand(0,900000000);
$ok2=$this->a->add("nom,type,date,code",'"'.$this->nom.'",1,'.time().','.$this->code,"block");
$ok3=$ok2 && ($arr=$this->a->isreturn('nom="'.$this->nom.'" and code='.$this->code,"block","num"));
$ok=$ok3 && ($sortie=@mysql_query('SELECT * FROM block WHERE nom="'.$this->nom.'" and num<'.$arr["num"]));
if ($ok){
while ($elem=mysql_fetch_array($sortie)){
$ok= $ok && $elem["type"];
}
}
$this->a->close("block");
$ok && ($this->permis1=1);
while(!$ok){
usleep(100000);
$i++;
if (!$ok2){
$ok2=$this->a->add("nom,type,date,code",'"'.$this->nom.'",1,'.time().','.$this->code,"block");
}
if (!$ok3){
$ok3=$ok2 && ($arr=$this->a->isreturn('nom="'.$this->nom.'" and code='.$this->code,"block","num"));
}
$ok=$ok3 && ($sortie=@mysql_query('SELECT * FROM block WHERE nom="'.$this->nom.'" and num<'.$arr["num"]));
if ($ok){
while ($elem=mysql_fetch_array($sortie)){
$ok= $ok && $elem["type"];
}
}
$this->a->close("block");
$ok && ($this->permis1=1);
$ok=($i > 99 ) || $ok;
}
$ok2 && !$this->permis1 && $this->a->del('nom="'.$this->nom.'" and code='.$this->code,"block");
return $this->permis1;
} else {
if ($this->permis) return true;
$this->a->del('nom="'.$this->nom.'" and date<'.(time()-10),"block");
$this->code=rand(0,900000000);
$ok2=$this->a->add("nom,type,date,code",'"'.$this->nom.'",0,'.time().','.$this->code,"block");
$ok3=$ok2 && ($arr=$this->a->isreturn('nom="'.$this->nom.'" and code='.$this->code,"block","num"));
$ok=$ok3 && ($sortie=@mysql_query('SELECT * FROM block WHERE nom="'.$this->nom.'" and num<'.$arr["num"])) && (!mysql_fetch_array($sortie));
$ok && ($this->permis=1);
$this->a->close("block");
while(!$ok){
usleep(100000);
$i++;
if (!$ok2){
$ok2=$this->a->add("nom,type,date,code",'"'.$this->nom.'",0,'.time().','.$this->code,"block");
}
if (!$ok3){
$ok3=$ok2 && ($arr=$this->a->isreturn('nom="'.$this->nom.'" and code='.$this->code,"block","num"));
}
$ok=$ok3 && ($sortie=@mysql_query('SELECT * FROM block WHERE nom="'.$this->nom.'" and num<'.$arr["num"])) && (!mysql_fetch_array($sortie));
$this->a->close("block");
$ok && ($this->permis=1);
$ok=($i > 99 ) || $ok;
}
$ok2 && !$this->permis && $this->a->del('nom="'.$this->nom.'" and code='.$this->code,"block");
return $this->permis;
}
}
function debloquer($type=0){
$arr=explode("/",$this->url);
$this->nom=$arr[count($arr)-1];
if (!((!$type && $this->permis) || ($type && $this->permis1 && !$this->permis))) return false;
sleep(2); // ce sleep sert a attendre entre deux modifications du fichier
$ok=$this->a->del('nom="'.$this->nom.'" and code='.$this->code,"block");
$this->a->close("block");
if ($ok) {
$this->permis1=0;
$this->permis=0;
}
return $ok;
} |
Partager