本文整理汇总了PHP中dbQuoteAll函数的典型用法代码示例。如果您正苦于以下问题:PHP dbQuoteAll函数的具体用法?PHP dbQuoteAll怎么用?PHP dbQuoteAll使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dbQuoteAll函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insert
/**
* dataentry::insert()
* insert new dataentry
* @return
*/
public function insert()
{
$subaction = Yii::app()->request->getPost('subaction');
$surveyid = Yii::app()->request->getPost('sid');
$lang = isset($_POST['lang']) ? Yii::app()->request->getPost('lang') : NULL;
$aData = array('surveyid' => $surveyid, 'lang' => $lang);
if (Permission::model()->hasSurveyPermission($surveyid, 'responses', 'create')) {
if ($subaction == "insert" && Permission::model()->hasSurveyPermission($surveyid, 'responses', 'create')) {
$surveytable = "{{survey_{$surveyid}}}";
$thissurvey = getSurveyInfo($surveyid);
$errormsg = "";
Yii::app()->loadHelper("database");
$aViewUrls['display']['menu_bars']['browse'] = gT("Data entry");
$aDataentryoutput = '';
$aDataentrymsgs = array();
$hiddenfields = '';
$lastanswfortoken = '';
// check if a previous answer has been submitted or saved
$rlanguage = '';
if (Yii::app()->request->getPost('token') && Permission::model()->hasSurveyPermission($surveyid, 'tokens', 'update')) {
$tokencompleted = "";
$tcquery = "SELECT completed from {{tokens_{$surveyid}}} WHERE token=" . dbQuoteAll($_POST['token']);
$tcresult = dbExecuteAssoc($tcquery);
$tcresult = $tcresult->readAll();
$tccount = count($tcresult);
foreach ($tcresult as $tcrow) {
$tokencompleted = $tcrow['completed'];
}
if ($tccount < 1) {
// token doesn't exist in token table
$lastanswfortoken = 'UnknownToken';
} elseif ($thissurvey['anonymized'] == "Y") {
// token exist but survey is anonymous, check completed state
if ($tokencompleted != "" && $tokencompleted != "N") {
// token is completed
$lastanswfortoken = 'PrivacyProtected';
}
} else {
// token is valid, survey not anonymous, try to get last recorded response id
$aquery = "SELECT id,startlanguage FROM {$surveytable} WHERE token=" . dbQuoteAll($_POST['token']);
$aresult = dbExecuteAssoc($aquery);
foreach ($aresult->readAll() as $arow) {
if ($tokencompleted != "N") {
$lastanswfortoken = $arow['id'];
}
$rlanguage = $arow['startlanguage'];
}
}
}
// First Check if the survey uses tokens and if a token has been provided
if (tableExists('{{tokens_' . $thissurvey['sid'] . '}}') && !$_POST['token']) {
$errormsg = CHtml::tag('div', array('class' => 'warningheader'), gT("Error"));
$errormsg .= CHtml::tag('p', array(), gT("This is a closed-access survey, so you must supply a valid token. Please contact the administrator for assistance."));
} elseif (tableExists('{{tokens_' . $thissurvey['sid'] . '}}') && $lastanswfortoken == 'UnknownToken') {
$errormsg = CHtml::tag('div', array('class' => 'warningheader'), gT("Error"));
$errormsg .= CHtml::tag('p', array(), gT("The token you have provided is not valid or has already been used."));
} elseif (tableExists('{{tokens_' . $thissurvey['sid'] . '}}') && $lastanswfortoken != '') {
$errormsg = CHtml::tag('div', array('class' => 'warningheader'), gT("Error"));
$errormsg .= CHtml::tag('p', array(), gT("There is already a recorded answer for this token"));
if ($lastanswfortoken != 'PrivacyProtected') {
$errormsg .= "<br /><br />" . gT("Follow the following link to update it") . ":\n";
$errormsg .= CHtml::link("[id:{$lastanswfortoken}]", $this->getController()->createUrl('/admin/dataentry/sa/editdata/subaction/edit/id/' . $lastanswfortoken . '/surveyid/' . $surveyid . '/lang/' . $rlanguage), array('title' => gT("Edit this entry")));
$errormsg .= "<br/><br/>";
} else {
$errormsg .= "<br /><br />" . gT("This surveys uses anonymized responses, so you can't update your response.") . "\n";
}
} else {
$last_db_id = 0;
if (isset($_POST['save']) && $_POST['save'] == "on") {
$aData['save'] = TRUE;
$saver['identifier'] = $_POST['save_identifier'];
$saver['language'] = $_POST['save_language'];
$saver['password'] = $_POST['save_password'];
$saver['passwordconfirm'] = $_POST['save_confirmpassword'];
$saver['email'] = $_POST['save_email'];
if (!returnGlobal('redo')) {
$password = md5($saver['password']);
} else {
$password = $saver['password'];
}
$errormsg = "";
if (!$saver['identifier']) {
$errormsg .= gT("Error") . ": " . gT("You must supply a name for this saved session.");
}
if (!$saver['password']) {
$errormsg .= gT("Error") . ": " . gT("You must supply a password for this saved session.");
}
if ($saver['password'] != $saver['passwordconfirm']) {
$errormsg .= gT("Error") . ": " . gT("Your passwords do not match.");
}
$aData['errormsg'] = $errormsg;
if ($errormsg) {
foreach ($_POST as $key => $val) {
if (substr($key, 0, 4) != "save" && $key != "action" && $key != "sid" && $key != "datestamp" && $key != "ipaddr") {
$hiddenfields .= CHtml::hiddenField($key, $val);
//.........这里部分代码省略.........
示例2: _prepFieldValues
private function _prepFieldValues($fieldnames, $field, $fieldcount, $donotimport)
{
$fieldvalues = explode("\t", str_replace("\n", "", $field), $fieldcount + 1);
// Excel likes to quote fields sometimes. =(
$fieldvalues = preg_replace('/^"(.*)"$/s', '\\1', $fieldvalues);
// Be careful about the order of these arrays:
// lbrace has to be substituted *last*
$fieldvalues = str_replace(array("{newline}", "{cr}", "{tab}", "{quote}", "{lbrace}"), array("\n", "\r", "\t", "\"", "{"), $fieldvalues);
//remove any fields which no longer exist
if (isset($donotimport)) {
foreach ($donotimport as $not) {
unset($fieldvalues[$not]);
}
}
// Sometimes columns with nothing in them get omitted by excel
while (count($fieldnames) > count($fieldvalues)) {
$fieldvalues[] = "";
}
// Sometimes columns with nothing in them get added by excel
while (count($fieldnames) < count($fieldvalues) && trim($fieldvalues[count($fieldvalues) - 1]) == "") {
unset($fieldvalues[count($fieldvalues) - 1]);
}
// Make this safe for DB (*after* we undo first excel's
// and then our escaping).
$fieldvalues = array_map('dbQuoteAll', $fieldvalues);
$fieldvalues = str_replace(dbQuoteAll('{question_not_shown}'), 'NULL', $fieldvalues);
return $fieldvalues;
}
示例3: upgradeTables143
function upgradeTables143()
{
global $modifyoutput;
$aQIDReplacements = array();
$answerquery = "select a.*, q.sid, q.gid from {{answers}} a,{{questions}} q where a.qid=q.qid and q.type in ('L','O','!') and a.default_value='Y'";
$answerresult = Yii::app()->getDb()->createCommand($answerquery)->queryAll();
foreach ($answerresult as $row) {
modifyDatabase("", "INSERT INTO {{defaultvalues}} (qid, scale_id,language,specialtype,defaultvalue) VALUES ({$row['qid']},0," . dbQuoteAll($row['language']) . ",''," . dbQuoteAll($row['code']) . ")");
echo $modifyoutput;
flush();
@ob_flush();
}
// Convert answers to subquestions
$answerquery = "select a.*, q.sid, q.gid, q.type from {{answers}} a,{{questions}} q where a.qid=q.qid and a.language=q.language and q.type in ('1','A','B','C','E','F','H','K',';',':','M','P','Q')";
$answerresult = Yii::app()->getDb()->createCommand($answerquery)->queryAll();
foreach ($answerresult as $row) {
$aInsert = array();
if (isset($aQIDReplacements[$row['qid'] . '_' . $row['code']])) {
$aInsert['qid'] = $aQIDReplacements[$row['qid'] . '_' . $row['code']];
}
$aInsert['sid'] = $row['sid'];
$aInsert['gid'] = $row['gid'];
$aInsert['parent_qid'] = $row['qid'];
$aInsert['type'] = $row['type'];
$aInsert['title'] = $row['code'];
$aInsert['question'] = $row['answer'];
$aInsert['question_order'] = $row['sortorder'];
$aInsert['language'] = $row['language'];
$iLastInsertID = Question::model()->insertRecords($aInsert);
if (!isset($aInsert['qid'])) {
$aQIDReplacements[$row['qid'] . '_' . $row['code']] = $iLastInsertID;
$iSaveSQID = $aQIDReplacements[$row['qid'] . '_' . $row['code']];
} else {
$iSaveSQID = $aInsert['qid'];
}
if (($row['type'] == 'M' || $row['type'] == 'P') && $row['default_value'] == 'Y') {
modifyDatabase("", "INSERT INTO {{defaultvalues}} (qid, sqid, scale_id,language,specialtype,defaultvalue) VALUES ({$row['qid']},{$iSaveSQID},0," . dbQuoteAll($row['language']) . ",'','Y')");
echo $modifyoutput;
flush();
@ob_flush();
}
}
// Sanitize data
if (Yii::app()->db->driverName == 'pgsql') {
modifyDatabase("", "delete from {{answers}} USING {{questions}} WHERE {{answers}}.qid={{questions}}.qid AND {{questions}}.type in ('1','F','H','M','P','W','Z')");
echo $modifyoutput;
flush();
@ob_flush();
} else {
modifyDatabase("", "delete {{answers}} from {{answers}} LEFT join {{questions}} ON {{answers}}.qid={{questions}}.qid where {{questions}}.type in ('1','F','H','M','P','W','Z')");
echo $modifyoutput;
flush();
@ob_flush();
}
// Convert labels to answers
$answerquery = "select qid ,type ,lid ,lid1, language from {{questions}} where parent_qid=0 and type in ('1','F','H','M','P','W','Z')";
$answerresult = Yii::app()->getDb()->createCommand($answerquery)->queryAll();
foreach ($answerresult as $row) {
$labelquery = "Select * from {{labels}} where lid={$row['lid']} and language=" . dbQuoteAll($row['language']);
$labelresult = Yii::app()->getDb()->createCommand($labelquery)->queryAll();
foreach ($labelresult as $lrow) {
modifyDatabase("", "INSERT INTO {{answers}} (qid, code, answer, sortorder, language, assessment_value) VALUES ({$row['qid']}," . dbQuoteAll($lrow['code']) . "," . dbQuoteAll($lrow['title']) . ",{$lrow['sortorder']}," . dbQuoteAll($lrow['language']) . ",{$lrow['assessment_value']})");
echo $modifyoutput;
flush();
@ob_flush();
//$labelids[]
}
if ($row['type'] == '1') {
$labelquery = "Select * from {{labels}} where lid={$row['lid1']} and language=" . dbQuoteAll($row['language']);
$labelresult = Yii::app()->getDb()->createCommand($labelquery)->queryAll();
foreach ($labelresult as $lrow) {
modifyDatabase("", "INSERT INTO {{answers}} (qid, code, answer, sortorder, language, scale_id, assessment_value) VALUES ({$row['qid']}," . dbQuoteAll($lrow['code']) . "," . dbQuoteAll($lrow['title']) . ",{$lrow['sortorder']}," . dbQuoteAll($lrow['language']) . ",1,{$lrow['assessment_value']})");
echo $modifyoutput;
flush();
@ob_flush();
}
}
}
// Convert labels to subquestions
$answerquery = "select * from {{questions}} where parent_qid=0 and type in (';',':')";
$answerresult = Yii::app()->getDb()->createCommand($answerquery)->queryAll();
foreach ($answerresult as $row) {
$labelquery = "Select * from {{labels}} where lid={$row['lid']} and language=" . dbQuoteAll($row['language']);
$labelresult = Yii::app()->getDb()->createCommand($labelquery)->queryAll();
foreach ($labelresult as $lrow) {
$aInsert = array();
if (isset($aQIDReplacements[$row['qid'] . '_' . $lrow['code'] . '_1'])) {
$aInsert['qid'] = $aQIDReplacements[$row['qid'] . '_' . $lrow['code'] . '_1'];
}
$aInsert['sid'] = $row['sid'];
$aInsert['gid'] = $row['gid'];
$aInsert['parent_qid'] = $row['qid'];
$aInsert['type'] = $row['type'];
$aInsert['title'] = $lrow['code'];
$aInsert['question'] = $lrow['title'];
$aInsert['question_order'] = $lrow['sortorder'];
$aInsert['language'] = $lrow['language'];
$aInsert['scale_id'] = 1;
$iLastInsertID = Question::model()->insertRecords($aInsert);
if (isset($aInsert['qid'])) {
//.........这里部分代码省略.........
示例4: doAssessment
/**
* Caculate assessement scores
*
* @param mixed $surveyid
* @param mixed $returndataonly - only returns an array with data
*/
function doAssessment($surveyid, $returndataonly = false)
{
$clang = Yii::app()->lang;
$baselang = Survey::model()->findByPk($surveyid)->language;
if (Survey::model()->findByPk($surveyid)->assessments != "Y") {
return false;
}
$total = 0;
if (!isset($_SESSION['survey_' . $surveyid]['s_lang'])) {
$_SESSION['survey_' . $surveyid]['s_lang'] = $baselang;
}
$query = "SELECT * FROM {{assessments}}\n WHERE sid={$surveyid} and language='" . $_SESSION['survey_' . $surveyid]['s_lang'] . "'\n ORDER BY scope, id";
if ($result = dbExecuteAssoc($query)) {
$aResultSet = $result->readAll();
if (count($aResultSet) > 0) {
foreach ($aResultSet as $row) {
if ($row['scope'] == "G") {
$assessment['group'][$row['gid']][] = array("name" => $row['name'], "min" => $row['minimum'], "max" => $row['maximum'], "message" => $row['message']);
} else {
$assessment['total'][] = array("name" => $row['name'], "min" => $row['minimum'], "max" => $row['maximum'], "message" => $row['message']);
}
}
$fieldmap = createFieldMap($surveyid, "full", false, false, $_SESSION['survey_' . $surveyid]['s_lang']);
$i = 0;
$total = 0;
$groups = array();
foreach ($fieldmap as $field) {
if (in_array($field['type'], array('1', 'F', 'H', 'W', 'Z', 'L', '!', 'M', 'O', 'P'))) {
$fieldmap[$field['fieldname']]['assessment_value'] = 0;
if (isset($_SESSION['survey_' . $surveyid][$field['fieldname']])) {
if ($field['type'] == "M" || $field['type'] == "P") {
if ($_SESSION['survey_' . $surveyid][$field['fieldname']] == "Y") {
$aAttributes = getQuestionAttributeValues($field['qid'], $field['type']);
$fieldmap[$field['fieldname']]['assessment_value'] = (int) $aAttributes['assessment_value'];
$total = $total + (int) $aAttributes['assessment_value'];
}
} else {
$usquery = "SELECT assessment_value FROM {{answers}} where qid=" . $field['qid'] . " and language='{$baselang}' and code=" . dbQuoteAll($_SESSION['survey_' . $surveyid][$field['fieldname']]);
$usresult = dbExecuteAssoc($usquery);
//Checked
if ($usresult) {
$usrow = $usresult->read();
$fieldmap[$field['fieldname']]['assessment_value'] = $usrow['assessment_value'];
$total = $total + $usrow['assessment_value'];
}
}
}
$groups[] = $field['gid'];
}
$i++;
}
$groups = array_unique($groups);
foreach ($groups as $group) {
$grouptotal = 0;
foreach ($fieldmap as $field) {
if ($field['gid'] == $group && isset($field['assessment_value'])) {
//$grouptotal=$grouptotal+$field['answer'];
if (isset($_SESSION['survey_' . $surveyid][$field['fieldname']])) {
$grouptotal = $grouptotal + $field['assessment_value'];
}
}
}
$subtotal[$group] = $grouptotal;
}
}
$assessments = "";
if (isset($subtotal) && is_array($subtotal)) {
foreach ($subtotal as $key => $val) {
if (isset($assessment['group'][$key])) {
foreach ($assessment['group'][$key] as $assessed) {
if ($val >= $assessed['min'] && $val <= $assessed['max'] && $returndataonly === false) {
$assessments .= "\t<!-- GROUP ASSESSMENT: Score: {$val} Min: " . $assessed['min'] . " Max: " . $assessed['max'] . "-->\n <table class='assessments'>\n <tr>\n <th>" . str_replace(array("{PERC}", "{TOTAL}"), array($val, $total), $assessed['name']) . "\n </th>\n </tr>\n <tr>\n <td>" . str_replace(array("{PERC}", "{TOTAL}"), array($val, $total), $assessed['message']) . "\n </td>\n </tr>\n </table><br />\n";
}
}
}
}
}
if (isset($assessment['total'])) {
foreach ($assessment['total'] as $assessed) {
if ($total >= $assessed['min'] && $total <= $assessed['max'] && $returndataonly === false) {
$assessments .= "\t\t\t<!-- TOTAL ASSESSMENT: Score: {$total} Min: " . $assessed['min'] . " Max: " . $assessed['max'] . "-->\n <table class='assessments' align='center'>\n <tr>\n <th>" . str_replace(array("{PERC}", "{TOTAL}"), array($val, $total), stripslashes($assessed['name'])) . "\n </th>\n </tr>\n <tr>\n <td>" . str_replace(array("{PERC}", "{TOTAL}"), array($val, $total), stripslashes($assessed['message'])) . "\n </td>\n </tr>\n </table>\n";
}
}
}
if ($returndataonly == true) {
return array('total' => $total);
} else {
return $assessments;
}
}
}
示例5: tokensExport
function tokensExport($iSurveyID)
{
$sEmailFiter = trim(App()->request->getPost('filteremail'));
$iTokenStatus = App()->request->getPost('tokenstatus');
$iInvitationStatus = App()->request->getPost('invitationstatus');
$iReminderStatus = App()->request->getPost('reminderstatus');
$sTokenLanguage = App()->request->getPost('tokenlanguage');
$oSurvey = Survey::model()->findByPk($iSurveyID);
$bIsNotAnonymous = $oSurvey->anonymized == 'N' && $oSurvey->active == 'Y';
// db table exist (survey_$iSurveyID) ?
$bquery = "SELECT * FROM {{tokens_{$iSurveyID}}} where 1=1";
$databasetype = Yii::app()->db->getDriverName();
if (trim($sEmailFiter) != '') {
if (in_array($databasetype, array('mssql', 'sqlsrv', 'dblib'))) {
$bquery .= ' and CAST(email as varchar) like ' . dbQuoteAll('%' . $_POST['filteremail'] . '%', true);
} else {
$bquery .= ' and email like ' . dbQuoteAll('%' . $_POST['filteremail'] . '%', true);
}
}
if ($_POST['tokenstatus'] == 1) {
$bquery .= " and completed<>'N'";
} elseif ($iTokenStatus == 2) {
$bquery .= " and completed='N'";
} elseif ($iTokenStatus == 3 && $bIsNotAnonymous) {
$bquery .= " and completed='N' and token not in (select token from {{survey_{$iSurveyID}}} group by token)";
} elseif ($iTokenStatus == 4 && $bIsNotAnonymous) {
$bquery .= " and completed='N' and token in (select token from {{survey_{$iSurveyID}}} group by token)";
}
if ($iInvitationStatus == 1) {
$bquery .= " and sent<>'N'";
}
if ($iInvitationStatus == 2) {
$bquery .= " and sent='N'";
}
if ($iReminderStatus == 1) {
$bquery .= " and remindersent<>'N'";
}
if ($iReminderStatus == 2) {
$bquery .= " and remindersent='N'";
}
if ($sTokenLanguage != '') {
$bquery .= " and language=" . dbQuoteAll($sTokenLanguage);
}
$bquery .= " ORDER BY tid";
Yii::app()->loadHelper('database');
$bresult = Yii::app()->db->createCommand($bquery)->query();
//dbExecuteAssoc($bquery) is faster but deprecated!
//HEADERS should be after the above query else timeout errors in case there are lots of tokens!
header("Content-Disposition: attachment; filename=tokens_" . $iSurveyID . ".csv");
header("Content-type: text/comma-separated-values; charset=UTF-8");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: cache");
// Export UTF8 WITH BOM
$tokenoutput = chr(hexdec('EF')) . chr(hexdec('BB')) . chr(hexdec('BF'));
$tokenoutput .= "tid,firstname,lastname,email,emailstatus,token,language,validfrom,validuntil,invited,reminded,remindercount,completed,usesleft";
$attrfieldnames = getAttributeFieldNames($iSurveyID);
$attrfielddescr = getTokenFieldsAndNames($iSurveyID, true);
foreach ($attrfieldnames as $attr_name) {
$tokenoutput .= ", {$attr_name}";
if (isset($attrfielddescr[$attr_name])) {
$tokenoutput .= " <" . str_replace(",", " ", $attrfielddescr[$attr_name]['description']) . ">";
}
}
$tokenoutput .= "\n";
echo $tokenoutput;
$tokenoutput = "";
// Export token line by line and fill $aExportedTokens with token exported
Yii::import('application.libraries.Date_Time_Converter', true);
$aExportedTokens = array();
while ($brow = $bresult->read()) {
if (trim($brow['validfrom'] != '')) {
$datetimeobj = new Date_Time_Converter($brow['validfrom'], "Y-m-d H:i:s");
$brow['validfrom'] = $datetimeobj->convert('Y-m-d H:i');
}
if (trim($brow['validuntil'] != '')) {
$datetimeobj = new Date_Time_Converter($brow['validuntil'], "Y-m-d H:i:s");
$brow['validuntil'] = $datetimeobj->convert('Y-m-d H:i');
}
$tokenoutput .= '"' . trim($brow['tid']) . '",';
$tokenoutput .= '"' . trim($brow['firstname']) . '",';
$tokenoutput .= '"' . trim($brow['lastname']) . '",';
$tokenoutput .= '"' . trim($brow['email']) . '",';
$tokenoutput .= '"' . trim($brow['emailstatus']) . '",';
$tokenoutput .= '"' . trim($brow['token']) . '",';
$tokenoutput .= '"' . trim($brow['language']) . '",';
$tokenoutput .= '"' . trim($brow['validfrom']) . '",';
$tokenoutput .= '"' . trim($brow['validuntil']) . '",';
$tokenoutput .= '"' . trim($brow['sent']) . '",';
$tokenoutput .= '"' . trim($brow['remindersent']) . '",';
$tokenoutput .= '"' . trim($brow['remindercount']) . '",';
$tokenoutput .= '"' . trim($brow['completed']) . '",';
$tokenoutput .= '"' . trim($brow['usesleft']) . '",';
foreach ($attrfieldnames as $attr_name) {
$tokenoutput .= '"' . trim($brow[$attr_name]) . '",';
}
$tokenoutput = substr($tokenoutput, 0, -1);
// remove last comma
$tokenoutput .= "\n";
echo $tokenoutput;
$tokenoutput = '';
//.........这里部分代码省略.........
示例6: buildSelects
//.........这里部分代码省略.........
//we collect all the to be selected data in this array
$selects[] = $thisquestion;
} elseif ($firstletter == "M" || $firstletter == "P") {
$mselects = array();
//create a list out of the $pv array
list($lsid, $lgid, $lqid) = explode("X", $pv);
$aresult = Question::model()->findAll(array('order' => 'question_order', 'condition' => 'parent_qid=:parent_qid AND scale_id=0', 'params' => array(":parent_qid" => $lqid)));
foreach ($aresult as $arow) {
// only add condition if answer has been chosen
if (in_array($arow['title'], $_POST[$pv])) {
$mselects[] = Yii::app()->db->quoteColumnName(substr($pv, 1, strlen($pv)) . $arow['title']) . " = 'Y'";
}
}
/* If there are mutliple conditions generated from this multiple choice question, join them using the boolean "OR" */
if ($mselects) {
$thismulti = implode(" OR ", $mselects);
$selects[] = "({$thismulti})";
unset($mselects);
}
} elseif ($firstletter == "N" || $firstletter == "K") {
//value greater than
if (substr($pv, strlen($pv) - 1, 1) == "G" && $_POST[$pv] != "") {
$selects[] = Yii::app()->db->quoteColumnName(substr($pv, 1, -1)) . " > " . sanitize_int($_POST[$pv]);
}
//value less than
if (substr($pv, strlen($pv) - 1, 1) == "L" && $_POST[$pv] != "") {
$selects[] = Yii::app()->db->quoteColumnName(substr($pv, 1, -1)) . " < " . sanitize_int($_POST[$pv]);
}
} else {
if ($firstletter == "|") {
// no. of files greater than
if (substr($pv, strlen($pv) - 1, 1) == "G" && $_POST[$pv] != "") {
$selects[] = Yii::app()->db->quoteColumnName(substr($pv, 1, -1) . "_filecount") . " > " . sanitize_int($_POST[$pv]);
}
// no. of files less than
if (substr($pv, strlen($pv) - 1, 1) == "L" && $_POST[$pv] != "") {
$selects[] = Yii::app()->db->quoteColumnName(substr($pv, 1, -1) . "_filecount") . " < " . sanitize_int($_POST[$pv]);
}
} elseif (substr($pv, 0, 2) == "id") {
if (substr($pv, strlen($pv) - 1, 1) == "G" && $_POST[$pv] != "") {
$selects[] = Yii::app()->db->quoteColumnName(substr($pv, 0, -1)) . " > " . sanitize_int($_POST[$pv]);
}
if (substr($pv, strlen($pv) - 1, 1) == "L" && $_POST[$pv] != "") {
$selects[] = Yii::app()->db->quoteColumnName(substr($pv, 0, -1)) . " < " . sanitize_int($_POST[$pv]);
}
} elseif (($firstletter == "T" || $firstletter == "Q") && $_POST[$pv] != "") {
$selectSubs = array();
//We intepret and * and % as wildcard matches, and use ' OR ' and , as the separators
$pvParts = explode(",", str_replace('*', '%', str_replace(' OR ', ',', $_POST[$pv])));
if (is_array($pvParts) and count($pvParts)) {
foreach ($pvParts as $pvPart) {
$selectSubs[] = Yii::app()->db->quoteColumnName(substr($pv, 1, strlen($pv))) . " LIKE '" . trim($pvPart) . "'";
}
if (count($selectSubs)) {
$selects[] = ' (' . implode(' OR ', $selectSubs) . ') ';
}
}
} elseif ($firstletter == "D" && $_POST[$pv] != "") {
//Date equals
if (substr($pv, -2) == "eq") {
$selects[] = Yii::app()->db->quoteColumnName(substr($pv, 1, strlen($pv) - 3)) . " = " . dbQuoteAll($_POST[$pv]);
} else {
//date less than
if (substr($pv, -4) == "less") {
$selects[] = Yii::app()->db->quoteColumnName(substr($pv, 1, strlen($pv) - 5)) . " >= " . dbQuoteAll($_POST[$pv]);
}
//date greater than
if (substr($pv, -4) == "more") {
$selects[] = Yii::app()->db->quoteColumnName(substr($pv, 1, strlen($pv) - 5)) . " <= " . dbQuoteAll($_POST[$pv]);
}
}
} elseif (substr($pv, 0, 9) == "datestamp") {
//timestamp equals
$formatdata = getDateFormatData(Yii::app()->session['dateformat']);
if (substr($pv, -1, 1) == "E" && !empty($_POST[$pv])) {
$datetimeobj = new Date_Time_Converter($_POST[$pv], $formatdata['phpdate'] . ' H:i');
$sDateValue = $datetimeobj->convert("Y-m-d");
$selects[] = Yii::app()->db->quoteColumnName('datestamp') . " >= " . dbQuoteAll($sDateValue . " 00:00:00") . " and " . Yii::app()->db->quoteColumnName('datestamp') . " <= " . dbQuoteAll($sDateValue . " 23:59:59");
} else {
//timestamp less than
if (substr($pv, -1, 1) == "L" && !empty($_POST[$pv])) {
$datetimeobj = new Date_Time_Converter($_POST[$pv], $formatdata['phpdate'] . ' H:i');
$sDateValue = $datetimeobj->convert("Y-m-d H:i:s");
$selects[] = Yii::app()->db->quoteColumnName('datestamp') . " < " . dbQuoteAll($sDateValue);
}
//timestamp greater than
if (substr($pv, -1, 1) == "G" && !empty($_POST[$pv])) {
$datetimeobj = new Date_Time_Converter($_POST[$pv], $formatdata['phpdate'] . ' H:i');
$sDateValue = $datetimeobj->convert("Y-m-d H:i:s");
$selects[] = Yii::app()->db->quoteColumnName('datestamp') . " > " . dbQuoteAll($sDateValue);
}
}
}
}
}
}
}
//end foreach -> loop through filter options to create SQL
return $selects;
}
示例7: _UpdateValuesInDatabase
/**
* Write values to database.
* @param <type> $updatedValues
* @param <boolean> $finished - true if the survey needs to be finalized
*/
private function _UpdateValuesInDatabase($updatedValues, $finished = false)
{
// TODO - now that using $this->updatedValues, may be able to remove local copies of it (unless needed by other sub-systems)
$updatedValues = $this->updatedValues;
$message = '';
if (!$this->surveyOptions['active'] || $this->sPreviewMode) {
return $message;
}
if (!isset($_SESSION[$this->sessid]['srid'])) {
$_SESSION[$this->sessid]['datestamp'] = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $this->surveyOptions['timeadjust']);
// Create initial insert row for this record
$today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $this->surveyOptions['timeadjust']);
$sdata = array("startlanguage" => $this->surveyOptions['startlanguage']);
if ($this->surveyOptions['anonymized'] == false) {
$sdata['token'] = $this->surveyOptions['token'];
}
if ($this->surveyOptions['datestamp'] == true) {
$sdata['datestamp'] = $_SESSION[$this->sessid]['datestamp'];
$sdata['startdate'] = $_SESSION[$this->sessid]['datestamp'];
}
if ($this->surveyOptions['ipaddr'] == true) {
$sdata['ipaddr'] = getIPAddress();
}
if ($this->surveyOptions['refurl'] == true) {
if (isset($_SESSION[$this->sessid]['refurl'])) {
$sdata['refurl'] = $_SESSION[$this->sessid]['refurl'];
} else {
$sdata['refurl'] = getenv("HTTP_REFERER");
}
}
$sdata = array_filter($sdata);
SurveyDynamic::sid($this->sid);
$oSurvey = new SurveyDynamic();
$iNewID = $oSurvey->insertRecords($sdata);
if ($iNewID) {
$srid = $iNewID;
$_SESSION[$this->sessid]['srid'] = $iNewID;
} else {
$message .= $this->gT("Unable to insert record into survey table");
// TODO - add SQL error?
echo submitfailed('');
// TODO - report SQL error?
}
//Insert Row for Timings, if needed
if ($this->surveyOptions['savetimings']) {
SurveyTimingDynamic::sid($this->sid);
$oSurveyTimings = new SurveyTimingDynamic();
$tdata = array('id' => $srid, 'interviewtime' => 0);
switchMSSQLIdentityInsert("survey_{$this->sid}_timings", true);
$iNewID = $oSurveyTimings->insertRecords($tdata);
switchMSSQLIdentityInsert("survey_{$this->sid}_timings", false);
}
}
if (count($updatedValues) > 0 || $finished) {
$query = 'UPDATE ' . $this->surveyOptions['tablename'] . ' SET ';
$setter = array();
switch ($this->surveyMode) {
case 'question':
$thisstep = $this->currentQuestionSeq;
break;
case 'group':
$thisstep = $this->currentGroupSeq;
break;
case 'survey':
$thisstep = 1;
break;
}
$setter[] = dbQuoteID('lastpage') . "=" . dbQuoteAll($thisstep);
if ($this->surveyOptions['datestamp'] && isset($_SESSION[$this->sessid]['datestamp'])) {
$_SESSION[$this->sessid]['datestamp'] = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $this->surveyOptions['timeadjust']);
$setter[] = dbQuoteID('datestamp') . "=" . dbQuoteAll(dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $this->surveyOptions['timeadjust']));
}
if ($this->surveyOptions['ipaddr']) {
$setter[] = dbQuoteID('ipaddr') . "=" . dbQuoteAll(getIPAddress());
}
foreach ($updatedValues as $key => $value) {
$val = is_null($value) ? NULL : $value['value'];
$type = is_null($value) ? NULL : $value['type'];
// Clean up the values to cope with database storage requirements
switch ($type) {
case 'D':
//DATE
if (trim($val) == '' || $val == "INVALID") {
$val = NULL;
// since some databases can't store blanks in date fields
}
// otherwise will already be in yyyy-mm-dd format after ProcessCurrentResponses()
break;
case '|':
//File upload
// This block can be removed once we require 5.3 or later
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
$val = addslashes($val);
}
break;
//.........这里部分代码省略.........