/**
 Retourne un tableau de factures correspondant aux champs du tableau en argument.
 @param $args
 */
 function Factures_chercher($args)
 {
     $tab_result = array();
     $sql = " SELECT * \n\t\t\t\tFROM " . $GLOBALS['prefix'] . "factures\n\t\t\t\tWHERE 1";
     if (!isset($args['id_facture']) && !isset($args['id_pere']) && !isset($args['type_pere']) && !isset($args['etat']) && !isset($args['date_facture_debut']) && !isset($args['date_facture_fin']) && !isset($args['date_facture']) && !isset($args['num_facture']) && !isset($args['order_by']) && !isset($args['tab_ids_factures'])) {
         return $tab_result;
     }
     $condition = "";
     if (isset($args['id_facture']) && $args['id_facture'] != "*") {
         $condition .= " AND id_facture = '" . $args['id_facture'] . "' ";
     }
     if (isset($args['id_pere']) && $args['id_pere'] != "*") {
         $condition .= " AND id_pere = " . $args['id_pere'] . " ";
     }
     if (isset($args['type_pere']) && $args['type_pere'] != "*") {
         $condition .= " AND type_pere LIKE '" . $args['type_pere'] . "' ";
     }
     if (isset($args['etat']) && $args['etat'] != "*") {
         $condition .= " AND etat = '" . $args['etat'] . "' ";
     }
     if (isset($args['date_facture']) && $args['date_facture'] != "*") {
         $condition .= " AND date_facture = '" . Lib_frToEn($args['date_facture']) . "' ";
     }
     if (isset($args['date_facture_debut']) && $args['date_facture_debut'] != "*") {
         $condition .= " AND date_facture >= '" . Lib_frToEn($args['date_facture_debut']) . "' ";
     }
     if (isset($args['date_facture_fin']) && $args['date_facture_fin'] != "*") {
         $condition .= " AND date_facture <= '" . Lib_frToEn($args['date_facture_fin']) . "' ";
     }
     if (isset($args['num_facture']) && $args['num_facture'] != "*") {
         $condition .= " AND num_facture LIKE '" . $args['num_facture'] . "' ";
     }
     if (isset($args['tab_ids_factures']) && $args['tab_ids_factures'] != "*") {
         $ids = implode(",", $args['tab_ids_factures']);
         $condition .= " AND id_facture IN (0" . $ids . ") ";
     }
     $sql .= $condition;
     if (isset($args['order_by']) && !isset($args['asc_desc'])) {
         $sql .= " ORDER BY " . $args['order_by'] . " ASC";
     }
     if (isset($args['order_by']) && isset($args['asc_desc'])) {
         $sql .= " ORDER BY " . $args['order_by'] . " " . $args['asc_desc'];
     }
     if (isset($args['limit']) && !isset($args['start'])) {
         $sql .= " LIMIT " . $args['limit'];
     }
     if (isset($args['limit']) && isset($args['start'])) {
         $sql .= " LIMIT " . $args['start'] . "," . $args['limit'];
     }
     /*=============*/
     Lib_myLog("SQL: {$sql}");
     $result = mysql_query($sql);
     if ($result) {
         while ($row = mysql_fetch_array($result)) {
             $id = $row['id_facture'];
             $tab_result[$id]["id_facture"] = $id;
             $tab_result[$id]["id_pere"] = $row['id_pere'];
             $tab_result[$id]["type_pere"] = $row['type_pere'];
             $tab_result[$id]["montant_ttc"] = $row['montant_ttc'];
             $tab_result[$id]["etat"] = $row['etat'];
             $tab_result[$id]["date_facture"] = Lib_enToFr($row['date_facture']);
             $tab_result[$id]["num_facture"] = $row['num_facture'];
             $tab_result[$id]["message"] = Lib_prepareTexteAffichage($row['message']);
             $tab_result[$id]["produit"] = Lib_prepareTexteAffichage($row['produit']);
             $tab_result[$id]["id_mode_reglement"] = $row['id_mode_reglement'];
             $tab_result[$id]["id_delai_reglement"] = $row['id_delai_reglement'];
             $tab_result[$id]["code_client"] = $row['code_client'];
             $tab_result[$id]["nom_fact"] = Lib_prepareTexteAffichage($row['nom_fact']);
             $tab_result[$id]["ligne1_fact"] = Lib_prepareTexteAffichage($row['ligne1_fact']);
             $tab_result[$id]["ligne2_fact"] = Lib_prepareTexteAffichage($row['ligne2_fact']);
             $tab_result[$id]["ligne3_fact"] = Lib_prepareTexteAffichage($row['ligne3_fact']);
             $tab_result[$id]["cp_fact"] = $row['cp_fact'];
             $tab_result[$id]["ville_fact"] = Lib_prepareTexteAffichage($row['ville_fact']);
             $tab_result[$id]["tel1_fact"] = $row['tel1_fact'];
             $tab_result[$id]["tel2_fact"] = $row['tel2_fact'];
             $tab_result[$id]["fax_fact"] = $row['fax_fact'];
             $tab_result[$id]["email_fact"] = $row['email_fact'];
             $tab_result[$id]["date_add"] = $row['date_add'];
             $tab_result[$id]["date_upd"] = $row['date_upd'];
             $tab_result[$id]["info_facture"] = $row['info_facture'];
         }
     }
     if (count($tab_result) == 1 && ($args['id_facture'] != '' && $args['id_facture'] != '*')) {
         $tab_result = array_pop($tab_result);
     }
     return $tab_result;
 }
 /**
 Retourne un tableau de selections correspondant aux champs du tableau en argument.
 @param $args
 */
 function Selections_chercher($args)
 {
     $tab_result = array();
     $sql = " SELECT * \n\t\t\t\tFROM " . $GLOBALS['prefix'] . "facture_selections\n\t\t\t\tWHERE 1";
     if (!isset($args['id_selection']) && !isset($args['id_facture']) && !isset($args['type_selection']) && !isset($args['position']) && !isset($args['order_by']) && !isset($args['tab_ids_selections'])) {
         return $tab_result;
     }
     $condition = "";
     if (isset($args['id_selection']) && $args['id_selection'] != "*") {
         $condition .= " AND id_selection = " . $args['id_selection'] . " ";
     }
     if (isset($args['id_facture']) && $args['id_facture'] != "*") {
         $condition .= " AND id_facture = " . $args['id_facture'] . " ";
     }
     if (isset($args['position']) && $args['position'] != "*") {
         $condition .= " AND position = " . $args['position'] . " ";
     }
     if (isset($args['type_selection']) && $args['type_selection'] != "*") {
         $condition .= " AND type_selection LIKE '" . $args['type_selection'] . "' ";
     }
     if (isset($args['tab_ids_selections']) && $args['tab_ids_selections'] != "*") {
         $ids = implode(",", $args['tab_ids_selections']);
         $condition .= " AND id_selection IN (0" . $ids . ") ";
     }
     $sql .= $condition;
     if (isset($args['order_by']) && !isset($args['asc_desc'])) {
         $sql .= " ORDER BY " . $args['order_by'] . " ASC";
     }
     if (isset($args['order_by']) && isset($args['asc_desc'])) {
         $sql .= " ORDER BY " . $args['order_by'] . " " . $args['asc_desc'];
     }
     if (isset($args['limit']) && !isset($args['start'])) {
         $sql .= " LIMIT " . $args['limit'];
     }
     if (isset($args['limit']) && isset($args['start'])) {
         $sql .= " LIMIT " . $args['start'] . "," . $args['limit'];
     }
     /*=============*/
     Lib_myLog("SQL: {$sql}");
     $result = mysql_query($sql);
     if ($result) {
         while ($row = mysql_fetch_array($result)) {
             $id = $row['id_selection'];
             $tab_result[$id]["id_selection"] = $id;
             $tab_result[$id]["position"] = $row['position'];
             $tab_result[$id]["id_facture"] = $row['id_facture'];
             $tab_result[$id]["type_selection"] = $row['type_selection'];
             $tab_result[$id]["designation"] = Lib_prepareTexteAffichage($row['designation']);
             $tab_result[$id]["description"] = Lib_prepareTexteAffichage($row['description']);
             $tab_result[$id]["pu_ht"] = $row['pu_ht'];
             $tab_result[$id]["remise"] = $row['remise'];
             $tab_result[$id]["quantite"] = $row['quantite'];
             $tab_result[$id]["tva"] = $row['tva'];
             $tab_result[$id]["date_add"] = $row['date_add'];
             $tab_result[$id]["date_upd"] = $row['date_upd'];
             $tab_result[$id]["info_selection"] = $row['info_selection'];
         }
     }
     if (count($tab_result) == 1 && ($args['id_selection'] != '' && $args['id_selection'] != '*')) {
         $tab_result = array_pop($tab_result);
     }
     return $tab_result;
 }