Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1245

Přidáno uživatelem Ondřej Fibich před asi 13 roky(ů)

Upravy:

- prepracovan export do csv: u clenu moznost exportovat dle filtru, automaticky export z jakekoli tabulky
- limitovany grid u telefonnich faktur
- odkaz na smazani subnetu u jeho zobrazeni

Zobrazit rozdíly:

freenetis/branches/testing/application/helpers/server.php
*/
class server
{
public static function http_user_agent()
{
return $_SERVER['HTTP_USER_AGENT'];
......
}
/**
* Returns query string of current url
* Returns query string of current url with ? if not empty
*
* @author Michal Kliment
* @return string
*/
public static function query_string ()
public static function query_string()
{
return $_SERVER['QUERY_STRING'];
return (empty($_SERVER['QUERY_STRING']) ? '' : '?' . $_SERVER['QUERY_STRING']);
}
}
freenetis/branches/testing/application/models/member.php
/**
* Function gets all members to export.
*
* @author Jiri Svitak
* !!!!!! SECURITY WARNING !!!!!!
* Be careful when you using this method, param $filter_sql is unprotected
* for SQL injections, security should be made at controller site using
* Filter_form class.
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*
* @param string $filter_values
*
* @author Jiri Svitak, Ondřej Fibich
* @return unknown_type
*/
public function get_all_members_to_export()
public function get_all_members_to_export($filter_sql = '')
{
// where condition
if (!empty($filter_sql))
{
$filter_sql = "WHERE $filter_sql";
}
// query
return $this->db->query("
SELECT m.id, m.registration, m.name AS member_name, m.variable_symbol,
SELECT m.id, m.name AS member_name, m.variable_symbol,
s.street, ap.street_number, t.town, t.quarter, u.login AS login_name,
u.birthday, m.entrance_date,
IF(m.leaving_date = '0000-00-00', null, m.leaving_date) AS leaving_date,
IFNULL(f.translated_term, e.value) AS type, m.comment
IFNULL(f.translated_term, e.value) AS type, m.comment,
IF(m.registration = 1, ?, ?) AS registration
FROM members m
JOIN users u ON u.member_id = m.id AND u.type = ?
LEFT JOIN address_points ap ON m.address_point_id = ap.id
LEFT JOIN towns t ON ap.town_id = t.id
LEFT JOIN streets s ON ap.street_id = s.id
LEFT JOIN enum_types e ON m.type = e.id
LEFT JOIN (
SELECT *
FROM translations
WHERE lang = ?
) f ON e.value = f.original_term
", User_Model::$member, Config::get('lang'));
LEFT JOIN translations f ON e.value = f.original_term AND lang = ?
$filter_sql
ORDER BY id
", __('Yes'), __('No'), User_Model::$member, Config::get('lang'));
}
/**
freenetis/branches/testing/application/models/phone_invoice.php
* @property double $tax
* @property double $tax_rate
*/
class Phone_invoice_Model extends ORM {
class Phone_invoice_Model extends ORM
{
protected $has_many = array('phone_invoice_users');
......
}
/**
* Count all phone invoices
*
* @return integer Count
*/
public function count_all_phone_invoices()
{
return $this->db->query("
SELECT COUNT(id) AS count
FROM `phone_invoices`
")->current()->count;
}
/**
* Return al phone invoicces
*
* @param integer $limit_from
* @param integer $limit_results
* @param string $order_by
* @param string $order_by_direction
* @return ORM iterator
*/
public function get_all_phone_invoices()
public function get_all_phone_invoices(
$limit_from = 0, $limit_results = 20,
$order_by = 'billing_period_from',
$order_by_direction = 'desc')
{
// order by direction check
if (strtolower($order_by_direction) != 'desc')
{
$order_by_direction = 'asc';
}
// query
return $this->db->query("
SELECT id, date_of_issuance, billing_period_from,
billing_period_to, variable_symbol, specific_symbol,
(total_price+tax) AS price, locked
FROM `phone_invoices`
FROM phone_invoices
ORDER BY ".$this->db->escape_column($order_by)." $order_by_direction
LIMIT ".intval($limit_from).", ".intval($limit_results)."
");
}
freenetis/branches/testing/application/controllers/phone_invoices.php
/**
* Shows all invoices.
* Enable delete invoice.
*
* @param integer $limit_results
* @param string $order_by
* @param string $order_by_direction
* @param integer $page_word
* @param integer $page
*/
public function show_all()
public function show_all(
$limit_results = 20, $order_by = 'billing_period_from',
$order_by_direction = 'DESC', $page_word = null, $page = 1)
{
if (!$this->acl_check_view('Phone_invoices_Controller', 'invoices'))
{
Controller::error(ACCESS);
}
// gets new selector
if (is_numeric($this->input->get('record_per_page')))
{
$limit_results = (int) $this->input->get('record_per_page');
}
// parameters control
$allowed_order_type = array
(
'id', 'date_of_issuance', 'billing_period_from', 'billing_period_to',
'variable_symbol', 'specific_symbol', 'price', 'locked'
);
if (!in_array(strtolower($order_by), $allowed_order_type))
{
$order_by = 'id';
}
if (strtolower($order_by_direction) != 'desc')
{
$order_by_direction = 'asc';
}
$phone_invoice_model = new Phone_invoice_Model();
$query = $phone_invoice_model->get_all_phone_invoices();
$total_invoices = $phone_invoice_model->count_all();
$grid = new Grid(url::base(TRUE) . url::current(true), null, array
if (($sql_offset = ($page - 1) * $limit_results) > $total_invoices)
{
$sql_offset = 0;
}
$invoices = $phone_invoice_model->get_all_phone_invoices(
$sql_offset, $limit_results,
$order_by, $order_by_direction
);
$grid = new Grid(url_lang::base() . 'phone_invoices/show_all', '', array
(
'use_paginator' => false,
'use_selector' => false
'use_paginator' => true,
'use_selector' => true,
'current' => $limit_results,
'selector_increace' => 200,
'selector_min' => 200,
'selector_max_multiplier' => 10,
'base_url' => Config::get('lang').'/phone_invoices/show_all/'.
$limit_results.'/'.$order_by.'/'.$order_by_direction,
'uri_segment' => 'page',
'total_items' => $total_invoices,
'items_per_page' => $limit_results,
'style' => 'classic',
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results
));
$grid->field('id')
$grid->order_field('id')
->label(__('ID'));
$grid->field('date_of_issuance')
$grid->order_field('date_of_issuance')
->label(__('Date of issue'));
$grid->field('billing_period_from')
->label(__('Billing period from'));
$grid->order_field('billing_period_from');
$grid->field('billing_period_to')
->label(__('Billing period to'));
$grid->order_field('billing_period_to');
$grid->field('variable_symbol')
->label(__('Variable symbol'));
$grid->order_field('variable_symbol');
$grid->field('specific_symbol')
->label(__('Specific symbol'));
$grid->order_field('specific_symbol');
$grid->callback_field('price')
$grid->order_callback_field('price')
->label(__('Price vat'))
->callback('callback::phone_price_field');
......
->url('phone_invoices/delete')
->class('delete_link');
$grid->datasource($query);
$grid->datasource($invoices);
$breadcrumbs = breadcrumbs::add()
->text('Phone invoices');
freenetis/branches/testing/application/controllers/members.php
{
// csv export of members
$grid->add_new_button(
url_lang::base().'export/csv/members',
url_lang::base().'export/csv/members' . server::query_string(),
__('Export to CSV (utf-8)')
);
$grid->add_new_button(
url_lang::base().'export/csv/members/windows-1250',
url_lang::base().'export/csv/members/windows-1250' . server::query_string(),
__('Export to CSV (windows-1250)')
);
}
freenetis/branches/testing/application/controllers/export.php
* Function exports list of items to csv file.
* Rows are separated by newlines and it columns by semicolon.
*
* @author Jiri Svitak
* @param encoding optional parameter;
* by default the result is encoded in utf-8 and encoding can change this
* @author Jiri Svitak, Ondřej Fibich
* @param string $content Content of export
* @param string $encoding By default the result is encoded in utf-8
* and encoding can change this
* @param mixed $id ID of item
*/
public function csv($content = null, $encoding = 'utf-8', $id = null)
{
// each content has specific query
switch ($content)
{
// export for members with filter
case 'members':
if (!$this->acl_check_view('Members_Controller', 'members'))
{
Controller::error(ACCESS);
$member_model = new Member_Model();
$items = $member_model->get_all_members_to_export();
}
$filter_form = new Filter_form('m');
$filter_form->autoload();
$member = new Member_Model();
$items = $member->get_all_members_to_export($filter_form->as_sql());
$filename = __('Members') . '.csv';
break;
// export for items of subnet
case 'subnets':
$subnet_model = new Subnet_Model($id);
if ($subnet_model->id == 0)
{
Controller::error(RECORD);
}
if (!$this->acl_check_view('Devices_Controller', 'subnet'))
{
Controller::error(ACCESS);
}
$items = $subnet_model->get_items_of_subnet($id);
$filename = $subnet_model->name . '.csv';
break;
// auto export for all tables
default:
Controller::warning(PARAMETER, __(
'Bad parameter for export'
));
if (!$this->acl_check_view('Settings_Controller', 'system'))
{
Controller::error(ACCESS);
}
if (empty($content))
{
Controller::warning(PARAMETER, __('Bad parameter for export'));
}
$filename = __(utf8::ucfirst($content)) . '.csv';
try
{
$model = ORM::factory(inflector::singular($content));
$all = $model->find_all();
$items = array();
foreach ($all as $one)
{
$items[] = $one->as_array();
}
}
catch (Exception $e)
{
Controller::warning(PARAMETER, __('Bad parameter for export'));
}
break;
}
/* Generate file */
// set content header
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="' . $filename . '"');
$first = true;
// yes and no for registration
$yes = __('yes');
$no = __('no');
// this foreach goes through rows
foreach ($items as $line)
// empty result?
if (!count($items))
{
// first headers of columns will be written
if ($first)
return;
}
// get headers
foreach ($items[0] as $key => $value)
{
// translation of column titles
$field = __(utf8::ucfirst(inflector::humanize($key)));
// file cannot start with ID, otherwise excel
// and openoffice think that the file is invalid
if ($field == 'ID')
{
foreach ($line as $key => $value)
{
// translation of column titles
$title = __('' . $key);
// file cannot start with ID, otherwise excel
// and openoffice think that the file is invalid
if ($title == 'ID')
$title = __('Number');
// character encoding
if ($encoding != 'utf-8')
$title = iconv('utf-8', $encoding, $title);
echo '"' . $title . '";';
}
echo "\n";
$first = false;
$field = __('Number');
}
// character encoding
if ($encoding != 'utf-8')
{
$field = iconv('utf-8', $encoding, $value);
}
// output
echo '"' . $field . '";';
}
echo "\n";
// for each data row
foreach ($items as $line)
{
// this foreach writes line
foreach ($line as $key => $value)
{
// special case - registration
if ($key == 'registration')
{
// character encoding
if ($encoding != 'utf-8')
{
if ($value == 1)
$value = $yes;
else
$value = $no;
$field = iconv('utf-8', $encoding, $value);
}
// character encoding
if ($encoding != 'utf-8')
$value = iconv('utf-8', $encoding, $value);
// output
echo '"' . $value . '";';
}
echo "\n";
}
}
/**
* Export list of members to xls file. Requires library PEAR.
* Works fine in OpenOffice, but there are problems probably with encoding in MS Excel.
*
* @author Jiri Svitak
*/
public function xls_export()
{
// access rights
if (!$this->acl_check_view(get_class($this), 'members'))
Controller::error(ACCESS);
// set content header
header('Content-type: application/xls');
// requires xls module from library PEAR
//require_once(APPPATH.'vendors/Spreadsheet/Excel/Writer.php');
require_once('Spreadsheet/Excel/Writer.php');
// workbook represents xls file
$workbook = new Spreadsheet_Excel_Writer();
$workbook->setVersion(8);
$workbook->send(__('Members') . '.xls');
// set xls cells format
$format_bold = & $workbook->addFormat();
$format_bold->setBold();
// worksheet represents sheet in xls file
$worksheet = & $workbook->addWorksheet('Clenove');
$worksheet->setInputEncoding("utf-8");
// creates database member model
$member_model = new Member_Model();
$members = $member_model->get_all_members_to_export();
$resultCnt = count($members);
$first = true;
$row = 0;
// yes and no for registration
$yes = __('yes');
$no = __('no');
// goes through rows of data
foreach ($members as $key => $line)
{
// get column count
$colCnt = count($line);
$col = 0;
// header is written only once
if ($first)
{
// foreach goes through columns of header
foreach ($line as $key => $value)
{
$valLen = strlen($value);
// max array stores lenghts of columns in xls sheet
$max[$key] = $valLen;
// writes header values
$worksheet->write(0, $col, __('' . $key), $format_bold);
if ($col >= $colCnt - 1)
$first = false;
// sets max size of cell
if ($row >= $resultCnt - 1)
$worksheet->setColumn($col, $col, $max[$key]);
$col++;
}
$row++;
$colCnt = count($line);
$col = 0;
}
// goes through columns of data and writes them into the sheet
foreach ($line as $key => $value)
{
// special case - registration
if ($key == 'registration')
{
if ($value == 1)
$value = $yes;
else
$value = $no;
}
// determining size of cell
$valLen = strlen($value);
if ($max[$key] < $valLen)
$max[$key] = $valLen;
// writes data
$worksheet->write($row, $col, $value);
// sets max size of cell
if ($row >= $resultCnt)
$worksheet->setColumn($col, $col, $max[$key]);
$col++;
}
$row++;
}
$workbook->close();
} // end of xls_export
}
freenetis/branches/testing/application/libraries/grid/Order_field.php
if (server::query_string() != '')
{
$this->return_link .= '?' . server::query_string();
$this->return_link .= server::query_string();
}
}
freenetis/branches/testing/application/views/main.php
<?php echo html::script('media/js/jquery.timer', FALSE) ?>
<?php echo html::script('media/js/messages_cs', FALSE) ?>
<?php echo html::script('media/js/php.min', FALSE) ?>
<script type="text/javascript" src="<?php echo url_lang::base() .'js/' . url_lang::current() . (empty($_SERVER['QUERY_STRING']) ? '' : '?' . $_SERVER['QUERY_STRING']) ?>"></script>
<script type="text/javascript" src="<?php echo url_lang::base() .'js/' . url_lang::current() . server::query_string() ?>"></script>
<?php if (!$this->popup && TextEditor::$instance_counter): ?>
<?php echo html::script('media/js/tinymce/tiny_mce', FALSE) ?>
<script type="text/javascript"><!--
freenetis/branches/testing/application/views/subnets_show.php
if ($this->acl_check_edit('Devices_Controller', 'subnet'))
{
$links[] = html::anchor(url_lang::base() . 'subnets/edit/' . $subnet->id, __('Edit'));
$links[] = html::anchor('subnets/edit/' . $subnet->id, __('Edit'));
}
if ($this->acl_check_delete('Devices_Controller', 'subnet'))
{
$links[] = html::anchor('subnets/delete/' . $subnet->id, __('Delete'));
}
if ($this->acl_check_edit('Devices_Controller', 'redirect'))
{
$links[] = html::anchor(url_lang::base() . 'notifications/subnet/' . $subnet->id, __('Notifications'));
$links[] = html::anchor('notifications/subnet/' . $subnet->id, __('Notifications'));
}
if ($this->acl_check_view('Devices_Controller', 'subnet'))
{
$links[] = html::anchor(url_lang::base() . 'export/csv/subnets/utf-8/' . $subnet->id, __('Export to CSV (utf-8)'));
$links[] = html::anchor(url_lang::base() . 'export/csv/subnets/windows-1250/' . $subnet->id, __('Export to CSV (windows-1250)'));
$links[] = html::anchor('export/csv/subnets/utf-8/' . $subnet->id, __('Export to CSV (utf-8)'));
$links[] = html::anchor('export/csv/subnets/windows-1250/' . $subnet->id, __('Export to CSV (windows-1250)'));
}
echo implode(' | ', $links);
......
<?php if ($owner_id): ?>
<tr>
<th><?php echo __('Owner') ?> <?php echo help::hint('subnet_owner') ?></th>
<td><?php echo html::anchor(url_lang::base() . 'members/show/' . $owner_id, $owner) ?></td>
<td><?php echo html::anchor('members/show/' . $owner_id, $owner) ?></td>
</tr>
<?php endif ?>
<tr>
......
$clouds_links = array();
foreach ($clouds as $cloud)
{
$clouds_links[] = html::anchor(url_lang::base() . 'clouds/show/' . $cloud->id, $cloud->name);
$clouds_links[] = html::anchor('clouds/show/' . $cloud->id, $cloud->name);
}
echo implode(', ', $clouds_links);
?>

Také k dispozici: Unified diff