/**
 * Accept an enquiry.
 *
 * When a client clicks the Book Event button to accept an enquiry
 * transition the event to the awaiting contract status.
 *
 * @since	1.3
 * @param	arr		$data	Data for the transition.
 * @return	bool	True on succes, otherwise false
 */
function mdjm_accept_enquiry($data)
{
    global $current_user;
    $mdjm_event = mdjm_get_event($data['event_id']);
    if (!$mdjm_event) {
        return false;
    }
    do_action('mdjm_pre_event_accept_enquiry', $mdjm_event->ID, $data);
    $data['meta'] = array('_mdjm_event_enquiry_accepted' => current_time('mysql'), '_mdjm_event_enquiry_accepted_by' => $current_user->ID);
    $data['client_notices'] = mdjm_get_option('contract_to_client');
    if (!mdjm_update_event_status($mdjm_event->ID, 'mdjm-contract', $mdjm_event->post_status, $data)) {
        return false;
    }
    mdjm_add_journal(array('user' => get_current_user_id(), 'event' => $mdjm_event->ID, 'comment_content' => sprintf(__('%s has accepted their event enquiry', 'mobile-dj-manager'), $current_user->display_name . '<br>')), array('type' => 'update-event', 'visibility' => '2'));
    $content = '<html>' . "\n" . '<body>' . "\n";
    $content .= '<p>' . sprintf(__('Good news... %s has just accepted their %s quotation via %s', 'mobile-dj-manager'), '{client_fullname}', mdjm_get_label_singular(true), '{application_name}') . '</p>';
    $content .= '<hr />' . "\n";
    $content .= '<h4>' . sprintf(__('<a href="%s">%s ID: %s</a>', 'mobile-dj-manager'), admin_url('post.php?post=' . $mdjm_event->ID . '&action=edit'), mdjm_get_label_singular(), '{contract_id}') . '</h4>' . "\n";
    $content .= '<p>' . sprintf(__('Date: %s', 'mobile-dj-manager'), '{event_date}') . '<br />' . "\n";
    $content .= __('Type', 'mobile-dj-manager') . ': ' . mdjm_get_event_type($mdjm_event->ID) . '<br />' . "\n";
    $content .= __('Status', 'mobile-dj-manager') . ': ' . mdjm_get_event_status($mdjm_event->ID) . '<br />' . "\n";
    $content .= __('Client', 'mobile-dj-manager') . ': {client_fullname}<br />' . "\n";
    $content .= __('Value', 'mobile-dj-manager') . ': {total_cost}<br />' . "\n";
    $content .= __('Deposit', 'mobile-dj-manager') . ': {deposit} ({deposit_status})<br />' . "\n";
    $content .= __('Balance Due', 'mobile-dj-manager') . ': {balance}</p>' . "\n";
    $content .= '<p>' . sprintf(__('<a href="%s">View %s</a>', 'mobile-dj-manager'), admin_url('post.php?post=' . $mdjm_event->ID . '&action=edit'), mdjm_get_label_singular()) . '</p>' . "\n";
    $content .= '</body>' . "\n" . '</html>' . "\n";
    $args = array('to_email' => mdjm_get_option('system_email'), 'event_id' => $mdjm_event->ID, 'client_id' => $mdjm_event->client, 'subject' => sprintf(__('%s Quotation Accepted', 'mobile-dj-manager'), mdjm_get_label_singular()), 'message' => $content, 'copy_to' => 'disabled');
    mdjm_send_email_content($args);
    do_action('mdjm_post_event_accept_enquiry', $mdjm_event->ID, $data);
    return true;
}
Esempio n. 2
0
/**
 * Fires after an event's status is updated.
 *
 * Add journal entry.
 *
 * @since	1.3
 * @param	int|bool	$result			The result of the status change function. False is an unsuccessful status update.
 * @param	int			$event_id		The event ID.
 * @param	str			$new_status		The new event status.
 * @param	str			$old_status		The old event status.
 * @param	arr			$args			Arguments passed to the mdjm_update_event_status function
 * @return	void
 */
function mdjm_event_add_journal_after_status_change($result, $event_id, $new_status, $old_status, $args)
{
    if (empty($result)) {
        return;
    }
    $reject_reason = $new_status == 'mdjm-rejected' && !empty($args['reject_reason']) ? '<br />' . $args['reject_reason'] : '';
    $comment_args = array('user_id' => is_user_logged_in() ? get_current_user_id() : 1, 'event_id' => $event_id, 'comment_content' => sprintf(__('%s status updated to %s.%s', 'mobile-dj-manager'), mdjm_get_label_singular(), mdjm_get_event_status($event_id), $reject_reason));
    mdjm_add_journal($comment_args);
}
Esempio n. 3
0
 function update_event()
 {
     global $mdjm, $post, $my_mdjm, $clientzone;
     $post = get_post($_POST['event_id']);
     $eventinfo = MDJM()->events->event_detail($post->ID);
     if (MDJM_DEBUG == true) {
         MDJM()->debug->log_it('Event ID ' . $post->ID . ' is being updated by ' . $eventinfo['client']->display_name, true);
     }
     // Prepare the meta data
     $event_data['_mdjm_event_last_updated_by'] = $my_mdjm['me']->ID;
     $event_data['_mdjm_event_name'] = !empty($_POST['_mdjm_event_name']) ? sanitize_text_field($_POST['_mdjm_event_name']) : get_term($_POST['mdjm_event_type'], 'event-types')->name;
     $event_data['_mdjm_event_package'] = !empty($_POST['_mdjm_event_package']) ? $_POST['_mdjm_event_package'] : '';
     $event_data['_mdjm_event_addons'] = !empty($_POST['event_addons']) ? $_POST['event_addons'] : '';
     $event_data['_mdjm_event_notes'] = !empty($_POST['_mdjm_event_notes']) ? sanitize_text_field($_POST['_mdjm_event_notes']) : '';
     /* -- Assign the event type -- */
     $existing_event_type = wp_get_object_terms($post->ID, 'event-types');
     if (!isset($existing_event_type[0]) || $existing_event_type[0]->term_id != $_POST['mdjm_event_type']) {
         $field_updates[] = 'Event Type changed from ' . $existing_event_type[0]->name . ' to ' . get_term($_POST['mdjm_event_type'], 'event-types')->name;
         MDJM()->events->mdjm_assign_event_type($_POST['mdjm_event_type']);
     }
     // Event Times
     if (date('H:i', strtotime($_POST['event_start_hr'] . ':' . $_POST['event_start_min'])) != $eventinfo['start']) {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('Event start time updating to ' . $_POST['event_start_hr'] . ':' . $_POST['event_start_min']);
         }
         $event_data['_mdjm_event_start'] = MDJM_TIME_FORMAT == 'H:i' ? date('H:i:s', strtotime($_POST['event_start_hr'] . ':' . $_POST['event_start_min'])) : date('H:i:s', strtotime($_POST['event_start_hr'] . ':' . $_POST['event_start_min'] . isset($_POST['event_start_period']) ? $_POST['event_start_period'] : ''));
     }
     if (date('H:i', strtotime($_POST['event_finish_hr'] . ':' . $_POST['event_finish_min'])) != $eventinfo['finish']) {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('Event finish time updating to ' . $_POST['event_finish_hr'] . ':' . $_POST['event_finish_min']);
         }
         $event_data['_mdjm_event_finish'] = MDJM_TIME_FORMAT == 'H:i' ? date('H:i:s', strtotime($_POST['event_finish_hr'] . ':' . $_POST['event_finish_min'])) : date('H:i:s', strtotime($_POST['event_finish_hr'] . ':' . $_POST['event_finish_min'] . isset($_POST['event_finish_period']) ? $_POST['event_finish_period'] : ''));
     }
     remove_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
     // Update event
     wp_update_post(array('ID' => $post->ID));
     // Update meta
     foreach ($event_data as $event_meta_key => $event_meta_value) {
         /* -- If we have a value and the key did not exist previously, add it -- */
         if (!empty($event_meta_value) && '' == get_post_meta($post->ID, $event_meta_key, true)) {
             add_post_meta($post->ID, $event_meta_key, $event_meta_value);
             $field_updates[] = 'Field ' . $event_meta_key . ' added: ' . is_array($event_meta_value) ? implode('<br />', $event_meta_value) : $event_meta_value;
         } elseif (!empty($event_meta_value) && $event_meta_value != get_post_meta($post->ID, $event_meta_key, true)) {
             update_post_meta($post->ID, $event_meta_key, $event_meta_value);
             $field_updates[] = 'Field ' . $event_meta_key . ' updated: ' . get_post_meta($post->ID, $event_meta_key, true) . ' replaced with ' . $event_meta_value;
         } elseif ('' == $event_meta_value && get_post_meta($post->ID, $event_meta_key, true)) {
             delete_post_meta($post->ID, $event_meta_key, $event_meta_value);
             $field_updates[] = 'Field ' . $event_meta_key . ' updated: ' . get_post_meta($post->ID, $event_meta_key, true) . ' removed';
         }
         // Log changes to debug file
         if (MDJM_DEBUG == true && !empty($field_updates)) {
             MDJM()->debug->log_it('Event Updates Completed     ' . "\r\n" . '| ' . implode("\r\n" . '     | ', $field_updates));
         }
     }
     add_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
     // Update journal
     mdjm_add_journal(array('user_id' => $my_mdjm['me']->ID, 'event_id' => $post->ID, 'comment_content' => $my_mdjm['me']->display_name . ' updated event - ' . $post->ID . '<br />(' . time() . ')'), array('type' => 'update-event', 'visibility' => '1'));
     $clientzone->display_notice('2', 'Your event details have been updated successfully');
 }
Esempio n. 4
0
 /**
  * Prepare and send an email
  * 
  * 
  *
  * @param    array	$args
  *						Required: content 		str			post ID or email content as str
  *						Required: to	 		str|int		email address or user ID of recipient
  *						Optional: subject		str			required if content is not a post ID
  *						Optional: from			int			user ID of sender, defaults to 0 (system)
  *						Optional: attachments	arr			files to attach
  *						Optional: journal		str|bool	The journal entry type or false not to log this action, default to 'email-client'
  *						Optional: event_id		int			event ID
  *						Optional: html			bool		true sends html (Default) false plain text
  *						Optional: cc_dj			bool		true sends copy to DJ false does not, only applicable if we have event. Default per settings
  *						Optional: cc_admin		bool		true sends copy to Admin false does not. Default per settings
  *						Optional: source		str			what initiated the email - i.e. Event Enquiry (Default)
  *						Optional: filter		bool		true (Default) filters subject and content for shortcode, false does not
  *						Optional: add_filters	arr			An array with key {SEARCH} and value $replace for additional filters to process
  *						Optional: log_comm		bool		true (Default) logs the email, false does not
  *
  * @return   str	$comm_id	The communication post ID if the email was successfully sent
  * @since    1.1.3
  */
 function send_email($args)
 {
     global $mdjm_settings;
     if (MDJM_DEBUG == true) {
         MDJM()->debug->log_it('Starting ' . __FUNCTION__, true);
     }
     /* -- Error checking -- */
     if (!is_numeric($args['content']) && empty($args['subject'])) {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('	ERROR: Missing `subject` argument');
         }
         return false;
     }
     $content = !empty($args['content']) ? $args['content'] : '';
     $to = !empty($args['to']) ? $args['to'] : '';
     $subject = !is_numeric($content) && !empty($args['subject']) ? $args['subject'] : get_the_title($content);
     $sender = !empty($args['from']) ? $args['from'] : 1;
     if (empty($to)) {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('	ERROR: Missing `to` argument');
         }
         return false;
     }
     if (empty($content)) {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('	ERROR: Missing `content` argument');
         }
         return false;
     }
     $journal = !empty($args['journal']) ? $args['journal'] : 'email-client';
     $cc_dj = isset($args['cc_dj']) ? $args['cc_dj'] : (isset($mdjm_settings['email']['bcc_dj_to_client']) ? true : false);
     $cc_admin = isset($args['cc_admin']) ? $args['cc_admin'] : (isset($mdjm_settings['email']['bcc_admin_to_client']) ? true : false);
     $filter = isset($args['filter']) ? $args['filter'] : true;
     $log_comm = isset($args['log_comm']) ? $args['log_comm'] : MDJM_TRACK_EMAILS;
     /* -- Do we have an event? -- */
     $event = !empty($args['event_id']) && is_numeric($args['event_id']) ? get_post($args['event_id']) : '';
     if (!empty($event)) {
         /* -- Get the DJ -- */
         if ($cc_dj == true) {
             $event_dj = get_post_meta($event->ID, '_mdjm_event_dj', true);
             $dj = get_user_by('ID', $event_dj);
         }
     }
     $html = isset($args['html']) ? $args['html'] : true;
     /* -- Set the correct values -- */
     $recipient = is_numeric($to) ? get_userdata($to) : get_user_by('email', $to);
     if (!$recipient) {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('	ERROR: User `' . $to . '` does not exist ');
         }
         return false;
     }
     if ($sender != 0) {
         $sender_data = get_userdata($sender);
     }
     $from = isset($sender_data) ? $sender_data->display_name . ' <' . $mdjm_settings['email']['system_email'] . '>' : MDJM_COMPANY . ' <' . $mdjm_settings['email']['system_email'] . '>';
     /* -- Set the message content -- */
     if (is_numeric($content)) {
         /* -- For a template -- */
         if (is_string(get_post_status($content))) {
             if (MDJM_DEBUG == true) {
                 MDJM()->debug->log_it('	ERROR: Specified template `' . $content . '` does not exist');
             }
             return false;
         }
         $p = get_post($content);
         $message = $p->post_content;
         $message = apply_filters('the_content', $message);
         $message = str_replace(']]>', ']]&gt;', $message);
     } else {
         /* -- Not a template -- */
         $message = $content;
     }
     /* -- Additional copies of the email to be sent to -- */
     $copy_dj = $cc_dj == true && !empty($dj) ? $dj->user_email : false;
     $copy_admin = $cc_admin == true ? $mdjm_settings['email']['system_email'] : false;
     if (!empty($copy_dj)) {
         $copy_to[] = $copy_dj;
     }
     if (!empty($copy_admin)) {
         $copy_to[] = $copy_admin;
     }
     /* -- Headers -- */
     if ($html != false) {
         $headers[] = 'MIME-Version: 1.0' . "\r\n";
         $headers[] = 'Content-type: text/html; charset=UTF-8' . "\r\n";
     }
     $headers[] = 'From: ' . $from . '>' . "\r\n";
     if (isset($sender_data)) {
         $headers[] = 'Reply-To: ' . $sender_data->user_email . "\r\n";
     }
     $headers[] = 'X-Mailer: ' . MDJM_NAME . ' version ' . MDJM_VERSION_NUM . ' (http://mdjm.co.uk)';
     // Filter the email headers
     $headers = apply_filters('mdjm_email_headers', $headers);
     if ($filter == true) {
         /* -- Filter the content -- */
         $msg = $this->filter_content(!empty($recipient) ? $recipient->ID : '', !empty($event) ? $event->ID : '', $message);
         /* -- Filter the subject -- */
         $sub = $this->filter_content(!empty($recipient) ? $recipient->ID : '', !empty($event) ? $event->ID : '', $subject);
     } else {
         $msg = $message;
         $sub = $subject;
     }
     /* -- Additional filters -- */
     if (!empty($args['add_filters']) && is_array($args['add_filters'])) {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('Additional content filtering requested...');
         }
         foreach ($args['add_filters'] as $key => $value) {
             $search[] = $key;
             $replace[] = $value;
         }
         $sub = str_replace($search, $replace, $sub);
         $msg = str_replace($search, $replace, $msg);
     }
     // File attachments
     if (!empty($args['attachments']) && is_array($args['attachments'])) {
         $files = $args['attachments'];
     } else {
         $files = array();
     }
     // Apply filter to attach (additional) files to an email
     $files = apply_filters('mdjm_attach_files_to_email', $files);
     /* -- Add the COMM post -- */
     if ($log_comm == true) {
         if (!class_exists('MDJM_Communication')) {
             require_once MDJM_PLUGIN_DIR . '/includes/admin/communications/mdjm-communications.php';
         }
         $mdjm_comms = new MDJM_Communication();
         $comm_post = $mdjm_comms->insert_comm(array('subject' => $sub, 'content' => $msg, 'recipient' => !empty($recipient) ? $recipient->ID : '', 'source' => !empty($args['source']) ? $args['source'] : 'Event Enquiry', 'event' => !empty($event) ? $event->ID : '', 'author' => $sender, 'attachments' => !empty($files) ? $files : ''));
         if (empty($comm_post) && MDJM_DEBUG == true) {
             MDJM()->debug->log_it('Could not create Comm post in ' . __FUNCTION__, true);
         } elseif (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('Comm post created with ID `' . $comm_post . '` ', true);
         }
     } else {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('Skipping communication logging by command');
         }
     }
     /* -- Send the email to the client with stat tracking if configured -- */
     if (wp_mail($recipient->user_email, $sub, $msg . (!empty($comm_post) ? $mdjm_comms->insert_stat_image($comm_post) : ''), $headers, $files)) {
         /* -- Set the status of the email -- */
         if ($log_comm == true) {
             $mdjm_comms->change_email_status($comm_post, 'sent');
         }
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('	-- Message "' . $sub . '" successfully sent to "' . $recipient->display_name . '"');
         }
         /* -- Update Journal -- */
         if (!empty($journal) && !empty($event)) {
             mdjm_add_journal(array('user_id' => !empty($sender_data->ID) ? $sender_data->ID : '1', 'event_id' => $event->ID, 'comment_content' => 'Email sent to Client - ' . $sub . '<br />(' . time() . ')'), array('type' => $journal, 'visibility' => '1'));
         }
     } else {
         /* -- Set the status of the email -- */
         $mdjm_comms->change_email_status($comm_post, 'failed');
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('	ERROR: Message "' . $sub . '" could not be sent to "' . $recipient->display_name . '"');
         }
         return false;
     }
     /* -- And now send the message to anyone else who needs a copy. No tracking here -- */
     if (!empty($copy_to)) {
         /* -- Prefix with status -- */
         $msg_prefix = '<hr size="1" />';
         $msg_prefix .= '<p style="font-size: 11px;">The following message was recently sent to ' . $recipient->display_name . ' via ' . MDJM_APP . '.<br />' . "\r\n";
         $msg_prefix .= 'You are receiving a copy of this message either because you chose to do so, or the  ' . MDJM_APP . ' application settings dictate that you do so.';
         $msg_prefix .= '<br /></p>' . "\r\n";
         $msg_prefix .= '<hr size="1" />';
         foreach ($copy_to as $mdjm_recipient) {
             if (wp_mail($mdjm_recipient, $sub, $msg_prefix . $msg, $headers, $files)) {
                 if (MDJM_DEBUG == true) {
                     MDJM()->debug->log_it('	-- A copy of the message "' . $sub . '" successfully sent to ' . $mdjm_recipient);
                 }
             } else {
                 if (MDJM_DEBUG == true) {
                     MDJM()->debug->log_it('	ERROR: A copy of the message "' . $sub . '" could not be sent to ' . $mdjm_recipient);
                 }
             }
         }
     }
     if (MDJM_DEBUG == true) {
         MDJM()->debug->log_it('Completed ' . __FUNCTION__, true);
     }
     return isset($comm_post) ? $comm_post : true;
 }
Esempio n. 5
0
/**
 * Save the event transaction
 *
 *
 */
function mdjm_save_event_transaction_ajax()
{
    global $mdjm_event;
    $result = array();
    $mdjm_event = new MDJM_Event($_POST['event_id']);
    $mdjm_txn = new MDJM_Txn();
    $txn_data = array('post_parent' => $_POST['event_id'], 'post_author' => $mdjm_event->client, 'post_status' => $_POST['direction'] == 'Out' ? 'mdjm-expenditure' : 'mdjm-income', 'post_date' => date('Y-m-d H:i:s', strtotime($_POST['date'])));
    $txn_meta = array('_mdjm_txn_status' => 'Completed', '_mdjm_payment_from' => $mdjm_event->client, '_mdjm_txn_total' => $_POST['amount'], '_mdjm_payer_firstname' => mdjm_get_client_firstname($mdjm_event->client), '_mdjm_payer_lastname' => mdjm_get_client_lastname($mdjm_event->client), '_mdjm_payer_email' => mdjm_get_client_email($mdjm_event->client), '_mdjm_payment_from' => mdjm_get_client_display_name($mdjm_event->client), '_mdjm_txn_source' => $_POST['src']);
    if ($_POST['direction'] == 'In') {
        if (!empty($_POST['from'])) {
            $txn_meta['_mdjm_payment_from'] = sanitize_text_field($_POST['from']);
        } else {
            $txn_meta['_mdjm_payment_from'] = mdjm_get_client_display_name($mdjm_event->client);
        }
    }
    if ($_POST['direction'] == 'Out') {
        if (!empty($_POST['to'])) {
            $txn_meta['_mdjm_payment_to'] = sanitize_text_field($_POST['to']);
        } else {
            $txn_meta['_mdjm_payment_to'] = mdjm_get_client_display_name($mdjm_event->client);
        }
    }
    $mdjm_txn->create($txn_data, $txn_meta);
    if ($mdjm_txn->ID > 0) {
        $result['type'] = 'success';
        mdjm_set_txn_type($mdjm_txn->ID, $_POST['for']);
        $args = array('user_id' => get_current_user_id(), 'event_id' => $_POST['event_id'], 'comment_content' => sprintf(__('%1$s payment of %2$s received for %3$s %4$s.', 'mobile-dj-manager'), $_POST['direction'] == 'In' ? __('Incoming', 'mobile-dj-manager') : __('Outgoing', 'mobile-dj-manager'), mdjm_currency_filter(mdjm_format_amount($_POST['amount'])), mdjm_get_label_singular(true), mdjm_get_event_contract_id($_POST['event_id'])));
        mdjm_add_journal($args);
        // Email overide
        if (empty($_POST['send_notice']) && mdjm_get_option('manual_payment_cfm_template')) {
            $manual_email_template = mdjm_get_option('manual_payment_cfm_template');
            mdjm_update_option('manual_payment_cfm_template', 0);
        }
        $payment_for = $mdjm_txn->get_type();
        $amount = mdjm_currency_filter(mdjm_format_amount($_POST['amount']));
        mdjm_add_content_tag('payment_for', __('Reason for payment', 'mobile-dj-manager'), function () use($payment_for) {
            return $payment_for;
        });
        mdjm_add_content_tag('payment_amount', __('Payment amount', 'mobile-dj-manager'), function () use($amount) {
            return $amount;
        });
        mdjm_add_content_tag('payment_date', __('Date of payment', 'mobile-dj-manager'), 'mdjm_content_tag_ddmmyyyy');
        /**
         * Allow hooks into this payment. The hook is suffixed with 'in' or 'out' depending
         * on the payment direction. i.e. mdjm_post_add_manual_txn_in and mdjm_post_add_manual_txn_out
         *
         * @since	1.3.7
         * @param	int		$event_id
         * @param	obj		$txn_id
         */
        do_action('mdjm_post_add_manual_txn_' . strtolower($_POST['direction']), $_POST['event_id'], $mdjm_txn->ID);
        // Email overide
        if (empty($_POST['send_notice']) && isset($manual_email_template)) {
            mdjm_update_option('manual_payment_cfm_template', $manual_email_template);
        }
        $result['deposit_paid'] = 'N';
        $result['balance_paid'] = 'N';
        if ($mdjm_event->get_remaining_deposit() < 1) {
            mdjm_update_event_meta($mdjm_event->ID, array('_mdjm_event_deposit_status' => 'Paid'));
            $result['deposit_paid'] = 'Y';
        }
        if ($mdjm_event->get_balance() < 1) {
            mdjm_update_event_meta($mdjm_event->ID, array('_mdjm_event_balance_status' => 'Paid'));
            mdjm_update_event_meta($mdjm_event->ID, array('_mdjm_event_deposit_status' => 'Paid'));
            $result['balance_paid'] = 'Y';
            $result['deposit_paid'] = 'Y';
        }
    } else {
        $result['type'] = 'error';
        $result['msg'] = __('Unable to add transaction', 'mobile-dj-manager');
    }
    ob_start();
    mdjm_do_event_txn_table($_POST['event_id']);
    $result['transactions'] = ob_get_contents();
    ob_get_clean();
    echo json_encode($result);
    die;
}
Esempio n. 6
0
/**
 * Updates an event once a payment is completed.
 *
 * @since	1.3.8
 * @param	arr		$txn_data	Transaction data from gateway.
 * @return	void
 */
function mdjm_update_event_after_payment($txn_data)
{
    $type = mdjm_get_txn_type($txn_data['txn_id']);
    if ($type == mdjm_get_deposit_label()) {
        $meta['_mdjm_event_deposit_status'] = 'Paid';
    } else {
        if ($type == mdjm_get_balance_label()) {
            $meta['_mdjm_event_deposit_status'] = 'Paid';
            $meta['_mdjm_event_balance_status'] = 'Paid';
        } else {
            if (mdjm_get_event_remaining_deposit($txn_data['event_id']) < 1) {
                $meta['_mdjm_event_deposit_status'] = 'Paid';
            }
            if (mdjm_get_event_balance($txn_data['event_id']) < 1) {
                $meta['_mdjm_event_deposit_status'] = 'Paid';
                $meta['_mdjm_event_balance_status'] = 'Paid';
            }
        }
    }
    mdjm_update_event_meta($txn_data['event_id'], $meta);
    // Update the journal
    mdjm_add_journal(array('user_id' => $txn_data['client_id'], 'event_id' => $txn_data['event_id'], 'comment_content' => sprintf(__('%s of %s received via %s', 'mobile-dj-manager'), $type, mdjm_currency_filter(mdjm_format_amount($txn_data['total'])), mdjm_get_gateway_admin_label($txn_data['gateway']))));
}
Esempio n. 7
0
        public function sign_contract()
        {
            global $mdjm, $my_mdjm, $clientzone, $mdjm_settings;
            /* -- Validate the nonce -- */
            if (!isset($_POST['mdjm_sign_event_contract']) || !wp_verify_nonce($_POST['mdjm_sign_event_contract'], 'sign_event_contract')) {
                echo '<script type="text/javascript">' . "\r\n" . 'alert("WordPress Security Validation failed. Please try again");' . "\r\n" . 'history.back();' . "\r\n" . '</script>' . "\r\n";
            }
            /* -- Check the users password is correct -- */
            $pass_cfm = wp_authenticate($my_mdjm['me']->user_login, $_POST['sign_pass_confirm']);
            /* -- Incorrect Password -- */
            if (is_wp_error($pass_cfm)) {
                echo '<script type="text/javascript">' . "\r\n" . 'alert("ERROR: Your password was not entered correctly. Please try again.");' . "\r\n" . 'history.back();' . "\r\n" . '</script>' . "\r\n";
            } else {
                /* -- Remove the save post hook to avoid loops -- */
                remove_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
                /* -- Create a new signed contract instance -- */
                $contract_data = array('post_title' => 'Event Contract: ' . MDJM_EVENT_PREFIX . $this->event->ID, 'post_author' => $my_mdjm['me']->ID, 'post_type' => 'mdjm-signed-contract', 'post_status' => 'publish', 'post_parent' => $this->event->ID, 'ping_status' => 'closed', 'comment_status' => 'closed');
                /* -- Prepare the contract content -- */
                $content = $this->event_contract->post_content;
                $content = apply_filters('the_content', $content);
                $content = str_replace(']]>', ']]&gt;', $content);
                /* -- Shortcode replacements -- */
                $contract_data['post_content'] = $mdjm->filter_content($my_mdjm['me']->ID, $this->event->ID, $content);
                /* -- Append Signatory info -- */
                $contract_data['post_content'] .= '<hr>' . "\r\n";
                $contract_data['post_content'] .= '<p style="font-weight: bold">' . __('Signatory') . ': <span style="text-decoration: underline;">' . ucfirst($_POST['sign_first_name']) . ' ' . ucfirst($_POST['sign_last_name']) . '</span></p>' . "\r\n";
                $contract_data['post_content'] .= '<p style="font-weight: bold">' . __('Date of Signature') . ': <span style="text-decoration: underline;">' . date('jS F Y') . '</span></p>' . "\r\n";
                $contract_data['post_content'] .= '<p style="font-weight: bold">' . __('Verification Method') . ': User Password Confirmation</p>' . "\r\n";
                /* -- Create the Signed Contract Post -- */
                $signed_contract = wp_insert_post($contract_data, true);
                // Success
                if (!is_wp_error($signed_contract)) {
                    if (MDJM_DEBUG == true) {
                        MDJM()->debug->log_it('Client event signed contract created (' . $signed_contract . ')', true);
                    }
                    add_post_meta($signed_contract, '_mdjm_contract_signed_name', ucfirst($_POST['sign_first_name']) . ' ' . ucfirst($_POST['sign_last_name']), true);
                    /* -- Update the event -- */
                    $event_meta = array('_mdjm_event_signed_contract' => $signed_contract, '_mdjm_event_contract_approved' => date('Y-m-d H:i:s'), '_mdjm_event_contract_approver' => ucfirst($_POST['sign_first_name']) . ' ' . ucfirst($_POST['sign_last_name']), '_mdjm_event_contract_approver_ip' => $_SERVER['REMOTE_ADDR'], '_mdjm_event_last_updated_by' => $my_mdjm['me']->ID);
                    /* -- Initiate actions for status change -- */
                    wp_transition_post_status('mdjm-approved', $this->event->post_status, $this->event);
                    /* -- Update the post status -- */
                    wp_update_post(array('ID' => $this->event->ID, 'post_status' => 'mdjm-approved'));
                    foreach ($event_meta as $event_meta_key => $event_meta_value) {
                        update_post_meta($this->event->ID, $event_meta_key, $event_meta_value);
                    }
                    /* -- Update Journal with event updates -- */
                    if (MDJM_JOURNAL == true) {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('	-- Adding journal entry');
                        }
                        mdjm_add_journal(array('user_id' => $my_mdjm['me']->ID, 'event_id' => $this->event->ID, 'comment_content' => 'Contract Approval completed by ' . ucfirst($_POST['sign_first_name']) . ' ' . ucfirst($_POST['sign_last_name'] . '<br>')), array('type' => 'update-event', 'visibility' => '2'));
                    } else {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('	-- Journalling is disabled');
                        }
                    }
                    /* -- Email booking confirmations -- */
                    $contact_client = isset($mdjm_settings['templates']['booking_conf_to_client']) ? true : false;
                    $contact_dj = isset($mdjm_settings['templates']['booking_conf_to_dj']) ? true : false;
                    $client_email = isset($mdjm_settings['templates']['booking_conf_client']) ? $mdjm_settings['templates']['booking_conf_client'] : false;
                    $dj_email = isset($mdjm_settings['templates']['email_dj_confirm']) ? $mdjm_settings['templates']['email_dj_confirm'] : false;
                    if (!is_string(get_post_status($client_email))) {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('ERROR: No email template for the contract has been found ' . __FUNCTION__, $stampit = true);
                        }
                        wp_die('ERROR: Either no email template is defined or an error has occured. Check your Settings.');
                    }
                    if ($contact_client == true) {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('Configured to email client with template ID ' . $client_email);
                        }
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('Generating email...');
                        }
                        $email_args = array('content' => $client_email, 'to' => get_post_meta($this->event->ID, '_mdjm_event_client', true), 'from' => $mdjm_settings['templates']['booking_conf_from'] == 'dj' ? get_post_meta($this->event->ID, '_mdjm_event_dj', true) : 0, 'journal' => 'email-client', 'event_id' => $this->event->ID, 'html' => true, 'cc_dj' => isset($mdjm_settings['email']['bcc_dj_to_client']) ? true : false, 'cc_admin' => isset($mdjm_settings['email']['bcc_admin_to_client']) ? true : false, 'source' => 'Event Status to Approved');
                        // Filter the email args
                        $email_args = apply_filters('mdjm_booking_conf_email_args', $email_args);
                        // Send the email
                        $approval_email = $mdjm->send_email($email_args);
                        if ($approval_email) {
                            if (MDJM_DEBUG == true) {
                                MDJM()->debug->log_it('	-- Confrmation email sent to client ');
                            }
                        } else {
                            if (MDJM_DEBUG == true) {
                                MDJM()->debug->log_it('	ERROR: Confrmation email was not sent');
                            }
                        }
                    } else {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('Not configured to email client');
                        }
                    }
                    if ($contact_dj == true) {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('Configured to email DJ with template ID ' . $dj_email);
                        }
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('Generating email...');
                        }
                        $approval_dj_email = $mdjm->send_email(array('content' => $dj_email, 'to' => get_post_meta($this->event->ID, '_mdjm_event_dj', true), 'from' => 0, 'journal' => 'email-dj', 'event_id' => $this->event->ID, 'html' => true, 'cc_dj' => false, 'cc_admin' => isset($mdjm_settings['email']['bcc_admin_to_dj']) ? true : false, 'source' => 'Event Status to Approved'));
                        if ($approval_dj_email) {
                            if (MDJM_DEBUG == true) {
                                MDJM()->debug->log_it('	-- Approval email sent to DJ ');
                            }
                        } else {
                            if (MDJM_DEBUG == true) {
                                MDJM()->debug->log_it('	ERROR: Approval email was not sent to DJ');
                            }
                        }
                    } else {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('Not configured to email DJ');
                        }
                    }
                }
                /* -- Re-add the save post hook -- */
                add_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
                if (MDJM_DEBUG == true) {
                    MDJM()->debug->log_it('Completed client signing of contract ' . __METHOD__, true);
                }
                /* -- Email admin to notify of changes -- */
                if (MDJM_NOTIFY_ADMIN == true) {
                    if (MDJM_DEBUG == true) {
                        MDJM()->debug->log_it('Sending event status change notification to admin (Contract Signed)');
                    }
                    $content = '<html>' . "\n" . '<body>' . "\n";
                    $content .= '<p>' . sprintf(__('Good news... %s has just signed their event contract via %s', 'mobile-dj-manager'), '{CLIENT_FULLNAME}', MDJM_APP) . '</p>';
                    $content .= '<hr />' . "\n";
                    $content .= '<h4><a href="' . get_edit_post_link($this->event->ID) . '">' . __('Event ID', 'mobile-dj-manager') . ': ' . MDJM_EVENT_PREFIX . $this->event->ID . '</a></h4>' . "\n";
                    $content .= '<p>' . "\n";
                    $content .= __('Date', 'mobile-dj-manager') . ': {EVENT_DATE}<br />' . "\n";
                    $content .= __('Type', 'mobile-dj-manager') . ': ' . MDJM()->events->get_event_type($this->event->ID) . '<br />' . "\n";
                    $event_stati = mdjm_all_event_status();
                    $content .= __('Status', 'mobile-dj-manager') . ': ' . $event_stati[get_post_status($this->event->ID)] . '<br />' . "\n";
                    $content .= __('Client', 'mobile-dj-manager') . ': {CLIENT_FULLNAME}<br />' . "\n";
                    $content .= __('Value', 'mobile-dj-manager') . ': {TOTAL_COST}<br />' . "\n";
                    $deposit = get_post_meta($this->event->ID, '_mdjm_event_deposit');
                    $deposit_status = get_post_meta($this->event->ID, '_mdjm_event_deposit_status');
                    if (!empty($deposit) && $deposit != '0.00') {
                        $content .= __('Deposit', 'mobile-dj-manager') . ': {DEPOSIT} ({DEPOSIT_STATUS})<br />' . "\n";
                    }
                    $content .= __('Balance Due', 'mobile-dj-manager') . ': {BALANCE}</p>' . "\n";
                    $content .= '<p>' . sprintf(__('%sView Event%s', 'mobile-dj-manager'), '<a href="=' . get_edit_post_link($this->event->ID) . '">', '</a>') . '</p>' . "\n";
                    $content .= '</body>' . "\n" . '</html>' . "\n";
                    $mdjm->send_email(array('content' => $mdjm->filter_content(get_post_meta($this->event->ID, '_mdjm_event_client', true), $this->event->ID, $content), 'to' => $mdjm_settings['email']['system_email'], 'subject' => __('Event Contract Signed', 'mobile-dj-manager'), 'journal' => false, 'event_id' => $this->event->ID, 'cc_dj' => false, 'cc_admin' => false, 'filter' => false, 'log_comm' => false));
                } else {
                    if (MDJM_DEBUG == true) {
                        MDJM()->debug->log_it('Skipping admin notification');
                    }
                }
                ?>
					<script type="text/javascript">
                    window.location.replace("<?php 
                echo mdjm_get_formatted_url(MDJM_CONTRACT_PAGE) . 'event_id=' . $this->event->ID . '&message=3&class=2';
                ?>
");
                    </script>
                    <?php 
                exit;
            }
        }
Esempio n. 8
0
 function add_song()
 {
     global $mdjm, $my_mdjm, $wpdb;
     // Firstly, our security check
     if (!isset($_POST['__mdjm_playlist']) || !wp_verify_nonce($_POST['__mdjm_playlist'], 'manage_playlist')) {
         MDJM()->debug->log_it('Security verification failed during playlist addition. No update occured', false);
         return parent::display_message(4, 4);
     } else {
         $when = !empty($_POST['playlist_when']) ? $_POST['playlist_when'] : 'General';
         if (!is_user_logged_in()) {
             $when = 'Guest Added';
         }
         $by = is_user_logged_in() ? $my_mdjm['me']->display_name : ucwords($_POST['first_name'] . ' ' . $_POST['last_name']);
         // Insert the record
         $update_id = $wpdb->insert(MDJM_PLAYLIST_TABLE, array('id' => '', 'event_id' => $this->event->ID, 'artist' => $_POST['playlist_artist'], 'song' => $_POST['playlist_song'], 'play_when' => $when, 'info' => isset($_POST['playlist_info']) ? $_POST['playlist_info'] : '', 'added_by' => $by, 'date_added' => date('Y-m-d')));
         if (!empty($update_id)) {
             // Success
             // Journal Entry
             if (MDJM_JOURNAL == true) {
                 mdjm_add_journal(array('user_id' => $this->eventinfo['client']->ID, 'event_id' => $this->event->ID, 'comment_content' => 'Song added to playlist by ' . $by), array('type' => 'update-event', 'visibility' => '2'));
             }
             if (MDJM_DEBUG == true) {
                 MDJM()->debug->log_it('Song added to Event ID: ' . $this->event->ID . ' Playlist by ' . $by, true);
             }
             // Create an array we can use to display the entries from this session
             $this->current_songs[] = $wpdb->insert_id;
             parent::display_notice(2, __('The song was successfully added'));
         } else {
             // Failed
             if (MDJM_DEBUG == true) {
                 MDJM()->debug->log_it('ERROR: Could not add song to playlist. ' . $wpdb->print_error(), true);
             }
             parent::display_notice(4, __('An error occurred. Please try again.'));
         }
     }
 }
Esempio n. 9
0
 public function balance_reminder()
 {
     global $mdjm, $mdjm_settings;
     if (MDJM_DEBUG == true) {
         MDJM()->debug->log_it('*** Starting the Request Balance task ***', true);
     }
     $cron_start = microtime(true);
     /* -- Calculate the time period for which the task should run -- */
     $due_date = date('Y-m-d', strtotime("-" . $this->schedules['balance-reminder']['options']['age']));
     $args = array('posts_per_page' => -1, 'post_type' => 'mdjm-event', 'post_status' => 'mdjm-approved', 'meta_query' => array('relation' => 'AND', array('key' => '_mdjm_event_date', 'compare' => '>=', 'value' => $due_date, 'type' => 'date'), array('key' => '_mdjm_event_balance_status', 'compare' => '==', 'value' => 'Due'), array('key' => '_mdjm_event_cost', 'value' => '0.00', 'compare' => '>'), array('key' => '_mdjm_event_tasks', 'value' => 'balance-reminder', 'compare' => 'NOT IN')));
     // Retrieve events for which balance is due
     $events = get_posts($args);
     $notify = array();
     $x = 0;
     if (count($events) > 0) {
         // Events to process
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it(count($events) . ' ' . _n('event', 'events', count($events)) . ' where the balance is due');
         }
         remove_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
         /* -- Loop through the enquiries and update as completed -- */
         foreach ($events as $event) {
             $cronned = get_post_meta($event->ID, '_mdjm_event_tasks', true);
             if (!empty($cronned) && $cronned != '') {
                 $cron_update = json_decode($cronned, true);
             }
             if (array_key_exists('balance-reminder', $cron_update)) {
                 // Task has already run for this event
                 continue;
             }
             if (!is_array($cron_update)) {
                 $cron_update = array();
             }
             $cron_update[$this->schedules['balance-reminder']['slug']] = time();
             wp_update_post(array('ID' => $event->ID, 'post_modified' => date('Y-m-d H:i:s')));
             update_post_meta($event->ID, '_mdjm_event_last_updated_by', 0);
             update_post_meta($event->ID, '_mdjm_event_tasks', json_encode($cron_update));
             /* -- Update Journal -- */
             if (MDJM_JOURNAL == true) {
                 if (MDJM_DEBUG == true) {
                     MDJM()->debug->log_it('	-- Adding journal entry');
                 }
                 mdjm_add_journal(array('user_id' => 1, 'event_id' => $event->ID, 'comment_content' => mdjm_get_balance_label() . ' Reminder Scheduled Task executed<br /><br />' . time()), array('type' => 'added-note', 'visibility' => '0'));
             } else {
                 if (MDJM_DEBUG == true) {
                     MDJM()->debug->log_it('	-- Journalling is disabled');
                 }
             }
             $notify_dj = isset($this->schedules['balance-reminder']['options']['notify_dj']) ? $this->schedules['balance-reminder']['options']['notify_dj'] : '';
             $notify_admin = isset($this->schedules['balance-reminder']['options']['notify_admin']) ? $this->schedules['balance-reminder']['options']['notify_admin'] : '';
             $client = get_post_meta($event->ID, '_mdjm_event_client', true);
             $dj = get_post_meta($event->ID, '_mdjm_event_dj', true);
             $event_date = get_post_meta($event->ID, '_mdjm_event_date', true);
             $event_dj = !empty($dj) ? get_userdata($dj) : 'DJ not found';
             $event_client = !empty($client) ? get_userdata($client) : 'Client not found';
             $event_deposit = get_post_meta($event->ID, '_mdjm_event_deposit', true);
             $event_cost = get_post_meta($event->ID, '_mdjm_event_cost', true);
             $venue_post_id = get_post_meta($event->ID, '_mdjm_event_venue_id', true);
             $event_venue = MDJM()->events->mdjm_get_venue_details($venue_post_id, $event->ID);
             $contact_client = isset($this->schedules['balance-reminder']['options']['email_client']) && $this->schedules['balance-reminder']['options']['email_client'] == 'Y' ? true : false;
             $email_template = isset($this->schedules['balance-reminder']['options']['email_template']) && is_string(get_post_status($this->schedules['balance-reminder']['options']['email_template'])) ? $this->schedules['balance-reminder']['options']['email_template'] : false;
             /* -- Client Deposit Request Email -- */
             if (!empty($contact_client) && !empty($email_template)) {
                 // Email the client
                 if (MDJM_DEBUG == true) {
                     MDJM()->debug->log_it('Task ' . $this->schedules['balance-reminder']['name'] . ' is configured to notify client that deposit is due');
                 }
                 $request = $mdjm->send_email(array('content' => $email_template, 'to' => $event_client->ID, 'from' => $mdjm_settings['templates']['enquiry_from'] == 'dj' ? $event_dj->ID : 0, 'journal' => 'email-client', 'event_id' => $event->ID, 'html' => true, 'cc_dj' => isset($mdjm_settings['email']['bcc_dj_to_client']) ? true : false, 'cc_admin' => isset($mdjm_settings['email']['bcc_admin_to_client']) ? true : false, 'source' => __('Request ' . mdjm_get_balance_label() . ' Scheduled Task')));
                 if ($request) {
                     if (MDJM_DEBUG == true) {
                         MDJM()->debug->log_it('	-- Balance reminder sent to ' . $event_client->display_name . '. ' . $request . ' ID ');
                     }
                 } else {
                     if (MDJM_DEBUG == true) {
                         MDJM()->debug->log_it('	ERROR: Balance reminder was not sent');
                     }
                 }
             } else {
                 if (MDJM_DEBUG == true) {
                     MDJM()->debug->log_it('Task ' . $this->schedules['balance-reminder']['name'] . ' is not configured to notify client');
                 }
             }
             /* Prepare admin notification email data array */
             if (!empty($notify_admin) && $notify_admin == 'Y') {
                 if (MDJM_DEBUG == true) {
                     MDJM()->debug->log_it('	-- Admin notifications are enabled');
                 }
                 if (!isset($notify['admin']) || !is_array($notify['admin'])) {
                     $notify['admin'] = array();
                 }
                 $notify['admin'][$event->ID] = array('id' => $event->ID, 'client' => $event_client->display_name, 'deposit' => !empty($event_deposit) ? $event_deposit : '0', 'cost' => !empty($event_cost) ? $event_cost : '0', 'venue' => !empty($event_venue['name']) ? $event_venue['name'] : 'No Venue Set', 'djinfo' => $event_dj, 'date' => !empty($event_date) ? date("d M Y", strtotime($event_date)) : 'Date not found');
             }
             // End if( !empty( $notify_admin ) && $notify_admin == 'Y' )
             /* Prepare DJ notification email data array */
             if (!empty($notify_dj) && $notify_dj == 'Y' && mdjm_employee_can('edit_txns')) {
                 if (MDJM_DEBUG == true) {
                     MDJM()->debug->log_it('	-- DJ notifications are enabled');
                 }
                 if (!isset($notify['dj']) || !is_array($notify['dj'])) {
                     $notify['dj'] = array();
                 }
                 $notify['dj'][$dj] = array();
                 $notify['dj'][$dj][$event->ID] = array('id' => $event->id, 'client' => $event_client->display_name, 'deposit' => !empty($event_deposit) ? $event_deposit : '0', 'cost' => !empty($event_cost) ? $event_cost : '0', 'venue' => !empty($event_venue['name']) ? $event_venue['name'] : 'No Venue Set', 'djinfo' => $event_dj, 'date' => !empty($event_date) ? date("d M Y", strtotime($event_date)) : 'Date not found');
             }
             // End if( !empty( $notify_dj ) && $notify_dj == 'Y' )
             $x++;
         }
         // End foreach
         $cron_end = microtime(true);
         /* -- Prepare the Admin notification email -- */
         if (!empty($notify_admin) && $notify_admin == 'Y') {
             $notify_email_args = array('data' => $notify['admin'], 'taskinfo' => $this->schedules['balance-reminder'], 'start' => $cron_start, 'end' => $cron_end, 'total' => $x);
             // $notify_email_args
             $mdjm->send_email(array('content' => $this->notification_content($notify_email_args), 'to' => $mdjm_settings['email']['system_email'], 'subject' => 'Balance Reminder Scheduled Task Completed - ' . MDJM_APP, 'journal' => false, 'html' => false, 'cc_admin' => false, 'cc_dj' => false, 'filter' => false, 'log_comm' => false));
         }
         // if( !empty( $notify_admin ) && $notify_admin == 'Y' )	{
         /* -- Prepare the DJ notification email -- */
         if (!empty($notify_dj) && $notify_dj == 'Y' && mdjm_employee_can('edit_txns')) {
             foreach ($notify['dj'] as $notify_dj) {
                 foreach ($notify_dj as $dj) {
                     $notify_email_args = array('data' => $notify_dj, 'taskinfo' => $this->schedules['balance-reminder'], 'start' => $cron_start, 'end' => $cron_end, 'total' => $x);
                     // $notify_email_args
                     $mdjm->send_email(array('content' => $this->notification_content($notify_email_args), 'to' => $dj->ID, 'subject' => 'Balance Reminder Scheduled Task Completed - ' . MDJM_APP, 'journal' => false, 'html' => false, 'cc_admin' => false, 'cc_dj' => false, 'filter' => false, 'log_comm' => false));
                 }
                 // foreach( $notify_dj as $dj )
             }
             // foreach( $notify['dj'] as $notify_dj )
         }
         // if( !empty( $notify_dj ) && $notify_dj == 'Y' )
         add_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
     } else {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('No balances are due');
         }
     }
     // Prepare next run time
     $this->update_nextrun('balance-reminder');
     if (MDJM_DEBUG == true) {
         MDJM()->debug->log_it('*** Completed the Balance Reminder task ***', true);
     }
 }
Esempio n. 10
0
        /**
         * accept_enquiry
         * Complete actions when client books event via Client Zone
         * The Client must be logged in
         *
         * @param		arr		$event	The event post object
         * @return		bool			True upon success, otherwise false
         * @since		2.0
         * 
         */
        public function accept_enquiry($post)
        {
            global $mdjm, $my_mdjm, $mdjm_settings;
            if (empty($post)) {
                if (MDJM_DEBUG == true) {
                    MDJM()->debug->log_it('ERROR: No event object was provided in ' . __METHOD__, true);
                }
                ?>
					<script type="text/javascript">
                    window.location.replace("<?php 
                echo mdjm_get_formatted_url(MDJM_HOME) . 'action=view_event&event_id=' . $post->ID . '&message=2&class=4';
                ?>
");
                    </script>
                    <?php 
                exit;
            }
            if (get_current_user_id() != get_post_meta($post->ID, '_mdjm_event_client', true)) {
                if (MDJM_DEBUG == true) {
                    MDJM()->debug->log_it('ERROR: User ' . get_current_user_id() . ' is not authorised to accept this enquiry (' . $post->ID . ') in ' . __METHOD__, true);
                }
                ?>
					<script type="text/javascript">
                    window.location.replace("<?php 
                echo mdjm_get_formatted_url(MDJM_HOME) . 'action=view_event&event_id=' . $post->ID . '&message=6&class=4';
                ?>
");
                    </script>
                    <?php 
                exit;
            }
            /* -- Security verification -- */
            if (!isset($_GET['__mdjm_verify']) || !wp_verify_nonce($_GET['__mdjm_verify'], 'book_event')) {
                if (MDJM_DEBUG == true) {
                    MDJM()->debug->log_it('ERROR: User ' . get_current_user_id() . ' is not authorised to accept this enquiry (' . $post->ID . ') in ' . __METHOD__, true);
                }
                ?>
					<script type="text/javascript">
                    window.location.replace("<?php 
                echo mdjm_get_formatted_url(MDJM_HOME) . 'action=view_event&event_id=' . $post->ID . '&message=6&class=4';
                ?>
");
                    </script>
                    <?php 
                exit;
            }
            /* -- Prepare the meta data -- */
            $meta_update = array('_mdjm_event_last_updated_by' => $my_mdjm['me']->ID, '_mdjm_event_enquiry_accepted' => date('Y-m-d H:i:s'), '_mdjm_event_enquiry_accepted_by' => $my_mdjm['me']->ID);
            /* -- Remove the save post hook to avoid loops -- */
            remove_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
            /* -- Initiate actions for status change -- */
            wp_transition_post_status('mdjm-contract', $post->post_status, $post);
            /* -- Update the post status -- */
            wp_update_post(array('ID' => $post->ID, 'post_status' => 'mdjm-contract'));
            /* -- Update the post meta -- */
            foreach ($meta_update as $event_meta_key => $event_meta_value) {
                update_post_meta($post->ID, $event_meta_key, $event_meta_value);
                $field_updates[] = 'Field ' . $event_meta_key . ' updated with ' . $event_meta_value;
            }
            /* -- Update Journal with event updates -- */
            if (MDJM_JOURNAL == true) {
                if (MDJM_DEBUG == true) {
                    MDJM()->debug->log_it('	-- Adding journal entry');
                }
                mdjm_add_journal(array('user_id' => $my_mdjm['me']->ID, 'event_id' => $post->ID, 'comment_content' => 'Enquiry accepted by ' . $my_mdjm['me']->display_name), array('type' => 'update-event', 'visibility' => '2'));
            } else {
                if (MDJM_DEBUG == true) {
                    MDJM()->debug->log_it('	-- Journalling is disabled');
                }
            }
            /* -- Email Contract Link -- */
            $contact_client = !empty($mdjm_settings['templates']['contract_to_client']) ? true : false;
            $client_email = isset($mdjm_settings['templates']['contract']) ? $mdjm_settings['templates']['contract'] : false;
            if (!is_string(get_post_status($client_email))) {
                if (MDJM_DEBUG == true) {
                    MDJM()->debug->log_it('ERROR: No email template for the contract link has been found ' . __FUNCTION__, $stampit = true);
                }
                wp_die('ERROR: Either no email template is defined or an error has occured. Check your Settings.');
            }
            if ($contact_client == true) {
                if (MDJM_DEBUG == true) {
                    MDJM()->debug->log_it('Configured to email client with template ID ' . $client_email);
                }
                if (MDJM_DEBUG == true) {
                    MDJM()->debug->log_it('Generating email...');
                }
                $email_args = array('content' => $client_email, 'to' => get_post_meta($post->ID, '_mdjm_event_client', true), 'from' => $mdjm_settings['templates']['contract_from'] == 'dj' ? get_post_meta($post->ID, '_mdjm_event_dj', true) : 0, 'journal' => 'email-client', 'event_id' => $post->ID, 'html' => true, 'cc_dj' => isset($mdjm_settings['email']['bcc_dj_to_client']) ? true : false, 'cc_admin' => isset($mdjm_settings['email']['bcc_admin_to_client']) ? true : false, 'source' => 'Event Enquiry Accepted via ' . MDJM_APP);
                // Filter the email args
                $email_args = apply_filters('mdjm_contract_email_args', $email_args);
                // Send the email
                $contract_email = $mdjm->send_email($email_args);
                if ($contract_email) {
                    if (MDJM_DEBUG == true) {
                        MDJM()->debug->log_it('	-- Contract link email sent to client ');
                    }
                } else {
                    if (MDJM_DEBUG == true) {
                        MDJM()->debug->log_it('	ERROR: Contract link email was not sent');
                    }
                }
            } else {
                if (MDJM_DEBUG == true) {
                    MDJM()->debug->log_it('Not configured to email client');
                }
            }
            /* -- Re-add the save post hook -- */
            add_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
            /* -- Email admin to notify of changes -- */
            if (MDJM_NOTIFY_ADMIN == true) {
                if (MDJM_DEBUG == true) {
                    MDJM()->debug->log_it('Sending event status change notification to admin');
                }
                $content = '<html>' . "\n" . '<body>' . "\n";
                $content .= '<p>' . sprintf(__('Good news... %s has just accepted their event quotation via %s', 'mobile-dj-manager'), '{CLIENT_FULLNAME}', MDJM_APP) . '</p>';
                $content .= '<hr />' . "\n";
                $content .= '<h4><a href="' . get_edit_post_link($post->ID) . '">' . __('Event ID', 'mobile-dj-manager') . ': ' . MDJM_EVENT_PREFIX . $post->ID . '</a></h4>' . "\n";
                $content .= '<p>' . "\n";
                $content .= __('Date', 'mobile-dj-manager') . ': {EVENT_DATE}<br />' . "\n";
                $content .= __('Type', 'mobile-dj-manager') . ': ' . MDJM()->events->get_event_type($post->ID) . '<br />' . "\n";
                $event_stati = mdjm_all_event_status();
                $content .= __('Status', 'mobile-dj-manager') . ': ' . $event_stati[get_post_status($post->ID)] . '<br />' . "\n";
                $content .= __('Client', 'mobile-dj-manager') . ': {CLIENT_FULLNAME}<br />' . "\n";
                $content .= __('Value', 'mobile-dj-manager') . ': {TOTAL_COST}<br />' . "\n";
                $deposit = get_post_meta($post->ID, '_mdjm_event_deposit');
                $deposit_status = get_post_meta($post->ID, '_mdjm_event_deposit_status');
                if (!empty($deposit) && $deposit != '0.00') {
                    $content .= __('Deposit', 'mobile-dj-manager') . ': {DEPOSIT} ({DEPOSIT_STATUS})<br />' . "\n";
                }
                $content .= __('Balance Due', 'mobile-dj-manager') . ': {BALANCE}</p>' . "\n";
                $content .= '<p>' . sprintf(__('%sView Event%s', 'mobile-dj-manager'), '<a href="=' . get_edit_post_link($post->ID) . '">', '</a>') . '</p>' . "\n";
                $content .= '</body>' . "\n" . '</html>' . "\n";
                $mdjm->send_email(array('content' => $content, 'to' => $mdjm_settings['email']['system_email'], 'subject' => __('Event Quotation Accepted', 'mobile-dj-manager'), 'journal' => false, 'event_id' => $post->ID, 'cc_dj' => false, 'cc_admin' => false, 'log_comm' => false));
            } else {
                if (MDJM_DEBUG == true) {
                    MDJM()->debug->log_it('Skipping admin notification');
                }
            }
            if (MDJM_DEBUG == true) {
                MDJM()->debug->log_it('Completed enquiry acceptance via ' . MDJM_APP . ' in ' . __METHOD__, true);
            }
            $this->display_message(1, 2);
        }
/**
 * Mark an event employee as paid.
 *
 * @since	1.3
 * @param	int		$employee_id	User ID of employee
 * @param	int		$event_id		Event ID
 * @param	int		$txn_id			The transaction ID associated with this payment.
 * @return	bool	True if payment data updated for event employee, otherwise false.
 */
function mdjm_set_employee_paid($employee_id, $event_id, $txn_id = '')
{
    global $wp_roles;
    if (!mdjm_get_option('enable_employee_payments')) {
        return;
    }
    if (!mdjm_is_employee($employee_id)) {
        return false;
    }
    $return = false;
    if ($employee_id == mdjm_get_event_primary_employee($event_id)) {
        /**
         *
         * Hook fires before marking event employee as paid.
         *
         * @since	1.3
         * @param	int	$event_id	The event ID.
         */
        do_action("mdjm_pre_mdjm_set_employee_paid_{$employee_id}", $event_id);
        $role = 'dj';
        $payment = mdjm_get_txn_price($txn_id);
        $payment_data = get_post_meta($event_id, '_mdjm_event_dj_payment_status', true);
        $payment_data['payment_status'] = mdjm_get_employees_event_wage($event_id, $employee_id) > $payment ? 'part-paid' : 'paid';
        $payment_data['payment_date'] = current_time('mysql');
        $payment_data['txn_id'] = $txn_id;
        $payment_data['payment_amount'] = $payment;
        $payment_update = update_post_meta($event_id, '_mdjm_event_dj_payment_status', $payment_data);
        if (!empty($payment_update)) {
            MDJM()->debug->log_it(sprintf('%s successfully paid %s for Event %d', mdjm_get_employee_display_name($employee_id), mdjm_currency_filter(mdjm_get_txn_price($txn_id)), $event_id));
            $return = true;
        } else {
            MDJM()->debug->log_it(sprintf('Unable to pay %s for Event %d', mdjm_get_employee_display_name($employee_id), $event_id));
            $return = false;
        }
    } else {
        $payment_data = get_post_meta($event_id, '_mdjm_event_employees_data', true);
        if (!mdjm_employee_working_event($event_id, $employee_id)) {
            MDJM()->debug->log_it('Employee not working this event');
            return false;
        } else {
            /**
             *
             * Hook fires before marking event employee as paid.
             *
             * @since	1.3
             * @param	int	$event_id	The event ID.
             */
            do_action("mdjm_pre_mdjm_set_employee_paid_{$employee_id}", $event_id);
            $role = $payment_data[$employee_id]['role'];
            $payment = mdjm_get_txn_price($payment_data[$employee_id]['txn_id']);
            $payment_data[$employee_id]['payment_status'] = mdjm_get_employees_event_wage($event_id, $employee_id) > $payment ? 'part-paid' : 'paid';
            $payment_data[$employee_id]['payment_date'] = current_time('mysql');
            $payment_data[$employee_id]['payment_amount'] = $payment;
            $payment_update = mdjm_update_txn_meta($payment_data[$employee_id]['txn_id'], array('_mdjm_txn_status' => 'Completed'));
            if (!empty($payment_update)) {
                $payment_update = update_post_meta($event_id, '_mdjm_event_employees_data', $payment_data);
            }
            if (!empty($payment_update)) {
                MDJM()->debug->log_it(sprintf('%s successfully paid %s for Event %d', mdjm_get_employee_display_name($employee_id), mdjm_currency_filter(mdjm_get_txn_price($txn_id)), $event_id));
                $return = true;
            } else {
                MDJM()->debug->log_it(sprintf('Unable to pay %s for Event %d', mdjm_get_employee_display_name($employee_id), $event_id));
                $return = false;
            }
        }
    }
    if (!empty($return)) {
        $journal_args = array('user_id' => 1, 'event_id' => $event_id, 'comment_content' => sprintf(__('Employee %s paid %s for their role as %s', 'mobile-dj-manager'), mdjm_get_employee_display_name($employee_id), $payment, translate_user_role($wp_roles->roles[$role]['name'])));
        $journal_meta = array('mdjm_visibility' => !empty($meta['visibility']) ? $meta['visibility'] : '2');
        mdjm_add_journal($journal_args, $journal_meta);
        /**
         *
         * Hook fires after successfully marking event employee as paid.
         *
         * @since	1.3
         * @param	int	$event_id	The event ID.
         * @param	int	$txn_id		The transaction ID associated with the payment
         */
        do_action("mdjm_post_mdjm_set_employee_paid_{$employee_id}", $event_id, $txn_id);
    }
    return $return;
}
Esempio n. 12
0
/**
 * Update event meta.
 *
 * We don't currently delete empty meta keys or values, instead we update with an empty value
 * if an empty value is passed to the function.
 *
 * We may soon move to a configuration where all meta key => value pairs are stored in a single
 * meta key (_mdjm_event_data). As a result there is some duplication here, but performance
 * impact is minimal.
 *
 * @since	1.3
 * @param	int		$event_id	The event ID.
 * @param	arr		$data		The appropriately formatted meta data values.
 * @return	mixed	See get_post_meta()
 */
function mdjm_update_event_meta($event_id, $data)
{
    do_action('mdjm_pre_update_event_meta', $event_id, $data);
    // For backwards compatibility
    $current_meta = get_post_meta($event_id);
    $debug = array();
    $meta = get_post_meta($event_id, '_mdjm_event_data', true);
    foreach ($data as $key => $value) {
        if ($key == 'mdjm_nonce' || $key == 'mdjm_action' || substr($key, 0, 12) != '_mdjm_event_') {
            continue;
        }
        if ($key == '_mdjm_event_cost' || $key == '_mdjm_event_deposit' || $key == '_mdjm_event_dj_wage') {
            $value = $value;
        } elseif ($key == '_mdjm_event_venue_postcode' && !empty($value)) {
            // Postcodes are uppercase.
            $value = strtoupper($value);
        } elseif ($key == '_mdjm_event_venue_email' && !empty($value)) {
            // Emails are lowercase.
            $value = strtolower($value);
        } elseif ($key == '_mdjm_event_package' && !empty($value)) {
            $value = sanitize_text_field(strtolower($value));
        } elseif ($key == '_mdjm_event_addons' && !empty($value)) {
            $value = $value;
        } elseif ($key == '_mdjm_event_travel_data') {
            $value = $value;
        } elseif (!strpos($key, 'notes') && !empty($value)) {
            $value = sanitize_text_field(ucwords($value));
        } elseif (!empty($value)) {
            $value = sanitize_text_field(ucfirst($value));
        } else {
            $value = '';
        }
        // If we have a value and the key did not exist previously, add it.
        if (!empty($value) && (empty($current_meta[$key]) || empty($current_meta[$key][0]))) {
            $debug[] = sprintf(__('Adding %s value as %s'), mdjm_event_get_meta_label($key), is_array($value) ? var_export($value, true) : $value);
            add_post_meta($event_id, $key, $value);
            $meta[str_replace('_mdjm_event', '', $key)] = $value;
        } elseif (!empty($value) && $value != $current_meta[$key][0]) {
            // If a value existed, but has changed, update it.
            $debug[] = sprintf(__('Updating %s with %s'), mdjm_event_get_meta_label($key), is_array($value) ? var_export($value, true) : $value);
            update_post_meta($event_id, $key, $value);
            $meta[str_replace('_mdjm_event', '', $key)] = $value;
        } elseif (empty($value) && !empty($current_meta[$key][0])) {
            // If there is no new meta value but an old value exists, delete it.
            $debug[] = sprintf(__('Removing %s from %s'), $current_meta[$key][0], mdjm_event_get_meta_label($key));
            delete_post_meta($event_id, $key, $value);
            if (isset($meta[str_replace('_mdjm_event_', '', $key)])) {
                unset($meta[str_replace('_mdjm_event_', '', $key)]);
            }
        }
    }
    $update = update_post_meta($event_id, '_mdjm_event_data', $meta);
    $journal_args = array('user_id' => is_user_logged_in() ? get_current_user_id() : 1, 'event_id' => $event_id, 'comment_content' => sprintf(__('%s Updated', 'mobile-dj-manager') . ':<br />    %s', mdjm_get_label_singular(), implode('<br />', $debug)));
    mdjm_add_journal($journal_args);
    do_action('mdjm_primary_employee_payment_status', $event_id, $current_meta, $data);
    do_action('mdjm_post_update_event_meta', $event_id, $current_meta, $data, $meta);
    if (!empty($debug)) {
        foreach ($debug as $log) {
            MDJM()->debug->log_it($log, false);
        }
    }
    return $update;
}
Esempio n. 13
0
/**
 * Save the meta data for the event
 *
 * @since	0.7
 * @param	int		$post_id		The current event post ID.
 * @param	obj		$post			The current event post object (WP_Post).
 * @param	bool	$update			Whether this is an existing post being updated or not.
 * 
 * @return	void
 */
function mdjm_save_event_post($post_id, $post, $update)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if ($post->post_status == 'trash') {
        return;
    }
    if (empty($update)) {
        return;
    }
    // Permission Check
    if (!mdjm_employee_can('manage_events')) {
        MDJM()->debug->log_it(sprintf('PERMISSION ERROR: User %s is not allowed to edit events', get_current_user_id()));
        return;
    }
    // Remove the save post action to avoid loops.
    remove_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
    // Fire our pre-save hook
    do_action('mdjm_pre_event_save', $post_id, $post, $update);
    $debug[] = 'Starting Event Save';
    // Get current meta data for the post so we can track changes within the journal.
    $current_meta = get_post_meta($post_id);
    /**
     * Get the Client ID and store it in the event data array.
     * If a client has been selected from the dropdown, we simply use that ID.
     * If adding a new client, call the method and use the returned user ID.
     */
    $event_data['_mdjm_event_client'] = $_POST['client_name'] != 'add_new' ? $_POST['client_name'] : mdjm_add_client();
    /**
     * For new events we fire the 'mdjm_add_new_event' action
     */
    if (empty($update)) {
        do_action('mdjm_create_new_event', $post);
    }
    /**
     * If the client is flagged to have their password reset, set the flag.
     * The flag will be checked and processed during the content tag filtering process.
     */
    if (!empty($_POST['mdjm_reset_pw'])) {
        $debug[] = sprintf('Client %s flagged for password reset', $event_data['_mdjm_event_client']);
        update_user_meta($event_data['_mdjm_event_client'], 'mdjm_pass_action', true);
    }
    /**
     * Determine the Venue ID if an existing venue was selected.
     * Otherwise, determine if we're using the client's address or adding a manual venue address
     */
    if ($_POST['venue_id'] != 'manual' && $_POST['venue_id'] != 'client') {
        $event_data['_mdjm_event_venue_id'] = $_POST['venue_id'];
    } elseif (!empty($_POST['_mdjm_event_venue_id']) && $_POST['_mdjm_event_venue_id'] == 'client') {
        $event_data['_mdjm_event_venue_id'] = 'client';
    } else {
        $event_data['_mdjm_event_venue_id'] = 'manual';
    }
    /**
     * If the option was selected to save the venue, prepare the post and post meta data
     * for the venue.
     */
    if ($_POST['venue_id'] == 'manual' && !empty($_POST['save_venue'])) {
        foreach ($_POST as $venue_key => $venue_value) {
            if (substr($venue_key, 0, 6) == 'venue_') {
                $venue_meta[$venue_key] = $venue_value;
                if ($venue_key == 'venue_postcode' && !empty($venue_value)) {
                    $venue_meta[$venue_key] = strtoupper($venue_value);
                } elseif ($venue_key == 'venue_email' && !empty($venue_value)) {
                    $venue_meta[$venue_key] = sanitize_email($venue_value);
                } else {
                    $venue_meta[$venue_key] = sanitize_text_field(ucwords($venue_value));
                }
            }
        }
        // Create the new venue
        $event_data['_mdjm_event_venue_id'] = mdjm_add_venue($_POST['venue_name'], $venue_meta);
    } else {
        // Manual venue address entry
        if ($_POST['venue_id'] != 'client') {
            $event_data['_mdjm_event_venue_name'] = sanitize_text_field(ucwords($_POST['venue_name']));
            $event_data['_mdjm_event_venue_contact'] = sanitize_text_field(ucwords($_POST['venue_contact']));
            $event_data['_mdjm_event_venue_phone'] = sanitize_text_field($_POST['venue_phone']);
            $event_data['_mdjm_event_venue_email'] = sanitize_email(strtolower($_POST['venue_email']));
            $event_data['_mdjm_event_venue_address1'] = sanitize_text_field(ucwords($_POST['venue_address1']));
            $event_data['_mdjm_event_venue_address2'] = sanitize_text_field(ucwords($_POST['venue_address2']));
            $event_data['_mdjm_event_venue_town'] = sanitize_text_field(ucwords($_POST['venue_town']));
            $event_data['_mdjm_event_venue_county'] = sanitize_text_field(ucwords($_POST['venue_county']));
            $event_data['_mdjm_event_venue_postcode'] = strtoupper(sanitize_text_field($_POST['venue_postcode']));
        } else {
            // Using clients address
            $client_data = get_userdata($event_data['_mdjm_event_client']);
            $event_data['_mdjm_event_venue_name'] = __('Client Address', 'mobile-dj-manager');
            $event_data['_mdjm_event_venue_contact'] = sprintf('%s %s', !empty($client_data->first_name) ? sanitize_text_field($client_data->first_name) : '', !empty($client_data->last_name) ? sanitize_text_field($client_data->last_name) : '');
            $event_data['_mdjm_event_venue_phone'] = !empty($client_data->phone1) ? $client_data->phone1 : '';
            $event_data['_mdjm_event_venue_email'] = !empty($client_data->user_email) ? $client_data->user_email : '';
            $event_data['_mdjm_event_venue_address1'] = !empty($client_data->address1) ? $client_data->address1 : '';
            $event_data['_mdjm_event_venue_address2'] = !empty($client_data->address2) ? $client_data->address2 : '';
            $event_data['_mdjm_event_venue_town'] = !empty($client_data->town) ? $client_data->town : '';
            $event_data['_mdjm_event_venue_county'] = !empty($client_data->county) ? $client_data->county : '';
            $event_data['_mdjm_event_venue_postcode'] = !empty($client_data->postcode) ? $client_data->postcode : '';
        }
    }
    /**
     * Travel data
     */
    $travel_fields = mdjm_get_event_travel_fields();
    foreach ($travel_fields as $travel_field) {
        $field = 'travel_' . $travel_field;
        $travel_data[$travel_field] = !empty($_POST[$field]) ? $_POST[$field] : '';
        if ('cost' == $travel_field && !empty($_POST[$field])) {
            $travel_data[$travel_field] = mdjm_sanitize_amount($_POST[$field]);
        }
    }
    $event_data['_mdjm_event_travel_data'] = $travel_data;
    /**
     * Prepare the remaining event meta data.
     */
    $event_data['_mdjm_event_last_updated_by'] = get_current_user_id();
    /**
     * Event name.
     * If no name is defined, use the event type.
     * Allow filtering of the event name with the `mdjm_event_name` filter.
     */
    if (empty($_POST['_mdjm_event_name'])) {
        $_POST['_mdjm_event_name'] = get_term($_POST['mdjm_event_type'], 'event-types')->name;
    }
    $_POST['_mdjm_event_name'] = apply_filters('mdjm_event_name', $_POST['_mdjm_event_name'], $post_id);
    // Generate the playlist reference for guest access
    if (empty($update) || empty($current_meta['_mdjm_event_playlist_access'][0])) {
        $event_data['_mdjm_event_playlist_access'] = mdjm_generate_playlist_guest_code();
    }
    // Set whether or not the playlist is enabled for the event
    $event_data['_mdjm_event_playlist'] = !empty($_POST['enable_playlist']) ? $_POST['enable_playlist'] : 'N';
    /**
     * All the remaining custom meta fields are prefixed with '_mdjm_event_'.
     * Loop through all $_POST data and put all event meta fields into the $event_data array
     */
    foreach ($_POST as $key => $value) {
        if (substr($key, 0, 12) == '_mdjm_event_') {
            if ($key == '_mdjm_event_dj_wage' || $key == '_mdjm_event_cost' || $key == '_mdjm_event_deposit') {
                $value = mdjm_sanitize_amount($value);
            }
            $event_data[$key] = $value;
        }
    }
    /**
     * We store all times in H:i:s but the user may prefer a different format so we
     * determine their time format setting and adjust to H:i:s for saving.
     */
    if (mdjm_get_option('time_format', 'H:i') == 'H:i') {
        // 24 Hr
        $event_data['_mdjm_event_start'] = date('H:i:s', strtotime($_POST['event_start_hr'] . ':' . $_POST['event_start_min']));
        $event_data['_mdjm_event_finish'] = date('H:i:s', strtotime($_POST['event_finish_hr'] . ':' . $_POST['event_finish_min']));
        $event_data['_mdjm_event_djsetup_time'] = date('H:i:s', strtotime($_POST['dj_setup_hr'] . ':' . $_POST['dj_setup_min']));
    } else {
        // 12 hr
        $event_data['_mdjm_event_start'] = date('H:i:s', strtotime($_POST['event_start_hr'] . ':' . $_POST['event_start_min'] . $_POST['event_start_period']));
        $event_data['_mdjm_event_finish'] = date('H:i:s', strtotime($_POST['event_finish_hr'] . ':' . $_POST['event_finish_min'] . $_POST['event_finish_period']));
        $event_data['_mdjm_event_djsetup_time'] = date('H:i:s', strtotime($_POST['dj_setup_hr'] . ':' . $_POST['dj_setup_min'] . $_POST['dj_setup_period']));
    }
    if (empty($_POST['_mdjm_event_djsetup'])) {
        $event_data['_mdjm_event_djsetup'] = $_POST['_mdjm_event_date'];
    }
    /**
     * Set the event end date.
     * If the finish time is less than the start time, assume following day.
     */
    if (date('H', strtotime($event_data['_mdjm_event_finish'])) > date('H', strtotime($event_data['_mdjm_event_start']))) {
        $event_data['_mdjm_event_end_date'] = $_POST['_mdjm_event_date'];
    } else {
        // End date is following day
        $event_data['_mdjm_event_end_date'] = date('Y-m-d', strtotime('+1 day', strtotime($_POST['_mdjm_event_date'])));
    }
    /**
     * Determine the state of the Deposit & Balance payments.
     * 
     */
    $event_data['_mdjm_event_deposit_status'] = !empty($_POST['deposit_paid']) ? $_POST['deposit_paid'] : 'Due';
    $event_data['_mdjm_event_balance_status'] = !empty($_POST['balance_paid']) ? $_POST['balance_paid'] : 'Due';
    $deposit_payment = $event_data['_mdjm_event_deposit_status'] == 'Paid' && $current_meta['_mdjm_event_deposit_status'][0] != 'Paid' ? true : false;
    $balance_payment = $event_data['_mdjm_event_balance_status'] == 'Paid' && $current_meta['_mdjm_event_balance_status'][0] != 'Paid' ? true : false;
    // Add-Ons
    if (mdjm_packages_enabled()) {
        $event_data['_mdjm_event_addons'] = !empty($_POST['event_addons']) ? $_POST['event_addons'] : '';
    }
    // Assign the event type
    $existing_event_type = wp_get_object_terms($post_id, 'event-types');
    mdjm_set_event_type($post_id, (int) $_POST['mdjm_event_type']);
    // Assign the enquiry source
    mdjm_set_enquiry_source($post_id, (int) $_POST['mdjm_enquiry_source']);
    /**
     * Update the event post meta data
     */
    $debug[] = 'Beginning Meta Updates';
    mdjm_update_event_meta($post_id, $event_data);
    $debug[] = 'Meta Updates Completed';
    if ($deposit_payment == true || $balance_payment == true) {
        if ($balance_payment == true) {
            unset($event_data['_mdjm_event_balance_status']);
            unset($event_data['_mdjm_event_deposit_status']);
            mdjm_mark_event_balance_paid($post_id);
        } else {
            unset($event_data['_mdjm_event_deposit_status']);
            mdjm_mark_event_deposit_paid($post_id);
        }
    }
    // Set the event status & initiate tasks based on the status
    if ($_POST['original_post_status'] != $_POST['mdjm_event_status']) {
        mdjm_update_event_status($post_id, $_POST['mdjm_event_status'], $_POST['original_post_status'], array('client_notices' => empty($_POST['mdjm_block_emails']) ? true : false, 'email_template' => !empty($_POST['mdjm_email_template']) ? $_POST['mdjm_email_template'] : false, 'quote_template' => !empty($_POST['mdjm_online_quote']) ? $_POST['mdjm_online_quote'] : false));
    } else {
        // Event status is un-changed so just log the changes to the journal
        mdjm_add_journal(array('user_id' => get_current_user_id(), 'event_id' => $post_id, 'comment_content' => sprintf('%s %s via Admin', mdjm_get_label_singular(), empty($update) ? 'created' : 'updated')), array('type' => 'update-event', 'visibility' => '2'));
    }
    // Fire the save event hook
    do_action('mdjm_save_event', $post, $_POST['mdjm_event_status']);
    // Fire our post save hook
    do_action('mdjm_after_event_save', $post_id, $post, $update);
    // Re-add the save post action to avoid loops
    add_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
    $debug[] = sprintf('Completed Event Save for event %s', $post_id);
    if (!empty($debug) && MDJM_DEBUG == true) {
        $true = true;
        foreach ($debug as $log) {
            MDJM()->debug->log_it($log, $true);
            $true = false;
        }
    }
}
/**
 * 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;
}