<?php
/**
 * @package		JooCart
 * @copyright	Copyright (C) 2009 - 2025 softPHP,https://www.soft-php.com
 * @license		GNU/GPL http://www.gnu.org/copyleft/gpl.html
 */
// no direct access
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
// register_activation_hook(JOOCART_PLUGIN_FILENAME,'joocart_store_activate');
// register_deactivation_hook(JOOCART_PLUGIN_FILENAME,'joocart_store_deactivate');
function joocart_store_activate() {
	$my_joocart_post=array();
	$joocart_content="<!-- JooCart Code. Please do not remove this line,otherwise JooCart shopping cart will not work properly. -->[joocart_main_content]<!-- JooCart Code End. -->";
	add_option("joocart_shop_page_id",'','','yes');
	add_option("joocart_upgrade_download_id",'','','yes');
	add_option("joocart_order_email",'','','yes');
	// add_option("joocart_site_url",'','','yes');
	add_option("joocart_opencart_dir_path",'','','yes');
	add_option("joocart_opencart_dir_url",'','','yes');
	add_option("joocart_who_can_access_admin",'','','yes');
	add_option("joocart_use_wordpress_button",'','','yes');
	add_option("joocart_dont_show_header",'','','yes');
	add_option("joocart_dont_show_footer",'','','yes');
	add_option("joocart_dont_show_menus",'','','yes');
	add_option("joocart_dont_show_admin_login",'','','yes');
	add_option("joocart_dont_include_jquery",'','','yes');
	add_option("joocart_disable_bootstrap_tooltip",'','','yes');
	add_option("joocart_use_jquery_dollar",'','','yes');
	add_option("joocart_dont_show_left_right_column",'','','yes');
	add_option("joocart_enable_wp_widget_title",'','','yes');
	// add_option("joocart_main_http_server",'','','yes');
	add_option("joocart_redirect_http_server",'','','yes');
	add_option("joocart_change_lang_to_default",'','','yes');
	add_option("joocart_use_wordpress_db",'','','yes');
	add_option("joocart_db_user_name",'','','yes');
	add_option("joocart_db_user_password",'','','yes');
	add_option("joocart_db_user_host",'','','yes');
	add_option("joocart_db_name",'','','yes');
	add_option("joocart_db_user_prefix",'','','yes');
	add_option("joocart_use_custom_color",'','','yes');
	add_option("joocart_default_txt_color",'','','yes');	
	add_option("joocart_default_link_color",'','','yes');
	add_option("joocart_default_link_hover_color",'','','yes');
	add_option("joocart_default_button_box_color",'','','yes');
	add_option("joocart_default_button_hover_color",'','','yes');
	add_option("joocart_default_button_txt_color",'','','yes');	
	add_option("joocart_default_menu_link_color",'','','yes');
	add_option("joocart_default_menu_link_hover_color",'','','yes');
	add_option("joocart_use_gradient_color",'','','yes');
	add_option("joocart_custom_css_oc",'','','yes');
	add_option("joocart_select_seo_for_prod_cat",'','','yes');
	add_option("joocart_use_dynamic_checkout_urls",'','','yes');

	$id=get_option("joocart_shop_page_id");
	$_tmp_page=NULL;
	if(!empty($id) && $id>0){
		$_tmp_page=get_page($id);
	}
	if($_tmp_page!=NULL){
		$my_joocart_post=array();
		$my_joocart_post['ID']=$id;
		$my_joocart_post['post_status']='publish';
		wp_update_post($my_joocart_post);
	}
	else{
		
		$my_joocart_post['post_title']='Shop';
		$my_joocart_post['post_content']=$joocart_content;
		$my_joocart_post['post_status']='publish';
		$my_joocart_post['post_author']=1;
		$my_joocart_post['post_type']='page';
		//$my_joocart_post['post_name']='shop';
		$my_joocart_post['comment_status']='closed';
		$id=wp_insert_post($my_joocart_post);
		update_option('joocart_shop_page_id',$id);
	}


}
function joocart_store_deactivate() {
	$id=get_option("joocart_shop_page_id");
	$_tmp_page=NULL;

	if(!empty($id) && $id>0){
		$_tmp_page=get_page($id);
		if($_tmp_page!=NULL){
			$my_joocart_post=array();
			$my_joocart_post['ID']=$id;
			$my_joocart_post['post_status']='draft';
			wp_update_post($my_joocart_post);
		}
		else{
			update_option('joocart_shop_page_id','');
		}
	}
	global $wp_rewrite;
    $wp_rewrite->flush_rules();
}
function joocart_installation_page(){
	
	$joocart_opencart_dir_path = rtrim(str_replace('\\', '/', trim(get_option('joocart_opencart_dir_path'))), '/') . '/';
	if(file_exists($joocart_opencart_dir_path . 'system/startup.php')) {
		joocart_admin_main();
	} else {
		joocart_options_do_page();
	}
}
?>