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

<postgresconnect>

<ltpage title="Project Management">

<p>Welcome <? echo $LINUXTAG_AUTH['name']; ?>!</p>

<? if (!isset ($project)) { ?>
<? if (is_admin()) { ?>

<p>In this system you may edit your personal information, information
of members of the project <? echo $LINUXTAG_AUTH['project']; ?>, add
new members to this project and finally read, edit and add new
comments, which store information useful for other project members and
the LinuxTag team.  You may also take a look at information from other
projects.</p>

<? } else { ?>

<p>In this system you may edit your personal information and read or
add new comments, which store information useful for other project
members and the LinuxTag team.  You may also take a look at
information from other projects.</p>

<? } ?>
<? } ?>

<p>
<?
  $templ_descr = '
<table width=100%% cellpadding=3>
<tr>
<td width=50%% bgcolor=#<cold>><font size="-1" face="Helvetica,Arial">%s</font></td>
<td width=50%% bgcolor=#<cold>><font size="-1" face="Helvetica,Arial">%s</font></td>
</tr>
</table>
';

  function members ($project)
  {
    global $dbh;

     $query = sprintf ("SELECT COUNT(*) FROM person,junction WHERE person = id "
                     ."AND junction.project = '%s' AND list = 0", $project);

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

    if (pg_NumRows ($sth) > 0) {
      $row = pg_fetch_array ($sth, 0);
      return $row[0];
    }
  }

  if (isset ($project)) {
    if ($project == 'Supporter' && !is_also_supporter()) {
      die ("Only supporters may read these page.");
    }
    $query_project = addslashes($project);
  } else {
    $query_project = addslashes($LINUXTAG_AUTH['project']);
  }

  $query = sprintf ("SELECT boothnr,computer,url FROM project WHERE name = '%s'",
		    $query_project);
  $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");

  if (pg_NumRows ($sth) > 0) {
    $row = pg_fetch_array ($sth, 0);
    $data['url'] = $row['url'];
    $data['boothnr'] = $row['boothnr'];
    $data['computer'] = $row['computer'];
  }

  $query = sprintf ("SELECT description,description_en FROM appendix WHERE project = '%s'",
		    $query_project);
  $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");

  if (pg_NumRows ($sth) > 0) {
    $row = pg_fetch_array ($sth, 0);
    $data['description'] = strlen ($row['description'])
			   ? $row['description'] : "Keine Beschreibung vorhanden.";
    $data['description_en'] = strlen ($row['description_en'])
			      ? $row['description_en'] : "No description available.";
  }

  if (!is_supporter() || isset ($project)) {
    printf ("<b>Project name:</b> %s", isset ($project)?$project:$LINUXTAG_AUTH['project']);
    if (strlen ($data['url']) > 0) {
      printf ("<br><b>URL:</b> <a href=\"%s\">%s</a>", $data['url'], $data['url']);
    }
    if (strlen ($data['boothnr']) > 0) {
      printf ("<br><b>Booth Nr.:</b> %s", $data['boothnr']);
    }
    # Display the desciptions of the project
    #
    printf ($templ_descr, $data['description'], $data['description_en']);

    if (!isset ($project)) {
      printf ("<br><b>Number of machines:</b> %d", $data['computer']);
    }
    printf ("<br><b>Members:</b> %d", members ($query_project));

    $query = sprintf ("SELECT oid,url,description,visible FROM urls WHERE project = '%s'",
		      $query_project);
    if (isset ($project)) {
      $query .= " AND visible = 1";
    }
    $query .= " ORDER BY upper(description)";

    $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
    if (pg_NumRows ($sth) > 0) {
      echo ("<br><b>Additional URLs:</b><ol>");
      if (is_admin() && !isset ($project)) {
	for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
	  $row = pg_fetch_array ($sth, $nr);
	  printf ("<li><a href=\"%s\">%s</a>%s <a href=\"edit_url.php3?oid=%d\">Edit</a>",
		  $row['url'], $row['description'],
		  $row['visible']==1?'':" (intern)",
		  $row['oid']);
	}
      } else {
	for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
	  $row = pg_fetch_array ($sth, $nr);
	  printf ("<li><a href=\"%s\">%s</a>%s",
		  $row['url'], $row['description'],
		  $row['visible']==1?'':" (intern)");
	}
      }
      echo ("</ol>");
    }

    $query = sprintf ("SELECT workshop.oid,title,name,email,date_time,abstract,visible FROM workshop,person "
		     ."WHERE person = id AND ( workshop.project = '%s' OR person = %d )",
		      $query_project, $LINUXTAG_AUTH['id']);
    if (isset ($project)) {
      $query .= " AND visible = 1";
    }
    $query .= " ORDER BY date_time,upper(name),upper(title)";

    $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
    if (pg_NumRows ($sth) > 0) {
      echo ("<br><b>Workshops:</b><ol>");

      if (is_admin() && !isset ($project)) {
	for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
	  $row = pg_fetch_array ($sth, $nr);
	  $date	= explode (" ", $row['date_time']);
	  $time	= $date[1];
	  $time	= explode (":", $time);
	  $time = sprintf ("%02d:%02d", $time[0], $time[1]);
	  $date	= $date[0];
	  printf ("<li><a href=\"display_workshop.php3?oid=%d%s\">%s: %s</a> (%s %s)",
		  $row['oid'],
		  $urlappend,
		  $row['name'], $row['title'],
		  $date, $time);
	}
      } else {
        if (isset ($project)) {
	  $urlappend = "&project=" . urlencode ($project);
	} else {
	  $urlappend = '';
	}
	for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
	  $row = pg_fetch_array ($sth, $nr);
	  $date	= explode (" ", $row['date_time']);
	  $time	= $date[1];
	  $time	= explode (":", $time);
	  $time = sprintf ("%02d:%02d", $time[0], $time[1]);
	  $date	= $date[0];
	  if (($row['name'] == $LINUXTAG_AUTH['name'] && $row['email'] == $LINUXTAG_AUTH['email'])
	     || strlen ($row['abstract'])) {
	    printf ("<li><a href=\"display_workshop.php3?oid=%d%s\">%s: %s</a> (%s %s)",
		    $row['oid'],
	            $urlappend,
		    $row['name'], $row['title'],
		    $date, $time);
	  } else {
	    printf ("<li>%s: %s (%s %s)",
		    $row['name'], $row['title'],
		    $date, $time);
	  }
	}
      }
      echo ("</ol>");
    }

  }
?>
</p>

<p>

##### This code is temporaly disabled

## Check for new comments
#<?
#$query = sprintf("select count(*) from comments where date > (select max(lastcomments) from person " .
#		 " where email = '%s')", addslashes($LINUXTAG_AUTH['email']));
#$sth = pg_exec($dbh, $query) or die ("Datenbank-Fehler");
#if (pg_NumRows($sth) > 0)
#{
#	$row = pg_fetch_array($sth, 0);
#} else {
#	die ("No rows");
#}
#if ($row[0] > 0)
#{
#	echo 'You got ' . $row[0] . ' new <a href="comments.php3">comments</a>';
#} else {
#	echo 'You got no new comments';
#}
#?>

# 	if (has logged in before)[1]
# 	  all recent comments
# 	else
# 	  three most recently added comments
# 	fi

</p>

<? if (!isset ($project)) { ?>
<hr>
<p>Important information may be found <a href="http://www.infodrom.org/Debian/events/LinuxTag2005/">here</a>.</p>
<?   if (is_also_supporter()) { ?>

<p>For communication and coordination of work for the upcoming
LinuxTag there is an IRC channel #LinuxTag on IRCnet.  This can not
properly be used during LinuxTag, when the phone needs to be used
instead.</p>

<?   } ?>
<? } ?>

</ltpage>

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