<?php
/**
- * Group object
+ * FusionForge groups
*
- * Sets up database results and preferences for a group and abstracts this info.
+ * Copyright 1999-2001, VA Linux Systems, Inc.
+ * Copyright 2009, Roland Mas
*
- * Foundry.class.php and Project.class.php call this.
+ * This file is part of FusionForge.
*
- * Project.class.php contains all the deprecated API from the old group.php file
- *
- * DEPENDS on user.php being present and setup properly
- *
- * GENERALLY YOU SHOULD NEVER INSTANTIATE THIS OBJECT DIRECTLY
- * USE group_get_object() to instantiate properly
- *
- * @version $Id$
- * @author Tim Perdue <tperdue@valinux.com>
- * @date 2000-08-28
- *
- * This file is part of GForge.
- *
- * GForge 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.
- *
- * GForge is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * FusionForge 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.
+ *
+ * FusionForge is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with GForge; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with FusionForge; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
*/
-require_once('common/tracker/ArtifactTypes.class.php');
-require_once('common/tracker/ArtifactTypeFactory.class.php');
-require_once('common/forum/Forum.class.php');
-require_once('common/forum/ForumFactory.class.php');
-require_once('common/pm/ProjectGroup.class.php');
-require_once('common/pm/ProjectGroupFactory.class.php');
-require_once('common/include/Role.class.php');
-require_once('common/frs/FRSPackage.class.php');
-require_once('common/docman/DocumentGroup.class.php');
-require_once('common/mail/MailingList.class.php');
-require_once('common/mail/MailingListFactory.class.php');
-require_once('common/survey/SurveyFactory.class.php');
-require_once('common/survey/SurveyQuestionFactory.class.php');
-require_once('www/include/BaseLanguage.class.php');
+require_once $gfcommon.'tracker/ArtifactTypes.class.php';
+require_once $gfcommon.'tracker/ArtifactTypeFactory.class.php';
+require_once $gfcommon.'forum/Forum.class.php';
+require_once $gfcommon.'forum/ForumFactory.class.php';
+require_once $gfcommon.'pm/ProjectGroup.class.php';
+require_once $gfcommon.'pm/ProjectGroupFactory.class.php';
+require_once $gfcommon.'include/Role.class.php';
+require_once $gfcommon.'frs/FRSPackage.class.php';
+require_once $gfcommon.'docman/DocumentGroup.class.php';
+require_once $gfcommon.'mail/MailingList.class.php';
+require_once $gfcommon.'mail/MailingListFactory.class.php';
+require_once $gfcommon.'survey/SurveyFactory.class.php';
+require_once $gfcommon.'survey/SurveyQuestionFactory.class.php';
+require_once $gfcommon.'include/gettext.php';
//the license_id of "Other/proprietary" license
define('GROUP_LICENSE_OTHER',126);
function & group_get_licenses() {
global $LICENSE_NAMES;
if(empty($LICENSE_NAMES)) {
- $result = db_query('select * from licenses');
+ $result = db_query_params ('select * from licenses', array());
while($data = db_fetch_array($result)) {
$LICENSE_NAMES[$data['license_id']] = $data['license_name'];
}
if ($res) {
//the db result handle was passed in
} else {
- $res=db_query("SELECT * FROM groups WHERE group_id='$group_id'");
+ $res = db_query_params ('SELECT * FROM groups WHERE group_id=$1', array ($group_id)) ;
}
if (!$res || db_numrows($res) < 1) {
$GROUP_OBJ["_".$group_id."_"]=false;
}
}
if (count($fetch) > 0) {
- $res=db_query("SELECT * FROM groups WHERE group_id IN ('".implode($fetch,'\',\'') ."')");
+ $res=db_query_params ('SELECT * FROM groups WHERE group_id = ANY ($1)',
+ array (db_int_array_to_any_clause ($fetch))) ;
while ($arr =& db_fetch_array($res)) {
$GROUP_OBJ["_".$arr['group_id']."_"] = new Group($arr['group_id'],$arr);
$return[] =& $GROUP_OBJ["_".$arr['group_id']."_"];
}
function &group_get_object_by_name($groupname) {
- $res=db_query("SELECT * FROM groups WHERE unix_group_name='$groupname'");
+ $res=db_query_params('SELECT * FROM groups WHERE unix_group_name=$1', array ($groupname)) ;
return group_get_object(db_result($res,0,'group_id'),$res);
}
function &group_get_objects_by_name($groupname_arr) {
- $sql="SELECT group_id FROM groups WHERE unix_group_name IN ('".implode($groupname_arr,'\',\'')."')";
- $res=db_query($sql);
+ $res=db_query_params ('SELECT group_id FROM groups WHERE unix_group_name = ANY ($1)',
+ array (db_string_array_to_any_clause ($groupname_arr))
+ );
$arr =& util_result_column_to_array($res,0);
return group_get_objects($arr);
}
+function &group_get_object_by_publicname($groupname) {
+ $res=db_query_params ('SELECT * FROM groups WHERE lower(group_name) LIKE $1',
+ array (htmlspecialchars (strtolower ($groupname)))) ;
+
+ return group_get_object(db_result($res,0,'group_id'),$res);
+}
+
class Group extends Error {
/**
* Associative array of data from db.
*/
var $membersArr;
- /**
- * Permissions data row from db.
- *
- * @var array $perm_data_array.
- */
- var $perm_data_array;
-
/**
* Whether the use is an admin/super user of this project.
*
/**
* Associative array of data for plugins.
*
- * @var array $plugins_array.
+ * @var array $plugins_data.
+ */
+ var $plugins_data;
+
+
+ /**
+ * Associative array of data for the group menu.
+ *
+ * @var array $menu_data.
*/
- var $plugins_array;
+ var $menu_data;
/**
* Group - Group object constructor - use group_get_object() to instantiate.
} else {
if (db_numrows($res) < 1) {
//function in class we extended
- $this->setError('Group Not Found');
+ $this->setError(_('Group Not Found'));
$this->data_array=array();
return false;
} else {
$perm =& $this->getPermission(session_get_user());
if (!$perm || !is_object($perm) || !$perm->isMember()) {
- // cannot use $Language as it is not created yet
- $this->setError('Permission denied', ERROR__PERMISSION_DENIED_ERROR);
+ $this->setError(_('Permission denied'), ERROR__PERMISSION_DENIED_ERROR);
return false;
}
}
* @param int The group_id.
*/
function fetchData($group_id) {
- $res = db_query("SELECT * FROM groups WHERE group_id='$group_id'");
+ $res = db_query_params ('SELECT * FROM groups WHERE group_id=$1',
+ array ($group_id));
if (!$res || db_numrows($res) < 1) {
- $this->setError('fetchData():: '.db_error());
+ $this->setError(sprintf(_('fetchData():: %s'),db_error()));
return false;
}
$this->data_array =& db_fetch_array($res);
* @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, $full_name, $unix_name, $description, $license, $license_other, $purpose, $unix_box='shell1', $scm_box='cvs1') {
+ 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");
+ $this->setError(_('Group::create: Group object already exists'));
return false;
- } else if (strlen($full_name)<3) {
- $this->setError(_('Invalid full name'));
+ } else if (!$this->validateGroupName($group_name)) {
return false;
} else if (!account_groupnamevalid($unix_name)) {
- $this->setError(_('Invalid 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) {
+ } 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'));
return false;
} else if (strlen($purpose)<10) {
} 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 do not have 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);
db_begin();
- $res = db_query("
+ $res = db_query_params ('
INSERT INTO groups (
group_name,
is_public,
status,
unix_box,
scm_box,
- license,
register_purpose,
register_time,
- license_other,
+ enable_anonscm,
rand_hash
)
- VALUES (
- '".htmlspecialchars($full_name)."',
- 1,
- '$unix_name',
- '".htmlspecialchars($description)."',
- '$unix_name.".$GLOBALS['sys_default_domain']."',
- '$unix_name.".$GLOBALS['sys_default_domain']."',
- 'P',
- '$unix_box',
- '$scm_box',
- '$license',
- '".htmlspecialchars($purpose)."',
- ".time().",
- '".htmlspecialchars($license_other)."',
- '".md5($random_num)."'
- )
- ");
-
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)',
+ array (htmlspecialchars ($group_name),
+ $is_public,
+ $unix_name,
+ htmlspecialchars($description),
+ $unix_name.".".$GLOBALS['sys_default_domain'],
+ $unix_name.".".$GLOBALS['sys_default_domain'],
+ 'P',
+ $unix_box,
+ $scm_box,
+ htmlspecialchars($purpose),
+ time(),
+ $is_public,
+ md5($random_num) )) ;
if (!$res || db_affected_rows($res) < 1) {
- $this->setError('ERROR: Could not create group: '.db_error());
+ $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('ERROR: Could not get group id: '.db_error());
+ $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,
+ $res=db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags,
cvs_flags, artifact_flags, forum_flags, role_id)
- VALUES ( ".$user->getID().", '$id', 'A', 1, 2, 2, 1)";
-
- $res=db_query($sql);
+ VALUES ($1, $2, $3, $4, $5, $6, $7)',
+ array ($user->getID(),
+ $id,
+ 'A',
+ 1,
+ 2,
+ 2,
+ 1));
if (!$res || db_affected_rows($res) < 1) {
- $this->setError('ERROR: Could not add admin to newly created group: '.db_error());
+ $this->setError(sprintf(_('ERROR: Could not add admin to newly created group: %s'),db_error()));
db_rollback();
return false;
}
db_rollback();
return false;
}
+
+ $hook_params = array ();
+ $hook_params['group'] = $this;
+ $hook_params['group_id'] = $this->getID();
+ $hook_params['group_name'] = $group_name;
+ $hook_params['unix_group_name'] = $unix_name;
+ 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.
+ * @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)) {
db_begin();
- $res = db_query("
+ $res = db_query_params ('
UPDATE groups
- SET is_public='$is_public',
- license='$license',type_id='$type_id',
- unix_box='$unix_box',http_domain='$http_domain'
- WHERE group_id='".$this->getID()."'
- ");
+ SET is_public=$1, type_id=$2,
+ unix_box=$3, http_domain=$4
+ WHERE group_id=$5',
+ array ($is_public,
+ $type_id,
+ $unix_box,
+ $http_domain,
+ $this->getID())) ;
if (!$res || db_affected_rows($res) < 1) {
- $this->setError('ERROR: DB: Could not change group properties: '.db_error());
+ $this->setError(_('ERROR: DB: Could not change group properties: %s'),db_error());
db_rollback();
return false;
}
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']);
}
* @param string Machine on which group's home directory located.
* @param string Domain which serves group's WWW.
* @return int status.
- * @access public.
+ * @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,
- $enable_pserver,$enable_anonscm,
- $use_ftp,$use_tracker,$use_frs,$use_stats) {
+ $use_ftp,$use_tracker,$use_frs,$use_stats,$tags,$is_public) {
$perm =& $this->getPermission($user);
}
// Validate some values
- if (!$group_name) {
- $this->setError('Invalid Group Name');
- return false;
+ if ($this->getPublicName() != $group_name) {
+ if (!$this->validateGroupName($group_name)) {
+ return false;
+ }
}
if ($new_doc_address) {
$invalid_mails = validate_emails($new_doc_address);
if (count($invalid_mails) > 0) {
- $this->setError('New Doc Address(es) Appeared Invalid: '.implode(',',$invalid_mails));
+ $this->setError(sprintf (ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
return false;
}
}
$send_all_docs=0;
}
+ $homepage = ltrim($homepage);
if (!$homepage) {
$homepage=$GLOBALS['sys_default_domain'].'/projects/'.$this->getUnixName().'/';
}
- if (strlen($short_description)>255) {
- $this->setError('Error updating project information: Maximum length for Project Description is 255 chars.');
+ if (strlen(htmlspecialchars($short_description))>255) {
+ $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
return false;
}
db_begin();
//XXX not yet actived logo_image_id='$logo_image_id',
- $sql = "
- UPDATE groups
- SET
- group_name='".htmlspecialchars($group_name)."',
- homepage='$homepage',
- short_description='".htmlspecialchars($short_description)."',
- use_mail='$use_mail',
- use_survey='$use_survey',
- use_forum='$use_forum',
- use_pm='$use_pm',
- use_pm_depend_box='$use_pm_depend_box',
- use_scm='$use_scm',
- use_news='$use_news',
- use_docman='$use_docman',
- new_doc_address='$new_doc_address',
- send_all_docs='$send_all_docs',
- ";
- if ($enable_pserver != '') {
- $sql .= "
- enable_pserver='$enable_pserver',
- ";
- }
- if ($enable_anonscm != '') {
- $sql .= "
- enable_anonscm='$enable_anonscm',
- ";
- }
- $sql .= "
- use_ftp='$use_ftp',
- use_tracker='$use_tracker',
- use_frs='$use_frs',
- use_stats='$use_stats'
- WHERE group_id='".$this->getID()."'
- ";
- $res = db_query($sql);
+ $res = db_query_params ('UPDATE groups
+ SET group_name=$1,
+ homepage=$2,
+ short_description=$3,
+ use_mail=$4,
+ use_survey=$5,
+ use_forum=$6,
+ use_pm=$7,
+ use_pm_depend_box=$8,
+ use_scm=$9,
+ use_news=$10,
+ use_docman=$11,
+ is_public=$12,
+ new_doc_address=$13,
+ send_all_docs=$14,
+ use_ftp=$15,
+ use_tracker=$16,
+ use_frs=$17,
+ use_stats=$18
+ WHERE group_id=$19',
+ array (htmlspecialchars($group_name),
+ $homepage,
+ htmlspecialchars($short_description),
+ $use_mail,
+ $use_survey,
+ $use_forum,
+ $use_pm,
+ $use_pm_depend_box,
+ $use_scm,
+ $use_news,
+ $use_docman,
+ $is_public,
+ $new_doc_address,
+ $send_all_docs,
+ $use_ftp,
+ $use_tracker,
+ $use_frs,
+ $use_stats,
+ $this->getID() )) ;
if (!$res) {
- $this->setError('Error updating project information: '.db_error());
+ $this->setError(sprintf(_('Error updating project information: %s'), db_error()));
db_rollback();
return false;
}
+ if ($this->setTags($tags) === false) {
+ db_rollback();
+ return false;
+ }
+
+ $hook_params = array ();
+ $hook_params['group'] = $this;
+ $hook_params['group_id'] = $this->getID();
+ $hook_params['group_homepage'] = $homepage;
+ $hook_params['group_name'] = htmlspecialchars($group_name);
+ $hook_params['group_description'] = htmlspecialchars($short_description);
+ plugin_hook ("group_update", $hook_params);
+
// Log the audit trail
$this->addHistory('Changed Public Info', '');
* @param object User requesting operation (for access control).
* @param string Status value.
* @return boolean success.
- * @access public.
+ * @access public
*/
function setStatus(&$user, $status) {
global $SYS;
$allowed_status_changes = array(
'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
'IP'=>1,'HA'=>1,'HD'=>1
- );
+ );
// Check that status transition is valid
if ($this->getStatus() != $status
&& !$allowed_status_changes[$this->getStatus().$status]) {
- $this->setError('Invalid Status Change');
+ $this->setError(_('Invalid Status Change'));
return false;
}
db_begin();
- $res = db_query("UPDATE groups
- SET status='$status'
- WHERE group_id='". $this->getID()."'");
+ $res = db_query_params ('UPDATE groups
+ SET status=$1
+ WHERE group_id=$2', array ($status, $this->getID())) ;
if (!$res || db_affected_rows($res) < 1) {
- $this->setError('ERROR: DB: Could not change group status: '.db_error());
+ $this->setError(sprintf(_('ERROR: DB: Could not change group status: %s'),db_error()));
db_rollback();
return false;
}
}
}
+ $hook_params = array ();
+ $hook_params['group'] = $this;
+ $hook_params['group_id'] = $this->getID();
+ $hook_params['status'] = $status;
+ plugin_hook ("group_setstatus", $hook_params);
+
db_commit();
// Log the audit trail
if ($status != $this->getStatus()) {
- $this->addHistory('status', $this->getStatus());
+ $this->addHistory('Status', $this->getStatus());
}
$this->data_array['status'] = $status;
* @param string The name of the new SCM_BOX
*/
function setSCMBox($scm_box) {
+
+ if ($scm_box == $this->data_array['scm_box']) {
+ return true;
+ }
if ($scm_box) {
db_begin();
- $sql = "UPDATE groups SET scm_box = '$scm_box' WHERE group_id = ".$this->getID();
- $res = db_query($sql);
+ $res = db_query_params ('UPDATE groups SET scm_box=$1 WHERE group_id=$2', array ($scm_box, $this->getID ()));
if ($res) {
$this->addHistory('scm_box', $this->data_array['scm_box']);
$this->data_array['scm_box']=$scm_box;
return true;
} else {
db_rollback();
- $this->setError('Couldn\'t insert SCM_BOX to database');
+ $this->setError(_("Couldn't insert SCM_BOX to database"));
return false;
}
} else {
- $this->setError(_('SCM Box can\'t be empty'));
+ $this->setError(_("SCM Box can't be empty"));
return false;
}
}
*/
function &getAdmins() {
// this function gets all group admins in order to send Jabber and mail messages
- $q = "SELECT user_id FROM user_group WHERE admin_flags = 'A' AND group_id = ".$this->getID();
- $res = db_query($q);
+ $res = db_query_params ('SELECT user_id FROM user_group WHERE admin_flags=$1 AND group_id=$2',
+ array ('A', $this->getID()));
$user_ids=util_result_column_to_array($res);
return user_get_objects($user_ids);
}
function SetUsesAnonSCM ($booleanparam) {
db_begin () ;
$booleanparam = $booleanparam ? 1 : 0 ;
- $sql = "UPDATE groups SET enable_anonscm = $booleanparam WHERE group_id = ".$this->getID() ;
- $res = db_query($sql);
+ $res = db_query_params ('UPDATE groups SET enable_anonscm=$1 WHERE group_id=$2',
+ array ($booleanparam, $this->getID()));
if ($res) {
$this->data_array['enable_anonscm']=$booleanparam;
db_commit () ;
}
}
+ 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.
*
function SetUsesPserver ($booleanparam) {
db_begin () ;
$booleanparam = $booleanparam ? 1 : 0 ;
- $sql = "UPDATE groups SET enable_pserver = $booleanparam WHERE group_id = ".$this->getID() ;
- $res = db_query($sql);
+ $res = db_query_params ('UPDATE groups SET enable_pserver=$1 WHERE group_id=$2',
+ array ($booleanparam, $this->getID()));
if ($res) {
$this->data_array['enable_pserver']=$booleanparam;
db_commit () ;
function getPlugins() {
if (!isset($this->plugins_data)) {
$this->plugins_data = array () ;
- $sql="SELECT group_plugin.plugin_id, plugins.plugin_name
- FROM group_plugin, plugins
- WHERE group_plugin.group_id=".$this->getID()."
- AND group_plugin.plugin_id = plugins.plugin_id" ;
- $res=db_query($sql);
+ $res = db_query_params ('SELECT group_plugin.plugin_id, plugins.plugin_name
+ FROM group_plugin, plugins
+ WHERE group_plugin.group_id=$1
+ AND group_plugin.plugin_id=plugins.plugin_id', array ($this->getID()));
$rows = db_numrows($res);
for ($i=0; $i<$rows; $i++) {
// State is already good, returning
return true ;
}
- $sql="SELECT plugin_id
- FROM plugins
- WHERE plugin_name = '" . $pluginname . "'" ;
- $res=db_query($sql);
+ $res = db_query_params ('SELECT plugin_id FROM plugins WHERE plugin_name=$1',
+ array ($pluginname));
$rows = db_numrows($res);
if ($rows == 0) {
// Error: no plugin by that name
// Invalidate cache
unset ($this->plugins_data) ;
if ($val) {
- $sql="INSERT INTO group_plugin (group_id, plugin_id)
- VALUES (". $this->getID() . ", ". $plugin_id .")" ;
- $res=db_query($sql);
+ $res = db_query_params ('INSERT INTO group_plugin (group_id, plugin_id) VALUES ($1, $2)',
+ array ($this->getID(),
+ $plugin_id));
return $res ;
} else {
- $sql="DELETE FROM group_plugin
- WHERE group_id = ". $this->getID() . "
- AND plugin_id = ". $plugin_id ;
- $res=db_query($sql);
+ $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1 AND plugin_id=$2',
+ array ($this->getID(),
+ $plugin_id));
return $res ;
}
}
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) {
+ 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.
*
$this->getID() == 1 ||
$this->getID() == $GLOBALS['sys_stats_group'] ||
$this->getID() == $GLOBALS['sys_peer_rating_group']) {
- $this->setError('Cannot Delete System Group');
+ $this->setError(_('Cannot Delete System Group'));
return false;
}
$perm =& $this->getPermission( session_get_user() );
$members =& $this->getMembers();
for ($i=0; $i<count($members); $i++) {
$this->removeUser($members[$i]->getID());
-//echo 'RemoveMembers'.db_error();
}
//
// Delete Trackers
$at_arr =& $atf->getArtifactTypes();
for ($i=0; $i<count($at_arr); $i++) {
if (!is_object($at_arr[$i])) {
- echo "Not Object: ArtifactType: ".$i;
+ printf (_("Not Object: ArtifactType: %d"),$i);
continue;
}
$at_arr[$i]->delete(1,1);
-//echo 'ArtifactTypeFactory'.db_error();
}
//
// Delete Forums
$f_arr =& $ff->getForums();
for ($i=0; $i<count($f_arr); $i++) {
if (!is_object($f_arr[$i])) {
- echo "Not Object: Forum: ".$i;
+ printf (_("Not Object: Forum: %d"),$i);
continue;
}
$f_arr[$i]->delete(1,1);
$pg_arr =& $pgf->getProjectGroups();
for ($i=0; $i<count($pg_arr); $i++) {
if (!is_object($pg_arr[$i])) {
- echo "Not Object: ProjectGroup: ".$i;
+ printf (_("Not Object: ProjectGroup: %d"),$i);
continue;
}
$pg_arr[$i]->delete(1,1);
// Delete FRS Packages
//
//$frspf = new FRSPackageFactory($this);
- $res=db_query("SELECT * FROM frs_package WHERE group_id='".$this->getID()."'");
+ $res = db_query_params ('SELECT * FROM frs_package WHERE group_id=$1',
+ array ($this->getID())) ;
//echo 'frs_package'.db_error();
//$frsp_arr =& $frspf->getPackages();
while ($arr = db_fetch_array($res)) {
// Delete news
//
$news_group=&group_get_object($GLOBALS['sys_news_group']);
- $res=db_query("SELECT forum_id FROM news_bytes WHERE group_id='".$this->getID()."'");
+ $res = db_query_params ('SELECT forum_id FROM news_bytes WHERE group_id=$1',
+ array ($this->getID())) ;
for ($i=0; $i<db_numrows($res); $i++) {
$Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
if (!$Forum->delete(1,1)) {
- echo "Could Not Delete News Forum: ".$Forum->getID();
+ printf (_("Could Not Delete News Forum: %d"),$Forum->getID());
}
}
- $res=db_query("DELETE FROM news_bytes WHERE group_id='".$this->getID()."'");
+ $res = db_query_params ('DELETE FROM news_bytes WHERE group_id=$1',
+ array ($this->getID())) ;
//
// Delete docs
//
- $res=db_query("DELETE FROM doc_data WHERE group_id='".$this->getID()."'");
+ $res = db_query_params ('DELETE FROM doc_data WHERE group_id=$1',
+ array ($this->getID())) ;
//echo 'doc_data'.db_error();
- $res=db_query("DELETE FROM doc_groups WHERE group_id='".$this->getID()."'");
+ $res = db_query_params ('DELETE FROM doc_groups WHERE group_id=$1',
+ array ($this->getID())) ;
//echo 'doc_groups'.db_error();
+
+ //
+ // Delete Tags
+ //
+ $res=db_query_params('DELETE FROM project_tags WHERE group_id=$1', array($this->getID()));
+
//
// Delete group history
//
- $res=db_query("DELETE FROM group_history WHERE group_id='".$this->getID()."'");
+ $res = db_query_params ('DELETE FROM group_history WHERE group_id=$1',
+ array ($this->getID())) ;
//echo 'group_history'.db_error();
//
// Delete group plugins
//
- $res=db_query("DELETE FROM group_plugin WHERE group_id='".$this->getID()."'");
+ $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1',
+ array ($this->getID())) ;
//echo 'group_plugin'.db_error();
//
// Delete group cvs stats
//
- $res=db_query("DELETE FROM stats_cvs_group WHERE group_id='".$this->getID()."'");
+ $res = db_query_params ('DELETE FROM stats_cvs_group WHERE group_id=$1',
+ array ($this->getID())) ;
//echo 'stats_cvs_group'.db_error();
//
// Delete Surveys
$s_arr =& $sf->getSurveys();
for ($i=0; $i<count($s_arr); $i++) {
if (!is_object($s_arr[$i])) {
- echo "Not Object: Survey: ".$i;
+ printf (_("Not Object: Survey: %d"),$i);
continue;
}
$s_arr[$i]->delete();
$sq_arr =& $sqf->getSurveyQuestions();
for ($i=0; $i<count($sq_arr); $i++) {
if (!is_object($sq_arr[$i])) {
- echo "Not Object: SurveyQuestion: ".$i;
+ printf (_("Not Object: SurveyQuestion: %d"),$i);
continue;
}
$sq_arr[$i]->delete();
$ml_arr =& $mlf->getMailingLists();
for ($i=0; $i<count($ml_arr); $i++) {
if (!is_object($ml_arr[$i])) {
- echo "Not Object: MailingList: ".$i;
+ printf (_("Not Object: MailingList: %d"),$i);
continue;
}
if (!$ml_arr[$i]->delete(1,1)) {
- $this->setError(_('Could not delete properly the mailing list'));
+ $this->setError(_('Could not properly delete the mailing list'));
}
//echo 'MailingListFactory'.db_error();
}
//
// Delete trove
//
- $res=db_query("DELETE FROM trove_group_link WHERE group_id='".$this->getID()."'");
- $res=db_query("DELETE FROM trove_agg WHERE group_id='".$this->getID()."'");
+ $res = db_query_params ('DELETE FROM trove_group_link WHERE group_id=$1',
+ array ($this->getID())) ;
+ $res = db_query_params ('DELETE FROM trove_agg WHERE group_id=$1',
+ array ($this->getID())) ;
//
// Delete counters
//
- $res=db_query("DELETE FROM project_sums_agg WHERE group_id='".$this->getID()."'");
+ $res = db_query_params ('DELETE FROM project_sums_agg WHERE group_id=$1',
+ array ($this->getID())) ;
//echo 'project_sums_agg'.db_error();
- $res=db_query("INSERT INTO deleted_groups (
- unix_group_name,delete_date,isdeleted) VALUES
- ('".$this->getUnixName()."','".time()."','0')");
+ $res = db_query_params ('INSERT INTO deleted_groups (unix_group_name,delete_date,isdeleted) VALUES ($1, $2, $3)',
+ array ($this->getUnixName(),
+ time(),
+ 0)) ;
//echo 'InsertIntoDeleteQueue'.db_error();
- $res=db_query("DELETE FROM groups WHERE group_id='".$this->getID()."'");
+ $res = db_query_params ('DELETE FROM groups WHERE group_id=$1',
+ array ($this->getID())) ;
//echo 'DeleteGroup'.db_error();
db_commit();
if (!$res) {
return false;
}
+
+ $hook_params = array ();
+ $hook_params['group'] = $this;
+ $hook_params['group_id'] = $this->getID();
+ plugin_hook ("group_delete", $hook_params);
+
if (isset($GLOBALS['sys_upload_dir']) && $this->getUnixName()) {
exec('/bin/rm -rf '.$GLOBALS['sys_upload_dir'].'/'.$this->getUnixName().'/');
}
//
// Delete reporting
//
- $res=db_query("DELETE FROM rep_group_act_weekly WHERE group_id='".$this->getID()."'");
-//echo 'rep_group_act_weekly'.db_error();
- $res=db_query("DELETE FROM rep_group_act_monthly WHERE group_id='".$this->getID()."'");
+ $res = db_query_params ('DELETE FROM rep_group_act_monthly WHERE group_id=$1',
+ array ($this->getID())) ;
//echo 'rep_group_act_monthly'.db_error();
- $res=db_query("DELETE FROM rep_group_act_daily WHERE group_id='".$this->getID()."'");
+ $res = db_query_params ('DELETE FROM rep_group_act_weekly WHERE group_id=$1',
+ array ($this->getID())) ;
+//echo 'rep_group_act_weekly'.db_error();
+ $res = db_query_params ('DELETE FROM rep_group_act_daily WHERE group_id=$1',
+ array ($this->getID())) ;
//echo 'rep_group_act_daily'.db_error();
unset($this->data_array);
return true;
* @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.
+ * @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 (eregi('[^0-9]',$user_unix_name)) {
- $res_newuser = db_query("SELECT * FROM users WHERE user_name='". strtolower($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("SELECT * FROM users WHERE user_id='". intval($user_unix_name) ."'");
+ $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array ($user_identifier)) ;
}
if (db_numrows($res_newuser) > 0) {
//
// make sure user is active
//
if (db_result($res_newuser,0,'status') != 'A') {
- $this->setError('User is not active. Only active users can be added.');
+ $this->setError(_('User is not active. Only active users can be added.'));
db_rollback();
return false;
}
//
// if not already a member, add them
//
- $res_member = db_query("SELECT user_id
+ $res_member = db_query_params ('SELECT user_id
FROM user_group
- WHERE user_id='$user_id' AND group_id='". $this->getID() ."'");
+ WHERE user_id=$1 AND group_id=$2',
+ array ($user_id, $this->getID())) ;
if (db_numrows($res_member) < 1) {
//
// Create this user's row in the user_group table
//
- $res=db_query("INSERT INTO user_group
+ $res = db_query_params ('INSERT INTO user_group
(user_id,group_id,admin_flags,forum_flags,project_flags,
doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
- VALUES ('$user_id','". $this->getID() ."','','0','0','0','1','100','0','0')");
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)',
+ array ($user_id,
+ $this->getID(),
+ '',
+ 0,
+ 0,
+ 0,
+ 1,
+ 100,
+ 0,
+ 0)) ;
//verify the insert worked
if (!$res || db_affected_rows($res) < 1) {
- $this->setError('ERROR: Could Not Add User To Group: '.db_error());
+ $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
db_rollback();
return false;
}
//
$role = new Role($this,$role_id);
if (!$role || !is_object($role)) {
- $this->setError('Error Getting Role Object');
+ $this->setError(_('Error Getting Role Object'));
db_rollback();
return false;
} elseif ($role->isError()) {
$user->fetchData($user->getID());
$role = new Role($this,$role_id);
if (!$role || !is_object($role)) {
- $this->setError('Error Getting Role Object');
+ $this->setError(_('Error Getting Role Object'));
db_rollback();
return false;
} elseif ($role->isError()) {
//
// user doesn't exist
//
- $this->setError('ERROR: User does not exist');
+ $this->setError(_('ERROR: User does not exist'));
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_adduser", $hook_params);
+
//
// audit trail
//
- $this->addHistory('Added User',$user_unix_name);
+ $this->addHistory('Added User',$user_identifier);
db_commit();
return true;
}
}
db_begin();
- $res=db_query("DELETE FROM user_group
- WHERE group_id='".$this->getID()."'
- AND user_id='$user_id'");
+ $res = db_query_params ('DELETE FROM user_group WHERE group_id=$1 AND user_id=$2',
+ array ($this->getID(),
+ $user_id)) ;
if (!$res || db_affected_rows($res) < 1) {
- $this->setError('ERROR: DB: User not removed.'.db_error());
+ $this->setError(sprintf(_('ERROR: User not removed: %s'),db_error()));
db_rollback();
return false;
} else {
//
// reassign open artifacts to id=100
//
- $res=db_query("UPDATE artifact SET assigned_to='100'
+ $res = db_query_params ('UPDATE artifact SET assigned_to=100
WHERE group_artifact_id
IN (SELECT group_artifact_id
FROM artifact_group_list
- WHERE group_id='".$this->getID()."')
- AND status_id='1' AND assigned_to='$user_id'");
+ WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
+ array ($this->getID(),
+ $user_id)) ;
if (!$res) {
- $this->setError('ERROR: DB: artifact.'.db_error());
+ $this->setError(sprintf(_('ERROR: DB: artifact: %s'),db_error()));
db_rollback();
return false;
}
$res = db_next_result();
}
} else {
- $res=db_query("DELETE FROM project_assigned_to
+ $res = db_query_params ('DELETE FROM project_assigned_to
WHERE project_task_id IN (SELECT pt.project_task_id
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='".$this->getID()."'
- AND pat.assigned_to_id='$user_id')
- AND assigned_to_id='100'");
+ AND pt.status_id=1 AND pgl.group_id=$1
+ AND pat.assigned_to_id=$2)
+ AND assigned_to_id=100',
+ array ($this->getID(),
+ $user_id)) ;
}
if (!$res) {
- $this->setError('ERROR: DB: project_assigned_to 1 - '.db_error());
+ $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),1,db_error()));
db_rollback();
return false;
}
- $res=db_query("UPDATE project_assigned_to SET assigned_to_id='100'
+ $res = db_query_params ('UPDATE project_assigned_to SET assigned_to_id=100
WHERE project_task_id IN (SELECT pt.project_task_id
FROM project_task pt, project_group_list pgl
WHERE pt.group_project_id = pgl.group_project_id
- AND pt.status_id='1' AND pgl.group_id='".$this->getID()."')
- AND assigned_to_id='$user_id'");
+ AND pt.status_id=1 AND pgl.group_id=$1)
+ AND assigned_to_id=$2',
+ array ($this->getID(),
+ $user_id)) ;
if (!$res) {
- $this->setError('ERROR: DB: project_assigned_to 2 - '.db_error());
+ $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),2,db_error()));
db_rollback();
return false;
}
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);
+ $this->addHistory('Removed User',$user_id);
}
db_commit();
return true;
$role = new Role($this,$role_id);
if (!$role || !is_object($role)) {
- $this->setError('Could Not Get Role');
+ $this->setError(_('Could Not Get Role'));
return false;
} elseif ($role->isError()) {
- $this->setError('Role: '.$role->getErrorMessage());
+ $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
return false;
}
//echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
if (!$role->setUser($user_id)) {
- $this->setError('Role: '.$role->getErrorMessage());
+ $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
return false;
}
- $this->addHistory('updated user',$user_id);
+
+
+ $this->addHistory('Updated User',$user_id);
return true;
}
* @param string The name of the field.
* @param string The Old Value for this $field_name.
* @return database result handle.
- * @access public.
+ * @access public
*/
function addHistory($field_name, $old_value) {
- $sql="
- INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
- VALUES ('". $this->getID() ."','$field_name','$old_value','". user_getid() ."','".time()."')
- ";
- return db_query($sql);
+ return db_query_params ('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
+ VALUES ($1,$2,$3,$4,$5)',
+ array ($this->getID(),
+ $field_name,
+ $old_value,
+ user_getid(),
+ time()));
}
/**
* Setup unix accounts for group members. Can be called even
* if members are already active.
*
- * @access private.
+ * @access private
*/
function activateUsers() {
/*
Activate member(s) of the project
*/
-
- $member_res = db_query("SELECT user_id, role_id
- FROM user_group
- WHERE group_id='".$this->getID()."'");
-
+
+ $member_res = db_query_params ('SELECT user_id, role_id FROM user_group WHERE group_id=$1',
+ array ($this->getID())) ;
+
$rows = db_numrows($member_res);
if ($rows > 0) {
$roleId = db_result($member_res,$i,'role_id');
if (!$member || !is_object($member)) {
- $this->setError('Error getting member object');
+ $this->setError(_('Error getting member object'));
return false;
} else if ($member->isError()) {
- $this->setError('Error getting member object: '.$member->getErrorMessage());
+ $this->setError(sprintf(_('Error getting member object: %s'),$member->getErrorMessage()));
return false;
}
*/
function &getMembers() {
if (!isset($this->membersArr)) {
- $res=db_query("SELECT users.* FROM users
- INNER JOIN user_group ON users.user_id=user_group.user_id
- WHERE user_group.group_id='".$this->getID()."'");
+ $res = db_query_params ('SELECT users.* FROM users INNER JOIN user_group ON users.user_id=user_group.user_id WHERE user_group.group_id=$1',
+ array ($this->getID())) ;
while ($arr =& db_fetch_array($res)) {
- $this->membersArr[] =& new User($arr['user_id'],$arr);
+ $this->membersArr[] =& new GFUser($arr['user_id'],$arr);
}
}
return $this->membersArr;
function approve(&$user) {
if ($this->getStatus()=='A') {
- $this->setError("Group already active");
+ $this->setError(_("Group already active"));
return false;
}
return false;
}
+ // Switch to system language for item creation
+ setup_gettext_from_sys_lang ();
+
+
//
//
// Tracker Integration
//
$ats = new ArtifactTypes($this);
if (!$ats || !is_object($ats)) {
- $this->setError('Error creating ArtifactTypes object');
+ $this->setError(_('Error creating ArtifactTypes object'));
db_rollback();
+ setup_gettext_from_context();
return false;
} else if ($ats->isError()) {
- $this->setError('ATS1 '.$ats->getErrorMessage());
+ $this->setError(sprintf (_('ATS%d: %s'), 1, $ats->getErrorMessage()));
db_rollback();
+ setup_gettext_from_context();
return false;
}
if (!$ats->createTrackers()) {
- $this->setError('ATS2 '.$ats->getErrorMessage());
+ $this->setError(sprintf (_('ATS%d: %s'), 2, $ats->getErrorMessage()));
db_rollback();
+ setup_gettext_from_context();
return false;
}
//
//
$f = new Forum($this);
- if (!$f->create('Open-Discussion','General Discussion',1,'',1,0)) {
- $this->setError('F1 '.$f->getErrorMessage());
+ if (!$f->create(_('Open-Discussion'),_('General Discussion'),1,'',1,0)) {
+ $this->setError(sprintf (_('F%d: %s'), 1, $f->getErrorMessage()));
db_rollback();
+ setup_gettext_from_context();
return false;
}
$f = new Forum($this);
- if (!$f->create('Help','Get Public Help',1,'',1,0)) {
- $this->setError('F2 '.$f->getErrorMessage());
+ if (!$f->create(_('Help'),_('Get Public Help'),1,'',1,0)) {
+ $this->setError(sprintf (_('F%d: %s'), 2, $f->getErrorMessage()));
db_rollback();
+ setup_gettext_from_context();
return false;
}
$f = new Forum($this);
- if (!$f->create('Developers','Project Developer Discussion',0,'',1,0)) {
- $this->setError('F3 '.$f->getErrorMessage());
+ if (!$f->create(_('Developers-Discussion'),_('Project Developer Discussion'),0,'',1,0)) {
+ $this->setError(sprintf (_('F%d: %s'), 3, $f->getErrorMessage()));
db_rollback();
+ setup_gettext_from_context();
return false;
}
//
//
$dg = new DocumentGroup($this);
- if (!$dg->create('Uncategorized Submissions')) {
- $this->setError('DG1 '.$dg->getErrorMessage());
+ if (!$dg->create(_('Uncategorized Submissions'))) {
+ $this->setError(sprintf(_('DG: %s'),$dg->getErrorMessage()));
db_rollback();
+ setup_gettext_from_context();
return false;
}
//
$frs = new FRSPackage($this);
if (!$frs->create($this->getUnixName())) {
- $this->setError('FRSP '.$frs->getErrorMessage());
+ $this->setError(sprintf(_('FRSP: %s'),$frs->getErrorMessage()));
db_rollback();
+ setup_gettext_from_context();
return false;
}
//
//
$pg = new ProjectGroup($this);
- if (!$pg->create('To Do','Things We Have To Do',1)) {
- $this->setError('PG1 '.$pg->getErrorMessage());
+ if (!$pg->create(_('To Do'),_('Things We Have To Do'),1)) {
+ $this->setError(sprintf(_('PG%d: %s'),1,$pg->getErrorMessage()));
db_rollback();
+ setup_gettext_from_context();
return false;
}
$pg = new ProjectGroup($this);
- if (!$pg->create('Next Release','Items For Our Next Release',1)) {
- $this->setError('PG2 '.$pg->getErrorMessage());
+ if (!$pg->create(_('Next Release'),_('Items For Our Next Release'),1)) {
+ $this->setError(sprintf(_('PG%d: %s'),2,$pg->getErrorMessage()));
db_rollback();
+ setup_gettext_from_context();
return false;
}
// 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 = $user->getID();
+ db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags) VALUES ($1, $2, $3)',
+ array ($idadmin_group,
+ $this->getID(),
+ 'A')) ;
+ }
+
$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])) {
- $this->setError('R'.$c.' '.$role->getErrorMessage());
+ 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);
+ }
}
+
//
//
// Create MailingList
//
//
- $mlist = new MailingList($this);
- $admin_group = db_query("SELECT user_id FROM user_group
- WHERE group_id=".$this->getID()." AND admin_flags='A'");
- if (db_numrows($admin_group) > 0) {
- $idadmin_group = db_result($admin_group,0,'user_id');
- }
- if (!$mlist->create('commits','cvs commits',1,$idadmin_group)) {
- $this->setError('MailingList: '.$mlist->getErrorMessage());
- db_rollback();
- return false;
+ if ($GLOBALS['sys_use_mail']) {
+ $mlist = new MailingList($this);
+ if (!$mlist->create('commits',_('Commits'),1,$idadmin_group)) {
+ $this->setError(sprintf(_('ML: %s'),$mlist->getErrorMessage()));
+ db_rollback();
+ setup_gettext_from_context();
+ return false;
+ }
}
+ // Switch back to user preference
+ setup_gettext_from_context();
+
db_commit();
$this->sendApprovalEmail();
- $this->addHistory('approved', 'x');
+ $this->addHistory('Approved', 'x');
- //plugin webcal
- //change assistant for webcal
-
- $params[0] = $idadmin_group ;
- $params[1] = $this->getID();
- plugin_hook('change_cal_permission_default',$params);
+ //
+ // Plugin can make approve operation there
+ //
+ //
+ $params[0] = $idadmin_group ;
+ $params[1] = $this->getID();
+ plugin_hook('group_approve',$params);
return true;
}
* sendApprovalEmail - Send new project email.
*
* @return boolean success.
- * @access public.
+ * @access public
*/
function sendApprovalEmail() {
- $res_admins = db_query("
+ $res_admins = db_query_params ('
SELECT users.user_name,users.email,users.language,users.user_id
FROM users,user_group
WHERE users.user_id=user_group.user_id
- AND user_group.group_id='".$this->getID()."'
- AND user_group.admin_flags='A'
- ");
+ AND user_group.group_id=$1
+ AND user_group.admin_flags=$2',
+ array ($this->getID(),
+ 'A')) ;
if (db_numrows($res_admins) < 1) {
- $this->setError("Group does not have any administrators.");
+ $this->setError(_("Group does not have any administrators."));
return false;
}
$admin =& user_get_object($row_admins['user_id']);
setup_gettext_for_user ($admin) ;
- // $2 $2 $3 $4 $5 $6
- $message=stripcslashes(sprintf(_('Your project registration for %7$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
services, and directory layout of the account.
If you visit your
-own project page in %7$s while logged in, you will find
+own project page in %4$s while logged in, you will find
additional menu functions to your left labeled \'Project Admin\'.
-We highly suggest that you now visit %7$s and create a public
+We highly suggest that you now visit %4$s and create a public
description for your project. This can be done by visiting your project
page while logged in, and selecting \'Project Admin\' from the menus
-on the left (or by visiting http://%3$s/project/admin/?group_id=%6$s
+on the left (or by visiting %3$s
after login).
Your project will also not appear in the Trove Software Map (primary
-list of projects hosted on %7$s which offers great flexibility in
+list of projects hosted on %4$s which offers great flexibility in
browsing and search) until you categorize it in the project administration
screens. So that people can find your project, you should do this now.
Visit your project while logged in, and select \'Project Admin\' from the
menus on the left.
-Enjoy the system, and please tell others about %7$s. Let us know
+Enjoy the system, and please tell others about %4$s. Let us know
if there is anything we can do to help you.
--- the %7$s crew'), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_default_domain'], $GLOBALS['sys_shell_host'], $GLOBALS['sys_scm_host'], $this->getID(), $GLOBALS['sys_name']));
+-- the %4$s crew'),
+ $this->getPublicName(),
+ $this->getUnixName(),
+ util_make_url ('/project/admin/?group_id='.$this->getID()),
+ forge_get_config ('forge_name'));
- util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), $GLOBALS['sys_name']), $message);
+ util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), forge_get_config ('forge_name')), $message);
- setup_gettext_from_browser () ;
+ setup_gettext_from_context();
}
return true;
* @param int The id of the response to use.
* @param string The rejection message.
* @return completion status.
- * @access public.
+ * @access public
*/
function sendRejectionEmail($response_id, $message="zxcv") {
- $res_admins = db_query("
+ $res_admins = db_query_params ('
SELECT u.email, u.language, u.user_id
FROM users u, user_group ug
- WHERE ug.group_id='".$this->getID()."'
- AND u.user_id=ug.user_id;
- ");
-
+ WHERE ug.group_id=$1
+ AND u.user_id=ug.user_id',
+ array ($this->getID())) ;
if (db_numrows($res_admins) < 1) {
- $this->setError("Group does not have any administrators.");
+ $this->setError(_("Group does not have any administrators."));
return false;
}
$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(), forge_get_config ('forge_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("
- SELECT response_text
- FROM canned_responses
- WHERE response_id='$response_id'
- "), 0, "response_text");
+ $response .= db_result (
+ db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array ($response_id)),
+ 0,
+ "response_text");
}
- util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), $GLOBALS['sys_name']), $response);
- setup_gettext_from_browser () ;
+ util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), forge_get_config ('forge_name')), $response);
+ setup_gettext_from_context();
}
return true;
* submitted.
*
* @return boolean success.
- * @access public.
+ * @access public
*/
function sendNewProjectNotificationEmail() {
+ // Get the user who wants to register the project
+ $res = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1',
+ array ($this->getID())) ;
+
+ if (db_numrows($res) < 1) {
+ $this->setError(_("Could not find user who has submitted the project."));
+ return false;
+ }
+
+ $submitter =& user_get_object(db_result($res,0,'user_id'));
- $res = db_query("SELECT users.email, users.language, users.user_id
- FROM users,user_group
+
+ $res = db_query_params ('SELECT users.email, users.language, users.user_id
+ FROM users, user_group
WHERE group_id=1
- AND user_group.admin_flags='A'
- AND users.user_id=user_group.user_id;");
+ AND user_group.admin_flags=$1
+ AND users.user_id=user_group.user_id',
+ array ('A'));
if (db_numrows($res) < 1) {
- $this->setError("There is no administrator to send the mail.");
+ $this->setError(_("There is no administrator to send the mail to."));
return false;
- } else {
- for ($i=0; $i<db_numrows($res) ; $i++) {
- $admin_email = db_result($res,$i,'email') ;
- $admin =& user_get_object(db_result($res,$i,'user_id'));
- setup_gettext_for_user ($admin) ;
+ }
- $message=stripcslashes(sprintf(_('New %1$s Project Submitted
+ for ($i=0; $i<db_numrows($res) ; $i++) {
+ $admin_email = db_result($res,$i,'email') ;
+ $admin =& user_get_object(db_result($res,$i,'user_id'));
+ setup_gettext_for_user ($admin) ;
+
+ $message=sprintf(_('New %1$s Project Submitted
Project Full Name: %2$s
Submitted Description: %3$s
-License: %4$s
+Submitter: %5$s (%6$s)
Please visit the following URL to approve or reject this project:
-http://%5$s/admin/approve-pending.php'), $GLOBALS['sys_name'], $this->getPublicName(), util_unconvert_htmlspecialchars($this->getRegistrationPurpose()), $this->getLicenseName(), $GLOBALS['sys_default_domain']));
- util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
- setup_gettext_from_browser () ;
- }
+%4$s'),
+ forge_get_config ('forge_name'),
+ $this->getPublicName(),
+ util_unconvert_htmlspecialchars($this->getRegistrationPurpose()),
+ util_make_url ('/admin/approve-pending.php'),
+ $submitter->getRealName(),
+ $submitter->getUnixName());
+ util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
+ setup_gettext_from_context();
}
- // Get the email of the user who wants to register the project
- $res = db_query("SELECT u.email, u.language, u.user_id
- FROM users u, user_group ug
- WHERE ug.group_id='".$this->getID()."' AND u.user_id=ug.user_id;");
- if (db_numrows($res) < 1) {
- $this->setError("Cound not find user who has submitted the project.");
- return false;
- } else {
- for ($i=0; $i<db_numrows($res) ; $i++) {
- $email = db_result($res, $i, 'email');
- $user =& user_get_object(db_result($res,$i,'user_id'));
- setup_gettext_for_user ($user) ;
+ $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.'), forge_get_config ('forge_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_browser () ;
+ util_send_message($email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
+ setup_gettext_from_context();
+
+ return true;
+ }
+
+
+
+
+/**
+ * validateGroupName - Validate the group name
+ *
+ * @param string Group name.
+ *
+ * @return an error false and set an error is the group name is invalide otherwise return true
+ */
+ function validateGroupName($group_name) {
+ if (strlen($group_name)<3) {
+ $this->setError(_('Group name is too short'));
+ return false;
+ } else if (strlen(htmlspecialchars($group_name))>50) {
+ $this->setError(_('Group name is too long'));
+ return false;
+ } else if ($group=group_get_object_by_publicname($group_name)) {
+ $this->setError(_('Group name already taken'));
+ return false;
+ }
+ return true;
+ }
+
+
+ /**
+ * getRoles - Get the roles of the group.
+ *
+ * @return array of Role id of this group.
+ */
+ function getRolesId () {
+
+ $rolesId = Array();
+
+ $roles_group_res = db_query_params ('SELECT role_id FROM role WHERE group_id=$1',
+ array ($this->getID()));
+ if (!$roles_group_res) {
+ $this->setError('Error: Roles from group id '. $this->getID() . ' ' .db_error());
+ return false;
+ } else {
+ for ($i=0; $i<db_numrows($roles_group_res); $i++) {
+ $rolesId[$i] = db_result($roles_group_res,$i,'role_id');
}
}
-
- return true;
+ return $rolesId;
+ }
+
+ /**
+ * getUnixStatus - Status of activation of unix account.
+ *
+ * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
+ */
+ function getUnixStatus() {
+ return $this->data_array['unix_status'];
+ }
+
+ /**
+ * setUnixStatus - Sets status of activation of unix account.
+ *
+ * @param string The unix status.
+ * N no_unix_account
+ * A active
+ * S suspended
+ * D deleted
+ *
+ * @return boolean success.
+ */
+ function setUnixStatus($status) {
+ global $SYS;
+ db_begin();
+ $res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
+ array ($status,
+ $this->getID())) ;
+
+ if (!$res) {
+ $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
+ db_rollback();
+ return false;
+ } else {
+ if ($status == 'A') {
+ if (!$SYS->sysCheckCreateGroup($this->getID())) {
+ $this->setError($SYS->getErrorMessage());
+ db_rollback();
+ return false;
+ }
+ } else {
+ if ($SYS->sysCheckGroup($this->getID())) {
+ if (!$SYS->sysRemoveGroup($this->getID())) {
+ $this->setError($SYS->getErrorMessage());
+ db_rollback();
+ return false;
+ }
+ }
+ }
+
+ $this->data_array['unix_status']=$status;
+ db_commit();
+ return true;
+ }
+ }
+
+ /**
+ * getUsers - Get the users of a group
+ *
+ * @return array of user's objects.
+ */
+ function getUsers() {
+ $users = Array();
+
+ $users_group_res = db_query_params ('SELECT u.user_id FROM users u, user_group ug WHERE ug.group_id=$1 AND ug.user_id=u.user_id AND u.status=$2',
+ array ($this->getID(),
+ 'A'));
+ if (!$users_group_res) {
+ $this->setError('Error: Enable to get users from group '. $this->getID() . ' ' .db_error());
+ return false;
+ }
+
+ for ($i=0; $i<db_numrows($users_group_res); $i++) {
+ $users[$i] = new GFUser(db_result($users_group_res,$i,'user_id'),false);
+ }
+
+ return $users;
}
}
}
}
-/**
- * getUnixStatus - Status of activation of unix account.
- *
- * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
- */
-function getUnixStatus() {
- return $this->data_array['unix_status'];
-}
-
-/**
- * setUnixStatus - Sets status of activation of unix account.
- *
- * @param string The unix status.
- * N no_unix_account
- * A active
- * S suspended
- * D deleted
- *
- * @return boolean success.
- */
-function setUnixStatus($status) {
- global $SYS;
- db_begin();
- $res=db_query("
- UPDATE groups
- SET unix_status='$status'
- WHERE group_id='". $this->getID()."'
- ");
-
- if (!$res) {
- $this->setError('ERROR - Could Not Update Group Unix Status: '.db_error());
- db_rollback();
- return false;
- } else {
- if ($status == 'A') {
- if (!$SYS->sysCheckCreateGroup($this->getID())) {
- $this->setError($SYS->getErrorMessage());
- db_rollback();
- return false;
- }
- } else {
- if ($SYS->sysCheckGroup($this->getID())) {
- if (!$SYS->sysRemoveGroup($this->getID())) {
- $this->setError($SYS->getErrorMessage());
- db_rollback();
- return false;
- }
- }
- }
-
- $this->data_array['unix_status']=$status;
- db_commit();
- return true;
- }
-}
// Local Variables:
// mode: php