| 99 | rodolico | 1 | /* this is only for upgrades */
 | 
        
           |  |  | 2 | create or replace table temp as select * from attrib;
 | 
        
           |  |  | 3 | /* end start upgrades */
 | 
        
           |  |  | 4 |   | 
        
           | 101 | rodolico | 5 | create or replace table attrib (
 | 
        
           | 99 | rodolico | 6 |   attrib_id       int(10) unsigned NOT NULL auto_increment,
 | 
        
           |  |  | 7 |   attrib_category_id int unsigned default 1 references attrib_category( attrib_category_id ),
 | 
        
           |  |  | 8 |   name            varchar(64) not null unique COMMENT 'the visible displayed name',
 | 
        
           | 101 | rodolico | 9 |   added_date      date not null COMMENT 'date record was added',
 | 
        
           | 102 | rodolico | 10 |   multiples       char(1) default null comment 'set to true if ultiple entries are allowed',
 | 
        
           | 101 | rodolico | 11 |   removed_date    date default NULL COMMENT 'date record was deleted or supserceded',
 | 
        
           |  |  | 12 |   keyname         varchar(32) comment 'used for sysinfo really needs to be separate table',
 | 
        
           | 99 | rodolico | 13 |   PRIMARY KEY     (attrib_id)
 | 
        
           | 101 | rodolico | 14 | ) comment 'attributes that can be applied to a device';
 | 
        
           | 99 | rodolico | 15 |   | 
        
           | 101 | rodolico | 16 | create  or replace table attrib_category (
 | 
        
           |  |  | 17 |    attrib_category_id int unsigned not null auto_increment,
 | 
        
           |  |  | 18 |    name           varchar(64),
 | 
        
           |  |  | 19 |    added_date     date not null comment 'When this category was added',
 | 
        
           |  |  | 20 |    primary key    (attrib_category_id)
 | 
        
           |  |  | 21 | ) comment 'just allows us to categorize attributes';
 | 
        
           |  |  | 22 |   | 
        
           |  |  | 23 | CREATE  or replace TABLE attrib_device (
 | 
        
           | 99 | rodolico | 24 |   attrib_device_id int unsigned not null auto_increment,
 | 
        
           |  |  | 25 |   device_id       int(10) unsigned NOT NULL REFERENCES device(device_id),
 | 
        
           |  |  | 26 |   attrib_id       int(10) unsigned NOT NULL REFERENCES attrib(attrib_id),
 | 
        
           |  |  | 27 |   value           text COMMENT 'The actual value of this attribute.',
 | 
        
           | 101 | rodolico | 28 |   added_date      date NOT NULL COMMENT 'date record was added',
 | 
        
           |  |  | 29 |   removed_date    date default NULL,
 | 
        
           | 99 | rodolico | 30 |   PRIMARY KEY     (attrib_device_id)
 | 
        
           |  |  | 31 | )  COMMENT='links devices and their attributes together';
 | 
        
           |  |  | 32 |   | 
        
           |  |  | 33 | insert into attrib_category values ( 1,'General',now() );
 | 
        
           |  |  | 34 |   | 
        
           |  |  | 35 | /* set up the _system table to plug in the module */
 | 
        
           |  |  | 36 | /* this is required, and officially installs the module */
 | 
        
           |  |  | 37 | insert into _system ( group_name,key_name,theValue,added_date) values ( 'Modules', 'Attributes', 'modules/attributes/', now() );
 | 
        
           |  |  | 38 | /* we will provide data to the main screen via a callback routine. In this case, function view is located in callable.php */
 | 
        
           | 100 | rodolico | 39 | insert into _system( group_name,key_name,theValue,added_date ) values ( 'device view', 'Attributes', 'callable.php:attributeView', now() );
 | 
        
           | 99 | rodolico | 40 |   | 
        
           |  |  | 41 | /* This has a menu entry, so add it */
 | 
        
           |  |  | 42 | /* first, make sure we don't have any danglies */
 | 
        
           |  |  | 43 | /* create three menu options. First one is the main menu option (ie, no parent_id) */
 | 
        
           |  |  | 44 | insert into menu( url, caption, parent_id) values ('/modules/attributes' , 'Attributes', null);
 | 
        
           |  |  | 45 | /* two additional menu options for bulk_load and editing the license_product table */
 | 
        
           |  |  | 46 | insert into menu( url,caption,parent_id) select '/modules/attributes/bulk_load.html','Bulk Load',menu_id from menu where caption = 'Attributes';
 | 
        
           |  |  | 47 | insert into menu( url,caption,parent_id) select '/modules/attributes/dmidecode_load.html','Load dmidecode file',menu_id from menu where caption = 'Attributes';
 | 
        
           |  |  | 48 | insert into menu( url,caption,parent_id) select '/modules/attributes/edit_device_attributes.html','Edit Device',menu_id from menu where caption = 'Attributes';
 | 
        
           |  |  | 49 |   | 
        
           |  |  | 50 | /* give all administrators the new menu */
 | 
        
           |  |  | 51 | insert into login_menu
 | 
        
           |  |  | 52 |    select null,login_id,menu_id
 | 
        
           |  |  | 53 |    from login,menu
 | 
        
           |  |  | 54 |    where 
 | 
        
           |  |  | 55 |       login.removed_date is null
 | 
        
           |  |  | 56 |       and login.where_clause = '1=1'
 | 
        
           |  |  | 57 |       and (
 | 
        
           |  |  | 58 |          menu.caption = 'Attributes'
 | 
        
           |  |  | 59 |          or menu.parent_id = (select menu_id from menu where caption = 'Attributes')
 | 
        
           |  |  | 60 |          )
 | 
        
           |  |  | 61 | ;
 | 
        
           |  |  | 62 |   | 
        
           |  |  | 63 |   | 
        
           |  |  | 64 | /* do this only for upgrades */
 | 
        
           |  |  | 65 | insert into attrib (attrib_id,name,added_date,removed_date,keyname) select * from temp;
 | 
        
           |  |  | 66 | insert into attrib_device select device_attrib_id,device_id,attrib_id,value,added_date,removed_date from device_attrib;
 | 
        
           |  |  | 67 |   | 
        
           | 102 | rodolico | 68 | update attrib set multiples = '1' where name in ( 'Alias','MAC Address','Mass Storage','Memory','Note' );
 | 
        
           |  |  | 69 |   | 
        
           | 99 | rodolico | 70 | drop table temp;
 | 
        
           |  |  | 71 | drop table device_attrib;
 | 
        
           | 102 | rodolico | 72 |   | 
        
           |  |  | 73 | update attrib set name = 'Memory Total' where name = 'Memory';
 | 
        
           |  |  | 74 | update attrib set name = 'CPU Count' where name = 'Number of CPUs';
 | 
        
           |  |  | 75 | update attrib set name = 'CPU Family' where name = 'CPU Type';
 | 
        
           |  |  | 76 | update attrib set name = 'CPU Cores' where name = 'Cores per CPU';
 | 
        
           |  |  | 77 | update attrib set name = 'CPU Version' where name = 'CPU SubType';
 | 
        
           |  |  | 78 |   | 
        
           |  |  | 79 | update attrib set name = 'Firmware Revision' where name = 'Boot ROM Version';
 | 
        
           |  |  | 80 | update report set screen_report = null where name in ( 'Device Attributes', 'Device PCI' );
 | 
        
           |  |  | 81 |   | 
        
           |  |  | 82 | update attrib_device set attrib_id = 5 where attrib_id = 45;
 | 
        
           |  |  | 83 | update attrib set name = 'CPU Manufacturer',multiples=null where attrib_id = 45;
 | 
        
           |  |  | 84 |   | 
        
           |  |  | 85 | update attrib_device 
 | 
        
           |  |  | 86 |    set removed_date = now() 
 | 
        
           |  |  | 87 |    where 
 | 
        
           |  |  | 88 |       attrib_device_id in (
 | 
        
           |  |  | 89 |          select toremove 
 | 
        
           |  |  | 90 |          from 
 | 
        
           |  |  | 91 |             (select 
 | 
        
           |  |  | 92 |                device_id,
 | 
        
           |  |  | 93 |                min(attrib_device_id) toremove, 
 | 
        
           |  |  | 94 |                count(*) 
 | 
        
           |  |  | 95 |             from 
 | 
        
           |  |  | 96 |                attrib_device k
 | 
        
           |  |  | 97 |             where 
 | 
        
           |  |  | 98 |                attrib_id = 5 
 | 
        
           |  |  | 99 |                and removed_date is null 
 | 
        
           |  |  | 100 |                group by device_id 
 | 
        
           |  |  | 101 |                having count(*) > 1) as j
 | 
        
           |  |  | 102 |                );
 | 
        
           |  |  | 103 |   | 
        
           |  |  | 104 |   | 
        
           | 99 | rodolico | 105 | /* end of only for upgrades section */
 |