Ejemplo n.º 1
0
 /**
  *	create - Create new group.
  *
  *	This method should be called on empty Group object.
  *  
  *  @param	object	The User object.
  *  @param	string	The full name of the user.
  *  @param	string	The Unix name of the user.
  *  @param	string	The new group description.
  *  @param	int	The ID of the license to use.
  *  @param	string	The 'other' license to use if any.
  *  @param	string	The purpose of the group.
  */
 function create(&$user, $full_name, $unix_name, $description, $license, $license_other, $purpose, $unix_box = 'shell1', $scm_box = 'cvs1', $is_public = 1)
 {
     // $user is ignored - anyone can create pending group
     if ($this->getID() != 0) {
         $this->setError(_('Group::create: Group object already exists'));
         return false;
     } else {
         if (strlen($full_name) < 3) {
             $this->setError(_('Invalid full name'));
             return false;
         } else {
             if (!account_groupnamevalid($unix_name)) {
                 $this->setError(_('Invalid Unix name'));
                 return false;
             } else {
                 if (db_numrows(db_query("SELECT group_id FROM groups WHERE unix_group_name='{$unix_name}'")) > 0) {
                     $this->setError(_('Unix name already taken'));
                     return false;
                 } else {
                     if (strlen($purpose) < 10) {
                         $this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
                         return false;
                     } else {
                         if (strlen($purpose) > 1500) {
                             $this->setError(_('The Registration Purpose text is too long. Please make it smaller than 1500 bytes.'));
                             return false;
                         } else {
                             if (strlen($description) < 10) {
                                 $this->setError(_('Describe in a more comprehensive manner your project.'));
                                 return false;
                             } else {
                                 if (strlen($description) > 255) {
                                     $this->setError(_('Your project description is too long. Please make it smaller than 256 bytes.'));
                                     return false;
                                 } else {
                                     if (!$license) {
                                         $this->setError(_('You have not chosen a license'));
                                         return false;
                                     } else {
                                         if ($license != GROUP_LICENSE_OTHER && $license_other) {
                                             $this->setError(_('Conflicting licenses choice'));
                                             return false;
                                         } else {
                                             if ($license == GROUP_LICENSE_OTHER && strlen($license_other) < 50) {
                                                 $this->setError(_('Please give more comprehensive licensing description'));
                                                 return false;
                                             } else {
                                                 srand((double) microtime() * 1000000);
                                                 $random_num = rand(0, 1000000);
                                                 db_begin();
                                                 $res = db_query("\n\t\t\t\tINSERT INTO groups (\n\t\t\t\t\tgroup_name,\n\t\t\t\t\tis_public,\n\t\t\t\t\tunix_group_name,\n\t\t\t\t\tshort_description,\n\t\t\t\t\thttp_domain,\n\t\t\t\t\thomepage,\n\t\t\t\t\tstatus,\n\t\t\t\t\tunix_box,\n\t\t\t\t\tscm_box,\n\t\t\t\t\tlicense,\n\t\t\t\t\tregister_purpose,\n\t\t\t\t\tregister_time,\n\t\t\t\t\tlicense_other,\n                                        enable_anonscm,\n\t\t\t\t\trand_hash\n\t\t\t\t)\n\t\t\t\tVALUES (\n\t\t\t\t\t'" . htmlspecialchars($full_name) . "',\n\t\t\t\t\t'{$is_public}',\n\t\t\t\t\t'{$unix_name}',\n\t\t\t\t\t'" . htmlspecialchars($description) . "',\n\t\t\t\t\t'{$unix_name}." . $GLOBALS['sys_default_domain'] . "',\n\t\t\t\t\t'{$unix_name}." . $GLOBALS['sys_default_domain'] . "',\n\t\t\t\t\t'P',\n\t\t\t\t\t'{$unix_box}',\n\t\t\t\t\t'{$scm_box}',\n\t\t\t\t\t'{$license}',\n\t\t\t\t\t'" . htmlspecialchars($purpose) . "',\n\t\t\t\t\t" . time() . ",\n\t\t\t\t\t'" . htmlspecialchars($license_other) . "',\n\t\t\t\t\t'{$is_public}',\n\t\t\t\t\t'" . md5($random_num) . "'\n\t\t\t\t)\n\t\t\t");
                                                 if (!$res || db_affected_rows($res) < 1) {
                                                     $this->setError(sprintf(_('ERROR: Could not create group: %s'), db_error()));
                                                     db_rollback();
                                                     return false;
                                                 }
                                                 $id = db_insertid($res, 'groups', 'group_id');
                                                 if (!$id) {
                                                     $this->setError(sprintf(_('ERROR: Could not get group id: %s'), db_error()));
                                                     db_rollback();
                                                     return false;
                                                 }
                                                 //
                                                 // Now, make the user an admin
                                                 //
                                                 $sql = "INSERT INTO user_group ( user_id, group_id, admin_flags,\n\t\t\t\tcvs_flags, artifact_flags, forum_flags, role_id)\n\t\t\t\tVALUES ( " . $user->getID() . ", '{$id}', 'A', 1, 2, 2, 1)";
                                                 $res = db_query($sql);
                                                 if (!$res || db_affected_rows($res) < 1) {
                                                     $this->setError(sprintf(_('ERROR: Could not add admin to newly created group: %s'), db_error()));
                                                     db_rollback();
                                                     return false;
                                                 }
                                                 if (!$this->fetchData($id)) {
                                                     db_rollback();
                                                     return false;
                                                 }
                                                 $hook_params = array();
                                                 $hook_params['group'] = $this;
                                                 $hook_params['group_id'] = $this->getID();
                                                 $hook_params['group_name'] = $full_name;
                                                 $hook_params['unix_group_name'] = $unix_name;
                                                 plugin_hook("group_create", $hook_params);
                                                 db_commit();
                                                 $this->sendNewProjectNotificationEmail();
                                                 return true;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
// SourceForge: Breaking Down the Barriers to Open Source Development
// Copyright 1999-2000 (c) The SourceForge Crew
// http://sourceforge.net
//
// $Id: license.php,v 1.2 2003/11/13 11:29:26 helix Exp $
require "pre.php";
// Initial db and session library, opens session
require "vars.php";
require 'account.php';
session_require(array('isloggedin' => '1'));
if ($insert_group_name && $group_id && $rand_hash && $form_full_name && $form_unix_name) {
    /*
    	check for valid group name
    */
    $form_unix_name = strtolower($form_unix_name);
    if (!account_groupnamevalid($form_unix_name)) {
        exit_error("Invalid Group Name", $register_error);
    }
    /*
    	See if it's taken already
    */
    if (db_numrows(db_query("SELECT group_id FROM groups WHERE unix_group_name='{$form_unix_name}'")) > 0) {
        exit_error("Group Name Taken", "That group name already exists.");
    }
    // Check that username is not identical with an existing unix groupname (groups) helix 22.06.2001
    if (db_numrows(db_query("SELECT user_id FROM users WHERE user_name LIKE '{$form_unix_name}'")) > 0) {
        exit_error("Group Name Taken", "An identical user name already exists.");
    }
    // End of change helix 22.06.2001
    /*
    	Hash prevents them from updating a live, existing group account