home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / classes / security.class.inc < prev    next >
Text File  |  2004-03-08  |  19KB  |  610 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_SECURITY extends db
  14. {
  15.   var $user_id = 0;
  16.   var $logged_in = false;
  17.   var $group_everyone = "2";
  18.   var $group_root = "1";
  19.   var $ldap;
  20.   var $imap;
  21.  
  22.   function GO_SECURITY()
  23.   {
  24.     global $GO_CONFIG;
  25.     $this->db();
  26.  
  27.     if (isset($_SESSION['GO_SESSION']['user_id']) && $_SESSION['GO_SESSION']['user_id'] > 0)
  28.     {
  29.       $this->logged_in=true;
  30.       $this->user_id=$_SESSION['GO_SESSION']['user_id'];
  31.     }
  32.   }
  33.  
  34.   function logout()
  35.   {
  36.     session_destroy();
  37.     $this->user_id = 0;
  38.     $this->logged_in = false;
  39.   }
  40.  
  41.   //attempts to login a user and registers user_id in a session.
  42.   //returns true on success. Stores general preferences in sessions
  43.   //////////////////////////////////////////////////////////////
  44.   function login($username, $password, $auth_mail_server_key=-1)
  45.   {
  46.     global $GO_CONFIG, $GO_SECURITY, $GO_LANGUAGE;
  47.  
  48.     require_once($GO_CONFIG->class_path.'users.class.inc');
  49.     $users = new users();
  50.  
  51.     $this->logged_in = false;
  52.     $this->user_id = 0;
  53.  
  54.     $_SESSION['GO_SESSION']['auth_src'] = 'sql';
  55.     $_SESSION['GO_SESSION']['password'] = $password;
  56.     $_SESSION['GO_SESSION']['old_password'] = $password;
  57.  
  58.     switch($GO_CONFIG->auth_db_type)
  59.     {
  60.       case 'ldap':
  61.     $_SESSION['GO_SESSION']['auth_src'] = "ldap";
  62.  
  63.     $ldap = new ldap();
  64.     $ldap->connect();
  65.     $ldap->bind( $GO_CONFIG->auth_db_user, $GO_CONFIG->auth_db_pass );
  66.     $ldap->search( "uid=$username", $ldap->PeopleDN );
  67.     if ( $ldap->next_entry() ) {
  68.       $dn = $ldap->dn();
  69.       $username = substr( $dn, 0, strpos( $dn, "," ) );
  70.       $username = substr( $username, strpos( $username, "=" )+1 );
  71.     }
  72.     if ( $ldap->bind( $dn, $password ) )
  73.     {
  74.       // Search directory for user information...
  75.       $ldap->search("uid=$username", $ldap->PeopleDN);
  76.       if ($ldap->next_entry())
  77.       {
  78.         $user_id = $ldap->first_value("uidNumber");
  79.  
  80.         if ($user_id > 0)
  81.         {
  82.           $this->query("SELECT id FROM users WHERE username='".smart_addslashes($username)."'");
  83.           if ($this->num_rows() < 1)
  84.           {
  85.         //if the administrator has set a maximum amount of users and it's reached then abort
  86.         if ($users->max_users_reached())
  87.         {
  88.           return false;
  89.         }
  90.         // User does not exist in SQL so wie create him.
  91.         // TODO: This could be optimized by users->add_user - but we need to take care that
  92.         // the uidNumber is the same in SQL and LDAP.
  93.         $acl_id = $GO_SECURITY->get_new_acl( $_SESSION['GO_SESSION']['email'] );
  94.  
  95.         $authcode = $users->random_password();
  96.  
  97.         require_once($GO_CONFIG->class_path.'profiles.class.inc');
  98.         $profiles = new profiles();
  99.         if (!$profile = $profiles->get_profile($user_id))
  100.         {
  101.           die('FATAL ERROR: Couldn\'t get profile from LDAP user');
  102.         }
  103.  
  104.         if ( $GO_CONFIG->auth_db_ldap_um )
  105.         {
  106.           // No need to add the User to SQL
  107.           $GO_SECURITY->set_acl_owner($acl_id, $user_id);
  108.         }else
  109.         {
  110.           // Check if this is the first login
  111.           $this->query("SELECT id FROM users WHERE username='".smart_addslashes($username)."'");
  112.           if ($this->num_rows() < 1)
  113.           {
  114.             //if the administrator has set a maximum amount of users and it's reached then abort
  115.             if ($users->max_users_reached())
  116.             {
  117.               return false;
  118.             }
  119.             // User does not exist in SQL so wie create him.
  120.             // TODO: This could be optimized by users->add_user - but we need to take care that
  121.             // the uidNumber is the same in SQL and LDAP.
  122.             $acl_id = $GO_SECURITY->get_new_acl( $_SESSION['GO_SESSION']['email'] );
  123.  
  124.             $authcode = $users->random_password();
  125.  
  126.             require_once($GO_CONFIG->class_path.'profiles.class.inc');
  127.             $profiles = new profiles();
  128.             if (!$profile = $profiles->get_profile($user_id))
  129.             {
  130.               die('FATAL ERROR: Couldn\'t get profile from LDAP user');
  131.             }
  132.  
  133.             if ($user_id = $users->add_user($username, $password, $profile['first_name'], $profile['last_name'],$profile['initials'], $profile['sex'], $profile['birtday'], $profile['email'], $authcode, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', $acl_id, false, $user_id))
  134.             {
  135.               $GO_SECURITY->set_acl_owner($acl_id, $user_id);
  136.               // add user to the everyone group
  137.               require_once( $GO_CONFIG->class_path."groups.class.inc" );
  138.               $groups = new groups();
  139.               $groups->add_user_to_group( $user_id, $GO_SECURITY->group_everyone );
  140.               // add administrator to the users acl
  141.               $GO_SECURITY->add_group_to_acl($GO_SECURITY->group_root, $acl_id);
  142.  
  143.               $old_umask = umask( 000);
  144.               @mkdir($GO_CONFIG->file_storage_path.$username, $GO_CONFIG->create_mode );
  145.               umask($old_umask);
  146.             } else {
  147.               die('FATAL ERROR: Failed adding LDAP user to Group-Office');
  148.               $GO_SECURITY->delete_acl($acl_id);
  149.             }
  150.           }
  151.         }
  152.           }
  153.         }
  154.       }
  155.     }
  156.     break;
  157.  
  158.       case 'mail':
  159.  
  160.     if ($auth_mail_server_key != '' && $auth_mail_server_key > -1)
  161.     {
  162.       require($GO_CONFIG->root_path.'auth_mail_servers.inc');
  163.  
  164.       $_SESSION['GO_SESSION']['auth_src'] = 'mail';
  165.  
  166.       require_once($GO_CONFIG->class_path.'imap.class.inc');
  167.       $imap = new imap();
  168.  
  169.       $email_address = $username.'@'.$auth_mail_servers[$auth_mail_server_key]['domain'];
  170.       if ($auth_mail_servers[$auth_mail_server_key]['add_domain_to_username'] == 'true')
  171.       {
  172.         $username = $email_address;
  173.       }
  174.  
  175.       if ($imap->open($auth_mail_servers[$auth_mail_server_key]['ip'], $auth_mail_servers[$auth_mail_server_key]['type'], $auth_mail_servers[$auth_mail_server_key]['port'], $username, $password))
  176.       {
  177.         $imap->close();
  178.         $email = eregi("^([a-z0-9]+)([._-]([a-z0-9]+))*[@]([a-z0-9]+)([._-]([a-z0-9]+))*[.]([a-z0-9]){2}([a-z0-9])?([a-z0-9])?$", $username) ? $username : $username.'@'.$auth_mail_servers[$auth_mail_server_key]['domain'];
  179.         $this->query("SELECT id FROM users WHERE username='".smart_addslashes($email_address)."'");
  180.         if ($this->num_rows() > 0)
  181.         {
  182.           $this->next_record();
  183.           $user_id = $this->f('id');
  184.         }else
  185.         {
  186.           //if the administrator has set a maximum amount of users and it's reached then abort
  187.           if ($users->max_users_reached())
  188.           {
  189.         return false;
  190.           }
  191.           $acl_id = $GO_SECURITY->get_new_acl($email);
  192.           $authcode = $users->random_password();
  193.  
  194.           if ($user_id = $users->add_user($email_address, $password, '', '', '','','', 'M', '',$email, $authcode, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', $acl_id))
  195.           {
  196.         $GO_SECURITY->set_acl_owner($acl_id, $user_id);
  197.  
  198.         // add user to the everyone group
  199.         require_once( $GO_CONFIG->class_path."groups.class.inc" );
  200.         $groups = new groups();
  201.         $groups->add_user_to_group($user_id, $GO_SECURITY->group_everyone);
  202.         // add administrator to the users acl
  203.         $GO_SECURITY->add_group_to_acl($GO_SECURITY->group_root, $acl_id);
  204.  
  205.         $old_umask = umask( 000 );
  206.         @mkdir( $GO_CONFIG->file_storage_path.$email_address, $GO_CONFIG->create_mode );
  207.         umask($old_umask);
  208.  
  209.         require_once($GO_CONFIG->class_path."email.class.inc");
  210.         require($GO_LANGUAGE->get_language_file('email'));
  211.         $email_client = new email();
  212.         if (!$account_id = $email_client->add_account($user_id, $auth_mail_servers[$auth_mail_server_key]['type'],$auth_mail_servers[$auth_mail_server_key]['ip'], $auth_mail_servers[$auth_mail_server_key]['port'], $auth_mail_servers[$auth_mail_server_key]['mbroot'], $username, $password, $username, $email_address, "", $ml_sent_items, $ml_spam, $ml_trash))
  213.         {
  214.           require($GO_LANGUAGE->get_language_file('email'));
  215.           echo "<p class=\"Error\">".$registration_email_error."</p>";
  216.           echo "<p class=\"Error\">".$email_client->last_error."</p>";
  217.         }
  218.           }else
  219.           {
  220.         die('FATAL ERROR: Failed adding mail user to Group-Office');
  221.         $GO_SECURITY->delete_acl($acl_id);
  222.           }
  223.         }
  224.         $username = $email_address;
  225.       }
  226.     }
  227.     break;
  228.     }
  229.  
  230.     if (!isset($user_id) || $user_id < 1)
  231.     {
  232.       $sql = "SELECT id FROM users WHERE username='".smart_addslashes($username)."' AND password='".md5($password)."'";
  233.       $this->query($sql);
  234.       if ($this->next_record())
  235.       {
  236.     $user_id = $this->f('id');
  237.       }
  238.     }
  239.  
  240.     if(isset($user_id) && $user_id > 0)
  241.     {
  242.       require_once($GO_CONFIG->class_path.'profiles.class.inc');
  243.       $profiles = new profiles();
  244.       $profile = $profiles->get_profile($user_id);
  245.  
  246.       if($GO_CONFIG->auth_db_type != 'sql' && md5($password) != $profile['password'])
  247.       {
  248.     $users->update_password($user_id, $password);
  249.     if ($GO_CONFIG->auth_db_type == 'mail' && $auth_mail_server_key > -1)
  250.     {
  251.       require_once($GO_CONFIG->class_path."email.class.inc");
  252.       $email_client = new email();
  253.       $email_client->update_password($auth_mail_servers[$auth_mail_server_key]['ip'], $username, $password);
  254.     }
  255.       }
  256.  
  257.       $_SESSION['GO_SESSION']['user_id'] = $user_id;
  258.       $_SESSION['GO_SESSION']['password'] = $password;
  259.       $middle_name = $profile['middle_name'] ==  '' ? '' : $profile['middle_name'].' ';
  260.       $_SESSION['GO_SESSION']['name']  = $profile['first_name'].' '.$middle_name.$profile['last_name'];
  261.       $_SESSION['GO_SESSION']['first_name']  = $profile['first_name'];
  262.       $_SESSION['GO_SESSION']['middle_name']  = $profile['middle_name'];
  263.       $_SESSION['GO_SESSION']['last_name']  = $profile['last_name'];
  264.       $_SESSION['GO_SESSION']['email'] = $profile['email'];
  265.       $_SESSION['GO_SESSION']['username'] = $username;
  266.       $_SESSION['GO_SESSION']['password'] = $password;
  267.       $_SESSION['GO_SESSION']['old_password'] = $password;
  268.       $_SESSION['GO_SESSION']['thousands_seperator'] = $profile['thousands_seperator'];
  269.       $_SESSION['GO_SESSION']['decimal_seperator'] = $profile['decimal_seperator'];;
  270.       $_SESSION['GO_SESSION']['date_format'] = $profile['date_format'];
  271.       $_SESSION['GO_SESSION']['time_format'] = $profile['time_format'];
  272.       $_SESSION['GO_SESSION']['currency'] = $profile['currency'];
  273.       $_SESSION['GO_SESSION']['mail_client'] = $profile['mail_client'];
  274.       $_SESSION['GO_SESSION']['lastlogin'] = $profile['lastlogin'];
  275.       $_SESSION['GO_SESSION']['max_rows_list'] = $profile['max_rows_list'];
  276.       $_SESSION['GO_SESSION']['timezone'] = $profile['timezone'];
  277.       $_SESSION['GO_SESSION']['start_module'] = $profile['start_module'];
  278.       $_SESSION['GO_SESSION']['theme'] = $profile['theme'];
  279.       $_SESSION['GO_SESSION']['language'] = $profile['language'];
  280.       $_SESSION['GO_SESSION']['first_weekday'] = $profile['first_weekday'];
  281.  
  282.       $this->user_id = $user_id;
  283.       $this->logged_in = true;
  284.  
  285.       $logins = $profile["logins"] + 1;
  286.       $sql = "UPDATE users SET logins='$logins', lastlogin='".get_gmt_time()."' WHERE id='$this->user_id'";
  287.       $this->query($sql);
  288.       return true;
  289.     }else
  290.     {
  291.       return false;
  292.     }
  293.   }
  294.  
  295.   //Checks if a user is logged in. if not it attempts to log in
  296.   //based on stored cookies. If that fails it attempts to authenticate
  297.   //by http authentication
  298.   ///////////////////////////////////////////////////////////////
  299.   function authenticate($admin = false)
  300.   {
  301.     global $GO_CONFIG;
  302.  
  303.     $GO_AUTH_MAIL_SERVER_KEY = isset($_COOKIE['GO_AUTH_MAIL_SERVER_KEY']) ? $_COOKIE['GO_AUTH_MAIL_SERVER_KEY'] : '';
  304.  
  305.     if ($this->logged_in == false)
  306.     {
  307.       if (!isset($_COOKIE['GO_UN']) || !isset($_COOKIE['GO_PW']) || $_COOKIE['GO_UN'] =='' || $_COOKIE['GO_PW'] == '' || !$this->login($_COOKIE['GO_UN'], $_COOKIE['GO_PW'], $GO_AUTH_MAIL_SERVER_KEY))
  308.       {
  309.     header('Location: '.$GO_CONFIG->host.'index.php?return_to='.urlencode($_SERVER['REQUEST_URI']));
  310.     exit();
  311.       }
  312.     }
  313.  
  314.     if ($admin && !$this->has_admin_permission($this->user_id))
  315.     {
  316.       header("Location: ".$GO_CONFIG->host."error_docs/403.php");
  317.       exit();
  318.     }
  319.   }
  320.  
  321.   //Create and returns a new acl item.
  322.   //////////////////////////////////////////////////////////////////
  323.   function get_new_acl($description, $user_id=-1)
  324.   {
  325.     if ($user_id == -1)
  326.     {
  327.       $user_id = $this->user_id;
  328.     }
  329.     $id = $this->nextid("acl_items");
  330.     if ($id > 0)
  331.     {
  332.       $this->query("INSERT INTO acl_items (id, description, user_id) VALUES ('$id', '$description', '$user_id')");
  333.       return $id;
  334.     }else
  335.     {
  336.       return false;
  337.     }
  338.   }
  339.  
  340.   function user_owns_acl($user_id, $acl_id)
  341.   {
  342.     $this->query("SELECT user_id FROM acl_items WHERE id='$acl_id'");
  343.     if ($this->next_record())
  344.     {
  345.       if ($user_id == $this->f('user_id'))
  346.       {
  347.     return true;
  348.       }elseif($this->f('user_id') == '0')
  349.       {
  350.     return $this->has_admin_permission($user_id);
  351.       }
  352.     }
  353.     return false;
  354.   }
  355.  
  356.   //Deletes an acl
  357.   //////////////////////////////////////////////////////////////////
  358.   function delete_acl($acl_id)
  359.   {
  360.     $this->query("DELETE FROM acl WHERE acl_id='$acl_id'");
  361.     $this->query("DELETE FROM acl_items WHERE id='$acl_id'");
  362.     return true;
  363.   }
  364.  
  365.   //add user to acl
  366.   //////////////////////////////////////////////////////////////////
  367.   function add_user_to_acl($user_id,$acl_id)
  368.   {
  369.     $this->query("INSERT INTO acl (acl_id,user_id) VALUES ('$acl_id','$user_id')");
  370.     if ($this->affected_rows() > 0)
  371.     {
  372.       return true;
  373.     }else
  374.     {
  375.       return false;
  376.     }
  377.   }
  378.  
  379.   function delete_user_from_acl($user_id, $acl_id)
  380.   {
  381.     $sql = "DELETE FROM acl WHERE user_id='$user_id' AND acl_id='$acl_id'";
  382.     return $this->query($sql);
  383.   }
  384.  
  385.   //add group to acl
  386.   //////////////////////////////////////////////////////////////////
  387.   function add_group_to_acl($group_id,$acl_id)
  388.   {
  389.     $this->query("INSERT INTO acl (acl_id,group_id) VALUES ('$acl_id','$group_id')");
  390.     if ($this->affected_rows() > 0)
  391.     {
  392.       return true;
  393.     }else
  394.     {
  395.       return false;
  396.     }
  397.   }
  398.  
  399.   function delete_group_from_acl($group_id, $acl_id)
  400.   {
  401.     $sql = "DELETE FROM acl WHERE group_id='$group_id' AND acl_id='$acl_id'";
  402.     return $this->query($sql);
  403.   }
  404.  
  405.   function clear_acl($acl_id)
  406.   {
  407.     $this->query("DELETE FROM acl WHERE acl_id='$acl_id'");
  408.   }
  409.  
  410.   //Checks if a user has permission for an acl
  411.   /////////////////////////////////////////////////////////////////
  412.   function has_permission($user_id, $acl_id)
  413.   {
  414.     global $GO_CONFIG;
  415.  
  416.     if ($user_id > 0 && $acl_id > 0)
  417.     {
  418.       if ( $GO_CONFIG->auth_db_ldap_um )
  419.       {
  420.     $ldap = new ldap();
  421.     $ldap->connect();
  422.     $ldap->bind();
  423.  
  424. ## Get the UserID Entries from LDAP for checking
  425.     $ldap->search( "(uidNumber=$user_id)",
  426.         $GO_CONFIG->auth_db_ldap_basedn );
  427.     $ldap->next_entry();
  428.     $uid_array = $ldap->get_values("uid");
  429.  
  430.     $sql = "SELECT acl.group_id FROM acl WHERE acl.acl_id=".
  431.       $acl_id." AND acl.user_id='0' ORDER BY group_id ASC";
  432.     $this->query($sql);
  433.     $this->next_record();
  434.  
  435.     while ( $this->Record != "" )
  436.     {
  437.       $result = $this->Record;
  438.       $group_id = $result["group_id"];
  439.  
  440. ## If there are only the new UserIDs we can burst the search                    //require_once($GO_CONFIG->class_path."users.class.inc");
  441.       //$users = new users();
  442.       //$uid=$users->get_user($user_id); $uid=$uid["username"];
  443.       //$ldap->search(
  444.       //  "(&(gidNumber=$group_id)(memberUid=$uid))",
  445.       //  $GO_CONFIG->auth_db_ldap_basedn );
  446.       //$ldap->next_entry();
  447.       //if ( $ldap->get_values("gidNumber") )
  448.       //  return true;
  449.  
  450.       $ldap->search( "(gidNumber=$group_id)",
  451.           $GO_CONFIG->auth_db_ldap_basedn );
  452.       $ldap->next_entry();
  453.       $is_in_group = $ldap->get_values("memberUid");
  454.  
  455.       if ( $is_in_group )
  456.         foreach ( $uid_array as $value )
  457.           if ( @in_array( $value, $is_in_group ) )
  458.         return true;
  459.  
  460.       $this->next_record();
  461.     }
  462.       }
  463.  
  464.       $sql = "SELECT acl.acl_id FROM acl, users_groups WHERE".
  465.     " acl.acl_id='$acl_id' AND (acl.user_id='$user_id' OR".
  466.     " (acl.group_id=users_groups.group_id AND".
  467.     " users_groups.user_id='$user_id')) GROUP BY acl.acl_id";
  468.       $this->query($sql);
  469.  
  470.       if ($this->num_rows() > 0)
  471.     return true;
  472.     }
  473.     return false;
  474.   }
  475.  
  476.   function set_acl_owner($acl_id, $user_id)
  477.   {
  478.     return $this->query("UPDATE acl_items SET user_id='$user_id' WHERE id='$acl_id'");
  479.   }
  480.  
  481.   function has_admin_permission($user_id)
  482.   {
  483.     global $GO_CONFIG;
  484.     require_once($GO_CONFIG->class_path."groups.class.inc");
  485.     $groups = new groups;
  486.     return $groups->is_in_group($user_id, $this->group_root);
  487.   }
  488.  
  489.   function get_groups_in_acl($acl_id)
  490.   {
  491.     global $GO_CONFIG;
  492.     if ( $GO_CONFIG->auth_db_ldap_um )
  493.     {
  494.       $sql = "SELECT * FROM acl WHERE acl_id='$acl_id' AND user_id=0";
  495.       $this->query($sql);
  496.       return $this->num_rows();
  497.     } else {
  498.       $sql = "SELECT groups.* FROM groups INNER JOIN acl ON".
  499.     " acl.group_id=groups.id WHERE acl.acl_id='$acl_id'".
  500.     " ORDER BY groups.name";
  501.       $this->query($sql);
  502.       return $this->num_rows();
  503.     }
  504.   }
  505.  
  506.   function get_users_in_acl($acl_id)
  507.   {
  508.     global $GO_CONFIG;
  509.     if ( $GO_CONFIG->auth_db_ldap_um ) {
  510.       $sql = "SELECT * FROM acl WHERE acl_id='$acl_id' AND group_id=0";
  511.       $this->query($sql);
  512.       return $this->num_rows();
  513.     } else {
  514.       $sql = "SELECT users.* FROM users INNER JOIN acl ON acl.user_id=users.id WHERE acl.acl_id='$acl_id' ORDER BY users.first_name ASC, users.last_name ASC";
  515.       $this->query($sql);
  516.       return $this->num_rows();
  517.     }
  518.   }
  519.  
  520.   function user_in_acl($user_id, $acl_id)
  521.   {
  522.     $sql = "SELECT user_id FROM acl WHERE acl_id='$acl_id' AND user_id='$user_id'";
  523.     $this->query($sql);
  524.     if ($this->num_rows() > 0)
  525.     {
  526.       return true;
  527.     }else
  528.     {
  529.       return false;
  530.     }
  531.   }
  532.  
  533.   function user_is_visible($user_id)
  534.   {
  535.     if ($this->user_id == $user_id)
  536.       return true;
  537.  
  538.     $sql = "SELECT acl_id FROM users WHERE id='$user_id'";
  539.     $this->query($sql);
  540.     $this->next_record();
  541.     return $this->has_permission($this->user_id, $this->f("acl_id"));
  542.   }
  543.  
  544.   function group_in_acl($group_id, $acl_id)
  545.   {
  546.     $sql = "SELECT group_id FROM acl WHERE acl_id='$acl_id' AND group_id='$group_id'";
  547.     $this->query($sql);
  548.     if ($this->num_rows() > 0)
  549.     {
  550.       return true;
  551.     }else
  552.     {
  553.       return false;
  554.     }
  555.   }
  556.  
  557.   function get_acl_id($description)
  558.   {
  559.     $sql = "SELECT id FROM acl_items WHERE description='$description'";
  560.     $this->query($sql);
  561.     if ($this->next_record())
  562.     {
  563.       return $this->f('id');
  564.     }
  565.     return false;
  566.   }
  567.  
  568.   function copy_acl($sAcl, $dAcl)
  569.   {
  570.     global $GO_CONFIG;
  571.     require_once($GO_CONFIG->class_path."groups.class.inc");
  572.     $groups = new groups();
  573.  
  574.     $this->clear_acl($dAcl);
  575.  
  576.     $sql = "SELECT * FROM acl WHERE acl_id='$sAcl'";
  577.  
  578.     $security = new GO_SECURITY();
  579.     $this->query($sql);
  580.     while($this->next_record())
  581.     {
  582.       $new_security = new GO_SECURITY();
  583.       if ($this->f("group_id") != 0 && $groups->group_is_visible($this->user_id, $this->f("group_id")))
  584.       {
  585.     $new_security->add_group_to_acl($this->f("group_id"), $dAcl);
  586.       }
  587.  
  588.       if ($this->f("user_id") != 0 && ($security->user_is_visible($this->f("user_id")) || $this->f("user_id") == $this->user_id))
  589.       {
  590.     $new_security->add_user_to_acl($this->f("user_id"), $dAcl);
  591.       }
  592.     }
  593.   }
  594.  
  595.   /*deprecated*/
  596.  
  597.   function delete_user($user_id)
  598.   {
  599.     $sql = "DELETE FROM acl WHERE user_id='$user_id'";
  600.     $this->query($sql);
  601.   }
  602.  
  603.   function delete_group($group_id)
  604.   {
  605.     $sql = "DELETE FROM acl WHERE group_id='$group_id'";
  606.     $this->query($sql);
  607.   }
  608. }
  609. ?>
  610.