<?php
	include('includes/application_top.php');
	require('admin/includes/config.ebayapi.inc.php');
	include(ABS_PATH_TO_PHPAPI."ebat/GetNotificationPreferencesRequestType.php");
	include(ABS_PATH_TO_PHPAPI."ebat/SetNotificationPreferencesRequestType.php");
	require_once ABS_PATH_TO_PHPAPI.'ebat/EbatNs_ServiceProxy.php';
	require_once ABS_PATH_TO_PHPAPI.'ebat/EbatNs_Logger.php';
	require_once(DIR_FS_DOCUMENT_ROOT.'admin/includes/classes/class.ebay.php');

	$event_array = array(
		'EndOfAuction',
		'FixedPriceTransaction'
	);
	$EBAYAPI = new ebayapi;
	$site_id = $EBAYAPI->get_site_id_from_name(EBAY_SITE);

	$act_user = 'yes-system';
	$session = new EbatNs_Session(ABS_PATH_TO_PHPAPI.'config/ebay.config.php');
	$session->setRequestToken( $EBAYAPI->getToken($act_user));
	$session->setSiteID($site_id);
	$cs = new EbatNs_ServiceProxy($session);

	$req = new GetNotificationPreferencesRequestType();
	$req->setPreferenceLevel('User');
	$res = $cs->GetNotificationPreferences($req);
	$U = $res->getUserDeliveryPreferenceArray();
	$install = array();
	for($a=0;$a<sizeOf($event_array);$a++){
		$checked = false;
		for($i=0;$i<sizeOf($U);$i++){
			$N = $U[$i];
			if($event_array[$a] == $N->getEventType()){
				$checked = ($N->getEventEnable() == 'Enable') ? true : false;
				if(!$checked)
					$install[] = $event_array[$a];
			}
		}
	}
	if(sizeOf($install)>0){
		$req = new SetNotificationPreferencesRequestType();
		for($i=0;$i<sizeOf($install);$i++){
			$enable = 'Enable';
			$user = new NotificationEnableArrayType();
			$app = new NotificationEnableType();
			$app->setEventEnable($enable);
			$app->setEventType($install[$i]);
			$user->NotificationEnable[] = $app;
			$req->setUserDeliveryPreferenceArray($user);
			$res = $cs->SetNotificationPreferences($req);
		}
	}

?>
