2005-02-03 01:27:31 +00:00
< ? php
2006-06-17 06:10:10 +00:00
require_once ( BASE . " include/util.php " );
2006-09-01 02:25:18 +00:00
require_once ( BASE . " include/version.php " );
2006-06-17 06:10:10 +00:00
2005-02-03 01:27:31 +00:00
/************************************/
/* note class and related functions */
/************************************/
2009-07-28 17:48:52 +02:00
define ( 'APPNOTE_SHOW_FOR_ALL' , - 1 );
define ( 'APPNOTE_SHOW_FOR_VERSIONS' , - 2 );
define ( 'APPNOTE_SHOW_FOR_APP' , - 3 );
2009-08-06 02:02:36 +02:00
define ( 'APPNOTE_SHOW_FOR_SPECIFIC_VERSIONS' , - 4 );
2009-07-28 17:48:52 +02:00
2005-02-03 01:27:31 +00:00
/**
* Note class for handling notes
*/
class Note {
var $iNoteId ;
var $iVersionId ;
2009-07-28 17:48:52 +02:00
var $iAppId ;
2005-02-03 01:27:31 +00:00
var $sTitle ;
2007-01-06 06:21:41 +00:00
var $shDescription ;
2007-01-02 04:44:27 +00:00
var $iSubmitterId ;
var $sSubmitTime ;
2009-08-06 02:02:36 +02:00
var $iLinkedWith ;
var $aNoteLinks ;
2005-02-03 01:27:31 +00:00
/**
* Constructor .
* If $iNoteId is provided , fetches note .
*/
2007-07-30 00:27:37 +00:00
function Note ( $iNoteId = null , $oRow = null )
2005-02-03 01:27:31 +00:00
{
2009-08-06 02:02:36 +02:00
$this -> aNoteLinks = array ();
2007-07-30 00:27:37 +00:00
if ( ! $iNoteId && ! $oRow )
return ;
if ( ! $oRow )
2005-02-03 01:27:31 +00:00
{
2007-07-30 00:27:37 +00:00
$sQuery = " SELECT * FROM appNotes WHERE noteId = '?' " ;
if ( $hResult = query_parameters ( $sQuery , $iNoteId ))
2007-08-03 23:27:25 +00:00
$oRow = query_fetch_object ( $hResult );
2007-07-30 00:27:37 +00:00
}
if ( $oRow )
{
$this -> iNoteId = $oRow -> noteId ;
$this -> iVersionId = $oRow -> versionId ;
2009-07-28 17:48:52 +02:00
$this -> iAppId = $oRow -> appId ;
2007-07-30 00:27:37 +00:00
$this -> sTitle = $oRow -> noteTitle ;
$this -> shDescription = $oRow -> noteDesc ;
$this -> sSubmitTime = $oRow -> submitTime ;
$this -> iSubmitterId = $oRow -> submitterId ;
2009-08-06 02:02:36 +02:00
$this -> iLinkedWith = $oRow -> linkedWith ;
$this -> aNoteLinks = $this -> objectGetChildren ();
2005-02-03 01:27:31 +00:00
}
}
/*
* Creates a new note .
* Informs interested people about the creation .
* Returns true on success , false on failure
*/
2006-06-30 19:48:33 +00:00
function create ()
2005-02-03 01:27:31 +00:00
{
2007-07-31 23:48:22 +00:00
$hResult = query_parameters ( " INSERT INTO appNotes (versionId, " .
2009-07-28 17:48:52 +02:00
" appId, noteTitle, noteDesc, submitterId, " .
2007-07-31 23:48:22 +00:00
" submitTime) " .
2009-07-28 17:48:52 +02:00
" VALUES('?', '?', '?', '?', '?', ?) " ,
$this -> iVersionId , $this -> iAppId ,
$this -> sTitle , $this -> shDescription ,
2007-07-31 23:48:22 +00:00
$_SESSION [ 'current' ] -> iUserId ,
" NOW() " );
2005-02-03 01:27:31 +00:00
2006-06-24 04:20:32 +00:00
if ( $hResult )
2005-02-03 01:27:31 +00:00
{
2009-08-06 02:02:36 +02:00
// We need to backup the noteLinks array
$aNoteLinks = $this -> aNoteLinks ;
2007-08-03 23:27:25 +00:00
$this -> note ( query_appdb_insert_id ());
2009-08-06 02:02:36 +02:00
foreach ( $aNoteLinks as $oLink )
{
$oLink -> objectSetParent ( $this -> iNoteId , 'note' );
$this -> aNoteLinks [] = $oLink ;
}
$this -> saveNoteLinks ( true );
2007-01-06 06:21:41 +00:00
$sWhatChanged = " Description is: \n " . $this -> shDescription . " . \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
2006-06-24 04:20:32 +00:00
{
addmsg ( " Error while creating a new note. " , " red " );
2005-02-03 01:27:31 +00:00
return false ;
2006-06-24 04:20:32 +00:00
}
2005-02-03 01:27:31 +00:00
}
2008-01-23 14:18:43 +01:00
function unQueue ()
{
return true ; // We don't queue notes
}
2005-02-03 01:27:31 +00:00
/**
* Update note .
* Returns true on success and false on failure .
*/
2006-06-30 19:48:33 +00:00
function update ()
2005-02-03 01:27:31 +00:00
{
2005-02-09 23:50:27 +00:00
$sWhatChanged = " " ;
2006-06-30 19:48:33 +00:00
/* create an instance of ourselves so we can see what has changed */
$oNote = new Note ( $this -> iNoteId );
2005-02-09 23:50:27 +00:00
2006-06-30 19:48:33 +00:00
if ( $this -> sTitle && $this -> sTitle != $oNote -> sTitle )
2005-02-03 01:27:31 +00:00
{
2006-06-27 19:16:27 +00:00
if ( ! query_parameters ( " UPDATE appNotes SET noteTitle = '?' WHERE noteId = '?' " ,
2006-06-30 19:48:33 +00:00
$this -> sTitle , $this -> iNoteId ))
2005-02-03 01:27:31 +00:00
return false ;
2006-06-30 19:48:33 +00:00
$sWhatChanged .= " Title was changed from " . $oNote -> sTitle . " to " . $this -> sTitle . " . \n \n " ;
2005-02-03 01:27:31 +00:00
}
2007-01-06 06:21:41 +00:00
if ( $this -> shDescription && $this -> shDescription != $oNote -> shDescription )
2005-02-03 01:27:31 +00:00
{
2006-06-27 19:16:27 +00:00
if ( ! query_parameters ( " UPDATE appNotes SET noteDesc = '?' WHERE noteId = '?' " ,
2007-01-06 06:21:41 +00:00
$this -> shDescription , $this -> iNoteId ))
2005-02-03 01:27:31 +00:00
return false ;
2007-01-06 06:21:41 +00:00
$sWhatChanged .= " Description was changed from \n " . $oNote -> shDescription . " \n to \n " . $this -> shDescription . " . \n \n " ;
2005-02-03 01:27:31 +00:00
}
2009-08-06 02:02:36 +02:00
if ( $this -> iVersionId == APPNOTE_SHOW_FOR_SPECIFIC_VERSIONS && ( sizeof ( $this -> aNoteLinks ) == 1 ))
{
$oLink = $this -> aNoteLinks [ 0 ];
$this -> iVersionId = $oLink -> objectGetParent ( 'version' );
$this -> iAppId = 0 ;
$oLink -> delete ();
}
2009-07-29 03:10:00 +02:00
if (( $this -> iVersionId || $this -> iAppId ) && $this -> iVersionId != $oNote -> iVersionId )
2005-02-03 01:27:31 +00:00
{
2006-06-27 19:16:27 +00:00
if ( ! query_parameters ( " UPDATE appNotes SET versionId = '?' WHERE noteId = '?' " ,
2006-06-30 19:48:33 +00:00
$this -> iVersionId , $this -> iNoteId ))
2005-02-03 01:27:31 +00:00
return false ;
2009-07-29 03:10:00 +02:00
2009-07-30 00:51:52 +02:00
if ( ! $this -> iAppId && ! $oNote -> iAppId ) // Changed version only
2009-07-29 03:10:00 +02:00
{
2009-07-29 17:33:41 +02:00
$sVersionBefore = Version :: lookup_name ( $oNote -> iVersionId );
2009-07-29 03:10:00 +02:00
$sVersionAfter = Version :: lookup_name ( $this -> iVersionId );
$sWhatChanged .= " Version was changed from " . $sVersionBefore . " to " . $sVersionAfter . " . \n \n " ;
2009-07-30 00:51:52 +02:00
} else if ( ! $this -> iAppId ) // Moved from app to version
{
$sVersionAfter = Version :: fullName ( $this -> iVersionId );
$oApp = new application ( $oNote -> iAppId );
$sOldApp = $oApp -> sName ;
$sWhatChanged .= " Moved from application $sOldApp to version $sVersionAfter . \n \n " ;
} else if ( $oNote -> hasRealVersionId ()) // Moved from version to app
2009-07-29 03:10:00 +02:00
{
$oApp = new application ( $this -> iAppId );
$sNewApp = $oApp -> sName ;
2009-07-29 17:33:41 +02:00
$sVersionBefore = version :: fullName ( $oNote -> iVersionId );
$sWhatChanged .= " Moved from version $sVersionBefore to application $sNewApp . \n \n " ;
2009-07-30 00:51:52 +02:00
} else // Change display mode for app note
{
$sOldMode = $oNote -> getDisplayModeName ();
$sNewMode = $this -> getDisplayModeName ();
$sWhatChanged .= " Display mode was changed from ' $sOldMode ' to ' $sNewMode '. \n \n " ;
2009-07-29 03:10:00 +02:00
}
}
if (( $this -> iAppId || $this -> iVersionId ) && $this -> iAppId != $oNote -> iAppId )
{
if ( ! query_parameters ( " UPDATE appNotes SET appId = '?' WHERE noteId = '?' " ,
$this -> iAppId , $this -> iNoteId ))
return false ;
2005-02-03 01:27:31 +00:00
}
2009-08-06 02:02:36 +02:00
$this -> saveNoteLinks ();
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 ;
}
2007-12-12 22:43:22 +01:00
function purge ()
{
return $this -> delete ();
}
2005-02-03 01:27:31 +00:00
/**
* Removes the current note from the database .
* Informs interested people about the deletion .
2007-07-30 00:27:37 +00:00
*
* Returns : true if successful , false if not
2005-02-03 01:27:31 +00:00
*/
2007-09-14 23:02:12 -04:00
function delete ()
2005-02-03 01:27:31 +00:00
{
2006-06-27 19:16:27 +00:00
$hResult = query_parameters ( " DELETE FROM appNotes WHERE noteId = '?' " , $this -> iNoteId );
2007-07-30 00:27:37 +00:00
2007-09-14 23:02:12 -04:00
if ( ! $hResult )
return FALSE ;
return TRUE ;
2005-02-09 23:50:27 +00:00
}
2007-09-23 16:09:38 +02:00
function objectShowPreview ()
{
return TRUE ;
}
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
{
2009-07-28 17:48:52 +02:00
if ( ! $this -> iAppId )
{
$oVersion = new version ( $this -> iVersionId );
$sAppName = version :: fullName ( $this -> iVersionId );
$sMsg .= $oVersion -> objectMakeUrl () . " \n " ;
} else
{
$oApp = new application ( $this -> iAppId );
$sAppName = $oApp -> sName ;
$sMsg .= $oApp -> objectMakeUrl () . " \n " ;
}
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 " :
2007-04-08 23:04:31 +00:00
$sSubject = " Note $this->sTitle for $sAppName added by " .
$_SESSION [ 'current' ] -> sRealname ;
2005-02-09 23:50:27 +00:00
addmsg ( " The note was successfully added into the database. " , " green " );
break ;
case " edit " :
2007-04-08 23:04:31 +00:00
$sSubject = " Note $this->sTitle for $sAppName has been modified by " .
$_SESSION [ 'current' ] -> sRealname ;
2005-02-09 23:50:27 +00:00
addmsg ( " Note modified. " , " green " );
break ;
case " delete " :
2007-01-02 04:44:27 +00:00
$oSubmitter = new User ( $this -> iSubmitterId );
2007-04-08 23:04:31 +00:00
$sSubject = " Note $this->sTitle for $sAppName has been deleted by " .
$_SESSION [ 'current' ] -> sRealname ;
2007-07-31 23:48:22 +00:00
$sMsg .= " This note was made on " . print_date ( mysqldatetime_to_unixtimestamp ( $this -> sSubmitTime )) .
" by " . $oSubmitter -> sRealname . " \n " ;
2005-02-03 01:27:31 +00:00
$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 " ;
2007-01-02 04:44:27 +00:00
$sMsg .= " Note contents: \n " ;
2007-01-06 06:21:41 +00:00
$sMsg .= $this -> shDescription . " \n " ;
2005-02-03 01:27:31 +00:00
$sMsg .= " \n " ;
$sMsg .= " Because: \n " ;
2007-07-30 00:27:37 +00:00
if ( isset ( $aClean [ 'sReplyText' ]) && $aClean [ 'sReplyText' ])
2006-07-13 18:54:10 +00:00
$sMsg .= $aClean [ 'sReplyText' ] . " \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
}
2006-06-29 15:54:29 +00:00
$sEmail = User :: get_notify_email_address_list ( null , $this -> iVersionId );
2005-02-09 23:50:27 +00:00
if ( $sEmail )
mail_appdb ( $sEmail , $sSubject , $sMsg );
}
2006-06-29 19:22:26 +00:00
/* Show note */
2006-06-30 19:48:33 +00:00
/* $bDisplayOnly means we should not display any editing controls, even if */
/* the user has the ability to edit this note */
2007-09-23 16:09:38 +02:00
function display ( $aVars = null )
2006-06-29 19:22:26 +00:00
{
switch ( $this -> sTitle )
{
case 'WARNING' :
2008-02-20 13:57:35 +11:00
$sClass = 'warning' ;
2006-06-29 19:22:26 +00:00
$sTitle = 'Warning' ;
break ;
case 'HOWTO' :
2008-02-20 13:57:35 +11:00
$sClass = 'howto' ;
2006-06-29 19:22:26 +00:00
$sTitle = 'HOWTO' ;
break ;
default :
if ( ! empty ( $this -> sTitle ))
$sTitle = $this -> sTitle ;
else
$sTitle = 'Note' ;
2008-02-20 13:57:35 +11:00
$sClass = 'defaultnote' ;
2006-06-29 19:22:26 +00:00
}
2007-09-19 20:12:37 +02:00
2009-07-28 17:48:52 +02:00
if ( ! $aVars || ! getInput ( 'shReturnTo' , $aVars ))
{
$oVersion = new version ( $this -> iVersionId );
$shReturnTo = $oVersion -> objectMakeUrl ();
} else
{
$shReturnTo = $aVars [ 'shReturnTo' ];
}
2007-09-19 20:12:37 +02:00
2006-06-29 19:22:26 +00:00
$shOutput = html_frame_start ( " " , " 98% " , '' , 0 );
$shOutput .= " <table width= \" 100% \" border= \" 0 \" cellspacing= \" 0 \" > \n " ;
2008-02-21 19:59:19 +11:00
$shOutput .= " <tr class= \" " . $sClass . " \" align= \" center \" valign= \" top \" ><td> </td></tr><tr class= \" notetitle \" valign= \" top \" align= \" center \" ><td> " . $sTitle . " </td></tr> \n " ;
2006-06-29 19:22:26 +00:00
$shOutput .= " <tr><td class= \" note \" > \n " ;
2007-01-06 06:21:41 +00:00
$shOutput .= $this -> shDescription ;
2006-06-29 19:22:26 +00:00
$shOutput .= " </td></tr> \n " ;
2007-09-23 16:09:38 +02:00
if (( ! $aVars || $aVars [ 'bEditing' ] != " true " ) && $this -> canEdit ())
2006-06-29 19:22:26 +00:00
{
2007-09-23 16:09:38 +02:00
$shOutput .= " <tr class= \" color1 \" align= \" center \" valign= \" top \" ><td> " ;
2009-07-28 17:48:52 +02:00
$shOutput .= " <form method= \" post \" name= \" message \" action= \" objectManager.php?sClass=note&sAction=edit&iId= " . $this -> iNoteId . " &sReturnTo= " . urlencode ( $shReturnTo ) . " \" > " ;
2009-07-29 21:21:11 +02:00
$shOutput .= '<input type="submit" value="Edit note" class="button">' ;
2007-09-23 16:09:38 +02:00
$shOutput .= '</form></td></tr>' ;
2006-06-29 19:22:26 +00:00
}
$shOutput .= " </table> \n " ;
$shOutput .= html_frame_end ();
echo $shOutput ;
}
2006-06-30 19:48:33 +00:00
2009-07-28 17:48:52 +02:00
function displayNotesForEntry ( $iVersionId , $iAppId = null )
{
if ( $iVersionId )
{
$oVersion = new version ( $iVersionId );
$oApp = $oVersion -> objectGetParent ();
2009-07-29 17:54:18 +02:00
$hResult = query_parameters ( " SELECT noteId FROM appNotes WHERE versionId = '?' OR (appId = '?' AND (versionId = '?' OR versionId = '?')) ORDER BY versionId,noteId " , $iVersionId , $oApp -> objectGetId (), APPNOTE_SHOW_FOR_ALL , APPNOTE_SHOW_FOR_VERSIONS );
2009-07-28 17:48:52 +02:00
} else if ( $iAppId )
{
2009-07-29 17:41:20 +02:00
$hResult = query_parameters ( " SELECT noteId FROM appNotes WHERE appId = '?' AND (versionId = '?' OR versionId = '?') " , $iAppId , APPNOTE_SHOW_FOR_ALL , APPNOTE_SHOW_FOR_APP );
2009-07-28 17:48:52 +02:00
}
if ( ! $hResult )
return ;
if ( $iVersionId )
$oVersion = new version ( $iVersionId );
else
$oApp = new application ( $iAppId );
while ( $oRow = mysql_fetch_object ( $hResult ))
{
$oNote = new note ( $oRow -> noteId );
$shReturnTo = $iVersionId ? $oVersion -> objectMakeUrl () : $oApp -> objectMakeUrl ();
$aVars = array ( 'shReturnTo' => $shReturnTo , 'bEditing' => 'false' );
2009-08-06 02:02:36 +02:00
$oLink = $oNote -> getLink ();
if ( $oLink )
$oLink -> display ( $aVars );
else
$oNote -> display ( $aVars );
2009-07-28 17:48:52 +02:00
}
}
2007-09-19 20:12:37 +02:00
function objectGetCustomVars ( $sAction )
{
switch ( $sAction )
{
2007-09-23 16:09:38 +02:00
case " preview " :
return array ( " bEditing " );
2007-09-19 20:12:37 +02:00
case " add " :
2009-07-28 17:48:52 +02:00
return array ( 'iVersionId' , 'iAppId' , 'sNoteTitle' );
2006-06-30 19:48:33 +00:00
2007-09-19 20:12:37 +02:00
default :
return null ;
}
}
2009-07-29 03:10:00 +02:00
public static function isRealVersionId ( $iVersionId )
{
return $iVersionId > 0 ;
}
2009-07-29 20:47:42 +02:00
public function hasRealVersionId ()
{
return note :: isRealVersionId ( $this -> iVersionId );
}
2009-07-30 00:51:52 +02:00
public static function getDisplayModeIds ()
{
2009-08-06 02:02:36 +02:00
return array ( APPNOTE_SHOW_FOR_ALL , APPNOTE_SHOW_FOR_VERSIONS , APPNOTE_SHOW_FOR_APP , APPNOTE_SHOW_FOR_SPECIFIC_VERSIONS );
2009-07-30 00:51:52 +02:00
}
public static function getDisplayModeNames ()
{
2009-08-06 02:02:36 +02:00
return array ( 'Show on both application and version pages' , 'Show on all version pages only' , 'Show on application page only' , 'Show on the following version pages only:' );
2009-07-30 00:51:52 +02:00
}
public function getDisplayModeName ( $iModeId = null )
{
if ( ! $iModeId )
$iModeId = $this -> iVersionId ;
$aNames = note :: getDisplayModeNames ();
$iIndex = 0 ;
foreach ( note :: getDisplayModeIds () as $iId )
{
if ( $iId == $iModeId )
return $aNames [ $iIndex ];
$iIndex ++ ;
}
return '' ;
}
2009-08-06 02:02:36 +02:00
public function findLink ( $iVersionId , $bQueryDB = true )
{
if ( $bQueryDB )
{
// If we don't have a noteId we can't be linked to anything
if ( ! $this -> iNoteId )
return null ;
$hResult = query_parameters ( " SELECT * FROM appNotes WHERE linkedWith = '?' AND versionId = '?' " , $this -> iNoteId , $iVersionId );
if ( ! $hResult || ! ( $oRow = mysql_fetch_object ( $hResult )))
return null ;
return new noteLink ( null , $oRow );
}
foreach ( $this -> aNoteLinks as $oLink )
{
if ( $oLink -> objectGetParent ( 'version' ) == $iVersionId )
return $oLink ;
}
return null ;
}
public function isLinkedWith ( $iVersionId , $bQueryDB = true )
{
$oLink = $this -> findLink ( $iVersionId , $bQueryDB );
return $oLink != null ;
}
public function getNoteLinksFromInput ( $aValues )
{
2009-08-08 04:13:20 +02:00
$iAppId = $this -> iAppId ;
if ( ! $iAppId )
$iAppId = getInput ( 'iAppId' , $aValues );
$oApp = new application ( $iAppId );
2009-08-06 02:02:36 +02:00
$iCount = sizeof ( $oApp -> getVersions ());
$aLinkedVersions = html_read_input_series ( 'iVersionId' , $aValues , $iCount );
$aLinks = array ();
foreach ( $aLinkedVersions as $sLinkedVersionId )
{
if ( ! $sLinkedVersionId )
continue ;
$iLinkedVersionId = ( int ) $sLinkedVersionId ;
// See if we already have a DB entry for this link
$oExistingLink = $this -> findLink ( $iLinkedVersionId );
if ( $oExistingLink )
{
$aLinks [] = $oExistingLink ;
continue ;
}
$oLink = new noteLink ();
$oLink -> objectSetParent ( $this -> iNoteId , 'note' );
$oLink -> objectSetParent ( $iLinkedVersionId , 'version' );
$aLinks [] = $oLink ;
}
return $aLinks ;
}
public function saveNoteLinks ( $bNewNote = false )
{
foreach ( $this -> aNoteLinks as $oLink )
{
if ( $bNewNote || ! $this -> isLinkedWith ( $oLink -> objectGetParent ( 'version' )))
$oLink -> create ();
}
// Check if we should delete any links
$aDBLinks = $this -> objectGetChildren ();
if ( sizeof ( $this -> aNoteLinks ) != sizeof ( $aDBLinks ))
{
foreach ( $aDBLinks as $oDBLink )
{
$bFound = false ;
foreach ( $this -> aNoteLinks as $oLink )
{
if ( $oDBLink -> objectGetParent ( 'version' ) == $oLink -> objectGetParent ( 'version' ))
$bFound = true ;
}
if ( ! $bFound )
$oDBLink -> delete ();
}
}
}
public function getLink ()
{
if ( $this -> iLinkedWith )
return new noteLink ( $this -> iNoteId );
return null ;
}
2007-09-19 20:12:37 +02:00
function outputEditor ( $aValues = null )
2006-06-30 19:48:33 +00:00
{
2009-07-29 16:32:37 +02:00
if ( $aValues )
{
if ( ! $this -> iVersionId )
$this -> iVersionId = getInput ( 'iVersionId' , $aValues );
2007-09-19 20:12:37 +02:00
2009-07-29 16:32:37 +02:00
if ( ! $this -> iAppId )
$this -> iAppId = getInput ( 'iAppId' , $aValues );
if ( ! $this -> sTitle )
$this -> sTitle = getInput ( 'sNoteTitle' , $aValues );
}
2009-07-28 17:48:52 +02:00
2009-07-29 03:10:00 +02:00
if ( $this -> iAppId && ! $this -> iVersionId )
$this -> iVersionId = APPNOTE_SHOW_FOR_ALL ;
2009-07-28 17:48:52 +02:00
2009-07-29 03:10:00 +02:00
if ( ! $this -> iAppId )
{
$oVersion = new version ( $this -> iVersionId );
$this -> iAppId = $oVersion -> iAppId ;
2007-09-19 20:12:37 +02:00
}
2006-06-30 19:48:33 +00:00
HtmlAreaLoaderScript ( array ( " editor " ));
2007-09-19 20:12:37 +02:00
2009-07-29 16:34:02 +02:00
echo html_frame_start ( " Edit Application Note " , " 90% " , " " , 0 );
2006-06-30 19:48:33 +00:00
echo html_table_begin ( " width='100%' border=0 align=left cellpadding=6 cellspacing=0 class='box-body' " );
2008-02-23 12:06:24 +11:00
echo '<input type="hidden" name="bEditing" value="true">' ;
echo '<input type="hidden" name="iNoteId" value="' . $this -> iNoteId . '">' ;
2009-07-29 03:10:00 +02:00
2009-07-28 17:48:52 +02:00
echo '<input type="hidden" name="iAppId" value="' . $this -> iAppId . '">' ;
2006-06-30 19:48:33 +00:00
echo '<tr><td class=color1>Title</td>' . " \n " ;
echo ' <td class=color0><input size=80% type="text" name="sNoteTitle" type="text" value="' . $this -> sTitle . '"></td></tr>' , " \n " ;
echo '<tr><td class=color4>Description</td><td class=color0>' , " \n " ;
echo '<p style="width:700px">' , " \n " ;
2007-01-06 06:21:41 +00:00
echo '<textarea cols="80" rows="20" id="editor" name="shNoteDesc">' . $this -> shDescription . '</textarea>' , " \n " ;
2006-06-30 19:48:33 +00:00
echo '</p>' ;
echo '</td></tr>' . " \n " ;
2009-07-29 03:10:00 +02:00
if ( $this -> iAppId || $oApp -> canEdit ())
2009-07-28 17:48:52 +02:00
{
2009-08-06 02:02:36 +02:00
if ( $this -> hasRealVersionId ())
{
$oLink = new noteLink ();
$oLink -> objectSetParent ( $this -> iNoteId , 'note' );
$oLink -> objectSetParent ( $this -> iVersionId , 'version' );
$this -> aNoteLinks [] = $oLink ;
$oVersion = new version ( $this -> iVersionId );
$this -> iAppId = $oVersion -> iAppId ;
$this -> iVersionId = APPNOTE_SHOW_FOR_SPECIFIC_VERSIONS ;
}
2009-07-30 00:51:52 +02:00
$oApp = new application ( $this -> iAppId );
$aIds = $this -> getDisplayModeIds ();
$aOptions = $this -> getDisplayModeNames ();
echo '<tr><td class="color1">Display mode</td>' . " \n " ;
echo '<td class="color0">' . html_radiobuttons ( $aIds , $aOptions , 'iVersionId' , $this -> iVersionId );
2009-08-06 02:02:36 +02:00
/* Allow the note to be shown for certain versions only */
2009-07-29 03:10:00 +02:00
$aIds = array ();
$aOptions = array ();
2009-08-06 02:02:36 +02:00
$aSelected = array ();
2009-07-30 00:51:52 +02:00
foreach ( $oApp -> getVersions ( true ) as $oAppVersion ) // Only accepted versions
2009-07-29 03:10:00 +02:00
{
2009-07-30 00:51:52 +02:00
$aIds [] = $oAppVersion -> objectGetId ();
$aOptions [] = $oAppVersion -> objectMakeLink ();
2009-08-06 02:02:36 +02:00
$aSelected [] = $this -> isLinkedWith ( $oAppVersion -> objectGetId (), false );
2009-07-29 03:10:00 +02:00
}
2009-08-06 02:02:36 +02:00
echo html_checkboxes ( 'iVersionId' , $aIds , $aOptions , $aSelected );
2009-07-30 00:51:52 +02:00
2009-07-28 17:48:52 +02:00
echo '</td></tr>' ;
2009-07-29 03:10:00 +02:00
} else if ( ! $this -> iAppId )
{
echo '<input type="hidden" name="iVersionId" value="' . $this -> iVersionId . '">' ;
2009-07-28 17:48:52 +02:00
}
2009-07-29 03:10:00 +02:00
2006-06-30 19:48:33 +00:00
echo '<tr><td colspan="2" align="center" class="color3">' , " \n " ;
echo html_table_end ();
echo html_frame_end ();
2009-08-08 04:13:20 +02:00
}
public function checkOutputEditorInput ( $aClean )
{
$shErrors = '' ;
$iVersionId = getInput ( 'iVersionId' , $aClean );
if ( $iVersionId == APPNOTE_SHOW_FOR_SPECIFIC_VERSIONS )
{
$aNoteLinks = $this -> getNoteLinksFromInput ( $aClean );
if ( ! sizeof ( $aNoteLinks ))
$shErrors .= '<li>You need to show the note for at least one version, or choose another display mode</li>' ;
}
return $shErrors ;
2006-06-30 19:48:33 +00:00
}
2007-01-17 03:18:49 +00:00
/* retrieves values from $aValue that were output by outputEditor() */
/* $aValues can be $_REQUEST or any array with the values from outputEditor() */
2006-07-08 22:06:28 +00:00
function GetOutputEditorValues ( $aValues )
2006-06-30 19:48:33 +00:00
{
2009-07-28 17:48:52 +02:00
$this -> iVersionId = getInput ( 'iVersionId' , $aValues );
2009-07-29 03:10:00 +02:00
if ( ! $this -> isRealVersionId ( $this -> iVersionId ))
$this -> iAppId = getInput ( 'iAppId' , $aValues );
else
$this -> iAppId = 0 ;
2009-08-06 02:02:36 +02:00
if ( $this -> iVersionId == APPNOTE_SHOW_FOR_SPECIFIC_VERSIONS )
{
$this -> aNoteLinks = $this -> getNoteLinksFromInput ( $aValues );
2009-08-07 15:24:41 +02:00
// There's no need to use links if the note is only shown for one version
2009-08-06 02:02:36 +02:00
if ( sizeof ( $this -> aNoteLinks ) == 1 )
{
$oLink = $this -> aNoteLinks [ 0 ];
$this -> iVersionId = $oLink -> objectGetParent ( 'version' );
$this -> iAppId = 0 ;
2009-08-07 15:24:41 +02:00
$this -> aNoteLinks = array ();
2009-08-06 02:02:36 +02:00
}
}
2006-07-08 22:06:28 +00:00
$this -> sTitle = $aValues [ 'sNoteTitle' ];
2007-01-06 06:21:41 +00:00
$this -> shDescription = $aValues [ 'shNoteDesc' ];
2006-06-30 19:48:33 +00:00
}
2007-07-30 00:27:37 +00:00
function allowAnonymousSubmissions ()
{
return false ;
}
2008-06-26 12:07:29 -04:00
// NOTE: notes cannot be queued at this point
2007-07-30 00:27:37 +00:00
function mustBeQueued ()
{
return false ;
}
function objectGetId ()
{
return $this -> iNoteId ;
}
// TODO: we ignore $bQueued and $bRejected as notes
// do not support queuing at this point
// TODO: we have no permissions scope on retrieving entries
// as notes are typically only added to unqueued versions
2008-04-12 21:50:02 +02:00
function objectGetEntries ( $sState , $iRows = 0 , $iStart = 0 , $sOrderBy = '' , $bAscending = true )
2007-07-30 00:27:37 +00:00
{
$sQuery = " select * from appNotes " ;
$hResult = query_parameters ( $sQuery );
return $hResult ;
}
2008-01-23 15:10:49 +01:00
function objectGetEntriesCount ( $sState )
{
$sQuery = " SELECT COUNT(DISTINCT noteId) as count FROM appNotes " ;
$hResult = query_parameters ( $sQuery );
if ( ! $hResult )
return false ;
if (( $oRow = mysql_fetch_object ( $hResult )))
return $oRow -> count ;
return false ;
}
2007-07-30 00:27:37 +00:00
//TODO: not sure how to best let users view a table of notes
// since the note contents could be very long we would only
// want to show a small amount of the text. Implement this
// routine when we need it
function objectGetHeader ()
{
return null ;
}
//TODO: implement this when we implement objectGetHeader()
function objectGetTableRow ()
{
return null ;
}
function objectMakeUrl ()
{
$oManager = new objectManager ( " note " , " View Note " );
return $oManager -> makeUrl ( " view " , $this -> objectGetId ());
}
2007-09-14 23:02:12 -04:00
function objectGetSubmitterId ()
{
return $this -> iSubmitterId ;
}
function objectGetMailOptions ( $sAction , $bMailSubmitter , $bParentAction )
{
return new mailOptions ();
}
function objectGetMail ( $sAction , $bMailSubmitter , $bParentAction )
{
/* We don't do this at the moment */
return array ( null , null , null );
}
2009-07-23 01:40:25 +02:00
public function objectGetParent ( $sClass = '' )
{
2009-07-29 20:47:42 +02:00
if ( $this -> hasRealVersionId ())
2009-07-23 01:40:25 +02:00
return new version ( $this -> iVersionId );
else
return new application ( $this -> iAppId );
}
public function objectSetParent ( $iNewId , $sClass = '' )
{
2009-07-29 20:47:42 +02:00
if ( $this -> hasRealVersionId ())
2009-07-23 01:40:25 +02:00
$this -> iVersionId = $iNewId ;
else
$this -> iAppId = $iNewId ;
}
2007-12-12 22:43:22 +01:00
function objectGetChildren ( $bIncludeDeleted = false )
2007-09-08 22:29:17 +00:00
{
2009-08-06 02:02:36 +02:00
$aRet = array ();
if ( ! $this -> iAppId )
return $aRet ;
$hResult = query_parameters ( " SELECT * FROM appNotes WHERE linkedWith = '?' " , $this -> iNoteId );
if ( ! $hResult )
return $aRet ;
while ( $oRow = mysql_fetch_object ( $hResult ))
$aRet [] = new noteLink ( null , $oRow );
return $aRet ;
2007-09-08 22:29:17 +00:00
}
2007-07-30 00:27:37 +00:00
//TODO: not sure if we want to use sTitle here or what
function objectMakeLink ()
{
$sLink = " <a href= \" " . $this -> objectMakeUrl () . " \" > " .
$this -> sTitle . " </a> " ;
return $sLink ;
}
2008-01-23 14:18:43 +01:00
function objectGetState ()
{
return 'accepted' ; // We don't queue notes
}
2007-07-30 00:27:37 +00:00
// users can edit the note if they:
// - have "admin" privileges
// - maintain the version, or supermaintain the application that
// this version is under
function canEdit ()
{
if ( $_SESSION [ 'current' ] -> hasPriv ( " admin " ))
return true ;
2009-07-28 17:48:52 +02:00
else if ( $this -> iVersionId && ! $this -> iAppId )
return maintainer :: isUserMaintainer ( $_SESSION [ 'current' ], $this -> iVersionId );
else if ( $this -> iAppId )
return maintainer :: isUserSuperMaintainer ( $_SESSION [ 'current' ], $this -> iAppId );
2007-07-30 00:27:37 +00:00
return false ;
}
2005-02-03 01:27:31 +00:00
}
2009-08-06 02:02:36 +02:00
class noteLink
{
private $iLinkId ;
private $iNoteId ;
private $iVersionId ;
function noteLink ( $iLinkId = null , $oRow = null )
{
$this -> iLinkId = $iLinkId ;
if ( ! $oRow && $this -> iLinkId )
{
$hResult = query_parameters ( " SELECT * FROM appNotes WHERE noteId = '?' " , $this -> iLinkId );
if ( ! $hResult )
return ;
$oRow = mysql_fetch_object ( $hResult );
}
if ( $oRow )
{
$this -> iLinkId = $oRow -> noteId ;
$this -> iNoteId = $oRow -> linkedWith ;
$this -> iVersionId = $oRow -> versionId ;
}
}
public function create ()
{
$hResult = query_parameters ( " INSERT INTO appNotes (linkedWith,versionId) VALUES('?','?') " , $this -> iNoteId , $this -> iVersionId );
if ( ! $hResult )
return false ;
return true ;
}
public function isDuplicate ()
{
$oNote = new note ( $this -> iNoteId );
return $oNote -> isLinkedWith ( $this -> iVersionId );
}
public function update ()
{
// Query the DB so we have something to compare against
$oLink = new noteLink ( $this -> iLinkId );
if ( $this -> objectGetParent ( 'version' ) != $oLink -> objectGetParent ( 'version' ) && ! $this -> isDuplicate ())
{
$hResult = query_parameters ( " UPDATE appNotes SET versionId = '?' WHERE noteId = '?' " , $this -> iVersionId , $this -> iNoteId );
if ( ! $hResult )
return false ;
}
return true ;
}
public function delete ()
{
$hResult = query_parameters ( " DELETE FROM appNotes WHERE noteId = '?' " , $this -> iLinkId );
if ( ! $hResult )
return false ;
return true ;
}
public function objectSetParent ( $iNewId , $sClass = '' )
{
if ( ! $sClass || $sClass == 'note' )
$this -> iNoteId = $iNewId ;
else if ( $sClass == 'version' )
$this -> iVersionId = $iNewId ;
}
public function objectGetParent ( $sClass = '' )
{
if ( ! $sClass || $sClass == 'note' )
return $this -> iNoteId ;
if ( $sClass == 'version' )
return $this -> iVersionId ;
}
function display ( $aValues = null )
{
$oNote = new note ( $this -> iNoteId );
$oNote -> display ( $aValues );
}
}
2005-02-03 01:27:31 +00:00
?>