This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/group/group.inc.php

162 lines
3.8 KiB
PHP
Raw Normal View History

<?php
/**
* AgileBill - Open Billing Software
*
* This body of work is free software; you can redistribute it and/or
* modify it under the terms of the Open AgileBill License
* License as published at http://www.agileco.com/agilebill/license1-4.txt
2009-08-03 04:10:16 +00:00
*
* Originally authored by Tony Landis, AgileBill LLC
*
* Recent modifications by Deon George
*
* @author Deon George <deonATleenooksDOTnet>
* @copyright 2009 Deon George
* @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
2009-08-03 04:10:16 +00:00
* @author Tony Landis <tony@agileco.com>
* @package AgileBill
2009-08-03 04:10:16 +00:00
* @subpackage Module:Group
*/
2009-08-03 04:10:16 +00:00
/**
* The main AgileBill Group Class
*
* @package AgileBill
* @subpackage Module:Group
*/
class group extends OSB_module {
/**
* Add a record
*/
public function add($VAR) {
$group_id = parent::add($VAR);
if ($group_id) {
# Add the new group to the account_group table:
$db = &DB();
$result = $db->Execute(sqlInsert($db,'account_group',array('date_orig'=>time(),'group_id'=>$group_id,'account_id'=>SESS_ACCOUNT,'acive'=>1)));
if ($result === false) {
global $C_debug;
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
return;
}
2009-08-03 04:10:16 +00:00
} else
return false;
2009-08-03 04:10:16 +00:00
# Update the current user's authentication so the newly added group appears
# as available to them
global $C_auth;
$C_auth->auth_update();
return;
}
2009-08-03 04:10:16 +00:00
private function isAuthorised($VAR) {
# Remove any group ids <= 1001 from the VAR array:
global $C_debug,$C_auth;
2009-08-03 04:10:16 +00:00
$id = array();
2009-08-03 04:10:16 +00:00
if (isset($VAR['id']))
$id = explode(',',$VAR['id']);
2009-08-03 04:10:16 +00:00
for ($i=0; $i<count($id); $i++) {
if (! empty($id[$i]) && $id[$i] > 1001) {
# Check if group allowed:
2009-08-03 04:10:16 +00:00
if (! $C_auth->auth_group_by_id($id[$i])) {
$C_debug->alert('The selected group cannot be modified as your account is not authorized for it.');
2009-08-03 04:10:16 +00:00
return true;
}
} else {
2009-08-03 04:10:16 +00:00
$C_debug->alert('The selected group is part of the CORE and cannot be edited or deleted.');
return true;
}
}
}
2009-08-03 04:10:16 +00:00
/**
* Update an entry
*/
public function update($VAR) {
if (! $this->isAuthorised($VAR))
return parent::update($VAR);
}
2009-08-03 04:10:16 +00:00
/**
* Delete a record
*/
public function delete($VAR) {
$this->associated_DELETE = array();
2009-08-03 04:10:16 +00:00
array_push($this->associated_DELETE,array('table'=>'account_group','field'=>'group_id'));
array_push($this->associated_DELETE,array('table'=>'group_method','field'=>'group_id'));
2009-08-03 04:10:16 +00:00
if (! $this->isAuthorised($VAR))
return parent::delete($VAR);
}
2009-08-03 04:10:16 +00:00
/**
* Draw the group layout
*/
public function tpl_visual_layout() {
$class = 'form_field';
2009-08-03 04:10:16 +00:00
# Get the default group
if (! isset($default))
$default = unserialize(DEFAULT_GROUP);
2009-08-03 04:10:16 +00:00
for ($i=0; $i<count($default); $i++)
$checked[$default[$i]] = true;
# Get the currect selected value & display
$db = &DB();
2009-08-03 04:10:16 +00:00
$result = $db->Execute(sqlSelect($db,'group','id,name,parent_id','id!=0','parent_id,name'));
2009-08-03 04:10:16 +00:00
# Error handling
if (! $result) {
global $C_debug;
2009-08-03 04:10:16 +00:00
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
2009-08-03 04:10:16 +00:00
# Number of results
if ($result->RecordCount() > 0)
echo $this->build_nested_list($result->GetArray(),0,0);
else
2009-08-03 04:10:16 +00:00
echo _('No groups available!');
}
2009-08-03 04:10:16 +00:00
/**
* This function will build a nested option list
* showing the heirachy of the groups
*
* @see tpl_visual_layout
*/
private function build_nested_list($arr,$level,$current) {
$ret = '';
for ($i=0; $i < count($arr); $i++) {
if ($arr[$i]['parent_id'] == $current) {
if ($level)
$ret .= sprintf('%s|__ ',str_repeat('&nbsp;&nbsp;&nbsp;',$level));
$ret .= sprintf('&nbsp;&nbsp;%s&nbsp;&nbsp;&nbsp;<a href="?_page=group:view&amp;id=%s">%s</a><br/>',$arr[$i]['name'],$arr[$i]['id'],_('Edit'));
$ret .= $this->build_nested_list($arr,$level+1,$arr[$i]['id']);
}
}
2009-08-03 04:10:16 +00:00
return $ret;
}
}
2009-08-03 04:10:16 +00:00
?>