Author Topic: [MOD] - Restrict users to use e-card and download if they have not voted first.  (Read 54528 times)

0 Members and 2 Guests are viewing this topic.

TheOracle

  • Guest
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)
« Last Edit: November 28, 2005, 01:24:25 AM by V@no »

Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
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 ;)
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

TheOracle

  • Guest
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.

TheOracle

  • Guest
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. ;)

Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Thanks for this....
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

TheOracle

  • Guest
No problem  - enjoy ! 8)

TheOracle

  • Guest
Update :

My post has been hugely updated - ACP version is now available. ;)

Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Great....many thanks!!!
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

TheOracle

  • Guest
And, yet, another topic on the move. 8)

TheOracle

  • Guest
Here's a screenshot for this MOD :


Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
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.
ch€ri{Bi}²


TheOracle

  • Guest
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 ?

Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
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:
ch€ri{Bi}²


TheOracle

  • Guest
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).

TheOracle

  • Guest
[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. ;)