Ejemplo n.º 1
0
 /**
  * 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 (Permission::model()->hasGlobalPermission('surveys', 'create')) {
         // Check if survey title was set
         if (!$_POST['surveyls_title']) {
             Yii::app()->session['flashmessage'] = gT("Survey could not be created because it did not have a title");
             redirect($this->getController()->createUrl('admin'));
             return;
         }
         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");
         }
         $iTokenLength = $_POST['tokenlength'];
         //token length has to be at least 5, otherwise set it to default (15)
         if ($iTokenLength < 5) {
             $iTokenLength = 15;
         }
         if ($iTokenLength > 36) {
             $iTokenLength = 36;
         }
         // Insert base settings into surveys table
         $aInsertData = array('expires' => $sExpiryDate, 'startdate' => $sStartDate, 'template' => App()->request->getPost('template'), 'owner_id' => Yii::app()->session['loginID'], 'admin' => App()->request->getPost('admin'), 'active' => 'N', 'anonymized' => App()->request->getPost('anonymized'), 'faxto' => App()->request->getPost('faxto'), 'format' => App()->request->getPost('format'), 'savetimings' => App()->request->getPost('savetimings'), 'language' => App()->request->getPost('language'), 'datestamp' => App()->request->getPost('datestamp'), 'ipaddr' => App()->request->getPost('ipaddr'), 'refurl' => App()->request->getPost('refurl'), 'usecookie' => App()->request->getPost('usecookie'), 'emailnotificationto' => App()->request->getPost('emailnotificationto'), 'allowregister' => App()->request->getPost('allowregister'), 'allowsave' => App()->request->getPost('allowsave'), 'navigationdelay' => App()->request->getPost('navigationdelay'), 'autoredirect' => App()->request->getPost('autoredirect'), 'showxquestions' => App()->request->getPost('showxquestions'), 'showgroupinfo' => App()->request->getPost('showgroupinfo'), 'showqnumcode' => App()->request->getPost('showqnumcode'), 'shownoanswer' => App()->request->getPost('shownoanswer'), 'showwelcome' => App()->request->getPost('showwelcome'), 'allowprev' => App()->request->getPost('allowprev'), 'questionindex' => App()->request->getPost('questionindex'), 'nokeyboard' => App()->request->getPost('nokeyboard'), 'showprogress' => App()->request->getPost('showprogress'), 'printanswers' => App()->request->getPost('printanswers'), 'listpublic' => App()->request->getPost('public'), 'htmlemail' => App()->request->getPost('htmlemail'), 'sendconfirmation' => App()->request->getPost('sendconfirmation'), 'tokenanswerspersistence' => App()->request->getPost('tokenanswerspersistence'), 'alloweditaftercompletion' => App()->request->getPost('alloweditaftercompletion'), 'usecaptcha' => App()->request->getPost('usecaptcha'), 'publicstatistics' => App()->request->getPost('publicstatistics'), 'publicgraphs' => App()->request->getPost('publicgraphs'), 'assessments' => App()->request->getPost('assessments'), 'emailresponseto' => App()->request->getPost('emailresponseto'), 'tokenlength' => $iTokenLength);
         $warning = '';
         // make sure we only update emails if they are valid
         if (Yii::app()->request->getPost('adminemail', '') == '' || validateEmailAddress(Yii::app()->request->getPost('adminemail'))) {
             $aInsertData['adminemail'] = Yii::app()->request->getPost('adminemail');
         } else {
             $aInsertData['adminemail'] = '';
             $warning .= gT("Warning! Notification email was not updated because it was not valid.") . '<br/>';
         }
         if (Yii::app()->request->getPost('bounce_email', '') == '' || validateEmailAddress(Yii::app()->request->getPost('bounce_email'))) {
             $aInsertData['bounce_email'] = Yii::app()->request->getPost('bounce_email');
         } else {
             $aInsertData['bounce_email'] = '';
             $warning .= gT("Warning! Bounce email was not updated because it was not valid.") . '<br/>';
         }
         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'];
         $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 SurveyLanguageSetting();
         $langsettings->insertNewSurvey($aInsertData);
         Yii::app()->session['flashmessage'] = $warning . gT("Survey was successfully added.");
         // Update survey permissions
         Permission::model()->giveAllSurveyPermissions(Yii::app()->session['loginID'], $iNewSurveyid);
         $this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $iNewSurveyid));
     }
 }
Ejemplo n.º 2
0
 /**
  * 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 (Permission::model()->hasGlobalPermission('surveys', 'create')) {
             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 SurveyLanguageSetting();
                 $langsettings->insertNewSurvey($aInsertData);
                 Permission::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');
     }
 }