Merge pull request #20874 from Hystepik/develop#3

New : import fields in societe class
This commit is contained in:
Laurent Destailleur 2022-05-21 22:50:36 +02:00 committed by GitHub
commit 9fd6d4bb1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 17 deletions

View File

@ -2959,7 +2959,7 @@ function dol_print_socialnetworks($value, $cid, $socid, $type, $dictsocialnetwor
} else {
if (!empty($dictsocialnetworks[$type]['url'])) {
$link = str_replace('{socialid}', $value, $dictsocialnetworks[$type]['url']);
$htmllink .= '&nbsp;<a href="'.$link.'" target="_blank" rel="noopener noreferrer">'.dol_escape_htmltag($value).'</a>';
$htmllink .= '&nbsp;<a href="'.dol_sanitizeUrl($link).'" target="_blank" rel="noopener noreferrer">'.dol_escape_htmltag($value).'</a>';
} else {
$htmllink .= dol_escape_htmltag($value);
}

View File

@ -709,15 +709,37 @@ class ImportCsv extends ModeleImports
}
// Define $listfields and $listvalues to build SQL request
$listfields[] = $fieldname;
// Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) {
$listvalues[] = ($newval == '0' ? $newval : "null");
} elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) {
$listvalues[] = "''";
if ($conf->socialnetworks->enabled && strpos($fieldname, "socialnetworks") !== false) {
if (!in_array("socialnetworks", $listfields)) {
$listfields[] = "socialnetworks";
}
if (!empty($newval) && $arrayrecord[($key - 1)]['type'] > 0) {
$socialkey = array_search("socialnetworks", $listfields);
if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") {
$socialnetwork = explode("_", $fieldname)[1];
$json = new stdClass();
$json->$socialnetwork = $newval;
$newvalue = json_encode($json);
$listvalues[$socialkey] = "'".$this->db->escape($newvalue)."'";
} else {
$socialnetwork = explode("_", $fieldname)[1];
$jsondata = $listvalues[$socialkey];
$jsondata = str_replace("'", "", $jsondata);
$json = json_decode($jsondata);
$json->$socialnetwork = $newval;
$listvalues[$socialkey] = "'".$this->db->escape(json_encode($json))."'";
}
}
} else {
$listvalues[] = "'".$this->db->escape($newval)."'";
$listfields[] = $fieldname;
// Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
if (empty($newval) && $arrayrecord[($key - 1)]['type'] < 0) {
$listvalues[] = ($newval == '0' ? $newval : "null");
} elseif (empty($newval) && $arrayrecord[($key - 1)]['type'] == 0) {
$listvalues[] = "''";
} else {
$listvalues[] = "'".$this->db->escape($newval)."'";
}
}
}
$i++;

View File

@ -363,6 +363,8 @@ class ImportXlsx extends ModeleImports
$warning = 0;
$this->errors = array();
$this->warnings = array();
$this->nbinsert = 0;
$this->nbupdate = 0;
//dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid);
@ -750,15 +752,38 @@ class ImportXlsx extends ModeleImports
}
// Define $listfields and $listvalues to build SQL request
$listfields[] = $fieldname;
// Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
if (empty($newval) && $arrayrecord[($key)]['type'] < 0) {
$listvalues[] = ($newval == '0' ? $newval : "null");
} elseif (empty($newval) && $arrayrecord[($key)]['type'] == 0) {
$listvalues[] = "''";
if ($conf->socialnetworks->enabled && strpos($fieldname, "socialnetworks") !== false) {
if (!in_array("socialnetworks", $listfields)) {
$listfields[] = "socialnetworks";
}
if (!empty($newval) && $arrayrecord[($key)]['type'] > 0) {
$socialkey = array_search("socialnetworks", $listfields);
if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") {
$socialnetwork = explode("_", $fieldname)[1];
$json = new stdClass();
$json->$socialnetwork = $newval;
$newvalue = json_encode($json);
$listvalues[$socialkey] = $newvalue;
} else {
$socialnetwork = explode("_", $fieldname)[1];
$jsondata = $listvalues[$socialkey];
$jsondata = str_replace("'", "", $jsondata);
$json = json_decode($jsondata);
$json->$socialnetwork = $this->db->escape($newval);
$listvalues[$socialkey] = "'".$this->db->escape(json_encode($json))."'";
}
}
} else {
$listvalues[] = "'" . $this->db->escape($newval) . "'";
$listfields[] = $fieldname;
// Note: arrayrecord (and 'type') is filled with ->import_read_record called by import.php page before calling import_insert
if (empty($newval) && $arrayrecord[($key)]['type'] < 0) {
$listvalues[] = ($newval == '0' ? $newval : "null");
} elseif (empty($newval) && $arrayrecord[($key)]['type'] == 0) {
$listvalues[] = "''";
} else {
$listvalues[] = "'" . $this->db->escape($newval) . "'";
}
}
}
$i++;

View File

@ -519,6 +519,16 @@ class modSociete extends DolibarrModules
if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
$this->import_fields_array[$r] += array('s.accountancy_code_sell'=>'ProductAccountancySellCode', 's.accountancy_code_buy'=>'ProductAccountancyBuyCode');
}
// Add social networks fields
if (!empty($conf->socialnetworks->enabled)) {
$sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
$resql = $this->db->query($sql);
while ($obj = $this->db->fetch_object($resql)) {
$fieldname = 's.socialnetworks_'.$obj->code;
$fieldlabel = ucfirst($obj->label);
$this->import_fields_array[$r][$fieldname] = $fieldlabel;
}
}
// Add extra fields
$sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'societe' AND entity IN (0, ".$conf->entity.")";
$resql = $this->db->query($sql);
@ -718,6 +728,16 @@ class modSociete extends DolibarrModules
's.note_private' => "NotePrivate",
's.note_public' => "NotePublic"
);
// Add social networks fields
if (!empty($conf->socialnetworks->enabled)) {
$sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
$resql = $this->db->query($sql);
while ($obj = $this->db->fetch_object($resql)) {
$fieldname = 's.socialnetworks_'.$obj->code;
$fieldlabel = ucfirst($obj->label);
$this->import_fields_array[$r][$fieldname] = $fieldlabel;
}
}
// Add extra fields
$sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type != 'separate' AND elementtype = 'socpeople' AND entity IN (0, ".$conf->entity.")";
$resql = $this->db->query($sql);