diff --git a/software-license-manager/includes/slm-api-listener.php b/software-license-manager/includes/slm-api-listener.php index 065e5f3..0cb20c5 100644 --- a/software-license-manager/includes/slm-api-listener.php +++ b/software-license-manager/includes/slm-api-listener.php @@ -33,9 +33,9 @@ function creation_api_listener() { SLM_API_Utility::verify_secret_key_for_creation(); //Verify the secret key first. $slm_debug_logger->log_debug("API - license creation (slm_create_new) request received."); - + //Action hook - do_action('slm_api_listener_slm_create_new'); + do_action('slm_api_listener_slm_create_new'); $fields = array(); if (isset($_REQUEST['license_key']) && !empty($_REQUEST['license_key'])){ @@ -49,11 +49,17 @@ function creation_api_listener() { $fields['email'] = strip_tags($_REQUEST['email']); $fields['company_name'] = wp_unslash(strip_tags($_REQUEST['company_name'])); $fields['txn_id'] = strip_tags($_REQUEST['txn_id']); + if (empty($_REQUEST['max_allowed_domains'])) { $fields['max_allowed_domains'] = $options['default_max_domains']; } else { $fields['max_allowed_domains'] = strip_tags($_REQUEST['max_allowed_domains']); } + if (empty($_REQUEST['max_allowed_devices'])) { + $fields['max_allowed_devices'] = $options['default_max_devices']; + } else { + $fields['max_allowed_devices'] = strip_tags($_REQUEST['max_allowed_devices']); + } $fields['date_created'] = isset($_REQUEST['date_created'])?strip_tags($_REQUEST['date_created']):date("Y-m-d"); $fields['date_expiry'] = isset($_REQUEST['date_expiry'])?strip_tags($_REQUEST['date_expiry']):''; @@ -87,9 +93,9 @@ function activation_api_listener() { SLM_API_Utility::verify_secret_key(); //Verify the secret key first. $slm_debug_logger->log_debug("API - license activation (slm_activate) request received."); - + //Action hook - do_action('slm_api_listener_slm_activate'); + do_action('slm_api_listener_slm_activate'); $fields = array(); $fields['lic_key'] = trim(strip_tags($_REQUEST['license_key'])); @@ -106,6 +112,7 @@ function activation_api_listener() { $sql_prep2 = $wpdb->prepare("SELECT * FROM $reg_table WHERE lic_key = %s", $key); $reg_domains = $wpdb->get_results($sql_prep2, OBJECT); + if ($retLic) { if ($retLic->lic_status == 'blocked') { $args = (array('result' => 'error', 'message' => 'Your License key is blocked', 'error_code' => SLM_Error_Codes::LICENSE_BLOCKED)); @@ -127,20 +134,52 @@ function activation_api_listener() { SLM_API_Utility::output_api_response($args); } } + $fields['lic_key_id'] = $retLic->id; $wpdb->insert($reg_table, $fields); - + $slm_debug_logger->log_debug("Updating license key status to active."); $data = array('lic_status' => 'active'); $where = array('id' => $retLic->id); $updated = $wpdb->update($tbl_name, $data, $where); - + $args = (array('result' => 'success', 'message' => 'License key activated')); SLM_API_Utility::output_api_response($args); - } else { + } + else { $args = (array('result' => 'error', 'message' => 'Reached maximum allowable domains', 'error_code' => SLM_Error_Codes::REACHED_MAX_DOMAINS)); SLM_API_Utility::output_api_response($args); } + + if (count($reg_domains) < floor($retLic->max_allowed_domains)) { + foreach ($reg_domains as $reg_domain) { + if (isset($_REQUEST['migrate_from']) && (trim($_REQUEST['migrate_from']) == $reg_domain->registered_domain)) { + $wpdb->update($reg_table, array('registered_domain' => $fields['registered_domain']), array('registered_domain' => trim(strip_tags($_REQUEST['migrate_from'])))); + $args = (array('result' => 'success', 'message' => 'Registered domain has been updated')); + SLM_API_Utility::output_api_response($args); + } + if ($fields['registered_domain'] == $reg_domain->registered_domain) { + $args = (array('result' => 'error', 'message' => 'License key already in use on ' . $reg_domain->registered_domain, 'error_code' => SLM_Error_Codes::LICENSE_IN_USE)); + SLM_API_Utility::output_api_response($args); + } + } + + $fields['lic_key_id'] = $retLic->id; + $wpdb->insert($reg_table, $fields); + + $slm_debug_logger->log_debug("Updating license key status to active."); + $data = array('lic_status' => 'active'); + $where = array('id' => $retLic->id); + $updated = $wpdb->update($tbl_name, $data, $where); + + $args = (array('result' => 'success', 'message' => 'License key activated')); + SLM_API_Utility::output_api_response($args); + } + else { + $args = (array('result' => 'error', 'message' => 'Reached maximum allowable devices', 'error_code' => SLM_Error_Codes::REACHED_MAX_DOMAINS)); + SLM_API_Utility::output_api_response($args); + } + } else { $args = (array('result' => 'error', 'message' => 'Invalid license key', 'error_code' => SLM_Error_Codes::LICENSE_INVALID)); SLM_API_Utility::output_api_response($args); @@ -156,9 +195,9 @@ function deactivation_api_listener() { SLM_API_Utility::verify_secret_key(); //Verify the secret key first. $slm_debug_logger->log_debug("API - license deactivation (slm_deactivate) request received."); - + //Action hook - do_action('slm_api_listener_slm_deactivate'); + do_action('slm_api_listener_slm_deactivate'); if (empty($_REQUEST['registered_domain'])) { $args = (array('result' => 'error', 'message' => 'Registered domain information is missing', 'error_code' => SLM_Error_Codes::DOMAIN_MISSING)); @@ -192,14 +231,14 @@ function check_api_listener() { SLM_API_Utility::verify_secret_key(); //Verify the secret key first. $slm_debug_logger->log_debug("API - license check (slm_check) request received."); - + $fields = array(); $fields['lic_key'] = trim(strip_tags($_REQUEST['license_key'])); $slm_debug_logger->log_debug("License key: " . $fields['lic_key']); //Action hook do_action('slm_api_listener_slm_check'); - + global $wpdb; $tbl_name = SLM_TBL_LICENSE_KEYS; $reg_table = SLM_TBL_LIC_DOMAIN; @@ -211,12 +250,18 @@ function check_api_listener() { $reg_domains = $wpdb->get_results($sql_prep2, OBJECT); if ($retLic) {//A license key exists $args = (array( - 'result' => 'success', - 'message' => 'License key details retrieved.', - 'status' => $retLic->lic_status, + 'result' => 'success', + 'code' => '200', + 'message' => 'License key details retrieved.', + 'status' => $retLic->lic_status, 'max_allowed_domains' => $retLic->max_allowed_domains, + 'max_allowed_devices' => $retLic->max_allowed_devices, 'email' => $retLic->email, + 'first_name' => $retLic->first_name, + 'last_name' => $retLic->last_name, + // 'until' => $retLic->until, //until what version license is supported 'registered_domains' => $reg_domains, + 'license_key' => $retLic->license_key, 'date_created' => $retLic->date_created, 'date_renewed' => $retLic->date_renewed, 'date_expiry' => $retLic->date_expiry, @@ -226,7 +271,7 @@ function check_api_listener() { } else { $args = (array('result' => 'error', 'message' => 'Invalid license key', 'error_code' => SLM_Error_Codes::LICENSE_INVALID)); SLM_API_Utility::output_api_response($args); - } + } } } diff --git a/software-license-manager/includes/slm-api-utility.php b/software-license-manager/includes/slm-api-utility.php index 61b3e2f..8fd3222 100644 --- a/software-license-manager/includes/slm-api-utility.php +++ b/software-license-manager/includes/slm-api-utility.php @@ -26,7 +26,7 @@ static function verify_secret_key() { SLM_API_Utility::output_api_response($args); } } - + static function verify_secret_key_for_creation() { $slm_options = get_option('slm_plugin_options'); $right_secret_key = $slm_options['lic_creation_secret']; @@ -35,7 +35,7 @@ static function verify_secret_key_for_creation() { $args = (array('result' => 'error', 'message' => 'License Creation API secret key is invalid', 'error_code' => SLM_Error_Codes::CREATE_KEY_INVALID)); SLM_API_Utility::output_api_response($args); } - } + } static function insert_license_data_internal($fields) { /* The fields array should have values for the following keys diff --git a/software-license-manager/includes/slm-meta-boxes.php b/software-license-manager/includes/slm-meta-boxes.php new file mode 100644 index 0000000..00ed4e1 --- /dev/null +++ b/software-license-manager/includes/slm-meta-boxes.php @@ -0,0 +1,64 @@ +'; + + // License Field + woocommerce_wp_text_input( + array( + 'id' => 'amount_of_licenses['. $loop .']', + 'label' => __( 'Number of Licenses (domain)', 'woocommerce' ), + 'placeholder' => '1-20', + 'desc_tip' => true, + 'wrapper_class' => 'form-row form-row-first', + 'description' => __( 'Ideal for themes, plugins, and websites', 'woocommerce' ), + 'value' => get_post_meta($variation->ID, 'amount_of_licenses', true) + ) + ); + + echo ""; + + echo '
'; + + // License Field + woocommerce_wp_text_input( + array( + 'id' => 'amount_of_licenses_devices['. $loop .']', + 'label' => __( 'Number of Licenses (devices)', 'woocommerce' ), + 'placeholder' => '1-20', + 'desc_tip' => true, + 'wrapper_class' => 'form-row form-row-first', + 'description' => __( 'Ideal for software and apps.', 'woocommerce' ), + 'value' => get_post_meta($variation->ID, 'amount_of_licenses_devices', true) + ) + ); + + echo "
"; + +} + +/** Save new fields for variations */ +function save_variation_fields( $variation_id, $i) { + + // License Field + $text_field = stripslashes( $_POST['amount_of_licenses'][$i] ); + update_post_meta( $variation_id, 'amount_of_licenses', esc_attr( $text_field ) ); + + $text_field = stripslashes( $_POST['amount_of_licenses_devices'][$i] ); + update_post_meta( $variation_id, 'amount_of_licenses_devices', esc_attr( $text_field ) ); + +} \ No newline at end of file diff --git a/software-license-manager/includes/slm-third-party-integration.php b/software-license-manager/includes/slm-third-party-integration.php index 8e06e33..6d0ca78 100644 --- a/software-license-manager/includes/slm-third-party-integration.php +++ b/software-license-manager/includes/slm-third-party-integration.php @@ -46,7 +46,7 @@ function slm_estore_check_and_generate_key($retrieved_product, $payment_data, $c //More than 1 qty of the same product for($i=0; $i < $requested_qty; $i++){ $slm_key = slm_estore_create_license($retrieved_product, $payment_data, $cart_items); - $license_data .= "\n" . __('Item Name: ', 'slm') . $retrieved_product->name . " - " . __('License Key '.($i+1).': ', 'slm') . $slm_key; + $license_data .= "\n" . __('Item Name: ', 'slm') . $retrieved_product->name . " - " . __('License Key '.($i+1).': ', 'slm') . $slm_key; } } else { @@ -54,7 +54,7 @@ function slm_estore_check_and_generate_key($retrieved_product, $payment_data, $c $slm_key = slm_estore_create_license($retrieved_product, $payment_data, $cart_items); $license_data = "\n" . __('Item Name: ', 'slm') . $retrieved_product->name . " - " . __('License Key: ', 'slm') . $slm_key; } - + $slm_debug_logger->log_debug('Liense data: ' . $license_data); $license_data = apply_filters('slm_estore_item_license_data', $license_data); } @@ -65,11 +65,12 @@ function slm_estore_create_license($retrieved_product, $payment_data, $cart_item global $slm_debug_logger; global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; - + //Retrieve the default settings values. $options = get_option('slm_plugin_options'); $lic_key_prefix = $options['lic_prefix']; $max_domains = $options['default_max_domains']; + $max_devices = $options['default_max_devices']; //Lets check any product specific configuration. $prod_id = $retrieved_product->id; @@ -80,7 +81,22 @@ function slm_estore_create_license($retrieved_product, $payment_data, $cart_item } else { //Use the default value from settings (the $max_domains variable contains the default value already). } - //Lets check if any product specific expiry date is set + + $product_meta = $wpdb->get_row("SELECT * FROM $product_meta_table_name WHERE prod_id = '$prod_id' AND meta_key='slm_max_allowed_devices'", OBJECT); + if ($product_meta) { + //Found product specific SLM config data. + $max_devices = $product_meta->meta_value; + } else { + //Use the default value from settings (the $max_domains variable contains the default value already). + } + + $product_meta = $wpdb->get_row("SELECT * FROM $product_meta_table_name WHERE prod_id = '$prod_id' AND meta_key='slm_max_allowed_devices'", OBJECT); + if ($product_meta) { + //Found product specific SLM config data. + $max_devices = $product_meta->meta_value; + } else { + //Use the default value from settings (the $max_domains variable contains the default value already). + } //Lets check if any product specific expiry date is set $product_meta = $wpdb->get_row("SELECT * FROM $product_meta_table_name WHERE prod_id = '$prod_id' AND meta_key='slm_date_of_expiry'", OBJECT); if ($product_meta) { //Found product specific SLM config data. @@ -91,8 +107,8 @@ function slm_estore_create_license($retrieved_product, $payment_data, $cart_item $current_date_plus_1year = date('Y-m-d', strtotime('+1 year')); $slm_date_of_expiry = $current_date_plus_1year; } - - + + $fields = array(); $fields['license_key'] = uniqid($lic_key_prefix); $fields['lic_status'] = 'pending'; @@ -102,7 +118,8 @@ function slm_estore_create_license($retrieved_product, $payment_data, $cart_item $fields['company_name'] = $payment_data['company_name']; $fields['txn_id'] = $payment_data['txn_id']; $fields['max_allowed_domains'] = $max_domains; - $fields['date_created'] = date("Y-m-d"); //Today's date + $fields['max_allowed_devices'] = $max_devices; + $fields['date_created'] = date("Y-m-d"); //Today's date $fields['date_expiry'] = $slm_date_of_expiry; $slm_debug_logger->log_debug('Inserting license data into the license manager DB table.'); @@ -140,14 +157,15 @@ function slm_estore_create_license($retrieved_product, $payment_data, $cart_item function slm_estore_product_configuration_html($product_config_html, $prod_id) { global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; - + if (empty($prod_id)) { //New product add $slm_max_allowed_domains = ""; + $slm_max_allowed_devices = ""; $slm_date_of_expiry = ""; } else { //Existing product edit - + //Retrieve the max domain value $product_meta = $wpdb->get_row("SELECT * FROM $product_meta_table_name WHERE prod_id = '$prod_id' AND meta_key='slm_max_allowed_domains'", OBJECT); if ($product_meta) { @@ -155,7 +173,14 @@ function slm_estore_product_configuration_html($product_config_html, $prod_id) { } else { $slm_max_allowed_domains = ""; } - + + $product_meta = $wpdb->get_row("SELECT * FROM $product_meta_table_name WHERE prod_id = '$prod_id' AND meta_key='slm_max_allowed_devices'", OBJECT); + if ($product_meta) { + $slm_max_allowed_devices = $product_meta->meta_value; + } else { + $slm_max_allowed_devices = ""; + } + //Retrieve the expiry date value $product_meta = $wpdb->get_row("SELECT * FROM $product_meta_table_name WHERE prod_id = '$prod_id' AND meta_key='slm_date_of_expiry'", OBJECT); if ($product_meta) { @@ -173,6 +198,11 @@ function slm_estore_product_configuration_html($product_config_html, $prod_id) { $product_config_html .= '

Number of domains/installs in which this license can be used. Leave blank if you wish to use the default value set in the license manager plugin settings.

'; $product_config_html .= ''; + $product_config_html .= 'Maximum Allowed Devices'; + $product_config_html .= ''; + $product_config_html .= '

Number of devices in which this license can be used. Leave blank if you wish to use the default value set in the license manager plugin settings.

'; + $product_config_html .= ''; + $product_config_html .= 'Number of Days before Expiry'; $product_config_html .= ' Days'; $product_config_html .= '

Number of days before expiry. The expiry date of the license will be set based on this value. For example, if you want the key to expire in 6 months then enter a value of 180.

'; @@ -192,11 +222,13 @@ function slm_estore_new_product_added($prod_dat_array, $prod_id) { $fields['prod_id'] = $prod_id; $fields['meta_key'] = 'slm_max_allowed_domains'; $fields['meta_value'] = $prod_dat_array['slm_max_allowed_domains']; + $fields['meta_key'] = 'slm_max_allowed_devices'; + $fields['meta_value'] = $prod_dat_array['slm_max_allowed_devices']; $result = $wpdb->insert($product_meta_table_name, $fields); if (!$result) { //insert query failed } - + //Save expiry date value $fields = array(); $fields['prod_id'] = $prod_id; @@ -206,7 +238,7 @@ function slm_estore_new_product_added($prod_dat_array, $prod_id) { if (!$result) { //insert query failed } - + } function slm_estore_product_updated($prod_dat_array, $prod_id) { @@ -219,18 +251,22 @@ function slm_estore_product_updated($prod_dat_array, $prod_id) { //Found existing value so lets update it $fields = array(); $fields['meta_key'] = 'slm_max_allowed_domains'; + $fields['meta_key'] = 'slm_max_allowed_devices'; $fields['meta_value'] = $prod_dat_array['slm_max_allowed_domains']; - $result = $wpdb->update($product_meta_table_name, $fields, array('prod_id' => $prod_id)); - + $fields['meta_value'] = $prod_dat_array['slm_max_allowed_devices']; + $result = $wpdb->update($product_meta_table_name, $fields, array('prod_id' => $prod_id)); + } else { //No value for this field was there so lets insert one. $fields = array(); $fields['prod_id'] = $prod_id; $fields['meta_key'] = 'slm_max_allowed_domains'; + $fields['meta_key'] = 'slm_max_allowed_devices'; $fields['meta_value'] = $prod_dat_array['slm_max_allowed_domains']; - $result = $wpdb->insert($product_meta_table_name, $fields); + $fields['meta_value'] = $prod_dat_array['slm_max_allowed_devices']; + $result = $wpdb->insert($product_meta_table_name, $fields); } - + //Find the existing value for the expiry date field (for the given product) $product_meta = $wpdb->get_row("SELECT * FROM $product_meta_table_name WHERE prod_id = '$prod_id' AND meta_key='slm_date_of_expiry'", OBJECT); if ($product_meta) { @@ -238,24 +274,25 @@ function slm_estore_product_updated($prod_dat_array, $prod_id) { $fields = array(); $fields['meta_key'] = 'slm_date_of_expiry'; $fields['meta_value'] = $prod_dat_array['slm_date_of_expiry']; - $result = $wpdb->update($product_meta_table_name, $fields, array('prod_id' => $prod_id)); - + $result = $wpdb->update($product_meta_table_name, $fields, array('prod_id' => $prod_id)); + } else { //No value for this field was there so lets insert one. $fields = array(); $fields['prod_id'] = $prod_id; $fields['meta_key'] = 'slm_date_of_expiry'; $fields['meta_value'] = $prod_dat_array['slm_date_of_expiry']; - $result = $wpdb->insert($product_meta_table_name, $fields); + $result = $wpdb->insert($product_meta_table_name, $fields); } - + } function slm_estore_product_deleted($prod_id) { global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; - + $result = $wpdb->delete($product_meta_table_name, array('prod_id' => $prod_id, 'meta_key' => 'slm_max_allowed_domains')); + $result = $wpdb->delete($product_meta_table_name, array('prod_id' => $prod_id, 'meta_key' => 'slm_max_allowed_devices')); $result = $wpdb->delete($product_meta_table_name, array('prod_id' => $prod_id, 'meta_key' => 'slm_date_of_expiry')); } diff --git a/software-license-manager/logs/log.txt b/software-license-manager/logs/log.txt index e69de29..28c2021 100644 --- a/software-license-manager/logs/log.txt +++ b/software-license-manager/logs/log.txt @@ -0,0 +1,33 @@ +[07/04/2017 7:02 PM] - STATUS : SLM daily cronjob - auto expiry of license key is enabled. +[07/05/2017 7:21 PM] - STATUS : SLM daily cronjob - auto expiry of license key is enabled. +[07/06/2017 6:44 PM] - STATUS : SLM daily cronjob - auto expiry of license key is enabled. +[07/10/2017 4:49 PM] - STATUS : SLM daily cronjob - auto expiry of license key is enabled. +[07/10/2017 8:57 PM] - STATUS : SLM daily cronjob - auto expiry of license key is enabled. +[07/14/2017 6:34 PM] - STATUS : SLM daily cronjob - auto expiry of license key is enabled. +[07/18/2017 11:23 PM] - SUCCESS : API - license check (slm_check) request received. +[07/18/2017 11:23 PM] - SUCCESS : License key: PK-15-LN-0-596e93655b246 +[07/18/2017 11:23 PM] - SUCCESS : API Response - Result: success Message: License key details retrieved. +[07/18/2017 11:23 PM] - SUCCESS : API - license check (slm_check) request received. +[07/18/2017 11:23 PM] - SUCCESS : License key: PK-15-LN-0-596e93655b246 +[07/18/2017 11:23 PM] - SUCCESS : API Response - Result: success Message: License key details retrieved. +[07/18/2017 11:24 PM] - SUCCESS : API - license check (slm_check) request received. +[07/18/2017 11:24 PM] - SUCCESS : License key: PK-15-LN-0-596e93655b246 +[07/18/2017 11:24 PM] - SUCCESS : API Response - Result: success Message: License key details retrieved. +[07/18/2017 11:25 PM] - SUCCESS : API - license check (slm_check) request received. +[07/18/2017 11:25 PM] - SUCCESS : License key: PK-15-LN-0-596e93655b246 +[07/18/2017 11:25 PM] - SUCCESS : API Response - Result: success Message: License key details retrieved. +[07/18/2017 11:25 PM] - SUCCESS : API - license check (slm_check) request received. +[07/18/2017 11:25 PM] - SUCCESS : License key: PK-15-LN-0-596e93655b246 +[07/18/2017 11:25 PM] - SUCCESS : API Response - Result: success Message: License key details retrieved. +[07/18/2017 11:25 PM] - SUCCESS : API - license check (slm_check) request received. +[07/18/2017 11:25 PM] - SUCCESS : License key: PK-15-LN-0-596e93655b246 +[07/18/2017 11:25 PM] - SUCCESS : API Response - Result: success Message: License key details retrieved. +[07/18/2017 11:26 PM] - SUCCESS : API - license check (slm_check) request received. +[07/18/2017 11:26 PM] - SUCCESS : License key: PK-15-LN-0-596e93655b246 +[07/18/2017 11:26 PM] - SUCCESS : API Response - Result: success Message: License key details retrieved. +[07/18/2017 11:28 PM] - SUCCESS : API - license check (slm_check) request received. +[07/18/2017 11:28 PM] - SUCCESS : License key: PK-15-LN-0-596e93655b246 +[07/18/2017 11:28 PM] - SUCCESS : API Response - Result: success Message: License key details retrieved. +[07/18/2017 11:30 PM] - SUCCESS : API - license check (slm_check) request received. +[07/18/2017 11:30 PM] - SUCCESS : License key: PK-15-LN-0-596e93655b246 +[07/18/2017 11:30 PM] - SUCCESS : API Response - Result: success Message: License key details retrieved. diff --git a/software-license-manager/menu/slm-add-licenses.php b/software-license-manager/menu/slm-add-licenses.php index 53648fa..421523d 100644 --- a/software-license-manager/menu/slm-add-licenses.php +++ b/software-license-manager/menu/slm-add-licenses.php @@ -6,6 +6,7 @@ function wp_lic_mgr_add_licenses_menu() { $id = ''; $license_key = ''; $max_domains = 1; + $max_devices = 1; $license_status = ''; $first_name = ''; $last_name = ''; @@ -20,7 +21,7 @@ function wp_lic_mgr_add_licenses_menu() { $current_date_plus_1year = date('Y-m-d', strtotime('+1 year')); $slm_options = get_option('slm_plugin_options'); - + echo '
'; echo '

Add/Edit Licenses

'; echo '
'; @@ -34,6 +35,7 @@ function wp_lic_mgr_add_licenses_menu() { $record = $wpdb->get_row($sql_prep, OBJECT); $license_key = $record->license_key; $max_domains = $record->max_allowed_domains; + $max_devices = $record->max_allowed_devices; $license_status = $record->lic_status; $first_name = $record->first_name; $last_name = $record->last_name; @@ -45,21 +47,22 @@ function wp_lic_mgr_add_licenses_menu() { $renewed_date = $record->date_renewed; $expiry_date = $record->date_expiry; } - - + + if (isset($_POST['save_record'])) { - + //Check nonce if ( !isset($_POST['slm_add_edit_nonce_val']) || !wp_verify_nonce($_POST['slm_add_edit_nonce_val'], 'slm_add_edit_nonce_action' )){ //Nonce check failed. wp_die("Error! Nonce verification failed for license save action."); } - + do_action('slm_add_edit_interface_save_submission'); - + //TODO - do some validation $license_key = $_POST['license_key']; $max_domains = $_POST['max_allowed_domains']; + $max_devices = $_POST['max_allowed_devices']; $license_status = $_POST['lic_status']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; @@ -70,7 +73,7 @@ function wp_lic_mgr_add_licenses_menu() { $created_date = $_POST['date_created']; $renewed_date = $_POST['date_renewed']; $expiry_date = $_POST['date_expiry']; - + if(empty($created_date)){ $created_date = $current_date; } @@ -80,11 +83,12 @@ function wp_lic_mgr_add_licenses_menu() { if(empty($expiry_date)){ $expiry_date = $current_date_plus_1year; } - + //Save the entry to the database $fields = array(); $fields['license_key'] = $license_key; $fields['max_allowed_domains'] = $max_domains; + $fields['max_allowed_devices'] = $max_devices; $fields['lic_status'] = $license_status; $fields['first_name'] = $first_name; $fields['last_name'] = $last_name; @@ -119,19 +123,19 @@ function wp_lic_mgr_add_licenses_menu() { echo $message; echo '

'; }else{ - echo '
' . $errors . '
'; + echo '
' . $errors . '
'; } - + $data = array('row_id' => $id, 'key' => $license_key); do_action('slm_add_edit_interface_save_record_processed',$data); - + } -?> +?> You can add a new license or edit an existing one from this interface. @@ -173,10 +177,15 @@ function wp_lic_mgr_add_licenses_menu() {
Number of domains/installs in which this license can be used. + + Maximum Allowed Devices +
Number of domains/installs in which this license can be used. + + License Status - @@ -204,14 +213,14 @@ function wp_lic_mgr_add_licenses_menu() { foreach ($reg_domains as $reg_domain) { ?> > - registered_domain; ?> + registered_domain; ?> id ?>>X - +
- +
diff --git a/software-license-manager/menu/slm-lic-settings.php b/software-license-manager/menu/slm-lic-settings.php index 5b3d0bb..5dac3a7 100644 --- a/software-license-manager/menu/slm-lic-settings.php +++ b/software-license-manager/menu/slm-lic-settings.php @@ -27,18 +27,22 @@ function wp_lic_mgr_general_settings() { if (!is_numeric($_POST["default_max_domains"])) {//Set it to one by default if incorrect value is entered $_POST["default_max_domains"] = '1'; } + if (!is_numeric($_POST["default_max_devices"])) {//Set it to one by default if incorrect value is entered + $_POST["default_max_devices"] = '1'; + } $options = array( 'lic_creation_secret' => trim($_POST["lic_creation_secret"]), 'lic_prefix' => trim($_POST["lic_prefix"]), 'default_max_domains' => trim($_POST["default_max_domains"]), + 'default_max_devices' => trim($_POST["default_max_devices"]), 'lic_verification_secret' => trim($_POST["lic_verification_secret"]), 'enable_auto_key_expiry' => isset($_POST['enable_auto_key_expiry']) ? '1':'', 'enable_debug' => isset($_POST['enable_debug']) ? '1':'', ); update_option('slm_plugin_options', $options); - - echo '

'; + + echo '

'; echo 'Options Updated!'; echo '

'; } @@ -95,15 +99,21 @@ function wp_lic_mgr_general_settings() {
Maximum number of domains/installs which each license is valid for (default value). - + + + Maximum Allowed Devices + +
Maximum number of devices which each license is valid for (default value). + + Auto Expire License Keys - value="1"/> -

When enabled, it will automatically set the status of a license key to "Expired" when the expiry date value of the key is reached. + value="1"/> +

When enabled, it will automatically set the status of a license key to "Expired" when the expiry date value of the key is reached. It doesn't remotely deactivate a key. It simply changes the status of the key in your database to expired.

- +
@@ -115,8 +125,8 @@ function wp_lic_mgr_general_settings() { Enable Debug Logging - value="1"/> -

If checked, debug output will be written to log files (keep it disabled unless you are troubleshooting).

+ value="1"/> +

If checked, debug output will be written to log files (keep it disabled unless you are troubleshooting).


- View debug log file by clicking here.
- Reset debug log file by clicking here. diff --git a/software-license-manager/slm_bootstrap.php b/software-license-manager/slm_bootstrap.php index 933267e..0c55d57 100644 --- a/software-license-manager/slm_bootstrap.php +++ b/software-license-manager/slm_bootstrap.php @@ -1,11 +1,11 @@ charset)){ @@ -16,12 +16,13 @@ if (!empty($wpdb->collate)){ $charset_collate .= " COLLATE $wpdb->collate"; } - + $lk_tbl_sql = "CREATE TABLE " . $lic_key_table . " ( id int(12) NOT NULL auto_increment, license_key varchar(255) NOT NULL, - max_allowed_domains int(12) NOT NULL, - lic_status ENUM('pending', 'active', 'blocked', 'expired') NOT NULL DEFAULT 'pending', + max_allowed_domains int(40) NOT NULL, + max_allowed_devices int(40) NOT NULL, + lic_status ENUM('pending', 'active', 'blocked', 'expired') NOT NULL DEFAULT 'pending', first_name varchar(32) NOT NULL default '', last_name varchar(32) NOT NULL default '', email varchar(64) NOT NULL, @@ -53,6 +54,7 @@ 'lic_creation_secret' => uniqid('', true), 'lic_prefix' => '', 'default_max_domains' => '1', + 'default_max_devices' => '1', 'lic_verification_secret' => uniqid('', true), 'enable_debug' => '', ); diff --git a/software-license-manager/slm_plugin_core.php b/software-license-manager/slm_plugin_core.php index 0005fe6..98b90e5 100644 --- a/software-license-manager/slm_plugin_core.php +++ b/software-license-manager/slm_plugin_core.php @@ -16,6 +16,8 @@ include_once('includes/slm-api-utility.php'); include_once('includes/slm-api-listener.php'); include_once('includes/slm-third-party-integration.php'); +// support for meta boxes (variations only, this can be applied to single prodicts as well) +include_once('includes/slm-meta-boxes.php'); //Include admin side only files if (is_admin()) { include_once('menu/slm-admin-init.php');