コード例 #1
0
ファイル: ImportFileCSV.php プロジェクト: Maxlander/shixi
 public function SJB_ImportFileCSV($file_info, $csv_delimiter = ';')
 {
     ini_set("auto_detect_line_endings", true);
     $this->data = array();
     parent::SJB_ImportFile($file_info);
     switch ($csv_delimiter) {
         case 'comma':
         case ',':
             $this->csv_delimiter = ",";
             break;
         case 'tab':
             $this->csv_delimiter = "\t";
             break;
         default:
             $this->csv_delimiter = ';';
             break;
     }
 }
コード例 #2
0
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8');
     $preview = SJB_Request::getVar('preview', false);
     $importedDataForPreview = array();
     $template_processor = SJB_System::getTemplateProcessor();
     $errors = null;
     $start_line = SJB_Request::getVar('start_line', null);
     $name_column = SJB_Request::getVar('name_column', null);
     $longitude_column = SJB_Request::getVar('longitude_column', null);
     $latitude_column = SJB_Request::getVar('latitude_column', null);
     $city_column = SJB_Request::getVar('city_column', null);
     $state_column = SJB_Request::getVar('state_column', null);
     $state_code_column = SJB_Request::getVar('state_code_column', null);
     $country_sid = SJB_Request::getVar('country_sid', null);
     $file_format = SJB_Request::getVar('file_format', null);
     $fields_delimiter = SJB_Request::getVar('fields_delimiter', null);
     $imported_file_config['start_line'] = $start_line;
     $imported_file_config['name_column'] = $name_column;
     $imported_file_config['longitude_column'] = $longitude_column;
     $imported_file_config['latitude_column'] = $latitude_column;
     $imported_file_config['city_column'] = $city_column;
     $imported_file_config['state_column'] = $state_column;
     $imported_file_config['state_code_column'] = $state_code_column;
     $imported_file_config['file_format'] = $file_format;
     $imported_file_config['fields_delimiter'] = $fields_delimiter;
     $imported_location_count = null;
     if (isset($_FILES['imported_geo_file']) && !$_FILES['imported_geo_file']['error']) {
         $fileInfo = $_FILES['imported_geo_file'];
         $fileFormats = array('csv', 'xls', 'xlsx');
         $pathInfo = pathinfo($fileInfo['name']);
         $fileExtension = isset($pathInfo['extension']) ? strtolower($pathInfo['extension']) : '';
         if (!in_array(strtolower($fileExtension), $fileFormats)) {
             $errors['File'] = 'WRONG_FORMAT';
         }
         if (empty($_FILES['imported_geo_file']['name'])) {
             $errors['File'] = 'EMPTY_VALUE';
         }
         if (empty($start_line)) {
             $errors['Start Line'] = 'EMPTY_VALUE';
         } elseif (!is_numeric($start_line) || !is_int($start_line + 0)) {
             $errors['Start Line'] = 'NOT_INT_VALUE';
         }
         if (empty($name_column)) {
             $errors['Name Column'] = 'EMPTY_VALUE';
         } elseif (!is_numeric($name_column) || !is_int($name_column + 0)) {
             $errors['Name Column'] = 'NOT_INT_VALUE';
         }
         if (empty($longitude_column)) {
             $errors['Longitude Column'] = 'EMPTY_VALUE';
         } elseif (!is_numeric($longitude_column) || !is_int($longitude_column + 0)) {
             $errors['Longitude Column'] = 'NOT_INT_VALUE';
         }
         if (empty($latitude_column)) {
             $errors['Latitude Column'] = 'EMPTY_VALUE';
         } elseif (!is_numeric($latitude_column) || !is_int($latitude_column + 0)) {
             $errors['Latitude Column'] = 'NOT_INT_VALUE';
         }
         if (empty($country_sid)) {
             $errors['Country'] = 'EMPTY_VALUE';
         }
         if (!SJB_ImportFile::isValidFileExtensionByFormat($file_format, $_FILES['imported_geo_file'])) {
             $errors['File'] = 'DO_NOT_MATCH_SELECTED_FILE_FORMAT';
         }
         if (!SJB_ImportFile::isValidFileCharset($_FILES['imported_geo_file'], $encodingFromCharset)) {
             $errors['Charset'] = 'CHARSET_INCORRECT';
         }
         if (is_null($errors)) {
             set_time_limit(0);
             $file_info = SJB_Array::get($_FILES, 'imported_geo_file');
             if (!strcasecmp($file_format, 'excel')) {
                 $import_file = new SJB_ImportFileXLS($file_info);
             } else {
                 if ($fields_delimiter == 'semicolon') {
                     $fields_delimiter = ';';
                 } elseif ($fields_delimiter == 'tab') {
                     $fields_delimiter = "\t";
                 } else {
                     $fields_delimiter = ',';
                 }
                 $import_file = new SJB_ImportFileCSV($file_info, $fields_delimiter);
             }
             $import_file->parse($encodingFromCharset);
             $imported_data = $import_file->getData();
             $imported_location_count = 0;
             $countryInfo = SJB_CountriesManager::getCountryInfoBySID($country_sid);
             foreach ($imported_data as $key => $importedColumn) {
                 if (empty($importedColumn[$name_column - 1]) || empty($importedColumn[$longitude_column - 1]) || empty($importedColumn[$latitude_column - 1]) || $start_line > $key) {
                     continue;
                 }
                 $name = $importedColumn[$name_column - 1];
                 $longitude = $importedColumn[$longitude_column - 1];
                 $latitude = $importedColumn[$latitude_column - 1];
                 $city = isset($importedColumn[$city_column - 1]) ? $importedColumn[$city_column - 1] : null;
                 $state = isset($importedColumn[$state_column - 1]) ? $importedColumn[$state_column - 1] : null;
                 $state_code = isset($importedColumn[$state_code_column - 1]) ? $importedColumn[$state_code_column - 1] : null;
                 if ($preview) {
                     if (count($importedDataForPreview) >= 10) {
                         break;
                     }
                     $importedDataForPreview[] = array('name' => $name, 'longitude' => $longitude, 'latitude' => $latitude, 'city' => $city, 'state' => $state, 'stateCode' => $state_code, 'country' => $countryInfo['country_name']);
                 } else {
                     $imported_location_count += SJB_LocationManager::addLocation($name, $longitude, $latitude, $city, $state, $state_code, $country_sid, $countryInfo);
                 }
             }
         }
     } elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $errorSid = isset($_FILES['imported_geo_file']['error']) ? $_FILES['imported_geo_file']['error'] : 0;
         $errors['File'] = SJB_UploadFileManager::getErrorId($errorSid);
     }
     $countries = SJB_CountriesManager::getAllCountriesCodesAndNames();
     $template_processor->assign("charSets", SJB_HelperFunctions::getCharSets());
     $template_processor->assign("importedGeographicData", $importedDataForPreview);
     $template_processor->assign("countries", $countries);
     $template_processor->assign("country_sid", $country_sid);
     $template_processor->assign("errors", $errors);
     $template_processor->assign("imported_location_count", $imported_location_count);
     $template_processor->assign("imported_file_config", $imported_file_config);
     $template_processor->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
     if ($preview) {
         $template_processor->display("import_geographic_data_preview.tpl");
     } else {
         $template_processor->display("import_geographic_data_form.tpl");
     }
 }
コード例 #3
0
ファイル: import_listings.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $tp = SJB_System::getTemplateProcessor();
     $file_info = isset($_FILES['import_file']) ? $_FILES['import_file'] : null;
     $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8');
     $listingTypeID = SJB_Request::getVar('listing_type_id', null);
     $productSID = SJB_Request::getVar('product_sid', 0);
     $errors = array();
     if ($listingTypeID && $productSID) {
         $acl = SJB_Acl::getInstance();
         $resource = 'post_' . strtolower($listingTypeID);
         if (!$acl->isAllowed($resource, $productSID, 'product')) {
             $errors[] = 'You cannot import listings of this type under the selected product';
         }
     }
     if (!empty($file_info)) {
         $extension = SJB_Request::getVar('file_type');
         if (!SJB_ImportFile::isValidFileExtensionByFormat($extension, $file_info)) {
             $errors['DO_NOT_MATCH_SELECTED_FILE_FORMAT'] = true;
         }
     }
     if (empty($file_info) || $file_info['error'] || $errors) {
         if (isset($file_info['error']) && $file_info['error'] > 0) {
             $errors[SJB_UploadFileManager::getErrorId($file_info['error'])] = 1;
         }
         $listing_types = SJB_ListingTypeManager::getAllListingTypesInfo();
         $products = SJB_ProductsManager::getProductsByProductType('post_listings');
         $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
         $tp->assign('listing_types', $listing_types);
         $tp->assign('products', $products);
         $tp->assign('errors', $errors);
         $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
         $tp->display('import_listings.tpl');
     } else {
         $i18n = SJB_I18N::getInstance();
         $csv_delimiter = SJB_Request::getVar('csv_delimiter', null);
         $activeStatus = SJB_Request::getVar('active', 0);
         $activationDate = SJB_Request::getVar('activation_date', date('Y-m-d'));
         $activationDate = $i18n->getInput('date', $activationDate);
         $non_existed_values_flag = SJB_Request::getVar('non_existed_values', null);
         $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
         if (empty($productInfo['listing_duration'])) {
             $expirationDate = '';
         } else {
             $timestamp = strtotime($activationDate . ' + ' . $productInfo['listing_duration'] . ' days');
             $expirationDate = $i18n->getDate(date('Y-m-d', $timestamp));
         }
         $extension = $_REQUEST['file_type'];
         if ($extension == 'xls') {
             $import_file = new SJB_ImportFileXLS($file_info);
         } elseif ($extension == 'csv') {
             $import_file = new SJB_ImportFileCSV($file_info, $csv_delimiter);
         }
         $import_file->parse($encodingFromCharset);
         $listing = $this->CreateListing(array(), $listingTypeID);
         $imported_data = $import_file->getData();
         $isFileImported = true;
         $count = 0;
         $addedListingsSids = array();
         $nonExistentUsers = array();
         foreach ($imported_data as $key => $importedColumn) {
             if ($key == 1) {
                 $imported_data_processor = new SJB_ImportedDataProcessor($importedColumn, $listing);
                 continue;
             }
             if (!$importedColumn) {
                 continue;
             }
             $count++;
             $listingInfo = $imported_data_processor->getData($non_existed_values_flag, $importedColumn);
             $doc = new DOMDocument();
             foreach ($listing->getProperties() as $property) {
                 if ($property->getType() == 'complex' && !empty($listingInfo[$property->id])) {
                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                     $doc->loadXML($listingInfo[$property->id]);
                     $results = $doc->getElementsByTagName($property->id . 's');
                     $listingInfo[$property->id] = array();
                     foreach ($results as $complexparent) {
                         $i = 1;
                         foreach ($complexparent->getElementsByTagName($property->id) as $result) {
                             $resultXML = simplexml_import_dom($result);
                             foreach ($childFields as $childField) {
                                 if (isset($resultXML->{$childField}['id'])) {
                                     $listingInfo[$property->id][$childField['id']][$i] = XML_Util::reverseEntities((string) $resultXML->{$childField}['id']);
                                 }
                             }
                             $i++;
                         }
                     }
                 } elseif ($property->getType() == 'monetary' && !empty($listingInfo[$property->id])) {
                     $value = $listingInfo[$property->id];
                     $listingInfo[$property->id] = array();
                     $listingInfo[$property->id]['value'] = $value;
                     $defaultCurrency = SJB_CurrencyManager::getDefaultCurrency();
                     $currencyCode = !empty($listingInfo[$property->id . "Currency"]) ? $listingInfo[$property->id . "Currency"] : $defaultCurrency['currency_code'];
                     $currency = SJB_CurrencyManager::getCurrencyByCurrCode($currencyCode);
                     $listingInfo[$property->id]['add_parameter'] = !empty($currency['sid']) ? $currency['sid'] : '';
                     if (isset($listingInfo[$property->id . "Currency"])) {
                         unset($listingInfo[$property->id . "Currency"]);
                     }
                 } elseif ($property->getType() == 'location') {
                     $locationFields = array($property->id . '.Country', $property->id . '.State', $property->id . '.City', $property->id . '.ZipCode');
                     $locationFieldAdded = array();
                     foreach ($locationFields as $locationField) {
                         if (array_key_exists($locationField, $listingInfo)) {
                             switch ($locationField) {
                                 case $property->id . '.Country':
                                     $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]);
                                     if (!$value) {
                                         $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]);
                                     }
                                     break;
                                 case $property->id . '.State':
                                     $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]);
                                     if (!$value) {
                                         $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]);
                                     }
                                     break;
                                 default:
                                     $value = $listingInfo[$locationField];
                                     break;
                             }
                             $listingInfo[$property->id][str_replace($property->id . '.', '', $locationField)] = $value;
                             $locationFieldAdded[] = str_replace($property->id . '.', '', $locationField);
                         }
                     }
                     if ($property->id == 'Location') {
                         $locationFields = array('Country', 'State', 'City', 'ZipCode');
                         foreach ($locationFields as $locationField) {
                             if (array_key_exists($locationField, $listingInfo) && !in_array($locationField, $locationFieldAdded) && !$listing->getProperty($locationField)) {
                                 switch ($locationField) {
                                     case 'Country':
                                         $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]);
                                         if (!$value) {
                                             $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]);
                                         }
                                         break;
                                     case 'State':
                                         $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]);
                                         if (!$value) {
                                             $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]);
                                         }
                                         break;
                                     default:
                                         $value = $listingInfo[$locationField];
                                         break;
                                 }
                                 $listingInfo[$property->id][$locationField] = $value;
                             }
                         }
                     }
                 }
             }
             $listing = $this->CreateListing($listingInfo, $listingTypeID);
             $pictures = array();
             if (isset($listingInfo['pictures'])) {
                 $listing->addPicturesProperty();
                 $explodedPictures = explode(';', $listingInfo['pictures']);
                 foreach ($explodedPictures as $picture) {
                     if (!empty($picture)) {
                         $pictures[] = $picture;
                     }
                 }
                 $listing->setPropertyValue('pictures', count($pictures));
             }
             $listing->addActiveProperty($activeStatus);
             $listing->addActivationDateProperty($activationDate);
             $listing->addExpirationDateProperty($expirationDate);
             SJB_ListingDBManager::setListingExpirationDateBySid($listing->sid);
             $listing->setProductInfo(SJB_ProductsManager::getProductExtraInfoBySID($productSID));
             $listing->setPropertyValue('access_type', 'everyone');
             $listing->setPropertyValue('status', 'approved');
             foreach ($listing->getProperties() as $property) {
                 if ($property->getType() == 'tree' && $property->value !== '') {
                     try {
                         $treeImportHelper = new SJB_FieldTreeImportHelper($property->value);
                         $treeValues = $treeImportHelper->parseAndGetValues();
                         $listing->setPropertyValue($property->id, $treeValues);
                         $listing->details->properties[$property->id]->type->property_info['value'] = $treeValues;
                     } catch (Exception $e) {
                         $listing->setPropertyValue($property->id, '');
                         $listing->details->properties[$property->id]->type->property_info['value'] = '';
                         SJB_Error::writeToLog('Listing Import. Tree Field Value Error: ' . $e->getMessage());
                     }
                 } elseif ($property->id == 'ApplicationSettings' && !empty($listingInfo['ApplicationSettings'])) {
                     if (preg_match("^[a-z0-9\\._-]+@[a-z0-9\\._-]+\\.[a-z]{2,}\$^iu", $listingInfo['ApplicationSettings'])) {
                         $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 1);
                     } elseif (preg_match("^(https?:\\/\\/)^", $listingInfo['ApplicationSettings'])) {
                         $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 2);
                     } else {
                         $listingInfo['ApplicationSettings'] = array('value' => '', 'add_parameter' => '');
                     }
                     //put empty if not valid email or url
                     $listing->details->properties[$property->id]->type->property_info['value'] = $listingInfo['ApplicationSettings'];
                 } elseif ($property->getType() == 'complex') {
                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                     $complexChildValues = $property->value;
                     foreach ($childFields as $childField) {
                         if ($childField['type'] == 'complexfile' && !empty($complexChildValues[$childField['id']])) {
                             $fieldInfo = SJB_ListingComplexFieldManager::getFieldInfoBySID($childField['sid']);
                             if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo, $property->id)) {
                                 $isFileImported = false;
                             }
                         }
                         if ($property->type->complex->details->properties[$childField['id']]->value == null) {
                             $property->type->complex->details->properties[$childField['id']]->value = array(1 => '');
                             $property->type->complex->details->properties[$childField['id']]->type->property_info['value'] = array(1 => '');
                         }
                     }
                 }
                 // The import of files at import of listings
                 if (in_array($property->getType(), array('file', 'logo', 'video')) && $property->value !== '') {
                     $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($property->id);
                     if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo)) {
                         $isFileImported = false;
                     }
                 }
             }
             if ($non_existed_values_flag == 'add') {
                 $this->UpdateListValues($listing);
             }
             if ($listing->getUserSID()) {
                 SJB_ListingManager::saveListing($listing);
                 $listingSid = $listing->getSID();
                 SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listingSid);
                 SJB_ListingManager::activateListingBySID($listingSid, false);
                 if (!$this->fillGallery($listingSid, $pictures)) {
                     $isFileImported = false;
                 }
                 $addedListingsSids[] = $listingSid;
             } else {
                 $nonExistentUsers[] = $listingInfo['username'];
                 $count--;
             }
         }
         SJB_BrowseDBManager::addListings($addedListingsSids);
         SJB_ProductsManager::incrementPostingsNumber($productSID, count($addedListingsSids));
         if ($isFileImported && file_exists(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY'))) {
             SJB_Filesystem::delete(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY'));
         }
         $tp->assign('imported_listings_count', $count);
         $tp->assign('nonExistentUsers', $nonExistentUsers);
         $tp->display('import_listings_result.tpl');
     }
 }
コード例 #4
0
ファイル: import_users.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $template_processor = SJB_System::getTemplateProcessor();
     $errors = array();
     $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8');
     $file_info = isset($_FILES['import_file']) ? $_FILES['import_file'] : null;
     if (!empty($file_info)) {
         $extension = $_REQUEST['file_type'];
         if (!SJB_ImportFile::isValidFileExtensionByFormat($extension, $file_info)) {
             $errors['DO_NOT_MATCH_SELECTED_FILE_FORMAT'] = true;
         }
     }
     if (empty($file_info) || $file_info['error'] || !empty($errors)) {
         if (isset($file_info['error']) && $file_info['error'] > 0) {
             $errors[SJB_UploadFileManager::getErrorId($file_info['error'])] = 1;
         }
         $user_groups = SJB_UserGroupManager::getAllUserGroupsInfo();
         $template_processor->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
         $template_processor->assign('user_groups', $user_groups);
         $template_processor->assign('errors', $errors);
         $template_processor->assign('charSets', SJB_HelperFunctions::getCharSets());
         $template_processor->display('import_users.tpl');
     } else {
         $csv_delimiter = SJB_Request::getVar('csv_delimiter', null);
         $user_group_id = SJB_Request::getVar('user_group_id', null);
         $user_group_sid = SJB_UserGroupManager::getUserGroupSIDByID($user_group_id);
         if ($extension == 'xls') {
             $import_file = new SJB_ImportFileXLS($file_info);
         } elseif ($extension == 'csv') {
             $import_file = new SJB_ImportFileCSV($file_info, $csv_delimiter);
         }
         $import_file->parse($encodingFromCharset);
         $user = $this->CreateUser(array(), $user_group_id);
         $imported_data = $import_file->getData();
         $count = 0;
         $import_file_url = false;
         $usersID = array();
         foreach ($imported_data as $key => $importedColumn) {
             if ($key == 1) {
                 $imported_user_processor = new SJB_ImportedUserProcessor($importedColumn, $user);
                 continue;
             }
             if (!$importedColumn) {
                 continue;
             }
             $userInfo = $imported_user_processor->getData($importedColumn);
             $extUserID = isset($userInfo['extUserID']) ? $userInfo['extUserID'] : '';
             $user = $this->CreateUser(array(), $user_group_id);
             $user->addExtUserIDProperty();
             $doc = new DOMDocument();
             foreach ($user->getProperties() as $property) {
                 if ($property->id == 'active') {
                     $property->type->property_info['value'] = $property->value;
                 } elseif ($property->getType() == 'location') {
                     $locationFields = array($property->id . '.Country', $property->id . '.State', $property->id . '.City', $property->id . '.ZipCode', $property->id . '.Address');
                     $locationFieldAdded = array();
                     foreach ($locationFields as $locationField) {
                         if (array_key_exists($locationField, $userInfo)) {
                             switch ($locationField) {
                                 case $property->id . '.Country':
                                     $value = SJB_CountriesManager::getCountrySIDByCountryName($userInfo[$locationField]);
                                     if (!$value) {
                                         $value = SJB_CountriesManager::getCountrySIDByCountryCode($userInfo[$locationField]);
                                     }
                                     break;
                                 case $property->id . '.State':
                                     $value = SJB_StatesManager::getStateSIDByStateName($userInfo[$locationField]);
                                     if (!$value) {
                                         $value = SJB_StatesManager::getStateSIDByStateCode($userInfo[$locationField]);
                                     }
                                     break;
                                 default:
                                     $value = $userInfo[$locationField];
                                     break;
                             }
                             unset($userInfo[$locationField]);
                             $userInfo[$property->id][str_replace($property->id . '.', '', $locationField)] = $value;
                             $locationFieldAdded[] = str_replace($property->id . '.', '', $locationField);
                         }
                     }
                     if ($property->id == 'Location') {
                         $locationFields = array('Country', 'State', 'City', 'ZipCode', 'Address');
                         foreach ($locationFields as $locationField) {
                             if (array_key_exists($locationField, $userInfo) && !in_array($locationField, $locationFieldAdded) && !$user->getProperty($locationField)) {
                                 switch ($locationField) {
                                     case 'Country':
                                         $value = SJB_CountriesManager::getCountrySIDByCountryName($userInfo[$locationField]);
                                         if (!$value) {
                                             $value = SJB_CountriesManager::getCountrySIDByCountryCode($userInfo[$locationField]);
                                         }
                                         break;
                                     case 'State':
                                         $value = SJB_StatesManager::getStateSIDByStateName($userInfo[$locationField]);
                                         if (!$value) {
                                             $value = SJB_StatesManager::getStateSIDByStateCode($userInfo[$locationField]);
                                         }
                                         break;
                                     default:
                                         $value = $userInfo[$locationField];
                                         break;
                                 }
                                 $userInfo[$property->id][$locationField] = $value;
                                 unset($userInfo[$locationField]);
                             }
                         }
                     }
                 }
             }
             $user = $this->CreateUser($userInfo, $user_group_id);
             $user->addExtUserIDProperty($extUserID);
             $username = SJB_Array::get($userInfo, 'username');
             if (empty($username)) {
                 $errors[] = 'Empty username is not allowed, record ignored.';
             } elseif (!is_null(SJB_UserManager::getUserSIDbyUsername($username))) {
                 $errors[] = '\'' . $userInfo['username'] . '\' - this user name already exists, record ignored.';
             } else {
                 $originalMd5Password = $user->getPropertyValue('password');
                 SJB_UserManager::saveUser($user);
                 $this->extraProperties($user, $userInfo, $usersID);
                 if (!empty($originalMd5Password)) {
                     SJB_UserManager::saveUserPassword($user->getSID(), $originalMd5Password);
                 }
                 $isApproveByAdmin = SJB_UserGroupManager::isApproveByAdmin($user_group_sid);
                 if ($isApproveByAdmin) {
                     SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending');
                 }
                 $count++;
             }
         }
         if ($import_file_url) {
             SJB_Filesystem::delete(SJB_System::getSystemSettings("IMPORT_FILES_DIRECTORY"));
         }
         $template_processor->assign('imported_users_count', $count);
         $template_processor->assign('errors', $errors);
         $template_processor->display('import_users_result.tpl');
     }
 }
コード例 #5
0
ファイル: import_tree_data.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $template_processor = SJB_System::getTemplateProcessor();
     $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8');
     $file_info = SJB_Array::get($_FILES, 'imported_tree_file');
     $field_sid = isset($_REQUEST['field_sid']) ? $_REQUEST['field_sid'] : null;
     $field_info = SJB_ListingFieldManager::getFieldInfoBySID($field_sid);
     $template_processor->assign("field", $field_info);
     $template_processor->assign("field_sid", $field_sid);
     $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($field_info['listing_type_sid']);
     $template_processor->assign("type_info", $listing_type_info);
     $template_processor->assign('charSets', SJB_HelperFunctions::getCharSets());
     if (!strcasecmp("tree", $field_info['type'])) {
         if (empty($_FILES['imported_tree_file']['name'])) {
             $errors['File'] = 'EMPTY_VALUE';
         }
         if (isset($_FILES['imported_tree_file']['error']) && $_FILES['imported_tree_file']['error']) {
             $errors[] = SJB_UploadFileManager::getErrorId($_FILES['imported_tree_file']['error']);
         }
         $start_line = SJB_Request::getVar('start_line', null);
         if (empty($start_line)) {
             $errors['Start Line'] = 'EMPTY_VALUE';
         } elseif (!is_numeric($start_line) || !is_int($start_line + 0)) {
             $errors['Start Line'] = 'NOT_INT_VALUE';
         }
         $form_submitted = $_SERVER['REQUEST_METHOD'] == 'POST';
         if ($form_submitted) {
             if (!SJB_ImportFile::isValidFileExtensionByFormat($_REQUEST['file_format'], $_FILES['imported_tree_file'])) {
                 $errors['File'] = 'DO_NOT_MATCH_SELECTED_FILE_FORMAT';
             }
         }
         $is_data_valid = empty($errors);
         if ($form_submitted && $is_data_valid) {
             if (!strcasecmp($_REQUEST['file_format'], 'excel')) {
                 $import_file = new SJB_ImportFileXLS($file_info);
             } else {
                 $import_file = new SJB_ImportFileCSV($file_info, ',');
             }
             $import_file->parse($encodingFromCharset);
             $imported_data = $import_file->getData();
             $count = 0;
             foreach ($imported_data as $key => $importedColumn) {
                 if (!$importedColumn || $start_line > $key) {
                     continue;
                 }
                 if (SJB_ListingFieldTreeManager::importTreeItem($field_sid, $importedColumn)) {
                     $count++;
                 }
             }
             $template_processor->assign("count", $count);
             $template_processor->display("import_tree_data_statistics.tpl");
         } else {
             if (!$form_submitted) {
                 $errors = null;
             }
             $template_processor->assign("errors", isset($errors) ? $errors : null);
             $template_processor->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
             $template_processor->display("import_tree_data.tpl");
         }
     } else {
         echo 'invalid Tree SID is specified';
     }
 }