<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
* @author Rick Ellis
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeignitor.com/user_guide/license.html
* @link http://www.codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* CodeIgniter Admin Output Class
*
* Permits admin pages to be constructed easier.
*
* @package CodeIgniter
* @subpackage Libraries
* @category Libraries
* @author Philip Sturgeon
* @link
*/
class Admin_output extends CI_Parser {
var $filename = '';
var $title = '';
var $sidebars = array('clock', 'to-do');
var $mode = 'html';
var $header = 'header.html';
var $footer = 'footer.html';
var $wrap = true;
var $pdf_filename = ''; // What will the PDF be stored as?
/**
* Constructor - Calls the CI instance and sets a debug message
*
* The constructor can be passed an array of config values
*/
function Admin_output()
{
$CI =& get_instance();
log_message('debug', "Admin Output Class Initialized");
}
// --------------------------------------------------------------------
/**
* Set the title of the page
*
* @access public
* @param string
* @return void
*/
function title($title = '')
{
if($title != '') $this->title = $title;
}
/**
* Set the mode of the creation
*
* @access public
* @param string
* @return void
*/
function create
($filename = '', $data = array(), $return = false)
{
$CI =& get_instance();
if($filename != '') $this->filename = $filename;
if($data != array()) $this->data = $data;
// Work out the basics the template will need
$this->_set_defaults();
// Want header and footer file included, or just the main file?
if($this->wrap === true):
$output = $this->parse('admincp/'.$this->header, $this->data, true);
$output .= $this->parse('admincp/'.$this->filename, $this->data, true);
$output .= $this->parse('admincp/'.$this->footer, $this->data, true);
else:
$output = $this->parse('admincp/'.$this->filename, $this->data, true);
endif;
// Want it returned or output to browser?
if($return):
return $output;
else:
if($this->mode == 'pdf'):
/*
* Using the code from PDF library for Code Igniter applications
* Author: Phil Went, May 2007
* uses HTMLDOC http://www.htmldoc.org/ to create the pdfs
* modelled on the specialpdf mediawiki plugin by Thomas Hempel
*/
$page = $this->pdf_filename;
$mytemp = "/tmp/f" .time(). "-" .rand() . ".html";
$article_f = fopen($mytemp,'w');
# Write the content type to the client...
header("Content-Type: application/pdf");
header(sprintf('Content-Disposition: attachment; filename="%s.pdf"', $page));
# if the page is on a HTTPS server and contains images that are on the HTTPS server AND also reachable with HTTP
# uncomment the next line
#system("perl -pi -e 's/img src=\"https:\/\//img src=\"http:\/\//g' '$mytemp'");
# Run HTMLDOC to provide the PDF file to the user...
passthru("htmldoc -t pdf14 --charset iso-8859-1 --color --quiet --jpeg --webpage '$mytemp'");
else:
// Send it to output
$CI->output->set_output($output);
endif;
endif;
}
/**
* Should we include headers and footers?
*
* @access public
* @param string
* @return void
*/
function wrap($wrap = true)
{
$this->wrap = $wrap;
}
/**
* Turn off wrap mode
*
* @access public
* @param string
* @return void
*/
function mode($mode = '')
{
if($mode != '') $this->mode = $mode;
}
function _set_defaults()
{
$CI =& get_instance();
$CI->load->library('session');
$CI->load->model('employee_model');
// Get worker ID and worker Name
if($this->data['workerID'] = $CI->session->userdata('workerID')):
$CI->employee_model->fields = array('employeeFirstName', 'employeeLastName');
$employee = $CI->employee_model->get($this->data['workerID']);
$this->data['workerName'] = $employee['employeeFirstName'].' '.$employee['employeeLastName'];
endif;
// Replace all underscores with spaces, then capitalise first letters of words
$defaultTitle = ucwords(str_replace('_', ' ', $CI->uri->router->class .' > '.$CI->uri->router->method));
// Set the basic defaults
$this->data['pageTitle'] = ($this->title != '') ? $this->title : $defaultTitle;
$this->data['sideBars'] = $this->_build_sidebars();
if($this->mode == 'print' or $this->mode == 'pdf'):
$this->header = 'print_header.html';
$this->footer = 'print_footer.html';
if(!isset($this->data['printDate'])):
$this->data['printDate'] = gmdate('d/m/y');
endif;
if(!isset($this->data['printTime'])):
$this->data['printTime'] = gmdate('H:i');
endif;
endif;
}
/**
* Set the mode of the creation
*
* @access public
* @param array
* @return array
*/
function _build_sidebars()
{
foreach($this->sidebars as $sidebarName):
include(APPPATH.'views/admincp/sidebars/'.$sidebarName.'_code.php');
$sidebarContent = $this->parse('admincp/sidebars/'.$sidebarName.'.html', $this->data, true);
$sidebarArray[] = array('name' => $sidebarName, 'content' => $sidebarContent);
endforeach;
return $sidebarArray;
}
}
// END Admin_output class
?>