diff --git a/application/config/internal.php b/application/config/internal.php index e0714790123..12c0a8fe2fc 100644 --- a/application/config/internal.php +++ b/application/config/internal.php @@ -64,11 +64,10 @@ 'modules'=>array( 'gii'=>array( - //'class'=>'system.gii.GiiModule', - //'password'=>'toto', - // 'ipFilters'=>array(...a list of IPs...), - // 'newFileMode'=>0666, - // 'newDirMode'=>0777, + 'class'=>'system.gii.GiiModule', + 'password'=>'toto', + 'newFileMode'=>0666, + 'newDirMode'=>0777, ), ), diff --git a/application/controllers/admin/SurveymenuController.php b/application/controllers/admin/SurveymenuController.php new file mode 100644 index 00000000000..44dce7c1e62 --- /dev/null +++ b/application/controllers/admin/SurveymenuController.php @@ -0,0 +1,36 @@ +render('index'); + } + + // Uncomment the following methods and override them if needed + /* + public function filters() + { + // return the filter configuration for this controller, e.g.: + return array( + 'inlineFilterName', + array( + 'class'=>'path.to.FilterClass', + 'propertyName'=>'propertyValue', + ), + ); + } + + public function actions() + { + // return external action classes, e.g.: + return array( + 'action1'=>'path.to.ActionClass', + 'action2'=>array( + 'class'=>'path.to.AnotherActionClass', + 'propertyName'=>'propertyValue', + ), + ); + } + */ +} \ No newline at end of file diff --git a/application/controllers/admin/SurveymenuEntryController.php b/application/controllers/admin/SurveymenuEntryController.php new file mode 100644 index 00000000000..2c05846d2d7 --- /dev/null +++ b/application/controllers/admin/SurveymenuEntryController.php @@ -0,0 +1,36 @@ +render('index'); + } + + // Uncomment the following methods and override them if needed + /* + public function filters() + { + // return the filter configuration for this controller, e.g.: + return array( + 'inlineFilterName', + array( + 'class'=>'path.to.FilterClass', + 'propertyName'=>'propertyValue', + ), + ); + } + + public function actions() + { + // return external action classes, e.g.: + return array( + 'action1'=>'path.to.ActionClass', + 'action2'=>array( + 'class'=>'path.to.AnotherActionClass', + 'propertyName'=>'propertyValue', + ), + ); + } + */ +} \ No newline at end of file diff --git a/application/controllers/admin/surveyadmin.php b/application/controllers/admin/surveyadmin.php index e844ea603bf..eb8bbc2d990 100644 --- a/application/controllers/admin/surveyadmin.php +++ b/application/controllers/admin/surveyadmin.php @@ -491,12 +491,8 @@ public function getAjaxMenuArray($surveyid){ $iSurveyID = sanitize_int($surveyid); $survey = Survey::model()->findByPk($iSurveyID); $baselang = $survey->language; - //$menu_items = $this->_collectMenuItems($currentMenu); - - return Yii::app()->getController()->renderPartial( - '/admin/super/_renderJson', - array( - 'data' => array( + $menus = $survey->getSurveyMenus(); + $propArray = array( 'menuEntries' => [ [ 'active' => false, @@ -516,7 +512,12 @@ public function getAjaxMenuArray($surveyid){ 'name' => gT('Language'), 'link' => $this->getController()->createUrl("admin/survey/sa/editlanguagesettings",['surveyid' => $surveyid]) ], - ], + ]); + return Yii::app()->getController()->renderPartial( + '/admin/super/_renderJson', + array( + 'data' => [ + 'menues'=> $menus, 'settings' => array( 'extrasettings' => false, 'parseHTML' => false, @@ -530,7 +531,7 @@ public function getAjaxMenuArray($surveyid){ // $setting_entry, // $lastquestiongroup // ] - ) + ] ), false, false @@ -926,23 +927,83 @@ public function editSurvey_json() } /** - * Edit surveytexts and general settings + * New system of rendering content + * Based on yii submenu rendering + * + * @param [int] $iSurveyID + * @param [string] $subaction + * @return void */ + public function rendersidemenulink($iSurveyID, $subaction){ + $aViewUrls = $aData = $activePanels = []; + $menuaction = (String) $subaction; + $iSurveyID = sanitize_int($iSurveyID); - public function surveygeneralsettings($iSurveyID){ - $aViewUrls = $aData = $activePanels = array(); + //Get all languages + $grplangs = Survey::model()->findByPk($iSurveyID)->additionalLanguages; + $baselang = Survey::model()->findByPk($iSurveyID)->language; + array_unshift($grplangs, $baselang); + + //Get surveyinfo + $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo; - $pageTitle=gT("Edit survey text elements and settings"); - if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'read') && !Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read')) + //@TODO add language checks here + $menuEntry = SurveymenuEntries::model()->find(['condition' => 'name="'.$menuaction.'"']); + + $esrow = self::_fetchSurveyInfo('editsurvey', $iSurveyID); + + if (!(Permission::model()->hasSurveyPermission($iSurveyID, $menuEntry->permission, $menuEntry->permission_grade))) { - $pageTitle=gT("Edit survey text elements"); + Yii::app()->setFlashMessage(gT("You do not have permission to access this page."),'error'); + $this->getController()->redirect(array('admin/survey','sa'=>'view','surveyid'=>$iSurveyID)); + Yii::app()->end(); } - elseif (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'read') && Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read')) + + if( empty($menuEntry->data)) + { + $templateData = call_user_func_array(array($this,$menuEntry->getdatamethod), array('surveyid'=> $iSurveyID, 'esrow' => $esrow)); + } + else { - $pageTitle=gT("Edit survey settings"); + $templateData = $menuEntry->data; } + + $templateData = array_merge($this->_getGeneralTemplateData($iSurveyID), $templateData); + + $this->_registerScriptFiles(); + Yii::app()->loadHelper("admin/htmleditor"); + + //Start collecting aData + $aData['surveyid'] = $iSurveyID; + $aData['menuaction'] = $menuaction; + $aData['template'] = $menuEntry->template; + $aData['templateData'] = $templateData; + $aData['surveyls_language'] = $baselang; + $aData['action'] = $menuEntry->action; + $aData['entryData'] = $menuEntry->attributes; + $aData['dateformatdetails'] = getDateFormatData(Yii::app()->session['dateformat']); + $aData['display']['menu_bars']['surveysummary'] = $menuEntry->title; + $aData['title_bar']['title'] = $surveyinfo['surveyls_title']." (".gT("ID").":".$iSurveyID.")"; + $aData['surveybar']['savebutton']['form'] = 'globalsetting'; + $aData['surveybar']['savebutton']['useformid'] = 'true'; + $aData['surveybar']['saveandclosebutton']['form'] = true; + $aData['surveybar']['closebutton']['url'] = $this->getController()->createUrl("'admin/survey/sa/view/",['surveyid' => $iSurveyID]); // Close button + + $aViewUrls[] = $menuEntry->template; + + $this->_renderWrappedTemplate('survey', $aViewUrls, $aData); + } + + /** + * Edit surveytexts and general settings + */ + public function surveygeneralsettings($iSurveyID){ + $aViewUrls = $aData = $activePanels = array(); $aData['surveyid'] = $iSurveyID = sanitize_int($iSurveyID); + + + if (!(Permission::model()->hasSurveyPermission($iSurveyID, 'surveylocale', 'read') || Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'read'))) { Yii::app()->setFlashMessage(gT("You do not have permission to access this page."),'error'); @@ -962,7 +1023,7 @@ public function surveygeneralsettings($iSurveyID){ $grplangs = Survey::model()->findByPk($iSurveyID)->additionalLanguages; $baselang = Survey::model()->findByPk($iSurveyID)->language; array_unshift($grplangs, $baselang); - + ### Yii::app()->loadHelper("admin/htmleditor"); $aData['scripts'] = PrepareEditorScript(false, $this->getController()); @@ -1555,17 +1616,8 @@ private function _generalTabNewSurvey() return $aData; } - /** - * survey::_generalTabEditSurvey() - * Load "General" tab of edit survey screen. - * @param mixed $iSurveyID - * @param mixed $esrow - * @return - */ - private function _generalTabEditSurvey($iSurveyID, $esrow) - { - $aData['action'] = "editsurveysettings"; - $aData['esrow'] = $esrow; + private function _getGeneralTemplateData($iSurveyID){ + //$aData['action'] = "editsurveysettings"; $aData['surveyid'] = $iSurveyID; // Get users, but we only need id and name (NOT password etc) @@ -1577,6 +1629,24 @@ private function _generalTabEditSurvey($iSurveyID, $esrow) } // Sort users by name asort($aData['users']); + return $aData; + } + + private function _getTextEditData($iSurveyID, $esrow){ + + } + + /** + * survey::_generalTabEditSurvey() + * Load "General" tab of edit survey screen. + * @param mixed $iSurveyID + * @param mixed $esrow + * @return + */ + private function _generalTabEditSurvey($iSurveyID, $esrow) + { + $aData['esrow'] = $esrow; + $beforeSurveySettings = new PluginEvent('beforeSurveySettings'); $beforeSurveySettings->set('survey', $iSurveyID); App()->getPluginManager()->dispatchEvent($beforeSurveySettings); @@ -1590,7 +1660,7 @@ private function _generalTabEditSurvey($iSurveyID, $esrow) * @param mixed $esrow * @return */ - private function _tabPresentationNavigation($esrow) + private function _tabPresentationNavigation($iSurveyID, $esrow) { global $showxquestions, $showgroupinfo, $showqnumcode; @@ -1613,7 +1683,7 @@ private function _tabPresentationNavigation($esrow) * @param mixed $esrow * @return */ - private function _tabPublicationAccess($esrow) + private function _tabPublicationAccess($iSurveyID, $esrow) { $aDateFormatDetails = getDateFormatData(Yii::app()->session['dateformat']); $startdate = ''; @@ -1644,7 +1714,7 @@ private function _tabPublicationAccess($esrow) * @param mixed $esrow * @return */ - private function _tabNotificationDataManagement($esrow) + private function _tabNotificationDataManagement($iSurveyID, $esrow) { $aData['esrow'] = $esrow; return $aData; @@ -1656,14 +1726,14 @@ private function _tabNotificationDataManagement($esrow) * @param mixed $esrow * @return */ - private function _tabTokens($esrow) + private function _tabTokens($iSurveyID, $esrow) { $aData = array(); $aData['esrow'] = $esrow; return $aData; } - private function _tabPanelIntegration($esrow) + private function _tabPanelIntegration($iSurveyID, $esrow) { $aData = array(); return $aData; @@ -1675,7 +1745,7 @@ private function _tabPanelIntegration($esrow) * @param mixed $iSurveyID * @return */ - private function _tabResourceManagement($iSurveyID) + private function _tabResourceManagement($iSurveyID, $esrow) { global $sCKEditorURL; diff --git a/application/models/Survey.php b/application/models/Survey.php index 0e0716df3fc..a1233547f9f 100644 --- a/application/models/Survey.php +++ b/application/models/Survey.php @@ -216,6 +216,7 @@ public function relations() 'owner' => array(self::BELONGS_TO, 'User', 'owner_id', 'together' => true), 'groups' => array(self::HAS_MANY, 'QuestionGroup', 'sid', 'together' => true), 'quotas' => array(self::HAS_MANY, 'Quota', 'sid','order'=>'name ASC'), + 'surveymenus' => array(self::HAS_MANY, 'Surveymenu', array('survey_id' => 'sid')), ); } @@ -538,6 +539,69 @@ public function getGoogleanalyticsapikey(){ } + private function _getDefaultSurveyMenu(){ + $oDefaultMenu = Surveymenu::model()->findByPk(1); + //Posibility to add more languages to the database is given, so it is possible to add a call by language + //Also for peripheral menues we may add submenus someday. + $defaultMenuEntries = $oDefaultMenu->surveymenuEntries; + $aResult = [ + "title" => $oDefaultMenu->title, + "description" => $oDefaultMenu->description, + "entries" => [ + [ + 'id'=> "0", + 'link'=> App()->getController()->createUrl("admin/survey/sa/view",['surveyid' => $this->sid]), + 'menu_class'=> "", + 'menu_description'=> "Survey overwiew", + 'menu_icon'=> "list", + 'menu_icon_type'=> "fontawesome", + 'menu_id'=> "1", + 'menu_title'=> "Overview", + 'name'=> "overview", + 'title'=> "General overview", + ] + ] + ]; + foreach($defaultMenuEntries as $menuEntry){ + $aEntry = $menuEntry->attributes; + $aEntry['link'] = App()->getController()->createUrl("admin/survey/sa/rendersidemenulink",['surveyid' => $this->sid, 'subaction' => $aEntry['name'] ]); + $aResult["entries"][] = $aEntry; + } + return $aResult; + } + + + /** + * Get surveymenu configuration + * This will be made bigger in future releases, but right now it only collects the default menu-entries + */ + public function getSurveyMenus(){ + + $aSurveyMenus = []; + + //Get the default menu + $aSurveyMenus[] = $this->_getDefaultSurveyMenu(); + + //get all survey specific menus + foreach($this->surveymenus as $menu){ + $aMenuResult = [ + "title" => $menu->title, + "description" => $menu->description, + "entries" => [] + ]; + + foreach($menu->surveymenuEntries as $menuEntry){ + $aEntry = $menuEntry->attributes; + $aEntry['link'] = App()->getController()->createUrl("admin/survey/sa/rendersidemenulink",['surveyid' => $this->sid, 'subaction' => $aEntry['name'] ]); + $aMenuResult["entries"][] = $aEntry; + } + $aSurveyMenus[] = $aMenuResult; + } + + //soon to come => Event to add menus for plugins + + return $aSurveyMenus; + } /** * Creates a new survey - does some basic checks of the suppplied data diff --git a/application/models/Surveymenu.php b/application/models/Surveymenu.php new file mode 100644 index 00000000000..9020a2b53e3 --- /dev/null +++ b/application/models/Surveymenu.php @@ -0,0 +1,128 @@ +true), + array('title', 'length', 'max'=>255), + array('description, created_at', 'safe'), + // The following rule is used by search(). + // @todo Please remove those attributes that should not be searched. + array('id, parent_id, survey_id, priority, level, title, description, changed_at, changed_by, created_at, created_by', 'safe', 'on'=>'search'), + ); + } + + /** + * @return array relational rules. + */ + public function relations() + { + // NOTE: you may need to adjust the relation name and the related + // class name for the relations automatically generated below. + return array( + 'surveymenuEntries' => array(self::HAS_MANY, 'SurveymenuEntries', 'menu_id'), + 'survey' => array(self::BELONGS_TO, 'Survey', ''), + ); + } + + /** + * @return array customized attribute labels (name=>label) + */ + public function attributeLabels() + { + return array( + 'id' => 'ID', + 'parent_id' => 'Parent', + 'survey_id' => 'Survey', + 'priority' => 'Priority', + 'level' => 'Level', + 'title' => 'Title', + 'description' => 'Description', + 'changed_at' => 'Changed At', + 'changed_by' => 'Changed By', + 'created_at' => 'Created At', + 'created_by' => 'Created By', + ); + } + + /** + * Retrieves a list of models based on the current search/filter conditions. + * + * Typical usecase: + * - Initialize the model fields with values from filter form. + * - Execute this method to get CActiveDataProvider instance which will filter + * models according to data in model fields. + * - Pass data provider to CGridView, CListView or any similar widget. + * + * @return CActiveDataProvider the data provider that can return the models + * based on the search/filter conditions. + */ + public function search() + { + // @todo Please modify the following code to remove attributes that should not be searched. + + $criteria=new CDbCriteria; + + $criteria->compare('id',$this->id); + $criteria->compare('parent_id',$this->parent_id); + $criteria->compare('survey_id',$this->survey_id); + $criteria->compare('priority',$this->priority); + $criteria->compare('level',$this->level); + $criteria->compare('title',$this->title,true); + $criteria->compare('description',$this->description,true); + $criteria->compare('changed_at',$this->changed_at,true); + $criteria->compare('changed_by',$this->changed_by); + $criteria->compare('created_at',$this->created_at,true); + $criteria->compare('created_by',$this->created_by); + + return new CActiveDataProvider($this, array( + 'criteria'=>$criteria, + )); + } + + /** + * Returns the static model of the specified AR class. + * Please note that you should have this exact method in all your CActiveRecord descendants! + * @param string $className active record class name. + * @return Surveymenu the static model class + */ + public static function model($className=__CLASS__) + { + return parent::model($className); + } +} diff --git a/application/models/SurveymenuEntries.php b/application/models/SurveymenuEntries.php new file mode 100644 index 00000000000..99798abd38f --- /dev/null +++ b/application/models/SurveymenuEntries.php @@ -0,0 +1,160 @@ +true), + array('title, menu_title, menu_icon, menu_class, action, template, partial, permission, permissionGrade, classes, getdatamethod', 'length', 'max'=>255), + array('description, menu_description, language, data, created_at', 'safe'), + // The following rule is used by search(). + // @todo Please remove those attributes that should not be searched. + array('id, menu_id, priority, title, description, menu_title, menu_description, menu_icon, menu_class, action, template, partial, language, permission, permissionGrade, classes, data, getdatamethod, changed_at, changed_by, created_at, created_by', 'safe', 'on'=>'search'), + ); + } + + /** + * @return array relational rules. + */ + public function relations() + { + // NOTE: you may need to adjust the relation name and the related + // class name for the relations automatically generated below. + return array( + 'menu' => array(self::BELONGS_TO, 'Surveymenu', 'menu_id'), + ); + } + + /** + * @return array customized attribute labels (name=>label) + */ + public function attributeLabels() + { + return array( + 'id' => 'ID', + 'menu_id' => 'Menu', + 'priority' => 'Priority', + 'title' => 'Title', + 'description' => 'Description', + 'menu_title' => 'Menu Title', + 'menu_description' => 'Menu Description', + 'menu_icon' => 'Menu Icon', + 'menu_class' => 'Menu Class', + 'action' => 'Action', + 'template' => 'Template', + 'partial' => 'Partial', + 'language' => 'Language', + 'permission' => 'Permission', + 'permissionGrade' => 'Permission Grade', + 'classes' => 'Classes', + 'data' => 'Data', + 'getdatamethod' => 'Getdatamethod', + 'changed_at' => 'Changed At', + 'changed_by' => 'Changed By', + 'created_at' => 'Created At', + 'created_by' => 'Created By', + ); + } + + /** + * Retrieves a list of models based on the current search/filter conditions. + * + * Typical usecase: + * - Initialize the model fields with values from filter form. + * - Execute this method to get CActiveDataProvider instance which will filter + * models according to data in model fields. + * - Pass data provider to CGridView, CListView or any similar widget. + * + * @return CActiveDataProvider the data provider that can return the models + * based on the search/filter conditions. + */ + public function search() + { + // @todo Please modify the following code to remove attributes that should not be searched. + + $criteria=new CDbCriteria; + + $criteria->compare('id',$this->id); + $criteria->compare('menu_id',$this->menu_id); + $criteria->compare('priority',$this->priority); + $criteria->compare('title',$this->title,true); + $criteria->compare('description',$this->description,true); + $criteria->compare('menu_title',$this->menu_title,true); + $criteria->compare('menu_description',$this->menu_description,true); + $criteria->compare('menu_icon',$this->menu_icon,true); + $criteria->compare('menu_class',$this->menu_class,true); + $criteria->compare('action',$this->action,true); + $criteria->compare('template',$this->template,true); + $criteria->compare('partial',$this->partial,true); + $criteria->compare('language',$this->language,true); + $criteria->compare('permission',$this->permission,true); + $criteria->compare('permissionGrade',$this->permissionGrade,true); + $criteria->compare('classes',$this->classes,true); + $criteria->compare('data',$this->data,true); + $criteria->compare('getdatamethod',$this->getdatamethod,true); + $criteria->compare('changed_at',$this->changed_at,true); + $criteria->compare('changed_by',$this->changed_by); + $criteria->compare('created_at',$this->created_at,true); + $criteria->compare('created_by',$this->created_by); + + return new CActiveDataProvider($this, array( + 'criteria'=>$criteria, + )); + } + + /** + * Returns the static model of the specified AR class. + * Please note that you should have this exact method in all your CActiveRecord descendants! + * @param string $className active record class name. + * @return SurveymenuEntries the static model class + */ + public static function model($className=__CLASS__) + { + return parent::model($className); + } +} diff --git a/application/views/admin/survey/editLocalSettings_main_view.php b/application/views/admin/survey/editLocalSettings_main_view.php index 07e5337f33d..cacebbfee09 100644 --- a/application/views/admin/survey/editLocalSettings_main_view.php +++ b/application/views/admin/survey/editLocalSettings_main_view.php @@ -18,21 +18,19 @@
- | ||||||
---|---|---|---|---|---|---|
+ |
'.gT("If the option -Anonymized responses- is activated only a dummy date stamp (1980-01-01) will be used for all responses to ensure the anonymity of your participants.").'
', + 'footer' => TbHtml::button('Close', array('data-dismiss' => 'modal')) + )); + } + ?> +'.gT("If the option -Anonymized responses- is activated only a dummy date stamp (1980-01-01) will be used for all responses to ensure the anonymity of your participants.").'
', - 'footer' => TbHtml::button('Close', array('data-dismiss' => 'modal')) + 'name' => 'ipaddr', + 'value'=> $esrow['ipaddr'] == "Y", + 'onLabel'=>gT('On'), + 'offLabel'=>gT('Off') )); - } - ?> + } ?> +