<?php if (!defined('PmWiki')) exit();

/*  Copyright 2004 Laurent Meister (kt007) (meister at apfelwiki dot de)
    
    Version: newpage 1.0.1
    
    *Licence*
    You can redistribute this file and/or modify
    it under the terms of the GNU General Public License as published
    by the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.  
    
    *Description*
    This file enables the "NewPage" feature for PmWiki, which
    allows authors to create new pages with a form.
    
    Simply copy this file into the 'cookbook/' subdirectory or some other
    suitable place and then do

        include_once('cookbook/changesum.php');
        
     Create a page (like Main.NewPage) an put (:newpageform:) on it.
            
    This script works only with pmwiki2!
    
   
*/

markup('newpageform','inline','/\\(:newpageform:\\)/e',"Keep(NewPageForm(\$pagename))");

## NewPageForm() generates the form for entering a new page.  Note that
## once a page has been created, it's a normal wikipage and is edited
## according to the normal editing code (i.e., there's no form-based
## editing yet).
function NewPageForm($pagename) {
    $out[] = "<form method='post'>
    <input type='hidden' name='action' value='postnewpage' />
    <table>
      <tr><td class='newpagefield'> $[Author]:</td>
        <td><input type='text' name='author' value='\$Author' /></td></tr>
      <tr><td class='seitenname'>$[Group]:</td>
       <td><input type='text' name='group'></td></tr>";
  $out [] = "
         <tr><td class='gruppe'>$[Pagename]:</td>
        <td><input type='text' name='newpagename'></td></tr>";

  $out[] = "
         <tr><td valign='top'>$[NewPage]:</td>
        <td><textarea name='description' cols='60' rows='15'></textarea>
        </td></tr></table>
      <div align='center'><input type='submit' value='$[submit new page]' />
       </div>
     </form>"; 
  return FmtPageName(implode('',$out),$pagename);
}

$HTMLStylesFmt[] = ".pitsfield { text-align:right; font-weight:bold; }\n";

include_once("$FarmD/scripts/author.php");

if ($action=='postnewpage') { 
$pagename = "{$_REQUEST ['group']}."."{$_REQUEST ['newpagename']}";
    if (!PageExists($pagename))
  { 	 if ($_REQUEST ['group'] == "") {
	   $pagename = "Main."."{$_REQUEST ['newpagename']}";}
     if ($_REQUEST ['group'] == "PITS") {
	   Abort("cannot create pages in PITS. Please use the PITS Form for a new issue. It's located at $ScriptUrl/PITS/PITS ");}
    if ($_REQUEST ['newpagename'] == "") {
        $UrlPage="{$_REQUEST ['group']}";
        Redirect($PageNotFound);}
    else
     Lock(2);
	  $action = 'edit';
	  $_REQUEST['post'] = 1;
	  $CreateTime = strftime('%Y-%m-%d %H:%M',$Now);
	  $EditMessageFmt = "<p class='vspace'>Please review and make any edits 
		to your issue below, then press 'Save'.</p>";
	  $_POST['text'] = "{$_REQUEST['description']}";
	}
	
    else
  		{Redirect($pagename);}
    
}


?>