[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net> 3 * Copyright (C) 2005 Destailleur Laurent <eldy@users.sourceforge.net> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * $Id: contact.php,v 1.4 2005/12/03 17:18:35 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/compta/facture/contact.php,v $ 21 */ 22 23 /** 24 \file htdocs/compta/contact.php 25 \ingroup facture 26 \brief Onglet de gestion des contacts des factures 27 \version $Revision: 1.4 $ 28 */ 29 30 require ("./pre.inc.php"); 31 require_once (DOL_DOCUMENT_ROOT."/facture.class.php"); 32 require_once (DOL_DOCUMENT_ROOT."/contact.class.php"); 33 require_once(DOL_DOCUMENT_ROOT.'/lib/invoice.lib.php'); 34 35 $langs->load("facture"); 36 // $langs->load("orders"); 37 $langs->load("companies"); 38 39 $user->getrights('facture'); 40 41 if (!$user->rights->facture->lire) 42 accessforbidden(); 43 44 // les methodes locales 45 /** 46 * \brief Retourne la liste déroulante des sociétés 47 * \param selected Societe présélectionnée 48 * \param htmlname Nom champ formulaire 49 */ 50 function select_societes_for_newconcat($facture, $selected = '', $htmlname = 'newcompany') 51 { 52 // On recherche les societes 53 $sql = "SELECT s.idp, s.nom FROM"; 54 $sql .= " ".MAIN_DB_PREFIX."societe as s"; 55 // if ($filter) $sql .= " WHERE $filter"; 56 $sql .= " ORDER BY nom ASC"; 57 58 $resql = $facture->db->query($sql); 59 if ($resql) 60 { 61 $javaScript = "window.location='./contact.php?facid=".$facture->id."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;"; 62 print '<select class="flat" name="'.$htmlname.'" onChange="'.$javaScript.'">'; 63 $num = $facture->db->num_rows($resql); 64 $i = 0; 65 if ($num) 66 { 67 while ($i < $num) 68 { 69 $obj = $facture->db->fetch_object($resql); 70 if ($i == 0) 71 $firstCompany = $obj->idp; 72 if ($selected > 0 && $selected == $obj->idp) 73 { 74 print '<option value="'.$obj->idp.'" selected="true">'.dolibarr_trunc($obj->nom,24).'</option>'; 75 $firstCompany = $obj->idp; 76 } else 77 { 78 print '<option value="'.$obj->idp.'">'.dolibarr_trunc($obj->nom,24).'</option>'; 79 } 80 $i ++; 81 } 82 } 83 print "</select>\n"; 84 return $firstCompany; 85 } else 86 { 87 dolibarr_print_error($facture->db); 88 } 89 } 90 91 /** 92 * 93 */ 94 function select_type_contact($facture, $defValue, $htmlname = 'type', $source) 95 { 96 $lesTypes = $facture->liste_type_contact($source); 97 print '<select class="flat" name="'.$htmlname.'">'; 98 foreach($lesTypes as $key=>$value) 99 { 100 print '<option value="'.$key.'">'.$value.'</option>'; 101 } 102 print "</select>\n"; 103 } 104 105 106 // Sécurité accés client 107 if ($user->societe_id > 0) 108 { 109 $action = ''; 110 $socidp = $user->societe_id; 111 } 112 113 /* 114 * Ajout d'un nouveau contact 115 */ 116 117 if ($_POST["action"] == 'addcontact' && $user->rights->facture->creer) 118 { 119 120 $result = 0; 121 $facture = new Facture($db); 122 $result = $facture->fetch($_GET["facid"]); 123 124 if ($result > 0 && $_GET["facid"] > 0) 125 { 126 $result = $facture->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]); 127 } 128 129 if ($result >= 0) 130 { 131 Header("Location: contact.php?facid=".$facture->id); 132 exit; 133 } else 134 { 135 $mesg = '<div class="error">'.$facture->error.'</div>'; 136 } 137 } 138 // modification d'un contact. On enregistre le type 139 if ($_POST["action"] == 'updateligne' && $user->rights->facture->creer) 140 { 141 $facture = new Facture($db); 142 if ($facture->fetch($_GET["facid"])) 143 { 144 $contact = $facture->detail_contact($_POST["elrowid"]); 145 $type = $_POST["type"]; 146 $statut = $contact->statut; 147 148 $result = $facture->update_contact($_POST["elrowid"], $statut, $type); 149 if ($result >= 0) 150 { 151 $db->commit(); 152 } else 153 { 154 dolibarr_print_error($db, "result=$result"); 155 $db->rollback(); 156 } 157 } else 158 { 159 dolibarr_print_error($db); 160 } 161 } 162 163 // bascule du statut d'un contact 164 if ($_GET["action"] == 'swapstatut' && $user->rights->facture->creer) 165 { 166 $facture = new Facture($db); 167 if ($facture->fetch($_GET["facid"])) 168 { 169 $contact = $facture->detail_contact($_GET["ligne"]); 170 $id_type_contact = $contact->fk_c_type_contact; 171 $statut = ($contact->statut == 4) ? 5 : 4; 172 173 $result = $facture->update_contact($_GET["ligne"], $statut, $id_type_contact); 174 if ($result >= 0) 175 { 176 $db->commit(); 177 } else 178 { 179 dolibarr_print_error($db, "result=$result"); 180 $db->rollback(); 181 } 182 } else 183 { 184 dolibarr_print_error($db); 185 } 186 } 187 188 // Efface un contact 189 if ($_GET["action"] == 'deleteline' && $user->rights->facture->creer) 190 { 191 $facture = new Facture($db); 192 $facture->fetch($_GET["facid"]); 193 $result = $facture->delete_contact($_GET["lineid"]); 194 195 if ($result >= 0) 196 { 197 Header("Location: contact.php?facid=".$facture->id); 198 exit; 199 } 200 else { 201 dolibarr_print_error($db); 202 } 203 } 204 205 206 llxHeader('', $langs->trans("Bill"), "Facture"); 207 208 $html = new Form($db); 209 210 /* *************************************************************************** */ 211 /* */ 212 /* Mode vue et edition */ 213 /* */ 214 /* *************************************************************************** */ 215 if ( isset($mesg)) 216 print $mesg; 217 $id = $_GET["facid"]; 218 if ($id > 0) 219 { 220 $facture = New Facture($db); 221 if ( $facture->fetch($_GET['facid'], $user->societe_id) > 0) 222 { 223 $soc = new Societe($db, $facture->socidp); 224 $soc->fetch($facture->socidp); 225 226 $head = facture_prepare_head($facture); 227 228 dolibarr_fiche_head($head, 1, $langs->trans('Bill').' : '.$facture->ref); 229 230 /* 231 * Facture synthese pour rappel 232 */ 233 print '<table class="border" width="100%">'; 234 235 // Reference du facture 236 print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">'; 237 print $facture->ref; 238 print "</td></tr>"; 239 240 // Customer 241 if ( is_null($facture->client) ) 242 $facture->fetch_client(); 243 244 print "<tr><td>".$langs->trans("Customer")."</td>"; 245 print '<td colspan="3">'; 246 print '<b><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$facture->client->id.'">'.$facture->client->nom.'</a></b></td></tr>'; 247 print "</table>"; 248 249 print '</div>'; 250 251 /* 252 * Lignes de contacts 253 */ 254 echo '<br><table class="noborder" width="100%">'; 255 256 /* 257 * Ajouter une ligne de contact 258 * Non affiché en mode modification de ligne 259 */ 260 if ($_GET["action"] != 'editline' && $user->rights->facture->creer) 261 { 262 print '<tr class="liste_titre">'; 263 print '<td>'.$langs->trans("Source").'</td>'; 264 print '<td>'.$langs->trans("Company").'</td>'; 265 print '<td>'.$langs->trans("Contacts").'</td>'; 266 print '<td>'.$langs->trans("ContactType").'</td>'; 267 print '<td colspan="3"> </td>'; 268 print "</tr>\n"; 269 270 $var = false; 271 272 print '<form action="contact.php?facid='.$id.'" method="post">'; 273 print '<input type="hidden" name="action" value="addcontact">'; 274 print '<input type="hidden" name="source" value="internal">'; 275 print '<input type="hidden" name="id" value="'.$id.'">'; 276 277 // Ligne ajout pour contact interne 278 print "<tr $bc[$var]>"; 279 280 print '<td>'; 281 print $langs->trans("Internal"); 282 print '</td>'; 283 284 print '<td colspan="1">'; 285 print $conf->global->MAIN_INFO_SOCIETE_NOM; 286 print '</td>'; 287 288 print '<td colspan="1">'; 289 $html->select_users($user->id,'contactid'); 290 print '</td>'; 291 print '<td>'; 292 select_type_contact($facture, '', 'type','internal'); 293 print '</td>'; 294 print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>'; 295 print '</tr>'; 296 297 print '</form>'; 298 299 print '<form action="contact.php?facid='.$id.'" method="post">'; 300 print '<input type="hidden" name="action" value="addcontact">'; 301 print '<input type="hidden" name="source" value="external">'; 302 print '<input type="hidden" name="id" value="'.$id.'">'; 303 304 // Ligne ajout pour contact externe 305 $var=!$var; 306 print "<tr $bc[$var]>"; 307 308 print '<td>'; 309 print $langs->trans("External"); 310 print '</td>'; 311 312 print '<td colspan="1">'; 313 $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$facture->client->id; 314 $selectedCompany = select_societes_for_newconcat($facture, $selectedCompany, $htmlname = 'newcompany'); 315 print '</td>'; 316 317 print '<td colspan="1">'; 318 $html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid'); 319 print '</td>'; 320 print '<td>'; 321 select_type_contact($facture, '', 'type','external'); 322 print '</td>'; 323 print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>'; 324 print '</tr>'; 325 326 print "</form>"; 327 328 print '<tr><td colspan="6"> </td></tr>'; 329 } 330 331 // Liste des contacts liés 332 print '<tr class="liste_titre">'; 333 print '<td>'.$langs->trans("Source").'</td>'; 334 print '<td>'.$langs->trans("Company").'</td>'; 335 print '<td>'.$langs->trans("Contacts").'</td>'; 336 print '<td>'.$langs->trans("ContactType").'</td>'; 337 print '<td align="center">'.$langs->trans("Status").'</td>'; 338 print '<td colspan="2"> </td>'; 339 print "</tr>\n"; 340 341 $societe = new Societe($db); 342 $var = true; 343 344 foreach(array('internal','external') as $source) 345 { 346 $tab = $facture->liste_contact(-1,$source); 347 $num=sizeof($tab); 348 349 $i = 0; 350 while ($i < $num) 351 { 352 $var = !$var; 353 354 print '<tr '.$bc[$var].' valign="top">'; 355 356 // Source 357 print '<td align="left">'; 358 if ($tab[$i]['source']=='internal') print $langs->trans("Internal"); 359 if ($tab[$i]['source']=='external') print $langs->trans("External"); 360 print '</td>'; 361 362 // Societe 363 print '<td align="left">'; 364 if ($tab[$i]['socid'] > 0) 365 { 366 print '<a href="'.DOL_URL_ROOT.'/soc.php?socid='.$tab[$i]['socid'].'">'; 367 print img_object($langs->trans("ShowCompany"),"company").' '.$societe->get_nom($tab[$i]['socid']); 368 print '</a>'; 369 } 370 if ($tab[$i]['socid'] < 0) 371 { 372 print $conf->global->MAIN_INFO_SOCIETE_NOM; 373 } 374 if (! $tab[$i]['socid']) 375 { 376 print ' '; 377 } 378 print '</td>'; 379 380 // Contact 381 print '<td>'; 382 if ($tab[$i]['source']=='internal') 383 { 384 print '<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$tab[$i]['id'].'">'; 385 print img_object($langs->trans("ShowUser"),"user").' '.$tab[$i]['nom'].'</a>'; 386 } 387 if ($tab[$i]['source']=='external') 388 { 389 print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$tab[$i]['id'].'">'; 390 print img_object($langs->trans("ShowContact"),"contact").' '.$tab[$i]['nom'].'</a>'; 391 } 392 print '</td>'; 393 394 // Type de contact 395 print '<td>'.$tab[$i]['libelle'].'</td>'; 396 397 // Statut 398 print '<td align="center">'; 399 // Activation desativation du contact 400 if ($facture->statut >= 0) 401 print '<a href="contact.php?facid='.$facture->id.'&action=swapstatut&ligne='.$tab[$i]['rowid'].'">'; 402 print img_statut($tab[$i]['status']); 403 404 if ($facture->statut >= 0) 405 print '</a>'; 406 print '</td>'; 407 408 // Icon update et delete (statut contrat 0=brouillon,1=validé,2=fermé) 409 print '<td align="center" nowrap>'; 410 if ($facture->statut == 0 && $user->rights->facture->creer) 411 { 412 print ' '; 413 print '<a href="contact.php?facid='.$facture->id.'&action=deleteline&lineid='.$tab[$i]['rowid'].'">'; 414 print img_delete(); 415 print '</a>'; 416 } 417 print '</td>'; 418 419 print "</tr>\n"; 420 421 $i ++; 422 } 423 $db->free($result); 424 } 425 print "</table>"; 426 } 427 else 428 { 429 // Contrat non trouvé 430 print "Contrat inexistant ou accés refusé"; 431 } 432 } 433 434 $db->close(); 435 436 llxFooter('$Date: 2005/12/03 17:18:35 $'); 437 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |