* Copyright 1999-2001, VA Linux Systems, Inc.
* Copyright 2009-2010, Roland Mas
* Copyright 2010-2011, Franck Villaume - Capgemini
- * Copyright 2010-2011, Alain Peyrat - Alcatel-Lucent
+ * Copyright 2010-2012, Alain Peyrat - Alcatel-Lucent
* Copyright 2012-2013, Franck Villaume - TrivialDev
* http://fusionforge.org
*
* IMPORTANT! That db result must contain all fields
* from groups table or you will have problems
*
- * @param int Required
- * @param int Result set handle ("SELECT * FROM groups WHERE group_id=xx")
- * @return object a group object or false on failure
+ * @param int $group_id Required
+ * @param int|bool $res Result set handle ("SELECT * FROM groups WHERE group_id=xx")
+ * @return Group|bool A group object or false on failure
*/
function &group_get_object($group_id, $res = false) {
//create a common set of group objects
return group_get_object(db_result($res, 0, 'group_id'), $res);
}
+/**
+ * get_public_active_projects_asc() - Get a list of rows for public active projects (initially in trove/full_list)
+ *
+ * @param int Opional Maximum number of rows to limit query length
+ */
+function get_public_active_projects_asc($max_query_limit = -1) {
+
+ $res_grp = db_query_params ('
+ SELECT group_id, group_name, unix_group_name, short_description, register_time
+ FROM groups
+ WHERE status = $1 AND type_id=1 AND group_id>4 AND register_time > 0
+ ORDER BY group_name ASC
+ ',
+ array ('A'),
+ $max_query_limit);
+ $projects = array();
+ while ($row_grp = db_fetch_array($res_grp)) {
+ if (!forge_check_perm ('project_read', $row_grp['group_id'])) {
+ continue ;
+ }
+ $projects[] = $row_grp;
+ }
+ return $projects;
+}
+
+
class Group extends Error {
/**
* Associative array of data from db.
/**
* Group - Group object constructor - use group_get_object() to instantiate.
*
- * @param int Required - group_id of the group you want to instantiate.
- * @param int Database result from select query OR associative array of all columns.
- * @return boolean success or not
+ * @param int|bool $id Required - Id of the group you want to instantiate.
+ * @param int|bool $res Database result from select query OR associative array of all columns.
+ * @return boolean Success or not
*/
- function Group($id = false, $res = false) {
+ function __construct($id = false, $res = false) {
$this->Error();
if (!$id) {
//setting up an empty object
/**
* fetchData - May need to refresh database fields if an update occurred.
*
- * @param int The group_id.
- * @return boolean success or not
+ * @param int $group_id The group_id.
+ * @return boolean success or not
*/
function fetchData($group_id) {
$res = db_query_params ('SELECT * FROM groups WHERE group_id=$1',
if ($this->getID()!=0) {
$this->setError(_('Group::create: Group object already exists'));
return false;
- } else if (!$this->validateGroupName($group_name)) {
+ } elseif (!$this->validateGroupName($group_name)) {
return false;
- } else if (!account_groupnamevalid($unix_name)) {
+ } elseif (!account_groupnamevalid($unix_name)) {
$this->setError(_('Invalid Unix name'));
return false;
- } else if (!$SYS->sysUseUnixName($unix_name)) {
+ } elseif (!$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',
+ } elseif (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) {
+ } elseif (strlen($purpose)<10) {
$this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
return false;
- } else if (strlen($purpose)>1500) {
+ } elseif (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) {
+ } elseif (strlen($description)<10) {
$this->setError(_('Describe in a more comprehensive manner your project.'));
return false;
} else {
scm_box,
register_purpose,
register_time,
- enable_anonscm,
rand_hash,
built_from_template
)
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)',
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)',
array (htmlspecialchars ($group_name),
$unix_name,
htmlspecialchars($description),
- $unix_name.".".forge_get_config('web_host'),
+ $homepage,
$homepage,
'P',
$unix_box,
$scm_box,
htmlspecialchars($purpose),
time(),
- 0,
md5(util_randbytes()),
$built_from_template));
if (!$res || db_affected_rows($res) < 1) {
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, $tags, $is_public) {
+ $use_ftp, $use_tracker, $use_frs, $use_stats, $tags, $use_activity, $is_public) {
$perm =& $this->getPermission();
}
// in the database, these all default to '1',
- // so we have to explicity set 0
+ // so we have to explicitly set 0
if (!$use_mail) {
$use_mail = 0;
}
if (!$use_stats) {
$use_stats = 0;
}
+ if (!$use_activity) {
+ $use_activity = 0;
+ }
if (!$send_all_docs) {
$send_all_docs = 0;
}
$homepage = util_make_url('/projects/' . $this->getUnixName() . '/');
}
- if (strlen(htmlspecialchars($short_description))>255) {
- $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
+ if (strlen(htmlspecialchars($short_description))<10) {
+ $this->setError(_('Describe in a more comprehensive manner your project.'));
return false;
}
use_ftp=$13,
use_tracker=$14,
use_frs=$15,
- use_stats=$16
- WHERE group_id=$17',
+ use_stats=$16,
+ use_activity=$17
+ WHERE group_id=$18',
array(htmlspecialchars($group_name),
$homepage,
htmlspecialchars($short_description),
$use_tracker,
$use_frs,
$use_stats,
+ $use_activity,
$this->getID()));
- if (!$res) {
+ if (!$res || db_affected_rows($res) < 1) {
$this->setError(sprintf(_('Error updating project information: %s'), db_error()));
db_rollback();
return false;
// Check that status transition is valid
if ($this->getStatus() != $status
- && !array_key_exists($this->getStatus(). $status,$allowed_status_changes)) {
- $this->setError(_('Invalid Status Change'));
+ && !array_key_exists($this->getStatus(). $status, $allowed_status_changes)) {
+ $this->setError(_('Invalid Status Change From: ').$this->getStatus(). _(' To: '.$status));
return false;
}
/* Otherwise, the group is not active, and make sure that
System group is not active either */
- } else if ($SYS->sysCheckGroup($this->getID())) {
+ } elseif ($SYS->sysCheckGroup($this->getID())) {
if (!$SYS->sysRemoveGroup($this->getID())) {
$this->setError($SYS->getErrorMessage());
db_rollback();
}
/**
+ * usesActivity - whether or not this group has opted to display Project Activities.
+ *
+ * @return boolean uses_activities.
+ */
+ function usesActivity() {
+ if (forge_get_config('use_activity')) {
+ return $this->data_array['use_activity'];
+ } else {
+ return false;
+ }
+ }
+
+ /**
* usesForum - whether or not this group has opted to use discussion forums.
*
* @return boolean uses_forum.
/**
* usesPlugin - returns true if the group uses a particular plugin
*
- * @param string name of the plugin
+ * @param string $pluginname name of the plugin
* @return boolean whether plugin is being used or not
*/
function usesPlugin($pluginname) {
return false;
}
}
- // Failsafe until user_group table is gone
- $res = db_query_params('DELETE FROM user_group WHERE group_id=$1',
- array($this->getID()));
// unlink roles from this project
foreach ($this->getRoles() as $r) {
//
if ($this->usesForum()) {
+ $ff = new ForumFactory($this);
$f_arr = $ff->getForums();
foreach ($f_arr as $i) {
if (!is_object($i)) {
// Delete SurveyQuestions
//
$sqf = new SurveyQuestionFactory($this);
- $sq_arr =& $sqf->getSurveyQuestions();
- foreach ($sq_arr as $i) {
- if (!is_object($i)) {
- continue;
- }
- if (!$i->delete()) {
- $this->setError(_('Could not properly delete the survey questions'));
- db_rollback();
- return false;
+ $sq_arr = $sqf->getSurveyQuestions();
+ if (is_array($sq_arr)) {
+ foreach ($sq_arr as $i) {
+ if (!is_object($i)) {
+ continue;
+ }
+ if (!$i->delete()) {
+ $this->setError(_('Could not properly delete the survey questions'));
+ db_rollback();
+ return false;
+ }
}
}
}
$oldatf = new ArtifactTypeFactory($template);
foreach ($oldatf->getArtifactTypes() as $o) {
$t = new ArtifactType ($this) ;
- $t->create ($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->isPublic(),$o->allowsAnon(),$o->emailAll(),$o->getEmailAddress(),$o->getDuePeriod()/86400,0,$o->getSubmitInstructions(),$o->getBrowseInstructions()) ;
+ $t->create ($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->emailAll(),$o->getEmailAddress(),$o->getDuePeriod()/86400,0,$o->getSubmitInstructions(),$o->getBrowseInstructions()) ;
$id_mappings['tracker'][$o->getID()] = $t->getID();
$t->cloneFieldsFrom ($o->getID());
}
$oldpgf = new ProjectGroupFactory($template);
foreach ($oldpgf->getProjectGroups() as $o) {
$pg = new ProjectGroup($this);
- $pg->create($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->isPublic(),$o->getSendAllPostsTo());
+ $pg->create($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->getSendAllPostsTo());
$id_mappings['pm'][$o->getID()] = $pg->getID();
}
}
$oldff = new ForumFactory($template) ;
foreach ($oldff->getForums() as $o) {
$f = new Forum($this);
- $f->create($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),0,$o->getSendAllPostsTo(),1,0,0);
+ $f->create($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->getSendAllPostsTo(),1);
$id_mappings['forum'][$o->getID()] = $f->getID();
}
}
if (strlen($group_name)<3) {
$this->setError(_('Group name is too short'));
return false;
- } else if (strlen(htmlspecialchars($group_name))>50) {
+ } elseif (strlen(htmlspecialchars($group_name))>50) {
$this->setError(_('Group name is too long'));
return false;
- } else if (group_get_object_by_publicname($group_name)) {
+ } elseif (group_get_object_by_publicname($group_name)) {
$this->setError(_('Group name already taken'));
return false;
}
}
}
- function setStorageAPI($type) {
- return true;
- }
-
- function getStorageAPI() {
- return 'DB';
- }
}
/**
// mode: php
// c-file-style: "bsd"
// End:
-
-?>
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-require "PFO-RBAC.interface.php";
+require 'PFO-RBAC.interface.php';
define ('USE_PFO_RBAC', true);
'pm_admin' => array(0, 1),
'forum_admin' => array(0, 1),
- 'tracker' => array(0, 1, 3, 5, 7),
+ 'tracker' => array(0, 1, 9, 11, 13, 15),
'pm' => array(0, 1, 3, 5, 7),
'forum' => array(0, 1, 2, 3, 4),
- 'new_tracker' => array(0, 1, 3, 5, 7),
+ 'new_tracker' => array(0, 1, 9, 11, 13, 15),
'new_pm' => array(0, 1, 3, 5, 7),
'new_forum' => array(0, 1, 2, 3, 4),
'docman' => array (0, 1, 2, 3, 4),
'frs' => array (0, 1, 2, 3),
-// 'webcal' => array(0, 1, 2),
);
// Global permissions
'forum_admin' => 1,
'new_forum' => 3,
'tracker_admin' => 1,
- 'new_tracker' => 7,
+ 'new_tracker' => 15,
'pm_admin' => 1,
'new_pm' => 7,
- 'webcal' => 2,
),
'Senior Developer' => array( 'project_read' => 1,
'frs' => 2,
'forum_admin' => 1,
'new_forum' => 3,
'tracker_admin' => 1,
- 'new_tracker' => 7,
+ 'new_tracker' => 15,
'pm_admin' => 1,
'new_pm' => 7,
- 'webcal' => 2,
),
'Junior Developer' => array( 'project_read' => 1,
'frs' => 2,
'scm' => 2,
'docman' => 2,
'new_forum' => 3,
- 'new_tracker' => 3,
+ 'new_tracker' => 11,
'new_pm' => 3,
- 'webcal' => 2,
),
'Doc Writer' => array( 'project_read' => 1,
'frs' => 2,
'docman' => 4,
'new_forum' => 3,
- 'new_tracker' => 1,
+ 'new_tracker' => 9,
'new_pm' => 1,
- 'webcal' => 2,
),
'Support Tech' => array( 'project_read' => 1,
'frs' => 2,
'docman' => 1,
'new_forum' => 3,
'tracker_admin' => 1,
- 'new_tracker' => 3,
+ 'new_tracker' => 11,
'pm_admin' => 1,
'new_pm' => 7,
- 'webcal' => 2,
),
);
}
case 'manager':
return (($value & 4) != 0) ;
break ;
+ case 'submit':
+ return (($value & 8) != 0) ;
+ break ;
+ /*
+ * bit4 (value & 16) is reserved
+ * for tracker item vote from Evolvis
+ */
}
break ;
db_begin () ;
// Remove obsolete project-wide settings
- $sections = array ('project_read', 'project_admin', 'frs', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm', 'webcal') ;
+ $sections = array ('project_read', 'project_admin', 'frs', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm') ;
db_query_params ('DELETE FROM pfo_role_setting where role_id=$1 AND section_name=ANY($2) and ref_id NOT IN (SELECT home_group_id FROM pfo_role WHERE role_id=$1 AND home_group_id IS NOT NULL UNION SELECT group_id from role_project_refs WHERE role_id=$1)',
array ($this->getID(),
db_string_array_to_any_clause($sections))) ;
// Add missing settings
// ...project-wide settings
- $arr = array ('project_read', 'project_admin', 'frs', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm', 'webcal') ;
+ $arr = array ('project_read', 'project_admin', 'frs', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm') ;
foreach ($projects as $p) {
foreach ($arr as $section) {
$this->normalizePermsForSection ($new_pa, $section, $p->getID()) ;
$new_pa['tracker'] = array () ;
foreach ($projects as $p) {
$atf = new ArtifactTypeFactory ($p) ;
- $trackerids = $atf->getAllArtifactTypeIds () ;
- foreach ($trackerids as $tid) {
- if (array_key_exists ('tracker', $this->perms_array)
- && array_key_exists ($tid, $this->perms_array['tracker']) ) {
- $new_pa['tracker'][$tid] = $this->perms_array['tracker'][$tid] ;
- } elseif (array_key_exists ('new_tracker', $this->perms_array)
- && array_key_exists ($p->getID(), $this->perms_array['new_tracker']) ) {
- $new_pa['tracker'][$tid] = $new_pa['new_tracker'][$p->getID()] ;
+ if (!$atf->isError()) {
+ $trackerids = $atf->getAllArtifactTypeIds () ;
+ foreach ($trackerids as $tid) {
+ if (array_key_exists ('tracker', $this->perms_array)
+ && array_key_exists ($tid, $this->perms_array['tracker']) ) {
+ $new_pa['tracker'][$tid] = $this->perms_array['tracker'][$tid] ;
+ } elseif (array_key_exists ('new_tracker', $this->perms_array)
+ && array_key_exists ($p->getID(), $this->perms_array['new_tracker']) ) {
+ $new_pa['tracker'][$tid] = $new_pa['new_tracker'][$p->getID()] ;
+ }
}
}
}
}
public function addUser ($user) {
- return $this->addUsers (array ($user)) ;
+ if (!$this->addUsers (array ($user))) {
+ return false;
+ }
+ $hook_params['user'] = $user;
+ $hook_params['role'] = $this;
+ plugin_hook ("role_adduser", $hook_params);
+
+ return true;
}
public function removeUsers($users) {
}
public function removeUser ($user) {
- return $this->removeUsers (array ($user)) ;
+ if(!$this->removeUsers (array ($user))){
+ return false;
+ }
+ $hook_params['user'] = $user;
+ $hook_params['role'] = $this;
+ plugin_hook ("role_removeuser", $hook_params);
+
+ return true;
}
public function getUsers() {
// mode: php
// c-file-style: "bsd"
// End:
-
-?>