Forum Moderators: coopster
First - I am a complete noob at PHP and HTML, and that's why I'm stuck!
I'm trying to make a slight modification to a Joomla component called "Chordbase". What it does, is the ability to have a database of songs - with song lyrics and guitar/piano chords shown. It shows a list of songs (by name), and by clicking a songname - it displays the songlyrics (with chordnames above the songtext).
Now; I'm adding an extra functionality to Chordbase. The function I'm trying to make - is to have the chords shown [u]below[/u] the song, as chord-images. By the help of a dropdown-box (select-box), one can choose between one of these:
- dont show chord-images
- show guitar chord images
- show piano chord images
I've gotten so far where I it actually works- in sense of that I can choose i.e. "Show guitar chords" and press the "Update" button (behind the select-box). Then, the chords ARE shown below the song! The trouble comes when I press "Printer friendly".... I will come back to that in a minute!
Most of the "action" going on in this Joomla-component, is divided into these php-scripts:
chordbase.php (the "main" program)
chordbase.html.php (makes the top-screenpart of the songview - where it gives a "menu" with different options,
like "Printer friendly" or "Edit song".... and so on... IT'S HERE I ADDED MY DROPDOWN-BOX).
song.class.php (displays the songtext / chordnames. IT'S IN HERE I ADDED THE CODE TO DISPLAY
CHORD-IMAGES).
In a function called "function songHeader" in "Chordbase.html.php" I've added the code like this:
<form action="index.php?option=com_chordbase&Itemid=<?php echo $Itemid?>&task=viewSong&song_id=<?php echo $song_id?>&pop="0"" method="post">
<select name="showchords"> <option value="dontshow" >Don't show chords</option>
<option value="showguitar">Show guitar chords</option>
<option value="showpiano">Show piano chords</option> -->
<input type="submit" name="submit" value="Update">
</select>
So far, so good.... BUT --- and here's a HUGE trauma (yes, I'm almost going nuts here):
-> When I choose "Printer friendly" and the song shows up in a new window- the chords are gone!
I've so far found out this:
When I select "Printer friendly" - ALL variables I'm using for checking whether chords are going to be shown or not - they are RESET (null-value).
I've added the variable $_POST['showchords'] in function "song.class.php" to check/evaluate if the chord-images are going to be shown (it's in this function I've added some programming to show the chord-images). Each time "Printer friendly" is called - [u]this variable is EMPTY[/u].
Another thing (this is maybe one major reason for this problem):
- usually, when the song itself is shown - it calls up Joomla's "index.php" - i.e. like this:
index.php?option=com_chordbase&Itemid=<?php echo $Itemid?>&task=viewSong&song_id=<?php echo $song_id?>&pop="0" But, when "Printer friendly" is called - Chordbase does this by calling Joomla's "index2.php", like this:
<?php echo $mosConfig_live_site?>/index2.php?option=com_chordbase&Itemid=<?php echo $Itemid?>&task=viewSong&showChords=<?php echo $showChords == "no"?"no":"yes"?>&song_id=<?php echo $song_id?>&pop=1" target="_blank">Printer friendly</a>]
So, I assume that because of the different approach of calling the function for showing the song (in "song.class.php") - it looses all knowledge of the content of this variable i mentioned further above...
How to deal with this - is far, far beyond my knowledge and skills :(
HOW in the world can I get it to REMEMBER that I chose "Show guitar chords" when I select "Printer friendly"?
I've tried absolutely "everything" my ignorant mind could find on the internet (Google)...
- koda
I thought of using SESSIONS - but I have trouble with understanding how to use it. I have read several places about it - but so far I've not understood how to use it and where to place these SESSION-variables. I became a bit confused when I read about it - because it seemed to be different ways to use it... sorry about that, but I am still in an early learning process...
In which of the php-scripts do I have to put something in? I would be glad for some examples... :)
-koda
It surprises me how many people bother to code 2 different complete pages, when they could just use different CSS (for the really lazy 1 CSS file with @media rules in). Sometimes there is a reason...most of the time there isnt, CSS may well save you a lot of hassle.
I'm sure it's possible to use CSS here, but then I'm into deep, deep water..... - this is something I haven't dug into yet... But, I appriciate your suggestion - I can understand that it many times would be a smart way of handling things like this...
As far as I can see in the original php code - where the "menu" link for "Printer friendly" is; it re-uses the same code for displaying the songtext - but it calls it thru "index2.php" (Joomla's php-script) - instead of "index.php" - which it normally uses (also a part of Joomla). I've found out that "index2.php" gives a page WITHOUT the Joomla template and menus (hence; a blank page)...
So, I thought it would be better for me not to hazzle too much with the original code - I would for sure make it a lot worse...
<?php session_start() ?> The variable $_POST['showchords'] I then save in $_SESSION['willshowchords'] --IF-- the $_POST['showchords'] is NOT empty.
I'm out of ideas.... such a thing SHOULD be possible (preserving a variable "no matter what")?
The problem with trying to use php with printing is that printing is a client side thing. As php is a server side thing you have to jump through more hoops to use php for a client side thing. Using CSS will allow you to print out whatever is displayed on the page at the time when the person clicks print...no additional page calls, no worrying about displaying the correct thing. The click print and get what you want them to get.