/** * 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); } }
/** * 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'); } }
/** * 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); } }