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 group_name ILIKE $1',
158 array (htmlspecialchars ($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 * Permissions data row from db.
181 * @var array $perm_data_array.
183 var $perm_data_array;
186 * Whether the use is an admin/super user of this project.
188 * @var bool $is_admin.
193 * Artifact types result handle.
195 * @var int $types_res.
200 * Associative array of data for plugins.
202 * @var array $plugins_array.
207 * Group - Group object constructor - use group_get_object() to instantiate.
209 * @param int Required - group_id of the group you want to instantiate.
210 * @param int Database result from select query OR associative array of all columns.
212 function Group($id=false, $res=false) {
215 //setting up an empty object
216 //probably going to call create()
220 if (!$this->fetchData($id)) {
225 // Assoc array was passed in
227 if (is_array($res)) {
228 $this->data_array =& $res;
230 if (db_numrows($res) < 1) {
231 //function in class we extended
232 $this->setError(_('Group Not Found'));
233 $this->data_array=array();
236 //set up an associative array for use by other functions
237 db_reset_result($res);
238 $this->data_array = db_fetch_array($res);
243 $systemGroups = array(GROUP_IS_NEWS, GROUP_IS_STATS, GROUP_IS_PEER_RATINGS);
244 if(!$this->isPublic() && !in_array($id, $systemGroups)) {
245 $perm =& $this->getPermission(session_get_user());
247 if (!$perm || !is_object($perm) || !$perm->isMember()) {
248 $this->setError(_('Permission denied'), ERROR__PERMISSION_DENIED_ERROR);
256 * fetchData - May need to refresh database fields if an update occurred.
258 * @param int The group_id.
260 function fetchData($group_id) {
261 $res = db_query_params ('SELECT * FROM groups WHERE group_id=$1',
263 if (!$res || db_numrows($res) < 1) {
264 $this->setError(sprintf(_('fetchData():: %s'),db_error()));
267 $this->data_array =& db_fetch_array($res);
272 * create - Create new group.
274 * This method should be called on empty Group object.
276 * @param object The User object.
277 * @param string The full name of the user.
278 * @param string The Unix name of the user.
279 * @param string The new group description.
280 * @param int The ID of the license to use.
281 * @param string The 'other' license to use if any.
282 * @param string The purpose of the group.
284 function create(&$user, $group_name, $unix_name, $description, $license, $license_other, $purpose, $unix_box='shell1', $scm_box='cvs1', $is_public=1) {
285 // $user is ignored - anyone can create pending group
287 if ($this->getID()!=0) {
288 $this->setError(_('Group::create: Group object already exists'));
290 } else if (!$this->validateGroupName($group_name)) {
292 } else if (!account_groupnamevalid($unix_name)) {
293 $this->setError(_('Invalid Unix name'));
295 } else if (db_numrows(db_query_params('SELECT group_id FROM groups WHERE unix_group_name=$1',
296 array ($unix_name))) > 0) {
297 $this->setError(_('Unix name already taken'));
299 } else if (strlen($purpose)<10) {
300 $this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
302 } else if (strlen($purpose)>1500) {
303 $this->setError(_('The Registration Purpose text is too long. Please make it smaller than 1500 bytes.'));
305 } else if (strlen($description)<10) {
306 $this->setError(_('Describe in a more comprehensive manner your project.'));
308 } else if (strlen($description)>255) {
309 $this->setError(_('Your project description is too long. Please make it smaller than 256 bytes.'));
311 } else if (!$license) {
312 $this->setError(_('You have not chosen a license'));
314 } else if ($license!=GROUP_LICENSE_OTHER && $license_other) {
315 $this->setError(_('Conflicting licenses choice'));
317 } else if ($license==GROUP_LICENSE_OTHER && strlen($license_other)<50) {
318 $this->setError(_('Please give more comprehensive licensing description'));
322 srand((double)microtime()*1000000);
323 $random_num = rand(0,1000000);
327 $res = db_query_params ('
345 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)',
346 array (htmlspecialchars ($group_name),
349 htmlspecialchars($description),
350 $unix_name.".".$GLOBALS['sys_default_domain'],
351 $unix_name.".".$GLOBALS['sys_default_domain'],
356 htmlspecialchars($purpose),
358 htmlspecialchars($license_other),
360 md5($random_num) )) ;
361 if (!$res || db_affected_rows($res) < 1) {
362 $this->setError(sprintf(_('ERROR: Could not create group: %s'),db_error()));
367 $id = db_insertid($res, 'groups', 'group_id');
369 $this->setError(sprintf(_('ERROR: Could not get group id: %s'),db_error()));
375 // Now, make the user an admin
377 $res=db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags,
378 cvs_flags, artifact_flags, forum_flags, role_id)
379 VALUES ($1, $2, $3, $4, $5, $6, $7)',
380 array ($user->getID(),
387 if (!$res || db_affected_rows($res) < 1) {
388 $this->setError(sprintf(_('ERROR: Could not add admin to newly created group: %s'),db_error()));
393 if (!$this->fetchData($id)) {
398 $hook_params = array ();
399 $hook_params['group'] = $this;
400 $hook_params['group_id'] = $this->getID();
401 $hook_params['group_name'] = $group_name;
402 $hook_params['unix_group_name'] = $unix_name;
403 plugin_hook ("group_create", $hook_params);
406 $this->sendNewProjectNotificationEmail();
413 * updateAdmin - Update core properties of group object.
415 * This function require site admin privilege.
417 * @param object User requesting operation (for access control).
418 * @param bool Whether group is publicly accessible (0/1).
419 * @param string Project's license (string ident).
420 * @param int Group type (1-project, 2-foundry).
421 * @param string Machine on which group's home directory located.
422 * @param string Domain which serves group's WWW.
426 function updateAdmin(&$user, $is_public, $license, $type_id, $unix_box, $http_domain) {
427 $perm =& $this->getPermission($user);
429 if (!$perm || !is_object($perm)) {
430 $this->setError(_('Could not get permission.'));
434 if (!$perm->isSuperUser()) {
435 $this->setError(_('Permission denied.'));
441 $res = db_query_params ('
443 SET is_public=$1, license=$2, type_id=$3,
444 unix_box=$4, http_domain=$5
453 if (!$res || db_affected_rows($res) < 1) {
454 $this->setError(_('ERROR: DB: Could not change group properties: %s'),db_error());
459 // Log the audit trail
460 if ($is_public != $this->isPublic()) {
461 $this->addHistory('is_public', $this->isPublic());
463 if ($license != $this->data_array['license']) {
464 $this->addHistory('license', $this->data_array['license']);
466 if ($type_id != $this->data_array['type_id']) {
467 $this->addHistory('type_id', $this->data_array['type_id']);
469 if ($unix_box != $this->data_array['unix_box']) {
470 $this->addHistory('unix_box', $this->data_array['unix_box']);
472 if ($http_domain != $this->data_array['http_domain']) {
473 $this->addHistory('http_domain', $this->data_array['http_domain']);
476 if (!$this->fetchData($this->getID())) {
485 * update - Update number of common properties.
487 * Unlike updateAdmin(), this function accessible to project admin.
489 function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,
490 $use_pm,$use_pm_depend_box,$use_scm,$use_news,$use_docman,
491 $new_doc_address,$send_all_docs,$logo_image_id,
492 $use_ftp,$use_tracker,$use_frs,$use_stats,$is_public) {
494 $perm =& $this->getPermission($user);
496 if (!$perm || !is_object($perm)) {
497 $this->setError(_('Could not get permission.'));
501 if (!$perm->isAdmin()) {
502 $this->setError(_('Permission denied.'));
506 // Validate some values
507 if (!$this->validateGroupName($group_name)) {
511 if ($new_doc_address) {
512 $invalid_mails = validate_emails($new_doc_address);
513 if (count($invalid_mails) > 0) {
514 $this->setError(sprintf (ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
519 // in the database, these all default to '1',
520 // so we have to explicity set 0
533 if (!$use_pm_depend_box) {
534 $use_pm_depend_box=0;
557 if (!$send_all_docs) {
562 $homepage=$GLOBALS['sys_default_domain'].'/projects/'.$this->getUnixName().'/';
565 if (strlen(htmlspecialchars($short_description))>255) {
566 $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
572 //XXX not yet actived logo_image_id='$logo_image_id',
573 $res = db_query_params ('UPDATE groups
576 short_description=$3,
581 use_pm_depend_box=$8,
593 array (htmlspecialchars($group_name),
595 htmlspecialchars($short_description),
614 $this->setError(sprintf(_('Error updating project information: %s'), db_error()));
619 $hook_params = array ();
620 $hook_params['group'] = $this;
621 $hook_params['group_id'] = $this->getID();
622 $hook_params['group_homepage'] = $homepage;
623 $hook_params['group_name'] = htmlspecialchars($group_name);
624 $hook_params['group_description'] = htmlspecialchars($short_description);
625 plugin_hook ("group_update", $hook_params);
627 // Log the audit trail
628 $this->addHistory('Changed Public Info', '');
630 if (!$this->fetchData($this->getID())) {
639 * getID - Simply return the group_id for this object.
641 * @return int group_id.
644 return $this->data_array['group_id'];
648 * getType() - Foundry, project, etc.
650 * @return int The type flag from the database.
653 return $this->data_array['type_id'];
658 * getStatus - the status code.
660 * Statuses char include I,H,A,D.
662 function getStatus() {
663 return $this->data_array['status'];
667 * setStatus - set the status code.
669 * Statuses include I,H,A,D.
671 * @param object User requesting operation (for access control).
672 * @param string Status value.
673 * @return boolean success.
676 function setStatus(&$user, $status) {
679 $perm =& $this->getPermission($user);
680 if (!$perm || !is_object($perm)) {
681 $this->setPermissionDeniedError();
683 } elseif (!$perm->isSuperUser()) {
684 $this->setPermissionDeniedError();
688 // Projects in 'A' status can only go to 'H' or 'D'
689 // Projects in 'D' status can only go to 'A'
690 // Projects in 'P' status can only go to 'A' OR 'D'
691 // Projects in 'I' status can only go to 'P'
692 // Projects in 'H' status can only go to 'A' OR 'D'
693 $allowed_status_changes = array(
694 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
695 'IP'=>1,'HA'=>1,'HD'=>1
698 // Check that status transition is valid
699 if ($this->getStatus() != $status
700 && !$allowed_status_changes[$this->getStatus().$status]) {
701 $this->setError(_('Invalid Status Change'));
707 $res = db_query_params ('UPDATE groups
709 WHERE group_id=$2', array ($status, $this->getID())) ;
711 if (!$res || db_affected_rows($res) < 1) {
712 $this->setError(sprintf(_('ERROR: DB: Could not change group status: %s'),db_error()));
718 // Activate system group, if not yet
719 if (!$SYS->sysCheckGroup($this->getID())) {
720 if (!$SYS->sysCreateGroup($this->getID())) {
721 $this->setError($SYS->getErrorMessage());
726 if (!$this->activateUsers()) {
731 /* Otherwise, the group is not active, and make sure that
732 System group is not active either */
733 } else if ($SYS->sysCheckGroup($this->getID())) {
734 if (!$SYS->sysRemoveGroup($this->getID())) {
735 $this->setError($SYS->getErrorMessage());
741 $hook_params = array ();
742 $hook_params['group'] = $this;
743 $hook_params['group_id'] = $this->getID();
744 $hook_params['status'] = $status;
745 plugin_hook ("group_setstatus", $hook_params);
749 // Log the audit trail
750 if ($status != $this->getStatus()) {
751 $this->addHistory('Status', $this->getStatus());
754 $this->data_array['status'] = $status;
759 * isProject - Simple boolean test to see if it's a project or not.
761 * @return boolean is_project.
763 function isProject() {
764 if ($this->getType()==1) {
772 * isPublic - Simply returns the is_public flag from the database.
774 * @return boolean is_public.
776 function isPublic() {
777 return $this->data_array['is_public'];
781 * isActive - Database field status of 'A' returns true.
783 * @return boolean is_active.
785 function isActive() {
786 if ($this->getStatus()=='A') {
794 * getUnixName - the unix_name
796 * @return string unix_name.
798 function getUnixName() {
799 return strtolower($this->data_array['unix_group_name']);
803 * getPublicName - the full-length public name.
805 * @return string The group_name.
807 function getPublicName() {
808 return $this->data_array['group_name'];
812 * getRegisterPurpose - the text description of the purpose of this project.
814 * @return string The description.
816 function getRegisterPurpose() {
817 return $this->data_array['register_purpose'];
821 * getDescription - the text description of this project.
823 * @return string The description.
825 function getDescription() {
826 return $this->data_array['short_description'];
830 * getStartDate - the unix time this project was registered.
832 * @return int (unix time) of registration.
834 function getStartDate() {
835 return $this->data_array['register_time'];
839 * getLogoImageID - the id of the logo in the database for this project.
841 * @return int The ID of logo image in db_images table (or 100 if none).
843 function getLogoImageID() {
844 return $this->data_array['logo_image_id'];
848 * getUnixBox - the hostname of the unix box where this project is located.
850 * @return string The name of the unix machine for the group.
852 function getUnixBox() {
853 return $this->data_array['unix_box'];
857 * getSCMBox - the hostname of the scm box where this project is located.
859 * @return string The name of the unix machine for the group.
861 function getSCMBox() {
862 return $this->data_array['scm_box'];
865 * setSCMBox - the hostname of the scm box where this project is located.
867 * @param string The name of the new SCM_BOX
869 function setSCMBox($scm_box) {
872 $res = db_query_params ('UPDATE groups SET scm_box=$1 WHERE group_id=$2', array ($scm_box, $this->getID ()));
874 $this->addHistory('scm_box', $this->data_array['scm_box']);
875 $this->data_array['scm_box']=$scm_box;
880 $this->setError(_("Couldn't insert SCM_BOX to database"));
884 $this->setError(_("SCM Box can't be empty"));
890 * getDomain - the hostname.domain where their web page is located.
892 * @return string The name of the group [web] domain.
894 function getDomain() {
895 return $this->data_array['http_domain'];
899 * getLicense - the license they chose.
901 * @return int ident of group license.
903 function getLicense() {
904 return $this->data_array['license'];
908 * getLicenseName - the name of the license
910 * @return string license name
912 function getLicenseName() {
913 $licenses =& group_get_licenses();
914 if(isset($licenses[$this->data_array['license']])) {
915 return $licenses[$this->data_array['license']];
922 * getLicenseOther - optional string describing license.
924 * @return string The custom license.
926 function getLicenseOther() {
927 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
928 return $this->data_array['license_other'];
935 * getRegistrationPurpose - the text description of the purpose of this project.
937 * @return string The application for project hosting.
939 function getRegistrationPurpose() {
940 return $this->data_array['register_purpose'];
945 * getAdmins() - Get array of Admin user objects.
947 * @return array Array of User objects.
949 function &getAdmins() {
950 // this function gets all group admins in order to send Jabber and mail messages
951 $res = db_query_params ('SELECT user_id FROM user_group WHERE admin_flags=$1 AND group_id=$2',
952 array ('A', $this->getID()));
953 $user_ids=util_result_column_to_array($res);
954 return user_get_objects($user_ids);
959 Common Group preferences for tools
964 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
966 * @return boolean enable_scm.
968 function enableAnonSCM() {
969 if ($this->isPublic() && $this->usesSCM()) {
970 return $this->data_array['enable_anonscm'];
976 function SetUsesAnonSCM ($booleanparam) {
978 $booleanparam = $booleanparam ? 1 : 0 ;
979 $res = db_query_params ('UPDATE groups SET enable_anonscm=$1 WHERE group_id=$2',
980 array ($booleanparam, $this->getID()));
982 $this->data_array['enable_anonscm']=$booleanparam;
991 * enablePserver - whether or not this group has opted to enable Pserver.
993 * @return boolean enable_pserver.
995 function enablePserver() {
996 if ($this->usesSCM()) {
997 return $this->data_array['enable_pserver'];
1003 function SetUsesPserver ($booleanparam) {
1005 $booleanparam = $booleanparam ? 1 : 0 ;
1006 $res = db_query_params ('UPDATE groups SET enable_pserver=$1 WHERE group_id=$2',
1007 array ($booleanparam, $this->getID()));
1009 $this->data_array['enable_pserver']=$booleanparam;
1018 * usesSCM - whether or not this group has opted to use SCM.
1020 * @return boolean uses_scm.
1022 function usesSCM() {
1023 global $sys_use_scm;
1025 return $this->data_array['use_scm'];
1032 * usesMail - whether or not this group has opted to use mailing lists.
1034 * @return boolean uses_mail.
1036 function usesMail() {
1037 global $sys_use_mail;
1038 if ($sys_use_mail) {
1039 return $this->data_array['use_mail'];
1046 * usesNews - whether or not this group has opted to use news.
1048 * @return boolean uses_news.
1050 function usesNews() {
1051 global $sys_use_news;
1052 if ($sys_use_news) {
1053 return $this->data_array['use_news'];
1060 * usesForum - whether or not this group has opted to use discussion forums.
1062 * @return boolean uses_forum.
1064 function usesForum() {
1065 global $sys_use_forum;
1066 if ($sys_use_forum) {
1067 return $this->data_array['use_forum'];
1074 * usesStats - whether or not this group has opted to use stats.
1076 * @return boolean uses_stats.
1078 function usesStats() {
1079 return $this->data_array['use_stats'];
1083 * usesFRS - whether or not this group has opted to use file release system.
1085 * @return boolean uses_frs.
1087 function usesFRS() {
1088 global $sys_use_frs;
1090 return $this->data_array['use_frs'];
1097 * usesTracker - whether or not this group has opted to use tracker.
1099 * @return boolean uses_tracker.
1101 function usesTracker() {
1102 global $sys_use_tracker;
1103 if ($sys_use_tracker) {
1104 return $this->data_array['use_tracker'];
1111 * usesDocman - whether or not this group has opted to use docman.
1113 * @return boolean uses_docman.
1115 function usesDocman() {
1116 global $sys_use_docman;
1117 if ($sys_use_docman) {
1118 return $this->data_array['use_docman'];
1125 * usesFTP - whether or not this group has opted to use FTP.
1127 * @return boolean uses_ftp.
1129 function usesFTP() {
1130 global $sys_use_ftp;
1132 return $this->data_array['use_ftp'];
1139 * usesSurvey - whether or not this group has opted to use surveys.
1141 * @return boolean uses_survey.
1143 function usesSurvey() {
1144 global $sys_use_survey;
1145 if ($sys_use_survey) {
1146 return $this->data_array['use_survey'];
1153 * usesPM - whether or not this group has opted to Project Manager.
1155 * @return boolean uses_projman.
1160 return $this->data_array['use_pm'];
1167 * getPlugins - get a list of all available group plugins
1169 * @return array array containing plugin_id => plugin_name
1171 function getPlugins() {
1172 if (!isset($this->plugins_data)) {
1173 $this->plugins_data = array () ;
1174 $res = db_query_params ('SELECT group_plugin.plugin_id, plugins.plugin_name
1175 FROM group_plugin, plugins
1176 WHERE group_plugin.group_id=$1
1177 AND group_plugin.plugin_id=plugins.plugin_id', array ($this->getID()));
1178 $rows = db_numrows($res);
1180 for ($i=0; $i<$rows; $i++) {
1181 $plugin_id = db_result($res,$i,'plugin_id');
1182 $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
1185 return $this->plugins_data ;
1189 * usesPlugin - returns true if the group uses a particular plugin
1191 * @param string name of the plugin
1192 * @return boolean whether plugin is being used or not
1194 function usesPlugin($pluginname) {
1195 $plugins_data = $this->getPlugins() ;
1196 foreach ($plugins_data as $p_id => $p_name) {
1197 if ($p_name == $pluginname) {
1205 * setPluginUse - enables/disables plugins for the group
1207 * @param string name of the plugin
1208 * @param boolean the new state
1209 * @return string database result
1211 function setPluginUse($pluginname, $val=true) {
1212 if ($val == $this->usesPlugin($pluginname)) {
1213 // State is already good, returning
1216 $res = db_query_params ('SELECT plugin_id FROM plugins WHERE plugin_name=$1',
1217 array ($pluginname));
1218 $rows = db_numrows($res);
1220 // Error: no plugin by that name
1223 $plugin_id = db_result($res,0,'plugin_id');
1225 unset ($this->plugins_data) ;
1227 $res = db_query_params ('INSERT INTO group_plugin (group_id, plugin_id) VALUES ($1, $2)',
1228 array ($this->getID(),
1232 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1 AND plugin_id=$2',
1233 array ($this->getID(),
1240 * getDocEmailAddress - get email address(es) to send doc notifications to.
1242 * @return string email address.
1244 function getDocEmailAddress() {
1245 return $this->data_array['new_doc_address'];
1249 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1251 * @return boolean email_on_all_doc_updates.
1253 function docEmailAll() {
1254 return $this->data_array['send_all_docs'];
1259 * getHomePage - The URL for this project's home page.
1261 * @return string homepage URL.
1263 function getHomePage() {
1264 return $this->data_array['homepage'];
1268 * getPermission - Return a Permission for this Group and the specified User.
1270 * @param object The user you wish to get permission for (usually the logged in user).
1271 * @return object The Permission.
1273 function &getPermission(&$_user) {
1274 return permission_get_object($this, $_user);
1279 * userIsAdmin - Return if for this Group the User is admin.
1281 * @return boolean is_admin.
1283 function userIsAdmin() {
1284 $perm =& $this->getPermission( session_get_user() );
1285 if (!$perm || !is_object($perm)) {
1287 } elseif ($perm->isError()) {
1290 return $perm->isAdmin();
1293 function delete($sure,$really_sure,$really_really_sure) {
1294 if (!$sure || !$really_sure || !$really_really_sure) {
1295 $this->setMissingParamsError();
1298 if ($this->getID() == $GLOBALS['sys_news_group'] ||
1299 $this->getID() == 1 ||
1300 $this->getID() == $GLOBALS['sys_stats_group'] ||
1301 $this->getID() == $GLOBALS['sys_peer_rating_group']) {
1302 $this->setError(_('Cannot Delete System Group'));
1305 $perm =& $this->getPermission( session_get_user() );
1306 if (!$perm || !is_object($perm)) {
1307 $this->setPermissionDeniedError();
1309 } elseif ($perm->isError()) {
1310 $this->setPermissionDeniedError();
1312 } elseif (!$perm->isSuperUser()) {
1313 $this->setPermissionDeniedError();
1319 // Remove all the members
1321 $members =& $this->getMembers();
1322 for ($i=0; $i<count($members); $i++) {
1323 $this->removeUser($members[$i]->getID());
1328 $atf = new ArtifactTypeFactory($this);
1329 $at_arr =& $atf->getArtifactTypes();
1330 for ($i=0; $i<count($at_arr); $i++) {
1331 if (!is_object($at_arr[$i])) {
1332 printf (_("Not Object: ArtifactType: %d"),$i);
1335 $at_arr[$i]->delete(1,1);
1340 $ff = new ForumFactory($this);
1341 $f_arr =& $ff->getForums();
1342 for ($i=0; $i<count($f_arr); $i++) {
1343 if (!is_object($f_arr[$i])) {
1344 printf (_("Not Object: Forum: %d"),$i);
1347 $f_arr[$i]->delete(1,1);
1348 //echo 'ForumFactory'.db_error();
1351 // Delete Subprojects
1353 $pgf = new ProjectGroupFactory($this);
1354 $pg_arr =& $pgf->getProjectGroups();
1355 for ($i=0; $i<count($pg_arr); $i++) {
1356 if (!is_object($pg_arr[$i])) {
1357 printf (_("Not Object: ProjectGroup: %d"),$i);
1360 $pg_arr[$i]->delete(1,1);
1361 //echo 'ProjectGroupFactory'.db_error();
1364 // Delete FRS Packages
1366 //$frspf = new FRSPackageFactory($this);
1367 $res = db_query_params ('SELECT * FROM frs_package WHERE group_id=$1',
1368 array ($this->getID())) ;
1369 //echo 'frs_package'.db_error();
1370 //$frsp_arr =& $frspf->getPackages();
1371 while ($arr = db_fetch_array($res)) {
1372 //if (!is_object($pg_arr[$i])) {
1373 // echo "Not Object: ProjectGroup: ".$i;
1376 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1382 $news_group=&group_get_object($GLOBALS['sys_news_group']);
1383 $res = db_query_params ('SELECT forum_id FROM news_bytes WHERE group_id=$1',
1384 array ($this->getID())) ;
1385 for ($i=0; $i<db_numrows($res); $i++) {
1386 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1387 if (!$Forum->delete(1,1)) {
1388 printf (_("Could Not Delete News Forum: %d"),$Forum->getID());
1391 $res = db_query_params ('DELETE FROM news_bytes WHERE group_id=$1',
1392 array ($this->getID())) ;
1397 $res = db_query_params ('DELETE FROM doc_data WHERE group_id=$1',
1398 array ($this->getID())) ;
1399 //echo 'doc_data'.db_error();
1400 $res = db_query_params ('DELETE FROM doc_groups WHERE group_id=$1',
1401 array ($this->getID())) ;
1402 //echo 'doc_groups'.db_error();
1404 // Delete group history
1406 $res = db_query_params ('DELETE FROM group_history WHERE group_id=$1',
1407 array ($this->getID())) ;
1408 //echo 'group_history'.db_error();
1410 // Delete group plugins
1412 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1',
1413 array ($this->getID())) ;
1414 //echo 'group_plugin'.db_error();
1416 // Delete group cvs stats
1418 $res = db_query_params ('DELETE FROM stats_cvs_group WHERE group_id=$1',
1419 array ($this->getID())) ;
1420 //echo 'stats_cvs_group'.db_error();
1424 $sf = new SurveyFactory($this);
1425 $s_arr =& $sf->getSurveys();
1426 for ($i=0; $i<count($s_arr); $i++) {
1427 if (!is_object($s_arr[$i])) {
1428 printf (_("Not Object: Survey: %d"),$i);
1431 $s_arr[$i]->delete();
1432 //echo 'SurveyFactory'.db_error();
1435 // Delete SurveyQuestions
1437 $sqf = new SurveyQuestionFactory($this);
1438 $sq_arr =& $sqf->getSurveyQuestions();
1439 for ($i=0; $i<count($sq_arr); $i++) {
1440 if (!is_object($sq_arr[$i])) {
1441 printf (_("Not Object: SurveyQuestion: %d"),$i);
1444 $sq_arr[$i]->delete();
1445 //echo 'SurveyQuestionFactory'.db_error();
1448 // Delete Mailing List Factory
1450 $mlf = new MailingListFactory($this);
1451 $ml_arr =& $mlf->getMailingLists();
1452 for ($i=0; $i<count($ml_arr); $i++) {
1453 if (!is_object($ml_arr[$i])) {
1454 printf (_("Not Object: MailingList: %d"),$i);
1457 if (!$ml_arr[$i]->delete(1,1)) {
1458 $this->setError(_('Could not properly delete the mailing list'));
1460 //echo 'MailingListFactory'.db_error();
1465 $res = db_query_params ('DELETE FROM trove_group_link WHERE group_id=$1',
1466 array ($this->getID())) ;
1467 $res = db_query_params ('DELETE FROM trove_agg WHERE group_id=$1',
1468 array ($this->getID())) ;
1472 $res = db_query_params ('DELETE FROM project_sums_agg WHERE group_id=$1',
1473 array ($this->getID())) ;
1474 //echo 'project_sums_agg'.db_error();
1475 $res = db_query_params ('INSERT INTO deleted_groups (unix_group_name,delete_date,isdeleted) VALUES ($1, $2, $3)',
1476 array ($this->getUnixName(),
1479 //echo 'InsertIntoDeleteQueue'.db_error();
1480 $res = db_query_params ('DELETE FROM groups WHERE group_id=$1',
1481 array ($this->getID())) ;
1482 //echo 'DeleteGroup'.db_error();
1488 $hook_params = array ();
1489 $hook_params['group'] = $this;
1490 $hook_params['group_id'] = $this->getID();
1491 plugin_hook ("group_delete", $hook_params);
1493 if (isset($GLOBALS['sys_upload_dir']) && $this->getUnixName()) {
1494 exec('/bin/rm -rf '.$GLOBALS['sys_upload_dir'].'/'.$this->getUnixName().'/');
1496 if (isset($GLOBALS['sys_ftp_upload_dir']) && $this->getUnixName()) {
1497 exec('/bin/rm -rf '.$GLOBALS['sys_ftp_upload_dir'].'/'.$this->getUnixName().'/');
1502 $res = db_query_params ('DELETE FROM rep_group_act_monthly WHERE group_id=$1',
1503 array ($this->getID())) ;
1504 //echo 'rep_group_act_monthly'.db_error();
1505 $res = db_query_params ('DELETE FROM rep_group_act_weekly WHERE group_id=$1',
1506 array ($this->getID())) ;
1507 //echo 'rep_group_act_weekly'.db_error();
1508 $res = db_query_params ('DELETE FROM rep_group_act_daily WHERE group_id=$1',
1509 array ($this->getID())) ;
1510 //echo 'rep_group_act_daily'.db_error();
1511 unset($this->data_array);
1519 Basic functions to add/remove users to/from a group
1520 and update their permissions
1526 * addUser - controls adding a user to a group.
1528 * @param string Unix name of the user to add OR integer user_id.
1529 * @param int The role_id this user should have.
1530 * @return boolean success.
1533 function addUser($user_identifier,$role_id) {
1536 Admins can add users to groups
1539 $perm =& $this->getPermission( session_get_user() );
1540 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1541 $this->setPermissionDeniedError();
1547 get user id for this user's unix_name
1549 if (is_int ($user_identifier)) { // user_id or user_name
1550 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array ($user_identifier)) ;
1552 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array ($user_identifier)) ;
1554 if (db_numrows($res_newuser) > 0) {
1556 // make sure user is active
1558 if (db_result($res_newuser,0,'status') != 'A') {
1559 $this->setError(_('User is not active. Only active users can be added.'));
1565 // user was found - set new user_id var
1567 $user_id = db_result($res_newuser,0,'user_id');
1570 // if not already a member, add them
1572 $res_member = db_query_params ('SELECT user_id
1574 WHERE user_id=$1 AND group_id=$2',
1575 array ($user_id, $this->getID())) ;
1577 if (db_numrows($res_member) < 1) {
1579 // Create this user's row in the user_group table
1581 $res = db_query_params ('INSERT INTO user_group
1582 (user_id,group_id,admin_flags,forum_flags,project_flags,
1583 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
1584 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)',
1596 //verify the insert worked
1597 if (!$res || db_affected_rows($res) < 1) {
1598 $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
1603 // check and create if group doesn't exists
1605 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
1606 if (!$SYS->sysCheckCreateGroup($this->getID())){
1607 $this->setError($SYS->getErrorMessage());
1612 // check and create if user doesn't exists
1614 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1615 if (!$SYS->sysCheckCreateUser($user_id)) {
1616 $this->setError($SYS->getErrorMessage());
1623 $role = new Role($this,$role_id);
1624 if (!$role || !is_object($role)) {
1625 $this->setError(_('Error Getting Role Object'));
1628 } elseif ($role->isError()) {
1629 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1633 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
1634 if (!$role->setUser($user_id)) {
1635 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1641 // user was already a member
1642 // make sure they are set up
1644 $user=&user_get_object($user_id,$res_newuser);
1645 $user->fetchData($user->getID());
1646 $role = new Role($this,$role_id);
1647 if (!$role || !is_object($role)) {
1648 $this->setError(_('Error Getting Role Object'));
1651 } elseif ($role->isError()) {
1652 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1656 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
1657 if (!$role->setUser($user_id)) {
1658 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1663 // set up their system info
1665 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1666 if (!$SYS->sysCheckCreateUser($user_id)) {
1667 $this->setError($SYS->getErrorMessage());
1676 // user doesn't exist
1678 $this->setError(_('ERROR: User does not exist'));
1683 $hook_params['group'] = $this;
1684 $hook_params['group_id'] = $this->getID();
1685 $hook_params['user'] = &user_get_object($user_id);
1686 $hook_params['user_id'] = $user_id;
1687 plugin_hook ("group_adduser", $hook_params);
1692 $this->addHistory('Added User',$user_identifier);
1698 * removeUser - controls removing a user from a group.
1700 * Users can remove themselves.
1702 * @param int The ID of the user to remove.
1703 * @return boolean success.
1705 function removeUser($user_id) {
1706 global $SYS,$sys_database_type;
1708 if ($user_id==user_getid()) {
1709 //users can remove themselves
1710 //everyone else must be a project admin
1712 $perm =& $this->getPermission( session_get_user() );
1714 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1715 $this->setPermissionDeniedError();
1721 $res = db_query_params ('DELETE FROM user_group WHERE group_id=$1 AND user_id=$2',
1722 array ($this->getID(),
1724 if (!$res || db_affected_rows($res) < 1) {
1725 $this->setError(sprintf(_('ERROR: User not removed: %s'),db_error()));
1730 // reassign open artifacts to id=100
1732 $res = db_query_params ('UPDATE artifact SET assigned_to=100
1733 WHERE group_artifact_id
1734 IN (SELECT group_artifact_id
1735 FROM artifact_group_list
1736 WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
1737 array ($this->getID(),
1740 $this->setError(sprintf(_('ERROR: DB: artifact: %s'),db_error()));
1746 // reassign open tasks to id=100
1747 // first have to purge any assignments that would cause
1748 // conflict with existing assignment to 100
1750 if ($sys_database_type == 'mysql') {
1752 SELECT pt.project_task_id
1753 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1754 WHERE pt.group_project_id = pgl.group_project_id
1755 AND pat.project_task_id=pt.project_task_id
1756 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."'
1757 AND pat.assigned_to_id='$user_id' INTO @task_list;
1758 DELETE FROM project_assigned_to WHERE project_task_id IN ( @task_list ) AND assigned_to_id='100'");
1760 $res = db_next_result();
1763 $res = db_query_params ('DELETE FROM project_assigned_to
1764 WHERE project_task_id IN (SELECT pt.project_task_id
1765 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1766 WHERE pt.group_project_id = pgl.group_project_id
1767 AND pat.project_task_id=pt.project_task_id
1768 AND pt.status_id=1 AND pgl.group_id=$1,
1769 AND pat.assigned_to_id=$2)
1770 AND assigned_to_id=100',
1771 array ($this->getID(),
1775 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),1,db_error()));
1779 $res = db_query_params ('UPDATE project_assigned_to SET assigned_to_id=100
1780 WHERE project_task_id IN (SELECT pt.project_task_id
1781 FROM project_task pt, project_group_list pgl
1782 WHERE pt.group_project_id = pgl.group_project_id
1783 AND pt.status_id=1 AND pgl.group_id=$1)
1784 AND assigned_to_id=$2',
1785 array ($this->getID(),
1788 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),2,db_error()));
1794 // Remove user from system
1796 //echo "<h2>Group::addUser SYS->sysGroupRemoveUser(".$this->getID().",$user_id)</h2>";
1797 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
1798 $this->setError($SYS->getErrorMessage());
1803 $this->addHistory('Removed User',$user_id);
1810 * updateUser - controls updating a user's role in this group.
1812 * @param int The ID of the user.
1813 * @param int The role_id to set this user to.
1814 * @return boolean success.
1816 function updateUser($user_id,$role_id) {
1819 $perm =& $this->getPermission( session_get_user() );
1820 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1821 $this->setPermissionDeniedError();
1825 $role = new Role($this,$role_id);
1826 if (!$role || !is_object($role)) {
1827 $this->setError(_('Could Not Get Role'));
1829 } elseif ($role->isError()) {
1830 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1833 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
1834 if (!$role->setUser($user_id)) {
1835 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1839 $hook_params['group'] = $this;
1840 $hook_params['group_id'] = $this->getID();
1841 $hook_params['user'] = &user_get_object($user_id);
1842 $hook_params['user_id'] = $user_id;
1843 plugin_hook ("group_removeuser", $hook_params);
1845 $this->addHistory('Updated User',$user_id);
1850 * addHistory - Makes an audit trail entry for this project.
1852 * @param string The name of the field.
1853 * @param string The Old Value for this $field_name.
1854 * @return database result handle.
1857 function addHistory($field_name, $old_value) {
1858 return db_query_params ('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
1859 VALUES ($1,$2,$3,$4,$5)',
1860 array ($this->getID(),
1868 * activateUsers - Make sure that group members have unix accounts.
1870 * Setup unix accounts for group members. Can be called even
1871 * if members are already active.
1875 function activateUsers() {
1878 Activate member(s) of the project
1881 $member_res = db_query_params ('SELECT user_id, role_id FROM user_group WHERE group_id=$1',
1882 array ($this->getID())) ;
1884 $rows = db_numrows($member_res);
1888 for ($i=0; $i<$rows; $i++) {
1890 $member =& user_get_object(db_result($member_res,$i,'user_id'));
1891 $roleId = db_result($member_res,$i,'role_id');
1893 if (!$member || !is_object($member)) {
1894 $this->setError(_('Error getting member object'));
1896 } else if ($member->isError()) {
1897 $this->setError(sprintf(_('Error getting member object: %s'),$member->getErrorMessage()));
1901 if (!$this->addUser($member->getUnixName(),$roleId)) {
1912 * getMembers - returns array of User objects for this project
1914 * @return array of User objects for this group.
1916 function &getMembers() {
1917 if (!isset($this->membersArr)) {
1918 $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',
1919 array ($this->getID())) ;
1920 while ($arr =& db_fetch_array($res)) {
1921 $this->membersArr[] =& new GFUser($arr['user_id'],$arr);
1924 return $this->membersArr;
1928 * approve - Approve pending project.
1930 * @param object The User object who is doing the updating.
1933 function approve(&$user) {
1935 if ($this->getStatus()=='A') {
1936 $this->setError(_("Group already active"));
1942 // Step 1: Activate group and create LDAP entries
1943 if (!$this->setStatus($user, 'A')) {
1948 // Switch to system language for item creation
1949 setup_gettext_from_sys_lang ();
1954 // Tracker Integration
1957 $ats = new ArtifactTypes($this);
1958 if (!$ats || !is_object($ats)) {
1959 $this->setError(_('Error creating ArtifactTypes object'));
1961 setup_gettext_from_context();
1963 } else if ($ats->isError()) {
1964 $this->setError(sprintf (_('ATS%d: %s'), 1, $ats->getErrorMessage()));
1966 setup_gettext_from_context();
1969 if (!$ats->createTrackers()) {
1970 $this->setError(sprintf (_('ATS%d: %s'), 2, $ats->getErrorMessage()));
1972 setup_gettext_from_context();
1978 // Forum Integration
1981 $f = new Forum($this);
1982 if (!$f->create(_('Open-Discussion'),_('General Discussion'),1,'',1,0)) {
1983 $this->setError(sprintf (_('F%d: %s'), 1, $f->getErrorMessage()));
1985 setup_gettext_from_context();
1988 $f = new Forum($this);
1989 if (!$f->create(_('Help'),_('Get Public Help'),1,'',1,0)) {
1990 $this->setError(sprintf (_('F%d: %s'), 2, $f->getErrorMessage()));
1992 setup_gettext_from_context();
1995 $f = new Forum($this);
1996 if (!$f->create(_('Developers'),_('Project Developer Discussion'),0,'',1,0)) {
1997 $this->setError(sprintf (_('F%d: %s'), 3, $f->getErrorMessage()));
1999 setup_gettext_from_context();
2005 // Doc Mgr Integration
2008 $dg = new DocumentGroup($this);
2009 if (!$dg->create(_('Uncategorized Submissions'))) {
2010 $this->setError(sprintf(_('DG: %s'),$dg->getErrorMessage()));
2012 setup_gettext_from_context();
2021 $frs = new FRSPackage($this);
2022 if (!$frs->create($this->getUnixName())) {
2023 $this->setError(sprintf(_('FRSP: %s'),$frs->getErrorMessage()));
2025 setup_gettext_from_context();
2034 $pg = new ProjectGroup($this);
2035 if (!$pg->create(_('To Do'),_('Things We Have To Do'),1)) {
2036 $this->setError(sprintf(_('PG%d: %s'),1,$pg->getErrorMessage()));
2038 setup_gettext_from_context();
2041 $pg = new ProjectGroup($this);
2042 if (!$pg->create(_('Next Release'),_('Items For Our Next Release'),1)) {
2043 $this->setError(sprintf(_('PG%d: %s'),2,$pg->getErrorMessage()));
2045 setup_gettext_from_context();
2051 // Set Default Roles
2054 $role = new Role($this);
2055 $todo = array_keys($role->defaults);
2056 for ($c=0; $c<count($todo); $c++) {
2057 $role = new Role($this);
2058 if (!$role->createDefault($todo[$c])) {
2059 $this->setError(sprintf(_('R%d: %s'),$c,$role->getErrorMessage()));
2061 setup_gettext_from_context();
2066 $admin_group = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1 AND admin_flags=$2',
2067 array ($this->getID(),
2069 if (db_numrows($admin_group) > 0) {
2070 $idadmin_group = db_result($admin_group,0,'user_id');
2077 // Create MailingList
2080 if ($GLOBALS['sys_use_mail']) {
2081 $mlist = new MailingList($this);
2082 if (!$mlist->create('commits',_('Commits'),1,$idadmin_group)) {
2083 $this->setError(sprintf(_('ML: %s'),$mlist->getErrorMessage()));
2085 setup_gettext_from_context();
2090 // Switch back to user preference
2091 setup_gettext_from_context();
2095 $this->sendApprovalEmail();
2096 $this->addHistory('Approved', 'x');
2099 //change assistant for webcal
2101 $params[0] = $idadmin_group ;
2102 $params[1] = $this->getID();
2103 plugin_hook('change_cal_permission_default',$params);
2111 * sendApprovalEmail - Send new project email.
2113 * @return boolean success.
2116 function sendApprovalEmail() {
2117 $res_admins = db_query_params ('
2118 SELECT users.user_name,users.email,users.language,users.user_id
2119 FROM users,user_group
2120 WHERE users.user_id=user_group.user_id
2121 AND user_group.group_id=$1
2122 AND user_group.admin_flags=$2',
2123 array ($this->getID(),
2126 if (db_numrows($res_admins) < 1) {
2127 $this->setError(_("Group does not have any administrators."));
2131 // send one email per admin
2132 while ($row_admins = db_fetch_array($res_admins)) {
2133 $admin =& user_get_object($row_admins['user_id']);
2134 setup_gettext_for_user ($admin) ;
2136 $message=stripcslashes(sprintf(_('Your project registration for %4$s has been approved.
2138 Project Full Name: %1$s
2139 Project Unix Name: %2$s
2141 Your DNS will take up to a day to become active on our site.
2142 Your web site is accessible through your shell account. Please read
2143 site documentation (see link below) about intended usage, available
2144 services, and directory layout of the account.
2147 own project page in %4$s while logged in, you will find
2148 additional menu functions to your left labeled \'Project Admin\'.
2150 We highly suggest that you now visit %4$s and create a public
2151 description for your project. This can be done by visiting your project
2152 page while logged in, and selecting \'Project Admin\' from the menus
2153 on the left (or by visiting %3$s
2156 Your project will also not appear in the Trove Software Map (primary
2157 list of projects hosted on %4$s which offers great flexibility in
2158 browsing and search) until you categorize it in the project administration
2159 screens. So that people can find your project, you should do this now.
2160 Visit your project while logged in, and select \'Project Admin\' from the
2163 Enjoy the system, and please tell others about %4$s. Let us know
2164 if there is anything we can do to help you.
2167 $this->getPublicName(),
2168 $this->getUnixName(),
2169 util_make_url ('/project/admin/?group_id='.$this->getID()),
2170 $GLOBALS['sys_name']));
2172 util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), $GLOBALS['sys_name']), $message);
2174 setup_gettext_from_context();
2182 * sendRejectionEmail - Send project rejection email.
2184 * This function sends out a rejection message to a user who
2185 * registered a project.
2187 * @param int The id of the response to use.
2188 * @param string The rejection message.
2189 * @return completion status.
2192 function sendRejectionEmail($response_id, $message="zxcv") {
2193 $res_admins = db_query_params ('
2194 SELECT u.email, u.language, u.user_id
2195 FROM users u, user_group ug
2196 WHERE ug.group_id=$1
2197 AND u.user_id=ug.user_id',
2198 array ($this->getID())) ;
2199 if (db_numrows($res_admins) < 1) {
2200 $this->setError(_("Group does not have any administrators."));
2204 while ($row_admins = db_fetch_array($res_admins)) {
2205 $admin =& user_get_object($row_admins['user_id']);
2206 setup_gettext_for_user ($admin) ;
2208 $response=stripcslashes(sprintf(_('Your project registration for %3$s has been denied.
2210 Project Full Name: %1$s
2211 Project Unix Name: %2$s
2213 Reasons for negative decision:
2215 '), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name']));
2217 // Check to see if they want to send a custom rejection response
2218 if ($response_id == 0) {
2219 $response .= stripcslashes($message);
2221 $response .= db_result (
2222 db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array ($response_id)),
2227 util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), $GLOBALS['sys_name']), $response);
2228 setup_gettext_from_context();
2235 * sendNewProjectNotificationEmail - Send new project notification email.
2237 * This function sends out a notification email to the
2238 * SourceForge admin user when a new project is
2241 * @return boolean success.
2244 function sendNewProjectNotificationEmail() {
2245 // Get the user who wants to register the project
2246 $res = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1',
2247 array ($this->getID())) ;
2249 if (db_numrows($res) < 1) {
2250 $this->setError(_("Could not find user who has submitted the project."));
2254 $submitter =& user_get_object(db_result($res,0,'user_id'));
2257 $res = db_query_params ('SELECT users.email, users.language, users.user_id
2258 FROM users, user_group
2260 AND user_group.admin_flags=$1
2261 AND users.user_id=user_group.user_id',
2264 if (db_numrows($res) < 1) {
2265 $this->setError(_("There is no administrator to send the mail."));
2269 for ($i=0; $i<db_numrows($res) ; $i++) {
2270 $admin_email = db_result($res,$i,'email') ;
2271 $admin =& user_get_object(db_result($res,$i,'user_id'));
2272 setup_gettext_for_user ($admin) ;
2274 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2276 Project Full Name: %2$s
2277 Submitted Description: %3$s
2279 Submitter: %6$s (%7$s)
2281 Please visit the following URL to approve or reject this project:
2283 $GLOBALS['sys_name'],
2284 $this->getPublicName(),
2285 util_unconvert_htmlspecialchars($this->getRegistrationPurpose()),
2286 $this->getLicenseName(),
2287 util_make_url ('/admin/approve-pending.php'),
2288 $submitter->getRealName(),
2289 $submitter->getUnixName()));
2290 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2291 setup_gettext_from_context();
2295 $email = $submitter->getEmail() ;
2296 setup_gettext_for_user ($submitter) ;
2298 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2300 Project Full Name: %2$s
2301 Submitted Description: %3$s
2304 The %1$s admin team will now examine your project submission. You will be notified of their decision.'), $GLOBALS['sys_name'], $this->getPublicName(), util_unconvert_htmlspecialchars($this->getRegistrationPurpose()), $this->getLicenseName(), $GLOBALS['sys_default_domain']));
2306 util_send_message($email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2307 setup_gettext_from_context();
2316 * validateGroupName - Validate the group name
2318 * @param string Group name.
2320 * @return an error false and set an error is the group name is invalide otherwise return true
2322 function validateGroupName($group_name) {
2323 if (strlen($group_name)<3) {
2324 $this->setError(_('Group name is too short'));
2326 } else if (strlen(htmlspecialchars($group_name))>50) {
2327 $this->setError(_('Group name is too long'));
2329 } else if ($group=group_get_object_by_publicname($group_name)) {
2330 $this->setError(_('Group name already taken'));
2342 * group_getname() - get the group name
2344 * @param int The group ID
2348 function group_getname ($group_id = 0) {
2349 $grp = &group_get_object($group_id);
2351 return $grp->getPublicName();
2358 * group_getunixname() - get the unixname for a group
2360 * @param int The group ID
2364 function group_getunixname ($group_id) {
2365 $grp = &group_get_object($group_id);
2367 return $grp->getUnixName();
2374 * group_get_result() - Get the group object result ID.
2376 * @param int The group ID
2380 function &group_get_result($group_id=0) {
2381 $grp = &group_get_object($group_id);
2383 return $grp->getData();
2390 * getUnixStatus - Status of activation of unix account.
2392 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2394 function getUnixStatus() {
2395 return $this->data_array['unix_status'];
2399 * setUnixStatus - Sets status of activation of unix account.
2401 * @param string The unix status.
2407 * @return boolean success.
2409 function setUnixStatus($status) {
2412 $res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
2417 $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
2421 if ($status == 'A') {
2422 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2423 $this->setError($SYS->getErrorMessage());
2428 if ($SYS->sysCheckGroup($this->getID())) {
2429 if (!$SYS->sysRemoveGroup($this->getID())) {
2430 $this->setError($SYS->getErrorMessage());
2437 $this->data_array['unix_status']=$status;
2445 // c-file-style: "bsd"