New: emailing submodules can be stored into the module directory.

This commit is contained in:
Laurent Destailleur 2012-01-26 23:05:59 +01:00
parent 30aeeee2fa
commit 0ab6cec007
3 changed files with 182 additions and 147 deletions

View File

@ -72,16 +72,8 @@ llxHeader('',$langs->trans("Setup"),$help_url);
print_fiche_titre($langs->trans("ModulesSetup"),'','setup'); print_fiche_titre($langs->trans("ModulesSetup"),'','setup');
// Search modules // Search modules dirs
$filename = array();
$modules = array();
$orders = array();
$categ = array();
$dirmod = array();
$modulesdir = array(); $modulesdir = array();
$i = 0; // is a sequencer of modules found
$j = 0; // j is module number. Automatically affected if module number not defined.
foreach ($conf->file->dol_document_root as $type => $dirroot) foreach ($conf->file->dol_document_root as $type => $dirroot)
{ {
$modulesdir[$dirroot . '/core/modules/'] = $dirroot . '/core/modules/'; $modulesdir[$dirroot . '/core/modules/'] = $dirroot . '/core/modules/';
@ -104,6 +96,15 @@ foreach ($conf->file->dol_document_root as $type => $dirroot)
} }
//var_dump($modulesdir); //var_dump($modulesdir);
$filename = array();
$modules = array();
$orders = array();
$categ = array();
$dirmod = array();
$i = 0; // is a sequencer of modules found
$j = 0; // j is module number. Automatically affected if module number not defined.
foreach ($modulesdir as $dir) foreach ($modulesdir as $dir)
{ {
// Load modules attributes in arrays (name, numero, orders) from dir directory // Load modules attributes in arrays (name, numero, orders) from dir directory

View File

@ -32,16 +32,11 @@ require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");
$langs->load("mails"); $langs->load("mails");
// Security check // Security check
if (! $user->rights->mailing->lire || $user->societe_id > 0) if (! $user->rights->mailing->lire || $user->societe_id > 0) accessforbidden();
accessforbidden();
$dirmod=DOL_DOCUMENT_ROOT."/core/modules/mailings";
$mesg = ''; $mesg = '';
$sortfield = GETPOST("sortfield",'alpha'); $sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha'); $sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page",'int'); $page = GETPOST("page",'int');
@ -52,30 +47,59 @@ $pagenext = $page + 1;
if (! $sortorder) $sortorder="ASC"; if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="email"; if (! $sortfield) $sortfield="email";
$search_nom=isset($_GET["search_nom"])?$_GET["search_nom"]:$_POST["search_nom"]; $id=GETPOST('rowid')?GETPOST('rowid'):GETPOST('id');
$search_prenom=isset($_GET["search_prenom"])?$_GET["search_prenom"]:$_POST["search_prenom"]; $action=GETPOST("action");
$search_email=isset($_GET["search_email"])?$_GET["search_email"]:$_POST["search_email"]; $search_nom=GETPOST("search_nom");
$search_prenom=GETPOST("search_prenom");
$search_email=GETPOST("search_email");
// Search modules dirs
$modulesdir = array();
foreach ($conf->file->dol_document_root as $type => $dirroot)
{
$modulesdir[$dirroot . '/core/modules/mailings/'] = $dirroot . '/core/modules/mailings/';
$handle=@opendir($dirroot);
if (is_resource($handle))
{
while (($file = readdir($handle))!==false)
{
if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes')
{
if (is_dir($dirroot . '/' . $file . '/core/modules/mailings/'))
{
$modulesdir[$dirroot . '/' . $file . '/core/modules/mailings/'] = $dirroot . '/' . $file . '/core/modules/mailings/';
}
}
}
closedir($handle);
}
}
//var_dump($modulesdir);
$dirmod=DOL_DOCUMENT_ROOT."/core/modules/mailings";
/* /*
* Actions * Actions
*/ */
if ($_GET["action"] == 'add') if ($action == 'add')
{ {
$modulename=$_GET["module"]; $module=GETPOST("module");
$result=0; $result=-1;
$var=true; $var=true;
foreach ($conf->file->dol_document_root as $dirmod)
{
$dir=$dirmod."/core/modules/mailings/";
if (is_dir($dir)) foreach ($modulesdir as $dir)
{ {
// Load modules attributes in arrays (name, numero, orders) from dir directory
//print $dir."\n<br>";
dol_syslog("Scan directory ".$dir." for modules");
// Chargement de la classe // Chargement de la classe
$file = $dir."/".$modulename.".modules.php"; $file = $dir."/".$module.".modules.php";
$classname = "mailing_".$modulename; $classname = "mailing_".$module;
if (file_exists($file)) if (file_exists($file))
{ {
@ -88,14 +112,13 @@ if ($_GET["action"] == 'add')
// Add targets into database // Add targets into database
$obj = new $classname($db); $obj = new $classname($db);
$result=$obj->add_to_target($_GET["rowid"],$filtersarray); $result=$obj->add_to_target($id,$filtersarray);
}
} }
} }
if ($result > 0) if ($result > 0)
{ {
Header("Location: cibles.php?id=".$_GET["rowid"]); Header("Location: cibles.php?id=".$id);
exit; exit;
} }
if ($result == 0) if ($result == 0)
@ -104,12 +127,11 @@ if ($_GET["action"] == 'add')
} }
if ($result < 0) if ($result < 0)
{ {
$mesg='<div class="error">'.$obj->error.'</div>'; $mesg='<div class="error">'.$langs->trans("Error").($obj->error?' '.$obj->error:'').'</div>';
} }
$_REQUEST["id"]=$_GET["rowid"];
} }
if ($_GET["action"] == 'clear') if ($action == 'clear')
{ {
// Chargement de la classe // Chargement de la classe
$file = $dirmod."/modules_mailings.php"; $file = $dirmod."/modules_mailings.php";
@ -117,16 +139,16 @@ if ($_GET["action"] == 'clear')
require_once($file); require_once($file);
$obj = new $classname($db); $obj = new $classname($db);
$obj->clear_target($_GET["rowid"]); $obj->clear_target($id);
Header("Location: cibles.php?id=".$_GET["rowid"]); Header("Location: cibles.php?id=".$id);
exit; exit;
} }
if ($_GET["action"] == 'delete') if ($action == 'delete')
{ {
// Ici, rowid indique le destinataire et id le mailing // Ici, rowid indique le destinataire et id le mailing
$sql="DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles where rowid=".$_GET["rowid"]; $sql="DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles where rowid=".$id;
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
@ -135,7 +157,7 @@ if ($_GET["action"] == 'delete')
require_once($file); require_once($file);
$obj = new $classname($db); $obj = new $classname($db);
$obj->update_nb($_REQUEST["id"]); $obj->update_nb($id);
} }
else else
{ {
@ -162,7 +184,7 @@ $form = new Form($db);
$mil = new Mailing($db); $mil = new Mailing($db);
if ($mil->fetch($_REQUEST["id"]) >= 0) if ($mil->fetch($id) >= 0)
{ {
$head = emailing_prepare_head($mil); $head = emailing_prepare_head($mil);
@ -207,7 +229,7 @@ if ($mil->fetch($_REQUEST["id"]) >= 0)
print "</div>"; print "</div>";
if ($mesg) print "$mesg<br>\n"; dol_htmloutput_mesg($mesg);
$var=!$var; $var=!$var;
@ -227,13 +249,15 @@ if ($mil->fetch($_REQUEST["id"]) >= 0)
clearstatcache(); clearstatcache();
$var=true; $var=true;
foreach ($conf->file->dol_document_root as $dirroot)
{
$dir=$dirroot."/core/modules/mailings/";
if (is_dir($dir)) foreach ($modulesdir as $dir)
{ {
$handle=opendir($dir); $modulenames=array();
// Load modules attributes in arrays (name, numero, orders) from dir directory
//print $dir."\n<br>";
dol_syslog("Scan directory ".$dir." for modules");
$handle=@opendir($dir);
if (is_resource($handle)) if (is_resource($handle))
{ {
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
@ -242,9 +266,20 @@ if ($mil->fetch($_REQUEST["id"]) >= 0)
{ {
if (preg_match("/(.*)\.modules\.php$/i",$file,$reg)) if (preg_match("/(.*)\.modules\.php$/i",$file,$reg))
{ {
$modulename=$reg[1]; if ($reg[1] == 'example') continue;
if ($modulename == 'example') continue; $modulenames[]=$reg[1];
}
}
}
closedir($handle);
}
// Sort $modulenames
// TODO
// Loop on each submodule
foreach($modulenames as $modulename)
{
// Chargement de la classe // Chargement de la classe
$file = $dir.$modulename.".modules.php"; $file = $dir.$modulename.".modules.php";
$classname = "mailing_".$modulename; $classname = "mailing_".$modulename;
@ -320,11 +355,6 @@ if ($mil->fetch($_REQUEST["id"]) >= 0)
print "</tr>\n"; print "</tr>\n";
} }
} }
}
}
closedir($handle);
}
}
} // End foreach dir } // End foreach dir
print '</table>'; print '</table>';
@ -511,7 +541,7 @@ if ($mil->fetch($_REQUEST["id"]) >= 0)
} }
$db->close();
llxFooter(); llxFooter();
$db->close();
?> ?>

View File

@ -4021,7 +4021,7 @@ function get_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0)
* *
* @param string $mesgstring Message * @param string $mesgstring Message
* @param array $mesgarray Messages array * @param array $mesgarray Messages array
* @param string $style Which style to use ('ok', 'error') * @param string $style Which style to use ('ok', 'warning', 'error')
* @param int $keepembedded Set to 1 if message must be kept embedded into its html place (this disable jnotify) * @param int $keepembedded Set to 1 if message must be kept embedded into its html place (this disable jnotify)
* @return void * @return void
* *
@ -4033,21 +4033,25 @@ function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb
if (empty($mesgstring) && (! is_array($mesgarray) || count($mesgarray) == 0)) return; if (empty($mesgstring) && (! is_array($mesgarray) || count($mesgarray) == 0)) return;
$iserror=0; $iserror=0;
$iswarning=0;
if (is_array($mesgarray)) if (is_array($mesgarray))
{ {
foreach($mesgarray as $val) foreach($mesgarray as $val)
{ {
if ($val && preg_match('/class="error"/i',$val)) { $iserror++; break; } if ($val && preg_match('/class="error"/i',$val)) { $iserror++; break; }
if ($val && preg_match('/class="warning"/i',$val)) { $iswarning++; break; }
} }
} }
else if ($mesgstring && preg_match('/class="error"/i',$mesgstring)) $iserror++; else if ($mesgstring && preg_match('/class="error"/i',$mesgstring)) $iserror++;
else if ($mesgstring && preg_match('/class="warning"/i',$mesgstring)) $iswarning++;
if ($style=='error') $iserror++; if ($style=='error') $iserror++;
if ($style=='warning') $iswarning++;
if ($iserror) if ($iserror || $iswarning)
{ {
// Remove div from texts // Remove div from texts
$mesgstring=preg_replace('/<\/div><div class="error">/','<br>',$mesgstring); $mesgstring=preg_replace('/<\/div><div class="(error|warning)">/','<br>',$mesgstring);
$mesgstring=preg_replace('/<div class="error">/','',$mesgstring); $mesgstring=preg_replace('/<div class="(error|warning)">/','',$mesgstring);
$mesgstring=preg_replace('/<\/div>/','',$mesgstring); $mesgstring=preg_replace('/<\/div>/','',$mesgstring);
// Remove div from texts array // Remove div from texts array
if (is_array($mesgarray)) if (is_array($mesgarray))
@ -4055,14 +4059,14 @@ function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb
$newmesgarray=array(); $newmesgarray=array();
foreach($mesgarray as $val) foreach($mesgarray as $val)
{ {
$tmpmesgstring=preg_replace('/<\/div><div class="error">/','<br>',$val); $tmpmesgstring=preg_replace('/<\/div><div class="(error|warning)">/','<br>',$val);
$tmpmesgstring=preg_replace('/<div class="error">/','',$tmpmesgstring); $tmpmesgstring=preg_replace('/<div class="(error|warning)">/','',$tmpmesgstring);
$tmpmesgstring=preg_replace('/<\/div>/','',$tmpmesgstring); $tmpmesgstring=preg_replace('/<\/div>/','',$tmpmesgstring);
$newmesgarray[]=$tmpmesgstring; $newmesgarray[]=$tmpmesgstring;
} }
$mesgarray=$newmesgarray; $mesgarray=$newmesgarray;
} }
print get_htmloutput_mesg($mesgstring,$mesgarray,'error',$keepembedded); print get_htmloutput_mesg($mesgstring,$mesgarray,($iserror?'error':'warning'),$keepembedded);
} }
else print get_htmloutput_mesg($mesgstring,$mesgarray,'ok',$keepembedded); else print get_htmloutput_mesg($mesgstring,$mesgarray,'ok',$keepembedded);
} }