<?php


function USERS_HISTORY() {
global $thiss,$MENU_INIT,$ARG1,$ARG1_VAL,$SQL_USER,$SQL_DATABASE,$INTERFACE_ADDR,$SQL_USER_PASS,$USERS_FILTER_PROBLEM,$USERS_FILTER_STATUS,$SQL_WIEV,$USERS_COLUMN,$USERS_COLUMN_DESC,$USERS_HIDECOLUMN;
DETECT_TABLE_COLUMN(); //TO_REMOVE trzeba sprawdzic czy mozna - nie musi byc w tylu miejscach, bo wymaga przeladowanie przy przeskakiwaniu z tabel

 if($_SESSION[DEBUG]) { echo "func USERS_HISTORY used for wiev ID ".$_SESSION[USERSHIST_COLUMN][WIEVID] ."Detected column/table is:".$thiss->DETECT_TABLE_COLUMN."/".$thiss->DETECT_TABLE_NAME."* Detected table:".$thiss->DETECT_TABLE_NAME."*";
//print_r($USERSHIST_COLUMN);
  }
if(($MENU_INIT==USERS_HISTORY) && ($ARG1=HISTORY)) { 
  if($ARG1_VAL) $_SESSION[USERSHIST_COLUMN][WIEVID]="$ARG1_VAL";
 if($_SESSION[DEBUG]) echo "VALUALIZED at USERS_HISTORY func _SESSION[USERSHIST_COLUMN][WIEVID] = $ARG1_VAL";
 }


//unset($_SESSION[DEBUG]);
SEF("MENU");
MENU();
NAVIGATOR();
//echo "<img src=icon/history.gif alt=HISTORIA border=1>";
// CREATE_MENUFUNC_INIT_2(USERS_EDIT,EDIT,$ARG1_VAL,'<img src=icon/edit.gif alt=EDYCJA border=0>') ;
TOOLBAR_DETECT();
//$_SESSION[CURRENT_MENU]=USERS;
if($_SESSION[DEBUG]) echo "USERS WIEV FUNCTION USED";
if($USERS_FILTER_PROBLEM) USERS_FILTER_PROBLEM();
//SQL_WIEV();
//USERS_HIDECOLUMN();
//USERS_SORTER();
$conn=mysql_pconnect($INTERFACE_ADDR,$SQL_USER,$SQL_USER_PASS);
if (!$conn) die("ERROR podczas tworzenia polaczenia do bazy $SQL_DATABASE !\n");
mysql_select_db($SQL_DATABASE) or die("ERROR podczas wyboru bazy R50!");

$zapSQL="SELECT * from ".$thiss->DETECT_TABLE_NAME." where ID_USERS2='".$_SESSION[$thiss->DETECT_TABLE_COLUMN][WIEVID]."' ;";
$result = mysql_query($zapSQL,$conn) or die("Blad zapytania2!");
$_SESSION[$thiss->DETECT_TABLE_COLUMN][MYSQL_NUM_ROWS_TOTAL] = mysql_num_rows($result);
$zapSQL="SELECT * from ".$thiss->DETECT_TABLE_NAME."  where ID_USERS2='".$_SESSION[USERSHIST_COLUMN][WIEVID]."' ".$_SESSION[$thiss->DETECT_TABLE_COLUMN][USERS_SORTER_SQL]." ". $_SESSION[$thiss->DETECT_TABLE_COLUMN][SQL_WIEV_CURR_SQL]." ;";

//echo "$zapSQL";
$result = mysql_query($zapSQL,$conn) or die("Blad zapytania2!");
$num_rows = mysql_num_rows($result);
$_SESSION[$thiss->DETECT_TABLE_COLUMN][MYSQL_NUM_ROWS] = $num_rows;
//echo "<BR>LICZBA_WIERSZY $num_rows<BR>";
/*
echo "<table border='1' cellspacing='0' cellpadding='0' width='100%'><tr>";
CREATE_MENU_INIT(USERS_FILTER_PROBLEM,PROBLEM,PROBLEMY);
CREATE_MENU_INIT(USERS_FILTER_PROBLEM,WARNING,OSTRZEZENIA);
CREATE_MENU_INIT(USERS_FILTER_PROBLEM,NORMAL,BEZ_PROBLEMOW);
CREATE_MENU_INIT(USERS_FILTER_PROBLEM,'','PROBLEM-ALL');
CREATE_MENU_INIT(USERS_FILTER_STATUS,WAITING,OCZEKUJACY);
CREATE_MENU_INIT(USERS_FILTER_STATUS,AKTYWNI,AKTYWNI);
CREATE_MENU_INIT(USERS_FILTER_STATUS,'','ALL-STATUS');
CREATE_MENU_INIT(SQL_WIEV,NEXT,NASTEPNE);
CREATE_MENU_INIT(SQL_WIEV,PREV,POPRZEDNIE);
CREATE_MENUFUNC_INIT(USERS_COLUMN_MENU,POKAZ_KOLUMNY);
echo "</tr></table>";
*/
echo "\n<table width='100%' border='1' cellspacing='0' cellpadding='0'>";
    echo "<TD><font size=-2>";
//    CREATE_MENU_NOTD_INIT_3(USERS_COLUMN,$value,HIDE,'X') ;
    echo "</TD>";
    foreach ($_SESSION[$thiss->DETECT_TABLE_COLUMN][ID] as $value) {
    if(!$_SESSION[$thiss->DETECT_TABLE_COLUMN][HIDE][$value]==HIDE) { echo "<td><font size='-2'>" ; 



if($_SESSION[$thiss->DETECT_TABLE_COLUMN][SORTED][$_SESSION[$thiss->DETECT_TABLE_COLUMN][DESC][$value]]==PRI)  $border=1; else $border=0; // echo "<font color='red'><img src=icon/sortred.gif width=10 border=0 alt=sortuj></font>";
    CREATE_MENU_NOTD_INIT_2(USERS_SORTER,USERS_SORTER,USERS_SORTER1,$_SESSION[$thiss->DETECT_TABLE_COLUMN][DESC][$value],'<img src=icon/sortred.gif border='.$border.' alt=SORTUJ><img src=icon/sortred.gif border='.$border.' alt=SORTUJ>') ; 
if($_SESSION[$thiss->DETECT_TABLE_COLUMN][USERS_SORTER_SQL]) { 
 if($_SESSION[$thiss->DETECT_TABLE_COLUMN][SORTED][$_SESSION[$thiss->DETECT_TABLE_COLUMN][DESC][$value]]==SEC)  $border=1; else $border=0; // echo "<font color='green'><img src=icon/sort.gif width=10 border=0 alt=sortuj></font>";
    CREATE_MENU_NOTD_INIT_2(USERS_SORTER,USERS_SORTER,USERS_SORTER2,$_SESSION[$thiss->DETECT_TABLE_COLUMN][DESC][$value],'<img src=icon/sort.gif border='.$border.' alt=sortuj>') ; 
      }
    CREATE_MENU_NOTD_INIT_3(USERS_COLUMN,$value,HIDE,'<img src=icon/shutdown.gif border=0 alt=sortuj>') ;



//    CREATE_MENU_NOTD(USERS_SORTER2,"$USERS_COLUMN_DESC[$value] DESC",'\\/') ; 
//    CREATE_MENU_NOTD(USERS_SORTER1,"$USERS_COLUMN_DESC[$value] DESC",'<b>\\/</b>') ; 
    
     echo "<br><b>" . $_SESSION[USERSHIST_COLUMN][DESC][$value] . "</font></b></td>"; }
//    next($USERSHIST_COLUMN_DESC);
     }
if( $num_rows == 0 ) echo "</tr></table>Brak Danych" ; else {

    while ($h=mysql_fetch_row($result)) {
    echo "<TR><TD><font size=-2>";
//    CREATE_MENUFUNC_INIT_2(USERS_HISTORY,HISTORY,$h[$_SESSION[USERS_COLUMN][DESC_TO_KEY][ID]],'HIST') ;
//    echo "<BR>";
//    CREATE_MENUFUNC_INIT_2(USERS_EDIT,EDIT,$h[$_SESSION[USERS_COLUMN][DESC_TO_KEY][ID]],'EDIT') ;
    echo "</TD>";
    foreach ($_SESSION[USERSHIST_COLUMN][ID] as $value) {
    if(!$_SESSION[USERSHIST_COLUMN][HIDE][$value]==HIDE) { 
//      if(!$h[$value]=='N/S;') {
     echo "<TD";
      USERS_COLUMN_COLOR($_SESSION[USERSHIST_COLUMN][DESC][$value],$h[$value],bgcolor);
	echo ">";
       if(!( "$h[$value]" == 'N/S;')) echo "$h[$value]";// . $_SESSION[USERSHIST_COLUMN][DESC][$value];
	echo "</td>";
       } //IF N/S
      } //CZY HIDDEN
     } //FOREACH
 echo "</tr>";
    }  //WHILE_MYSQL
echo "</table>";
 $result = mysql_query($zapSQL,$conn) or die("Blad zapytania2!");
echo "<TABLE border=1 cellspacing=0 cellpadding=0";
 while ($h=mysql_fetch_row($result)) {
//echo "============";
   // echo "<TR><TD><font size=-2>";
   
    echo "</TD><TD><font size=-1>";
    foreach ($_SESSION[USERSHIST_COLUMN][ID] as $value) {
    if(($_SESSION[USERSHIST_COLUMN]) && (!($_SESSION[USERSHIST_COLUMN][DESC][$value]==ID)) && (!($_SESSION[USERSHIST_COLUMN][DESC][$value]==ID_USERS2)) ) { 
//      if(!$h[$value]=='N/S;') {
       if((!( "$h[$value]" == 'N/S;')) && (!($_SESSION[USERSHIST_COLUMN][DESC][$value]==P_SERVICE_QUOTA_PROFILE))) { 
       if($_SESSION[USERS_COLUMN][DESC_TO_LANG][$_SESSION[USERSHIST_COLUMN][DESC][$value]]) echo $_SESSION[USERS_COLUMN][DESC_TO_LANG][$_SESSION[USERSHIST_COLUMN][DESC][$value]] ;  else echo  $_SESSION[USERSHIST_COLUMN][DESC][$value] ;
      echo "<font ";
      USERS_COLUMN_COLOR($_SESSION[USERSHIST_COLUMN][DESC][$value],$h[$value],color);
      echo ">==</font>" . "$h[$value]" . "<BR>"; 

        }
//	echo "</font>";
       } //
      } //
     echo "</td></tr>";
     } //
echo "</table>";

return;
}

