From e46faacac1d99c8a82eee26a0bcee616e3347936 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 2 Jun 2021 18:11:47 +0200 Subject: [PATCH 01/17] FIX : Add process payment with online link order --- htdocs/public/payment/paymentok.php | 101 ++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index f4b9f0feb5b..5f8f90ba72b 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -721,6 +721,107 @@ if ($ispaymentok) $postactionmessages[] = 'Invoice paid '.$tmptag['INV'].' was not found'; $ispostactionok = -1; } + } elseif (array_key_exists('ORD', $tmptag) && $tmptag['ORD'] > 0) { + // Record payment + include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; + $object = new Commande($db); + $result = $object->fetch($tmptag['ORD']); + if ($result) { + $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"]; + + $paymentTypeId = 0; + if ($paymentmethod == 'paybox') $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS; + if ($paymentmethod == 'paypal') $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS; + if ($paymentmethod == 'stripe') $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS; + if (empty($paymentTypeId)) { + $paymentType = $_SESSION["paymentType"]; + if (empty($paymentType)) $paymentType = 'CB'; + $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1); + } + + $currencyCodeType = $_SESSION['currencyCodeType']; + + // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time) + if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) { + include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; + $invoice = new Facture($db); + $result = $invoice->createFromOrder($object, $user); + if ($result > 0) { + $object->classifyBilled($user); + $invoice->validate($user); + // Creation of payment line + include_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; + $paiement = new Paiement($db); + $paiement->datepaye = $now; + if ($currencyCodeType == $conf->currency) { + $paiement->amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id + } else { + $paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching + + $postactionmessages[] = 'Payment was done in a different currency that currency expected of company'; + $ispostactionok = -1; + $error++; // Not yet supported + } + $paiement->paiementid = $paymentTypeId; + $paiement->num_payment = ''; + $paiement->note_public = 'Online payment ' . dol_print_date($now, 'standard') . ' from ' . $ipaddress; + $paiement->ext_payment_id = $TRANSACTIONID; + $paiement->ext_payment_site = $service; + + if (!$error) { + $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents + if ($paiement_id < 0) { + $postactionmessages[] = $paiement->error . ' ' . join("
\n", $paiement->errors); + $ispostactionok = -1; + $error++; + } else { + $postactionmessages[] = 'Payment created'; + $ispostactionok = 1; + } + } + + if (!$error && !empty($conf->banque->enabled)) { + $bankaccountid = 0; + if ($paymentmethod == 'paybox') $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS; + elseif ($paymentmethod == 'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS; + elseif ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS; + + if ($bankaccountid > 0) { + $label = '(CustomerInvoicePayment)'; + if ($object->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note + $result = $paiement->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', ''); + if ($result < 0) { + $postactionmessages[] = $paiement->error . ' ' . join("
\n", $paiement->errors); + $ispostactionok = -1; + $error++; + } else { + $postactionmessages[] = 'Bank transaction of payment created'; + $ispostactionok = 1; + } + } else { + $postactionmessages[] = 'Setup of bank account to use in module ' . $paymentmethod . ' was not set. No way to record the payment.'; + $ispostactionok = -1; + $error++; + } + } + + if (!$error) { + $db->commit(); + } else { + $db->rollback(); + } + } else { + $postactionmessages[] = 'Failed to create invoice form order ' . $tmptag['ORD'] . '.'; + $ispostactionok = -1; + } + } else { + $postactionmessages[] = 'Failed to get a valid value for "amount paid" (' . $FinalPaymentAmt . ') or "payment type" (' . $paymentType . ') to record the payment of order ' . $tmptag['ORD'] . '. May be payment was already recorded.'; + $ispostactionok = -1; + } + } else { + $postactionmessages[] = 'Order paid ' . $tmptag['ORD'] . ' was not found'; + $ispostactionok = -1; + } } else { // Nothing done } From 4e1fe23b7e1a83d34b45c51348968d415626085c Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 9 Jun 2021 15:48:31 +0200 Subject: [PATCH 02/17] FIX: add check display payment link if invoice module is enabled --- htdocs/commande/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 1ef37552f1f..4913731efb5 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2633,7 +2633,7 @@ if ($action == 'create' && $usercancreate) $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList); // Show online payment link - $useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled)); + $useonlinepayment = ((!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled)) && !empty($conf->facture->enabled)); if (!empty($conf->global->ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER)) $useonlinepayment = 0; if ($object->statut != Commande::STATUS_DRAFT && $useonlinepayment) { From 9b71f1e16b5d699c6f0375f0fc192509b585325c Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 1 Jul 2021 11:55:06 +0200 Subject: [PATCH 03/17] fix : move check if invoice module is enabled into paymentok.php --- htdocs/commande/card.php | 2 +- htdocs/public/payment/paymentok.php | 119 +++++++++++++++------------- 2 files changed, 63 insertions(+), 58 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 4913731efb5..1ef37552f1f 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2633,7 +2633,7 @@ if ($action == 'create' && $usercancreate) $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList); // Show online payment link - $useonlinepayment = ((!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled)) && !empty($conf->facture->enabled)); + $useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled)); if (!empty($conf->global->ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER)) $useonlinepayment = 0; if ($object->statut != Commande::STATUS_DRAFT && $useonlinepayment) { diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 5f8f90ba72b..d6d4da28c9e 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -742,80 +742,85 @@ if ($ispaymentok) $currencyCodeType = $_SESSION['currencyCodeType']; // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time) - if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) { - include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; - $invoice = new Facture($db); - $result = $invoice->createFromOrder($object, $user); - if ($result > 0) { - $object->classifyBilled($user); - $invoice->validate($user); - // Creation of payment line - include_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; - $paiement = new Paiement($db); - $paiement->datepaye = $now; - if ($currencyCodeType == $conf->currency) { - $paiement->amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id - } else { - $paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching - - $postactionmessages[] = 'Payment was done in a different currency that currency expected of company'; - $ispostactionok = -1; - $error++; // Not yet supported - } - $paiement->paiementid = $paymentTypeId; - $paiement->num_payment = ''; - $paiement->note_public = 'Online payment ' . dol_print_date($now, 'standard') . ' from ' . $ipaddress; - $paiement->ext_payment_id = $TRANSACTIONID; - $paiement->ext_payment_site = $service; - - if (!$error) { - $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents - if ($paiement_id < 0) { - $postactionmessages[] = $paiement->error . ' ' . join("
\n", $paiement->errors); - $ispostactionok = -1; - $error++; + if (!empty($conf->banque->enabled)) { + if (!empty($FinalPaymentAmt) && $paymentTypeId > 0 ) { + include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; + $invoice = new Facture($db); + $result = $invoice->createFromOrder($object, $user); + if ($result > 0) { + $object->classifyBilled($user); + $invoice->validate($user); + // Creation of payment line + include_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; + $paiement = new Paiement($db); + $paiement->datepaye = $now; + if ($currencyCodeType == $conf->currency) { + $paiement->amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id } else { - $postactionmessages[] = 'Payment created'; - $ispostactionok = 1; + $paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching + + $postactionmessages[] = 'Payment was done in a different currency that currency expected of company'; + $ispostactionok = -1; + $error++; // Not yet supported } - } + $paiement->paiementid = $paymentTypeId; + $paiement->num_payment = ''; + $paiement->note_public = 'Online payment ' . dol_print_date($now, 'standard') . ' from ' . $ipaddress; + $paiement->ext_payment_id = $TRANSACTIONID; + $paiement->ext_payment_site = ''; - if (!$error && !empty($conf->banque->enabled)) { - $bankaccountid = 0; - if ($paymentmethod == 'paybox') $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS; - elseif ($paymentmethod == 'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS; - elseif ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS; - - if ($bankaccountid > 0) { - $label = '(CustomerInvoicePayment)'; - if ($object->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note - $result = $paiement->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', ''); - if ($result < 0) { + if (!$error) { + $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents + if ($paiement_id < 0) { $postactionmessages[] = $paiement->error . ' ' . join("
\n", $paiement->errors); $ispostactionok = -1; $error++; } else { - $postactionmessages[] = 'Bank transaction of payment created'; + $postactionmessages[] = 'Payment created'; $ispostactionok = 1; } - } else { - $postactionmessages[] = 'Setup of bank account to use in module ' . $paymentmethod . ' was not set. No way to record the payment.'; - $ispostactionok = -1; - $error++; } - } - if (!$error) { - $db->commit(); + if (!$error && !empty($conf->banque->enabled)) { + $bankaccountid = 0; + if ($paymentmethod == 'paybox') $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS; + elseif ($paymentmethod == 'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS; + elseif ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS; + + if ($bankaccountid > 0) { + $label = '(CustomerInvoicePayment)'; + if ($object->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note + $result = $paiement->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', ''); + if ($result < 0) { + $postactionmessages[] = $paiement->error . ' ' . join("
\n", $paiement->errors); + $ispostactionok = -1; + $error++; + } else { + $postactionmessages[] = 'Bank transaction of payment created'; + $ispostactionok = 1; + } + } else { + $postactionmessages[] = 'Setup of bank account to use in module ' . $paymentmethod . ' was not set. No way to record the payment.'; + $ispostactionok = -1; + $error++; + } + } + + if (!$error) { + $db->commit(); + } else { + $db->rollback(); + } } else { - $db->rollback(); + $postactionmessages[] = 'Failed to create invoice form order ' . $tmptag['ORD'] . '.'; + $ispostactionok = -1; } } else { - $postactionmessages[] = 'Failed to create invoice form order ' . $tmptag['ORD'] . '.'; + $postactionmessages[] = 'Failed to get a valid value for "amount paid" (' . $FinalPaymentAmt . ') or "payment type" (' . $paymentType . ') to record the payment of order ' . $tmptag['ORD'] . '. May be payment was already recorded.'; $ispostactionok = -1; } } else { - $postactionmessages[] = 'Failed to get a valid value for "amount paid" (' . $FinalPaymentAmt . ') or "payment type" (' . $paymentType . ') to record the payment of order ' . $tmptag['ORD'] . '. May be payment was already recorded.'; + $postactionmessages[] = 'Invoice module is not enable'; $ispostactionok = -1; } } else { From 3e6eeeb977fca91c09e645cf8718ee05d50e6365 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 1 Jul 2021 11:59:00 +0200 Subject: [PATCH 04/17] fix : remove comments --- htdocs/public/payment/paymentok.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index d6d4da28c9e..18fef28d1c2 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -722,7 +722,6 @@ if ($ispaymentok) $ispostactionok = -1; } } elseif (array_key_exists('ORD', $tmptag) && $tmptag['ORD'] > 0) { - // Record payment include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; $object = new Commande($db); $result = $object->fetch($tmptag['ORD']); @@ -761,7 +760,7 @@ if ($ispaymentok) $postactionmessages[] = 'Payment was done in a different currency that currency expected of company'; $ispostactionok = -1; - $error++; // Not yet supported + $error++; } $paiement->paiementid = $paymentTypeId; $paiement->num_payment = ''; From b102dc619fad8f7c679c930fd5520f4bb06d7aaf Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 1 Jul 2021 10:15:55 +0000 Subject: [PATCH 05/17] Fixing style errors. --- htdocs/public/payment/paymentok.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 71c338cb6fc..5bb3f4de0fc 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -916,17 +916,17 @@ if ($ispaymentok) { } } else { $postactionmessages[] = 'Order paid ' . $tmptag['ORD'] . ' was not found'; - $ispostactionok = -1; - } - } elseif (array_key_exists('DON', $tmptag) && $tmptag['DON'] > 0) { + $ispostactionok = -1; + } + } elseif (array_key_exists('DON', $tmptag) && $tmptag['DON'] > 0) { include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; $don = new Don($db); $result = $don->fetch($tmptag['DON']); - if ($result) { + if ($result) { $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"]; - - $paymentTypeId = 0; - if ($paymentmethod == 'paybox') { + + $paymentTypeId = 0; + if ($paymentmethod == 'paybox') { $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS; } if ($paymentmethod == 'paypal') { @@ -940,9 +940,9 @@ if ($ispaymentok) { if (empty($paymentType)) { $paymentType = 'CB'; } - $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1); + $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1); } - + $currencyCodeType = $_SESSION['currencyCodeType']; // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time) From 079608fe00c1296787ba57fb7734c7fdee5f33af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20David?= Date: Fri, 2 Jul 2021 10:26:03 +0200 Subject: [PATCH 06/17] NEW #18046 Add ticket ticket categories functions --- htdocs/categories/class/categorie.class.php | 13 +- htdocs/core/class/html.form.class.php | 219 ++++++++++++++++++++ htdocs/core/class/html.formticket.class.php | 9 + htdocs/core/modules/modTicket.class.php | 13 ++ htdocs/ticket/class/ticket.class.php | 45 ++++ 5 files changed, 296 insertions(+), 3 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index b98cff5b3a5..caeab5b8ddd 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -34,6 +34,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; @@ -56,6 +57,7 @@ class Categorie extends CommonObject const TYPE_WAREHOUSE = 'warehouse'; const TYPE_ACTIONCOMM = 'actioncomm'; const TYPE_WEBSITE_PAGE = 'website_page'; + const TYPE_TICKET = 'ticket'; /** * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png @@ -78,7 +80,8 @@ class Categorie extends CommonObject 'bank_line' => 8, 'warehouse' => 9, 'actioncomm' => 10, - 'website_page' => 11 + 'website_page' => 11, + 'ticket' => 12 ); /** @@ -98,7 +101,8 @@ class Categorie extends CommonObject 8 => 'bank_line', 9 => 'warehouse', 10 => 'actioncomm', - 11 => 'website_page' + 11 => 'website_page', + 12 => 'ticket' ); /** @@ -141,7 +145,8 @@ class Categorie extends CommonObject 'project' => 'Project', 'warehouse'=> 'Entrepot', 'actioncomm' => 'ActionComm', - 'website_page' => 'WebsitePage' + 'website_page' => 'WebsitePage', + 'ticket' => 'Ticket' ); /** @@ -234,6 +239,8 @@ class Categorie extends CommonObject * @see Categorie::TYPE_WAREHOUSE * @see Categorie::TYPE_ACTIONCOMM * @see Categorie::TYPE_WEBSITE_PAGE + * @see Categorie::TYPE_TICKET + */ public $type; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 0b1504d229a..2d648ef1fd9 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6578,6 +6578,225 @@ class Form return; } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return list of tickets in Ajax if Ajax activated or go to select_tickets_list + * + * @param int $selected Preselected tickets + * @param string $htmlname Name of HTML select field (must be unique in page). + * @param int $limit Limit on number of returned lines + * @param int $status Ticket status + * @param string $selected_input_value Value of preselected input text (for use with ajax) + * @param int $hidelabel Hide label (0=no, 1=yes, 2=show search icon (before) and placeholder, 3 search icon after) + * @param array $ajaxoptions Options for ajax_autocompleter + * @param int $socid Thirdparty Id (to get also price dedicated to this customer) + * @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text. + * @param int $forcecombo Force to use combo box + * @param string $morecss Add more css on select + * @param array $selected_combinations Selected combinations. Format: array([attrid] => attrval, [...]) + * @param string $nooutput No print, return the output into a string + * @return void|string + */ + public function select_tickets($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 0, $status = 1, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $selected_combinations = null, $nooutput = 0) + { + // phpcs:enable + global $langs, $conf; + + $out = ''; + + // check parameters + if (is_null($ajaxoptions)) $ajaxoptions = array(); + + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->TICKET_USE_SEARCH_TO_SELECT)) + { + $placeholder = ''; + + if ($selected && empty($selected_input_value)) + { + require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php'; + $tickettmpselect = new Ticket($this->db); + $tickettmpselect->fetch($selected); + $selected_input_value = $tickettmpselect->ref; + unset($tickettmpselect); + } + + $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/ticket/ajax/tickets.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions); + + if (empty($hidelabel)) $out .= $langs->trans("RefOrLabel").' : '; + elseif ($hidelabel > 1) { + $placeholder = ' placeholder="'.$langs->trans("RefOrLabel").'"'; + if ($hidelabel == 2) { + $out .= img_picto($langs->trans("Search"), 'search'); + } + } + $out .= 'global->PRODUCT_SEARCH_AUTOFOCUS) ? 'autofocus' : '').' />'; + if ($hidelabel == 3) { + $out .= img_picto($langs->trans("Search"), 'search'); + } + } else { + $out .= $this->select_tickets_list($selected, $htmlname, $filtertype, $limit, $status, 0, $socid, $showempty, $forcecombo, $morecss); + } + + if (empty($nooutput)) print $out; + else return $out; + } + + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return list of tickets. + * Called by select_tickets. + * + * @param int $selected Preselected ticket + * @param string $htmlname Name of select html + * @param string $filtertype Filter on ticket type + * @param int $limit Limit on number of returned lines + * @param string $filterkey Filter on product + * @param int $status Ticket status + * @param int $outputmode 0=HTML select string, 1=Array + * @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text. + * @param int $forcecombo Force to use combo box + * @param string $morecss Add more css on select + * @return array Array of keys for json + */ + public function select_tickets_list($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '') + { + // phpcs:enable + global $langs, $conf, $user, $db; + + $out = ''; + $outarray = array(); + + $selectFields = " p.rowid, p.ref, p.message"; + + $sql = "SELECT "; + $sql .= $selectFields; + $sql .= " FROM ".MAIN_DB_PREFIX."ticket as p"; + $sql .= ' WHERE p.entity IN ('.getEntity('ticket').')'; + + // Add criteria on ref/label + if ($filterkey != '') + { + $sql .= ' AND ('; + $prefix = empty($conf->global->TICKET_DONOTSEARCH_ANYWHERE) ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on + // For natural search + $scrit = explode(' ', $filterkey); + $i = 0; + if (count($scrit) > 1) $sql .= "("; + foreach ($scrit as $crit) + { + if ($i > 0) $sql .= " AND "; + $sql .= "(p.ref LIKE '".$this->db->escape($prefix.$crit)."%' OR p.label LIKE '".$this->db->escape($prefix.$crit)."%'"; + $sql .= ")"; + $i++; + } + if (count($scrit) > 1) $sql .= ")"; + $sql .= ')'; + } + + $sql .= $this->db->plimit($limit, 0); + + // Build output string + dol_syslog(get_class($this)."::select_tickets_list search tickets", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php'; + + $num = $this->db->num_rows($result); + + $events = null; + + if (!$forcecombo) + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; + $out .= ajax_combobox($htmlname, $events, $conf->global->TICKET_USE_SEARCH_TO_SELECT); + } + + $out .= ''; + + $this->db->free($result); + + if (empty($outputmode)) return $out; + return $outarray; + } else { + dol_print_error($db); + } + } + + /** + * constructTicketListOption. + * This define value for &$opt and &$optJson. + * + * @param resource $objp Result set of fetch + * @param string $opt Option (var used for returned value in string option format) + * @param string $optJson Option (var used for returned value in json format) + * @param string $selected Preselected value + * @param string $filterkey Filter key to highlight + * @return void + */ + protected function constructTicketListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '') + { + global $langs, $conf, $user, $db; + + $outkey = ''; + $outval = ''; + $outref = ''; + $outlabel = ''; + $outtype = ''; + + $label = $objp->label; + + $outkey = $objp->rowid; + $outref = $objp->ref; + $outlabel = $objp->label; + $outtype = $objp->fk_product_type; + + $opt = '\n"; + $optJson = array('key'=>$outkey, 'value'=>$outref, 'type'=>$outtypem); + } + /** * Generic method to select a component from a combo list. diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index daafa88333f..2178a02cb89 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -272,6 +272,15 @@ class FormTicket print ''; } + //Categories + if ($conf->categorie->enabled) { + // Categories + print ''.$langs->trans("Categories").''; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_TICKET, '', 'parent', 64, 0, 1); + print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, GETPOST('categories', 'array'), '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0); + print ""; + } + // Attached files if (!empty($this->withfile)) { // Define list of attached files diff --git a/htdocs/core/modules/modTicket.class.php b/htdocs/core/modules/modTicket.class.php index 8b1a1dc8525..2a717ae4f42 100644 --- a/htdocs/core/modules/modTicket.class.php +++ b/htdocs/core/modules/modTicket.class.php @@ -283,6 +283,19 @@ class modTicket extends DolibarrModules 'target' => '', 'user' => 0); $r++; + + $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=ticket', + 'type' => 'left', + 'titre' => 'Categories', + 'mainmenu' => 'ticket', + 'url' => '/categories/index.php?type=12', + 'langs' => 'ticket', + 'position' => 107, + 'enabled' => '$conf->categorie->enabled', + 'perms' => '$user->rights->ticket->read', + 'target' => '', + 'user' => 0); + $r++; } /** diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 89f239db6c6..36d90c5519d 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -2497,6 +2497,51 @@ class Ticket extends CommonObject return array('listofpaths'=>$listofpaths, 'listofnames'=>$listofnames, 'listofmimes'=>$mimetype); } + /** + * Sets object to supplied categories. + * + * Deletes object from existing categories not supplied. + * Adds it to non existing supplied categories. + * Existing categories are left untouch. + * + * @param int[]|int $categories Category or categories IDs + * @return void + */ + public function setCategories($categories) + { + // Handle single category + if (!is_array($categories)) { + $categories = array($categories); + } + + // Get current categories + include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + $c = new Categorie($this->db); + $existing = $c->containing($this->id, Categorie::TYPE_TICKET, 'id'); + + // Diff + if (is_array($existing)) { + $to_del = array_diff($existing, $categories); + $to_add = array_diff($categories, $existing); + } else { + $to_del = array(); // Nothing to delete + $to_add = $categories; + } + + // Process + foreach ($to_del as $del) { + if ($c->fetch($del) > 0) { + $c->del_type($this, Categorie::TYPE_TICKET); + } + } + foreach ($to_add as $add) { + if ($c->fetch($add) > 0) { + $c->add_type($this, Categorie::TYPE_TICKET); + } + } + + return; + } /** * Add new message on a ticket (private/public area). Can also send it be email if GETPOST('send_email', 'int') is set. From 642d84a844db1666e6d8102f897aae43ef2100cd Mon Sep 17 00:00:00 2001 From: David Date: Mon, 12 Jul 2021 09:26:18 +0200 Subject: [PATCH 07/17] fix: code syntax --- htdocs/core/class/html.form.class.php | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index a569785863c..5ef8d804a6b 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6588,6 +6588,7 @@ class Form * * @param int $selected Preselected tickets * @param string $htmlname Name of HTML select field (must be unique in page). + * @param string $filtertype To add a filter * @param int $limit Limit on number of returned lines * @param int $status Ticket status * @param string $selected_input_value Value of preselected input text (for use with ajax) @@ -6611,12 +6612,10 @@ class Form // check parameters if (is_null($ajaxoptions)) $ajaxoptions = array(); - if (!empty($conf->use_javascript_ajax) && !empty($conf->global->TICKET_USE_SEARCH_TO_SELECT)) - { + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->TICKET_USE_SEARCH_TO_SELECT)) { $placeholder = ''; - if ($selected && empty($selected_input_value)) - { + if ($selected && empty($selected_input_value)) { require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php'; $tickettmpselect = new Ticket($this->db); $tickettmpselect->fetch($selected); @@ -6679,16 +6678,14 @@ class Form $sql .= ' WHERE p.entity IN ('.getEntity('ticket').')'; // Add criteria on ref/label - if ($filterkey != '') - { + if ($filterkey != '') { $sql .= ' AND ('; $prefix = empty($conf->global->TICKET_DONOTSEARCH_ANYWHERE) ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on // For natural search $scrit = explode(' ', $filterkey); $i = 0; if (count($scrit) > 1) $sql .= "("; - foreach ($scrit as $crit) - { + foreach ($scrit as $crit) { if ($i > 0) $sql .= " AND "; $sql .= "(p.ref LIKE '".$this->db->escape($prefix.$crit)."%' OR p.label LIKE '".$this->db->escape($prefix.$crit)."%'"; $sql .= ")"; @@ -6703,8 +6700,7 @@ class Form // Build output string dol_syslog(get_class($this)."::select_tickets_list search tickets", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { + if ($result) { require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php'; @@ -6712,8 +6708,7 @@ class Form $events = null; - if (!$forcecombo) - { + if (!$forcecombo) { include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; $out .= ajax_combobox($htmlname, $events, $conf->global->TICKET_USE_SEARCH_TO_SELECT); } @@ -6723,8 +6718,7 @@ class Form $textifempty = ''; // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. //if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty=''; - if (!empty($conf->global->TICKET_USE_SEARCH_TO_SELECT)) - { + if (!empty($conf->global->TICKET_USE_SEARCH_TO_SELECT)) { if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty); else $textifempty .= $langs->trans("All"); } else { @@ -6733,8 +6727,7 @@ class Form if ($showempty) $out .= ''; $i = 0; - while ($num && $i < $num) - { + while ($num && $i < $num) { $opt = ''; $optJson = array(); $objp = $this->db->fetch_object($result); From b59c1f1a3487fb334c824802b69c5a6d5736752f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20David?= Date: Mon, 12 Jul 2021 14:17:30 +0200 Subject: [PATCH 08/17] fix: rename select_tickets into selectTickets --- htdocs/core/class/html.form.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 5ef8d804a6b..23a6b724d14 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6582,7 +6582,6 @@ class Form return; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return list of tickets in Ajax if Ajax activated or go to select_tickets_list * @@ -6602,7 +6601,7 @@ class Form * @param string $nooutput No print, return the output into a string * @return void|string */ - public function select_tickets($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 0, $status = 1, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $selected_combinations = null, $nooutput = 0) + public function selectTickets($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 0, $status = 1, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $selected_combinations = null, $nooutput = 0) { // phpcs:enable global $langs, $conf; @@ -6648,7 +6647,7 @@ class Form // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return list of tickets. - * Called by select_tickets. + * Called by selectTickets. * * @param int $selected Preselected ticket * @param string $htmlname Name of select html From 12e327d6b4055711ef667999059d0aa27f02809e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20David?= Date: Mon, 12 Jul 2021 14:37:07 +0200 Subject: [PATCH 09/17] fix: remove phpcs:enable tag --- htdocs/core/class/html.form.class.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 23a6b724d14..cbb1f09f3d8 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6663,7 +6663,6 @@ class Form */ public function select_tickets_list($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '') { - // phpcs:enable global $langs, $conf, $user, $db; $out = ''; @@ -6738,7 +6737,6 @@ class Form $out .= $opt; array_push($outarray, $optJson); - $i++; } From bbce0f9c1bd89fda1c3774599d141d2a6e4a2bfc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Jul 2021 13:01:34 +0200 Subject: [PATCH 10/17] Update html.form.class.php --- htdocs/core/class/html.form.class.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index cbb1f09f3d8..8c588cfb2e4 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4454,7 +4454,6 @@ class Form */ public function selectEstablishments($selected = '', $htmlname = 'entity', $status = 0, $filtre = '', $useempty = 0, $moreattrib = '') { - // phpcs:enable global $langs, $conf; $langs->load("admin"); @@ -6603,7 +6602,6 @@ class Form */ public function selectTickets($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 0, $status = 1, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $selected_combinations = null, $nooutput = 0) { - // phpcs:enable global $langs, $conf; $out = ''; From 66f38d001265fa8441fdd7c51ca6f4fbbc5fb495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20David?= Date: Tue, 13 Jul 2021 14:00:16 +0200 Subject: [PATCH 11/17] fix: rename select_tickets_list into selectTicketsList --- htdocs/core/class/html.form.class.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 8c588cfb2e4..482b1672d51 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6582,7 +6582,7 @@ class Form } /** - * Return list of tickets in Ajax if Ajax activated or go to select_tickets_list + * Return list of tickets in Ajax if Ajax activated or go to selectTicketsList * * @param int $selected Preselected tickets * @param string $htmlname Name of HTML select field (must be unique in page). @@ -6634,7 +6634,7 @@ class Form $out .= img_picto($langs->trans("Search"), 'search'); } } else { - $out .= $this->select_tickets_list($selected, $htmlname, $filtertype, $limit, $status, 0, $socid, $showempty, $forcecombo, $morecss); + $out .= $this->selectTicketsList($selected, $htmlname, $filtertype, $limit, $status, 0, $socid, $showempty, $forcecombo, $morecss); } if (empty($nooutput)) print $out; @@ -6642,7 +6642,6 @@ class Form } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return list of tickets. * Called by selectTickets. @@ -6659,7 +6658,7 @@ class Form * @param string $morecss Add more css on select * @return array Array of keys for json */ - public function select_tickets_list($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '') + public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '') { global $langs, $conf, $user, $db; @@ -6694,7 +6693,7 @@ class Form $sql .= $this->db->plimit($limit, 0); // Build output string - dol_syslog(get_class($this)."::select_tickets_list search tickets", LOG_DEBUG); + dol_syslog(get_class($this)."::selectTicketsList search tickets", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php'; From 9a12b5e424fb061d3650f7be2352ccb92037e5e1 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Tue, 13 Jul 2021 15:17:01 +0200 Subject: [PATCH 12/17] Fix : remove of a button which was forgotten --- htdocs/core/class/html.formticket.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index 48c861fdd95..9383c0a6e78 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -701,7 +701,6 @@ class FormTicket $stringtoprint .= ''; $stringtoprint .= ''; } - $stringtoprint .= ''; $stringtoprint .= ' '; $levelid = 1; From 1a330e0b887657c4d9a1596b84979c2508d52c01 Mon Sep 17 00:00:00 2001 From: ATM john Date: Wed, 14 Jul 2021 00:02:55 +0200 Subject: [PATCH 13/17] Fix dialog BTN and add doc --- htdocs/core/js/lib_foot.js.php | 13 +- htdocs/core/lib/functions.lib.php | 5 +- htdocs/public/test/badges.php | 21 +--- htdocs/public/test/buttons.php | 196 ++++++++++++++++++++++++++++++ 4 files changed, 214 insertions(+), 21 deletions(-) create mode 100644 htdocs/public/test/buttons.php diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index beb2788ca24..00f161a31ef 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -263,6 +263,8 @@ print '$( document ).ready(function() { var confirmContent = $(this).attr(\'data-confirm-content\'); var confirmActionBtnLabel = $(this).attr(\'data-confirm-action-btn-label\'); var confirmCancelBtnLabel = $(this).attr(\'data-confirm-cancel-btn-label\'); + var confirmModal = $(this).attr(\'data-confirm-modal\'); + if(confirmModal == undefined){ confirmModal = false; } var confirmId = \'confirm-dialog-box\'; if($(this).attr(\'id\') != undefined){ var confirmId = confirmId + "-" + $(this).attr(\'id\'); } @@ -277,8 +279,9 @@ print '$( document ).ready(function() { $confirmBox.dialog({ autoOpen: true, - modal: false, + modal: confirmModal, //width: Math.min($( window ).width() - 50, 1700), + width: \'auto\', dialogClass: \'confirm-dialog-box\', buttons: [ { @@ -297,11 +300,11 @@ print '$( document ).ready(function() { } ], close: function( event, ui ) { - $(\'#\'+confirmBox).remove(); -}, + $(\'#\'+confirmBox).remove(); + }, open: function( event, ui ) { - $confirmBox.html(confirmContent); -} + $confirmBox.html(confirmContent); + } }); }); }); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 7f69dfb8609..9107f9514e4 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9818,7 +9818,7 @@ function dolGetButtonAction($label, $html = '', $actionType = 'default', $url = } // Js Confirm button - if (!empty($params['confirm'])) { + if ($userRight && !empty($params['confirm'])) { if (!is_array($params['confirm'])) { $params['confirm'] = array( 'url' => $url . (strpos($url, '?') > 0 ? '&' : '?') . 'confirm=yes' @@ -9829,8 +9829,11 @@ function dolGetButtonAction($label, $html = '', $actionType = 'default', $url = $attr['data-confirm-url'] = $params['confirm']['url']; $attr['data-confirm-title'] = !empty($params['confirm']['title']) ? $params['confirm']['title'] : $langs->trans('ConfirmBtnCommonTitle', $label); $attr['data-confirm-content'] = !empty($params['confirm']['content']) ? $params['confirm']['content'] : $langs->trans('ConfirmBtnCommonContent', $label); + $attr['data-confirm-content'] = preg_replace("/\r|\n/", "", $attr['data-confirm-content']); $attr['data-confirm-action-btn-label'] = !empty($params['confirm']['action-btn-label']) ? $params['confirm']['action-btn-label'] : $langs->trans('Confirm'); $attr['data-confirm-cancel-btn-label'] = !empty($params['confirm']['cancel-btn-label']) ? $params['confirm']['cancel-btn-label'] : $langs->trans('CloseDialog'); + $attr['data-confirm-modal'] = !empty($params['confirm']['modal']) ? $params['confirm']['modal'] : true; + $attr['class'].= ' butActionConfirm'; } diff --git a/htdocs/public/test/badges.php b/htdocs/public/test/badges.php index fd0add00af1..2190b96db7e 100644 --- a/htdocs/public/test/badges.php +++ b/htdocs/public/test/badges.php @@ -20,7 +20,9 @@ if (!defined('NOREQUIREAJAX')) { if (!defined('NOSESSION')) { define('NOSESSION', '1'); } - +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} session_cache_limiter('public'); require_once '../../main.inc.php'; @@ -30,19 +32,9 @@ if ($dolibarr_main_prod) { accessforbidden(); } + +llxHeader('', 'Documentation and examples for theme'); ?> - - - - - - - - - - - -

Badges

Documentation and examples for badges, our small count and labeling component.

@@ -342,5 +334,4 @@ if ($dolibarr_main_prod) {
- - \ No newline at end of file + +
+

Button for action

+

Documentation and examples for buttons.

+ +

Example of simple usage

+ +

Buttons for user allowed to click.

+ +
+ My default action'; + $actionType = 'default'; + $n++; + $id = 'mybuttonid'.$n; + $url = '#'.$id; + $userRight = 1; + $params = array(); + + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight); + + + $html = ' My delete action'; + $actionType = 'delete'; + $n++; + $id = 'mybuttonid'.$n; + $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id; + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight); + + + $html = ' My danger action'; + $actionType = 'danger'; + $n++; + $id = 'mybuttonid'.$n; + $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id; + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight); + + ?> +
+ +

Buttons for user NOT allowed to click.

+ +
+ My default action'; + $actionType = 'default'; + $n++; + $id = 'mybuttonid'.$n; + $url = '#'.$id; + $userRight = 0; + + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight); + + + $html = ' My delete action'; + $actionType = 'delete'; + $n++; + $id = 'mybuttonid'.$n; + $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id; + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight); + + + $html = ' My danger action'; + $actionType = 'danger'; + $n++; + $id = 'mybuttonid'.$n; + $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id; + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight); + + ?> +
+ + +

Example of confirm dialog

+ +

Buttons for user allowed to click.

+ +
+ My default action'; + $actionType = 'default'; + $n++; + $id = 'mybuttonid'.$n; + $url = '#'.$id; + $userRight = 1; + $params = array( + 'confirm' => true + ); + + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params); + + + $html = ' My delete action'; + $actionType = 'delete'; + $n++; + $id = 'mybuttonid'.$n; + $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id; + + $params = array( + 'confirm' => array( + 'url' => 'your confirm action url', + 'title' => 'Your title to display', + 'action-btn-label' => 'Your confirm label', + 'cancel-btn-label' => 'Your cancel label', + 'content' => 'Content to display with HTML compatible
  • test 01
  • test 02
  • test 03
' + ) + ); + + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params); + + ?> +
+ +

Buttons for user NOT allowed to click.

+ +
+ My default action'; + $actionType = 'default'; + $n++; + $id = 'mybuttonid'.$n; + $url = '#'.$id; + $userRight = 0; + $params = array( + 'confirm' => true + ); + + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params); + + + $html = ' My delete action'; + $actionType = 'delete'; + $n++; + $id = 'mybuttonid'.$n; + $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id; + + $params = array( + 'confirm' => array( + 'url' => 'your confirm action url', + 'title' => 'Your title to display', + 'action-btn-label' => 'Your confirm label', + 'cancel-btn-label' => 'Your cancel label', + 'content' => 'Content to display with HTML compatible
  • test 01
  • test 02
  • test 03
' + ) + ); + + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params); + + ?> +
+ + +
+ + Date: Wed, 14 Jul 2021 10:07:03 +0200 Subject: [PATCH 14/17] Add php doc --- htdocs/core/lib/functions.lib.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 9107f9514e4..26da9ee3d21 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9770,7 +9770,23 @@ function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $st * @param string $url the url for link * @param string $id attribute id of button * @param int $userRight user action right - * @param array $params various params for future : recommended rather than adding more function arguments + * // phpcs:disable + * @param array $params = [ // Various params for future : recommended rather than adding more function arguments + * 'attr' => [ // to add or override button attributes + * 'xxxxx' => '', // your xxxxx attribute you want + * 'class' => '', // to add more css class to the button class attribute + * 'classOverride' => '' // to replace class attribute of the button + * ], + * 'confirm' => [ + * 'url' => 'http://', // Overide Url to go when user click on action btn, if empty default url is $url.?confirm=yes, for no js compatibility use $url for fallback confirm. + * 'title' => '', // Overide title of modal, if empty default title use "ConfirmBtnCommonTitle" lang key + * 'action-btn-label' => '', // Overide label of action button, if empty default label use "Confirm" lang key + * 'cancel-btn-label' => '', // Overide label of cancel button, if empty default label use "CloseDialog" lang key + * 'content' => '', // Overide text of content, if empty default content use "ConfirmBtnCommonContent" lang key + * 'modal' => true, // true|false to display dialog as a modal (with dark background) + * ], + * ] + * // phpcs:enable * @return string html button */ function dolGetButtonAction($label, $html = '', $actionType = 'default', $url = '', $id = '', $userRight = 1, $params = array()) From 7406f2cc85a109e875bf2f81c45ab6f14032cdf2 Mon Sep 17 00:00:00 2001 From: BENKE Charlene <1179011+defrance@users.noreply.github.com> Date: Wed, 14 Jul 2021 12:55:33 +0200 Subject: [PATCH 15/17] a interventional drafts on commercial index --- htdocs/comm/index.php | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index 9d0d9f1befc..609e43ff765 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -497,6 +497,50 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU } } + +/* + * Draft interventionals + */ +if (!empty($conf->ficheinter->enabled)) { + $sql = "SELECT f.rowid, f.ref, s.nom as name, s.rowid as socid"; + $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f"; + $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } + $sql .= " WHERE f.entity IN (".getEntity('intervention').")"; + $sql .= " AND f.fk_soc = s.rowid"; + $sql .= " AND f.fk_statut = 0"; + if ($socid) { + $sql .= " AND f.fk_soc = ".$socid; + } + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + } + + $resql = $db->query($sql); + if ($resql) { + print '
'; + print ''; + print ''; + print ''; + $langs->load("fichinter"); + $num = $db->num_rows($resql); + if ($num) { + $i = 0; + while ($i < $num) { + $obj = $db->fetch_object($resql); + print ''; + print '"; + print ''; + $i++; + } + } + print "
'.$langs->trans("DraftFichinter").'
'; + print "rowid."\">".img_object($langs->trans("ShowFichinter"), "intervention").' '.$obj->ref."'.img_object($langs->trans("ShowCompany"), "company").' '.dol_trunc($obj->name, 24).'
"; + } +} + print '
'; print '
'; From 0fd980b00593d1dacf234545e9cbbb44c0a15258 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Jul 2021 13:57:17 +0200 Subject: [PATCH 16/17] Update index.php --- htdocs/comm/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index 609e43ff765..11accdb3f0a 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -512,10 +512,10 @@ if (!empty($conf->ficheinter->enabled)) { $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.fk_statut = 0"; if ($socid) { - $sql .= " AND f.fk_soc = ".$socid; + $sql .= " AND f.fk_soc = ".((int) $socid); } if (!$user->rights->societe->client->voir && !$socid) { - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } $resql = $db->query($sql); From b2425c2a9d2d91ffa0e796e11920c7257a7b367e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Jul 2021 14:04:44 +0200 Subject: [PATCH 17/17] Update paymentok.php --- htdocs/public/payment/paymentok.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 5bb3f4de0fc..f5d1e60a3fc 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -833,7 +833,7 @@ if ($ispaymentok) { $currencyCodeType = $_SESSION['currencyCodeType']; // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time) - if (!empty($conf->banque->enabled)) { + if (!empty($conf->facture->enabled)) { if (!empty($FinalPaymentAmt) && $paymentTypeId > 0 ) { include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; $invoice = new Facture($db);