| 1 | <?php |
|---|
| 2 | // $Id: xoopspollrenderer.php,v 1.2 2005/03/18 12:52:49 onokazu Exp $ |
|---|
| 3 | // ------------------------------------------------------------------------ // |
|---|
| 4 | // XOOPS - PHP Content Management System // |
|---|
| 5 | // Copyright (c) 2000 XOOPS.org // |
|---|
| 6 | // <http://www.xoops.org/> // |
|---|
| 7 | // ------------------------------------------------------------------------ // |
|---|
| 8 | // This program is free software; you can redistribute it and/or modify // |
|---|
| 9 | // it under the terms of the GNU General Public License as published by // |
|---|
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
|---|
| 11 | // (at your option) any later version. // |
|---|
| 12 | // // |
|---|
| 13 | // You may not change or alter any portion of this comment or credits // |
|---|
| 14 | // of supporting developers from this source code or any supporting // |
|---|
| 15 | // source code which is considered copyrighted (c) material of the // |
|---|
| 16 | // original comment or credit authors. // |
|---|
| 17 | // // |
|---|
| 18 | // This program is distributed in the hope that it will be useful, // |
|---|
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|---|
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|---|
| 21 | // GNU General Public License for more details. // |
|---|
| 22 | // // |
|---|
| 23 | // You should have received a copy of the GNU General Public License // |
|---|
| 24 | // along with this program; if not, write to the Free Software // |
|---|
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|---|
| 26 | // ------------------------------------------------------------------------ // |
|---|
| 27 | // Author: Kazumi Ono (AKA onokazu) // |
|---|
| 28 | // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ // |
|---|
| 29 | // Project: The XOOPS Project // |
|---|
| 30 | // ------------------------------------------------------------------------- // |
|---|
| 31 | include_once XOOPS_ROOT_PATH."/modules/xoopspoll/language/".$xoopsConfig['language']."/main.php"; |
|---|
| 32 | |
|---|
| 33 | class XoopsPollRenderer |
|---|
| 34 | { |
|---|
| 35 | // private |
|---|
| 36 | // XoopsPoll class object |
|---|
| 37 | var $poll; |
|---|
| 38 | |
|---|
| 39 | // constructor |
|---|
| 40 | function XoopsPollRenderer(&$poll) |
|---|
| 41 | { |
|---|
| 42 | $this->poll =& $poll; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | // public |
|---|
| 46 | function renderForm() |
|---|
| 47 | { |
|---|
| 48 | $content = "<form action='".XOOPS_URL."/modules/xoopspoll/index.php' method='post'>"; |
|---|
| 49 | $content .= "<table width='100%' border='0' cellpadding='4' cellspacing='1'>\n"; |
|---|
| 50 | $content .= "<tr class='bg3'><td align='center' colspan='2'><input type='hidden' name='poll_id' value='".$this->poll->getVar("poll_id")."' />\n"; |
|---|
| 51 | $content .= "<b>".$this->poll->getVar("question")."</b></td></tr>\n"; |
|---|
| 52 | $options_arr =& XoopsPollOption::getAllByPollId($this->poll->getVar("poll_id")); |
|---|
| 53 | $option_type = "radio"; |
|---|
| 54 | $option_name = "option_id"; |
|---|
| 55 | if ( $this->poll->getVar("multiple") == 1 ) { |
|---|
| 56 | $option_type = "checkbox"; |
|---|
| 57 | $option_name .= "[]"; |
|---|
| 58 | } |
|---|
| 59 | foreach ( $options_arr as $option ) { |
|---|
| 60 | $content .= "<tr class='bg1'><td align='center'><input type='$option_type' name='$option_name' value='".$option->getVar("option_id")."' /></td><td align='left'>".$option->getVar("option_text"). "</td></tr>\n"; |
|---|
| 61 | } |
|---|
| 62 | $content .= "<tr class='bg3'><td align='center' colspan='2'><input type='submit' value='"._PL_VOTE."' /> "; |
|---|
| 63 | $content .= "<input type='button' value='"._PL_RESULTS."' class='button' onclick='location=\"".XOOPS_URL."/modules/xoopspoll/pollresults.php?poll_id=".$this->poll->getVar("poll_id")."\"' />"; |
|---|
| 64 | $content .= "</td></tr></table></form>\n"; |
|---|
| 65 | return $content; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | function assignForm(&$tpl) |
|---|
| 69 | { |
|---|
| 70 | $options_arr =& XoopsPollOption::getAllByPollId($this->poll->getVar("poll_id")); |
|---|
| 71 | $option_type = "radio"; |
|---|
| 72 | $option_name = "option_id"; |
|---|
| 73 | if ( $this->poll->getVar("multiple") == 1 ) { |
|---|
| 74 | $option_type = "checkbox"; |
|---|
| 75 | $option_name .= "[]"; |
|---|
| 76 | } |
|---|
| 77 | $i = 0; |
|---|
| 78 | foreach ( $options_arr as $option ) { |
|---|
| 79 | $options[$i]['input'] = "<input type='$option_type' name='$option_name' value='".$option->getVar("option_id")."' />"; |
|---|
| 80 | $options[$i]['text'] = $option->getVar("option_text"); |
|---|
| 81 | $i++; |
|---|
| 82 | } |
|---|
| 83 | $tpl->assign('poll', array('question' => $this->poll->getVar("question"), 'pollId' => $this->poll->getVar("poll_id"), 'viewresults' => XOOPS_URL."/modules/xoopspoll/pollresults.php?poll_id=".$this->poll->getVar("poll_id"), 'action' => XOOPS_URL."/modules/xoopspoll/index.php", 'options' => $options)); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | // public |
|---|
| 87 | function renderResults() |
|---|
| 88 | { |
|---|
| 89 | if ( !$this->poll->hasExpired() ) { |
|---|
| 90 | $end_text = sprintf(_PL_ENDSAT, formatTimestamp($this->poll->getVar("end_time"), "m")); |
|---|
| 91 | } else { |
|---|
| 92 | $end_text = sprintf(_PL_ENDEDAT, formatTimestamp($this->poll->getVar("end_time"), "m")); |
|---|
| 93 | } |
|---|
| 94 | echo "<div style='text-align:center'><table width='60%' border='0' cellpadding='4' cellspacing='0'><tr class='bg3'><td><span style='font-weight:bold;'>".$this->poll->getVar("question")."</span></td></tr><tr class='bg1'><td align='right'>$end_text</td></tr></table>"; |
|---|
| 95 | |
|---|
| 96 | echo "<table width='60%' border='0' cellpadding='4' cellspacing='0'>"; |
|---|
| 97 | $options_arr =& XoopsPollOption::getAllByPollId($this->poll->getVar("poll_id")); |
|---|
| 98 | $total = $this->poll->getVar("votes"); |
|---|
| 99 | foreach ( $options_arr as $option ) { |
|---|
| 100 | if ( $total > 0 ) { |
|---|
| 101 | $percent = 100 * $option->getVar("option_count") / $total; |
|---|
| 102 | } else { |
|---|
| 103 | $percent = 0; |
|---|
| 104 | } |
|---|
| 105 | echo "<tr class='bg1'><td width='30%' align='left'>".$option->getVar("option_text")."</td><td width='70%' align='left'>"; |
|---|
| 106 | if ( $percent > 0 ) { |
|---|
| 107 | $width = intval($percent)*2; |
|---|
| 108 | echo "<img src='".XOOPS_URL."/modules/xoopspoll/images/colorbars/".$option->getVar("option_color", "E")."' height='14' width='".$width."' align='middle' alt='".intval($percent)." %' />"; |
|---|
| 109 | } |
|---|
| 110 | printf(" %d %% (%d)", $percent, $option->getVar("option_count")); |
|---|
| 111 | echo "</td></tr>"; |
|---|
| 112 | } |
|---|
| 113 | echo "<tr class='bg1'><td colspan='2' align='center'><br /><b>".sprintf(_PL_TOTALVOTES, $total)."<br />".sprintf(_PL_TOTALVOTERS, $this->poll->getVar("voters"))."</b>"; |
|---|
| 114 | if ( !$this->poll->hasExpired() ) { |
|---|
| 115 | echo "<br />[<a href='".XOOPS_URL."/modules/xoopspoll/index.php?poll_id=".$this->poll->getVar("poll_id")."'>"._PL_VOTE."</a>]"; |
|---|
| 116 | } |
|---|
| 117 | echo "</td></tr></table></div><br />"; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | function assignResults(&$tpl) |
|---|
| 121 | { |
|---|
| 122 | if ( !$this->poll->hasExpired() ) { |
|---|
| 123 | $end_text = sprintf(_PL_ENDSAT, formatTimestamp($this->poll->getVar("end_time"), "m")); |
|---|
| 124 | } else { |
|---|
| 125 | $end_text = sprintf(_PL_ENDEDAT, formatTimestamp($this->poll->getVar("end_time"), "m")); |
|---|
| 126 | } |
|---|
| 127 | $options_arr =& XoopsPollOption::getAllByPollId($this->poll->getVar("poll_id")); |
|---|
| 128 | $total = $this->poll->getVar("votes"); |
|---|
| 129 | $i = 0; |
|---|
| 130 | foreach ( $options_arr as $option ) { |
|---|
| 131 | if ( $total > 0 ) { |
|---|
| 132 | $percent = 100 * $option->getVar("option_count") / $total; |
|---|
| 133 | } else { |
|---|
| 134 | $percent = 0; |
|---|
| 135 | } |
|---|
| 136 | $options[$i]['text'] = $option->getVar("option_text"); |
|---|
| 137 | if ( $percent > 0 ) { |
|---|
| 138 | $width = intval($percent)*4; |
|---|
| 139 | //$options[$i]['image'] = "<img src='".XOOPS_URL."/modules/xoopspoll/images/colorbars/".$option->getVar("option_color", "E")."' height='14' width='".$width."' align='middle' alt='".intval($percent)." %' />"; |
|---|
| 140 | $options[$i]['image'] = "<img src='".XOOPS_URL."/themes/default/img/main/bar01.jpg' width='". $width ."' height='9' alt='". intval($percent) ."' style='vertical-align: middle;'/>"; |
|---|
| 141 | } |
|---|
| 142 | $options[$i]['percent'] = sprintf(" %d %% (%d)", $percent, $option->getVar("option_count")); |
|---|
| 143 | $options[$i]['total'] = $option->getVar("option_count"); |
|---|
| 144 | $i++; |
|---|
| 145 | } |
|---|
| 146 | if ( !$this->poll->hasExpired() ) { |
|---|
| 147 | $vote = "<a href='".XOOPS_URL."/modules/xoopspoll/index.php?poll_id=".$this->poll->getVar("poll_id")."'>"._PL_VOTE."</a>"; |
|---|
| 148 | } |
|---|
| 149 | $tpl->assign('poll', array('question' => $this->poll->getVar("question"),'end_text' => $end_text,'totalVotes' => sprintf(_PL_TOTALVOTES, $total), 'totalVoters' => sprintf(_PL_TOTALVOTERS, $this->poll->getVar("voters")),'vote' => $vote, 'options' => $options)); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | function assignOptions(&$tpl, $option) |
|---|
| 153 | { |
|---|
| 154 | $arrOption =& XoopsPollOption::getOptionByOptionId($option); |
|---|
| 155 | $tpl->assign('arrOption', $arrOption); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | function assignPoll(&$tpl) |
|---|
| 159 | { |
|---|
| 160 | $options_arr =& XoopsPollOption::getAllByPollId($this->poll->getVar("poll_id")); |
|---|
| 161 | $tpl->assign('option_list', $options_arr); |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | function assignComment(&$tpl, $option_id) |
|---|
| 165 | { |
|---|
| 166 | $arrComment =& XoopsPollOption::getAllCommentByOptionId($option_id); |
|---|
| 167 | $tpl->assign('arrComment', $arrComment); |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | } |
|---|
| 171 | ?> |
|---|