Fix: uniformize code

This commit is contained in:
Regis Houssin 2012-07-11 10:14:56 +02:00
parent ff0668e908
commit b53d108c50
5 changed files with 72 additions and 64 deletions

View File

@ -1,6 +1,7 @@
<?php <?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -34,14 +35,16 @@ $langs->load("companies");
$langs->load("donations"); $langs->load("donations");
$langs->load("bills"); $langs->load("bills");
$id=GETPOST('rowid')?GETPOST('rowid'):GETPOST('id','int'); $id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int');
$action=GETPOST('action'); $action=GETPOST('action','alpha');
$cancel=GETPOST('cancel');
$amount=GETPOST('amount');
$mesg=""; $mesg="";
$mesgs=array(); $mesgs=array();
$don = new Don($db); $don = new Don($db);
$donation_date=dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); $donation_date=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
// Security check // Security check
$result = restrictedArea($user, 'don', $id); $result = restrictedArea($user, 'don', $id);
@ -53,9 +56,9 @@ $result = restrictedArea($user, 'don', $id);
if ($action == 'update') if ($action == 'update')
{ {
if (! empty($_POST['cancel'])) if (! empty($cancel))
{ {
Header("Location: fiche.php?rowid=".$_POST["rowid"]); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
exit; exit;
} }
@ -68,7 +71,7 @@ if ($action == 'update')
$error++; $error++;
} }
if (! $_POST["amount"] > 0) if (empty($amount))
{ {
$mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Amount")); $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Amount"));
$action = "create"; $action = "create";
@ -77,8 +80,7 @@ if ($action == 'update')
if (! $error) if (! $error)
{ {
$don->id = $_POST["rowid"]; $don->fetch($id);
$don->fetch($_POST["rowid"]);
$don->prenom = $_POST["prenom"]; $don->prenom = $_POST["prenom"];
$don->nom = $_POST["nom"]; $don->nom = $_POST["nom"];
@ -100,7 +102,7 @@ if ($action == 'update')
if ($don->update($user) > 0) if ($don->update($user) > 0)
{ {
Header("Location: fiche.php?rowid=".$don->id); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$don->id);
exit; exit;
} }
} }
@ -108,7 +110,7 @@ if ($action == 'update')
if ($action == 'add') if ($action == 'add')
{ {
if (! empty($_POST['cancel'])) if (! empty($cancel))
{ {
Header("Location: index.php"); Header("Location: index.php");
exit; exit;
@ -119,14 +121,14 @@ if ($action == 'add')
if (empty($donation_date)) if (empty($donation_date))
{ {
$mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Date")); $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Date"));
$_GET["action"] = "create"; $action = "create";
$error++; $error++;
} }
if (! $_POST["amount"] > 0) if (empty($amount))
{ {
$mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Amount")); $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Amount"));
$_GET["action"] = "create"; $action = "create";
$error++; $error++;
} }
@ -160,48 +162,47 @@ if ($action == 'add')
if ($action == 'delete') if ($action == 'delete')
{ {
$don->delete($_GET["rowid"]); $don->delete($id);
Header("Location: liste.php"); Header("Location: liste.php");
exit; exit;
} }
if ($action == 'commentaire') if ($action == 'commentaire')
{ {
$don->fetch($_POST["rowid"]); $don->fetch($id);
$don->update_note($_POST["commentaire"]); $don->update_note($_POST["commentaire"]);
$_GET["rowid"] = $_POST["rowid"];
} }
if ($action == 'valid_promesse') if ($action == 'valid_promesse')
{ {
if ($don->valid_promesse($_GET["rowid"], $user->id) >= 0) if ($don->valid_promesse($id, $user->id) >= 0)
{ {
Header("Location: fiche.php?rowid=".$_GET["rowid"]); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
exit; exit;
} }
else $mesg=$don->error; else $mesg=$don->error;
} }
if ($action == 'set_cancel') if ($action == 'set_cancel')
{ {
if ($don->set_cancel($_GET["rowid"]) >= 0) if ($don->set_cancel($id) >= 0)
{ {
Header("Location: fiche.php?rowid=".$_GET["rowid"]); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
exit; exit;
} }
else $mesg=$don->error; else $mesg=$don->error;
} }
if ($action == 'set_paid') if ($action == 'set_paid')
{ {
if ($don->set_paye($_GET["rowid"], $modepaiement) >= 0) if ($don->set_paye($id, $modepaiement) >= 0)
{ {
Header("Location: fiche.php?rowid=".$_GET["rowid"]); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
exit; exit;
} }
else $mesg=$don->error; else $mesg=$don->error;
} }
if ($action == 'set_encaisse') if ($action == 'set_encaisse')
{ {
if ($don->set_encaisse($_GET["rowid"]) >= 0) if ($don->set_encaisse($id) >= 0)
{ {
Header("Location: fiche.php?rowid=".$_GET["rowid"]); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
exit; exit;
} }
else $mesg=$don->error; else $mesg=$don->error;
@ -213,7 +214,7 @@ if ($action == 'set_encaisse')
if ($action == 'builddoc') if ($action == 'builddoc')
{ {
$donation = new Don($db); $donation = new Don($db);
$donation->fetch($_GET['rowid']); $donation->fetch($id);
if ($_REQUEST['model']) if ($_REQUEST['model'])
{ {
@ -238,7 +239,7 @@ if ($action == 'builddoc')
} }
else else
{ {
Header('Location: '.$_SERVER["PHP_SELF"].'?rowid='.$donation->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$donation->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit; exit;
} }
} }
@ -332,12 +333,12 @@ if ($action == 'create')
/* */ /* */
/* ************************************************************ */ /* ************************************************************ */
if ($id && $_GET["action"] == 'edit') if (! empty($id) && $action == 'edit')
{ {
$don->fetch($id); $don->fetch($id);
$h=0; $h=0;
$head[$h][0] = DOL_URL_ROOT."/compta/dons/fiche.php?rowid=".$_GET["rowid"]; $head[$h][0] = $_SERVER['PHP_SELF']."?id=".$don->id;
$head[$h][1] = $langs->trans("Card"); $head[$h][1] = $langs->trans("Card");
$hselected=$h; $hselected=$h;
$h++; $h++;
@ -401,11 +402,11 @@ if ($id && $_GET["action"] == 'edit')
print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$don->getLibStatut(4).'</td></tr>'; print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$don->getLibStatut(4).'</td></tr>';
// Project // Project
if ($conf->projet->enabled) if (! empty($conf->projet->enabled))
{ {
$langs->load('projects'); $langs->load('projects');
print '<tr><td>'.$langs->trans('Project').'</td><td>'; print '<tr><td>'.$langs->trans('Project').'</td><td>';
select_projects($soc->id, isset($_POST["projectid"])?$_POST["projectid"]:$don->fk_project, 'projectid'); select_projects(-1, (isset($_POST["projectid"])?$_POST["projectid"]:$don->fk_project), 'projectid');
print '</td></tr>'; print '</td></tr>';
} }
@ -425,12 +426,12 @@ if ($id && $_GET["action"] == 'edit')
/* Fiche don en mode visu */ /* Fiche don en mode visu */
/* */ /* */
/* ************************************************************ */ /* ************************************************************ */
if ($id && $action != 'edit') if (! empty($id) && $action != 'edit')
{ {
$result=$don->fetch($id); $result=$don->fetch($id);
$h=0; $h=0;
$head[$h][0] = DOL_URL_ROOT."/compta/dons/fiche.php?rowid=".$_GET["rowid"]; $head[$h][0] = $_SERVER['PHP_SELF']."?id=".$don->id;
$head[$h][1] = $langs->trans("Card"); $head[$h][1] = $langs->trans("Card");
$hselected=$h; $hselected=$h;
$h++; $h++;
@ -565,8 +566,6 @@ if ($id && $action != 'edit')
} }
$db->close();
llxFooter(); llxFooter();
$db->close();
?> ?>

View File

@ -1,6 +1,7 @@
<?php <?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -27,7 +28,8 @@ require_once(DOL_DOCUMENT_ROOT."/compta/dons/class/don.class.php");
$langs->load("donations"); $langs->load("donations");
if (!$user->rights->don->lire) accessforbidden(); // Security check
$result = restrictedArea($user, 'don');
$donation_static=new Don($db); $donation_static=new Don($db);
@ -48,17 +50,19 @@ $donstatic=new Don($db);
$help_url='EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Subvenciones'; $help_url='EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Subvenciones';
llxHeader('',$langs->trans("Donations"),$help_url); llxHeader('',$langs->trans("Donations"),$help_url);
$nb=array();
$somme=array();
$sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut"; $sql = "SELECT count(d.rowid) as nb, sum(d.amount) as somme , d.fk_statut";
$sql.= " FROM ".MAIN_DB_PREFIX."don as d"; $sql.= " FROM ".MAIN_DB_PREFIX."don as d";
$sql.= " GROUP BY d.fk_statut"; $sql.= " GROUP BY d.fk_statut";
$sql.= " ORDER BY d.fk_statut"; $sql.= " ORDER BY d.fk_statut";
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
$i = 0;
$num = $db->num_rows($result); $num = $db->num_rows($result);
$i = 0;
while ($i < $num) while ($i < $num)
{ {
$objp = $db->fetch_object($result); $objp = $db->fetch_object($result);
@ -107,17 +111,19 @@ print '<td align="right">'.$langs->trans("Total").'</td>';
print '<td align="right">'.$langs->trans("Average").'</td>'; print '<td align="right">'.$langs->trans("Average").'</td>';
print '</tr>'; print '</tr>';
$total=0;
$totalnb=0;
$var=true; $var=true;
foreach ($listofstatus as $status) foreach ($listofstatus as $status)
{ {
$var=!$var; $var=!$var;
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
print '<td><a href="liste.php?statut='.$status.'">'.$donstatic->LibStatut($status,4).'</a></td>'; print '<td><a href="liste.php?statut='.$status.'">'.$donstatic->LibStatut($status,4).'</a></td>';
print '<td align="right">'.$nb[$status].'</td>'; print '<td align="right">'.(! empty($nb[$status])?$nb[$status]:'&nbsp;').'</td>';
print '<td align="right">'.($nb[$status]?price($somme[$status],'MT'):'&nbsp;').'</td>'; print '<td align="right">'.(! empty($nb[$status])?price($somme[$status],'MT'):'&nbsp;').'</td>';
print '<td align="right">'.($nb[$status]?price(price2num($somme[$status]/$nb[$status],'MT')):'&nbsp;').'</td>'; print '<td align="right">'.(! empty($nb[$status])?price(price2num($somme[$status]/$nb[$status],'MT')):'&nbsp;').'</td>';
$totalnb += $nb[$status]; $totalnb += (! empty($nb[$status])?$nb[$status]:0);
$total += $somme[$status]; $total += (! empty($somme[$status])?$somme[$status]:0);
print "</tr>"; print "</tr>";
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -24,7 +25,7 @@
require("../../main.inc.php"); require("../../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/compta/dons/class/don.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/dons/class/don.class.php");
if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php"); if (! empty($conf->projet->enabled)) require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
$langs->load("companies"); $langs->load("companies");
$langs->load("donations"); $langs->load("donations");
@ -83,10 +84,10 @@ if (trim($search_name) != '')
$sql.= $db->order($sortfield,$sortorder); $sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit+1, $offset); $sql.= $db->plimit($limit+1, $offset);
$result = $db->query($sql); $resql = $db->query($sql);
if ($result) if ($resql)
{ {
$num = $db->num_rows($result); $num = $db->num_rows($resql);
$i = 0; $i = 0;
$param="&statut=$statut&sortorder=$sortorder&sortfield=$sortfield"; $param="&statut=$statut&sortorder=$sortorder&sortfield=$sortfield";
@ -110,7 +111,7 @@ if ($result)
print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"d.societe","&page=$page&statut=$statut","","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"d.societe","&page=$page&statut=$statut","","",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Name"),$_SERVER["PHP_SELF"],"d.nom","&page=$page&statut=$statut","","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Name"),$_SERVER["PHP_SELF"],"d.nom","&page=$page&statut=$statut","","",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"d.datedon","&page=$page&statut=$statut","",'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"d.datedon","&page=$page&statut=$statut","",'align="center"',$sortfield,$sortorder);
if ($conf->projet->enabled) if (! empty($conf->projet->enabled))
{ {
$langs->load("projects"); $langs->load("projects");
print_liste_field_titre($langs->trans("Project"),$_SERVER["PHP_SELF"],"fk_don_projet","&page=$page&statut=$statut","","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Project"),$_SERVER["PHP_SELF"],"fk_don_projet","&page=$page&statut=$statut","","",$sortfield,$sortorder);
@ -133,7 +134,7 @@ if ($result)
print '<td class="liste_titre" align="left">'; print '<td class="liste_titre" align="left">';
print '&nbsp;'; print '&nbsp;';
print '</td>'; print '</td>';
if ($conf->projet->enabled) if (! empty($conf->projet->enabled))
{ {
print '<td class="liste_titre" align="right">'; print '<td class="liste_titre" align="right">';
print '&nbsp;'; print '&nbsp;';

View File

@ -435,7 +435,7 @@ class FormFile
$out.= '</tr>'; $out.= '</tr>';
// Execute hooks // Execute hooks
$parameters=array('socid'=>$GLOBALS['socid'],'id'=>$GLOBALS['id'],'modulepart'=>$modulepart); $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart);
if (is_object($hookmanager)) $out.= $hookmanager->executeHooks('formBuilddocOptions',$parameters,$GLOBALS['object']); if (is_object($hookmanager)) $out.= $hookmanager->executeHooks('formBuilddocOptions',$parameters,$GLOBALS['object']);
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -51,7 +52,7 @@ class html_cerfafr extends ModeleDon
/** /**
* Return if a module can be used or not * Return if a module can be used or not
* *
* @return boolean true if module can be used * @return boolean true if module can be used
*/ */
function isEnabled() function isEnabled()
@ -62,7 +63,7 @@ class html_cerfafr extends ModeleDon
/** /**
* Write the object to document file to disk * Write the object to document file to disk
* *
* @param Don $don Donation object * @param Don $don Donation object
* @param Translate $outputlangs Lang object for output language * @param Translate $outputlangs Lang object for output language
* @return int >0 if OK, <0 if KO * @return int >0 if OK, <0 if KO
@ -72,6 +73,7 @@ class html_cerfafr extends ModeleDon
global $user,$conf,$langs,$mysoc; global $user,$conf,$langs,$mysoc;
$now=dol_now(); $now=dol_now();
$id = (! is_object($don)?$don:'');
if (! is_object($outputlangs)) $outputlangs=$langs; if (! is_object($outputlangs)) $outputlangs=$langs;
@ -81,18 +83,18 @@ class html_cerfafr extends ModeleDon
$outputlangs->load("bills"); $outputlangs->load("bills");
$outputlangs->load("products"); $outputlangs->load("products");
if ($conf->don->dir_output) if (! empty($conf->don->dir_output))
{ {
// Definition de l'objet $don (pour compatibilite ascendante) // Definition de l'objet $don (pour compatibilite ascendante)
if (! is_object($don)) if (! is_object($don))
{ {
$id = $don;
$don = new Don($this->db); $don = new Don($this->db);
$ret=$don->fetch($id); $ret=$don->fetch($id);
$id=$don->id;
} }
// Definition de $dir et $file // Definition de $dir et $file
if ($don->specimen) if (! empty($don->specimen))
{ {
$dir = $conf->don->dir_output; $dir = $conf->don->dir_output;
$file = $dir . "/SPECIMEN.html"; $file = $dir . "/SPECIMEN.html";
@ -120,7 +122,7 @@ class html_cerfafr extends ModeleDon
$form = implode('', file($donmodel)); $form = implode('', file($donmodel));
$form = str_replace('__REF__',$id,$form); $form = str_replace('__REF__',$id,$form);
$form = str_replace('__DATE__',dol_print_date($don->date,'day',false,$outputlangs),$form); $form = str_replace('__DATE__',dol_print_date($don->date,'day',false,$outputlangs),$form);
$form = str_replace('__IP__',$user->ip,$form); //$form = str_replace('__IP__',$user->ip,$form); // TODO $user->ip not exist
$form = str_replace('__AMOUNT__',$don->amount,$form); $form = str_replace('__AMOUNT__',$don->amount,$form);
$form = str_replace('__CURRENCY__',$outputlangs->transnoentitiesnoconv("Currency".$conf->currency),$form); $form = str_replace('__CURRENCY__',$outputlangs->transnoentitiesnoconv("Currency".$conf->currency),$form);
$form = str_replace('__CURRENCYCODE__',$conf->currency,$form); $form = str_replace('__CURRENCYCODE__',$conf->currency,$form);