5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2009-2013, Roland Mas
7 * Copyright 2010-2011, Franck Villaume - Capgemini
8 * Copyright 2010-2012, Alain Peyrat - Alcatel-Lucent
9 * Copyright 2012-2017, Franck Villaume - TrivialDev
10 * Copyright 2013, French Ministry of National Education
11 * Copyright 2017, Stéphane-Eymeric Bredthauer - TrivialDev
12 * http://fusionforge.org
14 * This file is part of FusionForge. FusionForge is free software;
15 * you can redistribute it and/or modify it under the terms of the
16 * GNU General Public License as published by the Free Software
17 * Foundation; either version 2 of the Licence, or (at your option)
20 * FusionForge is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License along
26 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 require_once $gfcommon.'tracker/ArtifactTypes.class.php';
31 require_once $gfcommon.'tracker/ArtifactTypeFactory.class.php';
32 require_once $gfcommon.'tracker/RoadmapFactory.class.php';
33 require_once $gfcommon.'forum/Forum.class.php';
34 require_once $gfcommon.'forum/ForumFactory.class.php';
35 require_once $gfcommon.'pm/ProjectGroup.class.php';
36 require_once $gfcommon.'pm/ProjectGroupFactory.class.php';
37 require_once $gfcommon.'frs/FRSPackage.class.php';
38 require_once $gfcommon.'frs/FRSRelease.class.php';
39 require_once $gfcommon.'docman/DocumentGroup.class.php';
40 require_once $gfcommon.'docman/DocumentGroupFactory.class.php';
41 require_once $gfcommon.'mail/MailingList.class.php';
42 require_once $gfcommon.'mail/MailingListFactory.class.php';
43 require_once $gfcommon.'survey/SurveyFactory.class.php';
44 require_once $gfcommon.'survey/SurveyQuestionFactory.class.php';
45 require_once $gfcommon.'include/gettext.php';
46 require_once $gfcommon.'include/GroupJoinRequest.class.php';
47 require_once $gfcommon.'include/Role.class.php';
48 require_once $gfcommon.'widget/WidgetLayoutManager.class.php';
53 * group_get_object() - Get the group object.
55 * group_get_object() is useful so you can pool group objects/save database queries
56 * You should always use this instead of instantiating the object directly.
58 * You can now optionally pass in a db result handle. If you do, it re-uses that query
59 * to instantiate the objects.
61 * IMPORTANT! That db result must contain all fields
62 * from groups table or you will have problems
64 * @param int $group_id Required
65 * @param int|bool $res Result set handle ("SELECT * FROM groups WHERE group_id=xx")
66 * @return Group|bool A group object or false on failure
68 function &group_get_object($group_id, $res = false) {
69 //create a common set of group objects
70 //saves a little wear on the database
72 //automatically checks group_type and
73 //returns appropriate object
76 if (!isset($GROUP_OBJ["_".$group_id."_"])) {
78 //the db result handle was passed in
80 $res = db_query_params('SELECT * FROM groups WHERE group_id=$1', array($group_id));
82 if (!$res || db_numrows($res) < 1) {
83 $GROUP_OBJ["_".$group_id."_"]=false;
88 $GROUP_OBJ["_".$group_id."_"] = new Group($group_id, $res);
91 return $GROUP_OBJ["_".$group_id."_"];
94 function &group_get_objects($id_arr) {
97 // Note: if we don't do this, the result may be corrupted
101 foreach ($id_arr as $id) {
103 // See if this ID already has been fetched in the cache
105 if (!isset($GROUP_OBJ["_".$id."_"])) {
109 if (count($fetch) > 0) {
110 $res=db_query_params('SELECT * FROM groups WHERE group_id = ANY ($1)',
111 array(db_int_array_to_any_clause($fetch)));
112 while ($arr = db_fetch_array($res)) {
113 $GROUP_OBJ["_".$arr['group_id']."_"] = new Group($arr['group_id'],$arr);
116 foreach ($id_arr as $id) {
117 $return[] =& $GROUP_OBJ["_".$id."_"];
122 function &group_get_active_projects() {
123 $res = db_query_params('SELECT group_id FROM groups WHERE status=$1',
125 return group_get_objects(util_result_column_to_array($res,0));
128 function &group_get_all_projects() {
129 $res = db_query_params ('SELECT group_id FROM groups',
131 return group_get_objects(util_result_column_to_array($res,0));
134 function &group_get_template_projects() {
135 $res = db_query_params('SELECT group_id FROM groups WHERE is_template=1 AND status != $1',
137 return group_get_objects(util_result_column_to_array($res,0));
140 function &group_get_object_by_name($groupname) {
141 $res = db_query_params('SELECT * FROM groups WHERE unix_group_name=$1', array($groupname));
142 return group_get_object(db_result($res, 0, 'group_id'), $res);
145 function &group_get_objects_by_name($groupname_arr) {
146 $res = db_query_params('SELECT group_id FROM groups WHERE unix_group_name = ANY ($1)',
147 array(db_string_array_to_any_clause($groupname_arr)));
148 $arr =& util_result_column_to_array($res,0);
149 return group_get_objects($arr);
152 function group_get_object_by_publicname($groupname) {
153 $res = db_query_params('SELECT * FROM groups WHERE lower(group_name) LIKE $1',
154 array(htmlspecialchars(html_entity_decode(strtolower($groupname)))));
155 return group_get_object(db_result($res, 0, 'group_id'), $res);
158 function filter_groups_by_read_access($grps) {
159 $filteredgrps = array();
160 foreach ($grps as $g) {
161 if (forge_check_perm ('project_read', $g->getID())) {
162 $filteredgrps[] = $g;
165 return $filteredgrps;
169 * get_public_active_projects_asc() - Get a list of rows for public active projects (initially in trove/full_list)
171 * @param int $max_query_limit Optional Maximum number of rows to limit query length
172 * @param int $offset start to retrieve rows from offset value
173 * @return array List of public active projects
175 function group_get_public_active_projects_asc($max_query_limit = -1, $offset = 0) {
177 if (session_loggedin()) {
179 $userRoles = $LUSER->getRoles();
180 if (count($userRoles)) {
181 foreach ($userRoles as $r) {
182 $role_id .= ', '.$r->getID();
187 $res_grp = db_query_params ('
188 SELECT group_id, group_name, unix_group_name, short_description, register_time
190 WHERE status = $1 AND is_template=0 AND register_time > 0
191 AND group_id in (select ref_id FROM pfo_role_setting WHERE section_name = $2 and perm_val = 1 and role_id IN ('.$role_id.'))
192 ORDER BY group_name ASC
194 array('A', 'project_read'),
195 $max_query_limit, $offset);
197 while ($row_grp = db_fetch_array($res_grp)) {
198 $projects[] = $row_grp;
204 * group_get_readable_projects_using_tag_asc() - Get a list of group_id for active projects (initially in trove/tag_cloud)
206 * @param string $selected_tag Tag to search
207 * @param int $max_query_limit Optional Maximum number of rows to limit query length
208 * @param int $offset start to retrieve rows from offset value
209 * @return array List of public active projects
211 function group_get_readable_projects_using_tag_asc($selected_tag, $max_query_limit = -1, $offset = 0) {
213 if (session_loggedin()) {
215 $userRoles = $LUSER->getRoles();
216 if (count($userRoles)) {
217 foreach ($userRoles as $r) {
218 $role_id .= ', '.$r->getID();
223 $res_grp = db_query_params ('SELECT groups.group_id, group_name, unix_group_name, short_description, register_time
224 FROM project_tags, groups
225 WHERE LOWER(name) = $1
226 AND project_tags.group_id = groups.group_id
227 AND groups.status = $2 AND groups.is_template=0 AND groups.register_time > 0
228 AND groups.group_id in (select ref_id FROM pfo_role_setting WHERE section_name = $3 and perm_val = 1 and role_id IN ('.$role_id.'))
229 ORDER BY groups.group_name ASC',
230 array(strtolower($selected_tag), 'A', 'project_read'),
231 $max_query_limit, $offset);
233 while ($row_grp = db_fetch_array($res_grp)) {
234 $projects[] = $row_grp;
239 class Group extends FFError {
241 * Associative array of data from db.
243 * @var array $data_array.
248 * array of User objects.
250 * @var array $membersArr.
255 * Group - Group object constructor - use group_get_object() to instantiate.
257 * @param int|bool $id Required - Id of the group you want to instantiate.
258 * @param int|bool $res Database result from select query OR associative array of all columns.
260 function __construct($id = false, $res = false) {
261 parent::__construct();
263 //setting up an empty object
264 //probably going to call create()
268 if (!$this->fetchData($id)) {
273 // Assoc array was passed in
275 if (is_array($res)) {
276 $this->data_array =& $res;
278 if (db_numrows($res) < 1) {
279 //function in class we extended
280 $this->setError(_('Group Not Found'));
281 $this->data_array=array();
284 //set up an associative array for use by other functions
285 $this->data_array = db_fetch_array_by_row($res, 0);
293 * fetchData - May need to refresh database fields if an update occurred.
295 * @param int $group_id The group_id.
296 * @return bool success or not
298 function fetchData($group_id) {
299 $res = db_query_params ('SELECT * FROM groups WHERE group_id=$1',
301 if (!$res || db_numrows($res) < 1) {
302 $this->setError('fetchData()'._(': ').db_error());
305 $this->data_array = db_fetch_array($res);
310 * create - Create new group.
312 * This method should be called on empty Group object.
313 * It will add an entry for a pending group/project (status 'P')
315 * @param object $user The User object.
316 * @param string $group_name The full name of the user.
317 * @param string $unix_name The Unix name of the user.
318 * @param string $description The new group description.
319 * @param string $purpose The purpose of the group.
320 * @param string $unix_box
321 * @param string $scm_box
322 * @param bool $send_mail Whether to send an email or not
323 * @param int $built_from_template The id of the project this new project is based on
324 * @param int $createtimestamp The Time Stamp of creation to ease import.
325 * @return bool success or not
327 function create(&$user, $group_name, $unix_name, $description, $purpose, $unix_box = 'shell1',
328 $scm_box = 'cvs1', $send_mail = true, $built_from_template = 0, $createtimestamp = null) {
329 // $user is ignored - anyone can create pending group
332 if ($this->getID()!=0) {
333 $this->setError(_('Group object already exists.'));
335 } elseif (!$this->validateGroupName($group_name)) {
336 $this->setError(_('Invalid project name'));
338 } elseif (!account_groupnamevalid($unix_name)) {
339 $this->setError(_('Invalid Unix Name.'));
341 } elseif (!$SYS->sysUseUnixName($unix_name)) {
342 $this->setError(_('Unix name already taken.'));
344 } elseif (strlen($purpose)<10) {
345 $this->setError(_('Please describe your Registration Project Purpose and Summarization in a more comprehensive manner.'));
347 } elseif (strlen($purpose)>1500) {
348 $this->setError(_('The Registration Project Purpose and Summarization text is too long. Please make it smaller than 1500 characters.'));
350 } elseif (strlen($description)<10) {
351 $this->setError(_('Describe in a more comprehensive manner your project.'));
355 // Check if use_project_vhost for homepage
356 if (forge_get_config('use_project_vhost')) {
357 $homepage = $unix_name.'.'.forge_get_config('web_host');
359 $homepage = forge_get_config('web_host')."/www/".$unix_name."/";
363 $createtimestamp = (($createtimestamp) ? $createtimestamp : time());
364 $res = db_query_params('
379 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)',
380 array(htmlspecialchars($group_name),
382 htmlspecialchars($description),
388 htmlspecialchars($purpose),
390 md5(util_randbytes()),
391 $built_from_template));
392 if (!$res || db_affected_rows($res) < 1) {
393 $this->setError(_('Error')._(': ')._('Cannot create group')._(': ').db_error());
398 $id = db_insertid($res, 'groups', 'group_id');
400 $this->setError(_('Error')._(': ')._('Cannot get group id')._(': ').db_error());
405 if (!$this->fetchData($id)) {
410 $gjr = new GroupJoinRequest($this);
411 $gjr->create($user->getID(), 'Fake GroupJoinRequest to store the creator of a project', false);
413 $hook_params = array();
414 $hook_params['group'] = $this;
415 $hook_params['group_id'] = $this->getID();
416 $hook_params['group_name'] = $group_name;
417 $hook_params['unix_group_name'] = $unix_name;
418 $hook_params['createtimestamp'] = $createtimestamp;
419 plugin_hook("group_create", $hook_params);
423 $this->sendNewProjectNotificationEmail();
431 * updateAdmin - Update core properties of group object.
433 * This function require site admin privilege.
435 * @param object $user User requesting operation (for access control).
436 * @param string $unix_box Machine on which group's home directory located.
437 * @param string $http_domain Domain which serves group's WWW.
438 * @return bool status.
441 function updateAdmin(&$user, $unix_box, $http_domain) {
442 $perm =& $this->getPermission();
444 if (!$perm || !is_object($perm)) {
445 $this->setError(_('Could not get permission.'));
449 if (!$perm->isSuperUser()) {
450 $this->setError(_('Permission denied.'));
456 $res = db_query_params('
458 SET unix_box=$1, http_domain=$2
464 if (!$res || db_affected_rows($res) < 1) {
465 $this->setError(_('Error')._(': ')._('Cannot change group properties')._(': ').db_error());
470 // Log the audit trail
471 if ($unix_box != $this->data_array['unix_box']) {
472 $this->addHistory('unix_box', $this->data_array['unix_box']);
474 if ($http_domain != $this->data_array['http_domain']) {
475 $this->addHistory('http_domain', $this->data_array['http_domain']);
478 if (!$this->fetchData($this->getID())) {
487 * update - Update number of common properties.
489 * Unlike updateAdmin(), this function accessible to project admin.
491 * @param object $user User requesting operation (for access control).
492 * @param string $group_name
493 * @param string $homepage
494 * @param string $short_description
495 * @param bool $use_mail
496 * @param bool $use_survey
497 * @param bool $use_forum
498 * @param bool $use_pm
499 * @param bool $use_pm_depend_box
500 * @param bool $use_scm
501 * @param bool $use_news
502 * @param bool $use_docman
503 * @param string $new_doc_address
504 * @param bool $send_all_docs
505 * @param int $logo_image_id XXXX UNUSED XXXX -> see getLogoImageID function
506 * @param bool $use_ftp
507 * @param bool $use_tracker
508 * @param bool $use_frs
509 * @param bool $use_stats
510 * @param string $tags
511 * @param bool $use_activity
512 * @param bool $is_public group is publicly accessible
513 * @return int status.
516 function update(&$user, $group_name, $homepage, $short_description, $use_mail, $use_survey, $use_forum,
517 $use_pm, $use_pm_depend_box, $use_scm, $use_news, $use_docman,
518 $new_doc_address, $send_all_docs, $logo_image_id,
519 $use_ftp, $use_tracker, $use_frs, $use_stats, $tags, $use_activity, $is_public) {
521 $perm =& $this->getPermission();
523 if (!$perm || !is_object($perm)) {
524 $this->setError(_('Could not get permission.'));
528 if (!$perm->isAdmin()) {
529 $this->setError(_('Permission denied.'));
533 // Validate some values
534 if ($this->getPublicName() != htmlspecialchars($group_name)) {
535 if (!$this->validateGroupName($group_name)) {
540 if ($new_doc_address) {
541 $invalid_mails = validate_emails($new_doc_address);
542 if (count($invalid_mails) > 0) {
543 $this->setError(sprintf(ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
548 // in the database, these all default to '1',
549 // so we have to explicitly set 0
562 if (!$use_pm_depend_box) {
563 $use_pm_depend_box = 0;
586 if (!$use_activity) {
589 if (!$send_all_docs) {
593 $homepage = ltrim($homepage);
595 $homepage = util_make_url('/projects/'.$this->getUnixName().'/');
600 $res = db_query_params('UPDATE groups
603 short_description=$3,
608 use_pm_depend_box=$8,
619 array(htmlspecialchars($group_name),
621 htmlspecialchars($short_description),
638 if (!$res || db_affected_rows($res) < 1) {
639 $this->setError(_('Error updating project information')._(': ').db_error());
644 if (!$this->setUseDocman($use_docman)) {
645 $this->setError(_('Error updating project information use_docman')._(': ').db_error());
650 if ($this->setTags($tags) === false) {
655 // Log the audit trail
656 $this->addHistory('Changed Public Info', '');
658 if (!$this->fetchData($this->getID())) {
663 $hook_params = array();
664 $hook_params['group'] = $this;
665 $hook_params['group_id'] = $this->getID();
666 $hook_params['group_homepage'] = $homepage;
667 $hook_params['group_name'] = htmlspecialchars($group_name);
668 $hook_params['group_description'] = htmlspecialchars($short_description);
669 $hook_params['group_ispublic'] = $is_public;
670 if (!plugin_hook("group_update", $hook_params)) {
671 if (!$this->isError()) {
672 $this->setError(_('Error updating project information in plugin_hook group_update'));
683 * getID - Simply return the group_id for this object.
685 * @return int group_id.
688 return $this->data_array['group_id'];
692 * getStatus - the status code.
694 * Statuses char include I,H,A,D,P.
701 function getStatus() {
702 return $this->data_array['status'];
706 * setStatus - set the status code.
708 * Statuses include I,H,A,D,P.
715 * @param object $user User requesting operation (for access control).
716 * @param string $status Status value.
717 * @return bool success.
720 function setStatus(&$user, $status) {
723 if (!forge_check_global_perm_for_user($user, 'approve_projects')) {
724 $this->setPermissionDeniedError();
728 // Projects in 'A' status can only go to 'H' or 'D'
729 // Projects in 'D' status can only go to 'A'
730 // Projects in 'P' status can only go to 'A' OR 'D'
731 // Projects in 'I' status can only go to 'P'
732 // Projects in 'H' status can only go to 'A' OR 'D'
733 $allowed_status_changes = array(
734 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
735 'IP'=>1,'HA'=>1,'HD'=>1
738 // Check that status transition is valid
739 if ($this->getStatus() != $status
740 && !array_key_exists($this->getStatus(). $status, $allowed_status_changes)) {
741 $this->setError(_('Invalid Status Change From')._(': ').$this->getStatus()._(' To ')._(': ').$status);
747 $res = db_query_params('UPDATE groups
749 WHERE group_id=$2', array($status, $this->getID()));
751 if (!$res || db_affected_rows($res) < 1) {
752 $this->setError(_('Error')._(': ')._('Cannot change group status')._(': ').db_error());
758 // Activate system group, if not yet
759 if (!$SYS->sysCheckGroup($this->getID())) {
760 if (!$SYS->sysCreateGroup($this->getID())) {
761 $this->setError($SYS->getErrorMessage());
766 if (!$this->activateUsers()) {
771 /* Otherwise, the group is not active, and make sure that
772 System group is not active either */
773 } elseif ($SYS->sysCheckGroup($this->getID())) {
774 if (!$SYS->sysRemoveGroup($this->getID())) {
775 $this->setError($SYS->getErrorMessage());
781 $hook_params = array();
782 $hook_params['group'] = $this;
783 $hook_params['group_id'] = $this->getID();
784 $hook_params['status'] = $status;
785 plugin_hook("group_setstatus", $hook_params);
789 // Log the audit trail
790 if ($status != $this->getStatus()) {
791 $this->addHistory(_('Status'), $this->getStatus());
794 $this->data_array['status'] = $status;
799 * isPublic - Wrapper around RBAC to check if a project is anonymously readable
801 * @return boo is_public.
803 function isPublic() {
804 $ra = RoleAnonymous::getInstance();
805 return $ra->hasPermission('project_read', $this->getID());
809 * isActive - Database field status of 'A' returns true.
811 * @return bool is_active.
813 function isActive() {
814 if ($this->getStatus() == 'A') {
822 * isTemplate - Simply returns the is_template flag from the database.
824 * @return bool is_template.
826 function isTemplate() {
827 return $this->data_array['is_template'];
831 * setAsTemplate - Set the template status of a project
833 * @param bool $booleanparam is_template.
836 function setAsTemplate($booleanparam) {
838 $booleanparam = $booleanparam ? 1 : 0;
839 $res = db_query_params('UPDATE groups SET is_template=$1 WHERE group_id=$2',
840 array($booleanparam, $this->getID()));
842 if ($booleanparam != $this->data_array['is_template']) {
843 $this->addHistory('is_template', $this->data_array['is_template']);
845 $this->data_array['is_template'] = $booleanparam;
855 * getTemplateProject - Return the project template this project is built from
857 * @return object The template project
859 function getTemplateProject() {
860 return group_get_object($this->data_array['built_from_template']);
864 * getUnixName - the unix_name
866 * @return string unix_name.
868 function getUnixName() {
869 return strtolower($this->data_array['unix_group_name']);
873 * getPublicName - the full-length public name.
875 * @return string The group_name.
877 function getPublicName() {
878 return $this->data_array['group_name'];
882 * getRegisterPurpose - the text description of the purpose of this project.
884 * @return string The description.
886 function getRegisterPurpose() {
887 return $this->data_array['register_purpose'];
891 * getDescription - the text description of this project.
893 * @return string The description.
895 function getDescription() {
896 return $this->data_array['short_description'];
900 * getStartDate - the unix time this project was registered.
902 * @return int (unix time) of registration.
904 function getStartDate() {
905 return $this->data_array['register_time'];
909 * getLogoImageID - the id of the logo in the database for this project.
911 * @return int The ID of logo image in db_images table (or 100 if none).
913 function getLogoImageID() {
914 if (!isset($this->data_array['logo_image_id'])) {
915 $res = db_query_params('select id from db_images where group_id = $1 and is_logo = $2',
916 array($this->getID(), 1));
917 if ($res && db_numrows($res)) {
918 $this->data_array['logo_image_id'] = db_result($res, 0, 'id');
920 $this->data_array['logo_image_id'] = null;
923 return $this->data_array['logo_image_id'];
927 * getUnixBox - the hostname of the unix box where this project is located.
929 * @return string The name of the unix machine for the group.
931 function getUnixBox() {
932 return $this->data_array['unix_box'];
936 * getSCMBox - the hostname of the scm box where this project is located.
938 * @return string The name of the unix machine for the group.
940 function getSCMBox() {
941 return $this->data_array['scm_box'];
944 * setSCMBox - the hostname of the scm box where this project is located.
946 * @param string $scm_box The name of the new SCM_BOX
949 function setSCMBox($scm_box) {
951 if ($scm_box == $this->data_array['scm_box']) {
956 $res = db_query_params('UPDATE groups SET scm_box=$1 WHERE group_id=$2', array($scm_box, $this->getID()));
958 $this->addHistory('scm_box', $this->data_array['scm_box']);
959 $this->data_array['scm_box'] = $scm_box;
964 $this->setError(_("Could not insert SCM_BOX to database"));
968 $this->setError(_("SCM Box cannot be empty"));
974 * getDomain - the hostname.domain where their web page is located.
976 * @return string The name of the group [web] domain.
978 function getDomain() {
979 return $this->data_array['http_domain'];
983 * getRegistrationPurpose - the text description of the purpose of this project.
985 * @return string The application for project hosting.
987 function getRegistrationPurpose() {
988 return $this->data_array['register_purpose'];
992 * getAdmins - Get array of Admin user objects.
994 * @return array Array of User objects.
996 function &getAdmins() {
997 $roles = RBACEngine::getInstance()->getRolesByAllowedAction ('project_admin', $this->getID());
1001 foreach ($roles as $role) {
1002 if (! ($role instanceof RoleExplicit)) {
1005 if ($role->getHomeProject() == NULL
1006 || $role->getHomeProject()->getID() != $this->getID()) {
1010 foreach ($role->getUsers() as $u) {
1011 $user_ids[] = $u->getID();
1014 $active_ids = array();
1015 $ids = array_unique ($user_ids);
1016 foreach ($ids as $id) {
1017 $u = user_get_object ($id);
1018 if ($u->isActive()) {
1026 Common Group preferences for tools
1030 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
1032 * @return bool enable_scm.
1034 function enableAnonSCM() {
1035 $r = RoleAnonymous::getInstance();
1036 return $r->hasPermission('scm', $this->getID(), 'read');
1039 function SetUsesAnonSCM($booleanparam) {
1041 $booleanparam = $booleanparam ? 1 : 0;
1042 $r = RoleAnonymous::getInstance();
1043 $r->setSetting('scm', $this->getID(), $booleanparam);
1048 * enablePserver - whether or not this group has opted to enable Pserver.
1050 * @return bool enable_pserver.
1052 function enablePserver() {
1053 if ($this->usesSCM()) {
1054 return $this->data_array['enable_pserver'];
1060 function SetUsesPserver($booleanparam) {
1062 $booleanparam = $booleanparam ? 1 : 0;
1063 $res = db_query_params('UPDATE groups SET enable_pserver=$1 WHERE group_id=$2',
1064 array($booleanparam, $this->getID()));
1066 $this->data_array['enable_pserver'] = $booleanparam;
1076 * usesSCM - whether or not this group has opted to use SCM.
1078 * @return bool uses_scm.
1080 function usesSCM() {
1081 if (forge_get_config('use_scm')) {
1082 return $this->data_array['use_scm'];
1089 * setUseSCM - Set the SCM usage
1091 * @param bool $booleanparam enabled/disabled
1094 function setUseSCM($booleanparam) {
1096 $booleanparam = $booleanparam ? 1 : 0;
1097 $res = db_query_params('UPDATE groups SET use_scm=$1 WHERE group_id=$2',
1098 array($booleanparam, $this->getID()));
1100 $this->data_array['use_scm'] = $booleanparam;
1110 * usesMail - whether or not this group has opted to use mailing lists.
1112 * @return bool uses_mail.
1114 function usesMail() {
1115 if (forge_get_config('use_mail')) {
1116 return $this->data_array['use_mail'];
1121 $hook_params = array();
1122 $hook_params['group'] = $this;
1123 $hook_params['group_id'] = $this->getID();
1124 $hook_params['group_homepage'] = $this->getHomePage();
1125 $hook_params['group_name'] = $this->getPublicName();
1126 $hook_params['group_description'] = $this->getDescription();
1127 plugin_hook ("group_update", $hook_params);
1131 * setUseMail - Set the mailing-list usage
1133 * @param bool $booleanparam enabled/disabled
1136 function setUseMail($booleanparam) {
1138 $booleanparam = $booleanparam ? 1 : 0;
1139 $res = db_query_params('UPDATE groups SET use_mail=$1 WHERE group_id=$2',
1140 array($booleanparam, $this->getID()));
1142 $this->data_array['use_mail'] = $booleanparam;
1152 * usesNews - whether or not this group has opted to use news.
1154 * @return bool uses_news.
1156 function usesNews() {
1157 if (forge_get_config('use_news')) {
1158 return $this->data_array['use_news'];
1164 function setUseNews($booleanparam) {
1166 $booleanparam = $booleanparam ? 1 : 0;
1167 $res = db_query_params('UPDATE groups SET use_news=$1 WHERE group_id=$2',
1168 array($booleanparam, $this->getID()));
1170 $this->data_array['use_news'] = $booleanparam;
1180 * usesActivity - whether or not this group has opted to display Project Activities.
1182 * @return bool uses_activities.
1184 function usesActivity() {
1185 if (forge_get_config('use_activity')) {
1186 return $this->data_array['use_activity'];
1192 function setUseActivity($booleanparam) {
1194 $booleanparam = $booleanparam ? 1 : 0;
1195 $res = db_query_params('UPDATE groups SET use_activity=$1 WHERE group_id=$2',
1196 array($booleanparam, $this->getID()));
1198 $this->data_array['use_activity'] = $booleanparam;
1208 * usesForum - whether or not this group has opted to use discussion forums.
1210 * @return bool uses_forum.
1212 function usesForum() {
1213 if (forge_get_config('use_forum')) {
1214 return $this->data_array['use_forum'];
1221 * setUseForum - Set the forum usage
1223 * @param bool $booleanparam enabled/disabled
1226 function setUseForum($booleanparam) {
1228 $booleanparam = $booleanparam ? 1 : 0;
1229 $res = db_query_params('UPDATE groups SET use_forum=$1 WHERE group_id=$2',
1230 array($booleanparam, $this->getID()));
1232 $this->data_array['use_forum'] = $booleanparam;
1242 * usesStats - whether or not this group has opted to use stats.
1244 * @return bool uses_stats.
1246 function usesStats() {
1247 return $this->data_array['use_stats'];
1251 * usesFRS - whether or not this group has opted to use file release system.
1253 * @return bool uses_frs.
1255 function usesFRS() {
1256 if (forge_get_config('use_frs')) {
1257 return $this->data_array['use_frs'];
1264 * setUseFRS - Set the FRS usage
1266 * @param bool $booleanparam enabled/disabled
1269 function setUseFRS($booleanparam) {
1271 $booleanparam = $booleanparam ? 1 : 0;
1272 $res = db_query_params('UPDATE groups SET use_frs=$1 WHERE group_id=$2',
1273 array($booleanparam, $this->getID()));
1275 $this->data_array['use_frs']=$booleanparam;
1285 * usesTracker - whether or not this group has opted to use tracker.
1287 * @return bool uses_tracker.
1289 function usesTracker() {
1290 if (forge_get_config('use_tracker')) {
1291 return $this->data_array['use_tracker'];
1298 * setUseTracker - Set the tracker usage
1300 * @param bool $booleanparam enabled/disabled
1303 function setUseTracker($booleanparam) {
1305 $booleanparam = $booleanparam ? 1 : 0;
1306 $res = db_query_params ('UPDATE groups SET use_tracker=$1 WHERE group_id=$2',
1307 array($booleanparam, $this->getID()));
1309 $this->data_array['use_tracker']=$booleanparam;
1319 * useCreateOnline - whether or not this group has opted to use create online documents option.
1321 * @return bool use_docman_create_online.
1323 function useCreateOnline() {
1324 if (forge_get_config('use_docman')) {
1325 return $this->data_array['use_docman_create_online'];
1332 * usesDocman - whether or not this group has opted to use docman.
1334 * @return bool use_docman.
1336 function usesDocman() {
1337 if (forge_get_config('use_docman')) {
1338 return $this->data_array['use_docman'];
1345 * setUseDocman - Set the docman usage
1347 * @param bool $booleanparam enabled/disabled
1350 function setUseDocman($booleanparam) {
1352 $booleanparam = $booleanparam ? 1 : 0;
1353 $res = db_query_params('UPDATE groups SET use_docman = $1 WHERE group_id = $2',
1354 array($booleanparam, $this->getID()));
1356 // check if / doc_group exists, if not create it
1357 $trashdir = db_query_params('select groupname from doc_groups where groupname = $1 and group_id = $2',
1358 array('.trash', $this->getID()));
1359 if ($trashdir && db_numrows($trashdir) == 0) {
1360 $resinsert = db_query_params('insert into doc_groups (groupname, group_id, stateid) values ($1, $2, $3)',
1361 array('.trash', $this->getID(), '2'));
1367 $this->data_array['use_docman'] = $booleanparam;
1377 * useDocmanSearch - whether or not this group has opted to use docman search engine.
1379 * @return bool use_docman_search.
1381 function useDocmanSearch() {
1382 if (forge_get_config('use_docman')) {
1383 return $this->data_array['use_docman_search'];
1390 * useWebdav - whether or not this group has opted to use webdav interface.
1392 * @return bool use_docman_search.
1394 function useWebdav() {
1395 if (forge_get_config('use_webdav')) {
1396 return $this->data_array['use_webdav'];
1403 * usesFTP - whether or not this group has opted to use FTP.
1405 * @return bool uses_ftp.
1407 function usesFTP() {
1408 if (forge_get_config('use_ftp')) {
1409 return $this->data_array['use_ftp'];
1416 * usesSurvey - whether or not this group has opted to use surveys.
1418 * @return bool uses_survey.
1420 function usesSurvey() {
1421 if (forge_get_config('use_survey')) {
1422 return $this->data_array['use_survey'];
1429 * usesPM - whether or not this group has opted to Project Manager.
1431 * @return bool uses_projman.
1434 if (forge_get_config('use_pm')) {
1435 return $this->data_array['use_pm'];
1442 * setUsePM - Set the PM usage
1444 * @param bool $booleanparam enabled/disabled
1447 function setUsePM($booleanparam) {
1449 $booleanparam = $booleanparam ? 1 : 0;
1450 $res = db_query_params('UPDATE groups SET use_pm=$1 WHERE group_id=$2',
1451 array($booleanparam, $this->getID()));
1453 $this->data_array['use_pm']=$booleanparam;
1463 * getPlugins - get a list of all available group plugins
1465 * @return array array containing plugin_id => plugin_name
1467 function getPlugins() {
1468 if (!isset($this->plugins_data)) {
1469 $this->plugins_data = array();
1470 $res = db_query_params('SELECT group_plugin.plugin_id, plugins.plugin_name
1471 FROM group_plugin, plugins
1472 WHERE group_plugin.group_id=$1
1473 AND group_plugin.plugin_id=plugins.plugin_id', array($this->getID()));
1474 $rows = db_numrows($res);
1476 for ($i=0; $i<$rows; $i++) {
1477 $plugin_id = db_result($res, $i, 'plugin_id');
1478 $this->plugins_data[$plugin_id] = db_result($res, $i, 'plugin_name');
1481 return $this->plugins_data;
1485 * usesPlugin - returns true if the group uses a particular plugin
1487 * @param string $pluginname name of the plugin
1488 * @return bool whether plugin is being used or not
1490 function usesPlugin($pluginname) {
1491 $plugins_data = $this->getPlugins();
1492 foreach ($plugins_data as $p_id => $p_name) {
1493 if ($p_name == $pluginname) {
1501 * added for Codendi compatibility
1502 * usesServices - returns true if the group uses a particular plugin or feature
1504 * @param string $feature name of the plugin
1505 * @return bool whether plugin is being used or not
1507 function usesService($feature) {
1508 $plugins_data = $this->getPlugins();
1509 $pm = plugin_manager_get_object();
1510 foreach ($plugins_data as $p_id => $p_name) {
1511 if ($p_name == $feature) {
1514 if (is_object($pm->getPluginByName($p_name)) && $pm->getPluginByName($p_name)->provide($feature)) {
1522 * setPluginUse - enables/disables plugins for the group
1524 * @param string $pluginname name of the plugin
1525 * @param bool $val the new state
1526 * @return string database result
1528 function setPluginUse($pluginname, $val=true) {
1529 if ($val == $this->usesPlugin($pluginname)) {
1530 // State is already good, returning
1533 $res = db_query_params('SELECT plugin_id FROM plugins WHERE plugin_name=$1',
1534 array($pluginname));
1535 $rows = db_numrows($res);
1537 // Error: no plugin by that name
1540 $plugin_id = db_result($res,0,'plugin_id');
1542 unset($this->plugins_data);
1544 $res = db_query_params('INSERT INTO group_plugin (group_id, plugin_id) VALUES ($1, $2)',
1545 array($this->getID(),
1548 $res = db_query_params('DELETE FROM group_plugin WHERE group_id=$1 AND plugin_id=$2',
1549 array($this->getID(),
1552 $this->normalizeAllRoles();
1553 $hook_params = array();
1554 $hook_params['group_id'] = $this->getID();
1555 $hook_params['val'] = $val;
1556 plugin_hook("group_plugin_use", $hook_params);
1561 * getDocEmailAddress - get email address(es) to send doc notifications to.
1563 * @return string email address.
1565 function getDocEmailAddress() {
1566 return $this->data_array['new_doc_address'];
1569 function setDocEmailAddress($email) {
1570 $invalid_mails = validate_emails($email);
1571 if (count($invalid_mails) > 0) {
1572 $this->setError(sprintf(ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
1576 $res = db_query_params('UPDATE groups SET new_doc_address = $1 WHERE group_id = $2',
1577 array($email, $this->getID()));
1580 $this->setError(_('Error')._(': ')._('Cannot Update Group new_doc_address')._(': ').db_error());
1584 $this->data_array['new_doc_address'] = $email;
1591 * docEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1593 * @return bool email_on_all_doc_updates.
1595 function docEmailAll() {
1596 return $this->data_array['send_all_docs'];
1599 function setDocEmailAll($status) {
1601 $res = db_query_params('UPDATE groups SET send_all_docs = $1 WHERE group_id = $2',
1602 array($status, $this->getID()));
1605 $this->setError(_('Error')._(': ')._('Cannot Update Group send_all_docs')._(': ').db_error());
1609 $this->data_array['send_all_docs'] = $status;
1616 * getFRSEmailAddress - get email address(es) to send FRS notifications to.
1618 * @return string email address.
1620 function getFRSEmailAddress() {
1621 return $this->data_array['new_frs_address'];
1624 function setFRSEmailAddress($email) {
1625 $invalid_mails = validate_emails($email);
1626 if (count($invalid_mails) > 0) {
1627 $this->setError(sprintf(ngettext('New FRS Address Appeared Invalid: %s', 'New FRS Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
1631 $res = db_query_params('UPDATE groups SET new_frs_address = $1 WHERE group_id = $2',
1632 array($email, $this->getID()));
1635 $this->setError(_('Error')._(': ')._('Cannot Update Group new_frs_address')._(': ').db_error());
1639 $this->data_array['new_frs_address'] = $email;
1646 * frsEmailAll - whether or not this group has opted to use receive notices on all frs updates.
1648 * @return bool email_on_all_frs_updates.
1650 function frsEmailAll() {
1651 return $this->data_array['send_all_frs'];
1654 function setFRSEmailAll($status) {
1656 $res = db_query_params('UPDATE groups SET send_all_frs = $1 WHERE group_id = $2',
1657 array($status, $this->getID()));
1660 $this->setError(_('Error')._(': ')._('Cannot Update Group send_frs_docs')._(': ').db_error());
1664 $this->data_array['send_frs_docs'] = $status;
1671 * getHomePage - The URL for this project's home page.
1673 * @return string homepage URL.
1675 function getHomePage() {
1676 if (!preg_match("/^[a-zA-Z][a-zA-Z0-9+.-]*:/",
1677 $this->data_array['homepage'])) {
1678 $this->data_array['homepage'] = 'http://' .
1679 $this->data_array['homepage'];
1681 return $this->data_array['homepage'];
1685 * setHomepage - the hostname of the website url where this project is located.
1687 * @param string $homepage The name of the new HOMEPAGE
1690 function setHomepage($homepage) {
1692 if ($homepage == $this->data_array['homepage']) {
1697 $res = db_query_params('UPDATE groups SET homepage=$1 WHERE group_id=$2', array($homepage, $this->getID()));
1699 $this->addHistory('homepage', $this->data_array['homepage']);
1700 $this->data_array['homepage'] = $homepage;
1705 $this->setError(_('Could not insert homepage to database'));
1709 $this->setError(_('Homepage cannot be empty'));
1715 * getTags - Tags of this project.
1717 * @return string List of tags. Comma separated
1719 function getTags() {
1720 $sql = 'SELECT name FROM project_tags WHERE group_id = $1';
1721 $res = db_query_params($sql, array($this->getID()));
1722 return join(', ', util_result_column_to_array($res));
1726 * setTags - Set tags of this project.
1728 * @param string $tags
1729 * @return string database result.
1731 function setTags($tags) {
1733 $sql = 'DELETE FROM project_tags WHERE group_id=$1';
1734 $res = db_query_params($sql, array($this->getID()));
1736 $this->setError(_('Deleting old tags')._(': ').db_error());
1740 $inserted = array();
1741 $tags_array = preg_split('/[;,]/', $tags);
1742 foreach ($tags_array as $tag) {
1743 $tag = preg_replace('/[\t\r\n]/', ' ', $tag);
1744 // Allowed caracteres: [A-Z][a-z][0-9] -_&'#+.
1745 if (preg_match('/[^[:alnum:]| |\-|_|\&|\'|#|\+|\.]/', $tag)) {
1746 $this->setError(_('Bad tag name, you only can use the following characters: [A-Z][a-z][0-9]-_&\'#+. and space'));
1751 if ($tag == '' || array_search($tag, $inserted) !== false) {
1754 $sql = 'INSERT INTO project_tags (group_id,name) VALUES ($1, $2)';
1755 $res = db_query_params($sql, array($this->getID(), $tag));
1757 $this->setError(_('Setting tags')._(': ').db_error());
1768 * getPermission - Return a Permission for this Group
1770 * @return object The Permission.
1772 function &getPermission() {
1773 return permission_get_object($this);
1776 function delete($sure, $really_sure, $really_really_sure) {
1777 if (!$sure || !$really_sure || !$really_really_sure) {
1778 $this->setMissingParamsError(_('Please tick all checkboxes.'));
1781 if ($this->getID() == GROUP_IS_NEWS ||
1782 $this->getID() == GROUP_IS_MASTER ||
1783 $this->getID() == GROUP_IS_STATS ||
1784 $this->getID() == GROUP_IS_PEER_RATINGS) {
1785 $this->setError(_('Cannot Delete System Group'));
1788 $perm = $this->getPermission();
1789 if (!$perm || !is_object($perm)) {
1790 $this->setPermissionDeniedError();
1792 } elseif ($perm->isError() || !$perm->isSuperUser()) {
1793 $this->setPermissionDeniedError();
1799 // Remove all the members
1801 $members = $this->getMembers(false);
1802 foreach ($members as $i) {
1803 if(!$this->removeUser($i->getID())) {
1804 $this->setError(_('Could not properly remove member')._(': ').$i->getID());
1809 // unlink roles from this project
1810 foreach ($this->getRoles() as $r) {
1811 if ($r->getHomeProject() == NULL
1812 || $r->getHomeProject()->getID() != $this->getID()) {
1813 $r->unlinkProject($this);
1820 $atf = new ArtifactTypeFactory($this, true);
1821 $at_arr = $atf->getArtifactTypes();
1822 foreach ($at_arr as $i) {
1823 if (!is_object($i)) {
1826 if (!$i->delete(1,1)) {
1827 $this->setError(_('Could not properly delete the tracker')._(': ').$i->getErrorMessage());
1834 $rmf = new RoadmapFactory($this);
1835 $rm_arr = $rmf->getRoadmaps();
1836 foreach ($rm_arr as $i) {
1837 if (!is_object($i)) {
1840 if (!$i->delete()) {
1841 $this->setError(_('Could not properly delete the roadmap')._(': ').$i->getErrorMessage());
1849 $ff = new ForumFactory($this, true);
1850 $f_arr = $ff->getForums();
1851 foreach ($f_arr as $i) {
1852 if (!is_object($i)) {
1855 if(!$i->delete(1,1)) {
1856 $this->setError(_('Could not properly delete the forum')._(': ').$i->getErrorMessage());
1862 // Delete Subprojects
1864 $pgf = new ProjectGroupFactory($this, true);
1865 $pg_arr = $pgf->getProjectGroups();
1866 foreach ($pg_arr as $i) {
1867 if (!is_object($i)) {
1870 if (!$i->delete(1,1)) {
1871 $this->setError(_('Could not properly delete the ProjectGroup')._(': ').$i->getErrorMessage());
1877 // Delete FRS Packages
1879 $res = db_query_params('SELECT * FROM frs_package WHERE group_id=$1',
1880 array($this->getID()));
1882 $this->setError(_('Error FRS Packages')._(': ').db_error());
1887 while ($arr = db_fetch_array($res)) {
1888 $frsp=new FRSPackage($this, $arr['package_id'], $arr);
1889 if (!$frsp->delete(1, 1)) {
1890 $this->setError(_('Could not properly delete the FRSPackage')._(': ').$frsp->getErrorMessage());
1897 $news_group = group_get_object(GROUP_IS_NEWS);
1898 $res = db_query_params('SELECT forum_id FROM news_bytes WHERE group_id=$1',
1899 array($this->getID()));
1901 $this->setError(_('Error Deleting News')._(': ').db_error());
1906 for ($i=0; $i<db_numrows($res); $i++) {
1907 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1908 if (!$Forum->delete(1,1)) {
1909 $this->setError(_('Could not delete News Forum')._(': ').$Forum->getID());
1914 // Delete news forums in group itself
1915 for ($i = 0; $i < db_numrows($res); $i++) {
1916 $Forum = new Forum($this, db_result($res, $i, 'forum_id'));
1917 if (!$Forum->delete(1, 1)) {
1918 $this->setError(_('Could not delete News Forum')._(': ').$Forum->getID());
1923 $res = db_query_params('DELETE FROM news_bytes WHERE group_id=$1',
1924 array($this->getID()));
1926 $this->setError(_('Error Deleting News')._(': ').db_error());
1934 $res = db_query_params('DELETE FROM doc_data WHERE group_id=$1',
1935 array($this->getID()));
1937 $this->setError(_('Error Deleting Documents')._(': ').db_error());
1942 $res = db_query_params('DELETE FROM doc_groups WHERE group_id=$1',
1943 array($this->getID()));
1945 $this->setError(_('Error Deleting Document Groups')._(': ').db_error());
1953 $res=db_query_params('DELETE FROM project_tags WHERE group_id=$1', array($this->getID()));
1955 $this->setError(_('Error Deleting Tags')._(': ').db_error());
1961 // Delete group history
1963 $res = db_query_params('DELETE FROM group_history WHERE group_id=$1',
1964 array($this->getID()));
1966 $this->setError(_('Error Deleting Project History')._(': ').db_error());
1972 // Delete group plugins
1974 $res = db_query_params('DELETE FROM group_plugin WHERE group_id=$1',
1975 array($this->getID()));
1977 $this->setError(_('Error Deleting Project Plugins')._(': ').db_error());
1983 // Delete group cvs stats
1985 $res = db_query_params ('DELETE FROM stats_cvs_group WHERE group_id=$1',
1986 array($this->getID()));
1988 $this->setError(_('Error Deleting SCM Statistics')._(': ').db_error());
1996 $sf = new SurveyFactory($this, true);
1997 $s_arr =& $sf->getSurveys();
1998 foreach ($s_arr as $i) {
1999 if (!is_object($i)) {
2002 if (!$i->delete()) {
2003 $this->setError(_('Could not properly delete the survey'));
2008 // Delete SurveyQuestions
2010 $sqf = new SurveyQuestionFactory($this);
2011 $sq_arr = $sqf->getSurveyQuestions();
2012 if (is_array($sq_arr)) {
2013 foreach ($sq_arr as $i) {
2014 if (!is_object($i)) {
2017 if (!$i->delete()) {
2018 $this->setError(_('Could not properly delete the survey questions'));
2026 // Delete Mailing List Factory
2028 $mlf = new MailingListFactory($this, true);
2029 $ml_arr = $mlf->getMailingLists();
2030 foreach ($ml_arr as $i) {
2031 if (!is_object($i)) {
2034 if (!$i->delete(1,1)) {
2035 $this->setError(_('Could not properly delete the mailing list'));
2043 $res = db_query_params('DELETE FROM trove_group_link WHERE group_id=$1',
2044 array($this->getID()));
2046 $this->setError(_('Error Deleting Trove')._(': ').db_error());
2051 $res = db_query_params('DELETE FROM trove_agg WHERE group_id=$1',
2052 array($this->getID()));
2054 $this->setError(_('Error Deleting Trove')._(': ').db_error());
2062 $res = db_query_params('DELETE FROM project_sums_agg WHERE group_id=$1',
2063 array($this->getID()));
2065 $this->setError(_('Error Deleting Counters')._(': ').db_error());
2070 $res = db_query_params('INSERT INTO deleted_groups (unix_group_name, delete_date, isdeleted) VALUES ($1, $2, $3)',
2071 array($this->getUnixName(),
2075 $this->setError(_('Error Deleting Project')._(': ').db_error());
2080 // Remove users & delete roles from this project
2081 $members = $this->getMembers();
2082 foreach ($members as $userObject) {
2083 $this->removeUser($userObject->getID());
2085 $localRolesId = $this->getRolesId(false);
2086 foreach ($localRolesId as $localRoleId) {
2087 $roleObject = new Role($this, $localRoleId);
2088 $roleObject->delete();
2090 // Delete entry in groups.
2091 $res = db_query_params('DELETE FROM groups WHERE group_id=$1',
2092 array($this->getID()));
2094 $this->setError(_('Error Deleting Project')._(': ').db_error());
2101 $hook_params = array();
2102 $hook_params['group'] = $this;
2103 $hook_params['group_id'] = $this->getID();
2104 plugin_hook("group_delete", $hook_params);
2106 if (forge_get_config('upload_dir') != '' && $this->getUnixName()) {
2107 exec('/bin/rm -rf '.forge_get_config('upload_dir').'/'.$this->getUnixName().'/');
2109 if (forge_get_config('ftp_upload_dir') != '' && $this->getUnixName()) {
2110 exec('/bin/rm -rf '.forge_get_config('ftp_upload_dir').'/'.$this->getUnixName().'/');
2115 db_query_params('DELETE FROM rep_group_act_monthly WHERE group_id=$1',
2116 array($this->getID()));
2117 //echo 'rep_group_act_monthly'.db_error();
2118 db_query_params('DELETE FROM rep_group_act_weekly WHERE group_id=$1',
2119 array($this->getID()));
2120 //echo 'rep_group_act_weekly'.db_error();
2121 db_query_params('DELETE FROM rep_group_act_daily WHERE group_id=$1',
2122 array($this->getID()));
2123 //echo 'rep_group_act_daily'.db_error();
2124 unset($this->data_array);
2129 Basic functions to add/remove users to/from a group
2130 and update their permissions
2134 * addUser - controls adding a user to a group.
2136 * @param string $user_identifier Unix name of the user to add OR integer user_id.
2137 * @param int $role_id The role_id this user should have.
2138 * @return bool success.
2141 function addUser($user_identifier, $role_id) {
2144 Admins can add users to groups
2147 if (!forge_check_perm ('project_admin', $this->getID())) {
2148 $this->setPermissionDeniedError();
2154 get user id for this user's unix_name
2156 if (is_int ($user_identifier)) { // user_id or user_name
2157 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array($user_identifier));
2159 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array($user_identifier));
2161 if (db_numrows($res_newuser) > 0) {
2163 // make sure user is active
2165 if (db_result($res_newuser,0,'status') != 'A') {
2166 $this->setError(_('User is not active. Only active users can be added.'));
2172 // user was found - set new user_id var
2174 $user_id = db_result($res_newuser,0,'user_id');
2176 $role = new Role($this, $role_id);
2177 if (!$role || !is_object($role)) {
2178 $this->setError(_('Error Getting Role Object'));
2181 } elseif ($role->isError()) {
2182 $this->setError('addUser::roleget::'.$role->getErrorMessage());
2187 $role->addUser(user_get_object($user_id));
2188 if (!$SYS->sysCheckCreateGroup($this->getID())){
2189 $this->setError($SYS->getErrorMessage());
2193 if (!$SYS->sysCheckCreateUser($user_id)) {
2194 $this->setError($SYS->getErrorMessage());
2198 if (!$SYS->sysGroupCheckUser($this->getID(),$user_id)) {
2199 $this->setError($SYS->getErrorMessage());
2205 // user doesn't exist
2207 $this->setError(_('That user does not exist.'));
2212 $hook_params['group'] = $this;
2213 $hook_params['group_id'] = $this->getID();
2214 $hook_params['user'] = user_get_object($user_id);
2215 $hook_params['user_id'] = $user_id;
2216 plugin_hook ("group_adduser", $hook_params);
2221 $this->addHistory(_('Added User'), $user_identifier);
2227 $add_u = user_get_object($user_id);
2229 if (is_array($this->membersArr)) {
2230 foreach ($this->membersArr as $u) {
2231 if ($u->getID() == $add_u->getID()) {
2237 $this->membersArr[] = $add_u;
2245 * removeUser - controls removing a user from a group.
2247 * Users can remove themselves.
2249 * @param int $user_id The ID of the user to remove.
2250 * @return bool success.
2252 function removeUser($user_id) {
2255 if ($user_id != user_getid()
2256 && !forge_check_perm('project_admin', $this->getID())) {
2257 $this->setPermissionDeniedError();
2263 $user = user_get_object($user_id);
2264 $roles = RBACEngine::getInstance()->getAvailableRolesForUser($user);
2265 $found_roles = array();
2266 foreach ($roles as $role) {
2267 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
2268 $found_roles[] = $role;
2271 if (count($found_roles) == 0) {
2272 $this->setError(_('Error')._(': ')._('User not removed')._(': ').$user_id);
2276 foreach ($found_roles as $found_role) {
2277 $found_role->removeUser($user);
2278 if (!$SYS->sysGroupCheckUser($this->getID(), $user_id)) {
2279 $this->setError($SYS->getErrorMessage());
2286 // reassign open artifacts to id=100
2288 $res = db_query_params('UPDATE artifact SET assigned_to=100
2289 WHERE group_artifact_id
2290 IN (SELECT group_artifact_id
2291 FROM artifact_group_list
2292 WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
2293 array($this->getID(),
2296 $this->setError(_('Error')._(': ')._('artifact')._(': ').db_error());
2302 // reassign open tasks to id=100
2303 // first have to purge any assignments that would cause
2304 // conflict with existing assignment to 100
2306 $res = db_query_params('DELETE FROM project_assigned_to
2307 WHERE project_task_id IN (SELECT pt.project_task_id
2308 FROM project_task pt, project_group_list pgl, project_assigned_to pat
2309 WHERE pt.group_project_id = pgl.group_project_id
2310 AND pat.project_task_id=pt.project_task_id
2311 AND pt.status_id=1 AND pgl.group_id=$1
2312 AND pat.assigned_to_id=$2)
2313 AND assigned_to_id=100',
2314 array($this->getID(),
2317 $this->setError(_('Error')._(': ').sprintf(_('project_assigned_to %d: %s'), 1, db_error()));
2321 $res = db_query_params('UPDATE project_assigned_to SET assigned_to_id=100
2322 WHERE project_task_id IN (SELECT pt.project_task_id
2323 FROM project_task pt, project_group_list pgl
2324 WHERE pt.group_project_id = pgl.group_project_id
2325 AND pt.status_id=1 AND pgl.group_id=$1)
2326 AND assigned_to_id=$2',
2327 array($this->getID(),
2330 $this->setError(_('Error')._(': ').sprintf(_('project_assigned_to %d: %s'), 2, db_error()));
2336 // Remove user from system
2338 if (!$SYS->sysGroupRemoveUser($this->getID(), $user_id)) {
2339 $this->setError($SYS->getErrorMessage());
2344 $hook_params['group'] = $this;
2345 $hook_params['group_id'] = $this->getID();
2346 $hook_params['user'] = user_get_object($user_id);
2347 $hook_params['user_id'] = $user_id;
2348 plugin_hook("group_removeuser", $hook_params);
2351 $this->addHistory(_('Removed User'), $user_id);
2358 $del_u = user_get_object($user_id);
2359 foreach ($this->membersArr as $k => $u) {
2360 if ($u->getID() == $del_u->getID()) {
2361 unset($this->membersArr[$k]);
2370 * updateUser - controls updating a user's role in this group.
2372 * @param int $user_id The ID of the user.
2373 * @param int $role_id The role_id to set this user to.
2374 * @return bool success.
2376 function updateUser($user_id, $role_id) {
2378 if (!forge_check_perm ('project_admin', $this->getID())) {
2379 $this->setPermissionDeniedError();
2383 $newrole = RBACEngine::getInstance()->getRoleById ($role_id);
2384 if (!$newrole || !is_object($newrole)) {
2385 $this->setError(_('Could Not Get Role'));
2387 } elseif ($newrole->isError()) {
2388 $this->setError(_('Role')._(': ').$role->getErrorMessage());
2390 } elseif ($newrole->getHomeProject() == NULL
2391 || $newrole->getHomeProject()->getID() != $this->getID()) {
2392 $this->setError(_('Wrong destination role'));
2395 $user = user_get_object ($user_id);
2396 $roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user);
2398 foreach ($roles as $role) {
2399 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
2400 $found_role = $role;
2404 if ($found_role == NULL) {
2405 $this->setError(_('Error')._(': ')._('User not removed')._(': ').$user_id);
2409 $found_role->removeUser ($user);
2410 $newrole->addUser ($user);
2412 $this->addHistory(_('Updated User'), $user_id);
2417 * addHistory - Makes an audit trail entry for this project.
2419 * @param string $field_name The name of the field.
2420 * @param string $old_value The Old Value for this $field_name.
2421 * @return resource database result handle.
2424 function addHistory($field_name, $old_value) {
2425 if ($old_value == NULL) {
2429 return db_query_params('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
2430 VALUES ($1,$2,$3,$4,$5)',
2431 array($this->getID(),
2439 * activateUsers - Make sure that group members have unix accounts.
2441 * Setup unix accounts for group members. Can be called even
2442 * if members are already active.
2446 function activateUsers() {
2448 Activate member(s) of the project
2453 $members = $this->getUsers(true);
2455 foreach ($members as $member) {
2456 $user_id = $member->getID();
2458 if (!$SYS->sysCheckCreateGroup($this->getID())){
2459 $this->setError($SYS->getErrorMessage());
2463 if (!$SYS->sysCheckCreateUser($user_id)) {
2464 $this->setError($SYS->getErrorMessage());
2468 if (!$SYS->sysGroupCheckUser($this->getID(),$user_id)) {
2469 $this->setError($SYS->getErrorMessage());
2479 * getMembers - returns array of User objects for this project
2481 * @param bool $onlyactive Only users with state active, or all users of group
2482 * @return array of User objects for this group.
2484 function getMembers($onlyactive = true) {
2485 return $this->getUsers(true, $onlyactive);
2489 * replaceTemplateStrings - fill-in some blanks with project name
2491 * @param string $string Template string
2492 * @return string String after replacements
2494 function replaceTemplateStrings($string) {
2495 $string = str_replace('UNIXNAME', $this->getUnixName(), $string);
2496 $string = str_replace('PUBLICNAME', $this->getPublicName(), $string);
2497 $string = str_replace('DESCRIPTION', $this->getDescription(), $string);
2502 * approve - Approve pending project.
2504 * @param object $user The User object who is doing the updating.
2508 function approve(&$user) {
2509 global $gfcommon,$gfwww;
2510 require_once $gfcommon.'widget/WidgetLayoutManager.class.php';
2512 if ($this->getStatus()=='A') {
2513 $this->setError(_('Group already active'));
2519 // Step 1: Activate group and create LDAP entries
2520 if (!$this->setStatus($user, 'A')) {
2527 // Switch to system language for item creation
2528 setup_gettext_from_sys_lang();
2530 // Create default roles
2531 $idadmin_group = NULL;
2532 foreach (get_group_join_requests ($this) as $gjr) {
2533 $idadmin_group = $gjr->getUserID();
2536 if ($idadmin_group == NULL) {
2537 $idadmin_group = $user->getID();
2540 $template = $this->getTemplateProject();
2541 $id_mappings = array();
2542 $seen_admin_role = false;
2544 // Copy roles from template project
2545 foreach($template->getRoles() as $oldrole) {
2546 if ($oldrole->getHomeProject() != NULL) {
2547 $role = new Role($this);
2549 // Need to use a different role name so that the permissions aren't set from the hardcoded defaults
2550 $role->create('TEMPORARY ROLE NAME', $data, true);
2551 $role->setName($oldrole->getName());
2552 if ($oldrole->getSetting ('project_admin', $template->getID())) {
2553 $seen_admin_role = true;
2557 $role->linkProject($this);
2559 $id_mappings['role'][$oldrole->getID()] = $role->getID();
2560 // Reuse the project_admin permission
2561 $role->setSetting ('project_admin', $this->getID(), $oldrole->getSetting ('project_admin', $template->getID()));
2565 if (!$seen_admin_role) {
2566 $role = new Role($this);
2567 $adminperms = array('project_admin' => array ($this->getID() => 1));
2568 $role_id = $role->create ('Admin', $adminperms, true);
2571 $roles = $this->getRoles();
2572 foreach ($roles as $r) {
2573 if ($r->getHomeProject() == NULL) {
2576 if ($r->getSetting ('project_admin', $this->getID())) {
2577 $r->addUser(user_get_object ($idadmin_group));
2581 // Temporarily switch to the submitter's identity
2582 $saved_session = session_get_user();
2583 session_set_internal($idadmin_group);
2586 if (forge_get_config('use_tracker')) {
2587 $this->setUseTracker ($template->usesTracker());
2588 if ($template->usesTracker()) {
2589 $oldatf = new ArtifactTypeFactory($template);
2590 foreach ($oldatf->getArtifactTypes() as $o) {
2591 $t = new ArtifactType ($this);
2592 $t->create ($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->emailAll(),$o->getEmailAddress(),$o->getDuePeriod()/86400,0,$o->getSubmitInstructions(),$o->getBrowseInstructions());
2593 $id_mappings['tracker'][$o->getID()] = $t->getID();
2598 if (forge_get_config('use_pm')) {
2599 $this->setUsePM ($template->usesPM());
2600 if ($template->usesPM()) {
2601 $oldpgf = new ProjectGroupFactory($template);
2602 foreach ($oldpgf->getProjectGroups() as $o) {
2603 $pg = new ProjectGroup($this);
2604 $pg->create($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->getSendAllPostsTo());
2605 $id_mappings['pm'][$o->getID()] = $pg->getID();
2610 if (forge_get_config('use_forum')) {
2611 $this->setUseForum($template->usesForum());
2612 if ($template->usesForum()) {
2613 $oldff = new ForumFactory($template);
2614 foreach ($oldff->getForums() as $o) {
2615 $f = new Forum($this);
2616 $f->create($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->getSendAllPostsTo(),1);
2617 $id_mappings['forum'][$o->getID()] = $f->getID();
2622 if (forge_get_config('use_docman')) {
2623 $this->setUseDocman($template->usesDocman());
2624 if ($template->usesDocman()) {
2625 $olddgf = new DocumentGroupFactory($template);
2626 // First pass: create all docgroups
2627 $id_mappings['docman_docgroup'][0] = 0;
2628 foreach ($olddgf->getDocumentGroups(array(1, 5)) as $o) {
2629 $ndg = new DocumentGroup($this);
2630 // .trash is a reserved directory
2631 if ($o->getName() != '.trash') {
2632 $ndg->create($this->replaceTemplateStrings($o->getName()), 0, 1, null, true);
2633 $id_mappings['docman_docgroup'][$o->getID()] = $ndg->getID();
2636 // Second pass: restore hierarchy links & stateid
2637 foreach ($olddgf->getDocumentGroups(array(1, 5)) as $o) {
2638 $ndgf = new DocumentGroup($this);
2639 if ($o->getName() != '.trash') {
2640 $ndgf->fetchData($id_mappings['docman_docgroup'][$o->getID()]);
2641 $ndgf->update($ndgf->getName(), $id_mappings['docman_docgroup'][$o->getParentID()], 0, $o->getState());
2647 if (forge_get_config('use_frs')) {
2648 $this->setUseFRS ($template->usesFRS());
2649 if ($template->usesFRS()) {
2650 foreach (get_frs_packages($template) as $o) {
2651 $newp = new FRSPackage($this);
2652 $nname = $this->replaceTemplateStrings($o->getName());
2653 $newp->create($nname, $o->isPublic());
2654 $id_mappings['frs'][$o->getID()] = $newp->getID();
2655 foreach(get_frs_releases($o) as $or) {
2656 $newr = new FRSRelease($newp);
2657 $newr->create($this->replaceTemplateStrings($or->getName()), $this->replaceTemplateStrings($or->getNotes()), $this->replaceTemplateStrings($or->getChanges()), $or->getPreformatted());
2658 $id_mappings['frs_release'][$or->getID()] = $newr->getID();
2664 if (forge_get_config('use_mail')) {
2665 $this->setUseMail($template->usesMail());
2666 if ($template->usesMail()) {
2667 $oldmlf = new MailingListFactory($template);
2668 foreach ($oldmlf->getMailingLists() as $o) {
2669 $ml = new MailingList($this);
2670 $nname = preg_replace ('/^'.$template->getUnixName().'-/','',$o->getName());
2672 $ndescription = $this->replaceTemplateStrings($o->getDescription());
2673 $ml->create($nname, $ndescription, $o->isPublic());
2679 /* use SCM plugin from template group */
2680 $this->setUseSCM($template->usesSCM());
2682 foreach ($template->getPlugins() as
2683 $plugin_id => $plugin_name) {
2684 $this->setPluginUse($plugin_name);
2687 /* use SCM choice from registration page */
2688 foreach ($template->getPlugins() as $plugin_id => $plugin_name) {
2689 if (substr($plugin_name, 3) == 'scm' &&
2690 $plugin_name != 'scmhook') {
2691 /* skip copying scm plugins */
2694 /* enable other plugins though */
2695 $this->setPluginUse($plugin_name);
2699 foreach ($template->getRoles() as $oldrole) {
2700 $newrole = RBACEngine::getInstance()->getRoleById($id_mappings['role'][$oldrole->getID()]);
2701 if ($oldrole->getHomeProject() != NULL
2702 && $oldrole->getHomeProject()->getID() == $template->getID()) {
2703 $newrole->setPublic ($oldrole->isPublic());
2705 $oldsettings = $oldrole->getSettingsForProject ($template);
2707 $sections = array('project_read', 'project_admin', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm', 'frs_admin', 'new_frs');
2708 foreach ($sections as $section) {
2709 $newrole->setSetting ($section, $this->getID(), $oldsettings[$section][$template->getID()]);
2712 $sections = array('tracker', 'pm', 'forum', 'frs');
2713 foreach ($sections as $section) {
2714 if (isset ($oldsettings[$section])) {
2715 foreach ($oldsettings[$section] as $k => $v) {
2716 // Only copy perms for tools that have been copied
2717 if (isset ($id_mappings[$section][$k])) {
2718 $newrole->setSetting ($section,
2719 $id_mappings[$section][$k],
2727 $lm = new WidgetLayoutManager();
2728 $lm->createDefaultLayoutForProject($this->getID(), $template->getID());
2730 // second computation to clone fields and workflow
2731 if (forge_get_config('use_tracker')) {
2732 if ($template->usesTracker()) {
2733 $oldatf = new ArtifactTypeFactory($template);
2734 foreach ($oldatf->getArtifactTypes() as $o) {
2735 $t = artifactType_get_object($id_mappings['tracker'][$o->getID()]);
2736 $id_mappings['tracker'][$o->getID()] = $t->getID();
2737 $newEFIds = $t->cloneFieldsFrom($o->getID(), $id_mappings);
2738 if (forge_get_config('use_tracker_widget_display')) {
2739 $lm->createDefaultLayoutForTracker($t->getID(), $o->getID(), $newEFIds);
2746 $params['template'] = $template;
2747 $params['project'] = $this;
2748 $params['id_mappings'] = $id_mappings;
2749 plugin_hook_by_reference ('clone_project_from_template', $params);
2751 // Disable everything - except use_scm (manually set in the registration page)
2752 db_query_params ('UPDATE groups SET use_mail = 0, use_survey = 0, use_forum = 0, use_pm = 0, use_pm_depend_box = 0, use_news = 0,
2753 use_docman = 0, use_ftp = 0, use_tracker = 0, use_frs = 0, use_stats = 0 WHERE group_id = $1',
2754 array($this->getID()));
2757 $this->normalizeAllRoles();
2758 // empty members cache because the group creator is not yet in cache.
2759 unset($this->membersArr);
2760 $this->activateUsers();
2762 // Delete fake join request
2763 foreach (get_group_join_requests ($this) as $gjr) {
2767 // Switch back to user preference
2768 session_set_internal($saved_session->getID());
2769 setup_gettext_from_context();
2771 $this->sendApprovalEmail();
2772 $this->addHistory(_('Approved'), 'x');
2775 // Plugin can make approve operation there
2778 $params['group'] = $this;
2779 $params['group_id'] = $this->getID();
2780 plugin_hook('group_approved', $params);
2786 * sendApprovalEmail - Send new project email.
2788 * @return bool success.
2791 function sendApprovalEmail() {
2792 $admins = RBACEngine::getInstance()->getUsersByAllowedAction ('project_admin', $this->getID());
2794 if (count($admins) < 1) {
2795 $this->setError(_('Group does not have any administrators.'));
2799 // send one email per admin
2800 foreach ($admins as $admin) {
2801 setup_gettext_for_user ($admin);
2803 $message = sprintf(_('Your project registration for %s has been approved.'), forge_get_config ('forge_name')) . "\n\n"
2805 . _('Project Full Name')._(': '). htmlspecialchars_decode($this->getPublicName()) . "\n"
2806 . _('Project Unix Name')._(': '). $this->getUnixName() . "\n\n"
2808 . _('Your DNS will take up to a day to become active on our site. '
2809 .'Your web site is accessible through your shell account. Please read '
2810 .'site documentation (see link below) about intended usage, available '
2811 .'services, and directory layout of the account.') . "\n\n"
2813 . sprintf(_('If you visit your own project page in %s while logged in, '
2814 . 'you will find additional menu functions to your left labeled “Project Admin”.'),
2815 forge_get_config ('forge_name')) . "\n\n"
2817 . sprintf(_('We highly suggest that you now visit %1$s and create a public '
2818 . 'description for your project. This can be done by visiting your project '
2819 . 'page while logged in, and selecting “Project Admin” from the menus '
2820 . 'on the left (or by visiting %2$s after login).'),
2821 forge_get_config ('forge_name'), util_make_url('/project/admin/?group_id='.$this->getID())) . "\n\n"
2823 . sprintf(_('Your project will also not appear in the Trove Software Map (primary '
2824 . 'list of projects hosted on %s which offers great flexibility in '
2825 . 'browsing and search) until you categorize it in the project administration '
2826 . 'screens. So that people can find your project, you should do this now. '
2827 . 'Visit your project while logged in, and select “Project Admin” from the '
2828 . 'menus on the left.'), forge_get_config ('forge_name')) . "\n\n"
2830 . sprintf(_('Enjoy the system, and please tell others about %s. Let us know '
2831 . 'if there is anything we can do to help you.'), forge_get_config ('forge_name')) . "\n\n"
2833 . sprintf(_('-- the %s staff'), forge_get_config ('forge_name')) . "\n";
2835 util_send_message($admin->getEmail(), sprintf(_('%s Project Approved'), forge_get_config ('forge_name')), $message);
2837 setup_gettext_from_context();
2844 * sendRejectionEmail - Send project rejection email.
2846 * This function sends out a rejection message to a user who
2847 * registered a project.
2849 * @param int $response_id The id of the response to use.
2850 * @param string $message The rejection message.
2851 * @return bool completion status.
2854 function sendRejectionEmail($response_id, $message = 'zxcv') {
2855 $submitters = array();
2856 foreach (get_group_join_requests ($this) as $gjr) {
2857 $submitters[] = user_get_object($gjr->getUserID());
2860 if (count ($submitters) < 1) {
2861 $this->setError(_('Group does not have any administrators.'));
2865 foreach ($submitters as $admin) {
2866 setup_gettext_for_user($admin);
2868 $response = sprintf(_('Your project registration for %s has been denied.'), forge_get_config('forge_name')) . "\n\n"
2869 . _('Project Full Name')._(': '). $this->getPublicName() . "\n"
2870 . _('Project Unix Name')._(': '). $this->getUnixName() . "\n\n"
2871 . _('Reasons for negative decision')._(': ') . "\n\n";
2873 // Check to see if they want to send a custom rejection response
2874 if ($response_id == 0) {
2875 $response .= $message;
2877 $response .= db_result(
2878 db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array($response_id)),
2883 util_send_message($admin->getEmail(), sprintf(_('%s Project Denied'), forge_get_config('forge_name')), $response);
2884 setup_gettext_from_context();
2891 * sendNewProjectNotificationEmail - Send new project notification email.
2893 * This function sends out a notification email to the
2894 * SourceForge admin user when a new project is
2897 * @return bool success.
2900 function sendNewProjectNotificationEmail() {
2901 // Get the user who wants to register the project
2902 $submitters = array();
2903 foreach (get_group_join_requests ($this) as $gjr) {
2904 $submitters[] = user_get_object($gjr->getUserID());
2906 if (count ($submitters) < 1) {
2907 $this->setError(_('Could not find user who has submitted the project.'));
2911 $admins = RBACEngine::getInstance()->getUsersByAllowedAction('approve_projects', -1);
2913 if (count($admins) < 1) {
2914 $this->setError(_('There is no administrator to send the mail to.'));
2918 foreach ($admins as $admin) {
2919 $admin_email = $admin->getEmail();
2920 setup_gettext_for_user ($admin);
2922 $message = sprintf(_('New %s Project Submitted'), forge_get_config('forge_name')) . "\n\n"
2923 . _('Project Full Name')._(': ').htmlspecialchars_decode($this->getPublicName()) . "\n"
2924 . _('Submitted Description')._(': ').htmlspecialchars_decode($this->getRegistrationPurpose()) . "\n";
2926 foreach ($submitters as $submitter) {
2927 $message .= _('Submitter')._(': ').$submitter->getRealName().' ('.$submitter->getUnixName().')' . "\n\n";
2931 . _('Please visit the following URL to approve or reject this project')._(': '). "\n"
2932 . util_make_url('/admin/approve-pending.php');
2933 util_send_message($admin_email, sprintf(_('New %s Project Submitted'), forge_get_config('forge_name')), $message);
2934 setup_gettext_from_context();
2937 $email = $submitter->getEmail();
2938 setup_gettext_for_user ($submitter);
2940 $message = sprintf(_('New %s Project Submitted'), forge_get_config ('forge_name')) . "\n\n"
2941 . _('Project Full Name')._(': ') . $this->getPublicName() . "\n"
2942 . _('Submitted Description')._(': ') . util_unconvert_htmlspecialchars($this->getRegistrationPurpose()) . "\n\n"
2943 . sprintf(_('The %s admin team will now examine your project submission. You will be notified of their decision.'),
2944 forge_get_config ('web_host'));
2946 util_send_message($email, sprintf(_('New %s Project Submitted'), forge_get_config ('forge_name')), $message);
2947 setup_gettext_from_context();
2953 * validateGroupName - Validate the group name
2955 * @param string $group_name Project name.
2957 * @return bool an error false and set an error is the group name is invalid otherwise return true
2959 function validateGroupName($group_name) {
2960 if (strlen($group_name)<3) {
2961 $this->setError(_('Project name is too short'));
2963 } elseif (strlen(htmlspecialchars($group_name))>40) {
2964 $this->setError(_('Project name is too long'));
2966 } elseif (group_get_object_by_publicname($group_name)) {
2967 $this->setError(_('Project name already taken'));
2974 * getRolesId - Get Ids of the roles of the group.
2976 * @param bool all role ids or local role ids only. Default is all role ids
2977 * @return array Role ids of this group.
2979 function getRolesId($global = true) {
2980 $role_ids = array();
2982 $res = db_query_params('SELECT role_id FROM pfo_role WHERE home_group_id=$1',
2983 array($this->getID()));
2984 while ($arr = db_fetch_array($res)) {
2985 $role_ids[] = $arr['role_id'];
2988 $res = db_query_params('SELECT role_id FROM role_project_refs WHERE group_id=$1',
2989 array($this->getID()));
2990 while ($arr = db_fetch_array($res)) {
2991 $role_ids[] = $arr['role_id'];
2995 return array_unique($role_ids);
2999 * getRoles - Get the roles of the group.
3001 * @param bool all roles or local roles only. Default is all roles
3002 * @return array Roles of this group.
3004 function getRoles($global = true) {
3007 $roles = $this->getRolesId($global);
3008 $engine = RBACEngine::getInstance();
3009 foreach ($roles as $role_id) {
3010 $result[] = $engine->getRoleById($role_id);
3016 function normalizeAllRoles() {
3017 $roles = $this->getRoles();
3019 foreach ($roles as $r) {
3020 $r->normalizeData();
3025 * getUnixStatus - Status of activation of unix account.
3027 * @return string Values: (N)one, (A)ctive, (S)uspended or (D)eleted
3029 function getUnixStatus() {
3030 return $this->data_array['unix_status'];
3034 * setUnixStatus - Sets status of activation of unix account.
3036 * @param string $status The unix status.
3042 * @return bool success.
3044 function setUnixStatus($status) {
3047 $res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
3052 $this->setError(_('Error')._(': ')._('Cannot Update Group Unix Status')._(': ').db_error());
3056 if ($status == 'A') {
3057 if (!$SYS->sysCheckCreateGroup($this->getID())) {
3058 $this->setError($SYS->getErrorMessage());
3063 if ($SYS->sysCheckGroup($this->getID())) {
3064 if (!$SYS->sysRemoveGroup($this->getID())) {
3065 $this->setError($SYS->getErrorMessage());
3072 $this->data_array['unix_status'] = $status;
3079 * getUsers - Get the users of a group
3081 * @param bool $onlylocal
3082 * @param bool $onlyactive Only users with state active, or all users of group
3083 * @return array user's objects.
3085 function getUsers($onlylocal = true, $onlyactive = true) {
3086 if (!isset($this->membersArr)) {
3087 $this->membersArr = array();
3090 foreach ($this->getRoles() as $role) {
3092 && ($role->getHomeProject() == NULL || $role->getHomeProject()->getID() != $this->getID())) {
3095 foreach ($role->getUsers() as $user) {
3096 $ids[] = $user->getID();
3099 $ids = array_unique ($ids);
3100 foreach ($ids as $id) {
3101 $u = user_get_object ($id);
3102 if (!$onlyactive || $u->isActive()) {
3103 $this->membersArr[] = $u;
3107 return $this->membersArr;
3110 function setDocmanCreateOnlineStatus($status) {
3112 $res = db_query_params('UPDATE groups SET use_docman_create_online = $1 WHERE group_id = $2',
3113 array($status, $this->getID()));
3116 $this->setError(_('Error')._(': ')._('Cannot Update Group DocmanCreateOnline Status')._(': ').db_error());
3120 $this->data_array['use_docman_create_online'] = $status;
3126 function setDocmanWebdav($status) {
3128 $res = db_query_params('UPDATE groups SET use_webdav = $1 WHERE group_id = $2',
3133 $this->setError(_('Error')._(': ')._('Cannot Update Group UseWebdav Status')._(': ').db_error());
3137 $this->data_array['use_webdav'] = $status;
3143 function setDocmanSearchStatus($status) {
3145 /* if we activate search engine, we probably want to reindex */
3146 $res = db_query_params('UPDATE groups SET use_docman_search = $1, force_docman_reindex = $1 WHERE group_id = $2',
3147 array($status, $this->getID()));
3150 $this->setError(_('Error')._(': ')._('Cannot Update Group UseDocmanSearch Status')._(': ').db_error());
3154 $this->data_array['use_docman_search'] = $status;
3160 function setDocmanForceReindexSearch($status) {
3162 $res = db_query_params('UPDATE groups SET force_docman_reindex = $1 WHERE group_id = $2',
3163 array($status, $this->getID()));
3166 $this->setError(_('Error')._(': ')._('Cannot Update Group force_docman_reindex')._(': ').db_error());
3170 $this->data_array['force_docman_reindex'] = $status;
3178 * @param int $unit_set_id the effort unit set id
3181 function setEffortUnitSet($unit_set_id) {
3183 $res = db_query_params ('UPDATE groups SET unit_set_id=$1 WHERE group_id=$2',
3184 array($unit_set_id, $this->getID()));
3186 $this->data_array['unit_set_id'] = $unit_set_id;
3196 * getEffortUnitSet - Get the effort unit set id.
3198 * @return int The id of the effort unit set.
3200 function getEffortUnitSet() {
3201 return $this->data_array['unit_set_id'];
3204 function getWidgetLayoutConfig() {
3205 $lm = new WidgetLayoutManager();
3206 return $lm->getLayout($this->getID(), WidgetLayoutManager::OWNER_TYPE_GROUP);
3211 * group_getname() - get the group name
3213 * @param int $group_id The group ID
3218 function group_getname ($group_id = 0) {
3219 $grp = group_get_object($group_id);
3221 return $grp->getPublicName();
3228 * group_getunixname() - get the unixname for a group
3230 * @param int $group_id The group ID
3235 function group_getunixname ($group_id) {
3236 $grp = group_get_object($group_id);
3238 return $grp->getUnixName();
3245 * group_get_result() - Get the group object result ID.
3247 * @param int $group_id The group ID
3252 function &group_get_result($group_id=0) {
3253 $grp = group_get_object($group_id);
3255 return $grp->getData();
3261 function getAllProjectTags($onlyvisible = true) {
3262 $res = db_query_params('SELECT project_tags.name, groups.group_id FROM groups, project_tags WHERE groups.group_id = project_tags.group_id AND groups.status = $1 ORDER BY project_tags.name, groups.group_id',
3265 if (!$res || db_numrows($res) == 0) {
3271 while ($arr = db_fetch_array($res)) {
3273 $group_id = $arr[1];
3274 if (!isset($result[$tag])) {
3275 $result[$tag] = array();
3278 if (!$onlyvisible || forge_check_perm('project_read', $group_id)) {
3279 $p = group_get_object($group_id);
3280 $result[$tag][] = array('unix_group_name' => $p->getUnixName(),
3281 'group_id' => $group_id);
3289 * Utility class to compare project based in various criteria (names, unixnames, id, ...)
3292 class ProjectComparator {
3293 var $criterion = 'name';
3295 function Compare ($a, $b) {
3296 switch ($this->criterion) {
3299 $namecmp = strcoll ($a->getPublicName(), $b->getPublicName());
3300 if ($namecmp != 0) {
3303 /* If several projects share a same public name */
3304 return strcoll ($a->getUnixName(), $b->getUnixName());
3306 return strcmp ($a->getUnixName(), $b->getUnixName());
3313 return ($aid < $bid) ? -1 : 1;
3318 function sortProjectList (&$list, $criterion='name') {
3319 $cmp = new ProjectComparator();
3320 $cmp->criterion = $criterion;
3322 return usort ($list, array($cmp, 'Compare'));
3327 // c-file-style: "bsd"