Skip to content

Instantly share code, notes, and snippets.

@apipkin
Forked from anonymous/PM
Created January 25, 2010 15:33
Show Gist options
  • Save apipkin/285938 to your computer and use it in GitHub Desktop.
Save apipkin/285938 to your computer and use it in GitHub Desktop.
<?php
define("XMLAPI","1");
include("common.php");
defp();
connect();
auth();
$id=$user_id;
$aaid=intval($_REQUEST[aaid]);
$id=$user_id;
$aaid=intval($_REQUEST[aaid]);
//Below Used to get Vehicle History
$vin=$_REQUEST[vin];
//Below are the parameters to calculate the mileage range
$Interval=15000; ////HARD CODED FOR LEGACY
$bracket=15000; ////HARD CODED FOR LEGACY
$milespermo=intval($_REQUEST[mpmo]);
$NonMi=1;
///Below sets a variable if there is an interval sent
If( $Interval>0):
$All=1;
endif;
//Above VAR NonMi=1 is Requesting all those random "send when Light on, etc. Items are sent///
///Validate Miles Per Month
IF( $milespermo<10):
$milespermo=1000;
endif;
///Set DEFAULT=1000Miles Per Month (Per MFR usual Listing///
$BASE_sql="SELECT DISTINCT a.RecNo as recno ,a.AAIA_ID as aaid1,a.MODEL as model,
frall.FREQ_ITEM_ID as freq_item_id,frall.Freq_text as freq_text,
it.CODE as itemcode,it.Item as item,
act.CODE as actioncode ,act.ACTION as action ,
fr.CODE as frcode ,fr.Freq as freq,
a.INTMo as intmo,a.INTMi as intmi,a.INTKm as intkm, a.ITXX_RT_ID as ITXX_RT_ID, P07.RT_Name as RT_Name,P07.Category_ID_FK as CatID,
l.LUBE as lube,
l.AAIA_ID as aaid2,
ab.Abbreviation as abbr,ab.Definition as abdef,
l.QUAL as qual,
l.EQUIV as equiv,
l.OEPARTNOSPECNUMBER as oe_part,
l.DESCRIPTION as descr,
nl1.Code as lncode1,nl1.Note as lnot1,
nl2.Code as lncode2,nl2.Note as lnot2,
w.CODE as wcode ,w.Description as wdescr,
a.Ss as ss,
n2.Code as ncode1 ,n2.Note as not1,
n3.Code as ncode2 ,n3.Note as not2,
a.PROD_DATE as date1
from (P11_PM_ALL AS a
left join P07_Repair_Type as P07 on a.ITXX_RT_ID=P07.RT_ID_PK
left join P13_ITXX_FREQ_ALL as frall on a.FREQ_Text_ID_fk=frall.FREQ_ITEM_ID
left join P04_FREQ as fr on a.FREQ=fr.CODE
left join P06_KEY as l on ( a.aaia_id=l.aaia_id and a.lube=l.lube and a.ITEM=l.Unit )
left join P05_ITEM as it on a.ITEM=it.CODE
left join P02_ACTION as act on a.ACTION=act.CODE
left join P12_WARRANTY as w on a.W=w.CODE
left join P10_NOTE_PM as n2 on a.NOT1=n2.Code
left join P10_NOTE_PM as n3 on a.NOT1=n3.Code
)
left join X_ABBR as ab on l.UNIT=ab.Abbreviation
left join Q21_NOTE as nl1 on l.NOT1=nl1.Code
left join Q21_NOTE as nl2 on l.NOT2=nl2.Code ";
header("Content-type: application/xml");
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
getvalidaccess("PM",$id);
if(!$aaid)
{
echo " <PMDataResponse> <ErrorResponse>
<ErrorCode>110</ErrorCode>
<ErrorMessage>Invalid Request .Parameter not present. Required: aaid</ErrorMessage>
</ErrorResponse>
</PMDataResponse>";
exit;
}
$ss=sprintf( "%1s", $_REQUEST['SS']);
if($ss=="N"):
$ssSQL =" and a.SS='N' ";
elseif($ss=="Y"):
$ssSQL=" and a.SS='Y' ";
else:
$ssSQL='';
endif;
////TEMP HARD CODE - ABOVE NOT INCLUDED IN SQL CALL!!!!
//???TOP OF XML PAGE///
//???TOP OF XML PAGE///
//???TOP OF XML PAGE///
//???TOP OF XML PAGE///
echo "<PMDataResponse><CheckChartPM>";
////START FIRST NODE=> Lube
////START FIRST NODE=> Lube
////START FIRST NODE=> Lube
////START FIRST NODE=> Lube
echo "\n<Lube>";
$RT_Category=1;
$q=$BASE_sql."Where a.AAIA_ID = $aaid and P07.Category_ID_FK=".$RT_Category.$ssSQL;
///SQL for RO data
/////Below is a Static Test SQL Statement to test connection & Return
$rodbsql="SELECT * FROM `crm_vehicles` WHERE veh_id=14;";
////$rodbsql="SELECT * FROM `crm_vehicles` WHERE `veh_vin` LIKE '".$vin."';";
///Below is the Connection for the RO Data (1 of 2)
$c2=mysql_connect($mosConfig_host,$mosConfig_user,$mosConfig_password,true);
/// test for connection 2 added - JK
$lin=mysql_connect($mosConfig_host,$mosConfig_user,$mosConfig_password,true);
if(!mysql_select_db("Chek_Chart",$lin) OR !mysql_select_db("livedb",$c2)){
echo "<Error>DB connection $mosConfig_host $mosConfig_user $mosConfig_pass</Error>";
exit;
}
$f=mysql_query($q,$lin);
if(mysql_error($lin)){
echo "<Error>".mysql_error($lin).mysql_error($c2)."</Error>";
//OutputXML("ErrorResponse",1000);
exit;
}
$found=false;
while($row=mysql_fetch_assoc($f)){
//for($i=0;$i<count($rows);$i++){
//$row=$rows[$i];
foreach($row as $a=>$item){
$row[$a]=htmlspecialchars($item);
}
extract($row,EXTR_OVERWRITE);
if($ncode1==$ncode2)
$not2="";
if($lcode1==$lcode2)
$lnot2="";
//// $Interval is set above SQL Call
If( $intmi==0 ):
$Freq_Text2= $intmo.' Months';
///Assume $intmi < $Interval below
elseif (($Interval % $intmi)==0): ///Second Criteria
$Freq_Text2= $Interval.' Miles';
elseif (($Interval % $intmi)>0 AND ($bracket+$Interval)>( (floor($Interval/$intmi)* $intmi)+$intmi) ): ///Third Criteria
////EX: Interval=30K, intmi=7K, $bracket=15K
////30,000 % 7,000 IS 1999 OR >0 and 30,000 > (floor of 30/7=4) 4*7,000=28,000 + 7,000= 35,000 (< 30,000+15,000)
$Freq_Text2= ( (floor($Interval/$intmi)* $intmi)+$intmi).' Miles';
else: ////(($Interval % $intmi)>0 AND ($bracket+$Interval)<( (floor($Interval/$intmi)* $intmi)+$intmi) ): ///Third Criteria
////EX: Interval=30K, intmi=7K, $bracket=15K
////30,000 % 7,000 IS 1999 OR >0 and 30,000 > (floor of 30/7=4) 4*7,000=28,000 + 7,000= 35,000 (< 30,000+15,000)
$Freq_Text2= 'ERROR - Item Should NOT Be Displayed';
endif;
///Allowance for Mo Only Values using above Mi Per Month Variable
$intmi2=$intmi*$Repeat;
////Begin RO History CODE is code for RO History
$roq=mysql_query($rodbsql,$c2);//Send the Query
$rodbrecs="<RO_Recs>";
while($row=mysql_fetch_assoc($roq))
{
///Make the Record
////SELECT `veh_last_service` as `lastservice`,roaaia `date_added` as `dateadded`,`veh_id`,`shop_id`
$rodbrecord="<Ro_Rec><DateAdded>$dateadded</DateAdded><veh_id>$veh_id</veh_id><roaaia>$roaaia</roaaia></Ro_Rec>";
$rodbrecs.=$rodbrecord;//append here
}
$rodbrecs.="</RO_Recs>"; //close the master
$Diagnostic="<Diagnostic><Resource>".$roq."</Resource><IsResource>".is_resource($roq)."</IsResource><RType>".get_resource_type($roq)."</RType><Query>".$rodbsql."</Query><VIN>".$vin."</VIN></Diagnostic>";
///<MySQL_ErrorType>".mysql_errno($roq)."</MySQL_ErrorType>
//////<1Query>".htmlspecialchars($roq)."</1Query>
///END RO HISTORY CODE
echo<<<dtt
\n<Record rid="$recno">\n<AAIA_ID>$aaid1</AAIA_ID>\n\n<Model>$model</Model>\n\n<ITXX_RT_ID>$ITXX_RT_ID</ITXX_RT_ID>\n\n<CatID>$CatID</CatID>\n\n\n<Action>$action</Action>\n<Item code="$itemcode">$item</Item>\n<Frequency code="$frcode">$freq</Frequency>\n<Freq_Desc>$freq_text</Freq_Desc>\n<INTMi>$intmi</INTMi>\n<INTKm>$intkm</INTKm>\n<INTMo>$intmo</INTMo>\n<SS>$ss</SS>\n<Lube value="$lube">\n<UNIT>$abdef</UNIT>\n<EQUIV>$equiv</EQUIV>\n<QUAL>$qual</QUAL>\n<OE_PART_NO>$oe_part</OE_PART_NO>\n<DESCRIPTION>$descr</DESCRIPTION>\n<LubeNotes>\n<Note1 code="$lcode1">$lnot1</Note1>\n<Note2 code="$lcode2">$lnot2</Note2></LubeNotes></Lube>\n<Warranty>$wdescr</Warranty>\n<Notes>\n<Note1 code="$ncode1">$not1</Note1>\n<Note2 code="$ncode2">$not2</Note2></Notes>\n<Date>$date1</Date>$rodbrecs.$Diagnostic</Record>
dtt;
$found=true;
}
//END of IF STATEMENT ABOVE
////END OF LUBE NODE #1
echo "\n</Lube>";
///////END OF LUBE NODE
////START SECOND NODE=> INSPECT
////START SECOND NODE=> INSPECT
////START SECOND NODE=> INSPECT
////START SECOND NODE=> INSPECT
echo "\n<Inspect>";
$RT_Category=2;
$q=$BASE_sql."Where a.AAIA_ID = $aaid and P07.Category_ID_FK=".$RT_Category.$ssSQL;
$lin=mysql_connect($mosConfig_host,$mosConfig_user,$mosConfig_password,true);
if(!mysql_select_db("Chek_Chart",$lin)){
echo "<Error>DB connection $mosConfig_host $mosConfig_user $mosConfig_pass</Error>";
exit;
}
$f=mysql_query($q,$lin);
if(mysql_error($lin)){
echo "<Error>".mysql_error($lin)."</Error>";
//OutputXML("ErrorResponse",1000);
exit;
}
$found=false;
while($row=mysql_fetch_assoc($f)){
//for($i=0;$i<count($rows);$i++){
//$row=$rows[$i];
foreach($row as $a=>$item){
$row[$a]=htmlspecialchars($item);
}
extract($row,EXTR_OVERWRITE);
if($ncode1==$ncode2)
$not2="";
if($lcode1==$lcode2)
$lnot2="";
//// $Interval is set above SQL Call
If( $intmi==0 ):
$Freq_Text2= $intmo.' Months';
///Assume $intmi < $Interval below
elseif (($Interval % $intmi)==0): ///Second Criteria
$Freq_Text2= $Interval.' Miles';
elseif (($Interval % $intmi)>0 AND ($bracket+$Interval)>( (floor($Interval/$intmi)* $intmi)+$intmi) ): ///Third Criteria
////EX: Interval=30K, intmi=7K, $bracket=15K
////30,000 % 7,000 IS 1999 OR >0 and 30,000 > (floor of 30/7=4) 4*7,000=28,000 + 7,000= 35,000 (< 30,000+15,000)
$Freq_Text2= ( (floor($Interval/$intmi)* $intmi)+$intmi).' Miles';
else: ////(($Interval % $intmi)>0 AND ($bracket+$Interval)<( (floor($Interval/$intmi)* $intmi)+$intmi) ): ///Third Criteria
////EX: Interval=30K, intmi=7K, $bracket=15K
////30,000 % 7,000 IS 1999 OR >0 and 30,000 > (floor of 30/7=4) 4*7,000=28,000 + 7,000= 35,000 (< 30,000+15,000)
$Freq_Text2= 'ERROR - Item Should NOT Be Displayed';
endif;
///Allowance for Mo Only Values using above Mi Per Month Variable
$NewRecNo=($recno+($Interval*10));
$intmi2=$intmi*$Repeat;
echo<<<dtt
\n<Record rid="$recno">\n<AAIA_ID>$aaid1</AAIA_ID>\n\n<Model>$model</Model>\n\n<ITXX_RT_ID>$ITXX_RT_ID</ITXX_RT_ID>\n\n<CatID>$CatID</CatID>\n\n\n<Action>$action</Action>\n<Item code="$itemcode">$item</Item>\n<Frequency code="$frcode">$freq</Frequency>\n<Freq_Desc>$freq_text</Freq_Desc>\n<INTMi>$intmi</INTMi>\n<INTKm>$intkm</INTKm>\n<INTMo>$intmo</INTMo>\n<SS>$ss</SS>\n<Lube value="$lube">\n<UNIT>$abdef</UNIT>\n<EQUIV>$equiv</EQUIV>\n<QUAL>$qual</QUAL>\n<OE_PART_NO>$oe_part</OE_PART_NO>\n<DESCRIPTION>$descr</DESCRIPTION>\n<LubeNotes>\n<Note1 code="$lcode1">$lnot1</Note1>\n<Note2 code="$lcode2">$lnot2</Note2></LubeNotes></Lube>\n<Warranty>$wdescr</Warranty>\n<Notes>\n<Note1 code="$ncode1">$not1</Note1>\n<Note2 code="$ncode2">$not2</Note2></Notes>\n<Date>$date1</Date></Record>
dtt;
$found=true;
}
//END of IF STATEMENT ABOVE
echo "\n</Inspect>";
/////////END INSPECT NODE
/////////END INSPECT NODE
/////////END INSPECT NODE
/////////END INSPECT NODE
/////////END INSPECT NODE
////START OTHER #3 NODE
////START OTHER #3 NODE
////START OTHER #3 NODE
////START OTHER #3 NODE
echo "\n<Other_Items>";
$RT_Category='>2';
$q=$BASE_sql."Where a.AAIA_ID = $aaid and P07.Category_ID_FK<>2 and P07.Category_ID_FK<>1".$ssSQL." ORDER BY a.intmi";
$lin=mysql_connect($mosConfig_host,$mosConfig_user,$mosConfig_password,true);
if(!mysql_select_db("Chek_Chart",$lin)){
echo "<Error>DB connection $mosConfig_host $mosConfig_user $mosConfig_pass</Error>";
exit;
}
$f=mysql_query($q,$lin);
if(mysql_error($lin)){
echo "<Error>".mysql_error($lin)."</Error>";
//OutputXML("ErrorResponse",1000);
exit;
}
$found=false;
while($row=mysql_fetch_assoc($f)){
//for($i=0;$i<count($rows);$i++){
//$row=$rows[$i];
foreach($row as $a=>$item){
$row[$a]=htmlspecialchars($item);
}
extract($row,EXTR_OVERWRITE);
if($ncode1==$ncode2)
$not2="";
if($lcode1==$lcode2)
$lnot2="";
//// $Interval is set above SQL Call
If( $intmi==0 ):
$Freq_Text2= $intmo.' Months';
///Assume $intmi < $Interval below
elseif (($Interval % $intmi)==0): ///Second Criteria
$Freq_Text2= $Interval.' Miles';
elseif (($Interval % $intmi)>0 AND ($bracket+$Interval)>( (floor($Interval/$intmi)* $intmi)+$intmi) ): ///Third Criteria
////EX: Interval=30K, intmi=7K, $bracket=15K
////30,000 % 7,000 IS 1999 OR >0 and 30,000 > (floor of 30/7=4) 4*7,000=28,000 + 7,000= 35,000 (< 30,000+15,000)
$Freq_Text2= ( (floor($Interval/$intmi)* $intmi)+$intmi).' Miles';
else: ////(($Interval % $intmi)>0 AND ($bracket+$Interval)<( (floor($Interval/$intmi)* $intmi)+$intmi) ): ///Third Criteria
////EX: Interval=30K, intmi=7K, $bracket=15K
////30,000 % 7,000 IS 1999 OR >0 and 30,000 > (floor of 30/7=4) 4*7,000=28,000 + 7,000= 35,000 (< 30,000+15,000)
$Freq_Text2= 'ERROR - Item Should NOT Be Displayed';
endif;
$intmi2=$intmi*$Repeat;
echo<<<dtt
\n<Record rid="$recno">\n<AAIA_ID>$aaid1</AAIA_ID>\n\n<Model>$model</Model>\n\n<ITXX_RT_ID>$ITXX_RT_ID</ITXX_RT_ID>\n\n<CatID>$CatID</CatID>\n\n\n<Action>$action</Action>\n<Item code="$itemcode">$item</Item>\n<Frequency code="$frcode">$freq</Frequency>\n<Freq_Desc>$freq_text</Freq_Desc>\n<INTMi>$intmi</INTMi>\n<INTKm>$intkm</INTKm>\n<INTMo>$intmo</INTMo>\n<SS>$ss</SS>\n<Lube value="$lube">\n<UNIT>$abdef</UNIT>\n<EQUIV>$equiv</EQUIV>\n<QUAL>$qual</QUAL>\n<OE_PART_NO>$oe_part</OE_PART_NO>\n<DESCRIPTION>$descr</DESCRIPTION>\n<LubeNotes>\n<Note1 code="$lcode1">$lnot1</Note1>\n<Note2 code="$lcode2">$lnot2</Note2></LubeNotes></Lube>\n<Warranty>$wdescr</Warranty>\n<Notes>\n<Note1 code="$ncode1">$not1</Note1>\n<Note2 code="$ncode2">$not2</Note2></Notes>\n<Date>$date1</Date></Record>
dtt;
$found=true;
}
//END of IF STATEMENT ABOVE
echo "\n</Other_Items>";
/////////END OTHER #3 NODE
/////////END OTHER #3 NODE
/////////END OTHER #3 NODE
/////////END OTHER #3 NODE
/////////END OTHER #3 NODE
/*
if(!$found){
echo "<ErrorCode>205</ErrorCode><ErrorMessage>No Data Present</ErrorMessage>";
}
*/
///IF ($All=1):
///$counter=$counter+1;
///else:
///$counter=10000000; ///This killes the loop for those where it's not all
///endif;
///} ///END OF LOOP///
echo "</CheckChartPM></PMDataResponse>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment