5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2009, Roland Mas
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 require_once $gfcommon.'tracker/ArtifactTypes.class.php';
27 require_once $gfcommon.'tracker/ArtifactTypeFactory.class.php';
28 require_once $gfcommon.'forum/Forum.class.php';
29 require_once $gfcommon.'forum/ForumFactory.class.php';
30 require_once $gfcommon.'pm/ProjectGroup.class.php';
31 require_once $gfcommon.'pm/ProjectGroupFactory.class.php';
32 require_once $gfcommon.'include/Role.class.php';
33 require_once $gfcommon.'frs/FRSPackage.class.php';
34 require_once $gfcommon.'docman/DocumentGroup.class.php';
35 require_once $gfcommon.'mail/MailingList.class.php';
36 require_once $gfcommon.'mail/MailingListFactory.class.php';
37 require_once $gfcommon.'survey/SurveyFactory.class.php';
38 require_once $gfcommon.'survey/SurveyQuestionFactory.class.php';
39 require_once $gfcommon.'include/gettext.php';
41 //the license_id of "Other/proprietary" license
42 define('GROUP_LICENSE_OTHER',126);
44 $LICENSE_NAMES=array();
47 * group_get_licences() - get the licenses list
49 * @return array list of licenses
51 function & group_get_licenses() {
52 global $LICENSE_NAMES;
53 if(empty($LICENSE_NAMES)) {
54 $result = db_query_params ('select * from licenses', array());
55 while($data = db_fetch_array($result)) {
56 $LICENSE_NAMES[$data['license_id']] = $data['license_name'];
59 return $LICENSE_NAMES;
65 * group_get_object() - Get the group object.
67 * group_get_object() is useful so you can pool group objects/save database queries
68 * You should always use this instead of instantiating the object directly.
70 * You can now optionally pass in a db result handle. If you do, it re-uses that query
71 * to instantiate the objects.
73 * IMPORTANT! That db result must contain all fields
74 * from groups table or you will have problems
77 * @param int Result set handle ("SELECT * FROM groups WHERE group_id=xx")
78 * @return a group object or false on failure
80 function &group_get_object($group_id,$res=false) {
81 //create a common set of group objects
82 //saves a little wear on the database
84 //automatically checks group_type and
85 //returns appropriate object
88 if (!isset($GROUP_OBJ["_".$group_id."_"])) {
90 //the db result handle was passed in
92 $res = db_query_params ('SELECT * FROM groups WHERE group_id=$1', array ($group_id)) ;
94 if (!$res || db_numrows($res) < 1) {
95 $GROUP_OBJ["_".$group_id."_"]=false;
98 check group type and set up object
100 if (db_result($res,0,'type_id')==1) {
102 $GROUP_OBJ["_".$group_id."_"]= new Group($group_id,$res);
105 $GROUP_OBJ["_".$group_id."_"]=false;
109 return $GROUP_OBJ["_".$group_id."_"];
112 function &group_get_objects($id_arr) {
115 // Note: if we don't do this, the result may be corrupted
119 for ($i=0; $i<count($id_arr); $i++) {
121 // See if this ID already has been fetched in the cache
126 if (!isset($GROUP_OBJ["_".$id_arr[$i]."_"])) {
127 $fetch[]=$id_arr[$i];
129 $return[] =& $GROUP_OBJ["_".$id_arr[$i]."_"];
132 if (count($fetch) > 0) {
133 $res=db_query_params ('SELECT * FROM groups WHERE group_id = ANY ($1)',
134 array (db_int_array_to_any_clause ($fetch))) ;
135 while ($arr = db_fetch_array($res)) {
136 $GROUP_OBJ["_".$arr['group_id']."_"] = new Group($arr['group_id'],$arr);
137 $return[] =& $GROUP_OBJ["_".$arr['group_id']."_"];
143 function &group_get_object_by_name($groupname) {
144 $res=db_query_params('SELECT * FROM groups WHERE unix_group_name=$1', array ($groupname)) ;
145 return group_get_object(db_result($res,0,'group_id'),$res);
148 function &group_get_objects_by_name($groupname_arr) {
149 $res=db_query_params ('SELECT group_id FROM groups WHERE unix_group_name = ANY ($1)',
150 array (db_string_array_to_any_clause ($groupname_arr))
152 $arr =& util_result_column_to_array($res,0);
153 return group_get_objects($arr);
156 function &group_get_object_by_publicname($groupname) {
157 $res=db_query_params ('SELECT * FROM groups WHERE lower(group_name) LIKE $1',
158 array (htmlspecialchars (strtolower ($groupname)))) ;
160 return group_get_object(db_result($res,0,'group_id'),$res);
163 class Group extends Error {
165 * Associative array of data from db.
167 * @var array $data_array.
172 * array of User objects.
174 * @var array $membersArr.
179 * Whether the use is an admin/super user of this project.
181 * @var bool $is_admin.
186 * Artifact types result handle.
188 * @var int $types_res.
193 * Associative array of data for plugins.
195 * @var array $plugins_data.
201 * Associative array of data for the group menu.
203 * @var array $menu_data.
208 * Group - Group object constructor - use group_get_object() to instantiate.
210 * @param int Required - group_id of the group you want to instantiate.
211 * @param int Database result from select query OR associative array of all columns.
213 function Group($id=false, $res=false) {
216 //setting up an empty object
217 //probably going to call create()
221 if (!$this->fetchData($id)) {
226 // Assoc array was passed in
228 if (is_array($res)) {
229 $this->data_array =& $res;
231 if (db_numrows($res) < 1) {
232 //function in class we extended
233 $this->setError(_('Group Not Found'));
234 $this->data_array=array();
237 //set up an associative array for use by other functions
238 $this->data_array = db_fetch_array_by_row($res, 0);
247 * fetchData - May need to refresh database fields if an update occurred.
249 * @param int The group_id.
251 function fetchData($group_id) {
252 $res = db_query_params ('SELECT * FROM groups WHERE group_id=$1',
254 if (!$res || db_numrows($res) < 1) {
255 $this->setError(sprintf(_('fetchData():: %s'),db_error()));
258 $this->data_array = db_fetch_array($res);
263 * create - Create new group.
265 * This method should be called on empty Group object.
267 * @param object The User object.
268 * @param string The full name of the user.
269 * @param string The Unix name of the user.
270 * @param string The new group description.
271 * @param string The purpose of the group.
272 * @param bool Whether to send an email or not
274 function create(&$user, $group_name, $unix_name, $description, $purpose, $unix_box='shell1', $scm_box='cvs1', $is_public=1, $send_mail=true) {
275 // $user is ignored - anyone can create pending group
278 if ($this->getID()!=0) {
279 $this->setError(_('Group::create: Group object already exists'));
281 } else if (!$this->validateGroupName($group_name)) {
283 } else if (!account_groupnamevalid($unix_name)) {
284 $this->setError(_('Invalid Unix name'));
286 } else if (!$SYS->sysUseUnixName($unix_name)) {
287 $this->setError(_('Unix name already taken'));
289 } else if (db_numrows(db_query_params('SELECT group_id FROM groups WHERE unix_group_name=$1',
290 array ($unix_name))) > 0) {
291 $this->setError(_('Unix name already taken'));
293 } else if (strlen($purpose)<10) {
294 $this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
296 } else if (strlen($purpose)>1500) {
297 $this->setError(_('The Registration Purpose text is too long. Please make it smaller than 1500 bytes.'));
299 } else if (strlen($description)<10) {
300 $this->setError(_('Describe in a more comprehensive manner your project.'));
302 } else if (strlen($description)>255) {
303 $this->setError(_('Your project description is too long. Please make it smaller than 256 bytes.'));
307 srand((double)microtime()*1000000);
308 $random_num = rand(0,1000000);
312 $res = db_query_params ('
328 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)',
329 array (htmlspecialchars ($group_name),
332 htmlspecialchars($description),
333 $unix_name.".".forge_get_config('web_host'),
334 $unix_name.".".forge_get_config('web_host'),
338 htmlspecialchars($purpose),
341 md5($random_num) )) ;
342 if (!$res || db_affected_rows($res) < 1) {
343 $this->setError(sprintf(_('ERROR: Could not create group: %s'),db_error()));
348 $id = db_insertid($res, 'groups', 'group_id');
350 $this->setError(sprintf(_('ERROR: Could not get group id: %s'),db_error()));
356 // Now, make the user an admin
358 $res=db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags,
359 cvs_flags, artifact_flags, forum_flags, role_id)
360 VALUES ($1, $2, $3, $4, $5, $6, $7)',
361 array ($user->getID(),
368 if (!$res || db_affected_rows($res) < 1) {
369 $this->setError(sprintf(_('ERROR: Could not add admin to newly created group: %s'),db_error()));
374 if (!$this->fetchData($id)) {
379 $hook_params = array ();
380 $hook_params['group'] = $this;
381 $hook_params['group_id'] = $this->getID();
382 $hook_params['group_name'] = $group_name;
383 $hook_params['unix_group_name'] = $unix_name;
384 plugin_hook ("group_create", $hook_params);
388 $this->sendNewProjectNotificationEmail();
396 * updateAdmin - Update core properties of group object.
398 * This function require site admin privilege.
400 * @param object User requesting operation (for access control).
401 * @param bool Whether group is publicly accessible (0/1).
402 * @param int Group type (1-project, 2-foundry).
403 * @param string Machine on which group's home directory located.
404 * @param string Domain which serves group's WWW.
408 function updateAdmin(&$user, $is_public, $type_id, $unix_box, $http_domain) {
409 $perm =& $this->getPermission ();
411 if (!$perm || !is_object($perm)) {
412 $this->setError(_('Could not get permission.'));
416 if (!$perm->isSuperUser()) {
417 $this->setError(_('Permission denied.'));
423 $res = db_query_params ('
425 SET is_public=$1, type_id=$2,
426 unix_box=$3, http_domain=$4
434 if (!$res || db_affected_rows($res) < 1) {
435 $this->setError(_('ERROR: DB: Could not change group properties: %s'),db_error());
440 // Log the audit trail
441 if ($is_public != $this->isPublic()) {
442 $this->addHistory('is_public', $this->isPublic());
444 if ($type_id != $this->data_array['type_id']) {
445 $this->addHistory('type_id', $this->data_array['type_id']);
447 if ($unix_box != $this->data_array['unix_box']) {
448 $this->addHistory('unix_box', $this->data_array['unix_box']);
450 if ($http_domain != $this->data_array['http_domain']) {
451 $this->addHistory('http_domain', $this->data_array['http_domain']);
454 if (!$this->fetchData($this->getID())) {
463 * update - Update number of common properties.
465 * Unlike updateAdmin(), this function accessible to project admin.
467 * @param object User requesting operation (for access control).
468 * @param bool Whether group is publicly accessible (0/1).
469 * @param string Project's license (string ident).
470 * @param int Group type (1-project, 2-foundry).
471 * @param string Machine on which group's home directory located.
472 * @param string Domain which serves group's WWW.
473 * @return int status.
476 function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,
477 $use_pm,$use_pm_depend_box,$use_scm,$use_news,$use_docman,
478 $new_doc_address,$send_all_docs,$logo_image_id,
479 $use_ftp,$use_tracker,$use_frs,$use_stats,$tags,$is_public) {
481 $perm =& $this->getPermission ();
483 if (!$perm || !is_object($perm)) {
484 $this->setError(_('Could not get permission.'));
488 if (!$perm->isAdmin()) {
489 $this->setError(_('Permission denied.'));
493 // Validate some values
494 if ($this->getPublicName() != $group_name) {
495 if (!$this->validateGroupName($group_name)) {
500 if ($new_doc_address) {
501 $invalid_mails = validate_emails($new_doc_address);
502 if (count($invalid_mails) > 0) {
503 $this->setError(sprintf (ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
508 // in the database, these all default to '1',
509 // so we have to explicity set 0
522 if (!$use_pm_depend_box) {
523 $use_pm_depend_box=0;
546 if (!$send_all_docs) {
550 $homepage = ltrim($homepage);
552 $homepage=forge_get_config('web_host').'/projects/'.$this->getUnixName().'/';
555 if (strlen(htmlspecialchars($short_description))>255) {
556 $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
562 //XXX not yet actived logo_image_id='$logo_image_id',
563 $res = db_query_params ('UPDATE groups
566 short_description=$3,
571 use_pm_depend_box=$8,
583 array (htmlspecialchars($group_name),
585 htmlspecialchars($short_description),
604 $this->setError(sprintf(_('Error updating project information: %s'), db_error()));
609 if ($this->setTags($tags) === false) {
614 $hook_params = array ();
615 $hook_params['group'] = $this;
616 $hook_params['group_id'] = $this->getID();
617 $hook_params['group_homepage'] = $homepage;
618 $hook_params['group_name'] = htmlspecialchars($group_name);
619 $hook_params['group_description'] = htmlspecialchars($short_description);
620 plugin_hook ("group_update", $hook_params);
622 // Log the audit trail
623 $this->addHistory('Changed Public Info', '');
625 if (!$this->fetchData($this->getID())) {
634 * getID - Simply return the group_id for this object.
636 * @return int group_id.
639 return $this->data_array['group_id'];
643 * getType() - Foundry, project, etc.
645 * @return int The type flag from the database.
648 return $this->data_array['type_id'];
653 * getStatus - the status code.
655 * Statuses char include I,H,A,D.
657 function getStatus() {
658 return $this->data_array['status'];
662 * setStatus - set the status code.
664 * Statuses include I,H,A,D.
666 * @param object User requesting operation (for access control).
667 * @param string Status value.
668 * @return boolean success.
671 function setStatus(&$user, $status) {
674 $perm =& $this->getPermission ();
675 if (!$perm || !is_object($perm)) {
676 $this->setPermissionDeniedError();
678 } elseif (!$perm->isSuperUser()) {
679 $this->setPermissionDeniedError();
683 // Projects in 'A' status can only go to 'H' or 'D'
684 // Projects in 'D' status can only go to 'A'
685 // Projects in 'P' status can only go to 'A' OR 'D'
686 // Projects in 'I' status can only go to 'P'
687 // Projects in 'H' status can only go to 'A' OR 'D'
688 $allowed_status_changes = array(
689 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
690 'IP'=>1,'HA'=>1,'HD'=>1
693 // Check that status transition is valid
694 if ($this->getStatus() != $status
695 && !$allowed_status_changes[$this->getStatus().$status]) {
696 $this->setError(_('Invalid Status Change'));
702 $res = db_query_params ('UPDATE groups
704 WHERE group_id=$2', array ($status, $this->getID())) ;
706 if (!$res || db_affected_rows($res) < 1) {
707 $this->setError(sprintf(_('ERROR: DB: Could not change group status: %s'),db_error()));
713 // Activate system group, if not yet
714 if (!$SYS->sysCheckGroup($this->getID())) {
715 if (!$SYS->sysCreateGroup($this->getID())) {
716 $this->setError($SYS->getErrorMessage());
721 if (!$this->activateUsers()) {
726 /* Otherwise, the group is not active, and make sure that
727 System group is not active either */
728 } else if ($SYS->sysCheckGroup($this->getID())) {
729 if (!$SYS->sysRemoveGroup($this->getID())) {
730 $this->setError($SYS->getErrorMessage());
736 $hook_params = array ();
737 $hook_params['group'] = $this;
738 $hook_params['group_id'] = $this->getID();
739 $hook_params['status'] = $status;
740 plugin_hook ("group_setstatus", $hook_params);
744 // Log the audit trail
745 if ($status != $this->getStatus()) {
746 $this->addHistory('Status', $this->getStatus());
749 $this->data_array['status'] = $status;
754 * isProject - Simple boolean test to see if it's a project or not.
756 * @return boolean is_project.
758 function isProject() {
759 if ($this->getType()==1) {
767 * isPublic - Simply returns the is_public flag from the database.
769 * @return boolean is_public.
771 function isPublic() {
772 return $this->data_array['is_public'];
776 * isActive - Database field status of 'A' returns true.
778 * @return boolean is_active.
780 function isActive() {
781 if ($this->getStatus()=='A') {
789 * getUnixName - the unix_name
791 * @return string unix_name.
793 function getUnixName() {
794 return strtolower($this->data_array['unix_group_name']);
798 * getPublicName - the full-length public name.
800 * @return string The group_name.
802 function getPublicName() {
803 return $this->data_array['group_name'];
807 * getRegisterPurpose - the text description of the purpose of this project.
809 * @return string The description.
811 function getRegisterPurpose() {
812 return $this->data_array['register_purpose'];
816 * getDescription - the text description of this project.
818 * @return string The description.
820 function getDescription() {
821 return $this->data_array['short_description'];
825 * getStartDate - the unix time this project was registered.
827 * @return int (unix time) of registration.
829 function getStartDate() {
830 return $this->data_array['register_time'];
834 * getLogoImageID - the id of the logo in the database for this project.
836 * @return int The ID of logo image in db_images table (or 100 if none).
838 function getLogoImageID() {
839 return $this->data_array['logo_image_id'];
843 * getUnixBox - the hostname of the unix box where this project is located.
845 * @return string The name of the unix machine for the group.
847 function getUnixBox() {
848 return $this->data_array['unix_box'];
852 * getSCMBox - the hostname of the scm box where this project is located.
854 * @return string The name of the unix machine for the group.
856 function getSCMBox() {
857 return $this->data_array['scm_box'];
860 * setSCMBox - the hostname of the scm box where this project is located.
862 * @param string The name of the new SCM_BOX
864 function setSCMBox($scm_box) {
866 if ($scm_box == $this->data_array['scm_box']) {
871 $res = db_query_params ('UPDATE groups SET scm_box=$1 WHERE group_id=$2', array ($scm_box, $this->getID ()));
873 $this->addHistory('scm_box', $this->data_array['scm_box']);
874 $this->data_array['scm_box']=$scm_box;
879 $this->setError(_("Couldn't insert SCM_BOX to database"));
883 $this->setError(_("SCM Box can't be empty"));
889 * getDomain - the hostname.domain where their web page is located.
891 * @return string The name of the group [web] domain.
893 function getDomain() {
894 return $this->data_array['http_domain'];
898 * getLicense - the license they chose.
900 * @return int ident of group license.
902 function getLicense() {
903 return $this->data_array['license'];
907 * getLicenseName - the name of the license
909 * @return string license name
911 function getLicenseName() {
912 $licenses =& group_get_licenses();
913 if(isset($licenses[$this->data_array['license']])) {
914 return $licenses[$this->data_array['license']];
921 * getLicenseOther - optional string describing license.
923 * @return string The custom license.
925 function getLicenseOther() {
926 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
927 return $this->data_array['license_other'];
934 * getRegistrationPurpose - the text description of the purpose of this project.
936 * @return string The application for project hosting.
938 function getRegistrationPurpose() {
939 return $this->data_array['register_purpose'];
944 * getAdmins() - Get array of Admin user objects.
946 * @return array Array of User objects.
948 function &getAdmins() {
949 // this function gets all group admins in order to send Jabber and mail messages
950 $res = db_query_params ('SELECT user_id FROM user_group WHERE admin_flags=$1 AND group_id=$2',
951 array ('A', $this->getID()));
952 $user_ids=util_result_column_to_array($res);
953 return user_get_objects($user_ids);
958 Common Group preferences for tools
963 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
965 * @return boolean enable_scm.
967 function enableAnonSCM() {
969 $r = RoleAnonymous::getInstance () ;
970 return $r->hasPermission ('scm', $this->getID(), 'read') ;
972 if ($this->isPublic() && $this->usesSCM()) {
973 return $this->data_array['enable_anonscm'];
980 function SetUsesAnonSCM ($booleanparam) {
982 $booleanparam = $booleanparam ? 1 : 0 ;
984 $r = RoleAnonymous::getInstance () ;
985 $r->setSetting ('scm', $this->getID(), $booleanparam) ;
988 $res = db_query_params ('UPDATE groups SET enable_anonscm=$1 WHERE group_id=$2',
989 array ($booleanparam, $this->getID()));
991 $this->data_array['enable_anonscm']=$booleanparam;
1000 function setUsesSCM ($booleanparam) {
1002 $booleanparam = $booleanparam ? 1 : 0 ;
1003 $res = db_query_params ('UPDATE groups SET use_scm=$1 WHERE group_id=$2',
1004 array ($booleanparam, $this->getID()));
1006 $this->data_array['use_scm']=$booleanparam;
1015 * enablePserver - whether or not this group has opted to enable Pserver.
1017 * @return boolean enable_pserver.
1019 function enablePserver() {
1020 if ($this->usesSCM()) {
1021 return $this->data_array['enable_pserver'];
1027 function SetUsesPserver ($booleanparam) {
1029 $booleanparam = $booleanparam ? 1 : 0 ;
1030 $res = db_query_params ('UPDATE groups SET enable_pserver=$1 WHERE group_id=$2',
1031 array ($booleanparam, $this->getID()));
1033 $this->data_array['enable_pserver']=$booleanparam;
1042 * usesSCM - whether or not this group has opted to use SCM.
1044 * @return boolean uses_scm.
1046 function usesSCM() {
1048 if (forge_get_config('use_scm')) {
1049 return $this->data_array['use_scm'];
1056 * usesMail - whether or not this group has opted to use mailing lists.
1058 * @return boolean uses_mail.
1060 function usesMail() {
1062 if (forge_get_config('use_mail')) {
1063 return $this->data_array['use_mail'];
1070 * usesNews - whether or not this group has opted to use news.
1072 * @return boolean uses_news.
1074 function usesNews() {
1076 if (forge_get_config('use_news')) {
1077 return $this->data_array['use_news'];
1084 * usesForum - whether or not this group has opted to use discussion forums.
1086 * @return boolean uses_forum.
1088 function usesForum() {
1090 if (forge_get_config('use_forum')) {
1091 return $this->data_array['use_forum'];
1098 * usesStats - whether or not this group has opted to use stats.
1100 * @return boolean uses_stats.
1102 function usesStats() {
1103 return $this->data_array['use_stats'];
1107 * usesFRS - whether or not this group has opted to use file release system.
1109 * @return boolean uses_frs.
1111 function usesFRS() {
1113 if (forge_get_config('use_frs')) {
1114 return $this->data_array['use_frs'];
1121 * usesTracker - whether or not this group has opted to use tracker.
1123 * @return boolean uses_tracker.
1125 function usesTracker() {
1127 if (forge_get_config('use_tracker')) {
1128 return $this->data_array['use_tracker'];
1135 * usesDocman - whether or not this group has opted to use docman.
1137 * @return boolean uses_docman.
1139 function usesDocman() {
1141 if (forge_get_config('use_docman')) {
1142 return $this->data_array['use_docman'];
1148 * usesDocmanSearch - whether or not this group has opted to use docman search engine.
1150 * @return boolean use_docman_search.
1152 function useDocmanSearch() {
1154 if (forge_get_config('use_docman')) {
1155 return $this->data_array['use_docman_search'];
1162 * usesFTP - whether or not this group has opted to use FTP.
1164 * @return boolean uses_ftp.
1166 function usesFTP() {
1168 if (forge_get_config('use_ftp')) {
1169 return $this->data_array['use_ftp'];
1176 * usesSurvey - whether or not this group has opted to use surveys.
1178 * @return boolean uses_survey.
1180 function usesSurvey() {
1182 if (forge_get_config('use_survey')) {
1183 return $this->data_array['use_survey'];
1190 * usesPM - whether or not this group has opted to Project Manager.
1192 * @return boolean uses_projman.
1196 if (forge_get_config('use_pm')) {
1197 return $this->data_array['use_pm'];
1204 * getPlugins - get a list of all available group plugins
1206 * @return array array containing plugin_id => plugin_name
1208 function getPlugins() {
1209 if (!isset($this->plugins_data)) {
1210 $this->plugins_data = array () ;
1211 $res = db_query_params ('SELECT group_plugin.plugin_id, plugins.plugin_name
1212 FROM group_plugin, plugins
1213 WHERE group_plugin.group_id=$1
1214 AND group_plugin.plugin_id=plugins.plugin_id', array ($this->getID()));
1215 $rows = db_numrows($res);
1217 for ($i=0; $i<$rows; $i++) {
1218 $plugin_id = db_result($res,$i,'plugin_id');
1219 $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
1222 return $this->plugins_data ;
1226 * usesPlugin - returns true if the group uses a particular plugin
1228 * @param string name of the plugin
1229 * @return boolean whether plugin is being used or not
1231 function usesPlugin($pluginname) {
1232 $plugins_data = $this->getPlugins() ;
1233 foreach ($plugins_data as $p_id => $p_name) {
1234 if ($p_name == $pluginname) {
1241 * added for Codendi compatibility
1242 * usesServices - returns true if the group uses a particular plugin or feature
1244 * @param string name of the plugin
1245 * @return boolean whether plugin is being used or not
1247 function usesService($feature) {
1248 $plugins_data = $this->getPlugins() ;
1249 $pm = plugin_manager_get_object();
1250 foreach ($plugins_data as $p_id => $p_name) {
1251 if ($p_name == $feature) {
1254 if ($pm->getPluginByName($p_name)->provide($feature) ) {
1262 * setPluginUse - enables/disables plugins for the group
1264 * @param string name of the plugin
1265 * @param boolean the new state
1266 * @return string database result
1268 function setPluginUse($pluginname, $val=true) {
1269 if ($val == $this->usesPlugin($pluginname)) {
1270 // State is already good, returning
1273 $res = db_query_params ('SELECT plugin_id FROM plugins WHERE plugin_name=$1',
1274 array ($pluginname));
1275 $rows = db_numrows($res);
1277 // Error: no plugin by that name
1280 $plugin_id = db_result($res,0,'plugin_id');
1282 unset ($this->plugins_data) ;
1284 $res = db_query_params ('INSERT INTO group_plugin (group_id, plugin_id) VALUES ($1, $2)',
1285 array ($this->getID(),
1289 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1 AND plugin_id=$2',
1290 array ($this->getID(),
1297 * getDocEmailAddress - get email address(es) to send doc notifications to.
1299 * @return string email address.
1301 function getDocEmailAddress() {
1302 return $this->data_array['new_doc_address'];
1306 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1308 * @return boolean email_on_all_doc_updates.
1310 function docEmailAll() {
1311 return $this->data_array['send_all_docs'];
1316 * getHomePage - The URL for this project's home page.
1318 * @return string homepage URL.
1320 function getHomePage() {
1321 return $this->data_array['homepage'];
1325 * getTags - Tags of this project.
1327 * @return string List of tags.
1329 function getTags() {
1330 $sql = 'SELECT name FROM project_tags WHERE group_id = $1';
1331 $res = db_query_params($sql, array($this->getID()));
1332 return join(', ', util_result_column_to_array($res));
1336 * setTags - Set tags of this project.
1338 * @return string database result.
1340 function setTags($tags) {
1342 $sql='DELETE FROM project_tags WHERE group_id=$1';
1343 $res=db_query_params($sql, array($this->getID()));
1345 $this->setError('Deleting old tags: '.db_error());
1349 $inserted = array();
1350 $tags_array = explode('[;,]', $tags);
1351 foreach ($tags_array as $tag) {
1352 $tag = stripslashes($tag);
1353 $tag = preg_replace('/[\t\r\n]/', ' ', $tag);
1354 // Allowed caracteres: [A-Z][a-z][0-9] -_&'#+.
1355 if (preg_match('/[^[:alnum:]| |\-|_|\&|\'|#|\+|\.]/', $tag)) {
1356 $this->setError(_('Bad tag name, you only can use the following characters: [A-Z][a-z][0-9]-_&\'#+. and space'));
1361 $tag = addslashes($tag);
1362 if ($tag == '' || array_search($tag, $inserted) !== false) continue;
1363 $sql='INSERT INTO project_tags (group_id,name) VALUES ($1, $2)';
1364 $res=db_query_params($sql, array($this->getID(), $tag));
1366 $this->setError(_('Setting tags: ').db_error());
1377 * getPermission - Return a Permission for this Group
1379 * @return object The Permission.
1381 function &getPermission() {
1382 return permission_get_object($this);
1386 function delete($sure,$really_sure,$really_really_sure) {
1387 if (!$sure || !$really_sure || !$really_really_sure) {
1388 $this->setMissingParamsError();
1391 if ($this->getID() == forge_get_config('news_group') ||
1392 $this->getID() == 1 ||
1393 $this->getID() == forge_get_config('stats_group') ||
1394 $this->getID() == forge_get_config('peer_rating_group')) {
1395 $this->setError(_('Cannot Delete System Group'));
1398 $perm =& $this->getPermission ();
1399 if (!$perm || !is_object($perm)) {
1400 $this->setPermissionDeniedError();
1402 } elseif ($perm->isError()) {
1403 $this->setPermissionDeniedError();
1405 } elseif (!$perm->isSuperUser()) {
1406 $this->setPermissionDeniedError();
1412 // Remove all the members
1414 $members =& $this->getMembers();
1415 for ($i=0; $i<count($members); $i++) {
1416 $this->removeUser($members[$i]->getID());
1421 $atf = new ArtifactTypeFactory($this);
1422 $at_arr =& $atf->getArtifactTypes();
1423 for ($i=0; $i<count($at_arr); $i++) {
1424 if (!is_object($at_arr[$i])) {
1425 printf (_("Not Object: ArtifactType: %d"),$i);
1428 $at_arr[$i]->delete(1,1);
1433 $ff = new ForumFactory($this);
1434 $f_arr =& $ff->getForums();
1435 for ($i=0; $i<count($f_arr); $i++) {
1436 if (!is_object($f_arr[$i])) {
1437 printf (_("Not Object: Forum: %d"),$i);
1440 $f_arr[$i]->delete(1,1);
1441 //echo 'ForumFactory'.db_error();
1444 // Delete Subprojects
1446 $pgf = new ProjectGroupFactory($this);
1447 $pg_arr =& $pgf->getProjectGroups();
1448 for ($i=0; $i<count($pg_arr); $i++) {
1449 if (!is_object($pg_arr[$i])) {
1450 printf (_("Not Object: ProjectGroup: %d"),$i);
1453 $pg_arr[$i]->delete(1,1);
1454 //echo 'ProjectGroupFactory'.db_error();
1457 // Delete FRS Packages
1459 //$frspf = new FRSPackageFactory($this);
1460 $res = db_query_params ('SELECT * FROM frs_package WHERE group_id=$1',
1461 array ($this->getID())) ;
1462 //echo 'frs_package'.db_error();
1463 //$frsp_arr =& $frspf->getPackages();
1464 while ($arr = db_fetch_array($res)) {
1465 //if (!is_object($pg_arr[$i])) {
1466 // echo "Not Object: ProjectGroup: ".$i;
1469 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1475 $news_group=&group_get_object(forge_get_config('news_group'));
1476 $res = db_query_params ('SELECT forum_id FROM news_bytes WHERE group_id=$1',
1477 array ($this->getID())) ;
1478 for ($i=0; $i<db_numrows($res); $i++) {
1479 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1480 if (!$Forum->delete(1,1)) {
1481 printf (_("Could Not Delete News Forum: %d"),$Forum->getID());
1484 $res = db_query_params ('DELETE FROM news_bytes WHERE group_id=$1',
1485 array ($this->getID())) ;
1490 $res = db_query_params ('DELETE FROM doc_data WHERE group_id=$1',
1491 array ($this->getID())) ;
1492 //echo 'doc_data'.db_error();
1493 $res = db_query_params ('DELETE FROM doc_groups WHERE group_id=$1',
1494 array ($this->getID())) ;
1495 //echo 'doc_groups'.db_error();
1500 $res=db_query_params('DELETE FROM project_tags WHERE group_id=$1', array($this->getID()));
1503 // Delete group history
1505 $res = db_query_params ('DELETE FROM group_history WHERE group_id=$1',
1506 array ($this->getID())) ;
1507 //echo 'group_history'.db_error();
1509 // Delete group plugins
1511 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1',
1512 array ($this->getID())) ;
1513 //echo 'group_plugin'.db_error();
1515 // Delete group cvs stats
1517 $res = db_query_params ('DELETE FROM stats_cvs_group WHERE group_id=$1',
1518 array ($this->getID())) ;
1519 //echo 'stats_cvs_group'.db_error();
1523 $sf = new SurveyFactory($this);
1524 $s_arr =& $sf->getSurveys();
1525 for ($i=0; $i<count($s_arr); $i++) {
1526 if (!is_object($s_arr[$i])) {
1527 printf (_("Not Object: Survey: %d"),$i);
1530 $s_arr[$i]->delete();
1531 //echo 'SurveyFactory'.db_error();
1534 // Delete SurveyQuestions
1536 $sqf = new SurveyQuestionFactory($this);
1537 $sq_arr =& $sqf->getSurveyQuestions();
1538 for ($i=0; $i<count($sq_arr); $i++) {
1539 if (!is_object($sq_arr[$i])) {
1540 printf (_("Not Object: SurveyQuestion: %d"),$i);
1543 $sq_arr[$i]->delete();
1544 //echo 'SurveyQuestionFactory'.db_error();
1547 // Delete Mailing List Factory
1549 $mlf = new MailingListFactory($this);
1550 $ml_arr =& $mlf->getMailingLists();
1551 for ($i=0; $i<count($ml_arr); $i++) {
1552 if (!is_object($ml_arr[$i])) {
1553 printf (_("Not Object: MailingList: %d"),$i);
1556 if (!$ml_arr[$i]->delete(1,1)) {
1557 $this->setError(_('Could not properly delete the mailing list'));
1559 //echo 'MailingListFactory'.db_error();
1564 $res = db_query_params ('DELETE FROM trove_group_link WHERE group_id=$1',
1565 array ($this->getID())) ;
1566 $res = db_query_params ('DELETE FROM trove_agg WHERE group_id=$1',
1567 array ($this->getID())) ;
1571 $res = db_query_params ('DELETE FROM project_sums_agg WHERE group_id=$1',
1572 array ($this->getID())) ;
1573 //echo 'project_sums_agg'.db_error();
1574 $res = db_query_params ('INSERT INTO deleted_groups (unix_group_name,delete_date,isdeleted) VALUES ($1, $2, $3)',
1575 array ($this->getUnixName(),
1578 //echo 'InsertIntoDeleteQueue'.db_error();
1579 $res = db_query_params ('DELETE FROM groups WHERE group_id=$1',
1580 array ($this->getID())) ;
1581 //echo 'DeleteGroup'.db_error();
1587 $hook_params = array ();
1588 $hook_params['group'] = $this;
1589 $hook_params['group_id'] = $this->getID();
1590 plugin_hook ("group_delete", $hook_params);
1592 if (forge_get_config('upload_dir') != '' && $this->getUnixName()) {
1593 exec('/bin/rm -rf '.forge_get_config('upload_dir').'/'.$this->getUnixName().'/');
1595 if (forge_get_config('ftp_upload_dir') != '' && $this->getUnixName()) {
1596 exec('/bin/rm -rf '.forge_get_config('ftp_upload_dir').'/'.$this->getUnixName().'/');
1601 $res = db_query_params ('DELETE FROM rep_group_act_monthly WHERE group_id=$1',
1602 array ($this->getID())) ;
1603 //echo 'rep_group_act_monthly'.db_error();
1604 $res = db_query_params ('DELETE FROM rep_group_act_weekly WHERE group_id=$1',
1605 array ($this->getID())) ;
1606 //echo 'rep_group_act_weekly'.db_error();
1607 $res = db_query_params ('DELETE FROM rep_group_act_daily WHERE group_id=$1',
1608 array ($this->getID())) ;
1609 //echo 'rep_group_act_daily'.db_error();
1610 unset($this->data_array);
1618 Basic functions to add/remove users to/from a group
1619 and update their permissions
1625 * addUser - controls adding a user to a group.
1627 * @param string Unix name of the user to add OR integer user_id.
1628 * @param int The role_id this user should have.
1629 * @return boolean success.
1632 function addUser($user_identifier,$role_id) {
1635 Admins can add users to groups
1638 if (!forge_check_perm ('project_admin', $this->getID())) {
1639 $this->setPermissionDeniedError();
1645 get user id for this user's unix_name
1647 if (is_int ($user_identifier)) { // user_id or user_name
1648 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array ($user_identifier)) ;
1650 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array ($user_identifier)) ;
1652 if (db_numrows($res_newuser) > 0) {
1654 // make sure user is active
1656 if (db_result($res_newuser,0,'status') != 'A') {
1657 $this->setError(_('User is not active. Only active users can be added.'));
1663 // user was found - set new user_id var
1665 $user_id = db_result($res_newuser,0,'user_id');
1667 $role = new Role($this,$role_id);
1668 if (!$role || !is_object($role)) {
1669 $this->setError(_('Error Getting Role Object'));
1672 } elseif ($role->isError()) {
1673 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1679 $role->addUser (user_get_object ($user_id)) ;
1680 if (!$SYS->sysCheckCreateGroup($this->getID())){
1681 $this->setError($SYS->getErrorMessage());
1685 if (!$SYS->sysCheckCreateUser($user_id)) {
1686 $this->setError($SYS->getErrorMessage());
1693 // if not already a member, add them
1695 $res_member = db_query_params ('SELECT user_id
1697 WHERE user_id=$1 AND group_id=$2',
1698 array ($user_id, $this->getID())) ;
1700 if (db_numrows($res_member) < 1) {
1702 // Create this user's row in the user_group table
1704 $res = db_query_params ('INSERT INTO user_group
1705 (user_id,group_id,admin_flags,forum_flags,project_flags,
1706 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
1707 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)',
1719 //verify the insert worked
1720 if (!$res || db_affected_rows($res) < 1) {
1721 $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
1726 // check and create if group doesn't exists
1728 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
1729 if (!$SYS->sysCheckCreateGroup($this->getID())){
1730 $this->setError($SYS->getErrorMessage());
1735 // check and create if user doesn't exists
1737 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1738 if (!$SYS->sysCheckCreateUser($user_id)) {
1739 $this->setError($SYS->getErrorMessage());
1746 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
1747 if (!$role->setUser($user_id)) {
1748 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1754 // user was already a member
1755 // make sure they are set up
1757 $user=&user_get_object($user_id,$res_newuser);
1758 $user->fetchData($user->getID());
1759 $role = new Role($this,$role_id);
1760 if (!$role || !is_object($role)) {
1761 $this->setError(_('Error Getting Role Object'));
1764 } elseif ($role->isError()) {
1765 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1769 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
1770 if (!$role->setUser($user_id)) {
1771 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1776 // set up their system info
1778 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1779 if (!$SYS->sysCheckCreateUser($user_id)) {
1780 $this->setError($SYS->getErrorMessage());
1788 // user doesn't exist
1790 $this->setError(_('ERROR: User does not exist'));
1795 $hook_params['group'] = $this;
1796 $hook_params['group_id'] = $this->getID();
1797 $hook_params['user'] = &user_get_object($user_id);
1798 $hook_params['user_id'] = $user_id;
1799 plugin_hook ("group_adduser", $hook_params);
1804 $this->addHistory('Added User',$user_identifier);
1810 * removeUser - controls removing a user from a group.
1812 * Users can remove themselves.
1814 * @param int The ID of the user to remove.
1815 * @return boolean success.
1817 function removeUser($user_id) {
1820 if ($user_id != user_getid()
1821 || !forge_check_perm ('project_admin', $this->getID())) {
1822 $this->setPermissionDeniedError();
1829 $user = user_get_object ($user_id) ;
1830 $roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
1831 $found_role = NULL ;
1832 foreach ($roles as $role) {
1833 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
1834 $found_role = $role ;
1838 if ($found_role == NULL) {
1839 $this->setError(sprintf(_('ERROR: User not removed: %s')));
1843 $found_role->removeUser ($user) ;
1845 $res = db_query_params ('DELETE FROM user_group WHERE group_id=$1 AND user_id=$2',
1846 array ($this->getID(),
1848 if (!$res || db_affected_rows($res) < 1) {
1849 $this->setError(sprintf(_('ERROR: User not removed: %s'),db_error()));
1856 // reassign open artifacts to id=100
1858 $res = db_query_params ('UPDATE artifact SET assigned_to=100
1859 WHERE group_artifact_id
1860 IN (SELECT group_artifact_id
1861 FROM artifact_group_list
1862 WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
1863 array ($this->getID(),
1866 $this->setError(sprintf(_('ERROR: DB: artifact: %s'),db_error()));
1872 // reassign open tasks to id=100
1873 // first have to purge any assignments that would cause
1874 // conflict with existing assignment to 100
1876 $res = db_query_params ('DELETE FROM project_assigned_to
1877 WHERE project_task_id IN (SELECT pt.project_task_id
1878 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1879 WHERE pt.group_project_id = pgl.group_project_id
1880 AND pat.project_task_id=pt.project_task_id
1881 AND pt.status_id=1 AND pgl.group_id=$1
1882 AND pat.assigned_to_id=$2)
1883 AND assigned_to_id=100',
1884 array ($this->getID(),
1887 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),1,db_error()));
1891 $res = db_query_params ('UPDATE project_assigned_to SET assigned_to_id=100
1892 WHERE project_task_id IN (SELECT pt.project_task_id
1893 FROM project_task pt, project_group_list pgl
1894 WHERE pt.group_project_id = pgl.group_project_id
1895 AND pt.status_id=1 AND pgl.group_id=$1)
1896 AND assigned_to_id=$2',
1897 array ($this->getID(),
1900 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),2,db_error()));
1906 // Remove user from system
1908 //echo "<h2>Group::addUser SYS->sysGroupRemoveUser(".$this->getID().",$user_id)</h2>";
1909 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
1910 $this->setError($SYS->getErrorMessage());
1915 $hook_params['group'] = $this;
1916 $hook_params['group_id'] = $this->getID();
1917 $hook_params['user'] = &user_get_object($user_id);
1918 $hook_params['user_id'] = $user_id;
1919 plugin_hook ("group_removeuser", $hook_params);
1922 $this->addHistory('Removed User',$user_id);
1929 * updateUser - controls updating a user's role in this group.
1931 * @param int The ID of the user.
1932 * @param int The role_id to set this user to.
1933 * @return boolean success.
1935 function updateUser($user_id,$role_id) {
1938 if (!forge_check_perm ('project_admin', $this->getID())) {
1939 $this->setPermissionDeniedError();
1944 $newrole = RBACEngine::getInstance()->getRoleById ($role_id) ;
1945 if (!$newrole || !is_object($newrole)) {
1946 $this->setError(_('Could Not Get Role'));
1948 } elseif ($newrole->isError()) {
1949 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1951 } elseif ($newrole->getHomeProject() == NULL
1952 || $newrole->getHomeProject()->getID() != $this->getID()) {
1953 $this->setError(_('Wrong destination role'));
1956 $user = user_get_object ($user_id) ;
1957 $roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
1958 $found_role = NULL ;
1959 foreach ($roles as $role) {
1960 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
1961 $found_role = $role ;
1965 if ($found_role == NULL) {
1966 $this->setError(sprintf(_('ERROR: User not removed: %s')));
1970 $found_role->removeUser ($user) ;
1971 $newrole->addUser ($user) ;
1973 $role = new Role($this,$role_id);
1974 if (!$role || !is_object($role)) {
1975 $this->setError(_('Could Not Get Role'));
1977 } elseif ($role->isError()) {
1978 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1981 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
1982 if (!$role->setUser($user_id)) {
1983 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1988 $this->addHistory('Updated User',$user_id);
1993 * addHistory - Makes an audit trail entry for this project.
1995 * @param string The name of the field.
1996 * @param string The Old Value for this $field_name.
1997 * @return database result handle.
2000 function addHistory($field_name, $old_value) {
2001 return db_query_params ('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
2002 VALUES ($1,$2,$3,$4,$5)',
2003 array ($this->getID(),
2011 * activateUsers - Make sure that group members have unix accounts.
2013 * Setup unix accounts for group members. Can be called even
2014 * if members are already active.
2018 function activateUsers() {
2021 Activate member(s) of the project
2024 $member_res = db_query_params ('SELECT user_id, role_id FROM user_group WHERE group_id=$1',
2025 array ($this->getID())) ;
2027 $rows = db_numrows($member_res);
2031 for ($i=0; $i<$rows; $i++) {
2033 $member =& user_get_object(db_result($member_res,$i,'user_id'));
2034 $roleId = db_result($member_res,$i,'role_id');
2036 if (!$member || !is_object($member)) {
2037 $this->setError(_('Error getting member object'));
2039 } else if ($member->isError()) {
2040 $this->setError(sprintf(_('Error getting member object: %s'),$member->getErrorMessage()));
2044 if (!$this->addUser($member->getUnixName(),$roleId)) {
2055 * getMembers - returns array of User objects for this project
2057 * @return array of User objects for this group.
2059 function &getMembers() {
2060 if (!isset($this->membersArr)) {
2061 $res = db_query_params ('SELECT users.* FROM users INNER JOIN user_group ON users.user_id=user_group.user_id WHERE user_group.group_id=$1',
2062 array ($this->getID())) ;
2063 while ($arr = db_fetch_array($res)) {
2064 $this->membersArr[] = new GFUser($arr['user_id'],$arr);
2067 return $this->membersArr;
2071 * approve - Approve pending project.
2073 * @param object The User object who is doing the updating.
2076 function approve(&$user) {
2078 if ($this->getStatus()=='A') {
2079 $this->setError(_("Group already active"));
2085 // Step 1: Activate group and create LDAP entries
2086 if (!$this->setStatus($user, 'A')) {
2091 // Switch to system language for item creation
2092 setup_gettext_from_sys_lang ();
2097 // Tracker Integration
2100 $ats = new ArtifactTypes($this);
2101 if (!$ats || !is_object($ats)) {
2102 $this->setError(_('Error creating ArtifactTypes object'));
2104 setup_gettext_from_context();
2106 } else if ($ats->isError()) {
2107 $this->setError(sprintf (_('ATS%d: %s'), 1, $ats->getErrorMessage()));
2109 setup_gettext_from_context();
2112 if (!$ats->createTrackers()) {
2113 $this->setError(sprintf (_('ATS%d: %s'), 2, $ats->getErrorMessage()));
2115 setup_gettext_from_context();
2121 // Forum Integration
2124 $f = new Forum($this);
2125 if (!$f->create(_('Open-Discussion'),_('General Discussion'),1,'',1,0)) {
2126 $this->setError(sprintf (_('F%d: %s'), 1, $f->getErrorMessage()));
2128 setup_gettext_from_context();
2131 $f = new Forum($this);
2132 if (!$f->create(_('Help'),_('Get Public Help'),1,'',1,0)) {
2133 $this->setError(sprintf (_('F%d: %s'), 2, $f->getErrorMessage()));
2135 setup_gettext_from_context();
2138 $f = new Forum($this);
2139 if (!$f->create(_('Developers-Discussion'),_('Project Developer Discussion'),0,'',1,0)) {
2140 $this->setError(sprintf (_('F%d: %s'), 3, $f->getErrorMessage()));
2142 setup_gettext_from_context();
2148 // Doc Mgr Integration
2151 $dg = new DocumentGroup($this);
2152 if (!$dg->create(_('Uncategorized Submissions'))) {
2153 $this->setError(sprintf(_('DG: %s'),$dg->getErrorMessage()));
2155 setup_gettext_from_context();
2164 $frs = new FRSPackage($this);
2165 if (!$frs->create($this->getUnixName())) {
2166 $this->setError(sprintf(_('FRSP: %s'),$frs->getErrorMessage()));
2168 setup_gettext_from_context();
2177 $pg = new ProjectGroup($this);
2178 if (!$pg->create(_('To Do'),_('Things We Have To Do'),1)) {
2179 $this->setError(sprintf(_('PG%d: %s'),1,$pg->getErrorMessage()));
2181 setup_gettext_from_context();
2184 $pg = new ProjectGroup($this);
2185 if (!$pg->create(_('Next Release'),_('Items For Our Next Release'),1)) {
2186 $this->setError(sprintf(_('PG%d: %s'),2,$pg->getErrorMessage()));
2188 setup_gettext_from_context();
2194 // Set Default Roles
2198 $admin_group = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1 AND admin_flags=$2',
2199 array ($this->getID(),
2201 if (db_numrows($admin_group) > 0) {
2202 $idadmin_group = db_result($admin_group,0,'user_id');
2204 $idadmin_group = $user->getID();
2205 db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags) VALUES ($1, $2, $3)',
2206 array ($idadmin_group,
2211 $role = new Role($this);
2212 $todo = array_keys($role->defaults);
2213 for ($c=0; $c<count($todo); $c++) {
2214 $role = new Role($this);
2215 if (! ($role_id = $role->createDefault($todo[$c]))) {
2216 $this->setError(sprintf(_('R%d: %s'),$c,$role->getErrorMessage()));
2218 setup_gettext_from_context();
2221 $role = new Role($this, $role_id);
2222 if ($role->getVal('projectadmin',0)=='A') {
2223 $role->setUser($idadmin_group);
2230 // Create MailingList
2233 if (forge_get_config('use_mail')) {
2234 $mlist = new MailingList($this);
2235 if (!$mlist->create('commits',_('Commits'),1,$idadmin_group)) {
2236 $this->setError(sprintf(_('ML: %s'),$mlist->getErrorMessage()));
2238 setup_gettext_from_context();
2243 // Switch back to user preference
2244 setup_gettext_from_context();
2248 $this->sendApprovalEmail();
2249 $this->addHistory('Approved', 'x');
2252 // Plugin can make approve operation there
2255 $params[0] = $idadmin_group ;
2256 $params[1] = $this->getID();
2257 plugin_hook('group_approve',$params);
2265 * sendApprovalEmail - Send new project email.
2267 * @return boolean success.
2270 function sendApprovalEmail() {
2271 $res_admins = db_query_params ('
2272 SELECT users.user_name,users.email,users.language,users.user_id
2273 FROM users,user_group
2274 WHERE users.user_id=user_group.user_id
2275 AND user_group.group_id=$1
2276 AND user_group.admin_flags=$2',
2277 array ($this->getID(),
2280 if (db_numrows($res_admins) < 1) {
2281 $this->setError(_("Group does not have any administrators."));
2285 // send one email per admin
2286 while ($row_admins = db_fetch_array($res_admins)) {
2287 $admin =& user_get_object($row_admins['user_id']);
2288 setup_gettext_for_user ($admin) ;
2290 $message=sprintf(_('Your project registration for %4$s has been approved.
2292 Project Full Name: %1$s
2293 Project Unix Name: %2$s
2295 Your DNS will take up to a day to become active on our site.
2296 Your web site is accessible through your shell account. Please read
2297 site documentation (see link below) about intended usage, available
2298 services, and directory layout of the account.
2301 own project page in %4$s while logged in, you will find
2302 additional menu functions to your left labeled \'Project Admin\'.
2304 We highly suggest that you now visit %4$s and create a public
2305 description for your project. This can be done by visiting your project
2306 page while logged in, and selecting \'Project Admin\' from the menus
2307 on the left (or by visiting %3$s
2310 Your project will also not appear in the Trove Software Map (primary
2311 list of projects hosted on %4$s which offers great flexibility in
2312 browsing and search) until you categorize it in the project administration
2313 screens. So that people can find your project, you should do this now.
2314 Visit your project while logged in, and select \'Project Admin\' from the
2317 Enjoy the system, and please tell others about %4$s. Let us know
2318 if there is anything we can do to help you.
2321 htmlspecialchars_decode($this->getPublicName()),
2322 $this->getUnixName(),
2323 util_make_url ('/project/admin/?group_id='.$this->getID()),
2324 forge_get_config ('forge_name'));
2326 util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), forge_get_config ('forge_name')), $message);
2328 setup_gettext_from_context();
2336 * sendRejectionEmail - Send project rejection email.
2338 * This function sends out a rejection message to a user who
2339 * registered a project.
2341 * @param int The id of the response to use.
2342 * @param string The rejection message.
2343 * @return completion status.
2346 function sendRejectionEmail($response_id, $message="zxcv") {
2347 $res_admins = db_query_params ('
2348 SELECT u.email, u.language, u.user_id
2349 FROM users u, user_group ug
2350 WHERE ug.group_id=$1
2351 AND u.user_id=ug.user_id',
2352 array ($this->getID())) ;
2353 if (db_numrows($res_admins) < 1) {
2354 $this->setError(_("Group does not have any administrators."));
2358 while ($row_admins = db_fetch_array($res_admins)) {
2359 $admin =& user_get_object($row_admins['user_id']);
2360 setup_gettext_for_user ($admin) ;
2362 $response=sprintf(_('Your project registration for %3$s has been denied.
2364 Project Full Name: %1$s
2365 Project Unix Name: %2$s
2367 Reasons for negative decision:
2369 '), $this->getPublicName(), $this->getUnixName(), forge_get_config ('forge_name'));
2371 // Check to see if they want to send a custom rejection response
2372 if ($response_id == 0) {
2373 $response .= $message;
2375 $response .= db_result (
2376 db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array ($response_id)),
2381 util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), forge_get_config ('forge_name')), $response);
2382 setup_gettext_from_context();
2389 * sendNewProjectNotificationEmail - Send new project notification email.
2391 * This function sends out a notification email to the
2392 * SourceForge admin user when a new project is
2395 * @return boolean success.
2398 function sendNewProjectNotificationEmail() {
2399 // Get the user who wants to register the project
2400 $res = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1',
2401 array ($this->getID())) ;
2403 if (db_numrows($res) < 1) {
2404 $this->setError(_("Could not find user who has submitted the project."));
2408 $submitter =& user_get_object(db_result($res,0,'user_id'));
2411 $res = db_query_params ('SELECT users.email, users.language, users.user_id
2412 FROM users, user_group
2414 AND user_group.admin_flags=$1
2415 AND users.user_id=user_group.user_id',
2418 if (db_numrows($res) < 1) {
2419 $this->setError(_("There is no administrator to send the mail to."));
2423 for ($i=0; $i<db_numrows($res) ; $i++) {
2424 $admin_email = db_result($res,$i,'email') ;
2425 $admin =& user_get_object(db_result($res,$i,'user_id'));
2426 setup_gettext_for_user ($admin) ;
2428 $message=sprintf(_('New %1$s Project Submitted
2430 Project Full Name: %2$s
2431 Submitted Description: %3$s
2432 Submitter: %5$s (%6$s)
2434 Please visit the following URL to approve or reject this project:
2436 forge_get_config ('forge_name'),
2437 htmlspecialchars_decode($this->getPublicName()),
2438 htmlspecialchars_decode($this->getRegistrationPurpose()),
2439 util_make_url ('/admin/approve-pending.php'),
2440 $submitter->getRealName(),
2441 $submitter->getUnixName());
2442 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
2443 setup_gettext_from_context();
2447 $email = $submitter->getEmail() ;
2448 setup_gettext_for_user ($submitter) ;
2450 $message=sprintf(_('New %1$s Project Submitted
2452 Project Full Name: %2$s
2453 Submitted Description: %3$s
2455 The %1$s admin team will now examine your project submission. You will be notified of their decision.'), forge_get_config ('forge_name'), $this->getPublicName(), util_unconvert_htmlspecialchars($this->getRegistrationPurpose()), forge_get_config('web_host'));
2457 util_send_message($email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
2458 setup_gettext_from_context();
2467 * validateGroupName - Validate the group name
2469 * @param string Group name.
2471 * @return an error false and set an error is the group name is invalide otherwise return true
2473 function validateGroupName($group_name) {
2474 if (strlen($group_name)<3) {
2475 $this->setError(_('Group name is too short'));
2477 } else if (strlen(htmlspecialchars($group_name))>50) {
2478 $this->setError(_('Group name is too long'));
2480 } else if ($group=group_get_object_by_publicname($group_name)) {
2481 $this->setError(_('Group name already taken'));
2489 * getRoles - Get the roles of the group.
2491 * @return array of Role id of this group.
2493 function getRolesId () {
2494 $role_ids = array () ;
2497 $res = db_query_params ('SELECT role_id FROM pfo_role WHERE home_group_id=$1',
2498 array ($this->getID()));
2499 while ($arr = db_fetch_array($res)) {
2500 $role_ids[] = $arr['role_id'] ;
2502 $res = db_query_params ('SELECT role_id FROM role_project_refs WHERE group_id=$1',
2503 array ($this->getID()));
2504 while ($arr = db_fetch_array($res)) {
2505 $role_ids[] = $arr['role_id'] ;
2508 $res = db_query_params ('SELECT role_id FROM role WHERE group_id=$1',
2509 array ($this->getID()));
2510 while ($arr = db_fetch_array($res)) {
2511 $role_ids[] = $arr['role_id'] ;
2515 return array_unique ($role_ids) ;
2518 function getRoles () {
2519 $result = array () ;
2521 $roles = $this->getRolesId () ;
2523 $engine = RBACEngine::getInstance() ;
2524 foreach ($roles as $role_id) {
2525 $result[] = $engine->getRoleById ($role_id) ;
2528 foreach ($roles as $role_id) {
2529 $result[] = new Role ($this, $role_id) ;
2536 function normalizeAllRoles () {
2537 $roles = $this->getRoles () ;
2539 foreach ($roles as $r) {
2540 $r->normalizeData () ;
2545 * getUnixStatus - Status of activation of unix account.
2547 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2549 function getUnixStatus() {
2550 return $this->data_array['unix_status'];
2554 * setUnixStatus - Sets status of activation of unix account.
2556 * @param string The unix status.
2562 * @return boolean success.
2564 function setUnixStatus($status) {
2567 $res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
2572 $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
2576 if ($status == 'A') {
2577 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2578 $this->setError($SYS->getErrorMessage());
2583 if ($SYS->sysCheckGroup($this->getID())) {
2584 if (!$SYS->sysRemoveGroup($this->getID())) {
2585 $this->setError($SYS->getErrorMessage());
2592 $this->data_array['unix_status']=$status;
2599 * getUsers - Get the users of a group
2601 * @return array of user's objects.
2603 function getUsers($onlylocal = true) {
2608 foreach ($this->getRoles() as $role) {
2610 && ($role->getHomeProject() == NULL || $role->getHomeProject()->getID() != $this->getID())) {
2613 foreach ($role->getUsers() as $user) {
2614 $ids[] = $user->getID() ;
2617 $ids = array_unique ($ids) ;
2618 foreach ($ids as $id) {
2619 $u = user_get_object ($id) ;
2620 if ($u->isActive()) {
2626 $users_group_res = db_query_params ('SELECT u.user_id FROM users u, user_group ug WHERE ug.group_id=$1 AND ug.user_id=u.user_id AND u.status=$2',
2627 array ($this->getID(),
2629 if (!$users_group_res) {
2630 $this->setError('Error: Enable to get users from group '. $this->getID() . ' ' .db_error());
2634 for ($i=0; $i<db_numrows($users_group_res); $i++) {
2635 $users[$i] = new GFUser(db_result($users_group_res,$i,'user_id'),false);
2643 function setDocmanSearchStatus($status) {
2645 /* if we activate search engine, we probably want to reindex */
2646 $res = db_query_params ('UPDATE groups SET use_docman_search=$1, force_docman_reindex=$1 WHERE group_id=$2',
2651 $this->setError(sprintf(_('ERROR - Could Not Update Group UseDocmanSearch Status: %s'),db_error()));
2655 $this->data_array['use_docman_search']=$status;
2661 function setDocmanForceReindexSearch($status) {
2663 /* if we activate search engine, we probably want to reindex */
2664 $res = db_query_params ('UPDATE groups SET force_docman_reindex=$1 WHERE group_id=$2',
2669 $this->setError(sprintf(_('ERROR - Could Not Update Group force_docman_reindex %s'),db_error()));
2673 $this->data_array['force_docman_reindex']=$status;
2681 * group_getname() - get the group name
2683 * @param int The group ID
2687 function group_getname ($group_id = 0) {
2688 $grp = &group_get_object($group_id);
2690 return $grp->getPublicName();
2697 * group_getunixname() - get the unixname for a group
2699 * @param int The group ID
2703 function group_getunixname ($group_id) {
2704 $grp = &group_get_object($group_id);
2706 return $grp->getUnixName();
2713 * group_get_result() - Get the group object result ID.
2715 * @param int The group ID
2719 function &group_get_result($group_id=0) {
2720 $grp = &group_get_object($group_id);
2722 return $grp->getData();
2731 // c-file-style: "bsd"