mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
New options:
* possible to delete clients, * possible to edit clients accounts, * enable and pre-set client quesionnaire permissions to view results, statistics and quotas when assigning questionnaire to client @ 1st time, * link to edit quesionnaire permissions in Lime
This commit is contained in:
@@ -42,13 +42,15 @@ include ("../db.inc.php");
|
|||||||
/**
|
/**
|
||||||
* Authentication file
|
* Authentication file
|
||||||
*/
|
*/
|
||||||
include ("auth-admin.php");
|
require ("auth-admin.php");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XHTML functions
|
* XHTML functions
|
||||||
*/
|
*/
|
||||||
include ("../functions/functions.xhtml.php");
|
include ("../functions/functions.xhtml.php");
|
||||||
|
|
||||||
|
$msg = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return if an client has already been assigned to this questionnaire
|
* Return if an client has already been assigned to this questionnaire
|
||||||
*
|
*
|
||||||
@@ -78,78 +80,125 @@ function vq($client_id,$questionnaire_id)
|
|||||||
*
|
*
|
||||||
* @param int $client_id Client id
|
* @param int $client_id Client id
|
||||||
* @param int $questionnaire_id Questionnaire id
|
* @param int $questionnaire_id Questionnaire id
|
||||||
|
* @param int $lime_sid Lime survey ID
|
||||||
|
* @param int $uid Lime user ID
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function vqi($client_id,$questionnaire_id)
|
function vqi($client_id,$questionnaire_id,$lime_sid,$uid)
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
|
$db->StartTrans();
|
||||||
|
|
||||||
$sql = "INSERT INTO
|
$sql = "INSERT INTO
|
||||||
client_questionnaire (client_id,questionnaire_id)
|
client_questionnaire (client_id,questionnaire_id)
|
||||||
VALUES('$client_id','$questionnaire_id')";
|
VALUES('$client_id','$questionnaire_id')";
|
||||||
|
|
||||||
$db->Execute($sql);
|
$db->Execute($sql);
|
||||||
}
|
|
||||||
|
/* Add client questionnaire permissions to view Lime results + statistics and quotas, //preserve superadmin permissions */
|
||||||
|
if ($uid != 1 && empty($db->GetAll("SELECT * FROM " . LIME_PREFIX . "survey_permissions WHERE `sid` = '$lime_sid' AND `uid` = '$uid'")))
|
||||||
/**
|
{
|
||||||
* Unassign an client from a questionnaire
|
$sql = "INSERT INTO " . LIME_PREFIX . "survey_permissions (`sid`,`uid`,`permission`,`create_p`,`read_p`,`update_p`,`delete_p`,`import_p`,`export_p`)
|
||||||
*
|
VALUES ($lime_sid,$uid,'survey',0,1,0,0,0,0),($lime_sid,$uid,'statistics',0,1,0,0,0,0),($lime_sid,$uid,'quotas',0,1,0,0,0,0)";
|
||||||
* @param int $client_id Client id
|
$db->Execute($sql);
|
||||||
* @param int $questionnaire_id Questionnaire id
|
}
|
||||||
*
|
|
||||||
*/
|
$db->CompleteTrans();
|
||||||
function vqd($client_id,$questionnaire_id)
|
|
||||||
{
|
|
||||||
global $db;
|
|
||||||
|
|
||||||
$sql = "DELETE FROM
|
|
||||||
client_questionnaire
|
|
||||||
WHERE client_id = '$client_id' and questionnaire_id = '$questionnaire_id'";
|
|
||||||
|
|
||||||
$db->Execute($sql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (isset($_POST['submit']))
|
if (isset($_POST['submit']))
|
||||||
{
|
{
|
||||||
$db->StartTrans();
|
$db->StartTrans();
|
||||||
|
|
||||||
$sql = "DELETE
|
/* Unassign a client from a questionnaire , remove survey_permissions*/
|
||||||
FROM client_questionnaire
|
$sql = "DELETE FROM client_questionnaire
|
||||||
WHERE questionnaire_id IN (
|
WHERE questionnaire_id IN ( SELECT questionnaire_id FROM questionnaire WHERE enabled = 1)";
|
||||||
SELECT questionnaire_id
|
|
||||||
FROM questionnaire
|
|
||||||
WHERE enabled = 1)";
|
|
||||||
|
|
||||||
$db->Execute($sql);
|
$db->Execute($sql);
|
||||||
|
/*Currently disabled -> need to decide how to manage permissions set earlier*/
|
||||||
|
/* $questionnaires = $db->GetAll("SELECT lime_sid FROM questionnaire WHERE enabled = 1");
|
||||||
|
|
||||||
|
$clients = $db->GetAll("SELECT uid FROM client, " . LIME_PREFIX . "users WHERE `users_name` = `username`");
|
||||||
|
|
||||||
|
foreach($questionnaires as $q){
|
||||||
|
foreach($clients as $v){
|
||||||
|
$sql = "DELETE FROM " . LIME_PREFIX . "survey_permissions WHERE `uid` = {$v['uid']} AND `sid`={$q['lime_sid']} AND `uid` != 1";
|
||||||
|
$db->Execute($sql);
|
||||||
|
}
|
||||||
|
} */
|
||||||
|
/* - end - */
|
||||||
|
|
||||||
foreach ($_POST as $g => $v)
|
foreach ($_POST as $g => $v)
|
||||||
{
|
{
|
||||||
$a = explode("_",$g);
|
$a = explode("_",$g);
|
||||||
if ($a[0] == "cb")
|
if ($a[0] == "cb")
|
||||||
vqi($a[2],$a[1]);
|
vqi($a[2],$a[1],$a[3],$a[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->CompleteTrans();
|
$db->CompleteTrans();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* delete client from quexs and lime tables*/ //requires data-toggle-confirmation to finalize
|
||||||
|
if (isset($_POST['delete']) && isset($_POST['uid']))
|
||||||
|
{
|
||||||
|
$client_id = intval($_POST['delete']);
|
||||||
|
$uid = intval($_POST['uid']);
|
||||||
|
$uname = $_POST['uname'];
|
||||||
|
|
||||||
|
global $db;
|
||||||
|
|
||||||
|
$db->StartTrans();
|
||||||
|
|
||||||
|
if ($uid !=1){ //double protect superadmin from being deleted
|
||||||
|
|
||||||
|
$sql = "DELETE FROM " . LIME_PREFIX . "templates_rights WHERE `uid` = '$uid' AND `uid` != 1";
|
||||||
|
$db->Execute($sql);
|
||||||
|
|
||||||
|
$sql = "DELETE FROM " . LIME_PREFIX . "survey_permissions WHERE `uid` = '$uid' AND `uid` != 1";
|
||||||
|
$db->Execute($sql);
|
||||||
|
|
||||||
|
$sql = "DELETE FROM " . LIME_PREFIX . "user_in_groups WHERE `uid` = '$uid' AND `uid` != 1";
|
||||||
|
$db->Execute($sql);
|
||||||
|
|
||||||
|
$sql = "DELETE FROM " . LIME_PREFIX . "users WHERE `uid` = '$uid' AND `uid` != 1";
|
||||||
|
$db->Execute($sql);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$sql = "SELECT questionnaire_id,description
|
$sql = "DELETE FROM `client_questionnaire` WHERE `client_id` = '$client_id' ";
|
||||||
|
$db->Execute($sql);
|
||||||
|
|
||||||
|
$sql = "DELETE FROM `client` WHERE `client_id` = '$client_id'";
|
||||||
|
$db->Execute($sql);
|
||||||
|
|
||||||
|
$db->CompleteTrans();
|
||||||
|
|
||||||
|
if ($db->CompleteTrans()) $msg = "<p class='alert alert-info'>". T_("Client with username $uname deleted") . "</p>";
|
||||||
|
else $msg = "<p class='alert alert-warning'>". T_("ERROR deleting client with username $uname") . "</p>";
|
||||||
|
|
||||||
|
unset($_POST['delete'], $_POST['uid'], $_POST['uname'], $client_id, $username, $uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$sql = "SELECT questionnaire_id,description, lime_sid
|
||||||
FROM questionnaire
|
FROM questionnaire
|
||||||
WHERE enabled = 1
|
WHERE enabled = 1
|
||||||
ORDER by questionnaire_id ASC";
|
ORDER by questionnaire_id ASC";
|
||||||
|
|
||||||
$questionnaires = $db->GetAll($sql);
|
$questionnaires = $db->GetAll($sql);
|
||||||
|
|
||||||
$sql = "SELECT client_id, CONCAT(firstName,' ', lastName ) as description, username
|
$sql = "SELECT client_id, CONCAT(firstName,' ', lastName ) as description, username, uid
|
||||||
FROM client
|
FROM client, " . LIME_PREFIX . "users
|
||||||
|
WHERE `users_name` = `username`
|
||||||
ORDER by client_id ASC";
|
ORDER by client_id ASC";
|
||||||
|
|
||||||
$clients = $db->GetAll($sql);
|
$clients = $db->GetAll($sql);
|
||||||
|
|
||||||
|
|
||||||
xhtml_head(T_("Assign clients to questionnaires"),true,array("../include/bootstrap/css/bootstrap.min.css","../include/iCheck/skins/square/blue.css","../css/custom.css"),array("../include/jquery/jquery.min.js","../include/iCheck/icheck.min.js"));
|
xhtml_head(T_("Clients and questionnaires"),true,array("../include/bootstrap/css/bootstrap.min.css","../include/font-awesome/css/font-awesome.css","../include/iCheck/skins/square/blue.css","../css/custom.css"),array("../include/jquery/jquery.min.js","../include/iCheck/icheck.min.js"));
|
||||||
|
|
||||||
|
if (!empty($msg)) print $msg;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
@@ -243,7 +292,9 @@ print "<form action=\"\" method=\"post\" class=''><table class='table-bordered t
|
|||||||
print "<tr><th> " . T_("Username") . " </th><th> " . T_("Client") . " </th>";
|
print "<tr><th> " . T_("Username") . " </th><th> " . T_("Client") . " </th>";
|
||||||
foreach($questionnaires as $q)
|
foreach($questionnaires as $q)
|
||||||
{
|
{
|
||||||
print "<th><a href=\"javascript:checkQid({$q['questionnaire_id']})\">{$q['description']}</a></th>";
|
print "<th><a href=\"".LIME_URL."admin/admin.php?sid={$q['lime_sid']}&action=surveysecurity\" title=\"". T_("NOTICE! Please, check your user righs to edit client permissions or contact your superviser.") ."\"class=\"btn btn-default btn-sm btn-lime\" >" . T_("Questionnaire permissions") . "</a>
|
||||||
|
</br> <a href=\"javascript:checkQid({$q['questionnaire_id']})\">{$q['description']}</a>
|
||||||
|
</th>";
|
||||||
}
|
}
|
||||||
print "</tr></thead>";
|
print "</tr></thead>";
|
||||||
|
|
||||||
@@ -251,20 +302,24 @@ print "</tr></thead>";
|
|||||||
foreach($clients as $v)
|
foreach($clients as $v)
|
||||||
{
|
{
|
||||||
print "<tr class=''>
|
print "<tr class=''>
|
||||||
<th> {$v['username']} </th>
|
<th> {$v['username']} <div class=\"pull-right\">
|
||||||
|
<a href=\"?delete={$v['client_id']}&uid={$v['uid']}&uname={$v['username']}\" ><i class='fa fa-fw fa-trash-o fa-lg text-danger' data-toggle='tooltip' title=\"" . T_("Delete") . " {$v['username']} ?\"></i></a> 
|
||||||
|
<a href=\"clients.php?edit={$v['client_id']}\" ><i class='fa fa-fw fa-edit fa-lg' data-toggle='tooltip' title=\"" . T_("Edit") . " {$v['username']}\"></i></a> </div></th>
|
||||||
<th> <a href=\"javascript:checkVid({$v['client_id']})\">{$v['description']}</a> </th>";
|
<th> <a href=\"javascript:checkVid({$v['client_id']})\">{$v['description']}</a> </th>";
|
||||||
|
|
||||||
foreach($questionnaires as $q)
|
foreach($questionnaires as $q)
|
||||||
{
|
{
|
||||||
$checked = "";
|
|
||||||
if (vq($v['client_id'],$q['questionnaire_id'])) $checked="checked=\"checked\"";
|
if (vq($v['client_id'],$q['questionnaire_id'])) $checked="checked=\"checked\""; else $checked = "";
|
||||||
print "<td class='text-center'><input type=\"checkbox\" name=\"cb_{$q['questionnaire_id']}_{$v['client_id']}\" id=\"cb_{$q['questionnaire_id']}_{$v['client_id']}\" $checked></input></td>";
|
print "<td class='text-center'> 
|
||||||
|
<input type=\"checkbox\" name=\"cb_{$q['questionnaire_id']}_{$v['client_id']}_{$q['lime_sid']}_{$v['uid']}\" id=\"cb_{$q['questionnaire_id']}_{$v['client_id']}\" $checked/> </td>";
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</tr>";
|
print "</tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
print "</table><input type=\"submit\" class='btn btn-default fa' name=\"submit\" value=\"" . T_("Assign clients to questionnaires") . "\"/></form>";
|
print "</table><input type=\"submit\" class='btn btn-primary' name=\"submit\" value=\"" . T_("Assign clients to questionnaires") . "\"/></form>";
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|||||||
Reference in New Issue
Block a user