X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fpackages.inc;h=c9387233e8b354618bc20e6961805ed339314994;hb=34bfbfad2dd0239174e03f7cce2b0bdcfa6a8a10;hp=6b9cb674daa14bba7c26b3bc273e6e56090a7d7c;hpb=f36d4241ba673261532a1bb3c59b6b985901238e;p=fa-stable.git diff --git a/includes/packages.inc b/includes/packages.inc index 6b9cb674..c9387233 100644 --- a/includes/packages.inc +++ b/includes/packages.inc @@ -10,12 +10,13 @@ See the License here . ***********************************************************************/ include_once($path_to_root. "/includes/archive.inc"); +include_once($path_to_root. "/includes/remote_url.inc"); define('PKG_CACHE_PATH', $path_to_root.'/modules/_cache'); define('PUBKEY_PATH', $path_to_root); -define('REPO_URL', "$repository/$FA_repo_version"); +define('REPO_URL', 'http://'.$repo_auth['login'].':'.$repo_auth['pass'].'@'.$repo_auth['host'].'/'.$repo_auth['branch']); // -// FrontAccounting package class +// FrontAccounting package class // class package extends gzip_file { function package($filename, $basedir=null) @@ -179,7 +180,7 @@ function get_control_file($file, $index = false) { $line = ''; do { $line = rtrim($line); - if (@ctype_space($line[0])) { // continuation of multiline property + if ($line && ctype_space($line[0])) { // continuation of multiline property if (strlen(ltrim($line))) { if ($value !== '' && !is_array($value)) $value = array($value); @@ -277,23 +278,23 @@ function pkg_prop($pkg, $property, $lang=false) // function get_pkg_or_list($type = null, $pkgname = null, $filter=array(), $outkey=null, $download=true) { - global $path_to_root, $repository, $FA_repo_version; + global $path_to_root, $repo_auth; // first download local copy of repo release file // and check remote signature with local copy of public key // $loclist = PKG_CACHE_PATH.'/Release.gz'; - if ($type!=null && !is_array($type)) { + if (isset($type) && !is_array($type)) { $type = array($type); } $refresh = true; do{ if (!file_exists($loclist)) { - copy(REPO_URL.'/Release.gz', $loclist); + url_copy(REPO_URL.'/Release.gz', $loclist); $refresh = false; } - $sig = file_get_contents(REPO_URL.'/Release.sig', 'rb'); + $sig = url_get_contents(REPO_URL.'/Release.sig'); $data = file_get_contents($loclist); $cert = file_get_contents(PUBKEY_PATH.'/FA.pem'); if (!openssl_verify($data, $sig, $cert)) { @@ -308,7 +309,6 @@ function get_pkg_or_list($type = null, $pkgname = null, $filter=array(), $outkey } while($refresh); $Release = get_control_file($loclist, 'Filename'); - // download and check all indexes containing given package types // then complete package list or seek for pkg $Packages = array(); @@ -316,7 +316,7 @@ function get_pkg_or_list($type = null, $pkgname = null, $filter=array(), $outkey if ($type && !count(array_intersect(explode(' ', $parms['Type']), $type))) { unset($Release[$fname]); continue; // no packages of selected type in this index } - if ($Release[$fname]['Version'] != $FA_repo_version) { + if ($Release[$fname]['Version'] != $repo_auth['branch']) { display_warning(_('Repository version does not match application version.')); // ? } $remoteindex = REPO_URL.'/'.$fname; @@ -324,7 +324,7 @@ function get_pkg_or_list($type = null, $pkgname = null, $filter=array(), $outkey $refresh = true; do{ if (!file_exists($locindex)) { - copy($remoteindex, $locindex); + url_copy($remoteindex, $locindex); $refresh = false; } if ($parms['SHA1sum'] != sha1_file($locindex)) { // check subdir index consistency @@ -343,7 +343,7 @@ function get_pkg_or_list($type = null, $pkgname = null, $filter=array(), $outkey $pkglist = get_control_file($locindex, 'Package'); foreach($pkglist as $name => $pkg) { $pkgfullname = REPO_URL.'/'.$parms['Path']."/".$pkg['Filename'].'.pkg'; - if ($type==null || in_array($pkg['Type'], $type)) { + if (!isset($type) || in_array($pkg['Type'], $type)) { if (empty($filter)) $p = $pkg; else { @@ -360,7 +360,7 @@ function get_pkg_or_list($type = null, $pkgname = null, $filter=array(), $outkey //download package to temp directory if ($download) { $locname = "$path_to_root/tmp/".$pkg['Filename'].'.pkg'; - copy($pkgfullname, $locname); + url_copy($pkgfullname, $locname); // checking sha1 hash is expensive proces, so chekc the package // consistency just before downloading if ($pkg['SHA1sum'] != sha1_file($locname)) { @@ -374,14 +374,13 @@ function get_pkg_or_list($type = null, $pkgname = null, $filter=array(), $outkey } } } - + return $Packages; } function get_package($pkgname, $type = null) { - $all = get_pkg_or_list($type, $pkgname); - $pkg = array_search_value($all, $pkgname, 'Package'); + return get_pkg_or_list($type, $pkgname); } /* Returns full name of installed package, or null if package is not installed. @@ -458,12 +457,17 @@ function get_languages_list() } //--------------------------------------------------------------------------------------- // -// Return merged list of available and installed extensions in inform of local +// Return merged list of available and installed extensions as a local // configuration array supplemented with installed versions information. // -function get_extensions_list() +function get_extensions_list($type = null) { - $pkgs = get_pkg_or_list('extension', null, array( + + if (isset($type) && !is_array($type)) { + $type = array($type); + } + + $pkgs = get_pkg_or_list($type, null, array( 'Package' => 'package', 'Version' => 'available', 'Name' => 'name', @@ -472,6 +476,7 @@ function get_extensions_list() 'DefaultStatus'=> 'active', 'MenuTabs' => 'tabs', 'MenuEntries' => 'entries', + 'Encoding' => 'encoding', 'AccessExtensions' => 'acc_file', 'InstallPath' => 'path' )); @@ -480,7 +485,7 @@ function get_extensions_list() // $local = get_company_extensions(); foreach($local as $extno => $ext) { - if ($ext['type'] == 'theme') continue; + if (!in_array($ext['type'], $type)) continue; $ext['local_id'] = $extno; if (!isset($pkgs[$ext['package']]) || $ext['package'] == '') $pkgs[] = $ext; @@ -491,7 +496,7 @@ function get_extensions_list() return $pkgs; } // -// Return merged list of available and installed extensions in inform of local +// Return merged list of available and installed extensions as a local // configuration array supplemented with installed versions information. // function get_themes_list() @@ -518,6 +523,39 @@ function get_themes_list() ksort($pkgs); return $pkgs; } +//--------------------------------------------------------------------------------------- +// +// Return merged list of available and installed COAs as a local +// configuration array supplemented with installed versions information. +// +function get_charts_list() +{ + $pkgs = get_pkg_or_list('chart', null, array( + 'Package' => 'package', + 'Version' => 'available', + 'Name' => 'name', + 'Description' => 'Descr', + 'Type' => 'type', + 'InstallPath' => 'path', + 'Encoding' => 'encoding', + 'SqlScript' => 'sql' + )); + + // add/update default charts + // + $local = get_company_extensions(); + + foreach($local as $extno => $ext) { + if ($ext['type'] != 'chart') continue; + $ext['local_id'] = $extno; + if (!isset($pkgs[$ext['package']]) || $ext['package'] == '') + $pkgs[] = $ext; + else + $pkgs[$ext['package']] = array_merge($pkgs[$ext['package']], $ext); + } + ksort($pkgs); + return $pkgs; +} //--------------------------------------------------------------------------------------------- // Install/update package from repository // @@ -553,19 +591,24 @@ function install_language($pkg_name) write_lang($installed_languages); unlink("$path_to_root/tmp/".$pkg['Filename'].'.pkg'); $Ajax->activate('lang_tbl'); + } else { + display_error(implode('
', $package->error)); + return false; } - + } else { + display_error(sprintf(_("Package '%s' not found."), $pkg_name)); + return false; } - + return true; } //--------------------------------------------------------------------------------------------- // Install/update extension or theme package from repository // function install_extension($pkg_name) { - global $path_to_root, $next_extension_id, $Ajax; + global $path_to_root, $installed_extensions, $next_extension_id, $Ajax; - $pkg = get_pkg_or_list(array('extension', 'theme'), $pkg_name); + $pkg = get_pkg_or_list(array('extension', 'theme', 'chart'), $pkg_name); if ($pkg) { $package = new package("$path_to_root/tmp/".$pkg['Filename'].'.pkg'); $local_exts = get_company_extensions(); @@ -573,6 +616,11 @@ function install_extension($pkg_name) $ext_id = array_search_key($pkg['Package'], $local_exts, 'package'); if ($ext_id === null) $ext_id = $next_extension_id++; + else { // remove another already installed package for this language + $old_pkg = $installed_extensions[$ext_id]['package']; + if ($old_pkg) + uninstall_package($old_pkg); + } $ext = array( 'name' => $pkg['Name'], 'package' => $pkg['Package'], @@ -587,14 +635,22 @@ function install_extension($pkg_name) $ext['entries'] = $pkg['MenuEntries']; if (isset($pkg['AccessExtensions'])) $ext['acc_file'] = $pkg['AccessExtensions']; + if (isset($pkg['SqlScript'])) + $ext['sql'] = $pkg['SqlScript']; $local_exts[$ext_id] = $ext; - update_extensions($local_exts); + $ret = update_extensions($local_exts); unlink("$path_to_root/tmp/".$pkg['Filename'].'.pkg'); $Ajax->activate('ext_tbl'); + return $ret; } else { display_error(implode('
', $package->error)); + return false; } + } else { + display_error(sprintf(_("Package '%s' not found."), $pkg_name)); + return false; } + return true; } /* Returns true if newer package version is available