Location: PHPKode > projects > Silicon Fodder > SiliconFodder/DocumentRoot/notepad/notepad.php
<? require_once('../common/includes.php'); ?>
<? require_once('../admin/util.php'); ?>
<? require_once('../util/general.php'); ?>
<html>
<head>
<? require_once('../common/head.php'); ?>
<script type="text/javascript">
function changeOrder(field) {
	document.frm.orderBy.value = field;
	document.frm.submit();
}
function checkBoxes (form, check) {
  for (var c = 0; c < form.elements.length; c++)
    if (form.elements[c].type == 'checkbox')
      form.elements[c].checked = check;
}
function gotoPage(page) {
	document.frm.page.value = page;
	document.frm.submit();
}
</script>
</head>
<?
// set selected folder
if($HTTP_GET_VARS["folder"] != "") {
	$strSelectedFolder = $HTTP_GET_VARS["folder"];
} else {
	$strSelectedFolder = "U";
}

$strSQL = "SELECT notepad.*, notepadfolders.foldername AS strFolderName FROM notepad LEFT OUTER JOIN notepadfolders ON notepad.folderid = notepadfolders.id WHERE notepad.isDeleted=0 AND notepad.userid = ".$HTTP_SESSION_VARS["mwoid"];

if($strSelectedFolder == "U") {
	$strSQL.= " AND (notepad.folderid = 0)";
	$strFolderName = "Untitled";
} elseif($strSelectedFolder == "A") {
	$strFolderName = "All";
} else {
	$strSQL.= " AND notepad.folderid=".$strSelectedFolder;
}

if($HTTP_GET_VARS["orderBy"] != "") {
	$strSQL.= " ORDER BY ".$HTTP_GET_VARS["orderBy"];
} else {
	$strSQL.= " ORDER BY lastdate";
}

// Get starting Record Number
if($HTTP_GET_VARS["recshow"] != "") {
	$intRecShow = $HTTP_GET_VARS["recshow"];
	$HTTP_SESSION_VARS["recshow"] = $intRecShow;
} elseif($HTTP_SESSION_VARS["recshow"] != "") {
	$intRecShow  = $HTTP_SESSION_VARS["recshow"];
} else {
	$intRecShow = 10;
}

// Get the current page
if($HTTP_GET_VARS["page"] == "") {
	$currentPage = 1;
} else {
	$currentPage = $HTTP_GET_VARS["page"];
}

// Get total number of records (i.e. without limit)
$rows = gendb_query($strSQL, $myDb) or die(gendb_error());
$totalPages = ceil(gendb_num_rows($rows) / $intRecShow);
gendb_free_result($rows);

$strSQL.=" LIMIT ".($intRecShow*($currentPage-1)).", ".$intRecShow;

$rows = gendb_query($strSQL, $myDb) or die(gendb_error());
$row = gendb_fetch_assoc($rows);

if($strSelectedFolder != "U" && $strSelectedFolder != "A") {
	if($row["id"] == "") {
		$mySQL = "SELECT foldername FROM notepadfolders WHERE id=".$strSelectedFolder;
		$rows2 = gendb_query($mySQL, $myDb) or die(gendb_error());
		$row2 = gendb_fetch_assoc($rows2);
		$strFolderName = $row2["foldername"];
		gendb_free_result($rows2);
	} else {
		$strFolderName = $row["strFolderName"];
	}
}

?>
<body>
<?
$buttons = displayAddButton("addnote", "document.location.href='addnote.php?folder=".$strSelectedFolder."';");
$buttons.= "&nbsp;".displayDeleteButton("delnote", "document.frm.action='delnote.php';document.frm.submit();");
$selNum = "<select name=\"recshow\" onchange=\"javascript:document.frm.submit();\">".
$selNum.= "<option value=\"10\"".($intRecShow=="10" ? " SELECTED" : "").">10</option>";
$selNum.= "<option value=\"25\"".($intRecShow=="25" ? " SELECTED" : "").">25</option>";
$selNum.= "<option value=\"50\"".($intRecShow=="50" ? " SELECTED" : "").">50</option>";
$selNum.= "</select>";
if(isPda()) {
	pdaHeader("Notepad", "", true, $buttons);
} else {
	dispHeader("Notepad");
}
?>
<?=displayErrorMessage()?>
<form name="frm" method="get" action="notepad.php">
<input type="hidden" name="orderBy" value="<?=$HTTP_GET_VARS["orderBy"]?>">
<input type="hidden" name="folder" value="<?=$strSelectedFolder?>">
<input type="hidden" name="page">

<? if(!isPda()) { ?>
<table width="100%" cellspacing="0" cellpadding="1">
<tr>
<td>
<?=$buttons?>
</td>
<td>
<?=$selNum?>
&nbsp;Show # of records
</td>
</tr>
</table>
<hr>
<? } ?>
<table width="100%">
<tr><td>
<?
if($row["id"] != "") {
	if($totalPages != 0) {
			echo("<table width=\"100%\"><tr>");
			echo("<td>Page ".$currentPage." of ".$totalPages."</td>");
			echo("<td align=\"right\">");
			if($currentPage > 1) {
				echo("| <a href=\"javascript:gotoPage(1)\">First</a> | <a href=\"javascript:gotoPage(".($currentPage - 1).")\">Prev</a> |");
			} else {
				echo("| First | Prev |");
			}
			if($currentPage < $totalPages) {
				echo(" <a href=\"javascript:gotoPage(".($currentPage + 1).")\">Next</a> | <a href=\"javascript:gotoPage(".$totalPages.")\">Last</a> |");
			} else {
				echo("Next | Last |");
			}
			echo("</td></tr></TABLE>");
	}
}
?>
</td></tr>
<tr>
<td class="titlebar">
<?
if($strSelectedFolder == "A") echo("All");
elseif($strSelectedFolder == "U") echo("Unfiled");
else echo($strFolderName);
?>
</td>
</tr>
<tr>
<td>
<?
	if($row["id"] == "")  {
		echo("<table width=\"100%\"><tr><td align=\"center\">This folder is empty</td></tr></table>");
	} else {
?>
		<table width="100%">
		<tr>
		<th class="head" title="Select"><input name="toggleall" type="checkbox" ONCLICK="checkBoxes(this.form, this.checked)"></th>
		<th class="head" title="Order by note" onClick="changeOrder('notesort')" onMouseOver="this.style.backgroundColor='<?=getApplicationObject("HEAD_OVER_COLOUR")?>'" onMouseOut="this.style.backgroundColor='<?=getApplicationObject("HEAD_OUT_COLOUR")?>'">Note</th>
		<th class="head" title="Order by folder" onClick="changeOrder('notepadfolders.foldername')" onMouseOver="this.style.backgroundColor='<?=getApplicationObject("HEAD_OVER_COLOUR")?>'" onMouseOut="this.style.backgroundColor='<?=getApplicationObject("HEAD_OUT_COLOUR")?>'">Folder</th>
		<th class="head" title="Order by last modified" onClick="changeOrder('lastdate')" onMouseOver="this.style.backgroundColor='<?=getApplicationObject("HEAD_OVER_COLOUR")?>'" onMouseOut="this.style.backgroundColor='<?=getApplicationObject("HEAD_OUT_COLOUR")?>'">Last Modified</th>
		</tr>
		<?

		do {
			$intID = $row["id"];
			$strNote = substr($row["note"],0, 40);
			if(strpos($strNote, "\n")) {
				$strNote = substr($strNote, 0, strpos($strNote, "\n"));
			}
			$intFID = $row["folderid"];
			if(isPda()) {
				$strLD = substr($row["lastdate"], 0, 10);
			} else {
				$strLD = substr($row["lastdate"], 0, 16);
			}
			$strFN = $row["strFolderName"];

			echo("<tr>");
			echo("<td><input name=\"nC[]\" value=\"".$intID."\" type=\"checkbox\"></td><td><a href=\"editnote.php?id=".$intID."&folder=".$strSelectedFolder."\">".$strNote."</a></td>");

			if($intFID == 0) {
				echo("<td>Unfiled</td>");
			} else {
				echo("<td>".$strFN."</td>");
			}

			echo("<td>".displayRegionalDate($strLD, true)."</td>");

			echo("</tr>");
		} while ($row = gendb_fetch_assoc($rows));
		?>
		</table>
<?	} ?>
</td>
</tr>
</table>
<?=dispFooter()?>
</form>
<script language="javascript">
if(parent.notepadFolders && parent.notepadFolders.location.toString().indexOf('folders.php') <0) {
	parent.notepadFolders.location='folders.php?folder=<?=$strSelectedFolder?>&nores=1';
}
</script>
</body>
</html>
<? require_once("../common/incFinal.php"); ?>
Return current item: Silicon Fodder