2008-11-26 22:50:40 +00:00
|
|
|
<?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
|
2008-11-26 22:50:40 +00:00
|
|
|
*
|
|
|
|
* @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>
|
2008-11-26 22:50:40 +00:00
|
|
|
* @package AgileBill
|
2009-08-03 04:10:16 +00:00
|
|
|
* @subpackage Module:Group
|
2008-11-26 22:50:40 +00:00
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
}
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
} else
|
|
|
|
return false;
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Update the current user's authentication so the newly added group appears
|
2008-11-26 22:50:40 +00:00
|
|
|
# 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;
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
$id = array();
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
if (isset($VAR['id']))
|
|
|
|
$id = explode(',',$VAR['id']);
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
for ($i=0; $i<count($id); $i++) {
|
|
|
|
if (! empty($id[$i]) && $id[$i] > 1001) {
|
2008-11-26 22:50:40 +00:00
|
|
|
|
|
|
|
# Check if group allowed:
|
2009-08-03 04:10:16 +00:00
|
|
|
if (! $C_auth->auth_group_by_id($id[$i])) {
|
2008-11-26 22:50:40 +00:00
|
|
|
$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;
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} 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;
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
/**
|
|
|
|
* Update an entry
|
|
|
|
*/
|
|
|
|
public function update($VAR) {
|
|
|
|
if (! $this->isAuthorised($VAR))
|
|
|
|
return parent::update($VAR);
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
/**
|
|
|
|
* Delete a record
|
|
|
|
*/
|
|
|
|
public function delete($VAR) {
|
|
|
|
$this->associated_DELETE = array();
|
2008-11-26 22:50:40 +00:00
|
|
|
|
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'));
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
if (! $this->isAuthorised($VAR))
|
|
|
|
return parent::delete($VAR);
|
|
|
|
}
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
/**
|
|
|
|
* Draw the group layout
|
|
|
|
*/
|
|
|
|
public function tpl_visual_layout() {
|
2008-11-26 22:50:40 +00:00
|
|
|
$class = 'form_field';
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Get the default group
|
|
|
|
if (! isset($default))
|
|
|
|
$default = unserialize(DEFAULT_GROUP);
|
2008-11-26 22:50:40 +00:00
|
|
|
|
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
|
2008-11-26 22:50:40 +00:00
|
|
|
$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'));
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Error handling
|
|
|
|
if (! $result) {
|
2008-11-26 22:50:40 +00:00
|
|
|
global $C_debug;
|
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
$C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
|
|
|
|
}
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
# Number of results
|
|
|
|
if ($result->RecordCount() > 0)
|
|
|
|
echo $this->build_nested_list($result->GetArray(),0,0);
|
2008-11-26 22:50:40 +00:00
|
|
|
else
|
2009-08-03 04:10:16 +00:00
|
|
|
echo _('No groups available!');
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
|
|
|
|
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(' ',$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']);
|
|
|
|
}
|
|
|
|
}
|
2008-11-26 22:50:40 +00:00
|
|
|
|
2009-08-03 04:10:16 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
2008-11-26 22:50:40 +00:00
|
|
|
}
|
2009-08-03 04:10:16 +00:00
|
|
|
?>
|