Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1270

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

Novinky:

- do systemu upozornovani pridana moznost upozornovat pomoci SMS zprav
- moznost smazat vsechny neodeslane email a SMS zpravy

Upravy:

- prepsany funkce pro aktivaci presmerovani
- vylepsena implementace tridy Model

Zobrazit rozdíly:

freenetis/branches/testing/application/i18n/cs_CZ/texts.php
$lang = array
(
'%d prefix already in database' => '%d předčíslí se již nachází v databázi',
'%d unsended e-mails has been deleted' => '%d neposlaných emailových zpráv bylo smazáno.',
'%d unsended sms messages has been deleted' => '%d neposlaných SMS zpráv bylo smazáno.',
'%s days ago' => 'před %s dny',
'%s hours ago' => 'před %s hodinama',
'%s minutes ago' => 'před %s minutama',
......
'content of file htaccess' => 'Obsah souboru .htaccess',
'content of the message for e-mail' => 'Obsah zprávy pro e-mail',
'content of the message for redirection' => 'Obsah zprávy pro přesměrování',
'content of the message for sms' => 'Obsah zprávy pro SMS',
'continue with works filling' => 'Pokračovat vyplňováním prací',
'contractual increase' => 'Smluvní navýšení',
'cookies must be enabled' => 'Musí být zapnuty cookies.',
......
'delete_member' => 'Smazat tohoto člena',
'delete_work' => 'Smazat tuto práci',
'delete' => 'Smazat',
'delete all unsended e-mails' => 'Smazat všechny neposlané emaily',
'delete device' => 'Smazat zařízení',
'delete selection' => 'Smazat výběr',
'delete selected messages' => 'Smazat vybrané zprávy',
'delete this filter' => 'Smazat tento filtr',
'delete this work' => 'Smazat tuto práci',
'delete unsended messages' => 'Smazat neposlané zprávy',
'delete whole device' => 'Smazat celé zařízení',
'delete wireless setting' => 'Smazat bezdrátové nastavení',
'deleted' => 'Smazáno',
......
'sms message list' => 'Seznam SMS zpráv',
'sms message recieved' => 'SMS zpráva přijata',
'sms message send' => 'SMS zpráva odeslána',
'sms message "%s" has been sent for %d phone numbers' => 'SMS zpráva "%s" byla odeslána pro %d telefonních čísel.',
'sms messages' => 'SMS zprávy',
'sms messages enabled' => 'SMS zprávy povoleny',
'sms message has been successfully added' => 'SMS zpráva byla úspěšně přidána.',
......
'whitelist setting has been successfully set' => 'Bílá listina byla úspěšně nastavena.',
'whole d' => 'Celé z.',
'without change' => 'Beze změny',
'without prefixes' => 'Bez prefixů',
'without prefixes' => 'Bez předčíslí',
'without street' => 'Bez ulice',
'wireless' => 'bezdrátové',
'wireless interfaces' => 'Bezdrátová rozhraní',
freenetis/branches/testing/application/vendors/unit_tester/unit_testing_config.xml
</input>
</values>
</method>
<method name="delete_unsended" autogenerate="on">
<attributes></attributes>
<values>
<input></input>
</values>
</method>
</controller>
<controller name="enum_types">
<method name="index" autogenerate="on">
......
</input>
</values>
</method>
<method name="valid_email" autogenerate="off">
<method name="valid_email_or_sms" autogenerate="on">
<attributes>
<attribute name="input" default_value=""/>
<attribute name="input" default_value="" />
</attributes>
<values>
<input></input>
<input>
<param value="" />
</input>
</values>
</method>
</controller>
......
<input></input>
</values>
</method>
<method name="delete_unsended" autogenerate="on">
<attributes></attributes>
<values>
<input></input>
</values>
</method>
<method name="show" autogenerate="on">
<attributes>
<attribute name="sms_id" default_value="" />
......
</method>
<method name="activate_interrupted_membership_message" autogenerate="on">
<attributes>
<attribute name="message_id" default_value="" />
<attribute name="user_id" default_value="" />
</attributes>
<values>
<input>
<param value="" />
<param value="" />
</input>
</values>
</method>
......
</input>
</values>
</method>
<method name="activate_debtor_message" autogenerate="on">
<attributes>
<attribute name="user_id" default_value="" />
<attribute name="debtor_boundary" default_value="" />
<attribute name="redirection" default_value="" />
<attribute name="email" default_value="" />
</attributes>
<values>
<input>
<param value="" />
<param value="" />
<param value="" />
<param value="" />
</input>
</values>
</method>
<method name="activate_user_message" autogenerate="on">
<attributes>
<attribute name="message_id" default_value="" />
<attribute name="user_id" default_value="" />
<attribute name="redirection" default_value="" />
<attribute name="email" default_value="" />
</attributes>
<values>
<input>
<param value="" />
<param value="" />
<param value="" />
<param value="" />
</input>
</values>
</method>
<method name="deactivate_message" autogenerate="on">
<attributes>
<attribute name="message_id" default_value="" />
......
<input></input>
</values>
</method>
<method name="get_contacts_of_debtors_by_type" autogenerate="on">
<attributes>
<attribute name="debtor_boundary" default_value="" />
<attribute name="type" default_value="" />
</attributes>
<values>
<input>
<param value="" />
<param value="" />
</input>
</values>
</method>
<method name="get_all_contacts_by_type" autogenerate="on">
<attributes>
<attribute name="type" default_value="" />
<attribute name="ignore_whitelisted" default_value="FALSE" />
</attributes>
<values>
<input>
<param value="" />
</input>
<input>
<param value="" />
<param value="FALSE" />
</input>
</values>
</method>
</model>
<model name="users_key">
<method name="get_keys_by_device" autogenerate="off">
freenetis/branches/testing/application/models/message.php
*/
/**
* Messages for notifications and actions for activating redirection and
* sending email and SMS messages for notigfication.
*
* @package Model
*
* @property integer $id
* @property string $name
* @property string $text
* @property string $email_text
* @property string $sms_text
* @property integer $type
* @property integer $self_cancel
* @property boolean $ignore_whitelist
*/
class Message_Model extends ORM
{
// user message, can be added and deleted by user
// type constants
/**
* user message, can be added and deleted by user
*/
const USER_MESSAGE = 0;
// not exactly message, it is content of side panel, should be used for information for all redirections
/**
* not exactly message, it is content of side panel,
* should be used for information for all redirections
*/
const CONTACT_INFORMATION = 1;
// content of page shown after canceling redirection
/**
* content of page shown after canceling redirection
*/
const CANCEL_MESSAGE = 2;
// content of page with text for unknown device
/**
* content of page with text for unknown device
*/
const UNKNOWN_DEVICE_MESSAGE = 3;
// content of page for interrupted member, this redirection can be set in system
/**
* content of page for interrupted member,
* this redirection can be set in system
*/
const INTERRUPTED_MEMBERSHIP_MESSAGE = 4;
// content of page for debtor, this redirection can be set in system
/**
* content of page for debtor, this redirection can be set in system
*/
const DEBTOR_MESSAGE = 5;
// content of page for payment notice, this redirection can be set in system and can be canceled by user
/**
* content of page for payment notice, this redirection can be set
* in system and can be canceled by user
*/
const PAYMENT_NOTICE_MESSAGE = 6;
// content of page for unallowed connecting place, depends on allowed subnets
/**
* content of page for unallowed connecting place, depends on allowed subnets
*/
const UNALLOWED_CONNECTING_PLACE_MESSAGE = 7;
// self cancel disabled, remote computer cannot cancel this message
// self-cancel constants
/**
* self cancel disabled, remote computer cannot cancel this message
*/
const SELF_CANCEL_DISABLED = 0;
// self cancel enabled, every member's IP address will have cancelled given redirection
/**
* self cancel enabled, every member's IP address will have cancelled
* given redirection
*/
const SELF_CANCEL_MEMBER = 1;
// self cancel enabled, redirection is canceled only for current remote computer
/**
* self cancel enabled, redirection is canceled only for current remote computer
*/
const SELF_CANCEL_IP = 2;
......
/**
* Activates interrupted membership message to ip addresses of users with
* interrupted membership.
*
* @author Jiri Svitak
* @param integer $user_id
* @return integer number of ip addresses activated
* @param integer $message_id ID of message
* @param integer $user_id Who redirects
* @return integer Number of ip addresses activated
*/
public function activate_interrupted_membership_message($user_id)
public function activate_interrupted_membership_message($message_id, $user_id)
{
// user id
$user_id = intval($user_id);
$user_id = ($user_id) ? $user_id : 'NULL';
// preparation
$message = ORM::factory('message')->where(
'type', self::INTERRUPTED_MEMBERSHIP_MESSAGE)->find();
$content = $message->text;
$datetime = date('Y-m-d H:i:s');
$ip_count = 0;
// delete old redirections
$database = Database::instance();
$database->delete('messages_ip_addresses', array('message_id' => $message->id));
// find IP addresses with interrupted membership
$ip_model = new Ip_address_Model();
$ips = $ip_model->get_ip_addresses_with_interrupted_membership();
// first sql for inserting transfers
$sql_insert = "INSERT INTO messages_ip_addresses " .
"(message_id, ip_address_id, user_id, comment, datetime) VALUES ";
$values = array();
// set new redirections in junction table
foreach($ips as $ip)
{
// insert values
$values[] = "($message->id, $ip->id, $user_id, '', '$datetime')";
$ip_count++;
}
$message = new Message_Model($message_id);
if ($ip_count > 0)
// message do not exists
if (!$message || !$message->id)
{
$sql_insert .= implode(",", $values);
if (!$database->query($sql_insert))
throw new Exception();
throw new Exception('Debtor message not founded');
}
return $ip_count;
// IP adreesses
$ip_model = new Ip_address_Model();
$ips = $ip_model->get_ip_addresses_with_interrupted_membership();
// activate
return $this->_activate_redirection($message, $ips, $user_id);
}
/**
* Activates notifications for ip addresses with unallowed connecting place
*
* @author Michal Kliment
* @param integer $user_id
* @return integer
* @param integer $user_id Who redirects
* @return integer Number of ip addresses activated
*/
public function activate_unallowed_connecting_place_message($user_id)
{
// user id
$user_id = intval($user_id);
$user_id = ($user_id) ? $user_id : 'NULL';
// preparation
$message = ORM::factory('message')->where(
'type', self::UNALLOWED_CONNECTING_PLACE_MESSAGE)->find();
$content = $message->text;
$datetime = date('Y-m-d H:i:s');
$ip_count = 0;
// delete old redirections
$database = Database::instance();
$database->delete('messages_ip_addresses', array('message_id' => $message->id));
$message = ORM::factory('message')->where(array
(
'type' => self::UNALLOWED_CONNECTING_PLACE_MESSAGE
))->find();
// message do not exists
if (!$message || !$message->id)
{
throw new Exception('Debtor message not founded');
}
// find IP addresses with interrupted membership
$ip_model = new Ip_address_Model();
$ips = $ip_model->get_ip_addresses_with_unallowed_connecting_place();
// first sql for inserting transfers
$sql_insert = "INSERT INTO messages_ip_addresses " .
"(message_id, ip_address_id, user_id, comment, datetime) VALUES ";
$values = array();
// set new redirections in junction table
foreach($ips as $ip)
{
// insert values
$values[] = "($message->id, $ip->id, $user_id, '', '$datetime')";
$ip_count++;
}
if ($ip_count > 0)
{
$sql_insert .= implode(",", $values);
if (!$database->query($sql_insert))
throw new Exception();
}
return $ip_count;
// activate
return $this->_activate_redirection($message, $ips, $user_id);
}
/**
* Activates debtor message to ip addresses of members with
* negative credit.
* @author Jiri Svitak
* @param integer $user_id
* @param integer $debtor_boundary
* @return int
*
* @author Ondřej Fibich
* @param integer $message_id ID of message
* @param integer $user_id Who redirects
* @param double $debtor_boundary Border of debtor
* @param integer $redirection Redirection state
* @param integer $email E-mail state
* @param integer $sms SMS state
* @return array Stats array
*/
public function activate_debtor_message($user_id, $debtor_boundary, $redirection, $email)
public function activate_debtor_message(
$message_id, $user_id, $debtor_boundary,
$redirection, $email, $sms)
{
// user id
$user_id = intval($user_id);
$user_id = ($user_id) ? $user_id : 'NULL';
// preparation
$message = ORM::factory('message')->where(
'type', self::DEBTOR_MESSAGE)->find();
$content = $message->text;
$datetime = date('Y-m-d H:i:s');
$ip_count = 0;
// delete old redirections
$database = Database::instance();
// stats
$s = array
(
'ip_count' => 0,
'email_count' => 0,
'sms_count' => 0
);
// helper models
$ip_model = new Ip_address_Model();
$uc_model = new Users_contacts_Model();
$message = new Message_Model($message_id);
// message do not exists
if (!$message || !$message->id)
{
throw new Exception('Debtor message not founded');
}
// redirection
if ($redirection == Notifications_Controller::ACTIVATE)
{
$database->delete('messages_ip_addresses', array('message_id' => $message->id));
// finding IP addresses to redirect to debtor message
$ip_model = new Ip_address_Model();
// find IP addresses of debtors
$ips = $ip_model->get_ip_addresses_of_debtors($debtor_boundary);
// first sql for inserting transfers
$sql_insert = "INSERT INTO messages_ip_addresses " .
"(message_id, ip_address_id, user_id, comment, datetime) VALUES ";
$values = array();
// set new redirections in junction table
foreach($ips as $ip)
{
// insert values
$values[] = "($message->id, $ip->id, $user_id, '', '$datetime')";
$ip_count++;
}
if (count($values) > 0)
{
$sql_insert .= implode(",", $values);
if (!$database->query($sql_insert))
throw new Exception();
}
// activate redirection for finded IP addresses
$s['ip_count'] = $this->_activate_redirection($message, $ips, $user_id);
}
$email_count = 0;
// send emails
if ($email == Notifications_Controller::ACTIVATE)
{
$users_contacts_model = new Users_contacts_Model();
$contacts = $users_contacts_model->get_contacts_of_debtors_by_type(
// find email addresses of debtors
$emails = $uc_model->get_contacts_of_debtors_by_type(
$debtor_boundary, Contact_Model::TYPE_EMAIL
);
$sql_insert = "INSERT INTO email_queues ".
"(`from`, `to`, subject, body, state) VALUES ";
$values = array();
foreach ($contacts as $contact)
{
$text = $message->email_text;
foreach ($contact as $key => $value)
{
if ($key != 'email_text')
$text = str_replace('{'.$key.'}', $value, $text);
}
if ($text == '')
continue;
$values[] = "('".Settings::get('email_default_email')."', '$contact->value', '".
Settings::get('email_subject_prefix').": ".__('Debtor message')."', '$text', 0)";
$email_count++;
}
if (count($values) > 0)
{
$sql_insert .= implode(",", $values);
if (!$database->query($sql_insert))
throw new Exception();
}
// send emails for finded emails
$s['email_count'] = $this->_send_emails($message, $emails, $user_id);
}
return array
(
'ip_count' => $ip_count,
'email_count' => $email_count
);
// send SMS messages
if ($sms == Notifications_Controller::ACTIVATE)
{
// find phone numbers of debtors
$smss = $uc_model->get_contacts_of_debtors_by_type(
$debtor_boundary, Contact_Model::TYPE_PHONE
);
// send SMS messages for finded phone numbers
$s['sms_count'] = $this->_send_sms_messages($message, $smss, $user_id);
}
// return stats array
return $s;
}
/**
* Activates payment notice message to ip addresses of members who have
* low credit.
* @author Jiri Svitak
* @param integer $user_id
* @param integer $payment_notice_boundary
* @param integer $debtor_boundary
* @return int
*
* @author Ondřej Fibich
* @param integer $message_id ID of message
* @param integer $user_id Who redirects
* @param double $payment_notice_boundary
* @param double $debtor_boundary Border of debtor
* @param integer $redirection Redirection state
* @param integer $email E-mail state
* @param integer $sms SMS state
* @return array Stats array
*/
public function activate_payment_notice_message(
$user_id, $payment_notice_boundary, $debtor_boundary, $redirection, $email)
$message_id, $user_id, $payment_notice_boundary,
$debtor_boundary, $redirection, $email, $sms)
{
// user id
$user_id = intval($user_id);
$user_id = ($user_id) ? $user_id : 'NULL';
// preparation
$message = ORM::factory('message')->where(
'type', self::PAYMENT_NOTICE_MESSAGE)->find();
$content = $message->text;
$datetime = date('Y-m-d H:i:s');
$ip_count = 0;
// delete old redirections
$database = Database::instance();
// stats
$s = array
(
'ip_count' => 0,
'email_count' => 0,
'sms_count' => 0
);
// helper models
$ip_model = new Ip_address_Model();
$uc_model = new Users_contacts_Model();
$message = new Message_Model($message_id);
// message do not exists
if (!$message || !$message->id)
{
throw new Exception('Payment notice message not founded');
}
// redirection
if ($redirection == Notifications_Controller::ACTIVATE)
{
$database->delete('messages_ip_addresses', array('message_id' => $message->id));
// finding IP addresses to redirect to debtor message
$ip_model = new Ip_address_Model();
// find IP addresses of debtors
$ips = $ip_model->get_ip_addresses_of_almostdebtors(
$payment_notice_boundary, $debtor_boundary
);
// first sql for inserting transfers
$sql_insert = "INSERT INTO messages_ip_addresses ".
"(message_id, ip_address_id, user_id, comment, datetime) VALUES ";
$values = array();
// set new redirections in junction table
foreach($ips as $ip)
{
// insert values
$values[] = "($message->id, $ip->id, $user_id, '', '$datetime')";
$ip_count++;
}
$sql_insert .= implode(",", $values);
if (!$database->query($sql_insert))
throw new Exception();
// activate redirection for finded IP addresses
$s['ip_count'] = $this->_activate_redirection($message, $ips, $user_id);
}
$email_count = 0;
// send emails
if ($email == Notifications_Controller::ACTIVATE)
{
$users_contacts_model = new Users_contacts_Model();
$contacts = $users_contacts_model->get_contacts_of_almostdebtors_by_type(
// find email addresses of debtors
$emails = $uc_model->get_contacts_of_almostdebtors_by_type(
$payment_notice_boundary, $debtor_boundary,
Contact_Model::TYPE_EMAIL
);
$sql_insert = "INSERT INTO email_queues ".
"(`from`, `to`, subject, body, state) VALUES ";
$values = array();
foreach ($contacts as $contact)
{
$text = $message->email_text;
foreach ($contact as $key => $value)
{
if ($key != 'email_text')
$text = str_replace('{'.$key.'}', $value, $text);
}
if ($text == '')
continue;
$values[] = "('".Settings::get('email_default_email')."', '$contact->value', '".
Settings::get('email_subject_prefix').": ".__('Payment notice')."', '$text', 0)";
$email_count++;
}
if (count($values))
{
$sql_insert .= implode(",", $values);
if (!$database->query($sql_insert))
throw new Exception();
}
// send emails for finded emails
$s['email_count'] = $this->_send_emails($message, $emails, $user_id);
}
return array
(
'ip_count' => $ip_count,
'email_count' => $email_count
);
// send SMS messages
if ($sms == Notifications_Controller::ACTIVATE)
{
// find phone numbers of debtors
$smss = $uc_model->get_contacts_of_almostdebtors_by_type(
$payment_notice_boundary, $debtor_boundary,
Contact_Model::TYPE_PHONE
);
// send SMS messages for finded phone numbers
$s['sms_count'] = $this->_send_sms_messages($message, $smss, $user_id);
}
// return stats array
return $s;
}
/**
* Activates user message by given id
*
* @author Michal Kliment
* @param integer $message_id
* @param integer $user_id
* @return array
* @author Ondřej Fibich
* @param integer $message_id ID of message
* @param integer $user_id Who redirects
* @param integer $redirection Redirection state
* @param integer $email E-mail state
* @param integer $sms SMS state
* @return array Stats array
*/
public function activate_user_message ($message_id, $user_id, $redirection, $email)
public function activate_user_message(
$message_id, $user_id, $redirection, $email, $sms)
{
// user id
$user_id = intval($user_id);
$user_id = ($user_id) ? $user_id : 'NULL';
// preparation
$message = ORM::factory('message')->where(array
(
'id' => $message_id,
'type' => self::USER_MESSAGE
))->find();
// message doesn't exist
if (!$message->id)
// stats
$s = array
(
'ip_count' => 0,
'email_count' => 0,
'sms_count' => 0
);
// helper models
$ip_model = new Ip_address_Model();
$uc_model = new Users_contacts_Model();
$message = new Message_Model($message_id);
// message do not exists
if (!$message || !$message->id)
{
return array
(
'ip_count' => 0,
'email_count' => 0
);
throw new Exception('Message not founded');
}
$content = $message->text;
$datetime = date('Y-m-d H:i:s');
$ip_count = 0;
// delete old redirections
$database = Database::instance();
// redirection
if ($redirection == Notifications_Controller::ACTIVATE)
{
$database->delete('messages_ip_addresses', array('message_id' => $message->id));
// finding IP addresses to redirect to debtor message
$ip_model = new Ip_address_Model();
// find IP addresses of debtors
$ips = $ip_model->find_all();
// first sql for inserting transfers
$sql_insert = "INSERT INTO messages_ip_addresses ".
"(message_id, ip_address_id, user_id, comment, datetime) VALUES ";
$values = array();
// set new redirections in junction table
foreach($ips as $ip)
{
// insert values
$values[] = "($message->id, $ip->id, $user_id, '', '$datetime')";
$ip_count++;
}
$sql_insert .= implode(",", $values);
if (!$database->query($sql_insert))
throw new Exception();
// activate redirection for finded IP addresses
$s['ip_count'] = $this->_activate_redirection($message, $ips, $user_id);
}
$email_count = 0;
// send emails
if ($email == Notifications_Controller::ACTIVATE)
{
$users_contacts_model = new Users_contacts_Model();
$contacts = $users_contacts_model->get_all_contacts_by_type(
// find email addresses of debtors
$emails = $uc_model->get_all_contacts_by_type(
Contact_Model::TYPE_EMAIL, $message->ignore_whitelist
);
$sql_insert = "INSERT INTO email_queues ".
"(`from`, `to`, subject, body, state) VALUES ";
$values = array();
foreach ($contacts as $contact)
{
$text = $message->email_text;
foreach ($contact as $key => $value)
{
if ($key != 'email_text')
$text = str_replace('{'.$key.'}', $value, $text);
}
if ($text == '')
continue;
$values[] = "('".Settings::get('email_default_email')."', '$contact->value', '".Settings::get('email_subject_prefix').": ".$message->name."', '$text', 0)";
$email_count++;
}
if (count($values))
{
$sql_insert .= implode(",", $values);
if (!$database->query($sql_insert))
throw new Exception();
}
// send emails for finded emails
$s['email_count'] = $this->_send_emails($message, $emails, $user_id);
}
return array
(
'ip_count' => $ip_count,
'email_count' => $email_count
);
// send SMS messages
if ($sms == Notifications_Controller::ACTIVATE)
{
// find phone numbers of debtors
$smss = $uc_model->get_all_contacts_by_type(
Contact_Model::TYPE_PHONE, $message->ignore_whitelist
);
// send SMS messages for finded phone numbers
$s['sms_count'] = $this->_send_sms_messages($message, $smss, $user_id);
}
// return stats array
return $s;
}
/**
* Deactivates all redirections of given message.
*
* @author Jiri Svitak
* @param <type> $message_id
* @param integer $message_id
*/
public function deactivate_message($message_id)
{
$message_id = intval($message_id);
$this->db->query("DELETE FROM messages_ip_addresses WHERE message_id = ".$message_id);
$this->db->query("
DELETE FROM messages_ip_addresses
WHERE message_id = ?
", $message_id);
}
/**
......
public function get_message_id_by_type ($type)
{
if (!$type)
{
return NULL;
}
$message = $this->where('type', $type)->find();
if ($message->id)
{
return $message->id;
}
else
{
return NULL;
}
}
/**
* Activate redirection for given IPs
*
* @param Message_Model $message Message to redirect
* @param Mysql_Result $ips IPs to redirect
* @param mixed $user_id ID of who added redirection or NULL
* @return integer Number of redirected IPs
* @throws Exception On error
*/
private function _activate_redirection(
Message_Model $message, $ips, $user_id = NULL)
{
// preparations
$datetime = date('Y-m-d H:i:s');
$user_id = (intval($user_id)) ? intval($user_id) : 'NULL';
// ip count stats
$ip_count = 0;
// delete old redirections
$this->db->delete('messages_ip_addresses', array
(
'message_id' => $message->id
));
// first sql for inserting transfers
$sql_insert = "INSERT INTO messages_ip_addresses "
. "(message_id, ip_address_id, user_id, comment, datetime) "
. "VALUES ";
$values = array();
// set new redirections in junction table
foreach($ips as $ip)
{
// insert values
$values[] = "($message->id, $ip->id, $user_id, '', '$datetime')";
$ip_count++;
}
// any redirection?
if (count($values) > 0)
{
$sql_insert .= implode(',', $values);
if (!$this->db->query($sql_insert))
{
throw new Exception();
}
}
return $ip_count;
}
/**
* Send emails with redirection message to given contacts
*
* @param Message_Model $message Message to send
* @param Mysql_Result $contacts Contacts to send
* @return integer Number of sended emails
* @throws Exception On error
*/
private function _send_emails(Message_Model $message, $contacts)
{
// emails counter
$email_count = 0;
// if default email ans subject prefix is set
if (!Settings::get('email_default_email') ||
!Settings::get('email_subject_prefix'))
{
throw new Exception('Email not configured properly');
}
// continue
try
{
// Email queues model
$eq_model = new Email_queue_Model();
// start transaction
$eq_model->transaction_start();
// for each contact
foreach ($contacts as $contact)
{
// text of message
$text = $message->email_text;
// replace tags
foreach ($contact as $key => $value)
{
if ($key != 'email_text' && $key != 'country_code')
{
$text = str_replace('{'.$key.'}', $value, $text);
}
}
// if empty message do not send
if (empty($text))
{
continue;
}
// subject
$subject = Settings::get('email_subject_prefix')
. ': ' . __($message->name);
// add Email to queue
$eq_model->clear();
$eq_model->from = Settings::get('email_default_email');
$eq_model->to = $contact->value;
$eq_model->subject = $subject;
$eq_model->body = $text;
$eq_model->state = Email_queue_Model::STATE_NEW;
$eq_model->save_throwable();
// add SMS to counter
$email_count++;
}
// commit
$eq_model->transaction_commit();
}
catch (Exception $e)
{
$eq_model->transaction_rollback();
throw $e;
}
return $email_count;
}
/**
* Send SMS messages with redirection message to given contacts
*
* @param Message_Model $message Message to send
* @param Mysql_Result $contacts Contacts to send
* @param mixed $user_id ID of who added redirection or NULL
* @return integer Number of sended SMS
* @throws Exception On error
*/
private function _send_sms_messages(
Message_Model $message, $contacts, $user_id = NULL)
{
// preparations
$datetime = date('Y-m-d H:i:s');
$user_id = (intval($user_id)) ? intval($user_id) : 'NULL';
// ip count stats
$sms_count = 0;
// if SMS enabled, is any active SMS driver
// SMS sender number is set and SMS default driver is set
if (!Sms::enabled() ||
!Sms::has_active_driver() ||
!Settings::get('sms_sender_number') ||
!Settings::get('sms_driver'))
{
throw new Exception('SMS not active');
}
// continue
try
{
// SMS model
$sms = new Sms_message_Model();
// start transaction
$sms->transaction_start();
// for each contact
foreach ($contacts as $contact)
{
// text of message
$text = $message->sms_text;
// number
$number = $contact->country_code . $contact->value;
// replace tags
foreach ($contact as $key => $value)
{
if ($key != 'sms_text' && $key != 'country_code')
{
$text = str_replace('{'.$key.'}', $value, $text);
}
}
// if empty message or invalid number for sending SMS do not send
if (empty($text) || !Phone_operator_Model::is_sms_enabled_for($number))
{
continue;
}
// create header for message
$text = Settings::get('email_subject_prefix')
. ' - ' . __($message->name)
. ': ' . $text;
// add SMS
$sms->clear();
$sms->user_id = $user_id;
$sms->sms_message_id = NULL;
$sms->stamp = $datetime;
$sms->send_date = $datetime;
$sms->text = text::cs_utf2ascii($text);
$sms->sender = Settings::get('sms_sender_number');
$sms->receiver = $number;
$sms->driver = Settings::get('sms_driver');
$sms->type = Sms_message_Model::SENT;
$sms->state = Sms_message_Model::SENT_UNSENT;
$sms->save_throwable();
// add SMS to counter
$sms_count++;
}
// end transaction
$sms->transaction_commit();
}
catch (Exception $e)
{
$sms->transaction_rollback();
throw $e;
}
return $sms_count;
}
}
freenetis/branches/testing/application/models/users_contacts.php
*/
/**
* Pivot table for connecting users and theirs contacts, also containts
* whitelisted column for defining whitelist of contact in notification.
*
* @package Model
*/
class Users_contacts_Model extends Model
{
/** Contact is not whitelisted */
const NO_WHITELIST = 0;
/** Contact is under pernament whitelisted */
const PERMANENT_WHITELIST = 1;
/** Contact is under temporary whitelisted */
const TEMPORARY_WHITELIST = 2;
/**
* Sets whitelist flag for member's conntact
*
......
* Returns all contacts of debtors by type
*
* @author Michal Kliment
* @param integer $debtor_boundary
* @param double $debtor_boundary
* @param integer $type
* @return MySQL iteraor
*/
public function get_contacts_of_debtors_by_type(
$debtor_boundary, $type)
public function get_contacts_of_debtors_by_type($debtor_boundary, $type)
{
return $this->db->query("
SELECT
c.value, a.balance, m.id AS member_id, m.name AS member_name,
m.variable_symbol, u.login
c.value, a.balance, m.id AS member_id, m.name AS member_name,
m.variable_symbol, u.login, cou.country_code
FROM members m
JOIN accounts a ON a.member_id = m.id AND m.id <> 1
JOIN users u ON u.member_id = m.id
JOIN users_contacts uc ON uc.user_id = u.id
JOIN contacts c ON uc.contact_id = c.id AND c.type = ?
LEFT JOIN contacts_countries cc ON cc.contact_id = c.id
LEFT JOIN countries cou ON cou.id = cc.country_id
WHERE uc.whitelisted = ? AND m.type <> ? AND m.id NOT IN
(
SELECT m.id
......
* Returns all contacts of almost-debtors
*
* @author Michal Kliment
* @param integer $payment_notice_boundary
* @param integer $debtor_boundary
* @param double $payment_notice_boundary
* @param double $debtor_boundary
* @param integer $type
* @return MySQL iterator
*/
public function get_contacts_of_almostdebtors_by_type(
$payment_notice_boundary, $debtor_boundary, $type)
$payment_notice_boundary, $debtor_boundary, $type)
{
return $this->db->query("
SELECT
c.value, a.balance, m.id AS member_id, m.name AS member_name,
m.variable_symbol, u.login
m.variable_symbol, u.login, cou.country_code
FROM members m
JOIN accounts a ON a.member_id = m.id AND m.id <> 1
JOIN users u ON u.member_id = m.id
JOIN users_contacts uc ON uc.user_id = u.id
JOIN contacts c ON uc.contact_id = c.id AND c.type = ?
JOIN contacts_countries cc ON cc.contact_id = c.id
JOIN countries cou ON cou.id = cc.country_id
WHERE uc.whitelisted = ? AND m.type <> ? AND m.id NOT IN
(
SELECT m.id
......
* @return MySQL iterator
*/
public function get_contacts_by_subnet_and_type (
$subnet_id, $type, $ignore_whitelisted = FALSE)
$subnet_id, $type, $ignore_whitelisted = FALSE)
{
if ($ignore_whitelisted)
$whitelisted = "";
......
* @return MySQL iterator
*/
public function get_contacts_by_member_and_type (
$member_id, $type, $ignore_whitelisted = FALSE)
$member_id, $type, $ignore_whitelisted = FALSE)
{
if ($ignore_whitelisted)
$whitelisted = "";
......
* @param bool $ignore_whitelisted
* @return MySQL iterator
*/
public function get_all_contacts_by_type (
$type, $ignore_whitelisted = FALSE)
public function get_all_contacts_by_type ($type, $ignore_whitelisted = FALSE)
{
if ($ignore_whitelisted)
$whitelisted = "";
......
return $this->db->query("
SELECT c.value, a.balance, m.id AS member_id, m.name AS member_name,
m.variable_symbol, u.login
m.variable_symbol, u.login, cou.country_code
FROM contacts c
JOIN users_contacts uc ON uc.contact_id = c.id $whitelisted
JOIN users u ON uc.user_id = u.id
JOIN members m ON u.member_id = m.id
JOIN accounts a ON a.member_id = m.id
LEFT JOIN contacts_countries cc ON cc.contact_id = c.id
LEFT JOIN countries cou ON cou.id = cc.country_id
WHERE m.type <> ? AND c.type = ?
", array(Member_Model::TYPE_FORMER, $type));
}
freenetis/branches/testing/application/models/phone_operator.php
// trim number
$number = trim($phone_number);
// valid number?
if (empty($number) || !is_numeric($number))
{
return FALSE;
}
// find country
if (($country = $country_m->find_phone_country($number)) == FALSE)
{
freenetis/branches/testing/application/models/sms_message.php
*/
class Sms_message_Model extends ORM
{
//// type conctansts
//// type constansts
const RECEIVED = 0;
const SENT = 1;
freenetis/branches/testing/application/controllers/email_queues.php
'filter' => $filter_form
));
$grid->add_new_button('email_queues/show_all_sent', __('Show all sent e-mails'));
$grid->add_new_button(
'email_queues/show_all_sent', __('Show all sent e-mails')
);
$grid->add_new_button(
'email_queues/delete_unsended', __('Delete all unsended e-mails')
);
// database columns
$grid->order_field('id')
......
'email_queues/show_all_unsent', __('Show all unsent e-mails')
);
$grid->add_new_button(
'email_queues/delete_unsended', __('Delete all unsended e-mails')
);
// database columns
$grid->order_field('id')
......
*/
public function send($email_queue_id = NULL)
{
// access check
if (!$this->acl_check_view('Settings_Controller', 'system'))
Controller::error(ACCESS);
// bad parameter
if (!$email_queue_id || !is_numeric($email_queue_id))
Controller::warning(PARAMETER);
......
*/
public function delete($email_queue_id = NULL)
{
// access check
if (!$this->acl_check_view('Settings_Controller', 'system'))
Controller::error(ACCESS);
// bad parameter
if (!$email_queue_id || !is_numeric($email_queue_id))
Controller::warning(PARAMETER);
......
url::redirect('email_queues/show_all_unsent');
}
/**
* Deletes all unsended emails
*
* @author Ondřej Fibich
*/
public function delete_unsended()
{
// access
if (!$this->acl_check_view('Settings_Controller', 'system'))
{
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_sent');
}
}
freenetis/branches/testing/application/controllers/scheduler.php
}
// send emails
try
{
self::send_quened_emails();
......
/**
* Function sends SMS messages from db queue.
* Sends 30 SMS messages by one call.
*
* @author Ondrej Fibich, Roman Sevcik
*/
......
(
'type' => Sms_message_Model::SENT,
'state' => Sms_message_Model::SENT_UNSENT
))->where('send_date < CURRENT_TIMESTAMP')->limit(10)->find_all();
))->where('send_date < CURRENT_TIMESTAMP')->limit(30)->find_all();
// no SMS unsended => bye bye!
if (!count($unsent_messages))
freenetis/branches/testing/application/controllers/messages.php
->rows(5)
->cols(100)
->value($message->email_text);
$form->textarea('sms_text')
->label(__('Content of the message for SMS').':&nbsp;'.
help::hint('content_of_message'))
->rules('length[1,760]')
->style('width: 650px; height: 150px')
->value($message->sms_text);
}
$form->submit('submit')
->value(__('Edit'));
$form->submit('Edit');
special::required_forge_style($form, ' *', 'required');
if ($form->validate())
{
$form_data = $form->as_array();
if ($message->type == 0)
{
$message->name = $form_data['name'];
......
$message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE)
{
$message->email_text = $form_data['email_text'];
// email text
$email_text = trim($form_data['email_text']);
$email_text = empty($email_text) ? NULL : $email_text;
// sms text
$sms_text = trim(text::cs_utf2ascii(strip_tags($form_data['sms_text'])));
$sms_text = empty($sms_text) ? NULL : $sms_text;
// set vars
$message->email_text = $email_text;
$message->sms_text = $sms_text;
}
unset($form_data);
......
}
// preparation
$message = new Message_Model($message_id);
if (!$message || !$message->id)
{
Controller::error(RECORD);
}
$this->message_id = $message_id;
$this->message_id = $message->id;
$dropdown_options = array
(
Notifications_Controller::ACTIVATE => __('Activate'),
Notifications_Controller::KEEP => __('Without change')
);
$form = new Forge(url::base(TRUE) . url::current(TRUE));
$form->dropdown('redirection')
->label(__('Redirection').':')
->options(array
(
Notifications_Controller::ACTIVATE => __('Activate'),
Notifications_Controller::KEEP => __('Without change')
))
->options($dropdown_options)
->selected(Notifications_Controller::KEEP);
$form->dropdown('email')
->label(__('E-mail').':')
->options(array
(
Notifications_Controller::ACTIVATE => __('Activate'),
Notifications_Controller::KEEP => __('Without change')
))
->options($dropdown_options)
->selected(Notifications_Controller::KEEP)
->callback(array($this,'valid_email'));
->callback(array($this, 'valid_email_or_sms'));
$form->dropdown('sms')
->label(__('SMS').':')
->options($dropdown_options)
->selected(Notifications_Controller::KEEP)
->callback(array($this, 'valid_email_or_sms'));
$form->submit('Send');
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff