Mercurial > defr > drupal > ad
comparison channel/ad_channel.module @ 7:6aeff3329e01 ad
maj module ad 2.1rc1
author | piotre |
---|---|
date | Mon, 20 Jul 2009 13:54:40 +0000 |
parents | 0d1c70d51fbe |
children | 32c1a7d9e1fa |
comparison
equal
deleted
inserted
replaced
6:b7653861e0b4 | 7:6aeff3329e01 |
---|---|
1 <?php | 1 <?php |
2 // $Id: ad_channel.module,v 1.1.4.21 2009/04/22 15:14:46 jeremy Exp $ | 2 // $Id: ad_channel.module,v 1.1.4.26 2009/07/17 21:29:37 jeremy Exp $ |
3 | 3 |
4 /** | 4 /** |
5 * @file | 5 * @file |
6 * Ad Channel module. | 6 * Ad Channel module. |
7 * | 7 * |
140 ); | 140 ); |
141 } | 141 } |
142 foreach ($channels as $channel) { | 142 foreach ($channels as $channel) { |
143 if (is_object($form['#node'])) { | 143 if (is_object($form['#node'])) { |
144 $node = $form['#node']; | 144 $node = $form['#node']; |
145 $default = isset($node->channel[$channel->chid]); | 145 $default_value = isset($node->channel[$channel->chid]); |
146 } | 146 } |
147 else { | 147 else { |
148 $default = 0; | 148 $default_value = 0; |
149 } | |
150 if (!$default_value) { | |
151 $channel = _ad_channel_get_channels($channel->chid); | |
152 if (isset($channel->inventory) && $channel->inventory > 0) { | |
153 $num_ads = _ad_channel_get_channel_active_ad_count($channel->chid); | |
154 if($num_ads + 1 > $channel->inventory) { | |
155 $disabled = TRUE; | |
156 } | |
157 } | |
149 } | 158 } |
150 $form['channel'][$container->conid]["channel-$channel->chid"] = array( | 159 $form['channel'][$container->conid]["channel-$channel->chid"] = array( |
151 '#type' => 'checkbox', | 160 '#type' => 'checkbox', |
152 '#title' => $channel->name, | 161 '#title' => $channel->name, |
153 '#description' => $channel->description, | 162 '#description' => $channel->description, |
154 '#default_value' => $default, | 163 '#default_value' => $default_value, |
164 '#disabled' => isset($disabled) ? $disabled : FALSE, | |
155 ); | 165 ); |
156 } | 166 } |
157 } | 167 } |
158 } | 168 } |
159 $node = node_load($form['nid']['#value']); | 169 $node = node_load($form['nid']['#value']); |
180 '#title' => t('Premiere'), | 190 '#title' => t('Premiere'), |
181 '#description' => t('An active premiere advertisement will override all other non-premiere advertisements in the same channel. As long as one or more premiere advertisements are active in a channel, non-premiere advertisements will not be displayed in that channel.'), | 191 '#description' => t('An active premiere advertisement will override all other non-premiere advertisements in the same channel. As long as one or more premiere advertisements are active in a channel, non-premiere advertisements will not be displayed in that channel.'), |
182 '#default_value' => isset($node->premiere) ? $node->premiere : FALSE, | 192 '#default_value' => isset($node->premiere) ? $node->premiere : FALSE, |
183 ); | 193 ); |
184 $form['priority']['#weight'] = -1; | 194 $form['priority']['#weight'] = -1; |
195 | |
196 $form['inventory'] = array( | |
197 '#type' => 'fieldset', | |
198 '#title' => t('Inventory'), | |
199 '#collapsible' => TRUE, | |
200 '#collapsed' => FALSE, | |
201 ); | |
202 | |
203 $form['inventory']['remnant'] = array( | |
204 '#type' => 'checkbox', | |
205 '#title' => t('Remnant'), | |
206 '#description' => t('An advertisement marked as a remnant is eligible for display in any channel where the number of assigned advertisements for the channel is less than the inventory level specified.'), | |
207 '#default_value' => isset($node->remnant) ? $node->remnant : FALSE, | |
208 ); | |
185 } | 209 } |
186 else if ($form_id == 'ad_filter_form') { | 210 else if ($form_id == 'ad_filter_form') { |
187 $session = &$_SESSION['ad_overview_filter']; | 211 $session = &$_SESSION['ad_overview_filter']; |
188 $session = is_array($session) ? $session : array(); | 212 $session = is_array($session) ? $session : array(); |
189 | 213 |
239 $form['channels'] = array( | 263 $form['channels'] = array( |
240 '#type' => 'fieldset', | 264 '#type' => 'fieldset', |
241 '#title' => t('Channels'), | 265 '#title' => t('Channels'), |
242 ); | 266 ); |
243 $options = array(); | 267 $options = array(); |
244 $options['any'] = t('- Any -'); | 268 $options['any'] = t('<any>'); |
269 $options['none'] = t('<none>'); | |
245 foreach ($channels as $chan) { | 270 foreach ($channels as $chan) { |
246 $options[$chan->chid] = $chan->name; | 271 $options[$chan->chid] = $chan->name; |
247 } | 272 } |
248 $form['channels']['channel'] = array( | 273 $form['channels']['channel'] = array( |
249 '#type' => 'select', | 274 '#type' => 'select', |
300 * with channels. | 325 * with channels. |
301 */ | 326 */ |
302 function ad_channel_ad_admin_ads($form) { | 327 function ad_channel_ad_admin_ads($form) { |
303 $list = variable_get('ad_channel_admin_list', AD_CHANNEL_LIST_CHANNEL); | 328 $list = variable_get('ad_channel_admin_list', AD_CHANNEL_LIST_CHANNEL); |
304 | 329 |
330 // Conditionally build the header based on list type and | |
331 // the availability of probability values from the | |
332 // ad_weight_probability module | |
333 $header = array(theme('table_select_header_cell'), t('Title')); | |
334 | |
305 // Overview table: | 335 // Overview table: |
306 if ($list == AD_CHANNEL_LIST_CHANNEL) { | 336 if ($list != AD_CHANNEL_LIST_CHANNEL) { |
307 $header = array(theme('table_select_header_cell'), t('Title'), t('Channel'), t('Type'), t('Status'), t('Operations')); | 337 $header[] = t('Group'); |
308 } | 338 } |
309 else { | 339 |
310 $header = array(theme('table_select_header_cell'), t('Title'), t('Group'), t('Channel'), t('Type'), t('Status'), t('Operations')); | 340 $header = array_merge($header, array(t('Channel'))); |
311 } | 341 |
342 if (isset($form['probability']) && is_array($form['probability'])) { | |
343 $header[] = t('Probability'); | |
344 } | |
345 | |
346 $header[] = t('Type'); | |
347 $header[] = t('Status'); | |
348 $header[] = t('Operations'); | |
312 | 349 |
313 $output = drupal_render($form['options']); | 350 $output = drupal_render($form['options']); |
314 if (isset($form['title']) && is_array($form['title'])) { | 351 if (isset($form['title']) && is_array($form['title'])) { |
315 foreach (element_children($form['title']) as $key) { | 352 foreach (element_children($form['title']) as $key) { |
316 $row = array(); | 353 $row = array(); |
318 $row[] = drupal_render($form['title'][$key]); | 355 $row[] = drupal_render($form['title'][$key]); |
319 if ($list == AD_CHANNEL_LIST_BOTH) { | 356 if ($list == AD_CHANNEL_LIST_BOTH) { |
320 $row[] = drupal_render($form['group'][$key]); | 357 $row[] = drupal_render($form['group'][$key]); |
321 } | 358 } |
322 $row[] = drupal_render($form['channel'][$key]); | 359 $row[] = drupal_render($form['channel'][$key]); |
360 if (isset($form['probability']) && is_array($form['probability'])) { | |
361 $row[] = drupal_render($form['probability'][$key]); | |
362 } | |
323 $row[] = drupal_render($form['adtype'][$key]); | 363 $row[] = drupal_render($form['adtype'][$key]); |
324 $row[] = drupal_render($form['adstatus'][$key]); | 364 $row[] = drupal_render($form['adstatus'][$key]); |
325 $row[] = drupal_render($form['operations'][$key]); | 365 $row[] = drupal_render($form['operations'][$key]); |
326 $rows[] = $row; | 366 $rows[] = $row; |
327 } | 367 } |
359 $any = FALSE; | 399 $any = FALSE; |
360 foreach ($form_state['values']['channel'] as $chid) { | 400 foreach ($form_state['values']['channel'] as $chid) { |
361 if (is_numeric($chid)) { | 401 if (is_numeric($chid)) { |
362 $channels[] = $chid; | 402 $channels[] = $chid; |
363 } | 403 } |
404 else if ($chid == 'none') { | |
405 $channels[-1] = 'none'; | |
406 } | |
364 else { | 407 else { |
365 $any = TRUE; | 408 $any = TRUE; |
366 } | 409 } |
367 } | 410 } |
368 if (!$any && !empty($channels)) { | 411 if (!$any && !empty($channels)) { |
380 /** | 423 /** |
381 * Filter reports by selected channel. | 424 * Filter reports by selected channel. |
382 */ | 425 */ |
383 function ad_channel_adreport($join, $where, $args, $select) { | 426 function ad_channel_adreport($join, $where, $args, $select) { |
384 if (isset($_SESSION['ad_report_channel']) && is_array($_SESSION['ad_report_channel']) && !empty($_SESSION['ad_report_channel'])) { | 427 if (isset($_SESSION['ad_report_channel']) && is_array($_SESSION['ad_report_channel']) && !empty($_SESSION['ad_report_channel'])) { |
385 $join = array('LEFT JOIN {ad_channel_node} acn ON acn.nid = a.aid'); | 428 // Check if we're filtering by <none> |
386 $where = array('acn.chid IN (%s)'); | 429 if (isset($_SESSION['ad_report_channel'][-1])) { |
387 $args = array(implode(',', $_SESSION['ad_report_channel'])); | 430 $join = array('LEFT JOIN {ad_channel_node} acn ON acn.nid = a.aid'); |
388 return array('join' => $join, 'where' => $where, 'args' => $args); | 431 $channels = $_SESSION['ad_report_channel']; |
432 unset($channels[-1]); | |
433 // Check if we're filtering on <none> and one or more channels | |
434 if (count($channels)) { | |
435 $where = array('(ISNULL(acn.chid) OR acn.chid IN (%s))'); | |
436 $args = array(implode(',', $channels)); | |
437 } | |
438 else { | |
439 $where = array('ISNULL(acn.chid)'); | |
440 } | |
441 return array('join' => $join, 'where' => $where, 'args' => $args); | |
442 } | |
443 // Filtering by one or more channels | |
444 else { | |
445 $join = array('LEFT JOIN {ad_channel_node} acn ON acn.nid = a.aid'); | |
446 $where = array('acn.chid IN (%s)'); | |
447 $args = array(implode(',', $_SESSION['ad_report_channel'])); | |
448 return array('join' => $join, 'where' => $where, 'args' => $args); | |
449 } | |
389 } | 450 } |
390 } | 451 } |
391 | 452 |
392 /** | 453 /** |
393 * Implement hook _adapi. | 454 * Implement hook _adapi. |
408 $options = array( | 469 $options = array( |
409 '0' => t('false'), | 470 '0' => t('false'), |
410 '1' => t('true')); | 471 '1' => t('true')); |
411 $filters['premiere'] = array( | 472 $filters['premiere'] = array( |
412 'title' => t('premiere'), | 473 'title' => t('premiere'), |
474 'options' => $options, | |
475 ); | |
476 $filters['remnant'] = array( | |
477 'title' => t('remnant'), | |
413 'options' => $options, | 478 'options' => $options, |
414 ); | 479 ); |
415 return $filters; | 480 return $filters; |
416 case 'admin_filter_query': | 481 case 'admin_filter_query': |
417 if (is_array($node)) { | 482 if (is_array($node)) { |
431 'where' => 'p.priority = %d', | 496 'where' => 'p.priority = %d', |
432 'join' => 'INNER JOIN {ad_priority} p ON n.nid = p.aid ', | 497 'join' => 'INNER JOIN {ad_priority} p ON n.nid = p.aid ', |
433 'value' => $value, | 498 'value' => $value, |
434 )); | 499 )); |
435 } | 500 } |
501 else if ($key == 'remnant') { | |
502 return array( | |
503 'remnant' => array( | |
504 'where' => 'r.remnant = %d', | |
505 'join' => 'INNER JOIN {ad_channel_remnant} r ON n.nid = r.aid ', | |
506 'value' => $value, | |
507 )); | |
508 } | |
436 } | 509 } |
437 break; | 510 break; |
438 } | 511 } |
439 } | 512 } |
440 | 513 |
447 return _ad_channel_view_node($node); | 520 return _ad_channel_view_node($node); |
448 case 'load': | 521 case 'load': |
449 return _ad_channel_load_node($node); | 522 return _ad_channel_load_node($node); |
450 case 'insert': | 523 case 'insert': |
451 case 'update': | 524 case 'update': |
452 if (is_object($node) && isset($node->adtype) && | 525 if (is_object($node) && isset($node->adtype) && isset($node->nid)) { |
453 isset($node->probability) && isset($node->nid)) { | |
454 return _ad_channel_save_node($node); | 526 return _ad_channel_save_node($node); |
455 } | 527 } |
456 break; | 528 break; |
457 case 'delete': | 529 case 'delete': |
458 return _ad_channel_delete_node($node); | 530 return _ad_channel_delete_node($node); |
475 $ads[$ad->aid][$channel->chid] = $channel->chid; | 547 $ads[$ad->aid][$channel->chid] = $channel->chid; |
476 //$ads[$channel->chid][$ad->aid] = $ad->aid; | 548 //$ads[$channel->chid][$ad->aid] = $ad->aid; |
477 } | 549 } |
478 } | 550 } |
479 $channels = array(); | 551 $channels = array(); |
480 $result = db_query('SELECT chid, display, urls, no_channel_weight FROM {ad_channel}'); | 552 $result = db_query('SELECT chid, display, urls, no_channel_percent, inventory FROM {ad_channel}'); |
481 while ($channel = db_fetch_object($result)) { | 553 while ($channel = db_fetch_object($result)) { |
482 $channels[$channel->chid] = $channel; | 554 $channels[$channel->chid] = $channel; |
483 } | 555 } |
484 $result = db_query("SELECT p.aid, p.priority FROM {ads} a LEFT JOIN {ad_priority} p ON a.aid = p.aid WHERE a.adstatus = 'active' AND p.priority = 1"); | 556 $result = db_query("SELECT p.aid, p.priority FROM {ads} a LEFT JOIN {ad_priority} p ON a.aid = p.aid WHERE a.adstatus = 'active' AND p.priority = 1"); |
485 $premiere = array(); | 557 $premiere = array(); |
486 while ($priority = db_fetch_object($result)) { | 558 while ($priority = db_fetch_object($result)) { |
487 $premiere[$priority->aid] = $priority->aid; | 559 $premiere[$priority->aid] = $priority->aid; |
488 } | 560 } |
561 $result = db_query("SELECT r.aid, r.remnant FROM {ads} a LEFT JOIN {ad_channel_remnant} r ON a.aid = r.aid WHERE a.adstatus = 'active' AND r.remnant = 1"); | |
562 $remnants = array(); | |
563 while ($remnant = db_fetch_object($result)) { | |
564 $remnants[$remnant->aid] = $remnant->aid; | |
565 } | |
489 $cache['channel']['ads'] = $ads; | 566 $cache['channel']['ads'] = $ads; |
490 $cache['channel']['channels'] = $channels; | 567 $cache['channel']['channels'] = $channels; |
491 $cache['channel']['display'] = variable_get('ad_channel_display', 0); | 568 $cache['channel']['display'] = variable_get('ad_channel_display', 0); |
492 $cache['premiere'] = $premiere; | 569 $cache['premiere'] = $premiere; |
570 $cache['remnant'] = $remnants; | |
493 | 571 |
494 $cache['channel']['hook_filter'] = array( | 572 $cache['channel']['hook_filter'] = array( |
495 'weight' => 0, | 573 'weight' => 0, |
496 'file' => drupal_get_path('module', 'ad_channel') .'/ad_channel.inc', | 574 'file' => drupal_get_path('module', 'ad_channel') .'/ad_channel.inc', |
497 'function' => 'ad_channel_cache_filter', | 575 'function' => 'ad_channel_cache_filter', |
560 $node->content['premiere'] = array( | 638 $node->content['premiere'] = array( |
561 '#value' => theme('box', t('Premiere'), $output), | 639 '#value' => theme('box', t('Premiere'), $output), |
562 '#weight' => 1, | 640 '#weight' => 1, |
563 ); | 641 ); |
564 } | 642 } |
643 if (isset($node->remnant)) { | |
644 if (isset($node->remnant) && $node->remnant == 1) { | |
645 $output = t('This is a remnant advertisement.'); | |
646 $node->content['remnant'] = array( | |
647 '#value' => theme('box', t('Remnant'), $output), | |
648 '#weight' => 1, | |
649 ); | |
650 } | |
651 } | |
565 } | 652 } |
566 } | 653 } |
567 | 654 |
568 /** | 655 /** |
569 * Load channels associated with specified node. | 656 * Load channels associated with specified node. |
574 while ($chid = db_fetch_object($result)) { | 661 while ($chid = db_fetch_object($result)) { |
575 $output['channel'][$chid->chid] = $chid->chid; | 662 $output['channel'][$chid->chid] = $chid->chid; |
576 } | 663 } |
577 // currently 0 or 1, with one being a 'premiere' advertisement. | 664 // currently 0 or 1, with one being a 'premiere' advertisement. |
578 $output['premiere'] = (int)db_result(db_query('SELECT priority FROM {ad_priority} WHERE aid = %d', $node->nid)); | 665 $output['premiere'] = (int)db_result(db_query('SELECT priority FROM {ad_priority} WHERE aid = %d', $node->nid)); |
666 $output['remnant'] = (int)db_result(db_query('SELECT remnant FROM {ad_channel_remnant} WHERE aid = %d', $node->nid)); | |
579 return $output; | 667 return $output; |
580 } | 668 } |
581 | 669 |
582 /** | 670 /** |
583 * Save channels associated with added or updated node. | 671 * Save channels associated with added or updated node. |
593 db_query('UPDATE {ad_priority} SET priority = %d WHERE aid = %d', isset($node->premiere) ? $node->premiere : 0, $node->nid); | 681 db_query('UPDATE {ad_priority} SET priority = %d WHERE aid = %d', isset($node->premiere) ? $node->premiere : 0, $node->nid); |
594 if (!db_affected_rows()) { | 682 if (!db_affected_rows()) { |
595 db_query('INSERT INTO {ad_priority} (aid, priority) VALUES(%d, %d)', $node->nid, isset($node->premiere) ? $node->premiere : 0); | 683 db_query('INSERT INTO {ad_priority} (aid, priority) VALUES(%d, %d)', $node->nid, isset($node->premiere) ? $node->premiere : 0); |
596 } | 684 } |
597 } | 685 } |
686 db_query('UPDATE {ad_channel_remnant} SET remnant = %d WHERE aid = %d', isset($node->remnant) ? $node->remnant : 0, $node->nid); | |
687 if (!db_affected_rows()) { | |
688 db_query('INSERT INTO {ad_channel_remnant} (aid, remnant) VALUES(%d, %d)', $node->nid, isset($node->remnant) ? $node->remnant : 0); | |
689 } | |
598 } | 690 } |
599 | 691 |
600 /** | 692 /** |
601 * Delete channel information associated with node. | 693 * Delete channel information associated with node. |
602 */ | 694 */ |
610 /** | 702 /** |
611 * Be sure that the enabled channels actually can be enabled. | 703 * Be sure that the enabled channels actually can be enabled. |
612 */ | 704 */ |
613 function _ad_channel_validate_nodes($node) { | 705 function _ad_channel_validate_nodes($node) { |
614 $channels = _ad_channel_get_enabled($node); | 706 $channels = _ad_channel_get_enabled($node); |
707 | |
708 foreach ($channels as $chid) { | |
709 $channel = _ad_channel_get_channels($chid); | |
710 if(isset($channel->inventory) && $channel->inventory > 0) { | |
711 $num_ads = _ad_channel_get_channel_active_ad_count($chid); | |
712 if ($num_ads + 1 >= $channel->inventory) { | |
713 form_set_error("channel[$channel->conid][channel-$chid]", t('You may not assign more than !inventory to %name.', array('!inventory' => format_plural($channel->inventory, '1 advertisement', '@count advertisements'), '%name' => $channel->name))); | |
714 } | |
715 } | |
716 } | |
717 | |
615 $limit = variable_get('ad_channel_ad_limit', 0); | 718 $limit = variable_get('ad_channel_ad_limit', 0); |
616 if ($limit && sizeof($channels) > $limit) { | 719 if ($limit && sizeof($channels) > $limit) { |
617 $quantity_error = TRUE; | 720 $quantity_error = TRUE; |
618 } | 721 } |
619 else { | 722 else { |
678 drupal_add_css(drupal_get_path('module', 'ad_channel') .'/ad_channel.css'); | 781 drupal_add_css(drupal_get_path('module', 'ad_channel') .'/ad_channel.css'); |
679 | 782 |
680 $containers = _ad_channel_get_containers(); | 783 $containers = _ad_channel_get_containers(); |
681 $rows = array(); | 784 $rows = array(); |
682 if (count($containers)) { | 785 if (count($containers)) { |
683 $header = array(t('Name'), t('Options')); | 786 $header = array(t('Name'), t('Inventory'), t('Options')); |
684 $output = '<div id="ad-channel">'; | 787 $output = '<div id="ad-channel">'; |
685 foreach ($containers as $conid => $container) { | 788 foreach ($containers as $conid => $container) { |
686 $channels = _ad_channel_get_container_channels($conid); | 789 $channels = _ad_channel_get_container_channels($conid); |
687 if ($conid > 0 || count($channels)) { | 790 if ($conid > 0 || count($channels)) { |
688 if ($conid > 0) { | 791 if ($conid > 0) { |
692 $description = '<div class="name">'. $container->name . "</div>\n"; | 795 $description = '<div class="name">'. $container->name . "</div>\n"; |
693 } | 796 } |
694 if ($container->description) { | 797 if ($container->description) { |
695 $description .= '<div class="description">'. filter_xss_admin($container->description) ."</div>\n"; | 798 $description .= '<div class="description">'. filter_xss_admin($container->description) ."</div>\n"; |
696 } | 799 } |
697 $rows[] = array(array('data' => $description, 'class' => 'container', 'colspan' => 2)); | 800 $rows[] = array(array('data' => $description, 'class' => 'container', 'colspan' => 3)); |
698 } | 801 } |
699 foreach ($channels as $chid => $channel) { | 802 foreach ($channels as $chid => $channel) { |
700 $description = "<div style=\"margin-left: 30px;\">\n"; | 803 $description = "<div style=\"margin-left: 30px;\">\n"; |
701 $description .= ' <div class="name">' . $channel->name . "</div>\n"; | 804 $description .= ' <div class="name">' . $channel->name . "</div>\n"; |
702 if ($channel->description) { | 805 if ($channel->description) { |
703 $description .= ' <div class="description">'. filter_xss_admin($channel->description) ."</div>\n"; | 806 $description .= ' <div class="description">'. filter_xss_admin($channel->description) ."</div>\n"; |
704 } | 807 } |
705 $description .= "</div>\n"; | 808 $description .= "</div>\n"; |
809 $inventory = ' <div class="inventory">' . $channel->inventory . "</div>\n"; | |
706 $rows[] = array( | 810 $rows[] = array( |
707 array('data' => $description, 'class' => 'channel'), | 811 array('data' => $description, 'class' => 'channel'), |
812 array('data' => $inventory, 'class' => 'channel'), | |
708 l(t('edit'), "admin/content/ad/channel/channel/$channel->chid/edit") .' '. l(t('delete'), "admin/content/ad/channel/channel/$channel->chid/delete"), | 813 l(t('edit'), "admin/content/ad/channel/channel/$channel->chid/edit") .' '. l(t('delete'), "admin/content/ad/channel/channel/$channel->chid/delete"), |
709 ); | 814 ); |
710 } | 815 } |
711 } | 816 } |
712 $output .= theme('table', $header, $rows); | 817 $output .= theme('table', $header, $rows); |
747 */ | 852 */ |
748 function _ad_channel_get_container_channels($conid = 0) { | 853 function _ad_channel_get_container_channels($conid = 0) { |
749 static $cache; | 854 static $cache; |
750 if (!isset($cache[$conid])) { | 855 if (!isset($cache[$conid])) { |
751 $channels = array(); | 856 $channels = array(); |
752 $result = db_query('SELECT chid, name, description, weight FROM {ad_channel} WHERE conid = %d ORDER BY weight ASC', $conid); | 857 $result = db_query('SELECT chid, name, description, weight, inventory FROM {ad_channel} WHERE conid = %d ORDER BY weight ASC', $conid); |
753 while ($channel = db_fetch_object($result)) { | 858 while ($channel = db_fetch_object($result)) { |
754 $channels[$channel->chid] = $channel; | 859 $channels[$channel->chid] = $channel; |
755 } | 860 } |
756 $cache[$conid] = $channels; | 861 $cache[$conid] = $channels; |
757 } | 862 } |
954 '#title' => t('Weight'), | 1059 '#title' => t('Weight'), |
955 '#description' => t('When listing channels, those with the lighter (smaller) weights get listed before channels with heavier (larger) weights. Channels with equal weights are sorted alphabetically.'), | 1060 '#description' => t('When listing channels, those with the lighter (smaller) weights get listed before channels with heavier (larger) weights. Channels with equal weights are sorted alphabetically.'), |
956 '#default_value' => $chid ? $channel->weight : 0, | 1061 '#default_value' => $chid ? $channel->weight : 0, |
957 ); | 1062 ); |
958 | 1063 |
1064 // Inventory for remnant management | |
1065 $form['channel_inventory'] = array( | |
1066 '#type' => 'fieldset', | |
1067 '#title' => t('Inventory'), | |
1068 '#collapsible' => TRUE, | |
1069 '#collapsed' => FALSE | |
1070 ); | |
1071 $form['channel_inventory']['inventory'] = array( | |
1072 '#type' => 'textfield', | |
1073 '#title' => t('Level'), | |
1074 '#size' => 10, | |
1075 '#maxlength' => 10, | |
1076 '#required' => FALSE, | |
1077 '#description' => t('Entering an inventory value will limit the number of advertisements that may be assigned to this channel. As well, if fewer advertisements than the inventory value are assigned to this channel, advertisements marked as remnants will be used to reach the assigned inventory level.'), | |
1078 '#default_value' => $chid ? $channel->inventory : 0, | |
1079 ); | |
1080 | |
959 // URL rules | 1081 // URL rules |
960 $form['URL_rules'] = array( | 1082 $form['URL_rules'] = array( |
961 '#type' => 'fieldset', | 1083 '#type' => 'fieldset', |
962 '#title' => t('URL rules'), | 1084 '#title' => t('URL rules'), |
963 '#collapsible' => TRUE, | 1085 '#collapsible' => TRUE, |
970 '#default_value' => $chid ? $channel->display : 0, | 1092 '#default_value' => $chid ? $channel->display : 0, |
971 ); | 1093 ); |
972 $form['URL_rules']['urls'] = array( | 1094 $form['URL_rules']['urls'] = array( |
973 '#type' => 'textarea', | 1095 '#type' => 'textarea', |
974 '#title' => t('Paths'), | 1096 '#title' => t('Paths'), |
975 '#description' => t("Enter one URL per line, including the 'http://' or 'https:/'. The '*' character is a wildcard. Example URLs are <em>http://www.example.com/blog</em> for the blog page and <em>http://www.example.com/blog/*</em> for every personal blog."), | 1097 '#description' => t("Enter one URL per line. If serving ads locally use Drupal relative paths. If serving ads remotely include the 'http://' or 'https:/'. Use '<front>' to specify the front page. The '*' character is a wildcard. Example URLs are <em>blog</em> for the blog page and <em>blog/*</em> for every personal blog on your local website."), |
976 '#default_value' => $chid ? unserialize($channel->urls) : '', | 1098 '#default_value' => $chid ? unserialize($channel->urls) : '', |
977 ); | 1099 ); |
978 | 1100 |
979 // Group rules | 1101 // Group rules |
980 $groups = taxonomy_get_tree(_ad_get_vid()); | 1102 $groups = taxonomy_get_tree(_ad_get_vid()); |
1021 '#prefix' => '<div>', | 1143 '#prefix' => '<div>', |
1022 '#suffix' => '</div>', | 1144 '#suffix' => '</div>', |
1023 '#value' => t('You will need to set "!variable" to %value for these %type ad rules to be applicable. Currently these settings are doing nothing.', array('!variable' => l(t('display advertisements not assigned to any channel'), 'admin/content/ad/channel/settings'), '%value' => t('always'), '%type' => 'not-in-channel')), | 1145 '#value' => t('You will need to set "!variable" to %value for these %type ad rules to be applicable. Currently these settings are doing nothing.', array('!variable' => l(t('display advertisements not assigned to any channel'), 'admin/content/ad/channel/settings'), '%value' => t('always'), '%type' => 'not-in-channel')), |
1024 ); | 1146 ); |
1025 } | 1147 } |
1026 $form['nonchannel_rules']['no_channel_weight'] = array( | 1148 $form['nonchannel_rules']['no_channel_percent'] = array( |
1027 '#type' => 'select', | 1149 '#type' => 'select', |
1028 '#title' => t('Probability'), | 1150 '#title' => t('Percentage'), |
1029 '#options' => _ad_channel_probabilities(), | 1151 '#options' => _ad_channel_percentages(), |
1030 '#default_value' => $channel->no_channel_weight ? $channel->no_channel_weight : 100, | 1152 '#default_value' => $chid ? $channel->no_channel_percent : 10, |
1031 '#description' => t('The greater the probability, the more frequently advertisements that aren\'t in any channel will be displayed along with ads in this channel. For example, if set to 2, advertisements without any channel will be displayed twice as often as advertisements assigned to this channel. If set to 1/2, advertisements without any channel will be displayed half as often as advertisements assigned to this channel. If set to 1, advertisements without any channel will be displayed as often as advertisements assigned to this channel.'), | 1153 '#description' => t('Choose the maximum percentage of not-in-channel advertisements allowable for display. For instance, selecting 10% indicates that 1 out of 10 advertisements will be selected from those not assigned to this channel.'), |
1032 ); | 1154 ); |
1033 | |
1034 if ($chid) { | 1155 if ($chid) { |
1035 $form['update'] = array( | 1156 $form['update'] = array( |
1036 '#type' => 'submit', | 1157 '#type' => 'submit', |
1037 '#value' => t('Update'), | 1158 '#value' => t('Update'), |
1038 ); | 1159 ); |
1086 else { | 1207 else { |
1087 $urls = ''; | 1208 $urls = ''; |
1088 } | 1209 } |
1089 switch ($form_state['values']['op']) { | 1210 switch ($form_state['values']['op']) { |
1090 case t('Create'): | 1211 case t('Create'): |
1091 db_query("INSERT INTO {ad_channel} (name, description, conid, weight, display, urls, groups, no_channel_weight) VALUES('%s', '%s', %d, %d, %d, '%s', '%s', %d)", $form_state['values']['name'], $form_state['values']['description'], $form_state['values']['conid'], $form_state['values']['weight'], $form_state['values']['display'], serialize($urls), serialize($form_state['values']['groups']), $form_state['values']['no_channel_weight']); | 1212 db_query("INSERT INTO {ad_channel} (name, description, conid, weight, display, no_channel_percent, urls, groups, inventory) VALUES('%s', '%s', %d, %d, %d, '%s', '%s', %d, %d)", $form_state['values']['name'], $form_state['values']['description'], $form_state['values']['conid'], $form_state['values']['weight'], $form_state['values']['display'], $form_state['values']['no_channel_percent'], serialize($urls), serialize($form_state['values']['groups']), $form_state['values']['inventory']); |
1092 drupal_set_message(t('The %name channel has been created.', array('%name' => $form_state['values']['name']))); | 1213 drupal_set_message(t('The %name channel has been created.', array('%name' => $form_state['values']['name']))); |
1093 break; | 1214 break; |
1094 case t('Update'): | 1215 case t('Update'): |
1095 $groups = array(); | 1216 $groups = array(); |
1096 // Don't store information about groups that no longer exist. | 1217 // Don't store information about groups that no longer exist. |
1100 if (isset($form_state['values']['groups'][$ad_group->tid])) { | 1221 if (isset($form_state['values']['groups'][$ad_group->tid])) { |
1101 $groups[$ad_group->tid] = $form_state['values']['groups'][$ad_group->tid]; | 1222 $groups[$ad_group->tid] = $form_state['values']['groups'][$ad_group->tid]; |
1102 } | 1223 } |
1103 } | 1224 } |
1104 } | 1225 } |
1105 db_query("UPDATE {ad_channel} SET name = '%s', description = '%s', conid = %d, weight = %d, display = %d, urls = '%s', groups = '%s', no_channel_weight = %d WHERE chid = %d", $form_state['values']['name'], $form_state['values']['description'], $form_state['values']['conid'], $form_state['values']['weight'], $form_state['values']['display'], serialize($urls), serialize($groups), $form_state['values']['no_channel_weight'], $form_state['values']['chid']); | 1226 db_query("UPDATE {ad_channel} SET name = '%s', description = '%s', conid = %d, weight = %d, display = %d, urls = '%s', groups = '%s', no_channel_percent = %d, inventory = %d WHERE chid = %d", $form_state['values']['name'], $form_state['values']['description'], $form_state['values']['conid'], $form_state['values']['weight'], $form_state['values']['display'], serialize($urls), serialize($groups), $form_state['values']['no_channel_percent'], $form_state['values']['inventory'], $form_state['values']['chid']); |
1106 drupal_set_message(t('The %name channel has been updated.', array('%name' => $form_state['values']['name']))); | 1227 drupal_set_message(t('The %name channel has been updated.', array('%name' => $form_state['values']['name']))); |
1107 break; | 1228 break; |
1108 case t('Delete'): | 1229 case t('Delete'): |
1109 drupal_goto('admin/content/ad/channel/channel/'. $form_state['values']['chid'] .'/delete'); | 1230 drupal_goto('admin/content/ad/channel/channel/'. $form_state['values']['chid'] .'/delete'); |
1110 } | 1231 } |
1155 200 => t('2'), | 1276 200 => t('2'), |
1156 300 => t('3'), | 1277 300 => t('3'), |
1157 400 => t('4'), | 1278 400 => t('4'), |
1158 ); | 1279 ); |
1159 } | 1280 } |
1281 | |
1282 /** | |
1283 * Available percentages | |
1284 */ | |
1285 function _ad_channel_percentages() { | |
1286 $options = array(); | |
1287 for($i = 5; $i <= 95; $i += 5) { | |
1288 $options[$i] = t($i.'%'); | |
1289 } | |
1290 return $options; | |
1291 } | |
1292 | |
1293 function _ad_channel_get_channel_active_ad_count($chid) { | |
1294 if ($chid) { | |
1295 $count = db_result(db_query("SELECT COUNT(nid) AS count FROM {ad_channel_node} acn LEFT JOIN {ads} a ON acn.nid = a.aid WHERE acn.chid = %d AND a.adstatus = 'active'", $chid)); | |
1296 } | |
1297 return $count; | |
1298 } |