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

/*
Action execution

IN $id - current record id
*/


$debug=0;

$id=get('id');
$trans=get('trans');
$recalculate=get('save');
$copy=get('copy');
$delete=get('delete');
$compare=get('compare');

$sys_comment=get('sys_comment');

$show_result_array=array();

if(!$compare)
{
  if($bag)
  {
    $show_result_array=search($search.' MyBag='.$bag);
    if(count($show_result_array)==0)
      $show_result_array=search($search);
  }
  else
    $show_result_array=search($search);


  if($debug) echo '<br />QCHANGE: '.$search.' / '.$id.' RESULT_SIZE:'.count($show_result_array);

  if(count($show_result_array)>0)
  {
    $new_array=array();

    foreach($show_result_array as $show_result_line)
    {
      $variable_array=array();
      $variable_array['sysId']=read($show_result_line,'sysId');

      //delete check
      if($delete and get($variable_array['sysId']))
      {
        if($debug) echo 'DELETED:'.$variable_array['sysId'];
        {
          //USEREXIT OnDelete
          $userexit='ondelete';
          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');
          }
          delete(read($show_result_line,'MyBag'),$variable_array['sysId']);
          if(!$message) $message='Data deleted';
        }
      }
      else
      {
        $variable_array2=load_config(read($show_result_line,'sysGroupBy'));

        reset($variable_array2);
        while(list($variable_name,$tmp)=each($variable_array2))
          $variable_array[$variable_name]=read($show_result_line,$variable_name);

        $old_variable_array=$variable_array;

        $variable_array['sysComment']=$sys_comment;
        $variable_array['sysGroupBy']=strtolower(purename($variable_array['sysGroupBy']));

        $action_array=array();
        $action_values_array=array();

        //USEREXIT OnShowAction
        $userexit='onshowaction';
        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');
        }
        
        $action_count=0;
        foreach($action_array as $action_name => $tmp_value)
        {
          if(get('action'.$action_count))
            $action_values_array=$tmp_value;
          $action_count++;
        }
      
        $tmp_id=$variable_array['sysId'];

        //checking for changes
        //echo $tmp_id.'<pre>';  print_r($variable_array); echo '</pre>';
        $last_bag=$variable_array['MyBag'];
        $changes=0;

        reset($variable_array);
        while(list($variable_name,$variable_value)=each($variable_array))
        {
          $val=get(purename($variable_name).'_'.$tmp_id); //better field name coding
          if(!$val) // reading properly changes from old manual mascs
            $val=get(str_replace(' ','_',$variable_name).'_'.$tmp_id);
          if($variable_array2[$variable_name]['template']=='check' and $val==1 and !get(purename($variable_name).'_'.$tmp_id.'check')) //checkbox
            $val=' ';

          if($variable_array2[$variable_name]['template']=='button')
            if($val)
              $val=rand(10000,99999);
            else
              $val=' ';

          if(isset($action_values_array[$variable_name]) and get($tmp_id))
          {
            if(substr($action_values_array[$variable_name],0,1)=='[' and substr($action_values_array[$variable_name],-1,1)==']')
              $val=$old_variable_array[substr($action_values_array[$variable_name],1,-1)];
            else
              $val=$action_values_array[$variable_name];
          }
        
          if(strlen($val) and ($variable_value!=$val))
          {
            //checking for rights to add new records to that bag
            if(1)// or $variable_name!='MyBag' or check_access($val)>1) //off becouse of annoying me nawara 19.09.2005
            {
              //converting before comparison
              $template=$variable_array2[$variable_name]['template'];
              $show_value=$val;
              $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');
              }
              $val=$show_value;

              if(trim($variable_value)!=trim($val))
              {
                $changes=1;
                $variable_array[$variable_name]=trim($val);

                //echo 'DICT'.$variable_name.'='.$variable_array[$variable_name];
                addpath(cfg_data_path.'/config/dict');
                $fp=fopen(cfg_data_path.'/config/dict/dict_'.purename($variable_name).'.txt','ab');
                  fwrite($fp,$variable_array[$variable_name].CRLF);
                fclose($fp);

              }
            }
            else
            {
              myecho('Cannot set MyBag=%1. No access there...',$val);
            }
          }
        }
        
        //cloning check
        if($copy and get($variable_array['sysId']))
        {
          $variable_array['sysId']='';
          $changes=1;

          //USEREXIT OnClone
          $userexit='onclone';
          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');
          }
        }

        //SAVING -------------------------------------------------------------------
        if($changes)
        {
          //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');
          }

          if($copy)
          {
            $search='sysId='.save($variable_array,$last_bag); //problem - no group
            if(!$message) $message='Data copied';
          }
          else
          {
            save($variable_array,$last_bag);
            if(!$message) $message='Data saved';
          }

        }
      }
    }
  }
}
else //compare
{
  $session_array['compare']='';
  if($bag)
  {
    $show_result_array=search($search.' MyBag='.$bag);
    if(count($show_result_array)==0)
      $show_result_array=search($search);
  }
  else
    $show_result_array=search($search);

  if(count($show_result_array)>0)
  {
    foreach($show_result_array as $show_result_line)
    {
      $variable_array=array();
      $variable_array['sysId']=read($show_result_line,'sysId');
      $variable_array['sysGroupBy']=read($show_result_line,'sysGroupBy');

      if(get($variable_array['sysId']))
      {
        $session_array['compare'].='$'.$variable_array['sysId'].'$';
        if(strpos($session_array['compare'],$variable_array['sysGroupBy'])==0)
          $session_array['compare'].='$'.$variable_array['sysGroupBy'].'$';
      }
    }
  }
}

?>
Return current item: OpenBizMap