Jump to content
Sign in to follow this  
JohanV

Convert PHP to AutoIT

Recommended Posts

JohanV

Hello,

I've created a script for a Bingo / Lottery kind of game in PHP.

Now I want to make this a standalone application in AutoIT.

I really dont know how to do that as i´m just a Autoit-beginner.

Can you help me with it?

In general I have the following files:

data.csv - the "database" where the bingo-numbers are stored, together with the name of the candidate

index.htm - to show the 'program' in a browser

input.php - to take care of input

results.php - to show the winners

numbers.txt - the winning numbers to compare with

I have the following files:

Input.php:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body {  font-family:Times New Roman, Verdana,Geneva; font-size:12px; color:#000000;
    margin-left:20px; background:#F7F5DF; width: 300px; }
H2 { font-family:Times New Roman, Geneva; font-size:16pt; color:#840018; text-align:center; }
</style>
<link rel=stylesheet href="style.css" TYPE="text/css">
<title>Input</title>
<?php
$sepsign   = '/;/';
$text     = '';
$wnumbers = '';
$counter    = 0;
$filed     = "data.csv";
$fileg     = "numbers.txt";
$in_numbers = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  $name = $_POST['name'];
  $in_numbers = $_POST['$in_numbers'];
}

$fd        = fopen($fileg,"r") or die ("Unable to open $file.");
$text     = fread($fd,filesize($fileg));
$wnumbers = preg_split($sepsign,$text); // wnumbers is an array with winning numbers
Fclose($fd);

for ($j = 0; $j < 10; $j++) {
   for ($i = 0; $i < 10; $i++) {
      if ($wnumbers[$i] == $in_numbers[$j])  { $counter++; }
   }
}   // $counter will contain the number of matches on the input

# Append and write the line in a file <number of matches>;<name>;<number 1>;<number 2>; etc

$fdb = fopen($filed,"a+");
fwrite($fdb,$counter . ";" . $name);
for ($i = 0; $i < 10; $i++) {
   fwrite($fdb,";" . $in_numbers[$i]);
}
fwrite($fdb,"\r\n");
fclose($fdb); 
?>
<h2><br>Your input has been stored successfully!</h2>
</body></html>

Results.php:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML><head>
<meta http-equiv="Content-Type" content="text/HTML; charset=iso-8859-1">
<style>
body {  font-family:Times New Roman, Verdana,Geneva; font-size:12px; color:#000000;
    margin-left:20px; background:#F7F5DF; width: 300px; }
H2 { font-family:Times New Roman, Geneva; font-size:16pt; color:#840018; text-align:center; }
</style>
<title>Result</title>
</head><BODY>
<h2>Result of the draw</h2><hr><br>
<?php
$sepsign   = '/;/';
$text     = '';
$filed     = "data.csv";
$fileg     = "numbers.txt";

$fd = fopen($filed,"r") or die ("unable to open $file.");
$text = fread($fd,filesize($filed));
$lines = preg_split("/\r\n/",$text);    // Will split the file data.csv in lines
$count_reg = count($lines);
fclose($fd);
sort ($lines);
reset($lines);

for ($i = ($count_reg - 1); $i>($count_reg-4); $i--) {  // The three highest scores are showed
   $collums = preg_split($sepsign,$lines[$i]);
   print "<b>Name: " . $collums[1] . "<br>";
   print "Number of matches: " . $collums[0] . "</b><br>";
   print "Input: ";
   for ($j = 2; $j < 12; $j++) {
     print $collums[$j];
     if ($j <> 11 ) { print ", "; }  // to prevent the "," to appear after the last number
   }
   print "<br><br>";
}
$fd    = fopen($fileg,"r") or die ("Unable to open $file.");
$text = fread($fd,filesize($fileg));
$wnumbers = preg_split($sepsign,$text);
Fclose($fd);

print "<br><b>Bingo numbers</b><br><hr>";
for ($j = 0; $j < 11; $j++) {
   print $wnumbers[$j];
   if ($j < 9 ) { print ", "; }  // to prevent the "," to appear after the last number 
}
?>
</body></html>

Index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body {  font-family:Times New Roman, Verdana,Geneva; font-size:12px; color:#000000;
    margin-left:20px; background:#F7F5DF; width: 300px; }
H2 { font-family:Times New Roman, Geneva; font-size:16pt; color:#840018; text-align:center; }
</style>
<title>Bingo game, input numbers.</title>
</head><body>
<form action="input.php" method="post" name="form">
<center>
<h2>Input numbers</h2>
lines  &nbsp; <input type="text" name="lines" size=20 maxlength=50><br><br>
Number &nbsp;1 &nbsp;<input type="text" name="$in_numbers[0]" size=4><br>
Number &nbsp;2 &nbsp;<input type="text" name="$in_numbers[1]" size=4><br>
Number &nbsp;3 &nbsp;<input type="text" name="$in_numbers[2]" size=4><br>
Number &nbsp;4 &nbsp;<input type="text" name="$in_numbers[3]" size=4><br>
Number &nbsp;5 &nbsp;<input type="text" name="$in_numbers[4]" size=4><br>
Number &nbsp;6 &nbsp;<input type="text" name="$in_numbers[5]" size=4><br>
Number &nbsp;7 &nbsp;<input type="text" name="$in_numbers[6]" size=4><br>
Number &nbsp;8 &nbsp;<input type="text" name="$in_numbers[7]" size=4><br>
Number &nbsp;9 &nbsp;<input type="text" name="$in_numbers[8]" size=4><br>
Number 10&nbsp;<input type="text" name="$in_numbers[9]" size=4><br><br>
<input type="submit" value="Submit..."></FORM>
</center>
<p />&nbsp;<p />
</body></html>

Share this post


Link to post
Share on other sites
nullschritt

Hello friend! Welcome to autoit. While I don't have the time currently to write an example code for you, I can make some reccomendations which you can look up in the help file.

Depending on if you want the app to work offline, there's two different options I see that you have

The first option is to simply embed the webpage into a gui. (create a GUI then use _IECreateEmbedded) This will allow anyone with an internet connection to access the game.

If you don't wish to require an active internet connection, you can start your job by looking up the following information.

1)To store data (data.cvs and numbers.txt) it's reccomended you use SQLite [_SQLite_Open()], although INI files may work, depending on how much data you plan to store [iniwrite()].

2)Use a InputBox() to request input from the user

3)Process the information the same way you did with php.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • bowker
      By bowker
      Hi! Is there a way for me to set the value for my slider? I am getting the value for my slider with
       
      Local $strText = _UIA_getPropertyValue($oUIElement, $UIA_LegacyIAccessibleValuePropertyId) MsgBox(0,"",$strText)  
    • nacerbaaziz
      By nacerbaaziz
      Hello
      Can we pause and resume the download in the InetGet function?
      If is possible, what is the solution please?
      I used this code To manage the download

      #include <INet.au3> func _downloader($name, $linc, $filepath, $RTLF = false, $link = false) global $downloader = GUICreate("downloader", 400, 200, -1, -1, $WS_CLIPCHILDREn, $RTLF, $link) global $path = $filePath $labelTxt = GUICtrlCreateLabel("downloading " & $name, 50, 10, 200, 20) global $labelTxt0 = GUICtrlCreateLabel("downloaded size 0 MB " & "OF 0 MB", 50, 60, 300, 20) global $Progress = "" global $sText = ""     For $i = 1 To Random(5, 20, 1) ; Return an integer between 5 and 20 to determine the length of the string.         $sText &= Chr(Random(65, 122, 1)) ; Return an integer between 65 and 122 which represent the ASCII characters between a (lower-case) to Z (upper-case). next global $labelTxt2 = GUICtrlCreateInput("0%", 50, 80, 50, 20) _GUICtrlEdit_SetReadOnly(-1, true) GUIStartGroup("") global $beep = GUICtrlCreateCheckBox("use the progress beep notification", 150, 120, 200, 20) GUIStartGroup("") $button = GUICtrlCreateButton("Cancel', 130, 150, 180, 25, 0x01) $iIndex = 0 global $Target global $url GUIStartGroup("") global $Progress = GUICtrlCreateProgress(50, 90, 150, 20) global $Target = $filepath global $url = $linc global $path = $filepath global $hDownloadNo = _RSMWare_GetData($url, $Target) global $status = false AdlibRegister("SetProgress") global $onprogress = false, $curent = false GUISetState(@sw_Show) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $button $asc = MsgBox(4132,"exit download?","if you click yes the downloading will be cancel, do you want to cancel it ?") if $asc = 6 then AdlibUnRegister("SetProgress") GUIDelete() If $hDownloadNo <> 0 Then InetClose($hDownloadNo) exitLoop endIf EndSwitch if $status = -1 then $status = 0 $hDownloadNo = _RSMWare_GetData($url, $Target) $onprogress = false $curent = false elseIf $Status = 1 then $status = $path GUIDelete() AdlibUnRegister("SetProgress") exitLoop endIf WEnd return $status endFunc Func _RSMWare_GetData($url, $Target) Local $hDownload = InetGet($url, $Target, 1, 1) Return $hDownload EndFunc ;==>_RSMWare_GetData Func SetProgress() Local $state If $hDownloadNo <> 0 Then $state = InetGetInfo($hDownloadNo) If @error = 0 Then $infor = "downloaded size " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADREAD) / 1048576), 2) & " MB of " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) / 1048576), 2) & " MB " $onprogress = Round(Ceiling(($state[0] / $state[1]) * 100)) if not (InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) = 0) then if $onProgress <= 0 then $onProgress = 0 GUICtrlSetData($Progress, $onProgress) GUICtrlSetData($labelTxt0, $infor) GUICtrlSetData($labelTxt2, $onProgress & "%") if _isChecked($beep) then if $onprogress > $curent then beep((100 + $onprogress * 20), 100) $curent = $onprogress endIf endIf endIf If $state[2] Then If $state[3] Then InetClose($hDownloadNo) $status = 1 else InetClose($hDownloadNo) $status = -1 endIf endIf EndIf endIf EndFunc ;==>SetProgress
    • drapdv
      By drapdv
      So, I have this odd issue happening with UIAWrappers.  When I run simplespy.au3 through SciTE, it finds the object I'm trying to work with, no problem. But, when I compile simplespy.exe, it can't find it.  Another script that utilizes UIAWrappers is experiencing the same phenomenon. EDIT: Compiling as 32-bit or 64-bit does not affect this behavior.
      The trouble starts at the very first object I try to get via _UIA_getObjectByFindAll, so I included the $properties2Match array and the object properties that were returned by _UIA_getPropertyValue for that first object both when running from SciTE and when compiled.
      It always finds the matches for the title and control type properties.  But when compiled, it fails to find the Automation ID property.  Any ideas as to why this would be happening?  Hoping junkew will see this and have an idea.
       
      These are the $properties2Match
      30005|Screen/PVN - ###.###.##.## - CDK Drive|0|False
      30003|50032|0|False
      30011|Portal|0|False
       
      Object properties when running from SciTE:
      <propertymatching>       
              j:1 propID:[30005] expValue:[Screen/PVN - ###.###.##.## - CDK Drive]actualValue:[Screen/PVN - ###.###.##.## - CDK Drive]1
              j:2 propID:[30003] expValue:[50032]actualValue:[50032]1
              j:3 propID:[30011] expValue:[Portal]actualValue:[Portal]1  
      </propertymatching>
       
      Object properties when script is compiled:
      <propertymatching>
              j:1 propID:[30005] expValue:[Screen/PVN - ###.###.##.## - CDK Drive]actualValue:[Screen/PVN - ###.###.##.## - CDK Drive]1
              j:2 propID:[30003] expValue:[50032]actualValue:[50032]1
              j:3 propID:[30011] expValue:[Portal]actualValue:[]0  
      </propertymatching>
       
    • VollachR
      By VollachR
      Hi,
      I'm looking for a way to take a number value from a Row2 of a 2D array and according to this check if files that appear in rows 3-11 in the array exists.
      For example, if the number in Row2 is 5 I need to check for the files in Row 3-6 only, if it is 6 than rows 3-7 and so on.
      I thought on using a FOR loop but I have very little experience with those.
      Can you suggest the best way to do what I need?
      BTW, the files in Rows 3-11 will usually have blank value for any row above the number in Row2 (e.g. Row2 = 5 so Rows3-6 will have values but 8-11 be empty), The values I need are in Column 1 of the array, the name of the key from the INI file that the array was created from is in Column 0.
      Full Example:
      Row2 of Array:
      Col0 = Games# - Col1 = 5
      Rows3-6
      Col0 = Exe2 - Col1 = Path To File
      Col0 = Exe3 - Col1 = Path To File
      Col0 = Exe4 - Col1 = Path To File
      Col0 = Exe5 - Col1 = Path To File
      I need that if Row2 is 5 to check these above for rows if the file exists, if it was 6 then the next row as well and so on up until number 10 in Row2 as it can't go above 10.
      So basically for whatever number in Row2 from 2-10 need to check 1-9 rows from 3-11 to see if the files in Col1 exists and if any of them don't exist it should call a function that shows an error message.
      I'm pretty sure I have the first line of the for look correct:
      For $i = 1 To $aAIO[2][1] Just not sure how to continue from there, also not sure if $i should be equal 1 or 2.
      Help will be appreciated.
    • VollachR
      By VollachR
      Hi,
      I've written a specialty INI file editor for a specific set of INI files related to a bigger script I'm working on.
      I'm trying to create a verification script that checks the ini files structure and format and gives an error if they are not in expected format.
      What I did so far is create a couple of custom arrays, each with the list of Sections expected in the files and I use IniReadSectionNames in order to read the sections from the selected INI file and compare it to the array.
      It works fine, excepts it only gives an error if one or more of the sections in the custom array is missing, if they all exist but there are other additional sections that shouldn't be there it doesn't give an error and continue to open the editor screen.
      Here are the relevant part of my script:
      The Custom Verification Arrays:
      ;Creating Arrays for INI Verification Global $aSettingsVerify[7] $aSettingsVerify[1] = "Conversion" $aSettingsVerify[2] = "AIO" $aSettingsVerify[3] = "Data" $aSettingsVerify[4] = "Redist" $aSettingsVerify[5] = "Split" $aSettingsVerify[6] = "Autorun" Global $aDataVerify[6] $aDataVerify[1] = "Compression" $aDataVerify[2] = "Exclude" $aDataVerify[3] = "LangExclude" $aDataVerify[4] = "PreCommands" $aDataVerify[5] = "PostCommands" The IniReadSectionNames verification part:
      Case $OK If StringInStr($ActiveConfig, "Settings.ini") Then $CheckArray1 = IniReadSectionNames($ActiveConfig) $CheckArray2 = _ArrayCompare($aSettingsVerify, $CheckArray1) $CheckArray3 = UBound($CheckArray2, 1) If $CheckArray3 = 1 Then GUIDelete($ConfigStart) SettingsGUI() EndIf If $CheckArray3 > 1 Then WrongIni() EndIf EndIf If StringInStr($ActiveConfig, "Data") Then $CheckArray1 = IniReadSectionNames($ActiveConfig) $CheckArray2 = _ArrayCompare($aDataVerify, $CheckArray1) $CheckArray3 = UBound($CheckArray2, 1) If $CheckArray3 = 1 Then GUIDelete($ConfigStart) DataGUI() EndIf If $CheckArray3 > 1 Then WrongIni() EndIf EndIf The Function that performs the compare: (Found it in another thread on this forums somewhere by using Google Search)
      ;Compares Imported INI file with the Verification array Func _ArrayCompare(ByRef $a1, ByRef $a2) Local $nOldSize = UBound($a2) Local $a3[$nOldSize], $nNewSize = $nOldSize For $i = 0 To UBound($a1) - 1 For $j = 0 To $nOldSize - 1 If Not $a3[$j] And ($a1[$i] = $a2[$j]) Then $a3[$j] = 1 $nNewSize -= 1 EndIf Next Next Local $a4[$nNewSize], $j = 0 For $i = 0 To $nOldSize - 1 If Not $a3[$i] Then $a4[$j] = $a2[$i] $j += 1 EndIf Next Return $a4 EndFunc ;==>_ArrayCompare  
      Any way to make a check if there are sections other than the ones in the Verification Array and produce an error?
      Thanks
×