4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: TheOracle on August 13, 2005, 10:52:26 PM

Title: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: TheOracle on August 13, 2005, 10:52:26 PM
Original post : TheOracle (thanks to him)
Original idea & Final debug : me

With this mod, 4images admins can choose to disable download and e-card until the user rates the picture.
works with lightbox too.

 >> 04 files to edit from 4images root:
[change]lightbox.php
[change]includes/functions.php
[change]lang/<your_language>/admin.php
[change]admin/settings.php


 >> 01 new file to download (db update): install_rvotes.php


First, backup your files.

------ Installation ------


STEP 1:

open lightbox.php
find
Code: [Select]
if (function_exists("gzcompress") && function_exists("crc32")) {
  if (!empty($user_info['lightbox_image_ids'])) {
    $download_button = "<a href=\"".$site_sess->url(ROOT_PATH."download.php?action=lightbox")."\"><img src=\"".get_gallery_image("download_zip.gif")."\" border=\"0\" alt=\"\" /></a>";
  }
  else {
    $download_button = "<img src=\"".get_gallery_image("download_zip_off.gif")."\" border=\"0\" alt=\"\" />";
  }
}

replace by:
Code: [Select]
if (function_exists("gzcompress") && function_exists("crc32")) {
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]
$one_not_rated = "";
$rated_images = array();
// search all pics rated by user
$sql = "SELECT image_id
        FROM ".VOTED_TABLE."
        WHERE user_id =".$user_info['user_id'];

 $result = $site_db->query($sql);
 
while($row = $site_db->fetch_array($result)) {
  $rated_images[] = $row['image_id']; // put the result in an array
}
  
$array_lightbox_image_ids = explode(" ", $user_info['lightbox_image_ids']); // put lightboxed pics in an array

foreach ($array_lightbox_image_ids as $element) {
if (!in_array ($element, $rated_images)) { // if current lightboxed pics in not found in rated pics by user
$one_not_rated = 1;
    }
}
    if (!empty($user_info['lightbox_image_ids']) && !$one_not_rated) { // !$one_not_rated  :  means all pics in lightbox have been rated
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]

    $download_button = "<a href=\"".$site_sess->url(ROOT_PATH."download.php?action=lightbox")."\"><img src=\"".get_gallery_image("download_zip.gif")."\" border=\"0\" alt=\"\" /></a>";
  }
  else {
    $download_button = "<img src=\"".get_gallery_image("download_zip_off.gif")."\" border=\"0\" alt=\"\" />";
  }
}



STEP 2.1:
open includes/functions.php
find:
Code: [Select]
if (!check_permission("auth_download", $image_row['cat_id'])) {

replace by:
Code: [Select]
if (!check_permission("auth_download", $image_row['cat_id']) || ($user_info['user_level'] != ADMIN && !check_user_rate($image_row['image_id'],$image_row['cat_id']) && $config['details_vote_download_restriction_options'] == 1)) { //---[Mod] Restrict users to use

STEP 2.2:
find:
Code: [Select]
if (!check_permission("auth_sendpostcard", $image_row['cat_id'])) {

replace by:
Code: [Select]
if (!check_permission("auth_sendpostcard", $image_row['cat_id']) || ($user_info['user_level'] != ADMIN && !check_user_rate($image_row['image_id'],$image_row['cat_id']) && $config['details_vote_download_restriction_options'] == 1)) { //---[Mod] Restrict users to use

STEP 2.3:
find (2 times in this file):
Code: [Select]
"lang_new" => $lang['new'],

add after (2 times in this file):
Code: [Select]
"lang_not_voted" => $lang['not_voted'], //---[ [Mod] Restrict users to use e-card and download if they have not voted first]

STEP 2.4:
find
Code: [Select]
"image_votes" => $image_row['image_votes'],

add after:
Code: [Select]
"image_rated" => check_user_rate($image_row['image_id'], $image_row['cat_id']), //---[ [Mod] Restrict users to use e-card and download if they have not voted first]

STEP 2.5:
find:
Code: [Select]
function rate_form($id, $rate_suffix = "", $rating = ""){

add before:
Code: [Select]
//-------------------------------------------[ [Mod] Restrict users to use e-card and download if they have not voted first]
function check_user_rate($id, $cat_id) {
global $user_info, $site_db;
if (check_permission("auth_vote", $cat_id)) {
  $sql = "SELECT vote
            FROM ".VOTED_TABLE."
            WHERE image_id =".$id." AND user_id =".$user_info['user_id'];

  $row = $site_db->query_firstrow($sql);  
}
  
  return (isset($row['vote']))? 1 : 0 ;
  
}
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]





STEP 3
open lang/<your_language>/admin.php

Find last section that starts with
Quote
$setting_group[##] =
Where ## is a number. Add one (1) to that number and remember it: you will need in STEP 4.2.
(if you got a fresh 4images installation, that number is number 7, you should remember number 8 (7+1=8))
At the end, before closing ?> insert:
Code: [Select]
//-------------------------------------------[ [Mod] Restrict users to use e-card and download if they have not voted first]
/*-- Setting-Group ## --*/
$setting_group[##]="Rating before download and sending e-card";
$setting['details_vote_download_restriction_options'] = "Activate restrictions for download and e-card from the details page ?<br /><span class=\"smalltext\"><b>The users must rate the picture</b> to download it or send it by e-card (Note: The administrator account will not be affected by this restriction.)</span>";
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]
Replace ## with the right number from your code.



STEP 4.1:

open admin/settings.php

find:
Code: [Select]
// end of functions
and add before:
Code: [Select]
//-------------------------------------------[ [Mod] Restrict users to use e-card and download if they have not voted first]
function show_details_vote_download_restriction_options($setting_name, $setting_value) {
  global $details_vote_download_restriction_optionlist;
  echo "<select name=\"setting_item[".$setting_name."]\">";
  foreach ($details_vote_download_restriction_optionlist as $key => $val) {
echo "<input type=\"radio\" name=\"setting_item[".$setting_name."]\" value=\"$key\"";
    if ($setting_value == $key) {
      echo " checked=\"checked\"";
    }
    echo "> ".$val."<br />";
  }
  echo "</select>";
}
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]

STEP 4.2:
find:
Code: [Select]
 show_form_footer($lang['save_changes'], "", 2);

and add before:
Code: [Select]
//-------------------------------------------[ [Mod] Restrict users to use e-card and download if they have not voted first]
  show_table_separator($setting_group[##], 2, "#setting_group_##");
  show_setting_row("details_vote_download_restriction_options", "radio");
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]
Replace ## with the right number from your code, the same number you put in STEP 3.



STEP 5.1

Download, extract, save and execute the following/attached file in your 4images root to make a database update.
Note with this installer you can also remove the database modifications for this MOD  :wink:

------ End of Installation ------

Now, go to your ACP general setting to enable/desable the restriction. 8)
Title: Re: [MOD] - Restricts users to use e-card and download if they have not voted first.
Post by: JensF on August 14, 2005, 12:38:51 AM
Hi,

thanks, it works but what must i do to give an info to the user. Can it open a window they say....Please Vote before???

Or a little window open where the user can vote.....and when they have vote the download begins... <- this where better ;)
Title: Re: [MOD] - Restricts users to use e-card and download if they have not voted fi
Post by: TheOracle on August 14, 2005, 12:44:50 AM
Quote

thanks, it works but what must i do to give an info to the user. Can it open a window they say....Please Vote before???


I was 101% that one of you would post this additional request. 8)

Very well. I will update my post above and, all you'd need to do, is to follow step 2.

Quote

Or a little window open where the user can vote.....and when they have vote the download begins... <- this where better


Actually, it's worst than the first due to ressourcing issues.
Title: Re: [MOD] - Restricts users to use e-card and download if they have not voted fi
Post by: TheOracle on August 14, 2005, 01:02:25 AM
Update :

Post updated above - added step 2 to step 4.

If everything is alright, I could start coding this up to put in the ACP - Settings page. ;)
Title: Re: [MOD] - Restricts users to use e-card and download if they have not voted first.
Post by: JensF on August 14, 2005, 01:54:20 AM
Thanks for this....
Title: Re: [MOD] - Restricts users to use e-card and download if they have not voted fi
Post by: TheOracle on August 14, 2005, 02:10:50 AM
No problem  - enjoy ! 8)
Title: Re: [MOD] - Restricts users to use e-card and download if they have not voted fi
Post by: TheOracle on August 14, 2005, 03:58:52 AM
Update :

My post has been hugely updated - ACP version is now available. ;)
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: JensF on August 14, 2005, 11:26:26 AM
Great....many thanks!!!
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: TheOracle on August 14, 2005, 12:35:17 PM
And, yet, another topic on the move. 8)
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: TheOracle on August 14, 2005, 07:52:30 PM
Here's a screenshot for this MOD :

(http://img18.imageshack.us/img18/214/4imagesacpvotedownload9be.png) (http://imageshack.us)
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on August 20, 2005, 10:46:05 AM
Thank for this mod.
I had found a solution more basic than this one with a similar development  but no problem I am going to adopt this one  :D

Did you know if the limitation provoked by this mod is also valid in the lightbox ?
 :arrow: without voting, the user cannot download in the page of details but can he still download in the lightbox?

Thank you for your answers.
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: TheOracle on August 20, 2005, 12:43:38 PM
Quote

without voting, the user cannot download in the page of details but can he still download in the lightbox?


Indeed. Thanks for reporting this. I didn't thought of blocking this feature when this MOD was first released. Do you wish to have the ZIP function blocked as well - from the lightbox page if the user has not voted ?
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: ch€ri{Bi}² on August 21, 2005, 01:16:38 AM
Do you wish to have the ZIP function blocked as well - from the lightbox page if the user has not voted ?

I think, to go at the end of the reasoning for this mod, that all the functions of downloading (ZIP or not) should depend on the vote of the user  :wink:
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: TheOracle on August 21, 2005, 01:25:21 AM
Quote

I think, to go at the end of the reasoning for this mod, that all the functions of downloading (ZIP or not) should depend on the vote of the user


Excellent point. Which is why, in includes/functions.php file, you must look

for :

Quote

if ($user_info['user_level'] != GUEST) {
    $lightbox_url = $self_url;


then - replace with :

Code: [Select]

if ($user_info['user_level'] != GUEST && !empty($image_row['image_votes']) || $user_info['user_level'] == ADMIN) {
    $lightbox_url = $self_url;


;)

In the mean time, this will be updated in my instructions (see : Step 1.1 & Step 1.2).
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: TheOracle on August 21, 2005, 04:54:54 PM
[MOD-Fix] - Update :

A small correction were made on step 1.1 and step 4 - section 1. The admin account didn't also had the right to download if no votes were sent and users can now see all three statements when not voted. ;)
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on August 22, 2005, 12:53:40 PM
thank you for your work!
I try to install the mod but I have several questions:

Q1 - Step 1.2 : i found the code twice in lightbox.php file.  :?:  Do I have to add/replace it twice?

Q2 - Step 2 : you said "In the same file, find :", you mean "in includes/functions.php file, find:" .
 because the indicated code can not be found in lightbox.php file but in includes/functions.php file. ( update after Step 1.1 >> right?  :wink:)

Q3 - still Step 2 :  i found the code twice.  :?:  same question than Q1

Q4 - after aplying v1.0, it seems lightbox  does not work correctly  :?
when a user rates a picture and send it to the lightbox, the lightbox says : no image found!!!  :?:  how can i fix it?

Last point : You blocked access to the lightbox (unless the user rates the pic) while I thought that you would have (only) blocked the ZIP downloading...  :?
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: TheOracle on August 22, 2005, 01:21:16 PM
Quote

Q1 - Step 1.2 : i found the code twice in lightbox.php file.  Question  Do I have to add/replace it twice?


I only have one result on this one.

Quote

Q2 - Step 2 : you said "In the same file, find :", you mean "in includes/functions.php  file, find:" .
 because the indicated code can not be found in lightbox.php file but in includes/functions.php file. ( update after Step 1.1 >> right?  Wink)


That's a woops and just been edited. ;)

Quote

Q3 - still Step 2 :  i found the code twice.  Question  same question than Q1


Just left a note below that step. That is correct. There were two but forgot to mention to only modify the first one.

Quote

Q4 - after aplying v1.0, it seems lightbox  does not work correctly  Confused
when a user rates a picture and send it to the lightbox, the lightbox says : no image found!!!  Question  how can i fix it?


You made a mistake somewhere. In the mean time - yesterday - I made some corrections so you'd probably want to compare your readings again. ;)

Quote

Last point : You blocked access to the lightbox (unless the user rates the pic) while I thought that you would have (only) blocked the ZIP downloading...


Blocking the ZIP function alone is not an easy task since it has been coded on the same place as the download image (uncompressed) itself. Which is why, I had to block the entire lightbox page ' until ' the users gives their first vote.
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on August 22, 2005, 06:50:54 PM
thank you for your quick answer.

Quote
I only have one result on this one.
perhaps it's about the version. i'm using 1.7.1 and i confirm : i found the code twice in lightbox.php, 1 above line 50 + 1 above line 143.

 :arrow: first :
Quote
//-----------------------------------------------------
//--- Show Images -------------------------------------
//-----------------------------------------------------
$imgtable_width = ceil((intval($config['image_table_width'])) / $config['image_cells']);
if ((substr($config['image_table_width'], -1)) == "%") {
  $imgtable_width .= "%";
}

$num_rows_all = 0;
$num_rows = 0;

if (!empty($user_info['lightbox_image_ids']))  {
  $image_id_sql = str_replace(" ", ", ", trim($user_info['lightbox_image_ids']));


and second:
Quote
//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
$download_button = "";
if (function_exists("gzcompress") && function_exists("crc32")) {
  if (!empty($user_info['lightbox_image_ids'])) {
    $download_button = "<a href=\"".$site_sess->url(ROOT_PATH."download.php?action=lightbox")."\"><img src=\"".get_gallery_image("download_zip.gif")."\" border=\"0\" alt=\"\" /></a>";
  }
  else {
well, i modifyed the two lines  :roll:

Quote
You made a mistake somewhere. In the mean time - yesterday - I made some corrections so you'd probably want to compare your readings again
i began the installation this morning... but i only installed first part! Is there a relation with my lightbox which does not work any more?  :(

for the last point (bloking zip download), i saw this code in lightbox.php:
Code: [Select]
//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
$download_button = "";
if (function_exists("gzcompress") && function_exists("crc32")) {
  if (!empty($user_info['lightbox_image_ids'])) {
    $download_button = "<a href=\"".$site_sess->url(ROOT_PATH."download.php?action=lightbox")."\"><img src=\"".get_gallery_image("download_zip.gif")."\" border=\"0\" alt=\"\" /></a>";
  }
  else {
    $download_button = "<img src=\"".get_gallery_image("download_zip_off.gif")."\" border=\"0\" alt=\"\" />";
  }
}

  :?: is there a way to make a verification  about user's rate (with all pics in lightbox) on this part of lightbox.php file ?

Regards.
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: TheOracle on August 22, 2005, 06:56:34 PM
Quote

perhaps it's about the version. i'm using 1.7.1 and i confirm : i found the code twice in lightbox.php, 1 above line 50 + 1 above line 143.


 :oops: I have 4images v1.7. I'm so sorry for not having specified this in the first place.

Quote

Is there a relation with my lightbox which does not work any more?


Yes, it might ... I did not thought of that when I posted these codes the first time.

Quote

is there a way to make a verification  about user's rate (with all pics in lightbox) on this part of lightbox.php file ?


Try this :

Quote

if (!empty($user_info['lightbox_image_ids'])) {


for :

Code: [Select]

if (!empty($user_info['lightbox_image_ids']) && !empty($image_row['image_votes'])) {

Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on August 23, 2005, 12:30:00 AM
i have a problem with lightbox.php file with 4images v1.71  in Step 1.2.

the code is present twice.

Pb1 - if i modify the first part  :arrow:  my lightbox does not work any more (message : no picture in lightbox)
Pb2 - if i modify the second part  :arrow: lightbox works but ZIP download does not work even if all the images in the lightbox are rated by the user (button is disabled)
Pb3 - if i modify the 2 lines  :arrow:  same as Pb1

 :?:  any idea about the cause?

I would have wished that at this first part of the mod, it already works but... :?  i will complete the installation to know if everything is good at the end.

Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: TheOracle on August 23, 2005, 05:03:47 AM
Quote

Pb2 - if i modify the second part  Arrow lightbox works but ZIP download does not work even if all the images in the lightbox are rated by the user (button is disabled)


I was hoping that I would be the only one having this issue. Unfortunitely, I will have to work on this part again since ' two seperated ' process must be added in order to not affect each other's functions. The thing is, the ZIP download is the same function from the lightbox page as the details page.
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on August 23, 2005, 02:02:10 PM
all the mod installed : stll not working  :( 

the second part (in function.php) enables all buttons except lightbox  8O

Is there anybody who installed this mod (working) with 4images1.7.1?
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on August 23, 2005, 03:34:05 PM
i found the error  for:
Quote
the second part (in function.php) enables all buttons except lightbox 8O

 :arrow: in v1.1 STEP 3  you should replace $config['details_vote_download_options'] == "1"   by   $config['details_vote_download_restriction_options'] == 1

still testing  :wink:
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: TheOracle on August 23, 2005, 04:39:37 PM
Thanks for mentionning this. You are absolutely right. All statements with quotes must be removed due to a pre-defined $key statement from your settings. This has already been discussed elsewhere as it will be corrected. ;)
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: TheOracle on August 23, 2005, 04:41:23 PM
Update :

All quotes has been removed from the $config strings now. ;)
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: TheOracle on August 23, 2005, 05:52:14 PM
Update :

Further modifications has just been done on step 3 - section 2. Thanks to cheribibi for clairing this out.
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on August 23, 2005, 06:27:24 PM
still testing  :wink:

well i think there is a big problem   with empty($image_row['image_votes'])... A more advanced check is absolutely needed !!! 
 :arrow: i think about a check on the vote of the user for the pic and not as now on the presence of a vote on the pic (why not use MOD Votes saved in DB?  :wink:).

I explain : This field remains empty as long as nobody rates the picture. OK?
But as soon as someone rates the pic, this field is not empty any more and this condition comes true systematically... for all the users.
It means that after the first vote of an image, all the users can download, lightbox and send it by ecard  :twisted:

tested with 2 users on several pics : the first rates and the second can download all rated pics (by the first) without rate  8O
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: TheOracle on August 23, 2005, 06:49:36 PM
Quote

tested with 2 users on several pics : the first rates and the second can download rated pics (by the first) without rate


Thanks for pointing this out. That is definitely a bug. I will look into that and add additional statements into these functions to make sure that each votes are being handled seperately. ;)
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: JensF on October 03, 2005, 07:31:40 PM
Hi,

where is TheOracle???

I want help to this Mod. Now it works for a few days but now some Users say to me it doesn´t work. They can Download Pics whitout a vote.

Can anyone help me or can anyone write the Mod in this Board to check all code?!
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on October 03, 2005, 11:33:11 PM
Quote
where is TheOracle???
to know that, you should make a turn in the Chit Chat forum  :roll:

I confirm that full MOD works very well on my site but i don't know exactly what you installed because the published MOD wasn't complete  :?  just see the lasts posts from TheOracle and me.

 :arrow: well, I will publish this MOD again but for the moment I do not have time yet to reconstitute it.
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: JensF on November 13, 2005, 05:38:16 PM
Quote
well, I will publish this MOD again but for the moment I do not have time yet to reconstitute it.

Can you write the code from this Mod, please???

Or everyone???
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on November 28, 2005, 12:23:57 AM
it would be really cool if a rmoderator could move this message at the beginning of the topic  8)
because it's a Re-publishing  :)

Original post : TheOracle (thanks to him)
Original idea & Final debug : me

With this mod, 4images admins can choose to disable download and e-card until the user rates the picture.
works with lightbox too.

 >> 04 files to edit from 4images root:
[change]lightbox.php
[change]includes/functions.php
[change]lang/<your_language>/admin.php
[change]admin/settings.php


 >> 01 new file to download (db update): install_rvotes.php


First, backup your files.

------ Installation ------


STEP 1:

open lightbox.php
find
Code: [Select]
if (function_exists("gzcompress") && function_exists("crc32")) {
  if (!empty($user_info['lightbox_image_ids'])) {
    $download_button = "<a href=\"".$site_sess->url(ROOT_PATH."download.php?action=lightbox")."\"><img src=\"".get_gallery_image("download_zip.gif")."\" border=\"0\" alt=\"\" /></a>";
  }
  else {
    $download_button = "<img src=\"".get_gallery_image("download_zip_off.gif")."\" border=\"0\" alt=\"\" />";
  }
}

replace by:
Code: [Select]
if (function_exists("gzcompress") && function_exists("crc32")) {
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]
$one_not_rated = "";
$rated_images = array();
// search all pics rated by user
$sql = "SELECT image_id
        FROM ".VOTED_TABLE."
        WHERE user_id =".$user_info['user_id'];

 $result = $site_db->query($sql);
 
while($row = $site_db->fetch_array($result)) {
  $rated_images[] = $row['image_id']; // put the result in an array
}
 
$array_lightbox_image_ids = explode(" ", $user_info['lightbox_image_ids']); // put lightboxed pics in an array

foreach ($array_lightbox_image_ids as $element) {
if (!in_array ($element, $rated_images)) { // if current lightboxed pics in not found in rated pics by user
$one_not_rated = 1;
    }
}
    if (!empty($user_info['lightbox_image_ids']) && !$one_not_rated) { // !$one_not_rated  :  means all pics in lightbox have been rated
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]

    $download_button = "<a href=\"".$site_sess->url(ROOT_PATH."download.php?action=lightbox")."\"><img src=\"".get_gallery_image("download_zip.gif")."\" border=\"0\" alt=\"\" /></a>";
  }
  else {
    $download_button = "<img src=\"".get_gallery_image("download_zip_off.gif")."\" border=\"0\" alt=\"\" />";
  }
}



STEP 2.1:
open includes/functions.php
find:
Code: [Select]
if (!check_permission("auth_download", $image_row['cat_id'])) {

replace by:
Code: [Select]
if (!check_permission("auth_download", $image_row['cat_id']) || ($user_info['user_level'] != ADMIN && !check_user_rate($image_row['image_id'],$image_row['cat_id']) && $config['details_vote_download_restriction_options'] == 1)) { //---[Mod] Restrict users to use

STEP 2.2:
find:
Code: [Select]
if (!check_permission("auth_sendpostcard", $image_row['cat_id'])) {

replace by:
Code: [Select]
if (!check_permission("auth_sendpostcard", $image_row['cat_id']) || ($user_info['user_level'] != ADMIN && !check_user_rate($image_row['image_id'],$image_row['cat_id']) && $config['details_vote_download_restriction_options'] == 1)) { //---[Mod] Restrict users to use

STEP 2.3:
find (2 times in this file):
Code: [Select]
"lang_new" => $lang['new'],

add after (2 times in this file):
Code: [Select]
"lang_not_voted" => $lang['not_voted'], //---[ [Mod] Restrict users to use e-card and download if they have not voted first]

STEP 2.4:
find
Code: [Select]
"image_votes" => $image_row['image_votes'],

add after:
Code: [Select]
"image_rated" => check_user_rate($image_row['image_id'], $image_row['cat_id']), //---[ [Mod] Restrict users to use e-card and download if they have not voted first]

STEP 2.5:
find:
Code: [Select]
function rate_form($id, $rate_suffix = "", $rating = ""){

add before:
Code: [Select]
//-------------------------------------------[ [Mod] Restrict users to use e-card and download if they have not voted first]
function check_user_rate($id, $cat_id) {
global $user_info, $site_db;
if (check_permission("auth_vote", $cat_id)) {
  $sql = "SELECT vote
            FROM ".VOTED_TABLE."
            WHERE image_id =".$id." AND user_id =".$user_info['user_id'];

  $row = $site_db->query_firstrow($sql); 
}
 
  return (isset($row['vote']))? 1 : 0 ;
 
}
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]





STEP 3
open lang/<your_language>/admin.php

Find last section that starts with
Quote
$setting_group[##] =
Where ## is a number. Add one (1) to that number and remember it: you will need in STEP 4.2.
(if you got a fresh 4images installation, that number is number 7, you should remember number 8 (7+1=8))
At the end, before closing ?> insert:
Code: [Select]
//-------------------------------------------[ [Mod] Restrict users to use e-card and download if they have not voted first]
/*-- Setting-Group ## --*/
$setting_group[##]="Rating before download and sending e-card";
$setting['details_vote_download_restriction_options'] = "Activate restrictions for download and e-card from the details page ?<br /><span class=\"smalltext\"><b>The users must rate the picture</b> to download it or send it by e-card (Note: The administrator account will not be affected by this restriction.)</span>";
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]
Replace ## with the right number from your code.



STEP 4.1:

open admin/settings.php

find:
Code: [Select]
// end of functions
and add before:
Code: [Select]
//-------------------------------------------[ [Mod] Restrict users to use e-card and download if they have not voted first]
function show_details_vote_download_restriction_options($setting_name, $setting_value) {
  global $details_vote_download_restriction_optionlist;
  echo "<select name=\"setting_item[".$setting_name."]\">";
  foreach ($details_vote_download_restriction_optionlist as $key => $val) {
echo "<input type=\"radio\" name=\"setting_item[".$setting_name."]\" value=\"$key\"";
    if ($setting_value == $key) {
      echo " checked=\"checked\"";
    }
    echo "> ".$val."<br />";
  }
  echo "</select>";
}
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]

STEP 4.2:
find:
Code: [Select]
  show_form_footer($lang['save_changes'], "", 2);

and add before:
Code: [Select]
//-------------------------------------------[ [Mod] Restrict users to use e-card and download if they have not voted first]
  show_table_separator($setting_group[##], 2, "#setting_group_##");
  show_setting_row("details_vote_download_restriction_options", "radio");
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]
Replace ## with the right number from your code, the same number you put in STEP 3.



STEP 5.1

Download, extract, save and execute the following/attached file in your 4images root to make a database update.
Note with this installer you can also remove the database modifications for this MOD  :wink:

------ End of Installation ------

Now, go to your ACP general setting to enable/desable the restriction. 8)
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: V@no on November 28, 2005, 01:23:28 AM
it would be really cool if a rmoderator could move this message at the beginning of the topic  8)
because it's a Re-publishing  :)
Done
Thank you for posting it.
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: JensF on November 28, 2005, 04:31:12 PM
Hello,

thanks for republishing this mod. I have one problem. i can´t find

Code: [Select]
function rate_form($id, $rate_suffix = "", $rating = ""){
in my funkctions.php. I have the Version 1.7

Can anyone help me?
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on November 28, 2005, 08:02:51 PM
Hello,

thanks for republishing this mod. I have one problem. i can´t find

Code: [Select]
function rate_form($id, $rate_suffix = "", $rating = ""){

it does not matter the place where you puts the code  :wink:
the text to find was an example   :arrow:  in order to prevent that the modification affects an existing function !
write the code at the end of your functions.php file, before the ?>.
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: JensF on November 29, 2005, 03:16:54 PM
Thanks, the Mod is working fine....
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: JensF on December 05, 2005, 03:25:26 PM
Hi,

is there a way User must give a vote for the pic before he can put it into the lightbox???
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on December 05, 2005, 09:13:55 PM
yes it's possible but... need to add some other conditions...

 :idea: let me explain how this mod works in lightbox :

all the users are able to send picture in lightbox but they can not download  the (zipped) pictures  if there is at least one picture still not rated ...
in others words, a user can use lightbox as he want... but the only way to download all the pictures in lightbox is to rate all the pictures present in the lightbox  :wink:

and this is why i asked for this (http://www.4homepages.de/forum/index.php?topic=9387.0) : if a user forgot to rate a picture, he can do it directly on thumbs in lightbox  8)
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: JensF on December 11, 2005, 06:48:20 PM
Hi,

is there a way to disable the function for the own images????
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: V@no on December 11, 2005, 07:15:50 PM
Hi,

is there a way to disable the function for the own images????
not with this method...TheOracle introduced simple download button hiding method, yet, if you type manualy in the address bar the url to download lightbox, you'll be able to avoid this restrictions. If this restrctions were made directly in download.php intead, then it would be possible modify it to disable restrictions for own images...
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: Eagle Eye on January 26, 2006, 05:01:11 AM
nice MOD,

Did it, but now i am not able to save the settings in the ACP (meaning, its always in "no" and cannot activate it)
i had skiped the 1st part (the lightbox.php) cause i have a previous mod (multiple lightboxes) and don't care about the donwload, just the "send ecard" function...

Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: V@no on January 26, 2006, 05:17:08 AM
Probably missed step 5.1
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: Eagle Eye on January 26, 2006, 06:45:27 AM
:( i had done this step, did it again, no change, still i cannot save the changes

edit: i have skiped Step 1, is it the reason? (i do not want this funtion on download button) - also have the multi lightbox mod
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: V@no on January 26, 2006, 07:50:43 AM
Its a bug in Step 4.1
The code should be:
Code: [Select]
//-------------------------------------------[ [Mod] Restrict users to use e-card and download if they have not voted first]
function show_details_vote_download_restriction_options($setting_name, $setting_value) {
 global $details_vote_download_restriction_optionlist, $config;
 $setting_value = $config[$setting_name];
 echo "<select name=\"setting_item[".$setting_name."]\">";
 foreach ($details_vote_download_restriction_optionlist as $key => $val) {
echo "<input type=\"radio\" name=\"setting_item[".$setting_name."]\" value=\"$key\"";
   if ($setting_value == $key) {
     echo " checked=\"checked\"";
   }
   echo "> ".$val."<br />";
 }
 echo "</select>";
}
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]
Note, this is only a visual bug, the settings are being updated just fine ;)
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: Eagle Eye on January 26, 2006, 08:15:25 AM
 :cry: still no change (practically and visually)
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on January 26, 2006, 03:16:51 PM
:cry: still no change (practically and visually)
are you meaning that even if you change manually the value in field details_vote_download_restriction_options on 4images_settings table (change 0 to 1 or 1 to 0), nothing happens?

well, i think the best way to make it work is to install the entire the mod, test it first and then after  you are sure it works, you can suppress or delete some features like protect lightbox or other...
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: TheOracle on January 26, 2006, 03:19:24 PM
Thanks for advising this. When I first coded this, I wondered if the $config string could of been used under the settings page as part of the general function that has just been corrected above.

Quote

are you meaning that even if you change manually the value in field details_vote_download_restriction_options on 4images_settings table (change 0 to 1 or 1 to 0), nothing happens?


I have tested this part as it should work even by replacement - either - manually or automatically from your ACP's configuration page. ;)
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: john999 on May 16, 2006, 12:27:42 PM
I already doublechecked my code and still I´m getting this:

Code: [Select]
DB Error: Bad SQL Query: SELECT vote FROM VOTED_TABLE WHERE image_id =929 AND user_id =-1
Table 'john999.VOTED_TABLE' doesn't exist

This is just one of many, they differ only in the image ID.

What could be the reason for it?

I also execuded http://***.de/4images/install_rvotes.php and it said "success".


What did I miss?


Thx alot :)


€dit: http://www.4homepages.de/forum/index.php?topic=6123.0

Would this help? What Version should I take? A or B?
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: V@no on May 16, 2006, 03:26:18 PM
I guess this mod is required [MOD] Votes saved in DB  (http://www.4homepages.de/forum/index.php?topic=6123.0) mod...
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: john999 on May 16, 2006, 04:09:00 PM
Ok, I already installed that Mod. By executing this "voted_a_install.php" I got a new Table called "VOTED_TABLE"
-> The SQL Error vanished *surprise-surprise* ;)

Bad news: The Download Butten is still disabled after vote.

So I added also the changes named in "A".

After that I got again Errors, this time it mentioned:
Code: [Select]
DB Error: Bad SQL Query: SELECT vote FROM 4images_voted WHERE image_id =939 AND user_id =1
Table 'john999.4images_voted' doesn't exist

So I just copied "Voted_Table" to "4images_voted"
-> Errors vanished again

Bad news: The Button is still not enabeld.

In both Tables (4images_voted and VOTED_TABLE) no data is stored after a vote. Nor by guest, nor by registered user.
(BTW: As admin the Buttons are all the time activated.)
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on May 16, 2006, 05:32:01 PM
Quote
Bad news: The Download Butten is still disabled after vote.
i forgot to mention : this mod requires version A of [MOD]Votes saved in DB  (http://www.4homepages.de/forum/index.php?topic=6123.0)
the two tables you are talking about are supposed to be the same table (4images_voted is the real name of the mysql table, VOTED_TABLE is a global variable used in PHP to make mysql queries...)

and if there is no data stored in VOTED_TABLE after some votes then  :? 
 :arrow: the present mod will never know who voted  and the button will always stay disabled
 :arrow: you made a mistake when you install [MOD]Votes saved in DB  (http://www.4homepages.de/forum/index.php?topic=6123.0) version A!! Try to re-install the complete mod  :wink:

 :!: admin accounts are not concerned by these restrictions, that's why admin will always have buttons enabled.

Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: john999 on May 16, 2006, 06:53:53 PM
Oh no, I am so an idiot...

I tested this as admin -> ok there it is always activated (of course ... why should the admin lock himselfe out ^^)
So I tested it, when I was logged out -> as Guest


But I did not tested it as a normal registered user logged in. <- There it works perfectly...data is stored in table and so on.


But now I am a little bit sad because I thougt this MOD would also allow Guests to Download after they have voted.
The Votes are counted, but there is no entry in the table (jeah I know, he has no UserID)

But maybe it is possible that the voting is saved by cookie/ip, so that this Guest can download the image after a vote.

Code: [Select]
if (!in_array($id, $split_list) && !in_array($id, $cookie_rated) && !$rated) {Thought that "$cookie_rated" was what I was searching :(

Any ideas how to implement that?
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on May 16, 2006, 08:08:35 PM
Oh no, I am so an idiot...
hehe! you're welcome  :mrgreen:

But maybe it is possible that the voting is saved by cookie/ip, so that this Guest can download the image after a vote.
well you can use this mod (http://www.4homepages.de/forum/index.php?topic=5853) to store a cookie when a user rates a pic... but...
 :arrow: you have to add extra code to verify the cookies in this mod
 :arrow: if it's a guest and if he deletes the cookie, he can vote again and again for the same picture :twisted:



Code: [Select]
if (!in_array($id, $split_list) && !in_array($id, $cookie_rated) && !$rated) {Thought that "$cookie_rated" was what I was searching :(

Any ideas how to implement that?
:?: where did you see this code ?
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: john999 on May 16, 2006, 08:21:36 PM
The doublevoting isn´t that important. I just want to give them a chance to save the image :D


I´ll have a look at this MOD, but something tells me that won´t work at the first try ;)
Arghh you edited your post...
Quote
you have to add extra code to verify the cookies in this mod
... now I´m sure that I won´t manage it without help :([/color]

Maybe you could give me some advice how to verify cookies of guests (especially for my mod ^^)

Quote
where did you see this code ?
Found the Code here (http://www.4homepages.de/forum/index.php?topic=6123.0") ... Step 1.2 (but I´m not an expert in PHP so I don´t know what it does)
Thx so far
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: Ch*yeuk on July 18, 2006, 11:03:36 PM
I can't find the code in STEP 2.5? I have version 1.7.2
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on July 28, 2006, 07:58:09 PM
I can't find the code in STEP 2.5? I have version 1.7.2
:? not sure this code come from the original script !!!

but it's not a problem   :arrow:  add the code at the very end of the file, before the final ?>  :wink:
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted fir
Post by: macmaster_it on August 25, 2006, 05:36:31 PM
Hi all,
nice Mod. works well also with 4.Images 1.7.3.
But I must turn off this function, because I'm missing e massages to the user, that he must vote befor download....
Plaese make e change!! The button must be available and when you click them have to apear a pop-up-window...
otherwise you can give the info also when go with the mouse over the button (like e tooltip).
I not know how realize that, but maked like that it will be a great feature!!!

thank's a lot
ron.
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: ch€ri{Bi}² on August 26, 2006, 01:35:37 AM
you can give the info also when go with the mouse over the button (like e tooltip).
that's the method i use  8)
 :arrow: and you can make it by yourself with this help (http://www.4homepages.de/forum/index.php?topic=11252.msg58106#msg58106)  :wink:
Title: Re: [MOD] - Restrict users to use e-card and download if they have not voted first.
Post by: Jetstream on August 09, 2007, 12:51:32 AM
Hi all

I have exatcly the same request as john999. I give the download right for all my pictures not only to users, but also to guest. For that reason, it is important for me that this mod works cookie based. Now that I have found the other mod who saves ratings in a cookie too, I am looking for the "extra code to verify the cookies" mentioned by ch€ri{Bi}². Now I am, just like john999, not the php expert and need help to realize that.

Who can help us?