This topic is locked

Need a mini advanced search on the list page.

10/24/2006 4:32:23 PM
PHPRunner General questions
D
Dale author

I would like to be able to bring one field from the advanced search page and place it on the list page.
Users are asking if they could get a picklist on the list page that would force the display of certain records.

By selecting advanced search, they can select the one field in question, use its picklist to select a component and click search. The result is perfect. They just want to be able to do it from the normal list displayed.
Just trying to save a couple of clicks, and their point is valid, they use the advanced search on just this one field all the time.
Ive been playing around a bit, but just getting more confused.
Any pointers on how I could accomplish this effeciently. On loading the list I would like a picklist to be built from the component table, and then on changing the value, to invoke the search function displaying the new list.

Also the picklist value stored is an Id and the display is the name field corresponding to the id.
If I can get this happening, I actually could apply it to a few other lists. Kind of gives you multiple lists with one click of a button.
Any suggestions greatly appreciated.

T
thesofa 10/24/2006

Hi

You could try looking at This Page to see if this idea will suit your needs?

This would appear to put a search box at the top of each column in a table, with the use of pick lists as well as type in boxes, you could do all sorts of wicked things without using the advanced search at all.

Cheers
Well, I have tried the script on a page of static tables and it works really well and quite fast too, all we need now is a super-whizz kid to tell me where to put the bits of code into the xxx_list.php file generated by the project.

Any takers anywhere?

D
Dale author 10/24/2006

How are you thesofa,
Thanks for the reply. I think I have solved the issue. Hack Hack Hack. The table features you linked for me are very nice looking. Couple of issues though. One - they generally only work on complete tables, Phprunner nicely displays a list of 10 or 20. The routines that the javascript in the samples there, will only work on the current list. Phprunner does all these things nicely. The sorting, (although I would love multiple column sorts), the search and advance search work so nicely with the lists also. Point is I dont think you really want to waste anytime in piecing that code into Phprunner.
I did hack my way into a solution. I took the advanced search page, hacked it down to the bear minimum of the one field I was looking for. Then I copied it into a ..._list_select.php file.
Then in the list.php I added the snippet below just under the page select controls.
<?php if(file_exists("##SHORTTABLENAME##_list_select.php"))

include("##SHORTTABLENAME##_list_select.php");

?>
Now I have a nice clean row just above the list table with this advanced search picklist. I did a small tweak to the functions.php to that when the picklist value is changed it automatically reloads the expected list. I hate have to click a Go button. Anyway all works great so far.
If you are interested in seeing what it looks like, just drop me an email and I will give you access to my beta site for a peek.
Works great, actually I can see adding a couple of other important fields. It simply just brings the advanced search to the list page without have to go to an extra page and the advanced search remains the same.
I would really like to get to that upgrade, but alas, way to much code to find a new spot for. One day.

M
mmponline 10/25/2006

I'm really interested in this. Asked for this feature from support, but only got a temp solution to plase Hyperlinks on the top of the list page - this works well, but only for static links, not where field data are increasing.
Can you please post or send your link to me. I need this for some projects. If you have a step by step for me as well, it would be appreciated.
I'm sure support will look at this as a feature once they read this. Maybe in a next update. In a previous program I used, it was called a "category list" and was a built in feature (only for one field per table however).
I've started on a table wil all handy snippets and plan to make it live soon. I can add this to the list as well.
Thanks, we really should share these kind of tweaks. Will save a lot of time for everybody.
Stephan

T
thesofa 10/25/2006

Hi DaleM and Stephan-MMP

Certainly sounds good to me, I too have been building a bookmark list as I read these fora, it saves me hours of searching for the same post over again.

The hack sound like it will save me hours of messing about.

I too tried the search boxes from that link i sent you, it is a fantastic hack, but at 3.00 this morning i still could not see the light, so I gave up. It works really well on static tables.....

D
Dale author 10/25/2006

I think I have all the info you need below.

A big NOTE: This is done using PHPRunner 3.0 not the newer version.
First I copied the bit below from my construction_data_search.php and pasted it into a new file

as below. I found I only needed to copy the function WriteSearchOptions($field,$fmt) also as it

stopped the errors I was getting. I only have one field I wanted in this case, if I need more, I can

just copy them from the search page and paste them into this file.
Save it with the orginal ..._list.php and just add _select to the name as below for my file.
Start of construction_data_list_select.php file
<?php

echo "<form method=\"POST\" action=\"construction_data_list.php\" name=\"by_select\">";

echo "<input type=\"hidden\" id=\"a\" name=\"a\" value=\"advsearch\">";

echo "<input type=\"hidden\" name=\"type\" value=\"and\" checked>";

echo "<tr bgcolor=\"lightgray\" height=\"30px\">";

echo "<td align=\"right\" valign=\"middle\">Select&nbsp;by&nbsp;Component&nbsp;";

$secondid=1;

// component

if(!IsBinaryType(@$_SESSION[$strTableName."_fieldinfo"]["component"]["type"]))

{

$opt="";

$for="";

$for2="";

$not=false;

$i=array_search("component",$fieldlist);

if(@$_SESSION[$strTableName."_search"]==2)

{

if(@$_SESSION[$strTableName."_asearchopt"] && array_key_exists($i,@$_SESSION[$strTableName."_asearchopt"]))

$opt=$_SESSION[$strTableName."_asearchopt"][$i];

if(@$_SESSION[$strTableName."_asearchfor"] && array_key_exists($i,@$_SESSION[$strTableName."_asearchfor"]))

$for=$_SESSION[$strTableName."_asearchfor"][$i];

if(@$_SESSION[$strTableName."_asearchfor2"] && array_key_exists($i,@$_SESSION[$strTableName."_asearchfor2"]))

$for2=$_SESSION[$strTableName."_asearchfor2"][$i];

if(@$_SESSION[$strTableName."_asearchnot"] && array_key_exists($i,@$_SESSION[$strTableName."_asearchnot"]))

$not=$_SESSION[$strTableName."_asearchnot"][$i];

}

$fmt=GetEditFormat("component");

if(!$fmt)

$fmt=EDIT_FORMAT_TEXT_FIELD;

if(!$fmt || $fmt==EDIT_FORMAT_TEXT_AREA

|| $fmt==EDIT_FORMAT_PASSWORD || $fmt==EDIT_FORMAT_HIDDEN

|| $fmt==EDIT_FORMAT_READONLY)

$fmt=EDIT_FORMAT_TEXT_FIELD;

?>

<input type="hidden" name="asearchfield[]" value="<?php echo $i;?>">

<input type="hidden" name="not<?php echo $i;?>" <?php if($not) echo "checked" ?>>

<span style="display:none"><?php $havesecond=WriteSearchOptions("component",$fmt); ?></span>

<?php echo BuildEditControl("component",$for,$fmt,MODE_SEARCH); ?>

<span id="second<?php echo $secondid++;?>"><?php if($havesecond) echo BuildEditControl("component",$for2,$fmt,MODE_SEARCH,$i+10000); ?></span>
<?php

}

echo "</td></tr></form>";
function WriteSearchOptions($field,$fmt)

{

global $opt,$strSize;

$ret=0;

if($fmt==EDIT_FORMAT_TEXT_FIELD)

{

$a=array("Contains","Equals","Starts with ...","More than ...","Less than ...","Equal or more than ...","Equal or less than ...","Between","Empty");

$b=array(mlang_message("CONTAINS"),mlang_message("EQUALS"),mlang_message("STARTS_WITH"),mlang_message("MORE_THAN"),mlang_message("LESS_THAN"),mlang_message("EQUAL_OR_MORE"),mlang_message("EQUAL_OR_LESS"),mlang_message("BETWEEN"),mlang_message("EMPTY"));

$ret=1;

}

else if($fmt==EDIT_FORMAT_DATE)

{

$a=array("Equals","More than ...","Less than ...","Equal or more than ...","Equal or less than ...","Between","Empty");

$b=array(mlang_message("EQUALS"),mlang_message("MORE_THAN"),mlang_message("LESS_THAN"),mlang_message("EQUAL_OR_MORE"),mlang_message("EQUAL_OR_LESS"),mlang_message("BETWEEN"),mlang_message("EMPTY"));

$ret=1;

}

else if($fmt==EDIT_FORMAT_LOOKUP_WIZARD )

{

$strSize=1;

GetLookupData($field);

if($strSize==1)

{

$a=array("Equals");

$b=array(mlang_message("EQUALS"));

}

else

{

$a=array("Contains");

$b=array(mlang_message("CONTAINS"));

}

}

else

{

$a=array("Equals");

$b=array(mlang_message("EQUALS"));

}

echo "<SELECT ID=\"SearchOption\" NAME=\"asearchopt[]\" SIZE=1 onChange=\"return ShowHideControls();\">";

foreach($a as $key=>$o)

echo "<OPTION VALUE=\"".$o."\" ".(($opt==$o)?"selected":"").">".$b[$key]."</option>";

echo "</SELECT>";

return $ret;

}

?>
End of construction_data_list_select.php file
Second

Then I modified the list.php in my template folder and added a file check as below.

I placed the coded just above the list details. This way I ended up with a nice grey row

at the top of the list with this picklist in it. Also now I can employ the feature on any

list that I may need to pretty easily.
<?php if(file_exists("##SHORTTABLENAME##_list_select.php"))

include("##SHORTTABLENAME##_list_select.php");

?>
Third

I modified the functions.php in my template folder as below. I needed the search to happen

as soon as I changed the picklist. Similar to the way changing the number of records per

page does. The function below was changed just a little bit.
From ==>

LogInfo($LookupSQL);

$rs=db_query($LookupSQL,$conn);

if(!db_numrows($rs))

return "";
$onchange="";
To ==>

LogInfo($LookupSQL);

$rs=db_query($LookupSQL,$conn);

if(!db_numrows($rs))

return "";
global $strTableName;

if (($strTableName == "construction_data") || ($strTableName == "customer") || ($strTableName == "credit_data") )

$onchange="document.forms.by_select.submit();";

else

$onchange="";
As you can see, I have it on three lists currently, the if statement checks to see if the altered onchange should be used or the original function untouched.
That's it, generated my pages from Phprunner and all done. I havent come accross any issues

yet, seems to be working quite fine.
I am not experienced with php or mysql so if there was an easier way or a better way to do

this I sure would love the tips. I hate playing in that function.php file and there are

a ton of functions in there Im sure I could use if I had more experience.
I am thinking of using that nice band accross the top for a Button row. I have also

added a function to batch email to any viewed customer list. I currently have a new

button named Batch Email on the list page. Im thinking I'll get a toolbar button and

place it in this band. I could lots of things with this area.
Anyway, I have to get back at it. Hope this is a help to you. Any comments welcome.
Dale Miller

M
mmponline 10/26/2006

Any idea if this will work in 3.1?
I need this feature but is a bit pressed for time to experiment at the moment.