/** * @todo Document * @return boolean Are items available? */ function has_items() { global $lilina_items; if (count(Feeds::get_instance()->getAll()) === 0) { return false; } if (empty($lilina_items)) { foreach (Feeds::get_instance()->getAll() as $the_feed) { $feed_list[] = $the_feed['feed']; } $lilina_items = Items::get_instance(); $lilina_items->init(); $conditions = apply_filters('return_items-conditions', array('time' => time() - get_offset())); $lilina_items->set_conditions($conditions); $lilina_items->filter(); } return $lilina_items->has_items(); }
action_bar('before=&after= | '); ?> </div><?php $num++; } } elseif (!has_feeds()) { ?> <div style="border:1px solid #e7dc2b;background: #fff888;margin:15px;padding:10px;"><?php printf(_r('You haven\'t added any feeds yet. Add them from <a href="%s">your admin panel</a>'), 'admin/'); ?> </div> <?php } else { ?> <div style="border:1px solid #e7dc2b;background: #fff888;margin:15px;padding:10px;">No items available in the last <?php echo get_offset(true); ?> hours. Try <a href="index.php?hours=-1" id="viewallitems">viewing all items.</a></div> <div style="border:1px solid #e7dc2b;background: #fff888;margin:15px;padding:10px;display:none;">Now loading all available items - If they don't load within 20 seconds, click <a href="index.php?hours=-1">here</a><br /><img src="<?php template_directory(); ?> /loading.gif" alt="<?php _e('Loading...'); ?> " /></div> <?php } ?> </div> </div>
/** * display a page of thumbnails * * @copyright (c) 2001-2011, Universite catholique de Louvain (UCL) * @param imageList (array) list containing all image file names * @param fileList (array) file properties * @param page (int) current page number * @param thumbnailWidth (int) width of thumbnails * @param colWidth (int) width of columns * @param numberOfCols (int) number of columns * @param numberOfRows (int) number of rows * @global curDirPath */ function display_thumbnails($imageList, $fileList, $page, $thumbnailWidth, $colWidth, $numberOfCols, $numberOfRows) { global $curDirPath; global $searchCmdUrl; // get index of first thumbnail on the page $displayed = get_offset($page); $html = ''; // loop on rows for ($rows = 0; $rows < $numberOfRows; $rows++) { $html .= "<tr>\n"; // loop on columns for ($cols = 0; $cols < $numberOfCols; $cols++) { // get index of image $num = $imageList[$displayed]; // get file name $fileName = $fileList[$num]['path']; // visibility style if ($fileList[$num]['visibility'] == 'i') { $style = "style=\"font-style: italic; color: silver;\""; } else { $style = ''; } // display thumbnail /*echo "<td style=\"text-align: center;\" style=\"width:" . $colWidth . "%;\">\n" ;*/ // omit colwidth since already in th $html .= "<td style=\"text-align: center;\">\n"; $html .= "<a href=\"" . claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . "?docView=image&file=" . download_url_encode($fileName) . "&cwd=" . $curDirPath . $searchCmdUrl)) . "\">"; // display image description using title attribute $title = ""; if ($fileList[$num]['comment']) { $text = $fileList[$num]['comment']; $text = cutstring($text, 40, false, 5, "..."); $title = "title=\"" . $text . "\""; } $html .= create_thumbnail($fileName, $thumbnailWidth, $title); // unset title for the next pass in the loop unset($title); $html .= "</a>\n"; // display image name $imgName = strlen(basename($fileList[$num]['path'])) > 25 ? substr(basename($fileList[$num]['path']), 0, 25) . "..." : basename($fileList[$num]['path']); $html .= "<p " . $style . ">" . $imgName . "</p>"; $html .= "</td>\n"; // update image number $displayed++; // finished ? if ($displayed >= count($imageList)) { $html .= "</tr>\n"; return $html; } } // end loop on columns $html .= "</tr>\n"; } // end loop on rows return $html; }
<div id="current-channel-container"> <div class="channel-section show-full"> <div class="channel-header <?php echo $section; ?> "> <div class="box-top-corners"><div class="box-corner-top-left"></div></div> <div class="channel-header-content"> <h3>ALL <?php echo strtoupper(str_replace(array('_', '-'), array(' ', ' '), $section)); ?> ARTICLES</h3> <div class="title-right"><?php $num_articles = get_offset($filter, $section); if ($num_articles > 20) { $num_offsets = ceil($num_articles / 20); ?> <?php if ($offset > 1) { ?> <a href="<?php echo $_SERVER['DOCUMENT_ROOT'] . "/channel_" . $section . "/1"; ?> " name="first page" title="first page">«</a><?php } else { ?> <div class="disabled">«</div><?php } ?>
function get_sql_query_clauses_NEW($db, $params, $currentUser = null) { global $mysqli, $wg_ids, $publicOnly; $mysqli = $db; if (!$params) { $params = array(); } //$_REQUEST; // 1. DETECT CURRENT USER AND ITS GROUPS, if not logged search only all records (no bookmarks) ---------------------- $wg_ids = array(); //may be better use $system->get_user_group_ids() ??? if ($currentUser && @$currentUser['ugr_ID'] > 0) { if (@$currentUser['ugr_Groups']) { $wg_ids = array_keys($currentUser['ugr_Groups']); } $currUserID = $currentUser['ugr_ID']; array_push($wg_ids, $currUserID); } else { $currUserID = 0; $params['w'] = 'all'; } array_push($wg_ids, 0); // be sure to include the generic everybody workgroup $publicOnly = @$params['publiconly'] == 1; //@todo change to vt - visibility type parameter of query // 2. DETECT SEARCH DOMAIN ------------------------------------------------------------------------------------------ if (strcasecmp(@$params['w'], 'B') == 0 || strcasecmp(@$params['w'], BOOKMARK) == 0) { // my bookmark entries $search_domain = BOOKMARK; } else { if (@$params['w'] == 'e') { //everything - including temporary $search_domain = EVERYTHING; } else { if (@$params['w'] == 'nobookmark') { //all without BOOKMARK $search_domain = NO_BOOKMARK; } else { // all records entries $search_domain = "a"; } } } if (is_array(@$params['q'])) { $query_json = $params['q']; } else { $query_json = json_decode(@$params['q'], true); } $query = new HQuery("0", $query_json, $search_domain, $currUserID); $query->makeSQL(); //1. create tree of predicates //2. make where // 6. DEFINE LIMIT AND OFFSET --------------------------------------------------------------------------------------- $limit = get_limit($params); $offset = get_offset($params); if (!$query->where_clause) { $query->where_clause = "(1=1)"; } // 7. COMPOSE QUERY ------------------------------------------------------------------------------------------------ return array("from" => " FROM " . $query->from_clause, "where" => $query->where_clause, "sort" => $query->sort_clause, "limit" => " LIMIT {$limit}", "offset" => $offset > 0 ? " OFFSET {$offset} " : ""); }
/** * Show Trash List * * Lets you list the records in the database. * All records that are in trash are listed. * * @access public * @param integer - default set to 0 for pagination */ function show_trash_list($per_page = 0) { $query = ""; if ($this->session->flashdata('restore_indicator')) { $this->errors = $this->session->flashdata('restore_indicator'); } $data = array("pagetitle" => "List of page(s) in trash", "mode" => "show_trash_list", "msg" => $this->msg, "errors" => $this->errors); //Unset session data $this->_clear_search_filters(); // load pagination library $this->load->library('Digg_Pagination'); //********************SET UP PAGINATION VALUES**************************** //set up per_page_value, per_page_seg, cur_page_seg and $data['pbase_url'] //************************************************************************ $this->load->plugin('pagination'); $per_page_value = 50; //default - unless overridden later $per_page_seg = 4; //the uri segment for the per page value $cur_page_seg = 5; //the url segment for the current page value (generally +1 of per page seg) $per_page = $per_page ? $per_page : get_per_page($per_page_value, $per_page_seg); $offset = get_offset($cur_page_seg, $per_page); if ($this->session->userdata('user') == '*****@*****.**') { //generate the query $data['users_result'] = $this->db_interaction->get_records($offset, $per_page, array("status" => 2), "rank , page_name"); $total_rows = count($this->db_interaction->get_records(NULL, NULL, array("status" => 2))); } else { $allowed_modules_session = isset($this->session->userdata['modules_allowed']['pid_frontend']) ? $this->session->userdata['modules_allowed']['pid_frontend'] : ''; if ($allowed_modules_session != '') { $modules_allowed = implode(',', array_keys($allowed_modules_session)); } else { $modules_allowed = 0; } $user_id = $this->session->userdata('user_id'); $SQL_TRASH = "SELECT \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tid,page_name,page_head,page_header,page_footer,status,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcreated,modified,display_footer,hide_client,rank,created_by,user_id,page_parent_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . TBL_PAGE . " \n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSTATUS = 2\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t (ID IN (" . $modules_allowed . ") OR user_id = " . $user_id . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t rank\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t LIMIT\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t {$offset}, {$per_page}"; $data['users_result'] = $this->db_interaction->run_query($SQL_TRASH); $SQL_TRASH = "SELECT \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcount(id) AS TRASH_ROWS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . TBL_PAGE . " \n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSTATUS = 2\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t (ID IN (" . $modules_allowed . ") OR user_id = " . $user_id . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t rank\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t "; //$data['users_result'] = $this->db_interaction->get_records($offset, $per_page,array("status" => 2,"ID !="=>1),"rank , page_name"); $total_rows_trash = $this->db_interaction->run_query($SQL_TRASH); if (is_array($total_rows_trash) && count($total_rows_trash) > 0) { $total_rows = $total_rows_trash[0]['TRASH_ROWS']; } else { $total_rows = 0; } //$total_rows = count($this->db_interaction->get_records(NULL, NULL,array("status" => 2,"hide_client !="=>1))); } //find out the total amount of records $total_rows = count($this->db_interaction->get_records(NULL, NULL, array("status" => 2, "hide_client !=" => 1))); $data['pbase_url'] = site_url($this->page_name . "/show_trash_list/"); $data['pagination'] = init_paginate($cur_page_seg, $total_rows, $per_page, $per_page_seg, $data['pbase_url']); // get total no. of user in trash $where_trash_rows = array("status !=" => 2); $data['total_rows_items'] = $this->db_interaction->get_num_records_where($where_trash_rows); // get all pages $data['all_pages'] = $this->_get_all_pages(); // load view and add additional data $this->_display("trash", $data); }
/** * Gets the timezone stored in the DB, or a default * * Accounts for storage of GMT offset vs Timezone * * @return mixed|string|void */ function get_timezone() { $timezone = get_option('timezone_string'); if (!$timezone) { $timezone = new Helper_DateTimeZone(Helper_DateTimeZone::tzOffsetToName(get_offset())); $timezone = $timezone->getName(); } return apply_filters(__NAMESPACE__ . '\\timezone', $timezone ? $timezone : 'America/New_York'); }
</div> </li><?php endwhile; } elseif(!has_feeds()) { ?> <li> <h2>Whoops!</h2> <p>No feeds exist!</p> </li> <?php } else { ?> <div style="border:1px solid #e7dc2b;background: #fff888;margin:15px;padding:10px;">No items available from in the last <?php echo get_offset(true); ?> hour(s). Try <a href="index.php?hours=-1" id="viewallitems">viewing all items</a></div> <div style="background: url('<?php template_directory(); ?>/spinner-back.png');margin:15px;padding:10px;display:none;">Now loading all available items - If they don't load within 20 seconds, click <a href="index.php?hours=-1">here</a><br /><img src="<?php template_directory(); ?>/spinner.gif" alt="Loading..." /></div> <?php } ?> </ul> </div> </div> </div> <div id="sidebar"> <ul> <?php if( has_feeds() ): ?> <li id="sources"><h3>Sources</h3> <ul>
function build_query($query, $page, $order = 'id DESC') { $CI =& get_instance(); return $CI->db->query($query . ' ORDER BY ' . $order . ' LIMIT ' . get_offset($page) . ', ' . get_limit()); }
/** * put your comment there... * * @param mixed $system * @param mixed $params * * FOR RULES * rules - rules queries - to search related records on server side * getrelrecs (=1) - search relationship records (along with related) on server side * topids - list of records ids, it is used to compose 'parentquery' parameter to use in rules (@todo - replace with new rules algorithm) * * INTERNAL/recursive * parentquery - sql expression to substiture in rule query * sql - sql expression to execute (used as recursive parameters to search relationship records) * * SEARCH parameters that are used to compose sql expression * q - query string (old mode) or json array (new mode) * w (=all|bookmark a|b) - search among all or bookmarked records * limit - limit for sql query is set explicitely on client side * offset - offset parameter value for sql query * s - sort order * * OUTPUT parameters * vo (=h3) - output format in h3 for backward capability (for detail=ids only) * needall (=1) - by default it returns only first 3000, to return all set it to 1, * it is set to 1 for server-side rules searches * publiconly (=1) - ignore current user and returns only public records * * detail (former 'f') - ids - only record ids * header - record header * timemap - record header + timemap details * detail - record header + all details * structure - record header + all details + record type structure (for editing) - NOT USED * * CLIENT SIDE * id - unque id to sync with client side * source - id of html element that is originator of this search * qname - original name of saved search (for messaging) */ function recordSearch($system, $params) { //for error message $savedSearchName = @$params['qname'] ? "Saved search: " . $params['qname'] . "<br>" : ""; if (!@$params['detail']) { $params['detail'] = @$params['f']; //backward capability } $istimemap_request = @$params['detail'] == 'timemap'; $istimemap_counter = 0; //total records with timemap data $fieldtypes_ids = null; if ($istimemap_request) { //get date,year and geo fields from structure $fieldtypes_ids = dbs_GetDetailTypes($system, array('date', 'year', 'geo'), 3); if ($fieldtypes_ids == null || count($fieldtypes_ids) == 0) { $fieldtypes_ids = array(DT_GEO_OBJECT, DT_DATE, DT_START_DATE, DT_END_DATE); //9,10,11,28'; } $fieldtypes_ids = implode(',', $fieldtypes_ids); } else { if (!in_array(@$params['detail'], array('header', 'timemap', 'detail', 'structure'))) { //specific set of detail fields if (is_array($params['detail'])) { $fieldtypes_ids = $params['detail']; } else { $fieldtypes_ids = explode(',', $params['detail']); } if (is_array($fieldtypes_ids) && (count($fieldtypes_ids) > 1 || is_numeric($fieldtypes_ids[0]))) { $fieldtypes_ids = implode(',', $fieldtypes_ids); $params['detail'] = 'detail'; } else { $fieldtypes_ids = null; $params['detail'] = 'ids'; } } } $is_ids_only = 'ids' == $params['detail']; $return_h3_format = @$params['vo'] == 'h3' && $is_ids_only; if (null == $system) { $system = new System(); if (!$system->init(@$_REQUEST['db'])) { $response = $system->getError(); if ($return_h3_format) { $response['error'] = $response['message']; } return $response; } } $mysqli = $system->get_mysqli(); $currentUser = $system->getCurrentUser(); if ($system->get_user_id() < 1) { $params['w'] = 'all'; //does not allow to search bookmarks if not logged in } if ($is_ids_only) { $select_clause = 'select SQL_CALC_FOUND_ROWS DISTINCT rec_ID '; } else { $select_clause = 'select SQL_CALC_FOUND_ROWS DISTINCT ' . 'bkm_ID,' . 'bkm_UGrpID,' . 'rec_ID,' . 'rec_URL,' . 'rec_RecTypeID,' . 'rec_Title,' . 'rec_OwnerUGrpID,' . 'rec_NonOwnerVisibility,' . 'bkm_PwdReminder '; /*.'rec_URLLastVerified,' .'rec_URLErrorMessage,' .'bkm_PwdReminder ';*/ } if ($currentUser && @$currentUser['ugr_ID'] > 0) { $currUserID = $currentUser['ugr_ID']; } else { $currUserID = 0; $params['w'] = 'all'; } if (@$params['topids']) { //if topids are defined we use them as starting point for following rule query // it is used for incremental client side only //@todo - implement it in different way - substitute topids to query json as predicate ids: $query_top = array(); if (strcasecmp(@$params['w'], 'B') == 0 || strcasecmp(@$params['w'], 'bookmark') == 0) { $query_top['from'] = 'FROM usrBookmarks TOPBKMK LEFT JOIN Records TOPBIBLIO ON bkm_recID=rec_ID '; } else { $query_top['from'] = 'FROM Records TOPBIBLIO LEFT JOIN usrBookmarks TOPBKMK ON bkm_recID=rec_ID and bkm_UGrpID=' . $currUserID . ' '; } $query_top['where'] = "(TOPBIBLIO.rec_ID in (" . $params['topids'] . "))"; $query_top['sort'] = ''; $query_top['limit'] = ''; $query_top['offset'] = ''; $params['parentquery'] = $query_top; //parentquery parameter is used in get_sql_query_clauses } else { if (@$params['rules']) { //special case - server side operation // rules - JSON array the same as stored in saved searches table if (is_array(@$params['rules'])) { $rules_tree = $params['rules']; } else { $rules_tree = json_decode($params['rules'], true); } $flat_rules = array(); $flat_rules[0] = array(); //create flat rule array $rules = _createFlatRule($flat_rules, $rules_tree, 0); //find result for main query unset($params['rules']); if (@$params['limit']) { unset($params['limit']); } if (@$params['offset']) { unset($params['offset']); } if (@$params['vo']) { unset($params['vo']); } $params['needall'] = 1; //return all records $resSearch = recordSearch($system, $params); $keepMainSet = true; if ($keepMainSet) { //find main query results $fin_result = $resSearch; //main result set $flat_rules[0]['results'] = $is_ids_only ? $fin_result['data']['records'] : array_keys($fin_result['data']['records']); //get ids } else { //empty main result set //remove from $fin_result! but keep in $flat_rules[0]['results']? } $is_get_relation_records = @$params['getrelrecs'] == 1; //get all related and relationship records foreach ($flat_rules as $idx => $rule) { if ($idx == 0) { continue; } $is_last = @$rule['islast'] == 1; //create request $params['q'] = $rule['query']; $parent_ids = $flat_rules[$rule['parent']]['results']; //list of record ids of parent resultset $rule['results'] = array(); //reset //split by 3000 - search based on parent ids (max 3000) $k = 0; while ($k < count($parent_ids)) { //$need_details2 = $need_details && ($is_get_relation_records || $is_last); $params3 = $params; $params3['topids'] = implode(",", array_slice($parent_ids, $k, 3000)); if (!$is_last) { //($is_get_relation_records || //$params3['detail'] = 'ids'; //no need in details for preliminary results ??????? } $response = recordSearch($system, $params3); if ($response['status'] == HEURIST_OK) { //merge with final results if ($is_ids_only) { $fin_result['data']['records'] = array_merge_unique($fin_result['data']['records'], $response['data']['records']); } else { $fin_result['data']['records'] = mergeRecordSets($fin_result['data']['records'], $response['data']['records']); $fin_result['data']['order'] = array_merge($fin_result['data']['order'], array_keys($response['data']['records'])); foreach (array_keys($response['data']['records']) as $rt) { $rectype_id = @$rt['4']; if ($rectype_id) { /*if(@$fin_result['data']['rectypes'][$rectype_id]){ $fin_result['data']['rectypes'][$rectype_id]++; }else{ $fin_result['data']['rectypes'][$rectype_id]=1; }*/ if (!array_key_exists($rectype_id, $fin_result['data']['rectypes'])) { $fin_result['data']['rectypes'][$rectype_id] = 1; } } } } if (!$is_last) { //add top ids for next level $flat_rules[$idx]['results'] = array_merge_unique($flat_rules[$idx]['results'], $is_ids_only ? $response['data']['records'] : array_keys($response['data']['records'])); } if ($is_get_relation_records && (strpos($params3['q'], "related_to") > 0 || strpos($params3['q'], "relatedfrom") > 0)) { //find relation records (recType=1) //create query to search related records if (strcasecmp(@$params3['w'], 'B') == 0 || strcasecmp(@$params3['w'], 'bookmark') == 0) { $from = 'FROM usrBookmarks TOPBKMK LEFT JOIN Records TOPBIBLIO ON bkm_recID=rec_ID '; } else { $from = 'FROM Records TOPBIBLIO LEFT JOIN usrBookmarks TOPBKMK ON bkm_recID=rec_ID and bkm_UGrpID=' . $currUserID . ' '; } if (strpos($params3['q'], "related_to") > 0) { $fld2 = "rl_SourceID"; $fld1 = "rl_TargetID"; } else { $fld1 = "rl_SourceID"; $fld2 = "rl_TargetID"; } $where = "WHERE (TOPBIBLIO.rec_ID in (select rl_RelationID from recLinks where (rl_RelationID is not null) and {$fld1} in (" . $params3['topids'] . ") and {$fld2} in (" . implode(",", $is_ids_only ? $response['data']['records'] : array_keys($response['data']['records'])) . ")))"; $params2 = $params3; unset($params2['topids']); unset($params2['q']); $params2['sql'] = $select_clause . $from . $where; $response = recordSearch($system, $params2); //search for relationship records if ($response['status'] == HEURIST_OK) { if (!@$fin_result['data']['relationship']) { $fin_result['data']['relationship'] = array(); } if ($is_ids_only) { $fin_result['data']['relationship'] = array_merge_unique($fin_result['data']['relationship'], $response['data']['records']); } else { $fin_result['data']['relationship'] = mergeRecordSets($fin_result['data']['relationship'], $response['data']['records']); } /*merge with final results if($is_ids_only){ $fin_result['data']['records'] = array_merge($fin_result['data']['records'], $response['data']['records']); }else{ $fin_result['data']['records'] = mergeRecordSets($fin_result['data']['records'], $response['data']['records']); $fin_result['data']['order'] = array_merge($fin_result['data']['order'], array_keys($response['data']['records'])); $fin_result['data']['rectypes'][1] = 1; } */ } } //$is_get_relation_records } else { //@todo terminate execution and return error } $k = $k + 3000; } //while chunks } //for rules if ($is_ids_only) { //$fin_result['data']['records'] = array_unique($fin_result['data']['records']); } $fin_result['data']['count'] = count($fin_result['data']['records']); if ($return_h3_format) { $fin_result = array("resultCount" => $fin_result['data']['count'], "recordCount" => $fin_result['data']['count'], "recIDs" => implode(",", $fin_result['data']['records'])); } //@todo - assign if size less than 3000? only $fin_result['data']['mainset'] = $flat_rules[0]['results']; return $fin_result; } } //END RULES $chunk_size = PHP_INT_MAX; if (@$params['sql']) { $query = $params['sql']; } else { $is_mode_json = false; if (@$params['q']) { if (is_array(@$params['q'])) { $query_json = $params['q']; //DEBUG error_log('Q='.print_r($params['q'],true)); } else { $query_json = json_decode(@$params['q'], true); } if (is_array($query_json) && count($query_json) > 0) { $params['q'] = $query_json; $is_mode_json = true; } } else { return $system->addError(HEURIST_INVALID_REQUEST, $savedSearchName . "Invalid search request. Missed query parameter 'q'"); } if ($is_mode_json) { $aquery = get_sql_query_clauses_NEW($mysqli, $params, $currentUser); } else { $aquery = get_sql_query_clauses($mysqli, $params, $currentUser); //!!!! IMPORTANT CALL OR compose_sql_query at once } if ($is_ids_only && @$params['needall']) { $chunk_size = PHP_INT_MAX; $aquery["limit"] = ''; } else { $chunk_size = $system->user_GetPreference('search_detail_limit'); //limit for map/timemap output } if (!isset($aquery["where"]) || trim($aquery["where"]) === '') { return $system->addError(HEURIST_DB_ERROR, "Invalid search request; unable to construct valid SQL query", null); } $query = $select_clause . $aquery["from"] . " WHERE " . $aquery["where"] . $aquery["sort"] . $aquery["limit"] . $aquery["offset"]; //error_log($is_mode_json.' '.$query); /* DEBUG if($params['q']=='doerror'){ //force error $query ='abracadabra'; } */ } $res = $mysqli->query($query); if (!$res) { $response = $system->addError(HEURIST_DB_ERROR, $savedSearchName . 'Search query error', $mysqli->error); } else { $fres = $mysqli->query('select found_rows()'); if (!$fres) { $response = $system->addError(HEURIST_DB_ERROR, $savedSearchName . 'Search query error (retrieving number of records)', $mysqli->error); } else { $total_count_rows = $fres->fetch_row(); $total_count_rows = $total_count_rows[0]; $fres->close(); if ($is_ids_only) { //------------------------ LOAD and RETURN only IDS $records = array(); while ($row = $res->fetch_row()) { array_push($records, (int) $row[0]); } $res->close(); if (@$params['vo'] == 'h3') { //output version $response = array('resultCount' => $total_count_rows, 'recordCount' => count($records), 'recIDs' => implode(',', $records)); } else { $response = array('status' => HEURIST_OK, 'data' => array('queryid' => @$params['id'], 'count' => $total_count_rows, 'offset' => get_offset($params), 'reccount' => count($records), 'records' => $records)); } } else { //---------------------------------- // read all field names $_flds = $res->fetch_fields(); $fields = array(); foreach ($_flds as $fld) { array_push($fields, $fld->name); } array_push($fields, 'rec_ThumbnailURL'); //array_push($fields, 'rec_Icon'); //last one -icon ID $rectype_structures = array(); $rectypes = array(); $records = array(); $order = array(); // load all records while ($row = $res->fetch_row()) { //3000 maximal allowed chunk array_push($row, $fieldtypes_ids ? '' : fileGetThumbnailURL($system, $row[2])); //array_push( $row, $row[4] ); //by default icon if record type ID $records[$row[2]] = $row; array_push($order, $row[2]); if (!@$rectypes[$row[4]]) { $rectypes[$row[4]] = 1; } } $res->close(); if (($istimemap_request || $params['detail'] == 'detail' || $params['detail'] == 'structure') && count($records) > 0) { //search for specific details if (!$fieldtypes_ids && $fieldtypes_ids != '') { $detail_query = 'select dtl_RecID,' . 'dtl_DetailTypeID,' . 'dtl_Value,' . 'AsWKT(dtl_Geo), 0, 0, 0 ' . 'from recDetails where dtl_RecID in (' . join(',', array_keys($records)) . ') ' . ' and dtl_DetailTypeID in (' . $fieldtypes_ids . ')'; } else { $detail_query = 'select dtl_RecID,' . 'dtl_DetailTypeID,' . 'dtl_Value,' . 'AsWKT(dtl_Geo),' . 'dtl_UploadedFileID,' . 'recUploadedFiles.ulf_ObfuscatedFileID,' . 'recUploadedFiles.ulf_Parameters ' . 'from recDetails left join recUploadedFiles on ulf_ID = dtl_UploadedFileID where dtl_RecID in (' . join(',', array_keys($records)) . ')'; } // @todo - we may use getAllRecordDetails $res_det = $mysqli->query($detail_query); if (!$res_det) { $response = $system->addError(HEURIST_DB_ERROR, $savedSearchName . 'Search query error (retrieving details)', $mysqli->error); return $response; } else { while ($row = $res_det->fetch_row()) { $recID = array_shift($row); if (!array_key_exists('d', $records[$recID])) { $records[$recID]['d'] = array(); } $dtyID = $row[0]; $val = null; if ($row[2]) { $val = $row[1] . ' ' . $row[2]; //dtl_Geo @todo convert to JSON } else { if ($row[3]) { $val = array($row[4], $row[5]); //obfuscated value for fileid } else { if (@$row[1]) { $val = $row[1]; } } } if ($val) { if (!array_key_exists($dtyID, $records[$recID]['d'])) { $records[$recID]['d'][$dtyID] = array(); } array_push($records[$recID]['d'][$dtyID], $val); } } //while $res_det->close(); ///@todo // 1. optimize loop - include into main detail loop // 2. exit loop if more than 5000 geo enabled // 3. return geojson and timeline items //additional loop for timemap request //1. exclude records without timemap data //2. limit to $chunk_size if ($istimemap_request) { $tm_records = array(); $order = array(); $rectypes = array(); foreach ($records as $recID => $record) { if (is_array(@$record['d']) && count($record['d']) > 0) { //this record is time enabled if ($istimemap_counter < $chunk_size) { $tm_records[$recID] = $record; array_push($order, $recID); $rectypes[$record[4]] = 1; } $istimemap_counter++; } } $records = $tm_records; $total_count_rows = $istimemap_counter; } //$istimemap_request } } //$need_details $rectypes = array_keys($rectypes); if ($params['detail'] == 'structure' && count($rectypes) > 0) { //rarely used in editing.js //description of recordtype and used detail types $rectype_structures = dbs_GetRectypeStructures($system, $rectypes, 1); //no groups } //"query"=>$query, $response = array('status' => HEURIST_OK, 'data' => array('queryid' => @$params['id'], 'count' => $total_count_rows, 'offset' => get_offset($params), 'reccount' => count($records), 'fields' => $fields, 'records' => $records, 'order' => $order, 'rectypes' => $rectypes, 'structures' => $rectype_structures)); if ($fieldtypes_ids) { $response['data']['fields_detail'] = explode(',', $fieldtypes_ids); } } //$is_ids_only } } return $response; }
/** * Use the supplied _REQUEST variables (or $params if supplied) to construct a query starting with $query prefix * * @param System $system * @param mixed $query - prefix (usually SELECT with list of fields) * @param mixed $params * parameters: stype - (OUTDATED) type of search: key - by tag title, all - by title of record and titles of its resource, by default by record title s - sort order (NOTE!!! sort may be defined in "q" parameter also) l or limit - limit of records o or offset w - domain of search a|all, b|bookmark, e (everything) qq - several conjunctions and disjunctions q - query string keywords for 'q' parameter url: url title: title contains t: record type id f: field id tag: tag id: id n: description usr: user id any: relatedto: sortby: * * @param mixed $currentUser - array with indexes ugr_ID, ugr_Groups (list of group ids) * we can access; Records records marked with a rec_OwnerUGrpID not in this list are omitted */ function get_sql_query_clauses($db, $params, $currentUser = null) { global $mysqli; $mysqli = $db; /* use the supplied _REQUEST variables (or $params if supplied) to construct a query starting with $select_clause */ if (!$params) { $params = array(); } //$_REQUEST; if (!defined('stype') && @$params['stype']) { define('stype', @$params['stype']); } // 1. DETECT CURRENT USER AND ITS GROUPS, if not logged search only all records (no bookmarks) ---------------------- $wg_ids = array(); //may be better use $system->get_user_group_ids() ??? if ($currentUser && @$currentUser['ugr_ID'] > 0) { if (@$currentUser['ugr_Groups']) { $wg_ids = array_keys($currentUser['ugr_Groups']); } $currUserID = $currentUser['ugr_ID']; array_push($wg_ids, $currUserID); } else { $currUserID = 0; $params['w'] = 'all'; } array_push($wg_ids, 0); // be sure to include the generic everybody workgroup $publicOnly = @$params['publiconly'] == 1; //@todo // 2. DETECT SEARCH DOMAIN ------------------------------------------------------------------------------------------ if (strcasecmp(@$params['w'], 'B') == 0 || strcasecmp(@$params['w'], BOOKMARK) == 0) { // my bookmark entries $search_domain = BOOKMARK; } else { if (@$params['w'] == 'e') { //everything - including temporary $search_domain = EVERYTHING; } else { // all records entries $search_domain = null; } } // 3a. SPECIAL CASE for _BROKEN_ $needbroken = false; if (@$params['q'] && preg_match('/\\b_BROKEN_\\b/', $params['q'])) { $params['q'] = preg_replace('/\\b_BROKEN_\\b/', '', $params['q']); $needbroken = true; } // 3b. SPECIAL CASE for _NOTLINKED_ $neednotlinked = false; if (@$params['q'] && preg_match('/\\b_NOTLINKED_\\b/', $params['q'])) { $params['q'] = preg_replace('/\\b_NOTLINKED_\\b/', '', $params['q']); $neednotlinked = true; } // 4. QUERY MAY BE SIMPLE or full expressiveness ---------------------------------------------------------------------- $query = parse_query($search_domain, @$params['q'], @$params['s'], @$params['parentquery'], $currUserID); $where_clause = $query->where_clause; // 4a. SPECIAL CASE for _BROKEN_ if ($needbroken) { $where_clause = '(to_days(now()) - to_days(rec_URLLastVerified) >= 8) ' . ($where_clause ? ' and ' . $where_clause : ''); } // 4b. SPECIAL CASE for _NOTLINKED_ if ($neednotlinked) { $where_clause = '(not exists (select rl_ID from recLinks where rl_SourceID=TOPBIBLIO.rec_ID or rl_TargetID=TOPBIBLIO.rec_ID )) ' . ($where_clause ? ' and ' . $where_clause : ''); } // 5. DEFINE USERGROUP RESTRICTIONS --------------------------------------------------------------------------------- if ($search_domain != EVERYTHING) { if ($where_clause) { $where_clause = '(' . $where_clause . ') and '; } if ($search_domain == BOOKMARK) { $where_clause .= ' (bkm_UGrpID=' . $currUserID . ' and not TOPBIBLIO.rec_FlagTemporary) '; } else { if ($search_domain == BIBLIO) { //NOT USED $where_clause .= ' (bkm_UGrpID is null and not TOPBIBLIO.rec_FlagTemporary) '; } else { $where_clause .= ' not TOPBIBLIO.rec_FlagTemporary '; } } } if ($publicOnly) { $query->recVisibilityType = "public"; } if ($query->recVisibilityType && $query->recVisibilityType != "hidden") { $where2 = '(TOPBIBLIO.rec_NonOwnerVisibility="' . $query->recVisibilityType . '")'; //'pending','public','viewable' } else { if ($query->recVisibilityType) { //hidden $where2 = 'TOPBIBLIO.rec_NonOwnerVisibility="hidden" and '; } else { $where2 = '(not TOPBIBLIO.rec_NonOwnerVisibility="hidden") or '; } $where2 = '( ' . $where2 . 'TOPBIBLIO.rec_OwnerUGrpID in (' . join(',', $wg_ids) . ') )'; } $where_clause = $where_clause . ' and ' . $where2; // 6. DEFINE LIMIT AND OFFSET --------------------------------------------------------------------------------------- $limit = get_limit($params); $offset = get_offset($params); // 7. COMPOSE QUERY ------------------------------------------------------------------------------------------------ return array("from" => $query->from_clause, "where" => $where_clause, "sort" => $query->sort_clause, "limit" => " LIMIT {$limit}", "offset" => $offset > 0 ? " OFFSET {$offset} " : ""); }