View Full Version : conditional won't work together but work's split up?
sabret00the
03-15-2005, 12:17 PM
if ($postinfo['userid'] != $bbuserinfo[userid] AND !$grps_permissions['groupspostedit']) OR (!$grps_permissions['groupsmoderater']))
{
print_no_permission();
}
i can't figure out what's wrong with it :(
Marco van Herwaarden
03-15-2005, 12:38 PM
Should that OR be an AND?
neocorteqz
03-15-2005, 12:50 PM
Should that OR be an AND?I thought it was just OR, but then again I'm still learning php. :)
and is he not missing a ( at the beginning.
should be
if (($postinfo['userid'] != $bbuserinfo[userid] AND !$grps_permissions['groupspostedit']) OR (!$grps_permissions['groupsmoderater']))
{
print_no_permission();
}
I'm sure it was just a typo.
Marco van Herwaarden
03-15-2005, 01:15 PM
YEs you are right, he is also missing a leading (. He would get a syntax error on that.
sabret00the
03-15-2005, 01:17 PM
yeah that was a typo from where i reconstructed the two conditionals to make em once
but php
if ($postinfo['userid'] != $bbuserinfo[userid] AND !$grps_permissions['groupspostedit'])
works
and if (!$grps_permissions['groupsmoderater']) works but when you combine em
if (($postinfo['userid'] != $bbuserinfo[userid] AND !$grps_permissions['groupspostedit']) OR (!$grps_permissions['groupsmoderater']))
{
print_no_permission();
}
don't :( it just shows the no_permission screen :(
Marco van Herwaarden
03-15-2005, 01:27 PM
Like i said......change the OR to AND
sabret00the
03-15-2005, 01:47 PM
the OR is supposed to be an AND though
basically if the userid is not the same as your userid and you don't have the usergroup permission anyway then show no permission and the second bit is if you're not a moderator then show no permission, so both are independant.
Marco van Herwaarden
03-15-2005, 02:08 PM
Well if you combine 2 (or more) NOT '!' conditions they will get related.
Example of what you want:
1. If you are not the poster AND not have rights to edit (this will mean that if you are the poster, but don't have the right to edit (your own post) you still can edit):
(($postinfo['userid'] != $bbuserinfo[userid] AND !$grps_permissions['groupspostedit'])
Let's see what can happen:
- I am the poster, and i have rights to edit. The above is NOT true, so no error msg.
- I am the poster, and i have NO rights to edit. The above is NOT true (the first part of the condition is false), so no error msg.
- I am NOT the poster, and i have rights to edit. The above is NOT true, so no error msg.
- I am the NOT poster, and i have NO rights to edit. The above is true, so i get a no permission page.
Now the second part:
(!$grps_permissions['groupsmoderater'])
I guess what we want here is that a moderator (spelling mistake in the permission??) can always edit, no matter if he made the post himself. If not combined with other conditions this would be ok. But now let's see what happens if we combine:
(($postinfo['userid'] != $bbuserinfo[userid] AND !$grps_permissions['groupspostedit']) OR (!$grps_permissions['groupsmoderater']))
Let's call the 3 conditions here 'post_user != cur_user', 'C2' and 'C3', so we could write:
((post_user != cur_user AND !C2) OR (!C3))
We can have the following now:
- User is same, C2 is TRUE (making the test false!!!), and C3 is FALSE(he is not a moderator, making this test true. So we have here a user, who made this post, have edit rights and is not a moderator, this would result in:
1. post_user != cur_user......FALSE (the user is the same)
2. !C2....FALSE (the user has permission to edit)
3. !C3....TRUE (the user is not a moderator)
this will result in:
((FALSE AND FALSE) OR (TRUE))
this equals to:
(FALSE OR TRUE)
this equals to:
TRUE
what you probably need it the following:
( !($postinfo['userid'] == $bbuserinfo[userid] AND $grps_permissions['groupspostedit']) AND (!$grps_permissions['groupsmoderater']))
sabret00the
03-15-2005, 02:28 PM
Let's see what can happen:
- I am the poster, and i have rights to edit. The above is NOT true, so no error msg. correct and working as intended
- I am the poster, and i have NO rights to edit. The above is NOT true (the first part of the condition is false), so no error msg. incorrect should see error message
- I am NOT the poster, and i have rights to edit. The above is NOT true, so no error msg. correct and working as intended
- I am the NOT poster, and i have NO rights to edit. The above is true, so i get a no permission page. correct and working as intended
I guess what we want here is that a moderator (spelling mistake in the permission??) can always edit, no matter if he made the post himself. If not combined with other conditions this would be ok. But now let's see what happens if we combine: correct so far
( !($postinfo['userid'] == $bbuserinfo[userid] AND $grps_permissions['groupspostedit']) AND (!$grps_permissions['groupsmoderater']))
here i'm lost because, a user should be able to edit their own posts without being a moderator, however a moderator should be able to edit any post without being the original poster, but your code says they can't be a moderator?
so bascially let me try and do this in conditionals to try and explain myself
if ($postinfo[userid == $bbuserinfo[userid])
{
$allow_edit = TRUE;
}
if ($grps_permissions[groupspostedit] == TRUE)
{
$allow_edit2 = TRUE;
}
if (!$allow_edit and !$allow_edit2)
{
print_no_permission;
}
else
{
echo "edit screen";
}
but because we want mods to be able to edit posts two, we have to make sure you're not a moderator so
if ((!$allow_edit and !$allow_edit2) OR ($user_is_moderator == FALSE)
{
print_no_permission;
}
else
{
echo "edit screen";
}
Marco van Herwaarden
03-15-2005, 02:38 PM
What my code does is:
If they are NOT (poster AND have edit perms) AND are NOT a moderator: Error message
Edit wrong!
sabret00the
03-15-2005, 02:41 PM
What the code should do is:
If they are NOT original_poster OR are NOT a_moderator: Error message
(that's simplified cos i left out the check to make sure they have permission to edit their own posts)
Marco van Herwaarden
03-15-2005, 02:42 PM
Let's do this again
if (!$allow_edit and !$allow_edit2) is wrong, should be:
if (!($allow_edit and $allow_edit2))
What you want is that both conditions are true, must be the poster and must have permissions to edit. If this combination is not true (as opposed to the 2 seperate conditions being not true) then you want an error.
sabret00the
03-15-2005, 02:50 PM
that didn't work so let's simplify the original code
if (($postinfo['userid'] != $bbuserinfo[userid] AND !$grps_permissions['groupspostedit']) OR (!grps_permissions['groupsmoderater'])
simplified that would be
if ($clause_one OR $clause_two)
so basically i want if either of clause_one or clause_two = true then let the person edit the post, else show a no permission screen.
Marco van Herwaarden
03-15-2005, 02:51 PM
Now let's add the moderator part. Let's simplify by making the above into 1 condition, so:
if ( !(canedit) ) {error}
Now let's add the moderator with an OR statement:
if ( !(canedit) OR !(moderator) ) {error}
Possible combinations:
1. Can NOT edit, is NOT moderator, this will give:
if ( TRUE OR TRUE) {error}
Error is shown, this is correct.
2. Can edit, is NOT moderator, this will give:
if ( FALSE OR TRUE) {error}
Since you are using an OR statement only 1 of the conditions need to be TRUE. This is the case, so an error. This is not what you want.
3. Can NOT edit, is moderator, this will give:
if ( TRUE OR FALSE) {error}
Since you are using an OR statement only 1 of the conditions need to be TRUE. This is the case, so an error. This is not what you want.
Now let's see the same with an AND:
if ( !(canedit) AND !(moderator) ) {error}
1. Can NOT edit, is NOT moderator, this will give:
if ( TRUE AND TRUE) {error}
Error is shown, this is correct.
2. Can edit, is NOT moderator, this will give:
if ( FALSE AND TRUE) {error}
Since you are using an AND statement, both of the conditions need to be TRUE. This is NOT the case, so NO error. This is what you want.
3. Can NOT edit, is moderator, this will give:
if ( TRUE AND FALSE) {error}
Since you are using an AND statement, both of the conditions need to be TRUE. This is NOT the case, so NO error. This is what you want.
so basically i want if either of clause_one or clause_two = true then let the person edit the post, else show a no permission screen.
This is not what you are doing: You are showing an error if either of them is true
sabret00the
03-15-2005, 02:59 PM
ok so how do i get it to show
if ((canedit) AND !(moderator)) {no_error}
then have
if (!(canedit) AND (moderator)) {no_error}
but if
if (!(canedit) OR !(moderator)) {error}
Marco van Herwaarden
03-15-2005, 03:18 PM
Lol now you are confusing me.
What you will want is:
if (!(canedit) AND !(moderator)) {error}
Or you can turn the whole game upside down:
if ((canedit) OR (moderator)) {DO EDIT}
Jolten
03-15-2005, 03:35 PM
Talk about over-thinking things :)
if ((($postinfo['userid'] != $bbuserinfo[userid]) AND !$grps_permissions['groupspostedit']) AND !$grps_permissions['groupsmoderater'])
{
print_no_permission();
}
(((user does not equal poster) AND not in allowed to edit group) AND is not moderator)
Marco van Herwaarden
03-15-2005, 03:59 PM
Talk about over-thinking things :)
if ((($postinfo['userid'] != $bbuserinfo[userid]) AND !$grps_permissions['groupspostedit']) AND !$grps_permissions['groupsmoderater'])
{
print_no_permission();
}
(((user does not equal poster) AND not in allowed to edit group) AND is not moderator)
I gree, but he just didn't want to get it ;)
sabret00the
03-15-2005, 06:08 PM
win for the overthinking :p your code never worked :(
but
if (!$grps_permissions['groupsmoderater'])
{
//they'll only get in here if they're not a mod
if ($postinfo['userid'] != $bbuserinfo[userid] AND !$grps_permissions['groupspostedit'])
{
print_no_permission();
}
}
is the working code :)
Marco van Herwaarden
03-15-2005, 06:58 PM
So you give up? I am sure one of my codes worked ;)
sabret00the
03-15-2005, 07:05 PM
i'm pretty sure your codes were allowing me to edit no matter what or showing me no_permission no matter what but i'll have to play wit it in the morning marco as the original idea of using the almighty conditional is still favourable to me, especially as i have to replicate it for showing the "EDIT" link.
Marco van Herwaarden
03-15-2005, 09:04 PM
( !($postinfo['userid'] == $bbuserinfo[userid] AND $grps_permissions['groupspostedit']) AND (!$grps_permissions['groupsmoderater']))
This is the one you need
sabret00the
03-15-2005, 09:14 PM
works like a charm marco :D thank you :)
still aint sunk in how it works properly but i'll read it in the morning and no doubt it'll make perfect sense :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.