#include <infodrom.style>
#include "lt.style"
#include "functions.inc"

<postgresconnect>

<ltpage title="Project Management">

<?
  if (isset ($project) && $project == 'Supporter' && !is_also_supporter()) {
    die ("Only supporters may read these page.");
  }

function build_appendix ($phone, $mobile, $comment)
{
  $appendix = '';
  if (strlen($phone) && preg_match("/(\+[0-9]+ [0-9]+ [0-9]+)/", $phone, $r))
    $appendix = $r[1];
  if (strlen($mobile) && preg_match(/"(\+[0-9]+ [0-9]+ [0-9]+)/", $mobile, $r)) {
    if (strlen ($appendix)){
      $appendix .= "/".$r[1];
    } else {
      $appendix = $r[1];
    }
  }

  if (strlen ($comment)) {
    if (strlen ($appendix)){
      $appendix .= ", ".$comment;
    } else {
      $appendix = $comment;
    }
  }

  return $appendix;
}
?>

<? if ((is_supporter() && empty ($project))
    || (isset ($project) && $project == 'Supporter' && is_also_supporter())) { ?>
  <h3>Supporters</h3>
<? } else { ?>
  <h3>Members of project <? echo empty ($project)?$LINUXTAG_AUTH['project']:$project; ?></h3>
<? } ?>

<p>
<?
  $query = sprintf ("SELECT id,name,email,person.oid,comment,mobile,phone FROM person,junction "
		   ."WHERE person = id AND junction.project = '%s' ORDER BY upper(name)",
		    empty ($project)?$LINUXTAG_AUTH['project']:$project);

  $sth = pg_exec($dbh, $query) or die("Datenbank-Abfrage!");

  $edit_permitted = false;
  if (empty ($project) && is_admin ()) {
    $edit_permitted = true;
  }

  if ($edit_permitted) {
    for ($nr = 0; $nr < pg_NumRows($sth); $nr++) {
      $row = pg_fetch_array ($sth, $nr);

      printf ("<br><a href=\"edit_person.php3?id=%d\">%s</a>",
	     $row['id'], $row['name']);
      if (strlen ($row['email']) > 0) {
        printf (" &lt;%s&gt;", $row['email']);
      }

      $appendix = build_appendix ($row['phone'], $row['mobile'], $row['comment']);
      if (strlen ($appendix)) {
	printf (" (%s)", $appendix);
      }
    }
  } else {
    for ($nr = 0; $nr < pg_NumRows($sth); $nr++) {
      $row = pg_fetch_array ($sth, $nr);

      printf ("<br>%s", $row['name']);
      if (strlen ($row['email']) > 0) {
        printf (" &lt;%s&gt;", $row['email']);
      }
      if (!isset ($project) || $LINUXTAG_AUTH['project'] == $project) {
	$appendix = build_appendix ($row['phone'], $row['mobile'], $row['comment']);
	if (strlen ($appendix)) {
	  printf (" (%s)", $appendix);
	}
      }
    }
  }
?>

</ltpage>

# Local variables:
# mode: indented-text
# mode: auto-fill
# end:
