Work on module template
This commit is contained in:
parent
66420d0e80
commit
111087dfdc
@ -24,20 +24,22 @@
|
||||
|
||||
// $massaction 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
|
||||
|
||||
|
||||
// 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');
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
// Mass actions. Controls on number of lines checked
|
||||
$maxformassaction=1000;
|
||||
// Mass actions. Controls on number of lines checked.
|
||||
$maxformassaction=(empty($conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS)?1000:$conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS);
|
||||
if (! empty($massaction) && count($toselect) < 1)
|
||||
{
|
||||
$error++;
|
||||
@ -87,7 +89,7 @@ if (! $error && $massaction == 'confirm_presend')
|
||||
}
|
||||
}
|
||||
//var_dump($listofobjectthirdparties);exit;
|
||||
|
||||
|
||||
foreach ($listofobjectthirdparties as $thirdpartyid)
|
||||
{
|
||||
$result = $thirdparty->fetch($thirdpartyid);
|
||||
@ -144,7 +146,7 @@ if (! $error && $massaction == 'confirm_presend')
|
||||
{
|
||||
//var_dump($object);
|
||||
//var_dump($thirdpartyid.' - '.$objectid.' - '.$object->statut);
|
||||
|
||||
|
||||
if ($objectclass == 'Facture' && $object->statut != Facture::STATUS_VALIDATED)
|
||||
{
|
||||
$nbignored++;
|
||||
@ -157,7 +159,7 @@ if (! $error && $massaction == 'confirm_presend')
|
||||
$resaction.='<div class="error">'.$langs->trans('ErrorOnlyOrderNotDraftCanBeSentInMassAction',$object->ref).'</div><br>';
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Read document
|
||||
// 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.
|
||||
@ -202,7 +204,7 @@ if (! $error && $massaction == 'confirm_presend')
|
||||
dol_syslog('Failed to read file: '.$file, LOG_WARNING);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
//var_dump($listofqualifiedref);
|
||||
}
|
||||
|
||||
@ -252,9 +254,9 @@ if (! $error && $massaction == 'confirm_presend')
|
||||
$filepath = $attachedfiles['paths'];
|
||||
$filename = $attachedfiles['names'];
|
||||
$mimetype = $attachedfiles['mimes'];
|
||||
|
||||
|
||||
//var_dump($filepath);
|
||||
|
||||
|
||||
// Send mail
|
||||
require_once(DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php');
|
||||
$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 == 'CommandeFournisseur') $actiontypecode='AC_SUP_ORD';
|
||||
if ($objectclass == 'FactureFournisseur') $actiontypecode='AC_SUP_INV';*/
|
||||
|
||||
|
||||
$actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
|
||||
if ($message)
|
||||
{
|
||||
@ -290,7 +292,7 @@ if (! $error && $massaction == 'confirm_presend')
|
||||
$actionmsg = dol_concatdesc($actionmsg, $message);
|
||||
}
|
||||
$actionmsg2='';
|
||||
|
||||
|
||||
// Initialisation donnees
|
||||
$object->sendtoid = 0;
|
||||
$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("NbIgnored").': '.($nbignored?$nbignored:0)."\n<br>";
|
||||
$resaction.=$langs->trans("NbSent").': '.($nbsent?$nbsent:0)."\n<br>";
|
||||
|
||||
|
||||
if ($nbsent)
|
||||
{
|
||||
$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/pdf.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
|
||||
|
||||
$objecttmp=new $objectclass($db);
|
||||
$listofobjectid=array();
|
||||
$listofobjectthirdparties=array();
|
||||
@ -425,21 +427,21 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se
|
||||
|
||||
if (count($files)>0)
|
||||
{
|
||||
|
||||
|
||||
$now=dol_now();
|
||||
$file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf';
|
||||
|
||||
|
||||
$input_files = '';
|
||||
foreach($files as $f) {
|
||||
$input_files.=' '.escapeshellarg($f);
|
||||
}
|
||||
|
||||
|
||||
$cmd = 'pdftk '.$input_files.' cat output '.escapeshellarg($file);
|
||||
exec($cmd);
|
||||
|
||||
|
||||
if (! empty($conf->global->MAIN_UMASK))
|
||||
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
||||
|
||||
|
||||
$langs->load("exports");
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
// Create empty PDF
|
||||
@ -481,7 +483,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se
|
||||
// Defined name of merged file
|
||||
$filename=strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
|
||||
$filename=preg_replace('/\s/','_',$filename);
|
||||
|
||||
|
||||
// Save merged file
|
||||
if ($filter=='paye:0')
|
||||
{
|
||||
@ -565,6 +567,11 @@ if (! $error && $massaction == 'delete' && $permtodelete)
|
||||
//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',
|
||||
'deleteFile',
|
||||
'doActions',
|
||||
'doMassActions',
|
||||
'formCreateThirdpartyOptions',
|
||||
'formObjectOptions',
|
||||
'formattachOptions',
|
||||
|
||||
@ -546,7 +546,7 @@ class Form
|
||||
$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"':'').'>';
|
||||
|
||||
// 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();
|
||||
$reshook=$hookmanager->executeHooks('addMoreMassActions',$parameters); // Note that $action and $object may have been modified by hook
|
||||
if (empty($reshook))
|
||||
|
||||
@ -62,24 +62,101 @@ class ActionsMyModule
|
||||
*/
|
||||
public function doActions($parameters, &$object, &$action, $hookmanager)
|
||||
{
|
||||
global $conf, $user, $langs;
|
||||
|
||||
$error = 0; // Error counter
|
||||
$myvalue = 'test'; // A result value
|
||||
|
||||
/*
|
||||
print_r($parameters);
|
||||
echo "action: " . $action;
|
||||
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) {
|
||||
$this->results = array('myreturn' => $myvalue);
|
||||
$this->results = array('myreturn' => 999);
|
||||
$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 {
|
||||
$this->errors[] = 'Error message';
|
||||
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