coppermine-gallery.com/forum

Support => Older/other versions => cpg1.3.x Support => Topic started by: JasonB on October 21, 2004, 08:18:16 PM

Title: Batch Add folder sort order change in 1.3.2?
Post by: JasonB on October 21, 2004, 08:18:16 PM
Did the sort order of the folders in the Batch Add function get reversed?  Whenever I go to do a Batch Add now (I haven't done so since I upgraded to 1.3.2) it shows "Select Directory" - and then lists all of my folders in reverse alphabetical order (z-a) rather than what I'm used to (a-z).  Once I pick a folder, and then look at the "select album" dropdown box, it is in forward alphabetical order.  So things are inconsistent.

With 1.3.1 and 1.3.0 I don't recall the order being backwards in the directory listing - I think that something must have changed.  I'm seeing this behaviour with two different installs...

Update: It's no longer sorting at all.  I just added a new directory, and the Select Directory list is showing it at the bottom, out of any kind of alphabetic sequence. (So now I've got z-a, comprising all of my pre-1.3.2 directories, and then my new directory.)  Am I just losing my mind on this one?
Title: Re: Batch Add folder sort order change in 1.3.2?
Post by: Joachim Müller on October 22, 2004, 07:13:52 AM
folders never were sorted alphabetically when using batch-add, in no coppermine version. It's one of the drawbacks of the batch-add function we're about to fix for the next coppermine version - there's nothing you could do now (except look into the code and fix it for us). Your memory deceives you though - as I already said: it never was sorted.

Joachim
Title: Re: Batch Add folder sort order change in 1.3.2?
Post by: JasonB on October 22, 2004, 02:12:55 PM
How bizarre!  I could have sworn it did it before.  Okay, thanks for putting me straight. <grin>  I may see what I can do about modifying things a bit.  (Taking the readdir() section of the code, putting it into an array, sorting that, and then using that for the existing section.)
Title: Re: [FIXED] Batch Add folder sort order change in 1.3.2?
Post by: JasonB on October 22, 2004, 08:35:57 PM
Okay, here's the fix.

Make the following modification to the searchnew.php file.

Old code:

    $dir = opendir($dir_path);
    while ($file = readdir($dir)) {
        //if (is_dir($CONFIG['fullpath'] . $folder . $file) && $file != "." && $file != "..") { // removed by following line for 'do not show folders with dots': gaugau 03-11-02
        if (is_dir($CONFIG['fullpath'] . $folder . $file) && substr($file,0,1) != "." && strpos($file,"'") == FALSE && $file != "userpics"  && $file != "edit" ) {
            $start_target = $folder . $file;
            $dir_path = $CONFIG['fullpath'] . $folder . $file;

            $warnings = '';
            if (!is_writable($dir_path)) $warnings .= $lang_search_new_php['dir_ro'];
            if (!is_readable($dir_path)) $warnings .= $lang_search_new_php['dir_cant_read'];

            if ($warnings) $warnings = '&nbsp;&nbsp;&nbsp;<b>' . $warnings . '<b>';

            echo <<<EOT
                        <tr>
                                <td class="tableb">
                                        $ident<img src="images/folder.gif" alt="" />&nbsp;<a href= "$PHP_SELF?startdir=$start_target">$file</a>$warnings
                                </td>
                        </tr>
EOT;
            display_dir_tree($folder . $file . '/', $ident . '&nbsp;&nbsp;&nbsp;&nbsp;');
        }
    }
    closedir($dir);


New code:

    $dir = opendir($dir_path);
    while (($file = readdir($dir)) !== false) { $filelist[] = $file; }
    closedir($dir);
    asort($filelist);
    while (list ($key, $file) = each ($filelist)) {
        //if (is_dir($CONFIG['fullpath'] . $folder . $file) && $file != "." && $file != "..") { // removed by following line for 'do not show folders with dots': gaugau 03-11-02
        if (is_dir($CONFIG['fullpath'] . $folder . $file) && substr($file,0,1) != "." && strpos($file,"'") == FALSE && $file != "userpics"  && $file != "edit" ) {
            $start_target = $folder . $file;
            $dir_path = $CONFIG['fullpath'] . $folder . $file;

            $warnings = '';
            if (!is_writable($dir_path)) $warnings .= $lang_search_new_php['dir_ro'];
            if (!is_readable($dir_path)) $warnings .= $lang_search_new_php['dir_cant_read'];

            if ($warnings) $warnings = '&nbsp;&nbsp;&nbsp;<b>' . $warnings . '<b>';

            echo <<<EOT
                        <tr>
                                <td class="tableb">
                                        $ident<img src="images/folder.gif" alt="" />&nbsp;<a href= "$PHP_SELF?startdir=$start_target">$file</a>$warnings
                                </td>
                        </tr>
EOT;
            display_dir_tree($folder . $file . '/', $ident . '&nbsp;&nbsp;&nbsp;&nbsp;');
        }
    }


This preserves the original logic of the existing code (I didn't want to tinker with that) but does so by having it run against an alphabetically sorted array.  No doubt this could be streamlined - so that checks are done within the reading of the array itself rather than just having it capture everything - but for now I was just concerned with the simplest fix.

With this in place, all of your "Select Directory" listings (from "Batch add files") will be in alphabetical order.

I didn't bother doing anything to sort the dropdown Folders list, since I realised that I've been creating them in alphabetical order anyway.