[MOD-DB]tabulated survey at topic head

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: more than 7

Post by asinshesq »

mozg2 wrote: ...I understood that there is a limit for a number of cells in a table, so that you'd have to add another table? nevermind.. thanks anyway....

This is probably what you meant, but to be precise: there is not any special limit on the number of cells in a table...the only limit is a practical one on how wide someone's screen is and how crowded questions will look going across the screen.
mozg2 wrote: ...by the way, the tool did not work before I added a group to my board.

What do you mean when you say it didn't work until you added a group? Do you mean that you never saw the link in the new post screen allowing you to design a survey until you added a group? The code that figures out which users to show that link to (i.e. which users are authorized to post a new sruvey) ties things to authorization for polls...anyone who is allowed to post a poll is supposed to be able to post a survey. Before you added a group, were all uesrs authorized to post polls? Please let me know a little bit more about what you mean so that I can track down the problem if there is one.

And, once you added a new group, are you saying that everything seems to work fine?
mozg2
Registered User
Posts: 4
Joined: Mon Mar 14, 2005 5:50 pm

Re: more than 7

Post by mozg2 »

asinshesq wrote: What do you mean when you say it didn't work until you added a group?

oh, I've already minded that out. everything works fine.
asinshesq wrote: The only limit is a practical one on how wide someone's screen is and how crowded questions will look going across the screen


aha. you know, I am using your mod to mark players after a football match, so there are player's names instead of questions and no fear of getting crowdy. as a team counts over 7 men, I have to make another 'survey', having enough room to put everythig in one.
dccb
Registered User
Posts: 51
Joined: Mon Jul 15, 2002 9:06 am

Post by dccb »

Great mod. Works just as advertised. However, the All Users option didn't work for me.

When I checked the All users checkbox for the allowed usergroup, no one could take the survey [take survey button doesn't show up]

Other specified usergroups work fine.
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

dccb wrote: Great mod. Works just as advertised. However, the All Users option didn't work for me.

When I checked the All users checkbox for the allowed usergroup, no one could take the survey [take survey button doesn't show up]

Other specified usergroups work fine.


Oops...I confess that although I coded for that I never tried it (I never do anything for 'allusers' on my board so I never noticed it didn't work). I'm sure that's just a little typo thing...I'll get that straightened out if I have time in the next few days. Thanks for the report. (Maybe that's what mozg meant when he said it didn't work till he added a group...)
mozg2
Registered User
Posts: 4
Joined: Mon Mar 14, 2005 5:50 pm

Post by mozg2 »

exactly.
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

fix for 'all users' bug

Post by asinshesq »

I haven't tried this yet, but I think something like this should work so that if you have clicked 'All users' then everyone will see the Fill Out Survey button. I'll test it tonight.

[deleted since I posted code below that supersedes this post]
Last edited by asinshesq on Tue Mar 15, 2005 8:09 pm, edited 1 time in total.
dccb
Registered User
Posts: 51
Joined: Mon Jul 15, 2002 9:06 am

Post by dccb »

When All users is checked, with no other user groups selected, then the group_ids in phpbb_survey table has -1 in it.

Is -1 suppose to be for every users?

Because I didn't see a special check for group_ids being -1 in viewtopic.php after this SELECT statement.

Code: Select all

$sql = "SELECT survey_id, survey_caption, group_ids, show_order, show_nonresponders, widths, questions, question_sums, question_selected_text FROM " . SURVEY_TABLE . "
			WHERE topic_id = $topic_id";
Select statement to find out if user is supposed to be able to take the survey.

Code: Select all

$sql = "SELECT user_id
			FROM " . USER_GROUP_TABLE . "
			WHERE user_id = " . $userdata['user_id'] . "
			AND group_id IN ($group_ids)";
This means it would select users from phpbb_groups where the group_id is -1. But when I look at my database, I don't have a default -1 group_id
dccb
Registered User
Posts: 51
Joined: Mon Jul 15, 2002 9:06 am

Re: fix for 'all users' bug

Post by dccb »

asinshesq wrote: I haven't tried this yet, but I think something like this should work so that if you have clicked 'All users' then everyone will see the Fill Out Survey button. I'll test it tonight.

Code: Select all

OPEN
viewtopic.php

FIND
	if($db->sql_fetchrow($result))
	{
		$user_should_answer = 1;
	}
	$db->sql_freeresult($result);

AFTER, ADD
	$group_id_array = explode(",", $group_ids);
	if( in_array(-1, $group_id_array)
	{
		$user_should_answer = 1;
	}


There's a typo in that code

Should be

Code: Select all

$group_id_array = explode(",", $group_ids);
	if( in_array(-1, $group_id_array))
	{
		$user_should_answer = 1;
	}
you missing one ) in the if statement :D


This allows everyone to vote, but it would not record their answers, and won't tabulate the result.

Very quick response though, I like that! :D
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

I said I hadn't tested it ;) and you asked about the missing button, not recording the vot ;) .

Seriously, I'll try to test tonight and post back by tomorrow with the real solution if possible
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

[deleted double post]
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

dccb wrote: When All users is checked, with no other user groups selected, then the group_ids in phpbb_survey table has -1 in it.

Is -1 suppose to be for every users?...


Sorry, I was doing that last post via blackberry so I didn't see your second post till just now.

Answer: yes, I store '-1' in the DB for the all users selection. When it gets to viewtopic, it checks the survey table entry in the db to see which groups are enabled...if the user in question is in a group that appears in the group_ids field in the survey table, the 'Fill out survey' button gets shown. All the code that I added in the post above does is to add another check in viewtopic that says even if the user isn't a member of a group that has been specially picked to take the survey, show the 'fill out survey' button if 'all users' was selected (i.e. if there is a '-1' in the group_ids field of the relevant survey table entry).

I'm surprised that this doesn't all by itself fix things, since once a user clicks the fill out survey button and gets taken to the form I don't remember doing anything more with groups (and the results tabulation is not dependent on gorups at all)...but I'll try to track this down tonight.
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

OK, once again if you try a fix with untested code, you can try this instead of the earlier stuff I posted:

Code: Select all

OPEN
viewtopic.php  (note that the first two FINDS are of the same code because the mod adds them twice)

FIND
WHERE ug.group_id IN ($group_ids)

REPLACE WITH
WHERE ( ug.group_id IN ($group_ids) || -1 IN ($group_ids) )

FIND
WHERE ug.group_id IN ($group_ids)

REPLACE WITH
WHERE ( ug.group_id IN ($group_ids) || -1 IN ($group_ids) )

FIND
AND group_id IN ($group_ids)";

REPLACE WITH
AND ( group_id IN ($group_ids) || -1 IN ($group_ids) )";
You might have to put the -1 inside single or double quotes or in parens...I'll check it out tonight but if you want to play early here it is.
dccb
Registered User
Posts: 51
Joined: Mon Jul 15, 2002 9:06 am

Post by dccb »

Real nice, that did the trick!!! :D

Good job. However, now the Fill Out Survey button shows up for guest as well :D

So I did

Code: Select all

# 
#-----[ FIND ]------------------------------------------ 
#
if($db->sql_fetchrow($result))
	{		$user_should_answer = 1;
	}

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
if($db->sql_fetchrow($result) && $userdata['session_logged_in'])
	{		$user_should_answer = 1;
	}

Now the survey button only shows up for logged in user

Hope you can post a better way.

:D

Also, if you turn off the display nonresponder option. The caption People who haven't yet answered still shows up

So I added an ELSE statement

Code: Select all

# 
#-----[ FIND ]------------------------------------------ 
#
	if($nonresponders && $survey_info['show_nonresponders'])
	{
		$template->assign_vars(array('L_NONRESPONDERS' => $lang['Nonresponders']));
	}

# 
#-----[ AFTER ADD]------------------------------------------ 
#
	else
	{
		$template->assign_vars(array('L_NONRESPONDERS' => ''));
	}
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

dccb wrote: Real nice, that did the trick!!! :D ...

I assure you that was only coincidental ;) Seriouusly, did you need to do anything to that code (add quotes or parens or anything) or did it work fine exactly the way I posted it?
dccb wrote: ...Good job. However, now the Fill Out Survey button shows up for guest as well :D

So I did

Code: Select all

# 
#-----[ FIND ]------------------------------------------ 
#
if($db->sql_fetchrow($result))
	{		$user_should_answer = 1;
	}

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
if($db->sql_fetchrow($result) && $userdata['session_logged_in'])
	{		$user_should_answer = 1;
	}

Now the survey button only shows up for logged in user

Hope you can post a better way.

:D


Can't improve perfection...that's how I would have approached it as well (though I typically like to skip a line after the open bracket and another line before the close bracket so that it's easier to read the code). Thanks for helping to get that straightened out!

Are you finding this mod useful...waht kinds of things are you using it for?
dccb
Registered User
Posts: 51
Joined: Mon Jul 15, 2002 9:06 am

Post by dccb »

asinshesq wrote: I assure you that was only coincidental ;) Seriouusly, did you need to do anything to that code (add quotes or parens or anything) or did it work fine exactly the way I posted it?
It works perfectly fine exactly the way you posted it :D
asinshesq wrote: Are you finding this mod useful...waht kinds of things are you using it for?
Yeah, this mod is pretty useful actually. I want to use this to tabulate how many votes a member would get from current moderators and V.I.P. members when he or she applies to be a V.I.P. member. [approve | disapprove]

Also, I will use it to confirm sport betting on my forum.
Locked

Return to “[2.0.x] MODs in Development”