BUG 7093 Suggest adjustment for queries execution.

This commit is contained in:
Hector Cortez
2011-06-17 09:41:08 -04:00
parent a40a1229b7
commit c39eb93a60
7 changed files with 66 additions and 20 deletions

View File

@@ -475,6 +475,7 @@ _b.AutoSuggest.prototype.setHighlightedValue = function ()
* @autor Erik Amaru Ortiz <erik@colosa.com>
* This fix when a item on suggestion list have html wntities sent by json like &amp;
*/
if(this.aSug[ this.iHigh-1 ])
this.sInp = this.fld.value = html_entity_decode(this.aSug[ this.iHigh-1 ].value);;
//
@@ -498,6 +499,7 @@ _b.AutoSuggest.prototype.setHighlightedValue2 = function ()
{
if (this.iHigh)
{
if(this.aSug[ this.iHigh-1 ])
this.sInp = this.fld.value = html_entity_decode(this.aSug[ this.iHigh-1 ].value);
// move cursor to end of input (safari)

File diff suppressed because one or more lines are too long

View File

@@ -22,21 +22,53 @@ if( isset($request) ){
try{
$sData = base64_decode(str_rot13($_GET['hash']));
list($SQL, $DB_UID) = explode('@', $sData);
//fixed: improving the statement sql by krlos
$sSql=substr($SQL, 6, strlen($SQL));
$pattern = "/\bfrom\b/i";
$replacement = 'FROM';
$sSql = preg_replace($pattern, $replacement, $sSql);
$aSql = explode("FROM", $sSql);
list($SQL, $DB_UID) = explode('@|', $sData);
// Remplace values for dependent fields
$aDependentFieldsKeys = explode("|", base64_decode(str_rot13($_GET['dependentFieldsKeys'])));
$aDependentFieldsValue = explode("|", $_GET['dependentFieldsValue']);
if($aDependentFieldsKeys){
$SQL = str_replace($aDependentFieldsKeys, $aDependentFieldsValue, $SQL);
}
if (1===preg_match('/^\s*SELECT\s+([\w\W]+?)(?:\s+FROM\s+`?([^`]+?)`?)(?:\s+WHERE\s+([\w\W]+?))?(?:\s+GROUP\s+BY\s+([\w\W]+?))?(?:\s+ORDER\s+BY\s+([\w\W]+?))?(?:\s+BETWEEN\s+([\w\W]+?)\s+AND\s+([\w\W]+?))?(?:\s+LIMIT\s+(\d+)\s*,\s*(\d+))?\s*$/im', $SQL, $matches)) {
$sqlColumns = $matches[1];
$sqlFrom = isset($matches[2])?$matches[2]:'';
$sqlWhere = isset($matches[3])?$matches[3]:'';
$sqlGroupBy = isset($matches[4])?$matches[4]:'';
$sqlOrderBy = isset($matches[5])?$matches[5]:'';
$sqlLowLimit = isset($matches[8])?$matches[8]:'';
$sqlHighLimit = isset($matches[9])?$matches[9]:'';
// New SQL String
$SQL = "SELECT " . $sqlColumns . " FROM " . $sqlFrom;
$aFieldSelect = explode(",", $sqlColumns);
$sFieldSel = (count($aFieldSelect)>1 ) ? $aFieldSelect[1] : $aFieldSelect[0];
if( strlen(trim($sqlWhere))>0) {
$SQL .= " WHERE " . $sqlWhere . " AND " . $sFieldSel . " LIKE '". $_GET['input']."%'";
} else {
$SQL .= " WHERE " . $sFieldSel . " LIKE '". $_GET['input']."%'";
}
if( strlen(trim($sqlGroupBy))>0) {
$SQL .= " GROUP BY " . $sqlGroupBy;
}
if( strlen(trim($sqlOrderBy))>0) {
$SQL .= " ORDER BY " . $sqlOrderBy;
}
} else {
//fixed: improving the statement sql by krlos
$sSql=substr($SQL, 6, strlen($SQL));
$pattern = "/\bfrom\b/i";
$replacement = 'FROM';
$sSql = preg_replace($pattern, $replacement, $sSql);
$aSql = explode("FROM", $sSql);
$afieldSql = explode(",",$aSql[0]);
$afieldSql = explode(",",$aSql[0]);
if(count($afieldSql)>1)
$SQL .= " where $afieldSql[1] like '". $_GET['input']."%'";
else
$SQL .= " where $afieldSql[0] like '". $_GET['input']."%'";
//add fixed
}
if(count($afieldSql)>1)
$SQL .= " where $afieldSql[1] like '". $_GET['input']."%'";
else
$SQL .= " where $afieldSql[0] like '". $_GET['input']."%'";
//add fixed
$aRows = Array();
try {
$con = Propel::getConnection($DB_UID);
@@ -110,8 +142,9 @@ if( isset($request) ){
header("Content-Type: application/json");
echo "{\"status\":0, \"results\": [";
$arr = array();
$aReplace = array("(\r\n)", "(\n\r)", "(\n)", "(\r)");
for ($i=0;$i<count($aResults);$i++) {
$arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"".$aResults[$i]['info']."\"}";
$arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"". preg_replace($aReplace, "", $aResults[$i]['value']) ."\", \"info\": \"".$aResults[$i]['info']."\"}";
}
echo implode(", ", $arr);
echo "]}";

View File

@@ -310,6 +310,11 @@ class Form extends XmlForm
$values["{$k}_label"] = $newValues["{$k}_label"] = $v->options[$newValues[$k]];
break;
case 'suggest':
$values[$k] = $newValues[$k];
$values["{$k}_label"] = $newValues["{$k}_label"];
break;
case 'checkgroup':
case 'listbox':
if ( is_array($newValues[$k]) ) {

View File

@@ -1242,10 +1242,8 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
return $str;
}
} elseif ($this->mode === 'view') {
return '<input class="module_app_input___gray" id="form[' . $this->name . ']" name="form[' . $this->name . ']" type ="text" size="' . $this->size . '" maxlength="' . $this->maxLength . '" value=\'' . $this->htmlentities ( $value, ENT_COMPAT, 'utf-8' ) . '\' style="display:none;' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" onkeypress="' . htmlentities ( $onkeypress, ENT_COMPAT, 'utf-8' ) . '"/>' . $this->htmlentities ( $value, ENT_COMPAT, 'utf-8' );
} else {
return $this->htmlentities ( $value, ENT_COMPAT, 'utf-8' );
return $this->htmlentities ( $formVariableValue, ENT_COMPAT, 'utf-8' );
}
}
/**

View File

@@ -53,6 +53,9 @@
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_READONLY} </td> //-->
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_READONLY}</td>
</tr>
<td class="FormLabel" width="{$form_labelWidth}">{$PME_DEPENDENTFIELDS}</td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_DEPENDENTFIELDS} </td> //-->
<td class="FormFieldContent" width="{$form_fieldContentWidth}">{$form.PME_DEPENDENTFIELDS}</td>
<tr>
<td class='FormLabel' width="{$form_labelWidth}">{$PME_DEFAULTVALUE}</td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_DEFAULTVALUE} </td> //-->

View File

@@ -49,6 +49,11 @@ SELECT XMLNODE_NAME, TYPE FROM dynaForm WHERE XMLNODE_NAME = @@PME_XMLNODE_NAME
<en>Read Only</en>
</PME_READONLY>-->
<PME_DEPENDENTFIELDS type="listbox" defaultvalue="" sqlconnection="XMLDB" width="362"><![CDATA[
select XMLNODE_NAME, XMLNODE_NAME AS NAME FROM dynaForm WHERE XMLNODE_NAME <> @@PME_XMLNODE_NAME AND XMLNODE_NAME <> "" AND ( TYPE="text" or TYPE="textarea" or TYPE="dropdown" or TYPE="listbox" or TYPE="hidden" or TYPE="suggest")
]]><en>Dependent Fields<option name="">(none)</option></en>
</PME_DEPENDENTFIELDS>
<PME_DEFAULTVALUE type="text" maxlength="" size="30" defaultvalue="" >
<en>Default Value</en>
</PME_DEFAULTVALUE>