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->getPublicName() != $group_name) {
508 if (!$this->validateGroupName($group_name)) {
513 if ($new_doc_address) {
514 $invalid_mails = validate_emails($new_doc_address);
515 if (count($invalid_mails) > 0) {
516 $this->setError(sprintf (ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
521 // in the database, these all default to '1',
522 // so we have to explicity set 0
535 if (!$use_pm_depend_box) {
536 $use_pm_depend_box=0;
559 if (!$send_all_docs) {
564 $homepage=$GLOBALS['sys_default_domain'].'/projects/'.$this->getUnixName().'/';
567 if (strlen(htmlspecialchars($short_description))>255) {
568 $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
574 //XXX not yet actived logo_image_id='$logo_image_id',
575 $res = db_query_params ('UPDATE groups
578 short_description=$3,
583 use_pm_depend_box=$8,
595 array (htmlspecialchars($group_name),
597 htmlspecialchars($short_description),
616 $this->setError(sprintf(_('Error updating project information: %s'), db_error()));
621 $hook_params = array ();
622 $hook_params['group'] = $this;
623 $hook_params['group_id'] = $this->getID();
624 $hook_params['group_homepage'] = $homepage;
625 $hook_params['group_name'] = htmlspecialchars($group_name);
626 $hook_params['group_description'] = htmlspecialchars($short_description);
627 plugin_hook ("group_update", $hook_params);
629 // Log the audit trail
630 $this->addHistory('Changed Public Info', '');
632 if (!$this->fetchData($this->getID())) {
641 * getID - Simply return the group_id for this object.
643 * @return int group_id.
646 return $this->data_array['group_id'];
650 * getType() - Foundry, project, etc.
652 * @return int The type flag from the database.
655 return $this->data_array['type_id'];
660 * getStatus - the status code.
662 * Statuses char include I,H,A,D.
664 function getStatus() {
665 return $this->data_array['status'];
669 * setStatus - set the status code.
671 * Statuses include I,H,A,D.
673 * @param object User requesting operation (for access control).
674 * @param string Status value.
675 * @return boolean success.
678 function setStatus(&$user, $status) {
681 $perm =& $this->getPermission($user);
682 if (!$perm || !is_object($perm)) {
683 $this->setPermissionDeniedError();
685 } elseif (!$perm->isSuperUser()) {
686 $this->setPermissionDeniedError();
690 // Projects in 'A' status can only go to 'H' or 'D'
691 // Projects in 'D' status can only go to 'A'
692 // Projects in 'P' status can only go to 'A' OR 'D'
693 // Projects in 'I' status can only go to 'P'
694 // Projects in 'H' status can only go to 'A' OR 'D'
695 $allowed_status_changes = array(
696 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
697 'IP'=>1,'HA'=>1,'HD'=>1
700 // Check that status transition is valid
701 if ($this->getStatus() != $status
702 && !$allowed_status_changes[$this->getStatus().$status]) {
703 $this->setError(_('Invalid Status Change'));
709 $res = db_query_params ('UPDATE groups
711 WHERE group_id=$2', array ($status, $this->getID())) ;
713 if (!$res || db_affected_rows($res) < 1) {
714 $this->setError(sprintf(_('ERROR: DB: Could not change group status: %s'),db_error()));
720 // Activate system group, if not yet
721 if (!$SYS->sysCheckGroup($this->getID())) {
722 if (!$SYS->sysCreateGroup($this->getID())) {
723 $this->setError($SYS->getErrorMessage());
728 if (!$this->activateUsers()) {
733 /* Otherwise, the group is not active, and make sure that
734 System group is not active either */
735 } else if ($SYS->sysCheckGroup($this->getID())) {
736 if (!$SYS->sysRemoveGroup($this->getID())) {
737 $this->setError($SYS->getErrorMessage());
743 $hook_params = array ();
744 $hook_params['group'] = $this;
745 $hook_params['group_id'] = $this->getID();
746 $hook_params['status'] = $status;
747 plugin_hook ("group_setstatus", $hook_params);
751 // Log the audit trail
752 if ($status != $this->getStatus()) {
753 $this->addHistory('Status', $this->getStatus());
756 $this->data_array['status'] = $status;
761 * isProject - Simple boolean test to see if it's a project or not.
763 * @return boolean is_project.
765 function isProject() {
766 if ($this->getType()==1) {
774 * isPublic - Simply returns the is_public flag from the database.
776 * @return boolean is_public.
778 function isPublic() {
779 return $this->data_array['is_public'];
783 * isActive - Database field status of 'A' returns true.
785 * @return boolean is_active.
787 function isActive() {
788 if ($this->getStatus()=='A') {
796 * getUnixName - the unix_name
798 * @return string unix_name.
800 function getUnixName() {
801 return strtolower($this->data_array['unix_group_name']);
805 * getPublicName - the full-length public name.
807 * @return string The group_name.
809 function getPublicName() {
810 return $this->data_array['group_name'];
814 * getRegisterPurpose - the text description of the purpose of this project.
816 * @return string The description.
818 function getRegisterPurpose() {
819 return $this->data_array['register_purpose'];
823 * getDescription - the text description of this project.
825 * @return string The description.
827 function getDescription() {
828 return $this->data_array['short_description'];
832 * getStartDate - the unix time this project was registered.
834 * @return int (unix time) of registration.
836 function getStartDate() {
837 return $this->data_array['register_time'];
841 * getLogoImageID - the id of the logo in the database for this project.
843 * @return int The ID of logo image in db_images table (or 100 if none).
845 function getLogoImageID() {
846 return $this->data_array['logo_image_id'];
850 * getUnixBox - the hostname of the unix box where this project is located.
852 * @return string The name of the unix machine for the group.
854 function getUnixBox() {
855 return $this->data_array['unix_box'];
859 * getSCMBox - the hostname of the scm box where this project is located.
861 * @return string The name of the unix machine for the group.
863 function getSCMBox() {
864 return $this->data_array['scm_box'];
867 * setSCMBox - the hostname of the scm box where this project is located.
869 * @param string The name of the new SCM_BOX
871 function setSCMBox($scm_box) {
874 $res = db_query_params ('UPDATE groups SET scm_box=$1 WHERE group_id=$2', array ($scm_box, $this->getID ()));
876 $this->addHistory('scm_box', $this->data_array['scm_box']);
877 $this->data_array['scm_box']=$scm_box;
882 $this->setError(_("Couldn't insert SCM_BOX to database"));
886 $this->setError(_("SCM Box can't be empty"));
892 * getDomain - the hostname.domain where their web page is located.
894 * @return string The name of the group [web] domain.
896 function getDomain() {
897 return $this->data_array['http_domain'];
901 * getLicense - the license they chose.
903 * @return int ident of group license.
905 function getLicense() {
906 return $this->data_array['license'];
910 * getLicenseName - the name of the license
912 * @return string license name
914 function getLicenseName() {
915 $licenses =& group_get_licenses();
916 if(isset($licenses[$this->data_array['license']])) {
917 return $licenses[$this->data_array['license']];
924 * getLicenseOther - optional string describing license.
926 * @return string The custom license.
928 function getLicenseOther() {
929 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
930 return $this->data_array['license_other'];
937 * getRegistrationPurpose - the text description of the purpose of this project.
939 * @return string The application for project hosting.
941 function getRegistrationPurpose() {
942 return $this->data_array['register_purpose'];
947 * getAdmins() - Get array of Admin user objects.
949 * @return array Array of User objects.
951 function &getAdmins() {
952 // this function gets all group admins in order to send Jabber and mail messages
953 $res = db_query_params ('SELECT user_id FROM user_group WHERE admin_flags=$1 AND group_id=$2',
954 array ('A', $this->getID()));
955 $user_ids=util_result_column_to_array($res);
956 return user_get_objects($user_ids);
961 Common Group preferences for tools
966 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
968 * @return boolean enable_scm.
970 function enableAnonSCM() {
971 if ($this->isPublic() && $this->usesSCM()) {
972 return $this->data_array['enable_anonscm'];
978 function SetUsesAnonSCM ($booleanparam) {
980 $booleanparam = $booleanparam ? 1 : 0 ;
981 $res = db_query_params ('UPDATE groups SET enable_anonscm=$1 WHERE group_id=$2',
982 array ($booleanparam, $this->getID()));
984 $this->data_array['enable_anonscm']=$booleanparam;
993 * enablePserver - whether or not this group has opted to enable Pserver.
995 * @return boolean enable_pserver.
997 function enablePserver() {
998 if ($this->usesSCM()) {
999 return $this->data_array['enable_pserver'];
1005 function SetUsesPserver ($booleanparam) {
1007 $booleanparam = $booleanparam ? 1 : 0 ;
1008 $res = db_query_params ('UPDATE groups SET enable_pserver=$1 WHERE group_id=$2',
1009 array ($booleanparam, $this->getID()));
1011 $this->data_array['enable_pserver']=$booleanparam;
1020 * usesSCM - whether or not this group has opted to use SCM.
1022 * @return boolean uses_scm.
1024 function usesSCM() {
1025 global $sys_use_scm;
1027 return $this->data_array['use_scm'];
1034 * usesMail - whether or not this group has opted to use mailing lists.
1036 * @return boolean uses_mail.
1038 function usesMail() {
1039 global $sys_use_mail;
1040 if ($sys_use_mail) {
1041 return $this->data_array['use_mail'];
1048 * usesNews - whether or not this group has opted to use news.
1050 * @return boolean uses_news.
1052 function usesNews() {
1053 global $sys_use_news;
1054 if ($sys_use_news) {
1055 return $this->data_array['use_news'];
1062 * usesForum - whether or not this group has opted to use discussion forums.
1064 * @return boolean uses_forum.
1066 function usesForum() {
1067 global $sys_use_forum;
1068 if ($sys_use_forum) {
1069 return $this->data_array['use_forum'];
1076 * usesStats - whether or not this group has opted to use stats.
1078 * @return boolean uses_stats.
1080 function usesStats() {
1081 return $this->data_array['use_stats'];
1085 * usesFRS - whether or not this group has opted to use file release system.
1087 * @return boolean uses_frs.
1089 function usesFRS() {
1090 global $sys_use_frs;
1092 return $this->data_array['use_frs'];
1099 * usesTracker - whether or not this group has opted to use tracker.
1101 * @return boolean uses_tracker.
1103 function usesTracker() {
1104 global $sys_use_tracker;
1105 if ($sys_use_tracker) {
1106 return $this->data_array['use_tracker'];
1113 * usesDocman - whether or not this group has opted to use docman.
1115 * @return boolean uses_docman.
1117 function usesDocman() {
1118 global $sys_use_docman;
1119 if ($sys_use_docman) {
1120 return $this->data_array['use_docman'];
1127 * usesFTP - whether or not this group has opted to use FTP.
1129 * @return boolean uses_ftp.
1131 function usesFTP() {
1132 global $sys_use_ftp;
1134 return $this->data_array['use_ftp'];
1141 * usesSurvey - whether or not this group has opted to use surveys.
1143 * @return boolean uses_survey.
1145 function usesSurvey() {
1146 global $sys_use_survey;
1147 if ($sys_use_survey) {
1148 return $this->data_array['use_survey'];
1155 * usesPM - whether or not this group has opted to Project Manager.
1157 * @return boolean uses_projman.
1162 return $this->data_array['use_pm'];
1169 * getPlugins - get a list of all available group plugins
1171 * @return array array containing plugin_id => plugin_name
1173 function getPlugins() {
1174 if (!isset($this->plugins_data)) {
1175 $this->plugins_data = array () ;
1176 $res = db_query_params ('SELECT group_plugin.plugin_id, plugins.plugin_name
1177 FROM group_plugin, plugins
1178 WHERE group_plugin.group_id=$1
1179 AND group_plugin.plugin_id=plugins.plugin_id', array ($this->getID()));
1180 $rows = db_numrows($res);
1182 for ($i=0; $i<$rows; $i++) {
1183 $plugin_id = db_result($res,$i,'plugin_id');
1184 $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
1187 return $this->plugins_data ;
1191 * usesPlugin - returns true if the group uses a particular plugin
1193 * @param string name of the plugin
1194 * @return boolean whether plugin is being used or not
1196 function usesPlugin($pluginname) {
1197 $plugins_data = $this->getPlugins() ;
1198 foreach ($plugins_data as $p_id => $p_name) {
1199 if ($p_name == $pluginname) {
1207 * setPluginUse - enables/disables plugins for the group
1209 * @param string name of the plugin
1210 * @param boolean the new state
1211 * @return string database result
1213 function setPluginUse($pluginname, $val=true) {
1214 if ($val == $this->usesPlugin($pluginname)) {
1215 // State is already good, returning
1218 $res = db_query_params ('SELECT plugin_id FROM plugins WHERE plugin_name=$1',
1219 array ($pluginname));
1220 $rows = db_numrows($res);
1222 // Error: no plugin by that name
1225 $plugin_id = db_result($res,0,'plugin_id');
1227 unset ($this->plugins_data) ;
1229 $res = db_query_params ('INSERT INTO group_plugin (group_id, plugin_id) VALUES ($1, $2)',
1230 array ($this->getID(),
1234 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1 AND plugin_id=$2',
1235 array ($this->getID(),
1242 * getDocEmailAddress - get email address(es) to send doc notifications to.
1244 * @return string email address.
1246 function getDocEmailAddress() {
1247 return $this->data_array['new_doc_address'];
1251 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1253 * @return boolean email_on_all_doc_updates.
1255 function docEmailAll() {
1256 return $this->data_array['send_all_docs'];
1261 * getHomePage - The URL for this project's home page.
1263 * @return string homepage URL.
1265 function getHomePage() {
1266 return $this->data_array['homepage'];
1270 * getPermission - Return a Permission for this Group and the specified User.
1272 * @param object The user you wish to get permission for (usually the logged in user).
1273 * @return object The Permission.
1275 function &getPermission(&$_user) {
1276 return permission_get_object($this, $_user);
1281 * userIsAdmin - Return if for this Group the User is admin.
1283 * @return boolean is_admin.
1285 function userIsAdmin() {
1286 $perm =& $this->getPermission( session_get_user() );
1287 if (!$perm || !is_object($perm)) {
1289 } elseif ($perm->isError()) {
1292 return $perm->isAdmin();
1295 function delete($sure,$really_sure,$really_really_sure) {
1296 if (!$sure || !$really_sure || !$really_really_sure) {
1297 $this->setMissingParamsError();
1300 if ($this->getID() == $GLOBALS['sys_news_group'] ||
1301 $this->getID() == 1 ||
1302 $this->getID() == $GLOBALS['sys_stats_group'] ||
1303 $this->getID() == $GLOBALS['sys_peer_rating_group']) {
1304 $this->setError(_('Cannot Delete System Group'));
1307 $perm =& $this->getPermission( session_get_user() );
1308 if (!$perm || !is_object($perm)) {
1309 $this->setPermissionDeniedError();
1311 } elseif ($perm->isError()) {
1312 $this->setPermissionDeniedError();
1314 } elseif (!$perm->isSuperUser()) {
1315 $this->setPermissionDeniedError();
1321 // Remove all the members
1323 $members =& $this->getMembers();
1324 for ($i=0; $i<count($members); $i++) {
1325 $this->removeUser($members[$i]->getID());
1330 $atf = new ArtifactTypeFactory($this);
1331 $at_arr =& $atf->getArtifactTypes();
1332 for ($i=0; $i<count($at_arr); $i++) {
1333 if (!is_object($at_arr[$i])) {
1334 printf (_("Not Object: ArtifactType: %d"),$i);
1337 $at_arr[$i]->delete(1,1);
1342 $ff = new ForumFactory($this);
1343 $f_arr =& $ff->getForums();
1344 for ($i=0; $i<count($f_arr); $i++) {
1345 if (!is_object($f_arr[$i])) {
1346 printf (_("Not Object: Forum: %d"),$i);
1349 $f_arr[$i]->delete(1,1);
1350 //echo 'ForumFactory'.db_error();
1353 // Delete Subprojects
1355 $pgf = new ProjectGroupFactory($this);
1356 $pg_arr =& $pgf->getProjectGroups();
1357 for ($i=0; $i<count($pg_arr); $i++) {
1358 if (!is_object($pg_arr[$i])) {
1359 printf (_("Not Object: ProjectGroup: %d"),$i);
1362 $pg_arr[$i]->delete(1,1);
1363 //echo 'ProjectGroupFactory'.db_error();
1366 // Delete FRS Packages
1368 //$frspf = new FRSPackageFactory($this);
1369 $res = db_query_params ('SELECT * FROM frs_package WHERE group_id=$1',
1370 array ($this->getID())) ;
1371 //echo 'frs_package'.db_error();
1372 //$frsp_arr =& $frspf->getPackages();
1373 while ($arr = db_fetch_array($res)) {
1374 //if (!is_object($pg_arr[$i])) {
1375 // echo "Not Object: ProjectGroup: ".$i;
1378 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1384 $news_group=&group_get_object($GLOBALS['sys_news_group']);
1385 $res = db_query_params ('SELECT forum_id FROM news_bytes WHERE group_id=$1',
1386 array ($this->getID())) ;
1387 for ($i=0; $i<db_numrows($res); $i++) {
1388 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1389 if (!$Forum->delete(1,1)) {
1390 printf (_("Could Not Delete News Forum: %d"),$Forum->getID());
1393 $res = db_query_params ('DELETE FROM news_bytes WHERE group_id=$1',
1394 array ($this->getID())) ;
1399 $res = db_query_params ('DELETE FROM doc_data WHERE group_id=$1',
1400 array ($this->getID())) ;
1401 //echo 'doc_data'.db_error();
1402 $res = db_query_params ('DELETE FROM doc_groups WHERE group_id=$1',
1403 array ($this->getID())) ;
1404 //echo 'doc_groups'.db_error();
1406 // Delete group history
1408 $res = db_query_params ('DELETE FROM group_history WHERE group_id=$1',
1409 array ($this->getID())) ;
1410 //echo 'group_history'.db_error();
1412 // Delete group plugins
1414 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1',
1415 array ($this->getID())) ;
1416 //echo 'group_plugin'.db_error();
1418 // Delete group cvs stats
1420 $res = db_query_params ('DELETE FROM stats_cvs_group WHERE group_id=$1',
1421 array ($this->getID())) ;
1422 //echo 'stats_cvs_group'.db_error();
1426 $sf = new SurveyFactory($this);
1427 $s_arr =& $sf->getSurveys();
1428 for ($i=0; $i<count($s_arr); $i++) {
1429 if (!is_object($s_arr[$i])) {
1430 printf (_("Not Object: Survey: %d"),$i);
1433 $s_arr[$i]->delete();
1434 //echo 'SurveyFactory'.db_error();
1437 // Delete SurveyQuestions
1439 $sqf = new SurveyQuestionFactory($this);
1440 $sq_arr =& $sqf->getSurveyQuestions();
1441 for ($i=0; $i<count($sq_arr); $i++) {
1442 if (!is_object($sq_arr[$i])) {
1443 printf (_("Not Object: SurveyQuestion: %d"),$i);
1446 $sq_arr[$i]->delete();
1447 //echo 'SurveyQuestionFactory'.db_error();
1450 // Delete Mailing List Factory
1452 $mlf = new MailingListFactory($this);
1453 $ml_arr =& $mlf->getMailingLists();
1454 for ($i=0; $i<count($ml_arr); $i++) {
1455 if (!is_object($ml_arr[$i])) {
1456 printf (_("Not Object: MailingList: %d"),$i);
1459 if (!$ml_arr[$i]->delete(1,1)) {
1460 $this->setError(_('Could not properly delete the mailing list'));
1462 //echo 'MailingListFactory'.db_error();
1467 $res = db_query_params ('DELETE FROM trove_group_link WHERE group_id=$1',
1468 array ($this->getID())) ;
1469 $res = db_query_params ('DELETE FROM trove_agg WHERE group_id=$1',
1470 array ($this->getID())) ;
1474 $res = db_query_params ('DELETE FROM project_sums_agg WHERE group_id=$1',
1475 array ($this->getID())) ;
1476 //echo 'project_sums_agg'.db_error();
1477 $res = db_query_params ('INSERT INTO deleted_groups (unix_group_name,delete_date,isdeleted) VALUES ($1, $2, $3)',
1478 array ($this->getUnixName(),
1481 //echo 'InsertIntoDeleteQueue'.db_error();
1482 $res = db_query_params ('DELETE FROM groups WHERE group_id=$1',
1483 array ($this->getID())) ;
1484 //echo 'DeleteGroup'.db_error();
1490 $hook_params = array ();
1491 $hook_params['group'] = $this;
1492 $hook_params['group_id'] = $this->getID();
1493 plugin_hook ("group_delete", $hook_params);
1495 if (isset($GLOBALS['sys_upload_dir']) && $this->getUnixName()) {
1496 exec('/bin/rm -rf '.$GLOBALS['sys_upload_dir'].'/'.$this->getUnixName().'/');
1498 if (isset($GLOBALS['sys_ftp_upload_dir']) && $this->getUnixName()) {
1499 exec('/bin/rm -rf '.$GLOBALS['sys_ftp_upload_dir'].'/'.$this->getUnixName().'/');
1504 $res = db_query_params ('DELETE FROM rep_group_act_monthly WHERE group_id=$1',
1505 array ($this->getID())) ;
1506 //echo 'rep_group_act_monthly'.db_error();
1507 $res = db_query_params ('DELETE FROM rep_group_act_weekly WHERE group_id=$1',
1508 array ($this->getID())) ;
1509 //echo 'rep_group_act_weekly'.db_error();
1510 $res = db_query_params ('DELETE FROM rep_group_act_daily WHERE group_id=$1',
1511 array ($this->getID())) ;
1512 //echo 'rep_group_act_daily'.db_error();
1513 unset($this->data_array);
1521 Basic functions to add/remove users to/from a group
1522 and update their permissions
1528 * addUser - controls adding a user to a group.
1530 * @param string Unix name of the user to add OR integer user_id.
1531 * @param int The role_id this user should have.
1532 * @return boolean success.
1535 function addUser($user_identifier,$role_id) {
1538 Admins can add users to groups
1541 $perm =& $this->getPermission( session_get_user() );
1542 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1543 $this->setPermissionDeniedError();
1549 get user id for this user's unix_name
1551 if (is_int ($user_identifier)) { // user_id or user_name
1552 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array ($user_identifier)) ;
1554 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array ($user_identifier)) ;
1556 if (db_numrows($res_newuser) > 0) {
1558 // make sure user is active
1560 if (db_result($res_newuser,0,'status') != 'A') {
1561 $this->setError(_('User is not active. Only active users can be added.'));
1567 // user was found - set new user_id var
1569 $user_id = db_result($res_newuser,0,'user_id');
1572 // if not already a member, add them
1574 $res_member = db_query_params ('SELECT user_id
1576 WHERE user_id=$1 AND group_id=$2',
1577 array ($user_id, $this->getID())) ;
1579 if (db_numrows($res_member) < 1) {
1581 // Create this user's row in the user_group table
1583 $res = db_query_params ('INSERT INTO user_group
1584 (user_id,group_id,admin_flags,forum_flags,project_flags,
1585 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
1586 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)',
1598 //verify the insert worked
1599 if (!$res || db_affected_rows($res) < 1) {
1600 $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
1605 // check and create if group doesn't exists
1607 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
1608 if (!$SYS->sysCheckCreateGroup($this->getID())){
1609 $this->setError($SYS->getErrorMessage());
1614 // check and create if user doesn't exists
1616 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1617 if (!$SYS->sysCheckCreateUser($user_id)) {
1618 $this->setError($SYS->getErrorMessage());
1625 $role = new Role($this,$role_id);
1626 if (!$role || !is_object($role)) {
1627 $this->setError(_('Error Getting Role Object'));
1630 } elseif ($role->isError()) {
1631 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1635 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
1636 if (!$role->setUser($user_id)) {
1637 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1643 // user was already a member
1644 // make sure they are set up
1646 $user=&user_get_object($user_id,$res_newuser);
1647 $user->fetchData($user->getID());
1648 $role = new Role($this,$role_id);
1649 if (!$role || !is_object($role)) {
1650 $this->setError(_('Error Getting Role Object'));
1653 } elseif ($role->isError()) {
1654 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1658 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
1659 if (!$role->setUser($user_id)) {
1660 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1665 // set up their system info
1667 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1668 if (!$SYS->sysCheckCreateUser($user_id)) {
1669 $this->setError($SYS->getErrorMessage());
1678 // user doesn't exist
1680 $this->setError(_('ERROR: User does not exist'));
1685 $hook_params['group'] = $this;
1686 $hook_params['group_id'] = $this->getID();
1687 $hook_params['user'] = &user_get_object($user_id);
1688 $hook_params['user_id'] = $user_id;
1689 plugin_hook ("group_adduser", $hook_params);
1694 $this->addHistory('Added User',$user_identifier);
1700 * removeUser - controls removing a user from a group.
1702 * Users can remove themselves.
1704 * @param int The ID of the user to remove.
1705 * @return boolean success.
1707 function removeUser($user_id) {
1708 global $SYS,$sys_database_type;
1710 if ($user_id==user_getid()) {
1711 //users can remove themselves
1712 //everyone else must be a project admin
1714 $perm =& $this->getPermission( session_get_user() );
1716 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1717 $this->setPermissionDeniedError();
1723 $res = db_query_params ('DELETE FROM user_group WHERE group_id=$1 AND user_id=$2',
1724 array ($this->getID(),
1726 if (!$res || db_affected_rows($res) < 1) {
1727 $this->setError(sprintf(_('ERROR: User not removed: %s'),db_error()));
1732 // reassign open artifacts to id=100
1734 $res = db_query_params ('UPDATE artifact SET assigned_to=100
1735 WHERE group_artifact_id
1736 IN (SELECT group_artifact_id
1737 FROM artifact_group_list
1738 WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
1739 array ($this->getID(),
1742 $this->setError(sprintf(_('ERROR: DB: artifact: %s'),db_error()));
1748 // reassign open tasks to id=100
1749 // first have to purge any assignments that would cause
1750 // conflict with existing assignment to 100
1752 if ($sys_database_type == 'mysql') {
1754 SELECT pt.project_task_id
1755 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1756 WHERE pt.group_project_id = pgl.group_project_id
1757 AND pat.project_task_id=pt.project_task_id
1758 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."'
1759 AND pat.assigned_to_id='$user_id' INTO @task_list;
1760 DELETE FROM project_assigned_to WHERE project_task_id IN ( @task_list ) AND assigned_to_id='100'");
1762 $res = db_next_result();
1765 $res = db_query_params ('DELETE FROM project_assigned_to
1766 WHERE project_task_id IN (SELECT pt.project_task_id
1767 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1768 WHERE pt.group_project_id = pgl.group_project_id
1769 AND pat.project_task_id=pt.project_task_id
1770 AND pt.status_id=1 AND pgl.group_id=$1,
1771 AND pat.assigned_to_id=$2)
1772 AND assigned_to_id=100',
1773 array ($this->getID(),
1777 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),1,db_error()));
1781 $res = db_query_params ('UPDATE project_assigned_to SET assigned_to_id=100
1782 WHERE project_task_id IN (SELECT pt.project_task_id
1783 FROM project_task pt, project_group_list pgl
1784 WHERE pt.group_project_id = pgl.group_project_id
1785 AND pt.status_id=1 AND pgl.group_id=$1)
1786 AND assigned_to_id=$2',
1787 array ($this->getID(),
1790 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),2,db_error()));
1796 // Remove user from system
1798 //echo "<h2>Group::addUser SYS->sysGroupRemoveUser(".$this->getID().",$user_id)</h2>";
1799 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
1800 $this->setError($SYS->getErrorMessage());
1805 $this->addHistory('Removed User',$user_id);
1812 * updateUser - controls updating a user's role in this group.
1814 * @param int The ID of the user.
1815 * @param int The role_id to set this user to.
1816 * @return boolean success.
1818 function updateUser($user_id,$role_id) {
1821 $perm =& $this->getPermission( session_get_user() );
1822 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1823 $this->setPermissionDeniedError();
1827 $role = new Role($this,$role_id);
1828 if (!$role || !is_object($role)) {
1829 $this->setError(_('Could Not Get Role'));
1831 } elseif ($role->isError()) {
1832 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1835 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
1836 if (!$role->setUser($user_id)) {
1837 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1841 $hook_params['group'] = $this;
1842 $hook_params['group_id'] = $this->getID();
1843 $hook_params['user'] = &user_get_object($user_id);
1844 $hook_params['user_id'] = $user_id;
1845 plugin_hook ("group_removeuser", $hook_params);
1847 $this->addHistory('Updated User',$user_id);
1852 * addHistory - Makes an audit trail entry for this project.
1854 * @param string The name of the field.
1855 * @param string The Old Value for this $field_name.
1856 * @return database result handle.
1859 function addHistory($field_name, $old_value) {
1860 return db_query_params ('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
1861 VALUES ($1,$2,$3,$4,$5)',
1862 array ($this->getID(),
1870 * activateUsers - Make sure that group members have unix accounts.
1872 * Setup unix accounts for group members. Can be called even
1873 * if members are already active.
1877 function activateUsers() {
1880 Activate member(s) of the project
1883 $member_res = db_query_params ('SELECT user_id, role_id FROM user_group WHERE group_id=$1',
1884 array ($this->getID())) ;
1886 $rows = db_numrows($member_res);
1890 for ($i=0; $i<$rows; $i++) {
1892 $member =& user_get_object(db_result($member_res,$i,'user_id'));
1893 $roleId = db_result($member_res,$i,'role_id');
1895 if (!$member || !is_object($member)) {
1896 $this->setError(_('Error getting member object'));
1898 } else if ($member->isError()) {
1899 $this->setError(sprintf(_('Error getting member object: %s'),$member->getErrorMessage()));
1903 if (!$this->addUser($member->getUnixName(),$roleId)) {
1914 * getMembers - returns array of User objects for this project
1916 * @return array of User objects for this group.
1918 function &getMembers() {
1919 if (!isset($this->membersArr)) {
1920 $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',
1921 array ($this->getID())) ;
1922 while ($arr =& db_fetch_array($res)) {
1923 $this->membersArr[] =& new GFUser($arr['user_id'],$arr);
1926 return $this->membersArr;
1930 * approve - Approve pending project.
1932 * @param object The User object who is doing the updating.
1935 function approve(&$user) {
1937 if ($this->getStatus()=='A') {
1938 $this->setError(_("Group already active"));
1944 // Step 1: Activate group and create LDAP entries
1945 if (!$this->setStatus($user, 'A')) {
1950 // Switch to system language for item creation
1951 setup_gettext_from_sys_lang ();
1956 // Tracker Integration
1959 $ats = new ArtifactTypes($this);
1960 if (!$ats || !is_object($ats)) {
1961 $this->setError(_('Error creating ArtifactTypes object'));
1963 setup_gettext_from_context();
1965 } else if ($ats->isError()) {
1966 $this->setError(sprintf (_('ATS%d: %s'), 1, $ats->getErrorMessage()));
1968 setup_gettext_from_context();
1971 if (!$ats->createTrackers()) {
1972 $this->setError(sprintf (_('ATS%d: %s'), 2, $ats->getErrorMessage()));
1974 setup_gettext_from_context();
1980 // Forum Integration
1983 $f = new Forum($this);
1984 if (!$f->create(_('Open-Discussion'),_('General Discussion'),1,'',1,0)) {
1985 $this->setError(sprintf (_('F%d: %s'), 1, $f->getErrorMessage()));
1987 setup_gettext_from_context();
1990 $f = new Forum($this);
1991 if (!$f->create(_('Help'),_('Get Public Help'),1,'',1,0)) {
1992 $this->setError(sprintf (_('F%d: %s'), 2, $f->getErrorMessage()));
1994 setup_gettext_from_context();
1997 $f = new Forum($this);
1998 if (!$f->create(_('Developers'),_('Project Developer Discussion'),0,'',1,0)) {
1999 $this->setError(sprintf (_('F%d: %s'), 3, $f->getErrorMessage()));
2001 setup_gettext_from_context();
2007 // Doc Mgr Integration
2010 $dg = new DocumentGroup($this);
2011 if (!$dg->create(_('Uncategorized Submissions'))) {
2012 $this->setError(sprintf(_('DG: %s'),$dg->getErrorMessage()));
2014 setup_gettext_from_context();
2023 $frs = new FRSPackage($this);
2024 if (!$frs->create($this->getUnixName())) {
2025 $this->setError(sprintf(_('FRSP: %s'),$frs->getErrorMessage()));
2027 setup_gettext_from_context();
2036 $pg = new ProjectGroup($this);
2037 if (!$pg->create(_('To Do'),_('Things We Have To Do'),1)) {
2038 $this->setError(sprintf(_('PG%d: %s'),1,$pg->getErrorMessage()));
2040 setup_gettext_from_context();
2043 $pg = new ProjectGroup($this);
2044 if (!$pg->create(_('Next Release'),_('Items For Our Next Release'),1)) {
2045 $this->setError(sprintf(_('PG%d: %s'),2,$pg->getErrorMessage()));
2047 setup_gettext_from_context();
2053 // Set Default Roles
2056 $role = new Role($this);
2057 $todo = array_keys($role->defaults);
2058 for ($c=0; $c<count($todo); $c++) {
2059 $role = new Role($this);
2060 if (!$role->createDefault($todo[$c])) {
2061 $this->setError(sprintf(_('R%d: %s'),$c,$role->getErrorMessage()));
2063 setup_gettext_from_context();
2068 $admin_group = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1 AND admin_flags=$2',
2069 array ($this->getID(),
2071 if (db_numrows($admin_group) > 0) {
2072 $idadmin_group = db_result($admin_group,0,'user_id');
2079 // Create MailingList
2082 if ($GLOBALS['sys_use_mail']) {
2083 $mlist = new MailingList($this);
2084 if (!$mlist->create('commits',_('Commits'),1,$idadmin_group)) {
2085 $this->setError(sprintf(_('ML: %s'),$mlist->getErrorMessage()));
2087 setup_gettext_from_context();
2092 // Switch back to user preference
2093 setup_gettext_from_context();
2097 $this->sendApprovalEmail();
2098 $this->addHistory('Approved', 'x');
2101 //change assistant for webcal
2103 $params[0] = $idadmin_group ;
2104 $params[1] = $this->getID();
2105 plugin_hook('change_cal_permission_default',$params);
2113 * sendApprovalEmail - Send new project email.
2115 * @return boolean success.
2118 function sendApprovalEmail() {
2119 $res_admins = db_query_params ('
2120 SELECT users.user_name,users.email,users.language,users.user_id
2121 FROM users,user_group
2122 WHERE users.user_id=user_group.user_id
2123 AND user_group.group_id=$1
2124 AND user_group.admin_flags=$2',
2125 array ($this->getID(),
2128 if (db_numrows($res_admins) < 1) {
2129 $this->setError(_("Group does not have any administrators."));
2133 // send one email per admin
2134 while ($row_admins = db_fetch_array($res_admins)) {
2135 $admin =& user_get_object($row_admins['user_id']);
2136 setup_gettext_for_user ($admin) ;
2138 $message=stripcslashes(sprintf(_('Your project registration for %4$s has been approved.
2140 Project Full Name: %1$s
2141 Project Unix Name: %2$s
2143 Your DNS will take up to a day to become active on our site.
2144 Your web site is accessible through your shell account. Please read
2145 site documentation (see link below) about intended usage, available
2146 services, and directory layout of the account.
2149 own project page in %4$s while logged in, you will find
2150 additional menu functions to your left labeled \'Project Admin\'.
2152 We highly suggest that you now visit %4$s and create a public
2153 description for your project. This can be done by visiting your project
2154 page while logged in, and selecting \'Project Admin\' from the menus
2155 on the left (or by visiting %3$s
2158 Your project will also not appear in the Trove Software Map (primary
2159 list of projects hosted on %4$s which offers great flexibility in
2160 browsing and search) until you categorize it in the project administration
2161 screens. So that people can find your project, you should do this now.
2162 Visit your project while logged in, and select \'Project Admin\' from the
2165 Enjoy the system, and please tell others about %4$s. Let us know
2166 if there is anything we can do to help you.
2169 $this->getPublicName(),
2170 $this->getUnixName(),
2171 util_make_url ('/project/admin/?group_id='.$this->getID()),
2172 $GLOBALS['sys_name']));
2174 util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), $GLOBALS['sys_name']), $message);
2176 setup_gettext_from_context();
2184 * sendRejectionEmail - Send project rejection email.
2186 * This function sends out a rejection message to a user who
2187 * registered a project.
2189 * @param int The id of the response to use.
2190 * @param string The rejection message.
2191 * @return completion status.
2194 function sendRejectionEmail($response_id, $message="zxcv") {
2195 $res_admins = db_query_params ('
2196 SELECT u.email, u.language, u.user_id
2197 FROM users u, user_group ug
2198 WHERE ug.group_id=$1
2199 AND u.user_id=ug.user_id',
2200 array ($this->getID())) ;
2201 if (db_numrows($res_admins) < 1) {
2202 $this->setError(_("Group does not have any administrators."));
2206 while ($row_admins = db_fetch_array($res_admins)) {
2207 $admin =& user_get_object($row_admins['user_id']);
2208 setup_gettext_for_user ($admin) ;
2210 $response=stripcslashes(sprintf(_('Your project registration for %3$s has been denied.
2212 Project Full Name: %1$s
2213 Project Unix Name: %2$s
2215 Reasons for negative decision:
2217 '), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name']));
2219 // Check to see if they want to send a custom rejection response
2220 if ($response_id == 0) {
2221 $response .= stripcslashes($message);
2223 $response .= db_result (
2224 db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array ($response_id)),
2229 util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), $GLOBALS['sys_name']), $response);
2230 setup_gettext_from_context();
2237 * sendNewProjectNotificationEmail - Send new project notification email.
2239 * This function sends out a notification email to the
2240 * SourceForge admin user when a new project is
2243 * @return boolean success.
2246 function sendNewProjectNotificationEmail() {
2247 // Get the user who wants to register the project
2248 $res = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1',
2249 array ($this->getID())) ;
2251 if (db_numrows($res) < 1) {
2252 $this->setError(_("Could not find user who has submitted the project."));
2256 $submitter =& user_get_object(db_result($res,0,'user_id'));
2259 $res = db_query_params ('SELECT users.email, users.language, users.user_id
2260 FROM users, user_group
2262 AND user_group.admin_flags=$1
2263 AND users.user_id=user_group.user_id',
2266 if (db_numrows($res) < 1) {
2267 $this->setError(_("There is no administrator to send the mail."));
2271 for ($i=0; $i<db_numrows($res) ; $i++) {
2272 $admin_email = db_result($res,$i,'email') ;
2273 $admin =& user_get_object(db_result($res,$i,'user_id'));
2274 setup_gettext_for_user ($admin) ;
2276 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2278 Project Full Name: %2$s
2279 Submitted Description: %3$s
2281 Submitter: %6$s (%7$s)
2283 Please visit the following URL to approve or reject this project:
2285 $GLOBALS['sys_name'],
2286 $this->getPublicName(),
2287 util_unconvert_htmlspecialchars($this->getRegistrationPurpose()),
2288 $this->getLicenseName(),
2289 util_make_url ('/admin/approve-pending.php'),
2290 $submitter->getRealName(),
2291 $submitter->getUnixName()));
2292 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2293 setup_gettext_from_context();
2297 $email = $submitter->getEmail() ;
2298 setup_gettext_for_user ($submitter) ;
2300 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2302 Project Full Name: %2$s
2303 Submitted Description: %3$s
2306 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']));
2308 util_send_message($email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2309 setup_gettext_from_context();
2318 * validateGroupName - Validate the group name
2320 * @param string Group name.
2322 * @return an error false and set an error is the group name is invalide otherwise return true
2324 function validateGroupName($group_name) {
2325 if (strlen($group_name)<3) {
2326 $this->setError(_('Group name is too short'));
2328 } else if (strlen(htmlspecialchars($group_name))>50) {
2329 $this->setError(_('Group name is too long'));
2331 } else if ($group=group_get_object_by_publicname($group_name)) {
2332 $this->setError(_('Group name already taken'));
2344 * group_getname() - get the group name
2346 * @param int The group ID
2350 function group_getname ($group_id = 0) {
2351 $grp = &group_get_object($group_id);
2353 return $grp->getPublicName();
2360 * group_getunixname() - get the unixname for a group
2362 * @param int The group ID
2366 function group_getunixname ($group_id) {
2367 $grp = &group_get_object($group_id);
2369 return $grp->getUnixName();
2376 * group_get_result() - Get the group object result ID.
2378 * @param int The group ID
2382 function &group_get_result($group_id=0) {
2383 $grp = &group_get_object($group_id);
2385 return $grp->getData();
2392 * getUnixStatus - Status of activation of unix account.
2394 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2396 function getUnixStatus() {
2397 return $this->data_array['unix_status'];
2401 * setUnixStatus - Sets status of activation of unix account.
2403 * @param string The unix status.
2409 * @return boolean success.
2411 function setUnixStatus($status) {
2414 $res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
2419 $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
2423 if ($status == 'A') {
2424 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2425 $this->setError($SYS->getErrorMessage());
2430 if ($SYS->sysCheckGroup($this->getID())) {
2431 if (!$SYS->sysRemoveGroup($this->getID())) {
2432 $this->setError($SYS->getErrorMessage());
2439 $this->data_array['unix_status']=$status;
2447 // c-file-style: "bsd"