home *** CD-ROM | disk | FTP | other *** search
- <?php
- /*
- Copyright Intermesh 2003
- Author: Merijn Schering <mschering@intermesh.nl>
- Version: 1.0 Release date: 08 July 2003
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 2 of the License, or (at your
- option) any later version.
- */
-
- class GO_MODULES extends db
- {
- var $read_permissions = false;
- var $write_permissions = false;
- var $path;
- var $id;
- var $url;
-
- function GO_MODULES()
- {
- $this->db();
- }
-
-
- function authenticate($module_id)
- {
- global $GO_CONFIG, $GO_SECURITY;
- if($module = $this->get_module($module_id))
- {
- $_SESSION['GO_SESSION']['active_module'] = $module_id;
- $this->path = $module['path'];
- $this->read_permissions = $GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_read']);
- $this->write_permissions = $GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_write']);
- $this->id = $module_id;
- if ($GO_CONFIG->slash == '\\')
- {
- $this->url = $GO_CONFIG->host.str_replace('\\', '/', $module['path']);
- }else
- {
- $this->url = $GO_CONFIG->host.$module['path'];
- }
-
- if ($this->read_permissions || $this->write_permissions)
- {
- return true;
- }else
- {
- header('Location: '.$GO_CONFIG->host.'error_docs/403.php');
- exit();
- }
- }else
- {
- exit('Illegal module name specified');
- }
- }
-
- function has_read_permission($user_id, $module_id)
- {
- global $GO_SECURITY;
- $module = $this->get_module($module_id);
- if($GO_SECURITY->has_permission($user_id, $module['acl_read']) || $GO_SECURITY->has_permission($user_id, $module['acl_write']))
- {
- return true;
- }else
- {
- return false;
- }
- }
-
-
- function has_write_permission($user_id, $module_id)
- {
- global $GO_SECURITY;
- $module = $this->get_module($module_id);
- return $GO_SECURITY->has_permission($user_id, $module['acl_write']);
- }
-
- function get_module($module_id)
- {
- global $GO_CONFIG;
-
- $sql = "SELECT * FROM modules WHERE id='".addslashes($module_id)."'";
- $this->query($sql);
- if ($this->next_record())
- {
- if ($GO_CONFIG->slash == '\\')
- {
- $this->Record['url'] = $GO_CONFIG->host.str_replace('\\', '/', $this->f('path'));
- }else
- {
- $this->Record['url'] = $GO_CONFIG->host.$this->f('path');
- }
- return $this->Record;
- }else
- {
- return false;
- }
- }
-
- function add_module($module_id, $path, $acl_read, $acl_write)
- {
- $sql = "INSERT INTO modules (id, path, acl_read, acl_write) VALUES ('".addslashes($module_id)."', '".addslashes($path)."', '$acl_read', '$acl_write')";
- return $this->query($sql);
- }
-
- function update_module($old_module_id, $new_module_id, $path)
- {
- $sql = "UPDATE modules SET id='$new_module_id', path='$path' WHERE id='$old_module_id'";
- return $this->query($sql);
- }
-
- function delete_module($module_id)
- {
- global $GO_SECURITY;
- if ($module = $this->get_module($module_id))
- {
- $GO_SECURITY->delete_acl($module['acl_read']);
- $GO_SECURITY->delete_acl($module['acl_write']);
- $sql = "DELETE FROM modules WHERE id='".addslashes($module_id)."'";
- return $this->query($sql);
- }
- return false;
- }
-
- function get_modules()
- {
- $sql = "SELECT * FROM modules ORDER BY id ASC";
- $this->query($sql);
- return $this->num_rows();
- }
-
- function is_registered_module($path)
- {
- global $GO_CONFIG;
- if (substr($path, -1) != $GO_CONFIG->slash)
- {
- $path .= $GO_CONFIG->slash;
- }
- $path = str_replace($GO_CONFIG->root_path,'',$path);
-
- $sql = "SELECT id FROM modules WHERE path='".addslashes($path)."'";
-
- if ($this->query($sql))
- {
- if ($this->next_record())
- {
- return $this->f('id');
- }
- }
- return false;
- }
-
- function get_plugin($plugin_id, $module_id='')
- {
- global $GO_CONFIG;
-
- if ($module_id == '')
- {
- $module_path = $this->path;
- }else
- {
- if(!$module = $this->get_module($module_id))
- {
- return false;
- }else
- {
- $module_path = $module['path'];
- }
- }
-
- $plugin['id'] = $plugin_id;
- $plugin['path'] = $module_path.$plugin_id.$GO_CONFIG->slash;
-
- if(file_exists($GO_CONFIG->root_path.$plugin['path']))
- {
-
- if ($GO_CONFIG->slash == '\\')
- {
- $plugin['url'] = $GO_CONFIG->host.str_replace('\\', '/', $plugin['path']);
- }else
- {
- $plugin['url'] = $GO_CONFIG->host.$plugin['path'];
- }
- return $plugin;
- }else
- {
- return false;
- }
- }
- }
- ?>