/** * Show only Document icon with link * * @param string $modulepart propal, facture, facture_fourn, ... * @param string $modulesubdir Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. * @param string $filedir Directory to scan * @return string Output string with HTML link of documents (might be empty string) */ function getDocumentsLink($modulepart, $modulesubdir, $filedir) { if (!function_exists('dol_dir_list')) { include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; } $out = ''; $this->numoffiles = 0; $file_list = dol_dir_list($filedir, 'files', 0, preg_quote($modulesubdir . '.pdf', '/'), '\\.meta$|\\.png$'); // For ajax treatment $out .= '<div id="gen_pdf_' . $modulesubdir . '" class="linkobject hideobject">' . img_picto('', 'refresh') . '</div>' . "\n"; if (!empty($file_list)) { // Loop on each file found foreach ($file_list as $file) { // Define relative path for download link (depends on module) $relativepath = $file["name"]; // Cas general if ($modulesubdir) { $relativepath = $modulesubdir . "/" . $file["name"]; } // Cas propal, facture... // Autre cas if ($modulepart == 'donation') { $relativepath = get_exdir($modulesubdir, 2) . $file["name"]; } if ($modulepart == 'export') { $relativepath = $file["name"]; } // Show file name with link to download $out .= '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&file=' . urlencode($relativepath) . '"'; $mime = dol_mimetype($relativepath, '', 0); if (preg_match('/text/', $mime)) { $out .= ' target="_blank"'; } $out .= '>'; $out .= img_pdf($file["name"], 2); $out .= '</a>' . "\n"; $this->numoffiles++; } } return $out; }
/** * Show MIME img of a file * @param file Filename * @param alt Alternate text to show on img mous hover * @return string Return img tag */ function img_mime($file, $alt = '') { require_once DOL_DOCUMENT_ROOT . '/lib/files.lib.php'; $mimetype = dol_mimetype($file, '', 1); $mimeimg = dol_mimetype($file, '', 2); if (empty($alt)) { $alt = 'Mime type: ' . $mimetype; } return '<img src="' . DOL_URL_ROOT . '/theme/common/mime/' . $mimeimg . '" border="0" alt="' . $alt . '" title="' . $alt . '">'; }
/** * Check if notification are active for couple action/company. * If yes, send mail and save trace into llx_notify. * * @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage) * @param Object $object Object the notification deals on * @return int <0 if KO, or number of changes if OK */ function send($notifcode, $object) { global $user, $conf, $langs, $mysoc, $dolibarr_main_url_root; include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; dol_syslog(get_class($this) . "::send notifcode=" . $notifcode . ", object=" . $object->id); $langs->load("other"); // Define $urlwithroot $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($dolibarr_main_url_root)); $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT; // This is to use external domain name found into config file //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current // Define some vars $application = $mysoc->name; //if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE; $replyto = $conf->notification->email_from; $filename = basename($file); $mimefile = dol_mimetype($file); $object_type = ''; $link = ''; $num = 0; if (!in_array($notifcode, array('BILL_VALIDATE', 'ORDER_VALIDATE', 'PROPAL_VALIDATE', 'FICHINTER_VALIDATE', 'ORDER_SUPPLIER_VALIDATE', 'ORDER_SUPPLIER_APPROVE', 'ORDER_SUPPLIER_REFUSE', 'SHIPPING_VALIDATE'))) { return 0; } $oldref = empty($object->oldref) ? $object->ref : $object->oldref; $newref = empty($object->newref) ? $object->ref : $object->newref; // Check notification per third party $sql = "SELECT s.nom, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,"; $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as c,"; $sql .= " " . MAIN_DB_PREFIX . "c_action_trigger as a,"; $sql .= " " . MAIN_DB_PREFIX . "notify_def as n,"; $sql .= " " . MAIN_DB_PREFIX . "societe as s"; $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; $sql .= " AND n.fk_soc = s.rowid"; if (is_numeric($notifcode)) { $sql .= " AND n.fk_action = " . $notifcode; } else { $sql .= " AND a.code = '" . $notifcode . "'"; } // New usage $sql .= " AND s.rowid = " . $object->socid; $result = $this->db->query($sql); if ($result) { $num = $this->db->num_rows($result); if ($num > 0) { $i = 0; while ($i < $num && !$error) { $obj = $this->db->fetch_object($result); $sendto = dolGetFirstLastname($obj->firstname, $obj->lastname) . " <" . $obj->email . ">"; $notifcodedefid = $obj->adid; if (dol_strlen($obj->email)) { // Set output language $outputlangs = $langs; if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) { $outputlangs = new Translate('', $conf); $outputlangs->setDefaultLang($obj->default_lang); } switch ($notifcode) { case 'BILL_VALIDATE': $link = '/compta/facture.php?facid=' . $object->id; $dir_output = $conf->facture->dir_output; $object_type = 'facture'; $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $newref); break; case 'ORDER_VALIDATE': $link = '/commande/card.php?id=' . $object->id; $dir_output = $conf->commande->dir_output; $object_type = 'order'; $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $newref); break; case 'PROPAL_VALIDATE': $link = '/comm/propal.php?id=' . $object->id; $dir_output = $conf->propal->dir_output; $object_type = 'propal'; $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $newref); break; case 'FICHINTER_VALIDATE': $link = '/fichinter/card.php?id=' . $object->id; $dir_output = $conf->facture->dir_output; $object_type = 'ficheinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $object->ref); break; case 'ORDER_SUPPLIER_VALIDATE': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $object->ref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'ORDER_SUPPLIER_APPROVE': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'ORDER_SUPPLIER_REFUSE': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $newref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'SHIPPING_VALIDATE': $dir_output = $conf->expedition->dir_output . '/sending/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $newref); break; } $ref = dol_sanitizeFileName($newref); $pdf_path = $dir_output . "/" . $ref . "/" . $ref . ".pdf"; if (!dol_is_file($pdf_path)) { // We can't add PDF as it is not generated yet. $filepdf = ''; } else { $filepdf = $pdf_path; } $subject = '[' . $application . '] ' . $outputlangs->transnoentitiesnoconv("DolibarrNotification"); $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name) . "\n"; $message .= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n"; $message .= "\n"; $message .= $mesg; if ($link) { $message = dol_concatdesc($message, $urlwithroot . $link); } $mailfile = new CMailFile($subject, $sendto, $replyto, $message, array($file), array($mimefile), array($filename[count($filename) - 1]), '', '', 0, -1); if ($mailfile->sendfile()) { $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)"; $sql .= " VALUES ('" . $this->db->idate(dol_now()) . "', " . $notifcodedefid . ", " . $object->socid . ", " . $obj->cid . ", '" . $obj->type . "', '" . $object_type . "', " . $object->id . ", '" . $this->db->escape($obj->email) . "')"; if (!$this->db->query($sql)) { dol_print_error($this->db); } } else { $error++; $this->errors[] = $mailfile->error; } } else { dol_syslog("No notification sent for " . $sendto . " because email is empty"); } $i++; } } else { dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = " . $object->socid); } } else { $error++; $this->errors[] = $this->db->lasterror(); return -1; } // Check notification using fixed email if (!$error) { foreach ($conf->global as $key => $val) { if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_' . $notifcode . '_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) { continue; } $threshold = (double) $reg[1]; if ($object->total_ht <= $threshold) { dol_syslog("A notification is requested for notifcode = " . $notifcode . " but amount = " . $object->total_ht . " so lower than threshold = " . $threshold . ". We discard this notification"); continue; } $param = 'NOTIFICATION_FIXEDEMAIL_' . $notifcode . '_THRESHOLD_HIGHER_' . $reg[1]; $sendto = $conf->global->{$param}; $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid'); if ($notifcodedefid <= 0) { dol_print_error($this->db, 'Failed to get id from code'); } $object_type = ''; $link = ''; $num++; switch ($notifcode) { case 'BILL_VALIDATE': $link = '/compta/facture.php?facid=' . $object->id; $dir_output = $conf->facture->dir_output; $object_type = 'facture'; $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $newref); break; case 'ORDER_VALIDATE': $link = '/commande/card.php?id=' . $object->id; $dir_output = $conf->commande->dir_output; $object_type = 'order'; $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $newref); break; case 'PROPAL_VALIDATE': $link = '/comm/propal.php?id=' . $object->id; $dir_output = $conf->propal->dir_output; $object_type = 'propal'; $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $newref); break; case 'FICHINTER_VALIDATE': $link = '/fichinter/card.php?id=' . $object->id; $dir_output = $conf->facture->dir_output; $object_type = 'ficheinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $newref); break; case 'ORDER_SUPPLIER_VALIDATE': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $newref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'ORDER_SUPPLIER_APPROVE': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'ORDER_SUPPLIER_APPROVE2': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'ORDER_SUPPLIER_REFUSE': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $newref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'SHIPPING_VALIDATE': $dir_output = $conf->expedition->dir_output . '/sending/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $newref); break; } $ref = dol_sanitizeFileName($newref); $pdf_path = $dir_output . "/" . $ref . "/" . $ref . ".pdf"; if (!dol_is_file($pdf_path)) { // We can't add PDF as it is not generated yet. $filepdf = ''; } else { $filepdf = $pdf_path; } $subject = '[' . $application . '] ' . $langs->transnoentitiesnoconv("DolibarrNotification"); $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name) . "\n"; $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n"; $message .= "\n"; $message .= $mesg; if ($link) { $message = dol_concatdesc($message, $urlwithroot . $link); } // Replace keyword __SUPERVISOREMAIL__ if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) { $newval = ''; if ($user->fk_user > 0) { $supervisoruser = new User($this->db); $supervisoruser->fetch($user->fk_user); if ($supervisoruser->email) { $newval = trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname) . ' <' . $supervisoruser->email . '>'); } } dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with " . $newval); $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto); $sendto = preg_replace('/^[\\s,]+/', '', $sendto); // Clean start of string $sendto = preg_replace('/[\\s,]+$/', '', $sendto); // Clean end of string } if ($sendto) { $mailfile = new CMailFile($subject, $sendto, $replyto, $message, array($file), array($mimefile), array($filename[count($filename) - 1]), '', '', 0, -1); if ($mailfile->sendfile()) { $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)"; $sql .= " VALUES ('" . $this->db->idate(dol_now()) . "', " . $notifcodedefid . ", " . $object->socid . ", null, 'email', '" . $object_type . "', " . $object->id . ", '" . $this->db->escape($conf->global->{$param}) . "')"; if (!$this->db->query($sql)) { dol_print_error($this->db); } } else { $error++; $this->errors[] = $mailfile->error; } } } } if (!$error) { return $num; } else { return -1 * $error; } }
foreach ($contactarr as $contact) { if ($contact['libelle'] == $langs->trans('TypeContact_facture_external_BILLING')) { // TODO Use code and not label require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; $contactstatic = new Contact($db); $contactstatic->fetch($contact['id']); $custcontact = $contactstatic->getFullName($langs, 1); } } if (!empty($custcontact)) { $formmail->substit['__CONTACTCIVNAME__'] = $custcontact; } } // Tableau des parametres complementaires du post $formmail->param['action'] = $action; $formmail->param['models'] = $modelmail; $formmail->param['models_id'] = GETPOST('modelmailselected', 'int'); $formmail->param['facid'] = $object->id; $formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id; // Init list of files if (GETPOST("mode") == 'init') { $formmail->clear_attached_files(); $formmail->add_attached_files($file, basename($file), dol_mimetype($file)); } print $formmail->get_form(); dol_fiche_end(); } } } llxFooter(); $db->close();
/** * Return a string to show the box with list of available documents for object. * This also set the property $this->numoffiles * * @param string $modulepart propal, facture, facture_fourn, ... * @param string $filename Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if $filedir is already complete) * @param string $filedir Directory to scan * @param string $urlsource Url of origin page (for return) * @param int $genallowed Generation is allowed (1/0 or array list of templates) * @param int $delallowed Remove is allowed (1/0) * @param string $modelselected Model to preselect by default * @param string $allowgenifempty Allow generation even if list of template ($genallowed) is empty (show however a warning) * @param string $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined) * @param int $iconPDF Show only PDF icon with link (1/0) * @param int $maxfilenamelength Max length for filename shown * @param string $noform Do not output html form tags * @param string $param More param on http links * @param string $title Title to show on top of form * @param string $buttonlabel Label on submit button * @param string $codelang Default language code to use on lang combo box if multilang is enabled * @param HookManager $hookmanager Object hookmanager with instance of external modules hook classes * @return string Output string with HTML array of documents (might be empty string) */ function showdocuments($modulepart, $filename, $filedir, $urlsource, $genallowed, $delallowed = 0, $modelselected = '', $allowgenifempty = 1, $forcenomultilang = 0, $iconPDF = 0, $maxfilenamelength = 28, $noform = 0, $param = '', $title = '', $buttonlabel = '', $codelang = '', $hookmanager = false) { // filedir = conf->...dir_ouput."/".get_exdir(id) include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; global $langs, $bc, $conf; $forname = 'builddoc'; $out = ''; $var = true; // Clean paramaters if ($iconPDF == 1) { $genallowed = ''; $delallowed = 0; $modelselected = ''; $forcenomultilang = 0; } //$filename = dol_sanitizeFileName($filename); //Must be sanitized before calling show_documents $headershown = 0; $showempty = 0; $i = 0; $titletoshow = $langs->trans("Documents"); if (!empty($title)) { $titletoshow = $title; } $out .= "\n" . '<!-- Start show_document -->' . "\n"; //print 'filedir='.$filedir; // Affiche en-tete tableau if ($genallowed) { $modellist = array(); if ($modulepart == 'company') { $showempty = 1; if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/societe/modules_societe.class.php'; $modellist = ModeleThirdPartyDoc::liste_modeles($this->db); } } else { if ($modulepart == 'propal') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/propale/modules_propale.php'; $modellist = ModelePDFPropales::liste_modeles($this->db); } } else { if ($modulepart == 'commande') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/commande/modules_commande.php'; $modellist = ModelePDFCommandes::liste_modeles($this->db); } } elseif ($modulepart == 'expedition') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/expedition/modules_expedition.php'; $modellist = ModelePDFExpedition::liste_modeles($this->db); } } elseif ($modulepart == 'livraison') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/livraison/modules_livraison.php'; $modellist = ModelePDFDeliveryOrder::liste_modeles($this->db); } } else { if ($modulepart == 'ficheinter') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/fichinter/modules_fichinter.php'; $modellist = ModelePDFFicheinter::liste_modeles($this->db); } } elseif ($modulepart == 'facture') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php'; $modellist = ModelePDFFactures::liste_modeles($this->db); } } elseif ($modulepart == 'project') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/project/modules_project.php'; $modellist = ModelePDFProjects::liste_modeles($this->db); } } elseif ($modulepart == 'export') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/export/modules_export.php'; $modellist = ModeleExports::liste_modeles($this->db); } } else { if ($modulepart == 'commande_fournisseur') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_order/modules_commandefournisseur.php'; $modellist = ModelePDFSuppliersOrders::liste_modeles($this->db); } } else { if ($modulepart == 'facture_fournisseur') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php'; $modellist = ModelePDFSuppliersInvoices::liste_modeles($this->db); } } else { if ($modulepart == 'remisecheque') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/cheque/pdf/modules_chequereceipts.php'; $modellist = ModeleChequeReceipts::liste_modeles($this->db); } } elseif ($modulepart == 'donation') { if (is_array($genallowed)) { $modellist = $genallowed; } else { include_once DOL_DOCUMENT_ROOT . '/core/modules/dons/modules_don.php'; $modellist = ModeleDon::liste_modeles($this->db); } } else { if ($modulepart == 'unpaid') { $modellist = ''; } else { // Generic feature, for external modules $file = dol_buildpath('/core/modules/' . $modulepart . '/modules_' . $modulepart . '.php', 0); if (file_exists($file)) { $res = (include_once $file); } $class = 'Modele' . ucfirst($modulepart); if (class_exists($class)) { $modellist = call_user_func($class . '::liste_modeles', $this->db); } else { dol_print_error($this->db, 'Bad value for modulepart'); return -1; } } } } } } } } } $headershown = 1; $form = new Form($this->db); $buttonlabeltoshow = $buttonlabel; if (empty($buttonlabel)) { $buttonlabel = $langs->trans('Generate'); } if (empty($noform)) { $out .= '<form action="' . $urlsource . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc') . '" name="' . $forname . '" id="' . $forname . '_form" method="post">'; } $out .= '<input type="hidden" name="action" value="builddoc">'; $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; $out .= '<div class="titre">' . $titletoshow . '</div>'; $out .= '<table class="liste formdoc" summary="listofdocumentstable" width="100%">'; $out .= '<tr class="liste_titre">'; // Model if (!empty($modellist)) { $out .= '<th align="center" class="formdoc liste_titre">'; $out .= $langs->trans('Model') . ' '; if (is_array($modellist) && count($modellist) == 1) { $arraykeys = array_keys($modellist); $modelselected = $arraykeys[0]; } $out .= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0); $out .= '</th>'; } else { $out .= '<th align="left" class="formdoc liste_titre">'; $out .= $langs->trans("Files"); $out .= '</th>'; } // Language code (if multilang) $out .= '<th align="center" class="formdoc liste_titre">'; if (($allowgenifempty || is_array($modellist) && count($modellist) > 0) && $conf->global->MAIN_MULTILANGS && !$forcenomultilang) { include_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php'; $formadmin = new FormAdmin($this->db); $defaultlang = $codelang ? $codelang : $langs->getDefaultLang(); $out .= $formadmin->select_language($defaultlang); } else { $out .= ' '; } $out .= '</th>'; // Button $out .= '<th align="center" colspan="' . ($delallowed ? '2' : '1') . '" class="formdocbutton liste_titre">'; $out .= '<input class="button" id="' . $forname . '_generatebutton"'; $out .= ' type="submit" value="' . $buttonlabel . '"'; if (!$allowgenifempty && !is_array($modellist) && empty($modellist)) { $out .= ' disabled="disabled"'; } $out .= '>'; if ($allowgenifempty && !is_array($modellist) && empty($modellist) && $modulepart != 'unpaid') { $langs->load("errors"); $out .= ' ' . img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated")); } $out .= '</th>'; $out .= '</tr>'; // Execute hooks $parameters = array('socid' => isset($GLOBALS['socid']) ? $GLOBALS['socid'] : '', 'id' => isset($GLOBALS['id']) ? $GLOBALS['id'] : '', 'modulepart' => $modulepart); if (is_object($hookmanager)) { $out .= $hookmanager->executeHooks('formBuilddocOptions', $parameters, $GLOBALS['object']); } } // Get list of files if ($filedir) { $png = ''; $filter = ''; if ($iconPDF == 1) { $png = '\\.png$'; $filter = $filename . '.pdf'; } $file_list = dol_dir_list($filedir, 'files', 0, $filter, '\\.meta$' . ($png ? '|' . $png : ''), 'date', SORT_DESC); // Affiche en-tete tableau si non deja affiche if (!empty($file_list) && !$headershown && !$iconPDF) { $headershown = 1; $out .= '<div class="titre">' . $titletoshow . '</div>'; $out .= '<table class="border" summary="listofdocumentstable" width="100%">'; } else { if (empty($file_list) && !empty($iconPDF)) { // For ajax treatment $out .= '<div id="gen_pdf_' . $filename . '" class="linkobject hideobject">' . img_picto('', 'refresh') . '</div>' . "\n"; } } // Loop on each file found foreach ($file_list as $file) { $var = !$var; // Define relative path for download link (depends on module) $relativepath = $file["name"]; // Cas general if ($filename) { $relativepath = $filename . "/" . $file["name"]; } // Cas propal, facture... // Autre cas if ($modulepart == 'donation') { $relativepath = get_exdir($filename, 2) . $file["name"]; } if ($modulepart == 'export') { $relativepath = $file["name"]; } if (!$iconPDF) { $out .= "<tr " . $bc[$var] . ">"; } // Show file name with link to download if (!$iconPDF) { $out .= '<td nowrap="nowrap">'; } $out .= '<a href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&file=' . urlencode($relativepath) . '"'; $mime = dol_mimetype($relativepath, '', 0); if (preg_match('/text/', $mime)) { $out .= ' target="_blank"'; } $out .= '>'; if (!$iconPDF) { $out .= img_mime($file["name"], $langs->trans("File") . ': ' . $file["name"]) . ' ' . dol_trunc($file["name"], $maxfilenamelength); } else { $out .= img_pdf($file["name"], 2); } $out .= '</a>' . "\n"; if (!$iconPDF) { $out .= '</td>'; // Show file size $out .= '<td align="right" nowrap="nowrap">' . dol_print_size(dol_filesize($filedir . "/" . $file["name"])) . '</td>'; // Show file date $out .= '<td align="right" nowrap="nowrap">' . dol_print_date(dol_filemtime($filedir . "/" . $file["name"]), 'dayhour') . '</td>'; } if ($delallowed) { $out .= '<td align="right">'; //$out.= '<a href="'.DOL_URL_ROOT.'/document.php?action=remove_file&modulepart='.$modulepart.'&file='.urlencode($relativepath); $out .= '<a href="' . $urlsource . '&action=remove_file&modulepart=' . $modulepart . '&file=' . urlencode($relativepath); $out .= $param ? '&' . $param : ''; $out .= '&urlsource=' . urlencode($urlsource); $out .= '">' . img_delete() . '</a></td>'; } if (!$iconPDF) { $out .= '</tr>'; } $this->numoffiles++; } } if ($headershown) { // Affiche pied du tableau $out .= "</table>\n"; if ($genallowed) { if (empty($noform)) { $out .= '</form>' . "\n"; } } } $out .= '<!-- End show_document -->' . "\n"; //return ($i?$i:$headershown); return $out; }
/** * Function to build PDF on disk, then output on HTTP strem. * * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>) * @param Translate $outputlangs Lang object for output language * @param string $srctemplatepath Full path of source filename for generator using a template file * @param string $outputdir Output directory for pdf file * @param string $filename Short file name of PDF output file * @return int 1=OK, 0=KO */ function write_file($arrayofrecords, $outputlangs, $srctemplatepath, $outputdir = '', $filename = 'tmp_address_sheet.pdf') { global $user, $conf, $langs, $mysoc, $_Avery_Labels; $this->code = $srctemplatepath; $this->Tformat = $_Avery_Labels[$this->code]; if (empty($this->Tformat)) { dol_print_error('', 'ErrorBadTypeForCard' . $this->code); exit; } $this->type = 'pdf'; // standard format or custom if ($this->Tformat['paper-size'] != 'custom') { $this->format = $this->Tformat['paper-size']; } else { //custom $resolution = array($this->Tformat['custom_x'], $this->Tformat['custom_y']); $this->format = $resolution; } if (!is_object($outputlangs)) { $outputlangs = $langs; } // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (!empty($conf->global->MAIN_USE_FPDF)) { $outputlangs->charset_output = 'ISO-8859-1'; } $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("admin"); $title = $outputlangs->transnoentities('Labels'); $keywords = $title . " " . $outputlangs->convToOutputCharset($mysoc->name); $dir = empty($outputdir) ? $conf->adherent->dir_temp : $outputdir; $file = $dir . "/" . $filename; if (!file_exists($dir)) { if (dol_mkdir($dir) < 0) { $this->error = $langs->trans("ErrorCanNotCreateDir", $dir); return 0; } } $pdf = pdf_getInstance($this->format, $this->Tformat['metric'], $this->Tformat['orientation']); if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($outputlangs)); $pdf->SetTitle($title); $pdf->SetSubject($title); $pdf->SetCreator("Dolibarr " . DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($keywords); if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) { $pdf->SetCompression(false); } $pdf->SetMargins(0, 0); $pdf->SetAutoPageBreak(false); $this->_Metric_Doc = $this->Tformat['metric']; // Permet de commencer l'impression de l'etiquette desiree dans le cas ou la page a deja servie $posX = 1; $posY = 1; if ($posX > 0) { $posX--; } else { $posX = 0; } if ($posY > 0) { $posY--; } else { $posY = 0; } $this->_COUNTX = $posX; $this->_COUNTY = $posY; $this->_Set_Format($pdf, $this->Tformat); $pdf->Open(); $pdf->AddPage(); // Add each record foreach ($arrayofrecords as $val) { // imprime le texte specifique sur la carte $this->addSticker($pdf, $outputlangs, $val); } //$pdf->SetXY(10, 295); //$pdf->Cell($this->_Width, $this->_Line_Height, 'XXX',0,1,'C'); // Output to file $pdf->Output($file, 'F'); if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } // Output to http stream clearstatcache(); $attachment = true; if (!empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) { $attachment = false; } $type = dol_mimetype($filename); //if ($encoding) header('Content-Encoding: '.$encoding); if ($type) { header('Content-Type: ' . $type); } if ($attachment) { header('Content-Disposition: attachment; filename="' . $filename . '"'); } else { header('Content-Disposition: inline; filename="' . $filename . '"'); } // Ajout directives pour resoudre bug IE header('Cache-Control: Public, must-revalidate'); header('Pragma: public'); readfile($file); return 1; }
/** * Show only Document icon with link * * @param string $modulepart propal, facture, facture_fourn, ... * @param string $modulesubdir Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. * @param string $filedir Directory to scan * @param string $filter Filter filenames on this regex string (Example: '\.pdf$') * @return string Output string with HTML link of documents (might be empty string). This also fill the array ->infofiles */ function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter = '') { include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $out = ''; $this->infofiles = array('nboffiles' => 0, 'extensions' => array(), 'files' => array()); $file_list = dol_dir_list($filedir, 'files', 0, preg_quote(basename($modulesubdir), '/') . '[^\\-]+', '\\.meta$|\\.png$'); // Get list of files starting with name fo ref (but not followed by "-" to discard uploaded files) // For ajax treatment $out .= '<div id="gen_pdf_' . $modulesubdir . '" class="linkobject hideobject">' . img_picto('', 'refresh') . '</div>' . "\n"; if (!empty($file_list)) { // Loop on each file found foreach ($file_list as $file) { if ($filter && !preg_match('/' . $filter . '/i', $file["name"])) { continue; } // Discard this. It does not match provided filter. // Define relative path for download link (depends on module) $relativepath = $file["name"]; // Cas general if ($modulesubdir) { $relativepath = $modulesubdir . "/" . $file["name"]; } // Cas propal, facture... // Autre cas if ($modulepart == 'donation') { $relativepath = get_exdir($modulesubdir, 2, 0, 0, null, 'donation') . $file["name"]; } if ($modulepart == 'export') { $relativepath = $file["name"]; } if ($modulepart == 'facture_fournisseur' || $modulepart == 'invoice_fournisseur') { $relativepath = get_exdir($modulesubdir, 2, 0, 0, null, 'invoice_supplier') . $modulesubdir . "/" . $file["name"]; } // Show file name with link to download $out .= '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&file=' . urlencode($relativepath) . '"'; $mime = dol_mimetype($relativepath, '', 0); if (preg_match('/text/', $mime)) { $out .= ' target="_blank"'; } $out .= '>'; $out .= img_mime($relativepath, $file["name"]); $out .= '</a>' . "\n"; $this->infofiles['nboffiles']++; $this->infofiles['files'][] = $file['fullname']; $ext = pathinfo($file["name"], PATHINFO_EXTENSION); if (empty($this->infofiles[$ext])) { $this->infofiles['extensions'][$ext] = 1; } else { $this->infofiles['extensions'][$ext]++; } } } return $out; }
/** * Method to get a document by webservice * * @param array $authentication Array with permissions * @param string $modulepart Properties of document * @param string $file Relative path * @param string $refname Ref of object to check permission for external users (autodetect if not provided) * @return void */ function getDocument($authentication, $modulepart, $file, $refname = '') { global $db, $conf, $langs, $mysoc; dol_syslog("Function: getDocument login="******"/"; //$relativepath = $relativefilepath . $ref.'.pdf'; $accessallowed = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); if ($fuser->societe_id) { $socid = $fuser->societe_id; } // Check parameters if (!$error && (!$file || !$modulepart)) { $error++; $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter file and modulepart must be both provided."; } if (!$error) { $fuser->getrights(); // Suppression de la chaine de caractere ../ dans $original_file $original_file = str_replace("../", "/", $original_file); // find the subdirectory name as the reference if (empty($refname)) { $refname = basename(dirname($original_file) . "/"); } // Security check $check_access = dol_check_secure_access_document($modulepart, $original_file, $conf->entity, $fuser, $refname); $accessallowed = $check_access['accessallowed']; $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals']; $original_file = $check_access['original_file']; // Basic protection (against external users only) if ($fuser->societe_id > 0) { if ($sqlprotectagainstexternals) { $resql = $db->query($sqlprotectagainstexternals); if ($resql) { $num = $db->num_rows($resql); $i = 0; while ($i < $num) { $obj = $db->fetch_object($resql); if ($fuser->societe_id != $obj->fk_soc) { $accessallowed = 0; break; } $i++; } } } } // Security: // Limite acces si droits non corrects if (!$accessallowed) { $errorcode = 'NOT_PERMITTED'; $errorlabel = 'Access not allowed'; $error++; } // Security: // On interdit les remontees de repertoire ainsi que les pipe dans // les noms de fichiers. if (preg_match('/\\.\\./', $original_file) || preg_match('/[<>|]/', $original_file)) { dol_syslog("Refused to deliver file " . $original_file); $errorcode = 'REFUSED'; $errorlabel = ''; $error++; } clearstatcache(); if (!$error) { if (file_exists($original_file)) { dol_syslog("Function: getDocument {$original_file} {$filename} content-type={$type}"); $file = $fileparams['fullname']; $filename = basename($file); $f = fopen($original_file, 'r'); $content_file = fread($f, filesize($original_file)); $objectret = array('filename' => basename($original_file), 'mimetype' => dol_mimetype($original_file), 'content' => base64_encode($content_file), 'length' => filesize($original_file)); // Create return object $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'document' => $objectret); } else { dol_syslog("File doesn't exist " . $original_file); $errorcode = 'NOT_FOUND'; $errorlabel = ''; $error++; } } } if ($error) { $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel)); } return $objectresp; }
/** * * @param unknown $object */ static function sendOrderByMail(&$object) { global $conf, $langs, $user, $db; if (empty($object->thirdparty)) { $object->fetch_thirdparty(); } $sendto = $object->thirdparty->email; $sendtocc = ''; $from = empty($user->email) ? $conf->global->MAIN_MAIL_EMAIL_FROM : $user->email; $id = $object->id; $_POST['receiver'] = '-1'; $_POST['frommail'] = $_POST['replytomail'] = $from; $_POST['fromname'] = $_POST['replytoname'] = $user->getFullName($langs); dol_include_once('/core/class/html.formmail.class.php'); $formmail = new Formmail($db); $outputlangs = clone $langs; $id_template = (int) $conf->global->GRAPEFRUIT_SEND_BILL_BY_MAIL_ON_VALIDATE_MODEL; $formmail->fetchAllEMailTemplate('facture_send', $user, $outputlangs); foreach ($formmail->lines_model as &$model) { if ($model->id == $id_template) { break; } } if (empty($model)) { setEventMessage($langs->trans('ModelRequire'), 'errors'); } // Make substitution $substit['__REF__'] = $object->ref; $substit['__SIGNATURE__'] = $user->signature; $substit['__REFCLIENT__'] = $object->ref_client; $substit['__THIRDPARTY_NAME__'] = $object->thirdparty->name; $substit['__PROJECT_REF__'] = is_object($object->projet) ? $object->projet->ref : ''; $substit['__PROJECT_NAME__'] = is_object($object->projet) ? $object->projet->title : ''; $substit['__PERSONALIZED__'] = ''; $substit['__CONTACTCIVNAME__'] = ''; // Find the good contact adress $custcontact = ''; $contactarr = array(); $contactarr = $object->liste_contact(-1, 'external'); if (is_array($contactarr) && count($contactarr) > 0) { foreach ($contactarr as $contact) { dol_syslog(get_class($this) . '::' . __METHOD__ . ' lib=' . $contact['libelle']); dol_syslog(get_class($this) . '::' . __METHOD__ . ' trans=' . $langs->trans('TypeContact_commande_external_BILLING')); if ($contact['libelle'] == $langs->trans('TypeContact_commande_external_BILLING')) { require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; $contactstatic = new Contact($db); $contactstatic->fetch($contact['id']); $custcontact = $contactstatic->getFullName($langs, 1); dol_syslog(get_class($this) . '::' . __METHOD__ . ' email=' . $contactstatic->email); } } if (!empty($custcontact)) { $substit['__CONTACTCIVNAME__'] = $custcontact; } if (!empty($contactstatic->email)) { $sendto = $contactstatic->email; } } $topic = make_substitutions($model->topic, $substit); $message = make_substitutions($model->content, $substit); $_POST['message'] = $message; $_POST['subject'] = $topic; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; // Add attached files $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $object->ref, preg_quote($object->ref, '/') . '[^\\-]+'); if (is_array($fileparams) && array_key_exists('fullname', $fileparams) && !empty($fileparams['fullname'])) { $_SESSION["listofpaths"] = $fileparams['fullname']; $_SESSION["listofnames"] = basename($fileparams['fullname']); $_SESSION["listofmimes"] = dol_mimetype($fileparams['fullname']); } else { // generate invoice $result = $object->generateDocument($object->modelpdf, $outputlangs, 0, 0, 0); if ($result <= 0) { $this->error = $object->error; } $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $object->ref, preg_quote($object->ref, '/') . '[^\\-]+'); if (is_array($fileparams) && array_key_exists('fullname', $fileparams) && !empty($fileparams['fullname'])) { $_SESSION["listofpaths"] = $fileparams['fullname']; $_SESSION["listofnames"] = basename($fileparams['fullname']); $_SESSION["listofmimes"] = dol_mimetype($fileparams['fullname']); } } $action = 'send'; $actiontypecode = 'AC_FAC'; $trigger_name = 'BILL_SENTBYMAIL'; $paramname = 'id'; $mode = 'emailfrominvoice'; if (!empty($sendto)) { require_once __DIR__ . '/../tpl/actions_sendmails.inc.php'; } }
function _sendByMail(&$db, &$conf, &$user, &$langs, &$facture, &$societe, $label) { $filename_list = array(); $mimetype_list = array(); $mimefilename_list = array(); $ref = dol_sanitizeFileName($facture->ref); $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/') . '([^\\-])+'); $file = $fileparams['fullname']; // Build document if it not exists if (!$file || !is_readable($file)) { $result = $facture->generateDocument($facture->modelpdf, $langs, 0, 0, 0); if ($result <= 0) { $error = 1; return $error; } } $label = !empty($conf->global->SENDINVOICETOADHERENT_SUBJECT) ? $conf->global->SENDINVOICETOADHERENT_SUBJECT : $label; $substitutionarray = array('__NAME__' => $societe->name, '__REF__' => $facture->ref); $message = $conf->global->SENDINVOICETOADHERENT_MESSAGE; $message = make_substitutions($message, $substitutionarray); $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/') . '([^\\-])+'); $file = $fileparams['fullname']; $filename = basename($file); $mimefile = dol_mimetype($file); $filename_list[] = $file; $mimetype_list[] = $mimefile; $mimefilename_list[] = $filename; $CMail = new CMailFile($label, $societe->email, $conf->global->MAIN_MAIL_EMAIL_FROM, $message, $filename_list, $mimetype_list, $mimefilename_list, '', '', '', '', $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO); // Send mail return $CMail->sendfile(); }
/** * Show MIME img of a file * * @param string $file Filename * @param string $titlealt Text on alt and title of image. Alt only if param notitle is set to 1. If text is "TextA:TextB", use Text A on alt and Text B on title. * @return string Return img tag */ function img_mime($file, $titlealt = '') { require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $mimetype = dol_mimetype($file, '', 1); $mimeimg = dol_mimetype($file, '', 2); if (empty($titlealt)) { $titlealt = 'Mime type: ' . $mimetype; } return img_picto_common($titlealt, 'mime/' . $mimeimg); }
} $filename = $langs->trans("ExampleOfImportFile") . '_' . $datatoimport . '.' . $format; $objimport = new Import($db); $objimport->load_arrays($user, $datatoimport); // Load arrays from descriptor module $entity = $objimport->array_import_entities[0][$code]; $entityicon = $entitytoicon[$entity] ? $entitytoicon[$entity] : $entity; $entitylang = $entitytolang[$entity] ? $entitytolang[$entity] : $entity; $fieldstarget = $objimport->array_import_fields[0]; $valuestarget = $objimport->array_import_examplevalues[0]; $attachment = true; if (isset($_GET["attachment"])) { $attachment = $_GET["attachment"]; } //$attachment = false; $contenttype = dol_mimetype($format); if (isset($_GET["contenttype"])) { $contenttype = $_GET["contenttype"]; } //$contenttype='text/plain'; $outputencoding = 'UTF-8'; if ($contenttype) { header('Content-Type: ' . $contenttype . ($outputencoding ? '; charset=' . $outputencoding : '')); } if ($attachment) { header('Content-Disposition: attachment; filename="' . $filename . '"'); } // List of targets fields $headerlinefields = array(); $contentlinevalues = array(); $i = 0;
/** * Init $_SESSION with uploaded files * * @param string $pathtoscan Path to scan * @return void */ function dol_init_file_process($pathtoscan = '') { $listofpaths = array(); $listofnames = array(); $listofmimes = array(); if ($pathtoscan) { $listoffiles = dol_dir_list($pathtoscan, 'files'); foreach ($listoffiles as $key => $val) { $listofpaths[] = $val['fullname']; $listofnames[] = $val['name']; $listofmimes[] = dol_mimetype($val['name']); } } $_SESSION["listofpaths"] = join(';', $listofpaths); $_SESSION["listofnames"] = join(';', $listofnames); $_SESSION["listofmimes"] = join(';', $listofmimes); }
/** * testDolMimeType * * @return string */ public function testDolMimeType() { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; // file.png $result=dol_mimetype('file.png','',0); $this->assertEquals('image/png',$result); $result=dol_mimetype('file.png','',1); $this->assertEquals('png',$result); $result=dol_mimetype('file.png','',2); $this->assertEquals('image.png',$result); $result=dol_mimetype('file.png','',3); $this->assertEquals('',$result); // file.odt $result=dol_mimetype('file.odt','',0); $this->assertEquals('application/vnd.oasis.opendocument.text',$result); $result=dol_mimetype('file.odt','',1); $this->assertEquals('vnd.oasis.opendocument.text',$result); $result=dol_mimetype('file.odt','',2); $this->assertEquals('ooffice.png',$result); $result=dol_mimetype('file.odt','',3); $this->assertEquals('',$result); // file.php $result=dol_mimetype('file.php','',0); $this->assertEquals('text/plain',$result); $result=dol_mimetype('file.php','',1); $this->assertEquals('plain',$result); $result=dol_mimetype('file.php','',2); $this->assertEquals('php.png',$result); $result=dol_mimetype('file.php','',3); $this->assertEquals('php',$result); // file.php.noexe $result=dol_mimetype('file.php.noexe','',0); $this->assertEquals('text/plain',$result); }
/** * Enter description here ... * * @param string $uploaded_file Uploade file * @param string $name Name * @param int $size Size * @param string $type Type * @param string $error Error * @param string $index Index * @return stdClass */ protected function handleFileUpload($uploaded_file, $name, $size, $type, $error, $index) { $file = new stdClass(); $file->name = $this->trimFileName($name, $type, $index); $file->mime = dol_mimetype($file->name, '', 2); $file->size = intval($size); $file->type = $type; if ($this->validate($uploaded_file, $file, $error, $index) && dol_mkdir($this->options['upload_dir']) >= 0) { $file_path = $this->options['upload_dir'] . $file->name; $append_file = !$this->options['discard_aborted_uploads'] && is_file($file_path) && $file->size > filesize($file_path); clearstatcache(); if ($uploaded_file && is_uploaded_file($uploaded_file)) { // multipart/formdata uploads (POST method uploads) if ($append_file) { file_put_contents($file_path, fopen($uploaded_file, 'r'), FILE_APPEND); } else { dol_move_uploaded_file($uploaded_file, $file_path, 1, 0, 0, 0, 'userfile'); } } else { // Non-multipart uploads (PUT method support) file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0); } $file_size = filesize($file_path); if ($file_size === $file->size) { $file->url = $this->options['upload_url'] . rawurlencode($file->name); foreach ($this->options['image_versions'] as $version => $options) { if ($this->createScaledImage($file->name, $options)) { $tmp = explode('.', $file->name); $file->{$version . '_url'} = $options['upload_url'] . rawurlencode($tmp[0] . '_mini.' . $tmp[1]); } } } else { if ($this->options['discard_aborted_uploads']) { unlink($file_path); $file->error = 'abort'; } } $file->size = $file_size; $this->setFileDeleteUrl($file); } return $file; }
private function _addFiles(&$listofpaths, &$listofnames, &$listofmimes, $path) { global $langs; include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $fileList = dol_dir_list($path, 'files', 0); $nbFiles = 0; foreach ($fileList as $fileParams) { // Attachment in the e-mail $file = $fileParams['fullname']; $md5 = md5(file_get_contents($file)); if (!in_array($file, $listofpaths) && !in_array($md5, $this->TFileAdded)) { $listofpaths[] = $file; $this->TFileAdded[] = $md5; $listofnames[] = basename($file); $listofmimes[] = dol_mimetype($file); $nbFiles++; } } return $nbFiles; }
$arr_mime = array(); $arr_name = array(); $arr_css = array(); // Ajout CSS if (!empty($object->bgcolor)) { $arr_css['bgcolor'] = (preg_match('/^#/', $object->bgcolor) ? '' : '#') . $object->bgcolor; } if (!empty($object->bgimage)) { $arr_css['bgimage'] = $object->bgimage; } // Attached files $listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0); if (count($listofpaths)) { foreach ($listofpaths as $key => $val) { $arr_file[] = $listofpaths[$key]['fullname']; $arr_mime[] = dol_mimetype($listofpaths[$key]['name']); $arr_name[] = $listofpaths[$key]['name']; } } $mailfile = new CMailFile($tmpsujet, $object->sendto, $object->email_from, $tmpbody, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $object->email_errorsto, $arr_css); $result = $mailfile->sendfile(); if ($result) { $mesg = '<div class="ok">' . $langs->trans("MailSuccessfulySent", $mailfile->getValidAddress($object->email_from, 2), $mailfile->getValidAddress($object->sendto, 2)) . '</div>'; } else { $mesg = '<div class="error">' . $langs->trans("ResultKo") . '<br>' . $mailfile->error . ' ' . $result . '</div>'; } $action = ''; } } // Action add emailing if ($action == 'add') {
/** * Security check when accessing to a document (used by document.php, viewimage.php and webservices) * * @param string $modulepart Module of document ('module', 'module_user_temp', 'module_user' or 'module_temp') * @param string $original_file Relative path with filename * @param string $entity Restrict onto entity * @param User $fuser User object (forced) * @param string $refname Ref of object to check permission for external users (autodetect if not provided) * @return mixed Array with access information : accessallowed & sqlprotectagainstexternals & original_file (as full path name) */ function dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser = '', $refname = '') { global $user, $conf, $db; if (!is_object($fuser)) { $fuser = $user; } if (empty($modulepart)) { return 'ErrorBadParameter'; } if (empty($entity)) { $entity = 0; } dol_syslog('modulepart=' . $modulepart . ' original_file=' . $original_file); // We define $accessallowed and $sqlprotectagainstexternals $accessallowed = 0; $sqlprotectagainstexternals = ''; $ret = array(); // find the subdirectory name as the reference if (empty($refname)) { $refname = basename(dirname($original_file) . "/"); } // Wrapping for some images if ($modulepart == 'companylogo') { $accessallowed = 1; $original_file = $conf->mycompany->dir_output . '/logos/' . $original_file; } elseif ($modulepart == 'userphoto') { $accessallowed = 1; $original_file = $conf->user->dir_output . '/' . $original_file; } elseif ($modulepart == 'memberphoto') { $accessallowed = 1; $original_file = $conf->adherent->dir_output . '/' . $original_file; } elseif ($modulepart == 'apercufacture') { if ($fuser->rights->facture->lire) { $accessallowed = 1; } $original_file = $conf->facture->dir_output . '/' . $original_file; } elseif ($modulepart == 'apercupropal') { if ($fuser->rights->propale->lire) { $accessallowed = 1; } $original_file = $conf->propal->dir_output . '/' . $original_file; } elseif ($modulepart == 'apercucommande') { if ($fuser->rights->commande->lire) { $accessallowed = 1; } $original_file = $conf->commande->dir_output . '/' . $original_file; } elseif ($modulepart == 'apercufichinter') { if ($fuser->rights->ficheinter->lire) { $accessallowed = 1; } $original_file = $conf->ficheinter->dir_output . '/' . $original_file; } elseif ($modulepart == 'propalstats') { if ($fuser->rights->propale->lire) { $accessallowed = 1; } $original_file = $conf->propal->dir_temp . '/' . $original_file; } elseif ($modulepart == 'orderstats') { if ($fuser->rights->commande->lire) { $accessallowed = 1; } $original_file = $conf->commande->dir_temp . '/' . $original_file; } elseif ($modulepart == 'orderstatssupplier') { if ($fuser->rights->fournisseur->commande->lire) { $accessallowed = 1; } $original_file = $conf->fournisseur->dir_output . '/commande/temp/' . $original_file; } elseif ($modulepart == 'billstats') { if ($fuser->rights->facture->lire) { $accessallowed = 1; } $original_file = $conf->facture->dir_temp . '/' . $original_file; } elseif ($modulepart == 'billstatssupplier') { if ($fuser->rights->fournisseur->facture->lire) { $accessallowed = 1; } $original_file = $conf->fournisseur->dir_output . '/facture/temp/' . $original_file; } elseif ($modulepart == 'expeditionstats') { if ($fuser->rights->expedition->lire) { $accessallowed = 1; } $original_file = $conf->expedition->dir_temp . '/' . $original_file; } elseif ($modulepart == 'tripsexpensesstats') { if ($fuser->rights->deplacement->lire) { $accessallowed = 1; } $original_file = $conf->deplacement->dir_temp . '/' . $original_file; } elseif ($modulepart == 'memberstats') { if ($fuser->rights->adherent->lire) { $accessallowed = 1; } $original_file = $conf->adherent->dir_temp . '/' . $original_file; } elseif (preg_match('/^productstats_/i', $modulepart)) { if ($fuser->rights->produit->lire || $fuser->rights->service->lire) { $accessallowed = 1; } $original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]) . '/' . $original_file; } elseif ($modulepart == 'tax') { if ($fuser->rights->tax->charges->lire) { $accessallowed = 1; } $original_file = $conf->tax->dir_output . '/' . $original_file; } elseif ($modulepart == 'actions') { if ($fuser->rights->agenda->myactions->read) { $accessallowed = 1; } $original_file = $conf->agenda->dir_output . '/' . $original_file; } elseif ($modulepart == 'category') { if ($fuser->rights->categorie->lire) { $accessallowed = 1; } $original_file = $conf->categorie->multidir_output[$entity] . '/' . $original_file; } elseif ($modulepart == 'prelevement') { if ($fuser->rights->prelevement->bons->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->prelevement->dir_output . '/' . $original_file; } elseif ($modulepart == 'graph_stock') { $accessallowed = 1; $original_file = $conf->stock->dir_temp . '/' . $original_file; } elseif ($modulepart == 'graph_fourn') { $accessallowed = 1; $original_file = $conf->fournisseur->dir_temp . '/' . $original_file; } elseif ($modulepart == 'graph_product') { $accessallowed = 1; $original_file = $conf->product->multidir_temp[$entity] . '/' . $original_file; } elseif ($modulepart == 'barcode') { $accessallowed = 1; // If viewimage is called for barcode, we try to output an image on the fly, // with not build of file on disk. //$original_file=$conf->barcode->dir_temp.'/'.$original_file; $original_file = ''; } elseif ($modulepart == 'iconmailing') { $accessallowed = 1; $original_file = $conf->mailing->dir_temp . '/' . $original_file; } elseif ($modulepart == 'scanner_user_temp') { $accessallowed = 1; $original_file = $conf->scanner->dir_temp . '/' . $fuser->id . '/' . $original_file; } elseif ($modulepart == 'fckeditor') { $accessallowed = 1; $original_file = $conf->fckeditor->dir_output . '/' . $original_file; } else { if ($modulepart == 'company' || $modulepart == 'societe') { if ($fuser->rights->societe->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->societe->multidir_output[$entity] . '/' . $original_file; $sqlprotectagainstexternals = "SELECT rowid as fk_soc FROM " . MAIN_DB_PREFIX . "societe WHERE rowid='" . $db->escape($refname) . "' AND entity IN (" . getEntity('societe', 1) . ")"; } else { if ($modulepart == 'contact') { if ($fuser->rights->societe->lire) { $accessallowed = 1; } $original_file = $conf->societe->multidir_output[$entity] . '/contact/' . $original_file; } else { if ($modulepart == 'facture' || $modulepart == 'invoice') { if ($fuser->rights->facture->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->facture->dir_output . '/' . $original_file; $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM " . MAIN_DB_PREFIX . "facture WHERE ref='" . $db->escape($refname) . "' AND entity=" . $conf->entity; } else { if ($modulepart == 'unpaid') { if ($fuser->rights->facture->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->facture->dir_output . '/unpaid/temp/' . $original_file; } else { if ($modulepart == 'ficheinter') { if ($fuser->rights->ficheinter->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->ficheinter->dir_output . '/' . $original_file; $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM " . MAIN_DB_PREFIX . "fichinter WHERE ref='" . $db->escape($refname) . "' AND entity=" . $conf->entity; } else { if ($modulepart == 'deplacement') { if ($fuser->rights->deplacement->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->deplacement->dir_output . '/' . $original_file; //$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; } else { if ($modulepart == 'propal') { if ($fuser->rights->propale->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->propal->dir_output . '/' . $original_file; $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM " . MAIN_DB_PREFIX . "propal WHERE ref='" . $db->escape($refname) . "' AND entity=" . $conf->entity; } else { if ($modulepart == 'commande' || $modulepart == 'order') { if ($fuser->rights->commande->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->commande->dir_output . '/' . $original_file; $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM " . MAIN_DB_PREFIX . "commande WHERE ref='" . $db->escape($refname) . "' AND entity=" . $conf->entity; } else { if ($modulepart == 'project') { if ($fuser->rights->projet->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->projet->dir_output . '/' . $original_file; $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM " . MAIN_DB_PREFIX . "projet WHERE ref='" . $db->escape($refname) . "' AND entity=" . $conf->entity; } else { if ($modulepart == 'project_task') { if ($fuser->rights->projet->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->projet->dir_output . '/' . $original_file; $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM " . MAIN_DB_PREFIX . "projet WHERE ref='" . $db->escape($refname) . "' AND entity=" . $conf->entity; } else { if ($modulepart == 'fichinter') { if ($fuser->rights->ficheinter->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->ficheinter->dir_output . '/' . $original_file; $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM " . MAIN_DB_PREFIX . "fichinter WHERE ref='" . $db->escape($refname) . "' AND entity=" . $conf->entity; } else { if ($modulepart == 'commande_fournisseur' || $modulepart == 'order_supplier') { if ($fuser->rights->fournisseur->commande->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->fournisseur->commande->dir_output . '/' . $original_file; $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM " . MAIN_DB_PREFIX . "commande_fournisseur WHERE ref='" . $db->escape($refname) . "' AND entity=" . $conf->entity; } else { if ($modulepart == 'facture_fournisseur' || $modulepart == 'invoice_supplier') { if ($fuser->rights->fournisseur->facture->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->fournisseur->facture->dir_output . '/' . $original_file; $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM " . MAIN_DB_PREFIX . "facture_fourn WHERE facnumber='" . $db->escape($refname) . "' AND entity=" . $conf->entity; } else { if ($modulepart == 'facture_paiement') { if ($fuser->rights->facture->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } if ($fuser->societe_id > 0) { $original_file = $conf->facture->dir_output . '/payments/private/' . $fuser->id . '/' . $original_file; } else { $original_file = $conf->facture->dir_output . '/payments/' . $original_file; } } else { if ($modulepart == 'export_compta') { if ($fuser->rights->accounting->ventilation->dispatch || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->accounting->dir_output . '/' . $original_file; } else { if ($modulepart == 'expedition') { if ($fuser->rights->expedition->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->expedition->dir_output . "/sending/" . $original_file; } else { if ($modulepart == 'livraison') { if ($fuser->rights->expedition->livraison->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->expedition->dir_output . "/receipt/" . $original_file; } else { if ($modulepart == 'actions') { if ($fuser->rights->agenda->myactions->read || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->agenda->dir_output . '/' . $original_file; } else { if ($modulepart == 'actionsreport') { if ($fuser->rights->agenda->allactions->read || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->agenda->dir_temp . "/" . $original_file; } else { if ($modulepart == 'product' || $modulepart == 'produit' || $modulepart == 'service') { if ($fuser->rights->produit->lire || $fuser->rights->service->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } if (!empty($conf->product->enabled)) { $original_file = $conf->product->multidir_output[$entity] . '/' . $original_file; } elseif (!empty($conf->service->enabled)) { $original_file = $conf->service->multidir_output[$entity] . '/' . $original_file; } } else { if ($modulepart == 'contract') { if ($fuser->rights->contrat->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->contrat->dir_output . '/' . $original_file; } else { if ($modulepart == 'donation') { if ($fuser->rights->don->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->don->dir_output . '/' . $original_file; } else { if ($modulepart == 'remisecheque') { if ($fuser->rights->banque->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->banque->dir_output . '/bordereau/' . $original_file; // original_file should contains relative path so include the get_exdir result } else { if ($modulepart == 'bank') { if ($fuser->rights->banque->lire) { $accessallowed = 1; } $original_file = $conf->bank->dir_output . '/' . $original_file; } else { if ($modulepart == 'export') { // Aucun test necessaire car on force le rep de download sur // le rep export qui est propre a l'utilisateur $accessallowed = 1; $original_file = $conf->export->dir_temp . '/' . $fuser->id . '/' . $original_file; } else { if ($modulepart == 'import') { // Aucun test necessaire car on force le rep de download sur // le rep export qui est propre a l'utilisateur $accessallowed = 1; $original_file = $conf->import->dir_temp . '/' . $original_file; } else { if ($modulepart == 'editor') { // Aucun test necessaire car on force le rep de download sur // le rep export qui est propre a l'utilisateur $accessallowed = 1; $original_file = $conf->fckeditor->dir_output . '/' . $original_file; } else { if ($modulepart == 'systemtools') { if ($fuser->admin) { $accessallowed = 1; } $original_file = $conf->admin->dir_output . '/' . $original_file; } else { if ($modulepart == 'admin_temp') { if ($fuser->admin) { $accessallowed = 1; } $original_file = $conf->admin->dir_temp . '/' . $original_file; } else { if ($modulepart == 'bittorrent') { $accessallowed = 1; $dir = 'files'; if (dol_mimetype($original_file) == 'application/x-bittorrent') { $dir = 'torrents'; } $original_file = $conf->bittorrent->dir_output . '/' . $dir . '/' . $original_file; } else { if ($modulepart == 'member') { if ($fuser->rights->adherent->lire || preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } $original_file = $conf->adherent->dir_output . '/' . $original_file; } else { if ($modulepart == 'scanner_user_temp') { $accessallowed = 1; $original_file = $conf->scanner->dir_temp . '/' . $fuser->id . '/' . $original_file; } else { // Define $accessallowed if (preg_match('/^([a-z]+)_user_temp$/i', $modulepart, $reg)) { if ($fuser->rights->{$reg}[1]->lire || $fuser->rights->{$reg}[1]->read || $fuser->rights->{$reg}[1]->download) { $accessallowed = 1; } $original_file = $conf->{$reg}[1]->dir_temp . '/' . $fuser->id . '/' . $original_file; } else { if (preg_match('/^([a-z]+)_temp$/i', $modulepart, $reg)) { if ($fuser->rights->{$reg}[1]->lire || $fuser->rights->{$reg}[1]->read || $fuser->rights->{$reg}[1]->download) { $accessallowed = 1; } $original_file = $conf->{$reg}[1]->dir_temp . '/' . $original_file; } else { if (preg_match('/^([a-z]+)_user$/i', $modulepart, $reg)) { if ($fuser->rights->{$reg}[1]->lire || $fuser->rights->{$reg}[1]->read || $fuser->rights->{$reg}[1]->download) { $accessallowed = 1; } $original_file = $conf->{$reg}[1]->dir_output . '/' . $fuser->id . '/' . $original_file; } else { if (empty($conf->{$modulepart}->dir_output)) { dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter (' . $modulepart . ')'); exit; } $perm = GETPOST('perm'); $subperm = GETPOST('subperm'); if ($perm || $subperm) { if ($perm && !$subperm && $fuser->rights->{$modulepart}->{$perm} || $perm && $subperm && $fuser->rights->{$modulepart}->{$perm}->{$subperm}) { $accessallowed = 1; } $original_file = $conf->{$modulepart}->dir_output . '/' . $original_file; } else { if ($fuser->rights->{$modulepart}->lire || $fuser->rights->{$modulepart}->read) { $accessallowed = 1; } $original_file = $conf->{$modulepart}->dir_output . '/' . $original_file; } } } } if (preg_match('/^specimen/i', $original_file)) { $accessallowed = 1; } // If link to a specimen if ($fuser->admin) { $accessallowed = 1; } // If user is admin // For modules who wants to manage different levels of permissions for documents $subPermCategoryConstName = strtoupper($modulepart) . '_SUBPERMCATEGORY_FOR_DOCUMENTS'; if (!empty($conf->global->{$subPermCategoryConstName})) { $subPermCategory = $conf->global->{$subPermCategoryConstName}; if (!empty($subPermCategory) && ($fuser->rights->{$modulepart}->{$subPermCategory}->lire || $fuser->rights->{$modulepart}->{$subPermCategory}->read || $fuser->rights->{$modulepart}->{$subPermCategory}->download)) { $accessallowed = 1; } } // Define $sqlprotectagainstexternals for modules who want to protect access using a SQL query. $sqlProtectConstName = strtoupper($modulepart) . '_SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS'; if (!empty($conf->global->{$sqlProtectConstName})) { // Example: mymodule__SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS = "SELECT fk_soc FROM ".MAIN_DB_PREFIX.$modulepart." WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; eval('$sqlprotectagainstexternals = "' . $conf->global->{$sqlProtectConstName} . '";'); } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } $ret = array('accessallowed' => $accessallowed, 'sqlprotectagainstexternals' => $sqlprotectagainstexternals, 'original_file' => $original_file); return $ret; }
/** * \brief Function to build PDF on disk, then output on HTTP strem. * \param arrayofmembers Array of members informations * \param outputlangs Lang object for output language * \return int 1=ok, 0=ko */ function write_file($arrayofmembers,$outputlangs) { global $user,$conf,$langs,$mysoc,$_Avery_Labels; // Choose type (CARD by default) $this->code=empty($conf->global->ADHERENT_CARD_TYPE)?'CARD':$conf->global->ADHERENT_CARD_TYPE; $this->Tformat = $_Avery_Labels[$this->code]; if (empty($this->Tformat)) { dol_print_error('','ErrorBadTypeForCard'.$this->code); exit; } $this->type = 'pdf'; $this->format = $this->Tformat['paper-size']; if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (!class_exists('TCPDF')) $outputlangs->charset_output='ISO-8859-1'; $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("members"); $outputlangs->load("admin"); $dir = $conf->adherent->dir_temp; $file = $dir . "/tmpcards.pdf"; if (! file_exists($dir)) { if (create_exdir($dir) < 0) { $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); return 0; } } $pdf=pdf_getInstance($this->format,$this->Tformat['metric']); if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($outputlangs)); $pdf->SetTitle($outputlangs->transnoentities('MembersCards')); $pdf->SetSubject($outputlangs->transnoentities("MembersCards")); $pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->transnoentities('MembersCards')." ".$outputlangs->transnoentities("Foundation")." ".$outputlangs->convToOutputCharset($mysoc->name)); if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false); $pdf->SetMargins(0,0); $pdf->SetAutoPageBreak(false); $this->_Metric_Doc = $this->Tformat['metric']; // Permet de commencer l'impression de l'etiquette desiree dans le cas ou la page a deja servie $posX=1; $posY=1; if ($posX > 0) $posX--; else $posX=0; if ($posY > 0) $posY--; else $posY=0; $this->_COUNTX = $posX; $this->_COUNTY = $posY; $this->_Set_Format($pdf, $this->Tformat); $pdf->Open(); $pdf->AddPage(); // Add each record foreach($arrayofmembers as $val) { // imprime le texte specifique sur la carte $this->Add_PDF_card($pdf,$val['textleft'],$val['textheader'],$val['textfooter'],$langs,$val['textright'],$val['id'],$val['photo']); } //$pdf->SetXY(10, 295); //$pdf->Cell($this->_Width, $this->_Line_Height, 'XXX',0,1,'C'); // Output to file $pdf->Output($file,'F'); if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); // Output to http stream clearstatcache(); $attachment=true; if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; $filename='tmpcards.pdf'; $type=dol_mimetype($filename); if ($encoding) header('Content-Encoding: '.$encoding); if ($type) header('Content-Type: '.$type); if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); else header('Content-Disposition: inline; filename="'.$filename.'"'); // Ajout directives pour resoudre bug IE header('Cache-Control: Public, must-revalidate'); header('Pragma: public'); readfile($file); return 1; }
$listofqualifiedref = array(); foreach ($listofobjectref[$thirdpartyid] as $objectid => $object) { //var_dump($object); //var_dump($thirdpartyid.' - '.$objectid.' - '.$object->statut); if ($object->statut != Facture::STATUS_VALIDATED) { $nbignored++; continue; // Payment done or started or canceled } // Read document // TODO Use future field $object->fullpathdoc to know where is stored default file // TODO If not defined, use $object->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc. $filename = dol_sanitizeFileName($object->ref) . '.pdf'; $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref); $file = $filedir . '/' . $filename; $mime = dol_mimetype($file); if (dol_is_file($file)) { if (empty($sendto)) { $object->fetch_thirdparty(); $sendto = $object->thirdparty->email; } if (empty($sendto)) { //print "No recipient for thirdparty ".$object->thirdparty->name; $nbignored++; continue; } if (dol_strlen($sendto)) { // Create form object $attachedfiles = array('paths' => array_merge($attachedfiles['paths'], array($file)), 'names' => array_merge($attachedfiles['names'], array($filename)), 'mimes' => array_merge($attachedfiles['mimes'], array($mime))); } $listofqualifiedinvoice[$objectid] = $object;
{ // Important: Following code is to avoid page request by browser and PHP CPU at // each Dolibarr page access. if (empty($dolibarr_nocache)) { header('Cache-Control: max-age=3600, public, must-revalidate'); header('Pragma: cache'); // This is to avoid having Pragma: no-cache } else header('Cache-Control: no-cache'); //print $dolibarr_nocache; exit; } // Define mime type $type = 'application/octet-stream'; if (! empty($_GET["type"])) $type=$_GET["type"]; else $type=dol_mimetype($original_file); // Suppression de la chaine de caractere ../ dans $original_file $original_file = str_replace("../","/", $original_file); // Security checks if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart'); $accessallowed=0; if ($modulepart) { // Check permissions and define directory // Wrapping for company logo if ($modulepart == 'companylogo') { $accessallowed=1;
/** * Print selected file * * @param string $file file * @param string $module module * @param string $subdir subdir for file * @return int 0 if OK, >0 if KO */ function print_file($file, $module, $subdir = '') { require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; global $conf, $user, $db; $error = 0; $fileprint = $conf->{$module}->dir_output; if ($subdir != '') { $fileprint .= '/' . $subdir; } $fileprint .= '/' . $file; $mimetype = dol_mimetype($fileprint); // select printer uri for module order, propal,... $sql = "SELECT rowid, printer_id, copy FROM " . MAIN_DB_PREFIX . "printing WHERE module='" . $module . "' AND driver='printgcp' AND userid=" . $user->id; $result = $db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); if ($obj) { $printer_id = $obj->printer_id; } else { if (!empty($conf->global->PRINTING_GCP_DEFAULT)) { $printer_id = $conf->global->PRINTING_GCP_DEFAULT; } else { $this->errors[] = 'NoDefaultPrinterDefined'; $error++; return $error; } } } else { dol_print_error($db); } $ret = $this->sendPrintToPrinter($printer_id, $file, $fileprint, $mimetype); $this->errors = 'PRINTGCP: ' . mb_convert_encoding($ret['errormessage'], "UTF-8"); if ($ret['status'] != 1) { $error++; } return $error; }
/** * \brief Check if notification are active for couple action/company. * If yes, send mail and save trace into llx_notify. * \param action Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage) * \param socid Id of third party * \param texte Message to send * \param objet_type Type of object the notification deals on (facture, order, propal, order_supplier...). Just for log in llx_notify. * \param objet_id Id of object the notification deals on * \param file Attach a file * \return int <0 if KO, or number of changes if OK */ function send($action, $socid, $texte, $objet_type, $objet_id, $file = "") { global $conf, $langs, $mysoc, $dolibarr_main_url_root; $langs->load("other"); dol_syslog("Notify::send action={$action}, socid={$socid}, texte={$texte}, objet_type={$objet_type}, objet_id={$objet_id}, file={$file}"); $sql = "SELECT s.nom, c.email, c.rowid as cid, c.name, c.firstname,"; $sql .= " a.rowid as adid, a.label, a.code, n.rowid"; $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as c,"; $sql .= " " . MAIN_DB_PREFIX . "c_action_trigger as a,"; $sql .= " " . MAIN_DB_PREFIX . "notify_def as n,"; $sql .= " " . MAIN_DB_PREFIX . "societe as s"; $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; $sql .= " AND n.fk_soc = s.rowid"; if (is_numeric($action)) { $sql .= " AND n.fk_action = " . $action; } else { $sql .= " AND a.code = '" . $action . "'"; } // New usage $sql .= " AND s.rowid = " . $socid; dol_syslog("Notify::send sql=" . $sql); $result = $this->db->query($sql); if ($result) { $num = $this->db->num_rows($result); $i = 0; while ($i < $num) { $obj = $this->db->fetch_object($result); $sendto = $obj->firstname . " " . $obj->name . " <" . $obj->email . ">"; $actiondefid = $obj->adid; if (dol_strlen($sendto)) { include_once DOL_DOCUMENT_ROOT . '/lib/files.lib.php'; $application = $conf->global->MAIN_APPLICATION_TITLE ? $conf->global->MAIN_APPLICATION_TITLE : 'Dolibarr ERP/CRM'; $subject = '[' . $application . '] ' . $langs->transnoentitiesnoconv("DolibarrNotification"); $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name) . "\n"; $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n"; $message .= "\n"; $message .= $texte; // Add link switch ($objet_type) { case 'ficheinter': $link = DOL_URL_ROOT . '/fichinter/fiche.php?id=' . $objet_id; break; case 'propal': $link = DOL_URL_ROOT . '/comm/propal.php?id=' . $objet_id; break; case 'facture': $link = DOL_URL_ROOT . '/compta/facture.php?facid=' . $objet_id; break; case 'order': $link = DOL_URL_ROOT . '/commande/fiche.php?facid=' . $objet_id; break; case 'order_supplier': $link = DOL_URL_ROOT . '/fourn/commande/fiche.php?facid=' . $objet_id; break; } $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', $dolibarr_main_url_root); if ($link) { $message .= "\n" . $urlwithouturlroot . $link; } $filename = basename($file); $mimefile = dol_mimetype($file); $msgishtml = 0; $replyto = $conf->notification->email_from; $mailfile = new CMailFile($subject, $sendto, $replyto, $message, array($file), array($mimefile), array($filename[sizeof($filename) - 1]), '', '', 0, $msgishtml); if ($mailfile->sendfile()) { $sendto = htmlentities($sendto); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify (daten, fk_action, fk_contact, objet_type, objet_id, email)"; $sql .= " VALUES (" . $this->db->idate(mktime()) . ", " . $actiondefid . " ," . $obj->cid . " , '" . $objet_type . "', " . $objet_id . ", '" . $this->db->escape($obj->email) . "')"; dol_syslog("Notify::send sql=" . $sql); if (!$this->db->query($sql)) { dol_print_error($this->db); } } else { $this->error = $mailfile->error; //dol_syslog("Notify::send ".$this->error, LOG_ERR); } } $i++; } return $i; } else { $this->error = $this->db->error(); return -1; } }
private function handle_file_upload($uploaded_file, $name, $size, $type, $error) { $file = new stdClass(); $file->name = basename(stripslashes($name)); $file->mime = dol_mimetype($file->name,'',2); $file->size = intval($size); $file->type = $type; $error = $this->has_error($uploaded_file, $file, $error); if (!$error && $file->name && create_exdir($this->options['upload_dir']) >= 0) { if ($file->name[0] === '.') { $file->name = substr($file->name, 1); } $file_path = $this->options['upload_dir'].$file->name; $append_file = is_file($file_path) && $file->size > filesize($file_path); clearstatcache(); if ($uploaded_file && is_uploaded_file($uploaded_file)) { // multipart/formdata uploads (POST method uploads) if ($append_file) { file_put_contents( $file_path, fopen($uploaded_file, 'r'), FILE_APPEND ); } else { // FIXME problem with trigger dol_move_uploaded_file($uploaded_file, $file_path, 1, 0, 0, 1); } } else { // Non-multipart uploads (PUT method support) file_put_contents( $file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0 ); } $file_size = filesize($file_path); if ($file_size === $file->size) { $file->url = $this->options['upload_url'].rawurlencode($file->name); foreach($this->options['image_versions'] as $version => $options) { if ($this->create_scaled_image($file->name, $options)) { $tmp=explode('.',$file->name); $file->{$version.'_url'} = $options['upload_url'].rawurlencode($tmp[0].'_mini.'.$tmp[1]); } } } else if ($this->options['discard_aborted_uploads']) { unlink($file_path); $file->error = 'abort'; } $file->size = $file_size; $file->delete_url = $this->options['script_url'] .'?file='.rawurlencode($file->name).'&fk_element='.$this->fk_element.'&element='.$this->element; $file->delete_type = 'DELETE'; } else { $file->error = $error; } return $file; }