function ad_notify_overview in Advertisement 5.2
Function stub.
1 string reference to 'ad_notify_overview'
- ad_notify_menu in notify/
ad_notify.module - Implementation of hook_menu().
File
- notify/
ad_notify.module, line 245 - Receive email notifications regarding ads.
Code
function ad_notify_overview($aid, $uid, $notid = 0) {
global $user;
if (arg(2) == 'notifications') {
drupal_set_title('My notifications');
}
else {
drupal_set_title('Notifications');
}
$oid = db_result(db_query('SELECT oid FROM {ad_owners} WHERE aid = %d AND uid = %d', $aid, $uid));
$notifications = module_invoke_all('adnotifyapi', 'register');
$owner = user_load(array(
'uid' => $uid,
));
$header = array(
array(
'data' => t('last sent'),
'field' => 'sent',
'sort' => 'desc',
),
array(
'data' => t('notification'),
'field' => 'event',
),
array(
'data' => t('status'),
'field' => 'status',
),
array(
'data' => t('action'),
),
);
$sql = "SELECT notid, event, delay, sent, address, status FROM {ad_notify} WHERE oid = {$oid}";
$sql .= tablesort_sql($header);
$result = pager_query($sql, 25);
$rows = array();
while ($notify = db_fetch_object($result)) {
$row = array();
$row[] = $notify->sent ? format_interval(time() - $notify->sent) . t(' ago') : t('Never');
$row[] = t($notifications[$notify->event], array(
'@when' => format_interval($notify->delay),
));
$row[] = $notify->status == AD_NOTIFY_ENABLED ? t('enabled') : t('disabled');
$row[] = l(t('edit'), "node/{$aid}/adowners/{$uid}/notifications/{$notify->notid}/edit") . ' ' . l(t('delete'), "node/{$aid}/adowners/{$uid}/notifications/{$notify->notid}/delete");
$rows[] = $row;
}
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 25, 0);
$form = array();
if ($notid) {
$notification = ad_notify_load_notification($notid);
}
$help = '<p>' . t('You can configure one or more notifications for your advertisement using the drop down menus below. For example, to receive a weekly notification with information about how often your advertisement was viewed and clicked, select the <em>email every @when as long as the ad is active</em> event, and <em>1 week</em> for when. Or, to receive a reminder that your advertisement will expire in 24 hours select the <em>email @when before the advertisement will expire</em>, and <em>1 day</em> for when.') . '</p>';
$help .= '<p>' . t('If you schedule a delay between an event and when you are notified and the event happens multiple times, only one notification will be sent. For example, if you create a notification for <em>email 1 day after the advertisement is clicked</em> and the ad is clicked 42 more times in the next 24 hours, you will only receive one email 24 hours after your ad was first clicked that notes that your ad was clicked a total of 43 times in the past 24 hours.') . '</p>';
$form['create'] = array(
'#type' => 'fieldset',
'#description' => $help,
'#title' => $notid ? t('edit notification') : t('create new notification'),
'#collapsible' => TRUE,
'#collapsed' => $rows == array() || $notid ? FALSE : TRUE,
);
$form['create']['event'] = array(
'#type' => 'select',
'#title' => t('Event'),
'#options' => $notifications,
'#description' => t('Select an event for which you would like to receive a notification.'),
'#default_value' => $notid ? $notification->event : 1,
);
$form['create']['delay'] = array(
'#type' => 'select',
'#title' => t('When'),
'#options' => drupal_map_assoc(array(
0,
3600,
10800,
21600,
43200,
86400,
259200,
432000,
604800,
1209600,
1814400,
2419200,
4838400,
9676800,
31536000,
), 'format_interval'),
'#description' => t('Select a value to replace @when in the event notification you selected above.'),
'#default_value' => $notid ? $notification->delay : 0,
);
$form['create']['expire'] = array(
'#type' => 'checkbox',
'#title' => t('One-time'),
'#description' => t('Check this box if this notification email should only be sent one time. If not checked, an email will be sent each time the event happens. If checked, an email will only be sent the first time the event happens, then the notification will be automatically disabled.'),
'#default_value' => $notid ? $notification->expire : 0,
);
if (ad_permission($aid, 'manage owners') && arg(2) == 'adowners' && $user->uid != arg(3)) {
$form['create']['locked'] = array(
'#type' => 'checkbox',
'#title' => t('Locked'),
'#description' => t('Check this box if you are setting up a notification for someone else, and you don\'t want them to be able to disable the notification. Only users with the <em>manage owners</em> permission for this ad can edit or delete a locked notification.'),
'#default_value' => $notid ? $notification->locked : 0,
);
}
else {
$form['create']['locked'] = array(
'#type' => 'hidden',
'#value' => $notid ? $notification->locked : 0,
);
}
if ($notid) {
$form['create']['mail'] = array(
'#type' => 'fieldset',
'#title' => t('message'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
}
// TODO: Make it possible for admins to modify email address, and even to
// enter multiple email addresses. Wrap this in a special permission, as
// it involves trust to configure notifications to unverified addresses.
$form['create']['mail']['address-display'] = array(
'#type' => 'markup',
'#value' => '<b>' . t('Notify address') . ':</b><br />' . t('The email will be sent to %address.', array(
'%address' => $owner->mail,
)),
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
);
$form['create']['mail']['address'] = array(
'#type' => 'hidden',
'#value' => $owner->mail,
);
if ($notid) {
$form['create']['mail']['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#required' => TRUE,
'#default_value' => $notification->subject,
);
$form['create']['mail']['body'] = array(
'#type' => 'textarea',
'#title' => t('Body'),
'#required' => TRUE,
'#default_value' => $notification->body,
'#description' => t('Enter the body of your notification email. The following variables can be used in your message and will be automatically replaced before the email is sent:') . '<ul>' . '<li>' . t('%sitename: the name of this website.', array(
'%sitename' => '%sitename',
)) . '<li>' . t('%owner_name: the username of the ad owner.', array(
'%owner_name' => '%owner_name',
)) . '<li>' . t('%owner_mail: the email address of the ad owner.', array(
'%owner_mail' => '%owner_mail',
)) . '<li>' . t('%owner_uid: the user ID of the ad owner.', array(
'%owner_uid' => '%owner_uid',
)) . '<li>' . t('%event: the type of event that has triggered this notification.', array(
'%event' => '%event',
)) . '<li>' . t('%count: the number of times the event happened.', array(
'%count' => '%count',
)) . '<li>' . t('%frequency: a complete sentence describing the frequency this notification will be sent.', array(
'%frequency' => '%frequency',
)) . '<li>' . t('%type: the type of ad.', array(
'%type' => '%type',
)) . '<li>' . t('%status: the status of the ad.', array(
'%status' => '%status',
)) . '<li>' . t('%url: the url of the advertisement.', array(
'%url' => '%url',
)) . '<li>' . t('%siteurl: the url of the website.', array(
'%siteurl' => '%siteurl',
)) . '<li>' . t('%redirect: the redirection url of the advertisement.', array(
'%redirect' => '%redirect',
)) . '<li>' . t('%title: the title of the advertisement.', array(
'%title' => '%title',
)) . '<li>' . t('%aid: the ID of the advertisement.', array(
'%aid' => '%aid',
)) . '<li>' . t('%comments: the number of comments attached to the advertisement.', array(
'%comments' => '%comments',
)) . '<li>' . t('%created_small, %created_medium, %created_large: various formats of when the advertisement was created.', array(
'%created_small' => '%created_small',
'%created_medium' => 'created_medium',
'%created_large' => 'created_large',
)) . '<li>' . t('%activated_small, %activated_medium, %activated_large: various formats of when the advertisement was activated.', array(
'%activated_small' => '%activated_small',
'%activated_medium' => 'activated_medium',
'%activated_large' => 'activated_large',
)) . '<li>' . t('%expired_small, %expired_medium, %expired_large: various formats of when the advertisement was expired.', array(
'%expired_small' => '%expired_small',
'%expired_medium' => 'expired_medium',
'%expired_large' => 'expired_large',
)) . '<li>' . t('%autoactivate_small, %autoactivate_medium, %autoactivate_large: various formats of when the advertisement was automatically activated.', array(
'%autoactivate_small' => '%autoactivate_small',
'%autoactivate_medium' => 'autoactivate_medium',
'%autoactivate_large' => 'autoactivate_large',
)) . '<li>' . t('%autoexpire_small, %autoexpire_medium, %autoexpire_large: various formats of when the advertisement was automatically expired.', array(
'%autoexpire_small' => '%autoexpire_small',
'%autoexpire_medium' => 'autoexpire_medium',
'%autoexpire_large' => 'autoexpire_large',
)) . '<li>' . t('%maxviews: the maximum number of times this advertisement is allowed to be viewed.', array(
'%maxviews' => '%maxviews',
)) . '<li>' . t('%maxclicks: the maximum number of times this advertisement is allowed to be clicked.', array(
'%maxclicks' => '%maxclicks',
)) . '<li>' . t('%global_views, %global_clicks, %last_year_views, %last_year_clicks, %this_year_views, %this_year_clicks, %last_month_views, %last_month_clicks, %this_month_views, %this_month_clicks, %this_week_views, %this_week_clicks, %yesterday_views, %yesterday_clicks, %today_views, %today_clicks, %last_hour_views, %last_hour_clicks, %this_hour_views, %this_hour_clicks: various advertisement statistics', array(
'%global_views' => '%global_views',
'%global_clicks' => '%global_views',
'%last_year_views' => '%last_year_views',
'%last_year_clicks' => '%last_year_clicks',
'%this_year_views' => '%this_year_views',
'%this_year_clicks' => '%this_year_clicks',
'%this_hour_views' => '%this_hour_views',
'%this_hour_clicks' => '%this_hour_clicks',
)) . '</ul>',
);
}
$form['create']['oid'] = array(
'#type' => 'hidden',
'#value' => $oid,
);
$form['create']['aid'] = array(
'#type' => 'hidden',
'#value' => $aid,
);
$form['create']['uid'] = array(
'#type' => 'hidden',
'#value' => $uid,
);
if ($notid) {
$form['create']['notid'] = array(
'#type' => 'hidden',
'#value' => $notid,
);
}
$form['create']['submit'] = array(
'#type' => 'submit',
'#value' => $notid ? t('edit notification') : t('create notification'),
);
if ($rows != array()) {
$form['notifications'] = array(
'#type' => 'fieldset',
'#title' => t('notifications'),
'#collapsible' => TRUE,
);
$form['notifications']['current'] = array(
'#type' => 'markup',
'#value' => $output,
);
}
else {
$form['notifications'] = array(
'#type' => 'markup',
'#value' => '<p>' . t('There are no notifications configured for %owner.', array(
'%owner' => $owner->name,
)) . '</p>',
);
}
return $form;
}