write_file()   F
last analyzed

Complexity

Conditions 39
Paths > 20000

Size

Total Lines 281
Code Lines 177

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 39
eloc 177
nc 2074901
nop 6
dl 0
loc 281
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/* Copyright (C) 2010-2012  Laurent Destailleur         <[email protected]>
4
 * Copyright (C) 2012		Juanjo Menent		        <[email protected]>
5
 * Copyright (C) 2014		Marcos García		        <[email protected]>
6
 * Copyright (C) 2016		Charlie Benke		        <[email protected]>
7
 * Copyright (C) 2018-2021  Philippe Grand              <[email protected]>
8
 * Copyright (C) 2018-2024  Frédéric France             <[email protected]>
9
 * Copyright (C) 2024		MDW							<[email protected]>
10
 * Copyright (C) 2024       Rafael San José             <[email protected]>
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 3 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24
 * or see https://www.gnu.org/
25
 */
26
27
use Dolibarr\Code\Core\Classes\Form;
28
use Dolibarr\Code\Recruitement\Classes\ModelePDFRecruitmentJobPosition;
29
use Dolibarr\Lib\ViewMain;
30
31
/**
32
 *  \file       htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php
33
 *  \ingroup    recruitment
34
 *  \brief      File of class to build ODT documents for recruitmentjobpositions
35
 */
36
37
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/company.lib.php';
38
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/functions2.lib.php';
39
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php';
40
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/doc.lib.php';
41
42
/**
43
 *  Class to build documents using ODF templates generator
44
 */
45
class doc_generic_recruitmentjobposition_odt extends ModelePDFRecruitmentJobPosition
46
{
47
    /**
48
     * Issuer
49
     * @var Societe
50
     */
51
    public $emetteur;
52
53
    /**
54
     * @var array{0:int,1:int} Minimum version of PHP required by module.
55
     * e.g.: PHP ≥ 7.0 = array(7, 0)
56
     */
57
    public $phpmin = array(7, 0);
58
59
    /**
60
     * @var string Dolibarr version of the loaded document
61
     */
62
    public $version = 'dolibarr';
63
64
65
    /**
66
     *  Constructor
67
     *
68
     *  @param      DoliDB      $db      Database handler
69
     */
70
    public function __construct($db)
71
    {
72
        global $conf, $langs, $mysoc;
73
74
        // Load translation files required by the page
75
        $langs->loadLangs(array("main", "companies"));
76
77
        $this->db = $db;
78
        $this->name = "ODT templates";
79
        $this->description = $langs->trans("DocumentModelOdt");
80
        $this->scandir = 'RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan
81
82
        // Page size for A4 format
83
        $this->type = 'odt';
84
        $this->page_largeur = 0;
85
        $this->page_hauteur = 0;
86
        $this->format = array($this->page_largeur, $this->page_hauteur);
87
        $this->marge_gauche = 0;
88
        $this->marge_droite = 0;
89
        $this->marge_haute = 0;
90
        $this->marge_basse = 0;
91
92
        $this->option_logo = 1; // Display logo
93
        $this->option_tva = 0; // Manage the vat option COMMANDE_TVAOPTION
94
        $this->option_modereg = 0; // Display payment mode
95
        $this->option_condreg = 0; // Display payment terms
96
        $this->option_multilang = 1; // Available in several languages
97
        $this->option_escompte = 0; // Displays if there has been a discount
98
        $this->option_credit_note = 0; // Support credit notes
99
        $this->option_freetext = 1; // Support add of a personalised text
100
        $this->option_draft_watermark = 0; // Support add of a watermark on drafts
101
102
        // Get source company
103
        $this->emetteur = $mysoc;
104
        if (!$this->emetteur->country_code) {
105
            $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
106
        }
107
    }
108
109
110
    /**
111
     *  Return description of a module
112
     *
113
     *  @param  Translate   $langs      Lang object to use for output
114
     *  @return string                  Description
115
     */
116
    public function info($langs)
117
    {
118
        global $conf, $langs;
119
120
        // Load translation files required by the page
121
        $langs->loadLangs(array("errors", "companies"));
122
123
        $form = new Form($this->db);
124
125
        $texte = $this->description . ".<br>\n";
126
        $texte .= '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST" enctype="multipart/form-data">';
127
        $texte .= '<input type="hidden" name="token" value="' . newToken() . '">';
128
        $texte .= '<input type="hidden" name="page_y" value="">';
129
        $texte .= '<input type="hidden" name="action" value="setModuleOptions">';
130
        $texte .= '<input type="hidden" name="param1" value="RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH">';
131
        $texte .= '<table class="nobordernopadding centpercent">';
132
133
        // List of directories area
134
        $texte .= '<tr><td>';
135
        $texttitle = $langs->trans("ListOfDirectories");
136
        $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim(getDolGlobalString('RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH'))));
137
        $listoffiles = array();
138
        foreach ($listofdir as $key => $tmpdir) {
139
            $tmpdir = trim($tmpdir);
140
            $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
141
            if (!$tmpdir) {
142
                unset($listofdir[$key]);
143
                continue;
144
            }
145
            if (!is_dir($tmpdir)) {
146
                $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
147
            } else {
148
                $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
149
                if (count($tmpfiles)) {
150
                    $listoffiles = array_merge($listoffiles, $tmpfiles);
151
                }
152
            }
153
        }
154
        $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT");
155
        // Add list of substitution keys
156
        $texthelp .= '<br>' . $langs->trans("FollowingSubstitutionKeysCanBeUsed") . '<br>';
157
        $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
158
159
        $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
160
        $texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
161
        $texte .= '<textarea class="flat" cols="60" name="value1">';
162
        $texte .= getDolGlobalString('RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH');
163
        $texte .= '</textarea>';
164
        $texte .= '</div><div style="display: inline-block; vertical-align: middle;">';
165
        $texte .= '<input type="submit" class="button small reposition" name="modify" value="' . $langs->trans("Modify") . '">';
166
        $texte .= '<br></div></div>';
167
168
        // Scan directories
169
        $nbofiles = count($listoffiles);
170
        if (getDolGlobalString('RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH')) {
171
            $texte .= $langs->trans("NumberOfModelFilesFound") . ': <b>';
172
            //$texte.=$nbofiles?'<a id="a_'.get_only_class($this).'" href="#">':'';
173
            $texte .= count($listoffiles);
174
            //$texte.=$nbofiles?'</a>':'';
175
            $texte .= '</b>';
176
        }
177
178
        if ($nbofiles) {
179
            $texte .= '<div id="div_' . get_only_class($this) . '" class="hidden">';
180
            foreach ($listoffiles as $file) {
181
                $texte .= '- ' . $file['name'];
182
                //$texte .= ' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=recruitementjobposition/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a>';
183
                //$texte .= ' &nbsp; <a class="reposition" href="'.$_SERVER["PHP_SELF"].'?modulepart=doctemplates&keyforuploaddir=RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH&action=deletefile&token='.newToken().'&file='.urlencode(basename($file['name'])).'">'.img_picto('', 'delete').'</a>';
184
                $texte .= '<br>';
185
            }
186
            $texte .= '</div>';
187
        }
188
        // Add input to upload a new template file.
189
        $texte .= '<div>' . $langs->trans("UploadNewTemplate");
190
        $maxfilesizearray = getMaxFileSizeArray();
191
        $maxmin = $maxfilesizearray['maxmin'];
192
        if ($maxmin > 0) {
193
            $texte .= '<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) . '">';    // MAX_FILE_SIZE must precede the field type=file
194
        }
195
        $texte .= ' <input type="file" name="uploadfile">';
196
        $texte .= '<input type="hidden" value="RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
197
        $texte .= '<input type="submit" class="button smallpaddingimp reposition" value="' . dol_escape_htmltag($langs->trans("Upload")) . '" name="upload">';
198
        $texte .= '</div>';
199
        $texte .= '</td>';
200
201
        $texte .= '<td rowspan="2" class="tdtop hideonsmartphone">';
202
        $texte .= '<span class="opacitymedium">';
203
        $texte .= $langs->trans("ExampleOfDirectoriesForModelGen");
204
        $texte .= '</span>';
205
        $texte .= '</td>';
206
        $texte .= '</tr>';
207
208
        $texte .= '</table>';
209
        $texte .= '</form>';
210
211
        return $texte;
212
    }
213
214
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
215
    /**
216
     *  Function to build a document on disk using the generic odt module.
217
     *
218
     *  @param      RecruitmentJobPosition  $object             Object source to build document
219
     *  @param      Translate   $outputlangs        Lang output object
220
     *  @param      string      $srctemplatepath    Full path of source filename for generator using a template file
221
     *  @param      int         $hidedetails        Do not show line details
222
     *  @param      int         $hidedesc           Do not show desc
223
     *  @param      int         $hideref            Do not show ref
224
     *  @return     int                             1 if OK, <=0 if KO
225
     */
226
    public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
227
    {
228
		// phpcs:enable
229
        global $user, $langs, $conf, $mysoc, $hookmanager;
230
        global $action;
231
232
        if (empty($srctemplatepath)) {
233
            dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
234
            return -1;
235
        }
236
237
        // Add odtgeneration hook
238
        $hookmanager->initHooks(array('odtgeneration'));
239
240
        if (!is_object($outputlangs)) {
241
            $outputlangs = $langs;
242
        }
243
        $sav_charset_output = $outputlangs->charset_output;
244
        $outputlangs->charset_output = 'UTF-8';
245
246
        $outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
247
248
        if ($conf->recruitment->dir_output) {
249
            // If $object is id instead of object
250
            if (!is_object($object)) {
251
                $id = $object;
252
                $object = new RecruitmentJobPosition($this->db);
253
                $result = $object->fetch($id);
254
                if ($result < 0) {
255
                    dol_print_error($this->db, $object->error);
256
                    return -1;
257
                }
258
            }
259
260
            $dir = $conf->recruitment->multidir_output[isset($object->entity) ? $object->entity : 1] . '/recruitmentjobposition/';
261
            $objectref = dol_sanitizeFileName($object->ref);
262
            if (!preg_match('/specimen/i', $objectref)) {
263
                $dir .= "/" . $objectref;
264
            }
265
            $file = $dir . "/" . $objectref . ".odt";
266
267
            if (!file_exists($dir)) {
268
                if (dol_mkdir($dir) < 0) {
269
                    $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
270
                    return -1;
271
                }
272
            }
273
274
            if (file_exists($dir)) {
275
                //print "srctemplatepath=".$srctemplatepath;    // Src filename
276
                $newfile = basename($srctemplatepath);
277
                $newfiletmp = preg_replace('/\.od[ts]/i', '', $newfile);
278
                $newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
279
                $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
280
                $newfiletmp = $objectref . '_' . $newfiletmp;
281
                //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
282
                // Get extension (ods or odt)
283
                $newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
284
                if (getDolGlobalString('MAIN_DOC_USE_TIMING')) {
285
                    $format = getDolGlobalString('MAIN_DOC_USE_TIMING');
286
                    if ($format == '1') {
287
                        $format = '%Y%m%d%H%M%S';
288
                    }
289
                    $filename = $newfiletmp . '-' . dol_print_date(dol_now(), $format) . '.' . $newfileformat;
290
                } else {
291
                    $filename = $newfiletmp . '.' . $newfileformat;
292
                }
293
                $file = $dir . '/' . $filename;
294
                //print "newdir=".$dir;
295
                //print "newfile=".$newfile;
296
                //print "file=".$file;
297
                //print "conf->societe->dir_temp=".$conf->societe->dir_temp;
298
299
                dol_mkdir($conf->recruitment->dir_temp);
300
                if (!is_writable($conf->recruitment->dir_temp)) {
301
                    $this->error = $langs->transnoentities("ErrorFailedToWriteInTempDirectory", $conf->recruitment->dir_temp);
302
                    dol_syslog('Error in write_file: ' . $this->error, LOG_ERR);
303
                    return -1;
304
                }
305
306
                // If CUSTOMER contact defined on order, we use it
307
                $usecontact = false;
308
                $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
309
                if (count($arrayidcontact) > 0) {
310
                    $usecontact = true;
311
                    $result = $object->fetch_contact($arrayidcontact[0]);
312
                }
313
314
                // Recipient name
315
                $contactobject = null;
316
                if (!empty($usecontact)) {
317
                    // We can use the company of contact instead of thirdparty company
318
                    if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
319
                        $object->contact->fetch_thirdparty();
320
                        $socobject = $object->contact->thirdparty;
321
                        $contactobject = $object->contact;
322
                    } else {
323
                        $socobject = $object->thirdparty;
324
                        // if we have a CUSTOMER contact and we don't use it as thirdparty recipient we store the contact object for later use
325
                        $contactobject = $object->contact;
326
                    }
327
                } else {
328
                    $socobject = $object->thirdparty;
329
                }
330
331
                // Make substitution
332
                $substitutionarray = array(
333
                    '__FROM_NAME__' => $this->emetteur->name,
334
                    '__FROM_EMAIL__' => $this->emetteur->email,
335
                    '__TOTAL_TTC__' => $object->total_ttc,
336
                    '__TOTAL_HT__' => $object->total_ht,
337
                    '__TOTAL_VAT__' => $object->total_tva
338
                );
339
                complete_substitutions_array($substitutionarray, $langs, $object);
340
                // Call the ODTSubstitution hook
341
                $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$substitutionarray);
342
                $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
343
344
                // Line of free text
345
                $newfreetext = '';
346
                $paramfreetext = 'ORDER_FREE_TEXT';
347
                if (getDolGlobalString($paramfreetext)) {
348
                    $newfreetext = make_substitutions(getDolGlobalString($paramfreetext), $substitutionarray);
349
                }
350
351
                // Open and load template
352
                require_once ODTPHP_PATH . 'odf.php';
353
                try {
354
                    $odfHandler = new Odf(
355
                        $srctemplatepath,
356
                        array(
357
                            'PATH_TO_TMP'     => $conf->recruitment->dir_temp,
358
                            'ZIP_PROXY'       => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
359
                            'DELIMITER_LEFT'  => '{',
360
                            'DELIMITER_RIGHT' => '}'
361
                        )
362
                    );
363
                } catch (Exception $e) {
364
                    $this->error = $e->getMessage();
365
                    dol_syslog($e->getMessage(), LOG_INFO);
366
                    return -1;
367
                }
368
                // After construction $odfHandler->contentXml contains content and
369
                // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
370
                // [!-- BEGIN lines --]*[!-- END lines --]
371
                //print html_entity_decode($odfHandler->__toString());
372
                //print exit;
373
374
375
                // Make substitutions into odt of freetext
376
                try {
377
                    $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
378
                } catch (OdfException $e) {
379
                    dol_syslog($e->getMessage(), LOG_INFO);
380
                }
381
382
                // Define substitution array
383
                $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
384
                $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs);
385
                $array_objet = $this->get_substitutionarray_object($object, $outputlangs);
386
                $array_user = $this->get_substitutionarray_user($user, $outputlangs);
387
                $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
388
                $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
389
                $array_other = $this->get_substitutionarray_other($outputlangs);
390
                // retrieve contact information for use in object as contact_xxx tags
391
                $array_thirdparty_contact = array();
392
                if ($usecontact && is_object($contactobject)) {
393
                    $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact');
394
                }
395
396
                $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact);
397
                complete_substitutions_array($tmparray, $outputlangs, $object);
398
399
                // Call the ODTSubstitution hook
400
                $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
401
                $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
402
403
                foreach ($tmparray as $key => $value) {
404
                    try {
405
                        if (preg_match('/logo$/', $key)) {
406
                            // Image
407
                            if (file_exists($value)) {
408
                                $odfHandler->setImage($key, $value);
409
                            } else {
410
                                $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
411
                            }
412
                        } else {
413
                            // Text
414
                            $odfHandler->setVars($key, $value, true, 'UTF-8');
415
                        }
416
                    } catch (OdfException $e) {
417
                        dol_syslog($e->getMessage(), LOG_INFO);
418
                    }
419
                }
420
                // Replace tags of lines
421
                $foundtagforlines = 1;
422
                try {
423
                    $listlines = $odfHandler->setSegment('lines');
424
                } catch (OdfExceptionSegmentNotFound $e) {
425
                    // We may arrive here if tags for lines not present into template
426
                    $foundtagforlines = 0;
427
                    dol_syslog($e->getMessage(), LOG_INFO);
428
                }
429
                if ($foundtagforlines) {
430
                    $linenumber = 0;
431
                    foreach ($object->lines as $line) {
432
                        $linenumber++;
433
                        $tmparray = $this->get_substitutionarray_lines($line, $outputlangs, $linenumber);
434
                        complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
435
                        // Call the ODTSubstitutionLine hook
436
                        $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray, 'line' => $line);
437
                        $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
438
                        foreach ($tmparray as $key => $val) {
439
                            try {
440
                                $listlines->setVars($key, $val, true, 'UTF-8');
441
                            } catch (SegmentException $e) {
442
                                dol_syslog($e->getMessage(), LOG_INFO);
443
                            }
444
                        }
445
                        $listlines->merge();
446
                    }
447
                    try {
448
                        $odfHandler->mergeSegment($listlines);
449
                    } catch (OdfException $e) {
450
                        $this->error = $e->getMessage();
451
                        dol_syslog($this->error, LOG_WARNING);
452
                        return -1;
453
                    }
454
                }
455
456
                // Replace labels translated
457
                $tmparray = $outputlangs->get_translations_for_substitutions();
458
                foreach ($tmparray as $key => $value) {
459
                    try {
460
                        $odfHandler->setVars($key, $value, true, 'UTF-8');
461
                    } catch (OdfException $e) {
462
                        dol_syslog($e->getMessage(), LOG_INFO);
463
                    }
464
                }
465
466
                // Call the beforeODTSave hook
467
468
                $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
469
                $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
470
471
                // Write new file
472
                if (getDolGlobalString('MAIN_ODT_AS_PDF')) {
473
                    try {
474
                        $odfHandler->exportAsAttachedPDF($file);
475
                    } catch (Exception $e) {
476
                        $this->error = $e->getMessage();
477
                        dol_syslog($e->getMessage(), LOG_INFO);
478
                        return -1;
479
                    }
480
                } else {
481
                    try {
482
                        $odfHandler->saveToDisk($file);
483
                    } catch (Exception $e) {
484
                        $this->error = $e->getMessage();
485
                        dol_syslog($e->getMessage(), LOG_INFO);
486
                        return -1;
487
                    }
488
                }
489
490
                $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
491
                $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
492
493
                dolChmod($file);
494
495
                $odfHandler = null; // Destroy object
496
497
                $this->result = array('fullpath' => $file);
498
499
                return 1; // Success
500
            } else {
501
                $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
502
                return -1;
503
            }
504
        }
505
506
        return -1;
507
    }
508
}
509