* @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.
+ * @param bool Whether to send an email or not
*/
- function create(&$user, $group_name, $unix_name, $description, $license, $license_other, $purpose, $unix_box='shell1', $scm_box='cvs1', $is_public=1) {
+ function create(&$user, $group_name, $unix_name, $description, $purpose, $unix_box='shell1', $scm_box='cvs1', $is_public=1, $send_mail=true) {
// $user is ignored - anyone can create pending group
+ global $SYS;
if ($this->getID()!=0) {
$this->setError(_('Group::create: Group object already exists'));
return false;
} else if (!account_groupnamevalid($unix_name)) {
$this->setError(_('Invalid Unix name'));
return false;
+ } else if (!$SYS->sysUseUnixName($unix_name)) {
+ $this->setError(_('Unix name already taken'));
+ return false;
} else if (db_numrows(db_query_params('SELECT group_id FROM groups WHERE unix_group_name=$1',
array ($unix_name))) > 0) {
$this->setError(_('Unix name already taken'));
} 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);
status,
unix_box,
scm_box,
- license,
register_purpose,
register_time,
- license_other,
enable_anonscm,
rand_hash
)
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)',
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)',
array (htmlspecialchars ($group_name),
$is_public,
$unix_name,
'P',
$unix_box,
$scm_box,
- $license,
htmlspecialchars($purpose),
time(),
- htmlspecialchars($license_other),
$is_public,
md5($random_num) )) ;
if (!$res || db_affected_rows($res) < 1) {
//
// Now, make the user an admin
//
- $res=db_query_params ('INSERT INTO user_group ( user_id, group_id, admin_flags,
+ $res=db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags,
cvs_flags, artifact_flags, forum_flags, role_id)
VALUES ($1, $2, $3, $4, $5, $6, $7)',
array ($user->getID(),
plugin_hook ("group_create", $hook_params);
db_commit();
- $this->sendNewProjectNotificationEmail();
+ if ($send_mail) {
+ $this->sendNewProjectNotificationEmail();
+ }
return true;
}
}
*
* @param object User requesting operation (for access control).
* @param bool Whether group is publicly accessible (0/1).
- * @param string Project's license (string ident).
* @param int Group type (1-project, 2-foundry).
* @param string Machine on which group's home directory located.
* @param string Domain which serves group's WWW.
* @return status.
* @access public.
*/
- function updateAdmin(&$user, $is_public, $license, $type_id, $unix_box, $http_domain) {
+ function updateAdmin(&$user, $is_public, $type_id, $unix_box, $http_domain) {
$perm =& $this->getPermission($user);
if (!$perm || !is_object($perm)) {
$res = db_query_params ('
UPDATE groups
- SET is_public=$1, license=$2, type_id=$3,
- unix_box=$4, http_domain=$5
- WHERE group_id=$6',
+ SET is_public=$1, type_id=$2,
+ unix_box=$3, http_domain=$4
+ WHERE group_id=$5',
array ($is_public,
- $license,
$type_id,
$unix_box,
$http_domain,
if ($is_public != $this->isPublic()) {
$this->addHistory('is_public', $this->isPublic());
}
- if ($license != $this->data_array['license']) {
- $this->addHistory('license', $this->data_array['license']);
- }
if ($type_id != $this->data_array['type_id']) {
$this->addHistory('type_id', $this->data_array['type_id']);
}
* update - Update number of common properties.
*
* Unlike updateAdmin(), this function accessible to project admin.
+ *
+ * @param object User requesting operation (for access control).
+ * @param bool Whether group is publicly accessible (0/1).
+ * @param string Project's license (string ident).
+ * @param int Group type (1-project, 2-foundry).
+ * @param string Machine on which group's home directory located.
+ * @param string Domain which serves group's WWW.
+ * @return int status.
+ * @access public.
*/
function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,
- $use_pm,$use_pm_depend_box,$use_scm,$use_news,$use_docman,
- $new_doc_address,$send_all_docs,$logo_image_id,
- $use_ftp,$use_tracker,$use_frs,$use_stats,$is_public) {
+ $use_pm,$use_pm_depend_box,$use_scm,$use_news,$use_docman,
+ $new_doc_address,$send_all_docs,$logo_image_id,
+ $use_ftp,$use_tracker,$use_frs,$use_stats,$tags,$is_public) {
$perm =& $this->getPermission($user);
}
// Validate some values
- if (!$this->validateGroupName($group_name)) {
- return false;
+ if ($this->getPublicName() != $group_name) {
+ if (!$this->validateGroupName($group_name)) {
+ return false;
+ }
}
if ($new_doc_address) {
return false;
}
+ if ($this->setTags($tags) === false) {
+ db_rollback();
+ return false;
+ }
+
$hook_params = array ();
$hook_params['group'] = $this;
$hook_params['group_id'] = $this->getID();
}
}
+ function setUsesSCM ($booleanparam) {
+ db_begin () ;
+ $booleanparam = $booleanparam ? 1 : 0 ;
+ $res = db_query_params ('UPDATE groups SET use_scm=$1 WHERE group_id=$2',
+ array ($booleanparam, $this->getID()));
+ if ($res) {
+ $this->data_array['use_scm']=$booleanparam;
+ db_commit () ;
+ } else {
+ db_rollback ();
+ return false;
+ }
+ }
+
/**
* enablePserver - whether or not this group has opted to enable Pserver.
*
return $this->data_array['homepage'];
}
+ /**
+ * getTags - Tags of this project.
+ *
+ * @return string List of tags.
+ */
+ function getTags() {
+ $sql = 'SELECT name FROM project_tags WHERE group_id = $1';
+ $res = db_query_params($sql, array($this->getID()));
+ return join(', ', util_result_column_to_array($res));
+ }
+
+ /**
+ * setTags - Set tags of this project.
+ *
+ * @return string database result.
+ */
+ function setTags($tags) {
+ global $Language;
+
+ db_begin();
+ $sql='DELETE FROM project_tags WHERE group_id=$1';
+ $res=db_query_params($sql, array($this->getID()));
+ if (!$res) {
+ $this->setError('Deleting old tags: '.db_error());
+ db_rollback();
+ return false;
+ }
+ $inserted = array();
+ $tags_array = split('[;,]', $tags);
+ foreach ($tags_array as $tag) {
+ $tag = stripslashes($tag);
+ $tag = preg_replace('/[\t\r\n]/', ' ', $tag);
+ // Allowed caracteres: [A-Z][a-z][0-9] -_&'#+.
+ if (preg_match('/[^[:alnum:]| |\-|_|\&|\'|#|\+|\.]/', $tag)) {
+ $this->setError(_('Bad tag name, you only can use the following characters: [A-Z][a-z][0-9]-_&\'#+. and space'));
+ db_rollback();
+ return false;
+ }
+ $tag = trim($tag);
+ $tag = addslashes($tag);
+ if ($tag == '' || array_search($tag, $inserted) !== false) continue;
+ $sql='INSERT INTO project_tags (group_id,name) VALUES ($1, $2)';
+ $res=db_query_params($sql, array($this->getID(), $tag));
+ if (!$res) {
+ $this->setError(_('Setting tags: ').db_error());
+ db_rollback();
+ return false;
+ }
+ $inserted[] = $tag;
+ }
+ db_commit();
+ return true;
+ }
+
/**
* getPermission - Return a Permission for this Group and the specified User.
*
// Delete FRS Packages
//
//$frspf = new FRSPackageFactory($this);
- $res = db_query_params ('SELECT * FROM frs_package WHERE group_id=$A',
+ $res = db_query_params ('SELECT * FROM frs_package WHERE group_id=$1',
array ($this->getID())) ;
//echo 'frs_package'.db_error();
//$frsp_arr =& $frspf->getPackages();
/**
* addUser - controls adding a user to a group.
*
- * @param string Unix name of the user to add OR integer user_id.
+ * @param string Unix name of the user to add OR integer user_id.
* @param int The role_id this user should have.
* @return boolean success.
* @access public.
*/
- function addUser($user_unix_name,$role_id) {
+ function addUser($user_identifier,$role_id) {
global $SYS;
/*
Admins can add users to groups
/*
get user id for this user's unix_name
*/
- if (is_int ($user_unix_name)) {
- $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array ($user_unix_name)) ;
+ if (is_int ($user_identifier)) { // user_id or user_name
+ $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array ($user_identifier)) ;
} else {
- $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array ($user_unix_name)) ;
+ $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array ($user_identifier)) ;
}
if (db_numrows($res_newuser) > 0) {
//
//
// audit trail
//
- $this->addHistory('Added User',$user_unix_name);
+ $this->addHistory('Added User',$user_identifier);
db_commit();
return true;
}
FROM project_task pt, project_group_list pgl, project_assigned_to pat
WHERE pt.group_project_id = pgl.group_project_id
AND pat.project_task_id=pt.project_task_id
- AND pt.status_id=1 AND pgl.group_id=$1,
+ AND pt.status_id=1 AND pgl.group_id=$1
AND pat.assigned_to_id=$2)
AND assigned_to_id=100',
array ($this->getID(),
db_rollback();
return false;
}
+
+ $hook_params['group'] = $this;
+ $hook_params['group_id'] = $this->getID();
+ $hook_params['user'] = &user_get_object($user_id);
+ $hook_params['user_id'] = $user_id;
+ plugin_hook ("group_removeuser", $hook_params);
+
//audit trail
$this->addHistory('Removed User',$user_id);
}
return false;
}
- $hook_params['group'] = $this;
- $hook_params['group_id'] = $this->getID();
- $hook_params['user'] = &user_get_object($user_id);
- $hook_params['user_id'] = $user_id;
- plugin_hook ("group_removeuser", $hook_params);
$this->addHistory('Updated User',$user_id);
return true;
// Set Default Roles
//
//
+
+ $admin_group = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1 AND admin_flags=$2',
+ array ($this->getID(),
+ 'A')) ;
+ if (db_numrows($admin_group) > 0) {
+ $idadmin_group = db_result($admin_group,0,'user_id');
+ } else {
+ $idadmin_group = 1;
+ }
+
$role = new Role($this);
$todo = array_keys($role->defaults);
for ($c=0; $c<count($todo); $c++) {
$role = new Role($this);
- if (!$role->createDefault($todo[$c])) {
+ if (! ($role_id = $role->createDefault($todo[$c]))) {
$this->setError(sprintf(_('R%d: %s'),$c,$role->getErrorMessage()));
db_rollback();
setup_gettext_from_context();
return false;
}
+ $role = new Role($this, $role_id);
+ if ($role->getVal('projectadmin',0)=='A') {
+ $role->setUser($idadmin_group);
+ }
}
- $admin_group = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1 AND admin_flags=$2',
- array ($this->getID(),
- 'A')) ;
- if (db_numrows($admin_group) > 0) {
- $idadmin_group = db_result($admin_group,0,'user_id');
- } else {
- $idadmin_group = 1;
- }
//
//
$admin =& user_get_object($row_admins['user_id']);
setup_gettext_for_user ($admin) ;
- $message=stripcslashes(sprintf(_('Your project registration for %4$s has been approved.
+ $message=sprintf(_('Your project registration for %4$s has been approved.
Project Full Name: %1$s
Project Unix Name: %2$s
$this->getPublicName(),
$this->getUnixName(),
util_make_url ('/project/admin/?group_id='.$this->getID()),
- $GLOBALS['sys_name']));
+ $GLOBALS['sys_name']);
util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), $GLOBALS['sys_name']), $message);
$admin =& user_get_object($row_admins['user_id']);
setup_gettext_for_user ($admin) ;
- $response=stripcslashes(sprintf(_('Your project registration for %3$s has been denied.
+ $response=sprintf(_('Your project registration for %3$s has been denied.
Project Full Name: %1$s
Project Unix Name: %2$s
Reasons for negative decision:
-'), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name']));
+'), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name']);
// Check to see if they want to send a custom rejection response
if ($response_id == 0) {
- $response .= stripcslashes($message);
+ $response .= $message;
} else {
$response .= db_result (
db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array ($response_id)),
$admin =& user_get_object(db_result($res,$i,'user_id'));
setup_gettext_for_user ($admin) ;
- $message=stripcslashes(sprintf(_('New %1$s Project Submitted
+ $message=sprintf(_('New %1$s Project Submitted
Project Full Name: %2$s
Submitted Description: %3$s
-License: %4$s
-Submitter: %6$s (%7$s)
+Submitter: %5$s (%6$s)
Please visit the following URL to approve or reject this project:
-%5$s'),
+%4$s'),
$GLOBALS['sys_name'],
$this->getPublicName(),
util_unconvert_htmlspecialchars($this->getRegistrationPurpose()),
- $this->getLicenseName(),
util_make_url ('/admin/approve-pending.php'),
$submitter->getRealName(),
- $submitter->getUnixName()));
+ $submitter->getUnixName());
util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
setup_gettext_from_context();
}
$email = $submitter->getEmail() ;
setup_gettext_for_user ($submitter) ;
- $message=stripcslashes(sprintf(_('New %1$s Project Submitted
+ $message=sprintf(_('New %1$s Project Submitted
Project Full Name: %2$s
Submitted Description: %3$s
-License: %4$s
-The %1$s admin team will now examine your project submission. You will be notified of their decision.'), $GLOBALS['sys_name'], $this->getPublicName(), util_unconvert_htmlspecialchars($this->getRegistrationPurpose()), $this->getLicenseName(), $GLOBALS['sys_default_domain']));
+The %1$s admin team will now examine your project submission. You will be notified of their decision.'), $GLOBALS['sys_name'], $this->getPublicName(), util_unconvert_htmlspecialchars($this->getRegistrationPurpose()), $GLOBALS['sys_default_domain']);
util_send_message($email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
setup_gettext_from_context();