Location: PHPKode > projects > Dogfood-A Complete Groupware/CRM System > dogfood/notes/notes_data.php
<?php

// notes_data.php - PHProjekt Version 3.3
// copyright  ©  2000-2002 Albrecht Guenther  hide@address.com
// www.phprojekt.com
// Author: Albrecht Guenther

// check whether the lib has been included - authentication!
if (!defined("lib_included")) { die("Please use index.php!"); }

include_once("lib/permission.inc.php");

// delete note
function delete_note($in_id) {
	global $DB, $sql_session;
	if(!$in_id) return;
	// check persmission
	check_permission("notes","von",$in_id);
	// delete record in db
	$result=$sql_session->query("delete from ".$DB['current'].".notes where note_id = '$in_id'");
	free_values();
}

// insert new record
function insert_note() {
  global $DB, $dbIDnull, $title, $user_ID, $remark, $contact, $dbTSnull, $projekt, $ext, $persons, $profile, $clientname;
  if (!$title) { die("<br> $forum_text1"); }
   // add slashes for the text fields
  // insert record into db
  $result = db_query("INSERT INTO ".$DB['current'].".notes values($dbIDnull,'$user_ID','$title','$remark','$contact','$ext',".time().",".time().",'$projekt', '$clientname')");
}

// update existing record
function update_note() {
  global $DB, $ID, $title, $remark, $dbTSnull, $contact, $projekt, $ext, $persons, $profile, $mail, $copy, $clientname;
  // oncly check permission if the access to this note is personal (means: no group_ID is stored)
  if (!$ext) { check_permission("notes","von",$ID); }

  // add slashes for the text fields
  $result = db_query("UPDATE ".$DB['current'].".notes set name='$title',remark='$remark',div2='$dbTSnull',contact='$contact',projekt='$projekt',ext='$ext',client='$clientname' where ID='$ID'");

  // mail note to another user
  if ($mail) mail_note();
  // copy to another user
  if ($copy) copy_note();

  free_values();
}

// mail note to another user
function mail_note() {
  global $DB, $ID, $pers_ID, $user_name, $user_email;
  $result = db_query("select * from ".$DB['current'].".notes where ID = '$ID'");
  $row = db_fetch_row($result);
  $result2 = db_query("select email from ".$DB['core'].".users where ID = '$pers_ID'");
  $row2 = db_fetch_row($result2);
  if ($row2[0] <> "") { mail($row2[0], "$o_notes from $user_name: $row[2]", $row[3], "From:$user_email \nReply-To:$user_email"); }
  free_values();
}

// copy a note from you to another user
function copy_note() {
  global $DB, $dbIDnull, $title, $user_name, $remark, $contact, $dbTSnull, $projekt, $pers_ID, $ext, $persons, $profile;
  $result = db_query("INSERT INTO ".$DB['current'].".notes values($dbIDnull,'$pers_ID','[$user_name] $title','$remark','$contact','$ext','$dbTSnull','$dbTSnull','$projekt')");
  free_values();
}

// free record identification so the values won't be displayed again
function free_values() {
  global $DB, $ID, $title, $contact, $projekt, $remark;
  $ID = 0; $title = ""; $remark = ""; $contact = ""; $projekt = "";
}


// main selection
if ($action == "delete")
	delete_note($note_id);
elseif (!$note_id)
	insert_note();
else update_note();

if($_GET['mode']) $_GET['mode']="";

if($note_id) $note_id=0;
include_once("notes/notes_view.php");

?>
Return current item: Dogfood-A Complete Groupware/CRM System