Example #1
0
 /**
  * Returns Listing object by id 
  *
  * @param int $listing_sid
  * @return SJB_Listing
  */
 public static function getObjectBySID($listing_sid)
 {
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_sid);
     $listing = null;
     if (!is_null($listing_info)) {
         $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
         $listing->setSID($listing_sid);
         $listing->setUserSID($listing_info['user_sid']);
         $productInfo = !empty($listing_info['product_info']) ? unserialize($listing_info['product_info']) : array();
         $listing->setProductInfo($productInfo);
     }
     return $listing;
 }
Example #2
0
 public function execute()
 {
     $listing_id = SJB_Request::getVar('listing_id', null);
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id);
     $field_id = SJB_Request::getVar('field_id', null);
     $current_user_sid = SJB_UserManager::getCurrentUserSID();
     $owner_sid = SJB_ListingManager::getUserSIDByListingSID($listing_id);
     $errors = array();
     $complexEmun = SJB_Request::getVar('complexEnum', null, 'GET');
     $complexFieldID = SJB_Request::getVar('complexParent', null, 'GET');
     if (!is_null($complexEmun) && !is_null($complexFieldID)) {
         $fieldArr = array();
         array_push($fieldArr, $complexFieldID);
         array_push($fieldArr, $field_id);
         array_push($fieldArr, $complexEmun);
         $field_id = $complexFieldID . ':' . $field_id . $complexEmun . '_' . $listing_id;
     } else {
         $fieldArr = explode(':', $field_id);
         $complexEmun = isset($fieldArr[2]) ? explode('_', $fieldArr[2]) : false;
         $complexEmun = $complexEmun ? $complexEmun[0] : false;
     }
     if (is_null($listing_id) || is_null($field_id)) {
         $errors['PARAMETERS_MISSED'] = 1;
     } else {
         if (is_null($listing_info) || $complexEmun === false || !isset($listing_info[$fieldArr[0]][$fieldArr[1]][$complexEmun])) {
             $errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
         } else {
             if ($owner_sid != $current_user_sid) {
                 $errors['NOT_OWNER'] = 1;
             } else {
                 $uploaded_file_id = $listing_info[$fieldArr[0]][$fieldArr[1]][$complexEmun];
                 SJB_UploadFileManager::deleteUploadedFileByID($uploaded_file_id);
                 $listing_info[$field_id] = '';
                 $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
                 $props = $listing->getProperties();
                 foreach ($props as $prop) {
                     if ($prop->getID() !== $field_id) {
                         $listing->deleteProperty($prop->getID());
                     }
                 }
                 $listing->setSID($listing_id);
                 SJB_ListingManager::saveListing($listing);
             }
         }
     }
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('errors', $errors);
     $tp->assign('listing_id', $listing_id);
     $tp->display('delete_uploaded_file.tpl');
 }
Example #3
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listing_types = SJB_ListingTypeManager::getAllListingTypesInfo();
     $countListings = array();
     foreach ($listing_types as $type) {
         $requested_data = array();
         $requested_data['action'] = 'search';
         $requested_data['active']['equal'] = '1';
         $requested_data['listing_type']['equal'] = $type['id'];
         $requireApprove = SJB_ListingTypeManager::getWaitApproveSettingByListingType($type['sid']);
         if ($requireApprove) {
             $requested_data['status']['equal'] = 'approved';
         }
         $listing = new SJB_Listing(array(), $type['sid']);
         $id_alias_info = $listing->addIDProperty();
         $listing->addActivationDateProperty();
         $username_alias_info = $listing->addUsernameProperty();
         $listing_type_id_info = $listing->addListingTypeIDProperty();
         $listing->addCompanyNameProperty();
         if ($type['id'] == 'Resume') {
             $requested_data['access_type'] = array('accessible' => SJB_UserManager::getCurrentUserSID());
         }
         $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($requested_data, $listing);
         $aliases = new SJB_PropertyAliases();
         $aliases->addAlias($id_alias_info);
         $aliases->addAlias($username_alias_info);
         $aliases->addAlias($listing_type_id_info);
         $searcher = new SJB_ListingSearcher();
         $countListings[$type['id']] = $searcher->countRowsByCriteria($criteria, $aliases);
     }
     $tp->assign('listings_types', $countListings);
     $tp->display('count_listings.tpl');
 }
Example #4
0
 private function getListingSidCollectionFromRequest($requested_data, $listing_type_sid, $criteria_saver)
 {
     $listing = new SJB_Listing(array(), $listing_type_sid);
     $id_alias_info = $listing->addIDProperty();
     $listing->addActivationDateProperty();
     $username_alias_info = $listing->addUsernameProperty();
     $listing_type_id_info = $listing->addListingTypeIDProperty();
     $listing->addCompanyNameProperty();
     // select only accessible listings by user sid
     // see SearchCriterion.php, AccessibleCriterion class
     $requested_data['access_type'] = array('accessible' => SJB_UserManager::getCurrentUserSID());
     $criteria = $criteria_saver->getCriteria();
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData(array_merge($criteria, $requested_data), $listing);
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias($id_alias_info);
     $aliases->addAlias($username_alias_info);
     $aliases->addAlias($listing_type_id_info);
     $sortingFields = array();
     $orderInfo = $criteria_saver->getOrderInfo();
     $property = $listing->getProperty($orderInfo['sorting_field']);
     if (!empty($property) && $property->isSystem()) {
         $sortingFields = array('priority' => 'desc', $orderInfo['sorting_field'] => $orderInfo['sorting_order']);
     }
     $searcher = new SJB_ListingSearcher();
     return $searcher->getObjectsSIDsByCriteria($criteria, $aliases, $sortingFields);
 }
Example #5
0
 public function execute()
 {
     $listing_id = SJB_Request::getVar('listing_id', null);
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id);
     $listingTypeSID = SJB_ListingTypeManager::getListingTypeIDBySID($listing_info['listing_type_sid']);
     $field_id = SJB_Request::getVar('field_id', null);
     $current_user_sid = SJB_UserManager::getCurrentUserSID();
     $owner_sid = SJB_ListingManager::getUserSIDByListingSID($listing_id);
     $errors = array();
     if (is_null($listing_id) || is_null($field_id)) {
         $errors['PARAMETERS_MISSED'] = 1;
     } else {
         if (is_null($listing_info) || !isset($listing_info[$field_id])) {
             $errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
         } else {
             if ($owner_sid != $current_user_sid) {
                 $errors['NOT_OWNER'] = 1;
             } else {
                 $uploaded_file_id = $listing_info[$field_id];
                 SJB_UploadFileManager::deleteUploadedFileByID($uploaded_file_id);
                 $listing_info[$field_id] = '';
                 $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
                 $props = $listing->getProperties();
                 foreach ($props as $prop) {
                     if ($prop->getID() !== $field_id) {
                         $listing->deleteProperty($prop->getID());
                     }
                 }
                 $listing->setSID($listing_id);
                 SJB_ListingManager::saveListing($listing);
             }
         }
     }
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('errors', $errors);
     $tp->assign('listing_id', $listing_id);
     $tp->assign('listingTypeSID', $listingTypeSID);
     $tp->display('delete_uploaded_file.tpl');
 }
Example #6
0
 public function execute()
 {
     $listing_id = SJB_Request::getVar('listing_id', null);
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id);
     $listingTypeInfo = SJB_ListingTypeManager::getListingTypeInfoBySID($listing_info['listing_type_sid']);
     $field_id = SJB_Request::getVar('field_id', null);
     if (is_null($listing_id) || is_null($field_id)) {
         $errors['PARAMETERS_MISSED'] = 1;
     } elseif (is_null($listing_info) || !isset($listing_info[$field_id])) {
         $errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
     } else {
         $uploaded_file_id = $listing_info[$field_id];
         SJB_UploadFileManager::deleteUploadedFileByID($uploaded_file_id);
         $listing_info[$field_id] = '';
         $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
         $listing->setSID($listing_id);
         SJB_ListingManager::saveListing($listing);
     }
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('errors', isset($errors) ? $errors : null);
     $tp->assign('listing_id', $listing_id);
     $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
     $tp->display('delete_uploaded_file.tpl');
 }
Example #7
0
 public static function createListing($listing_type_id)
 {
     $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
     $listing = new SJB_Listing(array(), $listing_type_sid);
     $listing->addUsernameProperty();
     $listing->addListingTypeIDProperty();
     $listing->addActivationDateProperty();
     $listing->addExpirationDateProperty();
     return $listing;
 }
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $listingTypeSID = 0;
     if (isset($_REQUEST['passed_parameters_via_uri'])) {
         $params = SJB_FixedUrlParamProvider::getParams($_REQUEST);
         if ($params) {
             $listingTypeID = array_pop($params);
             $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
         }
     }
     if (!$listingTypeSID) {
         $errors['WRONG_LISTING_TYPE_ID_SPECIFIED'] = true;
     } else {
         $listing = new SJB_Listing(array(), $listingTypeSID);
         $listing->addIDProperty();
         $listing->addActivationDateProperty();
         $listing->addUsernameProperty();
         $listing->addKeywordsProperty();
         $listing->addPicturesProperty();
         $listing->addListingTypeIDProperty();
         $listing->addPostedWithinProperty();
         $listingTypeID = SJB_ListingTypeManager::getListingTypeIDBySID($listing->listing_type_sid);
         $display_form = new SJB_Form($listing);
         $display_form->registerTags($tp);
         $form_fields = $display_form->getFormFieldsInfo();
         $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
         $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
         $tp->assign('METADATA', array('listing' => $metaDataProvider->getMetaData($listing_structure['METADATA']), 'form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
         $tp->assign('form_fields', $form_fields);
         $tp->filterThenAssign('listing', $listing_structure);
         $formBuilder = SJB_FormBuilderManager::getFormBuilder(SJB_FormBuilderManager::FORM_BUILDER_TYPE_DISPLAY, $listingTypeID);
         $formBuilder->setChargedTemplateProcessor($tp);
         $tp->assign('listingTypeInfo', SJB_ListingTypeManager::getListingTypeInfoBySID($listingTypeSID));
         $tp->assign('currentTheme', SJB_TemplateSupplier::getUserCurrentTheme());
     }
     $tp->assign('errors', $errors);
     $tp->display('bf_displaylisting.tpl');
 }
Example #9
0
 private function CreateListing($listing_info, $listing_type_id)
 {
     $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
     $listing = new SJB_Listing($listing_info, $listing_type_sid);
     $userInfo = array();
     if (!empty($listing_info['extUserID'])) {
         $userInfo = SJB_UserManager::getUserInfoByExtUserID($listing_info['extUserID'], $listing_type_id);
         if ($userInfo) {
             $listing->setUserSID($userInfo['sid']);
         }
     }
     if (!$userInfo && !empty($listing_info['username'])) {
         $userInfo = SJB_UserManager::getUserInfoByUserName($listing_info['username']);
         $listing->setUserSID($userInfo['sid']);
     }
     return $listing;
 }
Example #10
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     if (isset($_REQUEST['listing_type_id'])) {
         $listing_type_id = $_REQUEST['listing_type_id'];
         SJB_Session::setValue('listing_type_id', $listing_type_id);
     } elseif (isset($_REQUEST['restore'])) {
         $listing_type_id = SJB_Session::getValue('listing_type_id');
     } else {
         SJB_Session::setValue('listing_type_id', null);
     }
     $listing_type_sid = 0;
     if (!empty($listing_type_id)) {
         $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
     }
     if (!isset($_REQUEST['listing_type']['equal']) && isset($listing_type_id)) {
         $_REQUEST['listing_type']['equal'] = $listing_type_id;
     }
     if (isset($_REQUEST['searchId'])) {
         $criteria_saver = new SJB_ListingCriteriaSaver($_REQUEST['searchId']);
         $_REQUEST = array_merge($_REQUEST, $criteria_saver->getCriteria());
     }
     $empty_listing = new SJB_Listing(array(), $listing_type_sid);
     $empty_listing->addIDProperty();
     $empty_listing->addActivationDateProperty();
     $empty_listing->addUsernameProperty();
     $empty_listing->addKeywordsProperty();
     $empty_listing->addPicturesProperty();
     $empty_listing->addListingTypeIDProperty();
     $empty_listing->addPostedWithinProperty();
     $search_form_builder = new SJB_SearchFormBuilder($empty_listing);
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST);
     $properties = $empty_listing->getProperties();
     foreach ($properties as $propertyName => $property) {
         if ($property->getType() == 'location') {
             $propertyInfo = $property->type->property_info;
             if ($propertyInfo['enable_search_by_radius'] == 1) {
                 if (!isset($criteria['system'][$propertyName])) {
                     $value = array('value' => '', 'radius' => '10');
                     $criterion = SJB_SearchCriterion::getCriterionByType('location');
                     $criterion->setProperty($property);
                     $criterion->setPropertyName($propertyName);
                     $criterion->setValue($value);
                     $criteria['system'][$propertyName][] = $criterion;
                 }
             }
         }
     }
     $search_form_builder->setCriteria($criteria);
     $search_form_builder->registerTags($tp);
     $form_fields = $search_form_builder->getFormFieldsInfo();
     $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
     $template = SJB_Request::getVar('form_template', 'search_form.tpl');
     $formBuilder = SJB_FormBuilderManager::getFormBuilder(SJB_FormBuilderManager::FORM_BUILDER_TYPE_SEARCH, $listing_type_id);
     $formBuilder->setChargedTemplateProcessor($tp);
     if ($template == 'quick_search.tpl') {
         $fieldSID = SJB_ListingFieldManager::getListingFieldSIDByID('Location');
         if ($fieldSID) {
             $fields = SJB_ListingFieldManager::getFieldInfoBySID($fieldSID);
             if (!empty($fields['fields'])) {
                 foreach ($fields['fields'] as $field) {
                     $form_fields[$fields['id'] . '_' . $field['id']] = $field;
                 }
             }
             $tp->assign('locationFields', array($fields));
         }
     }
     $tp->assign('form_fields', $form_fields);
     $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
     $tp->display($template);
 }
Example #11
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $current_user = SJB_UserManager::getCurrentUser();
     $currentUserInfo = SJB_UserManager::getCurrentUserInfo();
     $tp->assign('current_user', $currentUserInfo);
     $errors = array();
     $error = '';
     $listing_id = SJB_Request::getVar('listing_id', null, 'default', 'int');
     if (SJB_UserGroupManager::getUserGroupIDBySID($current_user->user_group_sid) == 'Employer') {
         $template = SJB_Request::getVar('input_template', 'copy_listing.tpl');
     } else {
         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-listings/Job/');
     }
     //getting $tmp_listing_id from request
     $tmp_listing_id_from_request = SJB_Request::getVar('tmp_listing_id', false, 'default', 'int');
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id);
     $listing_type_id = SJB_ListingTypeManager::getListingTypeIDBySID($listing_info['listing_type_sid']);
     if ($productsInfo = $this->canCurrentUserAddListing($error, $listing_type_id)) {
         $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listing_info['listing_type_sid']);
         if (!empty($tmp_listing_id_from_request)) {
             $tmp_listing_sid = $tmp_listing_id_from_request;
         } elseif (!$tmp_listing_id_from_request) {
             $tmp_listing_sid = time();
         }
         $gallery = new SJB_ListingGallery();
         $gallery->setListingSID($listing_info['sid']);
         $pictures_info = $gallery->getPicturesInfo();
         $gallery->setListingSID($tmp_listing_sid);
         $pictures_info_new = $gallery->getPicturesInfo();
         //reuploading pictures
         if (!$pictures_info_new) {
             foreach ($pictures_info as $v) {
                 if (!$gallery->uploadImage($v['picture_url'], $v['caption'])) {
                     $field_errors['Picture'] = $gallery->getError();
                 }
             }
         }
         $contractID = SJB_Request::getVar('contract_id', false, 'default', 'int');
         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('listing_id', $listing_id);
             $tp->assign("products_info", $productsInfo);
             $tp->assign("listing_type_id", $listing_type_id);
             $tp->display("listing_product_choice.tpl");
         }
         if ($contractID) {
             $tp->assign('tmp_listing_id', $tmp_listing_sid);
             $extraInfo = $contract->extra_info;
             $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
             $tp->assign("pic_limit", $numberOfPictures);
             $tp->assign('contractID', $contractID);
             if ($listing_info['user_sid'] != SJB_UserManager::getCurrentUserSID()) {
                 $errors['NOT_OWNER_OF_LISTING'] = $listing_id;
             } elseif (!is_null($listing_info)) {
                 $listing_info = array_merge($listing_info, $_REQUEST);
                 $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
                 $listing->deleteProperty('featured');
                 $listing->deleteProperty('priority');
                 $listing->deleteProperty('status');
                 $listing->deleteProperty('reject_reason');
                 $listing->setSID($listing_id);
                 $screening_questionnaires = SJB_ScreeningQuestionnaires::getList($current_user->getSID());
                 if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) {
                     $issetQuestionnairyField = $listing->getProperty('screening_questionnaire');
                     if ($issetQuestionnairyField) {
                         $value = SJB_Request::getVar('screening_questionnaire');
                         $value = $value ? $value : isset($listing_info['screening_questionnaire']) ? $listing_info['screening_questionnaire'] : '';
                         $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($current_user->getSID()), 'is_system' => true));
                     }
                 } else {
                     $listing->deleteProperty('screening_questionnaire');
                 }
                 $listing_edit_form = new SJB_Form($listing);
                 $listing_edit_form->registerTags($tp);
                 $extraInfo = $listing_info['product_info'];
                 if ($extraInfo) {
                     $extraInfo = unserialize($extraInfo);
                     $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
                     $tp->assign("pic_limit", $numberOfPictures);
                 }
                 $form_is_submitted = isset($_REQUEST['action']) && $_REQUEST['action'] == 'save_info' || isset($_REQUEST['action']) && $_REQUEST['action'] == 'add';
                 $listing->addProperty(array('id' => 'contract_id', 'type' => 'id', 'value' => $contractID, 'is_system' => true));
                 $delete = SJB_Request::getVar('action', '') == 'delete';
                 $field_errors = null;
                 if ($delete && isset($_REQUEST['field_id'])) {
                     $field_id = $_REQUEST['field_id'];
                     $listing->details->properties[$field_id]->type->property_info['value'] = null;
                 } elseif ($form_is_submitted && $listing_edit_form->isDataValid($field_errors)) {
                     $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                     $listing->setUserSID($current_user->getSID());
                     $extraInfo = $contract->extra_info;
                     $listing->setProductInfo($extraInfo);
                     $listing->sid = null;
                     if (!empty($listing_info['subuser_sid'])) {
                         $listing->addSubuserProperty($listing_info['subuser_sid']);
                     }
                     $listingSidsForCopy = array('filesFrom' => $listing_id, 'picturesFrom' => $tmp_listing_sid);
                     SJB_ListingManager::saveListing($listing, $listingSidsForCopy);
                     // >>> SJB-1197
                     // SET VALUES FROM TEMPORARY SESSION STORAGE
                     $formToken = SJB_Request::getVar('form_token');
                     $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage');
                     $tempFieldsData = SJB_Array::getPath($sessionFileStorage, $formToken);
                     if (is_array($tempFieldsData)) {
                         foreach ($tempFieldsData as $fieldId => $fieldData) {
                             $isComplex = false;
                             if (strpos($fieldId, ':') !== false) {
                                 $isComplex = true;
                             }
                             $tmpUploadedFileId = $fieldData['file_id'];
                             // rename it to real listing field value
                             $newFileId = $fieldId . "_" . $listing->getSID();
                             SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                             if ($isComplex) {
                                 list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                                 $parentProp = $listing->getProperty($parentField);
                                 $parentValue = $parentProp->getValue();
                                 // look for complex property with current $fieldID and set it to new value of property
                                 if (!empty($parentValue)) {
                                     foreach ($parentValue as $id => $value) {
                                         if ($id == $subField) {
                                             $parentValue[$id][$complexStep] = $newFileId;
                                         }
                                     }
                                     $listing->setPropertyValue($parentField, $parentValue);
                                 }
                             } else {
                                 $listing->setPropertyValue($fieldId, $newFileId);
                             }
                             // clean temporary field storage
                             $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}/{$fieldId}");
                         }
                         //and remove token key from temporary storage
                         $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}");
                         // clear temporary data in session storage
                         SJB_Session::setValue('tmp_uploads_storage', $sessionFileStorage);
                         $listingSidsForCopy = array('filesFrom' => $listing_id, 'picturesFrom' => $listing_id);
                         SJB_ListingManager::saveListing($listing, $listingSidsForCopy);
                     }
                     // <<< SJB-1197
                     SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $extraInfo['featured'], $extraInfo['priority']);
                     $contract->incrementPostingsNumber();
                     SJB_ProductsManager::incrementPostingsNumber($contract->product_sid);
                     // is listing featured by default
                     if ($extraInfo['featured']) {
                         SJB_ListingManager::makeFeaturedBySID($listing->getSID());
                     }
                     if ($extraInfo['priority']) {
                         SJB_ListingManager::makePriorityBySID($listing->getSID());
                     }
                     SJB_ListingManager::activateListingBySID($listing->getSID());
                     SJB_AdminNotifications::sendAdminListingAddedLetter($listing);
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-' . strtolower($listing_type_id) . '/?listing_id=' . $listing->getSID());
                 } elseif ($form_is_submitted) {
                     $field_id = 'video';
                     if (!isset($_REQUEST['video_hidden']) && $listing->getPropertyValue($field_id)) {
                         $listing->details->properties[$field_id]->type->property_info['value'] = null;
                     }
                 }
                 $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
                 $form_fields = $listing_edit_form->getFormFieldsInfo();
                 $listing_fields_by_page = array();
                 $countPages = count($pages);
                 $i = 1;
                 foreach ($pages as $page) {
                     $listing_fields_by_page[$page['page_name']] = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']);
                     if ($i == $countPages && isset($form_fields['screening_questionnaire'])) {
                         $listing_fields_by_page[$page['page_name']]['screening_questionnaire'] = $form_fields['screening_questionnaire'];
                     }
                     foreach (array_keys($listing_fields_by_page[$page['page_name']]) as $field) {
                         if (!$listing->propertyIsSet($field)) {
                             unset($listing_fields_by_page[$page['page_name']][$field]);
                         }
                     }
                     $i++;
                 }
                 $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
                 $tp->assign('METADATA', array('listing' => $metaDataProvider->getMetaData($listing_structure['METADATA']), 'form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
                 $contract_id = $listing_info['contract_id'];
                 $contract = new SJB_Contract(array('contract_id' => $contract_id));
                 $tp->assign('contract_id', $contract_id);
                 $tp->assign('contract', $contract->extra_info);
                 $tp->assign('countPages', count($listing_fields_by_page));
                 $tp->assign('copy_listing', 1);
                 $tp->assign('tmp_listing_id', $tmp_listing_sid);
                 $tp->assign('listing_id', $listing_id);
                 $tp->assign('contractID', $contractID);
                 $tp->assign('listing', $listing_structure);
                 $tp->assign('pages', $listing_fields_by_page);
                 $tp->assign('field_errors', $field_errors);
             }
             $tp->assign('errors', $errors);
             $tp->display($template);
         }
     } else {
         $listing_type_id = isset($listing_info['listing_type_sid']) ? $listing_info['listing_type_sid'] : false;
         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('clone_job', 1);
         $tp->assign('listing_type_id', $listing_type_id);
         $tp->assign('error', $error);
         $tp->display('add_listing_error.tpl');
     }
 }
Example #12
0
 public function execute()
 {
     $formToken = SJB_Request::getVar('form_token');
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('form_token', $formToken);
     $post_max_size_orig = ini_get('post_max_size');
     $server_content_length = isset($_SERVER['CONTENT_LENGTH']) ? $_SERVER['CONTENT_LENGTH'] : null;
     // get post_max_size in bytes
     $val = trim($post_max_size_orig);
     $tmp = substr($val, strlen($val) - 1);
     $tmp = strtolower($tmp);
     switch ($tmp) {
         case 'g':
             $val *= 1024;
             break;
         case 'm':
             $val *= 1024;
             break;
         case 'k':
             $val *= 1024;
             break;
     }
     $post_max_size = $val;
     $errors = array();
     if (SJB_Request::getVar('from-preview', false, 'POST') && !SJB_Request::getVar('action_add', false, 'POST')) {
         $listingId = SJB_Request::getVar('listing_id', null, 'GET', 'int');
         $previewListingId = SJB_Session::getValue('preview_listing_sid');
         if ($previewListingId && SJB_ListingManager::isListingExists($previewListingId)) {
             $listingId = $previewListingId;
         }
     } else {
         $listingId = SJB_Request::getVar('listing_id', null, 'default', 'int');
     }
     $template = SJB_Request::getVar('edit_template', 'edit_listing.tpl');
     $filename = SJB_Request::getVar('filename', false);
     if ($filename) {
         SJB_UploadFileManager::openFile($filename, $listingId);
         // if file not found - set error here
         $errors['NO_SUCH_FILE'] = true;
     }
     if (empty($_POST) && $server_content_length > $post_max_size) {
         $errors['MAX_FILE_SIZE_EXCEEDED'] = 1;
         $listingId = SJB_Request::getVar('listing_id', null, 'GET', 'int');
         $tp->assign('post_max_size', $post_max_size_orig);
     }
     $current_user = SJB_UserManager::getCurrentUser();
     $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
     // for listing preview
     $formSubmittedFromPreview = false;
     if (empty($listingInfo)) {
         $listingId = SJB_Session::getValue('preview_listing_sid');
         $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
         if (!empty($listingInfo)) {
             // if on preview page 'POST' button was pressed
             $formSubmittedFromPreview = SJB_Request::getVar('action_add', false, 'POST') && SJB_Request::getVar('from-preview', false, 'POST');
             if ($formSubmittedFromPreview) {
                 $listing = new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']);
                 $properties = $listing->getProperties();
                 foreach ($properties as $fieldID => $property) {
                     switch ($property->getType()) {
                         case 'date':
                             if (!empty($listingInfo[$fieldID])) {
                                 $listingInfo[$fieldID] = SJB_I18N::getInstance()->getDate($listingInfo[$fieldID]);
                             }
                             break;
                         case 'complex':
                             $complex = $property->type->complex;
                             $complexProperties = $complex->getProperties();
                             foreach ($complexProperties as $complexfieldID => $complexProperty) {
                                 if ($complexProperty->getType() == 'date') {
                                     $values = $complexProperty->getValue();
                                     foreach ($values as $index => $value) {
                                         if (!empty($listingInfo[$fieldID][$complexfieldID][$index])) {
                                             $listingInfo[$fieldID][$complexfieldID][$index] = SJB_I18N::getInstance()->getDate($listingInfo[$fieldID][$complexfieldID][$index]);
                                         }
                                     }
                                 }
                             }
                             break;
                     }
                 }
             }
         } else {
             $listingId = null;
             SJB_Session::unsetValue('preview_listing_sid');
         }
     }
     // if preview button was pressed
     $isPreviewListingRequested = SJB_Request::getVar('preview_listing', false, 'POST');
     if (SJB_UserManager::isUserLoggedIn()) {
         if ($listingInfo['user_sid'] != $current_user->getID()) {
             $errors['NOT_OWNER_OF_LISTING'] = $listingId;
         } elseif (!is_null($listingInfo)) {
             $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listingInfo['listing_type_sid']);
             $form_is_submitted = SJB_Request::getVar('action', '') == 'save_info' || SJB_Request::getVar('action', '') == 'add' || $isPreviewListingRequested || $formSubmittedFromPreview;
             if (!$form_is_submitted && !SJB_Request::getVar('from-preview', false, 'POST')) {
                 SJB_Session::unsetValue('previewListingId');
                 SJB_Session::unsetValue('preview_listing_sid_or');
             }
             // fill listing from an array of social data if allowed
             $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($listingInfo['listing_type_sid']);
             $listingTypeID = $listing_type_info['id'];
             $aAutoFillData = array('formSubmitted' => $form_is_submitted, 'listingTypeID' => $listingTypeID);
             SJB_Event::dispatch('SocialSynchronization', $aAutoFillData);
             $listingInfo = array_merge($listingInfo, $_REQUEST);
             $listing = new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']);
             $listing->deleteProperty('ListingLogo');
             $listing->deleteProperty('featured');
             $listing->deleteProperty('priority');
             $listing->deleteProperty('reject_reason');
             $listing->deleteProperty('status');
             $list_emp_ids = SJB_Request::getVar('list_emp_ids');
             $listing->setSID($listingId);
             $screening_questionnaires = SJB_ScreeningQuestionnaires::getList($current_user->getSID());
             if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) {
                 $value = SJB_Request::getVar('screening_questionnaire');
                 $value = $value ? $value : isset($listingInfo['screening_questionnaire']) ? $listingInfo['screening_questionnaire'] : '';
                 $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($current_user->getSID()), 'is_system' => true));
             } else {
                 $listing->deleteProperty('screening_questionnaire');
             }
             //--->CLT-2637
             $properties = $listing->getProperties();
             $listing_fields_by_page = array();
             foreach ($pages as $page) {
                 $listing_fields_by_page = array_merge(SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']), $listing_fields_by_page);
             }
             foreach ($properties as $property) {
                 if (!in_array($property->getID(), array_keys($listing_fields_by_page))) {
                     $listing->deleteProperty($property->getID());
                 }
             }
             //--->CLT-2637
             // if user is not registered using linkedin , delete linkedin sync property, also if sync is turned off in admin part
             $aAutoFillData = array('oListing' => &$listing, 'userSID' => $current_user->getSID(), 'listingTypeID' => $listingTypeID, 'listing_info' => $listingInfo);
             SJB_Event::dispatch('SocialSynchronizationFields', $aAutoFillData);
             $listing_edit_form = new SJB_Form($listing);
             $listing_edit_form->registerTags($tp);
             $extraInfo = $listingInfo['product_info'];
             if ($extraInfo) {
                 $extraInfo = unserialize($extraInfo);
                 $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
                 $listingSidForPictures = SJB_Session::getValue('preview_listing_sid_or') ? SJB_Session::getValue('preview_listing_sid_or') : $listingId;
                 $tp->assign('pic_limit', $numberOfPictures);
                 $tp->assign('listingSidForPictures', $listingSidForPictures);
             }
             if ($form_is_submitted) {
                 $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar('list_emp_ids'), 'is_system' => true));
             }
             $field_errors = array();
             if ($form_is_submitted && ($formSubmittedFromPreview || $listing_edit_form->isDataValid($field_errors))) {
                 $or_listing_id = SJB_Session::getValue('preview_listing_sid_or');
                 /* preview listing */
                 if ($isPreviewListingRequested && SJB_Session::getValue('preview_listing_sid') != $listing->getSID()) {
                     SJB_Session::setValue('preview_listing_sid_or', $listing->getSID());
                     $listing->setSID(null);
                 } elseif (!$isPreviewListingRequested && SJB_Session::getValue('preview_listing_sid') == $listing->getSID() && $or_listing_id && $or_listing_id != $listingId) {
                     $listing->setSID($or_listing_id);
                 }
                 if ($isPreviewListingRequested) {
                     $listing->addProperty(array('id' => 'preview', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 } else {
                     $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 }
                 if ($isPreviewListingRequested) {
                     $listing->product_info = $extraInfo;
                     if (SJB_Session::getValue('previewListingId')) {
                         $listing->setSID(SJB_Session::getValue('previewListingId'));
                     }
                 } else {
                     SJB_BrowseDBManager::deleteListings($listing->getID());
                 }
                 $listingSidsForCopy = array('filesFrom' => $listingId, 'picturesFrom' => $isPreviewListingRequested && (!$or_listing_id || $or_listing_id === $listingId) ? $listingId : null);
                 SJB_ListingManager::saveListing($listing, $listingSidsForCopy);
                 if (!$isPreviewListingRequested && SJB_Session::getValue('preview_listing_sid') == $listingId && $or_listing_id && $or_listing_id != $listingId) {
                     SJB_Session::unsetValue('preview_listing_sid');
                     SJB_ListingManager::deleteListingBySID($listingId);
                 }
                 $listingInfo = SJB_ListingManager::getListingInfoBySID($listing->getSID());
                 if ($listingInfo['active']) {
                     SJB_ListingManager::activateListingKeywordsBySID($listing->getSID());
                     SJB_BrowseDBManager::addListings($listing->getID());
                 }
                 // >>> SJB-1197
                 // SET VALUES FROM TEMPORARY SESSION STORAGE
                 $formToken = SJB_Request::getVar('form_token');
                 $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage');
                 $tempFieldsData = SJB_Array::getPath($sessionFileStorage, $formToken);
                 if (is_array($tempFieldsData)) {
                     foreach ($tempFieldsData as $fieldId => $fieldData) {
                         $isComplex = false;
                         if (strpos($fieldId, ':') !== false) {
                             $isComplex = true;
                         }
                         $tmpUploadedFileId = $fieldData['file_id'];
                         // rename it to real listing field value
                         $newFileId = $fieldId . "_" . $listing->getSID();
                         SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                         if ($isComplex) {
                             list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                             $parentProp = $listing->getProperty($parentField);
                             $parentValue = $parentProp->getValue();
                             // look for complex property with current $fieldID and set it to new value of property
                             if (!empty($parentValue)) {
                                 foreach ($parentValue as $id => $value) {
                                     if ($id == $subField) {
                                         $parentValue[$id][$complexStep] = $newFileId;
                                     }
                                 }
                                 $listing->setPropertyValue($parentField, $parentValue);
                             }
                         } else {
                             $listing->setPropertyValue($fieldId, $newFileId);
                         }
                     }
                     SJB_ListingManager::saveListing($listing);
                     // recreate form object for saved listing
                     // it fix display of complex file fields
                     $listing = SJB_ListingManager::getObjectBySID($listing->getSID());
                     $listing->deleteProperty('featured');
                     $listing->deleteProperty('priority');
                     $listing->deleteProperty('reject_reason');
                     $listing->deleteProperty('status');
                     $listing_edit_form = new SJB_Form($listing);
                     $listing_edit_form->registerTags($tp);
                 }
                 // <<< SJB-1197
                 if ($isPreviewListingRequested) {
                     SJB_Session::setValue('previewListingId', $listing->getSID());
                 }
                 /* preview listing */
                 if ($isPreviewListingRequested) {
                     $listing->setUserSID($current_user->getSID());
                     SJB_Session::setValue('preview_listing_sid', $listing->getSID());
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/' . strtolower($listingTypeID) . '-preview/' . $listing->getSID() . '/');
                 } else {
                     /* normal */
                     $listingSid = $listing->getSID();
                     SJB_Event::dispatch('listingEdited', $listingSid);
                     $tp->assign('display_preview', 1);
                     SJB_Session::unsetValue('preview_listing_sid');
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-' . strtolower($listingTypeID) . '-details/' . $listing->getSID() . '/');
                 }
             }
             $listing->deleteProperty('access_list');
             $tp->assign('form_is_submitted', $form_is_submitted);
             $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
             $form_fields = $listing_edit_form->getFormFieldsInfo();
             $listing_fields_by_page = array();
             foreach ($pages as $page) {
                 $listing_fields_by_page[$page['page_name']] = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']);
                 foreach (array_keys($listing_fields_by_page[$page['page_name']]) as $field) {
                     if (!$listing->propertyIsSet($field)) {
                         unset($listing_fields_by_page[$page['page_name']][$field]);
                     }
                 }
             }
             // delete sync fields from posting pages that are not in array $form_fields
             $aAutoFillData = array('listing_fields_by_page' => &$listing_fields_by_page, 'pages' => &$pages, 'form_fields' => $form_fields);
             SJB_Event::dispatch('SocialSynchronizationFieldsOnPostingPages', $aAutoFillData);
             $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
             $tp->assign('METADATA', array('listing' => $metaDataProvider->getMetaData($listing_structure['METADATA']), 'form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
             if (!isset($listing_structure['access_type'])) {
                 $listing_structure['access_type'] = 'everyone';
             }
             $listing_access_list = SJB_ListingManager::getListingAccessList($listingId, $listing->getPropertyValue('access_type'));
             $tp->assign('contract_id', $listingInfo['contract_id']);
             $tp->assign('extraInfo', $extraInfo);
             $tp->assign('listing', $listing_structure);
             $tp->assign('pages', $listing_fields_by_page);
             $tp->assign('countPages', count($listing_fields_by_page));
             $tp->assign('field_errors', $field_errors);
             $tp->assign('listing_access_list', $listing_access_list);
             $tp->assign('listingTypeID', $listingTypeID);
             $tp->assign('expired', SJB_ListingManager::getIfListingHasExpiredBySID($listing->getSID()));
             // only for Resume listing types
             $aAutoFillData = array('tp' => &$tp, 'listingTypeID' => $listingTypeID, 'userSID' => $current_user->getSID());
             SJB_Event::dispatch('SocialSynchronizationForm', $aAutoFillData);
         }
     } else {
         $errors['NOT_LOGGED_IN'] = 1;
     }
     $tp->assign('errors', $errors);
     $tp->display($template);
 }
Example #13
0
 /**
  * Returns sortable properties by listing
  * @return array
  */
 private function getSortableProperties()
 {
     $emptyListing = new SJB_Listing(array(), $this->listingTypeSID);
     $emptyListing->addPicturesProperty();
     $emptyListing->addIDProperty();
     $emptyListing->addListingTypeIDProperty();
     $emptyListing->addActivationDateProperty();
     $emptyListing->addNumberOfViewsProperty();
     $emptyListing->addApplicationsProperty();
     $emptyListing->addSubuserProperty();
     $emptyListing->addActiveProperty();
     $emptyListing->addExpirationDateProperty(null);
     $sortableProperties = array();
     $propertyList = $emptyListing->getPropertyList();
     foreach ($propertyList as $property) {
         $sortableProperties[$property]['is_sortable'] = true;
     }
     return $sortableProperties;
 }
Example #14
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listingTypeID = SJB_Request::getVar('listing_type_id', null);
     $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
     $listingTypeInfo = SJB_ListingTypeManager::getListingTypeInfoBySID($listingTypeSID);
     $productSID = SJB_Request::getVar('product_sid', false);
     $editUser = SJB_Request::getVar('edit_user', false);
     $action = SJB_Request::getVar('action', false);
     $username = SJB_Request::getVar('username', false);
     $errors = array();
     if ($username && ($userSID = SJB_UserManager::getUserSIDbyUsername($username))) {
         $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
         $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userInfo['user_group_sid']);
         if (!$productSID) {
             $products = SJB_ProductsManager::getProductsInfoByUserGroupSID($userGroupInfo['sid']);
             foreach ($products as $key => $product) {
                 if (empty($product['listing_type_sid']) || $product['listing_type_sid'] != $listingTypeSID) {
                     unset($products[$key]);
                 }
             }
             if ($action == 'productVerify') {
                 $errors['PRODUCT_NOT_SELECTED'] = 1;
             }
             $tp->assign('errors', $errors);
             $tp->assign('username', $username);
             $tp->assign('products', $products);
             $tp->assign('edit_user', $editUser);
             $tp->assign('userSID', $userSID);
             $tp->assign('userGroupInfo', $userGroupInfo);
             $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
             $tp->display('select_product.tpl');
         } else {
             $form_submitted = SJB_Request::getVar('action', '') == 'add';
             $tmp_listing_id_from_request = SJB_Request::getVar('listing_id', false, 'default', 'int');
             if (!empty($tmp_listing_id_from_request)) {
                 $tmp_listing_sid = $tmp_listing_id_from_request;
             } elseif (!$tmp_listing_id_from_request) {
                 $tmp_listing_sid = time();
             }
             $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
             $extraInfo = is_null($productInfo['serialized_extra_info']) ? null : unserialize($productInfo['serialized_extra_info']);
             if (!empty($extraInfo)) {
                 $extraInfo['product_sid'] = $productSID;
             }
             $_REQUEST['featured'] = !empty($_REQUEST['featured']) ? $_REQUEST['featured'] : $productInfo['featured'];
             $_REQUEST['priority'] = !empty($_REQUEST['priority']) ? $_REQUEST['priority'] : $productInfo['priority'];
             $listing = new SJB_Listing($_REQUEST, $listingTypeSID);
             $properties = $listing->getPropertyList();
             foreach ($properties as $property) {
                 $propertyInfo = $listing->getPropertyInfo($property);
                 $propertyInfo['user_sid'] = $userSID;
                 if ($propertyInfo['type'] == 'location') {
                     $child = $listing->getChild($property);
                     $childProperties = $child->getPropertyList();
                     foreach ($childProperties as $childProperty) {
                         $childPropertyInfo = $child->getPropertyInfo($childProperty);
                         $childPropertyInfo['user_sid'] = $userSID;
                         $child->setPropertyInfo($childProperty, $childPropertyInfo);
                     }
                 }
                 $listing->setPropertyInfo($property, $propertyInfo);
             }
             $listing->deleteProperty('status');
             $listing->deleteProperty('reject_reason');
             $access_type = $listing->getProperty('access_type');
             if ($form_submitted) {
                 if (!empty($access_type)) {
                     $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar("list_emp_ids"), 'is_system' => true));
                 }
             }
             $screening_questionnaires = SJB_ScreeningQuestionnaires::getList($userSID);
             if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) {
                 $issetQuestionnairyField = $listing->getProperty('screening_questionnaire');
                 if ($issetQuestionnairyField) {
                     $value = SJB_Request::getVar("screening_questionnaire");
                     $listing_info = $_REQUEST;
                     $value = $value ? $value : isset($listing_info['screening_questionnaire']) ? $listing_info['screening_questionnaire'] : '';
                     $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($userSID), 'is_system' => true));
                 }
             } else {
                 $listing->deleteProperty('screening_questionnaire');
             }
             if ($listing->getProperty('captcha')) {
                 $listing->deleteProperty('captcha');
             }
             $add_listing_form = new SJB_Form($listing);
             $add_listing_form->registerTags($tp);
             $field_errors = array();
             if ($form_submitted && $add_listing_form->isDataValid($field_errors)) {
                 $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 $listing->setUserSID($userSID);
                 $listing->setProductInfo($extraInfo);
                 if (empty($access_type->value)) {
                     $listing->setPropertyValue('access_type', 'everyone');
                 }
                 SJB_ListingManager::saveListing($listing);
                 SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $_REQUEST['featured'], $_REQUEST['priority'], $userSID);
                 if (isset($_SESSION['tmp_file_storage'])) {
                     foreach ($_SESSION['tmp_file_storage'] as $v) {
                         SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `picture_saved_name` = ?s", $listing->getSID(), $v['picture_saved_name']);
                         SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `thumb_saved_name` = ?s", $listing->getSID(), $v['thumb_saved_name']);
                     }
                     SJB_Session::unsetValue('tmp_file_storage');
                 }
                 $formToken = SJB_Request::getVar('form_token');
                 $sessionFilesStorage = SJB_Session::getValue('tmp_uploads_storage');
                 $uploadedFields = SJB_Array::getPath($sessionFilesStorage, $formToken);
                 if (!empty($uploadedFields)) {
                     foreach ($uploadedFields as $fieldId => $fieldValue) {
                         // get field of listing
                         $isComplex = false;
                         if (strpos($fieldId, ':') !== false) {
                             $isComplex = true;
                         }
                         $tmpUploadedFileId = $fieldValue['file_id'];
                         // rename it to real listing field value
                         $newFileId = $fieldId . "_" . $listing->getSID();
                         SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                         if ($isComplex) {
                             list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                             $parentProp = $listing->getProperty($parentField);
                             $parentValue = $parentProp->getValue();
                             // look for complex property with current $fieldID and set it to new value of property
                             if (!empty($parentValue)) {
                                 foreach ($parentValue as $id => $value) {
                                     if ($id == $subField) {
                                         $parentValue[$id][$complexStep] = $newFileId;
                                     }
                                 }
                                 $listing->setPropertyValue($parentField, $parentValue);
                             }
                         } else {
                             $listing->setPropertyValue($fieldId, $newFileId);
                         }
                         // unset value from session temporary storage
                         $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}/{$fieldId}");
                     }
                     //and remove token key from temporary storage
                     $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}");
                     SJB_Session::setValue('tmp_uploads_storage', $sessionFilesStorage);
                     SJB_ListingManager::saveListing($listing);
                 }
                 SJB_ListingManager::activateListingBySID($listing->getSID());
                 SJB_ProductsManager::incrementPostingsNumber($productSID);
                 $listingSid = $listing->getSID();
                 SJB_Event::dispatch('listingSaved', $listingSid);
                 if ($editUser) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-user/?user_sid=" . $userSID);
                 } else {
                     if ($listingTypeID == 'resume' || $listingTypeID == 'job') {
                         $link = "manage-" . strtolower($listingTypeID) . "s";
                     } else {
                         $link = "manage-" . strtolower($listingTypeID) . "-listings";
                     }
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/{$link}/?action=search&listing_type_sid=" . $listingTypeSID);
                 }
             } else {
                 $listing->deleteProperty('access_list');
                 $listing->deleteProperty('contract_id');
                 $add_listing_form = new SJB_Form($listing);
                 if ($form_submitted) {
                     $add_listing_form->isDataValid($field_errors);
                 }
                 $add_listing_form->registerTags($tp);
                 $form_fields = $add_listing_form->getFormFieldsInfo();
                 $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listingTypeSID);
                 $formFieldsSorted = array();
                 $formFieldsSorted['featured'] = $form_fields['featured'];
                 $formFieldsSorted['priority'] = $form_fields['priority'];
                 foreach ($pages as $page) {
                     $listing_fields = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']);
                     foreach (array_keys($listing_fields) as $field) {
                         if ($listing->propertyIsSet($field)) {
                             $formFieldsSorted[$field] = $form_fields[$field];
                         }
                     }
                 }
                 $form_fields = $formFieldsSorted;
                 //SJB_HelperFunctions::d($form_fields);
                 $employers_list = SJB_Request::getVar('list_emp_ids', false);
                 $employers = array();
                 if (is_array($employers_list)) {
                     foreach ($employers_list as $emp) {
                         $currEmp = SJB_UserManager::getUserInfoBySID($emp);
                         $employers[] = array('user_id' => $emp, 'value' => $currEmp['CompanyName']);
                     }
                     sort($employers);
                 }
                 $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
                 $tp->assign("pic_limit", $numberOfPictures);
                 $tp->assign("listing_id", $tmp_listing_sid);
                 $tp->assign("listing_access_list", $employers);
                 $tp->assign("errors", $field_errors);
                 $tp->assign("form_fields", $form_fields);
                 $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
                 $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields)));
             }
             $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
             $tp->assign('edit_user', $editUser);
             $tp->assign('productInfo', $productInfo);
             $tp->assign('username', $username);
             $tp->assign('product_sid', $productSID);
             $tp->assign('userSID', $userSID);
             $tp->assign('userGroupInfo', $userGroupInfo);
             $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
             $tp->display('input_form.tpl');
         }
     } else {
         if ($username && !$userSID) {
             $errors['USER_NOT_FOUND'] = 1;
         } elseif ($action == 'userVerify') {
             $errors['USER_NOT_SELECTED'] = 1;
         }
         $tp->assign('errors', $errors);
         $tp->assign('username', $username);
         $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
         $tp->display('select_user.tpl');
     }
 }
Example #15
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listing_type_id = SJB_Request::getVar('listing_type_id', false);
     $action = SJB_Request::getVar('action', false);
     $type = SJB_Request::getVar('type', false);
     $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8');
     $supportedFormats = array('xlsx', 'xls', 'csv');
     $warning = false;
     $error = '';
     if ($action == 'example' && $type) {
         $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
         $listing_field_manager = new SJB_ListingFieldManager();
         $common_details = $listing_field_manager->getCommonListingFieldsInfo();
         $extra_details = $listing_field_manager->getListingFieldsInfoByListingType($listing_type_sid);
         $listing_fields = array_merge($common_details, $extra_details);
         $directory_to_export = SJB_System::getSystemSettings('EXPORT_FILES_DIRECTORY');
         $export_properties = array();
         $export_data = array();
         foreach ($listing_fields as $listing_field) {
             $export_properties[$listing_field['id']] = $listing_field['id'];
             $export_data[0][$listing_field['id']] = '';
         }
         SJB_ExportController::createExportDirectoriesForExample();
         switch ($type) {
             case 'exl':
                 SJB_ExportController::makeExportFile($export_data, 'example.xls');
                 $export_files_dir = SJB_Path::combine($directory_to_export, 'example.xls');
                 for ($i = 0; $i < ob_get_level(); $i++) {
                     ob_end_clean();
                 }
                 header('Content-type: application/vnd.ms-excel');
                 header('Content-disposition: attachment; filename=example.xls');
                 header('Content-Length: ' . filesize($export_files_dir));
                 readfile($export_files_dir);
                 break;
             case 'csv':
                 $export_files_dir = SJB_Path::combine($directory_to_export, 'example.csv');
                 $fp = fopen($export_files_dir, 'w');
                 fputcsv($fp, explode(',', implode(',', $export_properties)));
                 fclose($fp);
                 for ($i = 0; $i < ob_get_level(); $i++) {
                     ob_end_clean();
                 }
                 header('Content-type: application/vnd.ms-excel');
                 header('Content-disposition: attachment; filename=example.csv');
                 header('Content-Length: ' . filesize($export_files_dir));
                 readfile($export_files_dir);
                 break;
         }
         SJB_Filesystem::delete($directory_to_export);
         exit;
     }
     if ($productsInfo = $this->canCurrentUserAddListing($error)) {
         $acl = SJB_Acl::getInstance();
         if ($acl->isAllowed('bulk_job_import') == true) {
             $fileInfo = null;
             if (isset($_FILES['import_file'])) {
                 $extension = strtolower(substr(strrchr($_FILES['import_file']['name'], '.'), 1));
                 if (empty($_FILES['import_file']['name']) || !in_array($extension, $supportedFormats)) {
                     $warning = 'Please choose Excel or csv file';
                 } else {
                     $fileInfo = $_FILES['import_file'];
                 }
             }
             $contractID = SJB_Request::getVar('contract_id', false);
             $current_user = SJB_UserManager::getCurrentUser();
             if ($contractID) {
                 $contract = new SJB_Contract(array('contract_id' => $contractID));
             } elseif (count($productsInfo) == 1) {
                 $productInfo = array_pop($productsInfo);
                 $contractID = $productInfo['contract_id'];
                 $contract = new SJB_Contract(array('contract_id' => $contractID));
             } else {
                 $tp->assign("products_info", $productsInfo);
                 $tp->assign("listing_type_id", $listing_type_id);
                 $tp->display("listing_product_choice.tpl");
             }
             if ($contractID && $listing_type_id) {
                 $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
                 if ($fileInfo) {
                     switch ($extension) {
                         case 'xls':
                         case 'xlsx':
                             $import_file = new SJB_ImportFileXLS($fileInfo);
                             break;
                         case 'csv':
                             $import_file = new SJB_ImportFileCSV($fileInfo, ',');
                             break;
                     }
                     $import_file->parse($encodingFromCharset);
                     $bulkPermissionParam = $this->acl->getPermissionParams('post_' . $listing_type_id, $contract->getID(), 'contract');
                     $imported_data = $import_file->getData();
                     $countData = 0;
                     foreach ($imported_data as $val) {
                         if ($val) {
                             $countData++;
                         }
                     }
                     if (empty($bulkPermissionParam) || $bulkPermissionParam - $contract->getPostingsNumber() - ($countData - 1) >= 0) {
                         $listing = new SJB_Listing(array(), $listing_type_sid);
                         $count = 0;
                         $listingSIDs = array();
                         foreach ($imported_data as $key => $importedColumn) {
                             if ($key == 1) {
                                 $imported_data_processor = new SJB_ImportedDataProcessor($importedColumn, $listing);
                                 continue;
                             }
                             if (!$importedColumn) {
                                 continue;
                             }
                             $count++;
                             $listing_info = $imported_data_processor->getData('ignore', $importedColumn);
                             $doc = new DOMDocument();
                             foreach ($listing->getProperties() as $property) {
                                 if ($property->getType() == 'complex' && !empty($listing_info[$property->id])) {
                                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                                     $doc->loadXML($listing_info[$property->id]);
                                     $results = $doc->getElementsByTagName($property->id . 's');
                                     $listing_info[$property->id] = array();
                                     foreach ($results as $complexparent) {
                                         $i = 0;
                                         foreach ($complexparent->getElementsByTagName($property->id) as $result) {
                                             $resultXML = simplexml_import_dom($result);
                                             foreach ($childFields as $childField) {
                                                 if (isset($resultXML->{$childField}['id'])) {
                                                     $listing_info[$property->id][$childField['id']][$i] = (string) $resultXML->{$childField}['id'];
                                                 }
                                             }
                                             $i++;
                                         }
                                     }
                                 } elseif ($property->getType() == 'location') {
                                     $locationFields = array($property->id . '.Country', $property->id . '.State', $property->id . '.City', $property->id . '.ZipCode');
                                     $locationFieldAdded = array();
                                     foreach ($locationFields as $locationField) {
                                         if (array_key_exists($locationField, $listing_info)) {
                                             switch ($locationField) {
                                                 case $property->id . '.Country':
                                                     $value = SJB_CountriesManager::getCountrySIDByCountryName($listing_info[$locationField]);
                                                     if (!$value) {
                                                         $value = SJB_CountriesManager::getCountrySIDByCountryCode($listing_info[$locationField]);
                                                     }
                                                     break;
                                                 case $property->id . '.State':
                                                     $value = SJB_StatesManager::getStateSIDByStateName($listing_info[$locationField]);
                                                     if (!$value) {
                                                         $value = SJB_StatesManager::getStateSIDByStateCode($listing_info[$locationField]);
                                                     }
                                                     break;
                                                 default:
                                                     $value = $listing_info[$locationField];
                                                     break;
                                             }
                                             $listing_info[$property->id][str_replace($property->id . '.', '', $locationField)] = $value;
                                             $locationFieldAdded[] = str_replace($property->id . '.', '', $locationField);
                                         }
                                     }
                                     if ($property->id == 'Location') {
                                         $locationFields = array('Country', 'State', 'City', 'ZipCode');
                                         foreach ($locationFields as $locationField) {
                                             if (array_key_exists($locationField, $listing_info) && !in_array($locationField, $locationFieldAdded) && !$listing->getProperty($locationField)) {
                                                 switch ($locationField) {
                                                     case 'Country':
                                                         $value = SJB_CountriesManager::getCountrySIDByCountryName($listing_info[$locationField]);
                                                         if (!$value) {
                                                             $value = SJB_CountriesManager::getCountrySIDByCountryCode($listing_info[$locationField]);
                                                         }
                                                         break;
                                                     case 'State':
                                                         $value = SJB_StatesManager::getStateSIDByStateName($listing_info[$locationField]);
                                                         if (!$value) {
                                                             $value = SJB_StatesManager::getStateSIDByStateCode($listing_info[$locationField]);
                                                         }
                                                         break;
                                                     default:
                                                         $value = $listing_info[$locationField];
                                                         break;
                                                 }
                                                 $listing_info[$property->id][$locationField] = $value;
                                             }
                                         }
                                     }
                                 }
                             }
                             $field_info = null;
                             $listing = new SJB_Listing($listing_info, $listing_type_sid);
                             foreach ($listing->getProperties() as $property) {
                                 if ($property->getType() == 'tree' && $property->value !== '') {
                                     $treeValues = explode(',', $property->value);
                                     $treeSIDs = array();
                                     foreach ($treeValues as $treeValue) {
                                         $info = SJB_ListingFieldTreeManager::getItemInfoByCaption($property->sid, trim($treeValue));
                                         $treeSIDs[] = $info['sid'];
                                     }
                                     $listing->setPropertyValue($property->id, implode(',', $treeSIDs));
                                     $listing->details->properties[$property->id]->type->property_info['value'] = implode(',', $treeSIDs);
                                 } elseif ($property->getType() == 'monetary') {
                                     $currency = SJB_CurrencyManager::getDefaultCurrency();
                                     $listing->details->properties[$property->id]->type->property_info['value']['add_parameter'] = $currency['sid'];
                                 } elseif ($property->id == 'ApplicationSettings' && !empty($listing_info['ApplicationSettings'])) {
                                     if (preg_match("^[a-z0-9\\._-]+@[a-z0-9\\._-]+\\.[a-z]{2,}\$^iu", $listing_info['ApplicationSettings'])) {
                                         $listing_info['ApplicationSettings'] = array('value' => $listing_info['ApplicationSettings'], 'add_parameter' => 1);
                                     } elseif (preg_match("^(https?:\\/\\/)^iu", $listing_info['ApplicationSettings'])) {
                                         $listing_info['ApplicationSettings'] = array('value' => $listing_info['ApplicationSettings'], 'add_parameter' => 2);
                                     } else {
                                         $listing_info['ApplicationSettings'] = array('value' => '', 'add_parameter' => '');
                                     }
                                     $listing->details->properties[$property->id]->type->property_info['value'] = $listing_info['ApplicationSettings'];
                                 } elseif ($property->getType() == 'complex' && is_array($property->value)) {
                                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                                     $complexChildValues = $property->value;
                                     foreach ($childFields as $childField) {
                                         if ($childField['type'] == 'complexfile' && !empty($complexChildValues[$childField['id']])) {
                                             $field_info = SJB_ListingComplexFieldManager::getFieldInfoBySID($childField['sid']);
                                             if (isset($listing_info[$property->id][$field_info['id']]) && file_exists($listing_info[$property->id][$field_info['id']])) {
                                                 SJB_UploadFileManager::fileImport($listing_info, $field_info, $property->id);
                                             }
                                         }
                                     }
                                 }
                                 // The import of files at import of listings
                                 if (in_array($property->getType(), array('file', 'logo', 'picture', 'video')) && $property->value !== '') {
                                     $field_info = SJB_ListingFieldDBManager::getListingFieldInfoByID($property->id);
                                     if (isset($listing_info[$field_info['id']]) && file_exists($listing_info[$field_info['id']])) {
                                         SJB_UploadFileManager::fileImport($listing_info, $field_info);
                                     }
                                 }
                             }
                             $listing->deleteProperty('featured');
                             $listing->deleteProperty('priority');
                             $listing->deleteProperty('status');
                             $listing->deleteProperty('reject_reason');
                             $listing->addProperty(array('id' => 'contract_id', 'type' => 'id', 'value' => $contract->getID(), 'is_system' => true));
                             $extraInfo = $contract->extra_info;
                             $listing->setProductInfo($extraInfo);
                             $listing->setPropertyValue('access_type', 'everyone');
                             $listing->setUserSID($current_user->sid);
                             if ($current_user->isSubuser()) {
                                 $subuserInfo = $current_user->getSubuserInfo();
                                 $listing->addSubuserProperty($subuserInfo['sid']);
                             }
                             SJB_ListingManager::saveListing($listing);
                             SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $extraInfo['featured'], $extraInfo['priority']);
                             $contract->incrementPostingsNumber();
                             SJB_ProductsManager::incrementPostingsNumber($contract->product_sid);
                             if (!empty($extraInfo['featured'])) {
                                 SJB_ListingManager::makeFeaturedBySID($listing->getSID());
                             }
                             if (!empty($extraInfo['priority'])) {
                                 SJB_ListingManager::makePriorityBySID($listing->getSID());
                             }
                             $this->FillGallery($listing, $listing_info);
                             $listingSIDs[] = $listing->getSID();
                         }
                         SJB_ListingManager::activateListingBySID($listingSIDs);
                         $tp->assign('listingsNum', count($listingSIDs));
                         $tp->display('job_import_complete.tpl');
                     } else {
                         $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
                         $error = 'LISTINGS_NUMBER_LIMIT_EXCEEDED';
                         $tp->assign('listing_type_id', $listing_type_id);
                         $tp->assign('error', $error);
                         $tp->display('job_import.tpl');
                     }
                 } else {
                     $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
                     $tp->assign('warning', $warning);
                     $tp->assign('contract_id', $contractID);
                     $tp->assign('listing_type_id', $listing_type_id);
                     $tp->display('job_import.tpl');
                 }
             }
         } else {
             $error = $acl->getPermissionMessage('bulk_job_import');
             if (empty($error)) {
                 $error = 'This action is not allowed within your current product';
             }
             $tp->assign('error', $error);
             $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
             $tp->assign('listing_type_id', $listing_type_id);
             $tp->display('job_import.tpl');
         }
     } else {
         if ($error == 'NO_CONTRACT') {
             if ($_GET) {
                 $getParam = '?';
                 foreach ($_GET as $key => $val) {
                     $getParam .= $key . '=' . $val . '&';
                 }
                 $getParam = substr($getParam, 0, -1);
             }
             $page = base64_encode(SJB_System::getURI() . $getParam);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-products/?page=' . $page);
         }
         $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
         $tp->assign('listing_type_id', $listing_type_id);
         $tp->assign('error', $error);
         $tp->display('job_import.tpl');
     }
 }
Example #16
0
 private function sendSearchedNotifications()
 {
     $savedSearches = SJB_SavedSearches::getAutoNotifySavedSearches();
     $listing = new SJB_Listing();
     $this->notifiedSavedSearchesSID = array();
     $notificationsLimit = (int) SJB_Settings::getSettingByName('num_of_listings_sent_in_email_alerts');
     foreach ($savedSearches as $savedSearch) {
         $searcher = new SJB_ListingSearcher();
         $listing->addActivationDateProperty();
         $dataSearch = unserialize($savedSearch['data']);
         $dataSearch['active']['equal'] = 1;
         $dateArray = explode('-', $savedSearch['last_send']);
         $savedSearch['last_send'] = strftime($this->lang['date_format'], mktime(0, 0, 0, $dateArray[1], $dateArray[2], $dateArray[0]));
         $dataSearch['activation_date']['not_less'] = $savedSearch['last_send'];
         $dataSearch['activation_date']['not_more'] = $this->currentDate;
         $listingTypeSID = 0;
         if ($dataSearch['listing_type']['equal']) {
             $listingTypeID = $dataSearch['listing_type']['equal'];
             $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
             if (SJB_ListingTypeManager::getWaitApproveSettingByListingType($listingTypeSID)) {
                 $dataSearch['status']['equal'] = 'approved';
             }
         }
         $idAliasInfo = $listing->addIDProperty();
         $usernameAliasInfo = $listing->addUsernameProperty();
         $listingTypeIDInfo = $listing->addListingTypeIDProperty();
         $aliases = new SJB_PropertyAliases();
         $aliases->addAlias($idAliasInfo);
         $aliases->addAlias($usernameAliasInfo);
         $aliases->addAlias($listingTypeIDInfo);
         $dataSearch['access_type'] = array('accessible' => $savedSearch['user_sid']);
         $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($dataSearch, $listing);
         $searcher->found_object_sids = array();
         $searcher->setLimit($notificationsLimit);
         $foundListingsIDs = $searcher->getObjectsSIDsByCriteria($criteria, $aliases);
         if (count($foundListingsIDs)) {
             $savedSearch['activation_date'] = $savedSearch['last_send'];
             if (SJB_Notifications::sendUserNewListingsFoundLetter($foundListingsIDs, $savedSearch['user_sid'], $savedSearch, $listingTypeSID)) {
                 SJB_Statistics::addStatistics('sentAlert', $listingTypeSID, $savedSearch['sid']);
                 SJB_DB::query('UPDATE `saved_searches` SET `last_send` = CURDATE() WHERE `sid` = ?n', $savedSearch['sid']);
             }
             $this->notifiedSavedSearchesSID[] = $savedSearch['sid'];
         }
     }
 }
Example #17
0
 /**
  * @param SJB_Listing $object
  * @param array $aFieldAssoc
  * @return void
  */
 public function fillOutListingData_Object(SJB_Listing &$object, $aFieldAssoc)
 {
     foreach ($aFieldAssoc as $propertyID => $value) {
         // checking if such property exists in listing
         if (!$object->getProperty($propertyID) instanceof SJB_ObjectProperty) {
             continue;
         }
         if ('tree' == $object->getProperty($propertyID)->getType()) {
             if (!empty($value['tree'])) {
                 $object->setPropertyValue($propertyID, $value['tree']);
             }
         } elseif (is_string($value) && strcmp($object->getPropertyValue($propertyID), $value) !== 0) {
             $object->setPropertyValue($propertyID, $value);
         } elseif (is_array($value)) {
             foreach ($value as $fieldID => $fieldValue) {
                 if ('complex' == $object->getProperty($propertyID)->getType()) {
                     if ('date' == $object->getProperty($propertyID)->type->complex->getProperty($fieldID)->getType()) {
                         foreach ($fieldValue as &$date) {
                             $date = !empty($date) ? SJB_I18N::getInstance()->getDate($date) : '';
                         }
                     }
                     $object->getProperty($propertyID)->type->complex->setPropertyValue($fieldID, $fieldValue);
                 } else {
                     $value = $value[0];
                     $object->setPropertyValue($propertyID, $value);
                 }
             }
         }
     }
 }
Example #18
0
 function _getEmptyListing()
 {
     $listing = new SJB_Listing(array(), $this->listing_type_sid);
     $listing->addPicturesProperty();
     $listing->addIDProperty();
     $listing->addListingTypeIDProperty();
     $listing->addActivationDateProperty();
     $listing->addUsernameProperty();
     $listing->addCompanyNameProperty();
     $listing->addFeaturedProperty();
     $listing->addFeaturedLastShowedProperty();
     return $listing;
 }
Example #19
0
 public function execute()
 {
     $listing_id = SJB_Request::getVar('listing_id', null);
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id);
     $listingTypeInfo = SJB_ListingTypeManager::getListingTypeInfoBySID($listing_info['listing_type_sid']);
     if (!is_null($listing_info)) {
         $filename = SJB_Request::getVar('filename', false);
         if ($filename) {
             $file = SJB_UploadFileManager::openFile($filename, $listing_id);
             $errors['NO_SUCH_FILE'] = true;
         }
         if (isset($_REQUEST['Occupations']) && isset($_REQUEST['Occupations']['tree']) && !$_REQUEST['Occupations']['tree']) {
             unset($_REQUEST['Occupations']['tree']);
         }
         $listing_info = array_merge($listing_info, $_REQUEST);
         if (isset($_REQUEST['Occupations']) && isset($_REQUEST['Occupations']['tree']) && $_REQUEST['Occupations']['tree']) {
             $listing_info['Occupations'] = $_REQUEST['Occupations']['tree'];
         }
         $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
         $listing->setSID($listing_id);
         $listing_edit_form = new SJB_Form($listing);
         $form_is_submitted = SJB_Request::getVar('action');
         $errors = array();
         if ($form_is_submitted) {
             $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar('list_emp_ids'), 'is_system' => true));
         }
         if ($form_is_submitted && $listing_edit_form->isDataValid($errors)) {
             $listingSid = $listing->getID();
             SJB_BrowseDBManager::deleteListings($listingSid);
             SJB_ListingManager::saveListing($listing);
             SJB_BrowseDBManager::addListings($listingSid);
             $formToken = SJB_Request::getVar('form_token');
             $sessionFilesStorage = SJB_Session::getValue('tmp_uploads_storage');
             $uploadedFields = SJB_Array::getPath($sessionFilesStorage, $formToken);
             if (!empty($uploadedFields)) {
                 foreach ($uploadedFields as $fieldId => $fieldValue) {
                     // get field of listing
                     $isComplex = false;
                     if (strpos($fieldId, ':') !== false) {
                         $isComplex = true;
                     }
                     $tmpUploadedFileId = $fieldValue['file_id'];
                     // rename it to real listing field value
                     $newFileId = $fieldId . "_" . $listing->getSID();
                     SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                     if ($isComplex) {
                         list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                         $parentProp = $listing->getProperty($parentField);
                         $parentValue = $parentProp->getValue();
                         // look for complex property with current $fieldID and set it to new value of property
                         if (!empty($parentValue)) {
                             foreach ($parentValue as $id => $value) {
                                 if ($id == $subField) {
                                     $parentValue[$id][$complexStep] = $newFileId;
                                 }
                             }
                             $listing->setPropertyValue($parentField, $parentValue);
                         }
                     } else {
                         $listing->setPropertyValue($fieldId, $newFileId);
                     }
                     // unset value from session temporary storage
                     $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}/{$fieldId}");
                 }
                 //and remove token key from temporary storage
                 $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}");
                 SJB_Session::setValue('tmp_uploads_storage', $sessionFilesStorage);
                 SJB_ListingManager::saveListing($listing);
             }
             SJB_Event::dispatch('listingEdited', $listingSid);
             if (SJB_Request::isAjax()) {
                 echo '<p class="green">Listing Saved</p>';
                 exit;
             }
             if ($form_is_submitted == 'save_info') {
                 $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listing_info['listing_type_sid']);
                 $listingType = $listingTypeId != 'Job' && $listingTypeId != 'Resume' ? $listingTypeId . '-listings' : $listingTypeId . 's';
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/manage-" . strtolower($listingType) . "/?restore=1");
             }
         }
         $listing->deleteProperty('access_list');
         $comments = SJB_CommentManager::getEnabledCommentsToListing($listing_id);
         $comments_total = count($comments);
         $rate = SJB_Rating::getRatingNumToListing($listing_id);
         $form_fields = $listing_edit_form->getFormFieldsInfo();
         $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listing->getListingTypeSID());
         $realFormFields = array();
         foreach ($pages as $page) {
             $listingFields = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']);
             foreach ($listingFields as $fieldID => $listingField) {
                 if (isset($form_fields[$fieldID])) {
                     $realFormFields[$fieldID] = $form_fields[$fieldID];
                 }
             }
         }
         $adminFields = array();
         foreach ($form_fields as $fieldName => $field) {
             if (!isset($realFormFields[$fieldName])) {
                 $adminFields[$fieldName] = $field;
             }
         }
         $realFormFields = array_merge($adminFields, $realFormFields);
         $tp = SJB_System::getTemplateProcessor();
         $listing_edit_form->registerTags($tp);
         $extraInfo = $listing_info['product_info'];
         if ($extraInfo) {
             $extraInfo = unserialize($extraInfo);
             $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
             $tp->assign("listing_duration", $extraInfo['listing_duration']);
             $tp->assign("pic_limit", $numberOfPictures);
         }
         $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
         if (!isset($listing_structure['access_type'])) {
             $listing_structure['access_type'] = 'everyone';
         }
         $listing_access_list = SJB_ListingManager::getListingAccessList($listing_id, $listing->getPropertyValue('access_type'));
         $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
         $tp->assign('form_fields', $realFormFields);
         $tp->assign('listing', $listing_structure);
         $tp->assign('errors', $errors);
         $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
         $tp->assign('listing_access_list', $listing_access_list);
         $tp->assign('comments_total', $comments_total);
         $tp->assign('rate', $rate);
         $tp->assign('expired', SJB_ListingManager::getIfListingHasExpiredBySID($listing->getSID()));
         SJB_System::setGlobalTemplateVariable('wikiExtraParam', $listingTypeInfo['id']);
         $tp->display('edit_listing.tpl');
     }
 }
Example #20
0
 /**
  * @param SJB_Listing $listing
  * @param string $network
  * @param int $value
  */
 public static function addSyncDetails(SJB_Listing $listing, $network, $value = 0)
 {
     $listing->addProperty(array('id' => $network . '_sync', 'caption' => 'Periodically synchronize my resume with my ' . $network . ' profile', 'type' => 'boolean', 'is_required' => false, 'is_system' => true, 'value' => $value));
 }
Example #21
0
 /**
  * @param $listingSID
  * @param $contractID
  * @param $productSID
  */
 public function addListing($listingSID, $contractID = false, $productSID = false)
 {
     if ($productSID != false) {
         $extraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productSID);
         $extraInfo['product_sid'] = (string) $extraInfo['product_sid'];
     } else {
         $contract = new SJB_Contract(array('contract_id' => $contractID));
         $extraInfo = $contract->extra_info;
     }
     $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
     $this->tp->assign("pic_limit", $numberOfPictures);
     $listingTypesInfo = SJB_ListingTypeManager::getAllListingTypesInfo();
     if (!$this->listingTypeID && count($listingTypesInfo) == 1) {
         $listingTypeInfo = array_pop($listingTypesInfo);
         $this->listingTypeID = $listingTypeInfo['id'];
     }
     $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($this->listingTypeID);
     $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listingTypeSID);
     $pageSID = $this->getPageSID($pages, $listingTypeSID);
     $isPageLast = SJB_PostingPagesManager::isLastPageByID($pageSID, $listingTypeSID);
     $isPreviewListingRequested = SJB_Request::getVar('preview_listing', false, 'POST');
     if (($contractID || !empty($this->buttonPressedPostToProceed)) && $this->listingTypeID) {
         $formSubmitted = isset($_REQUEST['action_add']) || isset($_REQUEST['action_add_pictures']) || $isPreviewListingRequested;
         /*
          * social plugin
          * complete listing of data from an array of social data
          * if is allowed
          */
         $aAutoFillData = array('formSubmitted' => &$formSubmitted, 'listingTypeID' => &$this->listingTypeID);
         SJB_Event::dispatch('SocialSynchronization', $aAutoFillData);
         /*
          * end of "social plugin"
          */
         $listing = new SJB_Listing($_REQUEST, $listingTypeSID, $pageSID);
         $listing->deleteProperty('featured');
         $listing->deleteProperty('priority');
         $listing->deleteProperty('status');
         $listing->deleteProperty('reject_reason');
         $listing->deleteProperty('ListingLogo');
         $access_type = $listing->getProperty('access_type');
         if ($formSubmitted) {
             if (!empty($access_type)) {
                 $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar("list_emp_ids"), 'is_system' => true));
             }
             $listing->addProperty(array('id' => 'contract_id', 'type' => 'id', 'value' => $contractID, 'is_system' => true));
         }
         $currentUser = SJB_UserManager::getCurrentUser();
         $screeningQuestionnaires = SJB_ScreeningQuestionnaires::getList($currentUser->getSID());
         if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screeningQuestionnaires) {
             $issetQuestionnairyField = $listing->getProperty('screening_questionnaire');
             if ($issetQuestionnairyField) {
                 $value = SJB_Request::getVar("screening_questionnaire");
                 $listingInfo = $_REQUEST;
                 $value = $value ? $value : isset($listingInfo['screening_questionnaire']) ? $listingInfo['screening_questionnaire'] : '';
                 $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($currentUser->getSID()), 'is_system' => true));
             }
         } else {
             $listing->deleteProperty('screening_questionnaire');
         }
         /*
          * social plugin
          * "synchronization"
          * if user is not registered using linkedin , delete linkedin sync property
          * also if sync is turned off in admin part
          */
         $aAutoFillData = array('oListing' => &$listing, 'userSID' => $currentUser->getSID(), 'listingTypeID' => $this->listingTypeID, 'listing_info' => $_REQUEST);
         SJB_Event::dispatch('SocialSynchronizationFields', $aAutoFillData);
         /*
          * end of social plugin "sync"
          */
         $listingFormAdd = new SJB_Form($listing);
         $listingFormAdd->registerTags($this->tp);
         $fieldErrors = array();
         if ($formSubmitted && ($this->formSubmittedFromPreview || $listingFormAdd->isDataValid($fieldErrors))) {
             if ($isPageLast) {
                 $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
             }
             $listing->setUserSID($currentUser->getSID());
             $listing->setProductInfo($extraInfo);
             if (empty($access_type->value)) {
                 $listing->setPropertyValue('access_type', 'everyone');
             }
             if ($currentUser->isSubuser()) {
                 $subuserInfo = $currentUser->getSubuserInfo();
                 $listing->addSubuserProperty($subuserInfo['sid']);
             }
             /**
              * >>>>> listing preview @author still
              */
             if (!empty($listingSID)) {
                 $listing->setSID($listingSID);
             }
             /*
              * <<<<< listing preview
              */
             SJB_ListingManager::saveListing($listing);
             if (!empty($this->buttonPressedPostToProceed)) {
                 SJB_ListingManager::unmakeCheckoutedBySID($listing->getSID());
             }
             SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $extraInfo['featured'], $extraInfo['priority']);
             if ($contractID) {
                 $contract = new SJB_Contract(array('contract_id' => $contractID));
                 $contract->incrementPostingsNumber();
                 SJB_ProductsManager::incrementPostingsNumber($contract->product_sid);
             }
             if (SJB_Session::getValue('tmp_file_storage')) {
                 foreach ($_SESSION['tmp_file_storage'] as $v) {
                     SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `picture_saved_name` = ?s", $listing->getSID(), $v['picture_saved_name']);
                     SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `thumb_saved_name` = ?s", $listing->getSID(), $v['thumb_saved_name']);
                 }
                 SJB_Session::unsetValue('tmp_file_storage');
             }
             // >>> SJB-1197
             // check temporary uploaded storage for listing uploads and assign it to saved listing
             $formToken = SJB_Request::getVar('form_token');
             $sessionFilesStorage = SJB_Session::getValue('tmp_uploads_storage');
             $uploadedFields = SJB_Array::getPath($sessionFilesStorage, $formToken);
             if (!empty($uploadedFields)) {
                 foreach ($uploadedFields as $fieldId => $fieldValue) {
                     // get field of listing
                     $isComplex = false;
                     if (strpos($fieldId, ':') !== false) {
                         $isComplex = true;
                     }
                     $tmpUploadedFileId = $fieldValue['file_id'];
                     // rename it to real listing field value
                     $newFileId = $fieldId . "_" . $listing->getSID();
                     SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                     if ($isComplex) {
                         list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                         $parentProp = $listing->getProperty($parentField);
                         $parentValue = $parentProp->getValue();
                         // look for complex property with current $fieldID and set it to new value of property
                         if (!empty($parentValue)) {
                             foreach ($parentValue as $id => $value) {
                                 if ($id == $subField) {
                                     $parentValue[$id][$complexStep] = $newFileId;
                                 }
                             }
                             $listing->setPropertyValue($parentField, $parentValue);
                         }
                     } else {
                         $listing->setPropertyValue($fieldId, $newFileId);
                     }
                     // unset value from session temporary storage
                     $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}/{$fieldId}");
                 }
                 //and remove token key from temporary storage
                 $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}");
                 SJB_Session::setValue('tmp_uploads_storage', $sessionFilesStorage);
                 SJB_ListingManager::saveListing($listing);
                 $keywords = $listing->getKeywords();
                 SJB_ListingManager::updateKeywords($keywords, $listing->getSID());
             }
             // <<< SJB-1197
             if ($isPageLast && !$isPreviewListingRequested) {
                 /* delete temp preview listing sid */
                 SJB_Session::unsetValue('preview_listing_sid_for_add');
                 // Start Event
                 $listingSid = $listing->getSID();
                 SJB_Event::dispatch('listingSaved', $listingSid);
                 if ($extraInfo['featured']) {
                     SJB_ListingManager::makeFeaturedBySID($listing->getSID());
                 }
                 if ($extraInfo['priority']) {
                     SJB_ListingManager::makePriorityBySID($listing->getSID());
                 }
                 if (!empty($this->buttonPressedPostToProceed)) {
                     $this->proceedToCheckout($currentUser->getSID(), $productSID);
                 } else {
                     if (SJB_ListingManager::activateListingBySID($listing->getSID())) {
                         SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID());
                     }
                     // notify administrator
                     SJB_AdminNotifications::sendAdminListingAddedLetter($listing);
                     if (isset($_REQUEST['action_add_pictures'])) {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-pictures/?listing_id=" . $listing->getSID());
                     } else {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-' . strtolower($this->listingTypeID) . '/?listing_id=' . $listing->getSID());
                     }
                 }
             } elseif ($isPageLast && $isPreviewListingRequested) {
                 // for listing preview
                 SJB_Session::setValue('preview_listing_sid_for_add', $listing->getSID());
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/' . strtolower($this->listingTypeID) . '-preview/' . $listing->getSID() . '/');
             } else {
                 // listing steps (pages)
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/add-listing/{$this->listingTypeID}/" . SJB_PostingPagesManager::getNextPage($pageSID) . "/" . $listing->getSID());
             }
         } else {
             $listing->deleteProperty('access_list');
             $listing->deleteProperty('contract_id');
             $listingFormAdd = new SJB_Form($listing);
             if ($formSubmitted) {
                 $listingFormAdd->isDataValid($fieldErrors);
             }
             $listingFormAdd->registerTags($this->tp);
             $template = isset($_REQUEST['input_template']) ? $_REQUEST['input_template'] : "input_form.tpl";
             $formFields = $listingFormAdd->getFormFieldsInfo();
             $employersList = SJB_Request::getVar('list_emp_ids', false);
             $employers = array();
             if (is_array($employersList)) {
                 foreach ($employersList as $emp) {
                     $currEmp = SJB_UserManager::getUserInfoBySID($emp);
                     $employers[] = array('user_id' => $emp, 'value' => $currEmp['CompanyName']);
                 }
                 sort($employers);
             }
             $this->tp->assign('form_token', SJB_Request::getVar('form_token'));
             $this->tp->assign("account_activated", SJB_Request::getVar('account_activated', ''));
             $this->tp->assign("contract_id", $contractID);
             $this->tp->assign("listing_access_list", $employers);
             $this->tp->assign("listingTypeID", $this->listingTypeID);
             $this->tp->assign('listingTypeStructure', SJB_ListingTypeManager::createTemplateStructure(SJB_ListingTypeManager::getListingTypeInfoBySID($listing->listing_type_sid)));
             $this->tp->assign("field_errors", $fieldErrors);
             $this->tp->assign("form_fields", $formFields);
             $this->tp->assign("pages", $pages);
             $this->tp->assign("pageSID", $pageSID);
             $this->tp->assign("extraInfo", $extraInfo);
             $this->tp->assign("currentPage", SJB_PostingPagesManager::getPageInfoBySID($pageSID));
             $this->tp->assign("isPageLast", $isPageLast);
             $this->tp->assign("nextPage", SJB_PostingPagesManager::getNextPage($pageSID));
             $this->tp->assign("prevPage", SJB_PostingPagesManager::getPrevPage($pageSID));
             $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
             $this->tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($formFields)));
             /*
              * social plugin
              * only for Resume listing types
              */
             $aAutoFillData = array('tp' => &$this->tp, 'listingTypeID' => &$this->listingTypeID, 'userSID' => $currentUser->getSID());
             SJB_Event::dispatch('SocialSynchronizationForm', $aAutoFillData);
             /*
              * social plugin
              */
             $this->tp->display($template);
         }
     }
 }
 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;
 }
Example #23
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     if (SJB_UserManager::isUserLoggedIn()) {
         $current_user = SJB_UserManager::getCurrentUser();
         if ($current_user->isSubuser()) {
             // У саб-юзера должны быть свои алерты
             $current_user = $current_user->getSubuserInfo();
         } else {
             $current_user = SJB_UserManager::getCurrentUserInfo();
         }
         $listing_type_id = '';
         /************************************************************/
         $tp = SJB_System::getTemplateProcessor();
         $tp->assign('action', 'list');
         $errors = array();
         $redirectUri = '/saved-searches/';
         if (isset($_REQUEST['is_alert'])) {
             if (isset($_REQUEST['listing_type_id'])) {
                 $listing_type_id = $_REQUEST['listing_type_id'];
                 SJB_Session::setValue('listing_type_id', $listing_type_id);
             } elseif (isset($_REQUEST['restore'])) {
                 $listing_type_id = SJB_Session::getValue('listing_type_id');
             } else {
                 SJB_Session::setValue('listing_type_id', null);
             }
             if (!SJB_Acl::getInstance()->isAllowed("use_{$listing_type_id}_alerts")) {
                 $errors = array('NOT_SUBSCRIBE' => true);
                 $tp->assign('ERRORS', $errors);
                 $tp->display('error.tpl');
                 return;
             } else {
                 $redirectUri = '/' . strtolower($listing_type_id) . '-alerts/';
             }
         } else {
             if (isset($_REQUEST['listing_type_id'])) {
                 $listing_type_id = $_REQUEST['listing_type_id'];
             }
             if (!SJB_Acl::getInstance()->isAllowed('save_searches')) {
                 $errors = array('NOT_SUBSCRIBE' => true);
                 $tp->assign('ERRORS', $errors);
                 $tp->display('error.tpl');
                 return;
             }
         }
         $isSubmittedForm = SJB_Request::getVar('submit', false);
         $listing_type_sid = !empty($listing_type_id) ? SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id) : 0;
         if (!isset($_REQUEST['listing_type']['equal']) && isset($listing_type_id)) {
             $_REQUEST['listing_type']['equal'] = $listing_type_id;
         }
         $action = SJB_Request::getVar('action', 'list');
         switch ($action) {
             case 'save':
                 if ($isSubmittedForm) {
                     $search_name = SJB_Request::getVar('name');
                     $emailFrequency = SJB_Request::getVar('email_frequency');
                     if (empty($search_name['equal'])) {
                         $errors['EMPTY_VALUE'] = 1;
                         $tp->assign('action', 'save');
                     } else {
                         unset($_REQUEST['name']);
                         unset($_REQUEST['email_frequency']);
                         if ($emailFrequency) {
                             $emailFrequency = array_pop($emailFrequency);
                             $emailFrequency = '&email_frequency=' . array_pop($emailFrequency);
                         } else {
                             $emailFrequency = '';
                         }
                         $search_name = $search_name['equal'];
                         $searchResultsTP = new SJB_SearchResultsTP($_REQUEST, $listing_type_id);
                         $tp = $searchResultsTP->getChargedTemplateProcessor();
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/save-search/?alert=true&url=' . $redirectUri . '&action=save&search_name=' . $search_name . '&searchId=' . $searchResultsTP->searchId . $emailFrequency);
                     }
                 } else {
                     $tp->assign('action', 'save');
                 }
                 break;
             case 'edit':
                 if (isset($_REQUEST['id_saved'])) {
                     if ($isSubmittedForm) {
                         $id_saved = $_REQUEST['id_saved'];
                         $name = $_REQUEST['name'];
                         $search_name = SJB_Request::getVar('name');
                         $emailFrequency = SJB_Request::getVar('email_frequency');
                         if (empty($search_name['equal'])) {
                             $errors['EMPTY_VALUE'] = 1;
                         } else {
                             unset($_REQUEST['name']);
                             unset($_REQUEST['email_frequency']);
                             if ($emailFrequency) {
                                 $emailFrequency = array_pop($emailFrequency);
                                 $emailFrequency = array_pop($emailFrequency);
                             } else {
                                 $emailFrequency = 'daily';
                             }
                             $searchResultsTP = new SJB_SearchResultsTP($_REQUEST, $listing_type_id);
                             $tp = $searchResultsTP->getChargedTemplateProcessor();
                             $criteria_saver = new SJB_ListingCriteriaSaver($searchResultsTP->searchId);
                             $requested_data = $criteria_saver->getCriteria();
                             SJB_SavedSearches::updateSearchOnDB($requested_data, $id_saved, $current_user['sid'], $name['equal'], $emailFrequency);
                         }
                         if (!empty($errors)) {
                             $tp->assign('action', 'edit');
                             $tp->assign('id_saved', $_REQUEST['id_saved']);
                         } else {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . $redirectUri . '?alert=is_update');
                         }
                     } else {
                         $tp->assign('action', 'edit');
                         $tp->assign('id_saved', $_REQUEST['id_saved']);
                     }
                 }
                 break;
             case 'edit_alert':
                 $tp->assign('action', 'edit');
                 $tp->assign('id_saved', $_REQUEST['id_saved']);
                 break;
             case 'edit_search':
                 $tp->assign('action', 'edit');
                 $tp->assign('id_saved', $_REQUEST['id_saved']);
                 $_REQUEST['form_template'] = SJB_Request::getVar('formTemplateNem');
                 break;
             case 'new':
                 $tp->assign('action', 'save');
                 break;
             case 'delete':
                 if (isset($_REQUEST['search_id'])) {
                     $search_id = $_REQUEST['search_id'];
                     SJB_SavedSearches::deleteSearchFromDBBySID($search_id);
                 }
                 break;
             case 'disable_notify':
                 if (isset($_REQUEST['search_id'])) {
                     SJB_SavedSearches::disableSearchAutoNotify($current_user['sid'], $_REQUEST['search_id']);
                 }
                 break;
             case 'enable_notify':
                 if (isset($_REQUEST['search_id'])) {
                     SJB_SavedSearches::enableSearchAutoNotify($current_user['sid'], $_REQUEST['search_id']);
                 }
                 break;
         }
         if ($action != 'new' && $action != 'edit_alert') {
             $saved_searches = SJB_SavedSearches::getSavedSearchesFromDB($current_user['sid']);
             if (isset($_REQUEST['is_alert'])) {
                 $saved_searches = SJB_SavedSearches::getSavedJobAlertFromDB($current_user['sid']);
             }
             foreach ($saved_searches as $key => $saved_search) {
                 $saved_searches[$key]['data'] = SJB_SavedSearches::buildCriteriaFields($saved_search['data']);
                 if (isset($saved_search['data']['listing_type']['equal'])) {
                     $saved_searches[$key]['listing_type'] = $saved_search['data']['listing_type']['equal'];
                 }
             }
             $tp->assign('saved_searches', $saved_searches);
         }
         $listing = new SJB_Listing(array(), $listing_type_sid);
         $listing->addIDProperty();
         $listing->addActivationDateProperty();
         $listing->addUsernameProperty();
         $listing->addKeywordsProperty();
         $listing->addPicturesProperty();
         $listing->addEmailFrequencyProperty();
         $listing->addListingTypeIDProperty();
         $listing->addPostedWithinProperty();
         $search_form_builder = new SJB_SearchFormBuilder($listing);
         $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($_REQUEST);
         $search_form_builder->setCriteria($criteria);
         $search_form_builder->registerTags($tp);
         $form_fields = $search_form_builder->getFormFieldsInfo();
         $tp->assign('form_fields', $form_fields);
         if (!empty($_REQUEST['name'])) {
             $tp->assign('search_name', $_REQUEST['name']);
         }
         if (!empty($_REQUEST['email_frequency'])) {
             $tp->assign('email_frequency', $_REQUEST['email_frequency']);
         }
         $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
         $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
         $form_template = SJB_Request::getVar('form_template', 'search_form.tpl');
         switch (SJB_Request::getVar('alert')) {
             case 'added':
                 $tp->assign('alert_added', 'added');
                 break;
             case 'is_update':
                 $tp->assign('alert_update', 'update');
                 break;
         }
         if (!$listing_type_id && isset($saved_search['data']['listing_type']['equal'])) {
             $listing_type_id = $saved_search['data']['listing_type']['equal'];
         }
         $tp->assign('errors', $errors);
         $tp->assign('user_logged_in', true);
         $tp->assign('listing_type_id', $listing_type_id);
         $formBuilder = SJB_FormBuilderManager::getFormBuilder(SJB_FormBuilderManager::FORM_BUILDER_TYPE_SEARCH, $listing_type_id);
         $formBuilder->setChargedTemplateProcessor($tp);
         $tp->display($form_template);
     } else {
         $tp->assign("ERROR", "NOT_LOGIN");
         $tp->display("../miscellaneous/error.tpl");
         return;
     }
 }
Example #24
0
 /**
  * @param $fieldName
  * @param $fieldID
  * @param SJB_SearchResultsTP $stp
  * @param $userField
  * @return mixed
  */
 public static function countListingsByFieldName($fieldName, $fieldID, $stp, $userField)
 {
     $refineSearchLimit = SJB_Settings::getSettingByName('refine_search_items_limit');
     $limit = $refineSearchLimit ? ' LIMIT 0, ' . $refineSearchLimit : '';
     $listing = new SJB_Listing(array(), $stp->listing_type_sid);
     $id_alias_info = $listing->addIDProperty();
     $listing->addActivationDateProperty();
     $listing->addFeaturedProperty();
     $username_alias_info = $listing->addUsernameProperty();
     $listing_type_id_info = $listing->addListingTypeIDProperty();
     $listing->addCompanyNameProperty();
     $requestedCriteria = $stp->criteria_saver->getCriteria();
     if (isset($requestedCriteria['PostedWithin']) && $requestedCriteria['PostedWithin']['multi_like'][0] != '') {
         $within_period = $requestedCriteria['PostedWithin']['multi_like'][0];
         $i18n = SJB_I18N::getInstance();
         $requestedCriteria['activation_date']['not_less'] = $i18n->getDate(date('Y-m-d', strtotime("- {$within_period} days")));
         unset($requestedCriteria['PostedWithin']);
     }
     if (isset($requestedCriteria['CompanyName']['multi_like_and'][0])) {
         $userName = SJB_UserManager::getUserNameByCompanyName($requestedCriteria['CompanyName']['multi_like_and'][0]);
         unset($requestedCriteria['CompanyName']);
         if ($userName) {
             $requestedCriteria['username']['equal'] = $userName;
         }
     }
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($requestedCriteria, $listing);
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias($id_alias_info);
     $aliases->addAlias($username_alias_info);
     $aliases->addAlias($listing_type_id_info);
     $aliases->changeAliasValuesInCriteria($criteria);
     $sqlTranslator = new SJB_SearchSqlTranslator('listings');
     $whereStatement = $sqlTranslator->_getWhereStatement($criteria);
     $objectSids = implode(',', $stp->found_listings_sids);
     if ($userField == 1) {
         $field = SJB_UserProfileFieldManager::getFieldInfoBySID($fieldID);
     } else {
         $field = SJB_ListingFieldDBManager::getListingFieldInfoBySID($fieldID);
     }
     $result = array();
     $cache = SJB_Cache::getInstance();
     if (!empty($field['parent_sid'])) {
         $parentInfo = SJB_ListingFieldManager::getFieldInfoBySID($field['parent_sid']);
         $fieldName = $parentInfo['id'] . "_" . $fieldName;
         $field['id'] = $fieldName;
         $field['parentID'] = $parentInfo['id'];
     }
     switch ($field['type']) {
         case 'list':
         case 'multilist':
             if ($userField == 1) {
                 $query = "SELECT up.`{$fieldName}` as caption, count(`listings`.`sid`) as count\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t FROM `listings`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t INNER JOIN `users` `up` ON `listings`.`user_sid` = `up`.`sid`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t {$whereStatement}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t AND up.`{$fieldName}` != ''\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t GROUP BY `up`.`{$fieldName}` ORDER BY count DESC";
                 if (!($result = $cache->load(md5($query)))) {
                     $result = SJB_DB::query($query);
                     $cache->save($result, md5($query), array(SJB_Cache::TAG_LISTINGS, SJB_Cache::TAG_USERS));
                 }
             } else {
                 $query = "SELECT `{$fieldName}` as caption, count(`{$fieldName}`) as count FROM `listings` {$whereStatement} AND `{$fieldName}` != '' GROUP BY `{$fieldName}` ORDER BY count DESC";
                 if (!($result = $cache->load(md5($query)))) {
                     $result = SJB_DB::query($query);
                     $cache->save($result, md5($query), array(SJB_Cache::TAG_LISTINGS));
                 }
             }
             self::breakMultiCategory($result);
             $newResult = array();
             $listItem = new SJB_ListingFieldListItemManager();
             foreach ($result as $key => $val) {
                 if (!empty($field['parent_sid'])) {
                     $caption = '';
                     if ($field['id'] == $field['parentID'] . '_State') {
                         $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $field['display_as']);
                     } else {
                         $listValues = $field['list_values'];
                     }
                     foreach ($listValues as $listValue) {
                         if ($listValue['id'] == $val['caption']) {
                             $caption = $listValue['caption'];
                             break;
                         }
                     }
                 } else {
                     $itemInfo = $listItem->getListItemBySID($val['caption']);
                     $caption = $itemInfo ? $itemInfo->getValue() : null;
                 }
                 if ($caption != null) {
                     $newResult[$key]['count'] = $val['count'];
                     $newResult[$key]['value'] = $caption;
                     $newResult[$key]['sid'] = $val['caption'];
                 }
             }
             arsort($newResult);
             $result = $newResult;
             if (count($result) > $refineSearchLimit) {
                 $result = array_slice($result, 0, $refineSearchLimit);
             }
             break;
         case 'tree':
             $query = "SELECT `lt`.`sid` as `sid`, `lt`.`caption` as `value`, count(`listings`.`sid`) as `count`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `listings`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `listing_field_tree` `lt` ON `lt`.`field_sid` = {$field['sid']} AND find_in_set(`lt`.`sid`, `listings`.`{$fieldName}`)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$whereStatement} GROUP BY `lt`.`sid` having `lt`.`sid` IS NOT NULL ORDER BY `count` DESC {$limit}";
             if (!($propertyValue = $cache->load(md5($query)))) {
                 $propertyValue = SJB_DB::query($query);
                 $cache->save($propertyValue, md5($query), array(SJB_Cache::TAG_LISTINGS, SJB_Cache::TAG_FIELDS));
             }
             foreach ($propertyValue as $value) {
                 $result[$value['sid']] = $value;
             }
             break;
         default:
             if ($userField == 1) {
                 $companyColumn = "up.`{$fieldName}`";
                 $query = "SELECT {$companyColumn} as `value`, count(listings.`sid`) as `count`\n\t\t\t\t\t\t\t\t\t\t\t FROM `listings`\n\t\t\t\t\t\t\t\t\t\t\t INNER JOIN `users` `up` ON `listings`.`user_sid` = `up`.`sid`\n\t\t\t\t\t\t\t\t\t\t\t {$whereStatement}\n\t\t\t\t\t\t\t\t\t\t\t GROUP BY {$companyColumn} ORDER BY `count` DESC {$limit}";
                 if (!($result = $cache->load(md5($query)))) {
                     $result = SJB_DB::query($query);
                     $cache->save($result, md5($query), array(SJB_Cache::TAG_LISTINGS, SJB_Cache::TAG_USERS));
                 }
             } else {
                 if ($field['type'] == 'complex') {
                     $query = "SELECT `value`, count(`value`) as count FROM `listings_properties` WHERE `id`='{$fieldName}' AND `value` != '' AND `object_sid` in ({$objectSids}) GROUP BY `value` ORDER BY count DESC {$limit}";
                 } else {
                     $query = "SELECT `{$fieldName}` as value, count(`{$fieldName}`) as count FROM `listings` {$whereStatement} AND `{$fieldName}` != '' GROUP BY `{$fieldName}` ORDER BY count DESC {$limit}";
                 }
                 if (!($result = $cache->load(md5($query)))) {
                     $result = SJB_DB::query($query);
                     $cache->save($result, md5($query), array(SJB_Cache::TAG_LISTINGS));
                 }
             }
             break;
     }
     $returnArr['caption'] = $field['caption'];
     $returnArr['values'] = $result;
     return $returnArr;
 }
Example #25
0
 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();
 }