Smarty Help: Changing the AssignName=UserName to UserId
Posted: Thu Jun 10, 2004 9:07 am
Hey. I have been working on this today.
I have my usergrid, in which i want to link up to a page, that shows all the information from my DB on the page like this:

but the page that sends which user i wish to view is sending the 'login' field of my DB to show the rest of the fields. I want it to send userId, and thus display all other fields:

So... Here is my code.
This code is from the DataGrid.TPL, WHICH gets data from DataGrid.PHP:
This gets the varibles from this file, DataGrid.PHP:
And finally, we have code from the OUTPUT/display of UsersView.tpl:
Also, this is some code from UsersView.php
I have my usergrid, in which i want to link up to a page, that shows all the information from my DB on the page like this:

but the page that sends which user i wish to view is sending the 'login' field of my DB to show the rest of the fields. I want it to send userId, and thus display all other fields:

So... Here is my code.
This code is from the DataGrid.TPL, WHICH gets data from DataGrid.PHP:
Code: Select all
<?php
{section name=user loop=$users}
{if $smarty.section.user.index % 2}
<tr>
<td bgcolor="#dddddd" class="text"><a class="link" href="frmUserInfo.php?assign_user={$users[user].user}">{$users[user].user}</a></td>
<td bgcolor="#dddddd" class="text">{$users[user].email}</td>
<td bgcolor="#dddddd" class="text">{$users[user].lastLogin|date_format:"%A %d of %B, %Y [%H:%M:%S]"}</td>
<td bgcolor="#dddddd" class="text">
{section name=grs loop=$users[user].groups}
{$users[user].groups[grs]}{if $users[user].groups[grs] != "Anonymous"}(<a class="link" href="frmUsersGrid.php?ruser={$users[user].user}&action=removegroup&group={$users[user].groups[grs]}">x</a>){/if}
{/section}
</td>
<td bgcolor="#dddddd" class="text">
<a class="link" href="frmUserInfo.php?assign_user={$users[user].user}">{tr}View Details{/tr}</a>
<a class="link" href="frmUserEdit.php?assign_user={$users[user].user}">{tr}Edit Details{/tr}</a>
<a class="link" href="frmUsersGrid.php?action=delete&user={$users[user].user}">{tr}Delete{/tr}</a>
</td>
</tr>
{else}
<tr>
<td bgcolor="#EEEECC" class="text"><a class="link" href="frmUserInfo.php?assign_user={$users[user].user}">{$users[user].user}</a></td>
<td bgcolor="#EEEECC" class="text">{$users[user].email}</td>
<td bgcolor="#EEEECC" class="text">{$users[user].lastLogin|date_format:"%A %d of %B, %Y [%H:%M:%S]"}</td>
<td bgcolor="#EEEECC" class="text">
{section name=grs loop=$users[user].groups}
{$users[user].groups[grs]}{if $users[user].groups[grs] != "Anonymous"}(<a class="link" href="frmUsersGrid.php?ruser={$users[user].user}&action=removegroup&group={$users[user].groups[grs]}">x</a>){/if}
{/section}
</td>
<td bgcolor="#EEEECC" class="text">
<a class="link" href="frmUserInfo.php?assign_user={$users[user].user}">{tr}View Details{/tr}</a>
<a class="link" href="frmUserEdit.php?assign_user={$users[user].user}">{tr}Edit Details{/tr}</a>
<a class="link" href="frmUsersGrid.php?action=delete&user={$users[user].user}">{tr}Delete{/tr}</a>
</td></td>
</tr>
{/if}
{/section}
?>This gets the varibles from this file, DataGrid.PHP:
Code: Select all
<?php
$users = $userlib->GetUsers($offset,$maxRecords,$sort_mode,$find);
$cant_pages = ceil($users["cant"] / $maxRecords);
$smarty->assign('cant_pages',$cant_pages);
$smarty->assign('actual_page',1+($offset/$maxRecords));
if($users["cant"] > ($offset+$maxRecords)) {
$smarty->assign('next_offset',$offset + $maxRecords);
} else {
$smarty->assign('next_offset',-1);
}
// If offset is > 0 then prev_offset
if($offset>0) {
$smarty->assign('prev_offset',$offset - $maxRecords);
} else {
$smarty->assign('prev_offset',-1);
}
// Get users (list of users)
$smarty->assign('users',$users["data"]);
// Display the template
$smarty->assign('tbody','frmUsersGrid.tpl');
?>And finally, we have code from the OUTPUT/display of UsersView.tpl:
Code: Select all
<?php
<h2>User Information/Details</h2>
<table>
<tr><td class="textbl">USERID:</td><td class="text">{$user_info.userId}</td>
<tr><td class="textbl">Login:</td><td class="text">{$user_info.login}</td>
<tr><td class="textbl">Email:</td><td class="text">{$user_info.email}</td>
<tr><td class="textbl">Real Name:</td><td class="text">{$user_info.realname}</td>
<tr><td class="textbl">Country:</td><td class="text">{$user_info.country}</td>
<tr><td class="textbl">Home Page:</td><td class="text">{$user_info.homePage}</td>
<tr><td class="textbl">Groups:</td><td class="text">
{section name=grp loop=$user_info.groups}
{$user_info.groups[grp]}{if $user_info.groups[grp] != "Anonymous"}(<a class="link" href="assignuser.php?assign_user={$assign_user}&action=removegroup&group={$user_info.groups[grp]}">x</a>){/if}
{/section}
</td></tr>
</table>
?>Also, this is some code from UsersView.php
Code: Select all
<?php
$user_info = $userlib->GetUserInfo($assign_user);
$smarty->assign('user_info',$user_info);
if(!isset($_REQUEST["sort_mode"])) {
$sort_mode = 'groupName_desc';
} else {
$sort_mode = $_REQUEST["sort_mode"];
}
$smarty->assign('sort_mode',$sort_mode);
// If offset is set use it if not then use offset =0
// use the maxRecords php variable to set the limit
// if sortMode is not set then use lastModif_desc
if(!isset($_REQUEST["offset"])) {
$offset = 0;
} else {
$offset = $_REQUEST["offset"];
}
$smarty->assign('offset',$offset);
if(isset($_REQUEST["find"])) {
$find = $_REQUEST["find"];
} else {
$find = '';
}
$users = $userlib->GetGroups($offset,$maxRecords,$sort_mode,$find);
$cant_pages = ceil($users["cant"] / $maxRecords);
$smarty->assign('cant_pages',$cant_pages);
$smarty->assign('actual_page',1+($offset/$maxRecords));
if($users["cant"] > ($offset+$maxRecords)) {
$smarty->assign('next_offset',$offset + $maxRecords);
} else {
$smarty->assign('next_offset',-1);
}
?>