partial #1964 - option to create admin groups
This commit is contained in:
parent
2feb0e2992
commit
cadee9cbc4
64
include/controllers/default/cockpit/permissions/groups.php
Normal file
64
include/controllers/default/cockpit/permissions/groups.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Controller_Permissions_Groups extends Crunchbutton_Controller_Account {
|
||||||
|
|
||||||
|
public function init() {
|
||||||
|
|
||||||
|
if (!c::admin()->permission()->check(['global','permissions-all', 'permission-groups'])) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
$action = c::getPagePiece(2);
|
||||||
|
|
||||||
|
switch ( $action ) {
|
||||||
|
|
||||||
|
case 'content':
|
||||||
|
$this->search();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'new':
|
||||||
|
$this->form();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'remove':
|
||||||
|
$id_group = $_REQUEST[ 'id_group' ];
|
||||||
|
$group = Crunchbutton_Group::o( $id_group );
|
||||||
|
if( $group->id_group ){
|
||||||
|
$group->delete();
|
||||||
|
}
|
||||||
|
echo 'ok';
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if( is_numeric( $action ) ){
|
||||||
|
$this->form();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
c::view()->page = 'permissions';
|
||||||
|
c::view()->display('permissions/groups/index');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function search(){
|
||||||
|
$search = [];
|
||||||
|
if ( $_REQUEST[ 'name' ] ) {
|
||||||
|
$search[ 'name' ] = $_REQUEST[ 'name' ];
|
||||||
|
}
|
||||||
|
c::view()->groups = Crunchbutton_Group::find( $search );
|
||||||
|
c::view()->layout( 'layout/ajax' );
|
||||||
|
c::view()->display( 'permissions/groups/content' );
|
||||||
|
}
|
||||||
|
|
||||||
|
private function form(){
|
||||||
|
$id_group = c::getPagePiece(2);
|
||||||
|
if( $id_group != 'new' ){
|
||||||
|
c::view()->group = Crunchbutton_Group::o( $id_group );
|
||||||
|
} else {
|
||||||
|
c::view()->group = new Crunchbutton_Group();
|
||||||
|
}
|
||||||
|
c::view()->display( 'permissions/groups/form' );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Controller_api_Permissions_Groups extends Crunchbutton_Controller_Rest {
|
||||||
|
public function init() {
|
||||||
|
if (!c::admin()->permission()->check(['global','permissions-all', 'permission-groups'])) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
switch ( $this->method() ) {
|
||||||
|
case 'post':
|
||||||
|
$id_group = c::getPagePiece( 3 );
|
||||||
|
$name = $_REQUEST[ 'name' ];
|
||||||
|
if( $id_group ){
|
||||||
|
$group = Crunchbutton_Group::o( $id_group );
|
||||||
|
} else {
|
||||||
|
$group = new Crunchbutton_Group();
|
||||||
|
}
|
||||||
|
$name = str_replace( ' ' , '-', $name );
|
||||||
|
$group->name = $name;
|
||||||
|
$group->save();
|
||||||
|
echo json_encode( ['success' => $group->id_group ] );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
echo json_encode( [ 'error' => 'invalid object' ] );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -130,8 +130,8 @@ class Crunchbutton_Admin extends Cana_Table {
|
|||||||
|
|
||||||
$query .= " ORDER BY name DESC";
|
$query .= " ORDER BY name DESC";
|
||||||
|
|
||||||
$gifts = self::q($query);
|
$admins = self::q($query);
|
||||||
return $gifts;
|
return $admins;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct($id = null) {
|
public function __construct($id = null) {
|
||||||
|
|||||||
@ -8,4 +8,33 @@ class Crunchbutton_Group extends Cana_Table {
|
|||||||
->idVar('id_group')
|
->idVar('id_group')
|
||||||
->load($id);
|
->load($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function find($search = []) {
|
||||||
|
|
||||||
|
$query = 'SELECT `group`.* FROM `group` WHERE id_group IS NOT NULL ';
|
||||||
|
|
||||||
|
if ( $search[ 'name' ] ) {
|
||||||
|
$query .= " AND name LIKE '%{$search[ 'name' ]}%' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
$query .= " ORDER BY name DESC";
|
||||||
|
|
||||||
|
$groups = self::q($query);
|
||||||
|
return $groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function users(){
|
||||||
|
if( $this->id_group ){
|
||||||
|
return Crunchbutton_Admin_Group::q( "SELECT a.* FROM admin a INNER JOIN admin_group ag ON ag.id_admin = a.id_admin AND ag.id_group = {$this->id_group}" );
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function usersTotal(){
|
||||||
|
if( $this->id_group ){
|
||||||
|
return Crunchbutton_Admin_Group::q( "SELECT a.* FROM admin a INNER JOIN admin_group ag ON ag.id_admin = a.id_admin AND ag.id_group = {$this->id_group}" )->count();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
$groups = $this->groups;
|
||||||
|
?>
|
||||||
|
<?php if (!$groups->count()) { ?>
|
||||||
|
No results found
|
||||||
|
<?php } else { ?>
|
||||||
|
<table class="table table-normal">
|
||||||
|
<thead>
|
||||||
|
<td>Name</td>
|
||||||
|
<td>Number of users at this group</td>
|
||||||
|
<td></td>
|
||||||
|
</thead>
|
||||||
|
<?php foreach ( $groups as $group ) { ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo $group->name;?> </td>
|
||||||
|
<td><?php echo $group->usersTotal();?> </td>
|
||||||
|
<td style="width:150px;">
|
||||||
|
<a href="/permissions/groups/<?php echo $group->id_group; ?>" class="btn btn-green"><i class="icon-edit"></i> Edit</a>
|
||||||
|
|
||||||
|
<button data-id="<?php echo $group->id_group; ?>" class="btn group-remove btn-red"><i class="icon-trash"></i> Remove</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</table>
|
||||||
|
<?php } ?>
|
||||||
122
include/views/default/cockpit/permissions/groups/form.phtml
Normal file
122
include/views/default/cockpit/permissions/groups/form.phtml
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<?
|
||||||
|
$this->title = 'Permissions';
|
||||||
|
$this->titleicon = 'lock';
|
||||||
|
$this->titleLink = '/permissions/groups';
|
||||||
|
|
||||||
|
$this->title2 = 'Groups';
|
||||||
|
$this->title2icon = 'group';
|
||||||
|
|
||||||
|
$group = $this->group;
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="container-fluid padded">
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span6">
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header">
|
||||||
|
<span class="title">Group</span>
|
||||||
|
</div>
|
||||||
|
<div class="box-content ">
|
||||||
|
<ul class="box-list">
|
||||||
|
<li>
|
||||||
|
<span>Name</span>
|
||||||
|
<span class="pull-right">
|
||||||
|
<input type="text" name="name" maxlength="40" id="name" value="<?php echo $group->name; ?>" />
|
||||||
|
<div class="note">Please don't use spaces use dashes instead!</div>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
<li class="input">
|
||||||
|
<button type="submit" class="btn btn-blue admin-save"><i class="icon-save"></i> Save </button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php if( $group->usersTotal() > 0 ) { ?>
|
||||||
|
<div class="span6">
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header">
|
||||||
|
<span class="title">Users</span>
|
||||||
|
</div>
|
||||||
|
<div class="box-content ">
|
||||||
|
<ul class="box-list">
|
||||||
|
<?php
|
||||||
|
$users = $group->users();
|
||||||
|
foreach( $users as $user ){
|
||||||
|
?>
|
||||||
|
<li>
|
||||||
|
<span>
|
||||||
|
<?php echo $user->name; ?>
|
||||||
|
</span>
|
||||||
|
<span class="pull-right">
|
||||||
|
<?php echo $user->login; ?>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
<?php } ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
$(document).on('click', '.admin-save', function() {
|
||||||
|
sendForm();
|
||||||
|
} );
|
||||||
|
});
|
||||||
|
|
||||||
|
var processing = false;
|
||||||
|
|
||||||
|
function sendForm(){
|
||||||
|
|
||||||
|
if( processing ){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var name = $.trim( $( '#name' ).val() );
|
||||||
|
|
||||||
|
if( name == '' ){
|
||||||
|
alert( 'Please type a name!' );
|
||||||
|
$( '#name' ).focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = { 'name' : name};
|
||||||
|
|
||||||
|
processing = true;
|
||||||
|
|
||||||
|
$( '.admin-save' ).html( '<i class="icon-spinner icon-spin"></i> Please wait' );
|
||||||
|
|
||||||
|
var url = App.service + 'permissions/groups/<?php echo $group->id_group; ?>';
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
dataType: 'json',
|
||||||
|
data: data,
|
||||||
|
url: url,
|
||||||
|
success: function( json ) {
|
||||||
|
processing = false;
|
||||||
|
if( json.error ){
|
||||||
|
if( json.error == 'login' ){
|
||||||
|
alert( 'This login is already in use!' );
|
||||||
|
$( '#login' ).focus();
|
||||||
|
$( '.admin-save' ).html( '<i class="icon-save"></i> Save ' );
|
||||||
|
} else {
|
||||||
|
alert( 'Error at saving the user!' );
|
||||||
|
$( '.admin-save' ).html( '<i class="icon-save"></i> Save ' );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alert( 'Group saved!' );
|
||||||
|
location.href = '/permissions/groups/';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function( ){
|
||||||
|
processing = false;
|
||||||
|
alert( 'Error at saving the user!' );
|
||||||
|
$( '.admin-save' ).html( '<i class="icon-save"></i> Save ' );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
69
include/views/default/cockpit/permissions/groups/index.phtml
Normal file
69
include/views/default/cockpit/permissions/groups/index.phtml
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?
|
||||||
|
$this->title = 'Permissions';
|
||||||
|
$this->titleicon = 'lock';
|
||||||
|
$this->titleLink = '/permissions';
|
||||||
|
|
||||||
|
$this->title2 = 'Groups';
|
||||||
|
$this->title2icon = 'group';
|
||||||
|
|
||||||
|
?>
|
||||||
|
<!-- content -->
|
||||||
|
<div class="container-fluid padded">
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-content">
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span6 separate-sections">
|
||||||
|
<ul class="padded separate-sections">
|
||||||
|
<li class="input">
|
||||||
|
<input class="span12" name="name" type="text" value="<?=strip_tags($_REQUEST['name'])?>" placeholder="Name">
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="span6 separate-sections">
|
||||||
|
<ul class="padded separate-sections">
|
||||||
|
<li><button class="btn btn-blue admin-group-search"><i class="icon-search"></i> Search </button>
|
||||||
|
<a href="/permissions/groups/new" class="btn btn-green admin-group-new"><i class="icon-group"></i> New Group </a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header"><span class="title">Results</span></div>
|
||||||
|
<div class="box-content">
|
||||||
|
<div class="permissions-loader">
|
||||||
|
<center><i class="icon-spinner icon-spin" style="font-size: 50px;"></i></center>
|
||||||
|
</div>
|
||||||
|
<div class="permissions-content"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
|
||||||
|
$(document).on('click', '.admin-group-search', function() {
|
||||||
|
App.permissions.group.load();
|
||||||
|
} );
|
||||||
|
|
||||||
|
$(document).on('keyup', '[name="name"]', function( e ) {
|
||||||
|
if (e.which == 13) {
|
||||||
|
App.permissions.group.load();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
App.permissions.group.load();
|
||||||
|
|
||||||
|
$(document).on('click', '.group-remove', function() {
|
||||||
|
var button = $( this );
|
||||||
|
if( confirm( 'Confirm? This action remove the group!' ) ){
|
||||||
|
var id_group = button.attr( 'data-id' );
|
||||||
|
App.permissions.group.remove( id_group );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@ -1,7 +1,7 @@
|
|||||||
<?
|
<?
|
||||||
$this->title = 'Permissions';
|
$this->title = 'Permissions';
|
||||||
$this->titleicon = 'lock';
|
$this->titleicon = 'lock';
|
||||||
$this->titleLink = '/permissions';
|
$this->titleLink = '/permissions/users';
|
||||||
|
|
||||||
$this->title2 = 'Users';
|
$this->title2 = 'Users';
|
||||||
$this->title2icon = 'user';
|
$this->title2icon = 'user';
|
||||||
|
|||||||
@ -58,7 +58,7 @@
|
|||||||
|
|
||||||
$(document).on('click', '.admin-user-remove', function() {
|
$(document).on('click', '.admin-user-remove', function() {
|
||||||
var button = $( this );
|
var button = $( this );
|
||||||
if( confirm( 'Confirm? This action will not remove the user!' ) ){
|
if( confirm( 'Confirm? This action will remove the user!' ) ){
|
||||||
var id_admin = button.attr( 'data-id' );
|
var id_admin = button.attr( 'data-id' );
|
||||||
App.permissions.admin.remove( id_admin );
|
App.permissions.admin.remove( id_admin );
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1025,7 +1025,7 @@ App.credits = {
|
|||||||
|
|
||||||
var url = App.service + 'credit/new';
|
var url = App.service + 'credit/new';
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: 'POST',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: data,
|
data: data,
|
||||||
url: url,
|
url: url,
|
||||||
@ -1563,7 +1563,7 @@ App.giftcards = {
|
|||||||
var data = { 'value' : value,'id_restaurant' : id_restaurant, 'phones' : phones, 'paid_by' : paid_by, 'id_restaurant_paid_by' : id_restaurant_paid_by, 'note' : note, 'created_by' : created_by, 'track' : track, 'notify_phone' : notify_phone, 'name' : name, 'how_delivery' : how_delivery, 'contact' : contact };
|
var data = { 'value' : value,'id_restaurant' : id_restaurant, 'phones' : phones, 'paid_by' : paid_by, 'id_restaurant_paid_by' : id_restaurant_paid_by, 'note' : note, 'created_by' : created_by, 'track' : track, 'notify_phone' : notify_phone, 'name' : name, 'how_delivery' : how_delivery, 'contact' : contact };
|
||||||
var url = App.service + 'giftcard/bunchsms';
|
var url = App.service + 'giftcard/bunchsms';
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: 'POST',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: data,
|
data: data,
|
||||||
url: url,
|
url: url,
|
||||||
@ -1652,7 +1652,7 @@ App.giftcards = {
|
|||||||
var data = { 'value' : value,'id_restaurant' : id_restaurant, 'emails' : emails, 'subject':subject, 'content': content, 'paid_by' : paid_by, 'id_restaurant_paid_by' : id_restaurant_paid_by, 'note' : note, 'created_by' : created_by, 'track' : track, 'notify_phone' : notify_phone, 'name' : name, 'how_delivery' : how_delivery, 'contact' : contact };
|
var data = { 'value' : value,'id_restaurant' : id_restaurant, 'emails' : emails, 'subject':subject, 'content': content, 'paid_by' : paid_by, 'id_restaurant_paid_by' : id_restaurant_paid_by, 'note' : note, 'created_by' : created_by, 'track' : track, 'notify_phone' : notify_phone, 'name' : name, 'how_delivery' : how_delivery, 'contact' : contact };
|
||||||
var url = App.service + 'giftcard/bunchemail';
|
var url = App.service + 'giftcard/bunchemail';
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: 'POST',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: data,
|
data: data,
|
||||||
url: url,
|
url: url,
|
||||||
@ -1676,7 +1676,7 @@ App.giftcards = {
|
|||||||
var data = { 'id_promo' : id_promo };
|
var data = { 'id_promo' : id_promo };
|
||||||
var url = App.service + 'giftcard/sms';
|
var url = App.service + 'giftcard/sms';
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: 'POST',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: data,
|
data: data,
|
||||||
url: url,
|
url: url,
|
||||||
@ -1700,7 +1700,7 @@ App.giftcards = {
|
|||||||
var data = { 'id_promo' : id_promo };
|
var data = { 'id_promo' : id_promo };
|
||||||
var url = App.service + 'giftcard/email';
|
var url = App.service + 'giftcard/email';
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: 'POST',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: data,
|
data: data,
|
||||||
url: url,
|
url: url,
|
||||||
@ -1730,7 +1730,7 @@ App.giftcards = {
|
|||||||
var data = { 'id_promo' : id_promo, 'id_user' : id_user };
|
var data = { 'id_promo' : id_promo, 'id_user' : id_user };
|
||||||
var url = App.service + 'giftcard/relateuser';
|
var url = App.service + 'giftcard/relateuser';
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: 'POST',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: data,
|
data: data,
|
||||||
url: url,
|
url: url,
|
||||||
@ -1799,7 +1799,7 @@ App.giftcardsGroup = {
|
|||||||
remove: function( id_promo_group ){
|
remove: function( id_promo_group ){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/giftcards/groups/remove',
|
url: '/giftcards/groups/remove',
|
||||||
type: "POST",
|
type: 'POST',
|
||||||
data: { 'id_promo_group': id_promo_group } ,
|
data: { 'id_promo_group': id_promo_group } ,
|
||||||
complete: function() {
|
complete: function() {
|
||||||
App.giftcardsGroup.load();
|
App.giftcardsGroup.load();
|
||||||
@ -1810,6 +1810,7 @@ App.giftcardsGroup = {
|
|||||||
|
|
||||||
|
|
||||||
App.permissions = {};
|
App.permissions = {};
|
||||||
|
|
||||||
App.permissions.admin = {
|
App.permissions.admin = {
|
||||||
params: function() {
|
params: function() {
|
||||||
return {
|
return {
|
||||||
@ -1831,7 +1832,7 @@ App.permissions.admin = {
|
|||||||
remove: function( id_admin ){
|
remove: function( id_admin ){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/permissions/users/remove',
|
url: '/permissions/users/remove',
|
||||||
type: "POST",
|
type: 'POST',
|
||||||
data: { 'id_admin': id_admin } ,
|
data: { 'id_admin': id_admin } ,
|
||||||
complete: function() {
|
complete: function() {
|
||||||
App.permissions.admin.load();
|
App.permissions.admin.load();
|
||||||
@ -1840,3 +1841,32 @@ App.permissions.admin = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App.permissions.group = {
|
||||||
|
params: function() {
|
||||||
|
return {
|
||||||
|
name: $('input[name="name"]').val()
|
||||||
|
};
|
||||||
|
},
|
||||||
|
load: function() {
|
||||||
|
$('.permissions-loader').show();
|
||||||
|
$('.permissions-content').html('');
|
||||||
|
$.ajax({
|
||||||
|
url: '/permissions/groups/content',
|
||||||
|
data: App.permissions.group.params(),
|
||||||
|
complete: function(content) {
|
||||||
|
$('.permissions-content').html(content.responseText);
|
||||||
|
$('.permissions-loader').hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
remove: function( id_group ){
|
||||||
|
$.ajax({
|
||||||
|
url: '/permissions/groups/remove',
|
||||||
|
type: 'POST',
|
||||||
|
data: { 'id_group': id_group } ,
|
||||||
|
complete: function() {
|
||||||
|
App.permissions.group.load();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user