Example #1
0
/**
 * Login Form
 *
 * @since	1.3
 * @global	$post
 * @param	str		$redirect	Redirect page URL
 * @return	str		Login form
 */
function mdjm_login_form($redirect = '')
{
    global $mdjm_login_redirect;
    if (empty($redirect)) {
        $redirect = mdjm_do_content_tags('{application_home}');
    }
    $mdjm_login_redirect = remove_query_arg('mdjm_message', $redirect);
    ob_start();
    mdjm_get_template_part('login', 'form');
    $output = ob_get_clean();
    $output = mdjm_do_content_tags($output);
    return apply_filters('mdjm_login_form', $output);
}
/**
 * Check the availability status for the given date
 *
 * @since	1.3
 * @param	Global $_POST
 * @return	arr
 */
function mdjm_do_availability_check_ajax()
{
    $date = $_POST['check_date'];
    $avail_text = !empty($_POST['avail_text']) ? $_POST['avail_text'] : mdjm_get_option('availability_check_pass_text');
    $unavail_text = !empty($_POST['unavail_text']) ? $_POST['unavail_text'] : mdjm_get_option('availability_check_fail_text');
    $search = array('{EVENT_DATE}', '{EVENT_DATE_SHORT}');
    $replace = array(date('l, jS F Y', strtotime($date)), mdjm_format_short_date($date));
    $result = mdjm_do_availability_check($date);
    if (!empty($result['available'])) {
        $result['result'] = 'available';
        $result['message'] = str_replace($search, $replace, $avail_text);
        $result['message'] = mdjm_do_content_tags($result['message']);
    } else {
        $result['result'] = 'unavailable';
        $result['message'] = str_replace($search, $replace, $unavail_text);
        $result['message'] = mdjm_do_content_tags($result['message']);
    }
    echo json_encode($result);
    die;
}
/**
 * Email the manual payment confirmation to the client from a customisable email template.
 *
 * @since	1.3
 * @param	int		$event_id		The event ID
 * @return	void
 */
function mdjm_email_manual_payment_confirmation($event_id)
{
    if (!mdjm_get_option('manual_payment_cfm_template')) {
        return;
    }
    $mdjm_event = mdjm_get_event($event_id);
    $from_name = mdjm_email_set_from_name('manual_payment', $mdjm_event);
    $from_name = apply_filters('mdjm_email_from_name', $from_name, 'manual_payment', $mdjm_event);
    $from_email = mdjm_email_set_from_address('manual_payment', $mdjm_event);
    $from_email = apply_filters('mdjm_email_from_address', $from_email, 'manual_payment', $mdjm_event);
    $client = get_userdata($mdjm_event->client);
    $to_email = $client->user_email;
    $subject = mdjm_email_set_subject(mdjm_get_option('manual_payment_cfm_template', false));
    $subject = apply_filters('mdjm_manual_payment_subject', wp_strip_all_tags($subject));
    $subject = mdjm_do_content_tags($subject, $event_id, $mdjm_event->client);
    $attachments = apply_filters('mdjm_manual_payment_attachments', array(), $mdjm_event);
    $message = mdjm_get_email_template_content(mdjm_get_option('manual_payment_cfm_template', false));
    $message = mdjm_do_content_tags($message, $event_id, $mdjm_event->client);
    $emails = MDJM()->emails;
    $emails->__set('event_id', $mdjm_event->ID);
    $emails->__set('from_name', $from_name);
    $emails->__set('from_address', $from_email);
    $headers = apply_filters('mdjm_manual_payment_headers', $emails->get_headers(), $event_id, $mdjm_event->client);
    $emails->__set('headers', $headers);
    $emails->__set('track', apply_filters('mdjm_track_email_manual_payment', mdjm_get_option('track_client_emails')));
    if (mdjm_get_option('bcc_admin_to_client')) {
        $emails->__set('copy_to', array(mdjm_get_option('system_email')));
    }
    $emails->send($to_email, $subject, $message, $attachments, sprintf(__('Payment received confirmation for %s', 'mobile-dj-manager'), mdjm_get_label_singular()));
}
/**
 * Display notice on front end.
 *
 * Check for super global $_GET['mdjm-message'] key and return message if set.
 *
 * @since	1.3
 * @param
 * @return	str		Out the relevant message to the browser.
 */
function mdjm_print_notices()
{
    if (!isset($_GET, $_GET['mdjm_message'])) {
        return;
    }
    if (isset($_GET['event_id'])) {
        $mdjm_event = new MDJM_Event($_GET['event_id']);
        echo mdjm_do_content_tags(mdjm_display_notice($_GET['mdjm_message']), $mdjm_event->ID, $mdjm_event->client);
    } else {
        echo mdjm_display_notice($_GET['mdjm_message']);
    }
}
 /**
  * Prepare and execute an availability check.
  *
  * @since	1.4
  * @return	void
  */
 public function availability_check()
 {
     $result = false;
     $response = array();
     if (!isset($this->request['date'])) {
         $this->missing_params('date');
     } else {
         do_action('mdjm_before_api_availability_check', $this);
         $date = $this->request['date'];
         $employees = isset($this->request['employees']) ? explode(',', $this->request['employees']) : '';
         $roles = isset($this->request['roles']) ? explode(',', $this->request['roles']) : '';
         $available_text = !empty($this->request['avail_text']) ? $this->request['avail_text'] : mdjm_get_option('availability_check_pass_text');
         $unavailable_text = !empty($this->request['unavail_text']) ? $this->request['unavail_text'] : mdjm_get_option('availability_check_fail_text');
         $search = array('{EVENT_DATE}', '{EVENT_DATE_SHORT}');
         $replace = array(date('l, jS F Y', strtotime($date)), mdjm_format_short_date($date));
         $result = mdjm_do_availability_check($date, $employees, $roles);
     }
     if ($result) {
         if (!empty($result['available'])) {
             $message = str_replace($search, $replace, $available_text);
             $response['availability'] = array('date' => $date, 'response' => 'available', 'employees' => $result['available'], 'message' => mdjm_do_content_tags($message));
         } else {
             $message = str_replace($search, $replace, $unavailable_text);
             $response['availability'] = array('date' => $date, 'response' => 'unavailable', 'employees' => '', 'message' => mdjm_do_content_tags($message));
         }
     }
     do_action('mdjm_after_api_availability_check', $this);
     $this->data = array_merge($this->data, $response);
     $this->output();
 }
Example #6
0
/**
 * MDJM Availability Checker Shortcode.
 *
 * Displays the MDJM Availability Checker form which allows clients to determine if you are
 * available on their chosen event date.
 * 
 * @since	1.3
 *
 * @return	string
 */
function mdjm_shortcode_availability($atts)
{
    $atts = shortcode_atts(array('label' => __('Select Date', 'mobile-dj-manager') . ':', 'label_class' => 'mdjm-label', 'field_class' => '', 'submit_text' => __('Check Availability', 'mobile-dj-manager'), 'submit_class' => '', 'please_wait_text' => __('Please wait...', 'mobile-dj-manager'), 'please_wait_class' => '', 'display' => 'horizontal'), $atts, 'mdjm-availability');
    $field_id = 'mdjm-availability-datepicker';
    $search = array('{label}', '{label_class}', '{field}', '{field_class}', '{submit_text}', '{submit_class}', '{please_wait_text}', '{please_wait_class}');
    $replace = array($atts['label'], $atts['label_class'], $field_id, $atts['field_class'], $atts['submit_text'], $atts['submit_class'], $atts['please_wait_text'], $atts['please_wait_class']);
    ob_start();
    mdjm_insert_datepicker(array('class' => '', 'id' => $field_id, 'altfield' => 'availability_check_date', 'mindate' => '1'));
    echo '<!-- ' . __('MDJM Availability Checker', 'mobile-dj-manager') . ' (' . MDJM_VERSION_NUM . ') -->';
    echo '<form name="mdjm-availability-check" id="mdjm-availability-check" method="post">';
    wp_nonce_field('do_availability_check', 'mdjm_nonce', true, true);
    mdjm_action_field('do_availability_check');
    echo '<input type="hidden" name="availability_check_date" id="availability_check_date" />';
    mdjm_get_template_part('availability', $atts['display'], true);
    echo '</form>';
    $output = ob_get_clean();
    $output = str_replace($search, $replace, $output);
    $output = mdjm_do_content_tags($output);
    $output .= '<!-- ' . __('MDJM Availability Checker', 'mobile-dj-manager') . ' (' . MDJM_VERSION_NUM . ') -->';
    return apply_filters('mdjm_availability_form', $output);
}
/**
 * Generates a new online quote for the event.
 *
 * Uses the quote template defined within settings unless $template_id is provided.
 *
 * @since	1.3
 * @param	int			$event_id		The event ID.
 * @param	int			$template_id	The template ID from which to create the quote.
 * @return	int			$quote_id		The ID of the newly created post or false on fail.
 */
function mdjm_create_online_quote($event_id, $template_id = '')
{
    $existing_id = mdjm_get_event_quote_id($event_id);
    $template_id = !empty($template_id) ? $template_id : mdjm_get_option('online_enquiry');
    if (empty($template_id)) {
        return false;
    }
    /**
     * Allow filtering of the quote template.
     *
     * @since	1.3
     * @param	$template_id
     */
    $template_id = apply_filters('mdjm_online_quote_template', $template_id);
    $template = get_post($template_id);
    if (!$template) {
        return false;
    }
    /**
     * Fire the `mdjm_pre_create_online_quote` hook.
     *
     * @since	1.3
     * @param	int		$event_id		The Event ID
     * @param	int		$template_id	The quote template ID
     * @param	obj		$template		The quote template WP_Post object
     */
    do_action('mdjm_pre_create_online_quote', $event_id, $template_id, $template);
    $client_id = mdjm_get_event_client_id($event_id);
    $content = $template->post_content;
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    $content = mdjm_do_content_tags($content, $event_id, $client_id);
    $args = array('ID' => $existing_id, 'post_date' => current_time('mysql'), 'post_modified' => current_time('mysql'), 'post_title' => sprintf(__('Quote %s', 'mobile-dj-manager'), mdjm_get_event_contract_id($event_id)), 'post_content' => $content, 'post_type' => 'mdjm-quotes', 'post_status' => 'mdjm-quote-generated', 'post_author' => !empty($client_id) ? $client_id : 1, 'post_parent' => $event_id, 'meta_input' => array('_mdjm_quote_viewed_date' => 0, '_mdjm_quote_viewed_count' => 0));
    /**
     * Allow filtering of the quote template args.
     *
     * @since	1.3
     * @param	$args
     */
    $args = apply_filters('mdjm_create_online_quote_args', $args);
    $quote_id = wp_insert_post($args);
    if (!$quote_id) {
        return false;
    }
    // Reset view date and count for existing quotes
    if (!empty($existing_id)) {
        delete_post_meta($quote_id, '_mdjm_quote_viewed_date');
        delete_post_meta($quote_id, '_mdjm_quote_viewed_count');
    }
    /**
     * Fire the `mdjm_post_create_online_quote` hook.
     *
     * @since	1.3
     * @param	int		$quote_id		The new quote ID
     */
    do_action('mdjm_pre_create_online_quote', $quote_id);
    return $quote_id;
}
/**
 * Sign the event contract
 *
 * @since	1.3
 * @param	int		$event_id	The event ID
 * @param	arr		$details	Contract and event info
 * @return	bool	Whether or not the contract was signed
 */
function mdjm_sign_event_contract($event_id, $details)
{
    $event = new MDJM_Event($event_id);
    if (!$event) {
        return false;
    }
    $contract_template = mdjm_get_contract(mdjm_get_event_contract($event->ID));
    if (!$contract_template) {
        return false;
    }
    do_action('mdjm_pre_sign_event_contract', $event_id, $details);
    // Prepare the content for the contract.
    $contract_content = $contract_template->post_content;
    $contract_content = apply_filters('the_content', $contract_content);
    $contract_content = str_replace(']]>', ']]&gt;', $contract_content);
    $contract_content = mdjm_do_content_tags($contract_content, $event->ID, $event->client);
    // The signatory information displayed at the foot of the contract
    $contract_signatory_content = '<hr>' . "\r\n";
    $contract_signatory_content .= '<p style="font-weight: bold">' . __('Signatory', 'mobile-dj-manager') . ': <span style="text-decoration: underline;">' . ucfirst($details['mdjm_first_name']) . ' ' . ucfirst($details['mdjm_last_name']) . '</span></p>' . "\r\n";
    $contract_signatory_content .= '<p style="font-weight: bold">' . __('Date of Signature', 'mobile-dj-manager') . ': <span style="text-decoration: underline;">' . date('jS F Y') . '</span></p>' . "\r\n";
    $contract_signatory_content .= '<p style="font-weight: bold">' . __('Verification Method', 'mobile-dj-manager') . ': ' . __('User Password Confirmation', 'mobile-dj-manager') . '</p>' . "\r\n";
    $contract_signatory_content .= '<p style="font-weight: bold">' . __('IP Address Used', 'mobile-dj-manager') . ': ' . $_SERVER['REMOTE_ADDR'] . '</p>' . "\r\n";
    $contract_signatory_content = apply_filters('mdjm_contract_signatory', $contract_signatory_content);
    $contract_content .= $contract_signatory_content;
    // Filter the signed contract post data
    $signed_contract = apply_filters('mdjm_signed_contract_data', array('post_title' => sprintf(__('Event Contract: %s', 'mobile-dj-manager'), mdjm_get_option('event_prefix') . $event->ID), 'post_author' => get_current_user_id(), 'post_type' => 'mdjm-signed-contract', 'post_status' => 'publish', 'post_content' => $contract_content, 'post_parent' => $event->ID, 'ping_status' => 'closed', 'comment_status' => 'closed'), $event->ID, $event);
    $signed_contract_id = wp_insert_post($signed_contract, true);
    if (is_wp_error($signed_contract_id)) {
        return false;
    }
    add_post_meta($signed_contract, '_mdjm_contract_signed_name', ucfirst($details['mdjm_first_name']) . ' ' . ucfirst($details['mdjm_last_name']), true);
    $event_meta = array('_mdjm_event_signed_contract' => $signed_contract_id, '_mdjm_event_contract_approved' => current_time('mysql'), '_mdjm_event_contract_approver' => strip_tags(addslashes(ucfirst($details['mdjm_first_name']) . ' ' . ucfirst($details['mdjm_last_name']))), '_mdjm_event_contract_approver_ip' => $_SERVER['REMOTE_ADDR'], '_mdjm_event_last_updated_by' => get_current_user_id());
    // Update the event status
    mdjm_update_event_status($event->ID, 'mdjm-approved', $event->post_status, array('meta' => $event_meta, 'client_notices' => mdjm_get_option('booking_conf_to_client')));
    mdjm_add_journal(array('user' => get_current_user_id(), 'event' => $event->ID, 'comment_content' => __('Contract Approval completed by ', 'mobile-dj-manager') . ucfirst($details['mdjm_first_name']) . ' ' . ucfirst($details['mdjm_last_name'] . '<br>')), array('type' => 'update-event', 'visibility' => '2'));
    do_action('mdjm_post_sign_event_contract', $event_id, $details);
    return true;
}