Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Dynamically Selecting Default Option on a Dropdown Menu  (Read 4148 times)

0 Members and 1 Guest are viewing this topic.

jeepguy_1980

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 94
    • Loop Family Forum & Gallery
Dynamically Selecting Default Option on a Dropdown Menu
« on: March 17, 2009, 07:16:52 pm »

I modified the sort cell in a theme I picked up from DaMysterious. I made it into a drop down menu so that the text wouldn't run off of the top of the table.  I would like to know how I can setup my drop down menu to automatically select the default sort order that I have in my CPG configuration.

Thank you.

Code: [Select]
// HTML template for title row of the thumbnail view (album title + sort options)
if (!isset($template_thumb_view_title_row)) { //{THEMES}
$template_thumb_view_title_row = <<<EOT

                        <table width="100%" cellpadding="4" cellspacing="0">
                        <tr>
                                <td width="100%" class="statlink"><h2>{ALBUM_NAME}</h2></td>
                                <td><img src="images/spacer.gif" width="1" alt="" /></td>
                                <td class="sortorder_cell">
<form name="sort">
<select name="sortbox" OnChange="location.href=sort.sortbox.options[selectedIndex].value">
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=ta">{TITLE} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=td">{TITLE} -</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=na">{NAME} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=nd">{NAME} -</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=da">{DATE} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=dd">{DATE} -</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=pa">{POSITION} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=pd">{POSITION} -</option>
</select>
</form>
                               
                                </td>
                        </tr>
                        </table>

EOT;
}  //{THEMES}
Logged

jeepguy_1980

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 94
    • Loop Family Forum & Gallery
Re: Dynamically Selecting Default Option on a Dropdown Menu
« Reply #1 on: March 17, 2009, 07:21:53 pm »

I changed it to this for now:

Code: [Select]
// HTML template for title row of the thumbnail view (album title + sort options)
if (!isset($template_thumb_view_title_row)) { //{THEMES}
$template_thumb_view_title_row = <<<EOT

                        <table width="100%" cellpadding="4" cellspacing="0">
                        <tr>
                                <td width="100%" class="statlink"><h2>{ALBUM_NAME}</h2></td>
                                <td><img src="images/spacer.gif" width="1" alt="" /></td>
                                <td class="sortorder_cell">
<form name="sort">
<select name="sortbox" OnChange="location.href=sort.sortbox.options[selectedIndex].value">
<option>Sorting Order</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=ta">{TITLE} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=td">{TITLE} -</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=na">{NAME} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=nd">{NAME} -</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=da">{DATE} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=dd">{DATE} -</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=pa">{POSITION} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=pd">{POSITION} -</option>
</select>
</form>
                                                                </td>
                        </tr>
                        </table>

EOT;
}  //{THEMES}

Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Dynamically Selecting Default Option on a Dropdown Menu
« Reply #2 on: March 18, 2009, 07:34:13 am »

Perform a check against $CONFIG['default_sort_order']
Don't forget to make that array global first inside a function.
Are you actually populating the placeholder tokens in theme_display_thumbnails() or is above code just wishfull thinking?
Logged

jeepguy_1980

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 94
    • Loop Family Forum & Gallery
Re: Dynamically Selecting Default Option on a Dropdown Menu
« Reply #3 on: March 18, 2009, 05:40:57 pm »


Thanks, I'll give that a try.

Are you actually populating the placeholder tokens in theme_display_thumbnails() or is above code just wishfull thinking?


The code works exactly as I hoped.  See here: www.loopfamily.net/CPG/  You can see it work on any gallery.

Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Dynamically Selecting Default Option on a Dropdown Menu
« Reply #4 on: March 19, 2009, 08:16:54 am »

Works as expected, thanks. Looks promising - you might consider to post your entire mod for the benefit of others.
Logged

jeepguy_1980

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 94
    • Loop Family Forum & Gallery
Re: Dynamically Selecting Default Option on a Dropdown Menu
« Reply #5 on: March 20, 2009, 06:23:51 am »

That is my entire mod, with the exception of a slight change I made to the stylesheet.css to get the drop down menu to line up a bit cleaner.

I have never written anything in PHP and don't know anything about it.  I am willing to post this mod to help others, but I would first like to make it display the sorting order used (i.e. the default sort order).

I have tried using the following code to display the the default sort order, but it's not working.

Code: [Select]
<form name="sort">
$sortarr = Array("ta","td","na","nd","da","dd","pa","pd");
$i = 1;
echo "<select name=\"sortbox\" size=1 OnChange=\"location.href=sort.sortbox.options[selectedIndex].value\">";
while($i !=  8){
     $r = mysql_fetch_array($CONFIG['default_sort_order']);
     if($r['default_sort_order'] == $sortarr[$i]){
          $selected = "selected";
            }
     else{
          $selected = "";
            }
     echo "<option value=\"thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=.$sortarr[$i].\" ".$selected.">".$sortarr[$i]."</option>";
     $i++
     }
     echo "</selected>";
</form>
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Dynamically Selecting Default Option on a Dropdown Menu
« Reply #6 on: March 20, 2009, 06:33:30 pm »

It can not possibly work because it contains syntax errors - you're mixing HTML and PHP, which is something you can't do. Haven't looked at your code, but
Code: [Select]
echo '<form name="sort">';
$sortarr = Array("ta","td","na","nd","da","dd","pa","pd");
$i = 1;
echo "<select name=\"sortbox\" size=1 OnChange=\"location.href=sort.sortbox.options[selectedIndex].value\">";
while($i !=  8){
     $r = mysql_fetch_array($CONFIG['default_sort_order']);
     if($r['default_sort_order'] == $sortarr[$i]){
          $selected = "selected";
            }
     else{
          $selected = "";
            }
     echo "<option value=\"thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=.$sortarr[$i].\" ".$selected.">".$sortarr[$i]."</option>";
     $i++
     }
     echo "</selected>";
echo '</form>';
should at least stop the syntax errors. Please post the entire code, not just snippets.
Logged
Pages: [1]   Go Up
 

Page created in 0.018 seconds with 15 queries.