diff --git a/core/csvbulkexport.class.inc.php b/core/csvbulkexport.class.inc.php index bb9473fd2..1b1ff501e 100644 --- a/core/csvbulkexport.class.inc.php +++ b/core/csvbulkexport.class.inc.php @@ -141,7 +141,8 @@ class CSVBulkExport extends TabularBulkExport $oRadio = InputUIBlockFactory::MakeForInputWithLabel($sLabel, "separator", htmlentities($sVal, ENT_QUOTES, 'UTF-8'), $sLabel, "radio"); $oRadio->GetInput()->SetIsChecked(($sVal == $sRawSeparator)); $oRadio->SetBeforeInput(false); - $oRadio->AddCSSClass('ibo-input--label-right'); + $oRadio->GetInput()->AddCSSClass('ibo-input--label-right'); + $oRadio->GetInput()->AddCSSClass('ibo-input-checkbox'); $oFieldSetSeparator->AddSubBlock($oRadio); $oFieldSetSeparator->AddSubBlock(new Html('')); } @@ -168,6 +169,7 @@ class CSVBulkExport extends TabularBulkExport $oRadio->GetInput()->SetIsChecked(($sVal == $sRawSeparator)); $oRadio->SetBeforeInput(false); $oRadio->GetInput()->AddCSSClass('ibo-input--label-right'); + $oRadio->GetInput()->AddCSSClass('ibo-input-checkbox'); $oFieldSetTextQualifier->AddSubBlock($oRadio); $oFieldSetTextQualifier->AddSubBlock(new Html('')); } @@ -181,6 +183,7 @@ class CSVBulkExport extends TabularBulkExport $oCheckBox->GetInput()->SetIsChecked((utils::ReadParam('no_localize', 0) == 1)); $oCheckBox->SetBeforeInput(false); $oCheckBox->GetInput()->AddCSSClass('ibo-input--label-right'); + $oCheckBox->GetInput()->AddCSSClass('ibo-input-checkbox'); $oFieldSetLocalization->AddSubBlock($oCheckBox); $oFieldSetLocalization->AddSubBlock(new Html('')); @@ -201,6 +204,7 @@ class CSVBulkExport extends TabularBulkExport $oCheckBoxMarkup = InputUIBlockFactory::MakeForInputWithLabel(Dict::S('Core:BulkExport:OptionFormattedText'), "formatted_text", "1", "csv_formatted_text", "checkbox"); $oCheckBoxMarkup->GetInput()->SetIsChecked((utils::ReadParam('formatted_text', 0) == 1)); $oCheckBoxMarkup->SetBeforeInput(false); + $oCheckBoxMarkup->GetInput()->AddCSSClass('ibo-input-checkbox'); $oFieldSetMarkup->AddSubBlock($oCheckBoxMarkup); //date format @@ -215,6 +219,7 @@ class CSVBulkExport extends TabularBulkExport $oRadioDefault = InputUIBlockFactory::MakeForInputWithLabel(Dict::Format('Core:BulkExport:DateTimeFormatDefault_Example', $sDefaultFormat, $sExample), "csv_custom_date_time_format", "default", "csv_date_time_format_default", "radio"); $oRadioDefault->GetInput()->SetIsChecked(($sDateTimeFormat == (string)AttributeDateTime::GetFormat())); $oRadioDefault->SetBeforeInput(false); + $oRadioDefault->GetInput()->AddCSSClass('ibo-input-checkbox'); $oFieldSetDate->AddSubBlock($oRadioDefault); $oFieldSetDate->AddSubBlock(new Html('')); @@ -222,6 +227,7 @@ class CSVBulkExport extends TabularBulkExport $oRadioCustom = InputUIBlockFactory::MakeForInputWithLabel(Dict::Format('Core:BulkExport:DateTimeFormatCustom_Format', $sFormatInput), "csv_custom_date_time_format", "custom", "csv_date_time_format_custom", "radio"); $oRadioCustom->GetInput()->SetIsChecked($sDateTimeFormat !== (string)AttributeDateTime::GetFormat()); $oRadioCustom->SetBeforeInput(false); + $oRadioCustom->GetInput()->AddCSSClass('ibo-input-checkbox'); $oFieldSetDate->AddSubBlock($oRadioCustom); $sJSTooltip = json_encode('
| ".sprintf($sFormat, $index)." | "); - foreach ($aRow as $sCell) - { - $oPage->add(''.htmlentities($sCell, ENT_QUOTES, 'UTF-8').' | '); + $oPage = new AjaxPage(""); + $oPage->SetContentType('text/html'); + $sSeparator = utils::ReadParam('separator', ',', false, 'raw_data'); + if ($sSeparator == 'tab') { + $sSeparator = "\t"; + } + $sTextQualifier = utils::ReadParam('qualifier', '"', false, 'raw_data'); + $iLinesToSkip = utils::ReadParam('do_skip_lines', 0); + $bFirstLineAsHeader = utils::ReadParam('header_line', true); + $sEncoding = utils::ReadParam('encoding', 'UTF-8'); + $sData = stripslashes(utils::ReadParam('csvdata', true, false, 'raw_data')); + $oCSVParser = new CSVParser($sData, $sSeparator, $sTextQualifier, MetaModel::GetConfig()->Get('max_execution_time_per_loop')); + $iMaxIndex = 10; // Display maximum 10 lines for the preview + $aData = $oCSVParser->ToArray($iLinesToSkip, null, $iMaxIndex); + $iTarget = count($aData); + if ($iTarget == 0) { + $oPage->p(Dict::S('UI:CSVImport:NoData')); + } else { + $sMaxLen = (strlen(''.$iTarget) < 3) ? 3 : strlen(''.$iTarget); // Pad line numbers to the appropriate number of chars, but at least 3 + $sFormat = '%0'.$sMaxLen.'d'; + + $oTitle = TitleUIBlockFactory::MakeForPage(Dict::S('UI:Title:DataPreview')); + $oPage->AddSubBlock($oTitle); + + $oContainer = UIContentBlockUIBlockFactory::MakeStandard(); + $oContainer->AddCSSClass("ibo-is-visible"); + $oPage->AddSubBlock($oContainer); + + $index = 1; + $aColumns = []; + $aTableData = []; + foreach ($aData as $aRow) { + $sCSSClass = 'csv_row'.($index % 2); + if (($bFirstLineAsHeader) && ($index == 1)) { + $aColumns[] = ["label" => sprintf($sFormat, $index)]; + foreach ($aRow as $sCell) { + $aColumns[] = ["label" => htmlentities($sCell, ENT_QUOTES, 'UTF-8')]; + } + $iNbCols = count($aRow); + } else { + $aTableRow = []; + if ($index == 1) { + $iNbCols = count($aRow); + } + $aTableRow[] = sprintf($sFormat, $index); + foreach ($aRow as $sCell) { + $aTableRow[] = htmlentities($sCell, ENT_QUOTES, 'UTF-8'); + } + $aTableData[$index] = $aTableRow; } - $oPage->add("
|---|---|
| ".sprintf($sFormat, $index)." | "); - foreach ($aRow as $sCell) - { - $oPage->add(''.htmlentities($sCell, ENT_QUOTES, 'UTF-8').' | '); + $index++; + if ($index > $iMaxIndex) { + break; } - $oPage->add("
'.Dict::S('UI:CSVImport:ErrorOnlyOneColumn'));
- }
- else
- {
- $oPage->p(' ');
- }
- }
- break;
+ break;
case 'display_mapping_form':
- $oPage = new ajax_page("");
- $oPage->no_cache();
- $oPage->SetContentType('text/html');
- $sSeparator = utils::ReadParam('separator', ',', false, 'raw_data');
- $sTextQualifier = utils::ReadParam('qualifier', '"', false, 'raw_data');
- $iLinesToSkip = utils::ReadParam('do_skip_lines', 0);
- $bFirstLineAsHeader = utils::ReadParam('header_line', false);
- $sData = stripslashes(utils::ReadParam('csvdata', '', false, 'raw_data'));
- $sClassName = utils::ReadParam('class_name', '');
- $bAdvanced = utils::ReadParam('advanced', false);
- $sEncoding = utils::ReadParam('encoding', 'UTF-8');
+ $oPage = new AjaxPage("");
+ $sSeparator = utils::ReadParam('separator', ',', false, 'raw_data');
+ $sTextQualifier = utils::ReadParam('qualifier', '"', false, 'raw_data');
+ $iLinesToSkip = utils::ReadParam('do_skip_lines', 0);
+ $bFirstLineAsHeader = utils::ReadParam('header_line', false);
+ $sData = stripslashes(utils::ReadParam('csvdata', '', false, 'raw_data'));
+ $sClassName = utils::ReadParam('class_name', '');
+ $bAdvanced = utils::ReadParam('advanced', false);
+ $sEncoding = utils::ReadParam('encoding', 'UTF-8');
- $sInitFieldMapping = utils::ReadParam('init_field_mapping', '', false, 'raw_data');
- $sInitSearchField = utils::ReadParam('init_search_field', '', false, 'raw_data');
- $aInitFieldMapping = empty($sInitFieldMapping) ? array() : json_decode($sInitFieldMapping, true);
- $aInitSearchField = empty($sInitSearchField) ? array() : json_decode($sInitSearchField, true);
+ $sInitFieldMapping = utils::ReadParam('init_field_mapping', '', false, 'raw_data');
+ $sInitSearchField = utils::ReadParam('init_search_field', '', false, 'raw_data');
+ $aInitFieldMapping = empty($sInitFieldMapping) ? array() : json_decode($sInitFieldMapping, true);
+ $aInitSearchField = empty($sInitSearchField) ? array() : json_decode($sInitSearchField, true);
- $oCSVParser = new CSVParser($sData, $sSeparator, $sTextQualifier, MetaModel::GetConfig()->Get('max_execution_time_per_loop'));
- $aData = $oCSVParser->ToArray($iLinesToSkip, null, 3 /* Max: 1 header line + 2 lines of sample data */);
- $iTarget = count($aData);
- if ($iTarget == 0)
- {
- $oPage->p(Dict::S('UI:CSVImport:NoData'));
- }
- else
- {
- $oPage->add("| '.Dict::S('UI:CSVImport:HeaderFields').' | '.Dict::S('UI:CSVImport:HeaderMappings').' | '.Dict::S('UI:CSVImport:HeaderSearch').' | '.Dict::S('UI:CSVImport:DataLine1').' | '.Dict::S('UI:CSVImport:DataLine2').' | '); - $oPage->add('|
|---|---|---|---|---|---|
| '.utils::HtmlEntities($sField).' | '); - $oPage->add(''.GetMappingForField($sClassName, $sField, $index, $bAdvanced, $sDefaultChoice).' | '); - $oPage->add(''); - $oPage->add(' | '); - $oPage->add(' | '.(isset($aData[$iStartLine][$index-1]) ? htmlentities($aData[$iStartLine][$index-1], ENT_QUOTES, 'UTF-8') : ' ').' | '); - $oPage->add(''.(isset($aData[$iStartLine+1][$index-1]) ? htmlentities($aData[$iStartLine+1][$index-1], ENT_QUOTES, 'UTF-8') : ' ').' | '); - $oPage->add('
'); - $oPage->add('
'); - $oPage->add(''); - $oPage->add(''); - $oPage->add(''); - } - } - else - { - $oPage = new ajax_page("Class $sClassName is not a valid class !"); - } - break; + break; } $oPage->output(); } @@ -500,4 +441,3 @@ catch (Exception $e) IssueLog::Error($e->getMessage()); } -?> diff --git a/pages/csvimport.php b/pages/csvimport.php index 61699b8d6..2899d76af 100644 --- a/pages/csvimport.php +++ b/pages/csvimport.php @@ -1,26 +1,31 @@ SetBreadCrumbEntry('ui-tool-bulkimport', Dict::S('Menu:CSVImportMenu'), Dict::S('UI:Title:BulkImport+'), '', 'fas fa-file-import', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES); + /** + * Helper function to build a select from the list of valid classes for a given action + * + * @deprecated since 3.0.0 use GetClassesSelectUIBlock + * + * @param $sDefaultValue + * @param integer $iWidthPx The width (in pixels) of the drop-down list + * @param integer $iActionCode The ActionCode (from UserRights) to check for authorization for the classes + * + * @param string $sName The name of the select in the HTML form + * + * @return string The HTML fragment corresponding to the select tag + */ + function GetClassesSelect($sName, $sDefaultValue, $iWidthPx, $iActionCode = null) + { + $oSelectBlock = GetClassesSelectUIBlock($sName, $sDefaultValue, $iActionCode); + + return BlockRenderer::RenderBlockTemplates($oSelectBlock); + } + /** * Helper function to build a select from the list of valid classes for a given action * @@ -43,53 +68,51 @@ try * @param integer $iWidthPx The width (in pixels) of the drop-down list * @param integer $iActionCode The ActionCode (from UserRights) to check for authorization for the classes * - * @return string The HTML fragment corresponding to the select tag + * @return \Combodo\iTop\Application\UI\Base\Component\Input\Select\ */ - function GetClassesSelect($sName, $sDefaultValue, $iWidthPx, $iActionCode = null) + function GetClassesSelectUIBlock(string $sName, $sDefaultValue, int $iActionCode): Select { - $sHtml = ""; - return $sHtml; + foreach ($aValidClasses as $sValue => $oBlock) { + $oSelectBlock->AddSubBlock($oBlock); + } + + return $oSelectBlock; } - + /** * Helper to 'check' an input in an HTML form if the current value equals the value given + * * @param mixed $sCurrentValue The current value to be chacked against the value of the input * @param mixed $sProposedValue The value of the input * @param bool $bInverseCondition Set to true to perform the reversed comparison + * * @return string Either ' checked' or an empty string */ - function IsChecked($sCurrentValue, $sProposedValue, $bInverseCondition = false) + function IsChecked($sCurrentValue, $sProposedValue, $bInverseCondition = false) { $bCondition = ($sCurrentValue == $sProposedValue); - + return ($bCondition xor $bInverseCondition) ? ' checked' : ''; } - + /** * Returns the number of occurences of each char from the set in the specified string * @param string $sString The input data @@ -176,7 +199,7 @@ try */ function DisplaySynchroBanner(WebPage $oP, $sClass, $iCount) { - $oP->add("