<?php include '../../../../wp-blog-header.php'; if (!($wrapper = wufoo_login($echo = false))) { die; } if (!($forms = wufoo_cache_get('forms'))) { $forms = $wrapper->getForms(); foreach ($forms as $id => $form) { $forms[$id]->EntryCount = $wrapper->getEntryCount($id); } wufoo_cache_set('forms', $forms); } header('Content-type: application/javascript'); ?> (function() { var plugin_url = null, _ed; tinymce.create('tinymce.plugins.WuPhooey', { init : function(ed, url) { plugin_url = url; _ed = ed; }, createControl : function(n, cm) { switch (n) { case 'WuPhooey': var c = cm.createSplitButton('WuPhooey', { title : 'WuPhooey', image : plugin_url + '/button.gif',
function wufoo_entries() { if (isset($_GET['new_entry'])) { return wufoo_add_entry(); } wufoo_header('Entries'); $WufooFields = new WuPhooeyFields(); if (!($wrapper = wufoo_login())) { return; } if (!($data = wufoo_cache_get('entries-' . $_GET['entries'])) || isset($_GET['reload_cache'])) { $data = array(); $fields = $wrapper->getFields($_GET['entries']); $entries = $wrapper->getEntries($_GET['entries']); // Save the list of fields $fields = $WufooFields->store($fields); $data = wufoo_cache_set('entries-' . $_GET['entries'], array('fields' => $fields, 'entries' => $entries)); } if (empty($entries)) { $entries = $data['entries']; } if (empty($fields)) { $fields = $data['fields']; } $WufooFields->set_fields($fields); ?> <?php if (is_array($entries)) { ?> <h3>Click on an entry to see it</h3> <div id="entry-viewer"> <?php foreach ($entries as $entry) { ?> <div class="entry" id="entry-<?php echo $entry->EntryId; ?> "> <h2>Entry #<?php echo $entry->EntryId; ?> <span class="date"><?php echo date('F j, Y', strtotime($entry->DateCreated)); ?> </span> <span class="time">@ <?php echo date('g:i a', strtotime($entry->DateCreated)); ?> </span></h2> <a class="close" href="#">x</a> <table class="widefat"> <tbody> <?php foreach ($fields as $field) { ?> <?php if (!in_array($field['id'], array('EntryId', 'CreatedBy', 'UpdatedBy', 'LastUpdated', 'DateCreated'))) { ?> <tr> <td class="field"><?php echo $field['title']; ?> </td> <td class="value"><?php echo stripslashes($entry->{$field}['id']); ?> </td> </tr> <?php } ?> <?php } ?> </tbody> </table> </div> <?php } ?> </div> <?php } ?> <p class="submit"> <a class="button" href="<?php echo wufoo_link('forms'); ?> ">« Back</a> <a class="button-primary" href="<?php echo wufoo_link('forms'); ?> &entries=<?php echo $_GET['entries']; ?> &new_entry">New Entry</a> </p> <ul class="fields"> <?php foreach ($fields as $field) { echo '<li class="selected"><a href="#" rel="' . $field['id'] . '">' . $field['title'] . '</a></li>'; } ?> </ul> <table class="widefat list entries"> <thead> <tr> <?php foreach ($fields as $field) { ?> <th rel="<?php echo $field['id']; ?> "><?php echo $WufooFields->field_info($field); ?> </th> <?php } ?> <th class="edit" width="20"> <a href="#" class="edit_fields"><img src="<?php echo plugins_url('/images/edit.png', __FILE__); ?> " /></a> </th> </tr> </thead> <tbody> <?php if (is_array($entries)) { ?> <?php foreach ($entries as $entry) { ?> <tr rel="<?php echo $entry->EntryId; ?> "> <?php foreach ($fields as $field) { ?> <td rel="<?php echo $field['id']; ?> "><?php echo stripslashes($entry->{$field}['id']); ?> </td> <?php } ?> </tr> <?php } ?> <?php } else { ?> <tr> <td align="center" id="no-entries">You don't have any entries!</td> </tr> <?php } ?> </tbody> <tfoot> <tr> <?php foreach ($fields as $field) { ?> <th rel="<?php echo $field['id']; ?> "><?php echo $WufooFields->field_info($field); ?> </th> <?php } ?> <th class="edit" width="20"> <a href="#" class="edit_fields"><img src="<?php echo plugins_url('/images/edit.png', __FILE__); ?> " /></a> </th> </tr> </tfoot> </table> <p class="submit"> <a class="button" href="<?php echo wufoo_link('forms'); ?> ">« Back</a> <a class="button-primary" href="<?php echo wufoo_link('forms'); ?> &entries=<?php echo $_GET['entries']; ?> &new_entry">New Entry</a> — <a id="cache-message" class="button" href="#">Something Wrong?</a> </p> <script src="<?php echo plugins_url('/js/jquery.cookie.js', __FILE__); ?> "></script> <script> var $ = jQuery; $('.fields').hide(); $('.edit_fields').click(function(e) { $('<div />', { id: 'overlay', }).appendTo($('.wufoo.wrap')); $('#overlay', '.wufoo.wrap').css({ width: $('.wufoo.wrap').outerWidth(), height: $('.wufoo.wrap').outerHeight(), position: 'absolute', background: '#fff', opacity: 0.3, top: 0, left: 0 }); $('.wufoo.wrap .fields').show(); e.preventDefault(); }); function reStyleColumns() { $('table.entries tbody tr').each(function() { $('td', this).attr('colspan', 1); $('td:visible:last', this).attr('colspan', '2'); }); } function removeColumn(id) { $('table.entries th[rel=' + id + '], table.entries td[rel=' + id + ']').hide(); $('.wufoo.wrap .fields a[rel=' + id + ']').parent().removeClass('selected'); } function showColumn(id) { $('table.entries th[rel=' + id + '], table.entries td[rel=' + id + ']').show(); $('.wufoo.wrap .fields a[rel=' + id + ']').parent().addClass('selected'); } // Show a default amount of columns if( !$.cookie('WuPhooey-entries-<?php echo $_GET['entries']; ?> ') ) $.cookie('WuPhooey-entries-<?php echo $_GET['entries']; ?> ', [<?php for ($i = 0; $i < 4; $i++) { echo '"' . $fields[$i]['id'] . '",'; } ?> ]); var fields_to_show = $.cookie('WuPhooey-entries-<?php echo $_GET['entries']; ?> ').replace(/,$/, '').split(','); (function() { // Hide all the columns $('.wufoo.wrap .fields a').each(function() { // console.log($(this).attr('rel')); removeColumn($(this).attr('rel')); }); // Show some of the columns $.each(fields_to_show, function(index, id) { showColumn(id); }); reStyleColumns(); })(); // Show or Hide a column $('.fields a').click(function(e) { var fields = ''; if( $(this).parent().hasClass('selected') ) removeColumn($(this).attr('rel')); else showColumn($(this).attr('rel')); reStyleColumns(); // Save the cookie $('.fields .selected a').each(function() { fields += $(this).attr('rel') + ','; }); fields = fields.replace(/,$/, '').split(','); $.cookie('WuPhooey-entries-<?php echo $_GET['entries']; ?> ', fields); $('#no-entries').attr('colspan', fields.length + 1); e.preventDefault(); }); $('#no-entries').attr('colspan', fields_to_show.length + 1); $('#entry-viewer .entry').hide(); $('table.entries tr') .css('cursor', 'pointer') .click(function() { $('#entry-viewer #entry-' + $(this).attr('rel')).slideToggle(300); }); $('#entry-viewer .close').click(function(e) { $(this).parent().slideUp(); e.preventDefault(); }); $.fn.pager = function(options) { options = $.extend({ perPage: 3, items: 'tr', navigation: '#pager-nav' }, options); return $(this).each(function() { var rows = $(this).find(options.items), nav = $(options.navigation).hide(), page = 0; // Show the first page if( page = window.location.hash.match(/page-(\d+)/) ) { var offset = (page[1] - 1) * options.perPage; rows.hide().slice(offset, offset+options.perPage).show(); }else rows.hide().slice(0, options.perPage).show(); // Create the navigation if( Math.ceil(rows.length / options.perPage) > 1 ) { nav.show(); for( var i = 0, len = Math.ceil(rows.length / options.perPage); i < len; i++ ) { nav.append('<li><a href="#page-' + (i + 1) + '">' + (i + 1) + '</a></li>'); } } // "Activate" the navigation nav.find('a').click(function(e) { var num = $(this).text() - 1; var offset = num * options.perPage; rows.hide().slice(offset, offset+options.perPage).show(); nav.find('a').removeClass('current'); $('a:contains(' + $(this).text() + ')', nav).addClass('current'); }); }); }; // Paging var numEntries = 3, rows = $('table.entries tbody tr'), length; $('.submit').append('<select id="pager-amount"><option value="3">3</option><option value="5">5</option><option value="10">10</option><option value="25">25</option><option value="50">50</option></select><ul class="pager-nav"><li>Page: </li></ul>'); $('table.entries tbody').pager({ perPage: 3, navigation: '.pager-nav' }); $('#pager-amount').change(function() { var amount = $(this).val(); $.cookie('WuPhooey-entries-count', amount); $('.pager-nav').find('li').filter(':not(:first-child)').remove(); $('table.entries tbody').pager({ perPage: amount, navigation: '.pager-nav' }); }); if( $.cookie('WuPhooey-entries-count') ) { var amount = $.cookie('WuPhooey-entries-count'); $('#pager-amount').val(amount).change(); } </script> <?php wufoo_message('caching'); wufoo_footer(); }