Beispiel #1
0
 public static function getDetails($user_group_sid, $referenceUid = false)
 {
     $details = array(array('id' => 'featured', 'caption' => 'Featured', 'type' => 'boolean', 'length' => '20', 'is_required' => false, 'is_system' => true, 'order' => null), array('id' => 'active', 'caption' => 'Status', 'type' => 'list', 'list_values' => array(array('id' => '1', 'caption' => 'Active'), array('id' => '0', 'caption' => 'Not active')), 'length' => '10', 'is_required' => false, 'is_system' => true), array('id' => 'sendmail', 'caption' => "Don't send mailings", 'type' => 'boolean', 'length' => '1', 'is_required' => false, 'is_system' => true));
     $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
     $email_confirmation = false;
     if (isset($user_group_info['email_confirmation'])) {
         $email_confirmation = $user_group_info['email_confirmation'];
     }
     if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_group_sid) || class_exists('SJB_SocialPlugin') && $referenceUid) {
         $userFields = array(array('id' => 'username', 'caption' => 'User name', 'type' => 'string', 'table_name' => 'users', 'length' => '20', 'is_required' => true, 'is_system' => true, 'order' => 0), array('id' => 'password', 'caption' => 'Password', 'type' => 'password', 'length' => '20', 'is_required' => true, 'is_system' => true, 'order' => 2), array('id' => 'email', 'caption' => 'Email', 'type' => 'unique_email', 'table_name' => 'users', 'length' => '20', 'is_required' => true, 'is_system' => true, 'order' => 1, 'email_confirmation' => $email_confirmation));
     } else {
         $userFields = array(array('id' => 'username', 'caption' => 'User name', 'type' => 'unique_string', 'table_name' => 'users', 'length' => '20', 'validators' => array('SJB_IdValidator', 'SJB_UniqueSystemValidator'), 'is_required' => true, 'is_system' => true, 'order' => 0), array('id' => 'password', 'caption' => 'Password', 'type' => 'password', 'length' => '20', 'is_required' => true, 'is_system' => true, 'order' => 1), array('id' => 'email', 'caption' => 'Email', 'type' => 'unique_email', 'table_name' => 'users', 'length' => '20', 'is_required' => true, 'is_system' => true, 'order' => 2, 'email_confirmation' => $email_confirmation));
     }
     $details = array_merge($userFields, $details);
     $extra_details = SJB_UserProfileFieldManager::getFieldsInfoByUserGroupSID($user_group_sid);
     foreach ($extra_details as $key => $extra_detail) {
         if ($extra_detail['type'] == 'monetary' || $extra_detail['type'] == 'complex') {
             $extra_details[$key]['is_system'] = false;
         } else {
             $extra_details[$key]['is_system'] = true;
         }
     }
     $details = array_merge($details, $extra_details);
     if (SJB_PluginManager::isPluginActive('CaptchaPlugin') && SJB_System::getSettingByName('registrationCaptcha') == 1 && SJB_System::getURI() == '/registration/') {
         $details_captcha = array(array('id' => 'captcha', 'caption' => 'Enter code from image', 'type' => 'captcha', 'length' => '20', 'is_required' => true, 'is_system' => false));
         $details = array_merge($details, $details_captcha);
     }
     return $details;
 }
 public function execute()
 {
     $user_group_sid = isset($_REQUEST['user_group_sid']) ? $_REQUEST['user_group_sid'] : null;
     $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
     $user_profile_field = new SJB_UserProfileField($_REQUEST);
     $user_profile_field->setUserGroupSID($user_group_sid);
     //infill instructions field
     //$user_profile_field->addInfillInstructions(SJB_Request::getVar('instructions'));
     $add_user_profile_field_form = new SJB_Form($user_profile_field);
     $form_is_submitted = isset($_REQUEST['action']) && $_REQUEST['action'] == 'add';
     $errors = null;
     if ($form_is_submitted && $add_user_profile_field_form->isDataValid($errors)) {
         SJB_UserProfileFieldManager::saveUserProfileField($user_profile_field);
         if (SJB_Request::getVar('type', '') == 'youtube') {
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/instruction_user_profile_field/?user_group_sid=" . $user_group_sid . "&user_field_sid=" . $user_profile_field->sid);
         } else {
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/edit-user-profile/?user_group_sid=" . $user_group_sid);
         }
     } else {
         $template_processor = SJB_System::getTemplateProcessor();
         $add_user_profile_field_form->registerTags($template_processor);
         $template_processor->assign("form_fields", $add_user_profile_field_form->getFormFieldsInfo());
         $template_processor->assign("user_group_sid", $user_group_sid);
         $template_processor->assign("errors", $errors);
         $template_processor->assign("user_group_info", $user_group_info);
         $template_processor->display("add_user_profile_field.tpl");
     }
 }
Beispiel #3
0
 private function addLocationField($userGroupSid)
 {
     $locationFieldDetails = array('id' => 'Location', 'caption' => 'Location', 'type' => 'location', 'is_required' => '0');
     $locationField = new SJB_UserProfileField($locationFieldDetails);
     $locationField->setUserGroupSID($userGroupSid);
     SJB_UserProfileFieldManager::saveUserProfileField($locationField);
 }
Beispiel #4
0
 public function execute()
 {
     $template_processor = SJB_System::getTemplateProcessor();
     $errors = array();
     $UserProfileFieldListItemManager = new SJB_UserProfileFieldListItemManager();
     if (!isset($_REQUEST['field_sid'], $_REQUEST['item_sid'])) {
         echo 'The system cannot proceed as some key paramaters are missed';
     } else {
         if (is_null($list_item = $UserProfileFieldListItemManager->getListItemBySID($_REQUEST['item_sid']))) {
             echo 'Wrong parameters are specified';
         } else {
             $list_item_info['value'] = $list_item->getValue();
             $template_processor->assign("list_item_info", $list_item_info);
             if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'save') {
                 $list_item->setValue($_REQUEST['list_item_value']);
                 if (empty($_REQUEST['list_item_value'])) {
                     $errors = array('Value' => 'EMPTY_VALUE');
                 } else {
                     $UserProfileFieldListItemManager->saveListItem($list_item);
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-user-profile-field/edit-list/?field_sid=" . $_REQUEST['field_sid']);
                 }
             }
             $user_profile_field = SJB_UserProfileFieldManager::getFieldBySID($_REQUEST['field_sid']);
             $user_profile_field_info = SJB_UserProfileFieldManager::getFieldInfoBySID($_REQUEST['field_sid']);
             $template_processor->assign("user_profile_field_info", $user_profile_field_info);
             $template_processor->assign("user_group_sid", $user_profile_field->getUserGroupSID());
             $template_processor->assign("user_profile_field_sid", $_REQUEST['field_sid']);
             $template_processor->assign("item_sid", $_REQUEST['item_sid']);
             $template_processor->assign("list_item_value", htmlspecialchars($list_item->getValue()));
             $template_processor->assign("errors", $errors);
             $template_processor->assign("user_group_info", SJB_UserGroupManager::getUserGroupInfoBySID($user_profile_field->getUserGroupSID()));
             $template_processor->display("user_profile_list_item_editing.tpl");
         }
     }
 }
Beispiel #5
0
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $tp = SJB_System::getTemplateProcessor();
     $userGroupID = SJB_Request::getVar('user_group_id', 0);
     $user = SJB_UsersExportController::createUser($userGroupID);
     $searchFormBuilder = new SJB_SearchFormBuilder($user);
     $criteria = $searchFormBuilder->extractCriteriaFromRequestData($_REQUEST, $user);
     $searchFormBuilder->registerTags($tp);
     $searchFormBuilder->setCriteria($criteria);
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $exportProperties = SJB_Request::getVar('export_properties', array());
         if (empty($exportProperties)) {
             SJB_FlashMessages::getInstance()->addWarning('EMPTY_EXPORT_PROPERTIES');
         } else {
             $innerJoin = false;
             if (isset($_REQUEST['product']['multi_like']) && $_REQUEST['product']['multi_like'] != '') {
                 $products = $_REQUEST['product']['multi_like'];
                 if (is_array($products)) {
                     $products = implode(',', $products);
                 }
                 $whereParam = implode(',', explode(',', SJB_DB::quote($products)));
                 $innerJoin = array('contracts' => array('join_field' => 'user_sid', 'join_field2' => 'sid', 'join' => 'INNER JOIN', 'where' => "AND FIND_IN_SET(`contracts`.`product_sid`, '{$whereParam}')"));
                 unset($criteria['system']['product']);
             }
             $searcher = new SJB_UserSearcher(false, 'parent_sid', 'ASC', $innerJoin);
             $searchAliases = SJB_UsersExportController::getSearchPropertyAliases();
             $foundUsersSid = $searcher->getObjectsSIDsByCriteria($criteria, $searchAliases);
             if (!empty($foundUsersSid)) {
                 $result = SJB_UsersExportController::createExportDirectories();
                 if ($result === true) {
                     $exportProperties['extUserID'] = 1;
                     $exportProperties['parent_sid'] = 1;
                     $exportAliases = SJB_UsersExportController::getExportPropertyAliases();
                     $exportData = SJB_UsersExportController::getExportData($foundUsersSid, $exportProperties, $exportAliases);
                     $fileName = 'users.xls';
                     SJB_UsersExportController::makeExportFile($exportData, $fileName);
                     if (!file_exists(SJB_System::getSystemSettings('EXPORT_FILES_DIRECTORY') . "/{$fileName}")) {
                         SJB_FlashMessages::getInstance()->addWarning('CANT_CREATE_EXPORT_FILES');
                     } else {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/users/archive-and-send-export-data/");
                     }
                 }
             } else {
                 SJB_FlashMessages::getInstance()->addWarning('EMPTY_EXPORT_DATA');
             }
         }
     }
     $userSystemProperties = SJB_UserManager::getAllUserSystemProperties();
     $userGroups = SJB_UserGroupManager::getAllUserGroupsInfo();
     $userCommonProperties = array();
     foreach ($userGroups as $userGroup) {
         $userGroupProperties = SJB_UserProfileFieldManager::getFieldsInfoByUserGroupSID($userGroup['sid']);
         $userCommonProperties[$userGroup['id']] = $userGroupProperties;
     }
     $tp->assign('userSystemProperties', $userSystemProperties);
     $tp->assign('userCommonProperties', $userCommonProperties);
     $tp->assign('selected_user_group_id', $userGroupID);
     $tp->display('export_users.tpl');
 }
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $user_group_sid = SJB_Request::getVar('user_group_sid', null);
     $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
     $errors = null;
     if (!is_null($user_group_sid)) {
         if (isset($_REQUEST['action'], $_REQUEST['field_sid'])) {
             if ($_REQUEST['action'] == 'move_up') {
                 SJB_UserProfileFieldManager::moveUpFieldBySID($_REQUEST['field_sid']);
             } elseif ($_REQUEST['action'] == 'move_down') {
                 SJB_UserProfileFieldManager::moveDownFieldBySID($_REQUEST['field_sid']);
             }
         }
         $user_profile_fields = SJB_UserProfileFieldManager::getFieldsInfoByUserGroupSID($user_group_sid);
     } else {
         $errors['USER_GROUP_SID_NOT_SET'] = 1;
         $user_profile_fields = null;
     }
     $tp->assign("errors", $errors);
     $tp->assign("user_profile_fields", $user_profile_fields);
     $tp->assign("user_group_sid", $user_group_sid);
     $tp->assign("user_group_info", $user_group_info);
     $tp->display("edit_user_profile_fields.tpl");
 }
 public static function getUserProfileFieldIDBySID($user_profile_field_sid)
 {
     $user_profile_field_info = SJB_UserProfileFieldManager::getFieldInfoBySID($user_profile_field_sid);
     if (empty($user_profile_field_info)) {
         return null;
     }
     return $user_profile_field_info['id'];
 }
Beispiel #8
0
 public static function deleteUserGroupBySID($user_group_sid)
 {
     $user_profile_fields_info = SJB_UserProfileFieldManager::getFieldsInfoByUserGroupSID($user_group_sid);
     foreach ($user_profile_fields_info as $user_profile_field_info) {
         SJB_UserProfileFieldManager::deleteUserProfileFieldBySID($user_profile_field_info['sid']);
     }
     SJB_DB::query('DELETE FROM `products` WHERE `user_group_sid` = ?n', $user_group_sid);
     return SJB_UserGroupDBManager::deleteUserGroupInfo($user_group_sid);
 }
 public function execute()
 {
     $user_profile_field_sid = SJB_Request::getVar('sid', null);
     if (!is_null($user_profile_field_sid)) {
         $user_profile_field_info = SJB_UserProfileFieldManager::getFieldInfoBySID($user_profile_field_sid);
         SJB_UserProfileFieldManager::deleteUserProfileFieldBySID($user_profile_field_sid);
         $user_group_sid = $user_profile_field_info['user_group_sid'];
         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/edit-user-profile/?user_group_sid=' . $user_group_sid);
     } else {
         echo 'The system  cannot proceed as User Group SID is not set';
     }
 }
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $user_field_sid = SJB_Request::getVar('user_field_sid', null);
     $errors = array();
     if (!is_null($user_field_sid)) {
         $profile_field = SJB_UserProfileFieldManager::getFieldInfoBySID($user_field_sid);
         $profile_field['user_group'] = SJB_UserGroupManager::getUserGroupIDBySID($profile_field['user_group_sid']);
         $tp->assign('fieldInfo', $profile_field);
     } else {
         $errors[] = 'The system cannot proceed as some required parameters are not set';
     }
     $tp->assign('errors', $errors);
     $tp->display('instruction_user_profile_field.tpl');
 }
Beispiel #11
0
 function getPropertyVariablesToAssign()
 {
     $propertyVariables = parent::getPropertyVariablesToAssign();
     $profileFieldAsDv = SJB_Array::get($propertyVariables, 'profile_field_as_dv');
     if ($profileFieldAsDv && !isset($this->property_info['parentID'])) {
         $fieldValue = SJB_UserProfileFieldManager::getListItemValueBySID($profileFieldAsDv);
         if ($fieldValue) {
             $listingListItemSID = SJB_ListingFieldManager::getListItemSIDByValue($fieldValue, SJB_Array::get($this->property_info, 'sid'));
             $propertyVariables['profile_field_as_dv'] = $listingListItemSID;
         }
     }
     $defaultValue = SJB_Array::get($propertyVariables, 'default_value');
     if ($defaultValue == 'default_country') {
         $propertyVariables['default_value'] = SJB_Settings::getSettingByName('default_country');
     }
     $propertyVariables['hidden'] = $this->property_info['hidden'];
     $newPropertyVariables = array('list_values' => $this->list_values, 'caption' => $this->property_info['caption'], 'sort_by_alphabet' => $this->property_info['sort_by_alphabet']);
     return array_merge($newPropertyVariables, $propertyVariables);
 }
 function getData($values = array())
 {
     $listFieldsInfo = SJB_UserProfileFieldManager::getFieldsInfoByType('list');
     $multilistFieldsInfo = SJB_UserProfileFieldManager::getFieldsInfoByType('multilist');
     $fieldsInfo = array_merge($listFieldsInfo, $multilistFieldsInfo);
     foreach ($fieldsInfo as $key => $fieldInfo) {
         if ($fieldInfo['user_group_sid'] == $this->user_group && empty($fieldInfo['parent_sid'])) {
             $fieldsInfo[$fieldInfo['id']] = $fieldInfo;
         }
         unset($fieldsInfo[$key]);
     }
     $result = array();
     foreach ($this->properties_names as $key => $property_name) {
         if (in_array($property_name, array_keys($fieldsInfo)) && isset($values[$key])) {
             $fieldInfo = SJB_UserProfileFieldManager::getFieldInfoBySID($fieldsInfo[$property_name]['sid']);
             switch ($fieldInfo['type']) {
                 case 'list':
                     foreach ($fieldInfo['list_values'] as $listValues) {
                         if ($listValues['caption'] == $values[$key]) {
                             $result[$property_name] = $listValues['id'];
                             break;
                         }
                     }
                     break;
                 case 'multilist':
                     $multilistValues = explode(',', $values[$key]);
                     $multilistDisplayValues = array();
                     foreach ($fieldInfo['list_values'] as $listValues) {
                         if (in_array($listValues['caption'], $multilistValues)) {
                             $multilistDisplayValues[] = $listValues['id'];
                         }
                     }
                     $result[$property_name] = implode(',', $multilistDisplayValues);
                     break;
             }
         } else {
             $result[$property_name] = isset($values[$key]) ? $values[$key] : null;
         }
     }
     $result = $result + $this->_getTreeValues($values);
     return $result;
 }
 public static function getUserProfileFieldInfoBySID($user_profile_field_sid)
 {
     $field_info = parent::getObjectInfo("user_profile_fields", $user_profile_field_sid);
     if (in_array($field_info['type'], array('list', 'multilist'))) {
         if (!empty($field_info['parent_sid'])) {
             if ($field_info['id'] == 'Country') {
                 $displayAS = !empty($field_info['display_as']) ? $field_info['display_as'] : 'country_name';
                 $field_info['list_values'] = SJB_CountriesManager::getAllCountriesCodesAndNames(true, $displayAS);
             }
         } else {
             $field_info['list_values'] = SJB_UserProfileFieldDBManager::getListValuesBySID($user_profile_field_sid);
         }
     } elseif ($field_info['type'] == 'tree') {
         $field_info['tree_values'] = SJB_UserProfileFieldTreeManager::getTreeValuesBySID($user_profile_field_sid);
         $field_info['tree_depth'] = SJB_UserProfileFieldTreeManager::getTreeDepthBySID($user_profile_field_sid);
     } elseif ($field_info['type'] == 'monetary') {
         $field_info['currency_values'] = SJB_CurrencyManager::getActiveCurrencyList();
     } elseif ($field_info['type'] == 'location') {
         $field_info['fields'] = SJB_UserProfileFieldManager::getUserProfileFieldsInfoByParentSID($user_profile_field_sid);
     }
     return $field_info;
 }
Beispiel #14
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");
    }
 public static function addMultupleTreeItem($item_sid, $node_sid, $tree_item_value, $order, $after_tree_item_sid = '')
 {
     $tree_item_value = str_replace("\r", " ", $tree_item_value);
     $tree_item_value = explode("\n", $tree_item_value);
     $result = true;
     foreach ($tree_item_value as $tree_item) {
         $tree_item = trim($tree_item);
         if ($tree_item != "") {
             if ($order == 'begin') {
                 if (!SJB_UserProfileFieldManager::addTreeItemToBeginByParentSID($item_sid, $node_sid, $tree_item)) {
                     $result = false;
                 }
             } elseif ($order == 'end') {
                 if (!SJB_UserProfileFieldManager::addTreeItemToEndByParentSID($item_sid, $node_sid, $tree_item)) {
                     $result = false;
                 }
             } elseif ($order == 'after') {
                 if (!SJB_UserProfileFieldManager::addTreeItemAfterByParentSID($item_sid, $node_sid, $tree_item, $after_tree_item_sid)) {
                     $result = false;
                 }
             }
         }
     }
     return $result;
 }
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', 'list');
     $fieldSID = SJB_Request::getVar('field_sid', false);
     $parentSID = SJB_Request::getVar('sid', false);
     $userGroupSID = SJB_Request::getVar('user_group_sid', false);
     $errors = null;
     if ($fieldSID) {
         $tp->assign('field_sid', $fieldSID);
         $fieldInfo = SJB_UserProfileFieldManager::getFieldInfoBySID($fieldSID);
         $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($fieldInfo['user_group_sid']);
         $userGroupSID = isset($userGroupInfo['sid']) ? $userGroupInfo['sid'] : 0;
         $tp->assign("field_info", $fieldInfo);
         $tp->assign("group_info", $userGroupInfo);
         $tp->assign("group_sid", $userGroupSID);
         switch ($action) {
             case 'edit':
                 $formSubmitted = SJB_Request::getVar('submit_form', false);
                 $sid = SJB_Request::getVar('sid', false);
                 $userFieldSid = SJB_Request::getVar('sid', 0);
                 $userFieldInfo = SJB_UserProfileFieldDBManager::getUserProfileFieldInfoBySID($userFieldSid);
                 $userFieldInfo = array_merge($userFieldInfo, $_REQUEST);
                 if (!empty($userFieldInfo['default_value_setting']) && $userFieldInfo['default_value_setting'] == 'default_country') {
                     $userFieldInfo['default_value'] = $userFieldInfo['default_value_setting'];
                 }
                 $userField = new SJB_UserProfileField($userFieldInfo);
                 $userField->deleteProperty('type');
                 $userField->addProperty(array('id' => 'hidden', 'caption' => 'Hidden', 'type' => 'boolean', 'value' => isset($userFieldInfo['hidden']) ? $userFieldInfo['hidden'] : '', 'is_system' => true));
                 $additionalParameters = array();
                 if ($userFieldInfo['id'] == 'Country') {
                     $additionalParameters = array('list_values' => SJB_CountriesManager::getAllCountriesCodesAndNames());
                     $userField->addProperty(array('id' => 'display_as', 'caption' => 'Display Country as', 'type' => 'list', 'value' => isset($userFieldInfo['display_as']) ? $userFieldInfo['display_as'] : '', 'list_values' => array(array('id' => 'country_name', 'caption' => 'Country Name'), array('id' => 'country_code', 'caption' => 'Country Code')), 'is_system' => true, 'is_required' => true));
                 } elseif ($userFieldInfo['id'] == 'State') {
                     $defaultCountry = SJB_UserProfileFieldManager::getDefaultCountryByParentSID($fieldSID);
                     $additionalParameters['list_values'] = SJB_StatesManager::getStatesNamesByCountry($defaultCountry);
                     $additionalParameters['comment'] = !$defaultCountry ? 'Please select default country first to select default State' : '';
                     $userField->addProperty(array('id' => 'display_as', 'caption' => 'Display State as', 'type' => 'list', 'value' => isset($userFieldInfo['display_as']) ? $userFieldInfo['display_as'] : '', 'list_values' => array(array('id' => 'state_name', 'caption' => 'State Name'), array('id' => 'state_code', 'caption' => 'State Code')), 'is_system' => true, 'is_required' => true));
                 }
                 $defaultValue = array('id' => 'default_value', 'sid' => isset($userFieldInfo['sid']) ? $userFieldInfo['sid'] : '', 'caption' => 'Default Value', 'value' => isset($userFieldInfo['default_value']) ? $userFieldInfo['default_value'] : '', 'type' => $userField->field_type, 'length' => '', 'is_required' => false, 'is_system' => true);
                 $defaultValue = array_merge($defaultValue, $additionalParameters);
                 $userField->addProperty($defaultValue);
                 if ($formSubmitted) {
                     $userField->addInfillInstructions(SJB_Request::getVar('instructions'));
                 } else {
                     $userField->addInfillInstructions(isset($userFieldInfo['instructions']) ? $userFieldInfo['instructions'] : '');
                 }
                 $UserFieldForm = new SJB_Form($userField);
                 $UserFieldForm->registerTags($tp);
                 $userField->setSID($sid);
                 $userField->setUserGroupSID($userGroupSID);
                 $addValidParam = array('field' => 'parent_sid', 'value' => $parentSID);
                 if ($formSubmitted && $UserFieldForm->isDataValid($errors, $addValidParam)) {
                     SJB_UserProfileFieldManager::saveUserProfileField($userField);
                     if (SJB_Request::getVar('apply') == 'no' && empty($errors)) {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/edit-user-profile-field/edit-location-fields/?field_sid=" . $fieldSID);
                     }
                 }
                 $UserFieldForm->makeDisabled('id');
                 $tp->assign('profileFieldAsDV', !empty($userFieldInfo['profile_field_as_dv']));
                 $tp->assign('userFieldInfo', $userFieldInfo);
                 $tp->assign("field_type", $userField->getFieldType());
                 $tp->assign("sid", $userFieldSid);
                 $tp->assign("form_fields", $UserFieldForm->getFormFieldsInfo());
                 $tp->assign("errors", $errors);
                 $tp->display("edit_location_field.tpl");
                 break;
             case 'move_up':
                 SJB_UserProfileFieldManager::moveUpFieldBySID($fieldSID);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-user-profile-field/edit-location-fields/?field_sid=" . $parentSID);
                 break;
             case 'move_down':
                 SJB_UserProfileFieldManager::moveDownFieldBySID($fieldSID);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-user-profile-field/edit-location-fields/?field_sid=" . $parentSID);
                 break;
         }
         if ($action == 'list') {
             $userFieldsInfo = SJB_UserProfileFieldManager::getUserProfileFieldsInfoByParentSID($fieldSID);
             $userFields = array();
             $userFieldSids = array();
             foreach ($userFieldsInfo as $userFieldInfo) {
                 $userField = new SJB_UserProfileField($userFieldInfo);
                 $userField->addProperty(array('id' => 'hidden', 'caption' => 'Hidden', 'type' => 'boolean', 'value' => isset($userFieldInfo['hidden']) ? $userFieldInfo['hidden'] : '', 'is_system' => true));
                 $userField->setSID($userFieldInfo['sid']);
                 $userFields[] = $userField;
                 $userFieldSids[] = $userFieldInfo['sid'];
             }
             $form_collection = new SJB_FormCollection($userFields);
             $form_collection->registerTags($tp);
             $tp->assign("user_field_sids", $userFieldSids);
             $tp->assign("user_group_sid", $userGroupSID);
             $tp->display("user_location_fields.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;
 }
Beispiel #18
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $parent_name = null;
     $user_sid = SJB_Request::getVar('user_sid', false);
     if (!is_null($user_sid)) {
         $user_info = SJB_UserManager::getUserInfoBySID($user_sid);
         $user_info = array_merge($user_info, $_REQUEST);
         $form_submitted = SJB_Request::getVar('action_name');
         $user = new SJB_User($user_info, $user_info['user_group_sid']);
         if (!empty($user_info['parent_sid'])) {
             $props = $user->getProperties();
             $allowedProperties = array('username', 'email', 'password');
             foreach ($props as $prop) {
                 if (!in_array($prop->getID(), $allowedProperties)) {
                     $user->deleteProperty($prop->getID());
                 }
             }
             $parent_name = SJB_UserManager::getUserNameByUserSID($user_info['parent_sid']);
         }
         $user->setSID($user_info['sid']);
         $user->getProperty('email')->type->disableEmailConfirmation();
         $user->deleteProperty("active");
         $user->makePropertyNotRequired("password");
         if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_info['user_group_sid'])) {
             if ($form_submitted) {
                 $email = $user->getPropertyValue('email');
                 if (is_array($email)) {
                     $email = $email['original'];
                 }
                 $user->setPropertyValue('username', $email);
             }
         }
         $user->addExtUserIDProperty($user_info['extUserID']);
         $edit_user_form = new SJB_Form($user);
         $errors = array();
         if ($form_submitted && $edit_user_form->isDataValid($errors)) {
             $password_value = $user->getPropertyValue('password');
             $properties = null;
             if (empty($password_value['original'])) {
                 $properties = $user->getProperties();
                 $user->deleteProperty('password');
             }
             SJB_UserManager::saveUser($user);
             // >>> SJB-1197
             // needs to check session for ajax-uploaded files, and set it to user profile
             $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
             $formToken = SJB_Request::getVar('form_token');
             if (!empty($formToken)) {
                 $tmpUploadedFields = SJB_Array::getPath($tmpUploadsStorage, $formToken);
                 if (!is_null($tmpUploadsStorage) && is_array($tmpUploadedFields)) {
                     // prepare user profile fields array
                     $userProfileFieldsInfo = SJB_UserProfileFieldManager::getAllFieldsInfo();
                     $userProfileFields = array();
                     foreach ($userProfileFieldsInfo as $field) {
                         $userProfileFields[$field['id']] = $field;
                     }
                     // look for temporary values
                     foreach ($tmpUploadedFields as $fieldId => $fieldInfo) {
                         // check field ID for valid ID in user profile fields
                         if (!array_key_exists($fieldId, $userProfileFields) || empty($fieldInfo)) {
                             continue;
                         }
                         $fieldType = $userProfileFields[$fieldId]['type'];
                         $profilePropertyId = $fieldId . '_' . $user->getSID();
                         switch (strtolower($fieldType)) {
                             case 'video':
                             case 'file':
                                 // change temporary file ID
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
                                 // set value of user property to new uploaded file
                                 $user->setPropertyValue($fieldId, $profilePropertyId);
                                 break;
                             case 'logo':
                                 // change temporary file ID and thumb ID
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId . '_thumb', $fieldInfo['file_id'] . '_thumb');
                                 // set value of user property to new uploaded file
                                 $user->setPropertyValue($fieldId, $profilePropertyId);
                                 break;
                             default:
                                 break;
                         }
                         $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}/{$fieldId}");
                     }
                     // and save user with new fields data
                     SJB_UserManager::saveUser($user);
                     SJB_Authorization::updateCurrentUserSession();
                     // clean temporary storage
                     $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}");
                     // CLEAR TEMPORARY SESSION STORAGE
                     SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
                 }
             }
             // <<< SJB-1197
             if (SJB_Request::isAjax()) {
                 echo "<p class=\"green\">User Saved</p>";
                 exit;
             }
             if ($form_submitted == 'save_info') {
                 $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($user_info['user_group_sid']);
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-users/" . mb_strtolower($userGroupInfo['id'], 'utf8'));
             }
             if (!empty($properties)) {
                 $user->details->properties = $properties;
             }
         }
         if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_info['user_group_sid'])) {
             $user->deleteProperty("username");
         }
         $listingTypes = SJB_ListingTypeManager::getAllListingTypesInfo();
         $products = SJB_ProductsManager::getProductsInfoByUserGroupSID($user_info['user_group_sid']);
         $allowedListingTypes = array();
         foreach ($products as $product) {
             if (!empty($product['listing_type_sid']) && empty($allowedListingTypes[$product['listing_type_sid']])) {
                 foreach ($listingTypes as $listingType) {
                     if ($product['listing_type_sid'] == $listingType['sid']) {
                         $allowedListingTypes[$product['listing_type_sid']] = $listingType;
                     }
                 }
             }
         }
         $edit_user_form = SJB_ObjectMother::createForm($user);
         $edit_user_form->registerTags($tp);
         $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($user_info['user_group_sid']);
         if (SJB_UserManager::checkBan($errors, $user_info['ip'])) {
             $user_info['ip_is_banned'] = 1;
         }
         $tp->assign("form_fields", $edit_user_form->getFormFieldsInfo());
         $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
         $tp->assign("errors", $errors);
         $tp->assign("listingTypes", $allowedListingTypes);
         $tp->assign("user_info", $user_info);
         $tp->assign("user_group_info", $userGroupInfo);
         $tp->assign('userTree', true);
         $tp->assign("parent_name", $parent_name);
         $tp->assign("restore", preg_match('/manage-(jobseekers)|(employers)|([a-z0-9\\_]-users)/', SJB_Request::getVar('HTTP_REFERER', '', 'SERVER')));
         SJB_System::setGlobalTemplateVariable('wikiExtraParam', $userGroupInfo['id']);
         $tp->display("edit_user.tpl");
     }
 }
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $listing_field_sid = SJB_Request::getVar('sid', null);
     if (!is_null($listing_field_sid)) {
         $listingFieldInfo = SJB_ListingFieldManager::getFieldInfoBySID($listing_field_sid);
         $old_listing_field_id = $listingFieldInfo['id'];
         $listingFieldInfo = array_merge($listingFieldInfo, $_REQUEST);
         $listing_field = new SJB_ListingField($listingFieldInfo, $listingFieldInfo['listing_type_sid']);
         $listing_field->setSID($listing_field_sid);
         $formSubmitted = SJB_Request::getVar('action', '');
         if (!in_array($listing_field->field_type, array('video', 'picture', 'file', 'complex'))) {
             $profileField = SJB_Request::getVar('profile_field', false);
             if ($formSubmitted) {
                 if ($profileField) {
                     $listingFieldInfo['default_value'] = '';
                 } else {
                     $listingFieldInfo['profile_field_as_dv'] = '';
                 }
             }
             $default_value = array('id' => 'default_value', 'sid' => isset($listingFieldInfo['sid']) ? $listingFieldInfo['sid'] : '', 'caption' => 'Default Value', 'value' => isset($listingFieldInfo['default_value']) ? $listingFieldInfo['default_value'] : '', 'type' => $listing_field->field_type, 'length' => '', 'is_required' => false, 'is_system' => true);
             $additionalParameters = array();
             switch ($listing_field->field_type) {
                 case 'list':
                     if (isset($listingFieldInfo['list_values'])) {
                         $additionalParameters = array('list_values' => $listingFieldInfo['list_values']);
                     }
                     break;
                 case 'multilist':
                     if (isset($listingFieldInfo['list_values'])) {
                         $additionalParameters = array('list_values' => $listingFieldInfo['list_values']);
                     }
                     if (!is_array($default_value['value'])) {
                         if (strpos($default_value['value'], ',')) {
                             $default_value['value'] = explode(',', $default_value['value']);
                         } else {
                             $default_value['value'] = array($default_value['value']);
                         }
                     }
                     break;
                 case 'tree':
                     if (isset($listingFieldInfo['tree_values'])) {
                         $additionalParameters = array('tree_values' => $listingFieldInfo['tree_values']);
                     }
                     break;
                 case 'monetary':
                     if (isset($listingFieldInfo['currency_values'])) {
                         $default_value['currency_values'] = $listingFieldInfo['currency_values'];
                     }
                     break;
             }
             $default_value = array_merge($default_value, $additionalParameters);
             $listing_field->addProperty($default_value);
             $user_groups = SJB_UserGroupManager::getAllUserGroupsInfo();
             $list_values = array();
             foreach ($user_groups as $user_group) {
                 $list_values = array_merge($list_values, SJB_UserProfileFieldManager::getFieldsInfoByUserGroupSID($user_group['sid']));
             }
             $profile_field_as_dv = array('id' => 'profile_field_as_dv', 'caption' => 'Default Value', 'value' => isset($listingFieldInfo['profile_field_as_dv']) ? $listingFieldInfo['profile_field_as_dv'] : '', 'type' => 'list', 'list_values' => $list_values, 'length' => '', 'is_required' => false, 'is_system' => true);
             $listing_field->addProperty($profile_field_as_dv);
             if (in_array($listing_field->field_type, array('tree', 'multilist', 'list'))) {
                 $sort_by_alphabet = array('id' => 'sort_by_alphabet', 'caption' => 'Sort Values By Alphabet', 'value' => isset($listingFieldInfo['sort_by_alphabet']) ? $listingFieldInfo['sort_by_alphabet'] : '', 'type' => 'boolean', 'lenght' => '', 'is_required' => false, 'is_system' => true);
                 $listing_field->addProperty($sort_by_alphabet);
             }
             $tp->assign('profileFieldAsDV', !empty($listingFieldInfo['profile_field_as_dv']));
         }
         if (in_array($listing_field->field_type, array('multilist', 'list'))) {
             $listing_field->addDisplayAsProperty($listingFieldInfo['display_as']);
         }
         // infil instructions should be the last element in form
         if (!in_array($listing_field->getFieldType(), array('complex', 'tree', 'location')) && 'ApplicationSettings' != $listing_field->getPropertyValue('id')) {
             if ($formSubmitted) {
                 $listing_field->addInfillInstructions(SJB_Request::getVar('instructions'));
             } else {
                 $listing_field->addInfillInstructions(isset($listingFieldInfo['instructions']) ? $listingFieldInfo['instructions'] : '');
             }
         }
         /**
          * "Display as" options for TREE TYPE
          */
         if ('tree' == $listing_field->getFieldType()) {
             $listing_field->addProperty(SJB_TreeType::getDisplayAsDetail(isset($listingFieldInfo['display_as_select_boxes']) ? $listingFieldInfo['display_as_select_boxes'] : ''));
             $treeLevelsNumber = SJB_ListingFieldTreeManager::getTreeDepthBySID($listing_field_sid);
             $tp->assign('tree_levels_number', $treeLevelsNumber);
             // treee levels captions
             for ($i = 1; $i <= $treeLevelsNumber; $i++) {
                 $levelID = 'level_' . $i;
                 $listing_field->addProperty(array('id' => $levelID, 'caption' => $i . ' Level Name', 'value' => isset($listingFieldInfo[$levelID]) ? $listingFieldInfo[$levelID] : '', 'type' => 'string', 'length' => '250', 'is_required' => false, 'is_system' => true));
             }
         }
         /*
          * end of ""Display as" options for TREE TYPE"
          */
         $edit_form = new SJB_Form($listing_field);
         $edit_form->makeDisabled("type");
         $errors = array();
         if ($formSubmitted && $edit_form->isDataValid($errors)) {
             SJB_ListingFieldManager::saveListingField($listing_field);
             SJB_ListingFieldManager::changeListingPropertyIDs($listingFieldInfo['id'], $old_listing_field_id);
             if ($formSubmitted == 'save_info') {
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/edit-listing-type/?sid=" . $listing_field->getListingTypeSID());
             }
         }
         $edit_form->registerTags($tp);
         $tp->assign("form_fields", $edit_form->getFormFieldsInfo());
         $tp->assign("errors", $errors);
         $tp->assign("listing_type_sid", $listing_field->getListingTypeSID());
         $tp->assign("field_type", $listing_field->getFieldType());
         $tp->assign("field_sid", $listing_field->getSID());
         $listing_type_info = SJB_ListingTypeManager::getListingTypeInfoBySID($listing_field->getListingTypeSID());
         $tp->assign("listing_type_info", $listing_type_info);
         $tp->assign("listing_field_info", $listingFieldInfo);
         $tp->display("edit_listing_type_field.tpl");
     }
 }
Beispiel #20
0
 public function execute()
 {
     $listing_field_sid = SJB_Request::getVar('sid', null);
     $tp = SJB_System::getTemplateProcessor();
     if (!is_null($listing_field_sid)) {
         $listing_field_info = SJB_ListingFieldManager::getFieldInfoBySID($listing_field_sid);
         $listing_field_info = array_merge($listing_field_info, $_REQUEST);
         $listing_field = new SJB_ListingField($listing_field_info);
         $listing_field->setSID($listing_field_sid);
         $form_submitted = SJB_Request::getVar('action', '');
         if (!in_array($listing_field->field_type, array('video', 'picture', 'file', 'complex'))) {
             $profile_field = SJB_Request::getVar('profile_field', false);
             if ($form_submitted) {
                 if ($profile_field) {
                     $listing_field_info['default_value'] = '';
                 } else {
                     $listing_field_info['profile_field_as_dv'] = '';
                 }
             }
             $default_value = array();
             if ($listing_field->field_type != 'location') {
                 $default_value = array('id' => 'default_value', 'sid' => isset($listing_field_info['sid']) ? $listing_field_info['sid'] : '', 'caption' => 'Default Value', 'value' => isset($listing_field_info['default_value']) ? $listing_field_info['default_value'] : '', 'type' => $listing_field->field_type, 'length' => '', 'is_required' => false, 'is_system' => true, 'add_parameter' => isset($listing_field_info['add_parameter']) ? $listing_field_info['add_parameter'] : '');
             }
             switch ($listing_field->field_type) {
                 case 'list':
                     if (isset($listing_field_info['list_values'])) {
                         $default_value['list_values'] = $listing_field_info['list_values'];
                     }
                     break;
                 case 'multilist':
                     if (isset($listing_field_info['list_values'])) {
                         $default_value['list_values'] = $listing_field_info['list_values'];
                     }
                     if (!is_array($default_value['value'])) {
                         if (strpos($default_value['value'], ',')) {
                             $default_value['value'] = explode(',', $default_value['value']);
                         } else {
                             $default_value['value'] = array($default_value['value']);
                         }
                     }
                     break;
                 case 'tree':
                     if (isset($listing_field_info['tree_values'])) {
                         $default_value['tree_values'] = $listing_field_info['tree_values'];
                     }
                     if (isset($listing_field_info['display_as_select_boxes'])) {
                         $default_value['display_as_select_boxes'] = $listing_field_info['display_as_select_boxes'];
                     }
                     unset($listing_field_info['choiceLimit']);
                     break;
                 case 'monetary':
                     if (isset($listing_field_info['currency_values'])) {
                         $default_value['currency_values'] = $listing_field_info['currency_values'];
                     }
                     break;
             }
             if ($listing_field->field_type != 'location') {
                 $listing_field->addProperty($default_value);
                 $profile_field_as_dv = array('id' => 'profile_field_as_dv', 'caption' => 'Default Value', 'value' => isset($listing_field_info['profile_field_as_dv']) ? $listing_field_info['profile_field_as_dv'] : '', 'type' => 'list', 'list_values' => SJB_UserProfileFieldManager::getAllFieldsInfo(), 'length' => '', 'is_required' => false, 'is_system' => true);
                 $listing_field->addProperty($profile_field_as_dv);
             }
             if (in_array($listing_field->field_type, array('tree', 'multilist', 'list'))) {
                 $sort_by_alphabet = array('id' => 'sort_by_alphabet', 'caption' => 'Sort Values By Alphabet', 'value' => isset($listing_field_info['sort_by_alphabet']) ? $listing_field_info['sort_by_alphabet'] : '', 'type' => 'boolean', 'lenght' => '', 'is_required' => false, 'is_system' => true);
                 $listing_field->addProperty($sort_by_alphabet);
             }
             $tp->assign('profileFieldAsDV', !empty($listing_field_info['profile_field_as_dv']));
         }
         if (in_array($listing_field->field_type, array('multilist', 'list'))) {
             $listing_field->addDisplayAsProperty($listing_field_info['display_as']);
         }
         // infil instructions should be the last element in form
         if (!in_array($listing_field->getFieldType(), array('complex', 'tree', 'location'))) {
             if ($form_submitted) {
                 $listing_field->addInfillInstructions(SJB_Request::getVar('instructions'));
             } else {
                 $listing_field->addInfillInstructions(isset($listing_field_info['instructions']) ? $listing_field_info['instructions'] : '');
             }
         }
         if ('tree' == $listing_field->getFieldType()) {
             $listing_field->addProperty(SJB_TreeType::getDisplayAsDetail(isset($listing_field_info['display_as_select_boxes']) ? $listing_field_info['display_as_select_boxes'] : ''));
             $treeLevelsNumber = SJB_ListingFieldTreeManager::getTreeDepthBySID($listing_field_sid);
             $tp->assign('tree_levels_number', $treeLevelsNumber);
             // treee levels captions
             for ($i = 1; $i <= $treeLevelsNumber; $i++) {
                 $levelID = 'level_' . $i;
                 $listing_field->addProperty(array('id' => $levelID, 'caption' => $i . ' Level Name', 'value' => isset($listing_field_info[$levelID]) ? $listing_field_info[$levelID] : '', 'type' => 'string', 'length' => '250', 'is_required' => false, 'is_system' => true));
             }
         }
         $edit_form = new SJB_Form($listing_field);
         $errors = array();
         if ($form_submitted && $edit_form->isDataValid($errors)) {
             $old_listing_field_id = SJB_Request::getVar('old_listing_field_id', null);
             SJB_ListingFieldManager::saveListingField($listing_field);
             SJB_ListingFieldManager::changeListingPropertyIDs($listing_field_info['id'], $old_listing_field_id);
             if ($form_submitted == 'save_info') {
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/listing-fields/');
             }
         }
         $edit_form->registerTags($tp);
         $edit_form->makeDisabled('type');
         if ($listing_field_info['id'] == 'Location' && empty($errors['ID'])) {
             $edit_form->makeDisabled('id');
         }
         $tp->assign('object_sid', $listing_field);
         $tp->assign('form_fields', $edit_form->getFormFieldsInfo());
         $tp->assign('errors', $errors);
         $tp->assign('field_type', $listing_field->getFieldType());
         $tp->assign('listing_field_info', $listing_field_info);
         $tp->assign('field_sid', $listing_field_sid);
         $tp->display('edit_listing_field.tpl');
     }
 }
Beispiel #21
0
 private function extraProperties($user, $userInfo, &$usersID)
 {
     $savedProperties = array('user_group' => 1, 'pictures' => 1);
     foreach ($user->getProperties() as $property) {
         if (!in_array($property->id, array('file', 'Logo', 'video'))) {
             $savedProperties[$property->id] = 1;
         }
     }
     $queryFields = '';
     foreach (array_diff_key($userInfo, $savedProperties) as $key => $value) {
         if ($key == 'id') {
             $usersID[$value] = $user->getSID();
             continue;
         }
         if ($key == 'product') {
             $products = $value ? explode(',', $value) : array();
             $i = sizeof($products);
             while (--$i != -1) {
                 $productProperties = @unserialize($products[$i]);
                 if (!$productProperties) {
                     continue;
                 }
                 $productSid = SJB_ProductsManager::getProductSidByName($productProperties['name']);
                 if (!$productSid) {
                     continue;
                 }
                 $contract = new SJB_Contract(array('product_sid' => $productSid, 'numberOfListings' => $productProperties['number_of_listings']));
                 $contract->setPrice($productProperties['price']);
                 $contract->setCreationDate($productProperties['creation_date']);
                 $contract->setExpiredDate($productProperties['expired_date']);
                 $contract->setStatus($productProperties['status']);
                 $contract->setUserSID($user->getSID());
                 $contract->saveInDB();
                 SJB_ContractSQL::updatePostingsNumber($contract->id, $productProperties['number_of_postings']);
                 SJB_ProductsManager::incrementPostingsNumber($productSid, $productProperties['number_of_postings']);
             }
             continue;
         }
         if (in_array($key, array('file', 'Logo', 'video')) && !empty($value)) {
             $property = $user->getProperty($key);
             if (!$property) {
                 continue;
             }
             $fileProperties = @unserialize($value);
             if (!$fileProperties) {
                 continue;
             }
             $fieldInfo = SJB_UserProfileFieldManager::getFieldInfoBySID($property->sid);
             switch ($key) {
                 case 'file':
                     $value = 'Resume_' . $user->getSID();
                     $this->databaseFileRegister('file', $value, $fileProperties['name'] . '.' . $fileProperties['extension'], $fileProperties['mimeType']);
                     break;
                 case 'Logo':
                     $value = 'Logo_' . $user->getSID();
                     $this->databaseFileRegister('pictures', $value, $fileProperties['name'] . '.' . $fileProperties['extension'], $fileProperties['mimeType']);
                     $this->databaseFileRegister('pictures', 'Logo_' . $user->getSID() . '_thumb', $fileProperties['name'] . '_thumb.' . $fileProperties['extension'], $fileProperties['mimeType']);
                     break;
                 case 'video':
                     $value = 'video_' . $user->getSID();
                     $this->databaseFileRegister('video', 'video_' . $user->getSID(), $fileProperties['name'] . '.' . $fileProperties['extension'], $fileProperties['mimeType']);
                     break;
             }
         }
         if ($key == 'registration_date') {
             $isValid = SJB_UserRegistrationDateValidator::isValid($userInfo['registration_date']);
             if ($isValid !== true) {
                 if (!isset($errors['registrationDate'])) {
                     $errors['registrationDate'][] = $isValid;
                 }
                 if (isset($userInfo['username'])) {
                     $errors['registrationDate'][] = $userInfo['username'] . ', ';
                 }
                 continue;
             }
         }
         if (!empty($value)) {
             $queryFields .= $queryFields ? ", `" . SJB_DB::quote($key) . "` = '" . SJB_DB::quote($value) . "'" : "`" . SJB_DB::quote($key) . "` = '" . SJB_DB::quote($value) . "'";
         }
     }
     if (!empty($queryFields)) {
         SJB_DB::queryExec("UPDATE ?w SET " . $queryFields . " WHERE `sid` = ?n", 'users', $user->getSID());
     }
 }
Beispiel #22
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action');
     $field_id = SJB_Request::getVar('field_id', false);
     if ($field_id || $action == 'save_setting') {
         switch ($action) {
             case 'save':
                 $listing_type_sid = SJB_Request::getVar('listing_type_sid', false);
                 $userField = 0;
                 if ($listing_type_sid) {
                     if (strstr($field_id, 'user_')) {
                         $field_id = str_replace('user_', '', $field_id);
                         $userField = 1;
                     }
                     if (!SJB_RefineSearch::getFieldByFieldSIDListingTypeSID($field_id, $listing_type_sid, $userField)) {
                         SJB_RefineSearch::addField($field_id, $listing_type_sid, $userField);
                     }
                 }
                 break;
             case 'save_setting':
                 $listing_type_id = SJB_Request::getVar('listing_type_id', false);
                 $refine_search_items_limit = SJB_Request::getVar('refine_search_items_limit', false);
                 if ($listing_type_id) {
                     $settingValue = SJB_Request::getVar('turn_on_refine_search_' . $listing_type_id, 0);
                     if (SJB_Settings::getSettingByName('turn_on_refine_search_' . $listing_type_id) === false) {
                         SJB_Settings::addSetting('turn_on_refine_search_' . $listing_type_id, $settingValue);
                     } else {
                         SJB_Settings::updateSetting('turn_on_refine_search_' . $listing_type_id, $settingValue);
                     }
                 } elseif ($refine_search_items_limit) {
                     if (SJB_Settings::getSettingByName('refine_search_items_limit') === false) {
                         SJB_Settings::addSetting('refine_search_items_limit', $refine_search_items_limit);
                     } else {
                         SJB_Settings::updateSetting('refine_search_items_limit', $refine_search_items_limit);
                     }
                 }
                 break;
             case 'delete':
                 SJB_RefineSearch::removeField($field_id);
                 break;
             case 'move_up':
                 $listing_type_sid = SJB_Request::getVar('listing_type_sid', false);
                 if ($listing_type_sid) {
                     SJB_RefineSearch::moveUpFieldBySID($field_id, $listing_type_sid);
                 }
                 break;
             case 'move_down':
                 $listing_type_sid = SJB_Request::getVar('listing_type_sid', false);
                 if ($listing_type_sid) {
                     SJB_RefineSearch::moveDownFieldBySID($field_id, $listing_type_sid);
                 }
                 break;
         }
     }
     $listingTypes = SJB_ListingTypeManager::getAllListingTypesInfo();
     foreach ($listingTypes as $key => $listingType) {
         $fields = array_merge(SJB_ListingFieldManager::getCommonListingFieldsInfo(), SJB_ListingFieldManager::getListingFieldsInfoByListingType($listingType['sid']));
         foreach ($fields as $field_key => $field) {
             if ($field['type'] == 'location') {
                 if (is_array($field['fields'])) {
                     $fields = array_merge($fields, $field['fields']);
                 }
             }
             if (!in_array($field['type'], array('list', 'multilist', 'string', 'boolean', 'tree')) || in_array($field['id'], array('ApplicationSettings', 'access_type', 'anonymous', 'screening_questionnaire'))) {
                 foreach ($fields as $fieldKey => $searchField) {
                     if ($searchField['id'] == $field['id']) {
                         unset($fields[$fieldKey]);
                     }
                 }
             }
         }
         $listingTypes[$key]['fields'] = $fields;
         if ($key == 'Job') {
             $userFieldSID = SJB_DB::queryValue("SELECT `sid` FROM `user_profile_fields` WHERE `id` = 'CompanyName'");
             if (!empty($userFieldSID)) {
                 $listingTypes[$key]['user_fields'] = SJB_UserProfileFieldManager::getFieldInfoBySID($userFieldSID);
             }
         }
         $listingTypes[$key]['saved_fields'] = SJB_RefineSearch::getFieldsByListingTypeSID($listingType['sid']);
         $listingTypes[$key]['setting'] = SJB_Settings::getSettingByName('turn_on_refine_search_' . $listingType['id']);
     }
     $tp->assign('refine_search_items_limit', SJB_Settings::getSettingByName('refine_search_items_limit'));
     $tp->assign('listingTypes', $listingTypes);
     $tp->display('refine_search.tpl');
 }
Beispiel #23
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $template = SJB_Request::getVar('display_template');
     $page = 1;
     $searchId = strip_tags(SJB_Request::getVar('searchId', time()));
     if (!empty($_REQUEST["page"])) {
         $page = intval($_REQUEST["page"]);
     }
     $items_per_page = SJB_Request::getVar('companies_per_page', false);
     $listing_type_sid = SJB_ListingTypeManager::getListingTypeSIDByID($_REQUEST["listing_type_id"]);
     $alphabets = SJB_AlphabetManager::getAlphabetsForDisplay();
     $abArr = array();
     foreach ($alphabets as $alphabet) {
         $abArr[] = explode(' ', $alphabet['value']);
     }
     $action = SJB_Request::getVar('action', 'search_form');
     if (SJB_Request::getVar('first_char')) {
         $action = 'search';
         $_REQUEST['CompanyName']['first_char_like'] = SJB_Request::getVar('first_char');
     } elseif (!isset($_REQUEST['CompanyName']) || $_REQUEST['CompanyName']['like'] == '') {
         $_REQUEST['CompanyName']['not_empty'] = true;
     }
     $userGroupSid = SJB_UserGroupManager::getUserGroupSIDByID('Employer');
     $userGroupFields = SJB_UserProfileFieldManager::getFieldsInfoByUserGroupSID($userGroupSid);
     foreach ($userGroupFields as $key => $userGroupField) {
         if ($userGroupField['type'] == 'location') {
             $userGroupFields[$key]['fields'] = array();
             $userGroupFields[$key]['fields'][$userGroupField['sid']] = $userGroupField;
         }
     }
     $user = new SJB_User(array(), $userGroupSid);
     $_REQUEST['active']['equal'] = 1;
     $search_form_builder = new SJB_SearchFormBuilder($user);
     $criteria_saver = new SJB_UserCriteriaSaver($searchId);
     $criteria_saver->setSessionForOrderInfo($_REQUEST);
     if (isset($_REQUEST['searchId'])) {
         $action = 'search';
         $criteria = $criteria_saver->getCriteria();
         if (!empty($_REQUEST['sorting_field'])) {
             unset($criteria['sorting_field']);
         } else {
             $orderInfo = $criteria_saver->getOrderInfo();
             if (!empty($orderInfo['sorting_order'])) {
                 $criteria['sorting_order'] = $orderInfo['sorting_order'];
             }
         }
         $_REQUEST = array_merge($_REQUEST, $criteria);
         if (!$items_per_page) {
             $items_per_page = $criteria_saver->listings_per_page;
         }
     }
     $items_per_page = $items_per_page ? $items_per_page : 10;
     $criteria = $search_form_builder->extractCriteriaFromRequestData(array_merge($_REQUEST, array('username' => array('not_equal' => 'jobg8'))), $user);
     if ($items_per_page) {
         $criteria_saver->setSessionForListingsPerPage($items_per_page);
     }
     $search_form_builder->setCriteria($criteria);
     $search_form_builder->registerTags($tp);
     $form_fields = $search_form_builder->getFormFieldsInfo();
     $tp->assign('form_fields', $form_fields);
     $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
     $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
     $tp->assign('userGroupFields', $userGroupFields);
     $tp->assign('action', $action);
     $tp->assign('alphabets', $abArr);
     if ($action == 'search') {
         $sorting_field = SJB_Request::getVar('sorting_field', false);
         $sorting_order = SJB_Request::getVar('sorting_order', false);
         if (isset($_REQUEST['searchId']) && !$sorting_field) {
             $order_info = $criteria_saver->order_info;
             if ($order_info) {
                 $sorting_field = $order_info['sorting_field'];
                 $sorting_order = $order_info['sorting_order'];
             }
         }
         if (!$sorting_field) {
             $sorting_field = 'CompanyName';
             $sorting_order = 'ASC';
         }
         $inner_join = array();
         if ($sorting_field == 'number_of_jobs') {
             if (SJB_ListingTypeManager::getWaitApproveSettingByListingType($listing_type_sid) == 1) {
                 $count = "sum( if( `listings`.`status` = 'approved', `listings`.`active`, 0 ) )";
             } else {
                 $count = "sum(`listings`.`active`)";
             }
             $inner_join = array('listings' => array('sort_field' => $count, 'noPresix' => true, 'join_field' => 'user_sid', 'join_field2' => 'sid', 'join' => 'LEFT JOIN', 'groupBy' => '`users`.`sid`'));
         } elseif ($sorting_field == 'Location_State') {
             $inner_join = array('states' => array('sort_field' => 'state_name', 'noPresix' => true, 'join_field' => 'sid', 'join_field2' => 'Location_State', 'join' => 'LEFT JOIN'));
         }
         $searcher = new SJB_UserSearcher(false, $sorting_field, $sorting_order, $inner_join, array('limit' => ($page - 1) * $items_per_page, 'num_rows' => $items_per_page));
         $found_users = array();
         $found_users_sids = array();
         $found_users_by_criteria = $searcher->getObjectsByCriteria($criteria, null, array(), true);
         $foundObjectSIDs = $searcher->getFoundObjectSIDs();
         // display search form
         $tp->display($template);
         $criteria_saver->setSession($_REQUEST, $foundObjectSIDs);
         if (count($foundObjectSIDs) > 0) {
             $listingType = SJB_ListingTypeManager::getListingTypeInfoBySID($listing_type_sid);
             $countListings = SJB_ListingDBManager::getActiveAndApproveJobsNumberForUsers($foundObjectSIDs, $listingType);
         }
         foreach ($found_users_by_criteria as $id => $user) {
             $listingsNumber = isset($countListings[$id]) ? $countListings[$id] : 0;
             $user->addProperty(array('id' => 'countListings', 'type' => 'string', 'value' => $listingsNumber));
             if ($user->getProperty('CompanyName')) {
                 $found_users_sids[$user->getSID()] = $user->getSID();
                 $found_users[$id] = $user;
             }
         }
         $usersCount = $searcher->getAffectedRows();
         $form_collection = new SJB_FormCollection($found_users);
         $form_collection->registerTags($tp);
         $pages = array();
         for ($i = $page - 3; $i < $page + 3; $i++) {
             if ($i > 0) {
                 $pages[] = $i;
             }
             if ($i * $items_per_page > $usersCount) {
                 break;
             }
         }
         $totalPages = ceil($usersCount / $items_per_page);
         if (empty($totalPages)) {
             $totalPages = 1;
         }
         if (array_search(1, $pages) === false) {
             array_unshift($pages, 1);
         }
         if (array_search($totalPages, $pages) === false) {
             array_push($pages, $totalPages);
         }
         $tp->assign("sorting_order", $sorting_order);
         $tp->assign("sorting_field", $sorting_field);
         $tp->assign("found_users_sids", $found_users_sids);
         $tp->assign("companies_per_page", $items_per_page);
         $tp->assign("searchId", $searchId);
         $tp->assign("usersCount", $usersCount);
         $tp->assign("current_page", $page);
         $tp->assign("pages_number", $totalPages);
         $tp->display('search_result_company.tpl');
     } else {
         // display search form
         $tp->display($template);
     }
 }
Beispiel #24
0
 /**
  * @param  int $numberOfProfiles
  * @return array
  */
 public static function getFeaturedProfiles($numberOfProfiles)
 {
     $logosInfo = SJB_UserProfileFieldManager::getFieldsInfoByType('logo');
     $logoFields = array();
     foreach ($logosInfo as $logoInfo) {
         if (!empty($logoInfo['id'])) {
             $logoFields[] = " `{$logoInfo['id']}` != '' ";
         }
     }
     $whereLogo = empty($logos) ? '' : 'AND (' . implode(' OR ', $logoFields) . ')';
     $usersInfo = SJB_DB::query("SELECT `sid` FROM `users` WHERE `featured`=1 AND `active`=1 {$whereLogo} ORDER BY RAND() LIMIT 0, ?n", $numberOfProfiles);
     $users = array();
     foreach ($usersInfo as $userInfo) {
         $user = SJB_UserManager::getObjectBySID($userInfo['sid']);
         $users[] = !empty($user) ? SJB_UserManager::createTemplateStructureForUser($user) : null;
     }
     return $users;
 }
Beispiel #25
0
 public function execute()
 {
     $field_sid = isset($_REQUEST['field_sid']) ? $_REQUEST['field_sid'] : null;
     $field_info = SJB_UserProfileFieldManager::getFieldInfoBySID($field_sid);
     $node_sid = isset($_REQUEST['node_sid']) ? $_REQUEST['node_sid'] : 0;
     $user_group_sid = isset($_REQUEST['user_group_sid']) ? $_REQUEST['user_group_sid'] : null;
     $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
     if (empty($field_info)) {
         $errors['INVALID_FIELD_SID'] = 1;
     } else {
         if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'add') {
             $tree_item_value = $_REQUEST['tree_item_value'];
             $order = $_REQUEST['order'];
             if ($tree_item_value == '') {
                 $field_errors['Value'] = 'EMPTY_VALUE';
             } else {
                 if ($order == 'begin') {
                     SJB_UserProfileFieldManager::addTreeItemToBeginByParentSID($field_sid, $node_sid, $tree_item_value);
                 } elseif ($order == 'end') {
                     SJB_UserProfileFieldManager::addTreeItemToEndByParentSID($field_sid, $node_sid, $tree_item_value);
                 } elseif ($order == 'after') {
                     $after_tree_item_sid = $_REQUEST['after_tree_item_sid'];
                     SJB_UserProfileFieldManager::addTreeItemAfterByParentSID($field_sid, $node_sid, $tree_item_value, $after_tree_item_sid);
                 }
                 $treeLevelsNumber = SJB_UserProfileFieldTreeManager::getTreeDepthBySID($field_sid);
                 SJB_UserProfileFieldManager::addLevelField($treeLevelsNumber);
             }
         } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'save') {
             $tree_item_value = $_REQUEST['tree_item_value'];
             if (empty($tree_item_value)) {
                 $field_errors['Value'] = 'EMPTY_VALUE';
             } else {
                 SJB_UserProfileFieldManager::updateTreeItemBySID($node_sid, $tree_item_value);
                 $order = isset($_REQUEST['order']) ? $_REQUEST['order'] : null;
                 if ($order == 'begin') {
                     SJB_UserProfileFieldManager::moveTreeItemToBeginBySID($node_sid);
                 } elseif ($order == 'end') {
                     SJB_UserProfileFieldManager::moveTreeItemToEndBySID($node_sid);
                 } elseif ($order == 'after') {
                     $after_tree_item_sid = $_REQUEST['after_tree_item_sid'];
                     SJB_UserProfileFieldManager::moveTreeItemAfterBySID($node_sid, $after_tree_item_sid);
                 }
             }
         } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
             $item_sid = isset($_REQUEST['item_sid']) ? $_REQUEST['item_sid'] : null;
             SJB_UserProfileFieldManager::deleteTreeItemBySID($item_sid);
         } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'move_up') {
             $item_sid = isset($_REQUEST['item_sid']) ? $_REQUEST['item_sid'] : null;
             SJB_UserProfileFieldManager::moveUpTreeItem($item_sid);
         } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'move_down') {
             $item_sid = isset($_REQUEST['item_sid']) ? $_REQUEST['item_sid'] : null;
             SJB_UserProfileFieldManager::moveDownTreeItem($item_sid);
         } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'add_multiple') {
             $node_sid = isset($_REQUEST['node_sid']) ? SJB_Request::getInt('node_sid') : 0;
             $item_sid = SJB_Request::getVar('field_sid');
             $tree_item_value = SJB_Request::getVar('tree_multiItem_value', false);
             $after_tree_item_sid = SJB_Request::getVar('after_tree_item_sid', 0);
             $order = SJB_Request::getVar('order', false);
             if ($tree_item_value == '') {
                 $field_errors['Value'] = 'EMPTY_VALUE';
             }
             SJB_UserProfileFieldTreeManager::addMultupleTreeItem($item_sid, $node_sid, $tree_item_value, $order, $after_tree_item_sid);
         }
         $tree_items = SJB_UserProfileFieldManager::getTreeValuesByParentSID($field_sid, $node_sid);
         $parent_sid = SJB_UserProfileFieldManager::getTreeParentSID($node_sid);
         $tree_parent_items = SJB_UserProfileFieldManager::getTreeValuesByParentSID($field_sid, $parent_sid);
     }
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign("field_sid", $field_sid);
     $tp->assign("node_sid", $node_sid);
     $tp->assign("user_group_sid", $user_group_sid);
     $tp->assign("user_group_info", $user_group_info);
     $tp->assign("field_info", $field_info);
     $tp->assign("tree_parent_items", $tree_parent_items);
     $tp->assign("tree_items", $tree_items);
     $node_info = SJB_UserProfileFieldManager::getTreeItemInfoBySID($node_sid);
     $node_path = SJB_UserProfileFieldManager::getTreeNodePath($node_sid);
     $node_path[0] = array('caption' => 'Root', 'sid' => 0);
     $node_info['node_path'] = $node_path;
     $tp->assign("node_info", $node_info);
     $current_level = isset($node_info['level']) ? $node_info['level'] : 0;
     $tp->assign("current_level", $current_level);
     $tp->assign("errors", isset($errors) ? $errors : null);
     $tp->assign("field_errors", isset($field_errors) ? $field_errors : null);
     $tp->display("edit_tree.tpl");
 }
Beispiel #26
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $errors = array();
     $registration_form_template = 'registration_form.tpl';
     if (SJB_Authorization::isUserLoggedIn()) {
         $tp->display('already_logged_in.tpl');
         return;
     }
     $tp->assign('terms_of_use_check', SJB_System::getSettingByName('terms_of_use_check'));
     $user_group_id = SJB_Request::getVar('user_group_id', null);
     if (!is_null($user_group_id)) {
         $user_group_sid = SJB_UserGroupManager::getUserGroupSIDByID($user_group_id);
         if (empty($user_group_sid)) {
             $errors['NO_SUCH_USER_GROUP_IN_THE_SYSTEM'] = 1;
         }
     }
     $this->setSessionValueForRedirectAfterRegister();
     if (!is_null($user_group_id) && empty($errors)) {
         $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
         $user = SJB_ObjectMother::createUser($_REQUEST, $user_group_sid);
         if (SJB_Request::isAjax() || 'true' == SJB_Request::getVar('isajaxrequest')) {
             $field = SJB_Request::getVar('type');
             if ('email' == $field) {
                 $user->getProperty($field)->type->disableEmailConfirmation();
             }
             echo $user->getProperty($field)->isValid();
             exit;
         }
         $user->deleteProperty('active');
         $user->deleteProperty('featured');
         $form_submitted = SJB_Request::getVar('action', false) == 'register';
         if (class_exists('MobilePlugin') && MobilePlugin::isMobileThemeOn()) {
             $user->prepareRegistrationFields();
         }
         $registration_form = SJB_ObjectMother::createForm($user);
         $registration_form->registerTags($tp);
         if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_group_sid) && $form_submitted) {
             $email = $user->getPropertyValue('email');
             if (is_array($email)) {
                 $email = $email['original'];
             }
             $user->setPropertyValue('username', $email);
         }
         if ($form_submitted && $registration_form->isDataValid($errors)) {
             $user->deleteProperty('captcha');
             $defaultProduct = SJB_UserGroupManager::getDefaultProduct($user_group_sid);
             SJB_UserManager::saveUser($user);
             SJB_Statistics::addStatistics('addUser', $user->getUserGroupSID(), $user->getSID());
             $availableProductIDs = SJB_ProductsManager::getProductsIDsByUserGroupSID($user_group_sid);
             if ($defaultProduct && in_array($defaultProduct, $availableProductIDs)) {
                 $contract = new SJB_Contract(array('product_sid' => $defaultProduct));
                 $contract->setUserSID($user->getSID());
                 $contract->saveInDB();
             }
             // >>> SJB-1197
             // needs to check session for ajax-uploaded files, and set it to user profile
             $formToken = SJB_Request::getVar('form_token');
             $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
             if (!empty($formToken)) {
                 $tmpUploadedFields = SJB_Array::getPath($tmpUploadsStorage, $formToken);
                 if (!is_null($tmpUploadsStorage) && is_array($tmpUploadedFields)) {
                     // prepare user profile fields array
                     $userProfileFieldsInfo = SJB_UserProfileFieldManager::getAllFieldsInfo();
                     $userProfileFields = array();
                     foreach ($userProfileFieldsInfo as $field) {
                         $userProfileFields[$field['id']] = $field;
                     }
                     // look for temporary values
                     foreach ($tmpUploadedFields as $fieldId => $fieldInfo) {
                         // check field ID for valid ID in user profile fields
                         if (!array_key_exists($fieldId, $userProfileFields) || empty($fieldInfo)) {
                             continue;
                         }
                         $fieldType = $userProfileFields[$fieldId]['type'];
                         $profilePropertyId = $fieldId . '_' . $user->getSID();
                         switch (strtolower($fieldType)) {
                             case 'video':
                             case 'file':
                                 // change temporary file ID
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
                                 // set value of user property to new uploaded file
                                 $user->setPropertyValue($fieldId, $profilePropertyId);
                                 break;
                             case 'logo':
                                 // change temporary file ID and thumb ID
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId . '_thumb', $fieldInfo['file_id'] . '_thumb');
                                 // set value of user property to new uploaded file
                                 $user->setPropertyValue($fieldId, $profilePropertyId);
                                 break;
                             default:
                                 break;
                         }
                         $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}/{$fieldId}");
                     }
                     // save user with new values
                     SJB_UserManager::saveUser($user);
                     // clean temporary storage
                     $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}");
                     // CLEAR TEMPORARY SESSION STORAGE
                     SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
                 }
             }
             // <<< SJB-1197
             // notifying administrator
             SJB_AdminNotifications::sendAdminUserRegistrationLetter($user);
             // Activation
             $isSendActivationEmail = SJB_UserGroupManager::isSendActivationEmail($user_group_sid);
             $isApproveByAdmin = SJB_UserGroupManager::isApproveByAdmin($user_group_sid);
             if ($isApproveByAdmin) {
                 SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending');
             }
             if ($isSendActivationEmail) {
                 $fromAnonymousShoppingCart = SJB_Session::getValue('fromAnonymousShoppingCart');
                 SJB_Session::unsetValue('fromAnonymousShoppingCart');
                 $isSent = SJB_Notifications::sendUserActivationLetter($user->getSID(), $fromAnonymousShoppingCart ? true : false);
                 if ($isSent) {
                     $registration_form_template = 'registration_confirm.tpl';
                 } else {
                     SJB_FlashMessages::getInstance()->addWarning('ERROR_SEND_ACTIVATION_EMAIL');
                     $registration_form_template = 'registration_failed_to_send_activation_email.tpl';
                 }
             } else {
                 if (!$isSendActivationEmail && $isApproveByAdmin) {
                     SJB_UserManager::setApprovalStatusByUserName($user->getUserName(), 'Pending');
                     $registration_form_template = 'registration_pending.tpl';
                 } else {
                     SJB_UserManager::activateUserByUserName($user->getUserName());
                     if (!SJB_SocialPlugin::getProfileSocialID($user->getSID())) {
                         SJB_Notifications::sendUserWelcomeLetter($user->getSID());
                     }
                     SJB_Authorization::login($user->getUserName(), $_REQUEST['password']['original'], false, $errors);
                     $proceedToPosting = SJB_Session::getValue('proceed_to_posting');
                     if ($proceedToPosting) {
                         $redirectUrl = SJB_HelperFunctions::getSiteUrl() . '/add-listing/?listing_type_id=' . SJB_Session::getValue('listing_type_id') . '&proceed_to_posting=' . $proceedToPosting . '&productSID=' . SJB_Session::getValue('productSID');
                     } else {
                         $pageId = !empty($user_group_info['after_registration_redirect_to']) ? $user_group_info['after_registration_redirect_to'] : '';
                         $redirectUrl = SJB_UserGroupManager::getRedirectUrlByPageID($pageId);
                     }
                     SJB_HelperFunctions::redirect($redirectUrl);
                 }
             }
         } else {
             if (SJB_UserGroupManager::isUserEmailAsUsernameInUserGroup($user_group_sid)) {
                 $user->deleteProperty('username');
             }
             $registration_form = SJB_ObjectMother::createForm($user);
             $registration_form->registerTags($tp);
             $registration_form_template = 'registration_form.tpl';
             if (isset($_REQUEST['reg_form_template'])) {
                 $registration_form_template = $_REQUEST['reg_form_template'];
             } elseif (!empty($user_group_info['reg_form_template'])) {
                 $registration_form_template = $user_group_info['reg_form_template'];
             }
             $form_fields = $registration_form->getFormFieldsInfo();
             // define default template with ajax checking
             $registration_form->setDefaultTemplateByFieldName('email', 'email_ajaxchecking.tpl');
             $registration_form->setDefaultTemplateByFieldName('username', 'unique_string.tpl');
             // use specific template for user profile video
             $registration_form->setDefaultTemplateByFieldName('video', 'video_profile.tpl');
             $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
             $tp->assign('user_group_info', $user_group_info);
             $tp->assign('errors', $errors);
             $tp->assign('form_fields', $form_fields);
             $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
             $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields)));
         }
     } else {
         $registration_form_template = 'registration_choose_user_group.tpl';
         $user_groups_info = SJB_UserGroupManager::getAllUserGroupsInfo();
         $tp->assign('user_groups_info', $user_groups_info);
     }
     $tp->assign('userTree', true);
     $tp->assign('errors', $errors);
     $tp->display($registration_form_template);
 }
Beispiel #27
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $user_info = SJB_Authorization::getCurrentUserInfo();
     if (!empty($user_info['subuser'])) {
         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/sub-accounts/edit/?user_id=' . $user_info['subuser']['sid']);
     }
     if (!empty($user_info)) {
         $user_info = array_merge($user_info, $_REQUEST);
         $username = $user_info['username'];
         $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_info['user_group_sid']);
         $delete_profile = SJB_Request::getVar('command', '', 'post') == 'unregister-user';
         $errors = array();
         if ($delete_profile && SJB_Acl::getInstance()->isAllowed('delete_user_profile')) {
             try {
                 $user = SJB_UserManager::getObjectBySID($user_info['sid']);
                 SJB_UserManager::deleteUserById($user_info['sid']);
                 SJB_AdminNotifications::sendAdminDeletingUserProfile($user, SJB_Request::getVar('reason', '', 'post'));
                 SJB_Authorization::logout();
                 $user_info = array();
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/edit-profile/?profile_deleted=true');
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
             }
         }
         $user = new SJB_User($user_info, $user_info['user_group_sid']);
         $user->setSID($user_info['sid']);
         $user->deleteProperty("active");
         $user->deleteProperty("featured");
         $user->makePropertyNotRequired("password");
         $user->getProperty('email')->type->disableEmailConfirmation();
         $edit_profile_form = new SJB_Form($user);
         $edit_profile_form->registerTags($tp);
         $edit_profile_form->makeDisabled("username");
         $form_submitted = SJB_Request::getVar('action', false) == 'save_info';
         if ($form_submitted && $edit_profile_form->isDataValid($errors)) {
             $password_value = $user->getPropertyValue('password');
             if (empty($password_value['original'])) {
                 $user->deleteProperty('password');
             }
             SJB_UserManager::saveUser($user);
             SJB_Authorization::updateCurrentUserSession();
             // >>> SJB-1197
             // needs to check session for ajax-uploaded files, and set it to user profile
             $tmpUploadsStorage = SJB_Session::getValue('tmp_uploads_storage');
             $formToken = SJB_Request::getVar('form_token');
             if (!empty($formToken)) {
                 $tmpUploadedFields = SJB_Array::getPath($tmpUploadsStorage, $formToken);
                 if (!is_null($tmpUploadsStorage) && is_array($tmpUploadedFields)) {
                     // prepare user profile fields array
                     $userProfileFieldsInfo = SJB_UserProfileFieldManager::getAllFieldsInfo();
                     $userProfileFields = array();
                     foreach ($userProfileFieldsInfo as $field) {
                         $userProfileFields[$field['id']] = $field;
                     }
                     // look for temporary values
                     foreach ($tmpUploadedFields as $fieldId => $fieldInfo) {
                         // check field ID for valid ID in user profile fields
                         if (!array_key_exists($fieldId, $userProfileFields) || empty($fieldInfo)) {
                             continue;
                         }
                         $fieldType = $userProfileFields[$fieldId]['type'];
                         $profilePropertyId = $fieldId . '_' . $user->getSID();
                         switch (strtolower($fieldType)) {
                             case 'video':
                             case 'file':
                                 // change temporary file ID
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
                                 // set value of user property to new uploaded file
                                 $user->setPropertyValue($fieldId, $profilePropertyId);
                                 break;
                             case 'logo':
                                 // change temporary file ID and thumb ID
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId, $fieldInfo['file_id']);
                                 SJB_DB::query("UPDATE `uploaded_files` SET `id` = ?s WHERE `id` = ?s", $profilePropertyId . '_thumb', $fieldInfo['file_id'] . '_thumb');
                                 // set value of user property to new uploaded file
                                 $user->setPropertyValue($fieldId, $profilePropertyId);
                                 break;
                             default:
                                 break;
                         }
                         $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}/{$fieldId}");
                     }
                     // and save user with new fields data
                     SJB_UserManager::saveUser($user);
                     SJB_Authorization::updateCurrentUserSession();
                     // clean temporary storage
                     $tmpUploadsStorage = SJB_Array::unsetValueByPath($tmpUploadsStorage, "{$formToken}");
                     // CLEAR TEMPORARY SESSION STORAGE
                     SJB_Session::setValue('tmp_uploads_storage', $tmpUploadsStorage);
                 }
             }
             // <<< SJB-1197
             $tp->assign("form_is_submitted", true);
         } else {
             $tp->assign("errors", $errors);
         }
         $form_fields = $edit_profile_form->getFormFieldsInfo();
         $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
         $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields)));
         $tp->assign("show_mailing_flag", $user_group_info['show_mailing_flag']);
         $tp->assign("form_fields", $form_fields);
         $tp->assign('userTree', true);
         $tp->display('edit_profile.tpl');
     } elseif (empty($user_info) && SJB_Request::getVar('profile_deleted', '') == true) {
         $user = new SJB_User(array());
         $edit_profile_form = new SJB_Form($user);
         $edit_profile_form->registerTags($tp);
         $edit_profile_form->makeDisabled("username");
         $form_fields = $edit_profile_form->getFormFieldsInfo();
         $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
         $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($form_fields)));
         $tp->assign("form_fields", $form_fields);
         $tp->assign('action', 'delete_profile');
         $tp->assign('tree_link_users', 'users');
         $tp->assign('userTree', true);
         $tp->display('edit_profile.tpl');
     } else {
         $tp->assign("ERROR", "NOT_LOGIN");
         $tp->display("../miscellaneous/error.tpl");
         return;
     }
 }
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $user_group_sid = SJB_Request::getVar('user_group_sid', null);
     $user_group_info = SJB_UserGroupManager::getUserGroupInfoBySID($user_group_sid);
     $user_profile_field_sid = SJB_Request::getVar('sid', null);
     if (!is_null($user_profile_field_sid)) {
         $user_profile_field_info = SJB_UserProfileFieldManager::getFieldInfoBySID($user_profile_field_sid);
         $user_profile_field_old_id = $user_profile_field_info['id'];
         $user_profile_field_info = array_merge($user_profile_field_info, $_REQUEST);
         $user_profile_field = new SJB_UserProfileField($user_profile_field_info);
         $user_profile_field->setSID($user_profile_field_sid);
         $user_profile_field->setUserGroupSID($user_group_sid);
         if (!in_array($user_profile_field->field_type, array('video', 'picture', 'logo', 'file', 'location'))) {
             $default_value = array('id' => 'default_value', 'sid' => isset($user_profile_field_info['sid']) ? $user_profile_field_info['sid'] : '', 'caption' => 'Default Value', 'value' => isset($user_profile_field_info['default_value']) ? $user_profile_field_info['default_value'] : '', 'type' => $user_profile_field->field_type, 'length' => '', 'is_required' => false, 'is_system' => true);
             $additionalParameters = array();
             switch ($user_profile_field->field_type) {
                 case 'list':
                     if (isset($user_profile_field_info['list_values'])) {
                         $additionalParameters = array('list_values' => $user_profile_field_info['list_values']);
                     }
                     break;
                 case 'multilist':
                     if (isset($user_profile_field_info['list_values'])) {
                         $additionalParameters = array('list_values' => $user_profile_field_info['list_values']);
                     }
                     if (!is_array($default_value['value'])) {
                         if (strpos($default_value['value'], ',')) {
                             $default_value['value'] = explode(',', $default_value['value']);
                         } else {
                             $default_value['value'] = array($default_value['value']);
                         }
                     }
                     break;
                 case 'tree':
                     if (isset($user_profile_field_info['tree_values'])) {
                         $additionalParameters = array('tree_values' => $user_profile_field_info['tree_values']);
                     }
                     if (isset($user_profile_field_info['display_as_select_boxes'])) {
                         $additionalParameters['display_as_select_boxes'] = $user_profile_field_info['display_as_select_boxes'];
                     }
                     break;
             }
             $default_value = array_merge($default_value, $additionalParameters);
             $user_profile_field->addProperty($default_value);
         }
         if (in_array($user_profile_field->field_type, array('tree', 'multilist', 'list'))) {
             $sort_by_alphabet = array('id' => 'sort_by_alphabet', 'caption' => 'Sort Values By Alphabet', 'value' => isset($user_profile_field_info['sort_by_alphabet']) ? $user_profile_field_info['sort_by_alphabet'] : '', 'type' => 'boolean', 'lenght' => '', 'is_required' => false, 'is_system' => true);
             $user_profile_field->addProperty($sort_by_alphabet);
         }
         $edit_form = new SJB_Form($user_profile_field);
         $form_submitted = SJB_Request::getVar('action');
         if (in_array($user_profile_field->field_type, array('multilist', 'list'))) {
             $user_profile_field->addDisplayAsProperty($user_profile_field_info['display_as']);
         }
         // infill instructions should be the last element in form
         // no instructions for tree field type
         if (!in_array($user_profile_field->getFieldType(), array('complex', 'tree', 'location'))) {
             if ($form_submitted) {
                 $user_profile_field->addInfillInstructions(SJB_Request::getVar('instructions'));
             } else {
                 $user_profile_field->addInfillInstructions(isset($user_profile_field_info['instructions']) ? $user_profile_field_info['instructions'] : '');
             }
         }
         /**
          * "Display as" options for TREE TYPE
          */
         if ('tree' == $user_profile_field->getFieldType()) {
             $user_profile_field->addProperty(SJB_TreeType::getDisplayAsDetail(isset($user_profile_field_info['display_as_select_boxes']) ? $user_profile_field_info['display_as_select_boxes'] : ''));
             $treeLevelsNumber = SJB_UserProfileFieldTreeManager::getTreeDepthBySID($user_profile_field_sid);
             $tp->assign('tree_levels_number', $treeLevelsNumber);
             // treee levels captions
             for ($i = 1; $i <= $treeLevelsNumber; $i++) {
                 $levelID = 'level_' . $i;
                 $user_profile_field->addProperty(array('id' => $levelID, 'caption' => $i . ' Level Name', 'value' => isset($user_profile_field_info[$levelID]) ? $user_profile_field_info[$levelID] : '', 'type' => 'string', 'length' => '250', 'is_required' => false, 'is_system' => true));
             }
         }
         // end of ""Display as" options for TREE TYPE"
         $edit_form = new SJB_Form($user_profile_field);
         $errors = array();
         if ($form_submitted && $edit_form->isDataValid($errors)) {
             SJB_UserProfileFieldManager::saveUserProfileField($user_profile_field);
             $user_profile_field_new_id = $user_profile_field_info['id'];
             if ($user_profile_field_old_id != $user_profile_field_new_id) {
                 SJB_UserProfileFieldManager::changeUserPropertyIDs($user_group_sid, $user_profile_field_old_id, $user_profile_field_new_id);
             }
             if ($form_submitted == 'save_info') {
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/edit-user-profile/?user_group_sid=' . $user_group_sid);
             }
         }
         if ($user_profile_field_info['id'] == 'Location' && empty($errors['ID'])) {
             $edit_form->makeDisabled('id');
         }
         $edit_form->registerTags($tp);
         $edit_form->makeDisabled('type');
         $tp->assign('user_group_sid', $user_group_sid);
         $tp->assign('form_fields', $edit_form->getFormFieldsInfo());
         $tp->assign('errors', $errors);
         $tp->assign('field_type', $user_profile_field->getFieldType());
         $tp->assign('userTree', true);
         $tp->assign('user_profile_field_info', $user_profile_field_info);
         $tp->assign('user_profile_field_sid', $user_profile_field_sid);
         $tp->assign('user_group_info', $user_group_info);
         $tp->display('edit_user_profile_field.tpl');
     }
 }
 private static function changeLocationProperties(&$exportProperties, &$exportData)
 {
     $locationFieldsInfo = SJB_UserProfileFieldManager::getFieldsInfoByType('location');
     foreach ($locationFieldsInfo as $fieldInfo) {
         if (isset($exportProperties[$fieldInfo['id']])) {
             unset($exportProperties[$fieldInfo['id']]);
             $exportLocationProperties[$fieldInfo['id'] . '.Country'] = $fieldInfo['id'] . '.Country';
             $exportLocationProperties[$fieldInfo['id'] . '.State'] = $fieldInfo['id'] . '.State';
             $exportLocationProperties[$fieldInfo['id'] . '.City'] = $fieldInfo['id'] . '.City';
             $exportLocationProperties[$fieldInfo['id'] . '.ZipCode'] = $fieldInfo['id'] . '.ZipCode';
             $exportLocationProperties[$fieldInfo['id'] . '.Address'] = $fieldInfo['id'] . '.Address';
             ksort($exportLocationProperties);
             $exportProperties = array_merge($exportProperties, $exportLocationProperties);
             foreach ($exportData as $userSID => $property) {
                 if (isset($property[$fieldInfo['id']]) && is_array($property[$fieldInfo['id']])) {
                     $propertyLocation = array();
                     foreach ($property[$fieldInfo['id']] as $locationField => $fieldValue) {
                         if ($locationField == 'Country' && !empty($locationField)) {
                             $countryInfo = SJB_CountriesManager::getCountryInfoBySID($fieldValue);
                             $fieldValue = !empty($countryInfo['country_name']) ? $countryInfo['country_name'] : '';
                         } elseif ($locationField == 'State') {
                             $stateInfo = SJB_StatesManager::getStateInfoBySID($fieldValue);
                             $fieldValue = !empty($stateInfo['state_name']) ? $stateInfo['state_name'] : '';
                         }
                         $propertyLocation[$fieldInfo['id'] . '.' . $locationField] = $fieldValue;
                     }
                     unset($property[$fieldInfo['id']]);
                     ksort($propertyLocation);
                     $exportData[$userSID] = array_merge($property, $propertyLocation);
                 }
             }
         }
     }
 }
Beispiel #30
0
 public static function getCurrentSearchByCriteria($criteria)
 {
     $returnArray = array();
     $locationFields = SJB_ListingFieldManager::getFieldsInfoByType('location');
     foreach ($criteria as $fieldName => $field) {
         if (!in_array($fieldName, array('listing_type', 'active', 'username', 'status', 'CompanyName', 'keywords', 'PostedWithin', 'anonymous'))) {
             $result = array();
             $fieldInfo = SJB_ListingFieldDBManager::getListingFieldInfoByID($fieldName);
             if (!$fieldInfo) {
                 foreach ($locationFields as $locationField) {
                     $locationSubFields = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($locationField['sid']);
                     foreach ($locationSubFields as $locationSubField) {
                         if ($fieldName == $locationField['id'] . "_" . $locationSubField['id']) {
                             $fieldInfo = $locationSubField;
                             $fieldInfo['id'] = $locationField['id'] . "_" . $locationSubField['id'];
                         }
                     }
                 }
             }
             foreach ($field as $fieldType => $fieldValue) {
                 switch ($fieldType) {
                     case 'geo':
                         if ($fieldValue['location'] !== '') {
                             $result[$fieldName][$fieldType][$fieldValue['location']] = $fieldValue['location'];
                         }
                         break;
                     case 'location':
                         if (!empty($fieldValue['value'])) {
                             $result[$fieldName][$fieldType][$fieldValue['value']] = $fieldValue['value'];
                         }
                         break;
                     case 'monetary':
                         if (!empty($fieldValue['not_less']) && $fieldValue['not_less'] !== '') {
                             $result[$fieldName][$fieldType][$fieldValue['not_less']] = $fieldValue['not_less'];
                         }
                         if (!empty($fieldValue['not_more']) && $fieldValue['not_more'] !== '') {
                             $result[$fieldName][$fieldType][$fieldValue['not_more']] = $fieldValue['not_more'];
                         }
                         break;
                     case 'multi_like':
                         $listItem = new SJB_ListingFieldListItemManager();
                         if (is_array($fieldValue)) {
                             foreach ($fieldValue as $value) {
                                 if ($value !== '') {
                                     if ($fieldInfo['type'] == 'tree') {
                                         $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'");
                                         $name = $name ? $name : '';
                                         $result[$fieldName][$fieldType][$value] = $name;
                                     } elseif ($fieldInfo['type'] == 'multilist' || $fieldInfo['type'] == 'list') {
                                         if (!empty($fieldInfo['parent_sid'])) {
                                             if ($fieldInfo['id'] == $fieldInfo['parentID'] . '_State') {
                                                 $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $fieldInfo['display_as']);
                                             } else {
                                                 $listValues = $fieldInfo['list_values'];
                                             }
                                             foreach ($listValues as $listValue) {
                                                 if ($listValue['id'] == $value) {
                                                     $result[$fieldName][$fieldType][$value] = $listValue['caption'];
                                                     break;
                                                 }
                                             }
                                         } else {
                                             $itemInfo = $listItem->getListItemBySID($value);
                                             $caption = $itemInfo ? $itemInfo->getValue() : $value;
                                             $result[$fieldName][$fieldType][$value] = $caption;
                                         }
                                     } else {
                                         $result[$fieldName][$fieldType][$value] = $value;
                                     }
                                 }
                             }
                         } elseif ($fieldValue !== '') {
                             $itemInfo = $listItem->getListItemBySID($fieldValue);
                             $caption = $itemInfo ? $itemInfo->getValue() : $fieldValue;
                             $result[$fieldName][$fieldType][$fieldValue] = $caption;
                         }
                         break;
                     case 'tree':
                         $fieldValue = $fieldValue ? explode(',', $fieldValue) : "";
                         if (is_array($fieldValue)) {
                             foreach ($fieldValue as $value) {
                                 if ($value !== '') {
                                     $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'");
                                     $name = $name ? $name : '';
                                     $result[$fieldName][$fieldType][$value] = $name;
                                 }
                             }
                         }
                         break;
                     case 'multi_like_and':
                         if (is_array($fieldValue)) {
                             $listItem = new SJB_ListingFieldListItemManager();
                             foreach ($fieldValue as $value) {
                                 if ($value !== '') {
                                     if ($fieldInfo['type'] == 'tree') {
                                         $name = SJB_DB::queryValue("SELECT `caption` FROM `listing_field_tree` WHERE `sid` = '{$value}'");
                                         $name = $name ? $name : '';
                                         $result[$fieldName][$fieldType][$value] = $name;
                                     } elseif ($fieldInfo['type'] == 'multilist' || $fieldInfo['type'] == 'list') {
                                         if (!empty($fieldInfo['parent_sid'])) {
                                             if ($fieldInfo['id'] == $fieldInfo['parentID'] . '_State') {
                                                 $listValues = SJB_StatesManager::getStatesNamesByCountry(false, true, $fieldInfo['display_as']);
                                             } else {
                                                 $listValues = $fieldInfo['list_values'];
                                             }
                                             foreach ($listValues as $listValue) {
                                                 if ($listValue['id'] == $value) {
                                                     $result[$fieldName][$fieldType][$value] = $listValue['caption'];
                                                     break;
                                                 }
                                             }
                                         } else {
                                             $itemInfo = $listItem->getListItemBySID($value);
                                             $caption = $itemInfo ? $itemInfo->getValue() : $value;
                                             $result[$fieldName][$fieldType][$value] = $caption;
                                         }
                                     } else {
                                         $result[$fieldName][$fieldType][$value] = $value;
                                     }
                                 }
                             }
                         } elseif ($fieldValue !== '') {
                             $result[$fieldName][$fieldType][$fieldValue] = $fieldValue;
                         }
                         break;
                     default:
                         if (is_array($fieldValue)) {
                             foreach ($fieldValue as $value) {
                                 if ($value !== '') {
                                     $result[$fieldName][$fieldType][$value] = $value;
                                 }
                             }
                         } elseif ($fieldValue !== '') {
                             $result[$fieldName][$fieldType][$fieldValue] = $fieldValue;
                         }
                         break;
                 }
             }
             if ($result && !empty($fieldInfo)) {
                 $returnArray[$fieldInfo['id']]['name'] = $fieldInfo['caption'];
                 $returnArray[$fieldInfo['id']]['field'] = $result[$fieldInfo['id']];
             }
         } elseif ($fieldName == 'CompanyName') {
             $result = array();
             $userFieldSID = SJB_DB::queryValue("SELECT `sid` FROM `user_profile_fields` WHERE `id` = 'CompanyName'");
             if ($userFieldSID) {
                 $fieldInfo = SJB_UserProfileFieldManager::getFieldInfoBySID($userFieldSID);
                 foreach ($field as $fieldType => $fieldValue) {
                     switch ($fieldType) {
                         case 'multi_like_and':
                             if (is_array($fieldValue)) {
                                 foreach ($fieldValue as $value) {
                                     if ($value !== '') {
                                         $result[$fieldName][$fieldType][$value] = $value;
                                     }
                                 }
                             } elseif ($fieldValue !== '') {
                                 $result[$fieldName][$fieldType][$fieldValue] = $fieldValue;
                             }
                             break;
                     }
                 }
             }
             if ($result && !empty($fieldInfo)) {
                 $returnArray[$fieldInfo['id']]['name'] = $fieldInfo['caption'];
                 $returnArray[$fieldInfo['id']]['field'] = $result[$fieldInfo['id']];
             }
         } elseif ($fieldName == 'keywords') {
             foreach ($field as $key => $val) {
                 if ($val) {
                     $returnArray['keywords']['field'][$key][$val] = $val;
                 }
             }
             if (isset($returnArray['keywords'])) {
                 $returnArray['keywords']['name'] = 'Keywords';
             }
         }
     }
     return $returnArray;
 }