I need a real time loop "status check" for buttons. Buttons "class" or "id" name is going to be changed depending on value it gets from txt file. This class/id name then will be processed with CSS. Also this button class or id depending from name should trigger/call function just to run specific php file.
Before: I have done it using only PHP, but there were no realtime "status check" :< It looked like this:
<?php
if(isset($_POST['run1']))
{exec('run1.bat');}?> // In this part it is waiting a button push with specific
<?php // class name and then runs some bat file which runs some
if(isset($_POST['run2'])) // command and writes output to R1.txt
{exec('run2.bat');}?>
<?php
$r1 = "R1.txt"; //This part reads txt file R1.txt ...
$fr1 = fopen($r1, "a+");
$sizer1 = filesize($r1);
$tr1 = fread($fr1, $sizer1);
sscanf($tr1, "SOMERANDOM TEXT(%d)", $nr1); // ...and gets value 1 or none
fclose($fr1);
?>
<form action="" method="post"> //This part is a form
<?php
if ($nr1=="1") //Here it check's value from txt and load specific
{ // type of button.
echo '<input type="submit" class="runing1" name="run1" value="">' . "
";
}
else
{
echo '<input type="submit" class="runing2" name="run2" value="">' . "
";
}
?>
For now i think out structure of it like this: There is gonna be check.php with something like
<?php
$r1 = "R1.txt"; //This part reads txt file R1.txt ...
$fr1 = fopen($r1, "a+");
$sizer1 = filesize($r1);
$tr1 = fread($fr1, $sizer1);
sscanf($tr1, "SOMERANDOM TEXT(%d)", $nr1); // ...and gets value 1 or none
fclose($fr1);
?>
<?php
$r2 = "R2.txt"; //This part reads txt file R2.txt ...
$fr2 = fopen($r2, "a+");
$sizer2 = filesize($r2);
$tr2 = fread($fr2, $sizer2);
sscanf($tr2, "SOMERANDOM TEXT(%d)", $nr2); // ...and gets value 1 or none
fclose($fr2);
?>
This PHP file should POST those $nr1 and $nr2 values some how Outside for Ajax. Then there will be index.php/htm With several buttons which runs some kind of loop thru check.php and get the value for buttons and applies specified class or id on buttons. Like yes/no or On/OFf etc. And then depending on button status class/id it should run specific function. In "Perfectness" it would be great if with help of AJAX the class or id would be perhaps variable, cuz it could be POSTed to enother run.php file with similar code...
<?php
if(isset($_POST['$class-name-from-button']))
{exec('($_POST['$class-name-from-button']).bat');}?>
<?php
It could save a lot of "repeating same line code" space i think.