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/module_method/module_method.inc.php

203 lines
5.2 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:Method
*/
2009-08-03 04:10:16 +00:00
/**
* The main AgileBill Module Method Class
*
* @package AgileBill
* @subpackage Module:Method
*/
class module_method extends OSB_module {
/**
* View methods
*/
public function view_methods($VAR) {
$type = 'search';
$this->method[$type] = explode(',',$this->method[$type]);
$db = new CORE_database;
2009-08-03 04:10:16 +00:00
$this->this_search_show($VAR,$this,$type);
}
##############################
## VIEW METHODS p.2 #####
##############################
2009-08-03 04:10:16 +00:00
function this_search_show($VAR,$construct,$type) {
global $VAR;
# Get the list of parents for this group
$this->group_parent_list($VAR['module_method_group_id']);
2009-08-03 04:10:16 +00:00
# Generate the full query
$db = &DB();
$result = $db->Execute(sqlSelect($db,'module_method','*',array('module_id'=>$VAR['module_method_module_id'])));
2009-08-03 04:10:16 +00:00
# Put the results into a smarty accessable array
$i = 0;
$class_name = true;
2009-08-03 04:10:16 +00:00
while (! $result->EOF) {
$smart[$i] = $result->fields;
$method_id = $smart[$i]['id'];
2009-08-03 04:10:16 +00:00
# Get the auth status for this method & group
$resulta = $db->Execute(sqlSelect($db,'group_method','id',array('method_id'=>$smart[$i]['id'],'group_id'=>$VAR['module_method_group_id'])));
2009-08-03 04:10:16 +00:00
# Authorized by current group
if ($resulta->RecordCount() >= 1) {
$smart[$i]['checked'] = '1';
2009-08-03 04:10:16 +00:00
} else {
# Get the parent group id(s) for this group
$match = false;
for ($ii=0; $ii < count($this->group); $ii++) {
if ($match == false && $this->group[$ii] != $VAR['module_method_group_id']) {
$resultb = $db->Execute(sqlSelect($db,'group_method','id',array('method_id'=>$method_id,'group_id'=>$this->group[$ii])));
2009-08-03 04:10:16 +00:00
if ($resultb->RecordCount() >= 1)
$match = true;
}
}
2009-08-03 04:10:16 +00:00
# authorized by parent
if ($match)
$smart[$i]['checked'] = '2';
else
2009-08-03 04:10:16 +00:00
$smart[$i]['checked'] = '3';
}
2009-08-03 04:10:16 +00:00
if ($class_name) {
$smart[$i]['_C'] = 'row2';
2009-08-03 04:10:16 +00:00
$class_name = false;
} else {
$smart[$i]['_C'] = 'row1';
2009-08-03 04:10:16 +00:00
$class_name = true;
}
$result->MoveNext();
$i++;
}
# get any linked fields
2009-08-03 04:10:16 +00:00
if ($i > 0) {
$db_join = new CORE_database;
$this->result = $db_join->join_fields($smart, $this->linked);
2009-08-03 04:10:16 +00:00
} else {
$this->result = $smart;
}
# get the result count:
$results = $result->RecordCount();
# define the DB vars as a Smarty accessible block
global $smarty;
# define the results
2009-08-03 04:10:16 +00:00
$smarty->assign($construct->table,$this->result);
$smarty->assign('page',$VAR['page']);
$smarty->assign('order',1111);
$smarty->assign('sort',1111);
$smarty->assign('limit',1111);
$smarty->assign('search_id',1111);
2009-08-03 04:10:16 +00:00
$smarty->assign('results',$results);
# get the total pages for this search:
$this->pages = 1;
2009-08-03 04:10:16 +00:00
if ($search->results % $search->limit)
$this->pages++;
# total pages
2009-08-03 04:10:16 +00:00
$smarty->assign('pages',$this->pages);
# current page
2009-08-03 04:10:16 +00:00
$smarty->assign('page',$current_page);
$page_arr = '';
2009-08-03 04:10:16 +00:00
for ($i=0; $i <= $this->pages; $i++)
if ($this->page != $i)
$page_arr[] = $i;
2009-08-03 04:10:16 +00:00
# page array for menu
$smarty->assign('page_arr',$page_arr);
}
/**
* Get any inherited groups (parent) for a specified group
* @return void
* @since Version 1.0
* @param int Group Id
*/
2009-08-03 04:10:16 +00:00
function group_parent_list($group) {
# check if this group is a child with an active parent
$db = &DB();
2009-08-03 04:10:16 +00:00
$result = $db->Execute(sqlSelect($db,'group','id,parent_id',array('id'=>$group)));
# error handling
2009-08-03 04:10:16 +00:00
if ($result === false) {
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
# loop through the results
while (! $result->EOF) {
# add this group to the list
$this->group[] = $result->fields['id'];
# get inherited groups and check that the associated
# group is active before adding to the list of authorized groups.
2009-08-03 04:10:16 +00:00
if ($result->fields['parent_id'] != 0)
$this->group_parent_list($result->fields['parent_id']);
# move to next record
$result->MoveNext();
}
}
/**
* Mass add methods to a specific group
* @return void
* @since Version 1.0
* @param int Group Id
*/
2009-08-03 04:10:16 +00:00
function update_relations() {
global $VAR;
2009-08-03 04:10:16 +00:00
$db = &DB();
2009-08-03 04:10:16 +00:00
if (isset($VAR['id']) && $VAR['id'] != '')
$arr = explode(',',$VAR['id']);
else
return;
2009-08-03 04:10:16 +00:00
for ($i=0; $i<count($arr); $i++) {
# Clear the entries first
if ($i == 0)
$db->Execute(sqlDelete($db,'group_method',array('module_id'=>$VAR['module_method_module_id'],'group_id'=>$VAR['module_method_group_id'])));
2009-08-03 04:10:16 +00:00
if ($arr[$i] == 0)
return;
2009-08-03 04:10:16 +00:00
$db->Execute(sqlInsert($db,'group_method',array('method_id'=>$arr[$i],'module_id'=>$VAR['module_method_module_id'],'group_id'=>$VAR['module_method_group_id'])));
}
2009-08-03 04:10:16 +00:00
}
}
2009-08-03 04:10:16 +00:00
?>