From 7bda345c7f04ea84f0bfe58f2c6d4f425abec89a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 6 May 2009 18:07:34 +0000 Subject: [PATCH] Qual: Use a so much simpler way to have ajax confirmation boxes --- htdocs/commande/fiche.php | 26 +++++++-------- htdocs/contrat/contrat.class.php | 31 +++++++++++------- htdocs/contrat/fiche.php | 53 +++++++++++++++++-------------- htdocs/html.form.class.php | 47 ++++++++++++++++++++------- htdocs/langs/en_US/contracts.lang | 2 ++ htdocs/langs/fr_FR/contracts.lang | 2 ++ 6 files changed, 102 insertions(+), 59 deletions(-) diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index cab7c300ba9..533a6be3766 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -70,7 +70,7 @@ if ($_GET["projetid"]) /******************************************************************************/ // Action clone object -if ($_POST["action"] == 'confirm_clone' && $_POST['confirm'] == 'yes') +if ($_REQUEST["action"] == 'confirm_clone' && $_REQUEST['confirm'] == 'yes') { if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"])) { @@ -1203,7 +1203,7 @@ else */ if ($_GET['action'] == 'delete') { - $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete'); + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1); if ($ret == 'html') print '
'; } @@ -1224,7 +1224,7 @@ else } $text=$langs->trans('ConfirmValidateOrder',$num); - $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_validate'); + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', '', 0, 1); if ($ret == 'html') print '
'; } @@ -1233,7 +1233,7 @@ else */ if ($_GET['action'] == 'close') { - $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_close'); + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_close', '', 0, 1); if ($ret == 'html') print '
'; } @@ -1242,7 +1242,7 @@ else */ if ($_GET['action'] == 'cancel') { - $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('Cancel'), $langs->trans('ConfirmCancelOrder'), 'confirm_cancel'); + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('Cancel'), $langs->trans('ConfirmCancelOrder'), 'confirm_cancel', '', 0, 1); if ($ret == 'html') print '
'; } @@ -1251,7 +1251,7 @@ else */ if ($_GET['action'] == 'ask_deleteline' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) { - $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline'); + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1); if ($ret == 'html') print '
'; } @@ -1264,7 +1264,7 @@ else //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1) ); // Paiement incomplet. On demande si motif = escompte ou autre - $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$commande->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$commande->ref),'confirm_clone',$formquestion,'yes'); + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$commande->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$commande->ref),'confirm_clone',$formquestion,'yes',1); if ($ret == 'html') print '
'; } @@ -1982,6 +1982,12 @@ else } } + // Clone + if ($user->rights->commande->creer) + { + print ''.$langs->trans("ToClone").''; + } + // Annuler commande if ($commande->statut == 1) { @@ -1993,12 +1999,6 @@ else } } - // Clone - if ($user->rights->commande->creer) - { - print ''.$langs->trans("ToClone").''; - } - // Delete order if ($user->rights->commande->supprimer) { diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php index 8333cdffff2..d5c893017b6 100644 --- a/htdocs/contrat/contrat.class.php +++ b/htdocs/contrat/contrat.class.php @@ -92,9 +92,10 @@ class Contrat extends CommonObject * \param line_id Id de la ligne de detail � activer * \param date Date d'ouverture * \param date_end Date fin prevue - * \return int < 0 si erreur, > 0 si ok + * \param comment A comment typed by user + * \return int <0 if KO, >0 if OK */ - function active_line($user, $line_id, $date, $date_end='') + function active_line($user, $line_id, $date, $date_end='', $comment='') { global $langs,$conf; @@ -104,7 +105,8 @@ class Contrat extends CommonObject $sql.= " date_ouverture = ".(strlen($date)!=0?"'".$this->db->idate($date)."'":"null").","; $sql.= " date_fin_validite = ".(strlen($date_end)!=0?"'".$this->db->idate($date_end)."'":"null").","; $sql.= " fk_user_ouverture = ".$user->id.","; - $sql.= " date_cloture = null"; + $sql.= " date_cloture = null,"; + $sql.= " commentaire = '".addslashes($comment)."'"; $sql.= " WHERE rowid = ".$line_id . " AND (statut = 0 OR statut = 3 OR statut = 5)"; dol_syslog("Contrat::active_line sql=".$sql); @@ -135,18 +137,22 @@ class Contrat extends CommonObject * \brief Close a contract line * \param user Objet User qui avtice le contrat * \param line_id Id de la ligne de detail a activer - * \param date_end Date fin - * \return int <0 si erreur, >0 si ok + * \param date_end Date fin + * \param comment A comment typed by user + * \return int <0 if KO, >0 if OK */ - function close_line($user, $line_id, $date_end) + function close_line($user, $line_id, $date_end, $comment='') { global $langs,$conf; // statut actif : 4 + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = 5,"; $sql.= " date_cloture = '".$this->db->idate($date_end)."',"; - $sql.= " fk_user_cloture = ".$user->id; + $sql.= " fk_user_cloture = ".$user->id.","; + $sql.= " commentaire = '".addslashes($comment)."'"; $sql.= " WHERE rowid = ".$line_id . " AND statut = 4"; $resql = $this->db->query($sql) ; @@ -159,11 +165,14 @@ class Contrat extends CommonObject if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers + $this->db->commit(); return 1; } else { - $this->error=$this->db->error(); + $this->error=$this->db->lasterror(); + dol_syslog("Contrat::close_line error ".$this->error, LOG_ERR); + $this->db->rollback(); return -1; } } @@ -1235,12 +1244,12 @@ class Contrat extends CommonObject $now=gmmktime(); $this->nbtodo=$this->nbtodolate=0; - + $this->from = " FROM ".MAIN_DB_PREFIX."contrat as c"; $this->from.= ", ".MAIN_DB_PREFIX."contratdet as cd"; $this->from.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) $this->from.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - + if ($mode == 'inactives') { $sql = "SELECT cd.rowid, cd.date_ouverture_prevue as datefin"; @@ -1304,7 +1313,7 @@ class Contrat extends CommonObject $clause = "AND"; } $sql.= " ".$clause." s.entity = ".$conf->entity; - + $resql=$this->db->query($sql); if ($resql) { diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index 752712e0964..8fb3a67ebc0 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -55,8 +55,7 @@ if ($_REQUEST["action"] == 'confirm_active' && $_REQUEST["confirm"] == 'yes' && { $contrat = new Contrat($db); $contrat->fetch($_GET["id"]); - - $result = $contrat->active_line($user, $_GET["ligne"], $_GET["date"], $_GET["dateend"]); + $result = $contrat->active_line($user, $_GET["ligne"], $_GET["date"], $_GET["dateend"], urldecode($_GET["comment"])); if ($result > 0) { @@ -72,7 +71,7 @@ if ($_REQUEST["action"] == 'confirm_closeline' && $_REQUEST["confirm"] == 'yes' { $contrat = new Contrat($db); $contrat->fetch($_GET["id"]); - $result = $contrat->close_line($user, $_GET["ligne"], $_GET["dateend"]); + $result = $contrat->close_line($user, $_GET["ligne"], $_GET["dateend"], urldecode($_GET["comment"])); if ($result > 0) { @@ -344,7 +343,7 @@ if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer && ! $_PO } } -if ($_GET["action"] == 'deleteline' && $user->rights->contrat->creer) +if ($_REQUEST["action"] == 'confirm_deleteline' && $_REQUEST["confirm"] == 'yes' && $user->rights->contrat->creer) { $contrat = new Contrat($db); $contrat->fetch($_GET["id"]); @@ -755,10 +754,10 @@ else $arrayothercontracts=$contrat->getListOfContracts('others'); /* - * Lignes de contrats + * Lines of contracts */ - // Menu list of services + // Title line for service print ''; // Array with (n*2)+1 lines $cursorline=1; while ($cursorline <= $nbofservices) @@ -776,6 +775,7 @@ else $sql.= " cd.tva_tx, cd.remise_percent, cd.info_bits, cd.subprice,"; $sql.= " ".$db->pdate("cd.date_ouverture_prevue")." as date_debut, ".$db->pdate("cd.date_ouverture")." as date_debut_reelle,"; $sql.= " ".$db->pdate("cd.date_fin_validite")." as date_fin, ".$db->pdate("cd.date_cloture")." as date_fin_reelle,"; + $sql.= " cd.commentaire as comment,"; $sql.= " p.ref, p.label"; $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; @@ -837,7 +837,7 @@ else print '
'; if ($user->rights->contrat->creer && sizeof($arrayothercontracts) && ($contrat->statut == 0 || ($contrat->statut >= 1 && empty($conf->global->CONTRAT_NOEDITWHENVALIDATED)))) { - print ''; + print ''; print img_picto($langs->trans("MoveToAnotherContract"),'uparrow'); print ''; } @@ -846,7 +846,7 @@ else } if ($user->rights->contrat->creer && ($contrat->statut == 0 || ($contrat->statut >= 1 && empty($conf->global->CONTRAT_NOEDITWHENVALIDATED))) ) { - print ''; + print ''; print img_edit(); print ''; } @@ -856,7 +856,7 @@ else if ( $user->rights->contrat->creer && ($contrat->statut == 0 || ($contrat->statut >= 1 && empty($conf->global->CONTRAT_NOEDITWHENVALIDATED))) ) { print ' '; - print ''; + print ''; print img_delete(); print ''; } @@ -950,6 +950,15 @@ else print "
"; + /* + * Confirmation to delete service line of contract + */ + if ($_REQUEST["action"] == 'deleteline' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $contrat->lignes[$cursorline-1]->id == $_GET["rowid"]) + { + $ret=$html->form_confirm($_SERVER["PHP_SELF"]."?id=".$contrat->id."&lineid=".$_GET["rowid"],$langs->trans("DeleteContractLine"),$langs->trans("ConfirmDeleteContractLine"),"confirm_deleteline",'',0,1); + if ($ret == 'html') print '
'; + } + /* * Confirmation to move service toward another contract */ @@ -967,7 +976,7 @@ else 'text' => $langs->trans("ConfirmMoveToAnotherContractQuestion"), array('type' => 'select', 'name' => 'newcid', 'values' => $arraycontractid)); - $html->form_confirm($_SERVER["PHP_SELF"]."?id=".$contrat->id."&lineid=".$_GET["rowid"],$langs->trans("MoveToAnotherContract"),$langs->trans("ConfirmMoveToAnotherContract"),"confirm_move",$formquestion); + $html->form_confirm($_SERVER["PHP_SELF"]."?id=".$contrat->id."&lineid=".$_GET["rowid"],$langs->trans("MoveToAnotherContract"),$langs->trans("ConfirmMoveToAnotherContract"),"confirm_move",$formquestion); print '
'; } @@ -979,7 +988,8 @@ else //print '
'; $dateactstart = dol_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); $dateactend = dol_mktime(12, 0 , 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); - $html->form_confirm($_SERVER["PHP_SELF"]."?id=".$contrat->id."&ligne=".$_GET["ligne"]."&date=".$dateactstart."&dateend=".$dateactend,$langs->trans("ActivateService"),$langs->trans("ConfirmActivateService",dol_print_date($dateactstart,"%A %d %B %Y")),"confirm_active"); + $comment = $_POST["comment"]; + $html->form_confirm($_SERVER["PHP_SELF"]."?id=".$contrat->id."&ligne=".$_GET["ligne"]."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment),$langs->trans("ActivateService"),$langs->trans("ConfirmActivateService",dol_print_date($dateactstart,"%A %d %B %Y")),"confirm_active", '', 0, 1); print '
'; } @@ -991,15 +1001,13 @@ else //print '
'; $dateactstart = dol_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); $dateactend = dol_mktime(12, 0 , 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); - $page=$_SERVER["PHP_SELF"]."?id=".$contrat->id."&ligne=".$_GET["ligne"]."&date=".$dateactstart."&dateend=".$dateactend; - $title=$langs->trans("CloseService"); - $question=$langs->trans("ConfirmCloseService",dol_print_date($dateactend,"%A %d %B %Y")); - $action="confirm_closeline"; - $html->form_confirm($page,$title,$question,$action,'',0,1); + $comment = $_POST["comment"]; + $html->form_confirm($_SERVER["PHP_SELF"]."?id=".$contrat->id."&ligne=".$_GET["ligne"]."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("CloseService"), $langs->trans("ConfirmCloseService",dol_print_date($dateactend,"%A %d %B %Y")), "confirm_closeline", '', 0, 1); print '
'; } - // Area with activation info + + // Area with status and activation info of line if ($contrat->statut > 0) { print ''; @@ -1043,12 +1051,11 @@ else print $langs->trans("DateEndReal").': '; print dol_print_date($objp->date_fin_reelle); } + if (! empty($objp->comment)) print "
".$objp->comment; print ''; - // Statut - print ''; + print ''; + print ''; print '
'; - print ' '; - print ' 
'; } @@ -1095,7 +1102,7 @@ else print ''; - print ''.$langs->trans("Comment").''; + print ''.$langs->trans("Comment").''; print ''; @@ -1145,7 +1152,7 @@ else print ''; print ''; - print ''.$langs->trans("Comment").''; + print ''.$langs->trans("Comment").''; print ''; print ''; diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 322fd6cd822..21b30256033 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -1563,7 +1563,7 @@ class Form if ($input['type'] == 'select') { $more.=''; - $more.=$this->select_array($input['name'],$input['values'],'',1); + $more.=$this->selectarray($input['name'],$input['values'],'',1); $more.=''; } if ($input['type'] == 'checkbox') @@ -2437,55 +2437,78 @@ class Form * \param translate Traduire la valeur * \param maxlen Length maximum for labels */ - function select_array($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $optionType=0, $option='', $translate=0, $maxlen=0) + function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $optionType=0, $option='', $translate=0, $maxlen=0) { global $langs; + + $out=''; + // \TODO Simplify optionType and option (only one should be necessary) if ($optionType == 1 && $option != '') { - print ''; } else { - print ''; } if ($show_empty) { - print ''."\n"; + $out.=''."\n"; } if (is_array($array)) { while (list($key, $value) = each ($array)) { - print '\n"; + $out.="\n"; } } - print ""; + $out.=""; + return $out; + } + + /** + * \brief Show a select form from an array + * \param htmlname Nom de la zone select + * \param array Tableau de key+valeur + * \param id Preselected key + * \param show_empty 1 si il faut ajouter une valeur vide dans la liste, 0 sinon + * \param key_in_label 1 pour afficher la key dans la valeur "[key] value" + * \param value_as_key 1 to use value as key + * \param optionType Type de l'option: 1 pour des fonctions javascript + * \param option Valeur de l'option en fonction du type choisi + * \param translate Traduire la valeur + * \param maxlen Length maximum for labels + * \deprecated Use selectarray instead + */ + function select_array($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $optionType=0, $option='', $translate=0, $maxlen=0) + { + print $this->selectarray($htmlname, $array, $id, $show_empty, $key_in_label, $value_as_key, $optionType, $option, $translate, $maxlen); } diff --git a/htdocs/langs/en_US/contracts.lang b/htdocs/langs/en_US/contracts.lang index 394f39cc0ca..c22eebd8427 100644 --- a/htdocs/langs/en_US/contracts.lang +++ b/htdocs/langs/en_US/contracts.lang @@ -72,6 +72,8 @@ ServiceStatus=Status of service DraftContracts=Drafts contracts CloseRefusedBecauseOneServiceActive=Contract can't be closed as ther is at least one open service on it CloseAllContracts=Close all contracts +DeleteContractLine=Delete a contract line +ConfirmDeleteContractLine=Are you sure you want to delete this contract line ? MoveToAnotherContract=Move service into another contract. ConfirmMoveToAnotherContract=I choosed new target contract and confirm I want to move this service into this contract. ConfirmMoveToAnotherContractQuestion=Choose in which existing contract (of same third party), you want to move this service to ? diff --git a/htdocs/langs/fr_FR/contracts.lang b/htdocs/langs/fr_FR/contracts.lang index 8f1d297b425..253141676e4 100644 --- a/htdocs/langs/fr_FR/contracts.lang +++ b/htdocs/langs/fr_FR/contracts.lang @@ -73,6 +73,8 @@ DraftContracts=Contrats brouillons CloseRefusedBecauseOneServiceActive=Fermeture du contrat impossible car il y a au moins un service actif CloseAllContracts=Tout clôturer MoveToAnotherContract=Déplacer le service vers un autre contrat de ce tiers. +DeleteContractLine=Supprimer ligne de contrat +ConfirmDeleteContractLine=Etes-vous sur de vouloir supprimer cette ligne de contrat de service ? ConfirmMoveToAnotherContract=J'ai choisi le contrat cible et confirme le déplacement du service dans ce contrat. ConfirmMoveToAnotherContractQuestion=Choisissez vers quel autre contrat de ce même tiers, vous voulez déplacer ce service ? PaymentRenewContractId=Renouvellement service (numéro %s)