hesabixWCPlugin/admin/partials/hesabix-admin-display.php
2025-08-05 17:24:52 +03:30

298 lines
13 KiB
PHP

<?php
/**
* Hesabix Admin Display
*
* @package Hesabix
* @author Mohammad Rezai
* @author URI https://pirouz.xyz
* @since 1.0.0
*/
class Hesabix_Admin_Display
{
public function __construct()
{
add_action('admin_menu', array(__CLASS__, 'hesabix_add_menu'));
}
static function hesabix_add_menu()
{
$iconUrl = HESABIX_PLUGIN_URL . 'assets/img/menu-icon.png';
add_menu_page(__("Hesabix", 'hesabix'), __("Hesabix", 'hesabix'), "manage_options", "hesabix-option", array(__CLASS__, 'hesabix_plugin_page'), $iconUrl, null);
add_submenu_page("hesabix-option", __("Hesabix Settings", 'hesabix'), __("Hesabix Settings", 'hesabix'), "manage_options", 'hesabix-option', array(__CLASS__, 'hesabix_plugin_page'));
}
function hesabix_plugin_repeated_products()
{
global $wpdb;
$rows = $wpdb->get_results(
"SELECT id_hesabix
FROM {$wpdb->prefix}hesabix
WHERE obj_type = 'product'
GROUP BY id_hesabix
HAVING COUNT(id_hesabix) > 1"
);
$ids = array();
foreach ($rows as $row)
$ids[] = $row->id_hesabix;
$idsStr = implode(',', $ids);
$rows = $wpdb->get_results(
$wpdb->prepare(
"SELECT *
FROM {$wpdb->prefix}hesabix
WHERE obj_type = 'product'
AND id_hesabix IN ($idsStr)
ORDER BY id_hesabix"
)
);
$i = 0;
self::hesabix_plugin_header();
?>
<div class="hesabix-f mt-4">
<h5 class="h5 hesabix-tab-page-title">
<?php echo __('Duplicate Product Codes', 'hesabix'); ?>
</h5>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col"><?php echo __('Hesabix Code', 'hesabix'); ?></th>
<th scope="col"><?php echo __('Product ID', 'hesabix'); ?></th>
<th scope="col"><?php echo __('Attribute ID', 'hesabix'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $p):
$i++; ?>
<tr>
<th scope="row"><?= $i; ?></th>
<td><?= $p->id_hesabix; ?></td>
<td><?= $p->id_ps; ?></td>
<td><?= $p->id_ps_attribute; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php
}
function hesabix_plugin_tools()
{
self::hesabix_plugin_header();
?>
<div class="hesabix-f mt-4">
<h5 class="h5 hesabix-tab-page-title">
<?php echo __('Hesabix Plugin Tools', 'hesabix'); ?>
</h5>
<a href="javascript:void(0);" class="btn btn-danger mt-2"
id="hesabix-clear-plugin-data"><?php echo __('Delete Plugin Data', 'hesabix'); ?></a>
<br>
<a href="javascript:void(0);" class="btn btn-success mt-2"
id="hesabix-install-plugin-data"><?php echo __('Install Plugin Data', 'hesabix'); ?></a>
</div>
<?php
}
public static function getProductsAndRelations($page, $rpp)
{
$offset = ($page - 1) * $rpp;
global $wpdb;
$rows = $wpdb->get_results(
$wpdb->prepare(
"SELECT post.ID, post.post_title, post.post_parent, post.post_excerpt, wc.sku
FROM {$wpdb->posts} AS post
LEFT OUTER JOIN {$wpdb->prefix}wc_product_meta_lookup AS wc
ON post.ID = wc.product_id
WHERE post.post_type IN ('product', 'product_variation')
AND post.post_status IN ('publish', 'private')
ORDER BY post.post_title ASC
LIMIT %d, %d",
$offset,
$rpp
)
);
$totalCount = $wpdb->get_var(
"SELECT COUNT(*)
FROM {$wpdb->posts} AS post
LEFT OUTER JOIN {$wpdb->prefix}wc_product_meta_lookup AS wc
ON post.ID = wc.product_id
WHERE post.post_type IN ('product', 'product_variation')
AND post.post_status IN ('publish', 'private')"
);
$links = $wpdb->get_results(
"SELECT *
FROM {$wpdb->prefix}hesabix
WHERE obj_type = 'product'"
);
foreach ($rows as $r) {
if ($r->post_excerpt)
$r->post_title = $r->post_title . ' [' . $r->post_excerpt . ']';
}
foreach ($links as $link) {
foreach ($rows as $r) {
if ($r->ID == $link->id_ps && $link->id_ps_attribute == 0) {
$r->id_hesabix = $link->id_hesabix;
} else if ($r->ID == $link->id_ps_attribute) {
$r->id_hesabix = $link->id_hesabix;
}
}
}
return array("data" => $rows, "totalCount" => $totalCount);
}
public static function hesabix_plugin_page()
{
$iconsArray = [
'home',
'cog',
'box-open',
'users',
'file-invoice-dollar',
'sync-alt',
'file-alt',
'cog'
];
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
$setting_tabs = apply_filters('hesabix_setting_tab', array(
'home' => __('Home', 'hesabix'),
'api' => __('API', 'hesabix'),
'catalog' => __('Catalog', 'hesabix'),
'customers' => __('Customers', 'hesabix'),
'invoice' => __('Invoice', 'hesabix'),
'sync' => __('Sync', 'hesabix'),
'log' => __('Log', 'hesabix'),
'extra' => __('Extra Settings', 'hesabix')
));
$current_tab = (isset($_GET['tab'])) ? wc_clean($_GET['tab']) : 'home';
?>
<div class="hesabix-admin">
<div class="hesabix-container">
<?php self::hesabix_plugin_header(); ?>
<div class="hesabix-tabs">
<?php
$i = 0;
foreach ($setting_tabs as $name => $label) {
$iconUrl = HESABIX_PLUGIN_URL . "assets/img/icons/$iconsArray[$i].svg";
$i++;
$active_class = ($current_tab == $name) ? 'active' : '';
echo '<button class="hesabix-tab ' . $active_class . '" data-tab="' . esc_attr($name) . '">';
echo "<svg width='16' height='16' class='hesabix-tab-icon'><image href='$iconUrl' width='16' height='16' /></svg>";
echo $label;
echo '</button>';
}
?>
</div>
<div class="hesabix-tab-content active">
<?php
foreach ($setting_tabs as $setting_tabkey => $setting_tabvalue) {
switch ($setting_tabkey) {
case $current_tab:
do_action('hesabix_' . $setting_tabkey . '_setting_save_field');
do_action('hesabix_' . $setting_tabkey . '_setting');
break;
}
}
?>
</div>
</div>
</div>
<?php
} else {
?>
<div class="hesabix-admin">
<div class="hesabix-container">
<div class="hesabix-alert hesabix-alert-danger">
<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" />
</svg>
<div>
<strong><?php echo __('Hesabix Plugin requires the WooCommerce to work!', 'hesabix') ?></strong>
<div><?php echo __('Please install/activate woocommerce and try again', 'hesabix') ?></div>
</div>
</div>
</div>
</div>
<?php
}
}
public static function hesabix_plugin_header()
{
$logoUrl = HESABIX_PLUGIN_URL . '/assets/img/hesabix-logo.png';
$plugin_version = HESABIX_VERSION;
$is_connected = get_option('hesabix_account_api') ? true : false;
?>
<div class="hesabix-header">
<div class="hesabix-logo">
<img src="<?php echo $logoUrl ?>" alt="<?php echo __('Hesabix', 'hesabix'); ?>">
</div>
<div class="hesabix-info">
<h1 class="hesabix-title text-white mb-4"><?php echo __('Hesabix: WooCommerce', 'hesabix'); ?></h1>
<p class="hesabix-subtitle"><?php echo __('Connect Hesabix Online Accounting to WooCommerce', 'hesabix'); ?></p>
<div class="hesabix-badges d-none d-sm-flex">
<span
class="hesabix-badge version"><?php echo sprintf(__('Version %s', 'hesabix'), $plugin_version); ?></span>
<button id="hesabix-check-update" class="hesabix-badge hesabix-update-badge d-flex flex-row" disabled>
<span class="update-text"></span>
<span class="update-loading d-flex flex-row gap-2"
style="justify-content: center; align-items: center; gap: 5px;">
<div class="hesabix-spinner-small"></div>
<?php echo __('Checking...', 'hesabix'); ?>
</span>
</button>
<a href="https://hesabix.ir/help/topics/" class="hesabix-badge hesabix-guide-badge version"
style="color: white; text-decoration: none;" target="_blank">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z" />
</svg>
<?php echo __('Plugin Guide', 'hesabix'); ?>
</a>
</div>
<div class="hesabix-badges d-flex d-sm-none flex-column" style="align-items: center;">
<div class="d-flex flex-row gap-2">
<span
class="hesabix-badge version"><?php echo sprintf(__('Version %s', 'hesabix'), $plugin_version); ?></span>
</div>
<button id="hesabix-check-update" class="hesabix-badge hesabix-update-badge d-flex flex-row"
style="width: 70%;" disabled>
<span class="update-text"></span>
<span class="update-loading d-flex flex-row gap-2"
style="justify-content: center; align-items: center; gap: 5px;">
<div class="hesabix-spinner-small"></div>
<?php echo __('Checking...', 'hesabix'); ?>
</span>
</button>
<a href="https://hesabix.ir/help/topics/" class="hesabix-badge hesabix-guide-badge version"
style="color: white; text-decoration: none;" target="_blank">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z" />
</svg>
<?php echo __('Plugin Guide', 'hesabix'); ?>
</a>
</div>
</div>
</div>
<?php
}
}
new Hesabix_Admin_Display();