/** * my_events * Retrieve all of the currently logged in users events, and details * and store within the global $my_mdjm array * * @param int $client Optional: ID of user. Default to current user * @return arr $my_mdjm Array of event and user data */ public function my_events($client = '') { global $current_user, $my_mdjm, $mdjm; /* -- No user, no data -- */ if (!is_user_logged_in()) { return; } $c = !empty($client) ? $client : $current_user->ID; $event_stati = mdjm_all_event_status(); $my_mdjm = array(); $my_mdjm['me'] = get_userdata($c); if (is_dj() || current_user_can('administrator')) { $my_mdjm['next'] = MDJM()->events->next_event('', 'dj'); $my_mdjm['active'] = MDJM()->events->active_events('', 'dj'); } else { $my_mdjm['next'] = MDJM()->events->next_event(); $my_mdjm['active'] = MDJM()->events->active_events(); } }
/** * Check if the current post belongs to the logged in user * * * * @param int event_id The event (post) to query * * @return bool true if the event belongs to the user, otherwise false * @since 1.1.3 */ public function is_my_event($event_id) { if (empty($event_id)) { return false; } $type = 'client'; if (current_user_can('administrator') || is_dj()) { $type = 'dj'; } if (get_current_user_id() == get_post_meta($event_id, '_mdjm_event_' . $type, true)) { return true; } return false; }
function f_mdjm_render_comms() { global $mdjm, $mdjm_settings; if (isset($_GET['template']) && !empty($_GET['template'])) { $template_query = get_post($_GET['template']); if ($template_query) { $content = $template_query->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $subject = get_the_title($_GET['template']); } } elseif (isset($_POST['email_content'])) { $content = stripslashes($_POST['email_content']); } else { $content = ''; } if (!isset($subject) || empty($subject)) { if (isset($_POST['subject'])) { $subject = stripslashes($_POST['subject']); } else { $subject = ''; } } ?> <div class="wrap"> <h1>Client Communications</h1> <?php $settings = array('media_buttons' => true, 'textarea_rows' => '10'); $clientinfo = $mdjm->mdjm_events->get_clients(); $djinfo = mdjm_get_djs(); ?> <script type="text/javascript"> function MM_jumpMenu(targ,selObj,restore){ //v3.0 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); if (restore) selObj.selectedIndex=0; } </script> <form name="form-email-template" id="form-email-template" method="post" enctype="multipart/form-data"> <?php if (isset($_GET['action']) && $_GET['action'] == 'respond_unavailable') { ?> <input type="hidden" name="respond_unavailable" id="respond_unavailable" value="<?php echo $_GET['event_id']; ?> " /><?php } ?> <table class="form-table"> <tr> <td width="20%"><label for="email_template">Select a template for content, or write your own:</label></td> <td><select name="email_template" id="email_template" onChange="MM_jumpMenu('parent',this,0)"> <option value="<?php echo add_query_arg('template', 0); ?> " <?php if (!isset($_GET['template']) || $_GET['template'] == '0') { echo ' selected'; } ?> >Do not use Template</option> <?php $email_args = array('posts_per_page' => -1, 'post_type' => 'email_template', 'orderby' => 'name', 'order' => 'ASC'); $contract_args = array('post_type' => 'contract', 'posts_per_page' => -1, 'orderby' => 'name', 'order' => 'ASC'); if (is_dj()) { // Check templates that DJ's cannot use if (!isset($mdjm_settings['permissions'])) { $mdjm_settings['permissions'] = get_option('mdjm_plugin_permissions'); } if (isset($mdjm_settings['permissions']['dj_disable_template']) && !empty($mdjm_settings['permissions']['dj_disable_template'])) { if (!is_array($mdjm_settings['permissions']['dj_disable_template'])) { $mdjm_settings['permissions']['dj_disable_template'] = array($mdjm_settings['permissions']['dj_disable_template']); } $email_args['post__not_in'] = $mdjm_settings['permissions']['dj_disable_template']; $contract_args['post__not_in'] = $mdjm_settings['permissions']['dj_disable_template']; } } $email_query = get_posts($email_args); if ($email_query) { ?> <optgroup label="EMAIL TEMPLATES"><?php foreach ($email_query as $email_template) { ?> <option value="<?php echo add_query_arg('template', $email_template->ID); ?> "<?php if (isset($_GET['template'])) { selected($email_template->ID, $_GET['template']); } ?> ><?php echo get_the_title($email_template->ID); ?> </option> <?php } ?> </optgroup> <?php } $contract_query = get_posts($contract_args); if ($contract_query) { ?> <optgroup label="CONTRACTS"><?php foreach ($contract_query as $contract_template) { ?> <option value="<?php echo add_query_arg('template', $contract_template->ID); ?> "<?php if (isset($_GET['template'])) { selected($contract_template->ID, $_GET['template']); } ?> ><?php echo get_the_title($contract_template->ID); ?> </option> <?php } ?> </optgroup> <?php } ?> </select></td> </tr> </table> <hr /> <?php wp_nonce_field('send-email', '__mdjm_send_email'); ?> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="widefat"> <tr> <td width="60%"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="widefat"> <tr class="alternate"> <th class="row-title" align="left"><label for="to">Send email to:</label></th> <td><select name="to" id="to" onChange="MM_jumpMenu('parent',this,0)"> <option value="">Select a Recipient</option> <optgroup label="CLIENTS"> <?php foreach ($clientinfo as $client) { if (current_user_can('administrator') || $mdjm->mdjm_events->is_my_client($client->ID)) { // Non-Admins only see their own clients ?> <option value="<?php echo add_query_arg(array('to_user' => $client->ID)); ?> "<?php if (isset($_GET['to_user'])) { selected($client->ID, $_GET['to_user']); } ?> ><?php echo $client->display_name; ?> </option> <?php } } ?> </optgroup> <?php if (current_user_can('administrator')) { // Admins see DJ's too ?> <optgroup label="<?php echo MDJM_DJ; ?> 's"><?php foreach ($djinfo as $dj) { ?> <option value="<?php echo add_query_arg(array('to_user' => $dj->ID)); ?> "<?php if (isset($_GET['to_user'])) { selected($dj->ID, $_GET['to_user']); } ?> ><?php echo $dj->display_name; ?> </option> <?php } } ?> </optgroup> </select> </td> </tr> <?php if (isset($_GET['to_user']) && $_GET['to_user'] != '') { echo '<input type="hidden" name="email_to" value="' . $_GET['to_user'] . '" />'; } ?> <tr class="alternate"> <th class="row-title"> </th> <td> <?php /* Get this users info */ if (isset($_GET['to_user']) && $_GET['to_user'] != '') { $userinfo = get_user_by('id', $_GET['to_user']); } ?> <input type="email" name="user_addr" id="user_addr" value="<?php if (isset($userinfo) && $userinfo != '') { echo $userinfo->user_email; } ?> " class="regular-text" readonly="readonly" /> </td> </tr> <tr class="alternate"> <th class="row-title"><label for="copy_sender">Copy yourself?</label></th> <td><input type="checkbox" name="copy_sender" id="copy_sender" value="Y" checked="checked" /> <span class="description">Depending on your <a href="<?php echo mdjm_get_admin_page('settings'); ?> ">settings</a>, the DJ and Admin may also receive a copy</span></td> </tr> <?php if (isset($_GET['to_user'])) { if (user_can($_GET['to_user'], 'dj')) { // Selected user is a DJ $events = $mdjm->mdjm_events->dj_events($_GET['to_user'], '', $order = 'DESC'); } else { $events = $mdjm->mdjm_events->client_events($_GET['to_user'], '', $order = 'DESC'); } } ?> <tr class="alternate"> <th class="row-title" align="left"><label for="event">Regarding Event:</label></th> <td> <?php if (empty($events)) { ?> <input type="text" name="event" class="regular-text" value="No Event (General Message)" disabled="disabled" /> <?php } else { $event_stati = mdjm_all_event_status(); ?> <select name="event" id="event"> <option value="">No Event (General Message)</option> <?php foreach ($events as $event) { ?> <option value="<?php echo $event->ID; ?> "<?php if (isset($_POST['event'])) { selected($_POST['event'], $event->ID); } elseif (isset($_GET['event_id'])) { selected($_GET['event_id'], $event->ID); } ?> ><?php echo date(MDJM_SHORTDATE_FORMAT, strtotime(get_post_meta($event->ID, '_mdjm_event_date', true))) . ' from ' . date(MDJM_TIME_FORMAT, strtotime(get_post_meta($event->ID, '_mdjm_event_start', true))) . ' (' . $event_stati[$event->post_status] . ')'; ?> </option> <?php } echo '</select>'; } ?> <br /> <span class="description">Note: If no event is selected you cannot use MDJM Shortcodes in your email</span> </td> </tr> <?php ?> <tr class="alternate"> <th class="row-title" align="left"><label for="subject">Subject:</label></th> <td><input type="text" name="subject" id="subject" class="regular-text" value="<?php echo $subject; ?> " /></td> </tr> <tr class="alternate"> <th class="row-title" align="left"><label for="upload_file">Attach File from Computer:</label></th> <td><input type="file" name="upload_file" id="upload_file" class="regular-text" value="" /><p class="description"><?php echo __('Max file size', 'mobile-dj-manager') . ': ' . ini_get('post_max_size') . '. ' . sprintf(__('Change php.ini %spost_max_size%s to increase', 'mobile-dj-manager'), '<strong>', '</strong>'); ?> </p></td> </tr> <?php do_action('mdjm_comms_fields_last', $email_query, $contract_query); ?> <tr> <td colspan="2"><?php wp_editor(html_entity_decode(stripcslashes($content)), 'email_content', $settings); ?> </td> </tr> <tr> <td colspan="2"> <?php submit_button('Send Email', 'primary', 'submit', true); ?> </td> </tr> </table></td> <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="widefat"> <tr> <td align="center" class="alternate"><strong>To do List</strong></td> </tr> <tr> <td>Coming soon...!</td> </tr> </table></td> </tr> </table> </form> </div> <?php }