- new note class

- improved performances (much less duplicated mysql queries)
- less code and better error handling
- fix various bugs
This commit is contained in:
Jonathan Ernst
2005-02-02 02:43:08 +00:00
committed by WineHQ
parent 039fba9a6a
commit 892349536c
3 changed files with 49 additions and 120 deletions

View File

@@ -7,9 +7,16 @@ include("path.php");
require(BASE."include/incl.php"); require(BASE."include/incl.php");
require(BASE."include/application.php"); require(BASE."include/application.php");
require(BASE."include/mail.php"); require(BASE."include/mail.php");
require(BASE."include/note.php");
//FIXME: get rid of appId references everywhere, as version is enough.
$sQuery = "SELECT appId FROM appVersion WHERE versionId = '".$_REQUEST['versionId']."'";
$hResult = query_appdb($sQuery);
$oRow = mysql_fetch_object($hResult);
$appId = $oRow->appId;
//check for admin privs //check for admin privs
if(!$_SESSION['current']->isLoggedIn() || (!$_SESSION['current']->hasPriv("admin") && !$_SESSION['current']->isMaintainer($_REQUEST['appId'],$_REQUEST['versionId'])) ) if(!$_SESSION['current']->isLoggedIn() || (!$_SESSION['current']->hasPriv("admin") && !$_SESSION['current']->isMaintainer($appId,$_REQUEST['versionId'])) )
{ {
errorpage("Insufficient Privileges!"); errorpage("Insufficient Privileges!");
exit; exit;
@@ -18,63 +25,33 @@ if(!$_SESSION['current']->isLoggedIn() || (!$_SESSION['current']->hasPriv("admin
//set link for version //set link for version
if(is_numeric($_REQUEST['versionId']) and !empty($_REQUEST['versionId'])) if(is_numeric($_REQUEST['versionId']) and !empty($_REQUEST['versionId']))
{ {
$versionLink = "&versionId={$_REQUEST['versionId']}"; $versionLink = "versionId={$_REQUEST['versionId']}";
} }
else else
exit; exit;
if(!is_numeric($_REQUEST['appId']))
{
errorpage('Wrong ID');
exit;
}
if($_REQUEST['sub'] == "Submit") if($_REQUEST['sub'] == "Submit")
{ {
$oNote = new Note();
$aInsert = compile_insert_string(array( 'noteTitle' =>$_REQUEST['noteTitle'], $oNote->create($_REQUEST['noteTitle'], $_REQUEST['noteDesc'], $_REQUEST['versionId']);
'NoteDesc' => $_REQUEST['noteDesc'], redirect(apidb_fullurl("appview.php?".$versionLink));
'appId' => $_REQUEST['appId'],
'versionId' => $_REQUEST['versionId'] ));
if (query_appdb("INSERT INTO `appNotes` ({$aInsert['FIELDS']}) VALUES ({$aInsert['VALUES']})"))
{
// successful
$sEmail = get_notify_email_address_list($_REQUEST['appId'], $_REQUEST['versionId']);
if($sEmail)
{
$sFullAppName = "Application: ".lookupAppName($_REQUEST['appId']);
$sFullAppName .= " Version: ".lookupVersionName($_REQUEST['appId'], $_REQUEST['versionId']);
$sMsg = APPDB_ROOT."appview.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']."\r\n";
$sMsg .= "\r\n";
$sMsg .= $_SESSION['current']->sRealname." added note to ".$sFullAppName."\r\n";
$sMsg .= "\r\n";
$sMsg .= "title: ".$_REQUEST['noteTitle']."\r\n";
$sMsg .= "\r\n";
$sMsg .= $_REQUEST['noteDesc']."\r\n";
mail_appdb($sEmail, $sFullAppName ,$sMsg);
}
$statusMessage = "<p>Note added into the database</p>\n";
addmsg($statusMessage,Green);
}
redirect(apidb_fullurl("appview.php?appId=".$_REQUEST['appId'].$versionLink));
exit; exit;
} }
else if($_REQUEST['sub'] == 'Preview' OR empty($_REQUEST['submit'])) else if($_REQUEST['sub'] == 'Preview' OR empty($_REQUEST['submit']))
{ {
?>
<link rel="stylesheet" href="./application.css" type="text/css">
<!-- load HTMLArea -->
<script type="text/javascript" src="../htmlarea/htmlarea_loader.js"></script>
<?php
apidb_header("Add Application Note"); apidb_header("Add Application Note");
echo "<form method=post action='addAppNote.php'>\n"; echo "<form method=post action='addAppNote.php'>\n";
echo html_frame_start("Add Application Note {$_REQUEST['appId']}", "90%","",0); 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 html_table_begin("width='100%' border=0 align=left cellpadding=6 cellspacing=0 class='box-body'");
echo "<input type=hidden name='appId' value='{$_REQUEST['appId']}'>"; echo "<input type=\"hidden\" name=\"versionId\" value=\"{$_REQUEST['versionId']}\">";
echo "<input type=hidden name='versionId' value='{$_REQUEST['versionId']}'>";
echo '<tr><td colspan=2 class=color4>';
echo '<center><b>You can use html to make your Warning, Howto or Note look better.</b></center>';
echo '</td></tr>',"\n";
echo add_br($_REQUEST['noteDesc']); echo add_br($_REQUEST['noteDesc']);
if ($_REQUEST['noteTitle'] == "HOWTO" || $_REQUEST['noteTitle'] == "WARNING") if ($_REQUEST['noteTitle'] == "HOWTO" || $_REQUEST['noteTitle'] == "WARNING")
@@ -86,17 +63,18 @@ else if($_REQUEST['sub'] == 'Preview' OR empty($_REQUEST['submit']))
{ {
echo "<tr><td class=color1>Title</td><td class=color0><input size='80%' type='text' name='noteTitle' type='text' value='{$_REQUEST['noteTitle']}'></td></tr>\n"; echo "<tr><td class=color1>Title</td><td class=color0><input size='80%' type='text' name='noteTitle' type='text' value='{$_REQUEST['noteTitle']}'></td></tr>\n";
} }
echo '<tr><td class=color4>Description</td><td class=color0>', "\n"; echo '<tr><td class="color4">Description</td><td class="color0">', "\n";
echo '<textarea cols=50 rows=10 name="noteDesc">'.stripslashes($_REQUEST['noteDesc']).'</textarea></td></tr>',"\n"; if(trim(strip_tags($_REQUEST['noteDesc']))=="") $_REQUEST['noteDesc']="<p>Enter note here</p>";
echo '<p style="width:700px">', "\n";
echo '<tr><td colspan=2 align=center class=color3>',"\n"; echo '<textarea cols="80" rows="20" id="editor" name="noteDesc">'.stripslashes($_REQUEST['noteDesc']).'</textarea>',"\n";
echo '<input type="submit" name=sub value="Preview">&nbsp',"\n"; echo '</p>';
echo '<input type="submit" name=sub value="Submit"></td></tr>',"\n"; 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_table_end();
echo html_frame_end(); echo html_frame_end();
echo html_back_link(1,BASE."appview.php?appId={$_REQUEST['appId']}$versionLink"); echo html_back_link(1,BASE."appview.php?".$versionLink);
apidb_footer(); apidb_footer();
} }
?> ?>

View File

@@ -7,6 +7,7 @@ include("path.php");
require(BASE."include/incl.php"); require(BASE."include/incl.php");
require(BASE."include/application.php"); require(BASE."include/application.php");
require(BASE."include/mail.php"); require(BASE."include/mail.php");
require(BASE."include/note.php");
if(!is_numeric($_REQUEST['noteId'])) if(!is_numeric($_REQUEST['noteId']))
{ {
@@ -15,12 +16,10 @@ if(!is_numeric($_REQUEST['noteId']))
} }
/* Get note data */ /* Get note data */
$sQuery = "SELECT * from appNotes where noteId = {$_REQUEST['noteId']}"; $oNote = new Note($_REQUEST['noteId']);
$hResult = query_appdb($sQuery);
$ob = mysql_fetch_object($hResult);
/* Check for privs */ /* Check for privs */
if(!$_SESSION['current']->isLoggedIn() || (!$_SESSION['current']->hasPriv("admin") && !$_SESSION['current']->isMaintainer($ob->appId,$ob->versionId)) ) if(!$_SESSION['current']->isLoggedIn() || (!$_SESSION['current']->hasPriv("admin") && !$_SESSION['current']->isMaintainer($oNote->iAppId,$oNote->iVersionId)) )
{ {
errorpage("Insufficient Privileges!"); errorpage("Insufficient Privileges!");
exit; exit;
@@ -28,86 +27,39 @@ if(!$_SESSION['current']->isLoggedIn() || (!$_SESSION['current']->hasPriv("admin
if(isset($_REQUEST['sub'])) if(isset($_REQUEST['sub']))
{ {
$sOldNoteTitle = $ob->noteTitle;
$sOldNoteDesc = $ob->noteDesc;
$sFullAppName = "Application: ".lookupAppName($ob->appId)." Version: ".lookupVersionName($ob->appId, $ob->versionId);
/* Start of e-mail */
$sMsg = APPDB_ROOT."appview.php?appId={$ob->appId}&versionId={$ob->versionId}\r\n";
$sMsg .= "\r\n";
$sEmail = get_notify_email_address_list($ob->appId, $ob->versionId);
if ($_REQUEST['sub'] == 'Delete') if ($_REQUEST['sub'] == 'Delete')
{ {
// delete Note $oNote->delete();
query_appdb("DELETE from `appNotes` where noteId = {$_REQUEST['noteId']}");
if($sEmail)
{
$sMsg .= $_SESSION['current']->sRealname." deleted note from ".$sFullAppName."\r\n";
$sMsg .= "\r\n";
$sMsg .= "title: ".$sOldNoteTitle."\r\n";
$sMsg .= "\r\n";
$sMsg .= $sOldNoteDesc."\r\n";
$sMsg .= "\r\n";
mail_appdb($sEmail, $sFullAppName ,$sMsg);
}
// success
addmsg("Note Deleted.", "green");
} }
else if ($_REQUEST['sub'] == 'Update') else if ($_REQUEST['sub'] == 'Update')
{ {
$sUpdate = compile_update_string(array( 'noteTitle' => $_REQUEST['noteTitle'], $oNote->update($_REQUEST['noteTitle'],$_REQUEST['noteDesc']);
'noteDesc' => $_REQUEST['noteDesc']));
query_appdb("UPDATE appNotes SET $sUpdate WHERE noteId = {$_REQUEST['noteId']}");
if($sEmail)
{
$sMsg .= $_SESSION['current']->sRealname." changed note for ".$sFullAppName."\r\n";
$sMsg .= "From --------------------------\r\n";
$sMsg .= "title: ".$sOldNoteTitle."\r\n";
$sMsg .= "\r\n";
$sMsg .= $sOldNoteDesc."\r\n";
$sMsg .= "To --------------------------\r\n";
$sMsg .= "title: ".$_REQUEST['noteTitle']."\r\n";
$sMsg .= "\r\n";
$sMsg .= $_REQUEST['noteDesc']."\r\n";
$sMsg .= "\r\n";
mail_appdb($sEmail, $sFullAppName ,$sMsg);
} }
addmsg("Note Updated", "green"); redirect(apidb_fullurl("appview.php?versionId={$oNote->iVersionId}"));
}
redirect(apidb_fullurl("appview.php?appId={$ob->appId}&versionId={$ob->versionId}"));
} }
else else
{ {
if (!isset($_REQUEST['preview'])) if (!isset($_REQUEST['preview']))
{ {
$_REQUEST['noteTitle'] = $ob->noteTitle; $_REQUEST['noteTitle'] = $oNote->sTitle;
$_REQUEST['noteDesc'] = $ob->noteDesc; $_REQUEST['noteDesc'] = $oNote->sDescription;
$_REQUEST['appId'] = $ob->appId; $_REQUEST['appId'] = $oNote->iAppId;
$_REQUEST['versionId'] = $ob->versionId; $_REQUEST['versionId'] = $oNote->iVersionId;
} }
?>
<link rel="stylesheet" href="./application.css" type="text/css">
<!-- load HTMLArea -->
<script type="text/javascript" src="../htmlarea/htmlarea_loader.js"></script>
<?php
// show form // show form
apidb_header("Edit Application Note"); apidb_header("Edit Application Note");
echo "<form method=post action='editAppNote.php'>\n"; echo "<form method=post action='editAppNote.php'>\n";
echo html_frame_start("Edit Application Note {$_REQUEST['noteId']}", "90%","",0); echo html_frame_start("Edit Application Note {$_REQUEST['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'");
echo '<tr><td colspan=2 class=color4>';
echo '<center><b>You can use html to make your Warning, Howto or Note look better.</b></center>';
echo '</td></tr>',"\n";
echo add_br($_REQUEST['noteDesc']); echo add_br($_REQUEST['noteDesc']);
echo '<input type=hidden name="noteId" value='.$_REQUEST['noteId'].'>'; echo '<input type="hidden" name="noteId" value='.$_REQUEST['noteId'].'>';
if ($_REQUEST['noteTitle'] == "HOWTO" || $_REQUEST['noteTitle'] == "WARNING") if ($_REQUEST['noteTitle'] == "HOWTO" || $_REQUEST['noteTitle'] == "WARNING")
{ {
@@ -119,8 +71,10 @@ else
echo '<tr><td class=color1>Title</td><td class=color0><input size=80% type="text" name="noteTitle" type="text" value="'.$_REQUEST['noteTitle'].'"></td></tr>',"\n"; echo '<tr><td class=color1>Title</td><td class=color0><input size=80% type="text" name="noteTitle" type="text" value="'.$_REQUEST['noteTitle'].'"></td></tr>',"\n";
} }
echo '<tr><td class=color4>Description</td><td class=color0>', "\n"; echo '<tr><td class=color4>Description</td><td class=color0>', "\n";
echo '<textarea cols=50 rows=10 name="noteDesc">'.stripslashes($_REQUEST['noteDesc']).'</textarea></td></tr>',"\n"; echo '<p style="width:700px">', "\n";
echo '<tr><td colspan=2 align=center class=color3>',"\n"; echo '<textarea cols="80" rows="20" id="editor" name="noteDesc">'.stripslashes($_REQUEST['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=preview value="Preview">&nbsp',"\n";
echo '<input type="submit" name=sub value="Update">&nbsp',"\n"; echo '<input type="submit" name=sub value="Update">&nbsp',"\n";
echo '<input type="submit" name=sub value="Delete"></td></tr>',"\n"; echo '<input type="submit" name=sub value="Delete"></td></tr>',"\n";
@@ -128,10 +82,8 @@ else
echo html_table_end(); echo html_table_end();
echo html_frame_end(); echo html_frame_end();
echo html_back_link(); echo html_back_link(1,BASE."appview.php?versionId=".$oNote->iVersionId);
} }
apidb_footer(); apidb_footer();
?> ?>

View File

@@ -208,7 +208,6 @@ create table appNotes (
noteId int not null auto_increment, noteId int not null auto_increment,
noteTitle varchar(255), noteTitle varchar(255),
noteDesc text, noteDesc text,
appId int not null,
versionId int not null, versionId int not null,
key(noteId) key(noteId)
); );