Presentation is loading. Please wait.

Presentation is loading. Please wait.

Video list editor BIS1523 – Lecture 24.

Similar presentations


Presentation on theme: "Video list editor BIS1523 – Lecture 24."— Presentation transcript:

1 Video list editor BIS1523 – Lecture 24

2 Video List In a previous class we designed a web page that would allow the user to view lists of videos. The lists were contained in files, and the videos displayed in iframes. The file system containing the data was in 2 levels. One file (menulist.txt) contained a list of categories. Each category had a title, and a filename.

3 File Structure Menulist.txt:
Each line in menulist.txt was a file that also contained a title, and a URL to be loadd in the iframe. Example: mup1.txt In todays program, we want to design a program that will let the user edit menulist.txt, add or remove categories, as well as edit the individual category files.

4 General List Editing In order to allow the user to edit a list of things, we are going to display the list on the screen, inside a text input area that will allow them to change the values presented. We will also add in a few blank lines, which will allow the user to add new entries, should they wish. Then, when user submits the form, we simply loop through each row of the data, and use that to update the file.

5 Initial Output We start by going through the input file, and listing each item in it in a text area. Load the file into the array $menulist, loop through each row, splitting it at the comma into the short array $fields.

6 Adding Lines We also want to add some blank lines sot he user can add new entries:

7 HTML Created

8 Parameters In order to update the file, we need a list of categories and a list of files associated with them. In the above HTML, those lists are passed as the arrays cat[] and catfile[]

9 Parameters The cat and catfiles arrays are “parallel”, that is, row 0 contains the 2 entries to go on to the first line file. Row 1 contains the next name/file pair, etc.

10 Writing the Category File
We do not have to save the old file, each time the user updates it, we rewrite the file. Thus, we want to erase the file first. To write the category file, we loop through the entire list that was submitted. file_put_contents can use the APPEND mode to add a line to the bottom of the file

11 Editing Categories We would also like the user to be able to edit an individual category. The actual editing is similar to category list, we list out the current data in text inputs, withs ome blank lines. First though, we need to set up a system so the “edit specific category” area knows which category to access.

12 Passing Category # We would like to have an individual button for each category, to allow the user to pick which one to edit To do this, we will give every button a different name. Using a $count variable, this will name the buttons Cat0, Cat1, etc.

13 HTML Generated When any submit button is selected the “name” is sent along with its value. So, for example, if the user clicks the Cat0 button, a $_POST[Cat0] will exist with the value “Edit Category”

14 Finding Which Button We can then query the $_POST array to see if a particular row exists. We just loop through each row of the cat array and see if CAT$i exists with an if statement If it exists, we want to print out the HTML that will allow us to edit it:

15 Editing HTML

16 Updating A Category If the user selects a category to update, we pass the list for that category in the arrays titles[] and links[] We also put a hidden field on that page as the file name for that category. So, when the program is submitted, we can query those arrays and that item to see if we need to update a category

17 Updating a Category File
The process is similar to the menulist.txt update. We erase the file with the unlink command, loop through every title, and then append each row of titles and links to that file.


Download ppt "Video list editor BIS1523 – Lecture 24."

Similar presentations


Ads by Google