| Line -... | Line 1... | 
          
            | - |   | 1 | /* this contains the license information itself */
 | 
          
            | 1 | drop table if exists license;
 | 2 | drop table if exists license;
 | 
          
            | 2 | create table license (
 | 3 | create table license (
 | 
          
            | 3 |    license_id int unsigned not null auto_increment,
 | 4 |    license_id int unsigned not null auto_increment,
 | 
          
            | 4 |    client_id  int unsigned null comment 'link to client table',
 | 5 |    client_id  int unsigned null comment 'link to client table',
 | 
          
            | 5 |    device_id   int unsigned null comment 'link to device table',
 | 6 |    device_id   int unsigned null comment 'link to device table',
 | 
          
            | Line 7... | Line 8... | 
          
            | 7 |    license_product_id int unsigned not null references license_product(license_product_id),
 | 8 |    license_product_id int unsigned not null references license_product(license_product_id),
 | 
          
            | 8 |    added_date date default null comment 'date the license used on this machine',
 | 9 |    added_date date default null comment 'date the license used on this machine',
 | 
          
            | 9 |    removed_date date default null comment 'date license removed from this machine',
 | 10 |    removed_date date default null comment 'date license removed from this machine',
 | 
          
            | 10 |    primary key (license_id)
 | 11 |    primary key (license_id)
 | 
          
            | 11 | ) comment 'Holds the license and links to machine installed on' ;
 | 12 | ) comment 'Holds the license and links to machine installed on' ;
 | 
          
            | 12 |    
 | 13 |  
 | 
          
            | - |   | 14 | /* child table that contains the "name" of the product, ie Microsoft - Office 2016, etc... */
 | 
          
            | 13 | drop table if exists license_product;
 | 15 | drop table if exists license_product;
 | 
          
            | 14 | create table license_product (
 | 16 | create table license_product (
 | 
          
            | 15 |    license_product_id int unsigned not null auto_increment,
 | 17 |    license_product_id int unsigned not null auto_increment,
 | 
          
            | 16 |    name text comment 'name of the license',
 | 18 |    name text comment 'name of the license',
 | 
          
            | 17 |    primary key ( license_product_id )
 | 19 |    primary key ( license_product_id )
 | 
          
            | 18 | ) comment 'a list of all products we track license for';
 | 20 | ) comment 'a list of all products we track license for';
 | 
          
            | 19 |  
 | 21 |  
 | 
          
            | - |   | 22 | /* set up the _system table to plug in the module */
 | 
          
            | 20 | delete from _system where key_name = 'license';
 | 23 | delete from _system where key_name = 'license';
 | 
          
            | - |   | 24 | /* this is required, and officially installs the module */
 | 
          
            | 21 | insert into _system ( group_name,key_name,theValue,added_date) values ( 'Modules', 'license', 'modules/license/', now() );
 | 25 | insert into _system ( group_name,key_name,theValue,added_date) values ( 'Modules', 'license', 'modules/license/', now() );
 | 
          
            | - |   | 26 | /* we will provide data to the main screen via a callback routine. In this case, function view is located in callable.php */
 | 
          
            | - |   | 27 | insert into _system( group_name,key_name,theValue,added_date ) values ( 'device view', 'license', 'callable.php:view', now() );
 | 
          
            | - |   | 28 |  
 | 
          
            | - |   | 29 | /* This has a menu entry, so add it */
 | 
          
            | - |   | 30 | /* first, make sure we don't have any danglies */
 | 
          
            | 22 | delete from menu 
 | 31 | delete from menu 
 | 
          
            | 23 | where 
 | 32 | where 
 | 
          
            | 24 |    menu.parent_id in 
 | 33 |    menu.parent_id in 
 | 
          
            | 25 |       ( select menu_id 
 | 34 |       ( select menu_id 
 | 
          
            | 26 |         from ( 
 | 35 |         from ( 
 | 
          
            | Line 28... | Line 37... | 
          
            | 28 |            from menu a join menu b on a.menu_id = b.menu_id 
 | 37 |            from menu a join menu b on a.menu_id = b.menu_id 
 | 
          
            | 29 |            where a.caption = 'Licenses' 
 | 38 |            where a.caption = 'Licenses' 
 | 
          
            | 30 |            ) 
 | 39 |            ) 
 | 
          
            | 31 |       as c );
 | 40 |       as c );
 | 
          
            | 32 | delete from menu where caption = 'Licenses';
 | 41 | delete from menu where caption = 'Licenses';
 | 
          
            | - |   | 42 | /* create three menu options. First one is the main menu option (ie, no parent_id) */
 | 
          
            | 33 | insert into menu( url, caption, parent_id) values ('/modules/license/', 'Licenses', null);
 | 43 | insert into menu( url, caption, parent_id) values ('/modules/license/', 'Licenses', null);
 | 
          
            | - |   | 44 | /* two additional menu options for bulk_load and editing the license_product table */
 | 
          
            | 34 | insert into menu( url,caption,parent_id) select '/modules/license/bulk_load.html','Bulk Load',menu_id from menu where caption = 'Licenses';
 | 45 | insert into menu( url,caption,parent_id) select '/modules/license/bulk_load.html','Bulk Load',menu_id from menu where caption = 'Licenses';
 | 
          
            | 35 | insert into menu( url,caption,parent_id) select '/modules/license/edit_license_product.html','Edit Products',menu_id from menu where caption = 'Licenses';
 | 46 | insert into menu( url,caption,parent_id) select '/modules/license/edit_license_product.html','Edit Products',menu_id from menu where caption = 'Licenses';
 | 
          
            | 36 |  
 | 47 |  
 | 
          
            | 37 | create or replace view view_device_systems as select * from device where device_type_id in (select device_type_id from device_type where show_as_system = 'Y');
 | - |   | 
          
            | 38 |  
 | - |   | 
          
            | 39 | insert into _system( group_name,key_name,theValue,added_date ) values ( 'device view', 'license', 'callable.php:view', now() );
 | - |   | 
          
            | 40 |  
 | - |   | 
          
            | 41 |  
 | - |   | 
          
            | 42 |  
 | - |   | 
          
            | 43 | /* DO NOT RUN BELOW THIS LINE */
 | - |   | 
          
            | 44 |  
 | - |   | 
          
            | 45 | select 
 | - |   | 
          
            | 46 |    license_product.name 'Product',
 | - |   | 
          
            | 47 |    license.license 'License',
 | - |   | 
          
            | 48 |    ifnull(device.name,'--- Available ---') 'Installed On',
 | - |   | 
          
            | 49 |    client.name 'Client'
 | - |   | 
          
            | 50 | from
 | - |   | 
          
            | 51 |    license join license_product using (license_product_id)
 | - |   | 
          
            | 52 |    left outer join device using (device_id)
 | - |   | 
          
            | 53 |    join client using ( client_id )
 | - |   | 
          
            | 54 | order by license_product.name, device.name;
 | - |   | 
          
            | 55 |    
 | - |   |