Esempio n. 1
0
 public function execute()
 {
     $cachePath = SJB_BASE_DIR . "system/cache/markers";
     if (SJB_Request::isAjax()) {
         $fileSystem = new SJB_Filesystem();
         $markers = $fileSystem->getFileNames($cachePath);
         $response = count($markers) ? json_encode($markers) : '';
         exit($response);
     }
     $grayImage = SJB_BASE_DIR . "templates/_system/main/images/marker_gray.gif";
     $greenImage = SJB_BASE_DIR . "templates/_system/main/images/marker_green.gif";
     $orangeImage = SJB_BASE_DIR . "templates/_system/main/images/marker_orange.gif";
     $blueImage = SJB_BASE_DIR . "templates/_system/main/images/marker_blue.gif";
     $pinkImage = SJB_BASE_DIR . "templates/_system/main/images/marker_pink.gif";
     $type = SJB_Request::getVar('type', 'Job');
     $text = SJB_Request::getVar('text', '');
     $filename = '';
     $assets = array('Job' => $orangeImage, 'priority' => $orangeImage, 'indeed' => $blueImage, 'simplyHired' => $greenImage, 'beyond' => $grayImage, 'Resume' => $orangeImage);
     if (array_key_exists($type, $assets)) {
         $filename = $assets[$type];
     } else {
         $filename = $grayImage;
     }
     $cacheFilename = $cachePath . "/marker_" . $type . '_' . $text . ".gif";
     $img = null;
     if (!file_exists($cacheFilename)) {
         if ($filename == $pinkImage || !empty($text) && is_string($text) && !empty($filename)) {
             $img = imagecreatefromgif($filename);
             $imageSx = imagesx($img);
             $imageSy = imagesy($img);
             $fontSize = 8;
             $textLen = strlen($text);
             $black = imageColorAllocate($img, 0, 0, 0);
             $white = imageColorAllocate($img, 255, 255, 255);
             if (!empty($text)) {
                 imagettftext($img, $fontSize, 0, $imageSx / 2 - floor($fontSize / 2 * $textLen) + 2, 13, $black, SJB_BASE_DIR . "templates/_system/main/images/arial.ttf", $text);
             }
             if (!file_exists($cachePath)) {
                 mkdir($cachePath, 0777);
             }
             imagegif($img, $cachePath . "/marker_" . $type . '_' . $text . ".gif");
         }
     } else {
         $img = imagecreatefromgif($cacheFilename);
     }
     if (!is_null($img)) {
         header("Content-type: image/gif");
         imagegif($img);
     }
     exit;
 }
Esempio n. 2
0
 /**
  * retrieve langs files paths (languages, pages)
  * @param $language_id
  * @return array
  */
 function getFilePathToLangFiles($language_id)
 {
     $path = $this->context->getPathToLanguageFiles();
     $file_name = sprintf($this->context->getFileNameTemplateForLanguageFile(), $language_id);
     $file_path = array();
     $file_path['languages'] = $this->fileSystem->pathCombine($path, $file_name);
     $file_path['pages'] = $this->getFilePathToLangPagesFile($language_id);
     return $file_path;
 }
Esempio n. 3
0
 public static function archiveAndSendExportFile()
 {
     $export_files_dir = SJB_System::getSystemSettings("EXPORT_FILES_DIRECTORY");
     if (empty($export_files_dir)) {
         return;
     }
     $archive_file_path = SJB_Path::combine($export_files_dir, "users.tar.gz");
     $old_path = getcwd();
     chdir($export_files_dir);
     $tar = new Archive_Tar('users.tar.gz', 'gz');
     $tar->create("files video pictures users.xls");
     chdir($old_path);
     for ($i = 0; $i < ob_get_level(); $i++) {
         ob_end_clean();
     }
     header("Content-type: application/octet-stream");
     header("Content-disposition: attachment; filename=users.tar.gz");
     header("Content-Length: " . filesize($archive_file_path));
     readfile($archive_file_path);
     SJB_Filesystem::delete($export_files_dir);
 }
Esempio n. 4
0
 public static function archive($name = false, $listFilesAndFolders, $export_files_dir, $export_files_dir_name, $backupName, $move = false, $identifier, $type)
 {
     if (empty($export_files_dir)) {
         return;
     }
     $dir_separator = DIRECTORY_SEPARATOR;
     $backupName = 'backup' . $dir_separator . $backupName;
     $installFilePath = 'system' . $dir_separator . 'admin-scripts' . $dir_separator . 'miscellaneous' . $dir_separator;
     $dbSQLFilePath = 'backup' . $dir_separator;
     $old_path = getcwd();
     chdir($export_files_dir);
     $tar = new Archive_Tar($backupName, 'gz');
     if (SJB_System::getIfTrialModeIsOn()) {
         $tar->setIgnoreList(array('system/plugins/mobile', 'system/plugins/facebook_app', 'templates/mobile', 'templates/Facebook'));
     }
     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
     switch ($type) {
         case 'full':
             $tar->addModify("{$installFilePath}install.php", '', $installFilePath);
             $tar->addModify($dbSQLFilePath . $name, '', $dbSQLFilePath);
             $tar->addModify($listFilesAndFolders, '');
             SJB_Filesystem::delete($export_files_dir . $dbSQLFilePath . $name);
             break;
         case 'files':
             $tar->addModify("{$installFilePath}install.php", '', $installFilePath);
             $tar->addModify($listFilesAndFolders, '');
             break;
         case 'database':
             $tar->addModify($dbSQLFilePath . $listFilesAndFolders, '', $dbSQLFilePath);
             SJB_Filesystem::delete($export_files_dir . $dbSQLFilePath . $listFilesAndFolders);
             break;
     }
     chdir($old_path);
     return true;
 }
Esempio n. 5
0
 private function deleteBackupAfterExpired($backups)
 {
     $dirSeparator = DIRECTORY_SEPARATOR;
     $scriptPath = explode(SJB_System::getSystemSettings('SYSTEM_URL_BASE'), __FILE__);
     $scriptPath = array_shift($scriptPath);
     $date = date("Y-m-d H:i");
     $expiredPeriod = SJB_System::getSettingByName('backup_expired_period');
     if (!empty($expiredPeriod)) {
         foreach ($backups as $key => $value) {
             $expiredDate = date('Y-m-d H:i', strtotime($value['date'] . " + {$expiredPeriod} day"));
             if ($expiredDate <= $date) {
                 if ($value['name']) {
                     $backup = $scriptPath . 'backup' . $dirSeparator . $value['name'];
                     if (is_file($backup)) {
                         SJB_Filesystem::delete($backup);
                         if (SJB_System::getSettingByName('ftp_backup')) {
                             SJB_Autobackup::deleteFileFromFtp($value['name']);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 6
0
 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');
     }
 }
Esempio n. 7
0
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $errors = array();
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', false);
     $dir_separator = DIRECTORY_SEPARATOR;
     $script_path = explode(SJB_System::getSystemSettings('SYSTEM_URL_BASE'), __FILE__);
     $script_path = array_shift($script_path);
     $identifier = SJB_Request::getVar('identifier', time());
     $filename = SJB_Request::getVar('filename', false);
     $settings = array();
     if ($filename) {
         SJB_Backup::sendArchiveFile($filename, $script_path . 'backup' . $dir_separator . $filename);
     }
     if (SJB_Request::getVar('action') == "save") {
         $expPeriod = SJB_Request::getVar('backup_expired_period');
         if (!empty($expPeriod) && (!is_numeric($expPeriod) || $expPeriod < 0)) {
             $errors[] = 'EXP_PERIOD_NOT_VALID';
         }
         $ftpValid = $this->isFTPDataValid();
         if (SJB_Request::getVar('autobackup', false) && SJB_Request::getVar('ftp_backup', false) && !$ftpValid) {
             $errors[] = 'FTP_DETAILS_NOT_VALID';
         }
         if (empty($errors)) {
             $backupSettings = $_REQUEST;
             foreach ($backupSettings as $setting => $value) {
                 if (!SJB_Settings::saveSetting($setting, $value)) {
                     $errors['SETTINGS_SAVED_WITH_PROBLEMS'] = "SETTINGS_SAVED_WITH_PROBLEMS";
                 }
             }
             if (empty($errors)) {
                 $tp->assign('successSaveMessage', true);
             }
         } else {
             $settings = $_REQUEST;
         }
     }
     switch ($action) {
         case 'backup':
             if (SJB_System::getSystemSettings('isDemo')) {
                 $i18N = SJB_I18N::getInstance();
                 $str = $i18N->gettext('Backend', 'Error: You don\'t have permissions for it. This is a Demo version of the software.');
                 SJB_Session::setValue('error', $str);
                 break;
             }
             if (SJB_System::getIfTrialModeIsOn() && $_SERVER['REMOTE_ADDR'] != "91.205.51.231") {
                 $i18N = SJB_I18N::getInstance();
                 $str = $i18N->gettext('Backend', 'Error: You don\'t have permissions for it. This is a Trial version of the software.');
                 SJB_Session::setValue('error', $str);
                 break;
             }
             SessionStorage::destroy('backup_' . $identifier);
             SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
             SJB_Session::unsetValue('restore');
             SJB_Session::unsetValue('error');
             $backup_type = SJB_Request::getVar('backup_type');
             $backupDir = $script_path . 'backup' . $dir_separator;
             try {
                 $this->prepareBackupDir($backupDir);
             } catch (Exception $e) {
                 SJB_Session::setValue('error', $e->getMessage());
                 exit;
             }
             switch ($backup_type) {
                 case 'full':
                     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
                     $backupDir = $script_path;
                     $name = 'db.sql';
                     SJB_Backup::dump($name, $script_path, $identifier);
                     $d = dir($script_path);
                     $contentDir = array();
                     $folders = array('.', '..', 'backup', '.svn', '.settings', '.cache', 'restore', $name);
                     while (false !== ($entry = $d->read())) {
                         if (!in_array($entry, $folders)) {
                             $contentDir[] = $entry;
                         }
                     }
                     $listFilesAndFolders = !empty($contentDir) ? $contentDir : false;
                     $backupName = 'full_backup_' . date('Y_m_d__H_i') . '.tar.gz';
                     $export_files_dir_name = '..' . $dir_separator;
                     if (SJB_Backup::archive($name, $listFilesAndFolders, $backupDir, $export_files_dir_name, $backupName, true, $identifier, 'full')) {
                         SessionStorage::write('backup_' . $identifier, serialize(array('name' => $backupName)));
                     }
                     exit;
                     break;
                 case 'database':
                     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
                     $name = 'db.sql';
                     $backupName = 'mysqldump_' . date('Y_m_d__H_i') . '.tar.gz';
                     $export_files_dir_name = '../backup' . $dir_separator;
                     SJB_Backup::dump($name, $script_path, $identifier);
                     if (SJB_Backup::archive(false, $name, $script_path, $export_files_dir_name, $backupName, false, $identifier, 'database')) {
                         SessionStorage::write('backup_' . $identifier, serialize(array('name' => $backupName)));
                     }
                     exit;
                     break;
                 case 'files':
                     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
                     $backupDir = $script_path;
                     $d = dir($script_path);
                     $contentDir = array();
                     $folders = array('.', '..', 'backup', '.svn', '.settings', '.cache', 'restore');
                     while (false !== ($entry = $d->read())) {
                         if (!in_array($entry, $folders)) {
                             $contentDir[] = $entry;
                         }
                     }
                     $listFilesAndFolders = !empty($contentDir) ? $contentDir : false;
                     $backupName = 'backup_' . date('Y_m_d__H_i') . '.tar.gz';
                     $export_files_dir_name = '..' . $dir_separator;
                     if (SJB_Backup::archive(false, $listFilesAndFolders, $backupDir, $export_files_dir_name, $backupName, true, $identifier, 'files')) {
                         SessionStorage::write('backup_' . $identifier, serialize(array('name' => $backupName)));
                     }
                     exit;
                     break;
             }
             break;
         case 'restore':
             if (SJB_System::getSystemSettings('isDemo')) {
                 SJB_Session::setValue('error', 'Error: You don\'t have permissions for it. This is a Demo version of the software.');
                 exit;
             }
             if (SJB_System::getIfTrialModeIsOn()) {
                 SJB_Session::setValue('error', 'Error: You don\'t have permissions for it. This is a Trial version of the software.');
                 exit;
             }
             SJB_Session::unsetValue('restore');
             SJB_Session::unsetValue('error');
             $error = false;
             $restoreDir = $script_path . 'restore' . $dir_separator;
             try {
                 $fileName = $this->moveUploadedFile($restoreDir);
                 $tar = new Archive_Tar($restoreDir . $fileName, 'gz');
                 $tar->_error_class = 'SJB_PEAR_Exception';
                 $tar->extractList('db.sql', $restoreDir);
                 $tar->extract($script_path);
                 if (is_file($restoreDir . 'db.sql')) {
                     SJB_Backup::restore_base_tables($restoreDir . 'db.sql');
                 }
                 SJB_Cache::getInstance()->clean();
             } catch (Exception $ex) {
                 $error = $ex->getMessage();
             }
             SJB_Filesystem::delete($restoreDir);
             if (is_file($script_path . 'install.php')) {
                 SJB_Filesystem::delete($script_path . 'install.php');
             }
             if ($error) {
                 SJB_Session::setValue('error', $error);
             } else {
                 SJB_Session::setValue('restore', 1);
             }
             exit;
             break;
         case 'send_archive':
             $name = SJB_Request::getVar('name', false);
             $archive_file_path = SJB_Path::combine(SJB_BASE_DIR . 'backup' . $dir_separator, $name);
             if ($name) {
                 SJB_Backup::sendArchiveFile($name, $archive_file_path);
             }
             break;
         case 'check':
             $sessionBackup = SessionStorage::read('backup_' . $identifier);
             $sessionBackup = $sessionBackup ? unserialize($sessionBackup) : array();
             $sessionRestore = SJB_Session::getValue('restore');
             $sessionError = SJB_Session::getValue('error');
             if (!empty($sessionBackup['name'])) {
                 $name = $sessionBackup['name'];
                 SessionStorage::destroy('backup_' . $identifier);
                 echo SJB_System::getSystemSettings('SITE_URL') . "/backup/?action=send_archive&name={$name}";
                 exit;
             } elseif (!empty($sessionRestore)) {
                 SJB_Session::unsetValue('restore');
                 echo SJB_System::getSystemSettings('SITE_URL') . '/backup/#restore';
                 exit;
             } elseif (!empty($sessionError)) {
                 echo 'Error';
                 if (SJB_System::getSystemSettings('isDemo')) {
                     echo ': You don\'t have permissions for it. This is a Demo version of the software.';
                 }
                 if (SJB_System::getIfTrialModeIsOn()) {
                     echo ': You don\'t have permissions for it. This is a Trial version of the software.';
                 }
                 exit;
             } elseif (!empty($sessionBackup['last_time'])) {
                 $period = (time() - $sessionBackup['last_time']) / 60;
                 if ($period < 5) {
                     echo 1;
                 } else {
                     SJB_Session::setValue('error', 'The backup generation process was unexpectedly interrupted. Please try again.');
                     echo 'error';
                 }
                 exit;
             } else {
                 echo 1;
             }
             exit;
             break;
         case 'delete_backup':
             $name = SJB_Request::getVar('name', false);
             if ($name) {
                 $backup = $script_path . 'backup' . $dir_separator . $name;
                 if (is_file($backup)) {
                     SJB_Filesystem::delete($backup);
                     SJB_Autobackup::deleteFileFromFtp($name);
                 } else {
                     $errors['FILE_NOT_FOUND'] = 1;
                 }
             }
             $tp->assign('errors', $errors);
             $tp->assign('delBackup', 1);
         case 'created_backups':
             $path = $script_path . 'backup' . $dir_separator;
             if (is_dir($path)) {
                 $di = new DirectoryIterator($path);
                 $backupsArr = array();
                 foreach ($di as $file) {
                     $fileName = $file->getFilename();
                     if (!$file->isDir() && !$file->isLink() && $fileName != '.htaccess') {
                         $cTime = $file->getCTime();
                         $backupsArr[$cTime]['name'] = $fileName;
                         if (preg_match('/mysqldump/', $fileName)) {
                             $backupsArr[$cTime]['type'] = 'Site database only';
                         } elseif (preg_match('/full_backup/', $fileName)) {
                             $backupsArr[$cTime]['type'] = 'Full site backup';
                         } elseif (preg_match('/backup/', $fileName)) {
                             $backupsArr[$cTime]['type'] = 'Site files only';
                         } else {
                             $backupsArr[$cTime]['type'] = 'Unknown';
                         }
                         $pattern = '/(\\w+)_(\\d+)_(\\d+)_(\\d+)__(\\d+)_(\\d+).tar.gz/i';
                         $replacement = '$2-$3-$4 $5:$6';
                         $backupsArr[$cTime]['date'] = preg_replace($pattern, $replacement, $fileName);
                     }
                 }
                 krsort($backupsArr);
                 $tp->assign('created_backups', $backupsArr);
             }
             $tp->display('created_backups.tpl');
             exit;
             break;
         case 'error':
             $sessionError = SJB_Session::getValue('error');
             if (!is_null($sessionError)) {
                 echo '<p class="error">' . $sessionError . '</p>';
                 exit;
             }
             break;
     }
     if (empty($settings)) {
         $settings = SJB_Settings::getSettings();
     }
     $tp->assign('errors', $errors);
     $tp->assign('settings', $settings);
     $tp->assign('identifier', $identifier);
     $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
     $tp->display('backup.tpl');
 }
Esempio n. 8
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listing_type_id = SJB_Request::getVar('listing_type_id', false);
     $action = SJB_Request::getVar('action', false);
     $type = SJB_Request::getVar('type', false);
     $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8');
     $supportedFormats = array('xlsx', 'xls', 'csv');
     $warning = false;
     $error = '';
     if ($action == 'example' && $type) {
         $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
         $listing_field_manager = new SJB_ListingFieldManager();
         $common_details = $listing_field_manager->getCommonListingFieldsInfo();
         $extra_details = $listing_field_manager->getListingFieldsInfoByListingType($listing_type_sid);
         $listing_fields = array_merge($common_details, $extra_details);
         $directory_to_export = SJB_System::getSystemSettings('EXPORT_FILES_DIRECTORY');
         $export_properties = array();
         $export_data = array();
         foreach ($listing_fields as $listing_field) {
             $export_properties[$listing_field['id']] = $listing_field['id'];
             $export_data[0][$listing_field['id']] = '';
         }
         SJB_ExportController::createExportDirectoriesForExample();
         switch ($type) {
             case 'exl':
                 SJB_ExportController::makeExportFile($export_data, 'example.xls');
                 $export_files_dir = SJB_Path::combine($directory_to_export, 'example.xls');
                 for ($i = 0; $i < ob_get_level(); $i++) {
                     ob_end_clean();
                 }
                 header('Content-type: application/vnd.ms-excel');
                 header('Content-disposition: attachment; filename=example.xls');
                 header('Content-Length: ' . filesize($export_files_dir));
                 readfile($export_files_dir);
                 break;
             case 'csv':
                 $export_files_dir = SJB_Path::combine($directory_to_export, 'example.csv');
                 $fp = fopen($export_files_dir, 'w');
                 fputcsv($fp, explode(',', implode(',', $export_properties)));
                 fclose($fp);
                 for ($i = 0; $i < ob_get_level(); $i++) {
                     ob_end_clean();
                 }
                 header('Content-type: application/vnd.ms-excel');
                 header('Content-disposition: attachment; filename=example.csv');
                 header('Content-Length: ' . filesize($export_files_dir));
                 readfile($export_files_dir);
                 break;
         }
         SJB_Filesystem::delete($directory_to_export);
         exit;
     }
     if ($productsInfo = $this->canCurrentUserAddListing($error)) {
         $acl = SJB_Acl::getInstance();
         if ($acl->isAllowed('bulk_job_import') == true) {
             $fileInfo = null;
             if (isset($_FILES['import_file'])) {
                 $extension = strtolower(substr(strrchr($_FILES['import_file']['name'], '.'), 1));
                 if (empty($_FILES['import_file']['name']) || !in_array($extension, $supportedFormats)) {
                     $warning = 'Please choose Excel or csv file';
                 } else {
                     $fileInfo = $_FILES['import_file'];
                 }
             }
             $contractID = SJB_Request::getVar('contract_id', false);
             $current_user = SJB_UserManager::getCurrentUser();
             if ($contractID) {
                 $contract = new SJB_Contract(array('contract_id' => $contractID));
             } elseif (count($productsInfo) == 1) {
                 $productInfo = array_pop($productsInfo);
                 $contractID = $productInfo['contract_id'];
                 $contract = new SJB_Contract(array('contract_id' => $contractID));
             } else {
                 $tp->assign("products_info", $productsInfo);
                 $tp->assign("listing_type_id", $listing_type_id);
                 $tp->display("listing_product_choice.tpl");
             }
             if ($contractID && $listing_type_id) {
                 $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
                 if ($fileInfo) {
                     switch ($extension) {
                         case 'xls':
                         case 'xlsx':
                             $import_file = new SJB_ImportFileXLS($fileInfo);
                             break;
                         case 'csv':
                             $import_file = new SJB_ImportFileCSV($fileInfo, ',');
                             break;
                     }
                     $import_file->parse($encodingFromCharset);
                     $bulkPermissionParam = $this->acl->getPermissionParams('post_' . $listing_type_id, $contract->getID(), 'contract');
                     $imported_data = $import_file->getData();
                     $countData = 0;
                     foreach ($imported_data as $val) {
                         if ($val) {
                             $countData++;
                         }
                     }
                     if (empty($bulkPermissionParam) || $bulkPermissionParam - $contract->getPostingsNumber() - ($countData - 1) >= 0) {
                         $listing = new SJB_Listing(array(), $listing_type_sid);
                         $count = 0;
                         $listingSIDs = array();
                         foreach ($imported_data as $key => $importedColumn) {
                             if ($key == 1) {
                                 $imported_data_processor = new SJB_ImportedDataProcessor($importedColumn, $listing);
                                 continue;
                             }
                             if (!$importedColumn) {
                                 continue;
                             }
                             $count++;
                             $listing_info = $imported_data_processor->getData('ignore', $importedColumn);
                             $doc = new DOMDocument();
                             foreach ($listing->getProperties() as $property) {
                                 if ($property->getType() == 'complex' && !empty($listing_info[$property->id])) {
                                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                                     $doc->loadXML($listing_info[$property->id]);
                                     $results = $doc->getElementsByTagName($property->id . 's');
                                     $listing_info[$property->id] = array();
                                     foreach ($results as $complexparent) {
                                         $i = 0;
                                         foreach ($complexparent->getElementsByTagName($property->id) as $result) {
                                             $resultXML = simplexml_import_dom($result);
                                             foreach ($childFields as $childField) {
                                                 if (isset($resultXML->{$childField}['id'])) {
                                                     $listing_info[$property->id][$childField['id']][$i] = (string) $resultXML->{$childField}['id'];
                                                 }
                                             }
                                             $i++;
                                         }
                                     }
                                 } 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, $listing_info)) {
                                             switch ($locationField) {
                                                 case $property->id . '.Country':
                                                     $value = SJB_CountriesManager::getCountrySIDByCountryName($listing_info[$locationField]);
                                                     if (!$value) {
                                                         $value = SJB_CountriesManager::getCountrySIDByCountryCode($listing_info[$locationField]);
                                                     }
                                                     break;
                                                 case $property->id . '.State':
                                                     $value = SJB_StatesManager::getStateSIDByStateName($listing_info[$locationField]);
                                                     if (!$value) {
                                                         $value = SJB_StatesManager::getStateSIDByStateCode($listing_info[$locationField]);
                                                     }
                                                     break;
                                                 default:
                                                     $value = $listing_info[$locationField];
                                                     break;
                                             }
                                             $listing_info[$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, $listing_info) && !in_array($locationField, $locationFieldAdded) && !$listing->getProperty($locationField)) {
                                                 switch ($locationField) {
                                                     case 'Country':
                                                         $value = SJB_CountriesManager::getCountrySIDByCountryName($listing_info[$locationField]);
                                                         if (!$value) {
                                                             $value = SJB_CountriesManager::getCountrySIDByCountryCode($listing_info[$locationField]);
                                                         }
                                                         break;
                                                     case 'State':
                                                         $value = SJB_StatesManager::getStateSIDByStateName($listing_info[$locationField]);
                                                         if (!$value) {
                                                             $value = SJB_StatesManager::getStateSIDByStateCode($listing_info[$locationField]);
                                                         }
                                                         break;
                                                     default:
                                                         $value = $listing_info[$locationField];
                                                         break;
                                                 }
                                                 $listing_info[$property->id][$locationField] = $value;
                                             }
                                         }
                                     }
                                 }
                             }
                             $field_info = null;
                             $listing = new SJB_Listing($listing_info, $listing_type_sid);
                             foreach ($listing->getProperties() as $property) {
                                 if ($property->getType() == 'tree' && $property->value !== '') {
                                     $treeValues = explode(',', $property->value);
                                     $treeSIDs = array();
                                     foreach ($treeValues as $treeValue) {
                                         $info = SJB_ListingFieldTreeManager::getItemInfoByCaption($property->sid, trim($treeValue));
                                         $treeSIDs[] = $info['sid'];
                                     }
                                     $listing->setPropertyValue($property->id, implode(',', $treeSIDs));
                                     $listing->details->properties[$property->id]->type->property_info['value'] = implode(',', $treeSIDs);
                                 } elseif ($property->getType() == 'monetary') {
                                     $currency = SJB_CurrencyManager::getDefaultCurrency();
                                     $listing->details->properties[$property->id]->type->property_info['value']['add_parameter'] = $currency['sid'];
                                 } elseif ($property->id == 'ApplicationSettings' && !empty($listing_info['ApplicationSettings'])) {
                                     if (preg_match("^[a-z0-9\\._-]+@[a-z0-9\\._-]+\\.[a-z]{2,}\$^iu", $listing_info['ApplicationSettings'])) {
                                         $listing_info['ApplicationSettings'] = array('value' => $listing_info['ApplicationSettings'], 'add_parameter' => 1);
                                     } elseif (preg_match("^(https?:\\/\\/)^iu", $listing_info['ApplicationSettings'])) {
                                         $listing_info['ApplicationSettings'] = array('value' => $listing_info['ApplicationSettings'], 'add_parameter' => 2);
                                     } else {
                                         $listing_info['ApplicationSettings'] = array('value' => '', 'add_parameter' => '');
                                     }
                                     $listing->details->properties[$property->id]->type->property_info['value'] = $listing_info['ApplicationSettings'];
                                 } elseif ($property->getType() == 'complex' && is_array($property->value)) {
                                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                                     $complexChildValues = $property->value;
                                     foreach ($childFields as $childField) {
                                         if ($childField['type'] == 'complexfile' && !empty($complexChildValues[$childField['id']])) {
                                             $field_info = SJB_ListingComplexFieldManager::getFieldInfoBySID($childField['sid']);
                                             if (isset($listing_info[$property->id][$field_info['id']]) && file_exists($listing_info[$property->id][$field_info['id']])) {
                                                 SJB_UploadFileManager::fileImport($listing_info, $field_info, $property->id);
                                             }
                                         }
                                     }
                                 }
                                 // The import of files at import of listings
                                 if (in_array($property->getType(), array('file', 'logo', 'picture', 'video')) && $property->value !== '') {
                                     $field_info = SJB_ListingFieldDBManager::getListingFieldInfoByID($property->id);
                                     if (isset($listing_info[$field_info['id']]) && file_exists($listing_info[$field_info['id']])) {
                                         SJB_UploadFileManager::fileImport($listing_info, $field_info);
                                     }
                                 }
                             }
                             $listing->deleteProperty('featured');
                             $listing->deleteProperty('priority');
                             $listing->deleteProperty('status');
                             $listing->deleteProperty('reject_reason');
                             $listing->addProperty(array('id' => 'contract_id', 'type' => 'id', 'value' => $contract->getID(), 'is_system' => true));
                             $extraInfo = $contract->extra_info;
                             $listing->setProductInfo($extraInfo);
                             $listing->setPropertyValue('access_type', 'everyone');
                             $listing->setUserSID($current_user->sid);
                             if ($current_user->isSubuser()) {
                                 $subuserInfo = $current_user->getSubuserInfo();
                                 $listing->addSubuserProperty($subuserInfo['sid']);
                             }
                             SJB_ListingManager::saveListing($listing);
                             SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $extraInfo['featured'], $extraInfo['priority']);
                             $contract->incrementPostingsNumber();
                             SJB_ProductsManager::incrementPostingsNumber($contract->product_sid);
                             if (!empty($extraInfo['featured'])) {
                                 SJB_ListingManager::makeFeaturedBySID($listing->getSID());
                             }
                             if (!empty($extraInfo['priority'])) {
                                 SJB_ListingManager::makePriorityBySID($listing->getSID());
                             }
                             $this->FillGallery($listing, $listing_info);
                             $listingSIDs[] = $listing->getSID();
                         }
                         SJB_ListingManager::activateListingBySID($listingSIDs);
                         $tp->assign('listingsNum', count($listingSIDs));
                         $tp->display('job_import_complete.tpl');
                     } else {
                         $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
                         $error = 'LISTINGS_NUMBER_LIMIT_EXCEEDED';
                         $tp->assign('listing_type_id', $listing_type_id);
                         $tp->assign('error', $error);
                         $tp->display('job_import.tpl');
                     }
                 } else {
                     $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
                     $tp->assign('warning', $warning);
                     $tp->assign('contract_id', $contractID);
                     $tp->assign('listing_type_id', $listing_type_id);
                     $tp->display('job_import.tpl');
                 }
             }
         } else {
             $error = $acl->getPermissionMessage('bulk_job_import');
             if (empty($error)) {
                 $error = 'This action is not allowed within your current product';
             }
             $tp->assign('error', $error);
             $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
             $tp->assign('listing_type_id', $listing_type_id);
             $tp->display('job_import.tpl');
         }
     } else {
         if ($error == 'NO_CONTRACT') {
             if ($_GET) {
                 $getParam = '?';
                 foreach ($_GET as $key => $val) {
                     $getParam .= $key . '=' . $val . '&';
                 }
                 $getParam = substr($getParam, 0, -1);
             }
             $page = base64_encode(SJB_System::getURI() . $getParam);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-products/?page=' . $page);
         }
         $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
         $tp->assign('listing_type_id', $listing_type_id);
         $tp->assign('error', $error);
         $tp->display('job_import.tpl');
     }
 }
Esempio n. 9
0
 public static function getFiles($dir, $filter = ".", $recursive = true, $exclude = array(".svn", "CVS", ".", ".."))
 {
     $files = array();
     if (is_dir($dir)) {
         $dh = opendir($dir);
         if ($dh !== false) {
             while (($dirItem = readdir($dh)) !== false) {
                 $file = $dir . DS . $dirItem;
                 if (is_dir($file)) {
                     if ($recursive && !in_array($dirItem, $exclude)) {
                         $files = array_merge($files, SJB_Filesystem::getFiles($file, $filter, $recursive, $exclude));
                     }
                 } else {
                     if (preg_match("/{$filter}/", $dirItem) === 1) {
                         $files[] = $file;
                     }
                 }
             }
         } else {
             SJB_Error::add("Open directory error '{$dir}'");
         }
     } else {
         SJB_Error::add("Trying to take files from directory {$dir}");
     }
     return $files;
 }
Esempio n. 10
0
 /**
  * create template file by theme, modulename, templatename
  *
  * @param string $theme
  * @param string $module_name
  * @param string $tpl_name
  * @param array $error
  * @return boolean
  */
 function createTemplate($theme, $module_name, $tpl_name, &$error = array())
 {
     $path_to_template = SJB_TemplatePathManager::getAbsoluteTemplatePath($theme, $module_name, $tpl_name);
     if (!is_dir($path_to_template)) {
         SJB_Filesystem::mkpath(dirname($path_to_template));
     }
     if (!file_exists($path_to_template)) {
         return self::createTemplateFile($path_to_template);
     } else {
         $error[] = 'FILE_EXISTS';
     }
     return false;
 }
Esempio n. 11
0
 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');
     }
 }
Esempio n. 12
0
 public function execute()
 {
     // таблица с данными xml-feeds
     $feedsTable = 'listing_feeds';
     $action = SJB_Request::getVar('action', '');
     $feedId = SJB_Request::getVar('feedId', null);
     $feedsArray = SJB_DB::query("SELECT f.*, f.count as count_listings, l.sid as typeId, l.id as type FROM {$feedsTable} as f LEFT JOIN `listing_types` as l ON (l.sid=f.type) ORDER BY f.sid");
     $listingTypes = SJB_DB::query("SELECT * FROM `listing_types`");
     $siteURL = SJB_System::getSystemSettings('SITE_URL');
     $tmp = strrchr(SJB_System::getSystemSettings('SITE_URL'), "/");
     $siteURL = str_replace($tmp, "", $siteURL);
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('listingTypes', $listingTypes);
     // данные для создания файлов-шаблонов для feed
     $module = SJB_System::getModuleManager()->getCurrentModuleAndFunction();
     $templatePath = SJB_TemplatePathManager::getAbsoluteTemplatesPath();
     $filePath = $templatePath . "_system/" . $module[0] . "/";
     switch ($action) {
         case 'add':
             // если была отправка формы
             if (isset($_REQUEST['addFeed']) && $_REQUEST['addFeed'] != '') {
                 $feed_name = $_REQUEST['feed_name'];
                 $feed_template = $_REQUEST['feed_template'];
                 $feed_desc = $_REQUEST['feed_desc'];
                 $typeId = $_REQUEST['typeId'];
                 $count_listings = $_REQUEST['count_listings'];
                 $feed_mimetype = $_REQUEST['mime_type'];
                 // создадим шаблон для нового feed
                 $feed_template = preg_replace("/^feed_|\\.tpl\$/", "", $feed_template);
                 $feed_template = "feed_" . $feed_template . ".tpl";
                 $filePath = $filePath . $feed_template;
                 $fileSystem = new SJB_Filesystem();
                 if (!file_exists($filePath)) {
                     $fileSystem->createFile($filePath);
                 } else {
                     $errors[] = array('code' => 'FILE_ALREADY_EXISTS', 'message' => "Template '{$filePath}' already exists!");
                     $tp->assign('feed', array('name' => $feed_name, 'template' => $feed_template, 'description' => $feed_desc, 'type' => $typeId, 'count_listings' => $count_listings, 'mime_type' => $feed_mimetype));
                     $tp->assign('errors', $errors);
                     $tp->display("add_listing_feed.tpl");
                     break;
                 }
                 SJB_DB::queryExec("INSERT INTO {$feedsTable} SET `name`=?s, `template`=?s, `description`=?s, `type`=?n, `count`=?n, `mime_type`=?s", $feed_name, $feed_template, $feed_desc, $typeId, $count_listings, $feed_mimetype);
                 $site_url = SJB_System::getSystemSettings("SITE_URL");
                 SJB_HelperFunctions::redirect($site_url . "/listing-feeds/");
             }
             $tp->display("add_listing_feed.tpl");
             break;
         case 'edit':
             // если была отправка формы редактирования элемента
             if ($form_submitted = SJB_Request::getVar('submit')) {
                 $feed_name = $_REQUEST['feed_name'];
                 $feed_template = $_REQUEST['feed_template'];
                 $feed_desc = $_REQUEST['feed_desc'];
                 $feedId = $_REQUEST['feedId'];
                 $typeId = $_REQUEST['typeId'];
                 $count_listings = $_REQUEST['count_listings'];
                 $feed_mimetype = $_REQUEST['mime_type'];
                 SJB_DB::queryExec("UPDATE {$feedsTable} SET `name`=?s, `template`=?s, `description`=?s, `type`=?n, `count`=?n, `mime_type`=?s WHERE `sid`=?n LIMIT 1", $feed_name, $feed_template, $feed_desc, $typeId, $count_listings, $feed_mimetype, $feedId);
                 $site_url = SJB_System::getSystemSettings("SITE_URL");
                 if ($form_submitted == 'save_info') {
                     SJB_HelperFunctions::redirect($site_url . "/listing-feeds/");
                 }
             }
             $feed = SJB_DB::query("SELECT f.*, f.count as count_listings  FROM {$feedsTable} as f WHERE `sid`=?n", $feedId);
             $feed = array_pop($feed);
             $tp->assign("feed", $feed);
             $tp->display("edit_listing_feed.tpl");
             break;
         case 'delete':
             $feed = SJB_DB::query("SELECT f.*, f.count as count_listings FROM {$feedsTable} as f WHERE `sid`=?n", $feedId);
             $feed = array_pop($feed);
             $filePath = $filePath . $feed['template'];
             $fileSystem = new SJB_Filesystem();
             if (file_exists($filePath)) {
                 $fileSystem->deleteFile($filePath);
             } else {
                 $errors[] = array('code' => 'FILE_NOT_EXISTS', 'message' => "Template for " . $feed['name'] . ": '{$filePath}' not exists!");
             }
             SJB_DB::queryExec("DELETE FROM {$feedsTable} WHERE `sid`=?n LIMIT 1", $feedId);
             $site_url = SJB_System::getSystemSettings("SITE_URL");
             SJB_HelperFunctions::redirect($site_url . "/listing-feeds/");
             break;
     }
     if ($action == '') {
         $tp->assign('siteURL', $siteURL);
         $tp->assign('feeds', $feedsArray);
         $tp->display('listing_feeds.tpl');
     }
 }