function serveFile() { if ($this->missingParams()) { $this->error("Required parameters are missing"); } else { if ($this->checkPermissions()) { $tc = new ThorCore("", $this->table); if ($this->mode == "fetch_zip") { $path = $this->zipfile; $matches = array(); $res = preg_match("/.*_(form_.*)/", $this->zipfile, $matches); $attachmentFilename = count($matches) == 2 ? $matches[1] : "thor_archive.zip"; } else { $path = $tc->construct_file_storage_location($this->row, $this->col, $this->filename); $attachmentFilename = $this->filename; } if (!file_exists($path)) { $this->error("Unable to find this file"); } else { header('Content-disposition: attachment; filename=' . $attachmentFilename); // header('Content-type: text/plain'); readfile($path); if ($this->mode == "fetch_zip") { ignore_user_abort(true); if (connection_aborted()) { unlink($this->zipfile); } unlink($this->zipfile); } } } else { $this->error("You do not have permissions to access this file."); } } }
function run() { $form = $this->get_form(); // thor_core needs the XML from the form entities thor_content field, and the table name the data is stored in $xml = $form->get_value('thor_content'); $table_name = 'form_' . $form->id(); $thor_core = new ThorCore($xml, $table_name); $thor_values = $thor_core->get_rows(); // Loop through the database information to gather the poll results $pretty_values = array(); if ($thor_values != "") { foreach ($thor_values as $t_v) { foreach ($t_v as $key => $value) { if ($key != "id" && $key != "submitted_by" && $key != "submitter_ip" && $key != "date_created" && $key != "date_modified") { $pretty_values[] = $value; } } } } // Get the total number of results and then find the total results for each option $responses = array_count_values($pretty_values); $accumulator = array(); foreach ($responses as $response) { $accumulator[] = $response; } // Get the label for each option $name = array(); foreach ($responses as $key => $value) { $name[] = $key; } // Calculate the total and get the percentage for each option $total = 0; $per = array(); foreach ($accumulator as $key => $value) { $total += $value; } if ($total > 0) { for ($i = 0; $i <= count($accumulator) - 1; $i++) { $per[$i] = round($accumulator[$i] / $total * 100) . "%"; } } if (!$this->show_results()) { echo '<p><a href="' . carl_make_link(array('show_results' => 1, 'submission_key' => '')) . '">Show Results</a></p>'; } else { echo '<p><a href="' . carl_make_link(array('show_results' => 0, 'submission_key' => '')) . '">Hide Results</a></p>'; } if ($this->show_results()) { if ($this->sidebar) { echo '<div id="interactive" class="graph">'; } else { echo '<div id="graph1" class="graph">'; } for ($i = 0; $i <= count($accumulator) - 1; $i++) { echo '<table width="300px" border="solid" cellpadding="5px"> <tr> <td width="50px">' . reason_htmlspecialchars($per[$i]) . ' </td><td> ' . reason_htmlspecialchars($name[$i]) . '</td> </tr> </table>'; } echo '</div>'; if ($this->sidebar) { echo '<div id="hover"></div>'; } echo '<div id="responses"><p><strong>Total responses: ' . $total . '</strong></p></div>'; } $datas = array(); $lbls = array(); for ($i = 0; $i <= count($accumulator) - 1; $i++) { $datas[$i] = $accumulator[$i]; $lbls[$i] = $name[$i]; } // Transfer the labels and totals for each option to polls.js echo '<script type="text/javascript">' . "\n"; echo 'var data = new Array();' . "\n"; echo 'var lbl = new Array();' . "\n"; echo 'var color = new Array();' . "\n"; for ($i = 0; $i <= count($datas) - 1; $i++) { $color = isset($this->params['custom_colors'][$i]) ? $this->params['custom_colors'][$i] : "#" . dechex(rand(0, 10000000)); echo 'color[' . $i . '] = "' . addslashes(htmlspecialchars($color)) . '" ;' . "\n"; echo 'data[' . $i . '] =' . addslashes(htmlspecialchars($datas[$i])) . ';' . "\n"; echo 'lbl[' . $i . '] = "' . addslashes(htmlspecialchars($lbls[$i])) . '" ;' . "\n"; } echo '</script>' . "\n"; }