本文整理汇总了PHP中ls_json_encode函数的典型用法代码示例。如果您正苦于以下问题:PHP ls_json_encode函数的具体用法?PHP ls_json_encode怎么用?PHP ls_json_encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ls_json_encode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sanitize_int
if (isset($_REQUEST['survey_id'])) {
$intSurveyId = sanitize_int($_REQUEST['survey_id']);
}
$owner_id = $_SESSION['loginID'];
header('Content-type: application/json');
$query = "UPDATE " . db_table_name('surveys') . " SET owner_id = {$intNewOwner} WHERE sid={$intSurveyId}";
if (bHasGlobalPermission("USER_RIGHT_SUPERADMIN")) {
$query .= ";";
} else {
$query .= " AND owner_id={$owner_id};";
}
$result = db_execute_assoc($query) or safe_die($connect->ErrorMsg());
$query = "SELECT b.users_name FROM " . db_table_name('surveys') . " as a" . " INNER JOIN " . db_table_name('users') . " as b ON a.owner_id = b.uid WHERE sid={$intSurveyId} AND owner_id={$intNewOwner};";
$result = db_execute_assoc($query) or safe_die($connect->ErrorMsg());
$intRecordCount = $result->RecordCount();
$aUsers = array('record_count' => $intRecordCount);
if ($result->RecordCount() > 0) {
while ($rows = $result->FetchRow()) {
$aUsers['newowner'] = $rows['users_name'];
}
}
$ajaxoutput = ls_json_encode($aUsers) . "\n";
} elseif ($action == "ajaxgetusers") {
header('Content-type: application/json');
$aSeenUsers = getuserlist();
$aUsers = array();
foreach ($aSeenUsers as $userline) {
$aUsers[] = array($userline['uid'], $userline['user']);
}
$ajaxoutput = ls_json_encode($aUsers) . "\n";
}
示例2: getTokens_json
//.........这里部分代码省略.........
$aData->records = Token::model($iSurveyId)->count($condition);
if ($limit > $aData->records) {
$limit = $aData->records;
}
if ($limit != 0) {
$aData->total = ceil($aData->records / $limit);
} else {
$aData->total = 0;
}
Yii::app()->loadHelper("surveytranslator");
$format = getDateFormatData(Yii::app()->session['dateformat']);
$aSurveyInfo = Survey::model()->findByPk($iSurveyId)->getAttributes();
//Get survey settings
$attributes = getAttributeFieldNames($iSurveyId);
// Now find all responses for the visible tokens
$visibleTokens = array();
$answeredTokens = array();
if ($aSurveyInfo['anonymized'] == "N" && $aSurveyInfo['active'] == "Y") {
foreach ($tokens as $token) {
if (isset($token['token']) && $token['token']) {
$visibleTokens[] = $token['token'];
}
}
$answers = SurveyDynamic::model($iSurveyId)->findAllByAttributes(array('token' => $visibleTokens));
foreach ($answers as $answer) {
$answeredTokens[$answer['token']] = $answer['token'];
}
}
$bReadPermission = Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'read');
$bCreatePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'create');
$bTokenUpdatePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'update');
$bTokenDeletePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'delete');
$bGlobalPanelReadPermission = Permission::model()->hasGlobalPermission('participantpanel', 'read');
foreach ($tokens as $token) {
$aRowToAdd = array();
if ((int) $token['validfrom']) {
$token['validfrom'] = date($format['phpdate'] . ' H:i', strtotime(trim($token['validfrom'])));
} else {
$token['validfrom'] = '';
}
if ((int) $token['validuntil']) {
$token['validuntil'] = date($format['phpdate'] . ' H:i', strtotime(trim($token['validuntil'])));
} else {
$token['validuntil'] = '';
}
$aRowToAdd['id'] = $token['tid'];
$action = "";
$action .= "<div class='inputbuttons'>";
// so we can hide this when edit is clicked
// Check is we have an answer
if (in_array($token['token'], $answeredTokens) && $bReadPermission) {
// @@TODO change link
$url = $this->getController()->createUrl("admin/responses/sa/browse/surveyid/{$iSurveyId}", array('token' => $token['token']));
$title = $clang->gT("View response details");
$action .= CHtml::link(CHtml::image(Yii::app()->getConfig('adminimageurl') . 'token_viewanswer.png', $title, array('title' => $title)), $url, array('class' => 'imagelink'));
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}
// Check if the token can be taken
if ($token['token'] != "" && ($token['completed'] == "N" || $token['completed'] == "" || $aSurveyInfo['alloweditaftercompletion'] == "Y") && $bCreatePermission) {
$action .= viewHelper::getImageLink('do_16.png', "survey/index/sid/{$iSurveyId}/token/{$token['token']}/lang/{$token['language']}/newtest/Y", $clang->gT("Do survey"), '_blank');
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}
if ($bTokenDeletePermission) {
$attribs = array('onclick' => 'if (confirm("' . $clang->gT("Are you sure you want to delete this entry?") . ' (' . $token['tid'] . ')")) {$("#displaytokens").delRowData(' . $token['tid'] . ');$.post(delUrl,{tid:' . $token['tid'] . '});}');
$action .= viewHelper::getImageLink('token_delete.png', null, $clang->gT("Delete token entry"), null, 'imagelink btnDelete', $attribs);
}
if (strtolower($token['emailstatus']) == 'ok' && $token['email'] && $bTokenUpdatePermission) {
if ($token['completed'] == 'N' && $token['usesleft'] > 0) {
if ($token['sent'] == 'N') {
$action .= viewHelper::getImageLink('token_invite.png', "admin/tokens/sa/email/surveyid/{$iSurveyId}/tokenids/" . $token['tid'], $clang->gT("Send invitation email to this person (if they have not yet been sent an invitation email)"), "_blank");
} else {
$action .= viewHelper::getImageLink('token_remind.png', "admin/tokens/sa/email/action/remind/surveyid/{$iSurveyId}/tokenids/" . $token['tid'], $clang->gT("Send reminder email to this person (if they have already received the invitation email)"), "_blank");
}
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}
if ($bTokenUpdatePermission) {
$action .= viewHelper::getImageLink('edit_16.png', null, $clang->gT("Edit token entry"), null, 'imagelink token_edit');
}
if (!empty($token['participant_id']) && $token['participant_id'] != "" && $bGlobalPanelReadPermission) {
$action .= viewHelper::getImageLink('cpdb_16.png', null, $clang->gT("View this person in the central participants database"), null, 'imagelink cpdb', array('onclick' => "sendPost('" . $this->getController()->createUrl('admin/participants/sa/displayParticipants') . "','',['searchcondition'],['participant_id||equal||{$token['participant_id']}']);"));
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}
$action .= '</div>';
$aRowToAdd['cell'] = array($token['tid'], $action, $token['firstname'], $token['lastname'], $token['email'], $token['emailstatus'], $token['token'], $token['language'], $token['sent'], $token['remindersent'], $token['remindercount'], $token['completed'], $token['usesleft'], $token['validfrom'], $token['validuntil']);
foreach ($attributes as $attribute) {
$aRowToAdd['cell'][] = $token[$attribute];
}
$aData->rows[] = $aRowToAdd;
}
viewHelper::disableHtmlLogging();
header("Content-type: application/json");
echo ls_json_encode($aData);
}
示例3: htmlspecialchars
} else {
//$questionselecter = substr($question, 0, 35)."..";
$questionselecter = htmlspecialchars(mb_strcut(html_entity_decode($question, ENT_QUOTES, 'UTF-8'), 0, 35, 'UTF-8')) . "...";
}
$quesitonNavOptions .= "<option value='{$scriptname}?sid={$surveyid}&gid={$row['gid']}&qid={$row['qid']}&action=conditions&subaction=editconditionsform'>{$row['title']}: " . $questionselecter . "</option>";
}
$quesitonNavOptions .= "</optgroup>\n";
$conditionsoutput_menubar .= "\t</div><div class='menubar-right'>\n" . "<img width=\"11\" alt=\"\" src=\"{$imageurl}/blank.gif\"/>\n" . "<font class=\"boxcaption\">" . $clang->gT("Questions") . ":</font>\n" . "<select id='questionNav' onchange=\"window.open(this.options[this.selectedIndex].value,'_self')\">{$quesitonNavOptions}</select>\n" . "<img hspace=\"0\" border=\"0\" alt=\"\" src=\"{$imageurl}/seperator.gif\"/>\n" . "<a href=\"http://docs.limesurvey.org\" target='_blank' title=\"" . $clang->gTview("LimeSurvey online manual") . "\">" . "<img src='{$imageurl}/showhelp.png' name='ShowHelp' title=''" . "alt='" . $clang->gT("LimeSurvey online manual") . "' /></a>";
$conditionsoutput_menubar .= "\t</div></div></div>\n" . "<p style='margin: 0pt; font-size: 1px; line-height: 1px; height: 1px;'> </p>" . "</td></tr>\n";
//Now display the information and forms
//BEGIN: PREPARE JAVASCRIPT TO SHOW MATCHING ANSWERS TO SELECTED QUESTION
$conditionsoutput_main_content .= "<script type='text/javascript'>\n" . "<!--\n" . "\tvar Fieldnames = new Array();\n" . "\tvar Codes = new Array();\n" . "\tvar Answers = new Array();\n" . "\tvar QFieldnames = new Array();\n" . "\tvar Qcqids = new Array();\n" . "\tvar Qtypes = new Array();\n";
$jn = 0;
if (isset($canswers)) {
foreach ($canswers as $can) {
$an = ls_json_encode(FlattenText($can[2]));
$conditionsoutput_main_content .= "Fieldnames[{$jn}]='{$can['0']}';\n" . "Codes[{$jn}]='{$can['1']}';\n" . "Answers[{$jn}]={$an};\n";
$jn++;
}
}
$jn = 0;
if (isset($cquestions)) {
foreach ($cquestions as $cqn) {
$conditionsoutput_main_content .= "QFieldnames[{$jn}]='{$cqn['3']}';\n" . "Qcqids[{$jn}]='{$cqn['1']}';\n" . "Qtypes[{$jn}]='{$cqn['2']}';\n";
$jn++;
}
}
// record a JS variable to let jQuery know if survey is Anonymous
if ($thissurvey['anonymized'] == 'Y') {
$conditionsoutput_main_content .= "isAnonymousSurvey = true;";
} else {
示例4: do_multiplenumeric
//.........这里部分代码省略.........
$slider_max = 100;
}
$slider_default = trim($aQuestionAttributes['slider_default']) != '' ? $aQuestionAttributes['slider_default'] : "";
if ($slider_default == '' && $aQuestionAttributes['slider_middlestart'] == 1) {
$slider_middlestart = intval(($slider_max + $slider_min) / 2);
} else {
$slider_middlestart = '';
}
$slider_separator = trim($aQuestionAttributes['slider_separator']) != '' ? $aQuestionAttributes['slider_separator'] : "";
$slider_reset = $aQuestionAttributes['slider_reset'] ? 1 : 0;
} else {
$slider_layout = false;
}
$hidetip = $aQuestionAttributes['hide_tip'];
if ($aQuestionAttributes['random_order'] == 1) {
$ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY " . dbRandom();
} else {
$ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY question_order";
}
$ansresult = dbExecuteAssoc($ansquery);
//Checked
$aSubquestions = $ansresult->readAll();
$anscount = count($aSubquestions) * 2;
$fn = 1;
$answer_main = '';
if ($anscount == 0) {
$inputnames = array();
$answer_main .= ' <li>' . $clang->gT('Error: This question has no answers.') . "</li>\n";
} else {
foreach ($aSubquestions as $ansrow) {
$myfname = $ia[1] . $ansrow['title'];
if ($ansrow['question'] == "") {
$ansrow['question'] = " ";
}
if ($slider_layout === false || $slider_separator == '') {
$theanswer = $ansrow['question'];
$sliderleft = '';
$sliderright = '';
} else {
$aAnswer = explode($slider_separator, $ansrow['question']);
$theanswer = isset($aAnswer[0]) ? $aAnswer[0] : "";
$sliderleft = isset($aAnswer[1]) ? $aAnswer[1] : "";
$sliderright = isset($aAnswer[2]) ? $aAnswer[2] : "";
$sliderleft = "<div class=\"slider_lefttext\">{$sliderleft}</div>";
$sliderright = "<div class=\"slider_righttext\">{$sliderright}</div>";
}
// color code missing mandatory questions red
if ($ia[6] == 'Y' && ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['step'] == $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['prevstep'] || $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['maxstep'] > $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['step']) && $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname] === '') {
$theanswer = "<span class='errormandatory'>{$theanswer}</span>";
}
list($htmltbody2, $hiddenfield) = return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, '', $myfname, "li", "question-item answer-item text-item numeric-item" . $extraclass);
$answer_main .= "\t{$htmltbody2}\n";
$answer_main .= "<label for=\"answer{$myfname}\" class=\"{$prefixclass}-label\">{$theanswer}</label>\n";
$sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeparator = $sSeparator['separator'];
$answer_main .= "{$sliderleft}<span class=\"input\">\n\t" . $prefix . "\n\t<input class=\"text {$kpclass}\" type=\"text\" size=\"" . $tiwidth . "\" name=\"" . $myfname . "\" id=\"answer" . $myfname . "\" title=\"" . $clang->gT('Only numbers may be entered in this field.') . "\" value=\"";
if (isset($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname])) {
$dispVal = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$myfname];
if (strpos($dispVal, ".")) {
$dispVal = rtrim(rtrim($dispVal, "0"), ".");
}
$dispVal = str_replace('.', $sSeparator, $dispVal);
$answer_main .= $dispVal;
}
$answer_main .= '" onkeyup="' . $checkconditionFunction . '(this.value, this.name, this.type);" ' . " {$maxlength} />\n\t" . $suffix . "\n</span>{$sliderright}\n\t</li>\n";
$fn++;
$inputnames[] = $myfname;
}
if (trim($aQuestionAttributes['equals_num_value']) != '' || trim($aQuestionAttributes['min_num_value']) != '' || trim($aQuestionAttributes['max_num_value']) != '') {
$qinfo = LimeExpressionManager::GetQuestionStatus($ia[0]);
if (trim($aQuestionAttributes['equals_num_value']) != '') {
$answer_main .= "\t<li class='multiplenumerichelp help-item'>\n" . "<span class=\"label\">" . $clang->gT('Remaining: ') . "</span>\n" . "<span id=\"remainingvalue_{$ia[0]}\" class=\"dynamic_remaining\">{$prefix}\n" . "{" . $qinfo['sumRemainingEqn'] . "}\n" . "{$suffix}</span>\n" . "\t</li>\n";
}
$answer_main .= "\t<li class='multiplenumerichelp help-item'>\n" . "<span class=\"label\">" . $clang->gT('Total: ') . "</span>\n" . "<span id=\"totalvalue_{$ia[0]}\" class=\"dynamic_sum\">{$prefix}\n" . "{" . $qinfo['sumEqn'] . "}\n" . "{$suffix}</span>\n" . "\t</li>\n";
}
$answer .= "<ul class=\"subquestions-list questions-list text-list {$prefixclass}-list\">\n" . $answer_main . "</ul>\n";
}
if ($aQuestionAttributes['slider_layout'] == 1) {
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "numeric-slider.js");
Yii::app()->getClientScript()->registerCssFile(Yii::app()->getConfig('publicstyleurl') . "numeric-slider.css");
if ($slider_default != "") {
$slider_startvalue = $slider_default;
$slider_displaycallout = 1;
} elseif ($slider_middlestart != '') {
$slider_startvalue = $slider_middlestart;
$slider_displaycallout = 0;
} else {
$slider_startvalue = 'NULL';
$slider_displaycallout = 0;
}
$slider_showminmax = $aQuestionAttributes['slider_showminmax'] == 1 ? 1 : 0;
//some var for slider
$aJsLang = array('reset' => $clang->gT('Reset'), 'tip' => $clang->gT('Please click and drag the slider handles to enter your answer.'));
$aJsVar = array('slider_showminmax' => $slider_showminmax, 'slider_min' => $slider_min, 'slider_mintext' => $slider_mintext, 'slider_max' => $slider_max, 'slider_maxtext' => $slider_maxtext, 'slider_step' => $slider_step, 'slider_startvalue' => $slider_startvalue, 'slider_displaycallout' => $slider_displaycallout, 'slider_prefix' => $prefix, 'slider_suffix' => $suffix, 'slider_reset' => $slider_reset, 'lang' => $aJsLang);
$answer .= "<script type='text/javascript'><!--\n" . " doNumericSlider({$ia[0]}," . ls_json_encode($aJsVar) . ");\n" . " //--></script>";
}
$sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeparator = $sSeparator['separator'];
return array($answer, $inputnames);
}
示例5: ajaxSets
public function ajaxSets()
{
$lid = Yii::app()->getRequest()->getPost('lid');
$answers = Yii::app()->getRequest()->getPost('answers');
$code = Yii::app()->getRequest()->getPost('code');
$aAssessmentValues = Yii::app()->getRequest()->getPost('assessmentvalues', array());
//Create new label set
$language = "";
foreach ($answers as $lang => $answer) {
$language .= $lang . " ";
}
$language = trim($language);
if ($lid == 0) {
$lset = new LabelSet();
$lset->label_name = Yii::app()->getRequest()->getPost('laname');
$lset->languages = $language;
$lset->save();
$lid = getLastInsertID($lset->tableName());
} else {
Label::model()->deleteAll('lid = :lid', array(':lid' => $lid));
}
$res = 'ok';
//optimistic
foreach ($answers as $lang => $answer) {
foreach ($answer as $key => $ans) {
$label = new Label();
$label->lid = $lid;
$label->code = $code[$key];
$label->title = $ans;
$label->sortorder = $key;
$label->language = $lang;
$label->assessment_value = isset($aAssessmentValues[$key]) ? $aAssessmentValues[$key] : 0;
if (!$label->save()) {
$res = 'fail';
}
}
}
echo ls_json_encode($res);
}
示例6: generate_statistics
//.........这里部分代码省略.........
break;
case 'html':
$sOutputHTML .= "<br />\n<table class='statisticssummary' >\n" . "\t<thead><tr><th colspan='2'>" . gT("Results") . "</th></tr></thead>\n" . "\t<tr><th >" . gT("Number of records in this query:") . '</th>' . "<td>{$results}</td></tr>\n" . "\t<tr><th>" . gT("Total records in survey:") . '</th>' . "<td>{$total}</td></tr>\n";
//only calculate percentage if $total is set
if ($total) {
$percent = sprintf("%01.2f", $results / $total * 100);
$sOutputHTML .= "\t<tr><th align='right'>" . gT("Percentage of total:") . '</th>' . "<td>{$percent}%</td></tr>\n";
}
$sOutputHTML .= "</table>\n";
break;
default:
break;
}
//put everything from $selects array into a string connected by AND
//This string ($sql) can then be passed on to other functions so you can
//browse these results
if (isset($selects) && $selects) {
$sql = implode(" AND ", $selects);
} elseif (!empty($newsql)) {
$sql = $newsql;
}
if (!isset($sql) || !$sql) {
$sql = null;
}
//only continue if we have something to output
if ($results > 0) {
if ($outputType == 'html' && $browse === true && Permission::model()->hasSurveyPermission($surveyid, 'responses', 'read')) {
//add a buttons to browse results
$sOutputHTML .= CHtml::form(array("admin/responses/sa/browse/surveyid/{$surveyid}"), 'post', array('target' => '_blank')) . "\n" . "\t\t<p>" . "\t\t\t<input type='submit' value='" . gT("Browse") . "' />\n" . "\t\t\t<input type='hidden' name='sid' value='{$surveyid}' />\n" . "\t\t\t<input type='hidden' name='sql' value=\"{$sql}\" />\n" . "\t\t\t<input type='hidden' name='subaction' value='all' />\n" . "\t\t</p>" . "\t\t</form>\n";
}
}
//end if (results > 0)
/* Show Summary results
* The $summary array contains each fieldname that we want to display statistics for
*
* */
if (isset($summary) && $summary) {
//let's run through the survey
$runthrough = $summary;
//START Chop up fieldname and find matching questions
//loop through all selected questions
foreach ($runthrough as $rt) {
//Step 1: Get information about this response field (SGQA) for the summary
$outputs = $this->buildOutputList($rt, $language, $surveyid, $outputType, $sql, $sLanguageCode);
$sOutputHTML .= $outputs['statisticsoutput'];
//2. Collect and Display results #######################################################################
if (isset($outputs['alist']) && $outputs['alist']) {
$display = $this->displayResults($outputs, $results, $rt, $outputType, $surveyid, $sql, $usegraph, $browse, $sLanguageCode);
$sOutputHTML .= $display['statisticsoutput'];
$aStatisticsData = array_merge($aStatisticsData, $display['astatdata']);
}
//end if -> collect and display results
//Delete Build Outputs data
unset($outputs);
unset($display);
}
// end foreach -> loop through all questions
//output
if ($outputType == 'html') {
$sOutputHTML .= "<br /> \n";
}
}
//end if -> show summary results
switch ($outputType) {
case 'xls':
$this->workbook->close();
if ($pdfOutput == 'F') {
return $sFileName;
} else {
return;
}
break;
case 'pdf':
$this->pdf->lastPage();
if ($pdfOutput == 'F') {
// This is only used by lsrc to send an E-Mail attachment, so it gives back the filename to send and delete afterwards
$tempfilename = $sTempDir . "/Survey_" . $surveyid . ".pdf";
$this->pdf->Output($tempfilename, $pdfOutput);
return $tempfilename;
} else {
return $this->pdf->Output(gT('Survey') . '_' . $surveyid . "_" . $surveyInfo['surveyls_title'] . '.pdf', $pdfOutput);
}
break;
case 'html':
$sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey"));
if ($sGoogleMapsAPIKey != '') {
$sGoogleMapsAPIKey = '&key=' . $sGoogleMapsAPIKey;
}
$sSSL = '';
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") {
$sSSL = 's';
}
$sOutputHTML .= "<script type=\"text/javascript\" src=\"http{$sSSL}://maps.googleapis.com/maps/api/js?sensor=false{$sGoogleMapsAPIKey}\"></script>\n" . "<script type=\"text/javascript\">var site_url='" . Yii::app()->baseUrl . "';var temppath='" . Yii::app()->getConfig("tempurl") . "';var imgpath='" . Yii::app()->getConfig('adminimageurl') . "';var aStatData=" . ls_json_encode($aStatisticsData) . "</script>";
return $sOutputHTML;
break;
default:
return $sOutputHTML;
break;
}
}
示例7: ajaxlabelsetpicker
/**
* This function prepares the data for labelset
*
* @access public
* @return void
*/
public function ajaxlabelsetpicker()
{
$match = (int) returnglobal('match');
$surveyid = returnglobal('sid');
if ($match == 1) {
$language = GetBaseLanguageFromSurveyID($surveyid);
} else {
$language = null;
}
$resultdata = getlabelsets($language);
echo ls_json_encode($resultdata);
}
示例8: editToken
function editToken($iSurveyId)
{
// CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
$bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}');
if (!$bTokenExists) {
self::_newtokentable($iSurveyId);
}
$sOperation = Yii::app()->request->getPost('oper');
if (trim(Yii::app()->request->getPost('validfrom')) == '') {
$from = null;
} else {
$from = date('Y-m-d H:i:s', strtotime(trim($_POST['validfrom'])));
}
if (trim(Yii::app()->request->getPost('validuntil')) == '') {
$until = null;
} else {
$until = date('Y-m-d H:i:s', strtotime(trim($_POST['validuntil'])));
}
// if edit it will update the row
if ($sOperation == 'edit') {
// if (Yii::app()->request->getPost('language') == '')
// {
// $sLang = Yii::app()->session['adminlang'];
// }
// else
// {
// $sLang = Yii::app()->request->getPost('language');
// }
Tokens_dynamic::model($iSurveyId);
echo $from . ',' . $until;
$aData = array('firstname' => Yii::app()->request->getPost('firstname'), 'lastname' => Yii::app()->request->getPost('lastname'), 'email' => Yii::app()->request->getPost('email'), 'emailstatus' => Yii::app()->request->getPost('emailstatus'), 'token' => Yii::app()->request->getPost('token'), 'language' => Yii::app()->request->getPost('language'), 'sent' => Yii::app()->request->getPost('sent'), 'remindersent' => Yii::app()->request->getPost('remindersent'), 'remindercount' => Yii::app()->request->getPost('remindercount'), 'completed' => Yii::app()->request->getPost('completed'), 'usesleft' => Yii::app()->request->getPost('usesleft'), 'validfrom' => $from, 'validuntil' => $until);
$attrfieldnames = Survey::model()->findByPk($iSurveyId)->tokenAttributes;
foreach ($attrfieldnames as $attr_name => $desc) {
$value = Yii::app()->request->getPost($attr_name);
if ($desc['mandatory'] == 'Y' && trim($value) == '') {
$this->getController()->error(sprintf($this->controller->lang->gT('%s cannot be empty'), $desc['description']));
}
$aData[$attr_name] = Yii::app()->request->getPost($attr_name);
}
$token = Tokens_dynamic::model()->find('tid=' . Yii::app()->getRequest()->getPost('id'));
foreach ($aData as $k => $v) {
$token->{$k} = $v;
}
echo $token->update();
} elseif ($sOperation == 'add') {
if (Yii::app()->request->getPost('language') == '') {
$aData = array('firstname' => Yii::app()->request->getPost('firstname'), 'lastname' => Yii::app()->request->getPost('lastname'), 'email' => Yii::app()->request->getPost('email'), 'emailstatus' => Yii::app()->request->getPost('emailstatus'), 'token' => Yii::app()->request->getPost('token'), 'language' => Yii::app()->request->getPost('language'), 'sent' => Yii::app()->request->getPost('sent'), 'remindersent' => Yii::app()->request->getPost('remindersent'), 'remindercount' => Yii::app()->request->getPost('remindercount'), 'completed' => Yii::app()->request->getPost('completed'), 'usesleft' => Yii::app()->request->getPost('usesleft'), 'validfrom' => $from, 'validuntil' => $until);
}
$attrfieldnames = Survey::model()->findByPk($iSurveyId)->tokenAttributes;
foreach ($attrfieldnames as $attr_name => $desc) {
$value = Yii::app()->request->getPost($attr_name);
if ($desc['mandatory'] == 'Y' && trim($value) == '') {
$this->getController()->error(sprintf($clang->gT('%s cannot be empty'), $desc['description']));
}
$aData[$attr_name] = Yii::app()->request->getPost($attr_name);
}
echo ls_json_encode(var_export($aData));
$token = new Tokens_dynamic();
foreach ($aData as $k => $v) {
$token->{$k} = $v;
}
echo $token->save();
} elseif ($sOperation == 'del') {
$_POST['tid'] = Yii::app()->request->getPost('id');
$this->delete($iSurveyId);
}
}
示例9: array
// unlink($randfileloc);
}
}
} else {
// if everything went fine and the file was uploaded successfuly,
// send the file related info back to the client
if ($size > $maxfilesize) {
$return = array("success" => false, "msg" => sprintf($clang->gT("Sorry, this file is too large. Only files up to %s KB are allowed.", 'unescaped'), $maxfilesize));
echo ls_json_encode($return);
} elseif ($iFileUploadTotalSpaceMB > 0 && fCalculateTotalFileUploadUsage() + $size / 1024 / 1024 > $iFileUploadTotalSpaceMB) {
$return = array("success" => false, "msg" => $clang->gT("We are sorry but there was a system error and your file was not saved. An email has been dispatched to notify the survey administrator.", 'unescaped'));
echo ls_json_encode($return);
} elseif (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $randfileloc)) {
$return = array("success" => true, "size" => $size, "name" => rawurlencode(basename($filename)), "ext" => $ext, "filename" => $randfilename, "msg" => $clang->gT("The file has been successfuly uploaded."));
echo ls_json_encode($return);
} else {
// check for upload error
if ($_FILES['uploadfile']['error'] > 2) {
$return = array("success" => false, "msg" => $clang->gT("Sorry, there was an error uploading your file"));
echo ls_json_encode($return);
} else {
if ($_FILES['uploadfile']['error'] == 1 || $_FILES['uploadfile']['error'] == 2 || $size > $maxfilesize) {
$return = array("success" => false, "msg" => sprintf($clang->gT("Sorry, this file is too large. Only files upto %s KB are allowed."), $maxfilesize));
echo ls_json_encode($return);
} else {
$return = array("success" => false, "msg" => $clang->gT("Unknown error"));
echo ls_json_encode($return);
}
}
}
}
示例10: db_table_name
$query = 'select * from ' . db_table_name('labels') . ' where lid=' . $lid . " and language='{$language}' order by sortorder";
$labels = $connect->GetArray($query);
$resultdata[] = array($language => array($labels, getLanguageNameFromCode($language, false)));
}
echo ls_json_encode($resultdata);
}
if ($action == "ajaxlabelsetpicker") {
$match = (int) returnglobal('match');
$surveyid = returnglobal('sid');
if ($match == 1) {
$language = GetBaseLanguageFromSurveyID($surveyid);
} else {
$language = null;
}
$resultdata = getlabelsets($language);
echo ls_json_encode($resultdata);
}
if ($action == "ajaxquestionattributes") {
$thissurvey = getSurveyInfo($surveyid);
$type = returnglobal('question_type');
if (isset($qid)) {
$attributesettings = getQuestionAttributes($qid);
}
$availableattributes = questionAttributes();
if (isset($availableattributes[$type])) {
uasort($availableattributes[$type], 'CategorySort');
$ajaxoutput = '';
$currentfieldset = '';
foreach ($availableattributes[$type] as $qa) {
if (isset($attributesettings[$qa['name']])) {
$value = $attributesettings[$qa['name']];
示例11: beforeQuestionRender
public function beforeQuestionRender()
{
$oEvent = $this->getEvent();
$sQuestionType = $this->get('questiontype', 'Survey', $oEvent->get('surveyId'), $this->get('questiontype', null, null, $this->settings['questiontype']['default']));
$sQuestionName = $this->get('questionname', 'Survey', $oEvent->get('surveyId'), $this->get('questionname'));
if ($sQuestionType == 'default') {
$sQuestionType = $this->get('questiontype', null, null, $this->settings['questiontype']['default']);
}
if ($sQuestionType != "NA" && $oEvent->get('type') == $sQuestionType || $sQuestionName && substr($oEvent->get('code'), -strlen($sQuestionName)) === $sQuestionName) {
$questionClass = $oEvent->get('class');
// Danger with other plugin
$oQuestionBrowser = Question::model()->find("sid=:sid AND qid=:qid", array(':sid' => $oEvent->get('surveyId'), ':qid' => $oEvent->get('qid')));
$sAnswerId = "answer" . $oQuestionBrowser->sid . "X" . $oQuestionBrowser->gid . "X" . $oQuestionBrowser->qid;
//$sScriptFile="//cdn.ckeditor.com/4.4.5/full/ckeditor.js"; // Disallow preview
$sScriptFile = Yii::app()->baseUrl . '/plugins/htmlEditorAnswers/third_party/ckeditor/ckeditor.js';
// Allow preview
Yii::app()->clientScript->registerScriptFile($sScriptFile);
// Some css correction (with asset)
$assetUrl = Yii::app()->assetManager->publish(dirname(__FILE__) . '/assets');
Yii::app()->clientScript->registerCssFile($assetUrl . '/htmleditoranswers.css');
// Call the config (with asset) move it to assets ? In config, seems more clear for dev user.
$assetUrl = Yii::app()->assetManager->publish(dirname(__FILE__) . '/config');
$sConfigFile = $this->get('configfile', 'Survey', $oEvent->get('surveyId'), $this->get('configfile', null, null, $this->settings['configfile']['default']));
if ($sConfigFile == 'default') {
$sConfigFile = $this->get('configfile', null, null, $this->settings['configfile']['default']);
}
$sLangCode = App()->language;
$aCkOptions = array('customConfig' => "{$assetUrl}/{$sConfigFile}.js", 'language' => $sLangCode);
$sCssFile = $this->get('cssfile', 'Survey', $oEvent->get('surveyId'), $this->get('cssfile'));
if ($sCssFile) {
$aCkOptions['contentsCss'] = $sCssFile;
}
$sJsonTag = $this->get('tags', 'Survey', $oEvent->get('surveyId'), $this->get('tags'));
$aTags = json_decode($sJsonTag, true);
$aCkOptionsLang = array();
if (!empty($aTags)) {
$aCkOptions['format_tags'] = implode(";", array_keys($aTags));
foreach ($aTags as $sTag => $aTag) {
if (!empty($aTag['description'])) {
$aCkOptionsLang["tag_{$sTag}"] = $aTag['description'];
}
unset($aTag['description']);
$aCkOptions["format_{$sTag}"] = $aTag;
}
} else {
$aCkOptions['removePlugins'] = 'format';
}
$jsonCkOptions = ls_json_encode($aCkOptions);
$ckeditorScript = "\$('#question{$oEvent->get('qid')} textarea').each(function(e){\n";
$ckeditorScript .= " var textarea = \$(this);";
$ckeditorScript .= " CKEDITOR.replace( this, {$jsonCkOptions} ).on( 'change', function( event ) {\n ";
$ckeditorScript .= " \$(textarea).val( event.editor.getData() ).trigger('keyup'); \n ";
$ckeditorScript .= " });";
if (!empty($aCkOptionsLang)) {
$ckeditorScript .= " CKEDITOR.on( 'instanceReady', function (event ){ \n";
foreach ($aCkOptionsLang as $label => $value) {
$ckeditorScript .= " event.editor.lang.format.{$label}='{$value}';";
}
$ckeditorScript .= " });\n";
}
$ckeditorScript .= "";
$ckeditorScript .= " })\n";
Yii::app()->clientScript->registerScript("ckeditorScript{$sAnswerId}", $ckeditorScript, CClientScript::POS_END);
}
}
示例12: ls_json_encode
{
"ok": <?php
echo $success;
?>
<?php
if (isset($mapdata)) {
echo ",\"mapdata\":" . ls_json_encode($mapdata);
}
?>
<?php
if (isset($chartdata)) {
echo ",\"chartdata\":" . ls_json_encode($chartdata);
}
?>
}
示例13: sanitize_filename
$sFilename = sanitize_filename($_GET['filename']);
$sOriginalFileName = sanitize_filename($_GET['name']);
if (substr($sFilename, 0, 6) == 'futmp_') {
$sFileDir = $tempdir . '/upload/';
} elseif (substr($sFilename, 0, 3) == 'fu_') {
$sFileDir = "{$uploaddir}/surveys/{$surveyid}/files/";
} else {
die('Invalid filename');
}
$sJSON = $_SESSION[$sFieldname];
$aFiles = json_decode(stripslashes($sJSON), true);
if (substr($sFilename, 0, 3) == 'fu_') {
$iFileIndex = 0;
$found = false;
foreach ($aFiles as $aFile) {
if ($aFile['filename'] == $sFilename) {
$found = true;
break;
}
$iFileIndex++;
}
if ($found == true) {
unset($aFiles[$iFileIndex]);
}
$_SESSION[$sFieldname] = ls_json_encode($aFiles);
}
if (@unlink($sFileDir . $sFilename)) {
echo sprintf($clang->gT('File %s deleted'), $sOriginalFileName);
} else {
echo $clang->gT('Oops, There was an error deleting the file');
}
示例14: run
function run($actionID)
{
$surveyid = $_SESSION['LEMsid'];
if (isset($_SESSION['survey_' . $surveyid]['s_lang'])) {
$sLanguage = $_SESSION['survey_' . $surveyid]['s_lang'];
} else {
$sLanguage = '';
}
$clang = SetSurveyLanguage($surveyid, $sLanguage);
$uploaddir = Yii::app()->getConfig("uploaddir");
$tempdir = Yii::app()->getConfig("tempdir");
Yii::app()->loadHelper("database");
$param = $_REQUEST;
if (isset($param['filegetcontents'])) {
$sFileName = $param['filegetcontents'];
if (substr($sFileName, 0, 6) == 'futmp_') {
$sFileDir = $tempdir . '/upload/';
} elseif (substr($sFileName, 0, 3) == 'fu_') {
$sFileDir = "{$uploaddir}/surveys/{$surveyid}/files/";
}
header('Content-Type: ' . CFileHelper::getMimeType($sFileDir . $sFileName));
readfile($sFileDir . $sFileName);
exit;
} elseif (isset($param['delete'])) {
$sFieldname = $param['fieldname'];
$sFilename = sanitize_filename($param['filename']);
$sOriginalFileName = sanitize_filename($param['name']);
if (substr($sFilename, 0, 6) == 'futmp_') {
$sFileDir = $tempdir . '/upload/';
} elseif (substr($sFilename, 0, 3) == 'fu_') {
$sFileDir = "{$uploaddir}/surveys/{$surveyid}/files/";
} else {
die('Invalid filename');
}
if (isset($_SESSION[$sFieldname])) {
$sJSON = $_SESSION[$sFieldname];
$aFiles = json_decode(stripslashes($sJSON), true);
if (substr($sFilename, 0, 3) == 'fu_') {
$iFileIndex = 0;
$found = false;
foreach ($aFiles as $aFile) {
if ($aFile['filename'] == $sFilename) {
$found = true;
break;
}
$iFileIndex++;
}
if ($found == true) {
unset($aFiles[$iFileIndex]);
}
$_SESSION[$sFieldname] = ls_json_encode($aFiles);
}
}
//var_dump($sFileDir.$sFilename);
if (@unlink($sFileDir . $sFilename)) {
echo sprintf($clang->gT('File %s deleted'), $sOriginalFileName);
} else {
echo $clang->gT('Oops, There was an error deleting the file');
}
exit;
}
if (isset($param['mode']) && $param['mode'] == "upload") {
$clang = Yii::app()->lang;
$sTempUploadDir = $tempdir . '/upload/';
// Check if exists and is writable
if (!file_exists($sTempUploadDir)) {
// Try to create
mkdir($sTempUploadDir);
}
$filename = $_FILES['uploadfile']['name'];
$size = 0.001 * $_FILES['uploadfile']['size'];
$valid_extensions = strtolower($_POST['valid_extensions']);
$maxfilesize = (int) $_POST['max_filesize'];
$preview = $_POST['preview'];
$fieldname = $_POST['fieldname'];
$aFieldMap = createFieldMap($surveyid, 'short', false, false, $_SESSION['survey_' . $surveyid]['s_lang']);
if (!isset($aFieldMap[$fieldname])) {
die;
}
$aAttributes = getQuestionAttributeValues($aFieldMap[$fieldname]['qid'], $aFieldMap[$fieldname]['type']);
$valid_extensions_array = explode(",", $aAttributes['allowed_filetypes']);
$valid_extensions_array = array_map('trim', $valid_extensions_array);
$pathinfo = pathinfo($_FILES['uploadfile']['name']);
$ext = $pathinfo['extension'];
$randfilename = 'futmp_' . randomChars(15) . '_' . $pathinfo['extension'];
$randfileloc = $sTempUploadDir . $randfilename;
// check to see that this file type is allowed
// it is also checked at the client side, but jst double checking
if (!in_array(strtolower($ext), $valid_extensions_array)) {
$return = array("success" => false, "msg" => sprintf($clang->gT("Sorry, this file extension (%s) is not allowed!"), $ext));
echo ls_json_encode($return);
exit;
}
// If this is just a preview, don't save the file
if ($preview) {
if ($size > $maxfilesize) {
$return = array("success" => false, "msg" => sprintf($clang->gT("Sorry, this file is too large. Only files upto %s KB are allowed."), $maxfilesize));
echo ls_json_encode($return);
exit;
} else {
//.........这里部分代码省略.........
示例15: ProcessCurrentResponses
//.........这里部分代码省略.........
}
}
$type = $qinfo['info']['type'];
if ($relevant && $grelevant && $sqrelevant || !$LEM->surveyOptions['deletenonvalues']) {
if ($qinfo['info']['hidden'] && !isset($_POST[$sq])) {
$value = isset($_SESSION[$LEM->sessid][$sq]) ? $_SESSION[$LEM->sessid][$sq] : '';
// if always hidden, use the default value, if any
} else {
$value = isset($_POST[$sq]) ? $_POST[$sq] : '';
}
// Check for and adjust ',' and '.' in numbers
$isOnlyNum = isset($LEM->knownVars[$sq]['onlynum']) && $LEM->knownVars[$sq]['onlynum'] == '1';
if ($radixchange && $isOnlyNum) {
// Convert from comma back to decimal
// Also make sure to be able to convert numbers like 1.100,10
$value = preg_replace('|\\.|', '', $value);
$value = preg_replace('|\\,|', '.', $value);
} elseif (!$radixchange && $isOnlyNum) {
// Still have to remove all ',' introduced by the thousand separator
$value = preg_replace('|\\,|', '', $value);
}
switch ($type) {
case 'D':
//DATE
$value = trim($value);
if ($value != "" && $value != "INVALID") {
$aAttributes = $LEM->getQuestionAttributesForEM($LEM->sid, $qid, $_SESSION['LEMlang']);
if (!isset($aAttributes[$qid])) {
$aAttributes[$qid] = array();
}
$aDateFormatData = getDateFormatDataForQID($aAttributes[$qid], $LEM->surveyOptions);
// We don't really validate date here : if date is invalid : return 1999-12-01 00:00
$oDateTimeConverter = new Date_Time_Converter(trim($value), $aDateFormatData['phpdate']);
$newValue = $oDateTimeConverter->convert("Y-m-d H:i");
$oDateTimeConverter = new Date_Time_Converter($newValue, "Y-m-d H:i");
if ($value == $oDateTimeConverter->convert($aDateFormatData['phpdate'])) {
$value = $newValue;
} else {
$value = "";
// Or $value="INVALID" ? : dropdown is OK with this not default.
}
}
break;
# case 'N': //NUMERICAL QUESTION TYPE
# case 'K': //MULTIPLE NUMERICAL QUESTION
# if (trim($value)=="") {
# $value = "";
# }
# else {
# $value = sanitize_float($value);
# }
break;
case '|':
//File Upload
if (!preg_match('/_filecount$/', $sq)) {
$json = $value;
$phparray = json_decode(stripslashes($json));
// if the files have not been saved already,
// move the files from tmp to the files folder
$tmp = $LEM->surveyOptions['tempdir'] . 'upload' . DIRECTORY_SEPARATOR;
if (!is_null($phparray) && count($phparray) > 0) {
// Move the (unmoved, temp) files from temp to files directory.
// Check all possible file uploads
for ($i = 0; $i < count($phparray); $i++) {
if (file_exists($tmp . $phparray[$i]->filename)) {
$sDestinationFileName = 'fu_' . randomChars(15);
if (!is_dir($LEM->surveyOptions['target'])) {
mkdir($LEM->surveyOptions['target'], 0777, true);
}
if (!rename($tmp . $phparray[$i]->filename, $LEM->surveyOptions['target'] . $sDestinationFileName)) {
echo "Error moving file to target destination";
}
$phparray[$i]->filename = $sDestinationFileName;
}
}
$value = ls_json_encode($phparray);
// so that EM doesn't try to parse it.
}
}
break;
}
$_SESSION[$LEM->sessid][$sq] = $value;
$_update = array('type' => $type, 'value' => $value);
$updatedValues[$sq] = $_update;
$LEM->updatedValues[$sq] = $_update;
} else {
// irrelevant, so database will be NULLed separately
// Must unset the value, rather than setting to '', so that EM can re-use the default value as needed.
unset($_SESSION[$LEM->sessid][$sq]);
$_update = array('type' => $type, 'value' => NULL);
$updatedValues[$sq] = $_update;
$LEM->updatedValues[$sq] = $_update;
}
}
}
if (isset($_POST['timerquestion'])) {
$_SESSION[$LEM->sessid][$_POST['timerquestion']] = sanitize_float($_POST[$_POST['timerquestion']]);
}
return $updatedValues;
}