*
* 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$
*
*/
require("./pre.inc.php");
if (!$user->rights->telephonie->adsl->lire) accessforbidden();
$mesg = '';
$dt = time();
$h = strftime("%H",$dt);
$m = strftime("%M",$dt);
$s = strftime("%S",$dt);
if ($_POST["action"] == 'add')
{
$ligne = new LigneAdsl($db);
$ligne->numero = $_POST["numero"];
$ligne->client = $_POST["client"];
$ligne->client_install = $_POST["client_install"];
$ligne->client_facture = $_POST["client_facture"];
$ligne->contrat = $_POST["contrat"];
$ligne->fournisseur = $_POST["fournisseur"];
$ligne->commercial = $_POST["commercial"];
$ligne->type = $_POST["type"];
$ligne->note = $_POST["note"];
if ( $ligne->create($user) == 0)
{
Header("Location: fiche.php?id=".$ligne->id);
}
else
{
$_GET["action"] = 'create_line';
$_GET["client"] = $_POST["client"];
}
}
if ($_GET["action"] == 'delete' && $user->rights->telephonie->adsl->creer)
{
$ligne = new LigneAdsl($db);
if ( $ligne->delete($_GET["id"]) == 0)
{
Header("Location: liste.php");
}
}
if ($_GET["action"] == 'ordertech')
{
$ligne = new LigneAdsl($db);
$ligne->fetch_by_id($_GET["id"]);
if ( $ligne->set_statut($user, 1) == 0)
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
if ($_GET["action"] == 'cancelordertech')
{
$ligne = new LigneAdsl($db);
$ligne->fetch_by_id($_GET["id"]);
if ( $ligne->set_statut($user, -1) == 0)
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
if ($_GET["action"] == 'refuse')
{
$ligne = new LigneAdsl($db);
$ligne->fetch_by_id($_GET["id"]);
$datea = $db->idate(mktime($h, $m , $s,
$_POST["remonth"],
$_POST["reday"],
$_POST["reyear"]));
if ( $ligne->set_statut($user, 7, $datea, $_POST["commentaire"]) == 0)
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
if ($_GET["action"] == 'resilier')
{
$ligne = new LigneAdsl($db);
$ligne->fetch_by_id($_GET["id"]);
$datea = $db->idate(mktime($h, $m , $s,
$_POST["remonth"],
$_POST["reday"],
$_POST["reyear"]));
if ( $user->rights->telephonie->adsl->gerer && $ligne->statut == 4)
{
if ( $ligne->set_statut($user, 5, $datea, $_POST["commentaire"]) == 0)
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
else
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
if ($_GET["action"] == 'annuleresilier')
{
$ligne = new LigneAdsl($db);
$ligne->fetch_by_id($_GET["id"]);
if ( $user->rights->telephonie->adsl->gerer && $ligne->statut == 5)
{
if ( $ligne->set_statut($user, 4) == 0)
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
else
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
if ($_GET["action"] == 'resilierfourn')
{
$ligne = new LigneAdsl($db);
$ligne->fetch_by_id($_GET["id"]);
$datea = $db->idate(mktime($h, $m , $s,
$_POST["remonth"],
$_POST["reday"],
$_POST["reyear"]));
if ( $user->rights->telephonie->adsl->gerer && $ligne->statut == 5)
{
if ( $ligne->set_statut($user, 6, $datea, $_POST["commentaire"]) == 0)
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
else
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
if ($_GET["action"] == 'acquitresilierfourn')
{
$ligne = new LigneAdsl($db);
$ligne->fetch_by_id($_GET["id"]);
$datea = $db->idate(mktime($h, $m , $s,
$_POST["remonth"],
$_POST["reday"],
$_POST["reyear"]));
if ( $user->rights->telephonie->adsl->gerer && $ligne->statut == 6)
{
if ( $ligne->set_statut($user, 7, $datea, $_POST["commentaire"]) == 0)
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
else
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
if ($_GET["action"] == 'commandefourn' && $user->rights->telephonie->adsl->commander)
{
$ligne = new LigneAdsl($db);
$ligne->fetch_by_id($_GET["id"]);
$datea = $db->idate(mktime($h, $m , $s,
$_POST["remonth"],
$_POST["reday"],
$_POST["reyear"]));
if ( $ligne->set_statut($user, 2, $datea, $_POST["commentaire"]) == 0)
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
if ($_GET["action"] == 'activefourn' && $user->rights->telephonie->adsl->gerer)
{
$ligne = new LigneAdsl($db);
$ligne->fetch_by_id($_GET["id"]);
$datea = $db->idate(mktime($h, $m , $s,
$_POST["remonth"],
$_POST["reday"],
$_POST["reyear"]));
$ligne->update_info($_POST["ip"], $_POST["login"], $_POST["password"]);
if ( $ligne->set_statut($user, 3, $datea, $_POST["commentaire"]) == 0)
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
if ($_GET["action"] == 'livraison' && $user->rights->telephonie->adsl->gerer)
{
$ligne = new LigneAdsl($db);
$ligne->fetch_by_id($_GET["id"]);
$datea = $db->idate(mktime($h, $m , $s,
$_POST["remonth"],
$_POST["reday"],
$_POST["reyear"]));
if ( $ligne->set_statut($user, 4, $datea, $_POST["commentaire"]) == 0)
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
if ($_GET["action"] == 'backbone' && $user->rights->telephonie->adsl->gerer)
{
$ligne = new LigneAdsl($db);
$ligne->fetch_by_id($_GET["id"]);
$datea = $db->idate(mktime($h, $m , $s,
$_POST["remonth"],
$_POST["reday"],
$_POST["reyear"]));
if ( $ligne->set_statut($user, 9, $datea, $_POST["commentaire"]) == 0)
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
if ($_GET["action"] == 'acommander')
{
$ligne = new LigneAdsl($db);
$ligne->fetch_by_id($_GET["id"]);
if ( $ligne->set_statut($user, 1, '', $_POST["commentaire"]) == 0)
{
Header("Location: fiche.php?id=".$ligne->id);
}
}
if ($_POST["action"] == 'update' && $_POST["cancel"] <> $langs->trans("Cancel"))
{
$ligne = new LigneAdsl($db);
$ligne->id = $_GET["id"];
$ligne->numero = $_POST["numero"];
$ligne->client_comm = $_POST["client_comm"];
$ligne->client = $_POST["client"];
$ligne->client_facture = $_POST["client_facture"];
$ligne->fournisseur = $_POST["fournisseur"];
$ligne->commercial = $_POST["commercial"];
$ligne->concurrent = $_POST["concurrent"];
$ligne->remise = $_POST["remise"];
$ligne->note = $_POST["note"];
if ( $ligne->update($user) )
{
$action = '';
$mesg = 'Fiche mise à jour';
}
else
{
$action = 're-edit';
$mesg = 'Fiche non mise à jour !' . "
" . $entrepot->mesg_error;
}
}
llxHeader("","","Fiche Liaison");
if ($cancel == $langs->trans("Cancel"))
{
$action = '';
}
/*
* Création en 2 étape
*
*/
if ($_GET["action"] == 'create')
{
$form = new Form($db);
print_titre("Nouvelle liaison ADSL");
if (is_object($ligne))
{
// La création a échouée
print $ligne->error_message;
}
else
{
$ligne = new LigneAdsl($db);
}
print '
';
}
elseif ($_GET["action"] == 'create_line' && $_GET["client"] > 0)
{
$form = new Form($db);
print_titre("Nouvelle liaison ADSL");
if (is_object($ligne))
{
// La création a échouée
print ''.$ligne->error_message.'
';
}
else
{
$ligne = new LigneAdsl($db);
$ligne->client_install_id = $_GET["client"];
$ligne->client_facture_id = $_GET["client"];
}
$socc = new Societe($db);
if ( $socc->fetch($_GET["client"]) == 1)
{
if (strlen($socc->code_client) == 0)
{
print '';
print '| Client | ';
print ''.$socc->nom.'';
print ' |
';
print '| Code client | ';
print $socc->code_client;
print ' |
';
print '
';
print 'Impossible de créer une ligne pour cette société, vous devez au préalablement lui affecter un code client.';
}
elseif (strlen($socc->code_client) > 0 && $socc->check_codeclient() <> 0)
{
print '';
print '| Client | ';
print ''.$socc->nom.'';
print ' |
';
print '| Code client | ';
print $socc->code_client;
print ' |
';
print '
';
print 'Le code client de cette société est incorrect, vous devez lui affecter un code client correct.';
}
else
{
print "';
}
else
{
print ''."\n";
print '';
print 'Nouveau contrat';
}
}
}
else
{
print "Erreur";
}
}
else
{
if ($_GET["id"] or $_GET["numero"])
{
if ($_GET["action"] <> 're-edit')
{
$ligne = new LigneAdsl($db);
if ($_GET["id"])
{
$result = $ligne->fetch_by_id($_GET["id"]);
}
if ($_GET["numero"])
{
$result = $ligne->fetch($_GET["numero"]);
}
}
if ( $result )
{
if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit')
{
$h=0;
$head[$h][0] = DOL_URL_ROOT."/telephonie/adsl/fiche.php?id=".$ligne->id;
$head[$h][1] = $langs->trans("Liaison ADSL");
$hselected = $h;
$h++;
$head[$h][0] = DOL_URL_ROOT."/telephonie/adsl/history.php?id=".$ligne->id;
$head[$h][1] = $langs->trans('Historique');
$h++;
dolibarr_fiche_head($head, $hselected, 'Liaison ADSL : '.$ligne->numero);
print_fiche_titre('Fiche Liaison ADSL', $mesg);
print '';
$client = new Societe($db, $ligne->client_id);
$client->fetch($ligne->client_id);
print '| Client | ';
print '';
print $client->nom.' | '.$client->code_client;
print ' |
';
print '| Numéro | '.dolibarr_print_phone($ligne->numero).' | ';
print ' |
';
print '| Débit de la liaison | '.$ligne->type.' | ';
print 'Prix de vente : '.price($ligne->prix).' euros HT |
';
$client_install = new Societe($db, $ligne->client_install_id);
$client_install->fetch($ligne->client_install_id);
print '| Client (Agence/Filiale) | ';
print $client_install->nom.' ';
print $client_install->cp . " " .$client_install->ville;
print ' |
';
$client_facture = new Societe($db);
$client_facture->fetch($ligne->client_facture_id);
print '| Client Facturé | ';
print $client_facture->nom.' ';
print $client_facture->cp . " " .$client_facture->ville;
print ' | ';
if ($ligne->mode_paiement == 'pre')
{
print 'RIB : '.$client_facture->display_rib();
}
else
{
print 'Paiement par virement';
}
print ' |
';
print '| Contrat | ';
print '';
print substr("00000000".$ligne->contrat_id,-8).' |
';
$commercial = new User($db, $ligne->commercial_id);
$commercial->fetch();
print '| Commercial | ';
print ''.$commercial->fullname.' |
';
if ( $user->rights->telephonie->adsl->gerer)
{
print '| IP | '.$ligne->ip.' |
';
print '| Login | '.$ligne->login.' |
';
print '| Password | '.$ligne->password.' |
';
}
print '| Statut | ';
print ' ';
print $ligne->statuts[$ligne->statut];
print ' |
';
print "
";
}
print '';
}
}
else
{
print "Error";
}
}
$form = new Form($db);
if ( $user->rights->telephonie->adsl->commander && $ligne->statut == 1)
{
/**
*
*/
print '| ';
print ' | ';
print ' |
';
}
if ( $user->rights->telephonie->adsl->gerer && $ligne->statut == 2)
{
/**
*
*/
print '| ';
print ' | ';
print ' |
';
}
if ( $user->rights->telephonie->adsl->gerer && $ligne->statut == 3)
{
print '| ';
print ' | ';
print ' |
';
}
if ( $user->rights->telephonie->adsl->gerer && $ligne->statut == 9)
{
print '| ';
print ' | ';
print ' |
';
}
if ( $user->rights->telephonie->adsl->gerer && $ligne->statut == 4)
{
print '| ';
print ' | ';
print ' |
';
}
if ( $user->rights->telephonie->adsl->gerer && $ligne->statut == 5)
{
print '| ';
print ' | ';
print ' |
';
}
if ( $user->rights->telephonie->adsl->gerer && $ligne->statut == 6)
{
print '| ';
print ' | ';
print ' |
';
}
/* ************************************************************************** */
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
print "\n
\n";
$db->close();
llxFooter("Dernière modification $Date$ révision $Revision$");
?>