Clean up link editing code
This commit is contained in:
committed by
WineHQ
parent
4f44475b6f
commit
6a92f95a6d
@@ -18,6 +18,7 @@ if(!($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isSuperMain
|
||||
if(!empty($aClean['sSubmit']))
|
||||
{
|
||||
process_app_version_changes(false);
|
||||
url::processForm($aClean);
|
||||
util_redirect_and_exit(apidb_fullurl("appview.php?iAppId={$aClean['iAppId']}"));
|
||||
}
|
||||
else
|
||||
@@ -48,51 +49,8 @@ else
|
||||
|
||||
echo "<p>";
|
||||
|
||||
// url edit form
|
||||
echo '<form enctype="multipart/form-data" action="editAppFamily.php" method="post">',"\n";
|
||||
echo '<input type="hidden" name="iAppId" value="'.$oApp->iAppId.'" />';
|
||||
echo html_frame_start("Edit URL","90%","",0);
|
||||
echo '<table border=0 cellpadding=6 cellspacing=0 width="100%">',"\n";
|
||||
|
||||
$i = 0;
|
||||
$hResult = query_parameters("SELECT * FROM appData WHERE appId = '?' AND type = 'url' AND versionId = 0",
|
||||
$oApp->iAppId);
|
||||
if($hResult && mysql_num_rows($hResult) > 0)
|
||||
{
|
||||
echo '<tr><td class=color1><b>Delete</b></td><td class=color1>',"\n";
|
||||
echo '<b>Description</b></td><td class=color1><b>URL</b></td></tr>',"\n";
|
||||
while($oRow = mysql_fetch_object($hResult))
|
||||
{
|
||||
$temp0 = "adelete[".$i."]";
|
||||
$temp1 = "adescription[".$i."]";
|
||||
$temp2 = "aURL[".$i."]";
|
||||
$temp3 = "aId[".$i."]";
|
||||
$temp4 = "aOldDesc[".$i."]";
|
||||
$temp5 = "aOldURL[".$i."]";
|
||||
echo '<tr><td class=color3><input type="checkbox" name="'.$temp0.'"></td>',"\n";
|
||||
echo '<td class=color3><input size=45% type="text" name="'.$temp1.'" value ="'.stripslashes($oRow->description).'"</td>',"\n";
|
||||
echo '<td class=color3><input size=45% type="text" name="'.$temp2.'" value="'.$oRow->url.'"></td></tr>',"\n";
|
||||
echo '<input type="hidden" name="'.$temp3.'" value="'.$oRow->id.'" />';
|
||||
echo '<input type=hidden name="'.$temp4.'" value="'.stripslashes($oRow->description).'">';
|
||||
echo '<input type=hidden name="'.$temp5.'" value="'.$oRow->url.'">',"\n";
|
||||
$i++;
|
||||
}
|
||||
} else
|
||||
{
|
||||
echo '<tr><td class=color1></td><td class=color1><b>Description</b></td>',"\n";
|
||||
echo '<td class=color1><b>URL</b></td></tr>',"\n";
|
||||
}
|
||||
echo "</td></tr>\n";
|
||||
echo "<input type=hidden name='iRows' value='$i'>";
|
||||
|
||||
echo '<tr><td class=color1>New</td><td class=color1><input size=45% type="text" name="sUrlDesc"></td>',"\n";
|
||||
echo '<td class=color1><input size=45% name="sUrl" type="text"></td></tr>',"\n";
|
||||
|
||||
echo '<tr><td colspan=3 align=center class=color3><input type="submit" name=sSubmit value="Update URL"></td></tr>',"\n";
|
||||
|
||||
echo '</table>',"\n";
|
||||
echo html_frame_end();
|
||||
echo "</form>";
|
||||
// URL editor
|
||||
echo url::outputEditor("editAppFamily.php", NULL, $oApp);
|
||||
|
||||
echo html_back_link(1,BASE."appview.php?iAppId=$oApp->iAppId");
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ if(!empty($aClean['sSubmit']))
|
||||
{
|
||||
process_app_version_changes(true);
|
||||
downloadurl::processForm($aClean);
|
||||
url::processForm($aClean);
|
||||
util_redirect_and_exit(apidb_fullurl("appview.php?iVersionId=".$aClean['iVersionId']));
|
||||
} else /* or display the webform for making changes */
|
||||
{
|
||||
@@ -40,51 +41,8 @@ if(!empty($aClean['sSubmit']))
|
||||
|
||||
echo "<br/><br/>\n";
|
||||
|
||||
// url edit form
|
||||
echo '<form enctype="multipart/form-data" action="editAppVersion.php" method="post">',"\n";
|
||||
echo '<input type="hidden" name="iAppId" value="'.$oVersion->iAppId.'" />';
|
||||
echo '<input type="hidden" name="iVersionId" value="'.$oVersion->iVersionId.'" />';
|
||||
echo html_frame_start("Edit URL","90%","",0);
|
||||
echo '<table border=0 cellpadding=6 cellspacing=0 width="100%">',"\n";
|
||||
|
||||
$i = 0;
|
||||
$hResult = query_parameters("SELECT * FROM appData WHERE versionId = '?' AND type = 'url'",
|
||||
$oVersion->iVersionId);
|
||||
if($hResult && mysql_num_rows($hResult) > 0)
|
||||
{
|
||||
echo '<tr><td class=color1><b>Delete</b></td><td class=color1>',"\n";
|
||||
echo '<b>Description</b></td><td class=color1><b>URL</b></td></tr>',"\n";
|
||||
while($oRow = mysql_fetch_object($hResult))
|
||||
{
|
||||
$temp0 = "adelete[".$i."]";
|
||||
$temp1 = "adescription[".$i."]";
|
||||
$temp2 = "aURL[".$i."]";
|
||||
$temp3 = "aId[".$i."]";
|
||||
$temp4 = "aOldDesc[".$i."]";
|
||||
$temp5 = "aOldURL[".$i."]";
|
||||
echo '<tr><td class=color3><input type="checkbox" name="'.$temp0.'"></td>',"\n";
|
||||
echo '<td class=color3><input size="45" type="text" name="'.$temp1.'" value ="'.stripslashes($oRow->description).'"</td>',"\n";
|
||||
echo '<td class=color3><input size="45" type="text" name="'.$temp2.'" value="'.$oRow->url.'"></td></tr>',"\n";
|
||||
echo '<input type="hidden" name="'.$temp3.'" value="'.$oRow->id.'" />';
|
||||
echo '<input type="hidden" name="'.$temp4.'" value="'.stripslashes($oRow->description).'" />';
|
||||
echo '<input type="hidden" name="'.$temp5.'" value="'.$oRow->url.'" />',"\n";
|
||||
$i++;
|
||||
}
|
||||
} else
|
||||
{
|
||||
echo '<tr><td class="color1"></td><td class="color1"><b>Description</b></td>',"\n";
|
||||
echo '<td class=color1><b>URL</b></td></tr>',"\n";
|
||||
}
|
||||
echo "</td></tr>\n";
|
||||
echo "<input type=hidden name='iRows' value='$i'>";
|
||||
echo '<tr><td class=color1>New</td><td class=color1><input size="45" type="text" name="sUrlDesc"></td>',"\n";
|
||||
echo '<td class=color1><input size=45% name="sUrl" type="text"></td></tr>',"\n";
|
||||
|
||||
echo '<tr><td colspan=3 align=center class="color3"><input type="submit" name="sSubmit" value="Update URL"></td></tr>',"\n";
|
||||
|
||||
echo '</table>',"\n";
|
||||
echo html_frame_end();
|
||||
echo "</form>";
|
||||
/* URL editor */
|
||||
echo url::outputEditor("editAppVersion.php", $oVersion);
|
||||
|
||||
/* Download URL editor */
|
||||
echo downloadurl::outputEditor($oVersion, "editAppVersion.php");
|
||||
|
||||
190
include/url.php
190
include/url.php
@@ -247,6 +247,196 @@ class Url {
|
||||
mail_appdb($sEmail, $sSubject ,$sMsg);
|
||||
}
|
||||
|
||||
/* Output an editor for URL fields */
|
||||
function outputEditor($sFormAction, $oVersion, $oApp = NULL)
|
||||
{
|
||||
/* Check for correct permissions */
|
||||
if(($oVersion && !url::canEdit($oVersion->iVersionId)) ||
|
||||
($oApp && !url::canEdit(NULL, $oApp->iAppId)))
|
||||
return FALSE;
|
||||
|
||||
if($oVersion)
|
||||
$hResult = appData::getData($oVersion->iVersionId, "url");
|
||||
else
|
||||
$hResult = appData::getData($oApp->iAppId, "url", FALSE);
|
||||
|
||||
$sReturn .= html_frame_start("URLs", "90%", "", 0);
|
||||
$sReturn .= "<form method=\"post\" action=\"$sFormAction\">\n";
|
||||
$sReturn .= html_table_begin("width=100%");
|
||||
$sReturn .= html_tr(array(
|
||||
array("<b>Remove</b>", "width=\"90\""),
|
||||
"<b>Description</b>",
|
||||
"<b>URL</b>"
|
||||
),
|
||||
"color0");
|
||||
|
||||
$sReturn .= html_tr(array(
|
||||
" ",
|
||||
"<input type=\"text\" size=\"45\" name=\"".
|
||||
"sDescriptionNew\" />",
|
||||
"<input type=\"text\" size=\"45\" name=\"sUrlNew\" />"),
|
||||
"color4");
|
||||
|
||||
if($hResult)
|
||||
{
|
||||
for($i = 1; $oRow = mysql_fetch_object($hResult); $i++)
|
||||
{
|
||||
$sReturn .= html_tr(array(
|
||||
"<input type=\"checkbox\" name=\"bRemove$oRow->id\" ".
|
||||
"value=\"true\" />",
|
||||
"<input type=\"text\" size=\"45\" name=\"".
|
||||
"sDescription$oRow->id\" value=\"$oRow->description\" />",
|
||||
"<input type=\"text\" size=\"45\" name=\"sUrl$oRow->id\" ".
|
||||
"value=\"$oRow->url\" />"),
|
||||
($i % 2) ? "color0" : "color4");
|
||||
}
|
||||
}
|
||||
|
||||
if($oVersion)
|
||||
$iAppId = $oVersion->iAppId;
|
||||
else
|
||||
$iAppId = $oApp->iAppId;
|
||||
|
||||
$sReturn .= html_table_end();
|
||||
$sReturn .= "<div align=\"center\"><input type=\"submit\" value=\"".
|
||||
"Update URLs\" name=\"sSubmit\" /></div>\n";
|
||||
|
||||
if($oVersion)
|
||||
$sReturn .=" <input type=\"hidden\" name=\"iVersionId\" ".
|
||||
"value=\"$oVersion->iVersionId\" />\n";
|
||||
|
||||
$sReturn .= "<input type=\"hidden\" name=\"iAppId\" ".
|
||||
"value=\"$iAppId\" />\n";
|
||||
$sReturn .= "</form>\n";
|
||||
$sReturn .= html_frame_end(" ");
|
||||
|
||||
return $sReturn;
|
||||
}
|
||||
|
||||
/* Process data from a URL form */
|
||||
function ProcessForm($aValues)
|
||||
{
|
||||
|
||||
/* Check that we are processing a Download URL form */
|
||||
if($aValues["sSubmit"] != "Update URLs")
|
||||
return FALSE;
|
||||
|
||||
/* Check permissions */
|
||||
if(($aValues['iVersionId'] && !url::canEdit($aValues["iVersionId"])) ||
|
||||
(!$aValues['iVersionId'] && !url::canEdit(NULL, $aValues['iAppId'])))
|
||||
return FALSE;
|
||||
|
||||
if($aValues["iVersionId"])
|
||||
{
|
||||
if(!($hResult = query_parameters("SELECT COUNT(*) as num FROM appData
|
||||
WHERE TYPE = '?' AND versionId = '?'",
|
||||
"url", $aValues["iVersionId"])))
|
||||
return FALSE;
|
||||
} else
|
||||
{
|
||||
if(!($hResult = query_parameters("SELECT COUNT(*) as num FROM appData
|
||||
WHERE TYPE = '?' AND appId = '?'",
|
||||
"url", $aValues["iAppId"])))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(!($oRow = mysql_fetch_object($hResult)))
|
||||
return FALSE;
|
||||
|
||||
$num = $oRow->num;
|
||||
|
||||
/* Update URLs. Nothing to do if none are present in the database */
|
||||
if($num)
|
||||
{
|
||||
if($aValues['iVersionId'])
|
||||
{
|
||||
if(!$hResult = appData::getData($aValues["iVersionId"], "url"))
|
||||
return FALSE;
|
||||
} else
|
||||
{
|
||||
if(!$hResult = appData::getData($aValues['iAppId'], "url", FALSE))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
while($oRow = mysql_fetch_object($hResult))
|
||||
{
|
||||
$url = new url($oRow->id);
|
||||
|
||||
/* Remove URL */
|
||||
if($aValues["bRemove$oRow->id"])
|
||||
{
|
||||
if(!$url->delete(TRUE))
|
||||
return FALSE;
|
||||
|
||||
$sWhatChangedRemove .= "Removed\nURL: $oRow->url\n".
|
||||
"Description: $oRow->description\n\n";
|
||||
}
|
||||
|
||||
/* Change description/URL */
|
||||
if(($aValues["sDescription$oRow->id"] != $oRow->description or
|
||||
$aValues["sUrl$oRow->id"] != $oRow->url) &&
|
||||
$aValues["sDescription$oRow->id"] && $aValues["sUrl$oRow->id"])
|
||||
{
|
||||
if(!$url->update($aValues["sDescription$oRow->id"],
|
||||
$aValues["sUrl$oRow->id"], $aValues["iVersionId"],
|
||||
$aValues["iVersionId"] ? 0 : $aValues["iAppId"], TRUE))
|
||||
return FALSE;
|
||||
|
||||
$sWhatChangedModify .= "Modified\nOld URL: $oRow->url\nOld ".
|
||||
"Description: $oRow->description\nNew URL: ".
|
||||
$aValues["sUrl$oRow->id"]."\nNew Description: ".
|
||||
$aValues["sDescription$oRow->id"]."\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert new URL */
|
||||
if($aValues["sDescriptionNew"] && $aValues["sUrlNew"])
|
||||
{
|
||||
$url = new Url();
|
||||
|
||||
if(!$url->create($aValues["sDescriptionNew"], $aValues["sUrlNew"],
|
||||
$aValues["iVersionId"] ? $aValues["iVersionId"] : "0",
|
||||
$aValues["iVersionId"] ? "0" : $aValues["iAppId"], TRUE))
|
||||
return FALSE;
|
||||
|
||||
$sWhatChanged = "Added\nURL: ".$aValues["sUrlNew"]."\nDescription: ".
|
||||
$aValues["sDescriptionNew"]."\n\n";
|
||||
}
|
||||
|
||||
$sWhatChanged .= "$sWhatChangedRemove$sWhatChangedModify";
|
||||
|
||||
if($aValues["iVersionId"])
|
||||
$sEmail = User::get_notify_email_address_list($aValues['iVersionId']);
|
||||
else
|
||||
$sEmail = User::get_notify_email_address_list($aValues['iAppId'])
|
||||
;
|
||||
if($sWhatChanged && $sEmail)
|
||||
{
|
||||
$oApp = new Application($aValues["iAppId"]);
|
||||
|
||||
if($aValues["iVersionId"])
|
||||
{
|
||||
$oVersion = new Version($aValues["iVersionId"]);
|
||||
$sVersionName = " $oVersion->sName";
|
||||
}
|
||||
|
||||
$sSubject = "Links for $oApp->sName$sVersionName updated by ".
|
||||
$_SESSION['current']->sRealname;
|
||||
|
||||
$sMsg = $aValues["iVersionId"] ?
|
||||
APPDB_ROOT."appview.php?iVersionId=".$aValues['iVersionId'] :
|
||||
APPDB_ROOT."appview.php?iAppId=".$avalues["iAppid"];
|
||||
$sMsg .= "\n\n";
|
||||
$sMsg .= "The following changed were made\n\n";
|
||||
$sMsg .= "$sWhatChanged\n\n";
|
||||
|
||||
mail_appdb($sEmail, $sSubject, $sMsg);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function canEdit($iVersionId, $iAppId = NULL)
|
||||
{
|
||||
$oUser = new User($_SESSION['current']->iUserId);
|
||||
|
||||
@@ -571,100 +571,6 @@ function process_app_version_changes($bIsVersion)
|
||||
{
|
||||
$oApp->GetOutputEditorValues($aClean);
|
||||
$oApp->update();
|
||||
} else if($aClean['sSubmit'] == "Update URL")
|
||||
{
|
||||
$sWhatChanged = "";
|
||||
$bAppChanged = false;
|
||||
|
||||
if (!empty($aClean['sUrlDesc']) && !empty($aClean['sUrl']) )
|
||||
{
|
||||
// process added URL
|
||||
if($_SESSION['current']->showDebuggingInfos()) { echo "<p align=center><b>{$aClean['sUrl']}:</b> {$aClean['sUrlDesc']} </p>"; }
|
||||
|
||||
if($bIsVersion)
|
||||
{
|
||||
$hResult = query_parameters("INSERT INTO appData (versionId, type, description, url) ".
|
||||
"VALUES ('?', '?', '?', '?')",
|
||||
$aClean['iVersionId'], "url", $aClean['sUrlDesc'],
|
||||
$aClean['sUrl']);
|
||||
} else
|
||||
{
|
||||
$hResult = query_parameters("INSERT INTO appData (appId, type, description, url) ".
|
||||
"VALUES ('?', '?', '?', '?')",
|
||||
$aClean['iAppId'], "url", $aClean['sUrlDesc'],
|
||||
$aClean['sUrl']);
|
||||
|
||||
}
|
||||
|
||||
if ($hResult)
|
||||
{
|
||||
addmsg("The URL was successfully added into the database", "green");
|
||||
$sWhatChanged .= " Added Url: Description: ".stripslashes($aClean['sUrlDesc'])."\n";
|
||||
$sWhatChanged .= " Url: ".stripslashes($aClean['sUrl'])."\n";
|
||||
$bAppChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Process changed URLs
|
||||
for($i = 0; $i < $aClean['iRows']; $i++)
|
||||
{
|
||||
if($_SESSION['current']->showDebuggingInfos()) { echo "<p align=center><b>{$aClean['adescription'][$i]}:</b> {$aClean['aURL'][$i]}: {$aClean['adelete'][$i]} : {$aClean['aId'][$i]} : .{$aClean['aOldDesc'][$i]}. : {$aClean['aOldURL'][$i]}</p>"; }
|
||||
|
||||
if ($aClean['adelete'][$i] == "on")
|
||||
{
|
||||
$hResult = query_parameters("DELETE FROM appData WHERE id = '?'", $aClean['aId'][$i]);
|
||||
|
||||
if($hResult)
|
||||
{
|
||||
addmsg("<p><b>Successfully deleted URL ".$aClean['aOldDesc'][$i]." (".$aClean['aOldURL'][$i].")</b></p>\n",'green');
|
||||
$sWhatChanged .= "Deleted Url: Description: ".stripslashes($aClean['aOldDesc'][$i])."\n";
|
||||
$sWhatChanged .= " url: ".stripslashes($aClean['aOldURL'][$i])."\n";
|
||||
$bAppChanged = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if( $aClean['aURL'][$i] != $aClean['aOldURL'][$i] || $aClean['adescription'][$i] != $aClean['aOldDesc'][$i])
|
||||
{
|
||||
if(empty($aClean['aURL'][$i]) || empty($aClean['adescription'][$i]))
|
||||
addmsg("The URL or description was blank. URL not changed in the database", "red");
|
||||
else
|
||||
{
|
||||
if (query_parameters("UPDATE appData SET description = '?', url = '?' WHERE id = '?'",
|
||||
$aClean['adescription'][$i], $aClean['aURL'][$i],
|
||||
$aClean['aId'][$i]))
|
||||
{
|
||||
addmsg("<p><b>Successfully updated ".$aClean['aOldDesc'][$i]." (".$aClean['aOldURL'][$i].")</b></p>\n",'green');
|
||||
$sWhatChanged .= "Changed Url: Old Description: ".stripslashes($aClean['aOldDesc'][$i])."\n";
|
||||
$sWhatChanged .= " Old Url: ".stripslashes($aClean['aOldURL'][$i])."\n";
|
||||
$sWhatChanged .= " New Description: ".stripslashes($aClean['adescription'][$i])."\n";
|
||||
$sWhatChanged .= " New url: ".stripslashes($aClean['aURL'][$i])."\n";
|
||||
$bAppChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($bAppChanged)
|
||||
{
|
||||
$sEmail = User::get_notify_email_address_list($aClean['iAppId']);
|
||||
$oApp = new Application($aClean['iAppId']);
|
||||
if($sEmail)
|
||||
{
|
||||
if($bIsVersion)
|
||||
$sSubject = "Links for ".$oApp->sName." ".$oVersion->sName." have been updated by ".$_SESSION['current']->sRealname;
|
||||
else
|
||||
$sSubject = "Links for ".$oApp->sName." have been updated by ".$_SESSION['current']->sRealname;
|
||||
|
||||
$sMsg = APPDB_ROOT."appview.php?iAppId=".$aClean['iAppId']."\n";
|
||||
$sMsg .= "\n";
|
||||
$sMsg .= "The following changes have been made:";
|
||||
$sMsg .= "\n";
|
||||
$sMsg .= $sWhatChanged."\n";
|
||||
$sMsg .= "\n";
|
||||
|
||||
mail_appdb($sEmail, $sSubject ,$sMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user