5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2009, Roland Mas
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 require_once $gfcommon.'tracker/ArtifactTypes.class.php';
27 require_once $gfcommon.'tracker/ArtifactTypeFactory.class.php';
28 require_once $gfcommon.'forum/Forum.class.php';
29 require_once $gfcommon.'forum/ForumFactory.class.php';
30 require_once $gfcommon.'pm/ProjectGroup.class.php';
31 require_once $gfcommon.'pm/ProjectGroupFactory.class.php';
32 require_once $gfcommon.'include/Role.class.php';
33 require_once $gfcommon.'frs/FRSPackage.class.php';
34 require_once $gfcommon.'docman/DocumentGroup.class.php';
35 require_once $gfcommon.'mail/MailingList.class.php';
36 require_once $gfcommon.'mail/MailingListFactory.class.php';
37 require_once $gfcommon.'survey/SurveyFactory.class.php';
38 require_once $gfcommon.'survey/SurveyQuestionFactory.class.php';
39 require_once $gfcommon.'include/gettext.php';
41 //the license_id of "Other/proprietary" license
42 define('GROUP_LICENSE_OTHER',126);
44 $LICENSE_NAMES=array();
47 * group_get_licences() - get the licenses list
49 * @return array list of licenses
51 function & group_get_licenses() {
52 global $LICENSE_NAMES;
53 if(empty($LICENSE_NAMES)) {
54 $result = db_query_params ('select * from licenses', array());
55 while($data = db_fetch_array($result)) {
56 $LICENSE_NAMES[$data['license_id']] = $data['license_name'];
59 return $LICENSE_NAMES;
65 * group_get_object() - Get the group object.
67 * group_get_object() is useful so you can pool group objects/save database queries
68 * You should always use this instead of instantiating the object directly.
70 * You can now optionally pass in a db result handle. If you do, it re-uses that query
71 * to instantiate the objects.
73 * IMPORTANT! That db result must contain all fields
74 * from groups table or you will have problems
77 * @param int Result set handle ("SELECT * FROM groups WHERE group_id=xx")
78 * @return a group object or false on failure
80 function &group_get_object($group_id,$res=false) {
81 //create a common set of group objects
82 //saves a little wear on the database
84 //automatically checks group_type and
85 //returns appropriate object
88 if (!isset($GROUP_OBJ["_".$group_id."_"])) {
90 //the db result handle was passed in
92 $res = db_query_params ('SELECT * FROM groups WHERE group_id=$1', array ($group_id)) ;
94 if (!$res || db_numrows($res) < 1) {
95 $GROUP_OBJ["_".$group_id."_"]=false;
98 check group type and set up object
100 if (db_result($res,0,'type_id')==1) {
102 $GROUP_OBJ["_".$group_id."_"]= new Group($group_id,$res);
105 $GROUP_OBJ["_".$group_id."_"]=false;
109 return $GROUP_OBJ["_".$group_id."_"];
112 function &group_get_objects($id_arr) {
115 // Note: if we don't do this, the result may be corrupted
119 for ($i=0; $i<count($id_arr); $i++) {
121 // See if this ID already has been fetched in the cache
126 if (!isset($GROUP_OBJ["_".$id_arr[$i]."_"])) {
127 $fetch[]=$id_arr[$i];
129 $return[] =& $GROUP_OBJ["_".$id_arr[$i]."_"];
132 if (count($fetch) > 0) {
133 $res=db_query_params ('SELECT * FROM groups WHERE group_id = ANY ($1)',
134 array (db_int_array_to_any_clause ($fetch))) ;
135 while ($arr =& db_fetch_array($res)) {
136 $GROUP_OBJ["_".$arr['group_id']."_"] = new Group($arr['group_id'],$arr);
137 $return[] =& $GROUP_OBJ["_".$arr['group_id']."_"];
143 function &group_get_object_by_name($groupname) {
144 $res=db_query_params('SELECT * FROM groups WHERE unix_group_name=$1', array ($groupname)) ;
145 return group_get_object(db_result($res,0,'group_id'),$res);
148 function &group_get_objects_by_name($groupname_arr) {
149 $res=db_query_params ('SELECT group_id FROM groups WHERE unix_group_name = ANY ($1)',
150 array (db_string_array_to_any_clause ($groupname_arr))
152 $arr =& util_result_column_to_array($res,0);
153 return group_get_objects($arr);
156 function &group_get_object_by_publicname($groupname) {
157 $res=db_query_params ('SELECT * FROM groups WHERE lower(group_name) LIKE $1',
158 array (htmlspecialchars (strtolower ($groupname)))) ;
160 return group_get_object(db_result($res,0,'group_id'),$res);
163 class Group extends Error {
165 * Associative array of data from db.
167 * @var array $data_array.
172 * array of User objects.
174 * @var array $membersArr.
179 * Whether the use is an admin/super user of this project.
181 * @var bool $is_admin.
186 * Artifact types result handle.
188 * @var int $types_res.
193 * Associative array of data for plugins.
195 * @var array $plugins_data.
201 * Associative array of data for the group menu.
203 * @var array $menu_data.
208 * Group - Group object constructor - use group_get_object() to instantiate.
210 * @param int Required - group_id of the group you want to instantiate.
211 * @param int Database result from select query OR associative array of all columns.
213 function Group($id=false, $res=false) {
216 //setting up an empty object
217 //probably going to call create()
221 if (!$this->fetchData($id)) {
226 // Assoc array was passed in
228 if (is_array($res)) {
229 $this->data_array =& $res;
231 if (db_numrows($res) < 1) {
232 //function in class we extended
233 $this->setError(_('Group Not Found'));
234 $this->data_array=array();
237 //set up an associative array for use by other functions
238 db_reset_result($res);
239 $this->data_array = db_fetch_array($res);
244 $systemGroups = array(GROUP_IS_NEWS, GROUP_IS_STATS, GROUP_IS_PEER_RATINGS);
245 if(!$this->isPublic() && !in_array($id, $systemGroups)) {
246 $perm =& $this->getPermission(session_get_user());
248 if (!$perm || !is_object($perm) || !$perm->isMember()) {
249 $this->setError(_('Permission denied'), ERROR__PERMISSION_DENIED_ERROR);
257 * fetchData - May need to refresh database fields if an update occurred.
259 * @param int The group_id.
261 function fetchData($group_id) {
262 $res = db_query_params ('SELECT * FROM groups WHERE group_id=$1',
264 if (!$res || db_numrows($res) < 1) {
265 $this->setError(sprintf(_('fetchData():: %s'),db_error()));
268 $this->data_array =& db_fetch_array($res);
273 * create - Create new group.
275 * This method should be called on empty Group object.
277 * @param object The User object.
278 * @param string The full name of the user.
279 * @param string The Unix name of the user.
280 * @param string The new group description.
281 * @param string The purpose of the group.
282 * @param bool Whether to send an email or not
284 function create(&$user, $group_name, $unix_name, $description, $purpose, $unix_box='shell1', $scm_box='cvs1', $is_public=1, $send_mail=true) {
285 // $user is ignored - anyone can create pending group
288 if ($this->getID()!=0) {
289 $this->setError(_('Group::create: Group object already exists'));
291 } else if (!$this->validateGroupName($group_name)) {
293 } else if (!account_groupnamevalid($unix_name)) {
294 $this->setError(_('Invalid Unix name'));
296 } else if (!$SYS->sysUseUnixName($unix_name)) {
297 $this->setError(_('Unix name already taken'));
299 } else if (db_numrows(db_query_params('SELECT group_id FROM groups WHERE unix_group_name=$1',
300 array ($unix_name))) > 0) {
301 $this->setError(_('Unix name already taken'));
303 } else if (strlen($purpose)<10) {
304 $this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
306 } else if (strlen($purpose)>1500) {
307 $this->setError(_('The Registration Purpose text is too long. Please make it smaller than 1500 bytes.'));
309 } else if (strlen($description)<10) {
310 $this->setError(_('Describe in a more comprehensive manner your project.'));
312 } else if (strlen($description)>255) {
313 $this->setError(_('Your project description is too long. Please make it smaller than 256 bytes.'));
317 srand((double)microtime()*1000000);
318 $random_num = rand(0,1000000);
322 $res = db_query_params ('
338 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)',
339 array (htmlspecialchars ($group_name),
342 htmlspecialchars($description),
343 $unix_name.".".forge_get_config('web_host'),
344 $unix_name.".".forge_get_config('web_host'),
348 htmlspecialchars($purpose),
351 md5($random_num) )) ;
352 if (!$res || db_affected_rows($res) < 1) {
353 $this->setError(sprintf(_('ERROR: Could not create group: %s'),db_error()));
358 $id = db_insertid($res, 'groups', 'group_id');
360 $this->setError(sprintf(_('ERROR: Could not get group id: %s'),db_error()));
366 // Now, make the user an admin
368 $res=db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags,
369 cvs_flags, artifact_flags, forum_flags, role_id)
370 VALUES ($1, $2, $3, $4, $5, $6, $7)',
371 array ($user->getID(),
378 if (!$res || db_affected_rows($res) < 1) {
379 $this->setError(sprintf(_('ERROR: Could not add admin to newly created group: %s'),db_error()));
384 if (!$this->fetchData($id)) {
389 $hook_params = array ();
390 $hook_params['group'] = $this;
391 $hook_params['group_id'] = $this->getID();
392 $hook_params['group_name'] = $group_name;
393 $hook_params['unix_group_name'] = $unix_name;
394 plugin_hook ("group_create", $hook_params);
398 $this->sendNewProjectNotificationEmail();
406 * updateAdmin - Update core properties of group object.
408 * This function require site admin privilege.
410 * @param object User requesting operation (for access control).
411 * @param bool Whether group is publicly accessible (0/1).
412 * @param int Group type (1-project, 2-foundry).
413 * @param string Machine on which group's home directory located.
414 * @param string Domain which serves group's WWW.
418 function updateAdmin(&$user, $is_public, $type_id, $unix_box, $http_domain) {
419 $perm =& $this->getPermission($user);
421 if (!$perm || !is_object($perm)) {
422 $this->setError(_('Could not get permission.'));
426 if (!$perm->isSuperUser()) {
427 $this->setError(_('Permission denied.'));
433 $res = db_query_params ('
435 SET is_public=$1, type_id=$2,
436 unix_box=$3, http_domain=$4
444 if (!$res || db_affected_rows($res) < 1) {
445 $this->setError(_('ERROR: DB: Could not change group properties: %s'),db_error());
450 // Log the audit trail
451 if ($is_public != $this->isPublic()) {
452 $this->addHistory('is_public', $this->isPublic());
454 if ($type_id != $this->data_array['type_id']) {
455 $this->addHistory('type_id', $this->data_array['type_id']);
457 if ($unix_box != $this->data_array['unix_box']) {
458 $this->addHistory('unix_box', $this->data_array['unix_box']);
460 if ($http_domain != $this->data_array['http_domain']) {
461 $this->addHistory('http_domain', $this->data_array['http_domain']);
464 if (!$this->fetchData($this->getID())) {
473 * update - Update number of common properties.
475 * Unlike updateAdmin(), this function accessible to project admin.
477 * @param object User requesting operation (for access control).
478 * @param bool Whether group is publicly accessible (0/1).
479 * @param string Project's license (string ident).
480 * @param int Group type (1-project, 2-foundry).
481 * @param string Machine on which group's home directory located.
482 * @param string Domain which serves group's WWW.
483 * @return int status.
486 function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,
487 $use_pm,$use_pm_depend_box,$use_scm,$use_news,$use_docman,
488 $new_doc_address,$send_all_docs,$logo_image_id,
489 $use_ftp,$use_tracker,$use_frs,$use_stats,$tags,$is_public) {
491 $perm =& $this->getPermission($user);
493 if (!$perm || !is_object($perm)) {
494 $this->setError(_('Could not get permission.'));
498 if (!$perm->isAdmin()) {
499 $this->setError(_('Permission denied.'));
503 // Validate some values
504 if ($this->getPublicName() != $group_name) {
505 if (!$this->validateGroupName($group_name)) {
510 if ($new_doc_address) {
511 $invalid_mails = validate_emails($new_doc_address);
512 if (count($invalid_mails) > 0) {
513 $this->setError(sprintf (ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
518 // in the database, these all default to '1',
519 // so we have to explicity set 0
532 if (!$use_pm_depend_box) {
533 $use_pm_depend_box=0;
556 if (!$send_all_docs) {
560 $homepage = ltrim($homepage);
562 $homepage=forge_get_config('web_host').'/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 if ($this->setTags($tags) === false) {
624 $hook_params = array ();
625 $hook_params['group'] = $this;
626 $hook_params['group_id'] = $this->getID();
627 $hook_params['group_homepage'] = $homepage;
628 $hook_params['group_name'] = htmlspecialchars($group_name);
629 $hook_params['group_description'] = htmlspecialchars($short_description);
630 plugin_hook ("group_update", $hook_params);
632 // Log the audit trail
633 $this->addHistory('Changed Public Info', '');
635 if (!$this->fetchData($this->getID())) {
644 * getID - Simply return the group_id for this object.
646 * @return int group_id.
649 return $this->data_array['group_id'];
653 * getType() - Foundry, project, etc.
655 * @return int The type flag from the database.
658 return $this->data_array['type_id'];
663 * getStatus - the status code.
665 * Statuses char include I,H,A,D.
667 function getStatus() {
668 return $this->data_array['status'];
672 * setStatus - set the status code.
674 * Statuses include I,H,A,D.
676 * @param object User requesting operation (for access control).
677 * @param string Status value.
678 * @return boolean success.
681 function setStatus(&$user, $status) {
684 $perm =& $this->getPermission($user);
685 if (!$perm || !is_object($perm)) {
686 $this->setPermissionDeniedError();
688 } elseif (!$perm->isSuperUser()) {
689 $this->setPermissionDeniedError();
693 // Projects in 'A' status can only go to 'H' or 'D'
694 // Projects in 'D' status can only go to 'A'
695 // Projects in 'P' status can only go to 'A' OR 'D'
696 // Projects in 'I' status can only go to 'P'
697 // Projects in 'H' status can only go to 'A' OR 'D'
698 $allowed_status_changes = array(
699 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
700 'IP'=>1,'HA'=>1,'HD'=>1
703 // Check that status transition is valid
704 if ($this->getStatus() != $status
705 && !$allowed_status_changes[$this->getStatus().$status]) {
706 $this->setError(_('Invalid Status Change'));
712 $res = db_query_params ('UPDATE groups
714 WHERE group_id=$2', array ($status, $this->getID())) ;
716 if (!$res || db_affected_rows($res) < 1) {
717 $this->setError(sprintf(_('ERROR: DB: Could not change group status: %s'),db_error()));
723 // Activate system group, if not yet
724 if (!$SYS->sysCheckGroup($this->getID())) {
725 if (!$SYS->sysCreateGroup($this->getID())) {
726 $this->setError($SYS->getErrorMessage());
731 if (!$this->activateUsers()) {
736 /* Otherwise, the group is not active, and make sure that
737 System group is not active either */
738 } else if ($SYS->sysCheckGroup($this->getID())) {
739 if (!$SYS->sysRemoveGroup($this->getID())) {
740 $this->setError($SYS->getErrorMessage());
746 $hook_params = array ();
747 $hook_params['group'] = $this;
748 $hook_params['group_id'] = $this->getID();
749 $hook_params['status'] = $status;
750 plugin_hook ("group_setstatus", $hook_params);
754 // Log the audit trail
755 if ($status != $this->getStatus()) {
756 $this->addHistory('Status', $this->getStatus());
759 $this->data_array['status'] = $status;
764 * isProject - Simple boolean test to see if it's a project or not.
766 * @return boolean is_project.
768 function isProject() {
769 if ($this->getType()==1) {
777 * isPublic - Simply returns the is_public flag from the database.
779 * @return boolean is_public.
781 function isPublic() {
782 return $this->data_array['is_public'];
786 * isActive - Database field status of 'A' returns true.
788 * @return boolean is_active.
790 function isActive() {
791 if ($this->getStatus()=='A') {
799 * getUnixName - the unix_name
801 * @return string unix_name.
803 function getUnixName() {
804 return strtolower($this->data_array['unix_group_name']);
808 * getPublicName - the full-length public name.
810 * @return string The group_name.
812 function getPublicName() {
813 return $this->data_array['group_name'];
817 * getRegisterPurpose - the text description of the purpose of this project.
819 * @return string The description.
821 function getRegisterPurpose() {
822 return $this->data_array['register_purpose'];
826 * getDescription - the text description of this project.
828 * @return string The description.
830 function getDescription() {
831 return $this->data_array['short_description'];
835 * getStartDate - the unix time this project was registered.
837 * @return int (unix time) of registration.
839 function getStartDate() {
840 return $this->data_array['register_time'];
844 * getLogoImageID - the id of the logo in the database for this project.
846 * @return int The ID of logo image in db_images table (or 100 if none).
848 function getLogoImageID() {
849 return $this->data_array['logo_image_id'];
853 * getUnixBox - the hostname of the unix box where this project is located.
855 * @return string The name of the unix machine for the group.
857 function getUnixBox() {
858 return $this->data_array['unix_box'];
862 * getSCMBox - the hostname of the scm box where this project is located.
864 * @return string The name of the unix machine for the group.
866 function getSCMBox() {
867 return $this->data_array['scm_box'];
870 * setSCMBox - the hostname of the scm box where this project is located.
872 * @param string The name of the new SCM_BOX
874 function setSCMBox($scm_box) {
876 if ($scm_box == $this->data_array['scm_box']) {
881 $res = db_query_params ('UPDATE groups SET scm_box=$1 WHERE group_id=$2', array ($scm_box, $this->getID ()));
883 $this->addHistory('scm_box', $this->data_array['scm_box']);
884 $this->data_array['scm_box']=$scm_box;
889 $this->setError(_("Couldn't insert SCM_BOX to database"));
893 $this->setError(_("SCM Box can't be empty"));
899 * getDomain - the hostname.domain where their web page is located.
901 * @return string The name of the group [web] domain.
903 function getDomain() {
904 return $this->data_array['http_domain'];
908 * getLicense - the license they chose.
910 * @return int ident of group license.
912 function getLicense() {
913 return $this->data_array['license'];
917 * getLicenseName - the name of the license
919 * @return string license name
921 function getLicenseName() {
922 $licenses =& group_get_licenses();
923 if(isset($licenses[$this->data_array['license']])) {
924 return $licenses[$this->data_array['license']];
931 * getLicenseOther - optional string describing license.
933 * @return string The custom license.
935 function getLicenseOther() {
936 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
937 return $this->data_array['license_other'];
944 * getRegistrationPurpose - the text description of the purpose of this project.
946 * @return string The application for project hosting.
948 function getRegistrationPurpose() {
949 return $this->data_array['register_purpose'];
954 * getAdmins() - Get array of Admin user objects.
956 * @return array Array of User objects.
958 function &getAdmins() {
959 // this function gets all group admins in order to send Jabber and mail messages
960 $res = db_query_params ('SELECT user_id FROM user_group WHERE admin_flags=$1 AND group_id=$2',
961 array ('A', $this->getID()));
962 $user_ids=util_result_column_to_array($res);
963 return user_get_objects($user_ids);
968 Common Group preferences for tools
973 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
975 * @return boolean enable_scm.
977 function enableAnonSCM() {
978 if ($this->isPublic() && $this->usesSCM()) {
979 return $this->data_array['enable_anonscm'];
985 function SetUsesAnonSCM ($booleanparam) {
987 $booleanparam = $booleanparam ? 1 : 0 ;
988 $res = db_query_params ('UPDATE groups SET enable_anonscm=$1 WHERE group_id=$2',
989 array ($booleanparam, $this->getID()));
991 $this->data_array['enable_anonscm']=$booleanparam;
999 function setUsesSCM ($booleanparam) {
1001 $booleanparam = $booleanparam ? 1 : 0 ;
1002 $res = db_query_params ('UPDATE groups SET use_scm=$1 WHERE group_id=$2',
1003 array ($booleanparam, $this->getID()));
1005 $this->data_array['use_scm']=$booleanparam;
1014 * enablePserver - whether or not this group has opted to enable Pserver.
1016 * @return boolean enable_pserver.
1018 function enablePserver() {
1019 if ($this->usesSCM()) {
1020 return $this->data_array['enable_pserver'];
1026 function SetUsesPserver ($booleanparam) {
1028 $booleanparam = $booleanparam ? 1 : 0 ;
1029 $res = db_query_params ('UPDATE groups SET enable_pserver=$1 WHERE group_id=$2',
1030 array ($booleanparam, $this->getID()));
1032 $this->data_array['enable_pserver']=$booleanparam;
1041 * usesSCM - whether or not this group has opted to use SCM.
1043 * @return boolean uses_scm.
1045 function usesSCM() {
1046 global $sys_use_scm;
1048 return $this->data_array['use_scm'];
1055 * usesMail - whether or not this group has opted to use mailing lists.
1057 * @return boolean uses_mail.
1059 function usesMail() {
1060 global $sys_use_mail;
1061 if ($sys_use_mail) {
1062 return $this->data_array['use_mail'];
1069 * usesNews - whether or not this group has opted to use news.
1071 * @return boolean uses_news.
1073 function usesNews() {
1074 global $sys_use_news;
1075 if ($sys_use_news) {
1076 return $this->data_array['use_news'];
1083 * usesForum - whether or not this group has opted to use discussion forums.
1085 * @return boolean uses_forum.
1087 function usesForum() {
1088 global $sys_use_forum;
1089 if ($sys_use_forum) {
1090 return $this->data_array['use_forum'];
1097 * usesStats - whether or not this group has opted to use stats.
1099 * @return boolean uses_stats.
1101 function usesStats() {
1102 return $this->data_array['use_stats'];
1106 * usesFRS - whether or not this group has opted to use file release system.
1108 * @return boolean uses_frs.
1110 function usesFRS() {
1111 global $sys_use_frs;
1113 return $this->data_array['use_frs'];
1120 * usesTracker - whether or not this group has opted to use tracker.
1122 * @return boolean uses_tracker.
1124 function usesTracker() {
1125 global $sys_use_tracker;
1126 if ($sys_use_tracker) {
1127 return $this->data_array['use_tracker'];
1134 * usesDocman - whether or not this group has opted to use docman.
1136 * @return boolean uses_docman.
1138 function usesDocman() {
1139 global $sys_use_docman;
1140 if ($sys_use_docman) {
1141 return $this->data_array['use_docman'];
1148 * usesFTP - whether or not this group has opted to use FTP.
1150 * @return boolean uses_ftp.
1152 function usesFTP() {
1153 global $sys_use_ftp;
1155 return $this->data_array['use_ftp'];
1162 * usesSurvey - whether or not this group has opted to use surveys.
1164 * @return boolean uses_survey.
1166 function usesSurvey() {
1167 global $sys_use_survey;
1168 if ($sys_use_survey) {
1169 return $this->data_array['use_survey'];
1176 * usesPM - whether or not this group has opted to Project Manager.
1178 * @return boolean uses_projman.
1183 return $this->data_array['use_pm'];
1190 * getPlugins - get a list of all available group plugins
1192 * @return array array containing plugin_id => plugin_name
1194 function getPlugins() {
1195 if (!isset($this->plugins_data)) {
1196 $this->plugins_data = array () ;
1197 $res = db_query_params ('SELECT group_plugin.plugin_id, plugins.plugin_name
1198 FROM group_plugin, plugins
1199 WHERE group_plugin.group_id=$1
1200 AND group_plugin.plugin_id=plugins.plugin_id', array ($this->getID()));
1201 $rows = db_numrows($res);
1203 for ($i=0; $i<$rows; $i++) {
1204 $plugin_id = db_result($res,$i,'plugin_id');
1205 $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
1208 return $this->plugins_data ;
1212 * usesPlugin - returns true if the group uses a particular plugin
1214 * @param string name of the plugin
1215 * @return boolean whether plugin is being used or not
1217 function usesPlugin($pluginname) {
1218 $plugins_data = $this->getPlugins() ;
1219 foreach ($plugins_data as $p_id => $p_name) {
1220 if ($p_name == $pluginname) {
1228 * setPluginUse - enables/disables plugins for the group
1230 * @param string name of the plugin
1231 * @param boolean the new state
1232 * @return string database result
1234 function setPluginUse($pluginname, $val=true) {
1235 if ($val == $this->usesPlugin($pluginname)) {
1236 // State is already good, returning
1239 $res = db_query_params ('SELECT plugin_id FROM plugins WHERE plugin_name=$1',
1240 array ($pluginname));
1241 $rows = db_numrows($res);
1243 // Error: no plugin by that name
1246 $plugin_id = db_result($res,0,'plugin_id');
1248 unset ($this->plugins_data) ;
1250 $res = db_query_params ('INSERT INTO group_plugin (group_id, plugin_id) VALUES ($1, $2)',
1251 array ($this->getID(),
1255 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1 AND plugin_id=$2',
1256 array ($this->getID(),
1263 * getDocEmailAddress - get email address(es) to send doc notifications to.
1265 * @return string email address.
1267 function getDocEmailAddress() {
1268 return $this->data_array['new_doc_address'];
1272 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1274 * @return boolean email_on_all_doc_updates.
1276 function docEmailAll() {
1277 return $this->data_array['send_all_docs'];
1282 * getHomePage - The URL for this project's home page.
1284 * @return string homepage URL.
1286 function getHomePage() {
1287 return $this->data_array['homepage'];
1291 * getTags - Tags of this project.
1293 * @return string List of tags.
1295 function getTags() {
1296 $sql = 'SELECT name FROM project_tags WHERE group_id = $1';
1297 $res = db_query_params($sql, array($this->getID()));
1298 return join(', ', util_result_column_to_array($res));
1302 * setTags - Set tags of this project.
1304 * @return string database result.
1306 function setTags($tags) {
1308 $sql='DELETE FROM project_tags WHERE group_id=$1';
1309 $res=db_query_params($sql, array($this->getID()));
1311 $this->setError('Deleting old tags: '.db_error());
1315 $inserted = array();
1316 $tags_array = split('[;,]', $tags);
1317 foreach ($tags_array as $tag) {
1318 $tag = stripslashes($tag);
1319 $tag = preg_replace('/[\t\r\n]/', ' ', $tag);
1320 // Allowed caracteres: [A-Z][a-z][0-9] -_&'#+.
1321 if (preg_match('/[^[:alnum:]| |\-|_|\&|\'|#|\+|\.]/', $tag)) {
1322 $this->setError(_('Bad tag name, you only can use the following characters: [A-Z][a-z][0-9]-_&\'#+. and space'));
1327 $tag = addslashes($tag);
1328 if ($tag == '' || array_search($tag, $inserted) !== false) continue;
1329 $sql='INSERT INTO project_tags (group_id,name) VALUES ($1, $2)';
1330 $res=db_query_params($sql, array($this->getID(), $tag));
1332 $this->setError(_('Setting tags: ').db_error());
1343 * getPermission - Return a Permission for this Group and the specified User.
1345 * @param object The user you wish to get permission for (usually the logged in user).
1346 * @return object The Permission.
1348 function &getPermission(&$_user) {
1349 return permission_get_object($this, $_user);
1354 * userIsAdmin - Return if for this Group the User is admin.
1356 * @return boolean is_admin.
1358 function userIsAdmin() {
1359 $perm =& $this->getPermission( session_get_user() );
1360 if (!$perm || !is_object($perm)) {
1362 } elseif ($perm->isError()) {
1365 return $perm->isAdmin();
1368 function delete($sure,$really_sure,$really_really_sure) {
1369 if (!$sure || !$really_sure || !$really_really_sure) {
1370 $this->setMissingParamsError();
1373 if ($this->getID() == $GLOBALS['sys_news_group'] ||
1374 $this->getID() == 1 ||
1375 $this->getID() == $GLOBALS['sys_stats_group'] ||
1376 $this->getID() == $GLOBALS['sys_peer_rating_group']) {
1377 $this->setError(_('Cannot Delete System Group'));
1380 $perm =& $this->getPermission( session_get_user() );
1381 if (!$perm || !is_object($perm)) {
1382 $this->setPermissionDeniedError();
1384 } elseif ($perm->isError()) {
1385 $this->setPermissionDeniedError();
1387 } elseif (!$perm->isSuperUser()) {
1388 $this->setPermissionDeniedError();
1394 // Remove all the members
1396 $members =& $this->getMembers();
1397 for ($i=0; $i<count($members); $i++) {
1398 $this->removeUser($members[$i]->getID());
1403 $atf = new ArtifactTypeFactory($this);
1404 $at_arr =& $atf->getArtifactTypes();
1405 for ($i=0; $i<count($at_arr); $i++) {
1406 if (!is_object($at_arr[$i])) {
1407 printf (_("Not Object: ArtifactType: %d"),$i);
1410 $at_arr[$i]->delete(1,1);
1415 $ff = new ForumFactory($this);
1416 $f_arr =& $ff->getForums();
1417 for ($i=0; $i<count($f_arr); $i++) {
1418 if (!is_object($f_arr[$i])) {
1419 printf (_("Not Object: Forum: %d"),$i);
1422 $f_arr[$i]->delete(1,1);
1423 //echo 'ForumFactory'.db_error();
1426 // Delete Subprojects
1428 $pgf = new ProjectGroupFactory($this);
1429 $pg_arr =& $pgf->getProjectGroups();
1430 for ($i=0; $i<count($pg_arr); $i++) {
1431 if (!is_object($pg_arr[$i])) {
1432 printf (_("Not Object: ProjectGroup: %d"),$i);
1435 $pg_arr[$i]->delete(1,1);
1436 //echo 'ProjectGroupFactory'.db_error();
1439 // Delete FRS Packages
1441 //$frspf = new FRSPackageFactory($this);
1442 $res = db_query_params ('SELECT * FROM frs_package WHERE group_id=$1',
1443 array ($this->getID())) ;
1444 //echo 'frs_package'.db_error();
1445 //$frsp_arr =& $frspf->getPackages();
1446 while ($arr = db_fetch_array($res)) {
1447 //if (!is_object($pg_arr[$i])) {
1448 // echo "Not Object: ProjectGroup: ".$i;
1451 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1457 $news_group=&group_get_object($GLOBALS['sys_news_group']);
1458 $res = db_query_params ('SELECT forum_id FROM news_bytes WHERE group_id=$1',
1459 array ($this->getID())) ;
1460 for ($i=0; $i<db_numrows($res); $i++) {
1461 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1462 if (!$Forum->delete(1,1)) {
1463 printf (_("Could Not Delete News Forum: %d"),$Forum->getID());
1466 $res = db_query_params ('DELETE FROM news_bytes WHERE group_id=$1',
1467 array ($this->getID())) ;
1472 $res = db_query_params ('DELETE FROM doc_data WHERE group_id=$1',
1473 array ($this->getID())) ;
1474 //echo 'doc_data'.db_error();
1475 $res = db_query_params ('DELETE FROM doc_groups WHERE group_id=$1',
1476 array ($this->getID())) ;
1477 //echo 'doc_groups'.db_error();
1482 $res=db_query_params('DELETE FROM project_tags WHERE group_id=$1', array($this->getID()));
1485 // Delete group history
1487 $res = db_query_params ('DELETE FROM group_history WHERE group_id=$1',
1488 array ($this->getID())) ;
1489 //echo 'group_history'.db_error();
1491 // Delete group plugins
1493 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1',
1494 array ($this->getID())) ;
1495 //echo 'group_plugin'.db_error();
1497 // Delete group cvs stats
1499 $res = db_query_params ('DELETE FROM stats_cvs_group WHERE group_id=$1',
1500 array ($this->getID())) ;
1501 //echo 'stats_cvs_group'.db_error();
1505 $sf = new SurveyFactory($this);
1506 $s_arr =& $sf->getSurveys();
1507 for ($i=0; $i<count($s_arr); $i++) {
1508 if (!is_object($s_arr[$i])) {
1509 printf (_("Not Object: Survey: %d"),$i);
1512 $s_arr[$i]->delete();
1513 //echo 'SurveyFactory'.db_error();
1516 // Delete SurveyQuestions
1518 $sqf = new SurveyQuestionFactory($this);
1519 $sq_arr =& $sqf->getSurveyQuestions();
1520 for ($i=0; $i<count($sq_arr); $i++) {
1521 if (!is_object($sq_arr[$i])) {
1522 printf (_("Not Object: SurveyQuestion: %d"),$i);
1525 $sq_arr[$i]->delete();
1526 //echo 'SurveyQuestionFactory'.db_error();
1529 // Delete Mailing List Factory
1531 $mlf = new MailingListFactory($this);
1532 $ml_arr =& $mlf->getMailingLists();
1533 for ($i=0; $i<count($ml_arr); $i++) {
1534 if (!is_object($ml_arr[$i])) {
1535 printf (_("Not Object: MailingList: %d"),$i);
1538 if (!$ml_arr[$i]->delete(1,1)) {
1539 $this->setError(_('Could not properly delete the mailing list'));
1541 //echo 'MailingListFactory'.db_error();
1546 $res = db_query_params ('DELETE FROM trove_group_link WHERE group_id=$1',
1547 array ($this->getID())) ;
1548 $res = db_query_params ('DELETE FROM trove_agg WHERE group_id=$1',
1549 array ($this->getID())) ;
1553 $res = db_query_params ('DELETE FROM project_sums_agg WHERE group_id=$1',
1554 array ($this->getID())) ;
1555 //echo 'project_sums_agg'.db_error();
1556 $res = db_query_params ('INSERT INTO deleted_groups (unix_group_name,delete_date,isdeleted) VALUES ($1, $2, $3)',
1557 array ($this->getUnixName(),
1560 //echo 'InsertIntoDeleteQueue'.db_error();
1561 $res = db_query_params ('DELETE FROM groups WHERE group_id=$1',
1562 array ($this->getID())) ;
1563 //echo 'DeleteGroup'.db_error();
1569 $hook_params = array ();
1570 $hook_params['group'] = $this;
1571 $hook_params['group_id'] = $this->getID();
1572 plugin_hook ("group_delete", $hook_params);
1574 if (isset($GLOBALS['sys_upload_dir']) && $this->getUnixName()) {
1575 exec('/bin/rm -rf '.$GLOBALS['sys_upload_dir'].'/'.$this->getUnixName().'/');
1577 if (isset($GLOBALS['sys_ftp_upload_dir']) && $this->getUnixName()) {
1578 exec('/bin/rm -rf '.$GLOBALS['sys_ftp_upload_dir'].'/'.$this->getUnixName().'/');
1583 $res = db_query_params ('DELETE FROM rep_group_act_monthly WHERE group_id=$1',
1584 array ($this->getID())) ;
1585 //echo 'rep_group_act_monthly'.db_error();
1586 $res = db_query_params ('DELETE FROM rep_group_act_weekly WHERE group_id=$1',
1587 array ($this->getID())) ;
1588 //echo 'rep_group_act_weekly'.db_error();
1589 $res = db_query_params ('DELETE FROM rep_group_act_daily WHERE group_id=$1',
1590 array ($this->getID())) ;
1591 //echo 'rep_group_act_daily'.db_error();
1592 unset($this->data_array);
1600 Basic functions to add/remove users to/from a group
1601 and update their permissions
1607 * addUser - controls adding a user to a group.
1609 * @param string Unix name of the user to add OR integer user_id.
1610 * @param int The role_id this user should have.
1611 * @return boolean success.
1614 function addUser($user_identifier,$role_id) {
1617 Admins can add users to groups
1620 $perm =& $this->getPermission( session_get_user() );
1621 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1622 $this->setPermissionDeniedError();
1628 get user id for this user's unix_name
1630 if (is_int ($user_identifier)) { // user_id or user_name
1631 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array ($user_identifier)) ;
1633 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array ($user_identifier)) ;
1635 if (db_numrows($res_newuser) > 0) {
1637 // make sure user is active
1639 if (db_result($res_newuser,0,'status') != 'A') {
1640 $this->setError(_('User is not active. Only active users can be added.'));
1646 // user was found - set new user_id var
1648 $user_id = db_result($res_newuser,0,'user_id');
1651 // if not already a member, add them
1653 $res_member = db_query_params ('SELECT user_id
1655 WHERE user_id=$1 AND group_id=$2',
1656 array ($user_id, $this->getID())) ;
1658 if (db_numrows($res_member) < 1) {
1660 // Create this user's row in the user_group table
1662 $res = db_query_params ('INSERT INTO user_group
1663 (user_id,group_id,admin_flags,forum_flags,project_flags,
1664 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
1665 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)',
1677 //verify the insert worked
1678 if (!$res || db_affected_rows($res) < 1) {
1679 $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
1684 // check and create if group doesn't exists
1686 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
1687 if (!$SYS->sysCheckCreateGroup($this->getID())){
1688 $this->setError($SYS->getErrorMessage());
1693 // check and create if user doesn't exists
1695 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1696 if (!$SYS->sysCheckCreateUser($user_id)) {
1697 $this->setError($SYS->getErrorMessage());
1704 $role = new Role($this,$role_id);
1705 if (!$role || !is_object($role)) {
1706 $this->setError(_('Error Getting Role Object'));
1709 } elseif ($role->isError()) {
1710 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1714 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
1715 if (!$role->setUser($user_id)) {
1716 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1722 // user was already a member
1723 // make sure they are set up
1725 $user=&user_get_object($user_id,$res_newuser);
1726 $user->fetchData($user->getID());
1727 $role = new Role($this,$role_id);
1728 if (!$role || !is_object($role)) {
1729 $this->setError(_('Error Getting Role Object'));
1732 } elseif ($role->isError()) {
1733 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1737 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
1738 if (!$role->setUser($user_id)) {
1739 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1744 // set up their system info
1746 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1747 if (!$SYS->sysCheckCreateUser($user_id)) {
1748 $this->setError($SYS->getErrorMessage());
1757 // user doesn't exist
1759 $this->setError(_('ERROR: User does not exist'));
1764 $hook_params['group'] = $this;
1765 $hook_params['group_id'] = $this->getID();
1766 $hook_params['user'] = &user_get_object($user_id);
1767 $hook_params['user_id'] = $user_id;
1768 plugin_hook ("group_adduser", $hook_params);
1773 $this->addHistory('Added User',$user_identifier);
1779 * removeUser - controls removing a user from a group.
1781 * Users can remove themselves.
1783 * @param int The ID of the user to remove.
1784 * @return boolean success.
1786 function removeUser($user_id) {
1789 if ($user_id==user_getid()) {
1790 //users can remove themselves
1791 //everyone else must be a project admin
1793 $perm =& $this->getPermission( session_get_user() );
1795 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1796 $this->setPermissionDeniedError();
1802 $res = db_query_params ('DELETE FROM user_group WHERE group_id=$1 AND user_id=$2',
1803 array ($this->getID(),
1805 if (!$res || db_affected_rows($res) < 1) {
1806 $this->setError(sprintf(_('ERROR: User not removed: %s'),db_error()));
1811 // reassign open artifacts to id=100
1813 $res = db_query_params ('UPDATE artifact SET assigned_to=100
1814 WHERE group_artifact_id
1815 IN (SELECT group_artifact_id
1816 FROM artifact_group_list
1817 WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
1818 array ($this->getID(),
1821 $this->setError(sprintf(_('ERROR: DB: artifact: %s'),db_error()));
1827 // reassign open tasks to id=100
1828 // first have to purge any assignments that would cause
1829 // conflict with existing assignment to 100
1831 $res = db_query_params ('DELETE FROM project_assigned_to
1832 WHERE project_task_id IN (SELECT pt.project_task_id
1833 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1834 WHERE pt.group_project_id = pgl.group_project_id
1835 AND pat.project_task_id=pt.project_task_id
1836 AND pt.status_id=1 AND pgl.group_id=$1
1837 AND pat.assigned_to_id=$2)
1838 AND assigned_to_id=100',
1839 array ($this->getID(),
1842 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),1,db_error()));
1846 $res = db_query_params ('UPDATE project_assigned_to SET assigned_to_id=100
1847 WHERE project_task_id IN (SELECT pt.project_task_id
1848 FROM project_task pt, project_group_list pgl
1849 WHERE pt.group_project_id = pgl.group_project_id
1850 AND pt.status_id=1 AND pgl.group_id=$1)
1851 AND assigned_to_id=$2',
1852 array ($this->getID(),
1855 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),2,db_error()));
1861 // Remove user from system
1863 //echo "<h2>Group::addUser SYS->sysGroupRemoveUser(".$this->getID().",$user_id)</h2>";
1864 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
1865 $this->setError($SYS->getErrorMessage());
1870 $hook_params['group'] = $this;
1871 $hook_params['group_id'] = $this->getID();
1872 $hook_params['user'] = &user_get_object($user_id);
1873 $hook_params['user_id'] = $user_id;
1874 plugin_hook ("group_removeuser", $hook_params);
1877 $this->addHistory('Removed User',$user_id);
1884 * updateUser - controls updating a user's role in this group.
1886 * @param int The ID of the user.
1887 * @param int The role_id to set this user to.
1888 * @return boolean success.
1890 function updateUser($user_id,$role_id) {
1893 $perm =& $this->getPermission( session_get_user() );
1894 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1895 $this->setPermissionDeniedError();
1899 $role = new Role($this,$role_id);
1900 if (!$role || !is_object($role)) {
1901 $this->setError(_('Could Not Get Role'));
1903 } elseif ($role->isError()) {
1904 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1907 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
1908 if (!$role->setUser($user_id)) {
1909 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1914 $this->addHistory('Updated User',$user_id);
1919 * addHistory - Makes an audit trail entry for this project.
1921 * @param string The name of the field.
1922 * @param string The Old Value for this $field_name.
1923 * @return database result handle.
1926 function addHistory($field_name, $old_value) {
1927 return db_query_params ('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
1928 VALUES ($1,$2,$3,$4,$5)',
1929 array ($this->getID(),
1937 * activateUsers - Make sure that group members have unix accounts.
1939 * Setup unix accounts for group members. Can be called even
1940 * if members are already active.
1944 function activateUsers() {
1947 Activate member(s) of the project
1950 $member_res = db_query_params ('SELECT user_id, role_id FROM user_group WHERE group_id=$1',
1951 array ($this->getID())) ;
1953 $rows = db_numrows($member_res);
1957 for ($i=0; $i<$rows; $i++) {
1959 $member =& user_get_object(db_result($member_res,$i,'user_id'));
1960 $roleId = db_result($member_res,$i,'role_id');
1962 if (!$member || !is_object($member)) {
1963 $this->setError(_('Error getting member object'));
1965 } else if ($member->isError()) {
1966 $this->setError(sprintf(_('Error getting member object: %s'),$member->getErrorMessage()));
1970 if (!$this->addUser($member->getUnixName(),$roleId)) {
1981 * getMembers - returns array of User objects for this project
1983 * @return array of User objects for this group.
1985 function &getMembers() {
1986 if (!isset($this->membersArr)) {
1987 $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',
1988 array ($this->getID())) ;
1989 while ($arr =& db_fetch_array($res)) {
1990 $this->membersArr[] =& new GFUser($arr['user_id'],$arr);
1993 return $this->membersArr;
1997 * approve - Approve pending project.
1999 * @param object The User object who is doing the updating.
2002 function approve(&$user) {
2004 if ($this->getStatus()=='A') {
2005 $this->setError(_("Group already active"));
2011 // Step 1: Activate group and create LDAP entries
2012 if (!$this->setStatus($user, 'A')) {
2017 // Switch to system language for item creation
2018 setup_gettext_from_sys_lang ();
2023 // Tracker Integration
2026 $ats = new ArtifactTypes($this);
2027 if (!$ats || !is_object($ats)) {
2028 $this->setError(_('Error creating ArtifactTypes object'));
2030 setup_gettext_from_context();
2032 } else if ($ats->isError()) {
2033 $this->setError(sprintf (_('ATS%d: %s'), 1, $ats->getErrorMessage()));
2035 setup_gettext_from_context();
2038 if (!$ats->createTrackers()) {
2039 $this->setError(sprintf (_('ATS%d: %s'), 2, $ats->getErrorMessage()));
2041 setup_gettext_from_context();
2047 // Forum Integration
2050 $f = new Forum($this);
2051 if (!$f->create(_('Open-Discussion'),_('General Discussion'),1,'',1,0)) {
2052 $this->setError(sprintf (_('F%d: %s'), 1, $f->getErrorMessage()));
2054 setup_gettext_from_context();
2057 $f = new Forum($this);
2058 if (!$f->create(_('Help'),_('Get Public Help'),1,'',1,0)) {
2059 $this->setError(sprintf (_('F%d: %s'), 2, $f->getErrorMessage()));
2061 setup_gettext_from_context();
2064 $f = new Forum($this);
2065 if (!$f->create(_('Developers-Discussion'),_('Project Developer Discussion'),0,'',1,0)) {
2066 $this->setError(sprintf (_('F%d: %s'), 3, $f->getErrorMessage()));
2068 setup_gettext_from_context();
2074 // Doc Mgr Integration
2077 $dg = new DocumentGroup($this);
2078 if (!$dg->create(_('Uncategorized Submissions'))) {
2079 $this->setError(sprintf(_('DG: %s'),$dg->getErrorMessage()));
2081 setup_gettext_from_context();
2090 $frs = new FRSPackage($this);
2091 if (!$frs->create($this->getUnixName())) {
2092 $this->setError(sprintf(_('FRSP: %s'),$frs->getErrorMessage()));
2094 setup_gettext_from_context();
2103 $pg = new ProjectGroup($this);
2104 if (!$pg->create(_('To Do'),_('Things We Have To Do'),1)) {
2105 $this->setError(sprintf(_('PG%d: %s'),1,$pg->getErrorMessage()));
2107 setup_gettext_from_context();
2110 $pg = new ProjectGroup($this);
2111 if (!$pg->create(_('Next Release'),_('Items For Our Next Release'),1)) {
2112 $this->setError(sprintf(_('PG%d: %s'),2,$pg->getErrorMessage()));
2114 setup_gettext_from_context();
2120 // Set Default Roles
2124 $admin_group = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1 AND admin_flags=$2',
2125 array ($this->getID(),
2127 if (db_numrows($admin_group) > 0) {
2128 $idadmin_group = db_result($admin_group,0,'user_id');
2130 $idadmin_group = $user->getID();
2131 db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags) VALUES ($1, $2, $3)',
2132 array ($idadmin_group,
2137 $role = new Role($this);
2138 $todo = array_keys($role->defaults);
2139 for ($c=0; $c<count($todo); $c++) {
2140 $role = new Role($this);
2141 if (! ($role_id = $role->createDefault($todo[$c]))) {
2142 $this->setError(sprintf(_('R%d: %s'),$c,$role->getErrorMessage()));
2144 setup_gettext_from_context();
2147 $role = new Role($this, $role_id);
2148 if ($role->getVal('projectadmin',0)=='A') {
2149 $role->setUser($idadmin_group);
2156 // Create MailingList
2159 if ($GLOBALS['sys_use_mail']) {
2160 $mlist = new MailingList($this);
2161 if (!$mlist->create('commits',_('Commits'),1,$idadmin_group)) {
2162 $this->setError(sprintf(_('ML: %s'),$mlist->getErrorMessage()));
2164 setup_gettext_from_context();
2169 // Switch back to user preference
2170 setup_gettext_from_context();
2174 $this->sendApprovalEmail();
2175 $this->addHistory('Approved', 'x');
2178 // Plugin can make approve operation there
2181 $params[0] = $idadmin_group ;
2182 $params[1] = $this->getID();
2183 plugin_hook('group_approve',$params);
2191 * sendApprovalEmail - Send new project email.
2193 * @return boolean success.
2196 function sendApprovalEmail() {
2197 $res_admins = db_query_params ('
2198 SELECT users.user_name,users.email,users.language,users.user_id
2199 FROM users,user_group
2200 WHERE users.user_id=user_group.user_id
2201 AND user_group.group_id=$1
2202 AND user_group.admin_flags=$2',
2203 array ($this->getID(),
2206 if (db_numrows($res_admins) < 1) {
2207 $this->setError(_("Group does not have any administrators."));
2211 // send one email per admin
2212 while ($row_admins = db_fetch_array($res_admins)) {
2213 $admin =& user_get_object($row_admins['user_id']);
2214 setup_gettext_for_user ($admin) ;
2216 $message=sprintf(_('Your project registration for %4$s has been approved.
2218 Project Full Name: %1$s
2219 Project Unix Name: %2$s
2221 Your DNS will take up to a day to become active on our site.
2222 Your web site is accessible through your shell account. Please read
2223 site documentation (see link below) about intended usage, available
2224 services, and directory layout of the account.
2227 own project page in %4$s while logged in, you will find
2228 additional menu functions to your left labeled \'Project Admin\'.
2230 We highly suggest that you now visit %4$s and create a public
2231 description for your project. This can be done by visiting your project
2232 page while logged in, and selecting \'Project Admin\' from the menus
2233 on the left (or by visiting %3$s
2236 Your project will also not appear in the Trove Software Map (primary
2237 list of projects hosted on %4$s which offers great flexibility in
2238 browsing and search) until you categorize it in the project administration
2239 screens. So that people can find your project, you should do this now.
2240 Visit your project while logged in, and select \'Project Admin\' from the
2243 Enjoy the system, and please tell others about %4$s. Let us know
2244 if there is anything we can do to help you.
2247 htmlspecialchars_decode($this->getPublicName()),
2248 $this->getUnixName(),
2249 util_make_url ('/project/admin/?group_id='.$this->getID()),
2250 forge_get_config ('forge_name'));
2252 util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), forge_get_config ('forge_name')), $message);
2254 setup_gettext_from_context();
2262 * sendRejectionEmail - Send project rejection email.
2264 * This function sends out a rejection message to a user who
2265 * registered a project.
2267 * @param int The id of the response to use.
2268 * @param string The rejection message.
2269 * @return completion status.
2272 function sendRejectionEmail($response_id, $message="zxcv") {
2273 $res_admins = db_query_params ('
2274 SELECT u.email, u.language, u.user_id
2275 FROM users u, user_group ug
2276 WHERE ug.group_id=$1
2277 AND u.user_id=ug.user_id',
2278 array ($this->getID())) ;
2279 if (db_numrows($res_admins) < 1) {
2280 $this->setError(_("Group does not have any administrators."));
2284 while ($row_admins = db_fetch_array($res_admins)) {
2285 $admin =& user_get_object($row_admins['user_id']);
2286 setup_gettext_for_user ($admin) ;
2288 $response=sprintf(_('Your project registration for %3$s has been denied.
2290 Project Full Name: %1$s
2291 Project Unix Name: %2$s
2293 Reasons for negative decision:
2295 '), $this->getPublicName(), $this->getUnixName(), forge_get_config ('forge_name'));
2297 // Check to see if they want to send a custom rejection response
2298 if ($response_id == 0) {
2299 $response .= $message;
2301 $response .= db_result (
2302 db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array ($response_id)),
2307 util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), forge_get_config ('forge_name')), $response);
2308 setup_gettext_from_context();
2315 * sendNewProjectNotificationEmail - Send new project notification email.
2317 * This function sends out a notification email to the
2318 * SourceForge admin user when a new project is
2321 * @return boolean success.
2324 function sendNewProjectNotificationEmail() {
2325 // Get the user who wants to register the project
2326 $res = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1',
2327 array ($this->getID())) ;
2329 if (db_numrows($res) < 1) {
2330 $this->setError(_("Could not find user who has submitted the project."));
2334 $submitter =& user_get_object(db_result($res,0,'user_id'));
2337 $res = db_query_params ('SELECT users.email, users.language, users.user_id
2338 FROM users, user_group
2340 AND user_group.admin_flags=$1
2341 AND users.user_id=user_group.user_id',
2344 if (db_numrows($res) < 1) {
2345 $this->setError(_("There is no administrator to send the mail to."));
2349 for ($i=0; $i<db_numrows($res) ; $i++) {
2350 $admin_email = db_result($res,$i,'email') ;
2351 $admin =& user_get_object(db_result($res,$i,'user_id'));
2352 setup_gettext_for_user ($admin) ;
2354 $message=sprintf(_('New %1$s Project Submitted
2356 Project Full Name: %2$s
2357 Submitted Description: %3$s
2358 Submitter: %5$s (%6$s)
2360 Please visit the following URL to approve or reject this project:
2362 forge_get_config ('forge_name'),
2363 htmlspecialchars_decode($this->getPublicName()),
2364 htmlspecialchars_decode($this->getRegistrationPurpose()),
2365 util_make_url ('/admin/approve-pending.php'),
2366 $submitter->getRealName(),
2367 $submitter->getUnixName());
2368 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
2369 setup_gettext_from_context();
2373 $email = $submitter->getEmail() ;
2374 setup_gettext_for_user ($submitter) ;
2376 $message=sprintf(_('New %1$s Project Submitted
2378 Project Full Name: %2$s
2379 Submitted Description: %3$s
2381 The %1$s admin team will now examine your project submission. You will be notified of their decision.'), forge_get_config ('forge_name'), $this->getPublicName(), util_unconvert_htmlspecialchars($this->getRegistrationPurpose()), forge_get_config('web_host'));
2383 util_send_message($email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
2384 setup_gettext_from_context();
2393 * validateGroupName - Validate the group name
2395 * @param string Group name.
2397 * @return an error false and set an error is the group name is invalide otherwise return true
2399 function validateGroupName($group_name) {
2400 if (strlen($group_name)<3) {
2401 $this->setError(_('Group name is too short'));
2403 } else if (strlen(htmlspecialchars($group_name))>50) {
2404 $this->setError(_('Group name is too long'));
2406 } else if ($group=group_get_object_by_publicname($group_name)) {
2407 $this->setError(_('Group name already taken'));
2415 * getRoles - Get the roles of the group.
2417 * @return array of Role id of this group.
2419 function getRolesId () {
2423 $roles_group_res = db_query_params ('SELECT role_id FROM role WHERE group_id=$1',
2424 array ($this->getID()));
2425 if (!$roles_group_res) {
2426 $this->setError('Error: Roles from group id '. $this->getID() . ' ' .db_error());
2429 for ($i=0; $i<db_numrows($roles_group_res); $i++) {
2430 $rolesId[$i] = db_result($roles_group_res,$i,'role_id');
2437 function getRoles () {
2438 $result = array () ;
2440 $roles = $this->getRolesId () ;
2441 foreach ($roles as $role_id) {
2442 $result[] = new Role ($this, $role_id) ;
2448 function normalizeAllRoles () {
2449 $roles = $this->getRoles () ;
2451 foreach ($roles as $r) {
2452 $r->normalizeData () ;
2457 * getUnixStatus - Status of activation of unix account.
2459 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2461 function getUnixStatus() {
2462 return $this->data_array['unix_status'];
2466 * setUnixStatus - Sets status of activation of unix account.
2468 * @param string The unix status.
2474 * @return boolean success.
2476 function setUnixStatus($status) {
2479 $res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
2484 $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
2488 if ($status == 'A') {
2489 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2490 $this->setError($SYS->getErrorMessage());
2495 if ($SYS->sysCheckGroup($this->getID())) {
2496 if (!$SYS->sysRemoveGroup($this->getID())) {
2497 $this->setError($SYS->getErrorMessage());
2504 $this->data_array['unix_status']=$status;
2511 * getUsers - Get the users of a group
2513 * @return array of user's objects.
2515 function getUsers() {
2518 $users_group_res = db_query_params ('SELECT u.user_id FROM users u, user_group ug WHERE ug.group_id=$1 AND ug.user_id=u.user_id AND u.status=$2',
2519 array ($this->getID(),
2521 if (!$users_group_res) {
2522 $this->setError('Error: Enable to get users from group '. $this->getID() . ' ' .db_error());
2526 for ($i=0; $i<db_numrows($users_group_res); $i++) {
2527 $users[$i] = new GFUser(db_result($users_group_res,$i,'user_id'),false);
2535 * group_getname() - get the group name
2537 * @param int The group ID
2541 function group_getname ($group_id = 0) {
2542 $grp = &group_get_object($group_id);
2544 return $grp->getPublicName();
2551 * group_getunixname() - get the unixname for a group
2553 * @param int The group ID
2557 function group_getunixname ($group_id) {
2558 $grp = &group_get_object($group_id);
2560 return $grp->getUnixName();
2567 * group_get_result() - Get the group object result ID.
2569 * @param int The group ID
2573 function &group_get_result($group_id=0) {
2574 $grp = &group_get_object($group_id);
2576 return $grp->getData();
2585 // c-file-style: "bsd"