Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
10 kB
7
Indexable
Never
<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if(wcs_user_has_subscription( '', '', 'any' )):

wc_print_notices();
$user_id = get_current_user_id();
	if ( empty( WC_AM_USER()->get_master_api_key( $user_id ) ) ) {
		WC_AM_USER()->set_registration_master_key_and_status( $user_id );
	}
	$master_api_key_status = WC_AM_USER()->has_api_access( $user_id );
	if ( $master_api_key_status ) {
		$resources = WC_AM_API_RESOURCE_DATA_STORE()->get_api_resources_for_user_id_sort_by_product_title( $user_id );
		if ( $resources ) {
			$master_api_key = WC_AM_USER()->get_master_api_key( $user_id );
			?>
            <table class="woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_api_manager my_account_orders">
                <thead>
                <tr>
                    <th class="master-api-key"><span class="nobr"><?php esc_html_e( 'Master API Key', 'woocommerce-api-manager' ); ?> <?php esc_html_e( ' - Can be used to activate any product.', 'woocommerce-api-manager' ); ?></span>
                    </th>
                </tr>
                </thead>
                <tbody>
                <tr class="order">
                    <td class="api-manager-master-api-key">
						<input readonly style="width:80%;border:1px solid #ddd;border-radius:4px;font-size:20px;padding:10px" value="<?php echo esc_attr( $master_api_key ); ?>" id="license-key">
						<button style="padding:10px 20px;border:none;color:#fff;background:#673ab6;border-radius:4px;" onclick="copyToClipboard()">کپی کردن</button>
						<script>
							function copyToClipboard() {
									var textBox = document.getElementById("license-key");
									textBox.select();
									document.execCommand("copy");
							}
						</script>
                    </td>
                </tr>
                </tbody>
            </table>
            <table class="woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_api_manager my_account_orders">
                <thead>
                <tr>
                    <th class="<?php echo esc_attr( 'api-manager-software-product' ); ?>"><span
                                class="nobr">عنوان محصول</span></th>
																<th><span
						                                class="nobr">وب‌سایت‌های فعال</span></th>
                </tr>
                </thead>
                <tbody>

				<?php

				foreach ( $resources as $resource ) {
					WC_AM_API_ACTIVATION_DATA_STORE()->delete_excess_api_key_activations_by_activation_id( $resource->activation_ids, $resource->activations_purchased_total );
					$product_object          = WC_AM_PRODUCT_DATA_STORE()->get_product_object( $resource->product_id );
					$parent_product_id       = $resource->parent_id;
					$is_api                  = WC_AM_PRODUCT_DATA_STORE()->is_api_product( $parent_product_id );
					$order_id                = $resource->order_id;
					$order_completed_status  = WC_AM_ORDER_DATA_STORE()->has_status_completed( $order_id );
					$order_processing_status = WC_AM_ORDER_DATA_STORE()->has_status_processing( $order_id );
					if ( $is_api && ( $order_completed_status || ( WCAM()->get_grant_access_after_payment() && $order_processing_status ) ) ) {
						$product_title = $resource->product_title;
						$product_id    = $resource->product_id;
						$order         = WC_AM_ORDER_DATA_STORE()->get_order_object( $order_id );
						if ( WCAM()->get_wc_subs_exist() ) {
							$is_wc_sub = WC_AM_SUBSCRIPTION()->is_wc_subscription( $product_id );
						} else {
							$is_wc_sub = false;
						}
							$product_ids[]     = $product_id;
							$total_product_ids = array_count_values( $product_ids );

						/**
						 * Calculate activations per Product ID # for Master API Key.
						 */
						$master_api_key_resources    = WC_AM_API_RESOURCE_DATA_STORE()->get_active_api_resources( $master_api_key, $product_id );
						$total_activations_purchased = WC_AM_API_RESOURCE_DATA_STORE()->get_total_activations_purchased( $master_api_key_resources );
						$total_activations           = WC_AM_API_RESOURCE_DATA_STORE()->get_total_activations( $master_api_key_resources );
						$product_order_api_key       = WC_AM_API_RESOURCE_DATA_STORE()->get_api_resource_product_order_api_key( $order_id, $product_id );
						if ( is_object( $order ) ) {
							/**
							 * WC Subscriptions Only API Keys
							 * Only display active subscriptions
							 */
							if ( WCAM()->get_wc_subs_exist() ) {
								if ( $is_wc_sub ) {
									$sub_id        = $resource->sub_id;
									$sub_order_key = $resource->sub_order_key;
									?>
                                    <tr class="order">
                                        <td class="api-manager-product">
                                          <?php echo esc_attr( $product_title ) ?>
                                        </td>
																				<td class="api-manager-activations">
												<?php
													echo esc_attr_e( $resource->activations_total ) . esc_html_e( ' out of ', 'woocommerce-api-manager' ) . esc_attr( $resource->activations_purchased_total );
												?>
																				</td>
                                    </tr>
									<?php
								}
							}
							/**
							 * Non WC Subscriptions API Keys
							 */
							if ( ! $is_wc_sub ) {
								?>
                                <tr class="order">
                                    <td class="api-manager-product">
                                        <a href="<?php echo esc_url( $order->get_view_order_url() ); ?>"><?php echo esc_attr( $product_title ) ?></a>
                                    </td>
                                        <td class="api-manager-license-key">
											<?php echo esc_attr( $product_order_api_key ); ?>
                                        </td>
                                    <td class="api-manager-expire">
										<?php
										if ( WC_AM_API_RESOURCE_DATA_STORE()->is_access_expired( $resource->access_expires ) ) {
											$expires = esc_html__( 'Expired', 'woocommerce-api-manager' );
										} else {
											$expires = $resource->access_expires == 0 ? esc_html__( 'never', 'woocommerce-api-manager' ) : esc_attr( WC_AM_FORMAT()->get_human_time_diff( $resource->access_expires ) );
										}
										esc_html_e( $expires );
										?>
                                    </td>
                                    <td class="api-manager-activations">
										<?php
											echo esc_attr_e( $resource->activations_total ) . esc_html_e( ' out of ', 'woocommerce-api-manager' ) . esc_attr( $resource->activations_purchased_total );
										?>
                                    </td>
                                </tr>
								<?php
							} // end if user subscription is active, or if non subscription API Key has API access
						}
						$activation_data = WC_AM_API_ACTIVATION_DATA_STORE()->get_total_activations_resources_for_api_key_by_product_id( $master_api_key, $product_id );
						if ( ! empty( $activation_data ) ) {
							foreach ( $activation_data as $key => $activation_info ) {
								if ( $activation_info->api_resource_id == $resource->api_resource_id ) {
									?>
                    <tr class="api-manager-domains">
											<td colspan="1">سایت فعال شده</td>
                    	<td colspan="1">
											<?php
											echo '<a href="' . esc_url( WC_AM_URL()->nonce_url( array(
												                                                    'delete_activation' => '1',
												                                                    'instance'          => $activation_info->instance,
												                                                    'order_id'          => $activation_info->order_id,
												                                                    'sub_parent_id'     => $activation_info->sub_parent_id,
												                                                    'api_key'           => $activation_info->api_key,
												                                                    'product_id'        => $activation_info->product_id,
												                                                    'user_id'           => $user_id
											                                                    ) ) ) . '" style="float: left;" class="button ' . sanitize_html_class( 'delete' ) . '">' . apply_filters( 'wc_api_manager_my_account_delete', '×' ) . '</a>';
											if ( filter_var( $activation_info->object, FILTER_VALIDATE_URL ) ) {
												// If $object is a URL, then remove the trailing slash.
												$obj_length = strlen( $activation_info->object );
												$object     = ! empty( $activation_info->object ) && substr( $activation_info->object, $obj_length - 1, $obj_length ) == '/' ? substr( $activation_info->object, 0, $obj_length - 1 ) : $activation_info->object;
												?>
                                                <a style="text-align:left; vertical-align: middle; border-left: 0; padding-left: 1.5em;"
                                                   href="<?php echo esc_url( $activation_info->object ); ?>"
                                                   target="_blank"><?php echo WC_AM_URL()->remove_url_prefix( $object ); ?></a>
											<?php } else { ?>
                                                <span style="vertical-align: middle;"><?php echo $activation_info->object;?></span>
											<?php } ?>
								<?php } ?>
							<?php } ?>
						<?php } // end $order_data
					} // end if $api
				} // end foreach
				?>
                </tbody>
            </table>
			<?php
		} else { ?>

			<?php
		} // end if $orders
	}
?>




<?php

$subscriptions  = wcs_get_users_subscriptions();
?>
<h4 style="margin-top:50px;width:100%;clear:both;display:block">لایسنس‌ها</h4>
<?php
	foreach ( $subscriptions as $subscription_id => $subscription ) :
		if($subscription->get_status() == 'on-hold' AND strtotime($subscription->get_date( 'end' )) > time()){
			$subscription->update_status('active');
		}
		if($subscription->get_status() != 'pending' AND $subscription->get_status() != 'cancelled'):
?>
<?php include('subscription.php');?>
<?php endif; ?>
<?php endforeach; ?>
<div class="clearfix"></div>
<a class="archive" href="?tab=5">دانلود آپدیت محصولات</a>
<?php else:?>
  <p class="alert alert-warning">شما محصولی خریداری نکرده‌اید. اگر اشتباهی پیش آمده، با بخش فروش در ارتباط باشید.</p>
<?php endif; ?>