/**
  * 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;
 }
/**
 * Adds a new client from the event field.
 *
 * @since	1.3.7
 * @global	arr		$_POST
 */
function mdjm_add_client_ajax()
{
    $client_id = false;
    $client_list = '';
    $result = array();
    $message = array();
    if (!is_email($_POST['client_email'])) {
        $message[] = __('Email address is invalid', 'mobile-dj-manager');
    } elseif (email_exists($_POST['client_email'])) {
        $message[] = __('Email address is already in use', 'mobile-dj-manager');
    } else {
        $user_data = array('first_name' => ucwords($_POST['client_firstname']), 'last_name' => !empty($_POST['client_lastname']) ? ucwords($_POST['client_lastname']) : '', 'user_email' => $_POST['client_email'], 'client_phone' => !empty($_POST['client_phone']) ? $_POST['client_phone'] : '', 'client_phone2' => !empty($_POST['client_phone2']) ? $_POST['client_phone2'] : '');
        $user_data = apply_filters('mdjm_event_new_client_data', $user_data);
        $client_id = mdjm_add_client($user_data);
    }
    $clients = mdjm_get_clients('client');
    if (!empty($clients)) {
        foreach ($clients as $client) {
            $client_list .= sprintf('<option value="%1$s"%2$s>%3$s</option>', $client->ID, $client->ID == $client_id ? ' selected="selected"' : '', $client->display_name);
        }
    }
    if (empty($client_id)) {
        $result = array('type' => 'error', 'message' => explode("\n", $message));
    } else {
        $result = array('type' => 'success', 'client_id' => $client_id, 'client_list' => $client_list);
        do_action('mdjm_after_add_new_client', $user_data);
    }
    echo json_encode($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;
 }
Example #4
0
/**
 * Output the event client row
 *
 * @since	1.3.7
 * @global	obj		$mdjm_event			MDJM_Event class object
 * @global	bool	$mdjm_event_update	True if this event is being updated, false if new.
 * @param	int		$event_id			The event ID.
 * @return	str
 */
function mdjm_event_metabox_client_select_row($event_id)
{
    global $mdjm_event, $mdjm_event_update;
    ?>
	<div class="mdjm_field_wrap mdjm_form_fields">
    	<div class="mdjm_col">
            <label for="client_name"><?php 
    _e('Client:');
    ?>
</label> 
            <?php 
    if (mdjm_event_is_active($event_id)) {
        ?>
    
                <?php 
        $clients = mdjm_get_clients('client');
        ?>
                
                <?php 
        echo MDJM()->html->client_dropdown(array('selected' => $mdjm_event->client, 'class' => '', 'roles' => array('client'), 'chosen' => true, 'placeholder' => __('Select a Client', 'mobile-dj-manager'), 'null_value' => array('' => __('Select a Client', 'mobile-dj-manager')), 'add_new' => empty($mdjm_event->client) ? true : false, 'show_option_all' => false, 'show_option_none' => false));
        ?>
    
            <?php 
    } else {
        ?>
    
                <?php 
        echo MDJM()->html->text(array('name' => 'client_name_display', 'class' => '', 'value' => mdjm_get_client_display_name($mdjm_event->client), 'readonly' => true));
        ?>
                
                <?php 
        echo MDJM()->html->hidden(array('name' => 'client_name', 'class' => '', 'value' => $mdjm_event->client));
        ?>
    
            <?php 
    }
    ?>
            <?php 
    if (mdjm_employee_can('view_clients_list') && $mdjm_event_update && $mdjm_event->client) {
        ?>
                <a id="toggle_client_details" class="mdjm-small mdjm-fake"><?php 
        _e('Toggle Client Details', 'mobile-dj-manager');
        ?>
</a>
            <?php 
    }
    ?>
        </div>
	</div>
	<?php 
}
 /**
  * Renders an HTML Dropdown of clients
  *
  * @access	public
  * @since	1.3.7
  * @param	arr		$args		Select list arguments. See @defaults.
  * @return	str		$output		Client dropdown
  */
 public function client_dropdown($args = array())
 {
     $options = array();
     $defaults = array('name' => 'client_name', 'class' => '', 'id' => '', 'selected' => 0, 'roles' => array('client', 'inactive_client'), 'chosen' => false, 'placeholder' => null, 'multiple' => false, 'null_value' => false, 'add_new' => false, 'show_option_all' => _x('All Clients', 'all dropdown items', 'mobile-dj-manager'), 'show_option_none' => _x('Select a Client', 'no dropdown items', 'mobile-dj-manager'), 'data' => array());
     $args = wp_parse_args($args, $defaults);
     $selected = empty($args['selected']) ? 0 : $args['selected'];
     $clients = mdjm_get_clients($args['roles']);
     if (!empty($args['null_value'])) {
         foreach ($args['null_value'] as $key => $value) {
             $options[$key] = $value;
         }
     }
     if (!empty($args['add_new'])) {
         $options['mdjm_add_client'] = __('Add New Client', 'mobile-dj-manager');
     }
     if ($clients) {
         foreach ($clients as $client) {
             $options[$client->ID] = $client->display_name;
         }
     }
     $output = $this->select(array('name' => $args['name'], 'class' => $args['class'], 'id' => $args['id'], 'selected' => $selected, 'options' => $options, 'chosen' => $args['chosen'], 'placeholder' => $args['placeholder'], 'multiple' => $args['multiple'], 'show_option_all' => $args['show_option_all'], 'show_option_none' => $args['show_option_none'], 'data' => $args['data']));
     return $output;
 }
 /**
  * Retrieve a list of all clients
  *
  * @param	str|arr	$roles		Optional: The roles for which we want to retrieve the clients from.
  *			int		$employee	Optional: Only display clients of the given employee
  *			str		$orderby	Optional: The field by which to order. Default display_name
  *			str		$order		Optional: ASC (default) | Desc
  *
  * @return	$arr	$employees	or false if no employees for the specified roles
  */
 public function get_clients($roles = '', $employee = '', $orderby = '', $order = '')
 {
     return mdjm_get_clients($roles = '', $employee = '', $orderby = '', $order = '');
 }
/**
 * Display the send email form on the communications page.
 *
 * @since	1.3
 * @param
 * @return	Outputs the page content
 */
function mdjm_comms_page()
{
    if (!mdjm_employee_can('send_comms')) {
        wp_die('<h1>' . __('Cheatin&#8217; uh?') . '</h1>' . '<p>' . __('You do not have permission to access this page.', 'mobile-dj-manager') . '</p>', 403);
    }
    global $current_user;
    if (mdjm_employee_can('list_all_clients')) {
        $clients = mdjm_get_clients();
    } else {
        $clients = mdjm_get_employee_clients();
    }
    if (mdjm_employee_can('mdjm_employee_edit')) {
        $employees = mdjm_get_employees();
    }
    ?>
    <div class="wrap">
		<h1><?php 
    _e('Client and Employee Communications', 'mobile-dj-manager');
    ?>
</h1>
        <form name="mdjm_form_send_comms" id="mdjm_form_send_comms" method="post" enctype="multipart/form-data">
        	<?php 
    wp_nonce_field('send_comm_email', 'mdjm_nonce', true, true);
    ?>
			<?php 
    mdjm_admin_action_field('send_comm_email');
    ?>
            <input type="hidden" name="mdjm_email_from_address" id="mdjm_email_from_address" value="<?php 
    echo $current_user->user_email;
    ?>
" />
            <input type="hidden" name="mdjm_email_from_name" id="mdjm_email_from_name" value="<?php 
    echo $current_user->display_name;
    ?>
" />
            <?php 
    do_action('mdjm_pre_comms_table');
    ?>
            <table class="form-table">
                <?php 
    do_action('mdjm_add_comms_fields_before_recipient');
    ?>
                <tr>
                	<th scope="row"><label for="mdjm_email_to"><?php 
    _e('Select a Recipient', 'mobile-dj-manager');
    ?>
</label></th>
                    <td>
                    	<select name="mdjm_email_to" id="mdjm_email_to">
                        	<option value=""><?php 
    _e('Select a Recipient', 'mobile-dj-manager');
    ?>
</option>
                        	<optgroup label="<?php 
    _e('Clients', 'mobile-dj-manager');
    ?>
">
                            	<?php 
    if (empty($clients)) {
        echo '<option disabled="disabled">' . __('No Clients Found', 'mobile-dj-manager') . '</option>';
    } else {
        foreach ($clients as $client) {
            echo '<option value="' . $client->ID . '">' . $client->display_name . '</option>';
        }
    }
    ?>
                            </optgroup>
                            <?php 
    if (!empty($employees)) {
        echo '<optgroup label="' . __('Employees', 'mobile-dj-manager') . '">';
        foreach ($employees as $employee) {
            echo '<option value="' . $employee->ID . '">' . $employee->display_name . '</option>';
        }
        echo '</optgroup>';
    }
    ?>
                        </select>
                    </td>
                </tr>
                <?php 
    do_action('mdjm_add_comms_fields_before_subject');
    ?>
                <tr>
                	<th scope="row"><label for="mdjm_email_subject"><?php 
    _e('Subject', 'mobile-dj-manager');
    ?>
</label></th>
                    <td><input type="text" name="mdjm_email_subject" id="mdjm_email_subject" class="regular-text" value="<?php 
    echo isset($_GET['template']) ? esc_attr(get_the_title($_GET['template'])) : '';
    ?>
" /></td>
                </tr>
                <tr>
                	<th scope="row"><label for="mdjm_email_copy_to"><?php 
    _e('Copy Yourself?', 'mobile-dj-manager');
    ?>
</label></th>
                    <td><input type="checkbox" name="mdjm_email_copy_to" id="mdjm_email_copy_to" value="<?php 
    echo $current_user->user_email;
    ?>
" /> <span class="description"><?php 
    _e('Settings may dictate that additional email copies are also sent', 'mobile-dj-manager');
    ?>
</span></td>
                </tr>
                <?php 
    do_action('mdjm_add_comms_fields_before_template');
    ?>
            	<tr>
                	<th scope="row"><label for="mdjm_email_template"><?php 
    _e('Select a Template', 'mobile-dj-manager');
    ?>
</label></th>
                    <td>
                    	<select name="mdjm_email_template" id="mdjm_email_template">
                        	<option value="0"><?php 
    _e('No Template', 'mobile-dj-manager');
    ?>
</option>
                            <?php 
    $template = isset($_GET['template']) ? $_GET['template'] : 0;
    ?>
                        	<?php 
    echo mdjm_comms_template_options($template);
    ?>
                        </select>
                    </td>
                </tr>
                <?php 
    do_action('mdjm_add_comms_fields_before_event');
    ?>
                <tr>
                    <th scope="row"><label for="mdjm_email_event"><?php 
    printf(__('Associated %s', 'mobile-dj-manager'), mdjm_get_label_singular());
    ?>
</label></th>
                    <td>
                    	<?php 
    if (isset($_GET['event_id']) || isset($_GET['mdjm-action']) && $_GET['mdjm-action'] == 'respond_unavailable') {
        ?>
                        	<?php 
        $value = mdjm_get_event_date($_GET['event_id']) . ' ';
        $value .= __('from', 'mobile-dj-manager') . ' ';
        $value .= mdjm_get_event_start($_GET['event_id']) . ' ';
        $value .= '(' . mdjm_get_event_status($_GET['event_id']) . ')';
        ?>
							<input type="text" name="mdjm_email_event_show" id="mdjm_email_event_show" value="<?php 
        echo $value;
        ?>
" readonly="readonly" size="50" />
                            <input type="hidden" name="mdjm_email_event" id="mdjm_email_event" value="<?php 
        echo $_GET['event_id'];
        ?>
" />
                        <?php 
    } else {
        ?>
                            <select name="mdjm_email_event" id="mdjm_email_event">
                            <option value="0"><?php 
        _e('Select an Event', 'mobile-dj-manager');
        ?>
</option>
                            </select>
                        <?php 
    }
    ?>
                        <p class="description"><?php 
    printf(__('If no %s is selected <code>{event_*}</code> content tags may not be used', 'mobile-dj-manager'), mdjm_get_label_singular(true));
    ?>
</p>
                    </td>
                </tr>
                <?php 
    do_action('mdjm_add_comms_fields_before_file');
    ?>
                <tr>
                	<th scope="row"><label for="mdjm_email_upload_file"><?php 
    _e('Attach a File', 'mobile-dj-manager');
    ?>
</label></th>
                    <td><input type="file" name="mdjm_email_upload_file" id="mdjm_email_upload_file" class="regular-text" value="" />
                    	<p class="description"><?php 
    printf(__('Max file size %dMB. Change php.ini <code>post_max_size</code> to increase', 'mobile-dj-manager'), ini_get('post_max_size'));
    ?>
</p>
                    </td>
                </tr>
                <?php 
    do_action('mdjm_add_comms_fields_before_content');
    ?>
                <tr>
                    <td colspan="2">
                        <?php 
    $content = isset($_GET['template']) ? mdjm_get_email_template_content($_GET['template']) : '';
    wp_editor($content, 'mdjm_email_content', array('media_buttons' => true, 'textarea_rows' => '10', 'editor_class' => 'required'));
    ?>
                    </td>
                </tr>
            </table>
            <?php 
    do_action('mdjm_post_comms_table');
    ?>
            <?php 
    submit_button(__('Send Email', 'mobile-dj-manager'), 'primary', 'submit', true);
    ?>
        </form>
    </div>
    <?php 
}
 /**
  * Generate the role view filters
  *
  * @param
  *
  * @return	$views		Array of $view => $link
  */
 public function get_views()
 {
     global $wp_roles;
     $views = array();
     $current = self::$display_role;
     // All roles link
     $class = empty($current) || $current == 'all' ? ' class="current"' : '';
     $all_url = remove_query_arg('display_role');
     $views['all'] = '<a href="' . $all_url . '" ' . $class . '>' . __('All') . ' <span class="count">(' . self::$total_clients . ')</span></a>';
     // Loop through all roles and generate the required views for each
     $roles = array('client', 'inactive_client');
     foreach ($roles as $key => $role) {
         $count = count(mdjm_get_clients($role));
         if (empty($count)) {
             continue;
         }
         $class = $current == $role ? ' class="current"' : '';
         $role_url = add_query_arg('display_role', $role);
         $views[$role] = '<a href="' . $role_url . '" ' . $class . '>' . translate_user_role($wp_roles->roles[$role]['name']) . ' <span class="count">(' . $count . ')</span></a>';
     }
     if (!empty($_POST['s'])) {
         $class = $current == $role ? ' class="current"' : '';
         $views['search'] = '<a href="#" ' . $class . '>' . __('Search Results', 'mobile-dj-manager') . ' <span class="count">(' . count(self::$clients) . ')</span></a>';
     }
     return $views;
 }
Example #9
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 
}