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

    $content=str_replace("\t",' ',$content);
    $content=str_replace("\r",'',$content);
    $content=str_replace("\n",' ',$content);
    $content=str_replace("<?",' ',$content);
    $content=str_replace("?>",' ',$content);
    $content=str_replace("<",' ',$content);
    $content=str_replace("/>",' ',$content);
    $content=str_replace(">",' ',$content);

    $fullname_array=array();
    $start=time();
    $timerun_sec=0;
    $record_array=array();
    $variable_array=array();
    $tag_array=explode('"',$content);
    $sizeof=sizeof($tag_array);
    $record_cnt=0;
    for($ii=0;$ii<$sizeof;$ii=$ii+2)
    {
      $tag=trim($tag_array[$ii]);
      $val=trim($tag_array[$ii+1]);

      //echo $tag.'!'.$val.CRLF;

      if(strpos($tag,' ')>0)
      {
        if(sizeof($variable_array)>1)
        {
          $variable_array['sysGroupBy']=$config;
          $variable_array['sysComment']='Import '.$importsign;
          $variable_array['sysValidFrom']=date('Ymd');
          $variable_array['sysValidTo']=99991231;
          $variable_array['sysValid']=1;
          $variable_array['Auto Import Stamp']=$importsign.' '.$record_cnt;

          // Save record
          save($variable_array);
          $variable_array=array();

          // Save import status
          if($record_cnt<3 or $last_perc!=round($ii/$sizeof*100,0))
          {
            $timerun_sec=time()-$start;

            $h=floor($timerun_sec/3600);
            $m=floor(($timerun_sec%3600)/60);
            $s=($timerun_sec%60);

            $timerun='';
            if($h) $timerun.= $h.'h ';
            if($m) $timerun.= $m.'m ';
            if($s) $timerun.= $s.'s ';

            echo 'Importing: '.$filename.' ('.(round($ii/$sizeof*100,0)).'%)  running time: '.$timerun.'                     '.chr(13);

            $import_variable_array['Import Status']=(round($ii/$sizeof*100,0)).'%';
            $import_variable_array['Running time']=$timerun;
            $import_variable_array['Imported records']=$record_cnt;

            save($import_variable_array);
          }

          $record_cnt++;
        }


        $config=substr($tag,0,strpos($tag,' '));
        $tag=trim(substr($tag,strpos($tag,' ')));

        $variable_array2=load_config($config);

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


      $key=substr($tag,0,strpos($tag,'='));

      $pos=strpos($key,'_');
      if($pos>1)
      {
        $attribute=substr($key,$pos+1);
        $key=substr($key,0,$pos);
      }
      else
      {
        $attribute='value';
        $key=$key;
      }

      if($attribute=='name')
        $fullname_array[$config][$key]=$val;

      if(isset($fullname_array[$config][$key]))
        $key=$fullname_array[$config][$key];

      if($attribute=='value')
        $variable_array[$key]=$val;

      //if($key=='sysId')
      //  $fullname_array[$config][$key]='sysId';
    }

    $variable_array['sysGroupBy']=$config;
    $variable_array['sysComment']='Import '.$importsign;
    $variable_array['sysValidFrom']=date('Ymd');
    $variable_array['sysValidTo']=99991231;
    $variable_array['sysValid']=1;
    $variable_array['Auto Import Stamp']=$importsign.' '.$record_cnt;
    //print_r($variable_array);
    //echo CRLF;

    // Save record
    save($variable_array);
?>
Return current item: OpenBizMap