Problems, need help? Have a tip or advice? Post it here.
12 posts Page 1 of 2
Two questions regarding the calendar:

1. The time format displays in 24 hour format. Is it possible to convert the display to 12 hour format without changing the values in <cms:editable name="start_time"> and <cms:editable name="end_time">? Choosing the time in 24 hour format when creating events is fine - I want it to display in the calendar as 12 hour time with am and pm, though.

2. The calendar I'm creating is replacing my client's previous calendar which has about 800 events on it. He'd like to have those imported into the new calendar. If that's even possible, what's the best way to go about it? I can export the events table with phpMyAdmin. Here are the first few lines of data:

-- Dumping data for table `kessler_mssgs`
--

INSERT INTO `kessler_mssgs` (`id`, `uid`, `m`, `d`, `y`, `start_time`, `end_time`, `title`, `text`) VALUES
(20, 2, 4, 16, 2008, '19:30:00', '23:30:00', 'Stan Kessler\\\'s TV, Jardines', ''),
(19, 2, 4, 13, 2008, '15:00:00', '17:00:00', 'The SOBs, Topeka Ramada Inn', 'Topeka Jazz Workshop series'),
(18, 2, 4, 12, 2008, '19:00:00', '23:00:00', 'W/Angela Hagenbach, Jardines', ''),


I'm not a database person so beyond rudimentary exporting and importing, I'm not sure what to do.

Thanks for any help.

Keith
Hi,

Assuming the type of your editable regions is 'datetime', you can find details about it here - viewtopic.php?p=12667#p12667

As mentioned in the link above, you may set the 'am_pm' parameter to '1' to make the region use the 12 hour format. Make sure to visit the modified template as super-admin for the change to take effect.

As for the second question - we do have a CSV importer available (viewtopic.php?f=5&t=8803). You may try exporting the table from phpMyAdmin as CSV and then use the importer to get the values into Couch.

Hope it helps,
Thanks very much for the help. Problem 1 is solved. Regarding problem 2, everything seems to be working correctly when I run import.php but when I comment out the <cms:ignore> tags and run it, nothing is imported. The .csv has about 750 rows and 4 fields with the first few lines being:

page_title,desc,start_time,end_time
"Stan Kessler\'s TV, Jardines",,2008-04-16 19:30:00,2008-04-16 23:30:00
"The SOBs, Topeka Ramada Inn",Topeka Jazz Workshop series,2008-04-13 15:00:00,2008-04-13 17:00:00
"W/Angela Hagenbach, Jardines",,2008-04-12 19:00:00,2008-04-12 23:00:00
"The Sons of Brasil, Jardines",,2008-04-10 19:30:00,2008-04-10 23:30:00
Sons of Brasil @ Jardines,,2008-03-06 20:00:00,2008-03-06 00:00:00

Here's the beginning of my calendar.php code:

Code: Select all
<?php require_once( 'sk_cms/cms.php' ); ?>
<cms:template title='Events' clonable='1'>
    <cms:editable name='desc' label='Description' type='textarea' />
    <cms:editable name='location' label='Location' type='text' />
    <cms:editable name='start_time' label='Start Time' type='datetime' allow_time='1' am_pm='1' />
    <cms:editable name='end_time' label='End Time' type='datetime' allow_time='1' am_pm='1' />
</cms:template>


The purposes of the fields we used on his previous calendar don't quite line up with the new one but this is close enough considering these are all old events.

And here's my import.php code:

Code: Select all
<?php require_once( 'sk_cms/cms.php' ); ?>
    <cms:template title='Import' ></cms:template>

    <cms:set mystart="<cms:gpc 'import' method='get' />" />

    <cms:if mystart >
        <cms:csv_reader
            file="<cms:show k_admin_path />addons/csv/kessler_mssgs.csv"
            paginate='1'
            limit='100'
            prefix='_'
            use_cache='0'
        >
            <cms:if k_paginated_top >

                <cms:if k_paginate_link_next >
                    <script language="JavaScript" type="text/javascript">
                        var myVar;
                        myVar = window.setTimeout( 'location.href="<cms:show k_paginate_link_next />";', 1000 );
                    </script>
                    <button onclick="clearTimeout(myVar);">Stop</button>
                <cms:else />
                    Done!
                </cms:if>

                <h3><cms:show k_current_page /> / <cms:show k_total_pages /> pages (Total <cms:show k_total_records /> records. Showing <cms:show k_paginate_limit /> records per page)</hr>

                <table border='0'>
                    <thead>
                        <tr>
                            <th>No.</th>
                            <cms:csv_headers>
                                <th><cms:show value /></th>
                            </cms:csv_headers>
                        </tr>
                    </thead>
                    <tbody>
            </cms:if>

            <tr>
                <td><cms:show k_current_record /></td>
                <cms:csv_columns>
                    <td><cms:show value /></td>
                </cms:csv_columns>

                <!-- database operation here -->
                <!-- <cms:ignore> -->
                    <cms:db_persist
                        _auto_title       = '0'
                        _invalidate_cache = '0'
                        _masterpage       = 'calendar.php'
                        _mode             = 'create'

                        k_page_title      = "<cms:show page_title/>"

                        page_title        = _page_title
                        desc              = _desc
                        start_time        = _start_time
                        end_time          = _end_time
                    >
                        <cms:if k_error>
                            <strong style="color:red;">ERROR:</strong> <cms:show k_error/>
                        </cms:if>
                    </cms:db_persist>
                <!-- </cms:ignore> -->
                <!-- end database operation -->

            </tr>

            <cms:if k_paginated_bottom >
                        <tr>
                            <td></td>
                            <td colspan='<cms:show k_csv_header_count />'>
                                <cms:paginator simple='1' />
                            </td>
                        </tr>
                    </tbody>
                </table>
            </cms:if>

        </cms:csv_reader>
    <cms:else/>
        <button onclick='location.href="<cms:add_querystring k_page_link 'import=1' />"'>Start!</button>
    </cms:if>

<?php COUCH::invoke(); ?>



I've read through quite a bit of the <cms:db_persist> information in the forums but don't understand what everything within that tag does.

Thanks again for your help.

Keith
Hi,

when I run import.php but when I comment out the <cms:ignore> tags and run it, nothing is imported.

I think I can see the problem - you are trying to use HTML comments (i.e. "<!-- -->") to turn off Couch tags.
That won't work :). The enclosed database operations are still being ignored so please physically remove the closing and ending <cms:ignore> tags to make the enclosed code active.

Hope it helps.
That gives me multiple instances of "ERROR:Name: Required field cannot be left empty" at the top of each page but nothing is imported. Does that refer to the page_name field? I'd like the title of each page to be the first field being imported (page_title) and I hoped couch would generate the name from that. Is that the way it works and, if so, can you tell if I have calendar.php and import.php set up correctly to do that?

Thank you.

Keith
The problem, I think, lies in the following line -
Code: Select all
k_page_title      = "<cms:show page_title/>"

You are using a variable named 'page_title' to set the title but this variable actually is non-existent - the correct name of it is '_page_title' i.e. has an underscore as prefix (it is the same variable that you use in the very next line to set the page_title).

Please make the change and let me know how it goes.
That did it. The events are now all on the calendar with one small problem - they all show up in the front end calendar on today's date instead of the start_time (which is correct in the admin panel). I assume it's getting that from the publish date instead. Is it possible to display the events based on the date assigned in start_time instead of the publish date? Here's what I have in calendar.php.

Code: Select all

<?php require_once( 'sk_cms/cms.php' ); ?>
<cms:template title='Events' clonable='1'>
    <cms:editable name='desc' label='Description' type='textarea' />
    <cms:editable name='location' label='Location' type='text' />
    <cms:editable name='start_time' label='Start Time' type='datetime' allow_time='1' am_pm='1' />
    <cms:editable name='end_time' label='End Time' type='datetime' allow_time='1' am_pm='1' />
</cms:template>

<cms:embed 'head.html' />

<body class="calendar">
   <!--[if lt IE 7]>
   <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
   <![endif]-->

<cms:embed 'header.html' />

<!-- MAIN -->

    <main class="wrapper">
      <div class="container">
        <aside>
          <h1>Calendar</h1>
          <img src="/img/stanhappy.jpg" alt="Stanton Kessler" />
        </aside>
        <article>
          <cms:if k_is_page >
            <!-- Page View -->
            <b>Event:</b> <cms:show k_page_title /><br>
            <b>Description:</b> <cms:show desc /><br>
            <b>Location:</b> <cms:show location /><br>
            <b>Date:</b> <cms:date start_time format='F d, Y' /><br>
            <cms:if start_time!='Unspecified' >
              <b>From:</b> <cms:show start_time /><br>
            </cms:if>
            <cms:if end_time!='Unspecified' >
              <b>Until:</b> <cms:show end_time /><br>
            </cms:if>

            <cms:else />
            <!-- List view -->
            <cms:calendar date="<cms:gpc 'cal' />" masterpage=k_template_name show_future_entries='1' >
              <table class="calendar_big">
                <tr>
                  <th><a href="<cms:concat k_page_link '?cal=' k_prev_calendar_date />"> << </a></th>
                  <th colspan="5"><cms:date k_calendar_date format='F Y' /></th>
                  <th><a href="<cms:concat k_page_link '?cal=' k_next_calendar_date />"> >> </a></th>
                </tr>
                <tr>
                  <cms:repeat count='7'>
                  <td class="months_heading"><cms:zebra 'S' 'M' 'T' 'W' 'Th' 'F' 'S'/></td>
                  </cms:repeat>
                </tr>

                <cms:weeks>
                  <tr>
                  <cms:days >
                    <cms:if k_timeline_position='present'>
                        <cms:set tdclass='today' />
                    <cms:else />
                        <cms:set tdclass='' />
                    </cms:if>

                    <cms:if k_position='current_month' >
                      <cms:if k_count_entries >
                        <td class='entries <cms:show tdclass />' align='center'>
                          <a href="#"><cms:show k_day /></a>
                          <ul>
                          <cms:entries limit='2' skip_custom_fields='0'>
                            <li>
                              <a rel="leanModal" href="#<cms:show k_page_name />"><cms:show k_page_title /></a>
                              <cms:if start_time!='Unspecified' >
                               (<cms:date start_time format='ga' /></cms:if> -
                              <cms:if end_time!='Unspecified' >
                                <cms:date end_time format='ga' /></cms:if>)
                              <div id="<cms:show k_page_name />" class="modal">
                                <cms:if k_is_page >
                                    <p class="lede"><cms:show k_page_title /></p>
                                    <p><cms:show desc /></p>
                                    <p><cms:show location /></p>
                                    <p><cms:date start_time format='F d, Y' /></p>
                                    <cms:if start_time!='Unspecified' >
                                      <p><cms:date start_time format='ga' /> -
                                    </cms:if>
                                    <cms:if end_time!='Unspecified' >
                                      <cms:date end_time format='ga' /></p>
                                    </cms:if>
                                </cms:if>
                              </div>
                            </li>
                          </cms:entries>
                          </ul>
                        </td>
                      <cms:else />
                          <td class='<cms:show tdclass />' ><cms:show k_day /></td>
                      </cms:if>
                    <cms:else />
                      <td class='other_month'><cms:show k_day /></td>
                    </cms:if>
                  </cms:days>
                  </tr>
                </cms:weeks>
              </table>
            </cms:calendar>
          </cms:if>
        </article>
      </div>
    </main>

<cms:embed 'footer.html' />

<cms:embed 'scripts.html' />

   </body>
</html>

<?php COUCH::invoke(); ?>



Thanks for your help.

Keith
The calendar, I am afraid, uses only the publish_date to sort the entries.

No worries, though. There is a workaround available -
We can 'tie up' your custom 'start_time' field to the system publish_date field in a manner that anytime the start_time value is changed, the publish_date gets set to the same value (so the two always have the same values).

Please see viewtopic.php?f=2&t=7672#p12070 for the mentioned workaround.
After adding the given PHP code to kfunctions.php file, modify your start_time editable region as follows (make sure to visit the template as superadmin for the changes to persist) -
Code: Select all
<cms:editable 
    name='start_time' label='Start Time' type='datetime' allow_time='1' am_pm='1'
    required='1'
    validator='MyEvent::start_date'
    validator_msg='myevent::start_date=Incorrect date format'
/>

Try changing the start_time on one of your existing page and verify that the system publish_date (accessible from the advanced settings dropdown) also changes automatically to match it.

OK, with that done the only problem left would be that your existing events that you imported will still have the wrong date.
To set that right, you'll have to delete all of those pages and re-apply the import script. This time, add the following highlighted line to the importer -
k_page_title = "<cms:show page_title/>"

k_publish_date = _start_time

page_title = _page_title
desc = _desc
start_time = _start_time
end_time = _end_time

As you can see, we are setting the publish date to the _start_time so now all imported events will have their publish_dates in sync with the custom field

Hope it helps.
Yes, that did the trick. It's working perfectly now. Thanks again for your help.

Keith
I have a CSV with date as the first column value.

The date in the column is displayed as
1-Feb-19

i.e.
Code: Select all
format='j-M-y'


When I try to import it throws the error Invalid Date. I understand that the CSV Importer can not take the date as 1-Feb-19 from the cell. So what should be the work around?

My editable region is:
Code: Select all
<cms:editable label='Date' name='att_date' type='datetime' allow_time='0' format='j-M-y' order='1' />


The Client can not edit the CSV as it is exported from a Biometric device Model Number Identix K30. And then uploaded to the CSV importer.

Please suggest.

Regards,
GenXCoders (Priya)
Image
where innovation meets technology
12 posts Page 1 of 2
cron