diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index f3910ca2013..3f848999e46 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -1,481 +1,481 @@ - - * Copyright (C) 2004-2005 Laurent Destailleur - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * $Source$ - */ - -/** - \file htdocs/compta/index.php - \ingroup compta - \brief Page accueil zone comptabilité - \version $Revision$ -*/ - -require("./pre.inc.php"); - -$user->getrights(); // On a besoin des permissions sur plusieurs modules - -$langs->load("compta"); -$langs->load("bills"); - -// Sécurité accés client -$socidp=''; -if ($user->societe_id > 0) -{ - $action = ''; - $socidp = $user->societe_id; -} - - -llxHeader("",$langs->trans("AccountancyTreasuryArea")); - - -/* - * Actions - */ - -if (isset($_GET["action"]) && $_GET["action"] == 'add_bookmark') -{ -$sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark WHERE fk_soc = ".$socidp." AND fk_user=".$user->id; -if (! $db->query($sql) ) -{ - dolibarr_print_error($db); -} -$sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_soc, dateb, fk_user) VALUES ($socidp, now(),".$user->id.");"; -if (! $db->query($sql) ) -{ - dolibarr_print_error($db); -} -} - -if (isset($_GET["action"]) && $_GET["action"] == 'del_bookmark') -{ - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark WHERE rowid=".$_GET["bid"]; - $result = $db->query($sql); -} - - - -/* - * Affichage page - * - */ -print_fiche_titre($langs->trans("AccountancyTreasuryArea")); - -print ''; - -print ''; - -print '
'; - -/* - * Zone recherche facture - */ -if ($conf->facture->enabled) { - print '
'; - print ''; - print ""; - print ''; - print "'; - print ''; - print "'; - print ''; - print "
'.$langs->trans("SearchABill").'
".$langs->trans("Ref").':
".$langs->trans("Other").':

"; -} - - -/** - * Factures brouillons - */ -if ($conf->facture->enabled && $user->rights->facture->lire) -{ - - $sql = "SELECT f.facnumber, f.rowid, f.total_ttc, s.nom, s.idp"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s"; - $sql .= " WHERE s.idp = f.fk_soc AND f.fk_statut = 0"; - - if ($socidp) - { - $sql .= " AND f.fk_soc = $socidp"; - } - - $resql = $db->query($sql); - - if ( $resql ) - { - $num = $db->num_rows($resql); - if ($num) - { - print ''; - print ''; - print ''; - $i = 0; - $tot_ttc = 0; - $var = True; - while ($i < $num && $i < 20) - { - $obj = $db->fetch_object($resql); - $var=!$var; - print ''; - print ''; - print ''; - print ''; - $tot_ttc+=$obj->total_ttc; - $i++; - } - - print ''; - print ''; - print ''; - - print "
'.$langs->trans("DraftBills").' ('.$num.')
'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.''.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($obj->nom,20).''.price($obj->total_ttc).'
'.$langs->trans("Total").''.price($tot_ttc).'

"; - } - $db->free($resql); - } - else - { - dolibarr_print_error($db); - } -} - -/** - * Charges a payer - */ -if ($conf->compta->enabled) -{ - if ($user->societe_id == 0) - { - - $sql = "SELECT c.rowid, c.amount, cc.libelle"; - $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as c, ".MAIN_DB_PREFIX."c_chargesociales as cc"; - $sql .= " WHERE c.fk_type = cc.id AND c.paye=0"; - - $resql = $db->query($sql); - - if ( $resql ) - { - $num = $db->num_rows($resql); - if ($num) - { - print ''; - print ''; - print ''; - $i = 0; - $tot_ttc=0; - $var = True; - while ($i < $num) - { - $obj = $db->fetch_object($resql); - $var = !$var; - print ""; - print ''; - print ''; - print ''; - $tot_ttc+=$obj->amount; - $i++; - } - - print ''; - print ''; - print ''; - - print '
'.$langs->trans("ContributionsToPay").' ('.$num.')
'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->libelle.''.price($obj->amount).'
'.$langs->trans("Total").''.price($tot_ttc).'

'; - } - $db->free($resql); - } - else - { - dolibarr_print_error($db); - } - } -} - - -/** - * Bookmark - */ -$sql = "SELECT s.idp, s.nom,b.rowid as bid"; -$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."bookmark as b"; -$sql .= " WHERE b.fk_soc = s.idp AND b.fk_user = ".$user->id; -$sql .= " ORDER BY lower(s.nom) ASC"; - -$resql = $db->query($sql); - -if ( $resql ) -{ - $num = $db->num_rows($resql); - $i = 0; - if ($num) - { - print ''; - print "\n"; - $var = True; - while ($i < $num) - { - $obj = $db->fetch_object($resql); - $var = !$var; - print ""; - print ''; - print ''; - print ''; - $i++; - } - print '
".$langs->trans("Bookmarks")."
'.$obj->nom.''.img_delete().'
'; - } - $db->free($resql); -} -else -{ - dolibarr_print_error($db); -} - - -print '
'; - - -/* - * Commandes à facturer - */ -if ($conf->commande->enabled && $user->rights->commande->lire) -{ - $langs->load("orders"); - - $sql = "SELECT sum(f.total) as tot_fht, sum(f.total_ttc) as tot_fttc"; - $sql .= " ,s.nom, s.idp, p.rowid, p.ref, p.total_ht, p.total_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."commande AS p, llx_societe AS s"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid"; - $sql .= " WHERE p.fk_soc = s.idp"; - if ($socidp) - { - $sql .= " AND p.fk_soc = $socidp"; - } - $sql .= " AND p.fk_statut >=1 AND p.facture=0"; - $sql .= " GROUP BY p.rowid"; - - $resql = $db->query($sql); - - if ( $resql ) - { - $num = $db->num_rows($resql); - if ($num) - { - $i = 0; - print ''; - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - $var = True; - $tot_ht=$tot_ttc=$tot_tobill=0; - while ($i < $num) - { - $obj = $db->fetch_object($resql); -// if ($obj->total_ttc-$obj->tot_fttc >0) -// { - $var=!$var; - print ""; - print "'; - - print ''; - print ''; - print ''; - print ''; - $tot_ht += $obj->total_ht; - $tot_ttc += $obj->total_ttc; - $tot_tobill += ($obj->total_ttc-$obj->tot_fttc); -// } - $i++; - } - $var=!$var; - - print ''; - print ''; - print ''; - print ''; - print ''; - print '
'.$langs->trans("OrdersToBill").' ('.$num.')'.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("ToBill").'
rowid\">".img_object($langs->trans("ShowOrder"),"order").' '; - print "rowid\">".$obj->ref.''.img_object($langs->trans("ShowCompany"),"company").' '; - print ''.dolibarr_trunc($obj->nom,50).''.price($obj->total_ht).''.price($obj->total_ttc).''.price($obj->total_ttc-$obj->tot_fttc).'
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToBill").': '.price($tot_tobill).') '.price($tot_ht).''.price($tot_ttc).''.price($tot_tobill).'

'; - } - $db->free($resql); - } - else - { - dolibarr_print_error($db); - } -} - - -if ($conf->facture->enabled && $user->rights->facture->lire) -{ - - /* - * Factures impayées - * - */ - - $sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total, f.total_ttc, ".$db->pdate("f.date_lim_reglement")." as datelimite, sum(pf.amount) as am"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture"; - $sql.= " WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1"; - if ($socidp) $sql .= " AND f.fk_soc = $socidp"; - $sql.= " GROUP BY f.facnumber, f.rowid, s.nom, s.idp, f.total, f.total_ttc"; - $sql.= " ORDER BY f.datef ASC "; - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - - if ($num) - { - print ''; - print ''; - print ''; - $var = True; - $total_ttc = $totalam = $total = 0; - while ($i < $num) - { - $obj = $db->fetch_object($resql); - - if ($i < $conf->liste_limit) - { - $var=!$var; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - } - $total_ttc += $obj->total_ttc; - $total += $obj->total; - $totalam += $obj->am; - $i++; - } - $var=!$var; - - print ''; - print ''; - print ''; - print ''; - print ''; - print '
'.$langs->trans("BillsCustomersUnpayed").' ('.$num.')'.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("Received").'
'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.''; - if ($obj->datelimite < (time() - $conf->facture->client->warning_delay)) print img_warning($langs->trans("Late")); - print ''.img_object($langs->trans("ShowCustomer"),"company").' '.dolibarr_trunc($obj->nom,44).''.price($obj->total).''.price($obj->total_ttc).''.price($obj->am).'
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToTake").': '.price($total_ttc-$totalam).') '.price($total).''.price($total_ttc).''.price($totalam).'

'; - } - $db->free($resql); - } - else - { - dolibarr_print_error($db); - } -} - - -// \todo Mettre ici recup des actions en rapport avec la compta -$resql = 0; -if ($resql) -{ - print ''; - print ''; - print "\n"; - $var = True; - $i = 0; - while ($i < $db->num_rows($resql) ) - { - $obj = $db->fetch_object($resql); - $var=!$var; - - print ""; - $i++; - } - $db->free($resql); - print "
'.$langs->trans("TasksToDo").'
".strftime("%d %b %Y",$obj->da)."$obj->libelle $obj->label

"; -} - - -/* - * Factures a payer - */ -if ($conf->facture->enabled) { - - if ($user->societe_id == 0) - { - $sql = "SELECT ff.rowid, ff.facnumber, ff.libelle, ff.total_ht, ff.total_ttc, s.nom, s.idp"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff"; - $sql .= " WHERE s.idp = ff.fk_soc"; - $sql .= " AND ff.paye=0"; - - $result=$db->query($sql); - if ($result) - { - $num = $db->num_rows(); - if ($num) - { - print ''; - print ''; - print ''; - print ''; - print "\n"; - $i = 0; - $var = True; - $total = $total_ttc = $totalam = 0; - while ($i < $num) - { - $obj = $db->fetch_object($result); - $var = !$var; - print ''; - print ''; - print ''; - print ''; - print ''; - $total += $obj->total_ht; - $total_ttc += $obj->total_ttc; - $totalam += $obj->am; - $i++; - } - $var=!$var; - - print ''; - print ''; - print ''; - print ''; - print '
'.$langs->trans("BillsSuppliersUnpayed").' ('.$num.')'.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").'
'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.''.img_object($langs->trans("ShowSupplier"),"company").' '.dolibarr_trunc($obj->nom,50).''.price($obj->total_ht).''.price($obj->total_ttc).'
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToPay").': '.price($total_ttc-$totalam).') '.price($total).''.price($total_ttc).'

'; - } - } - else - { - dolibarr_print_error($db); - } - } - -} - - -print '
'; - -$db->close(); - - -llxFooter('$Date$ - $Revision$'); -?> + + * Copyright (C) 2004-2005 Laurent Destailleur + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/compta/index.php + \ingroup compta + \brief Page accueil zone comptabilité + \version $Revision$ +*/ + +require("./pre.inc.php"); + +$user->getrights(); // On a besoin des permissions sur plusieurs modules + +$langs->load("compta"); +$langs->load("bills"); + +// Sécurité accés client +$socidp=''; +if ($user->societe_id > 0) +{ + $action = ''; + $socidp = $user->societe_id; +} + + +llxHeader("",$langs->trans("AccountancyTreasuryArea")); + + +/* + * Actions + */ + +if (isset($_GET["action"]) && $_GET["action"] == 'add_bookmark') +{ +$sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark WHERE fk_soc = ".$socidp." AND fk_user=".$user->id; +if (! $db->query($sql) ) +{ + dolibarr_print_error($db); +} +$sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_soc, dateb, fk_user) VALUES ($socidp, now(),".$user->id.");"; +if (! $db->query($sql) ) +{ + dolibarr_print_error($db); +} +} + +if (isset($_GET["action"]) && $_GET["action"] == 'del_bookmark') +{ + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark WHERE rowid=".$_GET["bid"]; + $result = $db->query($sql); +} + + + +/* + * Affichage page + * + */ +print_fiche_titre($langs->trans("AccountancyTreasuryArea")); + +print ''; + +print ''; + +print '
'; + +/* + * Zone recherche facture + */ +if ($conf->facture->enabled) { + print '
'; + print ''; + print ""; + print ''; + print "'; + print ''; + print "'; + print ''; + print "
'.$langs->trans("SearchABill").'
".$langs->trans("Ref").':
".$langs->trans("Other").':

"; +} + + +/** + * Factures brouillons + */ +if ($conf->facture->enabled && $user->rights->facture->lire) +{ + + $sql = "SELECT f.facnumber, f.rowid, f.total_ttc, s.nom, s.idp"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " WHERE s.idp = f.fk_soc AND f.fk_statut = 0"; + + if ($socidp) + { + $sql .= " AND f.fk_soc = $socidp"; + } + + $resql = $db->query($sql); + + if ( $resql ) + { + $num = $db->num_rows($resql); + if ($num) + { + print ''; + print ''; + print ''; + $i = 0; + $tot_ttc = 0; + $var = True; + while ($i < $num && $i < 20) + { + $obj = $db->fetch_object($resql); + $var=!$var; + print ''; + print ''; + print ''; + print ''; + $tot_ttc+=$obj->total_ttc; + $i++; + } + + print ''; + print ''; + print ''; + + print "
'.$langs->trans("DraftBills").' ('.$num.')
'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.''.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($obj->nom,20).''.price($obj->total_ttc).'
'.$langs->trans("Total").''.price($tot_ttc).'

"; + } + $db->free($resql); + } + else + { + dolibarr_print_error($db); + } +} + +/** + * Charges a payer + */ +if ($conf->compta->enabled) +{ + if ($user->societe_id == 0) + { + + $sql = "SELECT c.rowid, c.amount, cc.libelle"; + $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as c, ".MAIN_DB_PREFIX."c_chargesociales as cc"; + $sql .= " WHERE c.fk_type = cc.id AND c.paye=0"; + + $resql = $db->query($sql); + + if ( $resql ) + { + $num = $db->num_rows($resql); + if ($num) + { + print ''; + print ''; + print ''; + $i = 0; + $tot_ttc=0; + $var = True; + while ($i < $num) + { + $obj = $db->fetch_object($resql); + $var = !$var; + print ""; + print ''; + print ''; + print ''; + $tot_ttc+=$obj->amount; + $i++; + } + + print ''; + print ''; + print ''; + + print '
'.$langs->trans("ContributionsToPay").' ('.$num.')
'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->libelle.''.price($obj->amount).'
'.$langs->trans("Total").''.price($tot_ttc).'

'; + } + $db->free($resql); + } + else + { + dolibarr_print_error($db); + } + } +} + + +/** + * Bookmark + */ +$sql = "SELECT s.idp, s.nom,b.rowid as bid"; +$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."bookmark as b"; +$sql .= " WHERE b.fk_soc = s.idp AND b.fk_user = ".$user->id; +$sql .= " ORDER BY lower(s.nom) ASC"; + +$resql = $db->query($sql); + +if ( $resql ) +{ + $num = $db->num_rows($resql); + $i = 0; + if ($num) + { + print ''; + print "\n"; + $var = True; + while ($i < $num) + { + $obj = $db->fetch_object($resql); + $var = !$var; + print ""; + print ''; + print ''; + print ''; + $i++; + } + print '
".$langs->trans("Bookmarks")."
'.$obj->nom.''.img_delete().'
'; + } + $db->free($resql); +} +else +{ + dolibarr_print_error($db); +} + + +print '
'; + + +/* + * Commandes à facturer + */ +if ($conf->commande->enabled && $user->rights->commande->lire) +{ + $langs->load("orders"); + + $sql = "SELECT sum(f.total) as tot_fht, sum(f.total_ttc) as tot_fttc"; + $sql .= " ,s.nom, s.idp, p.rowid, p.ref, p.total_ht, p.total_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."commande AS p, llx_societe AS s"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid"; + $sql .= " WHERE p.fk_soc = s.idp"; + if ($socidp) + { + $sql .= " AND p.fk_soc = $socidp"; + } + $sql .= " AND p.fk_statut >=1 AND p.facture=0"; + $sql .= " GROUP BY p.rowid"; + + $resql = $db->query($sql); + + if ( $resql ) + { + $num = $db->num_rows($resql); + if ($num) + { + $i = 0; + print ''; + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + $var = True; + $tot_ht=$tot_ttc=$tot_tobill=0; + while ($i < $num) + { + $obj = $db->fetch_object($resql); +// if ($obj->total_ttc-$obj->tot_fttc >0) +// { + $var=!$var; + print ""; + print "'; + + print ''; + print ''; + print ''; + print ''; + $tot_ht += $obj->total_ht; + $tot_ttc += $obj->total_ttc; + $tot_tobill += ($obj->total_ttc-$obj->tot_fttc); +// } + $i++; + } + $var=!$var; + + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'.$langs->trans("OrdersToBill").' ('.$num.')'.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("ToBill").'
rowid\">".img_object($langs->trans("ShowOrder"),"order").' '; + print "rowid\">".$obj->ref.''.img_object($langs->trans("ShowCompany"),"company").' '; + print ''.dolibarr_trunc($obj->nom,50).''.price($obj->total_ht).''.price($obj->total_ttc).''.price($obj->total_ttc-$obj->tot_fttc).'
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToBill").': '.price($tot_tobill).') '.price($tot_ht).''.price($tot_ttc).''.price($tot_tobill).'

'; + } + $db->free($resql); + } + else + { + dolibarr_print_error($db); + } +} + + +if ($conf->facture->enabled && $user->rights->facture->lire) +{ + + /* + * Factures impayées + * + */ + + $sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total, f.total_ttc, ".$db->pdate("f.date_lim_reglement")." as datelimite, sum(pf.amount) as am"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture"; + $sql.= " WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1"; + if ($socidp) $sql .= " AND f.fk_soc = $socidp"; + $sql.= " GROUP BY f.facnumber, f.rowid, s.nom, s.idp, f.total, f.total_ttc"; + $sql.= " ORDER BY f.datef ASC "; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + if ($num) + { + print ''; + print ''; + print ''; + $var = True; + $total_ttc = $totalam = $total = 0; + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + if ($i < $conf->liste_limit) + { + $var=!$var; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + $total_ttc += $obj->total_ttc; + $total += $obj->total; + $totalam += $obj->am; + $i++; + } + $var=!$var; + + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'.$langs->trans("BillsCustomersUnpayed").' ('.$num.')'.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("Received").'
'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.''; + if ($obj->datelimite < (time() - $conf->facture->client->warning_delay)) print img_warning($langs->trans("Late")); + print ''.img_object($langs->trans("ShowCustomer"),"company").' '.dolibarr_trunc($obj->nom,44).''.price($obj->total).''.price($obj->total_ttc).''.price($obj->am).'
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToTake").': '.price($total_ttc-$totalam).') '.price($total).''.price($total_ttc).''.price($totalam).'

'; + } + $db->free($resql); + } + else + { + dolibarr_print_error($db); + } +} + + +// \todo Mettre ici recup des actions en rapport avec la compta +$resql = 0; +if ($resql) +{ + print ''; + print ''; + print "\n"; + $var = True; + $i = 0; + while ($i < $db->num_rows($resql) ) + { + $obj = $db->fetch_object($resql); + $var=!$var; + + print ""; + $i++; + } + $db->free($resql); + print "
'.$langs->trans("TasksToDo").'
".strftime("%d %b %Y",$obj->da)."$obj->libelle $obj->label

"; +} + + +/* + * Factures a payer + */ +if ($conf->facture->enabled) { + + if ($user->societe_id == 0) + { + $sql = "SELECT ff.rowid, ff.facnumber, ff.libelle, ff.total_ht, ff.total_ttc, s.nom, s.idp"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff"; + $sql .= " WHERE s.idp = ff.fk_soc"; + $sql .= " AND ff.paye=0"; + + $result=$db->query($sql); + if ($result) + { + $num = $db->num_rows(); + if ($num) + { + print ''; + print ''; + print ''; + print ''; + print "\n"; + $i = 0; + $var = True; + $total = $total_ttc = $totalam = 0; + while ($i < $num) + { + $obj = $db->fetch_object($result); + $var = !$var; + print ''; + print ''; + print ''; + print ''; + print ''; + $total += $obj->total_ht; + $total_ttc += $obj->total_ttc; + $totalam += $obj->am; + $i++; + } + $var=!$var; + + print ''; + print ''; + print ''; + print ''; + print '
'.$langs->trans("BillsSuppliersUnpayed").' ('.$num.')'.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").'
'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.''.img_object($langs->trans("ShowSupplier"),"company").' '.dolibarr_trunc($obj->nom,50).''.price($obj->total_ht).''.price($obj->total_ttc).'
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToPay").': '.price($total_ttc-$totalam).') '.price($total).''.price($total_ttc).'

'; + } + } + else + { + dolibarr_print_error($db); + } + } + +} + + +print '
'; + +$db->close(); + + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/includes/pear/Auth/Auth.php b/htdocs/includes/pear/Auth/Auth.php index 8f5d92f1ca5..cbe7c5fde37 100644 --- a/htdocs/includes/pear/Auth/Auth.php +++ b/htdocs/includes/pear/Auth/Auth.php @@ -1,816 +1,816 @@ - | -// +----------------------------------------------------------------------+ -// -// $Id$ -// -require_once DOL_DOCUMENT_ROOT."/includes/pear/PEAR.php"; -//require_once "PEAR.php"; - -define("AUTH_IDLED", -1); -define("AUTH_EXPIRED", -2); -define("AUTH_WRONG_LOGIN", -3); - -/** - * PEAR::Auth - * - * The PEAR::Auth class provides methods for creating an - * authentication system using PHP. - * - * @author Martin Jansen - * @package Auth - * @version $Revision$ - */ -class DOLIAuth { - - /** - * Auth lifetime in seconds - * - * If this variable is set to 0, auth never expires - * - * @var integer - * @see setExpire(), checkAuth() - */ - var $expire = 0; - - /** - * Has the auth session expired? - * - * @var bool - * @see checkAuth(), drawLogin() - */ - var $expired = false; - - /** - * Maximum time of idleness in seconds - * - * The difference to $expire is, that the idletime gets - * refreshed each time, checkAuth() is called. If this - * variable is set to 0, idle time is never checked. - * - * @var integer - * @see setIdle(), checkAuth() - */ - var $idle = 0; - - /** - * Is the maximum idletime over? - * - * @var boolean - * @see checkAuth(), drawLogin(); - */ - var $idled = false; - - /** - * Storage object - * - * @var object - * @see Auth(), validateLogin() - */ - var $storage = ""; - - /** - * function defined by the user, that creates the login screen - * - * @var string - */ - var $loginfunction = ""; - - /** - * Should the login form be displayed? - * - * @var bool - * @see setShowlogin() - */ - var $showLogin = true; - - /** - * Current authentication status - * - * @var string - */ - var $status = ""; - - /** - * Username - * - * @var string - */ - var $username = ""; - - /** - * Password - * - * @var string - */ - var $password = ""; - - /** - * Login callback function name - * - * @var string - * @see setLoginCallback() - */ - var $loginCallback = ""; - - /** - * Logout callback function name - * - * @var string - * @see setLogoutCallback() - */ - var $logoutCallback = ""; - - // {{{ Constructor - - /** - * Constructor - * - * Set up the storage driver. - * - * @param string Type of the storage driver - * @param mixed Additional options for the storage driver - * (example: if you are using DB as the storage - * driver, you have to pass the dsn string here) - * - * @param string Name of the function that creates the login form - * @param boolean Should the login form be displayed if neccessary? - * @return void - */ - function DOLIAuth($storageDriver, $options = "", $loginfunction = "", $showLogin = true) - { - if ($loginfunction != "" && function_exists($loginfunction)) { - $this->loginfunction = $loginfunction; - } - - if (is_bool($showLogin)) { - $this->showLogin = $showLogin; - } - - if (is_object($storageDriver)) { - $this->storage =& $storageDriver; - } - else{ - $this->storage = $this->_factory($storageDriver, $options); - } - } - - // }}} - // {{{ _factory() - - /** - * Return a storage driver based on $driver and $options - * - * @access private - * @static - * @param string $driver Type of storage class to return - * @param string $options Optional parameters for the storage class - * @return object Object Storage object - */ - function _factory($driver, $options = "") - { - $storage_path = "Auth/Container/" . $driver . ".php"; - $storage_class = "Auth_Container_" . $driver; - - require_once DOL_DOCUMENT_ROOT."/includes/pear/".$storage_path; - - return new $storage_class($options); - } - - // }}} - // {{{ assignData() - - /** - * Assign data from login form to internal values - * - * This function takes the values for username and password - * from $HTTP_POST_VARS and assigns them to internal variables. - * If you wish to use another source apart from $HTTP_POST_VARS, - * you have to derive this function. - * - * @access private - * @global $HTTP_POST_VARS - * @see Auth - * @return void - */ - function assignData() - { - $post = &$this->_importGlobalVariable("post"); - - if (isset($post['username']) && $post['username'] != "") { - $this->username = (get_magic_quotes_gpc() == 1 ? stripslashes($post['username']) : $post['username']); - } - - if (isset($post['password']) && $post['password'] != "") { - $this->password = (get_magic_quotes_gpc() == 1 ? stripslashes($post['password']) : $post['password'] ); - } - - } - - // }}} - // {{{ start() - - /** - * Start new auth session - * - * @access public - * @return void - */ - function start() - { - $this->assignData(); - - session_start(); - - if (!$this->checkAuth()) { - $this->login(); - } - } - - // }}} - // {{{ login() - - /** - * Login function - * - * @access private - * @return void - */ - function login() - { - $login_ok = false; - - /** - * When the user has already entered a username, - * we have to validate it. - */ - if (!empty($this->username)) { - if (true === $this->storage->fetchData($this->username, $this->password)) { - $login_ok = true; - } - } - - if (!empty($this->username) && $login_ok) { - $this->setAuth($this->username); - if (!empty($this->loginCallback)) { - call_user_func($this->loginCallback,$this->username); - } - } - - /** - * If the login failed or the user entered no username, - * output the login screen again. - */ - if (!empty($this->username) && !$login_ok) { - $this->status = AUTH_WRONG_LOGIN; - } - - if ((empty($this->username) || !$login_ok) && $this->showLogin) { - $this->drawLogin($this->storage->activeUser); - return; - } - } - - // }}} - // {{{ setExpire() - - /** - * Set the maximum expire time - * - * @access public - * @param integer time in seconds - * @param bool add time to current expire time or not - * @return void - */ - function setExpire($time, $add = false) - { - if ($add) { - $this->expire += $time; - } else { - $this->expire = $time; - } - } - - // }}} - // {{{ setIdle() - - /** - * Set the maximum idle time - * - * @access public - * @param integer time in seconds - * @param bool add time to current maximum idle time or not - * @return void - */ - function setIdle($time, $add = false) - { - if ($add) { - $this->idle += $time; - } else { - $this->idle = $time; - } - } - - // }}} - // {{{ setSessionname() - - /** - * Set name of the session to a customized value. - * - * If you are using multiple instances of PEAR::Auth - * on the same domain, you can change the name of - * session per application via this function. - * - * @access public - * @param string New name for the session - * @return void - */ - function setSessionname($name = "PHPSESSID") - { - @session_name($name); - } - - // }}} - // {{{ setShowLogin() - - /** - * Should the login form be displayed if neccessary? - * - * @access public - * @param bool show login form or not - * @return void - */ - function setShowLogin($showLogin = true) - { - $this->showLogin = $showLogin; - } - - /** - * Register a callback function to be called on user login. - * The function will receive a single parameter, the username. - * - * @access public - * @param string callback function name - * @return void - * @see setLogoutCallback() - */ - function setLoginCallback($loginCallback) - { - $this->loginCallback = $loginCallback; - } - - /** - * Register a callback function to be called on user logout. - * The function will receive a single parameter, the username. - * - * @access public - * @param string callback function name - * @return void - * @see setLoginCallback() - */ - function setLogoutCallback($logoutCallback) - { - $this->logoutCallback = $logoutCallback; - } - - // }}} - // {{{ setAuthData() - - /** - * Register additional information that is to be stored - * in the session. - * - * @access public - * @param string Name of the data field - * @param mixed Value of the data field - * @param boolean Should existing data be overwritten? (default - * is true) - * @return void - */ - function setAuthData($name, $value, $overwrite = true) - { - $session = &DOLIAuth::_importGlobalVariable("session"); - - if (!empty($session['auth']['data'][$name]) && $overwrite == false) { - return; - } - $session['auth']['data'][$name] = $value; - } - - // }}} - // {{{ getAuthData() - - /** - * Get additional information that is stored in the session. - * - * If no value for the first parameter is passed, the method will - * return all data that is currently stored. - * - * @access public - * @param string Name of the data field - * @return mixed Value of the data field. - */ - function getAuthData($name = null) - { - $session = &DOLIAuth::_importGlobalVariable("session"); - - if (is_null($name)) { - return $session['auth']['data']; - } - if (isset($session['auth']['data'][$name])) { - return $session['auth']['data'][$name]; - } else { - return null; - } - } - - // }}} - // {{{ setAuth() - - /** - * Register variable in a session telling that the user - * has logged in successfully - * - * @access public - * @param string Username - * @return void - */ - function setAuth($username) - { - $session = &DOLIAuth::_importGlobalVariable("session"); - - if (!isset($session['auth']) && !isset($_SESSION)) { - session_register("auth"); - } - - if (!isset($session['auth']) || !is_array($session['auth'])) { - $session['auth'] = array(); - } - - if(!isset($session['auth']['data'])){ - $session['auth']['data'] = array(); - } - $session['auth']['registered'] = true; - $session['auth']['username'] = $username; - $session['auth']['timestamp'] = time(); - $session['auth']['idle'] = time(); - } - - // }}} - // {{{ checkAuth() - - /** - * Checks if there is a session with valid auth information. - * - * @access private - * @return boolean Whether or not the user is authenticated. - */ - function checkAuth() - { - $session = &$this->_importGlobalVariable("session"); - - if (isset($session['auth'])) { - /** Check if authentication session is expired */ - if ($this->expire > 0 && - isset($session['auth']['timestamp']) && - ($session['auth']['timestamp'] + $this->expire) < time()) { - - $this->logout(); - $this->expired = true; - $this->status = AUTH_EXPIRED; - - return false; - } - - /** Check if maximum idle time is reached */ - if ($this->idle > 0 && - isset($session['auth']['idle']) && - ($session['auth']['idle'] + $this->idle) < time()) { - - $this->logout(); - $this->idled = true; - $this->status = AUTH_IDLED; - - return false; - } - - if (isset($session['auth']['registered']) && - isset($session['auth']['username']) && - $session['auth']['registered'] == true && - $session['auth']['username'] != "") { - - DOLIAuth::updateIdle(); - - return true; - } - } - - return false; - } - - // }}} - // {{{ getAuth() - - /** - * Has the user been authenticated? - * - * @access public - * @return bool True if the user is logged in, otherwise false. - */ - function getAuth() - { - $session = &$this->_importGlobalVariable("session"); - - if (!empty($session) && - (isset($session['auth']['registered']) && - $session['auth']['registered'] === true)) - { - return true; - } else { - return false; - } - } - - // }}} - // {{{ drawLogin() - - /** - * Draw the login form - * - * Normally you will not use this output in your application, - * because you can pass a different function name to the - * constructor. For more information on this, please - * consult the documentation. - * - * @access private - * @param string Username if already entered - * @return void - */ - function drawLogin($username = "") - { - if ($this->loginfunction != "") { - call_user_func($this->loginfunction, $username, $this->status); - } else { - $server = &$this->_importGlobalVariable("server"); - - echo "
\n"; - - if (!empty($this->status) && $this->status == AUTH_EXPIRED) { - echo "Your session expired. Please login again!\n"; - } else if (!empty($this->status) && $this->status == AUTH_IDLED) { - echo "You have been idle for too long. Please login again!\n"; - } else if (!empty ($this->status) && $this->status == AUTH_WRONG_LOGIN) { - echo "Wrong login data!\n"; - } - - DOLIPEAR::raiseError("You are using the built-in login screen of PEAR::Auth.
See the manual for details on how to create your own login function.", null); - - echo "
\n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; - echo "
Login:
Username:
Password:
\n"; - echo "
\n"; - echo "
\n\n"; - } - } - - // }}} - // {{{ logout() - - /** - * Logout function - * - * This function clears any auth tokens in the currently - * active session and executes the logout callback function, - * if any - * - * @access public - * @return void - */ - function logout() - { - $session = &$this->_importGlobalVariable("session"); - - if (!empty($this->logoutCallback)) { - call_user_func($this->logoutCallback, $session['auth']['username']); - } - - $this->username = ""; - $this->password = ""; - - $session['auth'] = array(); - if (isset($_SESSION)) { - unset($session['auth']); - } else { - session_unregister("auth"); - } - } - - // }}} - // {{{ updateIdle() - - /** - * Update the idletime - * - * @access private - * @return void - */ - function updateIdle() - { - $session = &$this->_importGlobalVariable("session"); - $session['auth']['idle'] = time(); - } - - // }}} - // {{{ getUsername() - - /** - * Get the username - * - * @access public - * @return string - */ - function getUsername() - { - $session = &$this->_importGlobalVariable("session"); - if (!isset($session['auth']['username'])) { - return ""; - } - return $session['auth']['username']; - } - - // }}} - // {{{ getStatus() - - /** - * Get the current status - * - * @access public - * @return string - */ - function getStatus() - { - return $this->status; - } - - // }}} - // {{{ sessionValidThru() - - /** - * Returns the time up to the session is valid - * - * @access public - * @return integer - */ - function sessionValidThru() - { - $session = &$this->_importGlobalVariable("session"); - if (!isset($session['auth']['idle'])) { - return 0; - } - return ($session['auth']['idle'] + $this->idle); - } - - // }}} - // {{{ listUsers() - - /** - * List all users that are currently available in the storage - * container - * - * @access public - * @return array - */ - function listUsers() - { - return $this->storage->listUsers(); - } - - // }}} - // {{{ addUser() - - /** - * Add user to the storage container - * - * @access public - * @param string Username - * @param string Password - * @param mixed Additional parameters - * @return mixed True on success, PEAR error object on error - * and AUTH_METHOD_NOT_SUPPORTED otherwise. - */ - function addUser($username, $password, $additional = "") - { - return $this->storage->addUser($username, $password, $additional); - } - - // }}} - // {{{ removeUser() - - /** - * Remove user from the storage container - * - * @access public - * @param string Username - * @return mixed True on success, PEAR error object on error - * and AUTH_METHOD_NOT_SUPPORTED otherwise. - */ - function removeUser($username) - { - return $this->storage->removeUser($username); - } - - // }}} - // {{{ _importGlobalVariable() - - /** - * Import variables from special namespaces. - * - * @access private - * @param string Type of variable (server, session, post) - * @return array - */ - function &_importGlobalVariable($variable) - { - $var = null; - - switch (strtolower($variable)) { - - case "server" : - if (isset($_SERVER)) { - $var = &$_SERVER; - } else { - $var = &$GLOBALS['HTTP_SERVER_VARS']; - } - break; - - case "session" : - if (isset($_SESSION)) { - $var = &$_SESSION; - } else { - $var = &$GLOBALS['HTTP_SESSION_VARS']; - } - break; - - case "post" : - if (isset($_POST)) { - $var = &$_POST; - } else { - $var = &$GLOBALS['HTTP_POST_VARS']; - } - break; - - case "cookie" : - if (isset($_COOKIE)) { - $var = &$_COOKIE; - } else { - $var = &$GLOBALS['HTTP_COOKIE_VARS']; - } - break; - - case "get" : - if (isset($_GET)) { - $var = &$_GET; - } else { - $var = &$GLOBALS['HTTP_GET_VARS']; - } - break; - - default: - break; - - } - - return $var; - } - - // }}} -} -?> + | +// +----------------------------------------------------------------------+ +// +// $Id$ +// +require_once DOL_DOCUMENT_ROOT."/includes/pear/PEAR.php"; +//require_once "PEAR.php"; + +define("AUTH_IDLED", -1); +define("AUTH_EXPIRED", -2); +define("AUTH_WRONG_LOGIN", -3); + +/** + * PEAR::Auth + * + * The PEAR::Auth class provides methods for creating an + * authentication system using PHP. + * + * @author Martin Jansen + * @package Auth + * @version $Revision$ + */ +class DOLIAuth { + + /** + * Auth lifetime in seconds + * + * If this variable is set to 0, auth never expires + * + * @var integer + * @see setExpire(), checkAuth() + */ + var $expire = 0; + + /** + * Has the auth session expired? + * + * @var bool + * @see checkAuth(), drawLogin() + */ + var $expired = false; + + /** + * Maximum time of idleness in seconds + * + * The difference to $expire is, that the idletime gets + * refreshed each time, checkAuth() is called. If this + * variable is set to 0, idle time is never checked. + * + * @var integer + * @see setIdle(), checkAuth() + */ + var $idle = 0; + + /** + * Is the maximum idletime over? + * + * @var boolean + * @see checkAuth(), drawLogin(); + */ + var $idled = false; + + /** + * Storage object + * + * @var object + * @see Auth(), validateLogin() + */ + var $storage = ""; + + /** + * function defined by the user, that creates the login screen + * + * @var string + */ + var $loginfunction = ""; + + /** + * Should the login form be displayed? + * + * @var bool + * @see setShowlogin() + */ + var $showLogin = true; + + /** + * Current authentication status + * + * @var string + */ + var $status = ""; + + /** + * Username + * + * @var string + */ + var $username = ""; + + /** + * Password + * + * @var string + */ + var $password = ""; + + /** + * Login callback function name + * + * @var string + * @see setLoginCallback() + */ + var $loginCallback = ""; + + /** + * Logout callback function name + * + * @var string + * @see setLogoutCallback() + */ + var $logoutCallback = ""; + + // {{{ Constructor + + /** + * Constructor + * + * Set up the storage driver. + * + * @param string Type of the storage driver + * @param mixed Additional options for the storage driver + * (example: if you are using DB as the storage + * driver, you have to pass the dsn string here) + * + * @param string Name of the function that creates the login form + * @param boolean Should the login form be displayed if neccessary? + * @return void + */ + function DOLIAuth($storageDriver, $options = "", $loginfunction = "", $showLogin = true) + { + if ($loginfunction != "" && function_exists($loginfunction)) { + $this->loginfunction = $loginfunction; + } + + if (is_bool($showLogin)) { + $this->showLogin = $showLogin; + } + + if (is_object($storageDriver)) { + $this->storage =& $storageDriver; + } + else{ + $this->storage = $this->_factory($storageDriver, $options); + } + } + + // }}} + // {{{ _factory() + + /** + * Return a storage driver based on $driver and $options + * + * @access private + * @static + * @param string $driver Type of storage class to return + * @param string $options Optional parameters for the storage class + * @return object Object Storage object + */ + function _factory($driver, $options = "") + { + $storage_path = "Auth/Container/" . $driver . ".php"; + $storage_class = "Auth_Container_" . $driver; + + require_once DOL_DOCUMENT_ROOT."/includes/pear/".$storage_path; + + return new $storage_class($options); + } + + // }}} + // {{{ assignData() + + /** + * Assign data from login form to internal values + * + * This function takes the values for username and password + * from $HTTP_POST_VARS and assigns them to internal variables. + * If you wish to use another source apart from $HTTP_POST_VARS, + * you have to derive this function. + * + * @access private + * @global $HTTP_POST_VARS + * @see Auth + * @return void + */ + function assignData() + { + $post = &$this->_importGlobalVariable("post"); + + if (isset($post['username']) && $post['username'] != "") { + $this->username = (get_magic_quotes_gpc() == 1 ? stripslashes($post['username']) : $post['username']); + } + + if (isset($post['password']) && $post['password'] != "") { + $this->password = (get_magic_quotes_gpc() == 1 ? stripslashes($post['password']) : $post['password'] ); + } + + } + + // }}} + // {{{ start() + + /** + * Start new auth session + * + * @access public + * @return void + */ + function start() + { + $this->assignData(); + + session_start(); + + if (!$this->checkAuth()) { + $this->login(); + } + } + + // }}} + // {{{ login() + + /** + * Login function + * + * @access private + * @return void + */ + function login() + { + $login_ok = false; + + /** + * When the user has already entered a username, + * we have to validate it. + */ + if (!empty($this->username)) { + if (true === $this->storage->fetchData($this->username, $this->password)) { + $login_ok = true; + } + } + + if (!empty($this->username) && $login_ok) { + $this->setAuth($this->username); + if (!empty($this->loginCallback)) { + call_user_func($this->loginCallback,$this->username); + } + } + + /** + * If the login failed or the user entered no username, + * output the login screen again. + */ + if (!empty($this->username) && !$login_ok) { + $this->status = AUTH_WRONG_LOGIN; + } + + if ((empty($this->username) || !$login_ok) && $this->showLogin) { + $this->drawLogin($this->storage->activeUser); + return; + } + } + + // }}} + // {{{ setExpire() + + /** + * Set the maximum expire time + * + * @access public + * @param integer time in seconds + * @param bool add time to current expire time or not + * @return void + */ + function setExpire($time, $add = false) + { + if ($add) { + $this->expire += $time; + } else { + $this->expire = $time; + } + } + + // }}} + // {{{ setIdle() + + /** + * Set the maximum idle time + * + * @access public + * @param integer time in seconds + * @param bool add time to current maximum idle time or not + * @return void + */ + function setIdle($time, $add = false) + { + if ($add) { + $this->idle += $time; + } else { + $this->idle = $time; + } + } + + // }}} + // {{{ setSessionname() + + /** + * Set name of the session to a customized value. + * + * If you are using multiple instances of PEAR::Auth + * on the same domain, you can change the name of + * session per application via this function. + * + * @access public + * @param string New name for the session + * @return void + */ + function setSessionname($name = "PHPSESSID") + { + @session_name($name); + } + + // }}} + // {{{ setShowLogin() + + /** + * Should the login form be displayed if neccessary? + * + * @access public + * @param bool show login form or not + * @return void + */ + function setShowLogin($showLogin = true) + { + $this->showLogin = $showLogin; + } + + /** + * Register a callback function to be called on user login. + * The function will receive a single parameter, the username. + * + * @access public + * @param string callback function name + * @return void + * @see setLogoutCallback() + */ + function setLoginCallback($loginCallback) + { + $this->loginCallback = $loginCallback; + } + + /** + * Register a callback function to be called on user logout. + * The function will receive a single parameter, the username. + * + * @access public + * @param string callback function name + * @return void + * @see setLoginCallback() + */ + function setLogoutCallback($logoutCallback) + { + $this->logoutCallback = $logoutCallback; + } + + // }}} + // {{{ setAuthData() + + /** + * Register additional information that is to be stored + * in the session. + * + * @access public + * @param string Name of the data field + * @param mixed Value of the data field + * @param boolean Should existing data be overwritten? (default + * is true) + * @return void + */ + function setAuthData($name, $value, $overwrite = true) + { + $session = &DOLIAuth::_importGlobalVariable("session"); + + if (!empty($session['auth']['data'][$name]) && $overwrite == false) { + return; + } + $session['auth']['data'][$name] = $value; + } + + // }}} + // {{{ getAuthData() + + /** + * Get additional information that is stored in the session. + * + * If no value for the first parameter is passed, the method will + * return all data that is currently stored. + * + * @access public + * @param string Name of the data field + * @return mixed Value of the data field. + */ + function getAuthData($name = null) + { + $session = &DOLIAuth::_importGlobalVariable("session"); + + if (is_null($name)) { + return $session['auth']['data']; + } + if (isset($session['auth']['data'][$name])) { + return $session['auth']['data'][$name]; + } else { + return null; + } + } + + // }}} + // {{{ setAuth() + + /** + * Register variable in a session telling that the user + * has logged in successfully + * + * @access public + * @param string Username + * @return void + */ + function setAuth($username) + { + $session = &DOLIAuth::_importGlobalVariable("session"); + + if (!isset($session['auth']) && !isset($_SESSION)) { + session_register("auth"); + } + + if (!isset($session['auth']) || !is_array($session['auth'])) { + $session['auth'] = array(); + } + + if(!isset($session['auth']['data'])){ + $session['auth']['data'] = array(); + } + $session['auth']['registered'] = true; + $session['auth']['username'] = $username; + $session['auth']['timestamp'] = time(); + $session['auth']['idle'] = time(); + } + + // }}} + // {{{ checkAuth() + + /** + * Checks if there is a session with valid auth information. + * + * @access private + * @return boolean Whether or not the user is authenticated. + */ + function checkAuth() + { + $session = &$this->_importGlobalVariable("session"); + + if (isset($session['auth'])) { + /** Check if authentication session is expired */ + if ($this->expire > 0 && + isset($session['auth']['timestamp']) && + ($session['auth']['timestamp'] + $this->expire) < time()) { + + $this->logout(); + $this->expired = true; + $this->status = AUTH_EXPIRED; + + return false; + } + + /** Check if maximum idle time is reached */ + if ($this->idle > 0 && + isset($session['auth']['idle']) && + ($session['auth']['idle'] + $this->idle) < time()) { + + $this->logout(); + $this->idled = true; + $this->status = AUTH_IDLED; + + return false; + } + + if (isset($session['auth']['registered']) && + isset($session['auth']['username']) && + $session['auth']['registered'] == true && + $session['auth']['username'] != "") { + + DOLIAuth::updateIdle(); + + return true; + } + } + + return false; + } + + // }}} + // {{{ getAuth() + + /** + * Has the user been authenticated? + * + * @access public + * @return bool True if the user is logged in, otherwise false. + */ + function getAuth() + { + $session = &$this->_importGlobalVariable("session"); + + if (!empty($session) && + (isset($session['auth']['registered']) && + $session['auth']['registered'] === true)) + { + return true; + } else { + return false; + } + } + + // }}} + // {{{ drawLogin() + + /** + * Draw the login form + * + * Normally you will not use this output in your application, + * because you can pass a different function name to the + * constructor. For more information on this, please + * consult the documentation. + * + * @access private + * @param string Username if already entered + * @return void + */ + function drawLogin($username = "") + { + if ($this->loginfunction != "") { + call_user_func($this->loginfunction, $username, $this->status); + } else { + $server = &$this->_importGlobalVariable("server"); + + echo "
\n"; + + if (!empty($this->status) && $this->status == AUTH_EXPIRED) { + echo "Your session expired. Please login again!\n"; + } else if (!empty($this->status) && $this->status == AUTH_IDLED) { + echo "You have been idle for too long. Please login again!\n"; + } else if (!empty ($this->status) && $this->status == AUTH_WRONG_LOGIN) { + echo "Wrong login data!\n"; + } + + DOLIPEAR::raiseError("You are using the built-in login screen of PEAR::Auth.
See the manual for details on how to create your own login function.", null); + + echo "
\n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + echo "\n"; + echo " \n"; + echo "\n"; + echo "
Login:
Username:
Password:
\n"; + echo "
\n"; + echo "
\n\n"; + } + } + + // }}} + // {{{ logout() + + /** + * Logout function + * + * This function clears any auth tokens in the currently + * active session and executes the logout callback function, + * if any + * + * @access public + * @return void + */ + function logout() + { + $session = &$this->_importGlobalVariable("session"); + + if (!empty($this->logoutCallback)) { + call_user_func($this->logoutCallback, $session['auth']['username']); + } + + $this->username = ""; + $this->password = ""; + + $session['auth'] = array(); + if (isset($_SESSION)) { + unset($session['auth']); + } else { + session_unregister("auth"); + } + } + + // }}} + // {{{ updateIdle() + + /** + * Update the idletime + * + * @access private + * @return void + */ + function updateIdle() + { + $session = &$this->_importGlobalVariable("session"); + $session['auth']['idle'] = time(); + } + + // }}} + // {{{ getUsername() + + /** + * Get the username + * + * @access public + * @return string + */ + function getUsername() + { + $session = &$this->_importGlobalVariable("session"); + if (!isset($session['auth']['username'])) { + return ""; + } + return $session['auth']['username']; + } + + // }}} + // {{{ getStatus() + + /** + * Get the current status + * + * @access public + * @return string + */ + function getStatus() + { + return $this->status; + } + + // }}} + // {{{ sessionValidThru() + + /** + * Returns the time up to the session is valid + * + * @access public + * @return integer + */ + function sessionValidThru() + { + $session = &$this->_importGlobalVariable("session"); + if (!isset($session['auth']['idle'])) { + return 0; + } + return ($session['auth']['idle'] + $this->idle); + } + + // }}} + // {{{ listUsers() + + /** + * List all users that are currently available in the storage + * container + * + * @access public + * @return array + */ + function listUsers() + { + return $this->storage->listUsers(); + } + + // }}} + // {{{ addUser() + + /** + * Add user to the storage container + * + * @access public + * @param string Username + * @param string Password + * @param mixed Additional parameters + * @return mixed True on success, PEAR error object on error + * and AUTH_METHOD_NOT_SUPPORTED otherwise. + */ + function addUser($username, $password, $additional = "") + { + return $this->storage->addUser($username, $password, $additional); + } + + // }}} + // {{{ removeUser() + + /** + * Remove user from the storage container + * + * @access public + * @param string Username + * @return mixed True on success, PEAR error object on error + * and AUTH_METHOD_NOT_SUPPORTED otherwise. + */ + function removeUser($username) + { + return $this->storage->removeUser($username); + } + + // }}} + // {{{ _importGlobalVariable() + + /** + * Import variables from special namespaces. + * + * @access private + * @param string Type of variable (server, session, post) + * @return array + */ + function &_importGlobalVariable($variable) + { + $var = null; + + switch (strtolower($variable)) { + + case "server" : + if (isset($_SERVER)) { + $var = &$_SERVER; + } else { + $var = &$GLOBALS['HTTP_SERVER_VARS']; + } + break; + + case "session" : + if (isset($_SESSION)) { + $var = &$_SESSION; + } else { + $var = &$GLOBALS['HTTP_SESSION_VARS']; + } + break; + + case "post" : + if (isset($_POST)) { + $var = &$_POST; + } else { + $var = &$GLOBALS['HTTP_POST_VARS']; + } + break; + + case "cookie" : + if (isset($_COOKIE)) { + $var = &$_COOKIE; + } else { + $var = &$GLOBALS['HTTP_COOKIE_VARS']; + } + break; + + case "get" : + if (isset($_GET)) { + $var = &$_GET; + } else { + $var = &$GLOBALS['HTTP_GET_VARS']; + } + break; + + default: + break; + + } + + return $var; + } + + // }}} +} +?> diff --git a/htdocs/includes/pear/Auth/Container.php b/htdocs/includes/pear/Auth/Container.php index 438a1989022..f12e43c4d56 100644 --- a/htdocs/includes/pear/Auth/Container.php +++ b/htdocs/includes/pear/Auth/Container.php @@ -1,152 +1,152 @@ - | -// +----------------------------------------------------------------------+ -// -// $Id$ -// - -define("AUTH_METHOD_NOT_SUPPORTED", -4); - -/** - * Storage class for fetching login data - * - * @author Martin Jansen - * @package Auth - */ -class Auth_Container -{ - - /** - * User that is currently selected from the storage container. - * - * @access public - */ - var $activeUser = ""; - - // {{{ Constructor - - /** - * Constructor - * - * Has to be overwritten by each storage class - * - * @access public - */ - function Auth_Container() - { - } - - // }}} - // {{{ fetchData() - - /** - * Fetch data from storage container - * - * Has to be overwritten by each storage class - * - * @access public - */ - function fetchData() - { - } - - // }}} - // {{{ verifyPassword() - - /** - * Crypt and verfiy the entered password - * - * @param string Entered password - * @param string Password from the data container (usually this password - * is already encrypted. - * @param string Type of algorithm with which the password from - * the container has been crypted. (md5, crypt etc.) - * Defaults to "md5". - * @return bool True, if the passwords match - */ - function verifyPassword($password1, $password2, $cryptType = "md5") - { - switch ($cryptType) { - case "crypt" : - return (($password2 == "**" . $password1) || - (crypt($password1, $password2) == $password2) - ); - break; - - case "none" : - return ($password1 == $password2); - break; - - case "md5" : - return (md5($password1) == $password2); - break; - - default : - if (function_exists($cryptType)) { - return ($cryptType($password1) == $password2); - } else { - return false; - } - break; - } - } - - // }}} - // {{{ listUsers() - - /** - * List all users that are available from the storage container - */ - function listUsers() - { - return AUTH_METHOD_NOT_SUPPORTED; - } - - // }}} - // {{{ addUser() - - /** - * Add a new user to the storage container - * - * @param string Username - * @param string Password - * @param array Additional information - * - * @return boolean - */ - function addUser($username, $password, $additional=null) - { - return AUTH_METHOD_NOT_SUPPORTED; - } - - // }}} - // {{{ removeUser() - - /** - * Remove user from the storage container - * - * @param string Username - */ - function removeUser($username) - { - return AUTH_METHOD_NOT_SUPPORTED; - } - - // }}} - -} -?> + | +// +----------------------------------------------------------------------+ +// +// $Id$ +// + +define("AUTH_METHOD_NOT_SUPPORTED", -4); + +/** + * Storage class for fetching login data + * + * @author Martin Jansen + * @package Auth + */ +class Auth_Container +{ + + /** + * User that is currently selected from the storage container. + * + * @access public + */ + var $activeUser = ""; + + // {{{ Constructor + + /** + * Constructor + * + * Has to be overwritten by each storage class + * + * @access public + */ + function Auth_Container() + { + } + + // }}} + // {{{ fetchData() + + /** + * Fetch data from storage container + * + * Has to be overwritten by each storage class + * + * @access public + */ + function fetchData() + { + } + + // }}} + // {{{ verifyPassword() + + /** + * Crypt and verfiy the entered password + * + * @param string Entered password + * @param string Password from the data container (usually this password + * is already encrypted. + * @param string Type of algorithm with which the password from + * the container has been crypted. (md5, crypt etc.) + * Defaults to "md5". + * @return bool True, if the passwords match + */ + function verifyPassword($password1, $password2, $cryptType = "md5") + { + switch ($cryptType) { + case "crypt" : + return (($password2 == "**" . $password1) || + (crypt($password1, $password2) == $password2) + ); + break; + + case "none" : + return ($password1 == $password2); + break; + + case "md5" : + return (md5($password1) == $password2); + break; + + default : + if (function_exists($cryptType)) { + return ($cryptType($password1) == $password2); + } else { + return false; + } + break; + } + } + + // }}} + // {{{ listUsers() + + /** + * List all users that are available from the storage container + */ + function listUsers() + { + return AUTH_METHOD_NOT_SUPPORTED; + } + + // }}} + // {{{ addUser() + + /** + * Add a new user to the storage container + * + * @param string Username + * @param string Password + * @param array Additional information + * + * @return boolean + */ + function addUser($username, $password, $additional=null) + { + return AUTH_METHOD_NOT_SUPPORTED; + } + + // }}} + // {{{ removeUser() + + /** + * Remove user from the storage container + * + * @param string Username + */ + function removeUser($username) + { + return AUTH_METHOD_NOT_SUPPORTED; + } + + // }}} + +} +?>