#!/usr/bin/perl
#
# gabriel 2010/06/03
#
# apt-get install libwww-mechanize-perl libwww-perl

use strict;

use WWW::Mechanize;
use Data::Dumper;

my $file_upload = $ARGV[0];
die "Usage /usr/lib/biblehal/biblehal-push file.bib" if not -f $file_upload;


my $config_file = '/etc/refbase.conf';
my $connect_name = qx{ grep '\$adminLoginEmail =' $config_file | cut -f 2 -d "'" };
my $connect_pass = qx{ grep '\$adminLoginPass ='  $config_file | cut -f 2 -d "'" };
chomp($connect_name, $connect_pass);


# Création du bot
my $url = 'http://localhost/'; # refbase server
my $bot = WWW::Mechanize->new;

# Hop, c'est parti, premiere page
$bot->get($url);


#--1
#
#form numero 2
#					<form action="user_login.php" method="POST" name="login">
#						<fieldset>
#							<legend>Login:</legend>
#							<input type="hidden" name="referer" value="index.php">
#							<div id="loginUser">
#								<div id="loginUserLabel">
#
#									<label for="loginEmail">Email:</label>
#								</div>
#								<div id="loginUserInput">
#									<input type="text" id="loginEmail" name="loginEmail">
#								</div>
#							</div>
#							<div id="loginPwd">
#								<div id="loginPwdLabel">
#
#									<label for="loginPassword">Password:</label>
#								</div>
#								<div id="loginPwdInput">
#									<input type="password" id="loginPassword" name="loginPassword">
#								</div>
#							</div>
#							<div id="loginSubmit">
#								<input type="submit" value="Login">
#
#							</div>
#						</fieldset>
#					</form>

# Hop, seconde page, on choisis le second formulaire
$bot->form_number(2);

$bot->field('loginEmail', "$connect_name");
$bot->field('loginPassword', "$connect_pass");

$bot->submit;

$bot->get('import.php');


$bot->form_number(2);

$bot->field('uploadFile', "$file_upload");

$bot->submit;

$bot->form_number(2);
$bot->submit;

#print $bot->content;


__END__ 

--2

<a href="import.php" title="importer enregistrements dans la base de donn&eacute;es">Importer</a>

suivre le lien


--3

form numero 2 sur 3

<form enctype="multipart/form-data" action="import_modify.php" method="POST">
<input type="hidden" name="formType" value="import">
<input type="hidden" name="submit" value="Import">
<input type="hidden" name="showLinks" value="1">
<input type="hidden" name="showSource" value="1">
<table align="center" border="0" cellpadding="0" cellspacing="10" width="95%" summary="This table holds the main import form">
<tr>
	<td width="94" valign="top"><b>Records:</b></td>

	<td width="10">&nbsp;</td>
	<td colspan="3"><textarea name="sourceText" rows="6" cols="63" title="paste your records here"></textarea></td>
</tr>
<tr>
	<td rowspan="2">&nbsp;</td>
	<td rowspan="2">&nbsp;</td>
	<td width="215" valign="top" rowspan="2"><input type="file" name="uploadFile" size="17" title="??import records from a file"></td>
	<td width="98" valign="top" rowspan="2">Import records:</td>
	<td valign="top"><input type="radio" name="importRecordsRadio" value="all" checked title="choose 'All' if you want to import all records at once">&nbsp;All</td>

</tr>
<tr>
	<td valign="top"><input type="radio" name="importRecordsRadio" value="only" title="choose 'Only' if you just want to import particular records">&nbsp;Only:&nbsp;&nbsp;<input type="text" name="importRecords" value="1" size="5" title="enter record number(s): e.g. '1-5 7' imports the first five and the seventh"></td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td colspan="3">
		<input type="submit" name="submit" value="Import" title="press this button to import the given source data">
	</td>

</tr>
</table>
</form>

--4

