NEW Can import users

This commit is contained in:
Laurent Destailleur 2017-04-17 04:22:53 +02:00
parent c8b0921c51
commit e97e202deb
10 changed files with 131 additions and 57 deletions

View File

@ -68,7 +68,7 @@ class modUser extends DolibarrModules
// Dependancies
$this->depends = array();
$this->requiredby = array();
$this->langfiles = array("main","users","companies","members");
$this->langfiles = array("main","users","companies","members",'salaries');
// Constants
$this->const = array();
@ -230,6 +230,43 @@ class modUser extends DolibarrModules
$this->export_sql_start[$r]='SELECT DISTINCT ';
$this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'user as u';
$this->export_sql_end[$r] .=' WHERE u.entity IN ('.getEntity('user',1).')';
// Imports
//--------
$r=0;
// Import list of users attributes
$r++;
$this->import_code[$r]=$this->rights_class.'_'.$r;
$this->import_label[$r]='ImportDataset_user_1';
$this->import_icon[$r]='user';
$this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
$this->import_tables_array[$r]=array('u'=>MAIN_DB_PREFIX.'user','extra'=>MAIN_DB_PREFIX.'user_extrafields'); // List of tables to insert into (insert done in same order)
$this->import_fields_array[$r]=array('u.lastname'=>"Name*",'u.firstname'=>"Firstname",'u.employee'=>"Employee*",'u.job'=>"Job",'u.gender'=>"Gender",'u.login'=>"Login*",'u.pass_crypted'=>"Password",'u.admin'=>"Administrator",'u.fk_soc'=>"Company*",'u.address'=>"Address",'u.zip'=>"Zip",'u.town'=>"Town",'u.fk_state'=>"StateId",'u.fk_country'=>"CountryCode",'u.office_phone'=>"Phone",'u.user_mobile'=>"Mobile",'u.office_fax'=>"Fax",'u.email'=>"Email",'u.note'=>"Note",'u.signature'=>'Signature','u.fk_user'=>'Supervisor','u.thm'=>'THM','u.tjm'=>'TJM','u.dateemployment'=>'DateEmployment','u.salary'=>'Salary','u.color'=>'Color','u.api_key'=>'ApiKey','u.datec'=>"DateCreation");
// Add extra fields
$sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'user' AND entity = ".$conf->entity;
$resql=$this->db->query($sql);
if ($resql) // This can fail when class is used on old database (during migration for example)
{
while ($obj=$this->db->fetch_object($resql))
{
$fieldname='extra.'.$obj->name;
$fieldlabel=ucfirst($obj->label);
$this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
}
}
// End add extra fields
$this->import_fieldshidden_array[$r]=array('u.fk_user_creat'=>'user->id','extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'user'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
$this->import_convertvalue_array[$r]=array(
'u.fk_state'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cstate.class.php','class'=>'Cstate','method'=>'fetch','dict'=>'DictionaryState'),
'u.fk_country'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'),
'u.salary'=>array('rule'=>'numeric')
);
//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
$this->import_regex_array[$r]=array('u.employee'=>'^[0|1]','u.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$');
$this->import_examplevalues_array[$r]=array('u.lastname'=>"Doe",'u.firstname'=>'John','u.login'=>'jdoe','u.employee'=>'0 or 1','u.status'=>"0 (closed) or 1 (active)",'u.fk_soc'=>'0 (internal user) or company name (external user)','u.datec'=>dol_print_date(dol_now(),'%Y-%m-%d'),'u.address'=>"61 jump street",'u.zip'=>"123456",'u.town'=>"Big town",'u.fk_country'=>'US, FR, DE...','u.office_phone'=>"0101010101",'u.office_fax'=>"0101010102",'u.email'=>"test@mycompany.com",'u.salary'=>"10000",'u.note'=>"This is an example of note for record",'u.datec'=>"2015-01-01 or 2015-01-01 12:30:00");
$this->import_updatekeys_array[$r]=array('u.lastname'=>'Lastname','u.firstname'=>'Firstname','u.login'=>'Login');
}

View File

@ -77,18 +77,27 @@ $(document).ready(function () {
<input type="hidden" name="dol_use_jmobile" id="dol_use_jmobile" value="<?php echo $dol_use_jmobile; ?>" />
<!-- Title with version -->
<div class="login_table_title center" title="<?php echo dol_escape_htmltag($title); ?>">
<?php
if ($disablenofollow) echo '<a class="login_table_title" href="https://www.dolibarr.org" target="_blank">';
echo dol_escape_htmltag($title);
if ($disablenofollow) echo '</a>';
?>
</div>
<div class="login_table">
<div id="login_line1">
<div id="login_left">
<img alt="" src="<?php echo $urllogo; ?>" id="img_logo" />
</div>
<div id="login_right">
<table class="left centpercent" title="<?php echo $langs->trans("EnterLoginDetail"); ?>">
@ -146,10 +155,10 @@ if (! empty($hookmanager->resArray['options'])) {
<?php } ?>
</table>
</div> <!-- end div left -->
</div> <!-- end div login-right -->
</div> <!-- end div login-line1 -->
</div>
<div id="login_line2" style="clear: both">
@ -209,19 +218,9 @@ if (isset($conf->file->main_authentication) && preg_match('/openid/',$conf->file
?>
</div>
</div> <!-- end login line 2 -->
</div>
<!-- Title with version -->
<div class="login_table_title center" title="<?php echo dol_escape_htmltag($title); ?>">
<?php
if ($disablenofollow) echo '<a class="login_table_title" href="https://www.dolibarr.org" target="_blank">';
echo dol_escape_htmltag($title);
if ($disablenofollow) echo '</a>';
?>
</div>
</div> <!-- end login table -->
</form>

View File

@ -52,18 +52,25 @@ $(document).ready(function () {
<input type="hidden" name="action" value="buildnewpassword">
<!-- Title with version -->
<div class="login_table_title center" title="<?php echo dol_escape_htmltag($title); ?>">
<?php
if ($disablenofollow) echo '<a class="login_table_title" href="https://www.dolibarr.org" target="_blank">';
echo dol_escape_htmltag($title);
if ($disablenofollow) echo '</a>';
?>
</div>
<div class="login_table">
<div id="login_line1">
<div id="login_left">
<img alt="Logo" title="" src="<?php echo $urllogo; ?>" id="img_logo" />
</div>
<div id="login_right">
<table summary="Login pass" class="centpercent">
@ -114,13 +121,11 @@ if (! empty($hookmanager->resArray['options'])) {
</table>
</div> <!-- end div left -->
</div> <!-- end div login right -->
</div> <!-- end div login_line1 -->
</div>
<div id="login_line2" style="clear: both">
<!-- Button "Regenerate and Send password" -->
@ -143,15 +148,6 @@ if (! empty($hookmanager->resArray['options'])) {
</div>
<!-- Title with version -->
<div class="login_table_title center" title="<?php echo dol_escape_htmltag($title); ?>">
<?php
if ($disablenofollow) echo '<a class="login_table_title" href="https://www.dolibarr.org" target="_blank">';
echo dol_escape_htmltag($title);
if ($disablenofollow) echo '</a>';
?>
</div>
</form>

View File

@ -340,7 +340,7 @@ if ($step == 1 || ! $datatoimport)
$head = import_prepare_head($param, 1);
dol_fiche_head($head, 'step1', $langs->trans("NewImport"));
dol_fiche_head($head, 'step1', $langs->trans("NewImport"), -1);
print $langs->trans("SelectImportDataSet").'<br>';
@ -403,8 +403,10 @@ if ($step == 2 && $datatoimport)
$head = import_prepare_head($param,2);
dol_fiche_head($head, 'step2', $langs->trans("NewImport"));
dol_fiche_head($head, 'step2', $langs->trans("NewImport"), -1);
print '<div class="underbanner clearboth"></div>';
print '<div class="fichecenter">';
print '<table width="100%" class="border">';
@ -426,6 +428,8 @@ if ($step == 2 && $datatoimport)
print '</table>';
print '</div><br>';
dol_fiche_end();
@ -478,7 +482,7 @@ if ($step == 3 && $datatoimport)
$head = import_prepare_head($param, 3);
dol_fiche_head($head, 'step3', $langs->trans("NewImport"));
dol_fiche_head($head, 'step3', $langs->trans("NewImport"), -1);
/*
* Confirm delete file
@ -489,6 +493,9 @@ if ($step == 3 && $datatoimport)
}
print '<div class="underbanner clearboth"></div>';
print '<div class="fichecenter">';
print '<table width="100%" class="border">';
// Module
@ -508,10 +515,14 @@ if ($step == 3 && $datatoimport)
print '</td></tr>';
print '</table>';
print '</div>';
print '<br>';
print '<b>'.$langs->trans("InformationOnSourceFile").'</b><hr>';
print '<b>'.$langs->trans("InformationOnSourceFile").'</b>';
print '<div class="underbanner clearboth"></div>';
print '<div class="fichecenter">';
print '<table width="100%" class="border">';
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnSourceFile").'</b></td></tr>';
@ -525,6 +536,7 @@ if ($step == 3 && $datatoimport)
print '</td></tr>';
print '</table>';
print '</div>';
dol_fiche_end();
@ -735,7 +747,10 @@ if ($step == 4 && $datatoimport)
$head = import_prepare_head($param,4);
dol_fiche_head($head, 'step4', $langs->trans("NewImport"));
dol_fiche_head($head, 'step4', $langs->trans("NewImport"), -1);
print '<div class="underbanner clearboth"></div>';
print '<div class="fichecenter">';
print '<table width="100%" class="border">';
@ -756,10 +771,13 @@ if ($step == 4 && $datatoimport)
print '</td></tr>';
print '</table>';
print '</div>';
print '<br>';
print '<b>'.$langs->trans("InformationOnSourceFile").'</b><hr>';
print '<b>'.$langs->trans("InformationOnSourceFile").'</b>';
print '<div class="underbanner clearboth"></div>';
print '<div class="fichecenter">';
print '<table width="100%" class="border">';
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnSourceFile").'</b></td></tr>';
@ -801,6 +819,7 @@ if ($step == 4 && $datatoimport)
print '</td></tr>';
print '</table>';
print '</div>';
dol_fiche_end();
@ -1204,8 +1223,10 @@ if ($step == 5 && $datatoimport)
print '<input type="hidden" name="step" value="5">'; // step 5
print '<input type="hidden" name="action" value="launchsimu">'; // step 5
dol_fiche_head($head, 'step5', $langs->trans("NewImport"));
dol_fiche_head($head, 'step5', $langs->trans("NewImport"), -1);
print '<div class="underbanner clearboth"></div>';
print '<div class="fichecenter">';
print '<table width="100%" class="border">';
@ -1226,10 +1247,13 @@ if ($step == 5 && $datatoimport)
print '</td></tr>';
print '</table>';
print '</div>';
print '<br>';
print '<b>'.$langs->trans("InformationOnSourceFile").'</b><hr>';
print '<b>'.$langs->trans("InformationOnSourceFile").'</b>';
print '<div class="underbanner clearboth"></div>';
print '<div class="fichecenter">';
print '<table width="100%" class="border">';
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnSourceFile").'</b></td></tr>';
@ -1276,7 +1300,6 @@ if ($step == 5 && $datatoimport)
{
print '<input type="number" class="maxwidth50" name="excludefirstlinebis" disabled="disabled" value="'.$excludefirstline.'">';
print '<input type="hidden" name="excludefirstline" value="'.$excludefirstline.'">';
print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'?step=5'.$param.'">'.$langs->trans("Modify").'</a>';
}
else
{
@ -1288,20 +1311,27 @@ if ($step == 5 && $datatoimport)
{
print '<input type="text" class="maxwidth50" name="endatlinenbbis" disabled="disabled" value="'.$endatlinenb.'">';
print '<input type="hidden" name="endatlinenb" value="'.$endatlinenb.'">';
print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'?step=5'.$param.'">'.$langs->trans("Modify").'</a>';
}
else
{
print '<input type="text" class="maxwidth50" name="endatlinenb" value="'.$endatlinenb.'">';
print $form->textwithpicto("", $langs->trans("KeepEmptyToGoToEndOfFile"));
}
if ($action == 'launchsimu') print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'?step=5'.$param.'">'.$langs->trans("Modify").'</a>';
print '</td></tr>';
print '<tr><td>';
print $langs->trans("KeysToUseForUpdates");
print '</td><td>';
if($action=='launchsimu') {
print $form->multiselectarray('updatekeysbis', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0, '', 1, '', 'disabled');
if (count($updatekeys))
{
print $form->multiselectarray('updatekeysbis', $objimport->array_import_updatekeys[0], $updatekeys, 0, 0, '', 1, '', 'disabled');
}
else
{
print '<span class="opacitymedium">'.$langs->trans("NoUpdateAttempt").'</span> &nbsp; -';
}
foreach($updatekeys as $val) {
print '<input type="hidden" name="updatekeys[]" value="'.$val.'">';
}
@ -1323,15 +1353,19 @@ if ($step == 5 && $datatoimport)
print '</td></tr>';
print '</table>';
print '</div>';
print '<br>';
print '<b>'.$langs->trans("InformationOnTargetTables").'</b><hr>';
print '<b>'.$langs->trans("InformationOnTargetTables").'</b>';
print '<div class="underbanner clearboth"></div>';
print '<div class="fichecenter">';
print '<table width="100%" class="border">';
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnTargetTables").'</b></td></tr>';
// Tables imported
print '<tr><td width="25%">';
print '<tr><td class="titlefield">';
print $langs->trans("TablesTarget");
print '</td><td>';
$listtables=array();
@ -1391,7 +1425,8 @@ if ($step == 5 && $datatoimport)
print '</td></tr>';
print '</table>';
print '</div>';
dol_fiche_end();

View File

@ -59,8 +59,9 @@ ALTER TABLE llx_product_price_by_qty ADD COLUMN fk_user_creat integer;
ALTER TABLE llx_product_price_by_qty ADD COLUMN fk_user_modif integer;
ALTER TABLE llx_product_price_by_qty DROP COLUMN date_price;
ALTER TABLE llx_product_price_by_qty ADD COLUMN tms timestamp;
ALTER TABLE llx_product_price_by_qty ADD COLUMN import_key integer;
ALTER TABLE llx_product_price_by_qty ADD COLUMN import_key varchar(14);
ALTER TABLE llx_user ADD COLUMN import_key varchar(14);
CREATE TABLE llx_product_attribute

View File

@ -31,5 +31,5 @@ create table llx_product_price_by_qty
fk_user_creat integer,
fk_user_modif integer,
tms timestamp,
import_key integer
import_key varchar(14)
)ENGINE=innodb;

View File

@ -83,5 +83,7 @@ create table llx_user
salary double(24,8), -- denormalized value coming from llx_user_employment
salaryextra double(24,8), -- denormalized value coming from llx_user_employment
dateemployment date, -- denormalized value coming from llx_user_employment
weeklyhours double(16,8) -- denormalized value coming from llx_user_employment
weeklyhours double(16,8), -- denormalized value coming from llx_user_employment
import_key varchar(14) -- import key
)ENGINE=innodb;

View File

@ -117,7 +117,9 @@ ImportFromToLine=Import line numbers (from - to)
SetThisValueTo2ToExcludeFirstLine=For example, set this value to 3 to exclude the 2 first lines
KeepEmptyToGoToEndOfFile=Keep this field empty to go up to the end of file
SelectPrimaryColumnsForUpdateAttempt=Select column(s) to use as primary key for update attempt
UpdateNotYetSupportedForThisImport=Update is not supported for this type of import (only insert)
UpdateNotYetSupportedForThisImport=Update is not supported for this type of import (only insert)
NoUpdateAttempt=No update attempt was performed, only insert
ImportDataset_user_1=Users (employees or not) and properties
## filters
SelectFilterFields=If you want to filter on some values, just input values here.
FilteredFields=Filtered fields

View File

@ -1526,6 +1526,7 @@ foreach($mainmenuusedarray as $val)
}
.login_vertical_align {
padding: 10px;
padding-bottom: 80px;
}
form#login {
padding-bottom: 30px;
@ -1535,7 +1536,7 @@ form#login {
.login_table_title {
max-width: 530px;
color: #aaa !important;
padding-top: 30px;
padding-bottom: 20px;
/* text-shadow: 1px 1px 1px #FFF; */
}
.login_table label {

View File

@ -1562,6 +1562,7 @@ foreach($mainmenuusedarray as $val)
}
.login_vertical_align {
padding: 10px;
padding-bottom: 80px;
}
form#login {
padding-bottom: 30px;
@ -1571,7 +1572,7 @@ form#login {
.login_table_title {
max-width: 530px;
color: #aaa !important;
padding-top: 30px;
padding-bottom: 20px;
/* text-shadow: 1px 1px 1px #FFF; */
}
.login_table label {