<?php

$issue = strip_tags($_POST['issue']);
$token = strip_tags($_POST['token']);
$select = strip_tags($_POST['select']);

/*
$durum = $issue . " -- " . $select . " -- \r\n\r\n" . $token ;

$dosya = "durum_" . rand(1,500). ".txt" ;
$dt = fopen($dosya, "w");
fwrite ($dt, $durum);
fclose($dt);
*/

function createTopic($topic,$id) {
  $url = 'https://iid.googleapis.com/iid/v1/' . $id . '/rel/topics/' . $topic;
  $headers = array (
    'Authorization: key=AAAA7al_fhg:APA91bGWy01wJ0eRgr7nWUjCNYQxEb_T3XWX_3h2Dx66SKpZOCWGE3L8MYO9ZJ5C-5XqEApWeCUz6376jeOO0Gocldi10MWIhxaYGWlWkbWm9DUFdTjl8zGy8lGYtm2ozLlHYU93dhTuC4i5NBR7tBoJcLDcTT92iQ',
	'Content-Length: 0'
  );
  $ch = curl_init ();
  curl_setopt ( $ch, CURLOPT_URL, $url );
  curl_setopt ( $ch, CURLOPT_POST, true );
  curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
  curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
  curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );	
  $result = curl_exec ( $ch );
  curl_close ( $ch );
}

function deleteTopic($topic,$id) {
  $url = 'https://iid.googleapis.com/iid/v1/' . $id . '/rel/topics/' . $topic;
  $headers = array (
    'Authorization: key=AAAA7al_fhg:APA91bGWy01wJ0eRgr7nWUjCNYQxEb_T3XWX_3h2Dx66SKpZOCWGE3L8MYO9ZJ5C-5XqEApWeCUz6376jeOO0Gocldi10MWIhxaYGWlWkbWm9DUFdTjl8zGy8lGYtm2ozLlHYU93dhTuC4i5NBR7tBoJcLDcTT92iQ',
	'Content-Length: 0'
  );
  $ch = curl_init ();
  curl_setopt ( $ch, CURLOPT_URL, $url );
  curl_setopt ( $ch, CURLOPT_POST, true );
  curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
  curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
  curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );	
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
  $result = curl_exec ( $ch );
  curl_close ( $ch );
}

if($select == "create"):

createTopic($issue,$token);

else:

deleteTopic($issue,$token);

endif;

?>