? .DS_Store
? affiliates.336656.1.patch
? affiliates.336656.2.patch
? affiliates.336656.2b.patch
? affiliates.336656.2c.patch
? affiliates.js
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
4a5
> define ('AFFILIATE_BUTTONS_DIRECTORY_RELATIVE_FILES', '/images/affiliates');
45c46
<       'title' => 'Affiliates ads',
---
>       'title' => 'Affiliates',
47c48
<       'page callback' => 'affiliates_ad_list',
---
>       'page callback' => 'affiliates_ad_button_list',
50,51c51,52
<     $items['affiliates/admin/list'] = array(
<       'title' => 'List',
---
>     $items['affiliates/admin/list/buttons'] = array(
>       'title' => 'List Buttons',
53,54c54,63
<       '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,59c67,76
<     $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,67c83,84
<     $items['affiliates/admin/edit'] = array(
<       'title' => 'Edit affiliate ad',
---
>     $items['affiliates/admin/edit/button'] = array(
>       'title' => 'Edit button',
72,74c89,98
< 
<     $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'),
79a104,110
>     $items['affiliates/admin/delete/category'] = array(
>       'title' => t('Delete affiliate category'),
>       'access arguments' => array('administer affiliates'),
>       'page callback' => 'affiliates_affiliate',
>       'type' => MENU_HIDE,
>     );
>     
271c302,303
<   $id = (int)arg(3);
---
>   $level = arg(3); 
>   $id = (int)arg(4);
275c307,312
<       $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,280c316,323
<       $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);
>       }  
284c327,332
<       $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);
>       } 
291c339
< function affiliate_form_delete($id) {
---
> function affiliate_form_button_delete($id) {
303c351
< function affiliate_form_add_edit(&$form_state, $affiliate = array()) {
---
> function affiliate_form_button_add_edit(&$form_state, $affiliate = array()) {
307c355
<     '#title' => t('Affiliate Ad'),
---
>     '#title' => t('Add a button'),
315a364
>     '#required' => TRUE,
341a391,397
>   
>    $form['affiliate']['image'] = array(
>   	'#type' => 'file',
>   	'#title' => t('Upload a button'),
>   	'#size' => 40,
>   	'#description' => t('Please upload a button.')
>   );
345c401
<     '#title'         => t('Link text'),
---
>     '#title'         => t('Hosted button URL'),
348a405
>     '#description' => t('If your button is  hosted elsewhere, enter the URL here.')
378c435
< 
---
>   $form['#attributes'] = array('enctype' => "multipart/form-data"); 
383,384c440,441
< function affiliate_form_add_edit_validate($form, &$form_state) {
<   $form_values = $form_state['values'];
---
> function affiliate_form_button_add_edit_validate($form, &$form_state) {
>   $form_values = $form_state['values']; 
397,399d453
<   if (!$form_values['anchor']) {
<     form_set_error('', t('You must enter link text'));
<   }
405a460,462
>    if (!$form_values['anchor'] && empty($_FILES['files']['name']['image'])) {
>     form_set_error('', t('You must either upload an button or enter the URL of the hosted button '));
>   }
417c474
< function affiliate_form_add_edit_submit($form, &$form_state) {
---
> function affiliate_form_button_add_edit_submit($form, &$form_state) { 
420c477
<   $id = arg(3);
---
>   $id = arg(4);
423a481,491
>        global $base_url;	
>        $FILE_DIRECTORY_PATH  = variable_get('file_directory_path', 'files');
>        if (!empty($_FILES['files']['name']['image']) && substr_count($_FILES['files']['type']['image'], "image")) {    
>          $directory = $FILE_DIRECTORY_PATH . AFFILIATE_BUTTONS_DIRECTORY_RELATIVE_FILES ;
>          if (file_check_directory($directory, $mode = 1, $form_item = NULL)) {  
>          chmod($directory, 0777) ; 
>          }
>          file_copy($_FILES['files']['tmp_name']['image'], $directory.'/'.$_FILES['files']['name']['image'], $replace = FILE_EXISTS_ERROR) ; 
>        }      
>        $button_url = $_FILES['files']['name']['image'] ? $base_url .'/'. $directory .'/'. $_FILES['files']['name']['image'] : $form_values['anchor'];       
>       //upload succeeded
430c498
<         $form_values['anchor'],
---
>         $button_url,
436,437c504,505
<       drupal_set_message('Ad has been added.');
<       break;
---
>     drupal_set_message('Affiliate button has been added.');
>     break;
440c508
<       $ad_id = (int)arg(3);
---
>       $ad_id = (int)arg(4);
460c528
<       drupal_set_message('Ad has been saved.');
---
>       drupal_set_message('Affiliate button has been saved.');
466c534
< function affiliate_form_delete_submit($form, &$form_state) {
---
> function affiliate_form_button_delete_submit($form, &$form_state) {
469c537
<   $id = arg(3);
---
>   $id = arg(4);
472,474c540,541
<   db_query("DELETE FROM {affiliates}     WHERE ad_id = %d", $id);
<   drupal_set_message('Ad has been deleted.');
<   drupal_goto('affiliates/admin');
---
>   drupal_set_message('Affiliate button has been deleted.');
>   drupal_goto('affiliates/admin/list/buttons');
477c544,640
< function affiliates_ad_list() {
---
> function affiliate_form_category_add_edit(&$form_state, $affiliate_category = array()) { 
> 
>   $form['affiliate'] = array(
>     '#type'  => 'fieldset',
>     '#title' => t('Add a category'),
>   );
>   
>   $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_category_delete($id) {
>   $form['affiliate']['message'] = array(
>     '#type'  => 'markup',
>     '#value' => t('Are you sure you want to delete this affiliate category and all of its buttons?'),
>   );
>   $form['affiliate']['delete'] = array(
>     '#type'  => 'submit',
>     '#value' => t('Delete'),
>   );
>   return $form;
> }
> 
> function affiliate_form_category_delete_submit($form, &$form_state) {
>   $form_values = $form_state['values'];
>   $op = arg(2);
>   $cat_id = arg(4);
> 
>   db_query("DELETE FROM {affiliates_cats}   WHERE cat_id = %d", $cat_id);
>   db_query("DELETE FROM {affiliates_ads} WHERE cat_id = %d", $cat_id);
>   drupal_set_message('Affiliate category has been deleted and all of its buttons.');
>   drupal_goto('affiliates/admin/list/categories');
> }
> 
> function affiliates_ad_button_list($cat_id = NULL) {  
489c652
<   $sql = "SELECT aa.*, ac.cat_name
---
>   $sql = "SELECT aa.*, ac.cat_name, ac.cat_id
491c654,656
<     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,504c668,669
<         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)
509c674
<     $rows[] = array(array('data' => t('No data.'), 'colspan' => '4'));
---
>     $rows[] = array(array('data' => t('No buttons.'), 'colspan' => '4'));
515c680,714
<   print theme('page', theme('table', $header, $rows), t('Affiliate Ads'));
---
>   print theme('page', theme('table', $header, $rows), t('Affiliates'));
> }
> 
> 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', 'affiliates/admin/edit/category/' . $data->cat_id) . " " .
>         l('delete', 'affiliates/admin/delete/category/' . $data->cat_id)
>         ),
>     );
>   }
>   if (!$rows) {
>     $rows[] = array(array('data' => t('No categories.'), '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('Affiliates'));
551a751,752
> 
> 
737c938
<     ORDER BY order_by ASC");
---
>     ORDER BY ac.weight ASC, aa.order_by ASC");
963c1164
< function _get_affiliate($ad_id = 0) {
---
> function _get_affiliate_button($ad_id = 0) {
965a1167,1171
> 
> function _get_affiliate_category($cat_id = 0) {
>   return db_fetch_object(db_query('SELECT * FROM {affiliates_cats} WHERE cat_id = %d', $cat_id));
> }
> 
