added group handling feature

This commit is contained in:
SJ
2012-06-22 12:30:55 +02:00
parent 26807592b5
commit e944852283
23 changed files with 744 additions and 11 deletions

View File

@ -0,0 +1,84 @@
<?php
class ControllerGroupAdd extends Controller {
private $error = array();
private $domains = array();
public function index(){
$this->id = "content";
$this->template = "group/add.tpl";
$this->layout = "common/layout";
$request = Registry::get('request');
$db = Registry::get('db');
$this->load->model('group/group');
$this->document->title = $this->data['text_group_management'];
/* check if we are admin */
if(Registry::get('admin_user') == 1) {
if($this->request->server['REQUEST_METHOD'] == 'POST') {
$ret = 0;
if($this->validate() == true){
$ret = $this->model_group_group->add_group($this->request->post);
if($ret == 1){
$this->data['x'] = $this->data['text_successfully_added'];
} else {
$this->data['errorstring'] = $this->data['text_failed_to_add'] . ": " . $ret;
}
}
else {
$this->data['errorstring'] = array_pop($this->error);
}
if($ret == 0) {
//$this->data['post'] = $this->request->post;
//$this->data['next_group_id'] = $this->model_group_group->getNextUid();
}
}
else {
//$this->data['next_group_id'] = $this->model_group_group->getNextUid();
}
}
else {
$this->template = "common/error.tpl";
$this->data['errorstring'] = $this->data['text_you_are_not_admin'];
}
$this->render();
}
private function validate() {
if(!isset($this->request->post['groupname'])) {
$this->error['group'] = $this->data['text_missing_data'];
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}
?>

View File

@ -0,0 +1,104 @@
<?php
class ControllerGroupEdit extends Controller {
private $error = array();
private $domains = array();
public function index(){
$this->data['id'] = 0;
$this->id = "content";
$this->template = "group/edit.tpl";
$this->layout = "common/layout";
$request = Registry::get('request');
$db = Registry::get('db');
$language = Registry::get('language');
$this->load->model('group/group');
$this->document->title = $language->get('text_group_management');
$this->data['domains'] = array();
if(isset($this->request->get['id']) && is_numeric($this->request->get['id']) && $this->request->get['id'] > 0) {
$this->data['id'] = $this->request->get['id'];
}
if(isset($this->request->post['id']) && is_numeric($this->request->post['id']) && $this->request->post['id'] > 0) {
$this->data['id'] = $this->request->post['id'];
}
/* check if we are admin */
if(Registry::get('admin_user') == 1) {
if($this->request->server['REQUEST_METHOD'] == 'POST') {
if($this->validate() == true){
$ret = $this->model_group_group->update_group($this->request->post);
if($ret == 1){
$this->data['x'] = $this->data['text_successfully_modified'];
} else {
$this->template = "common/error.tpl";
$this->data['errorstring'] = $this->data['text_failed_to_modify'] . ": " . $ret;
}
//$__groupname = $this->request->post['groupname'];
}
else {
$this->template = "common/error.tpl";
$this->data['errorstring'] = array_pop($this->error);
}
}
else {
$this->data['group'] = $this->model_group_group->get_domain_by_id($this->data['id']);
$this->data['email'] = $this->model_group_group->get_emails_by_group_id($this->data['id']);
//$this->data['user']['group_membership'] = $this->model_user_user->get_additional_uids($this->data['uid']);
//$this->data['emails'] = $this->model_user_user->getEmails($this->data['user']['username']);
}
}
else {
$this->template = "common/error.tpl";
$this->data['errorstring'] = $this->data['text_you_are_not_admin'];
}
$this->render();
}
private function validate() {
if(!isset($this->request->post['groupname'])) {
$this->error['group'] = $this->data['text_missing_data'];
}
if(!isset($this->request->post['id']) || !is_numeric($this->request->post['id']) || (int)$this->request->post['id'] < 0) {
$this->error['id'] = $this->data['text_invalid_data'];
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}
?>

View File

@ -0,0 +1,85 @@
<?php
class ControllerGroupList extends Controller {
private $error = array();
public function index(){
$this->id = "content";
$this->template = "group/list.tpl";
$this->layout = "common/layout";
$request = Registry::get('request');
$db = Registry::get('db');
$language = Registry::get('language');
$this->load->model('group/group');
$this->document->title = $language->get('text_group_management');
$this->data['page'] = 0;
$this->data['page_len'] = get_page_length();
$this->data['total_users'] = 0;
$users = array();
/* get search term if there's any */
if($this->request->server['REQUEST_METHOD'] == 'POST'){
$this->data['search'] = @$this->request->post['search'];
}
else {
$this->data['search'] = @$this->request->get['search'];
}
/* get page */
if(isset($this->request->get['page']) && is_numeric($this->request->get['page']) && $this->request->get['page'] > 0) {
$this->data['page'] = $this->request->get['page'];
}
$this->data['sort'] = 'groupname';
$this->data['order'] = (int)@$this->request->get['order'];
if(@$this->request->get['sort'] == "uid") { $this->data['sort'] = "uid"; }
if(@$this->request->get['sort'] == "realname") { $this->data['sort'] = "realname"; }
if(@$this->request->get['sort'] == "email") { $this->data['sort'] = "email"; }
if(@$this->request->get['sort'] == "domain") { $this->data['sort'] = "domain"; }
if(@$this->request->get['sort'] == "policy") { $this->data['sort'] = "policy_group"; }
/* check if we are admin */
if(Registry::get('admin_user') == 1) {
$this->data['groups'] = $this->model_group_group->get_groups($this->data['search'], $this->data['page'], $this->data['page_len'],
$this->data['sort'], $this->data['order']);
$this->data['total_groups'] = $this->model_group_group->count_groups($this->data['search']);
}
else {
$this->template = "common/error.tpl";
$this->data['errorstring'] = $this->data['text_you_are_not_admin'];
}
$this->data['prev_page'] = $this->data['page'] - 1;
$this->data['next_page'] = $this->data['page'] + 1;
$this->data['total_pages'] = floor($this->data['total_users'] / $this->data['page_len']);
$this->render();
}
}
?>

View File

@ -0,0 +1,76 @@
<?php
class ControllerGroupRemove extends Controller {
private $error = array();
private $domains = array();
private $d = array();
public function index(){
$this->id = "content";
$this->template = "group/remove.tpl";
$this->layout = "common/layout";
$request = Registry::get('request');
$db = Registry::get('db');
$this->load->model('group/group');
$this->document->title = $this->data['text_group_management'];
$this->data['username'] = Registry::get('username');
$this->data['id'] = (int)@$this->request->get['id'];
$this->data['group'] = @$this->request->get['group'];
$this->data['confirmed'] = (int)@$this->request->get['confirmed'];
if($this->validate() == true) {
if($this->data['confirmed'] == 1) {
$ret = $this->model_group_group->delete_group($this->data['id']);
if($ret == 1){
$this->data['x'] = $this->data['text_successfully_removed'];
}
else {
$this->data['x'] = $this->data['text_failed_to_remove'];
}
}
}
else {
$this->template = "common/error.tpl";
$this->data['errorstring'] = array_pop($this->error);
}
$this->render();
}
private function validate() {
if(Registry::get('admin_user') == 0) {
$this->error['admin'] = $this->data['text_you_are_not_admin'];
}
if(!isset($this->request->get['id']) || !is_numeric($this->request->get['id']) || $this->request->get['id'] < 1 ) {
$this->error['groupname'] = $this->data['text_invalid_data'];
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}
?>