예제 #1
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listingTypeID = SJB_Request::getVar('listing_type_id', null);
     $listingTypeSID = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
     $listingTypeInfo = SJB_ListingTypeManager::getListingTypeInfoBySID($listingTypeSID);
     $productSID = SJB_Request::getVar('product_sid', false);
     $editUser = SJB_Request::getVar('edit_user', false);
     $action = SJB_Request::getVar('action', false);
     $username = SJB_Request::getVar('username', false);
     $errors = array();
     if ($username && ($userSID = SJB_UserManager::getUserSIDbyUsername($username))) {
         $userInfo = SJB_UserManager::getUserInfoBySID($userSID);
         $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userInfo['user_group_sid']);
         if (!$productSID) {
             $products = SJB_ProductsManager::getProductsInfoByUserGroupSID($userGroupInfo['sid']);
             foreach ($products as $key => $product) {
                 if (empty($product['listing_type_sid']) || $product['listing_type_sid'] != $listingTypeSID) {
                     unset($products[$key]);
                 }
             }
             if ($action == 'productVerify') {
                 $errors['PRODUCT_NOT_SELECTED'] = 1;
             }
             $tp->assign('errors', $errors);
             $tp->assign('username', $username);
             $tp->assign('products', $products);
             $tp->assign('edit_user', $editUser);
             $tp->assign('userSID', $userSID);
             $tp->assign('userGroupInfo', $userGroupInfo);
             $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
             $tp->display('select_product.tpl');
         } else {
             $form_submitted = SJB_Request::getVar('action', '') == 'add';
             $tmp_listing_id_from_request = SJB_Request::getVar('listing_id', false, 'default', 'int');
             if (!empty($tmp_listing_id_from_request)) {
                 $tmp_listing_sid = $tmp_listing_id_from_request;
             } elseif (!$tmp_listing_id_from_request) {
                 $tmp_listing_sid = time();
             }
             $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
             $extraInfo = is_null($productInfo['serialized_extra_info']) ? null : unserialize($productInfo['serialized_extra_info']);
             if (!empty($extraInfo)) {
                 $extraInfo['product_sid'] = $productSID;
             }
             $_REQUEST['featured'] = !empty($_REQUEST['featured']) ? $_REQUEST['featured'] : $productInfo['featured'];
             $_REQUEST['priority'] = !empty($_REQUEST['priority']) ? $_REQUEST['priority'] : $productInfo['priority'];
             $listing = new SJB_Listing($_REQUEST, $listingTypeSID);
             $properties = $listing->getPropertyList();
             foreach ($properties as $property) {
                 $propertyInfo = $listing->getPropertyInfo($property);
                 $propertyInfo['user_sid'] = $userSID;
                 if ($propertyInfo['type'] == 'location') {
                     $child = $listing->getChild($property);
                     $childProperties = $child->getPropertyList();
                     foreach ($childProperties as $childProperty) {
                         $childPropertyInfo = $child->getPropertyInfo($childProperty);
                         $childPropertyInfo['user_sid'] = $userSID;
                         $child->setPropertyInfo($childProperty, $childPropertyInfo);
                     }
                 }
                 $listing->setPropertyInfo($property, $propertyInfo);
             }
             $listing->deleteProperty('status');
             $listing->deleteProperty('reject_reason');
             $access_type = $listing->getProperty('access_type');
             if ($form_submitted) {
                 if (!empty($access_type)) {
                     $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar("list_emp_ids"), 'is_system' => true));
                 }
             }
             $screening_questionnaires = SJB_ScreeningQuestionnaires::getList($userSID);
             if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) {
                 $issetQuestionnairyField = $listing->getProperty('screening_questionnaire');
                 if ($issetQuestionnairyField) {
                     $value = SJB_Request::getVar("screening_questionnaire");
                     $listing_info = $_REQUEST;
                     $value = $value ? $value : isset($listing_info['screening_questionnaire']) ? $listing_info['screening_questionnaire'] : '';
                     $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($userSID), 'is_system' => true));
                 }
             } else {
                 $listing->deleteProperty('screening_questionnaire');
             }
             if ($listing->getProperty('captcha')) {
                 $listing->deleteProperty('captcha');
             }
             $add_listing_form = new SJB_Form($listing);
             $add_listing_form->registerTags($tp);
             $field_errors = array();
             if ($form_submitted && $add_listing_form->isDataValid($field_errors)) {
                 $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                 $listing->setUserSID($userSID);
                 $listing->setProductInfo($extraInfo);
                 if (empty($access_type->value)) {
                     $listing->setPropertyValue('access_type', 'everyone');
                 }
                 SJB_ListingManager::saveListing($listing);
                 SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $_REQUEST['featured'], $_REQUEST['priority'], $userSID);
                 if (isset($_SESSION['tmp_file_storage'])) {
                     foreach ($_SESSION['tmp_file_storage'] as $v) {
                         SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `picture_saved_name` = ?s", $listing->getSID(), $v['picture_saved_name']);
                         SJB_DB::query("UPDATE `listings_pictures` SET `listing_sid` = ?n WHERE `thumb_saved_name` = ?s", $listing->getSID(), $v['thumb_saved_name']);
                     }
                     SJB_Session::unsetValue('tmp_file_storage');
                 }
                 $formToken = SJB_Request::getVar('form_token');
                 $sessionFilesStorage = SJB_Session::getValue('tmp_uploads_storage');
                 $uploadedFields = SJB_Array::getPath($sessionFilesStorage, $formToken);
                 if (!empty($uploadedFields)) {
                     foreach ($uploadedFields as $fieldId => $fieldValue) {
                         // get field of listing
                         $isComplex = false;
                         if (strpos($fieldId, ':') !== false) {
                             $isComplex = true;
                         }
                         $tmpUploadedFileId = $fieldValue['file_id'];
                         // rename it to real listing field value
                         $newFileId = $fieldId . "_" . $listing->getSID();
                         SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                         if ($isComplex) {
                             list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                             $parentProp = $listing->getProperty($parentField);
                             $parentValue = $parentProp->getValue();
                             // look for complex property with current $fieldID and set it to new value of property
                             if (!empty($parentValue)) {
                                 foreach ($parentValue as $id => $value) {
                                     if ($id == $subField) {
                                         $parentValue[$id][$complexStep] = $newFileId;
                                     }
                                 }
                                 $listing->setPropertyValue($parentField, $parentValue);
                             }
                         } else {
                             $listing->setPropertyValue($fieldId, $newFileId);
                         }
                         // unset value from session temporary storage
                         $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}/{$fieldId}");
                     }
                     //and remove token key from temporary storage
                     $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}");
                     SJB_Session::setValue('tmp_uploads_storage', $sessionFilesStorage);
                     SJB_ListingManager::saveListing($listing);
                 }
                 SJB_ListingManager::activateListingBySID($listing->getSID());
                 SJB_ProductsManager::incrementPostingsNumber($productSID);
                 $listingSid = $listing->getSID();
                 SJB_Event::dispatch('listingSaved', $listingSid);
                 if ($editUser) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-user/?user_sid=" . $userSID);
                 } else {
                     if ($listingTypeID == 'resume' || $listingTypeID == 'job') {
                         $link = "manage-" . strtolower($listingTypeID) . "s";
                     } else {
                         $link = "manage-" . strtolower($listingTypeID) . "-listings";
                     }
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/{$link}/?action=search&listing_type_sid=" . $listingTypeSID);
                 }
             } else {
                 $listing->deleteProperty('access_list');
                 $listing->deleteProperty('contract_id');
                 $add_listing_form = new SJB_Form($listing);
                 if ($form_submitted) {
                     $add_listing_form->isDataValid($field_errors);
                 }
                 $add_listing_form->registerTags($tp);
                 $form_fields = $add_listing_form->getFormFieldsInfo();
                 $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listingTypeSID);
                 $formFieldsSorted = array();
                 $formFieldsSorted['featured'] = $form_fields['featured'];
                 $formFieldsSorted['priority'] = $form_fields['priority'];
                 foreach ($pages as $page) {
                     $listing_fields = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']);
                     foreach (array_keys($listing_fields) as $field) {
                         if ($listing->propertyIsSet($field)) {
                             $formFieldsSorted[$field] = $form_fields[$field];
                         }
                     }
                 }
                 $form_fields = $formFieldsSorted;
                 //SJB_HelperFunctions::d($form_fields);
                 $employers_list = SJB_Request::getVar('list_emp_ids', false);
                 $employers = array();
                 if (is_array($employers_list)) {
                     foreach ($employers_list as $emp) {
                         $currEmp = SJB_UserManager::getUserInfoBySID($emp);
                         $employers[] = array('user_id' => $emp, 'value' => $currEmp['CompanyName']);
                     }
                     sort($employers);
                 }
                 $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
                 $tp->assign("pic_limit", $numberOfPictures);
                 $tp->assign("listing_id", $tmp_listing_sid);
                 $tp->assign("listing_access_list", $employers);
                 $tp->assign("errors", $field_errors);
                 $tp->assign("form_fields", $form_fields);
                 $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
                 $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields)));
             }
             $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
             $tp->assign('edit_user', $editUser);
             $tp->assign('productInfo', $productInfo);
             $tp->assign('username', $username);
             $tp->assign('product_sid', $productSID);
             $tp->assign('userSID', $userSID);
             $tp->assign('userGroupInfo', $userGroupInfo);
             $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
             $tp->display('input_form.tpl');
         }
     } else {
         if ($username && !$userSID) {
             $errors['USER_NOT_FOUND'] = 1;
         } elseif ($action == 'userVerify') {
             $errors['USER_NOT_SELECTED'] = 1;
         }
         $tp->assign('errors', $errors);
         $tp->assign('username', $username);
         $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
         $tp->display('select_user.tpl');
     }
 }
예제 #2
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $user_info = SJB_Authorization::getCurrentUserInfo();
     if (!empty($user_info['subuser'])) {
         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/sub-accounts/edit/?user_id=' . $user_info['subuser']['sid']);
     }
     if (!empty($user_info)) {
         $user_info = array_merge($user_info, $_REQUEST);
         $username = $user_info['username'];
         $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_info['user_group_sid']);
         $delete_profile = SJB_Request::getVar('command', '', 'post') == 'unregister-user';
         $errors = array();
         if ($delete_profile && SJB_Acl::getInstance()->isAllowed('delete_user_profile')) {
             try {
                 $user = SJB_UserManager::getObjectBySID($user_info['sid']);
                 SJB_UserManager::deleteUserById($user_info['sid']);
                 SJB_AdminNotifications::sendAdminDeletingUserProfile($user, SJB_Request::getVar('reason', '', 'post'));
                 SJB_Authorization::logout();
                 $user_info = array();
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/edit-profile/?profile_deleted=true');
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
             }
         }
         $user = new SJB_User($user_info, $user_info['user_group_sid']);
         $user->setSID($user_info['sid']);
         $user->deleteProperty("active");
         $user->deleteProperty("featured");
         $user->makePropertyNotRequired("password");
         $user->getProperty('email')->type->disableEmailConfirmation();
         $edit_profile_form = new SJB_Form($user);
         $edit_profile_form->registerTags($tp);
         $edit_profile_form->makeDisabled("username");
         $form_submitted = SJB_Request::getVar('action', false) == 'save_info';
         if ($form_submitted && $edit_profile_form->isDataValid($errors)) {
             $password_value = $user->getPropertyValue('password');
             if (empty($password_value['original'])) {
                 $user->deleteProperty('password');
             }
             SJB_UserManager::saveUser($user);
             SJB_Authorization::updateCurrentUserSession();
             // >>> SJB-1197
             // needs to check session for ajax-uploaded files, and set it to user profile
             $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
             $formToken = SJB_Request::getVar('form_token');
             if (!empty($formToken)) {
                 $tmpUploadedFields = SJB_Array::getPath($tmpUploadsStorage, $formToken);
                 if (!is_null($tmpUploadsStorage) && is_array($tmpUploadedFields)) {
                     // prepare user profile fields array
                     $userProfileFieldsInfo = SJB_UserProfileFieldManager::getAllFieldsInfo();
                     $userProfileFields = array();
                     foreach ($userProfileFieldsInfo as $field) {
                         $userProfileFields[$field['id']] = $field;
                     }
                     // look for temporary values
                     foreach ($tmpUploadedFields as $fieldId => $fieldInfo) {
                         // check field ID for valid ID in user profile fields
                         if (!array_key_exists($fieldId, $userProfileFields) || empty($fieldInfo)) {
                             continue;
                         }
                         $fieldType = $userProfileFields[$fieldId]['type'];
                         $profilePropertyId = $fieldId . '_' . $user->getSID();
                         switch (strtolower($fieldType)) {
                             case 'video':
                             case 'file':
                                 // change temporary file ID
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
                                 // set value of user property to new uploaded file
                                 $user->setPropertyValue($fieldId, $profilePropertyId);
                                 break;
                             case 'logo':
                                 // change temporary file ID and thumb ID
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId . '_thumb', $fieldInfo['file_id'] . '_thumb');
                                 // set value of user property to new uploaded file
                                 $user->setPropertyValue($fieldId, $profilePropertyId);
                                 break;
                             default:
                                 break;
                         }
                         $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}/{$fieldId}");
                     }
                     // and save user with new fields data
                     SJB_UserManager::saveUser($user);
                     SJB_Authorization::updateCurrentUserSession();
                     // clean temporary storage
                     $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}");
                     // CLEAR TEMPORARY SESSION STORAGE
                     SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
                 }
             }
             // <<< SJB-1197
             $tp->assign("form_is_submitted", true);
         } else {
             $tp->assign("errors", $errors);
         }
         $form_fields = $edit_profile_form->getFormFieldsInfo();
         $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
         $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields)));
         $tp->assign("show_mailing_flag", $user_group_info['show_mailing_flag']);
         $tp->assign("form_fields", $form_fields);
         $tp->assign('userTree', true);
         $tp->display('edit_profile.tpl');
     } elseif (empty($user_info) && SJB_Request::getVar('profile_deleted', '') == true) {
         $user = new SJB_User(array());
         $edit_profile_form = new SJB_Form($user);
         $edit_profile_form->registerTags($tp);
         $edit_profile_form->makeDisabled("username");
         $form_fields = $edit_profile_form->getFormFieldsInfo();
         $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
         $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields)));
         $tp->assign("form_fields", $form_fields);
         $tp->assign('action', 'delete_profile');
         $tp->assign('tree_link_users', 'users');
         $tp->assign('userTree', true);
         $tp->display('edit_profile.tpl');
     } else {
         $tp->assign("ERROR", "NOT_LOGIN");
         $tp->display("../miscellaneous/error.tpl");
         return;
     }
 }
예제 #3
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);
         }
     }
 }
예제 #4
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);
 }
예제 #5
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');
     }
 }
예제 #6
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $parent_name = null;
     $user_sid = SJB_Request::getVar('user_sid', false);
     if (!is_null($user_sid)) {
         $user_info = SJB_UserManager::getUserInfoBySID($user_sid);
         $user_info = array_merge($user_info, $_REQUEST);
         $form_submitted = SJB_Request::getVar('action_name');
         $user = new SJB_User($user_info, $user_info['user_group_sid']);
         if (!empty($user_info['parent_sid'])) {
             $props = $user->getProperties();
             $allowedProperties = array('username', 'email', 'password');
             foreach ($props as $prop) {
                 if (!in_array($prop->getID(), $allowedProperties)) {
                     $user->deleteProperty($prop->getID());
                 }
             }
             $parent_name = SJB_UserManager::getUserNameByUserSID($user_info['parent_sid']);
         }
         $user->setSID($user_info['sid']);
         $user->getProperty('email')->type->disableEmailConfirmation();
         $user->deleteProperty("active");
         $user->makePropertyNotRequired("password");
         if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_info['user_group_sid'])) {
             if ($form_submitted) {
                 $email = $user->getPropertyValue('email');
                 if (is_array($email)) {
                     $email = $email['original'];
                 }
                 $user->setPropertyValue('username', $email);
             }
         }
         $user->addExtUserIDProperty($user_info['extUserID']);
         $edit_user_form = new SJB_Form($user);
         $errors = array();
         if ($form_submitted && $edit_user_form->isDataValid($errors)) {
             $password_value = $user->getPropertyValue('password');
             $properties = null;
             if (empty($password_value['original'])) {
                 $properties = $user->getProperties();
                 $user->deleteProperty('password');
             }
             SJB_UserManager::saveUser($user);
             // >>> SJB-1197
             // needs to check session for ajax-uploaded files, and set it to user profile
             $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
             $formToken = SJB_Request::getVar('form_token');
             if (!empty($formToken)) {
                 $tmpUploadedFields = SJB_Array::getPath($tmpUploadsStorage, $formToken);
                 if (!is_null($tmpUploadsStorage) && is_array($tmpUploadedFields)) {
                     // prepare user profile fields array
                     $userProfileFieldsInfo = SJB_UserProfileFieldManager::getAllFieldsInfo();
                     $userProfileFields = array();
                     foreach ($userProfileFieldsInfo as $field) {
                         $userProfileFields[$field['id']] = $field;
                     }
                     // look for temporary values
                     foreach ($tmpUploadedFields as $fieldId => $fieldInfo) {
                         // check field ID for valid ID in user profile fields
                         if (!array_key_exists($fieldId, $userProfileFields) || empty($fieldInfo)) {
                             continue;
                         }
                         $fieldType = $userProfileFields[$fieldId]['type'];
                         $profilePropertyId = $fieldId . '_' . $user->getSID();
                         switch (strtolower($fieldType)) {
                             case 'video':
                             case 'file':
                                 // change temporary file ID
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
                                 // set value of user property to new uploaded file
                                 $user->setPropertyValue($fieldId, $profilePropertyId);
                                 break;
                             case 'logo':
                                 // change temporary file ID and thumb ID
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId . '_thumb', $fieldInfo['file_id'] . '_thumb');
                                 // set value of user property to new uploaded file
                                 $user->setPropertyValue($fieldId, $profilePropertyId);
                                 break;
                             default:
                                 break;
                         }
                         $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}/{$fieldId}");
                     }
                     // and save user with new fields data
                     SJB_UserManager::saveUser($user);
                     SJB_Authorization::updateCurrentUserSession();
                     // clean temporary storage
                     $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}");
                     // CLEAR TEMPORARY SESSION STORAGE
                     SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
                 }
             }
             // <<< SJB-1197
             if (SJB_Request::isAjax()) {
                 echo "<p class=\"green\">User Saved</p>";
                 exit;
             }
             if ($form_submitted == 'save_info') {
                 $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($user_info['user_group_sid']);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-users/" . mb_strtolower($userGroupInfo['id'], 'utf8'));
             }
             if (!empty($properties)) {
                 $user->details->properties = $properties;
             }
         }
         if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_info['user_group_sid'])) {
             $user->deleteProperty("username");
         }
         $listingTypes = SJB_ListingTypeManager::getAllListingTypesInfo();
         $products = SJB_ProductsManager::getProductsInfoByUserGroupSID($user_info['user_group_sid']);
         $allowedListingTypes = array();
         foreach ($products as $product) {
             if (!empty($product['listing_type_sid']) && empty($allowedListingTypes[$product['listing_type_sid']])) {
                 foreach ($listingTypes as $listingType) {
                     if ($product['listing_type_sid'] == $listingType['sid']) {
                         $allowedListingTypes[$product['listing_type_sid']] = $listingType;
                     }
                 }
             }
         }
         $edit_user_form = SJB_ObjectMother::createForm($user);
         $edit_user_form->registerTags($tp);
         $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($user_info['user_group_sid']);
         if (SJB_UserManager::checkBan($errors, $user_info['ip'])) {
             $user_info['ip_is_banned'] = 1;
         }
         $tp->assign("form_fields", $edit_user_form->getFormFieldsInfo());
         $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
         $tp->assign("errors", $errors);
         $tp->assign("listingTypes", $allowedListingTypes);
         $tp->assign("user_info", $user_info);
         $tp->assign("user_group_info", $userGroupInfo);
         $tp->assign('userTree', true);
         $tp->assign("parent_name", $parent_name);
         $tp->assign("restore", preg_match('/manage-(jobseekers)|(employers)|([a-z0-9\\_]-users)/', SJB_Request::getVar('HTTP_REFERER', '', 'SERVER')));
         SJB_System::setGlobalTemplateVariable('wikiExtraParam', $userGroupInfo['id']);
         $tp->display("edit_user.tpl");
     }
 }
예제 #7
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $current_user = SJB_UserManager::getCurrentUser();
     $currentUserInfo = SJB_UserManager::getCurrentUserInfo();
     $tp->assign('current_user', $currentUserInfo);
     $errors = array();
     $error = '';
     $listing_id = SJB_Request::getVar('listing_id', null, 'default', 'int');
     if (SJB_UserGroupManager::getUserGroupIDBySID($current_user->user_group_sid) == 'Employer') {
         $template = SJB_Request::getVar('input_template', 'copy_listing.tpl');
     } else {
         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-listings/Job/');
     }
     //getting $tmp_listing_id from request
     $tmp_listing_id_from_request = SJB_Request::getVar('tmp_listing_id', false, 'default', 'int');
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id);
     $listing_type_id = SJB_ListingTypeManager::getListingTypeIDBySID($listing_info['listing_type_sid']);
     if ($productsInfo = $this->canCurrentUserAddListing($error, $listing_type_id)) {
         $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listing_info['listing_type_sid']);
         if (!empty($tmp_listing_id_from_request)) {
             $tmp_listing_sid = $tmp_listing_id_from_request;
         } elseif (!$tmp_listing_id_from_request) {
             $tmp_listing_sid = time();
         }
         $gallery = new SJB_ListingGallery();
         $gallery->setListingSID($listing_info['sid']);
         $pictures_info = $gallery->getPicturesInfo();
         $gallery->setListingSID($tmp_listing_sid);
         $pictures_info_new = $gallery->getPicturesInfo();
         //reuploading pictures
         if (!$pictures_info_new) {
             foreach ($pictures_info as $v) {
                 if (!$gallery->uploadImage($v['picture_url'], $v['caption'])) {
                     $field_errors['Picture'] = $gallery->getError();
                 }
             }
         }
         $contractID = SJB_Request::getVar('contract_id', false, 'default', 'int');
         if ($contractID) {
             $contract = new SJB_Contract(array('contract_id' => $contractID));
         } elseif (count($productsInfo) == 1) {
             $productInfo = array_pop($productsInfo);
             $contractID = $productInfo['contract_id'];
             $contract = new SJB_Contract(array('contract_id' => $contractID));
         } else {
             $tp->assign('listing_id', $listing_id);
             $tp->assign("products_info", $productsInfo);
             $tp->assign("listing_type_id", $listing_type_id);
             $tp->display("listing_product_choice.tpl");
         }
         if ($contractID) {
             $tp->assign('tmp_listing_id', $tmp_listing_sid);
             $extraInfo = $contract->extra_info;
             $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
             $tp->assign("pic_limit", $numberOfPictures);
             $tp->assign('contractID', $contractID);
             if ($listing_info['user_sid'] != SJB_UserManager::getCurrentUserSID()) {
                 $errors['NOT_OWNER_OF_LISTING'] = $listing_id;
             } elseif (!is_null($listing_info)) {
                 $listing_info = array_merge($listing_info, $_REQUEST);
                 $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
                 $listing->deleteProperty('featured');
                 $listing->deleteProperty('priority');
                 $listing->deleteProperty('status');
                 $listing->deleteProperty('reject_reason');
                 $listing->setSID($listing_id);
                 $screening_questionnaires = SJB_ScreeningQuestionnaires::getList($current_user->getSID());
                 if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires') && $screening_questionnaires) {
                     $issetQuestionnairyField = $listing->getProperty('screening_questionnaire');
                     if ($issetQuestionnairyField) {
                         $value = SJB_Request::getVar('screening_questionnaire');
                         $value = $value ? $value : isset($listing_info['screening_questionnaire']) ? $listing_info['screening_questionnaire'] : '';
                         $listing->addProperty(array('id' => 'screening_questionnaire', 'type' => 'list', 'caption' => 'Screening Questionnaire', 'value' => $value, 'list_values' => SJB_ScreeningQuestionnaires::getListSIDsAndCaptions($current_user->getSID()), 'is_system' => true));
                     }
                 } else {
                     $listing->deleteProperty('screening_questionnaire');
                 }
                 $listing_edit_form = new SJB_Form($listing);
                 $listing_edit_form->registerTags($tp);
                 $extraInfo = $listing_info['product_info'];
                 if ($extraInfo) {
                     $extraInfo = unserialize($extraInfo);
                     $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
                     $tp->assign("pic_limit", $numberOfPictures);
                 }
                 $form_is_submitted = isset($_REQUEST['action']) && $_REQUEST['action'] == 'save_info' || isset($_REQUEST['action']) && $_REQUEST['action'] == 'add';
                 $listing->addProperty(array('id' => 'contract_id', 'type' => 'id', 'value' => $contractID, 'is_system' => true));
                 $delete = SJB_Request::getVar('action', '') == 'delete';
                 $field_errors = null;
                 if ($delete && isset($_REQUEST['field_id'])) {
                     $field_id = $_REQUEST['field_id'];
                     $listing->details->properties[$field_id]->type->property_info['value'] = null;
                 } elseif ($form_is_submitted && $listing_edit_form->isDataValid($field_errors)) {
                     $listing->addProperty(array('id' => 'complete', 'type' => 'integer', 'value' => 1, 'is_system' => true));
                     $listing->setUserSID($current_user->getSID());
                     $extraInfo = $contract->extra_info;
                     $listing->setProductInfo($extraInfo);
                     $listing->sid = null;
                     if (!empty($listing_info['subuser_sid'])) {
                         $listing->addSubuserProperty($listing_info['subuser_sid']);
                     }
                     $listingSidsForCopy = array('filesFrom' => $listing_id, 'picturesFrom' => $tmp_listing_sid);
                     SJB_ListingManager::saveListing($listing, $listingSidsForCopy);
                     // >>> SJB-1197
                     // SET VALUES FROM TEMPORARY SESSION STORAGE
                     $formToken = SJB_Request::getVar('form_token');
                     $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage');
                     $tempFieldsData = SJB_Array::getPath($sessionFileStorage, $formToken);
                     if (is_array($tempFieldsData)) {
                         foreach ($tempFieldsData as $fieldId => $fieldData) {
                             $isComplex = false;
                             if (strpos($fieldId, ':') !== false) {
                                 $isComplex = true;
                             }
                             $tmpUploadedFileId = $fieldData['file_id'];
                             // rename it to real listing field value
                             $newFileId = $fieldId . "_" . $listing->getSID();
                             SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                             if ($isComplex) {
                                 list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                                 $parentProp = $listing->getProperty($parentField);
                                 $parentValue = $parentProp->getValue();
                                 // look for complex property with current $fieldID and set it to new value of property
                                 if (!empty($parentValue)) {
                                     foreach ($parentValue as $id => $value) {
                                         if ($id == $subField) {
                                             $parentValue[$id][$complexStep] = $newFileId;
                                         }
                                     }
                                     $listing->setPropertyValue($parentField, $parentValue);
                                 }
                             } else {
                                 $listing->setPropertyValue($fieldId, $newFileId);
                             }
                             // clean temporary field storage
                             $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}/{$fieldId}");
                         }
                         //and remove token key from temporary storage
                         $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}");
                         // clear temporary data in session storage
                         SJB_Session::setValue('tmp_uploads_storage', $sessionFileStorage);
                         $listingSidsForCopy = array('filesFrom' => $listing_id, 'picturesFrom' => $listing_id);
                         SJB_ListingManager::saveListing($listing, $listingSidsForCopy);
                     }
                     // <<< SJB-1197
                     SJB_Statistics::addStatistics('addListing', $listing->getListingTypeSID(), $listing->getSID(), false, $extraInfo['featured'], $extraInfo['priority']);
                     $contract->incrementPostingsNumber();
                     SJB_ProductsManager::incrementPostingsNumber($contract->product_sid);
                     // is listing featured by default
                     if ($extraInfo['featured']) {
                         SJB_ListingManager::makeFeaturedBySID($listing->getSID());
                     }
                     if ($extraInfo['priority']) {
                         SJB_ListingManager::makePriorityBySID($listing->getSID());
                     }
                     SJB_ListingManager::activateListingBySID($listing->getSID());
                     SJB_AdminNotifications::sendAdminListingAddedLetter($listing);
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-' . strtolower($listing_type_id) . '/?listing_id=' . $listing->getSID());
                 } elseif ($form_is_submitted) {
                     $field_id = 'video';
                     if (!isset($_REQUEST['video_hidden']) && $listing->getPropertyValue($field_id)) {
                         $listing->details->properties[$field_id]->type->property_info['value'] = null;
                     }
                 }
                 $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
                 $form_fields = $listing_edit_form->getFormFieldsInfo();
                 $listing_fields_by_page = array();
                 $countPages = count($pages);
                 $i = 1;
                 foreach ($pages as $page) {
                     $listing_fields_by_page[$page['page_name']] = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']);
                     if ($i == $countPages && isset($form_fields['screening_questionnaire'])) {
                         $listing_fields_by_page[$page['page_name']]['screening_questionnaire'] = $form_fields['screening_questionnaire'];
                     }
                     foreach (array_keys($listing_fields_by_page[$page['page_name']]) as $field) {
                         if (!$listing->propertyIsSet($field)) {
                             unset($listing_fields_by_page[$page['page_name']][$field]);
                         }
                     }
                     $i++;
                 }
                 $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
                 $tp->assign('METADATA', array('listing' => $metaDataProvider->getMetaData($listing_structure['METADATA']), 'form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
                 $contract_id = $listing_info['contract_id'];
                 $contract = new SJB_Contract(array('contract_id' => $contract_id));
                 $tp->assign('contract_id', $contract_id);
                 $tp->assign('contract', $contract->extra_info);
                 $tp->assign('countPages', count($listing_fields_by_page));
                 $tp->assign('copy_listing', 1);
                 $tp->assign('tmp_listing_id', $tmp_listing_sid);
                 $tp->assign('listing_id', $listing_id);
                 $tp->assign('contractID', $contractID);
                 $tp->assign('listing', $listing_structure);
                 $tp->assign('pages', $listing_fields_by_page);
                 $tp->assign('field_errors', $field_errors);
             }
             $tp->assign('errors', $errors);
             $tp->display($template);
         }
     } else {
         $listing_type_id = isset($listing_info['listing_type_sid']) ? $listing_info['listing_type_sid'] : false;
         if ($error == 'NO_CONTRACT') {
             if ($_GET) {
                 $getParam = '?';
                 foreach ($_GET as $key => $val) {
                     $getParam .= $key . '=' . $val . '&';
                 }
                 $getParam = substr($getParam, 0, -1);
             }
             $page = base64_encode(SJB_System::getURI() . $getParam);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-products/?page=' . $page);
         }
         $tp->assign('clone_job', 1);
         $tp->assign('listing_type_id', $listing_type_id);
         $tp->assign('error', $error);
         $tp->display('add_listing_error.tpl');
     }
 }
예제 #8
0
 public static function cleanOldTokensFromSession()
 {
     $origTokensStorage = SJB_Session::getValue('tokens');
     if (!is_array($origTokensStorage)) {
         return;
     }
     $currentTime = time();
     $expireTime = 1440;
     // 24 minutes
     $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
     $tokensStorage = $origTokensStorage;
     // foreach token check time and remove it from session and remove it data from temporary uploads storage
     foreach ($tokensStorage as $token => $time) {
         $tokenTime = $currentTime - $time;
         if ($tokenTime > $expireTime) {
             // remove token data from session
             $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$token}");
             // remove token from tokens list
             $origTokensStorage = SJB_Array::unsetValueByPath($origTokensStorage, $token);
         }
     }
     unset($tokensStorage);
     SJB_Session::setValue('tokens', $origTokensStorage);
     SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
 }
예제 #9
0
 public function execute()
 {
     $listing_id = SJB_Request::getVar('listing_id', null);
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id);
     $listingTypeInfo = SJB_ListingTypeManager::getListingTypeInfoBySID($listing_info['listing_type_sid']);
     if (!is_null($listing_info)) {
         $filename = SJB_Request::getVar('filename', false);
         if ($filename) {
             $file = SJB_UploadFileManager::openFile($filename, $listing_id);
             $errors['NO_SUCH_FILE'] = true;
         }
         if (isset($_REQUEST['Occupations']) && isset($_REQUEST['Occupations']['tree']) && !$_REQUEST['Occupations']['tree']) {
             unset($_REQUEST['Occupations']['tree']);
         }
         $listing_info = array_merge($listing_info, $_REQUEST);
         if (isset($_REQUEST['Occupations']) && isset($_REQUEST['Occupations']['tree']) && $_REQUEST['Occupations']['tree']) {
             $listing_info['Occupations'] = $_REQUEST['Occupations']['tree'];
         }
         $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
         $listing->setSID($listing_id);
         $listing_edit_form = new SJB_Form($listing);
         $form_is_submitted = SJB_Request::getVar('action');
         $errors = array();
         if ($form_is_submitted) {
             $listing->addProperty(array('id' => 'access_list', 'type' => 'multilist', 'value' => SJB_Request::getVar('list_emp_ids'), 'is_system' => true));
         }
         if ($form_is_submitted && $listing_edit_form->isDataValid($errors)) {
             $listingSid = $listing->getID();
             SJB_BrowseDBManager::deleteListings($listingSid);
             SJB_ListingManager::saveListing($listing);
             SJB_BrowseDBManager::addListings($listingSid);
             $formToken = SJB_Request::getVar('form_token');
             $sessionFilesStorage = SJB_Session::getValue('tmp_uploads_storage');
             $uploadedFields = SJB_Array::getPath($sessionFilesStorage, $formToken);
             if (!empty($uploadedFields)) {
                 foreach ($uploadedFields as $fieldId => $fieldValue) {
                     // get field of listing
                     $isComplex = false;
                     if (strpos($fieldId, ':') !== false) {
                         $isComplex = true;
                     }
                     $tmpUploadedFileId = $fieldValue['file_id'];
                     // rename it to real listing field value
                     $newFileId = $fieldId . "_" . $listing->getSID();
                     SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` =?s", $newFileId, $tmpUploadedFileId);
                     if ($isComplex) {
                         list($parentField, $subField, $complexStep) = explode(':', $fieldId);
                         $parentProp = $listing->getProperty($parentField);
                         $parentValue = $parentProp->getValue();
                         // look for complex property with current $fieldID and set it to new value of property
                         if (!empty($parentValue)) {
                             foreach ($parentValue as $id => $value) {
                                 if ($id == $subField) {
                                     $parentValue[$id][$complexStep] = $newFileId;
                                 }
                             }
                             $listing->setPropertyValue($parentField, $parentValue);
                         }
                     } else {
                         $listing->setPropertyValue($fieldId, $newFileId);
                     }
                     // unset value from session temporary storage
                     $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}/{$fieldId}");
                 }
                 //and remove token key from temporary storage
                 $sessionFilesStorage = SJB_Array::unsetValueByPath($sessionFilesStorage, "{$formToken}");
                 SJB_Session::setValue('tmp_uploads_storage', $sessionFilesStorage);
                 SJB_ListingManager::saveListing($listing);
             }
             SJB_Event::dispatch('listingEdited', $listingSid);
             if (SJB_Request::isAjax()) {
                 echo '<p class="green">Listing Saved</p>';
                 exit;
             }
             if ($form_is_submitted == 'save_info') {
                 $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listing_info['listing_type_sid']);
                 $listingType = $listingTypeId != 'Job' && $listingTypeId != 'Resume' ? $listingTypeId . '-listings' : $listingTypeId . 's';
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/manage-" . strtolower($listingType) . "/?restore=1");
             }
         }
         $listing->deleteProperty('access_list');
         $comments = SJB_CommentManager::getEnabledCommentsToListing($listing_id);
         $comments_total = count($comments);
         $rate = SJB_Rating::getRatingNumToListing($listing_id);
         $form_fields = $listing_edit_form->getFormFieldsInfo();
         $pages = SJB_PostingPagesManager::getPagesByListingTypeSID($listing->getListingTypeSID());
         $realFormFields = array();
         foreach ($pages as $page) {
             $listingFields = SJB_PostingPagesManager::getAllFieldsByPageSIDForForm($page['sid']);
             foreach ($listingFields as $fieldID => $listingField) {
                 if (isset($form_fields[$fieldID])) {
                     $realFormFields[$fieldID] = $form_fields[$fieldID];
                 }
             }
         }
         $adminFields = array();
         foreach ($form_fields as $fieldName => $field) {
             if (!isset($realFormFields[$fieldName])) {
                 $adminFields[$fieldName] = $field;
             }
         }
         $realFormFields = array_merge($adminFields, $realFormFields);
         $tp = SJB_System::getTemplateProcessor();
         $listing_edit_form->registerTags($tp);
         $extraInfo = $listing_info['product_info'];
         if ($extraInfo) {
             $extraInfo = unserialize($extraInfo);
             $numberOfPictures = isset($extraInfo['number_of_pictures']) ? $extraInfo['number_of_pictures'] : 0;
             $tp->assign("listing_duration", $extraInfo['listing_duration']);
             $tp->assign("pic_limit", $numberOfPictures);
         }
         $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing);
         if (!isset($listing_structure['access_type'])) {
             $listing_structure['access_type'] = 'everyone';
         }
         $listing_access_list = SJB_ListingManager::getListingAccessList($listing_id, $listing->getPropertyValue('access_type'));
         $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
         $tp->assign('form_fields', $realFormFields);
         $tp->assign('listing', $listing_structure);
         $tp->assign('errors', $errors);
         $tp->assign('listingType', SJB_ListingTypeManager::createTemplateStructure($listingTypeInfo));
         $tp->assign('listing_access_list', $listing_access_list);
         $tp->assign('comments_total', $comments_total);
         $tp->assign('rate', $rate);
         $tp->assign('expired', SJB_ListingManager::getIfListingHasExpiredBySID($listing->getSID()));
         SJB_System::setGlobalTemplateVariable('wikiExtraParam', $listingTypeInfo['id']);
         $tp->display('edit_listing.tpl');
     }
 }
예제 #10
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $extUserID = SJB_Request::getVar('extUserID', null);
     $passedParametersViaUri = SJB_UrlParamProvider::getParams();
     $userGroupID = $passedParametersViaUri ? array_shift($passedParametersViaUri) : false;
     if (!$userGroupID) {
         $userGroupsInfo = SJB_UserGroupManager::getAllUserGroupsInfo();
         $tp->assign('user_groups_info', $userGroupsInfo);
         $tp->display('add_user_choose_user_group.tpl');
     } else {
         $userGroupSID = SJB_UserGroupManager::getUserGroupSIDByID($userGroupID);
         $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userGroupSID);
         $user = SJB_ObjectMother::createUser($_REQUEST, $userGroupSID);
         $user->deleteProperty('active');
         $user->addExtUserIDProperty($extUserID);
         $registration_form = SJB_ObjectMother::createForm($user);
         $registration_form->registerTags($tp);
         $form_submitted = SJB_Request::getVar('action', '') == 'add';
         $errors = array();
         if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($userGroupSID) && $form_submitted) {
             $email = $user->getPropertyValue('email');
             if (is_array($email)) {
                 $email = $email['original'];
             }
             $user->setPropertyValue('username', $email);
         }
         if ($form_submitted && $registration_form->isDataValid($errors)) {
             SJB_UserManager::saveUser($user);
             // >>> SJB-1197
             // needs to check session for ajax-uploaded files, and set it to user profile
             $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
             $formToken = SJB_Request::getVar('form_token');
             if (!empty($formToken)) {
                 $tmpUploadedFields = SJB_Array::getPath($tmpUploadsStorage, $formToken);
                 if (!is_null($tmpUploadsStorage) && is_array($tmpUploadedFields)) {
                     // prepare user profile fields array
                     $userProfileFieldsInfo = SJB_UserProfileFieldManager::getAllFieldsInfo();
                     $userProfileFields = array();
                     foreach ($userProfileFieldsInfo as $field) {
                         $userProfileFields[$field['id']] = $field;
                     }
                     // look for temporary values
                     foreach ($tmpUploadedFields as $fieldId => $fieldInfo) {
                         // check field ID for valid ID in user profile fields
                         if (!array_key_exists($fieldId, $userProfileFields) || empty($fieldInfo)) {
                             continue;
                         }
                         $fieldType = $userProfileFields[$fieldId]['type'];
                         $profilePropertyId = $fieldId . '_' . $user->getSID();
                         switch (strtolower($fieldType)) {
                             case 'video':
                             case 'file':
                                 // change temporary file ID
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
                                 // set value of user property to new uploaded file
                                 $user->setPropertyValue($fieldId, $profilePropertyId);
                                 break;
                             case 'logo':
                                 // change temporary file ID and thumb ID
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId . '_thumb', $fieldInfo['file_id'] . '_thumb');
                                 // set value of user property to new uploaded file
                                 $user->setPropertyValue($fieldId, $profilePropertyId);
                                 break;
                             default:
                                 break;
                         }
                         $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}/{$fieldId}");
                     }
                     // and save user with new fields data
                     SJB_UserManager::saveUser($user);
                     // clean temporary storage
                     $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}");
                     // CLEAR TEMPORARY SESSION STORAGE
                     SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
                 }
             }
             // <<< SJB-1197
             SJB_UserManager::activateUserByUserName($user->getUserName());
             $defaultProduct = SJB_UserGroupManager::getDefaultProduct($userGroupSID);
             $availableProductIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($userGroupSID);
             if ($defaultProduct && in_array($defaultProduct, $availableProductIDs)) {
                 $contract = new SJB_Contract(array('product_sid' => $defaultProduct));
                 $contract->setUserSID($user->getSID());
                 $contract->saveInDB();
             }
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-users/" . mb_strtolower($userGroupInfo['id'], 'utf8'));
         } else {
             if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($userGroupSID)) {
                 $user->deleteProperty('username');
             }
             $registration_form = SJB_ObjectMother::createForm($user);
             $registration_form->registerTags($tp);
             $tp->assign("errors", $errors);
             $tp->assign("user_group", $userGroupInfo);
             $tp->assign('userTree', true);
             $tp->assign("form_fields", $registration_form->getFormFieldsInfo());
             $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
             $tp->display("add_user.tpl");
         }
     }
 }