<?php

//warunek dla zewnetrznego statusu @2012-10-05 sqix


function USERS_COLUMN_COLOR( $ARG1, $ARG1_VAL, $ARG2, $h=null, $h_what='' ) {
//version 2009-05-28
global $thiss,$GETZAPSQL,$conn ,$A_STATUS_L2_SQL;
if ($_SESSION['DEBUG']) {
	echo "<br>function USERS_COLUMN_COLOR(".$ARG1.",".$ARG1_VAL.",".$ARG2.",".$h.",".$h_what.")<br>\n";
	if ($h) {
		echo "<br>L6: ".$GETZAPSQL['DESC_TO_KEY']['A_PROBLEM']." ==".$h[4]." EOL."; ;
	}
}

/*
if(substr($thiss->DETECT_TABLE_NAME,0,4)=='SES_' && substr($thiss->DETECT_TABLE_NAME,-2)=='_A') { //warunek dla zewnetrznego statusu @2012-10-05 sqix
  if($ARG1=='A_STATUS_CURRENT') {
    	$zap_sql="SELECT ".$A_STATUS_L2_SQL." as A_STATUS from ".$thiss->DETECT_TABLE_NAME." as U 
	  		left join SERVICES as SV on SV.ID=U.ID_SERVICES
	  		where  U.ID='".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDIT_TEMPLATE']['ID']."' ";//szukamy czy jest oznaczony poczatek liczenia abonamentu !!!
	  	    $res_ext=mysql_query($zap_sql);
	  	           while ($r=mysql_fetch_object($res_ext)) {
	  	             $ARG1_VAL=$r->A_STATUS;
	  	           }
  }
}
*/
if ($ARG1 == 'A_PROBLEM_DESC') {
	if ($h) {
		$ZAP_SQL = "select `A_PROBLEM` from ".$thiss->DETECT_TABLE_NAME." where `ID`='".$h[$GETZAPSQL['DESC_TO_KEY']['ID']]."' limit 1 ";
		$RES = mysql_query($ZAP_SQL);
		while ($H = mysql_fetch_array($RES)) {
			USERS_COLUMN_COLOR('A_PROBLEM', $H['A_PROBLEM'], $ARG2, $h, $h_what);
		}
	}
} else if(($ARG1 == 'A_STATUS') || ($ARG1 == 'A_STATUS_CURRENT')|| 
	($ARG1 == 'L2_SERVICE_STATUS') || ($ARG1 == 'L3_SERVICE_STATUS') ) {
 if($ARG1_VAL=='NORMAL') { echo " $ARG2='#88FF88'"; return "$ARG2='#88FF88'"; }
 if($ARG1_VAL=='OFF_SOFT') { echo " $ARG2='#FF9999'"; return "$ARG2='#FF9999'"; }
 if($ARG1_VAL=='DELETED') { echo " $ARG2='#CCCCCC'"; return "$ARG2='#CCCCCC'"; }
 if($ARG1_VAL=='DELETED') { echo " $ARG2='#CCCCCC'"; return "$ARG2='#CCCCCC'"; }
 if($ARG1_VAL=='WARNING') { echo " $ARG2='#FFCCCC'"; return "$ARG2='#FFCCCC'"; }
 if($ARG1_VAL=='OFF_HARD') { echo " $ARG2='#EEEEEE'"; return "$ARG2='#EEEEEE'"; }
 if($ARG1_VAL=='WAITING') { echo " $ARG2='#FF88FF'"; return "$ARG2='#FF88FF'"; }
} else if($ARG1=='A_PROBLEM') {
 if($ARG1_VAL=='WARNING') { echo " $ARG2='#FFFF88'"; return "$ARG2='#FFFF88'"; }
 if($ARG1_VAL=='PROBLEM') { echo " $ARG2='#FFBBBB'"; return "$ARG2='#FFBBBB'"; }
 if($ARG1_VAL=='SERIOUS') { echo " $ARG2='#FF5555'"; return "$ARG2='#FF5555'"; }
 if($ARG1_VAL=='UNVERIFIED') { echo " $ARG2='#FFc57D'"; return "$ARG2='#FFc57D'"; }
} else if($ARG1=='S_HWSTAT') {
 if($ARG1_VAL=='DETECT') echo " $ARG2='#FFFF88'";
 if($ARG1_VAL=='FREE') echo " $ARG2='#FFBBBB'";
 if($ARG1_VAL=='BLOCK') echo " $ARG2='#FF5555'";
 if($ARG1_VAL=='FIXED') echo " $ARG2='#88FF88'";
 if(!$ARG1_VAL) echo " $ARG2='#FF5555'";
} else if($ARG1=='L_APPOITMENT_TYPE') {
 if($ARG1_VAL=='ARRANGED') echo " $ARG2='#FFFF88'";
 if($ARG1_VAL=='TO_ARRANGE') echo " $ARG2='#FF88FF'";
 if($ARG1_VAL=='CANCELLED') echo " $ARG2='#FF5555'";
 if($ARG1_VAL=='TO_CANCEL') echo " $ARG2='#FF55FF'";
 if($ARG1_VAL=='RELATE') echo " $ARG2='#FFBBBB'";
 if($ARG1_VAL=='WAIT') echo " $ARG2='#88FF88'";
 if(!$ARG1_VAL) echo " $ARG2='#FFFFFF'";
}  else if(($ARG1=='L_APPOITMENT_DATE')||($ARG1=='M_DIST_TERM_OF_CLAIM')||($ARG1=='M_DIST_CLAIM_DATE')||($ARG1=='M_DIST_ORDER_DATE')||($ARG1=='M_DIST_DATE')) {
 if((strlen($ARG1_VAL)>5)) {
 $VAR="$ARG1_VAL";
 $VAR = join('-',(explode(':',$VAR)));
 $VAR = join('-',(explode('  ',$VAR)));
 $VAR = join('-',(explode(' ',$VAR)));
 $VAR=explode('-',$VAR);
 if(strlen($VAR[3])==0) $VAR[3]="0";
 if(strlen($VAR[4])==0) $VAR[4]="0";
 $VAR = "$VAR[0]-$VAR[1]-$VAR[2] $VAR[3]:$VAR[4]";
  $CTIME = time();
  if (!(($VAR = strtotime($VAR)) === -1)) {
   if($VAR > $CTIME) {
    if(($VAR - $CTIME) < 7200) echo " $ARG2='#FFFF88'"; 
    else if(($VAR - $CTIME) < 12200)  echo " $ARG2='#D5FF88'"; 
    else if(($VAR - $CTIME) < 43200)  echo " $ARG2='#C2FF88'"; 
    else if(($VAR - $CTIME) < 86400)  echo " $ARG2='#8CFF88'"; //1 dzien
    else if(($VAR - $CTIME) < 172800)  echo " $ARG2='#77FF88'";  //2 dni
    else if(($VAR - $CTIME) < 604800)  echo " $ARG2='#00FF00'"; 
      else echo " $ARG2='#BFC290'"; 
   } else if($VAR < $CTIME) {
    if(($CTIME - $VAR) < 3600) echo " $ARG2='red'";
    else if(($CTIME - $VAR) < 6200) echo " $ARG2='#FF4444'";
    else if(($CTIME - $VAR) < 8200) echo " $ARG2='#FF5555'";
    else if(($CTIME - $VAR) < 10200) echo " $ARG2='#FF6666'";
    else if(($CTIME - $VAR) < 14200) echo " $ARG2='#FF7777'";
    else if(($CTIME - $VAR) < 18200) echo " $ARG2='#FF7777'";
    else if(($CTIME - $VAR) < 28200) echo " $ARG2='#FF8888'";
    else if(($CTIME - $VAR) < 43200) echo " $ARG2='#FF9999'";
    else echo " $ARG2='cyan'";
   }
  }
 } //EOF strlen(ARG1_VAL>5)
} //EOF L_APPOINTMEND_DATE
else if($ARG1=='A_PROBLEM_DATE') {
 if(strlen($ARG1_VAL)>5 && $ARG1_VAL!="0000-00-00 00:00:00") {
 $VAR="$ARG1_VAL";
 $VAR = join('-',(explode(':',$VAR)));
 $VAR = join('-',(explode('  ',$VAR)));
 $VAR = join('-',(explode(' ',$VAR)));
 $VAR=explode('-',$VAR);
 if(strlen($VAR[3])==0) $VAR[3]="0";
 if(strlen($VAR[4])==0) $VAR[4]="0";
 $VAR = "$VAR[0]-$VAR[1]-$VAR[2] $VAR[3]:$VAR[4]";
  $CTIME = time();
  if (!(($VAR = strtotime($VAR)) === -1)) {
   if($VAR > $CTIME) {
    if(($VAR - $CTIME) < 7200) echo " $ARG2='#FFFF88'"; 
    else if(($VAR - $CTIME) < 12200)  echo " $ARG2='#D5FF88'"; 
    else if(($VAR - $CTIME) < 43200)  echo " $ARG2='#C2FF88'"; 
    else if(($VAR - $CTIME) < 86400)  echo " $ARG2='#8CFF88'"; //1 dzien
    else if(($VAR - $CTIME) < 172800)  echo " $ARG2='#77FF88'";  //2 dni
    else if(($VAR - $CTIME) < 604800)  echo " $ARG2='#00FF00'"; 
    else echo " $ARG2='#BFC290'"; 
   } else if($VAR < $CTIME) {

    $TIME_COLOR['START']['TIME']=0;
    $TIME_COLOR['STOP']['TIME']=211040;
    if(($CTIME - $VAR) < $TIME_COLOR['STOP']['TIME']) {
     $TIME_COLOR['START']['R']=00;
     $TIME_COLOR['START']['G']=255;
     $TIME_COLOR['START']['B']=00;
     $TIME_COLOR['STOP']['R']=255;
     $TIME_COLOR['STOP']['G']=255;
     $TIME_COLOR['STOP']['B']=00;
     $TIME_COLOR['PERCENT'] = ($CTIME - $VAR - $TIME_COLOR['START']['TIME'] ) / $TIME_COLOR['STOP']['TIME'] ; 
     $TIME_COLOR['CURR']['R'] = $TIME_COLOR['STOP']['R']=255 * $TIME_COLOR['PERCENT'] ;
     $TIME_COLOR['CURR']['R'] = dechex(ceil($TIME_COLOR['CURR']['R']));
     if(strlen($TIME_COLOR['CURR']['R'])==1) $TIME_COLOR['CURR']['R']="0".$TIME_COLOR['CURR']['R'];
     echo " $ARG2='".$TIME_COLOR['CURR']['R']."FF00'";
    } else if(($CTIME - $VAR) < 822080) {
     $TIME_COLOR['START']['TIME']=211040;
     $TIME_COLOR['STOP']['TIME']=822080;
     $TIME_COLOR['START']['R']=255;
     $TIME_COLOR['START']['G']=255;
     $TIME_COLOR['START']['B']=00;
     $TIME_COLOR['STOP']['R']=255;
     $TIME_COLOR['STOP']['G']=00;
     $TIME_COLOR['STOP']['B']=00;
     $TIME_COLOR['PERCENT'] = ($CTIME - $VAR - $TIME_COLOR['START']['TIME'] ) / $TIME_COLOR['STOP']['TIME']  ;
     $TIME_COLOR['CURR']['R'] = 255 - ( $TIME_COLOR['STOP']['R'] * $TIME_COLOR['PERCENT'] ) ;
     $TIME_COLOR['CURR']['R'] = dechex(ceil($TIME_COLOR['CURR']['R']));
     if(strlen($TIME_COLOR['CURR']['R'])==1) $TIME_COLOR['CURR']['R']="0".$TIME_COLOR['CURR']['R'];
     echo "$ARG2='#FF".$TIME_COLOR['CURR']['R']."00'";
    }
    else if(($CTIME - $VAR) < 22118400) echo " $ARG2='red'";

    else echo " $ARG2='red'";
   }
  }
 } //EOF strlen(ARG1_VAL>5)
}
}
