Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-22-2004, 05:17 AM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default whats going on here? :(

Yes im having abit of a problem with some hacking here. Maybe someone can help me out. Worth a shot huh? Okay here it goes.



I started to work on a hack that will remember if a user has clicked the I Agree on a T.O.S. Page. I was told to use a session or a setcookie. But then i decided to go ahead and do it this way:


add a field to the user table called 'tos' or 'agree' or something - enum ('n','y');

set all current and new users to 'n';

on the usercp.php page, once they successfully enter it, check this field - if it's set to 'n' then show the user agreement form - if it's set to 'y' then let them go to there user cp panel.


So heres what i did.

I ran this SQL Query:
[sql]
ALTER TABLE user ADD tos ENUM('n','y') DEFAULT 'n';
[/sql]


And this is what you put in the begining of the usercp.php after permissions are checked.

PHP Code:
//connetion info
$query mysql_query("select tos from user where id='$user[userid]'") or die(mysql_error());
$row=mysql_fetch_array($query);
$user $row[tos];

if (
$user=='n')
{
        
// this will fetch the agreement template
        
eval('print_output("' fetch_template('clients_tos') . '");');
}
else
{
       
//All the usercp.php code here

then the agreement template is this:
HTML Code:
<form action="tos.php" method="post">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr><td>

<!-- My Agreement Terms Here -->


<input type="checkbox" name="agree" value="y" /><strong>I have read, and agree to abide by tos rules.</strong>

<input type="submit" value="I Agree">
</td></tr>
</table>

</form>

Then i made a tos.php file with this:

PHP Code:
<?php
if ($_POST['agree'] == 'y')
{
echo 
$user[userid];
        
mysql_query("update user set tos = 'y' where id='$user[userid]'");
        echo 
'redirect code';
}
?>
But when i go to the usercp.php i get this error now from the or die(mysql_error()

Quote:
Unknown column 'id' in 'where clause'
Any ideas? Someone told me to do this sql

[sql]ALTER TABLE user ADD id BIGINT NOT NULL;[/sql]

and when i did that i had this problem. lets say no users have clicked i agree yet. And user A logs in and see the new agreement, then clicks the i agree button. Then he is redirect back to the usercp page. which is perfect. But now when user B logs in, he don't see it cause user A has clicked yes. This is vice versa also. Seems if any one person clicks yes, it sets yes to all.

i was told it may be that the $user array isn't returning the user data.

Any other ideas why? Thanks guys!!!!!!!!
Reply With Quote
  #2  
Old 07-22-2004, 07:13 AM
assassingod's Avatar
assassingod assassingod is offline
 
Join Date: Jul 2002
Posts: 3,337
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
        mysql_query("update user set tos = 'y' where id='$user[userid]'"); 
That should be
PHP Code:
        mysql_query("update user set tos = 'y' where userid='$user[userid]'"); 
The column is called userid, not id

Also, you can require global.php and you wont have to use mysql_query:

PHP Code:
<?php

require_once('./global.php');

if (
$_POST['agree'] == 'y')
{
echo 
$user[userid];
        
$DB_site->query("update user set tos = 'y' where userid='$user[userid]'");
        echo 
'redirect code';
}
?>
Reply With Quote
  #3  
Old 07-22-2004, 07:28 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Steve is right

just a suggestions, when you add yes/no options, i would suggest to use the useroptions bitarray for that.
Just a hint of course, enum isn't bad
Reply With Quote
  #4  
Old 07-22-2004, 07:47 AM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Xenon
Steve is right

just a suggestions, when you add yes/no options, i would suggest to use the useroptions bitarray for that.
Just a hint of course, enum isn't bad
How would i do that? And thanks Steve, can't belive i didn't see that. Kinda late
Reply With Quote
  #5  
Old 07-22-2004, 08:05 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

at first you have to edit init.php

there you will find this codeblock:

PHP Code:
// Defined constants used for user field.
$_USEROPTIONS = array(
    
'showsignatures'    => 1,
    
'showavatars'       => 2,
    
'showimages'        => 4,
    
'coppauser'         => 8,
    
'adminemail'        => 16,
    
'showvcard'         => 32,
    
'dstauto'           => 64,
    
'dstonoff'          => 128,
    
'showemail'         => 256,
    
'invisible'         => 512,
    
'showreputation'    => 1024,
    
'receivepm'         => 2048,
    
'emailonpm'         => 4096,
    
'hasaccessmask'     => 8192,
    
//'emailnotification' => 16384, // this value is now handled by the user.autosubscribe field
    
'postorder'         => 32768,
); 
you can add more options there, you just have to make sure, that your values, are 2 ^x and bigger than the currently existing ones, so in your special case here, i suggest something like:

PHP Code:
// Defined constants used for user field.
$_USEROPTIONS = array(
    
'showsignatures'    => 1,
    
'showavatars'       => 2,
    
'showimages'        => 4,
    
'coppauser'         => 8,
    
'adminemail'        => 16,
    
'showvcard'         => 32,
    
'dstauto'           => 64,
    
'dstonoff'          => 128,
    
'showemail'         => 256,
    
'invisible'         => 512,
    
'showreputation'    => 1024,
    
'receivepm'         => 2048,
    
'emailonpm'         => 4096,
    
'hasaccessmask'     => 8192,
    
//'emailnotification' => 16384, // this value is now handled by the user.autosubscribe field
    
'postorder'         => 32768,
    
'tosagree'        =>  1048576,
); 
and then instead of:
PHP Code:
$DB_site->query("update user set tos = 'y' where userid='$user[userid]'"); 
you have to use:
PHP Code:
$DB_site->query("UPDATE user SET options = options | $_USEROPTIONS[tosagree] WHERE userid = $user[userid]"); 

There is a thread at the mod hints and tips iirc explaining how to work with bitarrays
Reply With Quote
  #6  
Old 07-22-2004, 08:08 AM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you very much Xenon! Will look into this right now. Who needs sleep! (2 days and counting....)
Reply With Quote
  #7  
Old 07-22-2004, 08:48 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You're welcome

Hmm, who needs sleep? Would you be so kind to explain the word sleep? I don't recognize it ^^
Reply With Quote
  #8  
Old 07-22-2004, 08:51 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

@Xenon
I don't think it is a good idea to use currently unused bits in standard bitfields for custom hacks. Sooner or later Jelsoft will use them for other options, which will cause problems then.
Reply With Quote
  #9  
Old 07-22-2004, 09:00 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's why i left out a few bits between

the way Jelsoft did it was to make it easier for custom additions, and so i would recommend to follow their way
Reply With Quote
  #10  
Old 07-22-2004, 09:20 AM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

would require deleting the old query and adding a new one?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:01 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.10334 seconds
  • Memory Usage 2,303KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_html
  • (9)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete