<?php	// TWIG		Commonly used functions.	?>
<?php

 // Set group query info according to membership, etc.
 // if no group, set to default
 if (!isset($thisGroup)) {
  if ($defaultgroup[$command]) { $thisGroup = $defaultGroup[$command]; }
  else { $thisGroup = "*"; }
 }
 if ($thisGroup == "0") { // group is "Unfiled"
  $groupquery = " username = '$PHP_AUTH_USER' AND groupid = 0";
 }
 elseif ($thisGroup == "*") { // group is "ALL"
  $groupquery = " username = '$PHP_AUTH_USER' ";
  $go = @join(groupOwnership($PHP_AUTH_USER)," OR groupid = ");
  if ($go) { $groupquery .= "OR groupid = " . $go; }
  $gm = @join(groupMembership($PHP_AUTH_USER)," OR groupid = ");
  if ($gm) { $groupquery .= " OR groupid = " . $gm; }
 }
 else { // group is $thisGroup
  // FIXME this needs to handle errors better
  if (memberOf($thisGroup)) { $groupquery=" groupid = $thisGroup "; }
  elseif (groupOwner($thisGroup) == $PHP_AUTH_USER) {
   $groupquery=" groupid = $thisGroup ";
  }
  else { $groupquery = " groupid = -1 "; }
 }

?>
