home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / classes / modules.class.inc < prev    next >
Text File  |  2004-03-08  |  5KB  |  193 lines

  1. <?php
  2. /*
  3. Copyright Intermesh 2003
  4. Author: Merijn Schering <mschering@intermesh.nl>
  5. Version: 1.0 Release date: 08 July 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13. class GO_MODULES extends db
  14. {
  15.     var $read_permissions = false;
  16.     var $write_permissions = false;
  17.     var $path;
  18.     var $id;
  19.     var $url;
  20.  
  21.     function GO_MODULES()
  22.     {
  23.         $this->db();
  24.     }
  25.  
  26.  
  27.     function authenticate($module_id)
  28.     {
  29.         global $GO_CONFIG, $GO_SECURITY;
  30.         if($module = $this->get_module($module_id))
  31.         {
  32.             $_SESSION['GO_SESSION']['active_module'] = $module_id;
  33.             $this->path = $module['path'];
  34.             $this->read_permissions = $GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_read']);
  35.             $this->write_permissions = $GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_write']);
  36.             $this->id = $module_id;
  37.             if ($GO_CONFIG->slash == '\\')
  38.             {
  39.                 $this->url = $GO_CONFIG->host.str_replace('\\', '/', $module['path']);
  40.             }else
  41.             {
  42.                 $this->url = $GO_CONFIG->host.$module['path'];
  43.             }
  44.  
  45.             if ($this->read_permissions || $this->write_permissions)
  46.             {
  47.                 return true;
  48.             }else
  49.             {
  50.                 header('Location: '.$GO_CONFIG->host.'error_docs/403.php');
  51.                 exit();
  52.             }
  53.         }else
  54.         {
  55.             exit('Illegal module name specified');
  56.         }
  57.     }
  58.  
  59.     function has_read_permission($user_id, $module_id)
  60.     {
  61.         global $GO_SECURITY;
  62.         $module = $this->get_module($module_id);
  63.         if($GO_SECURITY->has_permission($user_id, $module['acl_read']) || $GO_SECURITY->has_permission($user_id, $module['acl_write']))
  64.         {
  65.             return true;
  66.         }else
  67.         {
  68.             return false;
  69.         }
  70.     }
  71.  
  72.  
  73.     function has_write_permission($user_id, $module_id)
  74.     {
  75.         global $GO_SECURITY;
  76.         $module = $this->get_module($module_id);
  77.         return $GO_SECURITY->has_permission($user_id, $module['acl_write']);
  78.     }
  79.  
  80.     function get_module($module_id)
  81.     {
  82.         global $GO_CONFIG;
  83.  
  84.         $sql = "SELECT * FROM modules WHERE id='".addslashes($module_id)."'";
  85.         $this->query($sql);
  86.         if ($this->next_record())
  87.         {
  88.             if ($GO_CONFIG->slash == '\\')
  89.             {
  90.                 $this->Record['url'] = $GO_CONFIG->host.str_replace('\\', '/', $this->f('path'));
  91.             }else
  92.             {
  93.                 $this->Record['url'] = $GO_CONFIG->host.$this->f('path');
  94.             }
  95.             return $this->Record;
  96.         }else
  97.         {
  98.             return false;
  99.         }
  100.     }
  101.  
  102.     function add_module($module_id, $path, $acl_read, $acl_write)
  103.     {
  104.         $sql = "INSERT INTO modules (id, path, acl_read, acl_write) VALUES ('".addslashes($module_id)."', '".addslashes($path)."', '$acl_read', '$acl_write')";
  105.         return $this->query($sql);
  106.     }
  107.  
  108.     function update_module($old_module_id, $new_module_id, $path)
  109.     {
  110.         $sql = "UPDATE modules SET id='$new_module_id', path='$path' WHERE id='$old_module_id'";
  111.         return $this->query($sql);
  112.     }
  113.  
  114.     function delete_module($module_id)
  115.     {
  116.         global $GO_SECURITY;
  117.         if ($module = $this->get_module($module_id))
  118.         {
  119.             $GO_SECURITY->delete_acl($module['acl_read']);
  120.             $GO_SECURITY->delete_acl($module['acl_write']);
  121.             $sql = "DELETE FROM modules WHERE id='".addslashes($module_id)."'";
  122.             return $this->query($sql);
  123.         }
  124.         return false;
  125.     }
  126.  
  127.     function get_modules()
  128.     {
  129.         $sql = "SELECT * FROM modules ORDER BY id ASC";
  130.         $this->query($sql);
  131.         return $this->num_rows();
  132.     }
  133.  
  134.     function is_registered_module($path)
  135.     {
  136.         global $GO_CONFIG;
  137.         if (substr($path, -1) != $GO_CONFIG->slash)
  138.         {
  139.             $path .= $GO_CONFIG->slash;
  140.         }
  141.         $path = str_replace($GO_CONFIG->root_path,'',$path);
  142.  
  143.         $sql = "SELECT id FROM modules WHERE path='".addslashes($path)."'";
  144.  
  145.         if ($this->query($sql))
  146.         {
  147.             if ($this->next_record())
  148.             {
  149.                 return $this->f('id');
  150.             }
  151.         }
  152.         return false;
  153.     }
  154.  
  155.     function get_plugin($plugin_id, $module_id='')
  156.     {
  157.         global $GO_CONFIG;
  158.  
  159.         if ($module_id == '')
  160.         {
  161.             $module_path = $this->path;
  162.         }else
  163.         {
  164.             if(!$module = $this->get_module($module_id))
  165.             {
  166.                 return false;
  167.             }else
  168.             {
  169.                 $module_path = $module['path'];
  170.             }
  171.         }
  172.  
  173.         $plugin['id'] = $plugin_id;
  174.         $plugin['path'] = $module_path.$plugin_id.$GO_CONFIG->slash;
  175.  
  176.         if(file_exists($GO_CONFIG->root_path.$plugin['path']))
  177.         {
  178.  
  179.             if ($GO_CONFIG->slash == '\\')
  180.             {
  181.                 $plugin['url'] = $GO_CONFIG->host.str_replace('\\', '/', $plugin['path']);
  182.             }else
  183.             {
  184.                 $plugin['url'] = $GO_CONFIG->host.$plugin['path'];
  185.             }
  186.             return $plugin;
  187.         }else
  188.         {
  189.             return false;
  190.         }
  191.     }
  192. }
  193. ?>