| 99 | 
           rodolico | 
           1 | 
           /* this is only for upgrades */
  | 
        
        
            | 
            | 
           2 | 
           create or replace table temp as select * from attrib;
  | 
        
        
            | 
            | 
           3 | 
           /* end start upgrades */
  | 
        
        
            | 
            | 
           4 | 
              | 
        
        
            | 
            | 
           5 | 
           /* this contains the attributes we can use information itself */
  | 
        
        
            | 
            | 
           6 | 
           CREATE or replace TABLE attrib (
  | 
        
        
            | 
            | 
           7 | 
             attrib_id       int(10) unsigned NOT NULL auto_increment,
  | 
        
        
            | 
            | 
           8 | 
             attrib_category_id int unsigned default 1 references attrib_category( attrib_category_id ),
  | 
        
        
            | 
            | 
           9 | 
             name            varchar(64) not null unique COMMENT 'the visible displayed name',
  | 
        
        
            | 
            | 
           10 | 
             added_date      datetime not null COMMENT 'date record was added',
  | 
        
        
            | 
            | 
           11 | 
             removed_date    datetime default NULL COMMENT 'date record was deleted/supserceded',
  | 
        
        
            | 
            | 
           12 | 
             keyname         varchar(32) comment 'used for sysinfo, really needs to be separate table',
  | 
        
        
            | 
            | 
           13 | 
             PRIMARY KEY     (attrib_id)
  | 
        
        
            | 
            | 
           14 | 
           )   COMMENT='These are attributes that can be applied to a device';
  | 
        
        
            | 
            | 
           15 | 
              | 
        
        
            | 
            | 
           16 | 
           CREATE or replace TABLE attrib_device (
  | 
        
        
            | 
            | 
           17 | 
             attrib_device_id int unsigned not null auto_increment,
  | 
        
        
            | 
            | 
           18 | 
             device_id       int(10) unsigned NOT NULL REFERENCES device(device_id),
  | 
        
        
            | 
            | 
           19 | 
             attrib_id       int(10) unsigned NOT NULL REFERENCES attrib(attrib_id),
  | 
        
        
            | 
            | 
           20 | 
             value           text COMMENT 'The actual value of this attribute.',
  | 
        
        
            | 
            | 
           21 | 
             added_date      datetime NOT NULL COMMENT 'date record was added',
  | 
        
        
            | 
            | 
           22 | 
             removed_date    datetime default NULL,
  | 
        
        
            | 
            | 
           23 | 
             PRIMARY KEY     (attrib_device_id)
  | 
        
        
            | 
            | 
           24 | 
           )  COMMENT='links devices and their attributes together';
  | 
        
        
            | 
            | 
           25 | 
              | 
        
        
            | 
            | 
           26 | 
           create or replace table attrib_category (
  | 
        
        
            | 
            | 
           27 | 
              attrib_category_id int unsigned not null auto_increment,
  | 
        
        
            | 
            | 
           28 | 
              name           varchar(64),
  | 
        
        
            | 
            | 
           29 | 
              added_date     datetime not null comment 'When this category was added',
  | 
        
        
            | 
            | 
           30 | 
              primary key    (attrib_category_id)
  | 
        
        
            | 
            | 
           31 | 
           ) comment 'just allows us to categorize attributes';
  | 
        
        
            | 
            | 
           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 | 
              | 
        
        
            | 
            | 
           68 | 
           drop table temp;
  | 
        
        
            | 
            | 
           69 | 
           drop table device_attrib;
  | 
        
        
            | 
            | 
           70 | 
           /* end of only for upgrades section */
  |