/[drupal]/contributions/modules/tw/tw_pages.inc
ViewVC logotype

Diff of /contributions/modules/tw/tw_pages.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.25, Fri Apr 17 20:15:55 2009 UTC revision 1.1.2.26, Fri May 1 01:44:13 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: tw_pages.inc,v 1.1.2.24 2009/04/15 21:18:33 mikeryan Exp $  // $Id: tw_pages.inc,v 1.1.2.25 2009/04/17 20:15:55 mikeryan Exp $
3  /**  /**
4   * @file   * @file
5   * Table Wizard menu callbacks   * Table Wizard menu callbacks
# Line 10  define('TW_COLS_IGNORE', 2); Line 10  define('TW_COLS_IGNORE', 2);
10  define('TW_COLS_NOIGNORE', 3);  define('TW_COLS_NOIGNORE', 3);
11    
12  /**  /**
13   * Enter description here...   * Page callback for sources form.
  *  
  * @return unknown  
14   */   */
15  function tw_sources() {  function tw_sources() {
16    return drupal_get_form('_tw_sources_form');    return drupal_get_form('tw_sources_form');
17  }  }
18    
19  /**  /**
20   * Enter description here...   * Sources form definition.
  *  
  * @param unknown_type $form_state  
  * @return unknown  
21   */   */
22  function _tw_sources_form($form_state) {  function tw_sources_form($form_state) {
23    $form['description'] = array(    $form['description'] = array(
24      '#prefix' => '<div>',      '#prefix' => '<div>',
25      '#value' => t('Tables managed by the Table Wizard module are listed here, each with the name of the      '#value' => t('Tables managed by the Table Wizard module are listed here, each with the name of the
# Line 39  function _tw_sources_form($form_state) { Line 34  function _tw_sources_form($form_state) {
34    if ($extconns >= 1) {    if ($extconns >= 1) {
35      $connheader = array('data' => t('Connection'), 'field' => 'twt.connection', 'sort' => 'asc');      $connheader = array('data' => t('Connection'), 'field' => 'twt.connection', 'sort' => 'asc');
36      $nameheader = array('data' => t('Table name'), 'field' => 'twt.tablename');      $nameheader = array('data' => t('Table name'), 'field' => 'twt.tablename');
37    } else {    }
38      else {
39      $nameheader = array('data' => t('Table name'), 'field' => 'twt.tablename', 'sort' => 'asc');      $nameheader = array('data' => t('Table name'), 'field' => 'twt.tablename', 'sort' => 'asc');
40    }    }
41    if ($extconns >= 1) {    if ($extconns >= 1) {
# Line 53  function _tw_sources_form($form_state) { Line 49  function _tw_sources_form($form_state) {
49          array('data' => t('Row count')),          array('data' => t('Row count')),
50        ),        ),
51      );      );
52    } else {    }
53      else {
54      $form['header'] = array(      $form['header'] = array(
55        '#type' => 'value',        '#type' => 'value',
56        '#value' => array(        '#value' => array(
# Line 68  function _tw_sources_form($form_state) { Line 65  function _tw_sources_form($form_state) {
65    $sql = "SELECT * FROM {tw_tables} twt";    $sql = "SELECT * FROM {tw_tables} twt";
66    if ($extconns >= 1) {    if ($extconns >= 1) {
67      $tablesort = tablesort_sql(array($connheader, $nameheader));      $tablesort = tablesort_sql(array($connheader, $nameheader));
68    } else {    }
69      else {
70      $tablesort = tablesort_sql(array($nameheader));      $tablesort = tablesort_sql(array($nameheader));
71    }    }
72    $result = db_query($sql . $tablesort);    $result = db_query($sql . $tablesort);
# Line 78  function _tw_sources_form($form_state) { Line 76  function _tw_sources_form($form_state) {
76      $checks[$row->twtid] = '';      $checks[$row->twtid] = '';
77      $form['twtid'][$row->twtid] = array('#value' => $row->twtid);      $form['twtid'][$row->twtid] = array('#value' => $row->twtid);
78      $form['analyze'][$row->twtid] = array('#value' =>      $form['analyze'][$row->twtid] = array('#value' =>
79        l(t('Analysis'), 'admin/content/tw/analyze/'. $row->twtid, array('html' => TRUE)));        l(t('Analysis'), 'admin/content/tw/analyze/' . $row->twtid, array('html' => TRUE)));
80      if ($extconns >= 1) {      if ($extconns >= 1) {
81        $form['connection'][$row->twtid] = array('#value' => $row->connection);        $form['connection'][$row->twtid] = array('#value' => $row->connection);
82      }      }
83      $form['tablename'][$row->twtid] = array('#value' =>      $form['tablename'][$row->twtid] = array('#value' =>
84        l($row->tablename, 'admin/content/tw/view/'. $row->tablename, array('html' => TRUE)));        l($row->tablename, 'admin/content/tw/view/' . $row->tablename, array('html' => TRUE)));
85      if ($last_connection != $row->connection) {      if ($last_connection != $row->connection) {
86        db_set_active($row->connection);        db_set_active($row->connection);
87        $last_connection = $row->connection;        $last_connection = $row->connection;
# Line 95  function _tw_sources_form($form_state) { Line 93  function _tw_sources_form($form_state) {
93          add an element to $db_prefix setting the prefix for this table to an empty string.',          add an element to $db_prefix setting the prefix for this table to an empty string.',
94          array('%tablename' => $row->tablename)));          array('%tablename' => $row->tablename)));
95        $rowcount = t('N/A');        $rowcount = t('N/A');
96      } else {      }
97        else {
98        $sql = 'SELECT COUNT(*) FROM {' . $row->tablename . '}';        $sql = 'SELECT COUNT(*) FROM {' . $row->tablename . '}';
99        $rowcount = db_result(db_query($sql));        $rowcount = db_result(db_query($sql));
100      }      }
# Line 154  function theme_tw_sources($form) { Line 153  function theme_tw_sources($form) {
153  }  }
154    
155  /**  /**
156   * Enter description here...   * Sources form submit handler.
  *  
  * @param unknown_type $form  
  * @param unknown_type $form_state  
157   */   */
158  function _tw_sources_form_submit($form, &$form_state) {  function tw_sources_form_submit($form, &$form_state) {
159    $type = $form_state['clicked_button']['#parents'][0];    $type = $form_state['clicked_button']['#parents'][0];
160    if ($type == 'delete') {    if ($type == 'delete') {
161      foreach ($form_state['values']['checks'] as $twtid => $value) {      foreach ($form_state['values']['checks'] as $twtid => $value) {
# Line 171  function _tw_sources_form_submit($form, Line 167  function _tw_sources_form_submit($form,
167            array('%tablename' => $row->tablename, '%connection' => $row->connection)));            array('%tablename' => $row->tablename, '%connection' => $row->connection)));
168        }        }
169      }      }
170    } else {    }
171      else {
172      // Submit hooks return arrays of tablenames they're bringing in      // Submit hooks return arrays of tablenames they're bringing in
173      $values = $form_state['values'][$type];      $values = $form_state['values'][$type];
174      $tableset = module_invoke_all("tw_form_submit_$type", $values);      $tableset = module_invoke_all("tw_form_submit_$type", $values);
# Line 181  function _tw_sources_form_submit($form, Line 178  function _tw_sources_form_submit($form,
178    
179  /**  /**
180   * Add a fieldset into the import form, for identifying where to obtain source data.   * Add a fieldset into the import form, for identifying where to obtain source data.
  *  
  * @return unknown  
181   */   */
182  function tw_tw_form() {  function tw_tw_form() {
183    $fieldsets['existing'] = array(    $fieldsets['existing'] = array(
# Line 211  function tw_tw_form() { Line 206  function tw_tw_form() {
206    global $db_url;    global $db_url;
207    if (!is_array($db_url)) {    if (!is_array($db_url)) {
208      $connlist = array('default' => $db_url);      $connlist = array('default' => $db_url);
209    } else {    }
210      else {
211      $connlist = $db_url;      $connlist = $db_url;
212    }    }
213    // We assume the default is first    // We assume the default is first
# Line 271  function tw_tw_form() { Line 267  function tw_tw_form() {
267  }  }
268    
269  /**  /**
270   * Enter description here...   * Implementation of hook_tw_form_submit_<type>.
  *  
  * @param unknown_type $values  
  * @return unknown  
271   */   */
272  function tw_tw_form_submit_existing($values) {  function tw_tw_form_submit_existing($values) {
273    $tablenames = array();    $tablenames = array();
# Line 292  function tw_tw_form_submit_existing($val Line 285  function tw_tw_form_submit_existing($val
285    
286    
287  /**  /**
288   * Menu callback function   * Menu callback function.
289   * TODO: Flag any available FKs that are not indexed   * TODO: Flag any available FKs that are not indexed.
  *  
  * @param unknown_type $form_state  
  * @param unknown_type $table  
  * @param unknown_type $flag  
  * @return unknown  
290   */   */
291  function tw_analysis($form_state, $twtid, $flag=TW_COLS_NOIGNORE) {  function tw_analysis($form_state, $twtid, $flag=TW_COLS_NOIGNORE) {
292    $row = db_fetch_object(db_query("SELECT connection, tablename FROM {tw_tables}    $row = db_fetch_object(db_query("SELECT connection, tablename FROM {tw_tables}
# Line 487  function tw_analysis($form_state, $twtid Line 475  function tw_analysis($form_state, $twtid
475    
476        if (tw_column_type($row->coltype) == 'text') {        if (tw_column_type($row->coltype) == 'text') {
477          $form['lengths'][$colname] = array('#value' =>          $form['lengths'][$colname] = array('#value' =>
478            $row->maxlength ? $row->minlength.'-'.$row->maxlength : ''            $row->maxlength ? $row->minlength . '-' . $row->maxlength : ''
479          );          );
480    
481          $form['values'][$colname] = array(          $form['values'][$colname] = array(
482            '#attributes' => array('style' => 'white-space: normal'),            '#attributes' => array('style' => 'white-space: normal'),
483            '#prefix' => '<div style="white-space: normal">',            '#prefix' => '<div style="white-space: normal">',
484            '#value' =>            '#value' =>
485              $row->maxlength ? substr(check_plain($row->minstring),0,40).'<hr />'.              $row->maxlength ? substr(check_plain($row->minstring), 0, 40) . '<hr />' .
486                substr(check_plain($row->maxstring),0,40) : '',                substr(check_plain($row->maxstring), 0, 40) : '',
487            '#suffix' => '</div>',            '#suffix' => '</div>',
488          );          );
489        } else {        }
490          else {
491          $form['lengths'][$colname] = array('#value' => '');          $form['lengths'][$colname] = array('#value' => '');
492          $form['values'][$colname] = array('#value' =>          $form['values'][$colname] = array('#value' =>
493            $row->maxvalue ? $row->minvalue.'-'.$row->maxvalue : ''            $row->maxvalue ? $row->minvalue . '-' . $row->maxvalue : ''
494          );          );
495        }        }
496        $form['comments'][$colname] = array(        $form['comments'][$colname] = array(
# Line 543  function tw_analysis($form_state, $twtid Line 532  function tw_analysis($form_state, $twtid
532      drupal_set_message(t('%tablename has no primary key defined. A single-column primary      drupal_set_message(t('%tablename has no primary key defined. A single-column primary
533        key is necessary to use this table as the base table for a view.',        key is necessary to use this table as the base table for a view.',
534        array('%tablename' => $tablename)));        array('%tablename' => $tablename)));
535    } elseif (count($pks) > 1) {    }
536      elseif (count($pks) > 1) {
537      drupal_set_message(t('%tablename has a multiple-column primary key. A single-column primary      drupal_set_message(t('%tablename has a multiple-column primary key. A single-column primary
538        key is necessary to use this table as the base table for a view.',        key is necessary to use this table as the base table for a view.',
539        array('%tablename' => $tablename)));        array('%tablename' => $tablename)));
540    } else {    }
541      else {
542      if (strlen($tablename) > 32) {      if (strlen($tablename) > 32) {
543        drupal_set_message(t('%tablename is more than 32 characters long. Although the default        drupal_set_message(t('%tablename is more than 32 characters long. Although the default
544          view for this table works, in versions of Views up through at least 2.5 you cannot          view for this table works, in versions of Views up through at least 2.5 you cannot
# Line 562  function tw_analysis($form_state, $twtid Line 553  function tw_analysis($form_state, $twtid
553  }  }
554    
555  /**  /**
556   * Enter description here...   * Theme analysis form.
  *  
  * @param unknown_type $form  
  * @return unknown  
557   */   */
558  function theme_tw_analysis($form) {  function theme_tw_analysis($form) {
559    $title = drupal_render($form['title']);    $title = drupal_render($form['title']);
# Line 576  function theme_tw_analysis($form) { Line 564  function theme_tw_analysis($form) {
564    $output .= '<b>Operations on this table: </b>';    $output .= '<b>Operations on this table: </b>';
565    $output .= l(t('Reanalyze'),    $output .= l(t('Reanalyze'),
566                 "admin/content/tw/analyze/$twtid/",                 "admin/content/tw/analyze/$twtid/",
567                 array('html' => TRUE, 'query' => 'reanalyze=1')).' | ';                 array('html' => TRUE, 'query' => 'reanalyze=1')) .' | ';
568    $output .= l(t('View table contents'),    $output .= l(t('View table contents'),
569                 "admin/content/tw/view/$tablename/",                 "admin/content/tw/view/$tablename/",
570                 array('html' => TRUE));                 array('html' => TRUE));
# Line 584  function theme_tw_analysis($form) { Line 572  function theme_tw_analysis($form) {
572    $output .= '<div class="tw_analyze_links">';    $output .= '<div class="tw_analyze_links">';
573    $output .= '<b>Filter: </b>';    $output .= '<b>Filter: </b>';
574    $output .= l(t('Show all fields'),    $output .= l(t('Show all fields'),
575                 "admin/content/tw/analyze/$twtid/".TW_COLS_ALL,                 "admin/content/tw/analyze/$twtid/". TW_COLS_ALL,
576                 array('html' => TRUE)).' | ';                 array('html' => TRUE)) .' | ';
577    $output .= l(t('Show only ignored fields'),    $output .= l(t('Show only ignored fields'),
578                 "admin/content/tw/analyze/$twtid/".TW_COLS_IGNORE,                 "admin/content/tw/analyze/$twtid/". TW_COLS_IGNORE,
579                 array('html' => TRUE)).' | ';                 array('html' => TRUE)) .' | ';
580    $output .= l(t('Show only fields which are not being ignored'),    $output .= l(t('Show only fields which are not being ignored'),
581                 "admin/content/tw/analyze/$twtid/".TW_COLS_NOIGNORE,                 "admin/content/tw/analyze/$twtid/". TW_COLS_NOIGNORE,
582                 array('html' => TRUE));                 array('html' => TRUE));
583    $output .= '</div>';    $output .= '</div>';
584    $output .= '<div>'.drupal_render($form['colcounts']).'</div>';    $output .= '<div>' . drupal_render($form['colcounts']) . '</div>';
585    
586    $output .= drupal_render($form['help']);    $output .= drupal_render($form['help']);
587    
588    if (isset($form['colname']) && is_array($form['colname'])) {    if (isset($form['colname']) && is_array($form['colname'])) {
589      foreach(element_children($form['colname']) as $colname) {      foreach (element_children($form['colname']) as $colname) {
590        $row = array();        $row = array();
591        $row[] = drupal_render($form['colname'][$colname]);        $row[] = drupal_render($form['colname'][$colname]);
592        // Remove ignore toggle for the primary key        // Remove ignore toggle for the primary key
# Line 630  function theme_tw_analysis($form) { Line 618  function theme_tw_analysis($form) {
618  }  }
619    
620  /**  /**
621   * Implementation of hook_submit()   * Implementation of hook_submit().
  *  
  * @param unknown_type $form  
  * @param unknown_type $form_state  
622   */   */
623  function tw_analysis_submit($form, &$form_state) {  function tw_analysis_submit($form, &$form_state) {
624    $twtid = $form_state['values']['twtid'];    $twtid = $form_state['values']['twtid'];
625    foreach($form_state['values']['cols'] as $key => $colname) {    foreach ($form_state['values']['cols'] as $key => $colname) {
626      $newignore = $form_state['values']['ignorecol'][$colname] ? 1 : 0;      $newignore = $form_state['values']['ignorecol'][$colname] ? 1 : 0;
627      $newavailablefk = $form_state['values']['availablefk'][$colname] ? 1 : 0;      $newavailablefk = $form_state['values']['availablefk'][$colname] ? 1 : 0;
628      $newcomment = $form_state['values'][$colname];      $newcomment = $form_state['values'][$colname];
# Line 651  function tw_analysis_submit($form, &$for Line 636  function tw_analysis_submit($form, &$for
636  }  }
637    
638  /**  /**
639   * Enter description here...   * Page callback for relationships form.
  *  
  * @return unknown  
640   */   */
641  function tw_relationships() {  function tw_relationships() {
642    return(drupal_get_form('_tw_relationships_form'));    return drupal_get_form('tw_relationships_form');
643  }  }
644    
645  /**  /**
646   * Enter description here...   * Relationships form definition.
  *  
  * @param unknown_type $form_state  
  * @return unknown  
647   */   */
648  function _tw_relationships_form($form_state) {  function tw_relationships_form($form_state) {
649    $form['description'] = array(    $form['description'] = array(
650      '#prefix' => '<div>',      '#prefix' => '<div>',
651      '#value' => t('Define relationships between tables, enabling the creation      '#value' => t('Define relationships between tables, enabling the creation
# Line 727  function _tw_relationships_form($form_st Line 707  function _tw_relationships_form($form_st
707    $result = db_query($sql);    $result = db_query($sql);
708    while ($row = db_fetch_array($result)) {    while ($row = db_fetch_array($result)) {
709      if ($use_connection) {      if ($use_connection) {
710        $options[$row['twcid']] = $row['connection'] . '.' . $row['tablename'] . '.' . $row['colname'];        $options[$row['twcid']] = $row['connection'] . '.' . $row['tablename'] .'.'. $row['colname'];
711      } else {      }
712        else {
713        $options[$row['twcid']] = $row['tablename'] . '.' . $row['colname'];        $options[$row['twcid']] = $row['tablename'] . '.' . $row['colname'];
714      }      }
715    }    }
# Line 750  function _tw_relationships_form($form_st Line 731  function _tw_relationships_form($form_st
731  }  }
732    
733  /**  /**
734   * Enter description here...   * Theme relationships form.
  *  
  * @param unknown_type $form  
735   */   */
736  function theme_tw_relationships($form) {  function theme_tw_relationships($form) {
737    $output = drupal_render($form['description']);    $output = drupal_render($form['description']);
# Line 780  function theme_tw_relationships($form) { Line 759  function theme_tw_relationships($form) {
759    
760    return $output;    return $output;
761  }  }
762    
763  /**  /**
764   * Enter description here...   * Submit handler for tw_relationships_form().
  *  
  * @param unknown_type $form  
  * @param unknown_type $form_state  
765   */   */
766  function _tw_relationships_form_submit($form, &$form_state) {  function tw_relationships_form_submit($form, &$form_state) {
767    if ($form_state['clicked_button']['#parents'][0] == 'delete') {    if ($form_state['clicked_button']['#parents'][0] == 'delete') {
768      $count = 0;      $count = 0;
769      foreach ($form_state['values']['checks'] as $twrid => $value) {      foreach ($form_state['values']['checks'] as $twrid => $value) {
# Line 798  function _tw_relationships_form_submit($ Line 775  function _tw_relationships_form_submit($
775      if ($count) {      if ($count) {
776        drupal_set_message(format_plural($count, '1 relationship deleted', '@count relationships deleted'));        drupal_set_message(format_plural($count, '1 relationship deleted', '@count relationships deleted'));
777      }      }
778    } else {    }
779      else {
780      $leftcol = $form_state['values']['newleftcol'];      $leftcol = $form_state['values']['newleftcol'];
781      $rightcol = $form_state['values']['newrightcol'];      $rightcol = $form_state['values']['newrightcol'];
782      tw_add_relationship($leftcol, $rightcol);      tw_add_relationship($leftcol, $rightcol);

Legend:
Removed from v.1.1.2.25  
changed lines
  Added in v.1.1.2.26

  ViewVC Help
Powered by ViewVC 1.1.2