2005-02-03 01:27:31 +00:00
< ? php
/************************************/
/* note class and related functions */
/************************************/
/**
* Note class for handling notes
*/
class Note {
var $iNoteId ;
var $iAppId ;
var $iVersionId ;
var $sTitle ;
var $sDescription ;
/**
* Constructor .
* If $iNoteId is provided , fetches note .
*/
function Note ( $iNoteId = " " )
{
if ( $iNoteId )
{
$sQuery = " SELECT appNotes.*, appVersion.appId AS appId
FROM appNotes , appVersion
WHERE appNotes . versionId = appVersion . versionId
AND noteId = '".$iNoteId."' " ;
$hResult = query_appdb ( $sQuery );
$oRow = mysql_fetch_object ( $hResult );
$this -> iNoteId = $oRow -> noteId ;
$this -> iAppId = $oRow -> appId ;
$this -> iVersionId = $oRow -> versionId ;
$this -> sTitle = $oRow -> noteTitle ;
$this -> sDescription = $oRow -> noteDesc ;
}
}
/*
* Creates a new note .
* Informs interested people about the creation .
* Returns true on success , false on failure
*/
function create ( $sTitle , $sDescription , $iVersionId )
{
$aInsert = compile_insert_string ( array ( 'versionId' => $iVersionId ,
'noteTitle' => $sTitle ,
'noteDesc' => $sDescription ));
$sFields = " ( { $aInsert [ 'FIELDS' ] } ) " ;
$sValues = " ( { $aInsert [ 'VALUES' ] } ) " ;
if ( query_appdb ( " INSERT INTO appNotes $sFields VALUES $sValues " , " Error while creating a new note. " ))
{
$this -> note ( mysql_insert_id ());
2005-05-27 23:53:26 +00:00
$sWhatChanged = " Description is: \n " . $sDescription . " . \n \n " ;
2005-09-30 01:55:51 +00:00
$this -> SendNotificationMail ( " add " , $sWhatChanged );
2005-02-03 01:27:31 +00:00
return true ;
}
else
return false ;
}
/**
* Update note .
* Returns true on success and false on failure .
*/
function update ( $sTitle = null , $sDescription = null , $iVersionId = null )
{
2005-02-09 23:50:27 +00:00
$sWhatChanged = " " ;
if ( $sTitle && $sTitle != $this -> sTitle )
2005-02-03 01:27:31 +00:00
{
2005-02-09 23:50:27 +00:00
$sUpdate = compile_update_string ( array ( 'noteTitle' => $sTitle ));
if ( ! query_appdb ( " UPDATE appNotes SET " . $sUpdate . " WHERE noteId = " . $this -> iNoteId ))
2005-02-03 01:27:31 +00:00
return false ;
2005-02-09 23:50:27 +00:00
$sWhatChanged .= " Title was changed from " . $this -> sTitle . " to " . $sTitle . " . \n \n " ;
2005-02-03 01:27:31 +00:00
$this -> sTitle = $sTitle ;
}
2005-02-09 23:50:27 +00:00
if ( $sDescription && $sDescription != $this -> sDescription )
2005-02-03 01:27:31 +00:00
{
2005-02-09 23:50:27 +00:00
$sUpdate = compile_update_string ( array ( 'noteDesc' => $sDescription ));
if ( ! query_appdb ( " UPDATE appNotes SET " . $sUpdate . " WHERE noteId = " . $this -> iNoteId ))
2005-02-03 01:27:31 +00:00
return false ;
2005-02-09 23:50:27 +00:00
$sWhatChanged .= " Description was changed from \n " . $this -> sDescription . " \n to \n " . $sDescription . " . \n \n " ;
2005-02-03 01:27:31 +00:00
$this -> sDescription = $sDescription ;
}
2005-02-09 23:50:27 +00:00
if ( $iVersionId && $iVersionId != $this -> iVersionId )
2005-02-03 01:27:31 +00:00
{
2005-02-09 23:50:27 +00:00
$sUpdate = compile_update_string ( array ( 'versionId' => $iVersionId ));
if ( ! query_appdb ( " UPDATE appNotes SET " . $sUpdate . " WHERE noteId = " . $this -> iNoteId ))
2005-02-03 01:27:31 +00:00
return false ;
2005-02-09 23:50:27 +00:00
$oVersionBefore = new Version ( $this -> iVersionId );
$oVersionAfter = new Version ( $iVersionId );
$sWhatChanged .= " Version was changed from " . $oVersionBefore -> sName . " to " . $oVersionAfter -> sName . " . \n \n " ;
2005-02-03 01:27:31 +00:00
$this -> iVersionId = $iVersionId ;
2005-02-09 23:50:27 +00:00
$this -> iAppId = $oVersionAfter -> iAppId ;
2005-02-03 01:27:31 +00:00
}
2005-02-09 23:50:27 +00:00
if ( $sWhatChanged )
2005-09-30 01:55:51 +00:00
$this -> SendNotificationMail ( " edit " , $sWhatChanged );
2005-02-03 01:27:31 +00:00
return true ;
}
/**
* Removes the current note from the database .
* Informs interested people about the deletion .
*/
2005-02-09 23:50:27 +00:00
function delete ( $bSilent = false )
2005-02-03 01:27:31 +00:00
{
$hResult = query_appdb ( " DELETE FROM appNotes WHERE noteId = ' " . $this -> iNoteId . " ' " );
2005-02-09 23:50:27 +00:00
if ( ! $bSilent )
2005-09-30 01:55:51 +00:00
$this -> SendNotificationMail ( " delete " );
2005-02-09 23:50:27 +00:00
}
2005-09-30 01:55:51 +00:00
function SendNotificationMail ( $sAction = " add " , $sMsg = null )
2005-02-09 23:50:27 +00:00
{
switch ( $sAction )
2005-02-03 01:27:31 +00:00
{
2005-02-09 23:50:27 +00:00
case " add " :
2005-02-25 05:04:54 +00:00
$sSubject = " Note " . $this -> sTitle . " for " . lookup_app_name ( $this -> iAppId ) . " " . lookup_version_name ( $this -> iVersionId ) . " added by " . $_SESSION [ 'current' ] -> sRealname ;
2005-05-27 23:53:26 +00:00
$sMsg .= APPDB_ROOT . " appview.php?versionId= " . $this -> iVersionId . " \n " ;
2005-02-09 23:50:27 +00:00
addmsg ( " The note was successfully added into the database. " , " green " );
break ;
case " edit " :
2005-02-25 05:04:54 +00:00
$sSubject = " Note " . $this -> sTitle . " for " . lookup_app_name ( $this -> iAppId ) . " " . lookup_version_name ( $this -> iVersionId ) . " has been modified by " . $_SESSION [ 'current' ] -> sRealname ;
2005-02-09 23:50:27 +00:00
addmsg ( " Note modified. " , " green " );
break ;
case " delete " :
2005-02-25 05:04:54 +00:00
$sSubject = " Note " . $this -> sTitle . " for " . lookup_app_name ( $this -> iAppId ) . " " . lookup_version_name ( $this -> iVersionId ) . " has been deleted by " . $_SESSION [ 'current' ] -> sRealname ;
2005-02-03 01:27:31 +00:00
$sMsg .= " This note was made on " . substr ( $this -> sDateCreated , 0 , 10 ) . " by " . $this -> oOwner -> sRealname . " \n " ;
$sMsg .= " \n " ;
2005-02-09 23:50:27 +00:00
$sMsg .= " Subject: " . $this -> sTitle . " \n " ;
2005-02-03 01:27:31 +00:00
$sMsg .= " \n " ;
$sMsg .= $this -> sBody . " \n " ;
$sMsg .= " \n " ;
$sMsg .= " Because: \n " ;
2005-02-09 23:50:27 +00:00
if ( $_REQUEST [ 'replyText' ])
$sMsg .= $_REQUEST [ 'replyText' ] . " \n " ;
2005-02-03 01:27:31 +00:00
else
$sMsg .= " No reason given. \n " ;
2005-02-09 23:50:27 +00:00
addmsg ( " Note deleted. " , " green " );
break ;
2005-02-03 01:27:31 +00:00
}
2005-02-09 23:50:27 +00:00
$sEmail = get_notify_email_address_list ( null , $this -> iVersionId );
if ( $sEmail )
mail_appdb ( $sEmail , $sSubject , $sMsg );
}
2005-02-03 01:27:31 +00:00
}
?>