Merge pull request #11921 from OPEN-DSI/fix-resource-event-move-check-busy
FIX check if a resource is in use after a drag and drop from events
This commit is contained in:
commit
7a733ff283
@ -652,8 +652,7 @@ if (empty($reshook) && $action == 'confirm_delete' && GETPOST("confirm") == 'yes
|
|||||||
*/
|
*/
|
||||||
if (empty($reshook) && GETPOST('actionmove', 'alpha') == 'mupdate')
|
if (empty($reshook) && GETPOST('actionmove', 'alpha') == 'mupdate')
|
||||||
{
|
{
|
||||||
//$object->fetch($id);
|
$error = 0;
|
||||||
//$object->fetch_userassigned();
|
|
||||||
|
|
||||||
$shour = dol_print_date($object->datep, "%H");
|
$shour = dol_print_date($object->datep, "%H");
|
||||||
$smin = dol_print_date($object->datep, "%M");
|
$smin = dol_print_date($object->datep, "%M");
|
||||||
@ -673,12 +672,78 @@ if (empty($reshook) && GETPOST('actionmove', 'alpha') == 'mupdate')
|
|||||||
$object->datef+=$datep-$object->datep;
|
$object->datef+=$datep-$object->datep;
|
||||||
}
|
}
|
||||||
$object->datep=$datep;
|
$object->datep=$datep;
|
||||||
$result=$object->update($user);
|
|
||||||
if ($result < 0)
|
if (!$error) {
|
||||||
{
|
// check if an event resource is already in use
|
||||||
|
if (!empty($conf->global->RESOURCE_USED_IN_EVENT_CHECK) && $object->element == 'action') {
|
||||||
|
$eventDateStart = $object->datep;
|
||||||
|
$eventDateEnd = $object->datef;
|
||||||
|
|
||||||
|
$sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label";
|
||||||
|
$sql .= " FROM " . MAIN_DB_PREFIX . "element_resources as er";
|
||||||
|
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "resource as r ON r.rowid = er.resource_id AND er.resource_type = 'dolresource'";
|
||||||
|
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "actioncomm as ac ON ac.id = er.element_id AND er.element_type = '" . $db->escape($object->element) . "'";
|
||||||
|
$sql .= " WHERE ac.id != " . $object->id;
|
||||||
|
$sql .= " AND er.resource_id IN (";
|
||||||
|
$sql .= " SELECT resource_id FROM " . MAIN_DB_PREFIX . "element_resources";
|
||||||
|
$sql .= " WHERE element_id = " . $object->id;
|
||||||
|
$sql .= " AND element_type = '" . $db->escape($object->element) . "'";
|
||||||
|
$sql .= " AND busy = 1";
|
||||||
|
$sql .= ")";
|
||||||
|
$sql .= " AND er.busy = 1";
|
||||||
|
$sql .= " AND (";
|
||||||
|
|
||||||
|
// event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
|
||||||
|
$sql .= " (ac.datep <= '" . $db->idate($eventDateStart) . "' AND (ac.datep2 IS NULL OR ac.datep2 >= '" . $db->idate($eventDateStart) . "'))";
|
||||||
|
// event date end between ac.datep and ac.datep2
|
||||||
|
if (!empty($eventDateEnd)) {
|
||||||
|
$sql .= " OR (ac.datep <= '" . $db->idate($eventDateEnd) . "' AND (ac.datep2 >= '" . $db->idate($eventDateEnd) . "'))";
|
||||||
|
}
|
||||||
|
// event date start before ac.datep and event date end after ac.datep2
|
||||||
|
$sql .= " OR (";
|
||||||
|
$sql .= "ac.datep >= '" . $db->idate($eventDateStart) . "'";
|
||||||
|
if (!empty($eventDateEnd)) {
|
||||||
|
$sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '" . $db->idate($eventDateEnd) . "')";
|
||||||
|
}
|
||||||
|
$sql .= ")";
|
||||||
|
|
||||||
|
$sql .= ")";
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if (!$resql) {
|
||||||
|
$error++;
|
||||||
|
$object->error = $db->lasterror();
|
||||||
|
$object->errors[] = $object->error;
|
||||||
|
} else {
|
||||||
|
if ($db->num_rows($resql) > 0) {
|
||||||
|
// already in use
|
||||||
|
$error++;
|
||||||
|
$object->error = $langs->trans('ErrorResourcesAlreadyInUse') . ' : ';
|
||||||
|
while ($obj = $db->fetch_object($resql)) {
|
||||||
|
$object->error .= '<br> - ' . $langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label . ' [' . $obj->ac_id . ']');
|
||||||
|
}
|
||||||
|
$object->errors[] = $object->error;
|
||||||
|
}
|
||||||
|
$db->free($resql);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error) {
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$error) {
|
||||||
|
$db->begin();
|
||||||
|
$result = $object->update($user);
|
||||||
|
if ($result < 0) {
|
||||||
|
$error++;
|
||||||
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
|
$db->rollback();
|
||||||
|
} else {
|
||||||
|
$db->commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (! empty($backtopage))
|
if (! empty($backtopage))
|
||||||
{
|
{
|
||||||
header("Location: ".$backtopage);
|
header("Location: ".$backtopage);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user