This topic is locked

Edit box with Ajax Popup

4/23/2016 2:01:26 PM
PHPRunner General questions
lefty author

When using edit as ajax on add / edit pages , always brings up with what the field data starts with . I have some complex data that users may not find with starts at . So I am looking to change code to contains . Like the word "Captain Morgan Rum". How can I change code so if they type "Morgan" it also will come up ? anyone in the forum run into this?

L
lewis 5/3/2016

I would be interested as well.

need2sleepDevClub member 5/15/2016

Use "%" before your search query.
%rum
will return
Bacardi _Rum

_Captain Morgan Rum
etc.

HJB 5/16/2016

Modify generated ..._lookupsuggest.php file

Find all occurencies of this line there:
QUOTE

$LookupSQL .= "BandName LIKE '".db_addslashes($value)."%'";and replace them with:
QUOTE

$LookupSQL .= "BandName LIKE '%".db_addslashes($value)."%'";
P.S. (as well set AJAX to start only after 3 characters are entered to keep server operations cool)
searchSuggest function in include\ajaxsuggest.js file:

--------------------------------------------------------------------------

function searchSuggest(oEvent,oElement,searchType)

{

if(oElement.value.length<3) return;

oEvent=window.event || oEvent;

lefty author 5/16/2016



Modify generated ..._lookupsuggest.php file

Find all occurencies of this line there:
QUOTE

$LookupSQL .= "BandName LIKE '".db_addslashes($value)."%'";and replace them with:
QUOTE

$LookupSQL .= "BandName LIKE '%".db_addslashes($value)."%'";
P.S. (as well set AJAX to start only after 3 characters are entered to keep server operations cool)
searchSuggest function in include\ajaxsuggest.js file:

--------------------------------------------------------------------------

function searchSuggest(oEvent,oElement,searchType)

{

if(oElement.value.length<3) return;

oEvent=window.event || oEvent;


Yes , I looked at the lookupsuggest.php file . I am using phprunner 8.1 and in that file it is global setting. It does not point to specific table. Looking at the code it does not look like you can modify the global sql. As it will not know which table to lookup if you have more than one edit as ajax field in any given table.

HJB 5/17/2016

https://xlinesoft.com/phprunner/docs/ajax_features.htm
Lookup wizard as Edit box with AJAX popup
... check TABLE DEPENDENCY options seen on the right of the relevant section.

lefty author 5/17/2016



https://xlinesoft.com/phprunner/docs/ajax_features.htm
Lookup wizard as Edit box with AJAX popup
... check TABLE DEPENDENCY options seen on the right of the relevant section.


Cannot find the code you supplied on your last post . So I am listing it below , so you see the lookup is one, I have mutiples of these type of fields (lookup - edit box with Ajax popup. So look at code be low . I do not see '

the changes you suggest above anywhere in the file. Any help would be appreciated. Thanks.
lookupsuggest.php - code below
<?php

@ini_set("display_errors","1");

@ini_set("display_startup_errors","1");
require_once("include/dbcommon.php");
header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");
$table = postvalue("table");

$pageType = postvalue("pageType");

if($pageType == "list")

$pageType = "search";

$strTableName = GetTableByShort($table);
if (!checkTableName($table))

{

exit(0);

}
require_once("include/".$table."_variables.php");
$cipherer = new RunnerCipherer($strTableName);

$gSettings = new ProjectSettings($strTableName, $pageType);
$field = postvalue('searchField');

$value = postvalue('searchFor');

$output = "";

$response = array();

$category = postvalue('category');

$LookupSQL = "";

$lookupValue = postvalue('lookupValue');

$isExistParent = postvalue('isExistParent');

$searchByLinkField = postvalue('searchByLinkField');
$values = postvalue('multiselection') ? splitvalues($value) : array($value);
// convert into an array as parent ctrl can have multiple values

$lookupCategory = !$isExistParent ? array() : splitvalues($category);
// if suggest for dashboard search

if ($gSettings->getNType() == DASHBOARD_SEARCH)

{

$dashFields = $gSettings->getDashboardSearchFields();

$table = GoodFieldName($dashFields[$field][0]["table"]);

$strTableName = GetTableByShort($table);

$field = GoodFieldName($dashFields[$field][0]["field"]);

if (!checkTableName($table))

{

exit(0);

}

require_once("include/".$table."_variables.php");

$cipherer = new RunnerCipherer($strTableName);

$gSettings = new ProjectSettings($strTableName, $pageType);

}
if( $strTableName != "Employees" )

{

if(!isLogged())

return;
if(!CheckSecurity(@$SESSION["".$strTableName."_OwnerID"],"Edit") && !CheckSecurity(@$SESSION["".$strTableName."_OwnerID"],"Add") && !CheckSecurity(@$SESSION["".$strTableName."_OwnerID"],"Search"))

return;

}

else

{

$checkResult = true;

if($field=="userid")

$checkResult=false;
if($field=="password")

$checkResult=false;
if($field=="fldemail")

$checkResult=false;
if($checkResult)

{

if(!isLogged())

return;

if(!CheckSecurity(@$SESSION["".$strTableName."_OwnerID"],"Edit") && !CheckSecurity(@$SESSION["".$strTableName."_OwnerID"],"Add") && !CheckSecurity(@$SESSION["".$strTableName."_OwnerID"],"Search"))

return;

}

}
$hasWhere = false;

$fieldsArr = $gSettings->getFieldsList();

$lwLinkField = '';

$lookupField = '';

$lwDisplayField = '';

$lookupConnection = $cman->getDefault();
foreach ($fieldsArr as $f)

{

$fEditFormat = $gSettings->getEditFormat($f);

if ($fEditFormat != EDIT_FORMAT_LOOKUP_WIZARD || GoodFieldName($f) != $field)

{

continue;

}
$lookupField = $f;

$LookupType = $gSettings->getLookupType($f);

if ($LookupType == LT_LOOKUPTABLE || $LookupType == LT_QUERY)

{

$lookupTable = $gSettings->getLookupTable($f);

if( $LookupType == LT_QUERY )

$lookupConnection = $cman->byTable( $lookupTable );

else

{

$connId = $gSettings->getNotProjectLookupTableConnId( $f );

$lookupConnection = strlen( $connId ) ? $cman->byId( $connId ) : $cman->getDefault();

}
$linkFieldName = $gSettings->getLinkField($f);

$displayFieldName = $gSettings->getDisplayField($f);

$linkAndDisplaySame = $displayFieldName == $linkFieldName;

$lookupOrderBy = $gSettings->getLookupOrderBy($f);
$lwDisplayField = RunnerPage::sqlFormattedDisplayField($f, $lookupConnection, $gSettings);
if( $lookupConnection->dbType == nDATABASE_MSSQLServer )

$strUniqueOrderBy = $lookupOrderBy;
if($LookupType == LT_QUERY)

{

$lookupPSet = new ProjectSettings($lookupTable, $pageType);

$lookupCipherer = new RunnerCipherer($lookupTable);

$lookupQueryObj = $lookupPSet->getSQLQuery();
if($gSettings->getCustomDisplay($f))

$lookupQueryObj->AddCustomExpression($displayFieldName, $lookupPSet, $strTableName, $f);
$lookupQueryObj->ReplaceFieldsWithDummies($lookupPSet->getBinaryFieldsIndices());

}

else

{

$LookupSQLTable = "SELECT ";

$lwLinkField = $lookupConnection->addFieldWrappers($gSettings->getLinkField($f));

if ($gSettings->isLookupUnique($f))

{

$LookupSQLTable .= "DISTINCT ";

}

$LookupSQLTable .= $cipherer->GetLookupFieldName($lwLinkField, $f, null, true);

if( $lookupConnection->dbType == nDATABASE_MSSQLServer )

{

if( $strUniqueOrderBy && $gSettings->isLookupUnique($f) )

$LookupSQLTable .= ",".$lookupConnection->addFieldWrappers( $strUniqueOrderBy );

}

if(!$linkAndDisplaySame)

$LookupSQLTable .= ",".($lwDisplayField == $lwLinkField ? $cipherer->GetFieldName($lwDisplayField, $f, true) : $lwDisplayField);
$LookupSQLTable .= " FROM ".$lookupConnection->addTableWrappers($lookupTable)." ";

}
$strLookupWhere = GetLWWhere($f, $pageType, $strTableName);

if($LookupType == LT_QUERY)

{

$secOpt = $lookupPSet->getAdvancedSecurityType();

if($secOpt == ADVSECURITY_VIEW_OWN)

$strLookupWhere = whereAdd($strLookupWhere, SecuritySQL("Search", $lookupTable));

}

if ($strLookupWhere)

{

$strLookupWhere = " (".$strLookupWhere.") AND ";

}
if($LookupType == LT_QUERY)

{

if($gSettings->getCustomDisplay($f))

$likeField = $searchByLinkField ? $linkFieldName : $displayFieldName;

else

$likeField = RunnerPage::_getFieldSQLDecrypt($searchByLinkField ? $linkFieldName : $displayFieldName, $lookupConnection ,$lookupPSet, $cipherer);

}

else

$likeField = $cipherer->GetFieldName($lwDisplayField, $f);
if ($searchByLinkField)

$likeConditionField = $LookupType == LT_QUERY ? $linkFieldName : $f;

else

$likeConditionField = $LookupType == LT_QUERY ? $displayFieldName : $f;
$likeWheres = array();

foreach($values as $fieldValue)

{

if($LookupType == LT_QUERY)

$likeWheres[] = $likeField.$lookupCipherer->GetLikeClause($likeConditionField, $fieldValue);

else

$likeWheres[] = $likeField.$cipherer->GetLikeClause($likeConditionField, $fieldValue);

}

$strLookupWhere.= implode(' OR ', $likeWheres);
if($gSettings->useCategory($f) && ($isExistParent || postvalue('editMode') != MODE_SEARCH))

{

$arLookupWhere = array();

foreach($lookupCategory as $arLookupCategory)

{

$cvalue = make_db_value($gSettings->getCategoryControl($f), $arLookupCategory);

$arLookupWhere[] = $lookupConnection->addFieldWrappers($gSettings->getCategoryFilter($f))."=".$cvalue;

}

$arLookupWhereToStr = (count($arLookupWhere) == 1) ? $arLookupWhere[0] : "(".implode(" OR ", $arLookupWhere).")";

if(count($arLookupWhere))

$strLookupWhere = whereAdd($strLookupWhere, $arLookupWhereToStr);

}

if(strlen($lookupOrderBy))

{

$lookupOrderBy = $lookupConnection->addFieldWrappers($lookupOrderBy);

if($gSettings->isLookupDesc($f))

$lookupOrderBy .= ' DESC';

}

if($LookupType == LT_QUERY)

{

$LookupSQL = $lookupQueryObj->toSql(whereAdd($lookupQueryObj->m_where->toSql($lookupQueryObj), $strLookupWhere),

strlen($lookupOrderBy) ? ' ORDER BY '.$lookupOrderBy : null);

}else

{

$LookupSQL = $LookupSQLTable." where ".$strLookupWhere;

if ( !$gSettings->isLookupUnique($f) || nDATABASE_Access != $lookupConnection->dbType )

{

if ($lookupOrderBy)

{

$LookupSQL.= " ORDER BY ".$lookupOrderBy;

}

}

}

}

if( strlen(GetLWWhere($f, $pageType, $strTableName)) )

{

$hasWhere = true;

}

break;

}

lefty author 5/17/2016



https://xlinesoft.com/phprunner/docs/ajax_features.htm
Lookup wizard as Edit box with AJAX popup
... check TABLE DEPENDENCY options seen on the right of the relevant section.


As you see in the above code . This is basically the setup of edit box ajax. It does not show each invidual table with fields to change in the lookupsuggest.php file so am I looking at the wrong file if your code above is supposed to work?

HJB 5/18/2016

@John - I took the "global settings" on bandname oriented AJAX from my archive and most probably it's only valid from some previous PHPR versions. Anyway, global settings have NOTHING to do with your problem at all, say, to only pick certain information related to the ADD/EDIT field from a particular table. As the code above is highly complex and as well the "Edit box with Ajax Popup" dedicated pick-up dependencies are only MAIN table oriented rather than ANY ELSE table, so, in my opinion, the only way to solve the problem is a) to look at the SQL QUERY BUILDER inside PHPR to see where the links between whatsoever are lined-up (to get a general good graphical overview rather than to run through coded lines) and <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=79390&image=1&table=forumreplies' class='bbc_emoticon' alt='B)' /> to drill a little bit deeper into SQL QUERY options (e.g. via Google) to manually adjust the table content dedications per ADD/EDIT field then. Say, in my opinion, the only time and energy way to go is to manually draw lines inside the PHPR's SQL query builder to those very table(s) you are eyeing on on per different ADD/EDIT fields on Ajax Popups with some freshly gained knowledge base on SQL QUERIES, TABLE POINT, FILTERING and else. Finally, on global settings, it seems that PHPR v8.1 is already equipped with same:
Citing excerpt out of https://xlinesoft.com/phprunner/docs/ajax_features.htm#lookupaseditbox

Note: If for some reasons you don't want to use AJAX-based functionality then all you need to do is to change the $useAJAX and $suggestAllContent variables value in the include\appsettings.php file to false.
$useAJAX = false;
$suggestAllContent = false;

unquote
Yet, as said, that issue is of secondary character while dedication of specific table content to various ADD/EDIT fields under AJAX Popup is a primary issue to get hopefully solved by you as per suggestions above.

lefty author 5/18/2016



@John - I took the "global settings" on bandname oriented AJAX from my archive and most probably it's only valid from some previous PHPR versions. Anyway, global settings have NOTHING to do with your problem at all, say, to only pick certain information related to the ADD/EDIT field from a particular table. As the code above is highly complex and as well the "Edit box with Ajax Popup" dedicated pick-up dependencies are only MAIN table oriented rather than ANY ELSE table, so, in my opinion, the only way to solve the problem is a) to look at the SQL QUERY BUILDER inside PHPR to see where the links between whatsoever are lined-up (to get a general good graphical overview rather than to run through coded lines) and <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=79398&image=1&table=forumreplies' class='bbc_emoticon' alt='B)' /> to drill a little bit deeper into SQL QUERY options (e.g. via Google) to manually adjust the table content dedications per ADD/EDIT field then. Say, in my opinion, the only time and energy way to go is to manually draw lines inside the PHPR's SQL query builder to those very table(s) you are eyeing on on per different ADD/EDIT fields on Ajax Popups with some freshly gained knowledge base on SQL QUERIES, TABLE POINT, FILTERING and else. Finally, on global settings, it seems that PHPR v8.1 is already equipped with same:
Citing excerpt out of https://xlinesoft.com/phprunner/docs/ajax_features.htm#lookupaseditbox

Note: If for some reasons you don't want to use AJAX-based functionality then all you need to do is to change the $useAJAX and $suggestAllContent variables value in the include\appsettings.php file to false.
$useAJAX = false;
$suggestAllContent = false;

unquote
Yet, as said, that issue is of secondary character while dedication of specific table content to various ADD/EDIT fields under AJAX Popup is a primary issue to get hopefully solved by you as per suggestions above.



As you see my code above for lookupsuggest . As you can see the code you supplied above is not in that file. And that is where that issue comes to a close. looks like custom coding will be neccesary to accomplish getting the ajax popup to include Contains instead of the first 3 letters or as you type the first word. I need to sometimes grap the second word for complex data. Stuck here.

HJB 5/19/2016

@John - As I said, I took that code from my ARCHIVE (I'm a registered user since PHPR v2.0) and as time goes by, I mean, new versions and upgrades are coming out, I do not have the time to run a properly updated code snippets "warehouse" at all. So, such code must have been shifted elsewhere and easily to get located by e.g. usage of "notepad++" where the built-in SEARCH feature allows to run through the WHOLE generated files seen within the output directory, finally listing in which .php files such code had been found. Accordingly, to get me nailed on trial to assist somewhere sometime, I beg for your understanding that 1st this forum is NOT a support oriented one and 2nd the time investments did not really payback at all, partially resulting in a kind of shitstorm (I had a serious encounter with a Newbie from on this forum Singapore who tried to convince me, a since PHPR 2.0 registered user is only a MORON). Finally, I had been waiting very long time (say, now almost 6 months) to now, here by PHPRUNNER 9.0 beta release to get "newTLD" mail support, PHP 7.0 support and finally the best, to see BOOTSTRAP in place, yet meanwhile most clients ran away (no big problem for me as my motto is: "WE DON'T SELL WINE BEFORE ITS TIME" has its own market value) and shifted over to a fresh clientel base now where I need to throw some ballast out of the hot balloon to reach out to some height here. So, due to lesser time to creep through either machined and manually coded lines, I beg your pardon.