/**
  * Provides shortcodes for retrieving licence metadata from licence generator for use in product definition
  * shortcodes [osgi_licence_metadata] retrieving licence specification from licence generator every time page viewed
  *
  * @param unknown $atts        	
  */
 public function osgi_licence_metadata_shortcode($atts)
 {
     // set time metadata uploaded
     $objDateTime = new DateTime('NOW');
     $content = "";
     $content .= "<div id=\"osgi_licence_metadata_shortcode\" class=\"osgi_metadata\">\n";
     try {
         $edd_osgiProductIdStr = get_post_meta(get_the_ID(), '_edd_osgiProductIdStr', true);
         if (!isset($edd_osgiProductIdStr)) {
             throw new Exception('edd-osgi: You must set productId on the download definition');
         }
         $user_can_modify_metadata = is_user_logged_in() && current_user_can('view_shop_sensitive_data');
         if ($this->osgipub_osgi_debug) {
             $content .= "<p>debug: Running osgi_licence_metadata_shortcode shortcode </p>\n";
             if ($user_can_modify_metadata) {
                 $content .= "<p>debug: osgi_licence_metadata_shortcode: user permitted to modify licence metadata</p>\n";
             } else {
                 $content .= "<p>debug: osgi_licence_metadata_shortcode: user NOT permitted to modify licence metadata</p>";
             }
             $content .= "<p>debug: Attributes:";
             if ("" != $atts) {
                 foreach ($atts as $key => $value) {
                     $content .= "   " . $key . "=" . $value . "<br>\n";
                 }
             } else {
                 $content .= " Not Set";
             }
             $content .= "</p>\n";
         }
         // If user can modify shop data then they will see licence metadata and can edit it
         // load supporting class
         $eddOsgiLicences = new EddOsgiLicences();
         if ($user_can_modify_metadata) {
             // load unmodified metadata spec from licence manager
             $licenceMetadataSpecStr = $eddOsgiLicences->getLicenceMetadataSpec($edd_osgiProductIdStr);
             $osgiLicenceMetadataSpec = new SimpleXMLElement($licenceMetadataSpecStr);
             // try loading modified LicenceMetadataSpecStr from this post
             $edd_modified_osgiLicenceMetadataSpecStr = get_post_meta(get_the_ID(), '_edd_modified_osgiLicenceMetadataSpecStr', true);
             // if no modified LicenceMetadataSpecStr in post then create new one
             if (!isset($edd_modified_osgiLicenceMetadataSpecStr) || '' == $edd_modified_osgiLicenceMetadataSpecStr) {
                 $edd_modified_osgiLicenceMetadataSpecStr = $licenceMetadataSpecStr;
                 // set the update time
                 $edd_osgiLicenceMetadataStrUpdateTime = $objDateTime->format(DateTime::COOKIE);
                 update_post_meta(get_the_ID(), '_edd_osgiLicenceMetadataStrUpdateTime', $edd_osgiLicenceMetadataStrUpdateTime);
             }
             $edd_modified_osgiLicenceMetadataSpec = new SimpleXMLElement($edd_modified_osgiLicenceMetadataSpecStr);
             // check if request asks to reset the modified Licence Metadata Spec
             if (isset($_POST['_resetLicenceMetadataSpec']) && $_POST['_resetLicenceMetadataSpec'] == 'true') {
                 // if reset then load unmodified metadata spec from licence manager
                 $licenceMetadataSpecStr = $eddOsgiLicences->getLicenceMetadataSpec($edd_osgiProductIdStr);
                 $osgiLicenceMetadataSpec = new SimpleXMLElement($licenceMetadataSpecStr);
                 $edd_modified_osgiLicenceMetadataSpec = $osgiLicenceMetadataSpec;
                 $payload = (string) $edd_modified_osgiLicenceMetadataSpec->asXML();
                 update_post_meta(get_the_ID(), '_edd_modified_osgiLicenceMetadataSpecStr', $payload);
                 // set the update time
                 $edd_osgiLicenceMetadataStrUpdateTime = $objDateTime->format(DateTime::COOKIE);
                 update_post_meta(get_the_ID(), '_edd_osgiLicenceMetadataStrUpdateTime', $edd_osgiProductMetadataStrUpdateTime);
             } elseif (isset($_POST['_modifyLicenceMetadataSpec']) && $_POST['_modifyLicenceMetadataSpec'] == 'true') {
                 // check if request asks to modify the Licence Metadata Spec
                 // parse post data into modified licene metadata spec an update the post
                 $edd_modified_osgiLicenceMetadataSpec = $eddOsgiLicences->modifyLicenceMetadataFromPost($osgiLicenceMetadataSpec, $edd_modified_osgiLicenceMetadataSpec, $_POST);
                 $payload = (string) $edd_modified_osgiLicenceMetadataSpec->asXML();
                 update_post_meta(get_the_ID(), '_edd_modified_osgiLicenceMetadataSpecStr', $payload);
                 // set the update time
                 $edd_osgiLicenceMetadataStrUpdateTime = $objDateTime->format(DateTime::COOKIE);
                 update_post_meta(get_the_ID(), '_edd_osgiLicenceMetadataStrUpdateTime', $edd_osgiLicenceMetadataStrUpdateTime);
             }
             $noinput = false;
             // update time string is time when matadata last updated
             $edd_osgiLicenceMetadataStrUpdateTime = get_post_meta(get_the_ID(), '_edd_osgiLicenceMetadataStrUpdateTime', true);
             if (isset($edd_osgiLicenceMetadataStrUpdateTime)) {
                 $content .= "<div style=\" line-height: 80%;\">Licence Metadata (Last Updated: " . $edd_osgiLicenceMetadataStrUpdateTime . ")</div>\n";
             }
             $content .= "<form method=\"post\" action=\"\" enctype=\"multipart/form-data\">\n";
             $content .= $eddOsgiLicences->licenceMetadataForm($edd_modified_osgiLicenceMetadataSpec, $osgiLicenceMetadataSpec, $noinput);
             // set up form to update licence metadata
             $content .= "<p>As a privileged user you can modify the standard metadata spec for this product instance</p>\n";
             $content .= "<p>(e.g. you can change the options or duration of the licence)</p>\n";
             $content .= "<input type=\"hidden\" name=\"_modifyLicenceMetadataSpec\" value=\"true\">\n";
             $content .= "<button type=\"submit\">Update Licence Metadata Spec</button>\n";
             $content .= "</form>\n";
             $content .= "<form method=\"post\" action=\"\" enctype=\"multipart/form-data\">\n";
             $content .= "<input type=\"hidden\" name=\"_resetLicenceMetadataSpec\" value=\"true\">\n";
             $content .= "<button type=\"submit\">Reset Licence Metadata Spec</button>\n";
             $content .= "</form>\n";
         }
     } catch (Exception $e) {
         $content .= "<p>" . "Exception in osgi_licence_metadata shortcode: Exception: " . $e->getMessage() . "</p>\n";
     }
     $content .= "</div> <!-- id=\"osgi_licence_metadata_shortcode\" -->\n";
     return $content;
 }
            ?>
">Link to Payment Receipt: <?php 
            echo edd_get_payment_number($edd_payment_post_id);
            ?>
</a>
<p>
<?php 
        }
        ?>


<h2>Licence Metadata</h2>

<form method="post" action="" enctype="multipart/form-data">
<?php 
        echo $eddOsgiLicences->licenceMetadataForm($osgilicenceMetadata, $osgilicenceMetadataSpec, $noEditMetadata);
        if ($noEditMetadata == TRUE) {
            ?>
<p>(Cannot be Edited)</p>
<?php 
        } else {
            ?>
<p>(Empty fields marked with ** must be completed before generating a
		licence)"</p>
<?php 
        }
        ?>
<p></p>
<?php 
        if (isset($edd_osgiLicenceStr) && $edd_osgiLicenceStr != '') {
            ?>