[support] Re: taxonomy_access, php input, and role id...
Jiann-Ming Su
sujiannming at gmail.com
Thu Feb 9 08:08:28 UTC 2006
On 2/8/06, Jiann-Ming Su <sujiannming at gmail.com> wrote:
> I found the taxonomy_access module
> (http://drupal.org/project/taxonomy_access), which will almost do what
> I wanted for the home pages per user/role. When a user logs in, what
> variable when using php input denotes the role id? Or, is there even
> such a thing, since a user can belong to multiple roles?
>
> What I want to do specifically, is create a generic "downloads" page.
> When the user logs in and access the "downloads" page, the contents of
> the page is dynamically generated listing nodes he/she has access to
> as specified by the taxonomy_access module.
>
> I can sort of do this now by creating individual aliases for the
> taxonomy term, i.e. downloads1->taxonomy/term/X,
> downloads2->taxonomy/term/Y, etc. Ideally, I'd like to just have a
> "downloads" that lists term/X and/or term/Y depending on the user.
> I'm guessing I should be able to key off of the role id to dynamically
> generate such a page. Thanks for any tips and links.
>
I was able to piece together the following code snippet to do the
custom downloads page. This still requires proper use of the
taxonomy_access module.
<?php
/**
*
* http://drupal.org/node/30967
*/
global $user;
if ($user->uid ) {
if (1 != $user->uid) // If not the admin
{
// For each role, be sure there's a corresponding taxonomy term
// Role "MyRole" AND taxonomy term "MyRole"
// I know this snippet works if the user belongs to only one role
// corresponding to one taxonomy term.
$taxo_sql = "SELECT term_data.tid FROM term_data, role,
users_roles WHERE role.rid=users_roles.rid AND
role.name=term_data.name AND users_roles.uid=$user->uid";
$result = db_query($taxo_sql);
$taxo_id = db_result($result);
// print "taxonomy id = $taxo_id";
// http://drupal.org/node/30967
$listlength="5";
$result1 = pager_query(db_rewrite_sql("SELECT n.nid, n.created
FROM {node} n INNER JOIN term_node ON n.nid = term_node.nid WHERE
term_node.tid = $taxo_id AND n.status = 1 ORDER BY n.created DESC"),
$listlength);
while ($node = db_fetch_object($result1))
{
$output .= node_view(node_load(array('nid' => $node->nid)), 1);
}
print $output;
}
else // the admin
{
/**
* This php snippet displays a themed summary list of
* vocabulary term titles(x) from a specific category
* Where (x) is the number of nodes in each term.
* The Snippet ignores terms with no nodes.
*
* Tested and works with Drupal 4.6
* To change the vocabulary references, change the
* $vocabulary_id value to suit.
*
* http://drupal.org/node/31536
*/
$vocabulary_id = 5; // this is the vid of the vocabulary that
"MyRole" belongs to
$result = db_query("SELECT d.tid, d.name, MAX(n.created) AS
updated, COUNT(*) AS count FROM {term_data} d INNER JOIN {term_node}
USING (tid) INNER JOIN {node} n USING (nid) WHERE d.vid =
$vocabulary_id AND n.status = 1 GROUP BY d.tid, d.name ORDER BY
updated DESC, d.name");
$items = array();
while ($category = db_fetch_object($result))
{
$items[] = l($category->name .' ('. $category->count .')',
'taxonomy/term/'. $category->tid) .'<br />'. t('%time ago',
array('%time' => format_interval(time() - $category->updated)));
}
print theme('item_list', $items);
}
}
// else anonymous user
else {
// Echo the login form for anonymous users
// Set the destination to something relevant to your site
echo "<form action=\"userlogin.aspx?destination=user%2Flogin\"
method=\"post\">";
echo "<div class=\"form-item\">";
echo "<label for=\"edit-name\">Username:</label><br />";
echo "<input type=\"text\" maxlength=\"64\" class=\"form-text\"
name=\"edit[name]\" id=\"edit-name\" size=\"30\" value=\"\" />";
echo "<div class=\"description\">Enter your Fidelis Group username.</div>";
echo "</div>";
echo "<div class=\"form-item\">";
echo "<label for=\"edit-pass\">Password:</label><br />";
echo "<input type=\"password\" class=\"form-password\"
maxlength=\"64\" name=\"edit[pass]\" id=\"edit-pass\" size=\"30\"
value=\"\" />";
echo "<div class=\"description\">Enter the password that accompanies
your username.</div>";
echo "</div>";
echo "<input type=\"submit\" class=\"form-submit\" name=\"op\"
value=\"Log in\" />";
echo "</form>";
}
?>
--
Jiann-Ming Su
"I have to decide between two equally frightening options.
If I wanted to do that, I'd vote." --Duckman
"The system's broke, Hank. The election baby has peed in
the bath water. You got to throw 'em both out." --Dale Gribble
More information about the support
mailing list