本文整理汇总了PHP中safeDie函数的典型用法代码示例。如果您正苦于以下问题:PHP safeDie函数的具体用法?PHP safeDie怎么用?PHP safeDie使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safeDie函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: outputRecord
public function outputRecord($headers, $values, FormattingOptions $oOptions)
{
$this->rowCounter++;
if ($oOptions->answerFormat == 'short') {
$pdfstring = '';
foreach ($values as $value) {
$pdfstring .= $value . ' | ';
}
$this->pdf->intopdf($pdfstring);
} elseif ($oOptions->answerFormat == 'long') {
if ($this->rowCounter != 1) {
$this->pdf->AddPage();
}
$this->pdf->addTitle(sprintf(gT("Survey response %d"), $this->rowCounter));
foreach ($this->aGroupMap as $gid => $questions) {
if ($gid != 0) {
$this->pdf->addGidAnswer($questions[0]['group_name']);
}
foreach ($questions as $question) {
if (isset($values[$question['index']]) && isset($headers[$question['index']])) {
$this->pdf->addAnswer($headers[$question['index']], $values[$question['index']], false);
}
}
}
} else {
safeDie('An invalid answer format was encountered: ' . $oOptions->answerFormat);
}
}
示例2: outputRecord
public function outputRecord($headers, $values, FormattingOptions $oOptions)
{
$this->rowCounter++;
if ($oOptions->answerFormat == 'short') {
$pdfstring = '';
$this->pdf->titleintopdf($this->clang->gT("Survey response"));
foreach ($values as $value) {
$pdfstring .= $value . ' | ';
}
$this->pdf->intopdf($pdfstring);
} elseif ($oOptions->answerFormat == 'long') {
if ($this->rowCounter != 1) {
$this->pdf->AddPage();
}
$this->pdf->Cell(0, 10, sprintf($this->clang->gT("Survey response %d"), $this->rowCounter), 1, 1);
$columnCounter = 0;
foreach ($headers as $header) {
$this->pdf->intopdf($header);
$this->pdf->intopdf($this->stripTagsFull($values[$columnCounter]));
$columnCounter++;
}
} else {
safeDie('An invalid answer format was encountered: ' . $oOptions->answerFormat);
}
}
示例3: outputRecord
/**
* @param array $headers
* @param array $values
* @param FormattingOptions $oOptions
*/
protected function outputRecord($headers, $values, FormattingOptions $oOptions)
{
if ($oOptions->answerFormat == 'short') {
//No headers at all, only output values.
$this->output .= implode($this->separator, $values) . PHP_EOL;
} elseif ($oOptions->answerFormat == 'long') {
//Output each record, one per page, with a header preceding every value.
if ($this->isBeginning) {
$this->isBeginning = false;
} else {
$this->output .= "<br clear='all' style='page-break-before:always'>";
}
$this->output .= "<table><tr><th colspan='2'>" . gT("Survey response") . "</td></tr>" . PHP_EOL;
$counter = 0;
foreach ($headers as $header) {
//if cell empty, output a space instead, otherwise the cell will be in 2pt font
$value = " ";
if ($values[$counter] != "") {
$value = $values[$counter];
}
$this->output .= "<tr><td>" . $header . "</td><td>" . $value . "</td></tr>" . PHP_EOL;
$counter++;
}
$this->output .= "</table>" . PHP_EOL;
} else {
safeDie('An invalid answer format was selected. Only \'short\' and \'long\' are valid.');
}
if ($oOptions->output == 'display') {
echo $this->output;
$this->output = '';
} elseif ($oOptions->output == 'file') {
fwrite($this->file, $this->output);
$this->output = '';
}
}
示例4: loadSurveyById
/**
* Loads a survey from the database that has the given ID. If no matching
* survey is found then null is returned. Note that no results are loaded
* from this function call, only survey structure/definition.
*
* In the future it would be nice to load all languages from the db at
* once and have the infrastructure be able to return responses based
* on language codes.
*
* @param int $id
* @return SurveyObj
*/
public function loadSurveyById($id, $lang = null)
{
$survey = new SurveyObj();
$clang = Yii::app()->lang;
$intId = sanitize_int($id);
$survey->id = $intId;
$survey->info = getSurveyInfo($survey->id);
$availableLanguages = Survey::model()->findByPk($intId)->getAllLanguages();
if (is_null($lang) || in_array($lang, $availableLanguages) === false) {
// use base language when requested language is not found or no specific language is requested
$lang = Survey::model()->findByPk($intId)->language;
}
$clang = new limesurvey_lang($lang);
$survey->fieldMap = createFieldMap($intId, 'full', true, false, $lang);
// Check to see if timings are present and add to fieldmap if needed
if ($survey->info['savetimings'] == "Y") {
$survey->fieldMap = $survey->fieldMap + createTimingsFieldMap($intId, 'full', true, false, $lang);
}
if (empty($intId)) {
//The id given to us is not an integer, croak.
safeDie("An invalid survey ID was encountered: {$sid}");
}
//Load groups
$sQuery = 'SELECT g.* FROM {{groups}} AS g ' . 'WHERE g.sid = ' . $intId . ' AND g.language = \'' . $lang . '\' ' . 'ORDER BY g.group_order;';
$recordSet = Yii::app()->db->createCommand($sQuery)->query()->readAll();
$survey->groups = $recordSet;
//Load questions
$sQuery = 'SELECT q.* FROM {{questions}} AS q ' . 'JOIN {{groups}} AS g ON (q.gid = g.gid and q.language = g.language) ' . 'WHERE q.sid = ' . $intId . ' AND q.language = \'' . $lang . '\' ' . 'ORDER BY g.group_order, q.question_order;';
$survey->questions = Yii::app()->db->createCommand($sQuery)->query()->readAll();
//Load answers
$sQuery = 'SELECT DISTINCT a.* FROM {{answers}} AS a ' . 'JOIN {{questions}} AS q ON a.qid = q.qid ' . 'WHERE q.sid = ' . $intId . ' AND a.language = \'' . $lang . '\' ' . 'ORDER BY a.qid, a.sortorder;';
//$survey->answers = Yii::app()->db->createCommand($sQuery)->queryAll();
$aAnswers = Yii::app()->db->createCommand($sQuery)->queryAll();
foreach ($aAnswers as $aAnswer) {
if (Yii::app()->controller->action->id != 'remotecontrol') {
$aAnswer['answer'] = stripTagsFull($aAnswer['answer']);
}
$survey->answers[$aAnswer['qid']][$aAnswer['scale_id']][$aAnswer['code']] = $aAnswer;
}
//Load language settings for requested language
$sQuery = 'SELECT * FROM {{surveys_languagesettings}} WHERE surveyls_survey_id = ' . $intId . ' AND surveyls_language = \'' . $lang . '\';';
$recordSet = Yii::app()->db->createCommand($sQuery)->query();
$survey->languageSettings = $recordSet->read();
$recordSet->close();
if (tableExists('tokens_' . $survey->id) && array_key_exists('token', SurveyDynamic::model($survey->id)->attributes) && Permission::model()->hasSurveyPermission($survey->id, 'tokens', 'read')) {
// Now add the tokenFields
$survey->tokenFields = getTokenFieldsAndNames($survey->id);
unset($survey->tokenFields['token']);
}
return $survey;
}
示例5: exportSurvey
/**
* Root function for any export results action
*
* @param mixed $iSurveyId
* @param mixed $sLanguageCode
* @param csv|doc|pdf|xls $sExportPlugin Type of export
* @param FormattingOptions $oOptions
* @param string $sFilter
*/
function exportSurvey($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingOptions $oOptions, $sFilter = '')
{
//Do some input validation.
if (empty($iSurveyId)) {
safeDie('A survey ID must be supplied.');
}
if (empty($sLanguageCode)) {
safeDie('A language code must be supplied.');
}
if (empty($oOptions)) {
safeDie('Formatting options must be supplied.');
}
if (empty($oOptions->selectedColumns)) {
safeDie('At least one column must be selected for export.');
}
//echo $oOptions->toString().PHP_EOL;
$writer = null;
$iSurveyId = sanitize_int($iSurveyId);
if ($oOptions->output == 'display') {
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
}
$exports = $this->getExports();
if (array_key_exists($sExportPlugin, $exports) && !empty($exports[$sExportPlugin])) {
// This must be a plugin, now use plugin to load the right class
$event = new PluginEvent('newExport');
$event->set('type', $sExportPlugin);
$oPluginManager = App()->getPluginManager();
$oPluginManager->dispatchEvent($event, $exports[$sExportPlugin]);
$writer = $event->get('writer');
}
if (!$writer instanceof IWriter) {
throw new Exception(sprintf('Writer for %s should implement IWriter', $sExportPlugin));
}
$surveyDao = new SurveyDao();
$survey = $surveyDao->loadSurveyById($iSurveyId, $sLanguageCode);
$writer->init($survey, $sLanguageCode, $oOptions);
$surveyDao->loadSurveyResults($survey, $oOptions->responseMinRecord, $oOptions->responseMaxRecord, $sFilter, $oOptions->responseCompletionState);
$writer->write($survey, $sLanguageCode, $oOptions, true);
$result = $writer->close();
// Close resultset if needed
if ($survey->responses instanceof CDbDataReader) {
$survey->responses->close();
}
if ($oOptions->output == 'file') {
return $writer->filename;
} else {
return $result;
}
}
示例6: outputRecord
public function outputRecord($headers, $values, FormattingOptions $oOptions)
{
$this->rowCounter++;
if ($oOptions->answerFormat == 'short') {
$pdfstring = '';
$this->pdf->titleintopdf($this->translate('New Record', $this->languageCode));
foreach ($values as $value) {
$pdfstring .= $value . ' | ';
}
$this->pdf->intopdf($pdfstring);
} elseif ($oOptions->answerFormat == 'long') {
if ($this->rowCounter != 1) {
$this->pdf->AddPage();
}
$this->pdf->Cell(0, 10, $this->translate('NEW RECORD', $this->languageCode) . ' ' . $this->rowCounter, 1, 1);
$columnCounter = 0;
foreach ($headers as $header) {
$this->pdf->intopdf($header);
$this->pdf->intopdf($this->stripTagsFull($values[$columnCounter]));
$columnCounter++;
}
} else {
safeDie('An invalid answer format was encountered: ' . $oOptions->answerFormat);
}
}
示例7: savedcontrol
function savedcontrol()
{
//This data will be saved to the "saved_control" table with one row per response.
// - a unique "saved_id" value (autoincremented)
// - the "sid" for this survey
// - the "srid" for the survey_x row id
// - "saved_thisstep" which is the step the user is up to in this survey
// - "saved_ip" which is the ip address of the submitter
// - "saved_date" which is the date ofthe saved response
// - an "identifier" which is like a username
// - a "password"
// - "fieldname" which is the fieldname of the saved response
// - "value" which is the value of the response
//We start by generating the first 5 values which are consistent for all rows.
global $surveyid, $thissurvey, $errormsg, $publicurl, $sitename, $clang, $clienttoken, $thisstep;
$timeadjust = getGlobalSetting('timeadjust');
//Check that the required fields have been completed.
$errormsg = '';
if (empty($_POST['savename'])) {
$errormsg .= $clang->gT("You must supply a name for this saved session.") . "<br />\n";
}
if (empty($_POST['savepass'])) {
$errormsg .= $clang->gT("You must supply a password for this saved session.") . "<br />\n";
}
if (empty($_POST['savepass']) || empty($_POST['savepass2']) || $_POST['savepass'] != $_POST['savepass2']) {
$errormsg .= $clang->gT("Your passwords do not match.") . "<br />\n";
}
// if security question asnwer is incorrect
if (function_exists("ImageCreate") && isCaptchaEnabled('saveandloadscreen', $thissurvey['usecaptcha'])) {
if (empty($_POST['loadsecurity']) || !isset($_SESSION['survey_' . $surveyid]['secanswer']) || $_POST['loadsecurity'] != $_SESSION['survey_' . $surveyid]['secanswer']) {
$errormsg .= $clang->gT("The answer to the security question is incorrect.") . "<br />\n";
}
}
if (!empty($errormsg)) {
return;
}
$duplicate = SavedControl::model()->findByAttributes(array('sid' => $surveyid, 'identifier' => $_POST['savename']));
if (!empty($duplicate) && $duplicate->count() > 0) {
$errormsg .= $clang->gT("This name has already been used for this survey. You must use a unique save name.") . "<br />\n";
return;
} else {
//INSERT BLANK RECORD INTO "survey_x" if one doesn't already exist
if (!isset($_SESSION['survey_' . $surveyid]['srid'])) {
$today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust);
$sdata = array("datestamp" => $today, "ipaddr" => getIPAddress(), "startlanguage" => $_SESSION['survey_' . $surveyid]['s_lang'], "refurl" => getenv("HTTP_REFERER"));
if (SurveyDynamic::model($thissurvey['sid'])->insert($sdata)) {
$srid = getLastInsertID('{{survey_' . $surveyid . '}}');
$_SESSION['survey_' . $surveyid]['srid'] = $srid;
} else {
safeDie("Unable to insert record into survey table.<br /><br />");
}
}
//CREATE ENTRY INTO "saved_control"
$today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust);
$saved_control = new SavedControl();
$saved_control->sid = $surveyid;
$saved_control->srid = $_SESSION['survey_' . $surveyid]['srid'];
$saved_control->identifier = $_POST['savename'];
// Binding does escape, so no quoting/escaping necessary
$saved_control->access_code = md5($_POST['savepass']);
$saved_control->email = $_POST['saveemail'];
$saved_control->ip = getIPAddress();
$saved_control->saved_thisstep = $thisstep;
$saved_control->status = 'S';
$saved_control->saved_date = $today;
$saved_control->refurl = getenv('HTTP_REFERER');
if ($saved_control->save()) {
$scid = getLastInsertID('{{saved_control}}');
$_SESSION['survey_' . $surveyid]['scid'] = $scid;
} else {
safeDie("Unable to insert record into saved_control table.<br /><br />");
}
$_SESSION['survey_' . $surveyid]['holdname'] = $_POST['savename'];
//Session variable used to load answers every page. Unsafe - so it has to be taken care of on output
$_SESSION['survey_' . $surveyid]['holdpass'] = $_POST['savepass'];
//Session variable used to load answers every page. Unsafe - so it has to be taken care of on output
//Email if needed
if (isset($_POST['saveemail']) && validateEmailAddress($_POST['saveemail'])) {
$subject = $clang->gT("Saved Survey Details") . " - " . $thissurvey['name'];
$message = $clang->gT("Thank you for saving your survey in progress. The following details can be used to return to this survey and continue where you left off. Please keep this e-mail for your reference - we cannot retrieve the password for you.");
$message .= "\n\n" . $thissurvey['name'] . "\n\n";
$message .= $clang->gT("Name") . ": " . $_POST['savename'] . "\n";
$message .= $clang->gT("Password") . ": " . $_POST['savepass'] . "\n\n";
$message .= $clang->gT("Reload your survey by clicking on the following link (or pasting it into your browser):") . "\n";
$message .= Yii::app()->getController()->createAbsoluteUrl("/survey/index/sid/{$surveyid}/loadall/reload/scid/{$scid}/loadname/" . rawurlencode($_POST['savename']) . "/loadpass/" . rawurlencode($_POST['savepass']) . "/lang/" . rawurlencode($clang->langcode));
if ($clienttoken) {
$message .= "/token/" . rawurlencode($clienttoken);
}
$from = "{$thissurvey['adminname']} <{$thissurvey['adminemail']}>";
if (SendEmailMessage($message, $subject, $_POST['saveemail'], $from, $sitename, false, getBounceEmail($surveyid))) {
$emailsent = "Y";
} else {
$errormsg .= $clang->gT('Error: Email failed, this may indicate a PHP Mail Setup problem on the server. Your survey details have still been saved, however you will not get an email with the details. You should note the "name" and "password" you just used for future reference.');
if (trim($thissurvey['adminemail']) == '') {
$errormsg .= $clang->gT('(Reason: Admin email address empty)');
}
}
}
return $clang->gT('Your survey was successfully saved.');
}
//.........这里部分代码省略.........
示例8: _shouldAddQuestion
private function _shouldAddQuestion($action, $gid, $qid, array $question, $previousQuestion)
{
switch ($action) {
case 'addgroup':
return true;
case 'editgroup':
case 'editgroup_desc':
case 'translategroup':
if (empty($gid)) {
safeDie("No GID provided.");
}
if ($question['gid'] == $gid) {
return false;
}
return true;
case 'addquestion':
if (empty($gid)) {
safeDie("No GID provided.");
}
if (!is_null($previousQuestion) && $previousQuestion['gid'] == $gid && $question['gid'] != $gid) {
return false;
}
return true;
case 'editanswer':
case 'copyquestion':
case 'editquestion':
case 'translatequestion':
case 'translateanswer':
if (empty($gid)) {
safeDie("No GID provided.");
}
if (empty($qid)) {
safeDie("No QID provided.");
}
if ($question['gid'] == $gid && $question['qid'] == $qid) {
return false;
}
return true;
case 'emailtemplates':
// this is the case for email-conf
return true;
default:
safeDie("No Action provided.");
}
}
示例9: XMLImportTimings
function XMLImportTimings($sFullFilePath, $iSurveyID, $aFieldReMap = array())
{
Yii::app()->loadHelper('database');
$sXMLdata = file_get_contents($sFullFilePath);
$xml = simplexml_load_string($sXMLdata, 'SimpleXMLElement', LIBXML_NONET);
if ($xml->LimeSurveyDocType != 'Timings') {
$results['error'] = gT("This is not a valid timings data XML file.");
return $results;
}
$results['responses'] = 0;
$aLanguagesSupported = array();
foreach ($xml->languages->language as $language) {
$aLanguagesSupported[] = (string) $language;
}
$results['languages'] = count($aLanguagesSupported);
// Return if there are no timing records to import
if (!isset($xml->timings->rows)) {
return $results;
}
switchMSSQLIdentityInsert('survey_' . $iSurveyID . '_timings', true);
foreach ($xml->timings->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
if ($key[0] == '_') {
$key = substr($key, 1);
}
if (isset($aFieldReMap[substr($key, 0, -4)])) {
$key = $aFieldReMap[substr($key, 0, -4)] . 'time';
}
$insertdata[$key] = (string) $value;
}
$result = SurveyTimingDynamic::model($iSurveyID)->insertRecords($insertdata) or safeDie(gT("Error") . ": Failed to insert data[17]<br />");
$results['responses']++;
}
switchMSSQLIdentityInsert('survey_' . $iSurveyID . '_timings', false);
return $results;
}
示例10: actionAction
/**
* @param int $surveyid
* @param string $language
*/
public function actionAction($surveyid, $language = null)
{
$sLanguage = $language;
$this->sLanguage = $language;
ob_start(function ($buffer) {
App()->getClientScript()->render($buffer);
App()->getClientScript()->reset();
return $buffer;
});
ob_implicit_flush(false);
$iSurveyID = (int) $surveyid;
$this->iSurveyID = (int) $surveyid;
//$postlang = returnglobal('lang');
Yii::import('application.libraries.admin.progressbar', true);
Yii::app()->loadHelper("userstatistics");
Yii::app()->loadHelper('database');
Yii::app()->loadHelper('surveytranslator');
App()->getClientScript()->registerPackage('jqueryui');
App()->getClientScript()->registerPackage('jquery-touch-punch');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "survey_runtime.js");
$data = array();
if (!isset($iSurveyID)) {
$iSurveyID = returnGlobal('sid');
} else {
$iSurveyID = (int) $iSurveyID;
}
if (!$iSurveyID) {
//This next line ensures that the $iSurveyID value is never anything but a number.
safeDie('You have to provide a valid survey ID.');
}
$actresult = Survey::model()->findAll('sid = :sid AND active = :active', array(':sid' => $iSurveyID, ':active' => 'Y'));
//Checked
if (count($actresult) == 0) {
safeDie('You have to provide a valid survey ID.');
} else {
$surveyinfo = getSurveyInfo($iSurveyID);
// CHANGE JSW_NZ - let's get the survey title for display
$thisSurveyTitle = $surveyinfo["name"];
// CHANGE JSW_NZ - let's get css from individual template.css - so define path
$thisSurveyCssPath = getTemplateURL($surveyinfo["template"]);
if ($surveyinfo['publicstatistics'] != 'Y') {
safeDie('The public statistics for this survey are deactivated.');
}
//check if graphs should be shown for this survey
if ($surveyinfo['publicgraphs'] == 'Y') {
$publicgraphs = 1;
} else {
$publicgraphs = 0;
}
}
//we collect all the output within this variable
$statisticsoutput = '';
//for creating graphs we need some more scripts which are included here
//True -> include
//False -> forget about charts
if (isset($publicgraphs) && $publicgraphs == 1) {
require_once APPPATH . 'third_party/pchart/pchart/pChart.class';
require_once APPPATH . 'third_party/pchart/pchart/pData.class';
require_once APPPATH . 'third_party/pchart/pchart/pCache.class';
$MyCache = new pCache(Yii::app()->getConfig("tempdir") . DIRECTORY_SEPARATOR);
//$currentuser is created as prefix for pchart files
if (isset($_SERVER['REDIRECT_REMOTE_USER'])) {
$currentuser = $_SERVER['REDIRECT_REMOTE_USER'];
} else {
if (session_id()) {
$currentuser = substr(session_id(), 0, 15);
} else {
$currentuser = "standard";
}
}
}
// Set language for questions and labels to base language of this survey
if ($sLanguage == null || !in_array($sLanguage, Survey::model()->findByPk($iSurveyID)->getAllLanguages())) {
$sLanguage = Survey::model()->findByPk($iSurveyID)->language;
} else {
$sLanguage = sanitize_languagecode($sLanguage);
}
//set survey language for translations
SetSurveyLanguage($iSurveyID, $sLanguage);
//Create header
sendCacheHeaders();
$condition = false;
$sitename = Yii::app()->getConfig("sitename");
$data['surveylanguage'] = $sLanguage;
$data['sitename'] = $sitename;
$data['condition'] = $condition;
$data['thisSurveyCssPath'] = $thisSurveyCssPath;
/*
* only show questions where question attribute "public_statistics" is set to "1"
*/
$query = "SELECT q.* , group_name, group_order FROM {{questions}} q, {{groups}} g, {{question_attributes}} qa\n WHERE g.gid = q.gid AND g.language = :lang1 AND q.language = :lang2 AND q.sid = :surveyid AND q.qid = qa.qid AND q.parent_qid = 0 AND qa.attribute = 'public_statistics'";
$databasetype = Yii::app()->db->getDriverName();
if ($databasetype == 'mssql' || $databasetype == "sqlsrv" || $databasetype == "dblib") {
$query .= " AND CAST(CAST(qa.value as varchar) as int)='1'\n";
} else {
$query .= " AND qa.value='1'\n";
//.........这里部分代码省略.........
示例11: XMLImportTimings
function XMLImportTimings($sFullFilepath, $iSurveyID, $aFieldReMap = array())
{
Yii::app()->loadHelper('database');
$clang = Yii::app()->lang;
$xml = simplexml_load_file($sFullFilepath);
if ($xml->LimeSurveyDocType != 'Timings') {
$results['error'] = $clang->gT("This is not a valid timings data XML file.");
return $results;
}
$results['responses'] = 0;
$aLanguagesSupported = array();
foreach ($xml->languages->language as $language) {
$aLanguagesSupported[] = (string) $language;
}
$results['languages'] = count($aLanguagesSupported);
switchMSSQLIdentityInsert('survey_' . $iSurveyID . '_timings', true);
foreach ($xml->timings->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
if ($key[0] == '_') {
$key = substr($key, 1);
}
if (isset($aFieldReMap[substr($key, 0, -4)])) {
$key = $aFieldReMap[substr($key, 0, -4)] . 'time';
}
$insertdata[$key] = (string) $value;
}
$result = Survey_timings::model($iSurveyID)->insertRecords($insertdata) or safeDie($clang->gT("Error") . ": Failed to insert data<br />");
$results['responses']++;
}
switchMSSQLIdentityInsert('survey_' . $iSurveyID . '_timings', false);
return $results;
}
示例12: translateInsertansTags
/**
* This function replaces the old insertans tags with new ones across a survey
*
* @param string $newsid Old SID
* @param string $oldsid New SID
* @param mixed $fieldnames Array array('oldfieldname'=>'newfieldname')
*/
function translateInsertansTags($newsid, $oldsid, $fieldnames)
{
uksort($fieldnames, create_function('$a,$b', 'return strlen($a) < strlen($b);'));
Yii::app()->loadHelper('database');
$newsid = sanitize_int($newsid);
$oldsid = sanitize_int($oldsid);
# translate 'surveyls_urldescription' and 'surveyls_url' INSERTANS tags in surveyls
$sql = "SELECT surveyls_survey_id, surveyls_language, surveyls_urldescription, surveyls_url from {{surveys_languagesettings}}\n WHERE surveyls_survey_id=" . $newsid . " AND (surveyls_urldescription LIKE '%{$oldsid}X%' OR surveyls_url LIKE '%{$oldsid}X%')";
$result = dbExecuteAssoc($sql) or show_error("Can't read groups table in transInsertAns ");
// Checked
//while ($qentry = $res->FetchRow())
foreach ($result->readAll() as $qentry) {
$urldescription = $qentry['surveyls_urldescription'];
$endurl = $qentry['surveyls_url'];
$language = $qentry['surveyls_language'];
foreach ($fieldnames as $sOldFieldname => $sNewFieldname) {
$pattern = $sOldFieldname;
$replacement = $sNewFieldname;
$urldescription = preg_replace('/' . $pattern . '/', $replacement, $urldescription);
$endurl = preg_replace('/' . $pattern . '/', $replacement, $endurl);
}
if (strcmp($urldescription, $qentry['surveyls_urldescription']) != 0 || strcmp($endurl, $qentry['surveyls_url']) != 0) {
// Update Field
$data = array('surveyls_urldescription' => $urldescription, 'surveyls_url' => $endurl);
$where = array('surveyls_survey_id' => $newsid, 'surveyls_language' => $language);
SurveyLanguageSetting::model()->updateRecord($data, $where);
}
// Enf if modified
}
// end while qentry
# translate 'quotals_urldescrip' and 'quotals_url' INSERTANS tags in quota_languagesettings
$sql = "SELECT quotals_id, quotals_urldescrip, quotals_url from {{quota_languagesettings}} qls, {{quota}} q\n WHERE sid=" . $newsid . " AND q.id=qls.quotals_quota_id AND (quotals_urldescrip LIKE '%{$oldsid}X%' OR quotals_url LIKE '%{$oldsid}X%')";
$result = dbExecuteAssoc($sql) or safeDie("Can't read quota table in transInsertAns");
// Checked
foreach ($result->readAll() as $qentry) {
$urldescription = $qentry['quotals_urldescrip'];
$endurl = $qentry['quotals_url'];
foreach ($fieldnames as $sOldFieldname => $sNewFieldname) {
$pattern = $sOldFieldname;
$replacement = $sNewFieldname;
$urldescription = preg_replace('/' . $pattern . '/', $replacement, $urldescription);
$endurl = preg_replace('/' . $pattern . '/', $replacement, $endurl);
}
if (strcmp($urldescription, $qentry['quotals_urldescrip']) != 0 || strcmp($endurl, $qentry['quotals_url']) != 0) {
// Update Field
$sqlupdate = "UPDATE {{quota_languagesettings}} SET quotals_urldescrip='" . $urldescription . "', quotals_url='" . $endurl . "' WHERE quotals_id={$qentry['quotals_id']}";
$updateres = dbExecuteAssoc($sqlupdate) or safeDie("Couldn't update INSERTANS in quota_languagesettings<br />{$sqlupdate}<br />");
//Checked
}
// Enf if modified
}
// end while qentry
# translate 'description' INSERTANS tags in groups
$sql = "SELECT gid, language, group_name, description from {{groups}}\n WHERE sid=" . $newsid . " AND description LIKE '%{$oldsid}X%' OR group_name LIKE '%{$oldsid}X%'";
$res = dbExecuteAssoc($sql) or show_error("Can't read groups table in transInsertAns");
// Checked
//while ($qentry = $res->FetchRow())
foreach ($res->readAll() as $qentry) {
$gpname = $qentry['group_name'];
$description = $qentry['description'];
$gid = $qentry['gid'];
$language = $qentry['language'];
foreach ($fieldnames as $sOldFieldname => $sNewFieldname) {
$pattern = $sOldFieldname;
$replacement = $sNewFieldname;
$gpname = preg_replace('/' . $pattern . '/', $replacement, $gpname);
$description = preg_replace('/' . $pattern . '/', $replacement, $description);
}
if (strcmp($description, $qentry['description']) != 0 || strcmp($gpname, $qentry['group_name']) != 0) {
// Update Fields
$where = array('gid' => $gid, 'language' => $language);
$oGroup = QuestionGroup::model()->findByAttributes($where);
$oGroup->description = $description;
$oGroup->group_name = $gpname;
$oGroup->save();
}
// Enf if modified
}
// end while qentry
# translate 'question' and 'help' INSERTANS tags in questions
$sql = "SELECT qid, language, question, help from {{questions}}\n WHERE sid=" . $newsid . " AND (question LIKE '%{$oldsid}X%' OR help LIKE '%{$oldsid}X%')";
$result = dbExecuteAssoc($sql) or die("Can't read question table in transInsertAns ");
// Checked
//while ($qentry = $res->FetchRow())
$aResultData = $result->readAll();
foreach ($aResultData as $qentry) {
$question = $qentry['question'];
$help = $qentry['help'];
$qid = $qentry['qid'];
$language = $qentry['language'];
foreach ($fieldnames as $sOldFieldname => $sNewFieldname) {
$pattern = $sOldFieldname;
$replacement = $sNewFieldname;
//.........这里部分代码省略.........
示例13: index
function index($subaction, $iSurveyID = null, $gid = null, $qid = null)
{
$iSurveyID = sanitize_int($iSurveyID);
$gid = sanitize_int($gid);
$qid = sanitize_int($qid);
$clang = $this->getController()->lang;
$imageurl = Yii::app()->getConfig("adminimageurl");
Yii::app()->loadHelper("database");
if (!empty($_POST['subaction'])) {
$subaction = Yii::app()->request->getPost('subaction');
}
//BEGIN Sanitizing POSTed data
if (!isset($iSurveyID)) {
$iSurveyID = returnGlobal('sid');
}
if (!isset($qid)) {
$qid = returnGlobal('qid');
}
if (!isset($gid)) {
$gid = returnGlobal('gid');
}
if (!isset($p_scenario)) {
$p_scenario = returnGlobal('scenario');
}
if (!isset($p_cqid)) {
$p_cqid = returnGlobal('cqid');
if ($p_cqid == '') {
$p_cqid = 0;
}
// we are not using another question as source of condition
}
if (!isset($p_cid)) {
$p_cid = returnGlobal('cid');
}
if (!isset($p_subaction)) {
if (isset($_POST['subaction'])) {
$p_subaction = $_POST['subaction'];
} else {
$p_subaction = $subaction;
}
}
if (!isset($p_cquestions)) {
$p_cquestions = returnGlobal('cquestions');
}
if (!isset($p_csrctoken)) {
$p_csrctoken = returnGlobal('csrctoken');
}
if (!isset($p_prevquestionsgqa)) {
$p_prevquestionsgqa = returnGlobal('prevQuestionSGQA');
}
if (!isset($p_canswers)) {
if (isset($_POST['canswers']) && is_array($_POST['canswers'])) {
foreach ($_POST['canswers'] as $key => $val) {
$p_canswers[$key] = preg_replace("/[^_.a-zA-Z0-9]@/", "", $val);
}
}
}
// this array will be used soon,
// to explain wich conditions is used to evaluate the question
if (Yii::app()->getConfig('stringcomparizonoperators') == 1) {
$method = array("<" => $clang->gT("Less than"), "<=" => $clang->gT("Less than or equal to"), "==" => $clang->gT("equals"), "!=" => $clang->gT("Not equal to"), ">=" => $clang->gT("Greater than or equal to"), ">" => $clang->gT("Greater than"), "RX" => $clang->gT("Regular expression"), "a<b" => $clang->gT("Less than (Strings)"), "a<=b" => $clang->gT("Less than or equal to (Strings)"), "a>=b" => $clang->gT("Greater than or equal to (Strings)"), "a>b" => $clang->gT("Greater than (Strings)"));
} else {
$method = array("<" => $clang->gT("Less than"), "<=" => $clang->gT("Less than or equal to"), "==" => $clang->gT("equals"), "!=" => $clang->gT("Not equal to"), ">=" => $clang->gT("Greater than or equal to"), ">" => $clang->gT("Greater than"), "RX" => $clang->gT("Regular expression"));
}
if (isset($_POST['method'])) {
if (!in_array($_POST['method'], array_keys($method))) {
$p_method = "==";
} else {
$p_method = trim($_POST['method']);
}
}
if (isset($_POST['newscenarionum'])) {
$p_newscenarionum = sanitize_int($_POST['newscenarionum']);
}
//END Sanitizing POSTed data
//include_once("login_check.php");
include_once "database.php";
// Caution (lemeur): database.php uses autoUnescape on all entries in $_POST
// Take care to not use autoUnescape on $_POST variables after this
$br = CHtml::openTag('br /');
//MAKE SURE THAT THERE IS A SID
if (!isset($iSurveyID) || !$iSurveyID) {
$conditionsoutput = $clang->gT("You have not selected a survey") . str_repeat($br, 2);
$conditionsoutput .= CHtml::submitButton($clang->gT("Main admin screen"), array('onclick' => "window.open('" . $this->getController()->createUrl("admin/") . "', '_top')")) . $br;
safeDie($conditionsoutput);
return;
}
if (isset($p_subaction) && $p_subaction == "resetsurveylogic") {
$clang = $this->getController()->lang;
$resetsurveylogicoutput = $br;
$resetsurveylogicoutput .= CHtml::openTag('table', array('class' => 'alertbox'));
$resetsurveylogicoutput .= CHtml::openTag('tr') . CHtml::openTag('td', array('colspan' => '2'));
$resetsurveylogicoutput .= CHtml::tag('font', array('size' => '1'), CHtml::tag('strong', array(), $clang->gT("Reset Survey Logic")));
$resetsurveylogicoutput .= CHtml::closeTag('td') . CHtml::closeTag('tr');
if (!isset($_GET['ok'])) {
$button_yes = CHtml::submitButton($clang->gT("Yes"), array('onclick' => "window.open('" . $this->getController()->createUrl("admin/conditions/sa/index/subaction/resetsurveylogic/surveyid/{$iSurveyID}") . "?ok=Y" . "', '_top')"));
$button_cancel = CHtml::submitButton($clang->gT("Cancel"), array('onclick' => "window.open('" . $this->getController()->createUrl("admin/survey/sa/view/surveyid/{$iSurveyID}") . "', '_top')"));
$messagebox_content = $clang->gT("You are about to delete all conditions on this survey's questions") . "({$iSurveyID})" . $br . $clang->gT("We recommend that before you proceed, you export the entire survey from the main administration screen.") . $br . $clang->gT("Continue?") . $br . $button_yes . $button_cancel;
$this->_renderWrappedTemplate('conditions', array('message' => array('title' => $clang->gT("Warning"), 'message' => $messagebox_content)));
exit;
//.........这里部分代码省略.........
示例14: buildXMLFromQuery
/**
* buildXMLFromQuery() creates a datadump of a table in XML using XMLWriter
*
* @param mixed $xmlwriter The existing XMLWriter object
* @param mixed $Query The table query to build from
* @param mixed $tagname If the XML tag of the resulting question should be named differently than the table name set it here
* @param array $excludes array of columnames not to include in export
*/
function buildXMLFromQuery($xmlwriter, $Query, $tagname = '', $excludes = array())
{
$iChunkSize = 3000;
// This works even for very large result sets and leaves a minimal memory footprint
preg_match('/\\bfrom\\b\\s*{{(\\w+)}}/i', $Query, $MatchResults);
if ($tagname != '') {
$TableName = $tagname;
} else {
$TableName = $MatchResults[1];
}
// Read table in smaller chunks
$iStart = 0;
do {
$QueryResult = Yii::app()->db->createCommand($Query)->limit($iChunkSize, $iStart)->query();
$result = $QueryResult->readAll();
if ($iStart == 0 && count($result) > 0) {
$exclude = array_flip($excludes);
//Flip key/value in array for faster checks
$xmlwriter->startElement($TableName);
$xmlwriter->startElement('fields');
$aColumninfo = array_keys($result[0]);
foreach ($aColumninfo as $fieldname) {
if (!isset($exclude[$fieldname])) {
$xmlwriter->writeElement('fieldname', $fieldname);
}
}
$xmlwriter->endElement();
// close columns
$xmlwriter->startElement('rows');
}
foreach ($result as $Row) {
$xmlwriter->startElement('row');
foreach ($Row as $Key => $Value) {
if (!isset($exclude[$Key])) {
if (!is_null($Value)) {
if (is_numeric($Key[0])) {
$Key = '_' . $Key;
}
// mask invalid element names with an underscore
$Key = str_replace('#', '-', $Key);
if (!$xmlwriter->startElement($Key)) {
safeDie('Invalid element key: ' . $Key);
}
// Remove invalid XML characters
if ($Value !== '') {
$Value = str_replace(']]>', '', $Value);
$xmlwriter->writeCData(preg_replace('/[^\\x9\\xA\\xD\\x20-\\x{D7FF}\\x{E000}-\\x{FFFD}\\x{10000}-\\x{10FFFF}]/u', '', $Value));
}
$xmlwriter->endElement();
}
}
}
$xmlwriter->endElement();
// close row
}
$iStart = $iStart + $iChunkSize;
} while (count($result) == $iChunkSize);
if (count($result) > 0) {
$xmlwriter->endElement();
// close rows
$xmlwriter->endElement();
// close tablename
}
}
示例15: view
//.........这里部分代码省略.........
if ($bgc == "even") {
$bgc = "odd";
} else {
$bgc = "even";
}
$qid = $deqrow['qid'];
$fieldname = "{$surveyid}" . "X" . "{$gid}" . "X" . "{$qid}";
$cdata['bgc'] = $bgc;
$cdata['fieldname'] = $fieldname;
$cdata['deqrow'] = $deqrow;
$cdata['thissurvey'] = $thissurvey;
if ($deqrow['help']) {
$hh = addcslashes($deqrow['help'], "..'\"");
//Escape ASCII decimal 0-32 plus single and double quotes to make JavaScript happy.
$hh = htmlspecialchars($hh, ENT_QUOTES);
//Change & " ' < > to HTML entities to make HTML happy.
$cdata['hh'] = $hh;
}
switch ($deqrow['type']) {
case "Q":
//MULTIPLE SHORT TEXT
//MULTIPLE SHORT TEXT
case "K":
$deaquery = "SELECT question,title FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order";
$dearesult = dbExecuteAssoc($deaquery);
$cdata['dearesult'] = $dearesult->readAll();
break;
case "1":
// multi scale^
$deaquery = "SELECT * FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$baselang}' ORDER BY question_order";
$dearesult = dbExecuteAssoc($deaquery);
$cdata['dearesult'] = $dearesult->readAll();
$oquery = "SELECT other FROM {{questions}} WHERE qid={$deqrow['qid']} AND language='{$baselang}'";
$oresult = dbExecuteAssoc($oquery) or safeDie("Couldn't get other for list question<br />" . $oquery);
foreach ($oresult->readAll() as $orow) {
$cdata['fother'] = $orow['other'];
}
break;
case "L":
//LIST drop-down/radio-button list
//LIST drop-down/radio-button list
case "!":
// $qidattributes=getQuestionAttributeValues($deqrow['qid']);
if ($deqrow['type'] == '!' && trim($qidattributes['category_separator']) != '') {
$optCategorySeparator = $qidattributes['category_separator'];
} else {
unset($optCategorySeparator);
}
$defexists = "";
$deaquery = "SELECT * FROM {{answers}} WHERE qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY sortorder, answer";
$dearesult = dbExecuteAssoc($deaquery);
//$aDataentryoutput .= "\t<select name='$fieldname' class='form-control' >\n";
$aDatatemp = '';
if (!isset($optCategorySeparator)) {
foreach ($dearesult->readAll() as $dearow) {
$aDatatemp .= "<option value='{$dearow['code']}'";
//if ($dearow['default_value'] == "Y") {$aDatatemp .= " selected='selected'"; $defexists = "Y";}
$aDatatemp .= ">{$dearow['answer']}</option>\n";
}
} else {
$defaultopts = array();
$optgroups = array();
foreach ($dearesult->readAll() as $dearow) {
list($categorytext, $answertext) = explode($optCategorySeparator, $dearow['answer']);
if ($categorytext == '') {
$defaultopts[] = array('code' => $dearow['code'], 'answer' => $answertext, 'default_value' => $dearow['assessment_value']);