/** * Get Vote Form HTML for convert plugin * * @static * @param array $votes * @param integer $vote_id vote form id * @global $vars * @global $vars['page'] * @global $defaultpage * @global $digest * @var $options 'readonly' * @var $options 'addchoice' * @var $options 'barchart' * @uses get_script_uri() * @return string */ function get_vote_form_convert($votes, $vote_id) { $choice_label = _('Selection'); $vote_label = _('Vote'); $vote_button = _('Vote'); $add_button = _('Vote'); // _('Add'); // Initilization global $vars, $defaultpage; global $digest; $page = isset($vars['page']) ? $vars['page'] : $defaultpage; $s_page = htmlspecialchars($page); $s_digest = htmlspecialchars($digest); $script = $this->options['readonly'] ? '' : get_script_uri(); $submit = $this->options['readonly'] ? 'hidden' : 'submit'; $choicestyle = 'padding-left:1em;padding-right:1em;'; $countstyle = ($this->options['barchart'] ? 'width:120px;' : '') . 'padding-right:1em;'; $buttonstyle = $this->options['readonly'] ? 'display:none;' : ''; $anchor = $this->get_anchor('convert', $vote_id); // Init barchart if ($this->options['barchart']) { $barchart = new BARCHART(0, 0, 100); $barchart->setColorCompound($this->CONF['BARCHART_COLOR_BAR']); $barchart->setColorBg($this->CONF['BARCHART_COLOR_BG']); $barchart->setColorBorder($this->CONF['BARCHART_COLOR_BORDER']); $sum = 0; $max = 0; $argmax = 0; foreach ($votes as $choice_id => $vote) { list($choice, $count) = $vote; $sum += $count; if ($max < $count) { $max = $count; $argmax = $choice_id; } } } // Header $form = ''; $form .= '<form class="votex" action="' . $script . '" method="post">' . "\n"; $form .= '<table cellspacing="0" cellpadding="2" class="style_table" summary="vote">' . "\n"; $form .= ' <tr>' . "\n"; $form .= ' <td align="left" class="vote_label" style="' . $choicestyle . '"><strong>' . $choice_label . '</strong>' . "\n"; $form .= ' <a name="' . $anchor . '" id="' . $anchor . '"></a>' . "\n"; $form .= ' <input type="hidden" name="cmd" value="votex" />' . "\n"; $form .= ' <input type="hidden" name="pcmd" value="convert" />' . "\n"; $form .= ' <input type="hidden" name="refer" value="' . $s_page . '" />' . "\n"; $form .= ' <input type="hidden" name="vote_id" value="' . $vote_id . '" />' . "\n"; $form .= ' <input type="hidden" name="digest" value="' . $s_digest . '" />' . "\n"; $form .= ' </td>' . "\n"; $form .= ' <td align="right" class="vote_label" style="' . $countstyle . '"><strong>' . $vote_label . '</strong></td>' . "\n"; $form .= ' <td align="right" class="vote_label" style="' . $buttonstyle . '"></td>' . "\n"; $form .= ' </tr>' . "\n"; // Body foreach ($votes as $choice_id => $vote) { list($choice, $count) = $vote; $class = $choice_id % 2 ? 'vote_td1' : 'vote_td2'; $s_choice = make_link($choice); $s_count = htmlspecialchars($count); $choice_key = $this->encode_choice($choice_id); if ($this->options['barchart']) { $percent = (int) ($count / $max * 100); // / $sum $barchart->setCurrPoint($percent); $barchart->setStrAfterBar(' ' . $s_count); $s_count = $barchart->getBar(); } $form .= ' <tr>' . "\n"; $form .= ' <td align="left" class="' . $class . '" style="' . $choicestyle . '">' . $s_choice . '</td>' . "\n"; $form .= ' <td align="right" class="' . $class . '" style="' . $countstyle . '">' . $s_count . '</td>' . "\n"; $form .= ' <td align="right" class="' . $class . '" style="' . $buttonstyle . '">' . "\n"; $form .= ' <input type="' . $submit . '" name="' . $choice_key . '" value="' . $vote_button . '" class="submit" />' . "\n"; $form .= ' </td>' . "\n"; $form .= ' </tr>' . "\n"; } // add choice if ($this->options['addchoice']) { $choice_id++; $class = $choice_id % 2 ? 'vote_td1' : 'vote_td2'; $choice_key = $this->encode_choice($choice_id); $form .= ' <tr>' . "\n"; $form .= ' <td colspan="2" align="left" class="' . $class . '" style="' . $choicestyle . '">' . "\n"; $form .= ' <input type="text" size="40" name="addchoice" value="" />' . "\n"; $form .= ' </td>' . "\n"; $form .= ' <td align="right" class="' . $class . '" style="' . $buttonstyle . '">' . "\n"; $form .= ' <input type="' . $submit . '" name="' . $choice_key . '" value="' . $add_button . '" class="submit" />' . "\n"; $form .= ' </td>' . "\n"; $form .= ' </tr>' . "\n"; } // Footer $form .= '</table>' . "\n"; $form .= '</form>' . "\n"; return $form; }
<body> <h2>BARCHARTCLASS class example - mailbox usage</h2> <p> <table border="0" width="100%" cellspacing="1" cellpadding="2"> <tr bgcolor="#c5c5c5"> <td width="40%"><b>Folder</b></td> <td width="30%"><b>Usage</b></td> <td width="3%" align="center"><b>%</b></td> <td width="9%"><b>Messages</b></td> <td width="9%"><b>New</b></td> <td width="9%"><b>Size</b></td> </tr> <?php $box_size = 519.6; $total_size += $box_size; $bar->setCurrPoint($box_size); ?> <tr bgcolor="#d7d7d7"> <td><b>Inbox</b></td> <td><?php echo $bar->getBar(); ?> </td> <td align="right"><?php echo $bar->getPercentage(); ?> %</td> <td>10</td> <td>0</td> <td align="right"><?php echo $box_size;
function plugin_vote2_convert() { global $script, $vars, $digest, $_vote2_messages; global $_vote_plugin_choice, $_vote_plugin_votes; global $digests; static $numbers = array(); static $notitle = FALSE; //$_vote_plugin_choice = _("Selection"); //$_vote_plugin_votes = _("Vote"); $str_notimestamp = $_vote2_messages['arg_notimestamp']; $str_nonumber = $_vote2_messages['arg_nonumber']; $str_nolabel = $_vote2_messages['arg_nolabel']; $str_notitle = $_vote2_messages['arg_notitle']; $str_barchart = $_vote2_messages['arg_barchart']; if (!array_key_exists($vars['page'], $numbers)) { $numbers[$vars['page']] = 0; } $o_vote_no = $f_vote_no = $vote_no = $numbers[$vars['page']]++; if (!func_num_args()) { return ''; } $args = func_get_args(); $page = $vars['page']; $ndigest = $digest; $tdcnt = 0; $body2 = ''; $nonumber = $nolabel = $barchart = FALSE; $options = array(); foreach ($args as $arg) { $arg = trim($arg); switch ($arg) { case $str_notimestamp: continue; case $str_nonumber: $nonumber = TRUE; continue; case $str_nolabel: $nolabel = TRUE; continue; case $str_notitle: $notitle = TRUE; continue; case $str_barchart: $barchart = TRUE; continue; default: $options[] = $arg; } } // Total $total = 0; if ($barchart) { foreach ($options as $arg) { if (preg_match('/^(.+(?==))=([+-]?\\d+)([bir]?)$/', $arg, $match)) { continue; } if (preg_match('/^(.*)\\[(\\d+)\\]$/', $arg, $match)) { $total += $match[2]; continue; } } if ($total > 0) { $bar = new BARCHART(0, 0, 100); $bar->setColorBg(VOTE2_COLOR_BG); $bar->setColorBorder(VOTE2_COLOR_BORDER); $bar->setColorCompound(VOTE2_COLOR_BAR); } else { $barchart = FALSE; } } foreach ($options as $arg) { $cnt = 0; if (preg_match('/^(.+(?==))=([+-]?\\d+)([bir]?)$/', $arg, $match)) { list($page, $vote_no, $f_vote_no, $ndigest) = plugin_vote2_address($match, $vote_no, $page, $ndigest); continue; } if (preg_match('/^(.*)\\[(\\d+)\\]$/', $arg, $match)) { $arg = $match[1]; $cnt = $match[2]; } $e_arg = encode($arg); $f_cnf = ''; if ($nonumber == FALSE) { $title = $notitle ? '' : "title=\"{$o_vote_no}\""; $f_cnt = "<span {$title}> " . $cnt . ' </span>'; } if ($barchart) { $Percentage = (int) ($cnt / $total * 100); $bar->setCurrPoint($Percentage); $getBar = $bar->getBar(); $barchart_style = 'style="width:95%;"'; } else { $barchart_style = ''; } $link = make_link($arg); switch ($tdcnt++ % 3) { case 0: $cls = 'vote_td1'; break; case 1: $cls = 'vote_td2'; break; case 2: $cls = 'vote_td3'; break; } $cls = $tdcnt++ % 2 ? 'vote_td1' : 'vote_td2'; $body2 .= <<<EOD <tr> <td align="left" class="{$cls}" style="padding-left:1em;padding-right:1em;">{$link}</td> EOD; $body2 .= <<<EOD <td align="right" class="{$cls}">{$f_cnt} EOD; if ($nolabel == FALSE) { $body2 .= <<<EOD <input type="submit" name="vote_{$e_arg}" value="{$_vote_plugin_votes}" class="submit" /> EOD; } $body2 .= " </td>\n"; if ($barchart) { $body2 .= <<<EOD <td class="{$cls}" style="padding-left:1em;padding-right:1em;">{$getBar}</td> EOD; } $body2 .= " </tr>\n"; } $s_page = htmlspecialchars($page); $s_digest = htmlspecialchars($ndigest); $title = $notitle ? '' : "title=\"{$f_vote_no}\""; $body = <<<EOD <form action="{$script}" method="post"> <table cellspacing="0" cellpadding="2" class="style_table" {$barchart_style} summary="vote" {$title}> <tr> <td align="left" class="vote_label" style="padding-left:1em;padding-right:1em"><strong>{$_vote_plugin_choice}</strong> <input type="hidden" name="plugin" value="vote2" /> <input type="hidden" name="refer" value="{$s_page}" /> <input type="hidden" name="digest" value="{$s_digest}" /> <input type="hidden" name="vote_no" value="{$vote_no}" /> </td> EOD; if ($barchart) { $body .= <<<EOD <td class="vote_label"> </td> EOD; } $body .= <<<EOD <td align="center" class="vote_label"><strong>{$_vote_plugin_votes}</strong></td> </tr> {$body2} </table> </form> EOD; return $body; }