Beispiel #1
0
 function getAddParameter()
 {
     if (isset($this->property_info['value']['add_parameter'])) {
         return SJB_DB::quote($this->property_info['value']['add_parameter']);
     }
     return '';
 }
 function _getWhatPart()
 {
     if (is_array($this->order_info['property'])) {
         foreach ($this->order_info['property'] as $orderInfoProperty) {
             $property[] = $orderInfoProperty;
         }
     } else {
         $property = $this->order_info['property'];
     }
     if (is_array($property)) {
         foreach ($property as $propertyItem) {
             if ($propertyItem->isSystem()) {
                 return "`{$this->table_prefix}`.sid";
             }
         }
     } elseif ($property->isSystem()) {
         if ($this->orderRelevance) {
             $value = SJB_DB::quote($this->orderRelevance['value']['value']);
             return "`{$this->table_prefix}`.sid,  MATCH(`{$this->orderRelevance['value']['field']}`) AGAINST ('{$value}') as relevance";
         } else {
             return "`{$this->table_prefix}`.sid";
         }
     } elseif ($property->getType() != 'tree') {
         $id = $property->getID();
         $sql_type = $property->getSQLType();
         if ($sql_type == 'DECIMAL') {
             // DECIMAL type is available in MYSQL 5.0.8 or higher
             return "{$this->table_prefix}.*, {$id}.value + 0.0 AS {$id}";
         }
         return "{$this->table_prefix}.*, CAST({$id}.value AS {$sql_type}) AS {$id}";
     }
     $tree_browser = new SJB_TreeBrowser($property->getID());
     return "{$this->table_prefix}.*, " . $tree_browser->getWhatPart();
 }
Beispiel #3
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');
 }
Beispiel #4
0
 public static function isAdminExist($username, $password)
 {
     $username = SJB_DB::quote($username);
     $password = md5(SJB_DB::quote($password));
     $value = SJB_DB::queryValue("SELECT * FROM `administrator` WHERE `username` = ?s AND `password` = '?w'", $username, $password);
     return !empty($value);
 }
Beispiel #5
0
 /**
  * logging into system as administrator
  * Function logs administrator into system.
  * If operation succeded it registers session variables 'username' and 'usertype'
  * @param string $username user's name
  * @param string $password user's password
  * @return bool 'true' if operation succeeded or 'false' otherwise
  */
 public static function admin_login($username)
 {
     $username = SJB_DB::quote($username);
     SJB_SubAdmin::setAdminInfo($username);
     SJB_Session::setValue('adminLoginCounter', 1);
     SJB_Session::setValue('username', $username);
     SJB_Session::setValue('usertype', "subadmin");
     setcookie("admin_mode", 'on', null, '/');
     return true;
 }
Beispiel #6
0
 public static function parse($expression, $returnAsArray = false, $field = '')
 {
     $expr = array();
     $oprs = array();
     preg_match_all('/".*?"|\\)|\\(|\\s+|[^"\\)\\(\\s]+/', $expression, $matches);
     $chunks = array();
     foreach ($matches[0] as $match) {
         $chunk = trim($match, "\" \t\r\n\v");
         if (!empty($chunk)) {
             $chunks[] = $chunk;
         }
     }
     foreach ($chunks as $char) {
         switch (strtolower($char)) {
             case "(":
                 $oprs[] = $char;
                 $expr[] = $char;
                 break;
             case "not":
             case "or":
             case "and":
                 $oprs[] = strtolower($char);
                 break;
             case ")":
                 SJB_BooleanEvaluator::evaluate($oprs, $expr, true, $returnAsArray);
                 SJB_BooleanEvaluator::evaluate($oprs, $expr, false, $returnAsArray);
                 break;
             default:
                 $char = SJB_DB::quote($char);
                 if ($returnAsArray) {
                     $expr[] = $char;
                 } else {
                     $expr[] = "{$field} like '%{$char}%'";
                 }
                 SJB_BooleanEvaluator::evaluate($oprs, $expr, false, $returnAsArray);
                 break;
         }
     }
     SJB_BooleanEvaluator::evaluate($oprs, $expr, false, $returnAsArray);
     if (count($expr) > 0) {
         $val = array_shift($expr);
         return !in_array($val, array('not', 'or', 'and', '(', ')')) ? $val : null;
     }
     return null;
 }
Beispiel #7
0
 /**
  * Get total flags number by listing type SID
  * 
  * Count and return total numbers of flag
  *
  * @param integer $listingTypeSID
  * @param array   $filters
  * @param boolean $groupByListing
  * @return integer
  */
 public static function getFlagsNumberByListingTypeSID($listingTypeSID, $filters = null, $groupByListing = false)
 {
     $filterFlag = '';
     $filterUser = '';
     $filterTitle = '';
     if ($filters !== null) {
         $filterFlag = isset($filters['flag_reason']) ? $filters['flag_reason'] : '';
         $filterUser = isset($filters['username']) ? $filters['username'] : '';
         $filterTitle = isset($filters['title']) ? $filters['title'] : '';
     }
     $joinUsers = '';
     if (!empty($filterFlag)) {
         $filterFlag = SJB_DB::quote($filterFlag);
         $filterFlag = " AND fl.flag_reason LIKE '%{$filterFlag}%' ";
     }
     if (!empty($filterUser)) {
         $filterUser = SJB_DB::quote($filterUser);
         $joinUsers = " LEFT JOIN `users` u ON (u.sid = l.user_sid) ";
         $filterUser = "******";
     }
     if (!empty($filterTitle)) {
         $filterTitle = SJB_DB::quote($filterTitle);
         $filterTitle = " AND l.`Title` LIKE '%{$filterTitle}%' ";
     }
     // SET GROUP PARAM
     $groupOption = '';
     if ($groupByListing) {
         $groupOption = " GROUP BY fl.listing_sid";
     }
     // SET LISTING TYPE FILTER
     if (empty($listingTypeSID)) {
         $listingTypeFilter = ' fl.`listing_type_sid` <> 0 ';
     } elseif (is_numeric($listingTypeSID)) {
         $listingTypeFilter = " fl.`listing_type_sid` = {$listingTypeSID} ";
     }
     $listingsNum = SJB_DB::query("\n\t\t\tSELECT count(*) count \n\t\t\t\tFROM `flagged_listings` fl \n\t\t\tLEFT JOIN `listings` l ON (l.sid = fl.listing_sid) \n\t\t\t{$joinUsers}\n\t\t\tWHERE {$listingTypeFilter} {$filterFlag} {$filterUser} {$filterTitle}\n\t\t\t{$groupOption}");
     // if group option - get number of flagged LISTINGs
     if ($groupByListing) {
         return count($listingsNum);
     }
     // if no group option - return number of flags
     return $listingsNum[0]['count'];
 }
Beispiel #8
0
 public function execute()
 {
     $errors = array();
     if (SJB_Request::isAjax()) {
         $response = null;
         $user_type = SJB_Request::getVar('user_type');
         $user_name = SJB_Request::getVar('parser_user');
         $products = SJB_XmlImport::getProducts($user_type, $user_name, $errors);
         $response = array('products' => empty($products) ? '' : SJB_XmlImport::translateProductsName($products), 'error' => empty($errors) ? '' : array_pop($errors));
         die(json_encode($response));
     }
     $tp = SJB_System::getTemplateProcessor();
     $add_level = SJB_Request::getVar('add_level', 1);
     // check for errors
     if ($add_level == '3') {
         $selectUserType = SJB_Request::getVar('selectUserType');
         $addNewUser = 0;
         if ($selectUserType == 'username') {
             $usr_name = isset($_REQUEST['parser_user']) ? SJB_DB::quote($_REQUEST['parser_user']) : '';
             $usr_id = SJB_UserManager::getUserSIDbyUsername($usr_name);
             if (empty($usr_name)) {
                 $errors[] = 'Please enter user name of existing user to the "User Name" field';
                 $usr_name = '';
             } else {
                 $user_sid_exists = SJB_UserManager::getUserSIDbyUsername($usr_name);
                 if (empty($user_sid_exists)) {
                     $errors[] = 'User "' . $usr_name . '" not exists. Please enter user name of existing user to the "User Name" field';
                     $usr_name = '';
                 }
             }
         } elseif ($selectUserType == 'group') {
             $userGroupSid = isset($_REQUEST['parser_user']) ? $_REQUEST['parser_user'] : 0;
             $usr_id = $userGroupSid;
             $usr_name = SJB_UserGroupManager::getUserGroupIDBySID($usr_id);
             $addNewUser = 1;
         }
         if ($errors) {
             $add_level = 2;
         }
     }
     $listings_type = SJB_ListingTypeManager::getAllListingTypesInfo();
     $types = array();
     foreach ($listings_type as $one) {
         $types[$one['sid']] = $one['id'];
     }
     $tp->assign('types', $types);
     $selected_logo_options = null;
     switch ($add_level) {
         case '1':
             $template = 'add_step_one.tpl';
             /*
             $types = array();
             foreach ( $listings_type as $one ) {
             					  $types[$one['sid']] = $one['id'];
             }
             $tp->assign('types', $types);
             */
             $tp->display('add_step_one.tpl');
             break;
         case '2':
             $template = 'add_step_two.tpl';
             $original_xml = SJB_Request::getVar('xml');
             $xml = $original_xml;
             $tree = '';
             $listing_fields = array();
             $logo_options_array = array('not_logo' => 'Do Not Import Logo', 'import_logo' => 'Import Logo with Listings', 'upload_logo' => 'Upload Logo for Imported Listings');
             $parsing_name = SJB_Request::getVar('parser_name');
             $usr_name = SJB_Request::getVar('parser_user');
             $pars_url = SJB_Request::getVar('parser_url');
             $form_description = SJB_Request::getVar('form_description', '', 'POST');
             $type_id = SJB_Request::getVar('type_id', '', 'POST');
             $selectedLogoOption = SJB_Request::getVar('logo_options');
             $selectedLogoField = SJB_Request::getVar('import_logo_field');
             $selectedProduct = SJB_Request::getVar('postUnderProduct');
             $id = SJB_Request::getVar('id', 0, 'GET');
             $selected = array();
             $a_selected = array();
             if (!empty($_REQUEST['xml']) || $id > 0) {
                 // step 2 OR edit exist
                 if ($id > 0) {
                     // load exist parser
                     $parser_from_id = SJB_XmlImport::getSystemParsers($id);
                     if (isset($parser_from_id[0]['name'])) {
                         $parser_from_id = $parser_from_id[0];
                     }
                     $parsing_name = $parser_from_id['name'];
                     $usr_id = $parser_from_id['usr_id'];
                     $usr_name = $parser_from_id['usr_name'];
                     $form_description = $parser_from_id['description'];
                     $pars_url = $parser_from_id['url'];
                     $type_id = $parser_from_id['type_id'];
                     $selected_logo_options = unserialize($parser_from_id['logo_options']);
                     $selectedLogoOption = $selected_logo_options['option'];
                     $selectedLogoField = $selected_logo_options['field'];
                     $selectedProduct = $parser_from_id['product_sid'];
                     $xml = $parser_from_id['xml'];
                     $xml = SJB_XmlImport::cleanXmlFromImport($xml);
                     $map = unserialize($parser_from_id['maper']);
                     $selected = array_values($map);
                     $a_selected = array_keys($map);
                 } else {
                     $xml = SJB_XmlImport::cleanXmlFromImport($_REQUEST['xml']);
                 }
                 $sxml = new simplexml();
                 $tree = $sxml->xml_load_file($xml, 'array');
                 if (isset($tree['@content'])) {
                     $tree = $tree[0];
                 }
                 if (is_array($tree)) {
                     $tree = SJB_XmlImport::convertArray($tree);
                     foreach ($tree as $key => $val) {
                         unset($tree[$key]);
                         // replace '@' and ':'
                         $key = SJB_XmlImport::encodeSpecialEntities($key);
                         $tree[$key]['val'] = $val;
                         $tree[$key]['key'] = $key;
                     }
                     $field_types = array(0, $type_id);
                     $listing_fields = array();
                     $i = 0;
                     foreach ($field_types as $type) {
                         $listing_fields_info = SJB_ListingFieldManager::getListingFieldsInfoByListingType($type);
                         foreach ($listing_fields_info as $listing_field_info) {
                             if ($listing_field_info['type'] == 'location') {
                                 foreach ($listing_field_info['fields'] as $fieldInfo) {
                                     $listing_field = new SJB_ListingField($fieldInfo);
                                     $listing_field->setSID($fieldInfo['sid']);
                                     $listing_fields[$i]['id'] = $listing_field_info['id'] . '_' . $listing_field->details->properties['id']->value;
                                     $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value;
                                     $i++;
                                 }
                             } else {
                                 $listing_field = new SJB_ListingField($listing_field_info);
                                 $listing_field->setSID($listing_field_info['sid']);
                                 $listing_fields[$i]['id'] = $listing_field->details->properties['id']->value;
                                 $listing_fields[$i]['caption'] = $listing_field->details->properties['id']->value;
                                 $i++;
                             }
                         }
                     }
                     $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "date";
                     $i++;
                     $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "url";
                     $i++;
                     $listing_fields[$i]['id'] = $listing_fields[$i]['caption'] = "external_id";
                 } else {
                     $errors[] = 'XML syntaxis error.';
                     $template = 'add_step_one.tpl';
                 }
             } else {
                 $errors[] = 'Please input correct xml';
                 $template = 'add_step_one.tpl';
             }
             $tp->assign('id', $id);
             $tp->assign('selected', $selected);
             $tp->assign('a_selected', $a_selected);
             $tp->assign('xml', htmlspecialchars($xml));
             $tp->assign('xmlToUser', $xml);
             $tp->assign('user_groups', SJB_UserGroupManager::getAllUserGroupsInfo());
             $tp->assign('form_name', $parsing_name);
             $tp->assign('form_user', $usr_name);
             $tp->assign('form_url', $pars_url);
             $tp->assign('form_description', $form_description);
             $type_name = SJB_ListingTypeManager::getListingTypeIDBySID($type_id);
             $tp->assign('type_id', $type_id);
             $tp->assign('type_name', $type_name);
             $tp->assign('errors', $errors);
             $tp->assign('tree', $tree);
             $tp->assign("fields", $listing_fields);
             $tp->assign('logo_options', $logo_options_array);
             $tp->assign('selectedLogoOption', $selectedLogoOption);
             $tp->assign('selectedLogoField', $selectedLogoField);
             $tp->assign('selectedProduct', $selectedProduct);
             $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
             $tp->display($template);
             break;
         case '3':
             $parsing_name = isset($_REQUEST['parser_name']) ? SJB_DB::quote($_REQUEST['parser_name']) : '';
             $pars_url = isset($_POST['parser_url']) ? SJB_DB::quote($_POST['parser_url']) : '';
             $selectedLogoOption = isset($_POST['logo_options']) ? $_POST['logo_options'] : '';
             $selectedLogoField = isset($_POST['import_logo_field']) ? $_POST['import_logo_field'] : '';
             $form_description = isset($_REQUEST['form_description']) ? SJB_DB::quote($_REQUEST['form_description']) : "";
             $type_id = isset($_POST['type_id']) ? intval($_POST['type_id']) : "";
             $script = isset($_POST['custom_script']) && !empty($_POST['custom_script']) ? SJB_DB::quote($_POST['custom_script']) : "";
             $script_users = SJB_DB::quote(SJB_Request::getVar('custom_script_users', '', SJB_Request::METHOD_POST));
             $defaultValue = SJB_Request::getVar('default_value', false);
             $defaultValueUser = SJB_Request::getVar('user_default_value', false);
             $selectedProduct = SJB_Request::getVar('postUnderProduct');
             $importType = SJB_Request::getVar('import_type', 'increment');
             if ($defaultValue) {
                 foreach ($defaultValue as $key => $val) {
                     $defaultValue[$key] = htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
                 }
             }
             if ($defaultValueUser) {
                 foreach ($defaultValueUser as $key => $val) {
                     $defaultValueUser[$key] = htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
                 }
             }
             $original_xml = !empty($_POST['xml']) ? SJB_DB::quote($_POST['xml']) : '';
             $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
             $addQuery = '';
             $username = SJB_XmlImport::decodeSpecialEntities(SJB_Request::getVar('username', ''));
             $external_id = str_replace('_dog_', '@', SJB_Request::getVar('external_id', ''));
             $site_url = SJB_System::getSystemSettings("SITE_URL");
             if ($addNewUser == 1 && empty($_REQUEST['mapped_user'])) {
                 $error = 'Required user profile fields are not mapped';
                 SJB_HelperFunctions::redirect($site_url . '/edit-import/?id=' . $id . '&save_error=' . base64_encode($error));
             }
             if (!empty($_REQUEST['mapped']) && is_array($_REQUEST['mapped']) && !empty($original_xml) && empty($errors)) {
                 // make map
                 $map1 = array();
                 $map2 = array();
                 $serUserMap = '';
                 foreach ($_REQUEST['mapped'] as $one) {
                     $tmp = explode(':', $one);
                     $map1[] = $tmp[0];
                     $map2[] = $tmp[1];
                 }
                 if ($addNewUser == 1 && !empty($_REQUEST['mapped_user']) && is_array($_REQUEST['mapped_user'])) {
                     // make map
                     $mapUser1 = array();
                     $mapUser2 = array();
                     foreach ($_REQUEST['mapped_user'] as $one) {
                         $tmp = explode(':', $one);
                         $mapUser1[] = str_replace('user_', '', $tmp[0]);
                         $mapUser2[] = $tmp[1];
                     }
                     foreach ($mapUser1 as $key => $val) {
                         $val = SJB_XmlImport::decodeSpecialEntities($val);
                         $mapUser[$val] = $mapUser2[$key];
                     }
                     $serUserMap = serialize($mapUser);
                 }
                 //$map = array_combine($map1, $map2); // PHP5
                 foreach ($map1 as $key => $val) {
                     $val = SJB_XmlImport::decodeSpecialEntities($val);
                     $map[$val] = $map2[$key];
                 }
                 if ($selectedLogoOption && $selectedLogoOption != 'not_logo') {
                     //get real data without any cache
                     if (!SJB_ListingFieldDBManager::getListingFieldInfoByID('ListingLogo')) {
                         $listing_field_info = array('id' => 'ListingLogo', 'type' => 'logo', 'is_system' => false, 'is_required' => false, 'caption' => 'Listing Logo');
                         $listing_field = new SJB_ListingField($listing_field_info, $type_id);
                         $pages = SJB_PostingPagesManager::getFirstPageEachListingType();
                         SJB_ListingFieldManager::saveListingField($listing_field, $pages);
                     }
                     if ($key = array_search('ListingLogo', $map) !== false) {
                         unset($map[$key]);
                     }
                 }
                 if ($defaultValue) {
                     foreach ($defaultValue as $key => $val) {
                         if ($val == '') {
                             unset($defaultValue[$key]);
                         }
                     }
                     $defaultValue = SJB_db::quote(serialize($defaultValue));
                     $addQuery .= ", default_value = '" . $defaultValue . "'";
                 }
                 if ($defaultValueUser) {
                     foreach ($defaultValueUser as $keyuser => $valuser) {
                         if ($valuser == '') {
                             unset($defaultValueUser[$keyuser]);
                         }
                     }
                     $defaultValueUser = SJB_db::quote(serialize($defaultValueUser));
                     $addQuery .= ", default_value_user = '******'";
                 }
                 $queryParsUrl = SJB_DB::quote($pars_url);
                 $queryImportType = SJB_DB::quote($importType);
                 $queryId = intval($id);
                 $query = "SET\n\t\t\t\t\t\t\t`custom_script_users` = ?s,\n\t\t\t\t\t\t\t`custom_script` = ?s,\n\t\t\t\t\t\t\t`type_id` = ?n,\n\t\t\t\t\t\t\t`name` = ?s,\n\t\t\t\t\t\t\t`description` = ?s,\n\t\t\t\t\t\t\t`url` = ?s,\n\t\t\t\t\t\t\t`usr_id` = ?n,\n\t\t\t\t\t\t\t`usr_name` = ?s,\n\t\t\t\t\t\t\t`maper_user` = ?s,\n\t\t\t\t\t\t\t`xml` = ?s,\n\t\t\t\t\t\t\t`add_new_user` = ?n,\n\t\t\t\t\t\t\t`username` = ?s,\n\t\t\t\t\t\t\t`external_id` = ?s,\n\t\t\t\t\t\t\t`product_sid` = ?n,\n\t\t\t\t\t\t\t`import_type` = ?s\n\t\t\t\t\t\t\t{$addQuery}";
                 if ($id > 0) {
                     SJB_DB::query("UPDATE `parsers` {$query} WHERE id = ?n", $script_users, $script, $type_id, $parsing_name, $form_description, $queryParsUrl, $usr_id, $usr_name, $serUserMap, $original_xml, $addNewUser, $username, $external_id, $selectedProduct, $queryImportType, $queryId);
                 } else {
                     $id = SJB_DB::query("INSERT INTO `parsers` {$query}", $script_users, $script, $type_id, $parsing_name, $form_description, $queryParsUrl, $usr_id, $usr_name, $serUserMap, $original_xml, $addNewUser, $username, $external_id, $selectedProduct, $queryImportType);
                 }
                 $errorFile = '';
                 $xml_logo = null;
                 switch ($selectedLogoOption) {
                     case 'import_logo':
                         $map[$selectedLogoField] = 'ListingLogo';
                         break;
                     case 'upload_logo':
                         if (!empty($_FILES['upload_logo_file'])) {
                             if ($_FILES['upload_logo_file']['error']) {
                                 $errorFile = SJB_UploadFileManager::getErrorId($_FILES['upload_logo_file']['error']);
                             } else {
                                 $width = SJB_Settings::getSettingByName('listing_picture_width');
                                 $height = SJB_Settings::getSettingByName('listing_picture_height');
                                 $property_info['second_width'] = SJB_Settings::getSettingByName('listing_thumbnail_width');
                                 $property_info['second_height'] = SJB_Settings::getSettingByName('listing_thumbnail_height');
                                 $picture = new SJB_UploadPictureManager();
                                 $picture->setWidth($width);
                                 $picture->setHeight($height);
                                 if ($picture->isValidUploadedPictureFile('upload_logo_file')) {
                                     $xml_logo = "XMLImportLogo_{$id}";
                                     $picture->setUploadedFileID($xml_logo);
                                     $picture->uploadPicture('upload_logo_file', $property_info);
                                 }
                             }
                         }
                         break;
                 }
                 $logo_options = serialize(array('option' => $selectedLogoOption, 'field' => $selectedLogoField));
                 $serMap = serialize($map);
                 if ($xml_logo) {
                     SJB_DB::query("UPDATE `parsers` SET maper = ?s, `xml_logo` = ?s, logo_options = ?s  WHERE id = ?n", $serMap, $xml_logo, $logo_options, $id);
                 } else {
                     SJB_DB::query("UPDATE `parsers` SET maper = ?s, logo_options = ?s  WHERE id = ?n", $serMap, $logo_options, $id);
                 }
                 $form_submitted = SJB_Request::getVar('form_action');
                 if ($form_submitted == 'save_info') {
                     SJB_HelperFunctions::redirect($site_url . '/show-import/');
                 } elseif ($form_submitted == 'apply_info') {
                     $getterParameters = '?id=' . $id;
                     if ($errorFile) {
                         $getterParameters .= '&error=' . $errorFile;
                     }
                     SJB_HelperFunctions::redirect($site_url . '/edit-import/' . $getterParameters);
                 }
             } else {
                 if (empty($errors)) {
                     $errors[] = 'No data to save';
                 }
                 $tp->assign('errors', $errors);
                 $tp->assign('xml', htmlspecialchars($original_xml));
                 $tp->assign('xmlToUser', $original_xml);
                 $tp->assign('form_name', $parsing_name);
                 $tp->assign('form_user', $usr_name);
                 $tp->assign('form_url', $pars_url);
                 $tp->assign('form_description', $form_description);
                 $tp->display('add_step_three.tpl');
             }
             break;
     }
 }
 function _getSelectRelevanceStatement($criteria)
 {
     $value = SJB_DB::quote($criteria['value']);
     if (SJB_DB::table_exists($this->object_table_prefix . '_properties')) {
         if ($this->object_table_prefix == 'listings' && $this->isComplex) {
             return "SELECT `{$this->object_table_prefix}`.`sid` as `object_sid`, if( COUNT( `complex_enum` ) >0, COUNT( DISTINCT `id` ), COUNT( *  ) ) `count`,  MATCH(`{$criteria['field']}`) AGAINST ('{$value}') as relevance ";
         } else {
             return "SELECT `{$this->object_table_prefix}`.`sid` as `object_sid`, COUNT(*) as `count` ";
         }
     }
     return "SELECT `{$this->object_table_prefix}`.`sid` as `object_sid`,  MATCH`(`{$criteria['field']}`) AGAINST ('{$value}') as relevance";
 }
Beispiel #10
0
 function getAddParameter()
 {
     if (isset($this->property_info['value']['add_parameter']) && $this->property_info['id'] == 'ApplicationSettings') {
         return SJB_DB::quote($this->property_info['value']['add_parameter']);
     }
     return '';
 }
Beispiel #11
0
 public function execute()
 {
     header('Content-Type: text/html; charset=utf-8');
     $requestUri = $_SERVER['REQUEST_URI'];
     preg_match('(.*/autocomplete/([a-zA-Z0-9:_]*)/?)', $requestUri, $fieldParam);
     $field = !empty($fieldParam[1]) ? $fieldParam[1] : '';
     preg_match("(.*/autocomplete/{$field}/([a-zA-Z]*)/?)", $requestUri, $fieldType);
     $fieldType = !empty($fieldType[1]) ? $fieldType[1] : '';
     preg_match("(.*/autocomplete/{$field}/{$fieldType}/([a-zA-Z]*)/?)", $requestUri, $tablePrefix);
     $tablePrefix = SJB_DB::quote(!empty($tablePrefix[1]) ? $tablePrefix[1] : '');
     preg_match("(.*/autocomplete/{$field}/{$fieldType}/{$tablePrefix}/([a-zA-Z]*)/?)", $requestUri, $viewType);
     $viewType = SJB_DB::quote(!empty($viewType[1]) ? $viewType[1] : '');
     preg_match("(.*/autocomplete/{$field}/{$fieldType}/{$tablePrefix}/{$viewType}/([a-zA-Z]*)/?)", $requestUri, $listingTypeID);
     $listingTypeID = SJB_DB::quote(!empty($listingTypeID[1]) ? $listingTypeID[1] : '');
     $query = SJB_Request::getVar('q', false);
     if (!empty($query) && $field && $fieldType && $tablePrefix && $viewType && $listingTypeID) {
         $queryCriterion = $query . '%';
         if ($fieldType == 'text' && $field == 'keywords') {
             $result = SJB_DB::query('SELECT `keywords` as `value`, COUNT(*) `count` FROM `listings_keywords` WHERE `keywords` LIKE ?s AND `active` = 1 GROUP BY `keywords` ORDER BY `count` DESC LIMIT 0 , 5', $queryCriterion);
         } elseif ($fieldType == 'geo') {
             $result = SJB_DB::query('SELECT DISTINCT `name` as `value`, COUNT(*) `count` FROM `locations` WHERE `name` <> \'\' AND `name` LIKE ?s GROUP BY `value` LIMIT 0 , 100', $queryCriterion);
         } elseif ($fieldType == 'location') {
             if (preg_match('/[a-z\\d]+\\d+/i', $query)) {
                 $result = SJB_DB::query('SELECT DISTINCT `name` as `value`, `city`, `state_code`, COUNT(*) `count` FROM `locations` WHERE `name` <> \'\' AND `name` LIKE ?s GROUP BY `value`, `country_sid` LIMIT 0 , 10', $queryCriterion);
             } else {
                 $country = SJB_DB::query("SELECT `country_name` as `value` FROM `countries` WHERE `country_code` = ?s AND `active` = 1", $query);
                 $countries = SJB_DB::query("SELECT `country_name` as `value` FROM `countries` WHERE `country_name` LIKE ?s AND `country_code` != ?s AND `active` = 1", $queryCriterion, $query);
                 $countries = array_merge($country, $countries);
                 $states = SJB_DB::query("SELECT `state_name` as `value` FROM `states` INNER JOIN `countries` ON `states`.`country_sid` = `countries`.`sid` WHERE `countries`.`active` = 1 AND `states`.`state_name` LIKE ?s AND `states`.`active` = 1", $queryCriterion);
                 foreach ($states as $key => $state) {
                     $state = trim(preg_replace('/(\\s+|[^\'"_\\w\\dÀ-ÿ])/ui', '', strip_tags($state['value'])));
                     $states[$state] = $states[$key];
                     unset($states[$key]);
                 }
                 $cities = SJB_DB::query("\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t`locations`.`state_code`, `city` as `value`\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`locations`\n\t\t\t\t\t\tINNER JOIN\n\t\t\t\t\t\t\t`countries` ON `locations`.`country_sid` = `countries`.`sid`\n\t\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\t\t`states` ON `locations`.`state_code` = `states`.`state_code`\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`countries`.`active` = 1 AND\n\t\t\t\t\t\t\t`locations`.`city` LIKE ?s AND\n\t\t\t\t\t\t\t(`states`.`active` = 1 OR\n\t\t\t\t\t\t\tLENGTH(`locations`.`state_code`) = 0)", $queryCriterion);
                 foreach ($cities as $key => $city) {
                     $state = trim(preg_replace('/(\\s+|[^\'"_\\w\\dÀ-ÿ])/ui', '', strip_tags($city['state_code'])));
                     $city = trim(preg_replace('/(\\s+|[^\'"_\\w\\dÀ-ÿ])/ui', '', strip_tags($city['value'])));
                     $cities[$city][$state] = $cities[$key];
                     unset($cities[$key]);
                 }
                 $result = array();
                 $i = 0;
                 foreach ($states as $key => $state) {
                     $result[$i] = $state;
                     $i++;
                     if (isset($cities[$key])) {
                         $result[$i] = $cities[$key];
                         unset($cities[$key]);
                         $i++;
                     }
                 }
                 $result = array_merge($countries, $result);
                 $result = array_merge($result, $cities);
             }
         } elseif ($fieldType == 'string') {
             $additionalCondition = '';
             $fieldParents = explode('_', $field);
             $fieldName = array_pop($fieldParents);
             if ($fieldName == 'City') {
                 if ($viewType == 'input') {
                     $tablePrefix = 'locations';
                     $field = 'City';
                 } elseif ($viewType == 'search' && $tablePrefix == 'listings') {
                     $listingTypeSid = SJB_ListingTypeManager::getListingTypeSIDByID($listingTypeID);
                     $additionalCondition = '`listing_type_sid` = ' . $listingTypeSid . ' AND';
                 }
             }
             $result = SJB_DB::query("SELECT DISTINCT `{$field}` as `value`, COUNT(*) `count` FROM `{$tablePrefix}` WHERE " . $additionalCondition . " `{$field}` LIKE ?s GROUP BY `{$field}` ORDER BY `count` DESC LIMIT 0 , 5", $queryCriterion);
         }
         if (!empty($result)) {
             foreach ($result as $rowBase) {
                 if (empty($rowBase['value']) && is_array($rowBase)) {
                     foreach ($rowBase as $rowBase) {
                         $res = strpos(strtolower($rowBase['value']), strtolower($query));
                         if ($res !== false || $fieldType == 'location') {
                             $rowBase['value'] = trim($rowBase['value']);
                             if (isset($rowBase['city']) && isset($rowBase['state_code'])) {
                                 print $rowBase['value'] . ', ' . $rowBase['city'] . ', ' . $rowBase['state_code'] . "\n";
                             } elseif (!empty($rowBase['state_code'])) {
                                 print $rowBase['value'] . ', ' . $rowBase['state_code'] . "\n";
                             } elseif (!isset($rowBase['count'])) {
                                 print $rowBase['value'] . "\n";
                             } else {
                                 print $rowBase['value'] . '|' . $rowBase['count'] . "\n";
                             }
                         }
                     }
                 } else {
                     $res = strpos(strtolower($rowBase['value']), strtolower($query));
                     if ($res !== false || $fieldType == 'location') {
                         $rowBase['value'] = trim($rowBase['value']);
                         if (isset($rowBase['city']) && isset($rowBase['state_code'])) {
                             print $rowBase['value'] . ', ' . $rowBase['city'] . ', ' . $rowBase['state_code'] . "\n";
                         } elseif (!empty($rowBase['state_code'])) {
                             print $rowBase['value'] . ', ' . $rowBase['state_code'] . "\n";
                         } elseif (!isset($rowBase['count'])) {
                             print $rowBase['value'] . "\n";
                         } else {
                             print $rowBase['value'] . '|' . $rowBase['count'] . "\n";
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #12
0
 private static function sqlProfileCallback($m)
 {
     global $sqlProfileArgs;
     @($arg = array_shift($sqlProfileArgs));
     switch ($m[0]) {
         case '?n':
             // number
             return intval($arg);
         case '?s':
             // string
             return "'" . SJB_DB::quote($arg) . "'";
         case '?b':
             // binary (0x462347238)
             return '0x' . bin2hex($arg);
         case '?f':
             // float
             return floatval(str_replace(',', '.', $arg));
         case '?w':
             // without
             return $arg;
         case '?t':
             // time
             return "'" . date("Y-m-d H:i:s", $arg) . "'";
         case '?l':
             // list
             $str = '';
             if (is_array($arg)) {
                 foreach ($arg as $value) {
                     $str .= (empty($str) ? "'" : ", '") . SJB_DB::quote($value) . "'";
                 }
                 return $str;
             }
             return "'" . SJB_DB::quote($arg) . "'";
         default:
             return $m[0];
             break;
     }
 }
Beispiel #13
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $appsPerPage = SJB_Request::getVar('appsPerPage', 10);
     $this->currentPage = SJB_Request::getVar('page', 1);
     $currentUser = SJB_UserManager::getCurrentUser();
     $appJobId = SJB_Request::getVar('appJobId', false, null, 'int');
     $score = SJB_Request::getVar('score', false);
     $orderBy = SJB_Request::getVar('orderBy', 'date');
     $order = SJB_Request::getVar('order', 'desc');
     $displayTemplate = "view.tpl";
     $errors = array();
     // не бум пускать незарегенных
     if (SJB_UserManager::isUserLoggedIn() === false) {
         $tp->assign("ERROR", "NOT_LOGIN");
         $tp->display("../miscellaneous/error.tpl");
         return;
     }
     $filename = SJB_Request::getVar('filename', false);
     if ($filename) {
         $appsID = SJB_Request::getVar('appsID', false);
         if ($appsID) {
             $file = SJB_UploadFileManager::openApplicationFile($filename, $appsID);
             if (!$file) {
                 $errors['NO_SUCH_FILE'] = true;
             }
         } else {
             $errors['NO_SUCH_APPS'] = true;
         }
     }
     if (!is_numeric($this->currentPage) || $this->currentPage < 1) {
         $this->currentPage = 1;
     }
     if (!is_numeric($appsPerPage) || $appsPerPage < 1) {
         $appsPerPage = 10;
     }
     if ($order != 'asc' && $order != 'desc') {
         $order = 'desc';
     }
     if (!empty($score) && $score != 'passed' && $score != 'not_passed') {
         $score = false;
     }
     $tp->assign("orderBy", $orderBy);
     $tp->assign("order", $order);
     if (isset($orderBy) && isset($order) && $orderBy != "") {
         switch ($orderBy) {
             case "date":
                 $orderInfo = array('sorting_field' => 'date', 'sorting_order' => $order);
                 break;
             case "title":
                 $orderInfo = array('sorting_field' => 'Title', 'sorting_order' => $order, 'inner_join' => array('table' => 'listings', 'field1' => 'sid', 'field2' => 'listing_id'));
                 break;
             case "applicant":
                 $orderInfo = false;
                 $sortByUsername = true;
                 break;
             case "status":
                 $orderInfo = array('sorting_field' => 'status', 'sorting_order' => $order);
                 break;
             case "score":
                 $orderInfo = array('sorting_field' => 'score', 'sorting_order' => $order);
                 break;
             case "company":
                 $orderInfo = array('sorting_field' => 'CompanyName', 'sorting_order' => $order, 'inner_join' => array('table' => 'listings', 'field1' => 'sid', 'field2' => 'listing_id'), 'inner_join2' => array('table1' => 'users', 'table2' => 'listings', 'field1' => 'sid', 'field2' => 'user_sid'));
                 break;
             default:
                 $orderInfo = array('sorting_field' => 'date', 'sorting_order' => $order);
         }
     }
     if ($currentUser->getUserGroupSID() == 41) {
         // Работадатель
         switch (SJB_Request::getVar('action', '')) {
             case "approve":
                 $applications = SJB_Request::getVar('applications', '');
                 if (!empty($applications)) {
                     if (is_array($applications)) {
                         foreach ($applications as $key => $value) {
                             $this->approveApplication($key);
                         }
                     } else {
                         $this->approveApplication($applications);
                     }
                 }
                 break;
             case "reject":
                 $applications = SJB_Request::getVar('applications', '');
                 if (!empty($applications)) {
                     if (is_array($applications)) {
                         foreach ($applications as $key => $value) {
                             $this->rejectApplication($key);
                         }
                     } else {
                         $this->rejectApplication($applications);
                     }
                 }
                 break;
             case "delete":
                 if (isset($_POST["applications"])) {
                     foreach ($_POST["applications"] as $key => $value) {
                         SJB_Applications::hideEmp($key);
                     }
                 }
                 break;
         }
         $whereSubuser = '';
         if (!empty($subuser)) {
             $whereSubuser = '******' . SJB_DB::quote($subuser);
         }
         $jobs = SJB_DB::query('select `Title` as `title`, `sid` as `id` from `listings` where `user_sid` = ?n' . $whereSubuser, $currentUser->sid);
         $listingTitle = null;
         foreach ($jobs as $job) {
             if ($job['id'] == $appJobId) {
                 $listingTitle = $job['title'];
             }
         }
         $apps = $this->executeApplicationsForEmployer($appsPerPage, $appJobId, $currentUser, $score, $orderInfo, $listingTitle);
         if (empty($apps) && $this->currentPage > 1) {
             $this->currentPage = 1;
             $apps = $this->executeApplicationsForEmployer($appsPerPage, $appJobId, $currentUser, $score, $orderInfo, $listingTitle);
         }
         foreach ($apps as $i => $app) {
             $apps[$i]["job"] = SJB_ListingManager::getListingInfoBySID($apps[$i]["listing_id"]);
             if (!empty($apps[$i]["job"]['screening_questionnaire'])) {
                 $screening_questionnaire = SJB_ScreeningQuestionnaires::getInfoBySID($apps[$i]["job"]['screening_questionnaire']);
                 $passing_score = 0;
                 switch ($screening_questionnaire['passing_score']) {
                     case 'acceptable':
                         $passing_score = 1;
                         break;
                     case 'good':
                         $passing_score = 2;
                         break;
                     case 'very_good':
                         $passing_score = 3;
                         break;
                     case 'excellent':
                         $passing_score = 4;
                         break;
                 }
                 if ($apps[$i]['score'] >= $passing_score) {
                     $apps[$i]['passing_score'] = 'Passed';
                 } else {
                     $apps[$i]['passing_score'] = 'Not passed';
                 }
             }
             if (isset($apps[$i]["resume"]) && !empty($apps[$i]["resume"])) {
                 $apps[$i]["resumeInfo"] = SJB_ListingManager::getListingInfoBySID($apps[$i]["resume"]);
             }
             // если это анонимный соискатель - то возьмем имя из пришедшего поля 'username'
             if ($apps[$i]['jobseeker_id'] == 0) {
                 $apps[$i]["user"]["FirstName"] = $apps[$i]['username'];
             } else {
                 $apps[$i]["user"] = SJB_UserManager::getUserInfoBySID($apps[$i]["jobseeker_id"]);
                 $apps[$i]['user']['stateInfo'] = SJB_StatesManager::getStateInfoBySID($apps[$i]['user']['Location_State']);
                 if (isset($apps[$i]['user']['stateInfo']['state_code'])) {
                     $apps[$i]['user']['Location']['State_Code'] = $apps[$i]['user']['stateInfo']['state_code'];
                 }
             }
         }
         $tp->assign("appsPerPage", $appsPerPage);
         $tp->assign("currentPage", $this->currentPage);
         $tp->assign("pages", $this->pages);
         $tp->assign("totalPages", $this->totalPages);
         $tp->assign("appJobs", $jobs);
         $tp->assign("score", $score);
         $tp->assign("current_filter", $appJobId);
         $tp->assign("listing_title", $listingTitle);
     } else {
         // Соискатель
         if (SJB_Request::getVar('action', '', 'POST') == "delete") {
             foreach (SJB_Request::getVar('applications', array(), 'POST') as $key => $value) {
                 SJB_Applications::hideJS($key);
             }
         }
         $apps = SJB_Applications::getByJobseeker($currentUser->sid, $orderInfo);
         for ($i = 0; $i < count($apps); ++$i) {
             $apps[$i]["job"] = SJB_ListingManager::getListingInfoBySID($apps[$i]["listing_id"]);
             $apps[$i]["company"] = SJB_UserManager::getUserInfoBySID($apps[$i]["job"]["user_sid"]);
         }
         $displayTemplate = "view_seeker.tpl";
     }
     if (isset($sortByUsername)) {
         $sortKeys = array();
         $order = $order == "desc" ? SORT_DESC : SORT_ASC;
         foreach ($apps as $key => $value) {
             if (!isset($apps[$key]["user"]["FirstName"])) {
                 $apps[$key]["user"]["FirstName"] = '';
             }
             if (!isset($apps[$key]["user"]["LastName"])) {
                 $apps[$key]["user"]["LastName"] = '';
             }
             $sortKeys[$key] = $apps[$key]["user"]["FirstName"] . " " . $apps[$key]["user"]["LastName"];
         }
         array_multisort($sortKeys, $order, SORT_REGULAR, $apps);
     }
     if (empty($apps) && empty($errors['NOT_OWNER_OF_APPLICATIONS'])) {
         $errors['APPLICATIONS_NOT_FOUND'] = true;
     }
     $tp->assign("METADATA", SJB_Application::getApplicationMeta());
     $tp->assign("applications", $apps);
     $tp->assign("errors", $errors);
     $tp->display($displayTemplate);
 }
Beispiel #14
0
 /**
  * @param array $findZipCodes
  * @param string $city
  * @return string
  */
 private function getQueryForZipCodesByRadius(array $findZipCodes, $city)
 {
     $geoLocation = new SJB_GeoLocation();
     $radiusSearchUnit = SJB_System::getSettingByName('radius_search_unit');
     if ($city) {
         $minLatitude = $maxLatitude = $findZipCodes[0]['latitude'];
         $minLongitude = $maxLongitude = $findZipCodes[0]['longitude'];
         $stateCode = $findZipCodes[0]['state_code'];
         $countrySid = $findZipCodes[0]['country_sid'];
         foreach ($findZipCodes as $zipCode) {
             if ($stateCode != $zipCode['state_code'] || $countrySid != $zipCode['country_sid']) {
                 return '';
             } else {
                 $zipLatitude = $zipCode['latitude'];
                 $zipLongitude = $zipCode['longitude'];
                 if ($zipLatitude < $minLatitude) {
                     $minLatitude = $zipLatitude;
                 } else {
                     if ($zipLatitude > $maxLatitude) {
                         $maxLatitude = $zipLatitude;
                     }
                 }
                 if ($zipLongitude < $minLongitude) {
                     $minLongitude = $zipLongitude;
                 } else {
                     if ($zipLongitude > $maxLongitude) {
                         $maxLongitude = $zipLongitude;
                     }
                 }
             }
         }
         $distance = SJB_LocationManager::getDistanceBetweenPointsInKm($minLatitude, $minLongitude, $maxLatitude, $maxLongitude);
         $distance /= 2;
         $distance += $radiusSearchUnit == 'kilometers' ? $this->value['radius'] : $this->value['radius'] * 1.60934;
         $centralLatitude = ($minLatitude + $maxLatitude) / 2;
         $centralLongitude = ($minLongitude + $maxLongitude) / 2;
         $centralLocation = $geoLocation->fromDegrees($centralLatitude, $centralLongitude);
         $query = SJB_LocationManager::findPlacesWithinDistance($centralLocation, $distance);
         $query .= " AND (`city` != '" . SJB_DB::quote($city) . "')";
     } else {
         $query = array();
         $distance = $radiusSearchUnit == 'kilometers' ? $this->value['radius'] : $this->value['radius'] * 1.60934;
         foreach ($findZipCodes as $zipCode) {
             $myLocation = $geoLocation->fromDegrees($zipCode['latitude'], $zipCode['longitude']);
             $query[] = SJB_LocationManager::findPlacesWithinDistance($myLocation, $distance);
         }
         $query = implode(' OR ', $query);
     }
     return "SELECT `name` FROM `locations` WHERE {$query}";
 }
Beispiel #15
0
 public static function getCountApplicationsByEmployer($userSID, $score = false, $subuser = false)
 {
     $subuserFilter = '';
     if ($subuser !== false) {
         $subuserFilter = ' and `l`.`subuser_sid` = ' . SJB_DB::quote($subuser);
     }
     $scoreFilter['case'] = '';
     $scoreFilter['inner_join'] = '';
     $scoreFilter['score'] = '';
     if (!empty($score)) {
         $scoreFilter = self::getScoredApplications($score);
     }
     $appsCount = SJB_DB::queryValue("\n\t\t\tSELECT COUNT(`a`.`listing_id`)\n\t\t\t\t{$scoreFilter['case']}\n\t\t\tFROM\n\t\t\t\t`applications` `a`\n\t\t\tINNER JOIN `listings` l ON\n\t\t\t\t`l`.`sid` = `a`.`listing_id`\n\t\t\t\t{$scoreFilter['inner_join']}\n\t\t\tWHERE `l`.`user_sid` = ?s AND `a`.`show_emp` = 1 {$scoreFilter['score']}{$subuserFilter} ", $userSID);
     return $appsCount;
 }
Beispiel #16
0
 /**
  * Get articles by search text
  *
  * @param string $text
  * @return array
  */
 public static function searchArticles($text, $lang = 'en', $active = false)
 {
     $text = SJB_DB::quote($text);
     $activeQuery = '';
     if ($active) {
         $activeQuery = '`active` = 1';
     }
     $result = SJB_DB::query("SELECT * FROM `news` WHERE (`brief` LIKE '%{$text}%' OR `text` LIKE '%{$text}%' OR `title` LIKE '%{$text}%') AND `language` = ?s AND {$activeQuery} ORDER BY `date` ASC", $lang);
     if (empty($result)) {
         return array();
     }
     $upload_manager = new SJB_UploadFileManager();
     foreach ($result as $key => $value) {
         $result[$key]['image_link'] = '';
         if (!empty($value['image'])) {
             $result[$key]['image_link'] = $upload_manager->getUploadedFileLink($value['image']);
         }
     }
     return $result;
 }
Beispiel #17
0
 public static function getListingsSIDByUserSID($userSid, $subuser = false, $limit = false)
 {
     $subuserFilter = $subuser !== false ? " AND `subuser_sid` = '" . SJB_DB::quote($subuser) . "'" : '';
     $limit = $limit ? ' LIMIT ' . $limit : '';
     $query = "SELECT `sid` FROM `listings` WHERE `user_sid` = {$userSid}" . $subuserFilter . $limit;
     $cache = SJB_Cache::getInstance();
     if ($cache->test(md5($query))) {
         $listings_info = $cache->load(md5($query));
     } else {
         $listings_info = SJB_DB::query('SELECT `sid` FROM `listings` WHERE `user_sid` = ?n ' . $subuserFilter . $limit, $userSid);
         $cache->save($listings_info, md5($query), array(SJB_Cache::TAG_LISTINGS));
     }
     $listings_sid = array();
     foreach ($listings_info as $listing_info) {
         $listings_sid[] = $listing_info['sid'];
     }
     return $listings_sid;
 }
Beispiel #18
0
 public static function getUserSIDsLikeCompanyName($companyName)
 {
     if (empty($companyName)) {
         return null;
     }
     $usersInfo = SJB_DB::query("SELECT `sid` FROM `users` WHERE `CompanyName` LIKE '%?w%'", SJB_DB::quote($companyName));
     if (!empty($usersInfo)) {
         foreach ($usersInfo as $userInfo) {
             $usersSids[$userInfo['sid']] = $userInfo['sid'];
         }
         return $usersSids;
     }
     return null;
 }
Beispiel #19
0
 public static function isValid($type)
 {
     $user_group_sid = SJB_Request::getVar('user_group_sid');
     $count = SJB_DB::queryValue("SELECT COUNT(*) FROM ?w WHERE user_group_sid = ?n AND `?w` = ?s AND sid <> ?n", $type->property_info['table_name'], $user_group_sid, SJB_DB::quote($type->property_info['id']), $type->property_info['value'], $type->object_sid);
     if ($count) {
         return 'NOT_UNIQUE_VALUE';
     }
     return true;
 }
Beispiel #20
0
 private function prepareRequestedCriteria()
 {
     if ($idKeyword = SJB_Request::getVar('idKeyword', false)) {
         if (strpos($idKeyword, ',') !== false) {
             $idKeywordTrimmed = array();
             foreach (explode(',', $idKeyword) as $idK) {
                 $idKeywordTrimmed[] = SJB_HelperFunctions::trimValue($idK);
             }
             foreach ($idKeywordTrimmed as $val) {
                 if (intval($val)) {
                     $_REQUEST['sid']['in'][] = (int) $val;
                 } else {
                     unset($_REQUEST['sid']['in']);
                     $_REQUEST['keywords']['like'][] = $val;
                 }
             }
         } else {
             if (intval($idKeyword)) {
                 $_REQUEST['sid']['equal'] = (int) $idKeyword;
             } else {
                 $_REQUEST['keywords']['like'] = SJB_HelperFunctions::trimValue($idKeyword);
             }
         }
     }
     if ($companyUserName = SJB_Request::getVar('company_name', false)) {
         if (!empty($companyUserName['like'])) {
             $listingSids = SJB_UserManager::getUserSIDsLikeCompanyName($companyUserName['like']);
             if (empty($listingSids)) {
                 unset($_REQUEST['company_name']);
             }
             $usernameLikeSids = SJB_UserManager::getUserSIDsLikeUsername(SJB_DB::quote($companyUserName['like']));
             $firstLastNameLikeSids = SJB_UserManager::getUserSIDsLikeFirstNameOrLastName(SJB_DB::quote($companyUserName['like']));
             $_REQUEST['user_sid']['in'] = array_merge(!empty($usernameLikeSids) ? $usernameLikeSids : array(''), !empty($firstLastNameLikeSids) ? $firstLastNameLikeSids : array(''));
         }
     }
 }
Beispiel #21
0
 public static function isUserAccessThisPage()
 {
     $pageID = SJB_PageManager::getPageParentURI(SJB_Navigator::getURI(), SJB_System::getSystemSettings('SYSTEM_ACCESS_TYPE'), false);
     $access = true;
     $currentUser = SJB_UserManager::getCurrentUser();
     if (!is_null($currentUser)) {
         $access = false;
         $queryParam = '';
         $listingId = SJB_Request::getVar("listing_id", false);
         $passedParametersViaUri = SJB_Request::getVar("passed_parameters_via_uri", false);
         if (!$listingId && $passedParametersViaUri) {
             $passedParametersViaUri = SJB_UrlParamProvider::getParams();
             $listingId = isset($passedParametersViaUri[0]) ? $passedParametersViaUri[0] : '';
         }
         if ($listingId) {
             $queryParam = " AND `param` = '" . SJB_DB::quote($listingId) . "' ";
         }
         $pageHasBeenVisited = SJB_DB::query("SELECT `param` FROM `page_view` WHERE `id_user` = ?s AND `id_pages` = ?s {$queryParam}", $currentUser->getSID(), $pageID);
         if (!empty($queryParam) && $pageHasBeenVisited || strpos($pageID, 'print') !== false) {
             $access = true;
         } else {
             $contractsId = $currentUser->getContractID();
             $pageAccess = SJB_ContractManager::getPageAccessByUserContracts($contractsId, $pageID);
             $numberOfPagesViewed = SJB_ContractManager::getNumbeOfPagesViewed($currentUser->getSID(), $contractsId, $pageID);
             if (isset($pageAccess[$pageID]) && $pageAccess[$pageID]['count_views'] != '') {
                 if ($numberOfPagesViewed < $pageAccess[$pageID]['count_views']) {
                     $access = true;
                 }
                 if ($access === true) {
                     $listingTypeSID = null;
                     if (is_numeric($listingId)) {
                         $listingInfo = SJB_ListingManager::getListingInfoBySID($listingId);
                         if ($listingInfo) {
                             $listingTypeSID = $listingInfo['listing_type_sid'];
                         }
                     }
                     $availableContractId = '';
                     foreach ($contractsId as $contractId) {
                         $pageAccessByContract = SJB_ContractManager::getPageAccessByUserContracts(array($contractId), $pageID);
                         $viewsLeft = SJB_ContractManager::getNumbeOfPagesViewed($currentUser->getSID(), array($contractId), false, $listingTypeSID);
                         if (!empty($pageAccessByContract[$pageID]['count_views']) && $pageAccessByContract[$pageID]['count_views'] > $viewsLeft) {
                             $availableContractId = $contractId;
                         }
                     }
                     if (!empty($availableContractId)) {
                         SJB_DB::query("INSERT INTO page_view (`id_user` ,`id_pages`, `param`, `contract_id`, `listing_type_sid`) VALUES ( ?n, ?s, ?s, ?n, ?n)", $currentUser->getSID(), $pageID, $listingId, $availableContractId, $listingTypeSID);
                     } else {
                         $access = false;
                     }
                 }
             } else {
                 $access = true;
             }
         }
     }
     return $access;
 }
Beispiel #22
0
 private function databaseFileRegister($fileGroup, $fileId, $fileSaveName, $mimeType)
 {
     $uploadManager = new SJB_UploadFileManager();
     $uploadManager->setFileGroup($fileGroup);
     $uploadManager->registNewFile($fileId, $fileSaveName);
     SJB_DB::query("UPDATE `uploaded_files` SET `mime_type` = ?s WHERE `id` = ?s", SJB_DB::quote($mimeType), $fileId);
 }
Beispiel #23
0
 public static function set_character_set_cc($charset)
 {
     $sql = "set names '" . SJB_DB::quote($charset) . "';";
     if (!SJB_DB::query($sql)) {
         return false;
     }
     return true;
 }
Beispiel #24
0
 public static function getStatistics($params)
 {
     $where = 'WHERE 1 ';
     $limit = '';
     foreach ($params as $name => $value) {
         switch ($name) {
             case 'date':
                 if (is_array($value)) {
                     $where .= " AND `{$name}` = '" . SJB_DB::quote($value) . "' ";
                 } else {
                     $where .= " AND " . SJB_DB::quote($value) . " ";
                 }
                 break;
             case 'limit':
                 $limit = " LIMIT {$value}";
                 break;
             default:
                 $where .= " AND `{$name}` = '" . SJB_DB::quote($value) . "' ";
         }
     }
     return SJB_DB::query("SELECT `sid`, `count`, `user_sid` FROM `statistics` {$where} {$limit}");
 }