Location: PHPKode > scripts > SimpleNotes > simplenotes/snote.php
<?php 

/*****************************************************************************
/* SimplyNotes
/* version 1.10 23/08/2005
/* Copyright (C) 2004 Martin Hanus
/* hide@address.com
/* License:	This code is released under GPL version 2
*****************************************************************************/

/* snote = simply note [one item] */


/* GLOBAL DEFINITIONS */

$dbhost = "mydbhost";         /* Define your database host  here */
$dbname = "simplenotes";            /* Define your database name here */
$dbuser = "user";            /* Define your database user here */
$dbpwd  = "psswd";           /* Define your database password here */
$tbl_snote = "snote_snote";        /* Name of the SQL table snote */

$ver = "v1.10";                /* project version number */


/* Set Font Size for Top 3 Level Note Names in Lines 161, 164 & 167  */

/* END OF GLOBAL DATA DEFINITIONS */


/*****************************************************************************
*  FUNCTION:  This function adds snote to the database
*****************************************************************************/

function add_snote($Name, $BriefDesc, $Hyperlink, $BigText, $LinkedTo) {
  global $dbhost, $dbname, $dbuser, $dbpwd, $tbl_snote;

  mysql_connect($dbhost,$dbuser,$dbpwd)
     or die("<br>ERROR: Unable to connect to database.<br>\n");
  $dbquery = "insert into ".$tbl_snote."  (Name, BriefDesc, Hyperlink, BigText, InputTime, LinkedTo) values ('$Name','$BriefDesc','$Hyperlink','$BigText',now(),'$LinkedTo')";
  $result = mysql_db_query($dbname,$dbquery)
     or die("<br>ERROR: Unable to add link.<br>\n");
  mysql_close();

}  /* END OF FUNCTION */


/*****************************************************************************
*  FUNCTION:  This function modifies snote in the database
*****************************************************************************/

function edit_snote($Name, $BriefDesc, $Hyperlink, $BigText, $SnoteID) {
  global $dbhost, $dbname, $dbuser, $dbpwd, $tbl_snote;

  mysql_connect($dbhost,$dbuser,$dbpwd)
     or die("<br>ERROR: Unable to connect to database.<br>\n");
  $dbquery = "update ".$tbl_snote." set Name='$Name', BriefDesc='$BriefDesc', Hyperlink='$Hyperlink', BigText='$BigText', InputTime=now() where SnoteID='$SnoteID'";
  $result = mysql_db_query($dbname,$dbquery)
     or die("<br>ERROR: Unable to add link.<br>\n");
  mysql_close();

}  /* END OF FUNCTION */

/*****************************************************************************
*  FUNCTION:  This function moves snote branch in the hiearchy
*****************************************************************************/

function move_snote($SnoteID, $LinkedTo) {
  global $dbhost, $dbname, $dbuser, $dbpwd, $tbl_snote;

  mysql_connect($dbhost,$dbuser,$dbpwd)
     or die("<br>ERROR: Unable to connect to database.<br>\n");
  $dbquery = "update ".$tbl_snote." set LinkedTo='$LinkedTo', InputTime=now() where SnoteID='$SnoteID'";
  $result = mysql_db_query($dbname,$dbquery)
     or die("<br>ERROR: Unable to edit snote.<br>\n");
  mysql_close();

}  /* END OF FUNCTION */

/*****************************************************************************
*  FUNCTION:  This function deletes snotes hiearchy from the database
*****************************************************************************/

function delete_snote($SnoteID) {
  global $dbhost, $dbname, $dbuser, $dbpwd, $tbl_snote;
  
  mysql_connect($dbhost,$dbuser,$dbpwd)
     or die("<br>ERROR: Unable to connect to database.<br>\n");
  $dbquery = "delete from ".$tbl_snote." where SnoteID='$SnoteID'";
  $result = mysql_db_query($dbname,$dbquery)
     or die("<br>ERROR: Unable to delete snote.<br>\n");
  $dbquery = "select SnoteID from ".$tbl_snote." where LinkedTo = '$SnoteID'";
  $result = mysql_db_query($dbname,$dbquery)
     or die("<br>ERROR: Unable to select snotes.<br>\n");
  while($row=mysql_fetch_array($result)){
      delete_snote($row[SnoteID]);
    };
  mysql_close();

}  /* END OF FUNCTION */


/*****************************************************************************
*  FUNCTION:  This function reduces $action space (it is used for root element only)
*****************************************************************************/

function ReduceAction($action) {
  switch ($action) {
  	case "selectnew":
  		return "new";
  		break;
  	case "movewhat":
  		return "movewhere";
  		break;
  	default:
  		return "";
  		break;
  }
}  /* END OF FUNCTION */

/*****************************************************************************
*  FUNCTION:  This function returns name of required php script for given $action
*****************************************************************************/
function httpwww($Hyperlink) {
   if(strlen($Hyperlink)>7){
	     if(!strcasecmp("http://",substr($Hyperlink,0,7))){$Hyperlink=substr($Hyperlink,7);};
      $httpwww="http://".$Hyperlink;
      $result = "<a href=".$httpwww.">".$Hyperlink."</a></td>\n";};
   return $result;
}  /* END OF FUNCTION */



/*****************************************************************************
*  FUNCTION:  This function returns name of required php script for given $action
*****************************************************************************/

function SnoteScript($action) {
  if (($action=="edit") or ($action=="new")) 
	{return "snoteform.php";} else
	{return "snoteindex.php";}
}  /* END OF FUNCTION */


/*****************************************************************************
*  FUNCTION:  This function shows hiearchical list of snotes related to actual SnoteID 
*  there is recurrent call that lists the whole structure under actual level
*****************************************************************************/

function show_snote_structure($RootID,$LinkedTo, $Level, $mode, $action, $MaxLevel, $MoveWhat) {
  global $dbhost, $dbname, $dbuser, $dbpwd, $tbl_snote;

  /* read data from the database */
  mysql_connect($dbhost,$dbuser,$dbpwd)
     or die("<br>ERROR: Unable to connect to database.<br>\n");
  $dbquery = "select * from ".$tbl_snote." where LinkedTo = '$LinkedTo' order by Name, SnoteID";
  $result = mysql_db_query($dbname,$dbquery)
     or die("<br>ERROR: Unable to select snotes.<br>\n");
  mysql_close();

  /* set font size */
  switch ($Level) {
  	case 1:
  		$fontsize=title1;
  		break;
  	case 2:
  		$fontsize=title2;
  		break;
  	default:
  		$fontsize=title3;
  }  
  
  /* output actual snote */
  echo "<table valign=top  border=0 class=description>\n";
  while($row=mysql_fetch_array($result)){
      if ($action=="") {$RootID_out = $row[SnoteID];} else {$RootID_out = $RootID;}
      echo "<tr>\n";
      for ($i = 1; $i <= $Level-1; $i++) {echo "<td></td>";}
      echo "<td><a class=$fontsize".HyperlinkToScript($RootID_out,$row[SnoteID],$mode,$action, $MaxLevel, $MoveWhat).">$row[Name]</a></td>\n";
      /* $trans je prevodni matice pro konverzi znaku, ktere nemuzou jit do databaze */
      $trans = array_flip (get_html_translation_table (HTML_ENTITIES,ENT_QUOTES));
      $original = strtr ($str, $trans);      
      $BriefDesc = strtr ($row[BriefDesc], $trans);
      $BigText = nl2br(strtr ($row[BigText], $trans));
      echo "<td>$BriefDesc</td>\n";
      echo "</tr>\n";
      /* here Details are shown */
      if ($mode == "full") {
  	if ($row["Hyperlink"]<>"") {
      	      echo "<tr>\n";
              for ($i = 1; $i <= $Level; $i++) {echo "<td></td>";}
              echo "<td>\n";
              echo httpwww($row[Hyperlink]);
              echo "</td>\n </tr>\n";
  	    }
      	  echo "<tr>\n";
          for ($i = 1; $i <= $Level; $i++) {echo "<td></td>";}
          echo "<td >\n";
         if ($BigText<>"") {
           echo "<table valign=top  border=0 class=fulltext><tr><td>\n";
           echo $BigText;
           echo "</td></tr></table>\n";}
          echo "</td>\n </tr>\n";
  	}
      if ($Level < $MaxLevel) {
      	  echo "<tr>\n";
          for ($i = 1; $i <= $Level; $i++) {echo "<td></td>";}
          echo "<td>\n";
          echo show_snote_structure($RootID,$row[SnoteID], $Level+1, $mode, $action, $MaxLevel, $MoveWhat);
          echo "</td>\n </tr>\n";
	}
    };
  echo "</table>\n";

}  /* END OF FUNCTION */

/*****************************************************************************
*  FUNCTION:  This function returns Name for given SnoteID
*****************************************************************************/

function SnoteName($SnoteID) {
  global $dbhost, $dbname, $dbuser, $dbpwd, $tbl_snote;
  
  mysql_connect($dbhost,$dbuser,$dbpwd)
     or die("<br>ERROR: Unable to connect to database.<br>\n");
  $dbquery = "select Name from ".$tbl_snote." where SnoteID='$SnoteID'";
  $result = mysql_db_query($dbname,$dbquery)
     or die("<br>ERROR: Unable to query snote.<br>\n");
  while($row=mysql_fetch_array($result)){
      $Name = $row[Name];
    };
  mysql_close();
  return $Name;

}  /* END OF FUNCTION */

/*****************************************************************************
*  FUNCTION:  This function returns BriefDesc for given SnoteID
*****************************************************************************/

function BriefDesc($SnoteID) {
  global $dbhost, $dbname, $dbuser, $dbpwd, $tbl_snote;
  
  mysql_connect($dbhost,$dbuser,$dbpwd)
     or die("<br>ERROR: Unable to connect to database.<br>\n");
  $dbquery = "select BriefDesc from ".$tbl_snote." where SnoteID='$SnoteID'";
  $result = mysql_db_query($dbname,$dbquery)
     or die("<br>ERROR: Unable to query snote.<br>\n");
  while($row=mysql_fetch_array($result)){
      $Name = $row[BriefDesc];
    };
  mysql_close();
  return $Name;

}  /* END OF FUNCTION */

/*****************************************************************************
*  FUNCTION:  This function returns Hyperlink for given SnoteID
*****************************************************************************/

function Hyperlink($SnoteID) {
  global $dbhost, $dbname, $dbuser, $dbpwd, $tbl_snote;
  
  mysql_connect($dbhost,$dbuser,$dbpwd)
     or die("<br>ERROR: Unable to connect to database.<br>\n");
  $dbquery = "select Hyperlink from ".$tbl_snote." where SnoteID='$SnoteID'";
  $result = mysql_db_query($dbname,$dbquery)
     or die("<br>ERROR: Unable to query snote.<br>\n");
  while($row=mysql_fetch_array($result)){
      $Name = $row[Hyperlink];
    };
  mysql_close();
  return $Name;

}  /* END OF FUNCTION */

/*****************************************************************************
*  FUNCTION:  This function returns BigText for given SnoteID
*****************************************************************************/

function BigText($SnoteID) {
  global $dbhost, $dbname, $dbuser, $dbpwd, $tbl_snote;
  
  mysql_connect($dbhost,$dbuser,$dbpwd)
     or die("<br>ERROR: Unable to connect to database.<br>\n");
  $dbquery = "select BigText from ".$tbl_snote." where SnoteID='$SnoteID'";
  $result = mysql_db_query($dbname,$dbquery)
     or die("<br>ERROR: Unable to query snote.<br>\n");
  while($row=mysql_fetch_array($result)){
      $Name = $row[BigText];
    };
  mysql_close();
  return $Name;

}  /* END OF FUNCTION */

/*****************************************************************************
*  FUNCTION:  This function returns hyperlink string for given parameters
*****************************************************************************/

function HyperlinkToScript($RootID, $SnoteID, $mode, $action, $MaxLevel, $MoveWhat) {
  $res = " href=";
  $res = $res . SnoteScript($action);
  $res = $res . "?RootID=$RootID&SnoteID=$SnoteID&mode=$mode&action=$action&MaxLevel=$MaxLevel&MoveWhat=$MoveWhat";
  return $res;

}  /* END OF FUNCTION */


/*****************************************************************************
*  END OF FUNCTION DEFINITIONS
*****************************************************************************/
?>

Return current item: SimpleNotes