require "../config/preferences.php"; require_once NSSDROPBOX_LIB_DIR . "MyZendTo.Smartyconf.php"; require_once NSSDROPBOX_LIB_DIR . "NSSDropoff.php"; // // This is pretty straightforward; depending upon the form data coming // into this PHP session, creating a new dropoff object will either // display the claimID-and-claimPasscode "dialog" (no form data or // missing/invalid passcode); display the selected dropoff if the // claimID and claimPasscode are valid OR the recipient matches the // authenticate user -- it's all built-into the NSSDropoff class. // if ($theDropbox = new NSSDropbox($NSSDROPBOX_PREFS, TRUE)) { $theDropbox->SetupPage(); if ($thePickup = new NSSDropoff($theDropbox)) { $claimID = $thePickup->claimID(); $smarty->assign('claimID', $claimID); $success = $thePickup->removeDropoff(); # If next=="index" then redirect them to the autoHome page without delay if ($success && $_POST['next'] == "index") { Header("HTTP/1.1 302 Moved Temporarily"); Header("Location: " . $NSSDROPBOX_URL); exit; } $smarty->assign('success', $success); $smarty->assign('autoHome', TRUE); if (!$success) { NSSError("Unable to remove the dropoff. Please contact the system administrator.", "Unable to remove " . $claimID); } } } $smarty->display('delete.tpl');
public static function cleanupOrphans($aDropbox) { $qResult = $aDropbox->database->DBDropoffsAll(); $scrubCount = 0; if ($qResult && ($iMax = count($qResult))) { // // Build a list of claim IDs and walk the dropoff directory // to remove any directories that aren't in the database: // $dropoffDir = $aDropbox->dropboxDirectory(); if ($dirRes = opendir($dropoffDir)) { $i = 0; $validClaimIDs = array(); while ($i < $iMax) { $nextClaim = $qResult[$i]['claimID']; // If there's no directory, then we should scrub this entry // from the database: if (!is_dir($dropoffDir . "/" . $nextClaim)) { if ($aDropoff = new NSSDropoff($aDropbox, $qResult[$i])) { $aDropoff->removeDropoff(FALSE); echo "- Removed orphaned record: {$nextClaim}\n"; } else { echo "- Unable to remove orphaned record: {$nextClaim}\n"; } $scrubCount++; } else { $validClaimIDs[] = $nextClaim; } $i++; } while ($nextDir = readdir($dirRes)) { // Each item is a NAME, not a PATH. Test whether it's a directory // and no longer in the database: if ($nextDir != '.' && $nextDir != '..' && is_dir($dropoffDir . "/" . $nextDir) && !in_array($nextDir, $validClaimIDs)) { if (rmdir_r($dropoffDir . "/" . $nextDir)) { echo "- Removed orphaned directory: {$nextDir}\n"; } else { echo "- Unable to remove orphaned directory: {$nextDir}\n"; } $scrubCount++; } } closedir($dirRes); } } if ($scrubCount) { printf("%d orphan%s removed.\n\n", $scrubCount, $scrubCount == 1 ? "" : "s"); } else { echo "No orphans found.\n\n"; } }