/
AdminController.php
403 lines (351 loc) · 13.2 KB
/
AdminController.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<?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.
*
*/
class AdminController extends LSYii_Controller
{
public $layout = false;
protected $user_id = 0;
/**
* Initialises this controller, does some basic checks and setups
*
* @access protected
* @return void
*/
protected function _init()
{
parent::_init();
App()->getComponent('bootstrap');
$this->_sessioncontrol();
$this->user_id = Yii::app()->user->getId();
if (!Yii::app()->getConfig("surveyid")) {Yii::app()->setConfig("surveyid", returnGlobal('sid'));} //SurveyID
if (!Yii::app()->getConfig("ugid")) {Yii::app()->setConfig("ugid", returnGlobal('ugid'));} //Usergroup-ID
if (!Yii::app()->getConfig("gid")) {Yii::app()->setConfig("gid", returnGlobal('gid'));} //GroupID
if (!Yii::app()->getConfig("qid")) {Yii::app()->setConfig("qid", returnGlobal('qid'));} //QuestionID
if (!Yii::app()->getConfig("lid")) {Yii::app()->setConfig("lid", returnGlobal('lid'));} //LabelID
if (!Yii::app()->getConfig("code")) {Yii::app()->setConfig("code", returnGlobal('code'));} // ??
if (!Yii::app()->getConfig("action")) {Yii::app()->setConfig("action", returnGlobal('action'));} //Desired action
if (!Yii::app()->getConfig("subaction")) {Yii::app()->setConfig("subaction", returnGlobal('subaction'));} //Desired subaction
if (!Yii::app()->getConfig("editedaction")) {Yii::app()->setConfig("editedaction", returnGlobal('editedaction'));} // for html editor integration
// This line is needed for template editor to work
$oAdminTheme = AdminTheme::getInstance();
AdminTheme::staticRegisterScriptFile('ADMIN_SCRIPT_PATH', 'admin_core.js' );
AdminTheme::staticRegisterScriptFile('ADMIN_SCRIPT_PATH', 'notifications.js' );
}
/**
* Shows a nice error message to the world
*
* @access public
* @param string $message The error message
* @return void
*/
public function error($message, $sURL = array())
{
$this->_getAdminHeader();
$sOutput = "<div class='messagebox ui-corner-all'>\n";
$sOutput .= '<div class="warningheader">'.gT('Error').'</div><br />'."\n";
$sOutput .= $message . '<br /><br />'."\n";
if (!empty($sURL) && !is_array($sURL))
{
$sTitle = gT('Back');
}
elseif (!empty($sURL['url']))
{
if (!empty($sURL['title']))
{
$sTitle = $sURL['title'];
}
else
{
$sTitle = gT('Back');
}
$sURL = $sURL['url'];
}
else
{
$sTitle = gT('Main Admin Screen');
$sURL = $this->createUrl('/admin');
}
$sOutput .= '<input type="submit" value="'.$sTitle.'" onclick=\'window.open("'.$sURL.'", "_top")\' /><br /><br />'."\n";
$sOutput .= '</div>'."\n";
$sOutput .= '</div>'."\n";
echo $sOutput;
$this->_getAdminFooter('http://manual.limesurvey.org', gT('LimeSurvey online manual'));
Yii::app()->end();
}
/**
* Load and set session vars
*
* @access protected
* @return void
*/
protected function _sessioncontrol()
{
// From personal settings
if (Yii::app()->request->getPost('action') == 'savepersonalsettings') {
if (Yii::app()->request->getPost('lang')=='auto')
{
$sLanguage= getBrowserLanguage();
}
else
{
$sLanguage=sanitize_languagecode(Yii::app()->request->getPost('lang'));
}
Yii::app()->session['adminlang'] = $sLanguage;
}
if (empty(Yii::app()->session['adminlang']))
Yii::app()->session["adminlang"] = Yii::app()->getConfig("defaultlang");
Yii::app()->setLanguage(Yii::app()->session["adminlang"]);
if (!empty($this->user_id))
$this->_GetSessionUserRights($this->user_id);
}
/**
* Checks for action specific authorization and then executes an action
*
* @access public
* @param string $action
* @return bool
*/
public function run($action)
{
// Check if the DB is up to date
if (Yii::app()->db->schema->getTable('{{surveys}}') )
{
$sDBVersion = getGlobalSetting('DBVersion');
}
if ((int) $sDBVersion < Yii::app()->getConfig('dbversionnumber') && $action != 'databaseupdate')
{
// Try a silent update first
Yii::app()->loadHelper('update/updatedb');
if (!db_upgrade_all(intval($sDBVersion),true)){
$this->redirect(array('/admin/databaseupdate/sa/db'));
}
}
if ($action != "databaseupdate" && $action != "db")
if (empty($this->user_id) && $action != "authentication" && $action != "remotecontrol")
{
if (!empty($action) && $action != 'index')
Yii::app()->session['redirect_after_login'] = $this->createUrl('/');
App()->user->setReturnUrl(App()->request->requestUri);
// If this is an ajax call, don't redirect, but echo login modal instead
$isAjax = isset($_GET['ajax']) && $_GET['ajax'];
if ($isAjax && Yii::app()->user->getIsGuest()) {
Yii::import('application.helpers.admin.ajax_helper', true);
ls\ajax\AjaxHelper::outputNotLoggedIn();
return;
}
$this->redirect(array('/admin/authentication/sa/login'));
}
elseif (!empty($this->user_id) && $action != "remotecontrol")
{
if (Yii::app()->session['session_hash'] != hash('sha256',getGlobalSetting('SessionName').Yii::app()->user->getName().Yii::app()->user->getId()))
{
Yii::app()->session->clear();
Yii::app()->session->close();
$this->redirect(array('/admin/authentication/sa/login'));
}
}
return parent::run($action);
}
/**
* Routes all the actions to their respective places
*
* @access public
* @return array
*/
public function actions()
{
$aActions = $this->getActionClasses();
foreach ($aActions as $action => $class)
{
$aActions[$action] = "application.controllers.admin.{$class}";
}
return $aActions;
}
public function getActionClasses()
{
return array(
'assessments' => 'assessments',
'authentication' => 'authentication',
'checkintegrity' => 'checkintegrity',
'conditions' => 'conditionsaction',
'database' => 'database',
'databaseupdate' => 'databaseupdate',
'dataentry' => 'dataentry',
'dumpdb' => 'dumpdb',
'emailtemplates' => 'emailtemplates',
'export' => 'export',
'expressions' => 'expressions',
'validate' => 'ExpressionValidate',
'globalsettings' => 'globalsettings',
'htmleditor_pop' => 'htmleditor_pop',
'homepagesettings' => 'homepagesettings',
'limereplacementfields' => 'limereplacementfields',
'index' => 'index',
'labels' => 'labels',
'participants' => 'participantsaction',
'pluginmanager' => 'pluginmanager',
'printablesurvey' => 'printablesurvey',
'questiongroups' => 'questiongroups',
'questions' => 'questions',
'quotas' => 'quotas',
'remotecontrol' => 'remotecontrol',
'responses' => 'responses',
'saved' => 'saved',
'statistics' => 'statistics',
'survey' => 'surveyadmin',
'surveypermission' => 'surveypermission',
'user' => 'useraction',
'usergroups' => 'usergroups',
'templates' => 'templates',
'tokens' => 'tokens',
'translate' => 'translate',
'update' => 'update',
'pluginhelper' => 'PluginHelper',
'notification' => 'NotificationController'
);
}
/**
* Set Session User Rights
*
* @access public
* @return void
*/
public function _GetSessionUserRights($loginID)
{
$oUser = User::model()->findByPk($loginID);
// SuperAdmins
// * original superadmin with uid=1 unless manually changed and defined
// in config-defaults.php
// * or any user having USER_RIGHT_SUPERADMIN right
// Let's check if I am the Initial SuperAdmin
$oUser = User::model()->findByAttributes(array('parent_id' => 0));
if (!is_null($oUser) && $oUser->uid == $loginID)
Yii::app()->session['USER_RIGHT_INITIALSUPERADMIN'] = 1;
else
Yii::app()->session['USER_RIGHT_INITIALSUPERADMIN'] = 0;
}
/**
* Prints Admin Header
*
* @access protected
* @param bool $meta
* @param bool $return
* @return mixed
*/
public function _getAdminHeader($meta = false, $return = false)
{
if (empty(Yii::app()->session['adminlang']))
Yii::app()->session["adminlang"] = Yii::app()->getConfig("defaultlang");
$aData = array();
$aData['adminlang'] = Yii::app()->language;
$aData['languageRTL']="";
$aData['styleRTL']="";
Yii::app()->loadHelper("surveytranslator");
if (getLanguageRTL(Yii::app()->language))
{
$aData['languageRTL'] = " dir=\"rtl\" ";
$aData['bIsRTL']=true;
}
else
{
$aData['languageRTL'] = " dir=\"ltr\" ";
$aData['bIsRTL']=false;
}
$aData['meta']="";
if ($meta)
{
$aData['meta']=$meta;
}
$aData['baseurl'] = Yii::app()->baseUrl . '/';
$aData['datepickerlang']="";
$aData['sitename'] = Yii::app()->getConfig("sitename");
$aData['firebug'] = useFirebug();
if (!empty(Yii::app()->session['dateformat']))
$aData['formatdata'] = getDateFormatData(Yii::app()->session['dateformat']);
// Register admin theme package with asset manager
$oAdminTheme = AdminTheme::getInstance();
$aData['sAdmintheme'] = $oAdminTheme->name;
$aData['aPackageScripts']=$aData['aPackageStyles']=array();
//foreach ($aData['aPackageStyles'] as &$filename)
//{
//$filename = str_replace('.css', '-rtl.css', $filename);
//}
$sOutput = $this->renderPartial("/admin/super/header", $aData, true);
if ($return)
{
return $sOutput;
}
else
{
echo $sOutput;
}
}
/**
* Prints Admin Footer
*
* @access protected
* @param string $url
* @param string $explanation
* @param bool $return
* @return mixed
*/
public function _getAdminFooter($url, $explanation, $return = false)
{
$aData['versionnumber'] = Yii::app()->getConfig("versionnumber");
$aData['buildtext'] = "";
if(Yii::app()->getConfig("buildnumber")!="") {
$aData['buildtext']= "+".Yii::app()->getConfig("buildnumber");
}
//If user is not logged in, don't print the version number information in the footer.
if (empty(Yii::app()->session['loginID']))
{
$aData['versionnumber']="";
$aData['versiontitle']="";
$aData['buildtext']="";
}
else
{
$aData['versiontitle'] = gT('Version');
}
$aData['imageurl'] = Yii::app()->getConfig("imageurl");
$aData['url'] = $url;
return $this->renderPartial("/admin/super/footer", $aData, $return);
}
/**
* Shows a message box
*
* @access public
* @param string $title
* @param string $message
* @param string $class
* @return void
*/
public function _showMessageBox($title,$message,$class="message-box-error")
{
$aData['title'] = $title;
$aData['message'] = $message;
$aData['class'] = $class;
$this->renderPartial('/admin/super/messagebox', $aData);
}
public function _loadEndScripts()
{
static $bRendered = false;
if ($bRendered)
return true;
$bRendered = true;
if (empty(Yii::app()->session['metaHeader']))
Yii::app()->session['metaHeader'] = '';
unset(Yii::app()->session['metaHeader']);
return $this->renderPartial('/admin/endScripts_view', array());
}
}