cvsimport
This commit is contained in:
commit
a95281357d
@ -143,7 +143,7 @@ $sql = "SELECT r.id, r.libelle, r.module, r.perms, r.subperms, r.bydefault";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r";
|
||||
$sql.= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
|
||||
$sql.= " AND entity in (".(!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)?"1,":"").$conf->entity.")";
|
||||
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $sql.= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is disable
|
||||
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $sql.= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
|
||||
$sql.= " ORDER BY r.module, r.id";
|
||||
|
||||
$result = $db->query($sql);
|
||||
@ -164,12 +164,23 @@ if ($result)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if permission is inside module definition
|
||||
// TODO If not, we remove it
|
||||
/*foreach($objMod->rights as $key => $val)
|
||||
// Check if permission we found is inside a module definition. If not, we discard it.
|
||||
$found=false;
|
||||
foreach($objMod->rights as $key => $val)
|
||||
{
|
||||
}*/
|
||||
|
||||
$rights_class=$objMod->rights_class;
|
||||
if ($val[4] == $obj->perms && (empty($val[5]) || $val[5] == $obj->subperms))
|
||||
{
|
||||
$found=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! $found)
|
||||
{
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Break found, it's a new module to catch
|
||||
if ($old <> $obj->module)
|
||||
{
|
||||
|
||||
@ -43,7 +43,7 @@ $langs->load("cashdesk");
|
||||
header("Content-type: text/html; charset=".$conf->file->character_set_client);
|
||||
|
||||
$arrayofjs=array();
|
||||
$arrayofcss=array(DOL_URL_ROOT.'/cashdesk/css/style.css');
|
||||
$arrayofcss=array('/cashdesk/css/style.css');
|
||||
|
||||
top_htmlhead($head,$langs->trans("CashDesk"),0,0,$arrayofjs,$arrayofcss);
|
||||
|
||||
|
||||
@ -30,10 +30,10 @@ class Auth
|
||||
var $reponse;
|
||||
|
||||
var $sqlQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Enter description here ...
|
||||
*
|
||||
*
|
||||
* @param unknown_type $DB
|
||||
*/
|
||||
function Auth($DB)
|
||||
@ -46,7 +46,7 @@ class Auth
|
||||
|
||||
/**
|
||||
* Enter description here ...
|
||||
*
|
||||
*
|
||||
* @param unknown_type $aLogin
|
||||
*/
|
||||
function login($aLogin)
|
||||
@ -55,10 +55,10 @@ class Auth
|
||||
$this->login = $aLogin;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enter description here ...
|
||||
*
|
||||
*
|
||||
* @param unknown_type $aPasswd
|
||||
*/
|
||||
function passwd($aPasswd)
|
||||
@ -68,10 +68,10 @@ class Auth
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enter description here ...
|
||||
*
|
||||
*
|
||||
* @param unknown_type $aReponse
|
||||
*/
|
||||
function reponse($aReponse)
|
||||
@ -82,24 +82,26 @@ class Auth
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here ...
|
||||
*
|
||||
* @param unknown_type $aLogin
|
||||
* @param unknown_type $aPasswd
|
||||
* Validate login/pass
|
||||
*
|
||||
* @param string $aLogin Login
|
||||
* @param string $aPasswd Password
|
||||
*/
|
||||
function verif($aLogin, $aPasswd)
|
||||
{
|
||||
global $conf,$dolibarr_main_authentication,$langs;
|
||||
global $conf,$langs;
|
||||
global $dolibarr_main_authentication,$dolibarr_auto_user;
|
||||
|
||||
$ret=-1;
|
||||
|
||||
$login='';
|
||||
|
||||
$test=true;
|
||||
|
||||
// Authentication mode
|
||||
if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication='http,dolibarr';
|
||||
// Authentication mode: forceuser
|
||||
if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) $dolibarr_auto_user='auto';
|
||||
|
||||
// Set authmode
|
||||
$authmode=explode(',',$dolibarr_main_authentication);
|
||||
|
||||
@ -111,16 +113,9 @@ class Auth
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$test=true;
|
||||
|
||||
// Validation of third party module login method
|
||||
if (is_array($conf->login_method_modules) && !empty($conf->login_method_modules))
|
||||
{
|
||||
include_once(DOL_DOCUMENT_ROOT . "/lib/security.lib.php");
|
||||
$login = getLoginMethod($_POST["username"],$_POST["password"],$_POST["entity"]);
|
||||
if ($login) $test=false;
|
||||
}
|
||||
$usertotest=$aLogin;
|
||||
$passwordtotest=$aPasswd;
|
||||
$entitytotest=$conf->entity;
|
||||
|
||||
// Validation tests user / password
|
||||
// If ok, the variable will be initialized login
|
||||
@ -131,34 +126,16 @@ class Auth
|
||||
|
||||
if ($test && $goontestloop)
|
||||
{
|
||||
foreach($authmode as $mode)
|
||||
$login = checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmode);
|
||||
if ($login)
|
||||
{
|
||||
if ($test && $mode && ! $login)
|
||||
{
|
||||
$authfile=DOL_DOCUMENT_ROOT.'/includes/login/functions_'.$mode.'.php';
|
||||
$result=include_once($authfile);
|
||||
if ($result)
|
||||
{
|
||||
$this->login($aLogin);
|
||||
$this->passwd($aPasswd);
|
||||
$entitytotest=$conf->entity;
|
||||
|
||||
$function='check_user_password_'.$mode;
|
||||
$login=$function($aLogin,$aPasswd,$entitytotest);
|
||||
if ($login) // Login is successfull
|
||||
{
|
||||
$test=false;
|
||||
$dol_authmode=$mode; // This properties is defined only when logged to say what mode was successfully used
|
||||
$ret=0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_syslog("Authentification ko - failed to load file '".$authfile."'",LOG_ERR);
|
||||
sleep(1);
|
||||
$ret=-1;
|
||||
}
|
||||
}
|
||||
$this->login($aLogin);
|
||||
$this->passwd($aPasswd);
|
||||
$ret=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret=-1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -57,7 +57,7 @@ class Conf
|
||||
var $tabs_modules = array();
|
||||
var $triggers_modules = array();
|
||||
var $hooks_modules = array();
|
||||
var $login_method_modules = array();
|
||||
public $login_method_modules = array();
|
||||
var $modules = array();
|
||||
var $entities = array();
|
||||
|
||||
|
||||
@ -78,7 +78,7 @@ class DolGraph
|
||||
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
* Constructor
|
||||
*/
|
||||
function DolGraph()
|
||||
{
|
||||
@ -121,6 +121,10 @@ class DolGraph
|
||||
|
||||
|
||||
/**
|
||||
* Set Y precision
|
||||
*
|
||||
* @param float $which_prec
|
||||
* @return string
|
||||
*/
|
||||
function SetPrecisionY($which_prec)
|
||||
{
|
||||
@ -129,7 +133,9 @@ class DolGraph
|
||||
}
|
||||
|
||||
/**
|
||||
* \remarks Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2
|
||||
* Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2
|
||||
*
|
||||
* @param float $xi
|
||||
*/
|
||||
function SetHorizTickIncrement($xi)
|
||||
{
|
||||
@ -138,7 +144,9 @@ class DolGraph
|
||||
}
|
||||
|
||||
/**
|
||||
* \remarks Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2
|
||||
* Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2
|
||||
*
|
||||
* @param float $xt
|
||||
*/
|
||||
function SetNumXTicks($xt)
|
||||
{
|
||||
@ -147,7 +155,9 @@ class DolGraph
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set label interval to reduce number of labels
|
||||
* Set label interval to reduce number of labels
|
||||
*
|
||||
* @param float $x
|
||||
*/
|
||||
function SetLabelInterval($x)
|
||||
{
|
||||
@ -156,7 +166,7 @@ class DolGraph
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Hide X grid
|
||||
* Hide X grid
|
||||
*/
|
||||
function SetHideXGrid($bool)
|
||||
{
|
||||
@ -165,7 +175,7 @@ class DolGraph
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Hide Y grid
|
||||
* Hide Y grid
|
||||
*/
|
||||
function SetHideYGrid($bool)
|
||||
{
|
||||
@ -173,78 +183,140 @@ class DolGraph
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param unknown_type $label
|
||||
*/
|
||||
function SetYLabel($label)
|
||||
{
|
||||
$this->YLabel = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $w
|
||||
*/
|
||||
function SetWidth($w)
|
||||
{
|
||||
$this->width = $w;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $title
|
||||
*/
|
||||
function SetTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $data
|
||||
*/
|
||||
function SetData($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $type
|
||||
*/
|
||||
function SetType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $legend
|
||||
*/
|
||||
function SetLegend($legend)
|
||||
{
|
||||
$this->Legend = $legend;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $legendwidthmin
|
||||
*/
|
||||
function SetLegendWidthMin($legendwidthmin)
|
||||
{
|
||||
$this->LegendWidthMin = $legendwidthmin;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $max
|
||||
*/
|
||||
function SetMaxValue($max)
|
||||
{
|
||||
$this->MaxValue = $max;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function GetMaxValue()
|
||||
{
|
||||
return $this->MaxValue;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $min
|
||||
*/
|
||||
function SetMinValue($min)
|
||||
{
|
||||
$this->MinValue = $min;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function GetMinValue()
|
||||
{
|
||||
return $this->MinValue;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $h
|
||||
*/
|
||||
function SetHeight($h)
|
||||
{
|
||||
$this->height = $h;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $s
|
||||
*/
|
||||
function SetShading($s)
|
||||
{
|
||||
$this->SetShading = $s;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function ResetBgColor()
|
||||
{
|
||||
unset($this->bgcolor);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function ResetBgColorGrid()
|
||||
{
|
||||
unset($this->bgcolorgrid);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function isGraphKo()
|
||||
{
|
||||
return $this->error;
|
||||
@ -252,8 +324,10 @@ class DolGraph
|
||||
|
||||
|
||||
/**
|
||||
* \brief Definie la couleur de fond de l'image complete
|
||||
* \param bg_color array(R,G,B) ou 'onglet' ou 'default'
|
||||
* Definie la couleur de fond de l'image complete
|
||||
*
|
||||
* @param array $bg_color array(R,G,B) ou 'onglet' ou 'default'
|
||||
* @return void
|
||||
*/
|
||||
function SetBgColor($bg_color = array(255,255,255))
|
||||
{
|
||||
@ -277,8 +351,9 @@ class DolGraph
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Definie la couleur de fond de la grille
|
||||
* \param bg_colorgrid array(R,G,B) ou 'onglet' ou 'default'
|
||||
* Definie la couleur de fond de la grille
|
||||
*
|
||||
* @param array $bg_colorgrid array(R,G,B) ou 'onglet' ou 'default'
|
||||
*/
|
||||
function SetBgColorGrid($bg_colorgrid = array(255,255,255))
|
||||
{
|
||||
@ -301,11 +376,17 @@ class DolGraph
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function ResetDataColor()
|
||||
{
|
||||
unset($this->datacolor);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function GetMaxValueInData()
|
||||
{
|
||||
$k = 0;
|
||||
@ -326,6 +407,9 @@ class DolGraph
|
||||
return $vals[0];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function GetMinValueInData()
|
||||
{
|
||||
$k = 0;
|
||||
@ -392,8 +476,10 @@ class DolGraph
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a graph onto disk
|
||||
* @param file Image file name on disk
|
||||
* Build a graph onto disk using correct library
|
||||
*
|
||||
* @param string $file Image file name on disk to generate
|
||||
* @return void
|
||||
*/
|
||||
function draw($file)
|
||||
{
|
||||
@ -409,12 +495,15 @@ class DolGraph
|
||||
|
||||
|
||||
/**
|
||||
* Build a graph onto disk using Artichow library
|
||||
* @param file Image file name on disk
|
||||
* Build a graph onto disk using Artichow library
|
||||
*
|
||||
* @param string $file Image file name on disk to generate
|
||||
* @return void
|
||||
*/
|
||||
function draw_artichow($file)
|
||||
private function draw_artichow($file)
|
||||
{
|
||||
global $artichow_defaultfont;
|
||||
|
||||
dol_syslog("DolGraph.class::draw_artichow this->type=".$this->type);
|
||||
|
||||
if (! defined('SHADOW_RIGHT_TOP')) define('SHADOW_RIGHT_TOP',3);
|
||||
@ -425,7 +514,7 @@ class DolGraph
|
||||
$classname='';
|
||||
if ($this->type == 'bars') $classname='BarPlot';
|
||||
if ($this->type == 'lines') $classname='LinePlot';
|
||||
include_once DOL_DOCUMENT_ROOT."/includes/artichow/".$classname.".class.php";
|
||||
include_once(ARTICHOW_PATH.$classname.".class.php");
|
||||
|
||||
// Definition de couleurs
|
||||
$bgcolor=new Color($this->bgcolor[0],$this->bgcolor[1],$this->bgcolor[2]);
|
||||
|
||||
@ -181,16 +181,17 @@ define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix);
|
||||
* To use other version than embeded libraries, define here constant to path. Use '' to use include class path autodetect.
|
||||
*/
|
||||
// Path to root libraries
|
||||
if (! defined('ADODB_PATH')) { define('ADODB_PATH', (!isset($dolibarr_lib_ADODB_PATH))?DOL_DOCUMENT_ROOT .'/includes/adodbtime/':(empty($dolibarr_lib_ADODB_PATH)?'':$dolibarr_lib_ADODB_PATH.'/')); }
|
||||
if (! defined('TCPDF_PATH')) { define('TCPDF_PATH', (!isset($dolibarr_lib_TCPDF_PATH))?DOL_DOCUMENT_ROOT .'/includes/tcpdf/':(empty($dolibarr_lib_TCPDF_PATH)?'':$dolibarr_lib_TCPDF_PATH.'/')); }
|
||||
if (! defined('FPDFI_PATH')) { define('FPDFI_PATH', (!isset($dolibarr_lib_FPDFI_PATH))?DOL_DOCUMENT_ROOT .'/includes/fpdfi/':(empty($dolibarr_lib_FPDFI_PATH)?'':$dolibarr_lib_FPDFI_PATH.'/')); }
|
||||
if (! defined('NUSOAP_PATH')) { define('NUSOAP_PATH', (!isset($dolibarr_lib_NUSOAP_PATH))?DOL_DOCUMENT_ROOT .'/includes/nusoap/lib/':(empty($dolibarr_lib_NUSOAP_PATH)?'':$dolibarr_lib_NUSOAP_PATH.'/')); }
|
||||
if (! defined('PHPEXCEL_PATH')) { define('PHPEXCEL_PATH', (!isset($dolibarr_lib_PHPEXCEL_PATH))?DOL_DOCUMENT_ROOT .'/includes/phpexcel/':(empty($dolibarr_lib_PHPEXCEL_PATH)?'':$dolibarr_lib_PHPEXCEL_PATH.'/')); }
|
||||
if (! defined('ADODB_PATH')) { define('ADODB_PATH', (!isset($dolibarr_lib_ADODB_PATH))?DOL_DOCUMENT_ROOT.'/includes/adodbtime/':(empty($dolibarr_lib_ADODB_PATH)?'':$dolibarr_lib_ADODB_PATH.'/')); }
|
||||
if (! defined('TCPDF_PATH')) { define('TCPDF_PATH', (!isset($dolibarr_lib_TCPDF_PATH))?DOL_DOCUMENT_ROOT.'/includes/tcpdf/':(empty($dolibarr_lib_TCPDF_PATH)?'':$dolibarr_lib_TCPDF_PATH.'/')); }
|
||||
if (! defined('FPDFI_PATH')) { define('FPDFI_PATH', (!isset($dolibarr_lib_FPDFI_PATH))?DOL_DOCUMENT_ROOT.'/includes/fpdfi/':(empty($dolibarr_lib_FPDFI_PATH)?'':$dolibarr_lib_FPDFI_PATH.'/')); }
|
||||
if (! defined('NUSOAP_PATH')) { define('NUSOAP_PATH', (!isset($dolibarr_lib_NUSOAP_PATH))?DOL_DOCUMENT_ROOT.'/includes/nusoap/lib/':(empty($dolibarr_lib_NUSOAP_PATH)?'':$dolibarr_lib_NUSOAP_PATH.'/')); }
|
||||
if (! defined('PHPEXCEL_PATH')) { define('PHPEXCEL_PATH', (!isset($dolibarr_lib_PHPEXCEL_PATH))?DOL_DOCUMENT_ROOT.'/includes/phpexcel/':(empty($dolibarr_lib_PHPEXCEL_PATH)?'':$dolibarr_lib_PHPEXCEL_PATH.'/')); }
|
||||
if (! defined('GEOIP_PATH')) { define('GEOIP_PATH', (!isset($dolibarr_lib_GEOIP_PATH))?DOL_DOCUMENT_ROOT.'/includes/geoip/':(empty($dolibarr_lib_GEOIP_PATH)?'':$dolibarr_lib_GEOIP_PATH.'/')); }
|
||||
if (! defined('ODTPHP_PATH')) { define('ODTPHP_PATH', (!isset($dolibarr_lib_ODTPHP_PATH))?DOL_DOCUMENT_ROOT.'/includes/odtphp/':(empty($dolibarr_lib_ODTPHP_PATH)?'':$dolibarr_lib_ODTPHP_PATH.'/')); }
|
||||
if (! defined('ODTPHP_PATHTOPCLZIP')) { define('ODTPHP_PATHTOPCLZIP', (!isset($dolibarr_lib_ODTPHP_PATHTOPCLZIP))?DOL_DOCUMENT_ROOT.'/includes/odtphp/zip/pclzip/':(empty($dolibarr_lib_ODTPHP_PATHTOPCLZIP)?'':$dolibarr_lib_ODTPHP_PATHTOPCLZIP.'/')); }
|
||||
if (! defined('ARTICHOW_FONT')) { define('ARTICHOW_FONT', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?DOL_DOCUMENT_ROOT.'/includes/artichow/font':dirname($dolibarr_font_DOL_DEFAULT_TTF_BOLD)); }
|
||||
if (! defined('ARTICHOW_PATH')) { define('ARTICHOW_PATH', (!isset($dolibarr_lib_ARTICHOW))?DOL_DOCUMENT_ROOT.'/includes/artichow/':(empty($dolibarr_lib_ARTICHOW)?'':$dolibarr_lib_ARTICHOW.'/')); }
|
||||
// Other required path
|
||||
if (! defined('ARTICHOW_FONT')) { define('ARTICHOW_FONT', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?DOL_DOCUMENT_ROOT.'/includes/artichow/font':dirname($dolibarr_font_DOL_DEFAULT_TTF_BOLD)); }
|
||||
if (! defined('ARTICHOW_FONT_NAMES')) { define('ARTICHOW_FONT_NAMES', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?'Tuffy,TuffyBold,TuffyBoldItalic,TuffyItalic':'DejaVuSans,DejaVuSans-Bold,DejaVuSans-BoldOblique,DejaVuSans-Oblique'); }
|
||||
if (! defined('DOL_DEFAULT_TTF')) { define('DOL_DEFAULT_TTF', (!isset($dolibarr_font_DOL_DEFAULT_TTF))?DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/fonts/Aerial.ttf':(empty($dolibarr_font_DOL_DEFAULT_TTF)?'':$dolibarr_font_DOL_DEFAULT_TTF)); }
|
||||
if (! defined('DOL_DEFAULT_TTF_BOLD')) { define('DOL_DEFAULT_TTF_BOLD', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/fonts/AerialBd.ttf':(empty($dolibarr_font_DOL_DEFAULT_TTF_BOLD)?'':$dolibarr_font_DOL_DEFAULT_TTF_BOLD)); }
|
||||
|
||||
@ -1,217 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Graph.class.php";
|
||||
|
||||
/**
|
||||
* AntiSpam
|
||||
* String printed on the images are case insensitive.
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awAntiSpam extends awImage {
|
||||
|
||||
/**
|
||||
* Anti-spam string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $string;
|
||||
|
||||
/**
|
||||
* Noise intensity
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $noise = 0;
|
||||
|
||||
/**
|
||||
* Construct a new awAntiSpam image
|
||||
*
|
||||
* @param string $string A string to display
|
||||
*/
|
||||
function awAntiSpam($string = '') {
|
||||
|
||||
parent::awImage();
|
||||
|
||||
$this->string = (string)$string;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a random string
|
||||
*
|
||||
* @param int $length String length
|
||||
* @return string String created
|
||||
*/
|
||||
function setRand($length) {
|
||||
|
||||
$length = (int)$length;
|
||||
|
||||
$this->string = '';
|
||||
|
||||
$letters = 'aAbBCDeEFgGhHJKLmMnNpPqQRsStTuVwWXYZz2345679';
|
||||
$number = strlen($letters);
|
||||
|
||||
for($i = 0; $i < $length; $i++) {
|
||||
$this->string .= $letters{mt_rand(0, $number - 1)};
|
||||
}
|
||||
|
||||
return $this->string;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set noise on image
|
||||
*
|
||||
* @param int $nois Noise intensity (from 0 to 10)
|
||||
*/
|
||||
function setNoise($noise) {
|
||||
if($noise < 0) {
|
||||
$noise = 0;
|
||||
}
|
||||
if($noise > 10) {
|
||||
$noise = 10;
|
||||
}
|
||||
$this->noise = (int)$noise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save string value in session
|
||||
* You can use check() to verify the value later
|
||||
*
|
||||
* @param string $qName A name that identify the anti-spam image
|
||||
*/
|
||||
function save($qName) {
|
||||
$this->session();
|
||||
$session = 'artichow_'.(string)$qName;
|
||||
$_SESSION[$session] = $this->string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify user entry
|
||||
*
|
||||
* @param string $qName A name that identify the anti-spam image
|
||||
* @param string $value User-defined value
|
||||
* @param bool $case TRUE for case insensitive check, FALSE for case sensitive check ? (default to TRUE)
|
||||
* @return bool TRUE if the value is correct, FALSE otherwise
|
||||
*/
|
||||
function check($qName, $value, $case = TRUE) {
|
||||
|
||||
$this->session();
|
||||
|
||||
$session = 'artichow_'.(string)$qName;
|
||||
|
||||
return (
|
||||
array_key_exists($session, $_SESSION) === TRUE and
|
||||
$case ?
|
||||
(strtolower($_SESSION[$session]) === strtolower((string)$value)) :
|
||||
($_SESSION[$session] === (string)$value)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw image
|
||||
*/
|
||||
function draw() {
|
||||
|
||||
$fonts = array(
|
||||
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'Tuffy.ttf',
|
||||
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'TuffyBold.ttf',
|
||||
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'TuffyItalic.ttf',
|
||||
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'TuffyBoldItalic.ttf'
|
||||
);
|
||||
|
||||
$sizes = array(12, 12.5, 13, 13.5, 14, 15, 16, 17, 18, 19);
|
||||
|
||||
$widths = array();
|
||||
$heights = array();
|
||||
$texts = array();
|
||||
|
||||
for($i = 0; $i < strlen($this->string); $i++) {
|
||||
|
||||
$fontKey = array_rand($fonts);
|
||||
$sizeKey = array_rand($sizes);
|
||||
|
||||
$font = new awTTFFont(
|
||||
$fonts[$fontKey], $sizes[$sizeKey]
|
||||
);
|
||||
|
||||
$text = new awText(
|
||||
$this->string{$i},
|
||||
$font,
|
||||
NULL,
|
||||
mt_rand(-15, 15)
|
||||
);
|
||||
|
||||
$widths[] = $font->getTextWidth($text);
|
||||
$heights[] = $font->getTextHeight($text);
|
||||
$texts[] = $text;
|
||||
|
||||
}
|
||||
|
||||
$width = array_sum($widths);
|
||||
$height = array_max($heights);
|
||||
|
||||
$totalWidth = $width + 10 + count($texts) * 10;
|
||||
$totalHeight = $height + 20;
|
||||
|
||||
$this->setSize($totalWidth, $totalHeight);
|
||||
|
||||
$this->create();
|
||||
|
||||
for($i = 0; $i < strlen($this->string); $i++) {
|
||||
|
||||
$this->drawer->string(
|
||||
$texts[$i],
|
||||
new awPoint(
|
||||
5 + array_sum(array_slice($widths, 0, $i)) + $widths[$i] / 2 + $i * 10,
|
||||
10 + ($height - $heights[$i]) / 2
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->drawNoise($totalWidth, $totalHeight);
|
||||
|
||||
$this->send();
|
||||
|
||||
}
|
||||
|
||||
function drawNoise($width, $height) {
|
||||
|
||||
$points = $this->noise * 30;
|
||||
$color = new awColor(0, 0, 0);
|
||||
|
||||
for($i = 0; $i < $points; $i++) {
|
||||
$this->drawer->point(
|
||||
$color,
|
||||
new awPoint(
|
||||
mt_rand(0, $width),
|
||||
mt_rand(0, $height)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function session() {
|
||||
|
||||
// Start session if needed
|
||||
if(!session_id()) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('AntiSpam');
|
||||
?>
|
||||
@ -1,364 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Plot.class.php";
|
||||
|
||||
/**
|
||||
* BarPlot
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awBarPlot extends awPlot {
|
||||
|
||||
/**
|
||||
* Labels on your bar plot
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
var $label;
|
||||
|
||||
/**
|
||||
* Bar plot identifier
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $identifier;
|
||||
|
||||
/**
|
||||
* Bar plot number
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $number;
|
||||
|
||||
/**
|
||||
* Bar plot depth
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $depth;
|
||||
|
||||
/**
|
||||
* For moving bars
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $move;
|
||||
|
||||
/**
|
||||
* Bars shadow
|
||||
*
|
||||
* @var Shadow
|
||||
*/
|
||||
var $barShadow;
|
||||
|
||||
/**
|
||||
* Bars border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
var $barBorder;
|
||||
|
||||
/**
|
||||
* Bars padding
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
var $barPadding;
|
||||
|
||||
/**
|
||||
* Bars space
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $barSpace = 0;
|
||||
|
||||
/**
|
||||
* Bars background
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
var $barBackground;
|
||||
|
||||
/**
|
||||
* Construct a new awBarPlot
|
||||
*
|
||||
* @param array $values Some numeric values for Y axis
|
||||
* @param int $identifier Plot identifier
|
||||
* @param int $number Bar plot number
|
||||
* @param int $depth Bar plot depth in pixels
|
||||
*/
|
||||
function awBarPlot($values, $identifier = 1, $number = 1, $depth = 0) {
|
||||
|
||||
parent::awPlot();
|
||||
|
||||
$this->label = new awLabel;
|
||||
|
||||
$this->barPadding = new awSide(0.08, 0.08, 0, 0);
|
||||
$this->barShadow = new awShadow(SHADOW_RIGHT_TOP);
|
||||
$this->barBorder = new awBorder;
|
||||
|
||||
$this->setValues($values);
|
||||
|
||||
$this->identifier = (int)$identifier;
|
||||
$this->number = (int)$number;
|
||||
$this->depth = (int)$depth;
|
||||
|
||||
$this->move = new awSide;
|
||||
|
||||
// Hide vertical grid
|
||||
$this->grid->hideVertical(TRUE);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change bars padding
|
||||
* This method is not compatible with awBarPlot::setBarPadding()
|
||||
*
|
||||
* @param float $left Left padding (between 0 and 1)
|
||||
* @param float $right Right padding (between 0 and 1)
|
||||
*/
|
||||
function setBarPadding($left = NULL, $right = NULL) {
|
||||
$this->barPadding->set($left, $right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change bars size
|
||||
* This method is not compatible with awBarPlot::setBarPadding()
|
||||
*
|
||||
* @param int $width Bars size (between 0 and 1)
|
||||
*/
|
||||
function setBarSize($size) {
|
||||
$padding = (1 - $size) / 2;
|
||||
$this->barPadding->set($padding, $padding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move bars
|
||||
*
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
*/
|
||||
function move($x, $y) {
|
||||
$this->move->set($x, NULL, $y, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change bars space
|
||||
*
|
||||
* @param int $space Space in pixels
|
||||
*/
|
||||
function setBarSpace($space) {
|
||||
$this->barSpace = (int)$space;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line background color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setBarColor($color) {
|
||||
$this->barBackground = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line background gradient
|
||||
*
|
||||
* @param $gradient
|
||||
*/
|
||||
function setBarGradient($gradient) {
|
||||
$this->barBackground = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getLegendLineThickness() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getLegendLineStyle() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
function getLegendLineColor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
function getLegendBackground() {
|
||||
return $this->barBackground;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return Mark
|
||||
*/
|
||||
function getLegendMark() {
|
||||
}
|
||||
|
||||
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
$count = count($this->datay);
|
||||
$max = $this->getRealYMax(NULL);
|
||||
$min = $this->getRealYMin(NULL);
|
||||
|
||||
// Find zero for bars
|
||||
if($this->xAxisZero and $min <= 0 and $max >= 0) {
|
||||
$zero = 0;
|
||||
} else if($max < 0) {
|
||||
$zero = $max;
|
||||
} else {
|
||||
$zero = $min;
|
||||
}
|
||||
|
||||
// Get base position
|
||||
$zero = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, $zero));
|
||||
|
||||
// Distance between two values on the graph
|
||||
$distance = $this->xAxis->getDistance(0, 1);
|
||||
|
||||
// Compute paddings
|
||||
$leftPadding = $this->barPadding->left * $distance;
|
||||
$rightPadding = $this->barPadding->right * $distance;
|
||||
|
||||
$padding = $leftPadding + $rightPadding;
|
||||
$space = $this->barSpace * ($this->number - 1);
|
||||
|
||||
$barSize = ($distance - $padding - $space) / $this->number;
|
||||
$barPosition = $leftPadding + $barSize * ($this->identifier - 1);
|
||||
|
||||
for($key = 0; $key < $count; $key++) {
|
||||
|
||||
$value = $this->datay[$key];
|
||||
|
||||
if($value !== NULL) {
|
||||
|
||||
$position = awAxis::toPosition(
|
||||
$this->xAxis,
|
||||
$this->yAxis,
|
||||
new awPoint($key, $value)
|
||||
);
|
||||
|
||||
$barStart = $barPosition + ($this->identifier - 1) * $this->barSpace + $position->x;
|
||||
$barStop = $barStart + $barSize;
|
||||
|
||||
$t1 = min($zero->y, $position->y);
|
||||
$t2 = max($zero->y, $position->y);
|
||||
|
||||
if(round($t2 - $t1) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$p1 = new awPoint(
|
||||
round($barStart) + $this->depth + $this->move->left,
|
||||
round($t1) - $this->depth + $this->move->top
|
||||
);
|
||||
|
||||
$p2 = new awPoint(
|
||||
round($barStop) + $this->depth + $this->move->left,
|
||||
round($t2) - $this->depth + $this->move->top
|
||||
);
|
||||
|
||||
$this->drawBar($drawer, $p1, $p2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Draw labels
|
||||
foreach($this->datay as $key => $value) {
|
||||
|
||||
if($value !== NULL) {
|
||||
|
||||
$position = awAxis::toPosition(
|
||||
$this->xAxis,
|
||||
$this->yAxis,
|
||||
new awPoint($key, $value)
|
||||
);
|
||||
|
||||
$point = new awPoint(
|
||||
$barPosition + ($this->identifier - 1) * $this->barSpace + $position->x + $barSize / 2 + 1 + $this->depth,
|
||||
$position->y - $this->depth
|
||||
);
|
||||
|
||||
$this->label->draw($drawer, $point, $key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getXAxisNumber() {
|
||||
return count($this->datay) + 1;
|
||||
}
|
||||
// ça bidouille à fond ici !
|
||||
function getXMax() {
|
||||
return array_max($this->datax) + 1;
|
||||
}
|
||||
|
||||
function getXCenter() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function drawBar($drawer, $p1, $p2) {
|
||||
|
||||
// Draw shadow
|
||||
$this->barShadow->draw(
|
||||
$drawer,
|
||||
$p1,
|
||||
$p2,
|
||||
SHADOW_OUT
|
||||
);
|
||||
|
||||
if(abs($p2->y - $p1->y) > 1) {
|
||||
|
||||
$this->barBorder->rectangle(
|
||||
$drawer,
|
||||
$p1,
|
||||
$p2
|
||||
);
|
||||
|
||||
if($this->barBackground !== NULL) {
|
||||
|
||||
$size = $this->barBorder->visible() ? 1 : 0;
|
||||
|
||||
$b1 = $p1->move($size, $size);
|
||||
$b2 = $p2->move(-1 * $size, -1 * $size);
|
||||
|
||||
// Draw background
|
||||
$drawer->filledRectangle(
|
||||
$this->barBackground,
|
||||
new awLine($b1, $b2)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('BarPlot');
|
||||
?>
|
||||
@ -1,418 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Graph.class.php";
|
||||
|
||||
|
||||
/**
|
||||
* A graph can contain some groups of components
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awComponentGroup extends awComponent {
|
||||
|
||||
/**
|
||||
* Components of this group
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $components;
|
||||
|
||||
/**
|
||||
* Build the component group
|
||||
*/
|
||||
function awComponentGroup() {
|
||||
parent::awComponent();
|
||||
$this->components = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a component to the group
|
||||
*
|
||||
* @param &$component A component
|
||||
*/
|
||||
function add(&$component) {
|
||||
$this->components[] = $component;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('ComponentGroup', TRUE);
|
||||
|
||||
class awComponent {
|
||||
|
||||
/**
|
||||
* Component drawer
|
||||
*
|
||||
* @var Drawer
|
||||
*/
|
||||
var $drawer;
|
||||
|
||||
/**
|
||||
* Component width
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
var $width = 1.0;
|
||||
|
||||
/**
|
||||
* Component height
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
var $height = 1.0;
|
||||
|
||||
/**
|
||||
* Position X of the center the graph (from 0 to 1)
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
var $x = 0.5;
|
||||
|
||||
/**
|
||||
* Position Y of the center the graph (from 0 to 1)
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
var $y = 0.5;
|
||||
|
||||
/**
|
||||
* Component absolute width (in pixels)
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $w;
|
||||
|
||||
/**
|
||||
* Component absolute height (in pixels)
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $h;
|
||||
|
||||
/**
|
||||
* Left-top corner Y position
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
var $top;
|
||||
|
||||
/**
|
||||
* Left-top corner X position
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
var $left;
|
||||
|
||||
/**
|
||||
* Component background color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $background;
|
||||
|
||||
/**
|
||||
* Component padding
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
var $padding;
|
||||
|
||||
/**
|
||||
* Component space
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
var $space;
|
||||
|
||||
/**
|
||||
* Component title
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
var $title;
|
||||
|
||||
/**
|
||||
* Adjust automatically the component ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $auto = TRUE;
|
||||
|
||||
/**
|
||||
* Legend
|
||||
*
|
||||
* @var Legend
|
||||
*/
|
||||
var $legend;
|
||||
|
||||
/**
|
||||
* Build the component
|
||||
*/
|
||||
function awComponent() {
|
||||
// DOL_CHANGE LDR Fix to allow usage of other fonts
|
||||
global $artichow_defaultfont;
|
||||
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
|
||||
|
||||
// Component legend
|
||||
$this->legend = new awLegend();
|
||||
|
||||
$this->padding = new awSide(25, 25, 25, 25);
|
||||
$this->space = new awSide(0, 0, 0, 0);
|
||||
|
||||
// Component title
|
||||
$this->title = new awLabel(
|
||||
NULL,
|
||||
new $classfontname(10),
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
$this->title->setAlign(LABEL_CENTER, LABEL_TOP);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust automatically the component ?
|
||||
*
|
||||
* @param bool $auto
|
||||
*/
|
||||
function auto($auto) {
|
||||
$this->auto = (bool)$auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size of the component
|
||||
*
|
||||
* @param int $width Component width (from 0 to 1)
|
||||
* @param int $height Component height (from 0 to 1)
|
||||
*/
|
||||
function setSize($width, $height) {
|
||||
|
||||
$this->width = (float)$width;
|
||||
$this->height = (float)$height;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the absolute size of the component
|
||||
*
|
||||
* @param int $w Component width (in pixels)
|
||||
* @param int $h Component height (in pixels)
|
||||
*/
|
||||
function setAbsSize($w, $h) {
|
||||
|
||||
$this->w = (int)$w;
|
||||
$this->h = (int)$h;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component background color
|
||||
*
|
||||
* @param $color (can be null)
|
||||
*/
|
||||
function setBackgroundColor($color) {
|
||||
if($color === NULL or is_a($color, 'awColor')) {
|
||||
$this->background = $color;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component background gradient
|
||||
*
|
||||
* @param $gradient (can be null)
|
||||
*/
|
||||
function setBackgroundGradient($gradient) {
|
||||
if($gradient === NULL or is_a($gradient, 'awGradient')) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component background image
|
||||
*
|
||||
* @param &$image (can be null)
|
||||
*/
|
||||
function setBackgroundImage($image) {
|
||||
if($image === NULL or is_a($image, 'awImage')) {
|
||||
$this->background = $image;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the component background
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
function getBackground() {
|
||||
return $this->background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component padding
|
||||
*
|
||||
* @param int $left Padding in pixels (NULL to keep old value)
|
||||
* @param int $right Padding in pixels (NULL to keep old value)
|
||||
* @param int $top Padding in pixels (NULL to keep old value)
|
||||
* @param int $bottom Padding in pixels (NULL to keep old value)
|
||||
*/
|
||||
function setPadding($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
|
||||
$this->padding->set($left, $right, $top, $bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component space
|
||||
*
|
||||
* @param float $left Space in % (NULL to keep old value)
|
||||
* @param float $right Space in % (NULL to keep old value)
|
||||
* @param float $bottom Space in % (NULL to keep old value)
|
||||
* @param float $top Space in % (NULL to keep old value)
|
||||
*/
|
||||
function setSpace($left = NULL, $right = NULL, $bottom = NULL, $top = NULL) {
|
||||
$this->space->set($left, $right, $bottom, $top);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the absolute position of the component on the graph
|
||||
*
|
||||
* @var int $x Left-top corner X position
|
||||
* @var int $y Left-top corner Y position
|
||||
*/
|
||||
function setAbsPosition($left, $top) {
|
||||
|
||||
$this->left = (int)$left;
|
||||
$this->top = (int)$top;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the center of the component
|
||||
*
|
||||
* @param int $x Position on X axis of the center of the component
|
||||
* @param int $y Position on Y axis of the center of the component
|
||||
*/
|
||||
function setCenter($x, $y) {
|
||||
|
||||
$this->x = (float)$x;
|
||||
$this->y = (float)$y;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get component coords with its padding
|
||||
*
|
||||
* @return array Coords of the component
|
||||
*/
|
||||
function getPosition() {
|
||||
|
||||
// Get component coords
|
||||
$x1 = $this->padding->left;
|
||||
$y1 = $this->padding->top;
|
||||
$x2 = $this->w - $this->padding->right;
|
||||
$y2 = $this->h - $this->padding->bottom;
|
||||
|
||||
return array($x1, $y1, $x2, $y2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the drawing of the component
|
||||
*/
|
||||
function init($drawer) {
|
||||
|
||||
// Set component background
|
||||
$background = $this->getBackground();
|
||||
|
||||
if($background !== NULL) {
|
||||
|
||||
$p1 = new awPoint(0, 0);
|
||||
$p2 = new awPoint($this->w - 1, $this->h - 1);
|
||||
|
||||
if(is_a($background, 'awImage')) {
|
||||
|
||||
$drawer->copyImage(
|
||||
$background,
|
||||
$p1,
|
||||
$p2
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$background,
|
||||
new awLine($p1, $p2)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize the drawing of the component
|
||||
*/
|
||||
function finalize($drawer) {
|
||||
|
||||
// Draw component title
|
||||
$point = new awPoint(
|
||||
$this->w / 2,
|
||||
$this->padding->top - 8
|
||||
);
|
||||
$this->title->draw($drawer, $point);
|
||||
|
||||
// Draw legend
|
||||
$this->legend->draw($drawer);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the grid around your component
|
||||
*
|
||||
* @param Drawer A drawer
|
||||
* @return array Coords for the component
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Draw the component on the graph
|
||||
* Component should be drawed into specified coords
|
||||
*
|
||||
* @param Drawer A drawer
|
||||
* @param int $x1
|
||||
* @param int $y1
|
||||
* @param int $x2
|
||||
* @param int $y2
|
||||
* @param bool $aliasing Use anti-aliasing to draw the component ?
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Get space width in pixels
|
||||
*
|
||||
* @param int $width Component width
|
||||
* @param int $height Component height
|
||||
* @return array
|
||||
*/
|
||||
function getSpace($width, $height) {
|
||||
|
||||
$left = (int)($width * $this->space->left / 100);
|
||||
$right = (int)($width * $this->space->right / 100);
|
||||
$top = (int)($height * $this->space->top / 100);
|
||||
$bottom = (int)($height * $this->space->bottom / 100);
|
||||
|
||||
return array($left, $right, $top, $bottom);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Component', TRUE);
|
||||
?>
|
||||
@ -1,393 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
// Artichow configuration
|
||||
|
||||
// Some useful files
|
||||
require_once ARTICHOW."/common.php";
|
||||
require_once ARTICHOW."/Component.class.php";
|
||||
require_once ARTICHOW."/Image.class.php";
|
||||
|
||||
require_once ARTICHOW."/inc/Grid.class.php";
|
||||
require_once ARTICHOW."/inc/Tools.class.php";
|
||||
require_once ARTICHOW."/inc/Drawer.class.php";
|
||||
require_once ARTICHOW."/inc/Math.class.php";
|
||||
require_once ARTICHOW."/inc/Tick.class.php";
|
||||
require_once ARTICHOW."/inc/Axis.class.php";
|
||||
require_once ARTICHOW."/inc/Legend.class.php";
|
||||
require_once ARTICHOW."/inc/Mark.class.php";
|
||||
require_once ARTICHOW."/inc/Label.class.php";
|
||||
require_once ARTICHOW."/inc/Text.class.php";
|
||||
require_once ARTICHOW."/inc/Color.class.php";
|
||||
require_once ARTICHOW."/inc/Font.class.php";
|
||||
require_once ARTICHOW."/inc/Gradient.class.php";
|
||||
|
||||
/**
|
||||
* A graph
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awGraph extends awImage {
|
||||
|
||||
/**
|
||||
* Graph name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* Cache timeout
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $timeout = 0;
|
||||
|
||||
/**
|
||||
* Graph timing ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $timing;
|
||||
|
||||
/**
|
||||
* Components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $components = array();
|
||||
|
||||
/**
|
||||
* Some labels to add to the component
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $labels = array();
|
||||
|
||||
/**
|
||||
* Graph title
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
var $title;
|
||||
|
||||
/**
|
||||
* Construct a new graph
|
||||
*
|
||||
* @param int $width Graph width
|
||||
* @param int $height Graph height
|
||||
* @param string $name Graph name for the cache (must be unique). Let it null to not use the cache.
|
||||
* @param int $timeout Cache timeout (unix timestamp)
|
||||
*/
|
||||
function awGraph($width = NULL, $height = NULL, $name = NULL, $timeout = 0) {
|
||||
|
||||
// DOL_CHANGE LDR Fix to allow usage of other fonts
|
||||
global $artichow_defaultfont;
|
||||
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
|
||||
|
||||
parent::awImage();
|
||||
|
||||
$this->setSize($width, $height);
|
||||
|
||||
if(ARTICHOW_CACHE) {
|
||||
|
||||
$this->name = $name;
|
||||
$this->timeout = $timeout;
|
||||
|
||||
// Clean sometimes all the cache
|
||||
if(mt_rand(0, 5000) === 0) {
|
||||
awGraph::cleanCache();
|
||||
}
|
||||
|
||||
if($this->name !== NULL) {
|
||||
|
||||
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."-time";
|
||||
|
||||
if(is_file($file)) {
|
||||
|
||||
$type = awGraph::cleanGraphCache($file);
|
||||
|
||||
if($type === NULL) {
|
||||
awGraph::deleteFromCache($this->name);
|
||||
} else {
|
||||
header("Content-Type: image/".$type);
|
||||
readfile(ARTICHOW_CACHE_DIRECTORY."/".$this->name."");
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->title = new awLabel(
|
||||
NULL,
|
||||
new $classfontname(16),
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
$this->title->setAlign(LABEL_CENTER, LABEL_BOTTOM);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a graph from the cache
|
||||
*
|
||||
* @param string $name Graph name
|
||||
* @return bool TRUE on success, FALSE on failure
|
||||
*/
|
||||
function deleteFromCache($name) {
|
||||
|
||||
if(ARTICHOW_CACHE) {
|
||||
|
||||
if(is_file(ARTICHOW_CACHE_DIRECTORY."/".$name."-time")) {
|
||||
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."");
|
||||
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."-time");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all graphs from the cache
|
||||
*/
|
||||
function deleteAllCache() {
|
||||
|
||||
if(ARTICHOW_CACHE) {
|
||||
|
||||
$dp = opendir(ARTICHOW_CACHE_DIRECTORY);
|
||||
|
||||
while($file = readdir($dp)) {
|
||||
if($file !== '.' and $file != '..') {
|
||||
unlink(ARTICHOW_CACHE_DIRECTORY."/".$file);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean cache
|
||||
*/
|
||||
function cleanCache() {
|
||||
|
||||
if(ARTICHOW_CACHE) {
|
||||
|
||||
$glob = glob(ARTICHOW_CACHE_DIRECTORY."/*-time");
|
||||
|
||||
foreach($glob as $file) {
|
||||
|
||||
$type = awGraph::cleanGraphCache($file);
|
||||
|
||||
if($type === NULL) {
|
||||
$name = ereg_replace(".*/(.*)\-time", "\\1", $file);
|
||||
awGraph::deleteFromCache($name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable Graph timing
|
||||
*
|
||||
* @param bool $timing
|
||||
*/
|
||||
function setTiming($timing) {
|
||||
$this->timing = (bool)$timing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a component to the graph
|
||||
*
|
||||
* @param &$component
|
||||
*/
|
||||
function add(&$component) {
|
||||
|
||||
$this->components[] = $component;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a label to the component
|
||||
*
|
||||
* @param &$label
|
||||
* @param int $x Position on X axis of the center of the text
|
||||
* @param int $y Position on Y axis of the center of the text
|
||||
*/
|
||||
function addLabel(&$label, $x, $y) {
|
||||
|
||||
$this->labels[] = array(
|
||||
$label, $x, $y
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a label to the component with aboslute position
|
||||
*
|
||||
* @param &$label
|
||||
* @param $point Text position
|
||||
*/
|
||||
function addAbsLabel(&$label, $point) {
|
||||
|
||||
$this->labels[] = array(
|
||||
$label, $point
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the graph and draw component on it
|
||||
* Image is sent to the user browser
|
||||
*
|
||||
* @param string $file Save the image in the specified file. Let it null to print image to screen.
|
||||
*/
|
||||
function draw($file = NULL) {
|
||||
|
||||
if($this->timing) {
|
||||
$time = microtimeFloat();
|
||||
}
|
||||
|
||||
$this->create();
|
||||
|
||||
foreach($this->components as $component) {
|
||||
|
||||
$this->drawComponent($component);
|
||||
|
||||
}
|
||||
|
||||
$this->drawTitle();
|
||||
$this->drawShadow();
|
||||
$this->drawLabels();
|
||||
|
||||
if($this->timing) {
|
||||
$this->drawTiming(microtimeFloat() - $time);
|
||||
}
|
||||
|
||||
if(ARTICHOW_CACHE and $this->name !== NULL) {
|
||||
ob_start();
|
||||
}
|
||||
|
||||
$this->send($file);
|
||||
|
||||
if(ARTICHOW_CACHE and $this->name !== NULL) {
|
||||
|
||||
$data = ob_get_contents();
|
||||
|
||||
if(is_writable(ARTICHOW_CACHE_DIRECTORY) === FALSE) {
|
||||
trigger_error("Cache directory is not writable");
|
||||
}
|
||||
|
||||
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."";
|
||||
file_put_contents($file, $data);
|
||||
|
||||
$file .= "-time";
|
||||
file_put_contents($file, $this->timeout."\n".$this->getFormat());
|
||||
|
||||
ob_clean();
|
||||
|
||||
echo $data;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function drawLabels() {
|
||||
|
||||
$drawer = $this->getDrawer();
|
||||
|
||||
foreach($this->labels as $array) {
|
||||
|
||||
if(count($array) === 3) {
|
||||
|
||||
// Text in relative position
|
||||
list($label, $x, $y) = $array;
|
||||
|
||||
$point = new awPoint(
|
||||
$x * $this->width,
|
||||
$y * $this->height
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
// Text in absolute position
|
||||
list($label, $point) = $array;
|
||||
|
||||
}
|
||||
|
||||
$label->draw($drawer, $point);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function drawTitle() {
|
||||
|
||||
$drawer = $this->getDrawer();
|
||||
|
||||
$point = new awPoint(
|
||||
$this->width / 2,
|
||||
10
|
||||
);
|
||||
|
||||
$this->title->draw($drawer, $point);
|
||||
|
||||
}
|
||||
|
||||
function drawTiming($time) {
|
||||
|
||||
$drawer = $this->getDrawer();
|
||||
|
||||
$label = new awLabel;
|
||||
$label->set("(".sprintf("%.3f", $time)." s)");
|
||||
$label->setAlign(LABEL_LEFT, LABEL_TOP);
|
||||
$label->border->show();
|
||||
$label->setPadding(1, 0, 0, 0);
|
||||
$label->setBackgroundColor(new awColor(230, 230, 230, 25));
|
||||
|
||||
$label->draw($drawer, new awPoint(5, $drawer->height - 5));
|
||||
|
||||
}
|
||||
|
||||
function cleanGraphCache($file) {
|
||||
|
||||
list(
|
||||
$time,
|
||||
$type
|
||||
) = explode("\n", file_get_contents($file));
|
||||
|
||||
$time = (int)$time;
|
||||
|
||||
if($time !== 0 and $time < time()) {
|
||||
return NULL;
|
||||
} else {
|
||||
return $type;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Graph');
|
||||
|
||||
/*
|
||||
* To preserve PHP 4 compatibility
|
||||
*/
|
||||
function microtimeFloat() {
|
||||
list($usec, $sec) = explode(" ", microtime());
|
||||
return (float)$usec + (float)$sec;
|
||||
}
|
||||
?>
|
||||
@ -1,421 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("IMAGE_JPEG", 1);
|
||||
define("IMAGE_PNG", 2);
|
||||
define("IMAGE_GIF", 3);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/*
|
||||
* Check for GD2
|
||||
*/
|
||||
if(function_exists('imagecreatetruecolor') === FALSE) {
|
||||
trigger_error("You must compile PHP with GD2 support to use Artichow", E_USER_ERROR);
|
||||
}
|
||||
|
||||
require_once ARTICHOW."/inc/Shadow.class.php";
|
||||
require_once ARTICHOW."/inc/Border.class.php";
|
||||
|
||||
/**
|
||||
* An image for a graph
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awImage {
|
||||
|
||||
/**
|
||||
* Graph width
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $width;
|
||||
|
||||
/**
|
||||
* Graph height
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $height;
|
||||
|
||||
/**
|
||||
* Use anti-aliasing ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $antiAliasing = FALSE;
|
||||
|
||||
/**
|
||||
* Image format
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $format = IMAGE_PNG;
|
||||
|
||||
/**
|
||||
* Image background color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $background;
|
||||
|
||||
/**
|
||||
* GD resource
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
var $resource;
|
||||
|
||||
/**
|
||||
* Image drawer
|
||||
*
|
||||
* @var Drawer
|
||||
*/
|
||||
var $drawer;
|
||||
|
||||
/**
|
||||
* Shadow
|
||||
*
|
||||
* @var Shadow
|
||||
*/
|
||||
var $shadow;
|
||||
|
||||
/**
|
||||
* Image border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
var $border;
|
||||
|
||||
/**
|
||||
* Use JPEG for image
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Use PNG for image
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Use GIF for image
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Build the image
|
||||
*/
|
||||
function awImage() {
|
||||
|
||||
$this->background = new awColor(255, 255, 255);
|
||||
$this->shadow = new awShadow(SHADOW_RIGHT_BOTTOM);
|
||||
$this->border = new awBorder;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get drawer of the image
|
||||
*
|
||||
* @param int $w Drawer width (from 0 to 1) (default to 1)
|
||||
* @param int $h Drawer height (from 0 to 1) (default to 1)
|
||||
* @param float $x Position on X axis of the center of the drawer (default to 0.5)
|
||||
* @param float $y Position on Y axis of the center of the drawer (default to 0.5)
|
||||
* @return Drawer
|
||||
*/
|
||||
function getDrawer($w = 1, $h = 1, $x = 0.5, $y = 0.5) {
|
||||
$this->create();
|
||||
$this->drawer->setSize($w, $h);
|
||||
$this->drawer->setPosition($x, $y);
|
||||
return $this->drawer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the image size
|
||||
*
|
||||
* @var int $width Image width
|
||||
* @var int $height Image height
|
||||
*/
|
||||
function setSize($width, $height) {
|
||||
|
||||
if($width !== NULL) {
|
||||
$this->width = (int)$width;
|
||||
}
|
||||
if($height !== NULL) {
|
||||
$this->height = (int)$height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change image background color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setBackgroundColor($color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change image background gradient
|
||||
*
|
||||
* @param $gradient
|
||||
*/
|
||||
function setBackgroundGradient($gradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can we use anti-aliasing ?
|
||||
*
|
||||
* @var bool $bool
|
||||
*/
|
||||
function setAntiAliasing($bool) {
|
||||
$this->antiAliasing = (bool)$bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change image format
|
||||
*
|
||||
* @var int $format New image format
|
||||
*/
|
||||
function setFormat($format) {
|
||||
if($format === IMAGE_JPEG or $format === IMAGE_PNG or $format === IMAGE_GIF) {
|
||||
$this->format = $format;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new awimage
|
||||
*/
|
||||
function create() {
|
||||
|
||||
if($this->resource === NULL) {
|
||||
|
||||
// Create image
|
||||
|
||||
$this->resource = imagecreatetruecolor($this->width, $this->height);
|
||||
if(!$this->resource) {
|
||||
trigger_error("Unable to create a graph", E_USER_ERROR);
|
||||
}
|
||||
|
||||
imagealphablending($this->resource, TRUE);
|
||||
|
||||
if($this->antiAliasing and function_exists('imageantialias')) {
|
||||
imageantialias($this->resource, TRUE);
|
||||
}
|
||||
|
||||
$this->drawer = new awDrawer($this->resource);
|
||||
$this->drawer->setImageSize($this->width, $this->height);
|
||||
|
||||
// Original color
|
||||
$this->drawer->filledRectangle(
|
||||
new awWhite,
|
||||
new awLine(
|
||||
new awPoint(0, 0),
|
||||
new awPoint($this->width, $this->height)
|
||||
)
|
||||
);
|
||||
|
||||
$shadow = $this->shadow->getSpace();
|
||||
|
||||
$p1 = new awPoint($shadow->left, $shadow->top);
|
||||
$p2 = new awPoint($this->width - $shadow->right - 1, $this->height - $shadow->bottom - 1);
|
||||
|
||||
// Draw image background
|
||||
$this->drawer->filledRectangle($this->background, new awLine($p1, $p2));
|
||||
$this->background->free();
|
||||
|
||||
// Draw image border
|
||||
$this->border->rectangle($this->drawer, $p1, $p2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a component on the image
|
||||
*
|
||||
* @var &$component A component
|
||||
*/
|
||||
function drawComponent(&$component) {
|
||||
|
||||
$shadow = $this->shadow->getSpace(); // Image shadow
|
||||
$border = $this->border->visible() ? 1 : 0; // Image border size
|
||||
|
||||
$drawer = $this->drawer;
|
||||
$drawer->setImageSize(
|
||||
$this->width - $shadow->left - $shadow->right - $border * 2,
|
||||
$this->height - $shadow->top - $shadow->bottom - $border * 2
|
||||
);
|
||||
|
||||
// No absolute size specified
|
||||
if($component->w === NULL and $component->h === NULL) {
|
||||
|
||||
list($width, $height) = $drawer->setSize($component->width, $component->height);
|
||||
|
||||
// Set component size in pixels
|
||||
$component->setAbsSize($width, $height);
|
||||
|
||||
} else {
|
||||
|
||||
$drawer->setAbsSize($component->w, $component->h);
|
||||
|
||||
}
|
||||
|
||||
if($component->top !== NULL and $component->left !== NULL) {
|
||||
$drawer->setAbsPosition(
|
||||
$border + $shadow->left + $component->left,
|
||||
$border + $shadow->top + $component->top
|
||||
);
|
||||
} else {
|
||||
$drawer->setPosition($component->x, $component->y);
|
||||
}
|
||||
|
||||
$drawer->movePosition($border + $shadow->left, $border + $shadow->top);
|
||||
|
||||
list($x1, $y1, $x2, $y2) = $component->getPosition();
|
||||
|
||||
$component->init($drawer);
|
||||
|
||||
$component->drawComponent($drawer, $x1, $y1, $x2, $y2, $this->antiAliasing);
|
||||
$component->drawEnvelope($drawer, $x1, $y1, $x2, $y2);
|
||||
|
||||
$component->finalize($drawer);
|
||||
|
||||
}
|
||||
|
||||
function drawShadow() {
|
||||
|
||||
$drawer = $this->getDrawer();
|
||||
|
||||
$this->shadow->draw(
|
||||
$drawer,
|
||||
new awPoint(0, 0),
|
||||
new awPoint($this->width, $this->height),
|
||||
SHADOW_IN
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the image into a file or to the user browser
|
||||
*
|
||||
* @var string $file Save image into a file if you provide a file name
|
||||
*/
|
||||
function send($file = NULL) {
|
||||
|
||||
// Test if format is available
|
||||
if((imagetypes() & $this->format) === FALSE) {
|
||||
trigger_error("Format '".$this->format."' is not available on your system. Check that your PHP has been compiled with the good libraries.");
|
||||
}
|
||||
|
||||
// Get some infos about this image
|
||||
|
||||
switch($this->format) {
|
||||
case IMAGE_JPEG :
|
||||
$function = 'imagejpeg';
|
||||
break;
|
||||
case IMAGE_PNG :
|
||||
$function = 'imagepng';
|
||||
break;
|
||||
case IMAGE_GIF :
|
||||
$function = 'imagegif';
|
||||
break;
|
||||
}
|
||||
|
||||
// Create image
|
||||
|
||||
if($file !== NULL) {
|
||||
|
||||
$function($this->resource, $file);
|
||||
|
||||
} else {
|
||||
|
||||
// Send headers to the browser
|
||||
if(headers_sent() === FALSE) {
|
||||
header("Content-type: image/".$this->getFormat());
|
||||
}
|
||||
|
||||
$function($this->resource);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getFormat() {
|
||||
|
||||
switch($this->format) {
|
||||
case IMAGE_JPEG :
|
||||
return 'jpeg';
|
||||
case IMAGE_PNG :
|
||||
return 'png';
|
||||
case IMAGE_GIF :
|
||||
return 'gif';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Image');
|
||||
|
||||
|
||||
/**
|
||||
* Load an image from a file
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awFileImage extends awImage {
|
||||
|
||||
/**
|
||||
* Build a new awimage
|
||||
*
|
||||
* @param string $file Image file name
|
||||
*/
|
||||
function awFileImage($file) {
|
||||
|
||||
$image = @getimagesize($file);
|
||||
|
||||
if($image and in_array($image[2], array(2, 3))) {
|
||||
|
||||
$this->setSize($image[0], $image[1]);
|
||||
|
||||
switch($image[2]) {
|
||||
|
||||
case 2 :
|
||||
$this->resource = imagecreatefromjpeg($file);
|
||||
break;
|
||||
|
||||
case 3 :
|
||||
$this->resource = imagecreatefrompng($file);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$this->drawer = new awDrawer($this->resource);
|
||||
$this->drawer->setImageSize($this->width, $this->height);
|
||||
|
||||
} else {
|
||||
trigger_error("Artichow does not support this image (must be in PNG or JPEG)", E_USER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('FileImage');
|
||||
?>
|
||||
@ -1,596 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Plot.class.php";
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("LINEPLOT_LINE", 0);
|
||||
define("LINEPLOT_MIDDLE", 1);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* LinePlot
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLinePlot extends awPlot {
|
||||
|
||||
/**
|
||||
* Add marks to your line plot
|
||||
*
|
||||
* @var Mark
|
||||
*/
|
||||
var $mark;
|
||||
|
||||
/**
|
||||
* Labels on your line plot
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
var $label;
|
||||
|
||||
/**
|
||||
* Filled areas
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $areas = array();
|
||||
|
||||
/**
|
||||
* Is the line hidden
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $lineHide = FALSE;
|
||||
|
||||
/**
|
||||
* Line color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $lineColor;
|
||||
|
||||
/**
|
||||
* Line mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $lineMode = LINEPLOT_LINE;
|
||||
|
||||
/**
|
||||
* Line type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $lineStyle = LINE_SOLID;
|
||||
|
||||
/**
|
||||
* Line thickness
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $lineThickness = 1;
|
||||
|
||||
/**
|
||||
* Line background
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
var $lineBackground;
|
||||
|
||||
/**
|
||||
* Line mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Line in the middle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new awLinePlot
|
||||
*
|
||||
* @param array $values Some numeric values for Y axis
|
||||
* @param int $mode
|
||||
*/
|
||||
function awLinePlot($values, $mode = LINEPLOT_LINE) {
|
||||
|
||||
parent::awPlot();
|
||||
|
||||
$this->mark = new awMark;
|
||||
$this->label = new awLabel;
|
||||
|
||||
$this->lineMode = (int)$mode;
|
||||
|
||||
$this->setValues($values);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide line
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
function hideLine($hide) {
|
||||
$this->lineHide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a filled area
|
||||
*
|
||||
* @param int $start Begining of the area
|
||||
* @param int $end End of the area
|
||||
* @param mixed $background Background color or gradient of the area
|
||||
*/
|
||||
function setFilledArea($start, $stop, $background) {
|
||||
|
||||
if($stop <= $start) {
|
||||
trigger_error("End position can not be greater than begin position in awLinePlot::setFilledArea()", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$this->areas[] = array((int)$start, (int)$stop, $background);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setColor($color) {
|
||||
$this->lineColor = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
function setStyle($style) {
|
||||
$this->lineStyle = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line tickness
|
||||
*
|
||||
* @param int $tickness
|
||||
*/
|
||||
function setThickness($tickness) {
|
||||
$this->lineThickness = (int)$tickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line background color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setFillColor($color) {
|
||||
$this->lineBackground = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line background gradient
|
||||
*
|
||||
* @param $gradient
|
||||
*/
|
||||
function setFillGradient($gradient) {
|
||||
$this->lineBackground = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getLegendLineThickness() {
|
||||
return $this->lineThickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getLegendLineStyle() {
|
||||
return $this->lineStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
function getLegendLineColor() {
|
||||
return $this->lineColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
function getLegendBackground() {
|
||||
return $this->lineBackground;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return Mark
|
||||
*/
|
||||
function getLegendMark() {
|
||||
return $this->mark;
|
||||
}
|
||||
|
||||
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
$max = $this->getRealYMax();
|
||||
$min = $this->getRealYMin();
|
||||
|
||||
// Get start and stop values
|
||||
list($start, $stop) = $this->getLimit();
|
||||
|
||||
if($this->lineMode === LINEPLOT_MIDDLE) {
|
||||
$inc = $this->xAxis->getDistance(0, 1) / 2;
|
||||
} else {
|
||||
$inc = 0;
|
||||
}
|
||||
|
||||
// Build the polygon
|
||||
$polygon = new awPolygon;
|
||||
|
||||
for($key = $start; $key <= $stop; $key++) {
|
||||
|
||||
$value = $this->datay[$key];
|
||||
|
||||
if($value !== NULL) {
|
||||
|
||||
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $value));
|
||||
$p = $p->move($inc, 0);
|
||||
$polygon->set($key, $p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Draw backgrounds
|
||||
if(is_a($this->lineBackground, 'awColor') or is_a($this->lineBackground, 'awGradient')) {
|
||||
|
||||
$backgroundPolygon = new awPolygon;
|
||||
|
||||
$p = $this->xAxisPoint($start);
|
||||
$p = $p->move($inc, 0);
|
||||
$backgroundPolygon->append($p);
|
||||
|
||||
// Add others points
|
||||
foreach($polygon->all() as $point) {
|
||||
$backgroundPolygon->append($point);
|
||||
}
|
||||
|
||||
$p = $this->xAxisPoint($stop);
|
||||
$p = $p->move($inc, 0);
|
||||
$backgroundPolygon->append($p);
|
||||
|
||||
// Draw polygon background
|
||||
$drawer->filledPolygon($this->lineBackground, $backgroundPolygon);
|
||||
|
||||
}
|
||||
|
||||
$this->drawArea($drawer, $polygon);
|
||||
|
||||
// Draw line
|
||||
$prev = NULL;
|
||||
|
||||
// Line color
|
||||
if($this->lineHide === FALSE) {
|
||||
|
||||
if($this->lineColor === NULL) {
|
||||
$this->lineColor = new awColor(0, 0, 0);
|
||||
}
|
||||
|
||||
foreach($polygon->all() as $point) {
|
||||
|
||||
if($prev !== NULL) {
|
||||
$drawer->line(
|
||||
$this->lineColor,
|
||||
new awLine(
|
||||
$prev,
|
||||
$point,
|
||||
$this->lineStyle,
|
||||
$this->lineThickness
|
||||
)
|
||||
);
|
||||
}
|
||||
$prev = $point;
|
||||
|
||||
}
|
||||
|
||||
$this->lineColor->free();
|
||||
|
||||
}
|
||||
|
||||
// Draw marks and labels
|
||||
foreach($polygon->all() as $key => $point) {
|
||||
|
||||
$this->mark->draw($drawer, $point);
|
||||
$this->label->draw($drawer, $point, $key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function drawArea($drawer, &$polygon) {
|
||||
|
||||
$starts = array();
|
||||
foreach($this->areas as $area) {
|
||||
list($start) = $area;
|
||||
$starts[$start] = TRUE;
|
||||
}
|
||||
|
||||
// Draw filled areas
|
||||
foreach($this->areas as $area) {
|
||||
|
||||
list($start, $stop, $background) = $area;
|
||||
|
||||
$polygonArea = new awPolygon;
|
||||
|
||||
$p = $this->xAxisPoint($start);
|
||||
$polygonArea->append($p);
|
||||
|
||||
for($i = $start; $i <= $stop; $i++) {
|
||||
$p = $polygon->get($i);
|
||||
if($i === $stop and array_key_exists($stop, $starts)) {
|
||||
$p = $p->move(-1, 0);
|
||||
}
|
||||
$polygonArea->append($p);
|
||||
}
|
||||
|
||||
$p = $this->xAxisPoint($stop);
|
||||
if(array_key_exists($stop, $starts)) {
|
||||
$p = $p->move(-1, 0);
|
||||
}
|
||||
$polygonArea->append($p);
|
||||
|
||||
// Draw area
|
||||
$drawer->filledPolygon($background, $polygonArea);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getXAxisNumber() {
|
||||
if($this->lineMode === LINEPLOT_MIDDLE) {
|
||||
return count($this->datay) + 1;
|
||||
} else {
|
||||
return count($this->datay);
|
||||
}
|
||||
}
|
||||
|
||||
function xAxisPoint($position) {
|
||||
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
|
||||
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
|
||||
}
|
||||
|
||||
function getXCenter() {
|
||||
return ($this->lineMode === LINEPLOT_MIDDLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('LinePlot');
|
||||
|
||||
|
||||
/**
|
||||
* Simple LinePlot
|
||||
* Useful to draw simple horizontal lines
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awSimpleLinePlot extends awPlot {
|
||||
|
||||
/**
|
||||
* Line color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $lineColor;
|
||||
|
||||
/**
|
||||
* Line start
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $lineStart;
|
||||
|
||||
/**
|
||||
* Line stop
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $lineStop;
|
||||
|
||||
/**
|
||||
* Line value
|
||||
*
|
||||
* @var flaot
|
||||
*/
|
||||
var $lineValue;
|
||||
|
||||
/**
|
||||
* Line mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $lineMode = LINEPLOT_LINE;
|
||||
|
||||
/**
|
||||
* Line type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $lineStyle = LINE_SOLID;
|
||||
|
||||
/**
|
||||
* Line thickness
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $lineThickness = 1;
|
||||
|
||||
/**
|
||||
* Line mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Line in the middle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new awLinePlot
|
||||
*
|
||||
* @param float $value A Y value
|
||||
* @param int $start Line start index
|
||||
* @param int $stop Line stop index
|
||||
* @param int $mode Line mode
|
||||
*/
|
||||
function awSimpleLinePlot($value, $start, $stop, $mode = LINEPLOT_LINE) {
|
||||
|
||||
parent::awPlot();
|
||||
|
||||
$this->lineMode = (int)$mode;
|
||||
|
||||
$this->lineStart = (int)$start;
|
||||
$this->lineStop = (int)$stop;
|
||||
$this->lineValue = (float)$value;
|
||||
|
||||
$this->lineColor = new awColor(0, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setColor($color) {
|
||||
$this->lineColor = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
function setStyle($style) {
|
||||
$this->lineStyle = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line tickness
|
||||
*
|
||||
* @param int $tickness
|
||||
*/
|
||||
function setThickness($tickness) {
|
||||
$this->lineThickness = (int)$tickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getLegendLineThickness() {
|
||||
return $this->lineThickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getLegendLineStyle() {
|
||||
return $this->lineStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
function getLegendLineColor() {
|
||||
return $this->lineColor;
|
||||
}
|
||||
|
||||
function getLegendBackground() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function getLegendMark() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
if($this->lineMode === LINEPLOT_MIDDLE) {
|
||||
$inc = $this->xAxis->getDistance(0, 1) / 2;
|
||||
} else {
|
||||
$inc = 0;
|
||||
}
|
||||
|
||||
$p1 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStart, $this->lineValue));
|
||||
$p2 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStop, $this->lineValue));
|
||||
|
||||
$drawer->line(
|
||||
$this->lineColor,
|
||||
new awLine(
|
||||
$p1->move($inc, 0),
|
||||
$p2->move($inc, 0),
|
||||
$this->lineStyle,
|
||||
$this->lineThickness
|
||||
)
|
||||
);
|
||||
|
||||
$this->lineColor->free();
|
||||
|
||||
}
|
||||
|
||||
function getXAxisNumber() {
|
||||
if($this->lineMode === LINEPLOT_MIDDLE) {
|
||||
return count($this->datay) + 1;
|
||||
} else {
|
||||
return count($this->datay);
|
||||
}
|
||||
}
|
||||
|
||||
function xAxisPoint($position) {
|
||||
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
|
||||
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
|
||||
}
|
||||
|
||||
function getXCenter() {
|
||||
return ($this->lineMode === LINEPLOT_MIDDLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('SimpleLinePlot');
|
||||
?>
|
||||
@ -1,442 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Component.class.php";
|
||||
|
||||
/**
|
||||
* A mathematic function
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awMathFunction {
|
||||
|
||||
/**
|
||||
* Function line
|
||||
*
|
||||
* @var Line
|
||||
*/
|
||||
var $line;
|
||||
|
||||
/**
|
||||
* Marks for your plot
|
||||
*
|
||||
* @var Mark
|
||||
*/
|
||||
var $mark;
|
||||
|
||||
/**
|
||||
* Callback function
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $f;
|
||||
|
||||
/**
|
||||
* Start the drawing from this value
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
var $fromX;
|
||||
|
||||
/**
|
||||
* Stop the drawing at this value
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
var $toX;
|
||||
|
||||
/**
|
||||
* Line color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $color;
|
||||
|
||||
/**
|
||||
* Construct the function
|
||||
*
|
||||
* @param string $f Callback function
|
||||
* @param float $fromX
|
||||
* @param float $toX
|
||||
*/
|
||||
function awMathFunction($f, $fromX = NULL, $toX = NULL) {
|
||||
|
||||
$this->f = (string)$f;
|
||||
$this->fromX = is_null($fromX) ? NULL : (float)$fromX;
|
||||
$this->toX = is_null($toX) ? NULL : (float)$toX;
|
||||
|
||||
$this->line = new awLine;
|
||||
$this->mark = new awMark;
|
||||
$this->color = new awBlack;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line color
|
||||
*
|
||||
* @param $color A new awcolor
|
||||
*/
|
||||
function setColor($color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line color
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
function getColor() {
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
function getLegendBackground() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function getLegendLineThickness() {
|
||||
return $this->line->getThickness();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function getLegendLineStyle() {
|
||||
return $this->line->getStyle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function getLegendLineColor() {
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function getLegendMark() {
|
||||
return $this->mark;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('MathFunction');
|
||||
|
||||
/**
|
||||
* For mathematics functions
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awMathPlot extends awComponent {
|
||||
|
||||
/**
|
||||
* Functions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $functions = array();
|
||||
|
||||
/**
|
||||
* Grid properties
|
||||
*
|
||||
* @var Grid
|
||||
*/
|
||||
var $grid;
|
||||
|
||||
/**
|
||||
* X axis
|
||||
*
|
||||
* @var Axis
|
||||
*/
|
||||
var $xAxis;
|
||||
|
||||
/**
|
||||
* Y axis
|
||||
*
|
||||
* @var Axis
|
||||
*/
|
||||
var $yAxis;
|
||||
|
||||
/**
|
||||
* Extremum
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
var $extremum = NULL;
|
||||
|
||||
/**
|
||||
* Interval
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
var $interval = 1;
|
||||
|
||||
/**
|
||||
* Build the plot
|
||||
*
|
||||
* @param int $xMin Minimum X value
|
||||
* @param int $xMax Maximum X value
|
||||
* @param int $yMax Maximum Y value
|
||||
* @param int $yMin Minimum Y value
|
||||
*/
|
||||
function awMathPlot($xMin, $xMax, $yMax, $yMin) {
|
||||
|
||||
parent::awComponent();
|
||||
|
||||
$this->setPadding(8, 8, 8, 8);
|
||||
|
||||
$this->grid = new awGrid;
|
||||
|
||||
// Hide grid by default
|
||||
$this->grid->hide(TRUE);
|
||||
|
||||
// Set extremum
|
||||
$this->extremum = new awSide($xMin, $xMax, $yMax, $yMin);
|
||||
|
||||
// Create axis
|
||||
$this->xAxis = new awAxis;
|
||||
$this->xAxis->setTickStyle(TICK_IN);
|
||||
$this->xAxis->label->hideValue(0);
|
||||
$this->initAxis($this->xAxis);
|
||||
|
||||
$this->yAxis = new awAxis;
|
||||
$this->yAxis->setTickStyle(TICK_IN);
|
||||
$this->yAxis->label->hideValue(0);
|
||||
$this->initAxis($this->yAxis);
|
||||
|
||||
}
|
||||
|
||||
function initAxis(&$axis) {
|
||||
// DOL_CHANGE LDR Fix to allow usage of other fonts
|
||||
global $artichow_defaultfont;
|
||||
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
|
||||
|
||||
$axis->setLabelPrecision(1);
|
||||
$axis->addTick('major', new awTick(0, 5));
|
||||
$axis->addTick('minor', new awTick(0, 3));
|
||||
$axis->addTick('micro', new awTick(0, 1));
|
||||
$axis->setNumberByTick('minor', 'major', 1);
|
||||
$axis->setNumberByTick('micro', 'minor', 4);
|
||||
$axis->label->setFont(new $classfontname(7));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Interval to calculate values
|
||||
*
|
||||
* @param float $interval
|
||||
*/
|
||||
function setInterval($interval) {
|
||||
$this->interval = (float)$interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a formula f(x)
|
||||
*
|
||||
* @param &$function
|
||||
* @param string $name Name for the legend (can be NULL if you don't want to set a legend)
|
||||
* @param int $type Type for the legend
|
||||
*/
|
||||
function add(&$function, $name = NULL, $type = LEGEND_LINE) {
|
||||
|
||||
$this->functions[] = $function;
|
||||
|
||||
if($name !== NULL) {
|
||||
$this->legend->add($function, $name, $type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function init($drawer) {
|
||||
|
||||
list($x1, $y1, $x2, $y2) = $this->getPosition();
|
||||
|
||||
$this->xAxis->line->setX($x1, $x2);
|
||||
$this->xAxis->label->setAlign(NULL, LABEL_BOTTOM);
|
||||
$this->xAxis->label->move(0, 3);
|
||||
$this->xAxis->setRange($this->extremum->left, $this->extremum->right);
|
||||
|
||||
$this->yAxis->line->setY($y2, $y1);
|
||||
$this->yAxis->label->setAlign(LABEL_RIGHT);
|
||||
$this->yAxis->label->move(-6, 0);
|
||||
$this->yAxis->reverseTickStyle();
|
||||
$this->yAxis->setRange($this->extremum->bottom, $this->extremum->top);
|
||||
|
||||
|
||||
$this->xAxis->setYCenter($this->yAxis, 0);
|
||||
$this->yAxis->setXCenter($this->xAxis, 0);
|
||||
|
||||
if($this->yAxis->getLabelNumber() === NULL) {
|
||||
$number = $this->extremum->top - $this->extremum->bottom + 1;
|
||||
$this->yAxis->setLabelNumber($number);
|
||||
}
|
||||
|
||||
if($this->xAxis->getLabelNumber() === NULL) {
|
||||
$number = $this->extremum->right - $this->extremum->left + 1;
|
||||
$this->xAxis->setLabelNumber($number);
|
||||
}
|
||||
|
||||
// Set ticks
|
||||
|
||||
$this->xAxis->ticks['major']->setNumber($this->xAxis->getLabelNumber());
|
||||
$this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber());
|
||||
|
||||
|
||||
// Set axis labels
|
||||
$labels = array();
|
||||
for($i = 0, $count = $this->xAxis->getLabelNumber(); $i < $count; $i++) {
|
||||
$labels[] = $i;
|
||||
}
|
||||
$this->xAxis->label->set($labels);
|
||||
|
||||
$labels = array();
|
||||
for($i = 0, $count = $this->yAxis->getLabelNumber(); $i < $count; $i++) {
|
||||
$labels[] = $i;
|
||||
}
|
||||
$this->yAxis->label->set($labels);
|
||||
|
||||
parent::init($drawer);
|
||||
|
||||
// Create the grid
|
||||
$this->createGrid();
|
||||
|
||||
// Draw the grid
|
||||
$this->grid->draw($drawer, $x1, $y1, $x2, $y2);
|
||||
|
||||
}
|
||||
|
||||
function drawEnvelope($drawer) {
|
||||
|
||||
// Draw axis
|
||||
$this->xAxis->draw($drawer);
|
||||
$this->yAxis->draw($drawer);
|
||||
|
||||
}
|
||||
|
||||
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
foreach($this->functions as $function) {
|
||||
|
||||
$f = $function->f;
|
||||
$fromX = is_null($function->fromX) ? $this->extremum->left : $function->fromX;
|
||||
$toX = is_null($function->toX) ? $this->extremum->right : $function->toX;
|
||||
|
||||
$old = NULL;
|
||||
|
||||
for($i = $fromX; $i <= $toX; $i += $this->interval) {
|
||||
|
||||
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($i, $f($i)));
|
||||
|
||||
if($p->y >= $y1 and $p->y <= $y2) {
|
||||
$function->mark->draw($drawer, $p);
|
||||
}
|
||||
|
||||
if($old !== NULL) {
|
||||
|
||||
$line = $function->line;
|
||||
$line->setLocation($old, $p);
|
||||
|
||||
if(
|
||||
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
|
||||
($line->p2->y >= $y1 and $line->p2->y <= $y2)
|
||||
) {
|
||||
$drawer->line(
|
||||
$function->getColor(),
|
||||
$line
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$old = $p;
|
||||
|
||||
}
|
||||
|
||||
// Draw last point if needed
|
||||
if($old !== NULL and $i - $this->interval != $toX) {
|
||||
|
||||
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($toX, $f($toX)));
|
||||
|
||||
if($p->y >= $y1 and $p->y <= $y2) {
|
||||
$function->mark->draw($drawer, $p);
|
||||
}
|
||||
|
||||
|
||||
$line = $function->line;
|
||||
$line->setLocation($old, $p);
|
||||
|
||||
if(
|
||||
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
|
||||
($line->p2->y >= $y1 and $line->p2->y <= $y2)
|
||||
) {
|
||||
$drawer->line(
|
||||
$function->getColor(),
|
||||
$line
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function createGrid() {
|
||||
|
||||
// Horizontal lines of the grid
|
||||
|
||||
$major = $this->yAxis->tick('major');
|
||||
$interval = $major->getInterval();
|
||||
$number = $this->yAxis->getLabelNumber() - 1;
|
||||
|
||||
$h = array();
|
||||
if($number > 0) {
|
||||
for($i = 0; $i <= $number; $i++) {
|
||||
$h[] = $i / $number;
|
||||
}
|
||||
}
|
||||
|
||||
// Vertical lines
|
||||
|
||||
$major = $this->xAxis->tick('major');
|
||||
$interval = $major->getInterval();
|
||||
$number = $this->xAxis->getLabelNumber() - 1;
|
||||
|
||||
$w = array();
|
||||
if($number > 0) {
|
||||
for($i = 0; $i <= $number; $i++) {
|
||||
if($i%$interval === 0) {
|
||||
$w[] = $i / $number;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->grid->setGrid($w, $h);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('MathPlot');
|
||||
?>
|
||||
@ -1,97 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Graph.class.php";
|
||||
|
||||
/**
|
||||
* All patterns must derivate from this class
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPattern {
|
||||
|
||||
/**
|
||||
* Pattern arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $args = array();
|
||||
|
||||
/**
|
||||
* Load a pattern
|
||||
*
|
||||
* @param string $pattern Pattern name
|
||||
* @return Component
|
||||
*/
|
||||
function get($pattern) {
|
||||
|
||||
$file = ARTICHOW_PATTERN.DIRECTORY_SEPARATOR.$pattern.'.php';
|
||||
|
||||
if(is_file($file)) {
|
||||
|
||||
require_once $file;
|
||||
|
||||
$class = $pattern.'Pattern';
|
||||
|
||||
if(class_exists($class)) {
|
||||
return new $class;
|
||||
} else {
|
||||
trigger_error("Class '".$class."' does not exist", E_USER_ERROR);
|
||||
}
|
||||
|
||||
} else {
|
||||
trigger_error("Pattern '".$pattern."' does not exist", E_USER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change pattern argument
|
||||
*
|
||||
* @param string $name Argument name
|
||||
* @param mixed $value Argument value
|
||||
*/
|
||||
function setArg($name, $value) {
|
||||
if(is_string($name)) {
|
||||
$this->args[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $default Default value if the argument does not exist (default to NULL)
|
||||
* @return mixed Argument value
|
||||
*/
|
||||
function getArg($name, $default = NULL) {
|
||||
if(array_key_exists($name, $this->args)) {
|
||||
return $this->args[$name];
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change several arguments
|
||||
*
|
||||
* @param array $args New arguments
|
||||
*/
|
||||
function setArgs($args) {
|
||||
if(is_array($args)) {
|
||||
foreach($args as $name => $value) {
|
||||
$this->setArg($name, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Pattern', TRUE);
|
||||
?>
|
||||
@ -1,680 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Component.class.php";
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("PIE_DARK", 1);
|
||||
define("PIE_COLORED", 2);
|
||||
define("PIE_AQUA", 3);
|
||||
define("PIE_EARTH", 4);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Pie
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPie extends awComponent {
|
||||
|
||||
/**
|
||||
* A dark theme for pies
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* A colored theme for pies
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* A water theme for pies
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* A earth theme for pies
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Pie values
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $values;
|
||||
|
||||
/**
|
||||
* Pie colors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $colors;
|
||||
|
||||
/**
|
||||
* Pie legend
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $legendValues = array();
|
||||
|
||||
/**
|
||||
* Intensity of the 3D effect
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $size;
|
||||
|
||||
/**
|
||||
* Border color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $border;
|
||||
|
||||
/**
|
||||
* Pie explode
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $explode = array();
|
||||
|
||||
/**
|
||||
* Initial angle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $angle = 0;
|
||||
|
||||
/**
|
||||
* Labels precision
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $precision;
|
||||
|
||||
/**
|
||||
* Labels number
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $number;
|
||||
|
||||
/**
|
||||
* Labels minimum
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $minimum;
|
||||
|
||||
/**
|
||||
* Labels position
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $position = 15;
|
||||
|
||||
/**
|
||||
* Labels of your pie
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
var $label;
|
||||
|
||||
/**
|
||||
* Build the plot
|
||||
*
|
||||
* @param array $values Pie values
|
||||
*/
|
||||
function awPie($values, $colors = PIE_COLORED) {
|
||||
|
||||
$this->setValues($values);
|
||||
|
||||
if(is_array($colors)) {
|
||||
$this->colors = $colors;
|
||||
} else {
|
||||
|
||||
switch($colors) {
|
||||
|
||||
case PIE_AQUA :
|
||||
$this->colors = array(
|
||||
new awColor(131, 220, 215),
|
||||
new awColor(131, 190, 215),
|
||||
new awColor(131, 160, 215),
|
||||
new awColor(160, 140, 215),
|
||||
new awColor(190, 131, 215),
|
||||
new awColor(220, 131, 215)
|
||||
);
|
||||
break;
|
||||
|
||||
case PIE_EARTH :
|
||||
$this->colors = array(
|
||||
new awColor(97, 179, 110),
|
||||
new awColor(130, 179, 97),
|
||||
new awColor(168, 179, 97),
|
||||
new awColor(179, 147, 97),
|
||||
new awColor(179, 108, 97),
|
||||
new awColor(99, 107, 189),
|
||||
new awColor(99, 165, 189)
|
||||
);
|
||||
break;
|
||||
|
||||
case PIE_DARK :
|
||||
$this->colors = array(
|
||||
new awColor(140, 100, 170),
|
||||
new awColor(130, 170, 100),
|
||||
new awColor(160, 160, 120),
|
||||
new awColor(150, 110, 140),
|
||||
new awColor(130, 150, 160),
|
||||
new awColor(90, 170, 140)
|
||||
);
|
||||
break;
|
||||
|
||||
default :
|
||||
$this->colors = array(
|
||||
new awColor(187, 213, 151),
|
||||
new awColor(223, 177, 151),
|
||||
new awColor(111, 186, 132),
|
||||
new awColor(197, 160, 230),
|
||||
new awColor(165, 169, 63),
|
||||
new awColor(218, 177, 89),
|
||||
new awColor(116, 205, 121),
|
||||
new awColor(200, 201, 78),
|
||||
new awColor(127, 205, 177),
|
||||
new awColor(205, 160, 160),
|
||||
new awColor(190, 190, 190)
|
||||
);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
parent::awComponent();
|
||||
|
||||
$this->label = new awLabel;
|
||||
$this->label->setCallbackFunction('callbackPerCent');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change legend values
|
||||
*
|
||||
* @param array $legend An array of values for each part of the pie
|
||||
*/
|
||||
function setLegend($legend) {
|
||||
|
||||
$this->legendValues = (array)$legend;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a border all around the pie
|
||||
*
|
||||
* @param $color A color for the border
|
||||
*/
|
||||
function setBorder($color) {
|
||||
$this->border = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change 3D effect intensity
|
||||
*
|
||||
* @param int $size Effect size
|
||||
*/
|
||||
function set3D($size) {
|
||||
$this->size = (int)$size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change initial angle
|
||||
*
|
||||
* @param int $angle New angle in degrees
|
||||
*/
|
||||
function setStartAngle($angle) {
|
||||
$this->angle = (int)$angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label precision
|
||||
*
|
||||
* @param int $precision New precision
|
||||
*/
|
||||
function setLabelPrecision($precision) {
|
||||
$this->precision = (int)$precision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label position
|
||||
*
|
||||
* @param int $position New position in pixels
|
||||
*/
|
||||
function setLabelPosition($position) {
|
||||
$this->position = (int)$position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label number
|
||||
*
|
||||
* @param int $number New number
|
||||
*/
|
||||
function setLabelNumber($number) {
|
||||
$this->number = is_null($number) ? $number : (int)$number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label minimum
|
||||
*
|
||||
* @param int $minimum New minimum
|
||||
*/
|
||||
function setLabelMinimum($minimum) {
|
||||
$this->minimum = is_null($minimum) ? $minimum : (int)$minimum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Pie explode
|
||||
*
|
||||
* @param array $explode
|
||||
*/
|
||||
function explode($explode) {
|
||||
$this->explode = (array)$explode;
|
||||
}
|
||||
|
||||
function drawEnvelope($drawer) {
|
||||
|
||||
}
|
||||
|
||||
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
$count = count($this->values);
|
||||
$sum = array_sum($this->values);
|
||||
|
||||
$width = $x2 - $x1;
|
||||
$height = $y2 - $y1;
|
||||
|
||||
if($aliasing) {
|
||||
$x = $width / 2;
|
||||
$y = $height / 2;
|
||||
} else {
|
||||
$x = $width / 2 + $x1;
|
||||
$y = $height / 2 + $y1;
|
||||
}
|
||||
|
||||
$position = $this->angle;
|
||||
$values = array();
|
||||
$parts = array();
|
||||
$angles = 0;
|
||||
|
||||
if($aliasing) {
|
||||
$side = new awSide(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
foreach($this->values as $key => $value) {
|
||||
|
||||
$angle = ($value / $sum * 360);
|
||||
|
||||
if($key === $count - 1) {
|
||||
$angle = 360 - $angles;
|
||||
}
|
||||
|
||||
$angles += $angle;
|
||||
|
||||
if(array_key_exists($key, $this->explode)) {
|
||||
$middle = 360 - ($position + $angle / 2);
|
||||
$posX = $this->explode[$key] * cos($middle * M_PI / 180);
|
||||
$posY = $this->explode[$key] * sin($middle * M_PI / 180) * -1;
|
||||
|
||||
if($aliasing) {
|
||||
$explode = new awPoint(
|
||||
$posX * 2,
|
||||
$posY * 2
|
||||
);
|
||||
$side->set(
|
||||
max($side->left, $posX * -2),
|
||||
max($side->right, $posX * 2),
|
||||
max($side->top, $posY * -2),
|
||||
max($side->bottom, $posY * 2)
|
||||
);
|
||||
} else {
|
||||
$explode = new awPoint(
|
||||
$posX,
|
||||
$posY
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
$explode = new awPoint(0, 0);
|
||||
}
|
||||
|
||||
$values[$key] = array(
|
||||
$position, ($position + $angle), $explode
|
||||
);
|
||||
|
||||
$color = $this->colors[$key % count($this->colors)];
|
||||
$parts[$key] = new awPiePart($color);
|
||||
|
||||
// Add part to the legend
|
||||
$legend = array_key_exists($key, $this->legendValues) ? $this->legendValues[$key] : $key;
|
||||
$this->legend->add($parts[$key], $legend, LEGEND_BACKGROUND);
|
||||
|
||||
$position += $angle;
|
||||
|
||||
}
|
||||
|
||||
if($aliasing) {
|
||||
|
||||
$mainDrawer = $drawer;
|
||||
|
||||
$x *= 2;
|
||||
$y *= 2;
|
||||
$width *= 2;
|
||||
$height *= 2;
|
||||
$this->size *= 2;
|
||||
|
||||
$image = new awImage;
|
||||
$image->border->hide();
|
||||
$image->setSize(
|
||||
$width + $side->left + $side->right,
|
||||
$height + $side->top + $side->bottom + $this->size + 1 /* bugs.php.net ! */
|
||||
);
|
||||
|
||||
$drawer = $image->getDrawer(
|
||||
$width / $image->width,
|
||||
$height / $image->height,
|
||||
($width / 2 + $side->left) / $image->width,
|
||||
($height / 2 + $side->top) / $image->height
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// Draw 3D effect
|
||||
for($i = $this->size; $i > 0; $i--) {
|
||||
|
||||
foreach($values as $key => $value) {
|
||||
|
||||
$color = $this->colors[$key % count($this->colors)];
|
||||
$color->brightness(-50);
|
||||
|
||||
list($from, $to, $explode) = $value;
|
||||
|
||||
$drawer->filledArc($color, $explode->move($x, $y + $i), $width, $height, $from, $to);
|
||||
|
||||
$color->free();
|
||||
unset($color);
|
||||
|
||||
if(is_a($this->border, 'awColor')) {
|
||||
|
||||
$point = $explode->move($x, $y);
|
||||
|
||||
if($i === $this->size) {
|
||||
|
||||
$drawer->arc($this->border, $point->move(0, $this->size), $width, $height, $from, $to);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach($values as $key => $value) {
|
||||
|
||||
$color = $this->colors[$key % count($this->colors)];
|
||||
|
||||
list($from, $to, $explode) = $value;
|
||||
|
||||
$drawer->filledArc($color, $explode->move($x, $y), $width, $height, $from, $to);
|
||||
|
||||
if(is_a($this->border, 'awColor')) {
|
||||
|
||||
$point = $explode->move($x, $y);
|
||||
$drawer->arc($this->border, $point, $width, $height, $from, $to);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($aliasing) {
|
||||
|
||||
$x = $x / 2 + $x1;
|
||||
$y = $y / 2 + $y1;
|
||||
$width /= 2;
|
||||
$height /= 2;
|
||||
$this->size /= 2;
|
||||
|
||||
foreach($values as $key => $value) {
|
||||
$old = $values[$key][2];
|
||||
$values[$key][2] = new awPoint(
|
||||
$old->x / 2, $old->y / 2
|
||||
);
|
||||
}
|
||||
|
||||
$mainDrawer->copyResizeImage(
|
||||
$image,
|
||||
new awPoint($x1 - $side->left / 2, $y1 - $side->top / 2),
|
||||
new awPoint($x1 - $side->left / 2 + $image->width / 2, $y1 - $side->top / 2 + $image->height/ 2),
|
||||
new awPoint(0, 0),
|
||||
new awPoint($image->width, $image->height),
|
||||
TRUE
|
||||
);
|
||||
|
||||
$drawer = $mainDrawer;
|
||||
|
||||
}
|
||||
|
||||
// Get labels values
|
||||
$pc = array();
|
||||
foreach($this->values as $key => $value) {
|
||||
$pc[$key] = round($value / $sum * 100, $this->precision);
|
||||
}
|
||||
if($this->label->count() === 0) { // Check that there is no user defined values
|
||||
$this->label->set($pc);
|
||||
}
|
||||
|
||||
$position = 0;
|
||||
|
||||
foreach($pc as $key => $value) {
|
||||
|
||||
// Limit number of labels to display
|
||||
if($position === $this->number) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(is_null($this->minimum) === FALSE and $value < $this->minimum) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$position++;
|
||||
|
||||
list($from, $to, $explode) = $values[$key];
|
||||
|
||||
$angle = $from + ($to - $from) / 2;
|
||||
$angleRad = (360 - $angle) * M_PI / 180;
|
||||
|
||||
$point = new awPoint(
|
||||
$x + $explode->x + cos($angleRad) * ($width / 2 + $this->position),
|
||||
$y + $explode->y - sin($angleRad) * ($height / 2 + $this->position)
|
||||
);
|
||||
|
||||
$angle %= 360;
|
||||
|
||||
// We don't display labels on the 3D effect
|
||||
if($angle > 0 and $angle < 180) {
|
||||
$point = $point->move(0, -1 * sin($angleRad) * $this->size);
|
||||
}
|
||||
|
||||
if($angle >= 45 and $angle < 135) {
|
||||
$this->label->setAlign(LABEL_CENTER, LABEL_BOTTOM);
|
||||
} else if($angle >= 135 and $angle < 225) {
|
||||
$this->label->setAlign(LABEL_RIGHT, LABEL_MIDDLE);
|
||||
} else if($angle >= 225 and $angle < 315) {
|
||||
$this->label->setAlign(LABEL_CENTER, LABEL_TOP);
|
||||
} else {
|
||||
$this->label->setAlign(LABEL_LEFT, LABEL_MIDDLE);
|
||||
}
|
||||
|
||||
$this->label->draw(
|
||||
$drawer,
|
||||
$point,
|
||||
$key
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return margins around the component
|
||||
*
|
||||
* @return array Left, right, top and bottom margins
|
||||
*/
|
||||
function getMargin() {
|
||||
|
||||
// Get axis informations
|
||||
|
||||
$leftAxis = $this->padding->left;
|
||||
$rightAxis = $this->padding->right;
|
||||
$topAxis = $this->padding->top;
|
||||
$bottomAxis = $this->padding->bottom;
|
||||
|
||||
return array($leftAxis, $rightAxis, $topAxis, $bottomAxis);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change values of Y axis
|
||||
* This method ignores not numeric values
|
||||
*
|
||||
* @param array $values
|
||||
*/
|
||||
function setValues($values) {
|
||||
|
||||
$this->checkArray($values);
|
||||
$this->values = $values;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return values of Y axis
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getValues() {
|
||||
return $this->values;
|
||||
}
|
||||
|
||||
function checkArray(&$array) {
|
||||
|
||||
if(is_array($array) === FALSE) {
|
||||
trigger_error("You tried to set values that are not an array");
|
||||
}
|
||||
|
||||
foreach($array as $key => $value) {
|
||||
if(is_numeric($value) === FALSE) {
|
||||
unset($array[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if(count($array) < 1) {
|
||||
trigger_error("Your graph must have at least 1 value");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Pie');
|
||||
|
||||
/**
|
||||
* Pie
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPiePart {
|
||||
|
||||
/**
|
||||
* Pie part color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $color;
|
||||
|
||||
/**
|
||||
* Build a new awPiePart
|
||||
*
|
||||
* @param $color Pie part color
|
||||
*/
|
||||
function awPiePart($color) {
|
||||
|
||||
$this->color = $color;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
function getLegendBackground() {
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function getLegendLineThickness() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function getLegendLineStyle() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function getLegendLineColor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
function getLegendMark() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('PiePart');
|
||||
|
||||
function callbackPerCent($value) {
|
||||
return $value.'%';
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,303 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Plot.class.php";
|
||||
|
||||
/**
|
||||
* ScatterPlot
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awScatterPlot extends awPlot {
|
||||
|
||||
/**
|
||||
* Add marks to the scatter plot
|
||||
*
|
||||
* @var Mark
|
||||
*/
|
||||
var $mark;
|
||||
|
||||
/**
|
||||
* Labels on the plot
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
var $label;
|
||||
|
||||
/**
|
||||
* Link points ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $link = FALSE;
|
||||
|
||||
/**
|
||||
* Display impulses
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $impulse = NULL;
|
||||
|
||||
/**
|
||||
* Link NULL points ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $linkNull = FALSE;
|
||||
|
||||
/**
|
||||
* Line color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $lineColor;
|
||||
|
||||
/**
|
||||
* Line type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $lineStyle = LINE_SOLID;
|
||||
|
||||
/**
|
||||
* Line thickness
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $lineThickness = 1;
|
||||
|
||||
/**
|
||||
* Construct a new awScatterPlot
|
||||
*
|
||||
* @param array $datay Numeric values for Y axis
|
||||
* @param array $datax Numeric values for X axis
|
||||
* @param int $mode
|
||||
*/
|
||||
function awScatterPlot($datay, $datax = NULL) {
|
||||
|
||||
parent::awPlot();
|
||||
|
||||
// Defaults marks
|
||||
$this->mark = new awMark;
|
||||
$this->mark->setType(MARK_CIRCLE);
|
||||
$this->mark->setSize(7);
|
||||
$this->mark->border->show();
|
||||
|
||||
$this->label = new awLabel;
|
||||
|
||||
$this->setValues($datay, $datax);
|
||||
$this->setColor(new awBlack);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display plot as impulses
|
||||
*
|
||||
* @param $impulse Impulses color (or NULL to disable impulses)
|
||||
*/
|
||||
function setImpulse($color) {
|
||||
$this->impulse = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link scatter plot points
|
||||
*
|
||||
* @param bool $link
|
||||
* @param $color Line color (default to black)
|
||||
*/
|
||||
function link($link, $color = NULL) {
|
||||
$this->link = (bool)$link;
|
||||
if(is_a($color, 'awColor')) {
|
||||
$this->setColor($color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore null values for Y data and continue linking
|
||||
*
|
||||
* @param bool $link
|
||||
*/
|
||||
function linkNull($link) {
|
||||
$this->linkNull = (bool)$link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setColor($color) {
|
||||
$this->lineColor = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
function setStyle($style) {
|
||||
$this->lineStyle = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line tickness
|
||||
*
|
||||
* @param int $tickness
|
||||
*/
|
||||
function setThickness($tickness) {
|
||||
$this->lineThickness = (int)$tickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getLegendLineThickness() {
|
||||
return $this->lineThickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getLegendLineStyle() {
|
||||
return $this->lineStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
function getLegendLineColor() {
|
||||
return $this->lineColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
function getLegendBackground() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return Mark
|
||||
*/
|
||||
function getLegendMark() {
|
||||
return $this->mark;
|
||||
}
|
||||
|
||||
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
$count = count($this->datay);
|
||||
|
||||
// Get start and stop values
|
||||
list($start, $stop) = $this->getLimit();
|
||||
|
||||
// Build the polygon
|
||||
$polygon = new awPolygon;
|
||||
|
||||
for($key = 0; $key < $count; $key++) {
|
||||
|
||||
$x = $this->datax[$key];
|
||||
$y = $this->datay[$key];
|
||||
|
||||
if($y !== NULL) {
|
||||
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($x, $y));
|
||||
$polygon->set($key, $p);
|
||||
} else if($this->linkNull === FALSE) {
|
||||
$polygon->set($key, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Link points if needed
|
||||
if($this->link) {
|
||||
|
||||
$prev = NULL;
|
||||
|
||||
foreach($polygon->all() as $point) {
|
||||
|
||||
if($prev !== NULL and $point !== NULL) {
|
||||
$drawer->line(
|
||||
$this->lineColor,
|
||||
new awLine(
|
||||
$prev,
|
||||
$point,
|
||||
$this->lineStyle,
|
||||
$this->lineThickness
|
||||
)
|
||||
);
|
||||
}
|
||||
$prev = $point;
|
||||
|
||||
}
|
||||
|
||||
$this->lineColor->free();
|
||||
|
||||
}
|
||||
|
||||
// Draw impulses
|
||||
if(is_a($this->impulse, 'awColor')) {
|
||||
|
||||
foreach($polygon->all() as $key => $point) {
|
||||
|
||||
if($point !== NULL) {
|
||||
|
||||
$zero = awAxis::toPosition(
|
||||
$this->xAxis,
|
||||
$this->yAxis,
|
||||
new awPoint($key, 0)
|
||||
);
|
||||
|
||||
$drawer->line(
|
||||
$this->impulse,
|
||||
new awLine(
|
||||
$zero,
|
||||
$point,
|
||||
LINE_SOLID,
|
||||
1
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Draw marks and labels
|
||||
foreach($polygon->all() as $key => $point) {
|
||||
|
||||
$this->mark->draw($drawer, $point);
|
||||
$this->label->draw($drawer, $point, $key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function xAxisPoint($position) {
|
||||
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
|
||||
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
|
||||
}
|
||||
|
||||
function getXCenter() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('ScatterPlot');
|
||||
?>
|
||||
@ -1,102 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Get the minimum of an array and ignore non numeric values
|
||||
*/
|
||||
function array_min($array) {
|
||||
|
||||
if(is_array($array) and count($array) > 0) {
|
||||
|
||||
do {
|
||||
$min = array_pop($array);
|
||||
if(is_numeric($min === FALSE)) {
|
||||
$min = NULL;
|
||||
}
|
||||
} while(count($array) > 0 and $min === NULL);
|
||||
|
||||
if($min !== NULL) {
|
||||
$min = (float)$min;
|
||||
}
|
||||
|
||||
foreach($array as $value) {
|
||||
if(is_numeric($value) and (float)$value < $min) {
|
||||
$min = (float)$value;
|
||||
}
|
||||
}
|
||||
|
||||
return $min;
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the maximum of an array and ignore non numeric values
|
||||
*/
|
||||
function array_max($array) {
|
||||
|
||||
if(is_array($array) and count($array) > 0) {
|
||||
|
||||
do {
|
||||
$max = array_pop($array);
|
||||
if(is_numeric($max === FALSE)) {
|
||||
$max = NULL;
|
||||
}
|
||||
} while(count($array) > 0 and $max === NULL);
|
||||
|
||||
if($max !== NULL) {
|
||||
$max = (float)$max;
|
||||
}
|
||||
|
||||
foreach($array as $value) {
|
||||
if(is_numeric($value) and (float)$value > $max) {
|
||||
$max = (float)$value;
|
||||
}
|
||||
}
|
||||
|
||||
return $max;
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Register a class with the prefix in configuration file
|
||||
*/
|
||||
function registerClass($class, $abstract = FALSE) {
|
||||
|
||||
if(ARTICHOW_PREFIX === 'aw') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$abstract = '';
|
||||
|
||||
|
||||
eval($abstract." class ".ARTICHOW_PREFIX.$class." extends aw".$class." { }");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Register an interface with the prefix in configuration file
|
||||
*/
|
||||
function registerInterface($interface) {
|
||||
|
||||
if(ARTICHOW_PREFIX === 'aw') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
@ -1,769 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle axis
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awAxis {
|
||||
|
||||
/**
|
||||
* Axis line
|
||||
*
|
||||
* @var Line
|
||||
*/
|
||||
var $line;
|
||||
|
||||
/**
|
||||
* Axis labels
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
var $label;
|
||||
|
||||
/**
|
||||
* Axis title
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
var $title;
|
||||
|
||||
/**
|
||||
* Title position
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
var $titlePosition = 0.5;
|
||||
|
||||
/**
|
||||
* Labels number
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $labelNumber;
|
||||
|
||||
/**
|
||||
* Axis ticks
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $ticks = array();
|
||||
|
||||
/**
|
||||
* Axis and ticks color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $color;
|
||||
|
||||
/**
|
||||
* Axis left and right padding
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
var $padding;
|
||||
|
||||
/**
|
||||
* Axis range
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $range;
|
||||
|
||||
/**
|
||||
* Hide axis
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Auto-scaling mode
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $auto = TRUE;
|
||||
|
||||
/**
|
||||
* Axis range callback function
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $rangeCallback = array(
|
||||
'toValue' => 'toProportionalValue',
|
||||
'toPosition' => 'toProportionalPosition'
|
||||
);
|
||||
|
||||
/**
|
||||
* Build the axis
|
||||
*
|
||||
* @param float $min Begin of the range of the axis
|
||||
* @param float $max End of the range of the axis
|
||||
*/
|
||||
function awAxis($min = NULL, $max = NULL) {
|
||||
|
||||
$this->line = new awVector(
|
||||
new awPoint(0, 0),
|
||||
new awPoint(0, 0)
|
||||
);
|
||||
|
||||
$this->label = new awLabel;
|
||||
$this->padding = new awSide;
|
||||
|
||||
$this->title = new awLabel(
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
|
||||
$this->setColor(new awBlack);
|
||||
|
||||
if($min !== NULL and $max !== NULL) {
|
||||
$this->setRange($min, $max);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable auto-scaling mode
|
||||
*
|
||||
* @param bool $auto
|
||||
*/
|
||||
function auto($auto) {
|
||||
$this->auto = (bool)$auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get auto-scaling mode status
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isAuto() {
|
||||
return $this->auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide axis
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show axis
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
function show($show = TRUE) {
|
||||
$this->hide = !(bool)$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a tick object from its name
|
||||
*
|
||||
* @param string $name Tick object name
|
||||
* @return Tick
|
||||
*/
|
||||
function tick($name) {
|
||||
|
||||
if(array_key_exists($name, $this->ticks)) {
|
||||
return $tick = &$this->ticks[$name];
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a tick object
|
||||
*
|
||||
* @param string $name Tick object name
|
||||
* @param &$tick Tick object
|
||||
*/
|
||||
function addTick($name, &$tick) {
|
||||
|
||||
$this->ticks[$name] = &$tick;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a tick object
|
||||
*
|
||||
* @param string $name Tick object name
|
||||
*/
|
||||
function deleteTick($name) {
|
||||
if(array_key_exists($name, $this->ticks)) {
|
||||
unset($this->ticks[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide all ticks
|
||||
*
|
||||
* @param bool $hide Hide or not ?
|
||||
*/
|
||||
function hideTicks($hide = TRUE) {
|
||||
|
||||
foreach($this->ticks as $key => $tick) {
|
||||
$this->ticks[$key]->hide($hide);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks style
|
||||
*
|
||||
* @param int $style Ticks style
|
||||
*/
|
||||
function setTickStyle($style) {
|
||||
|
||||
foreach($this->ticks as $key => $tick) {
|
||||
$this->ticks[$key]->setStyle($style);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks interval
|
||||
*
|
||||
* @param int $interval Ticks interval
|
||||
*/
|
||||
function setTickInterval($interval) {
|
||||
|
||||
foreach($this->ticks as $key => $tick) {
|
||||
$this->ticks[$key]->setInterval($interval);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of ticks relative to others ticks
|
||||
*
|
||||
* @param &$to Change number of theses ticks
|
||||
* @param &$from Ticks reference
|
||||
* @param float $number Number of ticks by the reference
|
||||
*/
|
||||
function setNumberByTick($to, $from, $number) {
|
||||
$this->ticks[$to]->setNumberByTick($this->ticks[$from], $number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse ticks style
|
||||
*/
|
||||
function reverseTickStyle() {
|
||||
|
||||
foreach($this->ticks as $key => $tick) {
|
||||
if($this->ticks[$key]->getStyle() === TICK_IN) {
|
||||
$this->ticks[$key]->setStyle(TICK_OUT);
|
||||
} else if($this->ticks[$key]->getStyle() === TICK_OUT) {
|
||||
$this->ticks[$key]->setStyle(TICK_IN);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change interval of labels
|
||||
*
|
||||
* @param int $interval Interval
|
||||
*/
|
||||
function setLabelInterval($interval) {
|
||||
$this->auto(FALSE);
|
||||
$this->setTickInterval($interval);
|
||||
$this->label->setInterval($interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of labels
|
||||
*
|
||||
* @param int $number Number of labels to display (can be NULL)
|
||||
*/
|
||||
function setLabelNumber($number) {
|
||||
$this->auto(FALSE);
|
||||
$this->labelNumber = is_null($number) ? NULL : (int)$number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of labels
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getLabelNumber() {
|
||||
return $this->labelNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change precision of labels
|
||||
*
|
||||
* @param int $precision Precision
|
||||
*/
|
||||
function setLabelPrecision($precision) {
|
||||
$this->auto(FALSE);
|
||||
$function = 'axis'.time().'_'.(microtime() * 1000000);
|
||||
eval('function '.$function.'($value) {
|
||||
return sprintf("%.'.(int)$precision.'f", $value);
|
||||
}');
|
||||
$this->label->setCallbackFunction($function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text of labels
|
||||
*
|
||||
* @param array $texts Some texts
|
||||
*/
|
||||
function setLabelText($texts) {
|
||||
if(is_array($texts)) {
|
||||
$this->auto(FALSE);
|
||||
$function = 'axis'.time().'_'.(microtime() * 1000000);
|
||||
eval('function '.$function.'($value) {
|
||||
$texts = '.var_export($texts, TRUE).';
|
||||
return isset($texts[$value]) ? $texts[$value] : \'?\';
|
||||
}');
|
||||
$this->label->setCallbackFunction($function);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position of a point
|
||||
*
|
||||
* @param &$xAxis X axis
|
||||
* @param &$yAxis Y axis
|
||||
* @param $p Position of the point
|
||||
* @return Point Position on the axis
|
||||
*/
|
||||
function toPosition(&$xAxis, &$yAxis, $p) {
|
||||
|
||||
$p1 = $xAxis->getPointFromValue($p->x);
|
||||
$p2 = $yAxis->getPointFromValue($p->y);
|
||||
|
||||
return new awPoint(
|
||||
round($p1->x),
|
||||
round($p2->y)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change title alignment
|
||||
*
|
||||
* @param int $alignment New Alignment
|
||||
*/
|
||||
function setTitleAlignment($alignment) {
|
||||
|
||||
switch($alignment) {
|
||||
|
||||
case LABEL_TOP :
|
||||
$this->setTitlePosition(1);
|
||||
$this->title->setAlign(NULL, LABEL_BOTTOM);
|
||||
break;
|
||||
|
||||
case LABEL_BOTTOM :
|
||||
$this->setTitlePosition(0);
|
||||
$this->title->setAlign(NULL, LABEL_TOP);
|
||||
break;
|
||||
|
||||
case LABEL_LEFT :
|
||||
$this->setTitlePosition(0);
|
||||
$this->title->setAlign(LABEL_LEFT);
|
||||
break;
|
||||
|
||||
case LABEL_RIGHT :
|
||||
$this->setTitlePosition(1);
|
||||
$this->title->setAlign(LABEL_RIGHT);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change title position on the axis
|
||||
*
|
||||
* @param float $position A new awposition between 0 and 1
|
||||
*/
|
||||
function setTitlePosition($position) {
|
||||
$this->titlePosition = (float)$position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change axis and axis title color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setColor($color) {
|
||||
$this->color = $color;
|
||||
$this->title->setColor($color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change axis padding
|
||||
*
|
||||
* @param int $left Left padding in pixels
|
||||
* @param int $right Right padding in pixels
|
||||
*/
|
||||
function setPadding($left, $right) {
|
||||
$this->padding->set($left, $right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get axis padding
|
||||
*
|
||||
* @return Side
|
||||
*/
|
||||
function getPadding() {
|
||||
return $this->padding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change axis range
|
||||
*
|
||||
* @param float $min
|
||||
* @param float $max
|
||||
*/
|
||||
function setRange($min, $max) {
|
||||
if($min !== NULL) {
|
||||
$this->range[0] = (float)$min;
|
||||
}
|
||||
if($max !== NULL) {
|
||||
$this->range[1] = (float)$max;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get axis range
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getRange() {
|
||||
return $this->range;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change axis range callback function
|
||||
*
|
||||
* @param string $toValue Transform a position between 0 and 1 to a value
|
||||
* @param string $toPosition Transform a value to a position between 0 and 1 on the axis
|
||||
*/
|
||||
function setRangeCallback($toValue, $toPosition) {
|
||||
$this->rangeCallback = array(
|
||||
'toValue' => (string)$toValue,
|
||||
'toPosition' => (string)$toPosition
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Center X values of the axis
|
||||
*
|
||||
* @param &$axis An axis
|
||||
* @param float $value The reference value on the axis
|
||||
*/
|
||||
function setXCenter(&$axis, $value) {
|
||||
|
||||
// Check vector angle
|
||||
if($this->line->isVertical() === FALSE) {
|
||||
trigger_error("setXCenter() can only be used on vertical axes", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$p = $axis->getPointFromValue($value);
|
||||
|
||||
$this->line->setX(
|
||||
$p->x,
|
||||
$p->x
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Center Y values of the axis
|
||||
*
|
||||
* @param &$axis An axis
|
||||
* @param float $value The reference value on the axis
|
||||
*/
|
||||
function setYCenter(&$axis, $value) {
|
||||
|
||||
// Check vector angle
|
||||
if($this->line->isHorizontal() === FALSE) {
|
||||
trigger_error("setYCenter() can only be used on horizontal axes", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$p = $axis->getPointFromValue($value);
|
||||
|
||||
$this->line->setY(
|
||||
$p->y,
|
||||
$p->y
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the distance between to values on the axis
|
||||
*
|
||||
* @param float $from The first value
|
||||
* @param float $to The last value
|
||||
* @return Point
|
||||
*/
|
||||
function getDistance($from, $to) {
|
||||
|
||||
$p1 = $this->getPointFromValue($from);
|
||||
$p2 = $this->getPointFromValue($to);
|
||||
|
||||
return $p1->getDistance($p2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point on the axis from a value
|
||||
*
|
||||
* @param float $value
|
||||
* @return Point
|
||||
*/
|
||||
function getPointFromValue($value) {
|
||||
|
||||
$callback = $this->rangeCallback['toPosition'];
|
||||
|
||||
list($min, $max) = $this->range;
|
||||
$position = $callback($value, $min, $max);
|
||||
|
||||
return $this->getPointFromPosition($position);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point on the axis from a position
|
||||
*
|
||||
* @param float $position A position between 0 and 1
|
||||
* @return Point
|
||||
*/
|
||||
function getPointFromPosition($position) {
|
||||
|
||||
$vector = $this->getVector();
|
||||
|
||||
$angle = $vector->getAngle();
|
||||
$size = $vector->getSize();
|
||||
|
||||
return $vector->p1->move(
|
||||
cos($angle) * $size * $position,
|
||||
-1 * sin($angle) * $size * $position
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw axis
|
||||
*
|
||||
* @param $drawer A drawer
|
||||
*/
|
||||
function draw($drawer) {
|
||||
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
$vector = $this->getVector();
|
||||
|
||||
// Draw axis ticks
|
||||
$this->drawTicks($drawer, $vector);
|
||||
|
||||
// Draw axis line
|
||||
$this->line($drawer);
|
||||
|
||||
// Draw labels
|
||||
$this->drawLabels($drawer);
|
||||
|
||||
// Draw axis title
|
||||
$p = $this->getPointFromPosition($this->titlePosition);
|
||||
$this->title->draw($drawer, $p);
|
||||
|
||||
}
|
||||
|
||||
function autoScale() {
|
||||
|
||||
if($this->isAuto() === FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
list($min, $max) = $this->getRange();
|
||||
$interval = $max - $min;
|
||||
|
||||
if($interval > 0) {
|
||||
$partMax = $max / $interval;
|
||||
$partMin = $min / $interval;
|
||||
} else {
|
||||
$partMax = 0;
|
||||
$partMin = 0;
|
||||
}
|
||||
|
||||
$difference = log($interval) / log(10);
|
||||
$difference = floor($difference);
|
||||
|
||||
$pow = pow(10, $difference);
|
||||
|
||||
if($pow > 0) {
|
||||
$intervalNormalize = $interval / $pow;
|
||||
} else {
|
||||
$intervalNormalize = 0;
|
||||
}
|
||||
|
||||
if($difference <= 0) {
|
||||
|
||||
$precision = $difference * -1 + 1;
|
||||
|
||||
if($intervalNormalize > 2) {
|
||||
$precision--;
|
||||
}
|
||||
|
||||
} else {
|
||||
$precision = 0;
|
||||
}
|
||||
|
||||
if($min != 0 and $max != 0) {
|
||||
$precision++;
|
||||
}
|
||||
|
||||
$this->setLabelPrecision($precision);
|
||||
|
||||
if($intervalNormalize <= 1.5) {
|
||||
$intervalReal = 1.5;
|
||||
$labelNumber = 4;
|
||||
} else if($intervalNormalize <= 2) {
|
||||
$intervalReal = 2;
|
||||
$labelNumber = 5;
|
||||
} else if($intervalNormalize <= 3) {
|
||||
$intervalReal = 3;
|
||||
$labelNumber = 4;
|
||||
} else if($intervalNormalize <= 4) {
|
||||
$intervalReal = 4;
|
||||
$labelNumber = 5;
|
||||
} else if($intervalNormalize <= 5) {
|
||||
$intervalReal = 5;
|
||||
$labelNumber = 6;
|
||||
} else if($intervalNormalize <= 8) {
|
||||
$intervalReal = 8;
|
||||
$labelNumber = 5;
|
||||
} else if($intervalNormalize <= 10) {
|
||||
$intervalReal = 10;
|
||||
$labelNumber = 6;
|
||||
}
|
||||
|
||||
if($min == 0) {
|
||||
|
||||
$this->setRange(
|
||||
$min,
|
||||
$intervalReal * $pow
|
||||
);
|
||||
|
||||
} else if($max == 0) {
|
||||
|
||||
$this->setRange(
|
||||
$intervalReal * $pow * -1,
|
||||
0
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->setLabelNumber($labelNumber);
|
||||
|
||||
}
|
||||
|
||||
function line($drawer) {
|
||||
|
||||
$drawer->line(
|
||||
$this->color,
|
||||
$this->line
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function drawTicks($drawer, &$vector) {
|
||||
|
||||
foreach($this->ticks as $tick) {
|
||||
$tick->setColor($this->color);
|
||||
$tick->draw($drawer, $vector);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function drawLabels($drawer) {
|
||||
|
||||
if($this->labelNumber !== NULL) {
|
||||
list($min, $max) = $this->range;
|
||||
$number = $this->labelNumber - 1;
|
||||
if($number < 1) {
|
||||
return;
|
||||
}
|
||||
$function = $this->rangeCallback['toValue'];
|
||||
$labels = array();
|
||||
for($i = 0; $i <= $number; $i++) {
|
||||
$labels[] = $function($i / $number, $min, $max);
|
||||
}
|
||||
$this->label->set($labels);
|
||||
}
|
||||
|
||||
$labels = $this->label->count();
|
||||
|
||||
for($i = 0; $i < $labels; $i++) {
|
||||
|
||||
$p = $this->getPointFromValue($this->label->get($i));
|
||||
$this->label->draw($drawer, $p, $i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getVector() {
|
||||
|
||||
$angle = $this->line->getAngle();
|
||||
|
||||
// Compute paddings
|
||||
$vector = new awVector(
|
||||
$this->line->p1->move(
|
||||
cos($angle) * $this->padding->left,
|
||||
-1 * sin($angle) * $this->padding->left
|
||||
),
|
||||
$this->line->p2->move(
|
||||
-1 * cos($angle) * $this->padding->right,
|
||||
-1 * -1 * sin($angle) * $this->padding->right
|
||||
)
|
||||
);
|
||||
|
||||
return $vector;
|
||||
|
||||
}
|
||||
|
||||
function __clone() {
|
||||
|
||||
$this->label = $this->label;
|
||||
$this->line = $this->line;
|
||||
$this->title = $this->title;
|
||||
|
||||
foreach($this->ticks as $name => $tick) {
|
||||
$this->ticks[$name] = $tick;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Axis');
|
||||
|
||||
function toProportionalValue($position, $min, $max) {
|
||||
return $min + ($max - $min) * $position;
|
||||
}
|
||||
|
||||
function toProportionalPosition($value, $min, $max) {
|
||||
if($max - $min == 0) {
|
||||
return 0;
|
||||
}
|
||||
return ($value - $min) / ($max - $min);
|
||||
}
|
||||
?>
|
||||
@ -1,158 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Draw border
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awBorder {
|
||||
|
||||
/**
|
||||
* Border color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $color;
|
||||
|
||||
/**
|
||||
* Hide border ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Border line style
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $style;
|
||||
|
||||
/**
|
||||
* Build the border
|
||||
*
|
||||
* @param $color Border color
|
||||
* @param int $style Border style
|
||||
*/
|
||||
function awBorder($color = NULL, $style = LINE_SOLID) {
|
||||
|
||||
$this->setStyle($style);
|
||||
|
||||
if(is_a($color, 'awColor')) {
|
||||
$this->setColor($color);
|
||||
} else {
|
||||
$this->setColor(new awBlack);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change border color
|
||||
* This method automatically shows the border if it is hidden
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setColor($color) {
|
||||
$this->color = $color;
|
||||
$this->show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change border style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
function setStyle($style) {
|
||||
$this->style = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide border ?
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show border ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the border visible ?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function visible() {
|
||||
return !$this->hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw border as a rectangle
|
||||
*
|
||||
* @param $drawer
|
||||
* @param $p1 Top-left corner
|
||||
* @param $p2 Bottom-right corner
|
||||
*/
|
||||
function rectangle($drawer, $p1, $p2) {
|
||||
|
||||
// Border is hidden
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
$line = new awLine;
|
||||
$line->setStyle($this->style);
|
||||
$line->setLocation($p1, $p2);
|
||||
|
||||
$drawer->rectangle($this->color, $line);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw border as an ellipse
|
||||
*
|
||||
* @param $drawer
|
||||
* @param $center Ellipse center
|
||||
* @param int $width Ellipse width
|
||||
* @param int $height Ellipse height
|
||||
*/
|
||||
function ellipse($drawer, $center, $width, $height) {
|
||||
|
||||
// Border is hidden
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch($this->style) {
|
||||
|
||||
case LINE_SOLID :
|
||||
$drawer->ellipse($this->color, $center, $width, $height);
|
||||
break;
|
||||
|
||||
default :
|
||||
trigger_error("Dashed and dotted borders and not yet implemented on ellipses", E_USER_ERROR);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Border');
|
||||
?>
|
||||
@ -1,201 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create your colors
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awColor {
|
||||
|
||||
var $red;
|
||||
var $green;
|
||||
var $blue;
|
||||
var $alpha;
|
||||
|
||||
var $resource;
|
||||
var $color;
|
||||
|
||||
/**
|
||||
* Build your color
|
||||
*
|
||||
* @var int $red Red intensity (from 0 to 255)
|
||||
* @var int $green Green intensity (from 0 to 255)
|
||||
* @var int $blue Blue intensity (from 0 to 255)
|
||||
* @var int $alpha Alpha channel (from 0 to 100)
|
||||
*/
|
||||
function awColor($red, $green, $blue, $alpha = 0) {
|
||||
|
||||
$this->red = (int)$red;
|
||||
$this->green = (int)$green;
|
||||
$this->blue = (int)$blue;
|
||||
$this->alpha = (int)round($alpha * 127 / 100);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a GDised color
|
||||
*
|
||||
* @param resource $resource A GD resource
|
||||
* @return int
|
||||
*/
|
||||
function getColor($resource) {
|
||||
|
||||
$this->resource = $resource;
|
||||
|
||||
if($this->color === NULL) {
|
||||
|
||||
if($this->alpha === 0 or function_exists('imagecolorallocatealpha') === FALSE) {
|
||||
$this->color = imagecolorallocate($this->resource, $this->red, $this->green, $this->blue);
|
||||
} else {
|
||||
$this->color = imagecolorallocatealpha($this->resource, $this->red, $this->green, $this->blue, $this->alpha);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->color;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change color brightness
|
||||
*
|
||||
* @param int $brightness Add this intensity to the color (betweeen -255 and +255)
|
||||
*/
|
||||
function brightness($brightness) {
|
||||
|
||||
$brightness = (int)$brightness;
|
||||
|
||||
$this->red = min(255, max(0, $this->red + $brightness));
|
||||
$this->green = min(255, max(0, $this->green + $brightness));
|
||||
$this->blue = min(255, max(0, $this->blue + $brightness));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get RGB and alpha values of your color
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function rgba() {
|
||||
|
||||
return array($this->red, $this->green, $this->blue, $this->alpha);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Free resources used for this color
|
||||
*/
|
||||
function free() {
|
||||
|
||||
if($this->resource !== NULL) {
|
||||
|
||||
@imagecolordeallocate($this->resource, $this->color);
|
||||
$this->resource = NULL;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function php5Destructor() {
|
||||
|
||||
$this->free();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Color');
|
||||
|
||||
$colors = array(
|
||||
'Black' => array(0, 0, 0),
|
||||
'AlmostBlack' => array(48, 48, 48),
|
||||
'VeryDarkGray' => array(88, 88, 88),
|
||||
'DarkGray' => array(128, 128, 128),
|
||||
'MidGray' => array(160, 160, 160),
|
||||
'LightGray' => array(195, 195, 195),
|
||||
'VeryLightGray' => array(220, 220, 220),
|
||||
'White' => array(255, 255, 255),
|
||||
'VeryDarkRed' => array(64, 0, 0),
|
||||
'DarkRed' => array(128, 0, 0),
|
||||
'MidRed' => array(192, 0, 0),
|
||||
'Red' => array(255, 0, 0),
|
||||
'LightRed' => array(255, 192, 192),
|
||||
'VeryDarkGreen' => array(0, 64, 0),
|
||||
'DarkGreen' => array(0, 128, 0),
|
||||
'MidGreen' => array(0, 192, 0),
|
||||
'Green' => array(0, 255, 0),
|
||||
'LightGreen' => array(192, 255, 192),
|
||||
'VeryDarkBlue' => array(0, 0, 64),
|
||||
'DarkBlue' => array(0, 0, 128),
|
||||
'MidBlue' => array(0, 0, 192),
|
||||
'Blue' => array(0, 0, 255),
|
||||
'LightBlue' => array(192, 192, 255),
|
||||
'VeryDarkYellow' => array(64, 64, 0),
|
||||
'DarkYellow' => array(128, 128, 0),
|
||||
'MidYellow' => array(192, 192, 0),
|
||||
'Yellow' => array(255, 255, 2),
|
||||
'LightYellow' => array(255, 255, 192),
|
||||
'VeryDarkCyan' => array(0, 64, 64),
|
||||
'DarkCyan' => array(0, 128, 128),
|
||||
'MidCyan' => array(0, 192, 192),
|
||||
'Cyan' => array(0, 255, 255),
|
||||
'LightCyan' => array(192, 255, 255),
|
||||
'VeryDarkMagenta' => array(64, 0, 64),
|
||||
'DarkMagenta' => array(128, 0, 128),
|
||||
'MidMagenta' => array(192, 0, 192),
|
||||
'Magenta' => array(255, 0, 255),
|
||||
'LightMagenta' => array(255, 192, 255),
|
||||
'DarkOrange' => array(192, 88, 0),
|
||||
'Orange' => array(255, 128, 0),
|
||||
'LightOrange' => array(255, 168, 88),
|
||||
'VeryLightOrange' => array(255, 220, 168),
|
||||
'DarkPink' => array(192, 0, 88),
|
||||
'Pink' => array(255, 0, 128),
|
||||
'LightPink' => array(255, 88, 168),
|
||||
'VeryLightPink' => array(255, 168, 220),
|
||||
'DarkPurple' => array(88, 0, 192),
|
||||
'Purple' => array(128, 0, 255),
|
||||
'LightPurple' => array(168, 88, 255),
|
||||
'VeryLightPurple' => array(220, 168, 255),
|
||||
);
|
||||
|
||||
|
||||
|
||||
$php = '';
|
||||
|
||||
foreach($colors as $name => $color) {
|
||||
|
||||
list($red, $green, $blue) = $color;
|
||||
|
||||
$php .= '
|
||||
class aw'.$name.' extends awColor {
|
||||
|
||||
function aw'.$name.'($alpha = 0) {
|
||||
parent::awColor('.$red.', '.$green.', '.$blue.', $alpha);
|
||||
}
|
||||
|
||||
}
|
||||
';
|
||||
|
||||
if(ARTICHOW_PREFIX !== 'aw') {
|
||||
$php .= '
|
||||
class '.ARTICHOW_PREFIX.$name.' extends aw'.$name.' {
|
||||
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval($php);
|
||||
|
||||
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,295 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Built-in PHP fonts
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awFont {
|
||||
|
||||
/**
|
||||
* Used font
|
||||
*
|
||||
* @param int $font
|
||||
*/
|
||||
var $font;
|
||||
|
||||
/**
|
||||
* Build the font
|
||||
*
|
||||
* @param int $font Font identifier
|
||||
*/
|
||||
function awFont($font) {
|
||||
|
||||
$this->font = $font;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a text
|
||||
*
|
||||
* @param $drawer
|
||||
* @param $p Draw text at this point
|
||||
* @param &$text The text
|
||||
*/
|
||||
function draw($drawer, $p, &$text) {
|
||||
|
||||
$angle = $text->getAngle();
|
||||
|
||||
if($angle !== 90 and $angle !== 0) {
|
||||
trigger_error("You can only use 0° and 90°", E_USER_ERROR);
|
||||
}
|
||||
|
||||
if($angle === 90) {
|
||||
$function = 'imagestringup';
|
||||
} else {
|
||||
$function = 'imagestring';
|
||||
}
|
||||
|
||||
if($angle === 90) {
|
||||
$add = $this->getTextHeight($text);
|
||||
} else {
|
||||
$add = 0;
|
||||
}
|
||||
|
||||
$color = $text->getColor();
|
||||
$rgb = $color->getColor($drawer->resource);
|
||||
|
||||
$function(
|
||||
$drawer->resource,
|
||||
$this->font,
|
||||
$drawer->x + $p->x,
|
||||
$drawer->y + $p->y + $add,
|
||||
$text->getText(),
|
||||
$rgb
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of a string
|
||||
*
|
||||
* @param &$text A string
|
||||
*/
|
||||
function getTextWidth(&$text) {
|
||||
|
||||
if($text->getAngle() === 90) {
|
||||
$text->setAngle(45);
|
||||
return $this->getTextHeight($text);
|
||||
} else if($text->getAngle() === 45) {
|
||||
$text->setAngle(90);
|
||||
}
|
||||
|
||||
$font = $text->getFont();
|
||||
$fontWidth = imagefontwidth($font->font);
|
||||
|
||||
if($fontWidth === FALSE) {
|
||||
trigger_error("Unable to get font size", E_USER_ERROR);
|
||||
}
|
||||
|
||||
return (int)$fontWidth * strlen($text->getText());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of a string
|
||||
*
|
||||
* @param &$text A string
|
||||
*/
|
||||
function getTextHeight(&$text) {
|
||||
|
||||
if($text->getAngle() === 90) {
|
||||
$text->setAngle(45);
|
||||
return $this->getTextWidth($text);
|
||||
} else if($text->getAngle() === 45) {
|
||||
$text->setAngle(90);
|
||||
}
|
||||
|
||||
$font = $text->getFont();
|
||||
$fontHeight = imagefontheight($font->font);
|
||||
|
||||
if($fontHeight === FALSE) {
|
||||
trigger_error("Unable to get font size", E_USER_ERROR);
|
||||
}
|
||||
|
||||
return (int)$fontHeight;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Font');
|
||||
|
||||
/**
|
||||
* TTF fonts
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awTTFFont extends awFont {
|
||||
|
||||
/**
|
||||
* Font size
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $size;
|
||||
|
||||
/**
|
||||
* Font file
|
||||
*
|
||||
* @param string $font Font file
|
||||
* @param int $size Font size
|
||||
*/
|
||||
function awTTFFont($font, $size) {
|
||||
|
||||
parent::awFont($font);
|
||||
|
||||
$this->size = (int)$size;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a text
|
||||
*
|
||||
* @param $drawer
|
||||
* @param $p Draw text at this point
|
||||
* @param &$text The text
|
||||
*/
|
||||
function draw($drawer, $p, &$text) {
|
||||
|
||||
// Make easier font positionment
|
||||
$text->setText($text->getText()." ");
|
||||
|
||||
$color = $text->getColor();
|
||||
$rgb = $color->getColor($drawer->resource);
|
||||
|
||||
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
|
||||
|
||||
$height = - $box[5];
|
||||
|
||||
$box = imagettfbbox($this->size, 90, $this->font, $text->getText());
|
||||
$width = abs($box[6] - $box[2]);
|
||||
|
||||
// Restore old text
|
||||
$text->setText(substr($text->getText(), 0, strlen($text->getText()) - 1));
|
||||
|
||||
imagettftext(
|
||||
$drawer->resource,
|
||||
$this->size,
|
||||
$text->getAngle(),
|
||||
$drawer->x + $p->x + $width * sin($text->getAngle() / 180 * M_PI),
|
||||
$drawer->y + $p->y + $height,
|
||||
$rgb,
|
||||
$this->font,
|
||||
$text->getText()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of a string
|
||||
*
|
||||
* @param &$text A string
|
||||
*/
|
||||
function getTextWidth(&$text) {
|
||||
|
||||
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
|
||||
|
||||
if($box === FALSE) {
|
||||
trigger_error("Unable to get font size", E_USER_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
list(, , $x2, $y2, , , $x1, $y1) = $box;
|
||||
|
||||
return abs($x2 - $x1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of a string
|
||||
*
|
||||
* @param &$text A string
|
||||
*/
|
||||
function getTextHeight(&$text) {
|
||||
|
||||
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
|
||||
|
||||
if($box === FALSE) {
|
||||
trigger_error("Unable to get font size", E_USER_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
list(, , $x2, $y2, , , $x1, $y1) = $box;
|
||||
|
||||
return abs($y2 - $y1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('TTFFont');
|
||||
|
||||
|
||||
|
||||
$php = '';
|
||||
|
||||
for($i = 1; $i <= 5; $i++) {
|
||||
|
||||
$php .= '
|
||||
class awFont'.$i.' extends awFont {
|
||||
|
||||
function awFont'.$i.'() {
|
||||
parent::awFont('.$i.');
|
||||
}
|
||||
|
||||
}
|
||||
';
|
||||
|
||||
if(ARTICHOW_PREFIX !== 'aw') {
|
||||
$php .= '
|
||||
class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval($php);
|
||||
|
||||
$php = '';
|
||||
|
||||
foreach($fonts as $font) {
|
||||
|
||||
$php .= '
|
||||
class aw'.$font.' extends awTTFFont {
|
||||
|
||||
function aw'.$font.'($size) {
|
||||
parent::awTTFFont(\''.(ARTICHOW_FONT.DIRECTORY_SEPARATOR.$font.'.ttf').'\', $size);
|
||||
}
|
||||
|
||||
}
|
||||
';
|
||||
|
||||
if(ARTICHOW_PREFIX !== 'aw') {
|
||||
$php .= '
|
||||
class '.ARTICHOW_PREFIX.$font.' extends aw'.$font.' {
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval($php);
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@ -1,149 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create your gradients
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awGradient {
|
||||
|
||||
/**
|
||||
* From color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $from;
|
||||
|
||||
/**
|
||||
* To color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $to;
|
||||
|
||||
/**
|
||||
* Build the gradient
|
||||
*
|
||||
* @param $from From color
|
||||
* @param $to To color
|
||||
*/
|
||||
function awGradient($from, $to) {
|
||||
|
||||
$this->from = $from;
|
||||
$this->to = $to;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Free memory used by the colors of the gradient
|
||||
*/
|
||||
function free() {
|
||||
|
||||
$this->from->free();
|
||||
$this->to->free();
|
||||
|
||||
}
|
||||
|
||||
function php5Destructor( ){
|
||||
|
||||
$this->free();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Gradient', TRUE);
|
||||
|
||||
|
||||
/**
|
||||
* Create a linear gradient
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLinearGradient extends awGradient {
|
||||
|
||||
/**
|
||||
* Gradient angle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $angle;
|
||||
|
||||
/**
|
||||
* Build the linear gradient
|
||||
*
|
||||
* @param $from From color
|
||||
* @param $to To color
|
||||
* @param int $angle Gradient angle
|
||||
*/
|
||||
function awLinearGradient($from, $to, $angle) {
|
||||
|
||||
parent::awGradient(
|
||||
$from, $to
|
||||
);
|
||||
|
||||
$this->angle = $angle;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('LinearGradient');
|
||||
|
||||
|
||||
/**
|
||||
* Create a bilinear gradient
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awBilinearGradient extends awLinearGradient {
|
||||
|
||||
/**
|
||||
* Gradient center
|
||||
*
|
||||
* @var int Center between 0 and 1
|
||||
*/
|
||||
var $center;
|
||||
|
||||
/**
|
||||
* Build the bilinear gradient
|
||||
*
|
||||
* @param $from From color
|
||||
* @param $to To color
|
||||
* @param int $angle Gradient angle
|
||||
* @param int $center Gradient center
|
||||
*/
|
||||
function awBilinearGradient($from, $to, $angle, $center = 0.5) {
|
||||
|
||||
parent::awLinearGradient(
|
||||
$from, $to, $angle
|
||||
);
|
||||
|
||||
$this->center = $center;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('BilinearGradient');
|
||||
|
||||
/**
|
||||
* Create a radial gradient
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awRadialGradient extends awGradient {
|
||||
|
||||
}
|
||||
|
||||
registerClass('RadialGradient');
|
||||
?>
|
||||
@ -1,289 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Grid
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awGrid {
|
||||
|
||||
/**
|
||||
* Vertical lines of the grid
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $xgrid = array();
|
||||
|
||||
/**
|
||||
* Horizontal lines of the grid
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $ygrid = array();
|
||||
|
||||
/**
|
||||
* Is the component grid hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Are horizontal lines hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hideHorizontal = FALSE;
|
||||
|
||||
/**
|
||||
* Are vertical lines hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hideVertical = FALSE;
|
||||
|
||||
/**
|
||||
* Grid color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $color;
|
||||
|
||||
/**
|
||||
* Grid space
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $space;
|
||||
|
||||
/**
|
||||
* Line type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $type = LINE_SOLID;
|
||||
|
||||
/**
|
||||
* Grid interval
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $interval = array(1, 1);
|
||||
|
||||
/**
|
||||
* Grid background color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $background;
|
||||
|
||||
/**
|
||||
* Build the factory
|
||||
*/
|
||||
function awGrid() {
|
||||
|
||||
// Set a grid default color
|
||||
$this->color = new awColor(210, 210, 210);
|
||||
$this->background = new awColor(255, 255, 255, 100);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide grid ?
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide horizontal lines ?
|
||||
*
|
||||
* @param bool $hideHorizontal
|
||||
*/
|
||||
function hideHorizontal($hide = TRUE) {
|
||||
$this->hideHorizontal = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide vertical lines ?
|
||||
*
|
||||
* @param bool $hideVertical
|
||||
*/
|
||||
function hideVertical($hide = TRUE) {
|
||||
$this->hideVertical = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change grid color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setColor($color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove grid background
|
||||
*/
|
||||
function setNoBackground() {
|
||||
$this->background = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change grid background color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setBackgroundColor($color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line type
|
||||
*
|
||||
* @param int $type
|
||||
*/
|
||||
function setType($type) {
|
||||
$this->type = (int)$type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change grid interval
|
||||
*
|
||||
* @param int $hInterval
|
||||
* @param int $vInterval
|
||||
*/
|
||||
function setInterval($hInterval, $vInterval) {
|
||||
$this->interval = array((int)$hInterval, (int)$vInterval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set grid space
|
||||
*
|
||||
* @param int $left Left space in pixels
|
||||
* @param int $right Right space in pixels
|
||||
* @param int $top Top space in pixels
|
||||
* @param int $bottom Bottom space in pixels
|
||||
*/
|
||||
function setSpace($left, $right, $top, $bottom) {
|
||||
$this->space = array((int)$left, (int)$right, (int)$top, (int)$bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the current grid
|
||||
*
|
||||
* @param array $xgrid Vertical lines
|
||||
* @param array $ygrid Horizontal lines
|
||||
*/
|
||||
function setGrid($xgrid, $ygrid) {
|
||||
|
||||
$this->xgrid = $xgrid;
|
||||
$this->ygrid = $ygrid;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw grids
|
||||
*
|
||||
* @param $drawer A drawer object
|
||||
* @param int $x1
|
||||
* @param int $y1
|
||||
* @param int $x2
|
||||
* @param int $y2
|
||||
*/
|
||||
function draw($drawer, $x1, $y1, $x2, $y2) {
|
||||
|
||||
if(is_a($this->background, 'awColor')) {
|
||||
|
||||
// Draw background color
|
||||
$drawer->filledRectangle(
|
||||
$this->background,
|
||||
awLine::build($x1, $y1, $x2, $y2)
|
||||
);
|
||||
|
||||
$this->background->free();
|
||||
|
||||
}
|
||||
|
||||
if($this->hide === FALSE) {
|
||||
|
||||
$this->drawGrid(
|
||||
$drawer,
|
||||
$this->color,
|
||||
$this->hideVertical ? array() : $this->xgrid,
|
||||
$this->hideHorizontal ? array() : $this->ygrid,
|
||||
$x1, $y1, $x2, $y2,
|
||||
$this->type,
|
||||
$this->space,
|
||||
$this->interval[0],
|
||||
$this->interval[1]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->color->free();
|
||||
|
||||
}
|
||||
|
||||
function drawGrid(
|
||||
$drawer, $color,
|
||||
$nx, $ny, $x1, $y1, $x2, $y2,
|
||||
$type, $space, $hInterval, $vInterval
|
||||
) {
|
||||
|
||||
list($left, $right, $top, $bottom) = $space;
|
||||
|
||||
$width = $x2 - $x1 - $left - $right;
|
||||
$height = $y2 - $y1 - $top - $bottom;
|
||||
|
||||
foreach($nx as $key => $n) {
|
||||
|
||||
if(($key % $vInterval) === 0) {
|
||||
|
||||
$pos = (int)round($x1 + $left + $n * $width);
|
||||
$drawer->line(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($pos, $y1),
|
||||
new awPoint($pos, $y2),
|
||||
$type
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach($ny as $key => $n) {
|
||||
|
||||
if(($key % $hInterval) === 0) {
|
||||
|
||||
$pos = (int)round($y1 + $top + $n * $height);
|
||||
$drawer->line(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($x1, $pos),
|
||||
new awPoint($x2, $pos),
|
||||
$type
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Grid');
|
||||
?>
|
||||
@ -1,596 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("LABEL_LEFT", 1);
|
||||
define("LABEL_RIGHT", 2);
|
||||
define("LABEL_CENTER", 3);
|
||||
define("LABEL_TOP", 4);
|
||||
define("LABEL_BOTTOM", 5);
|
||||
define("LABEL_MIDDLE", 6);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Draw labels
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLabel {
|
||||
|
||||
/**
|
||||
* Label border
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $border;
|
||||
|
||||
/**
|
||||
* Label texts
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $texts;
|
||||
|
||||
/**
|
||||
* Text font
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $font;
|
||||
|
||||
/**
|
||||
* Text angle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $angle = 0;
|
||||
|
||||
/**
|
||||
* Text color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $color;
|
||||
|
||||
/**
|
||||
* Text background
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
var $background;
|
||||
|
||||
/**
|
||||
* Callback function
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $function;
|
||||
|
||||
/**
|
||||
* Padding
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $padding;
|
||||
|
||||
/**
|
||||
* Move position from this vector
|
||||
*
|
||||
* @var Point
|
||||
*/
|
||||
var $move;
|
||||
|
||||
/**
|
||||
* Label interval
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $interval = 1;
|
||||
|
||||
/**
|
||||
* Horizontal align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $hAlign = LABEL_CENTER;
|
||||
|
||||
/**
|
||||
* Vertical align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $vAlign = LABEL_MIDDLE;
|
||||
|
||||
/**
|
||||
* Hide all labels ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Keys to hide
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $hideKey = array();
|
||||
|
||||
/**
|
||||
* Values to hide
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $hideValue = array();
|
||||
|
||||
/**
|
||||
* Hide first label
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hideFirst = FALSE;
|
||||
|
||||
/**
|
||||
* Hide last label
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hideLast = FALSE;
|
||||
|
||||
/**
|
||||
* Build the label
|
||||
*
|
||||
* @param string $label First label
|
||||
*/
|
||||
function awLabel($label = NULL, $font = NULL, $color = NULL, $angle = 0) {
|
||||
|
||||
if(is_array($label)) {
|
||||
$this->set($label);
|
||||
} else if(is_string($label)) {
|
||||
$this->set(array($label));
|
||||
}
|
||||
|
||||
if($font === NULL) {
|
||||
$font = new awFont2;
|
||||
}
|
||||
|
||||
$this->setFont($font);
|
||||
$this->setAngle($angle);
|
||||
|
||||
if(is_a($color, 'awColor')) {
|
||||
$this->setColor($color);
|
||||
} else {
|
||||
$this->setColor(new awColor(0, 0, 0));
|
||||
}
|
||||
|
||||
$this->move = new awPoint(0, 0);
|
||||
|
||||
$this->border = new awBorder;
|
||||
$this->border->hide();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an element of the label from its key
|
||||
*
|
||||
* @param int $key Element key
|
||||
* @return string A value
|
||||
*/
|
||||
function get($key) {
|
||||
return array_key_exists($key, $this->texts) ? $this->texts[$key] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function all() {
|
||||
return $this->texts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set one or several labels
|
||||
*
|
||||
* @param array $labels Array of string or a string
|
||||
*/
|
||||
function set($labels) {
|
||||
|
||||
if(is_string($labels)) {
|
||||
$this->texts = array($labels);
|
||||
} else if(is_array($labels)) {
|
||||
$this->texts = $labels;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of texts in the label
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function count() {
|
||||
return is_array($this->texts) ? count($this->texts) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a callback function for labels
|
||||
*
|
||||
* @param string $function
|
||||
*/
|
||||
function setCallbackFunction($function) {
|
||||
$this->function = is_null($function) ? $function : (string)$function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the callback function for labels
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getCallbackFunction() {
|
||||
return $this->function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change labels format
|
||||
*
|
||||
* @param string $format New format (printf style: %.2f for example)
|
||||
*/
|
||||
function setFormat($format) {
|
||||
$function = 'label'.time().'_'.(microtime() * 1000000);
|
||||
eval('function '.$function.'($value) {
|
||||
return sprintf("'.addcslashes($format, '"').'", $value);
|
||||
}');
|
||||
$this->setCallbackFunction($function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change font for label
|
||||
*
|
||||
* @param &$font New font
|
||||
* @param $color Font color (can be NULL)
|
||||
*/
|
||||
function setFont(&$font, $color = NULL) {
|
||||
$this->font = $font;
|
||||
if(is_a($color, 'awColor')) {
|
||||
$this->setColor($color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change font angle
|
||||
*
|
||||
* @param int $angle New angle
|
||||
*/
|
||||
function setAngle($angle) {
|
||||
$this->angle = (int)$angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change font color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setColor($color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background
|
||||
*
|
||||
* @param mixed $background
|
||||
*/
|
||||
function setBackground($background) {
|
||||
$this->background = $background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background color
|
||||
*
|
||||
* @param Color
|
||||
*/
|
||||
function setBackgroundColor($color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background gradient
|
||||
*
|
||||
* @param Gradient
|
||||
*/
|
||||
function setBackgroundGradient($gradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change padding
|
||||
*
|
||||
* @param int $left Left padding
|
||||
* @param int $right Right padding
|
||||
* @param int $top Top padding
|
||||
* @param int $bottom Bottom padding
|
||||
*/
|
||||
function setPadding($left, $right, $top, $bottom) {
|
||||
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide all labels ?
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all labels ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide a key
|
||||
*
|
||||
* @param int $key The key to hide
|
||||
*/
|
||||
function hideKey($key) {
|
||||
$this->hideKey[$key] = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide a value
|
||||
*
|
||||
* @param int $value The value to hide
|
||||
*/
|
||||
function hideValue($value) {
|
||||
$this->hideValue[] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide first label
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
function hideFirst($hide) {
|
||||
$this->hideFirst = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide last label
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
function hideLast($hide) {
|
||||
$this->hideLast = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set label interval
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
function setInterval($interval) {
|
||||
|
||||
$this->interval = (int)$interval;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label position
|
||||
*
|
||||
* @param int $x Add this interval to X coord
|
||||
* @param int $y Add this interval to Y coord
|
||||
*/
|
||||
function move($x, $y) {
|
||||
|
||||
$this->move = $this->move->move($x, $y);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change alignment
|
||||
*
|
||||
* @param int $h Horizontal alignment
|
||||
* @param int $v Vertical alignment
|
||||
*/
|
||||
function setAlign($h = NULL, $v = NULL) {
|
||||
if($h !== NULL) {
|
||||
$this->hAlign = (int)$h;
|
||||
}
|
||||
if($v !== NULL) {
|
||||
$this->vAlign = (int)$v;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a text from the labele
|
||||
*
|
||||
* @param mixed $key Key in the array text
|
||||
* @return Text
|
||||
*/
|
||||
function getText($key) {
|
||||
|
||||
if(is_array($this->texts) and array_key_exists($key, $this->texts)) {
|
||||
|
||||
$value = $this->texts[$key];
|
||||
|
||||
if(is_string($this->function)) {
|
||||
$value = call_user_func($this->function, $value);
|
||||
}
|
||||
|
||||
$text = new awText($value);
|
||||
$text->setFont($this->font);
|
||||
$text->setAngle($this->angle);
|
||||
$text->setColor($this->color);
|
||||
|
||||
if(is_a($this->background, 'awColor')) {
|
||||
$text->setBackgroundColor($this->background);
|
||||
} else if(is_a($this->background, 'awGradient')) {
|
||||
$text->setBackgroundGradient($this->background);
|
||||
}
|
||||
|
||||
$text->border = $this->border;
|
||||
|
||||
if($this->padding !== NULL) {
|
||||
call_user_func_array(array($text, 'setPadding'), $this->padding);
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max width of all texts
|
||||
*
|
||||
* @param $drawer A drawer
|
||||
* @return int
|
||||
*/
|
||||
function getMaxWidth($drawer) {
|
||||
|
||||
return $this->getMax($drawer, 'getTextWidth');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max height of all texts
|
||||
*
|
||||
* @param $drawer A drawer
|
||||
* @return int
|
||||
*/
|
||||
function getMaxHeight($drawer) {
|
||||
|
||||
return $this->getMax($drawer, 'getTextHeight');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the label
|
||||
*
|
||||
* @param $drawer
|
||||
* @param $p Label center
|
||||
* @param int $key Text position in the array of texts (default to zero)
|
||||
*/
|
||||
function draw($drawer, $p, $key = 0) {
|
||||
|
||||
if(($key % $this->interval) !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide all labels
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Key is hidden
|
||||
if(array_key_exists($key, $this->hideKey)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide first label
|
||||
if($key === 0 and $this->hideFirst) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide last label
|
||||
if($key === count($this->texts) - 1 and $this->hideLast) {
|
||||
return;
|
||||
}
|
||||
|
||||
$text = $this->getText($key);
|
||||
|
||||
if($text !== NULL) {
|
||||
|
||||
// Value must be hidden
|
||||
if(in_array($text->getText(), $this->hideValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$x = $p->x;
|
||||
$y = $p->y;
|
||||
|
||||
// Get padding
|
||||
list($left, $right, $top, $bottom) = $text->getPadding();
|
||||
|
||||
$font = $text->getFont();
|
||||
$width = $font->getTextWidth($text);
|
||||
$height = $font->getTextHeight($text);
|
||||
|
||||
switch($this->hAlign) {
|
||||
|
||||
case LABEL_RIGHT :
|
||||
$x -= ($width + $right);
|
||||
break;
|
||||
|
||||
case LABEL_CENTER :
|
||||
$x -= ($width - $left + $right) / 2;
|
||||
break;
|
||||
|
||||
case LABEL_LEFT :
|
||||
$x += $left;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
switch($this->vAlign) {
|
||||
|
||||
case LABEL_TOP :
|
||||
$y -= ($height + $bottom);
|
||||
break;
|
||||
|
||||
case LABEL_MIDDLE :
|
||||
$y -= ($height - $top + $bottom) / 2;
|
||||
break;
|
||||
|
||||
case LABEL_BOTTOM :
|
||||
$y += $top;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$drawer->string($text, $this->move->move($x, $y));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getMax($drawer, $function) {
|
||||
|
||||
$max = NULL;
|
||||
|
||||
foreach($this->texts as $key => $text) {
|
||||
|
||||
$text = $this->getText($key);
|
||||
$font = $text->getFont();
|
||||
|
||||
if(is_null($max)) {
|
||||
$max = $font->{$function}($text);
|
||||
} else {
|
||||
$max = max($max, $font->{$function}($text));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $max;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Label');
|
||||
?>
|
||||
@ -1,691 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("LEGEND_LINE", 1);
|
||||
define("LEGEND_BACKGROUND", 2);
|
||||
define("LEGEND_MARK", 3);
|
||||
define("LEGEND_MARKONLY", 4);
|
||||
|
||||
define("LEGEND_MODEL_RIGHT", 1);
|
||||
define("LEGEND_MODEL_BOTTOM", 2);
|
||||
|
||||
define("LEGEND_LEFT", 1);
|
||||
define("LEGEND_RIGHT", 2);
|
||||
define("LEGEND_CENTER", 3);
|
||||
define("LEGEND_TOP", 4);
|
||||
define("LEGEND_BOTTOM", 5);
|
||||
define("LEGEND_MIDDLE", 6);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Some legends
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLegend {
|
||||
|
||||
/**
|
||||
* Legends added
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $legends = array();
|
||||
|
||||
/**
|
||||
* The current component
|
||||
*
|
||||
* @var Component
|
||||
*/
|
||||
var $component;
|
||||
|
||||
/**
|
||||
* Background color or gradient
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
var $background;
|
||||
|
||||
/**
|
||||
* Text color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $textColor;
|
||||
|
||||
/**
|
||||
* Text font
|
||||
*
|
||||
* @var Font
|
||||
*/
|
||||
var $textFont;
|
||||
|
||||
/**
|
||||
* Text margin
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
var $textMargin;
|
||||
|
||||
/**
|
||||
* Number of columns
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $columns = NULL;
|
||||
|
||||
/**
|
||||
* Number of rows
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $rows = NULL;
|
||||
|
||||
/**
|
||||
* Legend position
|
||||
*
|
||||
* @var Point
|
||||
*/
|
||||
var $position;
|
||||
|
||||
/**
|
||||
* Hide legend ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Space between each legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $space = 4;
|
||||
|
||||
/**
|
||||
* Horizontal alignment
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $hAlign;
|
||||
|
||||
/**
|
||||
* Vertical alignment
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $vAlign;
|
||||
|
||||
/**
|
||||
* Margin
|
||||
*
|
||||
* @var array Array for left, right, top and bottom margins
|
||||
*/
|
||||
var $margin;
|
||||
|
||||
/**
|
||||
* Legend shadow
|
||||
*
|
||||
* @var Shadow
|
||||
*/
|
||||
var $shadow;
|
||||
|
||||
/**
|
||||
* Legend border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
var $border;
|
||||
|
||||
/**
|
||||
* Line legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Color/Gradient background legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Use marks and line as legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Use marks as legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Right side model
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Bottom side model
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Build the legend
|
||||
*
|
||||
* @param int $model Legend model
|
||||
*/
|
||||
function awLegend($model = LEGEND_MODEL_RIGHT) {
|
||||
|
||||
$this->shadow = new awShadow(SHADOW_LEFT_BOTTOM);
|
||||
$this->border = new awBorder;
|
||||
|
||||
$this->textMargin = new awSide(4);
|
||||
$this->setModel($model);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a predefined model for the legend
|
||||
*
|
||||
* @param int $model
|
||||
*/
|
||||
function setModel($model) {
|
||||
|
||||
$this->setBackgroundColor(new awColor(255, 255, 255, 15));
|
||||
$this->setPadding(8, 8, 8, 8);
|
||||
$this->setTextFont(new awFont2);
|
||||
$this->shadow->setSize(3);
|
||||
|
||||
switch($model) {
|
||||
|
||||
case LEGEND_MODEL_RIGHT :
|
||||
|
||||
$this->setColumns(1);
|
||||
$this->setAlign(LEGEND_RIGHT, LEGEND_MIDDLE);
|
||||
$this->setPosition(0.96, 0.50);
|
||||
|
||||
break;
|
||||
|
||||
case LEGEND_MODEL_BOTTOM :
|
||||
|
||||
$this->setRows(1);
|
||||
$this->setAlign(LEGEND_CENTER, LEGEND_TOP);
|
||||
$this->setPosition(0.50, 0.92);
|
||||
|
||||
break;
|
||||
|
||||
default :
|
||||
|
||||
$this->setPosition(0.5, 0.5);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide legend ?
|
||||
*
|
||||
* @param bool $hide TRUE to hide legend, FALSE otherwise
|
||||
*/
|
||||
function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show legend ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a Legendable object to the legend
|
||||
*
|
||||
* @param &$legendable
|
||||
* @param string $title Legend title
|
||||
* @param int $type Legend type (default to LEGEND_LINE)
|
||||
*/
|
||||
function add(&$legendable, $title, $type = LEGEND_LINE) {
|
||||
|
||||
$legend = array($legendable, $title, $type);
|
||||
|
||||
$this->legends[] = $legend;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change legend padding
|
||||
*
|
||||
* @param int $left
|
||||
* @param int $right
|
||||
* @param int $top
|
||||
* @param int $bottom
|
||||
*/
|
||||
function setPadding($left, $right, $top, $bottom) {
|
||||
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change space between each legend
|
||||
*
|
||||
* @param int $space
|
||||
*/
|
||||
function setSpace($space) {
|
||||
$this->space = (int)$space;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change alignment
|
||||
*
|
||||
* @param int $h Horizontal alignment
|
||||
* @param int $v Vertical alignment
|
||||
*/
|
||||
function setAlign($h = NULL, $v = NULL) {
|
||||
if($h !== NULL) {
|
||||
$this->hAlign = (int)$h;
|
||||
}
|
||||
if($v !== NULL) {
|
||||
$this->vAlign = (int)$v;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of columns
|
||||
*
|
||||
* @param int $columns
|
||||
*/
|
||||
function setColumns($columns) {
|
||||
$this->rows = NULL;
|
||||
$this->columns = (int)$columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of rows
|
||||
*
|
||||
* @param int $rows
|
||||
*/
|
||||
function setRows($rows) {
|
||||
$this->columns = NULL;
|
||||
$this->rows = (int)$rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change legend position
|
||||
* X and Y positions must be between 0 and 1.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
*/
|
||||
function setPosition($x = NULL, $y = NULL) {
|
||||
$x = (is_null($x) and !is_null($this->position)) ? $this->position->x : $x;
|
||||
$y = (is_null($y) and !is_null($this->position)) ? $this->position->y : $y;
|
||||
|
||||
$this->position = new awPoint($x, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get legend position
|
||||
*
|
||||
* @return Point
|
||||
*/
|
||||
function getPosition() {
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text font
|
||||
*
|
||||
* @param &$font
|
||||
*/
|
||||
function setTextFont(&$font) {
|
||||
$this->textFont = $font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text margin
|
||||
*
|
||||
* @param int $left
|
||||
* @param int $right
|
||||
*/
|
||||
function setTextMargin($left, $right) {
|
||||
$this->textMargin->set($left, $right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setTextColor($color) {
|
||||
$this->textColor = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change background
|
||||
*
|
||||
* @param mixed $background
|
||||
*/
|
||||
function setBackground($background) {
|
||||
$this->background = $background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change background color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setBackgroundColor($color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change background gradient
|
||||
*
|
||||
* @param $gradient
|
||||
*/
|
||||
function setBackgroundGradient($gradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of Legendable objects in the legend
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function count() {
|
||||
return count($this->legends);
|
||||
}
|
||||
|
||||
function draw($drawer) {
|
||||
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
$count = $this->count();
|
||||
|
||||
// No legend to print
|
||||
if($count === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get text widths and heights of each element of the legend
|
||||
$widths = array();
|
||||
$heights = array();
|
||||
$texts = array();
|
||||
for($i = 0; $i < $count; $i++) {
|
||||
list(, $title, ) = $this->legends[$i];
|
||||
$text = new awText(
|
||||
$title,
|
||||
$this->textFont,
|
||||
$this->textColor,
|
||||
0
|
||||
);
|
||||
$font = $text->getFont();
|
||||
$widths[$i] = $font->getTextWidth($text) + $this->textMargin->left + $this->textMargin->right;
|
||||
$heights[$i] = $font->getTextHeight($text);
|
||||
$texts[$i] = $text;
|
||||
}
|
||||
|
||||
// Maximum height of the font used
|
||||
$heightMax = array_max($heights);
|
||||
|
||||
// Get number of columns
|
||||
if($this->columns !== NULL) {
|
||||
$columns = $this->columns;
|
||||
} else if($this->rows !== NULL) {
|
||||
$columns = ceil($count / $this->rows);
|
||||
} else {
|
||||
$columns = $count;
|
||||
}
|
||||
|
||||
// Number of rows
|
||||
$rows = (int)ceil($count / $columns);
|
||||
|
||||
// Get maximum with of each column
|
||||
$widthMax = array();
|
||||
for($i = 0; $i < $count; $i++) {
|
||||
// Get column width
|
||||
$column = $i % $columns;
|
||||
if(array_key_exists($column, $widthMax) === FALSE) {
|
||||
$widthMax[$column] = $widths[$i];
|
||||
} else {
|
||||
$widthMax[$column] = max($widthMax[$column], $widths[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$width = $this->padding[0] + $this->padding[1] - $this->space;
|
||||
for($i = 0; $i < $columns; $i++) {
|
||||
$width += $this->space + 5 + 10 + $widthMax[$i];
|
||||
}
|
||||
|
||||
$height = ($heightMax + $this->space) * $rows - $this->space + $this->padding[2] + $this->padding[3];
|
||||
|
||||
// Look for legends position
|
||||
list($x, $y) = $drawer->getSize();
|
||||
|
||||
$p = new awPoint(
|
||||
$this->position->x * $x,
|
||||
$this->position->y * $y
|
||||
);
|
||||
|
||||
switch($this->hAlign) {
|
||||
|
||||
case LEGEND_CENTER :
|
||||
$p->x -= $width / 2;
|
||||
break;
|
||||
|
||||
case LEGEND_RIGHT :
|
||||
$p->x -= $width;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
switch($this->vAlign) {
|
||||
|
||||
case LEGEND_MIDDLE :
|
||||
$p->y -= $height / 2;
|
||||
break;
|
||||
|
||||
case LEGEND_BOTTOM :
|
||||
$p->y -= $height;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// Draw legend shadow
|
||||
$this->shadow->draw(
|
||||
$drawer,
|
||||
$p,
|
||||
$p->move($width, $height),
|
||||
SHADOW_OUT
|
||||
);
|
||||
|
||||
// Draw legends base
|
||||
$this->drawBase($drawer, $p, $width, $height);
|
||||
|
||||
// Draw each legend
|
||||
for($i = 0; $i < $count; $i++) {
|
||||
|
||||
list($component, $title, $type) = $this->legends[$i];
|
||||
|
||||
$column = $i % $columns;
|
||||
$row = (int)floor($i / $columns);
|
||||
|
||||
// Get width of all previous columns
|
||||
$previousColumns = 0;
|
||||
for($j = 0; $j < $column; $j++) {
|
||||
$previousColumns += $this->space + 10 + 5 + $widthMax[$j];
|
||||
}
|
||||
|
||||
// Draw legend text
|
||||
$drawer->string(
|
||||
$texts[$i],
|
||||
$p->move(
|
||||
$this->padding[0] + $previousColumns + 10 + 5 + $this->textMargin->left,
|
||||
$this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $heights[$i] / 2
|
||||
)
|
||||
);
|
||||
|
||||
// Draw legend icon
|
||||
switch($type) {
|
||||
|
||||
case LEGEND_LINE :
|
||||
case LEGEND_MARK :
|
||||
case LEGEND_MARKONLY :
|
||||
|
||||
// Get vertical position
|
||||
$x = $this->padding[0] + $previousColumns;
|
||||
$y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $component->getLegendLineThickness();
|
||||
|
||||
// Draw two lines
|
||||
if($component->getLegendLineColor() !== NULL) {
|
||||
|
||||
$color = $component->getLegendLineColor();
|
||||
|
||||
if(is_a($color, 'awColor') and $type !== LEGEND_MARKONLY) {
|
||||
|
||||
$drawer->line(
|
||||
$color,
|
||||
new awLine(
|
||||
$p->move(
|
||||
$x, // YaPB ??
|
||||
$y + $component->getLegendLineThickness() / 2
|
||||
),
|
||||
$p->move(
|
||||
$x + 10,
|
||||
$y + $component->getLegendLineThickness() / 2
|
||||
),
|
||||
$component->getLegendLineStyle(),
|
||||
$component->getLegendLineThickness()
|
||||
)
|
||||
);
|
||||
|
||||
$color->free();
|
||||
unset($color);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($type === LEGEND_MARK or $type === LEGEND_MARKONLY) {
|
||||
|
||||
$mark = $component->getLegendMark();
|
||||
|
||||
if($mark !== NULL) {
|
||||
$mark->draw(
|
||||
$drawer,
|
||||
$p->move(
|
||||
$x + 5.5,
|
||||
$y + $component->getLegendLineThickness() / 2
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
unset($mark);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case LEGEND_BACKGROUND :
|
||||
|
||||
// Get vertical position
|
||||
$x = $this->padding[0] + $previousColumns;
|
||||
$y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - 5;
|
||||
|
||||
$from = $p->move(
|
||||
$x,
|
||||
$y
|
||||
);
|
||||
|
||||
$to = $p->move(
|
||||
$x + 10,
|
||||
$y + 10
|
||||
);
|
||||
|
||||
$background = $component->getLegendBackground();
|
||||
|
||||
if($background !== NULL) {
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$component->getLegendBackground(),
|
||||
new awLine($from, $to)
|
||||
);
|
||||
|
||||
// Draw rectangle border
|
||||
$this->border->rectangle(
|
||||
$drawer,
|
||||
$from->move(0, 0),
|
||||
$to->move(0, 0)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
unset($background, $from, $to);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function drawBase($drawer, $p, $width, $height) {
|
||||
|
||||
$this->border->rectangle(
|
||||
$drawer,
|
||||
$p,
|
||||
$p->move($width, $height)
|
||||
);
|
||||
|
||||
$size = $this->border->visible() ? 1 : 0;
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$this->background,
|
||||
new awLine(
|
||||
$p->move($size, $size),
|
||||
$p->move($width - $size, $height - $size)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Legend');
|
||||
|
||||
/**
|
||||
* You can add a legend to components which implements this interface
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
|
||||
|
||||
registerInterface('Legendable');
|
||||
?>
|
||||
@ -1,335 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("MARK_CIRCLE", 1);
|
||||
define("MARK_SQUARE", 2);
|
||||
define("MARK_IMAGE", 3);
|
||||
define("MARK_STAR", 4);
|
||||
define("MARK_PAPERCLIP", 5);
|
||||
define("MARK_BOOK", 6);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Draw marks
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awMark {
|
||||
|
||||
/**
|
||||
* Circle mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Quare mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Image mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Star mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Paperclip mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Book mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Must marks be hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hide;
|
||||
|
||||
/**
|
||||
* Mark type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $type;
|
||||
|
||||
/**
|
||||
* Mark size
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $size = 8;
|
||||
|
||||
/**
|
||||
* Fill mark
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
var $fill;
|
||||
|
||||
/**
|
||||
* Mark image
|
||||
*
|
||||
* @var Image
|
||||
*/
|
||||
var $image;
|
||||
|
||||
/**
|
||||
* To draw marks
|
||||
*
|
||||
* @var Drawer
|
||||
*/
|
||||
var $drawer;
|
||||
|
||||
/**
|
||||
* Move position from this vector
|
||||
*
|
||||
* @var Point
|
||||
*/
|
||||
var $move;
|
||||
|
||||
/**
|
||||
* Marks border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
var $border;
|
||||
|
||||
/**
|
||||
* Build the mark
|
||||
*/
|
||||
function awMark() {
|
||||
|
||||
$this->fill = new awColor(255, 0, 0, 0);
|
||||
$this->border = new awBorder;
|
||||
$this->border->hide();
|
||||
|
||||
$this->move = new awPoint(0, 0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change mark position
|
||||
*
|
||||
* @param int $x Add this interval to X coord
|
||||
* @param int $y Add this interval to Y coord
|
||||
*/
|
||||
function move($x, $y) {
|
||||
|
||||
$this->move = $this->move->move($x, $y);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide marks ?
|
||||
*
|
||||
* @param bool $hide TRUE to hide marks, FALSE otherwise
|
||||
*/
|
||||
function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show marks ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change mark type
|
||||
*
|
||||
* @param int $size Size in pixels
|
||||
*/
|
||||
function setSize($size) {
|
||||
$this->size = (int)$size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change mark type
|
||||
*
|
||||
* @param int $type New mark type
|
||||
* @param int $size Mark size (can be NULL)
|
||||
*/
|
||||
function setType($type, $size = NULL) {
|
||||
$this->type = (int)$type;
|
||||
if($size !== NULL) {
|
||||
$this->setSize($size);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the mark with a color or a gradient
|
||||
*
|
||||
* @param mixed $fill A color or a gradient
|
||||
*/
|
||||
function setFill($fill) {
|
||||
if(is_a($fill, 'awColor') or is_a($fill, 'awGradient')) {
|
||||
$this->fill = $fill;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an image
|
||||
* Only for MARK_IMAGE type.
|
||||
*
|
||||
* @param Image An image
|
||||
*/
|
||||
function setImage(&$image) {
|
||||
$this->image = $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the mark
|
||||
*
|
||||
* @param $drawer
|
||||
* @param $point Mark center
|
||||
*/
|
||||
function draw($drawer, $point) {
|
||||
|
||||
// Hide marks ?
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we can print marks
|
||||
if($this->type !== NULL) {
|
||||
|
||||
$this->drawer = $drawer;
|
||||
$realPoint = $this->move->move($point->x, $point->y);
|
||||
|
||||
switch($this->type) {
|
||||
|
||||
case MARK_CIRCLE :
|
||||
$this->drawCircle($realPoint);
|
||||
break;
|
||||
|
||||
case MARK_SQUARE :
|
||||
$this->drawSquare($realPoint);
|
||||
break;
|
||||
|
||||
case MARK_IMAGE :
|
||||
$this->drawImage($realPoint);
|
||||
break;
|
||||
|
||||
case MARK_STAR :
|
||||
$this->changeType('star');
|
||||
$this->draw($drawer, $point);
|
||||
break;
|
||||
|
||||
case MARK_PAPERCLIP :
|
||||
$this->changeType('paperclip');
|
||||
$this->draw($drawer, $point);
|
||||
break;
|
||||
|
||||
case MARK_BOOK :
|
||||
$this->changeType('book');
|
||||
$this->draw($drawer, $point);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function changeType($image) {
|
||||
$this->setType(MARK_IMAGE);
|
||||
$this->setImage(new awFileImage(ARTICHOW_IMAGE.DIRECTORY_SEPARATOR.$image.'.png'));
|
||||
}
|
||||
|
||||
function drawCircle($point) {
|
||||
|
||||
$this->drawer->filledEllipse(
|
||||
$this->fill,
|
||||
$point,
|
||||
$this->size, $this->size
|
||||
);
|
||||
|
||||
$this->border->ellipse(
|
||||
$this->drawer,
|
||||
$point,
|
||||
$this->size, $this->size
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function drawSquare($point) {
|
||||
|
||||
list($x, $y) = $point->getLocation();
|
||||
|
||||
$x1 = (int)($x - $this->size / 2);
|
||||
$x2 = $x1 + $this->size;
|
||||
$y1 = (int)($y - $this->size / 2);
|
||||
$y2 = $y1 + $this->size;
|
||||
|
||||
$this->border->rectangle($this->drawer, new awPoint($x1, $y1), new awPoint($x2, $y2));
|
||||
|
||||
$size = $this->border->visible() ? 1 : 0;
|
||||
|
||||
$this->drawer->filledRectangle(
|
||||
$this->fill,
|
||||
new awLine(
|
||||
new awPoint($x1 + $size, $y1 + $size),
|
||||
new awPoint($x2 - $size, $y2 - $size)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function drawImage($point) {
|
||||
|
||||
if(is_a($this->image, 'awImage')) {
|
||||
|
||||
$width = $this->image->width;
|
||||
$height = $this->image->height;
|
||||
|
||||
list($x, $y) = $point->getLocation();
|
||||
|
||||
$x1 = (int)($x - $width / 2);
|
||||
$x2 = $x1 + $width;
|
||||
$y1 = (int)($y - $width / 2);
|
||||
$y2 = $y1 + $height;
|
||||
|
||||
$this->border->rectangle($this->drawer, new awPoint($x1 - 1, $y1 - 1), new awPoint($x2 + 1, $y2 + 1));
|
||||
|
||||
$this->drawer->copyImage($this->image, new awPoint($x1, $y1), new awPoint($x2, $y2));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Mark');
|
||||
?>
|
||||
@ -1,492 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
class awShape {
|
||||
|
||||
/**
|
||||
* Is the shape hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Shape style
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $style;
|
||||
|
||||
/**
|
||||
* Shape thickness
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $thickness;
|
||||
|
||||
/**
|
||||
* Solid shape
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Dotted shape
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Dashed shape
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Change shape style
|
||||
*
|
||||
* @param int $style Line style
|
||||
*/
|
||||
function setStyle($style) {
|
||||
$this->style = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return shape style
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getStyle() {
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change shape thickness
|
||||
*
|
||||
* @param int $thickness Shape thickness in pixels
|
||||
*/
|
||||
function setThickness($thickness) {
|
||||
$this->thickness = (int)$thickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return shape thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getThickness() {
|
||||
return $this->thickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the shape
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
function hide($hide) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the shape
|
||||
*
|
||||
* @param bool $shape
|
||||
*/
|
||||
function show($shape) {
|
||||
$this->hide = (bool)!$shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the line hidden ?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isHidden() {
|
||||
return $this->hide;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Shape', TRUE);
|
||||
|
||||
/**
|
||||
* Describe a point
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPoint extends awShape {
|
||||
|
||||
/**
|
||||
* X coord
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
var $x;
|
||||
|
||||
/**
|
||||
* Y coord
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
var $y;
|
||||
|
||||
/**
|
||||
* Build a new awpoint
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
*/
|
||||
function awPoint($x, $y) {
|
||||
|
||||
$this->setLocation($x, $y);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change X value
|
||||
*
|
||||
* @param float $x
|
||||
*/
|
||||
function setX($x) {
|
||||
$this->x = (float)$x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Y value
|
||||
*
|
||||
* @param float $y
|
||||
*/
|
||||
function setY($y) {
|
||||
$this->y = (float)$y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change point location
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
*/
|
||||
function setLocation($x, $y) {
|
||||
$this->setX($x);
|
||||
$this->setY($y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get point location
|
||||
*
|
||||
* @param array Point location
|
||||
*/
|
||||
function getLocation() {
|
||||
return array($this->x, $this->y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get distance to another point
|
||||
*
|
||||
* @param $p A point
|
||||
* @return float
|
||||
*/
|
||||
function getDistance($p) {
|
||||
|
||||
return sqrt(pow($p->x - $this->x, 2) + pow($p->y - $this->y, 2));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the point to another location
|
||||
*
|
||||
* @param Point A Point with the new awlocation
|
||||
*/
|
||||
function move($x, $y) {
|
||||
|
||||
return new awPoint(
|
||||
$this->x + $x,
|
||||
$this->y + $y
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Point');
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("LINE_SOLID", 1);
|
||||
define("LINE_DOTTED", 2);
|
||||
define("LINE_DASHED", 3);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Describe a line
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLine extends awShape {
|
||||
|
||||
/**
|
||||
* Line first point
|
||||
*
|
||||
* @param Point
|
||||
*/
|
||||
var $p1;
|
||||
|
||||
/**
|
||||
* Line second point
|
||||
*
|
||||
* @param Point
|
||||
*/
|
||||
var $p2;
|
||||
|
||||
/**
|
||||
* Build a new awline
|
||||
*
|
||||
* @param $p1 First point
|
||||
* @param $p2 Second point
|
||||
* @param int $type Style of line (default to solid)
|
||||
* @param int $thickness Line thickness (default to 1)
|
||||
*/
|
||||
function awLine($p1 = NULL, $p2 = NULL, $type = LINE_SOLID, $thickness = 1) {
|
||||
|
||||
$this->setLocation($p1, $p2);
|
||||
$this->setStyle($type);
|
||||
$this->setThickness($thickness);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a line from 4 coords
|
||||
*
|
||||
* @param int $x1 Left position
|
||||
* @param int $y1 Top position
|
||||
* @param int $x2 Right position
|
||||
* @param int $y2 Bottom position
|
||||
*/
|
||||
function build($x1, $y1, $x2, $y2) {
|
||||
|
||||
return new awLine(
|
||||
new awPoint($x1, $y1),
|
||||
new awPoint($x2, $y2)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change X values of the line
|
||||
*
|
||||
* @param int $x1 Begin value
|
||||
* @param int $x2 End value
|
||||
*/
|
||||
function setX($x1, $x2) {
|
||||
$this->p1->setX($x1);
|
||||
$this->p2->setX($x2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Y values of the line
|
||||
*
|
||||
* @param int $y1 Begin value
|
||||
* @param int $y2 End value
|
||||
*/
|
||||
function setY($y1, $y2) {
|
||||
$this->p1->setY($y1);
|
||||
$this->p2->setY($y2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line location
|
||||
*
|
||||
* @param $p1 First point
|
||||
* @param $p2 Second point
|
||||
*/
|
||||
function setLocation($p1, $p2) {
|
||||
if(is_null($p1) or is_a($p1, 'awPoint')) {
|
||||
$this->p1 = $p1;
|
||||
}
|
||||
if(is_null($p2) or is_a($p2, 'awPoint')) {
|
||||
$this->p2 = $p2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line location
|
||||
*
|
||||
* @param array Line location
|
||||
*/
|
||||
function getLocation() {
|
||||
return array($this->p1, $this->p2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line size
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function getSize() {
|
||||
|
||||
$square = pow($this->p2->x - $this->p1->x, 2) + pow($this->p2->y - $this->p1->y, 2);
|
||||
return sqrt($square);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the line can be considered as a point
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isPoint() {
|
||||
return ($this->p1->x === $this->p2->x and $this->p1->y === $this->p2->y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the line is a vertical line
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isVertical() {
|
||||
return ($this->p1->x === $this->p2->x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the line is an horizontal line
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isHorizontal() {
|
||||
return ($this->p1->y === $this->p2->y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Line');
|
||||
|
||||
/**
|
||||
* A vector is a type of line
|
||||
* The sense of the vector goes from $p1 to $p2.
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awVector extends awLine {
|
||||
|
||||
/**
|
||||
* Get vector angle in radians
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function getAngle() {
|
||||
|
||||
if($this->isPoint()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
$size = $this->getSize();
|
||||
|
||||
$width = ($this->p2->x - $this->p1->x);
|
||||
$height = ($this->p2->y - $this->p1->y) * -1;
|
||||
|
||||
if($width >= 0 and $height >= 0) {
|
||||
return acos($width / $size);
|
||||
} else if($width <= 0 and $height >= 0) {
|
||||
return acos($width / $size);
|
||||
} else {
|
||||
$height *= -1;
|
||||
if($width >= 0 and $height >= 0) {
|
||||
return 2 * M_PI - acos($width / $size);
|
||||
} else if($width <= 0 and $height >= 0) {
|
||||
return 2 * M_PI - acos($width / $size);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Vector');
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("POLYGON_SOLID", 1);
|
||||
define("POLYGON_DOTTED", 2);
|
||||
define("POLYGON_DASHED", 3);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Describe a polygon
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPolygon extends awShape {
|
||||
|
||||
/**
|
||||
* Polygon points
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $points = array();
|
||||
|
||||
/**
|
||||
* Set a point in the polygon
|
||||
*
|
||||
* @param int $pos Point position
|
||||
* @param $point
|
||||
*/
|
||||
function set($pos, $point) {
|
||||
if(is_null($point) or is_a($point, 'awPoint')) {
|
||||
$this->points[$pos] = $point;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point at the end of the polygon
|
||||
*
|
||||
* @param $point
|
||||
*/
|
||||
function append($point) {
|
||||
if(is_null($point) or is_a($point, 'awPoint')) {
|
||||
$this->points[] = $point;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point at a position in the polygon
|
||||
*
|
||||
* @param int $pos Point position
|
||||
* @return Point
|
||||
*/
|
||||
function get($pos) {
|
||||
return $this->points[$pos];
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of points in the polygon
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function count() {
|
||||
return count($this->points);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all points in the polygon
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function all() {
|
||||
return $this->points;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Polygon');
|
||||
?>
|
||||
@ -1,415 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("SHADOW_LEFT_TOP", 1);
|
||||
define("SHADOW_LEFT_BOTTOM", 2);
|
||||
define("SHADOW_RIGHT_TOP", 3);
|
||||
define("SHADOW_RIGHT_BOTTOM", 4);
|
||||
|
||||
define("SHADOW_IN", 1);
|
||||
define("SHADOW_OUT", 2);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Draw shadows
|
||||
*
|
||||
*/
|
||||
class awShadow {
|
||||
|
||||
/**
|
||||
* Shadow on left and top sides
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Shadow on left and bottom sides
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Shadow on right and top sides
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Shadow on right and bottom sides
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* In mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Out mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Shadow size
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $size = 0;
|
||||
|
||||
/**
|
||||
* Hide shadow ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Shadow color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $color;
|
||||
|
||||
/**
|
||||
* Shadow position
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $position;
|
||||
|
||||
/**
|
||||
* Smooth shadow ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $smooth = FALSE;
|
||||
|
||||
/**
|
||||
* Shadow constructor
|
||||
*
|
||||
* @param int $position Shadow position
|
||||
*/
|
||||
function awShadow($position) {
|
||||
$this->setPosition($position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide shadow ?
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show shadow ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change shadow size
|
||||
*
|
||||
* @param int $size
|
||||
* @param bool $smooth Smooth the shadow (facultative argument)
|
||||
*/
|
||||
function setSize($size, $smooth = NULL) {
|
||||
$this->size = (int)$size;
|
||||
if($smooth !== NULL) {
|
||||
$this->smooth($smooth);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change shadow color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setColor($color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change shadow position
|
||||
*
|
||||
* @param int $position
|
||||
*/
|
||||
function setPosition($position) {
|
||||
$this->position = (int)$position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Smooth shadow ?
|
||||
*
|
||||
* @param bool $smooth
|
||||
*/
|
||||
function smooth($smooth) {
|
||||
$this->smooth = (bool)$smooth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the space taken by the shadow
|
||||
*
|
||||
* @return Side
|
||||
*/
|
||||
function getSpace() {
|
||||
|
||||
return new awSide(
|
||||
($this->position === SHADOW_LEFT_TOP or $this->position === SHADOW_LEFT_BOTTOM) ? $this->size : 0,
|
||||
($this->position === SHADOW_RIGHT_TOP or $this->position === SHADOW_RIGHT_BOTTOM) ? $this->size : 0,
|
||||
($this->position === SHADOW_LEFT_TOP or $this->position === SHADOW_RIGHT_TOP) ? $this->size : 0,
|
||||
($this->position === SHADOW_LEFT_BOTTOM or $this->position === SHADOW_RIGHT_BOTTOM) ? $this->size : 0
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw shadow
|
||||
*
|
||||
* @param $drawer
|
||||
* @param $p1 Top-left point
|
||||
* @param $p2 Right-bottom point
|
||||
* @param int Drawing mode
|
||||
*/
|
||||
function draw($drawer, $p1, $p2, $mode) {
|
||||
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
if($this->size <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$color = (is_a($this->color, 'awColor')) ? $this->color : new awColor(125, 125, 125);
|
||||
|
||||
switch($this->position) {
|
||||
|
||||
case SHADOW_RIGHT_BOTTOM :
|
||||
|
||||
if($mode === SHADOW_OUT) {
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move($this->size + 1, $this->size + 1);
|
||||
} else { // PHP 4 compatibility
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move(0, 0);
|
||||
}
|
||||
|
||||
$width = $t2->x - $t1->x;
|
||||
$height = $t2->y - $t1->y;
|
||||
|
||||
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($width - $this->size, $this->size),
|
||||
new awPoint($width - 1, $height - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($this->size, $height - $this->size),
|
||||
new awPoint($width - $this->size - 1, $height - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->smoothPast($drawer, $color, $width, $height);
|
||||
|
||||
break;
|
||||
|
||||
case SHADOW_LEFT_TOP :
|
||||
|
||||
if($mode === SHADOW_OUT) {
|
||||
$t1 = $p1->move(- $this->size, - $this->size);
|
||||
$t2 = $p2->move(0, 0);
|
||||
} else { // PHP 4 compatibility
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move(0, 0);
|
||||
}
|
||||
|
||||
$width = $t2->x - $t1->x;
|
||||
$height = $t2->y - $t1->y;
|
||||
|
||||
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
|
||||
|
||||
$height = max($height + 1, $this->size);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint(0, 0),
|
||||
new awPoint($this->size - 1, $height - $this->size - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($this->size, 0),
|
||||
new awPoint($width - $this->size - 1, $this->size - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->smoothPast($drawer, $color, $width, $height);
|
||||
|
||||
break;
|
||||
|
||||
case SHADOW_RIGHT_TOP :
|
||||
|
||||
if($mode === SHADOW_OUT) {
|
||||
$t1 = $p1->move(0, - $this->size);
|
||||
$t2 = $p2->move($this->size + 1, 0);
|
||||
} else { // PHP 4 compatibility
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move(0, 0);
|
||||
}
|
||||
|
||||
$width = $t2->x - $t1->x;
|
||||
$height = $t2->y - $t1->y;
|
||||
|
||||
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
|
||||
|
||||
$height = max($height + 1, $this->size);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($width - $this->size, 0),
|
||||
new awPoint($width - 1, $height - $this->size - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($this->size, 0),
|
||||
new awPoint($width - $this->size - 1, $this->size - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->smoothFuture($drawer, $color, $width, $height);
|
||||
|
||||
break;
|
||||
|
||||
case SHADOW_LEFT_BOTTOM :
|
||||
|
||||
if($mode === SHADOW_OUT) {
|
||||
$t1 = $p1->move(- $this->size, 0);
|
||||
$t2 = $p2->move(0, $this->size + 1);
|
||||
} else { // PHP 4 compatibility
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move(0, 0);
|
||||
}
|
||||
|
||||
$width = $t2->x - $t1->x;
|
||||
$height = $t2->y - $t1->y;
|
||||
|
||||
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint(0, $this->size),
|
||||
new awPoint($this->size - 1, $height - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($this->size, $height - $this->size),
|
||||
new awPoint($width - $this->size - 1, $height - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->smoothFuture($drawer, $color, $width, $height);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function smoothPast($drawer, $color, $width, $height) {
|
||||
|
||||
if($this->smooth) {
|
||||
|
||||
for($i = 0; $i < $this->size; $i++) {
|
||||
for($j = 0; $j <= $i; $j++) {
|
||||
$drawer->point(
|
||||
$color,
|
||||
new awPoint($i, $j + $height - $this->size)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for($i = 0; $i < $this->size; $i++) {
|
||||
for($j = 0; $j <= $i; $j++) {
|
||||
$drawer->point(
|
||||
$color,
|
||||
new awPoint($width - $this->size + $j, $i)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function smoothFuture($drawer, $color, $width, $height) {
|
||||
|
||||
if($this->smooth) {
|
||||
|
||||
for($i = 0; $i < $this->size; $i++) {
|
||||
for($j = 0; $j <= $i; $j++) {
|
||||
$drawer->point(
|
||||
$color,
|
||||
new awPoint($i, $this->size - $j - 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for($i = 0; $i < $this->size; $i++) {
|
||||
for($j = 0; $j <= $i; $j++) {
|
||||
$drawer->point(
|
||||
$color,
|
||||
new awPoint($width - $this->size + $j, $height - $i - 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Shadow');
|
||||
?>
|
||||
@ -1,217 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* To handle text
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awText {
|
||||
|
||||
/**
|
||||
* Your text
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $text;
|
||||
|
||||
/**
|
||||
* Text font
|
||||
*
|
||||
* @var Font
|
||||
*/
|
||||
var $font;
|
||||
|
||||
/**
|
||||
* Text angle
|
||||
* Can be 0 or 90
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $angle;
|
||||
|
||||
/**
|
||||
* Text color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $color;
|
||||
|
||||
/**
|
||||
* Text background
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
var $background;
|
||||
|
||||
/**
|
||||
* Padding
|
||||
*
|
||||
* @var array Array for left, right, top and bottom paddings
|
||||
*/
|
||||
var $padding;
|
||||
|
||||
/**
|
||||
* Text border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
var $border;
|
||||
|
||||
/**
|
||||
* Build a new awtext
|
||||
*
|
||||
* @param string $text Your text
|
||||
*/
|
||||
function awText($text, $font = NULL, $color = NULL, $angle = 0) {
|
||||
|
||||
if(is_null($font)) {
|
||||
$font = new awFont2;
|
||||
}
|
||||
|
||||
$this->setText($text);
|
||||
$this->setFont($font);
|
||||
|
||||
// Set default color to black
|
||||
if($color === NULL) {
|
||||
$color = new awColor(0, 0, 0);
|
||||
}
|
||||
|
||||
$this->setColor($color);
|
||||
$this->setAngle($angle);
|
||||
|
||||
$this->border = new awBorder;
|
||||
$this->border->hide();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getText() {
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text
|
||||
*
|
||||
* @param string $text New text
|
||||
*/
|
||||
function setText($text) {
|
||||
$this->text = (string)$text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text font
|
||||
*
|
||||
* @param Font
|
||||
*/
|
||||
function setFont(&$font) {
|
||||
$this->font = $font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text font
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getFont() {
|
||||
return $this->font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text angle
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
function setAngle($angle) {
|
||||
$this->angle = (int)$angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text angle
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getAngle() {
|
||||
return $this->angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text color
|
||||
*
|
||||
* @param Color
|
||||
*/
|
||||
function setColor($color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text color
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
function getColor() {
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setBackgroundColor($color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background gradient
|
||||
*
|
||||
* @param $gradient
|
||||
*/
|
||||
function setBackgroundGradient($gradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text background
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
function getBackground() {
|
||||
return $this->background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change padding
|
||||
*
|
||||
* @param int $left Left padding
|
||||
* @param int $right Right padding
|
||||
* @param int $top Top padding
|
||||
* @param int $bottom Bottom padding
|
||||
*/
|
||||
function setPadding($left, $right, $top, $bottom) {
|
||||
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current padding
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getPadding() {
|
||||
return $this->padding;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Text');
|
||||
?>
|
||||
@ -1,349 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("TICK_IN", 0);
|
||||
define("TICK_OUT", 1);
|
||||
define("TICK_IN_OUT", 2);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Handle ticks
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awTick {
|
||||
|
||||
/**
|
||||
* Ticks style
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $style = TICK_IN;
|
||||
|
||||
/**
|
||||
* Ticks size
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $size;
|
||||
|
||||
/**
|
||||
* Ticks color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
var $color;
|
||||
|
||||
/**
|
||||
* Ticks number
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $number;
|
||||
|
||||
/**
|
||||
* Ticks number by other tick
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $numberByTick;
|
||||
|
||||
/**
|
||||
* Ticks interval
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $interval = 1;
|
||||
|
||||
/**
|
||||
* Hide ticks
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Hide first tick
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hideFirst = FALSE;
|
||||
|
||||
/**
|
||||
* Hide last tick
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
var $hideLast = FALSE;
|
||||
|
||||
/**
|
||||
* In mode
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Out mode
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* In and out mode
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Build the ticks
|
||||
*
|
||||
* @param int $number Number of ticks
|
||||
* @param int $size Ticks size
|
||||
*/
|
||||
function awTick($number, $size) {
|
||||
|
||||
$this->setSize($size);
|
||||
$this->setNumber($number);
|
||||
$this->setColor(new awBlack);
|
||||
$this->style = TICK_IN;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
function setStyle($style) {
|
||||
$this->style = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ticks style
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getStyle() {
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks color
|
||||
*
|
||||
* @param $color
|
||||
*/
|
||||
function setColor($color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks size
|
||||
*
|
||||
* @param int $size
|
||||
*/
|
||||
function setSize($size) {
|
||||
$this->size = (int)$size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change interval of ticks
|
||||
*
|
||||
* @param int $interval
|
||||
*/
|
||||
function setInterval($interval) {
|
||||
$this->interval = (int)$interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get interval between each tick
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getInterval() {
|
||||
return $this->interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of ticks
|
||||
*
|
||||
* @param int $number
|
||||
*/
|
||||
function setNumber($number) {
|
||||
$this->number = (int)$number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of ticks
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function getNumber() {
|
||||
return $this->number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of ticks relative to others ticks
|
||||
*
|
||||
* @param &$tick Ticks reference
|
||||
* @param int $number Number of ticks
|
||||
*/
|
||||
function setNumberByTick(&$tick, $number) {
|
||||
|
||||
$this->numberByTick = array(&$tick, (int)$number);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide ticks
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
function hide($hide) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide first tick
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
function hideFirst($hide) {
|
||||
$this->hideFirst = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide last tick
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
function hideLast($hide) {
|
||||
$this->hideLast = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw ticks on a vector
|
||||
*
|
||||
* @param $drawer A drawer
|
||||
* @param &$vector A vector
|
||||
*/
|
||||
function draw($drawer, &$vector) {
|
||||
|
||||
if($this->numberByTick !== NULL) {
|
||||
list($tick, $number) = $this->numberByTick;
|
||||
$this->number = 1 + ($tick->getNumber() - 1) * ($number + 1);
|
||||
$this->interval = $tick->getInterval();
|
||||
}
|
||||
|
||||
if($this->number < 2 or $this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
$angle = $vector->getAngle();
|
||||
// echo "INIT:".$angle."<br>";
|
||||
switch($this->style) {
|
||||
|
||||
case TICK_IN :
|
||||
$this->drawTicks($drawer, $vector, NULL, $angle + M_PI / 2);
|
||||
break;
|
||||
|
||||
case TICK_OUT :
|
||||
$this->drawTicks($drawer, $vector, $angle + 3 * M_PI / 2, NULL);
|
||||
break;
|
||||
|
||||
default :
|
||||
$this->drawTicks($drawer, $vector, $angle + M_PI / 2, $angle + 3 * M_PI / 2);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function drawTicks($drawer, &$vector, $from, $to) {
|
||||
|
||||
// Draw last tick
|
||||
if($this->hideLast === FALSE) {
|
||||
|
||||
//echo '<b>';
|
||||
if(($this->number - 1) % $this->interval === 0) {
|
||||
$this->drawTick($drawer, $vector->p2, $from, $to);
|
||||
}
|
||||
//echo '</b>';
|
||||
|
||||
}
|
||||
|
||||
$number = $this->number - 1;
|
||||
$size = $vector->getSize();
|
||||
|
||||
// Get tick increment in pixels
|
||||
$inc = $size / $number;
|
||||
|
||||
// Check if we must hide the first tick
|
||||
$start = $this->hideFirst ? $inc : 0;
|
||||
$stop = $inc * $number;
|
||||
|
||||
$position = 0;
|
||||
|
||||
for($i = $start; round($i, 6) < $stop; $i += $inc) {
|
||||
|
||||
if($position % $this->interval === 0) {
|
||||
$p = $vector->p1->move(
|
||||
round($i * cos($vector->getAngle()), 6),
|
||||
round($i * sin($vector->getAngle() * -1), 6)
|
||||
);
|
||||
$this->drawTick($drawer, $p, $from, $to);
|
||||
}
|
||||
|
||||
$position++;
|
||||
|
||||
}
|
||||
//echo '<br><br>';
|
||||
}
|
||||
|
||||
function drawTick($drawer, $p, $from, $to) {
|
||||
// echo $this->size.':'.$angle.'|<b>'.cos($angle).'</b>/';
|
||||
// The round avoid some errors in the calcul
|
||||
// For example, 12.00000008575245 becomes 12
|
||||
$p1 = $p;
|
||||
$p2 = $p;
|
||||
|
||||
if($from !== NULL) {
|
||||
$p1 = $p1->move(
|
||||
round($this->size * cos($from), 6),
|
||||
round($this->size * sin($from) * -1, 6)
|
||||
);
|
||||
}
|
||||
|
||||
if($to !== NULL) {
|
||||
$p2 = $p2->move(
|
||||
round($this->size * cos($to), 6),
|
||||
round($this->size * sin($to) * -1, 6)
|
||||
);
|
||||
}
|
||||
//echo $p1->x.':'.$p2->x.'('.$p1->y.':'.$p2->y.')'.'/';
|
||||
$vector = new awVector(
|
||||
$p1, $p2
|
||||
);
|
||||
|
||||
$drawer->line(
|
||||
$this->color,
|
||||
$vector
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Tick');
|
||||
?>
|
||||
@ -1,121 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Objects capable of being positioned
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
|
||||
|
||||
registerInterface('Positionable');
|
||||
|
||||
/**
|
||||
* Manage left, right, top and bottom sides
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awSide {
|
||||
|
||||
/**
|
||||
* Left side
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $left = 0;
|
||||
|
||||
/**
|
||||
* Right side
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $right = 0;
|
||||
|
||||
/**
|
||||
* Top side
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $top = 0;
|
||||
|
||||
/**
|
||||
* Bottom side
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $bottom = 0;
|
||||
|
||||
/**
|
||||
* Build the side
|
||||
*
|
||||
* @param mixed $left
|
||||
* @param mixed $right
|
||||
* @param mixed $top
|
||||
* @param mixed $bottom
|
||||
*/
|
||||
function awSide($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
|
||||
$this->set($left, $right, $top, $bottom);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change side values
|
||||
*
|
||||
* @param mixed $left
|
||||
* @param mixed $right
|
||||
* @param mixed $top
|
||||
* @param mixed $bottom
|
||||
*/
|
||||
function set($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
|
||||
|
||||
if($left !== NULL) {
|
||||
$this->left = (float)$left;
|
||||
}
|
||||
if($right !== NULL) {
|
||||
$this->right = (float)$right;
|
||||
}
|
||||
if($top !== NULL) {
|
||||
$this->top = (float)$top;
|
||||
}
|
||||
if($bottom !== NULL) {
|
||||
$this->bottom = (float)$bottom;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add values to each side
|
||||
*
|
||||
* @param mixed $left
|
||||
* @param mixed $right
|
||||
* @param mixed $top
|
||||
* @param mixed $bottom
|
||||
*/
|
||||
function add($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
|
||||
|
||||
if($left !== NULL) {
|
||||
$this->left += (float)$left;
|
||||
}
|
||||
if($right !== NULL) {
|
||||
$this->right += (float)$right;
|
||||
}
|
||||
if($top !== NULL) {
|
||||
$this->top += (float)$top;
|
||||
}
|
||||
if($bottom !== NULL) {
|
||||
$this->bottom += (float)$bottom;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Side');
|
||||
?>
|
||||
@ -24,11 +24,13 @@
|
||||
|
||||
|
||||
/**
|
||||
* Check user and password
|
||||
* @param usertotest Login
|
||||
* @param passwordtotest Password
|
||||
* @param entitytotest Entity
|
||||
* @return string Login if ok, '' if ko.
|
||||
* Check validity of user/password/entity
|
||||
* If test is ko, reason must be filled into $_SESSION["dol_loginmesg"]
|
||||
*
|
||||
* @param string $usertotest Login
|
||||
* @param string $passwordtotest Password
|
||||
* @param int $entitytotest Number of instance (always 1 if module multicompany not enabled)
|
||||
* @return string Login if OK, '' if KO
|
||||
*/
|
||||
function check_user_password_dolibarr($usertotest,$passwordtotest,$entitytotest=1)
|
||||
{
|
||||
|
||||
@ -23,10 +23,13 @@
|
||||
|
||||
|
||||
/**
|
||||
* \brief Check user and password
|
||||
* \param usertotest Login
|
||||
* \param passwordtotest Password
|
||||
* \return string Login if ok, '' if ko.
|
||||
* Check validity of user/password/entity
|
||||
* If test is ko, reason must be filled into $_SESSION["dol_loginmesg"]
|
||||
*
|
||||
* @param string $usertotest Login
|
||||
* @param string $passwordtotest Password
|
||||
* @param int $entitytotest Number of instance (always 1 if module multicompany not enabled)
|
||||
* @return string Login if OK, '' if KO
|
||||
*/
|
||||
function check_user_password_empty($usertotest,$passwordtotest)
|
||||
{
|
||||
|
||||
@ -24,23 +24,26 @@
|
||||
|
||||
|
||||
/**
|
||||
\brief Check user and password
|
||||
\param usertotest Login
|
||||
\param passwordtotest Password
|
||||
\return string Login if ok, '' if ko.
|
||||
*/
|
||||
* Check validity of user/password/entity
|
||||
* If test is ko, reason must be filled into $_SESSION["dol_loginmesg"]
|
||||
*
|
||||
* @param string $usertotest Login
|
||||
* @param string $passwordtotest Password
|
||||
* @param int $entitytotest Number of instance (always 1 if module multicompany not enabled)
|
||||
* @return string Login if OK, '' if KO
|
||||
*/
|
||||
function check_user_password_forceuser($usertotest,$passwordtotest)
|
||||
{
|
||||
// Variable dolibarr_auto_user must be defined in conf.php file
|
||||
global $dolibarr_auto_user;
|
||||
|
||||
|
||||
dol_syslog("functions_forceuser::check_user_password_forceuser");
|
||||
|
||||
$login=$dolibarr_auto_user;
|
||||
if (empty($login)) $login='auto';
|
||||
|
||||
|
||||
if ($_SESSION["dol_loginmesg"]) $login='';
|
||||
|
||||
|
||||
return $login;
|
||||
}
|
||||
|
||||
|
||||
@ -23,10 +23,13 @@
|
||||
|
||||
|
||||
/**
|
||||
\brief Check user and password
|
||||
\param usertotest Login
|
||||
\param passwordtotest Password
|
||||
\return string Login if ok, '' if ko.
|
||||
* Check validity of user/password/entity
|
||||
* If test is ko, reason must be filled into $_SESSION["dol_loginmesg"]
|
||||
*
|
||||
* @param string $usertotest Login
|
||||
* @param string $passwordtotest Password
|
||||
* @param int $entitytotest Number of instance (always 1 if module multicompany not enabled)
|
||||
* @return string Login if OK, '' if KO
|
||||
*/
|
||||
function check_user_password_http($usertotest,$passwordtotest)
|
||||
{
|
||||
@ -37,7 +40,7 @@ function check_user_password_http($usertotest,$passwordtotest)
|
||||
{
|
||||
$login=$_SERVER["REMOTE_USER"];
|
||||
}
|
||||
|
||||
|
||||
return $login;
|
||||
}
|
||||
|
||||
|
||||
@ -24,11 +24,13 @@
|
||||
|
||||
|
||||
/**
|
||||
* @brief Check user and password
|
||||
* @param usertotest Login
|
||||
* @param passwordtotest Password
|
||||
* @return string Login if ok, '' if ko.
|
||||
* @remarks If test is ko, reason must be filled into $_SESSION["dol_loginmesg"]
|
||||
* Check validity of user/password/entity
|
||||
* If test is ko, reason must be filled into $_SESSION["dol_loginmesg"]
|
||||
*
|
||||
* @param string $usertotest Login
|
||||
* @param string $passwordtotest Password
|
||||
* @param int $entitytotest Number of instance (always 1 if module multicompany not enabled)
|
||||
* @return string Login if OK, '' if KO
|
||||
*/
|
||||
function check_user_password_ldap($usertotest,$passwordtotest)
|
||||
{
|
||||
|
||||
@ -24,10 +24,13 @@
|
||||
|
||||
|
||||
/**
|
||||
* \brief Check user and password
|
||||
* \param usertotest Login
|
||||
* \param passwordtotest Password
|
||||
* \return string Login if ok, '' if ko.
|
||||
* Check validity of user/password/entity
|
||||
* If test is ko, reason must be filled into $_SESSION["dol_loginmesg"]
|
||||
*
|
||||
* @param string $usertotest Login
|
||||
* @param string $passwordtotest Password
|
||||
* @param int $entitytotest Number of instance (always 1 if module multicompany not enabled)
|
||||
* @return string Login if OK, '' if KO
|
||||
*/
|
||||
function check_user_password_myopenid($usertotest,$passwordtotest)
|
||||
{
|
||||
|
||||
@ -15,7 +15,7 @@ ErrorFailedToRunExternalCommand=Failed to run external command. Check it is avai
|
||||
ErrorFailedToChangePassword=Failed to change password
|
||||
ErrorLoginDoesNotExists=User with login <b>%s</b> could not be found.
|
||||
ErrorLoginHasNoEmail=This user has no email address. Process aborted.
|
||||
ErrorBadValueForCode=Bad value types for code. Try again with a new value...
|
||||
ErrorBadValueForCode=Bad value for security code. Try again with new value...
|
||||
SecurityCode=Security code
|
||||
Calendar=Calendar
|
||||
AddTrip=Add trip
|
||||
|
||||
@ -30,13 +30,12 @@ if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC',1);
|
||||
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1);
|
||||
|
||||
require_once("../main.inc.php");
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/artichow/Artichow.cfg.php';
|
||||
require_once ARTICHOW."/AntiSpam.class.php";
|
||||
require_once(ARTICHOW_PATH.'Artichow.cfg.php');
|
||||
require_once(ARTICHOW.'/AntiSpam.class.php');
|
||||
|
||||
// On cree l'objet anti-spam
|
||||
$object = new AntiSpam();
|
||||
|
||||
// La valeur affichée sur l'image aura 5 lettres
|
||||
// Value of image will contains 5 characters
|
||||
$value=$object->setRand(5);
|
||||
$object->setSize(128,36);
|
||||
|
||||
|
||||
@ -766,10 +766,11 @@ function dol_delete_preview($object)
|
||||
/**
|
||||
* Get and save an upload file (for example after submitting a new file a mail form).
|
||||
* All information used are in db, conf, langs, user and _FILES.
|
||||
* @param upload_dir Directory to store upload files
|
||||
* @param allowoverwrite 1=Allow overwrite existing file
|
||||
* @param donotupdatesession 1=Do no edit _SESSION variable
|
||||
* @return string Message with result of upload and store.
|
||||
*
|
||||
* @param string $upload_dir Directory to store upload files
|
||||
* @param int $allowoverwrite 1=Allow overwrite existing file
|
||||
* @param int $donotupdatesession 1=Do no edit _SESSION variable
|
||||
* @return string Message with result of upload and store.
|
||||
*/
|
||||
function dol_add_file_process($upload_dir,$allowoverwrite=0,$donotupdatesession=0)
|
||||
{
|
||||
|
||||
@ -3349,10 +3349,10 @@ function create_exdir($dir)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creation of a directory (recursive)
|
||||
* Creation of a directory (this can create recursive subdir)
|
||||
*
|
||||
* @param $dir Directory to create
|
||||
* @return int < 0 if KO, 0 = already exists, > 0 if OK
|
||||
* @param string $dir Directory to create (Separator must be '/'. Example: '/mydir/mysubdir')
|
||||
* @return int < 0 if KO, 0 = already exists, > 0 if OK
|
||||
*/
|
||||
function dol_mkdir($dir)
|
||||
{
|
||||
|
||||
@ -24,61 +24,113 @@
|
||||
|
||||
|
||||
/**
|
||||
* Return a login if login/pass was successfull using an external login method.
|
||||
* Return a login if login/pass was successfull
|
||||
*
|
||||
* @param string $usertotest Login value to test
|
||||
* @param string $passwordtotest Password value to test
|
||||
* @param string $entitytotest Instance to test
|
||||
* @param array $authmode Array list of selected authentication mode ('http', 'dolibarr', 'xxx'...)
|
||||
* @return string Login or ''
|
||||
*/
|
||||
function getLoginMethod($usertotest,$passwordtotest,$entitytotest=1)
|
||||
function checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmode)
|
||||
{
|
||||
global $conf,$langs;
|
||||
global $dolauthmode; // To return authentication finally used
|
||||
|
||||
// Check parameetrs
|
||||
if ($entitytotest == '') $entitytotest=1;
|
||||
|
||||
dol_syslog("checkLoginPassEntity usertotest=".$usertotest." entitytotest=".$entitytotest." authmode=".join(',',$authmode));
|
||||
$login = '';
|
||||
|
||||
foreach($conf->login_method_modules as $dir)
|
||||
// Validation of login/pass/entity with a third party login module method
|
||||
if (is_array($conf->login_method_modules) && !empty($conf->login_method_modules))
|
||||
{
|
||||
// Check if directory exists
|
||||
if (!is_dir($dir)) continue;
|
||||
foreach($conf->login_method_modules as $dir)
|
||||
{
|
||||
$newdir=dol_osencode($dir);
|
||||
|
||||
$handle=opendir($dir);
|
||||
if (is_resource($handle))
|
||||
{
|
||||
while (($file = readdir($handle))!==false)
|
||||
{
|
||||
if (is_readable($dir.'/'.$file) && preg_match('/^functions_([^_]+)\.php/',$file,$reg))
|
||||
{
|
||||
$authfile = $dir.'/'.$file;
|
||||
$mode = $reg[1];
|
||||
// Check if directory exists
|
||||
if (!is_dir($newdir)) continue;
|
||||
|
||||
$result=include_once($authfile);
|
||||
if ($result)
|
||||
{
|
||||
// Call function to check user/password
|
||||
$function='check_user_password_'.$mode;
|
||||
$login=call_user_func($function,$usertotest,$passwordtotest,$entitytotest);
|
||||
if ($login)
|
||||
{
|
||||
$conf->authmode=$mode; // This properties is defined only when logged
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_syslog("Authentification ko - failed to load file '".$authfile."'",LOG_ERR);
|
||||
sleep(1); // To slow brut force cracking
|
||||
$langs->load('main');
|
||||
$langs->load('other');
|
||||
$_SESSION["dol_loginmesg"]=$langs->trans("ErrorFailedToLoadLoginFileForMode",$mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
$handle=opendir($newdir);
|
||||
if (is_resource($handle))
|
||||
{
|
||||
while (($file = readdir($handle))!==false)
|
||||
{
|
||||
if (is_readable($dir.'/'.$file) && preg_match('/^functions_([^_]+)\.php/',$file,$reg))
|
||||
{
|
||||
$authfile = $dir.'/'.$file;
|
||||
$mode = $reg[1];
|
||||
|
||||
$result=include_once($authfile);
|
||||
if ($result)
|
||||
{
|
||||
// Call function to check user/password
|
||||
$function='check_user_password_'.$mode;
|
||||
$login=call_user_func($function,$usertotest,$passwordtotest,$entitytotest);
|
||||
if ($login)
|
||||
{
|
||||
$conf->authmode=$mode; // This properties is defined only when logged to say what mode was successfully used
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_syslog("Authentification ko - failed to load file '".$authfile."'",LOG_ERR);
|
||||
sleep(1); // To slow brut force cracking
|
||||
$langs->load('main');
|
||||
$langs->load('other');
|
||||
$_SESSION["dol_loginmesg"]=$langs->trans("ErrorFailedToLoadLoginFileForMode",$mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validation of login/pass/entity with standard modules
|
||||
if (empty($login))
|
||||
{
|
||||
$test=true;
|
||||
foreach($authmode as $mode)
|
||||
{
|
||||
if ($test && $mode && ! $login)
|
||||
{
|
||||
$mode=trim($mode);
|
||||
$authfile=DOL_DOCUMENT_ROOT.'/includes/login/functions_'.$mode.'.php';
|
||||
$result=include_once($authfile);
|
||||
if ($result)
|
||||
{
|
||||
// Call function to check user/password
|
||||
$function='check_user_password_'.$mode;
|
||||
$login=call_user_func($function,$usertotest,$passwordtotest,$entitytotest);
|
||||
if ($login) // Login is successfull
|
||||
{
|
||||
$test=false; // To stop once at first login success
|
||||
$conf->authmode=$mode; // This properties is defined only when logged to say what mode was successfully used
|
||||
$dol_tz=$_POST["tz"];
|
||||
$dol_dst=$_POST["dst"];
|
||||
$dol_screenwidth=$_POST["screenwidth"];
|
||||
$dol_screenheight=$_POST["screenheight"];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_syslog("Authentification ko - failed to load file '".$authfile."'",LOG_ERR);
|
||||
sleep(1);
|
||||
$langs->load('main');
|
||||
$langs->load('other');
|
||||
$_SESSION["dol_loginmesg"]=$langs->trans("ErrorFailedToLoadLoginFileForMode",$mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $login;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show Dolibarr default login page
|
||||
*
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
/**
|
||||
* Check authentication array and set error, errorcode, errorlabel
|
||||
*
|
||||
* @param authentication Array
|
||||
* @param error
|
||||
* @param errorcode
|
||||
@ -32,6 +33,7 @@
|
||||
function check_authentication($authentication,&$error,&$errorcode,&$errorlabel)
|
||||
{
|
||||
global $db,$conf,$langs;
|
||||
global $dolibarr_main_authentication,$dolibarr_auto_user;
|
||||
|
||||
$fuser=new User($db);
|
||||
|
||||
@ -50,26 +52,34 @@ function check_authentication($authentication,&$error,&$errorcode,&$errorlabel)
|
||||
if (! $error)
|
||||
{
|
||||
$result=$fuser->fetch('',$authentication['login'],'',0);
|
||||
if ($result <= 0) $error++;
|
||||
|
||||
// Validation of login with a third party login module method
|
||||
if (! $error)
|
||||
{
|
||||
if (is_array($conf->login_method_modules) && !empty($conf->login_method_modules))
|
||||
{
|
||||
$login = getLoginMethod($authentication['login'],$authentication['password'],$authentication['entity']);
|
||||
if (empty($login)) $error++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$errorcode='BAD_LOGIN_METHOD'; $errorlabel='Bad value for login method';
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
$errorcode='ERROR_FETCH_USER'; $errorlabel='A technical error occurs during fetch of user';
|
||||
}
|
||||
else if ($result == 0)
|
||||
{
|
||||
$error++;
|
||||
$errorcode='BAD_CREDENTIALS'; $errorlabel='Bad value for login or password';
|
||||
}
|
||||
|
||||
// Validation of login
|
||||
if (! $error)
|
||||
{
|
||||
// Authentication mode
|
||||
if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication='http,dolibarr';
|
||||
// Authentication mode: forceuser
|
||||
if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) $dolibarr_auto_user='auto';
|
||||
// Set authmode
|
||||
$authmode=explode(',',$dolibarr_main_authentication);
|
||||
|
||||
$login = checkLoginPassEntity($authentication['login'],$authentication['password'],$authentication['entity'],$authmode);
|
||||
if (empty($login))
|
||||
{
|
||||
$error++;
|
||||
$errorcode='BAD_CREDENTIALS'; $errorlabel='Bad value for login or password';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $fuser;
|
||||
|
||||
@ -155,7 +155,6 @@ require_once("master.inc.php");
|
||||
register_shutdown_function('dol_shutdown');
|
||||
|
||||
// Detection browser
|
||||
// TODO rename conf->browser into user->browser
|
||||
if (isset($_SERVER["HTTP_USER_AGENT"]))
|
||||
{
|
||||
// If phone/smartphone, we set phone os name.
|
||||
@ -304,7 +303,6 @@ if (! defined('NOLOGIN'))
|
||||
if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication='http,dolibarr';
|
||||
// Authentication mode: forceuser
|
||||
if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) $dolibarr_auto_user='auto';
|
||||
|
||||
// Set authmode
|
||||
$authmode=explode(',',$dolibarr_main_authentication);
|
||||
|
||||
@ -339,10 +337,9 @@ if (! defined('NOLOGIN'))
|
||||
// Verification security graphic code
|
||||
if (isset($_POST["username"]) && ! empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/artichow/Artichow.cfg.php';
|
||||
require_once ARTICHOW."/AntiSpam.class.php";
|
||||
require_once(ARTICHOW_PATH.'Artichow.cfg.php');
|
||||
require_once(ARTICHOW.'/AntiSpam.class.php');
|
||||
|
||||
// It creates an anti-spam object
|
||||
$object = new AntiSpam();
|
||||
|
||||
// Verifie code
|
||||
@ -365,15 +362,12 @@ if (! defined('NOLOGIN'))
|
||||
}
|
||||
}
|
||||
|
||||
// Validation of login with a third party login module method
|
||||
if (is_array($conf->login_method_modules) && !empty($conf->login_method_modules))
|
||||
{
|
||||
$login = getLoginMethod($_POST["username"],$_POST["password"],$_POST["entity"]);
|
||||
if ($login) $test=false;
|
||||
}
|
||||
$usertotest=$_POST["username"];
|
||||
$passwordtotest=$_POST["password"];
|
||||
$entitytotest=$_POST["entity"];
|
||||
|
||||
// Validation tests user / password
|
||||
// If ok, the variable will be initialized login
|
||||
// Validation of login/pass/entity
|
||||
// If ok, the variable login will be returned
|
||||
// If error, we will put error message in session under the name dol_loginmesg
|
||||
$goontestloop=false;
|
||||
if (isset($_SERVER["REMOTE_USER"]) && in_array('http',$authmode)) $goontestloop=true;
|
||||
@ -381,39 +375,14 @@ if (! defined('NOLOGIN'))
|
||||
|
||||
if ($test && $goontestloop)
|
||||
{
|
||||
foreach($authmode as $mode)
|
||||
$login = checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmode);
|
||||
if ($login)
|
||||
{
|
||||
if ($test && $mode && ! $login)
|
||||
{
|
||||
$authfile=DOL_DOCUMENT_ROOT.'/includes/login/functions_'.$mode.'.php';
|
||||
$result=include_once($authfile);
|
||||
if ($result)
|
||||
{
|
||||
// Call function to check user/password
|
||||
$usertotest=$_POST["username"];
|
||||
$passwordtotest=$_POST["password"];
|
||||
$entitytotest=$_POST["entity"];
|
||||
$function='check_user_password_'.$mode;
|
||||
$login=$function($usertotest,$passwordtotest,$entitytotest);
|
||||
if ($login) // Login is successfull
|
||||
{
|
||||
$test=false;
|
||||
$dol_authmode=$mode; // This properties is defined only when logged to say what mode was successfully used
|
||||
$dol_tz=$_POST["tz"];
|
||||
$dol_dst=$_POST["dst"];
|
||||
$dol_screenwidth=$_POST["screenwidth"];
|
||||
$dol_screenheight=$_POST["screenheight"];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_syslog("Authentification ko - failed to load file '".$authfile."'",LOG_ERR);
|
||||
sleep(1);
|
||||
$langs->load('main');
|
||||
$langs->load('other');
|
||||
$_SESSION["dol_loginmesg"]=$langs->trans("ErrorFailedToLoadLoginFileForMode",$mode);
|
||||
}
|
||||
}
|
||||
$dol_authmode=$conf->authmode; // This properties is defined only when logged to say what mode was successfully used
|
||||
$dol_tz=$_POST["tz"];
|
||||
$dol_dst=$_POST["dst"];
|
||||
$dol_screenwidth=$_POST["screenwidth"];
|
||||
$dol_screenheight=$_POST["screenheight"];
|
||||
}
|
||||
|
||||
if (! $login)
|
||||
|
||||
@ -45,8 +45,8 @@ class User extends CommonObject
|
||||
var $search_sid;
|
||||
var $nom; // TODO deprecated
|
||||
var $prenom; // TODO deprecated
|
||||
var $lastname;
|
||||
var $firstname;
|
||||
var $lastname;
|
||||
var $firstname;
|
||||
var $note;
|
||||
var $email;
|
||||
var $signature;
|
||||
@ -66,7 +66,7 @@ class User extends CommonObject
|
||||
|
||||
var $datec;
|
||||
var $datem;
|
||||
//! If this is defined, it is an external user
|
||||
//! If this is defined, it is an external user
|
||||
var $societe_id;
|
||||
var $fk_member;
|
||||
|
||||
@ -130,7 +130,7 @@ class User extends CommonObject
|
||||
$login=trim($login);
|
||||
|
||||
// Get user
|
||||
$sql = "SELECT u.rowid, u.name, u.firstname, u.email, u.signature, u.office_phone, u.office_fax, u.user_mobile,";
|
||||
$sql = "SELECT u.rowid, u.name, u.firstname, u.email, u.signature, u.office_phone, u.office_fax, u.user_mobile,";
|
||||
$sql.= " u.admin, u.login, u.webcal_login, u.phenix_login, u.phenix_pass, u.note,";
|
||||
$sql.= " u.pass, u.pass_crypted, u.pass_temp,";
|
||||
$sql.= " u.fk_societe, u.fk_socpeople, u.fk_member, u.ldap_sid,";
|
||||
@ -166,7 +166,7 @@ class User extends CommonObject
|
||||
$sql.= " AND u.rowid = ".$id;
|
||||
}
|
||||
|
||||
dol_syslog("User::Fetch sql=".$sql, LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
@ -194,7 +194,7 @@ class User extends CommonObject
|
||||
$this->office_fax = $obj->office_fax;
|
||||
$this->user_mobile = $obj->user_mobile;
|
||||
$this->email = $obj->email;
|
||||
$this->signature = $obj->signature;
|
||||
$this->signature = $obj->signature;
|
||||
$this->admin = $obj->admin;
|
||||
$this->note = $obj->note;
|
||||
$this->statut = $obj->statut;
|
||||
@ -222,7 +222,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error="USERNOTFOUND";
|
||||
dol_syslog("User::fetch user not found", LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::fetch user not found", LOG_DEBUG);
|
||||
|
||||
$this->db->free($result);
|
||||
return 0;
|
||||
@ -231,7 +231,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("User::fetch Error -1, fails to get user - ".$this->error." - sql=".$sql, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::fetch Error -1, fails to get user - ".$this->error." - sql=".$sql, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -258,7 +258,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("User::fetch Error -2, fails to get setup user - ".$this->error." - sql=".$sql, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::fetch Error -2, fails to get setup user - ".$this->error." - sql=".$sql, LOG_ERR);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
@ -468,7 +468,7 @@ class User extends CommonObject
|
||||
*/
|
||||
function clearrights()
|
||||
{
|
||||
dol_syslog("User::clearrights reset user->rights");
|
||||
dol_syslog(get_class($this)."::clearrights reset user->rights");
|
||||
$this->rights='';
|
||||
$this->all_permissions_are_loaded=false;
|
||||
$this->tab_loaded=array();
|
||||
@ -509,7 +509,7 @@ class User extends CommonObject
|
||||
$sql.= " AND r.perms IS NOT NULL";
|
||||
if ($moduletag) $sql.= " AND r.module = '".$this->db->escape($moduletag)."'";
|
||||
|
||||
dol_syslog('User::getRights sql='.$sql, LOG_DEBUG);
|
||||
dol_syslog(get_class($this).'::getRights sql='.$sql, LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
@ -558,7 +558,7 @@ class User extends CommonObject
|
||||
$sql.= " AND gu.entity IN (0,".$conf->entity.")";
|
||||
if ($moduletag) $sql.= " AND r.module = '".$this->db->escape($moduletag)."'";
|
||||
|
||||
dol_syslog('User::getRights sql='.$sql, LOG_DEBUG);
|
||||
dol_syslog(get_class($this).'::getRights sql='.$sql, LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
@ -623,7 +623,7 @@ class User extends CommonObject
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
dol_syslog("User::setstatus sql=".$sql);
|
||||
dol_syslog(get_class($this)."::setstatus sql=".$sql);
|
||||
if ($result)
|
||||
{
|
||||
// Appel des triggers
|
||||
@ -722,7 +722,7 @@ class User extends CommonObject
|
||||
$this->login = trim($this->login);
|
||||
if (! isset($this->entity)) $this->entity=$conf->entity; // If not defined, we use default value
|
||||
|
||||
dol_syslog("User::Create login=".$this->login.", user=".(is_object($user)?$user->id:''), LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::create login=".$this->login.", user=".(is_object($user)?$user->id:''), LOG_DEBUG);
|
||||
|
||||
// Check parameters
|
||||
if (! empty($conf->global->USER_MAIL_REQUIRED) && ! isValidEMail($this->email))
|
||||
@ -751,7 +751,7 @@ class User extends CommonObject
|
||||
if ($num)
|
||||
{
|
||||
$this->error = 'ErrorLoginAlreadyExists';
|
||||
dol_syslog("User::Create ".$this->error, LOG_WARNING);
|
||||
dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING);
|
||||
$this->db->rollback();
|
||||
return -6;
|
||||
}
|
||||
@ -761,7 +761,7 @@ class User extends CommonObject
|
||||
$sql.= " VALUES('".$this->db->idate($now)."','".$this->db->escape($this->login)."','".$this->ldap_sid."',".$this->entity.")";
|
||||
$result=$this->db->query($sql);
|
||||
|
||||
dol_syslog("User::Create sql=".$sql, LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
|
||||
if ($result)
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."user");
|
||||
@ -811,7 +811,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$interface->error;
|
||||
dol_syslog("User::Create ".$this->error, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
@ -819,7 +819,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("User::Create ".$this->error, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
@ -828,7 +828,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("User::Create ".$this->error, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
@ -870,7 +870,7 @@ class User extends CommonObject
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
$resql=$this->db->query($sql);
|
||||
|
||||
dol_syslog("User::create_from_contact sql=".$sql, LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::create_from_contact sql=".$sql, LOG_DEBUG);
|
||||
if ($resql)
|
||||
{
|
||||
// Appel des triggers
|
||||
@ -886,7 +886,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("User::create_from_contact ".$this->error, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::create_from_contact ".$this->error, LOG_ERR);
|
||||
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
@ -895,7 +895,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
// $this->error deja positionne
|
||||
dol_syslog("User::create_from_contact - 0");
|
||||
dol_syslog(get_class($this)."::create_from_contact - 0");
|
||||
|
||||
$this->db->rollback();
|
||||
return $result;
|
||||
@ -937,7 +937,7 @@ class User extends CommonObject
|
||||
if ($member->fk_soc) $sql.= ", fk_societe=".$member->fk_soc;
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
dol_syslog("User::create_from_member sql=".$sql, LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::create_from_member sql=".$sql, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -947,7 +947,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("User::create_from_member - 1 - ".$this->error, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::create_from_member - 1 - ".$this->error, LOG_ERR);
|
||||
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
@ -956,7 +956,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
// $this->error deja positionne
|
||||
dol_syslog("User::create_from_member - 2 - ".$this->error, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error, LOG_ERR);
|
||||
|
||||
$this->db->rollback();
|
||||
return $result;
|
||||
@ -1022,7 +1022,7 @@ class User extends CommonObject
|
||||
$nbrowsaffected=0;
|
||||
$error=0;
|
||||
|
||||
dol_syslog("User::update notrigger=".$notrigger.", nosyncmember=".$nosyncmember.", nosyncmemberpass=".$nosyncmemberpass);
|
||||
dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncmember=".$nosyncmember.", nosyncmemberpass=".$nosyncmemberpass);
|
||||
|
||||
// Clean parameters
|
||||
$this->nom = trim($this->nom); // TODO deprecated
|
||||
@ -1035,7 +1035,7 @@ class User extends CommonObject
|
||||
$this->office_fax = trim($this->office_fax);
|
||||
$this->user_mobile = trim($this->user_mobile);
|
||||
$this->email = trim($this->email);
|
||||
$this->signature = trim($this->signature);
|
||||
$this->signature = trim($this->signature);
|
||||
$this->note = trim($this->note);
|
||||
$this->openid = trim(empty($this->openid)?'':$this->openid); // Avoid warning
|
||||
$this->webcal_login = trim($this->webcal_login);
|
||||
@ -1066,7 +1066,7 @@ class User extends CommonObject
|
||||
$sql.= ", office_fax = '".$this->db->escape($this->office_fax)."'";
|
||||
$sql.= ", user_mobile = '".$this->db->escape($this->user_mobile)."'";
|
||||
$sql.= ", email = '".$this->db->escape($this->email)."'";
|
||||
$sql.= ", signature = '".addslashes($this->signature)."'";
|
||||
$sql.= ", signature = '".addslashes($this->signature)."'";
|
||||
$sql.= ", webcal_login = '".$this->db->escape($this->webcal_login)."'";
|
||||
$sql.= ", phenix_login = '".$this->db->escape($this->phenix_login)."'";
|
||||
$sql.= ", phenix_pass = '".$this->db->escape($this->phenix_pass)."'";
|
||||
@ -1076,7 +1076,7 @@ class User extends CommonObject
|
||||
$sql.= ", entity = '".$this->entity."'";
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog("User::update sql=".$sql, LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -1097,13 +1097,13 @@ class User extends CommonObject
|
||||
if ($this->fk_member > 0)
|
||||
{
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL where fk_member = ".$this->fk_member;
|
||||
dol_syslog("User::update sql=".$sql, LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; }
|
||||
}
|
||||
// Set link to user
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member =".($this->fk_member>0?$this->fk_member:'null')." where rowid = ".$this->id;
|
||||
dol_syslog("User::update sql=".$sql, LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; }
|
||||
|
||||
@ -1141,7 +1141,7 @@ class User extends CommonObject
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error=$luser->error;
|
||||
dol_syslog("User::update ".$this->error,LOG_ERR);
|
||||
dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
@ -1202,7 +1202,7 @@ class User extends CommonObject
|
||||
$sql.= " tms = tms"; // La date de derniere modif doit changer sauf pour la mise a jour de date de derniere connexion
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog("Update last login date for user->id=".$this->id." ".$sql, LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::update_last_login_date user->id=".$this->id." ".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -1212,7 +1212,7 @@ class User extends CommonObject
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error().' sql='.$sql;
|
||||
$this->error=$this->db->lasterror().' sql='.$sql;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -1235,12 +1235,12 @@ class User extends CommonObject
|
||||
|
||||
$error=0;
|
||||
|
||||
dol_syslog("User::setPassword user=".$user->id." password=".preg_replace('/./i','*',$password)." changelater=".$changelater." notrigger=".$notrigger." nosyncmember=".$nosyncmember, LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i','*',$password)." changelater=".$changelater." notrigger=".$notrigger." nosyncmember=".$nosyncmember, LOG_DEBUG);
|
||||
|
||||
// If new password not provided, we generate one
|
||||
// If new password not provided, we generate one
|
||||
if (! $password)
|
||||
{
|
||||
$password=getRandomPassword('');
|
||||
$password=getRandomPassword('');
|
||||
}
|
||||
|
||||
// Crypte avec md5
|
||||
@ -1262,7 +1262,7 @@ class User extends CommonObject
|
||||
}
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog("User::setPassword sql=hidden", LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::setPassword sql=hidden", LOG_DEBUG);
|
||||
//dol_syslog("User::Password sql=".$sql);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
@ -1288,7 +1288,7 @@ class User extends CommonObject
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error=$adh->error;
|
||||
dol_syslog("User::setPassword ".$this->error,LOG_ERR);
|
||||
dol_syslog(get_class($this)."::setPassword ".$this->error,LOG_ERR);
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
@ -1299,7 +1299,7 @@ class User extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
dol_syslog("User::setPassword notrigger=".$notrigger." error=".$error,LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::setPassword notrigger=".$notrigger." error=".$error,LOG_DEBUG);
|
||||
|
||||
if (! $error && ! $notrigger)
|
||||
{
|
||||
@ -1332,7 +1332,7 @@ class User extends CommonObject
|
||||
$sql.= " SET pass_temp = '".$this->db->escape($password)."'";
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog("User::setPassword sql=hidden", LOG_DEBUG); // No log
|
||||
dol_syslog(get_class($this)."::setPassword sql=hidden", LOG_DEBUG); // No log
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
@ -1416,17 +1416,17 @@ class User extends CommonObject
|
||||
dol_syslog("User::send_password url=".$url);
|
||||
}
|
||||
$mailfile = new CMailFile(
|
||||
$subject,
|
||||
$this->email,
|
||||
$conf->notification->email_from,
|
||||
$mesg,
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
$subject,
|
||||
$this->email,
|
||||
$conf->notification->email_from,
|
||||
$mesg,
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
$msgishtml
|
||||
0,
|
||||
$msgishtml
|
||||
);
|
||||
|
||||
if ($mailfile->sendfile())
|
||||
@ -1435,7 +1435,7 @@ class User extends CommonObject
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->trans("errors");
|
||||
$langs->trans("errors");
|
||||
$this->error=$langs->trans("ErrorFailedToSendPassword").' '.$mailfile->error;
|
||||
return -1;
|
||||
}
|
||||
@ -1494,7 +1494,7 @@ class User extends CommonObject
|
||||
*/
|
||||
function update_clicktodial()
|
||||
{
|
||||
$this->db->begin();
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_clicktodial";
|
||||
$sql .= " WHERE fk_user = ".$this->id;
|
||||
@ -1512,14 +1512,14 @@ class User extends CommonObject
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 0;
|
||||
$this->db->commit();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
$this->db->rollback();
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1536,7 +1536,7 @@ class User extends CommonObject
|
||||
{
|
||||
global $conf, $langs, $user;
|
||||
|
||||
$error=0;
|
||||
$error=0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
@ -1571,7 +1571,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$interface->error;
|
||||
dol_syslog("User::SetInGroup ".$this->error, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::SetInGroup ".$this->error, LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
@ -1579,7 +1579,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("User::SetInGroup ".$this->error, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::SetInGroup ".$this->error, LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
@ -1588,20 +1588,20 @@ class User extends CommonObject
|
||||
/**
|
||||
* Remove a user from a group
|
||||
*
|
||||
* @param Group $group Id of group
|
||||
* @param int $entity Entity
|
||||
* @param int $notrigger Disable triggers
|
||||
* @return int <0 if KO, >0 if OK
|
||||
* @param Group $group Id of group
|
||||
* @param int $entity Entity
|
||||
* @param int $notrigger Disable triggers
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function RemoveFromGroup($group, $entity, $notrigger=0)
|
||||
{
|
||||
global $conf,$langs,$user;
|
||||
|
||||
$error=0;
|
||||
$error=0;
|
||||
|
||||
$this->db->begin();
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user";
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user";
|
||||
$sql.= " WHERE fk_user = ".$this->id;
|
||||
$sql.= " AND fk_usergroup = ".$group;
|
||||
$sql.= " AND entity = ".$entity;
|
||||
@ -1627,7 +1627,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$interface->error;
|
||||
dol_syslog("User::RemoveFromGroup ".$this->error, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::RemoveFromGroup ".$this->error, LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
@ -1635,7 +1635,7 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("User::RemoveFromGroup ".$this->error, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::RemoveFromGroup ".$this->error, LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
@ -1665,7 +1665,7 @@ class User extends CommonObject
|
||||
}
|
||||
|
||||
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowUser"),'user').$lienfin);
|
||||
if ($withpicto && $withpicto != 2) $result.=' ';
|
||||
if ($withpicto && $withpicto != 2) $result.=' ';
|
||||
$result.=$lien.$this->getFullName($langs).$lienfin;
|
||||
return $result;
|
||||
}
|
||||
@ -1885,11 +1885,11 @@ class User extends CommonObject
|
||||
|
||||
|
||||
/**
|
||||
* Initialise an instance with random values.
|
||||
* Used to build previews or test instances.
|
||||
* id must be 0 if object instance is a specimen.
|
||||
*
|
||||
* @return void
|
||||
* Initialise an instance with random values.
|
||||
* Used to build previews or test instances.
|
||||
* id must be 0 if object instance is a specimen.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function initAsSpecimen()
|
||||
{
|
||||
@ -2005,8 +2005,8 @@ class User extends CommonObject
|
||||
else
|
||||
{
|
||||
if ($all) $sql.= " WHERE entity = is not null";
|
||||
else $sql.= " WHERE entity = ".$conf->entity;
|
||||
if ($limitTo == 'active') $sql.= " AND statut = 1";
|
||||
else $sql.= " WHERE entity = ".$conf->entity;
|
||||
if ($limitTo == 'active') $sql.= " AND statut = 1";
|
||||
}
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
|
||||
@ -82,10 +82,9 @@ if ($action == 'validatenewpassword' && $username && $passwordmd5)
|
||||
// Action modif mot de passe
|
||||
if ($action == 'buildnewpassword' && $username)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/artichow/Artichow.cfg.php';
|
||||
require_once ARTICHOW."/AntiSpam.class.php";
|
||||
require_once(ARTICHOW_PATH.'Artichow.cfg.php');
|
||||
require_once(ARTICHOW.'/AntiSpam.class.php');
|
||||
|
||||
// We create anti-spam object
|
||||
$object = new AntiSpam();
|
||||
|
||||
// Verify code
|
||||
|
||||
@ -39,13 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DoliDb
|
||||
* @xcovers Translate
|
||||
* @xcovers Conf
|
||||
* @xcovers Interfaces
|
||||
* @xcovers CommonObject
|
||||
* @xcovers Adherent
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -63,40 +63,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DoliDb
|
||||
* @xcovers User
|
||||
* @xcovers Translate
|
||||
* @xcovers Conf
|
||||
* @xcovers CommonObject
|
||||
* @xcovers Facture
|
||||
* @xcovers Commande
|
||||
* @xcovers Propal
|
||||
* @xcovers Expedition
|
||||
* @xcovers Fichinter
|
||||
* @xcovers Project
|
||||
*
|
||||
* @xcovers ModelePDFFactures
|
||||
* @xcovers pdf_crabe
|
||||
* @xcovers pdf_oursin
|
||||
*
|
||||
* @xcovers ModelePDFCommandes
|
||||
* @xcovers pdf_edison
|
||||
* @xcovers pdf_einstein
|
||||
*
|
||||
* @xcovers ModelePDFPropales
|
||||
* @xcovers pdf_propale_azur
|
||||
* @xcovers pdf_propale_jaune
|
||||
*
|
||||
* @xcovers ModelePDFProjects
|
||||
* @xcovers pdf_baleine
|
||||
*
|
||||
* @xcovers ModelePDFFicheinter
|
||||
* @xcovers pdf_soleil
|
||||
*
|
||||
* @xcovers ModelePDFExpedition
|
||||
* @xcovers pdf_expedition_merou
|
||||
* @xcovers pdf_expedition_rouget
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -39,13 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DoliDb
|
||||
* @xcovers Translate
|
||||
* @xcovers Conf
|
||||
* @xcovers Interfaces
|
||||
* @xcovers CommonObject
|
||||
* @xcovers Adherent
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -39,13 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DoliDb
|
||||
* @xcovers Translate
|
||||
* @xcovers Conf
|
||||
* @xcovers Interfaces
|
||||
* @xcovers CommonObject
|
||||
* @xcovers Categorie
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -39,13 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DoliDb
|
||||
* @xcovers Translate
|
||||
* @xcovers Conf
|
||||
* @xcovers Interfaces
|
||||
* @xcovers CommonObject
|
||||
* @xcovers ChargeSociales
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -40,9 +40,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers CommandeFournisseur
|
||||
* @xcovers CommandeFournisseurLigne
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -39,9 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers Commande
|
||||
* @xcovers OrderLine
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -40,12 +40,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DoliDb
|
||||
* @xcovers User
|
||||
* @xcovers Translate
|
||||
* @xcovers Conf
|
||||
* @xcovers CommonObject
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -39,8 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers CompanyBankAccount
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -39,14 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DoliDb
|
||||
* @xcovers Translate
|
||||
* @xcovers Conf
|
||||
* @xcovers Interfaces
|
||||
* @xcovers CommonObject
|
||||
* @xcovers Contrat
|
||||
* @xcovers ContratLigne
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -39,7 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
* When not cover is provided. We use everything.
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -39,6 +39,8 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
|
||||
|
||||
@ -42,7 +42,7 @@ if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is
|
||||
|
||||
|
||||
/**
|
||||
* When no cover is provided. We use everything.
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
@ -140,7 +140,7 @@ class ExportTest extends PHPUnit_Framework_TestCase
|
||||
$objexport->array_export_alias[0]=$array_alias;
|
||||
|
||||
dol_mkdir($conf->export->dir_temp);
|
||||
|
||||
|
||||
$model='csv';
|
||||
|
||||
// Build export file
|
||||
@ -178,7 +178,7 @@ class ExportTest extends PHPUnit_Framework_TestCase
|
||||
$datatoexport='societe_1';
|
||||
$array_selected = array("s.rowid"=>1, "s.nom"=>2); // Mut be fields found into declaration of dataset
|
||||
$model='csv';
|
||||
|
||||
|
||||
$objexport=new Export($db);
|
||||
$result=$objexport->load_arrays($user,$datatoexport);
|
||||
|
||||
|
||||
@ -39,14 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DoliDb
|
||||
* @xcovers User
|
||||
* @xcovers Translate
|
||||
* @xcovers Conf
|
||||
* @xcovers Interfaces
|
||||
* @xcovers CommonObject
|
||||
* @xcovers FactureFournisseur
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -39,23 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DoliDb
|
||||
* @xcovers User
|
||||
* @xcovers Translate
|
||||
* @xcovers Conf
|
||||
* @xcovers Interfaces
|
||||
* @xcovers CommonObject
|
||||
* @xcovers Facture
|
||||
* @xcovers FactureLigne
|
||||
* @xcovers ModeleNumRefFactures
|
||||
* @xcovers InterfaceLogevents
|
||||
* @xcovers InterfaceActionsAuto
|
||||
* @xcovers InterfaceLdapsynchro
|
||||
* @xcovers InterfaceNotification
|
||||
* @xcovers InterfacePhenixsynchro
|
||||
* @xcovers InterfacePropalWorkflow
|
||||
* @xcovers InterfaceWebcalsynchro
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -41,6 +41,7 @@ if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is
|
||||
|
||||
|
||||
/**
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -41,7 +41,7 @@ if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is
|
||||
|
||||
|
||||
/**
|
||||
* When no cover is provided. We use everything.
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -38,55 +38,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DolibarrModules
|
||||
* @xcovers modAccounting
|
||||
* @xcovers modAdherent
|
||||
* @xcovers modAgenda
|
||||
* @xcovers modBanque
|
||||
* @xcovers modBarcode
|
||||
* @xcovers modBookmark
|
||||
* @xcovers modBoutique
|
||||
* @xcovers modCashDesk
|
||||
* @xcovers modCategorie
|
||||
* @xcovers modClickToDial
|
||||
* @xcovers modCommande
|
||||
* @xcovers modComptabilite
|
||||
* @xcovers modContrat
|
||||
* @xcovers modDeplacement
|
||||
* @xcovers modDocument
|
||||
* @xcovers modDon
|
||||
* @xcovers modECM
|
||||
* @xcovers modExpedition
|
||||
* @xcovers modExport
|
||||
* @xcovers modExternalRss
|
||||
* @xcovers modExternalSite
|
||||
* @cxovers modFacture
|
||||
* @xcovers modFckeditor
|
||||
* @xcovers modFicheinter
|
||||
* @xcovers modFournisseur
|
||||
* @xcovers modFTP
|
||||
* @xcovers modGeoIPMaxmind
|
||||
* @xcovers modGravatar
|
||||
* @xcovers modImport
|
||||
* @xcovers modLabel
|
||||
* @xcovers modLdap
|
||||
* @xcovers modMailing
|
||||
* @xcovers modMantis
|
||||
* @xcovers modNotification
|
||||
* @xcovers modPaybox
|
||||
* @xcovers modPaypal
|
||||
* @xcovers modPrelevement
|
||||
* @xcovers modProduct
|
||||
* @xcovers modProjet
|
||||
* @xcovers modPropale
|
||||
* @xcovers modService
|
||||
* @xcovers modSociete
|
||||
* @xcovers modStock
|
||||
* @xcovers modSyslog
|
||||
* @xcovers modTax
|
||||
* @xcovers modUser
|
||||
* @xcovers modWebServices
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -39,9 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers Propal
|
||||
* @xcovers PropaleLigne
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -28,6 +28,7 @@ global $conf,$user,$langs,$db;
|
||||
require_once 'PHPUnit/Autoload.php';
|
||||
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
|
||||
require_once dirname(__FILE__).'/../../htdocs/lib/functions.lib.php';
|
||||
require_once dirname(__FILE__).'/../../htdocs/lib/security.lib.php';
|
||||
|
||||
if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
|
||||
if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
|
||||
@ -42,13 +43,7 @@ if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DoliDb
|
||||
* @xcovers Translate
|
||||
* @xcovers Conf
|
||||
* @xcovers Interfaces
|
||||
* @xcovers CommonObject
|
||||
* @xcovers Adherent
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
@ -109,6 +104,7 @@ class SecurityTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
protected function tearDown()
|
||||
@ -155,6 +151,31 @@ class SecurityTest extends PHPUnit_Framework_TestCase
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testCheckLoginPassEntity()
|
||||
{
|
||||
$login=checkLoginPassEntity('loginbidon','passwordbidon',1,array('dolibarr'));
|
||||
print __METHOD__." login=".$login."\n";
|
||||
$this->assertEquals($login,'');
|
||||
|
||||
$login=checkLoginPassEntity('admin','passwordbidon',1,array('dolibarr'));
|
||||
print __METHOD__." login=".$login."\n";
|
||||
$this->assertEquals($login,'');
|
||||
|
||||
$login=checkLoginPassEntity('admin','admin',1,array('dolibarr')); // Should works because admin/admin exists
|
||||
print __METHOD__." login=".$login."\n";
|
||||
$this->assertEquals($login,'admin');
|
||||
|
||||
$login=checkLoginPassEntity('admin','admin',1,array('http','dolibarr')); // Should work because of second authetntication method
|
||||
print __METHOD__." login=".$login."\n";
|
||||
$this->assertEquals($login,'admin');
|
||||
|
||||
$login=checkLoginPassEntity('admin','admin',1,array('forceuser'));
|
||||
print __METHOD__." login=".$login."\n";
|
||||
$this->assertEquals($login,''); // Expected '' because should failed because login 'auto' does not exists
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
/* public function testAnalyseSqlAndScript()
|
||||
|
||||
@ -39,10 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DoliDb
|
||||
* @xcovers Conf
|
||||
* @xcovers Societe
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -39,13 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DoliDb
|
||||
* @xcovers Translate
|
||||
* @xcovers Conf
|
||||
* @xcovers Interfaces
|
||||
* @xcovers CommonObject
|
||||
* @xcovers UserGroup
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -39,13 +39,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @xcovers DoliDb
|
||||
* @xcovers Translate
|
||||
* @xcovers Conf
|
||||
* @xcovers Interfaces
|
||||
* @xcovers CommonObject
|
||||
* @xcovers User
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file test/phpunit/DateLibTest.php
|
||||
* \file test/phpunit/WebservicesTest.php
|
||||
* \ingroup test
|
||||
* \brief PHPUnit test
|
||||
* \remarks To run this script as CLI: phpunit filename.php
|
||||
@ -41,7 +41,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
|
||||
/**
|
||||
* When no cover is provided. We use everything.
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
|
||||
Loading…
Reference in New Issue
Block a user