function createDocScripts($Table_ID, $path_array, $mysqli) { $doc_path = $path_array['project_path'] . 'help/doc_pages/'; //Let's get the table name so we know what subclass to require later. //The table name is also the class name generated, so let's call it 'class_name' in the query. $mysqli->real_query("SELECT a.`Table_Name` AS `class_name`, b.`Path_Filename` AS `List_View_Page`\n FROM `table` a, `table_pages` b, `page` c\n WHERE a.Table_ID='{$Table_ID}' AND\n a.Table_ID=b.Table_ID AND\n b.Page_ID=c.Page_ID AND\n c.Description LIKE 'List View%'"); if ($result = $mysqli->use_result()) { $data = $result->fetch_assoc(); extract($data); $doc_subclass = $class_name . '_doc'; $doc_subclass_file = $doc_subclass . '.php'; $doc_directory = $doc_path . $class_name; } else { die($mysqli->error); } $result->close(); //Doc Page $doc_script = <<<EOD <?php require 'path.php'; init_cobalt(); require 'subclasses/{$doc_subclass_file}'; \$obj_doc = new {$doc_subclass}; \$obj_doc->auto_doc(); EOD; //Delete existing old project, if any. if (file_exists($doc_directory)) { obliterate_dir($doc_directory); } mkdir($doc_directory, 0777); chmod($doc_directory, 0777); createDirectoryIndex($doc_directory . '/'); mkdir($doc_directory . '/images', 0777); chmod($doc_directory . '/images', 0777); createDirectoryIndex($doc_directory . '/images/'); $filename = $doc_directory . '/' . $class_name . '.php'; if (file_exists($filename)) { unlink($filename); } $newfile = fopen($filename, "ab"); fwrite($newfile, $doc_script); fclose($newfile); chmod($filename, 0777); //We should return the doc subclass and the class name (array) return array($doc_subclass, $class_name); }
function obliterate_dir($dir) { if (!file_exists($dir)) { return true; } if (!is_dir($dir) || is_link($dir)) { return unlink($dir); } foreach (scandir($dir) as $item) { if ($item == '.' || $item == '..') { continue; } if (!obliterate_dir($dir . DIRECTORY_SEPARATOR . $item)) { chmod($dir . DIRECTORY_SEPARATOR . $item, 0777); if (!obliterate_dir($dir . DIRECTORY_SEPARATOR . $item)) { return false; } } } return rmdir($dir); }
$result->close(); } else { die($mysqli->error); } if (xsrf_guard()) { init_var($_POST['btnCancel']); init_var($_POST['btnSubmit']); if ($_POST['btnCancel']) { header("location: " . HOME_PAGE); exit; } elseif ($_POST['btnSubmit']) { //If base directory is composed of nested subdirectories, we only need the very first folder. $subdirectories = explode('/', $_POST['Base_Directory']); $base_directory = $subdirectories[0]; if (is_dir("../Generator/Projects/" . $base_directory)) { obliterate_dir("../Generator/Projects/" . $base_directory); } queryDeleteProject($_POST, $mysqli); } } drawHeader(); drawPageTitle('DESTROY PROJECT', 'YOU ARE ABOUT TO DESTROY AN ENTIRE PROJECT!<br>Are you sure you wish to permanently delete this project and all of its contents?'); ?> <input type=hidden name=Project_ID value="<?php echo $_SESSION['Project_ID']; ?> "> <input type="hidden" name="Base_Directory" value="<?php echo $Base_Directory; ?> ">
//Check if "Generator/Projects" folder is writable clearstatcache(); if (is_writable($SCV2_path . TARGET_DIRECTORY)) { $SCV2_core_path = $SCV2_path . 'Generator/Core_Files/'; //Creating the base directory... $project_path = $SCV2_path . TARGET_DIRECTORY . $Base_Directory . '/'; //Note that it may be necessary to create multiple, nested directories, //depending on what the user specified as the project's base directory. $subdirectory = explode("/", $Base_Directory); $subdirectory_count = count($subdirectory); $current_directory = $SCV2_path . TARGET_DIRECTORY; for ($a = 0; $a < $subdirectory_count; ++$a) { $current_directory .= $subdirectory[$a] . '/'; //Delete existing old project, if any. if (file_exists($current_directory)) { obliterate_dir($current_directory); } mkdir(substr($current_directory, 0, -1), 0777); chmod(substr($current_directory, 0, -1), 0777); } //Creating the Core folder inside the base directory... $project_core_path = $project_path . "core/"; if (!file_exists($project_core_path)) { mkdir(substr($project_core_path, 0, -1), 0777); chmod($project_core_path, 0777); } //Creating the Subclasses folder inside the Core folder inside the base directory... $subclass_path = $project_path . 'core/subclasses/'; if (!file_exists($subclass_path)) { mkdir(substr($subclass_path, 0, -1), 0777); chmod(substr($subclass_path, 0, -1), 0777);