+ global $path_to_root, $installed_extensions, $next_extension_id;
+
+ if (!isset($extensions)) {
+ $extensions = $installed_extensions;
+ }
+ if (!isset($next_extension_id)) {
+ $next_extension_id = 1;
+ }
+
+ $msg = "<?php\n\n";
+ if ($company == -1)
+ $msg .=
+"/* List of installed additional extensions. If extensions are added to the list manually
+ make sure they have unique and so far never used extension_ids as a keys,
+ and \$next_extension_id is also updated. More about format of this file yo will find in
+ FA extension system documentation.
+*/
+\n\$next_extension_id = $next_extension_id; // unique id for next installed extension\n\n";
+ else
+ $msg .=
+"/*
+ Do not edit this file manually. This copy of global file is overwritten
+ by extensions editor.
+*/\n\n";
+
+ $msg .= "\$installed_extensions = ". var_export($extensions, true);
+ $msg .= ";\n?>";
+ $filename = $path_to_root . ($company==-1 ? '' : '/company/'.$company)
+ .'/installed_extensions.php';
+
+ // Check if the file is writable first.
+ if (!$zp = @fopen($filename, 'w'))
+ {
+ display_error(sprintf(_("Cannot open the extension setup file '%s' for writing."),
+ $filename));
+ return false;
+ }
+ else
+ {
+ if (!fwrite($zp, $msg))
+ {
+ display_error(sprintf(_("Cannot write to the extensions setup file '%s'."),
+ $filename));
+ fclose($zp);
+ return false;
+ }
+ // Close file
+ fclose($zp);
+ }
+ return true;
+}
+//---------------------------------------------------------------------------------------------
+//
+// Update per-company list of installed extensions
+//
+function update_extensions($extensions) {
+ global $db_connections;
+
+ if (!write_extensions($extensions)) {
+ display_notification(_("Cannot update system extensions list."));
+ return false;
+ }
+
+ // update per company files
+ $cnt = count($db_connections);
+ for($i = 0; $i < $cnt; $i++)