This topic is locked

Saved Search

11/10/2009 12:58:43 PM
PHPRunner General questions
H
hlewis author

I'm trying to create a function that allows users to save search criteria and run the search without having to re-set the search form.

If I use a car example as opposed the actual one I'm working on, it might be readily understood.
I have two tables titled 'Cars' and 'Save Car Search'. They both have pretty much the same columns e.g. make, colour, body, price, etc. Obviously the Save Car Search table has an ID column to recognise the user and a column called searchname. A view has been created based on the Saved Car Search table and contains the following pages list, edit, advanced search and view. Now on the list page it might show rows with columns for searchname, colour and body for example (in addition to the links for edit and view pages). At the end of the row I'd like to show a button titled something like 'Run Search' and upon clicking this the advanced search page fields (in the Cars table) are populated with the saved variables and then run to show the results in the list page for the Cars table.
Any pointers and help I terms of how to construct this particularly the Run Search button and linking this to creating the output list page from the Cars table would be greatly appreciated.

J
Jane 11/11/2009

Hi,
you can add link on the 'Save Car Search' page, point this link to the cars page and pass search parameters in this link. Use custom format to create this link:

http://www.xlinesoft.com/phprunner/docs/_view_as__settings_custom.htm

Also I recommend you to check this article:

http://www.asprunner.com/forums/topic/5704-how-to-get-the-url-of-advanced-search-results-page/

A
aalekizoglou 11/17/2009

I myself would be interested in such a functionality, and currently seeking ways to handle this. As far as I understand what one could do is the following:
On the Search Page put a button to let the user save the criteria given a specific search title. For example the user has filled in the desired criteria and then press the save button, the system ask for a title and save to a table. What could be saved is the title name, the relevant list page, and the criteria. As I can see if i change the form method=\"POST\" to form method=\"GET\"in the relevant search.php page the search form prepares and passes through the list.php the entire criteria.
After that on the list.php there would be a drop down control <SELECT> which would get filled with the search titles from the relevant table. Upon selecting a specific option, the relevant list.php?criteria should be called.
The functionality would be great to have in our application, and I understand it would be easy to build the list.php, but I find it difficult to build the search.php page.
If you feel we can exchange any ideas I would be happy to participate in building that functionality.
Regards,
Athanasios Alekizoglou

QUALISYS SOFTWARE

Sergey Kornilov admin 11/17/2009

Athanasios,
here is how I'd do that.

  1. Modify search page in Visual Editor adding the following:

Save search as <input name="searchname" value="">


This needs to be added in HTML mode of course. I would place it right before the 'Search' button.
2. Use ListBeforeProcess event to check if 'searchname' box was filled and construct an URL to save.



$url="tablename_list.php?";

if ($_POST['searchname'])

{

// loop through POST array to build GET like URL

// don't forget to exclude 'searchname'



foreach($_POST as $key => $data)

{

if($key != 'searchname' && $data!='')

{

$url.= $key."=".urlencode($data)."&";

}

}



if ($url[strlen($url)-1]=="&")

$url=substr($url,0,strlen($url)-1);

}
// save generated URL in your database along with search name.
...


3. Display a dropdown box with saved searches that point to search results page

A
aalekizoglou 11/18/2009

Sergey,
I've tried this

  1. Modified search page in Visual Editor adding the following:



<input name="SaveSearchButton" onclick="savename=prompt('Save Search','');if(savename=null) {return false;} else {}; return true;">



What I want to do is when i press the SaveSearch button have a prompt box for the user to enter the search name, and pass that to the 2nd step to save. What should I do here with javascript to return the name back to the URL?
2. In the ListBeforeProcess event with some modification to get the asearchfield array correct



$savesearchurl=$strBaseURL;

if ($_POST['SaveSearchButton'])

{

// loop through POST array to build GET like URL

// don't forget to exclude 'SaveSearchButton'



foreach($_POST as $key => $data)

{

if (is_array($data))

{

$i = 0;

foreach($data as $subkey => $subdata)

{

if($key != 'SaveSearchButton' && $subdata!='')

{

$savesearchurl.= $key."[".$i."]=".urlencode($subdata)."&";

$i+=1;

}

}

}

else

if($key != 'SaveSearchButton' && $data!='')

{

$savesearchurl.= $key."=".urlencode($data)."&";

}

}

if ($savesearchurl[strlen($savesearchurl)-1]=="&")

$savesearchurl=substr($savesearchurl,0,strlen($savesearchurl)-1);
// Here I am calling a function to store my search to DB
}



At this point I still do not know the name the user would like to store the search with.
Any help up to this point?
Regards,
Athanasios

C
charly1211 11/18/2009

I understand your function and I have experimented a little bit with the code. I am missing the possibility to do LIKE or NOT capabilities of the search page with the stored search, there is only a "=" functionality. Either I store the whole data fields of the search page - three fields for each field of the searched table/view - or you give me the trick how you read the search page within the list page. If I set debug=true, there is the right syntax of a mysql select statement, but how can I manage to save this select statement?
Thanks a lot for your help!!

A
aalekizoglou 11/19/2009

Charly
What this code does is to build the $savesearchurl with the exact url posted from the advanced search page to the list page. By putting this code on the BeforeProcessList event what you can achieve is filter posts coming for SaveSearchButton and get the url sent in order to save it on a desired DB table for further usage.
So what exactly you can do is save whatever you can build from the Advanced Search page, therefore you can use NOT and LIKE and BETWEEN since all of these are supported in Advanced Search.
Hope this help.
Athanasios Alekizoglou

QUALISYS SOFTWARE

Sergey Kornilov admin 11/19/2009

Charly,
it should work with all options, not with just 'equals'. It basically converts the whole POST to GET omitting empty values. Probably you can post your app to demo account to show us what doesn't work.
Saving SQL queries requires more work as you need to modify BeforeSQLQuery event as well replacing default SQL with saved one.

Sergey Kornilov admin 11/19/2009

Athanasios,
I'm not 100% sure I understand your approach. What page do you want to add this functionality to?
I think you can add a hidden field to the form and use javascript to populate it. Something like:

document.editform.hiddenfield.value='savename';


I still think that approach with adding a plain text box right to the search page works better.

A
aalekizoglou 11/24/2009

Well, here is how I've implemented my save search solution:

  1. I inserted two template contacts in my list view. In order to populate them in all my views I did that in my lheader.htm of the selected templetate. In fact I have implemented a copy of my preferred template where I do my modifications, but that is another topic. So I've inserted a block which I will be using for form POST before {BEGIN left_block}. Also I inserted a placeholder for my dropdown and buttons after the {END pages_block}. Here it is how the lheader.htm should look:



...

{BEGIN savesearchcontents_block}

{BEGIN left_block}

..

...

<div class="menu_text blackshade" id="pages_block{$id}">

{BEGIN pages_block}

<span>##message PAGE1## {$page} ##message PAGE2## {$maxpages}</span>

{END pages_block}

</div>

{BEGIN savesearch_block}

<div class="blackshade2" id="center_block{$id}">

<span>##message SAVEDSEARCH##</span>

</div>

<div class="blackshade">

{$savedsearches}

</div>

{END savesearch_block}
...

...

{END left_block}

{END savesearchcontents_block}


2) I call a php function to do all the work, so I have implemented my own file which I include. In every list's BeforeProcessList event I call . I need to pass on the $xt in order to have the function modify the template, and I also pass on the listname ('mylist') for every list.



include_once('include/QUIGeneric.php');
global $xt;
//Saved Searches

QUISavedSearches($xt, 'mylist');


3) In the QUISavedSearches I do the following:
Check the $_POST if there is an advsearch for that list to store it in a local variable. That would mean that the list is coming from an advsearch page. The function is QUICheckPOSTForSearch
Check the $_GET if there is a running search in order to show it in the dropdown box. The function is QUICheckURLForSearch
Prepare the form and assign in to the savesearchcontents_block
Check if we need to save anything. The function is QUICheckPOSTForSaving
Check if we need to delete an entry. The function is QUICheckPOSTForDelete
Check if we need to retrieve an entry. The function is QUIRetreiveSearches
Here is the code I've implemented. Sorry for the long post. You may use the code in case you find it useful.


//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Procedure to display Error Message Dialog

function QMSGShowError($strTitle, $strDescription)

{

echo "<script langauge=\"javascript\">alert(\"".$strDescription."\");</script>";

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Procedure to display Error Message Dialog

function QMSGShowPrompt($strTitle, $strDescription, $strDefault=null)

{

echo "<script langauge=\"javascript\">var x=prompt(\"".$strDescription."\", \"".$strDefault."\") </script>";

echo "<script langauge=\"javascript\">document.write(x); </script>";

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Function to check if we need to get POST for Save Search

function QUICheckPOSTForSearch()

{

$savesearchurl='';

if ($_POST['a'] == "advsearch")

{

$savesearchurl = '';

// loop through POST array to build GET like URL

// don't forget to exclude 'SearchButton'
foreach($_POST as $key => $data)

{

if (is_array($data))

{

$i = 0;

foreach($data as $subkey => $subdata)

{

if($key != 'SearchButton' && $subdata!='')

{

$savesearchurl.= $key."[".$i."]=".urlencode($subdata)."&";

$i+=1;

}

}

}

else

if($key != 'SearchButton' && $data!='')

{

$savesearchurl.= $key."=".urlencode($data)."&";

}

}

if ($savesearchurl[strlen($savesearchurl)-1]=="&")

$savesearchurl=substr($savesearchurl,0,strlen($savesearchurl)-1);



return $savesearchurl;

}

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Function to check if we need to get URL for Save Search

function QUICheckURLForSearch()

{

$savesearchurl='';

if ($_GET['a'] == "advsearch")

{

$savesearchurl = '';

// loop through POST array to build GET like URL

// don't forget to exclude 'SearchButton'
foreach($_GET as $key => $data)

{

if (is_array($data))

{

$i = 0;

foreach($data as $subkey => $subdata)

{

if($key != 'SearchButton' && $subdata!='')

{

$savesearchurl.= $key."[".$i."]=".urlencode($subdata)."&";

$i+=1;

}

}

}

else

if($key != 'SearchButton' && $data!='')

{

$savesearchurl.= $key."=".urlencode($data)."&";

}

}

if ($savesearchurl[strlen($savesearchurl)-1]=="&")

$savesearchurl=substr($savesearchurl,0,strlen($savesearchurl)-1);



return $savesearchurl;

}

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Function to check if we need to save a Search

function QUICheckPOSTForSaving()

{

if ($_POST['a'] == "savesearch" && $_POST['formname'] != null && $_POST['searchname'] != null)

{

global $conn;



$searchname = $_POST['searchname'];

$formname = $_POST['formname'];

$url = $_POST['url'];
//the code bellow checks if the search name exists in the DB

$sql = "SELECT COUNT(*) iCount FROM savesearch WHERE strFormName = '".$formname."' AND strCharacteristic = 'WEBSEARCH' AND strFieldKey = '".$searchname."' ";

$rs = CustomQuery($sql);

$row = db_fetch_array($rs);



if ($row["iCount"] > 0)

{

QMSGShowError('Save Search, 'The search name already exists!');

return;

}



//the code bellow inserts the search in the DB

$sql = "INSERT INTO savesearch (strFormName, strFieldKey, strCharacteristic, strValue) VALUES ('".$formname."', '".$searchname."', 'WEBSEARCH', '".$url."') ON DUPLICATE KEY UPDATE strValue = '".$url."'";

db_exec($sql,$conn);
//Clear out the form

$_POST['formname'] = '';

$_POST['searchname'] = '';

return true;

}

else

{

return false;

}

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Function to check if we need to delete a Search

function QUICheckPOSTForDelete()

{

if ($_POST['a'] == "deletesearch" && $_POST['formname'] != null && $_POST['searchname'] != null)

{

global $conn;



$searchname = $_POST['searchname'];

$formname = $_POST['formname'];

$url = $_POST['url'];
$sql = "DELETE FROM savesearch WHERE strFormName = '".$formname."' AND strCharacteristic = 'WEBSEARCH' AND strFieldKey = '".$searchname."' ";

db_exec($sql,$conn);
//Clear out the form

$_POST['formname'] = '';

$_POST['searchname'] = '';

return true;

}

else

{

return false;

}

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Function to Retreive Saved Searches

function QUIRetreiveSearches($formname)

{

global $conn;





//Code to retrieve from DB

$sql = "SELECT strFieldKey, strValue, FROM usersettings WHERE strFormName = '".$formname."' AND strCharacteristic = 'WEBSEARCH' ";

$rs = CustomQuery($sql);



$results = array();

while ($row = db_fetch_array($rs))

{

$results[] = array(

'searchname' => $row["strFieldKey"],

'url' => $row["strValue"]

);

}

return $results;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Function to load Saved Searches

function QUISavedSearches($xt, $formname)

{
$strPerm = GetUserPermissions();

$allow_search=(strpos($strPerm,"S")!==false);



if ($allow_search)

{
$xt->assign('savesearch_block',True);



$savedsearches = <<<EOT

<script type=text/javascript>

function savesearch() {

var answer = prompt("Name:", "");

if (answer){

document.forms.savesearchform.a.value='savesearch';

document.forms.savesearchform.searchname.value=answer;

document.forms.savesearchform.submit();

}

}

function deletesearch(searchname) {

var selObj = document.getElementById('optSavedSearches');

var selIndex = selObj.selectedIndex;

var selText = selObj.options[selIndex].text;

var answer = confirm("Do you want to delete the search '" + selText + "';");

if (answer){

document.forms.savesearchform.a.value='deletesearch';

document.forms.savesearchform.searchname.value=selText;

document.forms.savesearchform.submit();

}

}



function changesearch(x){

document.location.href=x.options[x.selectedIndex].value;

}
</SCRIPT>

EOT;



$currentsearch = $formname."_list.php?".QUICheckURLForSearch();



//Check if we have an advanced search in our URL

$currenturl = $formname."_list.php?".QUICheckPOSTForSearch();



$savesearch_block=array();

$savesearch_block["begin"]="<form method=\"POST\" ";

$savesearch_block["begin"].="action=\"".$formname."_list.php\" ";

$savesearch_block["begin"].="name=\"savesearchform\"><input type=\"hidden\" id=\"a\" name=\"a\" value=\"\">";

$savesearch_block["begin"].="<input type=\"hidden\" id=\"formname\" name=\"formname\" value=\"".$formname."\">";

$savesearch_block["begin"].="<input type=\"hidden\" id=\"searchname\" name=\"searchname\" value=\"\">";

$savesearch_block["begin"].="<input type=\"hidden\" id=\"url\" name=\"url\" value=\"".$currenturl."\">";

$savesearch_block["end"]="</form>";

$xt->assignbyref("savesearchcontents_block",$savesearch_block);
//Check if we need to save a search

QUICheckPOSTForSaving();
//Check if we need to delete a search

QUICheckPOSTForDelete();
//Check if we need to retreive searches

$reteivedsearches = QUIRetreiveSearches($formname);



$savedsearches .= '<select id="optSavedSearches" style="WIDTH: 185px" onchange="changesearch(this)">';



foreach ($reteivedsearches as $strSearch)

{

if (isset($currentsearch) && $currentsearch==$strSearch['url'])

{

$savedsearches .= '<option selected value="'.$strSearch['url'].'">'.$strSearch['searchname'].'</option>';

}

else

{

$savedsearches .= '<option value="'.$strSearch['url'].'">'.$strSearch['searchname'].'</option>';

}

}

$savedsearches .= '</select>';
//blackbutton is a css button that i've impelemented. You can see it in my screenshoots

$savedsearches .= '

&nbsp;<button class=blackbutton85 type=reset value="Save" title="Save Search" hidefocus="hidefocus" onclick="savesearch()">Save</button> ';

$savedsearches .= '<button class=blackbutton85 type=reset value="Delete" title="Delete Search" hidefocus="hidefocus" onclick="deletesearch()">Delete</button> ';

$xt->assign('savedsearches',$savedsearches);

}

}
H
hlewis author 11/25/2009

Athanasios,
Thanks for that. I'm only intending to use this on a single group of pages e.g list, view, adv search. How much of this code would I need?
Thanks in advance.



Well, here is how I've implemented my save search solution:

  1. I inserted two template contacts in my list view. In order to populate them in all my views I did that in my lheader.htm of the selected templetate. In fact I have implemented a copy of my preferred template where I do my modifications, but that is another topic. So I've inserted a block which I will be using for form POST before {BEGIN left_block}. Also I inserted a placeholder for my dropdown and buttons after the {END pages_block}. Here it is how the lheader.htm should look:



...

{BEGIN savesearchcontents_block}

{BEGIN left_block}

..

...

<div class="menu_text blackshade" id="pages_block{$id}">

{BEGIN pages_block}

<span>##message PAGE1## {$page} ##message PAGE2## {$maxpages}</span>

{END pages_block}

</div>

{BEGIN savesearch_block}

<div class="blackshade2" id="center_block{$id}">

<span>##message SAVEDSEARCH##</span>

</div>

<div class="blackshade">

{$savedsearches}

</div>

{END savesearch_block}
...

...

{END left_block}

{END savesearchcontents_block}


2) I call a php function to do all the work, so I have implemented my own file which I include. In every list's BeforeProcessList event I call . I need to pass on the $xt in order to have the function modify the template, and I also pass on the listname ('mylist') for every list.



include_once('include/QUIGeneric.php');
global $xt;
//Saved Searches

QUISavedSearches($xt, 'mylist');


3) In the QUISavedSearches I do the following:
Check the $_POST if there is an advsearch for that list to store it in a local variable. That would mean that the list is coming from an advsearch page. The function is QUICheckPOSTForSearch
Check the $_GET if there is a running search in order to show it in the dropdown box. The function is QUICheckURLForSearch
Prepare the form and assign in to the savesearchcontents_block
Check if we need to save anything. The function is QUICheckPOSTForSaving
Check if we need to delete an entry. The function is QUICheckPOSTForDelete
Check if we need to retrieve an entry. The function is QUIRetreiveSearches
Here is the code I've implemented. Sorry for the long post. You may use the code in case you find it useful.


//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Procedure to display Error Message Dialog

function QMSGShowError($strTitle, $strDescription)

{

echo "<script langauge=\"javascript\">alert(\"".$strDescription."\");</script>";

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Procedure to display Error Message Dialog

function QMSGShowPrompt($strTitle, $strDescription, $strDefault=null)

{

echo "<script langauge=\"javascript\">var x=prompt(\"".$strDescription."\", \"".$strDefault."\") </script>";

echo "<script langauge=\"javascript\">document.write(x); </script>";

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Function to check if we need to get POST for Save Search

function QUICheckPOSTForSearch()

{

$savesearchurl='';

if ($_POST['a'] == "advsearch")

{

$savesearchurl = '';

// loop through POST array to build GET like URL

// don't forget to exclude 'SearchButton'
foreach($_POST as $key => $data)

{

if (is_array($data))

{

$i = 0;

foreach($data as $subkey => $subdata)

{

if($key != 'SearchButton' && $subdata!='')

{

$savesearchurl.= $key."[".$i."]=".urlencode($subdata)."&";

$i+=1;

}

}

}

else

if($key != 'SearchButton' && $data!='')

{

$savesearchurl.= $key."=".urlencode($data)."&";

}

}

if ($savesearchurl[strlen($savesearchurl)-1]=="&")

$savesearchurl=substr($savesearchurl,0,strlen($savesearchurl)-1);
return $savesearchurl;

}

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Function to check if we need to get URL for Save Search

function QUICheckURLForSearch()

{

$savesearchurl='';

if ($_GET['a'] == "advsearch")

{

$savesearchurl = '';

// loop through POST array to build GET like URL

// don't forget to exclude 'SearchButton'
foreach($_GET as $key => $data)

{

if (is_array($data))

{

$i = 0;

foreach($data as $subkey => $subdata)

{

if($key != 'SearchButton' && $subdata!='')

{

$savesearchurl.= $key."[".$i."]=".urlencode($subdata)."&";

$i+=1;

}

}

}

else

if($key != 'SearchButton' && $data!='')

{

$savesearchurl.= $key."=".urlencode($data)."&";

}

}

if ($savesearchurl[strlen($savesearchurl)-1]=="&")

$savesearchurl=substr($savesearchurl,0,strlen($savesearchurl)-1);
return $savesearchurl;

}

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Function to check if we need to save a Search

function QUICheckPOSTForSaving()

{

if ($_POST['a'] == "savesearch" && $_POST['formname'] != null && $_POST['searchname'] != null)

{

global $conn;
$searchname = $_POST['searchname'];

$formname = $_POST['formname'];

$url = $_POST['url'];
//the code bellow checks if the search name exists in the DB

$sql = "SELECT COUNT(*) iCount FROM savesearch WHERE strFormName = '".$formname."' AND strCharacteristic = 'WEBSEARCH' AND strFieldKey = '".$searchname."' ";

$rs = CustomQuery($sql);

$row = db_fetch_array($rs);
if ($row["iCount"] > 0)

{

QMSGShowError('Save Search, 'The search name already exists!');

return;

}
//the code bellow inserts the search in the DB

$sql = "INSERT INTO savesearch (strFormName, strFieldKey, strCharacteristic, strValue) VALUES ('".$formname."', '".$searchname."', 'WEBSEARCH', '".$url."') ON DUPLICATE KEY UPDATE strValue = '".$url."'";

db_exec($sql,$conn);
//Clear out the form

$_POST['formname'] = '';

$_POST['searchname'] = '';

return true;

}

else

{

return false;

}

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Function to check if we need to delete a Search

function QUICheckPOSTForDelete()

{

if ($_POST['a'] == "deletesearch" && $_POST['formname'] != null && $_POST['searchname'] != null)

{

global $conn;
$searchname = $_POST['searchname'];

$formname = $_POST['formname'];

$url = $_POST['url'];
$sql = "DELETE FROM savesearch WHERE strFormName = '".$formname."' AND strCharacteristic = 'WEBSEARCH' AND strFieldKey = '".$searchname."' ";

db_exec($sql,$conn);
//Clear out the form

$_POST['formname'] = '';

$_POST['searchname'] = '';

return true;

}

else

{

return false;

}

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Function to Retreive Saved Searches

function QUIRetreiveSearches($formname)

{

global $conn;
//Code to retrieve from DB

$sql = "SELECT strFieldKey, strValue, FROM usersettings WHERE strFormName = '".$formname."' AND strCharacteristic = 'WEBSEARCH' ";

$rs = CustomQuery($sql);
$results = array();

while ($row = db_fetch_array($rs))

{

$results[] = array(

'searchname' => $row["strFieldKey"],

'url' => $row["strValue"]

);

}

return $results;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Function to load Saved Searches

function QUISavedSearches($xt, $formname)

{
$strPerm = GetUserPermissions();

$allow_search=(strpos($strPerm,"S")!==false);
if ($allow_search)

{
$xt->assign('savesearch_block',True);
$savedsearches = <<<EOT

<script type=text/javascript>

function savesearch() {

var answer = prompt("Name:", "");

if (answer){

document.forms.savesearchform.a.value='savesearch';

document.forms.savesearchform.searchname.value=answer;

document.forms.savesearchform.submit();

}

}

function deletesearch(searchname) {

var selObj = document.getElementById('optSavedSearches');

var selIndex = selObj.selectedIndex;

var selText = selObj.options[selIndex].text;

var answer = confirm("Do you want to delete the search '" + selText + "';");

if (answer){

document.forms.savesearchform.a.value='deletesearch';

document.forms.savesearchform.searchname.value=selText;

document.forms.savesearchform.submit();

}

}
function changesearch(x){

document.location.href=x.options[x.selectedIndex].value;

}
</SCRIPT>

EOT;
$currentsearch = $formname."_list.php?".QUICheckURLForSearch();
//Check if we have an advanced search in our URL

$currenturl = $formname."_list.php?".QUICheckPOSTForSearch();
$savesearch_block=array();

$savesearch_block["begin"]="<form method=\"POST\" ";

$savesearch_block["begin"].="action=\"".$formname."_list.php\" ";

$savesearch_block["begin"].="name=\"savesearchform\"><input type=\"hidden\" id=\"a\" name=\"a\" value=\"\">";

$savesearch_block["begin"].="<input type=\"hidden\" id=\"formname\" name=\"formname\" value=\"".$formname."\">";

$savesearch_block["begin"].="<input type=\"hidden\" id=\"searchname\" name=\"searchname\" value=\"\">";

$savesearch_block["begin"].="<input type=\"hidden\" id=\"url\" name=\"url\" value=\"".$currenturl."\">";

$savesearch_block["end"]="</form>";

$xt->assignbyref("savesearchcontents_block",$savesearch_block);
//Check if we need to save a search

QUICheckPOSTForSaving();
//Check if we need to delete a search

QUICheckPOSTForDelete();
//Check if we need to retreive searches

$reteivedsearches = QUIRetreiveSearches($formname);
$savedsearches .= '<select id="optSavedSearches" style="WIDTH: 185px" onchange="changesearch(this)">';
foreach ($reteivedsearches as $strSearch)

{

if (isset($currentsearch) && $currentsearch==$strSearch['url'])

{

$savedsearches .= '<option selected value="'.$strSearch['url'].'">'.$strSearch['searchname'].'</option>';

}

else

{

$savedsearches .= '<option value="'.$strSearch['url'].'">'.$strSearch['searchname'].'</option>';

}

}

$savedsearches .= '</select>';
//blackbutton is a css button that i've impelemented. You can see it in my screenshoots

$savedsearches .= '

&nbsp;<button class=blackbutton85 type=reset value="Save" title="Save Search" hidefocus="hidefocus" onclick="savesearch()">Save</button> ';

$savedsearches .= '<button class=blackbutton85 type=reset value="Delete" title="Delete Search" hidefocus="hidefocus" onclick="deletesearch()">Delete</button> ';

$xt->assign('savedsearches',$savedsearches);

}

}


A
aalekizoglou 11/26/2009

Well,
if you implement this code in a .php file and include that file in your project (see PHPR manual for that, files.txt) the only thing you need is to include

the



include_once('include/QUIGeneric.php');
global $xt;
//Saved Searches

QUISavedSearches($xt, 'mylist');


in BeforeProcessList of you list files.
Athanasios

S
snuffi01 11/26/2009

Hi!
Tahnks for this exelent post, exactly what i want to have on my site to.
I asume that i have to add some table in the databse with some columns?



Well,
if you implement this code in a .php file and include that file in your project (see PHPR manual for that, files.txt) the only thing you need is to include

the



include_once('include/QUIGeneric.php');
global $xt;
//Saved Searches

QUISavedSearches($xt, 'mylist');


in BeforeProcessList of you list files.
Athanasios

A
aalekizoglou 11/26/2009

Kristian,
what you need to have is some sort of storage for the searches. Those will be used in

QUIRetreiveSearches and QUISaveSearchesPersonally, I like to use a table in the DB. Here is the DDL
CREATE TABLE savesearches (

strFormName varchar(70) NOT NULL,

strFieldKey varchar(70) NOT NULL,

strCharacteristic varchar(70) NOT NULL,

strValue varchar(255) DEFAULT NULL,

PRIMARY KEY (strFormName,strFieldKey,strCharacteristic),

KEY strValue (strValue),

KEY usersettings_fk (strUserName)

) ENGINE=MyISAM DEFAULT CHARSET=utf8;
I really home some more fields that are not needed here, for the user that stored the search. By that way I can login with a specific user, say .MASTER and prepare / store searches that will be preserved so that users cannot delete them. That is a handle I do with SQL scripts.
Glad to help

Regards,



Hi!
Tahnks for this exelent post, exactly what i want to have on my site to.
I asume that i have to add some table in the databse with some columns?

H
hlewis author 11/28/2009

I checked the manual as suggested under files.txt and understood the guidance. However, whilst my project file has been built with a 'source' file it does not contain a files.txt. In fact I couldn't find a files.txt anywhere within my project folder. I read a separate posting on this matter ... could it be that because I didn't use a template for my project, one hasn't been created. I used Application Wizard to create my project. Any advice?
Regards

Sergey Kornilov admin 11/29/2009

C:\Program Files\PHPRunner5.1\source\files.txt

H
hlewis author 11/30/2009



C:\Program Files\PHPRunner5.1\source\files.txt


Hi, Yes I can see it in this location. What I am saying is that it is not visible in the project folder created after 'build' process?

Sergey Kornilov admin 11/30/2009

It should not be in the project folder. You need to modify one that is in 'source' folder.