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

165 lines
4.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 Modules:StaticPage
*/
2009-08-03 04:10:16 +00:00
/**
* The main AgileBill Static Page Class
*
* @package AgileBill
* @subpackage Modules:StaticPage
*/
class static_page extends OSB_module {
/**
* Delete a record
*/
public function delete($VAR) {
$this->associate_DELETE = array();
2009-08-03 04:10:16 +00:00
array_push($this->associated_DELETE,array('table'=>'static_page_translate','field'=>'static_page_id'));
2009-08-03 04:10:16 +00:00
return parent::delete($VAR);
}
2009-08-03 04:10:16 +00:00
/**
* Get a list of pages for a category
*
* @uses static_page_category
* @uses static_page_translate
*/
public function get_category_page_list($VAR) {
include_once(PATH_MODULES.'static_page_category/static_page_category.inc.php');
$spc = new static_page_category();
# Check we have an ID and are authorised to see the pages in that ID.
if (! isset($VAR['id']) || ! $spc->get_page_categories($VAR))
return false;
2009-08-03 04:10:16 +00:00
$db = &DB();
2009-08-03 04:10:16 +00:00
$result = $db->Execute(
sqlSelect($db,'static_page','id,name,date_expire,date_start',array('static_page_category_id'=>$VAR['id'],'status'=>1),'sort_order,date_orig,name'));
2009-08-03 04:10:16 +00:00
if (! $result || $result->RecordCount() == 0)
return false;
2009-08-03 04:10:16 +00:00
include_once(PATH_MODULES.'static_page_translate/static_page_translate.inc.php');
$spt = new static_page_translate();
global $C_auth;
$ii = 0;
2009-08-03 04:10:16 +00:00
$pages = array();
while (! $result->EOF) {
$start = $result->fields['date_start'];
2009-08-03 04:10:16 +00:00
$expire = $result->fields['date_expire'];
2009-08-03 04:10:16 +00:00
# Check that it is not expired
if (($start == '0' || $start <= time()+2) && ($expire == '0' || $expire >= time())) {
2009-08-03 04:10:16 +00:00
# Get the translated name, for the current session language
$translate = $spt->get_translated_page(array('id'=>$result->fields['id'],'language_id'=>SESS_LANGUAGE));
2009-08-03 04:10:16 +00:00
if ($translate) {
$translate['name'] = $result->fields['name'];
array_push($pages,$translate);
} else {
# Get the translated name, for the default langauge
$translate = $spt->get_translated_page(array('id'=>$result->fields['id'],'language_id'=>DEFAULT_LANGUAGE));
if ($translate) {
$translate['name'] = $result->fields['name'];
array_push($pages,$translate);
}
}
}
2009-08-03 04:10:16 +00:00
$result->MoveNext();
}
2009-08-03 04:10:16 +00:00
return $pages;
}
2009-08-03 04:10:16 +00:00
public function page_list($VAR) {
global $smarty;
$smart = $this->get_category_page_list($VAR);
2009-08-03 04:10:16 +00:00
if (! $smart || ! count($smart)) {
$smarty->assign('static_page_display',false);
return false;
2009-08-03 04:10:16 +00:00
} else {
$smarty->assign('static_page_display',true);
$smarty->assign('static_page_results',$smart);
return true;
}
}
2009-08-03 04:10:16 +00:00
/**
* Show a page
*/
public function page_show($VAR) {
global $smarty;
2009-08-03 04:10:16 +00:00
if (! isset($VAR['id']) && !isset($VAR['name'])) {
$smarty->assign('static_page_display', false);
return false;
}
2009-08-03 04:10:16 +00:00
# Get the page.
$db = &DB();
$page = $db->Execute($q=sqlSelect($db,'static_page','*',sprintf('status=1 AND (name=::%s:: OR id=::%s::)',@$VAR['name'],@$VAR['id'])));
2009-08-03 04:10:16 +00:00
if (! $page || $page->RecordCount() == 0) {
$smarty->assign('static_page_display',false);
return false;
}
2009-08-03 04:10:16 +00:00
# Check we have an ID and are authorised to see the pages in that ID.
$smart = $this->get_category_page_list(array('id'=>$page->fields['static_page_category_id']));
if (! $smart) {
$smarty->assign('static_page_display',false);
return false;
}
2009-08-03 04:10:16 +00:00
$pageValid = false;
foreach ($smart as $key => $values)
if ($values['name'] == $page->fields['name']) {
$pageValid = true;
break;
}
2009-08-03 04:10:16 +00:00
if (! $pageValid) {
$smarty->assign('static_page_display',false);
return false;
2009-08-03 04:10:16 +00:00
} else {
$smarty->assign('static_page_display',true);
$smarty->assign('static_page_results',$values);
return true;
}
}
}
2009-08-03 04:10:16 +00:00
?>