<?php
function USERS() {
global $GETZAPSQL,$thiss,$SQL_USER,$SQL_DATABASE,$INTERFACE_ADDR,$SQL_USER_PASS,$USERS_FILTER_PROBLEM,$USERS_FILTER_STATUS,$SQL_WIEV,$USERS_COLUMN,$USERS_COLUMN_DESC,$USERS_HIDECOLUMN;
if($_SESSION['DEBUG']) { echo "f.USERS"; 
// print_r($USERS_COLUMN);
 }
SEF("MENU");
MENU();
DETECT_TABLE_COLUMN();

//$_SESSION[CURRENT_MENU]=USERS;
if($_SESSION['DEBUG']) echo "USERS WIEV FUNCTION USED";
if($USERS_FILTER_PROBLEM) USERS_FILTER_PROBLEM();
if(!$_SESSION[$thiss->DETECT_TABLE_COLUMN]['SQL_WIEV_CURR_SQL']) 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!");

GETZAPSQL();


//$zapSQL="SELECT * from USERS2  where A_ADM_COMPANY like '$_SESSION[ADM_COMPANY]' $_SESSION[USERS_FILTER_PROBLEM_SQL] $_SESSION[USERS_FILTER_STATUS_SQL] $_SESSION[USERS_FILTER_APPOINTMENT_SQL] " . $_SESSION[USERS_COLUMN][FINDSQL] ." ". $_SESSION[$thiss->DETECT_TABLE_COLUMN][USERS_SORTER_SQL] ." ;";
$zapSQL="SELECT $GETZAPSQL[WHAT_SQL] from $GETZAPSQL[FROM_SQL]  where $GETZAPSQL[WHERE]  ;";
if($_SESSION['DEBUG']) { 
echo "zapSQL is $zapSQL<hr>".$_SESSION['USERS_COLUMN']['FINDSQL']."<hr>";
echo "<hr>GETZAPSQL[SQL] $GETZAPSQL[SQL]<hr>";
 } //EOF GETZAPSQL TESTS

$result = mysql_query($zapSQL,$conn) or die("Blad $zapSQL zapytania2!");
$_SESSION['MYSQL_NUM_ROWS_TOTAL']['USERS'] = mysql_num_rows($result); //TO_REMOVE_VARIABLE TODO
$_SESSION[$thiss->DETECT_TABLE_COLUMN]['MYSQL_NUM_ROWS_TOTAL'] = mysql_num_rows($result);
//$zapSQL="SELECT * from USERS2  where A_ADM_COMPANY like '$_SESSION[ADM_COMPANY]' $_SESSION[USERS_FILTER_PROBLEM_SQL] $_SESSION[USERS_FILTER_STATUS_SQL]  $_SESSION[USERS_FILTER_APPOINTMENT_SQL] " . $_SESSION[USERS_COLUMN][FINDSQL] . " ". $_SESSION[$thiss->DETECT_TABLE_COLUMN][USERS_SORTER_SQL] ."  ".$_SESSION[$thiss->DETECT_TABLE_COLUMN][SQL_WIEV_CURR_SQL]." ;";
$zapSQL="SELECT $GETZAPSQL[WHAT_SQL] from $GETZAPSQL[FROM_SQL]  where $GETZAPSQL[WHERE2]  ;";
//$zapSQL="SELECT * from USERS2  group by S_HWSTAT ;";
if($_SESSION['DEBUG']) echo "<hr>CORRECT_SQL_ZAPYTANIE **/*/* $thiss->DETECT_TABLE_COLUMN $zapSQL **/*";
$result = mysql_query($zapSQL,$conn) or die("Blad zapytania2 $zapSQL!");
$num_rows = mysql_num_rows($result);
$_SESSION['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','<font color=#CC0000>PROBLEMY</b></font>');
CREATE_MENU_INIT('USERS_FILTER_PROBLEM','WARNING','<font color=#CC0000>OSTRZEZENIA</b></font>');
CREATE_MENU_INIT('USERS_FILTER_PROBLEM','NORMAL','<font color=#CC0000>BEZ_PROBLEM.</b></font>');
if($_SESSION['USERS_FILTER_PROBLEM_SQL']) $FILTER_BOLD="<b>*"; else $FILTER_BOLD="";
CREATE_MENU_INIT('USERS_FILTER_PROBLEM','',"<font color=#CC0000>".$FILTER_BOLD."KASUJ-FILTR</b></font>");
CREATE_MENU_INIT('USERS_FILTER_STATUS','WAITING','<font color=#000055><i>OCZEKUJACY</i></font>');
CREATE_MENU_INIT('USERS_FILTER_STATUS','AKTYWNI','<font color=#000055><i>AKTYWNI</i></font>');
if($_SESSION['USERS_FILTER_STATUS_SQL']) $FILTER_BOLD="<b>*"; else $FILTER_BOLD="";
CREATE_MENU_INIT('USERS_FILTER_STATUS','',"<font color=#000055><i>".$FILTER_BOLD."KASUJ-FILTR</b></i></font>");
 CREATE_MENU_INIT('USERS_FILTER_APPOINTMENT','OLD','A_STARE');
CREATE_MENU_INIT('USERS_FILTER_APPOINTMENT','TODAY','APP_DZISIAJ');
if($_SESSION['USERS_FILTER_APPOINTMENT_SQL']) $FILTER_BOLD="<b>*"; else $FILTER_BOLD="";
CREATE_MENU_INIT('USERS_FILTER_APPOINTMENT','',$FILTER_BOLD."APP_ALL</b>");
//CREATE_MENU_INIT(SQL_WIEV,NEXT,NASTEPNE);
//CREATE_MENU_INIT(SQL_WIEV,PREV,POPRZEDNIE);
  CREATE_MENUFUNC_INIT('USERS_COLUMN_MENU','<img src=icon/excel.gif alt=WYBIERZ_KOLUMNY border=0 width=18>');
//CREATE_MENUFUNC_INIT(USERS_COLUMN_MENU,POKAZ_KOLUMNY);
echo "</tr></table>";
NAVIGATOR();
 if(strstr($_SESSION['USERS_COLUMN']['FUNCPERMEDIT']['P_NEW_DEAL'],'RW')) { 
  CREATE_MENUFUNC_INIT_2('USERS_NEWDEAL','NEWDEAL','','<font size=-1>( NOWA_UMOWA<img src=icon/new.gif border=0 alt=NOWA_UMOWA> )</font>') ;
//  echo "NOWA_UMOWA"; 
// if(strstr($_SESSION[USERS_COLUMN][FUNCPERMEDIT][P_NEW_DEAL],'R')) echo "DRUKUJ_UMOWY";

 }


echo'<table width="100%" border="1" cellspacing="0" cellpadding="0" class="tbl-view">';
echo'<thead>';
//echo "\n<table width='100%' border='1' cellspacing='1' cellpadding='0'>";
    echo "<tr><TD><font size=-1>";
    //CREATE_MENU_NOTD_INIT_3(USERS_COLUMN,$value,HIDE,'X') ;
    CREATE_MENU_NOTD_INIT_3('FILTER_SEARCH','MENU_FIND','ENABLE','<img src=icon/search.gif alt=SZUKAJ border=0>');
    echo "</TD>";
    foreach ($GETZAPSQL['ID'] as $value) {
    if(true) { echo "<td><font size='-2'>" ; 
     $ALT=$_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC_TO_LANG'][$GETZAPSQL['WHAT_DESC'][$value]];

if($_SESSION['USERS_COLUMN']['SORTED'][$GETZAPSQL['WHAT_DESC'][$value]]=='PRI')  $border=1; else $border=0; // echo "<font color='red'><img src=icon/sortred.gif width=10 border=0 alt=sortuj></font>";
//echo "$value";
    CREATE_MENU_NOTD_INIT_2('USERS_SORTER','USERS_SORTER','USERS_SORTER1',$GETZAPSQL['WHAT_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']) || ($_SESSION['USERS_SORTER_SQL'])) { //TODO remove second extra cond.
 if($_SESSION['USERS_COLUMN']['SORTED'][$GETZAPSQL['WHAT_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',$GETZAPSQL['WHAT_DESC'][$value],'<img src=icon/sort.gif border='.$border.' alt=sortuj>') ; 
      }
    CREATE_MENU_NOTD_INIT_3('USERS_COLUMN',$_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC_TO_KEY'][$GETZAPSQL['WHAT_DESC'][$value]],'HIDE','<img src=icon/shutdown.gif border=0 alt="WYLACZ_KOLUMNE '.$ALT.'">') ;

     echo "<br><b>" .str_replace('_',' ',$GETZAPSQL['WHAT_DESC'][$value]) . "</font></b></td>";    
     //echo "<br><b>" . $GETZAPSQL[WHAT_DESC][$value] . "</font></b></td>"; 
					 }

     }
     echo "</tr> \n";
//SECOND_ROW
   if($_SESSION['USERS_COLUMN']['MENU_FIND']=='ENABLE') {
    echo "<tr><TD><font size=-2><FORM action='".$_SERVER['PHP_SELF']."' method='POST' name='FILTER_SEARCH'>";
    CREATE_MENU_NOTD_INIT_3('FILTER_SEARCH','MENU_FIND','','X');
    echo "<input type=hidden name=FUNCTION_INIT value=FILTER_SEARCH><input type=submit value=OK>";
    echo "</TD>";
    foreach ($GETZAPSQL['ID'] as $value) {
    if(true) { echo "<td><font size='-2'>" ; 
	GETFORMITEM($_SESSION['USERS_COLUMN']['FIND'][$GETZAPSQL['WHAT_DESC'][$value]],$_SESSION['USERS_COLUMN']['TYPE'][$GETZAPSQL['WHAT_DESC'][$value]],$GETZAPSQL['WHAT_DESC'][$value]);
    echo "</font></b></td>"; 
					 } //EOF if(!$USERS_COLUMN[HIDE][$value]==HIDE)
     } //EOF foreach ($USERS_COLUMN[ID] as $value)
     echo "</tr></form> \n";
  } //EOF  if($_SESSION[USERS_COLUMN][MENU_FIND]==ENABLE)
echo'</thead>';
if( $num_rows == 0 ) echo "</tr></table>Brak Danych" ; else {

//    $USERS_COLUMN = array("0","1","2","3","4");
//    $USERS_COLUMN_DESC = array("JEDEN","DWA","TRZY","CZTERY","PIEC");
//    reset ($USERS_COLUMN);
//    reset ($USERS_COLUMN_DESC);


$t = 0;
echo'<tbody>';
    while ($h=mysql_fetch_row($result)) {
//  echo "$h->S_IP $h->A_STATUS $h->A_PROBLEM<BR>";
		echo '<TR class="row-' . ($t = 1 - $t) . '">';
		echo '<TD align="center">';
//    echo "<TR><TD align=center><font size=+0>";
//     echo $h[$_SESSION[USERS_COLUMN][DESC_TO_KEY][ID]];
    CREATE_MENUFUNC_INIT_2('USERS_HISTORY','HISTORY',$h[$GETZAPSQL['DESC_TO_KEY']['ID']],'<img src=icon/history.gif alt=HISTORIA border=0 width=18>') ;
//echo "&nbsp;|&nbsp; ";
    CREATE_MENUFUNC_INIT_2('USERS_EDIT','EDIT',$h[$GETZAPSQL['DESC_TO_KEY']['ID']],'<img src=icon/edit.gif alt=EDYCJA border=0 width=20>') ;
    echo "</TD>";
//print_r($h);
//print_r($GETZAPSQL['DESC_TO_KEY']['T_NETWORK_SERVER']);
    foreach ($GETZAPSQL['ID'] as $value) {
    if(true) { 
     echo "<TD ";
      USERS_COLUMN_COLOR($GETZAPSQL['WHAT_DESC'][$value],$h[$value], 'bgcolor');
	echo ">";
	echo "$h[$value]";// . $_SESSION[USERS_COLUMN][DESC][$value];
 	echo "</td>";

      }
     }
    echo "</TR>\n";
    }
echo'</tbody>';
   } 
echo "</table>";
return;
}
