Work on module template
This commit is contained in:
parent
66420d0e80
commit
111087dfdc
@ -24,20 +24,22 @@
|
|||||||
|
|
||||||
// $massaction must be defined
|
// $massaction must be defined
|
||||||
// $objectclass and $$objectlabel must be defined
|
// $objectclass and $$objectlabel must be defined
|
||||||
// $uploaddir (example $conf->projet->dir_output . "/";)
|
// $parameters, $object, $action must be defined for the hook.
|
||||||
|
|
||||||
|
// $uploaddir may be defined (example to $conf->projet->dir_output."/";)
|
||||||
// $toselect may be defined
|
// $toselect may be defined
|
||||||
|
|
||||||
|
|
||||||
// Protection
|
// Protection
|
||||||
if (empty($objectclass) || empty($uploaddir))
|
if (empty($objectclass) || empty($uploaddir))
|
||||||
{
|
{
|
||||||
dol_print_error(null, 'include of actions_massactions.inc.php is done but var $massaction or $objectclass or $uploaddir was not defined');
|
dol_print_error(null, 'include of actions_massactions.inc.php is done but var $massaction or $objectclass or $uploaddir was not defined');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Mass actions. Controls on number of lines checked
|
// Mass actions. Controls on number of lines checked.
|
||||||
$maxformassaction=1000;
|
$maxformassaction=(empty($conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS)?1000:$conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS);
|
||||||
if (! empty($massaction) && count($toselect) < 1)
|
if (! empty($massaction) && count($toselect) < 1)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
@ -87,7 +89,7 @@ if (! $error && $massaction == 'confirm_presend')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//var_dump($listofobjectthirdparties);exit;
|
//var_dump($listofobjectthirdparties);exit;
|
||||||
|
|
||||||
foreach ($listofobjectthirdparties as $thirdpartyid)
|
foreach ($listofobjectthirdparties as $thirdpartyid)
|
||||||
{
|
{
|
||||||
$result = $thirdparty->fetch($thirdpartyid);
|
$result = $thirdparty->fetch($thirdpartyid);
|
||||||
@ -144,7 +146,7 @@ if (! $error && $massaction == 'confirm_presend')
|
|||||||
{
|
{
|
||||||
//var_dump($object);
|
//var_dump($object);
|
||||||
//var_dump($thirdpartyid.' - '.$objectid.' - '.$object->statut);
|
//var_dump($thirdpartyid.' - '.$objectid.' - '.$object->statut);
|
||||||
|
|
||||||
if ($objectclass == 'Facture' && $object->statut != Facture::STATUS_VALIDATED)
|
if ($objectclass == 'Facture' && $object->statut != Facture::STATUS_VALIDATED)
|
||||||
{
|
{
|
||||||
$nbignored++;
|
$nbignored++;
|
||||||
@ -157,7 +159,7 @@ if (! $error && $massaction == 'confirm_presend')
|
|||||||
$resaction.='<div class="error">'.$langs->trans('ErrorOnlyOrderNotDraftCanBeSentInMassAction',$object->ref).'</div><br>';
|
$resaction.='<div class="error">'.$langs->trans('ErrorOnlyOrderNotDraftCanBeSentInMassAction',$object->ref).'</div><br>';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read document
|
// Read document
|
||||||
// TODO Use future field $object->fullpathdoc to know where is stored default file
|
// TODO Use future field $object->fullpathdoc to know where is stored default file
|
||||||
// TODO If not defined, use $object->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc.
|
// TODO If not defined, use $object->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc.
|
||||||
@ -202,7 +204,7 @@ if (! $error && $massaction == 'confirm_presend')
|
|||||||
dol_syslog('Failed to read file: '.$file, LOG_WARNING);
|
dol_syslog('Failed to read file: '.$file, LOG_WARNING);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//var_dump($listofqualifiedref);
|
//var_dump($listofqualifiedref);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,9 +254,9 @@ if (! $error && $massaction == 'confirm_presend')
|
|||||||
$filepath = $attachedfiles['paths'];
|
$filepath = $attachedfiles['paths'];
|
||||||
$filename = $attachedfiles['names'];
|
$filename = $attachedfiles['names'];
|
||||||
$mimetype = $attachedfiles['mimes'];
|
$mimetype = $attachedfiles['mimes'];
|
||||||
|
|
||||||
//var_dump($filepath);
|
//var_dump($filepath);
|
||||||
|
|
||||||
// Send mail
|
// Send mail
|
||||||
require_once(DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php');
|
require_once(DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php');
|
||||||
$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1);
|
$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1);
|
||||||
@ -280,7 +282,7 @@ if (! $error && $massaction == 'confirm_presend')
|
|||||||
if ($objectclass == 'Supplier_Proposal') $actiontypecode='AC_SUP_PRO';
|
if ($objectclass == 'Supplier_Proposal') $actiontypecode='AC_SUP_PRO';
|
||||||
if ($objectclass == 'CommandeFournisseur') $actiontypecode='AC_SUP_ORD';
|
if ($objectclass == 'CommandeFournisseur') $actiontypecode='AC_SUP_ORD';
|
||||||
if ($objectclass == 'FactureFournisseur') $actiontypecode='AC_SUP_INV';*/
|
if ($objectclass == 'FactureFournisseur') $actiontypecode='AC_SUP_INV';*/
|
||||||
|
|
||||||
$actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
|
$actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
|
||||||
if ($message)
|
if ($message)
|
||||||
{
|
{
|
||||||
@ -290,7 +292,7 @@ if (! $error && $massaction == 'confirm_presend')
|
|||||||
$actionmsg = dol_concatdesc($actionmsg, $message);
|
$actionmsg = dol_concatdesc($actionmsg, $message);
|
||||||
}
|
}
|
||||||
$actionmsg2='';
|
$actionmsg2='';
|
||||||
|
|
||||||
// Initialisation donnees
|
// Initialisation donnees
|
||||||
$object->sendtoid = 0;
|
$object->sendtoid = 0;
|
||||||
$object->actionmsg = $actionmsg; // Long text
|
$object->actionmsg = $actionmsg; // Long text
|
||||||
@ -335,7 +337,7 @@ if (! $error && $massaction == 'confirm_presend')
|
|||||||
$resaction.=$langs->trans("NbSelected").': '.count($toselect)."\n<br>";
|
$resaction.=$langs->trans("NbSelected").': '.count($toselect)."\n<br>";
|
||||||
$resaction.=$langs->trans("NbIgnored").': '.($nbignored?$nbignored:0)."\n<br>";
|
$resaction.=$langs->trans("NbIgnored").': '.($nbignored?$nbignored:0)."\n<br>";
|
||||||
$resaction.=$langs->trans("NbSent").': '.($nbsent?$nbsent:0)."\n<br>";
|
$resaction.=$langs->trans("NbSent").': '.($nbsent?$nbsent:0)."\n<br>";
|
||||||
|
|
||||||
if ($nbsent)
|
if ($nbsent)
|
||||||
{
|
{
|
||||||
$action=''; // Do not show form post if there was at least one successfull sent
|
$action=''; // Do not show form post if there was at least one successfull sent
|
||||||
@ -359,7 +361,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se
|
|||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||||
|
|
||||||
$objecttmp=new $objectclass($db);
|
$objecttmp=new $objectclass($db);
|
||||||
$listofobjectid=array();
|
$listofobjectid=array();
|
||||||
$listofobjectthirdparties=array();
|
$listofobjectthirdparties=array();
|
||||||
@ -425,21 +427,21 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se
|
|||||||
|
|
||||||
if (count($files)>0)
|
if (count($files)>0)
|
||||||
{
|
{
|
||||||
|
|
||||||
$now=dol_now();
|
$now=dol_now();
|
||||||
$file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf';
|
$file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf';
|
||||||
|
|
||||||
$input_files = '';
|
$input_files = '';
|
||||||
foreach($files as $f) {
|
foreach($files as $f) {
|
||||||
$input_files.=' '.escapeshellarg($f);
|
$input_files.=' '.escapeshellarg($f);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cmd = 'pdftk '.$input_files.' cat output '.escapeshellarg($file);
|
$cmd = 'pdftk '.$input_files.' cat output '.escapeshellarg($file);
|
||||||
exec($cmd);
|
exec($cmd);
|
||||||
|
|
||||||
if (! empty($conf->global->MAIN_UMASK))
|
if (! empty($conf->global->MAIN_UMASK))
|
||||||
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
||||||
|
|
||||||
$langs->load("exports");
|
$langs->load("exports");
|
||||||
setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs');
|
setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs');
|
||||||
}
|
}
|
||||||
@ -447,7 +449,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se
|
|||||||
{
|
{
|
||||||
setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors');
|
setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Create empty PDF
|
// Create empty PDF
|
||||||
@ -481,7 +483,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se
|
|||||||
// Defined name of merged file
|
// Defined name of merged file
|
||||||
$filename=strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
|
$filename=strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
|
||||||
$filename=preg_replace('/\s/','_',$filename);
|
$filename=preg_replace('/\s/','_',$filename);
|
||||||
|
|
||||||
// Save merged file
|
// Save merged file
|
||||||
if ($filter=='paye:0')
|
if ($filter=='paye:0')
|
||||||
{
|
{
|
||||||
@ -565,6 +567,11 @@ if (! $error && $massaction == 'delete' && $permtodelete)
|
|||||||
//var_dump($listofobjectthirdparties);exit;
|
//var_dump($listofobjectthirdparties);exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$parameters['toselect']=$toselect;
|
||||||
|
$parameters['uploaddir']=$uploaddir;
|
||||||
|
|
||||||
|
$reshook=$hookmanager->executeHooks('doMassActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
|
||||||
|
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -140,6 +140,7 @@ class HookManager
|
|||||||
'addStatisticLine',
|
'addStatisticLine',
|
||||||
'deleteFile',
|
'deleteFile',
|
||||||
'doActions',
|
'doActions',
|
||||||
|
'doMassActions',
|
||||||
'formCreateThirdpartyOptions',
|
'formCreateThirdpartyOptions',
|
||||||
'formObjectOptions',
|
'formObjectOptions',
|
||||||
'formattachOptions',
|
'formattachOptions',
|
||||||
|
|||||||
@ -546,7 +546,7 @@ class Form
|
|||||||
$ret='<div class="centpercent center">';
|
$ret='<div class="centpercent center">';
|
||||||
$ret.='<select data-role="none" class="flat'.(empty($conf->use_javascript_ajax)?'':' hideobject').' massaction massactionselect" name="massaction"'.($disabled?' disabled="disabled"':'').'>';
|
$ret.='<select data-role="none" class="flat'.(empty($conf->use_javascript_ajax)?'':' hideobject').' massaction massactionselect" name="massaction"'.($disabled?' disabled="disabled"':'').'>';
|
||||||
|
|
||||||
// Complete list with data from external modules. THe module can use $_SERVER['PHP_SELF'] to know on which page we are, or use the $parameters['context'] completed by executeHooks.
|
// Complete list with data from external modules. THe module can use $_SERVER['PHP_SELF'] to know on which page we are, or use the $parameters['currentcontext'] completed by executeHooks.
|
||||||
$parameters=array();
|
$parameters=array();
|
||||||
$reshook=$hookmanager->executeHooks('addMoreMassActions',$parameters); // Note that $action and $object may have been modified by hook
|
$reshook=$hookmanager->executeHooks('addMoreMassActions',$parameters); // Note that $action and $object may have been modified by hook
|
||||||
if (empty($reshook))
|
if (empty($reshook))
|
||||||
|
|||||||
@ -62,24 +62,101 @@ class ActionsMyModule
|
|||||||
*/
|
*/
|
||||||
public function doActions($parameters, &$object, &$action, $hookmanager)
|
public function doActions($parameters, &$object, &$action, $hookmanager)
|
||||||
{
|
{
|
||||||
|
global $conf, $user, $langs;
|
||||||
|
|
||||||
$error = 0; // Error counter
|
$error = 0; // Error counter
|
||||||
$myvalue = 'test'; // A result value
|
|
||||||
|
|
||||||
|
/*
|
||||||
print_r($parameters);
|
print_r($parameters);
|
||||||
echo "action: " . $action;
|
|
||||||
print_r($object);
|
print_r($object);
|
||||||
|
echo "action: " . $action;
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
|
||||||
|
|
||||||
|
|
||||||
if (in_array('somecontext', explode(':', $parameters['context']))) {
|
|
||||||
// do something only for the context 'somecontext'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error) {
|
if (! $error) {
|
||||||
$this->results = array('myreturn' => $myvalue);
|
$this->results = array('myreturn' => 999);
|
||||||
$this->resprints = 'A text to show';
|
$this->resprints = 'A text to show';
|
||||||
return 0; // or return 1 to replace standard code
|
return 0; // or return 1 to replace standard code
|
||||||
} else {
|
} else {
|
||||||
$this->errors[] = 'Error message';
|
$this->errors[] = 'Error message';
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overloading the doActions function : replacing the parent's function with the one below
|
||||||
|
*
|
||||||
|
* @param array() $parameters Hook metadatas (context, etc...)
|
||||||
|
* @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
|
||||||
|
* @param string $action Current action (if set). Generally create or edit or null
|
||||||
|
* @param HookManager $hookmanager Hook manager propagated to allow calling another hook
|
||||||
|
* @return int < 0 on error, 0 on success, 1 to replace standard code
|
||||||
|
*/
|
||||||
|
public function doMassActions($parameters, &$object, &$action, $hookmanager)
|
||||||
|
{
|
||||||
|
global $conf, $user, $langs;
|
||||||
|
|
||||||
|
$error = 0; // Error counter
|
||||||
|
|
||||||
|
/*
|
||||||
|
print_r($parameters);
|
||||||
|
print_r($object);
|
||||||
|
echo "action: " . $action;
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
|
||||||
|
|
||||||
|
foreach($parameters['toselect'] as $objectid)
|
||||||
|
{
|
||||||
|
// Do action on each object id
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error) {
|
||||||
|
$this->results = array('myreturn' => 999);
|
||||||
|
$this->resprints = 'A text to show';
|
||||||
|
return 0; // or return 1 to replace standard code
|
||||||
|
} else {
|
||||||
|
$this->errors[] = 'Error message';
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overloading the addMoreMassActions function : replacing the parent's function with the one below
|
||||||
|
*
|
||||||
|
* @param array() $parameters Hook metadatas (context, etc...)
|
||||||
|
* @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
|
||||||
|
* @param string $action Current action (if set). Generally create or edit or null
|
||||||
|
* @param HookManager $hookmanager Hook manager propagated to allow calling another hook
|
||||||
|
* @return int < 0 on error, 0 on success, 1 to replace standard code
|
||||||
|
*/
|
||||||
|
public function addMoreMassActions($parameters, &$object, &$action, $hookmanager)
|
||||||
|
{
|
||||||
|
global $conf, $user, $langs;
|
||||||
|
|
||||||
|
$error = 0; // Error counter
|
||||||
|
|
||||||
|
if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) // do something only for the context 'somecontext'
|
||||||
|
{
|
||||||
|
$this->resprints = '<option value="0"'.($disabled?' disabled="disabled"':'').'>'.$langs->trans("MyModuleMassAction").'</option>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error) {
|
||||||
|
return 0; // or return 1 to replace standard code
|
||||||
|
} else {
|
||||||
|
$this->errors[] = 'Error message';
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user