Exemplo n.º 1
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action');
     $api = SJB_Request::getVar('api', false);
     $request = $_REQUEST;
     unset($request['action']);
     switch ($action) {
         case 'header':
             $test = $tp->fetch("header.tpl");
             echo $test;
             exit;
             break;
         case 'simplyHired':
             SJB_Statistics::addStatistics('partneringSites');
             break;
         default:
             $isIPhone = false;
             if (class_exists('MobilePlugin')) {
                 $isIPhone = MobilePlugin::isPhone();
             }
             $url = SJB_Request::getVar('url');
             $url = $url ? base64_decode($url) : '';
             if (str_replace('www.', '', $_SERVER['HTTP_HOST']) === SJB_Settings::getValue('mobile_url') || SJB_Settings::getValue('detect_iphone') && $isIPhone) {
                 $url = str_replace('viewjob', 'm/viewjob', $url);
             }
             SJB_Statistics::addStatistics('partneringSites');
             if ($api && $api == 'indeed') {
                 SJB_HelperFunctions::redirect($url);
             }
             $tp->assign('url', $url);
             $tp->display("partnersite.tpl");
             break;
     }
 }
Exemplo n.º 2
0
 public function execute()
 {
     $template = SJB_Request::getVar('template', 'featured_listings.tpl');
     $listingType = SJB_Request::getVar('listing_type', 'Job');
     $searches['data']['listing_type']['equal'] = $listingType;
     $searches['data']['featured']['equal'] = 1;
     $searches['data']['default_listings_per_page'] = SJB_Request::getVar('items_count', 1);
     $searches['data']['sorting_field'] = 'featured_last_showed';
     $searches['data']['default_sorting_field'] = 'featured_last_showed';
     $searches['data']['default_sorting_order'] = 'ASC';
     $searches['data']['sorting_order'] = 'ASC';
     // фичерные листинги кешировать не будем
     $cache = SJB_Cache::getInstance();
     $caching = $cache->getOption('caching');
     $cache->setOption('caching', false);
     $searchResultsTP = new SJB_SearchResultsTP($searches['data'], $listingType);
     $searchResultsTP->setLimit(SJB_Request::getVar('items_count', 1));
     $tp = $searchResultsTP->getChargedTemplateProcessor();
     $featuredListingSIDs = $searchResultsTP->getListingSidCollectionForCurrentPage();
     if ($featuredListingSIDs) {
         SJB_DB::query('UPDATE `listings` SET `featured_last_showed` = NOW() WHERE `sid` in (?w)', implode(',', $featuredListingSIDs));
         SJB_Statistics::addSearchStatistics($featuredListingSIDs, $listingType);
     }
     $cache->setOption('caching', $caching);
     $tp->assign('number_of_cols', SJB_Request::getVar('number_of_cols', 1));
     $tp->display($template);
 }
Exemplo n.º 3
0
 public function search()
 {
     $action = SJB_Request::getVar('action');
     $period = SJB_Request::getVar('period', array());
     $sorting_field = SJB_Request::getVar('sorting_field', 'usageCount');
     $sorting_order = SJB_Request::getVar('sorting_order', 'DESC');
     $i18n = SJB_I18N::getInstance();
     $statistics = array();
     if ($action) {
         if (!empty($period['from']) && !empty($period['to'])) {
             $from = $i18n->getInput('date', $period['from']);
             $to = $i18n->getInput('date', $period['to']);
             if (strtotime($from) > strtotime($to)) {
                 throw new Exception('SELECTED_PERIOD_IS_INCORRECT');
             }
         }
         $statistics = SJB_Statistics::getPromotionsStatistics($period, $sorting_field, $sorting_order);
     }
     $periodView = array();
     foreach ($period as $key => $value) {
         $periodView[$key] = $i18n->getInput('date', $period[$key]);
     }
     $this->tp->assign('currency', SJB_CurrencyManager::getDefaultCurrency());
     $this->tp->assign('action', $action);
     $this->tp->assign('period', $period);
     $this->tp->assign('periodView', $periodView);
     $this->tp->assign('statistics', $statistics);
     $this->tp->assign('countResult', count($statistics));
     $this->tp->assign('sorting_field', $sorting_field);
     $this->tp->assign('sorting_order', $sorting_order);
 }
Exemplo n.º 4
0
 public static function deleteUserById($id)
 {
     SJB_DB::query('UPDATE `users` SET `parent_sid` = 0 WHERE `parent_sid` = ?n', $id);
     SJB_DB::query('UPDATE `listings` SET `subuser_sid` = 0 WHERE `subuser_sid` = ?n', $id);
     $user = SJB_UserManager::getObjectBySID($id);
     SJB_Statistics::addStatistics('deleteUser', $user->getUserGroupSID(), $user->getSID());
     return parent::deleteObjectInfoFromDB('users', $id);
 }
Exemplo n.º 5
0
 /**
  * Used to add listings from the search results, browse and featured block into statistics
  * @param $listingSIDs
  * @param $listingTypeId
  */
 public static function addSearchStatistics($listingSIDs, $listingTypeId)
 {
     $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeId);
     if ($listingSIDs) {
         foreach ($listingSIDs as $listingSID) {
             SJB_Statistics::addStatistics('showInSearchResults', $listingTypeSID, $listingSID);
         }
     }
 }
Exemplo n.º 6
0
 public function execute()
 {
     $request_uri = $_SERVER['REQUEST_URI'];
     $template_processor = SJB_System::getTemplateProcessor();
     $callback_page_uri = '';
     preg_match('#.*/system/payment/callback/([^/?]+)#', $request_uri, $mm);
     if (!empty($mm)) {
         $gateway_id = $mm[1];
         $redirectPage = $callback_page_uri . $gateway_id . "/";
         preg_match("(.*{$redirectPage}([^/]*)/?)", $request_uri, $invoice_sid);
         $invoice_sid = !empty($invoice_sid[1]) ? $invoice_sid[1] : '';
         $redirectPage = $callback_page_uri . $gateway_id . "/" . $invoice_sid;
         preg_match("(.*{$redirectPage}([^/]*)/?)", $request_uri, $tt);
         $redirectPage = !empty($tt[1]) ? $tt[1] : '';
         $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid);
         if (!empty($invoice) && $invoice->getStatus() == SJB_Invoice::INVOICE_STATUS_PAID) {
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/payment-completed/");
         }
         $gateway = SJB_PaymentGatewayManager::getObjectByID($gateway_id);
         $gateway_caption = $gateway->getPropertyValue('caption');
         $invoice = $gateway->getPaymentFromCallbackData($_REQUEST);
         SJB_PaymentLogManager::recordPaymentLog($gateway->getPaymentStatusFromCallbackData($_REQUEST), $gateway_caption, $_REQUEST);
         if (is_null($invoice)) {
             $errors = $gateway->getErrors();
             $template_processor->assign('errors', $errors);
             $template_processor->display('callback_payment_page.tpl');
         } else {
             $status = $invoice->getStatus();
             if ($status == SJB_Invoice::INVOICE_STATUS_VERIFIED) {
                 SJB_Statistics::addStatisticsFromInvoice($invoice);
                 $success_url = $invoice->getSuccessPageURL();
                 $page = empty($redirectPage) ? '' : '&' . $redirectPage;
                 SJB_HelperFunctions::redirect($success_url . '?invoice_sid=' . $invoice->getSID() . $page);
             } elseif ($status == SJB_Invoice::INVOICE_STATUS_PENDING) {
                 $template_processor->assign('message', 'INVOICE_WAITING');
                 $template_processor->display('callback_payment_page.tpl');
             } else {
                 SJB_InvoiceManager::markUnPaidInvoiceBySID($invoice_sid);
                 $payment_error = 1;
                 if ($gateway_id == 'paypal_pro') {
                     $httpPostResponse = SJB_Request::getVar('http_post_response', false);
                     if (!empty($httpPostResponse['L_SHORTMESSAGE0']) && urldecode($httpPostResponse['L_SHORTMESSAGE0']) == 'Authentication/Authorization Failed') {
                         $payment_error = 2;
                     }
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/view-invoice/?sid=" . $invoice_sid . "&payment_error=" . $payment_error . "&payment_gateway=" . $gateway_id);
             }
         }
     } else {
         $errors['INVOICE_ID_IS_NOT_SET'] = 1;
         $template_processor->assign('errors', $errors);
         $template_processor->display('callback_payment_page.tpl');
     }
 }
Exemplo n.º 7
0
 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");
     }
 }
Exemplo n.º 8
0
 public static function saveSearchOnDB($requested_data, $search_name, $user_sid, $enableNotify = false, $isAlert = false, $emailFrequency = false)
 {
     $is_alert = 0;
     if ($isAlert) {
         $is_alert = 1;
     }
     if ($enableNotify) {
         $sid = SJB_DB::query("INSERT INTO saved_searches SET user_sid = ?n, name = ?s, data = ?s, is_alert = ?s, auto_notify = '1', last_send = CURDATE(), email_frequency=?s", $user_sid, $search_name, serialize($requested_data), $is_alert, $emailFrequency);
     } else {
         $sid = SJB_DB::query("INSERT INTO saved_searches SET user_sid = ?n, name = ?s, data = ?s, is_alert = ?s, last_send = CURDATE(), email_frequency=?s", $user_sid, $search_name, serialize($requested_data), $is_alert, $emailFrequency);
     }
     if ($isAlert && $sid) {
         $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($requested_data['listing_type']['equal']);
         SJB_Statistics::addStatistics('addAlert', $listingTypeSID, $sid);
     }
 }
Exemplo n.º 9
0
 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);
 }
Exemplo n.º 10
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('terms_of_use_check', SJB_System::getSettingByName('terms_of_use_check'));
     $user_group_id = SJB_Request::getVar('user_group_id', null);
     $form_submitted = isset($_REQUEST['action']) && $_REQUEST['action'] == 'register';
     if (!is_null($user_group_id)) {
         $user_group_sid = SJB_UserGroupManager::getUserGroupSIDByID($user_group_id);
         /**
          * check if registration is allowed for this UserGroup
          */
         if (!SJB_SocialPlugin::ifRegistrationIsAllowedByUserGroupSID($user_group_sid)) {
             return null;
         }
         $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
         $user = SJB_ObjectMother::createUser($_REQUEST, $user_group_sid);
         $user->deleteProperty('active');
         $user->deleteProperty('featured');
         $errors = array();
         // social plugin
         if ($form_submitted) {
             SJB_Event::dispatch('SocialPlugin_AddListingFieldsIntoRegistration', $user, true);
             SJB_Event::dispatch('MakeRegistrationFieldsNotRequired_SocialPlugin', $user, true);
         } else {
             SJB_Event::dispatch('PrepareRegistrationFields_SocialPlugin', $user, true);
             SJB_Event::dispatch('SocialPlugin_AddListingFieldsIntoRegistration', $user, true);
             SJB_Event::dispatch('FillRegistrationData_Plugin', $user, true);
         }
         $registration_form = SJB_ObjectMother::createForm($user);
         $registration_form->registerTags($tp);
         if ($form_submitted && $registration_form->isDataValid($errors)) {
             SJB_Event::dispatch('FillRegistrationData_Plugin', $user, true);
             SJB_Event::dispatch('AddReferencePluginDetails', $user, true);
             $user->deleteProperty('captcha');
             $user->deleteProperty('active');
             $user->deleteProperty('featured');
             SJB_UserManager::saveUser($user);
             SJB_Statistics::addStatistics('addUser', $user->getUserGroupSID(), $user->getSID(), false, 0, 0, false, 0, SJB_SocialPlugin::getNetwork());
             SJB_Statistics::addStatistics('addUser' . SJB_SocialPlugin::getNetwork(), $user->getUserGroupSID(), $user->getSID(), false, 0, 0, false, 0, SJB_SocialPlugin::getNetwork());
             // subscribe user on default product
             $defaultProduct = SJB_UserGroupManager::getDefaultProduct($user_group_sid);
             $availableProductIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($user_group_sid);
             if ($defaultProduct && in_array($defaultProduct, $availableProductIDs)) {
                 $contract = new SJB_Contract(array('product_sid' => $defaultProduct));
                 $contract->setUserSID($user->getSID());
                 $contract->saveInDB();
             }
             SJB_SocialPlugin::sendUserSocialRegistrationLetter($user);
             // notify administrator
             SJB_AdminNotifications::sendAdminUserRegistrationLetter($user);
             // Activation
             $isSendActivationEmail = SJB_UserGroupManager::isSendActivationEmail($user_group_sid);
             $isApproveByAdmin = SJB_UserGroupManager::isApproveByAdmin($user_group_sid);
             if ($isApproveByAdmin) {
                 SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending');
             }
             if ($isSendActivationEmail) {
                 $isSent = SJB_Notifications::sendUserActivationLetter($user->getSID());
                 if ($isSent) {
                     $tp->display('../users/registration_confirm.tpl');
                 } else {
                     $tp->display('../users/registration_failed_to_send_activation_email.tpl');
                 }
             } else {
                 if (!$isSendActivationEmail && $isApproveByAdmin) {
                     SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending');
                     $tp->display('../users/registration_pending.tpl');
                 } else {
                     SJB_UserManager::activateUserByUserName($user->getUserName());
                     $errors = array();
                     SJB_Authorization::login($user->getUserName(), $user->getPropertyValue('password'), false, $errors, false);
                     // save access token, profile info for synchronization
                     SJB_SocialPlugin::postRegistration();
                     $tp->assign('socialNetwork', SJB_SocialPlugin::getNetwork());
                     $pageId = !empty($user_group_info['after_registration_redirect_to']) ? $user_group_info['after_registration_redirect_to'] : '';
                     $redirectUrl = SJB_UserGroupManager::getRedirectUrlByPageID($pageId);
                     SJB_HelperFunctions::redirect($redirectUrl);
                 }
             }
         } else {
             // social plugin
             SJB_Event::dispatch('PrepareRegistrationFields_SocialPlugin', $user, true);
             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);
             $registration_form_template = '../users/registration_form.tpl';
             if (isset($_REQUEST['reg_form_template'])) {
                 $registration_form_template = $_REQUEST['reg_form_template'];
             } elseif (!empty($user_group_info['reg_form_template'])) {
                 $registration_form_template = $user_group_info['reg_form_template'];
             }
             $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('user_group_id', $user_group_id);
             $tp->assign('form_fields', $form_fields);
             $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
             $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
             $tp->assign('socialRegistration', true);
             $tp->assign('userTree', true);
             $tp->display($registration_form_template);
         }
     } else {
         $userGroupsSIDs = SJB_SocialPlugin::getResolvedUserGroupsByNetwork();
         $user_groups_info = array();
         foreach ($userGroupsSIDs as $groupSID) {
             array_push($user_groups_info, SJB_UserGroupManager::getUserGroupInfoBySID($groupSID));
         }
         /*
          * if there is only one group available for registration
          * redirect user directly on Registration Fields page
          */
         if (count($user_groups_info) === 1 && !empty($user_groups_info[0]['id'])) {
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/registration-social/?user_group_id=' . $user_groups_info[0]['id']);
         }
         $tp->assign('user_groups_info', $user_groups_info);
         $tp->display('registration_choose_user_group_social.tpl');
     }
 }
Exemplo n.º 11
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', 'search');
     $template = SJB_Request::getVar('template', 'listings_statistics.tpl');
     $errors = array();
     $userGroups = SJB_UserGroupManager::getAllUserGroupsIDsAndCaptions();
     foreach ($userGroups as $key => $userGroup) {
         unset($userGroups[$key]);
         $userGroups[$userGroup['id']] = $userGroup;
     }
     switch ($action) {
         case 'export':
             $period = SJB_Request::getVar('period', array());
             $filter = SJB_Request::getVar('filter', false);
             $listingTypeSID = SJB_Request::getVar('listingTypeSID', false);
             $listingTypeID = SJB_ListingTypeManager::getListingTypeIDBySID($listingTypeSID);
             $sorting_field = SJB_Request::getVar('sorting_field', 'total');
             $sorting_order = SJB_Request::getVar('sorting_order', 'DESC');
             $statistics = array();
             if ($filter) {
                 $statistics = SJB_Statistics::getListingsStatistics($period, $listingTypeSID, $filter, $sorting_field, $sorting_order);
                 if (!empty($statistics['errors'])) {
                     $errors = $statistics['errors'];
                 }
             } else {
                 $errors[] = 'EMPTY_PARAMETER';
             }
             $columnTitle = '';
             if (strstr($filter, 'userGroup_')) {
                 $userGroupSID = str_replace('userGroup_', '', $filter);
                 if ($userGroups[$userGroupSID]['key'] == 'Employer') {
                     $columnTitle = 'Company Name';
                 } else {
                     $columnTitle = $userGroups[$userGroupSID]['caption'] . ' Name';
                 }
             } else {
                 $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($filter);
                 $columnTitle = $fieldInfo['caption'];
             }
             if (!$errors && $statistics) {
                 $type = SJB_Request::getVar('type', 'csv');
                 $listingTypes = SJB_ListingTypeManager::getListingAllTypesForListType();
                 SJB_StatisticsExportController::createExportDirectory();
                 $exportProperties['title'] = $columnTitle;
                 $exportProperties['regular'] = '';
                 if ($listingTypeID == 'Job') {
                     $exportProperties['featured'] = '';
                 }
                 $exportProperties['priority'] = '';
                 $exportProperties['total'] = 'Total';
                 $exportProperties['percent'] = '%';
                 foreach ($listingTypes as $listingType) {
                     if ($listingType['id'] == $listingTypeSID) {
                         switch ($listingType['key']) {
                             case 'Job':
                                 $featuredTitle = "Number of Featured {$listingType['key']}s Posted";
                                 $exportProperties['featured'] = $featuredTitle;
                             case 'Resume':
                                 $regularTitle = "Number of Regular {$listingType['key']}s Posted";
                                 $exportProperties['regular'] = $regularTitle;
                                 $priorityTitle = "Number of Priority {$listingType['key']}s Posted";
                                 $exportProperties['priority'] = $priorityTitle;
                                 break;
                             default:
                                 $regularTitle = 'Number of Regular "' . $listingType['caption'] . '" Listings Posted';
                                 $exportProperties['regular'] = $regularTitle;
                                 $priorityTitle = 'Number of Priority "' . $listingType['caption'] . '" Listings Posted';
                                 $exportProperties['priority'] = $priorityTitle;
                                 break;
                         }
                     }
                 }
                 switch ($type) {
                     case 'csv':
                         $exportData = SJB_StatisticsExportController::getListingExportData($statistics, $listingTypeID);
                         $fileName = strtolower($listingTypeID) . '_statistics.csv';
                         SJB_StatisticsExportController::makeCSVExportFile($exportData, $fileName, "{$listingTypeID} Statistics");
                         SJB_StatisticsExportController::archiveAndSendExportFile(strtolower($listingTypeID) . '_statistics', 'csv');
                         break;
                     case 'xls':
                         $exportData = SJB_StatisticsExportController::getListingExportData($statistics, $listingTypeID);
                         $fileName = strtolower($listingTypeID) . '_statistics.xls';
                         SJB_StatisticsExportController::makeXLSExportFile($exportData, $fileName, "{$listingTypeID} Statistics");
                         SJB_StatisticsExportController::archiveAndSendExportFile(strtolower($listingTypeID) . '_statistics', 'xls');
                         break;
                 }
                 break;
             }
         case 'search':
             $search = SJB_Request::getVar('search', false);
             $period = SJB_Request::getVar('period', array());
             $filter = SJB_Request::getVar('filter', false);
             $listingTypeSID = SJB_Request::getVar('listingTypeSID', false);
             $sorting_field = SJB_Request::getVar('sorting_field', 'total');
             $sorting_order = SJB_Request::getVar('sorting_order', 'DESC');
             $statistics = array();
             if ($search) {
                 $i18n = SJB_I18N::getInstance();
                 $from = $i18n->getInput('date', $period['from']);
                 $to = $i18n->getInput('date', $period['to']);
                 if (!empty($period['from']) && !empty($period['to']) && strtotime($from) > strtotime($to)) {
                     $errors[] = 'SELECTED_PERIOD_IS_INCORRECT';
                 } else {
                     if ($filter) {
                         $statistics = SJB_Statistics::getListingsStatistics($period, $listingTypeSID, $filter, $sorting_field, $sorting_order);
                         if (!empty($statistics['errors'])) {
                             $errors = $statistics['errors'];
                         }
                     } else {
                         $errors[] = 'EMPTY_PARAMETER';
                     }
                 }
             }
             $columnTitle = '';
             if (strstr($filter, 'userGroup_')) {
                 $userGroupSID = str_replace('userGroup_', '', $filter);
                 if ($userGroups[$userGroupSID]['key'] == 'Employer') {
                     $columnTitle = 'Company Name';
                 } else {
                     $columnTitle = $userGroups[$userGroupSID]['caption'] . ' Name';
                 }
                 $tp->assign('link', 'user');
             } else {
                 if (in_array($filter, array('Location_Country', 'Location_State', 'Location_City'))) {
                     $fieldInfo = SJB_ListingFieldDBManager::getLocationFieldsInfoById($filter);
                 } else {
                     $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($filter);
                 }
                 $columnTitle = $fieldInfo['caption'];
             }
             $i18n = SJB_I18N::getInstance();
             $periodView = array();
             foreach ($period as $key => $value) {
                 $periodView[$key] = $i18n->getInput('date', $period[$key]);
             }
             $tp->assign('filter', $filter);
             $tp->assign('search', $search);
             $tp->assign('columnTitle', $columnTitle);
             $tp->assign('listingTypeSID', $listingTypeSID);
             $tp->assign('period', $period);
             $tp->assign('periodView', $periodView);
             $tp->assign('statistics', $statistics);
             $tp->assign('countResult', count($statistics));
             $tp->assign('sorting_field', $sorting_field);
             $tp->assign('sorting_order', $sorting_order);
             break;
     }
     $listingTypes = SJB_ListingTypeManager::getListingAllTypesForListType();
     $products = SJB_ProductsManager::getAllProductsInfo();
     $acl = SJB_Acl::getInstance();
     foreach ($listingTypes as $key => $listingType) {
         $userGroup = array();
         foreach ($products as $productInfo) {
             if ($acl->isAllowed('post_' . strtolower($listingType['key']), $productInfo['sid'], 'product') && !in_array($productInfo['user_group_sid'], $userGroup)) {
                 $userGroup[] = $productInfo['user_group_sid'];
             }
         }
         $listingTypes[$listingType['id']] = $listingType;
         $listingTypes[$listingType['id']]['userGroups'] = $userGroup;
         unset($listingTypes[$key]);
     }
     $tp->assign('userGroups', $userGroups);
     $tp->assign('listingTypes', $listingTypes);
     $tp->assign('errors', $errors);
     $tp->assign('action', $action);
     $tp->display($template);
 }
Exemplo n.º 12
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listing_type_id = SJB_Request::getVar('listing_type_id', false);
     $action = SJB_Request::getVar('action', false);
     $type = SJB_Request::getVar('type', false);
     $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8');
     $supportedFormats = array('xlsx', 'xls', 'csv');
     $warning = false;
     $error = '';
     if ($action == 'example' && $type) {
         $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
         $listing_field_manager = new SJB_ListingFieldManager();
         $common_details = $listing_field_manager->getCommonListingFieldsInfo();
         $extra_details = $listing_field_manager->getListingFieldsInfoByListingType($listing_type_sid);
         $listing_fields = array_merge($common_details, $extra_details);
         $directory_to_export = SJB_System::getSystemSettings('EXPORT_FILES_DIRECTORY');
         $export_properties = array();
         $export_data = array();
         foreach ($listing_fields as $listing_field) {
             $export_properties[$listing_field['id']] = $listing_field['id'];
             $export_data[0][$listing_field['id']] = '';
         }
         SJB_ExportController::createExportDirectoriesForExample();
         switch ($type) {
             case 'exl':
                 SJB_ExportController::makeExportFile($export_data, 'example.xls');
                 $export_files_dir = SJB_Path::combine($directory_to_export, 'example.xls');
                 for ($i = 0; $i < ob_get_level(); $i++) {
                     ob_end_clean();
                 }
                 header('Content-type: application/vnd.ms-excel');
                 header('Content-disposition: attachment; filename=example.xls');
                 header('Content-Length: ' . filesize($export_files_dir));
                 readfile($export_files_dir);
                 break;
             case 'csv':
                 $export_files_dir = SJB_Path::combine($directory_to_export, 'example.csv');
                 $fp = fopen($export_files_dir, 'w');
                 fputcsv($fp, explode(',', implode(',', $export_properties)));
                 fclose($fp);
                 for ($i = 0; $i < ob_get_level(); $i++) {
                     ob_end_clean();
                 }
                 header('Content-type: application/vnd.ms-excel');
                 header('Content-disposition: attachment; filename=example.csv');
                 header('Content-Length: ' . filesize($export_files_dir));
                 readfile($export_files_dir);
                 break;
         }
         SJB_Filesystem::delete($directory_to_export);
         exit;
     }
     if ($productsInfo = $this->canCurrentUserAddListing($error)) {
         $acl = SJB_Acl::getInstance();
         if ($acl->isAllowed('bulk_job_import') == true) {
             $fileInfo = null;
             if (isset($_FILES['import_file'])) {
                 $extension = strtolower(substr(strrchr($_FILES['import_file']['name'], '.'), 1));
                 if (empty($_FILES['import_file']['name']) || !in_array($extension, $supportedFormats)) {
                     $warning = 'Please choose Excel or csv file';
                 } else {
                     $fileInfo = $_FILES['import_file'];
                 }
             }
             $contractID = SJB_Request::getVar('contract_id', false);
             $current_user = SJB_UserManager::getCurrentUser();
             if ($contractID) {
                 $contract = new SJB_Contract(array('contract_id' => $contractID));
             } elseif (count($productsInfo) == 1) {
                 $productInfo = array_pop($productsInfo);
                 $contractID = $productInfo['contract_id'];
                 $contract = new SJB_Contract(array('contract_id' => $contractID));
             } else {
                 $tp->assign("products_info", $productsInfo);
                 $tp->assign("listing_type_id", $listing_type_id);
                 $tp->display("listing_product_choice.tpl");
             }
             if ($contractID && $listing_type_id) {
                 $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listing_type_id);
                 if ($fileInfo) {
                     switch ($extension) {
                         case 'xls':
                         case 'xlsx':
                             $import_file = new SJB_ImportFileXLS($fileInfo);
                             break;
                         case 'csv':
                             $import_file = new SJB_ImportFileCSV($fileInfo, ',');
                             break;
                     }
                     $import_file->parse($encodingFromCharset);
                     $bulkPermissionParam = $this->acl->getPermissionParams('post_' . $listing_type_id, $contract->getID(), 'contract');
                     $imported_data = $import_file->getData();
                     $countData = 0;
                     foreach ($imported_data as $val) {
                         if ($val) {
                             $countData++;
                         }
                     }
                     if (empty($bulkPermissionParam) || $bulkPermissionParam - $contract->getPostingsNumber() - ($countData - 1) >= 0) {
                         $listing = new SJB_Listing(array(), $listing_type_sid);
                         $count = 0;
                         $listingSIDs = array();
                         foreach ($imported_data as $key => $importedColumn) {
                             if ($key == 1) {
                                 $imported_data_processor = new SJB_ImportedDataProcessor($importedColumn, $listing);
                                 continue;
                             }
                             if (!$importedColumn) {
                                 continue;
                             }
                             $count++;
                             $listing_info = $imported_data_processor->getData('ignore', $importedColumn);
                             $doc = new DOMDocument();
                             foreach ($listing->getProperties() as $property) {
                                 if ($property->getType() == 'complex' && !empty($listing_info[$property->id])) {
                                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                                     $doc->loadXML($listing_info[$property->id]);
                                     $results = $doc->getElementsByTagName($property->id . 's');
                                     $listing_info[$property->id] = array();
                                     foreach ($results as $complexparent) {
                                         $i = 0;
                                         foreach ($complexparent->getElementsByTagName($property->id) as $result) {
                                             $resultXML = simplexml_import_dom($result);
                                             foreach ($childFields as $childField) {
                                                 if (isset($resultXML->{$childField}['id'])) {
                                                     $listing_info[$property->id][$childField['id']][$i] = (string) $resultXML->{$childField}['id'];
                                                 }
                                             }
                                             $i++;
                                         }
                                     }
                                 } elseif ($property->getType() == 'location') {
                                     $locationFields = array($property->id . '.Country', $property->id . '.State', $property->id . '.City', $property->id . '.ZipCode');
                                     $locationFieldAdded = array();
                                     foreach ($locationFields as $locationField) {
                                         if (array_key_exists($locationField, $listing_info)) {
                                             switch ($locationField) {
                                                 case $property->id . '.Country':
                                                     $value = SJB_CountriesManager::getCountrySIDByCountryName($listing_info[$locationField]);
                                                     if (!$value) {
                                                         $value = SJB_CountriesManager::getCountrySIDByCountryCode($listing_info[$locationField]);
                                                     }
                                                     break;
                                                 case $property->id . '.State':
                                                     $value = SJB_StatesManager::getStateSIDByStateName($listing_info[$locationField]);
                                                     if (!$value) {
                                                         $value = SJB_StatesManager::getStateSIDByStateCode($listing_info[$locationField]);
                                                     }
                                                     break;
                                                 default:
                                                     $value = $listing_info[$locationField];
                                                     break;
                                             }
                                             $listing_info[$property->id][str_replace($property->id . '.', '', $locationField)] = $value;
                                             $locationFieldAdded[] = str_replace($property->id . '.', '', $locationField);
                                         }
                                     }
                                     if ($property->id == 'Location') {
                                         $locationFields = array('Country', 'State', 'City', 'ZipCode');
                                         foreach ($locationFields as $locationField) {
                                             if (array_key_exists($locationField, $listing_info) && !in_array($locationField, $locationFieldAdded) && !$listing->getProperty($locationField)) {
                                                 switch ($locationField) {
                                                     case 'Country':
                                                         $value = SJB_CountriesManager::getCountrySIDByCountryName($listing_info[$locationField]);
                                                         if (!$value) {
                                                             $value = SJB_CountriesManager::getCountrySIDByCountryCode($listing_info[$locationField]);
                                                         }
                                                         break;
                                                     case 'State':
                                                         $value = SJB_StatesManager::getStateSIDByStateName($listing_info[$locationField]);
                                                         if (!$value) {
                                                             $value = SJB_StatesManager::getStateSIDByStateCode($listing_info[$locationField]);
                                                         }
                                                         break;
                                                     default:
                                                         $value = $listing_info[$locationField];
                                                         break;
                                                 }
                                                 $listing_info[$property->id][$locationField] = $value;
                                             }
                                         }
                                     }
                                 }
                             }
                             $field_info = null;
                             $listing = new SJB_Listing($listing_info, $listing_type_sid);
                             foreach ($listing->getProperties() as $property) {
                                 if ($property->getType() == 'tree' && $property->value !== '') {
                                     $treeValues = explode(',', $property->value);
                                     $treeSIDs = array();
                                     foreach ($treeValues as $treeValue) {
                                         $info = SJB_ListingFieldTreeManager::getItemInfoByCaption($property->sid, trim($treeValue));
                                         $treeSIDs[] = $info['sid'];
                                     }
                                     $listing->setPropertyValue($property->id, implode(',', $treeSIDs));
                                     $listing->details->properties[$property->id]->type->property_info['value'] = implode(',', $treeSIDs);
                                 } elseif ($property->getType() == 'monetary') {
                                     $currency = SJB_CurrencyManager::getDefaultCurrency();
                                     $listing->details->properties[$property->id]->type->property_info['value']['add_parameter'] = $currency['sid'];
                                 } elseif ($property->id == 'ApplicationSettings' && !empty($listing_info['ApplicationSettings'])) {
                                     if (preg_match("^[a-z0-9\\._-]+@[a-z0-9\\._-]+\\.[a-z]{2,}\$^iu", $listing_info['ApplicationSettings'])) {
                                         $listing_info['ApplicationSettings'] = array('value' => $listing_info['ApplicationSettings'], 'add_parameter' => 1);
                                     } elseif (preg_match("^(https?:\\/\\/)^iu", $listing_info['ApplicationSettings'])) {
                                         $listing_info['ApplicationSettings'] = array('value' => $listing_info['ApplicationSettings'], 'add_parameter' => 2);
                                     } else {
                                         $listing_info['ApplicationSettings'] = array('value' => '', 'add_parameter' => '');
                                     }
                                     $listing->details->properties[$property->id]->type->property_info['value'] = $listing_info['ApplicationSettings'];
                                 } elseif ($property->getType() == 'complex' && is_array($property->value)) {
                                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                                     $complexChildValues = $property->value;
                                     foreach ($childFields as $childField) {
                                         if ($childField['type'] == 'complexfile' && !empty($complexChildValues[$childField['id']])) {
                                             $field_info = SJB_ListingComplexFieldManager::getFieldInfoBySID($childField['sid']);
                                             if (isset($listing_info[$property->id][$field_info['id']]) && file_exists($listing_info[$property->id][$field_info['id']])) {
                                                 SJB_UploadFileManager::fileImport($listing_info, $field_info, $property->id);
                                             }
                                         }
                                     }
                                 }
                                 // The import of files at import of listings
                                 if (in_array($property->getType(), array('file', 'logo', 'picture', 'video')) && $property->value !== '') {
                                     $field_info = SJB_ListingFieldDBManager::getListingFieldInfoByID($property->id);
                                     if (isset($listing_info[$field_info['id']]) && file_exists($listing_info[$field_info['id']])) {
                                         SJB_UploadFileManager::fileImport($listing_info, $field_info);
                                     }
                                 }
                             }
                             $listing->deleteProperty('featured');
                             $listing->deleteProperty('priority');
                             $listing->deleteProperty('status');
                             $listing->deleteProperty('reject_reason');
                             $listing->addProperty(array('id' => 'contract_id', 'type' => 'id', 'value' => $contract->getID(), 'is_system' => true));
                             $extraInfo = $contract->extra_info;
                             $listing->setProductInfo($extraInfo);
                             $listing->setPropertyValue('access_type', 'everyone');
                             $listing->setUserSID($current_user->sid);
                             if ($current_user->isSubuser()) {
                                 $subuserInfo = $current_user->getSubuserInfo();
                                 $listing->addSubuserProperty($subuserInfo['sid']);
                             }
                             SJB_ListingManager::saveListing($listing);
                             SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $extraInfo['featured'], $extraInfo['priority']);
                             $contract->incrementPostingsNumber();
                             SJB_ProductsManager::incrementPostingsNumber($contract->product_sid);
                             if (!empty($extraInfo['featured'])) {
                                 SJB_ListingManager::makeFeaturedBySID($listing->getSID());
                             }
                             if (!empty($extraInfo['priority'])) {
                                 SJB_ListingManager::makePriorityBySID($listing->getSID());
                             }
                             $this->FillGallery($listing, $listing_info);
                             $listingSIDs[] = $listing->getSID();
                         }
                         SJB_ListingManager::activateListingBySID($listingSIDs);
                         $tp->assign('listingsNum', count($listingSIDs));
                         $tp->display('job_import_complete.tpl');
                     } else {
                         $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
                         $error = 'LISTINGS_NUMBER_LIMIT_EXCEEDED';
                         $tp->assign('listing_type_id', $listing_type_id);
                         $tp->assign('error', $error);
                         $tp->display('job_import.tpl');
                     }
                 } else {
                     $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
                     $tp->assign('warning', $warning);
                     $tp->assign('contract_id', $contractID);
                     $tp->assign('listing_type_id', $listing_type_id);
                     $tp->display('job_import.tpl');
                 }
             }
         } else {
             $error = $acl->getPermissionMessage('bulk_job_import');
             if (empty($error)) {
                 $error = 'This action is not allowed within your current product';
             }
             $tp->assign('error', $error);
             $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
             $tp->assign('listing_type_id', $listing_type_id);
             $tp->display('job_import.tpl');
         }
     } else {
         if ($error == 'NO_CONTRACT') {
             if ($_GET) {
                 $getParam = '?';
                 foreach ($_GET as $key => $val) {
                     $getParam .= $key . '=' . $val . '&';
                 }
                 $getParam = substr($getParam, 0, -1);
             }
             $page = base64_encode(SJB_System::getURI() . $getParam);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-products/?page=' . $page);
         }
         $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
         $tp->assign('listing_type_id', $listing_type_id);
         $tp->assign('error', $error);
         $tp->display('job_import.tpl');
     }
 }
Exemplo n.º 13
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', 'search');
     $template = SJB_Request::getVar('template', 'sales.tpl');
     $errors = array();
     $userGroups = SJB_UserGroupManager::getAllUserGroupsIDsAndCaptions();
     foreach ($userGroups as $key => $userGroup) {
         unset($userGroups[$key]);
         $userGroups[$userGroup['id']] = $userGroup;
     }
     switch ($action) {
         case 'export':
             $period = SJB_Request::getVar('period', array());
             $filter = SJB_Request::getVar('filter', false);
             $sorting_field = SJB_Request::getVar('sorting_field', 'total');
             $sorting_order = SJB_Request::getVar('sorting_order', 'DESC');
             $statistics = array();
             if ($filter) {
                 $statistics = SJB_Statistics::getSalesStatistics($period, $filter, $sorting_field, $sorting_order);
                 if (!empty($statistics['errors'])) {
                     $errors = $statistics['errors'];
                 }
             } else {
                 $errors[] = 'EMPTY_PARAMETER';
             }
             $columnTitle = '';
             if (strstr($filter, 'userGroup_')) {
                 $userGroupSID = str_replace('userGroup_', '', $filter);
                 if ($userGroups[$userGroupSID]['key'] == 'Employer') {
                     $columnTitle = 'Company Name';
                 } else {
                     $columnTitle = $userGroups[$userGroupSID]['caption'] . ' Name';
                 }
                 $exportProperties['generalColumn'] = $columnTitle;
             } elseif ($filter == 'sid') {
                 $columnTitle = 'Product Name';
                 $exportProperties['generalColumn'] = 'Product Name';
                 $exportProperties['product_type'] = 'Product Type';
                 $tp->assign('link', 'product');
             } else {
                 $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($filter);
                 $exportProperties['generalColumn'] = $fieldInfo['caption'];
             }
             $exportProperties['units_sold'] = 'Units Sold';
             $exportProperties['total'] = 'Income';
             $exportProperties['percent'] = '%';
             if (!$errors && $statistics) {
                 $type = SJB_Request::getVar('type', 'csv');
                 SJB_StatisticsExportController::createExportDirectory();
                 switch ($type) {
                     case 'csv':
                         $exportData = SJB_StatisticsExportController::getSalesExportData($statistics, $exportProperties);
                         $fileName = 'sales.csv';
                         SJB_StatisticsExportController::makeCSVExportFile($exportData, $fileName, 'App & Views');
                         SJB_StatisticsExportController::archiveAndSendExportFile('sales', 'csv');
                         break;
                     case 'xls':
                         $exportData = SJB_StatisticsExportController::getSalesExportData($statistics, $exportProperties);
                         $fileName = 'sales.xls';
                         SJB_StatisticsExportController::makeXLSExportFile($exportData, $fileName, 'App & Views');
                         SJB_StatisticsExportController::archiveAndSendExportFile('sales', 'xls');
                         break;
                 }
                 break;
             }
         case 'search':
             $search = SJB_Request::getVar('search', false);
             $period = SJB_Request::getVar('period', array());
             $filter = SJB_Request::getVar('filter', false);
             $sorting_field = SJB_Request::getVar('sorting_field', 'total');
             $sorting_order = SJB_Request::getVar('sorting_order', 'DESC');
             $statistics = array();
             if ($search) {
                 if (!empty($period['from']) && !empty($period['to']) && strtotime($period['from']) > strtotime($period['to'])) {
                     $errors[] = 'SELECTED_PERIOD_IS_INCORRECT';
                 } else {
                     if ($filter) {
                         $statistics = SJB_Statistics::getSalesStatistics($period, $filter, $sorting_field, $sorting_order);
                         if (!empty($statistics['errors'])) {
                             $errors = $statistics['errors'];
                         }
                     } else {
                         $errors[] = 'EMPTY_PARAMETER';
                     }
                 }
             }
             $columnTitle = '';
             if (strstr($filter, 'userGroup_')) {
                 $userGroupSID = str_replace('userGroup_', '', $filter);
                 if ($userGroups[$userGroupSID]['key'] == 'Employer') {
                     $columnTitle = 'Company Name';
                 } else {
                     $columnTitle = $userGroups[$userGroupSID]['caption'] . ' Name';
                 }
                 $tp->assign('link', 'user');
             } else {
                 if ($filter == 'sid') {
                     $columnTitle = 'Product Name';
                     $tp->assign('link', 'product');
                 } else {
                     if (in_array($filter, array('Location_Country', 'Location_State', 'Location_City'))) {
                         $fieldInfo = SJB_ListingFieldDBManager::getLocationFieldsInfoById($filter);
                     } else {
                         $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($filter);
                     }
                     $columnTitle = $fieldInfo['caption'];
                 }
             }
             $i18n = SJB_I18N::getInstance();
             $periodView = array();
             foreach ($period as $key => $value) {
                 $periodView[$key] = $i18n->getInput('date', $period[$key]);
             }
             $tp->assign('search', $search);
             $tp->assign('filter', $filter);
             $tp->assign('columnTitle', $columnTitle);
             $tp->assign('period', $period);
             $tp->assign('periodView', $periodView);
             $tp->assign('statistics', $statistics);
             $tp->assign('countResult', count($statistics));
             $tp->assign('sorting_field', $sorting_field);
             $tp->assign('sorting_order', $sorting_order);
             break;
     }
     $tp->assign('userGroups', $userGroups);
     $tp->assign('errors', $errors);
     $tp->assign('action', $action);
     $tp->display($template);
 }
Exemplo n.º 14
0
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $tp = SJB_System::getTemplateProcessor();
     $file_info = isset($_FILES['import_file']) ? $_FILES['import_file'] : null;
     $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8');
     $listingTypeID = SJB_Request::getVar('listing_type_id', null);
     $productSID = SJB_Request::getVar('product_sid', 0);
     $errors = array();
     if ($listingTypeID && $productSID) {
         $acl = SJB_Acl::getInstance();
         $resource = 'post_' . strtolower($listingTypeID);
         if (!$acl->isAllowed($resource, $productSID, 'product')) {
             $errors[] = 'You cannot import listings of this type under the selected product';
         }
     }
     if (!empty($file_info)) {
         $extension = SJB_Request::getVar('file_type');
         if (!SJB_ImportFile::isValidFileExtensionByFormat($extension, $file_info)) {
             $errors['DO_NOT_MATCH_SELECTED_FILE_FORMAT'] = true;
         }
     }
     if (empty($file_info) || $file_info['error'] || $errors) {
         if (isset($file_info['error']) && $file_info['error'] > 0) {
             $errors[SJB_UploadFileManager::getErrorId($file_info['error'])] = 1;
         }
         $listing_types = SJB_ListingTypeManager::getAllListingTypesInfo();
         $products = SJB_ProductsManager::getProductsByProductType('post_listings');
         $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
         $tp->assign('listing_types', $listing_types);
         $tp->assign('products', $products);
         $tp->assign('errors', $errors);
         $tp->assign('charSets', SJB_HelperFunctions::getCharSets());
         $tp->display('import_listings.tpl');
     } else {
         $i18n = SJB_I18N::getInstance();
         $csv_delimiter = SJB_Request::getVar('csv_delimiter', null);
         $activeStatus = SJB_Request::getVar('active', 0);
         $activationDate = SJB_Request::getVar('activation_date', date('Y-m-d'));
         $activationDate = $i18n->getInput('date', $activationDate);
         $non_existed_values_flag = SJB_Request::getVar('non_existed_values', null);
         $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
         if (empty($productInfo['listing_duration'])) {
             $expirationDate = '';
         } else {
             $timestamp = strtotime($activationDate . ' + ' . $productInfo['listing_duration'] . ' days');
             $expirationDate = $i18n->getDate(date('Y-m-d', $timestamp));
         }
         $extension = $_REQUEST['file_type'];
         if ($extension == 'xls') {
             $import_file = new SJB_ImportFileXLS($file_info);
         } elseif ($extension == 'csv') {
             $import_file = new SJB_ImportFileCSV($file_info, $csv_delimiter);
         }
         $import_file->parse($encodingFromCharset);
         $listing = $this->CreateListing(array(), $listingTypeID);
         $imported_data = $import_file->getData();
         $isFileImported = true;
         $count = 0;
         $addedListingsSids = array();
         $nonExistentUsers = array();
         foreach ($imported_data as $key => $importedColumn) {
             if ($key == 1) {
                 $imported_data_processor = new SJB_ImportedDataProcessor($importedColumn, $listing);
                 continue;
             }
             if (!$importedColumn) {
                 continue;
             }
             $count++;
             $listingInfo = $imported_data_processor->getData($non_existed_values_flag, $importedColumn);
             $doc = new DOMDocument();
             foreach ($listing->getProperties() as $property) {
                 if ($property->getType() == 'complex' && !empty($listingInfo[$property->id])) {
                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                     $doc->loadXML($listingInfo[$property->id]);
                     $results = $doc->getElementsByTagName($property->id . 's');
                     $listingInfo[$property->id] = array();
                     foreach ($results as $complexparent) {
                         $i = 1;
                         foreach ($complexparent->getElementsByTagName($property->id) as $result) {
                             $resultXML = simplexml_import_dom($result);
                             foreach ($childFields as $childField) {
                                 if (isset($resultXML->{$childField}['id'])) {
                                     $listingInfo[$property->id][$childField['id']][$i] = XML_Util::reverseEntities((string) $resultXML->{$childField}['id']);
                                 }
                             }
                             $i++;
                         }
                     }
                 } elseif ($property->getType() == 'monetary' && !empty($listingInfo[$property->id])) {
                     $value = $listingInfo[$property->id];
                     $listingInfo[$property->id] = array();
                     $listingInfo[$property->id]['value'] = $value;
                     $defaultCurrency = SJB_CurrencyManager::getDefaultCurrency();
                     $currencyCode = !empty($listingInfo[$property->id . "Currency"]) ? $listingInfo[$property->id . "Currency"] : $defaultCurrency['currency_code'];
                     $currency = SJB_CurrencyManager::getCurrencyByCurrCode($currencyCode);
                     $listingInfo[$property->id]['add_parameter'] = !empty($currency['sid']) ? $currency['sid'] : '';
                     if (isset($listingInfo[$property->id . "Currency"])) {
                         unset($listingInfo[$property->id . "Currency"]);
                     }
                 } elseif ($property->getType() == 'location') {
                     $locationFields = array($property->id . '.Country', $property->id . '.State', $property->id . '.City', $property->id . '.ZipCode');
                     $locationFieldAdded = array();
                     foreach ($locationFields as $locationField) {
                         if (array_key_exists($locationField, $listingInfo)) {
                             switch ($locationField) {
                                 case $property->id . '.Country':
                                     $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]);
                                     if (!$value) {
                                         $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]);
                                     }
                                     break;
                                 case $property->id . '.State':
                                     $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]);
                                     if (!$value) {
                                         $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]);
                                     }
                                     break;
                                 default:
                                     $value = $listingInfo[$locationField];
                                     break;
                             }
                             $listingInfo[$property->id][str_replace($property->id . '.', '', $locationField)] = $value;
                             $locationFieldAdded[] = str_replace($property->id . '.', '', $locationField);
                         }
                     }
                     if ($property->id == 'Location') {
                         $locationFields = array('Country', 'State', 'City', 'ZipCode');
                         foreach ($locationFields as $locationField) {
                             if (array_key_exists($locationField, $listingInfo) && !in_array($locationField, $locationFieldAdded) && !$listing->getProperty($locationField)) {
                                 switch ($locationField) {
                                     case 'Country':
                                         $value = SJB_CountriesManager::getCountrySIDByCountryName($listingInfo[$locationField]);
                                         if (!$value) {
                                             $value = SJB_CountriesManager::getCountrySIDByCountryCode($listingInfo[$locationField]);
                                         }
                                         break;
                                     case 'State':
                                         $value = SJB_StatesManager::getStateSIDByStateName($listingInfo[$locationField]);
                                         if (!$value) {
                                             $value = SJB_StatesManager::getStateSIDByStateCode($listingInfo[$locationField]);
                                         }
                                         break;
                                     default:
                                         $value = $listingInfo[$locationField];
                                         break;
                                 }
                                 $listingInfo[$property->id][$locationField] = $value;
                             }
                         }
                     }
                 }
             }
             $listing = $this->CreateListing($listingInfo, $listingTypeID);
             $pictures = array();
             if (isset($listingInfo['pictures'])) {
                 $listing->addPicturesProperty();
                 $explodedPictures = explode(';', $listingInfo['pictures']);
                 foreach ($explodedPictures as $picture) {
                     if (!empty($picture)) {
                         $pictures[] = $picture;
                     }
                 }
                 $listing->setPropertyValue('pictures', count($pictures));
             }
             $listing->addActiveProperty($activeStatus);
             $listing->addActivationDateProperty($activationDate);
             $listing->addExpirationDateProperty($expirationDate);
             SJB_ListingDBManager::setListingExpirationDateBySid($listing->sid);
             $listing->setProductInfo(SJB_ProductsManager::getProductExtraInfoBySID($productSID));
             $listing->setPropertyValue('access_type', 'everyone');
             $listing->setPropertyValue('status', 'approved');
             foreach ($listing->getProperties() as $property) {
                 if ($property->getType() == 'tree' && $property->value !== '') {
                     try {
                         $treeImportHelper = new SJB_FieldTreeImportHelper($property->value);
                         $treeValues = $treeImportHelper->parseAndGetValues();
                         $listing->setPropertyValue($property->id, $treeValues);
                         $listing->details->properties[$property->id]->type->property_info['value'] = $treeValues;
                     } catch (Exception $e) {
                         $listing->setPropertyValue($property->id, '');
                         $listing->details->properties[$property->id]->type->property_info['value'] = '';
                         SJB_Error::writeToLog('Listing Import. Tree Field Value Error: ' . $e->getMessage());
                     }
                 } elseif ($property->id == 'ApplicationSettings' && !empty($listingInfo['ApplicationSettings'])) {
                     if (preg_match("^[a-z0-9\\._-]+@[a-z0-9\\._-]+\\.[a-z]{2,}\$^iu", $listingInfo['ApplicationSettings'])) {
                         $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 1);
                     } elseif (preg_match("^(https?:\\/\\/)^", $listingInfo['ApplicationSettings'])) {
                         $listingInfo['ApplicationSettings'] = array('value' => $listingInfo['ApplicationSettings'], 'add_parameter' => 2);
                     } else {
                         $listingInfo['ApplicationSettings'] = array('value' => '', 'add_parameter' => '');
                     }
                     //put empty if not valid email or url
                     $listing->details->properties[$property->id]->type->property_info['value'] = $listingInfo['ApplicationSettings'];
                 } elseif ($property->getType() == 'complex') {
                     $childFields = SJB_ListingComplexFieldManager::getListingFieldsInfoByParentSID($property->sid);
                     $complexChildValues = $property->value;
                     foreach ($childFields as $childField) {
                         if ($childField['type'] == 'complexfile' && !empty($complexChildValues[$childField['id']])) {
                             $fieldInfo = SJB_ListingComplexFieldManager::getFieldInfoBySID($childField['sid']);
                             if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo, $property->id)) {
                                 $isFileImported = false;
                             }
                         }
                         if ($property->type->complex->details->properties[$childField['id']]->value == null) {
                             $property->type->complex->details->properties[$childField['id']]->value = array(1 => '');
                             $property->type->complex->details->properties[$childField['id']]->type->property_info['value'] = array(1 => '');
                         }
                     }
                 }
                 // The import of files at import of listings
                 if (in_array($property->getType(), array('file', 'logo', 'video')) && $property->value !== '') {
                     $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($property->id);
                     if (!SJB_UploadFileManager::fileImport($listingInfo, $fieldInfo)) {
                         $isFileImported = false;
                     }
                 }
             }
             if ($non_existed_values_flag == 'add') {
                 $this->UpdateListValues($listing);
             }
             if ($listing->getUserSID()) {
                 SJB_ListingManager::saveListing($listing);
                 $listingSid = $listing->getSID();
                 SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listingSid);
                 SJB_ListingManager::activateListingBySID($listingSid, false);
                 if (!$this->fillGallery($listingSid, $pictures)) {
                     $isFileImported = false;
                 }
                 $addedListingsSids[] = $listingSid;
             } else {
                 $nonExistentUsers[] = $listingInfo['username'];
                 $count--;
             }
         }
         SJB_BrowseDBManager::addListings($addedListingsSids);
         SJB_ProductsManager::incrementPostingsNumber($productSID, count($addedListingsSids));
         if ($isFileImported && file_exists(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY'))) {
             SJB_Filesystem::delete(SJB_System::getSystemSettings('IMPORT_FILES_DIRECTORY'));
         }
         $tp->assign('imported_listings_count', $count);
         $tp->assign('nonExistentUsers', $nonExistentUsers);
         $tp->display('import_listings_result.tpl');
     }
 }
Exemplo n.º 15
0
 /**
  * Recurring notification handlign function
  * @param array|null $callback_data Notification data
  */
 function handleRecurringNotification($callback_data)
 {
     if (SJB_Array::get($callback_data, 'txn_type') == 'subscr_cancel' || SJB_Array::get($callback_data, 'txn_type') == 'subscr_eot') {
         SJB_ContractManager::removeSubscriptionId(SJB_Array::get($callback_data, 'subscr_id'));
         return;
     }
     if (SJB_Array::get($callback_data, 'txn_type') != 'subscr_payment') {
         return;
     }
     $invoice_sid = isset($callback_data['item_number']) ? $callback_data['item_number'] : null;
     if (is_null($invoice_sid)) {
         return;
     }
     $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid);
     if (is_null($invoice)) {
         return null;
     }
     $reactivation = false;
     $status = $invoice->getStatus();
     if ($invoice->getStatus() == SJB_Invoice::INVOICE_STATUS_PAID) {
         // Пришёл рекьюринг платёж
         $invoice->setSID(null);
         $invoice->setDate(null);
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
         $reactivation = true;
     }
     $invoice->setCallbackData($callback_data);
     if ($this->isPaymentVerified($invoice) && in_array($callback_data['payment_status'], array('Completed', 'Processed'))) {
         $items = $invoice->getPropertyValue('items');
         $user_sid = $invoice->getUserSID();
         $subscriptionSID = $callback_data['custom'];
         if (!empty($items['products'])) {
             $recurringProductsInfo = array();
             foreach ($items['products'] as $key => $product) {
                 if ($product != -1) {
                     $productInfo = $invoice->getItemValue($key);
                     if ($status == SJB_Invoice::INVOICE_STATUS_PAID && $subscriptionSID == $product) {
                         $listingNumber = $productInfo['qty'];
                         $contract = new SJB_Contract(array('product_sid' => $product, 'recurring_id' => $callback_data['subscr_id'], 'gateway_id' => 'paypal_standard', 'numberOfListings' => $listingNumber));
                         $contract->setUserSID($user_sid);
                         $contractSID = SJB_ContractManager::getContractSIDByRecurringId($callback_data['subscr_id']);
                         SJB_ContractManager::deleteAllContractsByRecurringId($callback_data['subscr_id']);
                         $contract->setPrice($productInfo['amount']);
                         if ($contract->saveInDB()) {
                             SJB_ShoppingCart::deleteItemFromCartBySID($productInfo['shoppingCartRecord'], $user_sid);
                             $bannerInfo = $productInfo['banner_info'];
                             if ($productInfo['product_type'] == 'banners' && !empty($bannerInfo)) {
                                 $bannersObj = new SJB_Banners();
                                 if (isset($contractSID)) {
                                     $bannerID = $bannersObj->getBannerIDByContract($contractSID);
                                     if ($bannerID) {
                                         $bannersObj->updateBannerContract($contract->getID(), $bannerID);
                                     }
                                 } else {
                                     $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $user_sid, $contract->getID());
                                     $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                                     SJB_AdminNotifications::sendAdminBannerAddedLetter($user_sid, $bannerGroup);
                                 }
                             }
                             if ($contract->isFeaturedProfile()) {
                                 SJB_UserManager::makeFeaturedBySID($user_sid);
                             }
                             SJB_Statistics::addStatistics('payment', 'product', $product, false, 0, 0, $user_sid, $productInfo['amount']);
                             if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($user_sid)) {
                                 SJB_Notifications::sendSubscriptionActivationLetter($user_sid, $productInfo, $reactivation);
                             }
                         }
                         $recurringProductsInfo[$key] = $productInfo;
                     } elseif ($status != SJB_Invoice::INVOICE_STATUS_PAID) {
                         $listingNumber = $productInfo['qty'];
                         if ($subscriptionSID == $product) {
                             $contract = new SJB_Contract(array('product_sid' => $product, 'recurring_id' => $callback_data['subscr_id'], 'gateway_id' => 'paypal_standard', 'numberOfListings' => $listingNumber));
                         } else {
                             $contract = new SJB_Contract(array('product_sid' => $product, 'gateway_id' => 'paypal_standard', 'numberOfListings' => $listingNumber));
                         }
                         $contract->setUserSID($user_sid);
                         $contract->setPrice($productInfo['amount']);
                         if ($contract->saveInDB()) {
                             SJB_ShoppingCart::deleteItemFromCartBySID($productInfo['shoppingCartRecord'], $user_sid);
                             $bannerInfo = $productInfo['banner_info'];
                             if ($productInfo['product_type'] == 'banners' && !empty($bannerInfo) && $contractSID) {
                                 $bannersObj = new SJB_Banners();
                                 $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $user_sid, $contract->getID());
                                 $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                                 SJB_AdminNotifications::sendAdminBannerAddedLetter($user_sid, $bannerGroup);
                             }
                             if ($contract->isFeaturedProfile()) {
                                 SJB_UserManager::makeFeaturedBySID($user_sid);
                             }
                             SJB_Statistics::addStatistics('payment', 'product', $product, false, 0, 0, $user_sid, $productInfo['amount']);
                             if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($user_sid)) {
                                 SJB_Notifications::sendSubscriptionActivationLetter($user_sid, $productInfo);
                             }
                         }
                     }
                 }
             }
             if ($reactivation) {
                 $invoice->setNewPropertiesToInvoice($recurringProductsInfo);
             }
             $price = isset($callback_data['payment_gross']) ? $callback_data['payment_gross'] : $invoice->getPropertyValue('total');
             $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_PAID);
             $id = $this->details->getProperty('id');
             $invoice->setPropertyValue('payment_method', $id->getValue());
             SJB_InvoiceManager::saveInvoice($invoice);
             SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoice->getSID());
             $transactionID = $callback_data['txn_id'];
             $transactionInfo = array('transaction_id' => $transactionID, 'invoice_sid' => $invoice->getSID(), 'amount' => $price, 'payment_method' => $invoice->getPropertyValue('payment_method'), 'user_sid' => $invoice->getPropertyValue('user_sid'));
             $transaction = new SJB_Transaction($transactionInfo);
             SJB_TransactionManager::saveTransaction($transaction);
         }
     } else {
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
         SJB_InvoiceManager::saveInvoice($invoice);
     }
 }
Exemplo n.º 16
0
 public function export()
 {
     $period = SJB_Request::getVar('period', array());
     $statisticEvent = SJB_Request::getVar('filter', false);
     $listingTypeID = SJB_Request::getVar('listingTypeID', false);
     $sorting_field = SJB_Request::getVar('sorting_field', 'total');
     $sorting_order = SJB_Request::getVar('sorting_order', 'DESC');
     if (empty($statisticEvent)) {
         throw new Exception('EMPTY_PARAMETER');
     }
     $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
     $statistics = SJB_Statistics::getGuestAlertsStatistics($period, $listingTypeSID, $statisticEvent, $sorting_field, $sorting_order);
     if (empty($statistics)) {
         throw new Exception('NOTHING_TO_EXPORT');
     }
     SJB_StatisticsExportController::createExportDirectory();
     $i18N = SJB_I18N::getInstance();
     $exportProperties['title'] = $i18N->gettext('Backend', 'Guest Email');
     $exportProperties['total'] = $i18N->gettext('Backend', 'Total');
     $exportProperties['percent'] = '%';
     $type = SJB_Request::getVar('type', 'csv');
     $fileName = 'guest_' . strtolower($listingTypeID . '_' . $statisticEvent) . '_statistics';
     $exportData = SJB_StatisticsExportController::getGuestAlertsExportData($statistics);
     switch ($type) {
         case 'csv':
             $ext = 'csv';
             SJB_StatisticsExportController::makeCSVExportFile($exportData, $fileName . '.' . $ext, "Guest {$listingTypeID} Alerts Statistics");
             break;
         default:
         case 'xls':
             $ext = 'xls';
             SJB_StatisticsExportController::makeXLSExportFile($exportData, $fileName . '.' . $ext, "Guest {$listingTypeID} Alerts Statistics");
             break;
     }
     SJB_StatisticsExportController::archiveAndSendExportFile($fileName, $ext);
 }
Exemplo n.º 17
0
 function handleRecurringNotification($notification_data)
 {
     //набор полей такой же как и при callback с Authorize.NET
     //плюс два поля x_subscription_id и x_subscription_paynum
     if (!$this->isNotificationFromGateway($notification_data)) {
         return;
         //уведомление не от Authorize.NET
     } else {
         if ($this->isNotificationSuccessfull($notification_data)) {
             $invoice_sid = null;
             if (isset($notification_data['x_invoice_num'])) {
                 $invoice_sid = $notification_data['x_invoice_num'];
             }
             if (is_null($invoice_sid)) {
                 return;
             }
             $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid);
             if (is_null($invoice)) {
                 return null;
             }
             $reactivation = false;
             if ($invoice->getStatus() == SJB_Invoice::INVOICE_STATUS_PAID) {
                 // Пришёл рекьюринг платёж
                 $invoice->setSID(null);
                 $invoice->setDate(null);
                 $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_UNPAID);
                 $reactivation = true;
             }
             $invoice->setCallbackData($notification_data);
             if (!$this->checkPaymentAmount($invoice)) {
                 return null;
             }
             $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_PAID);
             SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoice->getSID());
             $user_sid = $invoice->getPropertyValue('user_sid');
             $items = $invoice->getPropertyValue('items');
             if (!empty($items['products'])) {
                 $recurringProductsInfo = array();
                 foreach ($items['products'] as $key => $product) {
                     if ($product != -1) {
                         $productInfo = $invoice->getItemValue($key);
                         $listingNumber = $productInfo['qty'];
                         $contract = new SJB_Contract(array('product_sid' => $product, 'recurring_id' => $notification_data['x_subscription_id'], 'gateway_id' => 'authnet_sim', 'numberOfListings' => $listingNumber));
                         if (isset($contract)) {
                             $contract->setUserSID($user_sid);
                             $contractSID = SJB_ContractManager::getContractSIDByRecurringId($notification_data['x_subscription_id']);
                             SJB_ContractManager::deleteAllContractsByRecurringId($notification_data['x_subscription_id']);
                             $contract->setPrice($productInfo['amount']);
                             if ($contract->saveInDB()) {
                                 SJB_ShoppingCart::deleteItemFromCartBySID($productInfo['shoppingCartRecord'], $user_sid);
                                 $bannerInfo = $productInfo['banner_info'];
                                 if ($productInfo['product_type'] == 'banners' && !empty($bannerInfo) && $contractSID) {
                                     $bannersObj = new SJB_Banners();
                                     $bannerID = $bannersObj->getBannerIDByContract($contractSID);
                                     if ($bannerID) {
                                         $bannersObj->updateBannerContract($contract->getID(), $bannerID);
                                     }
                                 }
                                 SJB_Statistics::addStatistics('payment', 'product', $product, false, 0, 0, $user_sid, $productInfo['amount']);
                                 if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($user_sid)) {
                                     SJB_Notifications::sendSubscriptionActivationLetter($user_sid, $productInfo, $reactivation);
                                 }
                             }
                         }
                         if (isset($productInfo['recurring'])) {
                             $recurringProductsInfo[$key] = $productInfo;
                         }
                     }
                 }
                 if ($reactivation) {
                     $invoice->setNewPropertiesToInvoice($recurringProductsInfo);
                 }
                 SJB_InvoiceManager::saveInvoice($invoice);
                 if (isset($notification_data['x_trans_id'])) {
                     $transactionId = $notification_data['x_trans_id'];
                     $transactionInfo = array('transaction_id' => $transactionId, 'invoice_sid' => $invoice->getSID(), 'amount' => $invoice->getPropertyValue('total'), 'payment_method' => $invoice->getPropertyValue('payment_method'), 'user_sid' => $invoice->getPropertyValue('user_sid'));
                     $transaction = new SJB_Transaction($transactionInfo);
                     SJB_TransactionManager::saveTransaction($transaction);
                 }
             }
         } else {
             //уведомление о неуспешном платеже
         }
     }
 }
Exemplo n.º 18
0
 /**
  * @param $listingSID
  * @param $contractID
  * @param $productSID
  */
 public function addListing($listingSID, $contractID = false, $productSID = false)
 {
     if ($productSID != false) {
         $extraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productSID);
         $extraInfo['product_sid'] = (string) $extraInfo['product_sid'];
     } else {
         $contract = new SJB_Contract(array('contract_id' => $contractID));
         $extraInfo = $contract->extra_info;
     }
     $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
     $this->tp->assign("pic_limit", $numberOfPictures);
     $listingTypesInfo = SJB_ListingTypeManager::getAllListingTypesInfo();
     if (!$this->listingTypeID && count($listingTypesInfo) == 1) {
         $listingTypeInfo = array_pop($listingTypesInfo);
         $this->listingTypeID = $listingTypeInfo['id'];
     }
     $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($this->listingTypeID);
     $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listingTypeSID);
     $pageSID = $this->getPageSID($pages, $listingTypeSID);
     $isPageLast = SJB_PostingPagesManager::isLastPageByID($pageSID, $listingTypeSID);
     $isPreviewListingRequested = SJB_Request::getVar('preview_listing', false, 'POST');
     if (($contractID || !empty($this->buttonPressedPostToProceed)) && $this->listingTypeID) {
         $formSubmitted = isset($_REQUEST['action_add']) || isset($_REQUEST['action_add_pictures']) || $isPreviewListingRequested;
         /*
          * social plugin
          * complete listing of data from an array of social data
          * if is allowed
          */
         $aAutoFillData = array('formSubmitted' => &$formSubmitted, 'listingTypeID' => &$this->listingTypeID);
         SJB_Event::dispatch('SocialSynchronization', $aAutoFillData);
         /*
          * end of "social plugin"
          */
         $listing = new SJB_Listing($_REQUEST, $listingTypeSID, $pageSID);
         $listing->deleteProperty('featured');
         $listing->deleteProperty('priority');
         $listing->deleteProperty('status');
         $listing->deleteProperty('reject_reason');
         $listing->deleteProperty('ListingLogo');
         $access_type = $listing->getProperty('access_type');
         if ($formSubmitted) {
             if (!empty($access_type)) {
                 $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar("list_emp_ids"), 'is_system' => true));
             }
             $listing->addProperty(array('id' => 'contract_id', 'type' => 'id', 'value' => $contractID, 'is_system' => true));
         }
         $currentUser = SJB_UserManager::getCurrentUser();
         $screeningQuestionnaires = SJB_ScreeningQuestionnaires::getList($currentUser->getSID());
         if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screeningQuestionnaires) {
             $issetQuestionnairyField = $listing->getProperty('screening_questionnaire');
             if ($issetQuestionnairyField) {
                 $value = SJB_Request::getVar("screening_questionnaire");
                 $listingInfo = $_REQUEST;
                 $value = $value ? $value : isset($listingInfo['screening_questionnaire']) ? $listingInfo['screening_questionnaire'] : '';
                 $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($currentUser->getSID()), 'is_system' => true));
             }
         } else {
             $listing->deleteProperty('screening_questionnaire');
         }
         /*
          * social plugin
          * "synchronization"
          * if user is not registered using linkedin , delete linkedin sync property
          * also if sync is turned off in admin part
          */
         $aAutoFillData = array('oListing' => &$listing, 'userSID' => $currentUser->getSID(), 'listingTypeID' => $this->listingTypeID, 'listing_info' => $_REQUEST);
         SJB_Event::dispatch('SocialSynchronizationFields', $aAutoFillData);
         /*
          * end of social plugin "sync"
          */
         $listingFormAdd = new SJB_Form($listing);
         $listingFormAdd->registerTags($this->tp);
         $fieldErrors = array();
         if ($formSubmitted && ($this->formSubmittedFromPreview || $listingFormAdd->isDataValid($fieldErrors))) {
             if ($isPageLast) {
                 $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
             }
             $listing->setUserSID($currentUser->getSID());
             $listing->setProductInfo($extraInfo);
             if (empty($access_type->value)) {
                 $listing->setPropertyValue('access_type', 'everyone');
             }
             if ($currentUser->isSubuser()) {
                 $subuserInfo = $currentUser->getSubuserInfo();
                 $listing->addSubuserProperty($subuserInfo['sid']);
             }
             /**
              * >>>>> listing preview @author still
              */
             if (!empty($listingSID)) {
                 $listing->setSID($listingSID);
             }
             /*
              * <<<<< listing preview
              */
             SJB_ListingManager::saveListing($listing);
             if (!empty($this->buttonPressedPostToProceed)) {
                 SJB_ListingManager::unmakeCheckoutedBySID($listing->getSID());
             }
             SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $extraInfo['featured'], $extraInfo['priority']);
             if ($contractID) {
                 $contract = new SJB_Contract(array('contract_id' => $contractID));
                 $contract->incrementPostingsNumber();
                 SJB_ProductsManager::incrementPostingsNumber($contract->product_sid);
             }
             if (SJB_Session::getValue('tmp_file_storage')) {
                 foreach ($_SESSION['tmp_file_storage'] as $v) {
                     SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `picture_saved_name` = ?s", $listing->getSID(), $v['picture_saved_name']);
                     SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `thumb_saved_name` = ?s", $listing->getSID(), $v['thumb_saved_name']);
                 }
                 SJB_Session::unsetValue('tmp_file_storage');
             }
             // >>> SJB-1197
             // check temporary uploaded storage for listing uploads and assign it to saved listing
             $formToken = SJB_Request::getVar('form_token');
             $sessionFilesStorage = SJB_Session::getValue('tmp_uploads_storage');
             $uploadedFields = SJB_Array::getPath($sessionFilesStorage, $formToken);
             if (!empty($uploadedFields)) {
                 foreach ($uploadedFields as $fieldId => $fieldValue) {
                     // get field of listing
                     $isComplex = false;
                     if (strpos($fieldId, ':') !== false) {
                         $isComplex = true;
                     }
                     $tmpUploadedFileId = $fieldValue['file_id'];
                     // rename it to real listing field value
                     $newFileId = $fieldId . "_" . $listing->getSID();
                     SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                     if ($isComplex) {
                         list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                         $parentProp = $listing->getProperty($parentField);
                         $parentValue = $parentProp->getValue();
                         // look for complex property with current $fieldID and set it to new value of property
                         if (!empty($parentValue)) {
                             foreach ($parentValue as $id => $value) {
                                 if ($id == $subField) {
                                     $parentValue[$id][$complexStep] = $newFileId;
                                 }
                             }
                             $listing->setPropertyValue($parentField, $parentValue);
                         }
                     } else {
                         $listing->setPropertyValue($fieldId, $newFileId);
                     }
                     // unset value from session temporary storage
                     $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}/{$fieldId}");
                 }
                 //and remove token key from temporary storage
                 $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}");
                 SJB_Session::setValue('tmp_uploads_storage', $sessionFilesStorage);
                 SJB_ListingManager::saveListing($listing);
                 $keywords = $listing->getKeywords();
                 SJB_ListingManager::updateKeywords($keywords, $listing->getSID());
             }
             // <<< SJB-1197
             if ($isPageLast && !$isPreviewListingRequested) {
                 /* delete temp preview listing sid */
                 SJB_Session::unsetValue('preview_listing_sid_for_add');
                 // Start Event
                 $listingSid = $listing->getSID();
                 SJB_Event::dispatch('listingSaved', $listingSid);
                 if ($extraInfo['featured']) {
                     SJB_ListingManager::makeFeaturedBySID($listing->getSID());
                 }
                 if ($extraInfo['priority']) {
                     SJB_ListingManager::makePriorityBySID($listing->getSID());
                 }
                 if (!empty($this->buttonPressedPostToProceed)) {
                     $this->proceedToCheckout($currentUser->getSID(), $productSID);
                 } else {
                     if (SJB_ListingManager::activateListingBySID($listing->getSID())) {
                         SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID());
                     }
                     // notify administrator
                     SJB_AdminNotifications::sendAdminListingAddedLetter($listing);
                     if (isset($_REQUEST['action_add_pictures'])) {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-pictures/?listing_id=" . $listing->getSID());
                     } else {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-' . strtolower($this->listingTypeID) . '/?listing_id=' . $listing->getSID());
                     }
                 }
             } elseif ($isPageLast && $isPreviewListingRequested) {
                 // for listing preview
                 SJB_Session::setValue('preview_listing_sid_for_add', $listing->getSID());
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/' . strtolower($this->listingTypeID) . '-preview/' . $listing->getSID() . '/');
             } else {
                 // listing steps (pages)
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/add-listing/{$this->listingTypeID}/" . SJB_PostingPagesManager::getNextPage($pageSID) . "/" . $listing->getSID());
             }
         } else {
             $listing->deleteProperty('access_list');
             $listing->deleteProperty('contract_id');
             $listingFormAdd = new SJB_Form($listing);
             if ($formSubmitted) {
                 $listingFormAdd->isDataValid($fieldErrors);
             }
             $listingFormAdd->registerTags($this->tp);
             $template = isset($_REQUEST['input_template']) ? $_REQUEST['input_template'] : "input_form.tpl";
             $formFields = $listingFormAdd->getFormFieldsInfo();
             $employersList = SJB_Request::getVar('list_emp_ids', false);
             $employers = array();
             if (is_array($employersList)) {
                 foreach ($employersList as $emp) {
                     $currEmp = SJB_UserManager::getUserInfoBySID($emp);
                     $employers[] = array('user_id' => $emp, 'value' => $currEmp['CompanyName']);
                 }
                 sort($employers);
             }
             $this->tp->assign('form_token', SJB_Request::getVar('form_token'));
             $this->tp->assign("account_activated", SJB_Request::getVar('account_activated', ''));
             $this->tp->assign("contract_id", $contractID);
             $this->tp->assign("listing_access_list", $employers);
             $this->tp->assign("listingTypeID", $this->listingTypeID);
             $this->tp->assign('listingTypeStructure', SJB_ListingTypeManager::createTemplateStructure(SJB_ListingTypeManager::getListingTypeInfoBySID($listing->listing_type_sid)));
             $this->tp->assign("field_errors", $fieldErrors);
             $this->tp->assign("form_fields", $formFields);
             $this->tp->assign("pages", $pages);
             $this->tp->assign("pageSID", $pageSID);
             $this->tp->assign("extraInfo", $extraInfo);
             $this->tp->assign("currentPage", SJB_PostingPagesManager::getPageInfoBySID($pageSID));
             $this->tp->assign("isPageLast", $isPageLast);
             $this->tp->assign("nextPage", SJB_PostingPagesManager::getNextPage($pageSID));
             $this->tp->assign("prevPage", SJB_PostingPagesManager::getPrevPage($pageSID));
             $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
             $this->tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($formFields)));
             /*
              * social plugin
              * only for Resume listing types
              */
             $aAutoFillData = array('tp' => &$this->tp, 'listingTypeID' => &$this->listingTypeID, 'userSID' => $currentUser->getSID());
             SJB_Event::dispatch('SocialSynchronizationForm', $aAutoFillData);
             /*
              * social plugin
              */
             $this->tp->display($template);
         }
     }
 }
Exemplo n.º 19
0
 private function sendSearchedNotifications()
 {
     $savedSearches = SJB_SavedSearches::getAutoNotifySavedSearches();
     $listing = new SJB_Listing();
     $this->notifiedSavedSearchesSID = array();
     $notificationsLimit = (int) SJB_Settings::getSettingByName('num_of_listings_sent_in_email_alerts');
     foreach ($savedSearches as $savedSearch) {
         $searcher = new SJB_ListingSearcher();
         $listing->addActivationDateProperty();
         $dataSearch = unserialize($savedSearch['data']);
         $dataSearch['active']['equal'] = 1;
         $dateArray = explode('-', $savedSearch['last_send']);
         $savedSearch['last_send'] = strftime($this->lang['date_format'], mktime(0, 0, 0, $dateArray[1], $dateArray[2], $dateArray[0]));
         $dataSearch['activation_date']['not_less'] = $savedSearch['last_send'];
         $dataSearch['activation_date']['not_more'] = $this->currentDate;
         $listingTypeSID = 0;
         if ($dataSearch['listing_type']['equal']) {
             $listingTypeID = $dataSearch['listing_type']['equal'];
             $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
             if (SJB_ListingTypeManager::getWaitApproveSettingByListingType($listingTypeSID)) {
                 $dataSearch['status']['equal'] = 'approved';
             }
         }
         $idAliasInfo = $listing->addIDProperty();
         $usernameAliasInfo = $listing->addUsernameProperty();
         $listingTypeIDInfo = $listing->addListingTypeIDProperty();
         $aliases = new SJB_PropertyAliases();
         $aliases->addAlias($idAliasInfo);
         $aliases->addAlias($usernameAliasInfo);
         $aliases->addAlias($listingTypeIDInfo);
         $dataSearch['access_type'] = array('accessible' => $savedSearch['user_sid']);
         $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($dataSearch, $listing);
         $searcher->found_object_sids = array();
         $searcher->setLimit($notificationsLimit);
         $foundListingsIDs = $searcher->getObjectsSIDsByCriteria($criteria, $aliases);
         if (count($foundListingsIDs)) {
             $savedSearch['activation_date'] = $savedSearch['last_send'];
             if (SJB_Notifications::sendUserNewListingsFoundLetter($foundListingsIDs, $savedSearch['user_sid'], $savedSearch, $listingTypeSID)) {
                 SJB_Statistics::addStatistics('sentAlert', $listingTypeSID, $savedSearch['sid']);
                 SJB_DB::query('UPDATE `saved_searches` SET `last_send` = CURDATE() WHERE `sid` = ?n', $savedSearch['sid']);
             }
             $this->notifiedSavedSearchesSID[] = $savedSearch['sid'];
         }
     }
 }
Exemplo n.º 20
0
 public static function saveEventSubscribed($listingTypeSID, $guestAlertSID)
 {
     parent::addStatistics(self::EVENT_SUBSCRIBED, $listingTypeSID, $guestAlertSID);
 }
Exemplo n.º 21
0
 public function unmakePriority($userSID, $price)
 {
     $listing_id = $this->product['listing_id'];
     SJB_ListingManager::unmakePriorityBySID($listing_id);
     SJB_Statistics::deleteStatistics('payment', 'priorityListing', $this->invoiceSID, $userSID, $price);
 }
Exemplo n.º 22
0
 public static function incrementViewsCounterForListing($listingId, $listing)
 {
     $listingViews = SJB_DB::query('SELECT `views` FROM `listings` WHERE `sid` = ?n limit 1', $listingId);
     $ipAddress = SJB_Request::$remoteAddr;
     if (empty($listingViews) || SJB_Request::isBot() || !self::isViewCanBeCounted($listingId, $ipAddress)) {
         return false;
     }
     SJB_Statistics::addStatistics('viewListing', $listing->getListingTypeSID(), $listing->getSID());
     self::setListingLatestViewDateByIp($listingId, $ipAddress);
     return SJB_DB::query('UPDATE `listings` SET `views` = `views` + 1 WHERE `sid` = ?n limit 1', $listingId);
 }
Exemplo n.º 23
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listingTypeID = SJB_Request::getVar('listing_type_id', null);
     $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
     $listingTypeInfo = SJB_ListingTypeManager::getListingTypeInfoBySID($listingTypeSID);
     $productSID = SJB_Request::getVar('product_sid', false);
     $editUser = SJB_Request::getVar('edit_user', false);
     $action = SJB_Request::getVar('action', false);
     $username = SJB_Request::getVar('username', false);
     $errors = array();
     if ($username && ($userSID = SJB_UserManager::getUserSIDbyUsername($username))) {
         $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
         $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userInfo['user_group_sid']);
         if (!$productSID) {
             $products = SJB_ProductsManager::getProductsInfoByUserGroupSID($userGroupInfo['sid']);
             foreach ($products as $key => $product) {
                 if (empty($product['listing_type_sid']) || $product['listing_type_sid'] != $listingTypeSID) {
                     unset($products[$key]);
                 }
             }
             if ($action == 'productVerify') {
                 $errors['PRODUCT_NOT_SELECTED'] = 1;
             }
             $tp->assign('errors', $errors);
             $tp->assign('username', $username);
             $tp->assign('products', $products);
             $tp->assign('edit_user', $editUser);
             $tp->assign('userSID', $userSID);
             $tp->assign('userGroupInfo', $userGroupInfo);
             $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
             $tp->display('select_product.tpl');
         } else {
             $form_submitted = SJB_Request::getVar('action', '') == 'add';
             $tmp_listing_id_from_request = SJB_Request::getVar('listing_id', false, 'default', 'int');
             if (!empty($tmp_listing_id_from_request)) {
                 $tmp_listing_sid = $tmp_listing_id_from_request;
             } elseif (!$tmp_listing_id_from_request) {
                 $tmp_listing_sid = time();
             }
             $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
             $extraInfo = is_null($productInfo['serialized_extra_info']) ? null : unserialize($productInfo['serialized_extra_info']);
             if (!empty($extraInfo)) {
                 $extraInfo['product_sid'] = $productSID;
             }
             $_REQUEST['featured'] = !empty($_REQUEST['featured']) ? $_REQUEST['featured'] : $productInfo['featured'];
             $_REQUEST['priority'] = !empty($_REQUEST['priority']) ? $_REQUEST['priority'] : $productInfo['priority'];
             $listing = new SJB_Listing($_REQUEST, $listingTypeSID);
             $properties = $listing->getPropertyList();
             foreach ($properties as $property) {
                 $propertyInfo = $listing->getPropertyInfo($property);
                 $propertyInfo['user_sid'] = $userSID;
                 if ($propertyInfo['type'] == 'location') {
                     $child = $listing->getChild($property);
                     $childProperties = $child->getPropertyList();
                     foreach ($childProperties as $childProperty) {
                         $childPropertyInfo = $child->getPropertyInfo($childProperty);
                         $childPropertyInfo['user_sid'] = $userSID;
                         $child->setPropertyInfo($childProperty, $childPropertyInfo);
                     }
                 }
                 $listing->setPropertyInfo($property, $propertyInfo);
             }
             $listing->deleteProperty('status');
             $listing->deleteProperty('reject_reason');
             $access_type = $listing->getProperty('access_type');
             if ($form_submitted) {
                 if (!empty($access_type)) {
                     $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar("list_emp_ids"), 'is_system' => true));
                 }
             }
             $screening_questionnaires = SJB_ScreeningQuestionnaires::getList($userSID);
             if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) {
                 $issetQuestionnairyField = $listing->getProperty('screening_questionnaire');
                 if ($issetQuestionnairyField) {
                     $value = SJB_Request::getVar("screening_questionnaire");
                     $listing_info = $_REQUEST;
                     $value = $value ? $value : isset($listing_info['screening_questionnaire']) ? $listing_info['screening_questionnaire'] : '';
                     $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($userSID), 'is_system' => true));
                 }
             } else {
                 $listing->deleteProperty('screening_questionnaire');
             }
             if ($listing->getProperty('captcha')) {
                 $listing->deleteProperty('captcha');
             }
             $add_listing_form = new SJB_Form($listing);
             $add_listing_form->registerTags($tp);
             $field_errors = array();
             if ($form_submitted && $add_listing_form->isDataValid($field_errors)) {
                 $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 $listing->setUserSID($userSID);
                 $listing->setProductInfo($extraInfo);
                 if (empty($access_type->value)) {
                     $listing->setPropertyValue('access_type', 'everyone');
                 }
                 SJB_ListingManager::saveListing($listing);
                 SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $_REQUEST['featured'], $_REQUEST['priority'], $userSID);
                 if (isset($_SESSION['tmp_file_storage'])) {
                     foreach ($_SESSION['tmp_file_storage'] as $v) {
                         SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `picture_saved_name` = ?s", $listing->getSID(), $v['picture_saved_name']);
                         SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `thumb_saved_name` = ?s", $listing->getSID(), $v['thumb_saved_name']);
                     }
                     SJB_Session::unsetValue('tmp_file_storage');
                 }
                 $formToken = SJB_Request::getVar('form_token');
                 $sessionFilesStorage = SJB_Session::getValue('tmp_uploads_storage');
                 $uploadedFields = SJB_Array::getPath($sessionFilesStorage, $formToken);
                 if (!empty($uploadedFields)) {
                     foreach ($uploadedFields as $fieldId => $fieldValue) {
                         // get field of listing
                         $isComplex = false;
                         if (strpos($fieldId, ':') !== false) {
                             $isComplex = true;
                         }
                         $tmpUploadedFileId = $fieldValue['file_id'];
                         // rename it to real listing field value
                         $newFileId = $fieldId . "_" . $listing->getSID();
                         SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                         if ($isComplex) {
                             list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                             $parentProp = $listing->getProperty($parentField);
                             $parentValue = $parentProp->getValue();
                             // look for complex property with current $fieldID and set it to new value of property
                             if (!empty($parentValue)) {
                                 foreach ($parentValue as $id => $value) {
                                     if ($id == $subField) {
                                         $parentValue[$id][$complexStep] = $newFileId;
                                     }
                                 }
                                 $listing->setPropertyValue($parentField, $parentValue);
                             }
                         } else {
                             $listing->setPropertyValue($fieldId, $newFileId);
                         }
                         // unset value from session temporary storage
                         $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}/{$fieldId}");
                     }
                     //and remove token key from temporary storage
                     $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}");
                     SJB_Session::setValue('tmp_uploads_storage', $sessionFilesStorage);
                     SJB_ListingManager::saveListing($listing);
                 }
                 SJB_ListingManager::activateListingBySID($listing->getSID());
                 SJB_ProductsManager::incrementPostingsNumber($productSID);
                 $listingSid = $listing->getSID();
                 SJB_Event::dispatch('listingSaved', $listingSid);
                 if ($editUser) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-user/?user_sid=" . $userSID);
                 } else {
                     if ($listingTypeID == 'resume' || $listingTypeID == 'job') {
                         $link = "manage-" . strtolower($listingTypeID) . "s";
                     } else {
                         $link = "manage-" . strtolower($listingTypeID) . "-listings";
                     }
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/{$link}/?action=search&listing_type_sid=" . $listingTypeSID);
                 }
             } else {
                 $listing->deleteProperty('access_list');
                 $listing->deleteProperty('contract_id');
                 $add_listing_form = new SJB_Form($listing);
                 if ($form_submitted) {
                     $add_listing_form->isDataValid($field_errors);
                 }
                 $add_listing_form->registerTags($tp);
                 $form_fields = $add_listing_form->getFormFieldsInfo();
                 $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listingTypeSID);
                 $formFieldsSorted = array();
                 $formFieldsSorted['featured'] = $form_fields['featured'];
                 $formFieldsSorted['priority'] = $form_fields['priority'];
                 foreach ($pages as $page) {
                     $listing_fields = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']);
                     foreach (array_keys($listing_fields) as $field) {
                         if ($listing->propertyIsSet($field)) {
                             $formFieldsSorted[$field] = $form_fields[$field];
                         }
                     }
                 }
                 $form_fields = $formFieldsSorted;
                 //SJB_HelperFunctions::d($form_fields);
                 $employers_list = SJB_Request::getVar('list_emp_ids', false);
                 $employers = array();
                 if (is_array($employers_list)) {
                     foreach ($employers_list as $emp) {
                         $currEmp = SJB_UserManager::getUserInfoBySID($emp);
                         $employers[] = array('user_id' => $emp, 'value' => $currEmp['CompanyName']);
                     }
                     sort($employers);
                 }
                 $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
                 $tp->assign("pic_limit", $numberOfPictures);
                 $tp->assign("listing_id", $tmp_listing_sid);
                 $tp->assign("listing_access_list", $employers);
                 $tp->assign("errors", $field_errors);
                 $tp->assign("form_fields", $form_fields);
                 $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
                 $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields)));
             }
             $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
             $tp->assign('edit_user', $editUser);
             $tp->assign('productInfo', $productInfo);
             $tp->assign('username', $username);
             $tp->assign('product_sid', $productSID);
             $tp->assign('userSID', $userSID);
             $tp->assign('userGroupInfo', $userGroupInfo);
             $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
             $tp->display('input_form.tpl');
         }
     } else {
         if ($username && !$userSID) {
             $errors['USER_NOT_FOUND'] = 1;
         } elseif ($action == 'userVerify') {
             $errors['USER_NOT_SELECTED'] = 1;
         }
         $tp->assign('errors', $errors);
         $tp->assign('username', $username);
         $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
         $tp->display('select_user.tpl');
     }
 }
Exemplo n.º 24
0
SJB_System::init();
if (SJB_Profiler::getInstance()->isProfilerEnable()) {
    SJB_Profiler::getInstance()->setStartTime($timeBegin);
}
SJB_Event::dispatch('AfterSystemBoot');
SJB_UpdateManager::updateDatabase();
//bind send notification emails if listing deactivated/deleted
SJB_Event::handle('listingDeactivated', array('SJB_Notifications', 'notifyOnUserListingDeactivated'));
SJB_Event::handle('beforeListingDelete', array('SJB_Notifications', 'notifyOnUserListingDeleted'));
//bind send notification emails if user deactivated/deleted
SJB_Event::handle('onBeforeUserDelete', array('SJB_Notifications', 'notifyOnUserDeleted'));
SJB_Event::handle('onBeforeUserDeactivate', array('SJB_Notifications', 'notifyOnUserDeactivated'));
// bind session clear to task scheduler event
SJB_Event::handle('task_scheduler_run', array('SJB_Session', 'clearTemporaryData'));
SJB_Request::getInstance()->execute();
SJB_Statistics::addStatistics('siteView', '', 0, true);
$isPseudoCronEnabled = intval(SJB_Settings::getSettingByName('isPseudoCronEnabled')) === 1;
if ($isPseudoCronEnabled) {
    $isEmailSchedulerEnabled = intval(SJB_Settings::getSettingByName('email_scheduling')) === 1;
    $isOncePerHourCondition = SJB_Settings::getSettingByName('emailSchedule_lastTimeExecuted') < strtotime('1 hour ago');
    if ($isEmailSchedulerEnabled && $isOncePerHourCondition) {
        SJB_Settings::updateSetting('emailSchedule_lastTimeExecuted', time());
        SJB_System::getModuleManager()->executeFunction('miscellaneous', 'email_scheduling');
    }
    $numberOfPageViewsSinceLastTime = SJB_Settings::getValue('pseudoCron_numberOfPageViewsSinceLastTime');
    $isPageViewCondition = intval(SJB_Settings::getValue('pseudoCron_numberOfPageViewsSinceLastTime')) > SJB_Settings::getSettingByName('numberOfPageViewsToExecCronIfExceeded');
    if ($isPageViewCondition) {
        SJB_Settings::updateSetting('pseudoCron_numberOfPageViewsSinceLastTime', 0);
        list($month, $day, $year) = explode('.', SJB_Settings::getSettingByName('task_scheduler_last_executed_date'));
        $isOnceADayCondition = strtotime("{$year}-{$month}-{$day}") < strtotime('today');
        if ($isOnceADayCondition) {
Exemplo n.º 25
0
 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);
     }
 }
Exemplo n.º 26
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $registration_form_template = 'registration_form.tpl';
     if (SJB_Authorization::isUserLoggedIn()) {
         $tp->display('already_logged_in.tpl');
         return;
     }
     $tp->assign('terms_of_use_check', SJB_System::getSettingByName('terms_of_use_check'));
     $user_group_id = SJB_Request::getVar('user_group_id', null);
     if (!is_null($user_group_id)) {
         $user_group_sid = SJB_UserGroupManager::getUserGroupSIDByID($user_group_id);
         if (empty($user_group_sid)) {
             $errors['NO_SUCH_USER_GROUP_IN_THE_SYSTEM'] = 1;
         }
     }
     $this->setSessionValueForRedirectAfterRegister();
     if (!is_null($user_group_id) && empty($errors)) {
         $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
         $user = SJB_ObjectMother::createUser($_REQUEST, $user_group_sid);
         if (SJB_Request::isAjax() || 'true' == SJB_Request::getVar('isajaxrequest')) {
             $field = SJB_Request::getVar('type');
             if ('email' == $field) {
                 $user->getProperty($field)->type->disableEmailConfirmation();
             }
             echo $user->getProperty($field)->isValid();
             exit;
         }
         $user->deleteProperty('active');
         $user->deleteProperty('featured');
         $form_submitted = SJB_Request::getVar('action', false) == 'register';
         if (class_exists('MobilePlugin') && MobilePlugin::isMobileThemeOn()) {
             $user->prepareRegistrationFields();
         }
         $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);
         }
         if ($form_submitted && $registration_form->isDataValid($errors)) {
             $user->deleteProperty('captcha');
             $defaultProduct = SJB_UserGroupManager::getDefaultProduct($user_group_sid);
             SJB_UserManager::saveUser($user);
             SJB_Statistics::addStatistics('addUser', $user->getUserGroupSID(), $user->getSID());
             $availableProductIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($user_group_sid);
             if ($defaultProduct && in_array($defaultProduct, $availableProductIDs)) {
                 $contract = new SJB_Contract(array('product_sid' => $defaultProduct));
                 $contract->setUserSID($user->getSID());
                 $contract->saveInDB();
             }
             // >>> SJB-1197
             // needs to check session for ajax-uploaded files, and set it to user profile
             $formToken = SJB_Request::getVar('form_token');
             $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
             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}");
                     }
                     // save user with new values
                     SJB_UserManager::saveUser($user);
                     // clean temporary storage
                     $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}");
                     // CLEAR TEMPORARY SESSION STORAGE
                     SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
                 }
             }
             // <<< SJB-1197
             // notifying administrator
             SJB_AdminNotifications::sendAdminUserRegistrationLetter($user);
             // Activation
             $isSendActivationEmail = SJB_UserGroupManager::isSendActivationEmail($user_group_sid);
             $isApproveByAdmin = SJB_UserGroupManager::isApproveByAdmin($user_group_sid);
             if ($isApproveByAdmin) {
                 SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending');
             }
             if ($isSendActivationEmail) {
                 $fromAnonymousShoppingCart = SJB_Session::getValue('fromAnonymousShoppingCart');
                 SJB_Session::unsetValue('fromAnonymousShoppingCart');
                 $isSent = SJB_Notifications::sendUserActivationLetter($user->getSID(), $fromAnonymousShoppingCart ? true : false);
                 if ($isSent) {
                     $registration_form_template = 'registration_confirm.tpl';
                 } else {
                     SJB_FlashMessages::getInstance()->addWarning('ERROR_SEND_ACTIVATION_EMAIL');
                     $registration_form_template = 'registration_failed_to_send_activation_email.tpl';
                 }
             } else {
                 if (!$isSendActivationEmail && $isApproveByAdmin) {
                     SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending');
                     $registration_form_template = 'registration_pending.tpl';
                 } else {
                     SJB_UserManager::activateUserByUserName($user->getUserName());
                     if (!SJB_SocialPlugin::getProfileSocialID($user->getSID())) {
                         SJB_Notifications::sendUserWelcomeLetter($user->getSID());
                     }
                     SJB_Authorization::login($user->getUserName(), $_REQUEST['password']['original'], false, $errors);
                     $proceedToPosting = SJB_Session::getValue('proceed_to_posting');
                     if ($proceedToPosting) {
                         $redirectUrl = SJB_HelperFunctions::getSiteUrl() . '/add-listing/?listing_type_id=' . SJB_Session::getValue('listing_type_id') . '&proceed_to_posting=' . $proceedToPosting . '&productSID=' . SJB_Session::getValue('productSID');
                     } else {
                         $pageId = !empty($user_group_info['after_registration_redirect_to']) ? $user_group_info['after_registration_redirect_to'] : '';
                         $redirectUrl = SJB_UserGroupManager::getRedirectUrlByPageID($pageId);
                     }
                     SJB_HelperFunctions::redirect($redirectUrl);
                 }
             }
         } else {
             if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_group_sid)) {
                 $user->deleteProperty('username');
             }
             $registration_form = SJB_ObjectMother::createForm($user);
             $registration_form->registerTags($tp);
             $registration_form_template = 'registration_form.tpl';
             if (isset($_REQUEST['reg_form_template'])) {
                 $registration_form_template = $_REQUEST['reg_form_template'];
             } elseif (!empty($user_group_info['reg_form_template'])) {
                 $registration_form_template = $user_group_info['reg_form_template'];
             }
             $form_fields = $registration_form->getFormFieldsInfo();
             // define default template with ajax checking
             $registration_form->setDefaultTemplateByFieldName('email', 'email_ajaxchecking.tpl');
             $registration_form->setDefaultTemplateByFieldName('username', 'unique_string.tpl');
             // use specific template for user profile video
             $registration_form->setDefaultTemplateByFieldName('video', 'video_profile.tpl');
             $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)));
         }
     } else {
         $registration_form_template = 'registration_choose_user_group.tpl';
         $user_groups_info = SJB_UserGroupManager::getAllUserGroupsInfo();
         $tp->assign('user_groups_info', $user_groups_info);
     }
     $tp->assign('userTree', true);
     $tp->assign('errors', $errors);
     $tp->display($registration_form_template);
 }
Exemplo n.º 27
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', 'search');
     $filter = SJB_Request::getVar('filter', array());
     $template = SJB_Request::getVar('template', 'general_statistics.tpl');
     $errors = array();
     switch ($action) {
         case 'export':
             $period = SJB_Request::getVar('period', false);
             $groupBy = SJB_Request::getVar('group_by', 'day');
             $statistics = SJB_Statistics::getGeneralStatistics($period, $groupBy, $filter);
             if (!empty($statistics['errors'])) {
                 $errors[] = $statistics['errors'];
             }
             if (!$errors && $statistics) {
                 $type = SJB_Request::getVar('type', 'csv');
                 $listingTypes = SJB_ListingTypeManager::getListingAllTypesForListType();
                 $userGroups = SJB_UserGroupManager::getAllUserGroupsIDsAndCaptions();
                 SJB_StatisticsExportController::createExportDirectory();
                 switch ($type) {
                     case 'csv':
                         $exportData = SJB_StatisticsExportController::getGeneralExportData($statistics, $userGroups, $listingTypes, $filter);
                         $fileName = 'general_statistics.csv';
                         SJB_StatisticsExportController::makeCSVExportFile($exportData, $fileName, 'General Statistics');
                         SJB_StatisticsExportController::archiveAndSendExportFile('general_statistics', 'csv');
                         break;
                     case 'xls':
                         $exportData = SJB_StatisticsExportController::getGeneralExportData($statistics, $userGroups, $listingTypes, $filter);
                         $fileName = 'general_statistics.xls';
                         SJB_StatisticsExportController::makeXLSExportFile($exportData, $fileName, 'General Statistics');
                         SJB_StatisticsExportController::archiveAndSendExportFile('general_statistics', 'xls');
                         break;
                 }
                 break;
             }
         case 'search':
             $search = SJB_Request::getVar('search', false);
             $period = SJB_Request::getVar('period', false);
             $groupBy = SJB_Request::getVar('group_by', 'day');
             $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 (count($filter) > 1) {
                         $statistics = SJB_Statistics::getGeneralStatistics($period, $groupBy, $filter);
                         if (!empty($statistics['errors'])) {
                             $errors[] = $statistics['errors'];
                         }
                     } else {
                         $errors[] = 'EMPTY_PARAMETER';
                     }
                 }
             }
             $listingTypes = SJB_ListingTypeManager::getListingAllTypesForListType();
             $userGroups = SJB_UserGroupManager::getAllUserGroupsIDsAndCaptions();
             $listPlugins = SJB_PluginManager::getAllPluginsList();
             $tp->assign('listPlugins', $listPlugins);
             $tp->assign('countItems', count($statistics) + 2);
             $tp->assign('userGroups', $userGroups);
             $tp->assign('listingTypes', $listingTypes);
             $tp->assign('errors', $errors);
             $tp->assign('groupBy', $groupBy);
             $tp->assign('statistics', $statistics);
             $tp->assign('period', $period);
             break;
     }
     $tp->assign('filter', $filter);
     $tp->assign('action', $action);
     $tp->display($template);
 }
Exemplo n.º 28
0
 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);
 }
Exemplo n.º 29
0
 public function execute()
 {
     $errors = array();
     $field_errors = array();
     $tp = SJB_System::getTemplateProcessor();
     $loggedIn = SJB_UserManager::isUserLoggedIn();
     $current_user_sid = SJB_UserManager::getCurrentUserSID();
     $controller = new SJB_SendListingInfoController($_REQUEST);
     $isDataSubmitted = false;
     $jobInfo = SJB_ListingManager::getListingInfoBySID($controller->getListingID());
     if ($controller->isListingSpecified()) {
         if ($controller->isDataSubmitted()) {
             if (SJB_Captcha::getInstance($tp, $_REQUEST)->isValid($errors)) {
                 // получим уникальный id для файла в uploaded_files
                 $file_id_current = 'application_' . md5(microtime());
                 $upload_manager = new SJB_UploadFileManager();
                 $upload_manager->setFileGroup('files');
                 $upload_manager->setUploadedFileID($file_id_current);
                 $file_name = $upload_manager->uploadFile('file_tmp');
                 $id_file = $upload_manager->fileId;
                 $post = $controller->getData();
                 $listingId = 0;
                 $post['submitted_data']['questionnaire'] = '';
                 if (isset($post['submitted_data']['id_resume'])) {
                     $listingId = $post['submitted_data']['id_resume'];
                 }
                 $mimeType = isset($_FILES['file_tmp']['type']) ? $_FILES['file_tmp']['type'] : '';
                 if (isset($_FILES['file_tmp']['size']) && $file_name != '' && $_FILES['file_tmp']['size'] == 0) {
                     $errors['FILE_IS_EMPTY'] = 'The uploaded file should not be blank';
                 }
                 if (!empty($_FILES['file_tmp']['name'])) {
                     $fileFormats = explode(',', SJB_System::getSettingByName('file_valid_types'));
                     $fileInfo = pathinfo($_FILES['file_tmp']['name']);
                     if (!isset($fileInfo['extension']) || !in_array(strtolower($fileInfo['extension']), $fileFormats)) {
                         $errors['NOT_SUPPORTED_FILE_FORMAT'] = strtolower($fileInfo['extension']) . ' ' . SJB_I18N::getInstance()->gettext(null, 'is not in an acceptable file format');
                     }
                 }
                 if ($file_name == '' && $listingId == 0) {
                     $canAppplyWithoutResume = false;
                     SJB_Event::dispatch('CanApplyWithoutResume', $canAppplyWithoutResume);
                     if (!$canAppplyWithoutResume) {
                         $errors['APPLY_INPUT_ERROR'] = 'Please select file or resume';
                     }
                 } else {
                     if (SJB_Applications::isApplied($post['submitted_data']['listing_id'], $current_user_sid) && !is_null($current_user_sid)) {
                         $errors['APPLY_APPLIED_ERROR'] = 'You already applied';
                     }
                 }
                 $res = false;
                 $listing_info = '';
                 $notRegisterUserData = $_POST;
                 $score = 0;
                 // для зарегестрированного пользователя получим поля email и name
                 // для незарегестрированных - поля name и email приходят с формы
                 if ($loggedIn === true) {
                     $userData = SJB_UserManager::getCurrentUserInfo();
                     $post['submitted_data']['username'] = isset($userData['username']) ? $userData['username'] : '';
                     $post['submitted_data']['LastName'] = isset($userData['LastName']) ? $userData['LastName'] : '';
                     $post['submitted_data']['FirstName'] = isset($userData['FirstName']) ? $userData['FirstName'] : '';
                     $post['submitted_data']['name'] = $post['submitted_data']['FirstName'] . ' ' . $post['submitted_data']['LastName'];
                     $post['submitted_data']['email'] = $userData['email'];
                 }
                 if (!empty($jobInfo['screening_questionnaire'])) {
                     $questions = new SJB_Questions($_REQUEST, $jobInfo['screening_questionnaire']);
                     $add_form = new SJB_Form($questions);
                     $add_form->registerTags($tp);
                     $add_form->isDataValid($field_errors);
                     $tp->assign('field_errors', $field_errors);
                     if (!$field_errors) {
                         $result = array();
                         $properties = $questions->getProperties();
                         $countAnswers = 0;
                         foreach ($properties as $key => $val) {
                             if ($val->type->property_info['type'] == 'boolean') {
                                 switch ($val->value) {
                                     case 0:
                                         $val->value = 'No';
                                         break;
                                     case 1:
                                         $val->value = 'Yes';
                                         break;
                                 }
                             }
                             $result[$val->caption] = $val->value;
                             if (isset($val->type->property_info['list_values'])) {
                                 foreach ($val->type->property_info['list_values'] as $list_values) {
                                     if (is_array($val->value)) {
                                         foreach ($val->value as $value) {
                                             if ($value == $list_values['id'] && $list_values['score'] != 'no') {
                                                 $score += $list_values['score'];
                                                 $countAnswers++;
                                             }
                                         }
                                     } else {
                                         if ($val->value == $list_values['id'] && $list_values['score'] != 'no') {
                                             $score += $list_values['score'];
                                             $countAnswers++;
                                         }
                                     }
                                 }
                             }
                         }
                         if ($countAnswers === 0) {
                             $score = 0.0;
                         } else {
                             $score = round($score / $countAnswers, 2);
                         }
                         $post['submitted_data']['questionnaire'] = serialize($result);
                     }
                 }
                 if (count($errors) == 0 && count($field_errors) == 0) {
                     $res = SJB_Applications::create($post['submitted_data']['listing_id'], $current_user_sid, isset($post['submitted_data']['id_resume']) ? $post['submitted_data']['id_resume'] : '', $post['submitted_data']['comments'], $file_name, $mimeType, $id_file, isset($post['submitted_data']['anonymous']) ? $post['submitted_data']['anonymous'] : '0', $notRegisterUserData, $post['submitted_data']['questionnaire'], $score);
                     if ($res) {
                         SJB_Statistics::addStatistics('apply', $post['submitted_data']['listing_id'], $res);
                     }
                     if (isset($post['submitted_data']['id_resume']) && $post['submitted_data']['id_resume'] != 0) {
                         $listing_info = SJB_ListingManager::getListingInfoBySID($post['submitted_data']['id_resume']);
                         $emp_sid = SJB_ListingManager::getUserSIDByListingSID($post['submitted_data']['listing_id']);
                         $accessible = SJB_ListingManager::isListingAccessableByUser($post['submitted_data']['id_resume'], $emp_sid);
                         if (!$accessible) {
                             SJB_ListingManager::setListingAccessibleToUser($post['submitted_data']['id_resume'], $emp_sid);
                         }
                     }
                     if (!empty($file_name)) {
                         $file_name = 'files/files/' . $file_name;
                     }
                     SJB_Notifications::sendApplyNow($post, $file_name, $listing_info, $current_user_sid, $notRegisterUserData, $score);
                     if (!empty($jobInfo['screening_questionnaire'])) {
                         $questionnaire = SJB_ScreeningQuestionnaires::getInfoBySID($jobInfo['screening_questionnaire']);
                         if ($questionnaire) {
                             $passing_score = 0;
                             switch ($questionnaire['passing_score']) {
                                 case 'acceptable':
                                     $passing_score = 1;
                                     break;
                                 case 'good':
                                     $passing_score = 2;
                                     break;
                                 case 'very_good':
                                     $passing_score = 3;
                                     break;
                                 case 'excellent':
                                     $passing_score = 4;
                                     break;
                             }
                         }
                         if ($score >= $passing_score && $questionnaire['send_auto_reply_more'] == 1) {
                             if (!empty($questionnaire['email_text_more'])) {
                                 SJB_Notifications::userAutoReply($jobInfo, $current_user_sid, $questionnaire['email_text_more'], $notRegisterUserData);
                             }
                         } elseif ($score < $passing_score && $questionnaire['send_auto_reply_less'] == 1) {
                             if (!empty($questionnaire['email_text_less'])) {
                                 SJB_Notifications::userAutoReply($jobInfo, $current_user_sid, $questionnaire['email_text_less'], $notRegisterUserData);
                             }
                         }
                     }
                 }
                 if ($res === false) {
                     $errors['APPLY_ERROR'] = 'Cannot apply';
                 }
                 $isDataSubmitted = true;
             }
         }
         if (!empty($jobInfo['screening_questionnaire'])) {
             $questions = new SJB_Questions($_REQUEST, $jobInfo['screening_questionnaire']);
             $add_form = new SJB_Form($questions);
             $add_form->registerTags($tp);
             $form_fields = $add_form->getFormFieldsInfo();
             $tp->assign('form_fields', $form_fields);
             $tp->assign('questionsObject', $questions);
         }
         if ($loggedIn) {
             $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID('Resume');
             $wait_approve = SJB_ListingTypeManager::getWaitApproveSettingByListingType($listing_type_sid);
             $approve_status = '';
             if ($wait_approve) {
                 $approve_status = "AND `l`.`status` = 'approved'";
             }
             $result = SJB_DB::query("SELECT `l`.`sid` , `l`.`Title` FROM `listings` as `l`\n\t\t\t\tLEFT JOIN `listing_types` as `lt` ON (`lt`.`sid` = `l`.`listing_type_sid`)\n\t\t\t\tWHERE `lt`.`id` = 'Resume' {$approve_status} AND `l`.`user_sid` = {$current_user_sid} AND `l`.`active`");
             $resume = array();
             foreach ($result as $val) {
                 $resume[$val['sid']] = $val['Title'];
             }
             $tp->assign('resume', $resume);
         }
         $tp->assign('listing', $jobInfo);
     } else {
         $errors['UNDEFINED_LISTING_ID'] = true;
     }
     $tp->assign('request', $_REQUEST);
     $tp->assign('errors', $errors);
     $tp->assign('listing_id', $controller->getListingID());
     $tp->assign('is_data_submitted', $isDataSubmitted);
     $tp->display('apply_now.tpl');
 }
Exemplo n.º 30
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $invoice_sid = SJB_Request::getVar('invoice_sid', null, false, 'int');
     $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid);
     $user = null;
     $errors = null;
     $userHasContract = false;
     if (!is_null($invoice)) {
         $status = $invoice->getStatus();
         if ($status == SJB_Invoice::INVOICE_STATUS_VERIFIED) {
             $userSID = $invoice->getPropertyValue('user_sid');
             $items = $invoice->getPropertyValue('items');
             $products = $items['products'];
             $user = SJB_UserManager::getObjectBySID($userSID);
             $userHasContract = $user->hasContract();
             $paymentStatus = false;
             foreach ($products as $key => $productSID) {
                 if ($productSID != -1) {
                     $product_info = $invoice->getItemValue($key);
                     $products[$key] = $product_info;
                     if (!empty($product_info['listing_type_sid'])) {
                         $listingTypeID = SJB_ListingTypeDBManager::getListingTypeIDBySID($product_info['listing_type_sid']);
                         $listingTypeName = SJB_ListingTypeManager::getListingTypeNameBySID($product_info['listing_type_sid']);
                         if (!in_array($listingTypeID, array('Job', 'Resume'))) {
                             $listingTypeName .= ' Listing';
                         }
                         $listingTypes[] = array('ID' => $listingTypeID, 'name' => $listingTypeName);
                     }
                     $listingNumber = $product_info['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($product_info['shoppingCartRecord'], $userSID);
                         $bannerInfo = $product_info['banner_info'];
                         $paymentStatus = true;
                         if ($product_info['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, $product_info);
                         }
                     }
                 } else {
                     if (isset($items['custom_info'][$key]['type'])) {
                         $products[$key] = $this->updateListing($items['custom_info'][$key]['type'], $key, $items, $userSID);
                     } else {
                         $products[$key] = array('name' => $items['custom_item'][$key]);
                     }
                     $paymentStatus = true;
                 }
             }
             if ($paymentStatus) {
                 $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_PAID);
                 SJB_InvoiceManager::saveInvoice($invoice);
                 SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoice->getSID());
             }
             if (isset($listingTypes)) {
                 $tp->assign('listingTypes', $listingTypes);
             }
             $tp->assign('products', $products);
         } else {
             $errors['INVOICE_IS_NOT_VERIFIED'] = 1;
         }
     } else {
         $errors['INVALID_INVOICE_ID'] = 1;
     }
     if (!$errors) {
         $subTotal = $invoice->getPropertyValue('sub_total');
         if (empty($subTotal)) {
             SJB_Statistics::addStatisticsFromInvoice($invoice);
         }
         $isUserJustRegistered = SJB_UserManager::isCurrentUserJustRegistered();
         if (isset($items['products']) && count($items['products']) == 1 && $isUserJustRegistered && !$userHasContract) {
             $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($user->getUserGroupSID());
             $pageId = !empty($userGroupInfo['after_registration_redirect_to']) ? $userGroupInfo['after_registration_redirect_to'] : '';
             $redirectUrl = SJB_UserGroupManager::getRedirectUrlByPageID($pageId);
             SJB_HelperFunctions::redirect($redirectUrl);
         }
     }
     $tp->assign('errors', $errors);
     $tp->display('create_contract.tpl');
 }