Skip to content

Commit

Permalink
Merge pull request #25084 from FliyFly/feature2#21426
Browse files Browse the repository at this point in the history
NEW Add possibility to choose separator #21426
  • Loading branch information
eldy authored Aug 30, 2023
2 parents b866c1c + 8376c5b commit 9ce9eac
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 15 deletions.
18 changes: 6 additions & 12 deletions htdocs/core/class/html.form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8236,9 +8236,8 @@ public static function selectarray($htmlname, $array, $id = '', $show_empty = 0,
$addjscombo = 0;
}
}

$idname = str_replace(array('[', ']'), array('', ''), $htmlname);
$out .= '<select id="' . preg_replace('/^\./', '', $idname) . '" ' . ($disabled ? 'disabled="disabled" ' : '') . 'class="flat ' . (preg_replace('/^\./', '', $htmlname)) . ($morecss ? ' ' . $morecss : '') . '"';
$out .= '<select id="' . preg_replace('/^\./', '', $idname) . '" ' . ($disabled ? 'disabled="disabled" ' : '') . 'class="flat ' . (preg_replace('/^\./', '', $htmlname)) . ($morecss ? ' ' . $morecss : '') . ' selectformat"';
$out .= ' name="' . preg_replace('/^\./', '', $htmlname) . '" ' . ($moreparam ? $moreparam : '');
$out .= '>'."\n";

Expand All @@ -8252,7 +8251,6 @@ public static function selectarray($htmlname, $array, $id = '', $show_empty = 0,
}
$out .= '<option class="optiongrey" ' . ($moreparamonempty ? $moreparamonempty . ' ' : '') . 'value="' . ($show_empty < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected' : '') . '>' . $textforempty . '</option>' . "\n";
}

if (is_array($array)) {
// Translate
if ($translate) {
Expand All @@ -8264,14 +8262,12 @@ public static function selectarray($htmlname, $array, $id = '', $show_empty = 0,
}
}
}

// Sort
if ($sort == 'ASC') {
asort($array);
} elseif ($sort == 'DESC') {
arsort($array);
}

foreach ($array as $key => $tmpvalue) {
if (is_array($tmpvalue)) {
$value = $tmpvalue['label'];
Expand All @@ -8289,7 +8285,6 @@ public static function selectarray($htmlname, $array, $id = '', $show_empty = 0,
$style = ' class="warning"';
}
}

if ($key_in_label) {
if (empty($nohtmlescape)) {
$selectOptionValue = dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value));
Expand All @@ -8306,7 +8301,6 @@ public static function selectarray($htmlname, $array, $id = '', $show_empty = 0,
$selectOptionValue = '&nbsp;';
}
}

$out .= '<option value="' . $key . '"';
$out .= $style . $disabled;
if (is_array($id)) {
Expand All @@ -8330,25 +8324,25 @@ public static function selectarray($htmlname, $array, $id = '', $show_empty = 0,
}
}
$out .= '>';
//var_dump($selectOptionValue);
$out .= $selectOptionValue;
$out .= "</option>\n";
}
}

$out .= "</select>";

// Add code for jquery to use multiselect
// Add code for jquery to use multiselect
if ($addjscombo && $jsbeautify) {
// Enhance with select2
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
$out .= ajax_combobox($idname, array(), 0, 0, 'resolve', ($show_empty < 0 ? (string) $show_empty : '-1'), $morecss);
}





return $out;
}


/**
* Return a HTML select string, built from an array of key+value, but content returned into select come from an Ajax call of an URL.
* Note: Do not apply langs->trans function on returned content of Ajax service, content may be entity encoded twice.
Expand Down
48 changes: 47 additions & 1 deletion htdocs/core/class/html.formfile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,9 @@ public function showdocuments($modulepart, $modulesubdir, $filedir, $urlsource,
$out .= '<table class="liste formdoc noborder centpercent">';

$out .= '<tr class="liste_titre">';
$addcolumforpicto = ($delallowed || $printer || $morepicto);
$colspan = (4 + ($addcolumforpicto ? 1 : 0));
$colspanmore = 0;

$out .= '<th colspan="'.$colspan.'" class="formdoc liste_titre maxwidthonsmartphone center">';

Expand All @@ -719,7 +722,38 @@ public function showdocuments($modulepart, $modulesubdir, $filedir, $urlsource,
if ($conf->browser->layout == 'phone') {
$morecss = 'maxwidth100';
}
$out .= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss);
$out .= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1, '', 0, 0);
// script for select the separator
$out .= '<label class="forhide" for="delimiter">Delimiter:</label>';
$out .= '<input type="radio" class="testinput forhide" name="delimiter" value="," id="comma" checked><label class="forhide" for="comma">,</label>';
$out .= '<input type="radio" class="testinput forhide" name="delimiter" value=";" id="semicolon"><label class="forhide" for="semicolon">;</label>';

$out .= '<script>
jQuery(document).ready(function() {
$(".selectformat").on("change", function() {
var separator;
var selected = $(this).val();
if (selected == "excel2007" || selected == "tsv") {
$("input.testinput").prop("disabled", true);
$(".forhide").hide();
} else {
$("input.testinput").prop("disabled", false);
$(".forhide").show();
}
if ($("#semicolon").is(":checked")) {
separator = ";";
} else {
separator = ",";
}
});
if ("' . $conf->global->EXPORT_CSV_SEPARATOR_TO_USE . '" == ";") {
$("#semicolon").prop("checked", true);
} else {
$("#comma").prop("checked", true);
}
});
</script>';
if ($conf->use_javascript_ajax) {
$out .= ajax_combobox('model');
}
Expand Down Expand Up @@ -977,6 +1011,18 @@ public function showdocuments($modulepart, $modulesubdir, $filedir, $urlsource,
}
}
$out .= '<!-- End show_document -->'."\n";

$out .= '<script>
jQuery(document).ready(function() {
var selectedValue = $(".selectformat").val();
if (selectedValue === "excel2007" || selectedValue === "tsv") {
$(".forhide").prop("disabled", true).hide();
} else {
$(".forhide").prop("disabled", false).show();
}
});
</script>';
//return ($i?$i:$headershown);
return $out;
}
Expand Down
1 change: 1 addition & 0 deletions htdocs/core/modules/export/modules_export.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function listOfAvailableExportFormat($db, $maxfilenamelength = 0)
require_once $file;
if (class_exists($classname)) {
$module = new $classname($db);
// var_dump($classname);

// Picto
$this->picto[$module->id] = $module->picto;
Expand Down
7 changes: 6 additions & 1 deletion htdocs/exports/class/export.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,10 @@ public function genDocFilter($TypeField)
* @param array $array_selected Filter on array of fields to export
* @param array $array_filterValue Filter on array of fields with a filter
* @param string $sqlquery If set, transmit the sql request for select (otherwise, sql request is generated from arrays)
* @param string $separator separator to fill $objmodel->separator with the new separator
* @return int <0 if KO, >0 if OK
*/
public function build_file($user, $model, $datatoexport, $array_selected, $array_filterValue, $sqlquery = '')
public function build_file($user, $model, $datatoexport, $array_selected, $array_filterValue, $sqlquery = '', $separator = '')
{
// phpcs:enable
global $conf, $langs, $mysoc;
Expand All @@ -612,6 +613,10 @@ public function build_file($user, $model, $datatoexport, $array_selected, $array
require_once $dir.$file;
$objmodel = new $classname($this->db);

if (in_array($model, array('csvutf8', 'csviso')) && !empty($separator)) {
$objmodel->separator = $separator;
}

if (!empty($sqlquery)) {
$sql = $sqlquery;
} else {
Expand Down
3 changes: 2 additions & 1 deletion htdocs/exports/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
}

if ($action == 'builddoc') {
$separator = GETPOST('delimiter', 'alpha');
$max_execution_time_for_importexport = (empty($conf->global->EXPORT_MAX_EXECUTION_TIME) ? 300 : $conf->global->EXPORT_MAX_EXECUTION_TIME); // 5mn if not defined
$max_time = @ini_get("max_execution_time");
if ($max_time && $max_time < $max_execution_time_for_importexport) {
Expand All @@ -277,7 +278,7 @@
}

// Build export file
$result = $objexport->build_file($user, GETPOST('model', 'alpha'), $datatoexport, $array_selected, $array_filtervalue);
$result = $objexport->build_file($user, GETPOST('model', 'alpha'), $datatoexport, $array_selected, $array_filtervalue, '', $separator);
if ($result < 0) {
setEventMessages($objexport->error, $objexport->errors, 'errors');
$sqlusedforexport = $objexport->sqlusedforexport;
Expand Down

0 comments on commit 9ce9eac

Please sign in to comment.