function setGlobalSetting($settingname, $settingvalue)
{
    if (Yii::app()->getConfig("demoMode") == true && ($settingname == 'sitename' || $settingname == 'defaultlang' || $settingname == 'defaulthtmleditormode' || $settingname == 'filterxsshtml')) {
        return;
        //don't save
    }
    if ($record = SettingGlobal::model()->findByPk($settingname)) {
        $record->stg_value = $settingvalue;
        $record->save();
    } else {
        $record = new SettingGlobal();
        $record->stg_name = $settingname;
        $record->stg_value = $settingvalue;
        $record->save();
    }
    Yii::app()->setConfig($settingname, $settingvalue);
}
 /**
  * create or update the updatekey to the submited value
  * @param string $submittedUpdateKey the new key id
  * @return array<string,false|string> the new update key if success, CActiveRecord result if error
  * 
  * TODO : should return same status than server to use the same view render
  */
 public function setUpdateKey($submittedUpdateKey)
 {
     // The update keys never contains special characters, so, it should not affect the key
     // If it affects the key : then the key was wrong... and the database is safe
     $submittedUpdateKey = trim(htmlspecialchars(addslashes($submittedUpdateKey)));
     $updateKey = SettingGlobal::model()->findByPk('update_key');
     if (!$updateKey) {
         // Create
         $updateKey = new SettingGlobal();
         $updateKey->stg_name = 'update_key';
         $updateKey->stg_value = $submittedUpdateKey;
         $result = $updateKey->save();
     } else {
         //Update
         $result = SettingGlobal::model()->updateByPk('update_key', array('stg_value' => $submittedUpdateKey));
     }
     if ($result) {
         // If success we return the updatekey row
         $updateKey = SettingGlobal::model()->findByPk('update_key');
         return $updateKey;
     } else {
         // Else we return the errors
         return array('result' => FALSE, 'error' => 'db_error');
     }
 }
 /**
  * Stores the blacklist setting to the database
  */
 function storeBlacklistValues()
 {
     $values = array('blacklistallsurveys', 'blacklistnewsurveys', 'blockaddingtosurveys', 'hideblacklisted', 'deleteblacklisted', 'allowunblacklist', 'userideditable');
     foreach ($values as $value) {
         if ($find = SettingGlobal::model()->findByPk($value)) {
             SettingGlobal::model()->updateByPk($value, array('stg_value' => Yii::app()->request->getPost($value)));
         } else {
             $stg = new SettingGlobal();
             $stg->stg_name = $value;
             $stg->stg_value = Yii::app()->request->getPost($value);
             $stg->save();
         }
     }
     Yii::app()->getController()->redirect(array('admin/participants/sa/blacklistControl'));
 }
 /**
  * Function responsible for deleting a question.
  *
  * @access public
  * @param string $action
  * @param int $surveyid
  * @param int $gid
  * @param int $qid
  * @return void
  */
 public function delete($surveyid, $gid, $qid)
 {
     $surveyid = sanitize_int($surveyid);
     $gid = sanitize_int($gid);
     $qid = sanitize_int($qid);
     $rqid = $qid;
     if (Permission::model()->hasSurveyPermission($surveyid, 'surveycontent', 'delete')) {
         if (!isset($qid)) {
             $qid = returnGlobal('qid');
         }
         LimeExpressionManager::RevertUpgradeConditionsToRelevance(NULL, $qid);
         // Check if any other questions have conditions which rely on this question. Don't delete if there are.
         // TMSW Condition->Relevance:  Allow such deletes - can warn about missing relevance separately.
         $ccresult = Condition::model()->findAllByAttributes(array('cqid' => $qid));
         $cccount = count($ccresult);
         // There are conditions dependent on this question
         if ($cccount) {
             foreach ($ccresult as $ccr) {
                 $qidarray[] = $ccr->qid;
             }
             if (isset($qidarray)) {
                 $qidlist = implode(", ", $qidarray);
             }
             $message = gT("Question could not be deleted. There are conditions for other questions that rely on this question. You cannot delete this question until those conditions are removed.");
             $message .= "<br /><a href='" . $this->getController()->createUrl("admin/expressions/sa/survey_logic_file/sid/{$surveyid}") . "' >" . gT("Look at survey logic files") . "</a>.";
             $this->getController()->error($message, $this->getController()->createUrl("admin/survey/sa/view/surveyid/{$surveyid}/gid/{$gid}/qid/{$qid}"));
         } else {
             $row = Question::model()->findByAttributes(array('qid' => $qid))->attributes;
             $gid = $row['gid'];
             // See if there are any conditions/attributes/answers/defaultvalues for this question,
             // and delete them now as well
             Condition::model()->deleteAllByAttributes(array('qid' => $qid));
             QuestionAttribute::model()->deleteAllByAttributes(array('qid' => $qid));
             Answer::model()->deleteAllByAttributes(array('qid' => $qid));
             $criteria = new CDbCriteria();
             $criteria->addCondition('qid = :qid1 or parent_qid = :qid2');
             $criteria->params[':qid1'] = $qid;
             $criteria->params[':qid2'] = $qid;
             Question::model()->deleteAll($criteria);
             DefaultValue::model()->deleteAllByAttributes(array('qid' => $qid));
             QuotaMember::model()->deleteAllByAttributes(array('qid' => $qid));
             Question::model()->updateQuestionOrder($gid, $surveyid);
             $qid = "";
             $postqid = "";
             $_GET['qid'] = "";
         }
         Yii::app()->session['flashmessage'] = gT("Question was successfully deleted.");
         // remove question from lastVisited
         SettingGlobal::model()->deleteAll("stg_value = :stg_value", array(':stg_value' => $rqid));
         $this->getController()->redirect(array('admin/survey/sa/listquestions/surveyid/' . $surveyid));
     } else {
         Yii::app()->session['flashmessage'] = gT("You are not authorized to delete questions.");
         $this->getController()->redirect(array('admin/survey/sa/listquestions/surveyid/' . $surveyid));
     }
 }
 /**
  * Deletes a survey and all its data
  *
  * @access public
  * @param int $iSurveyID
  * @param bool @recursive
  * @return void
  */
 public function deleteSurvey($iSurveyID, $recursive = true)
 {
     Survey::model()->deleteByPk($iSurveyID);
     if ($recursive == true) {
         if (tableExists("{{survey_" . intval($iSurveyID) . "}}")) {
             Yii::app()->db->createCommand()->dropTable("{{survey_" . intval($iSurveyID) . "}}");
         }
         if (tableExists("{{survey_" . intval($iSurveyID) . "_timings}}")) {
             Yii::app()->db->createCommand()->dropTable("{{survey_" . intval($iSurveyID) . "_timings}}");
         }
         if (tableExists("{{tokens_" . intval($iSurveyID) . "}}")) {
             Yii::app()->db->createCommand()->dropTable("{{tokens_" . intval($iSurveyID) . "}}");
         }
         /* Remove User/global settings part : need Question and QuestionGroup*/
         // Settings specific for this survey
         $oCriteria = new CDbCriteria();
         $oCriteria->compare('stg_name', 'last_%', true, 'AND', false);
         $oCriteria->compare('stg_value', $iSurveyID, false, 'AND');
         SettingGlobal::model()->deleteAll($oCriteria);
         // Settings specific for this survey, 2nd part
         $oCriteria = new CDbCriteria();
         $oCriteria->compare('stg_name', 'last_%' . $iSurveyID . '%', true, 'AND', false);
         SettingGlobal::model()->deleteAll($oCriteria);
         // All Group id from this survey for ALL users
         $aGroupId = CHtml::listData(QuestionGroup::model()->findAll(array('select' => 'gid', 'condition' => 'sid=:sid', 'params' => array(':sid' => $iSurveyID))), 'gid', 'gid');
         $oCriteria = new CDbCriteria();
         $oCriteria->compare('stg_name', 'last_question_gid_%', true, 'AND', false);
         if (Yii::app()->db->getDriverName() == 'pgsql') {
             $oCriteria->addInCondition('CAST(stg_value as ' . App()->db->schema->getColumnType("integer") . ')', $aGroupId);
         } else {
             $oCriteria->addInCondition('stg_value', $aGroupId);
         }
         SettingGlobal::model()->deleteAll($oCriteria);
         // All Question id from this survey for ALL users
         $aQuestionId = CHtml::listData(Question::model()->findAll(array('select' => 'qid', 'condition' => 'sid=:sid', 'params' => array(':sid' => $iSurveyID))), 'qid', 'qid');
         $oCriteria = new CDbCriteria();
         $oCriteria->compare('stg_name', 'last_question_%', true, 'OR', false);
         if (Yii::app()->db->getDriverName() == 'pgsql') {
             $oCriteria->addInCondition('CAST(stg_value as ' . App()->db->schema->getColumnType("integer") . ')', $aQuestionId);
         } else {
             $oCriteria->addInCondition('stg_value', $aQuestionId);
         }
         SettingGlobal::model()->deleteAll($oCriteria);
         $oResult = Question::model()->findAllByAttributes(array('sid' => $iSurveyID));
         foreach ($oResult as $aRow) {
             Answer::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
             Condition::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
             QuestionAttribute::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
             DefaultValue::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
         }
         Question::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
         Assessment::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
         QuestionGroup::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
         SurveyLanguageSetting::model()->deleteAllByAttributes(array('surveyls_survey_id' => $iSurveyID));
         Permission::model()->deleteAllByAttributes(array('entity_id' => $iSurveyID, 'entity' => 'survey'));
         SavedControl::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
         SurveyURLParameter::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
         //Remove any survey_links to the CPDB
         SurveyLink::model()->deleteLinksBySurvey($iSurveyID);
         Quota::model()->deleteQuota(array('sid' => $iSurveyID), true);
     }
 }
 /**
  * Function responsible to delete a survey.
  *
  * @access public
  * @param int $iSurveyID
  * @param string $sa
  * @return void
  */
 public function delete($iSurveyID)
 {
     $aData = $aViewUrls = array();
     $aData['surveyid'] = $iSurveyID = (int) $iSurveyID;
     $aData['sidebar']['state'] = "close";
     $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
     $aData['title_bar']['title'] = $surveyinfo['surveyls_title'] . "(" . gT("ID") . ":" . $iSurveyID . ")";
     $aData['sidebar']['state'] = "close";
     if (Permission::model()->hasSurveyPermission($iSurveyID, 'survey', 'delete')) {
         if (Yii::app()->request->getPost("delete") == 'yes') {
             $aData['issuperadmin'] = Permission::model()->hasGlobalPermission('superadmin', 'read');
             $this->_deleteSurvey($iSurveyID);
             Yii::app()->session['flashmessage'] = gT("Survey deleted.");
             // We clean all the last visited
             $lastLikeSurvey = 'last%' . $iSurveyID . '%';
             $lastQuestionGidUser = '******' . Yii::app()->user->getId();
             $lastQuestionUser = '******' . Yii::app()->user->getId();
             SettingGlobal::model()->deleteAll("stg_name LIKE :stg_name  OR stg_name = :last_question_gid_user OR stg_name = :last_question_user OR stg_value = :stg_value", array(':stg_name' => $lastLikeSurvey, ':last_question_gid_user' => $lastQuestionGidUser, ':last_question_user' => $lastQuestionUser, ':stg_value' => $iSurveyID));
             $this->getController()->redirect(array("admin/index"));
         } else {
             $aViewUrls[] = 'deleteSurvey_view';
         }
     } else {
         $this->getController()->error('Access denied');
     }
     $this->_renderWrappedTemplate('survey', $aViewUrls, $aData);
 }
Exemple #7
0
 /**
  * Function responsible for deleting a question.
  *
  * @access public
  * @param string $action
  * @param int $surveyid
  * @param int $gid
  * @param int $qid
  * @return void
  */
 public function delete($surveyid, $gid, $qid, $ajax = false)
 {
     $surveyid = sanitize_int($surveyid);
     $gid = sanitize_int($gid);
     $qid = sanitize_int($qid);
     $rqid = $qid;
     if (Permission::model()->hasSurveyPermission($surveyid, 'surveycontent', 'delete')) {
         if (!isset($qid)) {
             $qid = returnGlobal('qid');
         }
         LimeExpressionManager::RevertUpgradeConditionsToRelevance(NULL, $qid);
         // Check if any other questions have conditions which rely on this question. Don't delete if there are.
         // TMSW Condition->Relevance:  Allow such deletes - can warn about missing relevance separately.
         $ccresult = Condition::model()->findAllByAttributes(array('cqid' => $qid));
         $cccount = count($ccresult);
         // There are conditions dependent on this question
         if ($cccount) {
             foreach ($ccresult as $ccr) {
                 $qidarray[] = $ccr->qid;
             }
             if (isset($qidarray)) {
                 $qidlist = implode(", ", $qidarray);
             }
             $sMessage = gT("Question could not be deleted. There are conditions for other questions that rely on this question. You cannot delete this question until those conditions are removed.");
             if (!$ajax) {
                 Yii::app()->setFlashMessage($sMessage, 'error');
                 $this->getController()->redirect(array('admin/survey/sa/listquestions/surveyid/' . $surveyid));
             } else {
                 return array('status' => false, 'message' => $sMessage);
             }
         } else {
             $row = Question::model()->findByAttributes(array('qid' => $qid))->attributes;
             $gid = $row['gid'];
             // See if there are any conditions/attributes/answers/defaultvalues for this question,
             // and delete them now as well
             Condition::model()->deleteAllByAttributes(array('qid' => $qid));
             QuestionAttribute::model()->deleteAllByAttributes(array('qid' => $qid));
             Answer::model()->deleteAllByAttributes(array('qid' => $qid));
             $criteria = new CDbCriteria();
             $criteria->addCondition('qid = :qid1 or parent_qid = :qid2');
             $criteria->params[':qid1'] = $qid;
             $criteria->params[':qid2'] = $qid;
             Question::model()->deleteAll($criteria);
             DefaultValue::model()->deleteAllByAttributes(array('qid' => $qid));
             QuotaMember::model()->deleteAllByAttributes(array('qid' => $qid));
             Question::model()->updateQuestionOrder($gid, $surveyid);
             $qid = "";
             $postqid = "";
             $_GET['qid'] = "";
         }
         $sMessage = gT("Question was successfully deleted.");
         // remove question from lastVisited
         $oCriteria = new CDbCriteria();
         $oCriteria->compare('stg_name', 'last_question_%', true, 'AND', false);
         $oCriteria->compare('stg_value', $rqid, false, 'AND');
         SettingGlobal::model()->deleteAll($oCriteria);
         if (!$ajax) {
             Yii::app()->session['flashmessage'] = $sMessage;
             $this->getController()->redirect(array('admin/survey/sa/listquestions/surveyid/' . $surveyid));
         } else {
             return array('status' => true, 'message' => $sMessage);
         }
     } else {
         $sMessage = gT("You are not authorized to delete questions.");
         if (!$ajax) {
             Yii::app()->session['flashmessage'] = $sMessage;
             $this->getController()->redirect(array('admin/survey/sa/listquestions/surveyid/' . $surveyid));
         } else {
             return array('status' => false, 'message' => $sMessage);
         }
     }
 }
 /**
  * Handles loading all active plugins
  *
  * Possible improvement would be to load them for a specific context.
  * For instance 'survey' for runtime or 'admin' for backend. This needs
  * some thinking before implementing.
  */
 public function loadPlugins()
 {
     // If DB version is less than 165 : plugins table don't exist. 175 update it (boolean to integer for active)
     $dbVersion = \SettingGlobal::model()->find("stg_name=:name", array(':name' => 'DBVersion'));
     // Need table SettingGlobal, but settings from DB is set only in controller, not in App, see #11294
     if ($dbVersion && $dbVersion->stg_value >= 165) {
         $pluginModel = Plugin::model();
         $records = $pluginModel->findAllByAttributes(array('active' => 1));
         foreach ($records as $record) {
             $this->loadPlugin($record->name, $record->id);
         }
     } else {
         // Log it ? tracevar ?
     }
     $this->dispatchEvent(new PluginEvent('afterPluginLoad', $this));
     // Alow plugins to do stuff after all plugins are loaded
 }