Forum Moderators: coopster
Is it possible to update a javascript menu from what is input into the form which uses php. See I have a photo gallery and the person posting into it needs to also go in by hand and enter the javascript for the new links on another site. The boss wants to automate this so that the person entering the promotions does not have to access these other files or know javascript. (These are 2 different sites even though they are for the same company. One is for internal and one is for external people.)
I figure it is probably possible if you put the links into MySQL but that would take a lot of programming to redo the whole site. He wants something that would not take a lot of time or big rewrite. Any ideas?
Thanks in advance!
Sure, you can automate that with php and no mysql. In addition to generating content to send to people's browsers, you can use php to manipulate your own files. Use a function like file_get_contents [us3.php.net] (other Filesystem [us3.php.net] functions) to read the content of your javascript file, append the info, then file_put_contents [us3.php.net] to save the modified information. Depending on how the javascript is laid out, you may want to manually put in some markers to look for:
// Begin menu
var item1 = open_window('joseph');
var item2 = jump_menu('billy');
// End menu
Then you can look for "// End menu" so you know where to make the insertion.
I think I need to look at this more closely. There is a js file which has all the menu items in it that also needs to be updated along with the inline javascript on the index.php file. I need to find out if there is a reason why the js file isn't just being used in both the main page and all the following pages. It does not make sense to me that the main page would not use the same js file instead of having it inline.
It's still do-able, though, you'll just modify two places if that's how it's going to be; you can use php to modify a php file, it's all just letters and numbers...
The tricky part is figuring out the logic to pin down where the modification needs to be made, and definitely keep backups until the script is debugged (yes that's from direct experience)! That's why I suggest inserting markers.
But the boss does not want to put a lot of work (expense to the client) into getting this done.