-
Notifications
You must be signed in to change notification settings - Fork 985
/
surveypermission.php
616 lines (540 loc) · 29.2 KB
/
surveypermission.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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* 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.
*
* $Id$
*/
/**
* surveypermission
*
* @package LimeSurvey
* @copyright 2011
* @version $Id$
* @access public
*/
class surveypermission extends Survey_Common_Action {
/**
* Load survey security screen.
* @param mixed $surveyid
* @return void
*/
function index($surveyid)
{
$aData['surveyid'] = $surveyid = sanitize_int($surveyid);
$aViewUrls = array();
$clang = Yii::app()->lang;
$imageurl = Yii::app()->getConfig('adminimageurl');
if(hasSurveyPermission($surveyid,'survey','read'))
{
$aBaseSurveyPermissions=Survey_permissions::model()->getBasePermissions();
$this->getController()->_js_admin_includes(Yii::app()->getConfig('generalscripts') . 'jquery/jquery.tablesorter.min.js');
$this->getController()->_js_admin_includes(Yii::app()->getConfig('adminscripts') . 'surveysecurity.js');
$result2 = Survey_permissions::model()->getUserDetails($surveyid);
$surveysecurity ="<div class='header ui-widget-header'>".$clang->gT("Survey permissions")."</div>\n"
. "<table class='surveysecurity'><thead>"
. "<tr>\n"
. "<th>".$clang->gT("Action")."</th>\n"
. "<th>".$clang->gT("Username")."</th>\n"
. "<th>".$clang->gT("User group")."</th>\n"
. "<th>".$clang->gT("Full name")."</th>\n";
foreach ($aBaseSurveyPermissions as $sPermission=>$aSubPermissions )
{
$surveysecurity.="<th><img src=\"{$imageurl}{$aSubPermissions['img']}_30.png\" alt=\"<span style='font-weight:bold;'>".$aSubPermissions['title']."</span><br />".$aSubPermissions['description']."\" /></th>\n";
}
$surveysecurity .= "</tr></thead>\n";
// Foot first
if (Yii::app()->getConfig('usercontrolSameGroupPolicy') == true)
{
$authorizedGroupsList = getUserGroupList(NULL,'simplegidarray');
}
$surveysecurity .= "<tbody>\n";
if(count($result2) > 0)
{
// output users
$row = 0;
foreach ($result2 as $PermissionRow)
{
$result3 = User_in_groups::model()->with('users')->findAll('users.uid = :uid',array(':uid' => $PermissionRow['uid']));
foreach ($result3 as $resul3row)
{
if (Yii::app()->getConfig('usercontrolSameGroupPolicy') == false ||
in_array($resul3row->ugid,$authorizedGroupsList))
{
$group_ids[] = $resul3row->ugid;
}
}
if(isset($group_ids) && $group_ids[0] != NULL)
{
$group_ids_query = implode(" OR ugid=", $group_ids);
unset($group_ids);
$result4 = User_groups::model()->findAll('ugid = :ugid',array(':ugid' => $group_ids_query));
foreach ($result4 as $resul4row)
{
$group_names[] = $resul4row->name;
}
if(count($group_names) > 0)
$group_names_query = implode(", ", $group_names);
}
// else {break;} //TODO Commented by lemeur
$surveysecurity .= "<tr>\n";
$surveysecurity .= "<td>\n";
$surveysecurity .= "<form style='display:inline;' method='post' action='".$this->getController()->createUrl('admin/surveypermission/set/surveyid/'.$surveyid)."'>"
."<input type='image' src='{$imageurl}edit_16.png' alt='".$clang->gT("Edit permissions")."' />"
."<input type='hidden' name='action' value='setsurveysecurity' />"
."<input type='hidden' name='user' value='{$PermissionRow['users_name']}' />"
."<input type='hidden' name='uid' value='{$PermissionRow['uid']}' />"
."</form>\n";
$surveysecurity .= "<form style='display:inline;' method='post' action='".$this->getController()->createUrl('admin/surveypermission/delete/surveyid/'.$surveyid)."'>"
."<input type='image' src='{$imageurl}/token_delete.png' alt='".$clang->gT("Delete")."' onclick='return confirm(\"".$clang->gT("Are you sure you want to delete this entry?","js")."\")' />"
."<input type='hidden' name='action' value='delsurveysecurity' />"
."<input type='hidden' name='user' value='{$PermissionRow['users_name']}' />"
."<input type='hidden' name='uid' value='{$PermissionRow['uid']}' />"
."</form>";
$surveysecurity .= "</td>\n";
$surveysecurity .= "<td>{$PermissionRow['users_name']}</td>\n"
. "<td>";
if(isset($group_names) > 0)
{
$surveysecurity .= $group_names_query;
}
else
{
$surveysecurity .= "---";
}
unset($group_names);
$surveysecurity .= "</td>\n"
. "<td>\n{$PermissionRow['full_name']}</td>\n";
//Now show the permissions
foreach ($aBaseSurveyPermissions as $sPKey=>$aPDetails) {
unset($aPDetails['img']);
unset($aPDetails['description']);
unset($aPDetails['title']);
$iCount=0;
$iPermissionCount=0;
foreach ($aPDetails as $sPDetailKey=>$sPDetailValue)
{
if ($sPDetailValue && hasSurveyPermission($surveyid,$sPKey,$sPDetailKey,$PermissionRow['uid']) && !($sPKey=='survey' && $sPDetailKey=='read')) $iCount++;
if ($sPDetailValue) $iPermissionCount++;
}
if ($sPKey=='survey') $iPermissionCount--;
if ($iCount==$iPermissionCount) {
$insert = "<div class=\"ui-icon ui-icon-check\"> </div>";
}
elseif ($iCount>0){
$insert = "<div class=\"ui-icon ui-icon-check mixed\"> </div>";
}
else
{
$insert = "<div> </div>";
}
$surveysecurity .= "<td>\n$insert\n</td>\n";
}
$surveysecurity .= "</tr>\n";
$row++;
}
} else {
$surveysecurity .= "<tr><td colspan='16'></td></tr>"; //fix error on empty table
}
$surveysecurity .= "</tbody>\n"
. "</table>\n"
. "<form class='form44' action='".$this->getController()->createUrl('admin/surveypermission/adduser/surveyid/'.$surveyid)."' method='post'><ul>\n"
. "<li><label for='uidselect'>".$clang->gT("User").": </label><select id='uidselect' name='uid'>\n"
. getSurveyUserList(false,false,$surveyid)
. "</select>\n"
. "<input style='width: 15em;' type='submit' value='".$clang->gT("Add User")."' onclick=\"if (document.getElementById('uidselect').value == -1) { alert('".$clang->gT("Please select a user first","js")."'); return false;}\"/>"
. "<input type='hidden' name='action' value='addsurveysecurity' />"
. "</li></ul></form>\n"
. "<form class='form44' action='".$this->getController()->createUrl('admin/surveypermission/addusergroup/surveyid/'.$surveyid)."' method='post'><ul><li>\n"
. "<label for='ugidselect'>".$clang->gT("Groups").": </label><select id='ugidselect' name='ugid'>\n"
. getSurveyUserGroupList('htmloptions',$surveyid)
. "</select>\n"
. "<input style='width: 15em;' type='submit' value='".$clang->gT("Add user group")."' onclick=\"if (document.getElementById('ugidselect').value == -1) { alert('".$clang->gT("Please select a user group first","js")."'); return false;}\" />"
. "<input type='hidden' name='action' value='addusergroupsurveysecurity' />\n"
. "</li></ul></form>";
$aViewUrls['output'] = $surveysecurity;
}
else
{
accessDenied();
}
$this->_renderWrappedTemplate('authentication', $aViewUrls, $aData);
}
/**
* surveypermission::addusergroup()
* Function responsible to add usergroup.
* @param mixed $surveyid
* @return void
*/
function addusergroup($surveyid)
{
$aData['surveyid'] = $surveyid = sanitize_int($surveyid);
$aViewUrls = array();
$action = $_POST['action'];
$clang = Yii::app()->lang;
$imageurl = Yii::app()->getConfig('imageurl');
$postusergroupid = !empty($_POST['ugid']) ? $_POST['ugid'] : false;
if($action == "addusergroupsurveysecurity")
{
$addsummary = "<div class=\"header\">".$clang->gT("Add user group")."</div>\n";
$addsummary .= "<div class=\"messagebox ui-corner-all\" >\n";
$result = Survey::model()->findAll('sid = :surveyid AND owner_id = :owner_id',array(':surveyid' => $surveyid, ':owner_id' => Yii::app()->session['loginID']));
if( (count($result) > 0 && in_array($postusergroupid,getSurveyUserGroupList('simpleugidarray',$surveyid))) ||Yii::app()->session['USER_RIGHT_SUPERADMIN'] == 1)
{
if($postusergroupid > 0){
$result2 = User::model()->getCommonUID($surveyid, $postusergroupid); //Checked
if($result2->getRowCount() > 0)
{
foreach ($result2->readAll() as $row2 )
{
$uid_arr[] = $row2['uid'];
$isrresult = Survey_permissions::model()->insertSomeRecords(array('sid' => $surveyid,'uid' => $row2['uid'], 'permission' => 'survey', 'read_p' => 1));
if (!$isrresult) break;
}
if($isrresult)
{
$addsummary .= "<div class=\"successheader\">".$clang->gT("User group added.")."</div>\n";
Yii::app()->session['uids'] = $uid_arr;
$addsummary .= "<br /><form method='post' action='".$this->getController()->createUrl('admin/surveypermission/set/surveyid/'.$surveyid)."'>"
."<input type='submit' value='".$clang->gT("Set Survey Rights")."' />"
."<input type='hidden' name='action' value='setusergroupsurveysecurity' />"
."<input type='hidden' name='ugid' value='{$postusergroupid}' />"
."</form>\n";
}
else
{
// Error while adding user to the database
$addsummary .= "<div class=\"warningheader\">".$clang->gT("Failed to add user group.")."</div>\n";
$addsummary .= "<br/><input type=\"submit\" onclick=\"window.open('".$this->getController()->createUrl('admin/surveypermission/view/surveyid/'.$surveyid)."', '_top')\" value=\"".$clang->gT("Continue")."\"/>\n";
}
}
else
{
// no user to add
$addsummary .= "<div class=\"warningheader\">".$clang->gT("Failed to add user group.")."</div>\n";
$addsummary .= "<br/><input type=\"submit\" onclick=\"window.open('".$this->getController()->createUrl('admin/surveypermission/view/surveyid/'.$surveyid)."', '_top')\" value=\"".$clang->gT("Continue")."\"/>\n";
}
}
else
{
$addsummary .= "<div class=\"warningheader\">".$clang->gT("Failed to add user.")."</div>\n"
. "<br />" . $clang->gT("No Username selected.")."<br />\n";
$addsummary .= "<br/><input type=\"submit\" onclick=\"window.open('".$this->getController()->createUrl('admin/surveypermission/view/surveyid/'.$surveyid)."', '_top')\" value=\"".$clang->gT("Continue")."\"/>\n";
}
}
else
{
accessDenied();
}
$addsummary .= "</div>\n";
$aViewUrls['output'] = $addsummary;
}
$this->_renderWrappedTemplate('authentication', $aViewUrls, $aData);
}
/**
* surveypermission::adduser()
* Function responsible to add user.
* @param mixed $surveyid
* @return void
*/
function adduser($surveyid)
{
$aData['surveyid'] = $surveyid = sanitize_int($surveyid);
$aViewUrls = array();
$action = $_POST['action'];
$clang = Yii::app()->lang;
$imageurl = Yii::app()->getConfig('imageurl');
$postuserid = $_POST['uid'];
if($action == "addsurveysecurity")
{
$addsummary = "<div class='header ui-widget-header'>".$clang->gT("Add User")."</div>\n";
$addsummary .= "<div class=\"messagebox ui-corner-all\">\n";
$result = Survey::model()->findAll('sid = :sid AND owner_id = :owner_id AND owner_id != :postuserid',array(':sid' => $surveyid, ':owner_id' => Yii::app()->session['loginID'], ':postuserid' => $postuserid));
if( (count($result) > 0 && in_array($postuserid,getUserList('onlyuidarray'))) ||
Yii::app()->session['USER_RIGHT_SUPERADMIN'] == 1)
{
if($postuserid > 0){
$isrresult = Survey_permissions::model()->insertSomeRecords(array('sid' => $surveyid, 'uid' => $postuserid, 'permission' => 'survey', 'read_p' => 1));
if($isrresult)
{
$addsummary .= "<div class=\"successheader\">".$clang->gT("User added.")."</div>\n";
$addsummary .= "<br /><form method='post' action='".$this->getController()->createUrl('admin/surveypermission/set/surveyid/'.$surveyid)."'>"
."<input type='submit' value='".$clang->gT("Set survey permissions")."' />"
."<input type='hidden' name='action' value='setsurveysecurity' />"
."<input type='hidden' name='uid' value='{$postuserid}' />"
."</form>\n";
}
else
{
// Username already exists.
$addsummary .= "<div class=\"warningheader\">".$clang->gT("Failed to add user.")."</div>\n"
. "<br />" . $clang->gT("Username already exists.")."<br />\n";
$addsummary .= "<br/><input type=\"submit\" onclick=\"window.open('".$this->getController()->createUrl('admin/surveypermission/view/surveyid/'.$surveyid)."', '_top')\" value=\"".$clang->gT("Continue")."\"/>\n";
}
}
else
{
$addsummary .= "<div class=\"warningheader\">".$clang->gT("Failed to add user.")."</div>\n"
. "<br />" . $clang->gT("No Username selected.")."<br />\n";
$addsummary .= "<br/><input type=\"submit\" onclick=\"window.open('".$this->getController()->createUrl('admin/surveypermission/view/surveyid/'.$surveyid)."', '_top')\" value=\"".$clang->gT("Continue")."\"/>\n";
}
}
else
{
accessDenied();
}
$addsummary .= "</div>\n";
$aViewUrls['output'] = $addsummary;
}
$this->_renderWrappedTemplate('authentication', $aViewUrls, $aData);
}
/**
* surveypermission::set()
* Function responsible to set permissions to a user/usergroup.
* @param mixed $surveyid
* @return void
*/
function set($surveyid)
{
$aData['surveyid'] = $surveyid = sanitize_int($surveyid);
$aViewUrls = array();
$action = $_POST['action'];
$clang = Yii::app()->lang;
$imageurl = Yii::app()->getConfig('adminimageurl');
$postuserid = !empty($_POST['uid']) ? $_POST['uid'] : null;
$postusergroupid = !empty($_POST['ugid']) ? $_POST['ugid'] : null;
if($action == "setsurveysecurity" || $action == "setusergroupsurveysecurity")
{
$where = 'sid = :surveyid AND owner_id = :owner_id ';
$params=array(':surveyid' => $surveyid, ':owner_id' => Yii::app()->session['loginID']);
if ($action == "setsurveysecurity")
{
$where.= "AND owner_id != :postuserid";
$params[':postuserid'] = $postuserid;
}
$result = Survey::model()->findAll($where,$params);
if(count($result) > 0 || Yii::app()->session['USER_RIGHT_SUPERADMIN'] == 1)
{
//$js_admin_includes[]='../scripts/jquery/jquery.tablesorter.min.js';
//$js_admin_includes[]='scripts/surveysecurity.js';
$this->getController()->_js_admin_includes(Yii::app()->getConfig('generalscripts') .'jquery/jquery.tablesorter.min.js');
$this->getController()->_js_admin_includes(Yii::app()->getConfig('adminscripts') . 'surveysecurity.js');
if ($action == "setsurveysecurity")
{
$query = "select users_name from {{users}} where uid=:uid";
$res = Yii::app()->db->createCommand($query)->bindParam(":uid", $postuserid, PDO::PARAM_INT)->query();
$resrow = $res->read();
$sUsername=$resrow['users_name'];
$usersummary = "<div class='header ui-widget-header'>".sprintf($clang->gT("Edit survey permissions for user %s"),"<span style='font-style:italic'>".$sUsername."</span>")."</div>";
}
else
{
$resrow = User_groups::model()->find('ugid = :ugid',array(':ugid' => $postusergroupid));
$sUsergroupName=$resrow['name'];
$usersummary = "<div class='header ui-widget-header'>".sprintf($clang->gT("Edit survey permissions for group %s"),"<span style='font-style:italic'>".$sUsergroupName."</span>")."</div>";
}
$usersummary .= "<br /><form action='".$this->getController()->createUrl('admin/surveypermission/surveyright/surveyid/'.$surveyid)."' method='post'>\n"
. "<table style='margin:0 auto;' class='usersurveypermissions'><thead>\n";
$usersummary .= ""
. "<tr><th></th><th>".$clang->gT("Permission")."</th>\n"
. "<th><input type='button' id='btnToggleAdvanced' value='<<' /></th>\n"
. "<th class='extended'>".$clang->gT("Create")."</th>\n"
. "<th class='extended'>".$clang->gT("View/read")."</th>\n"
. "<th class='extended'>".$clang->gT("Update")."</th>\n"
. "<th class='extended'>".$clang->gT("Delete")."</th>\n"
. "<th class='extended'>".$clang->gT("Import")."</th>\n"
. "<th class='extended'>".$clang->gT("Export")."</th>\n"
. "</tr></thead>\n";
//content
$aBasePermissions=Survey_permissions::model()->getBasePermissions();
$oddcolumn=false;
foreach($aBasePermissions as $sPermissionKey=>$aCRUDPermissions)
{
$oddcolumn=!$oddcolumn;
$usersummary .= "<tr><td><img src='{$imageurl}{$aCRUDPermissions['img']}_30.png' alt='{$aCRUDPermissions['description']}'/></td>";
$usersummary .= "<td>{$aCRUDPermissions['title']}</td>";
$usersummary .= "<td ><input type=\"checkbox\" class=\"markrow\" name='all_{$sPermissionKey}' /></td>";
foreach ($aCRUDPermissions as $sCRUDKey=>$CRUDValue)
{
if (!in_array($sCRUDKey,array('create','read','update','delete','import','export'))) continue;
$usersummary .= "<td class='extended'>";
if ($CRUDValue)
{
if (!($sPermissionKey=='survey' && $sCRUDKey=='read'))
{
$usersummary .= "<input type=\"checkbox\" class=\"checkboxbtn\" name='perm_{$sPermissionKey}_{$sCRUDKey}' ";
if($action=='setsurveysecurity' && hasSurveyPermission( $surveyid,$sPermissionKey,$sCRUDKey,$postuserid)) {
$usersummary .= ' checked="checked" ';
}
$usersummary .=" />";
}
}
$usersummary .= "</td>";
}
$usersummary .= "</tr>";
}
$usersummary .= "\n</table>"
."<p><input type='submit' value='".$clang->gT("Save Now")."' />"
."<input type='hidden' name='perm_survey_read' value='1' />"
."<input type='hidden' name='action' value='surveyrights' />";
if ($action=='setsurveysecurity')
{
$usersummary .="<input type='hidden' name='uid' value='{$postuserid}' />";
}
else
{
$usersummary .="<input type='hidden' name='ugid' value='{$postusergroupid}' />";
}
$usersummary .= "</form>\n";
$aViewUrls['output'] = $usersummary;
}
else
{
include("accessDenied.php");
}
}
$this->_renderWrappedTemplate('authentication', $aViewUrls, $aData);
}
/**
* surveypermission::delete()
* Function responsible to delete a user/usergroup.
* @param mixed $surveyid
* @return void
*/
function delete($surveyid)
{
$aData['surveyid'] = $surveyid = sanitize_int($surveyid);
$aViewUrls = array();
$action = $_POST['action'];
$clang = Yii::app()->lang;
$imageurl = Yii::app()->getConfig('imageurl');
$postuserid = !empty($_POST['uid']) ? $_POST['uid'] : false;
$postusergroupid = !empty($_POST['gid']) ? $_POST['gid'] : false;
if($action == "delsurveysecurity")
{
$addsummary = "<div class=\"header\">".$clang->gT("Deleting User")."</div>\n";
$addsummary .= "<div class=\"messagebox\">\n";
$result = Survey::model()->findAll('sid = :sid AND owner_id = :owner_id AND owner_id != :postuserid',array(':sid' => $surveyid, ':owner_id' => Yii::app()->session['loginID'], ':postuserid' => $postuserid));
if(count($result) > 0 || Yii::app()->session['USER_RIGHT_SUPERADMIN'] == 1)
{
if (isset($postuserid))
{
$dbresult = Survey_permissions::model()->deleteAll('uid = :uid AND sid = :sid',array(':uid' => $postuserid, ':sid' => $surveyid));
$addsummary .= "<br />".$clang->gT("Username").": ".sanitize_xss_string($_POST['user'])."<br /><br />\n";
$addsummary .= "<div class=\"successheader\">".$clang->gT("Success!")."</div>\n";
}
else
{
$addsummary .= "<div class=\"warningheader\">".$clang->gT("Could not delete user. User was not supplied.")."</div>\n";
}
$addsummary .= "<br/><input type=\"submit\" onclick=\"window.open('".$this->getController()->createUrl('admin/surveypermission/view/surveyid/'.$surveyid)."', '_top')\" value=\"".$clang->gT("Continue")."\"/>\n";
}
else
{
accessDenied();
}
$addsummary .= "</div>\n";
$aViewUrls['output'] = $addsummary;
}
$this->_renderWrappedTemplate('authentication', $aViewUrls, $aData);
}
/**
* surveypermission::surveyright()
* Function responsible to process setting of permission of a user/usergroup.
* @param mixed $surveyid
* @return void
*/
function surveyright($surveyid)
{
$aData['surveyid'] = $surveyid = sanitize_int($surveyid);
$aViewUrls = array();
$action = $_POST['action'];
$clang = Yii::app()->lang;
$imageurl = Yii::app()->getConfig('imageurl');
$postuserid = !empty($_POST['uid']) ? $_POST['uid'] : false;
$postusergroupid = !empty($_POST['ugid']) ? $_POST['ugid'] : false;
if ($action == "surveyrights")
{
$addsummary = "<div class='header ui-widget-header'>".$clang->gT("Edit survey permissions")."</div>\n";
$addsummary .= "<div class='messagebox ui-corner-all'>\n";
$where = ' ';
if($postuserid){
if (Yii::app()->session['USER_RIGHT_SUPERADMIN'] != 1)
{
$where .= "sid = :surveyid AND owner_id != :postuserid AND owner_id = :owner_id";
$resrow = Survey::model()->find($where,array(':sid' => $surveyid, ':owner_id' => Yii::app()->session['loginID'], ':postuserid' => $postuserid));
}
}
else{
$where .= "sid = :sid";
$resrow = Survey::model()->find($where,array(':sid' => $surveyid));
$iOwnerID=$resrow['owner_id'];
}
$aBaseSurveyPermissions = Survey_permissions::model()->getBasePermissions();
$aPermissions=array();
foreach ($aBaseSurveyPermissions as $sPermissionKey=>$aCRUDPermissions)
{
foreach ($aCRUDPermissions as $sCRUDKey=>$CRUDValue)
{
if (!in_array($sCRUDKey,array('create','read','update','delete','import','export'))) continue;
if ($CRUDValue)
{
if(isset($_POST["perm_{$sPermissionKey}_{$sCRUDKey}"])){
$aPermissions[$sPermissionKey][$sCRUDKey]=1;
}
else
{
$aPermissions[$sPermissionKey][$sCRUDKey]=0;
}
}
}
}
if (isset($postusergroupid) && $postusergroupid>0)
{
$oResult = User_in_groups::model()->findAll('ugid = :ugid AND uid <> :uid AND uid <> :iOwnerID',array(':ugid' => $postusergroupid, ':uid' => Yii::app()->session['loginID'], ':iOwnerID' => $iOwnerID));
if(count($oResult) > 0)
{
foreach ($oResult as $aRow)
{
Survey_permissions::model()->setPermission($aRow->uid, $surveyid, $aPermissions);
}
$addsummary .= "<div class=\"successheader\">".$clang->gT("Survey permissions for all users in this group were successfully updated.")."</div>\n";
}
}
else
{
if (Survey_permissions::model()->setPermission($postuserid, $surveyid, $aPermissions))
{
$addsummary .= "<div class=\"successheader\">".$clang->gT("Survey permissions were successfully updated.")."</div>\n";
}
else
{
$addsummary .= "<div class=\"warningheader\">".$clang->gT("Failed to update survey permissions!")."</div>\n";
}
}
$addsummary .= "<br/><input type=\"submit\" onclick=\"window.open('".$this->getController()->createUrl('admin/surveypermission/view/surveyid/'.$surveyid)."', '_top')\" value=\"".$clang->gT("Continue")."\"/>\n";
$addsummary .= "</div>\n";
$aViewUrls['output'] = $addsummary;
}
$this->_renderWrappedTemplate('authentication', $aViewUrls, $aData);
}
/**
* 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 = 'authentication', $aViewUrls = array(), $aData = array())
{
$this->getController()->_css_admin_includes(Yii::app()->getConfig('adminstyleurl')."superfish.css");
parent::_renderWrappedTemplate($sAction, $aViewUrls, $aData);
}
}