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 * 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) {
559 $homepage = ltrim($homepage);
561 $homepage=$GLOBALS['sys_default_domain'].'/projects/'.$this->getUnixName().'/';
564 if (strlen(htmlspecialchars($short_description))>255) {
565 $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
571 //XXX not yet actived logo_image_id='$logo_image_id',
572 $res = db_query_params ('UPDATE groups
575 short_description=$3,
580 use_pm_depend_box=$8,
592 array (htmlspecialchars($group_name),
594 htmlspecialchars($short_description),
613 $this->setError(sprintf(_('Error updating project information: %s'), db_error()));
618 if ($this->setTags($tags) === false) {
623 $hook_params = array ();
624 $hook_params['group'] = $this;
625 $hook_params['group_id'] = $this->getID();
626 $hook_params['group_homepage'] = $homepage;
627 $hook_params['group_name'] = htmlspecialchars($group_name);
628 $hook_params['group_description'] = htmlspecialchars($short_description);
629 plugin_hook ("group_update", $hook_params);
631 // Log the audit trail
632 $this->addHistory('Changed Public Info', '');
634 if (!$this->fetchData($this->getID())) {
643 * getID - Simply return the group_id for this object.
645 * @return int group_id.
648 return $this->data_array['group_id'];
652 * getType() - Foundry, project, etc.
654 * @return int The type flag from the database.
657 return $this->data_array['type_id'];
662 * getStatus - the status code.
664 * Statuses char include I,H,A,D.
666 function getStatus() {
667 return $this->data_array['status'];
671 * setStatus - set the status code.
673 * Statuses include I,H,A,D.
675 * @param object User requesting operation (for access control).
676 * @param string Status value.
677 * @return boolean success.
680 function setStatus(&$user, $status) {
683 $perm =& $this->getPermission($user);
684 if (!$perm || !is_object($perm)) {
685 $this->setPermissionDeniedError();
687 } elseif (!$perm->isSuperUser()) {
688 $this->setPermissionDeniedError();
692 // Projects in 'A' status can only go to 'H' or 'D'
693 // Projects in 'D' status can only go to 'A'
694 // Projects in 'P' status can only go to 'A' OR 'D'
695 // Projects in 'I' status can only go to 'P'
696 // Projects in 'H' status can only go to 'A' OR 'D'
697 $allowed_status_changes = array(
698 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
699 'IP'=>1,'HA'=>1,'HD'=>1
702 // Check that status transition is valid
703 if ($this->getStatus() != $status
704 && !$allowed_status_changes[$this->getStatus().$status]) {
705 $this->setError(_('Invalid Status Change'));
711 $res = db_query_params ('UPDATE groups
713 WHERE group_id=$2', array ($status, $this->getID())) ;
715 if (!$res || db_affected_rows($res) < 1) {
716 $this->setError(sprintf(_('ERROR: DB: Could not change group status: %s'),db_error()));
722 // Activate system group, if not yet
723 if (!$SYS->sysCheckGroup($this->getID())) {
724 if (!$SYS->sysCreateGroup($this->getID())) {
725 $this->setError($SYS->getErrorMessage());
730 if (!$this->activateUsers()) {
735 /* Otherwise, the group is not active, and make sure that
736 System group is not active either */
737 } else if ($SYS->sysCheckGroup($this->getID())) {
738 if (!$SYS->sysRemoveGroup($this->getID())) {
739 $this->setError($SYS->getErrorMessage());
745 $hook_params = array ();
746 $hook_params['group'] = $this;
747 $hook_params['group_id'] = $this->getID();
748 $hook_params['status'] = $status;
749 plugin_hook ("group_setstatus", $hook_params);
753 // Log the audit trail
754 if ($status != $this->getStatus()) {
755 $this->addHistory('Status', $this->getStatus());
758 $this->data_array['status'] = $status;
763 * isProject - Simple boolean test to see if it's a project or not.
765 * @return boolean is_project.
767 function isProject() {
768 if ($this->getType()==1) {
776 * isPublic - Simply returns the is_public flag from the database.
778 * @return boolean is_public.
780 function isPublic() {
781 return $this->data_array['is_public'];
785 * isActive - Database field status of 'A' returns true.
787 * @return boolean is_active.
789 function isActive() {
790 if ($this->getStatus()=='A') {
798 * getUnixName - the unix_name
800 * @return string unix_name.
802 function getUnixName() {
803 return strtolower($this->data_array['unix_group_name']);
807 * getPublicName - the full-length public name.
809 * @return string The group_name.
811 function getPublicName() {
812 return $this->data_array['group_name'];
816 * getRegisterPurpose - the text description of the purpose of this project.
818 * @return string The description.
820 function getRegisterPurpose() {
821 return $this->data_array['register_purpose'];
825 * getDescription - the text description of this project.
827 * @return string The description.
829 function getDescription() {
830 return $this->data_array['short_description'];
834 * getStartDate - the unix time this project was registered.
836 * @return int (unix time) of registration.
838 function getStartDate() {
839 return $this->data_array['register_time'];
843 * getLogoImageID - the id of the logo in the database for this project.
845 * @return int The ID of logo image in db_images table (or 100 if none).
847 function getLogoImageID() {
848 return $this->data_array['logo_image_id'];
852 * getUnixBox - the hostname of the unix box where this project is located.
854 * @return string The name of the unix machine for the group.
856 function getUnixBox() {
857 return $this->data_array['unix_box'];
861 * getSCMBox - the hostname of the scm box where this project is located.
863 * @return string The name of the unix machine for the group.
865 function getSCMBox() {
866 return $this->data_array['scm_box'];
869 * setSCMBox - the hostname of the scm box where this project is located.
871 * @param string The name of the new SCM_BOX
873 function setSCMBox($scm_box) {
876 $res = db_query_params ('UPDATE groups SET scm_box=$1 WHERE group_id=$2', array ($scm_box, $this->getID ()));
878 $this->addHistory('scm_box', $this->data_array['scm_box']);
879 $this->data_array['scm_box']=$scm_box;
884 $this->setError(_("Couldn't insert SCM_BOX to database"));
888 $this->setError(_("SCM Box can't be empty"));
894 * getDomain - the hostname.domain where their web page is located.
896 * @return string The name of the group [web] domain.
898 function getDomain() {
899 return $this->data_array['http_domain'];
903 * getLicense - the license they chose.
905 * @return int ident of group license.
907 function getLicense() {
908 return $this->data_array['license'];
912 * getLicenseName - the name of the license
914 * @return string license name
916 function getLicenseName() {
917 $licenses =& group_get_licenses();
918 if(isset($licenses[$this->data_array['license']])) {
919 return $licenses[$this->data_array['license']];
926 * getLicenseOther - optional string describing license.
928 * @return string The custom license.
930 function getLicenseOther() {
931 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
932 return $this->data_array['license_other'];
939 * getRegistrationPurpose - the text description of the purpose of this project.
941 * @return string The application for project hosting.
943 function getRegistrationPurpose() {
944 return $this->data_array['register_purpose'];
949 * getAdmins() - Get array of Admin user objects.
951 * @return array Array of User objects.
953 function &getAdmins() {
954 // this function gets all group admins in order to send Jabber and mail messages
955 $res = db_query_params ('SELECT user_id FROM user_group WHERE admin_flags=$1 AND group_id=$2',
956 array ('A', $this->getID()));
957 $user_ids=util_result_column_to_array($res);
958 return user_get_objects($user_ids);
963 Common Group preferences for tools
968 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
970 * @return boolean enable_scm.
972 function enableAnonSCM() {
973 if ($this->isPublic() && $this->usesSCM()) {
974 return $this->data_array['enable_anonscm'];
980 function SetUsesAnonSCM ($booleanparam) {
982 $booleanparam = $booleanparam ? 1 : 0 ;
983 $res = db_query_params ('UPDATE groups SET enable_anonscm=$1 WHERE group_id=$2',
984 array ($booleanparam, $this->getID()));
986 $this->data_array['enable_anonscm']=$booleanparam;
994 function setUsesSCM ($booleanparam) {
996 $booleanparam = $booleanparam ? 1 : 0 ;
997 $res = db_query_params ('UPDATE groups SET use_scm=$1 WHERE group_id=$2',
998 array ($booleanparam, $this->getID()));
1000 $this->data_array['use_scm']=$booleanparam;
1009 * enablePserver - whether or not this group has opted to enable Pserver.
1011 * @return boolean enable_pserver.
1013 function enablePserver() {
1014 if ($this->usesSCM()) {
1015 return $this->data_array['enable_pserver'];
1021 function SetUsesPserver ($booleanparam) {
1023 $booleanparam = $booleanparam ? 1 : 0 ;
1024 $res = db_query_params ('UPDATE groups SET enable_pserver=$1 WHERE group_id=$2',
1025 array ($booleanparam, $this->getID()));
1027 $this->data_array['enable_pserver']=$booleanparam;
1036 * usesSCM - whether or not this group has opted to use SCM.
1038 * @return boolean uses_scm.
1040 function usesSCM() {
1041 global $sys_use_scm;
1043 return $this->data_array['use_scm'];
1050 * usesMail - whether or not this group has opted to use mailing lists.
1052 * @return boolean uses_mail.
1054 function usesMail() {
1055 global $sys_use_mail;
1056 if ($sys_use_mail) {
1057 return $this->data_array['use_mail'];
1064 * usesNews - whether or not this group has opted to use news.
1066 * @return boolean uses_news.
1068 function usesNews() {
1069 global $sys_use_news;
1070 if ($sys_use_news) {
1071 return $this->data_array['use_news'];
1078 * usesForum - whether or not this group has opted to use discussion forums.
1080 * @return boolean uses_forum.
1082 function usesForum() {
1083 global $sys_use_forum;
1084 if ($sys_use_forum) {
1085 return $this->data_array['use_forum'];
1092 * usesStats - whether or not this group has opted to use stats.
1094 * @return boolean uses_stats.
1096 function usesStats() {
1097 return $this->data_array['use_stats'];
1101 * usesFRS - whether or not this group has opted to use file release system.
1103 * @return boolean uses_frs.
1105 function usesFRS() {
1106 global $sys_use_frs;
1108 return $this->data_array['use_frs'];
1115 * usesTracker - whether or not this group has opted to use tracker.
1117 * @return boolean uses_tracker.
1119 function usesTracker() {
1120 global $sys_use_tracker;
1121 if ($sys_use_tracker) {
1122 return $this->data_array['use_tracker'];
1129 * usesDocman - whether or not this group has opted to use docman.
1131 * @return boolean uses_docman.
1133 function usesDocman() {
1134 global $sys_use_docman;
1135 if ($sys_use_docman) {
1136 return $this->data_array['use_docman'];
1143 * usesFTP - whether or not this group has opted to use FTP.
1145 * @return boolean uses_ftp.
1147 function usesFTP() {
1148 global $sys_use_ftp;
1150 return $this->data_array['use_ftp'];
1157 * usesSurvey - whether or not this group has opted to use surveys.
1159 * @return boolean uses_survey.
1161 function usesSurvey() {
1162 global $sys_use_survey;
1163 if ($sys_use_survey) {
1164 return $this->data_array['use_survey'];
1171 * usesPM - whether or not this group has opted to Project Manager.
1173 * @return boolean uses_projman.
1178 return $this->data_array['use_pm'];
1185 * getPlugins - get a list of all available group plugins
1187 * @return array array containing plugin_id => plugin_name
1189 function getPlugins() {
1190 if (!isset($this->plugins_data)) {
1191 $this->plugins_data = array () ;
1192 $res = db_query_params ('SELECT group_plugin.plugin_id, plugins.plugin_name
1193 FROM group_plugin, plugins
1194 WHERE group_plugin.group_id=$1
1195 AND group_plugin.plugin_id=plugins.plugin_id', array ($this->getID()));
1196 $rows = db_numrows($res);
1198 for ($i=0; $i<$rows; $i++) {
1199 $plugin_id = db_result($res,$i,'plugin_id');
1200 $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
1203 return $this->plugins_data ;
1207 * usesPlugin - returns true if the group uses a particular plugin
1209 * @param string name of the plugin
1210 * @return boolean whether plugin is being used or not
1212 function usesPlugin($pluginname) {
1213 $plugins_data = $this->getPlugins() ;
1214 foreach ($plugins_data as $p_id => $p_name) {
1215 if ($p_name == $pluginname) {
1223 * setPluginUse - enables/disables plugins for the group
1225 * @param string name of the plugin
1226 * @param boolean the new state
1227 * @return string database result
1229 function setPluginUse($pluginname, $val=true) {
1230 if ($val == $this->usesPlugin($pluginname)) {
1231 // State is already good, returning
1234 $res = db_query_params ('SELECT plugin_id FROM plugins WHERE plugin_name=$1',
1235 array ($pluginname));
1236 $rows = db_numrows($res);
1238 // Error: no plugin by that name
1241 $plugin_id = db_result($res,0,'plugin_id');
1243 unset ($this->plugins_data) ;
1245 $res = db_query_params ('INSERT INTO group_plugin (group_id, plugin_id) VALUES ($1, $2)',
1246 array ($this->getID(),
1250 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1 AND plugin_id=$2',
1251 array ($this->getID(),
1258 * getDocEmailAddress - get email address(es) to send doc notifications to.
1260 * @return string email address.
1262 function getDocEmailAddress() {
1263 return $this->data_array['new_doc_address'];
1267 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1269 * @return boolean email_on_all_doc_updates.
1271 function docEmailAll() {
1272 return $this->data_array['send_all_docs'];
1277 * getHomePage - The URL for this project's home page.
1279 * @return string homepage URL.
1281 function getHomePage() {
1282 return $this->data_array['homepage'];
1286 * getTags - Tags of this project.
1288 * @return string List of tags.
1290 function getTags() {
1291 $sql = 'SELECT name FROM project_tags WHERE group_id = $1';
1292 $res = db_query_params($sql, array($this->getID()));
1293 return join(', ', util_result_column_to_array($res));
1297 * setTags - Set tags of this project.
1299 * @return string database result.
1301 function setTags($tags) {
1303 $sql='DELETE FROM project_tags WHERE group_id=$1';
1304 $res=db_query_params($sql, array($this->getID()));
1306 $this->setError('Deleting old tags: '.db_error());
1310 $inserted = array();
1311 $tags_array = split('[;,]', $tags);
1312 foreach ($tags_array as $tag) {
1313 $tag = stripslashes($tag);
1314 $tag = preg_replace('/[\t\r\n]/', ' ', $tag);
1315 // Allowed caracteres: [A-Z][a-z][0-9] -_&'#+.
1316 if (preg_match('/[^[:alnum:]| |\-|_|\&|\'|#|\+|\.]/', $tag)) {
1317 $this->setError(_('Bad tag name, you only can use the following characters: [A-Z][a-z][0-9]-_&\'#+. and space'));
1322 $tag = addslashes($tag);
1323 if ($tag == '' || array_search($tag, $inserted) !== false) continue;
1324 $sql='INSERT INTO project_tags (group_id,name) VALUES ($1, $2)';
1325 $res=db_query_params($sql, array($this->getID(), $tag));
1327 $this->setError(_('Setting tags: ').db_error());
1338 * getPermission - Return a Permission for this Group and the specified User.
1340 * @param object The user you wish to get permission for (usually the logged in user).
1341 * @return object The Permission.
1343 function &getPermission(&$_user) {
1344 return permission_get_object($this, $_user);
1349 * userIsAdmin - Return if for this Group the User is admin.
1351 * @return boolean is_admin.
1353 function userIsAdmin() {
1354 $perm =& $this->getPermission( session_get_user() );
1355 if (!$perm || !is_object($perm)) {
1357 } elseif ($perm->isError()) {
1360 return $perm->isAdmin();
1363 function delete($sure,$really_sure,$really_really_sure) {
1364 if (!$sure || !$really_sure || !$really_really_sure) {
1365 $this->setMissingParamsError();
1368 if ($this->getID() == $GLOBALS['sys_news_group'] ||
1369 $this->getID() == 1 ||
1370 $this->getID() == $GLOBALS['sys_stats_group'] ||
1371 $this->getID() == $GLOBALS['sys_peer_rating_group']) {
1372 $this->setError(_('Cannot Delete System Group'));
1375 $perm =& $this->getPermission( session_get_user() );
1376 if (!$perm || !is_object($perm)) {
1377 $this->setPermissionDeniedError();
1379 } elseif ($perm->isError()) {
1380 $this->setPermissionDeniedError();
1382 } elseif (!$perm->isSuperUser()) {
1383 $this->setPermissionDeniedError();
1389 // Remove all the members
1391 $members =& $this->getMembers();
1392 for ($i=0; $i<count($members); $i++) {
1393 $this->removeUser($members[$i]->getID());
1398 $atf = new ArtifactTypeFactory($this);
1399 $at_arr =& $atf->getArtifactTypes();
1400 for ($i=0; $i<count($at_arr); $i++) {
1401 if (!is_object($at_arr[$i])) {
1402 printf (_("Not Object: ArtifactType: %d"),$i);
1405 $at_arr[$i]->delete(1,1);
1410 $ff = new ForumFactory($this);
1411 $f_arr =& $ff->getForums();
1412 for ($i=0; $i<count($f_arr); $i++) {
1413 if (!is_object($f_arr[$i])) {
1414 printf (_("Not Object: Forum: %d"),$i);
1417 $f_arr[$i]->delete(1,1);
1418 //echo 'ForumFactory'.db_error();
1421 // Delete Subprojects
1423 $pgf = new ProjectGroupFactory($this);
1424 $pg_arr =& $pgf->getProjectGroups();
1425 for ($i=0; $i<count($pg_arr); $i++) {
1426 if (!is_object($pg_arr[$i])) {
1427 printf (_("Not Object: ProjectGroup: %d"),$i);
1430 $pg_arr[$i]->delete(1,1);
1431 //echo 'ProjectGroupFactory'.db_error();
1434 // Delete FRS Packages
1436 //$frspf = new FRSPackageFactory($this);
1437 $res = db_query_params ('SELECT * FROM frs_package WHERE group_id=$1',
1438 array ($this->getID())) ;
1439 //echo 'frs_package'.db_error();
1440 //$frsp_arr =& $frspf->getPackages();
1441 while ($arr = db_fetch_array($res)) {
1442 //if (!is_object($pg_arr[$i])) {
1443 // echo "Not Object: ProjectGroup: ".$i;
1446 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1452 $news_group=&group_get_object($GLOBALS['sys_news_group']);
1453 $res = db_query_params ('SELECT forum_id FROM news_bytes WHERE group_id=$1',
1454 array ($this->getID())) ;
1455 for ($i=0; $i<db_numrows($res); $i++) {
1456 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1457 if (!$Forum->delete(1,1)) {
1458 printf (_("Could Not Delete News Forum: %d"),$Forum->getID());
1461 $res = db_query_params ('DELETE FROM news_bytes WHERE group_id=$1',
1462 array ($this->getID())) ;
1467 $res = db_query_params ('DELETE FROM doc_data WHERE group_id=$1',
1468 array ($this->getID())) ;
1469 //echo 'doc_data'.db_error();
1470 $res = db_query_params ('DELETE FROM doc_groups WHERE group_id=$1',
1471 array ($this->getID())) ;
1472 //echo 'doc_groups'.db_error();
1477 $res=db_query_params('DELETE FROM project_tags WHERE group_id=$1', array($this->getID()));
1480 // Delete group history
1482 $res = db_query_params ('DELETE FROM group_history WHERE group_id=$1',
1483 array ($this->getID())) ;
1484 //echo 'group_history'.db_error();
1486 // Delete group plugins
1488 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1',
1489 array ($this->getID())) ;
1490 //echo 'group_plugin'.db_error();
1492 // Delete group cvs stats
1494 $res = db_query_params ('DELETE FROM stats_cvs_group WHERE group_id=$1',
1495 array ($this->getID())) ;
1496 //echo 'stats_cvs_group'.db_error();
1500 $sf = new SurveyFactory($this);
1501 $s_arr =& $sf->getSurveys();
1502 for ($i=0; $i<count($s_arr); $i++) {
1503 if (!is_object($s_arr[$i])) {
1504 printf (_("Not Object: Survey: %d"),$i);
1507 $s_arr[$i]->delete();
1508 //echo 'SurveyFactory'.db_error();
1511 // Delete SurveyQuestions
1513 $sqf = new SurveyQuestionFactory($this);
1514 $sq_arr =& $sqf->getSurveyQuestions();
1515 for ($i=0; $i<count($sq_arr); $i++) {
1516 if (!is_object($sq_arr[$i])) {
1517 printf (_("Not Object: SurveyQuestion: %d"),$i);
1520 $sq_arr[$i]->delete();
1521 //echo 'SurveyQuestionFactory'.db_error();
1524 // Delete Mailing List Factory
1526 $mlf = new MailingListFactory($this);
1527 $ml_arr =& $mlf->getMailingLists();
1528 for ($i=0; $i<count($ml_arr); $i++) {
1529 if (!is_object($ml_arr[$i])) {
1530 printf (_("Not Object: MailingList: %d"),$i);
1533 if (!$ml_arr[$i]->delete(1,1)) {
1534 $this->setError(_('Could not properly delete the mailing list'));
1536 //echo 'MailingListFactory'.db_error();
1541 $res = db_query_params ('DELETE FROM trove_group_link WHERE group_id=$1',
1542 array ($this->getID())) ;
1543 $res = db_query_params ('DELETE FROM trove_agg WHERE group_id=$1',
1544 array ($this->getID())) ;
1548 $res = db_query_params ('DELETE FROM project_sums_agg WHERE group_id=$1',
1549 array ($this->getID())) ;
1550 //echo 'project_sums_agg'.db_error();
1551 $res = db_query_params ('INSERT INTO deleted_groups (unix_group_name,delete_date,isdeleted) VALUES ($1, $2, $3)',
1552 array ($this->getUnixName(),
1555 //echo 'InsertIntoDeleteQueue'.db_error();
1556 $res = db_query_params ('DELETE FROM groups WHERE group_id=$1',
1557 array ($this->getID())) ;
1558 //echo 'DeleteGroup'.db_error();
1564 $hook_params = array ();
1565 $hook_params['group'] = $this;
1566 $hook_params['group_id'] = $this->getID();
1567 plugin_hook ("group_delete", $hook_params);
1569 if (isset($GLOBALS['sys_upload_dir']) && $this->getUnixName()) {
1570 exec('/bin/rm -rf '.$GLOBALS['sys_upload_dir'].'/'.$this->getUnixName().'/');
1572 if (isset($GLOBALS['sys_ftp_upload_dir']) && $this->getUnixName()) {
1573 exec('/bin/rm -rf '.$GLOBALS['sys_ftp_upload_dir'].'/'.$this->getUnixName().'/');
1578 $res = db_query_params ('DELETE FROM rep_group_act_monthly WHERE group_id=$1',
1579 array ($this->getID())) ;
1580 //echo 'rep_group_act_monthly'.db_error();
1581 $res = db_query_params ('DELETE FROM rep_group_act_weekly WHERE group_id=$1',
1582 array ($this->getID())) ;
1583 //echo 'rep_group_act_weekly'.db_error();
1584 $res = db_query_params ('DELETE FROM rep_group_act_daily WHERE group_id=$1',
1585 array ($this->getID())) ;
1586 //echo 'rep_group_act_daily'.db_error();
1587 unset($this->data_array);
1595 Basic functions to add/remove users to/from a group
1596 and update their permissions
1602 * addUser - controls adding a user to a group.
1604 * @param string Unix name of the user to add OR integer user_id.
1605 * @param int The role_id this user should have.
1606 * @return boolean success.
1609 function addUser($user_identifier,$role_id) {
1612 Admins can add users to groups
1615 $perm =& $this->getPermission( session_get_user() );
1616 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1617 $this->setPermissionDeniedError();
1623 get user id for this user's unix_name
1625 if (is_int ($user_identifier)) { // user_id or user_name
1626 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array ($user_identifier)) ;
1628 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array ($user_identifier)) ;
1630 if (db_numrows($res_newuser) > 0) {
1632 // make sure user is active
1634 if (db_result($res_newuser,0,'status') != 'A') {
1635 $this->setError(_('User is not active. Only active users can be added.'));
1641 // user was found - set new user_id var
1643 $user_id = db_result($res_newuser,0,'user_id');
1646 // if not already a member, add them
1648 $res_member = db_query_params ('SELECT user_id
1650 WHERE user_id=$1 AND group_id=$2',
1651 array ($user_id, $this->getID())) ;
1653 if (db_numrows($res_member) < 1) {
1655 // Create this user's row in the user_group table
1657 $res = db_query_params ('INSERT INTO user_group
1658 (user_id,group_id,admin_flags,forum_flags,project_flags,
1659 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
1660 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)',
1672 //verify the insert worked
1673 if (!$res || db_affected_rows($res) < 1) {
1674 $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
1679 // check and create if group doesn't exists
1681 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
1682 if (!$SYS->sysCheckCreateGroup($this->getID())){
1683 $this->setError($SYS->getErrorMessage());
1688 // check and create if user doesn't exists
1690 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1691 if (!$SYS->sysCheckCreateUser($user_id)) {
1692 $this->setError($SYS->getErrorMessage());
1699 $role = new Role($this,$role_id);
1700 if (!$role || !is_object($role)) {
1701 $this->setError(_('Error Getting Role Object'));
1704 } elseif ($role->isError()) {
1705 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1709 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
1710 if (!$role->setUser($user_id)) {
1711 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1717 // user was already a member
1718 // make sure they are set up
1720 $user=&user_get_object($user_id,$res_newuser);
1721 $user->fetchData($user->getID());
1722 $role = new Role($this,$role_id);
1723 if (!$role || !is_object($role)) {
1724 $this->setError(_('Error Getting Role Object'));
1727 } elseif ($role->isError()) {
1728 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1732 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
1733 if (!$role->setUser($user_id)) {
1734 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1739 // set up their system info
1741 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1742 if (!$SYS->sysCheckCreateUser($user_id)) {
1743 $this->setError($SYS->getErrorMessage());
1752 // user doesn't exist
1754 $this->setError(_('ERROR: User does not exist'));
1759 $hook_params['group'] = $this;
1760 $hook_params['group_id'] = $this->getID();
1761 $hook_params['user'] = &user_get_object($user_id);
1762 $hook_params['user_id'] = $user_id;
1763 plugin_hook ("group_adduser", $hook_params);
1768 $this->addHistory('Added User',$user_identifier);
1774 * removeUser - controls removing a user from a group.
1776 * Users can remove themselves.
1778 * @param int The ID of the user to remove.
1779 * @return boolean success.
1781 function removeUser($user_id) {
1782 global $SYS,$sys_database_type;
1784 if ($user_id==user_getid()) {
1785 //users can remove themselves
1786 //everyone else must be a project admin
1788 $perm =& $this->getPermission( session_get_user() );
1790 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1791 $this->setPermissionDeniedError();
1797 $res = db_query_params ('DELETE FROM user_group WHERE group_id=$1 AND user_id=$2',
1798 array ($this->getID(),
1800 if (!$res || db_affected_rows($res) < 1) {
1801 $this->setError(sprintf(_('ERROR: User not removed: %s'),db_error()));
1806 // reassign open artifacts to id=100
1808 $res = db_query_params ('UPDATE artifact SET assigned_to=100
1809 WHERE group_artifact_id
1810 IN (SELECT group_artifact_id
1811 FROM artifact_group_list
1812 WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
1813 array ($this->getID(),
1816 $this->setError(sprintf(_('ERROR: DB: artifact: %s'),db_error()));
1822 // reassign open tasks to id=100
1823 // first have to purge any assignments that would cause
1824 // conflict with existing assignment to 100
1826 if ($sys_database_type == 'mysql') {
1828 SELECT pt.project_task_id
1829 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1830 WHERE pt.group_project_id = pgl.group_project_id
1831 AND pat.project_task_id=pt.project_task_id
1832 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."'
1833 AND pat.assigned_to_id='$user_id' INTO @task_list;
1834 DELETE FROM project_assigned_to WHERE project_task_id IN ( @task_list ) AND assigned_to_id='100'");
1836 $res = db_next_result();
1839 $res = db_query_params ('DELETE FROM project_assigned_to
1840 WHERE project_task_id IN (SELECT pt.project_task_id
1841 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1842 WHERE pt.group_project_id = pgl.group_project_id
1843 AND pat.project_task_id=pt.project_task_id
1844 AND pt.status_id=1 AND pgl.group_id=$1
1845 AND pat.assigned_to_id=$2)
1846 AND assigned_to_id=100',
1847 array ($this->getID(),
1851 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),1,db_error()));
1855 $res = db_query_params ('UPDATE project_assigned_to SET assigned_to_id=100
1856 WHERE project_task_id IN (SELECT pt.project_task_id
1857 FROM project_task pt, project_group_list pgl
1858 WHERE pt.group_project_id = pgl.group_project_id
1859 AND pt.status_id=1 AND pgl.group_id=$1)
1860 AND assigned_to_id=$2',
1861 array ($this->getID(),
1864 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),2,db_error()));
1870 // Remove user from system
1872 //echo "<h2>Group::addUser SYS->sysGroupRemoveUser(".$this->getID().",$user_id)</h2>";
1873 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
1874 $this->setError($SYS->getErrorMessage());
1879 $hook_params['group'] = $this;
1880 $hook_params['group_id'] = $this->getID();
1881 $hook_params['user'] = &user_get_object($user_id);
1882 $hook_params['user_id'] = $user_id;
1883 plugin_hook ("group_removeuser", $hook_params);
1886 $this->addHistory('Removed User',$user_id);
1893 * updateUser - controls updating a user's role in this group.
1895 * @param int The ID of the user.
1896 * @param int The role_id to set this user to.
1897 * @return boolean success.
1899 function updateUser($user_id,$role_id) {
1902 $perm =& $this->getPermission( session_get_user() );
1903 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1904 $this->setPermissionDeniedError();
1908 $role = new Role($this,$role_id);
1909 if (!$role || !is_object($role)) {
1910 $this->setError(_('Could Not Get Role'));
1912 } elseif ($role->isError()) {
1913 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1916 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
1917 if (!$role->setUser($user_id)) {
1918 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1923 $this->addHistory('Updated User',$user_id);
1928 * addHistory - Makes an audit trail entry for this project.
1930 * @param string The name of the field.
1931 * @param string The Old Value for this $field_name.
1932 * @return database result handle.
1935 function addHistory($field_name, $old_value) {
1936 return db_query_params ('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
1937 VALUES ($1,$2,$3,$4,$5)',
1938 array ($this->getID(),
1946 * activateUsers - Make sure that group members have unix accounts.
1948 * Setup unix accounts for group members. Can be called even
1949 * if members are already active.
1953 function activateUsers() {
1956 Activate member(s) of the project
1959 $member_res = db_query_params ('SELECT user_id, role_id FROM user_group WHERE group_id=$1',
1960 array ($this->getID())) ;
1962 $rows = db_numrows($member_res);
1966 for ($i=0; $i<$rows; $i++) {
1968 $member =& user_get_object(db_result($member_res,$i,'user_id'));
1969 $roleId = db_result($member_res,$i,'role_id');
1971 if (!$member || !is_object($member)) {
1972 $this->setError(_('Error getting member object'));
1974 } else if ($member->isError()) {
1975 $this->setError(sprintf(_('Error getting member object: %s'),$member->getErrorMessage()));
1979 if (!$this->addUser($member->getUnixName(),$roleId)) {
1990 * getMembers - returns array of User objects for this project
1992 * @return array of User objects for this group.
1994 function &getMembers() {
1995 if (!isset($this->membersArr)) {
1996 $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',
1997 array ($this->getID())) ;
1998 while ($arr =& db_fetch_array($res)) {
1999 $this->membersArr[] =& new GFUser($arr['user_id'],$arr);
2002 return $this->membersArr;
2006 * approve - Approve pending project.
2008 * @param object The User object who is doing the updating.
2011 function approve(&$user) {
2013 if ($this->getStatus()=='A') {
2014 $this->setError(_("Group already active"));
2020 // Step 1: Activate group and create LDAP entries
2021 if (!$this->setStatus($user, 'A')) {
2026 // Switch to system language for item creation
2027 setup_gettext_from_sys_lang ();
2032 // Tracker Integration
2035 $ats = new ArtifactTypes($this);
2036 if (!$ats || !is_object($ats)) {
2037 $this->setError(_('Error creating ArtifactTypes object'));
2039 setup_gettext_from_context();
2041 } else if ($ats->isError()) {
2042 $this->setError(sprintf (_('ATS%d: %s'), 1, $ats->getErrorMessage()));
2044 setup_gettext_from_context();
2047 if (!$ats->createTrackers()) {
2048 $this->setError(sprintf (_('ATS%d: %s'), 2, $ats->getErrorMessage()));
2050 setup_gettext_from_context();
2056 // Forum Integration
2059 $f = new Forum($this);
2060 if (!$f->create(_('Open-Discussion'),_('General Discussion'),1,'',1,0)) {
2061 $this->setError(sprintf (_('F%d: %s'), 1, $f->getErrorMessage()));
2063 setup_gettext_from_context();
2066 $f = new Forum($this);
2067 if (!$f->create(_('Help'),_('Get Public Help'),1,'',1,0)) {
2068 $this->setError(sprintf (_('F%d: %s'), 2, $f->getErrorMessage()));
2070 setup_gettext_from_context();
2073 $f = new Forum($this);
2074 if (!$f->create(_('Developers'),_('Project Developer Discussion'),0,'',1,0)) {
2075 $this->setError(sprintf (_('F%d: %s'), 3, $f->getErrorMessage()));
2077 setup_gettext_from_context();
2083 // Doc Mgr Integration
2086 $dg = new DocumentGroup($this);
2087 if (!$dg->create(_('Uncategorized Submissions'))) {
2088 $this->setError(sprintf(_('DG: %s'),$dg->getErrorMessage()));
2090 setup_gettext_from_context();
2099 $frs = new FRSPackage($this);
2100 if (!$frs->create($this->getUnixName())) {
2101 $this->setError(sprintf(_('FRSP: %s'),$frs->getErrorMessage()));
2103 setup_gettext_from_context();
2112 $pg = new ProjectGroup($this);
2113 if (!$pg->create(_('To Do'),_('Things We Have To Do'),1)) {
2114 $this->setError(sprintf(_('PG%d: %s'),1,$pg->getErrorMessage()));
2116 setup_gettext_from_context();
2119 $pg = new ProjectGroup($this);
2120 if (!$pg->create(_('Next Release'),_('Items For Our Next Release'),1)) {
2121 $this->setError(sprintf(_('PG%d: %s'),2,$pg->getErrorMessage()));
2123 setup_gettext_from_context();
2129 // Set Default Roles
2133 $admin_group = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1 AND admin_flags=$2',
2134 array ($this->getID(),
2136 if (db_numrows($admin_group) > 0) {
2137 $idadmin_group = db_result($admin_group,0,'user_id');
2142 $role = new Role($this);
2143 $todo = array_keys($role->defaults);
2144 for ($c=0; $c<count($todo); $c++) {
2145 $role = new Role($this);
2146 if (! ($role_id = $role->createDefault($todo[$c]))) {
2147 $this->setError(sprintf(_('R%d: %s'),$c,$role->getErrorMessage()));
2149 setup_gettext_from_context();
2152 $role = new Role($this, $role_id);
2153 if ($role->getVal('projectadmin',0)=='A') {
2154 $role->setUser($idadmin_group);
2161 // Create MailingList
2164 if ($GLOBALS['sys_use_mail']) {
2165 $mlist = new MailingList($this);
2166 if (!$mlist->create('commits',_('Commits'),1,$idadmin_group)) {
2167 $this->setError(sprintf(_('ML: %s'),$mlist->getErrorMessage()));
2169 setup_gettext_from_context();
2174 // Switch back to user preference
2175 setup_gettext_from_context();
2179 $this->sendApprovalEmail();
2180 $this->addHistory('Approved', 'x');
2183 //change assistant for webcal
2185 $params[0] = $idadmin_group ;
2186 $params[1] = $this->getID();
2187 plugin_hook('change_cal_permission_default',$params);
2195 * sendApprovalEmail - Send new project email.
2197 * @return boolean success.
2200 function sendApprovalEmail() {
2201 $res_admins = db_query_params ('
2202 SELECT users.user_name,users.email,users.language,users.user_id
2203 FROM users,user_group
2204 WHERE users.user_id=user_group.user_id
2205 AND user_group.group_id=$1
2206 AND user_group.admin_flags=$2',
2207 array ($this->getID(),
2210 if (db_numrows($res_admins) < 1) {
2211 $this->setError(_("Group does not have any administrators."));
2215 // send one email per admin
2216 while ($row_admins = db_fetch_array($res_admins)) {
2217 $admin =& user_get_object($row_admins['user_id']);
2218 setup_gettext_for_user ($admin) ;
2220 $message=sprintf(_('Your project registration for %4$s has been approved.
2222 Project Full Name: %1$s
2223 Project Unix Name: %2$s
2225 Your DNS will take up to a day to become active on our site.
2226 Your web site is accessible through your shell account. Please read
2227 site documentation (see link below) about intended usage, available
2228 services, and directory layout of the account.
2231 own project page in %4$s while logged in, you will find
2232 additional menu functions to your left labeled \'Project Admin\'.
2234 We highly suggest that you now visit %4$s and create a public
2235 description for your project. This can be done by visiting your project
2236 page while logged in, and selecting \'Project Admin\' from the menus
2237 on the left (or by visiting %3$s
2240 Your project will also not appear in the Trove Software Map (primary
2241 list of projects hosted on %4$s which offers great flexibility in
2242 browsing and search) until you categorize it in the project administration
2243 screens. So that people can find your project, you should do this now.
2244 Visit your project while logged in, and select \'Project Admin\' from the
2247 Enjoy the system, and please tell others about %4$s. Let us know
2248 if there is anything we can do to help you.
2251 $this->getPublicName(),
2252 $this->getUnixName(),
2253 util_make_url ('/project/admin/?group_id='.$this->getID()),
2254 $GLOBALS['sys_name']);
2256 util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), $GLOBALS['sys_name']), $message);
2258 setup_gettext_from_context();
2266 * sendRejectionEmail - Send project rejection email.
2268 * This function sends out a rejection message to a user who
2269 * registered a project.
2271 * @param int The id of the response to use.
2272 * @param string The rejection message.
2273 * @return completion status.
2276 function sendRejectionEmail($response_id, $message="zxcv") {
2277 $res_admins = db_query_params ('
2278 SELECT u.email, u.language, u.user_id
2279 FROM users u, user_group ug
2280 WHERE ug.group_id=$1
2281 AND u.user_id=ug.user_id',
2282 array ($this->getID())) ;
2283 if (db_numrows($res_admins) < 1) {
2284 $this->setError(_("Group does not have any administrators."));
2288 while ($row_admins = db_fetch_array($res_admins)) {
2289 $admin =& user_get_object($row_admins['user_id']);
2290 setup_gettext_for_user ($admin) ;
2292 $response=sprintf(_('Your project registration for %3$s has been denied.
2294 Project Full Name: %1$s
2295 Project Unix Name: %2$s
2297 Reasons for negative decision:
2299 '), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name']);
2301 // Check to see if they want to send a custom rejection response
2302 if ($response_id == 0) {
2303 $response .= $message;
2305 $response .= db_result (
2306 db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array ($response_id)),
2311 util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), $GLOBALS['sys_name']), $response);
2312 setup_gettext_from_context();
2319 * sendNewProjectNotificationEmail - Send new project notification email.
2321 * This function sends out a notification email to the
2322 * SourceForge admin user when a new project is
2325 * @return boolean success.
2328 function sendNewProjectNotificationEmail() {
2329 // Get the user who wants to register the project
2330 $res = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1',
2331 array ($this->getID())) ;
2333 if (db_numrows($res) < 1) {
2334 $this->setError(_("Could not find user who has submitted the project."));
2338 $submitter =& user_get_object(db_result($res,0,'user_id'));
2341 $res = db_query_params ('SELECT users.email, users.language, users.user_id
2342 FROM users, user_group
2344 AND user_group.admin_flags=$1
2345 AND users.user_id=user_group.user_id',
2348 if (db_numrows($res) < 1) {
2349 $this->setError(_("There is no administrator to send the mail."));
2353 for ($i=0; $i<db_numrows($res) ; $i++) {
2354 $admin_email = db_result($res,$i,'email') ;
2355 $admin =& user_get_object(db_result($res,$i,'user_id'));
2356 setup_gettext_for_user ($admin) ;
2358 $message=sprintf(_('New %1$s Project Submitted
2360 Project Full Name: %2$s
2361 Submitted Description: %3$s
2362 Submitter: %5$s (%6$s)
2364 Please visit the following URL to approve or reject this project:
2366 $GLOBALS['sys_name'],
2367 $this->getPublicName(),
2368 util_unconvert_htmlspecialchars($this->getRegistrationPurpose()),
2369 util_make_url ('/admin/approve-pending.php'),
2370 $submitter->getRealName(),
2371 $submitter->getUnixName());
2372 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2373 setup_gettext_from_context();
2377 $email = $submitter->getEmail() ;
2378 setup_gettext_for_user ($submitter) ;
2380 $message=sprintf(_('New %1$s Project Submitted
2382 Project Full Name: %2$s
2383 Submitted Description: %3$s
2385 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']);
2387 util_send_message($email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2388 setup_gettext_from_context();
2397 * validateGroupName - Validate the group name
2399 * @param string Group name.
2401 * @return an error false and set an error is the group name is invalide otherwise return true
2403 function validateGroupName($group_name) {
2404 if (strlen($group_name)<3) {
2405 $this->setError(_('Group name is too short'));
2407 } else if (strlen(htmlspecialchars($group_name))>50) {
2408 $this->setError(_('Group name is too long'));
2410 } else if ($group=group_get_object_by_publicname($group_name)) {
2411 $this->setError(_('Group name already taken'));
2419 * getRoles - Get the roles of the group.
2421 * @return array of Role id of this group.
2423 function getRolesId () {
2427 $roles_group_res = db_query_params ('SELECT role_id FROM role WHERE group_id=$1',
2428 array ($this->getID()));
2429 if (!$roles_group_res) {
2430 $this->setError('Error: Roles from group id '. $this->Group->getID() . ' ' .db_error());
2433 for ($i=0; $i<db_numrows($roles_group_res); $i++) {
2434 $rolesId[$i] = db_result($roles_group_res,$i,'role_id');
2442 * getUnixStatus - Status of activation of unix account.
2444 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2446 function getUnixStatus() {
2447 return $this->data_array['unix_status'];
2451 * setUnixStatus - Sets status of activation of unix account.
2453 * @param string The unix status.
2459 * @return boolean success.
2461 function setUnixStatus($status) {
2464 $res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
2469 $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
2473 if ($status == 'A') {
2474 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2475 $this->setError($SYS->getErrorMessage());
2480 if ($SYS->sysCheckGroup($this->getID())) {
2481 if (!$SYS->sysRemoveGroup($this->getID())) {
2482 $this->setError($SYS->getErrorMessage());
2489 $this->data_array['unix_status']=$status;
2499 * group_getname() - get the group name
2501 * @param int The group ID
2505 function group_getname ($group_id = 0) {
2506 $grp = &group_get_object($group_id);
2508 return $grp->getPublicName();
2515 * group_getunixname() - get the unixname for a group
2517 * @param int The group ID
2521 function group_getunixname ($group_id) {
2522 $grp = &group_get_object($group_id);
2524 return $grp->getUnixName();
2531 * group_get_result() - Get the group object result ID.
2533 * @param int The group ID
2537 function &group_get_result($group_id=0) {
2538 $grp = &group_get_object($group_id);
2540 return $grp->getData();
2549 // c-file-style: "bsd"