function action_sf_my_tickets()
 {
     $statuses = SupportFlow()->post_statuses;
     $status_slugs = array();
     foreach ($statuses as $status => $status_data) {
         if (true == $status_data['show_tickets']) {
             $status_slugs[] = $status;
         }
     }
     $table = new SupportFlow_Table();
     $user_id = get_current_user_id();
     foreach ($status_slugs as $status_slug) {
         $args = array('post_type' => SupportFlow()->post_type, 'post_parent' => 0, 'posts_per_page' => 10, 'post_status' => $status_slug, 'author' => $user_id);
         $wp_query = new WP_Query($args);
         $tickets = $wp_query->posts;
         $no_items = '<a href="post-new.php?post_type=' . SupportFlow()->post_type . '">' . __('<b>Click here</b>') . '</a>';
         $no_items = sprintf(__('No matching ticket exists. %s to create new.', 'supportflow'), $no_items);
         $table->set_no_items($no_items);
         $table->set_columns(array('title' => __('Subject', 'supportflow'), 'modified' => __('Last modified', 'supportflow'), 'datetime' => __('Created', 'supportflow')));
         $data = array();
         foreach ($tickets as $ticket) {
             $post_date = strtotime($ticket->post_date);
             $post_modified = strtotime($ticket->post_modified);
             $title = '<b>' . esc_html($ticket->post_title) . '</b>';
             $title = "<a href='post.php?post=" . $ticket->ID . "&action=edit'>" . $title . "</a>";
             $data[] = array('title' => $title, 'modified' => sprintf(__('%s ago', 'supportflow'), human_time_diff(time(), $post_modified)), 'datetime' => sprintf(__('%s ago', 'supportflow'), human_time_diff(time(), $post_date)));
         }
         $table->set_data($data);
         echo '<div class="container">';
         echo "<h3 class='toggle-link'>" . $statuses[$status_slug]['label'] . "</h3>";
         echo "<div class='toggle-content'>";
         $table->display();
         echo "</div>";
         echo '</div>';
     }
 }
 public function meta_box_other_customers_tickets()
 {
     $ticket_customers = SupportFlow()->get_ticket_customers(get_the_ID(), array('fields' => 'slugs'));
     $statuses = SupportFlow()->post_statuses;
     $status_slugs = array_keys($statuses);
     $table = new SupportFlow_Table('', false, false);
     if (empty($ticket_customers)) {
         $tickets = array();
     } else {
         $args = array('post_type' => SupportFlow()->post_type, 'post_parent' => 0, 'post_status' => $status_slugs, 'posts_per_page' => 10, 'post__not_in' => array(get_the_id()), 'tax_query' => array(array('taxonomy' => SupportFlow()->customers_tax, 'field' => 'slug', 'terms' => $ticket_customers)));
         $wp_query = new WP_Query($args);
         $tickets = $wp_query->posts;
     }
     $no_items = __('No recent tickets found.', 'supportflow');
     $table->set_no_items($no_items);
     $table->set_columns(array('title' => __('Subject', 'supportflow'), 'status' => __('Status', 'supportflow')));
     $data = array();
     foreach ($tickets as $ticket) {
         $post_date = strtotime($ticket->post_date);
         $post_modified = strtotime($ticket->post_modified);
         $title = '<b>' . esc_html($ticket->post_title) . '</b>';
         $title = "<a href='post.php?post=" . $ticket->ID . "&action=edit'>" . $title . "</a>";
         $data[] = array('title' => $title, 'status' => $statuses[$ticket->post_status]['label']);
     }
     $table->set_data($data);
     $table->display();
 }
 /**
  * List all the existing E-Mail accounts in a table
  */
 public function list_email_accounts()
 {
     $no_items = __('No E-Mail accounts found. Please <b>add them</b> in the form below.', 'supportflow');
     $columns = array('table_username' => __('Username', 'supportflow'), 'table_imap_host' => __('IMAP Host', 'supportflow'), 'table_imap_port' => __('IMAP Port', 'supportflow'), 'table_imap_ssl' => __('IMAP use SSL', 'supportflow'), 'table_smtp_host' => __('SMTP Host', 'supportflow'), 'table_smtp_port' => __('SMTP Port', 'supportflow'), 'table_smtp_ssl' => __('SMTP use SSL', 'supportflow'), 'table_action' => __('Action', 'supportflow'));
     $data = array();
     foreach ($this->email_accounts as $account_id => $account) {
         // Account is deleted
         if (empty($account)) {
             continue;
         }
         $data[] = array('table_username' => esc_html($account['username']), 'table_imap_host' => esc_html($account['imap_host']), 'table_imap_port' => esc_html($account['imap_port']), 'table_imap_ssl' => esc_html($account['imap_ssl'] ? 'True' : 'False'), 'table_smtp_host' => esc_html($account['smtp_host']), 'table_smtp_port' => esc_html($account['smtp_port']), 'table_smtp_ssl' => esc_html($account['smtp_ssl'] ? 'True' : 'False'), 'table_action' => "<a href='#' data-account-id='" . esc_attr($account_id) . "' class='delete_email_account'>" . __('Delete', 'supportflow') . "</a>");
     }
     $email_accounts_table = new SupportFlow_Table();
     $email_accounts_table->set_columns($columns);
     $email_accounts_table->set_no_items($no_items);
     $email_accounts_table->set_data($data);
     $email_accounts_table->display();
 }
 public function show_permissions_table($user_permissions)
 {
     $message = __('No tag/e-mail accounts found. <b>%s</b> before setting user permissions.<br><b>Note: </b>Administrator accounts automatically have full access in SupportFlow.', 'supportflow');
     $link = '<a href="">' . __('Please add them', 'supportflow') . '</a>';
     $no_items = sprintf($message, $link);
     $columns = array('status' => __('Status', 'supportflow'), 'privilege' => __('Privilege', 'supportflow'), 'type' => __('Type', 'supportflow'), 'user' => __('User', 'supportflow'));
     $data = array();
     foreach ($user_permissions as $id => $user_permission) {
         $identfier = json_encode(array('user_id' => $user_permission['user_id'], 'privilege_type' => $user_permission['privilege_type'], 'privilege_id' => $user_permission['privilege_id']));
         $status = "<input type='checkbox' id='permission_{$id}' class='toggle_privilege' data-permission-identifier='" . $identfier . "' " . checked($user_permission['allowed'], true, false) . '>';
         $status .= " <label for='permission_{$id}' class='privilege_status'>" . __($user_permission['allowed'] ? 'Allowed' : 'Not allowed', 'supportflow') . "</label>";
         $data[] = array('status' => $status, 'privilege' => esc_html($user_permission['privilege']), 'type' => $user_permission['type'], 'user' => esc_html($user_permission['user']));
     }
     $permissions_table = new SupportFlow_Table('sf_user_permissions_table');
     $permissions_table->set_columns($columns);
     $permissions_table->set_no_items($no_items);
     $permissions_table->set_data($data);
     $permissions_table->display();
 }
 /**
  * Loads the page to change E-Mail notfication settings
  */
 public function notification_setting_page()
 {
     $columns = array('privilege' => __('Privilege', 'supportflow'), 'type' => __('Type', 'supportflow'), 'status' => __('Status', 'supportflow'));
     $no_items = __("You don't have <b>permission</b> to any tag/e-mail account, or maybe no tag/e-mail account exists yet. Please ask your administrator to give you permission to an e-mail account or tag.", 'supportflow');
     $data = array();
     $notification_settings = SupportFlow()->extend->email_notifications->get_notifications_settings(get_current_user_id());
     foreach ($notification_settings as $id => $notification_setting) {
         $identfier = json_encode(array('privilege_type' => $notification_setting['privilege_type'], 'privilege_id' => $notification_setting['privilege_id']));
         $status = "<input type='checkbox' id='permission_{$id}' class='toggle_privilege' data-email-notfication-identifier='" . $identfier . "' " . checked($notification_setting['allowed'], true, false) . '>';
         $status .= " <label for='permission_{$id}' class='privilege_status'> " . __($notification_setting['allowed'] ? 'Subscribed' : 'Unsubscribed', 'supportflow') . "</label>";
         $data[] = array('status' => $status, 'privilege' => esc_html($notification_setting['privilege']), 'type' => $notification_setting['type']);
     }
     $email_notifications_table = new SupportFlow_Table('sf_email_accounts_table');
     $email_notifications_table->set_columns($columns);
     $email_notifications_table->set_no_items($no_items);
     $email_notifications_table->set_data($data);
     echo '<h1>' . __('E-Mail Notifications', 'supportflow') . '</h1>';
     echo '<p>' . __('Please check the tags/E-Mail accounts for which you want to receive E-Mail notifications of replies. You will be able to override E-Mail notifications settings for individual tickets.', 'supportflow') . '</p>';
     echo '<div id="email_notification_table">';
     $email_notifications_table->display();
     echo '</div>';
 }
 public function show_5_year_stats()
 {
     $statistics_table = new SupportFlow_Table();
     $items = array();
     $statistics_table->set_columns(array('table_date' => __('Date', 'supportflow'), 'table_new' => __('New tickets', 'supportflow'), 'table_open' => __('Open tickets', 'supportflow'), 'table_closed' => __('Closed tickets', 'supportflow')));
     for ($i = 0; $i < 5; $i++) {
         $date_time = strtotime('-' . $i . 'year');
         $post_date = array('year' => (int) date("Y", $date_time));
         $link_date = date("Y", $date_time);
         $link_value = date("Y", $date_time);
         $items[] = $this->get_post_data_by_date($post_date, $link_date, $link_value);
     }
     $statistics_table->set_data($items);
     $statistics_table->display();
 }