/
templateoptions.php
229 lines (194 loc) · 7.71 KB
/
templateoptions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* Template Options controller
*/
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class templateoptions extends Survey_Common_Action
{
public function __construct($controller=null, $id=null)
{
parent::__construct($controller, $id);
}
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function view($id)
{
if (!Permission::model()->hasGlobalPermission('templates','read')){
Yii::app()->session['flashmessage'] =gT('Access denied!');
$this->getController()->redirect(App()->createUrl("/admin"));
}
$this->_renderWrappedTemplate('templateoptions', 'read', array(
'model'=>$this->loadModel($id),
));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function create()
{
if (!Permission::model()->hasGlobalPermission('templates','update')){
die('No permission');
}
$model = new TemplateOptions;
$model->bUseMagicInherit = false;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['TemplateOptions']))
{
$model->attributes=$_POST['TemplateOptions'];
if($model->save())
$this->getController()->redirect(array('admin/templateoptions/sa/update/id/'.$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
private function _updateCommon($model,$sid=null){
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
$oModelWithInheritReplacement = TemplateConfiguration::model()->findByPk($model->id);
$templateOptionPage = $oModelWithInheritReplacement->optionPage;
yii::app()->clientScript->registerPackage('bootstrap-switch');
$aData = array(
'model'=>$model,
'templateOptionPage' => $templateOptionPage
);
if($sid !== null){
$aData['surveyid'] = $sid;
$aData['title_bar']['title'] = gT("Survey template options");
$aData['subaction'] = gT("Survey template options");
}
$this->_renderWrappedTemplate('templateoptions', 'update', $aData);
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function update($id)
{
if (! Permission::model()->hasGlobalPermission('templates', 'update')){
Yii::app()->setFlashMessage(gT('Access denied!'),'error');
$this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/templateoptions"));
}
$model = $this->loadModel($id);
$model->bUseMagicInherit = false;
if(isset($_POST['TemplateConfiguration'])){
$model->attributes=$_POST['TemplateConfiguration'];
if($model->save())
$this->getController()->redirect(array('admin/templateoptions/sa/update/id/'.$model->id));
}
$this->_updateCommon($model);
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function updatesurvey($sid)
{
if (! Permission::model()->hasGlobalPermission('templates', 'update')){
Yii::app()->setFlashMessage(gT('Access denied!'),'error');
$this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/templateoptions/sa/updatesurvey",['surveyid'=>$sid,'sid'=>$sid]));
}
$model = Template::getTemplateConfiguration(null, $sid);
$model->bUseMagicInherit = false;
if(isset($_POST['TemplateConfiguration'])){
$model->attributes=$_POST['TemplateConfiguration'];
if($model->save())
$this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/templateoptions/sa/updatesurvey",['surveyid'=>$sid,'sid'=>$sid]));
}
$this->_updateCommon($model, $sid);
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function updatesurveygroup($gsid)
{
if (! Permission::model()->hasGlobalPermission('templates', 'update')){
Yii::app()->setFlashMessage(gT('Access denied!'),'error');
$this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/surveysgroups/sa/update/",['id'=>$gsid]));
}
$model = Template::getTemplateConfiguration(null, null, $gsid);
$model->bUseMagicInherit = false;
if(isset($_POST['TemplateConfiguration'])){
$model->attributes=$_POST['TemplateConfiguration'];
if($model->save())
$this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/surveysgroups/sa/update/",['id'=>$gsid]));
}
$this->_updateCommon($model, $sid);
}
/**
* Lists all models.
*/
public function index()
{
if (! Permission::model()->hasGlobalPermission('templates', 'read') ){
Yii::app()->session['flashmessage'] =gT('Access denied!');
$this->getController()->redirect(App()->createUrl("/admin"));
}
$aData = array();
$model = new TemplateConfiguration('search');
$model->bUseMagicInherit = false;
$model->sid = $model->gsid = $model->uid = null;
$aData['model'] = $model;
$this->_renderWrappedTemplate('templateoptions', 'index', $aData);
}
/**
* Manages all models.
*/
public function admin()
{
$model=new TemplateOptions('search');
$model->bUseMagicInherit = false;
$model->unsetAttributes(); // clear any default values
if(isset($_GET['TemplateOptions']))
$model->attributes=$_GET['TemplateOptions'];
$this->render('admin',array(
'model'=>$model,
));
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer $id the ID of the model to be loaded
* @return TemplateOptions the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model=TemplateConfiguration::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
$model->bUseMagicInherit = false;
return $model;
}
/**
* Performs the AJAX validation.
* @param TemplateOptions $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='template-options-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}