<?php

#1 Get Input
$page = "new_page";
$template = "template_default";
 
$page = $argv[1];
$template = $argv[2];

if ($page == "" OR $template == "") {
  echo "Syntax: php create_page.php page_name template_name\n";
  echo "cod0rzed by medicin3\n";  
  exit();
} 

function fix_string($in_string) {
$in_string = str_replace('_', ' ', $in_string);
$in_string = ucwords($in_string);
return $in_string;
}

$uc_page = strtoupper($page);
$ucf_page = ucfirst($page);
$fixed_page = fix_string($page);

echo"\n Initating...\n";

#2 Define Page
$fp = fopen("includes/filenames.php", "a");
fwrite($fp, "\n<? define('FILENAME_DEFINE_$uc_page', 'define_$page'); ?>");
fclose($fp);
echo " [x] added entry to includes/filenames.php \n";


#3 Define Headers
$output = "<?php
//
// +----------------------------------------------------------------------+
// |zen Open Source E-commerce                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen developers                          |
// |                                                                      |
// | http://www.zen-cart.com/index.php                              |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt. If you did            |
// | not receive a copy of the zen-cart license and are unable      |
// | to obtain it through the world-wide-web, please send a note to       |
// | license@zen-cart.com so we can mail you a copy immediately.    |
// +----------------------------------------------------------------------+
// $Id: \$page.php
//

	define('HEADING_TITLE', '$fixed_page');
	define('NAVBAR_TITLE', '$fixed_page');
?>";
$fp = fopen("includes/languages/english/" . $page . ".php", "w");
fwrite($fp, $output);
fclose($fp);
system("chmod 777 includes/languages/english/" . $page . ".php");
echo " [x] created includes/languages/english/". $page . ".php \n";


#4 Create Header File
$output = "<?php
//
// +----------------------------------------------------------------------+
// |zen Open Source E-commerce                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen developers                          |
// |                                                                      |
// | http://www.zen-cart.com/index.php                              |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt. If you did            |
// | not receive a copy of the zen-cart license and are unable      |
// | to obtain it through the world-wide-web, please send a note to       |
// | license@zen-cart.com so we can mail you a copy immediately.    |
// +----------------------------------------------------------------------+
// $Id: \$page.php
//

  require(DIR_WS_MODULES . 'require_languages.php');
  \$breadcrumb->add(NAVBAR_TITLE);
  \$define_$page = zen_get_file_directory(DIR_WS_LANGUAGES . \$_SESSION['language'] . '/html_includes/', FILENAME_DEFINE_$uc_page, 'false');
?>";
system("mkdir includes/modules/pages/$page");
$fp = fopen("includes/modules/pages/$page/header_php.php", "w");
fwrite($fp, $output);
fclose($fp);
system("chmod -R 777 includes/modules/pages/$page");
echo " [x] created includes/modules/pages/$page \n";


#5 Create Template Page
$output = "
<?php
//
// +----------------------------------------------------------------------+
// |zen Open Source E-commerce                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen developers                          |
// |                                                                      |
// | http://www.zen-cart.com/index.php                              |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt. If you did            |
// | not receive a copy of the zen-cart license and are unable      |
// | to obtain it through the world-wide-web, please send a note to       |
// | license@zen-cart.com so we can mail you a copy immediately.    |
// +----------------------------------------------------------------------+
// $Id: \$tpl_page_default.php
//
?>

<table  width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\" >
  <tr>
    <td class=\"breadCrumb\"><?php echo \$breadcrumb->trail(BREAD_CRUMBS_SEPARATOR); ?></td>
  </tr>
  <tr>
    <td class=\"pageHeading\"><h1><?php echo HEADING_TITLE; ?></h1></td>
  </tr>
  <tr>
  	<td><?php require(\$define_" . $page . "); ?></td>
  </tr>
  </table>";
$fp = fopen("includes/templates/$template/templates/tpl_" . $page . "_default.php", "w");
fwrite($fp, $output);
fclose($fp);
system("chmod 777 includes/templates/$template/templates/tpl_" . $page . "_default.php");
echo " [x] added entry to includes/templates/$template/templates/\n";


#6 Create HTML Page
$fp = fopen("includes/languages/english/html_includes/define_$page.php", "w");
fwrite($fp, "<p>insert text in me!</p>");
fclose($fp);
system("chmod 777 includes/languages/english/html_includes/define_$page.php");
echo " [x] done! now go and edit includes/languages/english/html_includes/define_$page.php \n";


#7 Success
echo "
 ****************************************************
 ****** Success! You have created a new page! *******
 ****************************************************\n
";
?>