Im trying to figure this out but its really getting to me 2nd all day on trying code and searching ...
Trying to see guidance if i am getting to the right direction with ajax and autosaving when a user performs an action on the button (BUT i do need to have a config.txt)
Because its more of an Active running application for enabling/disabling an action with custom options needed on the fly.
Trying to (ON page load ) read file config.txt (and auto change the values on the form to what was read from config.txt like a 2 way async (Without reloading the page)
config.txt
active=1
email=1
markets=chi,nyc,orl,sfo
timer=15
emailaddress=test@gmail.com
logviewer=1
so Being that markets has option to add 1 or more i need to post with commas ...
Thus when active=1 is enabled theres a bash script in the background that will be executed based on the selection of the active (when the user checks the box IN REALTIME) ... (onclick)
MAIN HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>....Tools....</title>
<script src="js/ajaxsbmt.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" media="all" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/ui-darkness/jquery-ui.css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
<script type="text/javascript" src="../src/jquery.multiselect.js"></script>
<script type="text/javascript" src="../src/jquery.multiselect.filter.js"></script>
<script type="text/javascript" src="assets/prettify.js"></script>
<link rel="stylesheet" type="text/css" href="../jquery.multiselect.css" />
<link rel="stylesheet" type="text/css" href="assets/style.css" />
<link rel="stylesheet" type="text/css" href="assets/prettify.css" />
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/ui-lightness/jquery-ui.css" />
<script type="text/javascript">
$(function(){
$("select").multiselect({
selectedList: 4
});
$("select").multiselect().multiselectfilter();
});
</script>
<script type="text/javascript">
function autosave()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("poll").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","save.php?data="+data,true);
if (multiple_id == "marketlist")
{
xmlhttp.send($value1","$value2","$value3","$value4",")
// NEED TO FIGURE OUT HOW TO POST it as CHI,ATL,NYC or however many selected with comma seperated values as the line item Hmmmmmmmmm
}
}
</script>
</head>
<body>
<div id="TESTING">
<h3>ENABLE Debug LOG VIEWER</h3>
<form>
Yes:
<input type="radio" id="logger" name="logviewer" value="logger=1" onclick="autosave(this.value)" />
<br />No:
<input type="radio" id="logger" name="logviewer" value="logger=0" onclick="autosave(this.value)" />
</form>
</div>
<div id="page">
<ul>
<li><label for="ch_effects">ENABLE Diaster Script:</label><input type="checkbox" id="ch_enable" name="ch_enable" data-on="Enable" data-off="Disable" onclick="autosave(this.value)" /></li>
Select Markets To be monitored
<form>
<form name="mkts" method="post" action="save.php">
<select name="marketlist" multiple="multiple" style="width:600px">
<option value="CHI">Chicago-CHI</option>
<option value="CHI">Baltimore-BAL</option>
<option value="NYC">New York-NYC</option>
<option value="BDR">Bridgeport-BDR</option>
<option value="PHL">Philadelphia-PHL</option>
<option value="PHL">Pittsburgh-PIT</option>
<option value="ORL">Orlando-ORL</option>
</select>
<input type="submit" id="marketlist" value="what is selected Seperate by Commas" name="submit" onclick="autosave(this.value)" />
</p>
<li><label for="ch_location">Email notifications</label><input type="checkbox" id="ch_emailnotify" name="ch_emailnotify" data-on="ON" data-off="OFF" onchange="autosave(this.value)"/></li>
<li><label for="ch_emails">Realtime log view</label><input type="checkbox" id="ch_logview" name="ch_logview" data-on="Show" data-off="Hide" onchange="autosave(this.value)"/></li>
</ul>
<p>
<div>
<input id="email" name="email" class="element text medium" type="text" maxlength="255" value="" onchange="autosave(this.value)"/>
</div>
<li class="buttons">
<input type="hidden" name="form_id" value="CONFIG" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
</body>
</html>
SAVE.PHP
<?php
$logger = $_REQUEST["logger"];
$active = $_REQUEST["ch_enable"];
$marketlist = $_REQUEST["marketlist"];
$emailnotify = $_REQUEST["ch_emailnotify"];
$filename="config.txt";
$act = "active='$active'";
$log = "logger='$logger'";
$mkt = "markets='$marketlist'";
$eml = "email='$emailnotify'";
$fin=fopen($filename,"w");
fwrite($fin,$content);
if ( $act = "" ) {
$cmd = "grep 'active=' " . $filename;
$output = system($cmd, $result);
$lines = explode("
", $result);
}
if ( $log != "" ) {
$cmd = "grep 'logger=' " . $filename;
$output = system($cmd, $result);
$lines = explode("
", $result);
}
if ( $mkt != "" ) {
$cmd = "grep 'markets=' " . $filename;
$output = system($cmd, $result);
$lines = explode("
", $result);
}
if ( $eml != "" ) {
$cmd = "grep 'email=' " . $filename;
$output = system($cmd, $result);
$lines = explode("
", $result);
}
fclose($fin);
echo "Data saved";
?>