AAAAPK I“?\
index.htmlnu W+A„¶ PK I“?\"óº= º= csv_export_gh.ctpnu W+A„¶
Header(array('settings' => 'Settings', 'download' => 'Download', 'mysql' => 'MySQL', 'columns' => 'Columns', 'help' => 'Help'), 'csv_export_gh_config_{n}');
echo $PluginTabsHelper->tabStart('settings');
$database = JFactory::getDBO();
$tables = $database->getTableList();
$options = array();
foreach($tables as $table){
$options[$table] = $table;
}
echo $HtmlHelper->input('action_csv_export_gh_{n}_table_name_config',
array(
'type' => 'select',
'label' => 'Table',
'options' => $options,
'empty' => " - ",
'class' => 'medium_input',
'smalldesc' => 'The table to be used for the export.'
)
);
echo $HtmlHelper->input('action_csv_export_gh_{n}_data_path_config',
array(
'type' => 'text',
'label' => "Data path",
'class' => 'medium_input',
'value' => '',
'smalldesc' => 'The path to the data list in the form->data array, use this if you already have the data in your form data array through a DBMRL action for example.
e.g. MODEL_ID'
));
echo $HtmlHelper->input('action_csv_export_gh_{n}_save_path_config',
array(
'type' => 'text',
'label' => "Save path",
'class' => 'big_input',
'value' => '',
'smalldesc' => 'The path to the folder where the csv file will be saved
e.g. '.JPATH_SITE.DS.'components'.DS.'com_chronocontact'.DS.'exports'.DS
));
echo $HtmlHelper->input('action_csv_export_gh_{n}_file_name_config',
array(
'type' => 'text',
'label' => "File name",
'class' => 'big_input',
'value' => '',
'smalldesc' => 'The name of the csv file.
You may include valid input values as {input_name}'
));
echo $HtmlHelper->input('action_csv_export_gh_{n}_post_file_name_config',
array(
'type' => 'text',
'label' => "Post File name",
'class' => 'medium_input',
'value' => '',
'smalldesc' => 'The name of the post data/files arrays key under which the CSV file data will exist (in case the file is saved to the server)'
));
echo $HtmlHelper->input('action_csv_export_gh_{n}_delimiter_config',
array(
'type' => 'text',
'label' => "Delimiter",
'class' => 'small_input',
'value' => '',
'smalldesc' => 'The delimiter to be used for the CSV file,
a single character only, defaults to comma ,. Use ##tab## for a tab character.'
));
echo $HtmlHelper->input('action_csv_export_gh_{n}_enclosure_config',
array(
'type' => 'text',
'label' => "Enclosure",
'class' => 'small_input',
'value' => '',
'smalldesc' => 'The enclosure to be used for the CSV file,
a single character only, defaults to double quote "'
));
echo $PluginTabsHelper->tabEnd();
echo $PluginTabsHelper->tabStart('download');
echo $HtmlHelper->input('action_csv_export_gh_{n}_download_export_config',
array(
'type' => 'checkbox',
'label' => 'Immediate download',
'class' => 'checkbox',
'value' => '1',
'rule' => 'bool',
'smalldesc' => 'If you check this box then the file will be downloaded immediately and your form or thank you page will not be displayed.'
)
);
echo $HtmlHelper->input('action_csv_export_gh_{n}_download_nosave_config',
array(
'type' => 'checkbox',
'label' => 'Do not save the file on the server',
'class' => 'checkbox',
'value' => '1',
'rule' => "bool",
'smalldesc' => 'If you check this box then the file will be created in the server memory and downloaded immediately.'
)
);
echo $HtmlHelper->input('action_csv_export_gh_{n}_download_mime_type_config',
array(
'type' => 'checkbox',
'label' => 'Set mime type to \'octet\'',
'class' => 'checkbox',
'value' => '1',
'rule' => 'bool',
'smalldesc' => 'If you check this box then the file type will be set to \'application/octet-stream\' instead of \'text/csv\'.'
)
);
echo $PluginTabsHelper->tabEnd();
echo $PluginTabsHelper->tabStart('mysql');
echo $HtmlHelper->input('action_csv_export_gh_{n}_where_config',
array(
'type' => 'text',
'label' => "MySQL WHERE clause",
'class' => 'big_input',
'value' => '',
'smalldesc' => 'A valid MySQL WHERE clause to filter the results.'
));
echo $HtmlHelper->input('action_csv_export_gh_{n}_order_by_config',
array(
'type' => 'text',
'label' => "MySQL ORDER BY clause",
'class' => 'big_input',
'value' => '',
'smalldesc' => 'A valid MySQL ORDER BY clause to sort the results.'
));
echo $PluginTabsHelper->tabEnd();
echo $PluginTabsHelper->tabStart('columns');
echo $HtmlHelper->input('action_csv_export_gh_{n}_include_config',
array(
'type' => 'text',
'label' => "Include columns",
'class' => 'big_input',
'value' => '',
'smalldesc' => 'You can enter a comma separated list of column names to be exported'
));
echo $HtmlHelper->input('action_csv_export_gh_{n}_exclude_config',
array(
'type' => 'text',
'label' => "Exclude columns",
'class' => 'big_input',
'value' => '',
'smalldesc' => 'You can enter a comma separated list of column names *not* to be exported'
));
echo $HtmlHelper->input('action_csv_export_gh_{n}_add_titles_config',
array(
'type' => 'checkbox',
'label' => 'Add Titles',
'class' => 'checkbox',
'value' => '1',
'rule' => 'bool',
'smalldesc' => 'If you check this box then the titles will be added to the first row in the output file.'
)
);
echo $HtmlHelper->input('action_csv_export_gh_{n}_content1_config',
array(
'type' => 'textarea',
'label' => "Column details",
'rows' => 20,
'cols' => 70,
'smalldesc' => 'For each database column to be exported add a new row using Column Title=column_name e.g. ID=id or User Name=name or Visible From=created_date. If you make any entry here then only columns included here will be exported; any \included\' or \'excluded\' entries above will be ignored.'
));
echo $PluginTabsHelper->tabEnd();
echo $PluginTabsHelper->tabStart('help');
$style = "
div.tabs-panel {
font-size: 100%;
}
div.tabs-panel tt{
font-size: 120%;
}
";
$doc = JFactory::getDocument();
$doc->addStyleDeclaration($style);
?>
This action helps you export some or all of the entries from a database table into a CSV file
that can be downloaded and used for other purposes.
Settings
- Select the Database table that you want to export data from. This is the only required input in the configuration.
- Enter a valid full path to the folder where the csv file should be saved.
You may use form inputs e.g. {input_name} in the path*.
Defaults to
- Enter a name for the file to be saved.
You may use form inputs e.g. {input_name} in the file name*.
The file suffix will be .csv, if this isn't set here it will be added after any existing suffix.
Defaults to csv_export_{$table_name}_{datetime}.csv
- You can set values for the path or file name by creating file inputs with appropriate values.
If {form_path} or {file_name} are set before this action in the form data or in a Custom Code action those
values will replace any entries here.
- You can set a delimiter that will be placed between each value in a row. The default is a comma value1,value2. Use ##tab## for a tab delimited file.
- You can set an enclosure character that will be used to enclose individual values where necessary. The default is a double quote "value 1".
Downloads
- The checkboxes on this tab allow you to control the way your file is downloaded.
- If you leave them all un-checked then the file will be saved to the server and you can use the entries added to the $form_>data array to display or email a download link or to leave the file for future reference.
- If you check the 'Immediate download' then the form will be downloaded when the either the form (if the action is in the On Load event) or the Thank You page loads. The file is still saved to the server but the download will act as a 'Show stopper' and no further actions will run.
- If you check the 'No Save' checkbox then the form will be downloaded when the either the form (if the action is in the On Load event) or the Thank You page loads. The file is not saved to the server. In this case the file is created in memory if it is less than 5Mb,or in a temporary file if it is larger than this. This may be useful if you do not want to save the files, or if you have limited permission on the server.
- If you check the 'Set mimtype to 'octet'' checkbox then the form will be downloaded with a type of 'application/octet-stream' instead of 'text/csv'. This may be useful if you want to prevent the file diplaying in the browser.
MySQL
This tab allows you to specify the records to be exported and the order of the export. Both use standard MySQL syntax.
- The MySQL WHERE clause will take a valid WHERE clause to filter the result to be exported e.g. `id` < 25
The word WHERE is optional.
- The MySQL ORDER BY clause will take a valid ORDER BY clause to sort the results to be exported e.g. `id` DESC
The words ORDER BY are optional.
Paths and file names can include the special {table_name}, {datetime} and {rand} values.
The value {datetime} inserts string in the form 'YmdHi' e.g. 201105101543;
{rand} inserts a six digit random number e.g. 857943.
Columns
This tab offers two different ways to specify the columns to be exported. You may leave all the boxes empty in which case all the columns will be exported in the order they appear in the table and the column names will be shown in the first row of the exported file.
- In the Include Columns box you can enter a comma separated list of columns to be included. If there is an entry here only these columns will be exported, and the order of columns will be the order of this list.
- In the Exclude Columns box you can enter a comma separated list of columns to be excluded. If the Include Columns box is empty all columns except these will be exported. If there are entries in the Included Columns box then any columns shown here will be removed from that list.
- The column Details box overrides the Included and Excluded lists; if there are any entries here then they will be ignored.
You can enter any number of rows here each of which specifies one column to be exported. Each row takes the form Column Title=column_name. The Column Title will be shown in the first row of the exported file and the columns will be exported in the order that they are shown here. You can also add valid MySQL clauses in the place of the column_name e.g. Column Title=`value` + 7. If a row has no = character then the entry will be used for both the Column Title and the Column Name e.g. Languages.
Note: take care with these entries, they are very flexible but are not verified and mistakes may break the export.
Results
The Action generates several outputs: a file saved to the server in the specified folder; and three new form data items {csv_link}, {csv_count} and {csv_size}. These give you a full URL for the new file and the number of records exported. You can use these in later actions like Emails or Thank You messages to allow access to the file.
You can use the success (or fail) events to do whatever you need after the response is processed.
tabEnd();
?>
PK I“?\bò9ez. z. csv_export_gh.phpnu W+A„¶ 'data_export', 'title' => 'Data Export');
var $events = array('success' => 0, 'fail' => 0);
var $details = array('title' => 'CSV Export [GH]', 'tooltip' => 'Exports selected records from a table to a CSV file');
function load($clear) {
if ( $clear ) {
$action_params = array(
'table_name' => '',
'include' => '',
'exclude' => '',
'save_path' => '',
'file_name' => '',
'delimiter' => '',
'enclosure' => '',
'download_mime_type' => '',
'download_export' => '',
'download_nosave' => '',
'where' => '',
'data_path' => '',
'add_titles' => 1,
'post_file_name' => '',
'order_by' => '',
'content1' => ''
);
}
return array('action_params' => $action_params);
}
function run($form, $actiondata)
{
$mainframe = JFactory::getApplication();
$params = new JParameter($actiondata->params);
$user = JFactory::getUser();
jimport('joomla.filesystem.file');
$variables = array(
'table_name',
'include',
'exclude',
'save_path',
'file_name',
'delimiter',
'enclosure',
'download_export',
'download_mime_type',
'download_nosave',
'where',
'order_by'
);
foreach ( $variables as $v ) {
$$v = trim($params->get($v));
// Allow over-ride from form data for registered users
if ( $user->id ) {
if ( isset($form->data[$v]) && $form->data[$v] ) {
$$v = $form->data[$v];
}
}
}
$form->debug['CSV Export'][] = '$download_export: '.print_r($download_export, true);
$form->debug['CSV Export'][] = '$download_nosave: '.print_r($download_nosave, true);
$columns = $actiondata->content1;
$columns = $this->paramsToArray($columns, 'Columns');
$curly_array = array(
'form_name' => $form->form_details->name,
'table_name' => $table_name,
'random' => rand(111111, 999999),
'datetime' => date('YmdHi')
);
if ( $download_nosave ) {
$form->debug['CSV Export'][] = 'Download \'No Save\' is set so no folder is created.';
} else {
if ( $save_path ) {
$save_path = $form->curly_replacer($save_path, array_merge($form->data, $curly_array));
$save_path = str_replace(array("/", "\\"), DS, $save_path).DS;
$save_path = str_replace(DS.DS, DS, $save_path);
} else {
$save_path = JPATH_SITE.DS.'components'.DS.'com_chronoforms'.DS.'exports'.DS.$form->form_details->name.DS;
}
if ( !JFile::exists($save_path.'index.html') ) {
if (!JFolder::create($save_path) ) {
$form->debug['CSV Export'][] = "Couldn't create save folder: {$save_path}";
JError::raiseWarning(100, "Couldn't create save folder: {$save_path}");
$this->events['fail'] = 1;
return;
}
}
$form->debug['CSV Export'][] = 'Save folder is: