Changeset 1498 in ExiteCMS for trunk/administration/modules.php


Ignore:
Timestamp:
07/01/08 23:52:31 (4 years ago)
Author:
root
Message:

Added a new reporting core module. Version 7.2 will come with some build in reports, modules can now add their own.
Updated the modules administration module, and added support for pluggable reports and pluggable searches (not implemented yet)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/administration/modules.php

    r1488 r1498  
    171171    // register the installation of this module 
    172172    $result = dbquery("INSERT INTO ".$db_prefix."modules (mod_title, mod_folder, mod_version) VALUES ('$mod_title', '$mod_folder', '$mod_version')"); 
     173    // save the key, we might need it later 
     174    $mod_id = mysql_insert_id(); 
     175 
     176    // if a module is installed, and if reports are defined, install the report links for this module 
     177    if ($mod_id && isset($mod_report_links) && is_array($mod_report_links) && count($mod_report_links)) { 
     178 
     179        // loop through the defined reports 
     180        foreach ($mod_report_links as $mod_report) { 
     181 
     182            // check if the code exists for this report 
     183            if (isset($mod_report['name']) && file_exists(PATH_MODULES.$mod_folder."/report.".$mod_report['name'].".php")) { 
     184                // check if the template exists for this report 
     185                if (file_exists(PATH_MODULES.$mod_folder."/templates/modules.".$mod_folder.".report.".$mod_report['name'].".tpl")) { 
     186                    // verify the other fields 
     187                    $mod_report['visibility'] = (isset($mod_report['visibility']) && isNum($mod_report['visibility']) ? $mod_report['visibility'] : 103); 
     188                    $mod_report['title'] = isset($mod_report['title']) ? $mod_report['title'] : ("Report: ".$mod_report['name']); 
     189                    $mod_report['version'] = isset($mod_report['version']) ? $mod_report['version'] : $mod_version; 
     190                    // add it to the report table 
     191                    $result = dbquery("INSERT INTO ".$db_prefix."reports (report_mod_id, report_name, report_title, report_version, report_visibility)  
     192                        VALUES ('".$mod_id."', '".$mod_report['name']."', '".$mod_report['title']."', '".$mod_report['version']."', '".$mod_report['visibility']."')"); 
     193                } 
     194            } 
     195        } 
     196    } 
     197 
     198    // if a module is installed, and if searches are defined, install the search links for this module 
     199    if ($mod_id && isset($mod_search_links) && is_array($mod_search_links) && count($mod_search_links)) { 
     200 
     201        // loop through the defined reports 
     202        foreach ($mod_search_links as $mod_search) { 
     203 
     204            // check if the code exists for this search 
     205            if (isset($mod_search['name']) && file_exists(PATH_MODULES.$mod_folder."/search.".$mod_search['name'].".php")) { 
     206                // check if the template exists for this search 
     207                if (file_exists(PATH_MODULES.$mod_folder."/templates/modules.".$mod_folder.".search.".$mod_search['name'].".tpl")) { 
     208                    // verify the other fields 
     209                    $mod_search['visibility'] = (isset($mod_search['visibility']) && isNum($mod_search['visibility']) ? $mod_search['visibility'] : 103); 
     210                    $mod_search['title'] = isset($mod_search['title']) ? $mod_search['title'] : ("Search: ".$mod_search['name']); 
     211                    $mod_search['version'] = isset($mod_search['version']) ? $mod_search['version'] : $mod_version; 
     212                    // add it to the search table 
     213                    $result = dbquery("INSERT INTO ".$db_prefix."searches (search_mod_id, search_name, search_title, search_version, search_visibility)  
     214                        VALUES ('".$mod_id."', '".$mod_search['name']."', '".$mod_search['title']."', '".$mod_search['version']."', '".$mod_search['visibility']."')"); 
     215                } 
     216            } 
     217        } 
     218    } 
    173219 
    174220    // update the access rights of the site administrators to include this new module 
     
    303349    // remove the module from the installed modules list 
    304350    $result = dbquery("DELETE FROM ".$db_prefix."modules WHERE mod_id='$id'"); 
     351 
     352    // remove any reports associated with this module 
     353    $result = dbquery("DELETE FROM ".$db_prefix."reports WHERE report_mod_id='$id'"); 
     354 
     355    // remove any searches associated with this module 
     356    $result = dbquery("DELETE FROM ".$db_prefix."searches WHERE search_mod_id='$id'"); 
     357} 
     358 
     359if ($action == 'locales' && isset($id)) { 
     360 
     361    // make sure the ID passed is numeric 
     362    if (!isNum($id)) fallback(FUSION_SELF.$aidlink); 
     363     
     364    // check if it exists 
     365    $result = dbquery("SELECT * FROM ".$db_prefix."modules WHERE mod_id='$id'"); 
     366    if (!$result)  fallback(FUSION_SELF.$aidlink); 
     367 
     368    // get the module data 
     369    $data = dbarray($result); 
     370 
     371    // load the module installer to start the upgrade 
     372    include PATH_MODULES.$data['mod_folder']."/module_installer.php"; 
     373 
     374    // if locale strings are defined, load them into the database 
     375    if (isset($localestrings) && is_array($localestrings)) { 
     376        foreach($localestrings as $locales_code => $locales_strings) { 
     377            load_localestrings($locales_strings, $locales_code, "modules.".$mod_folder); 
     378        } 
     379    } 
     380 
    305381} 
    306382 
     
    419495        foreach($localestrings as $locales_code => $locales_strings) { 
    420496            load_localestrings($locales_strings, $locales_code, "modules.".$mod_folder); 
     497        } 
     498    } 
     499 
     500    // remove any reports associated with this module 
     501    $result = dbquery("DELETE FROM ".$db_prefix."reports WHERE report_mod_id='$id'"); 
     502 
     503    // if a module is installed, and if reports are defined, (re)install the report links for this module 
     504    if (isset($mod_report_links) && is_array($mod_report_links) && count($mod_report_links)) { 
     505 
     506        // loop through the defined reports 
     507        foreach ($mod_report_links as $mod_report) { 
     508 
     509            // check if the code exists for this report 
     510            if (isset($mod_report['name']) && file_exists(PATH_MODULES.$mod_folder."/report.".$mod_report['name'].".php")) { 
     511                // check if the template exists for this report 
     512                if (file_exists(PATH_MODULES.$mod_folder."/templates/modules.".$mod_folder.".report.".$mod_report['name'].".tpl")) { 
     513                    // verify the other fields 
     514                    $mod_report['visibility'] = (isset($mod_report['visibility']) && isNum($mod_report['visibility']) ? $mod_report['visibility'] : 103); 
     515                    $mod_report['title'] = isset($mod_report['title']) ? $mod_report['title'] : ("Report: ".$mod_report['name']); 
     516                    $mod_report['version'] = isset($mod_report['version']) ? $mod_report['version'] : $mod_version; 
     517                    // add it to the report table 
     518                    $result = dbquery("INSERT INTO ".$db_prefix."reports (report_mod_id, report_name, report_title, report_version, report_visibility)  
     519                        VALUES ('".$id."', '".$mod_report['name']."', '".$mod_report['title']."', '".$mod_report['version']."', '".$mod_report['visibility']."')"); 
     520                } 
     521            } 
     522        } 
     523 
     524    } 
     525 
     526    // remove any searches associated with this module 
     527    $result = dbquery("DELETE FROM ".$db_prefix."searches WHERE search_mod_id='$id'"); 
     528 
     529    // if a module is installed, and if searches are defined, install the search links for this module 
     530    if (isset($mod_search_links) && is_array($mod_search_links) && count($mod_search_links)) { 
     531 
     532        // loop through the defined reports 
     533        foreach ($mod_search_links as $mod_search) { 
     534 
     535            // check if the code exists for this search 
     536            if (isset($mod_search['name']) && file_exists(PATH_MODULES.$mod_folder."/search.".$mod_search['name'].".php")) { 
     537                // check if the template exists for this search 
     538                if (file_exists(PATH_MODULES.$mod_folder."/templates/modules.".$mod_folder.".search.".$mod_search['name'].".tpl")) { 
     539                    // verify the other fields 
     540                    $mod_search['visibility'] = (isset($mod_search['visibility']) && isNum($mod_search['visibility']) ? $mod_search['visibility'] : 103); 
     541                    $mod_search['title'] = isset($mod_search['title']) ? $mod_search['title'] : ("Search: ".$mod_search['name']); 
     542                    $mod_search['version'] = isset($mod_search['version']) ? $mod_search['version'] : $mod_version; 
     543                    // add it to the search table 
     544                    $result = dbquery("INSERT INTO ".$db_prefix."searches (search_mod_id, search_name, search_title, search_version, search_visibility)  
     545                        VALUES ('".$id."', '".$mod_search['name']."', '".$mod_search['title']."', '".$mod_search['version']."', '".$mod_search['visibility']."')"); 
     546                } 
     547            } 
    421548        } 
    422549    } 
Note: See TracChangeset for help on using the changeset viewer.