Qual: Use a so much simpler way to have ajax confirmation boxes

This commit is contained in:
Laurent Destailleur 2009-05-06 18:07:34 +00:00
parent 866e5952b0
commit 7bda345c7f
6 changed files with 102 additions and 59 deletions

View File

@ -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 '<br>';
}
@ -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 '<br>';
}
@ -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 '<br>';
}
@ -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 '<br>';
}
@ -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.'&amp;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 '<br>';
}
@ -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 '<br>';
}
@ -1982,6 +1982,12 @@ else
}
}
// Clone
if ($user->rights->commande->creer)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$commande->id.'&amp;action=clone&amp;object=order">'.$langs->trans("ToClone").'</a>';
}
// Annuler commande
if ($commande->statut == 1)
{
@ -1993,12 +1999,6 @@ else
}
}
// Clone
if ($user->rights->commande->creer)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$commande->id.'&amp;action=clone&amp;object=order">'.$langs->trans("ToClone").'</a>';
}
// Delete order
if ($user->rights->commande->supprimer)
{

View File

@ -92,9 +92,10 @@ class Contrat extends CommonObject
* \param line_id Id de la ligne de detail <EFBFBD> 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)
{

View File

@ -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 '<table class="noborder" width="100%">'; // 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 '<td align="right" nowrap="nowrap">';
if ($user->rights->contrat->creer && sizeof($arrayothercontracts) && ($contrat->statut == 0 || ($contrat->statut >= 1 && empty($conf->global->CONTRAT_NOEDITWHENVALIDATED))))
{
print '<a href="fiche.php?id='.$id.'&amp;action=move&amp;rowid='.$objp->rowid.'">';
print '<a href="fiche.php?id='.$contrat->id.'&amp;action=move&amp;rowid='.$objp->rowid.'">';
print img_picto($langs->trans("MoveToAnotherContract"),'uparrow');
print '</a>';
}
@ -846,7 +846,7 @@ else
}
if ($user->rights->contrat->creer && ($contrat->statut == 0 || ($contrat->statut >= 1 && empty($conf->global->CONTRAT_NOEDITWHENVALIDATED))) )
{
print '<a href="fiche.php?id='.$id.'&amp;action=editline&amp;rowid='.$objp->rowid.'">';
print '<a href="fiche.php?id='.$contrat->id.'&amp;action=editline&amp;rowid='.$objp->rowid.'">';
print img_edit();
print '</a>';
}
@ -856,7 +856,7 @@ else
if ( $user->rights->contrat->creer && ($contrat->statut == 0 || ($contrat->statut >= 1 && empty($conf->global->CONTRAT_NOEDITWHENVALIDATED))) )
{
print '&nbsp;';
print '<a href="fiche.php?id='.$id.'&amp;action=deleteline&amp;lineid='.$objp->rowid.'">';
print '<a href="fiche.php?id='.$contrat->id.'&amp;action=deleteline&amp;rowid='.$objp->rowid.'">';
print img_delete();
print '</a>';
}
@ -950,6 +950,15 @@ else
print "</table>";
/*
* 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 '<table class="noborder" width="100%"><tr '.$bc[false].' height="6"><td></td></tr></table>';
}
/*
* 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."&amp;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 '<table class="noborder" width="100%"><tr '.$bc[false].' height="6"><td></td></tr></table>';
}
@ -979,7 +988,8 @@ else
//print '<br />';
$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."&amp;ligne=".$_GET["ligne"]."&amp;date=".$dateactstart."&amp;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 '<table class="noborder" width="100%"><tr '.$bc[false].' height="6"><td></td></tr></table>';
}
@ -991,15 +1001,13 @@ else
//print '<br />';
$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 '<table class="noborder" width="100%"><tr '.$bc[false].' height="6"><td></td></tr></table>';
}
// Area with activation info
// Area with status and activation info of line
if ($contrat->statut > 0)
{
print '<table class="noborder" width="100%">';
@ -1043,12 +1051,11 @@ else
print $langs->trans("DateEndReal").': ';
print dol_print_date($objp->date_fin_reelle);
}
if (! empty($objp->comment)) print "<br>".$objp->comment;
print '</td>';
// Statut
print '<td align="center">';
print '&nbsp;';
print '</td>';
print '<td align="center">&nbsp;</td>';
print '</tr>';
print '</table>';
}
@ -1095,7 +1102,7 @@ else
print '</tr>';
print '<tr '.$bc[$var].'><td>'.$langs->trans("Comment").'</td><td colspan="3"><input size="80" type="text" name="commentaire" value="'.$_POST["commentaire"].'"></td></tr>';
print '<tr '.$bc[$var].'><td>'.$langs->trans("Comment").'</td><td colspan="3"><input size="80" type="text" name="comment" value="'.$_POST["comment"].'"></td></tr>';
print '</table>';
@ -1145,7 +1152,7 @@ else
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</td></tr>';
print '<tr '.$bc[$var].'><td>'.$langs->trans("Comment").'</td><td><input size="70" type="text" class="flat" name="commentaire" value="'.$_POST["commentaire"].'"></td></tr>';
print '<tr '.$bc[$var].'><td>'.$langs->trans("Comment").'</td><td><input size="70" type="text" class="flat" name="comment" value="'.$_POST["comment"].'"></td></tr>';
print '</table>';
print '</form>';

View File

@ -1563,7 +1563,7 @@ class Form
if ($input['type'] == 'select')
{
$more.='<tr><td valign="top">';
$more.=$this->select_array($input['name'],$input['values'],'',1);
$more.=$this->selectarray($input['name'],$input['values'],'',1);
$more.='</td></tr>';
}
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 '<select class="flat" name="'.$htmlname.'" '.$option.'>';
$out.='<select class="flat" name="'.$htmlname.'" '.$option.'>';
}
else
{
print '<select class="flat" name="'.$htmlname.'">';
$out.='<select class="flat" name="'.$htmlname.'">';
}
if ($show_empty)
{
print '<option value="-1"'.($id==-1?' selected="true"':'').'>&nbsp;</option>'."\n";
$out.='<option value="-1"'.($id==-1?' selected="true"':'').'>&nbsp;</option>'."\n";
}
if (is_array($array))
{
while (list($key, $value) = each ($array))
{
print '<option value="'.($value_as_key?$value:$key).'"';
$out.='<option value="'.($value_as_key?$value:$key).'"';
// Si il faut pré-sélectionner une valeur
if ($id != '' && ($id == $key || $id == $value))
{
print ' selected="true"';
$out.=' selected="true"';
}
print '>';
$out.='>';
if ($key_in_label)
{
$newval=($translate?$langs->trans($value):$value);
$selectOptionValue = $key.' - '.($maxlen?dol_trunc($newval,$maxlen):$newval);
print $selectOptionValue;
$out.=$selectOptionValue;
}
else
{
$newval=($translate?$langs->trans($value):$value);
$selectOptionValue = ($maxlen?dol_trunc($newval,$maxlen):$newval);
if ($value == '' || $value == '-') { $selectOptionValue='&nbsp;'; }
print $selectOptionValue;
$out.=$selectOptionValue;
}
print "</option>\n";
$out.="</option>\n";
}
}
print "</select>";
$out.="</select>";
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);
}

View File

@ -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 ?

View File

@ -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)