Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c1bdc1c4

Přidáno uživatelem Michal Kliment před více než 9 roky(ů)

Release 1.1.0

Zobrazit rozdíly:

application/controllers/messages.php
*/
class Messages_Controller extends Controller
{
/**
* Only enable if notification enabled
*/
public function __construct()
{
parent::__construct();
if (!module::e('notification'))
self::error(ACCESS);
}
/**
* Redirects to show all
*/
......
if (!$this->acl_check_view('Messages_Controller', 'message'))
Controller::error(ACCESS);
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
if (is_numeric($this->input->post('record_per_page')))
$limit_results = (int) $this->input->post('record_per_page');
$allowed_order_type = array
(
......
if (strtolower($order_by_direction) != 'desc')
$order_by_direction = 'asc';
$filter_form = new Filter_form('m');
$filter_form->add('name');
$filter_form->add('type')
->type('select')
->values(Message_Model::get_types());
if (module::e('redirection'))
{
$filter_form->add('text')
->label('Content of the message for redirection');
}
if (module::e('email'))
{
$filter_form->add('email_text')
->label('Content of the message for e-mail');
}
if (module::e('sms'))
{
$filter_form->add('sms_text')
->label('Content of the message for sms');
}
$filter_form->add('self_cancel')
->label('User-cancelable')
->type('select')
->values(Message_Model::get_self_cancel_messages());
$filter_form->add('ignore_whitelist')
->type('select')
->values(arr::bool());
// model
$message_model = new Message_Model();
$total_messages = $message_model->count_all_messages();
$total_messages = $message_model->count_all_messages($filter_form->as_sql());
if (($sql_offset = ($page - 1) * $limit_results) > $total_messages)
$sql_offset = 0;
$messages = $message_model->get_all_messages(
$sql_offset, $limit_results, $order_by, $order_by_direction
$sql_offset, $limit_results, $order_by, $order_by_direction,
$filter_form->as_sql()
);
$headline = __('Messages');
......
. '/messages/show_all/' . $limit_results
. '/' . $order_by . '/' . $order_by_direction,
'uri_segment' => 'page',
'total_items' => $total_messages,
'total_items' => isset($total_messages) ? $total_messages : 0,
'items_per_page' => $limit_results,
'style' => 'classic',
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results,
'url_array_ofset' => 1,
'filter' => $filter_form
));
$grid->add_new_button('messages/add', __('Add new message'));
......
->callback('callback::message_type_field');
$grid->callback_field('self_cancel')
->label(__('sc').' '.help::hint('self_cancel'))
->label(__('SC').' '.help::hint('self_cancel'))
->callback('callback::message_self_cancel_field');
$grid->callback_field('ignore_whitelist')
->label(__('iw').' '.help::hint('ignore_whitelist'))
->label(__('IW').' '.help::hint('ignore_whitelist'))
->callback('callback::boolean');
$grid->callback_field('id')
->label('Preview')
->callback('callback::message_preview_field');
if ($this->acl_check_view('Messages_Controller', 'preview'))
{
$grid->callback_field('id')
->label('Preview')
->callback('callback::message_preview_field');
}
if ($this->acl_check_edit('Messages_Controller', 'message'))
if ($this->acl_check_edit('Messages_Controller', 'activate'))
{
$grid->callback_field('id')
->label('Activate')
->callback('callback::message_activate_field');
}
if ($this->acl_check_edit('Messages_Controller', 'message'))
if ($this->acl_check_edit('Messages_Controller', 'deactivate'))
{
$grid->callback_field('id')
->label('Deactivate')
->callback('callback::message_deactivate_field');
}
$actions = $grid->grouped_action_field();
if ($this->acl_check_view('Messages_Controller', 'message'))
{
$actions->add_conditional_action()
->condition('is_activatable_directlty')
->icon_action('show')
->url('messages/show');
}
if ($this->acl_check_edit('Messages_Controller', 'message'))
{
$grid->action_field('id')
->label('Edit')
->url('messages/edit')
->action('Edit');
$actions->add_conditional_action()
->condition('is_message_automatical_config')
->icon_action('settings_auto')
->url('messages_auto_settings/show')
->label('Setup automatical activation');
$actions->add_action()
->icon_action('edit')
->url('messages/edit');
}
if ($this->acl_check_delete('Messages_Controller', 'message'))
{
$grid->callback_field('id')
->label('Delete')
->callback('callback::message_delete_field');
$actions->add_conditional_action()
->condition('is_message_type_of_user')
->icon_action('delete')
->url('messages/delete')
->class('delete_link');
}
$grid->datasource($messages);
......
if (!$this->acl_check_new('Messages_Controller', 'message'))
Controller::error(ACCESS);
// self cancel
$self_cancel[Message_Model::SELF_CANCEL_DISABLED] = __('Disabled');
$self_cancel[Message_Model::SELF_CANCEL_MEMBER] =
__('Possibility of canceling redirection to all IP addresses of member');
$self_cancel[Message_Model::SELF_CANCEL_IP] =
__('Possibility of canceling redirection to only current IP address');
$form = new Forge('messages/add');
$form->group('Basic information');
......
$form->dropdown('self_cancel')
->label('User-cancelable')
->options($self_cancel)
->options(Message_Model::get_self_cancel_messages())
->selected(Message_Model::SELF_CANCEL_MEMBER)
->style('width: 600px');
......
->options(arr::rbool())
->selected(0);
$form->html_textarea('text')
->label('Content of the message')
if (module::e('redirection'))
{
$form->html_textarea('text')
->label(__('Content of the message for redirection').': '.
help::hint('content_of_message'))
->rows(5)
->cols(100);
}
if (module::e('email'))
{
$form->html_textarea('email_text')
->label(__('Content of the message for E-mail').': '.
help::hint('content_of_message'))
->rows(5)
->cols(100);
$form->html_textarea('email_text')
->label(__('Content of the message for E-mail').': '.
help::hint('content_of_message'))
->rows(5)
->cols(100);
$form->textarea('sms_text')
->label(__('Content of the message for SMS').': '.
help::hint('content_of_message'))
->rules('length[1,760]')
->style('width: 100%; max-width: 633px; height: 150px');
}
if (module::e('sms'))
{
$form->textarea('sms_text')
->label(__('Content of the message for SMS').': '.
help::hint('content_of_message'))
->rules('length[1,760]')
->style('width: 100%; max-width: 633px; height: 150px');
}
$form->submit('Add');
if ($form->validate())
{
$form_data = $form->as_array(FALSE);
$message = new Message_Model();
$message->name = htmlspecialchars($form_data['name']);
$message->type = Message_Model::USER_MESSAGE;
$message->self_cancel = htmlspecialchars($form_data['self_cancel']);
$message->ignore_whitelist = htmlspecialchars($form_data['ignore_whitelist']);
// 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;
$message->text = $form_data['text'];
unset($form_data);
$message = new Message_Model();
if ($message->save())
try
{
$message->transaction_start();
$message->name = htmlspecialchars($form_data['name']);
$message->type = Message_Model::USER_MESSAGE;
$message->self_cancel = htmlspecialchars($form_data['self_cancel']);
$message->ignore_whitelist = htmlspecialchars($form_data['ignore_whitelist']);
// redir text
if (module::e('redirection') &&
Message_Model::has_redirection_content($message->type))
{
$message->text = $form_data['text'];
}
// email text
if (module::e('email') &&
Message_Model::has_email_content($message->type))
{
$email_text = trim($form_data['email_text']);
$message->email_text = empty($email_text) ? NULL : $email_text;
}
// sms text
if (module::e('sms') &&
Message_Model::has_sms_content($message->type))
{
$sms_text = trim(text::cs_utf2ascii(strip_tags($form_data['sms_text'])));
$message->sms_text = empty($sms_text) ? NULL : $sms_text;
}
$message->save_throwable();
$message->transaction_commit();
status::success('Message has been successfully added.');
}
else
catch (Exception $e)
{
status::error('Error - cannot add message.');
$message->transaction_rollback();
status::error('Error - cannot add message.', $e);
Log::add_exception($e);
}
url::redirect('messages/show_all');
$this->redirect('messages/show_all');
}
else
{
$headline = __('Add redirection message');
$headline = __('Add notification message');
$breadcrumbs = breadcrumbs::add()
->link('messages/show_all', 'Messages',
$this->acl_check_view(
'Redirection_Controller', 'redirection'
)
)
->disable_translation()
$this->acl_check_view('Messages_Controller', 'message')
)->disable_translation()
->text($headline);
$view = new View('main');
......
$view->render(TRUE);
}
} // end of add
/**
* Shows notification message details
*
* @param integer $message_id
*/
public function show($message_id = NULL)
{
if (!$this->acl_check_view('Messages_Controller', 'message'))
Controller::error(ACCESS);
if (!isset($message_id))
Controller::warning(PARAMETER);
$message = new Message_Model($message_id);
// record doesn't exist
if (!$message->id)
Controller::error(RECORD);
if (($message->id == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->id == Message_Model::DEBTOR_MESSAGE ||
$message->id == Message_Model::RECEIVED_PAYMENT_NOTICE_MESSAGE) && !Settings::get('finance_enabled'))
{
Controller::error(ACCESS);
}
$headline = __('Show notification message');
$breadcrumbs = breadcrumbs::add()
->link('messages/show_all', 'Messages',
$this->acl_check_view(
'Messages_Controller', 'message'
)
);
if ($message->type > 0)
{
$breadcrumbs->text($message->name);
}
else
{
$breadcrumbs
->disable_translation()
->text($message->name . ' (' . $message->id . ')');
}
$view = new View('main');
$view->title = $headline;
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('messages/show');
$view->content->headline = $headline;
$view->content->message = $message;
$view->render(TRUE);
}
/**
* Edits message parameters.
......
$message = new Message_Model($message_id);
// access rights
if (!$this->acl_check_edit('Messages_Controller', 'message'))
Controller::error(ACCESS);
// record doesn't exist
if (!$message->id)
Controller::error(RECORD);
// self cancel
$self_cancel[Message_Model::SELF_CANCEL_DISABLED] = __('Disabled');
$self_cancel[Message_Model::SELF_CANCEL_MEMBER] =
__('Possibility of canceling redirection to all IP addresses of member');
$self_cancel[Message_Model::SELF_CANCEL_IP] =
__('Possibility of canceling redirection to only current IP address');
if (($message->id == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->id == Message_Model::DEBTOR_MESSAGE ||
$message->id == Message_Model::RECEIVED_PAYMENT_NOTICE_MESSAGE) &&
!Settings::get('finance_enabled'))
{
Controller::error(ACCESS);
}
$form = new Forge('messages/edit/'.$message_id);
$form->group('Basic information');
if ($message->type == 0)
if ($message->type == Message_Model::USER_MESSAGE)
{
$form->input('name')
->label('Message name')
......
->style('width: 600px');
}
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->type == Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE)
if (Message_Model::is_self_cancable($message->type))
{
$form->dropdown('self_cancel')
->label(__('User-cancelable').
': '.help::hint('self_cancel'))
->options($self_cancel)
->label(__('User-cancelable').': '.help::hint('self_cancel'))
->options(Message_Model::get_self_cancel_messages())
->selected($message->self_cancel)
->style('width: 600px');
}
if (Message_Model::is_white_list_ignorable($message->type) &&
Message_Model::USER_MESSAGE == $message->type)
{
$form->dropdown('ignore_whitelist')
->label(__('Ignore whitelist').
': '.help::hint('ignore_whitelist'))
->label(__('Ignore whitelist').': '.help::hint('ignore_whitelist'))
->options(arr::rbool())
->selected($message->ignore_whitelist);
}
$form->html_textarea('text')
->label(__('Content of the message for redirection').': '.
help::hint('content_of_message'))
->rows(5)
->cols(100)
->value($message->text);
if (module::e('redirection') &&
Message_Model::has_redirection_content($message->type))
{
$form->html_textarea('text')
->label(__('Content of the message for redirection').': '.
help::hint('content_of_message'))
->rows(5)
->cols(100)
->value($message->text);
}
if ($message->type == Message_Model::USER_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE)
if (module::e('email') &&
Message_Model::has_email_content($message->type))
{
$form->html_textarea('email_text')
->label(__('Content of the message for E-mail').': '.
......
->rows(5)
->cols(100)
->value($message->email_text);
}
if (module::e('sms') &&
Message_Model::has_sms_content($message->type))
{
$form->textarea('sms_text')
->label(__('Content of the message for SMS').': '.
help::hint('content_of_message'))
......
$message->name = $form_data['name'];
}
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->type == Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE)
if (Message_Model::is_self_cancable($message->type))
{
$message->self_cancel = htmlspecialchars($form_data['self_cancel']);
}
if (Message_Model::is_white_list_ignorable($message->type) &&
Message_Model::USER_MESSAGE == $message->type)
{
$message->ignore_whitelist = htmlspecialchars($form_data['ignore_whitelist']);
}
$message->text = $form_data['text'];
if ($message->type == Message_Model::USER_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE)
if (module::e('redirection') &&
Message_Model::has_redirection_content($message->type))
{
$message->text = $form_data['text'];
}
if (module::e('email') &&
Message_Model::has_email_content($message->type))
{
// email text
$email_text = trim($form_data['email_text']);
$email_text = empty($email_text) ? NULL : $email_text;
// set var
$message->email_text = empty($email_text) ? NULL : $email_text;
}
if (module::e('sms') &&
Message_Model::has_sms_content($message->type))
{
// 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;
// set var
$message->sms_text = empty($sms_text) ? NULL : $sms_text;
}
unset($form_data);
// saving message
if ($message->save())
{
......
}
else
{
$headline = __('Edit redirection message');
$headline = __('Edit notification message');
$breadcrumbs = breadcrumbs::add()
->link('messages/show_all', 'Messages',
$this->acl_check_view(
'Messages_Controller', 'message'
)
);
if ($message->type > 0)
{
$breadcrumbs = breadcrumbs::add()
->link('messages/show_all', 'Messages',
$this->acl_check_view(
'Redirection_Controller', 'redirection'
)
)
->text($message->name)
->text($headline);
$breadcrumbs->text($message->name);
}
else
{
$breadcrumbs = breadcrumbs::add()
->link('messages/show_all', 'Messages',
$this->acl_check_view(
'Redirection_Controller', 'redirection'
)
)
$breadcrumbs
->disable_translation()
->text($message->name . ' (' . $message->id . ')')
->text($headline);
->text($message->name . ' (' . $message->id . ')');
}
$breadcrumbs->text($headline);
$view = new View('main');
$view->title = $headline;
$view->breadcrumbs = $breadcrumbs->html();
......
}
/**
* Updates redirections for given message.
* Special redirection types are updated only to coresponding members.
* Updates notifications for given message.
* Special notification types are updated only to coresponding members.
*
* @author Jiri Svitak
* @param integer $message_id
*/
public function activate($message_id = NULL)
{
if (!$this->acl_check_new('Messages_Controller', 'member'))
if (!$this->acl_check_new('Messages_Controller', 'activate'))
{
Controller::error(ACCESS);
}
// param check
if (!$message_id || !is_numeric($message_id))
{
......
// preparation
$message = new Message_Model($message_id);
if (!$message || !$message->id)
if (!$message || !$message->id ||
!Message_Model::can_be_activate_directly($message->type))
{
Controller::error(RECORD);
}
if (($message->id == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->id == Message_Model::DEBTOR_MESSAGE) &&
!Settings::get('finance_enabled'))
{
Controller::error(ACCESS);
}
$this->message_id = $message->id;
// shows beetween page only for interrupt membership, payment notice and debtor
if ($message->type == Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE)
$member_model = new Member_Model();
// shows beetween page only for interrupt payment notice and debtor
if ($message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE)
{
if (!isset($_POST) || !isset($_POST["ids"]))
if (!isset($_POST) || !isset($_POST['ids']))
{
switch ($message->type)
{
case Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE:
$order_by = 'whitelisted DESC, allowed ASC';
break;
default:
$order_by = 'whitelisted DESC, id ASC';
break;
}
$member_model = new Member_Model();
$members = $member_model->get_members_to_messages($message->type);
$grid = new Grid('notifications/cloud', '', array
......
$grid->callback_field('balance')
->callback('callback::balance_field');
if ($message->type == Message_Model::INTERRUPTED_MEMBERSHIP_MESSAGE ||
$message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::USER_MESSAGE)
{
$grid->callback_field('interrupt')
->label('Membership interrupt')
->callback('callback::active_field')
->class('center');
}
$grid->callback_field('interrupt')
->label('Membership interrupt')
->callback('callback::active_field')
->class('center');
if ($message->type == Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE ||
$message->type == Message_Model::USER_MESSAGE)
if ($message->type == Message_Model::USER_MESSAGE)
{
$grid->callback_field('allowed')
->label('Allowed subnet')
......
->callback('callback::whitelisted_field')
->class('center');
$grid->form_field('redirection')
->label('Redirection')
->type('dropdown')
->options(array
(
Notifications_Controller::ACTIVATE => __('Activate'),
Notifications_Controller::KEEP => __('Without change'),
Notifications_Controller::DEACTIVATE => __('Deactivate')
))
->callback('callback::notification_form_field', $message->type, $message->ignore_whitelist);
if ($message->type == Message_Model::DEBTOR_MESSAGE ||
$message->type == Message_Model::PAYMENT_NOTICE_MESSAGE ||
$message->type == Message_Model::USER_MESSAGE)
if (module::e('redirection') &&
Message_Model::has_redirection_content($message->type))
{
$grid->form_field('redirection')
->type('dropdown')
->options(notification::redirection_form_array())
->callback(
'callback::notification_form_field', $message
);
}
if (module::e('email') &&
Message_Model::has_email_content($message->type))
{
$grid->form_field('email')
->label('E-Mail')
->label('E-mail')
->type('dropdown')
->options(array
(
Notifications_Controller::ACTIVATE => __('Activate'),
Notifications_Controller::KEEP => __('Without change')
))
->callback('callback::notification_form_field', $message->type, $message->ignore_whitelist);
->options(notification::redirection_form_array(TRUE))
->callback(
'callback::notification_form_field', $message
);
}
if (module::e('sms') &&
Message_Model::has_sms_content($message->type))
{
$grid->form_field('sms')
->label('SMS')
->type('dropdown')
->options(array
(
Notifications_Controller::ACTIVATE => __('Activate'),
Notifications_Controller::KEEP => __('Without change')
))
->options(notification::redirection_form_array(TRUE))
->callback(
'callback::notification_form_field',
$message->type,
$message->ignore_whitelist
'callback::notification_form_field', $message
);
}
......
(
"position" => 'top',
form::label(
'comment',
"<b>".__('Comment').":</b>"
'comment', "<b>".__('Comment').":</b>"
) . form::textarea('comment', '', 'style="margin-left: 30px"')."<br /><br />"
);
$grid->form_submit_value = __('Activate');
$grid->datasource($members);
$headline = __('Activate message for all members');
if ($message->type > 0)
{
$breadcrumbs = breadcrumbs::add()
->link('messages/show_all', 'Messages',
$this->acl_check_view(
'Redirection_Controller', 'redirection'
)
)
->text($message->name)
->text($headline);
$breadcrumbs = breadcrumbs::add()
->link('messages/show_all', 'Messages',
$this->acl_check_view(
'Messages_Controller', 'message'
)
);
if ($message->type != Message_Model::USER_MESSAGE)
{
$breadcrumbs->text($message->name);
}
else
{
$breadcrumbs = breadcrumbs::add()
->link('messages/show_all', 'Messages',
$this->acl_check_view(
'Redirection_Controller', 'redirection'
)
)
->disable_translation()
->text($message->name . ' (' . $message->id . ')')
->text($headline);
$breadcrumbs->disable_translation()
->text($message->name . ' (' . $message->id . ')');
}
$breadcrumbs->text($headline);
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
......
$view->content = new View('show_all');
$view->content->headline = $headline;
$view->content->table = $grid;
$view->content->status_message_info = url_lang::lang('help.notification_settings');
$view->render(TRUE);
}
else
{
$ip_address_model = new Ip_address_Model();
$mia_model = new Messages_ip_addresses_Model();
$uc_model = new Users_contacts_Model();
$comment = $_POST["comment"];
$redirections = $_POST["redirection"];
$emails = (isset($_POST["email"])) ? $_POST["email"] : array();
$smss = (isset($_POST["sms"])) ? $_POST["sms"] : array();
$user_id = $this->session->get('user_id');
$added_redr = 0;
$deleted_redr = 0;
$sent_emails = 0;
$sent_sms = 0;
$info_messages = array();
foreach ($redirections as $member_id => $redirection)
{
if ($redirection == Notifications_Controller::KEEP)
continue;
// get all redirection
$ips = $ip_address_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 ($redirection == Notifications_Controller::ACTIVATE)
{
$added_redr += Message_Model::activate_redirection(
$message, $ips,
$user_id, $comment
);
}
}
// info messages
if ($added_redr)
// params
$comment = $_POST['comment'];
$user_id = $this->user_id;
$redirections = $emails = $smss = array();
if (isset($_POST['redirection']) && module::e('redirection'))
{
$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).'.';
$redirections = $_POST['redirection'];
}
foreach ($emails as $member_id => $email)
if (isset($_POST['email']) && module::e('email'))
{
if ($email == Notifications_Controller::KEEP)
continue;
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_member_and_type(
$member_id, Contact_Model::TYPE_EMAIL, TRUE
);
// send email
$sent_emails += Message_Model::send_emails(
$message, $contacts, $comment
);
$emails = $_POST['email'];
}
// info message
$m = 'E-mail has been sent for %s e-mail addresses';
$info_messages[] = __($m, $sent_emails).'.';
foreach ($smss as $member_id => $sms)
if (isset($_POST['sms']) && module::e('sms'))
{
if ($sms == Notifications_Controller::KEEP)
continue;
// gets all contacts of member
$contacts = $uc_model->get_contacts_by_member_and_type(
$member_id, Contact_Model::TYPE_PHONE, TRUE
);
// send email
$sent_sms += Message_Model::send_sms_messages(
$message, $contacts,
$user_id, $comment
);
$smss = $_POST['sms'];
}
// info message
$m = 'SMS message has been sent for %d phone numbers.';
$info_messages[] = __($m, $sent_sms);
// user notification
// notify
$stats = Notifications_Controller::notify_from_form(
$message, $user_id, $comment,
$redirections, $emails, $smss
);
// info messages
$info_messages = notification::build_stats_string(
$stats, module::e('redirection'),
module::e('email'),
module::e('sms'),
module::e('redirection')
);
// log action
if (count($info_messages))
{
$un = ORM::factory('user', $user_id)->get_full_name();
$m = __('User "%s" has activated notification message "%s"',
array($un, __($message->name)));
status::success(implode('<br />', $info_messages), FALSE);
Log_queue_Model::info($m, implode("\n", $info_messages));
}
// redirect
url::redirect('messages/show_all');
}
}
// other messages will be activate right now
// user message will be activate right now
else
{
$dropdown_options = array
......
);
$form = new Forge(url::base(TRUE) . url::current(TRUE));
$form->dropdown('redirection')
->options($dropdown_options)
->selected(Notifications_Controller::KEEP);
if ($message->type == Message_Model::USER_MESSAGE)
if (module::e('redirection'))
{
$form->dropdown('email')
->label('E-mail')
$form->dropdown('redirection')
->options($dropdown_options)
->selected(Notifications_Controller::KEEP)
->callback(array($this, 'valid_email_or_sms'));
->selected(Notifications_Controller::KEEP);
}
if ($message->type == Message_Model::USER_MESSAGE)
{
if (module::e('email'))
{
$form->dropdown('email')
->label('E-mail')
->options($dropdown_options)
->selected(Notifications_Controller::KEEP)
->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'));
if (module::e('sms'))
{
$form->dropdown('sms')
->label('SMS')
->options($dropdown_options)
->selected(Notifications_Controller::KEEP)
->callback(array($this, 'valid_email_or_sms'));
}
}
$form->submit('Send');
if ($form->validate())
{
$form_data = $form->as_array();
$user_id = $this->session->get('user_id');
$ip_count = 0;
$comment = @$form_data['comment'];
$redirection = module::e('redirection') &&
($form_data['redirection'] == Notifications_Controller::ACTIVATE);
$email = module::e('email') &&
($form_data['email'] == Notifications_Controller::ACTIVATE);
$sms = module::e('sms') &&
($form_data['sms'] == Notifications_Controller::ACTIVATE);
try
{
// choose which message to update
switch($message->type)
{
case Message_Model::UNALLOWED_CONNECTING_PLACE_MESSAGE:
if ($form_data['redirection'] == Notifications_Controller::ACTIVATE)
{
$ip_count = $message->activate_unallowed_connecting_place_message($user_id);
}
break;
case Message_Model::USER_MESSAGE:
$counts = $message->activate_user_message(
$message_id,
$user_id,
$form_data['redirection'],
$form_data['email'],
$form_data['sms']
);
$ip_count = $counts['ip_count'];
$email_count = $counts['email_count'];
$sms_count = $counts['sms_count'];
break;
default:
Controller::warning(PARAMETER);
}
$m = 'Redirection "%s" for %d IP addresses have been activated.';
$info_message = __($m, array
(
0 => __($message->name),
1 => $ip_count
));
if (isset($email_count))
{
$m = 'E-mail "%s" has been sent for %d e-mail addresses.';
$info_message .= '<br />'.__($m, array
(
0 => __($message->name),
1 => $email_count
));
}
if (isset($sms_count))
// get members
$members = $member_model->get_members_to_messages(
Message_Model::USER_MESSAGE
);
// notify
$stats = Notifications_Controller::notify(
$message, $members, $user_id, $comment,
$redirection, $email, $sms, $redirection
);
// info messages
$info_messages = notification::build_stats_string(
$stats, module::e('redirection'), module::e('email'),
module::e('sms'), module::e('redirection')
);
// log action
if (count($info_messages))
{
$m = 'SMS message "%s" has been sent for %d phone numbers.';
$info_message .= '<br />'.__($m, array
(
0 => __($message->name),
1 => $sms_count
));
$un = ORM::factory('user', $user_id)->get_full_name();
$m = __('User "%s" has activated notification message "%s"',
array($un, __($message->name)));
status::success(implode('<br />', $info_messages), FALSE);
Log_queue_Model::info($m, implode("\n", $info_messages));
}
status::success($info_message, FALSE);
// redirect
url::redirect('messages/show_all');
}
catch (Exception $e)
{
$em = __('Error - cant set redirection.') . '<br>' . $e->getMessage();
status::error($em, FALSE);
status::error($em, $e, FALSE);
url::redirect('messages/show_all');
}
}
$headline = __('Activate message for all members');
$breadcrumbs = breadcrumbs::add()
->link('messages/show_all', 'Messages',
$this->acl_check_view(
'Messages_Controller', 'message'
)
);
if ($message->type > 0)
{
$breadcrumbs = breadcrumbs::add()
->link('messages/show_all', 'Messages',
$this->acl_check_view(
'Redirection_Controller', 'redirection'
)
)
->text($message->name)
->text($headline);
$breadcrumbs->text($message->name);
}
else
{
$breadcrumbs = breadcrumbs::add()
->link('messages/show_all', 'Messages',
$this->acl_check_view(
'Redirection_Controller', 'redirection'
)
)
->disable_translation()
->text($message->name . ' (' . $message->id . ')')
->text($headline);
$breadcrumbs->disable_translation()
->text($message->name . ' (' . $message->id . ')');
}
$breadcrumbs->text($headline);
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
......
*/
public function deactivate($message_id = NULL)
{
if (!$this->acl_check_edit('Messages_Controller', 'message'))
if (!$this->acl_check_edit('Messages_Controller', 'deactivate'))
{
Controller::error(ACCESS);
}
......
$message_model = new Message_Model();
$message_model->deactivate_message($message_id);
// log action
$un = ORM::factory('user', $this->user_id)->get_full_name();
$m = __('User "%s" has deactivated notification message "%s"',
array($un, __($message->name)));
Log_queue_Model::info($m);
status::success('Activated redirections of this message have been successfuly deactivated.');
url::redirect('messages/show_all');
......
*/
public function delete($message_id = NULL)
{
if (!$this->acl_check_edit('Messages_Controller', 'message'))
if (!$this->acl_check_delete('Messages_Controller', 'message'))
{
Controller::error(ACCESS);
}
......
url::redirect('messages/show_all');
}
/**
* Callback function to validate e-mail or sms notification
*

Také k dispozici: Unified diff