dolibarr  9.0.0
contract.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
3  * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("admin","errors","contracts"));
33 
34 if (!$user->admin) accessforbidden();
35 
36 $action = GETPOST('action','alpha');
37 $value = GETPOST('value','alpha');
38 $label = GETPOST('label','alpha');
39 $scandir = GETPOST('scan_dir','alpha');
40 $type='contract';
41 
42 if (empty($conf->global->CONTRACT_ADDON))
43 {
44  $conf->global->CONTRACT_ADDON='mod_contract_serpis';
45 }
46 
47 
48 /*
49  * Actions
50  */
51 
52 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
53 
54 if ($action == 'updateMask')
55 {
56  $maskconst = GETPOST('maskconstcontract','alpha');
57  $maskvalue = GETPOST('maskcontract','alpha');
58  if ($maskconst) $res = dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity);
59 
60  if (! $res > 0) $error++;
61 
62  if (! $error)
63  {
64  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
65  }
66  else
67  {
68  setEventMessages($langs->trans("Error"), null, 'errors');
69  }
70 }
71 
72 else if ($action == 'specimen') // For contract
73 {
74  $modele= GETPOST('module','alpha');
75 
76  $contract = new Contrat($db);
77  $contract->initAsSpecimen();
78 
79  // Search template files
80  $file=''; $classname=''; $filefound=0;
81  $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
82  foreach($dirmodels as $reldir)
83  {
84  $file=dol_buildpath($reldir."core/modules/contract/doc/pdf_".$modele.".modules.php",0);
85  if (file_exists($file))
86  {
87  $filefound=1;
88  $classname = "pdf_".$modele;
89  break;
90  }
91  }
92 
93  if ($filefound)
94  {
95  require_once $file;
96 
97  $module = new $classname($db);
98 
99  if ($module->write_file($contract,$langs) > 0)
100  {
101  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=contract&file=SPECIMEN.pdf");
102  return;
103  }
104  else
105  {
106  setEventMessages($obj->error, $obj->errors, 'errors');
107  dol_syslog($obj->error, LOG_ERR);
108  }
109  }
110  else
111  {
112  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
113  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
114  }
115 }
116 
117 // Activate a model
118 else if ($action == 'set')
119 {
120  $ret = addDocumentModel($value, $type, $label, $scandir);
121 }
122 
123 else if ($action == 'del')
124 {
125  $ret = delDocumentModel($value, $type);
126  if ($ret > 0)
127  {
128  if ($conf->global->CONTRACT_ADDON_PDF == "$value") dolibarr_del_const($db, 'CONTRACT_ADDON_PDF',$conf->entity);
129  }
130 }
131 
132 // Set default model
133 else if ($action == 'setdoc')
134 {
135  if (dolibarr_set_const($db, "CONTRACT_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
136  {
137  // La constante qui a ete lue en avant du nouveau set
138  // on passe donc par une variable pour avoir un affichage coherent
139  $conf->global->CONTRACT_ADDON_PDF = $value;
140  }
141 
142  // On active le modele
143  $ret = delDocumentModel($value, $type);
144  if ($ret > 0)
145  {
146  $ret = addDocumentModel($value, $type, $label, $scandir);
147  }
148 }
149 
150 else if ($action == 'setmod')
151 {
152  // TODO Verifier si module numerotation choisi peut etre active
153  // par appel methode canBeActivated
154 
155  dolibarr_set_const($db, "CONTRACT_ADDON",$value,'chaine',0,'',$conf->entity);
156 }
157 
158 else if ($action == 'set_other')
159 {
160  $freetext= GETPOST('CONTRACT_FREE_TEXT','none'); // No alpha here, we want exact string
161  $res1 = dolibarr_set_const($db, "CONTRACT_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity);
162 
163  $draft= GETPOST('CONTRACT_DRAFT_WATERMARK','alpha');
164  $res2 = dolibarr_set_const($db, "CONTRACT_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity);
165 
166  if (! $res1 > 0 || ! $res2 > 0) $error++;
167 
168  if (! $error)
169  {
170  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
171  }
172  else
173  {
174  setEventMessages($langs->trans("Error"), null, 'errors');
175  }
176 }
177 
178 
179 /*
180  * View
181  */
182 
183 $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
184 
185 llxHeader();
186 
187 $form=new Form($db);
188 
189 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
190 print load_fiche_titre($langs->trans("ContractsSetup"),$linkback,'title_setup');
191 
193 
194 dol_fiche_head($head, 'contract', $langs->trans("Contracts"), -1, 'contract');
195 
196 /*
197  * Contracts Numbering model
198  */
199 
200 print load_fiche_titre($langs->trans("ContractsNumberingModules"),'','');
201 
202 print '<table class="noborder" width="100%">';
203 print '<tr class="liste_titre">';
204 print '<td width="100">'.$langs->trans("Name").'</td>';
205 print '<td>'.$langs->trans("Description").'</td>';
206 print '<td>'.$langs->trans("Example").'</td>';
207 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
208 print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
209 print "</tr>\n";
210 
211 clearstatcache();
212 
213 foreach ($dirmodels as $reldir)
214 {
215  $dir = dol_buildpath($reldir."core/modules/contract/");
216 
217  if (is_dir($dir))
218  {
219  $handle = opendir($dir);
220  if (is_resource($handle))
221  {
222 
223  while (($file = readdir($handle))!==false)
224  {
225  if (substr($file, 0, 13) == 'mod_contract_' && substr($file, dol_strlen($file)-3, 3) == 'php')
226  {
227  $file = substr($file, 0, dol_strlen($file)-4);
228 
229  require_once $dir.$file.'.php';
230 
231  $module = new $file($db);
232 
233  // Show modules according to features level
234  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
235  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
236 
237  if ($module->isEnabled())
238  {
239 
240  print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
241  print $module->info();
242  print '</td>';
243 
244  // Show example of numbering model
245  print '<td class="nowrap">';
246  $tmp=$module->getExample();
247  if (preg_match('/^Error/',$tmp)) { $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>'; }
248  elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
249  else print $tmp;
250  print '</td>'."\n";
251 
252  print '<td align="center">';
253  if ($conf->global->CONTRACT_ADDON == "$file")
254  {
255  print img_picto($langs->trans("Activated"),'switch_on');
256  }
257  else
258  {
259  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'">';
260  print img_picto($langs->trans("Disabled"),'switch_off');
261  print '</a>';
262  }
263  print '</td>';
264 
265  $contract=new Contrat($db);
266  $contract->initAsSpecimen();
267 
268  // Info
269  $htmltooltip='';
270  $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
271  $nextval=$module->getNextValue($mysoc,$contract);
272  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
273  $htmltooltip.=''.$langs->trans("NextValue").': ';
274  if ($nextval) {
275  if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
276  $nextval = $langs->trans($nextval);
277  $htmltooltip.=$nextval.'<br>';
278  } else {
279  $htmltooltip.=$langs->trans($module->error).'<br>';
280  }
281  }
282 
283  print '<td align="center">';
284  print $form->textwithpicto('',$htmltooltip,1,0);
285  print '</td>';
286 
287  print '</tr>';
288  }
289  }
290  }
291  closedir($handle);
292  }
293  }
294 }
295 
296 print '</table><br>';
297 
298 /*
299  * Documents models for Contracts
300  */
301 
302 print load_fiche_titre($langs->trans("TemplatePDFContracts"),'','');
303 
304 // Defini tableau def des modeles
305 $def = array();
306 $sql = "SELECT nom";
307 $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
308 $sql.= " WHERE type = '".$type."'";
309 $sql.= " AND entity = ".$conf->entity;
310 $resql=$db->query($sql);
311 if ($resql)
312 {
313  $i = 0;
314  $num_rows=$db->num_rows($resql);
315  while ($i < $num_rows)
316  {
317  $array = $db->fetch_array($resql);
318  array_push($def, $array[0]);
319  $i++;
320  }
321 }
322 else
323 {
324  dol_print_error($db);
325 }
326 
327 
328 print '<table class="noborder" width="100%">';
329 print '<tr class="liste_titre">';
330 print '<td>'.$langs->trans("Name").'</td>';
331 print '<td>'.$langs->trans("Description").'</td>';
332 print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
333 print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
334 print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
335 print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
336 print "</tr>\n";
337 
338 clearstatcache();
339 
340 foreach ($dirmodels as $reldir)
341 {
342  foreach (array('','/doc') as $valdir)
343  {
344  $dir = dol_buildpath($reldir."core/modules/contract".$valdir);
345 
346  if (is_dir($dir))
347  {
348  $handle=opendir($dir);
349  if (is_resource($handle))
350  {
351  while (($file = readdir($handle))!==false)
352  {
353  $filelist[]=$file;
354  }
355  closedir($handle);
356  arsort($filelist);
357 
358  foreach($filelist as $file)
359  {
360  if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
361  {
362 
363  if (file_exists($dir.'/'.$file))
364  {
365  $name = substr($file, 4, dol_strlen($file) -16);
366  $classname = substr($file, 0, dol_strlen($file) -12);
367 
368  require_once $dir.'/'.$file;
369  $module = new $classname($db);
370 
371  $modulequalified=1;
372  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
373  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
374 
375  if ($modulequalified)
376  {
377  print '<tr class="oddeven"><td width="100">';
378  print (empty($module->name)?$name:$module->name);
379  print "</td><td>\n";
380  if (method_exists($module,'info')) print $module->info($langs);
381  else print $module->description;
382  print '</td>';
383 
384  // Active
385  if (in_array($name, $def))
386  {
387  print '<td align="center">'."\n";
388  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
389  print img_picto($langs->trans("Enabled"),'switch_on');
390  print '</a>';
391  print '</td>';
392  }
393  else
394  {
395  print '<td align="center">'."\n";
396  print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
397  print "</td>";
398  }
399 
400  // Defaut
401  print '<td align="center">';
402  if ($conf->global->CONTRACT_ADDON_PDF == $name)
403  {
404  print img_picto($langs->trans("Default"),'on');
405  }
406  else
407  {
408  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
409  }
410  print '</td>';
411 
412  // Info
413  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
414  $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
415  if ($module->type == 'pdf')
416  {
417  $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
418  }
419  $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
420  $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
421  $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
422  $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
423  $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
424  $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
425 
426 
427  print '<td align="center">';
428  print $form->textwithpicto('',$htmltooltip,1,0);
429  print '</td>';
430 
431  // Preview
432  print '<td align="center">';
433  if ($module->type == 'pdf')
434  {
435  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'contract').'</a>';
436  }
437  else
438  {
439  print img_object($langs->trans("PreviewNotAvailable"),'generic');
440  }
441  print '</td>';
442 
443  print "</tr>\n";
444  }
445  }
446  }
447  }
448  }
449  }
450  }
451 }
452 
453 print '</table>';
454 print "<br>";
455 
456 /*
457  * Other options
458  *
459  */
460 
461 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
462 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
463 print '<input type="hidden" name="action" value="set_other">';
464 
465 print load_fiche_titre($langs->trans("OtherOptions"),'','');
466 print '<table class="noborder" width="100%">';
467 print '<tr class="liste_titre">';
468 print '<td>'.$langs->trans("Parameter").'</td>';
469 print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
470 print "</tr>\n";
471 
472 $substitutionarray=pdf_getSubstitutionArray($langs, array('objectamount'), null, 2);
473 $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
474 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
475 foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
476 $htmltext.='</i>';
477 
478 print '<tr class="oddeven"><td colspan="2">';
479 print $form->textwithpicto($langs->trans("FreeLegalTextOnContracts"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'tooltiphelp');
480 print '<br>';
481 $variablename='CONTRACT_FREE_TEXT';
482 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
483 {
484  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
485 }
486 else
487 {
488  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
489  $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_notes');
490  print $doleditor->Create();
491 }
492 print '</td></tr>'."\n";
493 
494 //Use draft Watermark
495 
496 print '<tr class="oddeven"><td>';
497 print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
498 print '</td><td>';
499 print '<input size="50" class="flat" type="text" name="CONTRACT_DRAFT_WATERMARK" value="'.$conf->global->CONTRACT_DRAFT_WATERMARK.'">';
500 print '</td></tr>'."\n";
501 
502 print '</table>';
503 
504 print '<div class="center">';
505 print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
506 print '</div>';
507 
508 print '</form>';
509 
510 dol_fiche_end();
511 
512 // End of page
513 llxFooter();
514 $db->close();
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1643
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
contract_admin_prepare_head()
Return array head with list of tabs to view object informations.
Class to manage contracts.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:510
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1609
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
if(! GETPOST('transkey', 'alphanohtml') &&! GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:43
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:435
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:623
Class to manage a WYSIWYG editor.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)