Changeset 107673 in spip-zone
- Timestamp:
- Nov 20, 2017, 9:38:36 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
_plugins_/stocks/trunk/inc/stocks.php
r107636 r107673 2 2 3 3 // Sécurité 4 if (!defined( "_ECRIRE_INC_VERSION")) {4 if (!defined('_ECRIRE_INC_VERSION')) { 5 5 return; 6 6 } … … 12 12 * @param $id_objet 13 13 */ 14 function get_quantite($objet, $id_objet) {14 function get_quantite($objet, $id_objet) { 15 15 16 16 $table_stocks = table_objet_sql('stocks'); 17 17 18 19 20 21 22 "objet = ".sql_quote($objet),23 "id_objet = ".intval($id_objet)24 25 18 return sql_getfetsel( 19 'quantite', 20 $table_stocks, 21 array( 22 'objet = '.sql_quote($objet), 23 'id_objet = '.intval($id_objet) 24 ) 25 ); 26 26 } 27 27 … … 33 33 * @param $quantite 34 34 */ 35 function set_quantite($objet, $id_objet,$quantite) {35 function set_quantite($objet, $id_objet, $quantite) { 36 36 37 37 $table_stocks = table_objet_sql('stocks'); 38 39 38 $quantite = intval($quantite); 39 40 40 $insert = sql_insertq( 41 $table_stocks, 42 array( 43 "objet" => $objet, 44 "id_objet" => intval($id_objet), 45 "quantite" => $quantite 46 ) 47 ); 48 if(!$insert){ 41 $table_stocks, 42 array( 43 'objet' => $objet, 44 'id_objet' => intval($id_objet), 45 'quantite' => $quantite 46 ) 47 ); 48 49 if (!$insert) { 49 50 $update = sql_update( 50 51 52 "quantite"=> intval($quantite)53 54 55 "objet = ".sql_quote($objet),56 "id_objet = ".intval($id_objet)57 58 ); 51 $table_stocks, 52 array( 53 'quantite' => intval($quantite) 54 ), 55 array( 56 'objet = '.sql_quote($objet), 57 'id_objet = '.intval($id_objet) 58 ) 59 ); 59 60 } 60 61 61 62 if ($insert || $update) 63 return $quantite; 64 else 65 return false; 62 if ($insert || $update) { 63 return $quantite; 64 } else { 65 return false; 66 } 66 67 } 67 68 … … 73 74 * @param $quantite {int} peut être négatif dans ce cas c'est une décrémentation 74 75 */ 75 function incrementer_quantite($objet, $id_objet,$quantite) {76 function incrementer_quantite($objet, $id_objet, $quantite) { 76 77 77 78 $table_stocks = table_objet_sql('stocks'); 78 79 79 80 $quantite = intval($quantite); 80 81 81 if ($quantite == 0) 82 return 0; 82 if ($quantite == 0) { 83 return 0; 84 } 83 85 84 if ($quantite > 0) 85 $set = array("quantite" => "quantite + ".abs($quantite)); 86 else 87 $set = array("quantite" => "quantite - ".abs($quantite)); 86 if ($quantite > 0) { 87 $set = array('quantite' => 'quantite + '.abs($quantite)); 88 } else { 89 $set = array('quantite' => 'quantite - '.abs($quantite)); 90 } 88 91 89 90 91 $set,92 93 "objet = ".sql_quote($objet),94 "id_objet = ".intval($id_objet)95 96 92 $update = sql_update( 93 $table_stocks, 94 $set, 95 array( 96 'objet = '.sql_quote($objet), 97 'id_objet = '.intval($id_objet) 98 ) 99 ); 97 100 98 101 return $update; 99 102 }
Note: See TracChangeset
for help on using the changeset viewer.