/**
* Add a software. If already exist in dustbin restore it
*
* @param name the software's name
* @param manufacturer the software's manufacturer
* @param entity the entity in which the software must be added
* @param comment comment (default '')
* @param is_recursive boolean must the software be recursive (false by default)
* @param is_helpdesk_visible show in helpdesk, default = config value (false by default)
*/
function addOrRestoreFromTrash($name, $manufacturer, $entity, $comment = '', $is_recursive = false, $is_helpdesk_visible = NULL)
{
global $DB;
//Look for the software by his name in GLPI for a specific entity
$manufacturer_id = 0;
if ($manufacturer != '') {
$manufacturer_id = Dropdown::import('Manufacturer', array('name' => $manufacturer));
}
$query_search = "SELECT `glpi_softwares`.`id`, `glpi_softwares`.`is_deleted`\n FROM `glpi_softwares`\n WHERE `name` = '{$name}'\n AND `manufacturers_id` = '{$manufacturer_id}'\n AND `is_template` = '0' " . getEntitiesRestrictRequest('AND', 'glpi_softwares', 'entities_id', $entity, true);
$result_search = $DB->query($query_search);
if ($DB->numrows($result_search) > 0) {
//Software already exists for this entity, get his ID
$data = $DB->fetch_assoc($result_search);
$ID = $data["id"];
// restore software
if ($data['is_deleted']) {
$this->removeFromTrash($ID);
}
} else {
$ID = 0;
}
if (!$ID) {
$ID = $this->addSoftware($name, $manufacturer_id, $entity, $comment, $is_recursive, $is_helpdesk_visible);
}
return $ID;
}