I have 2 files, .tpl and .inc.php
In my .inc.php I am using 2 querys to get some data. With the smarty, I am passing the query responses to the .tpl file and showing those data in the table and in a select list.
Now, I would like that my list updates automaticaly when the user selects a new item in the select list.
I am actually able to detect the changes on the selection list.
The problem is, how could I call the function
updateToolPrivilegesTableForSelectedTool($Object)
from the .tpl file. The function is in .inc.php file. This shuld be possible with jquery but I don't know how.
Here is my code:
PHP:
<?php
updateToolPrivilegesTable();
$tool =$_DB->queryRaw("SELECT objects FROM backend_menu WHERE parent != 0");
while ($row_tool = $tool->next_assoc())
{
$resultstool[] = $row_tool;
}
$smarty->assign("tool_name",$resultstool);
$smarty->assign("privileges",$resultsprivlieges);
$smarty->TDisplay("users/backend_tools_user_privileges.tpl", "Backend Tools Privileges", "general-content.tpl");
function updateToolPrivilegesTable()
{
global $_DB;
global $resultsprivlieges;
$resultsprivlieges = array();
$privlieges = $_DB->queryRaw("SELECT `group_id`, `user_id`, `Object`, `Read`, `Update`, `Insert`, `Delete` FROM `backend_privileges`");
while ($row = $privlieges->next_assoc())
{
$resultsprivlieges[] = $row;
}
}
function updateToolPrivilegesTableForSelectedTool($Object)
{
global $_DB;
global $resultsprivlieges;
$resultsprivlieges = array();
$privlieges = $_DB->queryRaw("SELECT `group_id`, `user_id`, `Object`, `Read`, `Update`, `Insert`, `Delete` FROM `backend_privileges` WHERE `Object`=$Object");
while ($row = $privlieges->next_assoc())
{
$resultsprivlieges[] = $row;
}
}
?>
HTML (.tpl)
<h1> Backend Tools Privileges</h1>
<table>
<tr>
<td>Tool</td>
<td>
<SELECT name="object" id="selectTool">
{foreach from=$tool_name item=toolItem name=foo}
<OPTION name="object" VALUE="{$toolItem['objects']}">{$toolItem['objects']}</OPTION>
{/foreach}
</SELECT>
</td>
</tr>
</table>
<table width='700px' id="employeetable" class="tablesorter" style='table-layout:fixed;'>
<thead>
<tr>
<th>Group Id</th>
<th>User Id</th>
<th>Object</th>
<th>Read</th>
<th>Update</th>
<th>Insert</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
{foreach from=$privileges item=privilegesItem name=foo}
<tr>
<td>{$privilegesItem['group_id']}</td>
<td>{$privilegesItem['user_id']}</td>
<td>{$privilegesItem['Object']}</td>
<td>{$privilegesItem['Read']}</td>
<td>{$privilegesItem['Update']}</td>
<td>{$privilegesItem['Insert']}</td>
<td>{$privilegesItem['Delete']}</td>
</tr>
{/foreach}
</tbody>
</table>
</form>
{literal}
<script type="text/javascript">
$(selectTool).change(function()
{
!!!!!!! Here I shuld call the function updateToolPrivilegesTableForSelectedTool($Object) from .php file.
}
</script>
{/literal}