public function execute() { $tp = SJB_System::getTemplateProcessor(); $errors = array(); $listingTypeID = SJB_Request::getVar('listing_type_id', ''); if (SJB_UserManager::isUserLoggedIn()) { if (!SJB_Acl::getInstance()->isAllowed('save_' . trim($listingTypeID))) { $errors[] = 'DENIED_VIEW_SAVED_LISTING'; } if (!$errors) { $userSid = SJB_UserManager::getCurrentUserSID(); if (SJB_Request::getVar('action', '') == 'delete') { $listing_id = SJB_Request::getVar('listing_id', null); if (!is_null($listing_id)) { foreach ($listing_id as $key => $value) { SJB_SavedListings::deleteListingFromDBBySID($key, $userSid); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . SJB_Navigator::getURI()); } } $saved_listings_id = SJB_SavedListings::getSavedListingsFromDB($userSid); $listings_structure = array(); $listing_structure_meta_data = array(); foreach ($saved_listings_id as $saved_listing) { $saved_listing_id = $saved_listing['listing_sid']; $listing = SJB_ListingManager::getObjectBySID($saved_listing_id); if (is_null($listing)) { continue; } $listing->addPicturesProperty(); $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing); $listings_structure[$listing->getID()] = $listing_structure; $listings_structure[$listing->getID()]['saved_listing'] = $saved_listing; if (isset($listing_structure['METADATA'])) { $listing_structure_meta_data = array_merge($listing_structure_meta_data, $listing_structure['METADATA']); } } $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $tp->assign("METADATA", array("listing" => $metaDataProvider->getMetaData($listing_structure_meta_data))); $tp->assign("listings", $listings_structure); $tp->assign("listing_type_id", $listingTypeID); $tp->display("saved_listings.tpl"); } else { $tp->assign("errors", $errors); $tp->display("save_search_failed.tpl"); } } else { $url = base64_encode(SJB_System::getSystemSettings("SITE_URL") . "/system/classifieds" . SJB_System::getURI()); switch ($listingTypeID) { case 'job': $url = base64_encode(SJB_System::getSystemSettings("SITE_URL") . "/saved-jobs/"); break; case 'resume': $url = base64_encode(SJB_System::getSystemSettings("SITE_URL") . "/saved-resumes/"); break; } $tp->assign("return_url", $url); $tp->display("../users/login.tpl"); } }
/** * @return SJB_Acl */ public static function getInstance($reload = false) { if (null === self::$instance || $reload) { self::$instance = new self(); } return self::$instance; }
public function savePermissions($request, $product) { $acl = SJB_Acl::getInstance(); $resources = $acl->getResources(); $type = 'product'; $role = $product->getSID(); SJB_Acl::clearPermissions($type, $role); $userGroupSID = $product->getPropertyValue('user_group_sid'); $groupPermissions = SJB_DB::query('select * from `permissions` where `type` = ?s and `role` = ?s', 'group', $userGroupSID); foreach ($groupPermissions as $key => $groupPermission) { $groupPermissions[$groupPermission['name']] = $groupPermission; unset($groupPermissions[$key]); } foreach ($resources as $name => $resource) { $params = isset($request[$name . '_params']) ? $request[$name . '_params'] : ''; $params1 = isset($request[$name . '_params1']) ? $request[$name . '_params1'] : ''; $value = isset($request[$name]) ? $request[$name] : ''; $message = isset($request[$name . '_message']) ? $request[$name . '_message'] : ''; if (empty($value) && isset($groupPermissions[$name])) { $value = 'inherit'; $message = $groupPermissions[$name]['message']; $params = $groupPermissions[$name]['params']; } elseif ($value == 'deny' && $params1) { $params = $params1; } SJB_Acl::allow($name, $type, $role, $value, $params, $message); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $subAdminSID = SJB_Request::getVar('subadmin', 0); if (!empty($subAdminSID) && ($adminInfo = SJB_SubAdminManager::getSubAdminInfoBySID($subAdminSID))) { $editedSubAdminInfo = $_REQUEST; $subAdminInfo = array_merge($adminInfo, $editedSubAdminInfo); // create subAdmin object $oSubAdmin = SJB_ObjectMother::createSubAdmin($subAdminInfo); $oSubAdmin->setSID($adminInfo['sid']); $oSubAdmin->makePropertyNotRequired("password"); // permissions $acl = SJB_SubAdminAcl::getInstance(); $type = 'subadmin'; $resources = $acl->getResources(); $perms = SJB_SubAdminAcl::getAllPermissions($type, $oSubAdmin->getSID()); // /permissions SJB_SubAdminAcl::mergePermissionsWithResources($resources, $perms); $registration_form = SJB_ObjectMother::createForm($oSubAdmin); $action = SJB_Request::getVar('action', ''); $registration_form->registerTags($tp); $errors = array(); if ('save' == $action || $action == 'apply') { if ($adminInfo['username'] == $subAdminInfo['username']) { $oSubAdmin->deleteProperty('username'); } if ($adminInfo['email'] == $subAdminInfo['email']) { $oSubAdmin->deleteProperty('email'); } if ($registration_form->isDataValid($errors)) { $password_value = $oSubAdmin->getPropertyValue('password'); if (empty($password_value['original'])) { $oSubAdmin->deleteProperty('password'); } // save subAdmin SJB_SubAdminManager::saveSubAdmin($oSubAdmin); $role = $oSubAdmin->getSID(); SJB_Acl::clearPermissions($type, $role); foreach ($resources as $name => $resource) { SJB_SubAdminAcl::allow($name, $type, $role, SJB_SubAdminAcl::definePermission($name), SJB_Array::get($resource, 'params', '')); } SJB_FlashMessages::getInstance()->addMessage('CHANGES_SAVED'); if ($action == 'save') { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-subadmins/"); } } SJB_SubAdminAcl::mergePermissionsWithRequest($resources); } SJB_SubAdminAcl::prepareSubPermissions($resources); $tp->assign("errors", $errors); $tp->assign("form_fields", $registration_form->getFormFieldsInfo()); $tp->assign('groups', SJB_SubAdminAcl::getPermissionGroups()); $tp->assign('resources', $resources); $tp->assign('type', $type); $tp->assign('sid', $subAdminInfo['sid']); $tp->display('add_subadmin.tpl'); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $permission = SJB_Request::getVar('permission', false); if ($permission) { $acl = SJB_Acl::getInstance(); $tp->assign('message', $acl->getPermissionMessage($permission)); } $tp->display('denied_option_message.tpl'); }
/** * * @return bool */ public function isAccessible() { // admin can do everything if (SJB_System::getSystemSettings('SYSTEM_ACCESS_TYPE') == 'admin' && SJB_Admin::admin_authed()) { return true; } if (!$this->permissionLabel) { return $this->allowed; } $result = false; if (is_array($this->permissionLabel)) { foreach ($this->permissionLabel as $permission) { if ($this->acl->isAllowed($permission, $this->getAclRoleID())) { $result = true; } } } else { $result = (bool) $this->acl->isAllowed($this->permissionLabel, $this->getAclRoleID()); } return $result; }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $oSubAdmin = SJB_ObjectMother::createSubAdmin($_REQUEST); $registration_form = SJB_ObjectMother::createForm($oSubAdmin); $registration_form->registerTags($tp); $form_submitted = SJB_Request::getVar('action', '') == 'add'; $errors = array(); $acl = SJB_SubAdminAcl::getInstance(); $type = 'subadmin'; $resources = $acl->getResources(); SJB_SubAdminAcl::mergePermissionsWithResources($resources); switch (SJB_Request::getVar('action')) { case 'save': if ($registration_form->isDataValid($errors)) { SJB_SubAdminManager::saveSubAdmin($oSubAdmin); $role = $oSubAdmin->getSID(); SJB_Acl::clearPermissions($type, $role); foreach ($resources as $name => $resource) { SJB_SubAdminAcl::allow($name, $type, $role, SJB_SubAdminAcl::definePermission($name), SJB_Request::getVar($name . '_params')); } // get new defined permissions for notification letter $permissions = SJB_SubAdminAcl::getAllPermissions($type, $role); $resources = $acl->getResources(); SJB_SubAdminAcl::mergePermissionsWithResources($resources, $permissions); SJB_Notifications::sendSubAdminRegistrationLetter($oSubAdmin, SJB_Request::get(), $resources); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-subadmins/'); } break; case 'delete': $subadmins = SJB_Request::getVar('subadmin', array()); foreach ($subadmins as $subadmin_sid) { $username = SJB_SubAdminManager::getUserNameBySubAdminSID($subadmin_sid); SJB_SubAdminManager::deleteSubAdminByUserName($username); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-subadmins/'); break; default: break; } $tp->assign('errors', $errors); $tp->assign('form_fields', $registration_form->getFormFieldsInfo()); $aPermissionGroups = SJB_SubAdminAcl::getPermissionGroups(); if ('save' == SJB_Request::getVar('action', '')) { SJB_SubAdminAcl::mergePermissionsWithRequest($resources); } SJB_SubAdminAcl::prepareSubPermissions($resources); $tp->assign('groups', $aPermissionGroups); $tp->assign('resources', $resources); $tp->assign('type', $type); $tp->assign('role', 0); $tp->display('add_subadmin.tpl'); }
public function execute() { $template_processor = SJB_System::getTemplateProcessor(); $listingId = SJB_Request::getVar('listing_id', null, 'default', 'int'); $listingType = SJB_Request::getVar('listing_type', null); if (!$listingType) { if ($listingId) { $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId); $listingType = SJB_ListingTypeManager::getListingTypeIDBySID($listingInfo['listing_type_sid']); } else { $listingType = 'job'; } } $displayForm = SJB_Request::getVar('displayForm', false); $error = null; if (!SJB_Acl::getInstance()->isAllowed('save_' . trim($listingType))) { $error = 'DENIED_SAVE_LISTING'; } if (SJB_UserManager::isUserLoggedIn()) { if (!$error) { if (!is_null($listingId)) { if (SJB_UserManager::isUserLoggedIn()) { SJB_SavedListings::saveListingOnDB($listingId, SJB_UserManager::getCurrentUserSID()); SJB_Statistics::addStatistics('saveListing', SJB_ListingTypeManager::getListingTypeSIDByID($listingType), $listingId); } else { SJB_SavedListings::saveListingInCookie($listingId); } $template_processor->assign('saved_listing', SJB_SavedListings::getSavedListingsByUserAndListingSid(SJB_UserManager::getCurrentUserSID(), $listingId)); } else { $error = 'LISTING_ID_NOT_SPECIFIED'; } } $params = SJB_Request::getVar('params', false); $searchId = SJB_Request::getVar('searchId', false); $page = SJB_Request::getVar('page', false); $template_processor->assign("params", $params); $template_processor->assign("searchId", $searchId); $template_processor->assign("page", $page); $template_processor->assign("listing_type", $listingType); $template_processor->assign("listing_sid", $listingId); $template_processor->assign("from_login", SJB_Request::getVar("from_login", false)); $template_processor->assign("error", $error); $template_processor->assign("displayForm", $displayForm); $template_processor->assign("view", SJB_Request::getVar('view')); $template_processor->display("save_listing.tpl"); } else { $template_processor->assign("return_url", base64_encode(SJB_Navigator::getURIThis() . "&from_login=1")); $template_processor->assign("ajaxRelocate", true); $template_processor->display("../users/login.tpl"); } }
public static function getListingTypeByUserSID($sid) { if (empty($sid)) { return false; } $types = array(); $listingTypes = SJB_ListingTypeManager::getAllListingTypesInfo(); foreach ($listingTypes as $listingType) { if (SJB_Acl::getInstance()->isAllowed('post_' . $listingType['id'], $sid)) { $types[] = $listingType['sid']; } } return $types; }
/** * @param string $network * @param int $listingSID * @return bool */ private static function isNetworkAllowed($network, $listingSID) { $allowed = false; if (SJB_Settings::getSettingByName("enable_job_sharing_for_users_{$network}")) { $permission = SJB_ListingDBManager::getPermissionByListingSid('post_jobs_on_social_networks', $listingSID); if ($permission == 'deny') { $allowed = false; } else { if ($permission == 'allow' || SJB_Acl::getInstance()->isAllowed('post_jobs_on_social_networks')) { $allowed = true; } } } return $allowed; }
function saveInDB() { $result = SJB_ContractSQL::insert($this->_getHashedFields()); if ($result) { if (!$this->id) { $this->id = $result; } SJB_ContractSQL::updateContractExtraInfoByProductSID($this); if ($this->status == 'active') { SJB_Acl::copyPermissions($this->product_sid, $this->id, $this->number_of_listings); } else { SJB_Acl::clearPermissions('contract', $this->id); } $userInfo = SJB_UserManager::getUserInfoBySID($this->user_sid); $user = new SJB_User($userInfo, $userInfo['user_group_sid']); $user->updateSubscribeOnceUsersProperties($this->product_sid, $this->user_sid); } return (bool) $result; }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $action = SJB_Request::getVar('action', 'list'); $sid = SJB_Request::getVar('sid', null, null, 'int'); if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires')) { switch ($action) { case 'delete': if (SJB_ScreeningQuestionnaires::isUserOwnerQuestionnaire(SJB_UserManager::getCurrentUserSID(), $sid)) { SJB_ScreeningQuestionnaires::deleteQuestionnaireBySID($sid); } $action = 'list'; break; } $tp->assign('questionnaires', SJB_ScreeningQuestionnaires::getList(SJB_UserManager::getCurrentUserSID())); $tp->assign('action', $action); $tp->display('screening_questionnaires.tpl'); } }
public function savePermissions($request, $product) { $acl = SJB_Acl::getInstance(); $resources = $acl->getResources(); $type = 'product'; $role = $product->getSID(); $serialized_extra_info = unserialize($product->getPropertyValue('serialized_extra_info')); $pricingType = $serialized_extra_info['pricing_type']; $listingTypeSid = $serialized_extra_info['listing_type_sid']; $listingTypeId = strtolower(SJB_ListingTypeManager::getListingTypeIDBySID($listingTypeSid)); $userGroupSID = $product->getPropertyValue('user_group_sid'); $groupPermissions = SJB_DB::query('select * from `permissions` where `type` = ?s and `role` = ?s', 'group', $userGroupSID); SJB_Acl::clearPermissions($type, $role); foreach ($groupPermissions as $key => $groupPermission) { $groupPermissions[$groupPermission['name']] = $groupPermission; unset($groupPermissions[$key]); } foreach ($resources as $name => $resource) { $params = isset($request[$name . '_params']) ? $request[$name . '_params'] : ''; $params1 = isset($request[$name . '_params1']) ? $request[$name . '_params1'] : ''; $value = isset($request[$name]) ? $request[$name] : ''; $message = isset($request[$name . '_message']) ? $request[$name . '_message'] : ''; if ($name == 'post_' . $listingTypeId) { $value = 'allow'; if ($pricingType == 'fixed') { $params = $product->getPropertyValue('number_of_listings'); } } elseif ($name == 'add_featured_listings' && (!empty($serialized_extra_info['featured']) || !empty($serialized_extra_info['upgrade_to_featured_listing_price']))) { $value = 'allow'; } elseif ($name == 'add_priority_listings' && (!empty($serialized_extra_info['priority']) || !empty($serialized_extra_info['upgrade_to_priority_listing_price']))) { $value = 'allow'; } if (empty($value) && isset($groupPermissions[$name])) { $value = 'inherit'; $message = $groupPermissions[$name]['message']; $params = $groupPermissions[$name]['params']; } elseif ($value == 'deny' && $params1) { $params = $params1; } SJB_Acl::allow($name, $type, $role, $value, $params, $message); } }
public function execute() { $page_id = SJB_Request::getVar('pageid', null); if ($page_id) { $tp = SJB_System::getTemplateProcessor(); $i18n = SJB_I18N::getInstance(); $lang = SJB_Request::getVar('lang', $i18n->getCurrentLanguage()); $staticContent = SJB_StaticContent::getStaticContentByIDAndLang($page_id, $lang); if (empty($staticContent)) { $def_lang = SJB_System::getSettingByName('i18n_default_language'); $staticContent = SJB_StaticContent::getStaticContentByIDAndLang($page_id, $def_lang); } if (!empty($staticContent)) { if ($page_id == '404') { $isLoggedIn = SJB_Authorization::isUserLoggedIn(); if ($isLoggedIn) { $listingTypesInfo = SJB_ListingTypeManager::getAllListingTypesInfo(); $currentUserInfo = SJB_Authorization::getCurrentUserInfo(); $userGroupinfo = SJB_UserGroupManager::getUserGroupInfoBySID($currentUserInfo['user_group_sid']); $acl = SJB_Acl::getInstance(); $tp->assign('acl', $acl); $tp->assign('listingTypesInfo', $listingTypesInfo); $tp->assign('userGroupInfo', $userGroupinfo); } $staticContent['content'] = htmlspecialchars_decode($staticContent['content']); $tp->assign('isLoggedIn', $isLoggedIn); } if (empty($staticContent['content'])) { // Null создаёт ошибку в smarty $staticContent['content'] = ''; } $tp->assign('staticContent', $staticContent['content']); $tp->display('static_content.tpl'); } } }
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); }
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'); } }
public function execute() { $acl = SJB_Acl::getInstance(); $type = SJB_Request::getVar('type', ''); $role = SJB_Request::getVar('role', ''); $tp = SJB_System::getTemplateProcessor(); $resources = $acl->getResources(); $form_submitted = SJB_Request::getVar('action'); if ($form_submitted) { SJB_Acl::clearPermissions($type, $role); foreach ($resources as $name => $resource) { $params = SJB_Request::getVar($name . '_params'); $message = ''; if (SJB_Request::getVar($name) == 'deny') { $params = SJB_Request::getVar($name . '_params1'); if ($params == 'message') { $message = SJB_Request::getVar($name . '_message'); } } SJB_Acl::allow($name, $type, $role, SJB_Request::getVar($name, ''), $params, SJB_Request::getVar($name . '_message')); } if ($type == 'plan' && SJB_Request::getVar('update_users', 0) == 1) { $contracts = SJB_ContractManager::getAllContractsByMemebershipPlanSID($role); foreach ($contracts as $contract_id) { SJB_Acl::clearPermissions('contract', $contract_id['id']); SJB_DB::query("insert into `permissions` (`type`, `role`, `name`, `value`, `params`, `message`)" . " select 'contract', ?s, `name`, `value`, `params`, `message` from `permissions` " . " where `type` = 'plan' and `role` = ?s", $contract_id['id'], $role); } } if ($form_submitted == 'save') { switch ($type) { case 'group': $parameter = "/edit-user-group/?sid=" . $role; break; case 'guest': $parameter = "/user-groups/"; break; } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . $parameter); } } $acl = SJB_Acl::getInstance(true); $resources = $acl->getResources($type); $perms = SJB_DB::query('select * from `permissions` where `type` = ?s and `role` = ?s', $type, $role); foreach ($resources as $key => $resource) { $resources[$key]['value'] = 'inherit'; $resources[$key]['name'] = $key; foreach ($perms as $perm) { if ($key == $perm['name']) { $resources[$key]['value'] = $perm['value']; $resources[$key]['params'] = $perm['params']; $resources[$key]['message'] = $perm['message']; break; } } } $tp->assign('resources', $resources); $tp->assign('type', $type); $tp->assign('listingTypes', SJB_ListingTypeManager::getAllListingTypesInfo()); $tp->assign('role', $role); switch ($type) { case 'group': $tp->assign('userGroupInfo', SJB_UserGroupManager::getUserGroupInfoBySID($role)); break; case 'user': $userInfo = SJB_UserManager::getUserInfoBySID($role); $tp->assign('userGroupInfo', SJB_UserGroupManager::getUserGroupInfoBySID($userInfo['user_group_sid'])); break; } $tp->display('acl.tpl'); }
public function execute() { if (!function_exists('_filter_data')) { function _filter_data(&$array, $key, $pattern) { if (isset($array[$key])) { if (!preg_match($pattern, $array[$key])) { unset($array[$key]); } } } } _filter_data($_REQUEST, 'sorting_field', "/^[_\\w\\d]+\$/"); _filter_data($_REQUEST, 'sorting_order', "/(^DESC\$)|(^ASC\$)/i"); _filter_data($_REQUEST, 'default_sorting_field', "/^[_\\w\\d]+\$/"); _filter_data($_REQUEST, 'default_sorting_order', "/(^DESC\$)|(^ASC\$)/i"); $tp = SJB_System::getTemplateProcessor(); if (!SJB_UserManager::isUserLoggedIn()) { $errors['NOT_LOGGED_IN'] = true; $tp->assign("ERRORS", $errors); $tp->display("error.tpl"); return; } $this->defineRequestedListingTypeID(); if (!$this->listingTypeID) { $tp->assign('listingTypes', SJB_ListingTypeManager::getAllListingTypesInfo()); $tp->display('my_available_listing_types.tpl'); return; } $this->listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($this->listingTypeID); if (!$this->listingTypeSID) { SJB_HelperFunctions::redirect(SJB_HelperFunctions::getSiteUrl() . '/my-listings/'); return; } $currentUser = SJB_UserManager::getCurrentUser(); $userSID = $currentUser->getSID(); $this->requestCriteria = array('user_sid' => array('equal' => $userSID), 'listing_type_sid' => array('equal' => $this->listingTypeSID)); $acl = SJB_Acl::getInstance(); if ($currentUser->isSubuser()) { $subUserInfo = $currentUser->getSubuserInfo(); if (!$acl->isAllowed('subuser_manage_listings', $subUserInfo['sid'])) { $this->requestCriteria['subuser_sid'] = array('equal' => $subUserInfo['sid']); } } SJB_ListingManager::deletePreviewListingsByUserSID($userSID); $searcher = new SJB_ListingSearcher(); // to save criteria in the session different from search_results $criteriaSaver = new SJB_ListingCriteriaSaver('MyListings'); if (isset($_REQUEST['restore'])) { $_REQUEST = array_merge($_REQUEST, $criteriaSaver->getCriteria()); } if (isset($_REQUEST['listings'])) { $listingsSIDs = $_REQUEST['listings']; if (isset($_REQUEST['action_deactivate'])) { $this->executeAction($listingsSIDs, 'deactivate'); } elseif (isset($_REQUEST['action_activate'])) { $redirectToShoppingCard = false; $activatedListings = array(); foreach ($listingsSIDs as $listingSID => $value) { $listingInfo = SJB_ListingManager::getListingInfoBySID($listingSID); $productInfo = !empty($listingInfo['product_info']) ? unserialize($listingInfo['product_info']) : array(); if ($listingInfo['active']) { continue; } else { if (SJB_ListingManager::getIfListingHasExpiredBySID($listingSID) && isset($productInfo['renewal_price']) && $productInfo['renewal_price'] > 0) { $redirectToShoppingCard = true; $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listingInfo['listing_type_sid']); $newProductName = "Reactivation of \"{$listingInfo['Title']}\" {$listingTypeId}"; $newProductInfo = SJB_ShoppingCart::createInfoForCustomProduct($userSID, $productInfo['product_sid'], $listingSID, $productInfo['renewal_price'], $newProductName, 'activateListing'); SJB_ShoppingCart::createCustomProduct($newProductInfo, $userSID); } else { if ($listingInfo['checkouted'] == 0) { $redirectToShoppingCard = true; } else { if (SJB_ListingManager::activateListingBySID($listingSID, false)) { $listing = SJB_ListingManager::getObjectBySID($listingSID); SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID()); $activatedListings[] = $listingSID; } } } } } SJB_BrowseDBManager::addListings($activatedListings); if ($redirectToShoppingCard) { $shoppingUrl = SJB_System::getSystemSettings('SITE_URL') . '/shopping-cart/'; SJB_HelperFunctions::redirect($shoppingUrl); } } else { if (isset($_REQUEST['action_delete'])) { $this->executeAction($listingsSIDs, 'delete'); $allowedPostBeforeCheckout = SJB_Settings::getSettingByName('allow_to_post_before_checkout'); foreach ($listingsSIDs as $listingSID => $value) { if ($allowedPostBeforeCheckout == true) { $this->deleteCheckoutedListingFromShopCart($listingSID, $userSID); } } } elseif (isset($_REQUEST['action_sendToApprove'])) { $processListingsIds = array(); foreach ($listingsSIDs as $listingSID => $value) { $processListingsIds[] = $listingSID; } SJB_ListingManager::setListingApprovalStatus($processListingsIds, 'pending'); } } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/my-listings/{$this->listingTypeID}/"); } $listing = new SJB_Listing(array(), $this->listingTypeSID); $idAliasInfo = $listing->addIDProperty(); $listing->addActivationDateProperty(); $listing->addKeywordsProperty(); $listing->addPicturesProperty(); $listingTypeIdAliasInfo = $listing->addListingTypeIDProperty(); $sortingFields = array(); $innerJoin = array(); $sortingField = SJB_Request::getVar("sorting_field", null); $sortingOrder = SJB_Request::getVar("sorting_order", null); if (isset($sortingField, $sortingOrder)) { $orderInfo = array('sorting_field' => $sortingField, 'sorting_order' => $sortingOrder); } else { $orderInfo = $criteriaSaver->getOrderInfo(); } if ($orderInfo['sorting_field'] == 'applications') { $innerJoin['applications'] = array('count' => 'count(`applications`.id) as appCount', 'join' => 'LEFT JOIN', 'join_field' => 'listing_id', 'join_field2' => 'sid', 'main_table' => 'listings'); $sortingFields['appCount'] = $orderInfo['sorting_order']; $searcher->setGroupByField(array('listings' => 'sid')); } else { if ($orderInfo['sorting_field'] == 'id') { $sortingFields['sid'] = $orderInfo['sorting_order']; } else { if ($orderInfo['sorting_field'] == 'subuser_sid') { $innerJoin['users'] = array('join' => 'LEFT JOIN', 'join_field' => 'sid', 'join_field2' => 'subuser_sid', 'main_table' => 'listings'); $sortingFields['username'] = $orderInfo['sorting_order']; } else { $property = $listing->getProperty($sortingField); if (!empty($property) && $property->isSystem()) { $sortingFields[$orderInfo['sorting_field']] = $orderInfo['sorting_order']; } else { $sortingFields['activation_date'] = 'DESC'; } } } } $this->requestCriteria['sorting_field'] = $orderInfo['sorting_field']; $this->requestCriteria['sorting_order'] = $orderInfo['sorting_order']; $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData(array_merge($_REQUEST, $this->requestCriteria), $listing); $aliases = new SJB_PropertyAliases(); $aliases->addAlias($idAliasInfo); $aliases->addAlias($listingTypeIdAliasInfo); $foundListingsSIDs = $searcher->getObjectsSIDsByCriteria($criteria, $aliases, $sortingFields, $innerJoin); $searchFormBuilder = new SJB_SearchFormBuilder($listing); $searchFormBuilder->registerTags($tp); $searchFormBuilder->setCriteria($criteria); // получим информацию о имеющихся листингах $listingsInfo = array(); $currentUserInfo = SJB_UserManager::getCurrentUserInfo(); $contractInfo['extra_info']['listing_amount'] = 0; if ($acl->isAllowed('post_' . $this->listingTypeID)) { $permissionParam = $acl->getPermissionParams('post_' . $this->listingTypeID); if (empty($permissionParam)) { $contractInfo['extra_info']['listing_amount'] = 'unlimited'; } else { $contractInfo['extra_info']['listing_amount'] = $permissionParam; } } $currentUser = SJB_UserManager::getCurrentUser(); $contractsSIDs = $currentUser->getContractID(); $listingsInfo['listingsNum'] = SJB_ContractManager::getListingsNumberByContractSIDsListingType($contractsSIDs, $this->listingTypeID); $listingsInfo['listingsMax'] = $contractInfo['extra_info']['listing_amount']; if ($listingsInfo['listingsMax'] === 'unlimited') { $listingsInfo['listingsLeft'] = 'unlimited'; } else { $listingsInfo['listingsLeft'] = $listingsInfo['listingsMax'] - $listingsInfo['listingsNum']; $listingsInfo['listingsLeft'] = $listingsInfo['listingsLeft'] < 0 ? 0 : $listingsInfo['listingsLeft']; } $tp->assign('listingTypeID', $this->listingTypeID); $tp->assign('listingTypeName', SJB_ListingTypeManager::getListingTypeNameBySID($this->listingTypeSID)); $tp->assign('listingsInfo', $listingsInfo); $tp->display('my_listings_form.tpl'); $page = SJB_Request::getVar('page', 1); $listingsPerPage = $criteriaSaver->getListingsPerPage(); //save 'listings per page' in the session if (empty($listingsPerPage)) { $listingsPerPage = 10; } $listingsPerPage = SJB_Request::getVar('listings_per_page', $listingsPerPage); $criteriaSaver->setSessionForListingsPerPage($listingsPerPage); $criteriaSaver->setSessionForCurrentPage($page); $criteriaSaver->setSessionForCriteria($_REQUEST); $criteriaSaver->setSessionForOrderInfo($orderInfo); $criteriaSaver->setSessionForObjectSIDs($foundListingsSIDs); // get Applications $appsGroups = SJB_Applications::getAppGroupsByEmployer($currentUserInfo['sid']); $apps = array(); foreach ($appsGroups as $group) { $apps[$group['listing_id']] = $group['count']; } $searchCriteriaStructure = $criteriaSaver->createTemplateStructureForCriteria(); $listingSearchStructure = $criteriaSaver->createTemplateStructureForSearch(); /**************** P A G I N G *****************/ if ($listingSearchStructure['current_page'] > $listingSearchStructure['pages_number']) { $listingSearchStructure['current_page'] = $listingSearchStructure['pages_number']; } if ($listingSearchStructure['current_page'] < 1) { $listingSearchStructure['current_page'] = 1; } $sortedFoundListingsSIDsByPages = array_chunk($foundListingsSIDs, $listingSearchStructure['listings_per_page'], true); /************* S T R U C T U R E **************/ $listingsStructure = array(); $listingStructureMetaData = array(); if (isset($sortedFoundListingsSIDsByPages[$listingSearchStructure['current_page'] - 1])) { foreach ($sortedFoundListingsSIDsByPages[$listingSearchStructure['current_page'] - 1] as $sid) { $listing = SJB_ListingManager::getObjectBySID($sid); $listing->addPicturesProperty(); $listingStructure = SJB_ListingManager::createTemplateStructureForListing($listing); $listingsStructure[$listing->getID()] = $listingStructure; if (isset($listingStructure['METADATA'])) { $listingStructureMetaData = array_merge($listingStructureMetaData, $listingStructure['METADATA']); } } } /*************** D I S P L A Y ****************/ $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $metadata = array(); $metadata['listing'] = $metaDataProvider->getMetaData($listingStructureMetaData); $waitApprove = SJB_ListingTypeManager::getWaitApproveSettingByListingType($this->listingTypeSID); $tp->assign('show_rates', SJB_Settings::getSettingByName('show_rates')); $tp->assign('show_comments', SJB_Settings::getSettingByName('show_comments')); $tp->assign('METADATA', $metadata); $tp->assign('sorting_field', $listingSearchStructure['sorting_field']); $tp->assign('sorting_order', $listingSearchStructure['sorting_order']); $tp->assign('property', $this->getSortableProperties()); $tp->assign('listing_search', $listingSearchStructure); $tp->assign('search_criteria', $searchCriteriaStructure); $tp->assign('listings', $listingsStructure); $tp->assign('waitApprove', $waitApprove); $tp->assign('apps', $apps); $hasSubusersWithListings = false; $subusers = SJB_UserManager::getSubusers($currentUserInfo['sid']); foreach ($subusers as $subuser) { if ($acl->isAllowed('subuser_add_listings', $subuser['sid']) || $acl->isAllowed('subuser_manage_listings', $subuser['sid'])) { $hasSubusersWithListings = true; break; } } $tp->assign('hasSubusersWithListings', $hasSubusersWithListings); $tp->display('my_listings.tpl'); }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $action = SJB_Request::getVar('action', 'search'); $template = SJB_Request::getVar('template', 'listings_statistics.tpl'); $errors = array(); $userGroups = SJB_UserGroupManager::getAllUserGroupsIDsAndCaptions(); foreach ($userGroups as $key => $userGroup) { unset($userGroups[$key]); $userGroups[$userGroup['id']] = $userGroup; } switch ($action) { case 'export': $period = SJB_Request::getVar('period', array()); $filter = SJB_Request::getVar('filter', false); $listingTypeSID = SJB_Request::getVar('listingTypeSID', false); $listingTypeID = SJB_ListingTypeManager::getListingTypeIDBySID($listingTypeSID); $sorting_field = SJB_Request::getVar('sorting_field', 'total'); $sorting_order = SJB_Request::getVar('sorting_order', 'DESC'); $statistics = array(); if ($filter) { $statistics = SJB_Statistics::getListingsStatistics($period, $listingTypeSID, $filter, $sorting_field, $sorting_order); if (!empty($statistics['errors'])) { $errors = $statistics['errors']; } } else { $errors[] = 'EMPTY_PARAMETER'; } $columnTitle = ''; if (strstr($filter, 'userGroup_')) { $userGroupSID = str_replace('userGroup_', '', $filter); if ($userGroups[$userGroupSID]['key'] == 'Employer') { $columnTitle = 'Company Name'; } else { $columnTitle = $userGroups[$userGroupSID]['caption'] . ' Name'; } } else { $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($filter); $columnTitle = $fieldInfo['caption']; } if (!$errors && $statistics) { $type = SJB_Request::getVar('type', 'csv'); $listingTypes = SJB_ListingTypeManager::getListingAllTypesForListType(); SJB_StatisticsExportController::createExportDirectory(); $exportProperties['title'] = $columnTitle; $exportProperties['regular'] = ''; if ($listingTypeID == 'Job') { $exportProperties['featured'] = ''; } $exportProperties['priority'] = ''; $exportProperties['total'] = 'Total'; $exportProperties['percent'] = '%'; foreach ($listingTypes as $listingType) { if ($listingType['id'] == $listingTypeSID) { switch ($listingType['key']) { case 'Job': $featuredTitle = "Number of Featured {$listingType['key']}s Posted"; $exportProperties['featured'] = $featuredTitle; case 'Resume': $regularTitle = "Number of Regular {$listingType['key']}s Posted"; $exportProperties['regular'] = $regularTitle; $priorityTitle = "Number of Priority {$listingType['key']}s Posted"; $exportProperties['priority'] = $priorityTitle; break; default: $regularTitle = 'Number of Regular "' . $listingType['caption'] . '" Listings Posted'; $exportProperties['regular'] = $regularTitle; $priorityTitle = 'Number of Priority "' . $listingType['caption'] . '" Listings Posted'; $exportProperties['priority'] = $priorityTitle; break; } } } switch ($type) { case 'csv': $exportData = SJB_StatisticsExportController::getListingExportData($statistics, $listingTypeID); $fileName = strtolower($listingTypeID) . '_statistics.csv'; SJB_StatisticsExportController::makeCSVExportFile($exportData, $fileName, "{$listingTypeID} Statistics"); SJB_StatisticsExportController::archiveAndSendExportFile(strtolower($listingTypeID) . '_statistics', 'csv'); break; case 'xls': $exportData = SJB_StatisticsExportController::getListingExportData($statistics, $listingTypeID); $fileName = strtolower($listingTypeID) . '_statistics.xls'; SJB_StatisticsExportController::makeXLSExportFile($exportData, $fileName, "{$listingTypeID} Statistics"); SJB_StatisticsExportController::archiveAndSendExportFile(strtolower($listingTypeID) . '_statistics', 'xls'); break; } break; } case 'search': $search = SJB_Request::getVar('search', false); $period = SJB_Request::getVar('period', array()); $filter = SJB_Request::getVar('filter', false); $listingTypeSID = SJB_Request::getVar('listingTypeSID', false); $sorting_field = SJB_Request::getVar('sorting_field', 'total'); $sorting_order = SJB_Request::getVar('sorting_order', 'DESC'); $statistics = array(); if ($search) { $i18n = SJB_I18N::getInstance(); $from = $i18n->getInput('date', $period['from']); $to = $i18n->getInput('date', $period['to']); if (!empty($period['from']) && !empty($period['to']) && strtotime($from) > strtotime($to)) { $errors[] = 'SELECTED_PERIOD_IS_INCORRECT'; } else { if ($filter) { $statistics = SJB_Statistics::getListingsStatistics($period, $listingTypeSID, $filter, $sorting_field, $sorting_order); if (!empty($statistics['errors'])) { $errors = $statistics['errors']; } } else { $errors[] = 'EMPTY_PARAMETER'; } } } $columnTitle = ''; if (strstr($filter, 'userGroup_')) { $userGroupSID = str_replace('userGroup_', '', $filter); if ($userGroups[$userGroupSID]['key'] == 'Employer') { $columnTitle = 'Company Name'; } else { $columnTitle = $userGroups[$userGroupSID]['caption'] . ' Name'; } $tp->assign('link', 'user'); } else { if (in_array($filter, array('Location_Country', 'Location_State', 'Location_City'))) { $fieldInfo = SJB_ListingFieldDBManager::getLocationFieldsInfoById($filter); } else { $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($filter); } $columnTitle = $fieldInfo['caption']; } $i18n = SJB_I18N::getInstance(); $periodView = array(); foreach ($period as $key => $value) { $periodView[$key] = $i18n->getInput('date', $period[$key]); } $tp->assign('filter', $filter); $tp->assign('search', $search); $tp->assign('columnTitle', $columnTitle); $tp->assign('listingTypeSID', $listingTypeSID); $tp->assign('period', $period); $tp->assign('periodView', $periodView); $tp->assign('statistics', $statistics); $tp->assign('countResult', count($statistics)); $tp->assign('sorting_field', $sorting_field); $tp->assign('sorting_order', $sorting_order); break; } $listingTypes = SJB_ListingTypeManager::getListingAllTypesForListType(); $products = SJB_ProductsManager::getAllProductsInfo(); $acl = SJB_Acl::getInstance(); foreach ($listingTypes as $key => $listingType) { $userGroup = array(); foreach ($products as $productInfo) { if ($acl->isAllowed('post_' . strtolower($listingType['key']), $productInfo['sid'], 'product') && !in_array($productInfo['user_group_sid'], $userGroup)) { $userGroup[] = $productInfo['user_group_sid']; } } $listingTypes[$listingType['id']] = $listingType; $listingTypes[$listingType['id']]['userGroups'] = $userGroup; unset($listingTypes[$key]); } $tp->assign('userGroups', $userGroups); $tp->assign('listingTypes', $listingTypes); $tp->assign('errors', $errors); $tp->assign('action', $action); $tp->display($template); }
public static function canCurrentUserAddListing(&$error, $listingTypeId = false) { $acl = SJB_Acl::getInstance(); if (SJB_UserManager::isUserLoggedIn()) { $current_user = SJB_UserManager::getCurrentUser(); if ($current_user->hasContract()) { $contracts_id = $current_user->getContractID(); $contractsSIDs = $contracts_id ? implode(',', $contracts_id) : 0; $resultContractInfo = SJB_DB::query("SELECT `id`, `product_sid`, `expired_date`, `number_of_postings` FROM `contracts` WHERE `id` in ({$contractsSIDs}) ORDER BY `expired_date` DESC"); $PlanAcces = count($resultContractInfo) > 0 ? true : false; if ($PlanAcces && $acl->isAllowed('post_' . $listingTypeId)) { $productsInfo = array(); $is_contract = false; foreach ($resultContractInfo as $contractInfo) { if ($acl->isAllowed('post_' . $listingTypeId, $contractInfo['id'], 'contract')) { $permissionParam = $acl->getPermissionParams('post_' . $listingTypeId, $contractInfo['id'], 'contract'); if (empty($permissionParam) || $acl->getPermissionParams('post_' . $listingTypeId, $contractInfo['id'], 'contract') > $contractInfo['number_of_postings']) { $product = SJB_ProductsManager::getProductInfoBySID($contractInfo['product_sid']); $productsInfo[$contractInfo['id']]['product_name'] = $product['name']; $productsInfo[$contractInfo['id']]['expired_date'] = $contractInfo['expired_date']; $productsInfo[$contractInfo['id']]['contract_id'] = $contractInfo['id']; } } $is_contract = true; } if ($is_contract && count($productsInfo) > 0) { return $productsInfo; } else { $error = 'LISTINGS_NUMBER_LIMIT_EXCEEDED'; } } else { $error = 'DO_NOT_MATCH_POST_THIS_TYPE_LISTING'; } } else { $error = 'NO_CONTRACT'; } } else { $error = 'NOT_LOGGED_IN'; } return false; }
public function execute() { ini_set('max_execution_time', 0); $tp = SJB_System::getTemplateProcessor(); $file_info = isset($_FILES['import_file']) ? $_FILES['import_file'] : null; $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8'); $listingTypeID = SJB_Request::getVar('listing_type_id', null); $productSID = SJB_Request::getVar('product_sid', 0); $errors = array(); if ($listingTypeID && $productSID) { $acl = SJB_Acl::getInstance(); $resource = 'post_' . strtolower($listingTypeID); if (!$acl->isAllowed($resource, $productSID, 'product')) { $errors[] = 'You cannot import listings of this type under the selected product'; } } if (!empty($file_info)) { $extension = SJB_Request::getVar('file_type'); if (!SJB_ImportFile::isValidFileExtensionByFormat($extension, $file_info)) { $errors['DO_NOT_MATCH_SELECTED_FILE_FORMAT'] = true; } } if (empty($file_info) || $file_info['error'] || $errors) { if (isset($file_info['error']) && $file_info['error'] > 0) { $errors[SJB_UploadFileManager::getErrorId($file_info['error'])] = 1; } $listing_types = SJB_ListingTypeManager::getAllListingTypesInfo(); $products = SJB_ProductsManager::getProductsByProductType('post_listings'); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->assign('listing_types', $listing_types); $tp->assign('products', $products); $tp->assign('errors', $errors); $tp->assign('charSets', SJB_HelperFunctions::getCharSets()); $tp->display('import_listings.tpl'); } else { $i18n = SJB_I18N::getInstance(); $csv_delimiter = SJB_Request::getVar('csv_delimiter', null); $activeStatus = SJB_Request::getVar('active', 0); $activationDate = SJB_Request::getVar('activation_date', date('Y-m-d')); $activationDate = $i18n->getInput('date', $activationDate); $non_existed_values_flag = SJB_Request::getVar('non_existed_values', null); $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID); if (empty($productInfo['listing_duration'])) { $expirationDate = ''; } else { $timestamp = strtotime($activationDate . ' + ' . $productInfo['listing_duration'] . ' days'); $expirationDate = $i18n->getDate(date('Y-m-d', $timestamp)); } $extension = $_REQUEST['file_type']; if ($extension == 'xls') { $import_file = new SJB_ImportFileXLS($file_info); } elseif ($extension == 'csv') { $import_file = new SJB_ImportFileCSV($file_info, $csv_delimiter); } $import_file->parse($encodingFromCharset); $listing = $this->CreateListing(array(), $listingTypeID); $imported_data = $import_file->getData(); $isFileImported = true; $count = 0; $addedListingsSids = array(); $nonExistentUsers = array(); foreach ($imported_data as $key => $importedColumn) { if ($key == 1) { $imported_data_processor = new SJB_ImportedDataProcessor($importedColumn, $listing); continue; } if (!$importedColumn) { continue; } $count++; $listingInfo = $imported_data_processor->getData($non_existed_values_flag, $importedColumn); $doc = new DOMDocument(); foreach ($listing->getProperties() as $property) { if ($property->getType() == 'complex' && !empty($listingInfo[$property->id])) { $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid); $doc->loadXML($listingInfo[$property->id]); $results = $doc->getElementsByTagName($property->id . 's'); $listingInfo[$property->id] = array(); foreach ($results as $complexparent) { $i = 1; foreach ($complexparent->getElementsByTagName($property->id) as $result) { $resultXML = simplexml_import_dom($result); foreach ($childFields as $childField) { if (isset($resultXML->{$childField}['id'])) { $listingInfo[$property->id][$childField['id']][$i] = XML_Util::reverseEntities((string) $resultXML->{$childField}['id']); } } $i++; } } } elseif ($property->getType() == 'monetary' && !empty($listingInfo[$property->id])) { $value = $listingInfo[$property->id]; $listingInfo[$property->id] = array(); $listingInfo[$property->id]['value'] = $value; $defaultCurrency = SJB_CurrencyManager::getDefaultCurrency(); $currencyCode = !empty($listingInfo[$property->id . "Currency"]) ? $listingInfo[$property->id . "Currency"] : $defaultCurrency['currency_code']; $currency = SJB_CurrencyManager::getCurrencyByCurrCode($currencyCode); $listingInfo[$property->id]['add_parameter'] = !empty($currency['sid']) ? $currency['sid'] : ''; if (isset($listingInfo[$property->id . "Currency"])) { unset($listingInfo[$property->id . "Currency"]); } } elseif ($property->getType() == 'location') { $locationFields = array($property->id . '.Country', $property->id . '.State', $property->id . '.City', $property->id . '.ZipCode'); $locationFieldAdded = array(); foreach ($locationFields as $locationField) { if (array_key_exists($locationField, $listingInfo)) { switch ($locationField) { case $property->id . '.Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]); } break; case $property->id . '.State': $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]); } break; default: $value = $listingInfo[$locationField]; break; } $listingInfo[$property->id][str_replace($property->id . '.', '', $locationField)] = $value; $locationFieldAdded[] = str_replace($property->id . '.', '', $locationField); } } if ($property->id == 'Location') { $locationFields = array('Country', 'State', 'City', 'ZipCode'); foreach ($locationFields as $locationField) { if (array_key_exists($locationField, $listingInfo) && !in_array($locationField, $locationFieldAdded) && !$listing->getProperty($locationField)) { switch ($locationField) { case 'Country': $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]); if (!$value) { $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]); } break; case 'State': $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]); if (!$value) { $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]); } break; default: $value = $listingInfo[$locationField]; break; } $listingInfo[$property->id][$locationField] = $value; } } } } } $listing = $this->CreateListing($listingInfo, $listingTypeID); $pictures = array(); if (isset($listingInfo['pictures'])) { $listing->addPicturesProperty(); $explodedPictures = explode(';', $listingInfo['pictures']); foreach ($explodedPictures as $picture) { if (!empty($picture)) { $pictures[] = $picture; } } $listing->setPropertyValue('pictures', count($pictures)); } $listing->addActiveProperty($activeStatus); $listing->addActivationDateProperty($activationDate); $listing->addExpirationDateProperty($expirationDate); SJB_ListingDBManager::setListingExpirationDateBySid($listing->sid); $listing->setProductInfo(SJB_ProductsManager::getProductExtraInfoBySID($productSID)); $listing->setPropertyValue('access_type', 'everyone'); $listing->setPropertyValue('status', 'approved'); foreach ($listing->getProperties() as $property) { if ($property->getType() == 'tree' && $property->value !== '') { try { $treeImportHelper = new SJB_FieldTreeImportHelper($property->value); $treeValues = $treeImportHelper->parseAndGetValues(); $listing->setPropertyValue($property->id, $treeValues); $listing->details->properties[$property->id]->type->property_info['value'] = $treeValues; } catch (Exception $e) { $listing->setPropertyValue($property->id, ''); $listing->details->properties[$property->id]->type->property_info['value'] = ''; SJB_Error::writeToLog('Listing Import. Tree Field Value Error: ' . $e->getMessage()); } } elseif ($property->id == 'ApplicationSettings' && !empty($listingInfo['ApplicationSettings'])) { if (preg_match("^[a-z0-9\\._-]+@[a-z0-9\\._-]+\\.[a-z]{2,}\$^iu", $listingInfo['ApplicationSettings'])) { $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 1); } elseif (preg_match("^(https?:\\/\\/)^", $listingInfo['ApplicationSettings'])) { $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 2); } else { $listingInfo['ApplicationSettings'] = array('value' => '', 'add_parameter' => ''); } //put empty if not valid email or url $listing->details->properties[$property->id]->type->property_info['value'] = $listingInfo['ApplicationSettings']; } elseif ($property->getType() == 'complex') { $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid); $complexChildValues = $property->value; foreach ($childFields as $childField) { if ($childField['type'] == 'complexfile' && !empty($complexChildValues[$childField['id']])) { $fieldInfo = SJB_ListingComplexFieldManager::getFieldInfoBySID($childField['sid']); if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo, $property->id)) { $isFileImported = false; } } if ($property->type->complex->details->properties[$childField['id']]->value == null) { $property->type->complex->details->properties[$childField['id']]->value = array(1 => ''); $property->type->complex->details->properties[$childField['id']]->type->property_info['value'] = array(1 => ''); } } } // The import of files at import of listings if (in_array($property->getType(), array('file', 'logo', 'video')) && $property->value !== '') { $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($property->id); if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo)) { $isFileImported = false; } } } if ($non_existed_values_flag == 'add') { $this->UpdateListValues($listing); } if ($listing->getUserSID()) { SJB_ListingManager::saveListing($listing); $listingSid = $listing->getSID(); SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listingSid); SJB_ListingManager::activateListingBySID($listingSid, false); if (!$this->fillGallery($listingSid, $pictures)) { $isFileImported = false; } $addedListingsSids[] = $listingSid; } else { $nonExistentUsers[] = $listingInfo['username']; $count--; } } SJB_BrowseDBManager::addListings($addedListingsSids); SJB_ProductsManager::incrementPostingsNumber($productSID, count($addedListingsSids)); if ($isFileImported && file_exists(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY'))) { SJB_Filesystem::delete(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY')); } $tp->assign('imported_listings_count', $count); $tp->assign('nonExistentUsers', $nonExistentUsers); $tp->display('import_listings_result.tpl'); } }
/** * @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); } } }
/** * get SJB_Function instance by function name and module name * * @param $script_filename * @param $function_name * @param $module_name * @param SJB_Acl $acl * @param array $params * $param int $aclRoleID * @return SJB_Function */ public function getFunction($function_name, $module_name, $params = array()) { $aclRoleID = null; $adminAccessType = SJB_System::getSystemSettings('SYSTEM_ACCESS_TYPE') == SJB_System::getSystemSettings('ADMIN_ACCESS_TYPE'); $accessTypePrefix = $adminAccessType ? 'Admin_' : ''; if ($adminAccessType && SJB_SubAdmin::admin_authed()) { $aclRoleID = SJB_SubAdmin::getSubAdminSID(); $acl = SJB_SubAdminAcl::getInstance(); } else { $acl = SJB_Acl::getInstance(); $cu = SJB_UserManager::getCurrentUser(); if (!empty($cu) && $cu->isSubuser()) { $cu = $cu->getSubuserInfo(); $aclRoleID = SJB_Array::get($cu, 'sid'); } } $functionPart = $this->getCamelCaseName($function_name); $modulePart = $this->getCamelCaseName($module_name); $className = 'SJB_' . $accessTypePrefix . $modulePart . '_' . $functionPart; return new $className($acl, $params, $aclRoleID); }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $template = SJB_Request::getVar('input_template', 'input_form.tpl'); $error = null; $listingTypeID = SJB_Request::getVar('listing_type_id', false); $passed_parameters_via_uri = SJB_Request::getVar('passed_parameters_via_uri', false); $pageID = false; if ($passed_parameters_via_uri) { $passed_parameters_via_uri = SJB_UrlParamProvider::getParams(); $listingTypeID = isset($passed_parameters_via_uri[0]) ? $passed_parameters_via_uri[0] : $listingTypeID; $pageID = isset($passed_parameters_via_uri[1]) ? $passed_parameters_via_uri[1] : false; $listing_id = isset($passed_parameters_via_uri[2]) ? $passed_parameters_via_uri[2] : false; } if (SJB_UserManager::isUserLoggedIn()) { $post_max_size_orig = ini_get('post_max_size'); $server_content_length = isset($_SERVER['CONTENT_LENGTH']) ? $_SERVER['CONTENT_LENGTH'] : null; $fromPreview = SJB_Request::getVar('from-preview', false); // get post_max_size in bytes $val = trim($post_max_size_orig); $tmp = substr($val, strlen($val) - 1); $tmp = strtolower($tmp); /* if ini value is K - then multiply to 1024 * if ini value is M - then multiply twice: in case 'm', and case 'k' * if ini value is G - then multiply tree times: in 'g', 'm', 'k' * out value - in bytes! */ switch ($tmp) { case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } $post_max_size = $val; $filename = SJB_Request::getVar('filename', false); if ($filename) { $file = SJB_UploadFileManager::openFile($filename, $listing_id); $errors['NO_SUCH_FILE'] = true; } if (empty($_POST) && $server_content_length > $post_max_size) { $errors['MAX_FILE_SIZE_EXCEEDED'] = 1; $tp->assign('post_max_size', $post_max_size_orig); } $listingInfo = SJB_ListingManager::getListingInfoBySID($listing_id); $currentUser = SJB_UserManager::getCurrentUser(); $contractID = $listingInfo['contract_id']; if ($contractID == 0) { $extraInfo = unserialize($listingInfo['product_info']); $productSID = $extraInfo['product_sid']; } else { $contract = new SJB_Contract(array('contract_id' => $contractID)); $extraInfo = $contract->extra_info; } if ($listingInfo['user_sid'] != SJB_UserManager::getCurrentUserSID()) { $errors['NOT_OWNER_OF_LISTING'] = $listing_id; } else { $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID); $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listing_type_sid); if (!$pageID) { $pageID = $pages[0]['page_id']; } $pageSID = SJB_PostingPagesManager::getPostingPageSIDByID($pageID, $listing_type_sid); $isPageLast = SJB_PostingPagesManager::isLastPageByID($pageSID, $listing_type_sid); // preview listing $isPreviewListingRequested = SJB_Request::getVar('preview_listing', false, 'POST'); $form_submitted = isset($_REQUEST['action_add']) || isset($_REQUEST['action_add_pictures']) || $isPreviewListingRequested; // fill listing from an array of social data if allowed $aAutoFillData = array('formSubmitted' => &$form_submitted, 'listingTypeID' => &$listingTypeID); SJB_Event::dispatch('SocialSynchronization', $aAutoFillData); $listingInfo = array_merge($listingInfo, $_REQUEST); $listing = new SJB_Listing($listingInfo, $listing_type_sid, $pageSID); if ($fromPreview) { if ($form_submitted) { $properties = $listing->getProperties(); foreach ($properties as $fieldID => $property) { switch ($property->getType()) { case 'date': if (!empty($listing_info[$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; } } $listing = new SJB_Listing($listingInfo, $listing_type_sid, $pageSID); } } $previousComplexFields = $this->processComplexFields($listing, $listingInfo); $listing->deleteProperty('featured'); $listing->deleteProperty('priority'); $listing->deleteProperty('status'); $listing->deleteProperty('reject_reason'); $listing->deleteProperty('ListingLogo'); $listing->setSID($listing_id); $access_type = $listing->getProperty('access_type'); if ($form_submitted && !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($currentUser->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($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 deletes it if sync is turned off in admin part */ if ($pages[0]['page_id'] == $pageID) { $aAutoFillData = array('oListing' => &$listing, 'userSID' => $currentUser->getSID(), 'listingTypeID' => $listingTypeID, 'listing_info' => $listingInfo); SJB_Event::dispatch('SocialSynchronizationFields', $aAutoFillData); } $add_listing_form = new SJB_Form($listing); $add_listing_form->registerTags($tp); $field_errors = array(); if ($form_submitted && (SJB_Session::getValue(self::PREVIEW_LISTING_SID) == $listing_id || $add_listing_form->isDataValid($field_errors))) { /* delete temp preview listing sid */ SJB_Session::unsetValue(self::PREVIEW_LISTING_SID); if ($isPageLast) { $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true)); } $listing->setUserSID($currentUser->getSID()); if (empty($access_type->value)) { $listing->setPropertyValue('access_type', 'everyone'); } if (isset($_SESSION['tmp_file_storage'])) { foreach ($_SESSION['tmp_file_storage'] as $k => $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-1197 SJB_ListingManager::saveListing($listing); foreach ($previousComplexFields as $propertyId) { $listing->deleteProperty($propertyId); } if ($isPageLast && !$isPreviewListingRequested) { $listingSID = $listing->getSID(); $listing = SJB_ListingManager::getObjectBySID($listingSID); $listing->setSID($listingSID); $keywords = $listing->getKeywords(); SJB_ListingManager::updateKeywords($keywords, $listing->getSID()); // Start Event $listingSid = $listing->getSID(); SJB_Event::dispatch('listingSaved', $listingSid); // is listing featured by default if ($extraInfo['featured']) { SJB_ListingManager::makeFeaturedBySID($listing->getSID()); } if ($extraInfo['priority']) { SJB_ListingManager::makePriorityBySID($listing->getSID()); } if ($contractID) { 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($listingTypeID) . '/?listing_id=' . $listing->getSID()); } } else { SJB_ListingManager::unmakeCheckoutedBySID($listing->getSID()); $this->proceedToCheckout($currentUser->getSID(), $productSID); } } elseif ($isPageLast && $isPreviewListingRequested) { // for listing preview SJB_Session::setValue(self::PREVIEW_LISTING_SID, $listing->getSID()); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/' . strtolower($listingTypeID) . '-preview/' . $listing->getSID() . '/'); } else { // listing steps (pages) SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/add-listing/{$listingTypeID}/" . SJB_PostingPagesManager::getNextPage($pageSID) . '/' . $listing->getSID()); } } else { foreach ($previousComplexFields as $propertyId) { $listing->deleteProperty($propertyId); } $listing->deleteProperty('access_list'); $listing->deleteProperty('contract_id'); $add_listing_form = new SJB_Form($listing); if (SJB_Request::get('action_add') == 'Next') { $add_listing_form->setUseDefaultValues(); } if ($form_submitted) { $add_listing_form->isDataValid($field_errors); } $add_listing_form->registerTags($tp); $form_fields = $add_listing_form->getFormFieldsInfo(); $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); } else { $access_type = $listing->getPropertyValue('access_type'); $employers = SJB_ListingManager::getListingAccessList($listing_id, $access_type); } $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0; $tp->assign('pic_limit', $numberOfPictures); $tp->assign('listing_sid', $listing_id); $tp->assign('listing_id', $listing_id); $tp->assign('listingSID', $listing->getSID()); $tp->assign('listing_access_list', $employers); $tp->assign('listingTypeID', $listingTypeID); $tp->assign('contract_id', $contractID); $tp->assign('field_errors', $field_errors); $tp->assign('form_fields', $form_fields); $tp->assign("extraInfo", $extraInfo); $tp->assign('pages', $pages); $tp->assign('pageSID', $pageSID); $tp->assign('currentPage', SJB_PostingPagesManager::getPageInfoBySID($pageSID)); $tp->assign('isPageLast', $isPageLast); $tp->assign('nextPage', SJB_PostingPagesManager::getNextPage($pageSID)); $tp->assign('prevPage', SJB_PostingPagesManager::getPrevPage($pageSID)); $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields))); // social plugin only for Resume listing types $aAutoFillData = array('tp' => &$tp, 'listingTypeID' => $listingTypeID, 'userSID' => $currentUser->getSID()); SJB_Event::dispatch('SocialSynchronizationForm', $aAutoFillData); SJB_Session::unsetValue(self::PREVIEW_LISTING_SID); $tp->display($template); } } } else { $tp->assign('listingTypeID', $listingTypeID); $tp->assign('error', 'NOT_LOGGED_IN'); $tp->display('add_listing_error.tpl'); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $isAlert = $enableNotify = isset($_REQUEST["alert"]); $tp->assign('is_alert', $isAlert); if (SJB_UserManager::isUserLoggedIn()) { $cu = SJB_UserManager::getCurrentUser(); if ($cu->isSubuser()) { $current_user_info = $cu->getSubuserInfo(); } else { $current_user_info = SJB_UserManager::getCurrentUserInfo(); } $criteria_saver = new SJB_ListingCriteriaSaver(SJB_Request::getVar("searchId", "")); $requested_data = $criteria_saver->getCriteria(); if (isset($requested_data['listing_type'])) { $current_listing_type = array_pop($requested_data['listing_type']); } else { $current_listing_type = ''; if (isset($requested_data['listing_type_sid'])) { $listing_type_sid = array_pop($requested_data['listing_type_sid']); $current_listing_type = SJB_ListingTypeManager::getListingTypeIDBySID($listing_type_sid); } } $errors = array(); if (!$isAlert && !SJB_Acl::getInstance()->isAllowed('save_searches')) { $errors[] = "DENIED_SAVE_JOB_SEARCH"; } elseif ($isAlert && !SJB_Acl::getInstance()->isAllowed('use_' . trim($current_listing_type) . '_alerts')) { $errors[] = "DENIED_SAVE_JOB_SEARCH"; } switch (SJB_Request::getVar("action")) { case 'edit': unset($_GET['action']); if (isset($_GET['id_saved'])) { $id_saved = $_GET['id_saved']; unset($_GET['id_saved']); $errors = array(); SJB_SavedSearches::updateSearchOnDB($_GET, $id_saved, $current_user_info['sid'], 0); if (!empty($errors)) { $tp->assign("errors", $errors); $tp->display("save_search_failed.tpl"); } else { $url = SJB_System::getSystemSettings('SITE_URL') . "/saved-searches/"; if ($isAlert) { $url = SJB_System::getSystemSettings('SITE_URL') . "/job-alerts/"; } $tp->assign("url", $url); $tp->display("save_search_success.tpl"); } } break; case 'save': $search_name = SJB_Request::getVar("search_name"); $errors = array(); $criteria_saver = new SJB_ListingCriteriaSaver(SJB_Request::getVar("searchId", "")); $requested_data = $criteria_saver->getCriteria(); if (is_array($criteria_saver->order_info)) { $requested_data = array_merge($requested_data, $criteria_saver->order_info); } $requested_data['listings_per_page'] = $criteria_saver->listings_per_page; $emailFrequency = SJB_Request::getVar("email_frequency", 'daily'); SJB_SavedSearches::saveSearchOnDB($requested_data, $search_name, $current_user_info['sid'], $enableNotify, $isAlert, $emailFrequency); if (!empty($errors)) { $tp->assign("errors", $errors); $tp->display("save_search_failed.tpl"); } else { if (isset($_REQUEST['url'])) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . $_REQUEST['url'] . "?alert=added"); } $tp->display("save_search_success.tpl"); } break; default: if (!empty($errors)) { $tp->assign("errors", $errors); $tp->display("save_search_failed.tpl"); } else { $tp->assign("searchId", SJB_Request::getVar("searchId", "")); $tp->assign("listing_type_id", SJB_Session::getValue('listing_type_id')); $tp->display("save_search_form.tpl"); } break; } } else { $tp->assign("return_url", base64_encode(SJB_Navigator::getURIThis())); $tp->assign("ajaxRelocate", true); $tp->display("../users/login.tpl"); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $user_info = SJB_Authorization::getCurrentUserInfo(); if (!empty($user_info['subuser'])) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/sub-accounts/edit/?user_id=' . $user_info['subuser']['sid']); } if (!empty($user_info)) { $user_info = array_merge($user_info, $_REQUEST); $username = $user_info['username']; $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_info['user_group_sid']); $delete_profile = SJB_Request::getVar('command', '', 'post') == 'unregister-user'; $errors = array(); if ($delete_profile && SJB_Acl::getInstance()->isAllowed('delete_user_profile')) { try { $user = SJB_UserManager::getObjectBySID($user_info['sid']); SJB_UserManager::deleteUserById($user_info['sid']); SJB_AdminNotifications::sendAdminDeletingUserProfile($user, SJB_Request::getVar('reason', '', 'post')); SJB_Authorization::logout(); $user_info = array(); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/edit-profile/?profile_deleted=true'); } catch (Exception $e) { $errors[] = $e->getMessage(); } } $user = new SJB_User($user_info, $user_info['user_group_sid']); $user->setSID($user_info['sid']); $user->deleteProperty("active"); $user->deleteProperty("featured"); $user->makePropertyNotRequired("password"); $user->getProperty('email')->type->disableEmailConfirmation(); $edit_profile_form = new SJB_Form($user); $edit_profile_form->registerTags($tp); $edit_profile_form->makeDisabled("username"); $form_submitted = SJB_Request::getVar('action', false) == 'save_info'; if ($form_submitted && $edit_profile_form->isDataValid($errors)) { $password_value = $user->getPropertyValue('password'); if (empty($password_value['original'])) { $user->deleteProperty('password'); } SJB_UserManager::saveUser($user); SJB_Authorization::updateCurrentUserSession(); // >>> SJB-1197 // needs to check session for ajax-uploaded files, and set it to user profile $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage'); $formToken = SJB_Request::getVar('form_token'); if (!empty($formToken)) { $tmpUploadedFields = SJB_Array::getPath($tmpUploadsStorage, $formToken); if (!is_null($tmpUploadsStorage) && is_array($tmpUploadedFields)) { // prepare user profile fields array $userProfileFieldsInfo = SJB_UserProfileFieldManager::getAllFieldsInfo(); $userProfileFields = array(); foreach ($userProfileFieldsInfo as $field) { $userProfileFields[$field['id']] = $field; } // look for temporary values foreach ($tmpUploadedFields as $fieldId => $fieldInfo) { // check field ID for valid ID in user profile fields if (!array_key_exists($fieldId, $userProfileFields) || empty($fieldInfo)) { continue; } $fieldType = $userProfileFields[$fieldId]['type']; $profilePropertyId = $fieldId . '_' . $user->getSID(); switch (strtolower($fieldType)) { case 'video': case 'file': // change temporary file ID SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']); // set value of user property to new uploaded file $user->setPropertyValue($fieldId, $profilePropertyId); break; case 'logo': // change temporary file ID and thumb ID SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']); SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId . '_thumb', $fieldInfo['file_id'] . '_thumb'); // set value of user property to new uploaded file $user->setPropertyValue($fieldId, $profilePropertyId); break; default: break; } $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}/{$fieldId}"); } // and save user with new fields data SJB_UserManager::saveUser($user); SJB_Authorization::updateCurrentUserSession(); // clean temporary storage $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}"); // CLEAR TEMPORARY SESSION STORAGE SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage); } } // <<< SJB-1197 $tp->assign("form_is_submitted", true); } else { $tp->assign("errors", $errors); } $form_fields = $edit_profile_form->getFormFieldsInfo(); $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields))); $tp->assign("show_mailing_flag", $user_group_info['show_mailing_flag']); $tp->assign("form_fields", $form_fields); $tp->assign('userTree', true); $tp->display('edit_profile.tpl'); } elseif (empty($user_info) && SJB_Request::getVar('profile_deleted', '') == true) { $user = new SJB_User(array()); $edit_profile_form = new SJB_Form($user); $edit_profile_form->registerTags($tp); $edit_profile_form->makeDisabled("username"); $form_fields = $edit_profile_form->getFormFieldsInfo(); $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields))); $tp->assign("form_fields", $form_fields); $tp->assign('action', 'delete_profile'); $tp->assign('tree_link_users', 'users'); $tp->assign('userTree', true); $tp->display('edit_profile.tpl'); } else { $tp->assign("ERROR", "NOT_LOGIN"); $tp->display("../miscellaneous/error.tpl"); return; } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $errors = array(); $template = 'sub_accounts.tpl'; $currentUserInfo = SJB_UserManager::getCurrentUserInfo(); $listSubusers = false; if (!empty($currentUserInfo['subuser']) && SJB_Request::getVar('action_name') != 'edit' && SJB_Request::getVar('user_id', 0) != $currentUserInfo['subuser']['sid']) { $errors['ACCESS_DENIED'] = 'ACCESS_DENIED'; } switch (SJB_Request::getVar('action_name')) { case 'new': $form_submitted = SJB_Request::getMethod() === SJB_Request::METHOD_POST; $user_group_sid = $currentUserInfo['user_group_sid']; $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid); $_REQUEST['user_group_id'] = $user_group_info['id']; $user = SJB_ObjectMother::createUser($_REQUEST, $user_group_sid); $props = $user->getProperties(); $allowedProperties = array('username', 'email', 'password'); foreach ($props as $prop) { if (!in_array($prop->getID(), $allowedProperties)) { $user->deleteProperty($prop->getID()); } } $registration_form = SJB_ObjectMother::createForm($user); $registration_form->registerTags($tp); if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_group_sid) && $form_submitted) { $email = $user->getPropertyValue('email'); if (is_array($email)) { $email = $email['original']; } $user->setPropertyValue('username', $email); } $registration_form = SJB_ObjectMother::createForm($user); if ($form_submitted && $registration_form->isDataValid($errors)) { $user->addParentProperty($currentUserInfo['sid']); $subuserPermissions = array('subuser_add_listings' => array('title' => 'Add new listings', 'value' => 'deny'), 'subuser_manage_listings' => array('title' => 'Manage listings and applications of other sub users', 'value' => 'deny'), 'subuser_manage_subscription' => array('title' => 'View and update subscription', 'value' => 'deny'), 'subuser_use_screening_questionnaires' => array('title' => 'Manage Questionnaries', 'value' => 'deny')); SJB_UserManager::saveUser($user); SJB_Statistics::addStatistics('addSubAccount', $user->getUserGroupSID(), $user->getSID()); SJB_Acl::clearPermissions('user', $user->getSID()); foreach ($subuserPermissions as $permissionID => $permission) { $allowDeny = SJB_Request::getVar($permissionID, 'deny'); $subuserPermissions[$permissionID]['value'] = $allowDeny; SJB_Acl::allow($permissionID, 'user', $user->getSID(), $allowDeny); } SJB_UserManager::activateUserByUserName($user->getUserName()); SJB_Notifications::sendSubuserRegistrationLetter($user, SJB_Request::get(), $subuserPermissions); $tp->assign('isSubuserRegistered', true); $listSubusers = true; } else { if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_group_sid)) { $user->deleteProperty("username"); } $registration_form = SJB_ObjectMother::createForm($user); if ($form_submitted) { $registration_form->isDataValid($errors); } $registration_form->registerTags($tp); $form_fields = $registration_form->getFormFieldsInfo(); $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid); $tp->assign("user_group_info", $user_group_info); $tp->assign("errors", $errors); $tp->assign("form_fields", $form_fields); $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields))); $tp->display('subuser_registration_form.tpl'); } break; case 'edit': $userInfo = SJB_UserManager::getUserInfoBySID(SJB_Request::getVar('user_id', 0)); if (!empty($userInfo) && $userInfo['parent_sid'] === $currentUserInfo['sid']) { $userInfo = array_merge($userInfo, $_REQUEST); $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($currentUserInfo['user_group_sid']); $user = new SJB_User($userInfo, $userInfo['user_group_sid']); $user->setSID($userInfo['sid']); $user->addParentProperty($currentUserInfo['sid']); $props = $user->getProperties(); $allowedProperties = array('username', 'email', 'password'); foreach ($props as $prop) { if (!in_array($prop->getID(), $allowedProperties)) { $user->deleteProperty($prop->getID()); } } $user->makePropertyNotRequired("password"); $edit_profile_form = SJB_ObjectMother::createForm($user); $edit_profile_form->registerTags($tp); $edit_profile_form->makeDisabled("username"); $form_submitted = SJB_Request::getMethod() == SJB_Request::METHOD_POST; if (empty($errors) && $form_submitted && $edit_profile_form->isDataValid($errors)) { $password_value = $user->getPropertyValue('password'); if (empty($password_value['original'])) { $user->deleteProperty('password'); } $currentUser = SJB_UserManager::getCurrentUser(); if (!$currentUser->isSubuser()) { $subuserPermissions = array('subuser_add_listings', 'subuser_manage_listings', 'subuser_manage_subscription', 'subuser_use_screening_questionnaires'); SJB_Acl::clearPermissions('user', $user->getSID()); foreach ($subuserPermissions as $permission) { SJB_Acl::allow($permission, 'user', $user->getSID(), SJB_Request::getVar($permission, 'deny')); } } SJB_UserManager::saveUser($user); $tp->assign("form_is_submitted", true); } else { $tp->assign("errors", $errors); } $form_fields = $edit_profile_form->getFormFieldsInfo(); $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields))); $tp->assign("form_fields", $form_fields); $tp->assign('user_info', $userInfo); $tp->display('edit_subuser_profile.tpl'); } break; case 'delete': $users = SJB_Request::getVar('user_id', array()); foreach ($users as $user) { SJB_UserManager::deleteUserById($user); } $listSubusers = true; break; default: $listSubusers = true; break; } if ($listSubusers) { $tp->assign('errors', $errors); $tp->assign('subusers', SJB_UserManager::getSubusers($currentUserInfo['sid'])); $tp->assign('isEmailAsUsername', SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($currentUserInfo['user_group_sid'])); $tp->display($template); } }
function registerGlobalVariables() { $variables = SJB_System::getGlobalTemplateVariables(); foreach ($variables as $name => $value) { $this->assign($name, $value); } parse_str($_SERVER['QUERY_STRING'], $queryString); $params = array(); $uri = SJB_System::getURI(); if (!empty($_POST) && !in_array($uri, array('/paypal-pro-fill-payment-card/', '/add-invoice/', '/edit-invoice/', '/edit-product/', '/add-product/'))) { $queryString = array_merge($queryString, $_POST); } foreach ($queryString as $key => $val) { if (!in_array($key, array('lang', 'theme'))) { $params[$key] = $val; } } $this->assign('url', $uri); $this->assign('acl', SJB_Acl::getInstance()); $this->assign('params', http_build_query($params, '', '&')); $this->assign('isDemo', SJB_System::getSystemSettings("isDemo")); }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $userGroupSid = SJB_Request::getVar('user_group_sid', false); $productType = SJB_Request::getVar('product_type', false); $permissions_type = SJB_Request::getVar('permissions_type', 'additional'); $addedPermissions = false; $role = SJB_Request::getVar('role', false); $type = 'product'; $acl = SJB_Acl::getInstance(true); $resources = $acl->getResources($type); $product = new SJB_Product(array(), $productType); $additionalPermissions = $product->getAdditionalPermissions(); $accessPermissions = $product->getAccessPermissions(); $perms = SJB_DB::query('select * from `permissions` where `type` = ?s and `role` = ?s', $type, $role); $countGeneralPermissions = 0; foreach ($resources as $key => $resource) { switch ($permissions_type) { case 'additional': if (!in_array($key, $additionalPermissions)) { unset($resources[$key]); continue; } break; case 'access': if (!in_array($key, $accessPermissions)) { unset($resources[$key]); continue; } break; } $resources[$key]['value'] = 'inherit'; $resources[$key]['name'] = $key; foreach ($perms as $perm) { if ($key == $perm['name']) { $resources[$key]['value'] = $perm['value']; $resources[$key]['params'] = $perm['params']; $resources[$key]['message'] = $perm['message']; break; } } if (!empty($addedPermissions[$key])) { $params = isset($addedPermissions[$key . '_params']) ? $addedPermissions[$key . '_params'] : ''; $params1 = isset($addedPermissions[$key . '_params1']) ? $addedPermissions[$key . '_params1'] : ''; $message = isset($addedPermissions[$key . '_message']) ? $addedPermissions[$key . '_message'] : ''; if ($addedPermissions[$key] == 'deny' && $params1) { $params = $params1; } $resources[$key]['value'] = $addedPermissions[$key]; $resources[$key]['params'] = $params; $resources[$key]['message'] = $message; } if (isset($resources[$key]['group']) && $resources[$key]['group'] == 'general') { $countGeneralPermissions++; } } $tp->assign('countGeneralPermissions', $countGeneralPermissions); $tp->assign('resources', $resources); $tp->assign('listingTypes', SJB_ListingTypeManager::getAllListingTypesInfo()); $tp->assign('role', $role); $tp->assign('type', $type); $tp->assign('user_group_sid', $userGroupSid); $tp->display('product_permissions.tpl'); }
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'); } }