From 9036b624654a8961f15539f3fa1bd385de003804 Mon Sep 17 00:00:00 2001
From: Rodolphe Quiedeville <rodolphe@quiedeville.org>
Date: Tue, 17 May 2005 15:25:40 +0000
Subject: [PATCH] Ajout ChangeContrat

---
 htdocs/telephonie/ligne/fiche.php    | 69 ++++++++++++++++++++++++++--
 htdocs/telephonie/lignetel.class.php | 12 +++++
 2 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/htdocs/telephonie/ligne/fiche.php b/htdocs/telephonie/ligne/fiche.php
index d538fdee91f..8d5509215b8 100644
--- a/htdocs/telephonie/ligne/fiche.php
+++ b/htdocs/telephonie/ligne/fiche.php
@@ -80,7 +80,7 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes')
     }
 }
 
-if ($_POST["action"] == 'updateremise')
+if ($_POST["action"] == 'updateremise' && $user->rights->telephonie->ligne->creer)
 {
   $ligne = new LigneTel($db);
   $ligne->id = $_GET["id"];
@@ -95,6 +95,17 @@ if ($_POST["action"] == 'updateremise')
     }  
 }
 
+if ($_POST["action"] == 'changecontrat' && $user->rights->telephonie->ligne->creer)
+{
+  $ligne = new LigneTel($db);
+  $ligne->id = $_GET["id"];
+
+  if ( $ligne->ChangeContrat($user, $_POST["contrat"]) == 0)
+    {
+      Header("Location: fiche.php?id=".$ligne->id);
+    } 
+}
+
 if ($_POST["action"] == 'addcontact')
 {
   $ligne = new LigneTel($db);
@@ -687,7 +698,7 @@ else
 			  $i++;
 			}
 		    }
-		  $db->free();     
+		  $db->free();
 
 		}
 	      else
@@ -705,7 +716,7 @@ else
 
 	      print "</table><br />";
 
-	      if ($_GET["action"] == "editremise" &&  $ligne->statut <> 6)
+	      if ($_GET["action"] == "editremise" &&  $ligne->statut <> 6 && $user->rights->telephonie->ligne->creer)
 		{
 		  /**
 		   * Edition de la remise
@@ -728,6 +739,53 @@ else
 		  print '</form>';
 		}
 
+	      if ($_GET["action"] == "chgcontrat" && $user->rights->telephonie->ligne->creer)
+		{
+		  /**
+		   * Edition de la remise
+		   */
+
+		  print '<form action="fiche.php?id='.$ligne->id.'" method="POST">';
+		  print '<input type="hidden" name="action" value="changecontrat">';
+		  print '<table class="border" width="100%" cellpadding="4" cellspacing="0">';
+		  print '<tr class="liste_titre"><td colspan="2">Migrer vers un autre contrat</td></tr>';
+		  print '<tr><td width="20%">Nouveau contrat</td><td>';
+		  print '<select name="contrat">';
+
+		  $sql = "SELECT c.rowid, c.ref ";
+		  $sql .= "FROM ".MAIN_DB_PREFIX."telephonie_contrat as c";
+		  $sql .= " WHERE c.rowid <> ".$ligne->contrat;
+		  $sql .= " AND c.fk_client_comm = ".$ligne->client_comm_id;
+
+		  $resql =  $db->query($sql);
+		  if ($resql)
+		    {
+		      $num = $db->num_rows($resql);
+		      $i = 0;
+		      while ($i < $num)
+			{
+			  $row = $db->fetch_row($resql);
+			  
+			  print '<option value="'.$row[0].'">'.$row[1];
+			  $i++;
+			}
+		      
+		      $db->free();
+		    }
+		  else
+		    {
+		      print $sql;
+		    }
+
+		  print '</select></td></tr>';
+
+		  print '<tr><td align="center" colspan="2"><input type="submit" value="Migrer"></td></tr>';
+
+		  print '</table><br />';
+		  
+		  print '</form>';
+		}
+
 
 	    }
 
@@ -1163,6 +1221,11 @@ if ($_GET["action"] == '')
   print "<a class=\"tabAction\" href=\"fiche.php?action=contact&amp;id=$ligne->id\">".$langs->trans("Contact")."</a>";
     }
 
+  if ( $user->rights->telephonie->ligne->creer && $ligne->statut < 4)
+    {
+      print "<a class=\"tabAction\" href=\"fiche.php?action=chgcontrat&amp;id=$ligne->id\">".$langs->trans("Changer de contrat")."</a>";
+    }
+
   if ( $user->rights->telephonie->ligne->creer && $ligne->statut < 4)
     {
       print "<a class=\"tabAction\" href=\"fiche.php?action=editremise&amp;id=$ligne->id\">".$langs->trans("Changer la remise")."</a>";
diff --git a/htdocs/telephonie/lignetel.class.php b/htdocs/telephonie/lignetel.class.php
index fb8f3e30e59..f7de1d790be 100644
--- a/htdocs/telephonie/lignetel.class.php
+++ b/htdocs/telephonie/lignetel.class.php
@@ -704,5 +704,17 @@ class LigneTel {
 	  return -2;
 	}
     }
+
+  function ChangeContrat($user, $contrat_id)
+  {
+    $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_societe_ligne";
+    $sql .= " SET fk_contrat = ".$contrat_id ;
+    $sql .= " WHERE rowid = ".$this->id;
+
+    $resql = $this->db->query($sql);
+
+    return 0;
+  }
+
 }
 ?>
-- 
GitLab