diff --git a/inc/calendar.class.php b/inc/calendar.class.php
index d20c37c333e..e317d9fb0de 100755
--- a/inc/calendar.class.php
+++ b/inc/calendar.class.php
@@ -89,6 +89,7 @@ function getSpecificMassiveActions($checkitem=NULL) {
if ($isadmin) {
$actions[__CLASS__.MassiveAction::CLASS_ACTION_SEPARATOR.'duplicate'] = _x('button', 'Duplicate');
+ $actions[__CLASS__.MassiveAction::CLASS_ACTION_SEPARATOR.'addholiday'] = __('Add a close time');
}
return $actions;
}
@@ -107,6 +108,12 @@ static function showMassiveActionsSubForm(MassiveAction $ma) {
echo "
";
echo Html::submit(_x('button', 'Duplicate'), array('name' => 'massiveaction'))."";
return true;
+
+ case 'addholiday' :
+ Holiday::dropdown();
+ echo "
";
+ echo Html::submit(_x('button', 'Add'), array('name' => 'massiveaction'))."";
+ return true;
}
return parent::showMassiveActionsSubForm($ma);
@@ -157,6 +164,43 @@ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBT
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
}
return;
+
+ case 'addholiday' : // add an holiday with massive action
+ $input = $ma->getInput();
+ if ($input['holidays_id'] > 0) {
+ $holiday = new Holiday();
+ $calendar_holiday = new Calendar_Holiday();
+
+ $holiday->getFromDB($input['holidays_id']);
+ $entities = array(
+ $holiday->getEntityID() => $holiday->getEntityID()
+ );
+ if ($holiday->isRecursive()) {
+ $entities = getSonsOf("glpi_entities", $holiday->getEntityID());
+ }
+
+ foreach ($ids as $id) {
+ $entities_id = CommonDBTM::getItemEntity('Calendar', $id);
+ if (isset($entities[$entities_id])) {
+ $input = array(
+ 'calendars_id' => $id,
+ 'holidays_id' => $input['holidays_id']
+ );
+ if ($calendar_holiday->add($input)) {
+ $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
+ } else {
+ $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
+ $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
+ }
+ } else {
+ $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
+ $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
+ }
+ }
+ } else {
+ $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
+ }
+ return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}