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

global $filter_array;

echo '<h2>';
myecho('Action');
echo '</h2>';

echo '<a style="margin-left:10px;" href="#" onclick="document.getElementById(\'actiondef\').style.display=\'block\'; this.style.display=\'none\';">';
  myecho('Show definition');
echo '</a>';

echo('<form action="index.php" onsubmit="var tmp=prompt(\'Comment. Why do you change data?\', this.odb_sys_comment.value); if(tmp==null){return false;}else{this.odb_sys_comment.value=tmp;}" method="get">');
echo('<div id="actiondef" style="display:none;"><input name="odb_script" type="hidden" value="action"></input>');
echo('<input name="odb_search" type="hidden" value="'.$search.'"></input>');

  $sys_comment=$sys_comment;
  if(!$sys_comment)
    $sys_comment='Your comment here...';
  echo(' <input title="Why do you change data?" name="odb_sys_comment" type="hidden" value="'.$sys_comment.'"></input>');


$key2=get('k2');
$key3=get('k3');
$key4=get('k4');

echo '<div class="supergroup">';
  echo '<table>';
  echo '<tr>';
    //-----------------------------------------------------
    echo '<td class="label">';
    echo '</td>';

    for($ii=1;$ii<4;$ii++)
    {
      echo '<td class="label">';
        myecho('Key %1',$ii);
      echo '</td>';
    }

    echo '<td class="label">';
    echo '</td>';

    for($ii=1;$ii<4;$ii++)
    {
      echo '<td class="label">';
        myecho('Action %1',$ii);
      echo '</td>';
    }

    echo '<td class="label">';
    echo '</td>';

    for($ii=1;$ii<10;$ii++)
    {
      echo '<td class="label">';
        myecho('Column %1',$ii);
      echo '</td>';
    }

    echo '<td class="label">';
    echo '</td>';

  echo '</tr>';
  echo '<tr>';
    //-----------------------------------------------------
    echo '<td class="label">';
      echo 'Name';
    echo '</td>';

    for($ii=2;$ii<5;$ii++)
    {
      echo '<td class="input">';
        $show_name='k'.$ii;
        $show_value=get('k'.$ii);
        $variable_name='ALLWORDS';
        echo('<input class="fld_ sizeS" name="'.$show_name.'" id="'.$show_name.'" type="text" title="'.$show_value.'" onkeydown1="new AutoSuggestControl(this, \''.$variable_name.'\', new RemoteStateSuggestions());" value="'.$show_value.'"/>');
      echo '</td>';
    }

    echo '<td class="label">';
      echo 'Name';
    echo '</td>';

    for($ii=1;$ii<4;$ii++)
    {
      echo '<td class="input">';
        $show_name='a'.$ii;
        $show_value=get('a'.$ii);
        $variable_name='ALLWORDS';
        echo('<input class="fld_ sizeS" name="'.$show_name.'" id="'.$show_name.'" type="text" title="'.$show_value.'" onkeydown1="new AutoSuggestControl(this, \''.$variable_name.'\', new RemoteStateSuggestions());" value="'.$show_value.'"/>');
      echo '</td>';
    }

    echo '<td class="label">';
      myecho('Name');
    echo '</td>';

    for($ii=1;$ii<10;$ii++)
    {
      $key1name=get('n'.$ii);
      echo '<td class="input">';
        echo '<input class="fld_ sizeS" name="n'.$ii.'" value="'.$key1name.'" />';
      echo '</td>';
    }

    echo '<td class="label">';
    echo '</td>';

  echo '</tr>';
  echo '<tr>';
    //-----------------------------------------------------
    echo '<td class="label">';
      echo '';
    echo '</td>';

    for($ii=1;$ii<4;$ii++)
    {
      echo '<td class="input">';
      echo '</td>';
    }

    echo '<td class="label">';
      echo 'Field';
    echo '</td>';

    for($ii=1;$ii<4;$ii++)
    {
      echo '<td class="input">';
        $show_name='f'.$ii;
        $show_value=get('f'.$ii);
        $variable_name='ALLWORDS';
        echo('<input class="fld_ sizeS" name="'.$show_name.'" id="'.$show_name.'" type="text" title="'.$show_value.'" onkeydown1="new AutoSuggestControl(this, \''.$variable_name.'\', new RemoteStateSuggestions());" value="'.$show_value.'"/>');
      echo '</td>';
    }

    echo '<td class="label">';
      myecho('Filter');
    echo '</td>';

    for($ii=1;$ii<10;$ii++)
    {
      $key1filter=get('e'.$ii);
      echo '<td class="input">';
        echo '<input class="fld_ sizeS" name="e'.$ii.'" value="'.$key1filter.'" />';
      echo '</td>';
    }

    echo '<td class="label">';
    echo '</td>';

  echo '</tr>';
  echo '<tr>';
    //-----------------------------------------------------
    echo '<td class="label">';
      echo '';
    echo '</td>';

    for($ii=1;$ii<4;$ii++)
    {
      echo '<td class="input">';
      echo '</td>';
    }

    echo '<td class="label">';
      echo 'Value';
    echo '</td>';

    for($ii=1;$ii<4;$ii++)
    {
      echo '<td class="input">';
        $show_name='s'.$ii;
        $show_value=get('s'.$ii);
        $variable_name='ALLWORDS';
        echo('<input class="fld_ sizeS" name="'.$show_name.'" id="'.$show_name.'" type="text" title="'.$show_value.'" onkeydown1="new AutoSuggestControl(this, \''.$variable_name.'\', new RemoteStateSuggestions());" value="'.$show_value.'"/>');
      echo '</td>';
    }

    echo '<td class="label">';
      myecho('Formula');
    echo '</td>';

    for($ii=1;$ii<10;$ii++)
    {
      $key1var=get('v'.$ii);
      echo '<td class="input">';
        echo '<input class="fld_ sizeS" name="v'.$ii.'" value="'.$key1var.'" />';
      echo '</td>';
    }

    echo '<td>';
      echo('<input type="submit" class="submit" value="'.myecho('Action','RETURN').'" />');
    echo '</td>';

  echo '</tr>';
  echo '</table>';
  echo '<a style="margin-left:10px;" href="index.php?odb_sys=structure" target="_blank">';
    myecho('Show all available fields');
  echo '</a>';
echo '</div>';

echo('</div>');



//-------------------------------------------------------------------------------------------------------------

function stat_add($column_name,$filter,$condition=1,$add=1)
{
  global $agregation_array;
  global $val1_array;
  global $line;
  global $val2;
  global $val3;
  global $val4;

  $val1=$column_name;
  if($add!=0 and $condition)
  {
    if(strlen($filter)==0 or strpos('_'.$line,$filter))
    {
      $val1_array[$val1]=$filter;
      $agregation_array[$val2][$val3][$val4][$val1]+=$add;

      $agregation_array[$val2][$val3]['TOTAL'][$val1]+=$add;
      $agregation_array[$val2]['TOTAL']['TOTAL'][$val1]+=$add;
      $agregation_array['TOTAL']['TOTAL']['TOTAL'][$val1]+=$add;
    }
  }
}


function stat_percent($column_name,$column_part,$column_total)
{
  global $agregation_array;
  global $val1_array;
  global $line;
  global $val2;
  global $val3;
  global $val4;

  $val1=$column_name;

  if($agregation_array[$val2][$val3][$val4][$column_total]!=0)
  {
    $val1_array[$val1]=1;
    $agregation_array[$val2][$val3][$val4][$val1]=round(100*$agregation_array[$val2][$val3][$val4][$column_part]/$agregation_array[$val2][$val3][$val4][$column_total]).'%';;
  }
}


function stat_calc($column_name,$column_formula,$column_format='%d')
{
  global $agregation_array;
  global $val1_array;
  global $line;
  global $val2;
  global $val3;
  global $val4;
  global $variable_array;

  global $fn_ret;
  $val1=$column_name;

  $fn_ret=eval_formula($column_formula,$variable_array);
  $val1_array[$val1]=1;
  if($fn_ret>0)
  $agregation_array[$val2][$val3][$val4][$val1]=sprintf($column_format,$fn_ret);

}




$agregation_array=array();
$val1_array=array();
$val2_array=array();
$val3_array=array();
$val4_array=array();

//$record_array=search($search.' '.$key2.' '.$key3.' '.$key4);
$record_array=$show_result_array;

//showtime();
while(list($tmp,$line)=each($record_array))
{
  {
    $val2=read($line,$key2);
    $val3=read($line,$key3);
    $val4=read($line,$key4);

    $val2_array[$val2]++;
    $val3_array[$val3]++;
    $val4_array[$val4]++;

    for($kk=1;$kk<10;$kk++)
    {
      $key1name=get('n'.$kk);
      $key1filter=get('e'.$kk);
      $key1formula=get('v'.$kk);

      if($key1formula=='sum')
        $key1formulaval=read($line,$key1name);
      else
        $key1formulaval=1;


      if(strpos($key1name,']'))
      {
        $key1filter=trim($key1filter);

        $value=$key1name;
        $pos=strpos('_'.$value,'[');
        $replacements=0;
        while($pos>0)
        {
          $variable=substr($value,$pos,strpos($value.']',']',$pos)-$pos);
          $vv=read($line,$variable);
          if(strlen($vv))
          {
            //echo 'VAR:'.$variable.'<br/>';
            $value=str_replace('['.$variable.']',$vv,$value);
            $key1filter=str_replace('['.$variable.']',$vv,$key1filter);
            $pos=strpos('_'.$value,'[');
            $replacements++;
            //$key1filter=$variable.'='.$vv;
          }
          else
          {
            $value=str_replace('['.$variable.']','',$value);
            //$value=trim(str_replace('  ',' ',$value));
            if($pos+1<strlen('_'.$value))
              $pos=strpos('_'.$value,'[',$pos+1);
            else
              $pos=0;
          }
        }
        if($replacements==0)
          $value='';
        $key1name=$value;
      }

      if($key1name)
      {
        stat_add($kk.'  '.$key1name,$key1filter,1,$key1formulaval);
      }
      //stat_add('50 Test Drive Duration','',1,read('Test Drive Duration Hours'));
      //stat_add('60 MOI '.read('MOI'),'');
    }
  }
}
//showtime('loop');

if(count($agregation_array))
{

  @ksort($val2_array);
  @ksort($val3_array);
  @ksort($val4_array);
  $val2_array['TOTAL']++;
  $val3_array['TOTAL']++;
  $val4_array['TOTAL']++;

  reset($val2_array);
  while(list($val2,$tmp)=each($val2_array))
  {
    if(count($agregation_array[$val2]))
    {
      reset($agregation_array[$val2]);
      while(list($val3,$tmp)=each($agregation_array[$val2]))
      {
        reset($agregation_array[$val2][$val3]);
        while(list($val4,$tmp)=each($agregation_array[$val2][$val3]))
        {
          reset($val1_array);
          while(list($val1,$tmp)=each($val1_array))
            $variable_array[substr($val1,3)]=$agregation_array[$val2][$val3][$val4][$val1];

          for($kk=1;$kk<10;$kk++)
          {
            $key1name=get('n'.$kk);
            $key1filter=get('e'.$kk);
            $key1formula=get('v'.$kk);

            if($key1name and $key1formula and substr($key1formula,0,1)=='=')
            {
              stat_calc($kk.'  '.$key1name,substr($key1formula,1));
              //echo '<br>'.$fn_ret.'---';
              //print_r($variable_array);
            }
          }
        }
      }
    }
  }
  //-------------------------------------------------------------------------------------------------------------












  @ksort($val1_array);
  $rowsshown=0;
  $cnt=0;

  echo '<div class="supergroup">';
    echo '<table>';
    echo '<tr class="header">';
      echo '<td class="label">';
      echo '</td>';
      echo '<td class="label">';
        $cnt_mark=1;
        echo('<input id="sw'.$cnt_mark.'" title="Select / unselect all" type="checkbox" onclick="check(this.checked,document.forms,\'sw'.$cnt_mark.'\',\'sw'.($cnt_mark+1).'\');" /> ');
      echo '</td>';
      echo '<td class="label">';
        myecho($key2);
      echo '</td>';
      echo '<td class="label">';
        myecho($key3);
      echo '</td>';
      echo '<td class="label">';
        myecho($key4);
      echo '</td>';
      echo '<td class="label">';
        //myecho('Action');
        for($ii=1;$ii<4;$ii++)
          if(get('a'.$ii.'_run'))
            echo(' '.get('a'.$ii));
      echo '</td>';

      reset($val1_array);
      while(list($val1,$tmp)=each($val1_array))
      {
        echo '<td class="label">';
        echo substr($val1,3);
        echo '</td>';
      }
    echo '</tr>';

    reset($val2_array);
    while(list($val2,$tmp)=each($val2_array))
    {
      $rowsshown3=0;
      reset($val3_array);
      while(list($val3,$tmp)=each($val3_array))
      {
        reset($val4_array);
        while(list($val4,$tmp)=each($val4_array))
        {
          //*
          if(
               ($val2!='TOTAL' and $val3!='TOTAL' and $val4!='TOTAL')
            or ($val2!='TOTAL' and $val3!='TOTAL' and $val4=='TOTAL' and $rowsshown3>1)
            or ($val2!='TOTAL' and $val3=='TOTAL' and $val4=='TOTAL' and $rowsshown2>1)
            or ($val2=='TOTAL' and $val3=='TOTAL' and $val4=='TOTAL')
          )
          //*/
          {
            if(isset($agregation_array[$val2][$val3][$val4]))
            {
              $cnt++;
              $rowsshown2++;
              $rowsshown3++;

              if(strpos('_'.$val2.$val3.$val4,'TOTAL'))
                echo '<tr class="header">';
              else
                echo '<tr class="record'.(($cnt-1)%2).'">';

              echo '<td class="show right">';
                echo $cnt.'.';
              echo '</td>';
              echo '<td class="show right">';
                if($val2!='TOTAL' and $val3!='TOTAL' and $val4!='TOTAL')
                  echo('<input name="odb_'.$cnt.'" type="checkbox"></input>');
              echo '</td>';
              echo '<td class="show">';
                if(strlen($val2)==8 and $val2>19900101 and $val2<30000101)
                  echo substr($val2,6,2).'.'.substr($val2,4,2).'.'.substr($val2,0,4);
                else
                  echo str_replace(' ','&nbsp;',$val2);
              echo '</td>';
              echo '<td class="show">';
                if(strlen($val3)==8 and $val3>19900101 and $val3<30000101)
                  echo substr($val3,6,2).'.'.substr($val3,4,2).'.'.substr($val3,0,4);
                else
                  echo str_replace(' ','&nbsp;',$val3);
              echo '</td>';
              echo '<td class="show">';
                if(strlen($val4)==8 and $val4>19900101 and $val4<30000101)
                  echo substr($val4,6,2).'.'.substr($val4,4,2).'.'.substr($val4,0,4);
                else
                  echo str_replace(' ','&nbsp;',$val4);
              echo '</td>';

              echo '<td class="show right">';
                if(get($cnt)) // actions running ----------------------------
                {
                  $action_result_array=array();

                  $run_name='';
                  for($ii=1;$ii<4;$ii++)
                  {
                    if(get('a'.$ii.'_run'))
                    {
                      $run_name=get('a'.$ii);

                      $drill_search=$search;
                      if(strlen($key2))
                        if($val2=='TOTAL')
                          $drill_search.='';
                        elseif(strpos('_'.$key2,'['))
                          $drill_search.=' '.$filter_array[$key2.'***'.$val2];
                        elseif(strlen($val2))
                          $drill_search.=' ['.$key2.'='.$val2.']';
                        elseif(strlen($key2))
                          $drill_search.=' -['.$key2.'=]';

                      if(strlen($key3))
                        if($val3=='TOTAL')
                          $drill_search.='';
                        elseif(strpos('_'.$key3,'['))
                            $drill_search.=' '.$filter_array[$key3.'***'.$val3];
                        elseif(strlen($val3))
                          $drill_search.=' ['.$key3.'='.$val3.']';
                        elseif(strlen($key3))
                          $drill_search.=' -['.$key3.'=]';

                      if(strlen($key4))
                        if($val4=='TOTAL')
                          $drill_search.='';
                        elseif(strpos('_'.$key4,'['))
                            $drill_search.=' '.$filter_array[$key4.'***'.$val4];
                        elseif(strlen($val4))
                          $drill_search.=' ['.$key4.'='.$val4.']';
                        elseif(strlen($key4))
                          $drill_search.=' -['.$key4.'=]';

                      $drill_search=trim($drill_search);
                      $action_result_array=search($drill_search);
                      $drill_search=urlencode($drill_search);

                      break;
                    }
                  }

                  $action_cnt=0;

                  reset($action_result_array);
                  while(list($key,$line)=each($action_result_array))
                  {
                    $action_cnt=0;
                    $changes=0;
                    $save_variable_array=line2array($line);

                    for($ii=1;$ii<4;$ii++)
                    {
                      if($run_name==get('a'.$ii))
                      {
                        $new_val=get('s'.$ii);

                        if($new_val=='TODAY')
                          $new_val=date('Ymd');

                        if($save_variable_array[trim(get('f'.$ii))]!=$new_val)
                        {
                          $save_variable_array[trim(get('f'.$ii))]=$new_val;
                          $changes=1;
                        }
                      }
                    }

                    if($changes)
                    {
                      $sys_comment=get('sys_comment');
                      if($sys_comment=='Your comment here...')
                        $sys_comment='Action '.get('a'.$ii);

                      $save_variable_array['sysComment']=$sys_comment;

                      if(check_access($save_variable_array['MyBag'])<2)
                      {
                        $owner_list=get_owner_list($save_variable_array['MyBag']);
                        if($owner_list)
                          myecho('Cannot save data to bag %1 owned by %2.',$save_variable_array['MyBag'],$owner_list);
                        else
                          myecho('Cannot save data to bag %1.',$save_variable_array['MyBag']);

                        echo ' <a href="index.php?odb_sys=request&odb_run=request&amp;odb_reqbag='.$save_variable_array['MyBag'].'&amp;odb_access=2&amp;odb_days=3">';
                        myecho('Request needed access now.');
                        echo '</a>';
                        echo '<br />';
                      }
                      else
                      {
                        save($save_variable_array);
                        $action_cnt++;
                      }
                    }
                  }

                  echo '<a href="index.php?odb_search='.$drill_search.'">';
                  echo $action_cnt;
                  echo '</a>';

                }
              echo '</td>';

              reset($val1_array);
              while(list($val1,$tmp)=each($val1_array))
              {

                echo '<td class="show right">';

                  $drill_search=$search;
                  if(strlen($key2))
                    if($val2=='TOTAL')
                      $drill_search.='';
                    elseif(strpos('_'.$key2,'['))
                      $drill_search.=' '.$filter_array[$key2.'***'.$val2];
                    elseif(strlen($val2))
                      $drill_search.=' ['.$key2.']=['.$val2.']';
                    elseif(strlen($key2))
                      $drill_search.=' -['.$key2.']';

                  if(strlen($key3))
                    if($val3=='TOTAL')
                      $drill_search.='';
                    elseif(strpos('_'.$key3,'['))
                        $drill_search.=' '.$filter_array[$key3.'***'.$val3];
                    elseif(strlen($val3))
                      $drill_search.=' ['.$key3.']=['.$val3.']';
                    elseif(strlen($key3))
                      $drill_search.=' -['.$key3.']';

                  if(strlen($key4))
                    if($val4=='TOTAL')
                      $drill_search.='';
                    elseif(strpos('_'.$key4,'['))
                        $drill_search.=' '.$filter_array[$key4.'***'.$val4];
                    elseif(strlen($val4))
                      $drill_search.=' ['.$key4.']=['.$val4.']';
                    elseif(strlen($key4))
                      $drill_search.=' -['.$key4.']';

                  if(strlen($val1_array[$val1])) $drill_search.=' ['.$val1_array[$val1].']';
                  $drill_search=trim($drill_search);
                  $drill_search=urlencode($drill_search);

                  if($val2!='TOTAL' and $val3!='TOTAL' and $val4!='TOTAL')
                  {
                    echo '<a href="index.php?odb_search='.$drill_search.'">';
                    echo $agregation_array[$val2][$val3][$val4][$val1];
                    echo '</a>';
                  }
                  else
                    echo $agregation_array[$val2][$val3][$val4][$val1];
                  //echo $val1.$val2.$val3.$val4;
                echo '</td>';
              }
            }
          }

          if($val4=='TOTAL') $rowsshown3=0;
          if($val3=='TOTAL' and $val4=='TOTAL') $rowsshown2=0;

        }
      }
      echo '</tr>';
    }
    echo '</table>';
  echo '</div>';

  echo '<div style="width:100%; text-align:right;">';
    echo '<div style="margin:10px;">';
    $action_names=array();
    for($ii=1;$ii<4;$ii++)
    {
      echo '<td class="input">';
        $show_name='a'.$ii;
        $show_value=get('a'.$ii);
        if($show_value and !isset($action_names[$show_value]))
        {
          echo('<input type="submit" class="submit" name="'.$show_name.'_run" value="'.myecho($show_value,'RETURN').'" />');
          $action_names[$show_value]=1;
        }
      echo '</td>';
    }
    echo('</div>');
  echo('</div></form>');
}
else
{
  echo '<br /><h2>';
  myecho('No data found');
  echo '</h2><br /><br /><br />';
}

?>
Return current item: OpenBizMap