<?php
/*
OpenDataBag - Data Web Interface
Copyright (C) 2004 Nawara
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
$dictionary=get('dictionary');
$dictcontent=get('dictcontent');
$allownew=get('allownew');
//backup
if(file_exists(cfg_data_path.'/config/dict/static_'.purename($dictionary).'.txt'))
{
$tmp=1;
while(file_exists(cfg_data_path.'/config/dict/static_'.purename($dictionary).$tmp.'.bak'))
$tmp++;
rename(cfg_data_path.'/config/dict/static_'.purename($dictionary).'.txt',cfg_data_path.'/config/dict/static_'.purename($dictionary).$tmp.'.bak');
}
if(!$allownew)
{
if(strlen(trim($dictcontent)))
{
$fp=fopen(cfg_data_path.'/config/dict/static_'.purename($dictionary).'.txt','wb');
fwrite($fp,trim($dictcontent).CRLF);
fclose($fp);
}
}
else
{
if(strlen(trim($dictcontent)))
{
$fp=fopen(cfg_data_path.'/config/dict/dict_'.purename($dictionary).'.txt','wb');
fwrite($fp,trim($dictcontent).CRLF);
fclose($fp);
}
else
{
//backup
$tmp=1;
while(file_exists(cfg_data_path.'/config/dict/dict_'.purename($dictionary).$tmp.'.bak'))
$tmp++;
rename(cfg_data_path.'/config/dict/dict_'.purename($dictionary).'.txt',cfg_data_path.'/config/dict/dict_'.purename($dictionary).$tmp.'.bak');
}
}
$fp=fopen(cfg_data_path.'/data/.lastmod','wb');
fwrite($fp,date('Ymd H:i:s'));
fclose($fp);
?>