<?php


function WIEVTABLE_HIST() {
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 WIEVTABLE_HIST used for wiev ID ".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['WIEVID'] ."Detected column/table is:".$thiss->DETECT_TABLE_COLUMN."/".$thiss->DETECT_TABLE_NAME."*";
print_r($thiss->DETECT_TABLE_NAME);
  }
if(($MENU_INIT==$thiss->DETECT_HIST_FUNCTION) && ($ARG1='HISTORY')) { 
$_SESSION[$thiss->DETECT_TABLE_COLUMN]['WIEVID']="$ARG1_VAL";
 if($_SESSION['DEBUG']) echo "VALUALIZED at $thiss->DETECT_TABLE_COLUMN func _SESSION[$thiss->DETECT_TABLE_COLUMN][WIEVID] = $ARG1_VAL";
 }


SEF("MENU");
MENU();
NAVIGATOR();
TOOLBAR_DETECT();
//CREATE_MENUFUNC_INIT_2($thiss->DETECT_EDIT_FUNCTION,EDIT,$_SESSION[$thiss->DETECT_TABLE_COLUMN][WIEVID],'<img src=icon/edit.gif alt=EDYCJA border=0>');
//echo "<a href=$PHP_SELF?MENU_INIT=
if($_SESSION['DEBUG']) echo "USERS WIEV FUNCTION USED";
if($USERS_FILTER_PROBLEM) USERS_FILTER_PROBLEM();
$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']."' ;";
	if($_SESSION['DEBUG']) echo "<br> ZAP_SQL== $zapSQL <br>" ;
$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[$thiss->DETECT_TABLE_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 "\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>";
//print_r($_SESSION[$thiss->DETECT_TABLE_COLUMN]) ;
    foreach ($_SESSION[$thiss->DETECT_TABLE_COLUMN]['ID'] as $value) {
    if(isset($_SESSION[$thiss->DETECT_TABLE_COLUMN]['HIDE'][$value])) $TST121016['Line47']=$_SESSION[$thiss->DETECT_TABLE_COLUMN]['HIDE'][$value];
    else $TST121016['Line47']="";
    if(!$TST121016['Line47']=='HIDE') { echo "<td><font size='-2'>" ; 


/*
if($_SESSION[$thiss->DETECT_TABLE_COLUMN][SORTED][$_SESSION[$thiss->DETECT_TABLE_COLUMN][DESC][$value]]==PRI) echo "<font color='red'><b>&lt;&lt;&lt;</b></font>";
    CREATE_MENU_NOTD_INIT_2(USERS_SORTER,USERS_SORTER,USERS_SORTER1,$_SESSION[USERS_COLUMN][DESC][$value],'<b>SORTUJ</b>') ; 
//    CREATE_MENU_NOTD_INIT_2(USERS_SORTER,USERS_SORTER,USERS_SORTER1,$USERS_COLUMN_DESC[$value],'/\\') ; 
if($_SESSION[USERS_COLUMN][SORTED][$_SESSION[USERS_COLUMN][DESC][$value]]==SEC) echo "<font color='green'><b>&lt;</b></font>";
    CREATE_MENU_NOTD_INIT_2(USERS_SORTER,USERS_SORTER,USERS_SORTER2,$_SESSION[USERS_COLUMN][DESC][$value],'sortuj') ; 
//    CREATE_MENU_NOTD_INIT_2(USERS_SORTER,USERS_SORTER,USERS_SORTER2,$USERS_COLUMN_DESC[$value],'<b>/\\</b>') ; 
    //CREATE_MENU_NOTD_INIT(USERS_HIDECOLUMN,$USERS_COLUMN[$value],'X') ; 
    CREATE_MENU_NOTD_INIT_3(USERS_COLUMN,$value,HIDE,'X') ;
*/


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(isset($_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[$thiss->DETECT_TABLE_COLUMN]['DESC'][$value] . "</font></b></td>"; }
     }
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[$thiss->DETECT_TABLE_COLUMN]['ID'] as $value) {
    if(!$_SESSION[$thiss->DETECT_TABLE_COLUMN]['HIDE'][$value]=='HIDE') { 
//      if(!$h[$value]=='N/S;') {
     echo "<TD";
      USERS_COLUMN_COLOR($_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC'][$value],$h[$value],'bgcolor');
	echo ">";
       if(!( "$h[$value]" == 'N/S;')) echo "$h[$value]";// . $_SESSION[$thiss->DETECT_TABLE_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[$thiss->DETECT_TABLE_COLUMN]['ID'] as $value) {
    if((!$_SESSION[$thiss->DETECT_TABLE_COLUMN]['HIDE'][$value]=='HIDE') && (!($_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC'][$value]=='ID')) && (!($_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC'][$value]=='ID_USERS2')) ) { 
    echo "<font ";
      USERS_COLUMN_COLOR($_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC'][$value],$h[$value],'color');
  echo ">";
       if((!( "$h[$value]" == 'N/S;')) && (!($_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC'][$value]=='P_SERVICE_QUOTA_PROFILE'))) { 
         echo  $_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC'][$value] . "</font>=" . "$h[$value]" . "<BR>"; 

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

return;
}
