<?php if (!defined('PmWiki')) exit();
/*
******************************************************************************************
*                                                                                        *
*    EditForm Custom Fields - Add "Title", "Creation Date", etc. custom input fields to  *
*                             the edit-form of PmWiki.                                   *
*    Copyright (C) 2010  Subhrajit Bhattacharya                                          *
*                                                                                        *
*    This program is free software: you can redistribute it and/or modify                *
*    it under the terms of the GNU General Public License as published by                *
*    the Free Software Foundation, either version 3 of the License, or                   *
*    (at your option) any later version.                                                 *
*                                                                                        *
*    This program is distributed in the hope that it will be useful,                     *
*    but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                       *
*    GNU General Public License for more details <http://www.gnu.org/licenses/>.         *
*                                                                                        *
*                                                                                        *
*    Contact: subhrajit@gmail.com, http://fling.seas.upenn.edu/~subhrabh/                *
*                                                                                        *
*                                                                                        *
******************************************************************************************
*/

SDV($customFields_isActive, array( 'title' => true,
                                   'ctime' => true  ) );  // TODO: Add/change items here or in config file

SDV($ctimeDispFmt, "%Y-%m-%d (%H:%M:%S)");  // TODO: Edit display format for 'ctime' here or in config file


// =============================================================


$thispagename = @$_REQUEST['n'];
$thispage = ReadPage($thispagename);


if ($customFields_isActive['title']){
   Markup('titledisable','>title','/\\(:title\\s(.*?):\\)/ei',"Keep('')");  // Override (:title:) definition
   
   $requestVal = @$_REQUEST['title'];
   if (!empty($requestVal)) {
      $inpString = $requestVal;
      PZZ(PCache($thispagename, $zz=array('title' => SetProperty($thispagename, 'title', PSS($inpString)))));
      $thispage['title'] = $inpString;
   }
   
   $readString = $thispage['title'];
   SDVA($InputTags['e_title'], array(
     ':html' => "<input type='text' \$InputFormArgs />",
     'name' => 'title', 'size' => '60', 'value' => $readString));
}


if ($customFields_isActive['ctime']){
   //$SaveProperties[] = 'ctime';  // COMMENTED ON MAR 15, 2012  // Add 'ctime' to the list of properties that PmWiki will save

   $requestVal = @$_REQUEST['ctime'];
   if (!empty($requestVal)) {
      $SaveProperties[] = 'ctime'; // ADDED ON MAR 15, 2012
      $aResult = strptime($requestVal, $ctimeDispFmt);
      $inpString = mktime($aResult['tm_hour'], $aResult['tm_min'], $aResult['tm_sec'], $aResult['tm_mon'] + 1, $aResult['tm_mday'], $aResult['tm_year'] + 1900) . "";
      PZZ(PCache($thispagename, $zz=array('ctime' => SetProperty($thispagename, 'ctime', PSS($inpString)))));
      $thispage['ctime'] = $inpString;
   }

   $readString = strftime($ctimeDispFmt, $thispage['ctime']);
   SDVA($InputTags['e_ctime'], array(
     ':html' => "<input type='text' \$InputFormArgs />",
     'name' => 'ctime', 'value' => $readString));
}


// TODO: Add new 'if' block here
// Remember to set $SaveProperties[] = 'NewPropertyName'

?>