function index() { $data = array(); $data['breadcrumb'] = set_crumbs(array(current_url() => 'Users')); $this->load->library('pagination'); $this->load->model('users_model'); $this->load->model('groups_model'); $data['query_string'] = !empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''; // Hide super admin users from everyone but super admins if ($this->Group_session->type != SUPER_ADMIN) { $this->groups_model->where('type !=', SUPER_ADMIN); $this->users_model->where_related_groups('type !=', SUPER_ADMIN); } // Get groups for group filter $data['Groups'] = $this->groups_model->get(); // Process Filter Using Admin Helper $filter = process_filter('users'); // Filter results by search query if (isset($filter['search'])) { $this->users_model->where("(concat_ws(' ', first_name, last_name) LIKE '%{$filter['search']}%' OR email LIKE '%{$filter['search']}%')"); } // Filter results by group if (isset($filter['group_id'])) { $this->users_model->where("group_id", $filter['group_id']); } $per_page = 50; // Query $data['Users'] = $this->users_model->order_by($this->input->get('sort') ? $this->input->get('sort') : 'last_name', $this->input->get('order') ? $this->input->get('order') : 'asc')->include_related('groups', 'name')->get_paged($this->uri->segment(4), $per_page, TRUE); $config['base_url'] = site_url(ADMIN_PATH . '/users/index/'); $config['per_page'] = $per_page; $config['uri_segment'] = '4'; $config['num_links'] = 5; $config['suffix'] = $data['query_string']; $config['total_rows'] = $data['Users']->paged->total_rows; $this->pagination->initialize($config); $this->template->view('admin/users/users', $data); }
function index() { $data = array(); $data['breadcrumb'] = set_crumbs(array(current_url() => 'Pages')); // Load libraries and models $this->load->model('entries_model'); $this->load->model('content_types_model'); $this->load->model('revisions_model'); $this->load->library('pagination'); $data['query_string'] = !empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''; $data['content_types_filter'] = array('' => ''); $data['content_types_add_entry'] = array(); // Process Filter using Admin Helper $filter = process_filter('entries'); // Define fields the search filter searches $search = array(); if (isset($filter['search'])) { $search['title'] = $filter['search']; $search['slug'] = $filter['search']; $search['id'] = $filter['search']; unset($filter['search']); } // Pagination Settings $per_page = 50; // If user not a super admin only get the content types and entires allowed for access if ($this->Group_session->type != SUPER_ADMIN) { $this->content_types_model->where('restrict_admin_access', 0)->or_where_related('admin_groups', 'group_id', $this->Group_session->id); $this->entries_model->group_start()->where('restrict_admin_access', 0)->or_where_related('content_types/admin_groups', 'group_id', $this->Group_session->id)->group_end(); } // Build content type filter dropdown // and add entry's list of content types $Content_types = $this->content_types_model->order_by('title', 'asc')->get(); foreach ($Content_types as $Content_type) { $entries_count = $Content_type->entries->count(); // Only add the content type to the Add Entry dropdown if it has not reached the // limit of entries allowed. An empty entries_allowed is unlimited if ($Content_type->entries_allowed == '' || $entries_count < $Content_type->entries_allowed || $entries_count == 0 && $Content_type->entries_allowed > 0) { $data['content_types_add_entry'][$Content_type->id] = $Content_type->title; } // Only add the content type to the filter dropdown if it has one or more entries if ($entries_count > 0) { $data['content_types_filter'][$Content_type->id] = $Content_type->title; } } $this->entries_model->include_related('content_types', 'title'); // Filter by search string if (!empty($search)) { $this->entries_model->group_start()->or_like($search)->group_end(); } // Filter by dropdowns if (!empty($filter)) { $this->entries_model->group_start()->where($filter)->group_end(); } // Finalize and sort entries query $data['Entries'] = $this->entries_model->order_by($this->input->get('sort') ? $this->input->get('sort') : 'modified_date', $this->input->get('order') ? $this->input->get('order') : 'desc')->get_paged($this->uri->segment(5), $per_page, TRUE); // Create Pagination $config['base_url'] = site_url(ADMIN_PATH . '/content/entries/index/'); $config['total_rows'] = $data['Entries']->paged->total_rows; $config['per_page'] = $per_page; $config['uri_segment'] = '5'; $config['num_links'] = 5; $config['suffix'] = $data['query_string']; $this->pagination->initialize($config); $this->template->view('admin/entries/entries', $data); }
$page = isset($_GET['p']) ? $_GET['p'] : 1; $per_page = isset($_GET['pp']) ? $_GET['pp'] : 10; // Connect to the database $db = db_connect($database); // Save these variables for automatic URL formation later on. $display = array(); $display['id'] = $batch_id; $display['db'] = $database; $display['p'] = $page; $display['pp'] = $per_page; $display['filter_type'] = array(); // // Process the filtering parameters // $param = array($batch_id); process_filter($display); prepare_filter_parameters($display, $param); // // Prepare some SQL queries // $query = "SELECT batches.id as id, date, description, type FROM batches " . "WHERE batches.id=?"; $db['batch_sth'] = $db['dbh']->prepare($query); check_db_error($db['batch_sth'], __FILE__, __LINE__); $query = "SELECT COUNT(tag_id) as count FROM catalog_index " . "WHERE batch_id=?"; $query .= apply_query_filters($display); $db['count_sth'] = $db['dbh']->prepare($query); check_db_error($db['count_sth'], __FILE__, __LINE__); $query = "SELECT alleles as count FROM catalog_index " . "WHERE batch_id=? AND tag_id=?"; $db['allele_sth'] = $db['dbh']->prepare($query); check_db_error($db['allele_sth'], __FILE__, __LINE__); $query = "SELECT col, rank_2 FROM catalog_snps " . "JOIN batches ON (catalog_snps.batch_id=batches.id) " . "WHERE batch_id=? AND tag_id=? ORDER BY col";
function process_geomap($MAPCFG, $map_name, &$map_config) { $params = $MAPCFG->getSourceParams(); list($image_name, $image_path, $data_path) = geomap_files($params); // Load the list of locations $locations = geomap_get_locations($params); // This source does not directly honor the existing map configs. It saves // the existing config to use it later for modifying some object parameters. // The existing map config must not create new objects. The truth about the // existing objects comes only from this source. $saved_config = $map_config; $map_config = array(); $iconset = $params['iconset']; list($icon_w, $icon_h) = iconset_size($iconset); // Adapt the global section $map_config[0] = $saved_config[0]; $map_config[0]['map_image'] = $image_name . '?' . time() . '.png'; $map_config[0]['iconset'] = $iconset; // Now add the objects to the map foreach ($locations as $loc) { $object_id = $MAPCFG->genObjId($loc['name']); $map_config[$object_id] = array('type' => 'host', 'host_name' => $loc['name'], 'iconset' => $iconset, 'object_id' => $object_id, 'alias' => $loc['alias'], 'lat' => $loc['lat'], 'long' => $loc['long']); if (isset($loc['backend_id'])) { $map_config[$object_id]['backend_id'] = array($loc['backend_id']); } } unset($locations); // Now apply the filters. Though the map can be scaled by the filtered hosts process_filter($MAPCFG, $map_name, $map_config, $params); // Terminate empty views if (count($map_config) <= 1) { throw new GeomapError(l('Got empty map after filtering. Terminate rendering geomap.')); } // Now detect the upper and lower bounds of the locations to display // Left/upper and right/bottom // north/south $min_lat = 90; $max_lat = -90; // east/west $min_long = 180; $max_long = -180; foreach ($map_config as $obj) { if ($obj['type'] == 'global') { continue; } if ($obj['lat'] < $min_lat) { $min_lat = $obj['lat']; } if ($obj['lat'] > $max_lat) { $max_lat = $obj['lat']; } if ($obj['long'] < $min_long) { $min_long = $obj['long']; } if ($obj['long'] > $max_long) { $max_long = $obj['long']; } } // Fix equal coordinates (Simply add some space on all sides) $min_lat -= $params['geomap_border']; $max_lat += $params['geomap_border']; $min_long -= $params['geomap_border']; $max_long += $params['geomap_border']; // FIXME: Too small min/max? What is the minimum bbox size? //echo $min_lat . ' - ' . $max_lat. ' - '. $mid_lat.'\n'; //echo $min_long . ' - ' . $max_long. ' - ' . $mid_long; if (!$params['width'] || !$params['height']) { throw new GeomapError(l('Missing mandatory "width" and "height" parameters."')); } // Using this API: http://pafciu17.dev.openstreetmap.org/ $url = cfg('global', 'geomap_server') . '?module=map' . '&width=' . $params['width'] . '&height=' . $params['height'] . '&type=' . $params['geomap_type']; // The geomap zoom seems to be something different than the nagvis zoom. Use // the dedicated geomap_zoom parameter if (isset($params['geomap_zoom']) && $params['geomap_zoom'] != '') { $mid_lat = ($min_lat + $max_lat) / 2; $mid_long = ($min_long + $max_long) / 2; $url .= '&zoom=' . $params['geomap_zoom'] . '¢er=' . $mid_long . ',' . $mid_lat; } else { $url .= '&bbox=' . $min_long . ',' . $max_lat . ',' . $max_long . ',' . $min_lat; } //file_put_contents('/tmp/123', $url); // Fetch the background image when needed if (!file_exists($image_path) || geomap_source_age($params) > filemtime($image_path)) { // Allow/enable proxy $contents = geomap_get_contents($url); file_put_contents($image_path, $contents); } // Fetch the map bounds when needed if (!file_exists($data_path) || geomap_source_age($params) > filemtime($data_path)) { // Get the lat/long of the image bounds. The api adds a border area to the // generated image. This is good since this makes the outer nodes not touch // the border of the image. But this makes calculation of the x/y coords // problematic. I found a parameter which tells us the long/lat coordinates // of the image bounds. // http://pafciu17.dev.openstreetmap.org/?module=map&bbox=6.66748,53.7278,14.5533,51.05&width=1500&height=557&type=osmarender&bboxReturnFormat=csv // 2.373046875,54.239550531562,18.8525390625,50.499452103968 $data_url = $url . '&bboxReturnFormat=csv'; $contents = geomap_get_contents($data_url); if (!$contents || ord($contents[0]) == 137 && ord($contents[1]) == 80 && ord($contents[2]) == 78) { // Got an png image as answer - catch this! throw new GeomapError(l('Got invalid response from "[U]". This is mostly caused by an unhandled request.', array('U' => $data_url))); } if (!preg_match('/^-?[0-9]+\\.?[0-9]*,-?[0-9]+\\.?[0-9]*,-?[0-9]+\\.?[0-9]*,-?[0-9]+\\.?[0-9]*$/i', $contents)) { throw new GeomapError(l('Got invalid data from "[U]": "[C]"', array('U' => $data_url, 'C' => json_encode($contents)))); } file_put_contents($data_path, $contents); $parts = explode(',', $contents); } else { $parts = explode(',', file_get_contents($data_path)); } $img_left = (double) $parts[0]; $img_top = (double) $parts[1]; $img_right = (double) $parts[2]; $img_down = (double) $parts[3]; $long_diff = $img_right - $img_left; $lat_diff = $img_top - $img_down; $long_para = $params['width'] / $long_diff; $lat_para = $params['height'] / $lat_diff; $lat_mult = $params['height'] / (ProjectF($img_top) - ProjectF($img_down)); // Now add the coordinates to the map objects foreach ($map_config as &$obj) { if (!isset($obj['lat'])) { continue; } // Calculate the lat (y) coords $obj['y'] = round((ProjectF($img_top) - ProjectF($obj['lat'])) * $lat_mult - $icon_h / 2); if ($obj['y'] < 0) { $obj['y'] = 0; } // Calculate the long (x) coords $obj['x'] = round($long_para * ($obj['long'] - $img_left) - $icon_w / 2); if ($obj['x'] < 0) { $obj['x'] = 0; } unset($obj['lat']); unset($obj['long']); } return true; // allow caching }
/** * A source can modify the map configuration before it is used for further processing. * Such a source is a key which points to a "process", "params" and "changed" function * which can * 1. modify the map config array * 2. gather all the parameters used in this source * 3. tell the source processing that the data used in this source has changed and the * source needs processed again */ private function processSources() { global $_MAINCFG; $sources = $this->getValue(0, 'sources'); if (!$sources) { return; } // 1. Check if there is a cache file for a query with this params $params = $this->getSourceParams(); // FIXME: Add a flag to exclude options from cache file naming if (isset($params['source_file'])) { unset($params['source_file']); } $param_values = $this->paramsToString($params); $cacheFile = cfg('paths', 'var') . 'source-' . $this->name . '.cfg-' . $param_values . '-' . CONST_VERSION . '.cache'; $CACHE = new GlobalFileCache(array(), $cacheFile); // 2a. Check if the cache file exists // 2b. Check if the cache file is newer than the latest changed source $cache_sources = $CACHE->isCached(); $cache_map = $this->CACHE->isCached(); $cache_maincfg = $_MAINCFG->isCached(); if ($cache_sources != -1 && $cache_map != -1 && $cache_maincfg != -1 && $cache_sources >= $cache_maincfg && $cache_sources >= $cache_map && !$this->sourcesChanged($cache_sources)) { // 3a. Use the cache $this->mapConfig = $CACHE->getCache(); return; } $cacheable = true; // 3b. Process all the sources foreach ($sources as $source) { $func = 'process_' . $source; if (!function_exists($func)) { throw new NagVisException(l('Requested source "[S]" does not exist', array('S' => $source))); } try { $cacheable &= $func($this, $this->name, $this->mapConfig); } catch (Exception $e) { if (!$this->ignoreSourceErrors) { throw $e; } } } // Call process filter implicit if not already done process_filter($this, $this->name, $this->mapConfig); if ($cacheable) { $CACHE->writeCache($this->mapConfig, 1); } // FIXME: Invalidate/remove cache files on changed configurations }
$q[] = "by={$by}"; $title .= (!isset($type) ? 'Entries ' : '') . "by {$by} "; } } else { if (isset($q)) { $q[] = 'by=' . CoreUtils::FIXPATH_EMPTY; } } } $q = array(); if (isset($_GET['js'])) { $q[] = 'js=' . $_GET['js']; } process_filter($q); $Pagination = new Pagination('admin/logs', 20, $Database->count('log')); $heading = 'Global logs'; if (!empty($title)) { $title .= '- '; } $title .= "Page {$Pagination->page} - {$heading}"; CoreUtils::fixPath("/admin/logs/{$Pagination->page}" . (!empty($q) ? '?' . implode('&', $q) : '')); process_filter(); $LogItems = $Database->orderBy('timestamp')->orderBy('entryid')->get('log', $Pagination->getLimit()); if (isset($_GET['js'])) { $Pagination->respond(Logs::getTbody($LogItems), '#logs tbody'); } CoreUtils::loadPage(array('title' => $title, 'view' => "{$do}-logs", 'css' => "{$do}-logs", 'js' => array("{$do}-logs", 'paginate'))); break; default: CoreUtils::notFound(); }
$batch_id = isset($_GET['id']) ? $_GET['id'] : 0; $email = isset($_GET['email']) ? $_GET['email'] : ""; $data_type = isset($_GET['dtype']) ? $_GET['dtype'] : "haplo"; $map_type = isset($_GET['mtype']) ? $_GET['mtype'] : "gen"; $depth_lim = isset($_GET['dlim']) ? $_GET['dlim'] : "1"; $man_cor = isset($_GET['mcor']) ? $_GET['mcor'] : "0"; $ex_type = isset($_GET['otype']) ? $_GET['otype'] : "tsv"; // Connect to the database $db = db_connect($database); // Save these variables for automatic URL formation later on. $display = array(); $display['id'] = $batch_id; $display['db'] = $database; $display['filter_type'] = array(); $filters = array(); process_filter($display, $filters); // // Create a new catalog object to hold filtered loci // $catalog = new Catalog($db, $batch_id, $display); $catalog->determine_count(); $loci_cnt = $catalog->num_loci(); $mc = $man_cor > 0 ? "-c" : ""; if ($data_type == "haplo") { $dt = "-a haplo"; $dl = "-L {$depth_lim}"; } else { if ($data_type == "geno") { $dt = "-a geno -m {$map_type} {$mc}"; $dl = ""; }