if (!$xmlDir) {
exit(1);
}
$xmlFiles = glob($xmlDir . '/*.xml');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
foreach ($xmlFiles as $file) {
$xml = simplexml_load_file($file);
foreach ($xml->offer as $offer) {
$fields = array(
'id' => $offer->offer_ID.'',
'fields' => array(
'STAGE_ID' => 'true' === reset($offer->result) ? 'WON' : 'LOSE',
),
);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
logToFile('Updating deal, fields: ' . var_export($fields, true));
$result = curl_exec($ch);
logToFile('Update result: ' . var_export($result, true));
}
unlink($file);
}
exit(0);