project.php 27 KB

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