public function execute()
 {
     $listing_id = SJB_Request::getVar('listing_id', null);
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id);
     $field_id = SJB_Request::getVar('field_id', null);
     $current_user_sid = SJB_UserManager::getCurrentUserSID();
     $owner_sid = SJB_ListingManager::getUserSIDByListingSID($listing_id);
     $errors = array();
     $complexEmun = SJB_Request::getVar('complexEnum', null, 'GET');
     $complexFieldID = SJB_Request::getVar('complexParent', null, 'GET');
     if (!is_null($complexEmun) && !is_null($complexFieldID)) {
         $fieldArr = array();
         array_push($fieldArr, $complexFieldID);
         array_push($fieldArr, $field_id);
         array_push($fieldArr, $complexEmun);
         $field_id = $complexFieldID . ':' . $field_id . $complexEmun . '_' . $listing_id;
     } else {
         $fieldArr = explode(':', $field_id);
         $complexEmun = isset($fieldArr[2]) ? explode('_', $fieldArr[2]) : false;
         $complexEmun = $complexEmun ? $complexEmun[0] : false;
     }
     if (is_null($listing_id) || is_null($field_id)) {
         $errors['PARAMETERS_MISSED'] = 1;
     } else {
         if (is_null($listing_info) || $complexEmun === false || !isset($listing_info[$fieldArr[0]][$fieldArr[1]][$complexEmun])) {
             $errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
         } else {
             if ($owner_sid != $current_user_sid) {
                 $errors['NOT_OWNER'] = 1;
             } else {
                 $uploaded_file_id = $listing_info[$fieldArr[0]][$fieldArr[1]][$complexEmun];
                 SJB_UploadFileManager::deleteUploadedFileByID($uploaded_file_id);
                 $listing_info[$field_id] = '';
                 $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
                 $props = $listing->getProperties();
                 foreach ($props as $prop) {
                     if ($prop->getID() !== $field_id) {
                         $listing->deleteProperty($prop->getID());
                     }
                 }
                 $listing->setSID($listing_id);
                 SJB_ListingManager::saveListing($listing);
             }
         }
     }
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('errors', $errors);
     $tp->assign('listing_id', $listing_id);
     $tp->display('delete_uploaded_file.tpl');
 }
 public function execute()
 {
     $listing_id = SJB_Request::getVar('listing_id', null);
     $listing_info = SJB_ListingManager::getListingInfoBySID($listing_id);
     $listingTypeSID = SJB_ListingTypeManager::getListingTypeIDBySID($listing_info['listing_type_sid']);
     $field_id = SJB_Request::getVar('field_id', null);
     $current_user_sid = SJB_UserManager::getCurrentUserSID();
     $owner_sid = SJB_ListingManager::getUserSIDByListingSID($listing_id);
     $errors = array();
     if (is_null($listing_id) || is_null($field_id)) {
         $errors['PARAMETERS_MISSED'] = 1;
     } else {
         if (is_null($listing_info) || !isset($listing_info[$field_id])) {
             $errors['WRONG_PARAMETERS_SPECIFIED'] = 1;
         } else {
             if ($owner_sid != $current_user_sid) {
                 $errors['NOT_OWNER'] = 1;
             } else {
                 $uploaded_file_id = $listing_info[$field_id];
                 SJB_UploadFileManager::deleteUploadedFileByID($uploaded_file_id);
                 $listing_info[$field_id] = '';
                 $listing = new SJB_Listing($listing_info, $listing_info['listing_type_sid']);
                 $props = $listing->getProperties();
                 foreach ($props as $prop) {
                     if ($prop->getID() !== $field_id) {
                         $listing->deleteProperty($prop->getID());
                     }
                 }
                 $listing->setSID($listing_id);
                 SJB_ListingManager::saveListing($listing);
             }
         }
     }
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('errors', $errors);
     $tp->assign('listing_id', $listing_id);
     $tp->assign('listingTypeSID', $listingTypeSID);
     $tp->display('delete_uploaded_file.tpl');
 }
Beispiel #3
0
 public function execute()
 {
     $errors = array();
     $field_errors = array();
     $tp = SJB_System::getTemplateProcessor();
     $loggedIn = SJB_UserManager::isUserLoggedIn();
     $current_user_sid = SJB_UserManager::getCurrentUserSID();
     $controller = new SJB_SendListingInfoController($_REQUEST);
     $isDataSubmitted = false;
     $jobInfo = SJB_ListingManager::getListingInfoBySID($controller->getListingID());
     if ($controller->isListingSpecified()) {
         if ($controller->isDataSubmitted()) {
             if (SJB_Captcha::getInstance($tp, $_REQUEST)->isValid($errors)) {
                 // получим уникальный id для файла в uploaded_files
                 $file_id_current = 'application_' . md5(microtime());
                 $upload_manager = new SJB_UploadFileManager();
                 $upload_manager->setFileGroup('files');
                 $upload_manager->setUploadedFileID($file_id_current);
                 $file_name = $upload_manager->uploadFile('file_tmp');
                 $id_file = $upload_manager->fileId;
                 $post = $controller->getData();
                 $listingId = 0;
                 $post['submitted_data']['questionnaire'] = '';
                 if (isset($post['submitted_data']['id_resume'])) {
                     $listingId = $post['submitted_data']['id_resume'];
                 }
                 $mimeType = isset($_FILES['file_tmp']['type']) ? $_FILES['file_tmp']['type'] : '';
                 if (isset($_FILES['file_tmp']['size']) && $file_name != '' && $_FILES['file_tmp']['size'] == 0) {
                     $errors['FILE_IS_EMPTY'] = 'The uploaded file should not be blank';
                 }
                 if (!empty($_FILES['file_tmp']['name'])) {
                     $fileFormats = explode(',', SJB_System::getSettingByName('file_valid_types'));
                     $fileInfo = pathinfo($_FILES['file_tmp']['name']);
                     if (!isset($fileInfo['extension']) || !in_array(strtolower($fileInfo['extension']), $fileFormats)) {
                         $errors['NOT_SUPPORTED_FILE_FORMAT'] = strtolower($fileInfo['extension']) . ' ' . SJB_I18N::getInstance()->gettext(null, 'is not in an acceptable file format');
                     }
                 }
                 if ($file_name == '' && $listingId == 0) {
                     $canAppplyWithoutResume = false;
                     SJB_Event::dispatch('CanApplyWithoutResume', $canAppplyWithoutResume);
                     if (!$canAppplyWithoutResume) {
                         $errors['APPLY_INPUT_ERROR'] = 'Please select file or resume';
                     }
                 } else {
                     if (SJB_Applications::isApplied($post['submitted_data']['listing_id'], $current_user_sid) && !is_null($current_user_sid)) {
                         $errors['APPLY_APPLIED_ERROR'] = 'You already applied';
                     }
                 }
                 $res = false;
                 $listing_info = '';
                 $notRegisterUserData = $_POST;
                 $score = 0;
                 // для зарегестрированного пользователя получим поля email и name
                 // для незарегестрированных - поля name и email приходят с формы
                 if ($loggedIn === true) {
                     $userData = SJB_UserManager::getCurrentUserInfo();
                     $post['submitted_data']['username'] = isset($userData['username']) ? $userData['username'] : '';
                     $post['submitted_data']['LastName'] = isset($userData['LastName']) ? $userData['LastName'] : '';
                     $post['submitted_data']['FirstName'] = isset($userData['FirstName']) ? $userData['FirstName'] : '';
                     $post['submitted_data']['name'] = $post['submitted_data']['FirstName'] . ' ' . $post['submitted_data']['LastName'];
                     $post['submitted_data']['email'] = $userData['email'];
                 }
                 if (!empty($jobInfo['screening_questionnaire'])) {
                     $questions = new SJB_Questions($_REQUEST, $jobInfo['screening_questionnaire']);
                     $add_form = new SJB_Form($questions);
                     $add_form->registerTags($tp);
                     $add_form->isDataValid($field_errors);
                     $tp->assign('field_errors', $field_errors);
                     if (!$field_errors) {
                         $result = array();
                         $properties = $questions->getProperties();
                         $countAnswers = 0;
                         foreach ($properties as $key => $val) {
                             if ($val->type->property_info['type'] == 'boolean') {
                                 switch ($val->value) {
                                     case 0:
                                         $val->value = 'No';
                                         break;
                                     case 1:
                                         $val->value = 'Yes';
                                         break;
                                 }
                             }
                             $result[$val->caption] = $val->value;
                             if (isset($val->type->property_info['list_values'])) {
                                 foreach ($val->type->property_info['list_values'] as $list_values) {
                                     if (is_array($val->value)) {
                                         foreach ($val->value as $value) {
                                             if ($value == $list_values['id'] && $list_values['score'] != 'no') {
                                                 $score += $list_values['score'];
                                                 $countAnswers++;
                                             }
                                         }
                                     } else {
                                         if ($val->value == $list_values['id'] && $list_values['score'] != 'no') {
                                             $score += $list_values['score'];
                                             $countAnswers++;
                                         }
                                     }
                                 }
                             }
                         }
                         if ($countAnswers === 0) {
                             $score = 0.0;
                         } else {
                             $score = round($score / $countAnswers, 2);
                         }
                         $post['submitted_data']['questionnaire'] = serialize($result);
                     }
                 }
                 if (count($errors) == 0 && count($field_errors) == 0) {
                     $res = SJB_Applications::create($post['submitted_data']['listing_id'], $current_user_sid, isset($post['submitted_data']['id_resume']) ? $post['submitted_data']['id_resume'] : '', $post['submitted_data']['comments'], $file_name, $mimeType, $id_file, isset($post['submitted_data']['anonymous']) ? $post['submitted_data']['anonymous'] : '0', $notRegisterUserData, $post['submitted_data']['questionnaire'], $score);
                     if ($res) {
                         SJB_Statistics::addStatistics('apply', $post['submitted_data']['listing_id'], $res);
                     }
                     if (isset($post['submitted_data']['id_resume']) && $post['submitted_data']['id_resume'] != 0) {
                         $listing_info = SJB_ListingManager::getListingInfoBySID($post['submitted_data']['id_resume']);
                         $emp_sid = SJB_ListingManager::getUserSIDByListingSID($post['submitted_data']['listing_id']);
                         $accessible = SJB_ListingManager::isListingAccessableByUser($post['submitted_data']['id_resume'], $emp_sid);
                         if (!$accessible) {
                             SJB_ListingManager::setListingAccessibleToUser($post['submitted_data']['id_resume'], $emp_sid);
                         }
                     }
                     if (!empty($file_name)) {
                         $file_name = 'files/files/' . $file_name;
                     }
                     SJB_Notifications::sendApplyNow($post, $file_name, $listing_info, $current_user_sid, $notRegisterUserData, $score);
                     if (!empty($jobInfo['screening_questionnaire'])) {
                         $questionnaire = SJB_ScreeningQuestionnaires::getInfoBySID($jobInfo['screening_questionnaire']);
                         if ($questionnaire) {
                             $passing_score = 0;
                             switch ($questionnaire['passing_score']) {
                                 case 'acceptable':
                                     $passing_score = 1;
                                     break;
                                 case 'good':
                                     $passing_score = 2;
                                     break;
                                 case 'very_good':
                                     $passing_score = 3;
                                     break;
                                 case 'excellent':
                                     $passing_score = 4;
                                     break;
                             }
                         }
                         if ($score >= $passing_score && $questionnaire['send_auto_reply_more'] == 1) {
                             if (!empty($questionnaire['email_text_more'])) {
                                 SJB_Notifications::userAutoReply($jobInfo, $current_user_sid, $questionnaire['email_text_more'], $notRegisterUserData);
                             }
                         } elseif ($score < $passing_score && $questionnaire['send_auto_reply_less'] == 1) {
                             if (!empty($questionnaire['email_text_less'])) {
                                 SJB_Notifications::userAutoReply($jobInfo, $current_user_sid, $questionnaire['email_text_less'], $notRegisterUserData);
                             }
                         }
                     }
                 }
                 if ($res === false) {
                     $errors['APPLY_ERROR'] = 'Cannot apply';
                 }
                 $isDataSubmitted = true;
             }
         }
         if (!empty($jobInfo['screening_questionnaire'])) {
             $questions = new SJB_Questions($_REQUEST, $jobInfo['screening_questionnaire']);
             $add_form = new SJB_Form($questions);
             $add_form->registerTags($tp);
             $form_fields = $add_form->getFormFieldsInfo();
             $tp->assign('form_fields', $form_fields);
             $tp->assign('questionsObject', $questions);
         }
         if ($loggedIn) {
             $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID('Resume');
             $wait_approve = SJB_ListingTypeManager::getWaitApproveSettingByListingType($listing_type_sid);
             $approve_status = '';
             if ($wait_approve) {
                 $approve_status = "AND `l`.`status` = 'approved'";
             }
             $result = SJB_DB::query("SELECT `l`.`sid` , `l`.`Title` FROM `listings` as `l`\n\t\t\t\tLEFT JOIN `listing_types` as `lt` ON (`lt`.`sid` = `l`.`listing_type_sid`)\n\t\t\t\tWHERE `lt`.`id` = 'Resume' {$approve_status} AND `l`.`user_sid` = {$current_user_sid} AND `l`.`active`");
             $resume = array();
             foreach ($result as $val) {
                 $resume[$val['sid']] = $val['Title'];
             }
             $tp->assign('resume', $resume);
         }
         $tp->assign('listing', $jobInfo);
     } else {
         $errors['UNDEFINED_LISTING_ID'] = true;
     }
     $tp->assign('request', $_REQUEST);
     $tp->assign('errors', $errors);
     $tp->assign('listing_id', $controller->getListingID());
     $tp->assign('is_data_submitted', $isDataSubmitted);
     $tp->display('apply_now.tpl');
 }
Beispiel #4
0
 public function execute()
 {
     $restore = 'restore=';
     if (isset($_REQUEST['action_name'], $_REQUEST['listings'])) {
         $listings_ids = $_REQUEST['listings'];
         switch (strtolower($_REQUEST['action_name'])) {
             case 'activate':
                 $activatedListings = array();
                 foreach ($listings_ids as $listingId => $value) {
                     if (SJB_ListingManager::activateListingBySID($listingId, false)) {
                         $activatedListings[] = $listingId;
                     }
                     $listing = SJB_ListingManager::getObjectBySID($listingId);
                     if (SJB_UserNotificationsManager::isUserNotifiedOnListingActivation($listing->getUserSID())) {
                         SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID());
                     }
                 }
                 SJB_BrowseDBManager::addListings($activatedListings);
                 break;
             case 'deactivate':
                 $this->executeAction($listings_ids, 'deactivate');
                 break;
             case 'delete':
                 $this->executeAction($listings_ids, 'delete');
                 break;
             case 'datemodify':
                 if (isset($_REQUEST['date_to_change'])) {
                     $dateToUpdate = $_REQUEST['date_to_change'];
                     $date = SJB_I18N::getInstance()->getInput('date', $dateToUpdate);
                     foreach ($listings_ids as $listing_id => $value) {
                         $listingInfo = SJB_ListingManager::getListingInfoBySID($listing_id);
                         $result = SJB_DB::query('UPDATE `listings` SET `expiration_date` = ?s WHERE `sid` = ?n', $date, $listingInfo['sid']);
                     }
                 }
                 break;
             case 'approve':
                 $this->executeAction($listings_ids, 'approve');
                 foreach ($listings_ids as $listing_id => $value) {
                     $user_sid = SJB_ListingManager::getUserSIDByListingSID($listing_id);
                     if (SJB_UserNotificationsManager::isUserNotifiedOnListingApprove($user_sid)) {
                         SJB_Notifications::sendUserListingApproveOrRejectLetter($listing_id, $user_sid, 'approve');
                     }
                 }
                 break;
             case 'reject':
                 $this->executeAction($listings_ids, 'reject');
                 foreach ($listings_ids as $listing_id => $value) {
                     $user_sid = SJB_ListingManager::getUserSIDByListingSID($listing_id);
                     if (SJB_UserNotificationsManager::isUserNotifiedOnListingReject($user_sid)) {
                         SJB_Notifications::sendUserListingApproveOrRejectLetter($listing_id, $user_sid, 'reject');
                     }
                 }
                 break;
             default:
                 $restore = '';
                 break;
         }
     }
     $listingTypeId = SJB_Request::getVar('listingTypeId', null);
     $listingType = $listingTypeId != 'Job' && $listingTypeId != 'Resume' ? $listingTypeId . '-listings' : $listingTypeId . 's';
     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-' . strtolower($listingType) . '/?action=search&' . $restore);
 }
 private function isOwner($listingSid)
 {
     $ownerSid = SJB_ListingManager::getUserSIDByListingSID($listingSid);
     $currentUserSid = SJB_UserManager::getCurrentUserSID();
     if ($ownerSid != $currentUserSid && !SJB_Admin::admin_authed() && !SJB_SubAdmin::admin_authed()) {
         return false;
     }
     return true;
 }