|
Joined: Feb 2001
Posts: 2,268
Junior Member
|
Junior Member
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?
|
|
|
|
Joined: May 1999
Posts: 3,039
Guru
|
Guru
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. <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
|
|
|
|
Joined: Feb 2001
Posts: 2,268
Junior Member
|
Junior Member
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): <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.
|
|
|
|
Joined: Feb 2001
Posts: 2,268
Junior Member
|
Junior Member
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: <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!
|
|
|
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.
|
|
Posts: 1,157
Joined: July 2001
|
|
Forums63
Topics37,573
Posts293,925
Members13,849
|
Most Online5,166 Sep 15th, 2019
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|