Location: PHPKode > scripts > ScreamingToDos > std-0.9/functions.php
<?PHP

$currentdate = date("d-m-Y");

header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("Expires: -1");

function qDB ($q) {
 mysql_connect($GLOBALS["dbhost"],$GLOBALS["dbuser"],$GLOBALS["dbpass"]);
 $r = mysql_db_query($GLOBALS["dbname"],$q);
 return $r;
}

function makeAnchor($str) {
 $str = eregi_replace("(http|https|ftp)://([a-z0-9\-\./]+\.[a-z0-9]{2,3})","<a href=\"\\1://\\2\"target=\"_blank\">\\1://\\2</a>",$str);
 $str = eregi_replace("([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})","<a href=\"mailto:\\1\">\\1</a>",$str);
 return $str;
}

function showitem($todoD,$type,$showData,$showComments) {

 if ($type == "open") { $stateText = "close"; }
 elseif ($type == "closed") { $stateText = "open"; }

 if ($showData) {

  $r = qDB("SELECT id,comment,owner FROM ".$GLOBALS["commentstable"] ." WHERE todoid=".$todoD["id"]);
  $rNumRows = mysql_num_rows($r);
  $rStr = ":$rNumRows:";

 if (strrpos($GLOBALS["REQUEST_URI"],"?") == 0) {
  $new_url = $GLOBALS["REQUEST_URI"]."?";
 } else {
  $new_url = $GLOBALS["REQUEST_URI"]."&";
 }

?>
<tr>
 <td bgcolor="<?PHP echo $GLOBALS["backCol"] ?>" align="center"><font face="<?PHP echo $GLOBALS["pageFont"] ?>" color="<?PHP echo $GLOBALS["foreCol"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><nobr><?PHP echo $todoD["created_date"] ?></nobr></font></td>

<?PHP if ($type == "open") { ?>
 <td bgcolor="<?PHP echo $GLOBALS["backCol"] ?>" align="center"><font face="<?PHP echo $GLOBALS["pageFont"] ?>" color="<?PHP echo $GLOBALS["foreCol"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><nobr><?PHP echo substr($todoD["due_date"],0,10) ?></nobr></font></td>
<?PHP } else { ?>
 <td bgcolor="<?PHP echo $GLOBALS["backCol"] ?>" align="center"><font face="<?PHP echo $GLOBALS["pageFont"] ?>" color="<?PHP echo $GLOBALS["foreCol"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><nobr><?PHP echo substr($todoD["closed_date"],0,10) ?></nobr></font></td>
<?PHP } ?>

 <td bgcolor="<?PHP echo $GLOBALS["backCol"] ?>" align="center"><font face="<?PHP echo $GLOBALS["pageFont"] ?>" color="<?PHP echo $GLOBALS["foreCol"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP echo $todoD["priority"] ?></font></td>

<?PHP if ($GLOBALS["multiuser"]) { ?>
 <td bgcolor="<?PHP echo $GLOBALS["backCol"] ?>" align="center"><font face="<?PHP echo $GLOBALS["pageFont"] ?>" color="<?PHP echo $GLOBALS["foreCol"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP echo $todoD["owner"] ?></font></td>
<?PHP } ?>

 <td bgcolor="<?PHP echo $GLOBALS["backCol"] ?>" align="center"><font face="<?PHP echo $GLOBALS["pageFont"] ?>" color="<?PHP echo $GLOBALS["foreCol"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP if (!($GLOBALS["print"])) { echo makeAnchor($todoD["task"]); } else { echo $todoD["task"]; } ?></font></td>

<?PHP if (!($GLOBALS["print"])) { ?>
 <td bgcolor="<?PHP echo $GLOBALS["backCol"] ?>" align="center"><font face="<?PHP echo $GLOBALS["pageFont"] ?>" color="<?PHP echo $GLOBALS["foreCol"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><a href="edittask.php?editnum=<?PHP echo $todoD["id"] ?>">Modify</a></font></td>
<?PHP } ?>

 <td bgcolor="<?PHP echo $GLOBALS["backCol"] ?>" align="center"><font face="<?PHP echo $GLOBALS["pageFont"] ?>" color="<?PHP echo $GLOBALS["foreCol"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP if (!($GLOBALS["print"])) { ?><a href="comments.php?id=<?PHP echo $todoD["id"] ?>">Modify</a><?PHP } ?><?PHP echo $rStr ?></font></td>

<?PHP if (!($GLOBALS["print"])) { ?>
 <td bgcolor="<?PHP echo $GLOBALS["backCol"] ?>" align="center"><font face="<?PHP echo $GLOBALS["pageFont"] ?>" color="<?PHP echo $GLOBALS["foreCol"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><a href="<?PHP echo $new_url ?><?PHP echo $stateText ?>num=<?PHP echo $todoD["id"] ?>&category=<?PHP echo $todoD["categoryid"] ?>"><?PHP echo ucfirst($stateText) ?></a></font></td>

 <td bgcolor="<?PHP echo $GLOBALS["backCol"] ?>" align="center"><font face="<?PHP echo $GLOBALS["pageFont"] ?>" color="<?PHP echo $GLOBALS["foreCol"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><a href="javascript:if(doublecheck()){ document.location.href='<?PHP echo $new_url ?>deletenum=<?PHP echo $todoD["id"] ?>';}">Delete</a></font></td>
<?PHP } ?>

</tr>
<?PHP
  if ($rNumRows > 0) {
   while ($commentD = mysql_fetch_array($r)) {
    if ($showComments) {
?>
 <tr>
   <td colspan="3">&nbsp;</td>
<?PHP if ($GLOBALS["multiuser"]) { ?>
   <td bgcolor="<?PHP echo $GLOBALS["commentsBackCol"] ?>" align="center"><font face="<?PHP echo $GLOBALS["pageFont"] ?>" color="<?PHP echo $GLOBALS["commentsForeCol"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP echo $commentD["owner"] ?></td>
<?PHP } ?>
   <td colspan="5" bgcolor="<?PHP echo $GLOBALS["commentsBackCol"] ?>" align="center"><font face="<?PHP echo $GLOBALS["pageFont"] ?>" color="<?PHP echo $GLOBALS["commentsForeCol"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP if (!($GLOBALS["print"])) { echo makeAnchor($commentD["comment"]); } else { echo $commentD["comment"]; } ?></td>
<?PHP
    }
   }
?> </tr> <?PHP
  }
 }
}

function showTableHeader($categoryD,$type,$showComments) {

?><center><?PHP

if ($GLOBALS["fromCalendar"]) { ?>
 <font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="+<?PHP echo ($GLOBALS["pageFontsize"]+2) ?>">
  <?PHP echo $categoryD["category"] ?>
 </font>
<?PHP
 $closed_show = "no";
 $open_show = "no";

} else { ?>
 <form method="post" action="<?PHP echo $GLOBALS["REQUEST_URI"] ?>">
   <font face="<?PHP echo $GLOBALS["pageFont"] ?>">
<?PHP
 if ($type == "closed") {
  $stateText = "Open";
  if ($categoryD["closed_show"]) { $closed_show = "no"; } else { $closed_show = "yes"; }
  echo "<input type=\"hidden\" name=\"upshclosed\" value=\"$closed_show\">";
 } elseif ($type == "open") {
  $stateText = "Close"; 
  if ($categoryD["open_show"]) { $open_show = "no"; } else { $open_show = "yes"; }
  echo "<input type=\"hidden\" name=\"upshopen\" value=\"$open_show\">";
 }
?>
  <input type="hidden" name="category" value="<?PHP echo $categoryD["id"] ?>">
  <input type="submit" value="<?PHP echo $categoryD["category"] ?>" style="background:<?PHP echo $GLOBALS["pageBackCol"] ?>; color:<?PHP echo $GLOBALS["pageForeCol"] ?>; font-weight: bold"></form>
<?PHP } ?>
<font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"> :<?PHP echo strtoupper($type) ?>: :<?PHP echo $GLOBALS["totaltasks"] ?></a>:</font>
<?PHP
 if ((($closed_show == "no") || ($open_show == "no")) && ($GLOBALS["totaltasks"] > 0)) {
  if ($type == "closed") {
   if ($categoryD["closed_show_comments"]) { $commentsortALT = "no"; } else { $commentsortALT = "yes"; }
  } else {
   if ($categoryD["open_show_comments"]) { $commentsortALT = "no"; } else { $commentsortALT = "yes"; }
  }
 if (strrpos($GLOBALS["REQUEST_URI"],"?") == 0) {
  $new_url = $GLOBALS["REQUEST_URI"]."?";
 } else {
  $new_url = $GLOBALS["REQUEST_URI"]."&";
 }
?>
<form method="post" action="<?PHP echo $GLOBALS["REQUEST_URI"] ?>">
<table width="90%" border="0" align="center">
 <tr>
 <td align="center"><strong><font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP if (!($GLOBALS["print"])) { ?><a href="<?PHP echo $new_url ?><?PHP echo $type ?>_sortby=created_date&category=<?PHP echo $categoryD["id"] ?>"><?PHP } ?>Date added</a></font></strong></td>

<?PHP if ($type == "open") { ?>
 <td align="center"><strong><font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP if (!($GLOBALS["print"])) { ?><a href="<?PHP echo $new_url ?><?PHP echo $type ?>_sortby=due_date&category=<?PHP echo $categoryD["id"] ?>"><?PHP } ?>Due date</a></font></strong></td>
<?PHP } else { ?>
 <td align="center"><strong><font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP if (!($GLOBALS["print"])) { ?><a href="<?PHP echo $new_url ?><?PHP echo $type ?>_sortby=closed_date&category=<?PHP echo $categoryD["id"] ?>"><?PHP } ?>Closed date</a></font></strong></td>
<?PHP } ?>

 <td align="center"><strong><font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP if (!($GLOBALS["print"])) { ?><a href="<?PHP echo $new_url ?><?PHP echo $type ?>_sortby=priority&category=<?PHP echo $categoryD["id"] ?>"><?PHP } ?>Priority</a></font></strong></td>

<?PHP if ($GLOBALS["multiuser"]) { ?>
 <td align="center"><strong><font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP if (!($GLOBALS["print"])) { ?><a href="<?PHP echo $new_url ?><?PHP echo $type ?>_sortby=owner&category=<?PHP echo $categoryD["id"] ?>"><?PHP } ?>Owner</a></font></strong></td>
<?PHP } ?>

 <td align="center" width="100%"><strong><font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP if (!($GLOBALS["print"])) { ?><a href="<?PHP echo $new_url ?><?PHP echo $type ?>_sortby=task&category=<?PHP echo $categoryD["id"] ?>"><?PHP } ?>Task</a></font></strong></td>

<?PHP if (!($GLOBALS["print"])) { ?>
  <td align="center"><strong><font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>">Modify</font></strong></td>
<?PHP } ?>

 <td align="center"><strong><font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP if (!($GLOBALS["print"])) { ?><a href="<?PHP echo $new_url ?><?PHP echo $type ?>_show_comments=<?PHP echo $commentsortALT ?>&category=<?PHP echo $categoryD["id"] ?>"><?PHP } ?><?PHP if (!($GLOBALS["print"])) { if ($showComments) { echo "Hide c"; } else { echo "Show c"; } } else { echo "C"; } ?>omments</a></font></strong></td>

<?PHP if (!($GLOBALS["print"])) { ?>
  <td align="center"><strong><font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>"><?PHP echo $stateText ?></font></strong></td>
  <td align="center"><strong><font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>">Delete</font></strong></td>
<?PHP } ?>
 </tr>
<?PHP
 }
}

function getvars ($username) {
 if (!($username)) { echo "Oops! There's no username to get the parameters of!"; exit; }
 if (!($GLOBALS["updateprefs"])) {
  $q = "SELECT username, usergroup, created_date, last_logged_in, auto_open_category, show_empty_categories,";
  $q = $q." comments_sortby, category_sortby, user_sortby, themeid, start_page, last_todo_closed, last_todo_owner,";
  $q = $q." last_todo_priority, last_todo_categoryid, last_todo_month, last_todo_day, last_todo_year, last_todo_hour,";
  $q .= " last_todo_minutes, last_todo_ampm FROM ".$GLOBALS["usertable"]." WHERE username=\"$username\"";

  $r = qDB($q);
  $d = mysql_fetch_array($r);

  $GLOBALS["username"] = $d["username"];
  $GLOBALS["usergroup"] = $d["usergroup"];
  $GLOBALS["user_creationdate"] = $d["created_date"];
  $GLOBALS["last_logged_in"] = $d["last_logged_in"];
  $GLOBALS["auto_open_category"] = $d["auto_open_category"];
  $GLOBALS["show_empty_categories"] = $d["show_empty_categories"];
  $GLOBALS["comments_sortby"] = $d["comments_sortby"];
  $GLOBALS["category_sortby"] = $d["category_sortby"];
  $GLOBALS["user_sortby"] = $d["user_sortby"];
  $GLOBALS["themeid"] = $d["themeid"];
  $GLOBALS["start_page"] = $d["start_page"];
  $GLOBALS["last_todo_closed"] = $d["last_todo_closed"];
  $GLOBALS["last_todo_owner"] = $d["last_todo_owner"];
  $GLOBALS["last_todo_priority"] = $d["last_todo_priority"];
  $GLOBALS["last_todo_categoryid"] = $d["last_todo_categoryid"];
  $GLOBALS["last_todo_month"] = $d["last_todo_month"];
  $GLOBALS["last_todo_day"] = $d["last_todo_day"];
  $GLOBALS["last_todo_year"] = $d["last_todo_year"];
  $GLOBALS["last_todo_hour"] = $d["last_todo_hour"];
  $GLOBALS["last_todo_minutes"] = $d["last_todo_minutes"];
  $GLOBALS["last_todo_ampm"] = $d["last_todo_ampm"];

  $q = "SELECT id, theme, highBackCol, medBackCol, lowBackCol, doneBackCol, commentsBackCol, categoryBackCol,";
  $q = $q." highForeCol, medForeCol, lowForeCol, doneForeCol, commentsForeCol, categoryForeCol, errorForeCol,";
  $q = $q." categoryForeCol, errorForeCol, pageBackCol, pageForeCol, pageLinkCol, pageVlinkCol, pageAlinkCol,";
  $q = $q." pageFontsize, pageFont, CSS_hover_td, CSS_hover_font_style, CSS_hover_font_variant, CSS_hover_font_size,";
  $q = $q." CSS_hover_font_weight, CSS_hover_font_family, CSS_hover_bg, CSS_anchor_td, CSS_anchor_font_style,";
  $q = $q." CSS_anchor_font_variant, CSS_anchor_font_size, CSS_anchor_font_weight, CSS_anchor_font_family,";
  $q = $q." CSS_anchor_bg, CSS_active_td, CSS_active_font_style, CSS_active_font_variant, CSS_active_font_size,";
  $q = $q." CSS_active_font_weight, CSS_active_font_family, CSS_active_bg, CSS_visited_td, CSS_visited_font_style,";
  $q = $q." CSS_visited_font_variant, CSS_visited_font_size, CSS_visited_font_weight, CSS_visited_font_family,";
  $q = $q." CSS_visited_bg, cal_headingBackCol, cal_daysBackCol, cal_datesBackCol, cal_todayBackCol, cal_headingForeCol,";
  $q .= " cal_daysForeCol,cal_datesForeCol, cal_todayForeCol FROM ".$GLOBALS["themetable"]." WHERE id=".$GLOBALS["themeid"];
 
  $r = qDB($q);
  $d = mysql_fetch_array($r);

  if ($d["highBackCol"]) { $GLOBALS["highBackCol"] = "#".$d["highBackCol"]; }
  if ($d["medBackCol"]) { $GLOBALS["medBackCol"] = "#".$d["medBackCol"]; }
  if ($d["lowBackCol"]) { $GLOBALS["lowBackCol"] = "#".$d["lowBackCol"]; }
  if ($d["doneBackCol"]) { $GLOBALS["doneBackCol"] = "#".$d["doneBackCol"]; }
  if ($d["commentsBackCol"]) { $GLOBALS["commentsBackCol"] = "#".$d["commentsBackCol"]; }
  if ($d["categoryBackCol"]) { $GLOBALS["categoryBackCol"] = "#".$d["categoryBackCol"]; }

  if ($d["highForeCol"]) { $GLOBALS["highForeCol"] = "#".$d["highForeCol"]; }
  if ($d["medForeCol"]) { $GLOBALS["medForeCol"] = "#".$d["medForeCol"]; }
  if ($d["lowForeCol"]) { $GLOBALS["lowForeCol"] = "#".$d["lowForeCol"]; }
  if ($d["doneForeCol"]) { $GLOBALS["doneForeCol"] = "#".$d["doneForeCol"]; }
  if ($d["commentsForeCol"]) { $GLOBALS["commentsForeCol"] = "#".$d["commentsForeCol"]; }
  if ($d["categoryForeCol"]) { $GLOBALS["categoryForeCol"] = "#".$d["categoryForeCol"]; }
  if ($d["errorForeCol"]) { $GLOBALS["errorForeCol"] = "#".$d["errorForeCol"]; }

  if ($d["cal_headingBackCol"]) { $GLOBALS["cal_headingBackCol"] = "#".$d["cal_headingBackCol"]; }
  if ($d["cal_daysBackCol"]) { $GLOBALS["cal_daysBackCol"] = "#".$d["cal_daysBackCol"]; }
  if ($d["cal_datesBackCol"]) { $GLOBALS["cal_datesBackCol"] = "#".$d["cal_datesBackCol"]; }
  if ($d["cal_todayBackCol"]) { $GLOBALS["cal_todayBackCol"] = "#".$d["cal_todayBackCol"]; }
  if ($d["cal_headingForeCol"]) { $GLOBALS["cal_headingForeCol"] = "#".$d["cal_headingForeCol"]; }
  if ($d["cal_daysForeCol"]) { $GLOBALS["cal_daysForeCol"] = "#".$d["cal_daysForeCol"]; }
  if ($d["cal_datesForeCol"]) { $GLOBALS["cal_datesForeCol"] = "#".$d["cal_datesForeCol"]; }
  if ($d["cal_todayForeCol"]) { $GLOBALS["cal_todayForeCol"] = "#".$d["cal_todayForeCol"]; }

  if ($d["pageBackCol"]) { $GLOBALS["pageBackCol"] = "#".$d["pageBackCol"]; }
  if ($d["pageForeCol"]) { $GLOBALS["pageForeCol"] = "#".$d["pageForeCol"]; }
  $GLOBALS["pageFontsize"] = $d["pageFontsize"];
  $GLOBALS["pageFont"] = $d["pageFont"];

  if ($d["pageLinkCol"]) { $GLOBALS["pageLinkCol"] = "#".$d["pageLinkCol"]; }
  if ($d["pageVlinkCol"]) { $GLOBALS["pageVlinkCol"] = "#".$d["pageVlinkCol"]; }
  if ($d["pageAlinkCol"]) { $GLOBALS["pageAlinkCol"] = "#".$d["pageAlinkCol"]; }

  $GLOBALS["CSS_hover_td"] = $d["CSS_hover_td"];
  if ($d["CSS_hover_bg"]) { $GLOBALS["CSS_hover_bg"] = "#".$d["CSS_hover_bg"]; }
  $GLOBALS["CSS_hover_font_style"] = $d["CSS_hover_font_style"];
  $GLOBALS["CSS_hover_font_variant"] = $d["CSS_hover_font_variant"];
  $GLOBALS["CSS_hover_font_size"] = $d["CSS_hover_font_size"];
  $GLOBALS["CSS_hover_font_weight"] = $d["CSS_hover_font_weight"];
  $GLOBALS["CSS_hover_font_family"] = $d["CSS_hover_font_family"];

  $GLOBALS["CSS_anchor_td"] = $d["CSS_anchor_td"];
  if ($d["CSS_anchor_bg"]) { $GLOBALS["CSS_anchor_bg"] = "#".$d["CSS_anchor_bg"]; }
  $GLOBALS["CSS_anchor_font_style"] = $d["CSS_anchor_font_style"];
  $GLOBALS["CSS_anchor_font_variant"] = $d["CSS_anchor_font_variant"];
  $GLOBALS["CSS_anchor_font_size"] = $d["CSS_anchor_font_size"];
  $GLOBALS["CSS_anchor_font_weight"] = $d["CSS_anchor_font_weight"];
  $GLOBALS["CSS_anchor_font_family"] = $d["CSS_anchor_font_family"];

  $GLOBALS["CSS_active_td"] = $d["CSS_active_td"];
  if ($d["CSS_active_bg"]) { $GLOBALS["CSS_active_bg"] = "#".$d["CSS_active_bg"]; }
  $GLOBALS["CSS_active_font_style"] = $d["CSS_active_font_style"];
  $GLOBALS["CSS_active_font_variant"] = $d["CSS_active_font_variant"];
  $GLOBALS["CSS_active_font_size"] = $d["CSS_active_font_size"];
  $GLOBALS["CSS_active_font_weight"] = $d["CSS_active_font_weight"];
  $GLOBALS["CSS_active_font_family"] = $d["CSS_active_font_family"];

  $GLOBALS["CSS_visited_td"] = $d["CSS_visited_td"];
  if ($d["CSS_visited_bg"]) { $GLOBALS["CSS_visited_bg"] = "#".$d["CSS_visited_bg"]; }
  $GLOBALS["CSS_visited_font_style"] = $d["CSS_visited_font_style"];
  $GLOBALS["CSS_visited_font_variant"] = $d["CSS_visited_font_variant"];
  $GLOBALS["CSS_visited_font_size"] = $d["CSS_visited_font_size"];
  $GLOBALS["CSS_visited_font_weight"] = $d["CSS_visited_font_weight"];
  $GLOBALS["CSS_visited_font_family"] = $d["CSS_visited_font_family"];
 }
}

function checkDefaults() {
 if ($GLOBALS["adminuser"] == "") { die("Ack! The Administrator username is not set!"); }
 elseif ((substr_count($GLOBALS["adminuser"],"\"") > 0) || (substr_count($GLOBALS["adminuser"],"'") > 0) || (substr_count($GLOBALS["adminuser"],":") > 0)) {
  die("Ack! You cannot have singlequotes (') doublequotes (\"), or colons (:) in your usernames!");
 }
 $r = qDB("SELECT id FROM ".$GLOBALS["themetable"]);
 if (mysql_num_rows($r) == 0) {
  $q = "INSERT INTO ".$GLOBALS["themetable"]." VALUES (1,'Default','".$GLOBALS["adminuser"]."','','','FFC0C0','C0FFC0','FFFFCC',";
  $q .= " '202020','000060','006000','000000','000000','000000','808080','F0F0F0','F0F0F0','880000','000040','FFFFFF','A0A0A0'";
  $q .= " ,'A0A0A0','990000',-2,'Verdana, Arial, Helvetica, sans-serif','overline','','','','','','','underline','','','','',''";
  $q .= " ,'','','','','','','','','','','','','','','')";

  $r = qDB($q);
 }

 $r = qDB("SELECT usergroup FROM ".$GLOBALS["usertable"]." WHERE username=\"".$GLOBALS["adminuser"]."\"");
 if (mysql_num_rows($r) == 0) {
  $q = "INSERT INTO ".$GLOBALS["usertable"]." (username, password, usergroup, created_date, themeid)";
  $q .= " VALUES ('".$GLOBALS["adminuser"]."', '".md5($GLOBALS["defaultpassword"])."', 'admin',now(),1)";
  $r = qDB($q);
 } else {
  $d = mysql_fetch_array($r);
  if ($d["usergroup"] != "admin") {
   $r = qDB("UPDATE ".$GLOBALS["usertable"]." SET usergroup=\"admin\" WHERE username=\"".$GLOBALS["adminuser"]."\"");
  }
 }
}

function showLogin($errorMsg) {

 getvars($GLOBALS["adminuser"]);

 $loginPage = 1;
 $currentPage = "STD v".$GLOBALS["STDversion"];
 require "header.php";
?>
<center>
<font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>">
<form method="post" name="login">
<input type="hidden" name="fromlogin" value="1">
<table width="99%" height="99%">
 <tr valign="center">
  <td align="center">
<?PHP if ($errorMsg > "") { ?>
<font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="+<?PHP echo ($GLOBALS["pageFontsize"]+2) ?>" color="<?PHP echo $GLOBALS["errorForeCol"] ?>">
<strong><?PHP echo $errorMsg; ?></strong>
</font>
<br><p></p>
<?PHP } ?>
<table height="450" width="604">
 <tr valign="top" height="437">
  <td align="right" colspan="2" background="images/howcani.jpg" style="border-top:thin groove;border-right:thin groove;border-left:thin groove;border-bottom:thin groove;">
   <font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>">
   Username: <input type="text" name="currentuser" size="31" maxlength="30"><br>
   Password: <input type="password" name="password" size="31" maxlength="15"><br>
   Remember Me: <input type="checkbox" name="stdRememberMe"><br>&nbsp;<br>
   <input type="submit" value="Login">
   </font>
  </td>
 </tr>
 <tr vlign="top">
  <td align="left">
    <font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>">
      <a href="signup.php">Sign up!</a>
    </font>
  </td>
  <td align="right">
   <font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"]+1 ?>">
   :: ScreamingToDo :: version <?PHP echo $GLOBALS["STDversion"] ?> ::

  </td>
 </tr>
</table>
  </td>
 </tr>
</table>
</form>
</center>
<script>
 document.login.currentuser.focus();
</script>
</body>
</html>
<?PHP }

function show_calendar($month, $year) {
global $date;

?>
<table border="0" height="1<?PHP if (!($date)) { echo "00%"; } ?>" width="1<?PHP if (!($date)) { echo "00%"; } ?>"> 
 <tr height="6<?PHP if (!($date)) { echo "0"; } ?>">
  <td colspan="7" align="center">
<?PHP

$next_month = $month+1;
$last_day = date(d, mktime(0,0,0,$next_month,0,$year));

$first_day = mktime(0,0,0,$month,1,$year);
$first_day_of_week = date(l,$firstday);

if ($date) { $font_num = $GLOBALS["pageFontsize"]+2; }
else { $font_num = $GLOBALS["pageFontsize"]+3; }

if (!($date)) { ?>
<table border="0" width="100%"><tr><td bgcolor="<?PHP echo $GLOBALS["cal_headingBackCol"] ?>" align="center">
<font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="+<?PHP echo $font_num ?>" color="<?PHP echo $GLOBALS["cal_headingForeCol"] ?>"><strong><?PHP echo date(F, $first_day)." $year" ?></strong></font>
</td></tr></table>
<?PHP } else { ?>
<form method="post" action="<?PHP echo $GLOBALS["SCRIPT_NAME"] ?>"><input type="hidden" name="month" value="<?PHP echo $month ?>"><input type="hidden" name="year" value="<?PHP echo $year ?>"><input type="submit" style="background:<?PHP echo $GLOBALS["pageBackCol"] ?>; color:<?PHP echo $GLOBALS["pageForeCol"] ?>; font-weight: bold" value="<?PHP echo date(F, $first_day)." $year" ?>"></form>
<?PHP } ?>
</td></tr>

<tr height="3<?PHP if (!($date)) { echo "0"; } ?>">
<?PHP
if ($date) { $font_num = $GLOBALS["pageFontsize"]; }
else { $font_num = $GLOBALS["pageFontsize"]+1; }

 if ($date) { $y = 1; } else { $y = 10; }

for ($x = 1; $x <= 7; $x++) {
?>
<td width="14%" bgcolor="<?PHP echo $GLOBALS["cal_daysBackCol"] ?>" align="center"><font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $font_num ?>" color="<?PHP echo $GLOBALS["cal_daysForeCol"] ?>">
 <strong><?PHP echo substr(date("l",mktime(0,0,0,10,$x,2000)),0,$y) ?></strong></font>
</td>
<?PHP
}

?>
</tr>
<?PHP if (date(w,$first_day) > 0) { ?>
 <tr height="1<?PHP if (!($date)) { echo "00"; } ?>" valign="top">
  <?PHP echo str_repeat("<td></td>",date(w,$first_day));
 } 

 $today = mktime(0,0,0,date("m"), date("d"), date("Y"));
 
 for ($x = 1; $x <= $last_day; $x++) {
  $day = mktime(0,0,0,$month,$x,$year);
  $day_of_week = date(w,$day);
  if($day_of_week == 0) { ?> <tr height="1<?PHP if (!($date)) { echo "00"; } ?>" valign="top"><?PHP echo "\n"; }
  $backCol = $GLOBALS["cal_datesBackCol"];
  $foreCol = $GLOBALS["cal_datesForeCol"];

  $tomorrow  = mktime (0, 0, 0, $month, date("d",$day)+1, $year);

  $q1 = "SELECT priority,task,id FROM ".$GLOBALS["todotable"]." WHERE owner=\"".$GLOBALS["currentuser"]."\" AND (due_date>=\"$year-$month-$x\" AND";
  $q1 .= " due_date<\"".date("Y",$tomorrow)."-".date("m",$tomorrow)."-".date("d",$tomorrow)."\")";
  $q1 .= " AND closed=\"0\" ORDER BY priority";

  $q2 = "SELECT id,task FROM ".$GLOBALS["todotable"]." WHERE owner=\"".$GLOBALS["currentuser"]."\" AND (closed_date>=\"$year-$month-$x\" AND";
  $q2 .= " closed_date<\"".date("Y",$tomorrow)."-".date("m",$tomorrow)."-".date("d",$tomorrow)."\")";
  $q2 .= " AND closed=\"1\" ORDER BY priority";

  if ($d = mysql_fetch_array($r = qDB($q1))) {
   if (($d["priority"] >= 1) && ($d["priority"] <= 3)){ $foreCol = $GLOBALS["highForeCol"]; $backCol = $GLOBALS["highBackCol"]; }
   elseif (($d["priority"] > 3) && ($d["priority"] < 8)) { $foreCol = $GLOBALS["medForeCol"]; $backCol = $GLOBALS["medBackCol"]; }
   elseif (($d["priority"] >= 8) && ($d["priority"] <= 10)) { $foreCol = $GLOBALS["lowForeCol"]; $backCol = $GLOBALS["lowBackCol"]; }
   $totaltasks = mysql_num_rows($r);
  } elseif ($d = mysql_fetch_array($r = qDB($q2))) {
   $foreCol = $GLOBALS["doneForeCol"];
   $backCol = $GLOBALS["doneBackCol"];
   $totaltasks = mysql_num_rows($r);
  } else { $totaltasks = 0; }
  if ($day == $today) {
   $foreCol = $GLOBALS["cal_todayForeCol"];
   $backCol = $GLOBALS["cal_todayBackCol"];
  }
  if ($totaltasks > 0) { $totaltasks_string = " <font size=\"".$GLOBALS["pageFontsize"]."\" color=\"$foreCol\" face=\"".$GLOBALS["pageFont"]."\">:$totaltasks:</font>"; }
 else { $totaltasks = 0; }
?><td id="bordered" bgcolor="<?PHP echo $backCol ?>">
<font color="<?PHP echo $foreCol ?>" face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $font_num ?>"><?PHP

 if ($totaltasks > "") { ?>
<?PHP if (!($GLOBALS["print"])) { ?><a href="calendar.php?date=<?PHP echo date("m",$day)."-".date("d",$day)."-".date("Y",$day) ?>"><?PHP } ?><?PHP echo $x ?></a></font>
 <?PHP if (!($date)) {
     echo $totaltasks_string ?><br>
<font color="<?PHP echo $foreCol ?>" face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo $GLOBALS["pageFontsize"] ?>">
<?PHP
  for ($z = 1; $z <= $totaltasks; $z++) {
   $task_string = substr($d["task"],0,10);
   if (strlen($d["task"]) > 10) { $task_string = $task_string."..."; }
   if (!($GLOBALS["print"])) {
     echo "<nobr><a href=\"edittask.php?editnum=".$d["id"]."\">".$task_string."</a></nobr><br>";
   } else {
     echo "<nobr>".$task_string."</nobr><br>";
   }
   if ($z == 5) { break; }
   $d = mysql_fetch_array($r);
  }
 }
?>
<?PHP } else {
 echo $x."</font>";
 } ?>
</td>
<?PHP
  if($day_of_week == 6) { echo "</tr>\n"; }
 }

?>
</table>
<?PHP } 


function showAddTask() {
?>
<center>
<form method="post" name="addtask" action="<?PHP echo $GLOBALS["REQUEST_URI"] ?>">
 <table border="0" cellpadding="0" cellspacing="0" width="1">
  <tr>
   <td align=left>
     <font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo ($GLOBALS["pageFontsize"]+1) ?>"><strong>Type:</strong></font>
<?PHP if ($multiuser) { ?>
   </td><td align=left>
   <font face="<?PHP echo $pageFont ?>" size="<?PHP echo ($GLOBALS["pageFontsize"]+1) ?>"><strong>Assigned:</strong></font>
<?PHP } ?>
   </td><td align=left>
    <font face="<?PHP echo $pageFont ?>" size="<?PHP echo ($GLOBALS["pageFontsize"]+1) ?>"><strong>Pri:</strong></font>
   </td><td align=left>
    <font face="<?PHP echo $pageFont ?>" size="<?PHP echo ($GLOBALS["pageFontsize"]+1) ?>"><strong>Category:</strong></font>
   </td><td align=left>
    <font face="<?PHP echo $pageFont ?>" size="<?PHP echo ($GLOBALS["pageFontsize"]+1) ?>"><strong>Task:</strong></font>
   </td>
  </tr>
  <tr>
   <td align=left>
<?PHP
 if ($last_todo_closed) { $last_closed = "SELECTED"; }
 else { $last_open = "SELECTED"; }
?>
    <select name=closed size=1>
     <option <?PHP echo $last_closed ?> value="1">closed
     <option <?PHP echo $last_open ?> value="0">open
    </select>
<?PHP if ($multiuser) { ?>
   </td><td align=left width="1">
   <select name="owner" size="1">
<?PHP
 $r = qDB("SELECT username FROM $usertable ORDER BY username");
 while ($d = mysql_fetch_array($r)) {
  if ($d[0] == $last_todo_owner) { $SEL = "SELECTED"; } else { $SEL = ""; }
  echo "<option $SEL value=\"".$d[0]."\">".$d[0]."\n";
 }
 echo "   </select>\n";
}
?>
   </td><td align=left width="1">
    <select name="priority" size="1">
<?PHP
  for ($x = 1; $x <= 10; $x++) {
   if ($GLOBALS["last_todo_priority"] == $x) { $SEL = "SELECTED"; } else { $SEL = ""; }
?><option <?PHP echo $SEL ?> value="<?PHP echo $x ?>"><?PHP echo $x."\n"; 
  } ?>
    </select>
    </td><td align=left width="1">
   <select name="category" size="1">
<?PHP
 $r = qDB("SELECT id,category FROM ".$GLOBALS["categorytable"]." WHERE owner=\"".$GLOBALS["currentuser"]."\" ORDER BY sort_number");
 while ($d = mysql_fetch_array($r)) {
  if ($GLOBALS["last_todo_categoryid"] == $d["id"]) { $SEL = "SELECTED"; } else { $SEL = ""; }
  echo "<option $SEL value=\"".$d["id"]."\">".$d["category"]."\n";
 }
?>
    </select>
   </td><td width="100%" colspan="3">
    <input type="text" size="60" maxlength="200" name="task">
   </td>
  </tr>
  <tr>

  <td colspan="5">
<font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo ($GLOBALS["pageFontsize"]+1) ?>"><strong>Due date:</strong></font>
   <select name="month">
    <option value="">---------
<?PHP
  $monArray = array('January','February','March','April','May','June','July','August','September','October','November','December');
  for ($x = 1; $x <= 12; $x++) {
    if ($x == $GLOBALS["last_todo_month"]) { $SEL = "SELECTED"; } else { $SEL = ""; }
    $y = $x - 1;
    echo "<option $SEL value=\"$x\">$monArray[$y]\n";
  }
?>
   </select>
-
   <select name="day">
    <option value="">--
<?PHP
  for ($x = 1; $x <= 31; $x++) {
    if ($x == $GLOBALS["last_todo_day"]) { $SEL = "SELECTED"; } else { $SEL = ""; }
    if (strlen($x) == 1) { $x_str = "0".$x; } else { $x_str = $x; }
    echo "<option $SEL value=\"$x\">$x_str\n";
  }
?>
   </select>
-
   <select name="year">
    <option value="">----
<?PHP
  for ($x = 2000; $x <= 2020; $x++) {
    if ($x == $GLOBALS["last_todo_year"]) { $SEL = "SELECTED"; } else { $SEL = ""; }
    echo "<option $SEL value=\"$x\">$x\n";
  }
?>
   </select>
<a href="javascript:set_date();"><img src="images/clock.gif" border="0"></a>
&nbsp;&nbsp;&nbsp;<font face="<?PHP echo $GLOBALS["pageFont"] ?>" size="<?PHP echo ($GLOBALS["pageFontsize"]+1) ?>"><strong>Due time:</strong></font>
   <select name="hour">
    <option value="">--
<?PHP
  for ($x = 1; $x <= 12; $x++) {
   if ($x == $GLOBALS["last_todo_hour"]) { $SEL = "SELECTED"; } else { $SEL = ""; }
   if (strlen($x) == 1) { $x_str = "0".$x; } else { $x_str = $x; }
   echo "<option $SEL value=\"$x\">$x_str\n";
  }
?>
    </select>
:
   <select name="minutes">
    <option value="">--
<?PHP
  for ($x = 0; $x <= 59; $x++) {
   if (($x == $GLOBALS["last_todo_minutes"]) && (strval($GLOBALS["last_todo_minutes"]) != "")) { $SEL = "SELECTED"; } else { $SEL = ""; }
   if (strlen($x) == 1) { $x_str = "0".$x; } else { $x_str = $x; }
   echo "<option $SEL value=\"$x\">$x_str\n";
  }
?>
    </select>
&nbsp;
   <select name="ampm">
    <option value="">--
    <option <?PHP if (strtoupper($GLOBALS["last_todo_ampm"]) == "AM") { echo "SELECTED "; } ?>value="AM">AM
    <option <?PHP if (strtoupper($GLOBALS["last_todo_ampm"]) == "PM") { echo "SELECTED "; } ?>value="PM">PM
   </select>
   <a href="javascript:set_time();"><img src="images/clock.gif" border="0"></a>
  </td>
 </tr>
  <tr>
   <td colspan="4" align="right">
    <input type="hidden" name="status" value="New">
    <input type="hidden" name="addtask" value="1">
    <input type="hidden" name="fromPage" value="<?PHP echo $GLOBALS["PHP_SELF"] ?>">
<?PHP if (!($multiuser)) { echo "<input type=\"hidden\" name=\"owner\" value=\"".$GLOBALS["currentuser"]."\">\n"; } ?>
    <input type="submit" value="+ add +">
   </td>
  </tr>
 </table>
</form>
<script>
 document.addtask.task.focus();
</script>
</center>
<?PHP } ?>
Return current item: ScreamingToDos