forum.coppermine-gallery.net

Support => cpg1.4.x Support => Older/other versions => cpg1.4 miscellaneous => Topic started by: webbo on March 15, 2006, 10:10:21 pm

Title: Resetting View and Rating Counts ?
Post by: webbo on March 15, 2006, 10:10:21 pm
Hi,

As i am running a monthly competition using the coppermine gallery within my site, i am wondering if there is any way i can reset all the views and ratings of applicable files, with out having to go through each one individually.

We are using the views and ratings as a way of selecting shots for judging, so to be able to reset these values very rapidly at the beginning of each month would be very handy.

I have checked the FAQ's and can't find any relative info.

Can any one help and suggest any ideas ?
cheers
W ;D ;D
Title: Re: Resetting View and Rating Counts ?
Post by: xplicit on March 15, 2006, 10:21:07 pm
Sounds easy.

Just running a little query in a special php files sounds like the easiest way.

I dont know how your site is build up. I assume you dont want to reset all the views for all files on your gallery but that you placed the files which are running in the competition in a sepate album. In that case the page has its unique $aid and is eay to filter on.

If you post a link to your site I can take a look on how it looks and if help is needed I can code it and place the file here.
Title: Re: Resetting View and Rating Counts ?
Post by: xplicit on March 16, 2006, 01:37:45 am
Ok I just made a quick and dirty piece of code which will do the job, layout could be a lot better but functionality is ok

It will:

* Preset the number of hits of a specific album ID to a desired value
* Protected so that only people with admin rights can perform these actions

It will not:

* Check if the album is valid, could be easily done by checking the result of the query but I was lazy ;)
* Reset ratings since your post is not very clear to me what you mean.

To clear the actual votes you can write the code further yourself, bij selecting all pid's in the specific album in a query and reset these values in the vote_stats table and votes table in another query

Just run the script using: http://www.yoursite.com/competition.php or fit it properly in your design in the usual ways

It's valid for 1.3x , 1.4x (language is hard coded but its up to you if you want to do it the proper way in the language files)

Code: [Select]
<?php
/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2005 Coppermine Dev Team
  v1.1 originaly written by Gregory DEMAR

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  ********************************************
  Coppermine version: 1.4.4

  $Revision: 1.00 $
  $Author: AJ (Xplicit) $
  $Date: 2006/03/16 00:30:00 $
**********************************************/

define('IN_COPPERMINE'true);

require(
'include/init.inc.php');

if (!
GALLERY_ADMIN_MODEcpg_die(ERROR$lang_errors['access_denied']);

if (isset(
$_POST['resetalbum'])) {
$desired_album = (int)$_POST['resetalbum'];
$value = (int)$_POST['value'];

    $sql "UPDATE {$CONFIG['TABLE_PICTURES']} SET hits = $value WHERE aid=$desired_album"
$result cpg_db_query($sql);

pageheader("RESET BEING PERFORMED");

echo <<< EOT

<form method="post" action="competition.php" name="again">
EOT;


starttable('80%'"");
echo <<< EOT
  <tr>
        <td align="center" class="tableh2">
          <font size="3" color="red"><b>HITS FOR PICTURES IN ALBUM NR 
$desired_album SUCCESFULLY SET TO $value<b></font>
        </td>
      </tr>    

<tr>
  <td class="tableb" align="center" >
<input type="submit" value="PERFORM ANOTHER (P)RESET ACTION" class="button" />
       <input type="hidden" name="again" value="none" />
       </td>
     </tr>        
EOT;

endtable();
echo 
'</form>';


EOT;
endtable();

} else {

if (!
USER_ID && $CONFIG['allow_unlogged_access'] == 0) {
    $redirect $redirect "login.php";
    header("Location: $redirect");
    exit();
}

pageheader("Reset competition results of a specific album number");

echo <<< EOT

<form method="post" action="competition.php" name="resetcompetition">
EOT;


starttable('80%'"");

echo <<< EOT
<tr>
  <td  class="tableb" align="left" >
<div align="left"><font size="3"><b>ALBUM ID<b></font>
    <input type="text" style="width: 100" name="resetalbum" maxlength="5" value="" class="textinput" /><BR/>
    </div>
       </td>
</tr>
<tr>
<td  class="tableb" align="right" >
<div align="left"><font size="3"><b>PRESET VALUE<b></font>
    <input type="text" style="width: 100" name="value" maxlength="5" value="" class="textinput" /><BR/>
   </div>
       </td>
     </tr>        
<tr>
<td width="50%" colspan="2" align="center" >
<input type="submit" value="(P)RESET ALL HITS FOR THIS ALBUM" class="button" />
</td>
<tr>
EOT;

endtable();
echo 
'</form>';
}
pagefooter();
ob_end_flush();
?>


Title: Re: Resetting View and Rating Counts ?
Post by: webbo on March 16, 2006, 11:12:59 pm
Many thanks.

Heres a link to my site: www.enlyten.org/user_galleries/index.php

Apologies for being unclear in my initial post - heres a better description.

The gallery at the link above is used by registered users to upload photos.
Each photo that is uploaded is entered into the photo of the month competiton
To be able to reset the views and ratings for each image in the gallery will help us to decide which entry wins each month - this is decided on the average of ratings and views each month.

I can't write my own code - wouldn't have a clue how to start  ???

the galleries were set up for me by a friend who worked out how to run them.

Any help you can offer is appriciated ;D
Title: Re: Resetting View and Rating Counts ?
Post by: Nibbler on March 16, 2006, 11:16:37 pm
You can reset hits and votes in album properties.
Title: Re: Resetting View and Rating Counts ?
Post by: webbo on March 19, 2006, 01:23:48 pm
yeah that's how i'm resetting them at the moment - but as far as i can work out, you can only reset the values for single entries at one time - so you ahve to reset all the values individually. - thats a lot of resetting. :P

I would like to be able to reset all values for all entries in one easy method - so that at the beginning of the month all entries in the gallery - and therefore all entries in the competition - start at 0.

Make it easier to judge and the leaders are clearly visible to all gallery users under the 'most viewed' selection.

Do you know if there is a way to reset all the values easily ?

I tried running Xplicits code snippet - but it errors on me. Am i running it correctly - just typing in the URL.??

many thanks for your advice.

Webbo  ;D
Title: Re: Resetting View and Rating Counts ?
Post by: xplicit on March 20, 2006, 01:41:14 am
The file I made is without errors. just run is from your root. The only error you can get is a error if you try to run the script from a none admin account (cause this file is protected otherwise everyone could reset things)

Perhaps you didn't cut and paste it in a real low level text editor.

What kind of errors do you get?

If making a cut and paste file is too difficult perhaps it's just not your thing.
Title: Re: Resetting View and Rating Counts ?
Post by: webbo on March 26, 2006, 06:58:08 pm
I still can't get the code supplied to work.

Unfortunately - your gonna have to explain this one in laymans terms - I haven't had the time to nerd out on this one - hence why i'm asking if anyone can help.

If i try and run the above code like so : www.enlyten.org/user-galleries/competition.php,  this is the error i get :

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /vhost/vhost2/e/n/l/enlyten.org/www/user_galleries/competition.php on line 48

How do you integrate the code with the gallery ??? Does the code work properly ?
 
i'm not sure what you mean by : " just run is from your root. The only error you can get is a error if you try to run the script from a none admin account (cause this file is protected otherwise everyone could reset things)" 

How do you run the file competition.php from within the gallery ????

once again - if you can help it's appriciated.

cheers

W
Title: Re: Resetting View and Rating Counts ?
Post by: xplicit on March 26, 2006, 07:07:01 pm
Quote
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /vhost/vhost2/e/n/l/enlyten.org/www/user_galleries/competition.php on line 48

doesn't make sense if you cut and paste the code exactly since line 48 is just plain html or did you remove parts?

Else attach your file to see where your version goes wrong
Title: Re: Resetting View and Rating Counts ?
Post by: webbo on March 27, 2006, 11:02:33 am
I've just  cut and paste the code again into a new php file, uploaded the new file and still get the same error.

???

help.
Title: Re: Resetting View and Rating Counts ?
Post by: xplicit on March 27, 2006, 07:23:11 pm
I repeat:

Else attach your file to see where your version goes wrong

Otherwise I can't help you
Title: Re: Resetting View and Rating Counts ?
Post by: webbo on March 28, 2006, 02:28:04 am
Here it is. Attached file.
The file is a.php file - so you may need to change the extension to be able to read it.

 All i have done ins copy and pasted the info you provided above into a new .php doc and uploaded to the correct gallery folder on my server.
When i run the file as you instructed it errors with the above.

The code that i have used also is here too incase the file upload doesn't  work.

Code: [Select]
<?php
/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2005 Coppermine Dev Team
  v1.1 originaly written by Gregory DEMAR

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  ********************************************
  Coppermine version: 1.4.4

  $Revision: 1.00 $
  $Author: AJ (Xplicit) $
  $Date: 2006/03/16 00:30:00 $
**********************************************/

define('IN_COPPERMINE'true);

require(
'include/init.inc.php');

if (!
GALLERY_ADMIN_MODEcpg_die(ERROR$lang_errors['access_denied']);

if (isset(
$_POST['resetalbum'])) {
$desired_album = (int)$_POST['resetalbum'];
$value = (int)$_POST['value'];

    
$sql "UPDATE {$CONFIG['TABLE_PICTURES']} SET hits = $value WHERE aid=$desired_album"
$result cpg_db_query($sql);

pageheader("RESET BEING PERFORMED");

echo <<< EOT

<form method="post" action="competition.php" name="again">
EOT;


starttable('80%'"");
echo <<< EOT
  <tr>
        <td align="center" class="tableh2">
          <font size="3" color="red"><b>HITS FOR PICTURES IN ALBUM NR 
$desired_album SUCCESFULLY SET TO $value<b></font>
        </td>
      </tr>    
  
<tr>
  <td class="tableb" align="center" >
<input type="submit" value="PERFORM ANOTHER (P)RESET ACTION" class="button" />
       <input type="hidden" name="again" value="none" />
       </td>
     </tr>        
EOT;

endtable();
echo 
'</form>';


EOT;
endtable();

} else {

if (!
USER_ID && $CONFIG['allow_unlogged_access'] == 0) {
    
$redirect $redirect "login.php";
    
header("Location: $redirect");
    exit();
}

pageheader("Reset competition results of a specific album number");

echo <<< EOT

<form method="post" action="competition.php" name="resetcompetition">
EOT;


starttable('80%'"");

echo <<< EOT
<tr>
  <td  class="tableb" align="left" >
<div align="left"><font size="3"><b>ALBUM ID<b></font>
    <input type="text" style="width: 100" name="resetalbum" maxlength="5" value="" class="textinput" /><BR/>
    </div>
       </td>
</tr>
<tr>
<td  class="tableb" align="right" >
<div align="left"><font size="3"><b>PRESET VALUE<b></font>
    <input type="text" style="width: 100" name="value" maxlength="5" value="" class="textinput" /><BR/>
   </div>
       </td>
     </tr>        
<tr>
<td width="50%" colspan="2" align="center" >
<input type="submit" value="(P)RESET ALL HITS FOR THIS ALBUM" class="button" />
</td>
<tr>
EOT;

endtable();
echo 
'</form>';
}
pagefooter();
ob_end_flush();
?>
Title: Re: Resetting View and Rating Counts ?
Post by: xplicit on March 28, 2006, 02:43:31 am
Ok a few blank spaces are the problem

I'll send you a working version without them (rename jpg to php)
Title: Re: Resetting View and Rating Counts ?
Post by: Stramm on March 28, 2006, 07:09:27 pm
to reset the view counter is an admin tools function
Title: Re: Resetting View and Rating Counts ?
Post by: MstrMitch on October 26, 2006, 08:54:05 pm
I am getting an error

Fatal error: Call to undefined function: cpg_db_query() in /home/hsphere/local/home/fetish/azfetishball.com/pics/competition.php on line 31

using the same script..any help?

Mitch
Phoenix, AZ
Title: Re: Resetting View and Rating Counts ?
Post by: Nibbler on October 26, 2006, 09:00:26 pm
There is no support for Coppermine 1.3. Update your gallery.