예제 #1
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     if (isset($_REQUEST['ajax'])) {
         $sent = 0;
         $ids = array();
         if (isset($_REQUEST['userids'])) {
             $ids = $_REQUEST['userids'];
             foreach ($ids as $user_sid) {
                 if (!empty($user_sid) && SJB_Notifications::sendUserActivationLetter($user_sid)) {
                     $sent++;
                 }
             }
         }
         $tp->assign("countOfSuccessfulSent", $sent);
         $tp->assign("countOfUnsuccessfulSent", count($ids) - $sent);
         $tp->display("send_activation_letter.tpl");
         exit;
     }
     $user_sid = SJB_Request::getVar('usersid', null);
     $error = null;
     if (!SJB_UserManager::getObjectBySID($user_sid)) {
         $error = "USER_DOES_NOT_EXIST";
     } elseif (!SJB_Notifications::sendUserActivationLetter($user_sid)) {
         $error = "CANNOT_SEND_EMAIL";
     }
     $tp->assign("error", $error);
     $tp->display("send_activation_letter.tpl");
 }
예제 #2
0
 public function execute()
 {
     $templateProcessor = SJB_System::getTemplateProcessor();
     $listingSid = isset($_REQUEST['listing_id']) ? $_REQUEST['listing_id'] : null;
     $listing = SJB_ListingManager::getObjectBySID($listingSid);
     if (!is_null($listing) && !$listing->isActive()) {
         $listingInfo = SJB_ListingManager::getListingInfoBySID($listingSid);
         $productInfo = !empty($listingInfo['product_info']) ? unserialize($listingInfo['product_info']) : array();
         if (isset($listingInfo['complete']) && $listingInfo['complete'] == 1 && $listingInfo['checkouted'] == 1) {
             $subTotalPrice = 0;
             // проверить истек ли листинг, если истек , прайс прировнять к renewal_price
             if (SJB_ListingManager::getIfListingHasExpiredBySID($listing->getID()) && isset($productInfo['renewal_price'])) {
                 $subTotalPrice = $productInfo['renewal_price'];
             }
             $userSid = $listing->getUserSID();
             $productSid = $productInfo['product_sid'];
             $listingTitle = $listing->getProperty('Title')->getValue();
             $listingTypeSid = $listing->getListingTypeSID();
             $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listingTypeSid);
             $newProductName = "Reactivation of \"{$listingTitle}\" {$listingTypeId}";
             $newProductInfo = SJB_ShoppingCart::createInfoForCustomProduct($userSid, $productSid, $listingSid, $subTotalPrice, $newProductName, 'activateListing');
             if ($subTotalPrice <= 0) {
                 if (SJB_ListingManager::activateListingBySID($listing->getSID())) {
                     SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID());
                 }
             } else {
                 SJB_ShoppingCart::createCustomProduct($newProductInfo, $userSid);
                 $shoppingUrl = SJB_System::getSystemSettings('SITE_URL') . '/shopping-cart/';
                 SJB_HelperFunctions::redirect($shoppingUrl);
             }
             $templateProcessor->assign('listingTypeID', SJB_ListingTypeManager::getListingTypeIDBySID($listingTypeSid));
         } elseif ($listingInfo['checkouted'] == 0) {
             $productsInfoFromShopppingCart = SJB_ShoppingCart::getProductsInfoFromCartByProductSID($productInfo['product_sid'], $listing->getUserSID());
             if (empty($productsInfoFromShopppingCart)) {
                 $productInfoToShopCart = SJB_ProductsManager::getProductInfoBySID($productInfo['product_sid']);
                 $productInfo['number_of_listings'] = 1;
                 $productObj = new SJB_Product($productInfoToShopCart, $productInfoToShopCart['product_type']);
                 $productObj->setNumberOfListings($productInfoToShopCart['number_of_listings']);
                 $productInfoToShopCart['price'] = $productObj->getPrice();
                 SJB_ShoppingCart::addToShoppingCart($productInfoToShopCart, $listing->getUserSID());
             }
             SJB_HelperFunctions::redirect(SJB_System::getSystemsettings('SITE_URL') . '/shopping-cart/');
         } else {
             $errors['LISTING_IS_NOT_COMPLETE'] = 1;
         }
     } elseif (is_null($listingSid)) {
         $errors['INVALID_LISTING_ID'] = 1;
     } elseif (!is_null($listing) && $listing->isActive()) {
         $errors['LISTING_ALREADY_ACTIVE'] = 1;
     } else {
         $errors['WRONG_LISTING_ID_SPECIFIED'] = 1;
     }
     $templateProcessor->assign("errors", isset($errors) ? $errors : null);
     $templateProcessor->display("pay_for_listing.tpl");
 }
예제 #3
0
파일: create.php 프로젝트: Maxlander/shixi
 /**
  * @param SJB_GuestAlert $guestAlert
  * @param SJB_TemplateProcessor $tp
  */
 public function saveNewGuestAlert(SJB_GuestAlert $guestAlert, SJB_TemplateProcessor $tp)
 {
     $guestAlert->addDataProperty(serialize($this->criteriaData));
     $guestAlert->addListingTypeIDProperty($this->listingTypeID);
     $guestAlert->save();
     $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($this->listingTypeID);
     SJB_GuestAlertStatistics::saveEventSubscribed($listingTypeSID, $guestAlert->getSID());
     SJB_Notifications::sendConfirmationEmailForGuest($guestAlert);
     $tp->assign('email', $guestAlert->getAlertEmail());
     $this->template = 'alert_created.tpl';
 }
예제 #4
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $oSubAdmin = SJB_ObjectMother::createSubAdmin($_REQUEST);
     $registration_form = SJB_ObjectMother::createForm($oSubAdmin);
     $registration_form->registerTags($tp);
     $form_submitted = SJB_Request::getVar('action', '') == 'add';
     $errors = array();
     $acl = SJB_SubAdminAcl::getInstance();
     $type = 'subadmin';
     $resources = $acl->getResources();
     SJB_SubAdminAcl::mergePermissionsWithResources($resources);
     switch (SJB_Request::getVar('action')) {
         case 'save':
             if ($registration_form->isDataValid($errors)) {
                 SJB_SubAdminManager::saveSubAdmin($oSubAdmin);
                 $role = $oSubAdmin->getSID();
                 SJB_Acl::clearPermissions($type, $role);
                 foreach ($resources as $name => $resource) {
                     SJB_SubAdminAcl::allow($name, $type, $role, SJB_SubAdminAcl::definePermission($name), SJB_Request::getVar($name . '_params'));
                 }
                 // get new defined permissions for notification letter
                 $permissions = SJB_SubAdminAcl::getAllPermissions($type, $role);
                 $resources = $acl->getResources();
                 SJB_SubAdminAcl::mergePermissionsWithResources($resources, $permissions);
                 SJB_Notifications::sendSubAdminRegistrationLetter($oSubAdmin, SJB_Request::get(), $resources);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-subadmins/');
             }
             break;
         case 'delete':
             $subadmins = SJB_Request::getVar('subadmin', array());
             foreach ($subadmins as $subadmin_sid) {
                 $username = SJB_SubAdminManager::getUserNameBySubAdminSID($subadmin_sid);
                 SJB_SubAdminManager::deleteSubAdminByUserName($username);
             }
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-subadmins/');
             break;
         default:
             break;
     }
     $tp->assign('errors', $errors);
     $tp->assign('form_fields', $registration_form->getFormFieldsInfo());
     $aPermissionGroups = SJB_SubAdminAcl::getPermissionGroups();
     if ('save' == SJB_Request::getVar('action', '')) {
         SJB_SubAdminAcl::mergePermissionsWithRequest($resources);
     }
     SJB_SubAdminAcl::prepareSubPermissions($resources);
     $tp->assign('groups', $aPermissionGroups);
     $tp->assign('resources', $resources);
     $tp->assign('type', $type);
     $tp->assign('role', 0);
     $tp->display('add_subadmin.tpl');
 }
예제 #5
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $activated = SJB_Request::getVar('account_activated', '') == 'yes';
     if (SJB_Request::getVar('returnToShoppingCart', false)) {
         SJB_Session::setValue('fromAnonymousShoppingCart', 1);
     }
     if (!$activated) {
         if (!isset($_REQUEST['username'], $_REQUEST['activation_key'])) {
             $errors['PARAMETERS_MISSED'] = 1;
         } elseif (!($userInfo = SJB_UserManager::getUserInfoByUserName($_REQUEST['username']))) {
             $errors['USER_NOT_FOUND'] = 1;
         } elseif ($userInfo['activation_key'] != $_REQUEST['activation_key']) {
             $errors['INVALID_ACTIVATION_KEY'] = true;
         } elseif ($userInfo['approval'] == 'Rejected') {
             SJB_UserDBManager::deleteActivationKeyByUsername($_REQUEST['username']);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/system/users/activate_account/?account_activated=no&approval_status=Rejected');
         } else {
             if (SJB_UserManager::activateUserByUserName($_REQUEST['username'])) {
                 SJB_UserDBManager::deleteActivationKeyByUsername($_REQUEST['username']);
                 if (!SJB_Authorization::isUserLoggedIn()) {
                     SJB_Authorization::login($_REQUEST['username'], false, false, $errors, true, true);
                     if (!SJB_SocialPlugin::getProfileSocialID($userInfo['sid'])) {
                         SJB_Notifications::sendUserWelcomeLetter($userInfo['sid']);
                     }
                     $requireApprove = SJB_UserGroupManager::isApproveByAdmin($userInfo['user_group_sid']);
                     if ($requireApprove && !empty($userInfo['approval'])) {
                         $approvalStatus = $userInfo['approval'];
                     } else {
                         $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userInfo['user_group_sid']);
                         $pageId = !empty($userGroupInfo['after_registration_redirect_to']) ? $userGroupInfo['after_registration_redirect_to'] : '';
                         $redirectUrl = SJB_UserGroupManager::getRedirectUrlByPageID($pageId);
                         SJB_HelperFunctions::redirect($redirectUrl . 'account_activated=yes');
                     }
                 }
                 $activated = 1;
             } else {
                 $errors['CANNOT_ACTIVATE'] = TRUE;
             }
         }
     }
     $tp->assign('activated', $activated);
     $tp->assign('errors', $errors);
     $tp->assign('approvalStatus', !empty($approvalStatus) ? $approvalStatus : SJB_Request::getVar('approval_status', ''));
     $tp->assign('isLoggedIn', SJB_Authorization::isUserLoggedIn());
     $tp->display('activate_account.tpl');
 }
예제 #6
0
파일: confirm.php 프로젝트: Maxlander/shixi
 public function execute()
 {
     $key = SJB_Request::getVar('key', '', 'GET');
     $tp = SJB_System::getTemplateProcessor();
     $error = '';
     try {
         $guestAlert = SJB_GuestAlertManager::getGuestAlertByKey($key);
         $guestAlert->setStatusActiveFromUnconfirmed();
         $guestAlert->update();
         SJB_Notifications::sendGuestAlertWelcomeEmail($guestAlert);
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     $tp->assign('error', $error);
     $tp->display('confirm.tpl');
 }
예제 #7
0
 public function createContract($userSID, $invoiceID, $reactivation, $status = 'active')
 {
     $listingNumber = !empty($this->product['qty']) ? $this->product['qty'] : null;
     if ($this->recurringID) {
         $contract = new SJB_Contract(array('product_sid' => $this->product['sid'], 'recurring_id' => $this->recurringID, 'gateway_id' => $this->gatewayID, 'invoice_id' => $invoiceID, 'numberOfListings' => $listingNumber));
         $contractSID = SJB_ContractManager::getContractSIDByRecurringId($this->recurringID);
         SJB_ContractManager::deleteAllContractsByRecurringId($this->recurringID);
     } else {
         $contract = new SJB_Contract(array('product_sid' => $this->product['sid'], 'gateway_id' => $this->gatewayID, 'invoice_id' => $invoiceID, 'numberOfListings' => $listingNumber));
         if ($invoiceID) {
             SJB_ContractManager::deletePendingContractByInvoiceID($invoiceID, $userSID, $this->product['sid']);
         }
     }
     $contract->setUserSID($userSID);
     $contract->setPrice($this->product['amount']);
     $contract->setStatus($status);
     if ($contract->saveInDB()) {
         SJB_ShoppingCart::deleteItemFromCartBySID($this->product['shoppingCartRecord'], $userSID);
         $bannerInfo = $this->product['banner_info'];
         if ($this->product['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, $userSID, $contract->getID());
                 $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                 SJB_AdminNotifications::sendAdminBannerAddedLetter($userSID, $bannerGroup);
             }
         }
         if ($contract->isFeaturedProfile()) {
             SJB_UserManager::makeFeaturedBySID($userSID);
         }
         SJB_Statistics::addStatistics('payment', 'product', $this->product['sid'], false, 0, 0, $userSID, $this->product['amount']);
         if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($userSID)) {
             SJB_Notifications::sendSubscriptionActivationLetter($userSID, $this->product, $reactivation);
         }
     }
 }
예제 #8
0
 public function execute()
 {
     $template_processor = SJB_System::getTemplateProcessor();
     $ERRORS = array();
     $message_was_sent = false;
     if (!empty($_REQUEST['email'])) {
         $user_sid = SJB_UserManager::getUserSIDbyEmail($_REQUEST['email']);
         if (!empty($user_sid)) {
             $message_was_sent = SJB_Notifications::sendUserPasswordChangeLetter($user_sid);
         } else {
             $ERRORS['WRONG_EMAIL'] = 1;
         }
     }
     if (!$message_was_sent) {
         $email = SJB_Request::getVar('email', '');
         $template_processor->assign('errors', $ERRORS);
         $template_processor->assign('email', $email);
         $template_processor->display('password_recovery.tpl');
     } else {
         $template_processor->display('password_change_email_successfully_sent.tpl');
     }
 }
예제 #9
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $fatal_errors = array();
     $isDataSubmitted = false;
     try {
         $controller = new SJB_SendListingInfoController($_REQUEST);
     } catch (Exception $e) {
         $controller = false;
     }
     if (empty($controller)) {
         $fatal_errors['LISTING_ID_IS_NOT_NUMERIC'] = $e->getMessage();
     } elseif ($controller->isListingSpecified()) {
         if ($controller->isDataSubmitted()) {
             SJB_Captcha::getInstance($tp, $_REQUEST)->isValid($errors);
             if (!preg_match('^[a-zA-Z0-9\\._-]+@[a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,}$^', $_REQUEST['friend_email'])) {
                 $errors['NOT_VALID_EMAIL_FORMAT'] = true;
             }
             if (empty($errors)) {
                 $data_to_send = $controller->getData();
                 if (!SJB_Notifications::sendTellFriendLetter($data_to_send)) {
                     $errors['SEND_ERROR'] = true;
                 }
                 $isDataSubmitted = true;
             }
         }
         $tp->assign('listing_info', SJB_ListingManager::createTemplateStructureForListing(SJB_ListingManager::getObjectBySID($controller->getListingID())));
     } else {
         $fatal_errors['UNDEFINED_LISTING_ID'] = true;
     }
     $tp->assign('fatal_errors', $fatal_errors);
     $tp->assign('errors', $errors);
     $tp->assign('info', SJB_Request::get());
     $tp->assign('is_data_submitted', $isDataSubmitted);
     $tp->display('tell_friend.tpl');
 }
예제 #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');
     }
 }
예제 #11
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);
 }
예제 #12
0
    /**
     * Send private message
     *
     * @param integer $from
     * @param integer $to
     * @param string $subject
     * @param string $message
     * @param boolean $copy       Save copy in outbox
     * @param boolean $reply_id   if we reply to message with $reply_id, mark it as replied
     */
    public static function sendMessage($from, $to, $subject, $message, $copy = true, $reply_id = false, $cc = false, $anonym = 0)
    {
        $date = date('Y-m-d H:i:s');
        // to anonymous resume
        $anonym = $anonym ? $anonym : 0;
        $query = 'INSERT INTO `private_message` SET `from_id`=?n, `to_id`=?n, `data`=?s, `subject`=?s, `message`=?s, `anonym` = ?n';
        $mess_id = SJB_DB::query($query, $from, $to, $date, $subject, $message, $anonym);
        if ($mess_id) {
            if (SJB_UserNotificationsManager::isUserNotifiedOnNewPersonalMessage($to)) {
                $message_for_notification = SJB_PrivateMessage::readMessage($mess_id, true);
                SJB_Notifications::sendNewPrivateMessageLetter($to, $from, $message_for_notification, $cc);
            }
            if ($copy) {
                SJB_DB::query('INSERT INTO `private_message`
					SET `from_id`=?n, `to_id`=?n, `data`=?s, `subject`=?s, `message`=?s, `outbox`=1, `anonym` = ?n', $from, $to, $date, $subject, $message, $anonym);
            }
            if ($reply_id) {
                SJB_DB::query('UPDATE `private_message` SET `status`=?n WHERE id = ?n', PM_STATUS_REPLIED, $reply_id);
            }
        }
    }
예제 #13
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);
     }
 }
예제 #14
0
 function createSubscription($payment_data)
 {
     $validation_result = $this->validatePayment($payment_data);
     if ($validation_result !== true) {
         return $validation_result;
     }
     $properties = $this->details->getProperties();
     $api_login_id = $properties['authnet_api_login_id']->getValue();
     $transaction_key = $properties['authnet_api_transaction_key']->getValue();
     $use_test_account = $properties['authnet_use_test_account']->getValue();
     $invoice = SJB_InvoiceManager::getObjectBySID($payment_data['item_number']);
     if (empty($invoice)) {
         return;
     }
     $items = $invoice->getPropertyValue('items');
     $taxInfo = $invoice->getPropertyValue('tax_info');
     if (!empty($items['products'])) {
         foreach ($items['products'] as $key => $product) {
             if ($product != -1) {
                 $product_info = $invoice->getItemValue($key);
                 $payment_data['item_number'] = $invoice->getSID();
                 $payment_data['item_name'] = 'Payment for product ' . $product_info['name'];
                 $payment_data['x_description'] = 'Payment for product ' . $product_info['name'];
                 $payment_data['x_amount'] = $product_info['amount'];
                 if ($taxInfo && !$taxInfo['price_includes_tax']) {
                     $payment_data['x_amount'] += SJB_TaxesManager::getTaxAmount($payment_data['x_amount'], $taxInfo['tax_rate'], $taxInfo['price_includes_tax']);
                 }
                 $aimProcessor = new AuthnetAIMProcessor($api_login_id, $transaction_key, $use_test_account);
                 $aimProcessor->setTransactionType('AUTH_CAPTURE');
                 $aimProcessor->setParameter('x_login', $api_login_id);
                 $aimProcessor->setParameter('x_tran_key', $transaction_key);
                 $aimProcessor->setParameter('x_card_num', $payment_data['x_card_num']);
                 $aimProcessor->setParameter('x_amount', $payment_data['x_amount']);
                 $aimProcessor->setParameter('x_exp_date', $payment_data['x_exp_date']);
                 $aimProcessor->process();
                 if (!$aimProcessor->isApproved()) {
                     return array($aimProcessor->getResponseMessage());
                 }
                 $recurringID = null;
                 if (!empty($product_info['recurring'])) {
                     $product = new SJB_Product($product_info, $product_info['product_type']);
                     $expiration_period = $product->getExpirationPeriod();
                     $arbProcessor = new AuthnetARBProcessor($api_login_id, $transaction_key, $use_test_account);
                     $arbProcessor->setParameter('refID', $payment_data['item_number']);
                     $arbProcessor->setParameter('subscrName', $payment_data['x_description']);
                     $arbProcessor->setParameter('interval_length', $expiration_period);
                     $arbProcessor->setParameter('interval_unit', 'days');
                     $arbProcessor->setParameter('startDate', date("Y-m-d", strtotime("+ {$expiration_period} days")));
                     $arbProcessor->setParameter('totalOccurrences', 9999);
                     $arbProcessor->setParameter('trialOccurrences', 0);
                     $arbProcessor->setParameter('amount', $payment_data['x_amount']);
                     $arbProcessor->setParameter('trialAmount', 0.0);
                     $arbProcessor->setParameter('cardNumber', $payment_data['x_card_num']);
                     $arbProcessor->setParameter('expirationDate', $payment_data['x_exp_date']);
                     $arbProcessor->setParameter('orderInvoiceNumber', $payment_data['item_number']);
                     $arbProcessor->setParameter('orderDescription', $payment_data['x_description']);
                     $arbProcessor->setParameter('firstName', $payment_data['x_first_name']);
                     $arbProcessor->setParameter('lastName', $payment_data['x_last_name']);
                     $arbProcessor->setParameter('company', $payment_data['x_company']);
                     $arbProcessor->setParameter('address', $payment_data['x_address']);
                     $arbProcessor->setParameter('city', $payment_data['x_city']);
                     $arbProcessor->setParameter('state', $payment_data['x_state']);
                     $arbProcessor->setParameter('zip', $payment_data['x_zip']);
                     $arbProcessor->createAccount();
                     if (!$arbProcessor->isSuccessful()) {
                         return array($arbProcessor->getResponse());
                     }
                     $recurringID = $arbProcessor->getSubscriberID();
                 }
                 $user_sid = $invoice->getUserSID();
                 $listingNumber = $product_info['qty'];
                 $contract = new SJB_Contract(array('product_sid' => $product, 'recurring_id' => $recurringID, 'gateway_id' => 'authnet_sim', 'numberOfListings' => $listingNumber));
                 $contract->setUserSID($user_sid);
                 $contract->setPrice($product_info['amount']);
                 if ($contract->saveInDB()) {
                     SJB_ShoppingCart::deleteItemFromCartBySID($product_info['shoppingCartRecord'], $user_sid);
                     $bannerInfo = $product_info['banner_info'];
                     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, $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);
                     }
                     if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($user_sid)) {
                         SJB_Notifications::sendSubscriptionActivationLetter($user_sid, $product_info);
                     }
                 }
             }
         }
         $invoice->setCallbackData($payment_data);
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_PAID);
         SJB_InvoiceManager::saveInvoice($invoice);
         SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoice->getSID());
     }
     return true;
 }
예제 #15
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);
         }
     }
 }
예제 #16
0
 private function sendSearchedNotifications()
 {
     $savedSearches = SJB_SavedSearches::getAutoNotifySavedSearches();
     $listing = new SJB_Listing();
     $this->notifiedSavedSearchesSID = array();
     $notificationsLimit = (int) SJB_Settings::getSettingByName('num_of_listings_sent_in_email_alerts');
     foreach ($savedSearches as $savedSearch) {
         $searcher = new SJB_ListingSearcher();
         $listing->addActivationDateProperty();
         $dataSearch = unserialize($savedSearch['data']);
         $dataSearch['active']['equal'] = 1;
         $dateArray = explode('-', $savedSearch['last_send']);
         $savedSearch['last_send'] = strftime($this->lang['date_format'], mktime(0, 0, 0, $dateArray[1], $dateArray[2], $dateArray[0]));
         $dataSearch['activation_date']['not_less'] = $savedSearch['last_send'];
         $dataSearch['activation_date']['not_more'] = $this->currentDate;
         $listingTypeSID = 0;
         if ($dataSearch['listing_type']['equal']) {
             $listingTypeID = $dataSearch['listing_type']['equal'];
             $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
             if (SJB_ListingTypeManager::getWaitApproveSettingByListingType($listingTypeSID)) {
                 $dataSearch['status']['equal'] = 'approved';
             }
         }
         $idAliasInfo = $listing->addIDProperty();
         $usernameAliasInfo = $listing->addUsernameProperty();
         $listingTypeIDInfo = $listing->addListingTypeIDProperty();
         $aliases = new SJB_PropertyAliases();
         $aliases->addAlias($idAliasInfo);
         $aliases->addAlias($usernameAliasInfo);
         $aliases->addAlias($listingTypeIDInfo);
         $dataSearch['access_type'] = array('accessible' => $savedSearch['user_sid']);
         $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData($dataSearch, $listing);
         $searcher->found_object_sids = array();
         $searcher->setLimit($notificationsLimit);
         $foundListingsIDs = $searcher->getObjectsSIDsByCriteria($criteria, $aliases);
         if (count($foundListingsIDs)) {
             $savedSearch['activation_date'] = $savedSearch['last_send'];
             if (SJB_Notifications::sendUserNewListingsFoundLetter($foundListingsIDs, $savedSearch['user_sid'], $savedSearch, $listingTypeSID)) {
                 SJB_Statistics::addStatistics('sentAlert', $listingTypeSID, $savedSearch['sid']);
                 SJB_DB::query('UPDATE `saved_searches` SET `last_send` = CURDATE() WHERE `sid` = ?n', $savedSearch['sid']);
             }
             $this->notifiedSavedSearchesSID[] = $savedSearch['sid'];
         }
     }
 }
예제 #17
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $template = 'edit_invoice.tpl';
     $errors = array();
     $invoiceErrors = array();
     $invoiceSID = SJB_Request::getVar('sid', false);
     $action = SJB_Request::getVar('action', false);
     $tcpdfError = SJB_Request::getVar('error', false);
     if ($tcpdfError) {
         $invoiceErrors[] = $tcpdfError;
     }
     $invoiceInfo = SJB_InvoiceManager::getInvoiceInfoBySID($invoiceSID);
     $user_structure = null;
     if ($invoiceInfo) {
         $product_info = array();
         if (array_key_exists('custom_info', $invoiceInfo['items'])) {
             $product_info = $invoiceInfo['items']['custom_info'];
         }
         $invoiceInfo = array_merge($invoiceInfo, $_REQUEST);
         $invoiceInfo['items']['custom_info'] = $product_info;
         $includeTax = $invoiceInfo['include_tax'];
         $invoice = new SJB_Invoice($invoiceInfo);
         $invoice->setSID($invoiceSID);
         $userSID = $invoice->getPropertyValue('user_sid');
         $userExists = SJB_UserManager::isUserExistsByUserSid($userSID);
         $subUserSID = $invoice->getPropertyValue('subuser_sid');
         if (!empty($subUserSID)) {
             $userInfo = SJB_UserManager::getUserInfoBySID($subUserSID);
             $username = $userInfo['username'] . '/' . $userInfo['email'];
         } else {
             $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
             $username = $userInfo['FirstName'] . ' ' . $userInfo['LastName'] . ' ' . $userInfo['ContactName'] . ' ' . $userInfo['CompanyName'] . '/' . $userInfo['email'];
         }
         $taxInfo = $invoice->getPropertyValue('tax_info');
         $productsSIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($userInfo['user_group_sid']);
         $products = array();
         foreach ($productsSIDs as $key => $productSID) {
             $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
             if (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') {
                 $volumeBasedPricing = $productInfo['volume_based_pricing'];
                 $minListings = min($volumeBasedPricing['listings_range_from']);
                 $maxListings = max($volumeBasedPricing['listings_range_to']);
                 $countListings = array();
                 for ($i = $minListings; $i <= $maxListings; $i++) {
                     $countListings[$i]['number_of_listings'] = $i;
                     for ($j = 1; $j <= count($volumeBasedPricing['listings_range_from']); $j++) {
                         if ($i >= $volumeBasedPricing['listings_range_from'][$j] && $i <= $volumeBasedPricing['listings_range_to'][$j]) {
                             $countListings[$i]['price'] = $volumeBasedPricing['price_per_unit'][$j];
                         }
                     }
                 }
                 $productInfo['count_listings'] = $countListings;
             }
             $products[$key] = $productInfo;
         }
         $addForm = new SJB_Form($invoice);
         $addForm->registerTags($tp);
         $tp->assign('userExists', $userExists);
         $tp->assign('products', $products);
         $tp->assign('invoice_sid', $invoiceSID);
         $tp->assign('include_tax', $includeTax);
         $tp->assign('username', trim($username));
         if ($action) {
             switch ($action) {
                 case 'save':
                 case 'apply':
                     $invoiceErrors = $invoice->isValid();
                     if (empty($invoiceErrors) && $addForm->isDataValid($errors)) {
                         $invoice->setFloatNumbersIntoValidFormat();
                         SJB_InvoiceManager::saveInvoice($invoice);
                         if ($action == 'save') {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/manage-invoices/');
                         }
                     } else {
                         $invoiceDate = SJB_I18N::getInstance()->getInput('date', $invoice->getPropertyValue('date'));
                         $invoice->setPropertyValue('date', $invoiceDate);
                     }
                     $invoice->setFloatNumbersIntoValidFormat();
                     $taxInfo['tax_amount'] = SJB_I18N::getInstance()->getInput('float', $taxInfo['tax_amount']);
                     break;
                 case 'print':
                 case 'download_pdf_version':
                     $user = SJB_UserManager::getObjectBySID($userSID);
                     $user_structure = SJB_UserManager::createTemplateStructureForUser($user);
                     $template = 'print_invoice.tpl';
                     $username = SJB_Array::get($user_structure, 'CompanyName') . ' ' . SJB_Array::get($user_structure, 'FirstName') . ' ' . SJB_Array::get($user_structure, 'LastName');
                     $tp->assign('username', trim($username));
                     $tp->assign('user', $user_structure);
                     $tp->assign('tax', $taxInfo);
                     if ($action == 'download_pdf_version') {
                         $template = 'invoice_to_pdf.tpl';
                         $filename = 'invoice_' . $invoiceSID . '.pdf';
                         try {
                             SJB_HelperFunctions::html2pdf($tp->fetch($template), $filename);
                             exit;
                         } catch (Exception $e) {
                             SJB_Error::writeToLog($e->getMessage());
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/edit-invoice/?sid=' . $invoiceSID . '&error=TCPDF_ERROR');
                         }
                     }
                     break;
                 case 'send_invoice':
                     $result = SJB_Notifications::sendInvoiceToCustomer($invoiceSID, $userSID);
                     if ($result) {
                         echo SJB_I18N::getInstance()->gettext("Backend", "Invoice successfully sent");
                     } else {
                         echo SJB_I18N::getInstance()->gettext("Backend", "Invoice not sent");
                     }
                     exit;
                     break;
             }
         }
         $transactions = SJB_TransactionManager::getTransactionsByInvoice($invoiceSID);
         $tp->assign('tax', $taxInfo);
         $tp->assign('transactions', $transactions);
     } else {
         $tp->assign('action', 'edit');
         $errors[] = 'WRONG_INVOICE_ID_SPECIFIED';
         $template = 'errors.tpl';
     }
     $tp->assign("errors", array_merge($errors, $invoiceErrors));
     $tp->display($template);
 }
예제 #18
0
 public function execute()
 {
     $restore = 'restore=';
     if (isset($_REQUEST['action_name'], $_REQUEST['listings'])) {
         $listings_ids = $_REQUEST['listings'];
         switch (strtolower($_REQUEST['action_name'])) {
             case 'activate':
                 $activatedListings = array();
                 foreach ($listings_ids as $listingId => $value) {
                     if (SJB_ListingManager::activateListingBySID($listingId, false)) {
                         $activatedListings[] = $listingId;
                     }
                     $listing = SJB_ListingManager::getObjectBySID($listingId);
                     if (SJB_UserNotificationsManager::isUserNotifiedOnListingActivation($listing->getUserSID())) {
                         SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID());
                     }
                 }
                 SJB_BrowseDBManager::addListings($activatedListings);
                 break;
             case 'deactivate':
                 $this->executeAction($listings_ids, 'deactivate');
                 break;
             case 'delete':
                 $this->executeAction($listings_ids, 'delete');
                 break;
             case 'datemodify':
                 if (isset($_REQUEST['date_to_change'])) {
                     $dateToUpdate = $_REQUEST['date_to_change'];
                     $date = SJB_I18N::getInstance()->getInput('date', $dateToUpdate);
                     foreach ($listings_ids as $listing_id => $value) {
                         $listingInfo = SJB_ListingManager::getListingInfoBySID($listing_id);
                         $result = SJB_DB::query('UPDATE `listings` SET `expiration_date` = ?s WHERE `sid` = ?n', $date, $listingInfo['sid']);
                     }
                 }
                 break;
             case 'approve':
                 $this->executeAction($listings_ids, 'approve');
                 foreach ($listings_ids as $listing_id => $value) {
                     $user_sid = SJB_ListingManager::getUserSIDByListingSID($listing_id);
                     if (SJB_UserNotificationsManager::isUserNotifiedOnListingApprove($user_sid)) {
                         SJB_Notifications::sendUserListingApproveOrRejectLetter($listing_id, $user_sid, 'approve');
                     }
                 }
                 break;
             case 'reject':
                 $this->executeAction($listings_ids, 'reject');
                 foreach ($listings_ids as $listing_id => $value) {
                     $user_sid = SJB_ListingManager::getUserSIDByListingSID($listing_id);
                     if (SJB_UserNotificationsManager::isUserNotifiedOnListingReject($user_sid)) {
                         SJB_Notifications::sendUserListingApproveOrRejectLetter($listing_id, $user_sid, 'reject');
                     }
                 }
                 break;
             default:
                 $restore = '';
                 break;
         }
     }
     $listingTypeId = SJB_Request::getVar('listingTypeId', null);
     $listingType = $listingTypeId != 'Job' && $listingTypeId != 'Resume' ? $listingTypeId . '-listings' : $listingTypeId . 's';
     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-' . strtolower($listingType) . '/?action=search&' . $restore);
 }
예제 #19
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $template = SJB_Request::getVar('input_template', 'input_form.tpl');
     $error = null;
     $listingTypeID = SJB_Request::getVar('listing_type_id', false);
     $passed_parameters_via_uri = SJB_Request::getVar('passed_parameters_via_uri', false);
     $pageID = false;
     if ($passed_parameters_via_uri) {
         $passed_parameters_via_uri = SJB_UrlParamProvider::getParams();
         $listingTypeID = isset($passed_parameters_via_uri[0]) ? $passed_parameters_via_uri[0] : $listingTypeID;
         $pageID = isset($passed_parameters_via_uri[1]) ? $passed_parameters_via_uri[1] : false;
         $listing_id = isset($passed_parameters_via_uri[2]) ? $passed_parameters_via_uri[2] : false;
     }
     if (SJB_UserManager::isUserLoggedIn()) {
         $post_max_size_orig = ini_get('post_max_size');
         $server_content_length = isset($_SERVER['CONTENT_LENGTH']) ? $_SERVER['CONTENT_LENGTH'] : null;
         $fromPreview = SJB_Request::getVar('from-preview', false);
         // get post_max_size in bytes
         $val = trim($post_max_size_orig);
         $tmp = substr($val, strlen($val) - 1);
         $tmp = strtolower($tmp);
         /* if ini value is K - then multiply to 1024
          * if ini value is M - then multiply twice: in case 'm', and case 'k'
          * if ini value is G - then multiply tree times: in 'g', 'm', 'k'
          * out value - in bytes!
          */
         switch ($tmp) {
             case 'g':
                 $val *= 1024;
             case 'm':
                 $val *= 1024;
             case 'k':
                 $val *= 1024;
         }
         $post_max_size = $val;
         $filename = SJB_Request::getVar('filename', false);
         if ($filename) {
             $file = SJB_UploadFileManager::openFile($filename, $listing_id);
             $errors['NO_SUCH_FILE'] = true;
         }
         if (empty($_POST) && $server_content_length > $post_max_size) {
             $errors['MAX_FILE_SIZE_EXCEEDED'] = 1;
             $tp->assign('post_max_size', $post_max_size_orig);
         }
         $listingInfo = SJB_ListingManager::getListingInfoBySID($listing_id);
         $currentUser = SJB_UserManager::getCurrentUser();
         $contractID = $listingInfo['contract_id'];
         if ($contractID == 0) {
             $extraInfo = unserialize($listingInfo['product_info']);
             $productSID = $extraInfo['product_sid'];
         } else {
             $contract = new SJB_Contract(array('contract_id' => $contractID));
             $extraInfo = $contract->extra_info;
         }
         if ($listingInfo['user_sid'] != SJB_UserManager::getCurrentUserSID()) {
             $errors['NOT_OWNER_OF_LISTING'] = $listing_id;
         } else {
             $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
             $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listing_type_sid);
             if (!$pageID) {
                 $pageID = $pages[0]['page_id'];
             }
             $pageSID = SJB_PostingPagesManager::getPostingPageSIDByID($pageID, $listing_type_sid);
             $isPageLast = SJB_PostingPagesManager::isLastPageByID($pageSID, $listing_type_sid);
             // preview listing
             $isPreviewListingRequested = SJB_Request::getVar('preview_listing', false, 'POST');
             $form_submitted = isset($_REQUEST['action_add']) || isset($_REQUEST['action_add_pictures']) || $isPreviewListingRequested;
             // fill listing from an array of social data if allowed
             $aAutoFillData = array('formSubmitted' => &$form_submitted, 'listingTypeID' => &$listingTypeID);
             SJB_Event::dispatch('SocialSynchronization', $aAutoFillData);
             $listingInfo = array_merge($listingInfo, $_REQUEST);
             $listing = new SJB_Listing($listingInfo, $listing_type_sid, $pageSID);
             if ($fromPreview) {
                 if ($form_submitted) {
                     $properties = $listing->getProperties();
                     foreach ($properties as $fieldID => $property) {
                         switch ($property->getType()) {
                             case 'date':
                                 if (!empty($listing_info[$fieldID])) {
                                     $listingInfo[$fieldID] = SJB_I18N::getInstance()->getDate($listingInfo[$fieldID]);
                                 }
                                 break;
                             case 'complex':
                                 $complex = $property->type->complex;
                                 $complexProperties = $complex->getProperties();
                                 foreach ($complexProperties as $complexfieldID => $complexProperty) {
                                     if ($complexProperty->getType() == 'date') {
                                         $values = $complexProperty->getValue();
                                         foreach ($values as $index => $value) {
                                             if (!empty($listingInfo[$fieldID][$complexfieldID][$index])) {
                                                 $listingInfo[$fieldID][$complexfieldID][$index] = SJB_I18N::getInstance()->getDate($listingInfo[$fieldID][$complexfieldID][$index]);
                                             }
                                         }
                                     }
                                 }
                                 break;
                         }
                     }
                     $listing = new SJB_Listing($listingInfo, $listing_type_sid, $pageSID);
                 }
             }
             $previousComplexFields = $this->processComplexFields($listing, $listingInfo);
             $listing->deleteProperty('featured');
             $listing->deleteProperty('priority');
             $listing->deleteProperty('status');
             $listing->deleteProperty('reject_reason');
             $listing->deleteProperty('ListingLogo');
             $listing->setSID($listing_id);
             $access_type = $listing->getProperty('access_type');
             if ($form_submitted && !empty($access_type)) {
                 $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar('list_emp_ids'), 'is_system' => true));
             }
             $screening_questionnaires = SJB_ScreeningQuestionnaires::getList($currentUser->getSID());
             if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) {
                 $issetQuestionnairyField = $listing->getProperty('screening_questionnaire');
                 if ($issetQuestionnairyField) {
                     $value = SJB_Request::getVar('screening_questionnaire');
                     $value = $value ? $value : isset($listingInfo['screening_questionnaire']) ? $listingInfo['screening_questionnaire'] : '';
                     $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($currentUser->getSID()), 'is_system' => true));
                 }
             } else {
                 $listing->deleteProperty('screening_questionnaire');
             }
             /* social plugin
              * "synchronization"
              * if user is not registered using linkedin , delete linkedin sync property
              * also deletes it if sync is turned off in admin part
              */
             if ($pages[0]['page_id'] == $pageID) {
                 $aAutoFillData = array('oListing' => &$listing, 'userSID' => $currentUser->getSID(), 'listingTypeID' => $listingTypeID, 'listing_info' => $listingInfo);
                 SJB_Event::dispatch('SocialSynchronizationFields', $aAutoFillData);
             }
             $add_listing_form = new SJB_Form($listing);
             $add_listing_form->registerTags($tp);
             $field_errors = array();
             if ($form_submitted && (SJB_Session::getValue(self::PREVIEW_LISTING_SID) == $listing_id || $add_listing_form->isDataValid($field_errors))) {
                 /* delete temp preview listing sid */
                 SJB_Session::unsetValue(self::PREVIEW_LISTING_SID);
                 if ($isPageLast) {
                     $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 }
                 $listing->setUserSID($currentUser->getSID());
                 if (empty($access_type->value)) {
                     $listing->setPropertyValue('access_type', 'everyone');
                 }
                 if (isset($_SESSION['tmp_file_storage'])) {
                     foreach ($_SESSION['tmp_file_storage'] as $k => $v) {
                         SJB_DB::query('UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `picture_saved_name` = ?s', $listing->getSID(), $v['picture_saved_name']);
                         SJB_DB::query('UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `thumb_saved_name` = ?s', $listing->getSID(), $v['thumb_saved_name']);
                     }
                     SJB_Session::unsetValue('tmp_file_storage');
                 }
                 // >>> SJB-1197
                 // check temporary uploaded storage for listing uploads and assign it to saved listing
                 $formToken = SJB_Request::getVar('form_token');
                 $sessionFilesStorage = SJB_Session::getValue('tmp_uploads_storage');
                 $uploadedFields = SJB_Array::getPath($sessionFilesStorage, $formToken);
                 if (!empty($uploadedFields)) {
                     foreach ($uploadedFields as $fieldId => $fieldValue) {
                         // get field of listing
                         $isComplex = false;
                         if (strpos($fieldId, ':') !== false) {
                             $isComplex = true;
                         }
                         $tmpUploadedFileId = $fieldValue['file_id'];
                         // rename it to real listing field value
                         $newFileId = $fieldId . "_" . $listing->getSID();
                         SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                         if ($isComplex) {
                             list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                             $parentProp = $listing->getProperty($parentField);
                             $parentValue = $parentProp->getValue();
                             // look for complex property with current $fieldID and set it to new value of property
                             if (!empty($parentValue)) {
                                 foreach ($parentValue as $id => $value) {
                                     if ($id == $subField) {
                                         $parentValue[$id][$complexStep] = $newFileId;
                                     }
                                 }
                                 $listing->setPropertyValue($parentField, $parentValue);
                             }
                         } else {
                             $listing->setPropertyValue($fieldId, $newFileId);
                         }
                         // unset value from session temporary storage
                         $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}/{$fieldId}");
                     }
                     //and remove token key from temporary storage
                     $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}");
                     SJB_Session::setValue('tmp_uploads_storage', $sessionFilesStorage);
                 }
                 // <<< SJB-1197
                 SJB_ListingManager::saveListing($listing);
                 foreach ($previousComplexFields as $propertyId) {
                     $listing->deleteProperty($propertyId);
                 }
                 if ($isPageLast && !$isPreviewListingRequested) {
                     $listingSID = $listing->getSID();
                     $listing = SJB_ListingManager::getObjectBySID($listingSID);
                     $listing->setSID($listingSID);
                     $keywords = $listing->getKeywords();
                     SJB_ListingManager::updateKeywords($keywords, $listing->getSID());
                     // Start Event
                     $listingSid = $listing->getSID();
                     SJB_Event::dispatch('listingSaved', $listingSid);
                     // is listing featured by default
                     if ($extraInfo['featured']) {
                         SJB_ListingManager::makeFeaturedBySID($listing->getSID());
                     }
                     if ($extraInfo['priority']) {
                         SJB_ListingManager::makePriorityBySID($listing->getSID());
                     }
                     if ($contractID) {
                         if (SJB_ListingManager::activateListingBySID($listing->getSID())) {
                             SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID());
                         }
                         // notify administrator
                         SJB_AdminNotifications::sendAdminListingAddedLetter($listing);
                         if (isset($_REQUEST['action_add_pictures'])) {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-pictures/?listing_id=" . $listing->getSID());
                         } else {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-' . strtolower($listingTypeID) . '/?listing_id=' . $listing->getSID());
                         }
                     } else {
                         SJB_ListingManager::unmakeCheckoutedBySID($listing->getSID());
                         $this->proceedToCheckout($currentUser->getSID(), $productSID);
                     }
                 } elseif ($isPageLast && $isPreviewListingRequested) {
                     // for listing preview
                     SJB_Session::setValue(self::PREVIEW_LISTING_SID, $listing->getSID());
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/' . strtolower($listingTypeID) . '-preview/' . $listing->getSID() . '/');
                 } else {
                     // listing steps (pages)
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/add-listing/{$listingTypeID}/" . SJB_PostingPagesManager::getNextPage($pageSID) . '/' . $listing->getSID());
                 }
             } else {
                 foreach ($previousComplexFields as $propertyId) {
                     $listing->deleteProperty($propertyId);
                 }
                 $listing->deleteProperty('access_list');
                 $listing->deleteProperty('contract_id');
                 $add_listing_form = new SJB_Form($listing);
                 if (SJB_Request::get('action_add') == 'Next') {
                     $add_listing_form->setUseDefaultValues();
                 }
                 if ($form_submitted) {
                     $add_listing_form->isDataValid($field_errors);
                 }
                 $add_listing_form->registerTags($tp);
                 $form_fields = $add_listing_form->getFormFieldsInfo();
                 $employers_list = SJB_Request::getVar('list_emp_ids', false);
                 $employers = array();
                 if (is_array($employers_list)) {
                     foreach ($employers_list as $emp) {
                         $currEmp = SJB_UserManager::getUserInfoBySID($emp);
                         $employers[] = array('user_id' => $emp, 'value' => $currEmp['CompanyName']);
                     }
                     sort($employers);
                 } else {
                     $access_type = $listing->getPropertyValue('access_type');
                     $employers = SJB_ListingManager::getListingAccessList($listing_id, $access_type);
                 }
                 $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
                 $tp->assign('pic_limit', $numberOfPictures);
                 $tp->assign('listing_sid', $listing_id);
                 $tp->assign('listing_id', $listing_id);
                 $tp->assign('listingSID', $listing->getSID());
                 $tp->assign('listing_access_list', $employers);
                 $tp->assign('listingTypeID', $listingTypeID);
                 $tp->assign('contract_id', $contractID);
                 $tp->assign('field_errors', $field_errors);
                 $tp->assign('form_fields', $form_fields);
                 $tp->assign("extraInfo", $extraInfo);
                 $tp->assign('pages', $pages);
                 $tp->assign('pageSID', $pageSID);
                 $tp->assign('currentPage', SJB_PostingPagesManager::getPageInfoBySID($pageSID));
                 $tp->assign('isPageLast', $isPageLast);
                 $tp->assign('nextPage', SJB_PostingPagesManager::getNextPage($pageSID));
                 $tp->assign('prevPage', SJB_PostingPagesManager::getPrevPage($pageSID));
                 $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
                 $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
                 // social plugin  only for Resume listing types
                 $aAutoFillData = array('tp' => &$tp, 'listingTypeID' => $listingTypeID, 'userSID' => $currentUser->getSID());
                 SJB_Event::dispatch('SocialSynchronizationForm', $aAutoFillData);
                 SJB_Session::unsetValue(self::PREVIEW_LISTING_SID);
                 $tp->display($template);
             }
         }
     } else {
         $tp->assign('listingTypeID', $listingTypeID);
         $tp->assign('error', 'NOT_LOGGED_IN');
         $tp->display('add_listing_error.tpl');
     }
 }
예제 #20
0
 public function execute()
 {
     if (!function_exists('_filter_data')) {
         function _filter_data(&$array, $key, $pattern)
         {
             if (isset($array[$key])) {
                 if (!preg_match($pattern, $array[$key])) {
                     unset($array[$key]);
                 }
             }
         }
     }
     _filter_data($_REQUEST, 'sorting_field', "/^[_\\w\\d]+\$/");
     _filter_data($_REQUEST, 'sorting_order', "/(^DESC\$)|(^ASC\$)/i");
     _filter_data($_REQUEST, 'default_sorting_field', "/^[_\\w\\d]+\$/");
     _filter_data($_REQUEST, 'default_sorting_order', "/(^DESC\$)|(^ASC\$)/i");
     $tp = SJB_System::getTemplateProcessor();
     if (!SJB_UserManager::isUserLoggedIn()) {
         $errors['NOT_LOGGED_IN'] = true;
         $tp->assign("ERRORS", $errors);
         $tp->display("error.tpl");
         return;
     }
     $this->defineRequestedListingTypeID();
     if (!$this->listingTypeID) {
         $tp->assign('listingTypes', SJB_ListingTypeManager::getAllListingTypesInfo());
         $tp->display('my_available_listing_types.tpl');
         return;
     }
     $this->listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($this->listingTypeID);
     if (!$this->listingTypeSID) {
         SJB_HelperFunctions::redirect(SJB_HelperFunctions::getSiteUrl() . '/my-listings/');
         return;
     }
     $currentUser = SJB_UserManager::getCurrentUser();
     $userSID = $currentUser->getSID();
     $this->requestCriteria = array('user_sid' => array('equal' => $userSID), 'listing_type_sid' => array('equal' => $this->listingTypeSID));
     $acl = SJB_Acl::getInstance();
     if ($currentUser->isSubuser()) {
         $subUserInfo = $currentUser->getSubuserInfo();
         if (!$acl->isAllowed('subuser_manage_listings', $subUserInfo['sid'])) {
             $this->requestCriteria['subuser_sid'] = array('equal' => $subUserInfo['sid']);
         }
     }
     SJB_ListingManager::deletePreviewListingsByUserSID($userSID);
     $searcher = new SJB_ListingSearcher();
     // to save criteria in the session different from search_results
     $criteriaSaver = new SJB_ListingCriteriaSaver('MyListings');
     if (isset($_REQUEST['restore'])) {
         $_REQUEST = array_merge($_REQUEST, $criteriaSaver->getCriteria());
     }
     if (isset($_REQUEST['listings'])) {
         $listingsSIDs = $_REQUEST['listings'];
         if (isset($_REQUEST['action_deactivate'])) {
             $this->executeAction($listingsSIDs, 'deactivate');
         } elseif (isset($_REQUEST['action_activate'])) {
             $redirectToShoppingCard = false;
             $activatedListings = array();
             foreach ($listingsSIDs as $listingSID => $value) {
                 $listingInfo = SJB_ListingManager::getListingInfoBySID($listingSID);
                 $productInfo = !empty($listingInfo['product_info']) ? unserialize($listingInfo['product_info']) : array();
                 if ($listingInfo['active']) {
                     continue;
                 } else {
                     if (SJB_ListingManager::getIfListingHasExpiredBySID($listingSID) && isset($productInfo['renewal_price']) && $productInfo['renewal_price'] > 0) {
                         $redirectToShoppingCard = true;
                         $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listingInfo['listing_type_sid']);
                         $newProductName = "Reactivation of \"{$listingInfo['Title']}\" {$listingTypeId}";
                         $newProductInfo = SJB_ShoppingCart::createInfoForCustomProduct($userSID, $productInfo['product_sid'], $listingSID, $productInfo['renewal_price'], $newProductName, 'activateListing');
                         SJB_ShoppingCart::createCustomProduct($newProductInfo, $userSID);
                     } else {
                         if ($listingInfo['checkouted'] == 0) {
                             $redirectToShoppingCard = true;
                         } else {
                             if (SJB_ListingManager::activateListingBySID($listingSID, false)) {
                                 $listing = SJB_ListingManager::getObjectBySID($listingSID);
                                 SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID());
                                 $activatedListings[] = $listingSID;
                             }
                         }
                     }
                 }
             }
             SJB_BrowseDBManager::addListings($activatedListings);
             if ($redirectToShoppingCard) {
                 $shoppingUrl = SJB_System::getSystemSettings('SITE_URL') . '/shopping-cart/';
                 SJB_HelperFunctions::redirect($shoppingUrl);
             }
         } else {
             if (isset($_REQUEST['action_delete'])) {
                 $this->executeAction($listingsSIDs, 'delete');
                 $allowedPostBeforeCheckout = SJB_Settings::getSettingByName('allow_to_post_before_checkout');
                 foreach ($listingsSIDs as $listingSID => $value) {
                     if ($allowedPostBeforeCheckout == true) {
                         $this->deleteCheckoutedListingFromShopCart($listingSID, $userSID);
                     }
                 }
             } elseif (isset($_REQUEST['action_sendToApprove'])) {
                 $processListingsIds = array();
                 foreach ($listingsSIDs as $listingSID => $value) {
                     $processListingsIds[] = $listingSID;
                 }
                 SJB_ListingManager::setListingApprovalStatus($processListingsIds, 'pending');
             }
         }
         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/my-listings/{$this->listingTypeID}/");
     }
     $listing = new SJB_Listing(array(), $this->listingTypeSID);
     $idAliasInfo = $listing->addIDProperty();
     $listing->addActivationDateProperty();
     $listing->addKeywordsProperty();
     $listing->addPicturesProperty();
     $listingTypeIdAliasInfo = $listing->addListingTypeIDProperty();
     $sortingFields = array();
     $innerJoin = array();
     $sortingField = SJB_Request::getVar("sorting_field", null);
     $sortingOrder = SJB_Request::getVar("sorting_order", null);
     if (isset($sortingField, $sortingOrder)) {
         $orderInfo = array('sorting_field' => $sortingField, 'sorting_order' => $sortingOrder);
     } else {
         $orderInfo = $criteriaSaver->getOrderInfo();
     }
     if ($orderInfo['sorting_field'] == 'applications') {
         $innerJoin['applications'] = array('count' => 'count(`applications`.id) as appCount', 'join' => 'LEFT JOIN', 'join_field' => 'listing_id', 'join_field2' => 'sid', 'main_table' => 'listings');
         $sortingFields['appCount'] = $orderInfo['sorting_order'];
         $searcher->setGroupByField(array('listings' => 'sid'));
     } else {
         if ($orderInfo['sorting_field'] == 'id') {
             $sortingFields['sid'] = $orderInfo['sorting_order'];
         } else {
             if ($orderInfo['sorting_field'] == 'subuser_sid') {
                 $innerJoin['users'] = array('join' => 'LEFT JOIN', 'join_field' => 'sid', 'join_field2' => 'subuser_sid', 'main_table' => 'listings');
                 $sortingFields['username'] = $orderInfo['sorting_order'];
             } else {
                 $property = $listing->getProperty($sortingField);
                 if (!empty($property) && $property->isSystem()) {
                     $sortingFields[$orderInfo['sorting_field']] = $orderInfo['sorting_order'];
                 } else {
                     $sortingFields['activation_date'] = 'DESC';
                 }
             }
         }
     }
     $this->requestCriteria['sorting_field'] = $orderInfo['sorting_field'];
     $this->requestCriteria['sorting_order'] = $orderInfo['sorting_order'];
     $criteria = SJB_SearchFormBuilder::extractCriteriaFromRequestData(array_merge($_REQUEST, $this->requestCriteria), $listing);
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias($idAliasInfo);
     $aliases->addAlias($listingTypeIdAliasInfo);
     $foundListingsSIDs = $searcher->getObjectsSIDsByCriteria($criteria, $aliases, $sortingFields, $innerJoin);
     $searchFormBuilder = new SJB_SearchFormBuilder($listing);
     $searchFormBuilder->registerTags($tp);
     $searchFormBuilder->setCriteria($criteria);
     // получим информацию о имеющихся листингах
     $listingsInfo = array();
     $currentUserInfo = SJB_UserManager::getCurrentUserInfo();
     $contractInfo['extra_info']['listing_amount'] = 0;
     if ($acl->isAllowed('post_' . $this->listingTypeID)) {
         $permissionParam = $acl->getPermissionParams('post_' . $this->listingTypeID);
         if (empty($permissionParam)) {
             $contractInfo['extra_info']['listing_amount'] = 'unlimited';
         } else {
             $contractInfo['extra_info']['listing_amount'] = $permissionParam;
         }
     }
     $currentUser = SJB_UserManager::getCurrentUser();
     $contractsSIDs = $currentUser->getContractID();
     $listingsInfo['listingsNum'] = SJB_ContractManager::getListingsNumberByContractSIDsListingType($contractsSIDs, $this->listingTypeID);
     $listingsInfo['listingsMax'] = $contractInfo['extra_info']['listing_amount'];
     if ($listingsInfo['listingsMax'] === 'unlimited') {
         $listingsInfo['listingsLeft'] = 'unlimited';
     } else {
         $listingsInfo['listingsLeft'] = $listingsInfo['listingsMax'] - $listingsInfo['listingsNum'];
         $listingsInfo['listingsLeft'] = $listingsInfo['listingsLeft'] < 0 ? 0 : $listingsInfo['listingsLeft'];
     }
     $tp->assign('listingTypeID', $this->listingTypeID);
     $tp->assign('listingTypeName', SJB_ListingTypeManager::getListingTypeNameBySID($this->listingTypeSID));
     $tp->assign('listingsInfo', $listingsInfo);
     $tp->display('my_listings_form.tpl');
     $page = SJB_Request::getVar('page', 1);
     $listingsPerPage = $criteriaSaver->getListingsPerPage();
     //save 'listings per page' in the session
     if (empty($listingsPerPage)) {
         $listingsPerPage = 10;
     }
     $listingsPerPage = SJB_Request::getVar('listings_per_page', $listingsPerPage);
     $criteriaSaver->setSessionForListingsPerPage($listingsPerPage);
     $criteriaSaver->setSessionForCurrentPage($page);
     $criteriaSaver->setSessionForCriteria($_REQUEST);
     $criteriaSaver->setSessionForOrderInfo($orderInfo);
     $criteriaSaver->setSessionForObjectSIDs($foundListingsSIDs);
     // get Applications
     $appsGroups = SJB_Applications::getAppGroupsByEmployer($currentUserInfo['sid']);
     $apps = array();
     foreach ($appsGroups as $group) {
         $apps[$group['listing_id']] = $group['count'];
     }
     $searchCriteriaStructure = $criteriaSaver->createTemplateStructureForCriteria();
     $listingSearchStructure = $criteriaSaver->createTemplateStructureForSearch();
     /**************** P A G I N G *****************/
     if ($listingSearchStructure['current_page'] > $listingSearchStructure['pages_number']) {
         $listingSearchStructure['current_page'] = $listingSearchStructure['pages_number'];
     }
     if ($listingSearchStructure['current_page'] < 1) {
         $listingSearchStructure['current_page'] = 1;
     }
     $sortedFoundListingsSIDsByPages = array_chunk($foundListingsSIDs, $listingSearchStructure['listings_per_page'], true);
     /************* S T R U C T U R E **************/
     $listingsStructure = array();
     $listingStructureMetaData = array();
     if (isset($sortedFoundListingsSIDsByPages[$listingSearchStructure['current_page'] - 1])) {
         foreach ($sortedFoundListingsSIDsByPages[$listingSearchStructure['current_page'] - 1] as $sid) {
             $listing = SJB_ListingManager::getObjectBySID($sid);
             $listing->addPicturesProperty();
             $listingStructure = SJB_ListingManager::createTemplateStructureForListing($listing);
             $listingsStructure[$listing->getID()] = $listingStructure;
             if (isset($listingStructure['METADATA'])) {
                 $listingStructureMetaData = array_merge($listingStructureMetaData, $listingStructure['METADATA']);
             }
         }
     }
     /*************** D I S P L A Y ****************/
     $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
     $metadata = array();
     $metadata['listing'] = $metaDataProvider->getMetaData($listingStructureMetaData);
     $waitApprove = SJB_ListingTypeManager::getWaitApproveSettingByListingType($this->listingTypeSID);
     $tp->assign('show_rates', SJB_Settings::getSettingByName('show_rates'));
     $tp->assign('show_comments', SJB_Settings::getSettingByName('show_comments'));
     $tp->assign('METADATA', $metadata);
     $tp->assign('sorting_field', $listingSearchStructure['sorting_field']);
     $tp->assign('sorting_order', $listingSearchStructure['sorting_order']);
     $tp->assign('property', $this->getSortableProperties());
     $tp->assign('listing_search', $listingSearchStructure);
     $tp->assign('search_criteria', $searchCriteriaStructure);
     $tp->assign('listings', $listingsStructure);
     $tp->assign('waitApprove', $waitApprove);
     $tp->assign('apps', $apps);
     $hasSubusersWithListings = false;
     $subusers = SJB_UserManager::getSubusers($currentUserInfo['sid']);
     foreach ($subusers as $subuser) {
         if ($acl->isAllowed('subuser_add_listings', $subuser['sid']) || $acl->isAllowed('subuser_manage_listings', $subuser['sid'])) {
             $hasSubusersWithListings = true;
             break;
         }
     }
     $tp->assign('hasSubusersWithListings', $hasSubusersWithListings);
     $tp->display('my_listings.tpl');
 }
예제 #21
0
파일: users.php 프로젝트: Maxlander/shixi
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $template = SJB_Request::getVar('template', 'users.tpl');
     $searchTemplate = SJB_Request::getVar('search_template', 'user_search_form.tpl');
     $passedParametersViaUri = SJB_UrlParamProvider::getParams();
     $userGroupID = $passedParametersViaUri ? array_shift($passedParametersViaUri) : false;
     $userGroupSID = $userGroupID ? SJB_UserGroupManager::getUserGroupSIDByID($userGroupID) : null;
     $errors = array();
     /********** A C T I O N S   W I T H   U S E R S **********/
     $action = SJB_Request::getVar('action_name');
     if (!empty($action)) {
         $users_sids = SJB_Request::getVar('users', array());
         $_REQUEST['restore'] = 1;
         switch ($action) {
             case 'approve':
                 foreach ($users_sids as $user_sid => $value) {
                     $username = SJB_UserManager::getUserNameByUserSID($user_sid);
                     SJB_UserManager::setApprovalStatusByUserName($username, 'Approved');
                     SJB_UserManager::activateUserByUserName($username);
                     SJB_UserDBManager::deleteActivationKeyByUsername($username);
                     if (!SJB_SocialPlugin::getProfileSocialID($user_sid)) {
                         SJB_Notifications::sendUserWelcomeLetter($user_sid);
                     } else {
                         SJB_Notifications::sendUserApprovedLetter($user_sid);
                     }
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'reject':
                 $rejection_reason = SJB_Request::getVar('rejection_reason', '');
                 foreach ($users_sids as $user_sid => $value) {
                     $username = SJB_UserManager::getUserNameByUserSID($user_sid);
                     SJB_UserManager::setApprovalStatusByUserName($username, 'Rejected', $rejection_reason);
                     SJB_UserManager::deactivateUserByUserName($username);
                     SJB_Notifications::sendUserRejectedLetter($user_sid);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'activate':
                 foreach ($users_sids as $user_sid => $value) {
                     $username = SJB_UserManager::getUserNameByUserSID($user_sid);
                     $userinfo = SJB_UserManager::getUserInfoByUserName($username);
                     SJB_UserManager::activateUserByUserName($username);
                     if ($userinfo['approval'] == 'Approved') {
                         SJB_UserDBManager::deleteActivationKeyByUsername($username);
                         SJB_Notifications::sendUserApprovedLetter($user_sid);
                     }
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'deactivate':
                 foreach ($users_sids as $user_sid => $value) {
                     $username = SJB_UserManager::getUserNameByUserSID($user_sid);
                     SJB_UserManager::deactivateUserByUserName($username);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'delete':
                 foreach (array_keys($users_sids) as $user_sid) {
                     try {
                         SJB_UserManager::deleteUserById($user_sid);
                     } catch (Exception $e) {
                         $errors[] = $e->getMessage();
                     }
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'send_activation_letter':
                 foreach ($users_sids as $user_sid => $value) {
                     SJB_Notifications::sendUserActivationLetter($user_sid);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'change_product':
                 $productToChange = SJB_Request::getVar('product_to_change');
                 if (empty($productToChange)) {
                     $productToChange = 0;
                 }
                 foreach ($users_sids as $user_sid => $value) {
                     $user = SJB_UserManager::getObjectBySID($user_sid);
                     // UNSUBSCRIBE selected
                     if ($productToChange == 0) {
                         SJB_ContractManager::deleteAllContractsByUserSID($user_sid);
                     } else {
                         $productInfo = SJB_ProductsManager::getProductInfoBySID($productToChange);
                         $listingNumber = SJB_Request::getVar('number_of_listings', null);
                         if (is_null($listingNumber) && !empty($productInfo['number_of_listings'])) {
                             $listingNumber = $productInfo['number_of_listings'];
                         }
                         $contract = new SJB_Contract(array('product_sid' => $productToChange, 'numberOfListings' => $listingNumber, 'is_recurring' => 0));
                         $contract->setUserSID($user_sid);
                         $contract->saveInDB();
                         if ($contract->isFeaturedProfile()) {
                             SJB_UserManager::makeFeaturedBySID($user_sid);
                         }
                     }
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 break;
             case 'ban_ip':
                 $cantBanUsers = array();
                 foreach ($users_sids as $user_sid => $value) {
                     $user = SJB_UserManager::getUserInfoBySID($user_sid);
                     if ($user['ip'] && !SJB_IPManager::getBannedIPByValue($user['ip'])) {
                         SJB_IPManager::makeIPBanned($user['ip']);
                     } else {
                         $cantBanUsers[] = $user['username'];
                     }
                 }
                 if ($cantBanUsers) {
                     $tp->assign('cantBanUsers', $cantBanUsers);
                 } else {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 }
                 break;
             case 'unban_ip':
                 $cantUnbanIPs = array();
                 foreach ($users_sids as $user_sid => $value) {
                     $user = SJB_UserManager::getUserInfoBySID($user_sid);
                     if ($user['ip'] !== '') {
                         if (SJB_IPManager::getBannedIPByValue($user['ip'])) {
                             SJB_IPManager::makeIPEnabledByValue($user['ip']);
                         } elseif (SJB_UserManager::checkBan($errors, $user['ip'])) {
                             $cantUnbanIPs[] = $user['ip'];
                         }
                     }
                 }
                 if ($cantUnbanIPs) {
                     $tp->assign('rangeIPs', $cantUnbanIPs);
                 } else {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
                 }
                 break;
             default:
                 unset($_REQUEST['restore']);
                 break;
         }
         if (empty($errors)) {
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . SJB_Navigator::getURI());
         }
     }
     /***************************************************************/
     $_REQUEST['action'] = 'search';
     $user = new SJB_User(array(), $userGroupSID);
     $user->addProperty(array('id' => 'user_group', 'type' => 'list', 'value' => '', 'is_system' => true, 'list_values' => SJB_UserGroupManager::getAllUserGroupsIDsAndCaptions()));
     $user->addProperty(array('id' => 'registration_date', 'type' => 'date', 'value' => '', 'is_system' => true));
     $user->addProperty(array('id' => 'approval', 'caption' => 'Approval', 'type' => 'list', 'list_values' => array(array('id' => 'Pending', 'caption' => 'Pending'), array('id' => 'Approved', 'caption' => 'Approved'), array('id' => 'Rejected', 'caption' => 'Rejected')), 'length' => '10', 'is_required' => false, 'is_system' => true));
     // get array of accessible products
     $productsSIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($userGroupSID);
     $products = array();
     foreach ($productsSIDs as $key => $productSID) {
         $product = SJB_ProductsManager::getProductInfoBySID($productSID);
         $products[$key] = $product;
         if (!empty($product['pricing_type']) && $product['pricing_type'] == 'volume_based' && !empty($product['volume_based_pricing'])) {
             $volumeBasedPricing = $product['volume_based_pricing'];
             $minListings = min($volumeBasedPricing['listings_range_from']);
             $maxListings = max($volumeBasedPricing['listings_range_to']);
             $countListings = array();
             for ($i = $minListings; $i <= $maxListings; $i++) {
                 $countListings[] = $i;
             }
             $products[$key]['count_listings'] = $countListings;
         }
     }
     $user->addProperty(array('id' => 'product', 'type' => 'list', 'value' => '', 'list_values' => $products, 'is_system' => true));
     $aliases = new SJB_PropertyAliases();
     $aliases->addAlias(array('id' => 'user_group', 'real_id' => 'user_group_sid', 'transform_function' => 'SJB_UserGroupManager::getUserGroupSIDByID'));
     $aliases->addAlias(array('id' => 'product', 'real_id' => 'product_sid'));
     $_REQUEST['user_group']['equal'] = $userGroupSID;
     $search_form_builder = new SJB_SearchFormBuilder($user);
     $criteria_saver = new SJB_UserCriteriaSaver();
     if (isset($_REQUEST['restore'])) {
         $_REQUEST = array_merge($_REQUEST, $criteria_saver->getCriteria());
     }
     $criteria = $search_form_builder->extractCriteriaFromRequestData($_REQUEST, $user);
     $search_form_builder->setCriteria($criteria);
     $search_form_builder->registerTags($tp);
     $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userGroupSID);
     if (SJB_Request::getVar('online', '') == '1') {
         $tp->assign("online", true);
     }
     $tp->assign('userGroupInfo', $userGroupInfo);
     $tp->assign('products', $products);
     $tp->assign('selectedProduct', isset($_REQUEST['product']['simple_equal']) ? $_REQUEST['product']['simple_equal'] : '');
     $tp->display($searchTemplate);
     /********************** S O R T I N G *********************/
     $paginator = new SJB_UsersPagination($userGroupInfo, SJB_Request::getVar('online', ''), $template);
     $firstLastName = '';
     if (!empty($_REQUEST['FirstName']['equal'])) {
         $name['FirstName']['any_words'] = $name['LastName']['any_words'] = $_REQUEST['FirstName']['equal'];
         $firstLastName = $_REQUEST['FirstName'];
         unset($_REQUEST['FirstName']);
         $_REQUEST['FirstName']['fields_or'] = $name;
     }
     $criteria = $search_form_builder->extractCriteriaFromRequestData($_REQUEST, $user);
     $inner_join = false;
     // if search by product field
     if (isset($_REQUEST['product']['simple_equal']) && $_REQUEST['product']['simple_equal'] != '') {
         $inner_join = array('contracts' => array('join_field' => 'user_sid', 'join_field2' => 'sid', 'join' => 'INNER JOIN'));
     }
     if (SJB_Request::getVar('online', '') == '1') {
         $maxLifeTime = ini_get("session.gc_maxlifetime");
         $currentTime = time();
         $innerJoinOnline = array('user_session_data_storage' => array('join_field' => 'user_sid', 'join_field2' => 'sid', 'select_field' => 'session_id', 'join' => 'INNER JOIN', 'where' => "AND unix_timestamp(`user_session_data_storage`.`last_activity`) + {$maxLifeTime} > {$currentTime}"));
         if ($inner_join) {
             $inner_join = array_merge($inner_join, $innerJoinOnline);
         } else {
             $inner_join = $innerJoinOnline;
         }
     }
     $searcher = new SJB_UserSearcher(array('limit' => ($paginator->currentPage - 1) * $paginator->itemsPerPage, 'num_rows' => $paginator->itemsPerPage), $paginator->sortingField, $paginator->sortingOrder, $inner_join);
     $found_users = array();
     $found_users_sids = array();
     if (SJB_Request::getVar('action', '') == 'search') {
         $found_users = $searcher->getObjectsSIDsByCriteria($criteria, $aliases);
         $criteria_saver->setSession($_REQUEST, $searcher->getFoundObjectSIDs());
     } elseif (isset($_REQUEST['restore'])) {
         $found_users = $criteria_saver->getObjectsFromSession();
     }
     foreach ($found_users as $id => $userID) {
         $user_info = SJB_UserManager::getUserInfoBySID($userID);
         $contractInfo = SJB_ContractManager::getAllContractsInfoByUserSID($user_info['sid']);
         $user_info['products'] = count($contractInfo);
         $found_users[$id] = $user_info;
     }
     $paginator->setItemsCount($searcher->getAffectedRows());
     $sorted_found_users_sids = $found_users_sids;
     /****************************************************************/
     $tp->assign("userGroupInfo", $userGroupInfo);
     $tp->assign("found_users", $found_users);
     $searchFields = '';
     foreach ($_REQUEST as $key => $val) {
         if (is_array($val)) {
             foreach ($val as $fieldName => $fieldValue) {
                 if (is_array($fieldValue)) {
                     foreach ($fieldValue as $fieldSubName => $fieldSubValue) {
                         $searchFields .= "&{$key}[{$fieldSubName}]=" . array_pop($fieldSubValue);
                     }
                 } else {
                     $searchFields .= "&{$key}[{$fieldName}]={$fieldValue}";
                 }
             }
         }
     }
     $tp->assign('paginationInfo', $paginator->getPaginationInfo());
     $tp->assign("searchFields", $searchFields);
     $tp->assign("found_users_sids", $sorted_found_users_sids);
     $tp->assign('errors', $errors);
     $tp->display($template);
 }
예제 #22
0
파일: PayPal.php 프로젝트: Maxlander/shixi
 /**
  * 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);
     }
 }
예제 #23
0
파일: view.php 프로젝트: Maxlander/shixi
 /**
  * @param $applicationID
  */
 private function approveApplication($applicationID)
 {
     $applicationInfo = SJB_Applications::getBySID($applicationID);
     $jobseekerSID = $applicationInfo['jobseeker_id'];
     SJB_Applications::accept($applicationID);
     if (SJB_UserNotificationsManager::isUserNotifiedOnApplicationsApproval($jobseekerSID)) {
         SJB_Notifications::sendUserApplicationApproveOrRejectLetter($applicationID, 'approved');
     }
     $statisticSID = SJB_Statistics::getStatisticsByObjectSID($applicationID, 'apply');
     if ($statisticSID) {
         SJB_Statistics::updateStatistics($statisticSID, array('approve' => 1, 'reject' => 0));
     }
 }
예제 #24
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $userSID = SJB_Request::getVar('user_sid', false);
     $includeTax = SJB_Request::getVar('include_tax', SJB_Settings::getSettingByName('enable_taxes'));
     $errors = array();
     $invoiceErrors = array();
     $template = 'add_invoice.tpl';
     $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
     if ($userInfo) {
         if (!empty($userInfo['parent_sid'])) {
             $parent_sid = $userInfo['parent_sid'];
             $username = $userInfo['username'] . '/' . $userInfo['email'];
         } else {
             $parent_sid = $userSID;
             $username = $userInfo['FirstName'] . ' ' . $userInfo['LastName'] . ' ' . $userInfo['ContactName'] . ' ' . $userInfo['CompanyName'] . '/' . $userInfo['email'];
         }
         $formSubmitted = SJB_Request::getVar('action', '') == 'save';
         $productsSIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($userInfo['user_group_sid']);
         $products = array();
         foreach ($productsSIDs as $key => $productSID) {
             $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
             if (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') {
                 $volumeBasedPricing = $productInfo['volume_based_pricing'];
                 $minListings = min($volumeBasedPricing['listings_range_from']);
                 $maxListings = max($volumeBasedPricing['listings_range_to']);
                 $countListings = array();
                 for ($i = $minListings; $i <= $maxListings; $i++) {
                     $countListings[$i]['number_of_listings'] = $i;
                     for ($j = 1; $j <= count($volumeBasedPricing['listings_range_from']); $j++) {
                         if ($i >= $volumeBasedPricing['listings_range_from'][$j] && $i <= $volumeBasedPricing['listings_range_to'][$j]) {
                             $countListings[$i]['price'] = $volumeBasedPricing['price_per_unit'][$j];
                         }
                     }
                 }
                 $productInfo['count_listings'] = $countListings;
             } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'fixed') {
                 unset($productInfo['volume_based_pricing']);
             }
             $products[$key] = $productInfo;
         }
         $total = SJB_I18N::getInstance()->getInput('float', SJB_Request::getVar('total', 0));
         $taxInfo = SJB_TaxesManager::getTaxInfoByUserSidAndPrice($parent_sid, $total);
         $invoice = new SJB_Invoice($_REQUEST);
         $addForm = new SJB_Form($invoice);
         $addForm->registerTags($tp);
         if ($formSubmitted) {
             $invoiceErrors = $invoice->isValid();
             if (empty($invoiceErrors) && $addForm->isDataValid($errors)) {
                 $invoice->setFloatNumbersIntoValidFormat();
                 $invoice->setPropertyValue('success_page_url', SJB_System::getSystemSettings('USER_SITE_URL') . '/create-contract/');
                 SJB_InvoiceManager::saveInvoice($invoice);
                 if (SJB_Request::getVar('send_invoice', false)) {
                     SJB_Notifications::sendInvoiceToCustomer($invoice->getSID(), $userSID);
                 }
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/manage-invoices/');
             } else {
                 $invoiceDate = SJB_I18N::getInstance()->getInput('date', $invoice->getPropertyValue('date'));
                 $invoice->setPropertyValue('date', $invoiceDate);
             }
         } else {
             $invoice->setPropertyValue('date', date('Y-m-d'));
             $invoice->setPropertyValue('status', SJB_Invoice::INVOICE_STATUS_UNPAID);
         }
         $invoice->setFloatNumbersIntoValidFormat();
         $tp->assign('username', $username);
         $tp->assign('user_sid', $userSID);
         $tp->assign('products', $products);
         $tp->assign('tax', $taxInfo);
         $tp->assign('include_tax', $includeTax);
     } else {
         $errors[] = 'CUSTOMER_NOT_SELECTED';
         $tp->assign('action', 'add');
         $template = 'errors.tpl';
     }
     $tp->assign("errors", array_merge($errors, $invoiceErrors));
     $tp->display($template);
 }
예제 #25
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);
 }
예제 #26
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $bannersObj = new SJB_Banners();
     $errors = array();
     $groupSID = SJB_Request::getVar('groupSID', false);
     $form_submitted = SJB_Request::getVar('submit');
     if (isset($_REQUEST['action'])) {
         $action_name = $_REQUEST['action'];
         $params = $_REQUEST;
         switch ($action_name) {
             case 'edit':
                 if ($params['groupID'] == '') {
                     $errors[] = 'GROUP_ID_MISMATCHED';
                 }
                 if ($groupSID === false) {
                     $errors[] = 'BANNER_GROUP_SID_NOT_DEFINED';
                 }
                 if ($errors) {
                     break;
                 }
                 $result = $bannersObj->updateBannerGroup($params['groupSID'], $params['groupID'], $params['number_banners_display_at_once']);
                 if ($result === false) {
                     $errors[] = 'ERROR_UPDATE_BANNER_GROUP';
                     break;
                 }
                 if ($form_submitted == 'save_banner') {
                     $site_url = SJB_System::getSystemsettings('SITE_URL') . '/manage-banner-groups/';
                     SJB_HelperFunctions::redirect($site_url);
                 }
                 break;
             case 'delete_banner':
                 if (!isset($params['bannerId'])) {
                     $banners_sids = SJB_Request::getVar('banners', false);
                     if (count($banners_sids) > 0) {
                         $keys = array_keys($banners_sids);
                         $groupSID = $bannersObj->getBannerGroupSIDByBannerSID($keys[0]);
                         foreach ($banners_sids as $b_sid => $keys) {
                             $deleteBanner = $bannersObj->deleteBanner($b_sid);
                             if ($deleteBanner === false) {
                                 $errors[] = $bannersObj->bannersError;
                             }
                         }
                     }
                 } else {
                     $groupSID = $bannersObj->getBannerGroupSIDByBannerSID($params['bannerId']);
                     $deleteBanner = $bannersObj->deleteBanner($params['bannerId']);
                     if ($deleteBanner === false) {
                         $errors[] = $bannersObj->bannersError;
                         break;
                     }
                 }
                 $site_url = SJB_System::getSystemsettings('SITE_URL') . '/edit-banner-group/?groupSID=' . $groupSID;
                 SJB_HelperFunctions::redirect($site_url);
                 break;
             case 'activate':
                 $banners_sids = SJB_Request::getVar('banners', false);
                 if ($banners_sids) {
                     $keys = array_keys($banners_sids);
                     $groupSID = $bannersObj->getBannerGroupSIDByBannerSID($keys[0]);
                     foreach ($banners_sids as $b_sid => $keys) {
                         $deleteBanner = $bannersObj->updateActiveStatus($b_sid, true);
                         if ($deleteBanner === false) {
                             $errors[] = 'Can\'t activate banner. ID: ' . $b_sid;
                         }
                     }
                 }
                 break;
             case 'deactivate':
                 $banners_sids = SJB_Request::getVar('banners', false);
                 if ($banners_sids) {
                     $keys = array_keys($banners_sids);
                     $groupSID = $bannersObj->getBannerGroupSIDByBannerSID($keys[0]);
                     foreach ($banners_sids as $b_sid => $keys) {
                         $deleteBanner = $bannersObj->updateActiveStatus($b_sid, false);
                         if ($deleteBanner === false) {
                             $errors[] = 'Can\'t deactivate banner. ID: ' . $b_sid;
                         }
                     }
                 }
                 break;
             case 'approve':
                 $banners_sids = SJB_Request::getVar('banners', false);
                 if ($banners_sids) {
                     $keys = array_keys($banners_sids);
                     $groupSID = $bannersObj->getBannerGroupSIDByBannerSID($keys[0]);
                     foreach ($banners_sids as $b_sid => $keys) {
                         $bannerInfo = $bannersObj->getBannerProperties($b_sid);
                         $contractSID = !empty($bannerInfo['contract_sid']) ? $bannerInfo['contract_sid'] : false;
                         $approveBanner = $bannersObj->updateStatus($b_sid, 'approved');
                         if ($approveBanner === false) {
                             $errors[] = 'Can\'t approved banner. ID: ' . $b_sid;
                         } else {
                             $bannersObj->updateActiveStatus($b_sid, true);
                             if ($contractSID) {
                                 SJB_ContractManager::updateExpirationPeriod($contractSID);
                             }
                         }
                     }
                 }
                 break;
             case 'reject':
                 $banners_sids = SJB_Request::getVar('banners', false);
                 if ($banners_sids) {
                     $keys = array_keys($banners_sids);
                     $groupSID = $bannersObj->getBannerGroupSIDByBannerSID($keys[0]);
                     $reject = SJB_Request::getVar('rejection_reason', '');
                     foreach ($banners_sids as $b_sid => $keys) {
                         $approveBanner = $bannersObj->updateStatus($b_sid, 'rejected');
                         if ($approveBanner === false) {
                             $errors[] = 'Can\'t rejected banner. ID: ' . $b_sid;
                         } else {
                             $bannersObj->updateActiveStatus($b_sid, false);
                             if ($bannersObj->getBannerUserSID($b_sid)) {
                                 $bannerInfo = $bannersObj->getBannerProperties($b_sid);
                                 SJB_Notifications::sendBannerRejectedLetter($bannerInfo, $bannersObj->getBannerUserSID($b_sid), $reject);
                             }
                         }
                     }
                 }
                 break;
         }
     }
     $bannerGroup = $bannersObj->getBannerGroupBySID($groupSID);
     $banners = $bannersObj->getBannersByGroupSID($groupSID);
     $tp->assign('form_submitted', $form_submitted);
     $tp->assign('bannerGroup', $bannerGroup);
     $tp->assign('errors', $errors);
     $tp->display('edit_banner_group.tpl');
     $tp->assign('banners', $banners);
     $tp->assign('bannersPath', SJB_Banners::getSiteUrl());
     $tp->display('manage_banners.tpl');
 }
예제 #27
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');
 }
예제 #28
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');
 }
예제 #29
0
 /**
  * sends registration letter to user
  *
  * @param SJB_User $user
  * @return boolean
  */
 public static function sendUserSocialRegistrationLetter(SJB_User $user)
 {
     if (self::$oSocialPlugin) {
         return SJB_Notifications::sendUserSocialRegistrationLetter($user, self::getNetworkCaption());
     }
     return false;
 }