Version Notes
None
Download this release
Release Info
Developer | Adam Martin |
Extension | Tweakmag_Licensemanager |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses.php +26 -0
- app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Edit.php +48 -0
- app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Edit/Form.php +28 -0
- app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Edit/Tab/General.php +45 -0
- app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Edit/Tabs.php +33 -0
- app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Grid.php +113 -0
- app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Grid/Renderer/Expiry.php +108 -0
- app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Grid/Renderer/Status.php +187 -0
- app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Grid/Renderer/Type.php +38 -0
- app/code/community/Tweakmag/Licensemanager/Helper/Data.php +15 -0
- app/code/community/Tweakmag/Licensemanager/Model/Licenses.php +20 -0
- app/code/community/Tweakmag/Licensemanager/Model/Mysql4/Licenses.php +18 -0
- app/code/community/Tweakmag/Licensemanager/Model/Mysql4/Licenses/Collection.php +31 -0
- app/code/community/Tweakmag/Licensemanager/Model/Status.php +48 -0
- app/code/community/Tweakmag/Licensemanager/Model/Type.php +27 -0
- app/code/community/Tweakmag/Licensemanager/controllers/Adminhtml/LicensesController.php +263 -0
- app/code/community/Tweakmag/Licensemanager/etc/adminhtml.xml +50 -0
- app/code/community/Tweakmag/Licensemanager/etc/config.xml +85 -0
- app/code/community/Tweakmag/Licensemanager/sql/tmlicensemanager_setup/mysql4-install-1.0.0.php +33 -0
- app/design/adminhtml/default/default/layout/tmlicensemanager.xml +19 -0
- app/etc/modules/Tweakmag_Licensemanager.xml +20 -0
- callback.php +165 -0
- package.xml +18 -0
app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Block_Adminhtml_Licenses
|
13 |
+
extends Mage_Adminhtml_Block_Widget_Grid_Container
|
14 |
+
{
|
15 |
+
public function __construct()
|
16 |
+
{
|
17 |
+
|
18 |
+
$this->_controller = 'adminhtml_licenses';
|
19 |
+
$this->_blockGroup = 'tmlicensemanager';
|
20 |
+
$this->_headerText = Mage::helper('tmlicensemanager')->__('License Manager');
|
21 |
+
$this->_addButtonLabel = Mage::helper('tmlicensemanager')->__('Add New License');
|
22 |
+
parent::__construct();
|
23 |
+
|
24 |
+
}
|
25 |
+
|
26 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Edit.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Block_Adminhtml_Licenses_Edit
|
13 |
+
extends Mage_Adminhtml_Block_Widget_Form_Container
|
14 |
+
{
|
15 |
+
public function __construct()
|
16 |
+
{
|
17 |
+
parent::__construct();
|
18 |
+
|
19 |
+
$this->_objectId = 'id';
|
20 |
+
$this->_blockGroup = 'tmlicensemanager';
|
21 |
+
$this->_controller = 'adminhtml_licenses';
|
22 |
+
|
23 |
+
$this->_updateButton('save', 'label', Mage::helper('tmlicensemanager')->__('Save License'));
|
24 |
+
$this->_updateButton('delete', 'label', Mage::helper('tmlicensemanager')->__('Delete License'));
|
25 |
+
|
26 |
+
$this->_addButton('saveandcontinue', array(
|
27 |
+
'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'),
|
28 |
+
'onclick' => 'saveAndContinueEdit()',
|
29 |
+
'class' => 'save',
|
30 |
+
), -100);
|
31 |
+
|
32 |
+
$this->_formScripts[] = "
|
33 |
+
|
34 |
+
function saveAndContinueEdit(){
|
35 |
+
editForm.submit($('edit_form').action+'back/edit/');
|
36 |
+
}
|
37 |
+
";
|
38 |
+
}
|
39 |
+
|
40 |
+
public function getHeaderText()
|
41 |
+
{
|
42 |
+
if( Mage::registry('tmlicensemanager_data') && Mage::registry('tmlicensemanager_data')->getId() ) {
|
43 |
+
return Mage::helper('tmlicensemanager')->__("Edit License '%s'", $this->htmlEscape(Mage::registry('tmlicensemanager_data')->getExtensionName()));
|
44 |
+
} else {
|
45 |
+
return Mage::helper('tmlicensemanager')->__('Add License');
|
46 |
+
}
|
47 |
+
}
|
48 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Edit/Form.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Block_Adminhtml_Licenses_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
|
13 |
+
{
|
14 |
+
protected function _prepareForm()
|
15 |
+
{
|
16 |
+
$form = new Varien_Data_Form(array(
|
17 |
+
'id' => 'edit_form',
|
18 |
+
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
|
19 |
+
'method' => 'post',
|
20 |
+
'enctype' => 'multipart/form-data'
|
21 |
+
)
|
22 |
+
);
|
23 |
+
|
24 |
+
$form->setUseContainer(true);
|
25 |
+
$this->setForm($form);
|
26 |
+
return parent::_prepareForm();
|
27 |
+
}
|
28 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Edit/Tab/General.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Block_Adminhtml_Licenses_Edit_Tab_General extends Mage_Adminhtml_Block_Widget_Form
|
13 |
+
{
|
14 |
+
protected function _prepareForm()
|
15 |
+
{
|
16 |
+
$form = new Varien_Data_Form();
|
17 |
+
$this->setForm($form);
|
18 |
+
$fieldset = $form->addFieldset('tmlicensemanager_form', array('legend'=>Mage::helper('tmlicensemanager')->__('License Details')));
|
19 |
+
|
20 |
+
$fieldset->addField('extension_name', 'text', array(
|
21 |
+
'label' => Mage::helper('tmlicensemanager')->__('Extension Name'),
|
22 |
+
'class' => 'required-entry',
|
23 |
+
'required' => true,
|
24 |
+
'name' => 'extension_name',
|
25 |
+
));
|
26 |
+
|
27 |
+
$fieldset->addField('license_key', 'editor', array(
|
28 |
+
'name' => 'license_key',
|
29 |
+
'label' => Mage::helper('tmlicensemanager')->__('License Key'),
|
30 |
+
'title' => Mage::helper('tmlicensemanager')->__('License Key'),
|
31 |
+
'style' => 'width:300px; height:300px;',
|
32 |
+
'wysiwyg' => false,
|
33 |
+
'required' => false,
|
34 |
+
));
|
35 |
+
|
36 |
+
if ( Mage::getSingleton('adminhtml/session')->getLicensemanagerData() )
|
37 |
+
{
|
38 |
+
$form->setValues(Mage::getSingleton('adminhtml/session')->getTmlicensemanagerData());
|
39 |
+
Mage::getSingleton('adminhtml/session')->setTmlicensemanagerData(null);
|
40 |
+
} elseif ( Mage::registry('tmlicensemanager_data') ) {
|
41 |
+
$form->setValues(Mage::registry('tmlicensemanager_data')->getData());
|
42 |
+
}
|
43 |
+
return parent::_prepareForm();
|
44 |
+
}
|
45 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Edit/Tabs.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Block_Adminhtml_Licenses_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
|
13 |
+
{
|
14 |
+
|
15 |
+
public function __construct()
|
16 |
+
{
|
17 |
+
parent::__construct();
|
18 |
+
$this->setId('tmlicensemanager_tabs');
|
19 |
+
$this->setDestElementId('edit_form');
|
20 |
+
$this->setTitle(Mage::helper('tmlicensemanager')->__('License Overview'));
|
21 |
+
}
|
22 |
+
|
23 |
+
protected function _beforeToHtml()
|
24 |
+
{
|
25 |
+
$this->addTab('form_section', array(
|
26 |
+
'label' => Mage::helper('tmlicensemanager')->__('License Information'),
|
27 |
+
'title' => Mage::helper('tmlicensemanager')->__('License Information'),
|
28 |
+
'content' => $this->getLayout()->createBlock('tmlicensemanager/adminhtml_licenses_edit_tab_general')->toHtml(),
|
29 |
+
));
|
30 |
+
|
31 |
+
return parent::_beforeToHtml();
|
32 |
+
}
|
33 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Grid.php
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Block_Adminhtml_Licenses_Grid extends Mage_Adminhtml_Block_Widget_Grid
|
13 |
+
{
|
14 |
+
|
15 |
+
public function __construct()
|
16 |
+
{
|
17 |
+
parent::__construct();
|
18 |
+
$this->setId('licensesGrid');
|
19 |
+
$this->setDefaultSort('license_id');
|
20 |
+
$this->setDefaultDir('ASC');
|
21 |
+
$this->setSaveParametersInSession(false);
|
22 |
+
}
|
23 |
+
|
24 |
+
protected function _prepareCollection()
|
25 |
+
{
|
26 |
+
$collection = Mage::getModel('tmlicensemanager/licenses')->getCollection();
|
27 |
+
$this->setCollection($collection);
|
28 |
+
return parent::_prepareCollection();
|
29 |
+
}
|
30 |
+
|
31 |
+
protected function _prepareColumns()
|
32 |
+
{
|
33 |
+
$this->addColumn('licensemanager_id', array(
|
34 |
+
'header' => Mage::helper('tmlicensemanager')->__('ID'),
|
35 |
+
'align' =>'right',
|
36 |
+
'width' => '50px',
|
37 |
+
'index' => 'license_id',
|
38 |
+
));
|
39 |
+
|
40 |
+
|
41 |
+
$this->addColumn('status', array(
|
42 |
+
'header' => Mage::helper('tmlicensemanager')->__('License Status'),
|
43 |
+
'align' => 'left',
|
44 |
+
'width' => '150px',
|
45 |
+
'type' => 'options',
|
46 |
+
'index' => 'status',
|
47 |
+
'renderer' => new Tweakmag_Licensemanager_Block_Adminhtml_Licenses_Grid_Renderer_Status(),
|
48 |
+
'options' => Mage::getSingleton('tmlicensemanager/status')->getOptionArray(),
|
49 |
+
));
|
50 |
+
|
51 |
+
$this->addColumn('type', array(
|
52 |
+
'header' => Mage::helper('tmlicensemanager')->__('License Type'),
|
53 |
+
'align' => 'left',
|
54 |
+
'width' => '80px',
|
55 |
+
'type' => 'options',
|
56 |
+
'index' => 'type',
|
57 |
+
'renderer' => new Tweakmag_Licensemanager_Block_Adminhtml_Licenses_Grid_Renderer_Type(),
|
58 |
+
'options' => Mage::getSingleton('tmlicensemanager/type')->getOptionArray(),
|
59 |
+
));
|
60 |
+
|
61 |
+
$this->addColumn('expiry', array(
|
62 |
+
'header' => Mage::helper('tmlicensemanager')->__('Expiry Date'),
|
63 |
+
'align' => 'left',
|
64 |
+
'width' => '150px',
|
65 |
+
'type' => 'datetime',
|
66 |
+
'gmtoffset' => true,
|
67 |
+
'index' => 'expiry_date',
|
68 |
+
'renderer' => new Tweakmag_Licensemanager_Block_Adminhtml_Licenses_Grid_Renderer_Expiry(),
|
69 |
+
));
|
70 |
+
|
71 |
+
$this->addColumn('extension_name', array(
|
72 |
+
'header' => Mage::helper('tmlicensemanager')->__('Extension Name'),
|
73 |
+
'align' =>'left',
|
74 |
+
'index' => 'extension_name',
|
75 |
+
));
|
76 |
+
|
77 |
+
$this->addColumn('action',
|
78 |
+
array(
|
79 |
+
'header' => Mage::helper('tmlicensemanager')->__('Action'),
|
80 |
+
'width' => '100',
|
81 |
+
'type' => 'action',
|
82 |
+
'getter' => 'getId',
|
83 |
+
'actions' => array(
|
84 |
+
array(
|
85 |
+
'caption' => Mage::helper('tmlicensemanager')->__('Edit'),
|
86 |
+
'url' => array('base'=> '*/*/edit'),
|
87 |
+
'field' => 'id'
|
88 |
+
),
|
89 |
+
|
90 |
+
),
|
91 |
+
'filter' => false,
|
92 |
+
'sortable' => false,
|
93 |
+
'index' => 'stores',
|
94 |
+
'is_system' => true,
|
95 |
+
));
|
96 |
+
|
97 |
+
$this->addExportType('*/*/exportCsv', Mage::helper('tmlicensemanager')->__('CSV'));
|
98 |
+
$this->addExportType('*/*/exportXml', Mage::helper('tmlicensemanager')->__('XML'));
|
99 |
+
|
100 |
+
return parent::_prepareColumns();
|
101 |
+
}
|
102 |
+
|
103 |
+
protected function _prepareMassaction()
|
104 |
+
{
|
105 |
+
|
106 |
+
}
|
107 |
+
|
108 |
+
public function getRowUrl($row)
|
109 |
+
{
|
110 |
+
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
|
111 |
+
}
|
112 |
+
|
113 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Grid/Renderer/Expiry.php
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Block_Adminhtml_Licenses_Grid_Renderer_Expiry extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Date
|
13 |
+
{
|
14 |
+
/**
|
15 |
+
* Renders grid column
|
16 |
+
*
|
17 |
+
* @param Varien_Object $row
|
18 |
+
* @return string
|
19 |
+
*/
|
20 |
+
public function render(Varien_Object $row)
|
21 |
+
{
|
22 |
+
$license_id = $row->getId();
|
23 |
+
$licensemanager = Mage::getModel('tmlicensemanager/licenses')->load($license_id);
|
24 |
+
$expdate = $licensemanager->getData('expiry_date');
|
25 |
+
//calculate days to expiry (or days passed)
|
26 |
+
if($expdate){
|
27 |
+
//todays date
|
28 |
+
$todayday = date("j");
|
29 |
+
$todaymonth = date("n");
|
30 |
+
$todayyear = date("Y");
|
31 |
+
$date1 = mktime(0,0,0,$todaymonth,$todayday,$todayyear);
|
32 |
+
|
33 |
+
//expiry date
|
34 |
+
$tmp = explode(" ",$expdate);
|
35 |
+
$t = explode("-",$tmp[0]);
|
36 |
+
$expday = $t[2];
|
37 |
+
$expmonth = $t[1];
|
38 |
+
$expyear = $t[0];
|
39 |
+
$date2 = mktime(0,0,0,$expmonth,$expday,$expyear);
|
40 |
+
|
41 |
+
$seconds = $date2-$date1;
|
42 |
+
$expdays = ceil($seconds/86400);
|
43 |
+
}
|
44 |
+
|
45 |
+
if($expdays<0){
|
46 |
+
$e = "License Expired";
|
47 |
+
}
|
48 |
+
|
49 |
+
$format = $this->_getFormat();
|
50 |
+
if($expdate && empty($e)){
|
51 |
+
try {
|
52 |
+
if($this->getColumn()->getGmtoffset()) {
|
53 |
+
$e = Mage::app()->getLocale()->date($expdate, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format);
|
54 |
+
} else {
|
55 |
+
$e = Mage::getSingleton('core/locale')->date($expdate, Zend_Date::ISO_8601, null, false)->toString($format);
|
56 |
+
}
|
57 |
+
}
|
58 |
+
catch (Exception $e)
|
59 |
+
{
|
60 |
+
if($this->getColumn()->getTimezone()) {
|
61 |
+
$e = Mage::app()->getLocale()->date($expdate, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format);
|
62 |
+
} else {
|
63 |
+
$e = Mage::getSingleton('core/locale')->date($expdate, null, null, false)->toString($format);
|
64 |
+
}
|
65 |
+
}
|
66 |
+
if(empty($expdays)){
|
67 |
+
return $e;
|
68 |
+
} else {
|
69 |
+
if($expdays == 1){
|
70 |
+
return $e." (1 day)";
|
71 |
+
} else {
|
72 |
+
return $e." (".$expdays." days)";
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
}
|
77 |
+
if(empty($e)){
|
78 |
+
return "No Expiry";
|
79 |
+
} else {
|
80 |
+
return $e;
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Retrieve date format
|
86 |
+
*
|
87 |
+
* @return string
|
88 |
+
*/
|
89 |
+
protected function _getFormat()
|
90 |
+
{
|
91 |
+
$format = $this->getColumn()->getFormat();
|
92 |
+
if (!$format) {
|
93 |
+
if (is_null(self::$_format)) {
|
94 |
+
try {
|
95 |
+
self::$_format = Mage::app()->getLocale()->getDateFormat(
|
96 |
+
Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM
|
97 |
+
);
|
98 |
+
}
|
99 |
+
catch (Exception $e) {
|
100 |
+
|
101 |
+
}
|
102 |
+
}
|
103 |
+
$format = self::$_format;
|
104 |
+
}
|
105 |
+
return $format;
|
106 |
+
}
|
107 |
+
|
108 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Grid/Renderer/Status.php
ADDED
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Block_Adminhtml_Licenses_Grid_Renderer_Status extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
|
13 |
+
{
|
14 |
+
/**
|
15 |
+
* Renders grid column for license status
|
16 |
+
* Also, update db here in case anything has changed (i.e new license key)
|
17 |
+
*
|
18 |
+
* @param Varien_Object $row
|
19 |
+
* @return string
|
20 |
+
*/
|
21 |
+
public function render(Varien_Object $row)
|
22 |
+
{
|
23 |
+
//default values for vars
|
24 |
+
$status = $row->getData('status');
|
25 |
+
$type = 2;
|
26 |
+
$typetext = Mage::helper('tmlicensemanager')->__('Trial');
|
27 |
+
$expdays = 0;
|
28 |
+
$expiry = "0000-00-00 00:00:00";
|
29 |
+
|
30 |
+
//get data from row
|
31 |
+
$license_id = $row->getId();
|
32 |
+
$license_key = $row->getData('license_key');
|
33 |
+
$extension_name = $row->getData('extension_name');
|
34 |
+
|
35 |
+
//read parameters from license file
|
36 |
+
if(!empty($license_key)){
|
37 |
+
$temp = explode("\r\n",$license_key);
|
38 |
+
$data = null;
|
39 |
+
foreach($temp as $row){
|
40 |
+
if(strchr($row,":")){
|
41 |
+
$tmp = explode(":",$row);
|
42 |
+
$data[$tmp[0]] = $tmp[1];
|
43 |
+
}
|
44 |
+
}
|
45 |
+
} else {
|
46 |
+
//update status
|
47 |
+
$status = 6;
|
48 |
+
$statustext = Mage::helper('tmlicensemanager')->__('Missing License Key');
|
49 |
+
}
|
50 |
+
|
51 |
+
//convert expiry date to mysql format (2009-02-26 01:17:41)
|
52 |
+
if(!empty($data['Expires'])){
|
53 |
+
$expiry = trim($data['Expires']);
|
54 |
+
$tmp = explode(" ",$expiry);
|
55 |
+
switch ($tmp[1]){
|
56 |
+
case 'Jan':
|
57 |
+
$month = 1;
|
58 |
+
break;
|
59 |
+
case 'Feb':
|
60 |
+
$month = 2;
|
61 |
+
break;
|
62 |
+
case 'Mar':
|
63 |
+
$month = 3;
|
64 |
+
break;
|
65 |
+
case 'Apr':
|
66 |
+
$month = 4;
|
67 |
+
break;
|
68 |
+
case 'May':
|
69 |
+
$month = 5;
|
70 |
+
break;
|
71 |
+
case 'Jun':
|
72 |
+
$month = 6;
|
73 |
+
break;
|
74 |
+
case 'Jul':
|
75 |
+
$month = 7;
|
76 |
+
break;
|
77 |
+
case 'Aug':
|
78 |
+
$month = 8;
|
79 |
+
break;
|
80 |
+
case 'Sep':
|
81 |
+
$month = 9;
|
82 |
+
break;
|
83 |
+
case 'Oct':
|
84 |
+
$month = 10;
|
85 |
+
break;
|
86 |
+
case 'Nov':
|
87 |
+
$month = 11;
|
88 |
+
break;
|
89 |
+
case 'Dec':
|
90 |
+
$month = 12;
|
91 |
+
break;
|
92 |
+
}
|
93 |
+
$expiry = date("Y-m-d H:i:s", mktime(0,0,0,$month,$tmp[0],$tmp[2]));
|
94 |
+
}
|
95 |
+
|
96 |
+
if($expiry){
|
97 |
+
//todays date
|
98 |
+
$todayday = date("j");
|
99 |
+
$todaymonth = date("n");
|
100 |
+
$todayyear = date("Y");
|
101 |
+
$date1 = mktime(0,0,0,$todaymonth,$todayday,$todayyear);
|
102 |
+
|
103 |
+
//expiry date
|
104 |
+
$tmp = explode(" ",$expiry);
|
105 |
+
$t = explode("-",$tmp[0]);
|
106 |
+
$expday = $t[2];
|
107 |
+
$expmonth = $t[1];
|
108 |
+
$expyear = $t[0];
|
109 |
+
$date2 = mktime(0,0,0,$expmonth,$expday,$expyear);
|
110 |
+
|
111 |
+
$seconds = $date2-$date1;
|
112 |
+
$expdays = ceil($seconds/86400);
|
113 |
+
}
|
114 |
+
|
115 |
+
if($expdays<0){
|
116 |
+
if($status != 6){
|
117 |
+
$status = 8;
|
118 |
+
}
|
119 |
+
}
|
120 |
+
|
121 |
+
//get license type
|
122 |
+
if(!empty($data['Type'])){
|
123 |
+
switch(trim($data['Type'])){
|
124 |
+
case 'Unlimited':
|
125 |
+
$type = 0;
|
126 |
+
break;
|
127 |
+
case 'Date Limited':
|
128 |
+
$type = 1;
|
129 |
+
break;
|
130 |
+
case 'Trial':
|
131 |
+
default:
|
132 |
+
$type = 2;
|
133 |
+
break;
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
$data = array(
|
138 |
+
'license_id' => $license_id,
|
139 |
+
'status' => $status,
|
140 |
+
'type' => $type,
|
141 |
+
'expiry_date' => $expiry,
|
142 |
+
);
|
143 |
+
|
144 |
+
$licensemanager = Mage::getModel('tmlicensemanager/licenses')->load($license_id);
|
145 |
+
$licensemanager->setData($data);
|
146 |
+
$licensemanager->save();
|
147 |
+
|
148 |
+
switch($status){
|
149 |
+
case '0':
|
150 |
+
return Mage::helper('tmlicensemanager')->__('Active');
|
151 |
+
break;
|
152 |
+
case '1':
|
153 |
+
return Mage::helper('tmlicensemanager')->__('Corrupt File');
|
154 |
+
break;
|
155 |
+
case '2':
|
156 |
+
return Mage::helper('tmlicensemanager')->__('Expired File');
|
157 |
+
break;
|
158 |
+
case '3':
|
159 |
+
return Mage::helper('tmlicensemanager')->__('No Permissions');
|
160 |
+
break;
|
161 |
+
case '4':
|
162 |
+
return Mage::helper('tmlicensemanager')->__('Clock Skew');
|
163 |
+
break;
|
164 |
+
case '5':
|
165 |
+
return Mage::helper('tmlicensemanager')->__('Untrusted Extension');
|
166 |
+
break;
|
167 |
+
case '6':
|
168 |
+
return Mage::helper('tmlicensemanager')->__('Missing License Key');
|
169 |
+
break;
|
170 |
+
case '7':
|
171 |
+
return Mage::helper('tmlicensemanager')->__('Corrupt License');
|
172 |
+
break;
|
173 |
+
case '8':
|
174 |
+
return Mage::helper('tmlicensemanager')->__('License Expired');
|
175 |
+
break;
|
176 |
+
case '9':
|
177 |
+
return Mage::helper('tmlicensemanager')->__('Invalid Property');
|
178 |
+
break;
|
179 |
+
case '10':
|
180 |
+
return Mage::helper('tmlicensemanager')->__('Header Invalid');
|
181 |
+
break;
|
182 |
+
case '11':
|
183 |
+
return Mage::helper('tmlicensemanager')->__('Invalid Server');
|
184 |
+
break;
|
185 |
+
}
|
186 |
+
}
|
187 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Block/Adminhtml/Licenses/Grid/Renderer/Type.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Block_Adminhtml_Licenses_Grid_Renderer_Type
|
13 |
+
extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
|
14 |
+
{
|
15 |
+
/**
|
16 |
+
* Renders grid column
|
17 |
+
*
|
18 |
+
* @param Varien_Object $row
|
19 |
+
* @return string
|
20 |
+
*/
|
21 |
+
public function render(Varien_Object $row)
|
22 |
+
{
|
23 |
+
$license_id = $row->getId();
|
24 |
+
$licensemanager = Mage::getModel('tmlicensemanager/licenses')->load($license_id);
|
25 |
+
|
26 |
+
switch($licensemanager->getData('type')){
|
27 |
+
case '0':
|
28 |
+
return Mage::helper('tmlicensemanager')->__('Unlimited');
|
29 |
+
break;
|
30 |
+
case '1':
|
31 |
+
return Mage::helper('tmlicensemanager')->__('Date Limited');
|
32 |
+
break;
|
33 |
+
case '2':
|
34 |
+
return Mage::helper('tmlicensemanager')->__('Trial');
|
35 |
+
break;
|
36 |
+
}
|
37 |
+
}
|
38 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Helper/Data.php
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Helper_Data extends Mage_Core_Helper_Abstract {
|
13 |
+
|
14 |
+
|
15 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Model/Licenses.php
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Model_Licenses extends Mage_Core_Model_Abstract
|
13 |
+
{
|
14 |
+
public function _construct()
|
15 |
+
{
|
16 |
+
parent::_construct();
|
17 |
+
$this->_init('tmlicensemanager/licenses','license_id');
|
18 |
+
}
|
19 |
+
|
20 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Model/Mysql4/Licenses.php
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Model_Mysql4_Licenses extends Mage_Core_Model_Mysql4_Abstract
|
13 |
+
{
|
14 |
+
public function _construct()
|
15 |
+
{
|
16 |
+
$this->_init('tmlicensemanager/licenses','license_id');
|
17 |
+
}
|
18 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Model/Mysql4/Licenses/Collection.php
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Model_Mysql4_Licenses_Collection
|
13 |
+
extends Mage_Core_Model_Mysql4_Collection_Abstract
|
14 |
+
|
15 |
+
{
|
16 |
+
/**
|
17 |
+
* Initialize resources
|
18 |
+
*
|
19 |
+
*/
|
20 |
+
public function _construct()
|
21 |
+
{
|
22 |
+
$this->_init('tmlicensemanager/licenses');
|
23 |
+
}
|
24 |
+
|
25 |
+
public function addAttributeToSort($attribute, $dir='asc')
|
26 |
+
{
|
27 |
+
$this->addOrder($attribute, $dir);
|
28 |
+
return $this;
|
29 |
+
}
|
30 |
+
|
31 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Model/Status.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Model_Status extends Varien_Object
|
13 |
+
{
|
14 |
+
const STATUS_ACTIVE = 0;
|
15 |
+
const STATUS_ION_CORRUPT_FILE = 1;
|
16 |
+
const STATUS_ION_EXPIRED_FILE = 2;
|
17 |
+
const STATUS_ION_NO_PERMISSIONS = 3;
|
18 |
+
const STATUS_ION_CLOCK_SKEW = 4;
|
19 |
+
const STATUS_ION_UNTRUSTED_EXTENSION = 5;
|
20 |
+
const STATUS_ION_LICENSE_NOT_FOUND = 6;
|
21 |
+
const STATUS_ION_LICENSE_CORRUPT = 7;
|
22 |
+
const STATUS_ION_LICENSE_EXPIRED = 8;
|
23 |
+
const STATUS_ION_LICENSE_PROPERTY_INVALID = 9;
|
24 |
+
const STATUS_ION_LICENSE_HEADER_INVALID = 10;
|
25 |
+
const STATUS_ION_LICENSE_SERVER_INVALID = 11;
|
26 |
+
const STATUS_ION_UNAUTH_INCLUDING_FILE = 12; //not used for now
|
27 |
+
const STATUS_ION_UNAUTH_INCLUDED_FILE = 13; //not used for now
|
28 |
+
const STATUS_ION_UNAUTH_APPEND_PREPEND_FILE = 14; //not used for now
|
29 |
+
|
30 |
+
|
31 |
+
static public function getOptionArray()
|
32 |
+
{
|
33 |
+
return array(
|
34 |
+
self::STATUS_ACTIVE => Mage::helper('tmlicensemanager')->__('Active'),
|
35 |
+
self::STATUS_ION_CORRUPT_FILE => Mage::helper('tmlicensemanager')->__('Corrupt File'),
|
36 |
+
self::STATUS_ION_EXPIRED_FILE => Mage::helper('tmlicensemanager')->__('Expired File'),
|
37 |
+
self::STATUS_ION_NO_PERMISSIONS => Mage::helper('tmlicensemanager')->__('No Permissions'),
|
38 |
+
self::STATUS_ION_CLOCK_SKEW => Mage::helper('tmlicensemanager')->__('Clock Skew'),
|
39 |
+
self::STATUS_ION_UNTRUSTED_EXTENSION => Mage::helper('tmlicensemanager')->__('Untrusted Extension'),
|
40 |
+
self::STATUS_ION_LICENSE_NOT_FOUND => Mage::helper('tmlicensemanager')->__('Missing License Key'),
|
41 |
+
self::STATUS_ION_LICENSE_CORRUPT => Mage::helper('tmlicensemanager')->__('Corrupt License'),
|
42 |
+
self::STATUS_ION_LICENSE_EXPIRED => Mage::helper('tmlicensemanager')->__('License Expired'),
|
43 |
+
self::STATUS_ION_LICENSE_PROPERTY_INVALID => Mage::helper('tmlicensemanager')->__('Invalid Property'),
|
44 |
+
self::STATUS_ION_LICENSE_HEADER_INVALID => Mage::helper('tmlicensemanager')->__('Header Invalid'),
|
45 |
+
self::STATUS_ION_LICENSE_SERVER_INVALID => Mage::helper('tmlicensemanager')->__('Invalid Server'),
|
46 |
+
);
|
47 |
+
}
|
48 |
+
}
|
app/code/community/Tweakmag/Licensemanager/Model/Type.php
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Model_Type extends Varien_Object
|
13 |
+
{
|
14 |
+
const TYPE_UNLIMITED = 0;
|
15 |
+
const TYPE_DATELIMITED = 1;
|
16 |
+
const TYPE_TRIAL = 2;
|
17 |
+
|
18 |
+
|
19 |
+
static public function getOptionArray()
|
20 |
+
{
|
21 |
+
return array(
|
22 |
+
self::TYPE_UNLIMITED => Mage::helper('tmlicensemanager')->__('Unlimited'),
|
23 |
+
self::TYPE_DATELIMITED => Mage::helper('tmlicensemanager')->__('Date Limited'),
|
24 |
+
self::TYPE_TRIAL => Mage::helper('tmlicensemanager')->__('Trial'),
|
25 |
+
);
|
26 |
+
}
|
27 |
+
}
|
app/code/community/Tweakmag/Licensemanager/controllers/Adminhtml/LicensesController.php
ADDED
@@ -0,0 +1,263 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Tweakmag_Licensemanager_Adminhtml_LicensesController extends Mage_Adminhtml_Controller_Action
|
13 |
+
{
|
14 |
+
|
15 |
+
protected function _initAction() {
|
16 |
+
$this->loadLayout()
|
17 |
+
->_setActiveMenu('tmlicensemanager')
|
18 |
+
->_addBreadcrumb(Mage::helper('tmlicensemanager')->__('License Manager'), Mage::helper('tmlicensemanager')->__('Manage Licenses'));
|
19 |
+
|
20 |
+
return $this;
|
21 |
+
}
|
22 |
+
|
23 |
+
public function indexAction() {
|
24 |
+
$this->_initAction()
|
25 |
+
->renderLayout();
|
26 |
+
}
|
27 |
+
|
28 |
+
public function editAction() {
|
29 |
+
$id = $this->getRequest()->getParam('id');
|
30 |
+
$model = Mage::getModel('tmlicensemanager/licenses')->load($id);
|
31 |
+
|
32 |
+
if ($model->getId() || $id == 0) {
|
33 |
+
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
|
34 |
+
if (!empty($data)) {
|
35 |
+
$model->setData($data);
|
36 |
+
}
|
37 |
+
|
38 |
+
Mage::register('tmlicensemanager_data', $model);
|
39 |
+
|
40 |
+
$this->loadLayout();
|
41 |
+
$this->_setActiveMenu('tmlicensemanager');
|
42 |
+
|
43 |
+
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
|
44 |
+
|
45 |
+
$this->_addContent($this->getLayout()->createBlock('tmlicensemanager/adminhtml_licenses_edit'))
|
46 |
+
->_addLeft($this->getLayout()->createBlock('tmlicensemanager/adminhtml_licenses_edit_tabs'));
|
47 |
+
|
48 |
+
$this->renderLayout();
|
49 |
+
} else {
|
50 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tmlicensemanager')->__('License does not exist'));
|
51 |
+
$this->_redirect('*/*/');
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
public function newAction() {
|
56 |
+
$this->_forward('edit');
|
57 |
+
}
|
58 |
+
|
59 |
+
public function saveAction() {
|
60 |
+
if ($data = $this->getRequest()->getPost()) {
|
61 |
+
|
62 |
+
if(isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
|
63 |
+
try {
|
64 |
+
/* Starting upload */
|
65 |
+
$uploader = new Varien_File_Uploader('filename');
|
66 |
+
|
67 |
+
// Any extention would work
|
68 |
+
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
|
69 |
+
$uploader->setAllowRenameFiles(false);
|
70 |
+
|
71 |
+
// Set the file upload mode
|
72 |
+
// false -> get the file directly in the specified folder
|
73 |
+
// true -> get the file in the product like folders
|
74 |
+
// (file.jpg will go in something like /media/f/i/file.jpg)
|
75 |
+
$uploader->setFilesDispersion(false);
|
76 |
+
|
77 |
+
// We set media as the upload dir
|
78 |
+
$path = Mage::getBaseDir('media') . DS ;
|
79 |
+
$uploader->save($path, $_FILES['filename']['name'] );
|
80 |
+
|
81 |
+
} catch (Exception $e) {
|
82 |
+
|
83 |
+
}
|
84 |
+
|
85 |
+
//this way the name is saved in DB
|
86 |
+
$data['filename'] = $_FILES['filename']['name'];
|
87 |
+
}
|
88 |
+
|
89 |
+
//reset status
|
90 |
+
$data['status'] = 0;
|
91 |
+
|
92 |
+
$model = Mage::getModel('tmlicensemanager/licenses');
|
93 |
+
$model->setData($data)
|
94 |
+
->setId($this->getRequest()->getParam('id'));
|
95 |
+
|
96 |
+
try {
|
97 |
+
if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
|
98 |
+
$model->setCreatedTime(now())
|
99 |
+
->setUpdateTime(now());
|
100 |
+
} else {
|
101 |
+
$model->setUpdateTime(now());
|
102 |
+
}
|
103 |
+
|
104 |
+
$model->save();
|
105 |
+
//create license txt file
|
106 |
+
$txtfile = $data['extension_name'].".txt";
|
107 |
+
$fp = fopen($txtfile, 'w');
|
108 |
+
fwrite($fp, $data['license_key']);
|
109 |
+
fclose($fp);
|
110 |
+
|
111 |
+
//re-enable the module
|
112 |
+
$dir = new DirectoryIterator('app/etc/modules/');
|
113 |
+
$module = strtolower($data['extension_name'].".xml.disabled");
|
114 |
+
foreach($dir as $file){
|
115 |
+
if(!$file->isDot() && $file != ".svn"){
|
116 |
+
if (strtolower($file) == strtolower($module)) {
|
117 |
+
//extension xml found
|
118 |
+
rename("app/etc/modules/".$file,"app/etc/modules/".$data['extension_name'].".xml");
|
119 |
+
}
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
|
124 |
+
if(file_exists('app/etc/modules/Tweakmag_Cartlink.xml.disabled')){
|
125 |
+
rename('app/etc/modules/Tweakmag_Cartlink.xml.disabled','app/etc/modules/Tweakmag_Cartlink.xml');
|
126 |
+
}
|
127 |
+
|
128 |
+
|
129 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('tmlicensemanager')->__('License was successfully saved'));
|
130 |
+
Mage::getSingleton('adminhtml/session')->setFormData(false);
|
131 |
+
|
132 |
+
if ($this->getRequest()->getParam('back')) {
|
133 |
+
$this->_redirect('*/*/edit', array('id' => $model->getId()));
|
134 |
+
return;
|
135 |
+
}
|
136 |
+
$this->_redirect('*/*/');
|
137 |
+
return;
|
138 |
+
} catch (Exception $e) {
|
139 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
140 |
+
Mage::getSingleton('adminhtml/session')->setFormData($data);
|
141 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
142 |
+
return;
|
143 |
+
}
|
144 |
+
}
|
145 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('licensemanager')->__('Unable to find license to save'));
|
146 |
+
$this->_redirect('*/*/');
|
147 |
+
}
|
148 |
+
|
149 |
+
public function deleteAction() {
|
150 |
+
if( $this->getRequest()->getParam('id') > 0 ) {
|
151 |
+
try {
|
152 |
+
$model = Mage::getModel('licensemanager/licensemanager');
|
153 |
+
|
154 |
+
//delete license txt file
|
155 |
+
$tmp = $model->load($this->getRequest()->getParam('id'))->getData('extension_name');
|
156 |
+
$txtfile = $tmp.".txt";
|
157 |
+
if(file_exists($txtfile)){
|
158 |
+
unlink($txtfile);
|
159 |
+
}
|
160 |
+
|
161 |
+
$model->setId($this->getRequest()->getParam('id'))
|
162 |
+
->delete();
|
163 |
+
|
164 |
+
|
165 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('License was successfully deleted'));
|
166 |
+
$this->_redirect('*/*/');
|
167 |
+
} catch (Exception $e) {
|
168 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
169 |
+
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
|
170 |
+
}
|
171 |
+
}
|
172 |
+
$this->_redirect('*/*/');
|
173 |
+
}
|
174 |
+
|
175 |
+
public function massDeleteAction() {
|
176 |
+
$licensemanagerIds = $this->getRequest()->getParam('licensemanager');
|
177 |
+
if(!is_array($licensemanagerIds)) {
|
178 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select license(s)'));
|
179 |
+
} else {
|
180 |
+
try {
|
181 |
+
foreach ($licensemanagerIds as $licensemanagerId) {
|
182 |
+
$licensemanager = Mage::getModel('licensemanager/licensemanager')->load($licensemanagerId);
|
183 |
+
|
184 |
+
//delete license txt file
|
185 |
+
$tmp = $licensemanager->getData('extension_name');
|
186 |
+
$txtfile = $tmp.".txt";
|
187 |
+
if(file_exists($txtfile)){
|
188 |
+
unlink($txtfile);
|
189 |
+
}
|
190 |
+
|
191 |
+
$licensemanager->delete();
|
192 |
+
}
|
193 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(
|
194 |
+
Mage::helper('adminhtml')->__(
|
195 |
+
'Total of %d license(s) were successfully deleted', count($licensemanagerIds)
|
196 |
+
)
|
197 |
+
);
|
198 |
+
} catch (Exception $e) {
|
199 |
+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
200 |
+
}
|
201 |
+
}
|
202 |
+
$this->_redirect('*/*/index');
|
203 |
+
}
|
204 |
+
|
205 |
+
public function massStatusAction()
|
206 |
+
{
|
207 |
+
$licensemanagerIds = $this->getRequest()->getParam('licensemanager');
|
208 |
+
if(!is_array($licensemanagerIds)) {
|
209 |
+
Mage::getSingleton('adminhtml/session')->addError($this->__('Please select license(s)'));
|
210 |
+
} else {
|
211 |
+
try {
|
212 |
+
foreach ($licensemanagerIds as $licensemanagerId) {
|
213 |
+
$licensemanager = Mage::getSingleton('licensemanager/licensemanager')
|
214 |
+
->load($licensemanagerId)
|
215 |
+
->setStatus($this->getRequest()->getParam('status'))
|
216 |
+
->setIsMassupdate(true)
|
217 |
+
->save();
|
218 |
+
}
|
219 |
+
$this->_getSession()->addSuccess(
|
220 |
+
$this->__('Total of %d license(s) were successfully updated', count($licensemanagerIds))
|
221 |
+
);
|
222 |
+
} catch (Exception $e) {
|
223 |
+
$this->_getSession()->addError($e->getMessage());
|
224 |
+
}
|
225 |
+
}
|
226 |
+
$this->_redirect('*/*/index');
|
227 |
+
}
|
228 |
+
|
229 |
+
public function exportCsvAction()
|
230 |
+
{
|
231 |
+
$fileName = 'licensemanager.csv';
|
232 |
+
$content = $this->getLayout()->createBlock('licensemanager/adminhtml_licensemanager_grid')
|
233 |
+
->getCsv();
|
234 |
+
|
235 |
+
$this->_sendUploadResponse($fileName, $content);
|
236 |
+
}
|
237 |
+
|
238 |
+
public function exportXmlAction()
|
239 |
+
{
|
240 |
+
$fileName = 'licensemanager.xml';
|
241 |
+
$content = $this->getLayout()->createBlock('licensemanager/adminhtml_licensemanager_grid')
|
242 |
+
->getXml();
|
243 |
+
|
244 |
+
$this->_sendUploadResponse($fileName, $content);
|
245 |
+
}
|
246 |
+
|
247 |
+
protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
|
248 |
+
{
|
249 |
+
$response = $this->getResponse();
|
250 |
+
$response->setHeader('HTTP/1.1 200 OK','');
|
251 |
+
$response->setHeader('Pragma', 'public', true);
|
252 |
+
$response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
|
253 |
+
$response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
|
254 |
+
$response->setHeader('Last-Modified', date('r'));
|
255 |
+
$response->setHeader('Accept-Ranges', 'bytes');
|
256 |
+
$response->setHeader('Content-Length', strlen($content));
|
257 |
+
$response->setHeader('Content-type', $contentType);
|
258 |
+
$response->setBody($content);
|
259 |
+
$response->sendResponse();
|
260 |
+
die;
|
261 |
+
}
|
262 |
+
|
263 |
+
}
|
app/code/community/Tweakmag/Licensemanager/etc/adminhtml.xml
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Tweakmag License Manager Module
|
5 |
+
*
|
6 |
+
* @category Tweakmag
|
7 |
+
* @package Tweakmag_Licensemanager
|
8 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
9 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
10 |
+
* @license Commercial
|
11 |
+
*/
|
12 |
+
-->
|
13 |
+
<config>
|
14 |
+
<menu>
|
15 |
+
<tmlicensemanager translate="title" module="tmlicensemanager">
|
16 |
+
<title>License Manager</title>
|
17 |
+
<sort_order>60</sort_order>
|
18 |
+
<children>
|
19 |
+
<licenses translate="title" module="tmlicensemanager">
|
20 |
+
<title>Manage Your Licenses</title>
|
21 |
+
<action>tmlicensemanager/adminhtml_licenses</action>
|
22 |
+
</licenses>
|
23 |
+
<addlicense translate="title" module="tmlicensemanager">
|
24 |
+
<title>Add New License</title>
|
25 |
+
<action>tmlicensemanager/adminhtml_licenses/add</action>
|
26 |
+
</addlicense>
|
27 |
+
</children>
|
28 |
+
</tmlicensemanager>
|
29 |
+
</menu>
|
30 |
+
<acl>
|
31 |
+
<resources>
|
32 |
+
<admin>
|
33 |
+
<children>
|
34 |
+
<tmlicensemanager translate="title" module="tmlicensemanager">
|
35 |
+
<title>License Manager</title>
|
36 |
+
<sort_order>60</sort_order>
|
37 |
+
<children>
|
38 |
+
<licenses translate="title">
|
39 |
+
<title>Manage Your Licenses</title>
|
40 |
+
</licenses>
|
41 |
+
<addlicense>
|
42 |
+
<title>Add New License</title>
|
43 |
+
</addlicense>
|
44 |
+
</children>
|
45 |
+
</tmlicensemanager>
|
46 |
+
</children>
|
47 |
+
</admin>
|
48 |
+
</resources>
|
49 |
+
</acl>
|
50 |
+
</config>
|
app/code/community/Tweakmag/Licensemanager/etc/config.xml
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Tweakmag License Manager Module
|
5 |
+
*
|
6 |
+
* @category Tweakmag
|
7 |
+
* @package Tweakmag_Licensemanager
|
8 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
9 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
10 |
+
* @license Commercial
|
11 |
+
*/
|
12 |
+
-->
|
13 |
+
<config>
|
14 |
+
<modules>
|
15 |
+
<Tweakmag_Licensemanager>
|
16 |
+
<version>1.0.0</version>
|
17 |
+
</Tweakmag_Licensemanager>
|
18 |
+
</modules>
|
19 |
+
<adminhtml>
|
20 |
+
<layout>
|
21 |
+
<updates>
|
22 |
+
<tmlicensemanager>
|
23 |
+
<file>tmlicensemanager.xml</file>
|
24 |
+
</tmlicensemanager>
|
25 |
+
</updates>
|
26 |
+
</layout>
|
27 |
+
</adminhtml>
|
28 |
+
<global>
|
29 |
+
<blocks>
|
30 |
+
<tmlicensemanager>
|
31 |
+
<class>Tweakmag_Licensemanager_Block</class>
|
32 |
+
</tmlicensemanager>
|
33 |
+
</blocks>
|
34 |
+
<helpers>
|
35 |
+
<tmlicensemanager>
|
36 |
+
<class>Tweakmag_Licensemanager_Helper</class>
|
37 |
+
</tmlicensemanager>
|
38 |
+
</helpers>
|
39 |
+
<models>
|
40 |
+
<tmlicensemanager>
|
41 |
+
<class>Tweakmag_Licensemanager_Model</class>
|
42 |
+
<resourceModel>tmlicensemanager_mysql4</resourceModel>
|
43 |
+
</tmlicensemanager>
|
44 |
+
<tmlicensemanager_mysql4>
|
45 |
+
<class>Tweakmag_Licensemanager_Model_Mysql4</class>
|
46 |
+
<entities>
|
47 |
+
<licenses>
|
48 |
+
<table>tm_licensemanager_licenses</table>
|
49 |
+
</licenses>
|
50 |
+
</entities>
|
51 |
+
</tmlicensemanager_mysql4>
|
52 |
+
</models>
|
53 |
+
<resources>
|
54 |
+
<tmlicensemanager_setup>
|
55 |
+
<setup>
|
56 |
+
<module>Tweakmag_Licensemanager</module>
|
57 |
+
</setup>
|
58 |
+
<connection>
|
59 |
+
<use>core_setup</use>
|
60 |
+
</connection>
|
61 |
+
</tmlicensemanager_setup>
|
62 |
+
<tmlicensemanager_write>
|
63 |
+
<connection>
|
64 |
+
<use>core_write</use>
|
65 |
+
</connection>
|
66 |
+
</tmlicensemanager_write>
|
67 |
+
<tmlicensemanager_read>
|
68 |
+
<connection>
|
69 |
+
<use>core_read</use>
|
70 |
+
</connection>
|
71 |
+
</tmlicensemanager_read>
|
72 |
+
</resources>
|
73 |
+
</global>
|
74 |
+
<admin>
|
75 |
+
<routers>
|
76 |
+
<tmlicensemanager>
|
77 |
+
<use>admin</use>
|
78 |
+
<args>
|
79 |
+
<module>Tweakmag_Licensemanager</module>
|
80 |
+
<frontName>tmlicensemanager</frontName>
|
81 |
+
</args>
|
82 |
+
</tmlicensemanager>
|
83 |
+
</routers>
|
84 |
+
</admin>
|
85 |
+
</config>
|
app/code/community/Tweakmag/Licensemanager/sql/tmlicensemanager_setup/mysql4-install-1.0.0.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
$installer = $this;
|
13 |
+
|
14 |
+
$installer->startSetup();
|
15 |
+
|
16 |
+
$installer->run("
|
17 |
+
|
18 |
+
DROP TABLE IF EXISTS {$this->getTable('tm_licensemanager_licenses')};
|
19 |
+
CREATE TABLE {$this->getTable('tm_licensemanager_licenses')} (
|
20 |
+
`license_id` int(11) unsigned NOT NULL auto_increment,
|
21 |
+
`extension_name` varchar(255) NOT NULL default '',
|
22 |
+
`license_key` blob NULL default '',
|
23 |
+
`status` smallint(6) NOT NULL default '0',
|
24 |
+
`type` smallint(6) NOT NULL default '0',
|
25 |
+
`expiry_date` datetime NULL,
|
26 |
+
`created_time` datetime NULL,
|
27 |
+
`update_time` datetime NULL,
|
28 |
+
PRIMARY KEY (`license_id`)
|
29 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
30 |
+
|
31 |
+
");
|
32 |
+
|
33 |
+
$installer->endSetup();
|
app/design/adminhtml/default/default/layout/tmlicensemanager.xml
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Tweakmag License Manager Module
|
5 |
+
*
|
6 |
+
* @category Tweakmag
|
7 |
+
* @package Tweakmag_Licensemanager
|
8 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
9 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
10 |
+
* @license Commercial
|
11 |
+
*/
|
12 |
+
-->
|
13 |
+
<layout>
|
14 |
+
<tmlicensemanager_adminhtml_licenses_index>
|
15 |
+
<reference name="content">
|
16 |
+
<block type="tmlicensemanager/adminhtml_licenses" name="tmlicensemanagerlicenses" />
|
17 |
+
</reference>
|
18 |
+
</tmlicensemanager_adminhtml_licenses_index>
|
19 |
+
</layout>
|
app/etc/modules/Tweakmag_Licensemanager.xml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Tweakmag License Manager Module
|
5 |
+
*
|
6 |
+
* @category Tweakmag
|
7 |
+
* @package Tweakmag_Licensemanager
|
8 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
9 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
10 |
+
* @license Commercial
|
11 |
+
*/
|
12 |
+
-->
|
13 |
+
<config>
|
14 |
+
<modules>
|
15 |
+
<Tweakmag_Licensemanager>
|
16 |
+
<active>true</active>
|
17 |
+
<codePool>community</codePool>
|
18 |
+
</Tweakmag_Licensemanager>
|
19 |
+
</modules>
|
20 |
+
</config>
|
callback.php
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tweakmag License Manager Module
|
4 |
+
*
|
5 |
+
* @category Tweakmag
|
6 |
+
* @package Tweakmag_Licensemanager
|
7 |
+
* @copyright Copyright (c) 2011 Tweakmag (http://www.tweakmag.com)
|
8 |
+
* @author Adam Martin (adam.martin@tweakmag.com)
|
9 |
+
* @license Commercial
|
10 |
+
*/
|
11 |
+
|
12 |
+
function ioncube_event_handler($err_code, $params) {
|
13 |
+
|
14 |
+
switch($err_code){
|
15 |
+
case '1':
|
16 |
+
$message = Mage::helper('licensemanager')->__("The file ('%s') is corrupt",$params['current_file']);
|
17 |
+
break;
|
18 |
+
case '2':
|
19 |
+
$message = Mage::helper('licensemanager')->__("The file ('%s') has expired",$params['current_file']);
|
20 |
+
break;
|
21 |
+
case '3':
|
22 |
+
$message = Mage::helper('licensemanager')->__("The file ('%s') has a server restriction and is used on a non-authorised system.",$params['current_file']);
|
23 |
+
break;
|
24 |
+
case '4':
|
25 |
+
$message = Mage::helper('licensemanager')->__("The file ('%s') is used on a system where the clock is set more than 24 hours before the file was encoded.",$params['current_file']);
|
26 |
+
break;
|
27 |
+
case '5':
|
28 |
+
$message = Mage::helper('licensemanager')->__("System has an unrecognised extension installed.");
|
29 |
+
break;
|
30 |
+
case '6':
|
31 |
+
$message = Mage::helper('licensemanager')->__("The License file is missing");
|
32 |
+
writelicense($params);
|
33 |
+
reload();
|
34 |
+
break;
|
35 |
+
case '7':
|
36 |
+
$message = Mage::helper('licensemanager')->__("The license file ('%s') is corrupt",$params['current_file']);
|
37 |
+
break;
|
38 |
+
case '8':
|
39 |
+
$message = Mage::helper('licensemanager')->__("The license file ('%s') has reached its expiry time.",$params['current_file']);
|
40 |
+
break;
|
41 |
+
case '9':
|
42 |
+
$message = Mage::helper('licensemanager')->__("A property marked as 'enforced' in the license file ('%s') was not matched by a property contained in the encoded file.",$params['current_file']);
|
43 |
+
break;
|
44 |
+
case '10':
|
45 |
+
$message = Mage::helper('licensemanager')->__("The header block of the license file ('%s') has been altered.",$params['license_file']);
|
46 |
+
break;
|
47 |
+
case '11':
|
48 |
+
$message = Mage::helper('licensemanager')->__("The license ('%s') is not valid for this server",$params['current_file']);
|
49 |
+
break;
|
50 |
+
case '12':
|
51 |
+
$message = Mage::helper('licensemanager')->__("The encoded file ('%s') has been included by a file which is either unencoded or has incorrect properties.",$params['current_file']);
|
52 |
+
break;
|
53 |
+
case '13':
|
54 |
+
$message = Mage::helper('licensemanager')->__("The encoded file ('%s') has included a file which is either unencoded or has incorrect properties.",$params['current_file']);
|
55 |
+
break;
|
56 |
+
case '14':
|
57 |
+
$message = Mage::helper('licensemanager')->__("The php.ini has either the --auto-append-file or --auto-prepend-file setting enabled.");
|
58 |
+
break;
|
59 |
+
}
|
60 |
+
|
61 |
+
//we only get here if not err_code 6
|
62 |
+
disablemodule($params,$message,$err_code);
|
63 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('licensemanager')->__('Unable to find license to save'));
|
64 |
+
reload(); //echo this out to show error
|
65 |
+
}
|
66 |
+
|
67 |
+
|
68 |
+
function writelicense($params)
|
69 |
+
{
|
70 |
+
|
71 |
+
$resource = Mage::getSingleton('core/resource');
|
72 |
+
$read = $resource->getConnection('core_read');
|
73 |
+
$table = $resource->getTableName('licensemanager');
|
74 |
+
|
75 |
+
$extension = explode(".",$params['license_file']);
|
76 |
+
|
77 |
+
$select = $read->select()
|
78 |
+
->from($table,array('licensemanager_id','extension_name','license_key','status','type'))
|
79 |
+
->where('extension_name=?',$extension[0]);
|
80 |
+
|
81 |
+
$licensemanager = $read->fetchRow($select);
|
82 |
+
$license = $licensemanager['license_key'];
|
83 |
+
|
84 |
+
if(empty($license) || !license){
|
85 |
+
$license = "";
|
86 |
+
}
|
87 |
+
|
88 |
+
//write license file
|
89 |
+
$fp = fopen($params['license_file'], 'w');
|
90 |
+
fwrite($fp, $license);
|
91 |
+
fclose($fp);
|
92 |
+
|
93 |
+
|
94 |
+
}
|
95 |
+
|
96 |
+
function disablemodule($params,$message,$err_code)
|
97 |
+
{
|
98 |
+
//disable module (rename)
|
99 |
+
//this should stop site from breaking
|
100 |
+
//it gets re-enabled from within admin (by saving the license again)
|
101 |
+
//$t = explode("/",$params['license_file']);
|
102 |
+
$t = explode("\\",$params['license_file']);
|
103 |
+
$t = array_reverse($t);
|
104 |
+
$extension = explode(".",$t[0]);
|
105 |
+
$module = strtolower($extension[0].".xml");
|
106 |
+
$dir = new DirectoryIterator('app/etc/modules/');
|
107 |
+
foreach($dir as $file){
|
108 |
+
if(!$file->isDot() && $file != ".svn"){
|
109 |
+
if (strtolower($file) == strtolower($module)) {
|
110 |
+
//extension xml found
|
111 |
+
rename("app/etc/modules/".$file,"app/etc/modules/".$file.".disabled");
|
112 |
+
}
|
113 |
+
}
|
114 |
+
}
|
115 |
+
|
116 |
+
//send notification to site owner
|
117 |
+
$email = Mage::getStoreConfig('trans_email/ident_general/email');
|
118 |
+
$subject = 'Commercial Extension License Error - Code:'.$err_code;
|
119 |
+
$headers = 'From: extensions@tweakmag.com' . "\r\n" .
|
120 |
+
'Reply-To: extensions@tweakmag.com' . "\r\n" .
|
121 |
+
'X-Mailer: PHP/' . phpversion();
|
122 |
+
mail($email, $subject, $message, $headers);
|
123 |
+
|
124 |
+
//update license status in db
|
125 |
+
$resource = Mage::getSingleton('core/resource');
|
126 |
+
$read = $resource->getConnection('core_read');
|
127 |
+
$table = $resource->getTableName('licensemanager');
|
128 |
+
$select = $read->select()
|
129 |
+
->from($table,array('licensemanager_id','extension_name','license_key','status','type'))
|
130 |
+
->where('extension_name=?',$extension[0]);
|
131 |
+
|
132 |
+
$l = $read->fetchRow($select);
|
133 |
+
|
134 |
+
$license_id = $l['licensemanager_id'];
|
135 |
+
$data = array(
|
136 |
+
'licensemanager_id' => $license_id,
|
137 |
+
'status' => $err_code,
|
138 |
+
'extension_name' => (string)$extension[0],
|
139 |
+
'type' => $l['type'],
|
140 |
+
);
|
141 |
+
|
142 |
+
$licensemanager = Mage::getModel('licensemanager/licensemanager')->load($license_id);
|
143 |
+
$licensemanager->setData($data);
|
144 |
+
$licensemanager->save();
|
145 |
+
|
146 |
+
//add message to notification inbox
|
147 |
+
$feedData = array(
|
148 |
+
'severity' => 2,
|
149 |
+
'date_added' => gmdate('Y-m-d H:i:s'),
|
150 |
+
'title' => (string)$subject,
|
151 |
+
'description' => (string)$message,
|
152 |
+
'url' => (string)"http://www.tweakmag.com/magento-training-and-support/licensing/errors",
|
153 |
+
);
|
154 |
+
|
155 |
+
$notification = Mage::getModel('adminnotification/inbox');
|
156 |
+
$notification->setData($feedData);
|
157 |
+
$notification->save($feedData);
|
158 |
+
}
|
159 |
+
|
160 |
+
function reload(){
|
161 |
+
umask(0);
|
162 |
+
Mage::reset();
|
163 |
+
Mage::run();
|
164 |
+
exit;
|
165 |
+
}
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Tweakmag_Licensemanager</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>AFL</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Licensemanager for Ioncube Encoded Extensions</summary>
|
10 |
+
<description>Tweakmag Licensemanager proveds an easy way to manage all your extension licenses for those extensions that you are using that are Ioncube encoded. Rather than displaying Ioncube errors, Tweakmag Licensemanger will disable those modules that have issues (and email the site owner) automatically so that your site continues working*</description>
|
11 |
+
<notes>None</notes>
|
12 |
+
<authors><author><name>Adam Martin</name><user>ajazza</user><email>adam.martin@tweakmag.com</email></author></authors>
|
13 |
+
<date>2011-06-03</date>
|
14 |
+
<time>07:30:49</time>
|
15 |
+
<contents><target name="mageetc"><dir name="modules"><file name="Tweakmag_Licensemanager.xml" hash="de1baa4f0b718ab14b1e924a99d96034"/></dir></target><target name="mageweb"><dir name="."><file name="callback.php" hash="09477f59cac2e4716da6bd33c126c256"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="tmlicensemanager.xml" hash="c9c817031326422accd863f90c4fede8"/></dir></dir></dir></dir></target><target name="magecommunity"><dir name="Tweakmag"><dir name="Licensemanager"><dir name="Block"><dir name="Adminhtml"><dir name="Licenses"><dir name="Edit"><file name="Form.php" hash="ab7098e567313fcf41fc28cc1e18cb48"/><dir name="Tab"><file name="General.php" hash="e367d1334221f369df5430963bd80c6b"/></dir><file name="Tabs.php" hash="45af6be5f59d8b837273b5f1d04a5e90"/></dir><file name="Edit.php" hash="535beed06f4dc06a70f6a2c0cf33ce89"/><dir name="Grid"><dir name="Renderer"><file name="Expiry.php" hash="8f0e0d980ae4c76a036574faa3a4312a"/><file name="Status.php" hash="9643641b9dc66838e4406e9167a40ebd"/><file name="Type.php" hash="02c20086372e826996cffab13f7357ed"/></dir></dir><file name="Grid.php" hash="49e0de9b3c41c56fe31548f6d58eb246"/></dir><file name="Licenses.php" hash="f64ec43b1bedf4b111f29e07c6df9b2f"/></dir></dir><dir name="Helper"><file name="Data.php" hash="09a4f2f7281a0b756b0bcb7d310c4525"/></dir><dir name="Model"><file name="Licenses.php" hash="a0c78b3716da18a28eaeb17ae6701a92"/><dir name="Mysql4"><dir name="Licenses"><file name="Collection.php" hash="0918017379f2a9f3acd4e350bca8dfad"/></dir><file name="Licenses.php" hash="58ebed957e6f41510eac863e5bed0344"/></dir><file name="Status.php" hash="60141d34bdb60e7bbe6d668dbd7b86ea"/><file name="Type.php" hash="fa9c265d23f90345398a27b02294344b"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="LicensesController.php" hash="b0a8cb81d79030566ab00678151a0f4c"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="6775ec09d471addb121189e8c1bdd437"/><file name="config.xml" hash="67cf8931da8db8e91c6ec69f63c2cbfa"/></dir><dir name="sql"><dir name="tmlicensemanager_setup"><file name="mysql4-install-1.0.0.php" hash="142d26dd92483474a9b4e2b15ec304a5"/></dir></dir></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
+
</package>
|