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 string The purpose of the group.
281 * @param bool Whether to send an email or not
283 function create(&$user, $group_name, $unix_name, $description, $purpose, $unix_box='shell1', $scm_box='cvs1', $is_public=1, $send_mail=true) {
284 // $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 (!$SYS->sysUseUnixName($unix_name)) {
296 $this->setError(_('Unix name already taken'));
298 } else if (db_numrows(db_query_params('SELECT group_id FROM groups WHERE unix_group_name=$1',
299 array ($unix_name))) > 0) {
300 $this->setError(_('Unix name already taken'));
302 } else if (strlen($purpose)<10) {
303 $this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
305 } else if (strlen($purpose)>1500) {
306 $this->setError(_('The Registration Purpose text is too long. Please make it smaller than 1500 bytes.'));
308 } else if (strlen($description)<10) {
309 $this->setError(_('Describe in a more comprehensive manner your project.'));
311 } else if (strlen($description)>255) {
312 $this->setError(_('Your project description is too long. Please make it smaller than 256 bytes.'));
316 srand((double)microtime()*1000000);
317 $random_num = rand(0,1000000);
321 $res = db_query_params ('
337 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)',
338 array (htmlspecialchars ($group_name),
341 htmlspecialchars($description),
342 $unix_name.".".$GLOBALS['sys_default_domain'],
343 $unix_name.".".$GLOBALS['sys_default_domain'],
347 htmlspecialchars($purpose),
350 md5($random_num) )) ;
351 if (!$res || db_affected_rows($res) < 1) {
352 $this->setError(sprintf(_('ERROR: Could not create group: %s'),db_error()));
357 $id = db_insertid($res, 'groups', 'group_id');
359 $this->setError(sprintf(_('ERROR: Could not get group id: %s'),db_error()));
365 // Now, make the user an admin
367 $res=db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags,
368 cvs_flags, artifact_flags, forum_flags, role_id)
369 VALUES ($1, $2, $3, $4, $5, $6, $7)',
370 array ($user->getID(),
377 if (!$res || db_affected_rows($res) < 1) {
378 $this->setError(sprintf(_('ERROR: Could not add admin to newly created group: %s'),db_error()));
383 if (!$this->fetchData($id)) {
388 $hook_params = array ();
389 $hook_params['group'] = $this;
390 $hook_params['group_id'] = $this->getID();
391 $hook_params['group_name'] = $group_name;
392 $hook_params['unix_group_name'] = $unix_name;
393 plugin_hook ("group_create", $hook_params);
397 $this->sendNewProjectNotificationEmail();
405 * updateAdmin - Update core properties of group object.
407 * This function require site admin privilege.
409 * @param object User requesting operation (for access control).
410 * @param bool Whether group is publicly accessible (0/1).
411 * @param int Group type (1-project, 2-foundry).
412 * @param string Machine on which group's home directory located.
413 * @param string Domain which serves group's WWW.
417 function updateAdmin(&$user, $is_public, $type_id, $unix_box, $http_domain) {
418 $perm =& $this->getPermission($user);
420 if (!$perm || !is_object($perm)) {
421 $this->setError(_('Could not get permission.'));
425 if (!$perm->isSuperUser()) {
426 $this->setError(_('Permission denied.'));
432 $res = db_query_params ('
434 SET is_public=$1, type_id=$2,
435 unix_box=$3, http_domain=$4
443 if (!$res || db_affected_rows($res) < 1) {
444 $this->setError(_('ERROR: DB: Could not change group properties: %s'),db_error());
449 // Log the audit trail
450 if ($is_public != $this->isPublic()) {
451 $this->addHistory('is_public', $this->isPublic());
453 if ($type_id != $this->data_array['type_id']) {
454 $this->addHistory('type_id', $this->data_array['type_id']);
456 if ($unix_box != $this->data_array['unix_box']) {
457 $this->addHistory('unix_box', $this->data_array['unix_box']);
459 if ($http_domain != $this->data_array['http_domain']) {
460 $this->addHistory('http_domain', $this->data_array['http_domain']);
463 if (!$this->fetchData($this->getID())) {
472 * update - Update number of common properties.
474 * Unlike updateAdmin(), this function accessible to project admin.
476 * @param object User requesting operation (for access control).
477 * @param bool Whether group is publicly accessible (0/1).
478 * @param string Project's license (string ident).
479 * @param int Group type (1-project, 2-foundry).
480 * @param string Machine on which group's home directory located.
481 * @param string Domain which serves group's WWW.
482 * @return int status.
485 function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,
486 $use_pm,$use_pm_depend_box,$use_scm,$use_news,$use_docman,
487 $new_doc_address,$send_all_docs,$logo_image_id,
488 $use_ftp,$use_tracker,$use_frs,$use_stats,$tags,$is_public) {
490 $perm =& $this->getPermission($user);
492 if (!$perm || !is_object($perm)) {
493 $this->setError(_('Could not get permission.'));
497 if (!$perm->isAdmin()) {
498 $this->setError(_('Permission denied.'));
502 // Validate some values
503 if ($this->getPublicName() != $group_name) {
504 if (!$this->validateGroupName($group_name)) {
509 if ($new_doc_address) {
510 $invalid_mails = validate_emails($new_doc_address);
511 if (count($invalid_mails) > 0) {
512 $this->setError(sprintf (ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
517 // in the database, these all default to '1',
518 // so we have to explicity set 0
531 if (!$use_pm_depend_box) {
532 $use_pm_depend_box=0;
555 if (!$send_all_docs) {
560 $homepage=$GLOBALS['sys_default_domain'].'/projects/'.$this->getUnixName().'/';
563 if (strlen(htmlspecialchars($short_description))>255) {
564 $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
570 //XXX not yet actived logo_image_id='$logo_image_id',
571 $res = db_query_params ('UPDATE groups
574 short_description=$3,
579 use_pm_depend_box=$8,
591 array (htmlspecialchars($group_name),
593 htmlspecialchars($short_description),
612 $this->setError(sprintf(_('Error updating project information: %s'), db_error()));
617 if ($this->setTags($tags) === false) {
622 $hook_params = array ();
623 $hook_params['group'] = $this;
624 $hook_params['group_id'] = $this->getID();
625 $hook_params['group_homepage'] = $homepage;
626 $hook_params['group_name'] = htmlspecialchars($group_name);
627 $hook_params['group_description'] = htmlspecialchars($short_description);
628 plugin_hook ("group_update", $hook_params);
630 // Log the audit trail
631 $this->addHistory('Changed Public Info', '');
633 if (!$this->fetchData($this->getID())) {
642 * getID - Simply return the group_id for this object.
644 * @return int group_id.
647 return $this->data_array['group_id'];
651 * getType() - Foundry, project, etc.
653 * @return int The type flag from the database.
656 return $this->data_array['type_id'];
661 * getStatus - the status code.
663 * Statuses char include I,H,A,D.
665 function getStatus() {
666 return $this->data_array['status'];
670 * setStatus - set the status code.
672 * Statuses include I,H,A,D.
674 * @param object User requesting operation (for access control).
675 * @param string Status value.
676 * @return boolean success.
679 function setStatus(&$user, $status) {
682 $perm =& $this->getPermission($user);
683 if (!$perm || !is_object($perm)) {
684 $this->setPermissionDeniedError();
686 } elseif (!$perm->isSuperUser()) {
687 $this->setPermissionDeniedError();
691 // Projects in 'A' status can only go to 'H' or 'D'
692 // Projects in 'D' status can only go to 'A'
693 // Projects in 'P' status can only go to 'A' OR 'D'
694 // Projects in 'I' status can only go to 'P'
695 // Projects in 'H' status can only go to 'A' OR 'D'
696 $allowed_status_changes = array(
697 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
698 'IP'=>1,'HA'=>1,'HD'=>1
701 // Check that status transition is valid
702 if ($this->getStatus() != $status
703 && !$allowed_status_changes[$this->getStatus().$status]) {
704 $this->setError(_('Invalid Status Change'));
710 $res = db_query_params ('UPDATE groups
712 WHERE group_id=$2', array ($status, $this->getID())) ;
714 if (!$res || db_affected_rows($res) < 1) {
715 $this->setError(sprintf(_('ERROR: DB: Could not change group status: %s'),db_error()));
721 // Activate system group, if not yet
722 if (!$SYS->sysCheckGroup($this->getID())) {
723 if (!$SYS->sysCreateGroup($this->getID())) {
724 $this->setError($SYS->getErrorMessage());
729 if (!$this->activateUsers()) {
734 /* Otherwise, the group is not active, and make sure that
735 System group is not active either */
736 } else if ($SYS->sysCheckGroup($this->getID())) {
737 if (!$SYS->sysRemoveGroup($this->getID())) {
738 $this->setError($SYS->getErrorMessage());
744 $hook_params = array ();
745 $hook_params['group'] = $this;
746 $hook_params['group_id'] = $this->getID();
747 $hook_params['status'] = $status;
748 plugin_hook ("group_setstatus", $hook_params);
752 // Log the audit trail
753 if ($status != $this->getStatus()) {
754 $this->addHistory('Status', $this->getStatus());
757 $this->data_array['status'] = $status;
762 * isProject - Simple boolean test to see if it's a project or not.
764 * @return boolean is_project.
766 function isProject() {
767 if ($this->getType()==1) {
775 * isPublic - Simply returns the is_public flag from the database.
777 * @return boolean is_public.
779 function isPublic() {
780 return $this->data_array['is_public'];
784 * isActive - Database field status of 'A' returns true.
786 * @return boolean is_active.
788 function isActive() {
789 if ($this->getStatus()=='A') {
797 * getUnixName - the unix_name
799 * @return string unix_name.
801 function getUnixName() {
802 return strtolower($this->data_array['unix_group_name']);
806 * getPublicName - the full-length public name.
808 * @return string The group_name.
810 function getPublicName() {
811 return $this->data_array['group_name'];
815 * getRegisterPurpose - the text description of the purpose of this project.
817 * @return string The description.
819 function getRegisterPurpose() {
820 return $this->data_array['register_purpose'];
824 * getDescription - the text description of this project.
826 * @return string The description.
828 function getDescription() {
829 return $this->data_array['short_description'];
833 * getStartDate - the unix time this project was registered.
835 * @return int (unix time) of registration.
837 function getStartDate() {
838 return $this->data_array['register_time'];
842 * getLogoImageID - the id of the logo in the database for this project.
844 * @return int The ID of logo image in db_images table (or 100 if none).
846 function getLogoImageID() {
847 return $this->data_array['logo_image_id'];
851 * getUnixBox - the hostname of the unix box where this project is located.
853 * @return string The name of the unix machine for the group.
855 function getUnixBox() {
856 return $this->data_array['unix_box'];
860 * getSCMBox - the hostname of the scm box where this project is located.
862 * @return string The name of the unix machine for the group.
864 function getSCMBox() {
865 return $this->data_array['scm_box'];
868 * setSCMBox - the hostname of the scm box where this project is located.
870 * @param string The name of the new SCM_BOX
872 function setSCMBox($scm_box) {
875 $res = db_query_params ('UPDATE groups SET scm_box=$1 WHERE group_id=$2', array ($scm_box, $this->getID ()));
877 $this->addHistory('scm_box', $this->data_array['scm_box']);
878 $this->data_array['scm_box']=$scm_box;
883 $this->setError(_("Couldn't insert SCM_BOX to database"));
887 $this->setError(_("SCM Box can't be empty"));
893 * getDomain - the hostname.domain where their web page is located.
895 * @return string The name of the group [web] domain.
897 function getDomain() {
898 return $this->data_array['http_domain'];
902 * getLicense - the license they chose.
904 * @return int ident of group license.
906 function getLicense() {
907 return $this->data_array['license'];
911 * getLicenseName - the name of the license
913 * @return string license name
915 function getLicenseName() {
916 $licenses =& group_get_licenses();
917 if(isset($licenses[$this->data_array['license']])) {
918 return $licenses[$this->data_array['license']];
925 * getLicenseOther - optional string describing license.
927 * @return string The custom license.
929 function getLicenseOther() {
930 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
931 return $this->data_array['license_other'];
938 * getRegistrationPurpose - the text description of the purpose of this project.
940 * @return string The application for project hosting.
942 function getRegistrationPurpose() {
943 return $this->data_array['register_purpose'];
948 * getAdmins() - Get array of Admin user objects.
950 * @return array Array of User objects.
952 function &getAdmins() {
953 // this function gets all group admins in order to send Jabber and mail messages
954 $res = db_query_params ('SELECT user_id FROM user_group WHERE admin_flags=$1 AND group_id=$2',
955 array ('A', $this->getID()));
956 $user_ids=util_result_column_to_array($res);
957 return user_get_objects($user_ids);
962 Common Group preferences for tools
967 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
969 * @return boolean enable_scm.
971 function enableAnonSCM() {
972 if ($this->isPublic() && $this->usesSCM()) {
973 return $this->data_array['enable_anonscm'];
979 function SetUsesAnonSCM ($booleanparam) {
981 $booleanparam = $booleanparam ? 1 : 0 ;
982 $res = db_query_params ('UPDATE groups SET enable_anonscm=$1 WHERE group_id=$2',
983 array ($booleanparam, $this->getID()));
985 $this->data_array['enable_anonscm']=$booleanparam;
993 function setUsesSCM ($booleanparam) {
995 $booleanparam = $booleanparam ? 1 : 0 ;
996 $res = db_query_params ('UPDATE groups SET use_scm=$1 WHERE group_id=$2',
997 array ($booleanparam, $this->getID()));
999 $this->data_array['use_scm']=$booleanparam;
1008 * enablePserver - whether or not this group has opted to enable Pserver.
1010 * @return boolean enable_pserver.
1012 function enablePserver() {
1013 if ($this->usesSCM()) {
1014 return $this->data_array['enable_pserver'];
1020 function SetUsesPserver ($booleanparam) {
1022 $booleanparam = $booleanparam ? 1 : 0 ;
1023 $res = db_query_params ('UPDATE groups SET enable_pserver=$1 WHERE group_id=$2',
1024 array ($booleanparam, $this->getID()));
1026 $this->data_array['enable_pserver']=$booleanparam;
1035 * usesSCM - whether or not this group has opted to use SCM.
1037 * @return boolean uses_scm.
1039 function usesSCM() {
1040 global $sys_use_scm;
1042 return $this->data_array['use_scm'];
1049 * usesMail - whether or not this group has opted to use mailing lists.
1051 * @return boolean uses_mail.
1053 function usesMail() {
1054 global $sys_use_mail;
1055 if ($sys_use_mail) {
1056 return $this->data_array['use_mail'];
1063 * usesNews - whether or not this group has opted to use news.
1065 * @return boolean uses_news.
1067 function usesNews() {
1068 global $sys_use_news;
1069 if ($sys_use_news) {
1070 return $this->data_array['use_news'];
1077 * usesForum - whether or not this group has opted to use discussion forums.
1079 * @return boolean uses_forum.
1081 function usesForum() {
1082 global $sys_use_forum;
1083 if ($sys_use_forum) {
1084 return $this->data_array['use_forum'];
1091 * usesStats - whether or not this group has opted to use stats.
1093 * @return boolean uses_stats.
1095 function usesStats() {
1096 return $this->data_array['use_stats'];
1100 * usesFRS - whether or not this group has opted to use file release system.
1102 * @return boolean uses_frs.
1104 function usesFRS() {
1105 global $sys_use_frs;
1107 return $this->data_array['use_frs'];
1114 * usesTracker - whether or not this group has opted to use tracker.
1116 * @return boolean uses_tracker.
1118 function usesTracker() {
1119 global $sys_use_tracker;
1120 if ($sys_use_tracker) {
1121 return $this->data_array['use_tracker'];
1128 * usesDocman - whether or not this group has opted to use docman.
1130 * @return boolean uses_docman.
1132 function usesDocman() {
1133 global $sys_use_docman;
1134 if ($sys_use_docman) {
1135 return $this->data_array['use_docman'];
1142 * usesFTP - whether or not this group has opted to use FTP.
1144 * @return boolean uses_ftp.
1146 function usesFTP() {
1147 global $sys_use_ftp;
1149 return $this->data_array['use_ftp'];
1156 * usesSurvey - whether or not this group has opted to use surveys.
1158 * @return boolean uses_survey.
1160 function usesSurvey() {
1161 global $sys_use_survey;
1162 if ($sys_use_survey) {
1163 return $this->data_array['use_survey'];
1170 * usesPM - whether or not this group has opted to Project Manager.
1172 * @return boolean uses_projman.
1177 return $this->data_array['use_pm'];
1184 * getPlugins - get a list of all available group plugins
1186 * @return array array containing plugin_id => plugin_name
1188 function getPlugins() {
1189 if (!isset($this->plugins_data)) {
1190 $this->plugins_data = array () ;
1191 $res = db_query_params ('SELECT group_plugin.plugin_id, plugins.plugin_name
1192 FROM group_plugin, plugins
1193 WHERE group_plugin.group_id=$1
1194 AND group_plugin.plugin_id=plugins.plugin_id', array ($this->getID()));
1195 $rows = db_numrows($res);
1197 for ($i=0; $i<$rows; $i++) {
1198 $plugin_id = db_result($res,$i,'plugin_id');
1199 $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
1202 return $this->plugins_data ;
1206 * usesPlugin - returns true if the group uses a particular plugin
1208 * @param string name of the plugin
1209 * @return boolean whether plugin is being used or not
1211 function usesPlugin($pluginname) {
1212 $plugins_data = $this->getPlugins() ;
1213 foreach ($plugins_data as $p_id => $p_name) {
1214 if ($p_name == $pluginname) {
1222 * setPluginUse - enables/disables plugins for the group
1224 * @param string name of the plugin
1225 * @param boolean the new state
1226 * @return string database result
1228 function setPluginUse($pluginname, $val=true) {
1229 if ($val == $this->usesPlugin($pluginname)) {
1230 // State is already good, returning
1233 $res = db_query_params ('SELECT plugin_id FROM plugins WHERE plugin_name=$1',
1234 array ($pluginname));
1235 $rows = db_numrows($res);
1237 // Error: no plugin by that name
1240 $plugin_id = db_result($res,0,'plugin_id');
1242 unset ($this->plugins_data) ;
1244 $res = db_query_params ('INSERT INTO group_plugin (group_id, plugin_id) VALUES ($1, $2)',
1245 array ($this->getID(),
1249 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1 AND plugin_id=$2',
1250 array ($this->getID(),
1257 * getDocEmailAddress - get email address(es) to send doc notifications to.
1259 * @return string email address.
1261 function getDocEmailAddress() {
1262 return $this->data_array['new_doc_address'];
1266 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1268 * @return boolean email_on_all_doc_updates.
1270 function docEmailAll() {
1271 return $this->data_array['send_all_docs'];
1276 * getHomePage - The URL for this project's home page.
1278 * @return string homepage URL.
1280 function getHomePage() {
1281 return $this->data_array['homepage'];
1285 * getTags - Tags of this project.
1287 * @return string List of tags.
1289 function getTags() {
1290 $sql = 'SELECT name FROM project_tags WHERE group_id = $1';
1291 $res = db_query_params($sql, array($this->getID()));
1292 return join(', ', util_result_column_to_array($res));
1296 * setTags - Set tags of this project.
1298 * @return string database result.
1300 function setTags($tags) {
1304 $sql='DELETE FROM project_tags WHERE group_id=$1';
1305 $res=db_query_params($sql, array($this->getID()));
1307 $this->setError('Deleting old tags: '.db_error());
1311 $inserted = array();
1312 $tags_array = split('[;,]', $tags);
1313 foreach ($tags_array as $tag) {
1314 $tag = stripslashes($tag);
1315 $tag = preg_replace('/[\t\r\n]/', ' ', $tag);
1316 // Allowed caracteres: [A-Z][a-z][0-9] -_&'#+.
1317 if (preg_match('/[^[:alnum:]| |\-|_|\&|\'|#|\+|\.]/', $tag)) {
1318 $this->setError(_('Bad tag name, you only can use the following characters: [A-Z][a-z][0-9]-_&\'#+. and space'));
1323 $tag = addslashes($tag);
1324 if ($tag == '' || array_search($tag, $inserted) !== false) continue;
1325 $sql='INSERT INTO project_tags (group_id,name) VALUES ($1, $2)';
1326 $res=db_query_params($sql, array($this->getID(), $tag));
1328 $this->setError(_('Setting tags: ').db_error());
1339 * getPermission - Return a Permission for this Group and the specified User.
1341 * @param object The user you wish to get permission for (usually the logged in user).
1342 * @return object The Permission.
1344 function &getPermission(&$_user) {
1345 return permission_get_object($this, $_user);
1350 * userIsAdmin - Return if for this Group the User is admin.
1352 * @return boolean is_admin.
1354 function userIsAdmin() {
1355 $perm =& $this->getPermission( session_get_user() );
1356 if (!$perm || !is_object($perm)) {
1358 } elseif ($perm->isError()) {
1361 return $perm->isAdmin();
1364 function delete($sure,$really_sure,$really_really_sure) {
1365 if (!$sure || !$really_sure || !$really_really_sure) {
1366 $this->setMissingParamsError();
1369 if ($this->getID() == $GLOBALS['sys_news_group'] ||
1370 $this->getID() == 1 ||
1371 $this->getID() == $GLOBALS['sys_stats_group'] ||
1372 $this->getID() == $GLOBALS['sys_peer_rating_group']) {
1373 $this->setError(_('Cannot Delete System Group'));
1376 $perm =& $this->getPermission( session_get_user() );
1377 if (!$perm || !is_object($perm)) {
1378 $this->setPermissionDeniedError();
1380 } elseif ($perm->isError()) {
1381 $this->setPermissionDeniedError();
1383 } elseif (!$perm->isSuperUser()) {
1384 $this->setPermissionDeniedError();
1390 // Remove all the members
1392 $members =& $this->getMembers();
1393 for ($i=0; $i<count($members); $i++) {
1394 $this->removeUser($members[$i]->getID());
1399 $atf = new ArtifactTypeFactory($this);
1400 $at_arr =& $atf->getArtifactTypes();
1401 for ($i=0; $i<count($at_arr); $i++) {
1402 if (!is_object($at_arr[$i])) {
1403 printf (_("Not Object: ArtifactType: %d"),$i);
1406 $at_arr[$i]->delete(1,1);
1411 $ff = new ForumFactory($this);
1412 $f_arr =& $ff->getForums();
1413 for ($i=0; $i<count($f_arr); $i++) {
1414 if (!is_object($f_arr[$i])) {
1415 printf (_("Not Object: Forum: %d"),$i);
1418 $f_arr[$i]->delete(1,1);
1419 //echo 'ForumFactory'.db_error();
1422 // Delete Subprojects
1424 $pgf = new ProjectGroupFactory($this);
1425 $pg_arr =& $pgf->getProjectGroups();
1426 for ($i=0; $i<count($pg_arr); $i++) {
1427 if (!is_object($pg_arr[$i])) {
1428 printf (_("Not Object: ProjectGroup: %d"),$i);
1431 $pg_arr[$i]->delete(1,1);
1432 //echo 'ProjectGroupFactory'.db_error();
1435 // Delete FRS Packages
1437 //$frspf = new FRSPackageFactory($this);
1438 $res = db_query_params ('SELECT * FROM frs_package WHERE group_id=$1',
1439 array ($this->getID())) ;
1440 //echo 'frs_package'.db_error();
1441 //$frsp_arr =& $frspf->getPackages();
1442 while ($arr = db_fetch_array($res)) {
1443 //if (!is_object($pg_arr[$i])) {
1444 // echo "Not Object: ProjectGroup: ".$i;
1447 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1453 $news_group=&group_get_object($GLOBALS['sys_news_group']);
1454 $res = db_query_params ('SELECT forum_id FROM news_bytes WHERE group_id=$1',
1455 array ($this->getID())) ;
1456 for ($i=0; $i<db_numrows($res); $i++) {
1457 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1458 if (!$Forum->delete(1,1)) {
1459 printf (_("Could Not Delete News Forum: %d"),$Forum->getID());
1462 $res = db_query_params ('DELETE FROM news_bytes WHERE group_id=$1',
1463 array ($this->getID())) ;
1468 $res = db_query_params ('DELETE FROM doc_data WHERE group_id=$1',
1469 array ($this->getID())) ;
1470 //echo 'doc_data'.db_error();
1471 $res = db_query_params ('DELETE FROM doc_groups WHERE group_id=$1',
1472 array ($this->getID())) ;
1473 //echo 'doc_groups'.db_error();
1475 // Delete group history
1477 $res = db_query_params ('DELETE FROM group_history WHERE group_id=$1',
1478 array ($this->getID())) ;
1479 //echo 'group_history'.db_error();
1481 // Delete group plugins
1483 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1',
1484 array ($this->getID())) ;
1485 //echo 'group_plugin'.db_error();
1487 // Delete group cvs stats
1489 $res = db_query_params ('DELETE FROM stats_cvs_group WHERE group_id=$1',
1490 array ($this->getID())) ;
1491 //echo 'stats_cvs_group'.db_error();
1495 $sf = new SurveyFactory($this);
1496 $s_arr =& $sf->getSurveys();
1497 for ($i=0; $i<count($s_arr); $i++) {
1498 if (!is_object($s_arr[$i])) {
1499 printf (_("Not Object: Survey: %d"),$i);
1502 $s_arr[$i]->delete();
1503 //echo 'SurveyFactory'.db_error();
1506 // Delete SurveyQuestions
1508 $sqf = new SurveyQuestionFactory($this);
1509 $sq_arr =& $sqf->getSurveyQuestions();
1510 for ($i=0; $i<count($sq_arr); $i++) {
1511 if (!is_object($sq_arr[$i])) {
1512 printf (_("Not Object: SurveyQuestion: %d"),$i);
1515 $sq_arr[$i]->delete();
1516 //echo 'SurveyQuestionFactory'.db_error();
1519 // Delete Mailing List Factory
1521 $mlf = new MailingListFactory($this);
1522 $ml_arr =& $mlf->getMailingLists();
1523 for ($i=0; $i<count($ml_arr); $i++) {
1524 if (!is_object($ml_arr[$i])) {
1525 printf (_("Not Object: MailingList: %d"),$i);
1528 if (!$ml_arr[$i]->delete(1,1)) {
1529 $this->setError(_('Could not properly delete the mailing list'));
1531 //echo 'MailingListFactory'.db_error();
1536 $res = db_query_params ('DELETE FROM trove_group_link WHERE group_id=$1',
1537 array ($this->getID())) ;
1538 $res = db_query_params ('DELETE FROM trove_agg WHERE group_id=$1',
1539 array ($this->getID())) ;
1543 $res = db_query_params ('DELETE FROM project_sums_agg WHERE group_id=$1',
1544 array ($this->getID())) ;
1545 //echo 'project_sums_agg'.db_error();
1546 $res = db_query_params ('INSERT INTO deleted_groups (unix_group_name,delete_date,isdeleted) VALUES ($1, $2, $3)',
1547 array ($this->getUnixName(),
1550 //echo 'InsertIntoDeleteQueue'.db_error();
1551 $res = db_query_params ('DELETE FROM groups WHERE group_id=$1',
1552 array ($this->getID())) ;
1553 //echo 'DeleteGroup'.db_error();
1559 $hook_params = array ();
1560 $hook_params['group'] = $this;
1561 $hook_params['group_id'] = $this->getID();
1562 plugin_hook ("group_delete", $hook_params);
1564 if (isset($GLOBALS['sys_upload_dir']) && $this->getUnixName()) {
1565 exec('/bin/rm -rf '.$GLOBALS['sys_upload_dir'].'/'.$this->getUnixName().'/');
1567 if (isset($GLOBALS['sys_ftp_upload_dir']) && $this->getUnixName()) {
1568 exec('/bin/rm -rf '.$GLOBALS['sys_ftp_upload_dir'].'/'.$this->getUnixName().'/');
1573 $res = db_query_params ('DELETE FROM rep_group_act_monthly WHERE group_id=$1',
1574 array ($this->getID())) ;
1575 //echo 'rep_group_act_monthly'.db_error();
1576 $res = db_query_params ('DELETE FROM rep_group_act_weekly WHERE group_id=$1',
1577 array ($this->getID())) ;
1578 //echo 'rep_group_act_weekly'.db_error();
1579 $res = db_query_params ('DELETE FROM rep_group_act_daily WHERE group_id=$1',
1580 array ($this->getID())) ;
1581 //echo 'rep_group_act_daily'.db_error();
1582 unset($this->data_array);
1590 Basic functions to add/remove users to/from a group
1591 and update their permissions
1597 * addUser - controls adding a user to a group.
1599 * @param string Unix name of the user to add OR integer user_id.
1600 * @param int The role_id this user should have.
1601 * @return boolean success.
1604 function addUser($user_identifier,$role_id) {
1607 Admins can add users to groups
1610 $perm =& $this->getPermission( session_get_user() );
1611 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1612 $this->setPermissionDeniedError();
1618 get user id for this user's unix_name
1620 if (is_int ($user_identifier)) { // user_id or user_name
1621 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array ($user_identifier)) ;
1623 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array ($user_identifier)) ;
1625 if (db_numrows($res_newuser) > 0) {
1627 // make sure user is active
1629 if (db_result($res_newuser,0,'status') != 'A') {
1630 $this->setError(_('User is not active. Only active users can be added.'));
1636 // user was found - set new user_id var
1638 $user_id = db_result($res_newuser,0,'user_id');
1641 // if not already a member, add them
1643 $res_member = db_query_params ('SELECT user_id
1645 WHERE user_id=$1 AND group_id=$2',
1646 array ($user_id, $this->getID())) ;
1648 if (db_numrows($res_member) < 1) {
1650 // Create this user's row in the user_group table
1652 $res = db_query_params ('INSERT INTO user_group
1653 (user_id,group_id,admin_flags,forum_flags,project_flags,
1654 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
1655 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)',
1667 //verify the insert worked
1668 if (!$res || db_affected_rows($res) < 1) {
1669 $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
1674 // check and create if group doesn't exists
1676 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
1677 if (!$SYS->sysCheckCreateGroup($this->getID())){
1678 $this->setError($SYS->getErrorMessage());
1683 // check and create if user doesn't exists
1685 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1686 if (!$SYS->sysCheckCreateUser($user_id)) {
1687 $this->setError($SYS->getErrorMessage());
1694 $role = new Role($this,$role_id);
1695 if (!$role || !is_object($role)) {
1696 $this->setError(_('Error Getting Role Object'));
1699 } elseif ($role->isError()) {
1700 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1704 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
1705 if (!$role->setUser($user_id)) {
1706 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1712 // user was already a member
1713 // make sure they are set up
1715 $user=&user_get_object($user_id,$res_newuser);
1716 $user->fetchData($user->getID());
1717 $role = new Role($this,$role_id);
1718 if (!$role || !is_object($role)) {
1719 $this->setError(_('Error Getting Role Object'));
1722 } elseif ($role->isError()) {
1723 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1727 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
1728 if (!$role->setUser($user_id)) {
1729 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1734 // set up their system info
1736 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1737 if (!$SYS->sysCheckCreateUser($user_id)) {
1738 $this->setError($SYS->getErrorMessage());
1747 // user doesn't exist
1749 $this->setError(_('ERROR: User does not exist'));
1754 $hook_params['group'] = $this;
1755 $hook_params['group_id'] = $this->getID();
1756 $hook_params['user'] = &user_get_object($user_id);
1757 $hook_params['user_id'] = $user_id;
1758 plugin_hook ("group_adduser", $hook_params);
1763 $this->addHistory('Added User',$user_identifier);
1769 * removeUser - controls removing a user from a group.
1771 * Users can remove themselves.
1773 * @param int The ID of the user to remove.
1774 * @return boolean success.
1776 function removeUser($user_id) {
1777 global $SYS,$sys_database_type;
1779 if ($user_id==user_getid()) {
1780 //users can remove themselves
1781 //everyone else must be a project admin
1783 $perm =& $this->getPermission( session_get_user() );
1785 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1786 $this->setPermissionDeniedError();
1792 $res = db_query_params ('DELETE FROM user_group WHERE group_id=$1 AND user_id=$2',
1793 array ($this->getID(),
1795 if (!$res || db_affected_rows($res) < 1) {
1796 $this->setError(sprintf(_('ERROR: User not removed: %s'),db_error()));
1801 // reassign open artifacts to id=100
1803 $res = db_query_params ('UPDATE artifact SET assigned_to=100
1804 WHERE group_artifact_id
1805 IN (SELECT group_artifact_id
1806 FROM artifact_group_list
1807 WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
1808 array ($this->getID(),
1811 $this->setError(sprintf(_('ERROR: DB: artifact: %s'),db_error()));
1817 // reassign open tasks to id=100
1818 // first have to purge any assignments that would cause
1819 // conflict with existing assignment to 100
1821 if ($sys_database_type == 'mysql') {
1823 SELECT pt.project_task_id
1824 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1825 WHERE pt.group_project_id = pgl.group_project_id
1826 AND pat.project_task_id=pt.project_task_id
1827 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."'
1828 AND pat.assigned_to_id='$user_id' INTO @task_list;
1829 DELETE FROM project_assigned_to WHERE project_task_id IN ( @task_list ) AND assigned_to_id='100'");
1831 $res = db_next_result();
1834 $res = db_query_params ('DELETE FROM project_assigned_to
1835 WHERE project_task_id IN (SELECT pt.project_task_id
1836 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1837 WHERE pt.group_project_id = pgl.group_project_id
1838 AND pat.project_task_id=pt.project_task_id
1839 AND pt.status_id=1 AND pgl.group_id=$1
1840 AND pat.assigned_to_id=$2)
1841 AND assigned_to_id=100',
1842 array ($this->getID(),
1846 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),1,db_error()));
1850 $res = db_query_params ('UPDATE project_assigned_to SET assigned_to_id=100
1851 WHERE project_task_id IN (SELECT pt.project_task_id
1852 FROM project_task pt, project_group_list pgl
1853 WHERE pt.group_project_id = pgl.group_project_id
1854 AND pt.status_id=1 AND pgl.group_id=$1)
1855 AND assigned_to_id=$2',
1856 array ($this->getID(),
1859 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),2,db_error()));
1865 // Remove user from system
1867 //echo "<h2>Group::addUser SYS->sysGroupRemoveUser(".$this->getID().",$user_id)</h2>";
1868 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
1869 $this->setError($SYS->getErrorMessage());
1874 $hook_params['group'] = $this;
1875 $hook_params['group_id'] = $this->getID();
1876 $hook_params['user'] = &user_get_object($user_id);
1877 $hook_params['user_id'] = $user_id;
1878 plugin_hook ("group_removeuser", $hook_params);
1881 $this->addHistory('Removed User',$user_id);
1888 * updateUser - controls updating a user's role in this group.
1890 * @param int The ID of the user.
1891 * @param int The role_id to set this user to.
1892 * @return boolean success.
1894 function updateUser($user_id,$role_id) {
1897 $perm =& $this->getPermission( session_get_user() );
1898 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1899 $this->setPermissionDeniedError();
1903 $role = new Role($this,$role_id);
1904 if (!$role || !is_object($role)) {
1905 $this->setError(_('Could Not Get Role'));
1907 } elseif ($role->isError()) {
1908 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1911 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
1912 if (!$role->setUser($user_id)) {
1913 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1918 $this->addHistory('Updated User',$user_id);
1923 * addHistory - Makes an audit trail entry for this project.
1925 * @param string The name of the field.
1926 * @param string The Old Value for this $field_name.
1927 * @return database result handle.
1930 function addHistory($field_name, $old_value) {
1931 return db_query_params ('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
1932 VALUES ($1,$2,$3,$4,$5)',
1933 array ($this->getID(),
1941 * activateUsers - Make sure that group members have unix accounts.
1943 * Setup unix accounts for group members. Can be called even
1944 * if members are already active.
1948 function activateUsers() {
1951 Activate member(s) of the project
1954 $member_res = db_query_params ('SELECT user_id, role_id FROM user_group WHERE group_id=$1',
1955 array ($this->getID())) ;
1957 $rows = db_numrows($member_res);
1961 for ($i=0; $i<$rows; $i++) {
1963 $member =& user_get_object(db_result($member_res,$i,'user_id'));
1964 $roleId = db_result($member_res,$i,'role_id');
1966 if (!$member || !is_object($member)) {
1967 $this->setError(_('Error getting member object'));
1969 } else if ($member->isError()) {
1970 $this->setError(sprintf(_('Error getting member object: %s'),$member->getErrorMessage()));
1974 if (!$this->addUser($member->getUnixName(),$roleId)) {
1985 * getMembers - returns array of User objects for this project
1987 * @return array of User objects for this group.
1989 function &getMembers() {
1990 if (!isset($this->membersArr)) {
1991 $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',
1992 array ($this->getID())) ;
1993 while ($arr =& db_fetch_array($res)) {
1994 $this->membersArr[] =& new GFUser($arr['user_id'],$arr);
1997 return $this->membersArr;
2001 * approve - Approve pending project.
2003 * @param object The User object who is doing the updating.
2006 function approve(&$user) {
2008 if ($this->getStatus()=='A') {
2009 $this->setError(_("Group already active"));
2015 // Step 1: Activate group and create LDAP entries
2016 if (!$this->setStatus($user, 'A')) {
2021 // Switch to system language for item creation
2022 setup_gettext_from_sys_lang ();
2027 // Tracker Integration
2030 $ats = new ArtifactTypes($this);
2031 if (!$ats || !is_object($ats)) {
2032 $this->setError(_('Error creating ArtifactTypes object'));
2034 setup_gettext_from_context();
2036 } else if ($ats->isError()) {
2037 $this->setError(sprintf (_('ATS%d: %s'), 1, $ats->getErrorMessage()));
2039 setup_gettext_from_context();
2042 if (!$ats->createTrackers()) {
2043 $this->setError(sprintf (_('ATS%d: %s'), 2, $ats->getErrorMessage()));
2045 setup_gettext_from_context();
2051 // Forum Integration
2054 $f = new Forum($this);
2055 if (!$f->create(_('Open-Discussion'),_('General Discussion'),1,'',1,0)) {
2056 $this->setError(sprintf (_('F%d: %s'), 1, $f->getErrorMessage()));
2058 setup_gettext_from_context();
2061 $f = new Forum($this);
2062 if (!$f->create(_('Help'),_('Get Public Help'),1,'',1,0)) {
2063 $this->setError(sprintf (_('F%d: %s'), 2, $f->getErrorMessage()));
2065 setup_gettext_from_context();
2068 $f = new Forum($this);
2069 if (!$f->create(_('Developers'),_('Project Developer Discussion'),0,'',1,0)) {
2070 $this->setError(sprintf (_('F%d: %s'), 3, $f->getErrorMessage()));
2072 setup_gettext_from_context();
2078 // Doc Mgr Integration
2081 $dg = new DocumentGroup($this);
2082 if (!$dg->create(_('Uncategorized Submissions'))) {
2083 $this->setError(sprintf(_('DG: %s'),$dg->getErrorMessage()));
2085 setup_gettext_from_context();
2094 $frs = new FRSPackage($this);
2095 if (!$frs->create($this->getUnixName())) {
2096 $this->setError(sprintf(_('FRSP: %s'),$frs->getErrorMessage()));
2098 setup_gettext_from_context();
2107 $pg = new ProjectGroup($this);
2108 if (!$pg->create(_('To Do'),_('Things We Have To Do'),1)) {
2109 $this->setError(sprintf(_('PG%d: %s'),1,$pg->getErrorMessage()));
2111 setup_gettext_from_context();
2114 $pg = new ProjectGroup($this);
2115 if (!$pg->create(_('Next Release'),_('Items For Our Next Release'),1)) {
2116 $this->setError(sprintf(_('PG%d: %s'),2,$pg->getErrorMessage()));
2118 setup_gettext_from_context();
2124 // Set Default Roles
2128 $admin_group = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1 AND admin_flags=$2',
2129 array ($this->getID(),
2131 if (db_numrows($admin_group) > 0) {
2132 $idadmin_group = db_result($admin_group,0,'user_id');
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 //change assistant for webcal
2180 $params[0] = $idadmin_group ;
2181 $params[1] = $this->getID();
2182 plugin_hook('change_cal_permission_default',$params);
2190 * sendApprovalEmail - Send new project email.
2192 * @return boolean success.
2195 function sendApprovalEmail() {
2196 $res_admins = db_query_params ('
2197 SELECT users.user_name,users.email,users.language,users.user_id
2198 FROM users,user_group
2199 WHERE users.user_id=user_group.user_id
2200 AND user_group.group_id=$1
2201 AND user_group.admin_flags=$2',
2202 array ($this->getID(),
2205 if (db_numrows($res_admins) < 1) {
2206 $this->setError(_("Group does not have any administrators."));
2210 // send one email per admin
2211 while ($row_admins = db_fetch_array($res_admins)) {
2212 $admin =& user_get_object($row_admins['user_id']);
2213 setup_gettext_for_user ($admin) ;
2215 $message=sprintf(_('Your project registration for %4$s has been approved.
2217 Project Full Name: %1$s
2218 Project Unix Name: %2$s
2220 Your DNS will take up to a day to become active on our site.
2221 Your web site is accessible through your shell account. Please read
2222 site documentation (see link below) about intended usage, available
2223 services, and directory layout of the account.
2226 own project page in %4$s while logged in, you will find
2227 additional menu functions to your left labeled \'Project Admin\'.
2229 We highly suggest that you now visit %4$s and create a public
2230 description for your project. This can be done by visiting your project
2231 page while logged in, and selecting \'Project Admin\' from the menus
2232 on the left (or by visiting %3$s
2235 Your project will also not appear in the Trove Software Map (primary
2236 list of projects hosted on %4$s which offers great flexibility in
2237 browsing and search) until you categorize it in the project administration
2238 screens. So that people can find your project, you should do this now.
2239 Visit your project while logged in, and select \'Project Admin\' from the
2242 Enjoy the system, and please tell others about %4$s. Let us know
2243 if there is anything we can do to help you.
2246 $this->getPublicName(),
2247 $this->getUnixName(),
2248 util_make_url ('/project/admin/?group_id='.$this->getID()),
2249 $GLOBALS['sys_name']);
2251 util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), $GLOBALS['sys_name']), $message);
2253 setup_gettext_from_context();
2261 * sendRejectionEmail - Send project rejection email.
2263 * This function sends out a rejection message to a user who
2264 * registered a project.
2266 * @param int The id of the response to use.
2267 * @param string The rejection message.
2268 * @return completion status.
2271 function sendRejectionEmail($response_id, $message="zxcv") {
2272 $res_admins = db_query_params ('
2273 SELECT u.email, u.language, u.user_id
2274 FROM users u, user_group ug
2275 WHERE ug.group_id=$1
2276 AND u.user_id=ug.user_id',
2277 array ($this->getID())) ;
2278 if (db_numrows($res_admins) < 1) {
2279 $this->setError(_("Group does not have any administrators."));
2283 while ($row_admins = db_fetch_array($res_admins)) {
2284 $admin =& user_get_object($row_admins['user_id']);
2285 setup_gettext_for_user ($admin) ;
2287 $response=sprintf(_('Your project registration for %3$s has been denied.
2289 Project Full Name: %1$s
2290 Project Unix Name: %2$s
2292 Reasons for negative decision:
2294 '), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name']);
2296 // Check to see if they want to send a custom rejection response
2297 if ($response_id == 0) {
2298 $response .= $message;
2300 $response .= db_result (
2301 db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array ($response_id)),
2306 util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), $GLOBALS['sys_name']), $response);
2307 setup_gettext_from_context();
2314 * sendNewProjectNotificationEmail - Send new project notification email.
2316 * This function sends out a notification email to the
2317 * SourceForge admin user when a new project is
2320 * @return boolean success.
2323 function sendNewProjectNotificationEmail() {
2324 // Get the user who wants to register the project
2325 $res = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1',
2326 array ($this->getID())) ;
2328 if (db_numrows($res) < 1) {
2329 $this->setError(_("Could not find user who has submitted the project."));
2333 $submitter =& user_get_object(db_result($res,0,'user_id'));
2336 $res = db_query_params ('SELECT users.email, users.language, users.user_id
2337 FROM users, user_group
2339 AND user_group.admin_flags=$1
2340 AND users.user_id=user_group.user_id',
2343 if (db_numrows($res) < 1) {
2344 $this->setError(_("There is no administrator to send the mail."));
2348 for ($i=0; $i<db_numrows($res) ; $i++) {
2349 $admin_email = db_result($res,$i,'email') ;
2350 $admin =& user_get_object(db_result($res,$i,'user_id'));
2351 setup_gettext_for_user ($admin) ;
2353 $message=sprintf(_('New %1$s Project Submitted
2355 Project Full Name: %2$s
2356 Submitted Description: %3$s
2357 Submitter: %5$s (%6$s)
2359 Please visit the following URL to approve or reject this project:
2361 $GLOBALS['sys_name'],
2362 $this->getPublicName(),
2363 util_unconvert_htmlspecialchars($this->getRegistrationPurpose()),
2364 util_make_url ('/admin/approve-pending.php'),
2365 $submitter->getRealName(),
2366 $submitter->getUnixName());
2367 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2368 setup_gettext_from_context();
2372 $email = $submitter->getEmail() ;
2373 setup_gettext_for_user ($submitter) ;
2375 $message=sprintf(_('New %1$s Project Submitted
2377 Project Full Name: %2$s
2378 Submitted Description: %3$s
2380 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()), $GLOBALS['sys_default_domain']);
2382 util_send_message($email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2383 setup_gettext_from_context();
2392 * validateGroupName - Validate the group name
2394 * @param string Group name.
2396 * @return an error false and set an error is the group name is invalide otherwise return true
2398 function validateGroupName($group_name) {
2399 if (strlen($group_name)<3) {
2400 $this->setError(_('Group name is too short'));
2402 } else if (strlen(htmlspecialchars($group_name))>50) {
2403 $this->setError(_('Group name is too long'));
2405 } else if ($group=group_get_object_by_publicname($group_name)) {
2406 $this->setError(_('Group name already taken'));
2418 * group_getname() - get the group name
2420 * @param int The group ID
2424 function group_getname ($group_id = 0) {
2425 $grp = &group_get_object($group_id);
2427 return $grp->getPublicName();
2434 * group_getunixname() - get the unixname for a group
2436 * @param int The group ID
2440 function group_getunixname ($group_id) {
2441 $grp = &group_get_object($group_id);
2443 return $grp->getUnixName();
2450 * group_get_result() - Get the group object result ID.
2452 * @param int The group ID
2456 function &group_get_result($group_id=0) {
2457 $grp = &group_get_object($group_id);
2459 return $grp->getData();
2466 * getUnixStatus - Status of activation of unix account.
2468 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2470 function getUnixStatus() {
2471 return $this->data_array['unix_status'];
2475 * setUnixStatus - Sets status of activation of unix account.
2477 * @param string The unix status.
2483 * @return boolean success.
2485 function setUnixStatus($status) {
2488 $res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
2493 $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
2497 if ($status == 'A') {
2498 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2499 $this->setError($SYS->getErrorMessage());
2504 if ($SYS->sysCheckGroup($this->getID())) {
2505 if (!$SYS->sysRemoveGroup($this->getID())) {
2506 $this->setError($SYS->getErrorMessage());
2513 $this->data_array['unix_status']=$status;
2521 // c-file-style: "bsd"