205 public function write_file($object, $outputlangs, $srctemplatepath, $mode =
'member', $nooutput = 0, $filename =
'tmp_cards')
208 global $user, $langs, $conf, $mysoc, $hookmanager;
210 if (empty($srctemplatepath)) {
211 dol_syslog(
"doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
216 if (!is_object($hookmanager)) {
217 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
220 $hookmanager->initHooks(array(
'odtgeneration'));
223 if (!is_object($outputlangs)) {
224 $outputlangs = $langs;
226 $sav_charset_output = $outputlangs->charset_output;
227 $outputlangs->charset_output =
'UTF-8';
230 $outputlangs->loadLangs(array(
"main",
"companies",
"bills",
"dict"));
232 if ($conf->adherent->dir_output) {
234 if (!is_object($object)) {
236 $object =
new User($this->db);
237 $result = $object->fetch($id);
244 $object->fetch_thirdparty();
246 $dir = $conf->adherent->dir_output;
248 if (!preg_match(
'/specimen/i', $objectref)) {
249 $dir .=
"/".$objectref;
251 $file = $dir.
"/".$objectref.
".odt";
253 if (!file_exists($dir)) {
255 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
260 if (file_exists($dir)) {
262 $newfile = basename($srctemplatepath);
263 $newfiletmp = preg_replace(
'/\.od[ts]/i',
'', $newfile);
264 $newfiletmp = preg_replace(
'/template_/i',
'', $newfiletmp);
265 $newfiletmp = preg_replace(
'/modele_/i',
'', $newfiletmp);
267 $newfiletmp = $objectref .
'_' . $newfiletmp;
270 $newfileformat = substr($newfile, strrpos($newfile,
'.') + 1);
273 if ($format ==
'1') {
274 $format =
'%Y%m%d%H%M%S';
278 $filename = $newfiletmp .
'.' . $newfileformat;
280 $file = $dir .
'/' . $filename;
287 if (!is_writable($conf->adherent->dir_temp)) {
288 $this->error = $langs->transnoentities(
"ErrorFailedToWriteInTempDirectory", $conf->adherent->dir_temp);
289 dol_syslog(
'Error in write_file: ' . $this->error, LOG_ERR);
295 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
296 if (count($arrayidcontact) > 0) {
298 $result = $object->fetch_contact($arrayidcontact[0]);
302 if (!empty($usecontact)) {
304 if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))) {
305 $object->contact->fetch_thirdparty();
306 $socobject = $object->contact->thirdparty;
307 $contactobject = $object->contact;
309 $socobject = $object->thirdparty;
311 $contactobject = $object->contact;
314 $socobject = $object->thirdparty;
318 require_once ODTPHP_PATH.
'odf.php';
320 $odfHandler =
new Odf(
323 'PATH_TO_TMP' => $conf->adherent->dir_temp,
324 'ZIP_PROXY' =>
'PclZipProxy',
325 'DELIMITER_LEFT' =>
'{',
326 'DELIMITER_RIGHT' =>
'}'
330 $this->error = $e->getMessage();
341 $array_thirdparty_contact = array();
342 if ($usecontact && is_object($contactobject)) {
346 $tmparray = array_merge($array_member, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
352 'outputlangs'=>$outputlangs,
353 'substitutionarray'=>&$tmparray
355 $reshook = $hookmanager->executeHooks(
'ODTSubstitution', $parameters, $this, $action);
356 foreach ($tmparray as $key => $value) {
358 if (preg_match(
'/logo$/', $key)) {
360 if (file_exists($value)) {
361 $odfHandler->setImage($key, $value);
363 $odfHandler->setVars($key,
'ErrorFileNotFound',
true,
'UTF-8');
367 $odfHandler->setVars($key, $value,
true,
'UTF-8');
369 }
catch (OdfException $e) {
375 $tmparray = $outputlangs->get_translations_for_substitutions();
376 foreach ($tmparray as $key => $value) {
378 $odfHandler->setVars($key, $value,
true,
'UTF-8');
379 }
catch (OdfException $e) {
385 $parameters = array(
'odfHandler'=>&$odfHandler,
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
386 $reshook = $hookmanager->executeHooks(
'beforeODTSave', $parameters, $this, $action);
389 if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
391 $odfHandler->exportAsAttachedPDF($file);
393 $this->error = $e->getMessage();
399 $odfHandler->saveToDisk($file);
401 $this->error = $e->getMessage();
407 $reshook = $hookmanager->executeHooks(
'afterODTCreation', $parameters, $this, $action);
413 $this->result = array(
'fullpath'=>$file);
417 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);