• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP switchMSSQLIdentityInsert函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中switchMSSQLIdentityInsert函数的典型用法代码示例。如果您正苦于以下问题:PHP switchMSSQLIdentityInsert函数的具体用法?PHP switchMSSQLIdentityInsert怎么用?PHP switchMSSQLIdentityInsert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了switchMSSQLIdentityInsert函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: TSVImportSurvey


//.........这里部分代码省略.........
    // these aren't used here, but are needed to avoid errors in post-import display
    $results['assessments'] = 0;
    $results['quota'] = 0;
    $results['quotamembers'] = 0;
    $results['quotals'] = 0;
    // collect information about survey and its language settings
    $surveyinfo = array();
    $surveyls = array();
    foreach ($adata as $row) {
        switch ($row['class']) {
            case 'S':
                if (isset($row['text']) && $row['name'] != 'datecreated') {
                    $surveyinfo[$row['name']] = $row['text'];
                }
                break;
            case 'SL':
                if (!isset($surveyls[$row['language']])) {
                    $surveyls[$row['language']] = array();
                }
                if (isset($row['text'])) {
                    $surveyls[$row['language']][$row['name']] = $row['text'];
                }
                break;
        }
    }
    $iOldSID = 1;
    if (isset($surveyinfo['sid'])) {
        $iOldSID = (int) $surveyinfo['sid'];
    }
    // Create the survey entry
    $surveyinfo['startdate'] = NULL;
    $surveyinfo['active'] = 'N';
    // unset($surveyinfo['datecreated']);
    switchMSSQLIdentityInsert('surveys', true);
    $iNewSID = Survey::model()->insertNewSurvey($surveyinfo);
    //or safeDie($clang->gT("Error").": Failed to insert survey<br />");
    if ($iNewSID == false) {
        $results['error'] = Survey::model()->getErrors();
        $results['bFailed'] = true;
        return $results;
    }
    $surveyinfo['sid'] = $iNewSID;
    $results['surveys']++;
    switchMSSQLIdentityInsert('surveys', false);
    $results['newsid'] = $iNewSID;
    $gid = 0;
    $gseq = 0;
    // group_order
    $qid = 0;
    $qseq = 0;
    // question_order
    $qtype = 'T';
    $aseq = 0;
    // answer sortorder
    // set the language for the survey
    $_title = 'Missing Title';
    foreach ($surveyls as $_lang => $insertdata) {
        $insertdata['surveyls_survey_id'] = $iNewSID;
        $insertdata['surveyls_language'] = $_lang;
        if (isset($insertdata['surveyls_title'])) {
            $_title = $insertdata['surveyls_title'];
        } else {
            $insertdata['surveyls_title'] = $_title;
        }
        $result = Surveys_languagesettings::model()->insertNewSurvey($insertdata);
        //
开发者ID:rawaludin,项目名称:LimeSurvey,代码行数:67,代码来源:import_helper.php


示例2: _handleFileUpload

 private function _handleFileUpload($surveyid, $aData)
 {
     $vvoutput = '';
     $donotimport = array();
     $clang = $this->getController()->lang;
     $filePath = $this->_moveUploadedFile($aData);
     $aFileContents = $this->_readFile($filePath);
     unlink($filePath);
     //delete the uploaded file
     unset($aFileContents[0]);
     //delete the first line
     Survey_dynamic::sid($surveyid);
     $survey = new Survey_dynamic();
     list($aFieldnames, $nbOfFields) = $this->_getFieldInfo($aFileContents);
     $aRealFieldNames = Yii::app()->db->getSchema()->getTable($survey->tableName())->getColumnNames();
     if (Yii::app()->request->getPost('noid') == "noid") {
         unset($aRealFieldNames[0]);
     }
     if (Yii::app()->request->getPost('finalized') == "notfinalized") {
         unset($aRealFieldNames[1]);
     }
     unset($aFileContents[1]);
     //delete the second line
     //See if any fields in the import file don't exist in the active survey
     $missing = array_diff($aFieldnames, $aRealFieldNames);
     if (is_array($missing) && count($missing) > 0) {
         foreach ($missing as $key => $val) {
             $donotimport[] = $key;
             unset($aFieldnames[$key]);
         }
     }
     if (Yii::app()->request->getPost('finalized') == "notfinalized") {
         $donotimport[] = 1;
         unset($aFieldnames[1]);
     }
     $importcount = 0;
     $recordcount = 0;
     $aFieldnames = array_map('dbQuoteID', $aFieldnames);
     // Find out which fields are datefields, these have to be null if the imported string is empty
     $fieldmap = createFieldMap($surveyid, 'full', false, false, getBaseLanguageFromSurveyID($surveyid));
     $datefields = array();
     $numericfields = array();
     foreach ($fieldmap as $field) {
         if ($field['type'] == 'D') {
             $datefields[] = $field['fieldname'];
         }
         if ($field['type'] == 'N' || $field['type'] == 'K') {
             $numericfields[] = $field['fieldname'];
         }
     }
     foreach ($aFileContents as $row) {
         if (trim($row) != "") {
             $recordcount++;
             $fieldvalues = $this->_prepFieldValues($aFieldnames, $row, $nbOfFields, $donotimport);
             $fielddata = $aFieldnames === array() && $fieldvalues === array() ? array() : array_combine($aFieldnames, $fieldvalues);
             foreach ($datefields as $datefield) {
                 if (@$fielddata["'" . $datefield . "'"] == '') {
                     unset($fielddata["'" . $datefield . "'"]);
                 }
             }
             foreach ($numericfields as $numericfield) {
                 if ($fielddata["`" . $numericfield . "`"] == '') {
                     unset($fielddata["`" . $numericfield . "`"]);
                 }
             }
             if (isset($fielddata['`submitdate`']) && $fielddata['`submitdate`'] == 'NULL') {
                 unset($fielddata['`submitdate`']);
             }
             if ($fielddata['`lastpage`'] == '') {
                 $fielddata['`lastpage`'] = '0';
             }
             $recordexists = false;
             if (isset($fielddata['`id`'])) {
                 $result = $survey->findAllByAttributes(array('id' => $fielddata['`id`']));
                 $recordexists = $result > 0;
                 // Check if record with same id exists
                 if ($recordexists) {
                     if (Yii::app()->request->getPost('insert') == "ignore") {
                         $aData['msgs'][] .= sprintf($clang->gT("Record ID %s was skipped because of duplicate ID."), $fielddata['`id`']);
                         continue;
                     }
                     if (Yii::app()->request->getPost('insert') == "replace") {
                         $result = $survey->deleteSomeRecords(array('id' => $fielddata['`id`']));
                         $recordexists = false;
                     }
                 }
             }
             if (Yii::app()->request->getPost('insert') == "renumber") {
                 unset($fielddata['`id`']);
             }
             if (isset($fielddata['`id`'])) {
                 switchMSSQLIdentityInsert("survey_{$surveyid}", true);
             }
             $result = $survey->insertRecords($fielddata);
             if (isset($fielddata['id'])) {
                 switchMSSQLIdentityInsert("survey_{$surveyid}", false);
             }
             if (!$result) {
                 $aData['error_msg'] = sprintf($clang->gT("Import failed on record %d"), $recordcount);
                 $this->_renderWrappedTemplate('dataentry', 'warning_header', $aData);
//.........这里部分代码省略.........
开发者ID:rawaludin,项目名称:LimeSurvey,代码行数:101,代码来源:dataentry.php


示例3: XMLImportTimings

function XMLImportTimings($sFullFilePath, $iSurveyID, $aFieldReMap = array())
{
    Yii::app()->loadHelper('database');
    $clang = Yii::app()->lang;
    $sXMLdata = file_get_contents($sFullFilePath);
    $xml = simplexml_load_string($sXMLdata, 'SimpleXMLElement', LIBXML_NONET);
    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);
    // 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($clang->gT("Error") . ": Failed to insert data[17]<br />");
        $results['responses']++;
    }
    switchMSSQLIdentityInsert('survey_' . $iSurveyID . '_timings', false);
    return $results;
}
开发者ID:rouben,项目名称:LimeSurvey,代码行数:38,代码来源:import_helper.php


示例4: fixLanguageConsistency

/**
* fixLanguageConsistency() fixes missing groups, questions, answers, quotas & assessments for languages on a survey
* @param string $sid - the currently selected survey
* @param string $availlangs - space separated list of additional languages in survey - if empty all additional languages of a survey are checked against the base language
* @return bool - always returns true
*/
function fixLanguageConsistency($sid, $availlangs = '')
{
    $sid = sanitize_int($sid);
    if (trim($availlangs) != '') {
        $availlangs = sanitize_languagecodeS($availlangs);
        $langs = explode(" ", $availlangs);
        if ($langs[count($langs) - 1] == "") {
            array_pop($langs);
        }
    } else {
        $langs = Survey::model()->findByPk($sid)->additionalLanguages;
    }
    if (count($langs) == 0) {
        return true;
    }
    // Survey only has one language
    $baselang = Survey::model()->findByPk($sid)->language;
    $query = "SELECT * FROM {{groups}} WHERE sid='{$sid}' AND language='{$baselang}'  ORDER BY group_order";
    $result = Yii::app()->db->createCommand($query)->query();
    foreach ($result->readAll() as $group) {
        foreach ($langs as $lang) {
            $query = "SELECT count(gid) FROM {{groups}} WHERE sid='{$sid}' AND gid='{$group['gid']}' AND language='{$lang}'";
            $gresult = Yii::app()->db->createCommand($query)->queryScalar();
            if ($gresult < 1) {
                $data = array('gid' => $group['gid'], 'sid' => $group['sid'], 'group_name' => $group['group_name'], 'group_order' => $group['group_order'], 'description' => $group['description'], 'randomization_group' => $group['randomization_group'], 'grelevance' => $group['grelevance'], 'language' => $lang);
                switchMSSQLIdentityInsert('groups', true);
                Yii::app()->db->createCommand()->insert('{{groups}}', $data);
                switchMSSQLIdentityInsert('groups', false);
            }
        }
        reset($langs);
    }
    $quests = array();
    $query = "SELECT * FROM {{questions}} WHERE sid='{$sid}' AND language='{$baselang}' ORDER BY question_order";
    $result = Yii::app()->db->createCommand($query)->query()->readAll();
    if (count($result) > 0) {
        foreach ($result as $question) {
            array_push($quests, $question['qid']);
            foreach ($langs as $lang) {
                $query = "SELECT count(qid) FROM {{questions}} WHERE sid='{$sid}' AND qid='{$question['qid']}' AND language='{$lang}' AND scale_id={$question['scale_id']}";
                $gresult = Yii::app()->db->createCommand($query)->queryScalar();
                if ($gresult < 1) {
                    switchMSSQLIdentityInsert('questions', true);
                    $data = array('qid' => $question['qid'], 'sid' => $question['sid'], 'gid' => $question['gid'], 'type' => $question['type'], 'title' => $question['title'], 'question' => $question['question'], 'preg' => $question['preg'], 'help' => $question['help'], 'other' => $question['other'], 'mandatory' => $question['mandatory'], 'question_order' => $question['question_order'], 'language' => $lang, 'scale_id' => $question['scale_id'], 'parent_qid' => $question['parent_qid'], 'relevance' => $question['relevance']);
                    Yii::app()->db->createCommand()->insert('{{questions}}', $data);
                }
            }
            reset($langs);
        }
        $sqlans = "";
        foreach ($quests as $quest) {
            $sqlans .= " OR qid = '" . $quest . "' ";
        }
        $query = "SELECT * FROM {{answers}} WHERE language='{$baselang}' and (" . trim($sqlans, ' OR') . ") ORDER BY qid, code";
        $result = Yii::app()->db->createCommand($query)->query();
        foreach ($result->readAll() as $answer) {
            foreach ($langs as $lang) {
                $query = "SELECT count(qid) FROM {{answers}} WHERE code='{$answer['code']}' AND qid='{$answer['qid']}' AND language='{$lang}' AND scale_id={$answer['scale_id']}";
                $gresult = Yii::app()->db->createCommand($query)->queryScalar();
                if ($gresult < 1) {
                    $data = array('qid' => $answer['qid'], 'code' => $answer['code'], 'answer' => $answer['answer'], 'scale_id' => $answer['scale_id'], 'sortorder' => $answer['sortorder'], 'language' => $lang, 'assessment_value' => $answer['assessment_value']);
                    Yii::app()->db->createCommand()->insert('{{answers}}', $data);
                }
            }
            reset($langs);
        }
    }
    $query = "SELECT * FROM {{assessments}} WHERE sid='{$sid}' AND language='{$baselang}'";
    $result = Yii::app()->db->createCommand($query)->query();
    foreach ($result->readAll() as $assessment) {
        foreach ($langs as $lang) {
            $query = "SELECT count(id) FROM {{assessments}} WHERE sid='{$sid}' AND id='{$assessment['id']}' AND language='{$lang}'";
            $gresult = Yii::app()->db->createCommand($query)->queryScalar();
            if ($gresult < 1) {
                $data = array('id' => $assessment['id'], 'sid' => $assessment['sid'], 'scope' => $assessment['scope'], 'gid' => $assessment['gid'], 'name' => $assessment['name'], 'minimum' => $assessment['minimum'], 'maximum' => $assessment['maximum'], 'message' => $assessment['message'], 'language' => $lang);
                Yii::app()->db->createCommand()->insert('{{assessments}}', $data);
            }
        }
        reset($langs);
    }
    $query = "SELECT * FROM {{quota_languagesettings}} join {{quota}} q on quotals_quota_id=q.id WHERE q.sid='{$sid}' AND quotals_language='{$baselang}'";
    $result = Yii::app()->db->createCommand($query)->query();
    foreach ($result->readAll() as $qls) {
        foreach ($langs as $lang) {
            $query = "SELECT count(quotals_id) FROM {{quota_languagesettings}} WHERE quotals_quota_id='{$qls['quotals_quota_id']}' AND quotals_language='{$lang}'";
            $gresult = Yii::app()->db->createCommand($query)->queryScalar();
            if ($gresult < 1) {
                $data = array('quotals_quota_id' => $qls['quotals_quota_id'], 'quotals_name' => $qls['quotals_name'], 'quotals_message' => $qls['quotals_message'], 'quotals_url' => $qls['quotals_url'], 'quotals_urldescrip' => $qls['quotals_urldescrip'], 'quotals_language' => $lang);
                Yii::app()->db->createCommand()->insert('{{quota_languagesettings}}', $data);
            }
        }
        reset($langs);
    }
    return true;
//.........这里部分代码省略.........
开发者ID:GuillaumeSmaha,项目名称:LimeSurvey,代码行数:101,代码来源:common_helper.php


示例5: _editsubquestion

 /**
  * Load only subquestion specific screen only.
  *
  * @access public
  * @param int $surveyid
  * @param int $gid
  * @param int $qid
  * @return void
  */
 public function _editsubquestion($surveyid, $gid, $qid)
 {
     $surveyid = sanitize_int($surveyid);
     $qid = sanitize_int($qid);
     $gid = sanitize_int($gid);
     $clang = $this->getController()->lang;
     // Get languages select on survey.
     $anslangs = Survey::model()->findByPk($surveyid)->additionalLanguages;
     $baselang = Survey::model()->findByPk($surveyid)->language;
     $resultrow = Questions::model()->findByPk(array('qid' => $qid, 'language' => $baselang))->attributes;
     $sQuestiontype = $resultrow['type'];
     $aQuestiontypeInfo = getQuestionTypeList($sQuestiontype, 'array');
     $iScaleCount = $aQuestiontypeInfo[$sQuestiontype]['subquestions'];
     for ($iScale = 0; $iScale < $iScaleCount; $iScale++) {
         $subquestiondata = Questions::model()->findAllByAttributes(array('parent_qid' => $qid, 'language' => $baselang, 'scale_id' => $iScale));
         if (empty($subquestiondata)) {
             //Questions::model()->insert();
             $data = array('sid' => $surveyid, 'gid' => $gid, 'parent_qid' => $qid, 'title' => 'SQ001', 'question' => $clang->gT('Some example subquestion'), 'question_order' => 1, 'language' => $baselang, 'scale_id' => $iScale);
             Questions::model()->insertRecords($data);
             $subquestiondata = Questions::model()->findAllByAttributes(array('parent_qid' => $qid, 'language' => $baselang, 'scale_id' => $iScale));
         }
         // Check that there are subquestions for every language supported by the survey
         foreach ($anslangs as $language) {
             foreach ($subquestiondata as $row) {
                 $qrow = Questions::model()->count('
                 parent_qid = :qid AND
                 language = :language AND
                 qid = ' . $row->qid . ' AND
                 scale_id = :iScale', array(':qid' => $qid, ':language' => $language, ':iScale' => $iScale));
                 // Means that no record for the language exists in the questions table
                 if (empty($qrow)) {
                     switchMSSQLIdentityInsert('questions', true);
                     $question = new Questions();
                     $question->qid = $row->qid;
                     $question->sid = $surveyid;
                     $question->gid = $row->gid;
                     $question->parent_qid = $qid;
                     $question->title = $row->title;
                     $question->question = $row->question;
                     $question->question_order = $row->question_order;
                     $question->language = $language;
                     $question->scale_id = $iScale;
                     $question->save();
                     /** //activerecord is not not new bugfix!
                         Questions::model()->insert(array(
                         'qid' => $row->qid,
                         'sid' => $surveyid,
                         'gid' => $row->gid,
                         'parent_qid' => $qid,
                         'title' => $row->title,
                         'question' => $row->question,
                         'question_order' => $row->question_order,
                         'language' => $language,
                         'scale_id' => $iScale,
                         ));
                         */
                     switchMSSQLIdentityInsert('questions', false);
                 }
             }
         }
     }
     array_unshift($anslangs, $baselang);
     // Delete the subquestions in languages not supported by the survey
     $criteria = new CDbCriteria();
     $criteria->addColumnCondition(array('parent_qid' => $qid));
     $criteria->addNotInCondition('language', $anslangs);
     Questions::model()->deleteAll($criteria);
     // Check sort order for subquestions
     $qresult = Questions::model()->findByAttributes(array('qid' => $qid, 'language' => $baselang));
     if (!is_null($qresult)) {
         $qtype = $qresult->type;
     }
     if (!empty($_POST['ansaction'])) {
         // Check if any nulls exist. If they do, redo the sortorders
         $cacount = Questions::model()->count(array('parent_qid' => $qid, 'question_order' => null, 'language' => $baselang));
         if ($cacount) {
             Answers::model()->updateSortOrder($qid, Survey::model()->findByPk($surveyid)->language);
         }
     }
     Yii::app()->loadHelper('admin/htmleditor');
     // Print Key Control JavaScript
     $result = Questions::model()->findAllBYAttributes(array('parent_qid' => $qid, 'language' => Survey::model()->findByPk($surveyid)->language), array('order' => 'question_order desc'));
     $aData['anscount'] = $anscount = count($result);
     $row = $result[0]->attributes;
     $aData['row'] = $row;
     $maxsortorder = $row['question_order'] + 1;
     /**
      * The following line decides if the assessment input fields are visible or not
      * for some question types the assessment values is set in the label set instead of the answers
      */
     $qtypes = getQuestionTypeList('', 'array');
//.........这里部分代码省略.........
开发者ID:ryu1inaba,项目名称:LimeSurvey,代码行数:101,代码来源:question.php


示例6: edit

 /**
  * questiongroup::edit()
  * Load editing of a question group screen.
  *
  * @access public
  * @param int $surveyid
  * @param int $gid
  * @return void
  */
 public function edit($surveyid, $gid)
 {
     $surveyid = sanitize_int($surveyid);
     $gid = sanitize_int($gid);
     $aViewUrls = $aData = array();
     if (Permission::model()->hasSurveyPermission($surveyid, 'surveycontent', 'read')) {
         Yii::app()->session['FileManagerContext'] = "edit:group:{$surveyid}";
         Yii::app()->loadHelper('admin/htmleditor');
         Yii::app()->loadHelper('surveytranslator');
         $aAdditionalLanguages = Survey::model()->findByPk($surveyid)->additionalLanguages;
         $aBaseLanguage = Survey::model()->findByPk($surveyid)->language;
         $aLanguages = array_merge(array($aBaseLanguage), $aAdditionalLanguages);
         $grplangs = array_flip($aLanguages);
         // Check out the intgrity of the language versions of this group
         $egresult = QuestionGroup::model()->findAllByAttributes(array('sid' => $surveyid, 'gid' => $gid));
         foreach ($egresult as $esrow) {
             $esrow = $esrow->attributes;
             // Language Exists, BUT ITS NOT ON THE SURVEY ANYMORE
             if (!in_array($esrow['language'], $aLanguages)) {
                 QuestionGroup::model()->deleteAllByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'language' => $esrow['language']));
             } else {
                 $grplangs[$esrow['language']] = 'exists';
             }
             if ($esrow['language'] == $aBaseLanguage) {
                 $basesettings = $esrow;
             }
         }
         // Create groups in missing languages
         while (list($key, $value) = each($grplangs)) {
             if ($value != 'exists') {
                 $basesettings['language'] = $key;
                 $group = new QuestionGroup();
                 foreach ($basesettings as $k => $v) {
                     $group->{$k} = $v;
                 }
                 switchMSSQLIdentityInsert('groups', true);
                 $group->save();
                 switchMSSQLIdentityInsert('groups', false);
             }
         }
         $first = true;
         foreach ($aLanguages as $sLanguage) {
             $oResult = QuestionGroup::model()->findByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'language' => $sLanguage));
             $aData['aGroupData'][$sLanguage] = $oResult->attributes;
             $aTabTitles[$sLanguage] = getLanguageNameFromCode($sLanguage, false);
             if ($first) {
                 $aTabTitles[$sLanguage] .= ' (' . gT("Base language") . ')';
                 $first = false;
             }
         }
         $aData['action'] = $aData['display']['menu_bars']['gid_action'] = 'editgroup';
         $aData['surveyid'] = $surveyid;
         $aData['gid'] = $gid;
         $aData['tabtitles'] = $aTabTitles;
         $aData['aBaseLanguage'] = $aBaseLanguage;
         $this->_renderWrappedTemplate('survey/QuestionGroups', 'editGroup_view', $aData);
     }
 }
开发者ID:venurasasanka,项目名称:LimeSurvey,代码行数:67,代码来源:questiongroups.php


示例7: index


//.........这里部分代码省略.........
                         $oSubQuestion->question = $subquestionvalue;
                         $oSubQuestion->scale_id = $iScaleID;
                         $oSubQuestion->relevance = isset($aRelevance[$iScaleID][$iPosition]) ? $aRelevance[$iScaleID][$iPosition] : "";
                     } else {
                         if (!isset($aInsertQID[$iScaleID][$iPosition])) {
                             $oSubQuestion = new Question();
                             $oSubQuestion->sid = $iSurveyID;
                             $oSubQuestion->gid = $iQuestionGroupID;
                             $oSubQuestion->question_order = $iPosition + 1;
                             $oSubQuestion->title = $aCodes[$iScaleID][$iPosition];
                             $oSubQuestion->question = $subquestionvalue;
                             $oSubQuestion->parent_qid = $iQuestionID;
                             $oSubQuestion->language = $sLanguage;
                             $oSubQuestion->scale_id = $iScaleID;
                             $oSubQuestion->relevance = isset($aRelevance[$iScaleID][$iPosition]) ? $aRelevance[$iScaleID][$iPosition] : "";
                         } else {
                             $oSubQuestion = Question::model()->find("qid=:qid AND language=:language", array(":qid" => $aInsertQID[$iScaleID][$iPosition], ':language' => $sLanguage));
                             if (!$oSubQuestion) {
                                 $oSubQuestion = new Question();
                             }
                             $oSubQuestion->sid = $iSurveyID;
                             $oSubQuestion->qid = $aInsertQID[$iScaleID][$iPosition];
                             $oSubQuestion->gid = $iQuestionGroupID;
                             $oSubQuestion->question_order = $iPosition + 1;
                             $oSubQuestion->title = $aCodes[$iScaleID][$iPosition];
                             $oSubQuestion->question = $subquestionvalue;
                             $oSubQuestion->parent_qid = $iQuestionID;
                             $oSubQuestion->language = $sLanguage;
                             $oSubQuestion->scale_id = $iScaleID;
                             $oSubQuestion->relevance = isset($aRelevance[$iScaleID][$iPosition]) ? $aRelevance[$iScaleID][$iPosition] : "";
                         }
                     }
                     if ($oSubQuestion->qid) {
                         switchMSSQLIdentityInsert('questions', true);
                         $bSubQuestionResult = $oSubQuestion->save();
                         switchMSSQLIdentityInsert('questions', false);
                     } else {
                         $bSubQuestionResult = $oSubQuestion->save();
                     }
                     if ($bSubQuestionResult) {
                         if (substr($subquestionkey, 0, 3) != 'new' && isset($aOldCodes[$iScaleID][$iPosition]) && $aCodes[$iScaleID][$iPosition] !== $aOldCodes[$iScaleID][$iPosition]) {
                             Condition::model()->updateAll(array('cfieldname' => '+' . $iSurveyID . 'X' . $iQuestionGroupID . 'X' . $iQuestionID . $aCodes[$iScaleID][$iPosition], 'value' => $aCodes[$iScaleID][$iPosition]), 'cqid=:cqid AND cfieldname=:cfieldname AND value=:value', array(':cqid' => $iQuestionID, ':cfieldname' => $iSurveyID . 'X' . $iQuestionGroupID . 'X' . $iQuestionID, ':value' => $aOldCodes[$iScaleID][$iPosition]));
                         }
                         if (!isset($aInsertQID[$iScaleID][$iPosition])) {
                             $aInsertQID[$iScaleID][$iPosition] = $oSubQuestion->qid;
                         }
                     } else {
                         $aErrors = $oSubQuestion->getErrors();
                         if (count($aErrors)) {
                             //$sErrorMessage=gT("Question could not be updated with this errors:");
                             foreach ($aErrors as $sAttribute => $aStringErrors) {
                                 foreach ($aStringErrors as $sStringErrors) {
                                     Yii::app()->setFlashMessage(sprintf(gT("Error on %s for subquestion %s: %s"), $sAttribute, $aCodes[$iScaleID][$iPosition], $sStringErrors), 'error');
                                 }
                             }
                         } else {
                             Yii::app()->setFlashMessage(sprintf(gT("Subquestions %s could not be updated."), $aCodes[$iScaleID][$iPosition]), 'error');
                         }
                     }
                     $iPosition++;
                 }
             }
         }
         LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyID);
         // Do it only if there are no error ?
         if (!isset($aErrors) || !count($aErrors)) {
开发者ID:joaocc,项目名称:LimeSurvey--LimeSurvey,代码行数:67,代码来源:database.php


示例8: _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;
//.........这里部分代码省略.........
开发者ID:GuillaumeSmaha,项目名称:LimeSurvey,代码行数:101,代码来源:em_manager_helper.php


示例9: index


//.........这里部分代码省略.........
                         $oSubQuestion->scale_id = $iScaleID;
                         //dual matrix, text/number matrix: subQ relevance per line not per scale, so ScaleID is always 0
                         $oSubQuestion->relevance = $aRelevance[0][$iPosition];
                     } else {
                         if (!isset($aInsertQID[$iScaleID][$iPosition])) {
                             $oSubQuestion = new Question();
                             $oSubQuestion->sid = $iSurveyID;
                             $oSubQuestion->gid = $iQuestionGroupID;
                             $oSubQuestion->question_order = $iPosition + 1;
                             $oSubQuestion->title = $aCodes[$iScaleID][$iPosition];
                             $oSubQuestion->question = $subquestionvalue;
                             $oSubQuestion->parent_qid = $iQuestionID;
                             $oSubQuestion->language = $sLanguage;
                             $oSubQuestion->scale_id = $iScaleID;
                             $oSubQuestion->relevance = $aRelevance[0][$iPosition];
                         } else {
                             $oSubQuestion = Question::model()->find("qid=:qid AND language=:language", array(":qid" => $aInsertQID[$iScaleID][$iPosition], ':language' => $sLanguage));
                             if (!$oSubQuestion) {
                                 $oSubQuestion = new Question();
                             }
                             $oSubQuestion->sid = $iSurveyID;
                             $oSubQuestion->qid = $aInsertQID[$iScaleID][$iPosition];
                             $oSubQuestion->gid = $iQuestionGroupID;
                             $oSubQuestion->question_order = $iPosition + 1;
                             $oSubQuestion->title = $aCodes[$iScaleID][$iPosition];
                             $oSubQuestion->question = $subquestionvalue;
                             $oSubQuestion->parent_qid = $iQuestionID;
                             $oSubQuestion->language = $sLanguage;
                             $oSubQuestion->scale_id = $iScaleID;
                             $oSubQuestion->relevance = $aRelevance[$iScaleID][$iPosition];
                         }
                     }
                     if ($oSubQuestion->qid) {
                         switchMSSQLIdentityInsert('questions', true);
                         $bSubQuestionResult = $oSubQuestion->save();
                         switchMSSQLIdentityInsert('questions', false);
                     } else {
                         $bSubQuestionResult = $oSubQuestion->save();
                     }
                     if ($bSubQuestionResult) {
                         if (substr($subquestionkey, 0, 3) != 'new' && isset($aOldCodes[$iScaleID][$iPosition]) && $aCodes[$iScaleID][$iPosition] !== $aOldCodes[$iScaleID][$iPosition]) {
                             Condition::model()->updateAll(array('cfieldname' => '+' . $iSurveyID . 'X' . $iQuestionGroupID . 'X' . $iQuestionID . $aCodes[$iScaleID][$iPosition], 'value' => $aCodes[$iScaleID][$iPosition]), 'cqid=:cqid AND cfieldname=:cfieldname AND value=:value', array(':cqid' => $iQuestionID, ':cfieldname' => $iSurveyID . 'X' . $iQuestionGroupID . 'X' . $iQuestionID, ':value' => $aOldCodes[$iScaleID][$iPosition]));
                         }
                         if (!isset($aInsertQID[$iScaleID][$iPosition])) {
                             $aInsertQID[$iScaleID][$iPosition] = $oSubQuestion->qid;
                         }
                     } else {
                         $aErrors = $oSubQuestion->getErrors();
                         if (count($aErrors)) {
                             //$sErrorMessage=gT("Question could not be updated with this errors:");
                             foreach ($aErrors as $sAttribute => $aStringErrors) {
                                 foreach ($aStringErrors as $sStringErrors) {
                                     Yii::app()->setFlashMessage(sprintf(gT("Error on %s for subquestion %s: %s"), $sAttribute, $aCodes[$iScaleID][$iPosition], $sStringErrors), 'error');
                                 }
                             }
                         } else {
                             Yii::app()->setFlashMessage(sprintf(gT("Subquestions %s could not be updated."), $aCodes[$iScaleID][$iPosition]), 'error');
                         }
                     }
                     $iPosition++;
                 }
             }
         }
         LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyID);
         // Do it only if there are no error ?
         if (!isset($aErrors) || !count($aErrors)) {
开发者ID:nicbon,项目名称:LimeSurvey,代码行数:67,代码来源:database.php


示例10: edit

 /**
  * questiongroup::edit()
  * Load editing of a question group screen.
  *
  * @access public
  * @param int $surveyid
  * @param int $gid
  * @return void
  */
 public function edit($surveyid, $gid)
 {
     $surveyid = $iSurveyID = sanitize_int($surveyid);
     $gid = sanitize_int($gid);
     $aViewUrls = $aData = array();
     if (Permission::model()->hasSurveyPermission($surveyid, 'surveycontent', 'update')) {
         Yii::app()->session['FileManagerContext'] = "edit:group:{$surveyid}";
         Yii::app()->loadHelper('admin/htmleditor');
         Yii::app()->loadHelper('surveytranslator');
         $aAdditionalLanguages = Survey::model()->findByPk($surveyid)->additionalLanguages;
         // TODO: This is not an array, but a string "en"
         $aBaseLanguage = Survey::model()->findByPk($surveyid)->language;
         $aLanguages = array_merge(array($aBaseLanguage), $aAdditionalLanguages);
         $grplangs = array_flip($aLanguages);
         // Check out the intgrity of the language versions of this group
         $egresult = QuestionGroup::model()->findAllByAttributes(array('sid' => $surveyid, 'gid' => $gid));
         foreach ($egresult as $esrow) {
             $esrow = $esrow->attributes;
             // Language Exists, BUT ITS NOT ON THE SURVEY ANYMORE
             if (!in_array($esrow['language'], $aLanguages)) {
                 QuestionGroup::model()->deleteAllByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'language' => $esrow['language']));
             } else {
                 $grplangs[$esrow['language']] = 'exists';
             }
             if ($esrow['language'] == $aBaseLanguage) {
                 $basesettings = $esrow;
             }
         }
         // Create groups in missing languages
         while (list($key, $value) = each($grplangs)) {
             if ($value != 'exists') {
                 $basesettings['language'] = $key;
                 $group = new QuestionGroup();
                 foreach ($basesettings as $k => $v) {
                     $group->{$k} = $v;
                 }
                 switchMSSQLIdentityInsert('groups', true);
                 $group->save();
                 switchMSSQLIdentityInsert('groups', false);
             }
         }
         $first = true;
         foreach ($aLanguages as $sLanguage) {
             $oResult = $oQuestionGroup = QuestionGroup::model()->findByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'language' => $sLanguage));
             $aData['aGroupData'][$sLanguage] = $oResult->attributes;
             $aTabTitles[$sLanguage] = getLanguageNameFromCode($sLanguage, false);
             if ($first) {
                 $aTabTitles[$sLanguage] .= ' (' . gT("Base language") . ')';
                 $first = false;
             }
         }
         $aData['oQuestionGroup'] = $oQuestionGroup;
         $aData['sidemenu']['questiongroups'] = true;
         $aData['questiongroupbar']['buttonspreview'] = true;
         $aData['questiongroupbar']['savebutton']['form'] = true;
         $aData['questiongroupbar']['saveandclosebutton']['form'] = true;
         $aData['questiongroupbar']['closebutton']['url'] = 'admin/questiongroups/sa/view/surveyid/' . $surveyid . '/gid/' . $gid;
         // Close button
         $aData['action'] = $aData['display']['menu_bars']['gid_action'] = 'editgroup';
         $aData['surveyid'] = $surveyid;
         $aData['gid'] = $gid;
         $aData['tabtitles'] = $aTabTitles;
         $aData['aBaseLanguage'] = $aBaseLanguage;
         $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
         $aData['title_bar']['title'] = $surveyinfo['surveyls_title'] . "(" . gT("ID") . ":" . $iSurveyID . ")";
         ///////////
         // sidemenu
         $aData['sidemenu']['state'] = false;
         $aData['sidemenu']['explorer']['state'] = true;
         $aData['sidemenu']['explorer']['gid'] = isset($gid) ? $gid : false;
         $aData['sidemenu']['explorer']['qid'] = false;
         $this->_renderWrappedTemplate('survey/QuestionGroups', 'editGroup_view', $aData);
     } else {
         Yii::app()->user->setFlash('error', gT("Access denied"));
         $this->getController()->redirect(Yii::app()->request->urlReferrer);
     }
 }
开发者ID:mfavetti,项目名称:LimeSurvey,代码行数:86,代码来源:questiongroups.php


示例11: index


//.........这里部分代码省略.........
         $invalidCode = 0;
         $duplicateCode = 0;
         $dupanswers = array();
         /*
         for ($scale_id=0;$scale_id<$scalecount;$scale_id++)
         {
         
         // Find duplicate codes and add these to dupanswers array
         $foundCat=array_count_values($codes);
         foreach($foundCat as $key=>$value){
         if($value>=2){
         $dupanswers[]=$key;
         }
         }
         }
         */
         //require_once("../classes/inputfilter/class.inputfilter_clean.php");
         //$myFilter = new InputFilter('','',1,1,1);
         //$insertqids=array(); //?
         $insertqid = array();
         for ($scale_id = 0; $scale_id < $scalecount; $scale_id++) {
             foreach ($anslangs as $language) {
                 $position = 0;
                 foreach ($rows[$scale_id][$language] as $subquestionkey => $subquestionvalue) {
                     if (substr($subquestionkey, 0, 3) != 'new') {
                         Questions::model()->updateByPk(array('qid' => $subquestionkey, 'language' => $language), array('question_order' => $position + 1, 'title' => $codes[$scale_id][$position], 'question' => $subquestionvalue, 'scale_id' => $scale_id));
                         if (isset($oldcodes[$scale_id][$position]) && $codes[$scale_id][$position] !== $oldcodes[$scale_id][$position]) {
                             Conditions::model()->updateAll(array('cfieldname' => '+' . $surveyid . 'X' . $gid . 'X' . $qid . $codes[$scale_id][$position], 'value' => $codes[$scale_id][$position]), 'cqid=:cqid AND cfieldname=:cfieldname AND value=:value', array(':cqid' => $qid, ':cfieldname' => $surveyid . 'X' . $gid . 'X' . $qid, ':value' => $oldcodes[$scale_id][$position]));
                         }
                     } else {
                         if (!isset($insertqid[$scale_id][$position])) {
                             $insertqid[$scale_id][$position] = Questions::model()->insertRecords(array('sid' => $surveyid, 'gid' => $gid, 'question_order' => $position + 1, 'title' => $codes[$scale_id][$position], 'question' => $subquestionvalue, 'parent_qid' => $qid, 'language' => $language, 'scale_id' => $scale_id));
                         } else {
                             switchMSSQLIdentityInsert('questions', true);
                             Questions::model()->insertRecords(array('qid' => $insertqid[$scale_id][$position], 'sid' => $surveyid, 'gid' => $gid, 'question_order' => $position + 1, 'title' => $codes[$scale_id][$position], 'question' => $subquestionvalue, 'parent_qid' => $qid, 'language' => $language, 'scale_id' => $scale_id));
                             switchMSSQLIdentityInsert('questions', true);
                         }
                     }
                     $position++;
                 }
             }
         }
         LimeExpressionManager::UpgradeConditionsToRelevance($surveyid);
         //include("surveytable_functions.php");
         //surveyFixColumns($surveyid);
         Yii::app()->session['flashmessage'] = $clang->gT("Subquestions were successfully saved.");
         //$action='editsubquestions';
         LimeExpressionManager::SetDirtyFlag();
         if ($databaseoutput != '') {
             echo $databaseoutput;
         } else {
             $this->getController()->redirect($this->getController()->createUrl('/admin/question/sa/subquestions/surveyid/' . $surveyid . '/gid/' . $gid . '/qid/' . $qid));
         }
     }
     if (in_array($action, array('insertquestion', 'copyquestion')) && hasSurveyPermission($surveyid, 'surveycontent', 'create')) {
         $baselang = Survey::model()->findByPk($surveyid)->language;
         if (strlen(Yii::app()->request->getPost('title')) < 1) {
             $databaseoutput .= "<script type=\"text/javascript\">\n<!--\n " . "alert(\"" . $clang->gT("The question could not be added. You must enter at least a question code.", "js") . "\")\n " . "//-->\n</script>\n";
         } else {
             if (Yii::app()->request->getPost('questionposition', "") != "") {
        

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP switch_theme函数代码示例发布时间:2022-05-23
下一篇:
PHP swarmpath函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap