Jump to content

Generating a dinamic file problem


GridCube

Recommended Posts

Hello, I've just started using PHP in last few weeks. I did so because I wanted to create a Testing Interface for the Xubuntu Developement Channels on irc.freenode.net, this was my idea and I'm the solely responsable for it. If I can make it work like its sopose to they might consider using it.

 

The Interface works, it stores daily tests from users and recovers it in a rather simple way.

 

But now I need/want to create a way for the Team Leader to add scheluded tests for particular days, so I'm bassically adding a:

 

<?php 
$etad = date('Fd');
include './sch/$etad.htm';
?>

 

into one of my page table entries. And then what I'm doing is to create a FORM that aks for a Month and a Day, and then 16 selects named Sch[1-16], an All CheckBox, and an Announcements text area. What I want to do whit it is to send the form to a php script that will take all that info and create a

MonthDate.htm
file into the ./sch folder.

 

 

I started simple to see if stuff worked and so far i have:

 

<?php

$MONTH = $_POST['MONTH'];
$DAY = $_POST['DAY'];
if (!$MONTH) { include "../fail.htm";}
 elseif (!DAY) { include "../fail.htm";}
 else {	$filename = "$MONTH$DAY.htm";}

$SCH1 = 	$_POST['SCH1'];
$SCH2 = 	$_POST['SCH2'];		
$SCH3 = 	$_POST['SCH3'];
$SCH4 = 	$_POST['SCH4'];
$SCH5 = 	$_POST['SCH5'];
$SCH6 = 	$_POST['SCH6'];
$SCH7 = 	$_POST['SCH7'];
$SCH8 = 	$_POST['SCH8'];
$SCH9 = 	$_POST['SCH9'];
$SCH10 = 	$_POST['SCH10'];
$SCH11 = 	$_POST['SCH11'];
$SCH12 = 	$_POST['SCH12'];
$SCH13 = 	$_POST['SCH13'];
$SCH14 = 	$_POST['SCH14'];
$SCH15 = 	$_POST['SCH15'];
$SCH16 = 	$_POST['SCH16'];
$ALL	=	$_POST['ALL'];
$ANNOUN	=	$_POST['ANNOUN'];

if ( $ALL ) { 
$Content = "<h3><font color='#1E90EE'>Every Single Test! DO THEM ALL!</font></h3>
For Instructions on how to do this tests please go to:<br />
<a href='http://testcases.qa.ubuntu.com/Install'>Ubuntu Tests Cases</a><br />
<br />
<p>$ANNOUN</p><br />";
}
else {
$Content = "nope";
}

	echo "open";
	$handle = fopen($filename, 'x+');
	echo " write";
	fwrite($handle, $Content);
	echo " close";
	fclose($handle);


?>

 

This works, but now im facing all the SCH[1-16] variables, they are test cases names, each SCH can be up to 24 different options, each one related to a "how to test" web page.

 

I could add

<?php
if (!$SCH1) { $1HCS = NULL; } 
elseif ($SCH1 = "TestCase1") { $1HCS = "Test Case 1, <a href='link.to.test.com'>How to test</a>";}
elseif (....
?>

 

and so on for the 24 test cases, and for the 16 selects!

 

this is not very productive, and im sure there is a better way of doing it, but as I'm so new to this world I can't see another solution.

 

So hereby I come to ask for guideness to you people.

 

:) any help you can give will be greatly appreciated

Link to comment
Share on other sites

this:

include './sch/$etad.htm';

will not work, because php will not interpret variables inside single quotes. You can either do this:

include './sch/'.$etad.'.htm';

or use double quotes:

include "./sch/$etad.htm";

 

Yes, thank you, It was my mistake when writing this message, I have actually the last one of your options on my page, sorry for my mistake. :) thank you for answering.

Link to comment
Share on other sites

since all the selectable options are checkboxes, and unchecked boxes DO NOT get sent in a form, checking for the existence of each one is redundant.

 

But I'm not sure I get exactly what your objective is.

 

You want to grab all selected checkbox names, and store them in a file?

Link to comment
Share on other sites

since all the selectable options are checkboxes, and unchecked boxes DO NOT get sent in a form, checking for the existence of each one is redundant.

 

But I'm not sure I get exactly what your objective is.

 

You want to grab all selected checkbox names, and store them in a file?

 

I have two pages, one is called TestCenter.html, and inside of it it has an entry that shows something like:

 

<b>This are the tests meant for today:</b><br />
<?php
$etad = date("Fd");
include "./sch/$etad.htm";
?>

 

then on another page, stored on ./shc/ i have a Formularie that has Select type of options, not checkboxes, and I want that on the SEND of that form a MonthDate.htm file gets created, in which all the test cases choosen get named and linked to the proper guide.

 

Hope that answers your question.

Link to comment
Share on other sites

ok, so you basically want to create a new file and put a line like this:

"Test Case 1, <a href='link.to.test.com'>How to test</a>"

inside the created file for each selected case...

 

 

Can you post the exact code where your forms are? (one of the files in ./shc/)

 

For one of the files you meant the ones called MonthDay.htm?

 

if thats it this is one:

 

September19.htm

32bit Live CD [<a href="http://testcases.qa.ubuntu.com/Install/DesktopLiveSession">How to test</a>]<br />
32bit Desktop Entire Disk [<a href="http://testcases.qa.ubuntu.com/Install/DesktopWhole">How to test</a>]<br />
32bit Alternate Entire Disk whit Encryption [<a href="http://testcases.qa.ubuntu.com/Install/AlternateEncryptedLvm">How to Test</a>]<br />
64bit Live CD [<a href="http://testcases.qa.ubuntu.com/Install/DesktopLiveSession">How to test</a>]<br />
64bit Desktop Entire Disk [<a href="http://testcases.qa.ubuntu.com/Install/DesktopWhole">How to test</a>]<br />
64bit Alternate Entire Disk whit Encryption [<a href="http://testcases.qa.ubuntu.com/Install/AlternateEncryptedLvm">How to Test</a><br />
<br />
<font color="#1E90FF">Remember Beta 2 will be up in 1 days!</font><br />

 

as this goes on an include inside of another html i tried to make it the most clean posible.

Link to comment
Share on other sites

no, what I need to see is the file you include with the form where the users get to select values from the dropdown menus (<select> elements)

 

oh okay :) this is it:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type">
  <title>Admin Area</title>
  <style type="text/css">
body {
	color: rgb(0, 0, 0);
	background-color: rgb(162, 205, 226);
	background-image: url(../deg.png);
	font-family: Courier New,Courier,monospace;
	onload="stampForm()";
	background-attachment:fixed;
}
</style>
  <link media="testcase" rel="stylesheet" href="sea.css" type="text/css">
<link rel="icon" 
      type="image/png" 
      href="../favicon.png">
</head>

<body>

<div style="text-align: center; font-family: Calibri;">
<a href="http://www.xubuntu.org/"><img 	border="0" 
			alt="Xubuntu Logo" 
			title="Xubuntu is a free operative system" 
			src="../xubuntu.png" 
			style="width: 500px; height: 100px;" 
	/></a>
<br />
<h3 style="text-align = center; color = blue;">Welcome to the admin area</h3>
<h4>Here you can edit the day schedule that will be shown at the main screen</h4>
<br />
<table
style="	width: 646px; 
		height: 86px; 
		text-align: left; 
		margin-left: auto; 
		margin-right: auto;"
border="0" 
cellpadding="0" 
cellspacing="0">
<tbody>
<form method="POST" action="schfile.php">
	<tr><td colspan="2"><p>You don't have to use all boxes, only obligatories ones are Month and Date.</p></td></tr>
	<tr>
		<td>
		<b>Month:</b>
			<select name="MONTH">
				<option></option>
				<option>January</option>
				<option>February</option>
				<option>March</option>
				<option>April</option>
				<option>May</option>
				<option>June </option>
				<option>July</option>
				<option>August</option>
				<option>September</option>
				<option>October</option>
				<option>November</option>
				<option>December</option>
			</select>
		</td>
		<td>
		<b>Day:</b>
			<select name="DAY">
				<option></option>
				<option>1</option>
				<option>2</option>
				<option>3</option>
				<option>4</option>
				<option>5</option>
				<option>6</option>
				<option>7</option>
				<option>8</option>
				<option>9</option>
				<option>10</option>
				<option>11</option>
				<option>12</option>
				<option>13</option>
				<option>14</option>
				<option>15</option>
				<option>16</option>
				<option>17</option>
				<option>18</option>
				<option>19</option>
				<option>20</option>
				<option>21</option>
				<option>22</option>
				<option>23</option>
				<option>24</option>
				<option>25</option>
				<option>26</option>
				<option>27</option>
				<option>28</option>
				<option>29</option>
				<option>30</option>
				<option>31</option>
			</select>
		</td>
	</tr>
	<tr> <td colspan="2"><p>Now please choose what tests are meant for this day.</td></tr>
	<tr>
		<td>
		<select name="SCH1">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
		<td><select name="SCH2">
<?php include "./opt.htm"; ?>
			</select><br>

		</td>
	</tr>
	<tr>
		<td>
		<select name="SCH3">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
		<td><select name="SCH4">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
	</tr>
	<tr>
		<td><select name="SCH5">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
		<td><select name="SCH6">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
	</tr>
	<tr>
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
		<td><select name="SCH8">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
	</tr>
	<tr>
		<td><select name="SCH9">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
		<td><select name="SCH10">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
	</tr>
	<tr>
		<td><select name="SCH11">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
		<td><select name="SCH12">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
	</tr>
	<tr>
		<td><select name="SCH13">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
		<td><select name="SCH14">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
	</tr>
	<tr>
		<td><select name="SCH15">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
		<td><select name="SCH16">
<?php include "./opt.htm"; ?>
			</select><br>
		</td>
	</tr>
	<tr>
		<td><p>Or maybe All of Them?</p>
		</td>
		<td><input type="checkbox" name="ALL" value="ALL">
		</td>
	</tr>
	<tr>
		<td>Now if you have some commentaries or anouncements you want to do, add them here:
		</td>
		<td><textarea cols="30" rows="2" name="ANNOUN"></textarea>
		</td>
	</tr>
	<tr>
		<td><p> </p>
		</td>
		<td><p> </p>
		</td>
	</tr>
	<tr>
		<td><p>Remember, if you hit submit it will replace any exisiting file for that Month and Day, so be careful please.</p>
		</td>
		<td align="center"><input  type="submit" align="right" />	
		</td>
	</tr>
</form>	
  </tbody>
</table>
</body>
</html>

 

the opt.htm is this:

				<option></option>
					<optgroup label="i386">
						<option>32bit Live CD	                </option>
						<option>32bit Desktop Entire Disk	    </option>
						<option>32bit Desktop Manual Partition	</option>
						<option>32bit Desktop Auto-Resize	    </option>
						<option>32bit Desktop OEM Setup	        </option>
						<option>32bit Desktop Free Software	                </option>
						<option>32bit Alternate Entire Disk whit Encryption	</option>
						<option>32bit Alternate Entire Disk	                </option>
						<option>32bit Alternate Auto-Resize       </option>
						<option>32bit Alternate Manual Partition  </option>
						<option>32bit Alternate Free Software	  </option>
						<option>32bit Alternate OEM Setup	      </option>
					</optgroup>
					<optgroup label="AMD64">
						<option>64bit Live CD	                  </option>
						<option>64bit Desktop Entire Disk	      </option>
						<option>64bit Desktop Manual Partition	</option>
						<option>64bit Desktop Auto-Resize	    </option>
						<option>64bit Desktop OEM Setup	        </option>
						<option>64bit Desktop Free Software	                  </option>
						<option>64bit Alternate Entire Disk whit Encryption	  </option>
						<option>64bit Alternate Entire Disk	                  </option>
						<option>64bit Alternate Auto-Resize	        </option>
						<option>64bit Alternate Manual Partition    </option>
						<option>64bit Alternate Free Software	    </option>
						<option>64bit Alternate OEM Setup </option>
					</optgroup>

 

and the schfile.php is the same i already posted

<?php

$MONTH = $_POST['MONTH'];
$DAY = $_POST['DAY'];
if (!$MONTH) { include "../fail.htm";}
 elseif (!DAY) { include "../fail.htm";}
 else {	$filename = "$MONTH$DAY.php";}

$SCH1 = 	$_POST['SCH1'];
$SCH2 = 	$_POST['SCH2'];		
$SCH3 = 	$_POST['SCH3'];
$SCH4 = 	$_POST['SCH4'];
$SCH5 = 	$_POST['SCH5'];
$SCH6 = 	$_POST['SCH6'];
$SCH7 = 	$_POST['SCH7'];
$SCH8 = 	$_POST['SCH8'];
$SCH9 = 	$_POST['SCH9'];
$SCH10 = 	$_POST['SCH10'];
$SCH11 = 	$_POST['SCH11'];
$SCH12 = 	$_POST['SCH12'];
$SCH13 = 	$_POST['SCH13'];
$SCH14 = 	$_POST['SCH14'];
$SCH15 = 	$_POST['SCH15'];
$SCH16 = 	$_POST['SCH16'];
$ALL	=	$_POST['ALL'];
$ANNOUN	=	$_POST['ANNOUN'];

if ( $ALL ) { 
$Content = "<h3><font color='#1E90EE'>Every Single Test! DO THEM ALL!</font></h3>
For Instructions on how to do this tests please go to:<br />
<a href='http://testcases.qa.ubuntu.com/Install'>Ubuntu Tests Cases</a><br />
<br />
<p>$ANNOUN</p><br />";
}
else {
$Content = echo "error"
}

	echo "open";
	$handle = fopen($filename, 'x+');
	echo " write";
	fwrite($handle, $Content);
	echo " close";
	fclose($handle);


?>

 

guess thats all

Link to comment
Share on other sites

you cannot just use:

<option>64bit Live CD</option>

you need something like:

<option value="64bit Live CD">64bit Live CD</option>

so that the value gets sent over with the form.

 

I haven't done that on any of the forms I already have working, I guess it wont harm to have that included, but I've never used and haven't had any problems yet. Thank you for the warning anyway, it's always good to learn safety protocols :)

 

EDIT: also this is a Select, so the Value of the Select is the Option, I don't see why i should say to it twice that the Select Optioned Value is a Value?

Link to comment
Share on other sites

actually...

I just tried your <option></option> without the value and it does get sent... sorry.

Never seen it done that way before, cause i've always used the value="xxx", mainly because my values are always different from the label I display.

:D It's okay then

Link to comment
Share on other sites

anyway... getting back to your problem... try something like this:

 

$toFile = '';
foreach($_POST as $k=$v){
   if($v != '' && $k != 'ANNOUN'){
      $toFile .= $v.', <a href="link.to.test.com">How to test</a>'."<br />\n";
   }
}
echo $toFile;

 

this seems very nice... The problem is that I didn't make myself clare enough, each test case has its own testing protocol, you can see all the protocol pages here; http://testcases.qa.ubuntu.com/Install ; we just do the Desktop and Alternate ones, but they are many, so:

 

<?php
if ( $_POST['SCH1'] == "64bit Alternate Manual Partition" ) { $toFile = "64bit Alternate Manual Partition <a href='http://testcases.qa.ubuntu.com/Install/AlternateManual'>how to test</a><br />";}
elseif ( $_POST['SCH1'] == "32bit Desktop OEM" ) { $toFile = "32bit Desktop OEM <a href='http://testcases.qa.ubuntu.com/Install/DesktopOem'>How to test</a><br />";}

...
?>

 

so each of your proposed IF have to be different, because if $v is one of the 24 posible options it has to be paired whit its correspondent link.

 

 

Link to comment
Share on other sites

Ok, so, I figured a way to do what i want to do.

 

The Idea came thanks to WebStyles asking me to pass a value on the options, and I though, well, I do want to have an asociation of links to particular options!

 

so i changed my opt.htm to be something like this:

 

<option></option>
   <optgroup label="i386">
<option value="32bit Live CD [<a href='http://testcases.qa.ubuntu.com/Install/DesktopLiveSession'>How to test</a>]">32bit Live CD </option>
...

 

So now every Select sends its own html strings to the POST!

 

:D

 

now im trying to do

 

<?php

$MONTH = $_POST['MONTH'];
$DAY = $_POST['DAY'];
if (!$MONTH) { include "../fail.htm";}
 elseif (!DAY) { include "../fail.htm";}
 else {	$filename = "$MONTH$DAY.htm";}

$Content = '';
	foreach( $_POST as $k=>$v ){
		if($v != '' && $k != 'ANNOUN')	{ 
			$Content .= $v."<br />\n";
						}	
				}



	echo "open";
	$handle = fopen($filename, 'x+');
	echo " write";
	fwrite($handle, $Content);
	echo " close";
	fclose($handle);


?>

 

But its saving this kind of result:

January

7

32bit Live CD [How to test]

 

32bit Live CD [How to test]

 

32bit Live CD [How to test]

 

ALL

 

I don't want the January nor the 7 (that are the Month and Date) neither i want the "ALL" but i do want the ANNOUN that is not added.

 

:D

 

thank you for your help so far it has been really useful.

Link to comment
Share on other sites

:) good evening people, so I keep trying to do this :D

 

 

I figured out yesterday's problem, I neede to do this:

 

<?php

$YEAR = $_POST['YEAR'];
$MONTH = $_POST['MONTH'];
$DAY = $_POST['DAY'];
if (!$MONTH) { include "../fail.htm";}
 elseif (!DAY) { include "../fail.htm";}
 elseif (!YEAR) {include "../fail.htm";}
 else {	$filename = "$YEAR$MONTH$DAY.htm";}

$Content = '';
	foreach( $_POST as $k=>$v ){
		if($v != '' && $k != 'YEAR' && $k != 'MONTH' && $k != 'DAY')	{ 
			$Content .= $v."<br />\n";
						}	
				}

	echo "This is";
	$handle = fopen($filename, 'x+');
	echo " what has";
	fwrite($handle, $Content);
	echo " Been Stored:<br /><br />";
	fclose($handle);
                include "./$YEAR$MONTH$DAY.htm";

?>

 

Yes I added a $YEAR.

 

This IS working, however its creating an html whit this syntaxis;

 

32bit Live CD [<a href=\'http://testcases.qa.ubuntu.com/Install/DesktopLiveSession\'>How to test</a>]
32bit Desktop Entire Disk
<br /><font color=\"green\">This is a test</font><br />

 

as you can see its adding a \ inside the href, which very efectibly breaks the destination URL.

 

i've tried changing the opt.htm to look like this:

 

<option></option>
					<optgroup label="i386">
						<option value="32bit Live CD [<a href=&#039;http://testcases.qa.ubuntu.com/Install/DesktopLiveSession&#039;>How to test</a>]">32bit Live CD </option>
...

 

or changing ' for ", but every time I get the same results.

 

Is there a way I can avoid this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.