<?php
/* Directory Creator to be run by a cron job
-Will go to the path of the starting directory for the sites root directory
-it then will go into the monthly-files directory and go through and create the
appropriate directories and sub-directories.
-This script will be run at 12:00am on the first of the month.
*/
//require("all-vars.inc.php");
$inhousenames = array("Company1", "Company2");
$siteRoot = "/usr/local/apache/htdocs/042003";
$currMonthNum = date("m");
$curr2Year = date("y");
$currMainDir = $curr2Year . $currMonthNum;
$currentPath = $siteRoot . "/monthly-files";
$tempDir = "0306"; //change to $currMainDir
$updatesDirs = array("Commissions","Equipment","Plan-matrix","Promos","Rebates","Specials");
$wasCreated = array();
if (is_dir($currentPath))
{//a
if (!is_dir($currentPath . "/" . $tempDir))
{//b
mkdir($currentPath . "/" . $tempDir,0755);
$currentPath .= "/" . $tempDir;
if (is_dir($currentPath))
{//c
for ($i=0; $i < count($inhousenames); $i++)
{
mkdir($currentPath . "/" . $tempDir . $inhousenames[$i] . "Mailer",0755);
if (is_dir($currentPath . "/" . $tempDir . $inhousenames[$i] . "Mailer"))
$wasCreated[] = $currentPath . "/" . $tempDir . $inhousenames[$i] . "Mailer";
}
mkdir($currentPath . "/" . $tempDir . "Updates",0755);
$currentPath .= "/" . $tempDir . "Updates";
if (is_dir($currentPath))
{//d
for ($u=0; $u < count($updatesDirs); $u++)
{
mkdir($currentPath . "/" . $updatesDirs[$u],0755);
if (is_dir($currentPath . "/" . $updatesDirs[$u]))
$wasCreated[] = $currentPath . "/" . $updatesDirs[$u];
}
print "Directory Creator was successful on the following directories: <br><hr>";
for ($d=0; $d < count($wasCreated); $d++)
{ print "The directory <b>" . $wasCreated[$d] . "</b> created successfully.<br>"; }
} else {//end d
print "<b>ERROR LV 3:</b> " . $currentPath . " does not exist or was not created properly. Directory Creator will now exit....";
}
} else {//end c
print "<b>ERROR LV 2:</b> " . $currentPath . " does not exist or was not created properly. Directory Creator will now exit.......";
}
} else {//end b
print "The Directory, <b>" . $currentPath . "/" . $tempDir . "</b> already exists!!!";
}
} else {//end a
print "<b>ERROR LV 1:</b> " . $currentPath . " does not exist or was not created properly. Directory Creator will now exit.......";
}
?>