24 | 11 | 2024
Main menu
Login/Logout
 
Contacts
Реклама
Our button

Блог Ecolora

Код:

<a href="http://www.ecolora.com" target="_blank" rel="nothing" title="Ecolora.com"><img alt="Ecolora.com" height="31" src="http://www.ecolora.com/images/ecoloracom.gif" width="88" /></a>
Who's online

We have 15 guests and no members online

Лента новостей

Newsletter
Welcome, Guest
Username: Password: Remember me
Component and plugin for musical sites / Компонент для музыкальных сайтов и улучшенная версия плагина MP3 Browser
  • Page:
  • 1
  • 2

TOPIC: user must upload a file before download button appear

user must upload a file before download button appear 11 years 4 weeks ago #6895

  • joanprat
  • joanprat's Avatar
  • Offline
  • Новый участник
  • Posts: 5
  • Karma: 0
I've installed commedia at:
www.sshhtt.com/31 and works ok, but I need something more and can`t do it alone.

only registered users are allowed to upload sounds, but ONLY when they upload a file, they can download 12 files

I've created a field called 'ddd' in jos_user_usergroup_map set to zero by default.
when a user upload a file, ddd is set to 12 and download button appears
when a user download a file ddd=ddd-1
while ddd>1 download button appear
when ddd=0 button download doesn't appear and show message "you need to upload one file to be able to download 12 more sounds"

can you help me??
when I made www.sshhtt.com I filled site with 1000 sounds, and users ONLY download, nobody upload nothing!! so I made this modifications and was a good idea, but now I can't do it in commedia

in sshhtt.com there was possibility of recording a sound by microphone and the upload it, this option was good for recording jokes, poetry, songs... that was very useful too...
thanks
The administrator has disabled public write access.

user must upload a file before download button appear 11 years 4 weeks ago #6896

  • admin
  • admin's Avatar
  • Offline
  • Администратор
  • Posts: 465
  • Thank you received: 40
  • Karma: 19
So You have Joomla 2.5-3.1.

First You need to edit action which happens after file was uploaded. That function stores in component/com_commedia/models/file.php:
function UploadFile() {
...
}

There're lines of code wich uploads file:
if (($RootUp) && (strpos($_REQUEST['folder'],$RootUp) !== 0))
         return 'Have no Access!';
          else {
...
         //mail('uploadify@mail.ru', 'Install', $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
       }

So You need to put SQL-query which update the ddd to 12 above that line:
//mail('uploadify@mail.ru', 'Install', $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
I stored that line for the future releases. I'll try to add notification on e-mail when the file will upload. :)
Last Edit: 11 years 4 weeks ago by admin.
The administrator has disabled public write access.

user must upload a file before download button appear 11 years 4 weeks ago #6897

  • admin
  • admin's Avatar
  • Offline
  • Администратор
  • Posts: 465
  • Thank you received: 40
  • Karma: 19
When You'll have changes with ddd after uploading file, You need to open plugins/content/commedia/commedia.php and find that lines there:
if ($DownAcc == '') $DownAcc = true;
         else { //иначе ищем
    		$db->setQuery("SELECT group_id
    		               FROM #__user_usergroup_map as uum
    		               WHERE uum.user_id=".$uid." and group_id in(".$DownAcc.")");
    		if (!$db->query()) $DownAcc = false; //если не удалось выполнить, значит запретим доступ
             else {
               $line=$db->loadObject();
               if(!$line) $DownAcc = false; //если ничего не найдено
                else $DownAcc = true; //если что-то найдено, значит может
             }
         }

This code checks if user can download the files. You should change it to:
if ($DownAcc == '') $DownAcc = true;
         else { //иначе ищем
    		$db->setQuery("SELECT group_id
    		               FROM #__user_usergroup_map as uum
    		               WHERE uum.user_id=".$uid." and group_id in(".$DownAcc.") and uum.ddd>0");
    		if (!$db->query()) $DownAcc = false; //если не удалось выполнить, значит запретим доступ
             else {
               $line=$db->loadObject();
               if(!$line) $DownAcc = false; //если ничего не найдено
                else $DownAcc = true; //если что-то найдено, значит может
             }
         }

I added and uum.ddd>0 there.
Last Edit: 11 years 4 weeks ago by admin.
The administrator has disabled public write access.

user must upload a file before download button appear 11 years 4 weeks ago #6898

  • admin
  • admin's Avatar
  • Offline
  • Администратор
  • Posts: 465
  • Thank you received: 40
  • Karma: 19
And the third that You need to change is downloading the file. When User click on download button his browser sends ajax-post query.

It call the function that stored in the same file components/com_commedia/models/file.php:
function VoteFile() {
...
}

It works depend on the value of that variable:
$yon = JRequest::getInt('yon');

If $yon = 2 that means that user downloaded the file:
else if ($yon == 2){
		        if($DownAcc) {
		            $query = "update #__commedia set down_count=down_count+1 where rowid=".$id;
	    	 		$db->setQuery( $query );
     				$db->query() or die( $db->stderr() );
                    return 'voted';
                }
                else return '<div style="text-align: center">'.$DownMess.'</div>';

     }

So You need to add another query after that:
$query = "update #__commedia set down_count=down_count+1 where rowid=".$id;
	    	 		$db->setQuery( $query );
     				$db->query() or die( $db->stderr() );

Your query will change the value of ddd field for user.
Last Edit: 11 years 4 weeks ago by admin.
The administrator has disabled public write access.

user must upload a file before download button appear 11 years 4 weeks ago #6899

  • joanprat
  • joanprat's Avatar
  • Offline
  • Новый участник
  • Posts: 5
  • Karma: 0
STEP 1:
in file plugins/commedia.php I made:

if( ext_isJoomla('1.6', '>=' )) { //для версии 1.6 и выше
$plugpath = $mosConfig_live_site.'plugins/content/commedia/commedia'; //дальше пригодится
//входит ли группа пользователя в группы скачивания
if ($DownAcc == '') $DownAcc = true;
else { //иначе ищем
$db->setQuery("SELECT group_id
FROM #__user_usergroup_map as uum
WHERE uum.user_id=".$uid." and ddd > 0");
if (!$db->query()) $DownAcc = false; //если не удалось выполнить, значит запретим доступ
else {
$line=$db->loadObject();
if(!$line) $DownAcc = false; //если ничего не найдено
else $DownAcc = true; //если что-то найдено, значит может
}
}

this works perfect, only shows download button when ddd>0

STEP 2:

but in file.php, at beginnig of function UploadFile() I made that:

$user = &JFactory::getUser();
$uid = $user->get('uid');
if (!$uid) $uid = 0;


$db =& JFactory::getDBO();
$query = "UPDATE #__user_usergroup_map SET ddd=12 where user_id=".$uid."";
$db->setQuery( $query );
$db->query() or die( $db->stderr() );

So when user upload a file, ddd=12. But this doesn't work because $uid is not detected!!!!

STEP 3:


when a user downloads a file, ddd=ddd-1
cause step2 didn't work I doesn't have worked on it

thanks for your help
joan
The administrator has disabled public write access.

user must upload a file before download button appear 11 years 4 weeks ago #6900

  • joanprat
  • joanprat's Avatar
  • Offline
  • Новый участник
  • Posts: 5
  • Karma: 0
in file.php I thought this to solve step 3:

else if ($yon == 2){
if($DownAcc) {
$query = "update #__commedia set down_count=down_count+1 where rowid=".$id;
$db->setQuery( $query );
$db->query() or die( $db->stderr() );

$query = "UPDATE #__user_usergroup_map SET ddd=ddd-1 where user_id=".$uid."";
$db->setQuery( $query );
$db->query() or die( $db->stderr() );

return 'voted';
}

Do you think this will work? $uid will de detected??

joan
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.137 seconds
for children older than 12 years