cnt != 1) {
continue;
}
$twtid = $tblrow->twtid;
$tablename = $tblrow->tablename;
$dbconnection = $tblrow->dbconnection;
if ($dbconnection == 'default') {
$rawtablename = schema_unprefix_table($tablename);
$cleantablename = $rawtablename;
}
else {
global $db_url;
$url = parse_url($db_url[$dbconnection ]);
$truedbname = substr($url['path'], 1);
$rawtablename = $tablename;
$cleantablename = $truedbname . '_' . $tablename;
}
// Create a basic table view, with exclusion flags, for each import table
$view = new view;
$view->name = $tablename;
$view->description = $tablename;
$view->tag = 'tw';
$view->view_php = '';
$view->base_table = $rawtablename;
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', $tablename, 'default');
// Grab the available columns for this table (skip any marked ignore)
$pk = NULL;
$colnames = array();
$sql = "SELECT colname, primarykey
FROM {tw_columns}
WHERE ignorecol=0 AND twtid=%d
ORDER BY weight";
$colresult = db_query($sql, $twtid);
while ($colrow = db_fetch_object($colresult)) {
$colnames[] = $colrow->colname;
if ($colrow->primarykey) {
$pk = $colrow->colname;
}
}
// Add our columns to the fields
$fields = array();
foreach ($colnames as $colname) {
$fields[$colname] = array(
'id' => $colname,
'table' => $rawtablename,
'field' => $colname,
'label' => $colname,
'exclude' => 0,
'relationship' => 'none',
);
}
$handler->override_option('fields', $fields);
$handler->override_option('access', array(
'type' => 'perm',
'perm' => TW_ACCESS,
));
$handler->override_option('title', t('Contents of !tablename', array('!tablename' => $rawtablename)));
$handler->override_option('header', t('This is a view of a raw database table. It may be ' .
'sorted in various ways by clicking the column headers.
If you identify a particular field that does not need to be used in views of this table, ' .
'go to the analysis page ' .
'and check the Ignore box for that field. It will then no longer appear here.',
array('!analyze_url' => url("admin/content/tw/analyze/$rawtablename"))));
$handler->override_option('header_format', '1');
$handler->override_option('header_empty', 0);
$handler->override_option('empty', 'There are no rows in this table.');
$handler->override_option('empty_format', '1');
$handler->override_option('items_per_page', 25);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'table');
// Add our columns into the style options
$columns = array();
foreach ($colnames as $colname) {
$columns[$colname] = $colname;
}
$info = array();
foreach ($colnames as $colname) {
$info[$colname] = array(
'sortable' => 1,
'separator' => '',
);
}
$handler->override_option('style_options', array(
'grouping' => '',
'override' => 1,
'sticky' => 1,
'order' => 'asc',
'columns' => $columns,
'info' => $info,
'default' => -1,
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', "admin/content/tw/view/$tablename");
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$views[$view->name] = $view;
}
return $views;
}