Temporary fixes for php encoding library bugs ending with segfault.
[fa-stable.git] / admin / inst_module.php
index e19523f1c314e86bb337eee9b09c4368de9e790b..2309292bef911ddfda922060b78dfa1900e74010 100644 (file)
@@ -14,10 +14,10 @@ $path_to_root="..";
 include_once($path_to_root . "/includes/session.inc");
 include_once($path_to_root."/includes/packages.inc");
 
-if ($use_popup_windows) {
+if ($SysPrefs->use_popup_windows) {
        $js = get_js_open_window(900, 500);
 }
-page(_($help_context = "Install/Activate extensions"));
+page(_($help_context = "Install/Activate extensions"), false, false, "", $js);
 
 include_once($path_to_root . "/includes/date_functions.inc");
 include_once($path_to_root . "/admin/db/company_db.inc");
@@ -42,13 +42,14 @@ function local_extension($id)
                        'active' => false
        );
 
-       @include_once($path_to_root.'/modules/'.$id.'/hooks.php');
+       if (file_exists($path_to_root.'/modules/'.clean_file_name($id).'/hooks.php')) {
+               include_once($path_to_root.'/modules/'.clean_file_name($id).'/hooks.php');
+       }
        $hooks_class = 'hooks_'.$id;
-       if (class_exists($hooks_class)) {
+       if (class_exists($hooks_class, false)) {
                $hooks = new $hooks_class;
                $hooks->install_extension(false);
        }
-       
        $Ajax->activate('ext_tbl'); // refresh settings display
        if (!update_extensions($exts))
                return false;
@@ -93,7 +94,7 @@ function fmt_titles($defs)
 //
 // Display list of all extensions - installed and available from repository
 //
-function display_extensions()
+function display_extensions($mods)
 {
        global $installed_extensions;
        
@@ -105,20 +106,18 @@ function display_extensions()
        table_header($th);
 
        $k = 0;
-       $mods = get_extensions_list('extension');
 
        foreach($mods as $pkg_name => $ext)
        {
                $available = @$ext['available'];
                $installed = @$ext['version'];
                $id = @$ext['local_id'];
-               $is_mod = $ext['type'] == 'module';
 
                $entries = fmt_titles(@$ext['entries']);
                $tabs = fmt_titles(@$ext['tabs']);
 
                alt_table_row_color($k);
-//             label_cell(is_array($ext['Descr']) ? $ext['Descr'][0] : $ext['Descr']);
+
                label_cell($available ? get_package_view_str($pkg_name, $ext['name']) : $ext['name']);
                label_cell($tabs);
                label_cell($entries);
@@ -153,7 +152,6 @@ function display_extensions()
        end_table(1);
 
        submit_center_first('Refresh', _("Update"), '', null);
-       submit_center_last('Add', _("Add third-party extension"), '', false);
 
        div_end();
 }
@@ -212,12 +210,16 @@ if (get_post('Refresh')) {
 
        $result = true;
        foreach($exts as $i => $ext) {
-               if ($ext['package'] && ($ext['active'] ^ check_value('Active'.$i))) {
-                       if (!$ext['active'])
-                               $activated = activate_hooks($ext['package'], $comp);
-                       else
-                               $activated = hook_invoke($ext['package'], check_value('Active'.$i) ?
-                                'activate_extension':'deactivate_extension', $comp, false);
+               if ($ext['package'] && ($ext['active'] ^ check_value('Active'.$i))) 
+               {
+                       if (check_value('Active'.$i) && !check_src_ext_version($ext['version']))
+                       {
+                               display_warning(sprintf(_("Package '%s' is incompatible with current application version and cannot be activated.\n")
+                                       . _("Check Install/Activate page for newer package version."), $ext['name']));
+                               continue;
+                       }
+                       $activated = activate_hooks($ext['package'], $comp, !$ext['active']);   // change active state
+
                        if ($activated !== null)
                                $result &= $activated;
                        if ($activated || ($activated === null))
@@ -259,12 +261,16 @@ echo extset_list('extset', null, true);
 echo "</center><br>";
 
 if ($set == -1) 
-       display_extensions();
-else 
+{
+       $mods = get_extensions_list('extension');
+       if (!$mods)
+               display_note(_("No optional extension module is currently available."));
+       else
+               display_extensions($mods);
+} else 
        company_extensions($set);
 
 //---------------------------------------------------------------------------------------------
 end_form();
 
 end_page();
-?>
\ No newline at end of file