/** * RPC Routine to add an empty group with minimum details. * Used as a placeholder for importing questions. * Returns the groupid of the created group. * * @access public * @param string $sSessionKey Auth credentials * @param int $iSurveyID Dd of the Survey to add the group * @param string $sGroupTitle Name of the group * @param string $sGroupDescription Optional description of the group * @return array|int The id of the new group - Or status */ public function add_group($sSessionKey, $iSurveyID, $sGroupTitle, $sGroupDescription = '') { if ($this->_checkSessionKey($sSessionKey)) { if (Permission::model()->hasSurveyPermission($iSurveyID, 'survey', 'update')) { $oSurvey = Survey::model()->findByPk($iSurveyID); if (!isset($oSurvey)) { return array('status' => 'Error: Invalid survey ID'); } if ($oSurvey['active'] == 'Y') { return array('status' => 'Error:Survey is active and not editable'); } $oGroup = new QuestionGroup(); $oGroup->sid = $iSurveyID; $oGroup->group_name = $sGroupTitle; $oGroup->description = $sGroupDescription; $oGroup->group_order = getMaxGroupOrder($iSurveyID); $oGroup->language = Survey::model()->findByPk($iSurveyID)->language; if ($oGroup->save()) { return (int) $oGroup->gid; } else { return array('status' => 'Creation Failed'); } } else { return array('status' => 'No permission'); } } else { return array('status' => 'Invalid Session Key'); } }
/** * Insert the new group to the database * * @access public * @param int $surveyid * @return void */ public function insert($surveyid) { if (Permission::model()->hasSurveyPermission($surveyid, 'surveycontent', 'create')) { Yii::app()->loadHelper('surveytranslator'); $grplangs = Survey::model()->findByPk($surveyid)->additionalLanguages; $baselang = Survey::model()->findByPk($surveyid)->language; $grplangs[] = $baselang; $errorstring = ''; foreach ($grplangs as $grouplang) { if (empty($_POST['group_name_' . $grouplang])) { $errorstring .= getLanguageNameFromCode($grouplang, false) . "\\n"; } } if ($errorstring != '') { $this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $surveyid)); } else { $first = true; foreach ($grplangs as $grouplang) { //Clean XSS $group_name = $_POST['group_name_' . $grouplang]; $group_description = $_POST['description_' . $grouplang]; $group_name = html_entity_decode($group_name, ENT_QUOTES, "UTF-8"); $group_description = html_entity_decode($group_description, ENT_QUOTES, "UTF-8"); // Fix bug with FCKEditor saving strange BR types $group_name = fixCKeditorText($group_name); $group_description = fixCKeditorText($group_description); if ($first) { $aData = array('sid' => $surveyid, 'group_name' => $group_name, 'description' => $group_description, 'group_order' => getMaxGroupOrder($surveyid), 'language' => $grouplang, 'randomization_group' => $_POST['randomization_group'], 'grelevance' => $_POST['grelevance']); $group = new QuestionGroup(); foreach ($aData as $k => $v) { $group->{$k} = $v; } $group->save(); $groupid = $group->gid; $first = false; } else { switchMSSQLIdentityInsert('groups', true); $aData = array('gid' => $groupid, 'sid' => $surveyid, 'group_name' => $group_name, 'description' => $group_description, 'group_order' => getMaxGroupOrder($surveyid), 'language' => $grouplang, 'randomization_group' => $_POST['randomization_group']); $group = new QuestionGroup(); foreach ($aData as $k => $v) { $group->{$k} = $v; } $group->save(); switchMSSQLIdentityInsert('groups', false); } } // This line sets the newly inserted group as the new group if (isset($groupid)) { $gid = $groupid; } else { // Error, redirect back. Yii::app()->setFlashMessage(gT("Question group was not saved. Please check if the survey is active."), 'error'); $this->getController()->redirect(Yii::app()->request->urlReferrer); } $questions = new Question('search'); $questions->gid = $gid; Yii::app()->setFlashMessage(gT("New question group was saved.")); if ($questions->search()->itemCount < 1) { Yii::app()->setFlashMessage(gT('You can now add a question in this group.'), 'warning'); sprintf(gT("Q1 and Q3 calculated using %s"), "<a href='http://mathforum.org/library/drmath/view/60969.html' target='_blank'>" . gT("minitab method") . "</a>"); } } // http://local.lsinst/LimeSurvey_206/index.php/admin/survey/sa/view/surveyid/282267/gid/10 // http://local.lsinst/LimeSurvey_206/index.php//282267/gid/10 $this->getController()->redirect(array('admin/questiongroups/sa/view/surveyid/' . $surveyid . '/gid/' . $gid)); } }
/** * Insert the new group to the database * * @access public * @param int $surveyid * @return void */ public function insert($surveyid) { if (Permission::model()->hasSurveyPermission($surveyid, 'surveycontent', 'create')) { Yii::app()->loadHelper('surveytranslator'); $grplangs = Survey::model()->findByPk($surveyid)->additionalLanguages; $baselang = Survey::model()->findByPk($surveyid)->language; $grplangs[] = $baselang; $errorstring = ''; foreach ($grplangs as $grouplang) { if (empty($_POST['group_name_' . $grouplang])) { $errorstring .= getLanguageNameFromCode($grouplang, false) . "\\n"; } } if ($errorstring != '') { $this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $surveyid)); } else { $first = true; foreach ($grplangs as $grouplang) { //Clean XSS $group_name = $_POST['group_name_' . $grouplang]; $group_description = $_POST['description_' . $grouplang]; $group_name = html_entity_decode($group_name, ENT_QUOTES, "UTF-8"); $group_description = html_entity_decode($group_description, ENT_QUOTES, "UTF-8"); // Fix bug with FCKEditor saving strange BR types $group_name = fixCKeditorText($group_name); $group_description = fixCKeditorText($group_description); if ($first) { $aData = array('sid' => $surveyid, 'group_name' => $group_name, 'description' => $group_description, 'group_order' => getMaxGroupOrder($surveyid), 'language' => $grouplang, 'randomization_group' => $_POST['randomization_group'], 'grelevance' => $_POST['grelevance']); $group = new QuestionGroup(); foreach ($aData as $k => $v) { $group->{$k} = $v; } $group->save(); $groupid = $group->gid; $first = false; } else { switchMSSQLIdentityInsert('groups', true); $aData = array('gid' => $groupid, 'sid' => $surveyid, 'group_name' => $group_name, 'description' => $group_description, 'group_order' => getMaxGroupOrder($surveyid), 'language' => $grouplang, 'randomization_group' => $_POST['randomization_group']); $group = new QuestionGroup(); foreach ($aData as $k => $v) { $group->{$k} = $v; } $group->save(); switchMSSQLIdentityInsert('groups', false); } } // This line sets the newly inserted group as the new group if (isset($groupid)) { $gid = $groupid; } Yii::app()->session['flashmessage'] = gT("New question group was saved."); } $this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $surveyid . '/gid/' . $gid)); } }
/** * Insert the new group to the database * * @access public * @param int $surveyid * @return void */ public function insert($surveyid) { if (Permission::model()->hasSurveyPermission($surveyid, 'surveycontent', 'create')) { Yii::app()->loadHelper('surveytranslator'); $sSurveyLanguages = Survey::model()->findByPk($surveyid)->additionalLanguages; $sSurveyLanguages[] = Survey::model()->findByPk($surveyid)->language; $errorstring = ''; foreach ($sSurveyLanguages as $sLanguage) { if (empty($_POST['group_name_' . $sLanguage])) { $errorstring .= getLanguageNameFromCode($sLanguage, false) . "\\n"; } } if ($errorstring != '') { $this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $surveyid)); } else { $sInsertArray = array(); foreach ($sSurveyLanguages as $sLanguage) { $sGroupname = Yii::app()->request->getPost('group_name_' . $sLanguage); $sGroupDescription = Yii::app()->request->getPost('description_' . $sLanguage); // Decode entities $sGroupname = html_entity_decode($sGroupname, ENT_QUOTES, "UTF-8"); $sGroupDescription = html_entity_decode($sGroupDescription, ENT_QUOTES, "UTF-8"); // Fix bug with FCKEditor saving strange BR types $sGroupname = fixCKeditorText($sGroupname); $sGroupDescription = fixCKeditorText($sGroupDescription); $sInsertArray[$sLanguage] = array('sid' => $surveyid, 'group_name' => $sGroupname, 'description' => $sGroupDescription, 'group_order' => getMaxGroupOrder($surveyid), 'language' => $sLanguage, 'randomization_group' => Yii::app()->request->getPost('randomization_group'), 'grelevance' => Yii::app()->request->getPost('grelevance')); } $newGroupID = QuestionGroup::model()->insertNewGroup($sInsertArray); if ($newGroupID === false) { // Error, redirect back. Yii::app()->setFlashMessage(gT("Question group was not saved. Please check if the survey is active."), 'error'); $this->getController()->redirect(Yii::app()->request->urlReferrer); } $questions = new Question('search'); $questions->gid = $newGroupID; Yii::app()->setFlashMessage(gT("New question group was saved.")); if ($questions->search()->itemCount < 1) { Yii::app()->setFlashMessage(sprintf(gT('You can now %sadd a question%s in this group.'), '<a href="' . Yii::app()->createUrl("admin/questions/sa/newquestion/surveyid/{$surveyid}/gid/{$newGroupID}") . '">', '</a>'), 'info'); } if (Yii::app()->request->getPost('close-after-save') === 'true') { $this->getController()->redirect(array("admin/questiongroups/sa/view/surveyid/{$surveyid}/gid/{$newGroupID}")); } else { // After save, go to edit $this->getController()->redirect(array("admin/questiongroups/sa/edit/surveyid/{$surveyid}/gid/{$newGroupID}")); } } } else { Yii::app()->user->setFlash('error', gT("Access denied")); $this->getController()->redirect(Yii::app()->request->urlReferrer); } }