- Moderated by:
- Support
-
- rank:
-
Helper
- registered:
- October 2004
- Status:
- offline
- last visit:
- 01.03.06
- Posts:
- 437
Hey all I have my module just about done now ( all the standard functions work ) and now I need to add a search function to the pnuser & pnuserapi.php files and I am not quite sure how to do it, so I was wondering if you all could give me some pointers on the matter. Here is what I have built thus far:
pnuser.php search function:
Code
function pnDiagram_user_search()
{
if (!pnSecAuthAction(0, 'pnDiagram::', '::', ACCESS_OVERVIEW)) {
return pnVarPrepHTMLDisplay(_MODULENOAUTH);
}
$pnRender =& new pnRender('pnDiagram');
$pnRender->caching = false;
return $pnRender->fetch('pnDiagram_user_search.htm');
}
The above is called to from a link in the users menu.
this is what I have in my template file now:
Code
<!--[* $Id: pnDiagram_admin_modify.htm,v 1.9 2004/04/05 19:47:51 markwest exp $ *]-->
<!--[include file="pnDiagram_user_menu.htm"]-->
<br /><br />
<div class="pn-title"><!--[pnml name="_pnDiagramSEARCH"]--></div>
<br /><br />
<form action="<!--[pnmodurl modname="pnDiagram" type="user" func="query"]-->" method="post" enctype="application/x-www-form-urlencoded">
<div>
<input type="hidden" name="authid" value="<!--[pnsecgenauthkey module="pnDiagram"]-->" />
<input type="hidden" name="tid" value="<!--[$tid|pnvarprepfordisplay]-->" />
<table border="1" cellpadding="5" cellspacing="1"><tbody>
<tr>
<td><label for="pnDiagram_name"><!--[pnml name="_pnDiagramNAME"]--></label></td>
<td><input id="pnDiagram_name" name="itemname" type="text" size="32" maxlength="32" /></td>
</tr>
<tr>
<td><label for="pnDiagram_site_type"><!--[pnml name="_pnDiagramSITETYPE"]--></label></td>
<td><select name="Tsite" size="1" tabindex="3"><option value=""></option><option value="Master Headend">Master Headend</option><option value="Hub">Hub</option><option value="CoLocation">CoLocation</option><option value="Central Office">Central Office</option><option value="Aggregation Point">Aggregation Point</option></select></td>
</tr>
<tr>
<td><label for="pnDiagram_city"><!--[pnml name="_pnDiagramCITY"]--></label></td>
<td><input id="pnDiagram_city" name="city" type="text" size="32" maxlength="32" /></td>
</tr>
<tr>
<td><label for="pnDiagram_state"><!--[pnml name="_pnDiagramSTATE"]--></label></td>
<td><input id="pnDiagram_state" name="state" type="text" size="32" maxlength="32" /></td>
</tr>
<tr>
<td><label for="pnDiagram_technology"><!--[pnml name="_pnDiagramTECHNOLOGY"]--></label></td>
<td><label><input type="radio" name="tech1" value="PowerLink">PowerLink</label></td>
</tr>
<tr>
<td><label for="pnDiagram_technology"><!--[pnml name="_pnDiagramTECHNOLOGY"]--></label></td>
<td><label><input type="radio" name="tech2" value="Digital TV">Digital TV</label></td>
</tr>
<tr>
<td><label for="pnDiagram_technology"><!--[pnml name="_pnDiagramTECHNOLOGY"]--></label></td>
<td><label><input type="radio" name="tech3" value="Video on Demand">Video on Demand</label></td>
</tr>
<tr>
<td><label for="pnDiagram_status"><!--[pnml name="_pnDiagramSTATUS"]--></label></td>
<td><select name="status" size="1" tabindex="13"><option value=""></option><option value="Verified">Verified</option><option value="Unverified">Unverified</option><option value="Proposed">Proposed</option><option value="Acquisition">Acquisition</option></select></td>
</tr>
<tr>
<td><label for="pnDiagram_diagram"><!--[pnml name="_pnDiagramDIAGRAM"]--></label></td>
<td><select name="diagram" size="1" tabindex="11"><option value=""></option><option value="Port">Port</option><option value="Rack">Rack</option><option value="Vlan">Vlan</option><option value="Connectivity">Connectivity</option><option value="Overview">Overview</option></select></td>
</tr>
<tr>
<td><label for="pnDiagram_author"><!--[pnml name="_pnDiagramAUTHOR"]--></label></td>
<td><input id="pnDiagram_author" name="author" type="text" size="32" maxlength="32" /></td>
</tr>
<tr>
<td><label for="pnDiagram_category"><!--[pnml name="_pnDiagramCATEGORY"]--></label></td>
<td><select name="category" size="1" tabindex="11"><option value=""></option><option value="NorthEast">NorthEast</option><option value="SouthEast">SouthEast</option><option value="SoutherCal">SoutherCal</option><option value="Western">Western</option><option value="Central">Central</option></select></td>
</tr>
</table>
<input name="submit" type="submit" value="<!--[pnml name="_pnDiagramSEARCH"]-->" />
</div>
</form>
Now from this file I will call to a pnuser.php query function to run the API function to do the search, this is where I am having a bit of trouble I am not 100% sure what this function should look like since the Example module doesn't have a search function and every module I have loaded on my system does not make use of the pnrender engine.
Any pointers anyone could provide would be awesome.
Thanks
-SUNADMN -
- rank:
-
Helper
- registered:
- October 2004
- Status:
- offline
- last visit:
- 01.03.06
- Posts:
- 437
Ok so I have reached the point of trying to call to the API function but for some reason I have an issue with my SQL and am not sure how to adjust it to work correctly can anyone give me some advice please. Below is my API function:
Code
function pnDiagram_userapi_query()
{
$dbconn =& pnDBGetConn(true);
$pntable =& pnDBGetTables();
$pnDiagramtable = &$pntable['pnDiagram_data'];
$pnDiagramcolumn = &$pntable['pnDiagram_data_column'];
$sql = "SELECT $pnDiagramcolumn[site_name] LIKE '".$itemname."'
OR $pnDiagramcolumn[site_type] LIKE '".$Tsite."'
OR $pnDiagramcolumn[city] LIKE '".$city."'
OR $pnDiagramcolumn[state] LIKE '".$state."'
OR $pnDiagramcolumn[tech1] LIKE '".$tech1."'
OR $pnDiagramcolumn[tech2] LIKE '".$tech2."'
OR $pnDiagramcolumn[tech3] LIKE '".$tech3."'
OR $pnDiagramcolumn[status] LIKE '".$status."'
OR $pnDiagramcolumn[diagram_type] LIKE '".$diagram."'
OR $pnDiagramcolumn[author] LIKE '".$author."'
OR $pnDiagramcolumn[category] LIKE '".$category."');
print_r($sql);
die;
}
Thanks
-SUNADMN -
- rank:
-
Helper
- registered:
- June 2002
- Status:
- offline
- last visit:
- 09.09.08
- Posts:
- 288
jediping is correct.
You need to use either SELECT * FROM $pnDiagramtable WHERE ( {your LIKE statements from above} )
or
SELECT $pnDiagramcolumn[column1],$pnDiagramcolumn[column2],$pnDiagramcolumn[column3]... FROM $pnDiagramtable WHERE ( {your LIKE statements from above} )
--
cyber_wolf
www.bkbsolutions.com - My Zikula module development site. -
- rank:
-
Helper
- registered:
- October 2004
- Status:
- offline
- last visit:
- 01.03.06
- Posts:
- 437
Ok so I have changed that up a bit and the statement looks ok but for some reason my vars are empty and I am not getting the form fields passed to the SQL statement. I will post some code here to have you guys look at it to see if you guys see an issue.
this is the pnuser.php search function:
Code
function pnDiagram_user_search()
{
if (!pnSecAuthAction(0, 'pnDiagram::', '::', ACCESS_OVERVIEW)) {
return pnVarPrepHTMLDisplay(_MODULENOAUTH);
}
$pnRender =& new pnRender('pnDiagram');
$pnRender->caching = false;
return $pnRender->fetch('pnDiagram_user_search.htm');
}
Which calls to this pnrender template:
Code
<!--[* $Id: pnDiagram_admin_modify.htm,v 1.9 2004/04/05 19:47:51 markwest exp $ *]-->
<!--[include file="pnDiagram_user_menu.htm"]-->
<br /><br />
<div class="pn-title"><!--[pnml name="_pnDiagramSEARCH"]--></div>
<br /><br />
<form action="<!--[pnmodurl modname="pnDiagram" type="user" func="query"]-->" method="post" enctype="application/x-www-form-urlencoded">
<div>
<input type="hidden" name="authid" value="<!--[pnsecgenauthkey module="pnDiagram"]-->" />
<input type="hidden" name="tid" value="<!--[$tid|pnvarprepfordisplay]-->" />
<table border="1" cellpadding="5" cellspacing="1"><tbody>
<tr>
<td><label for="pnDiagram_name"><!--[pnml name="_pnDiagramNAME"]--></label></td>
<td><input id="pnDiagram_name" name="itemname" type="text" size="32" maxlength="32" /></td>
</tr>
<tr>
<td><label for="pnDiagram_site_type"><!--[pnml name="_pnDiagramSITETYPE"]--></label></td>
<td><select name="Tsite" size="1" tabindex="3"><option value=""></option><option value="Master Headend">Master Headend</option><option value="Hub">Hub</option><option value="CoLocation">CoLocation</option><option value="Central Office">Central Office</option><option value="Aggregation Point">Aggregation Point</option></select></td>
</tr>
<tr>
<td><label for="pnDiagram_city"><!--[pnml name="_pnDiagramCITY"]--></label></td>
<td><input id="pnDiagram_city" name="city" type="text" size="32" maxlength="32" /></td>
</tr>
<tr>
<td><label for="pnDiagram_state"><!--[pnml name="_pnDiagramSTATE"]--></label></td>
<td><input id="pnDiagram_state" name="state" type="text" size="32" maxlength="32" /></td>
</tr>
<tr>
<td><label for="pnDiagram_technology"><!--[pnml name="_pnDiagramTECHNOLOGY"]--></label></td>
<td><label><input type="radio" name="tech1" value="PowerLink">PowerLink</label></td>
</tr>
<tr>
<td><label for="pnDiagram_technology"><!--[pnml name="_pnDiagramTECHNOLOGY"]--></label></td>
<td><label><input type="radio" name="tech2" value="Digital TV">Digital TV</label></td>
</tr>
<tr>
<td><label for="pnDiagram_technology"><!--[pnml name="_pnDiagramTECHNOLOGY"]--></label></td>
<td><label><input type="radio" name="tech3" value="Video on Demand">Video on Demand</label></td>
</tr>
<tr>
<td><label for="pnDiagram_status"><!--[pnml name="_pnDiagramSTATUS"]--></label></td>
<td><select name="status" size="1" tabindex="13"><option value=""></option><option value="Verified">Verified</option><option value="Unverified">Unverified</option><option value="Proposed">Proposed</option><option value="Acquisition">Acquisition</option></select></td>
</tr>
<tr>
<td><label for="pnDiagram_diagram"><!--[pnml name="_pnDiagramDIAGRAM"]--></label></td>
<td><select name="diagram" size="1" tabindex="11"><option value=""></option><option value="Port">Port</option><option value="Rack">Rack</option><option value="Vlan">Vlan</option><option value="Connectivity">Connectivity</option><option value="Overview">Overview</option></select></td>
</tr>
<tr>
<td><label for="pnDiagram_author"><!--[pnml name="_pnDiagramAUTHOR"]--></label></td>
<td><input id="pnDiagram_author" name="author" type="text" size="32" maxlength="32" /></td>
</tr>
<tr>
<td><label for="pnDiagram_category"><!--[pnml name="_pnDiagramCATEGORY"]--></label></td>
<td><select name="category" size="1" tabindex="11"><option value=""></option><option value="NorthEast">NorthEast</option><option value="SouthEast">SouthEast</option><option value="SoutherCal">SoutherCal</option><option value="Western">Western</option><option value="Central">Central</option></select></td>
</tr>
</table>
<input name="submit" type="submit" value="<!--[pnml name="_pnDiagramSEARCH"]-->" />
</div>
</form>
And that submits the data to my pnuser.php query function:
Code
function pnDiagram_user_query($args)
{
//print_r($args);
//die;
list($itemname,
$Tsite,
$city,
$state,
$tech1,
$tech2,
$tech3,
$status,
$diagram,
$author,
$category) = pnVarCleanFromInput('itemname',
'Tsite',
'city',
'state',
'tech1',
'tech2',
'tech3',
'status',
'diagram',
'author',
'category');
extract($args);
if (!pnSecConfirmAuthKey()) {
pnSessionSetVar('errormsg', pnVarPrepHTMLDisplay(_BADAUTHKEY));
pnRedirect(pnModURL('pnDiagram', 'user', 'view'));
return true;
}
if (!pnModAPILoad('pnDiagram', 'user')) {
pnSessionSetVar('errormsg', pnVarPrepHTMLDisplay(_LOADFAILED));
pnRedirect(pnModURL('pnDiagram', 'user', 'view'));
return true;
}
pnModAPIFunc('pnDiagram',
'user',
'query',
array('itemname' => $itemname,
'Tsite' => $Tsite,
'address' => $address,
'city' => $city,
'state' => $state,
'zip' => $zip,
'tech1' => $tech1,
'tech2' => $tech2,
'tech3' => $tech3,
'status' => $status,
'diagram' => $diagram,
'date' => $date,
'author' => $author,
'rev' => $rev,
'version' => $version,
'file' => $file,
'category' => $category));
pnRedirect(pnModURL('pnDiagram', 'user', 'view'));
// Return
return true;
}
This then calls the API function to do the search on the DB:
Code
function pnDiagram_userapi_query()
{
$dbconn =& pnDBGetConn(true);
$pntable =& pnDBGetTables();
$pnDiagramtable = &$pntable['pnDiagram_data'];
$pnDiagramcolumn = &$pntable['pnDiagram_data_column'];
$sql = "SELECT * FROM $pnDiagramtable WHERE(
$pnDiagramcolumn[site_name] LIKE '".$itemname."'
OR $pnDiagramcolumn[site_type] LIKE '".$Tsite."'
OR $pnDiagramcolumn[city] LIKE '".$city."'
OR $pnDiagramcolumn[state] LIKE '".$state."'
OR $pnDiagramcolumn[tech1] LIKE '".$tech1."'
OR $pnDiagramcolumn[tech2] LIKE '".$tech2."'
OR $pnDiagramcolumn[tech3] LIKE '".$tech3."'
OR $pnDiagramcolumn[status] LIKE '".$status."'
OR $pnDiagramcolumn[diagram_type] LIKE '".$diagram."'
OR $pnDiagramcolumn[author] LIKE '".$author."'
OR $pnDiagramcolumn[category] LIKE '".$category."')";
print_r($sql);
die;
}
As you can see right now I am just testing the SQL statement to ensure I have data being passed from the user functions to the API and for some reason I am not any ideas you all might have would be great.
Thanks
-SUNADMN -
- rank:
-
Helper
- registered:
- November 2004
- Status:
- offline
- last visit:
- 12.03.07
- Posts:
- 387
It looks like you're not passing any args to your query, as in function pnDiagram_userapi_query($args). :)
A question on the design of this search thing, though. Might it not be easier for the user to just enter one term in one box and then have the search function check that one term against all the columns? Or am I thinking too simplistically? Guess it depends on what you anticipating them searching for. The planning stages of programming always intrigue me. :D -
- rank:
-
Helper
- registered:
- October 2004
- Status:
- offline
- last visit:
- 01.03.06
- Posts:
- 437
OK so I get my args passed now but for some stupid reason I am not getting any data in the vars in the SQL statement. Here is what I have now:
API function:
Code
function pnDiagram_userapi_query($args)
{
//print_r($args);
//die;
$dbconn =& pnDBGetConn(true);
$pntable =& pnDBGetTables();
$pnDiagramtable = &$pntable['pnDiagram_data'];
$pnDiagramcolumn = &$pntable['pnDiagram_data_column'];
$sql = "SELECT * FROM $pnDiagramtable WHERE(
$pnDiagramcolumn[site_name] LIKE '%$itemname%'
OR $pnDiagramcolumn[site_type] LIKE '%$Tsite%'
OR $pnDiagramcolumn[city] LIKE '%$city%'
OR $pnDiagramcolumn[state] LIKE '%$state%'
OR $pnDiagramcolumn[tech1] LIKE '%$tech1%'
OR $pnDiagramcolumn[tech2] LIKE '%$tech2%'
OR $pnDiagramcolumn[tech3] LIKE '%$tech3%'
OR $pnDiagramcolumn[status] LIKE '%$status%'
OR $pnDiagramcolumn[diagram_type] LIKE '%$diagram%'
OR $pnDiagramcolumn[author] LIKE '%$author%'
OR $pnDiagramcolumn[category] LIKE '%$category%')";
print_r($sql);
die;
}
and when I print the SQL out I get this:
Code
SELECT * FROM nuke_pnDiagram_data WHERE( nuke_pnDiagram_data.site_name LIKE '%%' OR nuke_pnDiagram_data.site_type LIKE '%%' OR nuke_pnDiagram_data.city LIKE '%%' OR nuke_pnDiagram_data.state LIKE '%%' OR nuke_pnDiagram_data.tech1 LIKE '%%' OR nuke_pnDiagram_data.tech2 LIKE '%%' OR nuke_pnDiagram_data.tech3 LIKE '%%' OR nuke_pnDiagram_data.status LIKE '%%' OR nuke_pnDiagram_data.diagram_type LIKE '%%' OR nuke_pnDiagram_data.author LIKE '%%' OR nuke_pnDiagram_data.category LIKE '%%')
I have tried building the vars in the statement in the above method and like this:
Code
'".$itemname."',
Neither of these work, am I building this incorrectly???
Thanks
-SUNADMN -
- rank:
-
Helper
- registered:
- October 2004
- Status:
- offline
- last visit:
- 01.03.06
- Posts:
- 437
Ok so jedi do you have any idea how I would use the render engine to produce results from that quewry and I run the SQL??? I am a little lost here as this is a stand alone function and nothing in the module really looks like anything I would use her.
Thanks
-SUNADMN -
- rank:
-
Helper
- registered:
- October 2004
- Status:
- offline
- last visit:
- 01.03.06
- Posts:
- 437
Ok so it has to be back to basics here as I can't figure out how to port the logic of the view/dispaly function to port to a search as the view/display functions dont really return a single item for a given match rather produce all items in the DB.
So I am going to make a list here of what is needed and hope for some insite on what else I am missing:
1st) a Menu link to a user function that produces a pntemplate file for a seach form ( done I have this part working )
2nd) a query function for the pntemplate file to call to that will run the pnuserapi function to get the data ( for the most part this is done but I think I am missing some logic here )
3rd) a userapi function that takes the form data from the pntemplate and runs a
