Subversion Repositories eFlore/Applications.cel

Compare Revisions

Problem with comparison.

Ignore whitespace Rev HEAD → Rev 1774

/trunk/jrest/tests/cmd-test.php
New file
0,0 → 1,69
<?php
 
define('DEFAULT_DOMAIN', 'http://cel');
define('DEFAULT_USER', 22506);
 
$options = getopt("hiou:d:e:p:FU:P:",array("help", "images", "obs", "user:", "domain:", "email:", "pass:", "flush", "upload:", "phpsessid"));
if(isset($options['h']) || isset($options['help'])) die(__help());
 
 
define('USER', isset($options['u']) ? $options['u'] : (isset($options['user']) ? $options['user'] : DEFAULT_USER));
define('DOMAIN', isset($options['d']) ? $options['d'] : (isset($options['domain']) ? $options['domain'] : DEFAULT_DOMAIN));
define('EMAIL', isset($options['e']) ? $options['e'] : (isset($options['email']) ? $options['email'] : NULL));
define('PASS', isset($options['p']) ? $options['p'] : (isset($options['pass']) ? $options['pass'] : NULL));
define('COOKIE', isset($options['P']) ? $options['P'] : (isset($options['phpsessid']) ? $options['phpsessid'] : NULL));
 
// API::auth() define()'s COOKIE
require_once('api.php');
 
if(isset($options['o']) || isset($options['obs']) || isset($options['F']) || isset($options['flush'])) {
cel_delete_all_obs();
}
 
if(isset($options['i']) || isset($options['images']) || isset($options['F']) || isset($options['flush'])) {
cel_delete_all_images();
}
 
$upload = isset($options['U']) ? $options['U'] : (isset($options['upload']) ? $options['upload'] : NULL);
if($upload) cel_upload_image($upload);
 
if(! COOKIE) { if(!auth()) die('no auth'); }
 
 
// $csv = genCSV(array('ordre' => 1, 'Date' => '23/06/1991', 'rien' => 'rien'));
var_dump(getCSV_line(export(), 1));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
function __help() {
$m = sprintf(
<<<EOF
%1\$s -i|--images -o|--obs -F|--flush
Supprime les images ou les observations, ou les deux, de l'utilisateur donné sur le CEL donné.
 
Options:
%1\$s [-u|--user = %3\$d] [-d|--domain = %2\$s] [-e|--email] [-p|--pass mot de passe] [-P|--phpsessid PHPSESSID]
La priorité est donnée à -P sur le couple (-e , -p) pour l'authentification, eg:
$ sqlite3 .mozilla/firefox/*.default/cookies.sqlite<<<"SELECT * FROM moz_cookies WHERE baseDomain = 'cel' AND name = 'PHPSESSID';"
 
%1\$s -u|--upload <file>
Upload le fichier "file".
EOF
, // */
basename(__FILE__),
DEFAULT_DOMAIN,
DEFAULT_USER);
die($m);
}
/trunk/jrest/tests/data/image-test.jpg
Cannot display: file marked as a binary type.
svn:mime-type = image/jpeg
/trunk/jrest/tests/data/image-test.jpg
New file
Property changes:
Added: svn:mime-type
+image/jpeg
\ No newline at end of property
/trunk/jrest/tests/data/images.sh
New file
0,0 → 1,8
# upload
curl -s -F file=@test/image-test.jpg -F ce_utilisateur=22506 http://cel/jrest/InventoryImage|grep OK
 
# list
http://cel/jrest/InventoryImageList/22506/?limite=50&numero_page=0|json_pp|egrep 'id_image|nom_original'|awk -F'"' '{print $4}'
 
# IO
POST http://cel/jrest/ExportXLS/22506<<<"format=csv&range=342212"|curl -F "upload=@-" -F utilisateur=22506 "http://cel/jrest/ImportXLS"
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
Added: svn:executable
+*
\ No newline at end of property
/trunk/jrest/tests/data/image-test2.jpg
Cannot display: file marked as a binary type.
svn:mime-type = image/jpeg
/trunk/jrest/tests/data/image-test2.jpg
New file
Property changes:
Added: svn:mime-type
+image/jpeg
\ No newline at end of property
/trunk/jrest/tests/phptests/accents.result.php
New file
0,0 → 1,29
<?php return array (
'nom_sel' => '',
'nom_sel_nn' => '',
'nom_ret' => '',
'nom_ret_nn' => '',
'nt' => '',
'famille' => '',
'nom_referentiel' => '',
'zone_geo' => '',
'ce_zone_geo' => '',
'date_observation' => '',
'lieudit' => 'œufs',
'station' => 'Ératostène',
'milieu' => 'Byørg',
'commentaire' => '',
'latitude' => '',
'longitude' => '',
'altitude' => '',
'geodatum' => '',
'ordre' => '1',
'mots_cles_texte' => '',
'transmission' => '',
'date_transmission' => '',
'abondance' => '',
'certitude' => '',
'phenologie' => '',
'images' => '',
'nom_commun' => '',
);
/trunk/jrest/tests/phptests/accents.test.php
New file
0,0 → 1,3
<?php
// test date format texte, pré 1900
return array('Lieu-dit' => 'œufs', 'Station' => 'Ératostène', 'Milieu' => 'Byørg');
/trunk/jrest/tests/phptests/determ-espece.result.php
New file
0,0 → 1,29
<?php return array (
'nom_sel' => 'heliotropium europaeum Xxumm',
'nom_sel_nn' => '31468',
'nom_ret' => 'Heliotropium europaeum L.',
'nom_ret_nn' => '31468',
'nt' => '1382',
'famille' => 'Boraginaceae',
'nom_referentiel' => '',
'zone_geo' => '',
'ce_zone_geo' => '',
'date_observation' => '',
'lieudit' => '',
'station' => '',
'milieu' => '',
'commentaire' => '',
'latitude' => '',
'longitude' => '',
'altitude' => '',
'geodatum' => '',
'ordre' => '1',
'mots_cles_texte' => '',
'transmission' => '',
'date_transmission' => '',
'abondance' => '',
'certitude' => '',
'phenologie' => '',
'images' => '',
'nom_commun' => '',
);
/trunk/jrest/tests/phptests/determ-espece.test.php
New file
0,0 → 1,3
<?php
// test détermination espèce, simple avec erreur, sans référentiel
return array('Espèce' => 'heliotropium europaeum Xxumm');
/trunk/jrest/tests/phptests/localisation-detect.result.php
New file
0,0 → 1,29
<?php return array (
'nom_sel' => '',
'nom_sel_nn' => '',
'nom_ret' => '',
'nom_ret_nn' => '',
'nt' => '',
'famille' => '',
'nom_referentiel' => '',
'zone_geo' => 'Marseille',
'ce_zone_geo' => '13',
'date_observation' => '',
'lieudit' => '',
'station' => '',
'milieu' => '',
'commentaire' => '',
'latitude' => '',
'longitude' => '',
'altitude' => '',
'geodatum' => '',
'ordre' => '1',
'mots_cles_texte' => '',
'transmission' => '',
'date_transmission' => '',
'abondance' => '',
'certitude' => '',
'phenologie' => '',
'images' => '',
'nom_commun' => '',
);
/trunk/jrest/tests/phptests/date-post-1900.result.php
New file
0,0 → 1,29
<?php return array (
'nom_sel' => '',
'nom_sel_nn' => '',
'nom_ret' => '',
'nom_ret_nn' => '',
'nt' => '',
'famille' => '',
'nom_referentiel' => '',
'zone_geo' => '',
'ce_zone_geo' => '',
'date_observation' => '1991/01/23',
'lieudit' => '',
'station' => '',
'milieu' => '',
'commentaire' => '',
'latitude' => '',
'longitude' => '',
'altitude' => '',
'geodatum' => '',
'ordre' => '1',
'mots_cles_texte' => '',
'transmission' => '',
'date_transmission' => '',
'abondance' => '',
'certitude' => '',
'phenologie' => '',
'images' => '',
'nom_commun' => '',
);
/trunk/jrest/tests/phptests/localisation-detect.test.php
New file
0,0 → 1,3
<?php
// test date format texte, pré 1900
return array('Commune' => 'Marseille');
/trunk/jrest/tests/phptests/date-post-1900.test.php
New file
0,0 → 1,3
<?php
// test date format texte, post 1900
return array('Date' => '23/01/1991');
/trunk/jrest/tests/phptests/date-post-2900.result.php
New file
0,0 → 1,29
<?php return array (
'nom_sel' => '',
'nom_sel_nn' => '',
'nom_ret' => '',
'nom_ret_nn' => '',
'nt' => '',
'famille' => '',
'nom_referentiel' => '',
'zone_geo' => '',
'ce_zone_geo' => '',
'date_observation' => '',
'lieudit' => '',
'station' => '',
'milieu' => '',
'commentaire' => '',
'latitude' => '',
'longitude' => '',
'altitude' => '',
'geodatum' => '',
'ordre' => '1',
'mots_cles_texte' => '',
'transmission' => '',
'date_transmission' => '',
'abondance' => '',
'certitude' => '',
'phenologie' => '',
'images' => '',
'nom_commun' => '',
);
/trunk/jrest/tests/phptests/date-pre-1900.result.php
New file
0,0 → 1,29
<?php return array (
'nom_sel' => '',
'nom_sel_nn' => '',
'nom_ret' => '',
'nom_ret_nn' => '',
'nt' => '',
'famille' => '',
'nom_referentiel' => '',
'zone_geo' => '',
'ce_zone_geo' => '',
'date_observation' => '1811/06/23',
'lieudit' => '',
'station' => '',
'milieu' => '',
'commentaire' => '',
'latitude' => '',
'longitude' => '',
'altitude' => '',
'geodatum' => '',
'ordre' => '1',
'mots_cles_texte' => '',
'transmission' => '',
'date_transmission' => '',
'abondance' => '',
'certitude' => '',
'phenologie' => '',
'images' => '',
'nom_commun' => ''
);
/trunk/jrest/tests/phptests/transmission.result.php
New file
0,0 → 1,29
<?php return array (
'nom_sel' => '',
'nom_sel_nn' => '',
'nom_ret' => '',
'nom_ret_nn' => '',
'nt' => '',
'famille' => '',
'nom_referentiel' => '',
'zone_geo' => '',
'ce_zone_geo' => '',
'date_observation' => '',
'lieudit' => '',
'station' => '',
'milieu' => '',
'commentaire' => '',
'latitude' => '',
'longitude' => '',
'altitude' => '',
'geodatum' => '',
'ordre' => '1',
'mots_cles_texte' => '',
'transmission' => 'oui',
'date_transmission' => '2013-07-26 18:20:08',
'abondance' => '',
'certitude' => '',
'phenologie' => '',
'images' => '',
'nom_commun' => '',
);
/trunk/jrest/tests/phptests/date-post-2900.test.php
New file
0,0 → 1,3
<?php
// test date format texte, futur
return array('Date' => '23/06/2900');
/trunk/jrest/tests/phptests/date-pre-1900.test.php
New file
0,0 → 1,3
<?php
// test date format texte, pré 1900
return array('Date' => '23/06/1811');
/trunk/jrest/tests/phptests/transmission.test.php
New file
0,0 → 1,3
<?php
// test transmission
return array('Transmis' => 'OuI');
/trunk/jrest/tests/phptests/01-sample.result.php
New file
0,0 → 1,29
<?php return array (
'nom_sel' => '',
'nom_sel_nn' => '',
'nom_ret' => '',
'nom_ret_nn' => '',
'nt' => '',
'famille' => '',
'nom_referentiel' => '',
'zone_geo' => '',
'ce_zone_geo' => '',
'date_observation' => '1991/06/23',
'lieudit' => '',
'station' => '',
'milieu' => '',
'commentaire' => '',
'latitude' => '',
'longitude' => '',
'altitude' => '',
'geodatum' => '',
'ordre' => '1',
'mots_cles_texte' => '',
'transmission' => '',
'date_transmission' => '',
'abondance' => '',
'certitude' => '',
'phenologie' => '',
'images' => '',
'nom_commun' => '',
);
/trunk/jrest/tests/phptests/01-sample.test.php
New file
0,0 → 1,7
<?php
//TODO: test settings:
// * colonnes (standard, avancé, ...)
// * field ignore
// * nombre de warnings
// sample test
return array('ordre' => 1, 'Date' => '23/06/1991', 'rien' => 'rien');
/trunk/jrest/tests/phptests/date-format-revert.result.php
New file
0,0 → 1,29
<?php return array (
'nom_sel' => '',
'nom_sel_nn' => '',
'nom_ret' => '',
'nom_ret_nn' => '',
'nt' => '',
'famille' => '',
'nom_referentiel' => '',
'zone_geo' => '',
'ce_zone_geo' => '',
'date_observation' => '1991/01/23',
'lieudit' => '',
'station' => '',
'milieu' => '',
'commentaire' => '',
'latitude' => '',
'longitude' => '',
'altitude' => '',
'geodatum' => '',
'ordre' => '1',
'mots_cles_texte' => '',
'transmission' => '',
'date_transmission' => '',
'abondance' => '',
'certitude' => '',
'phenologie' => '',
'images' => '',
'nom_commun' => '',
);
/trunk/jrest/tests/phptests/date-format-invert.result.php
New file
0,0 → 1,29
<?php return array (
'nom_sel' => '',
'nom_sel_nn' => '',
'nom_ret' => '',
'nom_ret_nn' => '',
'nt' => '',
'famille' => '',
'nom_referentiel' => '',
'zone_geo' => '',
'ce_zone_geo' => '',
'date_observation' => '1991/01/23',
'lieudit' => '',
'station' => '',
'milieu' => '',
'commentaire' => '',
'latitude' => '',
'longitude' => '',
'altitude' => '',
'geodatum' => '',
'ordre' => '1',
'mots_cles_texte' => '',
'transmission' => '',
'date_transmission' => '',
'abondance' => '',
'certitude' => '',
'phenologie' => '',
'images' => '',
'nom_commun' => '',
);
/trunk/jrest/tests/phptests/date-format-revert.test.php
New file
0,0 → 1,3
<?php
// test date format inverse YYYY/MM/DD
return array('Date' => '23/01/1991');
/trunk/jrest/tests/phptests/date-format-invert.test.php
New file
0,0 → 1,3
<?php
// test date format inverse YYYY/MM/DD
return array('Date' => '1991/01/23');
/trunk/jrest/tests/IO-fields-unittest.php
New file
0,0 → 1,78
<?php
 
$options = getopt("hu:d:e:p:P:",array("help", "user:", "domain:", "email:", "pass:", "phpsessid"));
if(isset($options['h']) || isset($options['help'])) {
die(basename(__FILE__) . ' [-u|--user = 22506] [-d|--domain = http://cel]');
}
 
define('USER', isset($options['u']) ? $options['u'] : (isset($options['user']) ? $options['user'] : 22506));
define('DOMAIN', isset($options['d']) ? $options['d'] : (isset($options['domain']) ? $options['domain'] : 'http://cel'));
define('EMAIL', isset($options['e']) ? $options['e'] : (isset($options['email']) ? $options['email'] : NULL));
define('PASS', isset($options['p']) ? $options['p'] : (isset($options['pass']) ? $options['pass'] : NULL));
define('COOKIE', isset($options['P']) ? $options['P'] : (isset($options['phpsessid']) ? $options['phpsessid'] : NULL));
 
require_once('api.php');
 
function setupTestEnv() {
cel_delete_all_obs();
cel_delete_all_images();
cel_upload_image('image-test.jpg');
cel_upload_image('image-test2.jpg');
}
 
if(! is_dir('phptests')) die('no phptests/');
if(! is_dir('run')) mkdir('run');
if(! is_dir('run')) die('no run/');
 
 
$all_tests = glob('phptests/*.test.php');
$tests = array_intersect($argv, $all_tests);
if(!$tests) $tests = $all_tests;
 
foreach($tests as $test) {
setupTestEnv(); @array_walk(glob('run/*'), function(&$i) { unlink($i);});
// cache car l'upload de fichier PHP-curl ne peut être
// simulé avec le contenu d'une variable (cf CURLOPT_POSTFIELDS et @fichier)
$runfile = 'run/' . basename($test);
if(!is_file($runfile)) {
$test_array = require($test);
$csv = genCSV($test_array);
file_put_contents($runfile, $csv);
}
 
echo "\tcurl -F \"upload=@$runfile\" -F utilisateur=" . USER . " \"" . DOMAIN . "/jrest/ImportXLS\"\n";
echo "$test: ";
$var_expected = include(str_replace('.test.', '.result.', $test));
 
$retour = import($runfile);
$count_warn = 0;
preg_match('/^ligne /', $retour, $count_warn);
$count_warn = count($count_warn);
 
$result = getCSV_line(export(), 1);
unset($result['date_creation'], $result['date_modification'], $result['id_observation']);
 
//var_dump(champsLongToShort2($test_array));die;
if($var_expected) {
$d1 = array_diff($var_expected, $result);
$d2 = array_diff($result, $var_expected);
if(!$d1 && !$d2) echo "OK\n";
else {
echo "FAIL\n";
if($d1) print_r($d1);
if($d2) print_r($d2);
//var_dump($var_expected, $result);
}
echo $retour;
if($count_warn) { echo "warnings: $count_warn\n"; }
}
else {
echo $retour;
if($count_warn) { echo "warnings: $count_warn\n"; }
 
echo '<?php return ' . var_export($result, true) . ';';
}
 
}
 
// sed -i -e '1{/<?php return/!s:^:<?php return :}' -e '${/^)$/s:$:;:}' phptests/*.result.php
/trunk/jrest/tests/api.php
New file
0,0 → 1,249
<?php
 
global $champs;
$champs = Array(
'nom_sel' => 'Espèce',
'nom_sel_nn' => 'Numéro nomenclatural',
'nom_ret' => 'Nom retenu',
'nom_ret_nn' => 'Numéro nomenclatural nom retenu',
'nt' => 'Numéro taxonomique',
'famille' => 'Famille',
'nom_referentiel' => 'Referentiel taxonomique',
'zone_geo' => 'Commune',
'ce_zone_geo' => 'Identifiant Commune',
'date_observation' => 'Date',
'lieudit' => 'Lieu-dit',
'station' => 'Station',
'milieu' => 'Milieu',
'commentaire' => 'Notes',
'latitude' => 'Latitude',
'longitude' => 'Longitude',
'altitude' => 'Altitude',
'geodatum' => 'Référentiel Géographique',
 
'ordre' => 'Ordre',
'id_observation' => 'Identifiant',
 
'mots_cles_texte' => 'Mots Clés',
 
'date_creation' => 'Date Création',
'date_modification' => 'Date Modification',
 
'transmission' => 'Transmis',
'date_transmission' => 'Date Transmission',
'abondance' => 'Abondance',
'certitude' => 'Certitude',
'phenologie' => 'Phénologie',
'images' => 'Image(s)',
'nom_commun' => 'Nom Commun',
);
 
 
function cel_get_obs() {
$URL = DOMAIN . '/jrest/InventoryObservationList/' . USER;
return json_decode(file_get_contents($URL . '/?limite=100000&numero_page=0'));
}
 
function cel_get_images() {
$URL = DOMAIN . '/jrest/InventoryImageList/' . USER;
return json_decode(file_get_contents($URL . '/?limite=100000&numero_page=0'));
}
 
function cel_delete_obs($obs) {
$URL = DOMAIN . '/jrest/InventoryObservationList/' . USER;
$ch = curl_init();
 
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $URL . '/' . implode(',', $obs));
curl_setopt($ch,CURLOPT_POSTFIELDS, array('action' => 'DELETE'));
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
//execute post
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
 
function cel_delete_image($img) {
$URL = DOMAIN . '/jrest/InventoryImageList/' . USER;
$ch = curl_init();
 
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $URL . '/' . implode(',', $img));
curl_setopt($ch,CURLOPT_POSTFIELDS, array('action' => 'DELETE'));
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
//execute post
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
 
 
function cel_delete_all_obs() {
$obs = cel_get_obs();
$ordres = array_map(function($item) { return $item->ordre; }, $obs);
cel_delete_obs($ordres);
}
 
 
function cel_delete_all_images() {
$img = cel_get_images();
$ids = array_map(function($item) { return $item->id_image; }, $img);
cel_delete_image($ids);
}
 
function cel_upload_image($file) {
if(! file_exists($file)) return NULL;
$URL = DOMAIN . '/jrest/InventoryImage';
 
$ch = curl_init();
 
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $URL);
curl_setopt($ch,CURLOPT_POSTFIELDS, array(
'file' => '@' . $file,
'ce_utilisateur' => USER
));
 
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
//execute post
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
 
function cel_link_images($user, $id_image, $id_obs) {
$URL = DOMAIN . '/jrest/inventoryImageLink/';
$ch = curl_init();
 
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $URL);
curl_setopt($ch,CURLOPT_POSTFIELDS, array(
'id_image' => $id_obs,
'id_observation' => $id_obs,
'ce_utilisateur' => $user
));
 
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
//execute post
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
 
 
function auth() {
// TODO: CURLOPT_NETRC + Cel API support
if(!defined('EMAIL') || !defined('PASS') || ! EMAIL || ! PASS) return FALSE;
$URL = DOMAIN . '/jrest/User/' . EMAIL . '/' . PASS;
 
$ch = curl_init();
 
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $URL);
curl_setopt($ch,CURLOPT_HEADER, true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
 
$result = curl_exec($ch);
curl_close($ch);
$sess = array();
preg_match('/.*PHPSESSID=(\w+).*/', $result, $sess);
if(isset($sess[1])) {
define('COOKIE', $sess[1]);
return true;
}
return false;
}
 
function genCSV($d = Array()) {
$out = fopen("php://temp", 'r+');
// don't filter-out unknown field (for testing)
// $d = array_intersect_key($d, $GLOBALS['champs']);
$head = array();
foreach($d as $k => $v) {
if(isset($GLOBALS['champs'][$k])) $head[$GLOBALS['champs'][$k]] = $v;
else $head[$k] = $v;
}
fputcsv($out, array_keys($head) , ',', '"');
fputcsv($out, array_values($head) , ',', '"');
rewind($out);
$csv = stream_get_contents($out);
fclose($out);
return $csv;
}
 
function import($d) {
$URL = DOMAIN . '/jrest/ImportXLS';
if(!is_file($d)) return FALSE;
$ch = curl_init();
 
// curl does not support setting filename="X.csv";type=application/octet-stream'
// with plain POST variables
 
curl_setopt($ch,CURLOPT_URL, $URL);
curl_setopt($ch,CURLOPT_POSTFIELDS, array(
'upload' => '@' . $d . ';filename=test.csv',
'utilisateur' => USER
));
 
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
//execute post
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
 
function export($cols = "standard,avance") {
if(!defined('COOKIE')) return FALSE;
 
$URL = DOMAIN . '/jrest/CelWidgetExport/export?';
$URL .= http_build_query(array('colonnes' => $cols,
'id_utilisateur' => USER,
'format' => 'csv'));
$ch = curl_init();
 
curl_setopt($ch,CURLOPT_URL, $URL);
curl_setopt($ch,CURLOPT_COOKIE, 'PHPSESSID=' . COOKIE);
 
if(DEBUG) fwrite(STDERR, "curl -b PHPSESSID=" . COOKIE . ' "' . $URL ."\"\n");
 
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
//execute post
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
 
function getCSV_line($csv, $line) {
$line = max(0, intval($line - 1)); // -1 à cause du header
 
$out = fopen("php://temp", 'rw');
fwrite($out, $csv);
rewind($out);
 
$head = champsLongToShort(fgetcsv($out));
while ($line--) fgetcsv($out);
$l = fgetcsv($out);
fclose($out);
return array_combine($head, $l);
}
 
 
function champsLongToShort($a) {
$r = array();
$x = array_flip($GLOBALS['champs']);
foreach($a as $k => $v) {
if(isset($x[$v])) $r[$k] = $x[$v];
else $r[$k] = -1;
}
return $r;
}
 
function champsLongToShort2($a) {
$r = array();
$x = array_flip($GLOBALS['champs']);
foreach($a as $k => $v) {
if(isset($x[$k])) $r[$x[$k]] = $v;
else $r[$k] = $v;
}
return $r;
}
/trunk/jrest/tests/multi-tests.xls
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/trunk/jrest/tests/multi-tests.xls
New file
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/trunk/jrest/tests/IO-file-diff.sh
New file
0,0 → 1,30
#!/bin/bash
 
orig=/tmp/orig.csv
ret=${1:-/tmp/result.csv}
 
# curl -sF "upload=@test.xls" -F utilisateur=22506 "http://cel/jrest/ImportXLS"
# $ sqlite3 .mozilla/firefox/*.default/cookies.sqlite<<<"SELECT * FROM moz_cookies WHERE baseDomain = 'cel' AND name = 'PHPSESSID';"
# GET -H "Cookie: PHPSESSID=ID" "http://cel/jrest/CelWidgetExport/export/?colonnes=standard,avance,etendu,baseflor&id_utilisateur=22506&format=csv > $ret
[[ ! -f $ret || ! -f test.xls ]] && echo "err" && exit 1
 
[[ ! -f $orig ]] && xls2csv -s cp1252 test.xls 2>/dev/null > $orig
[[ ! -f $orig ]] && echo "err" && exit 1
 
 
IFS=$'\n' cols=( $(csvtool head 1 $orig|tr , "\n") )
 
# test header
#diff <(csvtool head 1 $orig|tr , "\n") <(csvtool head 1 $ret |tr , "\n"); exit;
 
w=$(csvtool width $ret); w=32
 
# wdiff <(xls2csv -s cp1252 test.xls|csvtool readable -) <(csvtool readable $ret)
for i in ${cols[@]}; do
[[ $i =~ ^(Date Transmission|Date Création|Date Modification|Nom Commun|Identifiant|Ordre)$ ]] && continue;
echo "== $i";
wdiff -w "$(tput bold;tput setaf 1)" -x "$(tput sgr0)" -y "$(tput bold;tput setaf 2)" -z "$(tput sgr0)" <(csvtool namedcol "$i" $orig) <(csvtool namedcol "$i" $ret)
done
 
 
#ddiff <(csvtool namedcol Notes,Date /tmp/orig.csv ) <(csvtool namedcol Notes,Date /tmp/result.csv)
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
Added: svn:executable
+*
\ No newline at end of property
/trunk/jrest/tests/.
New file
Property changes:
Added: svn:ignore
+run