project.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis@dolibarr.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 2 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 <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/admin/project.php
  19. * \ingroup project
  20. * \brief Page d'administration-configuration du module Projet
  21. */
  22. require("../main.inc.php");
  23. require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
  24. require_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php');
  25. require_once(DOL_DOCUMENT_ROOT.'/projet/class/task.class.php');
  26. $langs->load("admin");
  27. $langs->load("other");
  28. $langs->load("projects");
  29. if (!$user->admin)
  30. accessforbidden();
  31. /*
  32. * Actions
  33. */
  34. if ($_POST["action"] == 'updateMask')
  35. {
  36. $maskconstproject=$_POST['maskconstproject'];
  37. $maskproject=$_POST['maskproject'];
  38. if ($maskconstproject) dolibarr_set_const($db,$maskconstproject,$maskproject,'chaine',0,'',$conf->entity);
  39. }
  40. if ($_GET["action"] == 'specimen')
  41. {
  42. $modele=$_GET["module"];
  43. $project = new Project($db);
  44. $project->initAsSpecimen();
  45. // Charge le modele
  46. $dir = DOL_DOCUMENT_ROOT . "/includes/modules/project/pdf/";
  47. $file = "pdf_".$modele.".modules.php";
  48. if (file_exists($dir.$file))
  49. {
  50. $classname = "pdf_".$modele;
  51. require_once($dir.$file);
  52. $obj = new $classname($db);
  53. if ($obj->write_file($project,$langs) > 0)
  54. {
  55. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=project&file=SPECIMEN.pdf");
  56. return;
  57. }
  58. else
  59. {
  60. $mesg='<div class="error">'.$obj->error.'</div>';
  61. dol_syslog($obj->error, LOG_ERR);
  62. }
  63. }
  64. else
  65. {
  66. $mesg='<div class="error">'.$langs->trans("ErrorModuleNotFound").'</div>';
  67. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  68. }
  69. }
  70. if ($_GET["action"] == 'set')
  71. {
  72. $type='project';
  73. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  74. $sql.= " VALUES ('".$db->escape($_GET["value"])."','".$type."',".$conf->entity.", ";
  75. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  76. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  77. $sql.= ")";
  78. if ($db->query($sql))
  79. {
  80. }
  81. }
  82. if ($_GET["action"] == 'del')
  83. {
  84. $type='project';
  85. $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  86. $sql.= " WHERE nom = '".$_GET["value"]."'";
  87. $sql.= " AND type = '".$type."'";
  88. $sql.= " AND entity = ".$conf->entity;
  89. if ($db->query($sql))
  90. {
  91. }
  92. }
  93. if ($_GET["action"] == 'setdoc')
  94. {
  95. $db->begin();
  96. if (dolibarr_set_const($db, "PROJECT_ADDON_PDF",$_GET["value"],'chaine',0,'',$conf->entity))
  97. {
  98. $conf->global->PROJECT_ADDON_PDF = $_GET["value"];
  99. }
  100. // On active le modele
  101. $type='project';
  102. $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  103. $sql_del.= " WHERE nom = '".$db->escape($_GET["value"])."'";
  104. $sql_del.= " AND type = '".$type."'";
  105. $sql_del.= " AND entity = ".$conf->entity;
  106. $result1=$db->query($sql_del);
  107. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  108. $sql.= " VALUES ('".$db->escape($_GET["value"])."', '".$type."', ".$conf->entity.", ";
  109. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  110. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  111. $sql.= ")";
  112. $result2=$db->query($sql);
  113. if ($result1 && $result2)
  114. {
  115. $db->commit();
  116. }
  117. else
  118. {
  119. $db->rollback();
  120. }
  121. }
  122. if ($_GET["action"] == 'setmod')
  123. {
  124. // TODO Verifier si module numerotation choisi peut etre active
  125. // par appel methode canBeActivated
  126. dolibarr_set_const($db, "PROJECT_ADDON",$_GET["value"],'chaine',0,'',$conf->entity);
  127. }
  128. /*
  129. * View
  130. */
  131. $html=new Form($db);
  132. llxHeader();
  133. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  134. print_fiche_titre($langs->trans("ProjectsSetup"),$linkback,'setup');
  135. print "<br>";
  136. // Project numbering module
  137. $dir = DOL_DOCUMENT_ROOT."/includes/modules/project/";
  138. print_titre($langs->trans("ProjectsNumberingModules"));
  139. print '<table class="noborder" width="100%">';
  140. print '<tr class="liste_titre">';
  141. print '<td width="100">'.$langs->trans("Name").'</td>';
  142. print '<td>'.$langs->trans("Description").'</td>';
  143. print '<td>'.$langs->trans("Example").'</td>';
  144. print '<td align="center" width="60">'.$langs->trans("Activated").'</td>';
  145. print '<td align="center" width="16">'.$langs->trans("Info").'</td>';
  146. print "</tr>\n";
  147. clearstatcache();
  148. $handle = opendir($dir);
  149. if (is_resource($handle))
  150. {
  151. $var=true;
  152. while (($file = readdir($handle))!==false)
  153. {
  154. if (substr($file, 0, 12) == 'mod_project_' && substr($file, dol_strlen($file)-3, 3) == 'php')
  155. {
  156. $file = substr($file, 0, dol_strlen($file)-4);
  157. require_once(DOL_DOCUMENT_ROOT ."/includes/modules/project/".$file.".php");
  158. $module = new $file;
  159. if ($module->isEnabled())
  160. {
  161. // Show modules according to features level
  162. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  163. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  164. $var=!$var;
  165. print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
  166. print $module->info();
  167. print '</td>';
  168. // Show example of numbering module
  169. print '<td nowrap="nowrap">';
  170. $tmp=$module->getExample();
  171. if (preg_match('/^Error/',$tmp)) print $langs->trans($tmp);
  172. else print $tmp;
  173. print '</td>'."\n";
  174. print '<td align="center">';
  175. if ($conf->global->PROJECT_ADDON == "$file")
  176. {
  177. print img_picto($langs->trans("Activated"),'on');
  178. }
  179. else
  180. {
  181. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  182. }
  183. print '</td>';
  184. $project=new Project($db);
  185. $project->initAsSpecimen();
  186. // Info
  187. $htmltooltip='';
  188. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  189. $nextval=$module->getNextValue($mysoc,$project);
  190. if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
  191. {
  192. $htmltooltip.=''.$langs->trans("NextValue").': ';
  193. if ($nextval)
  194. {
  195. $htmltooltip.=$nextval.'<br>';
  196. }
  197. else
  198. {
  199. $htmltooltip.=$langs->trans($module->error).'<br>';
  200. }
  201. }
  202. print '<td align="center">';
  203. print $html->textwithpicto('',$htmltooltip,1,0);
  204. print '</td>';
  205. print '</tr>';
  206. }
  207. }
  208. }
  209. closedir($handle);
  210. }
  211. print '</table><br>';
  212. /*
  213. * Modeles documents for projects
  214. */
  215. $dir = DOL_DOCUMENT_ROOT.'/includes/modules/project/pdf/';
  216. print_titre($langs->trans("ProjectsModelModule"));
  217. // Defini tableau def de modele
  218. $type='project';
  219. $def = array();
  220. $sql = "SELECT nom";
  221. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  222. $sql.= " WHERE type = '".$type."'";
  223. $sql.= " AND entity = ".$conf->entity;
  224. $resql=$db->query($sql);
  225. if ($resql)
  226. {
  227. $i = 0;
  228. $num_rows=$db->num_rows($resql);
  229. while ($i < $num_rows)
  230. {
  231. $array = $db->fetch_array($resql);
  232. array_push($def, $array[0]);
  233. $i++;
  234. }
  235. }
  236. else
  237. {
  238. dol_print_error($db);
  239. }
  240. print "<table class=\"noborder\" width=\"100%\">\n";
  241. print "<tr class=\"liste_titre\">\n";
  242. print ' <td width="100">'.$langs->trans("Name")."</td>\n";
  243. print " <td>".$langs->trans("Description")."</td>\n";
  244. print '<td align="center" width="60">'.$langs->trans("Activated")."</td>\n";
  245. print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
  246. print '<td align="center" width="32" colspan="2">'.$langs->trans("Info").'</td>';
  247. print "</tr>\n";
  248. clearstatcache();
  249. $handle=opendir($dir);
  250. $var=true;
  251. if (is_resource($handle))
  252. {
  253. while (($file = readdir($handle))!==false)
  254. {
  255. if (preg_match('/\.modules\.php$/i',$file) && substr($file,0,4) == 'pdf_')
  256. {
  257. $name = substr($file, 4, dol_strlen($file) -16);
  258. $classname = substr($file, 0, dol_strlen($file) -12);
  259. $var=!$var;
  260. print "<tr ".$bc[$var].">\n <td>$name";
  261. print "</td>\n <td>\n";
  262. require_once($dir.$file);
  263. $module = new $classname($db);
  264. print $module->description;
  265. print "</td>\n";
  266. // Active
  267. if (in_array($name, $def))
  268. {
  269. print "<td align=\"center\">\n";
  270. if ($conf->global->PROJECT_ADDON_PDF != "$name")
  271. {
  272. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  273. print img_picto($langs->trans("Enabled"),'on');
  274. print '</a>';
  275. }
  276. else
  277. {
  278. print img_picto($langs->trans("Enabled"),'on');
  279. }
  280. print "</td>";
  281. }
  282. else
  283. {
  284. print "<td align=\"center\">\n";
  285. 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"),'off').'</a>';
  286. print "</td>";
  287. }
  288. // Defaut
  289. print "<td align=\"center\">";
  290. if ($conf->global->PROJECT_ADDON_PDF == "$name")
  291. {
  292. print img_picto($langs->trans("Default"),'on');
  293. }
  294. else
  295. {
  296. 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>';
  297. }
  298. print '</td>';
  299. // Info
  300. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  301. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  302. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  303. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  304. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  305. print '<td align="center">';
  306. print $html->textwithpicto('',$htmltooltip,1,0);
  307. print '</td>';
  308. print '<td align="center">';
  309. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"),'order').'</a>';
  310. print '</td>';
  311. print "</tr>\n";
  312. }
  313. }
  314. closedir($handle);
  315. }
  316. print '</table><br/>';
  317. llxFooter();
  318. ?>