<?php


function L_APPOITMENT_RESULT( $QUERY ) {
global $result,$thiss,$error,$SQL_DATABASE,$INTERFACE_ADDR,$SQL_USER_PASS,$SQL_USER,$MENU_INIT,$CURRENT_MENU,$ARG1,$ARG1_VAL ;
$APP_FIELDS['FIELDS'][0]= array("ID","ADRES","A_STATUS","A_PROBLEM","INFO","A_PROBLEM_DATE","APP_U","L_APPOITMENT_DATE","APP_P","APP_I","L_APPOITMENT_TYPE","A_ADM_COMPANY","T_NETWORK_SERVER");
$APP_FIELDS['FIELDS'][1]= array("ID","S_ADDRESS_STREET","A_STATUS","A_PROBLEM","A_STATUS_INFO","P_DEAL_DATE","L_APPOITMENT_USER","L_APPOITMENT_DATE","L_APPOITMENT_PERIOD","L_APPOITMENT_INFO","L_APPOITMENT_TYPE","A_ADM_COMPANY","T_NETWORK_SERVER");
$APP_FIELDS['FIELDS'][2]= array("ID","S_ADDRESS_STREET","A_STATUS","A_PROBLEM","A_PROBLEM_DESC","A_PROBLEM_DATE","L_APPOITMENT_USER","L_APPOITMENT_DATE","L_APPOITMENT_PERIOD","L_APPOITMENT_INFO","L_APPOITMENT_TYPE","A_ADM_COMPANY","T_NETWORK_SERVER");
$APP_FIELDS['FIELDS'][3]= array("ID","T_TELBOX_NAME","A_STATUS","A_PROBLEM","A_PROBLEM_DESC","A_PROBLEM_DATE","L_APPOITMENT_USER","L_APPOITMENT_DATE","L_APPOITMENT_PERIOD","L_APPOITMENT_INFO","L_APPOITMENT_TYPE","A_ADM_COMPANY","T_NETWORK_SERVER");
$APP_FIELDS['FIELDS'][4]= array("ID","S_ADDRESS_STREET","''","A_PROBLEM","A_PROBLEM_DESC","A_PROBLEM_DATE","L_APPOITMENT_USER","L_APPOITMENT_DATE","L_APPOITMENT_PERIOD","L_APPOITMENT_INFO","L_APPOITMENT_TYPE","''","M_REWIR");
$APP_FIELDS['DESC']= array("TABELA","DESC","S_ADDRESS_STREET","A_STATUS","A_PROBLEM","A_PROBLEM_DESC","A_PROBLEM_DATE","L_APPOITMENT_USER","L_APPOITMENT_DATE","L_APPOITMENT_PERIOD","L_APPOITMENT_INFO","L_APPOITMENT_TYPE","A_ADM_COMPANY","T_NETWORK_SERVER");
$APP_FIELDS[4]['SELECT']=" $QUERY ";
$APP_FIELDS[5]['SELECT']=" DROP TABLE tmp ";

 $APP_FIELDS[0]['SELECT']=" CREATE TEMPORARY TABLE tmp ( TABELA char(10), OPIS char(240)";
 foreach ($APP_FIELDS['FIELDS'][0] as $field) {
  $APP_FIELDS[0]['SELECT']=$APP_FIELDS[0]['SELECT'].", $field char(240)";
 }
 $APP_FIELDS[0]['SELECT']=$APP_FIELDS[0]['SELECT']." )";

$APP_FIELDS['F'][1]['SELECT']=" INSERT INTO tmp ( TABELA,OPIS";
$APP_FIELDS['V'][1]['SELECT']=" select  'USERS2','INSTALACJE'";
 foreach ($APP_FIELDS['FIELDS'][0] as $field) {
  $APP_FIELDS['F'][1]['SELECT']=$APP_FIELDS['F'][1]['SELECT'].",$field"; }
 foreach ($APP_FIELDS['FIELDS'][1] as $field) {
  $APP_FIELDS['V'][1]['SELECT']=$APP_FIELDS['V'][1]['SELECT'].",$field"; }
 $APP_FIELDS[1]['SELECT']=$APP_FIELDS['F'][1]['SELECT']." ) ".$APP_FIELDS['V'][1]['SELECT']." from USERS2 where A_ADM_COMPANY like '".$_SESSION['ADM_COMPANY']."' and L_APPOITMENT_TYPE!='' and A_STATUS='WAITING'  ";

$APP_FIELDS['F'][1]['SELECT']=" INSERT INTO tmp ( TABELA,OPIS";
$APP_FIELDS['V'][1]['SELECT']=" select  'USERS2','SERWISY'";
 foreach ($APP_FIELDS['FIELDS'][0] as $field) {
  $APP_FIELDS['F'][1]['SELECT']=$APP_FIELDS['F'][1]['SELECT'].",$field"; }
 foreach ($APP_FIELDS['FIELDS'][2] as $field) {
  $APP_FIELDS['V'][1]['SELECT']=$APP_FIELDS['V'][1]['SELECT'].",$field"; }
 $APP_FIELDS[2]['SELECT']=$APP_FIELDS['F'][1]['SELECT']." ) ".$APP_FIELDS['V'][1]['SELECT']." from USERS2 where A_ADM_COMPANY like '".$_SESSION['ADM_COMPANY']."' and L_APPOITMENT_TYPE!='' and A_STATUS!='WAITING' and A_PROBLEM!='' ";

$APP_FIELDS['F'][1]['SELECT']=" INSERT INTO tmp ( TABELA,OPIS";
$APP_FIELDS['V'][1]['SELECT']=" select  'TELBOXES','MAGISTRALE'";
 foreach ($APP_FIELDS['FIELDS'][0] as $field) {
  $APP_FIELDS['F'][1]['SELECT']=$APP_FIELDS['F'][1]['SELECT'].",$field"; }
 foreach ($APP_FIELDS['FIELDS'][3] as $field) {
  $APP_FIELDS['V'][1]['SELECT']=$APP_FIELDS['V'][1]['SELECT'].",$field"; }
 $APP_FIELDS[3]['SELECT']=$APP_FIELDS['F'][1]['SELECT']." ) ".$APP_FIELDS['V'][1]['SELECT']." from TELBOXES where A_ADM_COMPANY like '".$_SESSION['ADM_COMPANY']."' and L_APPOITMENT_TYPE!='' and A_PROBLEM!='' ";

//USERS2_MARKETING

$APP_FIELDS['F'][1]['SELECT']=" INSERT INTO tmp ( TABELA,OPIS";
$APP_FIELDS['V'][1]['SELECT']=" select  'USERS2_MARKETING','MARKETING'";
 foreach ($APP_FIELDS['FIELDS'][0] as $field) {
  $APP_FIELDS['F'][1]['SELECT']=$APP_FIELDS['F'][1]['SELECT'].",$field"; }
 foreach ($APP_FIELDS['FIELDS'][4] as $field) {
  $APP_FIELDS['V'][1]['SELECT']=$APP_FIELDS['V'][1]['SELECT'].",$field"; }
 $APP_FIELDS[6]['SELECT']=$APP_FIELDS['F'][1]['SELECT']." ) ".$APP_FIELDS['V'][1]['SELECT']." from USERS2_MARKETING where L_APPOITMENT_TYPE!=''  ";
 //TODO2007-07-10 - dodac  A_ADM_COMPANY like '".$_SESSION[ADM_COMPANY]."' and




$conn=mysql_connect($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!");
//echo $APP_FIELDS[2]['SELECT'];

mysql_query($APP_FIELDS[0]['SELECT'],$conn) or die("Blad zapytania0 ".$APP_FIELDS[0]['SELECT']." ZAP_SQL *$zapSQL*!");
mysql_query($APP_FIELDS[1]['SELECT'],$conn) or die("Blad zapytania1 ".$APP_FIELDS[1]['SELECT']." ZAP_SQL *$zapSQL*!");
mysql_query($APP_FIELDS[2]['SELECT'],$conn) or die("Blad zapytania2 ".$APP_FIELDS[2]['SELECT']." ZAP_SQL *$zapSQL*!");
mysql_query($APP_FIELDS[3]['SELECT'],$conn) or die("Blad zapytania3 ".$APP_FIELDS[3]['SELECT']." ZAP_SQL *$zapSQL*!");
mysql_query($APP_FIELDS[6]['SELECT'],$conn) or die("Blad zapytania3 ".$APP_FIELDS[6]['SELECT']." ZAP_SQL *$zapSQL*!");
$result = mysql_query($APP_FIELDS[4]['SELECT'],$conn) or die("Blad zapytania4 ".$APP_FIELDS[4]['SELECT']." ZAP_SQL *$zapSQL*!");
mysql_query($APP_FIELDS[5]['SELECT'],$conn) or die("Blad zapytania5 ".$APP_FIELDS[5]['SELECT']." ZAP_SQL *$zapSQL*!");
//mysql_free_result ($result); 

//print_r($_SESSION);

}


?>
