2004-10-20 23:06:45 +02:00
< ? php
2003-09-12 12:56:39 +02:00
/* Copyright ( C ) 2002 - 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2005-04-09 15:33:39 +02:00
* Copyright ( C ) 2004 - 2005 Laurent Destailleur < eldy @ users . sourceforge . net >
2003-09-12 12:56:39 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2003-09-12 12:56:39 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-08-03 02:45:22 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2003-09-12 12:56:39 +02:00
*/
2005-04-09 15:33:39 +02:00
/**
2010-06-05 17:32:18 +02:00
* \file htdocs / comm / action / class / cactioncomm . class . php
2012-10-03 00:39:34 +02:00
* \ingroup agenda
2010-10-28 00:41:40 +02:00
* \brief File of class to manage type of agenda events
2011-08-27 17:14:31 +02:00
*/
2004-11-03 21:25:29 +01:00
2010-06-05 17:32:18 +02:00
/**
2012-10-03 00:39:34 +02:00
* Class to manage different types of events
2009-07-30 01:10:15 +02:00
*/
2011-09-12 19:08:02 +02:00
class CActionComm
{
var $error ;
var $db ;
2005-04-09 15:33:39 +02:00
2011-09-12 19:08:02 +02:00
var $id ;
2005-07-10 04:05:09 +02:00
2011-09-12 19:08:02 +02:00
var $code ;
var $type ;
var $libelle ;
var $active ;
2005-07-10 04:05:09 +02:00
2011-09-12 19:08:02 +02:00
var $type_actions = array ();
2009-07-30 01:10:15 +02:00
2011-09-12 19:08:02 +02:00
/**
* Constructor
*
2011-11-01 04:58:47 +01:00
* @ param DoliDB $db Database handler
2011-09-12 19:08:02 +02:00
*/
2012-07-30 17:17:33 +02:00
function __construct ( $db )
2003-09-12 12:56:39 +02:00
{
2011-11-01 04:58:47 +01:00
$this -> db = $db ;
2003-09-12 12:56:39 +02:00
}
2004-02-14 13:39:17 +01:00
2011-09-12 19:08:02 +02:00
/**
2011-09-22 01:28:01 +02:00
* Load action type from database
2011-09-12 19:08:02 +02:00
*
2011-09-22 01:28:01 +02:00
* @ param int $id id or code of action type to read
* @ return int 1 = ok , 0 = not found , - 1 = error
2011-09-12 19:08:02 +02:00
*/
function fetch ( $id )
2004-02-14 13:39:17 +01:00
{
2006-10-22 04:52:57 +02:00
$sql = " SELECT id, code, type, libelle, active " ;
2005-07-10 04:05:09 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_actioncomm " ;
2011-09-12 19:08:02 +02:00
if ( is_numeric ( $id )) $sql .= " WHERE id= " . $id ;
else $sql .= " WHERE code=' " . $id . " ' " ;
2009-07-30 01:10:15 +02:00
2011-09-22 01:28:01 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch sql= " . $sql );
2005-04-09 15:33:39 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
if ( $this -> db -> num_rows ( $resql ))
{
$obj = $this -> db -> fetch_object ( $resql );
2009-07-30 01:10:15 +02:00
2006-10-22 04:52:57 +02:00
$this -> id = $obj -> id ;
2005-07-10 04:05:09 +02:00
$this -> code = $obj -> code ;
$this -> type = $obj -> type ;
2005-04-09 15:33:39 +02:00
$this -> libelle = $obj -> libelle ;
2005-07-10 04:05:09 +02:00
$this -> active = $obj -> active ;
2009-07-30 01:10:15 +02:00
2013-11-07 20:38:06 +01:00
$this -> db -> free ( $resql );
2005-04-09 15:33:39 +02:00
return 1 ;
}
else
{
2013-11-07 20:38:06 +01:00
$this -> db -> free ( $resql );
2005-04-09 15:33:39 +02:00
return 0 ;
}
}
else
{
$this -> error = $this -> db -> error ();
return - 1 ;
}
2004-02-14 13:39:17 +01:00
}
2004-11-03 21:25:29 +01:00
2011-09-12 19:08:02 +02:00
/**
2012-09-20 00:42:51 +02:00
* Return list of event types
2011-09-12 19:08:02 +02:00
*
2012-09-20 00:42:51 +02:00
* @ param int $active 1 or 0 to filter on event state active or not ( '' by default = no filter )
* @ param string $idorcode 'id' or 'code'
* @ param string $excludetype Type to exclude
2012-12-01 15:45:05 +01:00
* @ param string $onlyautoornot Group list by auto events or not
2012-09-20 00:42:51 +02:00
* @ return array Array of all event types if OK , < 0 if KO
2011-09-12 19:08:02 +02:00
*/
2012-12-01 15:45:05 +01:00
function liste_array ( $active = '' , $idorcode = 'id' , $excludetype = '' , $onlyautoornot = 0 )
2011-09-12 19:08:02 +02:00
{
global $langs , $conf ;
$langs -> load ( " commercial " );
$repid = array ();
$repcode = array ();
2012-12-01 15:45:05 +01:00
$sql = " SELECT id, code, libelle, module, type " ;
2011-09-12 19:08:02 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_actioncomm " ;
2012-09-20 00:42:51 +02:00
if ( $active != '' ) $sql .= " WHERE active= " . $active ;
if ( ! empty ( $excludetype )) $sql .= ( $active != '' ? " AND " : " WHERE " ) . " type <> ' " . $excludetype . " ' " ;
2011-09-12 19:08:02 +02:00
$sql .= " ORDER BY module, position " ;
2011-09-22 01:28:01 +02:00
dol_syslog ( get_class ( $this ) . " ::liste_array sql= " . $sql );
2011-09-12 19:08:02 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$nump = $this -> db -> num_rows ( $resql );
if ( $nump )
{
$i = 0 ;
while ( $i < $nump )
{
$obj = $this -> db -> fetch_object ( $resql );
2012-12-01 15:45:05 +01:00
2011-09-12 19:08:02 +02:00
$qualified = 1 ;
2012-12-01 15:45:05 +01:00
// $obj->type can be system, systemauto, module, moduleauto, xxx, xxxauto
2013-04-21 12:26:44 +02:00
if ( $qualified && $onlyautoornot && preg_match ( '/^system/' , $obj -> type ) && ! preg_match ( '/^AC_OTH/' , $obj -> code )) $qualified = 0 ; // We discard detailed system events. We keep only the 2 generic lines (AC_OTH and AC_OTH_AUTO)
2012-12-01 15:45:05 +01:00
if ( $qualified && $obj -> module )
2011-09-12 19:08:02 +02:00
{
if ( $obj -> module == 'invoice' && ! $conf -> facture -> enabled ) $qualified = 0 ;
if ( $obj -> module == 'order' && ! $conf -> commande -> enabled ) $qualified = 0 ;
if ( $obj -> module == 'propal' && ! $conf -> propal -> enabled ) $qualified = 0 ;
2011-02-02 14:29:54 +01:00
if ( $obj -> module == 'invoice_supplier' && ! $conf -> fournisseur -> enabled ) $qualified = 0 ;
if ( $obj -> module == 'order_supplier' && ! $conf -> fournisseur -> enabled ) $qualified = 0 ;
2012-12-01 15:45:05 +01:00
if ( $obj -> module == 'shipping' && ! $conf -> expedition -> enabled ) $qualified = 0 ;
2011-09-12 19:08:02 +02:00
}
2012-12-01 15:45:05 +01:00
2011-09-12 19:08:02 +02:00
if ( $qualified )
{
2012-12-01 15:45:05 +01:00
$code = $obj -> code ;
if ( $onlyautoornot && $code == 'AC_OTH' ) $code = 'AC_MANUAL' ;
if ( $onlyautoornot && $code == 'AC_OTH_AUTO' ) $code = 'AC_AUTO' ;
$transcode = $langs -> trans ( " Action " . $code );
$repid [ $obj -> id ] = ( $transcode != " Action " . $code ? $transcode : $langs -> trans ( $obj -> libelle ));
$repcode [ $obj -> code ] = ( $transcode != " Action " . $code ? $transcode : $langs -> trans ( $obj -> libelle ));
if ( $onlyautoornot && preg_match ( '/^module/' , $obj -> type ) && $obj -> module ) $repcode [ $obj -> code ] .= ' (' . $langs -> trans ( " Module " ) . ': ' . $obj -> module . ')' ;
2011-09-12 19:08:02 +02:00
}
$i ++ ;
}
}
if ( $idorcode == 'id' ) $this -> liste_array = $repid ;
if ( $idorcode == 'code' ) $this -> liste_array = $repcode ;
return $this -> liste_array ;
}
else
{
$this -> error = $this -> db -> lasterror ();
return - 1 ;
}
}
/**
2011-09-22 01:28:01 +02:00
* Return name of action type as a label translated
2011-09-12 19:08:02 +02:00
*
2011-09-22 01:28:01 +02:00
* @ param int $withpicto 0 = No picto , 1 = Include picto into link , 2 = Picto only
* @ return string Label of action type
2011-09-12 19:08:02 +02:00
*/
function getNomUrl ( $withpicto = 0 )
{
global $langs ;
// Check if translation available
$transcode = $langs -> trans ( " Action " . $this -> code );
if ( $transcode != " Action " . $this -> code ) return $transcode ;
}
2005-04-09 15:33:39 +02:00
2009-07-30 01:10:15 +02:00
}
2003-09-12 12:56:39 +02:00
?>