/**
  * Get the Export Data
  *
  * @access	public
  * @since	1.4
  * @return	arr		$data	The data for the CSV file
  */
 public function get_data()
 {
     $data = array();
     // Export all clients
     add_filter('mdjm_get_clients_args', array($this, 'filter_args'));
     $clients = mdjm_get_clients();
     remove_filter('mdjm_get_clients_args', array($this, 'filter_args'));
     $i = 0;
     foreach ($clients as $client) {
         $events = mdjm_get_client_events($client->ID);
         $amount = 0;
         $data[$i]['id'] = $client->ID;
         $data[$i]['name'] = $client->display_name;
         $data[$i]['email'] = $client->user_email;
         $data[$i]['events'] = $events ? count($events) : 0;
         if ($events) {
             foreach ($events as $event) {
                 $amount += mdjm_get_event_price($event->ID);
             }
         }
         $data[$i]['amount'] = mdjm_format_amount($amount);
         $i++;
     }
     $data = apply_filters('mdjm_export_get_data', $data);
     $data = apply_filters('mdjm_export_get_data_' . $this->export_type, $data);
     return $data;
 }
/**
 * Update the email content field with the selected template.
 *
 *
 * @since	1.3
 * @return	void
 */
function mdjm_user_events_dropdown_ajax()
{
    $result['event_list'] = '<option value="0">' . __('Select an Event', 'mobile-dj-manager') . '</option>';
    if (!empty($_POST['recipient'])) {
        $statuses = 'any';
        if (mdjm_is_employee($_POST['recipient'])) {
            if (mdjm_get_option('comms_show_active_events_only')) {
                $statuses = array('post_status' => mdjm_active_event_statuses());
            }
            $events = mdjm_get_employee_events($_POST['recipient'], $statuses);
        } else {
            if (mdjm_get_option('comms_show_active_events_only')) {
                $statuses = mdjm_active_event_statuses();
            }
            $events = mdjm_get_client_events($_POST['recipient'], $statuses);
        }
        if ($events) {
            foreach ($events as $event) {
                $result['event_list'] .= '<option value="' . $event->ID . '">';
                $result['event_list'] .= mdjm_get_event_date($event->ID) . ' ';
                $result['event_list'] .= __('from', 'mobile-dj-manager') . ' ';
                $result['event_list'] .= mdjm_get_event_start($event->ID) . ' ';
                $result['event_list'] .= '(' . mdjm_get_event_status($event->ID) . ')';
                $result['event_list'] .= '</option>';
            }
        }
    }
    $result['type'] = 'success';
    $result = json_encode($result);
    echo $result;
    die;
}
 /**
  * Get the Export Data
  *
  * @access	public
  * @since	1.4
  * @global	obj		$wpdb	Used to query the database using the WordPress Database API
  * @return	arr		$data	The data for the CSV file
  */
 public function get_data()
 {
     global $wpdb;
     $data = array();
     // Export all clients
     $clients = mdjm_get_clients();
     $i = 0;
     foreach ($clients as $client) {
         if ('emails' != $_POST['mdjm_export_option']) {
             $data[$i]['name'] = $client->name;
         }
         $data[$i]['email'] = $client->email;
         if ('full' == $_POST['mdjm_export_option']) {
             $amount = 0;
             $events = mdjm_get_client_events($client->ID);
             $data[$i]['events'] = $events ? count($events) : 0;
             if ($events) {
                 foreach ($events as $event) {
                     $amount += mdjm_get_event_price($event->ID);
                 }
             }
             $data[$i]['amount'] = mdjm_format_amount($amount);
         }
         $i++;
     }
     $data = apply_filters('mdjm_export_get_data', $data);
     $data = apply_filters('mdjm_export_get_data_' . $this->export_type, $data);
     return $data;
 }
 /**
  * Retrieve events filtered by employee, client, date or status.
  *
  * @since	1.4
  * @return	void
  */
 public function list_events()
 {
     $response = array();
     if (!mdjm_employee_can('read_events', $this->user_id)) {
         $this->no_permsission();
     }
     if (!isset($this->request['employee_id']) && !mdjm_employee_can('read_events_all', $this->user_id)) {
         $this->no_permsission();
     }
     do_action('mdjm_before_api_event_list', $this);
     if (isset($this->request['employee_id'])) {
         $events = mdjm_get_employee_events($this->request['employee_id']);
     } elseif (isset($this->request['client_id'])) {
         $events = mdjm_get_client_events($this->request['client_id']);
     } elseif (isset($this->request['date'])) {
         $events = mdjm_get_events_by_date($this->request['date']);
     } elseif (isset($this->request['status'])) {
         $events = mdjm_get_events_by_status($this->request['status']);
     } else {
         $events = mdjm_get_events();
     }
     if (!$events) {
         $error = array();
         $error['error'] = sprintf(__('No %s found.', 'mobile-dj-manager'), mdjm_get_label_plural(true));
         $this->data = $error;
         $this->output();
     }
     $response['events'] = array();
     $i = 0;
     foreach ($events as $event) {
         $response['events'][$event->ID] = mdjm_get_event_data($event->ID);
         $i++;
     }
     $response['count'] = $i;
     $this->data = array_merge($this->data, $response);
     do_action('mdjm_after_api_event_list', $this);
     $this->output();
 }
/**
 * Check whether the user is a client.
 *
 * @since	1.3
 * @param	int		$client_id	The ID of the user to check.
 * @return	bool	True if user has the client role, or false.
 */
function mdjm_user_is_client($client_id)
{
    if (mdjm_get_client_events($client_id)) {
        return true;
    }
    return false;
}
Example #6
0
/**
 * MDJM Home Shortcode.
 *
 * Displays the Client Zone home page which will render event details if the client only has a single event
 * or a list of events if they have multiple events in the system.
 * 
 * @since	1.3
 *
 * @return	string
 */
function mdjm_shortcode_home($atts)
{
    if (is_user_logged_in()) {
        global $mdjm_event;
        $mdjm_event = '';
        ob_start();
        $output = '';
        $client_id = get_current_user_id();
        mdjm_add_content_tag('event_action_buttons', sprintf(__('%s action buttons within %s', 'mobile-dj-manager'), mdjm_get_label_singular(), mdjm_get_option('app_name')), 'mdjm_do_action_buttons');
        if (isset($_GET['event_id'])) {
            $mdjm_event = mdjm_get_event($_GET['event_id']);
            if (!empty($mdjm_event->ID)) {
                ob_start();
                mdjm_get_template_part('event', 'single');
                $output .= mdjm_do_content_tags(ob_get_contents(), $mdjm_event->ID, $client_id);
                ob_get_clean();
            } else {
                ob_start();
                mdjm_get_template_part('event', 'none');
                $output .= mdjm_do_content_tags(ob_get_contents(), '', $client_id);
                ob_get_clean();
            }
        } else {
            $client_events = mdjm_get_client_events($client_id, mdjm_active_event_statuses());
            if ($client_events) {
                $slug = 'single';
                if (count($client_events) > 1) {
                    $slug = 'loop';
                    ob_start();
                    mdjm_get_template_part('event', 'loop-header');
                    $output .= mdjm_do_content_tags(ob_get_contents(), '', $client_id);
                    do_action('mdjm_pre_event_loop');
                    ?>
<div id="mdjm-event-loop"><?php 
                    ob_get_clean();
                }
                foreach ($client_events as $event) {
                    $mdjm_event = new MDJM_Event($event->ID);
                    ob_start();
                    mdjm_get_template_part('event', $slug);
                    $output .= mdjm_do_content_tags(ob_get_contents(), $mdjm_event->ID, $client_id);
                    ob_get_clean();
                }
                if ($slug == 'loop') {
                    ob_start();
                    mdjm_get_template_part('event', 'loop-footer');
                    $output .= mdjm_do_content_tags(ob_get_contents(), '', $client_id);
                    ?>
</div><?php 
                    do_action('mdjm_post_event_loop', $client_events);
                    ob_get_clean();
                }
            } else {
                mdjm_get_template_part('event', 'none');
                $output .= mdjm_do_content_tags(ob_get_contents(), '', $client_id);
                ob_get_clean();
            }
        }
        $mdjm_event = '';
        return $output;
    } else {
        echo mdjm_login_form(mdjm_get_current_page_url());
    }
}
Example #7
0
/**
 * Display the filter drop down list to enable user to select and filter event by Client.
 * 
 * @since	1.0
 * @param	arr
 * @return	arr
 */
function mdjm_event_client_filter_dropdown()
{
    $roles = array('client', 'inactive_client');
    $employee = !mdjm_employee_can('read_events_all') ? get_current_user_id() : false;
    $all_clients = mdjm_get_clients($roles, $employee);
    if (!$all_clients || 1 == count($all_clients)) {
        return;
    }
    $selected = isset($_GET['mdjm_filter_client']) ? (int) $_GET['mdjm_filter_client'] : 0;
    foreach ($all_clients as $_client) {
        $client_events = mdjm_get_client_events($_client->ID);
        if ($client_events) {
            $clients[$_client->ID] = $_client->display_name;
        }
    }
    if (empty($clients)) {
        return;
    }
    ?>
	<label for="filter-by-client" class="screen-reader-text">Filter by <?php 
    _e('Client', 'mobile-dj-manager');
    ?>
</label>
	<select name="mdjm_filter_client" id="mdjm_filter_client-by-dj">
		<option value="0"<?php 
    selected($selected, 0, false);
    ?>
><?php 
    _e("All Client's", 'mobile-dj-manager');
    ?>
</option>
	<?php 
    foreach ($clients as $ID => $display_name) {
        if (empty($display_name)) {
            continue;
        }
        printf("<option %s value='%s'>%s</option>\n", selected($selected, $ID, false), $ID, $display_name);
    }
    ?>
	</select>
	<?php 
}