Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2139

Přidáno uživatelem David Raška před asi 11 roky(ů)

Upravy:
- dokumentace AXO: controllery E

Zobrazit rozdíly:

freenetis/branches/1.1/application/vendors/axo_doc/axo_doc.xml
<axo usage_type="breadcrumbs" section="Devices_Controller" value="devices" action="edit" own="true"></axo>
</method>
</object>
<object name="email" type="controller">
<object name="email" type="controller"
comment-en="E-mail - allows sending e-mail"
comment-cs="E-mail - umožňuje odesílání mailů">
<method name="__construct"></method>
<method name="index"></method>
<method name="send"></method>
<method name="send_email_to_developers"></method>
<method name="show">
<!-- show($email_id = null)
{
// access
if (!$this->acl_check_view('Email_queues_Controller', 'email_queue'))
{
Controller::error(ACCESS);
}
if (!isset($email_id))
{
Controller::warning(PARAMETER);
}
$email = new Email_queue_Model($email_id);
if (!$email || !$email->id)
{
Controller::error(RECORD);
}
$email_info = $email->from . ' &rarr; ' . $email->to . ' (' . $email->access_time . ')';
$breadcrumbs = breadcrumbs::add()
->link('email_queues', 'E-mails')
->disable_translation()
->text($email_info);
$view = new View('main');
$view->title = __('Show e-mail message');
$view->content = new View('email/show');
$view->breadcrumbs = $breadcrumbs->html();
$view->content->headline = __('e-mail message');
$view->content->email = $email;
$view->render(true);
}
/**
* Callback for state of SMS message
*
* @param object $item
* @param string $name
*/
protected static -->
<axo usage_type="unknown" section="Email_queues_Controller" value="email_queue" action="view" own="false"></axo>
<axo usage_type="accesss" section="Email_queues_Controller" value="email_queue" action="view" own="false"></axo>
</method>
</object>
<object name="email_queues" type="controller">
<object name="email_queues" type="controller"
comments-en="E-mail queues - administrate sended and unsended e-mail"
comments-cs="Fronta e-mailů - spravuje odeslané a neodeslané e-maily">
<method name="__construct"></method>
<method name="index"></method>
<method name="show_all_unsent">
<!-- show_all_unsent(
$limit_results = 50, $order_by = 'access_time',
$order_by_direction = 'DESC', $page_word = null, $page = 1)
{
// access check
if (!$this->acl_check_view('Email_queues_Controller', 'email_queue'))
Controller::error(ACCESS);
// filter form
$filter_form = new Filter_form();
$filter_form->add('from_user_name')
->label(__('User From'))
->callback('json/user_fullname');
$filter_form->add('from')
->label(__('E-mail From'))
->callback('json/user_email');
$filter_form->add('to_user_name')
->label(__('User To'))
->callback('json/user_fullname');
$filter_form->add('to')
->label(__('E-mail To'))
->callback('json/user_email');
$filter_form->add('subject');
$filter_form->add('access_time')
->type('date')
->label(__('Time'));
// gets new selector
if (is_numeric($this->input->post('record_per_page')))
$limit_results = (int) $this->input->post('record_per_page');
// parameters control
$allowed_order_type = array
(
'id', 'from', 'to', 'subject', 'access_time'
);
// order by check
if (!in_array(strtolower($order_by), $allowed_order_type))
$order_by = 'access_time';
// order by direction check
if (strtolower($order_by_direction) != 'asc')
$order_by_direction = 'desc';
$email_queue_model = new Email_queue_Model();
// counts all unsent e-mail
$total_emails = $email_queue_model->count_all_unsent_emails($filter_form->as_sql());
// limit check
if (($sql_offset = ($page - 1) * $limit_results) > $total_emails)
$sql_offset = 0;
$emails = $email_queue_model->get_all_unsent_emails(
$sql_offset, (int)$limit_results, $order_by, $order_by_direction,
$filter_form->as_sql()
);
// headline
$headline = __('List of all unsent e-mails');
// path to form
$path = Config::get('lang') . '/email_queues/show_all_unsent/' . $limit_results . '/'
. $order_by . '/' . $order_by_direction;
$grid = new Grid('email_queues', null, array
(
'current' => $limit_results,
'selector_increace' => 50,
'selector_min' => 50,
'selector_max_multiplier' => 20,
'base_url' => $path,
'uri_segment' => 'page',
'total_items' => $total_emails,
'items_per_page' => $limit_results,
'style' => 'classic',
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results,
'filter' => $filter_form
));
$grid->add_new_button(
'email_queues/show_all_sent', __('Show all sent e-mails')
);
if ($this->acl_check_delete('Email_queues_Controller', 'email_queue'))
{
$grid->add_new_button(
'email_queues/delete_unsent', __('Delete all unsended e-mails')
);
}
// database columns
$grid->order_field('id')
->label('ID');
$grid->order_callback_field('from')
->callback('callback::email_from_field');
$grid->order_callback_field('to')
->label('To')
->callback('callback::email_to_field');
$grid->order_callback_field('subject')
->callback('callback::email_subject_field');
$grid->order_callback_field('state')
->callback('callback::email_state_field');
$grid->order_field('access_time')
->label(__('Time'));
$actions = $grid->grouped_action_field();
$actions->add_action()
->icon_action('show')
->url('email/show');
if ($this->acl_check_new('Email_queues_Controller', 'email_queue'))
{
$actions->add_action()
->icon_action('mail_send')
->label('Send again')
->url('email_queues/send');
}
if ($this->acl_check_delete('Email_queues_Controller', 'email_queue'))
{
$actions->add_action()
->icon_action('delete')
->url('email_queues/delete')
->class('delete_link');
}
// load data
$grid->datasource($emails);
$view = new View('main');
$view->breadcrumbs = __('Unsent e-mails');
$view->title = $headline;
$view->content = new View('show_all');
$view->content->headline = $headline;
$view->content->table = $grid;
$view->render(TRUE);
}
/**
* Function to show all sent e-mails
*
* @author Michal Kliment
* @param integer $limit_results
* @param string $order_by
* @param string $order_by_direction
* @param string $page_word
* @param integer $page
*/
public -->
<axo usage_type="unknown" section="Email_queues_Controller" value="email_queue" action="view" own="false"></axo>
<axo usage_type="unknown" section="Email_queues_Controller" value="email_queue" action="delete" own="false"></axo>
<axo usage_type="unknown" section="Email_queues_Controller" value="email_queue" action="new" own="false"></axo>
<axo usage_type="unknown" section="Email_queues_Controller" value="email_queue" action="delete" own="false"></axo>
<axo usage_type="access" section="Email_queues_Controller" value="email_queue" action="view" own="false"></axo>
<axo usage_type="links" section="Email_queues_Controller" value="email_queue" action="delete" own="false"></axo>
<axo usage_type="grid-action" section="Email_queues_Controller" value="email_queue" action="new" own="false"></axo>
<axo usage_type="grid-action" section="Email_queues_Controller" value="email_queue" action="delete" own="false"></axo>
</method>
<method name="show_all_sent">
<!-- show_all_sent(
$limit_results = 50, $order_by = 'access_time',
$order_by_direction = 'DESC', $page_word = null, $page = 1)
{
// access check
if (!$this->acl_check_view('Email_queues_Controller', 'email_queue'))
Controller::error(ACCESS);
// filter form
$filter_form = new Filter_form();
$filter_form->add('from_user_name')
->label('User From')
->callback('json/user_fullname');
$filter_form->add('from')
->label('E-mail From')
->callback('json/user_email');
$filter_form->add('to_user_name')
->label('User To')
->callback('json/user_fullname');
$filter_form->add('to')
->label('E-mail To')
->callback('json/user_email');
$filter_form->add('subject');
$filter_form->add('access_time')
->type('date')
->label('Time');
// gets new selector
if (is_numeric($this->input->post('record_per_page')))
$limit_results = (int) $this->input->post('record_per_page');
// parameters control
$allowed_order_type = array
(
'id', 'from', 'to', 'subject', 'access_time'
);
// order by check
if (!in_array(strtolower($order_by), $allowed_order_type))
$order_by = 'access_time';
// order by direction check
if (strtolower($order_by_direction) != 'asc')
$order_by_direction = 'desc';
$email_queue_model = new Email_queue_Model();
// hide grid on its first load (#442)
$hide_grid = Settings::get('grid_hide_on_first_load') && $filter_form->is_first_load();
if (!$hide_grid)
{
try
{
// counts all sent e-mail
$total_emails = $email_queue_model->count_all_sent_emails($filter_form->as_sql());
// limit check
if (($sql_offset = ($page - 1) * $limit_results) > $total_emails)
$sql_offset = 0;
$emails = $email_queue_model->get_all_sent_emails(
$sql_offset, (int)$limit_results, $order_by, $order_by_direction,
$filter_form->as_sql()
);
}
catch (Exception $e)
{
if ($filter_form->is_loaded_from_saved_query())
{
status::error('Invalid saved query');
// disable default query (loop protection)
if ($filter_form->is_loaded_from_default_saved_query())
{
ORM::factory('filter_query')->remove_default($filter_form->get_base_url());
}
$this->redirect(url_lang::current());
}
throw $e;
}
}
// headline
$headline = __('List of all sent e-mails');
// path to form
$path = Config::get('lang') . '/email_queues/show_all_sent/' . $limit_results . '/'
. $order_by . '/' . $order_by_direction;
$grid = new Grid('email_queues', null, array
(
'current' => $limit_results,
'selector_increace' => 50,
'selector_min' => 50,
'selector_max_multiplier' => 20,
'base_url' => $path,
'uri_segment' => 'page',
'total_items' => isset($total_emails) ? $total_emails : 0,
'items_per_page' => $limit_results,
'style' => 'classic',
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results,
'filter' => $filter_form
));
$grid->add_new_button(
'email_queues/show_all_unsent', __('Show all unsent e-mails')
);
if (!$hide_grid && $this->acl_check_delete('Email_queues_Controller', 'email_queue'))
{
$grid->add_new_button(
'email_queues/delete_sent' . server::query_string(),
__('Delete all filtered e-mails'), array
(
'id' => 'delete_sent_link',
'ref' => $total_emails
)
);
}
$grid->add_new_button(
'export/csv/email_queue_sent' . server::query_string(),
'Export to CSV', array
(
'title' => __('Export to CSV'),
'class' => 'popup_link'
)
);
// database columns
$grid->order_field('id')
->label('ID');
$grid->order_callback_field('from')
->callback('callback::email_from_field');
$grid->order_callback_field('to')
->callback('callback::email_to_field');
$grid->order_callback_field('subject')
->callback('callback::email_subject_field');
$grid->order_field('access_time')
->label('Time');
$actions = $grid->grouped_action_field();
$actions->add_action()
->icon_action('show')
->url('email/show');
if ($this->acl_check_new('Email_queues_Controller', 'email_queue'))
{
$actions->add_action()
->icon_action('mail_send')
->label('Send again')
->url('email_queues/send');
}
if (!$hide_grid)
{
// load data
$grid->datasource($emails);
}
$view = new View('main');
$view->breadcrumbs = __('Sent e-mails');
$view->title = $headline;
$view->content = new View('show_all');
$view->content->headline = $headline;
$view->content->table = $grid;
$view->render(TRUE);
}
/**
* Tries to send message from queue
*
* @author Michal Kliment
* @param integer $email_queue_id
*/
public -->
<axo usage_type="unknown" section="Email_queues_Controller" value="email_queue" action="view" own="false"></axo>
<axo usage_type="unknown" section="Email_queues_Controller" value="email_queue" action="delete" own="false"></axo>
<axo usage_type="unknown" section="Email_queues_Controller" value="email_queue" action="new" own="false"></axo>
<axo usage_type="access" section="Email_queues_Controller" value="email_queue" action="view" own="false"></axo>
<axo usage_type="links" section="Email_queues_Controller" value="email_queue" action="delete" own="false"></axo>
<axo usage_type="grid-action" section="Email_queues_Controller" value="email_queue" action="new" own="false"></axo>
</method>
<method name="send">
<!-- send($email_queue_id = NULL)
{
// access check
if (!$this->acl_check_new('Email_queues_Controller', 'email_queue'))
Controller::error(ACCESS);
// bad parameter
if (!$email_queue_id || !is_numeric($email_queue_id))
Controller::warning(PARAMETER);
$email_queue = new Email_queue_Model($email_queue_id);
// record doens't exist
if (!$email_queue->id)
Controller::error(RECORD);
$swift = email::connect();
// Build recipient lists
$recipients = new Swift_RecipientList;
$recipients->addTo($email_queue->to);
// Build the HTML message
$message = new Swift_Message($email_queue->subject, $email_queue->body, "text/html");
// Send
$state = (
Config::get('unit_tester') ||
$swift->send($message, $recipients, $email_queue->from)
);
if ($state)
$email_queue->state = Email_queue_Model::STATE_OK;
else
$email_queue->state = Email_queue_Model::STATE_FAIL;
$email_queue->access_time = date('Y-m-d H:i:s');
$email_queue->save();
$swift->disconnect();
if ($state)
{
status::success('E-mail has been successfully sent');
url::redirect('email_queues/show_all_sent');
}
else
{
status::error('Error - e-mail has not been successfully sent');
url::redirect('email_queues/show_all_unsent');
}
}
/**
* Deletes message from queue
*
* @author Michal Kliment
* @param integer $email_queue_id
*/
public -->
<axo usage_type="unknown" section="Email_queues_Controller" value="email_queue" action="new" own="false"></axo>
<axo usage_type="access" section="Email_queues_Controller" value="email_queue" action="new" own="false"></axo>
</method>
<method name="delete">
<!-- delete($email_queue_id = NULL)
{
// access check
if (!$this->acl_check_delete('Email_queues_Controller', 'email_queue'))
Controller::error(ACCESS);
// bad parameter
if (!$email_queue_id || !is_numeric($email_queue_id))
Controller::warning(PARAMETER);
$email_queue = new Email_queue_Model($email_queue_id);
// record doens't exist
if (!$email_queue->id)
Controller::error(RECORD);
if ($email_queue->state != Email_queue_Model::STATE_OK)
{
$email_queue->delete();
status::success('Message has been successfully deleted');
}
else
status::error('Error - it is not possible delete already sent message');
url::redirect('email_queues/show_all_unsent');
}
/**
* Deletes all unsended emails
*
* @author Ondřej Fibich
*/
public -->
<axo usage_type="unknown" section="Email_queues_Controller" value="email_queue" action="delete" own="false"></axo>
<axo usage_type="access" section="Email_queues_Controller" value="email_queue" action="delete" own="false"></axo>
</method>
<method name="delete_unsent">
<!-- delete_unsent()
{
// access
if (!$this->acl_check_delete('Email_queues_Controller', 'email_queue'))
{
Controller::error(ACCESS);
}
// model
$eq_model = new Email_queue_Model();
// count first
$count = $eq_model->where(array
(
'state' => Email_queue_Model::STATE_NEW
))->count_all();
// delete all
$eq_model->where(array
(
'state' => Email_queue_Model::STATE_NEW
))->delete_all();
// send notification
status::success('%d unsended e-mails has been deleted.', TRUE, $count);
// redirects
url::redirect('email_queues/show_all_unsent');
}
/**
* Deletes filtered sent emails
*
* @author Ondřej Fibich
*/
public -->
<axo usage_type="unknown" section="Email_queues_Controller" value="email_queue" action="delete" own="false"></axo>
<axo usage_type="access" section="Email_queues_Controller" value="email_queue" action="delete" own="false"></axo>
</method>
<method name="delete_sent">
<!-- delete_sent()
{
// access
if (!$this->acl_check_delete('Email_queues_Controller', 'email_queue'))
{
Controller::error(ACCESS);
}
// filter load
$f = new Filter_form();
$f->autoload();
$fsql = $f->as_sql();
// model
$eq_model = new Email_queue_Model();
// count first
$count = $eq_model->count_all_sent_emails($fsql);
// delete all
if ($eq_model->count_all() == $count)
{
$eq_model->truncate();
}
// delete filtered
else
{
$eq_model->delete_sent_emails($fsql);
}
// send notification
status::success('%d sended e-mails has been deleted.', TRUE, $count);
// redirects
url::redirect('email_queues/show_all_sent');
}
}
-->
<axo usage_type="unknown" section="Email_queues_Controller" value="email_queue" action="delete" own="false"></axo>
<axo usage_type="access" section="Email_queues_Controller" value="email_queue" action="delete" own="false"></axo>
</method>
</object>
<object name="enum_types" type="controller">
<object name="enum_types" type="controller"
comment-en="Enumeration types - user types of antennas, devices, contacts etc."
comment-cs="Výčtové typy - uživatelské typy antén, zařízení, kontaktů atd.>
<method name="index"></method>
<method name="show_all">
<!-- show_all(
$limit_results = 200, $order_by = 'id', $order_by_direction = 'ASC')
{
// check if logged user have access right to view all translations
if (!$this->acl_check_view('Enum_types_Controller', 'enum_types'))
Controller::Error(ACCESS);
// to-do - pagination
// get new selector
if (is_numeric($this->input->post('record_per_page')))
$limit_results = (int) $this->input->post('record_per_page');
$allowed_order_type = array('id', 'type', 'value');
if (!in_array(strtolower($order_by), $allowed_order_type))
$order_by = 'id';
if (strtolower($order_by_direction) != 'desc')
$order_by_direction = 'asc';
$enum_type_model = new Enum_type_Model();
$enum_types = $enum_type_model->get_all($order_by, $order_by_direction);
$total_enum_types = count($enum_types);
$headline = __('Enumerations');
// create grid
$grid = new Grid('enum_types', $headline, array
(
'use_paginator' => true,
'use_selector' => true,
'current' => $limit_results,
'selector_increace' => 200,
'selector_min' => 200,
'selector_max_multiplier' => 10,
'base_url' => Config::get('lang') . '/translations/show_all/'
. $limit_results . '/' . $order_by . '/' . $order_by_direction,
'uri_segment' => 'page',
'total_items' => $total_enum_types,
'items_per_page' => $limit_results,
'style' => 'classic',
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results
));
// add button for new translation
// check if logged user have access right to add new translation
if ($this->acl_check_new('Enum_types_Controller', 'enum_types'))
{
$grid->add_new_button('enum_types/add', __('Add new enum type'));
}
// set grid fields
$grid->order_field('id');
$grid->order_field('type');
$grid->order_field('value');
$actions = $grid->grouped_action_field();
// check if logged user have access right to edit this enum types
if ($this->acl_check_edit('Enum_types_Controller', 'enum_types'))
{
$actions->add_conditional_action()
->condition('is_not_readonly')
->icon_action('edit')
->url('enum_types/edit');
}
// check if logged user have access right to delete this enum_types
if ($this->acl_check_delete('Enum_types_Controller', 'enum_types'))
{
$actions->add_conditional_action()
->condition('is_not_readonly')
->icon_action('delete')
->url('enum_types/delete')
->class('delete_link');
}
$grid->datasource($enum_types);
// create view for this template
$view = new View('main');
$view->title = $headline;
$view->breadcrumbs = $headline;
$view->content = new View('show_all');
$view->content->table = $grid;
$view->content->headline = '';
$view->render(TRUE);
}
/**
* Adds new enum type
*
* @author Michal Kliment
*/
public -->
<axo usage_type="unknown" section="Enum_types_Controller" value="enum_types" action="view" own="false"></axo>
<axo usage_type="unknown" section="Enum_types_Controller" value="enum_types" action="new" own="false"></axo>
<axo usage_type="unknown" section="Enum_types_Controller" value="enum_types" action="edit" own="false"></axo>
<axo usage_type="unknown" section="Enum_types_Controller" value="enum_types" action="delete" own="false"></axo>
<axo usage_type="access" section="Enum_types_Controller" value="enum_types" action="view" own="false"></axo>
<axo usage_type="links" section="Enum_types_Controller" value="enum_types" action="new" own="false"></axo>
<axo usage_type="grid-action" section="Enum_types_Controller" value="enum_types" action="edit" own="false"></axo>
<axo usage_type="grid-action" section="Enum_types_Controller" value="enum_types" action="delete" own="false"></axo>
</method>
<method name="add">
<!-- add()
{
// access control
if (!$this->acl_check_new('Enum_types_Controller', 'enum_types'))
Controller::error(ACCESS);
$arr_type_names = array
(
NULL => '- ' . __('select type') . ' -'
) + ORM::factory('enum_type_name')->select_list('id', 'type_name');
// form for new enum type
$form = new Forge('enum_types/add');
$form->dropdown('type_name_id')
->label('Type')
->options($arr_type_names)
->rules('required')
->style('width:200px');
$form->input('value')
->rules('required|length[3,254]');
$form->submit('Add');
// test validity of input, if it is validate it will continue in show_all
if ($form->validate())
{
$form_data = $form->as_array();
// assigns new enum type to model
$enum_type = new Enum_type_Model();
$enum_type->type_id = $form_data['type_name_id'];
$enum_type->value = $form_data['value'];
$enum_type->read_only = 0;
// clears form content
unset($form_data);
// has translation been successfully saved?
if ($enum_type->save())
{
status::success('Enum type has been successfully added');
url::redirect('enum_types/show_all');
}
else
{
status::success('Error - can\'t add new enum type.');
}
}
else
{
// breadcrumbs
$breadcrumbs = breadcrumbs::add()
->link('enum_types/show_all', 'Enumerations',
$this->acl_check_view('Enum_types_Controller', 'enum_types'))
->text('Add new enum type');
// view for adding translation
$view = new View('main');
$view->title = __('Add new enum type');
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('form');
$view->content->headline = __('Add new enum type');
$view->content->form = $form->html();
$view->render(TRUE);
}
}
/**
* Edits enum type
*
* @author Michal Kliment
* @param integer $enum_type_id
*/
public -->
<axo usage_type="unknown" section="Enum_types_Controller" value="enum_types" action="new" own="false"></axo>
<axo usage_type="unknown" section="Enum_types_Controller" value="enum_types" action="view" own="false"></axo>
<axo usage_type="access" section="Enum_types_Controller" value="enum_types" action="new" own="false"></axo>
<axo usage_type="breadcrumbs" section="Enum_types_Controller" value="enum_types" action="view" own="false"></axo>
</method>
<method name="edit">
<!-- edit($enum_type_id = NULL)
{
if ($enum_type_id)
{
// access control
if (!$this->acl_check_edit('Enum_types_Controller', 'enum_types'))
Controller::error(ACCESS);
$enum_type = new Enum_type_Model($enum_type_id);
if (!$enum_type->id || $enum_type->read_only)
url::redirect('enum_types/show_all');
$arr_type_names = ORM::factory('enum_type_name')->select_list('id', 'type_name');
// form for new enum type
$form = new Forge('enum_types/edit/' . $enum_type->id);
$form->dropdown('type_name_id')
->label('Type')
->options($arr_type_names)
->rules('required')
->selected($enum_type->type_id)
->style('width:200px');
$form->input('value')
->rules('required|length[3,254]')
->value($enum_type->value);
$form->submit('Edit');
// test validity of input, if it is validate it will continue in show_all
if ($form->validate())
{
$form_data = $form->as_array();
// assigns new enum type to model
$enum_type = new Enum_type_Model($enum_type_id);
$enum_type->type_id = $form_data['type_name_id'];
$enum_type->value = $form_data['value'];
$enum_type->read_only = 0;
// clears form content
unset($form_data);
// has translation been successfully saved?
if ($enum_type->save())
{
status::success('Enum type has been successfully updated');
url::redirect('enum_types/show_all');
}
else
{
status::error('Error - can\'t edit enum type.');
}
}
else
{
// breadcrumbs
$breadcrumbs = breadcrumbs::add()
->link('enum_types/show_all', 'Enumerations',
$this->acl_check_view('Enum_types_Controller', 'enum_types'))
->text($enum_type->value . ' (' . $enum_type_id . ')')
->text('Edit translation');
// view
$view = new View('main');
$view->title = __('Edit translation');
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('form');
$view->content->headline = __('Edit translation');
$view->content->form = $form->html();
$view->render(TRUE);
}
}
else
{
Controller::warning(PARAMETER);
}
}
/**
* Deletes enum type
*
* @author Michal Kliment
* @param integer $enum_type_id
*/
public -->
<axo usage_type="unknown" section="Enum_types_Controller" value="enum_types" action="edit" own="false"></axo>
<axo usage_type="unknown" section="Enum_types_Controller" value="enum_types" action="view" own="false"></axo>
<axo usage_type="access" section="Enum_types_Controller" value="enum_types" action="edit" own="false"></axo>
<axo usage_type="breadcrumbs" section="Enum_types_Controller" value="enum_types" action="view" own="false"></axo>
</method>
<method name="delete">
<!-- delete($enum_type_id = NULL)
{
if ($enum_type_id)
{
// access control
if (!$this->acl_check_delete('Enum_types_Controller', 'enum_types'))
Controller::error(ACCESS);
$enum_type = new Enum_type_Model($enum_type_id);
if (!$enum_type->id || $enum_type->read_only)
url::redirect('enum_types/show_all');
// success
if ($enum_type->delete())
{
status::success('Enum type has been successfully deleted');
url::redirect('enum_types/show_all');
}
}
else
{
Controller::warning(PARAMETER);
}
}
}
-->
<axo usage_type="unknown" section="Enum_types_Controller" value="enum_types" action="delete" own="false"></axo>
<axo usage_type="access" section="Enum_types_Controller" value="enum_types" action="delete" own="false"></axo>
</method>
</object>
<object name="errors" type="controller">
<object name="errors" type="controller"
comment-en="Displays error page"
comment-cs="Zobrazuje chybovou stránku">
<method name="e404"></method>
</object>
<object name="export" type="controller">
<object name="export" type="controller"
comment-en="Exports data from FreenetIS to file"
comment-cs="Exportuje data z FreenetISu do souboru">
<method name="csv">
<!-- csv($content = null, $encoding = null, $id = null)
{
$encodings = array
(
'utf-8' => 'UTF-8',
'windows-1250' => 'WINDOWS-1250'
);
// display form only if required
$form_display = !isset($encodings[$encoding]);
if ($form_display)
{
$form = new Forge();
$form->set_attr('class', 'form nopopup');
$form->dropdown('encoding')
->options($encodings)
->selected($encoding);
$form->submit('Submit');
}
// form is validate
if (!$form_display || $form->validate())
{
if ($form_display)
{
$form_data = $form->as_array();
$encoding = $form_data['encoding'];
}
// 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);
}
$filter_form = new Filter_form('m');
$filter_form->autoload();
$member = new Member_Model();
try
{
$items = $member->get_all_members_to_export($filter_form->as_sql());
}
catch (Exception $e)
{
$items = array();
}
$filename = __('Members') . '.csv';
break;
// export emails
case 'email_queue_sent':
if (!$this->acl_check_view('Email_queues_Controller', 'email_queue'))
{
Controller::error(ACCESS);
}
$filter_form = new Filter_form();
$filter_form->autoload();
$email_queue = new Email_queue_Model();
try
{
$items = $email_queue->get_all_sent_emails_for_export($filter_form->as_sql());
}
catch (Exception $e)
{
$items = array();
}
$filename = __('E-mails') . '.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('Subnets_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:
if (!$this->acl_check_view('Export_Controller', 'all_tables'))
{
Controller::error(ACCESS);
}
if (empty($content))
{
Controller::warning(PARAMETER, __('Bad parameter for export'));
}
$filename = __(utf8::ucfirst($content)) . '.csv';
$content = inflector::singular($content);
if (!Kohana::auto_load($content . '_Model'))
{
Controller::warning(PARAMETER, __('Bad parameter for export'));
}
try
{
$model = ORM::factory($content);
$all = $model->find_all();
$items = array();
// header
$items[0] = array_keys($model->list_fields());
foreach ($all as $one)
{
$items[] = $one->as_array();
}
unset($all);
}
catch (Exception $e)
{
Controller::warning(PARAMETER, __('Bad parameter for export'));
}
break;
}
// empty result?
if (!count($items))
{
status::error('Invalid data - no data available');
}
else
{
/* Generate file */
// set content header
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="' . $filename . '"');
$is_utf = $encoding == 'utf-8';
// 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')
{
$field = __('Number');
}
// character encoding
if (!$is_utf)
{
$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)
{
// character encoding
if (!$is_utf)
{
$field = iconv('utf-8', $encoding, $value);
}
// emails body
if ($content == 'email_queue_sent' && $key == 'message')
{
$value = str_replace('"', '\'', strip_tags($value));
}
// output
echo '"';
echo $value;
echo '";';
}
echo "\n";
}
// do not display view
die();
}
}
$title = __('Export');
$view = new View('main');
$view->title = $title;
$view->content = new View('form');
$view->content->headline = $title;
$view->content->form = $form;
$view->render(TRUE);
}
/**
* Function exports contacts to vCard file
*
* @author David Raška
*/
public -->
<axo usage_type="unknown" section="Members_Controller" value="members" action="view" own="false"></axo>
<axo usage_type="unknown" section="Email_queues_Controller" value="email_queue" action="view" own="false"></axo>
<axo usage_type="unknown" section="Subnets_Controller" value="subnet" action="view" own="false"></axo>
<axo usage_type="unknown" section="Export_Controller" value="all_tables" action="view" own="false"></axo>
<axo usage_type="access" section="Members_Controller" value="members" action="view" own="false"></axo>
<axo usage_type="access" section="Email_queues_Controller" value="email_queue" action="view" own="false"></axo>
<axo usage_type="access" section="Subnets_Controller" value="subnet" action="view" own="false"></axo>
<axo usage_type="access" section="Export_Controller" value="all_tables" action="view" own="false"></axo>
</method>
<method name="vcard">
<!-- vcard($export = NULL)
{
if (!$this->acl_check_view('Members_Controller', 'members'))
{
Controller::error(ACCESS);
}
$form = new Forge();
$form->set_attr('class', 'form nopopup');
$form->dropdown('format')
->options( array
(
'vcard21' => 'vCard 2.1',
'vcard40' => 'vCard 4.0',
))
->selected('vcard40');
if ($export != 'users')
{
$form->checkbox('main_only')
->label('Export only main users')
->checked(TRUE);
}
$form->hidden('export')
->value($export);
$form->submit('Submit');
if ($form->validate())
{
$form_data = $form->as_array();
$to_export = $form_data['export'];
$main_only = isset($form_data['main_only']) && $form_data['main_only'] == '1';
$filter_form = new Filter_form();
$filter_form->autoload();
$user_model = new User_Model();
$items = array();
try
{
if ($to_export === 'users')
{
// export all users
$count = $user_model->count_all_users($filter_form->as_sql());
$items = $user_model->get_all_users(
0, $count, 'id', 'ASC', $filter_form->as_sql()
);
}
else if ($to_export === 'members')
{
// export main users
$member_model = new Member_Model();
$count = $member_model->count_all_members($filter_form->as_sql());
$members = $member_model->get_all_members(
0, $count, 'id', 'ASC', $filter_form->as_sql()
);
$member_ids = array();
foreach ($members as $m)
{
$member_ids[] = $m->id;
}
if (!empty($member_ids))
{
$count = $user_model->count_all_users_of_members($member_ids);
$items = $user_model->get_all_users_of_members($member_ids, 0, $count);
}
}
else if (is_numeric($export))
{
// export members users
$count = $user_model->count_all_users_by_member($export);
$items = $user_model->get_all_users_of_member($export, 0, $count);
}
}
catch (Exception $e)
{
$items = array();
die;
}
// empty result?
if (!count($items))
{
status::error('Invalid data - no data available');
}
else
{
/* Generate file */
// set content header
header('Content-type: text/vcard; charset=utf-8');
header('Content-Disposition: attachment; filename="'.__('Contacts').'.vcf"');
switch ($form_data['format'])
{
case 'vcard21':
echo self::vcard21($items, $main_only);
break;
case 'vcard40':
default:
echo self::vcard40($items, $main_only);
}
// do not display view
die();
}
}
$title = __('Export contacts');
$view = new View('main');
$view->title = $title;
$view->content = new View('form');
$view->content->headline = $title;
$view->content->form = $form;
$view->render(TRUE);
}
/**
* Function Generates vCard in 4.0 format
*
* @param array $users Array of all users
* @param bool $main_only Export only main users
*/
private -->
<axo usage_type="unknown" section="Members_Controller" value="members" action="view" own="false"></axo>
<axo usage_type="access" section="Members_Controller" value="members" action="view" own="false"></axo>
</method>
<method name="logo"></method>
<method name="isdoc_invoices">
<!-- isdoc_invoices($invoice_id = null)
{
// access rights
if (!$this->acl_check_view('Accounts_Controller', 'invoices'))
Controller::Error(ACCESS);
$invoice = new Invoice_Model($invoice_id);
if (!$invoice_id || !$invoice->id)
url::redirect('invoices/show_all');
//cant export invoice with no items
if ($invoice->invoice_items->count() == 0) {
status::error('Error - cannot export invoice with no items');
url::redirect('invoices/show/' . $invoice_id);
}
//create an array of constants
$const = array(
'version' => '1.0',
'encoding' => 'utf-8',
'namespace' => 'http://isdoc.cz/namespace/invoice',
'isdoc_version' => '5.3.1',
'vat_method' => 0,
'guid' => guid::getGUID()
);
//get association and partner models
$association = new Member_Model(1);
$partner = $invoice->member_id ? new Member_Model($invoice->member_id) : null;
if ($invoice->invoice_type == Invoice_Model::TYPE_ISSUED) {
$supplier = $association;
$customer = $partner;
} else {
$customer = $association;
$supplier = $partner;
}
//set header
header('Content-type: "text/xml"; charset="utf8"');
header('Content-disposition: attachment; filename=inv_isdoc_'
. $invoice->invoice_nr . '.isdoc');
$view = new View('export/export_isdoc');
$view->const = $const;
$view->invoice = $invoice;
$view->supplier = $supplier;
$view->customer = $customer;
$view->render(TRUE);
}
/**
* Function exports list of invoices to XML
*
* @author Jan Dubina
* @param integer $invoice_template_id id of template of invoice to export
* @param integer $invoice_id id of invoice to export
*/
public -->
<axo usage_type="unknown" section="Accounts_Controller" value="invoices" action="view" own="false"></axo>
<axo usage_type="access" section="Accounts_Controller" value="invoices" action="view" own="false"></axo>
</method>
<method name="xml_invoices">
<!-- xml_invoices($invoice_template_id = null, $invoice_id = null)
{
//access rights
if (!$this->acl_check_view('Accounts_Controller', 'invoices'))
{
Controller::error(ACCESS);
}
$invoice_template = new Invoice_template_Model($invoice_template_id);
if(!$invoice_template_id || !$invoice_template->id)
url::redirect ('invoices/show_all/');
//export one invoice or filtered selection
if(!empty($invoice_id))
$filter = 'iv.id = ' . $invoice_id;
else
{
$filter_form = new Filter_form('iv');
$filter_form->autoload();
$filter = $filter_form->as_sql();
}
$invoice_model = new Invoice_Model();
try
{
$invoices = $invoice_model->get_all_invoices_export($filter);
}
catch (Exception $e)
{
$invoices = array();
}
//no invoices selected
if ($invoices->count() == 0) {
status::error('Invalid data - no data available');
url::redirect('invoices/show_all/');
}
//cant export invoice with no items
foreach ($invoices as $invoice)
if ($invoice->comments_count == 0) {
status::error('Error - cannot export invoice with no items');
url::redirect('invoices/show/' . $invoice->id);
}
//organization identifier must be set
$association = new Member_Model(Member_Model::ASSOCIATION);
if (!$association->organization_identifier) {
status::error('Error - organization identifier must be set');
url::redirect('invoices/show_all/');
}
//create an array of constants
$const = array(
'version' => '1.0',
'encoding' => 'utf-8',
'id' => 'inv_' . date("Y-m-d_H-i-s"),
'org_id' => $association->organization_identifier,
'application' => Settings::get('title'),
'currency' => Settings::get('currency'),
'invoice_ver' => '2.0',
'data_ns' => 'http://www.stormware.cz/schema/version_2/data.xsd',
'invoice_ns' => 'http://www.stormware.cz/schema/version_2/invoice.xsd',
'type_ns' => 'http://www.stormware.cz/schema/version_2/type.xsd'
);
$vat_var = json_decode($invoice_template->vat_variables, true);
//set header
header('Content-type: "text/xml"; charset="utf8"');
header('Content-disposition: attachment; filename=inv_xml_'
. $const['id'] . '.xml');
$view = new View('export/export_xml');
$view->const = $const;
$view->invoices = $invoices;
$view->vat_var = $vat_var;
$view->render(TRUE);
}
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff