function cp_transactions() { global $wpdb, $wp_version; include_once TEMPLATEPATH . '/includes/forms/step-functions.php'; if (isset($_GET['p'])) { $page = (int) $_GET['p']; } else { $page = 1; } $per_page = 10; $start = $per_page * $page - $per_page; // check to prevent php "notice: undefined index" msg when php strict warnings is on if (isset($_GET['action'])) { $theswitch = $_GET['action']; } else { $theswitch = ''; } switch ($theswitch) { // mark transaction as paid case 'setPaid': $wpdb->update($wpdb->cp_order_info, array('payment_status' => 'Completed'), array('id' => $_GET['id'])); ?> <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Updating transaction entry.....', APP_TD); ?> <br /><br /><img src="<?php bloginfo('template_directory'); ?> /images/loader.gif" alt="" /></p> <meta http-equiv="refresh" content="0; URL=?page=transactions"> <?php break; // mark transaction as unpaid // mark transaction as unpaid case 'unsetPaid': $wpdb->update($wpdb->cp_order_info, array('payment_status' => 'Pending'), array('id' => $_GET['id'])); ?> <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Updating transaction entry.....', APP_TD); ?> <br /><br /><img src="<?php bloginfo('template_directory'); ?> /images/loader.gif" alt="" /></p> <meta http-equiv="refresh" content="0; URL=?page=transactions"> <?php break; // delete transaction entry // delete transaction entry case 'delete': if (version_compare($wp_version, '3.4', '>=')) { $wpdb->delete($wpdb->cp_order_info, array('id' => $_GET['id'])); } else { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->cp_order_info} WHERE id = %d", $_GET['id'])); } ?> <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Deleting transaction entry.....', APP_TD); ?> <br /><br /><img src="<?php bloginfo('template_directory'); ?> /images/loader.gif" alt="" /></p> <meta http-equiv="refresh" content="0; URL=?page=transactions"> <?php break; // activate membership, update transaction entry // activate membership, update transaction entry case 'activateMembership': $orders = get_user_orders('', $_GET['oid']); if (!empty($orders)) { $order_id = get_order_id($orders); $storedOrder = get_option($orders); $user_id = get_order_userid($orders); $the_user = get_userdata($user_id); //activate membership $order_processed = appthemes_process_membership_order($the_user, $storedOrder); //send email to user if ($order_processed) { cp_owner_activated_membership_email($the_user, $order_processed); } //update transaction entry $wpdb->update($wpdb->cp_order_info, array('payment_status' => 'Completed'), array('custom' => $_GET['oid'])); } ?> <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Activating membership plan.....', APP_TD); ?> <br /><br /><img src="<?php bloginfo('template_directory'); ?> /images/loader.gif" alt="" /></p> <meta http-equiv="refresh" content="0; URL=?page=transactions"> <?php break; // show the table of all transactions // show the table of all transactions default: ?> <div class="wrap"> <div class="icon32" id="icon-themes"><br /></div> <h2><?php _e('Order Transactions', APP_TD); ?> </h2> <?php cp_admin_info_box(); ?> <table id="tblspacer" class="widefat fixed"> <thead> <tr> <th scope="col" style="width:35px;"> </th> <th scope="col"><?php _e('Payer Name', APP_TD); ?> </th> <th scope="col" style="text-align: center;"><?php _e('Payer Status', APP_TD); ?> </th> <th scope="col"><?php _e('Ad Title', APP_TD); ?> </th> <th scope="col"><?php _e('Item Description', APP_TD); ?> </th> <th scope="col" style="width:125px;"><?php _e('Transaction ID', APP_TD); ?> </th> <th scope="col"><?php _e('Payment Type', APP_TD); ?> </th> <th scope="col"><?php _e('Payment Status', APP_TD); ?> </th> <th scope="col"><?php _e('Total Amount', APP_TD); ?> </th> <th scope="col" style="width:150px;"><?php _e('Date Paid', APP_TD); ?> </th> <th scope="col" style="text-align:center;width:100px;"><?php _e('Actions', APP_TD); ?> </th> </tr> </thead> <?php // must be higher than personal edition so let's query the db $sql = "SELECT SQL_CALC_FOUND_ROWS o.*, p.post_title " . "FROM {$wpdb->cp_order_info} o, {$wpdb->posts} p " . "WHERE o.ad_id = p.id " . "ORDER BY o.id DESC LIMIT {$start},{$per_page}"; $results = $wpdb->get_results($sql); $total_pages = $wpdb->get_var("SELECT FOUND_ROWS()"); $total_pages = ceil($total_pages / $per_page); if ($results) { $rowclass = ''; $i = 1; ?> <tbody id="list"> <?php foreach ($results as $result) { $rowclass = 'even' == $rowclass ? 'alt' : 'even'; if ($result->user_id > 0) { $user = get_user_by('id', $result->user_id); $user_link = $user ? '( <a href="user-edit.php?user_id=' . $user->ID . '" title="' . __('Edit user', APP_TD) . '">' . $user->user_login . '</a> )<br />' : ''; } else { $user_link = ''; } ?> <tr class="<?php echo $rowclass; ?> "> <td style="padding-left:10px;"><?php echo $i; ?> .</td> <td><strong><?php echo $result->first_name; ?> <?php echo $result->last_name; ?> </strong><br /><?php echo $user_link; ?> <a href="mailto:<?php echo $result->payer_email; ?> "><?php echo $result->payer_email; ?> </a></td> <td style="text-align: center;"> <?php if ($result->payer_status == 'verified') { ?> <img src="<?php bloginfo('template_directory'); ?> /images/paypal_verified.gif" alt="" title="" /><br /><?php } ?> <?php echo cp_get_status_i18n($result->payer_status); ?> </td> <td><a href="post.php?action=edit&post=<?php echo $result->ad_id; ?> "><?php echo $result->post_title; ?> </a></td> <td><?php echo $result->item_name; ?> </td> <td><?php echo $result->txn_id; ?> </td> <td><?php echo ucfirst($result->payment_type); ?> </td> <td><?php echo cp_get_status_i18n($result->payment_status); ?> </td> <td><?php cp_display_price($result->mc_gross, $result->mc_currency); ?> </td> <td><?php echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $result->payment_date); ?> </td> <td style="text-align:center"> <?php echo '<a onclick="return confirmBeforeDelete();" href="?page=transactions&action=delete&id=' . $result->id . '" title="' . __('Delete', APP_TD) . '"><img src="' . get_bloginfo('template_directory') . '/images/cross.png" alt="' . __('Delete', APP_TD) . '" /></a> '; if (strtolower($result->payment_status) == 'completed') { echo '<br /><a href="?page=transactions&action=unsetPaid&id=' . $result->id . '" title="' . __('Mark as Unpaid', APP_TD) . '">' . __('Unmark Paid', APP_TD) . '</a>'; } else { echo '<br /><a href="?page=transactions&action=setPaid&id=' . $result->id . '" title="' . __('Mark as Paid', APP_TD) . '">' . __('Mark Paid', APP_TD) . '</a>'; } ?> </td> </tr> <?php $i++; } // end for each ?> </tbody> <?php } else { ?> <tr> <td> </td><td colspan="10"><?php _e('No transactions found.', APP_TD); ?> </td> </tr> <?php } // end $results ?> </table> <!-- this is ok --> <div class="tablenav"> <div class="tablenav-pages alignright"> <?php if ($total_pages > 1) { echo paginate_links(array('base' => 'admin.php?page=transactions%_%', 'format' => '&p=%#%', 'prev_text' => __('« Previous', APP_TD), 'next_text' => __('Next »', APP_TD), 'total' => $total_pages, 'current' => $page, 'end_size' => 1, 'mid_size' => 5)); } ?> </div> </div> <div class="clear"></div> <div class="icon32" id="icon-themes"><br /></div> <h2><?php _e('Membership Orders', APP_TD); ?> </h2> <table id="tblspacer" class="widefat fixed"> <thead> <tr> <th scope="col" style="width:35px;"> </th> <th scope="col"><?php _e('Payer Name', APP_TD); ?> </th> <th scope="col" style="text-align: center;"><?php _e('Payer Status', APP_TD); ?> </th> <th scope="col"><?php _e('Item Description', APP_TD); ?> </th> <th scope="col" style="width:125px;"><?php _e('Transaction ID', APP_TD); ?> </th> <th scope="col"><?php _e('Payment Type', APP_TD); ?> </th> <th scope="col"><?php _e('Payment Status', APP_TD); ?> </th> <th scope="col"><?php _e('Total Amount', APP_TD); ?> </th> <th scope="col" style="width:150px;"><?php _e('Date Paid', APP_TD); ?> </th> <th scope="col" style="text-align:center;width:100px;"><?php _e('Actions', APP_TD); ?> </th> </tr> </thead> <?php // seperate table for membership orders $sql = "SELECT SQL_CALC_FOUND_ROWS * " . "FROM {$wpdb->cp_order_info} " . "WHERE ad_id = 0 " . "ORDER BY id DESC LIMIT {$start},{$per_page}"; $results = $wpdb->get_results($sql); $total_pages = $wpdb->get_var("SELECT FOUND_ROWS()"); $total_pages = ceil($total_pages / $per_page); if ($results) { $rowclass = ''; $i = 1; ?> <tbody id="list"> <?php foreach ($results as $result) { $rowclass = 'even' == $rowclass ? 'alt' : 'even'; if ($result->user_id > 0) { $user = get_user_by('id', $result->user_id); $user_link = $user ? '( <a href="user-edit.php?user_id=' . $user->ID . '" title="' . __('Edit user', APP_TD) . '">' . $user->user_login . '</a> )<br />' : ''; } else { $user_link = ''; } ?> <tr class="<?php echo $rowclass; ?> "> <td style="padding-left:10px;"><?php echo $i; ?> .</td> <?php $payer = get_user_by('email', $result->payer_email); ?> <?php //TODO - LOOKUP CUSTOMER BY PAYPAL EMAIL CUSTOM PROFILE FIELD ?> <td><strong><?php echo $result->first_name; ?> <?php echo $result->last_name; ?> </strong><br /><?php echo $user_link; ?> <a href="<?php if (isset($payer->ID) && $payer) { echo get_bloginfo('url') . '/wp-admin/user-edit.php?user_id=' . $payer->ID; } else { echo 'mailto:' . $result->payer_email; } ?> "><?php echo $result->payer_email; ?> </a></td> <td style="text-align: center;"> <?php if ($result->payer_status == 'verified') { ?> <img src="<?php bloginfo('template_directory'); ?> /images/paypal_verified.gif" alt="" title="" /><br /><?php } ?> <?php echo cp_get_status_i18n($result->payer_status); ?> </td> <td><?php echo $result->item_name; ?> </td> <td><?php echo $result->txn_id; ?> </td> <td><?php echo ucfirst($result->payment_type); ?> </td> <td><?php echo cp_get_status_i18n($result->payment_status); ?> </td> <td><?php cp_display_price($result->mc_gross, $result->mc_currency); ?> </td> <td><?php echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $result->payment_date); ?> </td> <td style="text-align:center"> <?php echo '<a onclick="return confirmBeforeDelete();" href="?page=transactions&action=delete&id=' . $result->id . '" title="' . __('Delete', APP_TD) . '"><img src="' . get_bloginfo('template_directory') . '/images/cross.png" alt="' . __('Delete', APP_TD) . '" /></a> '; if (strtolower($result->payment_status) == 'completed') { echo '<br /><a href="?page=transactions&action=unsetPaid&id=' . $result->id . '" title="' . __('Mark as Unpaid', APP_TD) . '">' . __('Unmark Paid', APP_TD) . '</a>'; } else { echo '<br /><a href="?page=transactions&action=setPaid&id=' . $result->id . '" title="' . __('Mark as Paid', APP_TD) . '">' . __('Mark Paid', APP_TD) . '</a>'; if (!empty($result->custom)) { $orders = get_user_orders('', $result->custom); } else { $orders = ''; } if (!empty($orders)) { echo '<br /><a href="?page=transactions&action=activateMembership&oid=' . $result->custom . '" title="' . __('Activate membership', APP_TD) . '">' . __('Activate membership', APP_TD) . '</a>'; } } ?> </td> </tr> <?php $i++; } // end for each ?> </tbody> <?php } else { ?> <tr> <td> </td><td colspan="9"><?php _e('No transactions found.', APP_TD); ?> </td> </tr> <?php } // end $results ?> </table> <!-- this is ok --> <div class="tablenav"> <div class="tablenav-pages alignright"> <?php if ($total_pages > 1) { echo paginate_links(array('base' => 'admin.php?page=transactions%_%', 'format' => '&p=%#%', 'prev_text' => __('« Previous', APP_TD), 'next_text' => __('Next »', APP_TD), 'total' => $total_pages, 'current' => $page, 'end_size' => 1, 'mid_size' => 5)); } ?> </div> </div> <div class="clear"></div> </div><!-- end wrap --> <?php } // endswitch ?> <script type="text/javascript"> /* <![CDATA[ */ function confirmBeforeDelete() { return confirm("<?php _e('WARNING: Are you sure you want to delete this transaction entry?? (This cannot be undone)', APP_TD); ?> "); } /* ]]> */ </script> <?php }
function cp_notify_ad_owner_email($new_status, $old_status, $post) { global $current_user, $wpdb, $cp_options; if ($post->post_type != APP_POST_TYPE) { return; } $the_ad = get_post($post->ID); $category = appthemes_get_custom_taxonomy($post->ID, APP_TAX_CAT, 'name'); $ad_title = stripslashes($the_ad->post_title); $ad_cat = stripslashes($category); $ad_author_id = stripslashes(get_the_author_meta('ID', $the_ad->post_author)); $ad_author = stripslashes(cp_get_user_name($the_ad->post_author)); $ad_author_email = stripslashes(get_the_author_meta('user_email', $the_ad->post_author)); $ad_status = cp_get_status_i18n($the_ad->post_status); $ad_content = appthemes_filter(stripslashes($the_ad->post_content)); $siteurl = home_url('/'); $dashurl = trailingslashit(CP_DASHBOARD_URL); $mailto = $ad_author_email; // The blogname option is escaped with esc_html on the way into the database in sanitize_option // we want to reverse this for the plain text arena of emails. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); // make sure the admin wants to send emails $send_approved_email = $cp_options->new_ad_email_owner; $send_expired_email = $cp_options->expired_ad_email_owner; // if the ad has been approved send email to ad owner only if owner is not equal to approver // admin approving own ads or ad owner pausing and reactivating ad on his dashboard don't need to send email if ($old_status == 'pending' && $new_status == 'publish' && $current_user->ID != $ad_author_id && $send_approved_email) { $subject = __('Your ad has been approved', APP_TD); $message = sprintf(__('Hi %s,', APP_TD), $ad_author) . "\r\n\r\n"; $message .= sprintf(__('Your ad listing, "%s" has been approved and is now live on our site.', APP_TD), $ad_title) . "\r\n\r\n"; $message .= __('You can view your ad by clicking on the following link:', APP_TD) . "\r\n"; $message .= get_permalink($post->ID) . "\r\n\r\n\r\n\r\n"; $message .= __('Regards,', APP_TD) . "\r\n\r\n"; $message .= sprintf(__('Your %s Team', APP_TD), $blogname) . "\r\n"; $message .= $siteurl . "\r\n\r\n\r\n\r\n"; $email = array('to' => $mailto, 'subject' => $subject, 'message' => $message); $email = apply_filters('cp_email_user_ad_approved', $email, $post); wp_mail($email['to'], $email['subject'], $email['message']); // if the ad has expired, send an email to the ad owner only if owner is not equal to approver } elseif ($old_status == 'publish' && $new_status == 'draft' && $current_user->ID != $ad_author_id && $send_expired_email) { $subject = __('Your ad has expired', APP_TD); $message = sprintf(__('Hi %s,', APP_TD), $ad_author) . "\r\n\r\n"; $message .= sprintf(__('Your ad listing, "%s" has expired.', APP_TD), $ad_title) . "\r\n\r\n"; if ($cp_options->allow_relist) { $message .= __('If you would like to relist your ad, please visit your dashboard and click the "relist" link.', APP_TD) . "\r\n"; $message .= $dashurl . "\r\n\r\n\r\n\r\n"; } $message .= __('Regards,', APP_TD) . "\r\n\r\n"; $message .= sprintf(__('Your %s Team', APP_TD), $blogname) . "\r\n"; $message .= $siteurl . "\r\n\r\n\r\n\r\n"; $email = array('to' => $mailto, 'subject' => $subject, 'message' => $message); $email = apply_filters('cp_email_user_ad_expired', $email, $post); wp_mail($email['to'], $email['subject'], $email['message']); } }
function cp_form_layouts() { global $options_new_form, $wpdb, $current_user; $current_user = wp_get_current_user(); // check to prevent php "notice: undefined index" msg when php strict warnings is on if (isset($_GET['action'])) { $theswitch = $_GET['action']; } else { $theswitch = ''; } ?> <script type="text/javascript"> /* <![CDATA[ */ /* initialize the form validation */ jQuery(document).ready(function($) { $("#mainform").validate({errorClass: "invalid"}); }); /* ]]> */ </script> <?php switch ($theswitch) { case 'addform': ?> <div class="wrap"> <div class="icon32" id="icon-themes"><br /></div> <h2><?php _e('New Form Layout', APP_TD); ?> </h2> <?php // check and make sure the form was submitted and the hidden fcheck id matches the cookie fcheck id if (isset($_POST['submitted'])) { if (!isset($_POST['post_category'])) { wp_die('<p style="color:red;">' . __('Error: Please select at least one category.', APP_TD) . " <a href='#' onclick='history.go(-1);return false;'>" . __('Go back', APP_TD) . '</a></p>'); } $data = array('form_name' => cp_make_custom_name($_POST['form_label'], 'forms'), 'form_label' => appthemes_clean($_POST['form_label']), 'form_desc' => appthemes_clean($_POST['form_desc']), 'form_cats' => serialize($_POST['post_category']), 'form_status' => appthemes_clean($_POST['form_status']), 'form_owner' => appthemes_clean($_POST['form_owner']), 'form_created' => current_time('mysql')); $insert = $wpdb->insert($wpdb->cp_ad_forms, $data); if ($insert) { ?> <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Creating your form.....', APP_TD); ?> <br /><br /><img src="<?php echo get_template_directory_uri(); ?> /images/loader.gif" alt="" /></p> <meta http-equiv="refresh" content="0; URL=?page=layouts"> <?php } // end $insert } else { ?> <form method="post" id="mainform" action=""> <?php echo cp_admin_fields($options_new_form); ?> <p class="submit"><input class="btn button-primary" name="save" type="submit" value="<?php _e('Create New Form', APP_TD); ?> " /> <input class="btn button-secondary" name="cancel" type="button" onClick="location.href='?page=layouts'" value="<?php _e('Cancel', APP_TD); ?> " /></p> <input name="submitted" type="hidden" value="yes" /> <input name="form_owner" type="hidden" value="<?php echo $current_user->user_login; ?> " /> </form> <?php } // end isset $_POST ?> </div><!-- end wrap --> <?php break; case 'editform': ?> <div class="wrap"> <div class="icon32" id="icon-themes"><br /></div> <h2><?php _e('Edit Form Properties', APP_TD); ?> </h2> <?php if (isset($_POST['submitted']) && $_POST['submitted'] == 'yes') { if (!isset($_POST['post_category'])) { wp_die('<p style="color:red;">' . __('Error: Please select at least one category.', APP_TD) . " <a href='#' onclick='history.go(-1);return false;'>" . __('Go back', APP_TD) . '</a></p>'); } $data = array('form_label' => appthemes_clean($_POST['form_label']), 'form_desc' => appthemes_clean($_POST['form_desc']), 'form_cats' => serialize($_POST['post_category']), 'form_status' => appthemes_clean($_POST['form_status']), 'form_owner' => appthemes_clean($_POST['form_owner']), 'form_modified' => current_time('mysql')); $wpdb->update($wpdb->cp_ad_forms, $data, array('id' => $_GET['id'])); ?> <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Saving your changes.....', APP_TD); ?> <br /><br /><img src="<?php echo get_template_directory_uri(); ?> /images/loader.gif" alt="" /></p> <meta http-equiv="refresh" content="0; URL=?page=layouts"> <?php } else { ?> <form method="post" id="mainform" action=""> <?php echo cp_admin_db_fields($options_new_form, 'cp_ad_forms', 'id'); ?> <p class="submit"><input class="btn button-primary" name="save" type="submit" value="<?php _e('Save changes', APP_TD); ?> " /> <input class="btn button-secondary" name="cancel" type="button" onClick="location.href='?page=layouts'" value="<?php _e('Cancel', APP_TD); ?> " /></p> <input name="submitted" type="hidden" value="yes" /> <input name="form_owner" type="hidden" value="<?php echo $current_user->user_login; ?> " /> </form> <?php } // end isset $_POST ?> </div><!-- end wrap --> <?php break; /** * Form Builder Page * Where fields are added to form layouts */ /** * Form Builder Page * Where fields are added to form layouts */ case 'formbuilder': ?> <div class="wrap"> <div class="icon32" id="icon-themes"><br /></div> <h2><?php _e('Edit Form Layout', APP_TD); ?> </h2> <?php // add fields to page layout on left side if (isset($_POST['field_id'])) { // take selected checkbox array and loop through ids foreach ($_POST['field_id'] as $value) { $data = array('form_id' => appthemes_clean($_POST['form_id']), 'field_id' => appthemes_clean($value), 'field_pos' => '99'); $insert = $wpdb->insert($wpdb->cp_ad_meta, $data); } // end foreach } // end $_POST // update form layout positions and required fields on left side. if (isset($_POST['formlayout'])) { // loop through the post array and update the required checkbox and field position foreach ($_POST as $key => $value) { // since there's some $_POST values we don't want to process, only give us the // numeric ones which means it contains a meta_id and we want to update it if (is_numeric($key)) { // quick hack to prevent php "notice: undefined index:" msg when php strict warnings is on if (!isset($value['field_req'])) { $value['field_req'] = '0'; } if (!isset($value['field_search'])) { $value['field_search'] = '0'; } $data = array('field_req' => appthemes_clean($value['field_req']), 'field_search' => appthemes_clean($value['field_search'])); $wpdb->update($wpdb->cp_ad_meta, $data, array('meta_id' => $key)); } // end if_numeric } // end for each echo '<p class="info">' . __('Your changes have been saved.', APP_TD) . '</p>'; } // end isset $_POST // check to prevent php "notice: undefined index" msg when php strict warnings is on if (isset($_GET['del_id'])) { $theswitch = $_GET['del_id']; } else { $theswitch = ''; } // Remove items from form layout if ($theswitch) { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->cp_ad_meta} WHERE meta_id = %s", $_GET['del_id'])); } //update the forms modified date $data = array('form_modified' => current_time('mysql')); $wpdb->update($wpdb->cp_ad_forms, $data, array('id' => $_GET['id'])); ?> <table> <tr style="vertical-align:top;"> <td style="width:800px;padding:0 20px 0 0;"> <h3><?php _e('Form Name', APP_TD); ?> - <?php echo ucfirst(urldecode($_GET['title'])); ?> <span id="loading"></span></h3> <form method="post" id="mainform" action=""> <table class="widefat"> <thead> <tr> <th scope="col" colspan="2"><?php _e('Form Preview', APP_TD); ?> </th> <th scope="col" style="width:75px;text-align:center;" title="<?php _e('Show field in the category refine search sidebar', APP_TD); ?> "><?php _e('Advanced Search', APP_TD); ?> </th> <th scope="col" style="width:75px;text-align:center;"><?php _e('Required', APP_TD); ?> </th> <th scope="col" style="width:75px;text-align:center;"><?php _e('Remove', APP_TD); ?> </th> </tr> </thead> <tbody class="sortable"> <?php // If this is the first time this form is being customized then auto // create the core fields and put in cp_meta db table echo cp_add_core_fields($_GET['id']); // Then go back and select all the fields assigned to this // table which now includes the added core fields. $sql = $wpdb->prepare("SELECT f.field_label, f.field_name, f.field_type, f.field_values, f.field_perm, m.meta_id, m.field_pos, m.field_search, m.field_req, m.form_id " . "FROM {$wpdb->cp_ad_fields} f " . "INNER JOIN {$wpdb->cp_ad_meta} m " . "ON f.field_id = m.field_id " . "WHERE m.form_id = %s " . "ORDER BY m.field_pos asc", $_GET['id']); $results = $wpdb->get_results($sql); if ($results) { echo cp_admin_formbuilder($results); } else { ?> <tr> <td colspan="5" style="text-align: center;"><p><br /><?php _e('No fields have been added to this form layout yet.', APP_TD); ?> <br /><br /></p></td> </tr> <?php } // end $results ?> </tbody> </table> <p class="submit"> <input class="btn button-primary" name="save" type="submit" value="<?php _e('Save Changes', APP_TD); ?> " /> <input class="btn button-secondary" name="cancel" type="button" onClick="location.href='?page=layouts'" value="<?php _e('Cancel', APP_TD); ?> " /> <input name="formlayout" type="hidden" value="yes" /> <input name="form_owner" type="hidden" value="<?php $current_user->user_login; ?> " /> </p> </form> </td> <td> <h3><?php _e('Available Fields', APP_TD); ?> </h3> <form method="post" id="mainform" action=""> <div class="fields-panel"> <table class="widefat"> <thead> <tr> <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"/></th> <th scope="col"><?php _e('Field Name', APP_TD); ?> </th> <th scope="col"><?php _e('Type', APP_TD); ?> </th> </tr> </thead> <tbody> <?php // Select all available fields not currently on the form layout. // Also exclude any core fields since they cannot be removed from the layout. $sql = $wpdb->prepare("SELECT f.field_id,f.field_label,f.field_type " . "FROM {$wpdb->cp_ad_fields} f " . "WHERE f.field_id " . "NOT IN (SELECT m.field_id " . "FROM {$wpdb->cp_ad_meta} m " . "WHERE m.form_id = %s) " . "AND f.field_perm <> '1'", $_GET['id']); $results = $wpdb->get_results($sql); if ($results) { foreach ($results as $result) { ?> <tr class="even"> <th class="check-column" scope="row"><input type="checkbox" value="<?php echo $result->field_id; ?> " name="field_id[]"/></th> <td><?php echo esc_html(translate($result->field_label, APP_TD)); ?> </td> <td><?php echo $result->field_type; ?> </td> </tr> <?php } // end foreach } else { ?> <tr> <td colspan="4" style="text-align: center;"><p><br /><?php _e('No fields are available.', APP_TD); ?> <br /><br /></p></td> </tr> <?php } // end $results ?> </tbody> </table> </div> <p class="submit"><input class="btn button-primary" name="save" type="submit" value="<?php _e('Add Fields to Form Layout', APP_TD); ?> " /></p> <input name="form_id" type="hidden" value="<?php echo $_GET['id']; ?> " /> <input name="submitted" type="hidden" value="yes" /> </form> </td> </tr> </table> </div><!-- /wrap --> <?php break; case 'delete': // delete the form based on the form id cp_delete_form($_GET['id']); ?> <p style="text-align:center;padding-top:50px;font-size:22px;"><?php _e('Deleting form layout.....', APP_TD); ?> <br /><br /><img src="<?php echo get_template_directory_uri(); ?> /images/loader.gif" alt="" /></p> <meta http-equiv="refresh" content="0; URL=?page=layouts"> <?php break; default: $results = $wpdb->get_results("SELECT * FROM {$wpdb->cp_ad_forms} ORDER BY id desc"); ?> <div class="wrap"> <div class="icon32" id="icon-themes"><br /></div> <h2><?php _e('Form Layouts', APP_TD); ?> <a class="add-new-h2" href="?page=layouts&action=addform"><?php _e('Add New', APP_TD); ?> </a></h2> <p class="admin-msg"><?php _e('Form layouts allow you to create your own custom ad submission forms. Each form is essentially a container for your fields and can be applied to one or all of your categories. If you do not create any form layouts, the default one will be used. To change the default form, create a new form layout and apply it to all categories.', APP_TD); ?> </p> <table id="tblspacer" class="widefat fixed"> <thead> <tr> <th scope="col" style="width:35px;"> </th> <th scope="col"><?php _e('Name', APP_TD); ?> </th> <th scope="col"><?php _e('Description', APP_TD); ?> </th> <th scope="col"><?php _e('Categories', APP_TD); ?> </th> <th scope="col" style="width:150px;"><?php _e('Modified', APP_TD); ?> </th> <th scope="col" style="width:75px;"><?php _e('Status', APP_TD); ?> </th> <th scope="col" style="text-align:center;width:100px;"><?php _e('Actions', APP_TD); ?> </th> </tr> </thead> <?php if ($results) { $rowclass = ''; $i = 1; ?> <tbody id="list"> <?php foreach ($results as $result) { $rowclass = 'even' == $rowclass ? 'alt' : 'even'; ?> <tr class="<?php echo $rowclass; ?> "> <td style="padding-left:10px;"><?php echo $i; ?> .</td> <td><a href="?page=layouts&action=editform&id=<?php echo $result->id; ?> "><strong><?php echo $result->form_label; ?> </strong></a></td> <td><?php echo $result->form_desc; ?> </td> <td><?php echo cp_match_cats(unserialize($result->form_cats)); ?> </td> <td><?php echo appthemes_display_date($result->form_modified); ?> <?php _e('by', APP_TD); ?> <?php echo $result->form_owner; ?> </td> <td><?php echo cp_get_status_i18n($result->form_status); ?> </td> <td style="text-align:center"><a href="?page=layouts&action=formbuilder&id=<?php echo $result->id; ?> &title=<?php echo urlencode($result->form_label); ?> "><img src="<?php echo get_template_directory_uri(); ?> /images/layout_add.png" alt="<?php _e('Edit form layout', APP_TD); ?> " title="<?php _e('Edit form layout', APP_TD); ?> " /></a> <a href="?page=layouts&action=editform&id=<?php echo $result->id; ?> "><img src="<?php echo get_template_directory_uri(); ?> /images/edit.png" alt="<?php _e('Edit form properties', APP_TD); ?> " title="<?php _e('Edit form properties', APP_TD); ?> " /></a> <a onclick="return confirmBeforeDelete();" href="?page=layouts&action=delete&id=<?php echo $result->id; ?> "><img src="<?php echo get_template_directory_uri(); ?> /images/cross.png" alt="<?php _e('Delete form layout', APP_TD); ?> " title="<?php _e('Delete form layout', APP_TD); ?> " /></a></td> </tr> <?php $i++; } // end for each ?> </tbody> <?php } else { ?> <tr> <td colspan="7"><?php _e('No form layouts found.', APP_TD); ?> </td> </tr> <?php } // end $results ?> </table> </div><!-- end wrap --> <?php } // end switch ?> <script type="text/javascript"> /* <![CDATA[ */ function confirmBeforeDelete() { return confirm("<?php _e('Are you sure you want to delete this?', APP_TD); ?> "); } function confirmBeforeRemove() { return confirm("<?php _e('Are you sure you want to remove this?', APP_TD); ?> "); } /* ]]> */ </script> <?php }
/** * Sends email to ad owner when an ad is approved or expires. * * @param string $new_status * @param string $old_status * @param object $post * * @return void */ function cp_notify_ad_owner_email($new_status, $old_status, $post) { global $current_user, $cp_options; if ($post->post_type != APP_POST_TYPE) { return; } $title = $post->post_title; $category = appthemes_get_custom_taxonomy($post->ID, APP_TAX_CAT, 'name'); $author = stripslashes(cp_get_user_name($post->post_author)); $author_email = stripslashes(get_the_author_meta('user_email', $post->post_author)); $post_status = cp_get_status_i18n($post->post_status); $site_url = home_url('/'); $dashboard_url = trailingslashit(CP_DASHBOARD_URL); $blogname = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); // make sure the admin wants to send emails $send_approved_email = $cp_options->new_ad_email_owner; $send_expired_email = $cp_options->expired_ad_email_owner; // if the ad has been approved send email to ad owner only if owner is not equal to approver // admin approving own ads or ad owner pausing and reactivating ad on his dashboard don't need to send email if ($old_status == 'pending' && $new_status == 'publish' && $current_user->ID != $post->post_author && $send_approved_email) { $subject = __('Your ad has been approved', APP_TD); $message = html('p', sprintf(__('Hi %s,', APP_TD), $author)) . PHP_EOL; $message .= html('p', sprintf(__('Your ad listing, "%s" has been approved and is now live on our site.', APP_TD), $title)) . PHP_EOL; $message .= html('p', __('You can view your ad by clicking on the following link:', APP_TD) . '<br />' . html_link(get_permalink($post->ID))) . PHP_EOL; $message .= html('p', __('Regards,', APP_TD) . '<br />' . sprintf(__('Your %s Team', APP_TD), $blogname)) . PHP_EOL; $message .= html('p', html_link($site_url)) . PHP_EOL; $email = array('to' => $author_email, 'subject' => $subject, 'message' => $message); $email = apply_filters('cp_email_user_ad_approved', $email, $post); appthemes_send_email($email['to'], $email['subject'], $email['message']); // if the ad has expired, send an email to the ad owner only if owner is not equal to approver } elseif ($old_status == 'publish' && $new_status == 'draft' && $current_user->ID != $post->post_author && $send_expired_email) { $subject = __('Your ad has expired', APP_TD); $message = html('p', sprintf(__('Hi %s,', APP_TD), $author)) . PHP_EOL; $message .= html('p', sprintf(__('Your ad listing, "%s" has expired.', APP_TD), $title)) . PHP_EOL; if ($cp_options->allow_relist) { $message .= html('p', __('If you would like to relist your ad, please visit your dashboard and click the "relist" link.', APP_TD) . '<br />' . html_link($dashboard_url)) . PHP_EOL; } $message .= html('p', __('Regards,', APP_TD) . '<br />' . sprintf(__('Your %s Team', APP_TD), $blogname)) . PHP_EOL; $message .= html('p', html_link($site_url)) . PHP_EOL; $email = array('to' => $author_email, 'subject' => $subject, 'message' => $message); $email = apply_filters('cp_email_user_ad_expired', $email, $post); appthemes_send_email($email['to'], $email['subject'], $email['message']); } }
</td> <?php if (current_theme_supports('app-stats')) { ?> <td class="text-center"><?php echo appthemes_get_stats_by($post->ID, 'total'); ?> </td> <?php } ?> <td class="text-center"> <span class="status"><?php echo cp_get_status_i18n($status); ?> </span> <?php if (in_array($status, array('live', 'live_expired', 'ended'))) { ?> <p class="small muted">(<?php echo $expire_date; ?> )</p> <?php } ?> </td> <td class="text-center"><?php
function cp_notify_ad_owner_email($new_status, $old_status, $post) { global $current_user, $wpdb; //$contributor = get_userdata($post->post_author); $the_ad = get_post($post->ID); $category = appthemes_get_custom_taxonomy($post->ID, APP_TAX_CAT, 'name'); $ad_title = stripslashes($the_ad->post_title); $ad_cat = stripslashes($category); $ad_author_id = stripslashes(get_the_author_meta('ID', $the_ad->post_author)); $ad_author = stripslashes(cp_get_user_name($the_ad->post_author)); $ad_author_email = stripslashes(get_the_author_meta('user_email', $the_ad->post_author)); $ad_status = cp_get_status_i18n($the_ad->post_status); $ad_content = appthemes_filter(stripslashes($the_ad->post_content)); $siteurl = trailingslashit(get_option('home')); $dashurl = trailingslashit(CP_DASHBOARD_URL); // check to see if ad is legacy or not if (get_post_meta($post->ID, 'email', true)) { $mailto = get_post_meta($post->ID, 'email', true); } else { $mailto = $ad_author_email; } //$mailto = 'tester@127.0.0.1'; // USED FOR TESTING // The blogname option is escaped with esc_html on the way into the database in sanitize_option // we want to reverse this for the plain text arena of emails. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); // make sure the admin wants to send emails $send_approved_email = get_option('cp_new_ad_email_owner'); $send_expired_email = get_option('cp_expired_ad_email_owner'); // if the ad has been approved send email to ad owner only if owner is not equal to approver // admin approving own ads or ad owner pausing and reactivating ad on his dashboard don't need to send email if ($old_status == 'pending' && $new_status == 'publish' && $current_user->ID != $ad_author_id && $send_approved_email == 'yes') { $subject = __('Your ad has been approved', APP_TD); $headers = 'From: ' . sprintf(__('%s Admin', APP_TD), $blogname) . ' <' . get_option('admin_email') . '>' . "\r\n"; $message = sprintf(__('Hi %s,', APP_TD), $ad_author) . "\r\n\r\n"; $message .= sprintf(__('Your ad listing, "%s" has been approved and is now live on our site.', APP_TD), $ad_title) . "\r\n\r\n"; $message .= __('You can view your ad by clicking on the following link:', APP_TD) . "\r\n"; $message .= get_permalink($post->ID) . "\r\n\r\n\r\n\r\n"; $message .= __('Regards,', APP_TD) . "\r\n\r\n"; $message .= sprintf(__('Your %s Team', APP_TD), $blogname) . "\r\n"; $message .= $siteurl . "\r\n\r\n\r\n\r\n"; // ok let's send the email wp_mail($mailto, $subject, $message, $headers); // if the ad has expired, send an email to the ad owner only if owner is not equal to approver } elseif ($old_status == 'publish' && $new_status == 'draft' && $current_user->ID != $ad_author_id && $send_expired_email == 'yes') { $subject = __('Your ad has expired', APP_TD); $headers = 'From: ' . sprintf(__('%s Admin', APP_TD), $blogname) . ' <' . get_option('admin_email') . '>' . "\r\n"; $message = sprintf(__('Hi %s,', APP_TD), $ad_author) . "\r\n\r\n"; $message .= sprintf(__('Your ad listing, "%s" has expired.', APP_TD), $ad_title) . "\r\n\r\n"; if (get_option('cp_allow_relist') == 'yes') { $message .= __('If you would like to relist your ad, please visit your dashboard and click the "relist" link.', APP_TD) . "\r\n"; $message .= $dashurl . "\r\n\r\n\r\n\r\n"; } $message .= __('Regards,', APP_TD) . "\r\n\r\n"; $message .= sprintf(__('Your %s Team', APP_TD), $blogname) . "\r\n"; $message .= $siteurl . "\r\n\r\n\r\n\r\n"; // ok let's send the email wp_mail($mailto, $subject, $message, $headers); } }