Example #1
0
 /**
  * Sheets
  */
 function sheet_page()
 {
     if (!current_user_can('manage_options') && !current_user_can('manage_signup_sheets')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $err = false;
     $success = false;
     // Remove signup record
     if (isset($_GET['action']) && $_GET['action'] == 'clear') {
         try {
             $result = $this->data->delete_signup($_GET['signup_id']);
             $success = true;
             if ($result > 0) {
                 echo '<div class="updated"><p>Spot has been cleared.</p></div>';
             }
         } catch (DLS_SUS_Data_Exception $e) {
             $err = true;
             echo '<div class="error"><p>Error clearing spot (ID #' . esc_attr($_GET['signup_id']) . ')</p></div>';
         }
     }
     // Set Actions
     $trash = !empty($_GET['action']) && $_GET['action'] == 'trash';
     $untrash = !empty($_GET['action']) && $_GET['action'] == 'untrash';
     $delete = !empty($_GET['action']) && $_GET['action'] == 'delete';
     $copy = !empty($_GET['action']) && $_GET['action'] == 'copy';
     $view_signups = !empty($_GET['action']) && $_GET['action'] == 'view_signups';
     $edit = !$trash && !$untrash && !$delete && !$copy && !empty($_GET['sheet_id']);
     echo '<div class="wrap dls_sus">';
     echo '<div id="icon-dls-sus" class="icon32"><br /></div>';
     echo $edit || $view_signups ? '<h2>Sheet Details <a href="' . plugins_url('./', __FILE__) . 'export.php?sheet_id=' . $_GET['sheet_id'] . '" class="add-new-h2">Export Sheet as CSV</a></h2>' : '<h2>Sign-up Sheets <sup class="dls-sus-pro">Pro</sup>
         <a href="?page=' . $this->admin_settings_slug . '_modify_sheet" class="add-new-h2">Add New</a>
         <a href="' . plugins_url('./', __FILE__) . 'export.php" class="add-new-h2">Export All as CSV</a>
         </h2>
     ';
     if ($untrash) {
         try {
             $result = $this->data->update_sheet(array('sheet_trash' => 0), $_GET['sheet_id']);
             echo '<div class="updated"><p>Sheet has been restored.</p></div>';
         } catch (DLS_SUS_Data_Exception $e) {
             echo '<div class="error"><p>Error restoring sheet.' . ($this->detailed_errors === true ? '.. ' . print_r(mysql_error(), true) : '') . '</p></div>';
         }
     } elseif ($trash) {
         try {
             $result = $this->data->update_sheet(array('sheet_trash' => 1), $_GET['sheet_id']);
             echo '<div class="updated"><p>Sheet has been moved to trash.</p></div>';
         } catch (DLS_SUS_Data_Exception $e) {
             echo '<div class="error"><p>Error moving sheet to trash.' . ($this->detailed_errors === true ? '.. ' . print_r(mysql_error(), true) : '') . '</p></div>';
         }
     } elseif ($delete) {
         try {
             $result = $this->data->delete_sheet($_GET['sheet_id']);
             echo '<div class="updated"><p>Sheet has been permanently deleted.</p></div>';
         } catch (DLS_SUS_Data_Exception $e) {
             echo '<div class="error"><p>Error permanently deleting sheet.' . ($this->detailed_errors === true ? '.. ' . print_r(mysql_error(), true) : '') . '</p></div>';
         }
     } elseif ($copy) {
         try {
             $new_id = $this->data->copy_sheet($_GET['sheet_id']);
             echo '<div class="updated"><p>Sheet has been copied to new sheet ID #' . $new_id . ' (<a href="?page=' . $this->admin_settings_slug . '_modify_sheet&amp;sheet_id=' . $new_id . '">Edit</a>).</p></div>';
         } catch (DLS_SUS_Data_Exception $e) {
             echo '<div class="error"><p>Error copying sheet.' . ($this->detailed_errors === true ? '.. ' . print_r(mysql_error(), true) : '') . '</p></div>';
         }
     }
     if ($edit || $view_signups) {
         // View Single Sheet
         $sheet = new DLS_SUS_Sheet($_GET['sheet_id']);
         if (!$sheet->is_valid()) {
             echo '<p class="error">' . __('No sign-up sheet found.', $this->plugin_prefix) . '</p>';
         } else {
             echo '
             <h3>' . $sheet->title . '</h3>
             
             <p>Date: ' . ($sheet->date == '0000-00-00' ? 'N/A' : date(get_option('date_format'), strtotime($sheet->date))) . '</p>
             
             <div class="dls-sus-sheet-details">' . nl2br($sheet->details) . '</div>
             
             <h4>' . __('Sign-ups', $this->plugin_prefix) . '</h4>
             ';
             // Tasks
             echo $sheet->get_tasks_table(array('show_clear' => true, 'admin_table' => true));
         }
     } else {
         // View All
         $show_trash = isset($_GET['sheet_status']) && $_GET['sheet_status'] == 'trash';
         $show_all = !$show_trash;
         echo '
         <ul class="subsubsub">
             <li class="all"><a href="admin.php?page=' . $this->admin_settings_slug . '_sheets"' . ($show_all ? ' class="current"' : '') . '>All <span class="count">(' . $this->data->get_sheet_count() . ')</span></a> |</li>
             <li class="trash"><a href="admin.php?page=' . $this->admin_settings_slug . '_sheets&amp;sheet_status=trash"' . ($show_trash ? ' class="current"' : '') . '>Trash <span class="count">(' . $this->data->get_sheet_count(true) . ')</span></a></li>
         </ul>
         <form method="get" action="">
         ';
         // Get and display data
         $this->table = new DLS_SUS_List_Table_Sheets($show_trash);
         $this->table->prepare_items();
         $this->table->display();
         echo '</form><!-- #sheet-filter -->';
     }
     echo '</div><!-- .wrap -->';
 }