/** * Register Ad Management Panel menu */ public function menu() { /* Profile Menu */ // We are using read as an alias for edit_classifieds_listings. If a user can `read`, // he or she can `edit_classifieds_listings`. $capability = 'read'; // Account Balance if (awpcp_payments_api()->credit_system_enabled() && !awpcp_current_user_is_admin()) { $parts = array($this->account->title, $this->account->menu, $this->account->page); $hook = add_users_page($parts[0], $parts[1], $capability, $parts[2], array($this->account, 'dispatch')); add_action("admin_print_styles-{$hook}", array($this->account, 'scripts')); } $current_user_is_non_admin_moderator = awpcp_current_user_is_moderator() && !awpcp_current_user_is_admin(); if (get_awpcp_option('enable-user-panel') != 1 || $current_user_is_non_admin_moderator) { return; } /* Ad Management Menu */ $slug = 'awpcp-panel'; $title = sprintf(__('%s Ad Management Panel', 'AWPCP'), get_bloginfo()); $menu = __('Ad Management', 'AWPCP'); $hook = add_menu_page($title, $menu, $capability, $slug, array($this->listings, 'dispatch'), MENUICO); // Listings $title = __('Manage Ad Listings', 'AWPCP'); $menu = __('Listings', 'AWPCP'); $hook = add_submenu_page($slug, $title, $menu, $capability, $slug, array($this->listings, 'dispatch')); add_action("admin_print_styles-{$hook}", array($this->listings, 'scripts')); do_action('awpcp_panel_add_submenu_page', $slug, $capability); }
public function notices() { if (!awpcp_current_user_is_admin()) { return; } if (awpcp_request_param('page', false) == 'awpcp-admin-upgrade') { return; } if (get_option('awpcp-pending-manual-upgrade')) { ob_start(); include AWPCP_DIR . '/admin/templates/admin-pending-manual-upgrade-notice.tpl.php'; $html = ob_get_contents(); ob_end_clean(); echo $html; return; } $show_quick_start_quide_notice = get_awpcp_option('show-quick-start-guide-notice'); $show_drip_autoresponder = get_awpcp_option('show-drip-autoresponder'); if ($show_quick_start_quide_notice && is_awpcp_admin_page() && !$show_drip_autoresponder) { ob_start(); include AWPCP_DIR . '/admin/templates/admin-quick-start-guide-notice.tpl.php'; $html = ob_get_contents(); ob_end_clean(); echo $html; } if (get_awpcp_option('show-widget-modification-notice')) { ob_start(); include AWPCP_DIR . '/admin/templates/admin-widget-modification-notice.tpl.php'; $html = ob_get_contents(); ob_end_clean(); echo $html; } do_action('awpcp-admin-notices'); }
public function get_payment_terms() { global $wpdb; if (!awpcp_payments_api()->payments_enabled()) { return array($this->get_free_payment_term()); } $order = get_awpcp_option('fee-order'); $direction = get_awpcp_option('fee-order-direction'); switch ($order) { case 1: $orderby = array('adterm_name', $direction); break; case 2: $orderby = array("amount {$direction}, adterm_name", $direction); break; case 3: $orderby = array("imagesallowed {$direction}, adterm_name", $direction); break; case 5: $orderby = array("_duration_interval {$direction}, rec_period {$direction}, adterm_name", $direction); break; } if (awpcp_current_user_is_admin()) { $args = array('orderby' => $orderby[0], 'order' => $orderby[1]); } else { $args = array('where' => 'private = 0', 'orderby' => $orderby[0], 'order' => $orderby[1]); } return AWPCP_Fee::query($args); }
/** * Allow users to download Debug Info as an HTML file. * * @since 2.0.7 */ public function download() { global $pagenow; if (!awpcp_current_user_is_admin()) { return; } if ($pagenow == 'admin.php' && awpcp_request_param('page') === 'awpcp-debug' && awpcp_request_param('download') === 'debug-info') { $filename = sprintf('awpcp-debug-info-%s.html', date('Y-m-d-Hi', current_time('timestamp'))); header('Content-Description: File Transfer'); header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); header('Content-Disposition: attachment; filename=' . $filename); header("Pragma: no-cache"); die($this->render(true)); } }
public function ajax() { if (!awpcp_current_user_is_admin()) { return false; } $user_id = awpcp_post_param('user', 0); $action = str_replace('awpcp-users-', '', awpcp_post_param('action')); switch ($action) { case 'debit': case 'credit': $response = $this->ajax_edit_balance($user_id, $action); break; default: $response = array(); break; } header('Content-Type: application/json'); echo json_encode($response); exit; }
public function ajax() { if (!awpcp_current_user_is_admin()) { return false; } $id = awpcp_post_param('id', 0); $action = str_replace('awpcp-fees-', '', awpcp_post_param('action')); $response = array(); switch ($action) { case 'add': $response = $this->ajax_add(); break; case 'edit': $response = $this->ajax_edit($id); break; case 'delete': $response = $this->ajax_delete($id); break; } header('Content-Type: application/json'); echo json_encode($response); exit; }
function awpcp_get_menu_items() { $items = array(); $user_is_allowed_to_place_ads = !get_awpcp_option('onlyadmincanplaceads') || awpcp_current_user_is_admin(); $show_place_ad_item = $user_is_allowed_to_place_ads && get_awpcp_option('show-menu-item-place-ad'); $show_edit_ad_item = $user_is_allowed_to_place_ads && get_awpcp_option('show-menu-item-edit-ad'); $show_browse_ads_item = get_awpcp_option('show-menu-item-browse-ads'); $show_search_ads_item = get_awpcp_option('show-menu-item-search-ads'); if ($show_place_ad_item) { $place_ad_url = awpcp_get_page_url('place-ad-page-name'); $place_ad_page_name = get_awpcp_option('place-ad-page-name'); $items['post-listing'] = array('url' => $place_ad_url, 'title' => esc_html($place_ad_page_name)); } if ($show_edit_ad_item) { $items['edit-listing'] = awpcp_get_edit_listing_menu_item(); } if ($show_browse_ads_item) { if (is_awpcp_browse_listings_page() || is_awpcp_browse_categories_page()) { if (get_awpcp_option('main_page_display')) { $browse_cats_url = awpcp_get_view_categories_url(); } else { $browse_cats_url = awpcp_get_main_page_url(); } $view_categories_page_name = get_awpcp_option('view-categories-page-name'); $items['browse-listings'] = array('url' => $browse_cats_url, 'title' => esc_html($view_categories_page_name)); } else { $browse_ads_page_name = get_awpcp_option('browse-ads-page-name'); $browse_ads_url = awpcp_get_page_url('browse-ads-page-name'); $items['browse-listings'] = array('url' => $browse_ads_url, 'title' => esc_html($browse_ads_page_name)); } } if ($show_search_ads_item) { $search_ads_page_name = get_awpcp_option('search-ads-page-name'); $search_ads_url = awpcp_get_page_url('search-ads-page-name'); $items['search-listings'] = array('url' => $search_ads_url, 'title' => esc_html($search_ads_page_name)); } $items = apply_filters('awpcp_menu_items', $items); return $items; }
public function get_search_by_box() { if (empty($_REQUEST['s']) && !$this->has_items()) { return; } $id = 'search-by'; $label = __('Search by', 'AWPCP'); $options['id'] = __('Ad ID', 'AWPCP'); $options['title'] = __('Ad Title', 'AWPCP'); $options['keyword'] = __('Keyword', 'AWPCP'); $options['location'] = __('Location', 'AWPCP'); if (awpcp_current_user_is_admin()) { $options['payer-email'] = __('Payer Email', 'AWPCP'); } $options['user'] = __('User', 'AWPCP'); $search_by = awpcp_request_param('search-by', 'title'); $html = '<p class="search-by-box">'; $html .= '<label>' . $label . ':</label> '; foreach ($options as $value => $text) { $id = 'search-by-' . $value; $selected = $search_by == $value ? 'checked="checked"' : ''; $html .= '<input type="radio" id="' . $id . '" name="search-by" ' . $selected . ' value="' . $value . '" /> '; $html .= '<label for="' . $id . '">' . $text . '</label> '; } $html .= '</p>'; echo $html; }
public function user_has_enough_credit(&$balance = null) { if (awpcp_current_user_is_admin()) { return true; } if (awpcp_user_is_admin($this->user_id)) { return true; } $totals = $this->get_totals(); $credits = $totals['credits']; // no need for credits if ($credits === 0) { return true; } $payments = awpcp_payments_api(); if (!$payments->is_credit_accepted()) { return false; } $balance = $payments->get_account_balance($this->user_id); $plan = $payments->get_credit_plan($this->get('credit-plan')); $balance = $balance - $credits; if ($balance < 0) { if (is_null($plan)) { return false; } $balance = $balance + $plan->credits; if ($balance < 0) { return false; } } return true; }
function checkifisadmin() { return awpcp_current_user_is_admin() ? 1 : 0; }
?> <?php echo awpcp_print_message($message); } ?> <?php foreach ($transaction_errors as $error) { ?> <?php echo awpcp_print_message($error, array('error')); } ?> <?php if (!awpcp_current_user_is_admin()) { echo $payments->render_account_balance(); } ?> <form class="awpcp-order-form" method="post"> <?php echo $payments->render_payment_terms_form_field($transaction, $table, $form_errors); ?> <p class="form-submit"> <input class="button" type="submit" value="<?php echo esc_attr(__('Continue', 'AWPCP')); ?> " id="submit" name="submit"> <?php
/** * Set payment status to Not Required in requiredtransactions made by * admin users. * * TODO: move this into one of the steps decorator, when steps decorators become widely used. * * @since 2.2.2 */ public function process_transaction_update_payment_status($transaction) { switch ($transaction->get_status()) { case AWPCP_Payment_Transaction::STATUS_OPEN: if (awpcp_current_user_is_admin()) { $transaction->payment_status = AWPCP_Payment_Transaction::PAYMENT_STATUS_NOT_REQUIRED; } break; } }
public function show_sidebar() { return awpcp_current_user_is_admin(); }
public function show_admin_notices() { if (!awpcp_current_user_is_admin()) { return; } foreach ($this->modules as $module) { $this->show_module_notices($module); } }
public function order_step() { $ad = $this->page->get_ad(); $transaction = $this->page->get_transaction(true); $payments = awpcp_payments_api(); $fee = $payments->get_ad_payment_term($ad); $form_errors = array(); $transaction_errors = array(); // verify pre-conditions if ($transaction->is_new()) { $payments->set_transaction_status_to_open($transaction, $transaction_errors); } // validate submitted data and prepare transaction $payment_terms = new AWPCP_PaymentTermsTable(array($fee->type => array($fee)), $transaction->get('payment-term')); if (awpcp_current_user_is_admin() || !$payments->payment_term_requires_payment($fee)) { $term = $fee; $transaction->set('payment-term-type', $term->type); $transaction->set('payment-term-id', $term->id); $transaction->set('ad-id', $ad->ad_id); $transaction->remove_all_items(); $payment_terms->set_transaction_item($transaction, $term); } else { $term = $payments->get_transaction_payment_term($transaction); if (!empty($_POST)) { $term = $payment_terms->get_payment_term($payment_type, $selected); $this->validate_order(compact('term', 'fee'), $form_errors); if (empty($form_errors)) { $transaction->set('payment-term', $selected); $transaction->set('payment-term-type', $term->type); $transaction->set('payment-term-id', $term->id); $transaction->set('ad-id', $ad->ad_id); $transaction->remove_all_items(); $payment_terms->set_transaction_item($transaction); // process transaction to grab Credit Plan information $payments->set_transaction_credit_plan($transaction); } } } // let other parts of the plugin know a transaction is being processed $payments->process_transaction($transaction); // if everything is fine move onto the next step if (!is_null($term)) { $payments->set_transaction_status_to_ready_to_checkout($transaction, $transaction_errors); if (empty($transaction_errors)) { return $this->checkout_step(); } } // otherwise display the order form to grab information and show any errors $messages = $this->messages; if (awpcp_current_user_is_admin()) { $messages[] = __("You are logged in as an administrator. Any payment steps will be skipped.", "AWPCP"); } $params = array('payments' => $payments, 'transaction' => $transaction, 'table' => $payment_terms, 'messages' => $messages, 'form_errors' => $form_errors, 'transaction_errors' => $transaction_errors); $template = AWPCP_DIR . '/frontend/templates/page-renew-ad-order-step.tpl.php'; return $this->page->render($template, $params); }
public function details_form($form = array(), $edit = false, $hidden = array(), $required = array(), $errors = array()) { global $hasregionsmodule, $hasextrafieldsmodule; $is_admin_user = awpcp_current_user_is_admin(); $is_moderator = awpcp_current_user_is_moderator(); $payments_enabled = get_awpcp_option('freepay') == 1; $pay_first = get_awpcp_option('pay-before-place-ad'); $messages = $this->messages; if ($edit) { $messages[] = __("Your Ad details have been filled out in the form below. Make any changes needed and then resubmit the Ad to update it.", "AWPCP"); } else { if ($is_admin_user) { $messages[] = __("You are logged in as an administrator. Any payment steps will be skipped.", "AWPCP"); } else { if (empty($errors)) { $messages[] = __("Fill out the form below to post your classified Ad.", "AWPCP"); } } } if (!empty($errors)) { $message = __("We found errors in the details you submitted. A detailed error message is shown in front or below each invalid field. Please fix the errors and submit the form again.", 'AWPCP'); $errors = array_merge(array($message), $errors); } $ui = array(); // TODO: add form validation // TODO: strip slashes from title, details $ui['listing-actions'] = !is_admin() && $edit; // show categories dropdown if $category is not set $ui['category-field'] = ($edit || empty($form['ad_category'])) && $is_moderator; $ui['user-dropdown'] = $edit && $is_admin_user; $ui['start-end-date'] = $edit && $is_moderator; // $ui['payment-term-dropdown'] = !$pay_first || ($is_admin_user && !$edit && $payments_enabled); $ui['website-field'] = get_awpcp_option('displaywebsitefield') == 1; $ui['website-field-required'] = get_awpcp_option('displaywebsitefieldreqop') == 1; $ui['contact-name-field-readonly'] = !empty($form['ad_contact_name']) && !$is_moderator; $ui['contact-email-field-readonly'] = !empty($form['ad_contact_email']) && !$is_moderator; $ui['contact-phone-field'] = get_awpcp_option('displayphonefield') == 1; $ui['contact-phone-field-required'] = get_awpcp_option('displayphonefieldreqop') == 1; $ui['price-field'] = get_awpcp_option('displaypricefield') == 1; $ui['price-field-required'] = get_awpcp_option('displaypricefieldreqop') == 1; $ui['allow-regions-modification'] = $is_moderator || !$edit || get_awpcp_option('allow-regions-modification'); $ui['price-field'] = get_awpcp_option('displaypricefield') == 1; $ui['extra-fields'] = $hasextrafieldsmodule && function_exists('awpcp_extra_fields_render_form'); $ui['terms-of-service'] = !$edit && !$is_moderator && get_awpcp_option('requiredtos'); $ui['captcha'] = !$edit && !is_admin() && get_awpcp_option('captcha-enabled') == 1; $hidden['step'] = 'save-details'; $hidden['ad_id'] = $form['ad_id']; $hidden['ad_category'] = $form['ad_category']; $hidden['adterm_id'] = $form['adterm_id']; // propagate preview parameter sent when this step is accesed from the // Preview Ad screen $hidden['preview-hash'] = awpcp_post_param('preview-hash', false); $preview = strlen($hidden['preview-hash']) > 0; if (isset($form['transaction_id'])) { $hidden['transaction_id'] = $form['transaction_id']; } $page = $this; $url = $this->url(); $transaction = $this->get_transaction(); $template = AWPCP_DIR . '/frontend/templates/page-place-ad-details-step.tpl.php'; $params = compact('transaction', 'page', 'ui', 'messages', 'form', 'hidden', 'required', 'url', 'edit', 'preview', 'errors'); if (isset($this->ad) && is_object($this->ad)) { $params['listing'] = $this->ad; } return $this->render($template, $params); }
private function is_user_allowed_to_buy_credits() { return awpcp_current_user_is_admin() ? false : true; }
public function show_images($ad) { $title = awpcp_admin_page_title(__('Manage Images', 'AWPCP')); $this->page->title = apply_filters('awpcp-media-manager-page-title', $title); $this->page->page = 'awpcp-admin-images'; $urls = array('endpoint' => $this->page->url(array('action' => 'manage-images')), 'view-listing' => $this->page->url(array('action' => 'view', 'id' => $ad->ad_id)), 'listings' => $this->page->url(array('id' => null))); $hidden = array('adid' => $ad->ad_id); $groups = $this->get_files($ad); $actions = array('approvepic' => _x('Enable', 'media manager', 'AWPCP'), 'rejectpic' => _x('Disable', 'media manager', 'AWPCP'), 'deletepic' => _x('Delete', 'media manager', 'AWPCP'), 'approve-file' => _x('Approve', 'media manager', 'AWPCP'), 'reject-file' => _x('Reject', 'media manager', 'AWPCP'), 'set-primary-image' => _x('Set as primary', 'media manager', 'AWPCP')); if (!awpcp_current_user_is_admin() && get_awpcp_option('imagesapprove')) { unset($actions['approve-file']); unset($actions['reject-file']); } ob_start(); include AWPCP_DIR . '/admin/templates/admin-panel-media-manager.tpl.php'; $content = ob_get_contents(); ob_end_clean(); return $this->page->render('content', $content); }
public function column_title($item) { $title = $item->get_title(); $url = $this->page->url(array('action' => 'view', 'id' => $item->ad_id)); if (awpcp_current_user_is_admin()) { // TODO: build URL to view Ad inside admin $template = '<strong><a title="%3$s" href="%2$s">%1$s</a></strong><br/><strong>%4$s</strong>: %5$s'; $content = sprintf($template, $title, $url, __('View Ad.', 'AWPCP'), __('Access Key', 'AWPCP'), $item->get_access_key()); } else { $template = '<strong><a title="%3$s" href="%2$s">%1$s</a></strong>'; $content = sprintf($template, $title, $url, __('View Ad.', 'AWPCP')); } return $content; }
?> <?php foreach ($transaction_errors as $error) { ?> <?php echo awpcp_print_message($error, array('error')); } ?> <?php awpcp_print_form_errors($form_errors); ?> <?php if (!$skip_payment_term_selection && !awpcp_current_user_is_admin()) { echo $payments->render_account_balance(); } ?> <form class="awpcp-order-form" method="post"> <h3><?php echo esc_html(_x('Please select a Category for your Ad', 'place ad order step', 'AWPCP')); ?> </h3> <p class="awpcp-form-spacer"> <?php $dropdown = new AWPCP_CategoriesDropdown(); ?> <?php