/** * Output Page * * Assembles a completed page from template and sends it to output. * * @param string $template The name of the template file to load. * @param array $data An associative array of data to be made available to the template. */ public static function output($template, $data = array()) { global $page_errors; //////////////////////////////////////////////////////////// // Find the user's country. Used by header, so a safe bit to do regardless. if (preg_match('#^[A-Z]{2}$#i', get_http_var('country'))) { $data['country'] = strtoupper(get_http_var('country')); } else { $data['country'] = Utility\Gaze::getCountryByIp($_SERVER["REMOTE_ADDR"]); } //////////////////////////////////////////////////////////// // Get the page data global $DATA, $this_page, $THEUSER; $header = new Renderer\Header(); $data = array_merge($header->data, $data); $user = new Renderer\User(); $data = array_merge($user->data, $data); if (isset($page_errors)) { $data['page_errors'] = $page_errors; } //////////////////////////////////////////////////////////// // Search URL $SEARCH = new \URL('search'); $SEARCH->reset(); $data['search_url'] = $SEARCH->generate(); //////////////////////////////////////////////////////////// // Search URL // Footer Links $footer = new Renderer\Footer(); $data['footer_links'] = $footer->data; # banner text $b = new Model\Banner(); $data['banner_text'] = $b->get_text(); $data = self::addCommonURLs($data); # mini survey // we never want to display this on the front page or any // other survey page we might have if (!in_array($this_page, array('survey', 'overview'))) { $mini = new MiniSurvey(); $data['mini_survey'] = $mini->get_values(); } //////////////////////////////////////////////////////////// // Unpack the data we've been passed so it's available for use in the templates. extract($data); //////////////////////////////////////////////////////////// // Require the templates and output header('Content-Type: text/html; charset=iso-8859-1'); require_once INCLUDESPATH . 'easyparliament/templates/html/header.php'; require_once INCLUDESPATH . 'easyparliament/templates/html/' . $template . '.php'; require_once INCLUDESPATH . 'easyparliament/templates/html/footer.php'; }
private function loadSurveyResponses(){ $c=$this->getCollectionObject(); $db = Loader::db(); $tempMiniSurvey = new MiniSurvey(); $pageBase=DIR_REL.'/' . DISPATCHER_FILENAME . '?cID='.$c->getCollectionID(); if( $_REQUEST['action'] == 'deleteForm' ){ $this->deleteForm($_REQUEST['bID'], $_REQUEST['qsID']); } if( $_REQUEST['action'] == 'deleteResponse' ){ $this->deleteAnswers($_REQUEST['asid']); } //load surveys $surveysRS=FormBlockStatistics::loadSurveys($tempMiniSurvey); //index surveys by question set id $surveys=array(); while($survey=$surveysRS->fetchRow()){ //get Survey Answers $survey['answerSetCount'] = MiniSurvey::getAnswerCount( $survey['questionSetId'] ); $surveys[ $survey['questionSetId'] ] = $survey; } //load requested survey response if( strlen($_REQUEST['qsid'])>0 ){ $questionSet=preg_replace('/[^[:alnum:]]/','',$_REQUEST['qsid']); //get Survey Questions $questionsRS=MiniSurvey::loadQuestions($questionSet); $questions=array(); while( $question = $questionsRS->fetchRow() ){ $questions[$question['msqID']]=$question; } //get Survey Answers $answerSetCount = MiniSurvey::getAnswerCount($questionSet); //pagination $pageBaseSurvey=$pageBase.'&qsid='.$questionSet; $paginator=Loader::helper('pagination'); $sortBy=$_REQUEST['sortBy']; $paginator->init( intval($_REQUEST['page']) ,$answerSetCount,$pageBaseSurvey.'&page=%pageNum%&sortBy='.$sortBy,$this->pageSize); if($this->pageSize>0) $limit=$paginator->getLIMIT(); else $limit=''; $answerSets = FormBlockStatistics::buildAnswerSetsArray( $questionSet, $sortBy, $limit ); } $this->set('questions',$questions); $this->set('answerSets',$answerSets); $this->set('paginator',$paginator); $this->set('questionSet',$questionSet); $this->set('surveys',$surveys); }
<?php defined('C5_EXECUTE') or die("Access Denied."); $survey=$controller; //echo $survey->surveyName.'<br>'; $miniSurvey=new MiniSurvey($b); $miniSurvey->frontEndMode=true; ?> <a name="<?php echo $survey->questionSetId ?>"></a><br/> <?php if ($invalidIP) { ?> <div class="ccm-error"><p><?=$invalidIP?></p></div> <? } ?> <form enctype="multipart/form-data" id="miniSurveyView<?=intval($bID)?>" class="miniSurveyView" method="post" action="<?php echo $this->action('submit_form').'#'.$survey->questionSetId?>"> <?php if( $_GET['surveySuccess'] && $_GET['qsid']==intval($survey->questionSetId) ){ ?> <div id="msg"><?php echo $survey->thankyouMsg ?></div> <?php }elseif(strlen($formResponse)){ ?> <div id="msg"> <?php echo $formResponse ?> <?php if(is_array($errors) && count($errors)) foreach($errors as $error){ echo '<div class="error">'.$error.'</div>'; } ?> </div> <? } ?> <input name="qsID" type="hidden" value="<?= intval($survey->questionSetId)?>" /> <input name="pURI" type="hidden" value="<?= $pURI ?>" /> <?php $miniSurvey->loadSurvey( $survey->questionSetId, 0, intval($bID) ); ?> </form>
function delete() { $db = Loader::db(); $deleteData['questionsIDs'] = array(); $deleteData['strandedAnswerSetIDs'] = array(); $miniSurvey = new MiniSurvey(); $info = $miniSurvey->getMiniSurveyBlockInfo($this->bID); //get all answer sets $q = "SELECT asID FROM {$this->btAnswerSetTablename} WHERE questionSetId = " . intval($info['questionSetId']); $answerSetsRS = $db->query($q); //delete the questions $deleteData['questionsIDs'] = $db->getAll("SELECT qID FROM {$this->btQuestionsTablename} WHERE questionSetId = " . intval($info['questionSetId']) . ' AND bID=' . intval($this->bID)); foreach ($deleteData['questionsIDs'] as $questionData) { $db->query("DELETE FROM {$this->btQuestionsTablename} WHERE qID=" . intval($questionData['qID'])); } //delete left over answers $strandedAnswerIDs = $db->getAll('SELECT fa.aID FROM `btFormAnswers` AS fa LEFT JOIN btFormQuestions as fq ON fq.msqID=fa.msqID WHERE fq.msqID IS NULL'); foreach ($strandedAnswerIDs as $strandedAnswerIDs) { $db->query('DELETE FROM `btFormAnswers` WHERE aID=' . intval($strandedAnswer['aID'])); } //delete the left over answer sets $deleteData['strandedAnswerSetIDs'] = $db->getAll('SELECT aset.asID FROM btFormAnswerSet AS aset LEFT JOIN btFormAnswers AS fa ON aset.asID=fa.asID WHERE fa.asID IS NULL'); foreach ($deleteData['strandedAnswerSetIDs'] as $strandedAnswerSetIDs) { $db->query('DELETE FROM btFormAnswerSet WHERE asID=' . intval($strandedAnswerSetIDs['asID'])); } //delete the form block $q = "delete from {$this->btTable} where bID = '{$this->bID}'"; $r = $db->query($q); parent::delete(); return $deleteData; }
<?php defined('C5_EXECUTE') or die("Access Denied."); //$miniSurveyInfo['surveyName']= $bs->surveyName; $miniSurvey = new MiniSurvey($b); $miniSurveyInfo = $miniSurvey->getMiniSurveyBlockInfo($b->getBlockID()); MiniSurvey::questionCleanup(intval($miniSurveyInfo['questionSetId']), $b->getBlockID()); $u = new User(); $ui = UserInfo::getByID($u->uID); if (strlen(trim($miniSurveyInfo['recipientEmail'])) == 0) { $miniSurveyInfo['recipientEmail'] = $ui->uEmail; } ?> <script> var thisbID=parseInt(<?php echo $b->getBlockID(); ?> ); var thisbtID=parseInt(<?php echo $b->getBlockTypeID(); ?> ); </script> <?php $this->inc('styles_include.php', array('c' => $c, 'b' => $b, 'miniSurveyInfo' => $miniSurveyInfo, 'miniSurvey' => $miniSurvey, 'a' => $a, 'bt' => $bt)); $this->inc('form_setup_html.php', array('c' => $c, 'b' => $b, 'miniSurveyInfo' => $miniSurveyInfo, 'miniSurvey' => $miniSurvey, 'a' => $a, 'bt' => $bt));
/** * Output Page * * Assembles a completed page from template and sends it to output. * * @param string $template The name of the template file to load. * @param array $data An associative array of data to be made available to the template. */ public static function output($template, $data = array()) { // Include includes. // TODO: Wrap these in a class somewhere autoloadable. include_once INCLUDESPATH . 'postcode.inc'; //////////////////////////////////////////////////////////// // Find the user's country. Used by header, so a safe bit to do regardless. if (preg_match('#^[A-Z]{2}$#i', get_http_var('country'))) { $data['country'] = strtoupper(get_http_var('country')); } else { $data['country'] = Gaze::get_country_by_ip($_SERVER["REMOTE_ADDR"]); } //////////////////////////////////////////////////////////// // Get the page data global $DATA, $this_page, $THEUSER; $header = new Renderer\Header(); $data = array_merge($header->data, $data); //////////////////////////////////////////////////////////// // User Navigation Links $data['user_nav_links'] = array(); // We may want to send the user back to this current page after they've // joined, logged out or logged in. So we put the URL in $returl. $URL = new \URL($this_page); $returl = $URL->generate('none'); //user logged in if ($THEUSER->isloggedin()) { // The 'Edit details' link. $menudata = $DATA->page_metadata('userviewself', 'menu'); $edittext = $menudata['text']; $edittitle = $menudata['title']; $EDITURL = new \URL('userviewself'); if ($this_page == 'userviewself' || $this_page == 'useredit' || $header->top_highlight == 'userviewself') { $editclass = 'on'; } else { $editclass = ''; } // The 'Log out' link. $menudata = $DATA->page_metadata('userlogout', 'menu'); $logouttext = $menudata['text']; $logouttitle = $menudata['title']; $LOGOUTURL = new \URL('userlogout'); if ($this_page != 'userlogout') { $LOGOUTURL->insert(array("ret" => $returl)); $logoutclass = ''; } else { $logoutclass = 'on'; } $username = $THEUSER->firstname() . ' ' . $THEUSER->lastname(); $data['user_nav_links'][] = array('href' => $LOGOUTURL->generate(), 'title' => $logouttitle, 'classes' => $logoutclass, 'text' => $logouttext); $data['user_nav_links'][] = array('href' => $EDITURL->generate(), 'title' => $edittitle, 'classes' => $editclass, 'text' => $edittext); $data['user_nav_links'][] = array('href' => $EDITURL->generate(), 'title' => $edittitle, 'classes' => $editclass, 'text' => _htmlentities($username)); } else { // User not logged in // The 'Join' link. $menudata = $DATA->page_metadata('userjoin', 'menu'); $jointext = $menudata['text']; $jointitle = $menudata['title']; $JOINURL = new \URL('userjoin'); if ($this_page != 'userjoin') { if ($this_page != 'userlogout' && $this_page != 'userlogin') { // We don't do this on the logout page, because then the user // will return straight to the logout page and be logged out // immediately! $JOINURL->insert(array("ret" => $returl)); } $joinclass = ''; } else { $joinclass = 'on'; } // The 'Log in' link. $menudata = $DATA->page_metadata('userlogin', 'menu'); $logintext = $menudata['text']; $logintitle = $menudata['title']; $LOGINURL = new \URL('userlogin'); if ($this_page != 'userlogin') { if ($this_page != "userlogout" && $this_page != "userpassword" && $this_page != 'userjoin') { // We don't do this on the logout page, because then the user // will return straight to the logout page and be logged out // immediately! // And it's also silly if we're sent back to Change Password. // And the join page. $LOGINURL->insert(array("ret" => $returl)); } $loginclass = ''; } else { $loginclass = 'on'; } $data['user_nav_links'][] = array('href' => $LOGINURL->generate(), 'title' => $logintitle, 'classes' => $loginclass, 'text' => $logintext); $data['user_nav_links'][] = array('href' => $JOINURL->generate(), 'title' => $jointitle, 'classes' => $joinclass, 'text' => $jointext); } // If the user's postcode is set, then we add a link to Your MP etc. if ($THEUSER->postcode_is_set()) { $items = array('yourmp'); if (postcode_is_scottish($THEUSER->postcode())) { $items[] = 'yourmsp'; } elseif (postcode_is_ni($THEUSER->postcode())) { $items[] = 'yourmla'; } foreach ($items as $item) { $menudata = $DATA->page_metadata($item, 'menu'); $logintext = $menudata['text']; $URL = new \URL($item); $data['user_nav_links'][] = array('href' => $URL->generate(), 'title' => '', 'classes' => '', 'text' => $logintext); } } //////////////////////////////////////////////////////////// // Search URL $SEARCH = new \URL('search'); $SEARCH->reset(); $data['search_url'] = $SEARCH->generate(); //////////////////////////////////////////////////////////// // Search URL // Footer Links $footer = new Renderer\Footer(); $data['footer_links'] = $footer->data; # banner text $b = new Model\Banner(); $data['banner_text'] = $b->get_text(); # mini survey // we never want to display this on the front page or any // other survey page we might have if (!in_array($this_page, array('survey', 'overview'))) { $mini = new MiniSurvey(); $data['mini_survey'] = $mini->get_values(); } //////////////////////////////////////////////////////////// // Unpack the data we've been passed so it's available for use in the templates. extract($data); //////////////////////////////////////////////////////////// // Require the templates and output header('Content-Type: text/html; charset=iso-8859-1'); require_once INCLUDESPATH . 'easyparliament/templates/html/header.php'; require_once INCLUDESPATH . 'easyparliament/templates/html/' . $template . '.php'; require_once INCLUDESPATH . 'easyparliament/templates/html/footer.php'; }
<?php $survey = $controller; //echo $survey->surveyName.'<br>'; $miniSurvey = new MiniSurvey($b); $miniSurvey->frontEndMode = true; ?> <form id="miniSurveyView<?php echo intval($survey->questionSetId); ?> " class="miniSurveyView" method="post" action="<?php echo $this->action('submit_form'); ?> "> <div style="margin-bottom:8px"><strong><?php echo $survey->surveyName; ?> </strong></div> <?php if ($_GET['surveySuccess'] && $_GET['qsid'] == intval($survey->questionSetId)) { ?> <div id="msg">Thank you.</div> <?php } ?> <input name="qsID" type="hidden" value="<?php echo intval($survey->questionSetId); ?> " />
function delete() { $db = Loader::db(); $miniSurvey = new MiniSurvey(); $info = $miniSurvey->getMiniSurveyBlockInfo($this->bID); //get all answer sets $q = "SELECT asID FROM {$this->btAnswerSetTablename} WHERE questionSetId = " . intval($info['questionSetId']); $answerSetsRS = $db->query($q); //delete the answers while ($answerSet = $answerSetsRS->fetchRow()) { $q = "delete from {$this->btAnswersTablename} where asID = " . intval($answerSet['asID']); $r = $db->query($q); } //delete the answer sets $q = "delete from {$this->btAnswerSetTablename} where questionSetId = " . intval($info['questionSetId']); $r = $db->query($q); //delete the questions $q = "delete from {$this->btQuestionsTablename} where questionSetId = " . intval($info['questionSetId']); $r = $db->query($q); //delete the form block $q = "delete from {$this->btTable} where bID = '{$this->bID}'"; $r = $db->query($q); }