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