Location: PHPKode > projects > OpenBizMap > openbizmap/mydata/script/imp_csv.txt
<?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.
*/



$delim = ',';
$encl = '"';
$optional=1;
//$config=purename(substr($name,0,-4));

//$content="abc,abc\r\n1,2";

$fullname_array=array();
$variable_array=array();

$variable_array2=load_config($config);
if(!isset($fullname_array[$config]))
  while(list($key,$tmp)=each($variable_array2))
    $fullname_array[$config][purename($key)]=$key;

if ($content[strlen($content)-1]!="\r" && $content[strlen($content)-1]!="\n")
     $content .= "\r\n";

$content=str_replace("\r\n","\n",$content);
$content=str_replace("\r","\n",$content);
$content=str_replace("\n","\r\n",$content);

 $reg = '/(('.$encl.')'.($optional?'?(?(2)':'(').
         '[^'.$encl.']*'.$encl.'|[^'.$delim.'\r\n]*))('.$delim.
         '|\r\n)/smi';

 preg_match_all($reg, $content, $treffer);

 $linecount = 0;
 $fieldcount=0;
 $variable_array=array();
 $name_array=array();
 $sizeof=sizeof($treffer[3]);
 $last_perc=0;

//echo '<pre>';
//print_r($treffer);
//echo '</pre>';

 for($ii=0;$ii<=$sizeof;$ii++)
 {
    $value=$treffer[1][$ii];

    if(substr($value,0,1)==$encl)
      $value=substr($value,1);

    if(substr($value,-1)==$encl)
      $value=substr($value,0,-1);

    //if($linecount>0 and strpos('_'.strtolower($name_array[$fieldcount]),'date')>0 and strlen($value)==10) //date conversion to ISO
      //$value=substr($value,6,4).substr($value,3,2).substr($value,0,2);


    if($linecount==0)
      $name_array[$fieldcount]=$value;
    else
    {
      if(trim($value))
        $variable_array[$name_array[$fieldcount]]=$value;
    }

    $fieldcount++;

    if($treffer[3][$ii]!=$delim)
    {
      if(count($variable_array)>1)
      {
        //echo '<br />SAVE';
        //print_r($variable_array);
        //echo $config;

        if(!isset($variable_array['sysGroupBy']))
          $variable_array['sysGroupBy']=$config;

        $variable_array2=load_config($variable_array['sysGroupBy']);

        reset($variable_array);
        foreach($variable_array as $variable_name => $variable_value)
        {
          $template=$variable_array2[$variable_name]['template'];
          if(strlen(trim($template)))
          {
            //echo '<br />';
            //echo ' tmp='.$template;
            //echo ' pre='.$variable_value;

            $show_value=$variable_value;
            $show_mode=CFG_SAVE;
            if(file_exists(cfg_data_path.'/config/script/fld_'.$template.'.txt'))
            {
              include(cfg_data_path.'/config/script/fld_'.$template.'.txt');
            }
            else
            {
              if(!file_exists(cfg_data_path.'/script/fld_'.$template.'.txt'))
                $template='';

              include(cfg_data_path.'/script/fld_'.$template.'.txt');
            }
            $variable_array[$variable_name]=$show_value;
            //echo ' post='.$variable_array[$variable_name];
          }
        }


        $variable_array['sysComment']='Import '.substr($filename,0,-4);
        $variable_array['sysValidFrom']=date('Ymd');
        $variable_array['sysValidTo']=99991231;
        $variable_array['sysValid']=1;
        //$variable_array['Auto Import Stamp']=$importsign.' '.$record_cnt;

        //USEREXIT OnSave
        $userexit='onsave';
        if(file_exists(cfg_data_path.'/config/userexit/exit_'.$userexit.'.txt'))
        {
          include(cfg_data_path.'/config/userexit/exit_'.$userexit.'.txt');
        }
        else
        {
          include(cfg_data_path.'/script/userexit/exit_'.$userexit.'.txt');
        }

        // Save record
        save($variable_array);

        $record_cnt++;

        $variable_array=array();
      }

      $linecount++;
      $fieldcount=0;
    }
 }



?>
Return current item: OpenBizMap