<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once('include/Dashlets/Dashlet.php');
require_once('include/Sugar_Smarty.php');
include_once('include/ECM/open_flash_chart/ofc-library/open_flash_chart_object.php');


class MyChartsProductsDashlet extends Dashlet { 

	 var $savedText; // users's saved text
    var $height = '300'; // height of the pad

    function MyChartsProductsDashlet($id, $def) {
  
		global $current_user;


        parent::Dashlet($id); // call parent constructor
         
        $this->isConfigurable = true; // dashlet is configurable
        $this->hasScript = false;  // dashlet has java ipt attached to it
		
		if($current_user->id=='2e72f487-d92b-954e-f50c-528b10ce81c9'){
		
	
		}
        // if no custom title, use default
        if(empty($def['title'])) $this->title = 'Wykres: Czas rozmów & Sprzedaż ';
        else $this->title = $def['title'];        
    }
	
	function display() {
		global $current_user;
        $ss = new Sugar_Smarty();
		 $optionsArray = $this->loadOptions();
		//$ss->assign('account_id',$optionsArray['account_id']);
        $ss->assign('id', $this->id);
        $ss->assign('height', $this->height);
		 $ss->assign('year', $optionsArray['year']);
		 $_SESSION['EcmCharts_6_year']=$optionsArray['year'];
		$_SESSION['EcmCharts_6_category']=$category;
		$_SESSION['EcmCharts_6_account']=$optionsArray['account_id'];
		if(!isset($_SESSION['EcmCharts_6_year']))$_SESSION['EcmCharts_6_year']=(int)date("Y");
		if(!isset($_SESSION['EcmCharts_6_category']))$_SESSION['EcmCharts_6_category']='';
		if(!isset($_SESSION['EcmCharts_6_account']))$_SESSION['EcmCharts_6_account']='';
		//$_SESSION['EcmCharts_6_mmm']=$mmm;
		
         $str = $ss->fetch('modules/EcmCharts/Dashlets/MyChartsProductsDashlet/MyChartsProductsDashlet.tpl');   
        return parent::display('') . $str . '<br />'; // return parent::display for title and such
    }
	
	function displayOptions() {
 
	   global $app_strings,$current_user;
	
		$ss = new Sugar_Smarty();
		
		$ss->assign('year',$_SESSION['EcmCharts_6_year']);
		$ss->assign('id', $this->id); //The id must be assigned in all dashlet options pages
		
		return parent::displayOptions() . $ss->fetch('modules/EcmCharts/Dashlets/MyChartsProductsDashlet/MyChartsProductsDashletOptions.tpl');
		
	}
	
	function saveOptions($req) {
        global $sugar_config, $timedate, $current_user, $theme;
        $options = array();
		$options['account_name']=$_REQUEST['account_name'];
		$options['account_id']=$_REQUEST['account_id'];
		$options['year']=$_REQUEST['year'];
		$options['category']=$_REQUEST['category'];

        return $options;
    }
}
?>