Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1298

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

Create branche for ticket system

Zobrazit rozdíly:

freenetis/branches/ticket_system/application/controllers/redirect.php
<?php
/**
* Handles redirection of members for certain reasons.
* @author Jiri Svitak
*
*/
class Redirect_Controller extends Controller
{
function __construct()
{
parent::__construct();
/*if (!is_writable('static'))
{
Controller::error(WRITABLE, url_lang::lang('texts.Directory "static" is not writable, change access rights.'));
}*/
}
/**
* Shows all active redirections.
* @author Jiri Svitak
* @param $limit_results
* @param $order_by
* @param $order_by_direction
* @param $page_word
* @param $page
* @return unknown_type
*/
function show_all($limit_results = 500, $order_by = 'ip_address', $order_by_direction = 'desc', $page_word = null, $page = 1)
{
// access rights
if (!$this->acl_check_view('Redirection_Controller', 'redirection'))
Controller::error(ACCESS);
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
$allowed_order_type = array('ip_address', 'name', 'datetime');
if (!in_array(strtolower($order_by), $allowed_order_type))
$order_by = 'id';
if (strtolower($order_by_direction) != 'asc' && strtolower($order_by_direction) != 'desc')
$order_by_direction = 'desc';
// model
$message_model = new Message_Model();
$total_redirections = $message_model->count_all_redirections();
if (($sql_offset = ($page - 1) * $limit_results) > $total_redirections)
$sql_offset = 0;
$redirections = $message_model->get_all_redirections($sql_offset, (int)$limit_results, $order_by, $order_by_direction);
$headline = url_lang::lang('texts.Active redirections');
$grid = new Grid(url_lang::base().'redirect', null, array(
//'separator' => '<br />-----------',
//'use_paginator' => false,
//'use_selector' => false,
'current' => $limit_results, // current selected 'records_per_page' value
'selector_increace' => 500, // increace
'selector_min' => 500, // minimum where selector start
'selector_max_multiplier' => 10,
'base_url' => Config::get('lang').'/redirect/show_all/'.$limit_results.'/'.$order_by.'/'.$order_by_direction ,
'uri_segment' => 'page', // pass a string as uri_segment to trigger former 'label' functionality
'total_items' => $total_redirections, // use db count query here of course
'items_per_page' => $limit_results, // it may be handy to set defaults for stuff like this in config/pagination.php
'style' => 'classic',
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results,
'url_array_ofset' => 1,
));
$grid->add_new_button(url_lang::base().'messages/show_all', url_lang::lang('texts.Messages for redirection'));
$grid->add_new_button(url_lang::base().'redirect/show_all', url_lang::lang('texts.Active Redirections'));
$grid->add_new_button(url_lang::base().'redirect/settings', url_lang::lang('texts.Settings'));
$grid->order_callback_field('ip_address')->label(url_lang::lang('texts.IP address'))->callback('callback::ip_address_field');
$grid->order_field('name')->label(url_lang::lang('texts.Redirection'));
$grid->order_field('datetime')->label(url_lang::lang('texts.Date and time'));
/*
if ($this->acl_check_view('Accounts_Controller', 'bank_transfers'))
$grid->action_field('id') ->label(url_lang::lang('texts.Bank transfers'))->url(url_lang::base().'bank_transfers/show_by_bank_statement')->action(url_lang::lang('texts.Show'));
*/
$grid->datasource($redirections);
$view = new View('main');
$view->title = $headline;
$view->content = new View('show_all');
$view->content->headline = $headline;
$view->content->message = $this->session->get_once('message');
$view->content->table = $grid;
$view->render(TRUE);
}
/**
* Shows redirection settings and enables their editing.
* @author Jiri Svitak
* @return unknown_type
*/
function settings()
{
// access control
if (!$this->acl_check_edit('Settings_Controller', 'system'))
Controller::error(ACCESS);
// creating links
$arr_links = array();
$arr_links[] = html::anchor(url_lang::base().'messages/show_all', url_lang::lang('texts.Messages for redirection'));
$arr_links[] = html::anchor(url_lang::base().'redirect/show_all', url_lang::lang('texts.Active Redirections'));
$arr_links[] = html::anchor(url_lang::base().'redirect/settings', url_lang::lang('texts.Settings'));
$links = implode(' | ', $arr_links);
// creating of new forge
$this->form = new Forge(url_lang::base()."redirect/settings", '', 'POST', array('id' => 'article_form'));
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
$this->form->group('')->label(url_lang::lang('texts.Gateway'));
$this->form->input('gateway')->label(url_lang::lang('texts.Gateway IP address').":")->value($this->settings->get('gateway'));
$this->form->input('payment_notice_boundary')->label(url_lang::lang('texts.Payment notice boundary')." (".$this->settings->get('currency')."):")->value($this->settings->get('payment_notice_boundary'));
$this->form->input('debtor_boundary')->label(url_lang::lang('texts.Debtor boundary')." (".$this->settings->get('currency')."):")->value($this->settings->get('debtor_boundary'));
$this->form->submit('submit')->value(url_lang::lang('texts.Save'));
special::required_forge_style($this->form, ' *', 'required');
// form validate
if ($this->form->validate())
{
$form_data = $this->form->as_array();
$config_model = new Config_Model();
$issaved = true;
foreach ($form_data as $name => $value)
{
$value = addslashes($value);
// check if variable exists
if ($config_model->check_exist_variable($name))
// update of variable
$issaved = $issaved && $config_model->update_variable($name,$value);
else
// insert new variable
$issaved = $issaved && $config_model->insert_variable($name,$value);
}
if ($issaved)
// if all action were succesfull
$this->session->set_flash('message', url_lang::lang('texts.Redirection settings have been successfully updated.'));
else
// if not
$this->session->set_flash('message', url_lang::lang('texts.Redirection settings have not been updated.'));
url::redirect(url_lang::base().'redirect/settings');
}
// create view for this template
$view = new View('main');
$view->title = url_lang::lang('texts.Settings').' - '.url_lang::lang('texts.Gateway');
$view->content = new View('form');
$view->content->form = $this->form->html();
$view->content->headline = url_lang::lang('texts.Redirection settings');
$view->content->link_back = $links;
$message = $this->session->get_once('message');
if (!empty($message))
$view->content->message = $message;
$view->render(TRUE);
}
/**
* Adds IP address (or including IP addreses of member, or including IP addresses in subnet)
* to junction table for redirection.
* @param $ip_address_id
* @return unknown_type
*/
function add($ip_address_id = null)
{
// access rights
if (!$this->acl_check_edit('Messages_Controller', 'ip_address'))
Controller::error(ACCESS);
if (!isset($ip_address_id))
Controller::warning(PARAMETER);
// ip address
$ip = new Ip_address_Model($ip_address_id);
if ($ip->id == 0)
Controller::error(RECORD);
// load list of usable redirection message
$message_model = new Message_Model();
$messages = $message_model->find_all();
foreach($messages as $message)
{
// whitelisted IP addresses can be redirected only by redirections which ignore whitelist
if ($ip->whitelisted && !$message->ignore_whitelist)
continue;
// IP address can be manually redirected only to user message, interrupted membership message, debtor message, payment notice message
if ($message->type == Message_Model::$user_message ||
$message->type == Message_Model::$interrupted_membership_message ||
$message->type == Message_Model::$debtor_message ||
$message->type == Message_Model::$payment_notice_message)
{
$message_array[$message->id] = $message->name;
}
}
// no redirection possible for ip address?
if (empty($message_array))
{
$this->session->set_flash('message', url_lang::lang('texts.No redirection is possible to set for this IP address.'));
url::redirect(url_lang::base().'ip_addresses/show/'.$ip_address_id);
}
// form
$form = new Forge(url_lang::base().'redirect/add/'.$ip_address_id, '', 'POST', array('id' => 'article_form'));
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
$form->group('')->label(url_lang::lang('texts.Redirection'));
$form->dropdown('message_id')->label(url_lang::lang('texts.Redirection').':')->options($message_array);
$form->textarea('comment')->label(url_lang::lang('texts.Comment of admin shown to user').':');
$form->submit('submit')->value(url_lang::lang('texts.Redirect'));
special::required_forge_style($form, ' *', 'required');
// validation
if ($form->validate())
{
$form_data = $form->as_array();
$db = new Database();
// delete old redirection if present
$db->delete('messages_ip_addresses', array('message_id' => $form_data['message_id'], 'ip_address_id' => $ip->id));
// database insert sets redirection for ip address
$db->insert('messages_ip_addresses', array('message_id' => $form_data['message_id'],
'ip_address_id' => $ip->id, 'user_id' => $this->session->get('user_id'),
'comment' => $form_data['comment'], 'datetime' => date('Y-m-d H:i:s')));
// generate html page
self::update($ip->ip_address);
// set flash message
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
url::redirect(url_lang::base().'ip_addresses/show/'.$ip_address_id);
}
else
{
// view
$headline = url_lang::lang('texts.Redirection');
$view = new View('main');
$view->title = $headline;
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->link_back = html::anchor(url_lang::base().'ip_addresses/show/'.$ip_address_id, url_lang::lang('texts.Back to IP address'));
$view->content->form = $form->html();
$view->render(TRUE);
}
}
/**
* Deletes information from junction table for redirections.
* @param $ip_address_id IP address to cancel redirection
* @param $message_id Message to cancel redirection (multiple redirections for one IP address are possible)
* @param $from Tells where return after setting this redirection
* @return unknown_type
*/
function delete($ip_address_id, $message_id, $from = 'ip_address')
{
$where = array();
if (is_numeric($ip_address_id))
$array['ip_address_id'] = $ip_address_id;
if (is_numeric($message_id))
$array['message_id'] = $message_id;
$db = new Database();
$db->delete('messages_ip_addresses', $array);
$ip = new Ip_address_Model($ip_address_id);
self::update($ip->ip_address);
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully canceled.'));
if ($from == 'member')
url::redirect(url_lang::base().'members/show/'.$ip->iface->device->user->member_id);
else
url::redirect(url_lang::base().'ip_addresses/show/'.$ip_address_id);
}
/**
* Adds all IP addresses of member to redirection.
* @author Jiri Svitak
* @param unknown_type $member_id
*/
function add_to_member($member_id = null)
{
// access rights
if (!$this->acl_check_edit('Messages_Controller', 'member'))
Controller::error(ACCESS);
if (!isset($member_id))
Controller::warning(PARAMETER);
// member
$member = new Member_Model($member_id);
if ($member->id == 0)
Controller::error(RECORD);
// load list of IP addresses belonging to member
$ip_model = new Ip_address_Model();
$ips = $ip_model->get_ip_addresses_of_member($member_id);
// load list of usable redirection message
$message_model = new Message_Model();
$messages = $message_model->find_all();
foreach($ips as $ip)
{
foreach($messages as $message)
{
// whitelisted IP addresses can be redirected only by redirections which ignore whitelist
if ($ip->whitelisted && !$message->ignore_whitelist)
continue;
// IP address can be manually redirected only to user message, interrupted membership message, debtor message, payment notice message
if ($message->type == Message_Model::$user_message ||
$message->type == Message_Model::$interrupted_membership_message ||
$message->type == Message_Model::$debtor_message ||
$message->type == Message_Model::$payment_notice_message)
{
$message_array[$message->id] = $message->name;
}
}
}
// no redirection possible for this member?
if (empty($message_array))
{
$this->session->set_flash('message', url_lang::lang('texts.No redirection is possible to set for this IP address.'));
url::redirect(url_lang::base().'members/show/'.$member_id);
}
// form
$form = new Forge(url_lang::base().'redirect/add_to_member/'.$member_id, '', 'POST', array('id' => 'article_form'));
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
$form->group('')->label(url_lang::lang('texts.Redirection'));
$form->dropdown('message_id')->label(url_lang::lang('texts.Redirection').':')->options($message_array);
$form->textarea('comment')->label(url_lang::lang('texts.Comment of admin shown to user').':');
$form->submit('submit')->value(url_lang::lang('texts.Redirect'));
special::required_forge_style($form, ' *', 'required');
// validation
if ($form->validate())
{
$form_data = $form->as_array();
$db = new Database();
foreach($ips as $ip)
{
// delete old redirection if present
$db->delete('messages_ip_addresses', array('message_id' => $form_data['message_id'], 'ip_address_id' => $ip->id));
if (!$ip->whitelisted || $message->ignore_whitelist)
{
// database insert sets redirection for ip address
$db->insert('messages_ip_addresses', array('message_id' => $form_data['message_id'],
'ip_address_id' => $ip->id, 'user_id' => $this->session->get('user_id'),
'comment' => $form_data['comment'], 'datetime' => date('Y-m-d H:i:s')));
// generate html page
self::update($ip->ip_address);
}
}
// set flash message
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
url::redirect(url_lang::base().'members/show/'.$member_id);
}
else
{
// view
$headline = url_lang::lang('texts.Redirection');
$view = new View('main');
$view->title = $headline;
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->link_back = html::anchor(url_lang::base().'members/show/'.$member_id, url_lang::lang('texts.Back to the member'));
$view->content->form = $form->html();
$view->render(TRUE);
}
}
/**
* Cancel given redirection to all IP addresses of given member.
* @author Jiri Svitak
* @param $member_id
* @param $message_id
* @return unknown_type
*/
function delete_from_member($member_id, $message_id)
{
$db = new Database();
$ip_model = new Ip_address_Model();
$ips = $ip_model->get_ip_addresses_of_member($member_id);
foreach($ips as $ip)
{
$db->delete('messages_ip_addresses', array('message_id' => $message_id, 'ip_address_id' => $ip->id));
}
// set flash message
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully canceled.'));
url::redirect(url_lang::base().'members/show/'.$member_id);
}
/**
* Sets whitelist type to all IP addresses of member.
* @author Jiri Svitak
* @param $member_id
* @param $whitelist
*/
function set_whitelist($member_id, $whitelist)
{
$db = new Database();
$ip_model = new Ip_address_Model();
$ips = $ip_model->get_ip_addresses_of_member($member_id);
foreach($ips as $ip)
{
$ip = new Ip_address_Model($ip->id);
$ip->whitelisted = $whitelist;
$ip->save();
}
// set flash message
$this->session->set_flash('message', url_lang::lang('texts.Whitelist setting has been successfully set.'));
url::redirect(url_lang::base().'members/show/'.$member_id);
}
/**
* Updates static html file with redirection message.
* @param $ip_address
* @return unknown_type
*/
static function update($ip_address)
{
$page = file_get_contents(url_lang::base().'web_interface/redirect_content/'.$ip_address);
$filename = $ip_address.'.html';
$file = fopen('static/'.$filename,'w+');
fputs($file, $page);
fclose($file);
}
/**
* Replaces special tags in curly brackets {tag} by value associated to target's member IP address.
* Unknown values for tags are replaced by question mark ?.
* @author Jiri Svitak
* @param $text Input HTML stream.
* @param $ip_address Based on given IP address, dependent information in database is searched.
* @return unknown_type Output HTML stream.
*/
static function replace($text, $ip_address)
{
$ip = ORM::factory('ip_address')->where('ip_address', $ip_address)->find();
// other information dependent on IP address registered in database
if (!$ip->id)
{
$member_name = '???';
$variable_symbol = '???';
$current_credit = '???';
}
else
{
// member properties
$member_name = $ip->iface->device->user->member->name;
$variable_symbol = $ip->iface->device->user->member->variable_symbol;
// current credit
$account_balance = ORM::factory('account_balance')->where('member_id', $ip->iface->device->user->member_id)->find();
$current_credit = $account_balance->balance;
// count payment amount to end of year
}
// subnet name
$subnet_model = new Subnet_Model();
$subnet = $subnet_model->get_subnet_of_ip_address($ip_address);
if (!$subnet->id)
{
$subnet_name = '???';
}
else
{
$subnet_name = $subnet->name;
}
// ip address
$text = str_replace('{ip_address}', $ip_address, $text);
// subnet name
$text = str_replace('{subnet_name}', $subnet_name, $text);
// member name
$text = str_replace('{member_name}', $member_name, $text);
// variable symbol of member
$text = str_replace('{variable_symbol}', $variable_symbol, $text);
// current credit
$text = str_replace('{current_credit}', $current_credit, $text);
return $text;
}
/**
* This is the address where are members of network redirected to.
* @todo old version
* @return unknown_type
*/
function index()
{
// initialization
$content = '';
$subnet_name = '';
$member_name = '';
$login = '';
$continue = 0;
$device_engineers = array();
$device_admins = array();
// trying to find ip remote ip address in database
$ip = server::remote_addr();
$member = ORM::factory('member')->get_member_by_ip_address($ip);
$ip_address = ORM::factory('ip_address')->find_redirect_by_ip_address($ip);
// ip address is not in database, choosing content of message
if (!$member || $member->id == 0)
{
$content = $this->settings->get('unknown_device');
}
// optional message redirection
elseif ($member->redirect & 8)
{
$content = $this->settings->get('optional_message');
$continue = 8;
}
// payment notice redirection
elseif ($member->redirect & 4)
{
$content = $this->settings->get('payment_notice');
$continue = 4;
}
// debtor redirection
elseif ($member->redirect & 2)
{
$content = $this->settings->get('debtor');
}
// membership interrupt redirection
elseif ($member->redirect & 1 || $ip_address->redirect & 1)
{
$content = $this->settings->get('interrupt');
}
// no reason to redirect, this shouldn't happen
else
{
$content = $this->settings->get('website_after_redirection');
}
// engineer of user's device, owner of ip address - if available
if ($member && $member->id)
{
$member_name = $member->name;
$login = $member->login;
$device = ORM::factory('device')->get_by_ip_address($ip);
if ($device && $device->id)
{
$device_engineer_model = new Device_engineer_Model();
$device_engineers = $device_engineer_model->get_device_engineers($device->id);
}
}
// trying to find subnet of visitor's ip address
$subnet_model = new Subnet_Model();
$subnet = $subnet_model->get_subnet_of_ip_address($ip);
// remote ip address belongs to some subnet
if ($subnet !== false)
{
//$subnet = $arr_subnets[0];
$subnet_name = $subnet->name;
// finding subnet's gateway
$gw = ORM::factory('device')->get_gateway_of_subnet($subnet->id);
// admin of access point - only if ap exists
if ($gw && $gw->id)
$device_admins = ORM::factory('device_admin')->get_device_admins($gw->id);
}
// view
$view = new View('redirect');
$view->title = url_lang::lang('texts.Redirection');
$view->subnet_name = $subnet_name;
$view->member_name = $member_name;
$view->login = $login;
$view->device_engineers = $device_engineers;
$view->device_admins = $device_admins;
$view->content = stripslashes($content);
$view->continue = $continue;
$view->render(true);
}
/**
* Test method to view given type of redirect
*
* @author Michal Kliment
* @param integer$redir
*/
function test($redir = 0)
{
// initialization
$content = '';
$subnet_name = '';
$member_name = '';
$login = '';
$continue = 0;
$device_engineers = array();
$device_admins = array();
// trying to find ip remote ip address in database
$ip = server::remote_addr();
$member = ORM::factory('member')->get_member_by_ip_address($ip);
$ip_address = ORM::factory('ip_address')->find_redirect_by_ip_address($ip);
// ip address is not in database, choosing content of message
if ($redir == 0)
{
$content = $this->settings->get('unknown_device');
}
// optional message redirection
elseif ($redir == 8)
{
$content = $this->settings->get('optional_message');
$continue = 8;
}
// payment notice redirection
elseif ($redir == 4)
{
$content = $this->settings->get('payment_notice');
$continue = 4;
}
// debtor redirection
elseif ($redir == 2)
{
$content = $this->settings->get('debtor');
}
// membership interrupt redirection
elseif ($redir == 1)
{
$content = $this->settings->get('interrupt');
}
// no reason to redirect, this shouldn't happen
else
{
$content = $this->settings->get('website_after_redirection');
}
// engineer of user's device, owner of ip address - if available
if ($member && $member->id)
{
$member_name = $member->name;
$login = $member->login;
$device = ORM::factory('device')->get_by_ip_address($ip);
if ($device && $device->id)
{
$device_engineer_model = new Device_engineer_Model();
$device_engineers = $device_engineer_model->get_device_engineers($device->id);
}
}
// trying to find subnet of visitor's ip address
$subnet_model = new Subnet_Model();
$subnet = $subnet_model->get_subnet_of_ip_address($ip);
// remote ip address belongs to some subnet
if ($subnet !== false)
{
//$subnet = $arr_subnets[0];
$subnet_name = $subnet->name;
// finding subnet's gateway
$gw = ORM::factory('device')->get_gateway_of_subnet($subnet->id);
// admin of access point - only if ap exists
if ($gw && $gw->id)
$device_admins = ORM::factory('device_admin')->get_device_admins($gw->id);
}
// view
$view = new View('redirect');
$view->title = url_lang::lang('texts.Redirection');
$view->ip_address = $ip;
$view->subnet_name = $subnet_name;
$view->member_name = $member_name;
$view->login = $login;
$view->device_engineers = $device_engineers;
$view->device_admins = $device_admins;
$view->content = stripslashes($content);
$view->continue = $continue;
$view->render(true);
}
/**
* Provides info on ip address and tells users about their account in freenetis - how to log in,
* view payments, view devices etc.
* @author Jiri Svitak
* @return unknown_type
*/
function info()
{
// initialization
$content = '';
$subnet_name = '';
$member_name = '';
$member_id = '';
$login = '';
$continue = 0;
$device_engineers = array();
$device_admins = array();
// trying to find remote ip address in database
$ip_address = ORM::factory('ip_address')->where('ip_address', server::remote_addr())->find();
// engineer of user's device, owner of ip address - if available
if ($ip_address->id != 0)
{
$member_name = $ip_address->iface->device->user->member->name;
$member_id = $ip_address->iface->device->user->member_id;
$login = $ip_address->iface->device->user->login;
$device_engineer_model = new Device_engineer_Model();
$device_engineers = $device_engineer_model->get_device_engineers($ip_address->iface->device_id);
}
// trying to find subnet of visitor's ip address
$subnet_model = new Subnet_Model();
$subnet = $subnet_model->get_subnet_of_ip_address(server::remote_addr());
// remote ip address belongs to some subnet
if (!empty($subnet))
{
//$subnet = $arr_subnets[0];
$subnet_name = $subnet->name;
// finding subnet's gateway
$ip_address_model = new Ip_address_Model();
$ap = $ip_address_model->get_gateway_of_subnet($subnet->network_address);
// admin of access point - only if ap exists
if ($ap->id != 0)
{
// if ap has interface
$iface = new Iface_Model($ap->iface_id);
if ($iface->id != 0)
{
$device_admin_model = new Device_admin_Model();
$device_admins = $device_admin_model->get_device_admins($ap->iface->device_id);
}
}
}
// information for members how to log in to system
$content = $this->settings->get('info');
// view
$view = new View('redirect');
$view->title = url_lang::lang('texts.Redirection');
$view->subnet_name = $subnet_name;
$view->member_name = $member_name;
$view->member_id = $member_id;
$view->login = $login;
$view->device_engineers = $device_engineers;
$view->device_admins = $device_admins;
$view->content = $content;
$view->continue = $continue;
$view->render(true);
}
/**
* Function cancels redirection in case that member is allowed to do so.
* @param $redir
* @return unknown_type
*/
function cancel($redir = 0)
{
// member can cancel optional message and payment notice
if ($redir == 8 || $redir == 4)
{
// previous version
/*
$ip_address = ORM::factory('ip_address')->where('ip_address', server::remote_addr())->find();
$member = new Member_Model($ip_address->iface->device->user->member_id);
$member->redirect &= ~(int) $redir;
$member->redirect &= 15;
$member->save();
*/
// other possible solution
/*
$db = new Database();
$db->query("
UPDATE members m,
(
SELECT m2.id FROM members m2
JOIN users u ON u.member_id = m2.id
JOIN devices d ON d.user_id = u.id
JOIN ifaces i ON i.device_id = d.id
JOIN ip_addresses ip ON ip.iface_id = i.id
WHERE ip.ip_address = '".server::remote_addr()."'
) q
SET m.redirect = m.redirect & ~$redir
WHERE q.id = m.id
");
*/
// fastest query, found out by apache benchmark
$db = new Database();
$db->query("
UPDATE members m,
(
SELECT member_id
FROM users
WHERE id =
(
SELECT user_id
FROM devices
WHERE id =
(
SELECT device_id
FROM ifaces
WHERE id =
(
SELECT iface_id
FROM ip_addresses
WHERE ip_address = ?
)
)
)
UNION
SELECT member_id
FROM users
WHERE id =
(
SELECT user_id
FROM devices
WHERE id =
(
SELECT device_id
FROM ifaces
WHERE id =
(
SELECT iface_id
FROM vlan_ifaces
WHERE id =
(
SELECT vlan_iface_id
FROM ip_addresses
WHERE ip_address = ?
)
)
)
)
UNION
SELECT member_id
FROM subnets_owners
WHERE subnet_id =
(
SELECT id FROM subnets
WHERE inet_aton(?) & inet_aton(netmask) = inet_aton(network_address)
)
LIMIT 0,1
) q
SET m.redirect = m.redirect & ~?
WHERE q.member_id = m.id
", array(server::remote_addr(), server::remote_addr(), server::remote_addr(), $redir));
url::redirect(url_lang::base().'redirect');
}
else
{
echo 'nice try';
}
}
/**
* Function prints ipset of given type.
* @return unknown_type
*/
function ipset($type = null)
{
if (!isset($type))
{
echo 'parameter is missing - try members, ranges, partners, pokus';
return;
}
switch ($type)
{
// list of allowed ip addresses
// if ip address is in redirected range, then this ipset contains allowed ip addresses
case 'members':
$ip_model = new Ip_address_Model();
$ips = $ip_model->get_allowed_member_ips();
foreach ($ips as $ip)
{
echo "$ip->ip_address\n";
}
$subnets_owners = ORM::factory('subnets_owner')->get_all_subnets_with_owner_to_redirect ();
$subq = array();
foreach ($subnets_owners as $subnets_owner)
{
for ($i=1;$i<$subnets_owner->length;$i++)
{
$subq[] = "SELECT '".long2ip($subnets_owner->start+$i)."' AS ip_address\n";
}
}
$ips = $ip_model->get_all_ip_addresses_with_owner(implode("UNION\n",$subq));
foreach ($ips as $ip)
{
echo "$ip->ip_address\n";
}
break;
// list of network address ranges to redirect, gateway shorewall rules are applied to this ranges
case 'ranges':
$subnet_model = new Subnet_Model();
$subnets = $subnet_model->get_subnets_to_redirect();
foreach ($subnets as $subnet)
{
echo "$subnet->network_range\n";
}
break;
}
}
/**
* Function edits member's redirections.
* @param $member_id
* @return unknown_type
*/
function member($member_id = null)
{
// access rights
if (!$this->acl_check_edit('Members_Controller', 'redirect'))
Controller::error(ACCESS);
if (!isset($member_id))
Controller::warning(PARAMETER);
// member
$member = new Member_Model($member_id);
if ($member->id == 0 || $member->id == 1)
Controller::error(RECORD);
$array[0] = url_lang::lang('texts.No');
$array[1] = url_lang::lang('texts.Yes');
// form
$form = new Forge(url_lang::base().'redirect/member/'.$member_id, '', 'POST', array('id' => 'article_form'));
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
$form->group('')->label(url_lang::lang('texts.Redirection'));
$form->dropdown('interrupt')->label(url_lang::lang('texts.Membership interrupt').':')->options($array)->selected(($member->redirect & 1) ? 1 : 0);
$form->dropdown('debtor')->label(url_lang::lang('texts.Debtor').':')->options($array)->selected(($member->redirect & 2) ? 1 : 0);
$form->dropdown('payment_notice')->label(url_lang::lang('texts.Payment notice').':')->options($array)->selected(($member->redirect & 4) ? 1 : 0);
$form->dropdown('optional_message')->label(url_lang::lang('texts.Optional message').':')->options($array)->selected(($member->redirect & 8) ? 1 : 0);
$form->submit('submit')->value(url_lang::lang('texts.Redirect'));
special::required_forge_style($form, ' *', 'required');
// validation
if ($form->validate())
{
$form_data = $form->as_array();
// membership interrupt
if ($form_data['interrupt'] == 1)
$member->redirect |= 1;
else
$member->redirect &= ~1;
// debtor
if ($form_data['debtor'] == 1)
$member->redirect |= 2;
else
$member->redirect &= ~2;
// payment notice
if ($form_data['payment_notice'] == 1)
$member->redirect |= 4;
else
$member->redirect &= ~4;
// optional message
if ($form_data['optional_message'] == 1)
$member->redirect |= 8;
else
$member->redirect &= ~8;
$member->redirect &= 15;
if ($member->save())
{
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
url::redirect(url_lang::base().'members/show/'.$member_id);
}
else
{
$this->session->set_flash('message', url_lang::lang('texts.Error - cant set redirection.'));
url::redirect(url_lang::base().'members/show/'.$member_id);
}
}
else
{
// view
$headline = url_lang::lang('texts.Redirection');
$view = new View('main');
$view->title = $headline;
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->link_back = html::anchor(url_lang::base().'members/show/'.$member_id, url_lang::lang('texts.Back to the member'));
$view->content->form = $form->html();
$view->render(TRUE);
}
}
/**
* Function sets redirection of all members.
* @param $member_id
* @return unknown_type
*/
function members()
{
// access rights
if (!$this->acl_check_edit('Members_Controller', 'redirect'))
Controller::error(ACCESS);
$array[0] = url_lang::lang('texts.Without change');
$array[1] = url_lang::lang('texts.Yes');
$array[2] = url_lang::lang('texts.No');
// form
$form = new Forge(url_lang::base().'redirect/members', '', 'POST', array('id' => 'article_form'));
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
$form->group('')->label(url_lang::lang('texts.Redirection'));
$form->dropdown('interrupt')->label(url_lang::lang('texts.Membership interrupt').':')->options($array)->selected(0);
$form->dropdown('debtor')->label(url_lang::lang('texts.Debtor').':')->options($array)->selected(0);
$form->dropdown('payment_notice')->label(url_lang::lang('texts.Payment notice').':')->options($array)->selected(0);
$form->dropdown('optional_message')->label(url_lang::lang('texts.Optional message').':')->options($array)->selected(0);
$form->submit('submit')->value(url_lang::lang('texts.Redirect'));
special::required_forge_style($form, ' *', 'required');
// validation
if ($form->validate())
{
$form_data = $form->as_array();
$member_model = new Member_Model();
// membership interrupt
if ($form_data['interrupt'] == 1)
$member_model->update_membership_interrupts();
elseif ($form_data['interrupt'] == 2)
$member_model->cancel_redirection(1);
// debtor
if ($form_data['debtor'] == 1)
$member_model->update_debtors();
elseif ($form_data['debtor'] == 2)
$member_model->cancel_redirection(2);
// payment notice
if ($form_data['payment_notice'] == 1)
{
$fee_model = new Fee_Model();
$fee = $fee_model->get_by_date_type(date('Y-m-d'), 'regular member fee');
if ($fee->id)
$current_fee = $fee->fee;
$member_model->update_payment_notice(-100000, 0);
}
elseif ($form_data['payment_notice'] == 2)
$member_model->cancel_redirection(4);
// optional message
if ($form_data['optional_message'] == 1)
$member_model->update_optional_message();
elseif ($form_data['optional_message'] == 2)
$member_model->cancel_redirection(8);
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
url::redirect(url_lang::base().'members/show_all');
}
else
{
// view
$headline = url_lang::lang('texts.Redirection');
$view = new View('main');
$view->title = $headline;
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->link_back = html::anchor(url_lang::base().'members/show_all', url_lang::lang('texts.Back to list of all members'));
$view->content->form = $form->html();
$view->render(TRUE);
}
}
/**
* Function sets redirection to members on given subnet.
* @param $subnet_id
* @return unknown_type
*/
function subnet($subnet_id = NULL)
{
// access rights
if (!$this->acl_check_edit('Members_Controller', 'redirect'))
Controller::error(ACCESS);
if (!isset($subnet_id))
Controller::warning(PARAMETER);
$subnet = new Subnet_Model($subnet_id);
if ($subnet->id == 0)
Controller::error(RECORD);
$array[0] = url_lang::lang('texts.No');
$array[1] = url_lang::lang('texts.Yes');
// form
$form = new Forge(url_lang::base().'redirect/subnet/'.$subnet_id, '', 'POST', array('id' => 'article_form'));
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
$form->group('')->label(url_lang::lang('texts.Redirection'));
//$form->dropdown('payment_notice')->label(url_lang::lang('texts.Payment notice').':')->options($array)->selected(0);
$form->dropdown('optional_message')->label(url_lang::lang('texts.Optional message').':')->options($array)->selected(0);
$form->submit('submit')->value(url_lang::lang('texts.Redirect'));
special::required_forge_style($form, ' *', 'required');
// validation
if ($form->validate())
{
$form_data = $form->as_array();
$member_model = new Member_Model();
$members = $member_model->get_members_of_subnet($subnet_id);
$saved = true;
foreach ($members as $m)
{
$member = new Member_Model($m->id);
$member->redirect &= ~8;
if ($form_data['optional_message'] == 1)
$member->redirect |= 8;
$saved = $member->save();
}
if ($saved)
{
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
}
else
{
$this->session->set_flash('message', url_lang::lang('texts.Error - cant set redirection.'));
}
url::redirect(url_lang::base().'subnets/show/'.$subnet_id);
}
else
{
// view
$breadcrumbs[] = ($this->acl_check_view('Devices_Controller','subnet')) ? html::anchor(url_lang::base().'subnets/show_all', url_lang::lang('texts.Subnets')) : url_lang::lang('texts.Subnets');
$breadcrumbs[] = ($this->acl_check_view('Devices_Controller','subnet')) ? html::anchor(url_lang::base().'subnets/show/'.$subnet->id, $subnet->name." ($subnet->network_address/". network::netmask2cidr($subnet->netmask) .")") : $subnet->name." ($subnet->network_address/". network::netmask2cidr($subnet->netmask) .")";
$breadcrumbs[] = url_lang::lang('texts.Redirection');
$headline = url_lang::lang('texts.Redirection');
$view = new View('main');
$view->breadcrumbs = implode(' » ',$breadcrumbs);
$view->title = $headline;
$view->content = new View('form');
$view->content->headline = $headline;
//$view->content->link_back = html::anchor(url_lang::base().'subnets/show/'.$subnet_id, url_lang::lang('texts.Back to the subnet'));
$view->content->form = $form->html();
$view->render(TRUE);
}
}
}
?>
freenetis/branches/ticket_system/application/controllers/settings.php
<?php
class Settings_Controller extends Controller
{
private $links;
function __construct()
{
parent::__construct();
$this->sections = array(
'info' => url_lang::lang('texts.Info'),
'system' => url_lang::lang('texts.System'),
'email' => url_lang::lang('texts.Email'),
'approval' => url_lang::lang('texts.Approval'),
'voip' => url_lang::lang('texts.VoIP'),
'sms' => url_lang::lang('texts.SMS'),
'redirection' => url_lang::lang('texts.Redirection'),
'logging' => url_lang::lang('texts.Logování'),
'map' => url_lang::lang('texts.Map'),
'registration_export' => url_lang::lang('texts.Export of registration')
);
}
function index()
{
url::redirect(url_lang::base().'settings/info');
}
/**
* @author Tomas Dulik
* info() displays various system information
* @return unknown_type
*/
function info()
{
if (!$this->acl_check_edit('Settings_Controller','system'))
Controller::error(ACCESS);
$data = array();
foreach ($this->svn as $key => $value)
{
if (strpos($value,'http') !== FALSE)
$data[url_lang::lang ('texts.'.inflector::humanize($key))] = $value;
else
$data[url_lang::lang ('texts.'.inflector::humanize($key))] = url_lang::lang('texts.'.$value);
}
$data[url_lang::lang("texts.DB schema revision")] = $this->settings->get('db_schema_version');
ob_start();
phpinfo();
$html=ob_get_contents();
ob_end_clean();
// Delete styles from output (credits: Moodle.org)
$html = preg_replace('#(\n?<style[^>]*?>.*?</style[^>]*?>)|(\n?<style[^>]*?/>)#is', '', $html);
$html = preg_replace('#(\n?<head[^>]*?>.*?</head[^>]*?>)|(\n?<head[^>]*?/>)#is', '', $html);
// Delete DOCTYPE from output
$html = preg_replace('/<!DOCTYPE html PUBLIC.*?>/is', '', $html);
// Delete body and html tags
$html = preg_replace('/<html.*?>.*?<body.*?>/is', '', $html);
$html = preg_replace('/<\/body><\/html>/is', '', $html);
$html = preg_replace('/table border="0"/is', 'table class="extended"', $html);
$table=new View('table_2_columns');
$table->table_data = $data;
$view = new View('main');
$view->title = url_lang::lang('texts.System').' - '.url_lang::lang('texts.Info');
$view->content = new View("settings");
$view->content->current = 'info';
$view->content->headline = url_lang::lang('texts.Info');
$view->content->content = $table . $html;
$view->render(TRUE);
}
/**
* @author Michal Kliment
* Form to set up system variables
*/
function system()
{
// access control
if (!$this->acl_check_edit('Settings_Controller','system'))
Controller::error(ACCESS);
// creating of new forge
$this->form = new Forge(url_lang::base()."settings/system", '', 'POST', array('id' => 'article_form'));
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
$this->form->group('')->label(url_lang::lang('texts.System variables'));
// page title
$this->form->input('title')->label(url_lang::lang('texts.Page title').':')->rules('length[3,40]|required')->value($this->settings->get('title'));
$countries = ORM::factory('country')->select_list('id', 'country_name');
$this->form->dropdown('default_country')->label(url_lang::lang('texts.Country').':')->rules('required')->options($countries)->selected($this->settings->get('default_country'));
// currency
$this->form->input('currency')->label(url_lang::lang('texts.Currency').':')->rules('length[3,40]|required')->value($this->settings->get('currency'));
// self-registration
$this->form->radio('self_registration')->label(url_lang::lang('texts.Self-registration').':')->options(array('1'=>url_lang::lang('texts.Yes'),'0'=>url_lang::lang('texts.No')))->default($this->settings->get('self_registration'));
// forgotten password
$this->form->radio('forgotten_password')->label(url_lang::lang('texts.Forgotten password').':')->options(array('1'=>url_lang::lang('texts.Yes'),'0'=>url_lang::lang('texts.No')))->default($this->settings->get('forgotten_password'));
$this->form->group('')->label(url_lang::lang('texts.E-mail settings'));
$this->form->input('email_default_email')->label(url_lang::lang('texts.Default e-mail').':')->rules('length[3,100]|valid_email')->value($this->settings->get('email_default_email'));
$this->form->group('')->label(url_lang::lang('texts.URL settings'));
$this->form->dropdown('protocol')->label(url_lang::lang('texts.Protocol').':')->rules('length[3,100]')->options(array('http'=>'http', 'https'=>'https'))->selected(url::protocol());
$this->form->input('domain')->label(url_lang::lang('texts.Domain').':')->rules('required|length[3,100]')->value(url::domain());
$this->form->input('suffix')->label(url_lang::lang('texts.Suffix').':')->rules('required|valid_suffix')->value(url::suffix());
// load .htaccess sample file
if (($htaccessFile = @file('.htaccess-sample')) != FALSE)
{
$this->form->radio('clean_urls')->label(url_lang::lang('texts.Clean URLs').':')->options(array('1'=>url_lang::lang('texts.Yes'),'0'=>url_lang::lang('texts.No')))->default(!$this->settings->get('index_page'))->help(url_lang::lang('texts.URL addresses without index.php.'));
foreach ($htaccessFile as $line_num => $line)
{
// find line with RewriteBase
if (preg_match("/^RewriteBase (.+)/", $line, $matches))
{
// and set there our suffix (subdirectory)
$htaccessFile[$line_num] = preg_replace("/^(RewriteBase )(.+)/", '${1}'.url::suffix(), $line);
}
}
// write textarea with content of .htaccess sample file
if (!is_writable('.') && !file_exists('.htaccess'))
{
$textarea = '';
foreach ($htaccessFile as $line)
$textarea .= htmlentities ($line);
$this->form->textarea('htaccess')->label(url_lang::lang('texts.Content of file htaccess').':')->value($textarea)->help(url_lang::lang('texts.It\'s not possible to write your htacess file for clean URLS.').' '.url_lang::lang('texts.You must create it manually and paste the following text into it.'));
}
}
$this->form->group('')->label(url_lang::lang('texts.Network settings'));
$this->form->input('address_ranges')->label(url_lang::lang('texts.Address ranges').':')->rules('valid_address_ranges')->value(Settings::get('address_ranges'));
$this->form->submit('submit')->value(url_lang::lang('texts.Save'));
special::required_forge_style($this->form, ' *', 'required');
// form validate
if ($this->form->validate())
{
$form_data = $this->form->as_array();
$config_model = new Config_Model();
$issaved = true;
$message = '';
foreach ($form_data as $name => $value)
{
// transform clean_urls to index_page
if ($name == 'clean_urls')
{
$name = 'index_page';
$value = ($value) ? 0 : 1;
// we want clean urls
if (!$value)
{
// and can create it
if (is_writable('.'))
{
// create it
$handle = fopen('.htaccess', 'w');
foreach($htaccessFile as $line )
{
fwrite($handle, $line);
}
fclose($handle);
chmod('.htaccess', 0666);
$message = url_lang::lang('texts.Htaccess file has been successfully created.');
}
else
{
// we can't create it and it doen't exist
if (!file_exists('.htaccess'))
{
// we turn off clean urls
$value = 1;
$message = url_lang::lang('texts.Htaccess file hasn\'t been successfully created.');
}
}
}
}
// check if variable exists
if ($config_model->check_exist_variable($name))
// update of variable
$issaved = $issaved && $config_model->update_variable($name,$value);
else
// insert new variable
$issaved = $issaved && $config_model->insert_variable($name,$value);
}
if ($issaved)
// if all action were succesfull
$message = url_lang::lang('texts.System variables have been successfully updated.')."<br />".$message;
else
// if not
$message = url_lang::lang('texts.System variables havent been successfully updated.')."<br />".$message;
$this->session->set_flash('message', $message);
url::redirect(url_lang::base().'settings/system');
}
$view = new View('main');
$view->extra_scripts = "$(document).ready(function(){
var clean_urls = $('input[name=clean_urls]:checked').val();
if (clean_urls == 0)
$('.htaccess').hide();
$('input[name=clean_urls]').change(function(){
var clean_urls = $('input[name=clean_urls]:checked').val();
if (clean_urls == 0)
$('.htaccess').hide();
else
$('.htaccess').show();
});
});";
$view->title = url_lang::lang('texts.Settings').' - '.url_lang::lang('texts.System');
$view->content = new View('settings');
$view->content->current = 'system';
$view->content->content= $this->form->html();
$view->content->headline = url_lang::lang('texts.System');
$message = $this->session->get_once('message');
if (!empty($message))
$view->content->message = $message;
$view->render(TRUE);
}
/**
* @author Michal Kliment
* Settings of email variables
*/
function email()
{
// access control
if (!$this->acl_check_edit('Settings_Controller','system'))
Controller::error(ACCESS);
// creating of new forge
$this->form = new Forge(url_lang::base()."settings/email", '', 'POST', array('id' => 'article_form'));
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
$this->form->group('')->label(url_lang::lang('texts.E-mail variables'));
$this->form->dropdown('email_driver')->label(url_lang::lang('texts.Driver').':')->options(array('native' => url_lang::lang('texts.Native'), 'smtp' => url_lang::lang('texts.SMTP'), 'sendmail' => url_lang::lang('texts.Sendmail')))->selected($this->settings->get('email_driver'));
$this->form->input('email_hostname')->label(url_lang::lang('texts.Hostname').':')->value($this->settings->get('email_hostname'))->help(url_lang::lang('texts.For SMTP settings only.'));
$this->form->input('email_port')->label(url_lang::lang('texts.Port').':')->rules('valid_numeric')->value($this->settings->get('email_port'))->help(url_lang::lang('texts.For SMTP settings only.'));
$this->form->input('email_username')->label(url_lang::lang('texts.User name').':')->value($this->settings->get('email_username'))->help(url_lang::lang('texts.For SMTP settings only.'));
$this->form->input('email_password')->label(url_lang::lang('texts.Password').':')->value($this->settings->get('email_username'))->help(url_lang::lang('texts.For SMTP settings only.'));
$this->form->submit('submit')->value(url_lang::lang('texts.Save'));
special::required_forge_style($this->form, ' *', 'required');
// form validate
if ($this->form->validate())
{
$form_data = $this->form->as_array();
$config_model = new Config_Model();
$issaved = true;
foreach ($form_data as $name => $value)
{
// check if variable exists
if ($config_model->check_exist_variable($name))
// update of variable
$issaved = $issaved && $config_model->update_variable($name,$value);
else
// insert new variable
$issaved = $issaved && $config_model->insert_variable($name,$value);
}
if ($issaved)
// if all action were succesfull
$this->session->set_flash('message', url_lang::lang('texts.E-mail variables have been successfully updated.'));
else
// if not
$this->session->set_flash('message', url_lang::lang('texts.E-mail variables havent been successfully updated.'));
url::redirect(url_lang::base().'settings/email');
}
$view = new View('main');
$view->extra_scripts = '$(document).ready(function(){
var driver = $("#email_driver option:selected").val();
if (driver != "smtp")
$("#email_hostname,#email_port,#email_username,#email_password").attr("disabled", true);
$("#email_driver").change(function(){
var driver = $("#email_driver option:selected").val();
if (driver != "smtp")
$("#email_hostname,#email_port,#email_username,#email_password").attr("disabled", true);
else
$("#email_hostname,#email_port,#email_username,#email_password").removeAttr("disabled");
});
});';
$view->title = url_lang::lang('texts.Settings').' - '.url_lang::lang('texts.E-mail');
$view->content = new View('settings');
$view->content->current = 'email';
$view->content->content = $this->form->html();
$view->content->headline = url_lang::lang('texts.E-mail');
$message = $this->session->get_once('message');
if (!empty($message))
$view->content->message = $message;
$view->render(TRUE);
}
public function approval()
{
// access control
if (!$this->acl_check_edit('Settings_Controller','system'))
Controller::error(ACCESS);
$approval_template_model = new Approval_template_Model();
$approval_templates = $approval_template_model->find_all();
$arr_approval_templates = array();
foreach ($approval_templates as $approval_template)
{
$arr_approval_templates[$approval_template->id] = $approval_template->name;
}
$arr_approval_templates = arr::merge(array(NULL => '----- '.url_lang::lang('texts.select approval template').' -----'), $arr_approval_templates);
// creating of new forge
$this->form = new Forge(url_lang::base()."settings/approval", '', 'POST', array('id' => 'article_form'));
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
$this->form->group('')->label(url_lang::lang('texts.Work'));
$this->form->dropdown('default_work_approval_template')->label(url_lang::lang('texts.Default approval template').':')->options($arr_approval_templates)->selected($this->settings->get('default_work_approval_template'))->rules('required');
$this->form->group('')->label(url_lang::lang('texts.Work report'));
$this->form->dropdown('default_work_report_approval_template')->label(url_lang::lang('texts.Default approval template').':')->options($arr_approval_templates)->selected($this->settings->get('default_work_report_approval_template'))->rules('required');
$this->form->group('')->label(url_lang::lang('texts.Request'));
$this->form->dropdown('default_request_approval_template')->label(url_lang::lang('texts.Default approval template').':')->options($arr_approval_templates)->selected($this->settings->get('default_request_approval_template'))->rules('required');
$this->form->submit('submit')->value(url_lang::lang('texts.Save'));
special::required_forge_style($this->form, ' *', 'required');
if ($this->form->validate())
{
$form_data = $this->form->as_array();
$config_model = new Config_Model();
$issaved = true;
foreach ($form_data as $name => $value)
{
$value = addslashes($value);
// check if variable exists
if ($config_model->check_exist_variable($name))
// update of variable
$issaved = $issaved && $config_model->update_variable($name,$value);
else
// insert new variable
$issaved = $issaved && $config_model->insert_variable($name,$value);
}
if ($issaved)
// if all action were succesfull
$this->session->set_flash('message', url_lang::lang('texts.System variables have been successfully updated').'.');
else
// if not
$this->session->set_flash('message', url_lang::lang('texts.System variables havent been successfully updated').'.');
url::redirect(url_lang::base().'settings/approval');
}
$view = new View('main');
$view->title = url_lang::lang('texts.Settings').' - '.url_lang::lang('texts.Approval');
$view->content = new View('settings');
$view->content->current = 'approval';
$view->content->headline = url_lang::lang('texts.Approval');
$view->content->link_back = $this->links;
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff