<?
class PriceTable extends ModuleTable
{
var $classname = 'Price';
function DelDir($directory) {
$dir = opendir($directory);
while(($file = readdir($dir))) {
if (is_file($directory."/".$file)) {
unlink ($directory."/".$file);
} elseif (is_dir($directory."/".$file) && ($file!=".") && ($file != "..")) {
full_del_dir ($directory."/".$file);
}
}
closedir ($dir);
#rmdir ($directory);
}
function init () {
$sPath = '../files/db_price/';
$dDir = opendir($sPath);
$aFileList=array();
while ($sFileName=readdir($dDir)) {
if ($sFileName!='.' && $sFileName!='..') {
$aFileList[]=$sFileName;
}
sort($aFileList);
}
closedir ($dDir);
$iNumFiles=count($aFileList);
if ($iNumFiles!=0) {
$del_price = &new Price();
$del_price->query ('TRUNCATE '.$del_price->__table);
$this->DelDir('../files/price/');
foreach ($aFileList as $k=>$file) {
if (strtolower(substr($file,strlen($file)-4))=='html') {
$bufer = substr($file,0,strlen($file)-5);
$date = substr($bufer,strlen($bufer)-9,strlen($bufer));
$name = substr($bufer,0,strlen($bufer)-9);
$add = &new Price();
$add->pr_name = $name;
$add->pr_date = $date;
$add->update();
if (file_exists($sPath.$file)) {
copy($sPath.$file,'../files/price/price_'.$add->pr_name.'.html');
}
$update_file = &new Price();
$update_file->pr_id = $add->pr_id;
$update_file->pr_file = '/files/price/price_'.$add->pr_name.'.html';
$update_file->update();
} else {
$name = substr($file,0,strlen($file)-5);
$add = &new Price();
$add->pr_name = $name;
$add->pr_date = date('d.m.Y');
$add->update();
if (file_exists($sPath.$file)) {print_r($name);
copy($sPath.$file,'../files/price/'.$file);
}
$update_file = &new Price();
$update_file->pr_id = $add->pr_id;
$update_file->pr_file = '/files/price/'.$file;
$update_file->update();
}
unlink($sPath.$file);
}
}
}
}
?>
<?
require_once BACK_DIR_ABS . '/includes/access.php';
require_once BACK_DIR_ABS.'/modules/common/access/gallery.php';
class Price extends Access
{
var $pr_id;
var $pr_name;
var $pr_file;
var $pr_date;
var $pr_isactive;
var $pr_pos;
var $prefix = 'pr_';
function setFrom ($array)
{
parent::setFrom ($array);
}
}
?>
это обновление прайс-листа, все записи из таблицы старые удаляются, из каталога в каталог копируются, а в БД не добавляются..