public static function storeRecords($records, $user, $type = HOLIDAY_TYPE_COMPANY_HOLIDAY, $annual = 1, $description = "")
 {
     global $AppUI;
     foreach ($records as $record) {
         $startDate = $record['startDate']->getPrevDay()->format('%Y-%m-%d');
         $endDate = $record['endDate']->getNextDay()->format('%Y-%m-%d');
         $q = new w2p_Database_Query();
         $q->addTable("holiday");
         $q->addQuery("*");
         $where = "( date(holiday_start_date) = '";
         $where .= $endDate;
         $where .= "' OR date(holiday_end_date) = '";
         $where .= $startDate;
         $where .= "' )";
         $where .= " AND holiday_user="******" AND holiday_type=" . $type;
         $where .= " AND holiday_annual=" . $annual;
         $where .= " AND holiday_description=" . $q->quote($description);
         $q->addWhere($where);
         $q->addOrder('holiday_start_date');
         $list = $q->loadList();
         $obj = new CHoliday();
         switch (sizeof($list)) {
             case 0:
                 if (!$obj->bind($record)) {
                     $AppUI->setMsg($obj->getError(), UI_MSG_ERROR);
                     $AppUI->redirect();
                 }
                 break;
             case 1:
                 $item = $list[0];
                 $obj->load($item['holiday_id']);
                 if (substr($item['holiday_start_date'], 0, 10) == $endDate) {
                     $obj->holiday_start_date = $record['endDate']->getDate();
                 } else {
                     $obj->holiday_end_date = $record['startDate']->getDate();
                 }
                 break;
             case 2:
                 $item1 = $list[0];
                 $item2 = $list[1];
                 if (substr($item1['holiday_end_date'], 0, 10) != $startDate || substr($item2['holiday_start_date'], 0, 10) != $endDate) {
                     $AppUI->setMsg($AppUI->_('User holidays inconsistency'), UI_MSG_ERROR);
                     $AppUI->redirect();
                 }
                 $obj2 = new CHoliday();
                 $obj2->load($item2['holiday_id']);
                 $result = $obj2->delete($AppUI);
                 if (is_string($result)) {
                     $AppUI->setMsg($result, UI_MSG_ERROR);
                     $AppUI->redirect();
                 }
                 $obj->load($item1['holiday_id']);
                 $obj->holiday_end_date = $item2['holiday_end_date'];
                 break;
             default:
                 $AppUI->setMsg($AppUI->_('User holidays inconsistency'), UI_MSG_ERROR);
                 $AppUI->redirect();
         }
         $result = $obj->store($AppUI);
         if (is_string($result)) {
             $AppUI->setMsg($result, UI_MSG_ERROR);
             $AppUI->redirect();
         }
     }
 }