Mod: "move all/checked" option on editpics.php -- tweaking help? Mod: "move all/checked" option on editpics.php -- tweaking help?
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Mod: "move all/checked" option on editpics.php -- tweaking help?

Started by bowserbabe, May 09, 2007, 09:52:08 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bowserbabe

Okay, it works... that's not what I'd like help with. I was hoping someone who knows more about the underworkings of coppermine and/or php in general might be able to look at it and tell me if things should be moved around and/or done another way to be more in keeping with the rest of how the page is programmed.

Here are the parts I played with:

process_post_data
function process_post_data()
{
        global $CONFIG;
        global $user_albums_list, $lang_errors;

        $user_album_set = array();
        foreach($user_albums_list as $album) $user_album_set[$album['aid']] = 1;

        if (!is_array($_POST['pid'])) cpg_die(CRITICAL_ERROR, $lang_errors['param_missing'], __FILE__, __LINE__);
        $pid_array = &$_POST['pid'];

                $galleryicon = (int) $_POST['galleryicon'];

        foreach($pid_array as $pid){
                $pid = (int)$pid;

                $aid         = (int)get_post_var('aid', $pid);
                $title       = get_post_var('title', $pid);
                $caption     = get_post_var('caption', $pid);
                $keywords    = get_post_var('keywords', $pid);
                $user1       = get_post_var('user1', $pid);
                $user2       = get_post_var('user2', $pid);
                $user3       = get_post_var('user3', $pid);
                $user4       = get_post_var('user4', $pid);
                $moveall    = get_post_var('moveall');

                                $isgalleryicon = ($galleryicon===$pid);

                $move        = isset($_POST['move'.$pid]);
                $delete       = isset($_POST['delete'.$pid]);
                $reset_vcount = isset($_POST['reset_vcount'.$pid]);
                $reset_votes  = isset($_POST['reset_votes'.$pid]);
                $del_comments = isset($_POST['del_comments'.$pid]) || $delete;

                if ($move) {$aid = $moveall;}

                $query = "SELECT category, filepath, filename, owner_id FROM {$CONFIG['TABLE_PICTURES']}, {$CONFIG

['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND pid='$pid'";
                $result = cpg_db_query($query);
                if (!mysql_num_rows($result)) cpg_die(CRITICAL_ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
                $pic = mysql_fetch_array($result);
                mysql_free_result($result);

                if (!GALLERY_ADMIN_MODE) {
                        if ($pic['category'] != FIRST_USER_CAT + USER_ID) cpg_die(ERROR, $lang_errors['perm_denied']."<br />

(picture category = {$pic['category']}/ $pid)", __FILE__, __LINE__);
                        if (!isset($user_album_set[$aid])) cpg_die(ERROR, $lang_errors['perm_denied']."<br />(target album = $aid)",

__FILE__, __LINE__);
                }

                $update  = "aid = '".$aid."'";
                $update .= ", title = '".addslashes($title)."'";
                $update .= ", caption = '".addslashes($caption)."'";
                $update .= ", keywords = '".addslashes($keywords)."'";
                $update .= ", user1 = '".addslashes($user1)."'";
                $update .= ", user2 = '".addslashes($user2)."'";
                $update .= ", user3 = '".addslashes($user3)."'";
                $update .= ", user4 = '".addslashes($user4)."'";

                if ($isgalleryicon && $pic['category']>FIRST_USER_CAT) {
                                        $sql = 'update '.$CONFIG['TABLE_PICTURES'].' set galleryicon=0 where owner_id='.$pic

['owner_id'].';';
                                        cpg_db_query($sql);
                                        $update .= ", galleryicon = ".addslashes($galleryicon);
                                }

                                if (is_movie($pic['filename'])) {
                                        $pwidth = get_post_var('pwidth', $pid);
                                        $pheight = get_post_var('pheight', $pid);
                                        $update .= ", pwidth = " .  (int) $pwidth;
                                        $update .= ", pheight = " . (int) $pheight;
                                }

                if ($reset_vcount) {
                    $update .= ", hits = '0'";
                    resetDetailHits($pid);
                }
                if ($reset_votes) {
                    $update .= ", pic_rating = '0', votes = '0'";
                    resetDetailVotes($pid);
                }

                if (UPLOAD_APPROVAL_MODE) {
                    $approved = get_post_var('approved', $pid);
                        if ($approved == 'YES') {
                                $update .= ", approved = 'YES'";
                        } elseif ($approved == 'DELETE') {
                                $del_comments = 1;
                                $delete = 1;
                        }
                }

                if ($del_comments) {
                        $query = "DELETE FROM {$CONFIG['TABLE_COMMENTS']} WHERE pid='$pid'";
                        $result =cpg_db_query($query);
                }

                if ($delete) {
                        $dir=$CONFIG['fullpath'].$pic['filepath'];
                        $file=$pic['filename'];

                        if (!is_writable($dir)) cpg_die(CRITICAL_ERROR, sprintf($lang_errors['directory_ro'], $dir), __FILE__,

__LINE__);

                        $files=array($dir.$file, $dir.$CONFIG['normal_pfx'].$file, $dir.$CONFIG['thumb_pfx'].$file);
                        foreach ($files as $currFile){
                                if (is_file($currFile)) @unlink($currFile);
                        }

                        $query = "DELETE FROM {$CONFIG['TABLE_PICTURES']} WHERE pid='$pid' LIMIT 1";
                        $result = cpg_db_query($query);
                }

                if ($move) {
                        $query = "UPDATE {$CONFIG['TABLE_PICTURES']} SET $update WHERE pid='$pid' LIMIT 1";
                        $result = cpg_db_query($query);

                } else {
                        $query = "UPDATE {$CONFIG['TABLE_PICTURES']} SET $update WHERE pid='$pid' LIMIT 1";
                        $result = cpg_db_query($query);
                }
        }
}


form_options
function form_options()
{
        global $CURRENT_PIC, $lang_editpics_php;

                $isgalleryicon_selected = ($CURRENT_PIC['galleryicon']) ? 'checked="checked" ':'';
                $isgalleryicon_disabled = ($CURRENT_PIC['category'] < FIRST_USER_CAT) ? 'disabled="disabled" ':'';

        if (UPLOAD_APPROVAL_MODE) {
                echo <<<EOT
        <tr>
                <td class="tableb" colspan="3" align="center">
                        <input type="radio" name="approved{$CURRENT_PIC['pid']}" id="approved{$CURRENT_PIC['pid']}yes"

value="YES" class="radio" /><label for="approved{$CURRENT_PIC['pid']}yes" class="clickable_option">{$lang_editpics_php

['approve']}</label>&nbsp;
                        <input type="radio" name="approved{$CURRENT_PIC['pid']}" id="approved{$CURRENT_PIC['pid']}no"

value="NO" class="radio" checked="checked" /><label for="approved{$CURRENT_PIC['pid']}no" class="clickable_option">

{$lang_editpics_php['postpone_app']}</label>&nbsp;
                        <input type="radio" name="approved{$CURRENT_PIC['pid']}" id="approved{$CURRENT_PIC['pid']}del"

value="DELETE" class="radio" /><label for="approved{$CURRENT_PIC['pid']}del" class="clickable_option">

{$lang_editpics_php['del_pic']}</label>&nbsp;
                </td>
        </tr>

EOT;
        } else {
                echo <<<EOT
        <tr>
                <td class="tableb" colspan="3" align="center">
                    <table border="0" cellspacing="0" cellpadding="0" width="100%">
                        <tr>
                            <td width="15%" align="center"><input type="radio" name="galleryicon" id="galleryicon{$CURRENT_PIC

['pid']}" value="{$CURRENT_PIC['pid']}" {$isgalleryicon_selected}{$isgalleryicon_disabled}class="checkbox" />

{$lang_editpics_php['gallery_icon']}</td>
                            <td width="16%" align="center"><input type="checkbox" name="move{$CURRENT_PIC['pid']}" id="move

{$CURRENT_PIC['pid']}" value="1" class="checkbox" /><label for="move{$CURRENT_PIC['pid']}"

class="clickable_option">Move file</label></td>
                            <td width="17%" align="center"><input type="checkbox" name="delete{$CURRENT_PIC['pid']}" id="delete

{$CURRENT_PIC['pid']}" value="1" class="checkbox" /><label for="delete{$CURRENT_PIC['pid']}" class="clickable_option">

{$lang_editpics_php['del_pic']}</label></td>
                            <td width="17%" align="center"><input type="checkbox" name="reset_vcount{$CURRENT_PIC['pid']}"

id="reset_vcount{$CURRENT_PIC['pid']}" value="1" class="checkbox" /><label for="reset_vcount{$CURRENT_PIC['pid']}"

class="clickable_option">{$lang_editpics_php['reset_view_count']}</label></td>
                            <td width="16%" align="center"><input type="checkbox" name="reset_votes{$CURRENT_PIC['pid']}"

id="reset_votes{$CURRENT_PIC['pid']}" value="1" class="checkbox" /><label for="reset_votes{$CURRENT_PIC['pid']}"

class="clickable_option">{$lang_editpics_php['reset_votes']}</label></td>
                            <td width="17%" align="center"><input type="checkbox" name="del_comments{$CURRENT_PIC['pid']}"

id="del_comments{$CURRENT_PIC['pid']}" value="1" class="checkbox" /><label for="del_comments{$CURRENT_PIC['pid']}"

class="clickable_option">{$lang_editpics_php['del_comm']}</label></td>
                        </tr>
                    </table>
                </td>
        </tr>

EOT;
        }
}


The html at the top (added a "move all" check box) and the html at the bottom (added the drop-down box to choose the album to move to)
echo <<<EOT
        <tr>
            <td class="tableb" colspan="3" align="center">
                <table border="0" cellspacing="0" cellpadding="0" width="100%" style="padding-top:5px;padding-bottom:5px">
                    <tr>
                        <td width="14%" align="right">
                            <b>{$lang_editpics_php['select_unselect']}:</b>
                        </td>
                        <td width="16%" align="center">
                            <span class="admin_menu">
                                <input type="checkbox" name="moveAll" onclick="selectAll(this,'move');" class="checkbox"

id="moveAll" />
                                <label for="moveAll" class="clickable_option">Move ALL files</label>
                            </span>
                        </td>
                        <td width="17%" align="center">
                            <span class="admin_menu">
                                <input type="checkbox" name="deleteAll" onclick="selectAll(this,'delete');" class="checkbox"

id="deleteAll" />
                                <label for="deleteAll" class="clickable_option">{$lang_editpics_php['del_all']}</label>
                            </span>
                        </td>
                        <td width="18%" align="center">
                            <span class="admin_menu">
                                <input type="checkbox" name="reset_vcountAll" onclick="selectAll(this,'reset_vcount');"

class="checkbox" id="reset_vcountAll" />
                                <label for="reset_vcountAll" class="clickable_option">{$lang_editpics_php['reset_all_view_count']}

</label>
                            </span>
                        </td>
                        <td width="16%" align="center">
                            <span class="admin_menu">
                                <input type="checkbox" name="reset_votesAll" onclick="selectAll(this,'reset_votes');" class="checkbox"

id="reset_votesAll" />
                                <label for="reset_votesAll" class="clickable_option">{$lang_editpics_php['reset_all_votes']}</label>
                            </span>
                        </td>
                        <td width="17%" align="center">
                            <span class="admin_menu">
                                <input type="checkbox" name="del_commentsAll" onclick="selectAll(this,'del_comments');"

class="checkbox"reset_votesAll" id="del_commentsAll" />
                                <label for="del_commentsAll" class="clickable_option">{$lang_editpics_php['del_all_comm']}</label>
                            </span>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
EOT;

while($CURRENT_PIC = mysql_fetch_array($result)){

        if (GALLERY_ADMIN_MODE && $CURRENT_PIC['owner_id'] != USER_ID) {
              get_user_albums($CURRENT_PIC['owner_id']);
        } else {
              get_user_albums();
        }
        create_form($data);
        flush();
} // while
mysql_free_result($result);

echo <<<EOT
        <tr>
                <td colspan="3" align="center" class="tablef">
                         Move checked:
                <select name="moveall" class="listbox">

EOT;
                foreach($public_albums_list as $album) {
        echo '              <option value="' . $album['aid'] . '"' . ($album['aid'] == $sel_album ? ' selected' : '') . '>' . $album['cat_title'] .

"</option>\n";
    }
                foreach($user_albums_list as $album){
                        echo '                        <option value="'.$album['aid'].'"'.($album['aid'] == $sel_album ? ' selected' : '').'>*

'.$album['title'] . "</option>\n";
                }
echo <<<EOT
                </select>
               
        <tr>
                <td colspan="3" align="center" class="tablef">
                        <input type="submit" value="{$lang_editpics_php['apply']}" class="button" />
                </td>
                </form>
        </tr>

EOT;


I think that's it, but just to be safe, I'll go ahead and attach my editpics.php. It was a new install of the current version, so the only changes to it should be regarding the above mod.

It's kind of messy in places. My goal was to just get it working. >.>

Any and all comments/help/feedback appreciated! This is my very first mod of anything ever. lol

skidpics


bowserbabe

Wow. Okay. That was a while ago.

Let's see if I can remember how to do this. Looks like I do. So there should be an attachment there.

It's pretty dull though, just an extra box on the "select/unselect" row, and a pull-down box at the bottom.

skidpics

thanks..  there was not an actual written explanation of what you were accomplishing.  Let me get thsi straight.

It allows you to move the photo to a different album, correct?  Have you had any problem with the code or has it been revised since your original post?

bowserbabe

I got frustrated with various things and gave up on messing with my coppermine too much. Actually, the gallery is still there as you can see, but I haven't done anything with it in months.

I found it easier, under certain circumstances, to upload all the pictures I wanted to upload right then into an "upload" album and then move them individually to the albums I ultimately wanted them in.  So all I did really was make that easier by allowing you to check all of them at once, and to only have to set which album you wanted to move them to once, instead of on each individual picture.

There was some problem I think... I think I have it set to default to a "blank" album. So if you check a bunch of pictures and then don't set an album at the bottom it has an error or doesn't move them or moves them into a weird place... I don't remember if I fixed it before I posted here or not. Or if I fixed it at all.

I can look though if you want.

skidpics

it's okay - I will check out the code when I have the time..  I mainly use keywords to link to pics to albums, regardless of where they are.  I do try to upload into the correct albums.  I use the xp publishing wizard more, so I can send pics to the correct galleries as I see them.. 

Thanks for your quick reply...