Error when your username is not equal to your admin name

3.3 Forum ONLY: If you've run into a problem, such as an error message, blank page, or similar problem, this is where to look. Post any installation or other problems or questions here, and I and other users will try to help.
  
31 Dec '69 Tis Maj 18, 2010 22:15    
greenday2k
Sponsor  Sponsor
  •  

Inlägg Error when your username is not equal to your admin name

I had an error tryin the Discuss This! feature.
When i'm clicking That Link is shows me an database error on

News_Pro/functions.php line 2297
$Revision: 3.25 $
$Date: 2010-03-29 15:01:47 $
Author: layingback

PHP:

$sql
= "INSERT INTO ".$forumspro_prefix."topics (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote, icon_id) VALUES ('$subject', $userid, $current_time, $forum_id, ".TOPIC_UNLOCKED.", 0, 0, 0)";



The SQL query is right but when you have diffrent admin name and username the problem comes:

sinces the $user_id definition on line 2283:

PHP:

list($userid) = $db->sql_fetchrow($db->sql_query("SELECT user_id FROM ".$user_prefix."_users WHERE username='$username'"));



uses the $username, but in the query teh username used is the admin name, wich returns and empty value for the query on line 2283.

This issue is solved using the is_user() function wich returns a 'valid' user_id in this case.

This should be applied on line 2363 on the same file.

Notes:
1. Tested with a Custom Forums_Pro install.
2. DF version 921
3. The Discuss this function worked fine only logged as user.



greenday2k please enter your server specs in your user profile! Gråtande eller väldigt ledsen  
 
 
 
  
31 Dec '69 Ons Maj 19, 2010 16:29    
layingback
Site Admin  
  •  

Inlägg Re: Error when your username is not equal to your admin name

I'm sorry, I don't follow what your fix actually consists of, and so I can't be sure that I actually understand the problem.

The $username is being taken from the original story, so who is doing the discussThis, and whether or not they have an admin name = user name shouldn't matter ...



layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4

 
 
 
 
  
31 Dec '69 Ons Maj 19, 2010 21:02    
greenday2k
Sponsor  Sponsor
  •  

Inlägg Re: Error when your username is not equal to your admin name

OK, i'll try to explain this better.

To reproduce this you have to have a different administrator and username. Logged as Admin & regular user.

For this case: my admin nickname is: anticitizen1
my regular user name is: aker

Go to admin and Publish a new Article with Comments enabled.

Now go to the homepage click on start the disscusion, or discuss this!

You get this database error:

PHP:

On
/News_Pro/discuss=880.html
While executing query "INSERT INTO nuke_foro_topics (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote, icon_id) VALUES ('PostName', , 1274313251, 95, 0, 0, 0, 0)"



See the empty value for the second field in the query, is empty.
That's supossed to be a user_id.

The debug info showed the query to get that user_id is:

PHP:
list($userid) = $db->sql_fetchrow($db->sql_query("SELECT user_id FROM ".$user_prefix."_users WHERE username='$username'"));



Code:
 LINE 2286: SELECT user_id FROM nuke_users WHERE username='anticitizen1'



anticitizen1 is my Administrator Name, not my regular user name.
And if there are no records for a user_id wich has username of "anticitizen1", the query will return an empty value and cause the MySql error.

Now i understand that the solution of $user_id = is_user(); is not valid.
and the cuase of the bug comes from: /pro_news/admin/admin_functions.php line 1141

Code:
$postby = (can_admin($module_name) ? is_admin($module_name) : $userinfo['username']);



this returns my admin username not my regular username.



greenday2k please enter your server specs in your user profile! Gråtande eller väldigt ledsen  
 
 
 
  
31 Dec '69 Ons Maj 19, 2010 21:40    
layingback
Site Admin  
  •  

Inlägg Re: Error when your username is not equal to your admin name

Thanks, got it - both the problem and the solution!

Wow, I just checked, this bug has been there since the original 0.9 beta release that I started from! I guess not too many people use different admin/usernames Skrattande

I think that line in admin_functions.php should just be:

PHP:
				$postby = $userinfo['username']);



Please let me know if this works in your set up. Thanks again.



layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4

 
 
 
 
  
31 Dec '69 Ons Maj 19, 2010 23:22    
greenday2k
Sponsor  Sponsor
  •  

Inlägg Re: Error when your username is not equal to your admin name

PHP:
$postby = $userinfo['username'];



Works fine.



greenday2k please enter your server specs in your user profile! Gråtande eller väldigt ledsen  
 
 
 
  
31 Dec '69 Tor Maj 20, 2010 07:22    
layingback
Site Admin  
  •  

Inlägg Re: Error when your username is not equal to your admin name

Good.

Minor, but can I just ask if you would test the following please?

Create the article logged in as Admin, but NOT logged in as any user. It will post as Anonymous user, which is to be expected. But could you just check that it doesn't cause a similar SQL error inside discussThis when commented on by a properly logged in user or admin? TIA!



layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4

 
 
 
 
  
31 Dec '69 Tor Maj 20, 2010 16:06    
greenday2k
Sponsor  Sponsor
  •  

Inlägg Re: Error when your username is not equal to your admin name

Crated a new article loggged only as Admin.
Then clicked the DiscussThis the post is "correctly" created but using anonymous as user ( visitor, And looks terrible in the forum -thats another issue not directly related with PN ).

Not logged (Nor Admin, nor regular user)
Same history, but this time Not logged at all, click on the discussthis.
Message of "user only area" -wich seems to be fine!

logged as user.
Went and then clicked the DiscussThis as regular user. A Neew post was created correctly but using anomously.

Options:

create a "deafult" author (if none is selected) wich points to a valid account on the users database.

Select the database the user_id checking that is not anonymous using user level >1 AND if that returns an emtpy (no existent) use the info for the default user. Redundant check if option 1 is implemented, but useful if the "original" poster has changed his username (it happens on my site, the new fashion! ;D )

Or just check the user level and if returns an empty string the userinfo['username'] ?



greenday2k please enter your server specs in your user profile! Gråtande eller väldigt ledsen  
 
 
 
  
31 Dec '69 Fre Maj 21, 2010 07:32    
layingback
Site Admin  
  •  

Inlägg Re: Error when your username is not equal to your admin name

No I don't think I want to add that type of contingency code. Pro_News is big enough and complex enough as it is, without adding special case code.

My real concern is/was that it didn't trigger an error. Thanks for testing that.

Anyone who posts without being logged in as user as well as admin is asking for trouble, anywhere in DF. And it is a DF error of omission, not a Pro_News one.

I have a warning in the install notes (which is more than DF does). But I guess I could look at adding some sort of alert to Admin > Pro_News > Submit article...

I avoid this problem with my admins by never giving them the admin login URL! (I'll PM you the details.)



layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4

 
 
 
 
  
31 Dec '69 Fre Maj 21, 2010 15:28    
greenday2k
Sponsor  Sponsor
  •  

Inlägg Re: Error when your username is not equal to your admin name

I understand, But is it possible to add a warning if the admin is not logged as user? to avoid problems on the every day runtime.



greenday2k please enter your server specs in your user profile! Gråtande eller väldigt ledsen  
 
 
 
  
31 Dec '69 Fre Maj 21, 2010 16:30    
layingback
Site Admin  
  •  

Inlägg Re: Error when your username is not equal to your admin name

- greenday2k

But is it possible to add a warning if the admin is not logged as user?


That's what I meant by:

- layingback

But I guess I could look at adding some sort of alert to Admin > Pro_News > Submit article...


Just above the basic submit instructions.

But I'm currently trying to display the comments, or at least the first X comments, something like Amazon reviews (but without all the options!) Sorry I'll probably only do for Forums, but if I manage to do in Blocks like I'm want, then it will easy for you to recode to ForumsPro...



layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4

 
 
 
 
Link  QR 
Share this Utskriftsvänlig sida  facebook   google+   linkedin   twitthis  
Show more ...


Forumrättigheter - Du kan inte skapa nya inlägg i det här forumet
Du kan inte svara på inlägg i det här forumet
Du kan inte ändra dina inlägg i det här forumet
Du kan inte ta bort dina inlägg i det här forumet
Du kan inte rösta i det här forumet
Du kan inte bifoga filer i det här fourmet
Du kan inte ladda ner filer i detta forum