Revize 299
Přidáno uživatelem Michal Kliment před více než 15 roky(ů)
freenetis/trunk/kohana/application/helpers/arr.php | ||
---|---|---|
return $object;
|
||
}
|
||
|
||
/**
|
||
* @author Michal Kliment
|
||
* Converts array of objects to classic array in format: key = id of object, value = attributte
|
||
* @param $objects array of object to convert
|
||
* @param $attribute name of attributte to store as value of array
|
||
* @return array
|
||
*/
|
||
public static function from_objects ($objects, $attribute = 'name')
|
||
{
|
||
$array = array();
|
freenetis/trunk/kohana/application/models/invoice.php | ||
---|---|---|
<?php
|
||
class Invoice_Model extends ORM {
|
||
|
||
|
||
/**
|
||
* @author Michal Kliment
|
||
* Returns ORM_Iterator of all invoices
|
||
* @param $limit_from
|
||
* @param $limit_results
|
||
* @param $order_by
|
||
* @param $order_by_direction
|
||
* @return object ORM_Iterator
|
||
*/
|
||
public function get_all_invoices($limit_from = 0, $limit_results = 50, $order_by = 'id', $order_by_direction = 'ASC')
|
||
{
|
||
return self::$db->query('SELECT i.id, m.name as supplier, invoice_nr, var_sym, con_sym, date_inv, date_due, date_vat, vat, order_nr, currency FROM invoices i
|
freenetis/trunk/kohana/application/controllers/main.php | ||
---|---|---|
<?php defined('SYSPATH') or die('No direct script access.');
|
||
/**
|
||
* Default Kohana controller.
|
||
*/
|
||
class Main_Controller extends Controller {
|
||
|
||
public function index()
|
||
{
|
||
echo "jsme v mainu<br />
|
||
<br />
|
||
"; echo get_class($this)."<br />
|
||
<br />";
|
||
|
||
require_once('application/vendors/phpgacl/gacl.class.php');
|
||
$gacl = new gacl();
|
||
if ($gacl->acl_check(get_class($this),__FUNCTION__, 'all','mara')) echo "allow";
|
||
else echo "denny";
|
||
/*
|
||
function acl_check($aco_section_value, $aco_value, $aro_section_value, $aro_value, $axo_section_value=NULL, $axo_value=NULL, $root_aro_group=NULL, $root_axo_group=NULL) {
|
||
*/
|
||
echo html::anchor(url_lang::base().'login/logout', url_lang::lang('texts.Logout'));
|
||
}
|
||
|
||
}
|
freenetis/trunk/kohana/application/controllers/examples.php | ||
---|---|---|
<?php defined('SYSPATH') or die('No direct script access.');
|
||
/**
|
||
* Contains examples of various Kohana library examples. You can access these
|
||
* samples in your own installation of Kohana by going to ROOT_URL/examples.
|
||
*
|
||
* $Id: examples.php 1911 2008-02-04 16:13:16Z PugFish $
|
||
*
|
||
* @package Core
|
||
* @author Kohana Team
|
||
* @copyright (c) 2007-2008 Kohana Team
|
||
* @license http://kohanaphp.com/license.html
|
||
*/
|
||
class Examples_Controller extends Controller {
|
||
|
||
/**
|
||
* Displays a list of available examples
|
||
*/
|
||
function index()
|
||
{
|
||
// Get the methods that are only in this class and not the parent class.
|
||
$examples = array_diff
|
||
(
|
||
get_class_methods(__CLASS__),
|
||
get_class_methods(get_parent_class($this))
|
||
);
|
||
|
||
echo "<strong>Examples:</strong>\n";
|
||
echo "<ul>\n";
|
||
|
||
foreach($examples as $method)
|
||
{
|
||
if ($method == __FUNCTION__)
|
||
continue;
|
||
|
||
echo '<li>'.html::anchor('examples/'.$method, $method)."</li>\n";
|
||
}
|
||
|
||
echo "</ul>\n";
|
||
echo '<p>'.Kohana::lang('core.stats_footer')."</p>\n";
|
||
}
|
||
|
||
public function archive($build = FALSE)
|
||
{
|
||
if ($build === 'build')
|
||
{
|
||
// Load archive
|
||
$archive = new Archive('zip');
|
||
|
||
// Add welcome.php with the name of test.php
|
||
$archive->add(APPPATH.'controllers/welcome.php', 'test.php');
|
||
|
||
// Download the built archive
|
||
$archive->download('test.zip');
|
||
}
|
||
else
|
||
{
|
||
echo html::anchor(Router::$current_uri.'/build', 'Download welcome.php as test.php');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Demonstrates how to use views inside of views.
|
||
*/
|
||
function template()
|
||
{
|
||
$data = array
|
||
(
|
||
'title' => 'View-in-View Example',
|
||
'content' => 'This is my view-in-view page content.',
|
||
'copyright' => '© 2007 Kohana Team'
|
||
);
|
||
|
||
$view = $this->load->view('viewinview/container', $data);
|
||
$view->header = $this->load->view('viewinview/header', $data);
|
||
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Demonstrates how to parse RSS feeds by using DOMDocument.
|
||
*/
|
||
function rss()
|
||
{
|
||
// Parse an external atom feed
|
||
$feed = feed::parse('http://codeigniter.com/feeds/atom/news/');
|
||
|
||
// Show debug info
|
||
echo Kohana::debug($feed);
|
||
|
||
echo Kohana::lang('core.stats_footer');
|
||
}
|
||
|
||
/**
|
||
* Demonstrates the Session library and using session data.
|
||
*/
|
||
function session()
|
||
{
|
||
$this->load->database();
|
||
$s = new Session();
|
||
|
||
echo 'SESSID: <pre>'.session_id()."</pre>\n";
|
||
|
||
echo '<pre>'.print_r($_SESSION, TRUE)."</pre>\n";
|
||
|
||
echo '<br/>{execution_time} seconds';
|
||
}
|
||
|
||
/**
|
||
* Demonstrates how to use the form helper with the Validation library.
|
||
*/
|
||
function form()
|
||
{
|
||
$this->load->library('validation');
|
||
|
||
echo form::open('', array('enctype' => 'multipart/form-data'));
|
||
|
||
echo form::label('imageup', 'Image Uploads').':<br/>';
|
||
echo form::upload('imageup[]').'<br/>';
|
||
echo form::upload('imageup[]').'<br/>';
|
||
echo form::upload('imageup[]').'<br/>';
|
||
echo form::submit('upload', 'Upload!');
|
||
|
||
echo form::close();
|
||
|
||
if ( ! empty($_POST))
|
||
{
|
||
$this->validation->set_rules('imageup', 'required|upload[gif,png,jpg,500K]', 'Image Upload');
|
||
echo '<p>validation result: '.var_export($this->validation->run(), TRUE).'</p>';
|
||
}
|
||
|
||
echo Kohana::debug($this->validation);
|
||
echo Kohana::lang('core.stats_footer');
|
||
}
|
||
|
||
/**
|
||
* Demontrates how to use the Validation library to validate an arbitrary array.
|
||
*/
|
||
function validation()
|
||
{
|
||
// To demonstrate Validation being able to validate any array, I will
|
||
// be using a pre-built array. When you load validation with no arguments
|
||
// it will default to validating the POST array.
|
||
$data = array
|
||
(
|
||
'user' => 'hello',
|
||
'pass' => 'bigsecret',
|
||
'reme' => '1'
|
||
);
|
||
|
||
// Same as CI, but supports passing an array to the constructor
|
||
$this->load->library('validation', $data);
|
||
|
||
// Looks familiar...
|
||
$this->validation->set_rules(array
|
||
(
|
||
// Format:
|
||
// key friendly name, validation rules
|
||
'user' => array('username', '=trim|required[1,12]|regex[/[0-9]+/]'),
|
||
'pass' => array('password', 'required|=sha1'),
|
||
'reme' => array('remember me', 'required')
|
||
));
|
||
|
||
// Same syntax as before
|
||
$this->validation->run();
|
||
|
||
// Same syntax, but dynamcially generated wth __get()
|
||
echo $this->validation->error_string;
|
||
|
||
// Yay!
|
||
echo '{execution_time} ALL DONE!';
|
||
}
|
||
|
||
/**
|
||
* Demonstrates the features of the Database library.
|
||
*
|
||
* Table Structure:
|
||
* CREATE TABLE `pages` (
|
||
* `id` mediumint( 9 ) NOT NULL AUTO_INCREMENT ,
|
||
* `page_name` varchar( 100 ) NOT NULL ,
|
||
* `title` varchar( 255 ) NOT NULL ,
|
||
* `content` longtext NOT NULL ,
|
||
* `menu` tinyint( 1 ) NOT NULL default '0',
|
||
* `filename` varchar( 255 ) NOT NULL ,
|
||
* `order` mediumint( 9 ) NOT NULL ,
|
||
* `date` int( 11 ) NOT NULL ,
|
||
* `child_of` mediumint( 9 ) NOT NULL default '0',
|
||
* PRIMARY KEY ( `id` ) ,
|
||
* UNIQUE KEY `filename` ( `filename` )
|
||
* ) ENGINE = MYISAM DEFAULT CHARSET = utf8 PACK_KEYS =0;
|
||
*
|
||
*/
|
||
function database()
|
||
{
|
||
$this->load->database();
|
||
$table = 'pages';
|
||
echo 'Does the '.$table.' table exist? ';
|
||
if ($this->db->table_exists($table))
|
||
{
|
||
echo '<p>YES! Lets do some work =)</p>';
|
||
|
||
$query = $this->db->select('DISTINCT pages.*')->from($table)->get();
|
||
echo $this->db->last_query();
|
||
echo '<h3>Iterate through the result:</h3>';
|
||
foreach($query as $item)
|
||
{
|
||
echo '<p>'.$item->title.'</p>';
|
||
}
|
||
echo '<h3>Numrows using count(): '.count($query).'</h3>';
|
||
echo 'Table Listing:<pre>'.print_r($this->db->list_tables(), TRUE).'</pre>';
|
||
|
||
echo '<h3>Try Query Binding with objects:</h3>';
|
||
$sql = 'SELECT * FROM '.$table.' WHERE id = ?';
|
||
$query = $this->db->query($sql, array(1));
|
||
echo '<p>'.$this->db->last_query().'</p>';
|
||
$query->result(TRUE);
|
||
foreach($query as $item)
|
||
{
|
||
echo '<pre>'.print_r($item, true).'</pre>';
|
||
}
|
||
|
||
echo '<h3>Try Query Binding with arrays (returns both associative and numeric because I pass MYSQL_BOTH to result():</h3>';
|
||
$sql = 'SELECT * FROM '.$table.' WHERE id = ?';
|
||
$query = $this->db->query($sql, array(1));
|
||
echo '<p>'.$this->db->last_query().'</p>';
|
||
$query->result(FALSE, MYSQL_BOTH);
|
||
foreach($query as $item)
|
||
{
|
||
echo '<pre>'.print_r($item, true).'</pre>';
|
||
}
|
||
|
||
echo '<h3>Look, we can also manually advance the result pointer!</h3>';
|
||
$query = $this->db->select('title')->from($table)->get();
|
||
echo 'First:<pre>'.print_r($query->current(), true).'</pre><br />';
|
||
$query->next();
|
||
echo 'Second:<pre>'.print_r($query->current(), true).'</pre><br />';
|
||
$query->next();
|
||
echo 'Third:<pre>'.print_r($query->current(), true).'</pre>';
|
||
echo '<h3>And we can reset it to the beginning:</h3>';
|
||
$query->rewind();
|
||
echo 'Rewound:<pre>'.print_r($query->current(), true).'</pre>';
|
||
|
||
echo '<p>Number of rows using count_records(): '.$this->db->count_records('pages').'</p>';
|
||
}
|
||
else
|
||
{
|
||
echo 'NO! The '.$table.' table doesn\'t exist, so we can\'t continue =( ';
|
||
}
|
||
echo "<br/><br/>\n";
|
||
echo 'done in {execution_time} seconds';
|
||
}
|
||
|
||
/**
|
||
* Demonstrates how to use the Pagination library and Pagination styles.
|
||
*/
|
||
function pagination()
|
||
{
|
||
$this->pagination = new Pagination(array(
|
||
// 'base_url' => 'welcome/pagination_example/page/', // base_url will default to current uri
|
||
'uri_segment' => 'page', // pass a string as uri_segment to trigger former 'label' functionality
|
||
'total_items' => 254, // use db count query here of course
|
||
'items_per_page' => 10, // it may be handy to set defaults for stuff like this in config/pagination.php
|
||
'style' => 'classic' // pick one from: classic (default), digg, extended, punbb, or add your own!
|
||
));
|
||
|
||
// Just echoing it is enough to display the links (__toString() rocks!)
|
||
echo 'Classic style: '.$this->pagination;
|
||
|
||
// You can also use the create_links() method and pick a style on the fly if you want
|
||
echo '<hr />Digg style: '.$this->pagination->create_links('digg');
|
||
echo '<hr />Extended style: '.$this->pagination->create_links('extended');
|
||
echo '<hr />PunBB style: '.$this->pagination->create_links('punbb');
|
||
echo 'done in {execution_time} seconds';
|
||
}
|
||
|
||
/**
|
||
* Demonstrates the User_Agent library.
|
||
*/
|
||
function user_agent()
|
||
{
|
||
$this->load->library('user_agent');
|
||
|
||
foreach(array('agent', 'browser', 'version') as $key)
|
||
{
|
||
echo $key.': '.$this->user_agent->$key.'<br/>'."\n";
|
||
}
|
||
|
||
echo "<br/><br/>\n";
|
||
echo 'done in {execution_time} seconds';
|
||
}
|
||
|
||
/**
|
||
* Demonstrates the Payment library.
|
||
*/
|
||
/*function payment()
|
||
{
|
||
$credit_card = new Payment();
|
||
|
||
// You can also pass the driver name to the library to use multiple ones:
|
||
$credit_card = new Payment('Paypal');
|
||
$credit_card = new Payment('Authorize');
|
||
|
||
// You can specify one parameter at a time:
|
||
$credit_card->login = 'this';
|
||
$credit_card->first_name = 'Jeremy';
|
||
$credit_card->last_name = 'Bush';
|
||
$credit_card->card_num = '1234567890';
|
||
$credit_card->exp_date = '0910';
|
||
$credit_card->amount = '478.41';
|
||
|
||
// Or you can also set fields with an array and the <Payment.set_fields> method:
|
||
$credit_card->set_fields(array('login' => 'test',
|
||
'first_name' => 'Jeremy',
|
||
'last_name' => 'Bush',
|
||
'card_num' => '1234567890',
|
||
'exp_date' => '0910',
|
||
'amount' => '487.41'));
|
||
|
||
echo '<pre>'.print_r($credit_card, true).'</pre>';
|
||
|
||
echo 'Success? ';
|
||
echo ($response = $credit_card->process() == TRUE) ? 'YES!' : $response;
|
||
}*/
|
||
|
||
function calendar()
|
||
{
|
||
$profiler = new Profiler;
|
||
|
||
$cal = new Calendar(5, 2007);
|
||
|
||
echo $cal->render();
|
||
}
|
||
|
||
function image()
|
||
{
|
||
$profiler = new Profiler;
|
||
|
||
$dir = str_replace('\\', '/', realpath(dirname(__FILE__).'/../upload')).'/';
|
||
|
||
$image = new Image($dir.'moo.jpg');
|
||
|
||
$image->resize(400, NULL)->crop(400, 350, 'top')->sharpen(20);
|
||
|
||
$image->save($dir.'super-cow-crop.jpg');
|
||
|
||
echo Kohana::debug($image);
|
||
}
|
||
|
||
} // End Examples
|
freenetis/trunk/kohana/application/controllers/kodoc.php | ||
---|---|---|
<?php defined('SYSPATH') or die('No direct script access.');
|
||
|
||
class Kodoc_Controller extends Template_Controller {
|
||
|
||
protected $template = 'kodoc/template';
|
||
|
||
// Kodoc instance
|
||
protected $kodoc;
|
||
|
||
public function __construct()
|
||
{
|
||
parent::__construct();
|
||
|
||
$active = $this->uri->segment(2) ? $this->uri->segment(2) : 'core';
|
||
|
||
// Add the menu to the template
|
||
$this->template->menu = new View('kodoc/menu', array('active' => $active));
|
||
}
|
||
|
||
public function index()
|
||
{
|
||
$this->template->content = 'hi';
|
||
}
|
||
|
||
public function media()
|
||
{
|
||
if (isset($this->profiler)) $this->profiler->disable();
|
||
|
||
// Get the filename
|
||
$file = implode('/', $this->uri->segment_array(1));
|
||
$ext = strrchr($file, '.');
|
||
|
||
if ($ext !== FALSE)
|
||
{
|
||
$file = substr($file, 0, -strlen($ext));
|
||
$ext = substr($ext, 1);
|
||
}
|
||
|
||
// Disable auto-rendering
|
||
$this->auto_render = FALSE;
|
||
|
||
try
|
||
{
|
||
// Attempt to display the output
|
||
echo new View('kodoc/'.$file, NULL, $ext);
|
||
}
|
||
catch (Kohana_Exception $e)
|
||
{
|
||
Event::run('system.404');
|
||
}
|
||
}
|
||
|
||
public function _default()
|
||
{
|
||
if (count($segments = $this->uri->segment_array(1)) > 1)
|
||
{
|
||
// Find directory (type) and filename
|
||
$type = array_shift($segments);
|
||
$file = implode('/', $segments);
|
||
|
||
if (substr($file, -(strlen(EXT))) === EXT)
|
||
{
|
||
// Remove extension
|
||
$file = substr($file, 0, -(strlen(EXT)));
|
||
}
|
||
|
||
if ($type === 'config')
|
||
{
|
||
if ($file === 'config')
|
||
{
|
||
// This file can only exist in one location
|
||
$file = APPPATH.$type.'/config'.EXT;
|
||
}
|
||
else
|
||
{
|
||
foreach(array_reverse(Config::include_paths()) as $path)
|
||
{
|
||
if (is_file($path.$type.'/'.$file.EXT))
|
||
{
|
||
// Found the file
|
||
$file = $path.$type.'/'.$file.EXT;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// Get absolute path to file
|
||
$file = Kohana::find_file($type, $file);
|
||
}
|
||
|
||
if (in_array($type, Kodoc::get_types()))
|
||
{
|
||
// Load Kodoc
|
||
$this->kodoc = new Kodoc($type, $file);
|
||
|
||
// Set the title
|
||
$this->template->title = implode('/', $this->uri->segment_array(1));
|
||
|
||
// Load documentation for this file
|
||
$this->template->content = new View('kodoc/documentation');
|
||
|
||
// Exit this method
|
||
return;
|
||
}
|
||
}
|
||
|
||
// Nothing to document
|
||
url::redirect('kodoc');
|
||
}
|
||
|
||
} // End Kodoc Controller
|
freenetis/trunk/kohana/application/controllers/invoices.php | ||
---|---|---|
url::redirect(url_lang::base().'invoices/show_all');
|
||
}
|
||
|
||
/**
|
||
* @author Michal Kliment
|
||
* Shows all invoices table
|
||
* @param $limit_results
|
||
* @param $order_by
|
||
* @param $order_by_direction
|
||
* @param $page_word
|
||
* @param $page
|
||
*/
|
||
function show_all($limit_results = 200, $order_by = 'id', $order_by_direction = 'ASC', $page_word = null, $page = 1)
|
||
{
|
||
|
||
// access rights
|
||
if (!$this->acl_check_view('Accounts_Controller','invoices'))
|
||
Controller::Error(1);
|
||
|
||
// gets new selector
|
||
if (is_numeric($this->input->get('record_per_page')))
|
||
$limit_results = (int) $this->input->get('record_per_page');
|
||
... | ... | |
'limit_results' => $limit_results
|
||
));
|
||
|
||
$grid->add_new_button(url_lang::base().'invoices/add', url_lang::lang('texts.Add new invoice'));
|
||
$grid->add_new_button(url_lang::base().'invoices/import', url_lang::lang('texts.Import new invoice'));
|
||
// access control
|
||
if ($this->acl_check_new('Accounts_Controller','invoices'))
|
||
{
|
||
$grid->add_new_button(url_lang::base().'invoices/add', url_lang::lang('texts.Add new invoice'));
|
||
$grid->add_new_button(url_lang::base().'invoices/import', url_lang::lang('texts.Import new invoice'));
|
||
}
|
||
|
||
$grid->order_field('id')->label(url_lang::lang('texts.Id'));
|
||
$grid->order_field('supplier')->label(url_lang::lang('texts.Supplier'));
|
||
... | ... | |
//$grid->order_field('order_nr')->label(url_lang::lang('texts.Order number'));
|
||
//$grid->order_field('currency')->label(url_lang::lang('texts.Currency'));
|
||
|
||
$grid->action_field('id') ->label(url_lang::lang('texts.Show'))->url(url_lang::base().'invoices/show')->action(url_lang::lang('texts.Show'));
|
||
$grid->action_field('id') ->label(url_lang::lang('texts.Edit'))->url(url_lang::base().'invoices/edit')->action(url_lang::lang('texts.Edit'));
|
||
$grid->action_field('id') ->label(url_lang::lang('texts.Delete'))->url(url_lang::base().'invoices/delete')->action(url_lang::lang('texts.Delete'));
|
||
// access control
|
||
if ($this->acl_check_view('Accounts_Controller','invoices'))
|
||
$grid->action_field('id') ->label(url_lang::lang('texts.Show'))->url(url_lang::base().'invoices/show')->action(url_lang::lang('texts.Show'));
|
||
|
||
// access control
|
||
if ($this->acl_check_edit('Accounts_Controller','invoices'))
|
||
$grid->action_field('id') ->label(url_lang::lang('texts.Edit'))->url(url_lang::base().'invoices/edit')->action(url_lang::lang('texts.Edit'));
|
||
|
||
// access control
|
||
if ($this->acl_check_delete('Accounts_Controller','invoices'))
|
||
$grid->action_field('id') ->label(url_lang::lang('texts.Delete'))->url(url_lang::base().'invoices/delete')->action(url_lang::lang('texts.Delete'));
|
||
|
||
$grid->datasource($invoices);
|
||
|
||
$view = new View('template');
|
||
... | ... | |
$view->render(TRUE);
|
||
}
|
||
|
||
|
||
/**
|
||
* @author Michal Kliment
|
||
* Parses data from invoice in XML, HTML,etc. and stores it in session
|
||
*/
|
||
function import()
|
||
{
|
||
// access rights
|
||
if (!$this->acl_check_new('Accounts_Controller','invoices'))
|
||
Controller::Error(1);
|
||
|
||
|
||
// types of supported formats
|
||
$types = array('ed' => url_lang::lang('texts.ED invoice in XML'));
|
||
|
||
// if form is posted
|
||
|
||
if ($_FILES)
|
||
{
|
||
$form = new Validation($_FILES);
|
||
... | ... | |
|
||
}
|
||
|
||
/**
|
||
* @author Michal Kliment
|
||
* Adds new invoice
|
||
*/
|
||
function add()
|
||
{
|
||
// access rights
|
||
if (!$this->acl_check_new('Accounts_Controller','invoices'))
|
||
Controller::Error(1);
|
||
|
||
// setting up of default values
|
||
|
||
$supplier_id = 0;
|
||
$invoice_nr = 0;
|
||
... | ... | |
|
||
$invoice = $this->session->get('ssInvoice');
|
||
|
||
// if data from import are stored in session
|
||
|
||
if ($invoice)
|
||
{
|
||
$supplier_id = $invoice->supplier_id;
|
||
... | ... | |
$members = $member_model->find_all();
|
||
|
||
$arr_members = arr::from_objects($members);
|
||
|
||
|
||
// creates form
|
||
|
||
$this->form = new Forge(url_lang::base().'invoices/add', '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
... | ... | |
$this->form->submit('submit')->value(url_lang::lang('texts.Add'));
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
|
||
//if form is validated
|
||
if ($this->form->validate())
|
||
{
|
||
$form_data = $this->form->as_array();
|
||
|
||
// creates new Invoice
|
||
$invoice = new Invoice_Model();
|
||
|
||
$invoice->supplier_id = $form_data['supplier_id'];
|
||
... | ... | |
$invoice->order_nr = $form_data['order_nr'];
|
||
$invoice->currency = htmlspecialchars($form_data['currency']);
|
||
|
||
// succes
|
||
if ($invoice->save())
|
||
{
|
||
$this->session->set_flash('message', url_lang::lang('texts.Invoice has been successfully added.'));
|
||
... | ... | |
$view->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Edits invoice
|
||
* @param $invoice_id id of invoice to edit
|
||
*/
|
||
function edit($invoice_id = NULL)
|
||
{
|
||
|
||
// access rights
|
||
if (!$this->acl_check_edit('Accounts_Controller','invoices'))
|
||
Controller::Error(1);
|
||
|
||
$invoice = new Invoice_Model($invoice_id);
|
||
|
||
if (!$invoice_id || !$invoice->id) url::redirect(url_lang::base().'invoices/show_all');
|
||
... | ... | |
|
||
$arr_members = arr::from_objects($members);
|
||
|
||
// creates form
|
||
$this->form = new Forge(url_lang::base().'invoices/edit/'.$invoice->id, '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
... | ... | |
$this->form->submit('submit')->value(url_lang::lang('texts.Edit'));
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
|
||
// if form is validated
|
||
if ($this->form->validate())
|
||
{
|
||
$form_data = $this->form->as_array();
|
||
... | ... | |
$invoice->order_nr = $form_data['order_nr'];
|
||
$invoice->currency = htmlspecialchars($form_data['currency']);
|
||
|
||
// success
|
||
if ($invoice->save())
|
||
{
|
||
$this->session->set_flash('message', url_lang::lang('texts.Invoice has been successfully updated.'));
|
||
... | ... | |
$view->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Deletes invoice
|
||
* @param $invoice_id id of invoice to delete
|
||
*/
|
||
function delete ($invoice_id = NULL)
|
||
{
|
||
// access rights
|
||
if (!$this->acl_check_delete('Accounts_Controller','invoices'))
|
||
Controller::Error(1);
|
||
$invoice = new Invoice_Model($invoice_id);
|
||
|
||
if (!$invoice_id || !$invoice->id) url::redirect(url_lang::base().'invoices');
|
||
|
||
// success
|
||
if ($invoice->delete())
|
||
{
|
||
$this->session->set_flash('message', url_lang::lang('texts.Invoice has been successfully deleted.'));
|
freenetis/trunk/kohana/application/upgrade_sql/upgrade_sql.php | ||
---|---|---|
|
||
|
||
$upgrade_sql[get_SVN_rev()] = array(
|
||
"CREATE TABLE IF NOT EXISTS `invoices` (
|
||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||
`supplier_id` int(11) NOT NULL,
|
||
`invoice_nr` double NOT NULL,
|
||
`var_sym` double NOT NULL,
|
||
`con_sym` double NOT NULL,
|
||
`date_inv` date NOT NULL,
|
||
`date_due` date NOT NULL,
|
||
`date_vat` date NOT NULL,
|
||
`vat` tinyint(1) NOT NULL,
|
||
`order_nr` double NOT NULL,
|
||
`currency` varchar(3) COLLATE utf8_czech_ci NOT NULL,
|
||
PRIMARY KEY (`id`)
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;"
|
||
"UPDATE `axo` SET `name` = 'Faktury' WHERE `axo`.`id` =55 LIMIT 1;",
|
||
"INSERT INTO `axo_map` (`acl_id`, `section_value`, `value`) VALUES (38, 'Accounts_Controller', 'invoices');"
|
||
);
|
||
|
||
?>
|
freenetis/trunk/kohana/application/upgrade_sql/upgrade_sql_298.php | ||
---|---|---|
<?php
|
||
|
||
$upgrade_sql[298] = array(
|
||
"CREATE TABLE IF NOT EXISTS `invoices` (
|
||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||
`supplier_id` int(11) NOT NULL,
|
||
`invoice_nr` double NOT NULL,
|
||
`var_sym` double NOT NULL,
|
||
`con_sym` double NOT NULL,
|
||
`date_inv` date NOT NULL,
|
||
`date_due` date NOT NULL,
|
||
`date_vat` date NOT NULL,
|
||
`vat` tinyint(1) NOT NULL,
|
||
`order_nr` double NOT NULL,
|
||
`currency` varchar(3) COLLATE utf8_czech_ci NOT NULL,
|
||
PRIMARY KEY (`id`)
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;"
|
||
);
|
||
|
||
?>
|
freenetis/trunk/kohana/application/libraries/Parser_ED_Invoice.php | ||
---|---|---|
<?php
|
||
|
||
/**
|
||
* @author Michal Kliment
|
||
* @version 1.0
|
||
*
|
||
* This is one from parsers of some kinds of invoice.
|
||
* Parser loads data from XML file and store it in object.
|
||
*/
|
||
class Parser_ED_Invoice {
|
||
|
||
/**
|
||
* Basic data obtained from XML file
|
||
* @var SimpleXML object
|
||
*/
|
||
private $data = NULL;
|
||
|
||
/**
|
||
* Object of final data
|
||
* @var StdClass object
|
||
*/
|
||
private $values = NULL;
|
||
|
||
private function open($filename)
|
||
{
|
||
|
||
}
|
||
|
||
/**
|
||
* Private method to set up id of supplier
|
||
* @param $id if of member to set up as supplier
|
||
*/
|
||
public function set_supplier_id ($id = NULL)
|
||
{
|
||
$this->supplier_id = $id;
|
||
}
|
||
|
||
/**
|
||
* Private method to open XML file and load data in SImpleXML object
|
||
* @param $file file to parse
|
||
* @return true if data was successfully loaded, false if not
|
||
*/
|
||
private function load_data_from_xml_file($file)
|
||
{
|
||
if ($this->data) return true;
|
||
... | ... | |
return true;
|
||
}
|
||
|
||
/**
|
||
* Private method to setting up final values from basic data
|
||
*/
|
||
private function set_values_from_data()
|
||
{
|
||
if (!$this->data) die('Je potreba data!');
|
||
if (!$this->data) die('Need data!');
|
||
$this->values = new StdClass();
|
||
$this->values->supplier_id = $this->supplier_id;
|
||
$this->values->invoice_nr = (double) $this->data->INVOICE->INV_ID;
|
||
... | ... | |
$this->values->items[$i]->price = (double) strtr($item->PRICE,',','.');
|
||
$this->values->items[$i]->price_vat = (double) strtr($item->PRICE_VAT,',','.');
|
||
$i++;
|
||
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* Private method to convert string to datetime
|
||
* @param $string string to convert
|
||
* @return converted datetime
|
||
*/
|
||
private function get_datetime_from_string($string = NULL)
|
||
{
|
||
if (strlen($string)!=10) return NULL;
|
||
... | ... | |
return $year.'-'.$month.'-'.$day;
|
||
}
|
||
|
||
/**
|
||
* Private method to convert string to bool
|
||
* @param $value string, probably 'true' or 'false'
|
||
* @return return boolean true or false (without quotes)
|
||
*/
|
||
private function bool($value = 'false')
|
||
{
|
||
return (strtolower($value)=='true') ? 1 : 0;
|
||
}
|
||
|
||
/**
|
||
* Public method to parse XML file (uses private methods)
|
||
* @param $file file to parse
|
||
*/
|
||
public function parse($file)
|
||
{
|
||
if (!$this->load_data_from_xml_file($file)) die('Spatny format souboru');
|
||
$this->set_values_from_data();
|
||
}
|
||
|
||
/**
|
||
* Public method to get final values
|
||
* @return StdClass object final values
|
||
*/
|
||
public function get_values()
|
||
{
|
||
return $this->values;
|
Také k dispozici: Unified diff
Smazany 3 naprosto nepotrebne kontolery (examples, kodoc a main). Dodelany pristupove prava u faktur. Dopsany komentare...