$questionFields = $resultQuestion['extra_fields']; $condition_array = $resultQuestion['condition_array']; if (!empty($condition_array)) { $extraQuestionCondition = ' AND ( '; $extraQuestionCondition .= implode($filters->groupOp, $condition_array); $extraQuestionCondition .= ' ) '; // Remove conditions already added $extraQuestionCondition = str_replace($extraCondition, '', $extraQuestionCondition); } $whereCondition .= $extraQuestionCondition; } } elseif (!empty($filters->rules)) { $whereCondition .= ' AND ( '; $counter = 0; foreach ($filters->rules as $key => $rule) { $whereCondition .= getWhereClause($rule->field, $rule->op, $rule->data); if ($counter < count($filters->rules) - 1) { $whereCondition .= $filters->groupOp; } $counter++; } $whereCondition .= ' ) '; } } } // get index row - i.e. user click to sort $sord = $_GET['sord']; // get the direction if (!$sidx) { $sidx = 1; } //2. Selecting the count FIRST
/** * Load the data array from the database, using the unique id set to get the unique record. * * @param bool $allowCreate set to true to enable new object creation. * @return false if the record already exists, true if a new record was created. */ private function load($allowCreate) { $new = $entry = null; // Set up the SQL query in case we need it... $sql = 'SELECT * FROM ' . prefix($this->table) . getWhereClause($this->unique_set) . ' LIMIT 1;'; // But first, try the cache. if ($this->use_cache) { $entry = $this->getFromCache(); } // Check the database if: 1) not using cache, or 2) didn't get a hit. if (empty($entry)) { $entry = query_single_row($sql, false); // Save this entry into the cache so we get a hit next time. if ($entry) { $this->addToCache($entry); } } // If we don't have an entry yet, this is a new record. Create it. if (empty($entry)) { if ($this->transient) { // no don't save it in the DB! $entry = array_merge($this->unique_set, $this->updates, $this->tempdata); $entry['id'] = 0; } else { if (!$allowCreate) { return NULL; // does not exist and we are not allowed to create it } else { $new = true; $this->save(); $entry = query_single_row($sql); // If we still don't have an entry, something went wrong... if (!$entry) { return null; } // Save this new entry into the cache so we get a hit next time. $this->addToCache($entry); } } } $this->data = $entry; $this->id = (int) $entry['id']; $this->loaded = true; return $new; }
$val = Database::escape_string($val); return " {$col} {$ops[$oper]} '{$val}' "; } // If there is no search request sent by jqgrid, $where should be empty $whereCondition = null; $operation = isset($_REQUEST['oper']) ? $_REQUEST['oper'] : false; $exportFormat = isset($_REQUEST['export_format']) ? $_REQUEST['export_format'] : 'csv'; $searchField = isset($_REQUEST['searchField']) ? $_REQUEST['searchField'] : false; $searchOperator = isset($_REQUEST['searchOper']) ? $_REQUEST['searchOper'] : false; $searchString = isset($_REQUEST['searchString']) ? $_REQUEST['searchString'] : false; $search = isset($_REQUEST['_search']) ? $_REQUEST['_search'] : false; $forceSearch = isset($_REQUEST['_force_search']) ? $_REQUEST['_force_search'] : false; $extra_fields = array(); if (($search || $forceSearch) && $search !== 'false') { $whereCondition = ' 1 = 1 '; $whereConditionInForm = getWhereClause($searchField, $searchOperator, $searchString); if (!empty($whereConditionInForm)) { $whereCondition .= ' AND ' . $whereConditionInForm; } $filters = isset($_REQUEST['filters']) && !is_array($_REQUEST['filters']) ? json_decode($_REQUEST['filters']) : false; /*if (!empty($filters) && !empty($filters->rules)) { $whereCondition .= ' AND ( '; $counter = 0; foreach ($filters->rules as $key => $rule) { $whereCondition .= getWhereClause($rule->field, $rule->op, $rule->data); if ($counter < count($filters->rules) -1) { $whereCondition .= $filters->groupOp; } $counter++; }
/** * Load the data array from the database, using the unique id set to get the unique record. * @return false if the record already exists, true if a new record was created. */ function load() { $new = false; $entry = null; // Set up the SQL query in case we need it... $sql = 'SELECT * FROM ' . prefix($this->table) . getWhereClause($this->unique_set) . ' LIMIT 1;'; // But first, try the cache. if ($this->use_cache) { $reporting = error_reporting(0); // TODO: fix the following code. It is flagged by E_STRICT error reporting $cache_location =& $this->cache(); $entry =& $cache_location[$this->unique_set[$this->cache_by]]; error_reporting($reporting); } // Re-check the database if: 1) not using cache, or 2) didn't get a hit. if (empty($entry)) { $entry = query_single_row($sql); } // If we don't have an entry yet, this is a new record. Create it. if (empty($entry)) { if ($this->transient) { // no don't save it in the DB! $entry = array_merge($this->unique_set, $this->updates, $this->tempdata); $entry['id'] = ''; } else { $new = true; $this->save(); $entry = query_single_row($sql); // If we still don't have an entry, something went wrong... if (!$entry) { return null; } // Then save this new entry into the cache so we get a hit next time. $this->cache($entry); } } $this->data = $entry; $this->id = $entry['id']; $this->loaded = true; return $new; }
echo getScriptJS(__FILE__); ?> "></script> <script type="text/javascript" src="../scripts/calendar.js"></script> <?php include "application_" . $_SESSION['language'] . ".php"; include "mailfunctions_" . $_SESSION['language'] . ".php"; $type = isset($_GET['type']) ? $_GET['type'] : ''; $callback_function = isset($_GET['callback']) ? $_GET['callback'] : ''; $category = isset($_GET['category']) ? $_GET['category'] : ''; $exit = false; $close_window = false; $reload_overview = false; if (isset($_POST['overview_filter'])) { //Save the selected filter, then close the window $_SESSION[$category . '_load_conditions'] = getWhereClause($_POST); $_SESSION[$category . '_filter_set'] = $_POST; $reload_overview = true; $exit = true; } if ($type == "filter") { //Show the selected filter if (!(isset($_POST['submit_filter']) || isset($_POST['order']) || isset($_POST['current']) || isset($_POST['overview_filter']) || isset($_POST['records_by_page']))) { $_POST = $_SESSION[$category . '_filter_set']; } } ?> <?php if ($exit) { ?>
echo "<table id='filters'><th>Query String</th><th>Query Filter</th><th>Query Value</th><tr id='row0'><td id='barx0'><input type='text' id='bary0'></td><td id='filx0'><select onchange='displayQueryBar(\"barx0\",\"valx0\",this.value)' id='fils0' style='width:200'><option value='none'>--SELECT-- </option><option value='gt'>Greater Than \">\"</option><option value='lt'>Less Than \"<\"</option><option value='gte'>Greater Than or Equal To '>='</option><option value='lte'>Less Than or Equal To '<='</option><option value='eq'>Equal To \"=\"</option><option value='neq'>Not Equal To '!='</option><option value='in'>In [List]</option><option value='nin'>Not In [List]</option><option value='like'>Like [RegExp]</option><option value='nlike'>Not Like [RegExp]</option></select></td><td id='valx0'><input type='text' id='valy0'> <button type='button' class='btn' onclick='addFilter(0)' id='btn0'>Add</button></td></tr></table>"; echo "<input type='hidden' id='filcount' name='filcount' value='1'></input>"; echo "<input type='hidden' id='filsum' name='filsum' value='{$x}&'></input>"; echo "<input type='hidden' value='{$nj}' class='inp' name='nbr'/>"; echo "<input type='submit' name='phase1' value='Submit'/>"; echo "</form>"; } else { $x = $_POST["filsum"]; echo $x . "<br>"; echo "<br><br><br>"; $pon = explode("&", $x); //print_r($pon); echo "\t<table class='pieChart'>"; for ($i = 0; $i < count($pon); $i++) { if ($pon[$i] != '') { $n1 = getWhereClause($pon[$i]); $w = "Select * From {$tabname} Where " . $n1; $r = mysql_query($w); $d1 = mysql_num_rows($r); echo $w; echo " <tr><td>{$n1}</td> <td>{$d1}</td></tr>"; } } echo "</table>"; } } } } } } }
function getRowsFromSQL($sql, $columns_params, $links, $records_by_page, $filter_form, $list_form, $POST_vars, $input_type, $style, $default_order, $enable_order, $enable_limit, $category = "", $default_values = array(), $images = array()) { $resource = null; $time_start = startMetro(); //Stores the Group by statement $where_clause = ""; $group_by_statement = "GROUP BY"; if (strpos($sql, $group_by_statement) !== false) { $group_by_clause = substr($sql, strpos($sql, $group_by_statement), strlen($sql) - strpos($sql, $group_by_statement)); $sql = substr($sql, 0, strpos($sql, $group_by_statement)); } else { $group_by_clause = ""; } // Check if it takes into account the default values or the POST values $buttons = array("submit_filter", "reset_filter", "reset", "overview_filter", "current", "order", "by", "records_by_page", "PHPSESSID"); $get_post_values = false; foreach ($buttons as $key => $value) { if (isset($POST_vars[$value])) { $get_post_values = true; break; } } if ($get_post_values) { $values_array = $POST_vars; } else { $values_array = $default_values; } //Take into account the filter $where_clause = getWhereClause($values_array, $category, $sql); if ($where_clause != "") { if (strpos($sql, "WHERE") === false) { $sql .= " WHERE " . $where_clause . " "; /*if (strpos($sql, "ORDER BY") === false) { $sql .= " WHERE ".$where_clause." "; } else { $sql_array = explode("ORDER BY", $sql); $sql_order = array_pop($sql_array); $sql_select = implode("ORDER BY", $sql_array); $sql = $sql_select." WHERE ".$where_clause." ORDER BY ".$sql_order; }*/ } else { $sql .= " AND " . $where_clause . " "; /*$sql_array = explode("WHERE", $sql); $sql_where = array_pop($sql_array); $sql_select = implode("WHERE", $sql_array); $sql = $sql_select." WHERE ".$where_clause." AND ".$sql_where;*/ } } $sql .= " " . $group_by_clause; //echo '<!--' . $sql . '-->'; //Construction of headers $order_by = isset($values_array['by']) ? $values_array['by'] : ''; if ($order_by == "") { $order_by = $default_order; } $order_by = $order_by + 0; //str_replace("\\","",urldecode($order_by)); $order = isset($values_array['order']) ? $values_array['order'] : ''; $row_set = "<tr>\n"; switch ($input_type['type']) { case "checkbox": $row_set .= "<th><a href=\"JavaScript:checkAll(document." . $list_form . ");\" class=\"nothing\" title=\"" . $input_type['title'] . "\" ><img src=\"../images/icons/IcoCheckAll.gif\" alt=\"All\" /></a></th>\n"; break; case "radio": $row_set .= "<th>" . $input_type['title'] . "</th>\n"; break; default: break; } if (strpos($sql, " LIMIT ") !== false) { $head_sql = substr($sql, 0, strpos($sql, " LIMIT ")); } else { $head_sql = $sql; } /* $head_select = "SELECT"; $select_pos = strpos($head_sql, $head_select) + strlen($head_select); $head_sql = substr($head_sql, $select_pos, strlen($head_sql)-$select_pos); $head_sql = $head_select." SQL_CALC_FOUND_ROWS ".$head_sql." LIMIT 0,0"; $count_sql = "SELECT FOUND_ROWS() AS Count"; */ $from_pos = strpos($head_sql, 'FROM'); $count_sql = substr($head_sql, $from_pos, strlen($head_sql) - $from_pos); $count_sql = "SELECT COUNT(*) AS `Count` " . $count_sql; $time_start_b = startMetro(); $connect_db = connect(); endMetro($time_start_b, __FUNCTION__ . " connect"); echo '<!--' . $count_sql . '-->'; /* $time_start_b = startMetro(); $resource = mysql_query($head_sql) or die(reportError(mysql_error(),__FILE__, "function", __FUNCTION__, 'Erreur SQL : '.$head_sql)); endMetro($time_start_b, __FUNCTION__." head query"); //CHRONOPHAGE */ /* $time_start_b = startMetro(); $count_res = mysql_query($count_sql) or die(reportError(mysql_error(),__FILE__, "function", __FUNCTION__, 'Erreur SQL : '.$count_sql)); endMetro($time_start_b, __FUNCTION__." count query"); $time_start_b = startMetro(); $count = mysql_fetch_assoc($count_res); endMetro($time_start_b, __FUNCTION__." count fetch"); $time_start_b = startMetro(); $count = $count['Count']; mysql_free_result($count_res); endMetro($time_start_b, __FUNCTION__." free result"); */ $time_start_b = startMetro(); $count = getDataFromSQL($count_sql, __FILE__, 'function', __FUNCTION__); endMetro($time_start_b, __FUNCTION__ . " count query"); $count = $count['Count'] > 1 ? $count['Count'] : $count[0]['Count']; $time_start_b = startMetro(); //$resource = mysql_unbuffered_query($sql) or die(reportError(mysql_error(),__FILE__, "function", __FUNCTION__, 'Erreur SQL : '.$sql)); $columns_nb = count($columns_params); //mysql_num_fields($resource); endMetro($time_start_b, __FUNCTION__ . " num fields"); $time_start_b = startMetro(); // $count = mysql_num_rows($resource); for ($i = 0; $i < $columns_nb; $i++) { // $field = mysql_field_name($resource,$i); $columns[$i] = $columns_params[$i]; $field_array = explode("|", $columns[$i]); // $field_code = str_replace("*", ".", $field_array[0]); $field_name = $field_array[1]; if (strpos($field_name, '[hidden]') === false) { if ($order_by == $i + 1 && $order == "ASC") { $next_order = "DESC"; } else { $next_order = "ASC"; } if ($order_by == $i + 1) { if ($order == "ASC") { $class = "bg_asc"; } else { $class = "bg_desc"; } $a_class = "class=\"" . $class . "\" "; $th_class = "class=\"ordered\" "; } else { $a_class = ""; $th_class = ""; } if ($enable_order) { $row_set .= "<th " . $th_class . "><a href=\"JavaScript:document." . $filter_form . ".order.value='" . $next_order . "';document." . $filter_form . ".by.value='" . ($i + 1) . "';document." . $filter_form . ".submit();\" " . $a_class . ">" . $field_name . "</a></th>\n"; } else { $row_set .= "<th>" . $field_name . "</th>\n"; } } } endMetro($time_start_b, __FUNCTION__ . " columns headers"); $time_start_b = startMetro(); //mysql_free_result($resource); close($connect_db); endMetro($time_start_b, __FUNCTION__ . " close db"); $row_set .= "</tr>\n"; if ($count > 0) { //Take into account the order if ($order_by != "" && $order_by <= $columns_nb && $enable_order) { // $order_by = explode("|",$order_by); // $order_by = str_replace("*", ".", $order_by[0]); $sql .= " ORDER BY " . $order_by . " " . $order; } //Limit the result to the current page $current_page = isset($values_array['current']) ? $values_array['current'] : ''; if ($current_page == "") { $current_page = 1; } $from_record = ($current_page - 1) * $records_by_page; $to_record = $records_by_page; if ($enable_limit) { $sql .= " LIMIT " . $from_record . ", " . $to_record . " "; } //Construction of data rows $time_start_b = startMetro(); echo '<!--' . $sql . '-->'; $values = getDataFromSQL($sql, __FILE__, "function", __FUNCTION__); endMetro($time_start_b, __FUNCTION__ . " values query"); //CHRONOPHAGE for ($i = 0; $i < $values["Count"]; $i++) { //New Row $row_set .= "<tr>\n"; //Check the condition disable the input $do_enable = true; foreach ($input_type['conditions'] as $i_key => $i_value) { if ($values[$i][$i_key] != $i_value) { $do_enable = false; break; } } //Input style switch ($input_type['type']) { case "checkbox": $row_set .= "<td><input type=\"checkbox\" "; if (!$do_enable) { $row_set .= "disabled=\"disabled\" "; } $row_set .= "class=\"input1\" style=\"border: none;\" id=\"_" . $values[$i][0] . "\" name=\"" . $values[$i][1] . "\" /></td>\n"; break; case "radio": $row_set .= "<td><input type=\"radio\" "; if (!$do_enable) { $row_set .= "disabled=\"disabled\" "; } $row_set .= "class=\"input1\" style=\"border: none;\" id=\"_" . $values[$i][0] . "\" name=\"radio_list\" value=\"" . $values[$i][0] . "\" /></td>\n"; break; default: break; } //Add cells for ($j = 0; $j < $columns_nb; $j++) { $column = $columns[$j]; $column_name = explode("|", $column); $column_name = $column_name[1]; if (strpos($column_name, '[hidden]') === false) { //New cell $row_set .= "<td>"; $this_value = htmlentities($values[$i][$j], ENT_QUOTES, 'UTF-8'); if ($this_value == "") { //Empty cell $row_set .= " "; } else { //Check the style $style_class_o = ""; $style_class_c = ""; $style_tag = ""; if (isset($style[$j])) { $style_tag = $style[$j]['tag']; } if ($style_tag != "") { $do_style = true; foreach ($style[$j]['conditions'] as $s_key => $s_value) { if ($values[$i][$s_key] != $s_value) { $do_style = false; break; } } if ($do_style) { //Apply the class to the value $style_class_o = "<" . $style_tag . " class=\"" . $style[$j]['class'] . "\">"; $style_class_c = "</" . $style_tag . ">"; } } $row_set .= $style_class_o; if (strpos($this_value, "[|]") !== false) { $this_value_array = explode("[|]", $this_value); for ($k = 0; $k < count($this_value_array); $k++) { if ($this_value_array[$k] != "") { if ($k == 0) { $myValue = getLinkedValue(getImagedValue(nl2br($this_value_array[$k]), $images[$j], $values[$i]), $links[$j], $values[$i]); } else { // $myValue = nl2br(htmlentities($this_value_array[$k], ENT_QUOTES, 'UTF-8')); $myValue = nl2br($this_value_array[$k]); } $row_set .= "<div class=\"sub_cell_" . $k . "\">" . $myValue . "</div>"; } } } else { $getlink_links_array = array(); $getlink_values_array = array(); $getimage_images_array = array(); $getimage_values_array = array(); if (isset($links[$j])) { $getlink_links_array = $links[$j]; } if (isset($images[$j])) { $getimage_images_array = $images[$j]; } if (isset($values[$i])) { $getlink_values_array = $values[$i]; $getimage_values_array = $values[$i]; } $myValue = getLinkedValue(getImagedValue(nl2br($this_value), $getimage_images_array, $getimage_values_array), $getlink_links_array, $getlink_values_array); $row_set .= $myValue; } $row_set .= $style_class_c; } $row_set .= "</td>\n"; } } $row_set .= "</tr>\n"; } } endMetro($time_start, __FUNCTION__); //Return the result return array('rows' => $row_set, 'local_count' => $values['Count'], 'total_count' => $count, 'resource_id' => $resource, 'debug' => start_comment . $sql . end_comment); }
/** * Load the data array from the database, using the unique id set to get the unique record. * * @param bool $allowCreate set to true to enable new object creation. * @return false if the record already exists, true if a new record was created. */ private function load($allowCreate) { $new = $entry = null; // First, try the cache. if ($this->use_cache) { $entry = $this->getFromCache(); } // Check the database if: 1) not using cache, or 2) didn't get a hit. if (empty($entry) && !$this->transient) { $sql = 'SELECT * FROM ' . prefix($this->table) . getWhereClause($this->unique_set) . ' LIMIT 1;'; $entry = query_single_row($sql, false); // Save this entry into the cache so we get a hit next time. if ($entry) { $this->addToCache($entry); } } // If we don't have an entry yet, this is a new record. Create it. if (empty($entry)) { if ($this->transient || !$allowCreate) { // no don't save it in the DB! // populate $this->data so that the set method will work correctly $result = db_list_fields($this->table); if ($result) { foreach ($result as $row) { $this->data[$row['Field']] = NULL; } } if ($allowCreate) { $entry = array_merge($this->data, $this->unique_set); $entry['id'] = 0; $this->addToCache($entry); } else { return NULL; // does not exist and we are not allowed to create it } } else { $new = true; $this->save(); $entry = query_single_row($sql); // If we still don't have an entry, something went wrong... if (!$entry) { return null; } // Save this new entry into the cache so we get a hit next time. $this->addToCache($entry); } } $this->data = $entry; $this->id = (int) $entry['id']; $this->loaded = true; return $new; }