1<?php
2/* Copyright (C) 2010-2014	Regis Houssin		<regis.houssin@inodbox.com>
3 * Copyright (C) 2011-2016	Laurent Destailleur	<eldy@users.sourceforge.net>
4 * Copyright (C) 2011-2015	Juanjo Menent		<jmenent@2byte.es>
5 * Copyright (C) 2011-2018	Philippe Grand		<philippe.grand@atoo-net.com>
6 * Copyright (C) 2013		Florian Henry		<florian.henry@open-concept.pro>
7 * Copyright (C) 2015       Marcos García       <marcosgdf@gmail.com>
8 * Copyright (C) 2018		Ferran Marcet		<fmarcet@2byte.es>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24/**
25 *  \file       htdocs/projet/admin/project.php
26 *  \ingroup    project
27 *  \brief      Page to setup project module
28 */
29
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
34require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
35
36// Load translation files required by the page
37$langs->loadLangs(array('admin', 'errors', 'other', 'projects'));
38
39if (!$user->admin) {
40	accessforbidden();
41}
42
43$value = GETPOST('value', 'alpha');
44$action = GETPOST('action', 'aZ09');
45$label = GETPOST('label', 'alpha');
46$scandir = GETPOST('scan_dir', 'alpha');
47$type = 'project';
48
49
50/*
51 * Actions
52 */
53
54include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
55
56if ($action == 'updateMask') {
57	$maskconstproject = GETPOST('maskconstproject', 'alpha');
58	$maskproject = GETPOST('maskproject', 'alpha');
59
60	if ($maskconstproject) {
61		$res = dolibarr_set_const($db, $maskconstproject, $maskproject, 'chaine', 0, '', $conf->entity);
62	}
63
64	if (!($res > 0)) {
65		$error++;
66	}
67
68	if (!$error) {
69		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
70	} else {
71		setEventMessages($langs->trans("Error"), null, 'errors');
72	}
73}
74
75if ($action == 'updateMaskTask') {
76	$maskconstmasktask = GETPOST('maskconsttask', 'alpha');
77	$masktaskt = GETPOST('masktask', 'alpha');
78
79	if ($maskconstmasktask) {
80		$res = dolibarr_set_const($db, $maskconstmasktask, $masktaskt, 'chaine', 0, '', $conf->entity);
81	}
82
83	if (!($res > 0)) {
84		$error++;
85	}
86
87	if (!$error) {
88		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
89	} else {
90		setEventMessages($langs->trans("Error"), null, 'errors');
91	}
92} elseif ($action == 'specimen') {
93	$modele = GETPOST('module', 'alpha');
94
95	$project = new Project($db);
96	$project->initAsSpecimen();
97
98	// Search template files
99	$file = ''; $classname = ''; $filefound = 0;
100	$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
101	foreach ($dirmodels as $reldir) {
102		$file = dol_buildpath($reldir."core/modules/project/doc/pdf_".$modele.".modules.php", 0);
103		if (file_exists($file)) {
104			$filefound = 1;
105			$classname = "pdf_".$modele;
106			break;
107		}
108	}
109
110	if ($filefound) {
111		require_once $file;
112
113		$module = new $classname($db);
114
115		if ($module->write_file($project, $langs) > 0) {
116			header("Location: ".DOL_URL_ROOT."/document.php?modulepart=project&file=SPECIMEN.pdf");
117			return;
118		} else {
119			setEventMessages($obj->error, $obj->errors, 'errors');
120			dol_syslog($obj->error, LOG_ERR);
121		}
122	} else {
123		setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
124		dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
125	}
126} elseif ($action == 'specimentask') {
127	$modele = GETPOST('module', 'alpha');
128
129	$project = new Project($db);
130	$project->initAsSpecimen();
131
132	// Search template files
133	$file = ''; $classname = ''; $filefound = 0;
134	$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
135	foreach ($dirmodels as $reldir) {
136		$file = dol_buildpath($reldir."core/modules/project/task/doc/pdf_".$modele.".modules.php", 0);
137		if (file_exists($file)) {
138			$filefound = 1;
139			$classname = "pdf_".$modele;
140			break;
141		}
142	}
143
144	if ($filefound) {
145		require_once $file;
146
147		$module = new $classname($db);
148
149		if ($module->write_file($project, $langs) > 0) {
150			header("Location: ".DOL_URL_ROOT."/document.php?modulepart=project_task&file=SPECIMEN.pdf");
151			return;
152		} else {
153			setEventMessages($obj->error, $obj->errors, 'errors');
154			dol_syslog($obj->error, LOG_ERR);
155		}
156	} else {
157		setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
158		dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
159	}
160} elseif ($action == 'set') {
161	// Activate a model
162	$ret = addDocumentModel($value, $type, $label, $scandir);
163} elseif ($action == 'settask') {
164	// Activate a model for task
165	$ret = addDocumentModel($value, 'project_task', $label, $scandir);
166} elseif ($action == 'del') {
167	$ret = delDocumentModel($value, $type);
168	if ($ret > 0) {
169		if ($conf->global->PROJECT_ADDON_PDF == "$value") {
170			dolibarr_del_const($db, 'PROJECT_ADDON_PDF', $conf->entity);
171		}
172	}
173} elseif ($action == 'deltask') {
174	$ret = delDocumentModel($value, 'project_task');
175	if ($ret > 0) {
176		if ($conf->global->PROJECT_TASK_ADDON_PDF == "$value") {
177			dolibarr_del_const($db, 'PROJECT_TASK_ADDON_PDF', $conf->entity);
178		}
179	}
180} elseif ($action == 'setdoc') {
181	// Set default model
182	dolibarr_set_const($db, "PROJECT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity);
183
184	// On active le modele
185	$ret = delDocumentModel($value, $type);
186	if ($ret > 0) {
187		$ret = addDocumentModel($value, $type, $label, $scandir);
188	}
189} elseif ($action == 'setdoctask') {
190	if (dolibarr_set_const($db, "PROJECT_TASK_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
191		// La constante qui a ete lue en avant du nouveau set
192		// on passe donc par une variable pour avoir un affichage coherent
193		$conf->global->PROJECT_TASK_ADDON_PDF = $value;
194	}
195
196	// On active le modele
197	$ret = delDocumentModel($value, 'project_task');
198	if ($ret > 0) {
199		$ret = addDocumentModel($value, 'project_task', $label, $scandir);
200	}
201} elseif ($action == 'setmod') {
202	// TODO Verifier si module numerotation choisi peut etre active
203	// par appel methode canBeActivated
204
205	dolibarr_set_const($db, "PROJECT_ADDON", $value, 'chaine', 0, '', $conf->entity);
206} elseif ($action == 'setmodtask') {
207	// TODO Verifier si module numerotation choisi peut etre active
208	// par appel methode canBeActivated
209
210	dolibarr_set_const($db, "PROJECT_TASK_ADDON", $value, 'chaine', 0, '', $conf->entity);
211} elseif ($action == 'updateoptions') {
212	if (GETPOST('PROJECT_USE_SEARCH_TO_SELECT')) {
213		$companysearch = GETPOST('activate_PROJECT_USE_SEARCH_TO_SELECT', 'alpha');
214		if (dolibarr_set_const($db, "PROJECT_USE_SEARCH_TO_SELECT", $companysearch, 'chaine', 0, '', $conf->entity)) {
215			$conf->global->PROJECT_USE_SEARCH_TO_SELECT = $companysearch;
216		}
217	}
218	if (GETPOST('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY')) {
219		$projectToSelect = GETPOST('projectToSelect', 'alpha');
220		dolibarr_set_const($db, 'PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY', $projectToSelect, 'chaine', 0, '', $conf->entity); //Allow to disable this configuration if empty value
221	}
222} elseif (preg_match('/^(set|del)_?([A-Z_]+)$/', $action, $reg)) {
223	// Set boolean (on/off) constants
224	if (!dolibarr_set_const($db, $reg[2], ($reg[1] === 'set' ? '1' : '0'), 'chaine', 0, '', $conf->entity) > 0) {
225		dol_print_error($db);
226	}
227}
228
229/*
230 * View
231 */
232
233$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
234
235llxHeader("", $langs->trans("ProjectsSetup"));
236
237$form = new Form($db);
238
239$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
240print load_fiche_titre($langs->trans("ProjectsSetup"), $linkback, 'title_setup');
241
242$head = project_admin_prepare_head();
243
244print dol_get_fiche_head($head, 'project', $langs->trans("Projects"), -1, 'project');
245
246
247
248// Main options
249$form = new Form($db);
250
251print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
252print '<input type="hidden" name="token" value="'.newToken().'">';
253print '<input type="hidden" name="action" value="setmainoptions">';
254
255print '<table class="noborder centpercent">';
256print '<tr class="liste_titre">';
257print "<td>".$langs->trans("Parameters")."</td>\n";
258print '<td class="right" width="60">'.$langs->trans("Value").'</td>'."\n";
259print '<td width="80">&nbsp;</td></tr>'."\n";
260
261print '<tr class="oddeven">';
262print '<td width="80%">'.$langs->trans("ManageOpportunitiesStatus").'</td>';
263print '<td width="60" class="right">';
264print ajax_constantonoff("PROJECT_USE_OPPORTUNITIES");
265print '</td><td class="right">';
266print "</td>";
267print '</tr>';
268
269
270print '<tr class="oddeven">';
271print '<td width="80%">'.$langs->trans("ManageTasks").'</td>';
272print '<td width="60" class="right">';
273print ajax_constantonoff("PROJECT_HIDE_TASKS", array(), null, 1);
274print '</td><td class="right">';
275print "</td>";
276print '</tr>';
277
278print '</table></form>';
279
280print '<br>';
281
282
283
284/*
285 * Projects Numbering model
286 */
287
288print load_fiche_titre($langs->trans("ProjectsNumberingModules"), '', '');
289
290print '<table class="noborder centpercent">';
291print '<tr class="liste_titre">';
292print '<td width="100">'.$langs->trans("Name").'</td>';
293print '<td>'.$langs->trans("Description").'</td>';
294print '<td>'.$langs->trans("Example").'</td>';
295print '<td class="center" width="60">'.$langs->trans("Activated").'</td>';
296print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
297print "</tr>\n";
298
299clearstatcache();
300
301foreach ($dirmodels as $reldir) {
302	$dir = dol_buildpath($reldir."core/modules/project/");
303
304	if (is_dir($dir)) {
305		$handle = opendir($dir);
306		if (is_resource($handle)) {
307			while (($file = readdir($handle)) !== false) {
308				if (preg_match('/^(mod_.*)\.php$/i', $file, $reg)) {
309					$file = $reg[1];
310					$classname = substr($file, 4);
311
312					require_once $dir.$file.'.php';
313
314					$module = new $file;
315
316					// Show modules according to features level
317					if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
318						continue;
319					}
320					if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
321						continue;
322					}
323
324					if ($module->isEnabled()) {
325						print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
326						print $module->info();
327						print '</td>';
328
329						// Show example of numbering model
330						print '<td class="nowrap">';
331						$tmp = $module->getExample();
332						if (preg_match('/^Error/', $tmp)) {
333							$langs->load("errors");
334							print '<div class="error">'.$langs->trans($tmp).'</div>';
335						} elseif ($tmp == 'NotConfigured') {
336							print $langs->trans($tmp);
337						} else {
338							print $tmp;
339						}
340						print '</td>'."\n";
341
342						print '<td class="center">';
343						if ($conf->global->PROJECT_ADDON == 'mod_'.$classname) {
344							print img_picto($langs->trans("Activated"), 'switch_on');
345						} else {
346							print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;token='.newToken().'&amp;value=mod_'.$classname.'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
347						}
348						print '</td>';
349
350						$project = new Project($db);
351						$project->initAsSpecimen();
352
353						// Info
354						$htmltooltip = '';
355						$htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
356						$nextval = $module->getNextValue($mysoc, $project);
357						if ("$nextval" != $langs->trans("NotAvailable")) {	// Keep " on nextval
358							$htmltooltip .= ''.$langs->trans("NextValue").': ';
359							if ($nextval) {
360								$htmltooltip .= $nextval.'<br>';
361							} else {
362								$htmltooltip .= $langs->trans($module->error).'<br>';
363							}
364						}
365
366						print '<td class="center">';
367						print $form->textwithpicto('', $htmltooltip, 1, 0);
368						print '</td>';
369
370						print '</tr>';
371					}
372				}
373			}
374			closedir($handle);
375		}
376	}
377}
378
379print '</table><br>';
380
381
382if (empty($conf->global->PROJECT_HIDE_TASKS)) {
383	// Task numbering module
384	print load_fiche_titre($langs->trans("TasksNumberingModules"), '', '');
385
386	print '<table class="noborder centpercent">';
387	print '<tr class="liste_titre">';
388	print '<td width="100">'.$langs->trans("Name").'</td>';
389	print '<td>'.$langs->trans("Description").'</td>';
390	print '<td>'.$langs->trans("Example").'</td>';
391	print '<td class="center" width="60">'.$langs->trans("Activated").'</td>';
392	print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
393	print "</tr>\n";
394
395	clearstatcache();
396
397	foreach ($dirmodels as $reldir) {
398		$dir = dol_buildpath($reldir."core/modules/project/task/");
399
400		if (is_dir($dir)) {
401			$handle = opendir($dir);
402			if (is_resource($handle)) {
403				while (($file = readdir($handle)) !== false) {
404					if (preg_match('/^(mod_.*)\.php$/i', $file, $reg)) {
405						$file = $reg[1];
406						$classname = substr($file, 4);
407
408						require_once $dir.$file.'.php';
409
410						$module = new $file;
411
412						// Show modules according to features level
413						if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
414							continue;
415						}
416						if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
417							continue;
418						}
419
420						if ($module->isEnabled()) {
421							print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
422							print $module->info();
423							print '</td>';
424
425							// Show example of numbering module
426							print '<td class="nowrap">';
427							$tmp = $module->getExample();
428							if (preg_match('/^Error/', $tmp)) {
429								$langs->load("errors");
430								print '<div class="error">'.$langs->trans($tmp).'</div>';
431							} elseif ($tmp == 'NotConfigured') {
432								print $langs->trans($tmp);
433							} else {
434								print $tmp;
435							}
436							print '</td>'."\n";
437
438							print '<td class="center">';
439							if ($conf->global->PROJECT_TASK_ADDON == 'mod_'.$classname) {
440								print img_picto($langs->trans("Activated"), 'switch_on');
441							} else {
442								print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodtask&amp;token='.newToken().'&amp;value=mod_'.$classname.'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
443							}
444							print '</td>';
445
446							$project = new Project($db);
447							$project->initAsSpecimen();
448
449							// Info
450							$htmltooltip = '';
451							$htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
452							$nextval = $module->getNextValue($mysoc, $project);
453							if ("$nextval" != $langs->trans("NotAvailable")) {	// Keep " on nextval
454								$htmltooltip .= ''.$langs->trans("NextValue").': ';
455								if ($nextval) {
456									$htmltooltip .= $nextval.'<br>';
457								} else {
458									$htmltooltip .= $langs->trans($module->error).'<br>';
459								}
460							}
461
462							print '<td class="center">';
463							print $form->textwithpicto('', $htmltooltip, 1, 0);
464							print '</td>';
465
466							print '</tr>';
467						}
468					}
469				}
470				closedir($handle);
471			}
472		}
473	}
474
475	print '</table><br>';
476}
477
478
479/*
480 * Document templates generators
481 */
482
483print load_fiche_titre($langs->trans("ProjectsModelModule"), '', '');
484
485// Defini tableau def de modele
486$type = 'project';
487$def = array();
488
489$sql = "SELECT nom";
490$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
491$sql .= " WHERE type = '".$db->escape($type)."'";
492$sql .= " AND entity = ".$conf->entity;
493
494$resql = $db->query($sql);
495if ($resql) {
496	$i = 0;
497	$num_rows = $db->num_rows($resql);
498	while ($i < $num_rows) {
499		$array = $db->fetch_array($resql);
500		array_push($def, $array[0]);
501		$i++;
502	}
503} else {
504	dol_print_error($db);
505}
506
507print "<table class=\"noborder\" width=\"100%\">\n";
508print "<tr class=\"liste_titre\">\n";
509print '  <td width="100">'.$langs->trans("Name")."</td>\n";
510print "  <td>".$langs->trans("Description")."</td>\n";
511print '<td class="center" width="60">'.$langs->trans("Activated")."</td>\n";
512print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
513print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
514print '<td class="center" width="80">'.$langs->trans("Preview").'</td>';
515print "</tr>\n";
516
517clearstatcache();
518
519foreach ($dirmodels as $reldir) {
520	foreach (array('', '/doc') as $valdir) {
521		$dir = dol_buildpath($reldir."core/modules/project/".$valdir);
522
523		if (is_dir($dir)) {
524			$handle = opendir($dir);
525			if (is_resource($handle)) {
526				while (($file = readdir($handle)) !== false) {
527					$filelist[] = $file;
528				}
529				closedir($handle);
530				arsort($filelist);
531
532				foreach ($filelist as $file) {
533					if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
534						if (file_exists($dir.'/'.$file)) {
535							$name = substr($file, 4, dol_strlen($file) - 16);
536							$classname = substr($file, 0, dol_strlen($file) - 12);
537
538							require_once $dir.'/'.$file;
539							$module = new $classname($db);
540
541							$modulequalified = 1;
542							if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
543								$modulequalified = 0;
544							}
545							if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
546								$modulequalified = 0;
547							}
548
549							if ($modulequalified) {
550								print '<tr class="oddeven"><td width="100">';
551								print (empty($module->name) ? $name : $module->name);
552								print "</td><td>\n";
553								if (method_exists($module, 'info')) {
554									print $module->info($langs);
555								} else {
556									print $module->description;
557								}
558								print "</td>\n";
559
560								// Active
561								if (in_array($name, $def)) {
562									print "<td class=\"center\">\n";
563									print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
564									print img_picto($langs->trans("Enabled"), 'switch_on');
565									print '</a>';
566									print "</td>";
567								} else {
568									print "<td class=\"center\">\n";
569									print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
570									print "</td>";
571								}
572
573								// Default
574								print "<td class=\"center\">";
575								if ($conf->global->PROJECT_ADDON_PDF == "$name") {
576									print img_picto($langs->trans("Default"), 'on');
577								} else {
578									print '<a 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>';
579								}
580								print '</td>';
581
582								// Info
583								$htmltooltip = ''.$langs->trans("Name").': '.$module->name;
584								$htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
585								if ($module->type == 'pdf') {
586									$htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
587								}
588								$htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
589								$htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
590
591								print '<td class="center">';
592								print $form->textwithpicto('', $htmltooltip, 1, 0);
593								print '</td>';
594
595								// Preview
596								print '<td class="center">';
597								if ($module->type == 'pdf') {
598									print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'bill').'</a>';
599								} else {
600									print img_object($langs->trans("PreviewNotAvailable"), 'generic');
601								}
602								print '</td>';
603
604								print "</tr>\n";
605							}
606						}
607					}
608				}
609			}
610		}
611	}
612}
613
614print '</table><br>';
615
616
617
618if (empty($conf->global->PROJECT_HIDE_TASKS)) {
619	/*
620	 * Modeles documents for Task
621	 */
622
623	print load_fiche_titre($langs->trans("TaskModelModule"), '', '');
624
625	// Defini tableau def de modele
626	$type = 'project_task';
627	$def = array();
628
629	$sql = "SELECT nom";
630	$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
631	$sql .= " WHERE type = '".$db->escape($type)."'";
632	$sql .= " AND entity = ".$conf->entity;
633
634	$resql = $db->query($sql);
635	if ($resql) {
636		$i = 0;
637		$num_rows = $db->num_rows($resql);
638		while ($i < $num_rows) {
639			$array = $db->fetch_array($resql);
640			array_push($def, $array[0]);
641			$i++;
642		}
643	} else {
644		dol_print_error($db);
645	}
646
647	print "<table class=\"noborder\" width=\"100%\">\n";
648	print "<tr class=\"liste_titre\">\n";
649	print '  <td width="100">'.$langs->trans("Name")."</td>\n";
650	print "  <td>".$langs->trans("Description")."</td>\n";
651	print '<td class="center" width="60">'.$langs->trans("Activated")."</td>\n";
652	print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
653	print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
654	print '<td class="center" width="80">'.$langs->trans("Preview").'</td>';
655	print "</tr>\n";
656
657	clearstatcache();
658
659	foreach ($dirmodels as $reldir) {
660		foreach (array('', '/doc') as $valdir) {
661			$dir = dol_buildpath($reldir."core/modules/project/task/".$valdir);
662
663			if (is_dir($dir)) {
664				$handle = opendir($dir);
665				if (is_resource($handle)) {
666					while (($file = readdir($handle)) !== false) {
667						$filelist[] = $file;
668					}
669					closedir($handle);
670					arsort($filelist);
671
672					foreach ($filelist as $file) {
673						if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
674							if (file_exists($dir.'/'.$file)) {
675								$name = substr($file, 4, dol_strlen($file) - 16);
676								$classname = substr($file, 0, dol_strlen($file) - 12);
677
678								require_once $dir.'/'.$file;
679								$module = new $classname($db);
680
681								$modulequalified = 1;
682								if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
683									$modulequalified = 0;
684								}
685								if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
686									$modulequalified = 0;
687								}
688
689								if ($modulequalified) {
690									print '<tr class="oddeven"><td width="100">';
691									print (empty($module->name) ? $name : $module->name);
692									print "</td><td>\n";
693									if (method_exists($module, 'info')) {
694										print $module->info($langs);
695									} else {
696										print $module->description;
697									}
698									print "</td>\n";
699
700									// Active
701									if (in_array($name, $def)) {
702										print "<td class=\"center\">\n";
703										print '<a href="'.$_SERVER["PHP_SELF"].'?action=deltask&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
704										print img_picto($langs->trans("Enabled"), 'switch_on');
705										print '</a>';
706										print "</td>";
707									} else {
708										print "<td class=\"center\">\n";
709										print '<a href="'.$_SERVER["PHP_SELF"].'?action=settask&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
710										print "</td>";
711									}
712
713									// Defaut
714									print "<td class=\"center\">";
715									if ($conf->global->PROJECT_TASK_ADDON_PDF == "$name") {
716										print img_picto($langs->trans("Default"), 'on');
717									} else {
718										print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoctask&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>';
719									}
720									print '</td>';
721
722									// Info
723									$htmltooltip = ''.$langs->trans("Name").': '.$module->name;
724									$htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
725									if ($module->type == 'pdf') {
726										$htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
727									}
728									$htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
729									$htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
730
731									print '<td class="center">';
732									print $form->textwithpicto('', $htmltooltip, 1, 0);
733									print '</td>';
734
735									// Preview
736									print '<td class="center">';
737									if ($module->type == 'pdf') {
738										print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimentask&module='.$name.'">'.img_object($langs->trans("Preview"), 'bill').'</a>';
739									} else {
740										print img_object($langs->trans("PreviewNotAvailable"), 'generic');
741									}
742									print '</td>';
743									print "</tr>\n";
744								}
745							}
746						}
747					}
748				}
749			}
750		}
751	}
752
753	print '</table><br>';
754}
755
756
757print load_fiche_titre($langs->trans("Other"), '', '');
758
759// Other options
760$form = new Form($db);
761
762print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
763print '<input type="hidden" name="token" value="'.newToken().'">';
764print '<input type="hidden" name="action" value="updateoptions">';
765
766print '<table class="noborder centpercent">';
767print '<tr class="liste_titre">';
768print "<td>".$langs->trans("Parameters")."</td>\n";
769print '<td class="right" width="60">'.$langs->trans("Value").'</td>'."\n";
770print '<td width="80">&nbsp;</td></tr>'."\n";
771
772print '<tr class="oddeven">';
773print '<td width="80%">'.$langs->trans("UseSearchToSelectProject").'</td>';
774if (!$conf->use_javascript_ajax) {
775	print '<td class="nowrap right" colspan="2">';
776	print $langs->trans("NotAvailableWhenAjaxDisabled");
777	print "</td>";
778} else {
779	print '<td width="60" class="right">';
780	$arrval = array('0'=>$langs->trans("No"),
781		'1'=>$langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch", 1).')',
782		'2'=>$langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch", 2).')',
783		'3'=>$langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch", 3).')',
784	);
785	print $form->selectarray("activate_PROJECT_USE_SEARCH_TO_SELECT", $arrval, $conf->global->PROJECT_USE_SEARCH_TO_SELECT);
786	print '</td><td class="right">';
787	print '<input type="submit" class="button" name="PROJECT_USE_SEARCH_TO_SELECT" value="'.$langs->trans("Modify").'">';
788	print "</td>";
789}
790print '</tr>';
791
792print '<tr class="oddeven">';
793print '<td>'.$langs->trans("AllowToSelectProjectFromOtherCompany").'</td>';
794
795print '<td class="right" width="60" colspan="2">';
796print '<input type="text" id="projectToSelect" name="projectToSelect" value="'.$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.'"/>&nbsp;';
797print $form->textwithpicto('', $langs->trans('AllowToLinkFromOtherCompany'));
798print '<input type="submit" class="button" name="PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY" value="'.$langs->trans("Modify").'">';
799print '</td>';
800
801$key = 'PROJECT_CLASSIFY_CLOSED_WHEN_ALL_TASKS_DONE';
802echo '<tr class="oddeven">',
803		'<td class="left">',
804			$form->textwithpicto($langs->transnoentities($key), $langs->transnoentities($key . '_help')),
805		'</td>',
806		'<td class="right" colspan="2">',
807			ajax_constantonoff($key),
808		'</td>',
809	'</tr>';
810
811print '</table>';
812
813
814print '</form>';
815
816// End of page
817llxFooter();
818$db->close();
819