[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-ocs/sources/www/ -> preferences.php (source)

   1  <?
   2  //====================================================================================
   3  // OCS INVENTORY REPORTS
   4  // Copyleft Pierre LEMMET 2005
   5  // Web: http://ocsinventory.sourceforge.net
   6  //
   7  // This code is open source and may be copied and modified as long as the source
   8  // code is always made freely available.
   9  // Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
  10  //====================================================================================
  11  //Modified on 09/03/2006
  12  
  13  error_reporting(E_ALL & ~E_NOTICE);
  14  @session_start();
  15  
  16  if( ! function_exists ( "utf8_decode" )) {
  17  	function utf8_decode($st) {
  18          return $st;
  19      }
  20  }
  21  
  22  if( !in_array( $_GET["multi"], array(20,21,26,22,24,27)) ) {
  23      unset( $_SESSION["queryString"] );
  24      foreach( $_GET as $key=>$val )
  25          $_SESSION["queryString"] .= "&".$key."=".$val;
  26  }
  27  
  28  require('dbconfig.inc.php');
  29  include ("fichierConf.class.php");
  30  
  31  if(isset($_GET["lang"])) {
  32      $_SESSION["langueFich"] = "languages/".$_GET["lang"].".txt";
  33      unset($_SESSION["availFieldList"], $_SESSION["currentFieldList"]);
  34      setcookie( "lang", $_GET["lang"], time() + 3600 * 24 * 365 ); //expires in 365 days    
  35  
  36      if( isset( $_COOKIE["col"] ) ) {        
  37          foreach( $_COOKIE["col"] as $key=>$val ) {
  38              setcookie( "col[$key][value]", FALSE, time() - 3600 ); // deleting corresponding cookie
  39              setcookie( "col[$key][rang]", FALSE, time() - 3600 ); // deleting corresponding cookie            
  40          }
  41          unset( $_COOKIE["col"] );
  42      }
  43  }
  44  
  45  define("GUI_VER", "4020");
  46  define("SADMIN", 1);
  47  define("LADMIN", 2);   
  48  define("ADMIN", 3);
  49  define("PC_PAR_PAGE", 15); // default computer / page value
  50  define("TAG_NAME", "tag"); // do NOT change
  51  define("LOCAL_SERVER", $_SESSION["SERVEUR_SQL"]); // adress of the server handler used for local import
  52  $_SESSION["SERVER_READ"] = $_SESSION["SERVEUR_SQL"];
  53  $_SESSION["SERVER_WRITE"] = $_SESSION["SERVEUR_SQL"];
  54  unset( $_SESSION["debug"] );
  55  $_SESSION["debug"]  = false ;
  56  
  57  // DB NAME 
  58  define("DB_NAME", "ocsweb");
  59  //////////
  60  
  61  define("TAG_LBL", "Tag");
  62  define("DEFAULT_LANGUAGE", "" );
  63  if( isset($_COOKIE["lang"]) )
  64      $l = new FichierConf($_COOKIE["lang"]);
  65  else
  66      $l = new FichierConf(DEFAULT_LANGUAGE?DEFAULT_LANGUAGE:getBrowserLang());
  67  dbconnect();
  68  if(!isset($_SESSION["rangCookie"])) $_SESSION["rangCookie"] = 0;
  69  
  70  // available columns
  71  if( ! isset($_SESSION["availFieldList"]) ) {
  72      $_SESSION["availFieldList"] = array();
  73      
  74      $translateFields = array ( "a.".TAG_NAME=>TAG_LBL, "h.lastdate"=>$l->g(46), "h.name"=>$l->g(23), 
  75      "h.userid"=>$l->g(24),     "h.osname"=>$l->g(25), "h.memory"=>"Ram(MO)", "h.processors"=>"CPU(MHz)",
  76      "h.workgroup"=>$l->g(33), "h.osversion"=>$l->g(275), "h.oscomments"=>$l->g(286), "h.processort"=>$l->g(350), "h.processorn"=>$l->g(351),
  77      "h.swap"=>"Swap", "lastcome"=>$l->g(352), "h.quality"=>$l->g(353), "h.fidelity"=>$l->g(354),"h.description"=>$l->g(53), 
  78      "h.wincompany"=>$l->g(355), "h.winowner"=>$l->g(356), "h.useragent"=>$l->g(357), "b.smanufacturer"=>$l->g(64),
  79      "b.bmanufacturer"=>$l->g(284),"b.ssn"=>$l->g(36),"b.smodel"=>$l->g(65),"b.bversion"=>$l->g(209),"h.ipaddr"=>$l->g(34));
  80      
  81      $reqAc = "SHOW COLUMNS FROM accountinfo";
  82      $reqB  = "SHOW COLUMNS FROM bios";
  83      $reqHw = "SHOW COLUMNS FROM hardware";    
  84      
  85      $resAc = mysql_query($reqAc, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));
  86      $resB  = mysql_query($reqB, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));
  87      $resHw = mysql_query($reqHw, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));
  88      
  89      $lesCols = array();
  90      
  91      while($colname=mysql_fetch_array($resAc))
  92          $lesCols[] = Array( "pref"=>"a", "val"=>strtolower( $colname["Field"] ));
  93      while($colname=mysql_fetch_array($resB))
  94          $lesCols[] = Array( "pref"=>"b", "val"=>strtolower( $colname["Field"] ));
  95      while($colname=mysql_fetch_array($resHw))
  96          $lesCols[] = Array( "pref"=>"h", "val"=>strtolower( $colname["Field"] ));
  97      
  98      foreach( $lesCols as $laCol ) {
  99          if( in_array( $laCol["val"] , array("deviceid","id","checksum","hardware_id","etime","type") ))
 100              continue;
 101  
 102          if( isset( $translateFields[ $laCol["pref"].".".$laCol["val"] ] ) )
 103              $translated = $translateFields[ $laCol["pref"].".".$laCol["val"] ];
 104          else
 105              $translated = ucfirst( $laCol["val"] );
 106          $_SESSION["availFieldList"][$laCol["pref"].".".$laCol["val"]] = $translated;
 107      }
 108      array_multisort($_SESSION["availFieldList"]);
 109      
 110      // Registry
 111      /*
 112      $reqReg = "SELECT DISTINCT name FROM registry";
 113      $resReg = mysql_query($reqReg, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));        
 114      while($colname=mysql_fetch_array($resReg)) {
 115          $_SESSION["availRegistry"][] = $colname["name"];
 116      }
 117      array_multisort($_SESSION["availRegistry"]);
 118      */
 119  }
 120  
 121  if(!isset($_SESSION["currentFieldList"])) {// gui just launched
 122      if( isset( $_COOKIE["col"] ) ) { // columns cookie set ?
 123          // YES: load it
 124          foreach( $_COOKIE["col"] as $key=>$val ) { //sorting cookies by "rang"
 125              $cookSort[] = array("rang"=>$val["rang"],"name"=>$key, "value"=>urldecode($val["value"]));
 126              if( $val["rang"] > $_SESSION["rangCookie"] ) $_SESSION["rangCookie"] = $val["rang"];
 127          }
 128          
 129          sort($cookSort);
 130          foreach( $cookSort as $val ) { // loading ordered values
 131              $_SESSION["currentFieldList"][$val["name"]] = stripslashes($val["value"]);
 132          }        
 133      }
 134      else {// load default values
 135          $_SESSION["currentFieldList"] = array("a.".TAG_NAME=>TAG_LBL,"h.lastdate"=>$l->g(46),"h.name"=>$l->g(23),
 136          "h.userid"=>$l->g(24),"h.osname"=>$l->g(25),"h.memory"=>"Ram(MO)","h.processors"=>"CPU(MHz)");
 137          $_SESSION["rangCookie"] = 0;
 138          foreach( $_SESSION["currentFieldList"] as $key=>$val ) {                
 139              setcookie( "col[$key][value]", $val, time() + 3600 * 24 * 365 ); //expires in 365 days
 140              setcookie( "col[$key][rang]", $_SESSION["rangCookie"], time() + 3600 * 24 * 365 ); //expires in 365 days    
 141              $_SESSION["rangCookie"]++;
 142          }
 143      }
 144          
 145  }
 146  
 147  if(isset($_GET["suppCol"])) { // a column must be removed
 148      $keyName = array_search(  stripslashes($_GET["suppCol"]), $_SESSION["currentFieldList"] ); // look for the column's key
 149      
 150      if( $keyName ) { // found
 151          setcookie( "col[$keyName][value]", FALSE, time() - 3600 ); // deleting corresponding cookie
 152          setcookie( "col[$keyName][rang]", FALSE, time() - 3600 ); // deleting corresponding cookie
 153          unset( $_SESSION["storedRequest"]->select[$keyName] );
 154          unset($_SESSION["currentFieldList"][ $keyName ]);
 155          if( ! isset($_COOKIE["col"]) ) { // no cookie was previously set
 156              $_SESSION["rangCookie"] = 0;
 157              foreach( $_SESSION["currentFieldList"] as $key=>$val ) {                
 158                  setcookie( "col[$key][value]", $val, time() + 3600 * 24 * 365 ); //expires in 365 days
 159                  setcookie( "col[$key][rang]", $_SESSION["rangCookie"], time() + 3600 * 24 * 365 ); //expires in 365 days    
 160                  $_SESSION["rangCookie"]++;
 161              }
 162          }
 163      }
 164  }
 165  if( isset($_GET["resetcolumns"]) && $_GET["resetcolumns"] == $l->g(396) ) {
 166      $_SESSION["currentFieldList"] = array("a.".TAG_NAME=>TAG_LBL,"h.lastdate"=>$l->g(46),"h.name"=>$l->g(23),
 167      "h.userid"=>$l->g(24),"h.osname"=>$l->g(25),"h.memory"=>"Ram(MO)","h.processors"=>"CPU(MHz)");
 168      
 169      foreach( $_SESSION["availFieldList"] as $key=>$val ) {
 170          setcookie( "col[$key][value]", FALSE, time() - 3600 ); // deleting corresponding cookie
 171          setcookie( "col[$key][rang]", FALSE, time() - 3600 ); // deleting corresponding cookie
 172      }
 173          
 174      $_SESSION["rangCookie"] = 0;
 175      foreach( $_SESSION["currentFieldList"] as $key=>$val ) {                
 176          setcookie( "col[$key][value]", $val, time() + 3600 * 24 * 365 ); //expires in 365 days
 177          setcookie( "col[$key][rang]", $_SESSION["rangCookie"], time() + 3600 * 24 * 365 ); //expires in 365 days    
 178          $_SESSION["rangCookie"]++;
 179      }
 180  }
 181  else if(isset($_GET["newcol"])) { // new column
 182      $valName = stripslashes($_GET["newcol"]);
 183      //if( ! ereg("$Registry (.*)", $valName, $res) ) {
 184          $keyName = array_search( $valName, $_SESSION["availFieldList"] ); // look for the column's key
 185          if( $keyName ) { // found                    
 186              $_SESSION["rangCookie"]++;        
 187              $value = $_SESSION["availFieldList"][$keyName];
 188              setcookie("col[$keyName][value]", $value, time() + 3600 * 24 * 365 ); //expires in 365 days
 189              setcookie("col[$keyName][rang]", $_SESSION["rangCookie"], time() + 3600 * 24 * 365 ); //expires in 365 days
 190              $_SESSION["currentFieldList"] = array_merge($_SESSION["currentFieldList"], array( $keyName=>$value));
 191              $_SESSION["storedRequest"]->select[$keyName] = $value;
 192          }             
 193      /*}
 194      else {
 195          $_SESSION["currentRegistry"][] = $res[1];
 196      }*/
 197  }
 198  
 199  $boutOver="onmouseover=\"this.style.background='#FFFFFF';\" onmouseout=\"this.style.background='#C7D9F5'\"";
 200  
 201  function dbconnect() {
 202      $db = DB_NAME;
 203      
 204      $link=@mysql_connect($_SESSION["SERVER_READ"],$_SESSION["COMPTE_BASE"],$_SESSION["PSWD_BASE"]);
 205      if(!$link) {
 206          echo "<br><center><font color=red><b>ERROR: MySql connection problem<br>".mysql_error()."</b></font></center>";
 207          die();
 208      }
 209      if( ! @mysql_select_db($db,$link)) {
 210          include ('install.php');
 211          die();
 212      }
 213          
 214      $link2=@mysql_connect($_SESSION["SERVER_WRITE"],$_SESSION["COMPTE_BASE"],$_SESSION["PSWD_BASE"]);
 215      if(!$link2) {
 216          echo "<br><center><font color=red><b>ERROR: MySql connection problem<br>".mysql_error($link2)."</b></font></center>";
 217          die();
 218      }
 219  
 220      if( ! @mysql_select_db($db,$link2)) {
 221          include ('install.php');
 222          die();
 223      }
 224      
 225      $_SESSION["writeServer"] = $link2;    
 226      $_SESSION["readServer"] = $link;
 227      return $link2;
 228  }
 229  
 230  function ShowResults($req,$sortable=true,$modeCu=false,$modeRedon=false,$deletableP=true,$registrable=false,$teledeploy=false, $affect=false)
 231  {
 232          global $l, $_GET;                
 233          $deletable = ($_SESSION["lvluser"]==SADMIN) && $_GET["multi"]!=2 && $deletableP;        
 234          
 235          global $pcparpage;
 236          $columneditable = $req->columnEdit;        
 237          
 238          if( ! $affect )
 239              unset( $_SESSION["saveRequest"] );
 240          $ind=0;
 241          $var="option".$ind;        
 242  
 243          while(isset($_POST[$var]))
 244          {                    
 245              if($req->isNumber[$ind])     
 246                  $_POST[$var]=0+$_POST[$var];// si un nombre est attendu, on transforme en nombre
 247              
 248              $req->where=str_replace("option$ind",$_POST[$var],$req->where); 
 249              // on remplace les strings "optionX" de la requete par leurs valeurs présentes dans les variables en POST
 250              $ind++;
 251              $var="option".$ind;            
 252          }            
 253              
 254          if(    isset($_SESSION["storedRequest"])   && (  (isset($_GET["c"])&&$_GET["c"]) || $_GET["av"] == 1 || $_GET["suppCol"] == 1 || isset($_GET["newCol"]))   ) 
 255          {
 256              if($_SESSION["c"]==$_GET["c"]) { // If same column is sorted again
 257                  if( $_GET["rev"] == 1 )
 258                      $_GET["a"]= $_GET["a"] ? 0 : 1 ;
 259              }
 260              else {
 261                  $_SESSION["c"]=$_GET["c"];
 262                  $_GET["a"]= 1;
 263              }
 264  
 265              $suffixe = $_GET["a"] ? " ASC" : " DESC";        
 266  
 267              $count = getCount( $_SESSION["storedRequest"] );                
 268              $pcParPage = $modeCu ? $count : $pcparpage ;
 269              $pcParPage = $pcParPage>0 ? $pcParPage : PC_PAR_PAGE;
 270              $numPages = ceil($count/$pcParPage);    
 271  
 272              if( $numPages == 0 )
 273                  $numPages++;
 274              
 275              if( $_SESSION["pageCur"] > $numPages ){
 276                  $_SESSION["pageCur"] = $numPages ;
 277              }
 278              
 279              $beg = ($_SESSION["pageCur"]-1) * $pcParPage;                
 280          
 281              if ( $_GET["c"] ) {
 282                  $ord = stripslashes($_GET["c"]).$suffixe;
 283                  $_SESSION["storedRequest"]->order = $ord;
 284                  $toExec = getQuery( $_SESSION["storedRequest"], " {$beg},".$pcParPage ) ;
 285              }
 286              else {
 287                  $toExec = getQuery( $_SESSION["storedRequest"], " {$beg},".$pcParPage ) ;
 288              }
 289          }
 290          else
 291          {
 292              $count = getCount($req);
 293              $pcParPage = $modeCu ? $count : $pcparpage ;    
 294              $pcParPage = $pcParPage>0 ? $pcParPage : PC_PAR_PAGE;            
 295              $numPages = ceil($count/$pcParPage);    
 296  
 297              if( $numPages <= 0 )
 298                  $numPages++;
 299              
 300              if( $_SESSION["pageCur"] > $numPages || ! $_SESSION["pageCur"]){
 301                  $_SESSION["pageCur"] = $numPages ;
 302              }
 303  
 304              if( $columneditable && ! $req->order )
 305                  $orderDefault = isset($_SESSION["currentFieldList"]["h.lastdate"]) ? " h.lastdate DESC" : " 1 ASC";
 306              
 307              $beg = ($_SESSION["pageCur"]-1) * $pcParPage;
 308              if( ! $req->order ) $req->order = $orderDefault;
 309              
 310              $toExec = getQuery( $req, " {$beg},".$pcParPage ) ;
 311              $_SESSION["storedRequest"]=$req;
 312          }
 313          
 314          $result = mysql_query( $toExec, $_SESSION["readServer"] ) or die(mysql_error($_SESSION["readServer"]));    
 315                  
 316          //les GET a rajouter
 317          $pref="";
 318          foreach ($_GET as $gk=>$gv) {
 319              if($gk=="page" || $gk=="rev" || $gk == "logout" || $gk=="c"|| $gk=="direct"|| $gk=="supp" || $gk=="a"|| $gk=="suppCol" || $gk=="newcol" || $gk=="resetcolumns") continue;
 320              $pref .= "&{$gk}=".urlencode($gv);
 321          }
 322          
 323          //les GET globaux a rajouter
 324          $prefG="";
 325          $hiddens ="";
 326          foreach ($_GET as $gk=>$gv){
 327          
 328              if( $gk=="rev"|| $gk=="suppCol"|| $gk=="supp" || $gk == "logout" || $gk=="newcol" || $gk=="page" || $gk=="resetcolumns") continue;
 329              
 330              if( $gk =="page" && ($gv==-1 || $gv==-2)) {
 331                  $gv = $_SESSION["pageCur"];
 332              }
 333  
 334              $prefG .= "&{$gk}=".urlencode(stripslashes($gv));                
 335              $hiddens .= "<input type='hidden' name='$gk' value='".stripslashes($gv)."'>\n";
 336          }        
 337  
 338          if( !$modeCu && $count > 0) {
 339              echo "<br><center><table width='60%' border='0'><tr><td align='center'><b>".$count." ".$l->g(90)."</b>";        
 340                      
 341              echo "<br>&nbsp;&nbsp;<a href=ipcsv.php target=_blank>(".$l->g(183).")</a></td>";
 342                  
 343              $machNmb = array(5,10,15,20,50,100);
 344              
 345              echo "<td align='center'><form name='pcp' method='GET' action='index.php'>$hiddens".$l->g(340).
 346              ":&nbsp;<select name='pcparpage' OnChange='pcp.submit();'>";
 347              
 348              foreach( $machNmb as $nbm ) {
 349                  $countHl++;
 350                  echo "<option".($countHl%2==1?" class='hi'":"").($_SESSION["pcparpage"] == $nbm ? " selected" : "").">$nbm</option>";
 351              }
 352              
 353              echo "</select></form></font></td>";
 354              
 355              if( $columneditable) {
 356                  echo "<td align='center'><form name='addCol' method='GET' action='index.php'>";
 357                  echo $hiddens;                            
 358                  echo "<select name='newcol' OnChange='addCol.submit();'>";            
 359                  echo "<option>".$l->g(349)."</option>";
 360                  
 361                  foreach( $_SESSION["availFieldList"] as $nomField=>$valField ) {
 362                      if( ! in_array($valField,$_SESSION["currentFieldList"])    ) {
 363                          $countHl++;
 364                          echo "<option".($countHl%2==1?" class='hi'":"").">$valField</option>";                        
 365                      }
 366                  }
 367                  /*foreach( $_SESSION["availRegistry"] as $nomField=>$valField ) {
 368                      if( ! in_array($valField,$_SESSION["currentRegistry"])    ) {
 369                          $countHl++;
 370                          echo "<option".($countHl%2==1?" class='hi'":"").">Registry $valField</option>";                        
 371                      }
 372                  }*/
 373                  echo "</select><input type='submit' name='resetcolumns' value='".$l->g(396)."'></form></td>";
 374              }
 375              
 376              echo "</tr></table></center><br>";
 377          }
 378          
 379          if($modeRedon) {
 380              echo "<form id='idredon' name='redon' action='index.php?multi=6&c=".urlencode(stripslashes($_GET["c"]))."&a=".urlencode($_GET["a"])."' method='POST'>
 381                  <p align='center'><input name='subredon' value='".$l->g(177)."' type='submit'></p>";
 382          }
 383                  
 384          $cpt=1;
 385          printNavigation( $prefG, $numPages);    
 386          echo "<table BGCOLOR='#C7D9F5' BORDER='0' WIDTH = '95%' ALIGN = 'Center' CELLPADDING='0' BORDERCOLOR='#9894B5'>
 387          <tr BGCOLOR='#C7D9F5'>";        
 388          if($modeRedon)
 389              echo "<td>&nbsp;</td>";
 390          
 391          if(!isset($_GET["c"])) {            
 392              $_SESSION["storedRequest"]=$req;    
 393          }
 394          else
 395              $_SESSION["c"]=$_GET["c"];        
 396              
 397          if($deletable)
 398          {?>
 399              <script language=javascript>
 400  				function confirme(did, typ)
 401                  {
 402                      if(confirm("<?echo $l->g(119)?>"+did+" ?"))
 403                          if(typ == 1)
 404                              window.location="index.php?<?=$pref?>&c=<?=(isset($_GET["c"])?urlencode($_GET["c"]):"1")?>&a=<?=(isset($_GET["a"])?urlencode($_GET["a"]):0); ?>&page=<?=urlencode($_GET["page"])?>&suppnet="+did;
 405                          else
 406                              window.location="index.php?<?=$pref?>&c=<?=(isset($_GET["c"])?urlencode($_GET["c"]):"1")?>&a=<?=(isset($_GET["a"])?urlencode($_GET["a"]):0); ?>&page=<?=urlencode($_GET["page"])?>&supp="+did;
 407                  }
 408              </script>
 409          <?
 410  
 411          }
 412          if( $req->countId == "h.id" ) //computer in devices
 413              echo "<td width='15px'>&nbsp;</td>";
 414              
 415          while($colname=mysql_fetch_field($result)) // On récupère le nom de toutes les colonnes        
 416          {
 417              if($colname->name!="h.id"&&$colname->name!="deviceid")
 418              {                            
 419                  $a = ( isset($_GET["a"]) ? $_GET["a"] : 0 ) ;
 420                  $isDate[$colname->name] = ($colname->type == "date" ? 1 : 0);
 421                  $isDateTime[$colname->name] =($colname->type == "datetime" || $colname->type == "timestamp" ? 1 : 0);
 422  
 423                  if($sortable) {    
 424                      if( $_SESSION["storedRequest"]->countId == "h.id" && ($_SESSION["storedRequest"]->group == "" || ! in_array($_SESSION["storedRequest"]->group, array("h.id","s.name","a.tag") ) )) { // NO group by clause
 425                          
 426                          $vraiNomChamp = array_search( $colname->name, $_SESSION["currentFieldList"] );
 427                          
 428                          /*if( ! $vraiNomChamp ) {
 429                              $ind = array_search( $colname->name, $_SESSION["currentRegistry"] );
 430                              $vraiNomChamp = urlencode("\"".$_SESSION["currentRegistry"][$ind]."\"");
 431                          }*/
 432                                  
 433                          if( ! $vraiNomChamp )
 434                              $vraiNomChamp = array_search( $colname->name, $_SESSION["storedRequest"]->select );                            
 435                          }
 436                      else                    
 437                          $vraiNomChamp = "\"".$colname->name."\"";
 438                      //echo "if( $vraiNomChamp == ".$_SESSION["c"]." || \"\'\".".$colname->name.".\"\'\" == ".$_SESSION["c"]." ) \";";
 439                      echo "<td align='center'><table><tr><td>";
 440                      $hrefSort = "<a href=index.php?$pref&c=".urlencode($vraiNomChamp)."&a=$a&rev=1&page=1>";
 441                      if( isset($_SESSION["c"]) && ($vraiNomChamp == $_SESSION["c"] || "\'".$colname->name."\'" == $_SESSION["c"]) ) {
 442                          if($a == 1 ) 
 443                              echo "$hrefSort<img src='image/down.png'></a></td>";
 444                          else 
 445                              echo "$hrefSort<img src='image/up.png'></a></td>";
 446                      }
 447                      else {
 448                          mb_ereg( "\"? *([^\"]*)\"? (DESC|ASC)", $_SESSION["storedRequest"]->order, $res);
 449                          //echo "colname:".$colname->name."vrainomchamp:".$vraiNomChamp;
 450                          //var_dump( $res );    
 451                          
 452                          if( $res[1] == $colname->name || $res[1] == $vraiNomChamp )
 453                              if( $res[2] == "ASC" ) 
 454                                  echo "$hrefSort<img src='image/down.png'></a></td>";
 455                              else 
 456                                  echo "$hrefSort<img src='image/up.png'></a></td>";
 457                      }
 458                      echo "<td><B>{$hrefSort}{$colname->name}</b></a></td>";
 459                      
 460                      
 461                      if( sizeof($_SESSION["storedRequest"]->select)>3 && $columneditable && in_array( $colname->name , $_SESSION["currentFieldList"]))                        
 462                          echo "<td><a href=index.php?page=1&$prefG&suppCol=".urlencode($colname->name).">&nbsp;<img src=image/supp.png></td>";
 463                      echo "</tr></table></td>"; // Affichage en tete colonne*/
 464                      
 465                  }
 466                  else
 467                     echo "<td><CENTER><B>$colname->name</CENTER></td>"; // Affichage en tete colonne
 468                  
 469                  $tabChamps[$cpt]=$colname->name;
 470              }            
 471              $cpt++;
 472          }
 473          
 474          if( ($deletable||$modeRedon) && $req->countId == "h.id" ) //computer in devices
 475          {
 476              echo "<td>&nbsp;</td>";
 477          }
 478          if( $teledeploy ) {
 479              echo "<td>&nbsp;</td><td align='center'><b>".$l->g(431)."</b></td><td align='center'><b>Stats</b></td>";    
 480          }
 481          else if( $affect ) {
 482              echo "<td><b>".$l->g(122)."</b></td><td><b>".$l->g(432)."</b></td>";
 483              if( $affect != 2 )
 484                  echo "<td align='center'><b>".$l->g(433)."</b></td>";
 485          }
 486  
 487          echo "</tr>";
 488          $x=-1; $nb=0;
 489          $uneMachine=false;
 490  
 491          while($item = mysql_fetch_array($result)) // Parcour de toutes les lignes résultat
 492          {    
 493              flush();
 494              echo "<TR height=20px ". ($x == 1 ? "bgcolor='#FFFFFF'" : "bgcolor='#F2F2F2'") .">";    // on alterne les couleurs de ligne
 495              $x = ($x == 1 ? 0 : 1) ;    
 496              $nb++;
 497              if($modeRedon) {
 498                  echo "<td align=center><input type=checkbox name='ch$nb' value='".urlencode($item["h.id"])."'></td>";
 499              }        
 500                      
 501              if( $req->countId == "h.id" ) { //computer in devices
 502                      $resDev = @mysql_query("SELECT * FROM devices WHERE (name<>'IPDISCOVER' || ivalue<>1) AND hardware_id = ".$item["h.id"], $_SESSION["readServer"]);
 503                      if( mysql_num_rows( $resDev ) > 0)
 504                          echo "<td align='center' valign='center'><img width='15px' src='image/red.png'></td>";
 505                      else
 506                          echo "<td>&nbsp;</td>";
 507              }            
 508      
 509              foreach($tabChamps as $chmp) {// Affichage de toutes les valeurs résultats
 510                  echo "<td align='center'>";                                
 511                  if($chmp==TAG_LBL)
 512                  {
 513                      $leCuPrec=$item[$chmp];                    
 514                  }
 515                  else if($chmp==$l->g(23) && isset($item["h.id"]))
 516                  {                    
 517                      echo "<a href=\"machine.php?sessid=".session_id()."&systemid=".urlencode($item["h.id"])."\" target=\"_new\" onmouseout=\"this.style.color = 'blue';\" onmouseover=\"this.style.color = '#ff0000';\">";
 518                      $uneMachine=true;
 519                  }
 520                  else if($chmp==$l->g(28))
 521                  {
 522                      echo "<a href=?cuaff=$leCuPrec>";
 523                  }
 524                  
 525                  if( $isDate[$chmp] )
 526                      echo dateFromMysql($item[$chmp])."</span></a></font></td>\n";
 527                  else if( $isDateTime[$chmp] )
 528                      echo dateTimeFromMysql($item[$chmp])."</span></a></td>\n";                
 529  
 530                  else if(!$toutAffiche)
 531                      echo $item[$chmp]."</span></a></font></td>\n";
 532                  
 533              }
 534              
 535              if( $deletable && isset($item["h.id"]) ) {
 536                  echo "<td align=center><a href='#' OnClick='confirme(\"".$item["h.id"]."\",0);'><img src=image/supp.png></a></td>";
 537              }
 538              else if( $deletable && isset($item[$l->g(95)]) ) {
 539                  echo "<td align=center><a href='#' OnClick='confirme(\"".$item[$l->g(95)]."\",1);'><img src=image/supp.png></a></td>";
 540              }
 541              
 542              if( $teledeploy ) {    
 543                  echo "<td align='center'><a href='index.php?multi=21&suppack=".$item[0]."'><img src=image/supp.png></a></td>
 544                  <td align='center'><a href='index.php?multi=21&actpack=".$item[0]."'><img src='image/Gest_admin1.png'></a></td>
 545  <td align='center'>
 546  <a OnClick='window.open(\"tele_stats.php?sessid=".session_id()."&stat=".$item[0]."\",\"fenstat".$item[0]."\",\"location=0,status=0,scrollbars=0,menubar=0,resizable=0,width=820,height=600\")' 
 547   href='javascript:void(0);'><img src='image/cal.gif'></a></td>";    
 548              }
 549              else if( $affect ) {
 550                  echo "<td align='center'><a href='index.php?multi=".($affect==2?26:24)."&suppack=".$item[0]."'><img src=image/supp.png></a></td>";
 551                  echo "<td align='center'><a href='index.php?multi=".($affect==2?26:24)."&suppack=".$item[0]."&nonnot=1'><img src=image/suppv.png></a></td>";
 552                  
 553                  if( $affect != 2)
 554                      echo "<td align='center'><a href='index.php?".($affect==3?"systemid=".$_GET["systemid"]."&":"")."multi=24&affpack=".$item[0]."'><img src='image/Gest_admin1.png'></a></td>";    
 555              }
 556                          
 557              if( $registrable &&  isset($item["mac"]) )
 558                  echo "<td align=center><a href=index.php?multi=3&mode=8&mac=".$item["mac"]."><img src='image/Gest_admin1.png'></a></td>";
 559              echo "</tr>";
 560          }    
 561          
 562          echo"</td></tr></table>";
 563          if($modeRedon) {
 564              echo "<input name='maxredon' type='hidden' value='$nb'></form>";
 565          }
 566          
 567          if($x==-1)
 568          {
 569              echo "<div align=center><b>".$l->g(42)."</b></div>";
 570          }            
 571          
 572          if( $uneMachine ) {            
 573              if( $_SESSION["lvluser"]==SADMIN ) {
 574                  echo "<br><center><b>".$l->g(430).":</b>";            
 575                  echo "&nbsp;&nbsp;<b><a href='index.php?multi=22' target=_top>".$l->g(429)."</a></b>";
 576                  //echo "&nbsp;&nbsp;<b><a href='index.php?multi=23' target=_top>".$l->g(312)."</a></b>";
 577                  echo "&nbsp;&nbsp;<b><a href='index.php?multi=24' target=_top>".$l->g(428)."</a></b>";
 578                  echo "&nbsp;&nbsp;<b><a href='index.php?multi=27' target=_top>".$l->g(122)."</a></b>";            
 579                  echo "</center>";
 580              }
 581          }        
 582          printNavigation( $prefG, $numPages);
 583          return $nb;
 584  }
 585  
 586  function getCount( $req ) {
 587      $ech = $_SESSION["debug"];
 588      $reqCount = "SELECT count(distinct ".$req->countId.") AS cpt FROM ".$req->from.($req->fromPrelim?",":"").$req->fromPrelim;
 589      if( $req->where )
 590          $reqCount .= " WHERE ".$req->where;
 591          
 592      if($ech) echo "<br><font color='red'><b>$reqCount</b></font><br><br>";
 593  
 594      $resCount = mysql_query($reqCount);
 595      $valCount = mysql_fetch_array($resCount);
 596      
 597      return $valCount["cpt"];
 598  }
 599  
 600  function getPrelim(  $req, $limit=NULL ) {
 601      $ech = $_SESSION["debug"];
 602      $rac = "LEFT JOIN accountinfo a ON a.hardware_id=h.id";
 603      $selectReg = "";
 604      //    $selectFin = $req->getSelect();
 605      //$fromFin = $req->from;
 606      $cpt = 1;
 607      /*if( is_array($_SESSION["currentRegistry"]) )
 608          foreach( $_SESSION["currentRegistry"] as $regist ) {
 609              $selectReg .= ", regAff{$cpt}.regvalue AS \"$regist\"";
 610              $fromReg.= "LEFT JOIN registry regAff{$cpt} ON regAff{$cpt}.hardware_id=h.id";
 611              if( $cpt > 1 )
 612                  $whereReg .= " AND ";
 613              $whereReg .= "regAff{$cpt}.name='".$regist;        
 614              $cpt ++;
 615          }*/    
 616      
 617      $selPrelim = $req->getSelectPrelim();
 618      $fromPrelim = $req->from;    
 619      
 620      $reqPrelim = "SELECT $selPrelim FROM ".$fromPrelim.($req->fromPrelim?",":"").$req->fromPrelim;
 621      if( $req->where ) $reqPrelim .= " WHERE ".$req->where; 
 622      if( $req->group ) $reqPrelim .= " GROUP BY ".$req->group;
 623      
 624      // bidouille
 625      if( strstr( $req->order, "ipaddr" ) ) {
 626          if( strstr( $req->order, "DESC" ) ) {
 627              $order = "inet_aton(h.ipaddr) DESC";
 628          }
 629          else {
 630              $order = "inet_aton(h.ipaddr) ASC";
 631          }
 632      }
 633      else
 634          $order = $req->order;
 635          
 636      if( $req->order ) $reqPrelim .= " ORDER BY ".$order;
 637      
 638      
 639      if( $limit ) $reqPrelim .= " LIMIT ".$limit;
 640      
 641      if($ech) echo "<br><font color='green'><b>$reqPrelim</b></font><br><br>";
 642      flush();
 643      return $reqPrelim;
 644  }
 645  
 646  function getQuery( $req, $limit ) {
 647      
 648      $ech = $_SESSION["debug"];
 649      $resPrelim = mysql_query( getPrelim( $req, $limit ) , $_SESSION["readServer"]);
 650      
 651      $selFin = $req->getSelect();
 652      $fromFin = $req->from ;    
 653      
 654      $toExec = "SELECT ".$selFin." FROM ".$fromFin;
 655      $prem = true;
 656      
 657      while( $valPrelim = mysql_fetch_array($resPrelim) ) {
 658          if( !$prem) $lesIn .= ",";
 659  
 660          $lesIn .= "'".addslashes($valPrelim[$req->linkId])."'";
 661          $prem = false;
 662      }
 663      
 664      if( !$prem ) {
 665          $toExec .= " WHERE ".$req->whereId." IN($lesIn) ";    
 666          if( $req->selFinal )
 667              $toExec .= $req->selFinal;
 668      }
 669      else
 670          $toExec .= " WHERE 1=0";
 671      
 672      if( $req->group ) $toExec .= " GROUP BY ".$req->group;
 673      // bidouille
 674      if( strstr( $req->order, "ipaddr" ) ) {
 675          if( strstr( $req->order, "DESC" ) ) {
 676              $order = "inet_aton(h.ipaddr) DESC";
 677          }
 678          else {
 679              $order = "inet_aton(h.ipaddr) ASC";
 680          }
 681      }
 682      else
 683          $order = $req->order;
 684          
 685      if( $req->order ) $toExec .= " ORDER BY ".$order;
 686      
 687      if($ech) echo "<br><font color='blue'><b>$toExec</b></font><br><br>";
 688      flush();
 689      return $toExec;
 690  }
 691  
 692  function printEnTete($ent) {
 693      echo "<br><table border=1 class= \"Fenetre\" WIDTH = '100%' ALIGN = 'Center' CELLPADDING='5'>
 694      <th height=40px class=\"Fenetre\" colspan=2><b>".$ent."</b></th></table>";
 695  }
 696  
 697  function dateOnClick($input, $checkOnClick=false) {
 698      global $l;
 699      $dateForm = $l->g(269) == "%m/%d/%Y" ? "MMDDYYYY" : "DDMMYYYY" ;
 700      if( $checkOnClick ) $cOn = ",'$checkOnClick'";
 701      $ret = "OnClick=\"javascript:NewCal('$input','$dateForm',false,24{$cOn});\"";
 702      return $ret;
 703  }
 704  
 705  function datePick($input, $checkOnClick=false) {
 706      global $l;
 707      $dateForm = $l->g(269) == "%m/%d/%Y" ? "MMDDYYYY" : "DDMMYYYY" ;
 708      if( $checkOnClick ) $cOn = ",'$checkOnClick'";
 709      $ret = "<a href=\"javascript:NewCal('$input','$dateForm',false,24{$cOn});\">";
 710      $ret .= "<img src=\"image/cal.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"Pick a date\"></a>";
 711      return $ret;
 712  }
 713  
 714  function dateFromMysql($v) {
 715      global $l;
 716      
 717      if( $l->g(269) == "%m/%d/%Y" )
 718          $ret = sprintf("%02d/%02d/%04d", $v[5].$v[6], $v[8].$v[9], $v);
 719      else    
 720          $ret = sprintf("%02d/%02d/%04d", $v[8].$v[9], $v[5].$v[6], $v);
 721      return $ret;
 722  }
 723  
 724  function dateTimeFromMysql($v) {
 725      global $l;
 726      
 727      if( $l->g(269) == "%m/%d/%Y" )
 728          $ret = sprintf("%02d/%02d/%04d %02d:%02d:%02d", $v[5].$v[6], $v[8].$v[9], $v, $v[11].$v[12],$v[14].$v[15],$v[17].$v[18]);
 729      else    
 730          $ret = sprintf("%02d/%02d/%04d %02d:%02d:%02d", $v[8].$v[9], $v[5].$v[6], $v, $v[11].$v[12],$v[14].$v[15],$v[17].$v[18]);
 731      return $ret;
 732  }
 733  
 734  function dateToMysql($date_cible) {
 735  
 736      global $l;
 737      if(!isset($date_cible)) return "";
 738      
 739      $dateAr = explode("/", $date_cible);
 740      
 741      if( $l->g(269) == "%m/%d/%Y" ) {
 742          $jour  = $dateAr[1];
 743          $mois  = $dateAr[0];
 744      }
 745      else {
 746          $jour  = $dateAr[0];
 747          $mois  = $dateAr[1];
 748      }
 749  
 750      $annee = $dateAr[2];
 751      return sprintf("%04d-%02d-%02d", $annee, $mois, $jour);    
 752  }
 753  
 754  function getBrowser() {
 755      $bro = $_SERVER['HTTP_USER_AGENT'];
 756      if( strpos ( $bro, "MSIE") === false ) {
 757          return "MOZ";
 758      }
 759      return "IE";
 760  }
 761  
 762  function getBrowserLang() {
 763      $bro = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
 764      if (strpos( $bro,"de") === false) {
 765             // Not german
 766             if (strpos( $bro,"es") === false) {
 767                 // Not spanish
 768                 if (strpos( $bro,"fr") === false) {
 769                     // Not french
 770                     if (strpos( $bro,"it") === false) {
 771                         // Not italian
 772                         if (strpos( $bro,"pt-br") === false) {
 773                             // Not brazilian portugueuse
 774                             if (strpos( $bro,"pt") === false) {
 775                                 // Not portugueuse
 776                                 if (strpos( $bro,"pl") === false) {
 777                                    // Not polish
 778                                    // Use english default language
 779                                 return "english";
 780                                 }
 781                                 else
 782                                    // Polish
 783                                    return "polish";
 784                             }
 785                             else
 786                                 // Portugueuse
 787                           return "portugueuse";
 788                         }
 789                         else
 790                             // Brazilian portugueuse
 791                       return "brazilian_portugueuse";
 792                     }
 793                     else
 794                         // Italian
 795                   return "italian";
 796                 }
 797                 else
 798                     // French
 799               return "french";
 800             }
 801             else
 802                 // Spanish
 803                 return "spanish";
 804         }
 805         else
 806             // German
 807          return "german";
 808  }
 809  
 810  
 811  
 812  function printNavigation( $lesGets, $numPages) {
 813                  
 814          $prefG = "<a href=index.php?".stripslashes($lesGets)."&page=";
 815          echo "<p align='center'>";
 816          if( $numPages > 1 ) {            
 817              if( $_SESSION["pageCur"] == 1) {                
 818                  echo "&nbsp;&nbsp;";//voir grisé
 819                  echo "&nbsp;&nbsp;1&nbsp;..";                            
 820              } else {
 821                  echo "&nbsp;&nbsp;{$prefG}-1><img src='image/prec24.png'></a>";
 822                  echo "&nbsp;{$prefG}1>1</a>&nbsp;..";            
 823              }
 824              
 825              if( $_SESSION["pageCur"] && $_SESSION["pageCur"]>1 && $_SESSION["pageCur"]!=$numPages ) {
 826                  echo  "&nbsp;".$_SESSION["pageCur"]."&nbsp;";
 827              }
 828              
 829              if( $_SESSION["pageCur"] >= $numPages) {
 830                  echo "..&nbsp;&nbsp;$numPages&nbsp;";
 831                  //echo "<img src='image/proch24.png'>&nbsp;&nbsp;"; voir grisé
 832              } else {
 833                  echo "..&nbsp;{$prefG}$numPages>$numPages</a>&nbsp;";
 834                  echo "{$prefG}-2><img src='image/proch24.png'></a>&nbsp;&nbsp;";
 835              }
 836          }
 837          echo "</p><br>";
 838  }
 839  
 840  function deleteNet($id) {
 841      mysql_query("DELETE FROM network_devices WHERE macaddr='$id';", $_SESSION["writeServer"]);
 842  }
 843  
 844  function deleteDid($id, $checkLock = true, $traceDel = true) {
 845      global $l;
 846      
 847      if( ! $checkLock || lock($id) ) {
 848      
 849          $resId = mysql_query("SELECT deviceid FROM hardware WHERE id='$id'",$_SESSION["readServer"]) or die(mysql_error());
 850          $valId = mysql_fetch_array($resId);
 851          $idHard = $id;
 852          $did = $valId["deviceid"];
 853          if( $idHard ) {    
 854              if( strpos ( $did, "NETWORK_DEVICE-" ) === false ) {
 855                  $resNetm = @mysql_query("SELECT macaddr FROM networks WHERE hardware_id=$idHard", $_SESSION["writeServer"]) or die(mysql_error());
 856                  while( $valNetm = mysql_fetch_array($resNetm)) {
 857                      @mysql_query("DELETE FROM netmap WHERE mac='".$valNetm["macaddr"]."';", $_SESSION["writeServer"]) or die(mysql_error());
 858                  }        
 859              }
 860              
 861              $tables=Array("accesslog","accountinfo","bios","controllers","drives",
 862              "inputs","memories","modems","monitors","networks","ports","printers","registry",
 863              "slots","softwares","sounds","storages","videos","devices");    
 864              
 865              echo "<center><font color=red><b>$did ".$l->g(220)."</b></font></center>";
 866              
 867              foreach ($tables as $table) {
 868                  mysql_query("DELETE FROM $table WHERE hardware_id=$idHard;", $_SESSION["writeServer"]) or die(mysql_error());        
 869              }
 870              mysql_query("DELETE FROM hardware WHERE id=$idHard;", $_SESSION["writeServer"]) or die(mysql_error());        
 871              //TRACE_DELETED
 872              if($traceDel && mysql_num_rows(mysql_query("SELECT IVALUE FROM config WHERE IVALUE>0 AND NAME='TRACE_DELETED'", $_SESSION["writeServer"]))){
 873                  mysql_query("insert into deleted_equiv(DELETED,EQUIVALENT) values('$did',NULL)", $_SESSION["writeServer"]) or die(mysql_error());
 874              }
 875          }
 876          if( $checkLock ) 
 877              unlock($id);
 878      }
 879      else
 880          errlock();
 881  }
 882  
 883  function lock($id) {
 884      //echo "<br><font color='red'><b>LOCK $id</b></font><br>";
 885      $reqClean = "DELETE FROM locks WHERE unix_timestamp(since)<(unix_timestamp(NOW())-60)";
 886      $resClean = mysql_query($reqClean, $_SESSION["writeServer"]) or die(mysql_error());
 887      
 888      $reqLock = "INSERT INTO locks(hardware_id) VALUES ('$id')";
 889      if( $resLock = mysql_query($reqLock, $_SESSION["writeServer"]) or die(mysql_error()))
 890          return( mysql_affected_rows ( $_SESSION["writeServer"] ) == 1 );
 891      else return false;
 892  }
 893  
 894  function unlock($id) {
 895      //echo "<br><font color='green'><b>UNLOCK $id</b></font><br>";
 896      $reqLock = "DELETE FROM locks WHERE hardware_id='$id'";
 897      $resLock = mysql_query($reqLock, $_SESSION["writeServer"]) or die(mysql_error());
 898      return( mysql_affected_rows ( $_SESSION["writeServer"] ) == 1 );
 899  }
 900  
 901  function errlock() {
 902      global $l;
 903      echo "<br><center><font color=red><b>".$l->g(376)."</b></font></center><br>";
 904  }
 905  
 906  function incPicker() {
 907  
 908      global $l;
 909      echo "<script language=\"javascript\">
 910      var MonthName=[";
 911      
 912      for( $mois=527; $mois<538; $mois++ )
 913          echo "\"".$l->g($mois)."\",";
 914      echo "\"".$l->g(538)."\"";
 915      
 916      echo "];
 917      var WeekDayName=[";
 918      
 919      for( $jour=539; $jour<545; $jour++ )
 920          echo "\"".$l->g($jour)."\",";
 921      echo "\"".$l->g(545)."\"";    
 922      
 923      echo "];
 924      </script>    
 925          <script language=\"javascript\" type=\"text/javascript\" src=\"js/datetimepicker.js\">
 926      </script>";
 927  }
 928  
 929  ?>


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1