1<?php 2/* Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18/** 19 * \file htdocs/admin/reception_setup.php 20 * \ingroup reception 21 * \brief Page to setup reception module 22 */ 23 24require '../main.inc.php'; 25require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; 26require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php'; 27require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; 28require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php'; 29 30$langs->loadLangs(array("admin", "receptions", 'other')); 31 32 33if (!$user->admin) accessforbidden(); 34 35$action = GETPOST('action', 'aZ09'); 36$value = GETPOST('value', 'alpha'); 37$label = GETPOST('label', 'alpha'); 38$scandir = GETPOST('scan_dir', 'alpha'); 39$type = 'reception'; 40 41 42/* 43 * Actions 44 */ 45 46if (!empty($conf->reception->enabled) && empty($conf->global->MAIN_SUBMODULE_RECEPTION)) 47{ 48 // This option should always be set to on when module is on. 49 dolibarr_set_const($db, "MAIN_SUBMODULE_RECEPTION", "1", 'chaine', 0, '', $conf->entity); 50} 51 52if (empty($conf->global->RECEPTION_ADDON_NUMBER)) 53{ 54 $conf->global->RECEPTION_ADDON_NUMBER = 'mod_reception_beryl'; 55} 56 57 58/* 59 * Actions 60 */ 61 62include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; 63 64if ($action == 'updateMask') 65{ 66 $maskconst = GETPOST('maskconstreception', 'alpha'); 67 $maskvalue = GETPOST('maskreception', 'alpha'); 68 if (!empty($maskconst)) 69 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity); 70 71 if (isset($res)) 72 { 73 if ($res > 0) 74 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); 75 else setEventMessages($langs->trans("Error"), null, 'errors'); 76 } 77} elseif ($action == 'set_param') 78{ 79 $freetext = GETPOST('RECEPTION_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string 80 $res = dolibarr_set_const($db, "RECEPTION_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity); 81 if ($res <= 0) 82 { 83 $error++; 84 setEventMessages($langs->trans("Error"), null, 'errors'); 85 } 86 87 $draft = GETPOST('RECEPTION_DRAFT_WATERMARK', 'alpha'); 88 $res = dolibarr_set_const($db, "RECEPTION_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity); 89 if ($res <= 0) 90 { 91 $error++; 92 setEventMessages($langs->trans("Error"), null, 'errors'); 93 } 94 95 if (!$error) 96 { 97 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); 98 } 99} elseif ($action == 'specimen') 100{ 101 $modele = GETPOST('module', 'alpha'); 102 103 $exp = new Reception($db); 104 $exp->initAsSpecimen(); 105 106 // Search template files 107 $file = ''; $classname = ''; $filefound = 0; 108 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); 109 foreach ($dirmodels as $reldir) 110 { 111 $file = dol_buildpath($reldir."core/modules/reception/doc/pdf_".$modele.".modules.php", 0); 112 if (file_exists($file)) 113 { 114 $filefound = 1; 115 $classname = "pdf_".$modele; 116 break; 117 } 118 } 119 120 if ($filefound) 121 { 122 require_once $file; 123 124 $module = new $classname($db); 125 126 if ($module->write_file($exp, $langs) > 0) 127 { 128 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=reception&file=SPECIMEN.pdf"); 129 return; 130 } else { 131 setEventMessages($module->error, $module->errors, 'errors'); 132 dol_syslog($module->error, LOG_ERR); 133 } 134 } else { 135 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); 136 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); 137 } 138} 139 140// Activate a model 141elseif ($action == 'set') 142{ 143 $ret = addDocumentModel($value, $type, $label, $scandir); 144} elseif ($action == 'del') 145{ 146 $ret = delDocumentModel($value, $type); 147 if ($ret > 0) 148 { 149 if ($conf->global->RECEPTION_ADDON_PDF == "$value") dolibarr_del_const($db, 'RECEPTION_ADDON_PDF', $conf->entity); 150 } 151} 152 153// Set default model 154elseif ($action == 'setdoc') 155{ 156 if (dolibarr_set_const($db, "RECEPTION_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) 157 { 158 // La constante qui a ete lue en avant du nouveau set 159 // on passe donc par une variable pour avoir un affichage coherent 160 $conf->global->RECEPTION_ADDON_PDF = $value; 161 } 162 163 // On active le modele 164 $ret = delDocumentModel($value, $type); 165 if ($ret > 0) 166 { 167 $ret = addDocumentModel($value, $type, $label, $scandir); 168 } 169} elseif ($action == 'setmodel') 170{ 171 dolibarr_set_const($db, "RECEPTION_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity); 172} 173 174 175 176 177/* 178 * View 179 */ 180 181$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); 182 183$form = new Form($db); 184 185llxHeader("", $langs->trans("ReceptionsSetup")); 186 187$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>'; 188print load_fiche_titre($langs->trans("ReceptionsSetup"), $linkback, 'title_setup'); 189print '<br>'; 190$head = reception_admin_prepare_head(); 191 192print dol_get_fiche_head($head, 'reception', $langs->trans("Receptions"), -1, 'sending'); 193 194// Reception numbering model 195 196print load_fiche_titre($langs->trans("ReceptionsNumberingModules")); 197 198print '<table class="noborder centpercent">'; 199print '<tr class="liste_titre">'; 200print '<td width="100">'.$langs->trans("Name").'</td>'; 201print '<td>'.$langs->trans("Description").'</td>'; 202print '<td>'.$langs->trans("Example").'</td>'; 203print '<td class="center" width="60">'.$langs->trans("Status").'</td>'; 204print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>'; 205print "</tr>\n"; 206 207clearstatcache(); 208 209foreach ($dirmodels as $reldir) 210{ 211 $dir = dol_buildpath($reldir."core/modules/reception"); 212 213 if (is_dir($dir)) 214 { 215 $handle = opendir($dir); 216 if (is_resource($handle)) 217 { 218 while (($file = readdir($handle)) !== false) 219 { 220 if (substr($file, 0, 14) == 'mod_reception_' && substr($file, dol_strlen($file) - 3, 3) == 'php') 221 { 222 $file = substr($file, 0, dol_strlen($file) - 4); 223 224 require_once $dir.'/'.$file.'.php'; 225 226 $module = new $file; 227 228 if ($module->isEnabled()) 229 { 230 // Show modules according to features level 231 if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; 232 if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; 233 234 print '<tr><td>'.$module->nom."</td>\n"; 235 print '<td>'; 236 print $module->info(); 237 print '</td>'; 238 239 // Show example of numbering module 240 print '<td class="nowrap">'; 241 $tmp = $module->getExample(); 242 if (preg_match('/^Error/', $tmp)) { 243 $langs->load("errors"); 244 print '<div class="error">'.$langs->trans($tmp).'</div>'; 245 } elseif ($tmp == 'NotConfigured') print $langs->trans($tmp); 246 else print $tmp; 247 print '</td>'."\n"; 248 249 print '<td class="center">'; 250 if ($conf->global->RECEPTION_ADDON_NUMBER == "$file") 251 { 252 print img_picto($langs->trans("Activated"), 'switch_on'); 253 } else { 254 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodel&token='.newToken().'&value='.urlencode($file).'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'">'; 255 print img_picto($langs->trans("Disabled"), 'switch_off'); 256 print '</a>'; 257 } 258 print '</td>'; 259 260 $reception = new Reception($db); 261 $reception->initAsSpecimen(); 262 263 // Info 264 $htmltooltip = ''; 265 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>'; 266 $nextval = $module->getNextValue($mysoc, $reception); 267 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval 268 $htmltooltip .= ''.$langs->trans("NextValue").': '; 269 if ($nextval) { 270 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') 271 $nextval = $langs->trans($nextval); 272 $htmltooltip .= $nextval.'<br>'; 273 } else { 274 $htmltooltip .= $langs->trans($module->error).'<br>'; 275 } 276 } 277 278 print '<td class="center">'; 279 print $form->textwithpicto('', $htmltooltip, 1, 0); 280 print '</td>'; 281 282 print '</tr>'; 283 } 284 } 285 } 286 closedir($handle); 287 } 288 } 289} 290 291print '</table><br>'; 292 293 294/* 295 * Documents models for Receptions Receipt 296 */ 297print load_fiche_titre($langs->trans("ReceptionsReceiptModel")); 298 299// Defini tableau def de modele invoice 300$type = "reception"; 301$def = array(); 302 303$sql = "SELECT nom"; 304$sql .= " FROM ".MAIN_DB_PREFIX."document_model"; 305$sql .= " WHERE type = '".$db->escape($type)."'"; 306$sql .= " AND entity = ".$conf->entity; 307 308$resql = $db->query($sql); 309if ($resql) 310{ 311 $i = 0; 312 $num_rows = $db->num_rows($resql); 313 while ($i < $num_rows) 314 { 315 $array = $db->fetch_array($resql); 316 array_push($def, $array[0]); 317 $i++; 318 } 319} else { 320 dol_print_error($db); 321} 322 323print '<table class="noborder centpercent">'; 324print '<tr class="liste_titre">'; 325print '<td width="140">'.$langs->trans("Name").'</td>'; 326print '<td>'.$langs->trans("Description").'</td>'; 327print '<td align="center" width="60">'.$langs->trans("Status").'</td>'; 328print '<td align="center" width="60">'.$langs->trans("Default").'</td>'; 329print '<td align="center" width="80" class="nowrap">'.$langs->trans("ShortInfo").'</td>'; 330print '<td align="center" width="80" class="nowrap">'.$langs->trans("Preview").'</td>'; 331print "</tr>\n"; 332 333clearstatcache(); 334 335foreach ($dirmodels as $reldir) 336{ 337 foreach (array('', '/doc') as $valdir) 338 { 339 $realpath = $reldir."core/modules/reception".$valdir; 340 $dir = dol_buildpath($realpath); 341 342 if (is_dir($dir)) 343 { 344 $handle = opendir($dir); 345 if (is_resource($handle)) 346 { 347 while (($file = readdir($handle)) !== false) 348 { 349 $filelist[] = $file; 350 } 351 closedir($handle); 352 arsort($filelist); 353 354 foreach ($filelist as $file) 355 { 356 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) 357 { 358 if (file_exists($dir.'/'.$file)) 359 { 360 $name = substr($file, 4, dol_strlen($file) - 16); 361 $classname = substr($file, 0, dol_strlen($file) - 12); 362 363 require_once $dir.'/'.$file; 364 $module = new $classname($db); 365 366 $modulequalified = 1; 367 if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0; 368 if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0; 369 370 if ($modulequalified) 371 { 372 print '<tr><td width="100">'; 373 print (empty($module->name) ? $name : $module->name); 374 print "</td><td>\n"; 375 if (method_exists($module, 'info')) print $module->info($langs); 376 else print $module->description; 377 print '</td>'; 378 379 // Active 380 if (in_array($name, $def)) 381 { 382 print '<td class="center">'."\n"; 383 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.$name.'">'; 384 print img_picto($langs->trans("Enabled"), 'switch_on'); 385 print '</a>'; 386 print '</td>'; 387 } else { 388 print '<td class="center">'."\n"; 389 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>'; 390 print "</td>"; 391 } 392 393 // Defaut 394 print '<td class="center">'; 395 if ($conf->global->RECEPTION_ADDON_PDF == $name) 396 { 397 print img_picto($langs->trans("Default"), 'on'); 398 } else { 399 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>'; 400 } 401 print '</td>'; 402 403 // Info 404 $htmltooltip = ''.$langs->trans("Name").': '.$module->name; 405 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown")); 406 if ($module->type == 'pdf') 407 { 408 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; 409 } 410 $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file; 411 412 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>'; 413 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1); 414 $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1); 415 $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1); 416 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1); 417 $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1); 418 419 print '<td class="center">'; 420 print $form->textwithpicto('', $htmltooltip, 1, 0); 421 print '</td>'; 422 423 // Preview 424 print '<td class="center">'; 425 if ($module->type == 'pdf') 426 { 427 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'">'.img_object($langs->trans("Preview"), 'pdf').'</a>'; 428 } else { 429 print img_object($langs->trans("PreviewNotAvailable"), 'generic'); 430 } 431 print '</td>'; 432 433 print "</tr>\n"; 434 } 435 } 436 } 437 } 438 } 439 } 440 } 441} 442 443print '</table>'; 444print '<br>'; 445 446 447/* 448 * Other options 449 * 450 */ 451/* 452print load_fiche_titre($langs->trans("OtherOptions")); 453 454print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'; 455print '<input type="hidden" name="token" value="'.newToken().'">'; 456print '<input type="hidden" name="action" value="set_param">'; 457 458print "<table class=\"noborder\" width=\"100%\">"; 459print "<tr class=\"liste_titre\">"; 460print "<td>".$langs->trans("Parameter")."</td>\n"; 461print "</tr>"; 462 463$substitutionarray=pdf_getSubstitutionArray($langs); 464$substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation"); 465$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>'; 466foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>'; 467$htmltext.='</i>'; 468 469print '<tr><td>'; 470print $form->textwithpicto($langs->trans("FreeLegalTextOnReceptions"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext).'<br>'; 471$variablename='RECEPTION_FREE_TEXT'; 472if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) 473{ 474 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>'; 475} 476else 477{ 478 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; 479 $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_notes'); 480 print $doleditor->Create(); 481} 482print "</td></tr>\n"; 483 484print '<tr><td>'; 485print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext).'<br>'; 486print '<input size="50" class="flat" type="text" name="RECEPTION_DRAFT_WATERMARK" value="'.$conf->global->RECEPTION_DRAFT_WATERMARK.'">'; 487print "</td></tr>\n"; 488*/ 489print '</table>'; 490 491//print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>'; 492 493print '</form>'; 494 495llxFooter(); 496$db->close(); 497