public function login($credentials)
{
$this->_username = $credentials['user'];
$this->_password = $credentials['password'];
$this->_client = new \Oara\Curl\Access($credentials);
$postdata = \http_build_query(array('class' => 'Logon', 'method' => 'logon', 'val1' => $this->_username, 'val2' => $this->_password, 'val3' => ''));
$opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
$context = \stream_context_create($opts);
$result = \unserialize(file_get_contents('http://www.tyroocentral.com/www/api/v2/xmlrpc/APICall.php', false, $context));
\json_encode($result);
$this->_sessionID = $result[0];
$user = $credentials['user'];
$password = $credentials['password'];
//webpage uses javascript hex_md5 to encode the password
$valuesLogin = array(new \Oara\Curl\Parameter('username', $user), new \Oara\Curl\Parameter('password', $password), new \Oara\Curl\Parameter('loginByInterface', 1), new \Oara\Curl\Parameter('login', 'Login'));
$urls = array();
$urls[] = new \Oara\Curl\Request("http://www.tyroocentral.com/www/admin/index.php", $valuesLogin);
$exportReport = $this->_client->post($urls);
$doc = new \DOMDocument();
@$doc->loadHTML($exportReport[0]);
$xpath = new \DOMXPath($doc);
$hidden = $xpath->query('//input[@type="hidden"]');
foreach ($hidden as $values) {
$valuesLogin[] = new \Oara\Curl\Parameter($values->getAttribute("name"), $values->getAttribute("value"));
}
$urls = array();
$urls[] = new \Oara\Curl\Request("http://www.tyroocentral.com/www/admin/index.php", $valuesLogin);
$exportReport = $this->_client->post($urls);
$doc = new \DOMDocument();
@$doc->loadHTML($exportReport[0]);
$xpath = new \DOMXPath($doc);
$hidden = $xpath->query('//input[@type="hidden"]');
foreach ($hidden as $values) {
if ($values->getAttribute("name") == 'affiliateid') {
$this->_publisherID = $values->getAttribute("value");
}
}
$results = $xpath->query('//*[contains(concat(" ", normalize-space(@id), " "), " oaNavigationTabs ")]');
$finished = false;
foreach ($results as $result) {
$linkList = $result->getElementsByTagName('a');
if ($linkList->length > 0) {
$attrs = $linkList->item(0)->attributes;
foreach ($attrs as $attrName => $attrNode) {
if (!$finished && ($attrName = 'href')) {
$parseUrl = \trim($attrNode->nodeValue);
$parts = \parse_url($parseUrl);
\parse_str($parts['query'], $query);
$this->_windowid = $query['windowid'];
$this->_sessionIDCurl = $query['sessId'];
$finished = true;
}
}
}
}
}