/** * Return tableau de toutes les photos de la categorie * * @param string $dir Repertoire a scanner * @param int $nbmax Nombre maximum de photos (0=pas de max) * @return array Tableau de photos */ function liste_photos($dir, $nbmax = 0) { include_once DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php"; $nbphoto = 0; $tabobj = array(); $dirthumb = $dir . 'thumbs/'; if (file_exists($dir)) { $handle = opendir($dir); if (is_resource($handle)) { while (($file = readdir($handle)) != false) { if (dol_is_file($dir . $file) && preg_match('/(\\.jpg|\\.bmp|\\.gif|\\.png|\\.tiff)$/i', $dir . $file)) { $nbphoto++; $photo = $file; // On determine nom du fichier vignette $photo_vignette = ''; if (preg_match('/(\\.jpg|\\.bmp|\\.gif|\\.png|\\.tiff)$/i', $photo, $regs)) { $photo_vignette = preg_replace('/' . $regs[0] . '/i', '', $photo) . '_small' . $regs[0]; } // Objet $obj = array(); $obj['photo'] = $photo; if ($photo_vignette && is_file($dirthumb . $photo_vignette)) { $obj['photo_vignette'] = $photo_vignette; } else { $obj['photo_vignette'] = ""; } $tabobj[$nbphoto - 1] = $obj; // On continue ou on arrete de boucler if ($nbmax && $nbphoto >= $nbmax) { break; } } } closedir($handle); } } return $tabobj; }
print $langs->trans("DownloadPackageFromWebSite", $fullurl) . '<br>'; print '<b>' . $langs->trans("StepNb", 2) . '</b>: '; print $langs->trans("UnpackPackageInDolibarrRoot", $dolibarrroot) . '<br>'; print '<b>' . $langs->trans("StepNb", 3) . '</b>: '; print $langs->trans("RemoveLock", $dolibarrdataroot . '/install.lock') . '<br>'; print '<b>' . $langs->trans("StepNb", 4) . '</b>: '; $fullurl = '<a href="' . DOL_URL_ROOT . '/install/" target="_blank">' . DOL_URL_ROOT . '/install/</a>'; print $langs->trans("CallUpdatePage", $fullurl) . '<br>'; print '<b>' . $langs->trans("StepNb", 5) . '</b>: '; print $langs->trans("RestoreLock", $dolibarrdataroot . '/install.lock') . '<br>'; print '<br>'; print '<br>'; // Install external module $allowonlineinstall = true; $allowfromweb = 1; if (dol_is_file($dolibarrdataroot . '/installmodules.lock')) { $allowonlineinstall = false; } $fullurl = '<a href="' . $urldolibarrmodules . '" target="_blank">' . $urldolibarrmodules . '</a>'; $message = ''; if (!empty($allowonlineinstall)) { if (!in_array('/custom', explode(',', $dolibarr_main_url_root_alt))) { $message = info_admin($langs->trans("ConfFileMuseContainCustom", DOL_DOCUMENT_ROOT . '/custom', DOL_DOCUMENT_ROOT)); $allowfromweb = -1; } else { if ($dirins_ok) { if (!is_writable(dol_osencode($dirins))) { $langs->load("errors"); $message = info_admin($langs->trans("ErrorFailedToWriteInDir", $dirins)); $allowfromweb = 0; }
$mesg = $langs->trans("ErrorCanNotCreateDir", $dir); $error++; } } } $graphfiles = array('propal' => array('modulepart' => 'productstats_proposals', 'file' => $object->id . '/propal12m' . ((string) $type != '' ? '_type' . $type : '') . '_' . $mode . '.png', 'label' => $mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsProposals") : $langs->transnoentitiesnoconv("NumberOfProposals")), 'orders' => array('modulepart' => 'productstats_orders', 'file' => $object->id . '/orders12m' . ((string) $type != '' ? '_type' . $type : '') . '_' . $mode . '.png', 'label' => $mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsCustomerOrders") : $langs->transnoentitiesnoconv("NumberOfCustomerOrders")), 'invoices' => array('modulepart' => 'productstats_invoices', 'file' => $object->id . '/invoices12m' . ((string) $type != '' ? '_type' . $type : '') . '_' . $mode . '.png', 'label' => $mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsCustomerInvoices") : $langs->transnoentitiesnoconv("NumberOfCustomerInvoices")), 'orderssuppliers' => array('modulepart' => 'productstats_orderssuppliers', 'file' => $object->id . '/orderssuppliers12m' . ((string) $type != '' ? '_type' . $type : '') . '_' . $mode . '.png', 'label' => $mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsSupplierOrders") : $langs->transnoentitiesnoconv("NumberOfSupplierOrders")), 'invoicessuppliers' => array('modulepart' => 'productstats_invoicessuppliers', 'file' => $object->id . '/invoicessuppliers12m' . ((string) $type != '' ? '_type' . $type : '') . '_' . $mode . '.png', 'label' => $mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsSupplierInvoices") : $langs->transnoentitiesnoconv("NumberOfSupplierInvoices"))); $px = new DolGraph(); if (!$error) { $mesg = $px->isGraphKo(); if (!$mesg) { foreach ($graphfiles as $key => $val) { if (!$graphfiles[$key]['file']) { continue; } $graph_data = array(); if (dol_is_file($dir . '/' . $graphfiles[$key]['file'])) { // TODO Load cachefile $graphfiles[$key]['file'] } else { if ($key == 'propal') { $graph_data = $object->get_nb_propal($socid, $mode, (string) $type != '' ? $type : -1); } if ($key == 'orders') { $graph_data = $object->get_nb_order($socid, $mode, (string) $type != '' ? $type : -1); } if ($key == 'invoices') { $graph_data = $object->get_nb_vente($socid, $mode, (string) $type != '' ? $type : -1); } if ($key == 'invoicessuppliers') { $graph_data = $object->get_nb_achat($socid, $mode, (string) $type != '' ? $type : -1); } if ($key == 'orderssuppliers') {
function is_photo_available($sdir) { include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $pdir = get_exdir($this->id, 2) . $this->id . "/photos/"; $dir = $sdir . '/' . $pdir; $nbphoto = 0; $dir_osencoded = dol_osencode($dir); if (file_exists($dir_osencoded)) { $handle = opendir($dir_osencoded); if (is_resource($handle)) { while (($file = readdir($handle)) != false) { if (!utf8_check($file)) { $file = utf8_encode($file); } // To be sure data is stored in UTF8 in memory if (dol_is_file($dir . $file)) { return true; } } } } return false; }
$classname = "mod".ucfirst($generator); $module = new $classname($db); if ($module->encodingIsSupported($encoding)) { $result=$module->buildBarCode($code,$encoding,$readable); } } else // Open and return file { clearstatcache(); // Output files on browser dol_syslog("viewimage.php return file $original_file content-type=$type"); // This test is to avoid error images when image is not available (for example thumbs). if (! dol_is_file($original_file)) { $original_file=DOL_DOCUMENT_ROOT.'/theme/common/nophoto.jpg'; /*$error='Error: File '.$_GET["file"].' does not exists or filesystems permissions are not allowed'; dol_print_error(0,$error); print $error; exit;*/ } // Les drois sont ok et fichier trouve if ($type) { header('Content-Disposition: inline; filename="'.basename($original_file).'"'); header('Content-type: '.$type); } else
/** * testDolIsFileDir * * @return int */ public function testDolIsFileDir() { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $file=dirname(__FILE__).'/Example_import_company_1.csv'; $result=dol_is_file($file); print __METHOD__." result=".$result."\n"; $this->assertTrue($result); $result=dol_is_dir($file); print __METHOD__." result=".$result."\n"; $this->assertFalse($result); return $result; }
/** * Function to build a compiled PDF * * @param DoliDB $db Database handler * @param Translate $langs Object langs * @param Conf $conf Object conf * @param string $diroutputpdf Dir to output file * @param string $newlangid Lang id * @param array $filter Array with filters * @param date $dateafterdate Invoice after date * @param date $datebeforedate Invoice before date * @param date $paymentdateafter Payment after date (must includes hour) * @param date $paymentdatebefore Payment before date (must includes hour) * @param int $usestdout Add information onto standard output * @param int $regenerate ''=Use existing PDF files, 'nameofpdf'=Regenerate all PDF files using the template * @param string $filesuffix Suffix to add into file name of generated PDF * @param string $paymentbankid Only if payment on this bank account id * @param array $thirdpartiesid List of thirdparties id when using filter excludethirdpartiesid or onlythirdpartiesid * @param string $fileprefix Prefix to add into filename of generated PDF * @return int Error code */ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate = 0, $filesuffix = '', $paymentbankid = '', $thirdpartiesid = '', $fileprefix = 'mergedpdf') { $sql = "SELECT DISTINCT f.rowid, f.facnumber"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f"; $sqlwhere = ''; $sqlorder = ''; if (in_array('all', $filter)) { $sqlorder = " ORDER BY f.facnumber ASC"; } if (in_array('date', $filter)) { if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= " f.fk_statut > 0"; $sqlwhere .= " AND f.datef >= '" . $db->idate($dateafterdate) . "'"; $sqlwhere .= " AND f.datef <= '" . $db->idate($datebeforedate) . "'"; $sqlorder = " ORDER BY f.datef ASC"; } if (in_array('nopayment', $filter)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "paiement_facture as pf ON f.rowid = pf.fk_facture"; if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= " f.fk_statut > 0"; $sqlwhere .= " AND pf.fk_paiement IS NULL"; } if (in_array('payments', $filter) || in_array('bank', $filter)) { $sql .= ", " . MAIN_DB_PREFIX . "paiement_facture as pf, " . MAIN_DB_PREFIX . "paiement as p"; if (in_array('bank', $filter)) { $sql .= ", " . MAIN_DB_PREFIX . "bank as b"; } if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= " f.fk_statut > 0"; $sqlwhere .= " AND f.rowid = pf.fk_facture"; $sqlwhere .= " AND pf.fk_paiement = p.rowid"; if (in_array('payments', $filter)) { $sqlwhere .= " AND p.datep >= '" . $db->idate($paymentdateafter) . "'"; $sqlwhere .= " AND p.datep <= '" . $db->idate($paymentdatebefore) . "'"; } if (in_array('bank', $filter)) { $sqlwhere .= " AND p.fk_bank = b.rowid"; $sqlwhere .= " AND b.fk_account = " . $paymentbankid; } $sqlorder = " ORDER BY p.datep ASC"; } if (in_array('nodeposit', $filter)) { if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= ' type <> 3'; } if (in_array('noreplacement', $filter)) { if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= ' type <> 1'; } if (in_array('nocreditnote', $filter)) { if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= ' type <> 2'; } if (in_array('excludethirdparties', $filter) && is_array($thirdpartiesid)) { if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= ' f.fk_soc NOT IN (' . join(',', $thirdpartiesid) . ')'; } if (in_array('onlythirdparties', $filter) && is_array($thirdpartiesid)) { if (empty($sqlwhere)) { $sqlwhere = ' WHERE '; } else { $sqlwhere .= " AND"; } $sqlwhere .= ' f.fk_soc IN (' . join(',', $thirdpartiesid) . ')'; } if ($sqlwhere) { $sql .= $sqlwhere; } if ($sqlorder) { $sql .= $sqlorder; } //print $sql; exit; dol_syslog("scripts/invoices/rebuild_merge.php:", LOG_DEBUG); if ($usestdout) { print '--- start' . "\n"; } // Start of transaction //$db->begin(); $error = 0; $result = 0; $files = array(); // liste les fichiers dol_syslog("scripts/invoices/rebuild_merge.php", LOG_DEBUG); if ($resql = $db->query($sql)) { $num = $db->num_rows($resql); $cpt = 0; $oldemail = ''; $message = ''; $total = ''; if ($num) { // First loop on each resultset to build PDF // ----------------------------------------- while ($cpt < $num) { $obj = $db->fetch_object($resql); $fac = new Facture($db); $result = $fac->fetch($obj->rowid); if ($result > 0) { $outputlangs = $langs; if (!empty($newlangid)) { if ($outputlangs->defaultlang != $newlangid) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlangid); } } $filename = $conf->facture->dir_output . '/' . $fac->ref . '/' . $fac->ref . '.pdf'; if ($regenerate || !dol_is_file($filename)) { if ($usestdout) { print "Build PDF for invoice " . $obj->facnumber . " - Lang = " . $outputlangs->defaultlang . "\n"; } $result = $fac->generateDocument($regenerate ? $regenerate : $fac->modelpdf, $outputlangs); } else { if ($usestdout) { print "PDF for invoice " . $obj->facnumber . " already exists\n"; } } // Add file into files array $files[] = $filename; } if ($result <= 0) { $error++; if ($usestdout) { print "Error: Failed to build PDF for invoice " . ($fac->ref ? $fac->ref : ' id ' . $obj->rowid) . "\n"; } else { dol_syslog("Failed to build PDF for invoice " . ($fac->ref ? $fac->ref : ' id ' . $obj->rowid), LOG_ERR); } } $cpt++; } // Define format of output PDF $formatarray = pdf_getFormat($langs); $page_largeur = $formatarray['width']; $page_hauteur = $formatarray['height']; $format = array($page_largeur, $page_hauteur); if ($usestdout) { print "Using output PDF format " . join('x', $format) . "\n"; } else { dol_syslog("Using output PDF format " . join('x', $format), LOG_ERR); } // Now, build a merged files with all files in $files array //--------------------------------------------------------- // Create empty PDF $pdf = pdf_getInstance($format); if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($langs)); if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) { $pdf->SetCompression(false); } //$pdf->SetCompression(false); // Add all others foreach ($files as $file) { if ($usestdout) { print "Merge PDF file for invoice " . $file . "\n"; } else { dol_syslog("Merge PDF file for invoice " . $file); } // Charge un document PDF depuis un fichier. $pagecount = $pdf->setSourceFile($file); for ($i = 1; $i <= $pagecount; $i++) { $tplidx = $pdf->importPage($i); $s = $pdf->getTemplatesize($tplidx); $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); $pdf->useTemplate($tplidx); } } // Create output dir if not exists dol_mkdir($diroutputpdf); // Save merged file $filename = $fileprefix; if (empty($filename)) { $filename = 'mergedpdf'; } if (!empty($filesuffix)) { $filename .= '_' . $filesuffix; } $file = $diroutputpdf . '/' . $filename . '.pdf'; if (!$error && $pagecount) { $pdf->Output($file, 'F'); if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } } if ($usestdout) { if (!$error) { print "Merged PDF has been built in " . $file . "\n"; } else { print "Can't build PDF " . $file . "\n"; } } $result = 1; } else { if ($usestdout) { print "No invoices found for criteria.\n"; } else { dol_syslog("No invoices found for criteria"); } $result = 0; } } else { dol_print_error($db); dol_syslog("scripts/invoices/rebuild_merge.php: Error"); $error++; } if ($error) { return -1; } else { return $result; } }
break; } } // Load barcode class for generating barcode image $classname = "mod" . ucfirst($generator); $module = new $classname($db); if ($generator != 'tcpdfbarcode') { // May be phpbarcode $template = 'standardlabel'; $is2d = false; if ($module->encodingIsSupported($encoding)) { $barcodeimage = $conf->barcode->dir_temp . '/barcode_' . $code . '_' . $encoding . '.png'; dol_delete_file($barcodeimage); // File is created with full name $barcodeimage = $conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png'; $result = $module->writeBarCode($code, $encoding, 'Y', 4, 1); if ($result <= 0 || !dol_is_file($barcodeimage)) { $error++; setEventMessages('Failed to generate image file of barcode for code=' . $code . ' encoding=' . $encoding . ' file=' . basename($barcodeimage), null, 'errors'); setEventMessages($module->error, null, 'errors'); } } else { $error++; setEventMessages("Error, encoding " . $encoding . " is not supported by encoder " . $generator . '. You must choose another barcode type or install a barcode generation engine that support ' . $encoding, null, 'errors'); } } else { $template = 'tcpdflabel'; $encoding = $module->getTcpdfEncodingType($encoding); //convert to TCPDF compatible encoding types $is2d = $module->is2d; } }
/** * Move a file into another name. * This function differs from dol_move_uploaded_file, because it can be called in any context. * * @param string $srcfile Source file (can't be a directory. use native php @rename() to move a directory) * @param string $destfile Destination file (can't be a directory. use native php @rename() to move a directory) * @param integer $newmask Mask in octal string for new file (0 by default means $conf->global->MAIN_UMASK) * @param int $overwriteifexists Overwrite file if exists (1 by default) * @return boolean True if OK, false if KO */ function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1) { global $conf; $result = false; dol_syslog("files.lib.php::dol_move srcfile=" . $srcfile . " destfile=" . $destfile . " newmask=" . $newmask . " overwritifexists=" . $overwriteifexists); $destexists = dol_is_file($destfile); if ($overwriteifexists || !$destexists) { $newpathofsrcfile = dol_osencode($srcfile); $newpathofdestfile = dol_osencode($destfile); $result = @rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ if (!$result) { if ($destexists) { dol_syslog("files.lib.php::dol_move failed. We try to delete first and move after.", LOG_WARNING); // We force delete and try again. Rename function sometimes fails to replace dest file with some windows NTFS partitions. dol_delete_file($destfile); $result = @rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ } else { dol_syslog("files.lib.php::dol_move failed", LOG_WARNING); } } if (empty($newmask)) { $newmask = empty($conf->global->MAIN_UMASK) ? '0755' : $conf->global->MAIN_UMASK; } $newmaskdec = octdec($newmask); // Currently method is restricted to files (dol_delete_files previously used is for files, and mask usage if for files too) // to allow mask usage for dir, we shoul introduce a new param "isdir" to 1 to complete newmask like this // if ($isdir) $newmaskdec |= octdec('0111'); // Set x bit required for directories @chmod($newpathofdestfile, $newmaskdec); } return $result; }
/** * Common function for all objects extending CommonObject for generating documents * * @param string $modelspath Relative folder where generators are placed * @param string $modele Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example. * @param Translate $outputlangs Language to use * @param int $hidedetails 1 to hide details. 0 by default * @param int $hidedesc 1 to hide product description. 0 by default * @param int $hideref 1 to hide product reference. 0 by default * @return int >0 if OK, <0 if KO */ protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref) { global $conf, $langs; $srctemplatepath = ''; // Increase limit for PDF build $err = error_reporting(); error_reporting(0); @set_time_limit(120); error_reporting($err); // If selected model is a filename template (then $modele="modelname" or "modelname:filename") $tmp = explode(':', $modele, 2); if (!empty($tmp[1])) { $modele = $tmp[0]; $srctemplatepath = $tmp[1]; } // Search template files $file = ''; $classname = ''; $filefound = 0; $dirmodels = array('/'); if (is_array($conf->modules_parts['models'])) { $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']); } foreach ($dirmodels as $reldir) { foreach (array('doc', 'pdf') as $prefix) { $file = $prefix . "_" . $modele . ".modules.php"; // On verifie l'emplacement du modele $file = dol_buildpath($reldir . $modelspath . $file, 0); if (file_exists($file)) { $filefound = 1; $classname = $prefix . '_' . $modele; break; } } if ($filefound) { break; } } // If generator was found if ($filefound) { require_once $file; $obj = new $classname($this->db); // If generator is ODT, we must have srctemplatepath defined, if not we set it. if ($obj->type == 'odt' && empty($srctemplatepath)) { $varfortemplatedir = $obj->scandir; if ($varfortemplatedir && !empty($conf->global->{$varfortemplatedir})) { $dirtoscan = $conf->global->{$varfortemplatedir}; $listoffiles = array(); // Now we add first model found in directories scanned $listofdir = explode(',', $dirtoscan); foreach ($listofdir as $key => $tmpdir) { $tmpdir = trim($tmpdir); $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); if (!$tmpdir) { unset($listofdir[$key]); continue; } if (is_dir($tmpdir)) { $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\\.od(s|t)$', '', 'name', SORT_ASC, 0); if (count($tmpfiles)) { $listoffiles = array_merge($listoffiles, $tmpfiles); } } } if (count($listoffiles)) { foreach ($listoffiles as $record) { $srctemplatepath = $record['fullname']; break; } } } if (empty($srctemplatepath)) { $this->error = 'ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; return -1; } } if ($obj->type == 'odt' && !empty($srctemplatepath)) { if (!dol_is_file($srctemplatepath)) { $this->error = 'ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; return -1; } } // We save charset_output to restore it because write_file can change it if needed for // output format that does not support UTF8. $sav_charset_output = $outputlangs->charset_output; if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) { $outputlangs->charset_output = $sav_charset_output; // We delete old preview require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; dol_delete_preview($this); // Success in building document. We build meta file. dol_meta_create($this); return 1; } else { $outputlangs->charset_output = $sav_charset_output; dol_print_error($this->db, "Error generating document for " . __CLASS__ . ". Error: " . $obj->error, $obj->errors); return -1; } } else { $this->error = $langs->trans("Error") . " " . $langs->trans("ErrorFileDoesNotExists", $file); dol_print_error('', $this->error); return -1; } }
/** * Move a file into another name * @param $srcfile Source file (can't be a directory) * @param $destfile Destination file (can't be a directory) * @param $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK) * @param $overwriteifexists Overwrite file if exists (1 by default) * @return boolean True if OK, false if KO */ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1) { global $conf; $result=false; dol_syslog("files.lib.php::dol_move srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwritifexists=".$overwriteifexists); if ($overwriteifexists || ! dol_is_file($destfile)) { $newpathofsrcfile=dol_osencode($srcfile); $newpathofdestfile=dol_osencode($destfile); $result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ if (! $result) dol_syslog("files.lib.php::dol_move failed", LOG_WARNING); if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; @chmod($newpathofsrcfile, octdec($newmask)); } return $result; }
/** * Move a file into another name. * This function differs from dol_move_uploaded_file, because it can be called in any context. * * @param string $srcfile Source file (can't be a directory) * @param string $destfile Destination file (can't be a directory) * @param string $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK) * @param int $overwriteifexists Overwrite file if exists (1 by default) * @return boolean True if OK, false if KO */ function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1) { global $conf; $result = false; dol_syslog("files.lib.php::dol_move srcfile=" . $srcfile . " destfile=" . $destfile . " newmask=" . $newmask . " overwritifexists=" . $overwriteifexists); $destexists = dol_is_file($destfile); if ($overwriteifexists || !$destexists) { $newpathofsrcfile = dol_osencode($srcfile); $newpathofdestfile = dol_osencode($destfile); $result = @rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ if (!$result) { if ($destexists) { dol_syslog("files.lib.php::dol_move failed. We try to delete first and move after.", LOG_WARNING); // We force delete and try again. Rename function sometimes fails to replace dest file with some windows NTFS partitions. dol_delete_file($destfile); $result = @rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ } else { dol_syslog("files.lib.php::dol_move failed", LOG_WARNING); } } if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) { $newmask = $conf->global->MAIN_UMASK; } @chmod($newpathofsrcfile, octdec($newmask)); } return $result; }
$module = new $classname($db); if ($module->encodingIsSupported($encoding)) { $result=$module->buildBarCode($code,$encoding,$readable); } } else // Open and return file { clearstatcache(); // Output files on browser dol_syslog("viewimage.php return file $original_file content-type=$type"); $original_file_osencoded=dol_osencode($original_file); // This test if file exists should be useless. We keep it to find bug more easily if (! dol_is_file($original_file_osencoded)) { $error='Error: File '.$_GET["file"].' does not exists or filesystems permissions are not allowed'; dol_print_error(0,$error); print $error; exit; } // Les drois sont ok et fichier trouve if ($type) { header('Content-Disposition: inline; filename="'.basename($original_file).'"'); header('Content-type: '.$type); } else {
/** * Retourne tableau de toutes les photos du produit * * @param string $dir Repertoire a scanner * @param int $nbmax Nombre maximum de photos (0=pas de max) * @return array Tableau de photos */ function liste_photos($dir, $nbmax = 0) { include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $nbphoto = 0; $tabobj = array(); $dir_osencoded = dol_osencode($dir); $handle = @opendir($dir_osencoded); if (is_resource($handle)) { while (($file = readdir($handle)) != false) { if (!utf8_check($file)) { $file = utf8_encode($file); } // readdir returns ISO if (dol_is_file($dir . $file) && preg_match('/(' . $this->regeximgext . ')$/i', $dir . $file)) { $nbphoto++; // On determine nom du fichier vignette $photo = $file; $photo_vignette = ''; if (preg_match('/(' . $this->regeximgext . ')$/i', $photo, $regs)) { $photo_vignette = preg_replace('/' . $regs[0] . '/i', '', $photo) . '_small' . $regs[0]; } $dirthumb = $dir . 'thumbs/'; // Objet $obj = array(); $obj['photo'] = $photo; if ($photo_vignette && dol_is_file($dirthumb . $photo_vignette)) { $obj['photo_vignette'] = 'thumbs/' . $photo_vignette; } else { $obj['photo_vignette'] = ""; } $tabobj[$nbphoto - 1] = $obj; // On continue ou on arrete de boucler ? if ($nbmax && $nbphoto >= $nbmax) { break; } } } closedir($handle); } return $tabobj; }
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; $listofqualifiedref[$objectid] = $object->ref;
/** * Migrate file from old path to new one for product $product * * @param Product $product Object product * @return void */ function migrate_product_photospath($product) { global $conf; $dir = $conf->product->multidir_output[$product->entity]; $origin = $dir . '/' . get_exdir($product->id, 2) . $product->id . "/photos"; $destin = $dir . '/' . dol_sanitizeFileName($product->ref); $error = 0; $origin_osencoded = dol_osencode($origin); $destin_osencoded = dol_osencode($destin); dol_mkdir($destin); if (dol_is_dir($origin)) { $handle = opendir($origin_osencoded); if (is_resource($handle)) { while (($file = readdir($handle)) != false) { if ($file != '.' && $file != '..' && is_dir($origin_osencoded . '/' . $file)) { $thumbs = opendir($origin_osencoded . '/' . $file); if (is_resource($thumbs)) { dol_mkdir($destin . '/' . $file); while (($thumb = readdir($thumbs)) != false) { dol_move($origin . '/' . $file . '/' . $thumb, $destin . '/' . $file . '/' . $thumb); } // dol_delete_dir($origin.'/'.$file); } } else { if (dol_is_file($origin . '/' . $file)) { dol_move($origin . '/' . $file, $destin . '/' . $file); } } } } } }
$fac = new Facture($db); $result=$fac->fetch($obj->rowid); if ($result > 0) { $outputlangs = $langs; if (! empty($newlangid)) { if ($outputlangs->defaultlang != $newlangid) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlangid); } } $filename=$conf->facture->dir_output.'/'.$fac->ref.'/'.$fac->ref.'.pdf'; if ($regenerate || ! dol_is_file($filename)) { print "Build PDF for invoice ".$obj->facnumber." - Lang = ".$outputlangs->defaultlang."\n"; $result=facture_pdf_create($db, $fac, $newmodel?$newmodel:$fac->modelpdf, $outputlangs); } else { print "PDF for invoice ".$obj->facnumber." already exists\n"; } // Add file into files array $files[] = $filename; } if ($result <= 0) { print "Error: Failed to build PDF for invoice ".$fac->ref."\n";
$outputlangs->load("banks"); $outputlangs->load("members"); $outputlangs->load("compta"); $acct = new Account($db); $result = $acct->fetch('', $bankref); if ($result <= 0) { print "Failed to find bank account with ref " . $bankref . ".\n"; exit(-1); } else { print "Export for bank account " . $acct->ref . " (" . $acct->label . ").\n"; } // Creation de la classe d'export du model ExportXXX $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/"; $file = "export_" . $model . ".modules.php"; $classname = "Export" . $model; if (!dol_is_file($dir . $file)) { print "No driver to export with format " . $model . "\n"; exit(-1); } require_once $dir . $file; $objmodel = new $classname($db); // Define target path $dirname = $conf->banque->dir_temp; $filename = 'export-bank-receipts-' . $bankref . '-' . $num . '.' . $objmodel->extension; $array_fields = array('bankreceipt' => $outputlangs->transnoentitiesnoconv("AccountStatementShort"), 'bankaccount' => $outputlangs->transnoentitiesnoconv("BankAccount"), 'dateop' => $outputlangs->transnoentitiesnoconv("DateOperationShort"), 'dateval' => $outputlangs->transnoentitiesnoconv("DateValueShort"), 'type' => $outputlangs->transnoentitiesnoconv("Type"), 'description' => $outputlangs->transnoentitiesnoconv("Description"), 'thirdparty' => $outputlangs->transnoentitiesnoconv("Tiers"), 'accountelem' => $outputlangs->transnoentitiesnoconv("Piece"), 'debit' => $outputlangs->transnoentitiesnoconv("Debit"), 'credit' => $outputlangs->transnoentitiesnoconv("Credit"), 'soldbefore' => $outputlangs->transnoentitiesnoconv("BankBalanceBefore"), 'soldafter' => $outputlangs->transnoentitiesnoconv("BankBalanceAfter"), 'comment' => $outputlangs->transnoentitiesnoconv("Comment")); $array_selected = array('bankreceipt' => 'bankreceipt', 'bankaccount' => 'bankaccount', 'dateop' => 'dateop', 'dateval' => 'dateval', 'type' => 'type', 'description' => 'description', 'thirdparty' => 'thirdparty', 'accountelem' => 'accountelem', 'debit' => 'debit', 'credit' => 'credit', 'soldbefore' => 'soldbefore', 'soldafter' => 'soldafter', 'comment' => 'comment'); $array_export_TypeFields = array('bankreceipt' => 'Text', 'bankaccount' => 'Text', 'dateop' => 'Date', 'dateval' => 'Date', 'type' => 'Text', 'description' => 'Text', 'thirdparty' => 'Text', 'accountelem' => 'Text', 'debit' => 'Number', 'credit' => 'Number', 'soldbefore' => 'Number', 'soldafter' => 'Number', 'comment' => 'Text'); // Build request to find records for a bank account/receipt $listofnum = ""; if (!empty($num) && $num != "all") { $listofnum .= "'";
/** * 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; } }
$exists=dol_is_file($filetotest); print 'Check thirdparty '.$obj->rowid.' name='.$obj->name.' logo='.$obj->logo.' file '.$filetotest." exists=".$exists."<br>\n"; if ($exists) { $filetarget=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/'.$name.$ext; $filetargetsmall=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs/'.$name.'_small'.$ext; $existt=dol_is_file($filetarget); if (! $existt) { dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos'); print " -> Copy file ".$filetotest." -> ".$filetarget."<br>\n"; dol_copy($filetotest, $filetarget, '', 0); } $existtt=dol_is_file($filetargetsmall); if (! $existtt) { dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs'); print " -> Copy file ".$filetotestsmall." -> ".$filetargetsmall."<br>\n"; dol_copy($filetotestsmall, $filetargetsmall, '', 0); } } } $i++; } } else {
/** * Test export function for all dataset predefined into modules * * @depends testExportPersonalizedWithFilter * @return void */ public function testExportModulesDatasets() { global $conf, $user, $langs, $db; $model = 'csv'; $filterdatatoexport = ''; //$filterdatatoexport=''; //$array_selected = array("s.rowid"=>1, "s.nom"=>2); // Mut be fields found into declaration of dataset // Load properties of arrays to make export $objexport = new Export($db); $result = $objexport->load_arrays($user, $filterdatatoexport); // This load ->array_export_xxx properties for datatoexport // Loop on each dataset foreach ($objexport->array_export_code as $key => $datatoexport) { $exportfile = $conf->export->dir_temp . '/' . $user->id . '/export_' . $datatoexport . '.csv'; print "Process export for dataset " . $datatoexport . " into " . $exportfile . "\n"; dol_delete_file($exportfile); // Generate $array_selected $i = 0; $array_selected = array(); foreach ($objexport->array_export_fields[$key] as $key => $val) { $array_selected[$key] = $i++; } //var_dump($array_selected); // Build export file $sql = ""; $result = $objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); $expectedresult = 1; $this->assertEquals($result, $expectedresult, 'Call build_file to export ' . $exportfile . ' failed'); $result = dol_is_file($exportfile); $this->assertTrue($result, $expectedresult, 'File ' . $exportfile . ' not found'); } return true; }