40,19 → 40,21 |
'observateur' => 'Observateur', |
); |
|
define('URLPREFIX', 'service:cel:'); |
|
function cel_get_obs() { |
$URL = DOMAIN . '/jrest/InventoryObservationList/' . USER; |
return json_decode(file_get_contents($URL . '/?limite=100000&numero_page=0')); |
$URL = DOMAIN . '/' . URLPREFIX . 'InventoryObservationList/' . USER; |
// 5000 (memory_limit) |
return json_decode(file_get_contents($URL . '/?limite=5000&numero_page=0')); |
} |
|
function cel_get_images() { |
$URL = DOMAIN . '/jrest/InventoryImageList/' . USER; |
$URL = DOMAIN . '/' . URLPREFIX . 'InventoryImageList/' . USER; |
return json_decode(file_get_contents($URL . '/?limite=100000&numero_page=0')); |
} |
|
function cel_delete_obs($obs) { |
$URL = DOMAIN . '/jrest/InventoryObservationList/' . USER; |
$URL = DOMAIN . '/' . URLPREFIX . 'InventoryObservationList/' . USER; |
$ch = curl_init(); |
|
//set the url, number of POST vars, POST data |
59,6 → 61,8 |
curl_setopt($ch,CURLOPT_URL, $URL . '/' . implode(',', $obs)); |
curl_setopt($ch,CURLOPT_POSTFIELDS, array('action' => 'DELETE')); |
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE); |
|
if(DEBUG) @fwrite(STDERR, sprintf("curl -F action=DELETE '%s/%s'\n", $URL, implode(',', $obs))); |
//execute post |
$result = curl_exec($ch); |
curl_close($ch); |
66,7 → 70,7 |
} |
|
function cel_delete_image($img) { |
$URL = DOMAIN . '/jrest/InventoryImageList/' . USER; |
$URL = DOMAIN . '/' . URLPREFIX . 'InventoryImageList/' . USER; |
$ch = curl_init(); |
|
//set the url, number of POST vars, POST data |
81,10 → 85,14 |
|
|
function cel_delete_all_obs() { |
$obs = cel_get_obs(); |
while( ($obs = cel_get_obs()) ) { |
$ordres = array_map(function($item) { return $item->ordre; }, $obs); |
cel_delete_obs($ordres); |
// les chunks permettent d'éviter des REQUEST-URI too long (500 id * 4 digits + 500 (virgules)) < 4k |
while( $ordres_chunk = array_splice($ordres, 0, 500)) { |
cel_delete_obs($ordres_chunk); |
} |
} |
} |
|
|
function cel_delete_all_images() { |
95,7 → 103,7 |
|
function cel_upload_image($file) { |
if(! file_exists($file)) return NULL; |
$URL = DOMAIN . '/jrest/InventoryImage'; |
$URL = DOMAIN . '/' . URLPREFIX . 'InventoryImage'; |
|
$ch = curl_init(); |
|
116,7 → 124,7 |
} |
|
function cel_link_images($user, $id_image, $id_obs) { |
$URL = DOMAIN . '/jrest/inventoryImageLink/'; |
$URL = DOMAIN . '/' . URLPREFIX . 'inventoryImageLink/'; |
$ch = curl_init(); |
|
//set the url, number of POST vars, POST data |
139,7 → 147,7 |
// TODO: CURLOPT_NETRC + Cel API support |
if(!defined('EMAIL') || !defined('PASS') || ! EMAIL || ! PASS) return FALSE; |
if(defined('COOKIE') && COOKIE) return TRUE; |
$URL = DOMAIN . '/jrest/User/' . EMAIL . '/' . PASS; |
$URL = DOMAIN . '/' . URLPREFIX . 'User/' . EMAIL . '/' . PASS; |
|
$ch = curl_init(); |
|
184,7 → 192,7 |
} |
|
function import($d) { |
$URL = DOMAIN . '/jrest/ImportXLS'; |
$URL = DOMAIN . '/' . URLPREFIX . 'ImportXLS'; |
if(!is_file($d)) return FALSE; |
$ch = curl_init(); |
|
208,7 → 216,7 |
} |
|
function importXLS($d) { |
$URL = DOMAIN . '/jrest/ImportXLS'; |
$URL = DOMAIN . '/' . URLPREFIX . 'ImportXLS'; |
if(!is_file($d)) return FALSE; |
exec("csvtool -o /tmp/a.csv col 1- $d"); |
exec(__DIR__ . "/bin/csv2xls -v 0 -f -o /tmp/a /tmp/a.csv &>/dev/null"); |
242,7 → 250,7 |
function export($cols = "standard,avance") { |
if(!defined('COOKIE')) return FALSE; |
|
$URL = DOMAIN . '/jrest/CelWidgetExport/export?'; |
$URL = DOMAIN . '/' . URLPREFIX . 'CelWidgetExport/export?'; |
$URL .= http_build_query(array('colonnes' => $cols, |
'id_utilisateur' => USER, |
'format' => 'csv')); |
265,7 → 273,7 |
|
$file = "/tmp/b.xls"; |
|
$URL = DOMAIN . '/jrest/CelWidgetExport/export?'; |
$URL = DOMAIN . '/' . URLPREFIX . 'CelWidgetExport/export?'; |
$URL .= http_build_query(array('colonnes' => $cols, |
'id_utilisateur' => USER, |
'format' => 'xls')); |
321,6 → 329,7 |
|
|
function champsLongToShort($a) { |
if(! $a) return array(); |
$r = array(); |
$x = array_flip($GLOBALS['champs']); |
foreach($a as $k => $v) { |