Beispiel #1
0
 function MergeStructureFiles($filea, $fileb, $tmpdir = '')
 {
     $result = array();
     if (file_exists($filea) and file_exists($fileb)) {
         // Load structure files
         //
         $deffilea = new XMLDefFile($this->ampdb, $tmpdir);
         $deffilea->Load_DefFile($filea);
         $structurea = $deffilea->Get_Structure();
         $deffileb = new XMLDefFile($this->ampdb);
         $deffileb->Load_DefFile($fileb);
         $structureb = $deffileb->Get_Structure();
         // Fill scripts array
         //
         $scripts = array();
         if (isset($structureb['generalpreinstall'])) {
             $scripts['generalpreinstall'] = $structureb['generalpreinstall'];
         }
         if (isset($structureb['generalpreuninstall'])) {
             $scripts['generalpreuninstall'] = $structureb['generalpreuninstall'];
         }
         if (isset($structureb['generalpostinstall'])) {
             $scripts['generalpostinstall'] = $structureb['generalpostinstall'];
         }
         if (isset($structureb['generalpostuninstall'])) {
             $scripts['generalpostuninstall'] = $structureb['generalpostuninstall'];
         }
         if (isset($structureb['sitepreinstall'])) {
             $scripts['sitepreinstall'] = $structureb['sitepreinstall'];
         }
         if (isset($structureb['sitepreuninstall'])) {
             $scripts['sitepreuninstall'] = $structureb['sitepreuninstall'];
         }
         if (isset($structureb['sitepostinstall'])) {
             $scripts['sitepostinstall'] = $structureb['sitepostinstall'];
         }
         if (isset($structureb['sitepostuninstall'])) {
             $scripts['sitepostuninstall'] = $structureb['sitepostuninstall'];
         }
         if (isset($structureb['generalpreupdate'])) {
             $scripts['generalpreupdate'] = $structureb['generalpreupdate'];
         }
         if (isset($structureb['generalpostupdate'])) {
             $scripts['generalpostupdate'] = $structureb['generalpostupdate'];
         }
         if (isset($structureb['sitepreupdate'])) {
             $scripts['sitepreupdate'] = $structureb['sitepreupdate'];
         }
         if (isset($structureb['sitepostupdate'])) {
             $scripts['sitepostupdate'] = $structureb['sitepostupdate'];
         }
         // Remove scripts and odd entries
         //
         while (list($key, $val) = each($structurea)) {
             if (!is_array($val)) {
                 unset($structurea[$key]);
             }
         }
         reset($structurea);
         while (list($key, $val) = each($structureb)) {
             if (!is_array($val)) {
                 unset($structureb[$key]);
             }
         }
         reset($structureb);
         $tmpstructure = array();
         // Scan structure a
         //
         while (list($eltypea, $arraycontenta) = each($structurea)) {
             if (isset($structureb[$eltypea])) {
                 // This element type is in both structures
                 //
                 $arraycontentb = $structureb[$eltypea];
                 reset($arraycontenta);
                 // Checks every element in current structure a element type
                 //
                 while (list($keya, $vala) = each($arraycontenta)) {
                     reset($arraycontentb);
                     $found = FALSE;
                     while (list($keyb, $valb) = each($arraycontentb)) {
                         if ($valb['file'] == $vala['file']) {
                             $found = TRUE;
                             $tmpkey = $keyb;
                         }
                     }
                     if ($found) {
                         // This element must be updated
                         //
                         $tmparray = array();
                         $tmparray = $vala;
                         $tmparray['updatemode'] = Module::UPDATE_MODE_CHANGE;
                         $tmpstructure[$eltypea][] = $tmparray;
                         unset($structurea[$eltypea][$keya]);
                         unset($structureb[$eltypea][$tmpkey]);
                     } else {
                         // This element must be added
                         //
                         $tmparray = array();
                         $tmparray = $vala;
                         $tmparray['updatemode'] = Module::UPDATE_MODE_ADD;
                         $tmpstructure[$eltypea][] = $tmparray;
                     }
                 }
             } else {
                 // It is a completely new element type for structure file b, so add it
                 //
                 array_walk($arraycontenta, array($this, '_elem_add'));
                 $tmpstructure[$eltypea] = $arraycontenta;
                 unset($structurea[$eltypea]);
             }
         }
         reset($structureb);
         // Scan structure b
         //
         while (list($eltypeb, $arraycontentb) = each($structureb)) {
             if (isset($structurea[$eltypeb])) {
                 // This element type is in both structures
                 //
                 $arraycontenta = $structurea[$eltypeb];
                 reset($arraycontentb);
                 // Check every remaining element in current structure b element type
                 //
                 while (list($keyb, $valb) = each($arraycontentb)) {
                     reset($arraycontenta);
                     $found = FALSE;
                     // This is just a check
                     //
                     while (list($keya, $vala) = each($arraycontenta)) {
                         if ($vala['file'] == $valb['file']) {
                             $found = TRUE;
                         }
                     }
                     if ($found) {
                         // Should never happen
                         //
                         $tmparray = array();
                         $tmparray = $valb;
                         $tmparray['updatemode'] = Module::UPDATE_MODE_CHANGE;
                         $tmpstructure[$eltypeb][] = $tmparray;
                     } else {
                         // This element must be removed
                         //
                         $tmparray = array();
                         $tmparray = $valb;
                         $tmparray['updatemode'] = Module::UPDATE_MODE_REMOVE;
                         $tmpstructure[$eltypeb][] = $tmparray;
                     }
                     if (isset($structurea[$eltypea][$keya])) {
                         unset($structurea[$eltypea][$keya]);
                     }
                     if (isset($structureb[$eltypea][$keya])) {
                         unset($structureb[$eltypea][$keya]);
                     }
                 }
             } else {
                 // It is a completely old element type for structure file b, so remove it
                 //
                 array_walk($arraycontentb, array($this, '_elem_remove'));
                 $tmpstructure[$eltypeb] = $arraycontentb;
             }
         }
         $result = array_merge($tmpstructure, $scripts);
     } else {
         import('com.solarix.ampoliros.io.log.Logger');
         $log = new Logger(AMP_LOG);
         if (!file_exists($filea)) {
             $log->LogEvent('ampoliros.modules_library.module_class.mergestructurefiles', 'Structure file ' . $filea . ' not found', LOGGER_ERROR);
         }
         if (!file_exists($fileb)) {
             $log->LogEvent('ampoliros.modules_library.module_class.mergestructurefiles', 'Structure file ' . $fileb . ' not found', LOGGER_ERROR);
         }
     }
     return $result;
 }
Beispiel #2
0
function main_showmodule($eventData)
{
    global $env, $amp_locale, $hui_mainframe, $hui_titlebar;
    $query =& $env['ampdb']->execute('SELECT modid ' . 'FROM modules ' . 'WHERE id=' . $eventData['modid'] . ' ');
    $module_data = $query->Fields();
    $deffile = new XMLDefFile($env['ampdb'], PRIVATE_TREE);
    $deffile->Load_DefFile(MODULE_PATH . $module_data['modid'] . '/structure.xml');
    $structure = $deffile->Get_Structure();
    ksort($structure);
    $headers[0]['label'] = $amp_locale->GetStr('elementtype_header');
    $headers[1]['label'] = $amp_locale->GetStr('elementname_header');
    $headers[2]['label'] = $amp_locale->GetStr('elementattrs_header');
    $row = 0;
    $hui_modules_table = new HuiTable('modulestable', array('headers' => $headers, 'rowsperpage' => '20', 'pagesactionfunction' => 'show_module_action_builder', 'pagenumber' => isset($eventData['pagenumber']) ? $eventData['pagenumber'] : '', 'sessionobjectusername' => $module_data['modid']));
    while (list($type, $elems) = each($structure)) {
        if (is_array($elems)) {
            asort($elems);
            while (list($elem, $attrs) = each($elems)) {
                $attrs_string = '';
                while (list($key, $val) = each($attrs)) {
                    if (strcmp($key, 'name')) {
                        $attrs_string .= '<b>' . $key . '</b>: ' . $val . '. ';
                    }
                }
                $hui_modules_table->AddChild(new HuiLabel('elementtypelabel' . $row, array('label' => $type)), $row, 0);
                $hui_modules_table->AddChild(new HuiLabel('elementnamelabel' . $row, array('label' => $attrs['name'])), $row, 1);
                $hui_modules_table->AddChild(new HuiLabel('elementattrslabel' . $row, array('label' => $attrs_string)), $row, 2);
                $row++;
            }
        }
    }
    $hui_mainframe->AddChild($hui_modules_table);
    $hui_titlebar->mTitle .= ' - ' . $module_data['modid'] . ' - ' . $amp_locale->GetStr('modulestructure_title');
}