Forum for discussing general topics related to Couch.
5 posts Page 1 of 1
Hello.

I`m using event calendar (a complete working example - http://www.couchcms.com/docs/concepts/e ... endar.html) to display my events.

Is it possible, in case the event lasts more than one day, to color all cells (user enter the 'end_date') ?

Appreciate your help!

regards, J.
Hello J,

Multi-day events are currently not supported out-of-the-box, I'm afraid.
Hi Jz,

I've found a really ugly way to do it. There are probably way cleaner ways, but I wanted to share my code with you anyway.

First of all, I'm using databound forms. So you would have to replace your admin edit screen with a databound form using this guide: http://www.couchcms.com/docs/concepts/d ... forms.html

Basically it just copies the event for the amount of days the event lasts. In my case I simply ask the user how many days that is. You could probably also calculate how many days an event lasts when a start and end date have been inputted, but that was outside the scope of my work.

This is what the form looks like:

Code: Select all
 <cms:form
            masterpage='calendar.php'
            mode='create'
            enctype='multipart/form-data'
            method='post'
            anchor='0'
            >
         
<cms:if k_success >
         
                <cms:db_persist_form _invalidate_cache='0' k_publish_date="<cms:if frm_my_publish_status='0'>0000-00-00 00:00:00<cms:else/><cms:show frm_my_publish_date /></cms:if> />

<cms:if k_success >
<!-- We'll duplicate the form for the amount of days the event lasts, minus the first day, which is created by the original form.-->
<cms:decr frm_days '1'/>
<!--Here we use the amount of days the event lasts to duplicate forms.-->
<cms:repeat count=frm_days>
<cms:set number=k_count 'global'/>
<!--Start at the day after the original start day.-->
<cms:incr number '1'/>
<cms:set day="<cms:date frm_my_publish_date format='d'/>"/>
<cms:set month="<cms:date frm_my_publish_date format='m'/>"/>
<cms:set year="<cms:date frm_my_publish_date format='Y'/>"/>
<cms:incr day number/>
   <cms:if (month='01')>
      <cms:if day gt '31'>
         <cms:decr day '31'/>
         <cms:incr month '1'/>
      </cms:if>
   </cms:if>
   <cms:if (month='02')>
<!--Define leap years-->
      <cms:if (year="2016")||(year="2020")||(year="2024")||(year="2028")||(year="2032")>
      <cms:if day gt '29'>
            <cms:decr day '29'/>
            <cms:incr month '1'/>
         </cms:if>
      <cms:else/>
         <cms:if day gt '28'>
            <cms:decr day '28'/>
            <cms:incr month '1'/>
         </cms:if>
      </cms:if>
   </cms:if>
   <cms:if (month='03')>
      <cms:if day gt '31'>
         <cms:decr day '31'/>
         <cms:incr month '1'/>
      </cms:if>
   </cms:if>
   <cms:if (month='04')>
      <cms:if day gt '30'>
         <cms:decr day '30'/>
         <cms:incr month '1'/>
      </cms:if>
   </cms:if>
   <cms:if (month='05')>
      <cms:if day gt '31'>
         <cms:decr day '31'/>
         <cms:incr month '1'/>
      </cms:if>
   </cms:if>
   <cms:if (month='06')>
      <cms:if day gt '30'>
         <cms:decr day '30'/>
         <cms:incr month '1'/>
      </cms:if>
   </cms:if>
   <cms:if (month='07')>
      <cms:if day gt '31'>
         <cms:decr day '31'/>
         <cms:incr month '1'/>
      </cms:if>
   </cms:if>
   <cms:if (month='08')>
      <cms:if day gt '31'>
         <cms:decr day '31'/>
         <cms:incr month '1'/>
      </cms:if>
   </cms:if>
   <cms:if (month='09')>
      <cms:if day gt '30'>
         <cms:decr day '30'/>
         <cms:incr month '1'/>
      </cms:if>
   </cms:if>
   <cms:if (month='10')>
      <cms:if day gt '31'>
         <cms:decr day '31'/>
         <cms:incr month '1'/>
      </cms:if>
   </cms:if>
   <cms:if (month='11')>
      <cms:if day gt '30'>
         <cms:decr day '30'/>
         <cms:incr month '1'/>
      </cms:if>
   </cms:if>
   <cms:if (month='12')>
      <cms:if day gt '31'>
         <cms:decr day '31'/>
         <cms:incr month '1'/>
      </cms:if>
   </cms:if>
   <cms:if (month gt '12')>
      
         <cms:incr year '1'/>
      
   </cms:if>
   
<!--Create a duplicate of your fist form with an automatically created title.-->
   <cms:form
            masterpage='calender.php'
            mode='create'
            enctype='multipart/form-data'
            method='post'
            anchor='0'
            >
      <cms:db_persist_form
                _invalidate_cache='0'
      k_publish_date="<cms:show year/>-<cms:show month/>-<cms:show day/>"
                 start_time=frm_start_time
      end_time=frm_end_time
    location=frm_location
       _auto_title='1'
   duplicate="true"
    />
   
            <cms:hide>
            <cms:input type="bound" name="start_time"/>
            <cms:input type="bound" name="end_time"/>
            <cms:input type="bound" name="location"/>
            <cms:input type="bound" name="duplicate"/>
            </cms:hide>
   </cms:form>   
</cms:repeat>
<cms:redirect k_page_link />
               
                </cms:if>
            </cms:if>
         


   <cms:input type="bound" name="k_page_title"  /><br/>
   
   <cms:input type="bound" name="location"/><br/>
   
   
   <cms:input
                    name='my_publish_date'
                    type='datetime'
                    format='dmy'
                    fields_separator=','
                    default_time="<cms:if k_mode='edit' && k_page_date!='0000-00-00 00:00:00'><cms:show k_page_date /><cms:else />@current</cms:if>"
                    required='1'
                />

   <cms:input type="bound" name="start_time"/><br/>

   <cms:input type="bound" name="end_time"/><br/>

<!--Ask the number of days the event lasts-->
<cms:input type="bound" name="days"/>

            <cms:if "<cms:not submit_success />" >
                <input type="submit" name="submit" value="Save"/>
            </cms:if>

   </cms:form>


Good luck!
Oh and off course for creating a coloured day display. Simply copy the "<cms:entries></cms:entries> tag in the calendar" and add an element with background color to it. Also give the element a "z-index:-1" in css, so elements included in the next "entries-tag" will be upfront.
A snippet of your new calendar code:
Code: Select all
<cms:if k_position='current_month' >
                              <cms:if k_count_entries >
                                 <!--Elements with background colour here-->
                                    </cms:entries>
                                    <cms:entries>
                                       <!--standard elements to dispaly a single day event here-->
                                       
                                    </cms:entries>
                                    </ul>
                                 </td>
                              <cms:else />
                                 <td class='<cms:show tdclass />' ><cms:show k_day /></td>
                              </cms:if>
Does this work on v2.2 as I tried it and got the following error

ERROR! Closing tag "if" has no matching opening tag (line: 110 char: 6967)
5 posts Page 1 of 1