function group_check_ok($groupid) { $id = parse_id($groupid); $query = 'UPDATE groups_list SET group_points = group_points - ' . GROUP_CHECK_OK_MINUS . ' WHERE groupid = ' . $id; mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__)); jscript_location($_SERVER['PHP_SELF']); }
/** * Build SQL Query */ function build_sql_query($qstring = '') { $file_id = ''; $cat_id = ''; $dynamic = TRUE; // If dynamic is off, we'll override all dynamically set variables if ($this->EE->TMPL->fetch_param('dynamic') == 'no') { $dynamic = FALSE; } $this->limit = !is_numeric($this->EE->TMPL->fetch_param('limit')) ? $this->limit : $this->EE->TMPL->fetch_param('limit'); // Parse the URL query string $this->uristr = $this->EE->uri->uri_string; if ($qstring == '') { $qstring = $this->query_string; } $this->basepath = $this->EE->functions->create_url($this->uristr); if ($qstring != '') { if ($dynamic && is_numeric($qstring)) { $file_id = $qstring; } else { // Man- this is way redundant. Maybe move some to url helper or some such?? $this->EE->load->helper('segment'); // Parse ID if ($dynamic) { $seg = parse_id($qstring); $qstring = $seg['qstring']; $file_id = $seg['entry_id']; } // Parse page number if ($dynamic or $this->EE->TMPL->fetch_param('paginate')) { $seg = parse_page_number($qstring, $this->basepath, $this->uristr); $this->p_page = $seg['p_page']; $this->basepath = $seg['basepath']; $this->uristr = $seg['uristr']; $qstring = $seg['qstring']; $page_marker = $this->p_page ? TRUE : FALSE; } /** -------------------------------------- /** Parse category indicator /** --------------------------------------*/ // Text version of the category if ($qstring != '' and $this->reserved_cat_segment != '' and in_array($this->reserved_cat_segment, explode("/", $qstring)) and $dynamic) { $qstring = preg_replace("/(.*?)\\/" . preg_quote($this->reserved_cat_segment) . "\\//i", '', '/' . $qstring); $this->EE->db->distinct(); $this->EE->db->select('cat_group'); $this->EE->db->where_in('site_id', $this->EE->TMPL->site_ids); $this->EE->functions->ar_andor_string($this->EE->TMPL->fetch_param('directory_id'), 'id'); $query = $this->EE->db->get('upload_prefs'); if ($query->num_rows() > 0) { $valid = 'y'; $last = explode('|', $query->row('cat_group')); $valid_cats = array(); foreach ($query->result_array() as $row) { if ($this->EE->TMPL->fetch_param('relaxed_categories') == 'yes') { $valid_cats = array_merge($valid_cats, explode('|', $row['cat_group'])); } else { $valid_cats = array_intersect($last, explode('|', $row['cat_group'])); } $valid_cats = array_unique($valid_cats); if (count($valid_cats) == 0) { $valid = 'n'; break; } } } else { $valid = 'n'; } if ($valid == 'y') { // the category URL title should be the first segment left at this point in $qstring, // but because prior to this feature being added, category names were used in URLs, // and '/' is a valid character for category names. If they have not updated their // category url titles since updating to 1.6, their category URL title could still // contain a '/'. So we'll try to get the category the correct way first, and if // it fails, we'll try the whole $qstring // do this as separate commands to work around a PHP 5.0.x bug $arr = explode('/', $qstring); $cut_qstring = array_shift($arr); unset($arr); $result = $this->EE->db->select('cat_id')->where('cat_url_title', $cut_qstring)->where_in('group_id', $valid_cats)->get('categories'); if ($result->num_rows() == 1) { $qstring = str_replace($cut_qstring, 'C' . $result->row('cat_id'), $qstring); } else { $result = $this->EE->db->select('cat_id')->where('cat_url_title', $qstring)->where_in('group_id', $valid_cats)->get('categories'); if ($result->num_rows() == 1) { $qstring = 'C' . $result->row('cat_id'); } } } } // Numeric version of the category if ($dynamic && preg_match("#(^|\\/)C(\\d+)#", $qstring, $match)) { $this->cat_request = TRUE; $cat_id = $match[2]; $qstring = trim_slashes(str_replace($match[0], '', $qstring)); } // Remove "N" // The recent comments feature uses "N" as the URL indicator // It needs to be removed if present if ($dynamic) { $seg = parse_n($qstring, $this->uristr); $qstring = $seg['qstring']; $this->uristr = $seg['uristr']; } } } // If the "File ID" was hard-coded, use it instead of // using the dynamically set one above if ($this->EE->TMPL->fetch_param('file_id')) { $file_id = $this->EE->TMPL->fetch_param('file_id'); } // Setup Orderby $allowed_sorts = array('date', 'upload_date', 'random'); $order_by = $this->EE->TMPL->fetch_param('orderby', 'upload_date'); $sort = $this->EE->TMPL->fetch_param('sort', 'desc'); $random = $order_by == 'random' ? TRUE : FALSE; $order_by = ($order_by == 'date' or !in_array($order_by, $allowed_sorts)) ? 'upload_date' : $order_by; // Need to add a short_name to the file upload prefs to be consistent with gallery //$dir_ids = array(); // Start the cache so we can use for pagination $this->EE->db->start_cache(); // Fetch the file ids if ($this->EE->TMPL->fetch_param('category') or $this->EE->TMPL->fetch_param('category_group') or $cat_id != '') { $this->EE->db->distinct(); // We use 'LEFT' JOIN when there is a 'not' so that we get // entries that are not assigned to a category. if ((substr($this->EE->TMPL->fetch_param('category_group'), 0, 3) == 'not' or substr($this->EE->TMPL->fetch_param('category'), 0, 3) == 'not') && $this->EE->TMPL->fetch_param('uncategorized_entries') !== 'n') { $this->EE->db->join('file_categories', 'exp_files.file_id = exp_file_categories.file_id', 'LEFT'); $this->EE->db->join('categories', 'exp_file_categories.cat_id = exp_categories.cat_id', 'LEFT'); } else { $this->EE->db->join('file_categories', 'exp_files.file_id = exp_file_categories.file_id', 'INNER'); $this->EE->db->join('categories', 'exp_file_categories.cat_id = exp_categories.cat_id', 'INNER'); } } $this->EE->db->select('exp_files.file_id'); $this->EE->db->from('files'); if ($file_id != '') { $this->EE->functions->ar_andor_string($file_id, 'exp_files.file_id') . ' '; } // If directory_id is set in template if (($directory_ids = $this->EE->TMPL->fetch_param('directory_id')) != FALSE) { $this->EE->functions->ar_andor_string($directory_ids, 'upload_location_id'); } else { $this->EE->db->where_in('exp_files.site_id', $this->EE->TMPL->site_ids); } // Limit query by category if ($this->EE->TMPL->fetch_param('category')) { // Doing a simplified version for now- no & allowed ?? if (stristr($this->EE->TMPL->fetch_param('category'), '&')) { } else { if (substr($this->EE->TMPL->fetch_param('category'), 0, 3) == 'not' && $this->EE->TMPL->fetch_param('uncategorized_entries') !== 'n') { // $str, $field, $prefix = '', $null=FALSE $this->EE->functions->ar_andor_string($this->EE->TMPL->fetch_param('category'), 'exp_categories.cat_id', '', TRUE); } else { $this->EE->functions->ar_andor_string($this->EE->TMPL->fetch_param('category'), 'exp_categories.cat_id'); } } } if ($this->EE->TMPL->fetch_param('category_group')) { if (substr($this->EE->TMPL->fetch_param('category_group'), 0, 3) == 'not' && $this->EE->TMPL->fetch_param('uncategorized_entries') !== 'n') { $this->EE->functions->ar_andor_string($this->EE->TMPL->fetch_param('category_group'), 'exp_categories.group_id', '', TRUE); } else { $this->EE->functions->ar_andor_string($this->EE->TMPL->fetch_param('category_group'), 'exp_categories.group_id'); } } if ($this->EE->TMPL->fetch_param('category') === FALSE && $this->EE->TMPL->fetch_param('category_group') === FALSE) { if ($cat_id != '' and $dynamic) { $this->EE->db->where('exp_categories.cat_id', $cat_id); } } $this->EE->db->stop_cache(); if ($this->paginate == TRUE) { //$this->EE->db->select('exp_files.file_id'); $total = $this->EE->db->count_all_results(); $this->absolute_results = $total; $this->create_pagination($total); } // We do the select down here as it could have been lost from cache anyway if ($this->paginate == TRUE) { $this->EE->db->select('exp_files.file_id'); } // Add sorting $this_sort = $random ? 'random' : strtolower($sort); $this->EE->db->order_by($order_by, $this_sort); // Add the limit $this_page = ($this->p_page == '' or $this->limit > 1 and $this->p_page == 1) ? 0 : $this->p_page; $this->EE->db->limit($this->limit, $this_page); //Fetch the file_id numbers $query = $this->EE->db->get(); $this->EE->db->flush_cache(); if ($query->num_rows() == 0) { $this->sql = ''; return; } foreach ($query->result() as $row) { $file_ids[] = $row->file_id; } // Build the full SQL query $this->EE->db->select('*'); $this->EE->db->from('files'); $this->EE->db->join('upload_prefs', 'upload_prefs.id = files.upload_location_id', 'LEFT'); $this->EE->db->where_in('file_id', $file_ids); $this->EE->db->order_by($order_by, $this_sort); $this->sql = $this->EE->db->get(); }