The information in this topic is supplementary to the description of export highlighted in Export explained and is intended for use by developers.
Templates must be located in /bitrix/php_interface/include/catalog_export/
. The preset templates call the existing scripts only. Custom templates must contain all the code required for
the export. The system considers all files in this folder ending with
_run.php
as templates. If the folder contains a file with the same name but ending with _setup.php
the system considers this file as the export wizard for the corresponding
export template.
If the export template contains the tag <title>
(even if in PHP comments), the inner text of this tag is treated as the export template name. Otherwise, the name of the template
is taken after the file name.
You can add any number of templates to the folder /bitrix/php_interface/include/catalog_export/
.
An export template is a common PHP scripts without any data input. This script can use all standard variables and those specified in the export wizard.
The export template can assign a text value to the variable $strExportErrorMessage
containing the description of errors occurred during export. In this case, the system will consider
export unsuccessful and display the contents of $strExportErrorMessage
.
If the system detects the variable $SETUP_FILE_NAME
accessible, the system will treat this name as the path to file containing the exported data. This path may be either relative or
absolute. The system will display the full path name of this file.
<? // <title>Simplest</title> // Print the name of the selected information blocks $strName = ""; // The variable $IBLOCK_ID must be set by either export wizard // or taken from profile // The variable $SETUP_FILE_NAME must be set by either export wizard // or taken from profile $IBLOCK_ID = IntVal($IBLOCK_ID); // Catalog and iblock modules had been connected $db_res = CIBlock::GetList(Array(), Array("ID"=>IntVal($IBLOCK_ID))); if ($ar_res = $db_res->Fetch()) { $strName = $ar_res["NAME"]; } if (strlen($strName)>0) { if ($fp = @fopen($_SERVER["DOCUMENT_ROOT"].$SETUP_FILE_NAME, 'wb')) { @fwrite($fp, $strName); @fclose($fp); } else { $strExportErrorMessage = "Error opening data file for writing"; } } else { $strExportErrorMessage = "IBlock not found"; } ?>
Export wizard aims to provide additional export parameters (choosing catalogs and groups for export, specifying the path to a data file etc.). If an export template does not require extra parameters, export wizard is optional.
An export wizard may have multiple steps. In this case, you should use the variable $STEP
which contains the current wizard step. When passing to the next step, you have to increment
its value by 1.
The last step must set the variable $FINITE
to True. The system treats this flag as the indicator to finish the export wizard and passes control over to an export template or saves a
profile.
When the export wizard terminates, it must set the variable $SETUP_FIELDS_LIST
. This variable contains a list of names of variables that the wizard has set. Names must be separated
with commas.
If the final action of the wizard is the export profile creation (i.e. $ACTION
contains a value of EXPORT_SETUP
), the variable $SETUP_PROFILE_NAME
must be set
to the name of the profile to be created.
You should also set the variable $SETUP_FILE_NAME
to the name of a data file. In this case, the system will automatically prompt a user with the data file name.
<? $strMyError = ""; if ($STEP>1) { $IBLOCK_ID = IntVal($IBLOCK_ID); if ($IBLOCK_ID<=0) { $strMyError .= "Information block not selected.<br>"; } if (strlen($SETUP_FILE_NAME)<=0) $strMyError .= "Data file not specified.<br>"; if ($ACTION=="EXPORT_SETUP" && strlen($SETUP_PROFILE_NAME)<=0) $strMyError .= "Profile name not specified<br>"; if (strlen($strMyError)>0) { $STEP = 1; } } echo ShowError($strMyError); if ($STEP==1) { ?> <form method="post" action="<?echo $APPLICATION->GetCurPage() ?>"> Please select the information block: <select name="IBLOCK_ID"> <? $db_res = CIBlock::GetList(Array("iblock_type"=>"asc", "name"=>"asc")); while ($res = $db_res->Fetch()) { ?> <option value="<?echo $res["ID"] ?>" <?if (IntVal($res["ID"])==$IBLOCK_ID) echo " selected";?>> <?echo $res["NAME"];?> </option> <? } ?> </select><br> Please enter the data file name: <input type="text" name="SETUP_FILE_NAME" value="<?echo (strlen($SETUP_FILE_NAME)>0) ? htmlspecialchars($SETUP_FILE_NAME) : "/upload/file.csv" ?>" size="50"> <br> <?if ($ACTION=="EXPORT_SETUP"):?> Profile name: <input type="text" name="SETUP_PROFILE_NAME" value="<?echo htmlspecialchars($SETUP_PROFILE_NAME)?>" size="30"> <br> <?endif;?> <?//The following variables MUST be set?> <input type="hidden" name="lang" value="<?echo $lang ?>"> <input type="hidden" name="ACT_FILE" value="<?echo htmlspecialchars($_REQUEST["ACT_FILE"]) ?>"> <input type="hidden" name="ACTION" value="<?echo $ACTION ?>"> <input type="hidden" name="STEP" value="<?echo $STEP + 1 ?>"> <input type="hidden" name="SETUP_FIELDS_LIST" value="IBLOCK_ID,SETUP_FILE_NAME"> <input type="submit" value="<?echo ($ACTION=="EXPORT")?"Export":"Save";?>"> </form> <? } elseif ($STEP==2) { //We want only one step; pass the control $FINITE = True; } ?>
© 2001-2005 Bitrix | Bitrix Site Manager - Content Management & Portal Solutions |