You are here

function ad_weight_percent_settings_submit in Advertisement 6.3

Same name and namespace in other branches
  1. 5.2 weight/percent/ad_weight_percent.module \ad_weight_percent_settings_submit()
  2. 5 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 139
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, &$form_state) {
  $groups = module_invoke('ad', 'groups_list', TRUE);
  foreach ($groups as $tid => $group) {
    variable_set("enable-{$tid}", (int) $form_state['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_state['values']["percent-{$tid}-{$nid->nid}"]);
    }
  }
}