TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file FlexOptions.php

Documentation is available at FlexOptions.php

  1. <?php
  2.  
  3.  /**
  4.  * FlexOptions class
  5.  *
  6.  * Description: Flex options
  7.  *
  8.  * @author
  9.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @subpackage exports
  13.  * @link http://www.steema.com
  14.  */
  15.  
  16.  
  17. class FlexOptions {
  18.     
  19.     public static function CompileDeleteShow($chart$width$height$tempDirectoryPath$fileName
  20.         $deleteTemp$embedImages$show)
  21.     {
  22.         $tmpName=null;
  23.         
  24.         $tmpDest $tempDirectoryPath;
  25.       
  26.         //check if directory exist
  27.         if (!is_dir($tmpDest))
  28.         
  29.           die('invalid folder given!')
  30.         }       
  31.         else
  32.         {
  33.             if (!file_exists($tmpDest))
  34.               mkdir($tmpDest);
  35.         }
  36.  
  37.         if (strlen($fileName)>0)           
  38.           $tmpName $fileName;
  39.         
  40.         if (($tmpName==null|| ($tmpName==""))
  41.         {
  42.           $tmpName 'Chart1';
  43.         }
  44.  
  45.         if (substr($tmpDest,strlen($tmpDest)-2,strlen($tmpDest))=='/')
  46.         {
  47.           $tmpDest .= '/' $tmpName '.mxml';
  48.         }
  49.         else
  50.         {
  51.           $tmpDest .= '/' $tmpName '.mxml';
  52.         }
  53.       
  54.         $chart->getExport()->getImage()->getFlex()->setEmbeddedImages($embedImages);
  55.         $chart->getExport()->getImage()->getFlex()->setWidth($width);
  56.         $chart->getExport()->getImage()->getFlex()->setHeight($height);
  57.         $chart->getExport()->getImage()->getFlex()->Save($tmpDest);
  58.  
  59.         
  60.         self::Check_TeeSWC_Library($tempDirectoryPath '/tee.swc');
  61.         
  62.         $tmpRes self::Compile($chart$tmpDest);
  63.  
  64.         if ($deleteTemp)
  65.         {
  66.           if (file_exists($tempDirectoryPath '/tee.swc'))
  67.           {
  68.             // Deletes a file
  69.             unlink($tempDirectoryPath '/tee.swc');
  70.           }
  71.  
  72.           if (file_exists($tmpDest))
  73.           {
  74.             unlink($tmpDest);
  75.           }
  76.  
  77.           if ($embedImages)
  78.           {
  79.             $files scandir($tempDirectoryPath);
  80.             $arraySize sizeof($files);
  81.             for ($i=0;$i<$arraySize;$i++)
  82.              if (ereg('TeeChart_Flex_Temp_'$files[$i])) 
  83.              {
  84.                 unlink($tempDirectoryPath "/" $files[$i]);
  85.              }
  86.           }
  87.         }
  88.  
  89.         if ($tmpRes && $show)
  90.         {
  91.           self::GenerateHTML($chart$width$height$tempDirectoryPath$tmpName);
  92.           self::Preview($tempDirectoryPath '/' $tmpName '.html');
  93.         }
  94.     }
  95.     
  96.     private static function Preview($target)
  97.     {
  98.         exec($target);
  99.     }    
  100.     
  101.     private static function Check_TeeSWC_Library($teeSWC)
  102.     {
  103.             if (!file_exists($teeSWC))
  104.             {
  105.                 // copy from sources directory.
  106.                   if (!copy(dirname(__FILE__).'/tee.swc'dirname($teeSWC'/tee.swc'))
  107.                       echo "Error copying the resource file tee.swc";                    
  108.             }
  109.             
  110.     }
  111.     
  112.     private static function Compile($chart$targetFile)
  113.     {            
  114.             $tmpPath dirname($targetFile);
  115.                        
  116.             $WshShell new COM("WScript.Shell");
  117.             
  118.             // Path of flex compiler must be added at enviroment variables            
  119.             $str "cmd.exe /c mxmlc.exe -use-network=false -library-path+=" $tmpPath 
  120.                     '\tee.swc '$targetFile;
  121.             $oExec $WshShell->Run($str0true)
  122.  
  123.             /* Run parameter as 3, true to wait until finish..
  124.                 0 Hide the window and activate another window.
  125.                 1 Activate and display the window. (restore size and position) Specify this flag 
  126.                     when displaying a window for the first time.
  127.                 2 Activate & minimize.
  128.                 3 Activate & maximize.
  129.                 4 Restore. The active window remains active.
  130.                 5 Activate & Restore.
  131.                 6 Minimize & activate the next top-level window in the Z order.
  132.                 7 Minimize. The active window remains active.
  133.                 8 Display the window in its current state. The active window remains active.
  134.                 9 Restore & Activate. Specify this flag when restoring a minimized window.
  135.                 10 Sets the show-state based on the state of the program that started the application.  
  136.             */
  137.  
  138.             if ($oExec == 0)
  139.             {
  140.                 return true;
  141.             }
  142.             else
  143.             {
  144.                 echo "Error, swf file has not been generated";
  145.                 return false;
  146.             }            
  147.     }
  148.  
  149.     // Returns an array    
  150.     private static function Chart1_html({
  151.       return Array('<html>',
  152.       '<head>',
  153.       '<style type="text/css">',
  154.       'html, body',
  155.       '{',
  156.         'height: 100%;',
  157.         'margin: 0;',
  158.         'padding: 0;',
  159.        '}',
  160.       '</style>' ,
  161.       '</head>',
  162.       '<body>',
  163.           '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"',
  164.                 'id="Chart1" width="%WIDTH%" height="%HEIGHT%" menu="true"' ,
  165.                 'codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"/>',
  166.                 '<param name="movie" value="%MOVIE%.swf"/>',
  167.                 '<param name="quality" value="high"/>',
  168.                 '<param name="menu\" value="true"/>',
  169.                 '<param name="bgcolor" value="FFFFFF"/>',
  170.                 '<param name="allowScriptAccess" value="sameDomain"/>' ,
  171.                 '<embed src="%MOVIE%.swf" width="%WIDTH%" height="%HEIGHT%"/>',
  172.           '</object>',
  173.       '</body>',
  174.       '</html>'
  175.       );
  176.         
  177.     }
  178.         
  179.     static function GenerateHTML($chart$width$height$path$movie)
  180.     {                        
  181.             //FileStream fs;
  182.             //StreamWriter writer;
  183.             $lines self::Chart1_html();
  184.             for ($i 0$i sizeof($lines)$i++)
  185.             {
  186.                 if (strpos($lines[$i],"%MOVIE%"0)
  187.                 {
  188.                     $lines[$istr_replace('%MOVIE%'$movie$lines[$i]);
  189.                 }
  190.                 if (strpos($lines[$i],"%WIDTH%"0)
  191.                 {
  192.                     $lines[$istr_replace("%WIDTH%",$width$lines[$i]);
  193.                 }
  194.                 if (strpos($lines[$i],"%HEIGHT%"0)
  195.                 {
  196.                     $lines[$istr_replace("%HEIGHT%"$height$lines[$i]);
  197.                 }
  198.             }
  199.  
  200.             /* TODO remove fs = File.Create(path + "\\" + movie + ".html");
  201.             writer = new StreamWriter(fs);
  202.  
  203.             try
  204.             {
  205.                 foreach (string var in lines)
  206.                 {
  207.                     writer.Write(var + "\r\n");
  208.                 }
  209.             }
  210.             finally
  211.             {
  212.                 writer.Close();
  213.                 fs.Close();
  214.             }
  215.             */
  216.             
  217.             $fileName $path '/' $movie '.html';
  218.             
  219.             $fileHandle fopen($fileName'w'or die("can't open file");
  220.  
  221. //            $together = implode("\n",$lines); 
  222.  
  223. //            fwrite($fileHandle, $lines);                
  224.             foreach ($lines as $var
  225.             {                
  226.                 fwrite($fileHandle$var "\n");                
  227.             }
  228.             fclose($fileHandle);            
  229.         }
  230. }  
  231. ?>

Documentation generated on Wed, 16 Jun 2010 12:05:23 +0200 by phpDocumentor 1.4.1