<?php
  header("Content-Type: application/rss+xml; charset:UTF-8;");
  include '../../datasource.php';
  include '../constants.php';
  include_once $root . '/lib/fileUtils.php';
  include $root . '/CMSAdmin/modules/event/eventManager.php';
  if (!empty($_REQUEST['lang'])) {$language = $_REQUEST['lang'];}
  if (file_exists($root . '/'.$siteFolder.'/resources/resources_' . $language . '.php')){ include_once $root . '/'.$siteFolder.'/resources/resources_' . $language . '.php'; } else { include_once $root . '/'.$siteFolder.'/resources/resources_en.php';  $language = 'en';  }
  if (file_exists($root . '/'.$siteFolder.'/resources/countries_' . $language . '.php')){ include_once $root . '/'.$siteFolder.'/resources/countries_' . $language . '.php'; } else { include_once $root . '/'.$siteFolder.'/resources/countries_en.php';}
  $category = 'daca4ee557fc675ec608c158aa1635ad';
  $eventsArray = getAllSiteEvent($siteId, $language, 'D.PublishStartDate', 'DESC');
  //$eventsArray = getLastPublishedTaxonomyNodeEvents ($category,$language,10000);
  echo '<?xml version="1.0" encoding="utf-8"?>'."\n";
?>
<rss version="2.0"  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>MILSET Activities</title>
  <link>https://www.milset.org</link>
  <description><![CDATA[The International Movement for Leisure Activities in Science and Technology]]></description>
  <atom:link href="<?=$_SERVER['SCRIPT_URI']?>" rel="self" type="application/rss+xml" />
  <language>en-us</language>
  <copyright>MILSET</copyright>
  <image>
    <url>https://www.milset.org/design/images/milset.png</url>
    <title>MILSET Activities</title>
    <link>https://www.milset.org</link>
  </image>
<?php
$filteredList = getFilterList($filteredcategories);
foreach ($eventsArray as $event) {
  if (in_array($event->id,$filteredList)) continue;
  if ($event->isProd == 0) continue;
    $filename = null;
    if (isset($event->image) && $event->image != null && $event->image != '') {
      $filename = 'https://www.milset.org/tools/thumb/phpThumb.php?src=/modules/event/library/global/' . $event->id . '/' . getFileName($event->image, '_prod').'&amp;w=100';
    }
    $guid = 'https://www.milset.org/' . $language.'/activities.html?detail='.$event->id.'&lang='.$language;
    if ($event->htmlContent != null && $event->htmlContent != '') {
      $link = $guid;
    } else {
      $link = $event->website;
    }
    if ($link == '') $link = $guid;

    $dateArray = explode("-", $event->publishStartDate);
    $eventDate = date("D, d M Y H:i:s O", mktime(12, 0, 0, $dateArray[1], $dateArray[2], $dateArray[0]));


    $description = "<b>$event->title</b>\n<br>";
    if (!is_null($filename)) {
                                                                                                        $description .= '<img src="'.$filename.'" style="float:right;border: 0px;" width="100"><br>'."\n";
    }
    
    $flagseparator = true;

    $description .= '<br/>Date';
    if (!empty($event->publishEndDate) && $event->publishEndDate != $event->publishStartDate) {
      $description .= 's: ';
    } else {
      $description .= ': ';
    }
    $description .= date("d/m/Y", strtotime($event->publishStartDate));
    if (isset($event->eventStartTime) && $event->eventStartTime != '') {
      $description .= ' '.date("H:i", strtotime($event->eventStartTime));
      if (isset($event->eventEndTime) && $event->eventEndTime != '') {
        $description .= $RESOURCES['common.separator'].date("H:i", strtotime($event->eventEndTime));
      }
      $flagseparator = false;
    }
    if (isset($event->publishEndDate) && $event->publishEndDate != '' && $event->publishEndDate != null && $event->publishEndDate != $event->publishStartDate) {
        if ($flagseparator) $description .= $RESOURCES['common.separator']; else $description .= " ";
        $description .= date("d/m/Y", strtotime($event->publishEndDate));
    }
    $eventOwner = "\n".'<br/>Organiser';
    if (strpos($event->organiser,',')>0) {
      $eventOwner .= 's: '.$event->organiser;
    } else {
      $eventOwner .= ': '.$event->organiser;
    }
    
    if (isset($event->organiser) && $event->organiser != '' && $event->organiser != null)               $description .= $eventOwner;
    if ((isset($event->place) && $event->place != '' && $event->place != null) || (isset($event->country) && $event->country != '' && $event->country != null)){ 
                                                                                                        $description .= "\n".'<br>'.$RESOURCES ['event.edit.place'].$RESOURCES ['event.edit.separator'];
        if (isset($event->place) && $event->place != '' && $event->place != null)                       $description .= $event->place;
        if ((isset($event->place) && $event->place != '' && $event->place != null) && (isset($event->country) && $event->country != '' && $event->country != null)) 
                                                                                                        $description .= ', ';
        if (isset($event->country) && $event->country != '' && $event->country != null)                 $description .= $event->country;
    }
    if (isset($event->number) && $event->number != '' && $event->number != null)                         $description .= "\n".'<br>'.$RESOURCES ['event.edit.number'].$RESOURCES ['event.edit.separator'].$event->number;
    if (isset($event->level) && $event->level != '' && $event->level != null){
      $eventLevelLabel = 'event.edit.level.'.$event->level;
                                                                                                        $description .= "\n".'<br>'.$RESOURCES ['event.edit.level'].$RESOURCES ['event.edit.separator'].$RESOURCES [$eventLevelLabel];
    }
    if (isset($event->age) && $event->age != '' && $event->age != null)                                 $description .= "\n".'<br>'.$RESOURCES ['event.edit.age'].$RESOURCES ['event.edit.separator'].$event->age;
    if (isset($event->eventLanguage) && $event->eventLanguage != '' && $event->eventLanguage != null)   $description .= "\n".'<br>'.$RESOURCES ['event.edit.eventLanguage'].$RESOURCES ['event.edit.separator'].$event->eventLanguage;
    if (isset($event->participation) && $event->participation != '' && $event->participation != null)   $description .= "\n".'<br>'.$RESOURCES ['event.edit.participation'].$RESOURCES ['event.edit.separator'].$event->participation;
    if (isset($event->fee) && $event->fee != '' && $event->fee != null)                                 $description .= "\n".'<br>'.$RESOURCES ['event.edit.fee'].$RESOURCES ['event.edit.separator'].$event->fee;
    if (isset($event->abstract) && $event->abstract != '' && $event->abstract != null)                   $description .= "\n".'<br>'.$event->abstract;
    if (isset($event->contact) && $event->contact != '' && $event->contact != null)                     $description .= "\n".'<br>'.$RESOURCES ['event.edit.contact'].$RESOURCES ['event.edit.separator'].$event->contact;
?>
  <item>
    <title><![CDATA[<?=$event->title?>]]></title>
    <link><![CDATA[<?=$link?>]]></link>
    <guid><![CDATA[<?=$guid?>]]></guid>
    <pubDate><?=$eventDate?></pubDate>
    <description><![CDATA[<?=$description?>]]></description>
  </item>
<?php
  }
?>
</channel>
</rss>
<?php
/*  if (!is_null($filename)) {
?>
    <media:thumbnail   url="<?=$filename?>"/>
    <media:content     url="<?=$filename?>"/>
<?php }*/ ?>