<?php


function L_APPOITMENT_VERIFY() {
global $thiss,$L_APPOINTMENT_VERIFY_USER_SQL_MODE,$L_APPOINTMENT_VERIFY_TELBOX_SQL_MODE,$result,$thiss,$error,$SQL_USER,$SQL_DATABASE,$INTERFACE_ADDR,$SQL_USER_PASS,$MENU_INIT,$CURRENT_MENU,$ARG1,$ARG1_VAL ;



$APP_FIELDS['USERS_COLUMN']['SELECT']="S_ADDRESS_STREET,A_STATUS,A_PROBLEM,L_APPOITMENT_DATE,L_APPOITMENT_TYPE,L_APPOITMENT_PERIOD,L_APPOITMENT_INFO";
$APP_FIELDS['TELBOX_COLUMN']['SELECT']="T_TELBOX_NAME,A_STATUS,A_PROBLEM,L_APPOITMENT_DATE,L_APPOITMENT_TYPE,L_APPOITMENT_PERIOD,L_APPOITMENT_INFO";
$APP_FIELDS['USERS_COLUMN']['SELECT2']= array("S_ADDRESS_STREET,A_STATUS,A_PROBLEM,L_APPOITMENT_DATE,L_APPOITMENT_TYPE,L_APPOITMENT_PERIOD,L_APPOITMENT_INFO","T_TELBOX_NAME,A_STATUS,A_PROBLEM,L_APPOITMENT_DATE,L_APPOITMENT_TYPE,L_APPOITMENT_PERIOD,L_APPOITMENT_INFO");
$APP_FIELDS['GETFIELDS']= array ("L_APPOITMENT_DATE","L_APPOITMENT_PERIOD","L_APPOITMENT_USER");
$APP_FIELDS['TABLES_COLUMN']['COLUMNS']= array ("USERS_COLUMN","TELBOX_COLUMN");
$APP_FIELDS['TABLES_COLUMN']['TABLE']= array ("USERS2","TELBOXES");

  $TEST_IF_NOTHING_CHANGED=true;

 foreach ($APP_FIELDS['GETFIELDS'] as $value) {
$VALUE=$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD'][$value];
if(strlen($_POST[$value])==0) eval(" \$$value = \"$VALUE\" ;"); else eval(" \$$value = \"$_POST[$value]\" ;");
	if($_POST[$value]<>$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD'][$value]) $TEST_IF_NOTHING_CHANGED=false; 
 }

	if($TEST_IF_NOTHING_CHANGED) { 
		echo " No changes in appoitment";
		 return 0;
	 }

 $APP_X=" unix_timestamp(L_APPOITMENT_DATE) " ;
 $APP_Y=" unix_timestamp(L_APPOITMENT_DATE) +  L_APPOITMENT_PERIOD * 60 " ;
 $APP_X1=" unix_timestamp('".$L_APPOITMENT_DATE."') " ;
 $APP_Y1=" unix_timestamp('".$L_APPOITMENT_DATE."') + ".$L_APPOITMENT_PERIOD." * 60 " ;

$i=0;
foreach ($APP_FIELDS['TABLES_COLUMN']['COLUMNS'] as $value) {
$L_APPOINTMENT_VERIFY_TEMP_SQL_MODE="" ;
 if($i==0) {
   $L_APPOINTMENT_VERIFY_TEMP_SQL_MODE="$L_APPOINTMENT_VERIFY_USER_SQL_MODE";
  if(($_SESSION['THIS']['DETECT_TABLE_COLUMN']=='USERS_COLUMN') && ($_SESSION[$_SESSION['THIS']['DETECT_TABLE_COLUMN']]['EDITRECORD']['ID'])) $L_APPOINTMENT_VERIFY_TEMP_SQL_MODE="$L_APPOINTMENT_VERIFY_TEMP_SQL_MODE and ID!='".$_SESSION[$_SESSION['THIS']['DETECT_TABLE_COLUMN']]['EDITRECORD']['ID']."'";
  } else {
  if($i==1) {
   $L_APPOINTMENT_VERIFY_TEMP_SQL_MODE="$L_APPOINTMENT_VERIFY_TELBOX_SQL_MODE"; 
   if(($_SESSION['THIS']['DETECT_TABLE_COLUMN']=='TELBOX_COLUMN') && ($_SESSION[$_SESSION['THIS']['DETECT_TABLE_COLUMN']]['EDITRECORD']['ID'])) $L_APPOINTMENT_VERIFY_TEMP_SQL_MODE="$L_APPOINTMENT_VERIFY_TEMP_SQL_MODE and ID!='".$_SESSION[$_SESSION['THIS']['DETECT_TABLE_COLUMN']]['EDITRECORD']['ID']."'";
  }
 }

 $zapSQL=" select ".$APP_FIELDS['USERS_COLUMN']['SELECT2'][$i]." from ".$APP_FIELDS['TABLES_COLUMN']['TABLE'][$i]." where
 ( ( $APP_X <= $APP_Y1 and  $APP_Y1 <= $APP_Y  ) or (  $APP_X <= $APP_X1 and $APP_X1 <= $APP_Y ) or
 ( $APP_X1 <= $APP_X and $APP_Y1 >= $APP_Y )  ) and
  L_APPOITMENT_TYPE!='' and L_APPOITMENT_USER='$L_APPOITMENT_USER' $L_APPOINTMENT_VERIFY_TEMP_SQL_MODE order by L_APPOITMENT_DATE;";
if($_SESSION[DEBUG]) echo "<hr>Zapytanie do bazy <br> $zapSQL<hr>";
 ZAP_SQL("$zapSQL");
     $j=0;
     while ($h=mysql_fetch_row($result)) {
    $bgcolor->A_STATUS=USERS_COLUMN_COLOR_RETURN(A_STATUS,$h[1], 'bgcolor');
    $bgcolor->A_PROBLEM=USERS_COLUMN_COLOR_RETURN(A_PROBLEM,$h[2], 'bgcolor');
    $bgcolor->L_APPOITMENT_DATE=USERS_COLUMN_COLOR_RETURN(L_APPOITMENT_DATE,$h[3], 'bgcolor');
    $bgcolor->L_APPOITMENT_TYPE=USERS_COLUMN_COLOR_RETURN(L_APPOITMENT_TYPE,$h[4], 'bgcolor');
   $ERROR[$i][$j]="<tr><td>  $h[0] </td><td $bgcolor->A_STATUS> $h[1] </td><td $bgcolor->A_PROBLEM> $h[2] </td><td $bgcolor->L_APPOITMENT_DATE> $h[3] </td><td $bgcolor->L_APPOITMENT_TYPE>$h[4] </td><td> $h[5] </td><td> $h[6] ";
     $j++;
     }
 $i++;
}

if($ERROR) { $error="<table border=1 cellpadding=1 cellspacing=1>";
  if($ERROR[0]) { $error="$error<tr><td colspan=7><b>Konflikty w spotkaniach w tabeli UZYTKOWNIKOW/ABONENTOW:</b></td></tr>";
   foreach ($ERROR[0] as $value) {
    $error="$error $value \n";
   }
  }
  if($ERROR[1]) { $error="$error<tr><td colspan=7><b>Konflikty w spotkaniach w tabeli MAGISTRAL/SZAFEK:</b></td></tr>";
   foreach ($ERROR[1] as $value) {
    $error="$error $value \n";
   }
  }
$error="$error </table>";
 }

//echo "$error";
if($_SESSION[DEBUG]) echo " f.L_APPOITMENT_VERIFY VERIFIED for _P_APD:$_POST[L_APPOITMENT_DATE] _P_APP: $_POST[L_APPOITMENT_PERIOD] _P_APU: $_POST[L_APPOITMENT_USER] *";
}
