function transferLinkedSuppliers($itemtype, $ID, $newID)
{
global $DB;
switch ($itemtype) {
case 'Ticket':
$table = 'glpi_suppliers_tickets';
$field = 'tickets_id';
$link = new Supplier_Ticket();
break;
case 'Problem':
$table = 'glpi_problems_suppliers';
$field = 'problems_id';
$link = new Problem_Supplier();
break;
case 'Change':
$table = 'glpi_changes_suppliers';
$field = 'changes_id';
$link = new Change_Supplier();
break;
}
$query = "SELECT *\n FROM `{$table}`\n WHERE `{$field}` = '{$ID}'";
if ($result = $DB->query($query)) {
if ($DB->numrows($result) != 0) {
while ($data = $DB->fetch_assoc($result)) {
$input = array();
if ($data['suppliers_id'] > 0) {
$supplier = new Supplier();
if ($supplier->getFromDB($data['suppliers_id'])) {
$newID = -1;
$query = "SELECT *\n FROM `glpi_suppliers`\n WHERE `entities_id` = '" . $this->to . "'\n AND `name` = '" . addslashes($supplier->fields['name']) . "'";
if ($result_search = $DB->query($query)) {
if ($DB->numrows($result_search) > 0) {
$newID = $DB->result($result_search, 0, 'id');
}
}
if ($newID < 0) {
// 1 - create new item
unset($supplier->fields['id']);
$input = $supplier->fields;
$input['entities_id'] = $this->to;
// Not set new entity Do by transferItem
unset($supplier->fields);
$newID = $supplier->add(toolbox::addslashes_deep($input));
}
$input2['id'] = $data['id'];
$input2[$field] = $ID;
$input2['suppliers_id'] = $newID;
$link->update($input2);
}
}
}
}
}
}