Use objectManager to add and edit notes

This commit is contained in:
Alexander Nicolaysen Sørnes
2007-09-19 20:12:37 +02:00
committed by Chris Morgan
parent a6a62a2299
commit 72a250b2b0
6 changed files with 42 additions and 144 deletions

View File

@@ -1,61 +0,0 @@
<?php
/************************/
/* Add Application Note */
/************************/
require("path.php");
require(BASE."include/incl.php");
require_once(BASE."include/note.php");
//FIXME: get rid of appId references everywhere, as version is enough.
$sQuery = "SELECT appId FROM appVersion WHERE versionId = '?'";
$hResult = query_parameters($sQuery, $aClean['iVersionId']);
$oRow = query_fetch_object($hResult);
$appId = $oRow->appId;
//check for admin privs
if(!$_SESSION['current']->hasPriv("admin") &&
!$_SESSION['current']->isMaintainer($aClean['iVersionId']) &&
!$_SESSION['current']->isSuperMaintainer($aClean['iAppId']))
{
util_show_error_page_and_exit("Insufficient Privileges!");
}
//set link for version
if(is_numeric($aClean['iVersionId']) and !empty($aClean['iVersionId']))
{
$oVersion = new version($aClean['iVersionId']);
$sVersionLink = $oVersion->objectMakeUrl();
}
else
exit;
$oNote = new Note();
$oNote->GetOutputEditorValues($aClean);
if($aClean['sSub'] == "Submit")
{
$oNote->create();
util_redirect_and_exit($sVersionLink);
}
else if($aClean['sSub'] == 'Preview' OR empty($aClean['sSubmit']))
{
// show form
apidb_header("Application Note");
if($aClean['sSub'] == 'Preview')
$oNote->show(true);
echo "<form method=post action='addAppNote.php'>\n";
$oNote->outputEditor();
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,$sVersionLink);
apidb_footer();
}
?>

View File

@@ -1,61 +0,0 @@
<?php
/****************/
/* Edit AppNote */
/****************/
require("path.php");
require(BASE."include/incl.php");
require_once(BASE."include/note.php");
if(!is_numeric($aClean['iNoteId']))
util_show_error_page_and_exit('Wrong note ID');
/* Get note data */
$oNote = new Note($aClean['iNoteId']);
$oVersion = new version($oNote->iVersionId);
/* Check for privs */
if(!$oNote->canEdit())
util_show_error_page_and_exit("Insufficient Privileges!");
if(!empty($aClean['sSub']))
{
$oNote->GetOutputEditorValues($aClean); /* retrieve the updated values */
if ($aClean['sSub'] == 'Delete')
{
$oNote->delete();
}
else if ($aClean['sSub'] == 'Update')
{
$oNote->update();
}
util_redirect_and_exit($oVersion->objectMakeUrl());
} else /* display note */
{
// show form
apidb_header("Application Note");
/* if preview is set display the note for review */
if($aClean['sPreview'])
{
$oNote->GetOutputEditorValues($aClean); /* retrieve the updated values */
$oNote->display(true);
}
echo "<form method=post action='editAppNote.php'>\n";
/* 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,$oVersion->objectMakeUrl());
}
apidb_footer();
?>

View File

@@ -205,7 +205,9 @@ class Note {
$sColor = 'blue'; $sColor = 'blue';
} }
$oVersion = new version($this->iVersionId);
$shOutput = html_frame_start("","98%",'',0); $shOutput = html_frame_start("","98%",'',0);
$shOutput .= "<table width=\"100%\" border=\"0\" cellspacing=\"0\">\n"; $shOutput .= "<table width=\"100%\" border=\"0\" cellspacing=\"0\">\n";
@@ -219,7 +221,7 @@ class Note {
if ($this->canEdit()) if ($this->canEdit())
{ {
$shOutput .= "<tr class=\"color1\" align=\"center\" valign=\"top\"><td>"; $shOutput .= "<tr class=\"color1\" align=\"center\" valign=\"top\"><td>";
$shOutput .= "<form method=\"post\" name=\"message\" action=\"admin/editAppNote.php?iNoteId={$this->iNoteId}\">"; $shOutput .= "<form method=\"post\" name=\"message\" action=\"objectManager.php?sClass=note&sAction=edit&iId=".$this->iNoteId."&sReturnTo=".urlencode($oVersion->objectMakeUrl())."\">";
$shOutput .= '<input type="submit" value="Edit Note" class="button">'; $shOutput .= '<input type="submit" value="Edit Note" class="button">';
$shOutput .= '</form></td></tr>'; $shOutput .= '</form></td></tr>';
} }
@@ -231,11 +233,31 @@ class Note {
echo $shOutput; echo $shOutput;
} }
function objectGetCustomVars($sAction)
function outputEditor()
{ {
switch($sAction)
{
case "add":
return array("iVersionId","sNoteTitle");
default:
return null;
}
}
function outputEditor($aValues = null)
{
if($aValues)
{
if(!$this->iVersionId)
$this->iVersionId = $aValues['iVersionId'];
if(!$this->sTitle)
$this->sTitle = $aValues['sNoteTitle'];
}
HtmlAreaLoaderScript(array("editor")); HtmlAreaLoaderScript(array("editor"));
echo html_frame_start("Edit Application Note {$aClean['noteId']}", "90%","",0); 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 html_table_begin("width='100%' border=0 align=left cellpadding=6 cellspacing=0 class='box-body'");

View File

@@ -241,13 +241,7 @@ class ObjectManager
echo '<form name="sQform" action="'.$this->makeUrl("edit", $this->iId). echo '<form name="sQform" action="'.$this->makeUrl("edit", $this->iId).
'" method="post" enctype="multipart/form-data">',"\n"; '" method="post" enctype="multipart/form-data">',"\n";
echo '<input type="hidden" name="sClass" value="'.$this->sClass.'" />'; echo $this->makeUrlFormData();
echo '<input type="hidden" name="sTitle" value="'.$this->sTitle.'" />';
echo '<input type="hidden" name="iId" value="'.$this->iId.'" />';
echo '<input type="hidden" name="bIsQueue" '.
'value='.($this->bIsQueue ? "true" : "false").' />';
echo '<input type="hidden" name="bIsRejected" '.
'value='.($this->bIsRejected ? "true" : "false").' />';
$oObject->outputEditor(); $oObject->outputEditor();
@@ -317,6 +311,7 @@ class ObjectManager
echo '<tr valign=top><td class=color3 align=center colspan=2>',"\n"; echo '<tr valign=top><td class=color3 align=center colspan=2>',"\n";
echo '<input name="sSubmit" type="submit" value="Submit" class="button">'. echo '<input name="sSubmit" type="submit" value="Submit" class="button">'.
'&nbsp',"\n"; '&nbsp',"\n";
echo '<input name="sSubmit" type="submit" value="Delete" class="button" />'."\n";
echo "</td></tr>\n"; echo "</td></tr>\n";
} }
@@ -638,7 +633,7 @@ class ObjectManager
} }
/* Display screen for submitting a new entry of given type */ /* Display screen for submitting a new entry of given type */
function add_entry($sBackLink, $sErrors = "") function add_entry($aClean, $sErrors = "")
{ {
$this->checkMethods(array("outputEditor", "getOutputEditorValues", $this->checkMethods(array("outputEditor", "getOutputEditorValues",
"update", "create")); "update", "create"));
@@ -661,7 +656,12 @@ class ObjectManager
echo "<form method=\"post\">\n"; echo "<form method=\"post\">\n";
$oObject->outputEditor(); $aVars = $this->get_custom_vars($aClean, "add");
if($aVars)
$oObject->outputEditor($aVars);
else
$oObject->outputEditor();
echo "<input type=\"hidden\" name=\"sClass=\"distribution\" />\n"; echo "<input type=\"hidden\" name=\"sClass=\"distribution\" />\n";
echo "<input type=\"hidden\" name=\"sTitle\" value=\"$this->sTitle\" />\n"; echo "<input type=\"hidden\" name=\"sTitle\" value=\"$this->sTitle\" />\n";

View File

@@ -901,6 +901,7 @@ class version {
if ($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($this->iVersionId) || $_SESSION['current']->isSuperMaintainer($this->iAppId)) if ($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($this->iVersionId) || $_SESSION['current']->isSuperMaintainer($this->iAppId))
{ {
$shAdd = '<form method="post" name="sMessage" action="objectManager.php?sClass=note&sAction=add&iVersionId='.$this->iVersionId.'&sReturnTo='.urlencode($this->objectMakeUrl());
echo '<tr><td colspan="2" align="center">'."\n"; echo '<tr><td colspan="2" align="center">'."\n";
echo '<form method="post" name="sMessage" action="admin/editAppVersion.php">'."\n"; echo '<form method="post" name="sMessage" action="admin/editAppVersion.php">'."\n";
echo "\t".'<input type="hidden" name="iAppId" value="'.$oApp->iAppId.'" />'."\n"; echo "\t".'<input type="hidden" name="iAppId" value="'.$oApp->iAppId.'" />'."\n";
@@ -911,16 +912,13 @@ class version {
echo "<form method=\"post\" name=\"sDelete\" action=\"javascript:self.location = '".$url."'\">\n"; echo "<form method=\"post\" name=\"sDelete\" action=\"javascript:self.location = '".$url."'\">\n";
echo "\t".'<input type=submit value="Delete Version" class="button" />'."\n"; echo "\t".'<input type=submit value="Delete Version" class="button" />'."\n";
echo '</form>'."\n"; echo '</form>'."\n";
echo '<form method="post" name="message" action="admin/addAppNote.php">'."\n"; echo $shAdd.'" />';
echo "\t".'<input type="hidden" name="iVersionId" value="'.$this->iVersionId.'" />'."\n";
echo "\t".'<input type="submit" value="Add Note" class="button" />'."\n"; echo "\t".'<input type="submit" value="Add Note" class="button" />'."\n";
echo '</form>'."\n"; echo '</form>'."\n";
echo '<form method=post name=message action=admin/addAppNote.php?iVersionId='.$this->iVersionId.'>'."\n"; echo $shAdd.'&sNoteTitle=HOWTO" />';
echo "\t".'<input type=hidden name="sNoteTitle" value="HOWTO" />'."\n";
echo "\t".'<input type=submit value="Add How To" class="button" />'."\n"; echo "\t".'<input type=submit value="Add How To" class="button" />'."\n";
echo '</form>'."\n"; echo '</form>'."\n";
echo '<form method=post name=message action=admin/addAppNote.php?iVersionId='.$this->iVersionId.'>'."\n"; echo $shAdd.'&sNoteTitle=WARNING" />';
echo "\t".'<input type=hidden name="sNoteTitle" value="WARNING" />'."\n";
echo "\t".'<input type=submit value="Add Warning" class="button" />'."\n"; echo "\t".'<input type=submit value="Add Warning" class="button" />'."\n";
echo '</form>'; echo '</form>';
echo "</td></tr>"; echo "</td></tr>";

View File

@@ -91,7 +91,7 @@ if(!$sAction)
apidb_header($oObject->get_title($sAction)); apidb_header($oObject->get_title($sAction));
/* display a particular element */ /* display a particular element */
if($oObject->iId) if($oObject->iId && $sAction != "add")
{ {
switch($sAction) switch($sAction)
{ {
@@ -117,7 +117,7 @@ if($oObject->iId)
} }
} else if ($sAction == "add") } else if ($sAction == "add")
{ {
$oObject->add_entry($_SERVER['REQUEST_URI'], $sErrors); $oObject->add_entry($aClean, $sErrors);
} else } else
{ {
// if displaying a queue display the help for the given queue // if displaying a queue display the help for the given queue