? .DS_Store
? affiliates.336656.1.patch
? affiliates.336656.2.patch
Index: affiliates.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/affiliates/Attic/affiliates.install,v
retrieving revision 1.1.4.2.2.1
diff -r1.1.4.2.2.1 affiliates.install
75c75,79
< } 
\ No newline at end of file
---
> } 
> 
> function affiliates_update_1() { 
>     db_add_field($ret, affiliates_cats, 'weight', array('type' => 'int', 'length' => '3','default' => 0));
>  }
Index: affiliates.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/affiliates/Attic/affiliates.module,v
retrieving revision 1.1.4.5.2.3
diff -r1.1.4.5.2.3 affiliates.module
45c45
<       'title' => 'Affiliates ads',
---
>       'title' => 'Affiliates',
47c47
<       'page callback' => 'affiliates_ad_list',
---
>       'page callback' => 'affiliates_ad_button_list',
50,51c50,51
<     $items['affiliates/admin/list'] = array(
<       'title' => 'List',
---
>     $items['affiliates/admin/list/buttons'] = array(
>       'title' => 'List Buttons',
53,54c53,62
<       'page callback' => 'affiliates_ad_list',
<       'type' => MENU_DEFAULT_LOCAL_TASK,
---
>       'page callback' => 'affiliates_ad_button_list',
>       'type' => MENU_LOCAL_TASK,
>       'weight' => 1,
>     );
>     
>      $items['affiliates/admin/list/categories'] = array(
>       'title' => 'List Categories',
>       'access arguments' => array('administer affiliates'),
>       'page callback' => 'affiliates_ad_category_list',
>       'type' => MENU_LOCAL_TASK,
58,59c66,75
<     $items['affiliates/admin/add'] = array(
<       'title' => t('Add'),
---
>     $items['affiliates/admin/add/button'] = array(
>       'title' => t('Add Button'),
>       'access arguments' => array('administer affiliates'),
>       'page callback' => 'affiliates_affiliate',
>       'type' => MENU_LOCAL_TASK,
>       'weight' => 5,
>     );
>     
>     $items['affiliates/admin/add/category'] = array(
>       'title' => t('Add Category'),
66,67c82,83
<     $items['affiliates/admin/edit'] = array(
<       'title' => 'Edit affiliate ad',
---
>     $items['affiliates/admin/edit/button'] = array(
>       'title' => 'Edit button',
72,74c88,97
< 
<     $items['affiliates/admin/delete'] = array(
<       'title' => t('Delete affiliate ad'),
---
>     
>      $items['affiliates/admin/edit/category'] = array(
>       'title' => 'Edit Category',
>       'access arguments' => array('administer affiliates'),
>       'page callback' => 'affiliates_affiliate',
>       'type' => MENU_HIDE,
>     );
>     
>     $items['affiliates/admin/delete/button'] = array(
>       'title' => t('Delete affiliate button'),
79a103,109
>     $items['affiliates/admin/delete/category'] = array(
>       'title' => t('Delete affiliate category'),
>       'access arguments' => array('administer affiliates'),
>       'page callback' => 'affiliates_affiliate',
>       'type' => MENU_HIDE,
>     );
>     
271c301,302
<   $id = (int)arg(3);
---
>   $level = arg(3); 
>   $id = (int)arg(4);
275c306,311
<       $output = drupal_get_form('affiliate_form_add_edit');
---
>        if ($level == 'category') {
>         $output = drupal_get_form('affiliate_form_category_add_edit');
>        }
>        else {
>        $output = drupal_get_form('affiliate_form_button_add_edit');
>        }
279,280c315,322
<       $affiliate = _get_affiliate($id);
<       $output = drupal_get_form('affiliate_form_add_edit', $affiliate);
---
>       if ($level == 'category') {
>         $affiliate_category = _get_affiliate_category($id);
>         $output = drupal_get_form('affiliate_form_category_add_edit', $affiliate_category);
>       }
>       else {
>         $affiliate_button = _get_affiliate_button($id);
>         $output = drupal_get_form('affiliate_form_button_add_edit', $affiliate_button);
>       }  
284c326,331
<       $output = drupal_get_form('affiliate_form_delete', $id);
---
>       if ($level == 'category') {
>         $output = drupal_get_form('affiliate_form_category_delete', $id);
>       } 
>       else {
>          $output = drupal_get_form('affiliate_form_button_delete', $id);
>       } 
291c338
< function affiliate_form_delete($id) {
---
> function affiliate_form_button_delete($id) {
303c350
< function affiliate_form_add_edit(&$form_state, $affiliate = array()) {
---
> function affiliate_form_button_add_edit(&$form_state, $affiliate = array()) {
383c430
< function affiliate_form_add_edit_validate($form, &$form_state) {
---
> function affiliate_form_button_add_edit_validate($form, &$form_state) {
417c464
< function affiliate_form_add_edit_submit($form, &$form_state) {
---
> function affiliate_form_button_add_edit_submit($form, &$form_state) {
420c467
<   $id = arg(3);
---
>   $id = arg(4);
440c487
<       $ad_id = (int)arg(3);
---
>       $ad_id = (int)arg(4);
460c507
<       drupal_set_message('Ad has been saved.');
---
>       drupal_set_message('Affiliate button has been saved.');
466c513
< function affiliate_form_delete_submit($form, &$form_state) {
---
> function affiliate_form_button_delete_submit($form, &$form_state) {
469c516
<   $id = arg(3);
---
>   $id = arg(4);
472,473c519,520
<   db_query("DELETE FROM {affiliates}     WHERE ad_id = %d", $id);
<   drupal_set_message('Ad has been deleted.');
---
>   db_query("DELETE FROM {affiliates}     WHERE ad_id = %d", $id);  // TODO: If a button is deleted should an affiliate lose all of their affiliate points ?
>   drupal_set_message('Affiliate button has been deleted.');
477c524,609
< function affiliates_ad_list() {
---
> function affiliate_form_category_add_edit(&$form_state, $affiliate_category = array()) { 
> 
>   $form['affiliate'] = array(
>     '#type'  => 'fieldset',
>     '#title' => t('Affiliate Categories'),
>   );
>   
>   $form['affiliate']['cat_name'] = array(    
>     '#type' => 'textfield',
>     '#title' => t('Category name'),
>     '#required' => TRUE,
>     '#default_value' => $affiliate_category->cat_name,
>     '#size'          => 30,
>     '#maxlength'     => 30,
>   );
>   $form['affiliate']['weight'] = array(    
>     '#type' => 'textfield',
>     '#title' => t('Relative weight'),
>     '#default_value' => $affiliate_category->weight,
>     '#size'          => 3,
>     '#maxlength'     => 3,
>     '#required' => FALSE,
>     '#description' => t("Relative weight. Higher weights have higher positions on the affiliates page"),
>   );  
>   $form['affiliate']['active'] = array(
>     '#type' => 'radios',
>     '#title' => t('Category active'),
>     '#default_value' => $affiliate_category->active,
>     '#options' => array('Y' =>'yes','N' =>'no'),
>   );
>   
>   $form['affiliate']['submit'] = array(
>     '#type' => 'submit',
>     '#value' => t('Create an affiliate category'),
>   );
>   
>   return $form;
> }
> 
> function affiliate_form_category_add_edit_submit($form, &$form_state) {
>   $form_values = $form_state['values'];
>   $op = arg(2);
> 
>   switch($op) {
>     case 'add':
>       db_query("INSERT INTO {affiliates_cats}
>         (cat_name, active, weight)
>         VALUES
>         ('%s', '%s', %d)",
>         $form_values['cat_name'],
>         $form_values['active'],
>         $form_values['weight']
>         );
>       drupal_set_message('Affiliate category has been added.');
>       break;
> 
>     case 'edit':
>       $cat_id = (int)arg(4);
>       db_query("UPDATE {affiliates_cats} SET
>         cat_name  = '%s',
>         active  = '%s',
>         weight  = %d
>         WHERE cat_id = %d",
>         $form_values['cat_name'],
>         $form_values['active'],
>         $form_values['weight'],
>         $cat_id);
>       drupal_set_message('Affiliate category has been saved.');
>       break;
>   }
>   drupal_goto('affiliates/admin/list/categories');
> }
> /*
> function affiliate_form_button_delete_submit($form, &$form_state) {
>   $form_values = $form_state['values'];
>   $op = arg(2);
>   $id = arg(4);
> 
>   db_query("DELETE FROM {affiliates_ads} WHERE ad_id = %d", $id);
>   db_query("DELETE FROM {affiliates}     WHERE ad_id = %d", $id);  // TODO: If a button is deleted should an affiliate lose all of their affiliate points ?
>   drupal_set_message('Affiliate button has been deleted.');
>   drupal_goto('affiliates/admin');
> }
> */
> 
> function affiliates_ad_button_list($cat_id = NULL) {  
489c621
<   $sql = "SELECT aa.*, ac.cat_name
---
>   $sql = "SELECT aa.*, ac.cat_name, ac.cat_id
491c623,625
<     WHERE aa.cat_id = ac.cat_id" . tablesort_sql($header);
---
>     WHERE aa.cat_id = ac.cat_id";
>   $sql .=  !is_null($cat_id) ?  " AND ac.cat_id = " . $cat_id : "" ;  
>   $sql .= tablesort_sql($header);
503,504c637,671
<         l('edit',   'affiliates/admin/edit/'   . $data->ad_id) . " " .
<         l('delete', 'affiliates/admin/delete/' . $data->ad_id)
---
>         l('edit',   'affiliates/admin/edit/button/'   . $data->ad_id) . " " .
>         l('delete', 'affiliates/admin/delete/button/' . $data->ad_id)
>         ),
>     );
>   }
>   if (!$rows) {
>     $rows[] = array(array('data' => t('No data.'), 'colspan' => '4'));
>   }
>   $pager = theme('pager', NULL, 50, 0);
>   if (!empty($pager)) {
>     $rows[] = array(array('data' => $pager, 'colspan' => '4'));
>   }
>   print theme('page', theme('table', $header, $rows), t('Affiliate Ads'));
> }
> 
> function affiliates_ad_category_list() {
>   $header = array(
>     array('data' => t('Name'), 'field' => 'cat_name'),
>     array('data' => t('Active'), 'field' => 'active'),
>     array('data' => t('Weight'), 'field' => 'weight', 'sort' => 'desc'),
>     array('data' => t('Action'), NULL),
>   );
> 
>   $status = _get_status_desc();
>   $sql = "SELECT cat_id, cat_name, active, weight FROM {affiliates_cats}" . tablesort_sql($header);
> 
>   $result = pager_query($sql, 50);
>   while ($data = db_fetch_object($result)) {
>     $rows[] = array(
>             array('data' => $data->cat_name),
>             array('data' => $data->active),
>             array('data' => $data->weight),
>             array('data' => 
>         l('show buttons',   'affiliates/admin/list/buttons/'   . $data->cat_id) . " " .
>         l('edit category', 'affiliates/admin/edit/category/' . $data->cat_id)
551a719,720
> 
> 
963c1132
< function _get_affiliate($ad_id = 0) {
---
> function _get_affiliate_button($ad_id = 0) {
965a1135,1139
> 
> function _get_affiliate_category($cat_id = 0) {
>   return db_fetch_object(db_query('SELECT * FROM {affiliates_cats} WHERE cat_id = %d', $cat_id));
> }
> 
