Changes to AgileBill
This commit is contained in:
@@ -1,612 +1,367 @@
|
||||
<?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
|
||||
*
|
||||
* For questions, help, comments, discussion, etc., please join the
|
||||
* Agileco community forums at http://forum.agileco.com/
|
||||
*
|
||||
* 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>
|
||||
* @author Tony Landis <tony@agileco.com>
|
||||
* @package AgileBill
|
||||
* @version 1.4.93
|
||||
* @subpackage Module:Product
|
||||
*/
|
||||
|
||||
class product_cat
|
||||
{
|
||||
|
||||
# Open the constructor for this mod
|
||||
function product_cat()
|
||||
{
|
||||
# name of this module:
|
||||
$this->module = "product_cat";
|
||||
/**
|
||||
* The main AgileBill Product Category Class
|
||||
*
|
||||
* @package AgileBill
|
||||
* @subpackage Module:Product
|
||||
*/
|
||||
class product_cat extends OSB_module {
|
||||
/**
|
||||
* User Menu
|
||||
* List the available categories
|
||||
*/
|
||||
public function user_menu($VAR) {
|
||||
global $smarty,$C_auth;
|
||||
|
||||
# location of the construct XML file:
|
||||
$this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
|
||||
$db = &DB();
|
||||
$result = $db->Execute(sqlSelect($db,'product_cat','*','status=1 AND (parent_id=0 OR parent_id IS NULL OR parent_id=id)','position'));
|
||||
$smart = array();
|
||||
|
||||
# open the construct file for parsing
|
||||
$C_xml = new CORE_xml;
|
||||
$construct = $C_xml->xml_to_array($this->xml_construct);
|
||||
|
||||
$this->method = $construct["construct"]["method"];
|
||||
$this->trigger = $construct["construct"]["trigger"];
|
||||
$this->field = $construct["construct"]["field"];
|
||||
$this->table = $construct["construct"]["table"];
|
||||
$this->module = $construct["construct"]["module"];
|
||||
$this->cache = $construct["construct"]["cache"];
|
||||
$this->order_by = $construct["construct"]["order_by"];
|
||||
$this->limit = $construct["construct"]["limit"];
|
||||
}
|
||||
|
||||
|
||||
##############################
|
||||
## USER CATEGORY ARR SMARTY ##
|
||||
##############################
|
||||
function user_menu($VAR)
|
||||
{
|
||||
global $smarty, $C_auth;
|
||||
$db = &DB();
|
||||
$dbc = new CORE_database;
|
||||
$sql = $dbc->sql_select( "product_cat", "*",
|
||||
"status = 1 AND (parent_id = 0 OR parent_id IS NULL OR parent_id = id)", "position", $db);
|
||||
$result = $db->Execute($sql);
|
||||
if($result->RecordCount() == 0) {
|
||||
if ($result->RecordCount() == 0) {
|
||||
return false;
|
||||
} else {
|
||||
while(!$result->EOF) {
|
||||
# check for group settings:
|
||||
|
||||
} else {
|
||||
while (! $result->EOF) {
|
||||
# Check for group settings:
|
||||
$groups = unserialize($result->fields['group_avail']);
|
||||
|
||||
$auth = false;
|
||||
for($ii=0; $ii<count($groups); $ii++) {
|
||||
if($C_auth->auth_group_by_id($groups[$ii])) $auth = true;
|
||||
for ($ii=0; $ii<count($groups); $ii++) {
|
||||
if ($C_auth->auth_group_by_id($groups[$ii]))
|
||||
$auth = true;
|
||||
}
|
||||
|
||||
if($auth) {
|
||||
# Create the array for smarty
|
||||
$smart[] = $result->fields;
|
||||
if ($auth) {
|
||||
# Create the array for smarty
|
||||
array_push($smart,$result->fields);
|
||||
$i++;
|
||||
}
|
||||
$result->MoveNext();
|
||||
|
||||
$result->MoveNext();
|
||||
}
|
||||
$smarty->assign('product_cat', $smart);
|
||||
}
|
||||
|
||||
$smarty->assign('product_cat',$smart);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User view a category
|
||||
*/
|
||||
public function user_view($VAR) {
|
||||
global $smarty,$C_auth;
|
||||
|
||||
##############################
|
||||
## USER VIEW A CATEGORY ##
|
||||
##############################
|
||||
function user_view($VAR)
|
||||
{
|
||||
global $smarty, $C_auth;
|
||||
$db = &DB();
|
||||
$db = &DB();
|
||||
|
||||
### Get the category information:
|
||||
$sql = sqlSelect($db, "product_cat", "id,position,template,name,thumbnail,group_avail,parent_id,max", "status = 1 AND id = ::{$VAR['id']}::");
|
||||
$result = $db->Execute($sql);
|
||||
# Get the category information:
|
||||
$result = $db->Execute(sqlSelect($db,'product_cat','id,position,template,name,thumbnail,group_avail,parent_id,max',array('status'=>1,'id'=>$VAR['id'])));
|
||||
|
||||
if(!$result || $result->RecordCount() == 0) {
|
||||
if (! $result || $result->RecordCount() == 0) {
|
||||
return false;
|
||||
} else {
|
||||
|
||||
# check for group settings:
|
||||
} else {
|
||||
# Check for group settings
|
||||
$groups = unserialize($result->fields['group_avail']);
|
||||
|
||||
# max results per page:
|
||||
$max = $result->fields['max'];
|
||||
if(empty($max)) $max = 25;
|
||||
$count = 0;
|
||||
if(empty($VAR['page']) || !is_numeric($VAR['page']) || $VAR['page'] <= 1 ) {
|
||||
$page = 1;
|
||||
# Max results per page:
|
||||
$max = $result->fields['max'];
|
||||
|
||||
if (empty($max))
|
||||
$max = 25;
|
||||
|
||||
if (empty($VAR['page']) || ! is_numeric($VAR['page']) || $VAR['page'] <= 1) {
|
||||
$page = 1;
|
||||
$start = 0;
|
||||
|
||||
} else {
|
||||
$page = $VAR['page'];
|
||||
$start = ($page-1)*$max;
|
||||
}
|
||||
|
||||
$auth = false;
|
||||
for($ii=0; $ii<count($groups); $ii++) {
|
||||
if($C_auth->auth_group_by_id($groups[$ii])) $auth = true;
|
||||
}
|
||||
|
||||
if($auth) {
|
||||
$smart[] = $result->fields;
|
||||
$smarty->assign('product_cat_arr', $smart);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parent_id = $result->fields['parent_id'];
|
||||
if(!$parent_id) $parent_id = '0';
|
||||
}
|
||||
$auth = false;
|
||||
for ($ii=0; $ii<count($groups); $ii++) {
|
||||
if ($C_auth->auth_group_by_id($groups[$ii]))
|
||||
$auth = true;
|
||||
}
|
||||
|
||||
### Get the items in this category:
|
||||
$sql = sqlSelect($db, "product", "id,sku,thumbnail,avail_category_id,price_base,price_setup,group_avail", "active = 1", "position,sku");
|
||||
$result = $db->Execute($sql);
|
||||
if(!$result || $result->RecordCount() == 0) {
|
||||
if ($auth)
|
||||
$smarty->assign('product_cat_arr',array($result->fields));
|
||||
else
|
||||
return false;
|
||||
|
||||
$parent_id = $result->fields['parent_id'];
|
||||
if (! $parent_id)
|
||||
$parent_id = '0';
|
||||
}
|
||||
|
||||
# Get the items in this category:
|
||||
$result = $db->Execute(sqlSelect($db,'product','id,sku,thumbnail,avail_category_id,price_base,price_setup,group_avail',array('active'=>1),'position,sku'));
|
||||
if (! $result || $result->RecordCount() == 0) {
|
||||
return false;
|
||||
} else {
|
||||
while(!$result->EOF) {
|
||||
|
||||
} else {
|
||||
$count = 0;
|
||||
$smart_prod = array();
|
||||
while (! $result->EOF) {
|
||||
# check that this item can be displayed in the current category:
|
||||
$cat = false;
|
||||
$cats = unserialize($result->fields['avail_category_id']);
|
||||
for($i=0; $i<count($cats); $i++) {
|
||||
if($cats[$i] == $VAR['id']) {
|
||||
$cat = false;
|
||||
$cats = unserialize($result->fields['avail_category_id']);
|
||||
for ($i=0; $i<count($cats); $i++) {
|
||||
if ($cats[$i] == $VAR['id']) {
|
||||
$cat = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($cat) {
|
||||
# check for group settings:
|
||||
if ($cat) {
|
||||
# Check for group settings:
|
||||
$groups = unserialize($result->fields['group_avail']);
|
||||
|
||||
$auth = false;
|
||||
for($ii=0; $ii<count($groups); $ii++) {
|
||||
if($C_auth->auth_group_by_id($groups[$ii])) {
|
||||
for ($ii=0; $ii<count($groups); $ii++) {
|
||||
if ($C_auth->auth_group_by_id($groups[$ii])) {
|
||||
$auth = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### Paging
|
||||
if($auth) {
|
||||
if($count >= $start && $count < $max*$page)
|
||||
$smart_prod[] = $result->fields;
|
||||
# Paging
|
||||
if ($auth) {
|
||||
if ($count >= $start && $count < $max*$page)
|
||||
array_push($smart_prod,$result->fields);
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
$result->MoveNext();
|
||||
}
|
||||
}
|
||||
|
||||
$results = $count;
|
||||
$pages = intval($results / $max);
|
||||
if ($results % $max) $pages++;
|
||||
$pages = intval($results / $max);
|
||||
if ($results % $max)
|
||||
$pages++;
|
||||
|
||||
for($i=1;$i<=$pages;$i++) $pagearr[$i] = $i;
|
||||
for ($i=1;$i<=$pages;$i++)
|
||||
$pagearr[$i] = $i;
|
||||
|
||||
$smarty->assign('product_arr', $smart_prod);
|
||||
$smarty->assign('page_page', $page);
|
||||
$smarty->assign('page_results', $results);
|
||||
$smarty->assign('page_pages', $pages);
|
||||
$smarty->assign('page_arr', $pagearr);
|
||||
$smarty->assign('product_arr',$smart_prod);
|
||||
$smarty->assign('page_page',$page);
|
||||
$smarty->assign('page_results',$results);
|
||||
$smarty->assign('page_pages',$pages);
|
||||
$smarty->assign('page_arr',$pagearr);
|
||||
}
|
||||
|
||||
### Get any sub-categories:
|
||||
$sql = sqlSelect($db, "product_cat", "*", "status = 1 AND parent_id = ::{$VAR['id']}::","position,name");
|
||||
$result = $db->Execute($sql);
|
||||
if($result && $result->RecordCount()) {
|
||||
while(!$result->EOF) {
|
||||
$smart_sub_cat[] = $result->fields;
|
||||
# Get any sub-categories:
|
||||
$result = $db->Execute($q=sqlSelect($db,'product_cat','*',array('status'=>1,'parent_id'=>$VAR['id']),'position,name'));
|
||||
$smart_sub_cat = array();
|
||||
|
||||
if ($result && $result->RecordCount()) {
|
||||
while (! $result->EOF) {
|
||||
array_push($smart_sub_cat,$result->fields);
|
||||
$result->MoveNext();
|
||||
}
|
||||
$smarty->assign('product_sub_cat', $smart_sub_cat);
|
||||
}
|
||||
|
||||
### Get any parent categores:
|
||||
$p = AGILE_DB_PREFIX;
|
||||
$d = DEFAULT_SITE;
|
||||
$smart_parent_cat = Array();
|
||||
for($i=0; $i<=5; $i++)
|
||||
{
|
||||
if($parent_id > 0 )
|
||||
{
|
||||
$smarty->assign('product_sub_cat',$smart_sub_cat);
|
||||
}
|
||||
|
||||
# Get any parent categores:
|
||||
$smart_parent_cat = array();
|
||||
for ($i=0; $i<=5; $i++) {
|
||||
if ($parent_id > 0 ) {
|
||||
# Get parent id & add to array
|
||||
$sql = "SELECT
|
||||
{$p}product_cat.id,
|
||||
{$p}product_cat.parent_id,
|
||||
{$p}product_cat.template,
|
||||
{$p}product_cat_translate.name
|
||||
FROM
|
||||
{$p}product_cat,{$p}product_cat_translate
|
||||
WHERE
|
||||
{$p}product_cat.site_id = {$d}
|
||||
AND
|
||||
{$p}product_cat_translate.site_id = {$d}
|
||||
AND
|
||||
{$p}product_cat.id = $parent_id
|
||||
AND
|
||||
{$p}product_cat_translate.product_cat_id = $parent_id
|
||||
AND
|
||||
{$p}product_cat_translate.language_id = '".SESS_LANGUAGE."'";
|
||||
$result = $db->Execute($sql);
|
||||
if($result && $result->RecordCount())
|
||||
{
|
||||
$parent_id = $result->fields['parent_id'];
|
||||
$smart_parent_cat[] = $result->fields;
|
||||
$result = $db->Execute(sqlSelect($db,array('product_cat','product_cat_translate'),'A.id,A.parent_id,A.template,B.name',array('A.id'=>$parent_id,'B.product_cat_id'=>$parent_id,'B.language_id'=>SESS_LANGUAGE)));
|
||||
if ($result && $result->RecordCount()) {
|
||||
$parent_id = $result->fields['parent_id'];
|
||||
array_push($smart_parent_cat,$result->fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$smart_parent_cat = array_reverse($smart_parent_cat);
|
||||
|
||||
## Get the current category:
|
||||
$sql = "SELECT
|
||||
{$p}product_cat.id,
|
||||
{$p}product_cat.parent_id,
|
||||
{$p}product_cat.template,
|
||||
{$p}product_cat_translate.name
|
||||
FROM
|
||||
{$p}product_cat,{$p}product_cat_translate
|
||||
WHERE
|
||||
{$p}product_cat.site_id = {$d}
|
||||
AND
|
||||
{$p}product_cat_translate.site_id = {$d}
|
||||
AND
|
||||
{$p}product_cat.id = ".$db->qstr($VAR['id'])."
|
||||
AND
|
||||
{$p}product_cat_translate.product_cat_id = ".$db->qstr($VAR['id'])."
|
||||
AND
|
||||
{$p}product_cat_translate.language_id = '".SESS_LANGUAGE."'";
|
||||
$result = $db->Execute($sql);
|
||||
if($result && $result->RecordCount())
|
||||
$smart_parent_cat[] = $result->fields;
|
||||
|
||||
$smarty->assign('parent_cat', $smart_parent_cat);
|
||||
# Get the current category:
|
||||
$result = $db->Execute(sqlSelect($db,array('product_cat','product_cat_translate'),'A.id,A.parent_id,A.template,B.name',array('A.id'=>$VAR['id'],'B.product_cat_id'=>$VAR['id'],'B.language_id'=>SESS_LANGUAGE)));
|
||||
if ($result && $result->RecordCount())
|
||||
$smart_parent_cat[] = $result->fields;
|
||||
|
||||
$smarty->assign('parent_cat',$smart_parent_cat);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will build a nested option list
|
||||
* showing the heirachy of the product categories
|
||||
*
|
||||
* @see tpl_admin_menu_parent
|
||||
*/
|
||||
private function build_nested_option_list($arr,$start,$level,$current) {
|
||||
$option = '';
|
||||
|
||||
for ($i=0; $i<count($arr[$start]); $i++) {
|
||||
$id = $arr[$start][$i]['id'];
|
||||
|
||||
###############################
|
||||
## ADMIN SINGLE SELECT MENU ##
|
||||
###############################
|
||||
function admin_menu_parent($VAR)
|
||||
{
|
||||
global $smarty, $C_auth;
|
||||
$db = &DB();
|
||||
$dbc = new CORE_database;
|
||||
$sql = $dbc->sql_select( "product_cat", "*", "", "parent_id,position,name", $db);
|
||||
$result = $db->Execute($sql);
|
||||
if ($id == $current || $arr[$start][$i]['sel'])
|
||||
$sel = ' selected="selected"';
|
||||
else
|
||||
$sel = '';
|
||||
|
||||
# Get current id
|
||||
if(!empty($VAR['id'])) {
|
||||
$cid = ereg_replace(",","", $VAR['id']);
|
||||
} else {
|
||||
$current = '';
|
||||
if ($level == 0)
|
||||
$option .= sprintf('<option value="%s"%s>%s</option>',$id,$sel,$arr[$start][$i]['name']);
|
||||
else
|
||||
$option .= sprintf('<option value="%s"%s>%s- %s</option>',$id,$sel,str_repeat(' ',$level-1),$arr[$start][$i]['name']);
|
||||
|
||||
if (isset($arr[$id]))
|
||||
$option .= $this->build_nested_option_list($arr,$id,$level+1,$current);
|
||||
}
|
||||
|
||||
return $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a parent for a category
|
||||
*/
|
||||
public function tpl_admin_menu_parent($VAR) {
|
||||
global $smarty,$C_auth;
|
||||
|
||||
$db = &DB();
|
||||
|
||||
# Get current id
|
||||
if (! empty($VAR['id']))
|
||||
$cid = str_replace(',','',$VAR['id']);
|
||||
else
|
||||
$current = '';
|
||||
|
||||
# Loop and put in array
|
||||
while(!$result->EOF) {
|
||||
if($result->fields['parent_id'] == "" || $result->fields['parent_id'] == 0 || $result->fields['parent_id'] == $result->fields['id']) {
|
||||
$result = $db->Execute(sqlSelect($db,'product_cat','*','','parent_id,position,name'));
|
||||
|
||||
while (! $result->EOF) {
|
||||
if ($result->fields['parent_id'] == '' || $result->fields['parent_id'] == 0 || $result->fields['parent_id'] == $result->fields['id'])
|
||||
$arr[0][] = $result->fields;
|
||||
} else {
|
||||
$arr["{$result->fields['parent_id']}"][] = $result->fields;
|
||||
}
|
||||
else
|
||||
$arr[$result->fields['parent_id']][] = $result->fields;
|
||||
|
||||
# get current parent_id
|
||||
if($cid > 0 && $result->fields['id'] == $cid)
|
||||
if ($cid > 0 && $result->fields['id'] == $cid)
|
||||
$current = $result->fields['parent_id'];
|
||||
|
||||
$result->MoveNext();
|
||||
}
|
||||
|
||||
# Create menu
|
||||
$option = '';
|
||||
|
||||
for($i=0; $i<count($arr[0]); $i++)
|
||||
{
|
||||
$id = $arr[0][$i]["id"];
|
||||
|
||||
if($id == $current)
|
||||
$sel = 'selected';
|
||||
else
|
||||
$sel = '';
|
||||
|
||||
$option .= '<option value="'.$id.'" '.$sel.'>'.$arr[0][$i]["name"].'</option>';
|
||||
|
||||
##########################
|
||||
# get the sub-categories # (LEVEL 2)
|
||||
if(isset($arr[$id]))
|
||||
{
|
||||
for($ii=0; $ii<count($arr[$id]); $ii++)
|
||||
{
|
||||
$idx = $arr[$id][$ii]["id"];
|
||||
if($idx == $current) $sel = 'selected'; else $sel = '';
|
||||
$option .= '<option value="'.$idx.'" '.$sel.'>- '.$arr[$id][$ii]["name"].'</option>';
|
||||
}
|
||||
|
||||
##########################
|
||||
# get the sub-categories # (LEVEL 3)
|
||||
if(isset($arr[$idx]))
|
||||
{
|
||||
for($iii=0; $iii<count($arr[$idx]); $iii++)
|
||||
{
|
||||
$idx2 = $arr[$idx][$iii]["id"];
|
||||
if($idx2 == $current) $sel = 'selected'; else $sel = '';
|
||||
$option .= '<option value="'.$idx2.'" '.$sel.'> - '.$arr[$idx][$iii]["name"].'</option>';
|
||||
}
|
||||
|
||||
##########################
|
||||
# get the sub-categories # (LEVEL 4)
|
||||
if(isset($arr[$idx2]))
|
||||
{
|
||||
for($iiii=0; $iiii<count($arr[$idx2]); $iiii++)
|
||||
{
|
||||
$idx3 = $arr[$idx2][$iiii]["id"];
|
||||
if($idx3 == $current) $sel = 'selected'; else $sel = '';
|
||||
$option .= '<option value="'.$idx3.'" '.$sel.'> - '.$arr[$idx2][$iiii]["name"].'</option>';
|
||||
}
|
||||
|
||||
##########################
|
||||
# get the sub-categories # (LEVEL 5)
|
||||
if(isset($arr[$idx3]))
|
||||
{
|
||||
for($iiiii=0; $iiiii<count($arr[$idx3]); $iiiii++)
|
||||
{
|
||||
$idx4 = $arr[$idx3][$iiiii]["id"];
|
||||
if($idx4 == $current) $sel = 'selected'; else $sel = '';
|
||||
$option .= '<option value="'.$idx4.'" '.$sel.'> - '.$arr[$idx3][$iiiii]["name"].'</option>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Create menu
|
||||
echo '<select name="product_cat_parent_id" onChange="submit()">';
|
||||
echo '<option value="0"></option>';
|
||||
echo $option;
|
||||
echo '</select>';
|
||||
echo '<option value=""> </option>';
|
||||
echo $this->build_nested_option_list($arr,0,0,$current);
|
||||
echo '</select>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a product category for a product
|
||||
*/
|
||||
public function tpl_admin_menu_product($VAR) {
|
||||
global $smarty,$C_auth;
|
||||
|
||||
##############################
|
||||
## ADMIN MULTI SELECT MENU ##
|
||||
##############################
|
||||
function admin_menu_product($VAR)
|
||||
{
|
||||
global $smarty, $C_auth;
|
||||
$db = &DB();
|
||||
$dbc = new CORE_database;
|
||||
$db = &DB();
|
||||
$dbc = new CORE_database;
|
||||
|
||||
# Get current category id
|
||||
if(!empty($VAR['id'])) {
|
||||
$product_id = ereg_replace(",","", $VAR['id']);
|
||||
$sql = $dbc->sql_select("product", "avail_category_id", "id = $product_id","", $db);
|
||||
$product = $db->Execute($sql);
|
||||
if (! empty($VAR['id'])) {
|
||||
$product_id = str_replace(',','',$VAR['id']);
|
||||
$product = $db->Execute(sqlSelect($db,'product','avail_category_id',array('id'=>$product_id)));
|
||||
$current = unserialize($product->fields['avail_category_id']);
|
||||
|
||||
} else {
|
||||
$current = '';
|
||||
}
|
||||
|
||||
# Loop and put in array
|
||||
$sql = $dbc->sql_select( "product_cat", "*", "", "parent_id,position,name", $db);
|
||||
$result = $db->Execute($sql);
|
||||
while(!$result->EOF)
|
||||
{
|
||||
# determine if selected
|
||||
$result = $db->Execute(sqlSelect($db,'product_cat','*','','parent_id,position,name'));
|
||||
|
||||
while (! $result->EOF) {
|
||||
# Determine if selected
|
||||
$select = false;
|
||||
for($ix=0; $ix<count($current); $ix++) {
|
||||
if($current[$ix] == $result->fields['id']) {
|
||||
for ($ix=0; $ix<count($current); $ix++) {
|
||||
if ($current[$ix] == $result->fields['id']) {
|
||||
$result->fields['sel'] = 'selected';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# set array
|
||||
if($result->fields['parent_id'] == "" || $result->fields['parent_id'] == 0 || $result->fields['parent_id'] == $result->fields['id']) {
|
||||
$arr[0][] = $result->fields;
|
||||
} else {
|
||||
$arr["{$result->fields['parent_id']}"][] = $result->fields;
|
||||
}
|
||||
# set array
|
||||
if ($result->fields['parent_id'] == '' || $result->fields['parent_id'] == 0 || $result->fields['parent_id'] == $result->fields['id'])
|
||||
$arr[0][] = $result->fields;
|
||||
else
|
||||
$arr[$result->fields['parent_id']][] = $result->fields;
|
||||
|
||||
$result->MoveNext();
|
||||
}
|
||||
}
|
||||
|
||||
# Create menu
|
||||
$option = '';
|
||||
echo '<select name="product_avail_category_id[]" size="5" multiple >';
|
||||
echo $this->build_nested_option_list($arr,0,0,null);
|
||||
echo '</select>';
|
||||
}
|
||||
|
||||
for($i=0; $i<count($arr[0]); $i++)
|
||||
{
|
||||
$id = $arr[0][$i]["id"];
|
||||
|
||||
$option .= '<option value="'.$id.'" '.@$arr[0][$i]["sel"].'>'.$arr[0][$i]["name"].'</option>';
|
||||
|
||||
##########################
|
||||
# get the sub-categories # (LEVEL 2)
|
||||
if(isset($arr[$id]))
|
||||
{
|
||||
for($ii=0; $ii<count($arr[$id]); $ii++)
|
||||
{
|
||||
$idx = $arr[$id][$ii]["id"];
|
||||
$option .= '<option value="'.$idx.'" '.@$arr[$id][$ii]["sel"].'>- '.$arr[$id][$ii]["name"].'</option>';
|
||||
}
|
||||
|
||||
##########################
|
||||
# get the sub-categories # (LEVEL 3)
|
||||
if(isset($arr[$idx]))
|
||||
{
|
||||
for($iii=0; $iii<count($arr[$idx]); $iii++)
|
||||
{
|
||||
$idx2 = $arr[$idx][$iii]["id"];
|
||||
$option .= '<option value="'.$idx2.'" '.@$arr[$idx][$iii]["sel"].'> - '.$arr[$idx][$iii]["name"].'</option>';
|
||||
}
|
||||
|
||||
##########################
|
||||
# get the sub-categories # (LEVEL 4)
|
||||
if(isset($arr[$idx2]))
|
||||
{
|
||||
for($iiii=0; $iiii<count($arr[$idx2]); $iiii++)
|
||||
{
|
||||
$idx3 = $arr[$idx2][$iiii]["id"];
|
||||
$option .= '<option value="'.$idx3.'" '.@$arr[$idx2][$iiii]["sel"].'> - '.$arr[$idx2][$iiii]["name"].'</option>';
|
||||
}
|
||||
|
||||
##########################
|
||||
# get the sub-categories # (LEVEL 5)
|
||||
if(isset($arr[$idx3]))
|
||||
{
|
||||
for($iiiii=0; $iiiii<count($arr[$idx3]); $iiiii++)
|
||||
{
|
||||
$idx4 = $arr[$idx3][$iiiii]["id"];
|
||||
$option .= '<option value="'.$idx4.'" '.@$arr[$idx3][$iiiii]["sel"].'> - '.$arr[$idx3][$iiiii]["name"].'</option>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo '<select name="product_avail_category_id[]" size="5" multiple >';
|
||||
echo $option;
|
||||
echo '</select>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
##############################
|
||||
## ADD ##
|
||||
##############################
|
||||
function add($VAR)
|
||||
{
|
||||
/**
|
||||
* Update an entry
|
||||
*/
|
||||
public function update($VAR) {
|
||||
global $_FILES;
|
||||
|
||||
####################################################################
|
||||
### Validate the thumbnail upoad:
|
||||
if(isset($_FILES['upload_file1']) && $_FILES['upload_file1']['size'] > 0)
|
||||
{
|
||||
$VAR['product_cat_thumbnail'] = "cat_thmb_".$_FILES['upload_file1']['name'];
|
||||
# Validate the thumbnail upload
|
||||
if (isset($_FILES['upload_file1']) && $_FILES['upload_file1']['size'] > 0)
|
||||
$VAR['product_cat_thumbnail'] = sprintf('cat_thmb_%s',$_FILES['upload_file1']['name']);
|
||||
elseif ($VAR['delthumb'] == 1)
|
||||
$VAR['product_cat_thumbnail'] = '';
|
||||
|
||||
# Validate the image upload
|
||||
if (isset($_FILES['upload_file2']) && $_FILES['upload_file2']['size'] > 0)
|
||||
$VAR['product_cat_image'] = sprintf('cat_img_%s',$_FILES['upload_file2']['name']);
|
||||
elseif ( $VAR['delimg'] == 1 )
|
||||
$VAR['product_cat_image'] = '';
|
||||
|
||||
$result = parent::update($VAR);
|
||||
|
||||
# Copy the image(s)
|
||||
if ($result) {
|
||||
# Copy 1ST file upload
|
||||
if (isset($_FILES['upload_file1']) && $_FILES['upload_file1']['size'] > 0)
|
||||
copy($_FILES['upload_file1']['tmp_name'],sprintf('%scat_thmb_%s',PATH_IMAGES,$_FILES['upload_file1']['name']));
|
||||
|
||||
# Copy the 2ND file upload
|
||||
if (isset($_FILES['upload_file2']) && $_FILES['upload_file2']['size'] > 0)
|
||||
copy($_FILES['upload_file2']['tmp_name'],sprintf('%scat_img_',PATH_IMAGES,$_FILES['upload_file2']['name']));
|
||||
}
|
||||
|
||||
### Validate the image upoad:
|
||||
if(isset($_FILES['upload_file2']) && $_FILES['upload_file2']['size'] > 0)
|
||||
{
|
||||
$VAR['product_cat_image'] = "cat_img_".$_FILES['upload_file2']['name'];
|
||||
}
|
||||
|
||||
|
||||
####################################################################
|
||||
## Attempt to add the record:
|
||||
|
||||
$type = "add";
|
||||
$this->method["$type"] = explode(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$result = $db->add($VAR, $this, $type);
|
||||
|
||||
|
||||
####################################################################
|
||||
### Copy the image(s)
|
||||
if($result)
|
||||
{
|
||||
### Copy 1ST file upoad:
|
||||
if(isset($_FILES['upload_file1']) && $_FILES['upload_file1']['size'] > 0)
|
||||
copy($_FILES['upload_file1']['tmp_name'], PATH_IMAGES . "cat_thmb_" . $_FILES['upload_file1']['name']);
|
||||
|
||||
### Copy the 2ND file upoad:
|
||||
if(isset($_FILES['upload_file2']) && $_FILES['upload_file2']['size'] > 0)
|
||||
copy($_FILES['upload_file2']['tmp_name'], PATH_IMAGES . "cat_img_" . $_FILES['upload_file2']['name']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an Entry
|
||||
*/
|
||||
public function delete($VAR) {
|
||||
$this->associated_DELETE = array();
|
||||
|
||||
array_push($this->associated_DELETE,array('table' =>'product_cat_translate','field'=>'product_cat_id'));
|
||||
|
||||
##############################
|
||||
## VIEW ##
|
||||
##############################
|
||||
function view($VAR)
|
||||
{
|
||||
$type = "view";
|
||||
$this->method["$type"] = explode(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->view($VAR, $this, $type);
|
||||
}
|
||||
|
||||
##############################
|
||||
## UPDATE ##
|
||||
##############################
|
||||
function update($VAR)
|
||||
{
|
||||
global $_FILES;
|
||||
|
||||
####################################################################
|
||||
### Validate the thumbnail upoad:
|
||||
if(isset($_FILES['upload_file1']) && $_FILES['upload_file1']['size'] > 0)
|
||||
{
|
||||
$VAR['product_cat_thumbnail'] = "cat_thmb_".$_FILES['upload_file1']['name'];
|
||||
} elseif ( $VAR['delthumb'] == 1 ) {
|
||||
$VAR['product_cat_thumbnail'] = "";
|
||||
}
|
||||
|
||||
### Validate the image upoad:
|
||||
if(isset($_FILES['upload_file2']) && $_FILES['upload_file2']['size'] > 0)
|
||||
{
|
||||
$VAR['product_cat_image'] = "cat_img_".$_FILES['upload_file2']['name'];
|
||||
} elseif ( $VAR['delimg'] == 1 ) {
|
||||
$VAR['product_cat_image'] = "";
|
||||
}
|
||||
|
||||
$type = "update";
|
||||
$this->method["$type"] = explode(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$result = $db->update($VAR, $this, $type);
|
||||
|
||||
####################################################################
|
||||
### Copy the image(s)
|
||||
if($result)
|
||||
{
|
||||
### Copy 1ST file upoad:
|
||||
if(isset($_FILES['upload_file1']) && $_FILES['upload_file1']['size'] > 0)
|
||||
copy($_FILES['upload_file1']['tmp_name'], PATH_IMAGES . "cat_thmb_" . $_FILES['upload_file1']['name']);
|
||||
|
||||
### Copy the 2ND file upoad:
|
||||
if(isset($_FILES['upload_file2']) && $_FILES['upload_file2']['size'] > 0)
|
||||
copy($_FILES['upload_file2']['tmp_name'], PATH_IMAGES . "cat_img_" . $_FILES['upload_file2']['name']);
|
||||
}
|
||||
parent::delete($VAR);
|
||||
}
|
||||
|
||||
##############################
|
||||
## DELETE ##
|
||||
##############################
|
||||
function delete($VAR)
|
||||
{
|
||||
$this->associated_DELETE =
|
||||
Array ( Array ( 'table' => 'product_cat_translate', 'field' => 'product_cat_id') );
|
||||
|
||||
$db = new CORE_database;
|
||||
$db->mass_delete($VAR, $this, "");
|
||||
}
|
||||
|
||||
##############################
|
||||
## SEARCH FORM ##
|
||||
##############################
|
||||
function search_form($VAR)
|
||||
{
|
||||
$type = "search";
|
||||
$this->method["$type"] = explode(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->search_form($VAR, $this, $type);
|
||||
}
|
||||
|
||||
##############################
|
||||
## SEARCH ##
|
||||
##############################
|
||||
function search($VAR)
|
||||
{
|
||||
$type = "search";
|
||||
$this->method["$type"] = explode(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->search($VAR, $this, $type);
|
||||
}
|
||||
|
||||
##############################
|
||||
## SEARCH SHOW ##
|
||||
##############################
|
||||
|
||||
function search_show($VAR)
|
||||
{
|
||||
$type = "search";
|
||||
$this->method["$type"] = explode(",", $this->method["$type"]);
|
||||
$db = new CORE_database;
|
||||
$db->search_show($VAR, $this, $type);
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
Reference in New Issue
Block a user