2
0
forked from Wavyzz/dolibarr

code syntax admin dir

This commit is contained in:
Frédéric FRANCE
2021-02-26 22:04:03 +01:00
parent 0d4acc53e2
commit 608b933ef5
146 changed files with 8414 additions and 7535 deletions

View File

@@ -30,7 +30,9 @@ require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
$langs->loadLangs(array("admin", "receptions", 'other'));
if (!$user->admin) accessforbidden();
if (!$user->admin) {
accessforbidden();
}
$action = GETPOST('action', 'aZ09');
$value = GETPOST('value', 'alpha');
@@ -43,14 +45,12 @@ $type = 'reception';
* Actions
*/
if (!empty($conf->reception->enabled) && empty($conf->global->MAIN_SUBMODULE_RECEPTION))
{
if (!empty($conf->reception->enabled) && empty($conf->global->MAIN_SUBMODULE_RECEPTION)) {
// This option should always be set to on when module is on.
dolibarr_set_const($db, "MAIN_SUBMODULE_RECEPTION", "1", 'chaine', 0, '', $conf->entity);
}
if (empty($conf->global->RECEPTION_ADDON_NUMBER))
{
if (empty($conf->global->RECEPTION_ADDON_NUMBER)) {
$conf->global->RECEPTION_ADDON_NUMBER = 'mod_reception_beryl';
}
@@ -61,43 +61,39 @@ if (empty($conf->global->RECEPTION_ADDON_NUMBER))
include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
if ($action == 'updateMask')
{
if ($action == 'updateMask') {
$maskconst = GETPOST('maskconstreception', 'alpha');
$maskvalue = GETPOST('maskreception', 'alpha');
if (!empty($maskconst))
if (!empty($maskconst)) {
$res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
if (isset($res))
{
if ($res > 0)
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
else setEventMessages($langs->trans("Error"), null, 'errors');
}
} elseif ($action == 'set_param')
{
if (isset($res)) {
if ($res > 0) {
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
setEventMessages($langs->trans("Error"), null, 'errors');
}
}
} elseif ($action == 'set_param') {
$freetext = GETPOST('RECEPTION_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
$res = dolibarr_set_const($db, "RECEPTION_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
if ($res <= 0)
{
if ($res <= 0) {
$error++;
setEventMessages($langs->trans("Error"), null, 'errors');
}
$draft = GETPOST('RECEPTION_DRAFT_WATERMARK', 'alpha');
$res = dolibarr_set_const($db, "RECEPTION_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
if ($res <= 0)
{
if ($res <= 0) {
$error++;
setEventMessages($langs->trans("Error"), null, 'errors');
}
if (!$error)
{
if (!$error) {
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
}
} elseif ($action == 'specimen')
{
} elseif ($action == 'specimen') {
$modele = GETPOST('module', 'alpha');
$exp = new Reception($db);
@@ -106,25 +102,21 @@ if ($action == 'updateMask')
// Search template files
$file = ''; $classname = ''; $filefound = 0;
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
foreach ($dirmodels as $reldir)
{
foreach ($dirmodels as $reldir) {
$file = dol_buildpath($reldir."core/modules/reception/doc/pdf_".$modele.".modules.php", 0);
if (file_exists($file))
{
if (file_exists($file)) {
$filefound = 1;
$classname = "pdf_".$modele;
break;
}
}
if ($filefound)
{
if ($filefound) {
require_once $file;
$module = new $classname($db);
if ($module->write_file($exp, $langs) > 0)
{
if ($module->write_file($exp, $langs) > 0) {
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=reception&file=SPECIMEN.pdf");
return;
} else {
@@ -135,26 +127,19 @@ if ($action == 'updateMask')
setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
}
}
// Activate a model
elseif ($action == 'set')
{
} elseif ($action == 'set') {
// Activate a model
$ret = addDocumentModel($value, $type, $label, $scandir);
} elseif ($action == 'del')
{
} elseif ($action == 'del') {
$ret = delDocumentModel($value, $type);
if ($ret > 0)
{
if ($conf->global->RECEPTION_ADDON_PDF == "$value") dolibarr_del_const($db, 'RECEPTION_ADDON_PDF', $conf->entity);
if ($ret > 0) {
if ($conf->global->RECEPTION_ADDON_PDF == "$value") {
dolibarr_del_const($db, 'RECEPTION_ADDON_PDF', $conf->entity);
}
}
}
// Set default model
elseif ($action == 'setdoc')
{
if (dolibarr_set_const($db, "RECEPTION_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity))
{
} elseif ($action == 'setdoc') {
// Set default model
if (dolibarr_set_const($db, "RECEPTION_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
// La constante qui a ete lue en avant du nouveau set
// on passe donc par une variable pour avoir un affichage coherent
$conf->global->RECEPTION_ADDON_PDF = $value;
@@ -162,12 +147,10 @@ elseif ($action == 'setdoc')
// On active le modele
$ret = delDocumentModel($value, $type);
if ($ret > 0)
{
if ($ret > 0) {
$ret = addDocumentModel($value, $type, $label, $scandir);
}
} elseif ($action == 'setmodel')
{
} elseif ($action == 'setmodel') {
dolibarr_set_const($db, "RECEPTION_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity);
}
@@ -206,30 +189,28 @@ print "</tr>\n";
clearstatcache();
foreach ($dirmodels as $reldir)
{
foreach ($dirmodels as $reldir) {
$dir = dol_buildpath($reldir."core/modules/reception");
if (is_dir($dir))
{
if (is_dir($dir)) {
$handle = opendir($dir);
if (is_resource($handle))
{
while (($file = readdir($handle)) !== false)
{
if (substr($file, 0, 14) == 'mod_reception_' && substr($file, dol_strlen($file) - 3, 3) == 'php')
{
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
if (substr($file, 0, 14) == 'mod_reception_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
$file = substr($file, 0, dol_strlen($file) - 4);
require_once $dir.'/'.$file.'.php';
$module = new $file;
if ($module->isEnabled())
{
if ($module->isEnabled()) {
// Show modules according to features level
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
continue;
}
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
continue;
}
print '<tr><td>'.$module->nom."</td>\n";
print '<td>';
@@ -242,13 +223,15 @@ foreach ($dirmodels as $reldir)
if (preg_match('/^Error/', $tmp)) {
$langs->load("errors");
print '<div class="error">'.$langs->trans($tmp).'</div>';
} elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
else print $tmp;
} elseif ($tmp == 'NotConfigured') {
print $langs->trans($tmp);
} else {
print $tmp;
}
print '</td>'."\n";
print '<td class="center">';
if ($conf->global->RECEPTION_ADDON_NUMBER == "$file")
{
if ($conf->global->RECEPTION_ADDON_NUMBER == "$file") {
print img_picto($langs->trans("Activated"), 'switch_on');
} else {
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodel&amp;token='.newToken().'&amp;value='.urlencode($file).'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
@@ -267,8 +250,9 @@ foreach ($dirmodels as $reldir)
if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
$htmltooltip .= ''.$langs->trans("NextValue").': ';
if ($nextval) {
if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
$nextval = $langs->trans($nextval);
}
$htmltooltip .= $nextval.'<br>';
} else {
$htmltooltip .= $langs->trans($module->error).'<br>';
@@ -306,12 +290,10 @@ $sql .= " WHERE type = '".$db->escape($type)."'";
$sql .= " AND entity = ".$conf->entity;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$i = 0;
$num_rows = $db->num_rows($resql);
while ($i < $num_rows)
{
while ($i < $num_rows) {
$array = $db->fetch_array($resql);
array_push($def, $array[0]);
$i++;
@@ -332,31 +314,23 @@ print "</tr>\n";
clearstatcache();
foreach ($dirmodels as $reldir)
{
foreach (array('', '/doc') as $valdir)
{
foreach ($dirmodels as $reldir) {
foreach (array('', '/doc') as $valdir) {
$realpath = $reldir."core/modules/reception".$valdir;
$dir = dol_buildpath($realpath);
if (is_dir($dir))
{
if (is_dir($dir)) {
$handle = opendir($dir);
if (is_resource($handle))
{
while (($file = readdir($handle)) !== false)
{
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
$filelist[] = $file;
}
closedir($handle);
arsort($filelist);
foreach ($filelist as $file)
{
if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
{
if (file_exists($dir.'/'.$file))
{
foreach ($filelist as $file) {
if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
if (file_exists($dir.'/'.$file)) {
$name = substr($file, 4, dol_strlen($file) - 16);
$classname = substr($file, 0, dol_strlen($file) - 12);
@@ -364,21 +338,26 @@ foreach ($dirmodels as $reldir)
$module = new $classname($db);
$modulequalified = 1;
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0;
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0;
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
$modulequalified = 0;
}
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
$modulequalified = 0;
}
if ($modulequalified)
{
if ($modulequalified) {
print '<tr><td width="100">';
print (empty($module->name) ? $name : $module->name);
print "</td><td>\n";
if (method_exists($module, 'info')) print $module->info($langs);
else print $module->description;
if (method_exists($module, 'info')) {
print $module->info($langs);
} else {
print $module->description;
}
print '</td>';
// Active
if (in_array($name, $def))
{
if (in_array($name, $def)) {
print '<td class="center">'."\n";
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&amp;token='.newToken().'&amp;value='.$name.'">';
print img_picto($langs->trans("Enabled"), 'switch_on');
@@ -392,8 +371,7 @@ foreach ($dirmodels as $reldir)
// Defaut
print '<td class="center">';
if ($conf->global->RECEPTION_ADDON_PDF == $name)
{
if ($conf->global->RECEPTION_ADDON_PDF == $name) {
print img_picto($langs->trans("Default"), 'on');
} else {
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
@@ -403,8 +381,7 @@ foreach ($dirmodels as $reldir)
// Info
$htmltooltip = ''.$langs->trans("Name").': '.$module->name;
$htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
if ($module->type == 'pdf')
{
if ($module->type == 'pdf') {
$htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
}
$htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
@@ -422,8 +399,7 @@ foreach ($dirmodels as $reldir)
// Preview
print '<td class="center">';
if ($module->type == 'pdf')
{
if ($module->type == 'pdf') {
print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
} else {
print img_object($langs->trans("PreviewNotAvailable"), 'generic');
@@ -471,13 +447,13 @@ print $form->textwithpicto($langs->trans("FreeLegalTextOnReceptions"), $langs->t
$variablename='RECEPTION_FREE_TEXT';
if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
{
print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
}
else
{
include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_notes');
print $doleditor->Create();
include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_notes');
print $doleditor->Create();
}
print "</td></tr>\n";