コード例 #1
0
 public static function getListingFieldSIDByID($listing_field_id)
 {
     $listing_field_info = SJB_ListingFieldDBManager::getListingFieldInfoByID($listing_field_id);
     if (empty($listing_field_info)) {
         return null;
     }
     return $listing_field_info['sid'];
 }
コード例 #2
0
 public static function getLocationFieldsInfoById($fieldId)
 {
     $fieldInfo = null;
     $parentInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID('Location');
     $fields = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($parentInfo['sid']);
     if (!empty($fields)) {
         foreach ($fields as $field) {
             if ('Location_' . $field['id'] == $fieldId) {
                 return SJB_ListingFieldDBManager::getListingFieldInfoBySID($field['sid']);
             }
         }
     } else {
         return false;
     }
 }
コード例 #3
0
ファイル: FacebookFields.php プロジェクト: Maxlander/shixi
 public function getTreeValues($sValue, $fieldID)
 {
     $aFieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($fieldID);
     if (!$aFieldInfo) {
         return array('tree' => '');
     }
     $aTreeValues = array();
     $tok = strtok($sValue, "\n\r\t");
     while ($tok !== false) {
         array_push($aTreeValues, $tok);
         $tok = strtok("\n\r\t");
     }
     $aTreeValuesSIDs = array();
     foreach ($aTreeValues as $treeCaption) {
         $aTreeItemInfo = SJB_ListingFieldTreeManager::getItemInfoByCaption($aFieldInfo['sid'], $treeCaption);
         if ($aTreeItemInfo['sid'] > 0) {
             array_push($aTreeValuesSIDs, $aTreeItemInfo['sid']);
         }
     }
     if (!empty($aTreeValuesSIDs)) {
         return array('tree' => implode(',', $aTreeValuesSIDs));
     }
     return array('tree' => '');
 }
コード例 #4
0
ファイル: ListingManager.php プロジェクト: Maxlander/shixi
 public static function getPropertyByPropertyName($property_name, $listing_type_sid = 0)
 {
     $property_info = SJB_ListingFieldDBManager::getListingFieldInfoByID($property_name);
     if (empty($property_info)) {
         $listing_details = SJB_ListingDetails::getDetails($listing_type_sid);
         if (isset($listing_details[$property_name])) {
             $property_info = $listing_details[$property_name];
         } else {
             return null;
         }
     }
     return new SJB_ObjectProperty($property_info);
 }
コード例 #5
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');
     }
 }
コード例 #6
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', 'search');
     $template = SJB_Request::getVar('template', 'listings_statistics.tpl');
     $errors = array();
     $userGroups = SJB_UserGroupManager::getAllUserGroupsIDsAndCaptions();
     foreach ($userGroups as $key => $userGroup) {
         unset($userGroups[$key]);
         $userGroups[$userGroup['id']] = $userGroup;
     }
     switch ($action) {
         case 'export':
             $period = SJB_Request::getVar('period', array());
             $filter = SJB_Request::getVar('filter', false);
             $listingTypeSID = SJB_Request::getVar('listingTypeSID', false);
             $listingTypeID = SJB_ListingTypeManager::getListingTypeIDBySID($listingTypeSID);
             $sorting_field = SJB_Request::getVar('sorting_field', 'total');
             $sorting_order = SJB_Request::getVar('sorting_order', 'DESC');
             $statistics = array();
             if ($filter) {
                 $statistics = SJB_Statistics::getListingsStatistics($period, $listingTypeSID, $filter, $sorting_field, $sorting_order);
                 if (!empty($statistics['errors'])) {
                     $errors = $statistics['errors'];
                 }
             } else {
                 $errors[] = 'EMPTY_PARAMETER';
             }
             $columnTitle = '';
             if (strstr($filter, 'userGroup_')) {
                 $userGroupSID = str_replace('userGroup_', '', $filter);
                 if ($userGroups[$userGroupSID]['key'] == 'Employer') {
                     $columnTitle = 'Company Name';
                 } else {
                     $columnTitle = $userGroups[$userGroupSID]['caption'] . ' Name';
                 }
             } else {
                 $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($filter);
                 $columnTitle = $fieldInfo['caption'];
             }
             if (!$errors && $statistics) {
                 $type = SJB_Request::getVar('type', 'csv');
                 $listingTypes = SJB_ListingTypeManager::getListingAllTypesForListType();
                 SJB_StatisticsExportController::createExportDirectory();
                 $exportProperties['title'] = $columnTitle;
                 $exportProperties['regular'] = '';
                 if ($listingTypeID == 'Job') {
                     $exportProperties['featured'] = '';
                 }
                 $exportProperties['priority'] = '';
                 $exportProperties['total'] = 'Total';
                 $exportProperties['percent'] = '%';
                 foreach ($listingTypes as $listingType) {
                     if ($listingType['id'] == $listingTypeSID) {
                         switch ($listingType['key']) {
                             case 'Job':
                                 $featuredTitle = "Number of Featured {$listingType['key']}s Posted";
                                 $exportProperties['featured'] = $featuredTitle;
                             case 'Resume':
                                 $regularTitle = "Number of Regular {$listingType['key']}s Posted";
                                 $exportProperties['regular'] = $regularTitle;
                                 $priorityTitle = "Number of Priority {$listingType['key']}s Posted";
                                 $exportProperties['priority'] = $priorityTitle;
                                 break;
                             default:
                                 $regularTitle = 'Number of Regular "' . $listingType['caption'] . '" Listings Posted';
                                 $exportProperties['regular'] = $regularTitle;
                                 $priorityTitle = 'Number of Priority "' . $listingType['caption'] . '" Listings Posted';
                                 $exportProperties['priority'] = $priorityTitle;
                                 break;
                         }
                     }
                 }
                 switch ($type) {
                     case 'csv':
                         $exportData = SJB_StatisticsExportController::getListingExportData($statistics, $listingTypeID);
                         $fileName = strtolower($listingTypeID) . '_statistics.csv';
                         SJB_StatisticsExportController::makeCSVExportFile($exportData, $fileName, "{$listingTypeID} Statistics");
                         SJB_StatisticsExportController::archiveAndSendExportFile(strtolower($listingTypeID) . '_statistics', 'csv');
                         break;
                     case 'xls':
                         $exportData = SJB_StatisticsExportController::getListingExportData($statistics, $listingTypeID);
                         $fileName = strtolower($listingTypeID) . '_statistics.xls';
                         SJB_StatisticsExportController::makeXLSExportFile($exportData, $fileName, "{$listingTypeID} Statistics");
                         SJB_StatisticsExportController::archiveAndSendExportFile(strtolower($listingTypeID) . '_statistics', 'xls');
                         break;
                 }
                 break;
             }
         case 'search':
             $search = SJB_Request::getVar('search', false);
             $period = SJB_Request::getVar('period', array());
             $filter = SJB_Request::getVar('filter', false);
             $listingTypeSID = SJB_Request::getVar('listingTypeSID', false);
             $sorting_field = SJB_Request::getVar('sorting_field', 'total');
             $sorting_order = SJB_Request::getVar('sorting_order', 'DESC');
             $statistics = array();
             if ($search) {
                 $i18n = SJB_I18N::getInstance();
                 $from = $i18n->getInput('date', $period['from']);
                 $to = $i18n->getInput('date', $period['to']);
                 if (!empty($period['from']) && !empty($period['to']) && strtotime($from) > strtotime($to)) {
                     $errors[] = 'SELECTED_PERIOD_IS_INCORRECT';
                 } else {
                     if ($filter) {
                         $statistics = SJB_Statistics::getListingsStatistics($period, $listingTypeSID, $filter, $sorting_field, $sorting_order);
                         if (!empty($statistics['errors'])) {
                             $errors = $statistics['errors'];
                         }
                     } else {
                         $errors[] = 'EMPTY_PARAMETER';
                     }
                 }
             }
             $columnTitle = '';
             if (strstr($filter, 'userGroup_')) {
                 $userGroupSID = str_replace('userGroup_', '', $filter);
                 if ($userGroups[$userGroupSID]['key'] == 'Employer') {
                     $columnTitle = 'Company Name';
                 } else {
                     $columnTitle = $userGroups[$userGroupSID]['caption'] . ' Name';
                 }
                 $tp->assign('link', 'user');
             } else {
                 if (in_array($filter, array('Location_Country', 'Location_State', 'Location_City'))) {
                     $fieldInfo = SJB_ListingFieldDBManager::getLocationFieldsInfoById($filter);
                 } else {
                     $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($filter);
                 }
                 $columnTitle = $fieldInfo['caption'];
             }
             $i18n = SJB_I18N::getInstance();
             $periodView = array();
             foreach ($period as $key => $value) {
                 $periodView[$key] = $i18n->getInput('date', $period[$key]);
             }
             $tp->assign('filter', $filter);
             $tp->assign('search', $search);
             $tp->assign('columnTitle', $columnTitle);
             $tp->assign('listingTypeSID', $listingTypeSID);
             $tp->assign('period', $period);
             $tp->assign('periodView', $periodView);
             $tp->assign('statistics', $statistics);
             $tp->assign('countResult', count($statistics));
             $tp->assign('sorting_field', $sorting_field);
             $tp->assign('sorting_order', $sorting_order);
             break;
     }
     $listingTypes = SJB_ListingTypeManager::getListingAllTypesForListType();
     $products = SJB_ProductsManager::getAllProductsInfo();
     $acl = SJB_Acl::getInstance();
     foreach ($listingTypes as $key => $listingType) {
         $userGroup = array();
         foreach ($products as $productInfo) {
             if ($acl->isAllowed('post_' . strtolower($listingType['key']), $productInfo['sid'], 'product') && !in_array($productInfo['user_group_sid'], $userGroup)) {
                 $userGroup[] = $productInfo['user_group_sid'];
             }
         }
         $listingTypes[$listingType['id']] = $listingType;
         $listingTypes[$listingType['id']]['userGroups'] = $userGroup;
         unset($listingTypes[$key]);
     }
     $tp->assign('userGroups', $userGroups);
     $tp->assign('listingTypes', $listingTypes);
     $tp->assign('errors', $errors);
     $tp->assign('action', $action);
     $tp->display($template);
 }
コード例 #7
0
ファイル: job_import.php プロジェクト: Maxlander/shixi
 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');
     }
 }
コード例 #8
0
ファイル: ExportController.php プロジェクト: Maxlander/shixi
 public static function generateExportData($parameters)
 {
     $exportProperties = $aliases = $sid = null;
     extract($parameters);
     $listingInfo = SJB_ListingManager::getListingInfoBySID($sid);
     $listingInfo = $aliases->changePropertiesInfo($listingInfo);
     $exportData = array();
     $i18n = SJB_I18N::getInstance();
     foreach ($exportProperties as $propertyId => $value) {
         if ('ApplicationSettings' == $propertyId) {
             $exportData[$sid][$propertyId] = isset($listingInfo[$propertyId]['value']) ? $listingInfo[$propertyId]['value'] : null;
         } else {
             $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($propertyId);
             if (!empty($fieldInfo['type']) && $fieldInfo['type'] == 'complex' && isset($listingInfo[$propertyId])) {
                 $complexFields = $listingInfo[$propertyId];
                 if (is_string($listingInfo[$propertyId])) {
                     $complexFields = unserialize($complexFields);
                 }
                 if (is_array($complexFields)) {
                     $fieldsInfo = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($fieldInfo['sid']);
                     foreach ($fieldsInfo as $key => $info) {
                         $fieldsInfo[$info['id']] = $info;
                         unset($fieldsInfo[$key]);
                     }
                     $domDocument = new DOMDocument();
                     $rootElement = $domDocument->createElement($propertyId . 's');
                     $domDocument->appendChild($rootElement);
                     $propertyElements = array();
                     $createPropertyElements = true;
                     foreach ($complexFields as $fieldName => $fieldValue) {
                         $fieldInfo = isset($fieldsInfo[$fieldName]) ? $fieldsInfo[$fieldName] : array();
                         foreach ($fieldValue as $key => $value) {
                             if (isset($fieldInfo['type']) && $fieldInfo['type'] == 'complexfile' && $value != '') {
                                 $fileName = SJB_UploadFileManager::getUploadedSavedFileName($value);
                                 $value = $fileName ? 'files/' . $fileName : '';
                             } elseif (isset($fieldInfo['type']) && $fieldInfo['type'] == 'date' && $value != '') {
                                 $value = $i18n->getDate($value);
                             }
                             if ($createPropertyElements) {
                                 $propertyElement = $domDocument->createElement($propertyId);
                                 $rootElement->appendChild($propertyElement);
                                 $propertyElements[$key] = $propertyElement;
                             }
                             $fieldElement = $domDocument->createElement($fieldName);
                             $propertyElements[$key]->appendChild($fieldElement);
                             $valElement = $domDocument->createTextNode(XML_Util::replaceEntities($value));
                             $fieldElement->appendChild($valElement);
                         }
                         $createPropertyElements = false;
                     }
                     $exportData[$sid][$propertyId] = $domDocument->saveXML();
                 } else {
                     $exportData[$sid][$propertyId] = null;
                 }
             } else {
                 $exportData[$sid][$propertyId] = isset($listingInfo[$propertyId]) ? $listingInfo[$propertyId] : null;
             }
         }
     }
     self::changeTreeProperties($exportProperties, $exportData);
     self::changeMonetaryProperties($exportProperties, $exportData);
     self::changeListProperties($exportProperties, $exportData);
     self::changePicturesProperties($exportProperties, $exportData);
     self::changeFileProperties($exportProperties, $exportData, 'file');
     self::changeFileProperties($exportProperties, $exportData, 'video');
     self::changeComplexFileProperties($exportProperties, $exportData, 'complexfile');
     self::changeLocationProperties($exportProperties, $exportData);
     return $exportData[$sid];
 }
コード例 #9
0
 function _createTreeInfo($tree_column_name, $tree_captions)
 {
     $tree_sid_searcher = new SJB_TreeInfoSearcher($tree_column_name, array($tree_captions[0]), $this->listing_type);
     $tree_info = $tree_sid_searcher->getInfo();
     $field_info = SJB_ListingFieldDBManager::getListingFieldInfoByID($tree_column_name);
     $field_sid = $field_info['sid'];
     if ($tree_info == null) {
         SJB_ListingFieldTreeManager::addTreeItemToEndByParentSID($field_sid, 0, $tree_captions[0]);
     }
     $tree_info = $tree_sid_searcher->getInfo();
     SJB_ListingFieldTreeManager::addTreeItemToEndByParentSID($field_sid, $tree_info['sid'], $tree_captions[1]);
     $tree_sid_searcher = new SJB_TreeInfoSearcher($tree_column_name, $tree_captions, $this->listing_type);
     $tree_info = $tree_sid_searcher->getInfo();
     return $tree_info;
 }
コード例 #10
0
ファイル: add_listing_step.php プロジェクト: Maxlander/shixi
 private function processComplexFields(SJB_Listing $listing, $listingInfo)
 {
     if (!empty($listingInfo['complex'])) {
         $i18n = SJB_I18N::getInstance();
         $listingComplex = unserialize($listingInfo['complex']);
         $complexFieldsIds = array();
         foreach ($listingComplex as $complexId => $complexValues) {
             if (!$listing->getProperty($complexId)) {
                 $complexFieldsIds[] = $complexId;
                 $complexInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($complexId);
                 $complexInfo['value'] = $complexValues;
                 foreach ($complexValues as $fieldId => $fieldValue) {
                     $fieldSid = SJB_ListingFieldDBManager::getComplexFieldSIDbyID($fieldId);
                     $fieldInfo = SJB_ListingFieldDBManager::getListingComplexFieldInfoBySID($fieldSid);
                     $complexInfo['fields'][] = $fieldInfo;
                     foreach ($fieldValue as $key => $value) {
                         if ($value != null) {
                             switch ($fieldInfo['type']) {
                                 case 'int':
                                 case 'integer':
                                     $complexInfo['value'][$fieldId][$key] = $i18n->getInt($value);
                                     break;
                                 case 'float':
                                     $complexInfo['value'][$fieldId][$key] = $i18n->getFloat($value);
                                     break;
                                 case 'date':
                                     $complexInfo['value'][$fieldId][$key] = $i18n->getDate($value);
                                     break;
                             }
                         }
                     }
                 }
                 $listing->addProperty($complexInfo);
             }
         }
         return $complexFieldsIds;
     }
     return array();
 }
コード例 #11
0
ファイル: sales.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', 'search');
     $template = SJB_Request::getVar('template', 'sales.tpl');
     $errors = array();
     $userGroups = SJB_UserGroupManager::getAllUserGroupsIDsAndCaptions();
     foreach ($userGroups as $key => $userGroup) {
         unset($userGroups[$key]);
         $userGroups[$userGroup['id']] = $userGroup;
     }
     switch ($action) {
         case 'export':
             $period = SJB_Request::getVar('period', array());
             $filter = SJB_Request::getVar('filter', false);
             $sorting_field = SJB_Request::getVar('sorting_field', 'total');
             $sorting_order = SJB_Request::getVar('sorting_order', 'DESC');
             $statistics = array();
             if ($filter) {
                 $statistics = SJB_Statistics::getSalesStatistics($period, $filter, $sorting_field, $sorting_order);
                 if (!empty($statistics['errors'])) {
                     $errors = $statistics['errors'];
                 }
             } else {
                 $errors[] = 'EMPTY_PARAMETER';
             }
             $columnTitle = '';
             if (strstr($filter, 'userGroup_')) {
                 $userGroupSID = str_replace('userGroup_', '', $filter);
                 if ($userGroups[$userGroupSID]['key'] == 'Employer') {
                     $columnTitle = 'Company Name';
                 } else {
                     $columnTitle = $userGroups[$userGroupSID]['caption'] . ' Name';
                 }
                 $exportProperties['generalColumn'] = $columnTitle;
             } elseif ($filter == 'sid') {
                 $columnTitle = 'Product Name';
                 $exportProperties['generalColumn'] = 'Product Name';
                 $exportProperties['product_type'] = 'Product Type';
                 $tp->assign('link', 'product');
             } else {
                 $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($filter);
                 $exportProperties['generalColumn'] = $fieldInfo['caption'];
             }
             $exportProperties['units_sold'] = 'Units Sold';
             $exportProperties['total'] = 'Income';
             $exportProperties['percent'] = '%';
             if (!$errors && $statistics) {
                 $type = SJB_Request::getVar('type', 'csv');
                 SJB_StatisticsExportController::createExportDirectory();
                 switch ($type) {
                     case 'csv':
                         $exportData = SJB_StatisticsExportController::getSalesExportData($statistics, $exportProperties);
                         $fileName = 'sales.csv';
                         SJB_StatisticsExportController::makeCSVExportFile($exportData, $fileName, 'App & Views');
                         SJB_StatisticsExportController::archiveAndSendExportFile('sales', 'csv');
                         break;
                     case 'xls':
                         $exportData = SJB_StatisticsExportController::getSalesExportData($statistics, $exportProperties);
                         $fileName = 'sales.xls';
                         SJB_StatisticsExportController::makeXLSExportFile($exportData, $fileName, 'App & Views');
                         SJB_StatisticsExportController::archiveAndSendExportFile('sales', 'xls');
                         break;
                 }
                 break;
             }
         case 'search':
             $search = SJB_Request::getVar('search', false);
             $period = SJB_Request::getVar('period', array());
             $filter = SJB_Request::getVar('filter', false);
             $sorting_field = SJB_Request::getVar('sorting_field', 'total');
             $sorting_order = SJB_Request::getVar('sorting_order', 'DESC');
             $statistics = array();
             if ($search) {
                 if (!empty($period['from']) && !empty($period['to']) && strtotime($period['from']) > strtotime($period['to'])) {
                     $errors[] = 'SELECTED_PERIOD_IS_INCORRECT';
                 } else {
                     if ($filter) {
                         $statistics = SJB_Statistics::getSalesStatistics($period, $filter, $sorting_field, $sorting_order);
                         if (!empty($statistics['errors'])) {
                             $errors = $statistics['errors'];
                         }
                     } else {
                         $errors[] = 'EMPTY_PARAMETER';
                     }
                 }
             }
             $columnTitle = '';
             if (strstr($filter, 'userGroup_')) {
                 $userGroupSID = str_replace('userGroup_', '', $filter);
                 if ($userGroups[$userGroupSID]['key'] == 'Employer') {
                     $columnTitle = 'Company Name';
                 } else {
                     $columnTitle = $userGroups[$userGroupSID]['caption'] . ' Name';
                 }
                 $tp->assign('link', 'user');
             } else {
                 if ($filter == 'sid') {
                     $columnTitle = 'Product Name';
                     $tp->assign('link', 'product');
                 } else {
                     if (in_array($filter, array('Location_Country', 'Location_State', 'Location_City'))) {
                         $fieldInfo = SJB_ListingFieldDBManager::getLocationFieldsInfoById($filter);
                     } else {
                         $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($filter);
                     }
                     $columnTitle = $fieldInfo['caption'];
                 }
             }
             $i18n = SJB_I18N::getInstance();
             $periodView = array();
             foreach ($period as $key => $value) {
                 $periodView[$key] = $i18n->getInput('date', $period[$key]);
             }
             $tp->assign('search', $search);
             $tp->assign('filter', $filter);
             $tp->assign('columnTitle', $columnTitle);
             $tp->assign('period', $period);
             $tp->assign('periodView', $periodView);
             $tp->assign('statistics', $statistics);
             $tp->assign('countResult', count($statistics));
             $tp->assign('sorting_field', $sorting_field);
             $tp->assign('sorting_order', $sorting_order);
             break;
     }
     $tp->assign('userGroups', $userGroups);
     $tp->assign('errors', $errors);
     $tp->assign('action', $action);
     $tp->display($template);
 }
コード例 #12
0
 public function execute()
 {
     $ajaxAction = SJB_Request::getVar('ajax_action', '', 'GET');
     $formToken = SJB_Request::getVar('form_token', '');
     // save token date in session. In some code we needs to get list of it, and clean old tokens data from
     // session.
     self::setTokenDateToSession($formToken);
     switch ($ajaxAction) {
         // UPLOAD USER PROFILE VIDEO
         case 'upload_profile_video':
         case 'upload_profile_logo':
             $uploadedFieldId = SJB_Request::getVar('uploaded_field_name', '', 'GET');
             // get field by user group return not all fields of profile.
             // but now we use getAllFieldsInfo() to check fields
             $userProfileFields = SJB_UserProfileFieldManager::getAllFieldsInfo();
             $fieldSid = null;
             foreach ($userProfileFields as $field) {
                 if ($field['id'] != $uploadedFieldId) {
                     continue;
                 }
                 $fieldSid = $field['sid'];
             }
             if ($fieldSid == null) {
                 echo "Wrong profile field specified";
                 exit;
             }
             $fieldInfo = SJB_UserProfileFieldManager::getFieldInfoBySID($fieldSid);
             $tp = SJB_System::getTemplateProcessor();
             $validation = $this->validationManager($fieldInfo, $tp, $uploadedFieldId);
             if ($validation === true) {
                 // video file already uploaded after isValid checks
                 // but for 'Logo' - we need some actions to make save picture
                 if ($fieldInfo['type'] == 'logo') {
                     $upload_manager = new SJB_UploadPictureManager();
                     $upload_manager->setUploadedFileID($this->fileUniqueId);
                     $upload_manager->setHeight($fieldInfo['height']);
                     $upload_manager->setWidth($fieldInfo['width']);
                     $upload_manager->uploadPicture($fieldInfo['id'], $fieldInfo);
                     // and set value of file id to property
                     $this->property->setValue($this->fileUniqueId);
                     $this->propertyValue = $this->property->getValue();
                 }
                 // set uploaded video to temporary value
                 if ($fieldInfo['type'] == 'video' && isset($this->propertyValue['file_id'])) {
                     $uploadedID = $this->propertyValue['file_id'];
                     // rename it to unique value
                     SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $this->fileUniqueId, $uploadedID);
                     // fill session data for tmp storage
                     $fieldValue = array('file_id' => $this->fileUniqueId, 'file_url' => $this->propertyValue['file_url'], 'file_name' => $this->propertyValue['file_name'], 'saved_file_name' => $this->propertyValue['saved_file_name']);
                     $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
                     $tmpUploadsStorage = SJB_Array::setPathValue($tmpUploadsStorage, "{$formToken}/{$uploadedFieldId}", $fieldValue);
                     SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
                 } elseif ($fieldInfo['type'] == 'logo') {
                     // for Logo - we already have file_url data and file_thumb data, without file_id
                     // just add this to session storage
                     // fill session data for tmp storage
                     $fieldValue = array('file_id' => $this->fileUniqueId, 'file_url' => $this->propertyValue['file_url'], 'file_name' => $this->propertyValue['file_name'], 'thumb_file_url' => $this->propertyValue['thumb_file_url'], 'thumb_file_name' => $this->propertyValue['thumb_file_name']);
                     $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
                     $tmpUploadsStorage = SJB_Array::setPathValue($tmpUploadsStorage, "{$formToken}/{$uploadedFieldId}", $fieldValue);
                     SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
                 }
                 $tp->assign(array('id' => $uploadedFieldId, 'value' => $fieldValue));
             }
             $template = '';
             switch ($fieldInfo['type']) {
                 case 'video':
                     $template = '../field_types/input/video_profile.tpl';
                     break;
                 case 'logo':
                     $template = '../field_types/input/logo.tpl';
                     break;
                 default:
                     break;
             }
             $tp->assign('form_token', $formToken);
             $tp->assign('errors', $this->errors);
             $tp->display($template);
             break;
             ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         case 'delete_profile_video':
         case 'delete_profile_logo':
             $userSid = SJB_Request::getVar('user_sid', null);
             if (empty($userSid)) {
                 $userInfo = SJB_UserManager::getCurrentUserInfo();
             } else {
                 $userInfo = SJB_UserManager::getUserInfoBySID($userSid);
             }
             $fieldId = SJB_Request::getVar('field_id', null);
             // check session value
             $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage');
             $sessionFileId = SJB_Array::getPath($sessionFileStorage, "{$formToken}/{$fieldId}/file_id");
             if (is_null($fieldId)) {
                 $this->errors['PARAMETERS_MISSED'] = 1;
             } elseif (!empty($userInfo) && !isset($userInfo[$fieldId]) && empty($sessionFileId)) {
                 echo json_encode(array('result' => 'success'));
                 exit;
             } else {
                 if (!empty($userInfo)) {
                     $uploaded_file_id = $userInfo[$fieldId];
                     SJB_UploadFileManager::deleteUploadedFileByID($uploaded_file_id);
                 }
                 if (!empty($sessionFileId)) {
                     $formFileId = SJB_Request::getVar('file_id');
                     if ($sessionFileId == $formFileId) {
                         SJB_UploadFileManager::deleteUploadedFileByID($formFileId);
                         $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}/{$fieldId}");
                         SJB_Session::setValue('tmp_uploads_storage', $sessionFileStorage);
                     }
                 }
             }
             if (empty($this->errors)) {
                 echo json_encode(array('result' => 'success'));
             } else {
                 echo json_encode(array('result' => 'error', 'errors' => $this->errors));
             }
             exit;
             break;
             ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
             // UPLOAD LISTIG FILES
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         // UPLOAD LISTIG FILES
         case 'upload_classifieds_video':
         case 'upload_file':
             $uploadedFieldId = SJB_Request::getVar('uploaded_field_name', '', 'GET');
             // OK. For listings form we have 'listing_id' and optional field (for new listings with temporary id) - listing_type_id
             $listingId = SJB_Request::getVar('listing_id');
             $listingTypeId = SJB_Request::getVar('listing_type_id');
             if (empty($listingTypeId)) {
                 $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
                 $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listingInfo['listing_type_sid']);
             }
             $listingTypeSid = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeId);
             $commonListingFields = SJB_ListingFieldManager::getCommonListingFieldsInfo();
             $listingFieldsByType = SJB_ListingFieldManager::getListingFieldsInfoByListingType($listingTypeSid);
             $listingFields = array_merge($commonListingFields, $listingFieldsByType);
             $fieldSid = null;
             foreach ($listingFields as $field) {
                 if ($field['id'] != $uploadedFieldId) {
                     continue;
                 }
                 $fieldSid = $field['sid'];
             }
             $fieldInfo = SJB_ListingFieldManager::getFieldInfoBySID($fieldSid);
             $tp = SJB_System::getTemplateProcessor();
             $validation = $this->validationManager($fieldInfo, $tp, $uploadedFieldId);
             if (!$validation) {
                 $tp->assign(array('listing_id' => $listingId, 'listing' => array('id' => $listingId)));
             } else {
                 // video file already uploaded after isValid checks
                 // but for 'Logo' - we need some actions to make save picture
                 if ($this->property->getType() == 'file') {
                     if ($_FILES[$uploadedFieldId]['error']) {
                         $this->errors[SJB_UploadFileManager::getErrorId($_FILES[$uploadedFieldId]['error'])] = 1;
                     }
                     $upload_manager = new SJB_UploadFileManager();
                     $upload_manager->setUploadedFileID($this->fileUniqueId);
                     $upload_manager->setFileGroup('files');
                     $upload_manager->uploadFile($fieldInfo['id']);
                     // and set value of file id to property
                     $this->property->setValue($this->fileUniqueId);
                 }
                 $this->propertyValue = $this->property->getValue();
                 // set uploaded video to temporary value
                 if (isset($this->propertyValue['file_id'])) {
                     $uploadedID = $this->propertyValue['file_id'];
                     // rename it to unique value
                     SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $this->fileUniqueId, $uploadedID);
                     // SET VALUE TO TEMPORARY SESSION STORAGE
                     $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
                     $fileValue = array('file_id' => $this->fileUniqueId, 'saved_name' => $this->propertyValue['saved_file_name']);
                     $tmpUploadsStorage = SJB_Array::setPathValue($tmpUploadsStorage, "{$formToken}/{$uploadedFieldId}", $fileValue);
                     SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
                     // update listing property
                     $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
                     $listing = isset($listingInfo['listing_type_sid']) ? new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']) : new SJB_Listing($listingInfo);
                     $listingProperties = $listing->getProperties();
                     $propertyInfo = array('id' => $uploadedFieldId, 'type' => 'string', 'value' => $this->fileUniqueId, 'is_system' => true);
                     foreach ($listingProperties as $property) {
                         if ($property->getID() == $uploadedFieldId) {
                             $listing->addProperty($propertyInfo);
                         }
                     }
                     $listing->setSID($listingId);
                     SJB_ListingManager::saveListing($listing);
                     $tp->assign(array('id' => $uploadedFieldId, 'value' => array('file_url' => $this->propertyValue['file_url'], 'file_name' => $this->propertyValue['file_name'], 'saved_file_name' => $this->propertyValue['saved_file_name'], 'file_id' => $this->fileUniqueId), 'listing_id' => $listingId, 'listing' => array('id' => $listingId)));
                 }
             }
             switch ($this->property->getType()) {
                 case 'video':
                     $template = '../field_types/input/video.tpl';
                     break;
                 case 'file':
                     $template = '../field_types/input/file.tpl';
                     break;
                 default:
                     $template = '../field_types/input/video.tpl';
                     break;
             }
             $tp->assign('errors', $this->errors);
             $tp->assign('form_token', $formToken);
             $tp->display($template);
             self::cleanOldTokensFromSession();
             break;
             ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         case 'delete_classifieds_video':
         case 'delete_file':
             $listingId = SJB_Request::getVar('listing_id', null);
             $fieldId = SJB_Request::getVar('field_id', null);
             $formFileId = SJB_Request::getVar('file_id');
             $this->errors = array();
             // check session value
             $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage');
             $sessionFileId = SJB_Array::getPath($sessionFileStorage, "{$formToken}/{$fieldId}/file_id");
             // if empty listing id - check end empty temporary storage
             if (strlen($listingId) == strlen(time())) {
                 if ($sessionFileId == $formFileId) {
                     SJB_UploadFileManager::deleteUploadedFileByID($formFileId);
                     // remove field from temporary storage
                     if (!is_null($sessionFileStorage)) {
                         $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}/{$fieldId}");
                         SJB_Session::setValue('tmp_uploads_storage', $sessionFileStorage);
                     }
                 }
             } else {
                 // we change existing listing
                 $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
                 if ((is_null($listingInfo) || !isset($listingInfo[$fieldId])) && empty($sessionFileId)) {
                     $this->errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
                 } else {
                     if (!$this->isOwner($listingId)) {
                         $this->errors['NOT_OWNER'] = 1;
                     } else {
                         $uploadedFileId = $listingInfo[$fieldId];
                         if (!empty($uploadedFileId)) {
                             SJB_UploadFileManager::deleteUploadedFileByID($uploadedFileId);
                         }
                         SJB_UploadFileManager::deleteUploadedFileByID($formFileId);
                         $listingInfo[$fieldId] = '';
                         $listing = isset($listingInfo['listing_type_sid']) ? new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']) : new SJB_Listing($listingInfo);
                         // remove all non-changed properties and save only changed property in listing
                         $props = $listing->getProperties();
                         foreach ($props as $prop) {
                             if ($prop->getID() !== $fieldId) {
                                 $listing->deleteProperty($prop->getID());
                             }
                         }
                         $listing->setSID($listingId);
                         SJB_ListingManager::saveListing($listing);
                         // remove field from temporary storage
                         $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage');
                         if (!is_null($sessionFileStorage)) {
                             $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}/{$fieldId}");
                             SJB_Session::setValue('tmp_uploads_storage', $sessionFileStorage);
                         }
                     }
                 }
             }
             if (empty($this->errors)) {
                 echo json_encode(array('result' => 'success'));
             } else {
                 echo json_encode(array('result' => 'error', 'errors' => $this->errors));
             }
             exit;
             break;
             ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         case 'get_classifieds_video_data':
         case 'get_file_field_data':
             $fieldId = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null;
             $listingId = SJB_Request::getVar('listing_id');
             $filesFromTmpStorage = SJB_Session::getValue('tmp_uploads_storage');
             $fileUniqueId = SJB_Array::getPath($filesFromTmpStorage, "{$formToken}/{$fieldId}/file_id");
             // if no temporary files uploaded, return empty string
             if (empty($fileUniqueId)) {
                 return '';
             }
             $tp = SJB_System::getTemplateProcessor();
             $upload_manager = new SJB_UploadFileManager();
             $fileInfo = array('id' => $fieldId, 'value' => array('file_url' => $upload_manager->getUploadedFileLink($fileUniqueId), 'file_name' => $upload_manager->getUploadedFileName($fileUniqueId), 'saved_file_name' => $upload_manager->getUploadedSavedFileName($fileUniqueId), 'file_id' => $fileUniqueId), 'listing_id' => $listingId, 'listing' => array('id' => $listingId));
             $tp->assign($fileInfo);
             $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($fieldId);
             $fieldType = $fieldInfo['type'];
             $template = '';
             switch ($fieldType) {
                 case 'video':
                     $template = '../field_types/input/video.tpl';
                     break;
                 case 'file':
                     $template = '../field_types/input/file.tpl';
                     break;
                 case 'logo':
                     $template = '../field_types/input/logo_listing.tpl';
                     break;
                 default:
                     break;
             }
             $uploadedFilesize = $upload_manager->getUploadedFileSize($fileUniqueId);
             $filesizeInfo = SJB_HelperFunctions::getFileSizeAndSizeToken($uploadedFilesize);
             $tp->assign(array('filesize' => $filesizeInfo['filesize'], 'size_token' => $filesizeInfo['size_token']));
             $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
             $tp->assign('form_token', $formToken);
             $tp->display($template);
             break;
             ////////////////////////////////////////////////////////////////////////////////////////////////////////////
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////
         case 'upload_file_complex':
         case 'upload_classifieds_video_complex':
             $uploadedFieldId = SJB_Request::getVar('uploaded_field_name', '', 'GET');
             list($parentField, $subFieldId, $complexStep) = explode(':', $uploadedFieldId);
             // OK. For listings form we have 'listing_id' and optional field (for new listings with temporary id) - listing_type_id
             $listingId = SJB_Request::getVar('listing_id');
             $listingTypeId = SJB_Request::getVar('listing_type_id');
             if (empty($listingTypeId)) {
                 $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
                 $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listingInfo['listing_type_sid']);
             }
             $listingTypeSid = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeId);
             $commonListingFields = SJB_ListingFieldManager::getCommonListingFieldsInfo();
             $listingFieldsByType = SJB_ListingFieldManager::getListingFieldsInfoByListingType($listingTypeSid);
             $listingFields = array_merge($commonListingFields, $listingFieldsByType);
             // check parent field
             $fieldSid = null;
             foreach ($listingFields as $field) {
                 if ($field['id'] != $parentField) {
                     continue;
                 }
                 $fieldSid = $field['sid'];
             }
             $complexFieldInfo = SJB_ListingFieldManager::getFieldInfoBySID($fieldSid);
             $subFields = SJB_Array::get($complexFieldInfo, 'fields');
             if (empty($subFields)) {
                 echo 'wrong field ID';
                 exit;
             }
             // check field
             $fieldInfo = '';
             foreach ($subFields as $subField) {
                 if ($subField['id'] != $subFieldId) {
                     continue;
                 }
                 $fieldInfo = $subField;
             }
             $complexParameters = array('parentField' => $parentField, 'subFieldId' => $subFieldId, 'complexStep' => $complexStep);
             $tp = SJB_System::getTemplateProcessor();
             $validation = $this->validationManager($fieldInfo, $tp, $uploadedFieldId, $complexParameters);
             $upload_manager = new SJB_UploadFileManager();
             $upload_manager->setUploadedFileID($this->fileUniqueId);
             $upload_manager->setFileGroup('files');
             $upload_manager->uploadFile($fieldInfo['id'], $parentField);
             $this->property->setValue($this->fileUniqueId);
             $this->propertyValue = $this->property->getPropertyVariablesToAssign();
             // set uploaded video to temporary value
             if ((isset($this->propertyValue['value']['file_id']) || isset($this->propertyValue['value'][$complexStep]['file_id'])) && $validation) {
                 // fix for FILE type in complex field
                 if (isset($this->propertyValue['value'][$complexStep]['file_id'])) {
                     $this->propertyValue['value'] = $this->propertyValue['value'][$complexStep];
                 }
                 $filesInfo = array($complexStep => $this->propertyValue['value']);
                 $uploadedID = $this->propertyValue['value']['file_id'];
                 // rename it to unique value
                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $this->fileUniqueId, $uploadedID);
                 // SET VALUE TO TEMPORARY SESSION STORAGE
                 $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
                 $fileValue = array('file_id' => $this->fileUniqueId, 'saved_name' => $this->propertyValue['value']['saved_file_name']);
                 $tmpUploadsStorage = SJB_Array::setPathValue($tmpUploadsStorage, "{$formToken}/{$uploadedFieldId}", $fileValue);
                 SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
                 $tp->assign(array('id' => $subFieldId, 'value' => $this->propertyValue['value']['file_name'], 'filesInfo' => $filesInfo, 'complexField' => $parentField, 'complexStep' => $complexStep, 'listing_id' => $listingId, 'listing' => array('id' => $listingId)));
             } else {
                 $tp->assign(array('id' => $subFieldId, 'complexField' => $parentField, 'complexStep' => $complexStep, 'listing_id' => $listingId, 'listing' => array('id' => $listingId)));
             }
             switch ($this->property->getType()) {
                 case 'video':
                     $template = '../field_types/input/video.tpl';
                     break;
                 case 'file':
                 case 'complexfile':
                     $template = '../field_types/input/file.tpl';
                     break;
                 default:
                     $template = '../field_types/input/video.tpl';
                     break;
             }
             $tp->assign('form_token', $formToken);
             $tp->assign('errors', $this->errors);
             $tp->display($template);
             break;
             ////////////////////////////////////////////////////////////////////////////////////////////////////////////
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////
         case 'delete_file_complex':
             $listingId = SJB_Request::getVar('listing_id', null);
             $fieldId = SJB_Request::getVar('field_id', null);
             $formFileId = SJB_Request::getVar('file_id');
             $this->errors = array();
             // check session value
             $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage');
             $sessionFileId = SJB_Array::getPath($sessionFileStorage, "{$formToken}/{$fieldId}/file_id");
             // if empty listing id - check and empty temporary storage
             if (strlen($listingId) == strlen(time())) {
                 if ($sessionFileId == $formFileId) {
                     SJB_UploadFileManager::deleteUploadedFileByID($formFileId);
                     // remove field from temporary storage
                     $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}/{$fieldId}");
                     SJB_Session::setValue('tmp_uploads_storage', $sessionFileStorage);
                 }
             } else {
                 // we change existing listing
                 $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
                 list($complexField, $subField, $complexStep) = explode(':', $fieldId);
                 $fieldValue = SJB_Array::getPath($listingInfo, "{$complexField}/{$subField}/{$complexStep}");
                 // if field value not present in listing and not present in temporary storage - throw error
                 if ((is_null($listingInfo) || $fieldValue === null) && empty($sessionFileId)) {
                     $this->errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
                 } else {
                     if (!$this->isOwner($listingId)) {
                         $this->errors['NOT_OWNER'] = 1;
                     } else {
                         $uploadedFileId = $fieldValue;
                         if (!empty($uploadedFileId)) {
                             SJB_UploadFileManager::deleteUploadedFileByID($uploadedFileId);
                         }
                         SJB_UploadFileManager::deleteUploadedFileByID($formFileId);
                         $listingInfo = SJB_Array::setPathValue($listingInfo, "{$complexField}/{$subField}/{$complexStep}", '');
                         $listing = new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']);
                         // remove all non-changed properties and save only changed property in listing
                         $props = $listing->getProperties();
                         foreach ($props as $prop) {
                             if ($prop->getID() !== $fieldId) {
                                 $listing->deleteProperty($prop->getID());
                             }
                         }
                         $listing->setSID($listingId);
                         SJB_ListingManager::saveListing($listing);
                         // remove field from temporary storage
                         $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage');
                         if (!empty($sessionFileStorage)) {
                             $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}/{$fieldId}");
                             SJB_Session::setValue('tmp_uploads_storage', $sessionFileStorage);
                         }
                     }
                 }
             }
             if (empty($this->errors)) {
                 echo json_encode(array('result' => 'success'));
             } else {
                 echo json_encode(array('result' => 'error', 'errors' => $this->errors));
             }
             exit;
             break;
             ////////////////////////////////////////////////////////////////////////////////////////////////////////////
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////
         case 'get_complexfile_field_data':
             $listingId = SJB_Request::getVar('listing_id', null);
             $fieldId = SJB_Request::getVar('field_id', null);
             $listingTypeId = SJB_Request::getVar('listing_type_id');
             $listingTypeSid = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeId);
             $uploadFileManager = new SJB_UploadFileManager();
             // replace square brackets in complex field name
             $fieldId = str_replace("][", ":", $fieldId);
             $fieldId = str_replace("[", ":", $fieldId);
             $fieldId = str_replace("]", "", $fieldId);
             list($parentField, $subFieldId, $complexStep) = explode(':', $fieldId);
             $filesFromTmpStorage = SJB_Session::getValue('tmp_uploads_storage');
             //$fileUniqueId = SJB_Array::getPath($filesFromTmpStorage, "listings/{$listingId}/{$fieldId}/file_id");
             $fileUniqueId = SJB_Array::getPath($filesFromTmpStorage, "{$formToken}/{$fieldId}/file_id");
             // if no temporary files uploaded, return empty string
             if (empty($fileUniqueId)) {
                 return '';
             }
             // get list of fields for all listing types
             $listingTypesInfo = SJB_ListingTypeManager::getAllListingTypesInfo();
             $allFields = array();
             foreach ($listingTypesInfo as $listingTypeInfo) {
                 $typeFields = SJB_ListingFieldManager::getListingFieldsInfoByListingType($listingTypeInfo['sid']);
                 $allFields = array_merge($allFields, $typeFields);
             }
             // NEED TO GET COMPLEX SUBFIELD PROPERTY
             $commonListingFields = SJB_ListingFieldManager::getCommonListingFieldsInfo();
             $listingFieldsByType = $allFields;
             $listingFields = array_merge($commonListingFields, $listingFieldsByType);
             // check parent field
             $fieldSid = null;
             foreach ($listingFields as $field) {
                 if ($field['id'] != $parentField) {
                     continue;
                 }
                 $fieldSid = $field['sid'];
             }
             // parent complex field
             $complexFieldInfo = SJB_ListingFieldManager::getFieldInfoBySID($fieldSid);
             $subFields = SJB_Array::get($complexFieldInfo, 'fields');
             if (empty($subFields)) {
                 echo 'wrong field ID';
                 exit;
             }
             // check field for subfield
             $complexSubFieldInfo = '';
             foreach ($subFields as $subField) {
                 if ($subField['id'] != $subFieldId) {
                     continue;
                 }
                 $complexSubFieldInfo = $subField;
             }
             if (empty($complexSubFieldInfo)) {
                 echo 'Wrong field info';
                 exit;
             }
             // OK. COMPLEX SUBFIELD WE HAVE
             $complexSubFieldProperty = new SJB_ObjectProperty($complexSubFieldInfo);
             // complex file fields contents array of values, not just string filename
             $complexSubFieldProperty->setValue(array($complexStep => $fileUniqueId));
             $valueToAssign = $complexSubFieldProperty->getPropertyVariablesToAssign();
             $additionalInfo = array('listing_id' => $listingId, 'listing' => array('id' => $listingId), 'complexField' => $parentField, 'complexStep' => $complexStep);
             $tp = SJB_System::getTemplateProcessor();
             $tp->assign($valueToAssign);
             $tp->assign($additionalInfo);
             $template = '';
             switch ($complexSubFieldProperty->getType()) {
                 case 'complexfile':
                     $template = '../field_types/input/file.tpl';
                     break;
                 default:
                     break;
             }
             $uploadedFilesize = $uploadFileManager->getUploadedFileSize($fileUniqueId);
             $filesizeInfo = SJB_HelperFunctions::getFileSizeAndSizeToken($uploadedFilesize);
             $tp->assign(array('filesize' => $filesizeInfo['filesize'], 'size_token' => $filesizeInfo['size_token']));
             $tp->assign('form_token', $formToken);
             $tp->display($template);
             break;
         case 'upload_listing_logo':
             $uploadedFieldId = SJB_Request::getVar('uploaded_field_name', '', 'GET');
             $listingSid = SJB_Request::getVar('listing_id', null);
             $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($uploadedFieldId);
             $tp = SJB_System::getTemplateProcessor();
             $validation = $this->validationManager($fieldInfo, $tp, $uploadedFieldId);
             if ($validation === true) {
                 $upload_manager = new SJB_UploadPictureManager();
                 $upload_manager->setUploadedFileID($this->fileUniqueId);
                 $upload_manager->setHeight($fieldInfo['height']);
                 $upload_manager->setWidth($fieldInfo['width']);
                 $upload_manager->uploadPicture($fieldInfo['id'], $fieldInfo);
                 // and set value of file id to property
                 $this->property->setValue($this->fileUniqueId);
                 $this->propertyValue = $this->property->getValue();
                 // for Logo - we already have file_url data and file_thumb data, without file_id
                 // just add this to session storage
                 // fill session data for tmp storage
                 $fieldValue = array('file_id' => $this->fileUniqueId, 'file_url' => $this->propertyValue['file_url'], 'file_name' => $this->propertyValue['file_name'], 'thumb_file_url' => $this->propertyValue['thumb_file_url'], 'thumb_file_name' => $this->propertyValue['thumb_file_name']);
                 $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
                 $tmpUploadsStorage = SJB_Array::setPathValue($tmpUploadsStorage, "{$formToken}/{$uploadedFieldId}", $fieldValue);
                 SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
                 $tp->assign(array('id' => $uploadedFieldId, 'value' => $fieldValue));
             }
             $template = '../field_types/input/logo_listing.tpl';
             $tp->assign('form_token', $formToken);
             $tp->assign('errors', $this->errors);
             $tp->assign('listing_id', $listingSid);
             $tp->display($template);
             break;
         default:
             echo "Action not defined!";
             break;
     }
     exit;
 }
コード例 #13
0
ファイル: add_import.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $errors = array();
     if (SJB_Request::isAjax()) {
         $response = null;
         $user_type = SJB_Request::getVar('user_type');
         $user_name = SJB_Request::getVar('parser_user');
         $products = SJB_XmlImport::getProducts($user_type, $user_name, $errors);
         $response = array('products' => empty($products) ? '' : SJB_XmlImport::translateProductsName($products), 'error' => empty($errors) ? '' : array_pop($errors));
         die(json_encode($response));
     }
     $tp = SJB_System::getTemplateProcessor();
     $add_level = SJB_Request::getVar('add_level', 1);
     // check for errors
     if ($add_level == '3') {
         $selectUserType = SJB_Request::getVar('selectUserType');
         $addNewUser = 0;
         if ($selectUserType == 'username') {
             $usr_name = isset($_REQUEST['parser_user']) ? SJB_DB::quote($_REQUEST['parser_user']) : '';
             $usr_id = SJB_UserManager::getUserSIDbyUsername($usr_name);
             if (empty($usr_name)) {
                 $errors[] = 'Please enter user name of existing user to the "User Name" field';
                 $usr_name = '';
             } else {
                 $user_sid_exists = SJB_UserManager::getUserSIDbyUsername($usr_name);
                 if (empty($user_sid_exists)) {
                     $errors[] = 'User "' . $usr_name . '" not exists. Please enter user name of existing user to the "User Name" field';
                     $usr_name = '';
                 }
             }
         } elseif ($selectUserType == 'group') {
             $userGroupSid = isset($_REQUEST['parser_user']) ? $_REQUEST['parser_user'] : 0;
             $usr_id = $userGroupSid;
             $usr_name = SJB_UserGroupManager::getUserGroupIDBySID($usr_id);
             $addNewUser = 1;
         }
         if ($errors) {
             $add_level = 2;
         }
     }
     $listings_type = SJB_ListingTypeManager::getAllListingTypesInfo();
     $types = array();
     foreach ($listings_type as $one) {
         $types[$one['sid']] = $one['id'];
     }
     $tp->assign('types', $types);
     $selected_logo_options = null;
     switch ($add_level) {
         case '1':
             $template = 'add_step_one.tpl';
             /*
             $types = array();
             foreach ( $listings_type as $one ) {
             					  $types[$one['sid']] = $one['id'];
             }
             $tp->assign('types', $types);
             */
             $tp->display('add_step_one.tpl');
             break;
         case '2':
             $template = 'add_step_two.tpl';
             $original_xml = SJB_Request::getVar('xml');
             $xml = $original_xml;
             $tree = '';
             $listing_fields = array();
             $logo_options_array = array('not_logo' => 'Do Not Import Logo', 'import_logo' => 'Import Logo with Listings', 'upload_logo' => 'Upload Logo for Imported Listings');
             $parsing_name = SJB_Request::getVar('parser_name');
             $usr_name = SJB_Request::getVar('parser_user');
             $pars_url = SJB_Request::getVar('parser_url');
             $form_description = SJB_Request::getVar('form_description', '', 'POST');
             $type_id = SJB_Request::getVar('type_id', '', 'POST');
             $selectedLogoOption = SJB_Request::getVar('logo_options');
             $selectedLogoField = SJB_Request::getVar('import_logo_field');
             $selectedProduct = SJB_Request::getVar('postUnderProduct');
             $id = SJB_Request::getVar('id', 0, 'GET');
             $selected = array();
             $a_selected = array();
             if (!empty($_REQUEST['xml']) || $id > 0) {
                 // step 2 OR edit exist
                 if ($id > 0) {
                     // load exist parser
                     $parser_from_id = SJB_XmlImport::getSystemParsers($id);
                     if (isset($parser_from_id[0]['name'])) {
                         $parser_from_id = $parser_from_id[0];
                     }
                     $parsing_name = $parser_from_id['name'];
                     $usr_id = $parser_from_id['usr_id'];
                     $usr_name = $parser_from_id['usr_name'];
                     $form_description = $parser_from_id['description'];
                     $pars_url = $parser_from_id['url'];
                     $type_id = $parser_from_id['type_id'];
                     $selected_logo_options = unserialize($parser_from_id['logo_options']);
                     $selectedLogoOption = $selected_logo_options['option'];
                     $selectedLogoField = $selected_logo_options['field'];
                     $selectedProduct = $parser_from_id['product_sid'];
                     $xml = $parser_from_id['xml'];
                     $xml = SJB_XmlImport::cleanXmlFromImport($xml);
                     $map = unserialize($parser_from_id['maper']);
                     $selected = array_values($map);
                     $a_selected = array_keys($map);
                 } else {
                     $xml = SJB_XmlImport::cleanXmlFromImport($_REQUEST['xml']);
                 }
                 $sxml = new simplexml();
                 $tree = $sxml->xml_load_file($xml, 'array');
                 if (isset($tree['@content'])) {
                     $tree = $tree[0];
                 }
                 if (is_array($tree)) {
                     $tree = SJB_XmlImport::convertArray($tree);
                     foreach ($tree as $key => $val) {
                         unset($tree[$key]);
                         // replace '@' and ':'
                         $key = SJB_XmlImport::encodeSpecialEntities($key);
                         $tree[$key]['val'] = $val;
                         $tree[$key]['key'] = $key;
                     }
                     $field_types = array(0, $type_id);
                     $listing_fields = array();
                     $i = 0;
                     foreach ($field_types as $type) {
                         $listing_fields_info = SJB_ListingFieldManager::getListingFieldsInfoByListingType($type);
                         foreach ($listing_fields_info as $listing_field_info) {
                             if ($listing_field_info['type'] == 'location') {
                                 foreach ($listing_field_info['fields'] as $fieldInfo) {
                                     $listing_field = new SJB_ListingField($fieldInfo);
                                     $listing_field->setSID($fieldInfo['sid']);
                                     $listing_fields[$i]['id'] = $listing_field_info['id'] . '_' . $listing_field->details->properties['id']->value;
                                     $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value;
                                     $i++;
                                 }
                             } else {
                                 $listing_field = new SJB_ListingField($listing_field_info);
                                 $listing_field->setSID($listing_field_info['sid']);
                                 $listing_fields[$i]['id'] = $listing_field->details->properties['id']->value;
                                 $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value;
                                 $i++;
                             }
                         }
                     }
                     $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "date";
                     $i++;
                     $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "url";
                     $i++;
                     $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "external_id";
                 } else {
                     $errors[] = 'XML syntaxis error.';
                     $template = 'add_step_one.tpl';
                 }
             } else {
                 $errors[] = 'Please input correct xml';
                 $template = 'add_step_one.tpl';
             }
             $tp->assign('id', $id);
             $tp->assign('selected', $selected);
             $tp->assign('a_selected', $a_selected);
             $tp->assign('xml', htmlspecialchars($xml));
             $tp->assign('xmlToUser', $xml);
             $tp->assign('user_groups', SJB_UserGroupManager::getAllUserGroupsInfo());
             $tp->assign('form_name', $parsing_name);
             $tp->assign('form_user', $usr_name);
             $tp->assign('form_url', $pars_url);
             $tp->assign('form_description', $form_description);
             $type_name = SJB_ListingTypeManager::getListingTypeIDBySID($type_id);
             $tp->assign('type_id', $type_id);
             $tp->assign('type_name', $type_name);
             $tp->assign('errors', $errors);
             $tp->assign('tree', $tree);
             $tp->assign("fields", $listing_fields);
             $tp->assign('logo_options', $logo_options_array);
             $tp->assign('selectedLogoOption', $selectedLogoOption);
             $tp->assign('selectedLogoField', $selectedLogoField);
             $tp->assign('selectedProduct', $selectedProduct);
             $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
             $tp->display($template);
             break;
         case '3':
             $parsing_name = isset($_REQUEST['parser_name']) ? SJB_DB::quote($_REQUEST['parser_name']) : '';
             $pars_url = isset($_POST['parser_url']) ? SJB_DB::quote($_POST['parser_url']) : '';
             $selectedLogoOption = isset($_POST['logo_options']) ? $_POST['logo_options'] : '';
             $selectedLogoField = isset($_POST['import_logo_field']) ? $_POST['import_logo_field'] : '';
             $form_description = isset($_REQUEST['form_description']) ? SJB_DB::quote($_REQUEST['form_description']) : "";
             $type_id = isset($_POST['type_id']) ? intval($_POST['type_id']) : "";
             $script = isset($_POST['custom_script']) && !empty($_POST['custom_script']) ? SJB_DB::quote($_POST['custom_script']) : "";
             $script_users = SJB_DB::quote(SJB_Request::getVar('custom_script_users', '', SJB_Request::METHOD_POST));
             $defaultValue = SJB_Request::getVar('default_value', false);
             $defaultValueUser = SJB_Request::getVar('user_default_value', false);
             $selectedProduct = SJB_Request::getVar('postUnderProduct');
             $importType = SJB_Request::getVar('import_type', 'increment');
             if ($defaultValue) {
                 foreach ($defaultValue as $key => $val) {
                     $defaultValue[$key] = htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
                 }
             }
             if ($defaultValueUser) {
                 foreach ($defaultValueUser as $key => $val) {
                     $defaultValueUser[$key] = htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
                 }
             }
             $original_xml = !empty($_POST['xml']) ? SJB_DB::quote($_POST['xml']) : '';
             $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
             $addQuery = '';
             $username = SJB_XmlImport::decodeSpecialEntities(SJB_Request::getVar('username', ''));
             $external_id = str_replace('_dog_', '@', SJB_Request::getVar('external_id', ''));
             $site_url = SJB_System::getSystemSettings("SITE_URL");
             if ($addNewUser == 1 && empty($_REQUEST['mapped_user'])) {
                 $error = 'Required user profile fields are not mapped';
                 SJB_HelperFunctions::redirect($site_url . '/edit-import/?id=' . $id . '&save_error=' . base64_encode($error));
             }
             if (!empty($_REQUEST['mapped']) && is_array($_REQUEST['mapped']) && !empty($original_xml) && empty($errors)) {
                 // make map
                 $map1 = array();
                 $map2 = array();
                 $serUserMap = '';
                 foreach ($_REQUEST['mapped'] as $one) {
                     $tmp = explode(':', $one);
                     $map1[] = $tmp[0];
                     $map2[] = $tmp[1];
                 }
                 if ($addNewUser == 1 && !empty($_REQUEST['mapped_user']) && is_array($_REQUEST['mapped_user'])) {
                     // make map
                     $mapUser1 = array();
                     $mapUser2 = array();
                     foreach ($_REQUEST['mapped_user'] as $one) {
                         $tmp = explode(':', $one);
                         $mapUser1[] = str_replace('user_', '', $tmp[0]);
                         $mapUser2[] = $tmp[1];
                     }
                     foreach ($mapUser1 as $key => $val) {
                         $val = SJB_XmlImport::decodeSpecialEntities($val);
                         $mapUser[$val] = $mapUser2[$key];
                     }
                     $serUserMap = serialize($mapUser);
                 }
                 //$map = array_combine($map1, $map2); // PHP5
                 foreach ($map1 as $key => $val) {
                     $val = SJB_XmlImport::decodeSpecialEntities($val);
                     $map[$val] = $map2[$key];
                 }
                 if ($selectedLogoOption && $selectedLogoOption != 'not_logo') {
                     //get real data without any cache
                     if (!SJB_ListingFieldDBManager::getListingFieldInfoByID('ListingLogo')) {
                         $listing_field_info = array('id' => 'ListingLogo', 'type' => 'logo', 'is_system' => false, 'is_required' => false, 'caption' => 'Listing Logo');
                         $listing_field = new SJB_ListingField($listing_field_info, $type_id);
                         $pages = SJB_PostingPagesManager::getFirstPageEachListingType();
                         SJB_ListingFieldManager::saveListingField($listing_field, $pages);
                     }
                     if ($key = array_search('ListingLogo', $map) !== false) {
                         unset($map[$key]);
                     }
                 }
                 if ($defaultValue) {
                     foreach ($defaultValue as $key => $val) {
                         if ($val == '') {
                             unset($defaultValue[$key]);
                         }
                     }
                     $defaultValue = SJB_db::quote(serialize($defaultValue));
                     $addQuery .= ", default_value = '" . $defaultValue . "'";
                 }
                 if ($defaultValueUser) {
                     foreach ($defaultValueUser as $keyuser => $valuser) {
                         if ($valuser == '') {
                             unset($defaultValueUser[$keyuser]);
                         }
                     }
                     $defaultValueUser = SJB_db::quote(serialize($defaultValueUser));
                     $addQuery .= ", default_value_user = '******'";
                 }
                 $queryParsUrl = SJB_DB::quote($pars_url);
                 $queryImportType = SJB_DB::quote($importType);
                 $queryId = intval($id);
                 $query = "SET\n\t\t\t\t\t\t\t`custom_script_users` = ?s,\n\t\t\t\t\t\t\t`custom_script` = ?s,\n\t\t\t\t\t\t\t`type_id` = ?n,\n\t\t\t\t\t\t\t`name` = ?s,\n\t\t\t\t\t\t\t`description` = ?s,\n\t\t\t\t\t\t\t`url` = ?s,\n\t\t\t\t\t\t\t`usr_id` = ?n,\n\t\t\t\t\t\t\t`usr_name` = ?s,\n\t\t\t\t\t\t\t`maper_user` = ?s,\n\t\t\t\t\t\t\t`xml` = ?s,\n\t\t\t\t\t\t\t`add_new_user` = ?n,\n\t\t\t\t\t\t\t`username` = ?s,\n\t\t\t\t\t\t\t`external_id` = ?s,\n\t\t\t\t\t\t\t`product_sid` = ?n,\n\t\t\t\t\t\t\t`import_type` = ?s\n\t\t\t\t\t\t\t{$addQuery}";
                 if ($id > 0) {
                     SJB_DB::query("UPDATE `parsers` {$query} WHERE id = ?n", $script_users, $script, $type_id, $parsing_name, $form_description, $queryParsUrl, $usr_id, $usr_name, $serUserMap, $original_xml, $addNewUser, $username, $external_id, $selectedProduct, $queryImportType, $queryId);
                 } else {
                     $id = SJB_DB::query("INSERT INTO `parsers` {$query}", $script_users, $script, $type_id, $parsing_name, $form_description, $queryParsUrl, $usr_id, $usr_name, $serUserMap, $original_xml, $addNewUser, $username, $external_id, $selectedProduct, $queryImportType);
                 }
                 $errorFile = '';
                 $xml_logo = null;
                 switch ($selectedLogoOption) {
                     case 'import_logo':
                         $map[$selectedLogoField] = 'ListingLogo';
                         break;
                     case 'upload_logo':
                         if (!empty($_FILES['upload_logo_file'])) {
                             if ($_FILES['upload_logo_file']['error']) {
                                 $errorFile = SJB_UploadFileManager::getErrorId($_FILES['upload_logo_file']['error']);
                             } else {
                                 $width = SJB_Settings::getSettingByName('listing_picture_width');
                                 $height = SJB_Settings::getSettingByName('listing_picture_height');
                                 $property_info['second_width'] = SJB_Settings::getSettingByName('listing_thumbnail_width');
                                 $property_info['second_height'] = SJB_Settings::getSettingByName('listing_thumbnail_height');
                                 $picture = new SJB_UploadPictureManager();
                                 $picture->setWidth($width);
                                 $picture->setHeight($height);
                                 if ($picture->isValidUploadedPictureFile('upload_logo_file')) {
                                     $xml_logo = "XMLImportLogo_{$id}";
                                     $picture->setUploadedFileID($xml_logo);
                                     $picture->uploadPicture('upload_logo_file', $property_info);
                                 }
                             }
                         }
                         break;
                 }
                 $logo_options = serialize(array('option' => $selectedLogoOption, 'field' => $selectedLogoField));
                 $serMap = serialize($map);
                 if ($xml_logo) {
                     SJB_DB::query("UPDATE `parsers` SET maper = ?s, `xml_logo` = ?s, logo_options = ?s  WHERE id = ?n", $serMap, $xml_logo, $logo_options, $id);
                 } else {
                     SJB_DB::query("UPDATE `parsers` SET maper = ?s, logo_options = ?s  WHERE id = ?n", $serMap, $logo_options, $id);
                 }
                 $form_submitted = SJB_Request::getVar('form_action');
                 if ($form_submitted == 'save_info') {
                     SJB_HelperFunctions::redirect($site_url . '/show-import/');
                 } elseif ($form_submitted == 'apply_info') {
                     $getterParameters = '?id=' . $id;
                     if ($errorFile) {
                         $getterParameters .= '&error=' . $errorFile;
                     }
                     SJB_HelperFunctions::redirect($site_url . '/edit-import/' . $getterParameters);
                 }
             } else {
                 if (empty($errors)) {
                     $errors[] = 'No data to save';
                 }
                 $tp->assign('errors', $errors);
                 $tp->assign('xml', htmlspecialchars($original_xml));
                 $tp->assign('xmlToUser', $original_xml);
                 $tp->assign('form_name', $parsing_name);
                 $tp->assign('form_user', $usr_name);
                 $tp->assign('form_url', $pars_url);
                 $tp->assign('form_description', $form_description);
                 $tp->display('add_step_three.tpl');
             }
             break;
     }
 }
コード例 #14
0
ファイル: Statistics.php プロジェクト: Maxlander/shixi
 public static function getSalesStatistics($period, $filter, $sorting_field, $sorting_order)
 {
     $where = '';
     if (!empty($period['from'])) {
         $period['from'] = SJB_I18N::getInstance()->getInput('date', $period['from']);
         $time = "00:00:00";
         $where .= " AND s.`date` >= '{$period['from']} {$time}' ";
     }
     if (!empty($period['to'])) {
         $period['to'] = SJB_I18N::getInstance()->getInput('date', $period['to']);
         $time = "23:59:59";
         $where .= " AND s.`date` <= '{$period['to']} {$time}' ";
     }
     $join = '';
     $groupBy = '';
     $query = '';
     if (in_array($filter, array('Location_Country', 'Location_State', 'Location_City'))) {
         $fieldInfo = SJB_ListingFieldDBManager::getLocationFieldsInfoById($filter);
     } else {
         $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($filter);
     }
     if (strstr($filter, 'userGroup_')) {
         $userGroupSID = str_replace('userGroup_', '', $filter);
         $userGroupID = SJB_UserGroupManager::getUserGroupIDBySID($userGroupSID);
         $join = " INNER JOIN `users` u ON s.`user_sid` = u.`sid` ";
         $where .= " AND u.`user_group_sid` = '{$userGroupSID}'";
         $groupBy = " u.`sid`";
         $query = ', u.* ';
     } elseif (!empty($fieldInfo['type']) && $fieldInfo['type'] == 'list' && empty($fieldInfo['parent_sid'])) {
         $join = " INNER JOIN `users` u ON s.`user_sid` = u.`sid` INNER JOIN `user_profile_field_list` ufl ON u.`{$filter}` = ufl.`sid` ";
         $groupBy = " `{$filter}` ";
         $query = ", ufl.`value` as {$filter} ";
     } elseif (!empty($fieldInfo['type']) && $fieldInfo['type'] == 'list' && !empty($fieldInfo['parent_sid'])) {
         if ($filter == 'Location_Country') {
             $join = " INNER JOIN `users` u ON s.`user_sid` = u.`sid` INNER JOIN `countries` c ON u.`{$filter}` = c.`sid` ";
             $query = ", c.`country_name` as {$filter} ";
         } else {
             $join = " INNER JOIN `users` u ON s.`user_sid` = u.`sid` INNER JOIN `states` st ON u.`{$filter}` = st.`sid` ";
             $query = ", st.`state_name` as {$filter} ";
         }
         $groupBy = " `{$filter}` ";
     } elseif ($filter == 'sid') {
         $join = " INNER JOIN `products` p ON s.`object_sid` = p.`sid` ";
         $where .= " AND s.type = 'product' ";
         $groupBy = " s.`object_sid`, s.`featured`, s.`priority`, s.`reactivate` ";
         $query = ', p.* ';
     } else {
         $join = " INNER JOIN `users` u ON s.`user_sid` = u.`sid` ";
         $where .= " AND u.`{$filter}` != '' AND u.`{$filter}` IS NOT NULL ";
         $groupBy = " u.`{$filter}` ";
         $query = ', u.* ';
     }
     $orderBy = '';
     if ($sorting_field == 'username') {
         if (strstr($filter, 'userGroup_')) {
             if ($userGroupID == 'Employer') {
                 $orderBy = "ORDER BY `CompanyName` {$sorting_order}";
             } else {
                 $orderBy = "ORDER BY `FirstName`, `LastName` {$sorting_order}";
             }
         }
     } else {
         $orderBy = "ORDER BY {$sorting_field} {$sorting_order}";
     }
     $statisticsInfo = array();
     $total = $totalSum = SJB_DB::query("SELECT sum(s.`price`*s.`count`) as total, sum(s.`count`) as units_sold, 'Total' as totalSum, 0 as `sid` FROM `statistics` s {$join} WHERE s.`event` = 'payment' {$where}");
     $total = $total ? array_pop($total) : array('total' => 0);
     $percent = $total['total'] != 0 ? 100 / $total['total'] : 0;
     if ($filter == 'sid') {
         $statisticsInfo = SJB_DB::query("SELECT s.*, sum(s.`price`*s.`count`) as total, sum(s.`price`*s.`count`)*{$percent} as percent, sum(s.`count`) as units_sold {$query} \n\t\t\t\t\t\t\t\t\t\t\t\t FROM `statistics` s {$join} \n\t\t\t\t\t\t\t\t\t\t\t\t WHERE s.`event` = 'payment' {$where} \n\t\t\t\t\t\t\t\t\t\t\t\t GROUP BY {$groupBy} {$orderBy}");
     } else {
         $statisticsSIDs = SJB_DB::query("SELECT {$groupBy} as sid, sum(s.`price`*s.`count`) as total FROM `statistics` s {$join} WHERE s.`event` = 'payment' {$where} GROUP BY {$groupBy} ORDER BY total DESC LIMIT 10");
         foreach ($statisticsSIDs as $info) {
             $SIDs[] = "'" . $info['sid'] . "'";
         }
         if (isset($SIDs)) {
             $SIDs = implode(',', $SIDs);
             $statisticsInfo = SJB_DB::query("SELECT s.*, sum(s.`price`*s.`count`) as total, sum(s.`price`*s.`count`)*{$percent} as percent, sum(s.`count`) as units_sold {$query} \n\t\t\t\t\t\t\t\t\t\t\t\t FROM `statistics` s {$join} \n\t\t\t\t\t\t\t\t\t\t\t\t WHERE {$groupBy} in ({$SIDs}) AND s.`event` = 'payment' {$where} \n\t\t\t\t\t\t\t\t\t\t\t\t GROUP BY {$groupBy} {$orderBy}");
             $ohter = SJB_DB::query("SELECT s.*, sum(s.`price`*s.`count`) as total, sum(s.`price`*s.`count`)*{$percent} as percent, sum(s.`count`) as units_sold, 'Other' as other {$query} FROM `statistics` s {$join} WHERE {$groupBy} not in ({$SIDs}) AND s.`event` = 'payment' {$where}");
             if (!empty($ohter[0]['sid'])) {
                 $statisticsInfo = array_merge($statisticsInfo, $ohter);
             }
         }
     }
     $statisticsInfo = array_merge($statisticsInfo, $totalSum);
     $statistics = array();
     foreach ($statisticsInfo as $key => $statisticInfo) {
         if ($filter == 'sid') {
             $productInfo = SJB_ProductsManager::getProductInfoBySID($statisticInfo['sid']);
             $statisticInfo['product_type'] = SJB_ProductsManager::getProductTypeByID($productInfo['product_type']);
         }
         $statistics[$key] = $statisticInfo;
         if (isset($statisticInfo['other'])) {
             $statistics[$key]['generalColumn'] = 'Other';
         } elseif (isset($statisticInfo['totalSum'])) {
             $statistics[$key]['generalColumn'] = 'Total';
             $statistics[$key]['name'] = 'Total';
             $statistics[$key]['percent'] = '100%';
         } elseif (strstr($filter, 'userGroup_')) {
             if ($userGroupID == 'Employer') {
                 $statistics[$key]['generalColumn'] = !empty($statisticInfo['CompanyName']) ? $statisticInfo['CompanyName'] : $statisticInfo['username'];
             } else {
                 $statistics[$key]['generalColumn'] = !empty($statisticInfo['FirstName']) && !empty($statisticInfo['LastName']) ? $statisticInfo['FirstName'] . " " . $statisticInfo['LastName'] : $statisticInfo['username'];
             }
         } elseif ($filter == 'sid') {
             $statistics[$key]['generalColumn'] = $statisticInfo['name'];
         } else {
             $statistics[$key]['generalColumn'] = $statisticInfo[$filter];
         }
         $statistics[$key]['percent'] = round($statistics[$key]['percent'], 2);
         if ($statistics[$key]['percent'] == 99.98999999999999) {
             $statistics[$key]['percent'] = 100;
         }
     }
     return $statistics;
 }
コード例 #15
0
ファイル: RefineSearch.php プロジェクト: Maxlander/shixi
 public static function getCurrentSearchByCriteria($criteria)
 {
     $returnArray = array();
     $locationFields = SJB_ListingFieldManager::getFieldsInfoByType('location');
     foreach ($criteria as $fieldName => $field) {
         if (!in_array($fieldName, array('listing_type', 'active', 'username', 'status', 'CompanyName', 'keywords', 'PostedWithin', 'anonymous'))) {
             $result = array();
             $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($fieldName);
             if (!$fieldInfo) {
                 foreach ($locationFields as $locationField) {
                     $locationSubFields = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($locationField['sid']);
                     foreach ($locationSubFields as $locationSubField) {
                         if ($fieldName == $locationField['id'] . "_" . $locationSubField['id']) {
                             $fieldInfo = $locationSubField;
                             $fieldInfo['id'] = $locationField['id'] . "_" . $locationSubField['id'];
                         }
                     }
                 }
             }
             foreach ($field as $fieldType => $fieldValue) {
                 switch ($fieldType) {
                     case 'geo':
                         if ($fieldValue['location'] !== '') {
                             $result[$fieldName][$fieldType][$fieldValue['location']] = $fieldValue['location'];
                         }
                         break;
                     case 'location':
                         if (!empty($fieldValue['value'])) {
                             $result[$fieldName][$fieldType][$fieldValue['value']] = $fieldValue['value'];
                         }
                         break;
                     case 'monetary':
                         if (!empty($fieldValue['not_less']) && $fieldValue['not_less'] !== '') {
                             $result[$fieldName][$fieldType][$fieldValue['not_less']] = $fieldValue['not_less'];
                         }
                         if (!empty($fieldValue['not_more']) && $fieldValue['not_more'] !== '') {
                             $result[$fieldName][$fieldType][$fieldValue['not_more']] = $fieldValue['not_more'];
                         }
                         break;
                     case 'multi_like':
                         $listItem = new SJB_ListingFieldListItemManager();
                         if (is_array($fieldValue)) {
                             foreach ($fieldValue as $value) {
                                 if ($value !== '') {
                                     if ($fieldInfo['type'] == 'tree') {
                                         $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'");
                                         $name = $name ? $name : '';
                                         $result[$fieldName][$fieldType][$value] = $name;
                                     } elseif ($fieldInfo['type'] == 'multilist' || $fieldInfo['type'] == 'list') {
                                         if (!empty($fieldInfo['parent_sid'])) {
                                             if ($fieldInfo['id'] == $fieldInfo['parentID'] . '_State') {
                                                 $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $fieldInfo['display_as']);
                                             } else {
                                                 $listValues = $fieldInfo['list_values'];
                                             }
                                             foreach ($listValues as $listValue) {
                                                 if ($listValue['id'] == $value) {
                                                     $result[$fieldName][$fieldType][$value] = $listValue['caption'];
                                                     break;
                                                 }
                                             }
                                         } else {
                                             $itemInfo = $listItem->getListItemBySID($value);
                                             $caption = $itemInfo ? $itemInfo->getValue() : $value;
                                             $result[$fieldName][$fieldType][$value] = $caption;
                                         }
                                     } else {
                                         $result[$fieldName][$fieldType][$value] = $value;
                                     }
                                 }
                             }
                         } elseif ($fieldValue !== '') {
                             $itemInfo = $listItem->getListItemBySID($fieldValue);
                             $caption = $itemInfo ? $itemInfo->getValue() : $fieldValue;
                             $result[$fieldName][$fieldType][$fieldValue] = $caption;
                         }
                         break;
                     case 'tree':
                         $fieldValue = $fieldValue ? explode(',', $fieldValue) : "";
                         if (is_array($fieldValue)) {
                             foreach ($fieldValue as $value) {
                                 if ($value !== '') {
                                     $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'");
                                     $name = $name ? $name : '';
                                     $result[$fieldName][$fieldType][$value] = $name;
                                 }
                             }
                         }
                         break;
                     case 'multi_like_and':
                         if (is_array($fieldValue)) {
                             $listItem = new SJB_ListingFieldListItemManager();
                             foreach ($fieldValue as $value) {
                                 if ($value !== '') {
                                     if ($fieldInfo['type'] == 'tree') {
                                         $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'");
                                         $name = $name ? $name : '';
                                         $result[$fieldName][$fieldType][$value] = $name;
                                     } elseif ($fieldInfo['type'] == 'multilist' || $fieldInfo['type'] == 'list') {
                                         if (!empty($fieldInfo['parent_sid'])) {
                                             if ($fieldInfo['id'] == $fieldInfo['parentID'] . '_State') {
                                                 $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $fieldInfo['display_as']);
                                             } else {
                                                 $listValues = $fieldInfo['list_values'];
                                             }
                                             foreach ($listValues as $listValue) {
                                                 if ($listValue['id'] == $value) {
                                                     $result[$fieldName][$fieldType][$value] = $listValue['caption'];
                                                     break;
                                                 }
                                             }
                                         } else {
                                             $itemInfo = $listItem->getListItemBySID($value);
                                             $caption = $itemInfo ? $itemInfo->getValue() : $value;
                                             $result[$fieldName][$fieldType][$value] = $caption;
                                         }
                                     } else {
                                         $result[$fieldName][$fieldType][$value] = $value;
                                     }
                                 }
                             }
                         } elseif ($fieldValue !== '') {
                             $result[$fieldName][$fieldType][$fieldValue] = $fieldValue;
                         }
                         break;
                     default:
                         if (is_array($fieldValue)) {
                             foreach ($fieldValue as $value) {
                                 if ($value !== '') {
                                     $result[$fieldName][$fieldType][$value] = $value;
                                 }
                             }
                         } elseif ($fieldValue !== '') {
                             $result[$fieldName][$fieldType][$fieldValue] = $fieldValue;
                         }
                         break;
                 }
             }
             if ($result && !empty($fieldInfo)) {
                 $returnArray[$fieldInfo['id']]['name'] = $fieldInfo['caption'];
                 $returnArray[$fieldInfo['id']]['field'] = $result[$fieldInfo['id']];
             }
         } elseif ($fieldName == 'CompanyName') {
             $result = array();
             $userFieldSID = SJB_DB::queryValue("SELECT `sid` FROM `user_profile_fields` WHERE `id` = 'CompanyName'");
             if ($userFieldSID) {
                 $fieldInfo = SJB_UserProfileFieldManager::getFieldInfoBySID($userFieldSID);
                 foreach ($field as $fieldType => $fieldValue) {
                     switch ($fieldType) {
                         case 'multi_like_and':
                             if (is_array($fieldValue)) {
                                 foreach ($fieldValue as $value) {
                                     if ($value !== '') {
                                         $result[$fieldName][$fieldType][$value] = $value;
                                     }
                                 }
                             } elseif ($fieldValue !== '') {
                                 $result[$fieldName][$fieldType][$fieldValue] = $fieldValue;
                             }
                             break;
                     }
                 }
             }
             if ($result && !empty($fieldInfo)) {
                 $returnArray[$fieldInfo['id']]['name'] = $fieldInfo['caption'];
                 $returnArray[$fieldInfo['id']]['field'] = $result[$fieldInfo['id']];
             }
         } elseif ($fieldName == 'keywords') {
             foreach ($field as $key => $val) {
                 if ($val) {
                     $returnArray['keywords']['field'][$key][$val] = $val;
                 }
             }
             if (isset($returnArray['keywords'])) {
                 $returnArray['keywords']['name'] = 'Keywords';
             }
         }
     }
     return $returnArray;
 }