
<h3>
	Discord Notification Bot
	<br>
	<span class="text-muted">
		<small>
			developed by icrewsystems | Version 1.05 &copy;  <?php echo date("Y"); ?>
		</small>
	</span>
</h3>

<h2>
	Deliver Notification
</h2>
<?php
	//=======================================================================
// Create new webhook in your Discord channel settings and copy&paste URL
//=======================================================================
$webhookurl = DISCORD_WEBHOOK_URL;

if(DISCORD_ENABLE_WEBHOOKS == 0) {
	die("Webhook notifications are currently disabled!");
}
//=======================================================================
// Compose message. You can use Markdown
//=======================================================================
$msg = $_POST['message'];
$title = $_POST['title'];
$description = $_POST['description'];
$image_url = $_POST['image_url'];
$url = $_POST['url'];
$url_text = $_POST['author'];


 $json_data = array ('content'=>"$msg", "embeds" => ["title" => "$url_text", "type" => "rich", "description" => "$description", "url" => "$url", "timestamp" => date(), "color" => hexdec( "fafafa" ),
             "footer" => [
                 "text" => SITE_NAME." | Powered by iCrew v4 Premium",
                 "icon_url" => "https://icrew.skydream-airlines.com/dashboard/v4logo.png"
             ],
             "image" => [
                 "url" => "$image_url"
             ],
             "author" => [
                 "name" => "$title"
             ]
 					]);

$msg = $_POST['message'];
$json_data = array ('content'=>"$msg");
$make_json = json_encode($json_data);
$ch = curl_init( $webhookurl );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $make_json);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );


if (curl_errno($ch)) {
    // this would be your first hint that something went wrong
    die('Couldn\'t send request: ' . curl_error($ch));
} else {
    // check the HTTP status code of the request
    $resultStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($resultStatus == 200 || $resultStatus == 204) {
        // everything went better than expected
        $clr = "success";
        $status = 'Payload delivered successfully to the server! Check notifications, status code : ' . $resultStatus.'';

    } else if ($resultStatus == 404) {
        // everything went better than expected
        $clr = "danger";
        $status = 'Webhook URL is invalid, get a new URL from Discord > Server Settings > Webhooks and configure at local.config.php, status code : ' . $resultStatus.'';

    } else {
        // the request did not complete as expected. common errors are 4xx
        // (not found, bad request, etc.) and 5xx (usually concerning
        // errors/exceptions in the remote script execution)
		$clr = "danger";
        $status = 'Request failed: HTTP status code: ' . $resultStatus.'';
    }
}

?>


<p>
	<div class="alert alert-<?php echo $clr; ?>">
		<strong>
			Status
		</strong> : <?php echo $status; ?>
	</div>

	<br>

	<strong>
		Message :
	</strong> <?php echo $msg; ?>
</p>

<div class="row">
	<div class="col-md-6">
		<form action="<?php echo SITE_URL; ?>/admin/index.php/Discord" method="POST">
			<input type="submit" name="action" value="Home" class="btn btn-block btn-success" />
		</form>
	</div>
	<div class="col-md-6">
		<form action="<?php echo SITE_URL; ?>/admin/index.php/Discord/single" method="POST">
			<input type="submit" name="action" value="Send Another Notification" class="btn btn-block btn-info" />
		</form>
	</div>
</div>
