Help...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fruityfreak
    New Member
    • Jun 2007
    • 24

    Help...

    What languages is this in???

    <?php
    session_start() ;
    require('db.php ');

    mysql_connect(M ACHINE, USER, '');
    mysql_select_db (DBNAME);

    //Obtaining session variables (From do_login.php)
    $uname = $_SESSION['username'];
    $pwd =$_SESSION['pwd'];
    $outletid = $_SESSION['outletid'];
    $role = $_SESSION['role'];
    $userid = $_SESSION['userid'];

    $month = $_POST['month'];
    $year = $_POST['year'];

    class easyChart {
    var $title;
    var $width;
    var $height;
    var $bartitle;
    var $barheight;
    var $barwidth;
    var $background;
    var $multiply;
    var $spacebar;
    var $leftspace;
    var $rightspace;
    var $upspace;
    var $bottomspace;
    var $leftlegend;
    var $linecolor;
    var $barcolor;
    var $titlecolor;
    var $legendcolor;
    var $barinfocolor;

    function easyChart () {
    $this->title = "Chart Title";
    $this->background = Array(153,204,1 02);
    $this->linecolor = Array(240,240,2 40);
    $this->barcolor = Array(255,255,1 53);
    $this->titlecolor = Array(111,166,5 5);
    $this->legendcolor = Array(0,0,0);
    $this->barinfocolor = Array(0,0,0);
    $this->width = 600;
    $this->height = 500;
    $this->barwidth = 20;
    $this->leftspace = 75;
    $this->rightspace = 25;
    $this->upspace = 50;
    $this->bottomspace = 50;
    $this->leftlegend = 10;
    $this->chartlegend = "";
    }

    function setTitleColor ($color) {
    $this->titlecolor = explode(",",$co lor);
    }
    function setLegendColor ($color) {
    $this->legendcolor = explode(",",$co lor);
    }
    function setBarInfoColor ($color) {
    $this->barinfocolor = explode(",",$co lor);
    }
    function setBarColor ($color) {
    $this->barcolor = explode(",",$co lor);
    }
    function setLineColor ($color) {
    $this->linecolor = explode(",",$co lor);
    }
    function setLeftLegend ($leftlegend) {
    $this->leftlegend = $leftlegend;
    }
    function setLeftSpace ($leftspace) {
    $this->leftspace = $leftspace;
    }
    function setRightSpace ($rightspace) {
    $this->rightspace = $rightspace;
    }
    function setTitle ($title) {
    $this->title = $title;
    }
    function setBackground ($color) {
    $this->background = explode (",", $color);
    }
    function setWidth ($width) {
    $this->width = $width;
    }
    function setHeight ($height) {
    $this->height = $height;
    }
    function setBarWidth ($barwidth) {
    $this->barwidth = $barwidth;
    }
    function addBar ($bartitle, $barheight) {
    $this->bartitle[] = $bartitle;
    $this->barheight[] = $barheight;
    }
    function prepare() {
    $this->chartlegend .= "";
    $arr = $this->barheight;
    sort ($arr);
    reset ($arr);
    $this->highestvalue = end($arr);
    $this->valueincriemen t = $this->highestvalue / $this->leftlegend;
    $this->multiply = ( ($this->height-($this->upspace + $this->bottomspace) ) / $this->highestvalue );
    $this->spacebar = ( ($this->width - ($this->leftspace + $this->rightspace)) - ($this->barwidth * count($arr) ) ) / (count($arr)+1) ;
    $this->legendspace = ($this->height - ($this->upspace+$thi s->bottomspace) ) / $this->leftlegend;
    if ($this->barwidth * count($this->barheight) > ($this->width-($this->upspace+$thi s->bottomspace) )) $err = "Bar width is to large";
    if ($err!="") {
    print $err;
    exit;
    }
    }
    function generateChart() {
    $im = ImageCreate($th is->width,$this->height);
    $white = ImageColorAlloc ate($im,255,255 ,255);
    $background = ImageColorAlloc ate($im,$this->background[0],$this->background[1],$this->background[2]);
    $black = ImageColorAlloc ate($im,0,0,0);
    $gray = ImageColorAlloc ate($im,100,100 ,100);
    $linecolor = ImageColorAlloc ate($im,$this->linecolor[0],$this->linecolor[1],$this->linecolor[2]);
    $barcolor = ImageColorAlloc ate($im,$this->barcolor[0],$this->barcolor[1],$this->barcolor[2]);
    $titlecolor = ImageColorAlloc ate($im,$this->titlecolor[0],$this->titlecolor[1],$this->titlecolor[2]);
    $legendcolor = ImageColorAlloc ate($im,$this->legendcolor[0],$this->legendcolor[1],$this->legendcolor[2]);
    $barinfocolor = ImageColorAlloc ate($im,$this->barinfocolor[0],$this->barinfocolor[1],$this->barinfocolor[2]);
    @ImageFilledRec tangle($im,0,25 ,$this->width,$this->height-15,$background) ;
    @ImageFilledRec tangle($im,1,26 ,$this->width-2,$this->height-16,$white);
    @ImageFilledRec tangle($im,2,27 ,$this->width-3,$this->height-17,$background) ;
    @ImageFilledRec tangle($im,$thi s->leftspace,$thi s->upspace-10,$this->width-$this->rightspace,$th is->height-($this->bottomspace-20),$white);
    $titlewidth = strlen($this->title) * ImageFontWidth( 5);
    $titlexpos = ($this->width - $titlewidth)/2;
    @ImageString ($im, 5, $titlexpos, 5, $this->title, $titlecolor);
    @ImageString ($im, 1, 0, $this->height - 10, base64_decode($ this->chartlegend."" ), $black);
    for($i=0;$i<=$t his->leftlegend;$i+ +){
    $legendx = 5;
    $legendy = $this->upspace + ($this->legendspace * $i) - 6;
    @ImageString($i m, 2, $legendx, $legendy, $this->highestvalue-($this->valueincriemen t*$i), $legendcolor);
    @ImageLine ($im, $this->leftspace, $legendy+6, $this->width - $this->rightspace, $legendy+6, $linecolor);
    }
    for($i=0;$i<cou nt($this->barheight);$i+ +){
    $j=$i+1;
    $x1 = ($j * $this->spacebar) + ($i * $this->barwidth) + $this->leftspace;
    $y1 = $this->height - ($this->barheight[$i]*$this->multiply) - $this->upspace;
    $x2 = $x1 + $this->barwidth;
    $y2 = $this->height - $this->bottomspace;
    $bartitlewidth = strlen($this->bartitle[$i]) * ImageFontWidth( 2);
    $centerofbar = $x1 + ($this->barwidth / 2);
    $bartitlex = $centerofbar - ($bartitlewidth/2);
    $bartitley = $y2 + 5;
    @ImageFilledRec tangle($im, $x1, $y1, $x2, $y2, $barcolor);
    @ImageString($i m, 2, $bartitlex, $bartitley, $this->bartitle[$i], $barinfocolor);
    }
    @ImageJPEG($im) ;
    @ImageDestroy($ im);
    }
    };

    // HERE IS THE EXAMPLE TO USE THE CHART CLASS
    $chart = new easyChart(); // Object initialized
    $chart->setTitle("Stoc k Item Graph"); // Title of Chart
    $chart->setBackground( "153,204,10 2"); // Background of chart [opt]
    $chart->setLineColor(" 225,225,225"); // Line color separator [opt]
    $chart->setBarColor("2 55,255,153"); // Bar color [opt]
    $chart->setTitleColor( "111,166,55 "); // Color Title [opt]
    $chart->setLegendColor ("0,0,0"); // Legend Color [opt]
    $chart->setBarInfoColo r("0,0,0"); // Bar Info Color [opt]
    $chart->setWidth(800 ); // Width of Chart
    $chart->setHeight(500) ; // Height of Chart
    $chart->setBarWidth(20 ); // Bar Width
    $chart->setLeftSpace(5 5); // Left Space
    $chart->setRightSpace( 25); // Right Space
    $chart->setLeftLegend( 10); // Left Legend

    $sql="SELECT SUM(quantity), SUM(amount), category FROM invoice WHERE category='Botto ms - Shorts' AND month = '$month' AND year = '$year' GROUP BY category";
    $results=mysql_ query($sql) or die(mysql_error ());
    $rows = mysql_fetch_arr ay($results);
    $shorts = $rows['SUM(quantity)'];

    $sql="SELECT SUM(quantity), SUM(amount), category FROM invoice WHERE category='Botto ms - Skirts' AND month = '$month' AND year = '$year' GROUP BY category";
    $results=mysql_ query($sql) or die(mysql_error ());
    $rows = mysql_fetch_arr ay($results);
    $skirts = $rows['SUM(quantity)'];

    $sql="SELECT SUM(quantity), SUM(amount), category FROM invoice WHERE category='Outer wear - Coats' AND month = '$month' AND year = '$year' GROUP BY category";
    $results=mysql_ query($sql) or die(mysql_error ());
    $rows = mysql_fetch_arr ay($results);
    $coats = $rows['SUM(quantity)'];

    $sql="SELECT SUM(quantity), SUM(amount), category FROM invoice WHERE category='Tops - Blouse' AND month = '$month' AND year = '$year' GROUP BY category";
    $results=mysql_ query($sql) or die(mysql_error ());
    $rows = mysql_fetch_arr ay($results);
    $blouse = $rows['SUM(quantity)'];

    $sql="SELECT SUM(quantity), SUM(amount), category FROM invoice WHERE category='Other s' AND month = '$month' AND year = '$year' GROUP BY category";
    $results=mysql_ query($sql) or die(mysql_error ());
    $rows = mysql_fetch_arr ay($results);
    $others = $rows['SUM(quantity)'];

    $chart->addBar("Bottom s - Shorts",$shorts ); // Sample content of chart
    $chart->addBar("Bottom s - Skirts",$skirts );
    $chart->addBar("Outerw ear - Coats",$coats);
    $chart->addBar("Tops - Blouse",$blouse );
    $chart->addBar("Others ",$others);


    $chart->prepare(); // Chart Preparation
    $chart->generateChart( ); // Chart Generation
    ?>
  • nitinpatel1117
    New Member
    • Jun 2007
    • 111

    #2
    hi, it looks like PHP

    It usess OO (Object oriented) programing.


    so if you've never seen or done any OOD code before, then i suppose this will look unfamiliar.

    Comment

    • fruityfreak
      New Member
      • Jun 2007
      • 24

      #3
      I've done a bit of it before... But I've never came across something like this... (A mixture of PHP and the bold part codes) Mmm... Any idea how can I label my x-axis and y-axis???

      Comment

      • mwasif
        Recognized Expert Contributor
        • Jul 2006
        • 802

        #4
        It will be easy for others to read your code if you can use proper coding tags. Read the guidelines to use CODE tags.

        Comment

        • fruityfreak
          New Member
          • Jun 2007
          • 24

          #5
          sorry...

          [code=php]

          <?php
          session_start() ;
          require('db.php ');

          mysql_connect(M ACHINE, USER, '');
          mysql_select_db (DBNAME);

          //Obtaining session variables (From do_login.php)
          $uname = $_SESSION['username'];
          $pwd =$_SESSION['pwd'];
          $outletid = $_SESSION['outletid'];
          $role = $_SESSION['role'];
          $userid = $_SESSION['userid'];

          $month = $_POST['month'];
          $year = $_POST['year'];

          class easyChart {
          var $title;
          var $width;
          var $height;
          var $bartitle;
          var $barheight;
          var $barwidth;
          var $background;
          var $multiply;
          var $spacebar;
          var $leftspace;
          var $rightspace;
          var $upspace;
          var $bottomspace;
          var $leftlegend;
          var $linecolor;
          var $barcolor;
          var $titlecolor;
          var $legendcolor;
          var $barinfocolor;

          function easyChart () {
          $this->title = "Chart Title";
          $this->background = Array(153,204,1 02);
          $this->linecolor = Array(240,240,2 40);
          $this->barcolor = Array(255,255,1 53);
          $this->titlecolor = Array(111,166,5 5);
          $this->legendcolor = Array(0,0,0);
          $this->barinfocolor = Array(0,0,0);
          $this->width = 600;
          $this->height = 500;
          $this->barwidth = 20;
          $this->leftspace = 75;
          $this->rightspace = 25;
          $this->upspace = 50;
          $this->bottomspace = 50;
          $this->leftlegend = 10;
          $this->chartlegend = "";
          }

          function setTitleColor ($color) {
          $this->titlecolor = explode(",",$co lor);
          }
          function setLegendColor ($color) {
          $this->legendcolor = explode(",",$co lor);
          }
          function setBarInfoColor ($color) {
          $this->barinfocolor = explode(",",$co lor);
          }
          function setBarColor ($color) {
          $this->barcolor = explode(",",$co lor);
          }
          function setLineColor ($color) {
          $this->linecolor = explode(",",$co lor);
          }
          function setLeftLegend ($leftlegend) {
          $this->leftlegend = $leftlegend;
          }
          function setLeftSpace ($leftspace) {
          $this->leftspace = $leftspace;
          }
          function setRightSpace ($rightspace) {
          $this->rightspace = $rightspace;
          }
          function setTitle ($title) {
          $this->title = $title;
          }
          function setBackground ($color) {
          $this->background = explode (",", $color);
          }
          function setWidth ($width) {
          $this->width = $width;
          }
          function setHeight ($height) {
          $this->height = $height;
          }
          function setBarWidth ($barwidth) {
          $this->barwidth = $barwidth;
          }
          function addBar ($bartitle, $barheight) {
          $this->bartitle[] = $bartitle;
          $this->barheight[] = $barheight;
          }
          function prepare() {
          $this->chartlegend .= "";
          $arr = $this->barheight;
          sort ($arr);
          reset ($arr);
          $this->highestvalue = end($arr);
          $this->valueincriemen t = $this->highestvalue / $this->leftlegend;
          $this->multiply = ( ($this->height-($this->upspace + $this->bottomspace) ) / $this->highestvalue );
          $this->spacebar = ( ($this->width - ($this->leftspace + $this->rightspace)) - ($this->barwidth * count($arr) ) ) / (count($arr)+1) ;
          $this->legendspace = ($this->height - ($this->upspace+$thi s->bottomspace) ) / $this->leftlegend;
          if ($this->barwidth * count($this->barheight) > ($this->width-($this->upspace+$thi s->bottomspace) )) $err = "Bar width is to large";
          if ($err!="") {
          print $err;
          exit;
          }
          }
          function generateChart() {
          $im = ImageCreate($th is->width,$this->height);
          $white = ImageColorAlloc ate($im,255,255 ,255);
          $background = ImageColorAlloc ate($im,$this->background[0],$this->background[1],$this->background[2]);
          $black = ImageColorAlloc ate($im,0,0,0);
          $gray = ImageColorAlloc ate($im,100,100 ,100);
          $linecolor = ImageColorAlloc ate($im,$this->linecolor[0],$this->linecolor[1],$this->linecolor[2]);
          $barcolor = ImageColorAlloc ate($im,$this->barcolor[0],$this->barcolor[1],$this->barcolor[2]);
          $titlecolor = ImageColorAlloc ate($im,$this->titlecolor[0],$this->titlecolor[1],$this->titlecolor[2]);
          $legendcolor = ImageColorAlloc ate($im,$this->legendcolor[0],$this->legendcolor[1],$this->legendcolor[2]);
          $barinfocolor = ImageColorAlloc ate($im,$this->barinfocolor[0],$this->barinfocolor[1],$this->barinfocolor[2]);
          @ImageFilledRec tangle($im,0,25 ,$this->width,$this->height-15,$background) ;
          @ImageFilledRec tangle($im,1,26 ,$this->width-2,$this->height-16,$white);
          @ImageFilledRec tangle($im,2,27 ,$this->width-3,$this->height-17,$background) ;
          @ImageFilledRec tangle($im,$thi s->leftspace,$thi s->upspace-10,$this->width-$this->rightspace,$th is->height-($this->bottomspace-20),$white);
          $titlewidth = strlen($this->title) * ImageFontWidth( 5);
          $titlexpos = ($this->width - $titlewidth)/2;
          @ImageString ($im, 5, $titlexpos, 5, $this->title, $titlecolor);
          @ImageString ($im, 1, 0, $this->height - 10, base64_decode($ this->chartlegend."" ), $black);
          for($i=0;$i<=$t his->leftlegend;$i+ +){
          $legendx = 5;
          $legendy = $this->upspace + ($this->legendspace * $i) - 6;
          @ImageString($i m, 2, $legendx, $legendy, $this->highestvalue-($this->valueincriemen t*$i), $legendcolor);
          @ImageLine ($im, $this->leftspace, $legendy+6, $this->width - $this->rightspace, $legendy+6, $linecolor);
          }
          for($i=0;$i<cou nt($this->barheight);$i+ +){
          $j=$i+1;
          $x1 = ($j * $this->spacebar) + ($i * $this->barwidth) + $this->leftspace;
          $y1 = $this->height - ($this->barheight[$i]*$this->multiply) - $this->upspace;
          $x2 = $x1 + $this->barwidth;
          $y2 = $this->height - $this->bottomspace;
          $bartitlewidth = strlen($this->bartitle[$i]) * ImageFontWidth( 2);
          $centerofbar = $x1 + ($this->barwidth / 2);
          $bartitlex = $centerofbar - ($bartitlewidth/2);
          $bartitley = $y2 + 5;
          @ImageFilledRec tangle($im, $x1, $y1, $x2, $y2, $barcolor);
          @ImageString($i m, 2, $bartitlex, $bartitley, $this->bartitle[$i], $barinfocolor);
          }
          @ImageJPEG($im) ;
          @ImageDestroy($ im);
          }
          };

          // HERE IS THE EXAMPLE TO USE THE CHART CLASS
          $chart = new easyChart(); // Object initialized
          $chart->setTitle("Stoc k Item Graph"); // Title of Chart
          $chart->setBackground( "153,204,10 2"); // Background of chart [opt]
          $chart->setLineColor(" 225,225,225"); // Line color separator [opt]
          $chart->setBarColor("2 55,255,153"); // Bar color [opt]
          $chart->setTitleColor( "111,166,55 "); // Color Title [opt]
          $chart->setLegendColor ("0,0,0"); // Legend Color [opt]
          $chart->setBarInfoColo r("0,0,0"); // Bar Info Color [opt]
          $chart->setWidth(800 ); // Width of Chart
          $chart->setHeight(500) ; // Height of Chart
          $chart->setBarWidth(20 ); // Bar Width
          $chart->setLeftSpace(5 5); // Left Space
          $chart->setRightSpace( 25); // Right Space
          $chart->setLeftLegend( 10); // Left Legend

          $sql="SELECT SUM(quantity), SUM(amount), category FROM invoice WHERE category='Botto ms - Shorts' AND month = '$month' AND year = '$year' GROUP BY category";
          $results=mysql_ query($sql) or die(mysql_error ());
          $rows = mysql_fetch_arr ay($results);
          $shorts = $rows['SUM(quantity)'];

          $sql="SELECT SUM(quantity), SUM(amount), category FROM invoice WHERE category='Botto ms - Skirts' AND month = '$month' AND year = '$year' GROUP BY category";
          $results=mysql_ query($sql) or die(mysql_error ());
          $rows = mysql_fetch_arr ay($results);
          $skirts = $rows['SUM(quantity)'];

          $sql="SELECT SUM(quantity), SUM(amount), category FROM invoice WHERE category='Outer wear - Coats' AND month = '$month' AND year = '$year' GROUP BY category";
          $results=mysql_ query($sql) or die(mysql_error ());
          $rows = mysql_fetch_arr ay($results);
          $coats = $rows['SUM(quantity)'];

          $sql="SELECT SUM(quantity), SUM(amount), category FROM invoice WHERE category='Tops - Blouse' AND month = '$month' AND year = '$year' GROUP BY category";
          $results=mysql_ query($sql) or die(mysql_error ());
          $rows = mysql_fetch_arr ay($results);
          $blouse = $rows['SUM(quantity)'];

          $sql="SELECT SUM(quantity), SUM(amount), category FROM invoice WHERE category='Other s' AND month = '$month' AND year = '$year' GROUP BY category";
          $results=mysql_ query($sql) or die(mysql_error ());
          $rows = mysql_fetch_arr ay($results);
          $others = $rows['SUM(quantity)'];

          $chart->addBar("Bottom s - Shorts",$shorts ); // Sample content of chart
          $chart->addBar("Bottom s - Skirts",$skirts );
          $chart->addBar("Outerw ear - Coats",$coats);
          $chart->addBar("Tops - Blouse",$blouse );
          $chart->addBar("Others ",$others);


          $chart->prepare(); // Chart Preparation
          $chart->generateChart( ); // Chart Generation
          ?>

          [/code]

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            It's most definitely in PHP.

            I know this by:
            [php]
            <?php
            [/php]

            ;)

            Comment

            Working...