|
<?php defined('SYSPATH') or die('No direct script access.');
|
|
/*
|
|
* This file is part of open source system FreeNetIS
|
|
* and it is release under GPLv3 licence.
|
|
*
|
|
* More info about licence can be found:
|
|
* http://www.gnu.org/licenses/gpl-3.0.html
|
|
*
|
|
* More info about project can be found:
|
|
* http://www.freenetis.org/
|
|
*
|
|
*/
|
|
|
|
/**
|
|
* @package Model
|
|
*/
|
|
class Message_Model extends ORM
|
|
{
|
|
// user message, can be added and deleted by user
|
|
public static $user_message = 0;
|
|
// not exactly message, it is content of side panel, should be used for information for all redirections
|
|
public static $contact_information = 1;
|
|
// content of page shown after canceling redirection
|
|
public static $cancel_message = 2;
|
|
// content of page with text for unknown device
|
|
public static $unknown_device_message = 3;
|
|
// content of page for interrupted member, this redirection can be set in system
|
|
public static $interrupted_membership_message = 4;
|
|
// content of page for debtor, this redirection can be set in system
|
|
public static $debtor_message = 5;
|
|
// content of page for payment notice, this redirection can be set in system and can be canceled by user
|
|
public static $payment_notice_message = 6;
|
|
|
|
// self cancel disabled, remote computer cannot cancel this message
|
|
public static $self_cancel_disabled = 0;
|
|
// self cancel enabled, every member's IP address will have cancelled given redirection
|
|
public static $self_cancel_member = 1;
|
|
// self cancel enabled, redirection is canceled only for current remote computer
|
|
public static $self_cancel_ip = 2;
|
|
|
|
|
|
/**
|
|
* Counts all activated redirections from junction table messages_ip_addresses.
|
|
*
|
|
*
|
|
* @author Jiri Svitak
|
|
* @return unknown_type
|
|
*/
|
|
public function count_all_redirections()
|
|
{
|
|
return $this->db->count_records('messages_ip_addresses');
|
|
}
|
|
|
|
/**
|
|
* Gets all activated redirections from junction table messages_ip_addresses.
|
|
*
|
|
*
|
|
* @return unknown_type
|
|
*/
|
|
public function get_all_redirections($limit_from = 0, $limit_results = 20,
|
|
$order_by = 'ip_address', $order_by_direction = 'ASC', $filter_values = array())
|
|
{
|
|
// order by check
|
|
if ($order_by == 'ip_address')
|
|
{
|
|
//$order_by = 'inet_aton(ip_address)';
|
|
$order_by = 'inet_aton(ip.ip_address) ASC, m.self_cancel DESC, mip.datetime ASC';
|
|
$order_by_direction = "";
|
|
}
|
|
else
|
|
{
|
|
$order_by = $this->db->escape_column($order_by);
|
|
}
|
|
// query
|
|
return $this->db->query("
|
|
SELECT mip.ip_address_id, ip.ip_address, m.name AS message, mip.datetime, mip.comment, m.type, m.self_cancel
|
|
FROM messages_ip_addresses mip
|
|
LEFT JOIN ip_addresses ip ON ip.id = mip.ip_address_id
|
|
LEFT JOIN messages m ON m.id = mip.message_id
|
|
ORDER BY $order_by $order_by_direction
|
|
LIMIT $limit_from, $limit_results
|
|
");
|
|
}
|
|
|
|
/**
|
|
* Counts all messages.
|
|
*
|
|
* @return unknown_type
|
|
*/
|
|
public function count_all_messages()
|
|
{
|
|
return $this->db->count_records('messages');
|
|
}
|
|
|
|
/**
|
|
* Gets all redirection messages.
|
|
*
|
|
* @author Jiri Svitak
|
|
* @param integer $limit_from
|
|
* @param integer $limit_results
|
|
* @param string $order_by
|
|
* @param string $order_by_direction
|
|
* @param array $filter_values
|
|
* @return unknown_type
|
|
*/
|
|
public function get_all_messages($limit_from = 0, $limit_results = 20,
|
|
$order_by = 'id', $order_by_direction = 'DESC', $filter_values = array())
|
|
{
|
|
// order by check
|
|
if (!$this->has_column($order_by))
|
|
{
|
|
$order_by = 'id';
|
|
}
|
|
// order by direction check
|
|
$order_by_direction = strtolower($order_by_direction);
|
|
if ($order_by_direction != 'desc')
|
|
{
|
|
$order_by_direction = 'asc';
|
|
}
|
|
// query
|
|
return $this->db->query("
|
|
SELECT m.id, m.name AS message, m.type
|
|
FROM messages m
|
|
ORDER BY $order_by $order_by_direction
|
|
LIMIT $limit_from, $limit_results
|
|
");
|
|
}
|
|
|
|
}
|