diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 2a6a3b2cd8c..4a2f1210c51 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -3798,7 +3798,7 @@ class Propal extends CommonObject * @param int $hidedetails Hide details of lines * @param int $hidedesc Hide description * @param int $hideref Hide ref - * @param null|array $moreparams Array to provide more information + * @param null|array $moreparams Array to provide more information * @return int 0 if KO, 1 if OK */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) diff --git a/htdocs/core/ajax/onlineSign.php b/htdocs/core/ajax/onlineSign.php index 5f3cc281f90..c680c580589 100644 --- a/htdocs/core/ajax/onlineSign.php +++ b/htdocs/core/ajax/onlineSign.php @@ -53,6 +53,7 @@ if (is_numeric($entity)) { define("DOLENTITY", $entity); } include '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $action = GETPOST('action', 'aZ09'); @@ -123,9 +124,11 @@ if ($action == "importSignature") { if (!$error) { // Defined modele of doc - $directdownloadlink = $object->getLastMainDocLink('proposal'); + $last_main_doc_file = $object->last_main_doc; + $directdownloadlink = $object->getLastMainDocLink('proposal'); // url to download the $object->last_main_doc - if (preg_match('/\.pdf/i', $directdownloadlink)) { + if (preg_match('/\.pdf/i', $last_main_doc_file)) { + // TODO Use the $last_main_doc_file to defined the $newpdffilename and $sourcefile $newpdffilename = $upload_dir.$ref."_signed-".$date.".pdf"; $sourcefile = $upload_dir.$ref.".pdf"; @@ -148,8 +151,12 @@ if ($action == "importSignature") { // Index the new file and update the last_main_doc property of object. $object->indexFile($newpdffilename, 1); } + } elseif (preg_match('/\.odt/i', $last_main_doc_file)) { + // Adding signature on .ODT not yet supported + // TODO } else { - // Adding signature on doc not yet supported + // Document format not supported to insert online signature. + // We should just create an image file with the signature. } } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d7e2472f22c..7b78d9bbcb9 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1032,7 +1032,8 @@ abstract class CommonObject // Add entry into index if ($initsharekey) { require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; - // TODO We can't, we dont' have full path of file, only last_main_doc adn ->element, so we must rebuild full path first + + // TODO We can't, we dont' have full path of file, only last_main_doc and ->element, so we must first rebuild full path $destfull /* $ecmfile->filepath = $rel_dir; $ecmfile->filename = $filename; diff --git a/htdocs/public/onlinesign/newonlinesign.php b/htdocs/public/onlinesign/newonlinesign.php index 5e920444c35..db27089acb1 100644 --- a/htdocs/public/onlinesign/newonlinesign.php +++ b/htdocs/public/onlinesign/newonlinesign.php @@ -51,7 +51,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; -require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; // Load translation files $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "members", "paybox", "propal")); @@ -125,8 +124,9 @@ $creditor = $mysoc->name; $type = $source; if ($source == 'proposal') { + require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; $object = new Propal($db); - $object->fetch(0, $ref); + $result= $object->fetch(0, $ref); } else { accessforbidden('Bad value for source'); exit; @@ -290,16 +290,7 @@ if ($source == 'proposal') { $found = true; $langs->load("proposal"); - require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; - - $proposal = new Propal($db); - $result = $proposal->fetch('', $ref); - if ($result <= 0) { - $mesg = $proposal->error; - $error++; - } else { - $result = $proposal->fetch_thirdparty($proposal->socid); - } + $result = $object->fetch_thirdparty($object->socid); // Creditor @@ -315,39 +306,47 @@ if ($source == 'proposal') { print ''.$langs->trans("ThirdParty"); print ''; print img_picto('', 'company', 'class="pictofixedwidth"'); - print ''.$proposal->thirdparty->name.''; + print ''.$object->thirdparty->name.''; print ''."\n"; // Amount print ''.$langs->trans("Amount"); print ''; - print ''.price($proposal->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).''; + print ''.price($object->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).''; print ''."\n"; // Object - $text = ''.$langs->trans("SignatureProposalRef", $proposal->ref).''; + $text = ''.$langs->trans("SignatureProposalRef", $object->ref).''; print ''.$langs->trans("Designation"); print ''.$text; - if ($proposal->status == $proposal::STATUS_VALIDATED) { - $directdownloadlink = $proposal->getLastMainDocLink('proposal'); + + $last_main_doc_file = $object->last_main_doc; + + if ($object->status == $object::STATUS_VALIDATED) { + if (empty($last_main_doc_file) || !dol_is_file(DOL_DATA_ROOT.'/'.$object->last_main_doc)) { + // It seems document has never been generated, or was generated and then deleted. + // So we try to regenerate it with its default template. + $defaulttemplate = ''; // We force the use an empty string instead of $object->model_pdf to be sure to use a "main" default template and not the last one used. + $object->generateDocument($defaulttemplate, $langs); + } + + $directdownloadlink = $object->getLastMainDocLink('proposal'); if ($directdownloadlink) { print '
'; - print img_mime($proposal->last_main_doc, ''); + print img_mime($object->last_main_doc, ''); print $langs->trans("DownloadDocument").''; } } else { - $last_main_doc_file = $proposal->last_main_doc; - - if ($proposal->status == $proposal::STATUS_NOTSIGNED) { - $directdownloadlink = $proposal->getLastMainDocLink('proposal'); + if ($object->status == $object::STATUS_NOTSIGNED) { + $directdownloadlink = $object->getLastMainDocLink('proposal'); if ($directdownloadlink) { print '
'; - print img_mime($proposal->last_main_doc, ''); + print img_mime($last_main_doc_file, ''); print $langs->trans("DownloadDocument").''; } - } elseif ($proposal->status == $proposal::STATUS_SIGNED || $proposal->status == $proposal::STATUS_BILLED) { + } elseif ($object->status == $object::STATUS_SIGNED || $object->status == $object::STATUS_BILLED) { if (preg_match('/_signed-(\d+)/', $last_main_doc_file)) { // If the last main doc has been signed $last_main_doc_file_not_signed = preg_replace('/_signed-(\d+)/', '', $last_main_doc_file); @@ -355,10 +354,10 @@ if ($source == 'proposal') { $datefilenotsigned = dol_filemtime($last_main_doc_file_not_signed); if (empty($datefilenotsigned) || $datefilesigned > $datefilenotsigned) { - $directdownloadlink = $proposal->getLastMainDocLink('proposal'); + $directdownloadlink = $object->getLastMainDocLink('proposal'); if ($directdownloadlink) { print '
'; - print img_mime($proposal->last_main_doc, ''); + print img_mime($object->last_main_doc, ''); print $langs->trans("DownloadDocument").''; } } @@ -367,10 +366,8 @@ if ($source == 'proposal') { } print ''; - print ''; + print ''; print ''."\n"; - - // TODO Add link to download PDF (similar code than for invoice) }