Previous Thread
Next Thread
Print Thread
Rate Thread
#267677 01/21/2004 2:24 PM
Joined: Feb 2001
Posts: 2,268
Junior Member
Junior Member
Offline
Joined: Feb 2001
Posts: 2,268
I'm trying to compair a user's groups to the groups that are allowed to reply to a board. This is what I have:

Groups = -3-1-

Can Reply = -1-2-3-

I've been trying to use strstr to compair them, but I can't get a true result. Any ideas?

Sponsored Links
Joined: May 1999
Posts: 3,039
Guru
Guru
Offline
Joined: May 1999
Posts: 3,039
You'd actually need to do a couple of arrays and do a comparison using the arrays. Something like below might work.

Code
<br />$usergroups = split("-",$Groups);<br />$replygroups = split("-",$CanReply);<br /><br />$canreply = 0;<br />for($i=0;$i<sizeof($readgroups);$i++) {<br />   if (in_array($readgroups[$i],$usergroups)) {<br />      $canreply = 1;<br />   }<br />}<br /><br />// If $canreply is one then the user can reply<br />


UBB.threads Developer
Sally #267679 01/22/2004 1:01 AM
Joined: Feb 2001
Posts: 2,268
Junior Member
Junior Member
Offline
Joined: Feb 2001
Posts: 2,268
I tried the script you posted and I can't get it to work (I made a few changes to it):

Code
 <br />   $usergroups = split("-",$Groups); <br />   $gsize = sizeof($usergroups); <br /> <br />   $replygroups = split("-",$canreply); <br />   $rsize = sizeof($replygroups); <br />   $reply = "No"; <br />   for($i=0;$i<$rsize;$i++) { <br /> 	if (in_array($usergroups[$i],$replygroups)) { <br /> 		$reply = "Yes"; <br /> 			} <br /> 		} <br /> <br />   $writegroups = split("-",$canpost); <br />   $wsize = sizeof($writegroups); <br />   $post = "No"; <br />   for($i=0;$i<$wsize;$i++) { <br />	if (in_array($usergroups[$i],$writegroups)) { <br /> 		$post = "Yes"; <br /> 			} <br /> 		} <br /> <br /> 


This is the outcome:

User Groups = -3-1-
Reply Groups = -1-2-3-
Post Groups = -1-2-
Group Size = 4 Reply Size = 5 Write Size = 4
Can Reply = No
Can Post = No

I'll keep at it, but man is it frustrating!

Last edited by Dalantech; 01/22/2004 1:50 AM.
Sally #267680 01/22/2004 2:11 AM
Joined: Feb 2001
Posts: 2,268
Junior Member
Junior Member
Offline
Joined: Feb 2001
Posts: 2,268
OK, I got it. I had to do a little "script diving" in the showflat.php file to figure it out. Here is what it looks like:

Code
 <br />// Set up the news board for the queries<br />   $Newsboard_q = addslashes($index['newsboard']);<br /><br />// We need to see if they have reply and post access to the news board.<br /><br />   $query = "<br />     SELECT Bo_Reply_Perm,Bo_Write_Perm<br />     FROM   {$config['tbprefix']}Boards<br />     WHERE  Bo_Keyword = '$Newsboard_q'<br />   ";<br />   $sth = $dbh -> do_query($query);<br />   list($canreply,$canpost) = $dbh -> fetch_array($sth);<br />   $dbh -> finish_sth($sth);<br /> <br />   $usergroups = split("-",$Groups);<br />   $gsize = sizeof($usergroups);<br />   <br />   $reply = "No";<br />   for($i=0;$i<$gsize;$i++) {   <br />   if (strstr($canreply,"-$usergroups[$i]-") ) {<br /> 		$reply = "Yes"; <br /> 			}<br /> 		}<br /> 		<br />   $post = "No";<br />   for($i=0;$i<$gsize;$i++) {   <br />	if (strstr($canpost,"-$usergroups[$i]-") ) {<br /> 		$post = "Yes"; <br /> 			}<br /> 		}<br /><br /> 


I tested it by echoing out the contents of the post and reply variables on my dev site, and then I hit the page logged in and out -works like a charm

BTW: Thanks for taking the time to comment your scripts! I've learned a great deal about PHP from reading your comments and then going over your code!


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
isaac
isaac
California
Posts: 1,157
Joined: July 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)