PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/project.php

https://github.com/asterix14/dolibarr
PHP | 404 lines | 285 code | 69 blank | 50 comment | 54 complexity | 33e694bea32aded9140bbba832870611 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
  3. * Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/admin/project.php
  21. * \ingroup project
  22. * \brief Page to setup project module
  23. */
  24. require("../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
  26. require_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php');
  27. require_once(DOL_DOCUMENT_ROOT.'/projet/class/task.class.php');
  28. $langs->load("admin");
  29. $langs->load("other");
  30. $langs->load("projects");
  31. if (!$user->admin)
  32. accessforbidden();
  33. $value=GETPOST('value');
  34. $action=GETPOST('action');
  35. /*
  36. * Actions
  37. */
  38. if ($action == 'updateMask')
  39. {
  40. $maskconstproject=GETPOST("maskconstproject");
  41. $maskproject=GETPOST("maskproject");
  42. if ($maskconstproject) $res = dolibarr_set_const($db,$maskconstproject,$maskproject,'chaine',0,'',$conf->entity);
  43. if (! $res > 0) $error++;
  44. if (! $error)
  45. {
  46. $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  47. }
  48. else
  49. {
  50. $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  51. }
  52. }
  53. if ($action == 'specimen')
  54. {
  55. $modele=GETPOST("module");
  56. $project = new Project($db);
  57. $project->initAsSpecimen();
  58. // Charge le modele
  59. $dir = DOL_DOCUMENT_ROOT . "/core/modules/project/pdf/";
  60. $file = "pdf_".$modele.".modules.php";
  61. if (file_exists($dir.$file))
  62. {
  63. $classname = "pdf_".$modele;
  64. require_once($dir.$file);
  65. $obj = new $classname($db);
  66. if ($obj->write_file($project,$langs) > 0)
  67. {
  68. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=project&file=SPECIMEN.pdf");
  69. return;
  70. }
  71. else
  72. {
  73. $mesg='<div class="error">'.$obj->error.'</div>';
  74. dol_syslog($obj->error, LOG_ERR);
  75. }
  76. }
  77. else
  78. {
  79. $mesg='<div class="error">'.$langs->trans("ErrorModuleNotFound").'</div>';
  80. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  81. }
  82. }
  83. if ($action == 'set')
  84. {
  85. $label = GETPOST("label");
  86. $scandir = GETPOST("scandir");
  87. $type='project';
  88. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  89. $sql.= " VALUES ('".$db->escape($value)."','".$type."',".$conf->entity.", ";
  90. $sql.= ($label?"'".$db->escape($label)."'":'null').", ";
  91. $sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null");
  92. $sql.= ")";
  93. $resql=$db->query($sql);
  94. }
  95. if ($action == 'del')
  96. {
  97. $type='project';
  98. $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  99. $sql.= " WHERE nom = '".$db->escape($value)."'";
  100. $sql.= " AND type = '".$type."'";
  101. $sql.= " AND entity = ".$conf->entity;
  102. if ($db->query($sql))
  103. {
  104. if ($conf->global->PROJECT_ADDON_PDF == "$value") dolibarr_del_const($db, 'PROJECT_ADDON_PDF',$conf->entity);
  105. }
  106. }
  107. if ($action == 'setdoc')
  108. {
  109. $label = GETPOST("label");
  110. $scandir = GETPOST("scandir");
  111. $db->begin();
  112. if (dolibarr_set_const($db, "PROJECT_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
  113. {
  114. $conf->global->PROJECT_ADDON_PDF = $value;
  115. }
  116. // On active le modele
  117. $type='project';
  118. $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  119. $sql_del.= " WHERE nom = '".$db->escape($value)."'";
  120. $sql_del.= " AND type = '".$type."'";
  121. $sql_del.= " AND entity = ".$conf->entity;
  122. $result1=$db->query($sql_del);
  123. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  124. $sql.= " VALUES ('".$db->escape($value)."', '".$type."', ".$conf->entity.", ";
  125. $sql.= ($label?"'".$db->escape($label)."'":'null').", ";
  126. $sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null");
  127. $sql.= ")";
  128. $result2=$db->query($sql);
  129. if ($result1 && $result2)
  130. {
  131. $db->commit();
  132. }
  133. else
  134. {
  135. $db->rollback();
  136. }
  137. }
  138. if ($action == 'setmod')
  139. {
  140. // TODO Verifier si module numerotation choisi peut etre active
  141. // par appel methode canBeActivated
  142. dolibarr_set_const($db, "PROJECT_ADDON",$_GET["value"],'chaine',0,'',$conf->entity);
  143. }
  144. /*
  145. * View
  146. */
  147. $form=new Form($db);
  148. llxHeader();
  149. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  150. print_fiche_titre($langs->trans("ProjectsSetup"),$linkback,'setup');
  151. print "<br>";
  152. // Project numbering module
  153. $dir = DOL_DOCUMENT_ROOT."/core/modules/project/";
  154. print_titre($langs->trans("ProjectsNumberingModules"));
  155. print '<table class="noborder" width="100%">';
  156. print '<tr class="liste_titre">';
  157. print '<td width="100">'.$langs->trans("Name").'</td>';
  158. print '<td>'.$langs->trans("Description").'</td>';
  159. print '<td>'.$langs->trans("Example").'</td>';
  160. print '<td align="center" width="60">'.$langs->trans("Activated").'</td>';
  161. print '<td align="center" width="80">'.$langs->trans("Infos").'</td>';
  162. print "</tr>\n";
  163. clearstatcache();
  164. $handle = opendir($dir);
  165. if (is_resource($handle))
  166. {
  167. $var=true;
  168. while (($file = readdir($handle))!==false)
  169. {
  170. if (substr($file, 0, 12) == 'mod_project_' && substr($file, dol_strlen($file)-3, 3) == 'php')
  171. {
  172. $file = substr($file, 0, dol_strlen($file)-4);
  173. require_once(DOL_DOCUMENT_ROOT ."/core/modules/project/".$file.".php");
  174. $module = new $file;
  175. if ($module->isEnabled())
  176. {
  177. // Show modules according to features level
  178. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  179. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  180. $var=!$var;
  181. print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
  182. print $module->info();
  183. print '</td>';
  184. // Show example of numbering module
  185. print '<td nowrap="nowrap">';
  186. $tmp=$module->getExample();
  187. if (preg_match('/^Error/',$tmp)) { $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>'; }
  188. elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
  189. else print $tmp;
  190. print '</td>'."\n";
  191. print '<td align="center">';
  192. if ($conf->global->PROJECT_ADDON == "$file")
  193. {
  194. print img_picto($langs->trans("Activated"),'switch_on');
  195. }
  196. else
  197. {
  198. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  199. }
  200. print '</td>';
  201. $project=new Project($db);
  202. $project->initAsSpecimen();
  203. // Info
  204. $htmltooltip='';
  205. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  206. $nextval=$module->getNextValue($mysoc,$project);
  207. if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
  208. {
  209. $htmltooltip.=''.$langs->trans("NextValue").': ';
  210. if ($nextval)
  211. {
  212. $htmltooltip.=$nextval.'<br>';
  213. }
  214. else
  215. {
  216. $htmltooltip.=$langs->trans($module->error).'<br>';
  217. }
  218. }
  219. print '<td align="center">';
  220. print $form->textwithpicto('',$htmltooltip,1,0);
  221. print '</td>';
  222. print '</tr>';
  223. }
  224. }
  225. }
  226. closedir($handle);
  227. }
  228. print '</table><br>';
  229. /*
  230. * Modeles documents for projects
  231. */
  232. $dir = DOL_DOCUMENT_ROOT.'/core/modules/project/pdf/';
  233. print_titre($langs->trans("ProjectsModelModule"));
  234. // Defini tableau def de modele
  235. $type='project';
  236. $def = array();
  237. $sql = "SELECT nom";
  238. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  239. $sql.= " WHERE type = '".$type."'";
  240. $sql.= " AND entity = ".$conf->entity;
  241. $resql=$db->query($sql);
  242. if ($resql)
  243. {
  244. $i = 0;
  245. $num_rows=$db->num_rows($resql);
  246. while ($i < $num_rows)
  247. {
  248. $array = $db->fetch_array($resql);
  249. array_push($def, $array[0]);
  250. $i++;
  251. }
  252. }
  253. else
  254. {
  255. dol_print_error($db);
  256. }
  257. print "<table class=\"noborder\" width=\"100%\">\n";
  258. print "<tr class=\"liste_titre\">\n";
  259. print ' <td width="100">'.$langs->trans("Name")."</td>\n";
  260. print " <td>".$langs->trans("Description")."</td>\n";
  261. print '<td align="center" width="60">'.$langs->trans("Activated")."</td>\n";
  262. print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
  263. print '<td align="center" width="80">'.$langs->trans("Infos").'</td>';
  264. print "</tr>\n";
  265. clearstatcache();
  266. $handle=opendir($dir);
  267. $var=true;
  268. if (is_resource($handle))
  269. {
  270. while (($file = readdir($handle))!==false)
  271. {
  272. if (preg_match('/\.modules\.php$/i',$file) && substr($file,0,4) == 'pdf_')
  273. {
  274. $name = substr($file, 4, dol_strlen($file) -16);
  275. $classname = substr($file, 0, dol_strlen($file) -12);
  276. $var=!$var;
  277. print "<tr ".$bc[$var].">\n <td>$name";
  278. print "</td>\n <td>\n";
  279. require_once($dir.$file);
  280. $module = new $classname($db);
  281. print $module->description;
  282. print "</td>\n";
  283. // Active
  284. if (in_array($name, $def))
  285. {
  286. print "<td align=\"center\">\n";
  287. //if ($conf->global->PROJECT_ADDON_PDF != "$name")
  288. //{
  289. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  290. print img_picto($langs->trans("Enabled"),'switch_on');
  291. print '</a>';
  292. //}
  293. //else
  294. //{
  295. // print img_picto($langs->trans("Enabled"),'on');
  296. //}
  297. print "</td>";
  298. }
  299. else
  300. {
  301. print "<td align=\"center\">\n";
  302. 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>';
  303. print "</td>";
  304. }
  305. // Defaut
  306. print "<td align=\"center\">";
  307. if ($conf->global->PROJECT_ADDON_PDF == "$name")
  308. {
  309. print img_picto($langs->trans("Default"),'on');
  310. }
  311. else
  312. {
  313. 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>';
  314. }
  315. print '</td>';
  316. // Info
  317. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  318. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  319. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  320. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  321. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  322. print '<td align="center">';
  323. $link='<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"),'order').'</a>';
  324. print $form->textwithpicto(' &nbsp; &nbsp; '.$link,$htmltooltip,-1,0);
  325. print '</td>';
  326. print "</tr>\n";
  327. }
  328. }
  329. closedir($handle);
  330. }
  331. print '</table><br/>';
  332. dol_htmloutput_mesg($mesg);
  333. $db->close();
  334. llxFooter();
  335. ?>