propale.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 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) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  7. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  8. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  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 2 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/propale.php
  25. * \ingroup propale
  26. * \brief Page d'administration/configuration du module Propale
  27. */
  28. require("../main.inc.php");
  29. require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
  30. require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php");
  31. $langs->load("admin");
  32. $langs->load("bills");
  33. $langs->load("propal");
  34. $langs->load("other");
  35. if (!$user->admin)
  36. accessforbidden();
  37. /*
  38. * Actions
  39. */
  40. if ($_POST["action"] == 'updateMask')
  41. {
  42. $maskconstpropal=$_POST['maskconstpropal'];
  43. $maskpropal=$_POST['maskpropal'];
  44. if ($maskconstpropal) dolibarr_set_const($db,$maskconstpropal,$maskpropal,'chaine',0,'',$conf->entity);
  45. }
  46. if ($_GET["action"] == 'specimen')
  47. {
  48. $modele=$_GET["module"];
  49. $propal = new Propal($db);
  50. $propal->initAsSpecimen();
  51. // Charge le modele
  52. $dir = "/includes/modules/propale/";
  53. $file = "pdf_propale_".$modele.".modules.php";
  54. $file = dol_buildpath($dir.$file);
  55. if (file_exists($file))
  56. {
  57. $classname = "pdf_propale_".$modele;
  58. require_once($file);
  59. $module = new $classname($db);
  60. if ($module->write_file($propal,$langs) > 0)
  61. {
  62. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=propal&file=SPECIMEN.pdf");
  63. return;
  64. }
  65. else
  66. {
  67. $mesg='<div class="error">'.$module->error.'</div>';
  68. dol_syslog($module->error, LOG_ERR);
  69. }
  70. }
  71. else
  72. {
  73. $mesg='<div class="error">'.$langs->trans("ErrorModuleNotFound").'</div>';
  74. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  75. }
  76. }
  77. if ($_POST["action"] == 'set_PROPALE_DRAFT_WATERMARK')
  78. {
  79. dolibarr_set_const($db, "PROPALE_DRAFT_WATERMARK",trim($_POST["PROPALE_DRAFT_WATERMARK"]),'chaine',0,'',$conf->entity);
  80. }
  81. if ($_POST["action"] == 'set_PROPALE_FREE_TEXT')
  82. {
  83. dolibarr_set_const($db, "PROPALE_FREE_TEXT",$_POST["PROPALE_FREE_TEXT"],'chaine',0,'',$conf->entity);
  84. }
  85. if ($_POST["action"] == 'setdefaultduration')
  86. {
  87. dolibarr_set_const($db, "PROPALE_VALIDITY_DURATION",$_POST["value"],'chaine',0,'',$conf->entity);
  88. }
  89. if ($_POST["action"] == 'setclassifiedinvoiced')
  90. {
  91. dolibarr_set_const($db, "PROPALE_CLASSIFIED_INVOICED_WITH_ORDER",$_POST["value"],'chaine',0,'',$conf->entity);
  92. }
  93. if ($_POST["action"] == 'setusecustomercontactasrecipient')
  94. {
  95. dolibarr_set_const($db, "PROPALE_USE_CUSTOMER_CONTACT_AS_RECIPIENT",$_POST["value"],'chaine',0,'',$conf->entity);
  96. }
  97. if ($_GET["action"] == 'set')
  98. {
  99. $type='propal';
  100. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  101. $sql.= " VALUES ('".$db->escape($_GET["value"])."','".$type."',".$conf->entity.", ";
  102. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  103. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  104. $sql.= ")";
  105. if ($db->query($sql))
  106. {
  107. }
  108. }
  109. if ($_GET["action"] == 'del')
  110. {
  111. $type='propal';
  112. $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  113. $sql.= " WHERE nom = '".$_GET["value"]."'";
  114. $sql.= " AND type = '".$type."'";
  115. $sql.= " AND entity = ".$conf->entity;
  116. if ($db->query($sql))
  117. {
  118. }
  119. }
  120. if ($_GET["action"] == 'setdoc')
  121. {
  122. $db->begin();
  123. if (dolibarr_set_const($db, "PROPALE_ADDON_PDF",$_GET["value"],'chaine',0,'',$conf->entity))
  124. {
  125. $conf->global->PROPALE_ADDON_PDF = $_GET["value"];
  126. }
  127. // On active le modele
  128. $type='propal';
  129. $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  130. $sql_del.= " WHERE nom = '".$db->escape($_GET["value"])."'";
  131. $sql_del.= " AND type = '".$type."'";
  132. $sql_del.= " AND entity = ".$conf->entity;
  133. $result1=$db->query($sql_del);
  134. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  135. $sql.= " VALUES ('".$db->escape($_GET["value"])."', '".$type."', ".$conf->entity.", ";
  136. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  137. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  138. $sql.= ")";
  139. $result2=$db->query($sql);
  140. if ($result1 && $result2)
  141. {
  142. $db->commit();
  143. }
  144. else
  145. {
  146. $db->rollback();
  147. }
  148. }
  149. if ($_GET["action"] == 'setmod')
  150. {
  151. // TODO Verifier si module numerotation choisi peut etre active
  152. // par appel methode canBeActivated
  153. dolibarr_set_const($db, "PROPALE_ADDON",$_GET["value"],'chaine',0,'',$conf->entity);
  154. }
  155. /*
  156. * Affiche page
  157. */
  158. llxHeader('',$langs->trans("PropalSetup"));
  159. $html=new Form($db);
  160. if ($mesg) print $mesg;
  161. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  162. print_fiche_titre($langs->trans("PropalSetup"),$linkback,'setup');
  163. /*
  164. * Module numerotation
  165. */
  166. print "<br>";
  167. print_titre($langs->trans("ProposalsNumberingModules"));
  168. print '<table class="noborder" width="100%">';
  169. print '<tr class="liste_titre">';
  170. print '<td>'.$langs->trans("Name")."</td>\n";
  171. print '<td>'.$langs->trans("Description")."</td>\n";
  172. print '<td nowrap>'.$langs->trans("Example")."</td>\n";
  173. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  174. print '<td align="center" width="16">'.$langs->trans("Infos").'</td>';
  175. print '</tr>'."\n";
  176. clearstatcache();
  177. foreach ($conf->file->dol_document_root as $dirroot)
  178. {
  179. $dir = $dirroot . "/includes/modules/propale/";
  180. if (is_dir($dir))
  181. {
  182. $handle = opendir($dir);
  183. if (is_resource($handle))
  184. {
  185. $var=true;
  186. while (($file = readdir($handle))!==false)
  187. {
  188. if (substr($file, 0, 12) == 'mod_propale_' && substr($file, dol_strlen($file)-3, 3) == 'php')
  189. {
  190. $file = substr($file, 0, dol_strlen($file)-4);
  191. require_once($dir.$file.".php");
  192. $module = new $file;
  193. // Show modules according to features level
  194. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  195. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  196. if ($module->isEnabled())
  197. {
  198. $var=!$var;
  199. print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
  200. print $module->info();
  201. print '</td>';
  202. // Show example of numbering module
  203. print '<td nowrap="nowrap">';
  204. $tmp=$module->getExample();
  205. if (preg_match('/^Error/',$tmp)) print $langs->trans($tmp);
  206. else print $tmp;
  207. print '</td>'."\n";
  208. print '<td align="center">';
  209. if ($conf->global->PROPALE_ADDON == "$file")
  210. {
  211. print img_picto($langs->trans("Activated"),'on');
  212. }
  213. else
  214. {
  215. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'">';
  216. print img_picto($langs->trans("Disabled"),'off');
  217. print '</a>';
  218. }
  219. print '</td>';
  220. $propale=new Propal($db);
  221. $propale->initAsSpecimen();
  222. // Info
  223. $htmltooltip='';
  224. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  225. $facture->type=0;
  226. $nextval=$module->getNextValue($mysoc,$propale);
  227. if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
  228. {
  229. $htmltooltip.=''.$langs->trans("NextValue").': ';
  230. if ($nextval)
  231. {
  232. $htmltooltip.=$nextval.'<br>';
  233. }
  234. else
  235. {
  236. $htmltooltip.=$langs->trans($module->error).'<br>';
  237. }
  238. }
  239. print '<td align="center">';
  240. print $html->textwithpicto('',$htmltooltip,1,0);
  241. print '</td>';
  242. print "</tr>\n";
  243. }
  244. }
  245. }
  246. closedir($handle);
  247. }
  248. }
  249. }
  250. print "</table><br>\n";
  251. /*
  252. * Modeles de documents
  253. */
  254. print_titre($langs->trans("ProposalsPDFModules"));
  255. // Defini tableau def de modele propal
  256. $def = array();
  257. $sql = "SELECT nom";
  258. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  259. $sql.= " WHERE type = 'propal'";
  260. $sql.= " AND entity = ".$conf->entity;
  261. $resql=$db->query($sql);
  262. if ($resql)
  263. {
  264. $i = 0;
  265. $num_rows=$db->num_rows($resql);
  266. while ($i < $num_rows)
  267. {
  268. $array = $db->fetch_array($resql);
  269. array_push($def, $array[0]);
  270. $i++;
  271. }
  272. }
  273. else
  274. {
  275. dol_print_error($db);
  276. }
  277. print "<table class=\"noborder\" width=\"100%\">\n";
  278. print "<tr class=\"liste_titre\">\n";
  279. print " <td width=\"140\">".$langs->trans("Name")."</td>\n";
  280. print " <td>".$langs->trans("Description")."</td>\n";
  281. print '<td align="center" width="40">'.$langs->trans("Status")."</td>\n";
  282. print '<td align="center" width="40">'.$langs->trans("Default")."</td>\n";
  283. print '<td align="center" width="40">'.$langs->trans("Infos").'</td>';
  284. print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
  285. print "</tr>\n";
  286. clearstatcache();
  287. foreach ($conf->file->dol_document_root as $dirroot)
  288. {
  289. $dir = $dirroot . "/includes/modules/propale/";
  290. if (is_dir($dir))
  291. {
  292. $var=true;
  293. $handle=opendir($dir);
  294. if (is_resource($handle))
  295. {
  296. while (($file = readdir($handle))!==false)
  297. {
  298. if (substr($file, dol_strlen($file) -12) == '.modules.php' && substr($file,0,12) == 'pdf_propale_')
  299. {
  300. $name = substr($file, 12, dol_strlen($file) - 24);
  301. $classname = substr($file, 0, dol_strlen($file) -12);
  302. $var=!$var;
  303. print "<tr ".$bc[$var].">\n <td>";
  304. print $name;
  305. print "</td>\n <td>\n";
  306. require_once($dir.$file);
  307. $module = new $classname($db);
  308. print $module->description;
  309. print '</td>';
  310. // Activate
  311. print '<td align="center">'."\n";
  312. if (in_array($name, $def))
  313. {
  314. if ($conf->global->PROPALE_ADDON_PDF != "$name")
  315. {
  316. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  317. print img_picto($langs->trans("Activated"),'on');
  318. print '</a>';
  319. }
  320. else
  321. {
  322. print img_picto($langs->trans("Activated"),'on');
  323. }
  324. }
  325. else
  326. {
  327. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  328. print img_picto($langs->trans("Disabled"),'off');
  329. print '</a>';
  330. }
  331. print "</td>";
  332. // Default
  333. print '<td align="center">';
  334. if ($conf->global->PROPALE_ADDON_PDF == "$name")
  335. {
  336. print img_picto($langs->trans("Yes"),'on');
  337. }
  338. else
  339. {
  340. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  341. print img_picto($langs->trans("No"),'off');
  342. print '</a>';
  343. }
  344. print '</td>';
  345. // Info
  346. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  347. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  348. $htmltooltip.='<br>'.$langs->trans("Height").'/'.$langs->trans("Width").': '.$module->page_hauteur.'/'.$module->page_largeur;
  349. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  350. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  351. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  352. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  353. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  354. //$htmltooltip.='<br>'.$langs->trans("Escompte").': '.yn($module->option_escompte,1,1);
  355. //$htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
  356. $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftProposal").': '.yn($module->option_draft_watermark,1,1);
  357. print '<td align="center">';
  358. print $html->textwithpicto('',$htmltooltip,1,0);
  359. print '</td>';
  360. print '<td align="center">';
  361. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'propal').'</a>';
  362. print '</td>';
  363. print "</tr>\n";
  364. }
  365. }
  366. closedir($handle);
  367. }
  368. }
  369. }
  370. print '</table>';
  371. print '<br>';
  372. /*
  373. * Other options
  374. *
  375. */
  376. print_titre($langs->trans("OtherOptions"));
  377. $var=true;
  378. print "<table class=\"noborder\" width=\"100%\">";
  379. print "<tr class=\"liste_titre\">";
  380. print "<td>".$langs->trans("Parameter")."</td>\n";
  381. print '<td width="60" align="center">'.$langs->trans("Value")."</td>\n";
  382. print "<td>&nbsp;</td>\n";
  383. print "</tr>";
  384. $var=!$var;
  385. print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
  386. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  387. print "<input type=\"hidden\" name=\"action\" value=\"setdefaultduration\">";
  388. print "<tr ".$bc[$var].">";
  389. print '<td>'.$langs->trans("DefaultProposalDurationValidity").'</td>';
  390. print '<td width="60" align="center">'."<input size=\"3\" class=\"flat\" type=\"text\" name=\"value\" value=\"".$conf->global->PROPALE_VALIDITY_DURATION."\"></td>";
  391. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  392. print '</tr>';
  393. print '</form>';
  394. /*
  395. $var=! $var;
  396. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  397. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  398. print '<input type="hidden" name="action" value="setusecustomercontactasrecipient">';
  399. print '<tr '.$bc[$var].'><td>';
  400. print $langs->trans("UseCustomerContactAsPropalRecipientIfExist");
  401. print '</td><td width="60" align="center">';
  402. print $html->selectyesno("value",$conf->global->PROPALE_USE_CUSTOMER_CONTACT_AS_RECIPIENT,1);
  403. print '</td><td align="right">';
  404. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  405. print "</td></tr>\n";
  406. print '</form>';
  407. */
  408. if ($conf->commande->enabled)
  409. {
  410. $var=!$var;
  411. print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
  412. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  413. print "<input type=\"hidden\" name=\"action\" value=\"setclassifiedinvoiced\">";
  414. print "<tr ".$bc[$var].">";
  415. print '<td>'.$langs->trans("ClassifiedInvoicedWithOrder").'</td>';
  416. print '<td width="60" align="center">';
  417. print $html->selectyesno('value',$conf->global->PROPALE_CLASSIFIED_INVOICED_WITH_ORDER,1);
  418. print "</td>";
  419. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  420. print '</tr>';
  421. print '</form>';
  422. }
  423. $var=! $var;
  424. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  425. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  426. print '<input type="hidden" name="action" value="set_PROPALE_FREE_TEXT">';
  427. print '<tr '.$bc[$var].'><td colspan="2">';
  428. print $langs->trans("FreeLegalTextOnProposal").' ('.$langs->trans("AddCRIfTooLong").')<br>';
  429. print '<textarea name="PROPALE_FREE_TEXT" class="flat" cols="120">'.$conf->global->PROPALE_FREE_TEXT.'</textarea>';
  430. print '</td><td align="right">';
  431. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  432. print "</td></tr>\n";
  433. print '</form>';
  434. $var=!$var;
  435. print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
  436. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  437. print "<input type=\"hidden\" name=\"action\" value=\"set_PROPALE_DRAFT_WATERMARK\">";
  438. print '<tr '.$bc[$var].'><td colspan="2">';
  439. print $langs->trans("WatermarkOnDraftProposal").'<br>';
  440. print '<input size="50" class="flat" type="text" name="PROPALE_DRAFT_WATERMARK" value="'.$conf->global->PROPALE_DRAFT_WATERMARK.'">';
  441. print '</td><td align="right">';
  442. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  443. print "</td></tr>\n";
  444. print '</form>';
  445. print '</table>';
  446. /*
  447. * Directory
  448. */
  449. print '<br>';
  450. print_titre($langs->trans("PathToDocuments"));
  451. print "<table class=\"noborder\" width=\"100%\">\n";
  452. print "<tr class=\"liste_titre\">\n";
  453. print " <td>".$langs->trans("Name")."</td>\n";
  454. print " <td>".$langs->trans("Value")."</td>\n";
  455. print "</tr>\n";
  456. print "<tr ".$bc[false].">\n <td width=\"140\">".$langs->trans("PathDirectory")."</td>\n <td>".$conf->propale->dir_output."</td>\n</tr>\n";
  457. print "</table>\n<br>";
  458. $db->close();
  459. llxFooter();
  460. ?>