162 lines
3.8 KiB
PHP
162 lines
3.8 KiB
PHP
<?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
|
|
*
|
|
* 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
|
|
* @author Tony Landis <tony@agileco.com>
|
|
* @package AgileBill
|
|
* @subpackage Module:Group
|
|
*/
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
} else
|
|
return false;
|
|
|
|
# Update the current user's authentication so the newly added group appears
|
|
# as available to them
|
|
global $C_auth;
|
|
$C_auth->auth_update();
|
|
|
|
return;
|
|
}
|
|
|
|
private function isAuthorised($VAR) {
|
|
# Remove any group ids <= 1001 from the VAR array:
|
|
global $C_debug,$C_auth;
|
|
|
|
$id = array();
|
|
|
|
if (isset($VAR['id']))
|
|
$id = explode(',',$VAR['id']);
|
|
|
|
for ($i=0; $i<count($id); $i++) {
|
|
if (! empty($id[$i]) && $id[$i] > 1001) {
|
|
|
|
# Check if group allowed:
|
|
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.');
|
|
|
|
return true;
|
|
}
|
|
|
|
} else {
|
|
$C_debug->alert('The selected group is part of the CORE and cannot be edited or deleted.');
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update an entry
|
|
*/
|
|
public function update($VAR) {
|
|
if (! $this->isAuthorised($VAR))
|
|
return parent::update($VAR);
|
|
}
|
|
|
|
/**
|
|
* Delete a record
|
|
*/
|
|
public function delete($VAR) {
|
|
$this->associated_DELETE = array();
|
|
|
|
array_push($this->associated_DELETE,array('table'=>'account_group','field'=>'group_id'));
|
|
array_push($this->associated_DELETE,array('table'=>'group_method','field'=>'group_id'));
|
|
|
|
if (! $this->isAuthorised($VAR))
|
|
return parent::delete($VAR);
|
|
}
|
|
|
|
/**
|
|
* Draw the group layout
|
|
*/
|
|
public function tpl_visual_layout() {
|
|
$class = 'form_field';
|
|
|
|
# Get the default group
|
|
if (! isset($default))
|
|
$default = unserialize(DEFAULT_GROUP);
|
|
|
|
for ($i=0; $i<count($default); $i++)
|
|
$checked[$default[$i]] = true;
|
|
|
|
# Get the currect selected value & display
|
|
$db = &DB();
|
|
$result = $db->Execute(sqlSelect($db,'group','id,name,parent_id','id!=0','parent_id,name'));
|
|
|
|
# Error handling
|
|
if (! $result) {
|
|
global $C_debug;
|
|
|
|
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
|
|
}
|
|
|
|
# Number of results
|
|
if ($result->RecordCount() > 0)
|
|
echo $this->build_nested_list($result->GetArray(),0,0);
|
|
else
|
|
echo _('No groups available!');
|
|
}
|
|
|
|
/**
|
|
* 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(' ',$level));
|
|
|
|
$ret .= sprintf(' %s <a href="?_page=group:view&id=%s">%s</a><br/>',$arr[$i]['name'],$arr[$i]['id'],_('Edit'));
|
|
$ret .= $this->build_nested_list($arr,$level+1,$arr[$i]['id']);
|
|
}
|
|
}
|
|
|
|
return $ret;
|
|
}
|
|
}
|
|
?>
|