﻿<html><head></head><body onload="IOTAPAddOnLicensing.OnLoad()">﻿

 <title>License Activation</title> 
    <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
    <script src="iotap_oneclickpdf_jquery1.8.3.js" type="text/javascript"></script>
    <script src="iotap_oneclickpdf_XrmSvcToolkit.min.js" type="text/javascript"></script>
    <script src="iotap_oneclickpdf_licenseactivation.js" type="text/javascript"></script>    
    <script>    
        function EnableEventLogging()
        {
            window.GUID = null;
            window.guid = null;

            var isChecked;
            var URL = Xrm.Page.context.getClientUrl();

            if ($('#cbEnableEventLog').is(":checked"))
                isChecked = true;
            else
                isChecked = false;

            var settingsPresent = RetrieveGlobalSettings(URL);

            if (settingsPresent == true)
                UpdateSettingRequest(URL, guid, isChecked);
            else
                CreateSettingRequest(URL, isChecked);
        }

        function UpdateSettingRequest(URL, GUID, isChecked)
        {
            var updateRequest = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">' +
                                '<s:Body>' +
                                '<Update xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">' +
                                '<entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">' +
                                '<a:Attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">' +
                                '<a:KeyValuePairOfstringanyType>' +
                                '<b:key>iotap_enablelogging</b:key>' +
                                '<b:value i:type="c:boolean" xmlns:c="http://www.w3.org/2001/XMLSchema">' + isChecked + '</b:value>' +
                                '</a:KeyValuePairOfstringanyType>' +
                                '</a:Attributes>' +
                                '<a:EntityState i:nil="true" />' +
                                '<a:FormattedValues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />' +
                                '<a:Id>' + GUID + '</a:Id>' +
                                '<a:LogicalName>iotap_globalsettings</a:LogicalName>' +
                                '<a:RelatedEntities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />' +
                                '</entity>' +
                                '</Update>' +
                                '</s:Body>' +
                                '</s:Envelope>';

            var xmlhttpUpdateRequest;
            if (navigator.appName == "Microsoft Internet Explorer")
                xmlhttpUpdateRequest = new ActiveXObject("Microsoft.XMLHTTP");
            else
                xmlhttpUpdateRequest = new XMLHttpRequest();

            xmlhttpUpdateRequest.open("POST", URL + "/XRMServices/2011/Organization.svc/web", false);
            xmlhttpUpdateRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            xmlhttpUpdateRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Update");
            xmlhttpUpdateRequest.send(updateRequest);

            if (xmlhttpUpdateRequest.status == 200)
                alert("Settings Updated");
        }

        function CreateSettingRequest(URL, isChecked)
        {
            var createRequest = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">' +
                            '<s:Body>' +
                            '<Create xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">' +
                            '<entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">' +
                            '<a:Attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">' +
                            '<a:KeyValuePairOfstringanyType>' +
                            '<b:key>iotap_enablelogging</b:key>' +
                            '<b:value i:type="c:boolean" xmlns:c="http://www.w3.org/2001/XMLSchema">' + isChecked + '</b:value>' +
                            '</a:KeyValuePairOfstringanyType>' +
                            '</a:Attributes>' +
                            '<a:EntityState i:nil="true" />' +
                            '<a:FormattedValues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />' +
                            '<a:Id>00000000-0000-0000-0000-000000000000</a:Id>' +
                            '<a:LogicalName>iotap_globalsettings</a:LogicalName>' +
                            '<a:RelatedEntities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />' +
                            '</entity>' +
                            '</Create>' +
                            '</s:Body>' +
                            '</s:Envelope>';

            var xmlhttpCreateRequest;
            if (navigator.appName == "Microsoft Internet Explorer")
                xmlhttpCreateRequest = new ActiveXObject("Microsoft.XMLHTTP");
            else
                xmlhttpCreateRequest = new XMLHttpRequest();

            xmlhttpCreateRequest.open("POST", URL + "/XRMServices/2011/Organization.svc/web", false);
            xmlhttpCreateRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            xmlhttpCreateRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Create");
            xmlhttpCreateRequest.send(createRequest);

            if (xmlhttpCreateRequest.status == 200)
                alert("Settings Created");

            var response = xmlhttpCreateRequest.responseText || xmlhttpCreateRequest.responseXML || xmlhttpCreateRequest.response;

            var ResultXml = response;
            try {
                xmlDoc = $.parseXML(ResultXml);
            }
            catch (E) {
                alert(error_Xml);
                return;
            }
            $xml = $(xmlDoc);
            GUID = $xml.find("CreateResult")[0].textContent || $xml.find("CreateResult")[0].text || $xml.find("CreateResult")[0].innerHTML;

            UpdateGUID(URL, GUID);
        }

        function UpdateGUID(URL, GUID)
        {
            var updateGuidRequest = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">' +
                                    '<s:Body>' +
                                    '<Update xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">' +
                                    '<entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">' +
                                    '<a:Attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">' +
                                    '<a:KeyValuePairOfstringanyType>' +
                                    '<b:key>iotap_guid</b:key>' +
                                    '<b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">' + GUID + '</b:value>' +
                                    '</a:KeyValuePairOfstringanyType>' +
                                    '</a:Attributes>' +
                                    '<a:EntityState i:nil="true" />' +
                                    '<a:FormattedValues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />' +
                                    '<a:Id>' + GUID + '</a:Id>' +
                                    '<a:LogicalName>iotap_globalsettings</a:LogicalName>' +
                                    '<a:RelatedEntities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />' +
                                    '</entity>' +
                                    '</Update>' +
                                    '</s:Body>' + 
                                    '</s:Envelope>';

            var xmlhttpGuidUpdateRequest;
            if (navigator.appName == "Microsoft Internet Explorer")
                xmlhttpGuidUpdateRequest = new ActiveXObject("Microsoft.XMLHTTP");
            else
                xmlhttpGuidUpdateRequest = new XMLHttpRequest();

            xmlhttpGuidUpdateRequest.open("POST", URL + "/XRMServices/2011/Organization.svc/web", false);
            xmlhttpGuidUpdateRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            xmlhttpGuidUpdateRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Update");
            xmlhttpGuidUpdateRequest.send(updateGuidRequest);
        }

        function RetrieveGlobalSettings(URL) {
            var retrieveRequest = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">' +
                                    '<s:Body>' +
                                    '<RetrieveMultiple xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">' +
                                    '<query i:type="a:QueryExpression" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">' +
                                    '<a:ColumnSet>' +
                                    '<a:AllColumns>true</a:AllColumns>' +
                                    '<a:Columns xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />' +
                                    '</a:ColumnSet>' +
                                    '<a:Criteria>' +
                                    '<a:Conditions />' +
                                    '<a:FilterOperator>And</a:FilterOperator>' +
                                    '<a:Filters />' +
                                    '</a:Criteria>' +
                                    '<a:Distinct>false</a:Distinct>' +
                                    '<a:EntityName>iotap_globalsettings</a:EntityName>' +
                                    '<a:LinkEntities />' +
                                    '<a:Orders />' +
                                    '<a:PageInfo>' +
                                    '<a:Count>1</a:Count>' +
                                    '<a:PageNumber>1</a:PageNumber>' +
                                    '<a:PagingCookie i:nil="true" />' +
                                    '<a:ReturnTotalRecordCount>true</a:ReturnTotalRecordCount>' +
                                    '</a:PageInfo>' +
                                    '<a:NoLock>false</a:NoLock>' +
                                    '</query>' +
                                    '</RetrieveMultiple>' +
                                  '</s:Body>' +
                                '</s:Envelope>';

            var xmlhttpRetrieveRequest;
            if (navigator.appName == "Microsoft Internet Explorer")
                xmlhttpRetrieveRequest = new ActiveXObject("Microsoft.XMLHTTP");
            else
                xmlhttpRetrieveRequest = new XMLHttpRequest();

            xmlhttpRetrieveRequest.open("POST", URL + "/XRMServices/2011/Organization.svc/web", false);
            xmlhttpRetrieveRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            xmlhttpRetrieveRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/RetrieveMultiple");
            xmlhttpRetrieveRequest.send(retrieveRequest);

            var response = xmlhttpRetrieveRequest.responseText || xmlhttpRetrieveRequest.responseXML || xmlhttpRetrieveRequest.response;

            var ResultXml = response;
            try {
                xmlDoc = $.parseXML(ResultXml);
            }
            catch (E) {
                alert(error_Xml);
                return;
            }
            $xml = $(xmlDoc);

            var totalRecordCount = $xml.find("TotalRecordCount, a\\:TotalRecordCount")[0].textContent || $xml.find("TotalRecordCount, a:\\TotalRecordCount")[0].text || $xml.find("TotalRecordCount, a:\\TotalRecordCount")[0].innerHTML;
            if (totalRecordCount > 0) {
                var XMLEntityNodes = $xml.find("RetrieveMultipleResult").find("Entity, a\\:Entity");
                var KVPSanytype = XMLEntityNodes.find("KeyValuePairOfstringanyType, a\\:KeyValuePairOfstringanyType");
                for (var j = 0; j < KVPSanytype.length; j++) {
                    if ($(KVPSanytype[j]).find("key, b\\:key")[0].text == "iotap_guid" || $(KVPSanytype[j]).find("key, b\\:key")[0].innerHTML == "iotap_guid" ||
                        $(KVPSanytype[j]).find("key, b\\:key")[0].textContent == "iotap_guid") {
                        guid = $(KVPSanytype[j]).find("value, b\\:value")[0].text || $(KVPSanytype[j]).find("value, b\\:value")[0].innerHTML ||
                            $(KVPSanytype[j]).find("value, b\\:value")[0].textContent;
                    }
                }
            }
            if (totalRecordCount > 0)
                return true;
            else
                return false;
        }
        </script>
    <link href="iotap_oneclickpdf_license.css" rel="Stylesheet" type="text/css">    
    <style type="text/css">
        #txtSerialNo {
            width: 362px;
        }
    </style>



 <div id="min-container">
<div id="header">
    <!--iotap_e2cm_logo.png-->
<img id="logo" style="float: left;" src="">
<table style="width: 50%; padding-top: 5px; font-size: 16px; float: right;">
<tbody><tr>
<td style="width: 16%;">Status</td><td style="width: 16%;">Expires</td><td style="width: 16%;">Version</td>
</tr>
<tr>
<td id="tdhead"><span id="lblActivationType">Unregistered</span></td><td id="td1"><span id="lblExpiry"></span></td><td id="td2"><span id="lblVersion"></span><span id="lblNewVersion"></span></td>
</tr>
<tr>
<!--<td style="width:16%;"></td><td></td><td id="tdCheckUpdates"><a id="btnCheckUpdates" href="#">Download Updates</a></td>-->
</tr>
</tbody></table>
</div>

<div id="wrapper">
	<div id="tab-box">
		<div id="nav">
			<ul id="main-nav">                
				<li class="selected"><a class="deActivatedLink" id="lblAutoActivationLink" href="#lblAutoActivationControls">Profile</a></li>
				<li><a class="deActivatedLink" id="lblManualActivationLink" href="#lblManualActivationControls">License</a></li>
				<li><a class="deActivatedLink" id="lblSettingsControlsLink" href="#lblSettingsControls">Settings</a></li>
                <li><a class="deActivatedLink" id="lblHelpControlsLink" href="#lblHelpControls">Help</a></li>
			</ul>
		</div>
	</div>
	<div style="clear: both;"></div>
	<div class="messages" id="messages">	
	<p><span id="infomsg"><img width="16" height="16" id="info" src="iotap_oneclickpdf_infomsg"> Please register to enable add-on</span></p>
     <p><span id="lblSaveMessage"></span></p>
     <p><span id="lblErrorMessage"></span></p>
	 </div>
    <!-- <p><span id="lblSaveMessage" ></span></p>-->
	<div class="sub-container" id="lblAutoActivationControls">
		<table style="width: 100%;" border="0" cellspacing="4" cellpadding="4">
        <tbody><tr>
            <td width="20%"><span class="fieldCaption" id="lblSerialNo">Serial No:</span></td>
            <td width="40%">
                <input name="txtSerialNo" disabled="" id="txtSerialNo" onfocus="if (this.value == '[AUTO-GENERATED]') {this.value = '';}" onblur="if (this.value == '') {this.value = '[AUTO-GENERATED]';}" type="text" value="[AUTO-GENERATED]">
            </td>
        </tr>
        <tr>
            <td width="20%"><span class="fieldCaption" id="lblOrgName">Organization Name</span></td>
            <td width="40%"><input name="txtOrgName" id="txtOrgName" type="text" readonly="true"> </td>
        </tr>
        <tr>
            <td width="20%"><span class="fieldCaption" id="lblActualUserCount">Actual User Count</span></td>
            <td width="40%"><input name="txtActualUserCount" id="txtActualUserCount" type="text" readonly="true"> </td>
        </tr>
        <tr>
            <td width="20%"><span class="fieldCaption" id="lblEnvironmentType">Environment Type</span><span class="required" id="reqEnvType"> *</span></td>
            <td width="40%">
                <select name="drpEnvironmentType" class="dropdown" id="drpEnvironmentType">
                    <option value="0"></option>
                    <option value="1">Development</option>
                    <option value="2">UAT</option>
                    <option value="3">Production</option>
                </select>
            </td>
        </tr>
        <tr>
            <td width="20%"><span class="fieldCaption" id="lblVersionType">CRM Version</span><span class="required" id="reqVerType"> *</span></td>
            <td width="40%">
                <select name="drpVersionType" class="dropdown" id="drpVersionType">
                    <option value="0"></option>
                    <option value="1">2011</option>
                    <option value="2">2013</option>
                    <option value="3">2015</option>
                </select>
            </td>
        </tr>
        <tr>
            <td width="20%"><span class="fieldCaption" id="lblDeploymentType">Deployment Type</span><span class="required" id="reqDeploymentType"> *</span></td>
            <td width="40%">
                <select name="drpDeploymentType" class="dropdown" id="drpDeploymentType">
                    <option value="0"></option>
                    <option value="1">OnPremise</option>
                    <option value="2">OnLine</option>
                </select>
            </td>
            </tr>
            <tr>
                <td colspan="2">&nbsp;</td>            
            </tr>
            <tr>
                <td width="20%"><span class="fieldCaption" id="lblFirstName">First Name</span><span class="required" id="reqlblFirstName"> *</span></td>
                <td width="40%"><input name="txtFirstName" class="textBox" id="txtFirstName" type="text"> </td>
            </tr>
            <tr>
                <td width="20%"><span class="fieldCaption" id="lblLastName">Last Name</span><span class="required" id="reqLastName"> *</span></td>
                <td width="40%"><input name="txtLastName" class="textBox" id="txtLastName" type="text"> </td>
            </tr>
            <tr>
                <td width="20%"><span class="fieldCaption" id="lblCompany">Company</span><span class="required" id="reqCompany"> *</span></td>
                <td width="40%"><input name="txtCompany" class="textBox" id="txtCompany" type="text"> </td>
            </tr>
            <tr>
                <td width="20%"><span class="fieldCaption" id="lblJobTitle">Job Title</span><span class="required" id="reqJobTitle"> *</span></td>
                <td width="40%"><input name="txtJobTitle" class="textBox" id="txtJobTitle" type="text"> </td>
            </tr>
            <tr>
                <td width="20%"><span class="fieldCaption" id="lblBusinessPhone">Business Phone</span><span class="required" id="reqBusinessPhone"> *</span></td>
                <td width="40%"><input name="txtBusinessPhone" class="textBox" id="txtBusinessPhone" type="text" maxlength="20"> </td>
            </tr>
            <tr>
                <td width="20%"><span class="fieldCaption" id="lblMobilePhone">Mobile Phone</span></td>
                <td width="40%"><input name="txtMobilePhone" class="textBox" id="txtMobilePhone" type="text" maxlength="20"> </td>
            </tr>
            <tr>
                <td width="20%"><span class="fieldCaption" id="lblEmail">Email</span><span class="required" id="reqEmail"> *</span></td>
                <td width="40%"><input name="txtEmail" class="textBox" id="txtEmail" type="text"> </td>
            </tr>
            <tr>
                <td width="20%"><span class="fieldCaption" id="lblWebsite">Website</span><span class="required" id="reqWebsite"> *</span></td>
                <td width="40%"><input name="txtWebsite" class="textBox" id="txtWebsite" type="text"> </td>
            </tr>
             <tr>
                <td width="20%"><span class="fieldCaption" id="lblEndDate">Activation End Date</span></td>
                <td width="40%"><input name="txtEndDate" class="textBox" id="txtEndDate" type="text" readonly="true"> </td>
            </tr>
             <tr>
                <td width="20%"><span class="fieldCaption" id="lblDaysLeft">Activation Days Left</span></td>
                <td width="40%"><input name="txtEndDate" class="textBox" id="txtDaysLeft" type="text" readonly="true"> </td>
            </tr>                        
             <tr id="trEULA">
                <td></td>
                <td id="tdEulaAgreement">I accept the licensing terms and conditions (Click <a id="btnEulaAgreement" href="#" target="_blank">here</a> to read the EULA)<input id="chkEula" type="checkbox"></td>
            </tr>        
            <tr>
                <td align="left"><input name="btnSaveTrial" class="button" id="btnSaveTrial" type="button" value="Submit"><input name="btnUpdateProfile" class="button" id="btnUpdateProfile" type="button" value="Update Profile"></td>
                <td id="tdPrivacyPolicy"><a id="btnPrivacyPolicy" href="#" target="_blank">Privacy Policy</a></td>
            </tr>

        </tbody></table>
	</div>
    <div class="sub-container" id="lblManualActivationControls">
         <table style="width: 100%;" border="0" cellspacing="4" cellpadding="4">
			<tbody><tr>
				<td width="100%" class="heading" valign="top">Online Activation
				</td>	
			</tr>
			<tr>
				<td width="100%" class="heading" valign="top"><input name="btnRefreshLicense" class="button" id="btnRefreshLicense" type="button" value="Refresh License">
				</td>	
			</tr>
			<tr>
				<td width="100%" class="heading" valign="top">Manual Activation
				</td>	
			</tr>
			<tr>
				<td width="100%" valign="top">
					<textarea name="txtLicense" class="textarea" id="txtLicense" readonly="readonly"></textarea>
					<br>
					<span class="textarea" id="lblInstruction">(Please paste license in above textbox)</span>
				</td>
                </tr>
            <tr>
				<td>
					<input name="btnSave" class="button" id="btnSave" type="button" value="Edit"> &nbsp;&nbsp;
				</td>
			</tr>
		</tbody></table>
		
     </div>
    <div class="sub-container_Iframe" id="lblSettingsControls">
        <!--<iframe id="iframe" src="" style="width: 100%; height: 550px;"></iframe>-->
        <table style="width: 100%;" border="0" cellspacing="4" cellpadding="4">
			<tbody>
                <tr>
				    <td>
                        <label><input type="checkbox" id="cbEnableEventLog"/>Enable Event Logging</label>
                    </td>
			    </tr>
                <tr>
                    <td width="100%" class="heading" valign="top">
                    <input type="button" value="Save" onclick="EnableEventLogging()" />
                    </td>
                </tr>
                </tbody>
            </table>
    </div>
    <div class="sub-container" id="lblHelpActivationControls">
        <br>
        <fieldset>
        <legend><font size="3">Getting Started</font></legend>
        <table style="width: 100%;" border="0" cellspacing="4" cellpadding="4">
            <tbody><tr>
                <td id="tdGettingStarted">
                    <textarea name="txtGettingStarted" class="textarea" id="txtGettingStarted" readonly="readonly"></textarea>
                </td>
            </tr>
        </tbody></table>
        </fieldset>
        <fieldset>
        <legend><font size="3"> Useful Links </font></legend>
        <table style="width: 100%;" border="0" cellspacing="4" cellpadding="4">
            <tbody><tr>
                <td id="tdUsefulLinks">
                    <div id="divUserGuide"><a id="btnUserGuide" href="#" target="_blank">User Guide</a></div><br>
                    <div id="divProductDetails"><a id="btnProductDetails" href="#" target="_blank">Product Details</a></div><br>
                    <div id="divBuyNow"><a id="btnBuyNow" href="#" target="_blank">Buy Now</a></div><br>
                    <!--<div id="divDownloads"><a id="btnDownloads" href="#" target="_blank">Downloads</a></div><br />-->
                    <div id="divReleaseNotes"><a id="btnReleaseNotes" href="#" target="_blank">Release Notes and Downloads</a></div><br>
                    <div id="divUserGroup"><a id="btnUserGroup" href="#" target="_blank">Join our CRM Add-ons User group (Stay up-to date, Share your feedback and Get quick support!)</a></div><br>
                </td>
            </tr>
        </tbody></table>
        </fieldset>
    </div>
    <p id="footerMsg">Need help? Please email <a href="mailto:support@iotap.com?subject=Support.">support@iotap.com</a> for any queries.</p>
 </div>
     </div>
 <!-- try putting loading in here-->
 <div id="divLoading" style="background: rgba(255, 255, 255, 0.5); top: 0px; width: 100%; height: 100%; display: none; position: fixed;">
     <table style="width: 100%; height: 100%;">
         <tbody><tr>
             <td align="center" style="vertical-align: middle;">
             <img id="loading" alt="" src="">
             <br><label id="lblStatus">Please wait.... </label>
             </td>
         </tr>
     </tbody></table>
 </div>


</body></html>