You are here

function ad_weight_percent_settings in Advertisement 5.2

Same name and namespace in other branches
  1. 5 weight/percent/ad_weight_percent.module \ad_weight_percent_settings()
  2. 6.3 weight/percent/ad_weight_percent.module \ad_weight_percent_settings()
  3. 6 weight/percent/ad_weight_percent.module \ad_weight_percent_settings()
  4. 6.2 weight/percent/ad_weight_percent.module \ad_weight_percent_settings()
  5. 7 weight/percent/ad_weight_percent.module \ad_weight_percent_settings()

Configure per-group percentage settings.

1 string reference to 'ad_weight_percent_settings'
ad_weight_percent_menu in weight/percent/ad_weight_percent.module
Drupal hook_menu().

File

weight/percent/ad_weight_percent.module, line 35
A plug in for the ad.module, providing a percentage based weighting mechanism for the random selection of ads.

Code

function ad_weight_percent_settings() {
  $form = array();
  $groups = module_invoke('ad', 'groups_list', TRUE);
  foreach ($groups as $tid => $group) {
    $form["group-{$tid}"] = array(
      '#type' => 'fieldset',
      '#title' => $group->name,
      '#collapsible' => TRUE,
      '#collapsed' => variable_get("enable-{$tid}", 0) ? FALSE : TRUE,
    );
    $form["group-{$tid}"]["description-{$tid}"] = array(
      '#type' => 'markup',
      '#prefix' => '<div>',
      '#suffix' => '</div>',
      '#value' => theme_placeholder("{$group->description}"),
    );
    $form["group-{$tid}"]["enable-{$tid}"] = array(
      '#type' => 'checkbox',
      '#default_value' => variable_get("enable-{$tid}", 0),
      '#title' => t('Enabled'),
      '#description' => t('If enabled, each ad in this group will be weighted per the percentages defined below.'),
    );
    $result = db_query('SELECT nid FROM {term_node} WHERE tid = %d', $group->tid);
    while ($nid = db_fetch_object($result)) {
      $ad = node_load($nid->nid);
      $percent = db_fetch_object(db_query('SELECT * FROM {ad_weight_percent} WHERE tid = %d AND aid = %d', $tid, $nid->nid));
      $form["group-{$tid}"]["ad-{$tid}"]["{$tid}-{$nid->nid}"] = array(
        '#type' => 'fieldset',
        '#title' => $ad->title,
        '#collapsible' => TRUE,
      );
      $form["group-{$tid}"]["ad-{$tid}"]["{$tid}-{$nid->nid}"]["ad-{$tid}-{$nid->nid}"] = array(
        '#type' => 'markup',
        '#prefix' => '<div>',
        '#suffix' => '</div>',
        '#value' => "{$ad->ad}<br />{$ad->url}",
      );
      $form["group-{$tid}"]["ad-{$tid}"]["{$tid}-{$nid->nid}"]["percent-{$tid}-{$nid->nid}"] = array(
        '#type' => 'textfield',
        '#title' => t('Display percent'),
        '#default_value' => $percent->weight,
        '#size' => 2,
        '#maxlength' => 3,
        '#description' => t("Enter a percentage from 0 to 100.  The total percentages of all ads in this group must add up to 100.  For example, if you have two ads, and want one to be displayed 70% of the time and the other 30% of the time enter '70' in one and '30' in the other."),
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}