Web Poll Content Type

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

Web Poll Content Type

Post by JensZ »

Thought I'd share my latest enhancement, a web poll for phpwcms.

See demo and download from: http://www.ikfrej.se/index.php?downloads

Cheers!
rushclub
Posts: 915
Joined: Tue 17. Feb 2004, 18:52

Post by rushclub »

thanks for that cp. one small question.
where can we see the results of the poll? in the backend?

cheers
rush
3 (!) Jahre warten reichen mir. Ich bin erst mal weg.
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

Hi JensZ,

great addition! Little mod, big effects, thanks.
Your one of my favourite MOD-man :D

Cheers
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

Post by JensZ »

The results are shown once the user hits send. However, minutes after I released the code I actually added code so that the results can be seen in the backend. Now I'm too lazy to wrap up another package, it'll come in the next version along with code that allows the poll and results to be rendered using templates. Replace inc_tmpl\cnt89.list.inc.php with this to get it to appear in the backend:

Code: Select all

<?php
/*************************************************************************************
   Copyright notice
   
   (c) 2002-2005 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
 
   This script is part of PHPWCMS. The PHPWCMS web content management system is
   free software; you can redistribute it and/or modify it under the terms of
   the GNU General Public License as published by the Free Software Foundation;
   either version 2 of the License, or (at your option) any later version.
  
   The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
   A copy is found in the textfile GPL.txt and important notices to the license 
   from the author is found in LICENSE.txt distributed with these scripts.
  
   This script is distributed in the hope that it will be useful, but WITHOUT ANY 
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
   PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 
   This copyright notice MUST APPEAR in all copies of the script!
*************************************************************************************/

// Content 89: Poll  		jens

$cinfo["result"]  = $row["acontent_title"] ? cut_string($row["acontent_title"],"…", 55) : "";
$cinfo["result"] .= ($cinfo["result"] && $row["acontent_subtitle"]) ? " / " : "";
$cinfo["result"] .= $row["acontent_subtitle"] ? cut_string($row["acontent_subtitle"],"…", 55) : "";

$poll_text = unserialize($row["acontent_text"]);
$poll_form = unserialize($row["acontent_form"]);
$poll_image = unserialize($row["acontent_image"]);

$total_votes = 0;
foreach($poll_form["count"] as $key => $value)
{
	$total_votes += $value;
}
$html .= "<table>";
$html .= "<tr>\n<td><table>";
if($total_votes > 0)
{
	
	$cnt = max(count($poll_form["choice"]), count($poll_image["images"]));

	for($key = 0; $key < $cnt; $key++)
	{
		$html .= '<tr><td class="v10">';
		if(isset($poll_form["choice"][$key]) && !empty($poll_form["choice"][$key]))
		{
			$html .= $poll_form["choice"][$key];
		}
		//if(is_array($poll_image["images"][$key]) && count($poll_image["images"][$key]))
		//{
		//	$html .= "<br/>";
		//	$html .= showPollImage($poll_image["images"][$key]);
		//}
		$html .= '</td><td class="v10"><span style="float: left; height: 13px; background-color: #0FA5FB; border-top: 1px solid #78CBFB; border-left: 1px solid #78CBFB; border-right: 1px solid #0AA3BE; border-bottom: 1px solid #0AA3BE; margin: .2em 0 .5em 0; width:'.round(($poll_form["count"][$key]/$total_votes*100),0).'px;"><!-- --></span>&nbsp;<span style="">'.round(($poll_form["count"][$key]/$total_votes*100),0).'%</span></td></tr>'."\n";
	}
}
$html .= "<tr><td class=\"v10\"><span style=\"font-weight:bold;\">total votes:</span> ".$total_votes."</td></tr>";
$html .= "</table></td>\n</tr>";
$html .= "</table>";

if($cinfo["result"]) 
{ 
	echo "<tr><td>&nbsp;</td><td class=\"v10\">";
	echo "<a href=\"phpwcms.php?do=articles&p=2&s=1&aktion=2&id=".$article["article_id"]."&acid=".$row["acontent_id"]."\">";
	echo $cinfo["result"]."</a>".$html."</td><td>&nbsp;</td></tr>";
}

?>
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

Hi,

made a test here:
http://www.piezoworks.be/mulieris/index.php?fr_mulieris

Works like a charm!!! :lol: :lol: :lol: :lol:

Some questions though... You might think "they're never happy, I break my b* to do a nice CP and they complain!" No, no, I was just wondering about these things:

Q: what is the time limit to re-enter the vote? (cookie based/session?) I suppose I can change the value?
Q: every time I edit the poll, it resets the results to 0... no tbig deal but can be annoying for future aplpications.
Q: I don't get th eimage thing, it only shows under the first choice...


Anyway, very nice job!
Thanks again!

Cheers
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

Post by JensZ »

Nope, it is based on IP. One visitor, one vote. However, it can be reset by updating the content part in the backend, but that will reset all the votes. Maybe I'll put some reset logic in the next version...
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

Kosse wrote: Q: I don't get the image thing, it only shows under the first choice...
Stupid me... if I add 4 choices, then I have to add 4 images, ok got it...
:oops:

Note: funny, 12 pple voted so far :P

Cheers
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

hey,

what about placing the total numbers of votes....?

OFftopic - how did you made this:
Läst 411 gånger (idag: 7)
Updated 2 sec after I posted.. :oops:
Display number of users currently online, number of visitors, number of times a page/article has been viewed, and more. Requires VTS
http://www.studmed.dk Portal for doctors and medical students in Denmark
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

Post by JensZ »

Frold,

To show the total number of votes replace

Code: Select all

		$html .= "</table></td>\n</tr>";
		$html .= "</table>";
with

Code: Select all

		$html .= "</table></td>\n</tr>";
		$html .= "<tr><td><span style=\"font-weight:bold;\">total votes:</span> ".$total_votes."</td></tr>";
		$html .= "</table>";
To get the number of times an article has been read, install the vts_users_online.zip package and put something like this in your article template:

Code: Select all

<div>
[TITLE]<h1 style="margin:0 0 5px 0;">{TITLE}</h1>[/TITLE]
[SUB]<h3 style="margin:0 0 5px 0;">{SUB}</h3>[/SUB]
<p style="margin:5px 0 5px 0;">
<span>{DATE:Y-m-d:EN}</span> 
<span>
&nbsp;&nbsp;Read {VTS_DOCUMENT:total} times (today: {VTS_DOCUMENT:today}).</span><br /> 
{SUMMARY}
</p>
<br/>
</div>
cheers

/Jens
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

JensZ wrote:To show the total number of votes replace
Done, works like a charm (as always) thx JensZ

Cheers
Dave_LOgic
Posts: 51
Joined: Wed 10. Nov 2004, 21:48
Location: London

Re: Web Poll Content Type

Post by Dave_LOgic »

JensZ wrote:Thought I'd share my latest enhancement, a web poll for phpwcms.

See demo and download from: http://www.ikfrej.se/index.php?downloads

Cheers!
Another awesome content part..!!.I use both of your {SHOW_CONTENT} and {NEWS_FLASH} hacks....I haven't installed this one yet as it looks that this one involves modifying the same core files...Is this the case..??
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

Post by JensZ »

Yes, changes are made to the same files, but the changes are minor. A function in front.func.inc.php and a line or two in the other files. Just look for "jens" to find the lines that changed and merge them in.
Dave_LOgic
Posts: 51
Joined: Wed 10. Nov 2004, 21:48
Location: London

Post by Dave_LOgic »

JensZ wrote:Yes, changes are made to the same files, but the changes are minor. A function in front.func.inc.php and a line or two in the other files. Just look for "jens" to find the lines that changed and merge them in.

Many thanks....I have done as you said and all is working OK now...
Paal
Posts: 204
Joined: Wed 6. Oct 2004, 19:54
Location: Budapest, Hungary
Contact:

Post by Paal »

JensZ wrote:Yes, changes are made to the same files, but the changes are minor. A function in front.func.inc.php and a line or two in the other files. Just look for "jens" to find the lines that changed and merge them in.
Fine this MOD, but I have one question. How to hide the poll results to end off poll period (secret poll)?

eg.: after user vote, say "thx, the vote. Results later..."

Thx, Paul
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

Hi Jens
could you post this mod with all the install features on --...-- ?

TriP
Post Reply