function getStamp($params)
    {
        // iCthumb generator pre-settings
        include_once JPATH_ROOT . '/media/com_icagenda/scripts/icthumb.php';
        $iC_params = JComponentHelper::getParams('com_icagenda');
        // Check if GD is enabled on the server
        if (extension_loaded('gd') && function_exists('gd_info')) {
            $thumb_generator = $iC_params->get('thumb_generator', 1);
        } else {
            $thumb_generator = 0;
        }
        $timeformat = '1';
        $timeformat = $iC_params->get('timeformat', 1);
        if ($timeformat == 1) {
            $lang_time = 'H:i';
        } else {
            $lang_time = 'h:i A';
        }
        // Check if fopen is allowed
        $fopen = true;
        $result = ini_get('allow_url_fopen');
        if (empty($result)) {
            $fopen = false;
        }
        $this->start($params);
        // Get the database
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        // Build the query
        $query->select('e.*,
				e.place as place_name,
				c.title as cat_title,
				c.alias as cat_alias,
				c.color as cat_color,
				c.ordering as cat_order
			')->from($db->qn('#__icagenda_events') . ' AS e')->leftJoin($db->qn('#__icagenda_category') . ' AS c ON ' . $db->qn('c.id') . ' = ' . $db->qn('e.catid'));
        // Where State is 'published'
        $where = $db->qn('e.state') . ' = ' . $db->q('1');
        // Where event is 'approved'
        $where .= ' AND ' . $db->qn('e.approval') . ' = ' . $db->q('0');
        // Add filters
        if (isset($this->filter)) {
            foreach ($this->filter as $filter) {
                $where .= $filter;
            }
        }
        // Check Access Levels
        $user = JFactory::getUser();
        $userID = $user->id;
        $userLevels = $user->getAuthorisedViewLevels();
        if (version_compare(JVERSION, '3.0', 'lt')) {
            $userGroups = $user->getAuthorisedGroups();
        } else {
            $userGroups = $user->groups;
        }
        //		$user = JFactory::getUser();
        //		$userLevels = $user->getAuthorisedViewLevels();
        $userAccess = implode(', ', $userLevels);
        if (!in_array('8', $userGroups)) {
            $where .= ' AND ' . $db->qn('e.access') . ' IN (' . $userAccess . ')';
        }
        // Where
        $query->where($where);
        //		$query.=' LIMIT 0, 1000';
        // Run the query
        $db->setQuery($query);
        // Invoke the query
        $res = $db->loadObjectList();
        $days = $this->getDays($this->date_start, 'Y-m-d H:i');
        foreach ($res as $r) {
            // liste dates calendrier
            if (isset($next)) {
                $next = $next;
            } else {
                $next = '';
            }
            $datemultiplelist = $this->getDatelist($r->dates, $next);
            $datelist = $datemultiplelist;
            $AllDates = array();
            if (isset($r->weekdays)) {
                $weekdays = $r->weekdays;
            } else {
                $weekdays = '';
            }
            $weekdays = explode(',', $weekdays);
            $weekdaysarray = array();
            foreach ($weekdays as $wed) {
                array_push($weekdaysarray, $wed);
            }
            if (in_array('', $weekdaysarray)) {
                $arrayWeekDays = array(0, 1, 2, 3, 4, 5, 6);
            } elseif ($r->weekdays) {
                $arrayWeekDays = $weekdaysarray;
            } elseif (in_array('0', $weekdaysarray)) {
                $arrayWeekDays = $weekdaysarray;
            } else {
                $arrayWeekDays = array(0, 1, 2, 3, 4, 5, 6);
            }
            $WeeksDays = $arrayWeekDays;
            // If Single Dates, added to all dates for this event
            $singledates = unserialize($r->dates);
            if (isset($datemultiplelist) and $datemultiplelist != NULL and !in_array('0000-00-00 00:00:00', $singledates)) {
                $AllDates = array_merge($AllDates, $datemultiplelist);
            }
            $StDate = date('Y-m-d H:i', $this->mkttime($r->startdate));
            $EnDate = date('Y-m-d H:i', $this->mkttime($r->enddate));
            $perioddates = $this->getDatesPeriod($StDate, $EnDate);
            $onlyStDate = '';
            if (isset($this->onlyStDate)) {
                $onlyStDate = $this->onlyStDate;
            }
            if (isset($perioddates) and $perioddates != NULL) {
                if ($onlyStDate == 1) {
                    array_push($AllDates, $StDate);
                } else {
                    foreach ($perioddates as $Dat) {
                        if (in_array(date('w', strtotime($Dat)), $WeeksDays)) {
                            $SingleDate = date('Y-m-d H:i', $this->mkttime($Dat));
                            array_push($AllDates, $SingleDate);
                        }
                    }
                }
            }
            rsort($AllDates);
            //liste dates next
            $datemlist = $this->getmlist($r->dates, $next);
            $dateplist = $this->getplist($r->period, $next);
            if ($dateplist) {
                $datelistcal = array_merge($datemlist, $dateplist);
            } else {
                $datelistcal = $datemlist;
            }
            $todaytime = time();
            rsort($datelist);
            rsort($datelistcal);
            // requête Itemid
            $lang = JFactory::getLanguage();
            $langcur = $lang->getTag();
            $langcurrent = $langcur;
            $noidm = '';
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query->select('id AS idm')->from('#__menu')->where("(link = 'index.php?option=com_icagenda&view=list') AND (published > 0) AND (language = '{$langcurrent}')");
            $db->setQuery($query);
            $idm = $db->loadResult();
            $mItemid = $idm;
            if ($mItemid == NULL) {
                $db = JFactory::getDbo();
                $query = $db->getQuery(true);
                $query->select('id AS noidm')->from('#__menu')->where("(link = 'index.php?option=com_icagenda&view=list') AND (published > 0) AND (language = '*')");
                $db->setQuery($query);
                $noidm = $db->loadResult();
                $noidm = $noidm;
            }
            $nolink = '';
            if ($noidm == NULL && $mItemid == NULL) {
                $nolink = 1;
            }
            $iCmenuitem = '';
            $iCmenuitem = $params->get('iCmenuitem');
            if (is_numeric($iCmenuitem)) {
                $lien = $iCmenuitem;
            } else {
                if ($mItemid == NULL) {
                    $lien = $noidm;
                } else {
                    $lien = $mItemid;
                }
            }
            $eventnumber = NULL;
            $eventnumber = $r->id;
            if ($nolink == 1) {
                $urlevent = '#';
            } else {
                $urlevent = JRoute::_('index.php?option=com_icagenda&view=list&layout=event&id=' . (int) $eventnumber . '&Itemid=' . (int) $lien);
            }
            // Gets Short Description limit, set in global options of the component iCagenda
            $limit = JComponentHelper::getParams('com_icagenda')->get('ShortDescLimit', '100');
            // Html tags removal Global Option (component iCagenda) - Short Description
            $Filtering_ShortDesc_Global = JComponentHelper::getParams('com_icagenda')->get('Filtering_ShortDesc_Global', '');
            $HTMLTags_ShortDesc_Global = JComponentHelper::getParams('com_icagenda')->get('HTMLTags_ShortDesc_Global', array());
            // Get Module Option
            $Filtering_ShortDesc_Local = $this->filtering_shortDesc;
            /**
             * START Filtering HTML method
             */
            $limit = is_numeric($limit) ? $limit : false;
            $descdata = $r->desc;
            $desc_full = deleteAllBetween('{', '}', $descdata);
            // Gets length of the short desc, when not filtered
            $limit_not_filtered = substr($desc_full, 0, $limit);
            $text_length = strlen($limit_not_filtered);
            // Gets length of the short desc, after html filtering
            $limit_filtered = preg_replace('/[\\p{Z}\\s]{2,}/u', ' ', $limit_not_filtered);
            $limit_filtered = strip_tags($limit_filtered);
            $text_short_length = strlen($limit_filtered);
            // Sets Limit + special tags authorized
            $limit_short = $limit + ($text_length - $text_short_length);
            // Replaces all authorized html tags with tag strings
            if (empty($Filtering_ShortDesc_Local) && $Filtering_ShortDesc_Global == '1') {
                $desc_full = str_replace('+', '@@', $desc_full);
                $desc_full = in_array('1', $HTMLTags_ShortDesc_Global) ? str_replace('<br>', '+@br@', $desc_full) : $desc_full;
                $desc_full = in_array('1', $HTMLTags_ShortDesc_Global) ? str_replace('<br/>', '+@br@', $desc_full) : $desc_full;
                $desc_full = in_array('1', $HTMLTags_ShortDesc_Global) ? str_replace('<br />', '+@br@', $desc_full) : $desc_full;
                $desc_full = in_array('2', $HTMLTags_ShortDesc_Global) ? str_replace('<b>', '+@b@', $desc_full) : $desc_full;
                $desc_full = in_array('2', $HTMLTags_ShortDesc_Global) ? str_replace('</b>', '@bc@', $desc_full) : $desc_full;
                $desc_full = in_array('3', $HTMLTags_ShortDesc_Global) ? str_replace('<strong>', '@strong@', $desc_full) : $desc_full;
                $desc_full = in_array('3', $HTMLTags_ShortDesc_Global) ? str_replace('</strong>', '@strongc@', $desc_full) : $desc_full;
                $desc_full = in_array('4', $HTMLTags_ShortDesc_Global) ? str_replace('<i>', '@i@', $desc_full) : $desc_full;
                $desc_full = in_array('4', $HTMLTags_ShortDesc_Global) ? str_replace('</i>', '@ic@', $desc_full) : $desc_full;
                $desc_full = in_array('5', $HTMLTags_ShortDesc_Global) ? str_replace('<em>', '@em@', $desc_full) : $desc_full;
                $desc_full = in_array('5', $HTMLTags_ShortDesc_Global) ? str_replace('</em>', '@emc@', $desc_full) : $desc_full;
                $desc_full = in_array('6', $HTMLTags_ShortDesc_Global) ? str_replace('<u>', '@u@', $desc_full) : $desc_full;
                $desc_full = in_array('6', $HTMLTags_ShortDesc_Global) ? str_replace('</u>', '@uc@', $desc_full) : $desc_full;
            } elseif ($Filtering_ShortDesc_Local == '2' || $Filtering_ShortDesc_Global == '' && empty($Filtering_ShortDesc_Local)) {
                $desc_full = '@i@' . $desc_full . '@ic@';
                $limit_short = $limit_short + 7;
            } else {
                $desc_full = $desc_full;
            }
            // Removes HTML tags
            $desc_nohtml = strip_tags($desc_full);
            // Replaces all sequences of two or more spaces, tabs, and/or line breaks with a single space
            $desc_nohtml = preg_replace('/[\\p{Z}\\s]{2,}/u', ' ', $desc_nohtml);
            // Replaces all spaces with a single +
            $desc_nohtml = str_replace(' ', '+', $desc_nohtml);
            if (strlen($desc_nohtml) > $limit_short) {
                // Cuts full description, to get short description
                $string_cut = substr($desc_nohtml, 0, $limit_short);
                // Detects last space of the short description
                $last_space = strrpos($string_cut, '+');
                // Cuts the short description after last space
                $string_ok = substr($string_cut, 0, $last_space);
                // Counts number of tags converted to string, and returns lenght
                $nb_br = substr_count($string_ok, '+@br@');
                $nb_plus = substr_count($string_ok, '@@');
                $nb_bopen = substr_count($string_ok, '@b@');
                $nb_bclose = substr_count($string_ok, '@bc@');
                $nb_strongopen = substr_count($string_ok, '@strong@');
                $nb_strongclose = substr_count($string_ok, '@strongc@');
                $nb_iopen = substr_count($string_ok, '@i@');
                $nb_iclose = substr_count($string_ok, '@ic@');
                $nb_emopen = substr_count($string_ok, '@em@');
                $nb_emclose = substr_count($string_ok, '@emc@');
                $nb_uopen = substr_count($string_ok, '@u@');
                $nb_uclose = substr_count($string_ok, '@uc@');
                // Replaces tag strings with html tags
                $string_ok = str_replace('@br@', '<br />', $string_ok);
                $string_ok = str_replace('@b@', '<b>', $string_ok);
                $string_ok = str_replace('@bc@', '</b>', $string_ok);
                $string_ok = str_replace('@strong@', '<strong>', $string_ok);
                $string_ok = str_replace('@strongc@', '</strong>', $string_ok);
                $string_ok = str_replace('@i@', '<i>', $string_ok);
                $string_ok = str_replace('@ic@', '</i>', $string_ok);
                $string_ok = str_replace('@em@', '<em>', $string_ok);
                $string_ok = str_replace('@emc@', '</em>', $string_ok);
                $string_ok = str_replace('@u@', '<u>', $string_ok);
                $string_ok = str_replace('@uc@', '</u>', $string_ok);
                $string_ok = str_replace('+', ' ', $string_ok);
                $string_ok = str_replace('@@', '+', $string_ok);
                $text = $string_ok;
                // Close html tags if not closed
                if ($nb_bclose < $nb_bopen) {
                    $text = $string_ok . '</b>';
                }
                if ($nb_strongclose < $nb_strongopen) {
                    $text = $string_ok . '</strong>';
                }
                if ($nb_iclose < $nb_iopen) {
                    $text = $string_ok . '</i>';
                }
                if ($nb_emclose < $nb_emopen) {
                    $text = $string_ok . '</em>';
                }
                if ($nb_uclose < $nb_uopen) {
                    $text = $string_ok . '</u>';
                }
                $ic_readmore = '[&#46;&#46;&#46;]';
                $return_text = $text . ' ' . $ic_readmore;
                $descShort = $limit ? $return_text : '';
            } else {
                $desc_full = $desc_nohtml;
                $desc_full = str_replace('@br@', '<br />', $desc_full);
                $desc_full = str_replace('@b@', '<b>', $desc_full);
                $desc_full = str_replace('@bc@', '</b>', $desc_full);
                $desc_full = str_replace('@strong@', '<strong>', $desc_full);
                $desc_full = str_replace('@strongc@', '</strong>', $desc_full);
                $desc_full = str_replace('@i@', '<i>', $desc_full);
                $desc_full = str_replace('@ic@', '</i>', $desc_full);
                $desc_full = str_replace('@em@', '<em>', $desc_full);
                $desc_full = str_replace('@emc@', '</em>', $desc_full);
                $desc_full = str_replace('@u@', '<u>', $desc_full);
                $desc_full = str_replace('@uc@', '</u>', $desc_full);
                $desc_full = str_replace('+', ' ', $desc_full);
                $desc_full = str_replace('@@', '+', $desc_full);
                $descShort = $limit ? $desc_full : '';
            }
            /** END Filtering HTML function */
            /**
             * To be moved to a special library
             */
            // START iCthumb
            // Initialize Vars
            $Image_Link = '';
            $Thumb_Link = '';
            $Display_Thumb = false;
            $No_Thumb_Option = false;
            $Default_Thumb = false;
            $MimeTypeOK = true;
            $MimeTypeERROR = false;
            $Invalid_Link = false;
            $Invalid_Img_Format = false;
            $fopen_bmp_error_msg = false;
            // SETTINGS ICTHUMB
            $FixedImageVar = $r->image;
            // Set if run iCthumb
            if ($FixedImageVar and $thumb_generator == 1) {
                $params_media = JComponentHelper::getParams('com_media');
                $image_path = $params_media->get('image_path', 'images');
                // Set folder vars
                $fld_icagenda = 'icagenda';
                $fld_thumbs = 'thumbs';
                $fld_copy = 'copy';
                // SETTINGS ICTHUMB
                $thumb_width = '100';
                $thumb_height = '200';
                $thumb_quality = '100';
                $thumb_destination = 'themes/w' . $thumb_width . 'h' . $thumb_height . 'q' . $thumb_quality . '_';
                // Get Image File Infos
                $url = $FixedImageVar;
                $decomposition = explode('/', $url);
                // in each parent
                $i = 0;
                while (isset($decomposition[$i])) {
                    $i++;
                }
                $i--;
                $imgname = $decomposition[$i];
                $fichier = explode('.', $decomposition[$i]);
                $imgtitle = $fichier[0];
                $imgextension = strtolower($fichier[1]);
                // fixed 3.1.10
                // Clean file name
                jimport('joomla.filter.output');
                $cleanFileName = JFilterOutput::stringURLSafe($imgtitle) . '.' . $imgextension;
                $cleanTitle = JFilterOutput::stringURLSafe($imgtitle);
                //							$cleanFileName2 = cleanString($imgtitle) . '.' . $imgextension;
                //							$cleanTitle2 = cleanString($imgtitle);
                // Paths to thumbs and copy folders
                $thumbsPath = $image_path . '/' . $fld_icagenda . '/' . $fld_thumbs . '/';
                $copyPath = $image_path . '/' . $fld_icagenda . '/' . $fld_thumbs . '/' . $fld_copy . '/';
                // Image pre-settings
                $imageValue = $FixedImageVar;
                $Image_Link = $FixedImageVar;
                $Invalid_LinkMsg = '<i class="icon-warning"></i><br /><span style="color:red;"><strong>' . JText::_('COM_ICAGENDA_INVALID_PICTURE_LINK') . '</strong></span>';
                $Wrong_img_format = '<i class="icon-warning"></i><br/><span style="color:red;"><strong>' . JText::_('COM_ICAGENDA_NOT_AUTHORIZED_IMAGE_TYPE') . '</strong><br/>' . JText::_('COM_ICAGENDA_NOT_AUTHORIZED_IMAGE_TYPE_INFO') . '</span>';
                $fopen_bmp_error = '<i class="icon-warning"></i><br/><span style="color:red;"><strong>' . JText::_('COM_ICAGENDA_PHP_ERROR_FOPEN_COPY_BMP') . '</strong><br/>' . JText::_('COM_ICAGENDA_PHP_ERROR_FOPEN_COPY_BMP_INFO') . '</span>';
                // Mime-Type pre-settings
                $errorMimeTypeMsg = '<i class="icon-warning"></i><br /><span style="color:red;"><strong>' . JText::_('COM_ICAGENDA_ERROR_MIME_TYPE') . '</strong><br/>' . JText::_('COM_ICAGENDA_ERROR_MIME_TYPE_NO_THUMBNAIL');
                // url to thumbnails already created
                $Thumb_Link = $image_path . '/' . $fld_icagenda . '/' . $fld_thumbs . '/' . $thumb_destination . $cleanFileName;
                $Thumb_aftercopy_Link = $image_path . '/' . $fld_icagenda . '/' . $fld_thumbs . '/' . $thumb_destination . $cleanTitle . '.jpg';
                // Check if thumbnails already created
                if (file_exists(JPATH_ROOT . '/' . $Thumb_Link) and !file_exists(JPATH_ROOT . '/' . $Thumb_aftercopy_Link)) {
                    $Thumb_Link = $Thumb_Link;
                    $Display_Thumb = true;
                } elseif (file_exists(JPATH_ROOT . '/' . $Thumb_aftercopy_Link)) {
                    $Thumb_Link = $Thumb_aftercopy_Link;
                    $Display_Thumb = true;
                } else {
                    if (filter_var($imageValue, FILTER_VALIDATE_URL)) {
                        $linkToImage = $imageValue;
                    } else {
                        $linkToImage = JPATH_ROOT . '/' . $imageValue;
                    }
                    if (file_exists($linkToImage)) {
                        // Test Mime-Type
                        $fileinfos = getimagesize($linkToImage);
                        $mimeType = $fileinfos['mime'];
                        $extensionType = 'image/' . $imgextension;
                        // Message Error Mime-Type info
                        $errorMimeTypeInfo = '<span style="color:black;"><br/>' . JText::sprintf('COM_ICAGENDA_ERROR_MIME_TYPE_INFO', $imgextension, $mimeType);
                        // Error message if Mime-Type is not the same as extension
                        if ($imgextension == 'jpeg' or $imgextension == 'jpg') {
                            if ($mimeType != 'image/jpeg' and $mimeType != 'image/jpg') {
                                $MimeTypeOK = false;
                                $MimeTypeERROR = true;
                            }
                        } elseif ($imgextension == 'bmp') {
                            if ($mimeType != 'image/bmp' and $mimeType != 'image/x-ms-bmp') {
                                $MimeTypeOK = false;
                                $MimeTypeERROR = true;
                            }
                        } else {
                            if ($mimeType != $extensionType) {
                                $MimeTypeOK = false;
                                $MimeTypeERROR = true;
                            }
                        }
                    }
                    // If Error mime-type, no thumbnail creation
                    if ($MimeTypeOK) {
                        // Call function and create image thumbnail for events list in admin
                        // If Image JPG, JPEG, PNG or GIF
                        if ($imgextension == "jpg" or $imgextension == "jpeg" or $imgextension == "png" or $imgextension == "gif") {
                            $Thumb_Link = $Thumb_Link;
                            if (!file_exists(JPATH_ROOT . '/' . $Thumb_Link)) {
                                if (filter_var($imageValue, FILTER_VALIDATE_URL)) {
                                    if (url_exists($imageValue) and $fopen) {
                                        $testFile = JPATH_ROOT . '/' . $copyPath . $cleanFileName;
                                        if (!file_exists($testFile)) {
                                            //Get the file
                                            $content = file_get_contents($imageValue);
                                            //Store in the filesystem.
                                            $fp = fopen(JPATH_ROOT . '/' . $copyPath . $cleanFileName, "w");
                                            fwrite($fp, $content);
                                            fclose($fp);
                                        }
                                        $linkToImage = JPATH_ROOT . '/' . $copyPath . $cleanFileName;
                                        $imageValue = $copyPath . $cleanFileName;
                                    } else {
                                        $linkToImage = $imageValue;
                                    }
                                } else {
                                    $linkToImage = JPATH_ROOT . '/' . $imageValue;
                                }
                                if (url_exists($linkToImage) or file_exists($linkToImage)) {
                                    createthumb($linkToImage, JPATH_ROOT . '/' . $Thumb_Link, $thumb_width, $thumb_height, $thumb_quality);
                                } else {
                                    $Invalid_Link = true;
                                }
                            }
                        } elseif ($imgextension == "bmp") {
                            $Image_Link = $copyPath . $cleanTitle . '.jpg';
                            $Thumb_Link = $Thumb_aftercopy_Link;
                            if (!file_exists(JPATH_ROOT . '/' . $Thumb_Link)) {
                                if (filter_var($imageValue, FILTER_VALIDATE_URL)) {
                                    if (url_exists($imageValue) and $fopen) {
                                        $testFile = JPATH_ROOT . '/' . $copyPath . $cleanTitle . '.jpg';
                                        if (!file_exists($testFile)) {
                                            //Get the file
                                            $content = file_get_contents($imageValue);
                                            //Store in the filesystem.
                                            $fp = fopen(JPATH_ROOT . '/' . $copyPath . $cleanFileName, "w");
                                            fwrite($fp, $content);
                                            fclose($fp);
                                            $imageNewValue = JPATH_ROOT . '/' . $copyPath . $cleanFileName;
                                            imagejpeg(icImageCreateFromBMP($imageNewValue), JPATH_ROOT . '/' . $copyPath . $cleanTitle . '.jpg', 100);
                                            unlink($imageNewValue);
                                        }
                                    } else {
                                        $linkToImage = $imageValue;
                                    }
                                } else {
                                    imagejpeg(icImageCreateFromBMP(JPATH_ROOT . '/' . $imageValue), JPATH_ROOT . '/' . $copyPath . $cleanTitle . '.jpg', 100);
                                }
                                $imageValue = $copyPath . $cleanTitle . '.jpg';
                                $linkToImage = JPATH_ROOT . '/' . $imageValue;
                                if (!$fopen) {
                                    $fopen_bmp_error_msg = true;
                                } elseif (url_exists($linkToImage) or file_exists($linkToImage)) {
                                    createthumb($linkToImage, JPATH_ROOT . '/' . $Thumb_Link, $thumb_width, $thumb_height, $thumb_quality);
                                } else {
                                    $Invalid_Link = true;
                                }
                            }
                        } else {
                            if (url_exists($linkToImage) or file_exists($linkToImage)) {
                                $Invalid_Img_Format = true;
                            } else {
                                $Invalid_Link = true;
                            }
                        }
                        if (!$Invalid_Link) {
                            $Display_Thumb = true;
                        }
                    } else {
                        if ($imgextension == "jpg" or $imgextension == "jpeg" or $imgextension == "png" or $imgextension == "gif" or $imgextension == "bmp") {
                            $MimeTypeERROR = true;
                        } else {
                            $Invalid_Img_Format = true;
                            $MimeTypeERROR = false;
                        }
                    }
                }
            } elseif ($FixedImageVar and $thumb_generator == 0) {
                $No_Thumb_Option = true;
            } else {
                $Default_Thumb = true;
            }
            // END iCthumb
            // Set Thumbnail
            $default_thumbnail = 'media/com_icagenda/images/nophoto.jpg';
            if ($Invalid_Img_Format) {
                $thumb_img = $default_thumbnail;
            }
            if ($Invalid_Link) {
                $thumb_img = $default_thumbnail;
            }
            if ($MimeTypeERROR) {
                $thumb_img = $default_thumbnail;
            }
            if ($fopen_bmp_error_msg) {
                $thumb_img = $default_thumbnail;
            }
            if ($Display_Thumb) {
                $thumb_img = $Thumb_Link;
            }
            if ($No_Thumb_Option) {
                $thumb_img = $FixedImageVar;
            }
            if ($Default_Thumb) {
                if ($r->image) {
                    $thumb_img = $default_thumbnail;
                } else {
                    $thumb_img = '';
                }
            }
            if (!file_exists(JPATH_ROOT . '/' . $Thumb_Link) and $r->image) {
                $thumb_img = $default_thumbnail;
            }
            $evtParams = '';
            $evtParams = new JRegistry($r->params);
            // Display Time
            $dp_time = $params->get('dp_time', 1);
            if ($dp_time == 1) {
                $r_time = true;
            } else {
                $r_time = false;
            }
            // Display City
            $dp_city = $params->get('dp_city', 1);
            if ($dp_city == 1) {
                $r_city = $r->city;
            } else {
                $r_city = false;
            }
            // Display Country
            $dp_country = $params->get('dp_country', 1);
            if ($dp_country == 1) {
                $r_country = $r->country;
            } else {
                $r_country = false;
            }
            // Display Venue Name
            $dp_venuename = $params->get('dp_venuename', 1);
            if ($dp_venuename == 1) {
                $r_place = $r->place_name;
            } else {
                $r_place = false;
            }
            // Display Short Description
            $dp_shortDesc = $params->get('dp_shortDesc', '');
            if (!$dp_shortDesc) {
                $descShort = false;
            } elseif ($dp_shortDesc == 2) {
                $descShort = $r->metadesc;
            }
            // Display Registration Infos
            $dp_regInfos = $params->get('dp_regInfos', 1);
            if ($dp_regInfos == 1) {
                $registered = $this->registered($r->id);
                $maxTickets = $evtParams->get('maxReg');
                $TicketsLeft = $maxTickets - $registered;
            } else {
                $registered = false;
                $maxTickets = false;
                $TicketsLeft = false;
            }
            $event = array('id' => (int) $r->id, 'registered' => (int) $registered, 'maxTickets' => (int) $maxTickets, 'TicketsLeft' => (int) $TicketsLeft, 'Itemid' => (int) $mItemid, 'url' => $urlevent, 'title' => $r->title, 'next' => $this->formatDate($r->next), 'image' => $thumb_img, 'address' => $r->address, 'city' => $r_city, 'country' => $r_country, 'place' => $r_place, 'description' => $r->desc, 'descShort' => $descShort, 'cat_title' => $r->cat_title, 'cat_order' => $r->cat_order, 'cat_color' => $r->cat_color, 'nb_events' => count($r->id), 'no_image' => JTEXT::_('MOD_ICCALENDAR_NO_IMAGE'), 'params' => $r->params);
            // Initialize
            $access = '0';
            $control = '';
            // Access Control
            $user = JFactory::getUser();
            $userLevels = $user->getAuthorisedViewLevels();
            $access = $r->access;
            if ($access == '0') {
                $access = '1';
            }
            if (in_array($access, $userLevels) or in_array('8', $userGroups)) {
                $control = $access;
            }
            // Language Control
            $lang = JFactory::getLanguage();
            $eventLang = '';
            $langTag = '';
            $langTag = $lang->getTag();
            if (isset($r->language)) {
                $eventLang = $r->language;
            }
            if ($eventLang == '') {
                $eventLang = $langTag;
            }
            if ($eventLang == '*') {
                $eventLang = $langTag;
            }
            $events_per_day = array();
            $displaytime = '';
            if (isset($r->displaytime)) {
                $displaytime = $r->displaytime;
            }
            // Get List of Dates
            if ($control == $access) {
                if ($eventLang == $langTag) {
                    if (is_numeric($lien) && is_numeric($eventnumber) && !is_array($lien) && !is_array($eventnumber)) {
                        if (is_array($event)) {
                            foreach ($AllDates as $d) {
                                if ($r_time) {
                                    $time = array('time' => date($lang_time, $this->mkttime($d)), 'displaytime' => $displaytime);
                                } else {
                                    $time = array('time' => '', 'displaytime' => '');
                                }
                                $event = array_merge($event, $time);
                                foreach ($days as $k => $dy) {
                                    if (date('Y-m-d', strtotime($d)) == date('Y-m-d', strtotime($dy['date']))) {
                                        array_push($days[$k]['events'], $event);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        $i = '';
        $lang = JFactory::getLanguage();
        $langcur = $lang->getTag();
        $langcurrent = $langcur;
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select('id AS idm')->from('#__menu')->where("(link = 'index.php?option=com_icagenda&view=list') AND (published > 0) AND (language = '{$langcurrent}')");
        $db->setQuery($query);
        $idm = $db->loadResult();
        $mItemid = $idm;
        if ($mItemid == NULL) {
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query->select('id AS noidm')->from('#__menu')->where("(link = 'index.php?option=com_icagenda&view=list') AND (published > 0) AND (language = '*')");
            $db->setQuery($query);
            $noidm = $db->loadResult();
            $noidm = $noidm;
        }
        $nolink = '';
        if ($noidm == NULL && $mItemid == NULL) {
            $nolink = 1;
        }
        if ($nolink == 1) {
            do {
                echo '<div style="color:#a40505; text-align: center;"><b>info :</b></div><div style="color:#a40505; font-size: 0.8em; text-align: center;">' . JText::_('MOD_ICCALENDAR_COM_ICAGENDA_MENULINK_UNPUBLISHED_MESSAGE') . '</div>';
            } while ($i > 0);
        }
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select('id AS nbevt')->from('`#__icagenda_events` AS e')->where('e.state > 0');
        $db->setQuery($query);
        $nbevt = $db->loadResult();
        $nbevt = count($nbevt);
        if ($nbevt == NULL) {
            //			do {
            echo '<div style="font-size: 0.8em; text-align: center;">' . JText::_('MOD_ICCALENDAR_NO_EVENT') . '</div>';
            //			} while ($i = 0);
        }
        return $days;
    }
                 if (!file_exists($testFile)) {
                     //Get the file
                     $content = file_get_contents($imageValue);
                     //Store in the filesystem.
                     $fp = fopen(JPATH_ROOT . '/' . $copyPath . $cleanFileName, "w");
                     fwrite($fp, $content);
                     fclose($fp);
                     $imageNewValue = JPATH_ROOT . '/' . $copyPath . $cleanFileName;
                     imagejpeg(icImageCreateFromBMP($imageNewValue), JPATH_ROOT . '/' . $copyPath . $cleanTitle . '.jpg', 100);
                     unlink($imageNewValue);
                 }
             } else {
                 $linkToImage = $imageValue;
             }
         } else {
             imagejpeg(icImageCreateFromBMP(JPATH_ROOT . '/' . $imageValue), JPATH_ROOT . '/' . $copyPath . $cleanTitle . '.jpg', 100);
         }
         $imageValue = $copyPath . $cleanTitle . '.jpg';
         $linkToImage = JPATH_ROOT . '/' . $imageValue;
         if (!$fopen) {
             $fopen_bmp_error_msg = true;
         } elseif (url_exists($linkToImage) or file_exists($linkToImage)) {
             createthumb($linkToImage, JPATH_ROOT . '/' . $Thumb_Link, $thumb_width, $thumb_height, $thumb_quality);
         } else {
             $Invalid_Link = true;
         }
     }
 } else {
     if (url_exists($linkToImage) or file_exists($linkToImage)) {
         $Invalid_Img_Format = true;
     } else {