2004-11-02 00:17:15 +03:00
|
|
|
<?php
|
|
|
|
//Function: process_approval(file, action)
|
|
|
|
// Reusable function for handling the approval process, file should be the DB URI and action is either approve or deny.
|
|
|
|
// Returns true on success, false on failure.
|
|
|
|
|
|
|
|
function process_approval($type, $file, $action) {
|
|
|
|
global $connection, $sitehostname, $ftpurl, $repositorypath;
|
|
|
|
if ($action=="approve") {
|
|
|
|
$action_comment = "Approval+";
|
2004-12-13 04:09:37 +03:00
|
|
|
$action_email = "Approval Granted";
|
2004-11-02 00:17:15 +03:00
|
|
|
$approved = "YES";
|
|
|
|
} else if ($action=="deny") {
|
|
|
|
$action_comment = "Approval-";
|
2004-12-13 04:09:37 +03:00
|
|
|
$action_email = "Approval Denied";
|
2004-11-02 00:17:15 +03:00
|
|
|
$approved = "NO";
|
|
|
|
}
|
|
|
|
|
|
|
|
//Firstly, log the comments and action taken..
|
|
|
|
$userid = $_SESSION["uid"];
|
2004-12-13 04:09:37 +03:00
|
|
|
$sql = "SELECT TM.ID, `Name`, `vID`, TV.Version from `main` TM INNER JOIN `version` TV ON TM.ID = TV.ID WHERE TV.URI = '$file' ORDER BY `vID` ASC";
|
2004-11-02 00:17:15 +03:00
|
|
|
$sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE);
|
|
|
|
while ($row = mysql_fetch_array($sql_result)) {
|
|
|
|
$id = $row["ID"];
|
|
|
|
$vid = $row["vID"];
|
|
|
|
$name = $row["Name"];
|
2004-12-13 04:09:37 +03:00
|
|
|
$version = $row["Version"];
|
2004-11-02 00:17:15 +03:00
|
|
|
|
|
|
|
global $installation, $uninstallation, $newchrome, $appworks, $visualerrors, $allelementsthemed, $cleanprofile, $worksasdescribed, $testbuild, $testos, $comments;
|
2004-12-09 09:34:53 +03:00
|
|
|
$sql2 = "INSERT INTO `approvallog` (`ID`, `vID`, `UserID`, `action`, `date`, `Installation`, `Uninstallation`, `NewChrome`, `AppWorks`, `VisualErrors`, `AllElementsThemed`, `CleanProfile`, `WorksAsDescribed`, `TestBuild`, `TestOS`, `comments`) VALUES ('$id', '$vid', '$userid', '$action_comment', NOW(NULL), '$installation', '$uninstallation', '$newchrome', '$appworks', '$visualerrors', '$allelementsthemed', '$cleanprofile', '$worksasdescribed', '$testbuild', '$testos', '$comments');";
|
2004-11-02 00:17:15 +03:00
|
|
|
$sql_result2 = mysql_query($sql2, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE);
|
|
|
|
if ($sql_result2) {} else { $operations_failed=="true";}
|
|
|
|
}
|
|
|
|
if ($sql_result) {} else { $operations_failed=="true";}
|
|
|
|
|
|
|
|
//Secondly, If Stage 1 was successful (and we're approving the file), let's move the file to it's new home in /ftp/ for staging...
|
|
|
|
$filename = str_replace ("http://$sitehostname/developers/approvalfile.php", "$repositorypath/approval", $file);
|
|
|
|
if ($action=="approve") {
|
|
|
|
if (file_exists($filename)) {
|
|
|
|
if ($type=="T") {$type="themes";} else if ($type=="E") {$type="extensions";}
|
|
|
|
$path = strtolower("$type/$name");
|
|
|
|
$destination = str_replace("approval",strtolower("ftp/$path"),$filename);
|
|
|
|
$dirpath = "$repositorypath/ftp/$path";
|
|
|
|
if (!file_exists($dirpath)) {
|
|
|
|
mkdir($dirpath,0755);
|
|
|
|
}
|
2004-12-17 09:50:35 +03:00
|
|
|
if (!file_exists("$destination")) {
|
2004-12-13 04:09:37 +03:00
|
|
|
//No File Exists, its safe to rename.
|
|
|
|
if (rename("$filename", "$destination")) {
|
|
|
|
//Rename Successfull
|
|
|
|
} else {
|
|
|
|
//Rename Unsuccessfull
|
|
|
|
$operations_failed=="true";
|
|
|
|
}
|
2004-11-02 00:17:15 +03:00
|
|
|
} else {
|
2004-12-13 04:09:37 +03:00
|
|
|
//A File exists, not safe to rename, throw error.
|
2004-11-02 00:17:15 +03:00
|
|
|
$operations_failed=="true";
|
|
|
|
}
|
|
|
|
//$ftpurl defined in config.php
|
|
|
|
$uri = str_replace("$repositorypath/ftp","$ftpurl","$destination");
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if ($action=="deny") {
|
|
|
|
//We're denying approval on this item, delete the file and set URI to null.
|
|
|
|
if (file_exists($filename)) {unlink($filename); }
|
|
|
|
$uri = "";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Thirdly, update version record...
|
2004-12-09 09:34:53 +03:00
|
|
|
$sql = "UPDATE `version` SET `URI`='$uri', `approved`='$approved', `DateUpdated`=NOW(NULL) WHERE `URI`='$file'";
|
2004-11-02 00:17:15 +03:00
|
|
|
$sql_result = mysql_query($sql, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE);
|
|
|
|
if ($sql_result) {} else { $operations_failed=="true";}
|
|
|
|
|
|
|
|
@include"mail_approval.php";
|
|
|
|
|
|
|
|
if ($operations_failed=="true") { return false; } else { return true; }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|