Example #1
0
 function getPropertyVariablesToAssign()
 {
     $upload_manager = new SJB_UploadFileManager();
     $upload_manager->setFileGroup("files");
     if (is_array($this->property_info['value'])) {
         $value = array();
         foreach ($this->property_info['value'] as $key => $fileId) {
             $value[$key] = array('file_url' => $upload_manager->getUploadedFileLink($fileId), 'file_name' => $upload_manager->getUploadedFileName($fileId), 'saved_file_name' => $upload_manager->getUploadedSavedFileName($fileId), 'file_id' => $fileId);
         }
         return array('id' => $this->property_info['id'], 'filesInfo' => $value, 'value' => $value);
     }
     return array('id' => $this->property_info['id'], 'value' => array('file_url' => $upload_manager->getUploadedFileLink($this->property_info['value']), 'file_name' => $upload_manager->getUploadedFileName($this->property_info['value']), 'saved_file_name' => $upload_manager->getUploadedSavedFileName($this->property_info['value']), 'file_id' => $this->property_info['value']));
 }
Example #2
0
 function getValue()
 {
     $upload_manager = new SJB_UploadFileManager();
     if (!empty($_FILES[$this->getComplexParent()]['name'][$this->property_info['id']])) {
         if (!empty($this->property_info['value'])) {
             $this->values = $this->property_info['value'];
         }
         $files = $_FILES[$this->getComplexParent()]['name'][$this->property_info['id']];
         $this->files = $_FILES[$this->getComplexParent()];
         return $files;
     } elseif (is_array($this->property_info['value'])) {
         $value = array();
         foreach ($this->property_info['value'] as $key => $fileId) {
             $value[$key] = array('file_url' => $upload_manager->getUploadedFileLink($fileId), 'file_name' => $upload_manager->getUploadedFileName($fileId), 'saved_file_name' => $upload_manager->getUploadedSavedFileName($fileId), 'file_id' => $fileId);
         }
         return $value;
     }
     return array('file_url' => $upload_manager->getUploadedFileLink($this->property_info['value']), 'file_name' => $upload_manager->getUploadedFileName($this->property_info['value']), 'saved_file_name' => $upload_manager->getUploadedSavedFileName($this->property_info['value']), 'file_id' => $this->property_info['value']);
 }
Example #3
0
    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");
    }
Example #4
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $display_form = new SJB_Form();
     $display_form->registerTags($tp);
     $current_user = SJB_UserManager::getCurrentUser();
     $errors = array();
     $template = SJB_Request::getVar('display_template', 'display_listing.tpl');
     $tcpdfError = SJB_Request::getVar('error', false);
     $action = substr($template, 0, -4);
     $listing_id = SJB_Request::getVar("listing_id");
     if (isset($_REQUEST['passed_parameters_via_uri'])) {
         $passed_parameters_via_uri = SJB_UrlParamProvider::getParams();
         $listing_id = isset($passed_parameters_via_uri[0]) ? $passed_parameters_via_uri[0] : null;
     }
     if (is_null($listing_id) && SJB_FormBuilderManager::getIfBuilderModeIsSet()) {
         $listing_type_id = SJB_Request::getVar('listing_type_id');
         $listing_id = SJB_ListingManager::getListingIDByListingTypeID($listing_type_id);
     }
     if (is_null($listing_id)) {
         $errors['UNDEFINED_LISTING_ID'] = true;
     } elseif (is_null($listing = SJB_ListingManager::getObjectBySID($listing_id)) || !SJB_ListingManager::isListingAccessableByUser($listing_id, SJB_UserManager::getCurrentUserSID())) {
         $errors['WRONG_LISTING_ID_SPECIFIED'] = true;
     } elseif (!$listing->isActive() && $listing->getUserSID() != SJB_UserManager::getCurrentUserSID()) {
         $errors['LISTING_IS_NOT_ACTIVE'] = true;
     } elseif (($listingStatus = SJB_ListingManager::getListingApprovalStatusBySID($listing_id)) != 'approved' && SJB_ListingTypeManager::getWaitApproveSettingByListingType($listing->listing_type_sid) == 1 && $listing->getUserSID() != SJB_UserManager::getCurrentUserSID()) {
         $errors['LISTING_IS_NOT_APPROVED'] = true;
     } elseif (SJB_ListingTypeManager::getListingTypeIDBySID($listing->listing_type_sid) == 'Resume' && ($template == 'display_job.tpl' or SJB_System::getURI() == '/print-job/') || SJB_ListingTypeManager::getListingTypeIDBySID($listing->listing_type_sid) == 'Job' && ($template == 'display_resume.tpl' or SJB_System::getURI() == '/print-resume/')) {
         $errors['WRONG_DISPLAY_TEMPLATE'] = true;
     } else {
         $listing_type_id = SJB_ListingTypeManager::getListingTypeIDBySID($listing->listing_type_sid);
         if (SJB_System::getURI() == '/print-listing/') {
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/print-' . strtolower($listing_type_id) . '/?listing_id=' . $listing_id);
             exit;
         }
         $listing->addPicturesProperty();
         $display_form = new SJB_Form($listing);
         $display_form->registerTags($tp);
         $form_fields = $display_form->getFormFieldsInfo();
         $listingOwner = SJB_UserManager::getObjectBySID($listing->user_sid);
         if ($action !== 'print_listing') {
             SJB_ListingManager::incrementViewsCounterForListing($listing_id, $listing);
         }
         $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing, array('comments', 'ratings'));
         $filename = SJB_Request::getVar('filename', false);
         if ($filename) {
             $file = SJB_UploadFileManager::openFile($filename, $listing_id);
             $errors['NO_SUCH_FILE'] = true;
         }
         $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
         $tp->assign("METADATA", array("listing" => $metaDataProvider->getMetaData($listing_structure['METADATA']), "form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields)));
         $comments = array();
         $comments_total = '';
         if (SJB_Settings::getSettingByName('show_comments') == '1') {
             $comments = SJB_CommentManager::getEnabledCommentsToListing($listing_id);
             $comments_total = count($comments);
         }
         $searchId = SJB_Request::getVar("searchId", "");
         $page = SJB_Request::getVar("page", "");
         $criteria_saver = new SJB_ListingCriteriaSaver($searchId);
         $searchCriteria = $criteria_saver->getCriteria();
         $keywordsHighlight = '';
         if (isset($searchCriteria['keywords']) && SJB_System::getSettingByName('use_highlight_for_keywords')) {
             foreach ($searchCriteria['keywords'] as $type => $keywords) {
                 switch ($type) {
                     case 'like':
                     case 'exact_phrase':
                         $keywordsHighlight = json_encode($keywords);
                         break;
                     case 'all_words':
                     case 'any_words':
                         $keywordsHighlight = json_encode(explode(' ', $keywords));
                         break;
                     case 'boolean':
                         $keywordsHighlight = json_encode(SJB_BooleanEvaluator::parse($keywords, true));
                         break;
                 }
             }
         }
         $prevNextIds = $criteria_saver->getPreviousAndNextObjectID($listing_id);
         $search_criteria_structure = $criteria_saver->createTemplateStructureForCriteria();
         //permissions contact info
         $acl = SJB_Acl::getInstance();
         $permission = 'view_' . $listing_type_id . '_contact_info';
         $allowViewContactInfo = false;
         if (SJB_UserManager::isUserLoggedIn()) {
             if (SJB_ContractManager::isPageViewed($current_user->getSID(), $permission, $listing_id) || $acl->isAllowed($permission) && in_array($acl->getPermissionParams($permission), array('', '0'))) {
                 $allowViewContactInfo = true;
             } elseif ($acl->isAllowed($permission)) {
                 $viewContactInfo['count_views'] = 0;
                 $contractIDs = $current_user->getContractID();
                 $numberOfContactViewed = SJB_ContractManager::getNumbeOfPagesViewed($current_user->getSID(), $contractIDs, $permission);
                 foreach ($contractIDs as $contractID) {
                     if ($acl->getPermissionParams($permission, $contractID, 'contract')) {
                         $params = $acl->getPermissionParams($permission, $contractID, 'contract');
                         $viewsLeft = SJB_ContractManager::getNumbeOfPagesViewed($current_user->getSID(), array($contractID), $permission);
                         if (isset($viewContactInfo['count_views']) && is_numeric($params)) {
                             $viewContactInfo['count_views'] += $params;
                             if ($params > $viewsLeft) {
                                 $viewContactInfo['contract_id'] = $contractID;
                             }
                         }
                     }
                 }
                 if ($viewContactInfo && $viewContactInfo['count_views'] > $numberOfContactViewed) {
                     $allowViewContactInfo = true;
                     SJB_ContractManager::addViewPage($current_user->getSID(), $permission, $listing_id, $viewContactInfo['contract_id'], $listing->getListingTypeSID());
                 }
             }
             $user_group_id = SJB_UserGroupManager::getUserGroupIDBySID($current_user->getUserGroupSID());
             if ($allowViewContactInfo && $user_group_id == 'JobSeeker' && $listing_type_id == 'Job') {
                 SJB_UserManager::saveRecentlyViewedListings($current_user->getSID(), $listing_id);
             }
         } elseif ($acl->isAllowed($permission)) {
             $allowViewContactInfo = true;
         }
         $tp->assign("keywordsHighlight", $keywordsHighlight);
         $tp->assign('allowViewContactInfo', $allowViewContactInfo);
         $tp->assign('show_rates', SJB_Settings::getSettingByName('show_rates'));
         $tp->assign("isApplied", SJB_Applications::isApplied($listing_id, SJB_UserManager::getCurrentUserSID()));
         $tp->assign('show_rates', SJB_Settings::getSettingByName('show_rates'));
         $tp->assign('show_comments', SJB_Settings::getSettingByName('show_comments'));
         $tp->assign('comments', $comments);
         $tp->assign('comments_total', $comments_total);
         $tp->assign('listing_id', $listing_id);
         $tp->assign("form_fields", $form_fields);
         $tp->assign('video_fields', SJB_HelperFunctions::takeMediaFields($form_fields));
         $tp->assign('uri', base64_encode(SJB_Navigator::getURIThis()));
         $tp->assign('listingOwner', $listingOwner);
         $listing_structure = SJB_ListingManager::newValueFromSearchCriteria($listing_structure, $criteria_saver->criteria);
         // SJB-1197: ajax autoupload.
         // Fix to view video from temporary uploaded storage.
         $sessionFilesStorage = SJB_Session::getValue('tmp_uploads_storage');
         // NEED TO CHECK FOR COMPLEX PARENT AND COMPLEX STEP PARAMETERS!
         $complexParent = SJB_Request::getVar('complexParent');
         $complexStep = SJB_Request::getVar('complexEnum');
         $fieldId = SJB_Request::getVar('field_id');
         $isComplex = false;
         if ($complexParent && $complexStep) {
             $fieldId = $complexParent . ":" . $fieldId . ":" . $complexStep;
             $isComplex = true;
         }
         $tempFileValue = SJB_Array::getPath($sessionFilesStorage, "listings/{$listing_id}/{$fieldId}");
         if ($isComplex) {
             $uploadFileManager = new SJB_UploadFileManager();
             $fileLink = $uploadFileManager->getUploadedFileLink($tempFileValue['file_id']);
             $tp->assign('videoFileLink', $fileLink);
         } else {
             if (!empty($tempFileValue)) {
                 $fileUniqueId = isset($tempFileValue['file_id']) ? $tempFileValue['file_id'] : '';
                 if (!empty($fileUniqueId)) {
                     $upload_manager = new SJB_UploadFileManager();
                     // file structure for videoplayer
                     $fileInfo = array('file_url' => $upload_manager->getUploadedFileLink($fileUniqueId), 'file_name' => $upload_manager->getUploadedFileName($fileUniqueId), 'saved_file_name' => $upload_manager->getUploadedSavedFileName($fileUniqueId), 'file_id' => $fileUniqueId);
                     $listing_structure[$fieldId] = $fileInfo;
                 }
             }
         }
         // SJB-1197
         // GOOGLE MAP SEARCH RESULTS CUSTOMIZATION
         $zipCode = '';
         if (!empty($listing_structure['Location']['ZipCode'])) {
             $zipCode = $listing_structure['Location']['ZipCode'];
         }
         // get 'latitude' and 'longitude' from zipCode field, if it not set
         $latitude = isset($listing_structure['latitude']) ? $listing_structure['latitude'] : '';
         $longitude = isset($listing_structure['longitude']) ? $listing_structure['longitude'] : '';
         if (!empty($zipCode) && empty($latitude) && empty($longitude)) {
             $result = SJB_DB::query("SELECT * FROM `locations` WHERE `name` = ?s LIMIT 1", $zipCode);
             if ($result) {
                 $listing_structure['latitude'] = $result[0]['latitude'];
                 $listing_structure['longitude'] = $result[0]['longitude'];
             }
         } elseif (!empty($listing_structure['Location']['City']) && !empty($listing_structure['Location']['State']) && !empty($listing_structure['Location']['Country'])) {
             $address = $listing_structure['Location']['City'] . ', ' . $listing_structure['Location']['State'] . ', ' . $listing_structure['Location']['Country'];
             $address = urlencode($address);
             $cache = SJB_Cache::getInstance();
             $parameters = array('City' => $listing_structure['Location']['City'], 'State' => $listing_structure['Location']['State'], 'Country' => $listing_structure['Location']['Country']);
             $hash = md5('google_map' . serialize($parameters));
             $data = $cache->load($hash);
             $geoCod = '';
             if (!$data) {
                 try {
                     $geoCod = SJB_HelperFunctions::getUrlContentByCurl("http://maps.googleapis.com/maps/api/geocode/json?address={$address}&sensor=false");
                     $geoCod = json_decode($geoCod);
                     if ($geoCod->status == 'OK') {
                         $cache->save($geoCod, $hash);
                     }
                 } catch (Exception $e) {
                     $backtrace = SJB_Logger::getBackTrace();
                     SJB_Error::writeToLog(array(array('level' => 'E_USER_WARNING', 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'backtrace' => sprintf("BACKTRACE:\n [%s]", join("<br/>\n", $backtrace)))));
                 }
             } else {
                 $geoCod = $data;
             }
             try {
                 if (!is_object($geoCod)) {
                     throw new Exception("Map object nave not been Created");
                 }
                 if ($geoCod->status !== 'OK') {
                     throw new Exception("Status is not OK");
                 }
                 $location = $geoCod->results[0]->geometry->location;
                 $listing_structure['latitude'] = $location->lat;
                 $listing_structure['longitude'] = $location->lng;
             } catch (Exception $e) {
                 $backtrace = SJB_Logger::getBackTrace();
                 SJB_Error::writeToLog(array(array('level' => 'E_USER_WARNING', 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'backtrace' => sprintf("BACKTRACE:\n [%s]", join("<br/>\n", $backtrace)))));
             }
         }
         if (SJB_Request::getVar('view')) {
             $tp->assign('listings', array($listing_structure));
         }
         $tp->filterThenAssign("listing", $listing_structure);
         $tp->assign("prev_next_ids", $prevNextIds);
         $tp->assign("searchId", $searchId);
         $tp->assign("page", $page);
         $tp->filterThenAssign("search_criteria", $search_criteria_structure);
         $tp->filterThenAssign("search_uri", $criteria_saver->getUri());
         if ($field_id = SJB_Request::getVar('field_id')) {
             // SJB-825
             $complexEnum = SJB_Request::getVar('complexEnum', null, 'GET');
             $complexFieldID = SJB_Request::getVar('complexParent', null, 'GET');
             if (!is_null($complexEnum) && !is_null($complexFieldID)) {
                 $videoFileID = $complexFieldID . ':' . $field_id . ':' . $complexEnum . '_' . $listing_id;
                 $videoFileLink = SJB_UploadFileManager::getUploadedFileLink($videoFileID);
                 if ($videoFileLink) {
                     $tp->assign('videoFileLink', $videoFileLink);
                 }
             }
             // SJB-825
             $tp->assign('field_id', $field_id);
         } else {
             if (SJB_Request::getVar('action', false) == 'download_pdf_version') {
                 $formBuilder = SJB_FormBuilderManager::getFormBuilder(SJB_FormBuilderManager::FORM_BUILDER_TYPE_PDF, $listing_type_id);
                 $formBuilder->setChargedTemplateProcessor($tp);
                 $tpl = 'resume_to_pdf.tpl';
                 if ($listing_structure['anonymous'] == '1') {
                     $filename = 'Anonymous User_' . $listing_structure['Title'] . '.pdf';
                 } else {
                     $filename = $listing_structure['user']['FirstName'] . ' ' . $listing_structure['user']['LastName'] . '_' . $listing_structure['Title'] . '.pdf';
                 }
                 try {
                     $html = $tp->fetch($tpl);
                     $html = preg_replace('/<div[^>]*>/', '', $html);
                     $html = str_replace('</div>', '', $html);
                     SJB_HelperFunctions::html2pdf($html, $filename, str_replace('http://', '', SJB_HelperFunctions::getSiteUrl()));
                     exit;
                 } catch (Exception $e) {
                     SJB_Error::writeToLog($e->getMessage());
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/display-resume/' . $listing_id . '/?error=TCPDF_ERROR');
                 }
             } else {
                 $formBuilder = SJB_FormBuilderManager::getFormBuilder(SJB_FormBuilderManager::FORM_BUILDER_TYPE_DISPLAY, $listing_type_id);
                 $formBuilder->setChargedTemplateProcessor($tp);
             }
         }
     }
     if ($errors) {
         foreach ($errors as $k => $v) {
             switch ($k) {
                 case 'TCPDF_ERROR':
                 case 'UNDEFINED_LISTING_ID':
                 case 'WRONG_LISTING_ID_SPECIFIED':
                 case 'LISTING_IS_NOT_ACTIVE':
                 case 'LISTING_IS_NOT_APPROVED':
                     $header = $_SERVER['SERVER_PROTOCOL'] . ' 404  Not Found';
                     $header_status = "Status: 404  Not Found";
                     header($header_status);
                     header($header);
                     SJB_System::setGlobalTemplateVariable('page_not_found', true);
                     break;
             }
         }
     }
     $tp->assign('errors', $errors);
     $tp->assign('tcpdfError', $tcpdfError);
     $tp->display($template);
 }
 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;
 }