function jr_update_listing_after_payment($posted) { global $jr_log; $jr_log->write_log('Valid IPN response detected: ' . print_r($posted, true)); // Custom holds post ID if (!empty($posted['txn_type']) && !empty($posted['custom']) && is_numeric($posted['custom']) && $posted['custom'] > 0) { $accepted_types = array('cart', 'express_checkout', 'web_accept'); // Check transation is what we want if (!in_array(strtolower($posted['txn_type']), $accepted_types)) { exit; } $jr_order = new jr_order($posted['custom']); if ($jr_order->order_key !== $posted['item_number']) { exit; } if ($posted['test_ipn'] == 1 && $posted['payment_status'] == 'Pending') { $posted['payment_status'] = 'completed'; } // We are here so lets check status and do actions switch (strtolower($posted['payment_status'])) { case 'completed': // Payment was made so we can approve the job $jr_order->complete_order('IPN'); $payment_data = array(); $payment_data['payment_date'] = date("Y-m-d H:i:s"); $payment_data['payer_first_name'] = stripslashes(trim($_POST['first_name'])); $payment_data['payer_last_name'] = stripslashes(trim($_POST['last_name'])); $payment_data['payer_email'] = stripslashes(trim($_POST['payer_email'])); $payment_data['payment_type'] = 'PayPal'; $payment_data['approval_method'] = 'IPN'; $payment_data['payer_address'] = stripslashes(trim($_POST['residence_country'])); $payment_data['transaction_id'] = stripslashes(trim($_POST['txn_id'])); $jr_order->add_payment($payment_data); $jr_log->write_log('IPN Transaction Completed for Order #' . $posted['custom']); break; case 'denied': case 'expired': case 'failed': case 'voided': // In these cases the payment failed so we can trash the job $jr_order->cancel_order(); $jr_log->write_log('IPN Transaction Failed for Order #' . $posted['custom']); break; default: // Default if action not recognised $jr_log->write_log('IPN Transaction default action. Nothing done. Order #' . $posted['custom']); break; } } }
/** * JobRoller Relist Job Process * Processes a job edit/relist. * * * @version 1.3 * @author AppThemes * @package JobRoller * @copyright 2010 all rights reserved * */ function jr_process_relist_job_form() { global $user_ID, $post, $posted, $job_details, $wpdb, $jr_log; $errors = new WP_Error(); if (isset($_POST['job_submit']) && $_POST['job_submit']) { include_once ABSPATH . 'wp-admin/includes/file.php'; include_once ABSPATH . 'wp-admin/includes/image.php'; include_once ABSPATH . 'wp-admin/includes/media.php'; // Get (and clean) data $fields = array('your_name', 'website', 'job_title', 'job_term_type', 'job_term_cat', 'job_pack', 'jr_geo_latitude', 'jr_geo_longitude', 'jr_address', 'details', 'apply', 'tags'); foreach ($fields as $field) { $posted[$field] = stripslashes(trim($_POST[$field])); } if (isset($_POST['featureit']) && $_POST['featureit']) { $posted['featureit'] = 'yes'; } else { $posted['featureit'] = ''; } ### Strip html if (get_option('jr_html_allowed') == 'no') { $posted['details'] = strip_tags($posted['details']); $posted['apply'] = strip_tags($posted['apply']); } ### End strip // Check required fields $required = array('job_title' => __('Job title', 'appthemes'), 'job_term_type' => __('Job type', 'appthemes'), 'details' => __('Job description', 'appthemes')); if (get_option('jr_submit_cat_required') == 'yes') { $submit_cat = array('job_term_cat' => __('Job category', 'appthemes')); $required = array_merge($required, $submit_cat); } foreach ($required as $field => $name) { if (empty($posted[$field])) { $errors->add('submit_error', __('<strong>ERROR</strong>: “', 'appthemes') . $name . __('” is a required field.', 'appthemes')); } } if ($errors && sizeof($errors) > 0 && $errors->get_error_code()) { // Do nothing - edit has failed } else { // So far, so good. Upload logo if set. if (isset($_FILES['company-logo']) && !empty($_FILES['company-logo']['name'])) { $posted['company-logo-name'] = $_FILES['company-logo']['name']; // Check valid extension $allowed = array('png', 'gif', 'jpg', 'jpeg'); //$extension = strtolower(pathinfo($_FILES['company-logo']['name'], PATHINFO_EXTENSION)); $extension = strtolower(substr(strrchr($_FILES['company-logo']['name'], "."), 1)); if (!in_array($extension, $allowed)) { $errors->add('submit_error', __('<strong>ERROR</strong>: Only jpg, gif, and png images are allowed.', 'appthemes')); } function company_logo_upload_dir($pathdata) { $subdir = '/company_logos' . $pathdata['subdir']; $pathdata['path'] = str_replace($pathdata['subdir'], $subdir, $pathdata['path']); $pathdata['url'] = str_replace($pathdata['subdir'], $subdir, $pathdata['url']); $pathdata['subdir'] = str_replace($pathdata['subdir'], $subdir, $pathdata['subdir']); return $pathdata; } add_filter('upload_dir', 'company_logo_upload_dir'); $time = current_time('mysql'); $overrides = array('test_form' => false); $file = wp_handle_upload($_FILES['company-logo'], $overrides, $time); remove_filter('upload_dir', 'company_logo_upload_dir'); if (!isset($file['error'])) { $posted['company-logo'] = $file['url']; $posted['company-logo-type'] = $file['type']; $posted['company-logo-file'] = $file['file']; } else { $errors->add('submit_error', __('<strong>ERROR</strong>: ', 'appthemes') . $file['error'] . ''); } } } if ($errors && sizeof($errors) > 0 && $errors->get_error_code()) { // Do nothing - edit has failed } else { // Good to go, lets save this bad boy and show a confirmation message // Calc costs/get packs $cost = 0; $job_pack = ''; $user_pack = ''; $jobs_last = ''; // Get Pack from previous step if (isset($posted['job_pack']) && !empty($posted['job_pack'])) { if (strstr($posted['job_pack'], 'user_')) { $user_pack_id = (int) str_replace('user_', '', $posted['job_pack']); $user_pack = new jr_user_pack($user_pack_id); if (!$user_pack->get_valid_pack()) { wp_die(__('Error: Invalid Pack.', 'appthemes')); } $jobs_last = $user_pack->job_duration; } else { $job_pack = new jr_pack($posted['job_pack']); $cost += $job_pack->pack_cost; $jobs_last = $job_pack->job_duration; } } else { // No Packs $listing_cost = get_option('jr_jobs_relisting_cost'); $cost += $listing_cost; } // Caculate expirey date from today if (!$jobs_last) { $jobs_last = 30; } // 30 day default $date = strtotime('+' . $jobs_last . ' day', current_time('timestamp')); // Get Featured from previous step if ($posted['featureit'] == 'yes') { $featured_cost = get_option('jr_cost_to_feature'); $cost += $featured_cost; } ### Approval needed? $status = 'publish'; if ($cost > 0 && !$user_pack) { $status = 'pending'; } ### Update Post $data = array('ID' => $job_details->ID, 'post_content' => $wpdb->escape($posted['details']), 'post_title' => $wpdb->escape($posted['job_title']), 'post_status' => $status, 'post_date' => date('Y-m-d H:i:s'), 'post_date_gmt' => get_gmt_from_date(date('Y-m-d H:i:s'))); wp_update_post($data); ### Update meta data and category update_post_meta($job_details->ID, '_Company', $posted['your_name']); update_post_meta($job_details->ID, '_CompanyURL', $posted['website']); update_post_meta($job_details->ID, '_how_to_apply', $posted['apply']); update_post_meta($job_details->ID, '_expires', $date); $post_into_cats = array(); $post_into_types = array(); if ($posted['job_term_cat'] > 0) { $post_into_cats[] = get_term_by('id', $posted['job_term_cat'], 'job_cat')->slug; } ### Set Categories if ($posted['featureit'] == 'yes') { global $featured_job_cat_id; $featured_job_cat_name = get_term_by('id', $featured_job_cat_id, 'job_cat')->name; $post_into_cats[] = sanitize_title($featured_job_cat_name); } if (sizeof($post_into_cats) > 0) { wp_set_object_terms($job_details->ID, $post_into_cats, 'job_cat'); } $post_into_types[] = get_term_by('slug', sanitize_title($posted['job_term_type']), 'job_type')->slug; if (sizeof($post_into_types) > 0) { wp_set_object_terms($job_details->ID, $post_into_types, 'job_type'); } ### Salary $salary = array(); if ($posted['job_term_salary'] > 0) { $salary[] = get_term_by('id', $posted['job_term_salary'], 'job_salary')->slug; } wp_set_object_terms($job_details->ID, $salary, 'job_salary'); ### Tags if ($posted['tags']) { $thetags = explode(',', $posted['tags']); $thetags = array_map('trim', $thetags); $thetags = array_map('strtolower', $thetags); if (sizeof($thetags) > 0) { wp_set_object_terms($job_details->ID, $thetags, 'job_tag'); } } ### GEO if (!empty($posted['jr_address'])) { $latitude = jr_clean_coordinate($posted['jr_geo_latitude']); $longitude = jr_clean_coordinate($posted['jr_geo_longitude']); update_post_meta($job_details->ID, '_jr_geo_latitude', $latitude); update_post_meta($job_details->ID, '_jr_geo_longitude', $longitude); if ($latitude && $longitude) { $address = jr_reverse_geocode($latitude, $longitude); update_post_meta($job_details->ID, 'geo_address', $address['address']); update_post_meta($job_details->ID, 'geo_country', $address['country']); update_post_meta($job_details->ID, 'geo_short_address', $address['short_address']); update_post_meta($job_details->ID, 'geo_short_address_country', $address['short_address_country']); } } else { // They left the field blank so we assume the job is for 'anywhere' delete_post_meta($job_details->ID, '_jr_geo_latitude'); delete_post_meta($job_details->ID, '_jr_geo_longitude'); delete_post_meta($job_details->ID, 'geo_address'); delete_post_meta($job_details->ID, 'geo_country'); delete_post_meta($job_details->ID, 'geo_short_address'); delete_post_meta($job_details->ID, 'geo_short_address_country'); } ## Link to company image if (isset($posted['company-logo']) && $posted['company-logo']) { $name_parts = pathinfo($posted['company-logo-name']); $name = trim(substr($name, 0, -(1 + strlen($name_parts['extension'])))); $url = $posted['company-logo']; $type = $posted['company-logo-type']; $file = $posted['company-logo-file']; $title = $posted['company-logo-name']; $content = ''; // use image exif/iptc data for title and caption defaults if possible if ($image_meta = @wp_read_image_metadata($file)) { if (trim($image_meta['title'])) { $title = $image_meta['title']; } if (trim($image_meta['caption'])) { $content = $image_meta['caption']; } } // Construct the attachment array $attachment = array_merge(array('post_mime_type' => $type, 'guid' => $url, 'post_parent' => $job_details->ID, 'post_title' => $title, 'post_content' => $content), array()); // Save the data $id = wp_insert_attachment($attachment, $file, $job_details->ID); if (!is_wp_error($id)) { wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file)); } update_post_meta($job_details->ID, '_thumbnail_id', $id); } ### If paying with pack, update the customers pack totals if ($user_pack) { $inspack = ''; $user_pack->inc_job_count(); } elseif (!empty($posted['job_pack'])) { $inspack = $posted['job_pack']; } if ($posted['featureit'] == 'yes') { $insfeatured = 1; } else { $insfeatured = 0; } ### Create the order in the database so it can be confirmed by user/IPN before going live if ($cost > 0) { $jr_order = new jr_order(0, $user_ID, $cost, $job_details->ID, $inspack, $insfeatured); $jr_order->insert_order(); ### Redirect to paypal payment page (if paid listing) $name = urlencode(__('Relisting ', 'appthemes') . $posted['job_title'] . __(' w/ Job Pack ', 'appthemes') . $job_pack->pack_name); $link = $jr_order->generate_paypal_link($name); header('Location: ' . $link); exit; } else { ### Relisting was free wp_mail(get_option('admin_email'), __('Job Re-Listed ', 'appthemes') . '[' . get_bloginfo('name') . ']', __('A job has been re-listed called ', 'appthemes') . '"' . $posted['job_title'] . '" (' . __('ID', 'appthemes') . ': ' . $job_details->ID . ")\n\nEdit post link: " . admin_url("post.php?action=edit&post=" . $job_details->ID . "") . "\nView Post: " . get_permalink($job_details->ID)); ### Redirect to my jobs $args = array('message' => urlencode('Job relisted successfully')); redirect_myjobs($args); } } // endif errors } $form_results = array('errors' => $errors, 'posted' => $posted); return $form_results; }
<td><strong><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></strong></td> <td class="date"><strong><?php the_time(__('j M', 'appthemes')); ?> </strong> <span class="year"><?php the_time(__('Y', 'appthemes')); ?> </span></td> <td class="center"><?php $jr_order = new jr_order(); if ($jr_order->find_order_for_job($my_query->post->ID)) { if ($jr_order->status != 'completed') { echo __('Ended (order incomplete)', 'appthemes'); } else { echo __('Ended', 'appthemes'); } } else { echo __('Ended', 'appthemes'); } ?> </td> <td class="center"><?php echo $job_views; ?> </td>
/** * JobRoller Confirm Job Process * Once a job has been confirmed, this takes the posted data and adds it to WordPress. * * * @version 1.3 * @author AppThemes * @package JobRoller * @copyright 2010 all rights reserved * */ function jr_process_confirm_job_form() { global $user_ID, $post, $posted, $wpdb, $jr_log; $posted = json_decode(stripslashes($_POST['posted']), true); // Calc costs/get packs $cost = 0; $job_pack = ''; $user_pack = ''; $jobs_last = null; // Get Pack from previous step if (isset($posted['job_pack']) && !empty($posted['job_pack'])) { if (strstr($posted['job_pack'], 'user_')) { $user_pack_id = (int) str_replace('user_', '', $posted['job_pack']); $user_pack = new jr_user_pack($user_pack_id); if (!$user_pack->get_valid_pack()) { wp_die(__('Error: Invalid Pack.', 'appthemes')); } $jobs_last = $user_pack->job_duration; } else { $job_pack = new jr_pack($posted['job_pack']); $cost += $job_pack->pack_cost; $jobs_last = $job_pack->job_duration; } } else { // No Packs $listing_cost = get_option('jr_jobs_listing_cost'); $cost += $listing_cost; } // Caculate expirey date from today if (!isset($jobs_last)) { $jobs_last = get_option('jr_jobs_default_expires'); } // 30 day default $date = strtotime('+' . $jobs_last . ' day', current_time('timestamp')); // Get Featured from previous step if ($posted['featureit'] == 'yes') { $featured_cost = get_option('jr_cost_to_feature'); $cost += $featured_cost; } ### Validate required again - just in case $required = array('job_title' => __('Job title', 'appthemes'), 'job_term_type' => __('Job type', 'appthemes'), 'details' => __('Job description', 'appthemes')); foreach ($required as $field => $name) { if (empty($posted[$field])) { wp_die(__('Error: Unable to create entry.', 'appthemes')); } } ### Approval needed? $status = 'publish'; if ($cost > 0) { $status = 'pending'; } else { // Free listing if (get_option('jr_jobs_require_moderation') == 'yes') { $status = 'pending'; } } if ($user_pack) { $status = 'publish'; } ### Create Post $data = array('post_content' => $wpdb->escape($posted['details']), 'post_title' => $wpdb->escape(strip_tags($posted['job_title'])), 'post_status' => $status, 'post_author' => $user_ID, 'post_type' => 'job_listing'); jr_before_insert_job($data); // do_action hook $post_id = wp_insert_post($data); jr_after_insert_job($post_id); // do_action hook // Was the post created? if ($post_id == 0 || is_wp_error($post_id)) { wp_die(__('Error: Unable to create entry.', 'appthemes')); } ### Add meta data and category add_post_meta($post_id, '_Company', strip_tags($posted['your_name']), true); add_post_meta($post_id, '_CompanyURL', $posted['website'], true); add_post_meta($post_id, '_how_to_apply', $posted['apply'], true); add_post_meta($post_id, 'user_IP', jr_getIP(), true); add_post_meta($post_id, '_expires', $date); ### GEO if (!empty($posted['jr_address'])) { $latitude = jr_clean_coordinate($posted['jr_geo_latitude']); $longitude = jr_clean_coordinate($posted['jr_geo_longitude']); add_post_meta($post_id, '_jr_geo_latitude', $posted['jr_geo_latitude'], true); add_post_meta($post_id, '_jr_geo_longitude', $posted['jr_geo_longitude'], true); if ($latitude && $longitude) { // If we don't have address data, do a look-up if ($posted['jr_geo_short_address'] && $posted['jr_geo_country'] && $posted['jr_geo_short_address'] && $posted['jr_geo_short_address_country']) { add_post_meta($post_id, 'geo_address', $posted['jr_geo_short_address'], true); add_post_meta($post_id, 'geo_country', $posted['jr_geo_country'], true); add_post_meta($post_id, 'geo_short_address', $posted['jr_geo_short_address'], true); add_post_meta($post_id, 'geo_short_address_country', $posted['jr_geo_short_address_country'], true); } else { $address = jr_reverse_geocode($latitude, $longitude); add_post_meta($post_id, 'geo_address', $address['address'], true); add_post_meta($post_id, 'geo_country', $address['country'], true); add_post_meta($post_id, 'geo_short_address', $address['short_address'], true); add_post_meta($post_id, 'geo_short_address_country', $address['short_address_country'], true); } } } else { // They left the field blank so we assume the job is for 'anywhere' } ### Set terms $post_into_cats = array(); $post_into_types = array(); if ($posted['job_term_cat'] > 0) { $post_into_cats[] = get_term_by('id', $posted['job_term_cat'], 'job_cat')->slug; } if ($featured_cost && is_numeric($featured_cost) && $featured_cost > 0 && $posted['featureit'] == 'yes') { global $featured_job_cat_id; $featured_job_cat_name = get_term_by('id', $featured_job_cat_id, 'job_cat')->name; $post_into_cats[] = sanitize_title($featured_job_cat_name); } if (sizeof($post_into_cats) > 0) { wp_set_object_terms($post_id, $post_into_cats, 'job_cat'); } $post_into_types[] = get_term_by('slug', sanitize_title($posted['job_term_type']), 'job_type')->slug; if (sizeof($post_into_types) > 0) { wp_set_object_terms($post_id, $post_into_types, 'job_type'); } ### Salary $salary = array(); if ($posted['job_term_salary'] > 0) { $salary[] = get_term_by('id', $posted['job_term_salary'], 'job_salary')->slug; } if (sizeof($salary) > 0) { wp_set_object_terms($post_id, $salary, 'job_salary'); } ### Tags if ($posted['tags']) { $thetags = explode(',', $posted['tags']); $thetags = array_map('trim', $thetags); $thetags = array_map('strtolower', $thetags); if (sizeof($thetags) > 0) { wp_set_object_terms($post_id, $thetags, 'job_tag'); } } ## Load APIs and Link to company image include_once ABSPATH . 'wp-admin/includes/file.php'; include_once ABSPATH . 'wp-admin/includes/image.php'; include_once ABSPATH . 'wp-admin/includes/media.php'; $name_parts = pathinfo($posted['company-logo-name']); $name = trim(substr($name, 0, -(1 + strlen($name_parts['extension'])))); $url = $posted['company-logo']; $type = $posted['company-logo-type']; $file = $posted['company-logo-file']; $title = $posted['company-logo-name']; $content = ''; if ($file) { // use image exif/iptc data for title and caption defaults if possible if ($image_meta = @wp_read_image_metadata($file)) { if (trim($image_meta['title'])) { $title = $image_meta['title']; } if (trim($image_meta['caption'])) { $content = $image_meta['caption']; } } // Construct the attachment array $attachment = array_merge(array('post_mime_type' => $type, 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $title, 'post_content' => $content), array()); // Save the data $id = wp_insert_attachment($attachment, $file, $post_id); if (!is_wp_error($id)) { wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file)); } update_post_meta($post_id, '_thumbnail_id', $id); } ### If paying with user pack, update the customers pack totals if ($user_pack) { $inspack = ''; $user_pack->inc_job_count(); } elseif (!empty($posted['job_pack'])) { $inspack = $posted['job_pack']; } if ($posted['featureit'] == 'yes') { $insfeatured = 1; } ### Create the order in the database so it can be confirmed by user/IPN before going live if ($cost > 0) { $jr_order = new jr_order(0, $user_ID, $cost, $post_id, $inspack, $insfeatured); $jr_order->insert_order(); ### Redirect to paypal payment page (if paid listing) $name = urlencode(__('Job Listing ', 'appthemes') . $posted['job_title'] . __(' with Job Pack ', 'appthemes') . $job_pack->pack_name); $link = $jr_order->generate_paypal_link($name); $jr_log->write_log('Sending user (#' . $user_ID . ') to paypal after job submission (' . $posted['job_title'] . ' - order#' . $jr_order->id . ').'); header('Location: ' . $link); exit; } else { ### FREE LISTING / LISTING PAID WITH USER PACK (no additional cost) if (get_option('jr_jobs_require_moderation') == 'yes') { if (get_option('jr_new_ad_email') !== 'no') { jr_admin_new_job_pending($post_id); } jr_owner_new_job_pending($post_id); } elseif (get_option('jr_new_ad_email') !== 'no') { jr_admin_new_job($post_id); } redirect_myjobs(); } }
*/ /** * This script is the landing page after payment has been processed * by PayPal or other gateways. It is used to add order information to the orders table and approve the job. * * @package JobRoller * @author AppThemes * @version 1.2 * */ global $wpdb, $jr_log; $newjobid = ''; // get the order id and activate the job if (!empty($_POST['custom'])) { // jr_before_gateway_process($_POST['custom']); // do_action hook $jr_order = new jr_order($_POST['custom']); if ($jr_order->order_key == $_POST['item_number'] || $_POST['test_ipn'] == '1') { $newjobid = $jr_order->job_id; $jr_order->complete_order(__('Return URL', 'appthemes')); $jr_log->write_log('Publishing job submission (#' . $jr_order->job_id . ') via tpl-add-new-confirm.php'); $payment_data = array(); $payment_data['payment_date'] = date("Y-m-d H:i:s"); $payment_data['payer_first_name'] = stripslashes(trim($_POST['first_name'])); $payment_data['payer_last_name'] = stripslashes(trim($_POST['last_name'])); $payment_data['payer_email'] = stripslashes(trim($_POST['payer_email'])); $payment_data['payment_type'] = 'PayPal'; $payment_data['payer_address'] = stripslashes(trim($_POST['residence_country'])); $payment_data['transaction_id'] = stripslashes(trim($_POST['txn_id'])); $payment_data['approval_method'] = __('Return URL', 'appthemes'); $jr_order->add_payment($payment_data); // jr_after_gateway_process($newjobid); // do_action hook
function jr_orders() { global $wpdb; $message = ''; jr_tables_install(); if (isset($_GET['export'])) { ob_end_clean(); header("Content-type: text/plain"); header("Content-Disposition: attachment; filename=jobroller_export_" . date('Ymd') . ".csv"); $jr_orders = new jr_orders(); $csv = array(); $row = array("ID", "User", "Job", "Pack", "Featured", "Cost", "Order Date", "Payment Date", "Payer", "Payment type", "Txn ID", "Approval Method", "Order Status"); $csv[] = '"' . implode('","', $row) . '"'; $row = array(); if (sizeof($jr_orders->orders) > 0) { foreach ($jr_orders->orders as $order) { $user_info = get_userdata($order->user_id); $row[] = $order->id; $row[] = '#' . $user_info->ID . ' - ' . $user_info->first_name . ' ' . $user_info->last_name . ' (' . $user_info->user_email . ')'; if ($order->job_id > 0) { $job_post = get_post($order->job_id); $row[] = '#' . $order->job_id . ' - ' . $job_post->post_title; } else { $row[] = ''; } if ($order->pack_id > 0) { $row[] = $order->pack_id; } else { $row[] = ''; } if ($order->featured) { $row[] = __('Yes', 'appthemes'); } else { $row[] = __('No', 'appthemes'); } if ($order->cost) { $row[] = jr_get_currency($order->cost); } else { $row[] = __('Free', 'appthemes'); } $row[] = mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $order->order_date); if ($order->payment_date) { $row[] = mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $order->payment_date); } else { $row[] = ''; } if ($order->payer_first_name || $order->payer_last_name) { $row[] = trim($order->payer_first_name . ' ' . $order->payer_last_name) . ', ' . trim($order->payer_address); } else { $row[] = ''; } if ($order->payment_type) { $row[] = trim($order->payment_type); } else { $row[] = ''; } if ($order->transaction_id) { $row[] = trim($order->transaction_id); } else { $row[] = ''; } if ($order->approval_method) { $row[] = trim($order->approval_method); } else { $row[] = ''; } $row[] = $order->status; $row = array_map('trim', $row); $row = array_map('html_entity_decode', $row); $row = array_map('addslashes', $row); $csv[] = '"' . implode('","', $row) . '"'; $row = array(); } } echo implode("\n", $csv); exit; } if (isset($_GET['paid'])) { $paid_listing = (int) $_GET['paid']; if ($paid_listing > 0) { $order = new jr_order($paid_listing); $order->complete_order(__('Manual', 'appthemes')); $message = __('Order complete.', 'appthemes'); } } if (isset($_GET['cancel'])) { $cancelled_listing = (int) $_GET['cancel']; if ($cancelled_listing > 0) { $order = new jr_order($cancelled_listing); $order->cancel_order(); $message = __('Order cancelled.', 'appthemes'); } } ?> <div class="wrap jobroller"> <div class="icon32" id="icon-themes"><br/></div> <h2><?php _e('Orders', 'appthemes'); ?> <a href="admin.php?page=orders&export=true" class="button" title=""><?php _e('Export CSV', 'appthemes'); ?> </a></h2> <?php if (isset($_GET['message'])) { $message = stripslashes(urldecode($_GET['message'])); } if (isset($message) && !empty($message)) { echo '<p class="success">' . $message . '</p>'; } ?> <?php $jr_orders = new jr_orders(); if (isset($_GET['p'])) { $page = $_GET['p']; } else { $page = 1; } $dir = 'ASC'; $sort = 'ID'; $per_page = 20; $total_pages = 1; $show = 'pending_payment'; if (isset($_GET['show'])) { switch ($_GET['show']) { case "completed": $show = 'completed'; $total_pages = ceil($jr_orders->completed_count / 20); break; case "cancelled": $show = 'cancelled'; $total_pages = ceil($jr_orders->cancelled_count / 20); break; default: $total_pages = ceil($jr_orders->pending_count / 20); break; } } else { $_GET['show'] = ''; } if (isset($_GET['dir'])) { $posteddir = $_GET['dir']; } else { $posteddir = ''; } if (isset($_GET['sort'])) { $postedsort = $_GET['sort']; } else { $postedsort = ''; } $jr_orders->get_orders($show, $per_page * ($page - 1), $per_page, $postedsort, $posteddir); ?> <div class="tablenav"> <div class="tablenav-pages alignright"> <?php if ($total_pages > 1) { echo paginate_links(array('base' => 'admin.php?page=orders&show=' . $_GET['show'] . '%_%&sort=' . $postedsort . '&dir=' . $posteddir, 'format' => '&p=%#%', 'prev_text' => __('« Previous'), 'next_text' => __('Next »'), 'total' => $total_pages, 'current' => $page, 'end_size' => 1, 'mid_size' => 5)); } ?> </div> <ul class="subsubsub"> <li><a href="admin.php?page=orders" <?php if ($show == 'pending_payment') { echo 'class="current"'; } ?> ><?php _e('Pending', 'appthemes'); ?> <span class="count">(<?php echo $jr_orders->pending_count; ?> )</span></a> |</li> <li><a href="admin.php?page=orders&show=completed" <?php if ($show == 'completed') { echo 'class="current"'; } ?> ><?php _e('Completed', 'appthemes'); ?> <span class="count">(<?php echo $jr_orders->completed_count; ?> )</span></a> |</li> <li><a href="admin.php?page=orders&show=cancelled" <?php if ($show == 'cancelled') { echo 'class="current"'; } ?> ><?php _e('Cancelled', 'appthemes'); ?> <span class="count">(<?php echo $jr_orders->cancelled_count; ?> )</span></a></li> </ul> </div> <div class="clear"></div> <table class="widefat fixed"> <thead> <tr> <th scope="col" style="width:3em;"><a href="<?php echo jr_echo_ordering_link('id', 'DESC'); ?> "><?php _e('ID', 'appthemes'); ?> </a></th> <th scope="col"><a href="<?php echo jr_echo_ordering_link('user_id', 'ASC'); ?> "><?php _e('User', 'appthemes'); ?> </a></th> <th scope="col"><a href="<?php echo jr_echo_ordering_link('job_id', 'ASC'); ?> "><?php _e('Job', 'appthemes'); ?> </a></th> <th scope="col"><a href="<?php echo jr_echo_ordering_link('pack_id', 'ASC'); ?> "><?php _e('Pack', 'appthemes'); ?> </a></th> <th scope="col"><a href="<?php echo jr_echo_ordering_link('featured', 'DESC'); ?> "><?php _e('Featured', 'appthemes'); ?> </a></th> <th scope="col"><a href="<?php echo jr_echo_ordering_link('cost', 'DESC'); ?> "><?php _e('Total Cost', 'appthemes'); ?> </a></th> <th scope="col"><a href="<?php echo jr_echo_ordering_link('order_date', 'DESC'); ?> "><?php _e('Order Date', 'appthemes'); ?> </a></th> <?php if ($show !== 'pending_payment' && $show !== 'cancelled') { ?> <th scope="col"><a href="<?php echo jr_echo_ordering_link('payment_date', 'DESC'); ?> "><?php _e('Payment Date', 'appthemes'); ?> </a></th> <th scope="col"><?php _e('Payer', 'appthemes'); ?> </th> <th scope="col"><a href="<?php echo jr_echo_ordering_link('payment_type', 'ASC'); ?> "><?php _e('Payment type', 'appthemes'); ?> </a></th> <th scope="col"><a href="<?php echo jr_echo_ordering_link('transaction_id', 'ASC'); ?> "><?php _e('Txn ID', 'appthemes'); ?> </a></th> <th scope="col"><a href="<?php echo jr_echo_ordering_link('approval_method', 'ASC'); ?> "><?php _e('Approval Method', 'appthemes'); ?> </a></th> <?php } ?> <th scope="col"><?php _e('Actions', 'appthemes'); ?> </th> </tr> </thead> <?php if (sizeof($jr_orders->orders) > 0) { $rowclass = ''; ?> <tbody id="list"> <?php foreach ($jr_orders->orders as $order) { $rowclass = 'even' == $rowclass ? 'alt' : 'even'; if ($order->user_id) { $user_info = get_userdata($order->user_id); } ?> <tr class="<?php echo $rowclass; ?> "> <td><?php echo $order->id; ?> </td> <td><?php if ($user_info) { ?> #<?php echo $user_info->ID; ?> – <strong><?php echo $user_info->first_name; ?> <?php echo $user_info->last_name; ?> </strong><br/><a href="mailto:<?php echo $user_info->user_email; ?> "><?php echo $user_info->user_email; ?> </a><?php } ?> </td> <td> <?php if ($order->job_id > 0) { $job_post = get_post($order->job_id); if ($job_post) { echo '<a href="post.php?action=edit&post=' . $order->job_id . '">'; echo '#' . $order->job_id . ' – ' . $job_post->post_title; echo '</a>'; } else { echo '#' . $order->job_id; } } else { _e('N/A', 'appthemes'); } ?> </td> <td><?php if ($order->pack_id > 0) { echo $order->pack_id; } else { _e('N/A', 'appthemes'); } ?> </td> <td><?php if ($order->featured) { echo __('Yes', 'appthemes'); } else { echo __('No', 'appthemes'); } ?> </td> <td><?php if ($order->cost) { echo jr_get_currency($order->cost); } else { _e('Free', 'appthemes'); } ?> </td> <td><?php echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $order->order_date); ?> </td> <?php if ($show !== 'pending_payment' && $show !== 'cancelled') { ?> <td><?php if ($order->payment_date) { echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $order->payment_date); } else { echo __('N/A', 'appthemes'); } ?> </td> <td><?php if ($order->payer_first_name || $order->payer_last_name) { echo trim($order->payer_first_name . ' ' . $order->payer_last_name) . '<br/>' . trim($order->payer_address); } else { echo __('N/A', 'appthemes'); } ?> </td> <td><?php if ($order->payment_type) { echo trim($order->payment_type); } else { echo __('N/A', 'appthemes'); } ?> </td> <td><?php if ($order->transaction_id) { echo trim($order->transaction_id); } else { echo __('N/A', 'appthemes'); } ?> </td> <td><?php if ($order->approval_method) { echo trim($order->approval_method); } else { echo __('N/A', 'appthemes'); } ?> </td> <?php } ?> <td> <?php if ($order->status == 'pending_payment') { ?> <a href="admin.php?page=orders&paid=<?php echo $order->id; ?> " class="button button-primary">Mark as paid</a> <a href="admin.php?page=orders&cancel=<?php echo $order->id; ?> " class="button cancel">Cancel</a> <?php } else { ?> <?php _e('N/A', 'appthemes'); ?> <?php } ?> </td> </tr> <?php } ?> </tbody> <?php } else { ?> <tr><td colspan="<?php if ($show !== 'pending_payment' && $show !== 'cancelled') { ?> 15<?php } else { ?> 8<?php } ?> "><?php _e('No orders found.', 'appthemes'); ?> </td></tr> <?php } ?> </table> <br /> <script type="text/javascript"> /* <![CDATA[ */ jQuery('a.cancel').click(function(){ var answer = confirm ("<?php _e('Are you sure you want to cancel this order? The order will be cancelled and the Job Post will be deleted from the system.', 'appthemes'); ?> "); if (answer) return true; return false; }); /* ]]> */ </script> </div><!-- end wrap --> <?php }