Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1272

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

Novinky:

- upozornovani pro clena, podsit a oblast pomoci SMS

Upravy:

- prepsani metod pro aktivaci upozornovani v controlleru Notification

Zobrazit rozdíly:

freenetis/branches/testing/application/i18n/cs_CZ/texts.php
'delete_member' => 'Smazat tohoto člena',
'delete_work' => 'Smazat tuto práci',
'delete' => 'Smazat',
'delete all unsended e-mails' => 'Smazat všechny neposlané emaily',
'delete all unsended e-mails' => 'Smazat všechny neodeslané 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 unsended messages' => 'Smazat neodeslané zprávy',
'delete whole device' => 'Smazat celé zařízení',
'delete wireless setting' => 'Smazat bezdrátové nastavení',
'deleted' => 'Smazáno',
......
'smokeping record has been successfully added' => 'Záznam smokepingu byl úspěšně přidán',
'smokeping record has been successfully deleted' => 'Záznam smokepingu byl úspěšně smazán',
'smokeping record has been successfully updated' => 'Záznam smokepingu byl úspěšně aktualizován',
'sms message' => 'SMS zpráva',
'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 message has been sent for %d phone numbers' => 'SMS zpráva 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.',
freenetis/branches/testing/application/vendors/unit_tester/unit_testing_config.xml
</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>
......
<method name="get_transaction_code_duplicities" autogenerate="on">
<attributes>
<attribute name="transaction_codes" default_value="" />
<attribute name="bank_account_id" default_value="" />
</attributes>
<values>
<input>
<param value="" />
<param value="" />
</input>
</values>
</method>
freenetis/branches/testing/application/models/cloud.php
* Model of cloud which can be managed by admins and contains subnets
*
* @package Model
*
* @property integer $id
* @property string $name
* @property ORM_Iterator $subnets
* @property ORM_Iterator $users
*/
class Cloud_Model extends ORM
{
protected $has_and_belongs_to_many = array('subnets', 'users');
public $arr_sql = array
(
'id' => 'c.id',
'name' => 'c.name'
);
/**
* Function gets all cloud's names and ids
*
* @author Ondřej Fibich
* @return unknown_type
* @return Mysql_Result
*/
public function get_all_clouds()
{
......
* Gets admins of cloud
*
* @param integer $cloud_id
* @return unknown_type
* @return Mysql_Result
*/
public function get_cloud_admins($cloud_id = NULL)
{
......
* Gets subnets of cloud
*
* @param integer $cloud_id
* @return unknown_type
* @return Mysql_Result
*/
public function get_cloud_subnets($cloud_id = NULL)
{
freenetis/branches/testing/application/models/message.php
$ips = $ip_model->get_ip_addresses_with_interrupted_membership();
// activate
return $this->_activate_redirection($message, $ips, $user_id);
return self::activate_redirection($message, $ips, $user_id);
}
/**
......
$ips = $ip_model->get_ip_addresses_with_unallowed_connecting_place();
// activate
return $this->_activate_redirection($message, $ips, $user_id);
return self::activate_redirection($message, $ips, $user_id);
}
......
// find IP addresses of debtors
$ips = $ip_model->get_ip_addresses_of_debtors($debtor_boundary);
// activate redirection for finded IP addresses
$s['ip_count'] = $this->_activate_redirection($message, $ips, $user_id);
$s['ip_count'] = self::activate_redirection($message, $ips, $user_id);
}
// send emails
......
$debtor_boundary, Contact_Model::TYPE_EMAIL
);
// send emails for finded emails
$s['email_count'] = $this->_send_emails($message, $emails, $user_id);
$s['email_count'] = self::send_emails($message, $emails);
}
// send SMS messages
......
$debtor_boundary, Contact_Model::TYPE_PHONE
);
// send SMS messages for finded phone numbers
$s['sms_count'] = $this->_send_sms_messages($message, $smss, $user_id);
$s['sms_count'] = self::send_sms_messages($message, $smss, $user_id);
}
// return stats array
......
$payment_notice_boundary, $debtor_boundary
);
// activate redirection for finded IP addresses
$s['ip_count'] = $this->_activate_redirection($message, $ips, $user_id);
$s['ip_count'] = self::activate_redirection($message, $ips, $user_id);
}
// send emails
......
Contact_Model::TYPE_EMAIL
);
// send emails for finded emails
$s['email_count'] = $this->_send_emails($message, $emails, $user_id);
$s['email_count'] = self::send_emails($message, $emails);
}
// send SMS messages
......
Contact_Model::TYPE_PHONE
);
// send SMS messages for finded phone numbers
$s['sms_count'] = $this->_send_sms_messages($message, $smss, $user_id);
$s['sms_count'] = self::send_sms_messages($message, $smss, $user_id);
}
// return stats array
......
// find IP addresses of debtors
$ips = $ip_model->find_all();
// activate redirection for finded IP addresses
$s['ip_count'] = $this->_activate_redirection($message, $ips, $user_id);
$s['ip_count'] = self::activate_redirection($message, $ips, $user_id);
}
// send emails
......
Contact_Model::TYPE_EMAIL, $message->ignore_whitelist
);
// send emails for finded emails
$s['email_count'] = $this->_send_emails($message, $emails, $user_id);
$s['email_count'] = self::send_emails($message, $emails);
}
// send SMS messages
......
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);
$s['sms_count'] = self::send_sms_messages($message, $smss, $user_id);
}
// return stats array
......
* @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
* @param string $comment Comment
* @return integer Number of redirected IPs
* @throws Exception On error
*/
private function _activate_redirection(
Message_Model $message, $ips, $user_id = NULL)
public static function activate_redirection(
Message_Model $message, $ips, $user_id = NULL, $comment = NULL)
{
// param check
if (!$message->id || !is_object($ips))
{
throw new Exception('Wrong args');
}
// preparations
$datetime = date('Y-m-d H:i:s');
$user_id = (intval($user_id)) ? intval($user_id) : 'NULL';
$comment = Database::instance()->escape($comment);
// ip count stats
$ip_count = 0;
// delete old redirections
$this->db->delete('messages_ip_addresses', array
Database::instance()->delete('messages_ip_addresses', array
(
'message_id' => $message->id
));
......
foreach($ips as $ip)
{
// insert values
$values[] = "($message->id, $ip->id, $user_id, '', '$datetime')";
$values[] = "($message->id, $ip->id, $user_id, $comment, '$datetime')";
$ip_count++;
}
......
{
$sql_insert .= implode(',', $values);
if (!$this->db->query($sql_insert))
if (!Database::instance()->query($sql_insert))
{
throw new Exception();
}
......
*
* @param Message_Model $message Message to send
* @param Mysql_Result $contacts Contacts to send
* @param string $comment Comment
* @return integer Number of sended emails
* @throws Exception On error
*/
private function _send_emails(Message_Model $message, $contacts)
public static function send_emails(
Message_Model $message, $contacts, $comment = NULL)
{
// param check
if (!$message->id || !is_object($contacts))
{
throw new Exception('Wrong args');
}
// emails counter
$email_count = 0;
......
$text = str_replace('{'.$key.'}', $value, $text);
}
}
// replace comment
$text = str_replace('{comment}', $comment, $text);
// if empty message do not send
if (empty($text))
......
* @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
* @param string $comment Comment
* @return integer Number of sended SMS
* @throws Exception On error
*/
private function _send_sms_messages(
Message_Model $message, $contacts, $user_id = NULL)
public static function send_sms_messages(
Message_Model $message, $contacts, $user_id = NULL, $comment = NULL)
{
// param check
if (!$message->id || !is_object($contacts))
{
throw new Exception('Wrong args');
}
// preparations
$datetime = date('Y-m-d H:i:s');
$user_id = (intval($user_id)) ? intval($user_id) : 'NULL';
$comment = strip_tags($comment);
// ip count stats
$sms_count = 0;
......
$text = str_replace('{'.$key.'}', $value, $text);
}
}
// replace comment
$text = str_replace('{comment}', $comment, $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();
freenetis/branches/testing/application/models/users_contacts.php
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
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
......
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
(
SELECT
......
JOIN users u ON u.member_id = m.id
JOIN users_contacts uc ON uc.user_id = u.id $whitelisted
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 m.id NOT IN
(
SELECT m.id
......
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
JOIN users u ON u.member_id = m.id
JOIN users_contacts uc ON uc.user_id = u.id $whitelisted
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 m.id = ? AND m.type <> ? AND m.id NOT in
(
SELECT m.id
freenetis/branches/testing/application/controllers/notifications.php
/**
* Controller performs notifications actions.
* Informs user of system using redirection or email about some action or change.
* Informs user of system using redirection, SMS or email about some action or change.
*
* @package Controller
* @author Michal Kliment
*/
class Notifications_Controller extends Controller
{
// activate notification
/** activate notification */
const ACTIVATE = 1;
// keep current settings
/** keep current settings */
const KEEP = 2;
// deactivate notification
/** deactivate notification */
const DEACTIVATE = 3;
/**
......
$headline = __('Notification setting of member').' '.$member->name;
// gets all user messages
$messages = ORM::factory('message')
->find_all();
$messages = ORM::factory('message')->find_all();
$arr_messages = array();
foreach ($messages as $message)
{
if ($message->type == Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE ||
......
$form = new Forge('notifications/member/'.$member->id);
$form->dropdown('message_id')
->label(__('Message').":")
->label(__('Message').':')
->options($arr_messages)
->rules('required');
......
self::KEEP => __('Without change')
))
->selected(self::KEEP)
->callback(array($this,'valid_email'));
->callback(array($this,'valid_email_or_sms'));
$form->dropdown('sms')
->label(__('SMS message').':')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change')
))
->selected(self::KEEP)
->callback(array($this,'valid_email_or_sms'));
$form->submit('Send');
special::required_forge_style($form, ' *', 'required');
// for is validate
// form is validate
if ($form->validate())
{
$form_data = $form->as_array();
// needed class
$message = new Message_Model($form_data['message_id']);
$ip_model = new Ip_address_Model();
$mia_model = new Messages_ip_addresses_Model();
$uc_model = new Users_contacts_Model();
// needed data
$user_id = $this->session->get('user_id');
$comment = $form_data['comment'];
$info_messages = array();
// redirection
switch ($form_data['redirection'])
/* Redirection */
if ($form_data['redirection'] == self::ACTIVATE ||
$form_data['redirection'] == self::DEACTIVATE)
{
case self::ACTIVATE:
case self::DEACTIVATE:
$messages_ip_addresses_model = new Messages_ip_addresses_Model();
$deleted_redirections = 0;
$added_redirections = 0;
// finds all ip addresses of subnet
$ip_addresses = ORM::factory('ip_address')
->get_ip_addresses_of_member($member->id);
foreach ($ip_addresses as $ip_address)
{
// allways deletes all redirection of ip address
$deleted_redirections += $messages_ip_addresses_model
->delete_redirection_of_ip_address($message->id, $ip_address->id);
// activation => adds new redirection to ip address
if ($form_data['redirection'] == self::ACTIVATE)
{
$added_redirections += $messages_ip_addresses_model
->add_redirection_to_ip_address(
$message->id, $ip_address->id,
$form_data['comment']);
}
}
if ($added_redirections)
{
$info_messages[] = __('Redirection has been activated for %s IP addresses', $added_redirections).'.';
}
else
{
$info_messages[] = __('Redirection has been deactivated for %s IP addresses', $deleted_redirections).'.';
}
break;
// stats vars
$deleted_redr = 0;
$added_redr = 0;
// get all redirection
$ips = $ip_model->get_ip_addresses_of_member($member->id);
// delete redirection of these IP address
foreach ($ips as $ip)
{
$mia_model->delete_redirection_of_ip_address(
$message->id, $ip->id
);
$deleted_redr++;
}
// set new redirection?
if ($form_data['redirection'] == self::ACTIVATE)
{
$added_redr = Message_Model::activate_redirection(
$message, $ips,
$user_id, $comment
);
}
// info messages
if ($added_redr)
{
$m = 'Redirection has been activated for %s IP addresses';
$info_messages[] = __($m, $added_redr).'.';
}
else
{
$m = 'Redirection has been deactivated for %s IP addresses';
$info_messages[] = __($m, $deleted_redr).'.';
}
}
// e-mail
switch ($form_data['email'])
/* Email */
if ($form_data['email'] == self::ACTIVATE)
{
case self::ACTIVATE:
$sent_emails = 0;
$email_queue_model = new Email_queue_Model();
$users_contacts_model = new Users_contacts_Model();
// gets all e-mails of subnet
$contacts = $users_contacts_model->get_contacts_by_member_and_type(
$member->id, Contact_Model::TYPE_EMAIL,
$message->ignore_whitelist
);
$name = $message->name;
if ($message->type)
{
$name = __($message->name);
}
foreach ($contacts as $contact)
{
$text = $message->email_text;
foreach ($contact as $key => $value)
{
if ($key != 'email_text')
{
$text = str_replace('{'.$key.'}', $value, $text);
}
}
$email_queue_model->clear();
$email_queue_model->from = Settings::get('email_default_email');
$email_queue_model->to = $contact->value;
$email_queue_model->subject = Settings::get('email_subject_prefix').": ".$name;
$email_queue_model->body = $text;
$email_queue_model->state = Email_queue_Model::STATE_NEW;
// sends e-mail
if ($email_queue_model->save())
{
$sent_emails++;
}
}
$info_messages[] = __('E-mail has been sent for %s e-mail addresses', $sent_emails).'.';
break;
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_member_and_type(
$member->id, Contact_Model::TYPE_EMAIL,
$message->ignore_whitelist
);
// send email
$sent_emails = Message_Model::send_emails(
$message, $contacts, $comment
);
// info message
$m = 'E-mail has been sent for %s e-mail addresses';
$info_messages[] = __($m, $sent_emails).'.';
}
status::success(implode('<br />', $info_messages), FALSE);
/* SMS messages */
if ($form_data['sms'] == self::ACTIVATE)
{
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_member_and_type(
$member->id, Contact_Model::TYPE_PHONE,
$message->ignore_whitelist
);
// send email
$sent_sms = Message_Model::send_sms_messages(
$message, $contacts,
$user_id, $comment
);
// info message
$m = 'SMS message has been sent for %d phone numbers.';
$info_messages[] = __($m, $sent_sms);
}
// user notification
if (count($info_messages))
{
status::success(implode('<br />', $info_messages), FALSE);
}
// redirect
url::redirect('members/show/'.$member->id);
}
......
->link('members/show/'.$member->id,
"ID $member->id - $member->name",
$this->acl_check_view(
'Members_Controller','members', $member->id
'Members_Controller', 'members', $member->id
)
)
->text(__('Notification setting'));
->enable_translation()
->text('Notification setting');
$view = new View('main');
$view->breadcrumbs = $breadcrumbs;
......
->find_all();
$arr_messages = array();
foreach ($messages as $message)
{
if ($message->type == Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE ||
......
$form = new Forge('notifications/subnet/'.$subnet->id);
$form->dropdown('message_id')
->label(__('Message').":")
->label(__('Message').':')
->options($arr_messages)
->rules('required');
......
self::KEEP => __('Without change')
))
->selected(self::KEEP)
->callback(array($this,'valid_email'));
->callback(array($this, 'valid_email_or_sms'));
$form->submit('submit')
->value(__('Send'));
$form->dropdown('sms')
->label(__('SMS message').':')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change')
))
->selected(self::KEEP)
->callback(array($this,'valid_email_or_sms'));
$form->submit('Send');
special::required_forge_style($form, ' *', 'required');
// for is validate
......
{
$form_data = $form->as_array();
// needed class
$message = new Message_Model($form_data['message_id']);
$ip_model = new Ip_address_Model();
$mia_model = new Messages_ip_addresses_Model();
$uc_model = new Users_contacts_Model();
// needed data
$user_id = $this->session->get('user_id');
$comment = $form_data['comment'];
$info_messages = array();
// redirection
switch ($form_data['redirection'])
/* Redirection */
if ($form_data['redirection'] == self::ACTIVATE ||
$form_data['redirection'] == self::DEACTIVATE)
{
case self::ACTIVATE:
case self::DEACTIVATE:
$messages_ip_addresses_model = new Messages_ip_addresses_Model();
$deleted_redirections = 0;
$added_redirections = 0;
// finds all ip addresses of subnet
$ip_addresses = ORM::factory('ip_address')
->get_ip_addresses_of_subnet($subnet->id);
foreach ($ip_addresses as $ip_address)
{
// allways deletes all redirection of ip address
$deleted_redirections += $messages_ip_addresses_model
->delete_redirection_of_ip_address($message->id, $ip_address->id);
// activation => adds new redirection to ip address
if ($form_data['redirection'] == self::ACTIVATE)
{
$added_redirections += $messages_ip_addresses_model
->add_redirection_to_ip_address(
$message->id, $ip_address->id,
$form_data['comment']
);
}
}
if ($added_redirections)
{
$info_messages[] = __('Redirection has been activated for %s IP addresses', $added_redirections).'.';
}
else
{
$info_messages[] = __('Redirection has been deactivated for %s IP addresses', $deleted_redirections).'.';
}
break;
// stats vars
$deleted_redr = 0;
$added_redr = 0;
// get all redirection
$ips = $ip_model->get_ip_addresses_of_subnet($subnet->id);
// delete redirection of these IP address
foreach ($ips as $ip)
{
$mia_model->delete_redirection_of_ip_address(
$message->id, $ip->id
);
$deleted_redr++;
}
// set new redirection?
if ($form_data['redirection'] == self::ACTIVATE)
{
$added_redr = Message_Model::activate_redirection(
$message, $ips,
$user_id, $comment
);
}
// info messages
if ($added_redr)
{
$m = 'Redirection has been activated for %s IP addresses';
$info_messages[] = __($m, $added_redr).'.';
}
else
{
$m = 'Redirection has been deactivated for %s IP addresses';
$info_messages[] = __($m, $deleted_redr).'.';
}
}
// e-mail
switch ($form_data['email'])
/* Email */
if ($form_data['email'] == self::ACTIVATE)
{
case self::ACTIVATE:
$sent_emails = 0;
$email_queue_model = new Email_queue_Model();
$users_contacts_model = new Users_contacts_Model();
// gets all e-mails of subnet
$contacts = $users_contacts_model
->get_contacts_by_subnet_and_type(
$subnet->id, Contact_Model::TYPE_EMAIL,
$message->ignore_whitelist
);
foreach ($contacts as $contact)
{
$text = $message->email_text;
foreach ($contact as $key => $value)
{
if ($key != 'email_text')
$text = str_replace('{'.$key.'}', $value, $text);
}
$email_queue_model->clear();
$email_queue_model->from = Settings::get('email_default_email');
$email_queue_model->to = $contact->value;
$email_queue_model->subject = Settings::get('email_subject_prefix').": ".$message->name;
$email_queue_model->body = $text;
$email_queue_model->state = Email_queue_Model::STATE_NEW;
// sends e-mail
if ($email_queue_model->save())
$sent_emails++;
}
$info_messages[] = __('E-mail has been sent for %s e-mail addresses', $sent_emails).'.';
break;
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_subnet_and_type(
$subnet->id, Contact_Model::TYPE_EMAIL,
$message->ignore_whitelist
);
// send email
$sent_emails = Message_Model::send_emails(
$message, $contacts, $comment
);
// info message
$m = 'E-mail has been sent for %s e-mail addresses';
$info_messages[] = __($m, $sent_emails).'.';
}
status::success(implode("<br />", $info_messages), FALSE);
/* SMS messages */
if ($form_data['sms'] == self::ACTIVATE)
{
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_subnet_and_type(
$subnet->id, Contact_Model::TYPE_PHONE,
$message->ignore_whitelist
);
// send email
$sent_sms = Message_Model::send_sms_messages(
$message, $contacts,
$user_id, $comment
);
// info message
$m = 'SMS message has been sent for %d phone numbers.';
$info_messages[] = __($m, $sent_sms);
}
// user notification
if (count($info_messages))
{
status::success(implode('<br />', $info_messages), FALSE);
}
// redirect
url::redirect('subnets/show/'.$subnet->id);
}
......
->link('subnets/show/'.$subnet->id, $subnet_text,
$this->acl_check_view('Devices_Controller','subnet'))
->enable_translation()
->text(__('Notification setting'))
->text('Notification setting')
->html();
$view = new View('main');
......
$headline = __('Notification setting of cloud').' '.$cloud->name;
// gets all user messages
$messages = ORM::factory('message')
->find_all();
$messages = ORM::factory('message')->find_all();
$arr_messages = array();
foreach ($messages as $message)
{
if ($message->type == Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE ||
......
$form = new Forge('notifications/cloud/'.$cloud->id);
$form->dropdown('message_id')
->label(__('Message').":")
->label(__('Message').':')
->options($arr_messages)
->rules('required');
......
self::KEEP => __('Without change')
))
->selected(self::KEEP)
->callback(array($this,'valid_email'));
->callback(array($this,'valid_email_or_sms'));
$form->dropdown('sms')
->label(__('SMS message').':')
->options(array
(
self::ACTIVATE => __('Activate'),
self::KEEP => __('Without change')
))
->selected(self::KEEP)
->callback(array($this,'valid_email_or_sms'));
$form->submit('Send');
special::required_forge_style($form, ' *', 'required');
......
{
$form_data = $form->as_array();
// needed class
$message = new Message_Model($form_data['message_id']);
$ip_model = new Ip_address_Model();
$mia_model = new Messages_ip_addresses_Model();
$uc_model = new Users_contacts_Model();
// needed data
$user_id = $this->session->get('user_id');
$comment = $form_data['comment'];
$info_messages = array();
// redirection
switch ($form_data['redirection'])
/* Redirection */
if ($form_data['redirection'] == self::ACTIVATE ||
$form_data['redirection'] == self::DEACTIVATE)
{
case self::ACTIVATE:
case self::DEACTIVATE:
$messages_ip_addresses_model = new Messages_ip_addresses_Model();
$deleted_redirections = 0;
$added_redirections = 0;
// for each subnet of cloud
foreach ($cloud->subnets as $subnet)
// stats vars
$deleted_redr = 0;
$added_redr = 0;
// for each subnet in cloud
foreach ($cloud->subnets as $subnet)
{
// get all redirection
$ips = $ip_model->get_ip_addresses_of_subnet($subnet->id);
// delete redirection of these IP address
foreach ($ips as $ip)
{
// gets all ip addresses of subnet
$ip_addresses = ORM::factory('ip_address')
->get_ip_addresses_of_subnet($subnet->id);
foreach ($ip_addresses as $ip_address)
{
// allways deletes redirection of ip address
$deleted_redirections += $messages_ip_addresses_model
->delete_redirection_of_ip_address($message->id, $ip_address->id);
// activation => adds new redirection to ip address
if ($form_data['redirection'] == self::ACTIVATE)
{
$added_redirections += $messages_ip_addresses_model
->add_redirection_to_ip_address(
$message->id, $ip_address->id,
$form_data['comment']
);
}
}
$mia_model->delete_redirection_of_ip_address(
$message->id, $ip->id
);
$deleted_redr++;
}
if ($added_redirections)
// set new redirection?
if ($form_data['redirection'] == self::ACTIVATE)
{
$info_messages[] = __('Redirection has been activated for %s IP addresses', $added_redirections).'.';
$added_redr += Message_Model::activate_redirection(
$message, $ips,
$user_id, $comment
);
}
else
{
$info_messages[] = __('Redirection has been deactivated for %s IP addresses', $deleted_redirections).'.';
}
break;
}
// info messages
if ($added_redr)
{
$m = 'Redirection has been activated for %s IP addresses';
$info_messages[] = __($m, $added_redr).'.';
}
else
{
$m = 'Redirection has been deactivated for %s IP addresses';
$info_messages[] = __($m, $deleted_redr).'.';
}
}
// e-mail
switch ($form_data['email'])
/* Email */
if ($form_data['email'] == self::ACTIVATE)
{
case self::ACTIVATE:
$sent_emails = 0;
$email_queue_model = new Email_queue_Model();
$users_contacts_model = new Users_contacts_Model();
// for each subnet of cloud
foreach ($cloud->subnets as $subnet)
{
// gets all e-mails of subnet
$contacts = $users_contacts_model
->get_contacts_by_subnet_and_type(
$subnet->id, Contact_Model::TYPE_EMAIL,
$message->ignore_whitelist
);
foreach ($contacts as $contact)
{
$text = $message->email_text;
foreach ($contact as $key => $value)
{
if ($key != 'email_text')
$text = str_replace('{'.$key.'}', $value, $text);
}
$email_queue_model->clear();
$email_queue_model->from = Settings::get('email_default_email');
$email_queue_model->to = $contact->value;
$email_queue_model->subject = Settings::get('email_subject_prefix').": ".$message->name;
$email_queue_model->body = $text;
$email_queue_model->state = Email_queue_Model::STATE_NEW;
// send e-mail
if ($email_queue_model->save())
{
$sent_emails++;
}
}
}
$info_messages[] = __('E-mail has been sent for %s e-mail addresses', $sent_emails).'.';
break;
// stat var
$sent_emails = 0;
// for each subnet in cloud
foreach ($cloud->subnets as $subnet)
{
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_subnet_and_type(
$subnet->id, Contact_Model::TYPE_EMAIL,
$message->ignore_whitelist
);
// send email
$sent_emails += Message_Model::send_emails(
$message, $contacts, $comment
);
}
// info message
$m = 'E-mail has been sent for %s e-mail addresses';
$info_messages[] = __($m, $sent_emails).'.';
}
status::success(implode('<br />', $info_messages), FALSE);
/* SMS messages */
if ($form_data['sms'] == self::ACTIVATE)
{
// stat var
$sent_sms = 0;
// for each subnet in cloud
foreach ($cloud->subnets as $subnet)
{
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_subnet_and_type(
$subnet->id, Contact_Model::TYPE_PHONE,
$message->ignore_whitelist
);
// send email
$sent_sms += Message_Model::send_sms_messages(
$message, $contacts,
$user_id, $comment
);
}
// info message
$m = 'SMS message has been sent for %d phone numbers.';
$info_messages[] = __($m, $sent_sms);
}
// user notification
if (count($info_messages))
{
status::success(implode('<br />', $info_messages), FALSE);
}
// redirect
url::redirect('clouds/show/'.$cloud->id);
}
......
* @author Michal Kliment
* @param type $input
*/
public function valid_email ($input = NULL)
public function valid_email_or_sms ($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
freenetis/branches/testing/application/views/subnets_show.php
<h2><?php echo $headline ?></h2>
<br />
<?php
if (isset($submenu))
{

Také k dispozici: Unified diff