Esempio n. 1
0
function copyConfig($token)
{
    global $mysql_link;
    $configFromDB = getConfigFromDatabase($token);
    $newToken = "";
    if ($configFromDB != null) {
        $newToken = generateRandomToken();
        $configFromDB->token = $newToken;
        $userEmail = $configFromDB->general->userEmail;
        $configName = $configFromDB->general->demoName;
        $configDesc = "Copy of token " . $token . "\n" . $configFromDB->general->demoDescription;
        $userIP = gethostbyaddr($_SERVER['REMOTE_ADDR']);
        $configString = $mysql_link->real_escape_string(json_encode($configFromDB));
        $createConfigSql = "INSERT INTO `iot_demo`.`demo_config` (`id`, `token`, `config_name`, `config_desc`, `config_json`, `create_dttm`, `modify_dttm`, `modify_by`, `email_to`) VALUES (NULL, '" . $newToken . "', '" . $configName . "', '" . $configDesc . "', '" . $configString . "', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '" . $userIP . "', '" . $userEmail . "');";
        $createConfigResult = $mysql_link->query($createConfigSql);
    }
    return $newToken;
}
Esempio n. 2
0
function sendTelegram($token, $customerId, $offer)
{
    global $mysql_link;
    //check if token is valid
    $config = getConfigFromDatabase($token);
    if ($config == null) {
        return;
    }
    $response = "Telegram activated";
    if ($config->general->sendSms == 0 || $config->general->sendSms == "") {
        $response = "Telegram deactivated";
        return $response;
    }
    global $http_proxy;
    $customer = getCustomerObject($customerId, $config);
    $mobileNumber = $customer->mobileNumber;
    $mobileName = $customer->firstName;
    $telegramId = $customer->telegramId;
    $mobileSmsText = $offer->offerSms;
    $offerName = $offer->offerName;
    $newText = parseTextMessage($mobileSmsText, $offer, $customer);
    $serverUrl = "http://dachgpci01.emea.sas.com/MessagingService/rest/";
    $requestParameter = array("sender" => "SAS.Demo", "recipient" => $telegramId, "subject" => $offer->offerImg, "body" => $newText, "channel" => "TELEGRAM", "provider" => "AUTO");
    $response = $response . " - " . $offer->offerImg;
    $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => "POST", 'content' => http_build_query($requestParameter)));
    $context = stream_context_create($options);
    @file_get_contents($serverUrl, false, $context);
    return $response;
}
Esempio n. 3
0
function displayEditor($token, $page)
{
    $content = getPageFromDatabase($token, $page);
    $config = getConfigFromDatabase($token);
    ?>
	<!DOCTYPE html>
	<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<title><?php 
    echo "Editor: " . $page . " Page of " . $config->general->demoName;
    ?>
</title>
		<link href="../css/bootstrap.min.css" rel="stylesheet">
		<style type="text/css" media="screen">
		body {
			overflow: hidden;
			background: #333;
			color: #fff;
		}

		#editor {
			margin: 0;
			position: absolute;
			top: 0px;
			bottom: 65px;
			left: 0;
			right: 0;
			font-size: 16px;
		}

		.ace_search_field {
			color: black;
		}

		#control_buttons {
			margin: 0px;
			position: absolute;
			bottom: 10px;
			right: 10px;
		}

		#control_buttons > lable {
			padding-right: 20px;
		}

		</style>
	</head>
	<body>

		<div id="control_buttons">
			<lable>
				<input id="optionsCheckbox" type="checkbox" value="insert_js_base"/> (re) insert required Javascripts and clean up HTML.
			</lable>

			<input type="button" class="btn btn-lg btn-default" value="Save" onclick="saveContent();"/>
			<input type="button" class="btn btn-lg btn-primary" value="Save and Close" onclick="saveContent(true);"/>
		</div>

		<div>
			<pre>
<code id="editor"><?php 
    echo htmlentities($content, ENT_QUOTES, "UTF-8");
    ?>
</code>
			</pre>
		</div>



		<script src="../js/ext/ace/ace.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/ext/jquery-1.11.3.min.js" type="text/javascript" charset="utf-8"></script>
		<script>
		var editor = ace.edit("editor");
		var reloadPageAfterSaving = true;
		editor.setTheme("ace/theme/monokai");
		editor.session.setMode("ace/mode/html");

		function saveContent(closeWindowAfterSaving) {
			var token = "<?php 
    echo $token;
    ?>
";
			var page = "<?php 
    echo $page;
    ?>
";
			var content = editor.getValue();
			var options = ($('input#optionsCheckbox').is(':checked'));

			return $.ajax("./", {
				type: 'POST',
				data: {action: "save",token: token, page: page, content: content, options: options}
			} ).done(function(result) {
				if(result.status == "success") {
					alert("Website saved successfully.");
					if(closeWindowAfterSaving) {
						window.close();
					}
					else if(reloadPageAfterSaving) {
						location.reload();
					}
				} else {
					alert("Error: Could not save website.");
					console.log("Error Message: " + result.message);
				}

			});;

		}

		</script>


	</body>
	</html>

	<?php 
}