Skip to content
This repository has been archived by the owner on Feb 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #579 from janus-ssp/bugfix/576-fixed-user-admin
Browse files Browse the repository at this point in the history
Fixed #576: Edit/Delete buttons on user tab inactive
  • Loading branch information
thijskh committed May 8, 2015
2 parents b2e15e7 + 8917da9 commit b4626cd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 101 deletions.
112 changes: 46 additions & 66 deletions templates/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ function initSubTabs(subTabContainer) {

// Build list of translations for js
$this->data['translations']['admin_save'] = $this->t('admin_save');
$this->data['translations']['text_delete_user'] = $this->t('text_delete_user');

$pageJs[] = <<<JAVASCRIPT_TAB_ADMIN_ENTITIES
$(document).ready(function() {
Expand Down Expand Up @@ -155,7 +154,6 @@ function(data) {
if ($this->data['selectedSubTab'] == SELECTED_SUBTAB_ADMIN_USERS) {
// Build list of translations for js
$this->data['translations']['admin_save'] = $this->t('admin_save');
$this->data['translations']['text_delete_user'] = $this->t('text_delete_user');


$pageJs[] = <<<JAVASCRIPT_TAB_ADMIN_USERS
Expand All @@ -164,13 +162,13 @@ function(data) {
});
function editUser(uid) {
tr_editUser = $("#delete-user-" + uid);
td_type = tr_editUser.children("[name='type']");
td_userid = tr_editUser.children("[name='userid']");
td_active = tr_editUser.children("[name='active']");
td_action = tr_editUser.children("[name='action']");
a_edit = td_action.children("[name='admin_edit']");
a_delete = td_action.children("[name='admin_delete']");
var tr_editUser = $("#user-" + uid),
td_type = tr_editUser.children("[name='type']"),
td_userid = tr_editUser.children("[name='userid']"),
td_active = tr_editUser.children("[name='active']"),
td_action = tr_editUser.children("[name='action']"),
a_edit = td_action.children("[name='admin_edit']"),
checkbox_active;
if (td_active.text() == "yes") {
checkbox_active = "<input type=\"checkbox\" name=\"active\" checked=\"checked\" />";
Expand All @@ -180,7 +178,7 @@ function editUser(uid) {
// Add change event to selct to add types to list
td_type.append($('{$select_type}').change(function() {
tmp = $("<span class=\"usertype\">" + $(this).val() + " <b style=\"color: red;\">x</b>, </span>");
var tmp = $("<span class=\"usertype\">" + $(this).val() + " <b style=\"color: red;\">x</b>, </span>");
$(this).before(tmp);
$(this).children("option:selected").remove();
// Add event to enable remove of types
Expand Down Expand Up @@ -215,29 +213,35 @@ function editUser(uid) {
td_userid.html($('<input name="userid" />').val(td_userid.text()));
a_edit.hide();
$("<a name=\"admin_save\" class=\"janus_button\" onclick=\"saveUser("+uid+");\">{$this->data['translations']['admin_save']}</a>&nbsp;").insertBefore(a_delete);
td_action.append(
'<a name="admin_save" ' +
'class="janus_button" ' +
'onclick="saveUser(' + uid + ');">'+
'{$this->data['translations']['admin_save']}'+
'</a>'
);
td_active.html($(checkbox_active));
}
function saveUser(uid) {
tr_editUser = $("#delete-user-" + uid);
var tr_editUser = $("#user-" + uid),
type = tr_editUser.children("[name='type']");
type = tr_editUser.children("[name='type']");
// Get selected types
types = [];
// Get selected types
var types = new Array();
type.children(".usertype").each(function() {
$(this).text(
$(this).text().slice(0, -4) + ", "
);
types.push($(this).text().slice(0, -2));
});
userid_input = tr_editUser.children("[name='userid']").children("[name='userid']");
userid = userid_input.val();
active = tr_editUser.children("[name='active']").children("[name='active']")[0].checked;
var userid_input = tr_editUser.children("[name='userid']").children("[name='userid']"),
userid = userid_input.val(),
active = tr_editUser.children("[name='active']").children("[name='active']")[0].checked;
if(active == true) {
if (active == true) {
active = "yes";
} else {
active = "no";
Expand All @@ -255,14 +259,14 @@ function saveUser(uid) {
},
function(data){
if(data.status == "success") {
td_action = tr_editUser.children("[name='action']");
var td_action = tr_editUser.children("[name='action']");
td_action.children("[name='admin_edit']").show();
td_action.children("[name='admin_save']").remove();
$("#edit-select-" + data.uid).remove();
tr_editUser.children("[name='userid']").html(userid);
tr_editUser.children("[name='active']").html(active);
} else {
userid_input = tr_editUser.children("[name='userid']").children("[name='userid']");
var userid_input = tr_editUser.children("[name='userid']").children("[name='userid']");
userid_input.focus();
userid_input.css("background-color", "#E94426");
}
Expand Down Expand Up @@ -334,35 +338,6 @@ function(data) {
JAVASCRIPT_TAB_ADMIN_ENTITIES;
}
/* END TAB ADMIN ENTITIES JS ******************************************************************************************/



/* START TAB ADMIN USERS JS *******************************************************************************************/
if ($this->data['selectedSubTab'] == SELECTED_SUBTAB_ADMIN_USERS) {
$pageJs[] = <<<JAVASCRIPT_TAB_ADMIN_USERS
function deleteUser(uid, userid) {
if(confirm("{$this->data['translations']['text_delete_user']}: " + userid)) {
$.post(
"AJAXRequestHandler.php",
{
"func": "deleteUser",
"uid": uid,
"csrf_token": $csrf_ajax_token_json_encoded
},
function(data){
if(data.status == "success") {
$("#delete-user-" + uid).hide();
}
},
"json"
);
}
}
JAVASCRIPT_TAB_ADMIN_USERS;
}
/* END TAB ADMIN USERS JS *********************************************************************************************/


}
/* END TAB ADMIN JS ***************************************************************************************************/

Expand Down Expand Up @@ -775,31 +750,36 @@ function(data) {
/** @var sspmod_janus_User[] $users */
$users = $this->data['users'];
echo '<table class="dashboard_container">';
echo '<thead><tr><th>'. $this->t('admin_type') .'</th><th>'. $this->t('admin_userid') .'</th><th>'. $this->t('admin_active') .'</th><th align="center">'. $this->t('admin_action') .'</th></tr></thead>';
echo '<thead>';
echo '<tr>';
echo '<th>'. $this->t('admin_type') .'</th>';
echo '<th>'. $this->t('admin_userid') .'</th>';
echo '<th>'. $this->t('admin_active') .'</th>';
echo '<th align="center">'. $this->t('admin_action') .'</th>';
echo '</tr>';
echo '</thead>' . PHP_EOL;
echo '<tbody>';
$i = 0;
foreach($users AS $user) {
echo '<tr id="delete-user-'. $user->getUid() .'" class="'. ($i % 2 == 0 ? 'even' : 'odd') .'" >';
echo '<tr id="user-'. $user->getUid() .'" class="'. ($i % 2 == 0 ? 'even' : 'odd') .'" >';
$type = $user->getType();
echo '<td name="type" class="dashboard_user">';
foreach($type AS $t) {
echo '<span class="usertype">' . $t . ', </span>';
}
echo '</td>';
echo '<td name="userid" class="dashboard_user">', htmlspecialchars($user->getUserid()). '</td>';
echo '<td name="active" class="dashboard_user">', htmlspecialchars($user->getActive()). '</td>';
echo '<td name="action" class="dashboard_user" align="center">';
echo '</td>' . PHP_EOL;
echo '<td name="userid" class="dashboard_user">';
echo htmlspecialchars($user->getUserid());
echo '</td>' . PHP_EOL;
echo '<td name="active" class="dashboard_user">';
echo htmlspecialchars($user->getActive());
echo '</td>' . PHP_EOL;
echo '<td name="action" class="dashboard_user" align="center">' . PHP_EOL;
echo '<a name="admin_edit" class="janus_button" onclick="editUser(';
echo json_encode($user->getUid());
echo ');">'. $this->t('admin_edit') .'</a>';
echo ' ';
echo '<a name="admin_delete" class="janus_button" onclick="deleteUser(';
echo json_encode($user->getUid());
echo ', ';
echo $user->getUserid();
echo ');">'. $this->t('admin_delete') .'</a>';
echo '</td>';
echo '</tr>';
echo htmlspecialchars(json_encode($user->getUid()));
echo ');">'. $this->t('admin_edit') .'</a>' . PHP_EOL;
echo '</td>' . PHP_EOL;
echo '</tr>' . PHP_EOL;
$i++;
}
echo '</tbody>';
Expand Down
35 changes: 0 additions & 35 deletions www/AJAXRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,41 +323,6 @@ function updateSubscription($params) {
return $return;
}

function deleteUser($params) {
if(!isset($params['uid'])) {
return FALSE;
}

// only the superuser can delete a user and not herself
if (!$params['__superuser'] || $params['uid'] == $params['__uid']) {
echo json_encode(array('status' => 'permission_denied')); exit;
}

$janus_config = sspmod_janus_DiContainer::getInstance()->getConfig();
$util = new sspmod_janus_AdminUtil();

$uid = $params['uid'];

$user = new sspmod_janus_User();
$user->setUid($uid);
$user->load();

$entities = $util->getEntitiesFromUser($uid);

$sucess = $user->delete();
if ($sucess) {
$util = new sspmod_janus_AdminUtil();
$entity_id_array = array();
$entity_id_array['eid'] = array();
foreach($entities as $entity) {
$entity_id_array['eid'][] = $entity['eid'];
}
$util->removeAllEntitiesFromUser($uid);
return $entity_id_array;
}
return FALSE;
}

function editUser($params) {
if(empty($params['uid']) || empty($params['userid']) || !isset($params['active']) || empty($params['type'])) {
return array('status' => 'missing_param');
Expand Down

0 comments on commit b4626cd

Please sign in to comment.