public function execute() { $tp = SJB_System::getTemplateProcessor(); $user_field_sid = SJB_Request::getVar('user_field_sid', null); $errors = array(); if (!is_null($user_field_sid)) { $profile_field = SJB_UserProfileFieldManager::getFieldInfoBySID($user_field_sid); $profile_field['user_group'] = SJB_UserGroupManager::getUserGroupIDBySID($profile_field['user_group_sid']); $tp->assign('fieldInfo', $profile_field); } else { $errors[] = 'The system cannot proceed as some required parameters are not set'; } $tp->assign('errors', $errors); $tp->display('instruction_user_profile_field.tpl'); }
public function execute() { $template = SJB_Request::getVar('display_template', 'my_reports.tpl'); $action = SJB_Request::getVar('action', 'quickStat'); $tp = SJB_System::getTemplateProcessor(); $errors = array(); $currentUser = SJB_UserManager::getCurrentUser(); if (empty($currentUser)) { $tp->assign('ERROR', 'NOT_LOGIN'); $tp->display('../miscellaneous/error.tpl'); return; } else { if (SJB_UserGroupManager::getUserGroupIDBySID($currentUser->getUserGroupSID()) == 'Employer') { switch ($action) { case 'generalStat': $generalStat = SJB_Statistics::getEmployerGeneralStatistics($currentUser->getSID()); $tp->assign('generalStat', $generalStat); break; case 'jobsStat': $active = SJB_Request::getVar('active', 1); $sortingField = SJB_Request::getVar('sortingField', 'postedDate'); $sortingOrder = SJB_Request::getVar('sortingOrder', 'DESC'); $jobsStat = SJB_Statistics::getEmployerJobsStatistics($currentUser->getSID(), $active, $sortingField, $sortingOrder); $tp->assign('jobsStat', $jobsStat); $tp->assign('active', $active); $tp->assign('sortingField', $sortingField); $tp->assign('sortingOrder', $sortingOrder); break; case 'quickStat': $quickStat = SJB_Statistics::getEmployerQuickStatistics($currentUser->getSID()); $tp->assign('quickStat', $quickStat); break; default: break; } } else { $errors['NOT_EMPLOYER'] = true; } } $tp->assign('errors', $errors); $tp->display($template); }
/** * Get list of contacts by user id * * @param integer $userSID * @param integer $page * @param integer $perPage * @return array */ public static function getContacts($userSID, $page = 1, $perPage = 10) { $from = ($page - 1) * $perPage; $res = SJB_DB::query("SELECT * FROM `private_message_contacts` WHERE `user_sid` = ?n LIMIT {$from}, {$perPage}", $userSID); $list = array(); foreach ($res as $contactInfo) { $userInfo = SJB_UserManager::getUserInfoBySID($contactInfo['contact_sid']); $userInfo['user_group_id'] = SJB_UserGroupManager::getUserGroupIDBySID($userInfo['user_group_sid']); $list[$contactInfo['contact_sid']] = $userInfo; } return $list; }
public static function getUsersApproveInfo($userGroupSID = false) { if ($userGroupSID != false) { $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userGroupSID); if (empty($userGroupInfo['approve_user_by_admin'])) { return false; } $res = SJB_DB::query("\n\t\t\t\tSELECT count(*) as `count`, `approval`, `user_group_sid` \n\t\t\t\tFROM `users` \n\t\t\t\tWHERE `user_group_sid` = ?n \n\t\t\t\tGROUP BY `approval`", $userGroupSID); $statusInfo = array(); foreach ($res as $arr) { $statusInfo[$arr['approval']] = $arr['count']; } $statusInfo['user_group_sid'] = $userGroupSID; $statusInfo['user_group_id'] = SJB_UserGroupManager::getUserGroupIDBySID($userGroupSID); return $statusInfo; } $res = SJB_DB::query("\n\t\t\t\tSELECT count(*) as `count`, `user_group_sid`, `approval` \n\t\t\t\tFROM `users` \n\t\t\t\tGROUP BY `user_group_sid`, `approval`"); $approve = array(); foreach ($res as $arr) { $approve[$arr['user_group_sid']][$arr['approval']] = $arr['count']; } return $approve; }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $template = SJB_Request::getVar('template', 'manage_invoices.tpl'); $searchTemplate = SJB_Request::getVar('search_template', 'invoice_search_form.tpl'); $action = SJB_Request::getVar('action_name'); if (!empty($action)) { $invoicesSIDs = SJB_Request::getVar('invoices', array()); $_REQUEST['restore'] = 1; switch ($action) { case 'paid': foreach (array_keys($invoicesSIDs) as $invoiceSID) { $invoice = SJB_InvoiceManager::getObjectBySID($invoiceSID); $userSID = $invoice->getPropertyValue('user_sid'); if (SJB_UserManager::isUserExistsByUserSid($userSID)) { $items = $invoice->getPropertyValue('items'); $productSIDs = $items['products']; foreach ($productSIDs as $key => $productSID) { if ($productSID != -1) { if (SJB_ProductsManager::isProductExists($productSID)) { $productInfo = $invoice->getItemValue($key); $listingNumber = $productInfo['qty']; $contract = new SJB_Contract(array('product_sid' => $productSID, 'numberOfListings' => $listingNumber, 'is_recurring' => $invoice->isRecurring())); $contract->setUserSID($userSID); $contract->setPrice($items['amount'][$key]); if ($contract->saveInDB()) { SJB_ListingManager::activateListingsAfterPaid($userSID, $productSID, $contract->getID(), $listingNumber); SJB_ShoppingCart::deleteItemFromCartBySID($productInfo['shoppingCartRecord'], $userSID); $bannerInfo = $productInfo['banner_info']; if ($productInfo['product_type'] == 'banners' && !empty($bannerInfo)) { $bannersObj = new SJB_Banners(); $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $userSID, $contract->getID()); $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']); SJB_AdminNotifications::sendAdminBannerAddedLetter($userSID, $bannerGroup); } if ($contract->isFeaturedProfile()) { SJB_UserManager::makeFeaturedBySID($userSID); } if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($userSID)) { SJB_Notifications::sendSubscriptionActivationLetter($userSID, $productInfo); } } } } else { $type = SJB_Array::getPath($items, 'custom_info/' . $key . '/type'); switch ($type) { case 'featuredListing': $listingId = SJB_Array::getPath($items, 'custom_info/' . $key . '/listing_id'); SJB_ListingManager::makeFeaturedBySID($listingId); break; case 'priorityListing': $listingId = SJB_Array::getPath($items, 'custom_info/' . $key . '/listing_id'); SJB_ListingManager::makePriorityBySID($listingId); break; case 'activateListing': $listingsIds = explode(",", SJB_Array::getPath($items, 'custom_info/' . $key . '/listings_ids')); foreach ($listingsIds as $listingId) { SJB_ListingManager::activateListingBySID($listingId); } break; } } } SJB_Statistics::addStatisticsFromInvoice($invoice); } $total = $invoice->getPropertyValue('total'); if ($total > 0) { $gatewayID = $invoice->getPropertyValue('payment_method'); $gatewayID = isset($gatewayID) ? $gatewayID : 'cash_payment'; $transactionId = md5($invoiceSID . $gatewayID); $transactionInfo = array('transaction_id' => $transactionId, 'invoice_sid' => $invoiceSID, 'amount' => $total, 'payment_method' => $gatewayID, 'user_sid' => $invoice->getPropertyValue('user_sid')); $transaction = new SJB_Transaction($transactionInfo); SJB_TransactionManager::saveTransaction($transaction); } SJB_InvoiceManager::markPaidInvoiceBySID($invoiceSID); SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoiceSID); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-invoices/"); break; case 'unpaid': foreach (array_keys($invoicesSIDs) as $invoiceSID) { SJB_InvoiceManager::markUnPaidInvoiceBySID($invoiceSID); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/'); break; case 'delete': foreach (array_keys($invoicesSIDs) as $invoiceSID) { SJB_InvoiceManager::deleteInvoiceBySID($invoiceSID); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/'); break; default: unset($_REQUEST['restore']); break; } } /***************************************************************/ $_REQUEST['action'] = 'search'; $invoice = new SJB_Invoice(array()); $invoice->addProperty(array('id' => 'username', 'type' => 'string', 'value' => '', 'is_system' => true)); $aliases = new SJB_PropertyAliases(); $aliases->addAlias(array('id' => 'username', 'real_id' => 'user_sid', 'transform_function' => 'SJB_UserDBManager::getUserSIDsLikeSearchString')); $searchFormBuilder = new SJB_SearchFormBuilder($invoice); $criteriaSaver = new SJB_InvoiceCriteriaSaver(); if (isset($_REQUEST['restore'])) { $_REQUEST = array_merge($_REQUEST, $criteriaSaver->getCriteria()); } $criteria = $searchFormBuilder->extractCriteriaFromRequestData($_REQUEST, $invoice); $searchFormBuilder->setCriteria($criteria); $searchFormBuilder->registerTags($tp); $tp->display($searchTemplate); /********************** S O R T I N G *********************/ $paginator = new SJB_InvoicePagination(); $innerJoin = false; if ($paginator->sortingField == 'username') { $innerJoin = array('users' => array('sort_field' => array(36 => array('FirstName', 'LastName'), 41 => 'CompanyName'), 'join_field' => 'sid', 'join_field2' => 'user_sid', 'main_table' => 'invoices', 'join' => 'LEFT JOIN')); } $searcher = new SJB_InvoiceSearcher(array('limit' => ($paginator->currentPage - 1) * $paginator->itemsPerPage, 'num_rows' => $paginator->itemsPerPage), $paginator->sortingField, $paginator->sortingOrder, $innerJoin); $foundInvoices = array(); $foundInvoicesInfo = array(); if (SJB_Request::getVar('action', '') == 'search') { $foundInvoices = $searcher->getObjectsByCriteria($criteria, $aliases); if (empty($foundInvoices) && $paginator->currentPage != 1) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-invoices/?page=1'); } $criteriaSaver->setSession($_REQUEST, $searcher->getFoundObjectSIDs()); } elseif (isset($_REQUEST['restore'])) { $foundInvoices = $criteriaSaver->getObjectsFromSession(); } foreach ($foundInvoices as $id => $invoice) { $subUserSID = $invoice->getPropertyValue('subuser_sid'); if ($subUserSID) { $subUserInfo = SJB_UserManager::getUserInfoBySID($subUserSID); $parentInfo = SJB_UserManager::getUserInfoBySID($subUserInfo['parent_sid']); $username = $parentInfo['CompanyName']; } else { $userSID = $invoice->getPropertyValue('user_sid'); $userInfo = SJB_UserManager::getUserInfoBySID($userSID); if (SJB_UserGroupManager::getUserGroupIDBySID($userInfo['user_group_sid']) == 'Employer') { $username = $userInfo['CompanyName']; } else { if (SJB_UserGroupManager::getUserGroupIDBySID($userInfo['user_group_sid']) == 'JobSeeker') { $username = $userInfo['FirstName'] . ' ' . $userInfo['LastName']; } else { $username = $userInfo['username']; } } } $invoice->addProperty(array('id' => 'sid', 'type' => 'string', 'value' => $invoice->getSID())); $invoice->addProperty(array('id' => 'username', 'type' => 'string', 'value' => $username)); $foundInvoices[$id] = $invoice; $foundInvoicesInfo[$invoice->getSID()] = SJB_InvoiceManager::getInvoiceInfoBySID($invoice->getSID()); $foundInvoicesInfo[$invoice->getSID()]['userExists'] = !empty($username) ? 1 : 0; } /****************************************************************/ $paginator->setItemsCount($searcher->getAffectedRows()); $form_collection = new SJB_FormCollection($foundInvoices); $form_collection->registerTags($tp); $tp->assign('paginationInfo', $paginator->getPaginationInfo()); $tp->assign("found_invoices", $foundInvoicesInfo); $tp->display($template); }
public static function getRedirectUrlByPageID($pageId) { $error = ''; if (!is_null(SJB_Session::getValue('fromAnonymousShoppingCart'))) { SJB_Session::unsetValue('fromAnonymousShoppingCart'); return SJB_System::getSystemSettings('SITE_URL') . '/shopping-cart/?'; } $redirectUrl = SJB_System::getSystemSettings('SITE_URL') . '/my-account/?'; if (empty($pageId)) { return $redirectUrl; } if ($pageId == 'posting_page') { $user = SJB_UserManager::getCurrentUser(); $userGroupId = SJB_UserGroupManager::getUserGroupIDBySID($user->getUserGroupSID()); $listingTypeSid = SJB_ListingTypeManager::getListingTypeByUserSID($user->getSID()); $listingTypeId = !empty($listingTypeSid) ? SJB_ListingTypeManager::getListingTypeIDBySID(array_pop($listingTypeSid)) : ''; if ($user->hasContract() && SJB_ListingManager::canCurrentUserAddListing($error, $listingTypeId)) { $redirectUrl = SJB_System::getSystemSettings('SITE_URL') . '/add-listing/?listing_type_id=' . $listingTypeId . "&"; } elseif ($user->hasContract()) { $redirectUrl = SJB_System::getSystemSettings('SITE_URL') . '/my-account/?'; } else { $redirectUrl = SJB_System::getSystemSettings('SITE_URL') . '/' . mb_strtolower($userGroupId) . '-products/?postingProductsOnly=1&'; } } return $redirectUrl; }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $current_user = SJB_UserManager::getCurrentUser(); $currentUserInfo = SJB_UserManager::getCurrentUserInfo(); $tp->assign('current_user', $currentUserInfo); $errors = array(); $error = ''; $listing_id = SJB_Request::getVar('listing_id', null, 'default', 'int'); if (SJB_UserGroupManager::getUserGroupIDBySID($current_user->user_group_sid) == 'Employer') { $template = SJB_Request::getVar('input_template', 'copy_listing.tpl'); } else { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-listings/Job/'); } //getting $tmp_listing_id from request $tmp_listing_id_from_request = SJB_Request::getVar('tmp_listing_id', false, 'default', 'int'); $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id); $listing_type_id = SJB_ListingTypeManager::getListingTypeIDBySID($listing_info['listing_type_sid']); if ($productsInfo = $this->canCurrentUserAddListing($error, $listing_type_id)) { $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listing_info['listing_type_sid']); if (!empty($tmp_listing_id_from_request)) { $tmp_listing_sid = $tmp_listing_id_from_request; } elseif (!$tmp_listing_id_from_request) { $tmp_listing_sid = time(); } $gallery = new SJB_ListingGallery(); $gallery->setListingSID($listing_info['sid']); $pictures_info = $gallery->getPicturesInfo(); $gallery->setListingSID($tmp_listing_sid); $pictures_info_new = $gallery->getPicturesInfo(); //reuploading pictures if (!$pictures_info_new) { foreach ($pictures_info as $v) { if (!$gallery->uploadImage($v['picture_url'], $v['caption'])) { $field_errors['Picture'] = $gallery->getError(); } } } $contractID = SJB_Request::getVar('contract_id', false, 'default', 'int'); if ($contractID) { $contract = new SJB_Contract(array('contract_id' => $contractID)); } elseif (count($productsInfo) == 1) { $productInfo = array_pop($productsInfo); $contractID = $productInfo['contract_id']; $contract = new SJB_Contract(array('contract_id' => $contractID)); } else { $tp->assign('listing_id', $listing_id); $tp->assign("products_info", $productsInfo); $tp->assign("listing_type_id", $listing_type_id); $tp->display("listing_product_choice.tpl"); } if ($contractID) { $tp->assign('tmp_listing_id', $tmp_listing_sid); $extraInfo = $contract->extra_info; $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0; $tp->assign("pic_limit", $numberOfPictures); $tp->assign('contractID', $contractID); if ($listing_info['user_sid'] != SJB_UserManager::getCurrentUserSID()) { $errors['NOT_OWNER_OF_LISTING'] = $listing_id; } elseif (!is_null($listing_info)) { $listing_info = array_merge($listing_info, $_REQUEST); $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']); $listing->deleteProperty('featured'); $listing->deleteProperty('priority'); $listing->deleteProperty('status'); $listing->deleteProperty('reject_reason'); $listing->setSID($listing_id); $screening_questionnaires = SJB_ScreeningQuestionnaires::getList($current_user->getSID()); if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) { $issetQuestionnairyField = $listing->getProperty('screening_questionnaire'); if ($issetQuestionnairyField) { $value = SJB_Request::getVar('screening_questionnaire'); $value = $value ? $value : isset($listing_info['screening_questionnaire']) ? $listing_info['screening_questionnaire'] : ''; $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($current_user->getSID()), 'is_system' => true)); } } else { $listing->deleteProperty('screening_questionnaire'); } $listing_edit_form = new SJB_Form($listing); $listing_edit_form->registerTags($tp); $extraInfo = $listing_info['product_info']; if ($extraInfo) { $extraInfo = unserialize($extraInfo); $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0; $tp->assign("pic_limit", $numberOfPictures); } $form_is_submitted = isset($_REQUEST['action']) && $_REQUEST['action'] == 'save_info' || isset($_REQUEST['action']) && $_REQUEST['action'] == 'add'; $listing->addProperty(array('id' => 'contract_id', 'type' => 'id', 'value' => $contractID, 'is_system' => true)); $delete = SJB_Request::getVar('action', '') == 'delete'; $field_errors = null; if ($delete && isset($_REQUEST['field_id'])) { $field_id = $_REQUEST['field_id']; $listing->details->properties[$field_id]->type->property_info['value'] = null; } elseif ($form_is_submitted && $listing_edit_form->isDataValid($field_errors)) { $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true)); $listing->setUserSID($current_user->getSID()); $extraInfo = $contract->extra_info; $listing->setProductInfo($extraInfo); $listing->sid = null; if (!empty($listing_info['subuser_sid'])) { $listing->addSubuserProperty($listing_info['subuser_sid']); } $listingSidsForCopy = array('filesFrom' => $listing_id, 'picturesFrom' => $tmp_listing_sid); SJB_ListingManager::saveListing($listing, $listingSidsForCopy); // >>> SJB-1197 // SET VALUES FROM TEMPORARY SESSION STORAGE $formToken = SJB_Request::getVar('form_token'); $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage'); $tempFieldsData = SJB_Array::getPath($sessionFileStorage, $formToken); if (is_array($tempFieldsData)) { foreach ($tempFieldsData as $fieldId => $fieldData) { $isComplex = false; if (strpos($fieldId, ':') !== false) { $isComplex = true; } $tmpUploadedFileId = $fieldData['file_id']; // rename it to real listing field value $newFileId = $fieldId . "_" . $listing->getSID(); SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId); if ($isComplex) { list($parentField, $subField, $complexStep) = explode(':', $fieldId); $parentProp = $listing->getProperty($parentField); $parentValue = $parentProp->getValue(); // look for complex property with current $fieldID and set it to new value of property if (!empty($parentValue)) { foreach ($parentValue as $id => $value) { if ($id == $subField) { $parentValue[$id][$complexStep] = $newFileId; } } $listing->setPropertyValue($parentField, $parentValue); } } else { $listing->setPropertyValue($fieldId, $newFileId); } // clean temporary field storage $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}/{$fieldId}"); } //and remove token key from temporary storage $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}"); // clear temporary data in session storage SJB_Session::setValue('tmp_uploads_storage', $sessionFileStorage); $listingSidsForCopy = array('filesFrom' => $listing_id, 'picturesFrom' => $listing_id); SJB_ListingManager::saveListing($listing, $listingSidsForCopy); } // <<< SJB-1197 SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $extraInfo['featured'], $extraInfo['priority']); $contract->incrementPostingsNumber(); SJB_ProductsManager::incrementPostingsNumber($contract->product_sid); // is listing featured by default if ($extraInfo['featured']) { SJB_ListingManager::makeFeaturedBySID($listing->getSID()); } if ($extraInfo['priority']) { SJB_ListingManager::makePriorityBySID($listing->getSID()); } SJB_ListingManager::activateListingBySID($listing->getSID()); SJB_AdminNotifications::sendAdminListingAddedLetter($listing); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-' . strtolower($listing_type_id) . '/?listing_id=' . $listing->getSID()); } elseif ($form_is_submitted) { $field_id = 'video'; if (!isset($_REQUEST['video_hidden']) && $listing->getPropertyValue($field_id)) { $listing->details->properties[$field_id]->type->property_info['value'] = null; } } $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing); $form_fields = $listing_edit_form->getFormFieldsInfo(); $listing_fields_by_page = array(); $countPages = count($pages); $i = 1; foreach ($pages as $page) { $listing_fields_by_page[$page['page_name']] = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']); if ($i == $countPages && isset($form_fields['screening_questionnaire'])) { $listing_fields_by_page[$page['page_name']]['screening_questionnaire'] = $form_fields['screening_questionnaire']; } foreach (array_keys($listing_fields_by_page[$page['page_name']]) as $field) { if (!$listing->propertyIsSet($field)) { unset($listing_fields_by_page[$page['page_name']][$field]); } } $i++; } $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $tp->assign('METADATA', array('listing' => $metaDataProvider->getMetaData($listing_structure['METADATA']), 'form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields))); $contract_id = $listing_info['contract_id']; $contract = new SJB_Contract(array('contract_id' => $contract_id)); $tp->assign('contract_id', $contract_id); $tp->assign('contract', $contract->extra_info); $tp->assign('countPages', count($listing_fields_by_page)); $tp->assign('copy_listing', 1); $tp->assign('tmp_listing_id', $tmp_listing_sid); $tp->assign('listing_id', $listing_id); $tp->assign('contractID', $contractID); $tp->assign('listing', $listing_structure); $tp->assign('pages', $listing_fields_by_page); $tp->assign('field_errors', $field_errors); } $tp->assign('errors', $errors); $tp->display($template); } } else { $listing_type_id = isset($listing_info['listing_type_sid']) ? $listing_info['listing_type_sid'] : false; if ($error == 'NO_CONTRACT') { if ($_GET) { $getParam = '?'; foreach ($_GET as $key => $val) { $getParam .= $key . '=' . $val . '&'; } $getParam = substr($getParam, 0, -1); } $page = base64_encode(SJB_System::getURI() . $getParam); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-products/?page=' . $page); } $tp->assign('clone_job', 1); $tp->assign('listing_type_id', $listing_type_id); $tp->assign('error', $error); $tp->display('add_listing_error.tpl'); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $display_form = new SJB_Form(); $display_form->registerTags($tp); $current_user = SJB_UserManager::getCurrentUser(); $errors = array(); $template = SJB_Request::getVar('display_template', 'display_listing.tpl'); $tcpdfError = SJB_Request::getVar('error', false); $action = substr($template, 0, -4); $listing_id = SJB_Request::getVar("listing_id"); if (isset($_REQUEST['passed_parameters_via_uri'])) { $passed_parameters_via_uri = SJB_UrlParamProvider::getParams(); $listing_id = isset($passed_parameters_via_uri[0]) ? $passed_parameters_via_uri[0] : null; } if (is_null($listing_id) && SJB_FormBuilderManager::getIfBuilderModeIsSet()) { $listing_type_id = SJB_Request::getVar('listing_type_id'); $listing_id = SJB_ListingManager::getListingIDByListingTypeID($listing_type_id); } if (is_null($listing_id)) { $errors['UNDEFINED_LISTING_ID'] = true; } elseif (is_null($listing = SJB_ListingManager::getObjectBySID($listing_id)) || !SJB_ListingManager::isListingAccessableByUser($listing_id, SJB_UserManager::getCurrentUserSID())) { $errors['WRONG_LISTING_ID_SPECIFIED'] = true; } elseif (!$listing->isActive() && $listing->getUserSID() != SJB_UserManager::getCurrentUserSID()) { $errors['LISTING_IS_NOT_ACTIVE'] = true; } elseif (($listingStatus = SJB_ListingManager::getListingApprovalStatusBySID($listing_id)) != 'approved' && SJB_ListingTypeManager::getWaitApproveSettingByListingType($listing->listing_type_sid) == 1 && $listing->getUserSID() != SJB_UserManager::getCurrentUserSID()) { $errors['LISTING_IS_NOT_APPROVED'] = true; } elseif (SJB_ListingTypeManager::getListingTypeIDBySID($listing->listing_type_sid) == 'Resume' && ($template == 'display_job.tpl' or SJB_System::getURI() == '/print-job/') || SJB_ListingTypeManager::getListingTypeIDBySID($listing->listing_type_sid) == 'Job' && ($template == 'display_resume.tpl' or SJB_System::getURI() == '/print-resume/')) { $errors['WRONG_DISPLAY_TEMPLATE'] = true; } else { $listing_type_id = SJB_ListingTypeManager::getListingTypeIDBySID($listing->listing_type_sid); if (SJB_System::getURI() == '/print-listing/') { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/print-' . strtolower($listing_type_id) . '/?listing_id=' . $listing_id); exit; } $listing->addPicturesProperty(); $display_form = new SJB_Form($listing); $display_form->registerTags($tp); $form_fields = $display_form->getFormFieldsInfo(); $listingOwner = SJB_UserManager::getObjectBySID($listing->user_sid); if ($action !== 'print_listing') { SJB_ListingManager::incrementViewsCounterForListing($listing_id, $listing); } $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing, array('comments', 'ratings')); $filename = SJB_Request::getVar('filename', false); if ($filename) { $file = SJB_UploadFileManager::openFile($filename, $listing_id); $errors['NO_SUCH_FILE'] = true; } $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $tp->assign("METADATA", array("listing" => $metaDataProvider->getMetaData($listing_structure['METADATA']), "form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields))); $comments = array(); $comments_total = ''; if (SJB_Settings::getSettingByName('show_comments') == '1') { $comments = SJB_CommentManager::getEnabledCommentsToListing($listing_id); $comments_total = count($comments); } $searchId = SJB_Request::getVar("searchId", ""); $page = SJB_Request::getVar("page", ""); $criteria_saver = new SJB_ListingCriteriaSaver($searchId); $searchCriteria = $criteria_saver->getCriteria(); $keywordsHighlight = ''; if (isset($searchCriteria['keywords']) && SJB_System::getSettingByName('use_highlight_for_keywords')) { foreach ($searchCriteria['keywords'] as $type => $keywords) { switch ($type) { case 'like': case 'exact_phrase': $keywordsHighlight = json_encode($keywords); break; case 'all_words': case 'any_words': $keywordsHighlight = json_encode(explode(' ', $keywords)); break; case 'boolean': $keywordsHighlight = json_encode(SJB_BooleanEvaluator::parse($keywords, true)); break; } } } $prevNextIds = $criteria_saver->getPreviousAndNextObjectID($listing_id); $search_criteria_structure = $criteria_saver->createTemplateStructureForCriteria(); //permissions contact info $acl = SJB_Acl::getInstance(); $permission = 'view_' . $listing_type_id . '_contact_info'; $allowViewContactInfo = false; if (SJB_UserManager::isUserLoggedIn()) { if (SJB_ContractManager::isPageViewed($current_user->getSID(), $permission, $listing_id) || $acl->isAllowed($permission) && in_array($acl->getPermissionParams($permission), array('', '0'))) { $allowViewContactInfo = true; } elseif ($acl->isAllowed($permission)) { $viewContactInfo['count_views'] = 0; $contractIDs = $current_user->getContractID(); $numberOfContactViewed = SJB_ContractManager::getNumbeOfPagesViewed($current_user->getSID(), $contractIDs, $permission); foreach ($contractIDs as $contractID) { if ($acl->getPermissionParams($permission, $contractID, 'contract')) { $params = $acl->getPermissionParams($permission, $contractID, 'contract'); $viewsLeft = SJB_ContractManager::getNumbeOfPagesViewed($current_user->getSID(), array($contractID), $permission); if (isset($viewContactInfo['count_views']) && is_numeric($params)) { $viewContactInfo['count_views'] += $params; if ($params > $viewsLeft) { $viewContactInfo['contract_id'] = $contractID; } } } } if ($viewContactInfo && $viewContactInfo['count_views'] > $numberOfContactViewed) { $allowViewContactInfo = true; SJB_ContractManager::addViewPage($current_user->getSID(), $permission, $listing_id, $viewContactInfo['contract_id'], $listing->getListingTypeSID()); } } $user_group_id = SJB_UserGroupManager::getUserGroupIDBySID($current_user->getUserGroupSID()); if ($allowViewContactInfo && $user_group_id == 'JobSeeker' && $listing_type_id == 'Job') { SJB_UserManager::saveRecentlyViewedListings($current_user->getSID(), $listing_id); } } elseif ($acl->isAllowed($permission)) { $allowViewContactInfo = true; } $tp->assign("keywordsHighlight", $keywordsHighlight); $tp->assign('allowViewContactInfo', $allowViewContactInfo); $tp->assign('show_rates', SJB_Settings::getSettingByName('show_rates')); $tp->assign("isApplied", SJB_Applications::isApplied($listing_id, SJB_UserManager::getCurrentUserSID())); $tp->assign('show_rates', SJB_Settings::getSettingByName('show_rates')); $tp->assign('show_comments', SJB_Settings::getSettingByName('show_comments')); $tp->assign('comments', $comments); $tp->assign('comments_total', $comments_total); $tp->assign('listing_id', $listing_id); $tp->assign("form_fields", $form_fields); $tp->assign('video_fields', SJB_HelperFunctions::takeMediaFields($form_fields)); $tp->assign('uri', base64_encode(SJB_Navigator::getURIThis())); $tp->assign('listingOwner', $listingOwner); $listing_structure = SJB_ListingManager::newValueFromSearchCriteria($listing_structure, $criteria_saver->criteria); // SJB-1197: ajax autoupload. // Fix to view video from temporary uploaded storage. $sessionFilesStorage = SJB_Session::getValue('tmp_uploads_storage'); // NEED TO CHECK FOR COMPLEX PARENT AND COMPLEX STEP PARAMETERS! $complexParent = SJB_Request::getVar('complexParent'); $complexStep = SJB_Request::getVar('complexEnum'); $fieldId = SJB_Request::getVar('field_id'); $isComplex = false; if ($complexParent && $complexStep) { $fieldId = $complexParent . ":" . $fieldId . ":" . $complexStep; $isComplex = true; } $tempFileValue = SJB_Array::getPath($sessionFilesStorage, "listings/{$listing_id}/{$fieldId}"); if ($isComplex) { $uploadFileManager = new SJB_UploadFileManager(); $fileLink = $uploadFileManager->getUploadedFileLink($tempFileValue['file_id']); $tp->assign('videoFileLink', $fileLink); } else { if (!empty($tempFileValue)) { $fileUniqueId = isset($tempFileValue['file_id']) ? $tempFileValue['file_id'] : ''; if (!empty($fileUniqueId)) { $upload_manager = new SJB_UploadFileManager(); // file structure for videoplayer $fileInfo = array('file_url' => $upload_manager->getUploadedFileLink($fileUniqueId), 'file_name' => $upload_manager->getUploadedFileName($fileUniqueId), 'saved_file_name' => $upload_manager->getUploadedSavedFileName($fileUniqueId), 'file_id' => $fileUniqueId); $listing_structure[$fieldId] = $fileInfo; } } } // SJB-1197 // GOOGLE MAP SEARCH RESULTS CUSTOMIZATION $zipCode = ''; if (!empty($listing_structure['Location']['ZipCode'])) { $zipCode = $listing_structure['Location']['ZipCode']; } // get 'latitude' and 'longitude' from zipCode field, if it not set $latitude = isset($listing_structure['latitude']) ? $listing_structure['latitude'] : ''; $longitude = isset($listing_structure['longitude']) ? $listing_structure['longitude'] : ''; if (!empty($zipCode) && empty($latitude) && empty($longitude)) { $result = SJB_DB::query("SELECT * FROM `locations` WHERE `name` = ?s LIMIT 1", $zipCode); if ($result) { $listing_structure['latitude'] = $result[0]['latitude']; $listing_structure['longitude'] = $result[0]['longitude']; } } elseif (!empty($listing_structure['Location']['City']) && !empty($listing_structure['Location']['State']) && !empty($listing_structure['Location']['Country'])) { $address = $listing_structure['Location']['City'] . ', ' . $listing_structure['Location']['State'] . ', ' . $listing_structure['Location']['Country']; $address = urlencode($address); $cache = SJB_Cache::getInstance(); $parameters = array('City' => $listing_structure['Location']['City'], 'State' => $listing_structure['Location']['State'], 'Country' => $listing_structure['Location']['Country']); $hash = md5('google_map' . serialize($parameters)); $data = $cache->load($hash); $geoCod = ''; if (!$data) { try { $geoCod = SJB_HelperFunctions::getUrlContentByCurl("http://maps.googleapis.com/maps/api/geocode/json?address={$address}&sensor=false"); $geoCod = json_decode($geoCod); if ($geoCod->status == 'OK') { $cache->save($geoCod, $hash); } } catch (Exception $e) { $backtrace = SJB_Logger::getBackTrace(); SJB_Error::writeToLog(array(array('level' => 'E_USER_WARNING', 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'backtrace' => sprintf("BACKTRACE:\n [%s]", join("<br/>\n", $backtrace))))); } } else { $geoCod = $data; } try { if (!is_object($geoCod)) { throw new Exception("Map object nave not been Created"); } if ($geoCod->status !== 'OK') { throw new Exception("Status is not OK"); } $location = $geoCod->results[0]->geometry->location; $listing_structure['latitude'] = $location->lat; $listing_structure['longitude'] = $location->lng; } catch (Exception $e) { $backtrace = SJB_Logger::getBackTrace(); SJB_Error::writeToLog(array(array('level' => 'E_USER_WARNING', 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'backtrace' => sprintf("BACKTRACE:\n [%s]", join("<br/>\n", $backtrace))))); } } if (SJB_Request::getVar('view')) { $tp->assign('listings', array($listing_structure)); } $tp->filterThenAssign("listing", $listing_structure); $tp->assign("prev_next_ids", $prevNextIds); $tp->assign("searchId", $searchId); $tp->assign("page", $page); $tp->filterThenAssign("search_criteria", $search_criteria_structure); $tp->filterThenAssign("search_uri", $criteria_saver->getUri()); if ($field_id = SJB_Request::getVar('field_id')) { // SJB-825 $complexEnum = SJB_Request::getVar('complexEnum', null, 'GET'); $complexFieldID = SJB_Request::getVar('complexParent', null, 'GET'); if (!is_null($complexEnum) && !is_null($complexFieldID)) { $videoFileID = $complexFieldID . ':' . $field_id . ':' . $complexEnum . '_' . $listing_id; $videoFileLink = SJB_UploadFileManager::getUploadedFileLink($videoFileID); if ($videoFileLink) { $tp->assign('videoFileLink', $videoFileLink); } } // SJB-825 $tp->assign('field_id', $field_id); } else { if (SJB_Request::getVar('action', false) == 'download_pdf_version') { $formBuilder = SJB_FormBuilderManager::getFormBuilder(SJB_FormBuilderManager::FORM_BUILDER_TYPE_PDF, $listing_type_id); $formBuilder->setChargedTemplateProcessor($tp); $tpl = 'resume_to_pdf.tpl'; if ($listing_structure['anonymous'] == '1') { $filename = 'Anonymous User_' . $listing_structure['Title'] . '.pdf'; } else { $filename = $listing_structure['user']['FirstName'] . ' ' . $listing_structure['user']['LastName'] . '_' . $listing_structure['Title'] . '.pdf'; } try { $html = $tp->fetch($tpl); $html = preg_replace('/<div[^>]*>/', '', $html); $html = str_replace('</div>', '', $html); SJB_HelperFunctions::html2pdf($html, $filename, str_replace('http://', '', SJB_HelperFunctions::getSiteUrl())); exit; } catch (Exception $e) { SJB_Error::writeToLog($e->getMessage()); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/display-resume/' . $listing_id . '/?error=TCPDF_ERROR'); } } else { $formBuilder = SJB_FormBuilderManager::getFormBuilder(SJB_FormBuilderManager::FORM_BUILDER_TYPE_DISPLAY, $listing_type_id); $formBuilder->setChargedTemplateProcessor($tp); } } } if ($errors) { foreach ($errors as $k => $v) { switch ($k) { case 'TCPDF_ERROR': case 'UNDEFINED_LISTING_ID': case 'WRONG_LISTING_ID_SPECIFIED': case 'LISTING_IS_NOT_ACTIVE': case 'LISTING_IS_NOT_APPROVED': $header = $_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'; $header_status = "Status: 404 Not Found"; header($header_status); header($header); SJB_System::setGlobalTemplateVariable('page_not_found', true); break; } } } $tp->assign('errors', $errors); $tp->assign('tcpdfError', $tcpdfError); $tp->display($template); }
public function execute() { $errors = array(); if (SJB_Request::isAjax()) { $response = null; $user_type = SJB_Request::getVar('user_type'); $user_name = SJB_Request::getVar('parser_user'); $products = SJB_XmlImport::getProducts($user_type, $user_name, $errors); $response = array('products' => empty($products) ? '' : SJB_XmlImport::translateProductsName($products), 'error' => empty($errors) ? '' : array_pop($errors)); die(json_encode($response)); } $tp = SJB_System::getTemplateProcessor(); $add_level = SJB_Request::getVar('add_level', 1); // check for errors if ($add_level == '3') { $selectUserType = SJB_Request::getVar('selectUserType'); $addNewUser = 0; if ($selectUserType == 'username') { $usr_name = isset($_REQUEST['parser_user']) ? SJB_DB::quote($_REQUEST['parser_user']) : ''; $usr_id = SJB_UserManager::getUserSIDbyUsername($usr_name); if (empty($usr_name)) { $errors[] = 'Please enter user name of existing user to the "User Name" field'; $usr_name = ''; } else { $user_sid_exists = SJB_UserManager::getUserSIDbyUsername($usr_name); if (empty($user_sid_exists)) { $errors[] = 'User "' . $usr_name . '" not exists. Please enter user name of existing user to the "User Name" field'; $usr_name = ''; } } } elseif ($selectUserType == 'group') { $userGroupSid = isset($_REQUEST['parser_user']) ? $_REQUEST['parser_user'] : 0; $usr_id = $userGroupSid; $usr_name = SJB_UserGroupManager::getUserGroupIDBySID($usr_id); $addNewUser = 1; } if ($errors) { $add_level = 2; } } $listings_type = SJB_ListingTypeManager::getAllListingTypesInfo(); $types = array(); foreach ($listings_type as $one) { $types[$one['sid']] = $one['id']; } $tp->assign('types', $types); $selected_logo_options = null; switch ($add_level) { case '1': $template = 'add_step_one.tpl'; /* $types = array(); foreach ( $listings_type as $one ) { $types[$one['sid']] = $one['id']; } $tp->assign('types', $types); */ $tp->display('add_step_one.tpl'); break; case '2': $template = 'add_step_two.tpl'; $original_xml = SJB_Request::getVar('xml'); $xml = $original_xml; $tree = ''; $listing_fields = array(); $logo_options_array = array('not_logo' => 'Do Not Import Logo', 'import_logo' => 'Import Logo with Listings', 'upload_logo' => 'Upload Logo for Imported Listings'); $parsing_name = SJB_Request::getVar('parser_name'); $usr_name = SJB_Request::getVar('parser_user'); $pars_url = SJB_Request::getVar('parser_url'); $form_description = SJB_Request::getVar('form_description', '', 'POST'); $type_id = SJB_Request::getVar('type_id', '', 'POST'); $selectedLogoOption = SJB_Request::getVar('logo_options'); $selectedLogoField = SJB_Request::getVar('import_logo_field'); $selectedProduct = SJB_Request::getVar('postUnderProduct'); $id = SJB_Request::getVar('id', 0, 'GET'); $selected = array(); $a_selected = array(); if (!empty($_REQUEST['xml']) || $id > 0) { // step 2 OR edit exist if ($id > 0) { // load exist parser $parser_from_id = SJB_XmlImport::getSystemParsers($id); if (isset($parser_from_id[0]['name'])) { $parser_from_id = $parser_from_id[0]; } $parsing_name = $parser_from_id['name']; $usr_id = $parser_from_id['usr_id']; $usr_name = $parser_from_id['usr_name']; $form_description = $parser_from_id['description']; $pars_url = $parser_from_id['url']; $type_id = $parser_from_id['type_id']; $selected_logo_options = unserialize($parser_from_id['logo_options']); $selectedLogoOption = $selected_logo_options['option']; $selectedLogoField = $selected_logo_options['field']; $selectedProduct = $parser_from_id['product_sid']; $xml = $parser_from_id['xml']; $xml = SJB_XmlImport::cleanXmlFromImport($xml); $map = unserialize($parser_from_id['maper']); $selected = array_values($map); $a_selected = array_keys($map); } else { $xml = SJB_XmlImport::cleanXmlFromImport($_REQUEST['xml']); } $sxml = new simplexml(); $tree = $sxml->xml_load_file($xml, 'array'); if (isset($tree['@content'])) { $tree = $tree[0]; } if (is_array($tree)) { $tree = SJB_XmlImport::convertArray($tree); foreach ($tree as $key => $val) { unset($tree[$key]); // replace '@' and ':' $key = SJB_XmlImport::encodeSpecialEntities($key); $tree[$key]['val'] = $val; $tree[$key]['key'] = $key; } $field_types = array(0, $type_id); $listing_fields = array(); $i = 0; foreach ($field_types as $type) { $listing_fields_info = SJB_ListingFieldManager::getListingFieldsInfoByListingType($type); foreach ($listing_fields_info as $listing_field_info) { if ($listing_field_info['type'] == 'location') { foreach ($listing_field_info['fields'] as $fieldInfo) { $listing_field = new SJB_ListingField($fieldInfo); $listing_field->setSID($fieldInfo['sid']); $listing_fields[$i]['id'] = $listing_field_info['id'] . '_' . $listing_field->details->properties['id']->value; $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value; $i++; } } else { $listing_field = new SJB_ListingField($listing_field_info); $listing_field->setSID($listing_field_info['sid']); $listing_fields[$i]['id'] = $listing_field->details->properties['id']->value; $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value; $i++; } } } $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "date"; $i++; $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "url"; $i++; $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "external_id"; } else { $errors[] = 'XML syntaxis error.'; $template = 'add_step_one.tpl'; } } else { $errors[] = 'Please input correct xml'; $template = 'add_step_one.tpl'; } $tp->assign('id', $id); $tp->assign('selected', $selected); $tp->assign('a_selected', $a_selected); $tp->assign('xml', htmlspecialchars($xml)); $tp->assign('xmlToUser', $xml); $tp->assign('user_groups', SJB_UserGroupManager::getAllUserGroupsInfo()); $tp->assign('form_name', $parsing_name); $tp->assign('form_user', $usr_name); $tp->assign('form_url', $pars_url); $tp->assign('form_description', $form_description); $type_name = SJB_ListingTypeManager::getListingTypeIDBySID($type_id); $tp->assign('type_id', $type_id); $tp->assign('type_name', $type_name); $tp->assign('errors', $errors); $tp->assign('tree', $tree); $tp->assign("fields", $listing_fields); $tp->assign('logo_options', $logo_options_array); $tp->assign('selectedLogoOption', $selectedLogoOption); $tp->assign('selectedLogoField', $selectedLogoField); $tp->assign('selectedProduct', $selectedProduct); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->display($template); break; case '3': $parsing_name = isset($_REQUEST['parser_name']) ? SJB_DB::quote($_REQUEST['parser_name']) : ''; $pars_url = isset($_POST['parser_url']) ? SJB_DB::quote($_POST['parser_url']) : ''; $selectedLogoOption = isset($_POST['logo_options']) ? $_POST['logo_options'] : ''; $selectedLogoField = isset($_POST['import_logo_field']) ? $_POST['import_logo_field'] : ''; $form_description = isset($_REQUEST['form_description']) ? SJB_DB::quote($_REQUEST['form_description']) : ""; $type_id = isset($_POST['type_id']) ? intval($_POST['type_id']) : ""; $script = isset($_POST['custom_script']) && !empty($_POST['custom_script']) ? SJB_DB::quote($_POST['custom_script']) : ""; $script_users = SJB_DB::quote(SJB_Request::getVar('custom_script_users', '', SJB_Request::METHOD_POST)); $defaultValue = SJB_Request::getVar('default_value', false); $defaultValueUser = SJB_Request::getVar('user_default_value', false); $selectedProduct = SJB_Request::getVar('postUnderProduct'); $importType = SJB_Request::getVar('import_type', 'increment'); if ($defaultValue) { foreach ($defaultValue as $key => $val) { $defaultValue[$key] = htmlspecialchars($val, ENT_QUOTES, 'UTF-8'); } } if ($defaultValueUser) { foreach ($defaultValueUser as $key => $val) { $defaultValueUser[$key] = htmlspecialchars($val, ENT_QUOTES, 'UTF-8'); } } $original_xml = !empty($_POST['xml']) ? SJB_DB::quote($_POST['xml']) : ''; $id = isset($_GET['id']) ? intval($_GET['id']) : 0; $addQuery = ''; $username = SJB_XmlImport::decodeSpecialEntities(SJB_Request::getVar('username', '')); $external_id = str_replace('_dog_', '@', SJB_Request::getVar('external_id', '')); $site_url = SJB_System::getSystemSettings("SITE_URL"); if ($addNewUser == 1 && empty($_REQUEST['mapped_user'])) { $error = 'Required user profile fields are not mapped'; SJB_HelperFunctions::redirect($site_url . '/edit-import/?id=' . $id . '&save_error=' . base64_encode($error)); } if (!empty($_REQUEST['mapped']) && is_array($_REQUEST['mapped']) && !empty($original_xml) && empty($errors)) { // make map $map1 = array(); $map2 = array(); $serUserMap = ''; foreach ($_REQUEST['mapped'] as $one) { $tmp = explode(':', $one); $map1[] = $tmp[0]; $map2[] = $tmp[1]; } if ($addNewUser == 1 && !empty($_REQUEST['mapped_user']) && is_array($_REQUEST['mapped_user'])) { // make map $mapUser1 = array(); $mapUser2 = array(); foreach ($_REQUEST['mapped_user'] as $one) { $tmp = explode(':', $one); $mapUser1[] = str_replace('user_', '', $tmp[0]); $mapUser2[] = $tmp[1]; } foreach ($mapUser1 as $key => $val) { $val = SJB_XmlImport::decodeSpecialEntities($val); $mapUser[$val] = $mapUser2[$key]; } $serUserMap = serialize($mapUser); } //$map = array_combine($map1, $map2); // PHP5 foreach ($map1 as $key => $val) { $val = SJB_XmlImport::decodeSpecialEntities($val); $map[$val] = $map2[$key]; } if ($selectedLogoOption && $selectedLogoOption != 'not_logo') { //get real data without any cache if (!SJB_ListingFieldDBManager::getListingFieldInfoByID('ListingLogo')) { $listing_field_info = array('id' => 'ListingLogo', 'type' => 'logo', 'is_system' => false, 'is_required' => false, 'caption' => 'Listing Logo'); $listing_field = new SJB_ListingField($listing_field_info, $type_id); $pages = SJB_PostingPagesManager::getFirstPageEachListingType(); SJB_ListingFieldManager::saveListingField($listing_field, $pages); } if ($key = array_search('ListingLogo', $map) !== false) { unset($map[$key]); } } if ($defaultValue) { foreach ($defaultValue as $key => $val) { if ($val == '') { unset($defaultValue[$key]); } } $defaultValue = SJB_db::quote(serialize($defaultValue)); $addQuery .= ", default_value = '" . $defaultValue . "'"; } if ($defaultValueUser) { foreach ($defaultValueUser as $keyuser => $valuser) { if ($valuser == '') { unset($defaultValueUser[$keyuser]); } } $defaultValueUser = SJB_db::quote(serialize($defaultValueUser)); $addQuery .= ", default_value_user = '******'"; } $queryParsUrl = SJB_DB::quote($pars_url); $queryImportType = SJB_DB::quote($importType); $queryId = intval($id); $query = "SET\n\t\t\t\t\t\t\t`custom_script_users` = ?s,\n\t\t\t\t\t\t\t`custom_script` = ?s,\n\t\t\t\t\t\t\t`type_id` = ?n,\n\t\t\t\t\t\t\t`name` = ?s,\n\t\t\t\t\t\t\t`description` = ?s,\n\t\t\t\t\t\t\t`url` = ?s,\n\t\t\t\t\t\t\t`usr_id` = ?n,\n\t\t\t\t\t\t\t`usr_name` = ?s,\n\t\t\t\t\t\t\t`maper_user` = ?s,\n\t\t\t\t\t\t\t`xml` = ?s,\n\t\t\t\t\t\t\t`add_new_user` = ?n,\n\t\t\t\t\t\t\t`username` = ?s,\n\t\t\t\t\t\t\t`external_id` = ?s,\n\t\t\t\t\t\t\t`product_sid` = ?n,\n\t\t\t\t\t\t\t`import_type` = ?s\n\t\t\t\t\t\t\t{$addQuery}"; if ($id > 0) { SJB_DB::query("UPDATE `parsers` {$query} WHERE id = ?n", $script_users, $script, $type_id, $parsing_name, $form_description, $queryParsUrl, $usr_id, $usr_name, $serUserMap, $original_xml, $addNewUser, $username, $external_id, $selectedProduct, $queryImportType, $queryId); } else { $id = SJB_DB::query("INSERT INTO `parsers` {$query}", $script_users, $script, $type_id, $parsing_name, $form_description, $queryParsUrl, $usr_id, $usr_name, $serUserMap, $original_xml, $addNewUser, $username, $external_id, $selectedProduct, $queryImportType); } $errorFile = ''; $xml_logo = null; switch ($selectedLogoOption) { case 'import_logo': $map[$selectedLogoField] = 'ListingLogo'; break; case 'upload_logo': if (!empty($_FILES['upload_logo_file'])) { if ($_FILES['upload_logo_file']['error']) { $errorFile = SJB_UploadFileManager::getErrorId($_FILES['upload_logo_file']['error']); } else { $width = SJB_Settings::getSettingByName('listing_picture_width'); $height = SJB_Settings::getSettingByName('listing_picture_height'); $property_info['second_width'] = SJB_Settings::getSettingByName('listing_thumbnail_width'); $property_info['second_height'] = SJB_Settings::getSettingByName('listing_thumbnail_height'); $picture = new SJB_UploadPictureManager(); $picture->setWidth($width); $picture->setHeight($height); if ($picture->isValidUploadedPictureFile('upload_logo_file')) { $xml_logo = "XMLImportLogo_{$id}"; $picture->setUploadedFileID($xml_logo); $picture->uploadPicture('upload_logo_file', $property_info); } } } break; } $logo_options = serialize(array('option' => $selectedLogoOption, 'field' => $selectedLogoField)); $serMap = serialize($map); if ($xml_logo) { SJB_DB::query("UPDATE `parsers` SET maper = ?s, `xml_logo` = ?s, logo_options = ?s WHERE id = ?n", $serMap, $xml_logo, $logo_options, $id); } else { SJB_DB::query("UPDATE `parsers` SET maper = ?s, logo_options = ?s WHERE id = ?n", $serMap, $logo_options, $id); } $form_submitted = SJB_Request::getVar('form_action'); if ($form_submitted == 'save_info') { SJB_HelperFunctions::redirect($site_url . '/show-import/'); } elseif ($form_submitted == 'apply_info') { $getterParameters = '?id=' . $id; if ($errorFile) { $getterParameters .= '&error=' . $errorFile; } SJB_HelperFunctions::redirect($site_url . '/edit-import/' . $getterParameters); } } else { if (empty($errors)) { $errors[] = 'No data to save'; } $tp->assign('errors', $errors); $tp->assign('xml', htmlspecialchars($original_xml)); $tp->assign('xmlToUser', $original_xml); $tp->assign('form_name', $parsing_name); $tp->assign('form_user', $usr_name); $tp->assign('form_url', $pars_url); $tp->assign('form_description', $form_description); $tp->display('add_step_three.tpl'); } break; } }
public static function getSalesStatistics($period, $filter, $sorting_field, $sorting_order) { $where = ''; if (!empty($period['from'])) { $period['from'] = SJB_I18N::getInstance()->getInput('date', $period['from']); $time = "00:00:00"; $where .= " AND s.`date` >= '{$period['from']} {$time}' "; } if (!empty($period['to'])) { $period['to'] = SJB_I18N::getInstance()->getInput('date', $period['to']); $time = "23:59:59"; $where .= " AND s.`date` <= '{$period['to']} {$time}' "; } $join = ''; $groupBy = ''; $query = ''; if (in_array($filter, array('Location_Country', 'Location_State', 'Location_City'))) { $fieldInfo = SJB_ListingFieldDBManager::getLocationFieldsInfoById($filter); } else { $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($filter); } if (strstr($filter, 'userGroup_')) { $userGroupSID = str_replace('userGroup_', '', $filter); $userGroupID = SJB_UserGroupManager::getUserGroupIDBySID($userGroupSID); $join = " INNER JOIN `users` u ON s.`user_sid` = u.`sid` "; $where .= " AND u.`user_group_sid` = '{$userGroupSID}'"; $groupBy = " u.`sid`"; $query = ', u.* '; } elseif (!empty($fieldInfo['type']) && $fieldInfo['type'] == 'list' && empty($fieldInfo['parent_sid'])) { $join = " INNER JOIN `users` u ON s.`user_sid` = u.`sid` INNER JOIN `user_profile_field_list` ufl ON u.`{$filter}` = ufl.`sid` "; $groupBy = " `{$filter}` "; $query = ", ufl.`value` as {$filter} "; } elseif (!empty($fieldInfo['type']) && $fieldInfo['type'] == 'list' && !empty($fieldInfo['parent_sid'])) { if ($filter == 'Location_Country') { $join = " INNER JOIN `users` u ON s.`user_sid` = u.`sid` INNER JOIN `countries` c ON u.`{$filter}` = c.`sid` "; $query = ", c.`country_name` as {$filter} "; } else { $join = " INNER JOIN `users` u ON s.`user_sid` = u.`sid` INNER JOIN `states` st ON u.`{$filter}` = st.`sid` "; $query = ", st.`state_name` as {$filter} "; } $groupBy = " `{$filter}` "; } elseif ($filter == 'sid') { $join = " INNER JOIN `products` p ON s.`object_sid` = p.`sid` "; $where .= " AND s.type = 'product' "; $groupBy = " s.`object_sid`, s.`featured`, s.`priority`, s.`reactivate` "; $query = ', p.* '; } else { $join = " INNER JOIN `users` u ON s.`user_sid` = u.`sid` "; $where .= " AND u.`{$filter}` != '' AND u.`{$filter}` IS NOT NULL "; $groupBy = " u.`{$filter}` "; $query = ', u.* '; } $orderBy = ''; if ($sorting_field == 'username') { if (strstr($filter, 'userGroup_')) { if ($userGroupID == 'Employer') { $orderBy = "ORDER BY `CompanyName` {$sorting_order}"; } else { $orderBy = "ORDER BY `FirstName`, `LastName` {$sorting_order}"; } } } else { $orderBy = "ORDER BY {$sorting_field} {$sorting_order}"; } $statisticsInfo = array(); $total = $totalSum = SJB_DB::query("SELECT sum(s.`price`*s.`count`) as total, sum(s.`count`) as units_sold, 'Total' as totalSum, 0 as `sid` FROM `statistics` s {$join} WHERE s.`event` = 'payment' {$where}"); $total = $total ? array_pop($total) : array('total' => 0); $percent = $total['total'] != 0 ? 100 / $total['total'] : 0; if ($filter == 'sid') { $statisticsInfo = SJB_DB::query("SELECT s.*, sum(s.`price`*s.`count`) as total, sum(s.`price`*s.`count`)*{$percent} as percent, sum(s.`count`) as units_sold {$query} \n\t\t\t\t\t\t\t\t\t\t\t\t FROM `statistics` s {$join} \n\t\t\t\t\t\t\t\t\t\t\t\t WHERE s.`event` = 'payment' {$where} \n\t\t\t\t\t\t\t\t\t\t\t\t GROUP BY {$groupBy} {$orderBy}"); } else { $statisticsSIDs = SJB_DB::query("SELECT {$groupBy} as sid, sum(s.`price`*s.`count`) as total FROM `statistics` s {$join} WHERE s.`event` = 'payment' {$where} GROUP BY {$groupBy} ORDER BY total DESC LIMIT 10"); foreach ($statisticsSIDs as $info) { $SIDs[] = "'" . $info['sid'] . "'"; } if (isset($SIDs)) { $SIDs = implode(',', $SIDs); $statisticsInfo = SJB_DB::query("SELECT s.*, sum(s.`price`*s.`count`) as total, sum(s.`price`*s.`count`)*{$percent} as percent, sum(s.`count`) as units_sold {$query} \n\t\t\t\t\t\t\t\t\t\t\t\t FROM `statistics` s {$join} \n\t\t\t\t\t\t\t\t\t\t\t\t WHERE {$groupBy} in ({$SIDs}) AND s.`event` = 'payment' {$where} \n\t\t\t\t\t\t\t\t\t\t\t\t GROUP BY {$groupBy} {$orderBy}"); $ohter = SJB_DB::query("SELECT s.*, sum(s.`price`*s.`count`) as total, sum(s.`price`*s.`count`)*{$percent} as percent, sum(s.`count`) as units_sold, 'Other' as other {$query} FROM `statistics` s {$join} WHERE {$groupBy} not in ({$SIDs}) AND s.`event` = 'payment' {$where}"); if (!empty($ohter[0]['sid'])) { $statisticsInfo = array_merge($statisticsInfo, $ohter); } } } $statisticsInfo = array_merge($statisticsInfo, $totalSum); $statistics = array(); foreach ($statisticsInfo as $key => $statisticInfo) { if ($filter == 'sid') { $productInfo = SJB_ProductsManager::getProductInfoBySID($statisticInfo['sid']); $statisticInfo['product_type'] = SJB_ProductsManager::getProductTypeByID($productInfo['product_type']); } $statistics[$key] = $statisticInfo; if (isset($statisticInfo['other'])) { $statistics[$key]['generalColumn'] = 'Other'; } elseif (isset($statisticInfo['totalSum'])) { $statistics[$key]['generalColumn'] = 'Total'; $statistics[$key]['name'] = 'Total'; $statistics[$key]['percent'] = '100%'; } elseif (strstr($filter, 'userGroup_')) { if ($userGroupID == 'Employer') { $statistics[$key]['generalColumn'] = !empty($statisticInfo['CompanyName']) ? $statisticInfo['CompanyName'] : $statisticInfo['username']; } else { $statistics[$key]['generalColumn'] = !empty($statisticInfo['FirstName']) && !empty($statisticInfo['LastName']) ? $statisticInfo['FirstName'] . " " . $statisticInfo['LastName'] : $statisticInfo['username']; } } elseif ($filter == 'sid') { $statistics[$key]['generalColumn'] = $statisticInfo['name']; } else { $statistics[$key]['generalColumn'] = $statisticInfo[$filter]; } $statistics[$key]['percent'] = round($statistics[$key]['percent'], 2); if ($statistics[$key]['percent'] == 99.98999999999999) { $statistics[$key]['percent'] = 100; } } return $statistics; }