Location: PHPKode > projects > MyPhpMoney > myphpmoney_2.0/public_html/graph/general.php
<?php
/**
 * $Id: general.php 418 2007-05-17 17:29:45Z hpfn $
 *
 * Author     : courou&#64;users.sourceforge.net
 * Website    : http://allreponse.ath.cx
 *
 * Support    : http://sourceforge.net/projects/myphpmoney/
 * CVS        : http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/myphpmoney/
 */

if (!defined('__DOC__')) { define('__DOC__', 'YES');

/**
 * INCLUDE FILE
 */
     require_once '../config/settings.inc.php';

/**
 * ENTER IN THE SESSION OR BUILD THE LOGIN FORM
 */
     if (SQL_VerifSession() && isset($_GET['option'])) {

/**
 * DEFINE VARIABLE GLOBALS
 */
      $s_active      = '';       ## used by class_graph file
      $acct_cal      = array();  ## used by class_graph file
      $active        = array();  ## used by class_graph file
      $outgoing      = array();  ## used by class_graph file
      $incoming      = array();  ## used by class_graph file
      $sold          = array();  ## used by class_graph file
      $place         = array();  ## used by class_graph file
      $act           = array();  ## used by class_graph file
      $opening       = array();  ## used by class_graph file

/**
 * PREPARE THE VALUE
 */
if ($_GET['option'] == '' || $_GET['option'] == 0 || $_GET['option'] >= 19) $_GET['option'] = 1;
if (($_GET['option'] >= 1) && ($_GET['option'] <= 6)) {
     $req  = "SELECT ".$_MPM['table'][2].".ACCOUNT, SUM(".$_MPM['table'][1].".IMP - ".$_MPM['table'][1].".SOUTT) as t1 ";
     $req .= "FROM ".$_MPM['table'][1].", ".$_MPM['table'][2]." WHERE ".$_MPM['table'][1].".TEMPID=1 ";
     $req .= "AND TO_DAYS(now()) >= TO_DAYS(".$_MPM['table'][1].".DATES) AND ";
     $req .= "".$_MPM['table'][1].".ACCOUNT=".$_MPM['table'][2].".ACCOUNTID ";
     if ($_GET['option'] == 3 || $_GET['option'] == 4) {
     $req .= "AND ".$_MPM['table'][1].".CAT=2 ";
     }
     $req .= "AND ".$_MPM['table'][1].".USERID='$sess_pid' GROUP BY ACCOUNT ";

   $db->query($req);
   if ($db->num_rows() > 0) {
      while ($db->next_record()) {
        $acct_cal[] .= $tools->Reduit_chaine($db->f('ACCOUNT'),__LENGTH_ACCOUNT__,0);
        $dep = $db->f('t1');
        $euro_dep = $dep * $_MPM['lang_euro'];

               switch($_GET['option']) {
                     case 1 : $active[]  .= $dep;        break;
                     case 2 : $active[]  .= $euro_dep;   break;
                     case 3 : $opening[] .= $dep;        break;
                     case 4 : $opening[] .= $euro_dep;   break;
                     case 5 : $s_active  += $dep;        break;
                     case 6 : $s_active  += $euro_dep;   break;
               }
      } ## end of while ($db->next_record())
   } ## end of if ($db->num_rows() > 0)
} ## end of if (($_GET['option'] >= 1) && ($_GET['option'] <= 6))
if (($_GET['option'] >= 7) && ($_GET['option'] <= 12)) {
     $req  = "SELECT ".$_MPM['table'][2].".ACCOUNT, SUM(".$_MPM['table'][1].".IMP) as t2, ";
     $req .= "SUM(".$_MPM['table'][1].".SOUTT) as t1 ,SUM(".$_MPM['table'][1].".IMP - ".$_MPM['table'][1].".SOUTT) as t3 ";
     $req .= "FROM ".$_MPM['table'][1].", ".$_MPM['table'][2]." WHERE ".$_MPM['table'][1].".TEMPID=1 AND TO_DAYS(now())-TO_DAYS(DATES) < 30 AND ";
     $req .= "".$_MPM['table'][1].".ACCOUNT=".$_MPM['table'][2].".ACCOUNTID AND ".$_MPM['table'][1].".USERID='$sess_pid' GROUP BY ACCOUNT ";
     $db->query("$req");
     if ($db->num_rows() > 0) {
          while ($db->next_record()) {

               $t1 = $db->f('t1'); if ($t1 == '') $t1 = 0;
               $t2 = $db->f('t2'); if ($t2 == '') $t2 = 0;
               $t3 = $db->f('t3'); if ($t3 == '') $t3 = 0;

               $acct_cal[] .= $tools->Reduit_chaine($db->f('ACCOUNT'),__LENGTH_ACCOUNT__,0);

               switch($_GET['option']) {
                     case 7 :   $outgoing[] .= -($t1);                                     break;
                     case 8 :   $outgoing[] .= -($t1 * $_MPM['lang_euro']);                break;
                     case 9 :   $incoming[] .= $t2;                                        break;
                     case 10 :  $incoming[] .= $t2 * $_MPM['lang_euro'];                   break;
                     case 11 :  $incoming[] .= $t2; $outgoing[] .= -($t1); $sold[] .= $t3; break;
                     case 12 :  $incoming[] .= $t2 * $_MPM['lang_euro']; $outgoing[] .= -($t1 * $_MPM['lang_euro']); $sold[] .= $t3 * $_MPM['lang_euro']; break;
               }
          }
     } else {
                $acct_cal[] .= '';
                $outgoing[] .= 0;
                $incoming[] .= 0;
                $sold[]     .= 0;
     } ## end of if (!$db->num_rows() > 0)
} ## end of if (($_GET['option'] >= 7) && ($_GET['option'] <= 12))
if (($_GET['option'] >= 13) && ($_GET['option'] <= 18)) {
     $req  = "SELECT ".$_MPM['table'][0].".CAT, ".$_MPM['table'][4].".THIRD,".$_MPM['table'][2].".ACCOUNT, ";
     $req .= "SUM(".$_MPM['table'][1].".SOUTT) AS t1, SUM(".$_MPM['table'][1].".IMP) AS t2, SUM(".$_MPM['table'][1].".IMP) - SUM(".$_MPM['table'][1].".SOUTT) as t3 ";
     $req .= "FROM ".$_MPM['table'][1].",".$_MPM['table'][2].", ".$_MPM['table'][0]." , ".$_MPM['table'][4]." ";
     $req .= "WHERE ".$_MPM['table'][1].".TEMPID=1 AND TO_DAYS(now())-TO_DAYS(DATES) < 30 AND ".$_MPM['table'][1].".USERID='$sess_pid' AND ";
     $req .= "".$_MPM['table'][1].".ACCOUNT=".$_MPM['table'][2].".ACCOUNTID AND ".$_MPM['table'][1].".CAT=".$_MPM['table'][0].".CATID ";
     $req .= "AND ".$_MPM['table'][1].".THIRD=".$_MPM['table'][4].".THIRDID GROUP BY CAT ORDER BY ACCOUNT";
     $db->query("$req");
     if ($db->num_rows() > 0) {
          while ($db->next_record()) {

                $t1 = $db->f('t1');
                $t2 = $db->f('t2');
                $t3 = $db->f('t3');
                $acct_cal[] .= $tools->Reduit_chaine($db->f('CAT'),__LENGTH_ACCOUNT__,0);

               switch($_GET['option']) {
                     case 13 :  $outgoing[] .= -($t1);                                     break;
                     case 14 :  $outgoing[] .= -($t1 * $_MPM['lang_euro']);                break;
                     case 15 :  $incoming[] .= $t2;                                        break;
                     case 16 :  $incoming[] .= $t2 * $_MPM['lang_euro'];                   break;
                     case 17 :  $outgoing[] .= -($t1); $incoming[] .= $t2; $sold[] .= $t3; break;
                     case 18 :  $outgoing[] .= -($t1 * $_MPM['lang_euro']);$incoming[] .= $t2 * $_MPM['lang_euro']; $sold[] .= $t3 * $_MPM['lang_euro'];   break;
               }
          }
     } else {
                $acct_cal[] .= '';
                $outgoing[] .= 0;
                $incoming[] .= 0;
                $sold[]     .= 0;
     } ## end of if (!$db->num_rows() > 0)
} ## end of if (($_GET['option'] >= 13) && ($_GET['option'] <= 18))

/**
 * INSTANCE THE GRAPH CLASS
 */
     require_once $_MPM['dir_class'].''.$_MPM['class_graph'];
     $graph = new graph(__IMG_GRAPH_W_WIDTH__,__IMG_GRAPH_H_HEIGHT__);
     $graph->parameter['path_to_fonts'] = str_replace(basename($_MPM['dir_graph']),'',dirname(__FILE__)).''.$_MPM['dir_font'];

     ## The Font Police
     $graph->parameter['title_font']      = __FONT_GRAPH__;
     $graph->parameter['label_font']      = __FONT_GRAPH__;
     $graph->parameter['axis_font']       = __FONT_GRAPH__;
     $graph->parameter['legend_font']     = __FONT_GRAPH__;

     ## The Size
     $graph->parameter['label_size']      = __SIZE_GRAPH__;
     $graph->parameter['title_size']      = __SIZE_GRAPH__;
     $graph->parameter['axis_size']       = __SIZE_GRAPH__;
     $graph->parameter['legend_padding']  = __SIZE_GRAPH__;
     $graph->parameter['legend_size']     = __SIZE_GRAPH__;

     $times    = $_MPM['date_gettime']['mday'].' '.$_VAR['THIS_MONTH'][$_MPM['date_gettime']['mon'] - 1].' '.$_MPM['date_gettime']['year'];
     $nbr_cols = bcadd((sizeof($acct_cal) * 2),1);
     $place[] .= $_VAR['LANG_HOME_GRAPH_9']." (".$tools->formatage($s_active).")";
     $act[]   .= $s_active;

/**
 * DISPLAY THE TEXT FOR THE GRAPH
 */
     switch($_GET['option']) {
           case 1 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][1]." ".$_VAR['LANG_HOME_GRAPH_8']." $times";
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][1];
                    $letter  = 'X';
                    $valeur  = $active;
                    $color   = __COLOR_GRAPHIQUE__;
      break;
           case 2 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][1]." ".$_VAR['LANG_HOME_GRAPH_8']." $times";
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][1];
                    $letter  = 'X';
                    $valeur  = $active;
                    $color   = __COLOR_GRAPHIQUE__;
      break;
           case 3 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][2];
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][2];
                    $letter  = 'Y';
                    $valeur  = $opening;
                    $color   = __COLOR_GRAPHIQUE_1__;
      break;
           case 4 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][2];
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][2];
                    $letter  = 'Y';
                    $valeur  = $opening;
                    $color   = __COLOR_GRAPHIQUE_1__;
      break;
           case 5 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][3]." ".$_VAR['LANG_HOME_GRAPH_8']." $times";
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][3];
                    $letter  = 'Z';
                    $valeur  = $act;
                    $color   = __COLOR_GRAPHIQUE_2__;
      break;
           case 6 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][3]." ".$_VAR['LANG_HOME_GRAPH_8']." $times";
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][3];
                    $letter  = 'Z';
                    $valeur  = $act;
                    $color   = __COLOR_GRAPHIQUE_2__;
      break;
           case 7 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][4];
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][4];
                    $letter  = 'X';
                    $valeur  = $outgoing;
                    $color   = __COLOR_GRAPHIQUE_3__;
      break;
           case 8 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][4];
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][4];
                    $letter  = 'X';
                    $valeur  = $outgoing;
                    $color   = __COLOR_GRAPHIQUE_3__;
      break;
           case 9 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][5];
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][5];
                    $letter  = 'Y';
                    $valeur  = $incoming;
                    $color   = __COLOR_GRAPHIQUE__;
      break;
           case 10 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][5];
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][5];
                    $letter  = 'Y';
                    $valeur  = $incoming;
                    $color   = __COLOR_GRAPHIQUE__;
           case 11 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][6];
                    $legend1 = $_VAR['SELECT_GRAPHIQUE'][4];
                    $letter1 = 'X';
                    $valeur1 = $outgoing;
                    $color1  = __COLOR_GRAPHIQUE_3__;

                    $legend2 = $_VAR['SELECT_GRAPHIQUE'][5];
                    $letter2 = 'Y';
                    $valeur2 = $incoming;
                    $color2  = __COLOR_GRAPHIQUE__;

                    $legend3 = $_VAR['SELECT_GRAPHIQUE'][6];
                    $letter3 = 'Z';
                    $valeur3 = $sold;
                    $color3  = __COLOR_GRAPHIQUE_1__;
      break;
           case 12 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][6];
                    $legend1 = $_VAR['SELECT_GRAPHIQUE'][4];
                    $letter1 = 'X';
                    $valeur1 = $outgoing;
                    $color1  = __COLOR_GRAPHIQUE_3__;

                    $legend2 = $_VAR['SELECT_GRAPHIQUE'][5];
                    $letter2 = 'Y';
                    $valeur2 = $incoming;
                    $color2  = __COLOR_GRAPHIQUE__;

                    $legend3 = $_VAR['SELECT_GRAPHIQUE'][6];
                    $letter3 = 'Z';
                    $valeur3 = $sold;
                    $color3  = __COLOR_GRAPHIQUE_1__;
      break;
          case 13 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][7];
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][7];
                    $letter  = 'X';
                    $valeur  = $outgoing;
                    $color   = __COLOR_GRAPHIQUE_3__;
      break;
          case 14 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][7];
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][7];
                    $letter  = 'X';
                    $valeur  = $outgoing;
                    $color   = __COLOR_GRAPHIQUE_3__;
      break;
           case 15 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][8];
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][8];
                    $letter  = 'Y';
                    $valeur  = $incoming;
                    $color   = __COLOR_GRAPHIQUE__;
      break;
           case 16 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][8];
                    $legend  = $_VAR['SELECT_GRAPHIQUE'][8];
                    $letter  = 'Y';
                    $valeur  = $incoming;
                    $color   = __COLOR_GRAPHIQUE__;
      break;
           case 17 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][9];
                    $legend1 = $_VAR['SELECT_GRAPHIQUE'][7];
                    $letter1 = 'X';
                    $valeur1 = $outgoing;
                    $color1  = __COLOR_GRAPHIQUE_3__;

                    $legend2 = $_VAR['SELECT_GRAPHIQUE'][8];
                    $letter2 = 'Y';
                    $valeur2 = $incoming;
                    $color2  = __COLOR_GRAPHIQUE__;

                    $legend3 = $_VAR['SELECT_GRAPHIQUE'][9];
                    $letter3 = 'Z';
                    $valeur3 = $sold;
                    $color3  = __COLOR_GRAPHIQUE_1__;
      break;
           case 18 :
                    $title   = $_VAR['SELECT_GRAPHIQUE'][9];
                    $legend1 = $_VAR['SELECT_GRAPHIQUE'][7];
                    $letter1 = 'X';
                    $valeur1 = $outgoing;
                    $color1  = __COLOR_GRAPHIQUE_3__;

                    $legend2 = $_VAR['SELECT_GRAPHIQUE'][8];
                    $letter2 = 'Y';
                    $valeur2 = $incoming;
                    $color2  = __COLOR_GRAPHIQUE__;

                    $legend3 = $_VAR['SELECT_GRAPHIQUE'][9];
                    $letter3 = 'Z';
                    $valeur3 = $sold;
                    $color3  = __COLOR_GRAPHIQUE_1__;
      break;
     }

    if (($_GET['option'] == 11 || $_GET['option'] == 12) || ($_GET['option'] == 17 || $_GET['option'] == 18))  {
          $graph->y_format[$letter1]             = array('bar'=>'fill','shadow_offset'=>2);
          $graph->y_format[$letter2]             = array('bar'=>'fill','shadow_offset'=>2);
          $graph->y_format[$letter3]             = array('bar'=>'fill','shadow_offset'=>2);
          $graph->y_format[$letter1]['colour']   = $color1;
          $graph->y_format[$letter2]['colour']   = $color2;
          $graph->y_format[$letter3]['colour']   = $color3;
          $graph->y_format[$letter1]['legend']   = $legend1;
          $graph->y_format[$letter2]['legend']   = $legend2;
          $graph->y_format[$letter3]['legend']   = $legend3;
          $graph->y_data[$letter1]               = $valeur1;
          $graph->y_data[$letter2]               = $valeur2;
          $graph->y_data[$letter3]               = $valeur3;
          $graph->y_order                        = array($letter1,$letter2,$letter3);
    } else {
          $graph->y_format[$letter]              = array('bar'=>'fill','shadow_offset'=>2);
          $graph->y_format[$letter]['colour']    = $color;
          $graph->y_format[$letter]['legend']    = $legend;
          $graph->y_data[$letter]                = $valeur;
          $graph->y_order                        = array($letter);
    }
          $graph->parameter['y_label_left']      = ($_GET['option'] % 2 != 0)
                                                      ? $_VAR['LANG_HOME_GRAPH_7'].' '.$_VAR['IMG_TXT_EUROS']
                                                      : $_VAR['LANG_HOME_GRAPH_7'].' '.$_MPM['lang_money_country'];
          $graph->x_data                         = $_GET['option'] == 5 || $_GET['option'] == 6 ? $place : $acct_cal;
          $graph->parameter['x_axis_angle']      = $_GET['option'] == 5 || $_GET['option'] == 6 ? 0 : 30;
          $graph->parameter['title']             = $title;
          $graph->parameter['zero_axis']         = 'black';
          $graph->parameter['outer_background']  = 'money';
          $graph->parameter['bar_size']          = "0.$nbr_cols";
          $graph->parameter['bar_spacing']       = 5;
          $graph->parameter['inner_border_type'] = 'y-left';
          $graph->parameter['y_axis_gridlines']  = 11;
          $graph->parameter['y_min_left']        = -5;
          $graph->parameter['y_max_left']        = 5;
          $graph->parameter['y_decimal_left']    = 0;
          $graph->parameter['y_label_rot']       = 60;
          $graph->parameter['y_resolution_left'] = 3;
          $graph->parameter['legend']            = 'outside-right';
          $graph->parameter['legend_offset']     = 2;
          $graph->draw();
     } ## end if (SQL_VerifSession())

/**
 * CLOSE THE SESSION
 */
       page_close();

  } ## end of __DOC__
Return current item: MyPhpMoney