You are here

function ad_weight_percent_settings_submit in Advertisement 5.2

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

Save the weight percent settings in the database.

File

weight/percent/ad_weight_percent.module, line 120
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_submit($form_id, $form_values) {
  $groups = module_invoke('ad', 'groups_list', TRUE);
  foreach ($groups as $tid => $group) {
    variable_set("enable-{$tid}", (int) $form_values["enable-{$tid}"]);
    db_query('DELETE FROM {ad_weight_percent} WHERE tid = %d', $tid);
    $result = db_query('SELECT nid FROM {term_node} WHERE tid = %d', $group->tid);
    while ($nid = db_fetch_object($result)) {
      db_query('INSERT INTO {ad_weight_percent} (tid, aid, weight) VALUES(%d, %d, %d)', $tid, $nid->nid, (int) $form_values["percent-{$tid}-{$nid->nid}"]);
    }
  }
}