/** * Submit display statistics to the server * @return bool * @param string $serverKey * @param string $hardwareKey * @param string $statXml * @throws SoapFault */ function SubmitStats($serverKey, $hardwareKey, $statXml) { // Sanitize $serverKey = Kit::ValidateParam($serverKey, _STRING); $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING); $statXml = Kit::ValidateParam($statXml, _HTMLSTRING); // Check the serverKey matches if ($serverKey != Config::GetSetting('SERVER_KEY')) { throw new SoapFault('Sender', 'The Server key you entered does not match with the server key at this address'); } // Make sure we are sticking to our bandwidth limit if (!$this->CheckBandwidth()) { throw new SoapFault('Receiver', "Bandwidth Limit exceeded"); } // Auth this request... if (!$this->AuthDisplay($hardwareKey)) { throw new SoapFault('Receiver', "This display client is not licensed"); } if ($this->isAuditing == 1) { Debug::Audit('Received XML. ' . $statXml, $this->displayId); } if ($statXml == "") { throw new SoapFault('Receiver', "Stat XML is empty."); } // Log $statObject = new Stat(); // Load the XML into a DOMDocument $document = new DOMDocument("1.0"); $document->loadXML($statXml); foreach ($document->documentElement->childNodes as $node) { // Make sure we don't consider any text nodes if ($node->nodeType == XML_TEXT_NODE) { continue; } // Each element should have these attributes $fromdt = $node->getAttribute('fromdt'); $todt = $node->getAttribute('todt'); $type = $node->getAttribute('type'); if ($fromdt == '' || $todt == '' || $type == '') { Debug::Error('Stat submitted without the fromdt, todt or type attributes.', $this->displayId); continue; } $scheduleID = $node->getAttribute('scheduleid'); $layoutID = $node->getAttribute('layoutid'); $mediaID = $node->getAttribute('mediaid'); $tag = $node->getAttribute('tag'); // Write the stat record with the information we have available to us. if (!$statObject->Add($type, $fromdt, $todt, $scheduleID, $this->displayId, $layoutID, $mediaID, $tag)) { Debug::Error(sprintf('Stat Add failed with error: %s', $statObject->GetErrorMessage()), $this->displayId); continue; } } $this->LogBandwidth($this->displayId, Bandwidth::$SUBMITSTATS, strlen($statXml)); return true; }
/** * Submit display statistics to the server * @return * @param $version Object * @param $serverKey Object * @param $hardwareKey Object * @param $statXml Object */ function SubmitStats($version, $serverKey, $hardwareKey, $statXml) { $db =& $this->db; // Sanitize $serverKey = Kit::ValidateParam($serverKey, _STRING); $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING); $version = Kit::ValidateParam($version, _STRING); $statXml = Kit::ValidateParam($statXml, _HTMLSTRING); // Make sure we are talking the same language if (!$this->CheckVersion($version)) { throw new SoapFault('Receiver', "Your client is not of the correct version for communication with this server."); } // Make sure we are sticking to our bandwidth limit if (!$this->CheckBandwidth()) { throw new SoapFault('Receiver', "Bandwidth Limit exceeded"); } // Auth this request... if (!$this->AuthDisplay($hardwareKey)) { throw new SoapFault('Receiver', "This display client is not licensed"); } if ($this->isAuditing == 1) { Debug::LogEntry("audit", "IN", "xmds", "SubmitStats", "", $this->displayId); } if ($this->isAuditing == 1) { Debug::LogEntry("audit", "StatXml: [" . $statXml . "]", "xmds", "SubmitStats", "", $this->displayId); } if ($statXml == "") { throw new SoapFault('Receiver', "Stat XML is empty."); } // Log if ($this->isAuditing == 1) { Debug::LogEntry("audit", "About to create Stat Object.", "xmds", "SubmitStats", "", $this->displayId); } $statObject = new Stat($db); // Log if ($this->isAuditing == 1) { Debug::LogEntry("audit", "About to Create DOMDocument.", "xmds", "SubmitStats", "", $this->displayId); } // Load the XML into a DOMDocument $document = new DOMDocument("1.0"); $document->loadXML($statXml); foreach ($document->documentElement->childNodes as $node) { // Make sure we dont consider any text nodes if ($node->nodeType == XML_TEXT_NODE) { continue; } //Zero out the common vars $fromdt = ''; $todt = ''; $type = ''; $scheduleID = 0; $layoutID = 0; $mediaID = ''; $tag = ''; // Each element should have these attributes $fromdt = $node->getAttribute('fromdt'); $todt = $node->getAttribute('todt'); $type = $node->getAttribute('type'); if ($fromdt == '' || $todt == '' || $type == '') { trigger_error('Stat submitted without the fromdt, todt or type attributes.'); continue; } $scheduleID = $node->getAttribute('scheduleid'); $layoutID = $node->getAttribute('layoutid'); $mediaID = $node->getAttribute('mediaid'); $tag = $node->getAttribute('tag'); // Write the stat record with the information we have available to us. if (!$statObject->Add($type, $fromdt, $todt, $scheduleID, $this->displayId, $layoutID, $mediaID, $tag)) { trigger_error(sprintf('Stat Add failed with error: %s', $statObject->GetErrorMessage())); continue; } } if ($this->isAuditing == 1) { Debug::LogEntry("audit", "OUT", "xmds", "SubmitStats", "", $this->displayId); } return true; }