????
????????DataFeed?Diff
????????
????
????
????if?($_SERVER['REQUEST_METHOD']?!=?'POST'):??>
????????DataFeed?Diff
????????See?what's?changed?between?two?datafeeds.?Upload?two?datafeeds?from?ShareASale,?and?this?script?will?tell?you?the?added,?changed?and?removed?items.
????????
????else:
????????if?(!isset($_FILES['old_feed'])?OR?!isset($_FILES['new_feed']))?{
????????????print_error?('Please?upload?two?datafeeds.');
????????}
????????if?($_FILES['old_feed']['error']?!=?UPLOAD_ERR_OK?OR?$_FILES['new_feed']['error']?!=?UPLOAD_ERR_OK)?{
????????????print_error?('Please?upload?two?datafeeds.');
????????}
????????$one?=?file_get_contents($_FILES['old_feed']['tmp_name']);
????????$two?=?file_get_contents($_FILES['new_feed']['tmp_name']);
????????//?Exactly?the?same?
????????if?($one?==?$two)?{
????????????echo?'No?changes?between?datafeeds
';
????????????echo?'There?are?absolutely?no?changes?at?all?between?the?two?datafeeds?you?uploaded.
';
????????????die();
????????}?else?{
????????????$one?=?process_datafeed($one);
????????????$two?=?process_datafeed($two);
????????????echo?'The?following?changes?have?been?made:
';
????????????//?Find?added?items
????????????echo?'Added:
';
????????????foreach?($two?as?$id?=>?$item)?{
????????????????if?(array_key_exists($id,?$one))?continue;
????????????????echo?'-?'?.?$item['1']?.?'
';
????????????}
????????????//?Find?changed?items
????????????echo?'Changed:
';
????????????foreach?($two?as?$id?=>?$item)?{
????????????????//?Not?in?the?first?datafeed?
????????????????if?(array_key_exists($id,?$one)?==?false)?continue;
????????????????//?Compare
????????????????$one_item?=?$one[$id];
????????????????$two_item?=?$item;
????????????????if?($one_item['raw']?!=?$two_item['raw'])?{
????????????????????echo?'-?'?.?$item['1']?.?'
';
????????????????}
????????????????//?TODO:?check?each?field,?and?determine?what?has?changed
????????????}
????????????//?Find?removed?items
????????????echo?'Removed:
';
????????????foreach?($one?as?$id?=>?$item)?{
????????????????if?(array_key_exists($id,?$two))?continue;
????????????????echo?'-?'?.?$item['1']?.?'
';
????????????}
????????}
????endif;??>
????
function?process_datafeed($feed)?{
????$feed?=?explode("\n",?$feed);
????$newarr?=?array();
????foreach?($feed?as?$item)?{
????????if?(empty($item))?continue;
????????$split?=?explode("|",?$item);
????????$id?=?$split['0'];
????????$newarr[$id]?=?$split;
????????$newarr[$id]['raw']?=?$item;
????}
????return?$newarr;
}
function?print_error?($msg)?{
????echo?'An?Error?Occured
';
????echo?''?
.?$msg?.?'';
????die();
}
?>