<?php

if(0){
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7" />
<?
}

require_once('config.php');
require_once('functions.php');

$balance_soft_limit = 50;



function hyperhosting_getConfigArray() {
	global $balance_soft_limit;
	
	$configarray = array(
	 "Username" => array( "Type" => "text", "Size" => "20", "Description" => i7u8("Όνομα χρήστη - Reseller")),
	 "Password" => array( "Type" => "password", "Size" => "20", "Description" => i7u8("Κωδικός χρήστη - Reseller")),
 	 "TestMode" => array( "Type" => "yesno", "Description" => i7u8("Ενεργοποίηση debugging/test mode")),
	 "ResellerNotify" => array( "Type" => "yesno", "Description" => i7u8("Ενημέρωση του Reseller για δημιουργία ή ανανέωση domains μέσω e-mail")),
	 "ResellerEmail" => array( "Type" => "text", "Size" => "50", "Description" => i7u8("Email ειδοποιήσεων - Για πολλαπλά email χωρίζετε με κόμμα (,)")),
	 "Balance" => array( "Type" => "yesno", "Description" => i7u8("Θα γίνει αυτόματη χρέωση στο balance σας, αν αποτύχει θα πρέπει να εξοφλήσετε χειροκίνητα το domain")),
	 "BalanceSoftLimit" => array( "Type" => "yesno", "Description" => i7u8("Ενημέρωση χαμηλού ποσού χρημάτων (Κάτω από <b>".$balance_soft_limit."&euro;</b>) στον λογαριασμό σας")),
	 i7u8("<b>Πληροφορίες:</b>") => array( "Description"=> i7u8("H version αυτή είναι <u>BETA (0.8)</u>. Για υποστήριξη καλέστε στο 2104631800.")),
	 "Domain Sync" => array("Description" => i7u8("<a href=\"../modules/registrars/hyperhosting/cron.php\" target=\"_blank\">Πατήστε εδώ για να γίνει συγχρονισμός των domain με το μητρώο.</a>")),
	 "RegAutoPay" => array( "Type" => "yesno", "Description" => i7u8("Αυτόματη εξόφληση καινούργιων domain από το πιστωτικό μου."))

	);
	
	return $configarray;
}



function hyperhosting_GetNameservers($params) {
	$username = $params["Username"];
	$password = $params["Password"];
	$testmode = $params["TestMode"];
	$tld = $params["tld"];
	$sld = $params["sld"];
	# Put your code to get the nameservers here and return the values below

	$params["HYP_action"] = "checknameserver";
	$ret_data = postdata($params);
	
	if($tld == "eu"){
	$splited = explode("{",$ret_data);
	$resdata = json_decode("{".$splited[1], true);
	//mail("alex@hyperhosting.gr","data eu",print_r($resdata,true));
	}else{
	$resdata = json_decode($ret_data, true);
	//mail("alex@hyperhosting.gr","data",print_r($ret_data,true));
	}
	$values["error"] = $resdata["error"];
	
	$values["ns1"] = $resdata["ns1"];
	$values["ns2"] = $resdata["ns2"];
	$values["ns3"] = $resdata["ns3"];
	$values["ns4"] = $resdata["ns4"];


	$expdate = $resdata["expdate"];
	$regdate = $resdata["regdate"];
	if($expdate)
	{
		$query = "UPDATE `tbldomains` SET `registrationdate` = '".$regdate."', `expirydate` = '".$expdate."', `nextduedate` = '".$expdate."', `nextinvoicedate` = '".$expdate."', `status` = 'Active' WHERE id = ".$params['domainid'];
		mysql_query($query);
	}
# If error, return the error message in the value below
	return $values;
}


function hyperhosting_SaveNameservers($params) {
	$username = $params["Username"];
	$password = $params["Password"];
	$testmode = $params["TestMode"];
	$tld = $params["tld"];
	$sld = $params["sld"];
	
    $nameserver1 = $params["ns1"];
	$nameserver2 = $params["ns2"];
    $nameserver3 = $params["ns3"];
	$nameserver4 = $params["ns4"];
	# Put your code to save the nameservers here
	$params["HYP_action"] = "updatenameserver";
	$ret_data = postdata($params);
	$resdata = json_decode($ret_data, true);

	# If error, return the error message in the value below
	$values["error"] = $resdata["error"];
	$values["error"] = $error;
	return $values;
}


function hyperhosting_RegisterDomain($params) {
	
	$username = $params["Username"];
	$password = $params["Password"];
	$testmode = $params["TestMode"];
	$tld = $params["tld"];
	$sld = $params["sld"];
	$regperiod = $params["regperiod"];
	$nameserver1 = $params["ns1"];
	$nameserver2 = $params["ns2"];
    $nameserver3 = $params["ns3"];
    $nameserver4 = $params["ns4"];
	$description = $params["additionalfields"]["Description"];
	# Registrant Details
	$RegistrantFirstName = $params["firstname"];
	$RegistrantLastName = $params["lastname"];
	$RegistrantAddress1 = $params["address1"];
	$RegistrantAddress2 = $params["address2"];
	$RegistrantCity = $params["city"];
	$RegistrantStateProvince = $params["state"];
	$RegistrantPostalCode = $params["postcode"];
	$RegistrantCountry = $params["country"];
	$RegistrantEmailAddress = $params["email"];
	$RegistrantPhone = $params["phonenumber"];
	# Admin Details
	$AdminFirstName = $params["adminfirstname"];
	$AdminLastName = $params["adminlastname"];
	$AdminAddress1 = $params["adminaddress1"];
	$AdminAddress2 = $params["adminaddress2"];
	$AdminCity = $params["admincity"];
	$AdminStateProvince = $params["adminstate"];
	$AdminPostalCode = $params["adminpostcode"];
	$AdminCountry = $params["admincountry"];
	$AdminEmailAddress = $params["adminemail"];
	$AdminPhone = $params["adminphonenumber"];

	# Put your code to register domain here
	$params["HYP_action"] = "registerdomain";
	$ret_data = postdata($params);
	$resdata = json_decode($ret_data, true);
	$values["error"] = $resdata["error"];
	# If error, return the error message in the value below
	return $values;
}

function hyperhosting_RenewDomain($params) {
	$username = $params["Username"];
	$password = $params["Password"];
	$testmode = $params["TestMode"];
	$tld = $params["tld"];
	$sld = $params["sld"];
	$regperiod = $params["regperiod"];
	# Put your code to renew domain here
	
	$params["HYP_action"] = "renewdomain";
	$ret_data = postdata($params);
	$splited = explode("}{",$ret_data);
	$resdata = json_decode("{".$splited[1], true);
	$values["error"] = $resdata["error"];
	# If error, return the error message in the value below
	return $values;
}

function hyperhosting_GetContactDetails($params) {
	$username = $params["Username"];
	$password = $params["Password"];
	$testmode = $params["TestMode"];
	$tld = $params["tld"];
	$sld = $params["sld"];
	# Put your code to get WHOIS data here
	$params["HYP_action"] = "updatecontact";
	$ret_data = postdata($params);
	
	if($tld == "eu"){
	$splited = explode("{",$ret_data);
	$resdata = json_decode("{".$splited[1], true);
//	mail("alex@hyperhosting.gr","data eu",print_r($resdata,true));
	}else{
	$splited = explode("}{",$ret_data);
	$resdata = json_decode("{".$splited[1], true);
//	mail("alex@hyperhosting.gr","data",print_r($ret_data,true));
	}
	# Data should be returned in an array as follows
	$values["Registrant"]["First Name"] = $resdata["firstname"];
	$values["Registrant"]["Last Name"] = $resdata["lastname"];
	$values["Registrant"]["Company Name"] = $resdata["company"];
	$values["Registrant"]["Email"] = $resdata["email"];
	$values["Registrant"]["Street 1"] = $resdata["street1"];
	$values["Registrant"]["Street 2"] = $resdata["street2"];
	$values["Registrant"]["City"] = $resdata["city"];
	$values["Registrant"]["State"] = $resdata["state"];
	$values["Registrant"]["Postal Code"] = $resdata["postal"];	
	$values["Registrant"]["Country"] = $resdata["country"];
	$values["Registrant"]["Telephone"] = $resdata["telephone"];
	$values["Registrant"]["Fax"] = $resdata["fax"];

//	mail("alex@hyperhosting.gr","sendata2",print_r($resdata,true));
	return $values;
}


function hyperhosting_SaveContactDetails($params) {
	$username = $params["Username"];
	$password = $params["Password"];
	$testmode = $params["TestMode"];
	$tld = $params["tld"];
	$sld = $params["sld"];
	# Data is returned as specified in the GetContactDetails() function
	$owners['first_name'] = $params["contactdetails"]["Registrant"]["First Name"];
	$owners['last_name'] = $params["contactdetails"]["Registrant"]["Last Name"];
	$owners['company'] = $params["contactdetails"]["Registrant"]["Company Name"];
	$owners['email'] = $params["contactdetails"]["Registrant"]["Email"];
	$owners['street1'] = $params["contactdetails"]["Registrant"]["Street 1"];
	$owners['street2'] = $params["contactdetails"]["Registrant"]["Street 2"];
	$owners['city'] = $params["contactdetails"]["Registrant"]["City"];
	$owners['state'] = $params["contactdetails"]["Registrant"]["State"];
	$owners['postal_code'] = $params["contactdetails"]["Registrant"]["Postal Code"];
	$owners['country'] = $params["contactdetails"]["Registrant"]["Country"];
	$owners['telephone'] = $params["contactdetails"]["Registrant"]["Telephone"];
	$owners['fax'] = $params["contactdetails"]["Registrant"]["Fax"];
	
	# Put your code to save new WHOIS data here
	$params["first_name"] = $owners['first_name'];
	$params["last_name"] = $owners['last_name'];
	$params["company"] = $owners['company'];
	$params["email"] = $owners['email'];
	$params["street1"] = $owners['street1'];
	$params["street2"] = $owners['street2'];
	$params["city"] = $owners['city'];
	$params["state"] = $owners['state'];
	$params["postal_code"] = $owners['postal_code'];	
	$params["country"] = $owners['country'];
	$params["telephone"] = $owners['telephone'];
	$params["fax"] = $owners['fax'];

	$params["HYP_action"] = "savecontact";
	$ret_data = postdata($params);
	$resdata = json_decode($ret_data, true);
	$values["error"] = $resdata["error"];

	# If error, return the error message in the value below
	return $values;
}

function hyperhosting_TransferDomain($params) {
	$username = $params["Username"];
	$password = $params["Password"];
	$testmode = $params["TestMode"];
	$tld = $params["tld"];
	$sld = $params["sld"];
	$regperiod = $params["regperiod"];
	$transfersecret = $params["transfersecret"];
	$nameserver1 = $params["ns1"];
	$nameserver2 = $params["ns2"];
	# Registrant Details
	$RegistrantFirstName = $params["firstname"];
	$RegistrantLastName = $params["lastname"];
	$RegistrantAddress1 = $params["address1"];
	$RegistrantAddress2 = $params["address2"];
	$RegistrantCity = $params["city"];
	$RegistrantStateProvince = $params["state"];
	$RegistrantPostalCode = $params["postcode"];
	$RegistrantCountry = $params["country"];
	$RegistrantEmailAddress = $params["email"];
	$RegistrantPhone = $params["phonenumber"];
	# Admin Details
	$AdminFirstName = $params["adminfirstname"];
	$AdminLastName = $params["adminlastname"];
	$AdminAddress1 = $params["adminaddress1"];
	$AdminAddress2 = $params["adminaddress2"];
	$AdminCity = $params["admincity"];
	$AdminStateProvince = $params["adminstate"];
	$AdminPostalCode = $params["adminpostcode"];
	$AdminCountry = $params["admincountry"];
	$AdminEmailAddress = $params["adminemail"];
	$AdminPhone = $params["adminphonenumber"];
	# Put your code to transfer domain here

	$params["HYP_action"] = "transferdomain";
	$ret_data = postdata($params);
	$splited = explode("}{",$ret_data);
	$resdata = json_decode("{".$splited[1], true);
	$values["error"] = $resdata["error"];
	# If error, return the error message in the value below
	return $values;
}


function hyp_send_epp_code($params){
	list(, $caller) = debug_backtrace(false);
	//mailme2(print_r($params, true),$caller['function']);
	
	$params["HYP_action"] = "domain_code_request";
	$ret_data = postdata($params);
	//mailme2(print_r($ret_data, true),$caller['function']);

	$resdata = json_decode($ret_data, true);


	# If error, return the error message in the value below
	return $resdata;
}

function hyperhosting_GetEPPCode($params) {
	return hyp_send_epp_code($params);
}
function hyperhosting_DomainRequestEPP($params) {
	return hyp_send_epp_code($params);
}
