poll

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

poll

Post by Gregor »

I Often get the question how I installed the poll on www.uisge-beatha.eu

I'm using Advanced Poll http://www.proxy2.de/poll/index.php
Installed it in folder called Poll in the root of the website

Made some changed to demo_1.php

Code: Select all

/* fourth poll */
//echo $php_poll->poll_process(4);  
echo $php_poll->poll_process($pollnr); 


In the template I added:

Code: Select all

<__script__ type="text/javascript" src="/uploads/Javascripts/resize_iframe.js"></__script>
Don't know where I picked up the js-file. Suggest to google it.

Created a UDT named 'poll', containing:

Code: Select all

echo '<__iframe width="190" id="the_iframe" onLoad="calcHeight()" frameborder="0" src="poll/demo_1.php?pollnr='.$params[pnr].'"></__iframe>';
Created a UDT named 'include_poll', containing:

Code: Select all

include_once "/home/gregor/domains/uisge-beatha.eu/public_html/poll/poll_cookie.php";
In the page I call the UDT:
{poll pnr=8}
This refers to poll number 8.

Hope this helps.

Gregor
xmas3
Forum Members
Forum Members
Posts: 41
Joined: Sat Jul 28, 2007 9:22 am
Location: Bratislava / Slovakia

Re: poll

Post by xmas3 »

Hi Gregor,
thanks for your T&T !
Please correct me if Im wrong, but your Poll is now only icluded into your template, it isnt managed from the CMS MS backend, isnt it?
Actually, I played a little bit around with the official CMS MS Polls and I get a very similar result (find the file attached). I also added the possibility to create categories into it including the new parameter to show only polls from concrete category.
All the best,
Miro
Attachments
polls_example.png
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: poll

Post by Gregor »

Hi Miro,

You're welcome.

When I had the 'need' for a poll, the cmsms poll was different than I would like to have on my site, so I looked for another solution outside cmsms. I included my poll in the site page instead of the template. Maybe I should have a look to the cms solution again.

Greetz, Gregor
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: poll

Post by Gregor »

To give it a try, I installed polls made simple, added a poll, added the reference to the ajax-java script to the template. I can see the poll http://www.uisge-beatha.eu/index.php?page=test, after voting I return to the home page. The link shown is:
http://www.uisge-beatha.eu/?pollvotingchoice_1=1&vote=Vote#

Any ideas?

Gregor
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: poll

Post by Gregor »

Anyone who got the poll ms working? Plse see my previous post.

Gregor
Peciura

Re: poll

Post by Peciura »

I think you have issues with ".htaccess". I am not using pretty url.
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: poll

Post by Gregor »

Thnks for reply!
Hmm, would be a pitty if that is the case. I'll give it a try on one of my other site.

Let's assume pretty rl's is the reason why, any idea how to solve it?
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: poll

Post by Gregor »

I gave it a try on a non-pretty url website and there it worked out fine.

Any idee how to get bars to show the number and percentage after the given answers?
Peciura

Re: poll

Post by Peciura »

Here is simple idea.
Copy this Poll result template.

{$max_width} max bar length
{$extra_width} percent value label width

Code: Select all

<div id="pollresults" style='margin: 0 10px;'>
	<table cellspacing="0" style="border-style:none;">
		<thead>
			<tr>
				<th colspan='2' style='background-color:#ffffff;'>
					{$pollname}
				</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>
					<br/>
				</td>
			</tr>
			{assign var='max_value' value='0'}
			{foreach from=$options item=entry}
				{if $max_value	< $entry->votes}
					{assign var='max_value' value=$entry->votes}
				{/if}
			{/foreach}
			{assign var='max_width' value='100'}
			{assign var='multiplier' value="`$max_width/$max_value`"}
			{assign var='extra_width' value='40'}
					
			{foreach from=$options item=entry}
				<tr>
					<td>
						{$entry->name}
					</td>
						<td>
							<div style='position:relative;width:{$max_width+$extra_width}px;'>
							<div style=' background-color:red;width:{"`$multiplier*$entry->votes`"|round}px;float:left;'>
								 
							</div>
							<div>
								{$entry->percent}
							</div>
						</div>
					</td>
					<td>
						({$entry->votes}{if $entry->votes==1}{*$votetext*}{else}{*$votestext*}{/if})
					</td>
				</tr>
			{/foreach}
			<tr>
				<td colspan="2">
					<br/>	{*$totalvotestext*}Viso balsų: {$totalvotes}
				</td>
			</tr>
			<tr>
				<td colspan="2">
					{$voteform}
				</td>
			</tr>
		</tbody>
	</table>
</div>
Attachments
poll_results.png
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: poll

Post by Gregor »

Great, thanks! It does work with non-pretty url's.

On another site with pretty url's, poll ms does not work :-(
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: poll

Post by Gregor »

I noticed that the bars all have the same color. Could it be possible to create an array with different colors and that for each bar a different color is picked from the array? Suggestion on how to do it?
Peciura

Re: poll

Post by Peciura »

Bar colors are "#39e,blue,#999,red". Write comma separated values you need.
Actually bars with background image instead of plain color would look better.  

Code: Select all

{assign var='bar_colors' value=','|explode:"#39e,blue,#999,red"}
{foreach from=$bar_colors item=color key=color_key}
{/foreach}
{assign var='colors_count' value="`$color_key+1`"}
<div id="pollresults" style='margin: 0 10px;'>


	<table cellspacing="0" style="border-style:none;">
		<thead>
			<tr>
				<th colspan='2' style='background-color:#ffffff;'>
					{$pollname}
				</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>
					<br/>
				</td>
			</tr>
			{assign var='max_value' value='0'}
			{foreach from=$options item=entry}
				{if $max_value	< $entry->votes}
					{assign var='max_value' value=$entry->votes}
				{/if}
			{/foreach}
			{assign var='max_width' value='100'}
			{assign var='multiplier' value="`$max_width/$max_value`"}
			{assign var='extra_width' value='30'}
					
			{foreach from=$options item=entry key='option_key'}
				<tr>
					<td>
						{$entry->name}
					</td>
						<td>
							<div style='position:relative;width:{$max_width+$extra_width}px;'>
							<div style=' background-color:
{assign var=color_key value="`$option_key%$colors_count`"}
{$bar_colors.$color_key};width:{"`$multiplier*$entry->votes`"|round}px;float:left;'>
								 
							</div>
							<div>
								{$entry->percent}
							</div>
						</div>
					</td>
					<td>
						({$entry->votes}{if $entry->votes==1}{else}{/if})
					</td>
				</tr>
			{/foreach}
			<tr>
				<td colspan="2">
					<br/>Viso balsų: {$totalvotes}
				</td>
			</tr>
			<tr>
				<td colspan="2">
					{$voteform}
				</td>
			</tr>
		</tbody>
	</table>

</div>

Last edited by Peciura on Fri Feb 26, 2010 9:42 pm, edited 1 time in total.
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: poll

Post by Gregor »

Thanks for your fast reply and work. I'll give it a try.
User avatar
Gregor
Power Poster
Power Poster
Posts: 1874
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: poll

Post by Gregor »

Looks nice. Don't quite understand what you mean with: "Actually bars with background image instead of plain color would look better.  "
Do you have a suggestion how to print the label before the bar? I tried:

Code: Select all

<div style=' background-color:
{$option->label}{assign var=color_key value="`$option_key%$colors_count`"}
{$bar_colors.$color_key};width:{"`$multiplier*$entry->votes`"|round}px;float:left;'>
								 
							</div>
But that didn't work out....
Peciura

Re: poll

Post by Peciura »

In this one i have mixed background patterns (4 in 1 picture ) and background colors (3).
If you want to see pattern only - comment {*$bar_colors.$color_key*}, to see colors only - {* url("{$bar_pattern}")*}
Also values you most likely want to change are marked.
{assign var='bar_pattern' value='/uploads/images/bars_pattern.png'}
{assign var='bar_pattern_count' value=4}
{assign var='bar_colors' value=','|explode:"green,#999,red"}
{foreach from=$bar_colors item=color key=color_key}
{/foreach}
{assign var='colors_count' value="`$color_key+1`"}
{assign var='extra_width' value='30'}
{assign var='max_width' value='100'}

 
     
       
           
              {$pollname}
           
       
     
     
       
           
             
           
       
        {assign var='max_value' value='0'}
        {foreach from=$options item=entry}
           {if $max_value   votes}
              {assign var='max_value' value=$entry->votes}
           {/if}
        {/foreach}
        {assign var='multiplier' value="`$max_width/$max_value`"}              
        {foreach from=$options item=entry key='option_key'}
        {assign var=color_key value="`$option_key%$colors_count`"}
        {assign var='bg_offset' value="`$option_key%$bar_pattern_count`"}
           
             
                 {$entry->name}
             
                 
                   
                    votes`"|round}px; float:left; height:20px;'>
                        
                   
                   
                       {$entry->percent}
                   
                 
             
             
                 ({$entry->votes}{if $entry->votes==1}{else}{/if})
             
           
        {/foreach}
       
           
              Viso balsų: {$totalvotes}
           
       
       
           
              {$voteform}
           
       
     
 
P.S.
{$max_width} max bar length
{$extra_width} percent value label width
Units are px.
I am sure your patterns will be better than mine :).
Attachments
bars_pattern.png
bars_pattern.png (1.28 KiB) Viewed 9825 times
poll_results_pattern_color.png
poll_results_pattern.png
poll_results_color.png
Last edited by Peciura on Fri Feb 26, 2010 9:44 pm, edited 1 time in total.
Post Reply

Return to “Tips and Tricks”