diff --git a/admin/editAppFamily.php b/admin/editAppFamily.php
index 5c45e60..b8f1ce6 100644
--- a/admin/editAppFamily.php
+++ b/admin/editAppFamily.php
@@ -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 "
";
- // url edit form
- echo '
";
+ // URL editor
+ echo url::outputEditor("editAppFamily.php", NULL, $oApp);
echo html_back_link(1,BASE."appview.php?iAppId=$oApp->iAppId");
}
diff --git a/admin/editAppVersion.php b/admin/editAppVersion.php
index 598794c..b33605e 100644
--- a/admin/editAppVersion.php
+++ b/admin/editAppVersion.php
@@ -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 "
\n";
- // url edit form
- echo '";
+ /* URL editor */
+ echo url::outputEditor("editAppVersion.php", $oVersion);
/* Download URL editor */
echo downloadurl::outputEditor($oVersion, "editAppVersion.php");
diff --git a/include/url.php b/include/url.php
index 65937b0..b66342e 100644
--- a/include/url.php
+++ b/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 .= "\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);
diff --git a/include/util.php b/include/util.php
index 54ff814..b3f451b 100644
--- a/include/util.php
+++ b/include/util.php
@@ -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 "{$aClean['sUrl']}: {$aClean['sUrlDesc']}
"; }
-
- 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 "{$aClean['adescription'][$i]}: {$aClean['aURL'][$i]}: {$aClean['adelete'][$i]} : {$aClean['aId'][$i]} : .{$aClean['aOldDesc'][$i]}. : {$aClean['aOldURL'][$i]}
"; }
-
- if ($aClean['adelete'][$i] == "on")
- {
- $hResult = query_parameters("DELETE FROM appData WHERE id = '?'", $aClean['aId'][$i]);
-
- if($hResult)
- {
- addmsg("Successfully deleted URL ".$aClean['aOldDesc'][$i]." (".$aClean['aOldURL'][$i].")
\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("Successfully updated ".$aClean['aOldDesc'][$i]." (".$aClean['aOldURL'][$i].")
\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);
- }
- }
}
}