To edit the names, we’ll use a crude but effective method: direct editing! Incorporating the editing into a form will make it less daunting, however. Observe the following code:
First, the user should pick the list to edit:
picklist.php3
<html><head><title>Pick the list</title></head><body>
<center>
<br><br>
Please pick the list you would like to edit:
<br>
<form method=post action="editnames.php3">
<select name="List" size=4>
<?
$fileloc = "lists.txt";
$groups = file("data/lists.txt");
for ($index=0; $index < count($groups); $index++)
{
$grouplist = split("\|", chop($groups[$index]));
?>
<option value="<? echo $grouplist[1] ?>"
<? if ($index==0)
{echo "selected";} ?>>
<? echo $grouplist[0] ?><br>
<?
}
?>
</select>
<br><br>
<input type="submit" value="Edit list"></form></center>
</body></html>
Then, a form is created to allow editing and deleting of the
names:
editnames.php3
<html><head><title>Edit Maillist addresses</title></head><body>
<form method=post action="writenamefile.php3">
<br>
Editing <? echo $List ?>.
<br><br>
Fix an address by editing in place, or delete an address
by deleting the WHOLE line. <b>No blank lines or spaces allowed! </b>
<br><br><textarea cols=50 rows=20 name="Body">
<?
if (file_exists("data/$List"))
{readfile("data/$List");}
?>
</textarea>
<br><br>
<input type="hidden" name="List" value="<? echo $List ?>">
<input type="submit" name="submit" value="Save This List"></FORM>
<br><br><a href="addnames.php3">Add names to the list</a>.
<br><br><a href="data/log.txt">View Send Log</a>.
<br>
</body></html>
The readfile function (line 8) reads in a file and
directly sends in to the browser. This places all the addresses for the specified list into a textbox, where they can be deleted or fixed directly. Also, note the warnings about one address to a line, something to remind the administrator about what’s right and wrong. The next script saves all the changes:
This was just as easy as reading the file in! Since the whole
list was in the textbox, it is all included in the variable $Body, newlines and all. Writing $Body to the file saves the entire thing exactly as it looked in the previous form.