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 * @param string $new_doc_address
514 * @param bool $send_all_docs
515 * @return int status.
518 function update(&$user, $group_name, $homepage, $short_description, $use_mail, $use_survey, $use_forum,
519 $use_pm, $use_pm_depend_box, $use_scm, $use_news, $use_docman,
520 $new_doc_address, $send_all_docs, $logo_image_id,
521 $use_ftp, $use_tracker, $use_frs, $use_stats, $tags, $use_activity, $is_public, $new_frs_address, $send_all_frs) {
523 $perm =& $this->getPermission();
525 if (!$perm || !is_object($perm)) {
526 $this->setError(_('Could not get permission.'));
530 if (!$perm->isAdmin()) {
531 $this->setError(_('Permission denied.'));
535 // Validate some values
536 if ($this->getPublicName() != htmlspecialchars($group_name)) {
537 if (!$this->validateGroupName($group_name)) {
542 if ($new_doc_address) {
543 $invalid_mails = validate_emails($new_doc_address);
544 if (count($invalid_mails) > 0) {
545 $this->setError(sprintf(ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
550 if ($new_frs_address) {
551 $invalid_mails = validate_emails($new_frs_address);
552 if (count($invalid_mails) > 0) {
553 $this->setError(sprintf(ngettext('New FRS Address Appeared Invalid: %s', 'New FRS Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
558 // in the database, these all default to '1',
559 // so we have to explicitly set 0
572 if (!$use_pm_depend_box) {
573 $use_pm_depend_box = 0;
596 if (!$use_activity) {
599 if (!$send_all_docs) {
603 if (!$send_all_frs) {
607 $homepage = ltrim($homepage);
609 $homepage = util_make_url('/projects/'.$this->getUnixName().'/');
614 $res = db_query_params('UPDATE groups
617 short_description=$3,
622 use_pm_depend_box=$8,
635 array(htmlspecialchars($group_name),
637 htmlspecialchars($short_description),
656 if (!$res || db_affected_rows($res) < 1) {
657 $this->setError(_('Error updating project information')._(': ').db_error());
662 if (!$this->setUseDocman($use_docman)) {
663 $this->setError(_('Error updating project information use_docman')._(': ').db_error());
668 if ($this->setTags($tags) === false) {
673 // Log the audit trail
674 $this->addHistory('Changed Public Info', '');
676 if (!$this->fetchData($this->getID())) {
681 $hook_params = array();
682 $hook_params['group'] = $this;
683 $hook_params['group_id'] = $this->getID();
684 $hook_params['group_homepage'] = $homepage;
685 $hook_params['group_name'] = htmlspecialchars($group_name);
686 $hook_params['group_description'] = htmlspecialchars($short_description);
687 $hook_params['group_ispublic'] = $is_public;
688 if (!plugin_hook("group_update", $hook_params)) {
689 if (!$this->isError()) {
690 $this->setError(_('Error updating project information in plugin_hook group_update'));
701 * getID - Simply return the group_id for this object.
703 * @return int group_id.
706 return $this->data_array['group_id'];
710 * getStatus - the status code.
712 * Statuses char include I,H,A,D,P.
719 function getStatus() {
720 return $this->data_array['status'];
724 * setStatus - set the status code.
726 * Statuses include I,H,A,D,P.
733 * @param object $user User requesting operation (for access control).
734 * @param string $status Status value.
735 * @return bool success.
738 function setStatus(&$user, $status) {
741 if (!forge_check_global_perm_for_user($user, 'approve_projects')) {
742 $this->setPermissionDeniedError();
746 // Projects in 'A' status can only go to 'H' or 'D'
747 // Projects in 'D' status can only go to 'A'
748 // Projects in 'P' status can only go to 'A' OR 'D'
749 // Projects in 'I' status can only go to 'P'
750 // Projects in 'H' status can only go to 'A' OR 'D'
751 $allowed_status_changes = array(
752 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
753 'IP'=>1,'HA'=>1,'HD'=>1
756 // Check that status transition is valid
757 if ($this->getStatus() != $status
758 && !array_key_exists($this->getStatus(). $status, $allowed_status_changes)) {
759 $this->setError(_('Invalid Status Change From')._(': ').$this->getStatus()._(' To ')._(': ').$status);
765 $res = db_query_params('UPDATE groups
767 WHERE group_id=$2', array($status, $this->getID()));
769 if (!$res || db_affected_rows($res) < 1) {
770 $this->setError(_('Error')._(': ')._('Cannot change group status')._(': ').db_error());
776 // Activate system group, if not yet
777 if (!$SYS->sysCheckGroup($this->getID())) {
778 if (!$SYS->sysCreateGroup($this->getID())) {
779 $this->setError($SYS->getErrorMessage());
784 if (!$this->activateUsers()) {
789 /* Otherwise, the group is not active, and make sure that
790 System group is not active either */
791 } elseif ($SYS->sysCheckGroup($this->getID())) {
792 if (!$SYS->sysRemoveGroup($this->getID())) {
793 $this->setError($SYS->getErrorMessage());
799 $hook_params = array();
800 $hook_params['group'] = $this;
801 $hook_params['group_id'] = $this->getID();
802 $hook_params['status'] = $status;
803 plugin_hook("group_setstatus", $hook_params);
807 // Log the audit trail
808 if ($status != $this->getStatus()) {
809 $this->addHistory(_('Status'), $this->getStatus());
812 $this->data_array['status'] = $status;
817 * isPublic - Wrapper around RBAC to check if a project is anonymously readable
819 * @return boo is_public.
821 function isPublic() {
822 $ra = RoleAnonymous::getInstance();
823 return $ra->hasPermission('project_read', $this->getID());
827 * isActive - Database field status of 'A' returns true.
829 * @return bool is_active.
831 function isActive() {
832 if ($this->getStatus() == 'A') {
840 * isTemplate - Simply returns the is_template flag from the database.
842 * @return bool is_template.
844 function isTemplate() {
845 return $this->data_array['is_template'];
849 * setAsTemplate - Set the template status of a project
851 * @param bool $booleanparam is_template.
854 function setAsTemplate($booleanparam) {
856 $booleanparam = $booleanparam ? 1 : 0;
857 $res = db_query_params('UPDATE groups SET is_template=$1 WHERE group_id=$2',
858 array($booleanparam, $this->getID()));
860 if ($booleanparam != $this->data_array['is_template']) {
861 $this->addHistory('is_template', $this->data_array['is_template']);
863 $this->data_array['is_template'] = $booleanparam;
873 * getTemplateProject - Return the project template this project is built from
875 * @return object The template project
877 function getTemplateProject() {
878 return group_get_object($this->data_array['built_from_template']);
882 * getUnixName - the unix_name
884 * @return string unix_name.
886 function getUnixName() {
887 return strtolower($this->data_array['unix_group_name']);
891 * getPublicName - the full-length public name.
893 * @return string The group_name.
895 function getPublicName() {
896 return $this->data_array['group_name'];
900 * getRegisterPurpose - the text description of the purpose of this project.
902 * @return string The description.
904 function getRegisterPurpose() {
905 return $this->data_array['register_purpose'];
909 * getDescription - the text description of this project.
911 * @return string The description.
913 function getDescription() {
914 return $this->data_array['short_description'];
918 * getStartDate - the unix time this project was registered.
920 * @return int (unix time) of registration.
922 function getStartDate() {
923 return $this->data_array['register_time'];
927 * getLogoImageID - the id of the logo in the database for this project.
929 * @return int The ID of logo image in db_images table (or 100 if none).
931 function getLogoImageID() {
932 if (!isset($this->data_array['logo_image_id'])) {
933 $res = db_query_params('select id from db_images where group_id = $1 and is_logo = $2',
934 array($this->getID(), 1));
935 if ($res && db_numrows($res)) {
936 $this->data_array['logo_image_id'] = db_result($res, 0, 'id');
938 $this->data_array['logo_image_id'] = null;
941 return $this->data_array['logo_image_id'];
945 * getUnixBox - the hostname of the unix box where this project is located.
947 * @return string The name of the unix machine for the group.
949 function getUnixBox() {
950 return $this->data_array['unix_box'];
954 * getSCMBox - the hostname of the scm box where this project is located.
956 * @return string The name of the unix machine for the group.
958 function getSCMBox() {
959 return $this->data_array['scm_box'];
962 * setSCMBox - the hostname of the scm box where this project is located.
964 * @param string $scm_box The name of the new SCM_BOX
967 function setSCMBox($scm_box) {
969 if ($scm_box == $this->data_array['scm_box']) {
974 $res = db_query_params('UPDATE groups SET scm_box=$1 WHERE group_id=$2', array($scm_box, $this->getID()));
976 $this->addHistory('scm_box', $this->data_array['scm_box']);
977 $this->data_array['scm_box'] = $scm_box;
982 $this->setError(_("Could not insert SCM_BOX to database"));
986 $this->setError(_("SCM Box cannot be empty"));
992 * getDomain - the hostname.domain where their web page is located.
994 * @return string The name of the group [web] domain.
996 function getDomain() {
997 return $this->data_array['http_domain'];
1001 * getRegistrationPurpose - the text description of the purpose of this project.
1003 * @return string The application for project hosting.
1005 function getRegistrationPurpose() {
1006 return $this->data_array['register_purpose'];
1010 * getAdmins - Get array of Admin user objects.
1012 * @return array Array of User objects.
1014 function &getAdmins() {
1015 $roles = RBACEngine::getInstance()->getRolesByAllowedAction ('project_admin', $this->getID());
1017 $user_ids = array();
1019 foreach ($roles as $role) {
1020 if (! ($role instanceof RoleExplicit)) {
1023 if ($role->getHomeProject() == NULL
1024 || $role->getHomeProject()->getID() != $this->getID()) {
1028 foreach ($role->getUsers() as $u) {
1029 $user_ids[] = $u->getID();
1032 $active_ids = array();
1033 $ids = array_unique ($user_ids);
1034 foreach ($ids as $id) {
1035 $u = user_get_object ($id);
1036 if ($u->isActive()) {
1044 Common Group preferences for tools
1048 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
1050 * @return bool enable_scm.
1052 function enableAnonSCM() {
1053 $r = RoleAnonymous::getInstance();
1054 return $r->hasPermission('scm', $this->getID(), 'read');
1057 function SetUsesAnonSCM($booleanparam) {
1059 $booleanparam = $booleanparam ? 1 : 0;
1060 $r = RoleAnonymous::getInstance();
1061 $r->setSetting('scm', $this->getID(), $booleanparam);
1066 * enablePserver - whether or not this group has opted to enable Pserver.
1068 * @return bool enable_pserver.
1070 function enablePserver() {
1071 if ($this->usesSCM()) {
1072 return $this->data_array['enable_pserver'];
1078 function SetUsesPserver($booleanparam) {
1080 $booleanparam = $booleanparam ? 1 : 0;
1081 $res = db_query_params('UPDATE groups SET enable_pserver=$1 WHERE group_id=$2',
1082 array($booleanparam, $this->getID()));
1084 $this->data_array['enable_pserver'] = $booleanparam;
1094 * usesSCM - whether or not this group has opted to use SCM.
1096 * @return bool uses_scm.
1098 function usesSCM() {
1099 if (forge_get_config('use_scm')) {
1100 return $this->data_array['use_scm'];
1107 * setUseSCM - Set the SCM usage
1109 * @param bool $booleanparam enabled/disabled
1112 function setUseSCM($booleanparam) {
1114 $booleanparam = $booleanparam ? 1 : 0;
1115 $res = db_query_params('UPDATE groups SET use_scm=$1 WHERE group_id=$2',
1116 array($booleanparam, $this->getID()));
1118 $this->data_array['use_scm'] = $booleanparam;
1128 * usesMail - whether or not this group has opted to use mailing lists.
1130 * @return bool uses_mail.
1132 function usesMail() {
1133 if (forge_get_config('use_mail')) {
1134 return $this->data_array['use_mail'];
1139 $hook_params = array();
1140 $hook_params['group'] = $this;
1141 $hook_params['group_id'] = $this->getID();
1142 $hook_params['group_homepage'] = $this->getHomePage();
1143 $hook_params['group_name'] = $this->getPublicName();
1144 $hook_params['group_description'] = $this->getDescription();
1145 plugin_hook ("group_update", $hook_params);
1149 * setUseMail - Set the mailing-list usage
1151 * @param bool $booleanparam enabled/disabled
1154 function setUseMail($booleanparam) {
1156 $booleanparam = $booleanparam ? 1 : 0;
1157 $res = db_query_params('UPDATE groups SET use_mail=$1 WHERE group_id=$2',
1158 array($booleanparam, $this->getID()));
1160 $this->data_array['use_mail'] = $booleanparam;
1170 * usesNews - whether or not this group has opted to use news.
1172 * @return bool uses_news.
1174 function usesNews() {
1175 if (forge_get_config('use_news')) {
1176 return $this->data_array['use_news'];
1182 function setUseNews($booleanparam) {
1184 $booleanparam = $booleanparam ? 1 : 0;
1185 $res = db_query_params('UPDATE groups SET use_news=$1 WHERE group_id=$2',
1186 array($booleanparam, $this->getID()));
1188 $this->data_array['use_news'] = $booleanparam;
1198 * usesActivity - whether or not this group has opted to display Project Activities.
1200 * @return bool uses_activities.
1202 function usesActivity() {
1203 if (forge_get_config('use_activity')) {
1204 return $this->data_array['use_activity'];
1210 function setUseActivity($booleanparam) {
1212 $booleanparam = $booleanparam ? 1 : 0;
1213 $res = db_query_params('UPDATE groups SET use_activity=$1 WHERE group_id=$2',
1214 array($booleanparam, $this->getID()));
1216 $this->data_array['use_activity'] = $booleanparam;
1226 * usesForum - whether or not this group has opted to use discussion forums.
1228 * @return bool uses_forum.
1230 function usesForum() {
1231 if (forge_get_config('use_forum')) {
1232 return $this->data_array['use_forum'];
1239 * setUseForum - Set the forum usage
1241 * @param bool $booleanparam enabled/disabled
1244 function setUseForum($booleanparam) {
1246 $booleanparam = $booleanparam ? 1 : 0;
1247 $res = db_query_params('UPDATE groups SET use_forum=$1 WHERE group_id=$2',
1248 array($booleanparam, $this->getID()));
1250 $this->data_array['use_forum'] = $booleanparam;
1260 * usesStats - whether or not this group has opted to use stats.
1262 * @return bool uses_stats.
1264 function usesStats() {
1265 return $this->data_array['use_stats'];
1269 * usesFRS - whether or not this group has opted to use file release system.
1271 * @return bool uses_frs.
1273 function usesFRS() {
1274 if (forge_get_config('use_frs')) {
1275 return $this->data_array['use_frs'];
1282 * setUseFRS - Set the FRS usage
1284 * @param bool $booleanparam enabled/disabled
1287 function setUseFRS($booleanparam) {
1289 $booleanparam = $booleanparam ? 1 : 0;
1290 $res = db_query_params('UPDATE groups SET use_frs=$1 WHERE group_id=$2',
1291 array($booleanparam, $this->getID()));
1293 $this->data_array['use_frs']=$booleanparam;
1303 * usesTracker - whether or not this group has opted to use tracker.
1305 * @return bool uses_tracker.
1307 function usesTracker() {
1308 if (forge_get_config('use_tracker')) {
1309 return $this->data_array['use_tracker'];
1316 * setUseTracker - Set the tracker usage
1318 * @param bool $booleanparam enabled/disabled
1321 function setUseTracker($booleanparam) {
1323 $booleanparam = $booleanparam ? 1 : 0;
1324 $res = db_query_params ('UPDATE groups SET use_tracker=$1 WHERE group_id=$2',
1325 array($booleanparam, $this->getID()));
1327 $this->data_array['use_tracker']=$booleanparam;
1337 * useCreateOnline - whether or not this group has opted to use create online documents option.
1339 * @return bool use_docman_create_online.
1341 function useCreateOnline() {
1342 if (forge_get_config('use_docman')) {
1343 return $this->data_array['use_docman_create_online'];
1350 * usesDocman - whether or not this group has opted to use docman.
1352 * @return bool use_docman.
1354 function usesDocman() {
1355 if (forge_get_config('use_docman')) {
1356 return $this->data_array['use_docman'];
1363 * setUseDocman - Set the docman usage
1365 * @param bool $booleanparam enabled/disabled
1368 function setUseDocman($booleanparam) {
1370 $booleanparam = $booleanparam ? 1 : 0;
1371 $res = db_query_params('UPDATE groups SET use_docman = $1 WHERE group_id = $2',
1372 array($booleanparam, $this->getID()));
1374 // check if / doc_group exists, if not create it
1375 $trashdir = db_query_params('select groupname from doc_groups where groupname = $1 and group_id = $2',
1376 array('.trash', $this->getID()));
1377 if ($trashdir && db_numrows($trashdir) == 0) {
1378 $resinsert = db_query_params('insert into doc_groups (groupname, group_id, stateid) values ($1, $2, $3)',
1379 array('.trash', $this->getID(), '2'));
1385 $this->data_array['use_docman'] = $booleanparam;
1395 * useDocmanSearch - whether or not this group has opted to use docman search engine.
1397 * @return bool use_docman_search.
1399 function useDocmanSearch() {
1400 if (forge_get_config('use_docman')) {
1401 return $this->data_array['use_docman_search'];
1408 * useWebdav - whether or not this group has opted to use webdav interface.
1410 * @return bool use_docman_search.
1412 function useWebdav() {
1413 if (forge_get_config('use_webdav')) {
1414 return $this->data_array['use_webdav'];
1421 * usesFTP - whether or not this group has opted to use FTP.
1423 * @return bool uses_ftp.
1425 function usesFTP() {
1426 if (forge_get_config('use_ftp')) {
1427 return $this->data_array['use_ftp'];
1434 * usesSurvey - whether or not this group has opted to use surveys.
1436 * @return bool uses_survey.
1438 function usesSurvey() {
1439 if (forge_get_config('use_survey')) {
1440 return $this->data_array['use_survey'];
1447 * usesPM - whether or not this group has opted to Project Manager.
1449 * @return bool uses_projman.
1452 if (forge_get_config('use_pm')) {
1453 return $this->data_array['use_pm'];
1460 * setUsePM - Set the PM usage
1462 * @param bool $booleanparam enabled/disabled
1465 function setUsePM($booleanparam) {
1467 $booleanparam = $booleanparam ? 1 : 0;
1468 $res = db_query_params('UPDATE groups SET use_pm=$1 WHERE group_id=$2',
1469 array($booleanparam, $this->getID()));
1471 $this->data_array['use_pm']=$booleanparam;
1481 * getPlugins - get a list of all available group plugins
1483 * @return array array containing plugin_id => plugin_name
1485 function getPlugins() {
1486 if (!isset($this->plugins_data)) {
1487 $this->plugins_data = array();
1488 $res = db_query_params('SELECT group_plugin.plugin_id, plugins.plugin_name
1489 FROM group_plugin, plugins
1490 WHERE group_plugin.group_id=$1
1491 AND group_plugin.plugin_id=plugins.plugin_id', array($this->getID()));
1492 $rows = db_numrows($res);
1494 for ($i=0; $i<$rows; $i++) {
1495 $plugin_id = db_result($res, $i, 'plugin_id');
1496 $this->plugins_data[$plugin_id] = db_result($res, $i, 'plugin_name');
1499 return $this->plugins_data;
1503 * usesPlugin - returns true if the group uses a particular plugin
1505 * @param string $pluginname name of the plugin
1506 * @return bool whether plugin is being used or not
1508 function usesPlugin($pluginname) {
1509 $plugins_data = $this->getPlugins();
1510 foreach ($plugins_data as $p_id => $p_name) {
1511 if ($p_name == $pluginname) {
1519 * added for Codendi compatibility
1520 * usesServices - returns true if the group uses a particular plugin or feature
1522 * @param string $feature name of the plugin
1523 * @return bool whether plugin is being used or not
1525 function usesService($feature) {
1526 $plugins_data = $this->getPlugins();
1527 $pm = plugin_manager_get_object();
1528 foreach ($plugins_data as $p_id => $p_name) {
1529 if ($p_name == $feature) {
1532 if (is_object($pm->getPluginByName($p_name)) && $pm->getPluginByName($p_name)->provide($feature)) {
1540 * setPluginUse - enables/disables plugins for the group
1542 * @param string $pluginname name of the plugin
1543 * @param bool $val the new state
1544 * @return string database result
1546 function setPluginUse($pluginname, $val=true) {
1547 if ($val == $this->usesPlugin($pluginname)) {
1548 // State is already good, returning
1551 $res = db_query_params('SELECT plugin_id FROM plugins WHERE plugin_name=$1',
1552 array($pluginname));
1553 $rows = db_numrows($res);
1555 // Error: no plugin by that name
1558 $plugin_id = db_result($res,0,'plugin_id');
1560 unset($this->plugins_data);
1562 $res = db_query_params('INSERT INTO group_plugin (group_id, plugin_id) VALUES ($1, $2)',
1563 array($this->getID(),
1566 $res = db_query_params('DELETE FROM group_plugin WHERE group_id=$1 AND plugin_id=$2',
1567 array($this->getID(),
1570 $this->normalizeAllRoles();
1571 $hook_params = array();
1572 $hook_params['group_id'] = $this->getID();
1573 $hook_params['val'] = $val;
1574 plugin_hook("group_plugin_use", $hook_params);
1579 * getDocEmailAddress - get email address(es) to send doc notifications to.
1581 * @return string email address.
1583 function getDocEmailAddress() {
1584 return $this->data_array['new_doc_address'];
1587 function setDocEmailAddress($email) {
1588 $invalid_mails = validate_emails($email);
1589 if (count($invalid_mails) > 0) {
1590 $this->setError(sprintf(ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
1594 $res = db_query_params('UPDATE groups SET new_doc_address = $1 WHERE group_id = $2',
1595 array($email, $this->getID()));
1598 $this->setError(_('Error')._(': ')._('Cannot Update Group new_doc_address')._(': ').db_error());
1602 $this->data_array['new_doc_address'] = $email;
1609 * docEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1611 * @return bool email_on_all_doc_updates.
1613 function docEmailAll() {
1614 return $this->data_array['send_all_docs'];
1617 function setDocEmailAll($status) {
1619 $res = db_query_params('UPDATE groups SET send_all_docs = $1 WHERE group_id = $2',
1620 array($status, $this->getID()));
1623 $this->setError(_('Error')._(': ')._('Cannot Update Group send_all_docs')._(': ').db_error());
1627 $this->data_array['send_all_docs'] = $status;
1634 * getFRSEmailAddress - get email address(es) to send FRS notifications to.
1636 * @return string email address.
1638 function getFRSEmailAddress() {
1639 return $this->data_array['new_frs_address'];
1642 function setFRSEmailAddress($email) {
1643 $invalid_mails = validate_emails($email);
1644 if (count($invalid_mails) > 0) {
1645 $this->setError(sprintf(ngettext('New FRS Address Appeared Invalid: %s', 'New FRS Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
1649 $res = db_query_params('UPDATE groups SET new_frs_address = $1 WHERE group_id = $2',
1650 array($email, $this->getID()));
1653 $this->setError(_('Error')._(': ')._('Cannot Update Group new_frs_address')._(': ').db_error());
1657 $this->data_array['new_frs_address'] = $email;
1664 * frsEmailAll - whether or not this group has opted to use receive notices on all frs updates.
1666 * @return bool email_on_all_frs_updates.
1668 function frsEmailAll() {
1669 return $this->data_array['send_all_frs'];
1672 function setFRSEmailAll($status) {
1674 $res = db_query_params('UPDATE groups SET send_all_frs = $1 WHERE group_id = $2',
1675 array($status, $this->getID()));
1678 $this->setError(_('Error')._(': ')._('Cannot Update Group send_frs_docs')._(': ').db_error());
1682 $this->data_array['send_frs_docs'] = $status;
1689 * getHomePage - The URL for this project's home page.
1691 * @return string homepage URL.
1693 function getHomePage() {
1694 if (!preg_match("/^[a-zA-Z][a-zA-Z0-9+.-]*:/",
1695 $this->data_array['homepage'])) {
1696 $this->data_array['homepage'] = 'http://' .
1697 $this->data_array['homepage'];
1699 return $this->data_array['homepage'];
1703 * setHomepage - the hostname of the website url where this project is located.
1705 * @param string $homepage The name of the new HOMEPAGE
1708 function setHomepage($homepage) {
1710 if ($homepage == $this->data_array['homepage']) {
1715 $res = db_query_params('UPDATE groups SET homepage=$1 WHERE group_id=$2', array($homepage, $this->getID()));
1717 $this->addHistory('homepage', $this->data_array['homepage']);
1718 $this->data_array['homepage'] = $homepage;
1723 $this->setError(_('Could not insert homepage to database'));
1727 $this->setError(_('Homepage cannot be empty'));
1733 * getTags - Tags of this project.
1735 * @return string List of tags. Comma separated
1737 function getTags() {
1738 $sql = 'SELECT name FROM project_tags WHERE group_id = $1';
1739 $res = db_query_params($sql, array($this->getID()));
1740 return join(', ', util_result_column_to_array($res));
1744 * setTags - Set tags of this project.
1746 * @param string $tags
1747 * @return string database result.
1749 function setTags($tags) {
1751 $sql = 'DELETE FROM project_tags WHERE group_id=$1';
1752 $res = db_query_params($sql, array($this->getID()));
1754 $this->setError(_('Deleting old tags')._(': ').db_error());
1758 $inserted = array();
1759 $tags_array = preg_split('/[;,]/', $tags);
1760 foreach ($tags_array as $tag) {
1761 $tag = preg_replace('/[\t\r\n]/', ' ', $tag);
1762 // Allowed caracteres: [A-Z][a-z][0-9] -_&'#+.
1763 if (preg_match('/[^[:alnum:]| |\-|_|\&|\'|#|\+|\.]/', $tag)) {
1764 $this->setError(_('Bad tag name, you only can use the following characters: [A-Z][a-z][0-9]-_&\'#+. and space'));
1769 if ($tag == '' || array_search($tag, $inserted) !== false) {
1772 $sql = 'INSERT INTO project_tags (group_id,name) VALUES ($1, $2)';
1773 $res = db_query_params($sql, array($this->getID(), $tag));
1775 $this->setError(_('Setting tags')._(': ').db_error());
1786 * getPermission - Return a Permission for this Group
1788 * @return object The Permission.
1790 function &getPermission() {
1791 return permission_get_object($this);
1794 function delete($sure, $really_sure, $really_really_sure) {
1795 if (!$sure || !$really_sure || !$really_really_sure) {
1796 $this->setMissingParamsError(_('Please tick all checkboxes.'));
1799 if ($this->getID() == GROUP_IS_NEWS ||
1800 $this->getID() == GROUP_IS_MASTER ||
1801 $this->getID() == GROUP_IS_STATS ||
1802 $this->getID() == GROUP_IS_PEER_RATINGS) {
1803 $this->setError(_('Cannot Delete System Group'));
1806 $perm = $this->getPermission();
1807 if (!$perm || !is_object($perm)) {
1808 $this->setPermissionDeniedError();
1810 } elseif ($perm->isError() || !$perm->isSuperUser()) {
1811 $this->setPermissionDeniedError();
1817 // Remove all the members
1819 $members = $this->getMembers(false);
1820 foreach ($members as $i) {
1821 if(!$this->removeUser($i->getID())) {
1822 $this->setError(_('Could not properly remove member')._(': ').$i->getID());
1827 // unlink roles from this project
1828 foreach ($this->getRoles() as $r) {
1829 if ($r->getHomeProject() == NULL
1830 || $r->getHomeProject()->getID() != $this->getID()) {
1831 $r->unlinkProject($this);
1838 $atf = new ArtifactTypeFactory($this, true);
1839 $at_arr = $atf->getArtifactTypes();
1840 foreach ($at_arr as $i) {
1841 if (!is_object($i)) {
1844 if (!$i->delete(1,1)) {
1845 $this->setError(_('Could not properly delete the tracker')._(': ').$i->getErrorMessage());
1852 $rmf = new RoadmapFactory($this);
1853 $rm_arr = $rmf->getRoadmaps();
1854 foreach ($rm_arr as $i) {
1855 if (!is_object($i)) {
1858 if (!$i->delete()) {
1859 $this->setError(_('Could not properly delete the roadmap')._(': ').$i->getErrorMessage());
1867 $ff = new ForumFactory($this, true);
1868 $f_arr = $ff->getForums();
1869 foreach ($f_arr as $i) {
1870 if (!is_object($i)) {
1873 if(!$i->delete(1,1)) {
1874 $this->setError(_('Could not properly delete the forum')._(': ').$i->getErrorMessage());
1880 // Delete Subprojects
1882 $pgf = new ProjectGroupFactory($this, true);
1883 $pg_arr = $pgf->getProjectGroups();
1884 foreach ($pg_arr as $i) {
1885 if (!is_object($i)) {
1888 if (!$i->delete(1,1)) {
1889 $this->setError(_('Could not properly delete the ProjectGroup')._(': ').$i->getErrorMessage());
1895 // Delete FRS Packages
1897 $res = db_query_params('SELECT * FROM frs_package WHERE group_id=$1',
1898 array($this->getID()));
1900 $this->setError(_('Error FRS Packages')._(': ').db_error());
1905 while ($arr = db_fetch_array($res)) {
1906 $frsp=new FRSPackage($this, $arr['package_id'], $arr);
1907 if (!$frsp->delete(1, 1)) {
1908 $this->setError(_('Could not properly delete the FRSPackage')._(': ').$frsp->getErrorMessage());
1915 $news_group = group_get_object(GROUP_IS_NEWS);
1916 $res = db_query_params('SELECT forum_id FROM news_bytes WHERE group_id=$1',
1917 array($this->getID()));
1919 $this->setError(_('Error Deleting News')._(': ').db_error());
1924 for ($i=0; $i<db_numrows($res); $i++) {
1925 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1926 if (!$Forum->delete(1,1)) {
1927 $this->setError(_('Could not delete News Forum')._(': ').$Forum->getID());
1932 // Delete news forums in group itself
1933 for ($i = 0; $i < db_numrows($res); $i++) {
1934 $Forum = new Forum($this, db_result($res, $i, 'forum_id'));
1935 if (!$Forum->delete(1, 1)) {
1936 $this->setError(_('Could not delete News Forum')._(': ').$Forum->getID());
1941 $res = db_query_params('DELETE FROM news_bytes WHERE group_id=$1',
1942 array($this->getID()));
1944 $this->setError(_('Error Deleting News')._(': ').db_error());
1952 $res = db_query_params('DELETE FROM doc_data WHERE group_id=$1',
1953 array($this->getID()));
1955 $this->setError(_('Error Deleting Documents')._(': ').db_error());
1960 $res = db_query_params('DELETE FROM doc_groups WHERE group_id=$1',
1961 array($this->getID()));
1963 $this->setError(_('Error Deleting Document Groups')._(': ').db_error());
1971 $res=db_query_params('DELETE FROM project_tags WHERE group_id=$1', array($this->getID()));
1973 $this->setError(_('Error Deleting Tags')._(': ').db_error());
1979 // Delete group history
1981 $res = db_query_params('DELETE FROM group_history WHERE group_id=$1',
1982 array($this->getID()));
1984 $this->setError(_('Error Deleting Project History')._(': ').db_error());
1990 // Delete group plugins
1992 $res = db_query_params('DELETE FROM group_plugin WHERE group_id=$1',
1993 array($this->getID()));
1995 $this->setError(_('Error Deleting Project Plugins')._(': ').db_error());
2001 // Delete group cvs stats
2003 $res = db_query_params ('DELETE FROM stats_cvs_group WHERE group_id=$1',
2004 array($this->getID()));
2006 $this->setError(_('Error Deleting SCM Statistics')._(': ').db_error());
2014 $sf = new SurveyFactory($this, true);
2015 $s_arr =& $sf->getSurveys();
2016 foreach ($s_arr as $i) {
2017 if (!is_object($i)) {
2020 if (!$i->delete()) {
2021 $this->setError(_('Could not properly delete the survey'));
2026 // Delete SurveyQuestions
2028 $sqf = new SurveyQuestionFactory($this);
2029 $sq_arr = $sqf->getSurveyQuestions();
2030 if (is_array($sq_arr)) {
2031 foreach ($sq_arr as $i) {
2032 if (!is_object($i)) {
2035 if (!$i->delete()) {
2036 $this->setError(_('Could not properly delete the survey questions'));
2044 // Delete Mailing List Factory
2046 $mlf = new MailingListFactory($this, true);
2047 $ml_arr = $mlf->getMailingLists();
2048 foreach ($ml_arr as $i) {
2049 if (!is_object($i)) {
2052 if (!$i->delete(1,1)) {
2053 $this->setError(_('Could not properly delete the mailing list'));
2061 $res = db_query_params('DELETE FROM trove_group_link WHERE group_id=$1',
2062 array($this->getID()));
2064 $this->setError(_('Error Deleting Trove')._(': ').db_error());
2069 $res = db_query_params('DELETE FROM trove_agg WHERE group_id=$1',
2070 array($this->getID()));
2072 $this->setError(_('Error Deleting Trove')._(': ').db_error());
2080 $res = db_query_params('DELETE FROM project_sums_agg WHERE group_id=$1',
2081 array($this->getID()));
2083 $this->setError(_('Error Deleting Counters')._(': ').db_error());
2088 $res = db_query_params('INSERT INTO deleted_groups (unix_group_name, delete_date, isdeleted) VALUES ($1, $2, $3)',
2089 array($this->getUnixName(),
2093 $this->setError(_('Error Deleting Project')._(': ').db_error());
2098 // Remove users & delete roles from this project
2099 $members = $this->getMembers();
2100 foreach ($members as $userObject) {
2101 $this->removeUser($userObject->getID());
2103 $localRolesId = $this->getRolesId(false);
2104 foreach ($localRolesId as $localRoleId) {
2105 $roleObject = new Role($this, $localRoleId);
2106 $roleObject->delete();
2108 // Delete entry in groups.
2109 $res = db_query_params('DELETE FROM groups WHERE group_id=$1',
2110 array($this->getID()));
2112 $this->setError(_('Error Deleting Project')._(': ').db_error());
2119 $hook_params = array();
2120 $hook_params['group'] = $this;
2121 $hook_params['group_id'] = $this->getID();
2122 plugin_hook("group_delete", $hook_params);
2124 if (forge_get_config('upload_dir') != '' && $this->getUnixName()) {
2125 exec('/bin/rm -rf '.forge_get_config('upload_dir').'/'.$this->getUnixName().'/');
2127 if (forge_get_config('ftp_upload_dir') != '' && $this->getUnixName()) {
2128 exec('/bin/rm -rf '.forge_get_config('ftp_upload_dir').'/'.$this->getUnixName().'/');
2133 db_query_params('DELETE FROM rep_group_act_monthly WHERE group_id=$1',
2134 array($this->getID()));
2135 //echo 'rep_group_act_monthly'.db_error();
2136 db_query_params('DELETE FROM rep_group_act_weekly WHERE group_id=$1',
2137 array($this->getID()));
2138 //echo 'rep_group_act_weekly'.db_error();
2139 db_query_params('DELETE FROM rep_group_act_daily WHERE group_id=$1',
2140 array($this->getID()));
2141 //echo 'rep_group_act_daily'.db_error();
2142 unset($this->data_array);
2147 Basic functions to add/remove users to/from a group
2148 and update their permissions
2152 * addUser - controls adding a user to a group.
2154 * @param string $user_identifier Unix name of the user to add OR integer user_id.
2155 * @param int $role_id The role_id this user should have.
2156 * @return bool success.
2159 function addUser($user_identifier, $role_id) {
2162 Admins can add users to groups
2165 if (!forge_check_perm ('project_admin', $this->getID())) {
2166 $this->setPermissionDeniedError();
2172 get user id for this user's unix_name
2174 if (is_int ($user_identifier)) { // user_id or user_name
2175 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array($user_identifier));
2177 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array($user_identifier));
2179 if (db_numrows($res_newuser) > 0) {
2181 // make sure user is active
2183 if (db_result($res_newuser,0,'status') != 'A') {
2184 $this->setError(_('User is not active. Only active users can be added.'));
2190 // user was found - set new user_id var
2192 $user_id = db_result($res_newuser,0,'user_id');
2194 $role = new Role($this, $role_id);
2195 if (!$role || !is_object($role)) {
2196 $this->setError(_('Error Getting Role Object'));
2199 } elseif ($role->isError()) {
2200 $this->setError('addUser::roleget::'.$role->getErrorMessage());
2205 $role->addUser(user_get_object($user_id));
2206 if (!$SYS->sysCheckCreateGroup($this->getID())){
2207 $this->setError($SYS->getErrorMessage());
2211 if (!$SYS->sysCheckCreateUser($user_id)) {
2212 $this->setError($SYS->getErrorMessage());
2216 if (!$SYS->sysGroupCheckUser($this->getID(),$user_id)) {
2217 $this->setError($SYS->getErrorMessage());
2223 // user doesn't exist
2225 $this->setError(_('That user does not exist.'));
2230 $hook_params['group'] = $this;
2231 $hook_params['group_id'] = $this->getID();
2232 $hook_params['user'] = user_get_object($user_id);
2233 $hook_params['user_id'] = $user_id;
2234 plugin_hook ("group_adduser", $hook_params);
2239 $this->addHistory(_('Added User'), $user_identifier);
2245 $add_u = user_get_object($user_id);
2247 if (is_array($this->membersArr)) {
2248 foreach ($this->membersArr as $u) {
2249 if ($u->getID() == $add_u->getID()) {
2255 $this->membersArr[] = $add_u;
2263 * removeUser - controls removing a user from a group.
2265 * Users can remove themselves.
2267 * @param int $user_id The ID of the user to remove.
2268 * @return bool success.
2270 function removeUser($user_id) {
2273 if ($user_id != user_getid()
2274 && !forge_check_perm('project_admin', $this->getID())) {
2275 $this->setPermissionDeniedError();
2281 $user = user_get_object($user_id);
2282 $roles = RBACEngine::getInstance()->getAvailableRolesForUser($user);
2283 $found_roles = array();
2284 foreach ($roles as $role) {
2285 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
2286 $found_roles[] = $role;
2289 if (count($found_roles) == 0) {
2290 $this->setError(_('Error')._(': ')._('User not removed')._(': ').$user_id);
2294 foreach ($found_roles as $found_role) {
2295 $found_role->removeUser($user);
2296 if (!$SYS->sysGroupCheckUser($this->getID(), $user_id)) {
2297 $this->setError($SYS->getErrorMessage());
2304 // reassign open artifacts to id=100
2306 $res = db_query_params('UPDATE artifact SET assigned_to=100
2307 WHERE group_artifact_id
2308 IN (SELECT group_artifact_id
2309 FROM artifact_group_list
2310 WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
2311 array($this->getID(),
2314 $this->setError(_('Error')._(': ')._('artifact')._(': ').db_error());
2320 // reassign open tasks to id=100
2321 // first have to purge any assignments that would cause
2322 // conflict with existing assignment to 100
2324 $res = db_query_params('DELETE FROM project_assigned_to
2325 WHERE project_task_id IN (SELECT pt.project_task_id
2326 FROM project_task pt, project_group_list pgl, project_assigned_to pat
2327 WHERE pt.group_project_id = pgl.group_project_id
2328 AND pat.project_task_id=pt.project_task_id
2329 AND pt.status_id=1 AND pgl.group_id=$1
2330 AND pat.assigned_to_id=$2)
2331 AND assigned_to_id=100',
2332 array($this->getID(),
2335 $this->setError(_('Error')._(': ').sprintf(_('project_assigned_to %d: %s'), 1, db_error()));
2339 $res = db_query_params('UPDATE project_assigned_to SET assigned_to_id=100
2340 WHERE project_task_id IN (SELECT pt.project_task_id
2341 FROM project_task pt, project_group_list pgl
2342 WHERE pt.group_project_id = pgl.group_project_id
2343 AND pt.status_id=1 AND pgl.group_id=$1)
2344 AND assigned_to_id=$2',
2345 array($this->getID(),
2348 $this->setError(_('Error')._(': ').sprintf(_('project_assigned_to %d: %s'), 2, db_error()));
2354 // Remove user from system
2356 if (!$SYS->sysGroupRemoveUser($this->getID(), $user_id)) {
2357 $this->setError($SYS->getErrorMessage());
2362 $hook_params['group'] = $this;
2363 $hook_params['group_id'] = $this->getID();
2364 $hook_params['user'] = user_get_object($user_id);
2365 $hook_params['user_id'] = $user_id;
2366 plugin_hook("group_removeuser", $hook_params);
2369 $this->addHistory(_('Removed User'), $user_id);
2376 $del_u = user_get_object($user_id);
2377 foreach ($this->membersArr as $k => $u) {
2378 if ($u->getID() == $del_u->getID()) {
2379 unset($this->membersArr[$k]);
2388 * updateUser - controls updating a user's role in this group.
2390 * @param int $user_id The ID of the user.
2391 * @param int $role_id The role_id to set this user to.
2392 * @return bool success.
2394 function updateUser($user_id, $role_id) {
2396 if (!forge_check_perm ('project_admin', $this->getID())) {
2397 $this->setPermissionDeniedError();
2401 $newrole = RBACEngine::getInstance()->getRoleById ($role_id);
2402 if (!$newrole || !is_object($newrole)) {
2403 $this->setError(_('Could Not Get Role'));
2405 } elseif ($newrole->isError()) {
2406 $this->setError(_('Role')._(': ').$role->getErrorMessage());
2408 } elseif ($newrole->getHomeProject() == NULL
2409 || $newrole->getHomeProject()->getID() != $this->getID()) {
2410 $this->setError(_('Wrong destination role'));
2413 $user = user_get_object ($user_id);
2414 $roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user);
2416 foreach ($roles as $role) {
2417 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
2418 $found_role = $role;
2422 if ($found_role == NULL) {
2423 $this->setError(_('Error')._(': ')._('User not removed')._(': ').$user_id);
2427 $found_role->removeUser ($user);
2428 $newrole->addUser ($user);
2430 $this->addHistory(_('Updated User'), $user_id);
2435 * addHistory - Makes an audit trail entry for this project.
2437 * @param string $field_name The name of the field.
2438 * @param string $old_value The Old Value for this $field_name.
2439 * @return resource database result handle.
2442 function addHistory($field_name, $old_value) {
2443 if ($old_value == NULL) {
2447 return db_query_params('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
2448 VALUES ($1,$2,$3,$4,$5)',
2449 array($this->getID(),
2457 * activateUsers - Make sure that group members have unix accounts.
2459 * Setup unix accounts for group members. Can be called even
2460 * if members are already active.
2464 function activateUsers() {
2466 Activate member(s) of the project
2471 $members = $this->getUsers(true);
2473 foreach ($members as $member) {
2474 $user_id = $member->getID();
2476 if (!$SYS->sysCheckCreateGroup($this->getID())){
2477 $this->setError($SYS->getErrorMessage());
2481 if (!$SYS->sysCheckCreateUser($user_id)) {
2482 $this->setError($SYS->getErrorMessage());
2486 if (!$SYS->sysGroupCheckUser($this->getID(),$user_id)) {
2487 $this->setError($SYS->getErrorMessage());
2497 * getMembers - returns array of User objects for this project
2499 * @param bool $onlyactive Only users with state active, or all users of group
2500 * @return array of User objects for this group.
2502 function getMembers($onlyactive = true) {
2503 return $this->getUsers(true, $onlyactive);
2507 * replaceTemplateStrings - fill-in some blanks with project name
2509 * @param string $string Template string
2510 * @return string String after replacements
2512 function replaceTemplateStrings($string) {
2513 $string = str_replace('UNIXNAME', $this->getUnixName(), $string);
2514 $string = str_replace('PUBLICNAME', $this->getPublicName(), $string);
2515 $string = str_replace('DESCRIPTION', $this->getDescription(), $string);
2520 * approve - Approve pending project.
2522 * @param object $user The User object who is doing the updating.
2526 function approve(&$user) {
2527 global $gfcommon,$gfwww;
2528 require_once $gfcommon.'widget/WidgetLayoutManager.class.php';
2530 if ($this->getStatus()=='A') {
2531 $this->setError(_('Group already active'));
2537 // Step 1: Activate group and create LDAP entries
2538 if (!$this->setStatus($user, 'A')) {
2545 // Switch to system language for item creation
2546 setup_gettext_from_sys_lang();
2548 // Create default roles
2549 $idadmin_group = NULL;
2550 foreach (get_group_join_requests ($this) as $gjr) {
2551 $idadmin_group = $gjr->getUserID();
2554 if ($idadmin_group == NULL) {
2555 $idadmin_group = $user->getID();
2558 $template = $this->getTemplateProject();
2559 $id_mappings = array();
2560 $seen_admin_role = false;
2562 // Copy roles from template project
2563 foreach($template->getRoles() as $oldrole) {
2564 if ($oldrole->getHomeProject() != NULL) {
2565 $role = new Role($this);
2567 // Need to use a different role name so that the permissions aren't set from the hardcoded defaults
2568 $role->create('TEMPORARY ROLE NAME', $data, true);
2569 $role->setName($oldrole->getName());
2570 if ($oldrole->getSetting ('project_admin', $template->getID())) {
2571 $seen_admin_role = true;
2575 $role->linkProject($this);
2577 $id_mappings['role'][$oldrole->getID()] = $role->getID();
2578 // Reuse the project_admin permission
2579 $role->setSetting ('project_admin', $this->getID(), $oldrole->getSetting ('project_admin', $template->getID()));
2583 if (!$seen_admin_role) {
2584 $role = new Role($this);
2585 $adminperms = array('project_admin' => array ($this->getID() => 1));
2586 $role_id = $role->create ('Admin', $adminperms, true);
2589 $roles = $this->getRoles();
2590 foreach ($roles as $r) {
2591 if ($r->getHomeProject() == NULL) {
2594 if ($r->getSetting ('project_admin', $this->getID())) {
2595 $r->addUser(user_get_object ($idadmin_group));
2599 // Temporarily switch to the submitter's identity
2600 $saved_session = session_get_user();
2601 session_set_internal($idadmin_group);
2604 if (forge_get_config('use_tracker')) {
2605 $this->setUseTracker ($template->usesTracker());
2606 if ($template->usesTracker()) {
2607 $oldatf = new ArtifactTypeFactory($template);
2608 foreach ($oldatf->getArtifactTypes() as $o) {
2609 $t = new ArtifactType ($this);
2610 $t->create ($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->emailAll(),$o->getEmailAddress(),$o->getDuePeriod()/86400,0,$o->getSubmitInstructions(),$o->getBrowseInstructions());
2611 $id_mappings['tracker'][$o->getID()] = $t->getID();
2616 if (forge_get_config('use_pm')) {
2617 $this->setUsePM ($template->usesPM());
2618 if ($template->usesPM()) {
2619 $oldpgf = new ProjectGroupFactory($template);
2620 foreach ($oldpgf->getProjectGroups() as $o) {
2621 $pg = new ProjectGroup($this);
2622 $pg->create($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->getSendAllPostsTo());
2623 $id_mappings['pm'][$o->getID()] = $pg->getID();
2628 if (forge_get_config('use_forum')) {
2629 $this->setUseForum($template->usesForum());
2630 if ($template->usesForum()) {
2631 $oldff = new ForumFactory($template);
2632 foreach ($oldff->getForums() as $o) {
2633 $f = new Forum($this);
2634 $f->create($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->getSendAllPostsTo(),1);
2635 $id_mappings['forum'][$o->getID()] = $f->getID();
2640 if (forge_get_config('use_docman')) {
2641 $this->setUseDocman($template->usesDocman());
2642 if ($template->usesDocman()) {
2643 $olddgf = new DocumentGroupFactory($template);
2644 // First pass: create all docgroups
2645 $id_mappings['docman_docgroup'][0] = 0;
2646 foreach ($olddgf->getDocumentGroups(array(1, 5)) as $o) {
2647 $ndg = new DocumentGroup($this);
2648 // .trash is a reserved directory
2649 if ($o->getName() != '.trash') {
2650 $ndg->create($this->replaceTemplateStrings($o->getName()), 0, 1, null, true);
2651 $id_mappings['docman_docgroup'][$o->getID()] = $ndg->getID();
2654 // Second pass: restore hierarchy links & stateid
2655 foreach ($olddgf->getDocumentGroups(array(1, 5)) as $o) {
2656 $ndgf = new DocumentGroup($this);
2657 if ($o->getName() != '.trash') {
2658 $ndgf->fetchData($id_mappings['docman_docgroup'][$o->getID()]);
2659 $ndgf->update($ndgf->getName(), $id_mappings['docman_docgroup'][$o->getParentID()], 0, $o->getState());
2665 if (forge_get_config('use_frs')) {
2666 $this->setUseFRS ($template->usesFRS());
2667 if ($template->usesFRS()) {
2668 foreach (get_frs_packages($template) as $o) {
2669 $newp = new FRSPackage($this);
2670 $nname = $this->replaceTemplateStrings($o->getName());
2671 $newp->create($nname, $o->isPublic());
2672 $id_mappings['frs'][$o->getID()] = $newp->getID();
2673 foreach(get_frs_releases($o) as $or) {
2674 $newr = new FRSRelease($newp);
2675 $newr->create($this->replaceTemplateStrings($or->getName()), $this->replaceTemplateStrings($or->getNotes()), $this->replaceTemplateStrings($or->getChanges()), $or->getPreformatted());
2676 $id_mappings['frs_release'][$or->getID()] = $newr->getID();
2682 if (forge_get_config('use_mail')) {
2683 $this->setUseMail($template->usesMail());
2684 if ($template->usesMail()) {
2685 $oldmlf = new MailingListFactory($template);
2686 foreach ($oldmlf->getMailingLists() as $o) {
2687 $ml = new MailingList($this);
2688 $nname = preg_replace ('/^'.$template->getUnixName().'-/','',$o->getName());
2690 $ndescription = $this->replaceTemplateStrings($o->getDescription());
2691 $ml->create($nname, $ndescription, $o->isPublic());
2697 /* use SCM plugin from template group */
2698 $this->setUseSCM($template->usesSCM());
2700 foreach ($template->getPlugins() as
2701 $plugin_id => $plugin_name) {
2702 $this->setPluginUse($plugin_name);
2705 /* use SCM choice from registration page */
2706 foreach ($template->getPlugins() as $plugin_id => $plugin_name) {
2707 if (substr($plugin_name, 3) == 'scm' &&
2708 $plugin_name != 'scmhook') {
2709 /* skip copying scm plugins */
2712 /* enable other plugins though */
2713 $this->setPluginUse($plugin_name);
2717 foreach ($template->getRoles() as $oldrole) {
2718 $newrole = RBACEngine::getInstance()->getRoleById($id_mappings['role'][$oldrole->getID()]);
2719 if ($oldrole->getHomeProject() != NULL
2720 && $oldrole->getHomeProject()->getID() == $template->getID()) {
2721 $newrole->setPublic ($oldrole->isPublic());
2723 $oldsettings = $oldrole->getSettingsForProject ($template);
2725 $sections = array('project_read', 'project_admin', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm', 'frs_admin', 'new_frs');
2726 foreach ($sections as $section) {
2727 $newrole->setSetting ($section, $this->getID(), $oldsettings[$section][$template->getID()]);
2730 $sections = array('tracker', 'pm', 'forum', 'frs');
2731 foreach ($sections as $section) {
2732 if (isset ($oldsettings[$section])) {
2733 foreach ($oldsettings[$section] as $k => $v) {
2734 // Only copy perms for tools that have been copied
2735 if (isset ($id_mappings[$section][$k])) {
2736 $newrole->setSetting ($section,
2737 $id_mappings[$section][$k],
2745 $lm = new WidgetLayoutManager();
2746 $lm->createDefaultLayoutForProject($this->getID(), $template->getID());
2748 // second computation to clone fields and workflow
2749 if (forge_get_config('use_tracker')) {
2750 if ($template->usesTracker()) {
2751 $oldatf = new ArtifactTypeFactory($template);
2752 foreach ($oldatf->getArtifactTypes() as $o) {
2753 $t = artifactType_get_object($id_mappings['tracker'][$o->getID()]);
2754 $id_mappings['tracker'][$o->getID()] = $t->getID();
2755 $newEFIds = $t->cloneFieldsFrom($o->getID(), $id_mappings);
2756 if (forge_get_config('use_tracker_widget_display')) {
2757 $lm->createDefaultLayoutForTracker($t->getID(), $o->getID(), $newEFIds);
2764 $params['template'] = $template;
2765 $params['project'] = $this;
2766 $params['id_mappings'] = $id_mappings;
2767 plugin_hook_by_reference ('clone_project_from_template', $params);
2769 // Disable everything - except use_scm (manually set in the registration page)
2770 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,
2771 use_docman = 0, use_ftp = 0, use_tracker = 0, use_frs = 0, use_stats = 0 WHERE group_id = $1',
2772 array($this->getID()));
2775 $this->normalizeAllRoles();
2776 // empty members cache because the group creator is not yet in cache.
2777 unset($this->membersArr);
2778 $this->activateUsers();
2780 // Delete fake join request
2781 foreach (get_group_join_requests ($this) as $gjr) {
2785 // Switch back to user preference
2786 session_set_internal($saved_session->getID());
2787 setup_gettext_from_context();
2789 $this->sendApprovalEmail();
2790 $this->addHistory(_('Approved'), 'x');
2793 // Plugin can make approve operation there
2796 $params['group'] = $this;
2797 $params['group_id'] = $this->getID();
2798 plugin_hook('group_approved', $params);
2804 * sendApprovalEmail - Send new project email.
2806 * @return bool success.
2809 function sendApprovalEmail() {
2810 $admins = RBACEngine::getInstance()->getUsersByAllowedAction ('project_admin', $this->getID());
2812 if (count($admins) < 1) {
2813 $this->setError(_('Group does not have any administrators.'));
2817 // send one email per admin
2818 foreach ($admins as $admin) {
2819 setup_gettext_for_user ($admin);
2821 $message = sprintf(_('Your project registration for %s has been approved.'), forge_get_config ('forge_name')) . "\n\n"
2823 . _('Project Full Name')._(': '). htmlspecialchars_decode($this->getPublicName()) . "\n"
2824 . _('Project Unix Name')._(': '). $this->getUnixName() . "\n\n"
2826 . _('Your DNS will take up to a day to become active on our site. '
2827 .'Your web site is accessible through your shell account. Please read '
2828 .'site documentation (see link below) about intended usage, available '
2829 .'services, and directory layout of the account.') . "\n\n"
2831 . sprintf(_('If you visit your own project page in %s while logged in, '
2832 . 'you will find additional menu functions to your left labeled “Project Admin”.'),
2833 forge_get_config ('forge_name')) . "\n\n"
2835 . sprintf(_('We highly suggest that you now visit %1$s and create a public '
2836 . 'description for your project. This can be done by visiting your project '
2837 . 'page while logged in, and selecting “Project Admin” from the menus '
2838 . 'on the left (or by visiting %2$s after login).'),
2839 forge_get_config ('forge_name'), util_make_url('/project/admin/?group_id='.$this->getID())) . "\n\n"
2841 . sprintf(_('Your project will also not appear in the Trove Software Map (primary '
2842 . 'list of projects hosted on %s which offers great flexibility in '
2843 . 'browsing and search) until you categorize it in the project administration '
2844 . 'screens. So that people can find your project, you should do this now. '
2845 . 'Visit your project while logged in, and select “Project Admin” from the '
2846 . 'menus on the left.'), forge_get_config ('forge_name')) . "\n\n"
2848 . sprintf(_('Enjoy the system, and please tell others about %s. Let us know '
2849 . 'if there is anything we can do to help you.'), forge_get_config ('forge_name')) . "\n\n"
2851 . sprintf(_('-- the %s staff'), forge_get_config ('forge_name')) . "\n";
2853 util_send_message($admin->getEmail(), sprintf(_('%s Project Approved'), forge_get_config ('forge_name')), $message);
2855 setup_gettext_from_context();
2862 * sendRejectionEmail - Send project rejection email.
2864 * This function sends out a rejection message to a user who
2865 * registered a project.
2867 * @param int $response_id The id of the response to use.
2868 * @param string $message The rejection message.
2869 * @return bool completion status.
2872 function sendRejectionEmail($response_id, $message = 'zxcv') {
2873 $submitters = array();
2874 foreach (get_group_join_requests ($this) as $gjr) {
2875 $submitters[] = user_get_object($gjr->getUserID());
2878 if (count ($submitters) < 1) {
2879 $this->setError(_('Group does not have any administrators.'));
2883 foreach ($submitters as $admin) {
2884 setup_gettext_for_user($admin);
2886 $response = sprintf(_('Your project registration for %s has been denied.'), forge_get_config('forge_name')) . "\n\n"
2887 . _('Project Full Name')._(': '). $this->getPublicName() . "\n"
2888 . _('Project Unix Name')._(': '). $this->getUnixName() . "\n\n"
2889 . _('Reasons for negative decision')._(': ') . "\n\n";
2891 // Check to see if they want to send a custom rejection response
2892 if ($response_id == 0) {
2893 $response .= $message;
2895 $response .= db_result(
2896 db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array($response_id)),
2901 util_send_message($admin->getEmail(), sprintf(_('%s Project Denied'), forge_get_config('forge_name')), $response);
2902 setup_gettext_from_context();
2909 * sendNewProjectNotificationEmail - Send new project notification email.
2911 * This function sends out a notification email to the
2912 * SourceForge admin user when a new project is
2915 * @return bool success.
2918 function sendNewProjectNotificationEmail() {
2919 // Get the user who wants to register the project
2920 $submitters = array();
2921 foreach (get_group_join_requests ($this) as $gjr) {
2922 $submitters[] = user_get_object($gjr->getUserID());
2924 if (count ($submitters) < 1) {
2925 $this->setError(_('Could not find user who has submitted the project.'));
2929 $admins = RBACEngine::getInstance()->getUsersByAllowedAction('approve_projects', -1);
2931 if (count($admins) < 1) {
2932 $this->setError(_('There is no administrator to send the mail to.'));
2936 foreach ($admins as $admin) {
2937 $admin_email = $admin->getEmail();
2938 setup_gettext_for_user ($admin);
2940 $message = sprintf(_('New %s Project Submitted'), forge_get_config('forge_name')) . "\n\n"
2941 . _('Project Full Name')._(': ').htmlspecialchars_decode($this->getPublicName()) . "\n"
2942 . _('Submitted Description')._(': ').htmlspecialchars_decode($this->getRegistrationPurpose()) . "\n";
2944 foreach ($submitters as $submitter) {
2945 $message .= _('Submitter')._(': ').$submitter->getRealName().' ('.$submitter->getUnixName().')' . "\n\n";
2949 . _('Please visit the following URL to approve or reject this project')._(': '). "\n"
2950 . util_make_url('/admin/approve-pending.php');
2951 util_send_message($admin_email, sprintf(_('New %s Project Submitted'), forge_get_config('forge_name')), $message);
2952 setup_gettext_from_context();
2955 $email = $submitter->getEmail();
2956 setup_gettext_for_user ($submitter);
2958 $message = sprintf(_('New %s Project Submitted'), forge_get_config ('forge_name')) . "\n\n"
2959 . _('Project Full Name')._(': ') . $this->getPublicName() . "\n"
2960 . _('Submitted Description')._(': ') . util_unconvert_htmlspecialchars($this->getRegistrationPurpose()) . "\n\n"
2961 . sprintf(_('The %s admin team will now examine your project submission. You will be notified of their decision.'),
2962 forge_get_config ('web_host'));
2964 util_send_message($email, sprintf(_('New %s Project Submitted'), forge_get_config ('forge_name')), $message);
2965 setup_gettext_from_context();
2971 * validateGroupName - Validate the group name
2973 * @param string $group_name Project name.
2975 * @return bool an error false and set an error is the group name is invalid otherwise return true
2977 function validateGroupName($group_name) {
2978 if (strlen($group_name)<3) {
2979 $this->setError(_('Project name is too short'));
2981 } elseif (strlen(htmlspecialchars($group_name))>40) {
2982 $this->setError(_('Project name is too long'));
2984 } elseif (group_get_object_by_publicname($group_name)) {
2985 $this->setError(_('Project name already taken'));
2992 * getRolesId - Get Ids of the roles of the group.
2994 * @param bool all role ids or local role ids only. Default is all role ids
2995 * @return array Role ids of this group.
2997 function getRolesId($global = true) {
2998 $role_ids = array();
3000 $res = db_query_params('SELECT role_id FROM pfo_role WHERE home_group_id=$1',
3001 array($this->getID()));
3002 while ($arr = db_fetch_array($res)) {
3003 $role_ids[] = $arr['role_id'];
3006 $res = db_query_params('SELECT role_id FROM role_project_refs WHERE group_id=$1',
3007 array($this->getID()));
3008 while ($arr = db_fetch_array($res)) {
3009 $role_ids[] = $arr['role_id'];
3013 return array_unique($role_ids);
3017 * getRoles - Get the roles of the group.
3019 * @param bool all roles or local roles only. Default is all roles
3020 * @return array Roles of this group.
3022 function getRoles($global = true) {
3025 $roles = $this->getRolesId($global);
3026 $engine = RBACEngine::getInstance();
3027 foreach ($roles as $role_id) {
3028 $result[] = $engine->getRoleById($role_id);
3034 function normalizeAllRoles() {
3035 $roles = $this->getRoles();
3037 foreach ($roles as $r) {
3038 $r->normalizeData();
3043 * getUnixStatus - Status of activation of unix account.
3045 * @return string Values: (N)one, (A)ctive, (S)uspended or (D)eleted
3047 function getUnixStatus() {
3048 return $this->data_array['unix_status'];
3052 * setUnixStatus - Sets status of activation of unix account.
3054 * @param string $status The unix status.
3060 * @return bool success.
3062 function setUnixStatus($status) {
3065 $res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
3070 $this->setError(_('Error')._(': ')._('Cannot Update Group Unix Status')._(': ').db_error());
3074 if ($status == 'A') {
3075 if (!$SYS->sysCheckCreateGroup($this->getID())) {
3076 $this->setError($SYS->getErrorMessage());
3081 if ($SYS->sysCheckGroup($this->getID())) {
3082 if (!$SYS->sysRemoveGroup($this->getID())) {
3083 $this->setError($SYS->getErrorMessage());
3090 $this->data_array['unix_status'] = $status;
3097 * getUsers - Get the users of a group
3099 * @param bool $onlylocal
3100 * @param bool $onlyactive Only users with state active, or all users of group
3101 * @return array user's objects.
3103 function getUsers($onlylocal = true, $onlyactive = true) {
3104 if (!isset($this->membersArr)) {
3105 $this->membersArr = array();
3108 foreach ($this->getRoles() as $role) {
3110 && ($role->getHomeProject() == NULL || $role->getHomeProject()->getID() != $this->getID())) {
3113 foreach ($role->getUsers() as $user) {
3114 $ids[] = $user->getID();
3117 $ids = array_unique ($ids);
3118 foreach ($ids as $id) {
3119 $u = user_get_object ($id);
3120 if (!$onlyactive || $u->isActive()) {
3121 $this->membersArr[] = $u;
3125 return $this->membersArr;
3128 function setDocmanCreateOnlineStatus($status) {
3130 $res = db_query_params('UPDATE groups SET use_docman_create_online = $1 WHERE group_id = $2',
3131 array($status, $this->getID()));
3134 $this->setError(_('Error')._(': ')._('Cannot Update Group DocmanCreateOnline Status')._(': ').db_error());
3138 $this->data_array['use_docman_create_online'] = $status;
3144 function setDocmanWebdav($status) {
3146 $res = db_query_params('UPDATE groups SET use_webdav = $1 WHERE group_id = $2',
3151 $this->setError(_('Error')._(': ')._('Cannot Update Group UseWebdav Status')._(': ').db_error());
3155 $this->data_array['use_webdav'] = $status;
3161 function setDocmanSearchStatus($status) {
3163 /* if we activate search engine, we probably want to reindex */
3164 $res = db_query_params('UPDATE groups SET use_docman_search = $1, force_docman_reindex = $1 WHERE group_id = $2',
3165 array($status, $this->getID()));
3168 $this->setError(_('Error')._(': ')._('Cannot Update Group UseDocmanSearch Status')._(': ').db_error());
3172 $this->data_array['use_docman_search'] = $status;
3178 function setDocmanForceReindexSearch($status) {
3180 $res = db_query_params('UPDATE groups SET force_docman_reindex = $1 WHERE group_id = $2',
3181 array($status, $this->getID()));
3184 $this->setError(_('Error')._(': ')._('Cannot Update Group force_docman_reindex')._(': ').db_error());
3188 $this->data_array['force_docman_reindex'] = $status;
3196 * @param int $unit_set_id the effort unit set id
3199 function setEffortUnitSet($unit_set_id) {
3201 $res = db_query_params ('UPDATE groups SET unit_set_id=$1 WHERE group_id=$2',
3202 array($unit_set_id, $this->getID()));
3204 $this->data_array['unit_set_id'] = $unit_set_id;
3214 * getEffortUnitSet - Get the effort unit set id.
3216 * @return int The id of the effort unit set.
3218 function getEffortUnitSet() {
3219 return $this->data_array['unit_set_id'];
3222 function getWidgetLayoutConfig() {
3223 $lm = new WidgetLayoutManager();
3224 return $lm->getLayout($this->getID(), WidgetLayoutManager::OWNER_TYPE_GROUP);
3229 * group_getname() - get the group name
3231 * @param int $group_id The group ID
3236 function group_getname ($group_id = 0) {
3237 $grp = group_get_object($group_id);
3239 return $grp->getPublicName();
3246 * group_getunixname() - get the unixname for a group
3248 * @param int $group_id The group ID
3253 function group_getunixname ($group_id) {
3254 $grp = group_get_object($group_id);
3256 return $grp->getUnixName();
3263 * group_get_result() - Get the group object result ID.
3265 * @param int $group_id The group ID
3270 function &group_get_result($group_id=0) {
3271 $grp = group_get_object($group_id);
3273 return $grp->getData();
3279 function getAllProjectTags($onlyvisible = true) {
3280 $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',
3283 if (!$res || db_numrows($res) == 0) {
3289 while ($arr = db_fetch_array($res)) {
3291 $group_id = $arr[1];
3292 if (!isset($result[$tag])) {
3293 $result[$tag] = array();
3296 if (!$onlyvisible || forge_check_perm('project_read', $group_id)) {
3297 $p = group_get_object($group_id);
3298 $result[$tag][] = array('unix_group_name' => $p->getUnixName(),
3299 'group_id' => $group_id);
3307 * Utility class to compare project based in various criteria (names, unixnames, id, ...)
3310 class ProjectComparator {
3311 var $criterion = 'name';
3313 function Compare ($a, $b) {
3314 switch ($this->criterion) {
3317 $namecmp = strcoll ($a->getPublicName(), $b->getPublicName());
3318 if ($namecmp != 0) {
3321 /* If several projects share a same public name */
3322 return strcoll ($a->getUnixName(), $b->getUnixName());
3324 return strcmp ($a->getUnixName(), $b->getUnixName());
3331 return ($aid < $bid) ? -1 : 1;
3336 function sortProjectList (&$list, $criterion='name') {
3337 $cmp = new ProjectComparator();
3338 $cmp->criterion = $criterion;
3340 return usort ($list, array($cmp, 'Compare'));
3345 // c-file-style: "bsd"