--- civicspace-0.8.0.3/modules/affiliate.module Sat May 14 00:35:18 2005 +++ affiliate/affiliate.module Sat May 14 16:27:31 2005 @@ -17,18 +17,30 @@ return array('administer affiliates'); } -function affiliate_link($type) { - if ($type == 'system') { +/** + * Implementation of hook_menu(). + */ +function affiliate_menu($may_cache) { affiliate_record(); $access = user_access('administer affiliates'); - menu('admin/affiliate', t('affiliates'), $access ? 'affiliate_admin' : MENU_DENIED, 5); - menu('admin/affiliate/user', t('users by affiliate'), $access ? 'affiliate_admin_user' : MENU_DENIED, 5, 1); - menu('admin/affiliate/form', t('create new affiliate'), $access ? 'affiliate_form' : MENU_DENIED, 5); - menu('admin/affiliate/delete', t('affiliate delete'), $access ? 'affiliate_delete' : MENU_DENIED, 5, 1); - menu('affiliate/cron', t('affiliate cron'), 1 ? 'affiliate_cron' : MENU_DENIED, 5, 1); - } + $items[] = array('path' => 'admin/affiliate', 'title' => t('affiliates'), 'access' => $access, + 'callback' => 'affiliate_admin', 'weight' => 5, 'type' => MENU_NORMAL_ITEM); + $items[] = array('path' => 'admin/affiliate/user', 'title' => t('users by affiliate'), 'access' => $access, + 'callback' => 'affiliate_admin_user', 'weight' => 5, 'type' => MENU_DEFAULT_LOCAL_TASK); + $items[] = array('path' => 'admin/affiliate/form', 'title' => t('create new affiliate'), 'access' => $access, + 'callback' => 'affiliate_form', 'weight' => 5, 'type' => MENU_LOCAL_TASK); + $items[] = array('path' => 'admin/affiliate/delete', 'title' => t('delete affiliate'), 'access' => $access, + 'callback' => 'affiliate_delete', 'weight' => 5, 'type' => MENU_CALLBACK); + $items[] = array('path' => 'affiliate/cron', 'title' => t('affiliate cron'), 'access' => TRUE, + 'callback' => 'affiliate_cron', 'weight' => 5, 'type' => MENU_CALLBACK); + +return $items; + } +/** + * Records affiliate ID in the user session. + */ function affiliate_record() { global $user; $aff = $_REQUEST['aff']; @@ -41,6 +53,9 @@ } } +/** + * Implementation of hook_user() + */ function affiliate_user($op, $array = NULL, $user) { switch ($op) { case 'insert': @@ -55,12 +70,13 @@ return array('History' => $output); } } + break; case 'form': if (user_access('administer affiliates')) { $options = affiliate_get_affiliates(); $options = array(0 => t('')) + $options; $output = form_select(t('Affiliate'), 'affiliate', $user->affiliate, $options); - return array('Misc' => $output); + return array(array('title' => t('Misc'), 'data' => $output, 'weight' => 0)); } } } @@ -75,6 +91,9 @@ return $all; } +/** + * Implementation of hook_cron() + */ function affiliate_cron() { $last = variable_get('affiliate_cron_last', 0); if (time()-$last > 24*60*60) { @@ -120,7 +139,7 @@ array("data" => t('last access'), "field" => 'changed', 'sort' => 'desc'), array("data" => t('operations')) ); - $sql = 'SELECT uid, u.name, u.status, u.changed FROM {users} u JOIN {affiliates} a ON u.affiliate = a.aid WHERE affiliate = '. check_query($aid); + $sql = 'SELECT uid, u.name, u.status, u.changed FROM {users} u INNER JOIN {affiliates} a ON u.affiliate = a.aid WHERE affiliate = '. check_query($aid); $sql .= tablesort_sql($header); $result = pager_query($sql, 50); $status = array(t("blocked"), t("active")); @@ -129,7 +148,7 @@ array("data" => format_name($row)), array("data" => $status[$row->status]), array("data" => format_date($row->changed, 'small')), - array("data" => l(t('edit'), "user/edit/$row->uid")), + array("data" => l(t('edit'), "user/$row->uid/edit")), ); } if (!$rows) { @@ -194,6 +213,7 @@ $sql = 'SELECT * FROM {affiliates} WHERE aid = %d'; $row = db_fetch_object(db_query($sql, $aid)); $output .= form_item(t('Affiliate ID'), $aid); +// Make this link to registration page $output .= form_item(t('Affiliate Link'), l(t('Home'), '', array(), "aff=$aid")); } else {