Mercurial > defr > drupal > ad
comparison ad.admin.inc @ 1:948362c2a207 ad
update advertisement
author | pierre |
---|---|
date | Thu, 02 Apr 2009 15:28:21 +0000 |
parents | d8a3998dac8e |
children | 416ea999ed76 |
comparison
equal
deleted
inserted
replaced
0:d8a3998dac8e | 1:948362c2a207 |
---|---|
1 <?php | 1 <?php |
2 // $Id: ad.admin.inc,v 1.1.2.9 2009/02/17 19:22:45 jeremy Exp $ | 2 // $Id: ad.admin.inc,v 1.1.2.9.2.2 2009/03/02 07:31:23 jeremy Exp $ |
3 | 3 |
4 /** | 4 /** |
5 * @file | 5 * @file |
6 * Advertisement admin pages and functions. | 6 * Advertisement admin pages and functions. |
7 * | 7 * |
87 'offline' => array( | 87 'offline' => array( |
88 'label' => t('Mark as offline'), | 88 'label' => t('Mark as offline'), |
89 'callback' => 'ad_operations_callback', | 89 'callback' => 'ad_operations_callback', |
90 'callback arguments' => array('offline'), | 90 'callback arguments' => array('offline'), |
91 ), | 91 ), |
92 'unpublished' => array( | |
93 'label' => t('Mark as unpublished'), | |
94 'callback' => 'ad_operations_callback', | |
95 'callback arguments' => array('unpublished'), | |
96 ), | |
97 'denied' => array( | 92 'denied' => array( |
98 'label' => t('Mark as denied'), | 93 'label' => t('Mark as denied'), |
99 'callback' => 'ad_operations_callback', | 94 'callback' => 'ad_operations_callback', |
100 'callback arguments' => array('denied'), | 95 'callback arguments' => array('denied'), |
101 ), | 96 ), |
232 $args = array($ads); | 227 $args = array($ads); |
233 } | 228 } |
234 call_user_func_array($function, $args); | 229 call_user_func_array($function, $args); |
235 | 230 |
236 cache_clear_all(); | 231 cache_clear_all(); |
232 ad_rebuild_cache(TRUE); | |
237 drupal_set_message(t('The update has been performed.')); | 233 drupal_set_message(t('The update has been performed.')); |
238 } | 234 } |
239 } | 235 } |
240 | 236 |
241 /** | 237 /** |
260 $where[] = "$table.tid = %d"; | 256 $where[] = "$table.tid = %d"; |
261 $join .= "INNER JOIN {term_node} $table ON n.nid = $table.nid "; | 257 $join .= "INNER JOIN {term_node} $table ON n.nid = $table.nid "; |
262 break; | 258 break; |
263 case 'type': | 259 case 'type': |
264 $where[] = "a.adtype = '%s'"; | 260 $where[] = "a.adtype = '%s'"; |
261 default: | |
262 $return = module_invoke_all('adapi', 'admin_filter_query', $filter); | |
263 foreach ($return as $module => $funcs) { | |
264 if (isset($funcs['where'])) { | |
265 $where[] = $funcs['where']; | |
266 } | |
267 if (isset($funcs['join'])) { | |
268 $join .= $funcs['join']; | |
269 } | |
270 if (isset($funcs['value'])) { | |
271 $value = $funcs['value']; | |
272 } | |
273 } | |
274 break; | |
265 } | 275 } |
266 $args[] = $value; | 276 $args[] = $value; |
267 } | 277 } |
268 $where = count($where) ? 'WHERE '. implode(' AND ', $where) : ''; | 278 $where = count($where) ? 'WHERE '. implode(' AND ', $where) : ''; |
269 | 279 |
281 $options = array( | 291 $options = array( |
282 'pending-1' => t('pending'), | 292 'pending-1' => t('pending'), |
283 'approved-1' => t('approved'), | 293 'approved-1' => t('approved'), |
284 'active-1' => t('active'), | 294 'active-1' => t('active'), |
285 'offline-1' => t('offline'), | 295 'offline-1' => t('offline'), |
286 'unpublished-1' => t('unpublished'), | |
287 'expired-1' => t('expired'), | 296 'expired-1' => t('expired'), |
288 'denied-1' => t('denied'), | 297 'denied-1' => t('denied'), |
289 'pending-0' => t('not pending'), | 298 'pending-0' => t('not pending'), |
290 'approved-0' => t('not approved'), | 299 'approved-0' => t('not approved'), |
291 'active-0' => t('not active'), | 300 'active-0' => t('not active'), |
292 'offline-0' => t('not offline'), | 301 'offline-0' => t('not offline'), |
293 'unpublished-0' => t('not unpublished'), | |
294 'expired-0' => t('not expired'), | 302 'expired-0' => t('not expired'), |
295 'denied-0' => t('not denied') | 303 'denied-0' => t('not denied') |
296 ); | 304 ); |
297 | 305 |
298 $filters['status'] = array( | 306 $filters['status'] = array( |
313 $options[$term->tid] = check_plain($term->name); | 321 $options[$term->tid] = check_plain($term->name); |
314 } | 322 } |
315 $filters['group'] = array('title' => t('group'), 'options' => $options); | 323 $filters['group'] = array('title' => t('group'), 'options' => $options); |
316 } | 324 } |
317 | 325 |
326 $filters = array_merge($filters, module_invoke_all('adapi', 'admin_filters', array())); | |
318 return $filters; | 327 return $filters; |
319 } | 328 } |
320 | 329 |
321 /** | 330 /** |
322 * Theme ad administration filter selector. | 331 * Theme ad administration filter selector. |
468 $_SESSION['ad_overview_filter'] = array(); | 477 $_SESSION['ad_overview_filter'] = array(); |
469 break; | 478 break; |
470 } | 479 } |
471 } | 480 } |
472 | 481 |
473 | |
474 /** | |
475 * | |
476 */ | |
477 function ad_admin_statistics($form_state) { | |
478 $groups = ad_groups_list(TRUE); | |
479 foreach ($groups as $tid => $group) { | |
480 if ($tid) { | |
481 $ads = db_result(db_query("SELECT count(aid) FROM {ads} a JOIN {term_node} t ON a.aid = t.nid WHERE t.tid = %d AND adstatus = 'active'", $tid)); | |
482 $filter = "= ". $tid; | |
483 } | |
484 else { | |
485 $ads = db_result(db_query("SELECT count(aid) FROM {ads} a LEFT JOIN {term_node} t ON a.aid = t.nid WHERE t.tid IS NULL AND adstatus = 'active'")); | |
486 $filter = "IS NULL"; | |
487 } | |
488 if (!$ads) { | |
489 continue; | |
490 } | |
491 | |
492 $form[$group->name] = array( | |
493 '#type' => 'fieldset', | |
494 '#title' => check_plain($group->name), | |
495 '#collapsible' => TRUE, | |
496 ); | |
497 | |
498 // Get overall global statistics. | |
499 $statistics['global']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND n.tid %s", $filter)); | |
500 $statistics['global']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND n.tid %s", $filter)); | |
501 | |
502 // Get overall statistics for this year and last year. | |
503 $this_year = date('Y000000'); | |
504 $last_year = date('Y') - 1 .'000000'; | |
505 $statistics['last_year']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND date <= %d AND n.tid %s", $last_year, $this_year, $filter)); | |
506 $statistics['last_year']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND date <= %d AND n.tid %s", $last_year, $this_year, $filter)); | |
507 $statistics['this_year']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND n.tid %s", $this_year, $filter)); | |
508 $statistics['this_year']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND n.tid %s", $this_year, $filter)); | |
509 | |
510 // Get statistics for this month and last month. | |
511 $this_month = date('Ym0000'); | |
512 $last_month = date('m') - 1; | |
513 if ($last_month == 0) { | |
514 $last_month = date('Y') - 1 .'120000'; | |
515 } | |
516 else { | |
517 $last_month = date('Y') . ($last_month < 10 ? '0' : '') . $last_month .'0000'; | |
518 } | |
519 $statistics['last_month']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND date <= %d AND n.tid %s", $last_month, $this_month, $filter)); | |
520 $statistics['last_month']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND date <= %d AND n.tid %s", $last_month, $this_month, $filter)); | |
521 $statistics['this_month']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND n.tid %s", $this_month, $filter)); | |
522 $statistics['this_month']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND n.tid %s", $this_month, $filter)); | |
523 | |
524 // Get statistics for this week. | |
525 $this_week_start = date('Ymd00', time() - 60*60*24*6); | |
526 $statistics['this_week']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND n.tid %s", $this_week_start, $filter)); | |
527 $statistics['this_week']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND n.tid %s", $this_week_start, $filter)); | |
528 | |
529 // Get statistics for yesterday and today. | |
530 $yesterday_start = date('Ymd00', time() - 60*60*24); | |
531 $yesterday_end = date('Ymd24', time() - 60*60*24); | |
532 $today_start = date('Ymd00', time()); | |
533 $statistics['yesterday']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND date <= %d AND n.tid %s", $yesterday_start, $yesterday_end, $filter)); | |
534 $statistics['yesterday']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND date <= %d AND n.tid %s", $yesterday_start, $yesterday_end, $filter)); | |
535 $statistics['today']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date >= %d AND n.tid %s", $today_start, $filter)); | |
536 $statistics['today']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date >= %d AND n.tid %s", $today_start, $filter)); | |
537 | |
538 // Get statistics for this hour and the last hour. | |
539 $last_hour = date('YmdH', time() - 60*60); | |
540 $this_hour = date('YmdH', time()); | |
541 $statistics['last_hour']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date = %d AND n.tid %s", $last_hour, $filter)); | |
542 $statistics['last_hour']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date = %d AND n.tid %s", $last_hour, $filter)); | |
543 $statistics['this_hour']['views'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'view' AND date = %d AND n.tid %s", $this_hour, $filter)); | |
544 $statistics['this_hour']['clicks'] = (int)db_result(db_query("SELECT SUM(s.count) FROM {ad_statistics} s LEFT JOIN {ads} a ON s.aid = a.aid LEFT JOIN {term_node} n ON a.aid = n.nid WHERE action = 'click' AND date = %d AND n.tid %s", $this_hour, $filter)); | |
545 | |
546 // TODO: Create this view and remove the && FALSE to enable this code. | |
547 if (module_exists('views') && FALSE) { | |
548 $form[$group->name]['statistics'] = array( | |
549 '#type' => 'markup', | |
550 '#value' => '<p>'. format_plural($ads, 'There is <a href="!url">1 active ad</a> in this group.', 'There are <a href="!url">%count</a> active ads in this group.', array('!url' => url('ad/'. $group->tid .'/group'))) .'</p>'. theme('ad_statistics_display', $statistics), | |
551 ); | |
552 } | |
553 else { | |
554 $form[$group->name]['statistics'] = array( | |
555 '#type' => 'markup', | |
556 '#value' => '<p>'. format_plural($ads, 'There is 1 active ad in this group.', 'There are @count active ads in this group.') .'</p>'. theme('ad_statistics_display', $statistics), | |
557 ); | |
558 } | |
559 } | |
560 | |
561 if (!isset($form) || count($form) == 0) { | |
562 $form['header'] = array( | |
563 '#type' => 'markup', | |
564 '#value' => '<p>'. t('There are no active ads.') .'</p>', | |
565 ); | |
566 } | |
567 | |
568 return $form; | |
569 } | |
570 | |
571 /** | 482 /** |
572 * Display a form for the ad module settings. | 483 * Display a form for the ad module settings. |
573 */ | 484 */ |
574 function ad_admin_configure_settings($form_state) { | 485 function ad_admin_configure_settings($form_state) { |
575 _ad_check_installation(); | 486 _ad_check_installation(); |