public static function global_citation_page()
 {
     // Process incoming form and preload previous citations.
     $rows = array();
     if (!empty($_POST['__citation'])) {
         CandelaCitation::process_global_form();
         if (!empty($citations)) {
             foreach ($citations as $citation) {
                 $rows[] = CandelaCitation::get_meta_row($citation);
             }
         }
     }
     print '<div class="wrap">';
     print '<div>' . __('Global Citations', 'candela-citation') . '</div>';
     print '<form method="POST" action="' . get_permalink() . '">';
     print '<input type="hidden" name="__citation" value="1" >';
     $rows[] = CandelaCitation::get_meta_row();
     CandelaCitation::citations_table($rows);
     print '<input type="submit" id="citation-add-all" name="citation-add-all" value="' . __('Add citations to every page', 'candela-citation') . '">';
     print '<input type="submit" id="citation-replace-all" name="citation-replace-all" value="' . __('OVERWRITE citations on every page', 'candela-citation') . '">';
     print "<script type=\"text/javascript\">\n      jQuery( document ).ready( function( \$ ) {\n        \$('#citation-add-all').click(function() {\n          if (!confirm(\"Are you sure you want to add citations to *every* page in this book?\")) {\n            return false;\n          }\n        });\n      });\n    </script>";
     print "<script type=\"text/javascript\">\n      jQuery( document ).ready( function( \$ ) {\n        \$('#citation-replace-all').click(function() {\n          if (!confirm(\"Are you sure you want to replace all citations in *every* page in this book?\")) {\n            return false;\n          }\n        });\n      });\n    </script>";
     print '</form>';
     print '</div>';
     // Show citations for every book
     $structure = pb_get_book_structure();
     if (!empty($structure['__order'])) {
         $grouped = array();
         $headers = array('title' => __('Post'));
         foreach ($structure['__order'] as $id => $info) {
             $post = get_post($id);
             $citations = CandelaCitation::get_citations($id);
             $fields = CandelaCitation::citation_fields();
             foreach ($citations as $citation) {
                 $parts = array();
                 $parts['title'] = '<a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a>';
                 foreach ($fields as $field => $info) {
                     if (empty($headers[$field])) {
                         $headers[$field] = $info['label'];
                     }
                     if (!empty($citation[$field])) {
                         $parts[$field] = esc_html($citation[$field]);
                     }
                 }
                 $grouped[$id][$citation['type']][] = $parts;
             }
         }
         if (!empty($grouped)) {
             print '<div class="wrap"><table>';
             print '<thead><tr>';
             foreach ($headers as $title) {
                 print '<th>' . $title . '</th>';
             }
             print '</tr></thead>';
             print '<tbody>';
             foreach ($grouped as $id => $citations) {
                 foreach ($citations as $type => $parts) {
                     foreach ($parts as $row) {
                         print '<tr>';
                         foreach (array_keys($headers) as $field) {
                             if (!empty($row[$field])) {
                                 switch ($field) {
                                     case 'url':
                                         print '<td><a href="' . esc_url($row[$field]) . '">' . esc_url($row[$field]) . '</a></td>';
                                         break;
                                     default:
                                         print '<td>' . $row[$field] . '</td>';
                                         break;
                                 }
                             } else {
                                 print '<td></td>';
                             }
                         }
                         print '</tr>';
                     }
                 }
             }
             print '</tbody>';
             print '</table></div>';
         } else {
             print '';
         }
     }
 }