/
homepagesettings.php
339 lines (303 loc) · 11.4 KB
/
homepagesettings.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<?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.
*
* Home Page boxes can respect user permissions.
* To that goal, create user groups corresponding (like 'administrator', 'publisher', 'templateeditor') related to the permissions
* Inspired by ACL pattern, see : https://en.wikipedia.org/wiki/Access_control_list
*/
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class homepagesettings extends Survey_Common_Action
{
public function __construct($controller, $id)
{
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('settings', 'read') )
{
Yii::app()->session['flashmessage'] =gT('Access denied!');
$this->getController()->redirect(App()->createUrl("/admin"));
}
$this->_renderWrappedTemplate('homepagesettings', '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('settings', 'update') )
{
Yii::app()->session['flashmessage'] =gT('Access denied!');
$this->getController()->redirect($this->createUrl("/admin/homepagesettings"));
}
$model=new Boxes;
if(isset($_POST['Boxes']))
{
$model->attributes=$_POST['Boxes'];
if($model->save())
{
Yii::app()->user->setFlash('success', gT('New box created'));
if (isset($_POST['saveandclose']))
{
$this->getController()->redirect(array('admin/homepagesettings'));
}
else
{
$this->getController()->redirect(array('admin/homepagesettings/sa/update/id/'.$model->id));
}
}
else
{
Yii::app()->user->setFlash('error', gT('Could not create new box'));
}
}
$this->_renderWrappedTemplate('homepagesettings', 'create', array(
'model'=>$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 update($id)
{
if (! Permission::model()->hasGlobalPermission('settings', 'update') )
{
Yii::app()->session['flashmessage'] =gT('Access denied!');
$this->getController()->redirect($this->createUrl("/admin/homepagesettings"));
}
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Boxes']))
{
$model->attributes=$_POST['Boxes'];
if($model->save())
{
Yii::app()->user->setFlash('success', gT('Box updated'));
if (isset($_POST['saveandclose']))
{
$this->getController()->redirect(array('admin/homepagesettings','id'=>$model->id));
}
}
else
{
Yii::app()->user->setFlash('error', gT('Could not update box'));
}
}
$this->_renderWrappedTemplate('homepagesettings', 'update', array(
'model'=>$model,
));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function delete($id)
{
if (! Permission::model()->hasGlobalPermission('settings', 'update') )
{
Yii::app()->session['flashmessage'] =gT('Access denied!');
$this->getController()->redirect($this->createUrl("/admin/homepagesettings"));
}
$this->loadModel($id)->delete();
Yii::app()->user->setFlash('success', gT('Box deleted'));
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
{
$this->getController()->redirect(array('admin/homepagesettings'));
}
}
/**
* Lists all models.
*/
public function index()
{
if (! Permission::model()->hasGlobalPermission('settings', 'read') )
{
Yii::app()->session['flashmessage'] =gT('Access denied!');
$this->getController()->redirect(App()->createUrl("/admin"));
}
$dataProvider=new CActiveDataProvider('Boxes');
$aData = array(
'dataProvider'=>$dataProvider,
'bShowLogo'=>(getGlobalSetting('show_logo')=="show"),
'bShowLastSurveyAndQuestion'=>(getGlobalSetting('show_last_survey_and_question')=="show"),
'iBoxesByRow'=>(int) getGlobalSetting('boxes_by_row'),
'iBoxesOffset'=>(int) getGlobalSetting('boxes_offset'),
);
$this->_renderWrappedTemplate('homepagesettings', 'index', $aData);
}
/**
* Manages all models.
*/
public function admin()
{
$model=new Boxes('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Boxes']))
$model->attributes=$_GET['Boxes'];
$this->_renderWrappedTemplate('homepagesettings', '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 Boxes the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model=Boxes::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
/**
* Performs the AJAX toggle of show_logo setting
*/
public function toggleShowLogoStatus()
{
if ( Permission::model()->hasGlobalPermission('settings', 'update') )
{
$bNewShowLogo = (getGlobalSetting('show_logo')=="show")?"hide":"show";
setGlobalSetting('show_logo', $bNewShowLogo);
echo $bNewShowLogo;
}
}
/**
* Performs the AJAX toggle of show_last_survey_and_question setting
*/
public function toggleShowLastSurveyAndQuestion()
{
if ( Permission::model()->hasGlobalPermission('settings', 'update') )
{
$bNewShowLastSurveyAndQuestion = (getGlobalSetting('show_last_survey_and_question')=="show")?"hide":"show";
setGlobalSetting('show_last_survey_and_question', $bNewShowLastSurveyAndQuestion);
echo $bNewShowLastSurveyAndQuestion;
}
}
/**
* Performs the AJAX update of box setting
*/
public function setBoxesSettings($boxesbyrow, $boxesoffset)
{
if ( Permission::model()->hasGlobalPermission('settings', 'update') )
{
setGlobalSetting('boxes_by_row', $boxesbyrow);
setGlobalSetting('boxes_offset', $boxesoffset);
return true;
}
}
public function resetall()
{
if ( Permission::model()->hasGlobalPermission('settings', 'update') )
{
// We delete all the old boxes, and reinsert new ones
Boxes::model()->deleteAll();
// Then we recreate them
$oDB = Yii::app()->db;
$oDB->createCommand()->insert('{{boxes}}', array(
'position' => '1',
'url' => 'admin/survey/sa/newsurvey' ,
'title' => 'Create survey' ,
'ico' => 'add' ,
'desc' => 'Create a new survey' ,
'page' => 'welcome',
'usergroup' => '-2',
));
$oDB->createCommand()->insert('{{boxes}}', array(
'position' => '2',
'url' => 'admin/survey/sa/listsurveys',
'title' => 'List surveys',
'ico' => 'list',
'desc' => 'List available surveys',
'page' => 'welcome',
'usergroup' => '-1',
));
$oDB->createCommand()->insert('{{boxes}}', array(
'position' => '3',
'url' => 'admin/globalsettings',
'title' => 'Global settings',
'ico' => 'global',
'desc' => 'Edit global settings',
'page' => 'welcome',
'usergroup' => '-2',
));
$oDB->createCommand()->insert('{{boxes}}', array(
'position' => '4',
'url' => 'admin/update',
'title' => 'ComfortUpdate',
'ico' => 'shield',
'desc' => 'Stay safe and up to date',
'page' => 'welcome',
'usergroup' => '-2',
));
$oDB->createCommand()->insert('{{boxes}}', array(
'position' => '5',
'url' => 'admin/labels/sa/view',
'title' => 'Label sets',
'ico' => 'labels',
'desc' => 'Edit label sets',
'page' => 'welcome',
'usergroup' => '-2',
));
$oDB->createCommand()->insert('{{boxes}}', array(
'position' => '6',
'url' => 'admin/templates/sa/view',
'title' => 'Template editor',
'ico' => 'templates',
'desc' => 'Edit LimeSurvey templates',
'page' => 'welcome',
'usergroup' => '-2',
));
}
$this->getController()->redirect(array('admin/homepagesettings'));
}
/**
* Performs the AJAX validation.
* @param Boxes $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='boxes-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
/**
* Renders template(s) wrapped in header and footer
*
* @param string $sAction Current action, the folder to fetch views from
* @param string|array $aViewUrls View url(s)
* @param array $aData Data to be passed on. Optional.
*/
protected function _renderWrappedTemplate($sAction = '', $aViewUrls = array(), $aData = array())
{
App()->getClientScript()->registerScriptFile( App()->getAssetManager()->publish( ADMIN_SCRIPT_PATH . 'homepagesettings.js' ));
parent::_renderWrappedTemplate($sAction, $aViewUrls, $aData);
}
}