Cleanup note editing. Improve previewing of notes during addition and editing. Rename note related

variables to have the proper prefix.
This commit is contained in:
Chris Morgan
2006-06-30 19:48:33 +00:00
committed by WineHQ
parent c4caf6c85f
commit 91b44a3733
4 changed files with 139 additions and 123 deletions

View File

@@ -10,76 +10,61 @@ require(BASE."include/mail.php");
$aClean = array(); //array of filtered user input
$aClean['versionId'] = makeSafe($_REQUEST['versionId']);
$aClean['appId'] = makeSafe( $_REQUEST['appId']);
$aClean['sub'] = makeSafe($_REQUEST['sub']);
$aClean['submit'] = makeSafe($_REQUEST['submit']);
$aClean['noteTitle'] = makeSafe($_REQUEST['noteTitle']);
$aClean['noteDesc'] = makeSafe($_REQUEST['noteDesc']);
$aClean['iVersionId'] = makeSafe($_REQUEST['iVersionId']);
$aClean['iAppId'] = makeSafe( $_REQUEST['iAppId']);
$aClean['sSub'] = makeSafe($_REQUEST['sSub']);
$aClean['sSubmit'] = makeSafe($_REQUEST['sSubmit']);
//FIXME: get rid of appId references everywhere, as version is enough.
$sQuery = "SELECT appId FROM appVersion WHERE versionId = '?'";
$hResult = query_parameters($sQuery, $aClean['versionId']);
$hResult = query_parameters($sQuery, $aClean['iVersionId']);
$oRow = mysql_fetch_object($hResult);
$appId = $oRow->appId;
//check for admin privs
if(!$_SESSION['current']->hasPriv("admin") && !$_SESSION['current']->isMaintainer($aClean['versionId']) && !$_SESSION['current']->isSuperMaintainer($aClean['appId']))
if(!$_SESSION['current']->hasPriv("admin") &&
!$_SESSION['current']->isMaintainer($aClean['iVersionId']) &&
!$_SESSION['current']->isSuperMaintainer($aClean['iAppId']))
{
util_show_error_page("Insufficient Privileges!");
exit;
}
//set link for version
if(is_numeric($aClean['versionId']) and !empty($aClean['versionId']))
if(is_numeric($aClean['iVersionId']) and !empty($aClean['iVersionId']))
{
$versionLink = "versionId={$aClean['versionId']}";
$sVersionLink = "versionId={$aClean['iVersionId']}";
}
else
exit;
$oNote = new Note();
$oNote->GetOutputEditorValues();
if($aClean['sub'] == "Submit")
if($aClean['sSub'] == "Submit")
{
$oNote = new Note();
$oNote->create($aClean['noteTitle'], $aClean['noteDesc'], $aClean['versionId']);
redirect(apidb_fullurl("appview.php?".$versionLink));
$oNote->create();
redirect(apidb_fullurl("appview.php?".$sVersionLink));
exit;
}
else if($aClean['sub'] == 'Preview' OR empty($aClean['submit']))
else if($aClean['sSub'] == 'Preview' OR empty($aClean['sSubmit']))
{
HtmlAreaLoaderScript(array("editor"));
apidb_header("Add Application Note");
// show form
apidb_header("Application Note");
if($aClean['sSub'] == 'Preview')
$oNote->show(true);
echo "<form method=post action='addAppNote.php'>\n";
echo html_frame_start("Add Application Note", "90%","",0);
echo html_table_begin("width='100%' border=0 align=left cellpadding=6 cellspacing=0 class='box-body'");
echo "<input type=\"hidden\" name=\"versionId\" value=\"{$aClean['versionId']}\">";
echo add_br($aClean['noteDesc']);
$oNote->OutputEditor();
if ($aClean['noteTitle'] == "HOWTO" || $aClean['noteTitle'] == "WARNING")
{
echo "<input type=hidden name='noteTitle' value='{$aClean['noteTitle']}'>";
echo "<tr><td class=color1>Type</td><td class=color0>{$aClean['noteTitle']}</td></tr>\n";
}
else
{
echo "<tr><td class=color1>Title</td><td class=color0><input size='80%' type='text' name='noteTitle' type='text' value='{$aClean['noteTitle']}'></td></tr>\n";
}
echo '<tr><td class="color4">Description</td><td class="color0">', "\n";
if ( $aClean['noteDesc'] == "" ) $aClean['noteDesc']="<p>Enter note here</p>";
echo '<p style="width:700px">', "\n";
echo '<textarea cols="80" rows="20" id="editor" name="noteDesc">'.stripslashes($aClean['noteDesc']).'</textarea>',"\n";
echo '</p>';
echo '</td></tr><tr><td colspan="2" align="center" class="color3">',"\n";
echo '<input type="submit" name="sub" value="Preview">&nbsp',"\n";
echo '<input type="submit" name="sub" value="Submit"></td></tr>',"\n";
echo html_table_end();
echo html_frame_end();
echo '<center>';
echo '<input type="submit" name="sSub" value="Preview">&nbsp',"\n";
echo '<input type="submit" name="sSub" value="Submit"></td></tr>',"\n";
echo '</center>';
echo html_back_link(1,BASE."appview.php?".$versionLink);
echo html_back_link(1,BASE."appview.php?".$sVersionLink);
apidb_footer();
}
?>

View File

@@ -10,22 +10,19 @@ require(BASE."include/mail.php");
$aClean = array(); //array of filtered user input
$aClean['noteId'] = makeSafe($_REQUEST['noteId']);
$aClean['sub'] = makeSafe($_REQUEST['sub']);
$aClean['noteTitle'] = makeSafe($_REQUEST['noteTitle']);
$aClean['noteDesc'] = makeSafe($_REQUEST['noteDesc']);
$aClean['preview'] = makeSafe($_REQUEST['preview']);
$aClean['appId'] = makeSafe($_REQUEST['appId']);
$aClean['versionId'] = makeSafe($_REQUEST['versionId']);
$aClean['iNoteId'] = makeSafe($_REQUEST['iNoteId']);
$aClean['sSub'] = makeSafe($_REQUEST['sSub']);
$aClean['sSubmit'] = makeSafe($_REQUEST['sSubmit']);
$aClean['sPreview'] = makeSafe($_REQUEST['sPreview']);
if(!is_numeric($aClean['noteId']))
if(!is_numeric($aClean['iNoteId']))
{
util_show_error_page('Wrong note ID');
exit;
}
/* Get note data */
$oNote = new Note($aClean['noteId']);
$oNote = new Note($aClean['iNoteId']);
/* Check for privs */
if(!$_SESSION['current']->hasPriv("admin") && !$_SESSION['current']->isMaintainer($oNote->iVersionId) && !$_SESSION['current']->isSuperMaintainer($oNote->iAppId))
@@ -34,60 +31,41 @@ if(!$_SESSION['current']->hasPriv("admin") && !$_SESSION['current']->isMaintaine
exit;
}
if(!empty($aClean['sub']))
if(!empty($aClean['sSub']))
{
if ($aClean['sub'] == 'Delete')
$oNote->GetOutputEditorValues(); /* retrieve the updated values */
if ($aClean['sSub'] == 'Delete')
{
$oNote->delete();
}
else if ($aClean['sub'] == 'Update')
else if ($aClean['sSub'] == 'Update')
{
$oNote->update($aClean['noteTitle'],$aClean['noteDesc']);
$oNote->update();
}
redirect(apidb_fullurl("appview.php?versionId={$oNote->iVersionId}"));
}
else
} else /* display note */
{
if (empty($aClean['preview']))
{
$aClean['noteTitle'] = $oNote->sTitle;
$aClean['noteDesc'] = $oNote->sDescription;
$aClean['appId'] = $oNote->iAppId;
$aClean['versionId'] = $oNote->iVersionId;
}
HtmlAreaLoaderScript(array("editor"));
// show form
apidb_header("Edit Application Note");
apidb_header("Application Note");
/* if preview is set display the note for review */
if($aClean['sPreview'])
{
$oNote->GetOutputEditorValues(); /* retrieve the updated values */
$oNote->show(true);
}
echo "<form method=post action='editAppNote.php'>\n";
echo html_frame_start("Edit Application Note {$aClean['noteId']}", "90%","",0);
echo html_table_begin("width='100%' border=0 align=left cellpadding=6 cellspacing=0 class='box-body'");
echo add_br($aClean['noteDesc']);
echo '<input type="hidden" name="noteId" value='.$aClean['noteId'].'>';
if ($aClean['noteTitle'] == "HOWTO" || $aClean['noteTitle'] == "WARNING")
{
echo '<tr><td class=color1>Title (Do not change)</td>';
echo '<td class=color0><input size=80% type="text" name="noteTitle" type="text" value="'.$aClean['noteTitle'].'"></td></tr>',"\n";
}
else
{
echo '<tr><td class=color1>Title</td><td class=color0><input size=80% type="text" name="noteTitle" type="text" value="'.$aClean['noteTitle'].'"></td></tr>',"\n";
}
echo '<tr><td class=color4>Description</td><td class=color0>', "\n";
echo '<p style="width:700px">', "\n";
echo '<textarea cols="80" rows="20" id="editor" name="noteDesc">'.$aClean['noteDesc'].'</textarea>',"\n";
echo '</p>';
echo '</td></tr><tr><td colspan="2" align="center" class="color3">',"\n";
echo '<input type="submit" name=preview value="Preview">&nbsp',"\n";
echo '<input type="submit" name=sub value="Update">&nbsp',"\n";
echo '<input type="submit" name=sub value="Delete"></td></tr>',"\n";
echo html_table_end();
echo html_frame_end();
/* display the editor for this note */
$oNote->OutputEditor();
echo '<center>';
echo '<input type="submit" name=sPreview value="Preview">&nbsp',"\n";
echo '<input type="submit" name=sSub value="Update">&nbsp',"\n";
echo '<input type="submit" name=sSub value="Delete"></td></tr>',"\n";
echo '</center>';
echo html_back_link(1,BASE."appview.php?versionId=".$oNote->iVersionId);
}

View File

@@ -47,16 +47,16 @@ class Note {
* Informs interested people about the creation.
* Returns true on success, false on failure
*/
function create($sTitle, $sDescription, $iVersionId)
function create()
{
$hResult = query_parameters("INSERT INTO appNotes (versionId, noteTitle, noteDesc) ".
"VALUES('?', '?', '?')",
$iVersionId, $sTitle, $sDescription);
$this->iVersionId, $this->sTitle, $this->sDescription);
if($hResult)
{
$this->note(mysql_insert_id());
$sWhatChanged = "Description is:\n".$sDescription.".\n\n";
$sWhatChanged = "Description is:\n".$this->sDescription.".\n\n";
$this->SendNotificationMail("add", $sWhatChanged);
return true;
}
@@ -72,37 +72,44 @@ class Note {
* Update note.
* Returns true on success and false on failure.
*/
function update($sTitle=null, $sDescription=null, $iVersionId=null)
function update()
{
$sWhatChanged = "";
/* create an instance of ourselves so we can see what has changed */
$oNote = new Note($this->iNoteId);
if ($sTitle && $sTitle!=$this->sTitle)
if ($this->sTitle && $this->sTitle!=$oNote->sTitle)
{
if (!query_parameters("UPDATE appNotes SET noteTitle = '?' WHERE noteId = '?'",
$sTitle, $this->iNoteId))
$this->sTitle, $this->iNoteId))
return false;
$sWhatChanged .= "Title was changed from ".$this->sTitle." to ".$sTitle.".\n\n";
$this->sTitle = $sTitle;
$sWhatChanged .= "Title was changed from ".$oNote->sTitle." to ".$this->sTitle.".\n\n";
}
if ($sDescription && $sDescription!=$this->sDescription)
if ($this->sDescription && $this->sDescription!=$oNote->sDescription)
{
if (!query_parameters("UPDATE appNotes SET noteDesc = '?' WHERE noteId = '?'",
$sDescription, $this->iNoteId))
$this->sDescription, $this->iNoteId))
return false;
$sWhatChanged .= "Description was changed from\n ".$this->sDescription."\n to \n".$sDescription.".\n\n";
$this->sDescription = $sDescription;
$sWhatChanged .= "Description was changed from\n ".$oNote->sDescription."\n to \n".$this->sDescription.".\n\n";
}
if ($iVersionId && $iVersionId!=$this->iVersionId)
if ($this->iVersionId && $this->iVersionId!=$oNote->iVersionId)
{
if (!query_parameters("UPDATE appNotes SET versionId = '?' WHERE noteId = '?'",
$iVersionId, $this->iNoteId))
$this->iVersionId, $this->iNoteId))
return false;
$oVersionBefore = new Version($this->iVersionId);
$oVersionAfter = new Version($iVersionId);
$sWhatChanged .= "Version was changed from ".$oVersionBefore->sName." to ".$oVersionAfter->sName.".\n\n";
$sVersionBefore = Version::lookup_name($oNote->iVersionId);
$sVersionAfter = Version::lookup_name($this->iVersionId);
$sWhatChanged .= "Version was changed from ".$sVersionBefore." to ".$sVersionAfter.".\n\n";
$this->iVersionId = $iVersionId;
//TODO: iAppId isn't in the appNotes table
// and we only use it for permissions checking in showNote() and in SendNotificationEmail
// we may be able to look it up on the fly if we had a more efficient way of doing so
// instead of having to construct a version object each time
$oVersionAfter = new Version($this->iVersionId);
$this->iAppId = $oVersionAfter->iAppId;
}
if($sWhatChanged)
@@ -160,7 +167,9 @@ class Note {
}
/* Show note */
function show()
/* $bDisplayOnly means we should not display any editing controls, even if */
/* the user has the ability to edit this note */
function show($bDisplayOnly = false)
{
switch($this->sTitle)
{
@@ -191,14 +200,17 @@ class Note {
$shOutput .= $this->sDescription;
$shOutput .= "</td></tr>\n";
if ($_SESSION['current']->hasPriv("admin") ||
$_SESSION['current']->isMaintainer($this->iVersionId) ||
$_SESSION['current']->isSuperMaintainer($this->iAppId))
if(!$bDisplayOnly)
{
$shOutput .= "<tr class=\"color1\" align=\"center\" valign=\"top\"><td>";
$shOutput .= "<form method=\"post\" name=\"message\" action=\"admin/editAppNote.php?noteId={$this->iNoteId}\">";
$shOutput .= '<input type="submit" value="Edit Note" class="button">';
$shOutput .= '</form></td></tr>';
if ($_SESSION['current']->hasPriv("admin") ||
$_SESSION['current']->isMaintainer($this->iVersionId) ||
$_SESSION['current']->isSuperMaintainer($this->iAppId))
{
$shOutput .= "<tr class=\"color1\" align=\"center\" valign=\"top\"><td>";
$shOutput .= "<form method=\"post\" name=\"message\" action=\"admin/editAppNote.php?iNoteId={$this->iNoteId}\">";
$shOutput .= '<input type="submit" value="Edit Note" class="button">';
$shOutput .= '</form></td></tr>';
}
}
$shOutput .= "</table>\n";
@@ -206,5 +218,46 @@ class Note {
echo $shOutput;
}
function OutputEditor()
{
HtmlAreaLoaderScript(array("editor"));
echo html_frame_start("Edit Application Note {$aClean['noteId']}", "90%","",0);
echo html_table_begin("width='100%' border=0 align=left cellpadding=6 cellspacing=0 class='box-body'");
echo '<input type="hidden" name="iNoteId" value='.$this->iNoteId.'>';
echo '<input type="hidden" name="iAppId" value='.$this->iAppId.'>';
echo '<input type="hidden" name="iVersionId" value='.$this->iVersionId.'>';
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";
echo '<textarea cols="80" rows="20" id="editor" name="sNoteDesc">'.$this->sDescription.'</textarea>',"\n";
echo '</p>';
echo '</td></tr>'."\n";
echo '<tr><td colspan="2" align="center" class="color3">',"\n";
echo html_table_end();
echo html_frame_end();
}
/* retrieves values from $_REQUEST that were output by OutputEditor() */
function GetOutputEditorValues()
{
$aClean = array(); //array of filtered user input
$aClean['iVersionId'] = makeSafe($_REQUEST['iVersionId']);
$aClean['iAppId'] = makeSafe( $_REQUEST['iAppId']);
$aClean['sNoteTitle'] = makeSafe($_REQUEST['sNoteTitle']);
$aClean['sNoteDesc'] = makeSafe($_REQUEST['sNoteDesc']);
$this->iVersionId = $aClean['iVersionId'];
$this->iAppId = $aClean['iAppId'];
$this->sTitle = $aClean['sNoteTitle'];
$this->sDescription = $aClean['sNoteDesc'];
}
}
?>

View File

@@ -773,15 +773,15 @@ class Version {
echo '<input type=submit value="Delete Version" class="button" />';
echo '</form>';
echo '<form method="post" name="message" action="admin/addAppNote.php">';
echo '<input type="hidden" name="versionId" value="'.$this->iVersionId.'" />';
echo '<input type="hidden" name="iVersionId" value="'.$this->iVersionId.'" />';
echo '<input type="submit" value="Add Note" class="button" />';
echo '</form>';
echo '<form method=post name=message action=admin/addAppNote.php?versionId='.$this->iVersionId.'>';
echo '<input type=hidden name="noteTitle" value="HOWTO" />';
echo '<form method=post name=message action=admin/addAppNote.php?iVersionId='.$this->iVersionId.'>';
echo '<input type=hidden name="sNoteTitle" value="HOWTO" />';
echo '<input type=submit value="Add How To" class="button" />';
echo '</form>';
echo '<form method=post name=message action=admin/addAppNote.php?versionId='.$this->iVersionId.'>';
echo '<input type=hidden name="noteTitle" value="WARNING" />';
echo '<form method=post name=message action=admin/addAppNote.php?iVersionId='.$this->iVersionId.'>';
echo '<input type=hidden name="sNoteTitle" value="WARNING" />';
echo '<input type=submit value="Add Warning" class="button" />';
echo '</form>';
echo "</td></tr>";