Thanks for voting! banner AFTER voting Thanks for voting! banner AFTER voting
 

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

Thanks for voting! banner AFTER voting

Started by Steve-R, February 17, 2008, 04:43:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Steve-R

I want to be able to display a banner (Thanks for Voting/You have already voted on this file) instead of the voting options when displaying a photo I have already voted on and/or immediately after voting, I've tried adding an elseif into the themehtml rating box area of theme php..even using the following caption from ratepic.php


$user_md5_id = USER_ID ? md5(USER_ID) : $USER['ID'];
$sql = "SELECT * " . "FROM {$CONFIG['TABLE_VOTES']} " . "WHERE pic_id = '$pic' AND vote_id = '$vote_id' " . "AND user_md5_id = '$user_md5_id'";
$result = cpg_db_query($sql);
if (mysql_num_rows($result)) cpg_die(ERROR, $lang_rate_pic_php['already_rated'], __FILE__, __LINE__);


I'm thinking now that I might need to edit displayimage.php..is this right..or am I going off in the wrong direction?

Steve...:)

Steve-R

Can anyone give me any hints on this to send me in the right direction?

Many thanks!

Steve...:)

Steve-R

Here's what I have as the HTML template for the image rating box in my theme.php, it has an alternate voting display for all pictures except for album 16 which needs to use the original stars instead. This all works except for when you vote on any image in album 16, where after voting it reverts to the voting area specified in the else statement below...which is why I was wanting it to say something like "Thanks for voting" after the fact.


// HTML template for the image rating box
if ($aid == 16){
$template_image_rating = <<<EOT
<table align="center" width="{WIDTH}" cellspacing="0" cellpadding="0" class="maintable">
        <tr>
                <td colspan="5" class="tableh2_compact"><b></b>  <center><b><FONT FACE="Helvetica" SIZE="5" COLOR="#FF0000">Vote for POTD using the stars below!!</FONT></b></center></td>
        </tr>
        <tr>
                <td class="tableb_compact" width="17%" align="center"><a href="{RATE1}" title="{1STAR}"><img src="{LOCATION}images/rating1.gif" alt="{1STAR}" border="0px" alt="" /><br /></a></td>
                <td class="tableb_compact" width="17%" align="center"><a href="{RATE2}" title="{2STAR}"><img src="{LOCATION}images/rating2.gif" alt="{2STAR}" border="0px" alt="" /><br /></a></td>
                <td class="tableb_compact" width="17%" align="center"><a href="{RATE3}" title="{3STAR}"><img src="{LOCATION}images/rating3.gif" alt="{3STAR}" border="0px" alt="" /><br /></a></td>
                <td class="tableb_compact" width="17%" align="center"><a href="{RATE4}" title="{4STAR}"><img src="{LOCATION}images/rating4.gif" alt="{4STAR}" border="0px" alt="" /><br /></a></td>
                <td class="tableb_compact" width="17%" align="center"><a href="{RATE5}" title="{5STAR}"><img src="{LOCATION}images/rating5.gif" alt="{5STAR}" border="0px" alt=""
/><br /></a></td>
<tr>
                <td class="tableb_compact" width="17%" align="center"><a href="{RATE6}" title="{6STAR}"><img src="{LOCATION}images/rating6.gif" alt="{6STAR}" border="0px" alt="" /><br /></a></td>
                <td class="tableb_compact" width="17%" align="center"><a href="{RATE7}" title="{7STAR}"><img src="{LOCATION}images/rating7.gif" alt="{7STAR}" border="0px" alt="" /><br /></a></td>
                <td class="tableb_compact" width="17%" align="center"><a href="{RATE8}" title="{8STAR}"><img src="{LOCATION}images/rating8.gif" alt="{8STAR}" border="0px" alt="" /><br /></a></td>
                <td class="tableb_compact" width="17%" align="center"><a href="{RATE9}" title="{9STAR}"><img src="{LOCATION}images/rating9.gif" alt="{9STAR}" border="0px" alt="" /><br /></a></td>
                <td class="tableb_compact" width="17%" align="center"><a href="{RATE10}" title="{10STAR}"><img src="{LOCATION}images/rating10.gif" alt="{10STAR}" border="0px" alt=""
/><br /></a></td>
</tr>
</tr>
</table>
EOT;

}else {
$template_image_rating = <<<EOT
<table align="center" width="{WIDTH}" cellspacing="0" cellpadding="0" class="maintable">
        <tr>
                <td colspan="5" class="tableh2_compact"><b></b>  <center><b><FONT FACE="Helvetica" SIZE="5" COLOR="#FF0000">Vote for POTD using one of these three buttons!</FONT></b></center></td>
        </tr>
        <tr>
                <td class="tableb_compact" width="17%" align="center"><a href="{XATE1}" title="{1SCORE}"><img src="{LOCATION}images/good.gif" alt="{1SCORE}" border="0px" alt="" /><br /></a></td>
                <td class="tableb_compact" width="17%" align="center"><a href="{YATE1}" title="{2SCORE}"><img src="{LOCATION}images/verygood.gif" alt="{2SCORE}" border="0px" alt="" /><br /></a></td>
                <td class="tableb_compact" width="17%" align="center"><a href="{ZATE1}" title="{3SCORE}"><img src="{LOCATION}images/excellent.gif" alt="{3SCORE}" border="0px" alt="" /><br /></a></td>
</tr>
</table>
EOT;
}



I've tried adding an elsif statement in between "}elseif ($sql) {" where sql checks if the user has already rated, and this is where I am falling down I think as I cant seem to get this part to work.

If anyone can help I would appreciate that, many thanks!

Steve...:)

SaWey

You're lucky I was working on the voting system in the dev version last week,
This is the query I use to see if the user has voted already:
Code (php) Select

$result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_VOTES']} WHERE pic_id={$CURRENT_PIC_DATA['pid']} AND user_md5_id='" . md5($USER_DATA['user_id']) . "'");
if(mysql_num_rows($result)){
    //user has voted already
    //your stuff here
}else{
    //user can still vote
    //your stuff here
}

Steve-R

Many thanks SaWey, will give this one a try this evening, then come back to confirm this solved.

Regards

Steve...:)

Steve-R

I'm getting this error with the new code, looks like it cant find the pid


While executing query "SELECT * FROM cpg14x_votes WHERE pic_id=  AND user_md5_id='c4ca4238a0b923820dcc509a6f75849b''" on 0

mySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND user_md5_id='c4ca4238a0b923820dcc509a6f75849b''' at line 1


Any ideas?

Regards

Steve...:)

SaWey

You should use this in 'function theme_html_rating_box()', not in '$template_image_rating'

Steve-R

Okay tried this today, and added the code from SaWey as below. I've posted the whole function from theme.php as it is now. When I click on a pic in the gallery I only see the new button vote I have added (which is in the "else" below), I've commented parts of it for clarity and removed some code which is just table content. Where do I go from here?


function theme_html_rating_box()
{
    global $CONFIG, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA, $THEME_DIR;
    global $template_image_rating, $lang_rate_pic;

    if (!(USER_CAN_RATE_PICTURES && $CURRENT_ALBUM_DATA['votes'] == 'YES')) return '';

$result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_VOTES']} WHERE pic_id= {$CURRENT_PIC_DATA['pid']} AND user_md5_id='" .

md5($USER_DATA['user_id']) . "'");
if(mysql_num_rows($result)){
$template_image_rating = <<<EOT
<table align="center" width="{WIDTH}" cellspacing="0" cellpadding="0" class="maintable">
        <tr>
                <td colspan="5" class="tableh2_compact"><b></b>  <center><b><FONT FACE="Helvetica" SIZE="5" COLOR="#FF0000">Thanks

for voting!</FONT></b></center></td>
        </tr>

</table>
EOT;

}elseif ($aid == 16){
$template_image_rating = <<<EOT
<table align="center" width="{WIDTH}" cellspacing="0" cellpadding="0" class="maintable">
        <tr>
                <td colspan="5" class="tableh2_compact"><b></b>  <center><b><FONT FACE="Helvetica" SIZE="5" COLOR="#FF0000">Vote  using the stars below!!</FONT></b></center></td> // Stars voting for album 16
        </tr>
</table>
EOT;

}else {
$template_image_rating = <<<EOT
<table align="center" width="{WIDTH}" cellspacing="0" cellpadding="0" class="maintable">
        <tr>
                <td colspan="5" class="tableh2_compact"><b></b>  <center><b><FONT FACE="Helvetica" SIZE="5" COLOR="#FF0000">Vote using one of these three buttons!</FONT></b></center></td>  // Button vote for all gallery except album 16 (In another category)
        </tr>
        <tr>
                <td class="tableb_compact" width="17%" align="center"><a href="{XATE1}" title="{1SCORE}"><img

src="{LOCATION}images/good.gif" alt="{1SCORE}" border="0px" alt="" /><br /></a></td>
                <td class="tableb_compact" width="17%" align="center"><a href="{YATE1}" title="{2SCORE}"><img

src="{LOCATION}images/verygood.gif" alt="{2SCORE}" border="0px" alt="" /><br /></a></td>
                <td class="tableb_compact" width="17%" align="center"><a href="{ZATE1}" title="{3SCORE}"><img

src="{LOCATION}images/excellent.gif" alt="{3SCORE}" border="0px" alt="" /><br /></a></td>
</tr>
</table>
EOT;
}

$votes = $CURRENT_PIC_DATA['votes'] ? sprintf($lang_rate_pic['rating'], round($CURRENT_PIC_DATA['pic_rating'] / 2000 *

$CURRENT_PIC_DATA['votes'], 1), $CURRENT_PIC_DATA['votes']) : $lang_rate_pic['no_votes'];
    $pid = $CURRENT_PIC_DATA['pid'];

    if (defined('THEME_HAS_RATING_GRAPHICS')) {
        $location= $THEME_DIR;
    } else {
        $location= '';
    }

    $params = array('{TITLE}' => $lang_rate_pic['rate_this_pic'],
        '{VOTES}' => $votes,
       
        '{RATE1}' => "ratepic.php?pic=$pid&amp;rate=1",
        '{RATE2}' => "ratepic.php?pic=$pid&amp;rate=2",
        '{RATE3}' => "ratepic.php?pic=$pid&amp;rate=3",
        '{RATE4}' => "ratepic.php?pic=$pid&amp;rate=4",
        '{RATE5}' => "ratepic.php?pic=$pid&amp;rate=5",
'{RATE6}' => "ratepic.php?pic=$pid&amp;rate=6",
'{RATE7}' => "ratepic.php?pic=$pid&amp;rate=7",
'{RATE8}' => "ratepic.php?pic=$pid&amp;rate=8",
'{RATE9}' => "ratepic.php?pic=$pid&amp;rate=9",
'{RATE10}' => "ratepic.php?pic=$pid&amp;rate=10",
'{XATE1}' => "ratepic.php?pic=$pid&amp;xate=1",
'{YATE1}' => "ratepic.php?pic=$pid&amp;yate=1",
'{ZATE1}' => "ratepic.php?pic=$pid&amp;zate=1",
        '{1STAR}' => $lang_rate_pic['1star'],
        '{2STAR}' => $lang_rate_pic['2star'],
        '{3STAR}' => $lang_rate_pic['3star'],
        '{4STAR}' => $lang_rate_pic['4star'],
'{5STAR}' => $lang_rate_pic['5star'],
'{6STAR}' => $lang_rate_pic['6star'],
'{7STAR}' => $lang_rate_pic['7star'],
'{8STAR}' => $lang_rate_pic['8star'],
'{9STAR}' => $lang_rate_pic['9star'],
'{10STAR}' => $lang_rate_pic['10star'],
'{1SCORE}' => $lang_rate_pic['1score'],
'{2SCORE}' => $lang_rate_pic['2score'],
'{3SCORE}' => $lang_rate_pic['3score'],
        '{EXCELLENT}' => $lang_rate_pic['excellent'],
        '{GREAT}' => $lang_rate_pic['great'],
        '{WIDTH}' => $CONFIG['picture_table_width'],
        '{LOCATION}' => $location,        //theme dir or default images directory
        );

    return template_eval($template_image_rating, $params);
}


Regards

Steve...:)

Nibbler

You need to add $USER to the list of globals at the top of the function. Then the correct query would be:


$user_md5_id = USER_ID ? md5(USER_ID) : $USER['ID'];
$result = cpg_db_query("SELECT null FROM {$CONFIG['TABLE_VOTES']} WHERE pic_id= {$CURRENT_PIC_DATA['pid']} AND user_md5_id='$user_md5_id' LIMIT 1");



PS. SaWay, check you are using the right code for user_md5_id for whatever you are doing in devel; it's not simply the md5 of the user_id since that would not work properly for anonymous voting.

SaWey

Quote from: Nibbler on February 19, 2008, 08:09:43 PM
...
PS. SaWay, check you are using the right code for user_md5_id for whatever you are doing in devel; it's not simply the md5 of the user_id since that would not work properly for anonymous voting.
Yes, thanks for noticing, totally forgot about that

Steve-R

Thanks to SaWey and Nibbler for their help on this one, can be marked as solved now.

I made only one more change which was.

Change

}else if ($aid == 16){

To

}else if ($CURRENT_ALBUM_DATA['aid'] == '16'){


Steve...:)

Heroe

Is it possible somebody ho have time to make this mod ? I like the idea but I'm php newbie and don't know how to make the edits.Im sure this is very good idea for mod :) Im sorry if somebody else ask before me for that but been searching the forum exactly for that today.