diff --git a/src/Checkin.php b/src/Checkin.php index b66611054e..0f51306478 100644 --- a/src/Checkin.php +++ b/src/Checkin.php @@ -472,7 +472,7 @@ class="col-sm-12 control-label"> ?>
- + diff --git a/src/EcclesiaCRM/APIControllers/CalendarEventV2Controller.php b/src/EcclesiaCRM/APIControllers/CalendarEventV2Controller.php index 229c31e3b7..0454f13444 100644 --- a/src/EcclesiaCRM/APIControllers/CalendarEventV2Controller.php +++ b/src/EcclesiaCRM/APIControllers/CalendarEventV2Controller.php @@ -15,11 +15,9 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use EcclesiaCRM\dto\SystemConfig; use EcclesiaCRM\Base\EventQuery; use EcclesiaCRM\Base\EventTypesQuery; use EcclesiaCRM\EventCountsQuery; -use EcclesiaCRM\EventCounts; use EcclesiaCRM\Person2group2roleP2g2rQuery; use EcclesiaCRM\FamilyQuery; use EcclesiaCRM\dto\MenuEventsCount; @@ -28,9 +26,6 @@ use EcclesiaCRM\EventAttend; use EcclesiaCRM\Utils\GeoUtils; use EcclesiaCRM\SessionUser; -use EcclesiaCRM\UserQuery; - -use EcclesiaCRM\CalendarinstancesQuery; use Sabre\VObject; @@ -47,12 +42,33 @@ public function __construct(ContainerInterface $container) $this->container = $container; } - public function getAllEvents (ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface + public function getAllEvents(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface { $Events = EventQuery::create() ->find(); - return $response->withJson($Events->toArray()); + $return = []; + + foreach ($Events as $event) { + $values = [ + 'Id' => $event->getID(), + 'Title' => $event->getTitle(), + 'Type' => $event->getType(), + 'InActive' => $event->getInActive(), + 'Text' => $event->getText(), + 'Start' => $event->getStart(), + 'End' => $event->getEnd(), + 'TypeName' => $event->getTypeName(), + 'GroupId' => $event->getGroupId(), + 'LastOccurence' => $event->getLastOccurence(), + 'Location' => $event->getLocation(), + 'Coordinates' => $event->getCoordinates(), + ]; + + $return[] = $values; + } + + return $response->withJson($return); } public function getNotDoneEvents(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface @@ -84,7 +100,7 @@ public function getNotDoneEvents(ServerRequestInterface $request, ResponseInterf return $response->write($Events->toJSON()); }*/ - return $response->withJson(["Events" =>$return]); + return $response->withJson(["Events" => $return]); } public function numbersOfEventOfToday(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface @@ -195,7 +211,7 @@ public function personCheckIn(ServerRequestInterface $request, ResponseInterface $eventAttent->setEventId($params->EventID); $eventAttent->setCheckinId(SessionUser::getUser()->getPersonId()); - $eventAttent->setCheckinDate( NULL); + $eventAttent->setCheckinDate(NULL); $eventAttent->setPersonId($params->PersonId); $eventAttent->save(); } catch (\Exception $ex) { @@ -292,8 +308,8 @@ public function eventCount(ServerRequestInterface $request, ResponseInterface $r $values['countID'] = $eventCountName->getId(); $values['countName'] = $eventCountName->getName(); $values['typeID'] = $params->typeID; - $values['startHour'] = sprintf("%02d",$aEventStartHour); - $values['startMin'] = sprintf("%02d",$aEventStartMins); + $values['startHour'] = sprintf("%02d", $aEventStartHour); + $values['startMin'] = sprintf("%02d", $aEventStartMins); $values['DefRecurDOW'] = $aDefRecurDOW;// unusefull actually $values['DefRecurDOM'] = $aDefRecurDOM;// unusefull actually @@ -322,7 +338,7 @@ public function manageEvent(ServerRequestInterface $request, ResponseInterface $ $the_event = Null; - if ( isset($input->eventID) ) { + if (isset($input->eventID)) { $the_event = EventQuery::create()->findOneById($input->eventID); } @@ -330,10 +346,10 @@ public function manageEvent(ServerRequestInterface $request, ResponseInterface $ if (!strcmp($input->eventAction, 'createEvent')) { - if ( !$calendarService->createEventForCalendar($input->calendarID, $input->start, $input->end, + if (!$calendarService->createEventForCalendar($input->calendarID, $input->start, $input->end, $input->recurrenceType, $input->endrecurrence, $input->EventDesc, $input->EventTitle, $input->location, $input->recurrenceValid, $input->addGroupAttendees, $input->alarm, $input->eventTypeID, $input->eventNotes, - $input->eventInActive, $input->Fields, $input->EventCountNotes) ) { + $input->eventInActive, $input->Fields, $input->EventCountNotes)) { return $response->withJson(["status" => "failed", "message" => _("Two resource reservations cannot be in the same time slot.")]); } @@ -342,7 +358,7 @@ public function manageEvent(ServerRequestInterface $request, ResponseInterface $ } else if (!strcmp($input->eventAction, 'moveEvent')) { // this part allows to create a resource without being in collision on another one - if ( $the_event->getCreatorUserId() != 0 and SessionUser::getId() != $the_event->getCreatorUserId() and !SessionUser::isManageCalendarResources() ) { + if ($the_event->getCreatorUserId() != 0 and SessionUser::getId() != $the_event->getCreatorUserId() and !SessionUser::isManageCalendarResources()) { return $response->withJson(["status" => "failed", "message" => _("This resource reservation was not created by you. You cannot edit, move or delete a resource that you do not own.")]); } @@ -429,7 +445,7 @@ public function manageEvent(ServerRequestInterface $request, ResponseInterface $ } // this part allows to create a resource without being in collision on another one - if ( is_array( $input->calendarID ) ) { + if (is_array($input->calendarID)) { $calIDs = $input->calendarID; } else { $calIDs = explode(",", $input->calendarID); @@ -564,7 +580,7 @@ public function manageEvent(ServerRequestInterface $request, ResponseInterface $ } else if (!strcmp($input->eventAction, 'resizeEvent')) { // this part allows to create a resource without being in collision on another one - if ( $the_event->getCreatorUserId() != 0 and SessionUser::getId() != $the_event->getCreatorUserId() and !SessionUser::isManageCalendarResources() ) { + if ($the_event->getCreatorUserId() != 0 and SessionUser::getId() != $the_event->getCreatorUserId() and !SessionUser::isManageCalendarResources()) { return $response->withJson(["status" => "failed", "message" => _("This resource reservation was not created by you. You cannot edit, move or delete a resource that you do not own.")]); } @@ -709,7 +725,7 @@ public function manageEvent(ServerRequestInterface $request, ResponseInterface $ $_SESSION['EID'] = $event->getID(); $_SESSION['EName'] = $event->getTitle(); $_SESSION['EDesc'] = $event->getDesc(); - $_SESSION['EDate'] = ( !is_null($event->getStart()) )?$event->getStart()->format('Y-m-d H:i:s'):''; + $_SESSION['EDate'] = (!is_null($event->getStart())) ? $event->getStart()->format('Y-m-d H:i:s') : ''; $_SESSION['EventID'] = $event->getID(); @@ -718,7 +734,7 @@ public function manageEvent(ServerRequestInterface $request, ResponseInterface $ } else if (!strcmp($input->eventAction, 'suppress')) { // this part allows to create a resource without being in collision on another one - if ( $the_event->getCreatorUserId() != 0 and SessionUser::getId() != $the_event->getCreatorUserId() and !SessionUser::isManageCalendarResources() ) { + if ($the_event->getCreatorUserId() != 0 and SessionUser::getId() != $the_event->getCreatorUserId() and !SessionUser::isManageCalendarResources()) { return $response->withJson(["status" => "failed", "message" => _("This resource reservation was not created by you. You cannot edit, move or delete a resource that you do not own.")]); } @@ -730,13 +746,13 @@ public function manageEvent(ServerRequestInterface $request, ResponseInterface $ } else if (!strcmp($input->eventAction, 'modifyEvent')) { - if ( $the_event->getCreatorUserId() != 0 and SessionUser::getId() != $the_event->getCreatorUserId() and !SessionUser::isManageCalendarResources() ) { + if ($the_event->getCreatorUserId() != 0 and SessionUser::getId() != $the_event->getCreatorUserId() and !SessionUser::isManageCalendarResources()) { return $response->withJson(["status" => "failed", "message" => _("This resource reservation was not created by you. You cannot edit, move or delete a resource that you do not own.")]); } - return $response->withJson( $calendarService->modifyEventFromCalendar($input->calendarID, $input->eventID, $input->reccurenceID, $input->start, + return $response->withJson($calendarService->modifyEventFromCalendar($input->calendarID, $input->eventID, $input->reccurenceID, $input->start, $input->end, $input->EventTitle, $input->EventDesc, $input->location, $input->addGroupAttendees, $input->alarm, $input->eventTypeID, $input->eventNotes, - $input->eventInActive, $input->Fields, $input->EventCountNotes, $input->recurrenceValid, $input->recurrenceType, $input->endrecurrence) ); + $input->eventInActive, $input->Fields, $input->EventCountNotes, $input->recurrenceValid, $input->recurrenceType, $input->endrecurrence)); } return $response->withJson(["status" => "failed"]); diff --git a/src/EcclesiaCRM/APIControllers/CalendarV2Controller.php b/src/EcclesiaCRM/APIControllers/CalendarV2Controller.php index 1c23786487..dcd4303c59 100644 --- a/src/EcclesiaCRM/APIControllers/CalendarV2Controller.php +++ b/src/EcclesiaCRM/APIControllers/CalendarV2Controller.php @@ -47,7 +47,15 @@ public function getallCalendarEvents (ServerRequestInterface $request, ResponseI $CalendarService = $this->container->get('CalendarService'); - return $response->withJson($CalendarService->getEvents($params->start, $params->end, $params->isBirthdayActive, $params->isAnniversaryActive));; + return $response->withJson($CalendarService->getEvents($params->start, $params->end, $params->isBirthdayActive, $params->isAnniversaryActive)['EventsListResults']);; + } + + public function getallCalendarEventsForEventsList (ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface { + $params = (object)$request->getParsedBody(); + + $CalendarService = $this->container->get('CalendarService'); + + return $response->withJson($CalendarService->getEvents($params->start, $params->end, $params->isBirthdayActive, $params->isAnniversaryActive, $params->forEventslist)); } public function numberOfCalendars (ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface { diff --git a/src/EcclesiaCRM/MenuBar/MenuBar.php b/src/EcclesiaCRM/MenuBar/MenuBar.php index d8f2c353d8..f53a05eae2 100644 --- a/src/EcclesiaCRM/MenuBar/MenuBar.php +++ b/src/EcclesiaCRM/MenuBar/MenuBar.php @@ -85,7 +85,7 @@ public function addEventMenu() $menuItem = new Menu (_("View on Map"), "fa fa-map-o", "v2/map/-2", true, $menu); } - $menuItem = new Menu (_("List Church Events"), "fa fa-circle-o", "ListEvents.php", true, $menu); + $menuItem = new Menu (_("List Church Events"), "fa fa-circle-o", "v2/calendar/events/list", true, $menu); $menuItem = new Menu (_("List Event Types"), "fa fa-circle-o", "EventNames.php", SessionUser::getUser()->isAdmin(), $menu); $menuItem = new Menu (_("Call the Register"), "fa fa-circle-o", "Checkin.php", true, $menu); diff --git a/src/EcclesiaCRM/Service/CalendarService.php b/src/EcclesiaCRM/Service/CalendarService.php index 6e39583a80..8644fdef9a 100644 --- a/src/EcclesiaCRM/Service/CalendarService.php +++ b/src/EcclesiaCRM/Service/CalendarService.php @@ -13,21 +13,34 @@ use EcclesiaCRM\Base\EventTypesQuery; use EcclesiaCRM\CalendarinstancesQuery; -use EcclesiaCRM\dto\SystemConfig; -use EcclesiaCRM\EventAttend; -use EcclesiaCRM\EventCounts; use EcclesiaCRM\EventQuery; use EcclesiaCRM\FamilyQuery; -use EcclesiaCRM\MyVCalendar\VCalendarExtension; +use EcclesiaCRM\EventAttendQuery; use EcclesiaCRM\Person2group2roleP2g2rQuery; use EcclesiaCRM\PersonQuery; use EcclesiaCRM\UserQuery; +use EcclesiaCRM\EventCountsQuery; + +use EcclesiaCRM\Map\EventTableMap; +use EcclesiaCRM\Map\EventTypesTableMap; +use EcclesiaCRM\Map\GroupTableMap; + +use EcclesiaCRM\Map\CalendarinstancesTableMap; +use EcclesiaCRM\Map\PrincipalsTableMap; +use EcclesiaCRM\dto\SystemConfig; +use EcclesiaCRM\EventAttend; +use EcclesiaCRM\EventCounts; + +use EcclesiaCRM\SessionUser; use EcclesiaCRM\Utils\GeoUtils; use Propel\Runtime\ActiveQuery\Criteria; -use EcclesiaCRM\EventCountsQuery; +use EcclesiaCRM\dto\SystemURLs; +use EcclesiaCRM\Utils\OutputUtils; + use EcclesiaCRM\MyPDO\CalDavPDO; use EcclesiaCRM\MyPDO\PrincipalPDO; -use EcclesiaCRM\SessionUser; +use EcclesiaCRM\MyVCalendar\VCalendarExtension; + use EcclesiaCRM\MyPDO\VObjectExtract; use Sabre\DAV\UUIDUtil; @@ -45,58 +58,54 @@ public function getEventTypes() return $eventTypes; } - public function getEvents($start, $end, $isBirthdayActive, $isAnniversaryActive) + public function getEvents($start, $end, $isBirthdayActive, $isAnniversaryActive, $for_events_list = false) { $origStart = $start; $origEnd = $end; + $dtOrigStart = new \DateTime($origStart); + $dtOrigEnd = new \DateTime($origEnd); + + // get the first and the last month + $firstMonth = $real_firstMonth = (int)$dtOrigStart->format('m') - 1; + $endMonth = (int)$dtOrigEnd->format('m') - 1; + + $all_months = $firstMonth + 1; + + $i = 0; + while ($firstMonth != $endMonth and $i < 13) { + $firstMonth = ($firstMonth + 1) % 12; + $all_months .= "," . ($firstMonth + 1); + $i++; + } + $events = []; $startDate = date_create($start); $endDate = date_create($end); - $startYear = $endYear = '1900'; $endsNextYear = false; if ($endDate->format('Y') > $startDate->format('Y')) { - $endYear = '1901'; $endsNextYear = true; } $firstYear = $startDate->format('Y'); - if (SessionUser::getUser()->isSeePrivacyDataEnabled()) { if ($isBirthdayActive) { $peopleWithBirthDays = PersonQuery::create() ->filterByDateDeactivated(null)// GDRP, when a person is completely deactivated - ->JoinWithFamily(); - - // get the first and the last month - $firstMonth = $startDate->format('m'); - $endMonth = $endDate->format('m'); - - $month = $firstMonth; - - $peopleWithBirthDays->filterByBirthMonth($firstMonth);// the event aren't more than a month - - while ($month != $endMonth) {// we loop to have all the months from the first in the start to the end - $month += 1; - if ($month == 13) { - $month = 1; - } - if ($month == 0) { - $month = 1; - } - $peopleWithBirthDays->_or()->filterByBirthMonth($month);// the event aren't more than a month - } - + ->JoinWithFamily() + ->filterByBirthMonth(explode(",", $all_months))// the event aren't more than a month + ->find(); - $peopleWithBirthDays->find(); foreach ($peopleWithBirthDays as $person) { $year = $firstYear; if ($person->getBirthMonth() == 1 && $endsNextYear) { $year = $firstYear + 1; } - $start = date_create($year . '-' . $person->getBirthMonth() . '-' . $person->getBirthDay()); + + $dtStart = new \DateTime($year . '-' . $person->getBirthMonth() . '-' . $person->getBirthDay()); + $event = $this->createCalendarItemForGetEvents('birthday', '', - $person->getFullName() . " " . $person->getAge(), $start->format(DATE_ATOM), '', $person->getViewURI()); + $person->getFullName() . " " . $person->getAge(), $dtStart->format(\DateTimeInterface::ATOM), '', $person->getViewURI()); array_push($events, $event); } } @@ -104,8 +113,8 @@ public function getEvents($start, $end, $isBirthdayActive, $isAnniversaryActive) if ($isAnniversaryActive) { // we search the Anniversaries $Anniversaries = FamilyQuery::create() - ->filterByWeddingDate(['min' => '0001-00-00']) // a Wedding Date ->filterByDateDeactivated(null, Criteria::EQUAL) //Date Deactivated is null (active) + ->Where('MONTH(fam_WeddingDate) IN (' . $all_months . ')') ->find(); $curYear = date('Y'); @@ -115,9 +124,11 @@ public function getEvents($start, $end, $isBirthdayActive, $isAnniversaryActive) if ($anniversary->getWeddingMonth() < $curMonth) { $year = $year + 1; } - $start = $year . '-' . $anniversary->getWeddingMonth() . '-' . $anniversary->getWeddingDay(); + + $dtStart = new \DateTime($year . '-' . $anniversary->getWeddingMonth() . '-' . $anniversary->getWeddingDay()); + $event = $this->createCalendarItemForGetEvents('anniversary', '', - $anniversary->getName(), $start, '', $anniversary->getViewURI()); + $anniversary->getName(), $dtStart->format(\DateTimeInterface::ATOM), '', $anniversary->getViewURI()); array_push($events, $event); } } @@ -133,6 +144,24 @@ public function getEvents($start, $end, $isBirthdayActive, $isAnniversaryActive) $calendars = $calendarBackend->getCalendarsForUser('principals/' . strtolower(SessionUser::getUser()->getUserName()), "displayname", false); + // for the globas stats : v2/calendar/events/list + // only in case of monthly view + // for : $for_events_list + $AVG_stats = [ + '1' => ['numAVGAtt' => 0, 'numAVG_CheckIn' => 0, 'numAVG_CheckOut' => 0], + '2' => ['numAVGAtt' => 0, 'numAVG_CheckIn' => 0, 'numAVG_CheckOut' => 0], + '3' => ['numAVGAtt' => 0, 'numAVG_CheckIn' => 0, 'numAVG_CheckOut' => 0], + '4' => ['numAVGAtt' => 0, 'numAVG_CheckIn' => 0, 'numAVG_CheckOut' => 0], + '5' => ['numAVGAtt' => 0, 'numAVG_CheckIn' => 0, 'numAVG_CheckOut' => 0], + '6' => ['numAVGAtt' => 0, 'numAVG_CheckIn' => 0, 'numAVG_CheckOut' => 0], + '7' => ['numAVGAtt' => 0, 'numAVG_CheckIn' => 0, 'numAVG_CheckOut' => 0], + '8' => ['numAVGAtt' => 0, 'numAVG_CheckIn' => 0, 'numAVG_CheckOut' => 0], + '9' => ['numAVGAtt' => 0, 'numAVG_CheckIn' => 0, 'numAVG_CheckOut' => 0], + '10' => ['numAVGAtt' => 0, 'numAVG_CheckIn' => 0, 'numAVG_CheckOut' => 0], + '11' => ['numAVGAtt' => 0, 'numAVG_CheckIn' => 0, 'numAVG_CheckOut' => 0], + '12' => ['numAVGAtt' => 0, 'numAVG_CheckIn' => 0, 'numAVG_CheckOut' => 0] + ]; + foreach ($calendars as $calendar) { $calendarName = $calendar['{DAV:}displayname']; $calendarColor = $calendar['{http://apple.com/ns/ical/}calendar-color']; @@ -173,14 +202,29 @@ public function getEvents($start, $end, $isBirthdayActive, $isAnniversaryActive) // we get all the events for the Cal $eventsForCal = $calendarBackend->getCalendarObjects($calendar['id']); + $criteria = [0]; + if ( $for_events_list ) { + $criteria = [0,1]; + } + foreach ($eventsForCal as $eventForCal) { - $evnt = EventQuery::Create()->filterByInActive('false')->findOneById($eventForCal['id']); + $evnt = EventQuery::Create() + ->addJoin(EventTableMap::COL_EVENT_TYPE, EventTypesTableMap::COL_TYPE_ID, Criteria::LEFT_JOIN) + ->addJoin(EventTableMap::COL_EVENT_GRPID, GroupTableMap::COL_GRP_ID, Criteria::LEFT_JOIN) + ->addJoin(EventTableMap::COL_EVENT_CALENDARID, CalendarinstancesTableMap::COL_CALENDARID, Criteria::LEFT_JOIN) + ->addJoin(CalendarinstancesTableMap::COL_PRINCIPALURI, PrincipalsTableMap::COL_URI, Criteria::LEFT_JOIN) + ->addAsColumn('EventTypeName', EventTypesTableMap::COL_TYPE_NAME) + ->addAsColumn('GroupName', GroupTableMap::COL_GRP_NAME) + ->addAsColumn('CalendarName', CalendarinstancesTableMap::COL_DISPLAYNAME) + ->addAsColumn('rights', CalendarinstancesTableMap::COL_ACCESS) + ->addAsColumn('login', PrincipalsTableMap::COL_URI) + ->filterByInActive($criteria) + ->findOneById($eventForCal['id']); if ($evnt != null) { $calObj = $calendarBackend->getCalendarObject($calendar['id'], $eventForCal['uri']); - $cal_category = ($calendar['grpid'] != "0") ? 'group' : 'personal'; if ($calendar['share-access'] >= 2) { @@ -210,10 +254,79 @@ public function getEvents($start, $end, $isBirthdayActive, $isAnniversaryActive) $alarm = $evnt->getAlarm(); $rrule = $evnt->getFreqLastOccurence(); $freq = $evnt->getFreq(); + $eventTypeName = $evnt->getEventTypeName(); + $eventGroupName = $evnt->getGroupName(); + $eventCalendarName = $evnt->getCalendarName(); + $loginName = $evnt->getLogin(); + $status = ($evnt->getInactive() != 0)? _('No') : _('Yes'); + + if (!(SessionUser::getUser()->isAdmin())) { + $eventRights = ($evnt->getRights() == 1 || $evnt->getRights() == 3) ? true : false; + } else { + $eventRights = true; + } $fEvnt = false; $subid = 1; + // stats for each month + $month = $evnt->getStart()->format('m'); + + // only for v2/calendar/events/list + if ($for_events_list) { + + $attendees = EventAttendQuery::create() + ->findByEventId($evnt->getId()); + + if (!is_null($attendees)) { + $realStats['attNumRows'] = $attendees->count(); + + $attendees1 = EventAttendQuery::create() + ->filterByCheckoutDate(NULL, Criteria::NOT_EQUAL) + ->findByEventId($evnt->getId()); + + if (!is_null($realStats)) { + $realStats['attCheckOut'] = $attendees1->count(); + } + + $attendees2 = EventAttendQuery::create() + ->filterByCheckoutId(NULL, Criteria::NOT_EQUAL) + ->findByEventId($evnt->getId()); + + if (!is_null($realStats)) { + $realStats['realAttCheckOut'] = $attendees2->count(); + } + + $AVG_stats[$month]['numAVG_CheckIn'] += $realStats['attNumRows']; + $AVG_stats[$month]['numAVG_CheckOut'] += $realStats['attCheckOut']; + } + + if ($realStats['attNumRows']) { + $AVG_stats[$month]['numAVGAtt']++; + } + + // RETRIEVE THE list of counts associated with the current event + // Free Attendance Counts without Attendees + $freeStats = []; + + $eventCounts = EventCountsQuery::Create() + ->filterByEvtcntEventid($evnt->getId()) + ->orderByEvtcntCountid(Criteria::ASC) + ->find(); + + // the count is is inside the count of elements of $freeStats + //$aNumCounts = $eventCounts->count(); + foreach ($eventCounts as $eventCount) { + $freeStats[] = [ + 'cCountID' => $eventCount->getEvtcntCountid(), + 'cCountName' => $eventCount->getEvtcntCountname(), + 'cCount' => $eventCount->getEvtcntCountcount(), + 'cCountNotes' => $eventCount->getEvtcntNotes() + ]; + } + + } + foreach ($freqEvents as $key => $value) { if ($key == 'freq' && $value != 'none') { $fEvnt = true; @@ -224,38 +337,59 @@ public function getEvents($start, $end, $isBirthdayActive, $isAnniversaryActive) $end = $freqValue['DTEND']; $reccurenceID = $freqValue['RECURRENCE-ID']; - $event = $this->createCalendarItemForGetEvents('event', $icon, - $title, $start, $end, - '', $id, $type, $grpID, - $desc, $text, $calID, $calendarColor, - $subid++, 1, $reccurenceID, $rrule, $freq, $writeable, - $loc, $lat, $long, $alarm, $cal_type, $cal_category);// only the event id sould be edited and moved and have custom color + $dtStart = new \DateTime($start); + $dtEnd = new \DateTime($end); + + if ($dtOrigStart <= $dtStart and $dtStart <= $dtOrigEnd + and $dtOrigStart <= $dtEnd and $dtEnd <= $dtOrigEnd) { - array_push($events, $event); + $event = $this->createCalendarItemForGetEvents('event', $icon, + $title, $start, $end, + '', $id, $type, $grpID, + $desc, $text, $calID, $calendarColor, + $subid++, 1, $reccurenceID, $rrule, $freq, $writeable, + $loc, $lat, $long, $alarm, $cal_type, $cal_category, $eventTypeName, + $eventGroupName, $eventCalendarName, $eventRights, $loginName, + $realStats, $freeStats, $status);// only the event id sould be edited and moved and have custom color + + array_push($events, $event); + } } } } if ($fEvnt == false) { - $event = $this->createCalendarItemForGetEvents('event', $icon, - $title, $start, $end, - '', $id, $type, $grpID, - $desc, $text, $calID, $calendarColor, 0, 0, 0, $rrule, $freq, - $writeable, $loc, $lat, $long, $alarm, $cal_type, $cal_category);// only the event id sould be edited and moved and have custom color - array_push($events, $event); + $dtStart = new \DateTime($start); + $dtEnd = new \DateTime($end); + + if ($dtOrigStart <= $dtStart and $dtStart <= $dtOrigEnd + and $dtOrigStart <= $dtEnd and $dtEnd <= $dtOrigEnd) { + + $event = $this->createCalendarItemForGetEvents('event', $icon, + $title, $start, $end, + '', $id, $type, $grpID, + $desc, $text, $calID, $calendarColor, 0, 0, 0, $rrule, $freq, + $writeable, $loc, $lat, $long, $alarm, $cal_type, $cal_category, + $eventTypeName, $eventGroupName, $eventCalendarName, $eventRights, $loginName, + $realStats, $freeStats, $status);// only the event id sould be edited and moved and have custom color + + array_push($events, $event); + } } } } } - return $events; + + return ['EventsListResults' => $events, 'AVG_stats' => $AVG_stats]; } public function createCalendarItemForGetEvents($type, $icon, $title, $start, $end, $uri, $eventID = 0, $eventTypeID = 0, $groupID = 0, $desc = "", $text = "", $calendarid = null, $backgroundColor = null, $subid = 0, $recurrent = 0, $reccurenceID = '', $rrule = '', $freq = '', $writeable = false, $location = "", $latitude = 0, $longitude = 0, $alarm = "", $cal_type = "0", - $cal_category = "personal") + $cal_category = "personal", $eventTypeName = "all", $eventGroupName = "None", $eventCalendarName = "None", + $eventRights = false, $loginName = "", $realStats = [], $freeStats = [], $status='no') { $event = []; switch ($type) { @@ -271,9 +405,133 @@ public function createCalendarItemForGetEvents($type, $icon, $title, $start, $en $event['title'] = $title; $event['start'] = $start; + $event['month'] = (int)explode('-', $start)[1]; $event['origStart'] = $start; $event['icon'] = $icon; $event['realType'] = $event['type'] = $type; + $event['TypeName'] = $eventTypeName; + $event['GroupName'] = $eventGroupName; + $event['CalendarName'] = $eventCalendarName; + $event['Rights'] = $eventRights; + + if ($status == _('No')) { + $event['Status'] = ''.$status.''; + } else { + $event['Status'] = ''.$status.''; + } + + // only for v2/calendar/events/list + $event['RealStats'] = ''; + + if (!empty($realStats)) { + $ret = ''; + + if ($realStats['attNumRows']) { + $ret = '' + . '' + . ' ' + . ' ' + . ' ' + . '' + . '' + . ' ' + . ' ' + . ' ' + . '' + . '' + . ' ' + . '' + . '
' . _("Check-in") . '' . _("Check-out") . '' . _("Rest") . '
' . $realStats['attNumRows'] . '' . $realStats['attCheckOut'] . '' . $realStats['attNumRows'] - $realStats['attCheckOut'] . '
' + . ' ' + . ' ' + . ' ' + . ' ' + . ' ' + . '
'; + + if ($eventRights) { + $ret .= '
'; + } + + $ret .= ' ' + . ' ' + . ' ' + . ' ' + . ' '; + + if ($eventRights) { + $ret .= '
'; + } + + $ret .= '
'; + + + if ($eventRights) { + $ret .= '
'; + } + + $ret .= ' ' + . ' '; + + if ($eventRights) { + $ret .= '
'; + } + + $ret .= '
' + . '
'; + } else { + $ret .= '
' + . ' ' + . ' ' + . ' ' + . ' ' + . '' ._('No Attendance Recorded') . '
' + . ' ' + . '
'; + + } + + $event['RealStats'] = $ret; + } + + + // only for v2/calendar/events/list + $event['FreeStats'] = ''; + + if ( !empty($freeStats) ) { + $ret = '' + . ''; + + if ( !empty($freeStats) ) { + foreach ($freeStats as $freeStat) { + $ret .= ''; + } + } else { + $ret .= ''; + } + + $ret .= '' + .'
' + . '
' . $freeStat['cCountName'] . '
' + . '
' . $freeStat['cCount'] . '
' + . '
' + . '

' + . _('No Attendance Recorded') + . '

' + . '
'; + + $event['FreeStats'] = $ret; + } + + // end of : for v2/calendar/events/list only + + if (SessionUser::getUser()->isAdmin()) { + $event['Login'] = _("login") . " : " . str_replace("principals/", "", $loginName) . ""; + } else { + $event['Login'] = ""; + } if ($end != '') { $event['end'] = $end; @@ -302,6 +560,18 @@ public function createCalendarItemForGetEvents($type, $icon, $title, $start, $en $event['calType'] = intval($cal_type); $event['cal_category'] = $cal_category; + switch ($cal_category) { + case 'personal': + $event['cal_category_translated'] = _("Personal Calendar"); + break; + case 'group': + $event['cal_category_translated'] = _("Group"); + break; + case 'share': + $event['cal_category_translated'] = _("Share"); + break; + } + if ($calendarid != null) { $event['calendarID'] = $calendarid;//[$calendarid[0],$calendarid[1]];//$calendarid; } @@ -599,7 +869,7 @@ public function modifyEventFromCalendar($calendarID, $eventID, $reccurenceID, $s $freqEventsCount = count($eventFullInfos['freqEvents']); } - if ( isset($reccurenceID) && $reccurenceID != '' ) {// we're in a recursive event + if (isset($reccurenceID) && $reccurenceID != '') {// we're in a recursive event try { // we have to delete the old event from the reccurence event diff --git a/src/EcclesiaCRM/VIEWControllers/VIEWCalendarController.php b/src/EcclesiaCRM/VIEWControllers/VIEWCalendarController.php index ef5e48eee6..0fc8fcf1b6 100644 --- a/src/EcclesiaCRM/VIEWControllers/VIEWCalendarController.php +++ b/src/EcclesiaCRM/VIEWControllers/VIEWCalendarController.php @@ -15,13 +15,22 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use EcclesiaCRM\EventQuery; use EcclesiaCRM\EventTypesQuery; + +use EcclesiaCRM\Map\EventTypesTableMap; +use EcclesiaCRM\Map\EventTableMap; + use EcclesiaCRM\dto\ChurchMetaData; use EcclesiaCRM\Utils\OutputUtils; use EcclesiaCRM\dto\SystemConfig; use EcclesiaCRM\dto\SystemURLs; use EcclesiaCRM\SessionUser; + +use Propel\Runtime\ActiveQuery\Criteria; + + use Slim\Views\PhpRenderer; class VIEWCalendarController { @@ -69,4 +78,61 @@ public function argumentsCalendarArray () return $paramsArguments; } + public function renderCalendarEventsList (ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface { + $renderer = new PhpRenderer('templates/calendar/'); + + return $renderer->render($response, 'eventslist.php', $this->argumentsCalendarEventsListArray()); + } + + public function argumentsCalendarEventsListArray () + { + $eventTypes = EventTypesQuery::Create() + ->addJoin(EventTypesTableMap::COL_TYPE_ID, EventTableMap::COL_EVENT_TYPE,Criteria::RIGHT_JOIN) + ->setDistinct(EventTypesTableMap::COL_TYPE_ID) + ->orderById() + ->find(); + + + // year selector + $eType = 'All'; + + if ($eType == 'All') { + $years = EventQuery::Create() + ->addAsColumn('year', 'YEAR(' . EventTableMap::COL_EVENT_START . ')') + ->select('year') + ->setDistinct() + ->where('YEAR(' . EventTableMap::COL_EVENT_START . ')') + ->find(); + } + + $yVal = date('Y'); + + $lat = OutputUtils::number_dot(ChurchMetaData::getChurchLatitude()); + $lng = OutputUtils::number_dot(ChurchMetaData::getChurchLongitude()); + + $iLittleMapZoom = SystemConfig::getValue("iLittleMapZoom"); + $sMapProvider = SystemConfig::getValue('sMapProvider'); + $sGoogleMapKey = SystemConfig::getValue('sGoogleMapKey'); + + $sPageTitle = _('Listing All Church Events'); + + $paramsArguments = ['sRootPath' => SystemURLs::getRootPath(), + 'sRootDocument' => SystemURLs::getDocumentRoot(), + 'sPageTitle' => $sPageTitle, + 'eventTypes' => $eventTypes, + 'eType' => $eType, + 'yVal' => $yVal, + 'years' => $years, + 'coordinates' => [ + 'lat' => $lat, + 'lng' => $lng + ], + 'iLittleMapZoom' => $iLittleMapZoom, + 'sGoogleMapKey' => $sGoogleMapKey, + 'sMapProvider' => $sMapProvider, + 'sessionUsr' => SessionUser::getUser() + ]; + + return $paramsArguments; + } } diff --git a/src/EditEventAttendees.php b/src/EditEventAttendees.php index ea681f47d2..d9c7f872d0 100644 --- a/src/EditEventAttendees.php +++ b/src/EditEventAttendees.php @@ -173,7 +173,7 @@ class="btn btn-
- + diff --git a/src/api/routes/calendar/calendar-calendarV2.php b/src/api/routes/calendar/calendar-calendarV2.php index f3e64c9e81..69e0a5cf40 100644 --- a/src/api/routes/calendar/calendar-calendarV2.php +++ b/src/api/routes/calendar/calendar-calendarV2.php @@ -20,6 +20,12 @@ * #! param: ref->end :: the end date : YYYY-MM-DD */ $group->post('/getallevents', CalendarV2Controller::class . ':getallCalendarEvents' ); + /* + * @! Get all events for all calendars for a specified range + * #! param: ref->start :: the start date : YYYY-MM-DD + * #! param: ref->end :: the end date : YYYY-MM-DD + */ + $group->post('/getalleventsForEventsList', CalendarV2Controller::class . ':getallCalendarEventsForEventsList' ); /* * @! get all the number of calendar for the current user */ diff --git a/src/index.php b/src/index.php index 9c50ffbe5c..7dfc14a733 100644 --- a/src/index.php +++ b/src/index.php @@ -34,7 +34,7 @@ function endsWith($haystack, $needle) $redirectTo = ($hasSession) ? '/v2/dashboard' : '/login'; // Get the current request path and convert it into a magic filename -// e.g. /list-events => /ListEvents.php +// e.g. /list-events => /v2/calendar/events/list $shortName = str_replace(SystemURLs::getRootPath().'/', '', $_SERVER['REQUEST_URI']); $fileName = dashesToCamelCase($shortName, true).'.php'; diff --git a/src/skin/js/CRMJSOM.js b/src/skin/js/CRMJSOM.js index 2e4013dd70..1f7d7a7a23 100644 --- a/src/skin/js/CRMJSOM.js +++ b/src/skin/js/CRMJSOM.js @@ -189,7 +189,7 @@ 'emptyCartToEvent' : function () { window.CRM.cart.emptytoEvent(function(data){ window.CRM.cart.refresh(); - location.href = window.CRM.root + '/ListEvents.php'; + location.href = window.CRM.root + '/v2/calendar/events/list'; }); }, 'emptyCartToGroup' : function () { @@ -1568,7 +1568,7 @@ if (window.CRM.attendeesPresences == false) { window.CRM.notify('fa fa-info-circle', "" + data.EventCountAttend + " " + i18next.t("Attendees Checked In") + ".", - "
" + i18next.t("More info") + ' ' + '', + "
" + i18next.t("More info") + ' ' + '', null, "warning", "bottom", Math.min(window.CRM.iDashboardPageServiceIntervalTime * 1000, window.CRM.timeOut), '_blank', diff --git a/src/skin/js/calendar/EventEditor.js b/src/skin/js/calendar/EventEditor.js index 00a1bc597b..f316e1762d 100644 --- a/src/skin/js/calendar/EventEditor.js +++ b/src/skin/js/calendar/EventEditor.js @@ -909,7 +909,6 @@ function createEventEditorWindow(start, end, dialogType, eventID, reccurenceID, }) }).done(function (data) { - if (data.status == "failed") { add = false; @@ -925,8 +924,8 @@ function createEventEditorWindow(start, end, dialogType, eventID, reccurenceID, eventCreated = true; } - if ( page.includes("ListEvent.php") ) { - location.reload(); + if (page.includes("v2/calendar/events/list") ) { + window.CRM.reloadListEventPage(); } else if ( page.includes("Checkin.php") ) { window.location.href = window.CRM.root + '/Checkin.php'; } else if (page.includes("/v2/calendar")) { diff --git a/src/skin/js/calendar/EventsList.js b/src/skin/js/calendar/EventsList.js new file mode 100644 index 0000000000..63ce0d5d61 --- /dev/null +++ b/src/skin/js/calendar/EventsList.js @@ -0,0 +1,500 @@ +$(document).ready(function () { + moment.locale(window.CRM.shortLocale); + + window.CRM.fmt = ""; + + if (window.CRM.timeEnglish == true) { + window.CRM.fmt = window.CRM.datePickerformat.toUpperCase() + ' hh:mm a'; + } else { + window.CRM.fmt = window.CRM.datePickerformat.toUpperCase() + ' HH:mm'; + } + + var DataEventsListTable = { + ajax: { + url: window.CRM.root + "/api/calendar/getalleventsForEventsList", + type: 'POST', + contentType: "application/json", + dataSrc: "EventsListResults", + data: function (json) { + var search_Term = $("#SearchTerm").val(); + + if (search_Term !='') { + $('.in-progress').css("color", "red"); + $('.in-progress').html(" "+ i18next.t("In progress....")); + } + + return JSON.stringify({ + "start": window.CRM.yVal + '-01-01', + "end" : window.CRM.yVal + '-12-31', + "isBirthdayActive": false, + "isAnniversaryActive": false, + "forEventslist": true}); + } + }, + rowGroup: { + dataSrc: 'month', + startRender: function(rows, group) { + var oneDate = moment('02-' + group + '-2021', 'DD-MM-YYYY'); + return rows.count() + ' ' + ((rows.count()>1)?i18next.t('Events for'):i18next.t('Event for')) + ' ' + ' : ' + oneDate.format('MMMM'); + } + }, + "pageLength": 20000, + "language": { + "url": window.CRM.plugin.dataTable.language.url + }, + "searching": true, + "initComplete": function( settings, json ) { + $('.in-progress').css("color", "green"); + $('.in-progress').html(" "+ i18next.t("Loading finished....")); + }, + //"deferRender": true, + //orderFixed: [3, 'asc'], + columns: [ + { + width: 'auto', + title: i18next.t('Month'), + visible: true, + data: 'month', + render: function (data, type, full, meta) { + var oneDate = moment('02-' + full.month + '-2021', 'DD-MM-YYYY'); + return oneDate.format('MMMM'); + } + }, + { + width: 'auto', + title: i18next.t('Actions'), + visible: true, + data: 'icon', + render: function (data, type, full, meta) { + //full.backgroundColor + return '\n' + + ' \n' + + ' \n' + + ' \n' + + ' \n' + + ' \n' + + '
\n' + + ' \n' + + ' \n' + + ' \n' + + ' \n' + + ' \n' + + '
'; + } + }, + { + width: 'auto', + title: i18next.t('Title') + ' (' + i18next.t('Desc') + ')', + data: 'title', + render: function (data, type, full, meta) { + var ret = data; + + if ( full.Desc != '') { + ret += "
(" + full.Desc + ")"; + } + return ret; + } + }, + { + width: 'auto', + title: i18next.t('Calendar'), + data: 'CalendarName', + render: function (data, type, full, meta) { + return i18next.t('Name') + ' : ' + data + "
"+ + full.Login; + + } + }, + { + width: 'auto', + title: i18next.t('Attendance Counts with real Attendees'), + data: 'RealStats', + render: function (data, type, full, meta) { + return data; + + } + }, + { + width: 'auto', + title: i18next.t('Free Attendance Counts without Attendees'), + data: 'FreeStats', + render: function (data, type, full, meta) { + return data; + + } + }, + { + width: 'auto', + title: i18next.t('Start Date'), + visible: true, + data: 'start', + render: function (data, type, full, meta) { + return moment(data).format(window.CRM.fmt); + } + }, + { + width: 'auto', + title: i18next.t('End Date'), + visible: true, + data: 'start', + render: function (data, type, full, meta) { + return moment(data).format(window.CRM.fmt); + } + }, + { + width: 'auto', + title: i18next.t('Event Type'), + data: 'TypeName', + visible: false, + render: function (data, type, full, meta) { + return data; + } + }, + { + width: 'auto', + title: i18next.t('Calendar Type'), + data: 'cal_category_translated', + visible: false, + render: function (data, type, full, meta) { + return data; + } + }, + { + width: 'auto', + title: i18next.t('Active'), + data: 'Status', + visible: true, + render: function (data, type, full, meta) { + return data; + } + } + ] + }; + + $.extend(DataEventsListTable,window.CRM.plugin.dataTable); + + // add the date time filter + $.fn.dataTable.moment(window.CRM.fmt); + + // create the table + window.CRM.DataEventsListTable = $("#DataEventsListTable").DataTable(DataEventsListTable); + + // filter by month correctelly + window.CRM.DataEventsListTable + .order( [ 6, 'desc' ] ) + .draw(); + + // the function to reload the datas in the table + window.CRM.reloadListEventPage = function() { + window.CRM.DataEventsListTable.ajax.reload(function (){ + $('.in-progress').css("color", "green"); + $('.in-progress').html(" "+ i18next.t("Loading finished....")); + + window.CRM.DataEventsListTable + .order( [ 6, 'desc' ] ) + .draw(); + }); + } + + // the actions + $("#YearSelector").change(function() { + window.CRM.yVal = $(this).val(); + + $("#main-Title-events").html(i18next.t('Events in Year') + " : " + window.CRM.yVal); + + window.CRM.reloadListEventPage(); + }); + + $("#MonthSelector").change(function() { + if (this.value == 'all') { + window.CRM.DataEventsListTable.search( "" ).draw(); + $("#main-Title-events").html(i18next.t('Events in Year') + " : " + window.CRM.yVal); + } else { + window.CRM.DataEventsListTable.search(this.value).draw(); + $("#main-Title-events").html(i18next.t('Events in month') + " : " + this.value); + } + }); + + $("#EventTypeSelector").change(function() { + if (this.value == 'all') { + window.CRM.DataEventsListTable.search( "" ).draw(); + $("#main-Title-events").html(i18next.t('Events in Year') + " : " + window.CRM.yVal); + } else { + window.CRM.DataEventsListTable.search(this.value).draw(); + $("#main-Title-events").html(i18next.t('Events by Type') + " : " + this.value); + } + }); + + $(document).on("click", ".EditEvent", function () { + var eventID = $(this).data("id"); + + window.CRM.APIRequest({ + method: 'POST', + path: 'events/info', + data: JSON.stringify({"eventID":eventID}) + }).done(function(calEvent) { + if (window.CRM.editor != null) { + CKEDITOR.remove(window.CRM.editor); + window.CRM.editor = null; + } + + modal = createEventEditorWindow (calEvent.start,calEvent.end,'modifyEvent',eventID,'','v2/calendar/events/list'); + + $('form #EventTitle').val(calEvent.Title); + $('form #EventDesc').val(calEvent.Desc); + $('form #eventNotes').val(calEvent.Text); + $('form #EventLocation').val(calEvent.location); + + $("form #addGroupAttendees").prop("disabled", (calEvent.groupID == "0") ? true : false); + $("form #addGroupAttendees").prop('checked', (calEvent.groupID == "0") ? false : true); + + + if (calEvent.alarm !== null) { + $("form #EventAlarm").val(calEvent.alarm.trigger).trigger('change'); + } + + // we add the calendars and the types + addCalendars(calEvent.calendarID); + addCalendarEventTypes(calEvent.eventTypeID,false); + addAttendees(calEvent.eventTypeID,true,calEvent.eventID); + setActiveState(calEvent.inActive); + + //Timepicker + $('.timepicker').datetimepicker({ + format: 'LT', + locale: window.CRM.lang, + icons: + { + up: 'fa fa-angle-up', + down: 'fa fa-angle-down' + } + }); + + $('.date-picker').datepicker({format:window.CRM.datePickerformat, language: window.CRM.lang}); + + $('.date-picker').click('focus', function (e) { + e.preventDefault(); + $(this).datepicker('show'); + }); + + $('.date-start').hide(); + $('.date-end').hide(); + $('.date-recurrence').hide(); + $(".eventNotes").hide(); + + var theme = 'n1theme,/skin/js/ckeditor/themes/n1theme/'; + if (window.CRM.bDarkMode) { + theme = 'moono-dark,/skin/js/ckeditor/themes/moono-dark/'; + } + + // this will create the toolbar for the textarea + if (window.CRM.editor == null) { + if (window.CRM.bEDrive) { + window.CRM.editor = CKEDITOR.replace('eventNotes',{ + customConfig: window.CRM.root+'/skin/js/ckeditor/configs/calendar_event_editor_config.js', + language : window.CRM.lang, + width : '100%', + extraPlugins : 'uploadfile,uploadimage,filebrowser', + uploadUrl: window.CRM.root+'/uploader/upload.php?type=publicDocuments', + imageUploadUrl: window.CRM.root+'/uploader/upload.php?type=publicImages', + filebrowserUploadUrl: window.CRM.root+'/uploader/upload.php?type=publicDocuments', + filebrowserBrowseUrl: window.CRM.root+'/browser/browse.php?type=publicDocuments', + skin:theme + }); + } else { + window.CRM.editor = CKEDITOR.replace('eventNotes',{ + customConfig: window.CRM.root+'/skin/js/ckeditor/configs/calendar_event_editor_config.js', + language : window.CRM.lang, + width : '100%', + skin:theme + }); + } + + add_ckeditor_buttons(window.CRM.editor); + } + + $(".ATTENDENCES").hide(); + + modal.modal("show"); + + initMap(calEvent.longitude,calEvent.latitude,calEvent.title+'('+calEvent.Desc+')',calEvent.location,calEvent.title+'('+calEvent.Desc+')',calEvent.Text); + }); + }); + + $(document).on("click", ".DeleteEvent", function () { + var eventID = $(this).data("id"); + var calendarID = $(this).data("calendarid").split(','); + var recurrent = $(this).data("recurrent"); + var reccurenceID = $(this).data("reccurenceid"); + var dateStart = $(this).data("datestart"); + + + var box = bootbox.dialog({ + title: i18next.t("Modify Event"), + message: i18next.t("What would you like to do ? Be careful with the deletion, it's impossible to revert !!!"), + size: 'large', + buttons: { + delete: { + label: ' ' + i18next.t("Delete Event"), + className: 'btn btn-danger', + callback: function () { + if (recurrent == 0) { + bootbox.confirm(i18next.t("Are you sure to delete this event?"), function (confirmed) { + if (confirmed) { + window.CRM.APIRequest({ + method: 'POST', + path: 'events/', + data: JSON.stringify({ + "calendarID": calendarID, + "eventAction": 'suppress', + "eventID": eventID + }) + }).done(function (data) { + if (data.status == "failed") { + window.CRM.DisplayNormalAlert(i18next.t("Error"), data.message); + } + window.CRM.reloadListEventPage(); + }); + } + }); + } else if (recurrent == 1) { + var reccurenceID = moment(reccurenceID).format(fmt); + + var box = bootbox.dialog({ + title: i18next.t("Delete all repeated Events"), + message: i18next.t("You are about to delete all the repeated Events linked to this event. Are you sure? This can't be undone."), + buttons: { + cancel: { + label: i18next.t('No'), + className: 'btn btn-success' + }, + add: { + label: i18next.t('Only this event'), + className: 'btn btn-info', + callback: function () { + window.CRM.APIRequest({ + method: 'POST', + path: 'events/', + data: JSON.stringify({ + "calendarID": calendarID, + "eventAction": 'suppress', + "eventID": eventID, + "dateStart": dateStart, + "reccurenceID": reccurenceID + }) + }).done(function (data) { + if (data.status == "failed") { + window.CRM.DisplayNormalAlert(i18next.t("Error"), data.message); + } + window.CRM.reloadListEventPage(); + }); + } + }, + confirm: { + label: i18next.t('Every Events linked to this Event'), + className: 'btn btn-danger', + callback: function () { + window.CRM.APIRequest({ + method: 'POST', + path: 'events/', + data: JSON.stringify({ + "calendarID": calendarID, + "eventAction": 'suppress', + "eventID": eventID + }) + }).done(function (data) { + window.CRM.reloadListEventPage(); + }); + } + } + } + }); + } + } + }, + cancel: { + label: ' ' + i18next.t('Cancel'), + className: 'btn btn-primary', + callback: function () { + } + } + } + }); + + box.show(); + }); + + function BootboxInfo(data) { + var frm_str = data; + var object = $('
').html(frm_str).contents(); + return object + } + + $(document).on("click", ".EventInfo", function () { + var eventID = $(this).data("id"); + + window.CRM.APIRequest({ + method: 'POST', + path: 'events/info', + data: JSON.stringify({ + "eventID": eventID + }) + }).done(function (data) { + var box = bootbox.dialog({ + title: i18next.t("Text for Event ID") + " (" + data.eventID + ") : " + data.Title, + message: BootboxInfo(data.Text), + size: 'extra-large', + buttons: { + ok: { + label: ' ' + i18next.t("Ok"), + className: 'btn btn-primary', + } + } + }); + }); + }); + + // the main add event button + $('#add-event').click('focus', function (e) { + var fmt = 'YYYY-MM-DD HH:mm:ss'; + + var dateStart = moment().format(fmt); + var dateEnd = moment().format(fmt); + + window.CRM.APIRequest({ + method: 'POST', + path: 'calendar/numberofcalendars', + }).done(function(data) { + if (data.CalendarNumber > 0) { + if (window.CRM.editor != null) { + CKEDITOR.remove(window.CRM.editor); + window.CRM.editor = null; + } + + modal = createEventEditorWindow(dateStart, dateEnd, 'createEvent', 0, '', 'v2/calendar/events/list'); + + // we add the calendars and the types + addCalendars(); + addCalendarEventTypes(-1, true); + + // finish installing the window + installAndfinishEventEditorWindow(); + + $("#typeEventrecurrence").prop("disabled", true); + $("#endDateEventrecurrence").prop("disabled", true); + + modal.modal("show"); + + initMap(); + } else { + window.CRM.DisplayAlert(i18next.t("Error"),i18next.t("To add an event, You have to create a calendar or activate one first.")); + } + }); + }); +}); diff --git a/src/v2/routes/calendar/calendar.php b/src/v2/routes/calendar/calendar.php index 81329ad8db..0f1f1fc149 100644 --- a/src/v2/routes/calendar/calendar.php +++ b/src/v2/routes/calendar/calendar.php @@ -7,4 +7,5 @@ $app->group('/calendar', function (RouteCollectorProxy $group) { $group->get('', VIEWCalendarController::class . ':renderCalendar'); $group->get('/', VIEWCalendarController::class . ':renderCalendar'); + $group->get('/events/list', VIEWCalendarController::class . ':renderCalendarEventsList'); }); diff --git a/src/v2/templates/calendar/eventslist.php b/src/v2/templates/calendar/eventslist.php new file mode 100644 index 0000000000..5337e9a478 --- /dev/null +++ b/src/v2/templates/calendar/eventslist.php @@ -0,0 +1,170 @@ + + + + + +
+
+ + +
+
+ + +
+
+ +
+
+ +
+ + +
+
+

:

+
+

+
+
+
+ +
+
+ + +
+ + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +