2017-06-02 20:17:08 +02:00
< ? php
/* Copyright ( C ) 2001 - 2002 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2006 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2009 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2017-06-02 20:17:08 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2017-06-02 20:17:08 +02:00
*/
/**
2019-12-15 10:02:20 +01:00
* \file htdocs / public / onlinesign / newonlinesign . php
2017-06-02 20:17:08 +02:00
* \ingroup core
* \brief File to offer a way to make an online signature for a particular Dolibarr entity
2021-12-17 17:40:30 +01:00
* Example of URL : https :// localhost / public / onlinesign / newonlinesign . php ? ref = PR ...
2017-06-02 20:17:08 +02:00
*/
2021-02-26 18:58:34 +01:00
if ( ! defined ( 'NOLOGIN' )) {
define ( " NOLOGIN " , 1 ); // This means this output page does not require to be logged.
}
if ( ! defined ( 'NOCSRFCHECK' )) {
define ( " NOCSRFCHECK " , 1 ); // We accept to go on this page from external web site.
}
if ( ! defined ( 'NOIPCHECK' )) {
define ( 'NOIPCHECK' , '1' ); // Do not check IP defined into conf $dolibarr_main_restrict_ip
}
if ( ! defined ( 'NOBROWSERNOTIF' )) {
define ( 'NOBROWSERNOTIF' , '1' );
}
2017-06-02 20:17:08 +02:00
// For MultiCompany module.
// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
2022-08-14 20:45:04 +02:00
// Because 2 entities can have the same ref.
2019-11-14 12:09:15 +01:00
$entity = ( ! empty ( $_GET [ 'entity' ]) ? ( int ) $_GET [ 'entity' ] : ( ! empty ( $_POST [ 'entity' ]) ? ( int ) $_POST [ 'entity' ] : 1 ));
2021-02-26 18:58:34 +01:00
if ( is_numeric ( $entity )) {
define ( " DOLENTITY " , $entity );
}
2017-06-02 20:17:08 +02:00
require '../../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php' ;
2022-01-04 13:33:59 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2017-06-02 20:17:08 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2020-01-27 14:11:40 +01:00
// Load translation files
2022-01-04 12:56:08 +01:00
$langs -> loadLangs ( array ( " main " , " other " , " dict " , " bills " , " companies " , " errors " , " members " , " paybox " , " propal " ));
2020-01-27 14:11:40 +01:00
2017-06-02 20:17:08 +02:00
// Security check
// No check on module enabled. Done later according to $validpaymentmethod
2020-07-30 03:50:27 +02:00
// Get parameters
2020-01-27 14:11:40 +01:00
$action = GETPOST ( 'action' , 'aZ09' );
2021-10-15 16:58:59 +02:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2022-01-07 12:22:48 +01:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
2022-01-04 12:56:08 +01:00
2021-10-15 16:58:59 +02:00
$refusepropal = GETPOST ( 'refusepropal' , 'alpha' );
2021-10-30 17:19:46 +02:00
$message = GETPOST ( 'message' , 'aZ09' );
2017-06-02 20:17:08 +02:00
// Input are:
// type ('invoice','order','contractline'),
// id (object id),
// amount (required if id is empty),
// tag (a free text, required if type is empty)
// currency (iso code)
2020-01-27 14:11:40 +01:00
$suffix = GETPOST ( " suffix " , 'aZ09' );
2019-11-14 12:09:15 +01:00
$source = GETPOST ( " source " , 'alpha' );
$ref = $REF = GETPOST ( " ref " , 'alpha' );
2017-06-02 20:17:08 +02:00
2021-02-26 18:58:34 +01:00
if ( empty ( $source )) {
$source = 'proposal' ;
}
2017-10-19 11:14:31 +02:00
2021-02-26 18:58:34 +01:00
if ( ! $action ) {
if ( $source && ! $ref ) {
2020-10-27 19:46:07 +01:00
print $langs -> trans ( 'ErrorBadParameters' ) . " - ref missing " ;
exit ;
}
2017-06-02 20:17:08 +02:00
}
2021-10-15 16:58:59 +02:00
if ( ! empty ( $refusepropal )) {
$action = " refusepropal " ;
}
2017-06-02 20:17:08 +02:00
// 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
2019-11-14 12:09:15 +01:00
$urlwithroot = DOL_MAIN_URL_ROOT ; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
2017-06-02 20:17:08 +02:00
// Complete urls for post treatment
2019-11-14 12:09:15 +01:00
$SECUREKEY = GETPOST ( " securekey " ); // Secure key
2017-06-02 20:17:08 +02:00
2021-02-26 18:58:34 +01:00
if ( ! empty ( $source )) {
2020-10-27 19:46:07 +01:00
$urlok .= 'source=' . urlencode ( $source ) . '&' ;
$urlko .= 'source=' . urlencode ( $source ) . '&' ;
2017-06-02 20:17:08 +02:00
}
2021-02-26 18:58:34 +01:00
if ( ! empty ( $REF )) {
2020-10-27 19:46:07 +01:00
$urlok .= 'ref=' . urlencode ( $REF ) . '&' ;
$urlko .= 'ref=' . urlencode ( $REF ) . '&' ;
2017-06-02 20:17:08 +02:00
}
2021-02-26 18:58:34 +01:00
if ( ! empty ( $SECUREKEY )) {
2020-10-27 19:46:07 +01:00
$urlok .= 'securekey=' . urlencode ( $SECUREKEY ) . '&' ;
$urlko .= 'securekey=' . urlencode ( $SECUREKEY ) . '&' ;
2017-06-02 20:17:08 +02:00
}
2021-02-26 18:58:34 +01:00
if ( ! empty ( $entity )) {
2019-11-14 12:09:15 +01:00
$urlok .= 'entity=' . urlencode ( $entity ) . '&' ;
$urlko .= 'entity=' . urlencode ( $entity ) . '&' ;
2017-06-02 20:17:08 +02:00
}
2019-11-14 12:09:15 +01:00
$urlok = preg_replace ( '/&$/' , '' , $urlok ); // Remove last &
$urlko = preg_replace ( '/&$/' , '' , $urlko ); // Remove last &
2017-06-02 20:17:08 +02:00
2017-10-19 11:14:31 +02:00
$creditor = $mysoc -> name ;
2017-06-02 20:17:08 +02:00
2022-01-04 12:56:08 +01:00
$type = $source ;
if ( $source == 'proposal' ) {
2022-08-14 20:45:04 +02:00
require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php' ;
2022-01-04 12:56:08 +01:00
$object = new Propal ( $db );
2022-08-14 21:41:25 +02:00
$result = $object -> fetch ( 0 , $ref , '' , $entity );
2022-01-04 12:56:08 +01:00
} else {
accessforbidden ( 'Bad value for source' );
exit ;
}
2017-06-02 20:17:08 +02:00
2021-12-25 17:08:40 +01:00
// Check securitykey
2022-01-04 12:56:08 +01:00
$securekeyseed = '' ;
if ( $source == 'proposal' ) {
$securekeyseed = $conf -> global -> PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN ;
}
2021-12-25 17:08:40 +01:00
2022-08-18 17:02:20 +02:00
if ( ! dol_verifyHash ( $securekeyseed . $type . $ref . ( empty ( $conf -> multicompany -> enabled ) ? '' : $entity ), $SECUREKEY , '0' )) {
2021-12-25 17:08:40 +01:00
http_response_code ( 403 );
print 'Bad value for securitykey. Value provided ' . dol_escape_htmltag ( $SECUREKEY ) . ' does not match expected value for ref=' . dol_escape_htmltag ( $ref );
exit ( - 1 );
}
2021-10-30 17:19:46 +02:00
2017-06-02 20:17:08 +02:00
/*
* Actions
*/
2022-01-07 12:22:48 +01:00
if ( $action == 'confirm_refusepropal' && $confirm == 'yes' ) {
2021-10-30 17:19:46 +02:00
$db -> begin ();
2021-10-18 14:28:30 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " propal " ;
2021-10-30 17:19:46 +02:00
$sql .= " SET fk_statut = " . (( int ) $object :: STATUS_NOTSIGNED ) . " , note_private = ' " . $db -> escape ( $object -> note_private ) . " ', date_signature=' " . $db -> idate ( dol_now ()) . " ' " ;
2021-10-18 14:28:30 +02:00
$sql .= " WHERE rowid = " . (( int ) $object -> id );
2021-10-30 17:19:46 +02:00
2021-10-18 14:28:30 +02:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
$resql = $db -> query ( $sql );
if ( ! $resql ) {
$error ++ ;
}
2021-10-30 17:19:46 +02:00
2021-10-18 14:28:30 +02:00
if ( ! $error ) {
$db -> commit ();
2021-10-30 17:19:46 +02:00
$message = 'refused' ;
2021-12-25 17:08:40 +01:00
setEventMessages ( " PropalRefused " , null , 'warnings' );
2022-08-29 15:57:13 +02:00
if ( method_exists ( $object , 'call_trigger' )) {
2022-09-28 14:23:28 +02:00
// Online customer is not a user, so we use the use that validates the documents
2022-08-29 15:57:13 +02:00
$user = new User ( $db );
$user -> fetch ( $object -> user_valid_id );
$result = $object -> call_trigger ( 'PROPAL_CLOSE_REFUSED' , $user );
if ( $result < 0 ) {
$error ++ ;
}
}
2021-10-18 14:28:30 +02:00
} else {
$db -> rollback ();
}
2021-10-30 17:19:46 +02:00
2021-10-18 14:28:30 +02:00
$object -> fetch ( 0 , $ref );
2017-06-02 20:17:08 +02:00
}
/*
* View
*/
2021-10-18 14:28:30 +02:00
$form = new Form ( $db );
2019-11-14 12:09:15 +01:00
$head = '' ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> MAIN_SIGN_CSS_URL )) {
$head = '<link rel="stylesheet" type="text/css" href="' . $conf -> global -> MAIN_SIGN_CSS_URL . '?lang=' . $langs -> defaultlang . '">' . " \n " ;
}
2017-06-02 20:17:08 +02:00
2019-11-14 12:09:15 +01:00
$conf -> dol_hide_topmenu = 1 ;
$conf -> dol_hide_leftmenu = 1 ;
2017-06-02 20:17:08 +02:00
2020-01-27 14:11:40 +01:00
$replacemainarea = ( empty ( $conf -> dol_hide_leftmenu ) ? '<div>' : '' ) . '<div>' ;
2020-11-07 12:47:42 +01:00
llxHeader ( $head , $langs -> trans ( " OnlineSignature " ), '' , '' , 0 , 0 , '' , '' , '' , 'onlinepaymentbody' , $replacemainarea , 1 );
2017-06-02 20:17:08 +02:00
2021-10-18 14:28:30 +02:00
if ( $action == 'refusepropal' ) {
2022-04-11 18:41:36 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?ref=' . urlencode ( $ref ) . '&securekey=' . urlencode ( $SECUREKEY ) . ( $conf -> multicompany -> enabled ? '&entity=' . $entity : '' ), $langs -> trans ( 'RefusePropal' ), $langs -> trans ( 'ConfirmRefusePropal' , $object -> ref ), 'confirm_refusepropal' , '' , '' , 1 );
2021-10-18 14:28:30 +02:00
}
2022-01-04 12:56:08 +01:00
// Check link validity for param 'source' to avoid use of the examples as value
if ( ! empty ( $source ) && in_array ( $ref , array ( 'member_ref' , 'contractline_ref' , 'invoice_ref' , 'order_ref' , 'proposal_ref' , '' ))) {
2020-10-27 19:46:07 +01:00
$langs -> load ( " errors " );
dol_print_error_email ( 'BADREFINONLINESIGNFORM' , $langs -> trans ( " ErrorBadLinkSourceSetButBadValueForRef " , $source , $ref ));
// End of page
llxFooter ();
$db -> close ();
exit ;
2017-06-02 20:17:08 +02:00
}
print '<span id="dolpaymentspan"></span>' . " \n " ;
print '<div class="center">' . " \n " ;
print '<form id="dolpaymentform" class="center" name="paymentform" action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' . " \n " ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' . " \n " ;
2017-06-02 20:17:08 +02:00
print '<input type="hidden" name="action" value="dosign">' . " \n " ;
2019-01-27 11:55:16 +01:00
print '<input type="hidden" name="tag" value="' . GETPOST ( " tag " , 'alpha' ) . '">' . " \n " ;
print '<input type="hidden" name="suffix" value="' . GETPOST ( " suffix " , 'alpha' ) . '">' . " \n " ;
2017-06-02 20:17:08 +02:00
print '<input type="hidden" name="securekey" value="' . $SECUREKEY . '">' . " \n " ;
print '<input type="hidden" name="entity" value="' . $entity . '" />' ;
2022-01-07 12:22:48 +01:00
print '<input type="hidden" name="page_y" value="" />' ;
2017-06-02 20:17:08 +02:00
print " \n " ;
print '<!-- Form to sign -->' . " \n " ;
2021-12-25 12:44:46 +01:00
print '<table id="dolpublictable" summary="Payment form" class="center">' . " \n " ;
2017-06-02 20:17:08 +02:00
2017-08-31 02:34:07 +02:00
// Show logo (search order: logo defined by ONLINE_SIGN_LOGO_suffix, then ONLINE_SIGN_LOGO_, then small company logo, large company logo, theme logo, common logo)
2017-06-02 20:17:08 +02:00
// Define logo and logosmall
2019-11-14 12:09:15 +01:00
$logosmall = $mysoc -> logo_small ;
$logo = $mysoc -> logo ;
$paramlogo = 'ONLINE_SIGN_LOGO_' . $suffix ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> $paramlogo )) {
$logosmall = $conf -> global -> $paramlogo ;
} elseif ( ! empty ( $conf -> global -> ONLINE_SIGN_LOGO )) {
$logosmall = $conf -> global -> ONLINE_SIGN_LOGO ;
}
2017-06-02 20:17:08 +02:00
//print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
// Define urllogo
2019-11-14 12:09:15 +01:00
$urllogo = '' ;
2020-01-27 14:11:40 +01:00
$urllogofull = '' ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $logosmall ) && is_readable ( $conf -> mycompany -> dir_output . '/logos/thumbs/' . $logosmall )) {
2019-11-14 12:09:15 +01:00
$urllogo = DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/thumbs/' . $logosmall );
2020-01-27 14:11:40 +01:00
$urllogofull = $dolibarr_main_url_root . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/thumbs/' . $logosmall );
2021-02-26 18:58:34 +01:00
} elseif ( ! empty ( $logo ) && is_readable ( $conf -> mycompany -> dir_output . '/logos/' . $logo )) {
2019-11-14 12:09:15 +01:00
$urllogo = DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/' . $logo );
2020-01-27 14:11:40 +01:00
$urllogofull = $dolibarr_main_url_root . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/' . $logo );
2017-06-02 20:17:08 +02:00
}
// Output html code for logo
2021-02-26 18:58:34 +01:00
if ( $urllogo ) {
2020-01-27 14:11:40 +01:00
print '<div class="backgreypublicpayment">' ;
print '<div class="logopublicpayment">' ;
print '<img id="dolpaymentlogo" src="' . $urllogo . '"' ;
print '>' ;
print '</div>' ;
if ( empty ( $conf -> global -> MAIN_HIDE_POWERED_BY )) {
2020-11-14 18:11:46 +01:00
print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">' . $langs -> trans ( " PoweredBy " ) . '<br><img class="poweredbyimg" src="' . DOL_URL_ROOT . '/theme/dolibarr_logo.svg" width="80px"></a></div>' ;
2020-01-27 14:11:40 +01:00
}
print '</div>' ;
2017-06-02 20:17:08 +02:00
}
2022-01-04 12:56:08 +01:00
if ( $source == 'proposal' && ! empty ( $conf -> global -> PROPOSAL_IMAGE_PUBLIC_SIGN )) {
2021-06-19 19:45:13 +02:00
print '<div class="backimagepublicproposalsign">' ;
2022-01-04 12:56:08 +01:00
print '<img id="idPROPOSAL_IMAGE_PUBLIC_INTERFACE" src="' . $conf -> global -> PROPOSAL_IMAGE_PUBLIC_SIGN . '">' ;
2021-06-19 19:45:13 +02:00
print '</div>' ;
2017-06-02 20:17:08 +02:00
}
// Output introduction text
2019-11-14 12:09:15 +01:00
$text = '' ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> ONLINE_SIGN_NEWFORM_TEXT )) {
2020-10-27 19:46:07 +01:00
$reg = array ();
2021-02-26 18:58:34 +01:00
if ( preg_match ( '/^\((.*)\)$/' , $conf -> global -> ONLINE_SIGN_NEWFORM_TEXT , $reg )) {
$text .= $langs -> trans ( $reg [ 1 ]) . " <br> \n " ;
} else {
$text .= $conf -> global -> ONLINE_SIGN_NEWFORM_TEXT . " <br> \n " ;
}
2020-10-27 19:46:07 +01:00
$text = '<tr><td align="center"><br>' . $text . '<br></td></tr>' . " \n " ;
2017-06-02 20:17:08 +02:00
}
2021-02-26 18:58:34 +01:00
if ( empty ( $text )) {
2020-10-27 19:46:07 +01:00
$text .= '<tr><td class="textpublicpayment"><br><strong>' . $langs -> trans ( " WelcomeOnOnlineSignaturePage " , $mysoc -> name ) . '</strong></td></tr>' . " \n " ;
2021-10-18 20:46:28 +02:00
$text .= '<tr><td class="textpublicpayment opacitymedium">' . $langs -> trans ( " ThisScreenAllowsYouToSignDocFrom " , $creditor ) . '<br><br></td></tr>' . " \n " ;
2017-06-02 20:17:08 +02:00
}
print $text ;
// Output payment summary form
print '<tr><td align="center">' ;
print '<table with="100%" id="tablepublicpayment">' ;
2020-01-27 14:11:40 +01:00
print '<tr><td align="left" colspan="2" class="opacitymedium">' . $langs -> trans ( " ThisIsInformationOnDocumentToSign " ) . ' :</td></tr>' . " \n " ;
2017-06-02 20:17:08 +02:00
2019-11-14 12:09:15 +01:00
$found = false ;
$error = 0 ;
2017-06-02 20:17:08 +02:00
2021-10-18 20:46:28 +02:00
// Signature on commercial proposal
2021-02-26 18:58:34 +01:00
if ( $source == 'proposal' ) {
2019-11-14 12:09:15 +01:00
$found = true ;
2017-10-19 11:14:31 +02:00
$langs -> load ( " proposal " );
2017-06-02 20:17:08 +02:00
2022-07-18 16:48:53 +02:00
$result = $object -> fetch_thirdparty ( $object -> socid );
2017-06-02 20:17:08 +02:00
// Creditor
2021-10-18 20:46:28 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Creditor " );
print '</td><td class="CTableRow2">' ;
print img_picto ( '' , 'company' , 'class="pictofixedwidth"' );
print '<b>' . $creditor . '</b>' ;
2020-10-27 19:46:07 +01:00
print '<input type="hidden" name="creditor" value="' . $creditor . '">' ;
print '</td></tr>' . " \n " ;
2017-06-02 20:17:08 +02:00
// Debitor
2021-10-18 20:46:28 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " ThirdParty " );
print '</td><td class="CTableRow2">' ;
print img_picto ( '' , 'company' , 'class="pictofixedwidth"' );
2022-07-18 16:48:53 +02:00
print '<b>' . $object -> thirdparty -> name . '</b>' ;
2021-10-18 20:46:28 +02:00
print '</td></tr>' . " \n " ;
2017-06-02 20:17:08 +02:00
2021-12-25 17:08:40 +01:00
// Amount
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Amount " );
print '</td><td class="CTableRow2">' ;
2022-07-18 16:48:53 +02:00
print '<b>' . price ( $object -> total_ttc , 0 , $langs , 1 , - 1 , - 1 , $conf -> currency ) . '</b>' ;
2021-12-25 17:08:40 +01:00
print '</td></tr>' . " \n " ;
2017-06-02 20:17:08 +02:00
// Object
2022-07-18 16:48:53 +02:00
$text = '<b>' . $langs -> trans ( " SignatureProposalRef " , $object -> ref ) . '</b>' ;
2022-07-10 18:06:41 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Designation " );
2021-10-18 20:46:28 +02:00
print '</td><td class="CTableRow2">' . $text ;
2022-08-14 20:45:04 +02:00
$last_main_doc_file = $object -> last_main_doc ;
2022-07-18 16:48:53 +02:00
if ( $object -> status == $object :: STATUS_VALIDATED ) {
2022-08-14 20:45:04 +02:00
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.
2022-08-14 20:03:13 +02:00
// 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 );
}
2022-07-18 16:48:53 +02:00
$directdownloadlink = $object -> getLastMainDocLink ( 'proposal' );
2021-10-18 20:46:28 +02:00
if ( $directdownloadlink ) {
print '<br><a href="' . $directdownloadlink . '">' ;
2022-07-18 16:48:53 +02:00
print img_mime ( $object -> last_main_doc , '' );
2021-10-18 20:46:28 +02:00
print $langs -> trans ( " DownloadDocument " ) . '</a>' ;
}
} else {
2022-07-18 16:48:53 +02:00
if ( $object -> status == $object :: STATUS_NOTSIGNED ) {
$directdownloadlink = $object -> getLastMainDocLink ( 'proposal' );
2022-01-07 12:22:48 +01:00
if ( $directdownloadlink ) {
print '<br><a href="' . $directdownloadlink . '">' ;
2022-08-14 20:45:04 +02:00
print img_mime ( $last_main_doc_file , '' );
2022-01-07 12:22:48 +01:00
print $langs -> trans ( " DownloadDocument " ) . '</a>' ;
}
2022-07-18 16:48:53 +02:00
} elseif ( $object -> status == $object :: STATUS_SIGNED || $object -> status == $object :: STATUS_BILLED ) {
2022-01-07 12:22:48 +01:00
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 );
$datefilesigned = dol_filemtime ( $last_main_doc_file );
$datefilenotsigned = dol_filemtime ( $last_main_doc_file_not_signed );
if ( empty ( $datefilenotsigned ) || $datefilesigned > $datefilenotsigned ) {
2022-07-18 16:48:53 +02:00
$directdownloadlink = $object -> getLastMainDocLink ( 'proposal' );
2022-01-07 12:22:48 +01:00
if ( $directdownloadlink ) {
print '<br><a href="' . $directdownloadlink . '">' ;
2022-07-18 16:48:53 +02:00
print img_mime ( $object -> last_main_doc , '' );
2022-01-07 12:22:48 +01:00
print $langs -> trans ( " DownloadDocument " ) . '</a>' ;
}
2022-01-04 13:33:59 +01:00
}
}
}
2021-10-18 20:46:28 +02:00
}
2019-01-27 11:55:16 +01:00
print '<input type="hidden" name="source" value="' . GETPOST ( " source " , 'alpha' ) . '">' ;
2022-07-18 16:48:53 +02:00
print '<input type="hidden" name="ref" value="' . $object -> ref . '">' ;
2017-06-02 20:17:08 +02:00
print '</td></tr>' . " \n " ;
}
2021-02-26 18:58:34 +01:00
if ( ! $found && ! $mesg ) {
$mesg = $langs -> transnoentitiesnoconv ( " ErrorBadParameters " );
}
2017-06-02 20:17:08 +02:00
2021-02-26 18:58:34 +01:00
if ( $mesg ) {
2021-10-18 21:20:58 +02:00
print '<tr><td class="center" colspan="2"><br><div class="warning">' . dol_escape_htmltag ( $mesg ) . '</div></td></tr>' . " \n " ;
2021-02-26 18:58:34 +01:00
}
2017-06-02 20:17:08 +02:00
print '</table>' . " \n " ;
print " \n " ;
2020-10-23 19:54:45 +02:00
if ( $action != 'dosign' ) {
2020-10-27 19:46:07 +01:00
if ( $found && ! $error ) {
// We are in a management option and no error
} else {
dol_print_error_email ( 'ERRORNEWONLINESIGN' );
}
2020-05-21 15:05:19 +02:00
} else {
2020-10-27 19:46:07 +01:00
// Print
2017-06-02 20:17:08 +02:00
}
print '</td></tr>' . " \n " ;
2021-10-18 21:20:58 +02:00
print '<tr><td class="center">' ;
2021-10-18 20:46:28 +02:00
2022-01-04 12:56:08 +01:00
2021-10-15 16:58:59 +02:00
if ( $action == " dosign " && empty ( $cancel )) {
print '<div class="tablepublicpayment">' ;
2021-10-18 20:46:28 +02:00
print '<input type="button" class="buttonDelete small" id="clearsignature" value="' . $langs -> trans ( " ClearSignature " ) . '">' ;
2021-10-18 15:35:15 +02:00
print '<div id="signature" style="border:solid;"></div>' ;
2021-10-15 16:58:59 +02:00
print '</div>' ;
2022-01-07 12:22:48 +01:00
// Do not use class="reposition" here: It breaks the submit and there is a message on top to say it's ok, so going back top is better.
2022-01-04 12:56:08 +01:00
print '<input type="button" class="button" id="signbutton" value="' . $langs -> trans ( " Sign " ) . '">' ;
2021-10-15 16:58:59 +02:00
print '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2021-12-17 17:40:30 +01:00
// Add js code managed into the div #signature
2021-10-15 16:58:59 +02:00
print '<script language="JavaScript" type="text/javascript" src="' . DOL_URL_ROOT . ' / includes / jquery / plugins / jSignature / jSignature . js " ></script>
< script type = " text/javascript " >
$ ( document ) . ready ( function () {
2021-12-25 12:44:46 +01:00
$ ( " #signature " ) . jSignature ({ color : " #000 " , lineWidth : 4 , '.(empty($conf->dol_optimize_smallscreen) ? ' ' : ' width : 280 , ' ).' height : 180 });
2021-10-15 16:58:59 +02:00
$ ( " #signature " ) . on ( " change " , function (){
$ ( " #clearsignature " ) . css ( " display " , " " );
2022-01-04 12:56:08 +01:00
$ ( " #signbutton " ) . attr ( " disabled " , false );
if ( ! $ . _data ( $ ( " #signbutton " )[ 0 ], " events " )){
$ ( " #signbutton " ) . on ( " click " , function (){
2021-10-15 16:58:59 +02:00
var signature = $ ( " #signature " ) . jSignature ( " getData " , " image " );
2021-10-18 20:46:28 +02:00
$ . ajax ({
type : " POST " ,
2021-10-15 16:58:59 +02:00
url : " '.DOL_URL_ROOT.'/core/ajax/onlineSign.php " ,
dataType : " text " ,
data : {
" action " : " importSignature " ,
" signaturebase64 " : signature ,
2021-12-25 12:44:46 +01:00
" ref " : \ '' . dol_escape_js ( $REF ) . ' \ ' ,
2021-12-25 17:08:40 +01:00
" securekey " : \ '' . dol_escape_js ( $SECUREKEY ) . ' \ ' ,
" mode " : \ '' . dol_escape_htmltag ( $source ) . ' \ ' ,
2022-04-11 18:01:25 +02:00
" entity " : \ '' . dol_escape_htmltag ( $entity ) . ' \ ' ,
2021-10-15 16:58:59 +02:00
},
success : function ( response ) {
if ( response == " success " ){
console . log ( " Success on saving signature " );
2022-04-11 18:01:25 +02:00
window . location . replace ( " '. $_SERVER["PHP_SELF"] .'?ref='.urlencode( $ref ).'&message=signed&securekey='.urlencode( $SECUREKEY ).( $conf->multicompany ->enabled?'&entity='. $entity :'').' " );
2021-10-15 16:58:59 +02:00
} else {
console . error ( response );
}
},
});
});
}
});
$ ( " #clearsignature " ) . on ( " click " , function (){
$ ( " #signature " ) . jSignature ( " clear " );
2022-01-04 12:56:08 +01:00
$ ( " #signbutton " ) . attr ( " disabled " , true );
2021-10-15 16:58:59 +02:00
});
2022-01-04 12:56:08 +01:00
$ ( " #signbutton " ) . attr ( " disabled " , true );
2021-10-15 16:58:59 +02:00
});
</ script > ' ;
} else {
2022-01-04 12:56:08 +01:00
if ( $source == 'proposal' ) {
if ( $object -> status == $object :: STATUS_SIGNED ) {
print '<br>' ;
if ( $message == 'signed' ) {
print '<span class="ok">' . $langs -> trans ( " PropalSigned " ) . '</span>' ;
} else {
print '<span class="ok">' . $langs -> trans ( " PropalAlreadySigned " ) . '</span>' ;
}
} elseif ( $object -> status == $object :: STATUS_NOTSIGNED ) {
print '<br>' ;
if ( $message == 'refused' ) {
print '<span class="ok">' . $langs -> trans ( " PropalRefused " ) . '</span>' ;
} else {
print '<span class="warning">' . $langs -> trans ( " PropalAlreadyRefused " ) . '</span>' ;
}
2021-10-30 17:19:46 +02:00
} else {
2022-01-04 12:56:08 +01:00
print '<input type="submit" class="butAction small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="' . $langs -> trans ( " SignPropal " ) . '">' ;
2022-01-07 12:22:48 +01:00
print '<input name="refusepropal" type="submit" class="butActionDelete small wraponsmartphone marginbottomonly marginleftonly marginrightonly reposition" value="' . $langs -> trans ( " RefusePropal " ) . '">' ;
2021-10-30 17:19:46 +02:00
}
2021-10-15 16:58:59 +02:00
}
}
print '</td></tr>' . " \n " ;
2017-06-02 20:17:08 +02:00
print '</table>' . " \n " ;
print '</form>' . " \n " ;
print '</div>' . " \n " ;
print '<br>' ;
2019-01-27 11:55:16 +01:00
htmlPrintOnlinePaymentFooter ( $mysoc , $langs );
2017-06-02 20:17:08 +02:00
llxFooter ( '' , 'public' );
$db -> close ();