/** * RPC Routine to add an empty survey with minimum details. * Used as a placeholder for importing groups and/or questions. * * @access public * @param string $sSessionKey Auth credentials * @param int $iSurveyID The wish id of the Survey to add * @param string $sSurveyTitle Title of the new Survey * @param string $sSurveyLanguage Default language of the Survey * @param string $sformat Question appearance format * @return array|string|int */ public function add_survey($sSessionKey, $iSurveyID, $sSurveyTitle, $sSurveyLanguage, $sformat = 'G') { Yii::app()->loadHelper("surveytranslator"); if ($this->_checkSessionKey($sSessionKey)) { if (Yii::app()->session['USER_RIGHT_CREATE_SURVEY']) { if ($sSurveyTitle == '' || $sSurveyLanguage == '' || !array_key_exists($sSurveyLanguage, getLanguageDataRestricted()) || !in_array($sformat, array('A', 'G', 'S'))) { return array('status' => 'Faulty parameters'); } $aInsertData = array('template' => 'default', 'owner_id' => Yii::app()->session['loginID'], 'active' => 'N', 'language' => $sSurveyLanguage, 'format' => $sformat); if (!is_null($iSurveyID)) { $aInsertData['wishSID'] = $iSurveyID; } try { $iNewSurveyid = Survey::model()->insertNewSurvey($aInsertData); if (!$iNewSurveyid) { return array('status' => 'Creation Failed'); } $sTitle = html_entity_decode($sSurveyTitle, ENT_QUOTES, "UTF-8"); // Load default email templates for the chosen language $oLanguage = new Limesurvey_lang($sSurveyLanguage); $aDefaultTexts = templateDefaultTexts($oLanguage, 'unescaped'); unset($oLanguage); $bIsHTMLEmail = false; $aInsertData = array('surveyls_survey_id' => $iNewSurveyid, 'surveyls_title' => $sTitle, 'surveyls_language' => $sSurveyLanguage); $langsettings = new Surveys_languagesettings(); $langsettings->insertNewSurvey($aInsertData); Survey_permissions::model()->giveAllSurveyPermissions(Yii::app()->session['loginID'], $iNewSurveyid); return (int) $iNewSurveyid; } catch (Exception $e) { return array('status' => $e->getmessage()); } } else { return array('status' => 'No permission'); } } else { return array('status' => 'Invalid session key'); } }
/** * Saves the new survey after the creation screen is submitted * * @param $iSurveyID The survey id to be used for the new survey. If already taken a new random one will be used. */ function insert($iSurveyID = null) { if (Yii::app()->session['USER_RIGHT_CREATE_SURVEY']) { // Check if survey title was set if (!$_POST['surveyls_title']) { Yii::app()->session['flashmessage'] = $clang->gT("Survey could not be created because it did not have a title"); redirect($this->getController()->createUrl('admin')); return; } // Check if template may be used $sTemplate = $_POST['template']; if (!$sTemplate || Yii::app()->session['USER_RIGHT_SUPERADMIN'] != 1 && Yii::app()->session['USER_RIGHT_MANAGE_TEMPLATE'] != 1 && !hasTemplateManageRights(Yii::app()->session['loginID'], $_POST['template'])) { $sTemplate = "default"; } Yii::app()->loadHelper("surveytranslator"); // If start date supplied convert it to the right format $aDateFormatData = getDateFormatData(Yii::app()->session['dateformat']); $sStartDate = $_POST['startdate']; if (trim($sStartDate) != '') { Yii::import('application.libraries.Date_Time_Converter'); $converter = new Date_Time_Converter($sStartDate, $aDateFormatData['phpdate'] . ' H:i:s'); $sStartDate = $converter->convert("Y-m-d H:i:s"); } // If expiry date supplied convert it to the right format $sExpiryDate = $_POST['expires']; if (trim($sExpiryDate) != '') { Yii::import('application.libraries.Date_Time_Converter'); $converter = new Date_Time_Converter($sExpiryDate, $aDateFormatData['phpdate'] . ' H:i:s'); $sExpiryDate = $converter->convert("Y-m-d H:i:s"); } // Insert base settings into surveys table $aInsertData = array('expires' => $sExpiryDate, 'startdate' => $sStartDate, 'template' => $sTemplate, 'owner_id' => Yii::app()->session['loginID'], 'admin' => $_POST['admin'], 'active' => 'N', 'adminemail' => $_POST['adminemail'], 'bounce_email' => $_POST['bounce_email'], 'anonymized' => $_POST['anonymized'], 'faxto' => $_POST['faxto'], 'format' => $_POST['format'], 'savetimings' => $_POST['savetimings'], 'language' => $_POST['language'], 'datestamp' => $_POST['datestamp'], 'ipaddr' => $_POST['ipaddr'], 'refurl' => $_POST['refurl'], 'usecookie' => $_POST['usecookie'], 'emailnotificationto' => $_POST['emailnotificationto'], 'allowregister' => $_POST['allowregister'], 'allowsave' => $_POST['allowsave'], 'navigationdelay' => $_POST['navigationdelay'], 'autoredirect' => $_POST['autoredirect'], 'showxquestions' => $_POST['showxquestions'], 'showgroupinfo' => $_POST['showgroupinfo'], 'showqnumcode' => $_POST['showqnumcode'], 'shownoanswer' => $_POST['shownoanswer'], 'showwelcome' => $_POST['showwelcome'], 'allowprev' => $_POST['allowprev'], 'allowjumps' => $_POST['allowjumps'], 'nokeyboard' => $_POST['nokeyboard'], 'showprogress' => $_POST['showprogress'], 'printanswers' => $_POST['printanswers'], 'listpublic' => $_POST['public'], 'htmlemail' => $_POST['htmlemail'], 'sendconfirmation' => $_POST['sendconfirmation'], 'tokenanswerspersistence' => $_POST['tokenanswerspersistence'], 'alloweditaftercompletion' => $_POST['alloweditaftercompletion'], 'usecaptcha' => $_POST['usecaptcha'], 'publicstatistics' => $_POST['publicstatistics'], 'publicgraphs' => $_POST['publicgraphs'], 'assessments' => $_POST['assessments'], 'emailresponseto' => $_POST['emailresponseto'], 'tokenlength' => $_POST['tokenlength']); if (!is_null($iSurveyID)) { $aInsertData['wishSID'] = $iSurveyID; } $iNewSurveyid = Survey::model()->insertNewSurvey($aInsertData); if (!$iNewSurveyid) { die('Survey could not be created.'); } // Prepare locale data for surveys_language_settings table $sTitle = $_POST['surveyls_title']; $sDescription = $_POST['description']; $sWelcome = $_POST['welcome']; $sURLDescription = $_POST['urldescrip']; if (Yii::app()->getConfig('filterxsshtml')) { //$p = new CHtmlPurifier(); //$p->options = array('URI.AllowedSchemes'=>array('http' => true, 'https' => true)); //$sTitle=$p->purify($sTitle); //$sDescription=$p->purify($sDescription); //$sWelcome=$p->purify($sWelcome); //$sURLDescription=$p->purify($sURLDescription); } $sTitle = html_entity_decode($sTitle, ENT_QUOTES, "UTF-8"); $sDescription = html_entity_decode($sDescription, ENT_QUOTES, "UTF-8"); $sWelcome = html_entity_decode($sWelcome, ENT_QUOTES, "UTF-8"); $sURLDescription = html_entity_decode($sURLDescription, ENT_QUOTES, "UTF-8"); // Fix bug with FCKEditor saving strange BR types $sTitle = fixCKeditorText($sTitle); $sDescription = fixCKeditorText($sDescription); $sWelcome = fixCKeditorText($sWelcome); // Insert base language into surveys_language_settings table $aInsertData = array('surveyls_survey_id' => $iNewSurveyid, 'surveyls_title' => $sTitle, 'surveyls_description' => $sDescription, 'surveyls_welcometext' => $sWelcome, 'surveyls_language' => $_POST['language'], 'surveyls_urldescription' => $_POST['urldescrip'], 'surveyls_endtext' => $_POST['endtext'], 'surveyls_url' => $_POST['url'], 'surveyls_dateformat' => (int) $_POST['dateformat'], 'surveyls_numberformat' => (int) $_POST['numberformat']); $langsettings = new Surveys_languagesettings(); $langsettings->insertNewSurvey($aInsertData); Yii::app()->session['flashmessage'] = $this->getController()->lang->gT("Survey was successfully added."); // Update survey permissions Survey_permissions::model()->giveAllSurveyPermissions(Yii::app()->session['loginID'], $iNewSurveyid); $this->getController()->redirect($this->getController()->createUrl('admin/survey/sa/view/surveyid/' . $iNewSurveyid)); } }