function isValid() { $this->fieldID = $this->property_info['id']; if (!isset($_FILES[$this->fieldID]['name']) || $_FILES[$this->fieldID]['name'] == '') { return true; } $file_id = $this->fieldID . "_tmp"; SJB_DB::query('DELETE FROM uploaded_files WHERE id=?s', $file_id); $this->property_info['value'] = $file_id; $upload_manager = new SJB_UploadFileManager(); $upload_manager->setFileGroup("video"); $upload_manager->setUploadedFileID($file_id); // CHECK FILE BEFORE UPLOAD if (!empty($this->property_info['max_file_size'])) { $upload_manager->setMaxFileSize($this->property_info['max_file_size']); } if (!$upload_manager->isValidUploadedVideoFile($this->fieldID)) { return $upload_manager->getError(); } $saved_file_name = $upload_manager->uploadFile($this->fieldID); if ($saved_file_name === false) { return $upload_manager->getError(); } $filename = SJB_BASE_DIR . '/files/video/' . $saved_file_name; $base_name = substr($saved_file_name, 0, strrpos($saved_file_name, ".")); $ext = substr($saved_file_name, 1 + strrpos($saved_file_name, ".")); if ($ext == 'flv') { $t_outfile = SJB_BASE_DIR . '/files/video/' . $base_name . '.flv_'; $outfile = SJB_BASE_DIR . '/files/video/' . $base_name . '.flv'; $this->convert_media($filename, $t_outfile, 640, 480, 32, 22050); if (!$upload_manager->fileExists($base_name . '.flv_', true)) { $upload_manager->deleteUploadedFileByID($file_id); return $upload_manager->getError(); } $upload_manager->deleteUploadedFileByID($file_id); rename($t_outfile, $outfile); } else { $outfile = SJB_BASE_DIR . '/files/video/' . $base_name . '.flv'; $this->convert_media($filename, $outfile, 640, 480, 32, 22050); if (!$upload_manager->fileExists($base_name . '.flv', true)) { $upload_manager->deleteUploadedFileByID($file_id); return $upload_manager->getError(); } $upload_manager->deleteUploadedFileByID($file_id); } $filename = SJB_BASE_DIR . '/files/video/' . $base_name . '.flv'; $img = SJB_BASE_DIR . '/files/video/' . $base_name . '.png'; $this->grab_image($filename, $img, "00:00:03", 'png', 640, 480); $upload_manager->registNewFile($file_id, $base_name . '.flv'); return true; }
function getSQLValue() { if (is_array($this->property_info['value']) && !empty($this->property_info['value']['import'])) { return $this->property_info['value']['import']; } else { $fileId = $this->property_info['id'] . "_" . $this->object_sid; $this->property_info['value'] = $fileId; $uploadManager = new SJB_UploadFileManager(); $uploadManager->setFileGroup('files'); $uploadManager->setUploadedFileID($fileId); $uploadManager->uploadFile($this->property_info['id']); if (SJB_UploadFileManager::doesFileExistByID($fileId)) { return $fileId; } return ''; } }
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'); }
function getSQLValue($file_id = null) { // fix to allow checks unique file id (fix for ajax_file_upload_handler.php and complexfile) if ($file_id === null) { $file_id = $this->getComplexParent() . ":" . $this->property_info['id'] . ":" . $this->complexEnum . "_" . $this->object_sid; } if (isset($this->files)) { foreach ($this->files as $key => $value) { $_FILES[$this->property_info['id']][$key] = $value[$this->property_info['id']][$this->complexEnum]; } } $this->property_info['value'] = $file_id; $this->values[$this->complexEnum] = $file_id; $upload_manager = new SJB_UploadFileManager(); $upload_manager->setFileGroup("files"); $upload_manager->setUploadedFileID($file_id); $upload_manager->uploadFile($this->property_info['id']); if (SJB_UploadFileManager::doesFileExistByID($file_id)) { return $file_id; } return ''; }
function getSQLValue() { $properties = $this->complex->getProperties(); foreach ($properties as $field) { if ($field->type->getType() === 'date') { $field->type->setConvertToDBDate(true); $i18n = SJB_I18N::getInstance(); $values = $field->value; if (empty($values) || !is_array($values)) { continue; } foreach ($values as $key => $value) { $this->property_info['value'][$field->id][$key] = $i18n->getInput('date', $value); } } if ($field->type->getType() === 'file') { $file_id = $this->property_info['id'] . "_" . $this->object_sid; $upload_manager = new SJB_UploadFileManager(); $upload_manager->setFileGroup("files"); $upload_manager->setUploadedFileID($file_id); $uploadFilesResults = $upload_manager->uploadFiles($this->property_info['id'], $field->id); $oldVals = isset($this->property_info['value'][$field->id]) && is_array($this->property_info['value'][$field->id]) ? $this->property_info['value'][$field->id] : array(); $this->property_info['value'][$field->id] = array(); foreach ($uploadFilesResults as $key => $value) { if (empty($value) && !empty($oldVals[$key])) { $this->property_info['value'][$field->id][$key] = $oldVals[$key]; } else { $this->property_info['value'][$field->id][$key] = $value; } } $field->setValue($this->property_info['value'][$field->id]); } } return serialize($this->property_info['value']); }
public function execute() { set_time_limit(0); ini_set('memory_limit', -1); $tp = SJB_System::getTemplateProcessor(); $user_groups_info = SJB_UserGroupManager::getAllUserGroupsInfo(); $user_group_info = reset($user_groups_info); $user_group_sid = $user_group_info['sid']; $fields_info = SJB_UserProfileFieldManager::getFieldsInfoByUserGroupSID($user_group_sid); $fields = array(); $tp->assign('test_message', SJB_Request::getVar('test_message', false)); $tp->assign('undeliveredMailingsForTest', SJB_Request::getVar('undeliveredMailingsForTest', false)); foreach ($fields_info as $key => $val) { if ($val['id'] == 'Location') { foreach ($val['fields'] as $field) { if ($field['id'] == 'Country') { $fields['country'] = SJB_CountriesManager::getAllCountriesCodesAndNames(); } elseif ($field['id'] == 'State') { $fields['state'] = SJB_StatesManager::getStatesNamesByCountry(); } } } } $tp->assign('fields', $fields); $errors = array(); $errorId = SJB_Request::getVar('error', null, 'GET'); if ($errorId) { $errors[$errorId] = 1; } if (isset($_REQUEST['submit']) && $_FILES['file_mail']['name'] && $_FILES['file_mail']['error']) { $errorId = SJB_UploadFileManager::getErrorId($_FILES['file_mail']['error']); if ($_REQUEST['submit'] != 'save') { $mailID = SJB_Request::getVar('mail_id', 0); $parameter = $mailID ? '?edit=' . $mailID : ''; SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/' . $parameter . '&error=' . $errorId); } $errors[$errorId] = 1; } else { if (isset($_REQUEST['submit'])) { SJB_DB::query("DELETE FROM uploaded_files WHERE id = 'file_mail'"); $upload_manager = new SJB_UploadFileManager(); $upload_manager->setFileGroup('files'); $upload_manager->setUploadedFileID('file_mail'); $upload_manager->uploadFile('file_mail'); $file_name = ''; if (!isset($_REQUEST['delete_file']) && isset($_REQUEST['old_file']) && !$upload_manager->getUploadedFileName('file_mail')) { $file_name = $_REQUEST['old_file']; } elseif ($upload_manager->getUploadedFileName('file_mail')) { $file_name = "files/files/" . $upload_manager->getUploadedSavedFileName('file_mail'); } $language = SJB_Request::getVar('language', 'any'); $users = SJB_Request::getVar('users', 'any'); $without_cv = SJB_Request::getVar('without_cv', false); $country = SJB_Request::getVar('country', ''); $state = SJB_Request::getVar('state', ''); $city = SJB_Request::getVar('city', ''); $products = SJB_Request::getVar('products', array()); $user_status = SJB_Request::getVar('user_status', ''); $registration_date = SJB_Request::getVar('registration_date', array()); $param = serialize(array('language' => $language, 'users' => $users, 'without_cv' => $without_cv, 'products' => $products, 'country' => $country, 'state' => $state, 'city' => $city, 'status' => $user_status, 'registration' => $registration_date)); $email = ''; $mailSubject = SJB_Request::getVar('subject', ''); $mailText = stripcslashes(SJB_Request::getVar('text', '')); $mailID = SJB_Request::getVar('mail_id', 0); if ($mailID) { SJB_DB::query('UPDATE `mailing` SET `subject` = ?s, `text` = ?s, `email` = ?s, `file` = ?s, `param` = ?s WHERE `id` = ?s', $mailSubject, $mailText, $email, $file_name, $param, $mailID); } else { $query = "INSERT INTO mailing ( email , subject , text , file, param) VALUES ( ?s, ?s, ?s, ?s, ?s)"; SJB_DB::query($query, $email, $mailSubject, $mailText, $file_name, $param); } if ($_REQUEST['submit'] == 'save') { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/'); } else { $parameter = $mailID ? '?edit=' . $mailID : ''; SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/' . $parameter); } } } if (SJB_Request::getVar('delete')) { $mailings = SJB_Request::getVar('mailing'); if (is_array($mailings)) { foreach ($mailings as $id => $value) { SJB_DB::query('DELETE FROM `mailing` WHERE `id` = ?n', $id); SJB_DB::query('DELETE FROM `mailing_info` WHERE `mailing_id` = ?n', $id); } } else { $idToDelete = SJB_Request::getInt('delete', 0); SJB_DB::query('DELETE FROM `mailing` WHERE `id` = ?n', $idToDelete); SJB_DB::query('DELETE FROM `mailing_info` WHERE `mailing_id` = ?n', $idToDelete); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/'); } if (isset($_REQUEST['edit'])) { $idToEdit = SJB_Request::getInt('edit', 0); $mail_arr = SJB_DB::query('SELECT * FROM mailing WHERE id = ?n', $idToEdit); $tp->assign("mail_id", $mail_arr[0]['id']); $tp->assign("subject", $mail_arr[0]['subject']); $tp->assign("text", $mail_arr[0]['text']); $tp->assign("file", $mail_arr[0]['file']); $tp->assign("file_url", $mail_arr[0]['file']); $tp->assign("param", unserialize($mail_arr[0]['param'])); } // get products by UserGroup ID if (SJB_Request::isAjax()) { $userGroupID = SJB_Request::getVar('usergr', 0); if ($userGroupID > 0) { $products = SJB_ProductsManager::getProductsInfoByUserGroupSID($userGroupID); } else { $products = SJB_ProductsManager::getAllProductsInfo(); } $tp->assign("products", $products); $tp->display("mailing_products.tpl"); exit; } $mail_list = SJB_DB::query('SELECT * FROM mailing'); foreach ($mail_list as $key => $var) { $param = unserialize($mail_list[$key]['param']); $where = ''; $join = ''; $numSentEmails = SJB_DB::queryValue('SELECT count(*) FROM `mailing_info` WHERE `mailing_id` = ?n AND `status`=0', $var['id']); if ($param["language"] != 'any') { $where .= " and language='{$param['language']}'"; } if ($param["users"] != '0') { $where .= ' and u.user_group_sid=' . $param['users']; } if ($param["without_cv"]) { $join = "left join listings l on l.user_sid = u.sid"; $where .= " and l.sid is null"; } // user status if (!empty($param['status'])) { $where .= ' and `u`.`active`=' . (int) $param['status']; } // registration date if (!empty($param['registration']) && is_array($param['registration'])) { $i18n = SJB_I18N::getInstance(); if (!empty($param['registration']['not_less'])) { $where .= ' AND `u`.`registration_date` > \'' . $i18n->getInput('date', $param['registration']['not_less']) . '\''; } if (!empty($param['registration']['not_more'])) { $where .= ' AND `u`.`registration_date` < \'' . $i18n->getInput('date', $param['registration']['not_more']) . '\''; } } // products if (!empty($param['products'])) { $join .= "\n LEFT JOIN contracts ON u.sid = contracts.user_sid\n LEFT JOIN products ON products.sid = contracts.product_sid\n "; $whereProduct = array(); foreach ($param['products'] as $theProduct) { $theProduct = (int) $theProduct; if (!empty($theProduct)) { $whereProduct[] .= "products.sid = '{$theProduct}'"; } else { $whereProduct[] .= 'products.sid IS NULL'; } } if (!empty($whereProduct)) { $where .= ' AND (' . implode(' OR ', $whereProduct) . ')'; } } /// products if (!empty($param['country']) || !empty($param['state'])) { if (!empty($param['country'])) { $where_country = array(); foreach ($param['country'] as $the_country) { if (!empty($the_country)) { $where_country[] .= "`u`.`Location_Country` = '{$the_country}'"; } else { $where_country[] .= "`u`.`Location_Country` IS NULL"; } } if (!empty($where_country)) { $where .= ' AND (' . implode(' OR ', $where_country) . ')'; } } if (!empty($param['state'])) { $where_state = array(); foreach ($param['state'] as $the_state) { if (!empty($the_state)) { $where_state[] .= "`u`.`Location_State` = '{$the_state}'"; } else { $where_state[] .= "`u`.`Location_State` IS NULL"; } } } if (!empty($where_state)) { $where .= ' AND (' . implode(' OR ', $where_state) . ')'; } if (!empty($param['city'])) { $where .= " AND `u`.`Location_City` = '{$param['city']}'"; } } $mail_list[$key]['not_send'] = $numSentEmails; $mail_list[$key]['mail_arr'] = SJB_DB::query("\n SELECT u.sid as sid, u.username, u.user_group_sid, u.language\n FROM users u\n {$join}\n WHERE u.sendmail = 0\n {$where}\n GROUP BY `u`.`sid`"); $mail_list[$key]['count'] = count($mail_list[$key]['mail_arr']); } /* * test sending */ $testMailingID = SJB_Request::getVar('test_send', 0); if ($testMailingID) { if ($this->isTestEmailValid()) { $testSendResult = false; $oMailing = new SJB_Mailing($testMailingID); $mailings = SJB_Request::getVar('mailing'); if (is_array($mailings)) { foreach ($mailings as $id => $value) { $oMailing->setMailingID($id); $oMailing->setMailingList($mail_list); if ($oMailing->testSend()) { $testSendResult = true; } } } else { $oMailing->setMailingList($mail_list); $testSendResult = $oMailing->testSend(); } if ($testSendResult) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/mailing/?test_message=1'); } else { $email = urlencode(SJB_Request::getString('email', false)); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/mailing/?undeliveredMailingsForTest={$email}"); } } else { $tp->assign('testEmailNotValid', true); } } // general sending $sendToMailingID = SJB_Request::getVar('sending', 0); $sendResult = false; if ($sendToMailingID) { $oMailing = new SJB_Mailing($sendToMailingID); $mailings = SJB_Request::getVar('mailing'); $undeliveredMailingsInfo = array(); if (is_array($mailings)) { foreach ($mailings as $id => $value) { $oMailing->setMailingID($id); $oMailing->setMailingList($mail_list); $countOfSendMailings = $oMailing->send(); if ($countOfSendMailings != 0) { $sendResult = true; } $undeliveredMailingsInfo = array_merge($oMailing->getUndeliveredMailingsInfo(), $undeliveredMailingsInfo); } } else { $oMailing->setMailingList($mail_list); $countOfSendMailings = $oMailing->send(); if ($countOfSendMailings != 0) { $sendResult = true; } $undeliveredMailingsInfo = $oMailing->getUndeliveredMailingsInfo(); } if ($sendResult) { $tp->assign('send_result', $sendResult); } if (count($undeliveredMailingsInfo)) { $tp->assign("UndeliveredMailings", $oMailing->getUndeliveredMailingsInfo()); } } // send mailing to undelivered $sendToUndeliveredMailingID = SJB_Request::getVar('sendToUndeliveredEmails', 0); if (!empty($sendToUndeliveredMailingID)) { $oMailing = new SJB_Mailing($sendToUndeliveredMailingID); $oMailing->setMailingList($mail_list); $oMailing->sendToUndelivered(); if ($oMailing->getUndeliveredMailingsInfo()) { $tp->assign("UndeliveredMailings", $oMailing->getUndeliveredMailingsInfo()); } } $groups = SJB_DB::query("SELECT * FROM `user_groups`"); $products = SJB_ProductsManager::getAllProductsInfo(); $testEmail = SJB_Settings::getSettingByName('test_email'); $tp->assign('test_email', $testEmail); $tp->assign("products", $products); $tp->assign("groups", $groups); $tp->assign("mail_list", $mail_list); $tp->assign('errors', $errors); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->display("mailing.tpl"); }
public function execute() { $ajaxAction = SJB_Request::getVar('ajax_action', '', 'GET'); $formToken = SJB_Request::getVar('form_token', ''); // save token date in session. In some code we needs to get list of it, and clean old tokens data from // session. self::setTokenDateToSession($formToken); switch ($ajaxAction) { // UPLOAD USER PROFILE VIDEO case 'upload_profile_video': case 'upload_profile_logo': $uploadedFieldId = SJB_Request::getVar('uploaded_field_name', '', 'GET'); // get field by user group return not all fields of profile. // but now we use getAllFieldsInfo() to check fields $userProfileFields = SJB_UserProfileFieldManager::getAllFieldsInfo(); $fieldSid = null; foreach ($userProfileFields as $field) { if ($field['id'] != $uploadedFieldId) { continue; } $fieldSid = $field['sid']; } if ($fieldSid == null) { echo "Wrong profile field specified"; exit; } $fieldInfo = SJB_UserProfileFieldManager::getFieldInfoBySID($fieldSid); $tp = SJB_System::getTemplateProcessor(); $validation = $this->validationManager($fieldInfo, $tp, $uploadedFieldId); if ($validation === true) { // video file already uploaded after isValid checks // but for 'Logo' - we need some actions to make save picture if ($fieldInfo['type'] == 'logo') { $upload_manager = new SJB_UploadPictureManager(); $upload_manager->setUploadedFileID($this->fileUniqueId); $upload_manager->setHeight($fieldInfo['height']); $upload_manager->setWidth($fieldInfo['width']); $upload_manager->uploadPicture($fieldInfo['id'], $fieldInfo); // and set value of file id to property $this->property->setValue($this->fileUniqueId); $this->propertyValue = $this->property->getValue(); } // set uploaded video to temporary value if ($fieldInfo['type'] == 'video' && isset($this->propertyValue['file_id'])) { $uploadedID = $this->propertyValue['file_id']; // rename it to unique value SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $this->fileUniqueId, $uploadedID); // fill session data for tmp storage $fieldValue = array('file_id' => $this->fileUniqueId, 'file_url' => $this->propertyValue['file_url'], 'file_name' => $this->propertyValue['file_name'], 'saved_file_name' => $this->propertyValue['saved_file_name']); $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage'); $tmpUploadsStorage = SJB_Array::setPathValue($tmpUploadsStorage, "{$formToken}/{$uploadedFieldId}", $fieldValue); SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage); } elseif ($fieldInfo['type'] == 'logo') { // for Logo - we already have file_url data and file_thumb data, without file_id // just add this to session storage // fill session data for tmp storage $fieldValue = array('file_id' => $this->fileUniqueId, 'file_url' => $this->propertyValue['file_url'], 'file_name' => $this->propertyValue['file_name'], 'thumb_file_url' => $this->propertyValue['thumb_file_url'], 'thumb_file_name' => $this->propertyValue['thumb_file_name']); $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage'); $tmpUploadsStorage = SJB_Array::setPathValue($tmpUploadsStorage, "{$formToken}/{$uploadedFieldId}", $fieldValue); SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage); } $tp->assign(array('id' => $uploadedFieldId, 'value' => $fieldValue)); } $template = ''; switch ($fieldInfo['type']) { case 'video': $template = '../field_types/input/video_profile.tpl'; break; case 'logo': $template = '../field_types/input/logo.tpl'; break; default: break; } $tp->assign('form_token', $formToken); $tp->assign('errors', $this->errors); $tp->display($template); break; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// case 'delete_profile_video': case 'delete_profile_logo': $userSid = SJB_Request::getVar('user_sid', null); if (empty($userSid)) { $userInfo = SJB_UserManager::getCurrentUserInfo(); } else { $userInfo = SJB_UserManager::getUserInfoBySID($userSid); } $fieldId = SJB_Request::getVar('field_id', null); // check session value $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage'); $sessionFileId = SJB_Array::getPath($sessionFileStorage, "{$formToken}/{$fieldId}/file_id"); if (is_null($fieldId)) { $this->errors['PARAMETERS_MISSED'] = 1; } elseif (!empty($userInfo) && !isset($userInfo[$fieldId]) && empty($sessionFileId)) { echo json_encode(array('result' => 'success')); exit; } else { if (!empty($userInfo)) { $uploaded_file_id = $userInfo[$fieldId]; SJB_UploadFileManager::deleteUploadedFileByID($uploaded_file_id); } if (!empty($sessionFileId)) { $formFileId = SJB_Request::getVar('file_id'); if ($sessionFileId == $formFileId) { SJB_UploadFileManager::deleteUploadedFileByID($formFileId); $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}/{$fieldId}"); SJB_Session::setValue('tmp_uploads_storage', $sessionFileStorage); } } } if (empty($this->errors)) { echo json_encode(array('result' => 'success')); } else { echo json_encode(array('result' => 'error', 'errors' => $this->errors)); } exit; break; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // UPLOAD LISTIG FILES //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // UPLOAD LISTIG FILES case 'upload_classifieds_video': case 'upload_file': $uploadedFieldId = SJB_Request::getVar('uploaded_field_name', '', 'GET'); // OK. For listings form we have 'listing_id' and optional field (for new listings with temporary id) - listing_type_id $listingId = SJB_Request::getVar('listing_id'); $listingTypeId = SJB_Request::getVar('listing_type_id'); if (empty($listingTypeId)) { $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId); $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listingInfo['listing_type_sid']); } $listingTypeSid = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeId); $commonListingFields = SJB_ListingFieldManager::getCommonListingFieldsInfo(); $listingFieldsByType = SJB_ListingFieldManager::getListingFieldsInfoByListingType($listingTypeSid); $listingFields = array_merge($commonListingFields, $listingFieldsByType); $fieldSid = null; foreach ($listingFields as $field) { if ($field['id'] != $uploadedFieldId) { continue; } $fieldSid = $field['sid']; } $fieldInfo = SJB_ListingFieldManager::getFieldInfoBySID($fieldSid); $tp = SJB_System::getTemplateProcessor(); $validation = $this->validationManager($fieldInfo, $tp, $uploadedFieldId); if (!$validation) { $tp->assign(array('listing_id' => $listingId, 'listing' => array('id' => $listingId))); } else { // video file already uploaded after isValid checks // but for 'Logo' - we need some actions to make save picture if ($this->property->getType() == 'file') { if ($_FILES[$uploadedFieldId]['error']) { $this->errors[SJB_UploadFileManager::getErrorId($_FILES[$uploadedFieldId]['error'])] = 1; } $upload_manager = new SJB_UploadFileManager(); $upload_manager->setUploadedFileID($this->fileUniqueId); $upload_manager->setFileGroup('files'); $upload_manager->uploadFile($fieldInfo['id']); // and set value of file id to property $this->property->setValue($this->fileUniqueId); } $this->propertyValue = $this->property->getValue(); // set uploaded video to temporary value if (isset($this->propertyValue['file_id'])) { $uploadedID = $this->propertyValue['file_id']; // rename it to unique value SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $this->fileUniqueId, $uploadedID); // SET VALUE TO TEMPORARY SESSION STORAGE $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage'); $fileValue = array('file_id' => $this->fileUniqueId, 'saved_name' => $this->propertyValue['saved_file_name']); $tmpUploadsStorage = SJB_Array::setPathValue($tmpUploadsStorage, "{$formToken}/{$uploadedFieldId}", $fileValue); SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage); // update listing property $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId); $listing = isset($listingInfo['listing_type_sid']) ? new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']) : new SJB_Listing($listingInfo); $listingProperties = $listing->getProperties(); $propertyInfo = array('id' => $uploadedFieldId, 'type' => 'string', 'value' => $this->fileUniqueId, 'is_system' => true); foreach ($listingProperties as $property) { if ($property->getID() == $uploadedFieldId) { $listing->addProperty($propertyInfo); } } $listing->setSID($listingId); SJB_ListingManager::saveListing($listing); $tp->assign(array('id' => $uploadedFieldId, 'value' => array('file_url' => $this->propertyValue['file_url'], 'file_name' => $this->propertyValue['file_name'], 'saved_file_name' => $this->propertyValue['saved_file_name'], 'file_id' => $this->fileUniqueId), 'listing_id' => $listingId, 'listing' => array('id' => $listingId))); } } switch ($this->property->getType()) { case 'video': $template = '../field_types/input/video.tpl'; break; case 'file': $template = '../field_types/input/file.tpl'; break; default: $template = '../field_types/input/video.tpl'; break; } $tp->assign('errors', $this->errors); $tp->assign('form_token', $formToken); $tp->display($template); self::cleanOldTokensFromSession(); break; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// case 'delete_classifieds_video': case 'delete_file': $listingId = SJB_Request::getVar('listing_id', null); $fieldId = SJB_Request::getVar('field_id', null); $formFileId = SJB_Request::getVar('file_id'); $this->errors = array(); // check session value $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage'); $sessionFileId = SJB_Array::getPath($sessionFileStorage, "{$formToken}/{$fieldId}/file_id"); // if empty listing id - check end empty temporary storage if (strlen($listingId) == strlen(time())) { if ($sessionFileId == $formFileId) { SJB_UploadFileManager::deleteUploadedFileByID($formFileId); // remove field from temporary storage if (!is_null($sessionFileStorage)) { $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}/{$fieldId}"); SJB_Session::setValue('tmp_uploads_storage', $sessionFileStorage); } } } else { // we change existing listing $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId); if ((is_null($listingInfo) || !isset($listingInfo[$fieldId])) && empty($sessionFileId)) { $this->errors['WRONG_PARAMETERS_SPECIFIED'] = 1; } else { if (!$this->isOwner($listingId)) { $this->errors['NOT_OWNER'] = 1; } else { $uploadedFileId = $listingInfo[$fieldId]; if (!empty($uploadedFileId)) { SJB_UploadFileManager::deleteUploadedFileByID($uploadedFileId); } SJB_UploadFileManager::deleteUploadedFileByID($formFileId); $listingInfo[$fieldId] = ''; $listing = isset($listingInfo['listing_type_sid']) ? new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']) : new SJB_Listing($listingInfo); // remove all non-changed properties and save only changed property in listing $props = $listing->getProperties(); foreach ($props as $prop) { if ($prop->getID() !== $fieldId) { $listing->deleteProperty($prop->getID()); } } $listing->setSID($listingId); SJB_ListingManager::saveListing($listing); // remove field from temporary storage $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage'); if (!is_null($sessionFileStorage)) { $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}/{$fieldId}"); SJB_Session::setValue('tmp_uploads_storage', $sessionFileStorage); } } } } if (empty($this->errors)) { echo json_encode(array('result' => 'success')); } else { echo json_encode(array('result' => 'error', 'errors' => $this->errors)); } exit; break; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// case 'get_classifieds_video_data': case 'get_file_field_data': $fieldId = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null; $listingId = SJB_Request::getVar('listing_id'); $filesFromTmpStorage = SJB_Session::getValue('tmp_uploads_storage'); $fileUniqueId = SJB_Array::getPath($filesFromTmpStorage, "{$formToken}/{$fieldId}/file_id"); // if no temporary files uploaded, return empty string if (empty($fileUniqueId)) { return ''; } $tp = SJB_System::getTemplateProcessor(); $upload_manager = new SJB_UploadFileManager(); $fileInfo = array('id' => $fieldId, 'value' => array('file_url' => $upload_manager->getUploadedFileLink($fileUniqueId), 'file_name' => $upload_manager->getUploadedFileName($fileUniqueId), 'saved_file_name' => $upload_manager->getUploadedSavedFileName($fileUniqueId), 'file_id' => $fileUniqueId), 'listing_id' => $listingId, 'listing' => array('id' => $listingId)); $tp->assign($fileInfo); $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($fieldId); $fieldType = $fieldInfo['type']; $template = ''; switch ($fieldType) { case 'video': $template = '../field_types/input/video.tpl'; break; case 'file': $template = '../field_types/input/file.tpl'; break; case 'logo': $template = '../field_types/input/logo_listing.tpl'; break; default: break; } $uploadedFilesize = $upload_manager->getUploadedFileSize($fileUniqueId); $filesizeInfo = SJB_HelperFunctions::getFileSizeAndSizeToken($uploadedFilesize); $tp->assign(array('filesize' => $filesizeInfo['filesize'], 'size_token' => $filesizeInfo['size_token'])); $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); $tp->assign('form_token', $formToken); $tp->display($template); break; //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// case 'upload_file_complex': case 'upload_classifieds_video_complex': $uploadedFieldId = SJB_Request::getVar('uploaded_field_name', '', 'GET'); list($parentField, $subFieldId, $complexStep) = explode(':', $uploadedFieldId); // OK. For listings form we have 'listing_id' and optional field (for new listings with temporary id) - listing_type_id $listingId = SJB_Request::getVar('listing_id'); $listingTypeId = SJB_Request::getVar('listing_type_id'); if (empty($listingTypeId)) { $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId); $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listingInfo['listing_type_sid']); } $listingTypeSid = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeId); $commonListingFields = SJB_ListingFieldManager::getCommonListingFieldsInfo(); $listingFieldsByType = SJB_ListingFieldManager::getListingFieldsInfoByListingType($listingTypeSid); $listingFields = array_merge($commonListingFields, $listingFieldsByType); // check parent field $fieldSid = null; foreach ($listingFields as $field) { if ($field['id'] != $parentField) { continue; } $fieldSid = $field['sid']; } $complexFieldInfo = SJB_ListingFieldManager::getFieldInfoBySID($fieldSid); $subFields = SJB_Array::get($complexFieldInfo, 'fields'); if (empty($subFields)) { echo 'wrong field ID'; exit; } // check field $fieldInfo = ''; foreach ($subFields as $subField) { if ($subField['id'] != $subFieldId) { continue; } $fieldInfo = $subField; } $complexParameters = array('parentField' => $parentField, 'subFieldId' => $subFieldId, 'complexStep' => $complexStep); $tp = SJB_System::getTemplateProcessor(); $validation = $this->validationManager($fieldInfo, $tp, $uploadedFieldId, $complexParameters); $upload_manager = new SJB_UploadFileManager(); $upload_manager->setUploadedFileID($this->fileUniqueId); $upload_manager->setFileGroup('files'); $upload_manager->uploadFile($fieldInfo['id'], $parentField); $this->property->setValue($this->fileUniqueId); $this->propertyValue = $this->property->getPropertyVariablesToAssign(); // set uploaded video to temporary value if ((isset($this->propertyValue['value']['file_id']) || isset($this->propertyValue['value'][$complexStep]['file_id'])) && $validation) { // fix for FILE type in complex field if (isset($this->propertyValue['value'][$complexStep]['file_id'])) { $this->propertyValue['value'] = $this->propertyValue['value'][$complexStep]; } $filesInfo = array($complexStep => $this->propertyValue['value']); $uploadedID = $this->propertyValue['value']['file_id']; // rename it to unique value SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $this->fileUniqueId, $uploadedID); // SET VALUE TO TEMPORARY SESSION STORAGE $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage'); $fileValue = array('file_id' => $this->fileUniqueId, 'saved_name' => $this->propertyValue['value']['saved_file_name']); $tmpUploadsStorage = SJB_Array::setPathValue($tmpUploadsStorage, "{$formToken}/{$uploadedFieldId}", $fileValue); SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage); $tp->assign(array('id' => $subFieldId, 'value' => $this->propertyValue['value']['file_name'], 'filesInfo' => $filesInfo, 'complexField' => $parentField, 'complexStep' => $complexStep, 'listing_id' => $listingId, 'listing' => array('id' => $listingId))); } else { $tp->assign(array('id' => $subFieldId, 'complexField' => $parentField, 'complexStep' => $complexStep, 'listing_id' => $listingId, 'listing' => array('id' => $listingId))); } switch ($this->property->getType()) { case 'video': $template = '../field_types/input/video.tpl'; break; case 'file': case 'complexfile': $template = '../field_types/input/file.tpl'; break; default: $template = '../field_types/input/video.tpl'; break; } $tp->assign('form_token', $formToken); $tp->assign('errors', $this->errors); $tp->display($template); break; //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// case 'delete_file_complex': $listingId = SJB_Request::getVar('listing_id', null); $fieldId = SJB_Request::getVar('field_id', null); $formFileId = SJB_Request::getVar('file_id'); $this->errors = array(); // check session value $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage'); $sessionFileId = SJB_Array::getPath($sessionFileStorage, "{$formToken}/{$fieldId}/file_id"); // if empty listing id - check and empty temporary storage if (strlen($listingId) == strlen(time())) { if ($sessionFileId == $formFileId) { SJB_UploadFileManager::deleteUploadedFileByID($formFileId); // remove field from temporary storage $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}/{$fieldId}"); SJB_Session::setValue('tmp_uploads_storage', $sessionFileStorage); } } else { // we change existing listing $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId); list($complexField, $subField, $complexStep) = explode(':', $fieldId); $fieldValue = SJB_Array::getPath($listingInfo, "{$complexField}/{$subField}/{$complexStep}"); // if field value not present in listing and not present in temporary storage - throw error if ((is_null($listingInfo) || $fieldValue === null) && empty($sessionFileId)) { $this->errors['WRONG_PARAMETERS_SPECIFIED'] = 1; } else { if (!$this->isOwner($listingId)) { $this->errors['NOT_OWNER'] = 1; } else { $uploadedFileId = $fieldValue; if (!empty($uploadedFileId)) { SJB_UploadFileManager::deleteUploadedFileByID($uploadedFileId); } SJB_UploadFileManager::deleteUploadedFileByID($formFileId); $listingInfo = SJB_Array::setPathValue($listingInfo, "{$complexField}/{$subField}/{$complexStep}", ''); $listing = new SJB_Listing($listingInfo, $listingInfo['listing_type_sid']); // remove all non-changed properties and save only changed property in listing $props = $listing->getProperties(); foreach ($props as $prop) { if ($prop->getID() !== $fieldId) { $listing->deleteProperty($prop->getID()); } } $listing->setSID($listingId); SJB_ListingManager::saveListing($listing); // remove field from temporary storage $sessionFileStorage = SJB_Session::getValue('tmp_uploads_storage'); if (!empty($sessionFileStorage)) { $sessionFileStorage = SJB_Array::unsetValueByPath($sessionFileStorage, "{$formToken}/{$fieldId}"); SJB_Session::setValue('tmp_uploads_storage', $sessionFileStorage); } } } } if (empty($this->errors)) { echo json_encode(array('result' => 'success')); } else { echo json_encode(array('result' => 'error', 'errors' => $this->errors)); } exit; break; //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// case 'get_complexfile_field_data': $listingId = SJB_Request::getVar('listing_id', null); $fieldId = SJB_Request::getVar('field_id', null); $listingTypeId = SJB_Request::getVar('listing_type_id'); $listingTypeSid = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeId); $uploadFileManager = new SJB_UploadFileManager(); // replace square brackets in complex field name $fieldId = str_replace("][", ":", $fieldId); $fieldId = str_replace("[", ":", $fieldId); $fieldId = str_replace("]", "", $fieldId); list($parentField, $subFieldId, $complexStep) = explode(':', $fieldId); $filesFromTmpStorage = SJB_Session::getValue('tmp_uploads_storage'); //$fileUniqueId = SJB_Array::getPath($filesFromTmpStorage, "listings/{$listingId}/{$fieldId}/file_id"); $fileUniqueId = SJB_Array::getPath($filesFromTmpStorage, "{$formToken}/{$fieldId}/file_id"); // if no temporary files uploaded, return empty string if (empty($fileUniqueId)) { return ''; } // get list of fields for all listing types $listingTypesInfo = SJB_ListingTypeManager::getAllListingTypesInfo(); $allFields = array(); foreach ($listingTypesInfo as $listingTypeInfo) { $typeFields = SJB_ListingFieldManager::getListingFieldsInfoByListingType($listingTypeInfo['sid']); $allFields = array_merge($allFields, $typeFields); } // NEED TO GET COMPLEX SUBFIELD PROPERTY $commonListingFields = SJB_ListingFieldManager::getCommonListingFieldsInfo(); $listingFieldsByType = $allFields; $listingFields = array_merge($commonListingFields, $listingFieldsByType); // check parent field $fieldSid = null; foreach ($listingFields as $field) { if ($field['id'] != $parentField) { continue; } $fieldSid = $field['sid']; } // parent complex field $complexFieldInfo = SJB_ListingFieldManager::getFieldInfoBySID($fieldSid); $subFields = SJB_Array::get($complexFieldInfo, 'fields'); if (empty($subFields)) { echo 'wrong field ID'; exit; } // check field for subfield $complexSubFieldInfo = ''; foreach ($subFields as $subField) { if ($subField['id'] != $subFieldId) { continue; } $complexSubFieldInfo = $subField; } if (empty($complexSubFieldInfo)) { echo 'Wrong field info'; exit; } // OK. COMPLEX SUBFIELD WE HAVE $complexSubFieldProperty = new SJB_ObjectProperty($complexSubFieldInfo); // complex file fields contents array of values, not just string filename $complexSubFieldProperty->setValue(array($complexStep => $fileUniqueId)); $valueToAssign = $complexSubFieldProperty->getPropertyVariablesToAssign(); $additionalInfo = array('listing_id' => $listingId, 'listing' => array('id' => $listingId), 'complexField' => $parentField, 'complexStep' => $complexStep); $tp = SJB_System::getTemplateProcessor(); $tp->assign($valueToAssign); $tp->assign($additionalInfo); $template = ''; switch ($complexSubFieldProperty->getType()) { case 'complexfile': $template = '../field_types/input/file.tpl'; break; default: break; } $uploadedFilesize = $uploadFileManager->getUploadedFileSize($fileUniqueId); $filesizeInfo = SJB_HelperFunctions::getFileSizeAndSizeToken($uploadedFilesize); $tp->assign(array('filesize' => $filesizeInfo['filesize'], 'size_token' => $filesizeInfo['size_token'])); $tp->assign('form_token', $formToken); $tp->display($template); break; case 'upload_listing_logo': $uploadedFieldId = SJB_Request::getVar('uploaded_field_name', '', 'GET'); $listingSid = SJB_Request::getVar('listing_id', null); $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($uploadedFieldId); $tp = SJB_System::getTemplateProcessor(); $validation = $this->validationManager($fieldInfo, $tp, $uploadedFieldId); if ($validation === true) { $upload_manager = new SJB_UploadPictureManager(); $upload_manager->setUploadedFileID($this->fileUniqueId); $upload_manager->setHeight($fieldInfo['height']); $upload_manager->setWidth($fieldInfo['width']); $upload_manager->uploadPicture($fieldInfo['id'], $fieldInfo); // and set value of file id to property $this->property->setValue($this->fileUniqueId); $this->propertyValue = $this->property->getValue(); // for Logo - we already have file_url data and file_thumb data, without file_id // just add this to session storage // fill session data for tmp storage $fieldValue = array('file_id' => $this->fileUniqueId, 'file_url' => $this->propertyValue['file_url'], 'file_name' => $this->propertyValue['file_name'], 'thumb_file_url' => $this->propertyValue['thumb_file_url'], 'thumb_file_name' => $this->propertyValue['thumb_file_name']); $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage'); $tmpUploadsStorage = SJB_Array::setPathValue($tmpUploadsStorage, "{$formToken}/{$uploadedFieldId}", $fieldValue); SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage); $tp->assign(array('id' => $uploadedFieldId, 'value' => $fieldValue)); } $template = '../field_types/input/logo_listing.tpl'; $tp->assign('form_token', $formToken); $tp->assign('errors', $this->errors); $tp->assign('listing_id', $listingSid); $tp->display($template); break; default: echo "Action not defined!"; break; } exit; }