[pmwiki-users] New recipe: Fox
marc
gmane at auxbuss.com
Thu Dec 21 09:45:20 CST 2006
Hans said...
> Wednesday, December 20, 2006, 3:46:30 PM, Daniel wrote:
>
> > Now one small question:
> > After click on "submit" I generate a new page in a given group called "Log".
>
> > Is there a chance to define the name of this new page dynamically with
> > the current date like:
> > "Log.20061220001" where 001 is a autoincrement?
>
> Okay here is a solution: a new page variable {$NewTicket}
> which is the new ticket pagename, i.e 'Log.20061220002'
> Put the variable in the Fox form as
> (:fox formname redirect=1 target={$NewTicket} template=... :)
> ...
>
> Put this code in config.php:
>
> # add page variable {$NewTicket}
> # creates auto increasing pagename of format
> # Log.20061220001 (date and 3 digit number)
> $FmtPV['$NewTicket'] = 'MakeNewTicket()';
> function MakeNewTicket() {
> foreach(ListPages('/^Log\\.\\d/') as $i)
> $issue = max(@$issue,substr($i,4));
> $issueday = substr($issue,0,8);
> $today = strftime("%Y%m%d", time());
> if($issueday==$today) {
> $nextissue = $issue+1;
> $pagename = 'Log.'.$nextissue;
> }
> else $pagename = 'Log.'.$today.'001';
> return $pagename;
> }
>
> Note that this code is group specific and deals with the exact format
> you wanted. I have not tried to 'generalise' it.
> Original idea adapted from PITS.php, thanks Pm!
Very neat! However, the 'Log.' format is invalid (I think) and ListPages
() returns $FullName, so the substr() doesn't work.
I tried the following with a pattern as a parameter (and changed 'Log.'
to 'Log-'):
$FmtPV['$NewTicket'] = 'MakeNewTicket(\'Log-\')';
function MakeNewTicket($pattern) {
foreach(ListPages("/^.*\\.$pattern/") as $i)
$issue = max(@$issue,preg_replace("/.*\\.$pattern/",'',$i));
$issueday = substr($issue,0,8);
$today = strftime("%Y%m%d", time());
if($issueday==$today) {
$nextissue = $issue+1;
$pagename = $pattern.$nextissue;
}
else $pagename = $pattern.$today.'001';
return $pagename;
}
Note, however, that two (or more) users could obtain the same
$nextissue, which results in both messages being written to the same
page.
--
Best,
Marc
More information about the pmwiki-users
mailing list