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.
282 function create(&$user, $group_name, $unix_name, $description, $purpose, $unix_box='shell1', $scm_box='cvs1', $is_public=1) {
283 // $user is ignored - anyone can create pending group
285 if ($this->getID()!=0) {
286 $this->setError(_('Group::create: Group object already exists'));
288 } else if (!$this->validateGroupName($group_name)) {
290 } else if (!account_groupnamevalid($unix_name)) {
291 $this->setError(_('Invalid Unix name'));
293 } else if (db_numrows(db_query_params('SELECT group_id FROM groups WHERE unix_group_name=$1',
294 array ($unix_name))) > 0) {
295 $this->setError(_('Unix name already taken'));
297 } else if (strlen($purpose)<10) {
298 $this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
300 } else if (strlen($purpose)>1500) {
301 $this->setError(_('The Registration Purpose text is too long. Please make it smaller than 1500 bytes.'));
303 } else if (strlen($description)<10) {
304 $this->setError(_('Describe in a more comprehensive manner your project.'));
306 } else if (strlen($description)>255) {
307 $this->setError(_('Your project description is too long. Please make it smaller than 256 bytes.'));
311 srand((double)microtime()*1000000);
312 $random_num = rand(0,1000000);
316 $res = db_query_params ('
332 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)',
333 array (htmlspecialchars ($group_name),
336 htmlspecialchars($description),
337 $unix_name.".".$GLOBALS['sys_default_domain'],
338 $unix_name.".".$GLOBALS['sys_default_domain'],
342 htmlspecialchars($purpose),
345 md5($random_num) )) ;
346 if (!$res || db_affected_rows($res) < 1) {
347 $this->setError(sprintf(_('ERROR: Could not create group: %s'),db_error()));
352 $id = db_insertid($res, 'groups', 'group_id');
354 $this->setError(sprintf(_('ERROR: Could not get group id: %s'),db_error()));
360 // Now, make the user an admin
362 $res=db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags,
363 cvs_flags, artifact_flags, forum_flags, role_id)
364 VALUES ($1, $2, $3, $4, $5, $6, $7)',
365 array ($user->getID(),
372 if (!$res || db_affected_rows($res) < 1) {
373 $this->setError(sprintf(_('ERROR: Could not add admin to newly created group: %s'),db_error()));
378 if (!$this->fetchData($id)) {
383 $hook_params = array ();
384 $hook_params['group'] = $this;
385 $hook_params['group_id'] = $this->getID();
386 $hook_params['group_name'] = $group_name;
387 $hook_params['unix_group_name'] = $unix_name;
388 plugin_hook ("group_create", $hook_params);
391 $this->sendNewProjectNotificationEmail();
398 * updateAdmin - Update core properties of group object.
400 * This function require site admin privilege.
402 * @param object User requesting operation (for access control).
403 * @param bool Whether group is publicly accessible (0/1).
404 * @param int Group type (1-project, 2-foundry).
405 * @param string Machine on which group's home directory located.
406 * @param string Domain which serves group's WWW.
410 function updateAdmin(&$user, $is_public, $type_id, $unix_box, $http_domain) {
411 $perm =& $this->getPermission($user);
413 if (!$perm || !is_object($perm)) {
414 $this->setError(_('Could not get permission.'));
418 if (!$perm->isSuperUser()) {
419 $this->setError(_('Permission denied.'));
425 $res = db_query_params ('
427 SET is_public=$1, type_id=$2,
428 unix_box=$3, http_domain=$4
436 if (!$res || db_affected_rows($res) < 1) {
437 $this->setError(_('ERROR: DB: Could not change group properties: %s'),db_error());
442 // Log the audit trail
443 if ($is_public != $this->isPublic()) {
444 $this->addHistory('is_public', $this->isPublic());
446 if ($type_id != $this->data_array['type_id']) {
447 $this->addHistory('type_id', $this->data_array['type_id']);
449 if ($unix_box != $this->data_array['unix_box']) {
450 $this->addHistory('unix_box', $this->data_array['unix_box']);
452 if ($http_domain != $this->data_array['http_domain']) {
453 $this->addHistory('http_domain', $this->data_array['http_domain']);
456 if (!$this->fetchData($this->getID())) {
465 * update - Update number of common properties.
467 * Unlike updateAdmin(), this function accessible to project admin.
469 * @param object User requesting operation (for access control).
470 * @param bool Whether group is publicly accessible (0/1).
471 * @param string Project's license (string ident).
472 * @param int Group type (1-project, 2-foundry).
473 * @param string Machine on which group's home directory located.
474 * @param string Domain which serves group's WWW.
475 * @return int status.
478 function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,
479 $use_pm,$use_pm_depend_box,$use_scm,$use_news,$use_docman,
480 $new_doc_address,$send_all_docs,$logo_image_id,
481 $use_ftp,$use_tracker,$use_frs,$use_stats,$tags,$is_public) {
483 $perm =& $this->getPermission($user);
485 if (!$perm || !is_object($perm)) {
486 $this->setError(_('Could not get permission.'));
490 if (!$perm->isAdmin()) {
491 $this->setError(_('Permission denied.'));
495 // Validate some values
496 if ($this->getPublicName() != $group_name) {
497 if (!$this->validateGroupName($group_name)) {
502 if ($new_doc_address) {
503 $invalid_mails = validate_emails($new_doc_address);
504 if (count($invalid_mails) > 0) {
505 $this->setError(sprintf (ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
510 // in the database, these all default to '1',
511 // so we have to explicity set 0
524 if (!$use_pm_depend_box) {
525 $use_pm_depend_box=0;
548 if (!$send_all_docs) {
553 $homepage=$GLOBALS['sys_default_domain'].'/projects/'.$this->getUnixName().'/';
556 if (strlen(htmlspecialchars($short_description))>255) {
557 $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
563 //XXX not yet actived logo_image_id='$logo_image_id',
564 $res = db_query_params ('UPDATE groups
567 short_description=$3,
572 use_pm_depend_box=$8,
584 array (htmlspecialchars($group_name),
586 htmlspecialchars($short_description),
605 $this->setError(sprintf(_('Error updating project information: %s'), db_error()));
610 if ($this->setTags($tags) === false) {
615 $hook_params = array ();
616 $hook_params['group'] = $this;
617 $hook_params['group_id'] = $this->getID();
618 $hook_params['group_homepage'] = $homepage;
619 $hook_params['group_name'] = htmlspecialchars($group_name);
620 $hook_params['group_description'] = htmlspecialchars($short_description);
621 plugin_hook ("group_update", $hook_params);
623 // Log the audit trail
624 $this->addHistory('Changed Public Info', '');
626 if (!$this->fetchData($this->getID())) {
635 * getID - Simply return the group_id for this object.
637 * @return int group_id.
640 return $this->data_array['group_id'];
644 * getType() - Foundry, project, etc.
646 * @return int The type flag from the database.
649 return $this->data_array['type_id'];
654 * getStatus - the status code.
656 * Statuses char include I,H,A,D.
658 function getStatus() {
659 return $this->data_array['status'];
663 * setStatus - set the status code.
665 * Statuses include I,H,A,D.
667 * @param object User requesting operation (for access control).
668 * @param string Status value.
669 * @return boolean success.
672 function setStatus(&$user, $status) {
675 $perm =& $this->getPermission($user);
676 if (!$perm || !is_object($perm)) {
677 $this->setPermissionDeniedError();
679 } elseif (!$perm->isSuperUser()) {
680 $this->setPermissionDeniedError();
684 // Projects in 'A' status can only go to 'H' or 'D'
685 // Projects in 'D' status can only go to 'A'
686 // Projects in 'P' status can only go to 'A' OR 'D'
687 // Projects in 'I' status can only go to 'P'
688 // Projects in 'H' status can only go to 'A' OR 'D'
689 $allowed_status_changes = array(
690 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
691 'IP'=>1,'HA'=>1,'HD'=>1
694 // Check that status transition is valid
695 if ($this->getStatus() != $status
696 && !$allowed_status_changes[$this->getStatus().$status]) {
697 $this->setError(_('Invalid Status Change'));
703 $res = db_query_params ('UPDATE groups
705 WHERE group_id=$2', array ($status, $this->getID())) ;
707 if (!$res || db_affected_rows($res) < 1) {
708 $this->setError(sprintf(_('ERROR: DB: Could not change group status: %s'),db_error()));
714 // Activate system group, if not yet
715 if (!$SYS->sysCheckGroup($this->getID())) {
716 if (!$SYS->sysCreateGroup($this->getID())) {
717 $this->setError($SYS->getErrorMessage());
722 if (!$this->activateUsers()) {
727 /* Otherwise, the group is not active, and make sure that
728 System group is not active either */
729 } else if ($SYS->sysCheckGroup($this->getID())) {
730 if (!$SYS->sysRemoveGroup($this->getID())) {
731 $this->setError($SYS->getErrorMessage());
737 $hook_params = array ();
738 $hook_params['group'] = $this;
739 $hook_params['group_id'] = $this->getID();
740 $hook_params['status'] = $status;
741 plugin_hook ("group_setstatus", $hook_params);
745 // Log the audit trail
746 if ($status != $this->getStatus()) {
747 $this->addHistory('Status', $this->getStatus());
750 $this->data_array['status'] = $status;
755 * isProject - Simple boolean test to see if it's a project or not.
757 * @return boolean is_project.
759 function isProject() {
760 if ($this->getType()==1) {
768 * isPublic - Simply returns the is_public flag from the database.
770 * @return boolean is_public.
772 function isPublic() {
773 return $this->data_array['is_public'];
777 * isActive - Database field status of 'A' returns true.
779 * @return boolean is_active.
781 function isActive() {
782 if ($this->getStatus()=='A') {
790 * getUnixName - the unix_name
792 * @return string unix_name.
794 function getUnixName() {
795 return strtolower($this->data_array['unix_group_name']);
799 * getPublicName - the full-length public name.
801 * @return string The group_name.
803 function getPublicName() {
804 return $this->data_array['group_name'];
808 * getRegisterPurpose - the text description of the purpose of this project.
810 * @return string The description.
812 function getRegisterPurpose() {
813 return $this->data_array['register_purpose'];
817 * getDescription - the text description of this project.
819 * @return string The description.
821 function getDescription() {
822 return $this->data_array['short_description'];
826 * getStartDate - the unix time this project was registered.
828 * @return int (unix time) of registration.
830 function getStartDate() {
831 return $this->data_array['register_time'];
835 * getLogoImageID - the id of the logo in the database for this project.
837 * @return int The ID of logo image in db_images table (or 100 if none).
839 function getLogoImageID() {
840 return $this->data_array['logo_image_id'];
844 * getUnixBox - the hostname of the unix box where this project is located.
846 * @return string The name of the unix machine for the group.
848 function getUnixBox() {
849 return $this->data_array['unix_box'];
853 * getSCMBox - the hostname of the scm box where this project is located.
855 * @return string The name of the unix machine for the group.
857 function getSCMBox() {
858 return $this->data_array['scm_box'];
861 * setSCMBox - the hostname of the scm box where this project is located.
863 * @param string The name of the new SCM_BOX
865 function setSCMBox($scm_box) {
868 $res = db_query_params ('UPDATE groups SET scm_box=$1 WHERE group_id=$2', array ($scm_box, $this->getID ()));
870 $this->addHistory('scm_box', $this->data_array['scm_box']);
871 $this->data_array['scm_box']=$scm_box;
876 $this->setError(_("Couldn't insert SCM_BOX to database"));
880 $this->setError(_("SCM Box can't be empty"));
886 * getDomain - the hostname.domain where their web page is located.
888 * @return string The name of the group [web] domain.
890 function getDomain() {
891 return $this->data_array['http_domain'];
895 * getLicense - the license they chose.
897 * @return int ident of group license.
899 function getLicense() {
900 return $this->data_array['license'];
904 * getLicenseName - the name of the license
906 * @return string license name
908 function getLicenseName() {
909 $licenses =& group_get_licenses();
910 if(isset($licenses[$this->data_array['license']])) {
911 return $licenses[$this->data_array['license']];
918 * getLicenseOther - optional string describing license.
920 * @return string The custom license.
922 function getLicenseOther() {
923 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
924 return $this->data_array['license_other'];
931 * getRegistrationPurpose - the text description of the purpose of this project.
933 * @return string The application for project hosting.
935 function getRegistrationPurpose() {
936 return $this->data_array['register_purpose'];
941 * getAdmins() - Get array of Admin user objects.
943 * @return array Array of User objects.
945 function &getAdmins() {
946 // this function gets all group admins in order to send Jabber and mail messages
947 $res = db_query_params ('SELECT user_id FROM user_group WHERE admin_flags=$1 AND group_id=$2',
948 array ('A', $this->getID()));
949 $user_ids=util_result_column_to_array($res);
950 return user_get_objects($user_ids);
955 Common Group preferences for tools
960 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
962 * @return boolean enable_scm.
964 function enableAnonSCM() {
965 if ($this->isPublic() && $this->usesSCM()) {
966 return $this->data_array['enable_anonscm'];
972 function SetUsesAnonSCM ($booleanparam) {
974 $booleanparam = $booleanparam ? 1 : 0 ;
975 $res = db_query_params ('UPDATE groups SET enable_anonscm=$1 WHERE group_id=$2',
976 array ($booleanparam, $this->getID()));
978 $this->data_array['enable_anonscm']=$booleanparam;
987 * enablePserver - whether or not this group has opted to enable Pserver.
989 * @return boolean enable_pserver.
991 function enablePserver() {
992 if ($this->usesSCM()) {
993 return $this->data_array['enable_pserver'];
999 function SetUsesPserver ($booleanparam) {
1001 $booleanparam = $booleanparam ? 1 : 0 ;
1002 $res = db_query_params ('UPDATE groups SET enable_pserver=$1 WHERE group_id=$2',
1003 array ($booleanparam, $this->getID()));
1005 $this->data_array['enable_pserver']=$booleanparam;
1014 * usesSCM - whether or not this group has opted to use SCM.
1016 * @return boolean uses_scm.
1018 function usesSCM() {
1019 global $sys_use_scm;
1021 return $this->data_array['use_scm'];
1028 * usesMail - whether or not this group has opted to use mailing lists.
1030 * @return boolean uses_mail.
1032 function usesMail() {
1033 global $sys_use_mail;
1034 if ($sys_use_mail) {
1035 return $this->data_array['use_mail'];
1042 * usesNews - whether or not this group has opted to use news.
1044 * @return boolean uses_news.
1046 function usesNews() {
1047 global $sys_use_news;
1048 if ($sys_use_news) {
1049 return $this->data_array['use_news'];
1056 * usesForum - whether or not this group has opted to use discussion forums.
1058 * @return boolean uses_forum.
1060 function usesForum() {
1061 global $sys_use_forum;
1062 if ($sys_use_forum) {
1063 return $this->data_array['use_forum'];
1070 * usesStats - whether or not this group has opted to use stats.
1072 * @return boolean uses_stats.
1074 function usesStats() {
1075 return $this->data_array['use_stats'];
1079 * usesFRS - whether or not this group has opted to use file release system.
1081 * @return boolean uses_frs.
1083 function usesFRS() {
1084 global $sys_use_frs;
1086 return $this->data_array['use_frs'];
1093 * usesTracker - whether or not this group has opted to use tracker.
1095 * @return boolean uses_tracker.
1097 function usesTracker() {
1098 global $sys_use_tracker;
1099 if ($sys_use_tracker) {
1100 return $this->data_array['use_tracker'];
1107 * usesDocman - whether or not this group has opted to use docman.
1109 * @return boolean uses_docman.
1111 function usesDocman() {
1112 global $sys_use_docman;
1113 if ($sys_use_docman) {
1114 return $this->data_array['use_docman'];
1121 * usesFTP - whether or not this group has opted to use FTP.
1123 * @return boolean uses_ftp.
1125 function usesFTP() {
1126 global $sys_use_ftp;
1128 return $this->data_array['use_ftp'];
1135 * usesSurvey - whether or not this group has opted to use surveys.
1137 * @return boolean uses_survey.
1139 function usesSurvey() {
1140 global $sys_use_survey;
1141 if ($sys_use_survey) {
1142 return $this->data_array['use_survey'];
1149 * usesPM - whether or not this group has opted to Project Manager.
1151 * @return boolean uses_projman.
1156 return $this->data_array['use_pm'];
1163 * getPlugins - get a list of all available group plugins
1165 * @return array array containing plugin_id => plugin_name
1167 function getPlugins() {
1168 if (!isset($this->plugins_data)) {
1169 $this->plugins_data = array () ;
1170 $res = db_query_params ('SELECT group_plugin.plugin_id, plugins.plugin_name
1171 FROM group_plugin, plugins
1172 WHERE group_plugin.group_id=$1
1173 AND group_plugin.plugin_id=plugins.plugin_id', array ($this->getID()));
1174 $rows = db_numrows($res);
1176 for ($i=0; $i<$rows; $i++) {
1177 $plugin_id = db_result($res,$i,'plugin_id');
1178 $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
1181 return $this->plugins_data ;
1185 * usesPlugin - returns true if the group uses a particular plugin
1187 * @param string name of the plugin
1188 * @return boolean whether plugin is being used or not
1190 function usesPlugin($pluginname) {
1191 $plugins_data = $this->getPlugins() ;
1192 foreach ($plugins_data as $p_id => $p_name) {
1193 if ($p_name == $pluginname) {
1201 * setPluginUse - enables/disables plugins for the group
1203 * @param string name of the plugin
1204 * @param boolean the new state
1205 * @return string database result
1207 function setPluginUse($pluginname, $val=true) {
1208 if ($val == $this->usesPlugin($pluginname)) {
1209 // State is already good, returning
1212 $res = db_query_params ('SELECT plugin_id FROM plugins WHERE plugin_name=$1',
1213 array ($pluginname));
1214 $rows = db_numrows($res);
1216 // Error: no plugin by that name
1219 $plugin_id = db_result($res,0,'plugin_id');
1221 unset ($this->plugins_data) ;
1223 $res = db_query_params ('INSERT INTO group_plugin (group_id, plugin_id) VALUES ($1, $2)',
1224 array ($this->getID(),
1228 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1 AND plugin_id=$2',
1229 array ($this->getID(),
1236 * getDocEmailAddress - get email address(es) to send doc notifications to.
1238 * @return string email address.
1240 function getDocEmailAddress() {
1241 return $this->data_array['new_doc_address'];
1245 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1247 * @return boolean email_on_all_doc_updates.
1249 function docEmailAll() {
1250 return $this->data_array['send_all_docs'];
1255 * getHomePage - The URL for this project's home page.
1257 * @return string homepage URL.
1259 function getHomePage() {
1260 return $this->data_array['homepage'];
1264 * getTags - Tags of this project.
1266 * @return string List of tags.
1268 function getTags() {
1269 $sql = 'SELECT name FROM project_tags WHERE group_id = $1';
1270 $res = db_query_params($sql, array($this->getID()));
1271 return join(', ', util_result_column_to_array($res));
1275 * setTags - Set tags of this project.
1277 * @return string database result.
1279 function setTags($tags) {
1283 $sql='DELETE FROM project_tags WHERE group_id=$1';
1284 $res=db_query_params($sql, array($this->getID()));
1286 $this->setError('Deleting old tags: '.db_error());
1290 $inserted = array();
1291 $tags_array = split('[;,]', $tags);
1292 foreach ($tags_array as $tag) {
1293 $tag = stripslashes($tag);
1294 $tag = preg_replace('/[\t\r\n]/', ' ', $tag);
1295 // Allowed caracteres: [A-Z][a-z][0-9] -_&'#+.
1296 if (preg_match('/[^[:alnum:]| |\-|_|\&|\'|#|\+|\.]/', $tag)) {
1297 $this->setError(_('Bad tag name, you only can use the following characters: [A-Z][a-z][0-9]-_&\'#+. and space'));
1302 $tag = addslashes($tag);
1303 if ($tag == '' || array_search($tag, $inserted) !== false) continue;
1304 $sql='INSERT INTO project_tags (group_id,name) VALUES ($1, $2)';
1305 $res=db_query_params($sql, array($this->getID(), $tag));
1307 $this->setError(_('Setting tags: ').db_error());
1318 * getPermission - Return a Permission for this Group and the specified User.
1320 * @param object The user you wish to get permission for (usually the logged in user).
1321 * @return object The Permission.
1323 function &getPermission(&$_user) {
1324 return permission_get_object($this, $_user);
1329 * userIsAdmin - Return if for this Group the User is admin.
1331 * @return boolean is_admin.
1333 function userIsAdmin() {
1334 $perm =& $this->getPermission( session_get_user() );
1335 if (!$perm || !is_object($perm)) {
1337 } elseif ($perm->isError()) {
1340 return $perm->isAdmin();
1343 function delete($sure,$really_sure,$really_really_sure) {
1344 if (!$sure || !$really_sure || !$really_really_sure) {
1345 $this->setMissingParamsError();
1348 if ($this->getID() == $GLOBALS['sys_news_group'] ||
1349 $this->getID() == 1 ||
1350 $this->getID() == $GLOBALS['sys_stats_group'] ||
1351 $this->getID() == $GLOBALS['sys_peer_rating_group']) {
1352 $this->setError(_('Cannot Delete System Group'));
1355 $perm =& $this->getPermission( session_get_user() );
1356 if (!$perm || !is_object($perm)) {
1357 $this->setPermissionDeniedError();
1359 } elseif ($perm->isError()) {
1360 $this->setPermissionDeniedError();
1362 } elseif (!$perm->isSuperUser()) {
1363 $this->setPermissionDeniedError();
1369 // Remove all the members
1371 $members =& $this->getMembers();
1372 for ($i=0; $i<count($members); $i++) {
1373 $this->removeUser($members[$i]->getID());
1378 $atf = new ArtifactTypeFactory($this);
1379 $at_arr =& $atf->getArtifactTypes();
1380 for ($i=0; $i<count($at_arr); $i++) {
1381 if (!is_object($at_arr[$i])) {
1382 printf (_("Not Object: ArtifactType: %d"),$i);
1385 $at_arr[$i]->delete(1,1);
1390 $ff = new ForumFactory($this);
1391 $f_arr =& $ff->getForums();
1392 for ($i=0; $i<count($f_arr); $i++) {
1393 if (!is_object($f_arr[$i])) {
1394 printf (_("Not Object: Forum: %d"),$i);
1397 $f_arr[$i]->delete(1,1);
1398 //echo 'ForumFactory'.db_error();
1401 // Delete Subprojects
1403 $pgf = new ProjectGroupFactory($this);
1404 $pg_arr =& $pgf->getProjectGroups();
1405 for ($i=0; $i<count($pg_arr); $i++) {
1406 if (!is_object($pg_arr[$i])) {
1407 printf (_("Not Object: ProjectGroup: %d"),$i);
1410 $pg_arr[$i]->delete(1,1);
1411 //echo 'ProjectGroupFactory'.db_error();
1414 // Delete FRS Packages
1416 //$frspf = new FRSPackageFactory($this);
1417 $res = db_query_params ('SELECT * FROM frs_package WHERE group_id=$1',
1418 array ($this->getID())) ;
1419 //echo 'frs_package'.db_error();
1420 //$frsp_arr =& $frspf->getPackages();
1421 while ($arr = db_fetch_array($res)) {
1422 //if (!is_object($pg_arr[$i])) {
1423 // echo "Not Object: ProjectGroup: ".$i;
1426 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1432 $news_group=&group_get_object($GLOBALS['sys_news_group']);
1433 $res = db_query_params ('SELECT forum_id FROM news_bytes WHERE group_id=$1',
1434 array ($this->getID())) ;
1435 for ($i=0; $i<db_numrows($res); $i++) {
1436 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1437 if (!$Forum->delete(1,1)) {
1438 printf (_("Could Not Delete News Forum: %d"),$Forum->getID());
1441 $res = db_query_params ('DELETE FROM news_bytes WHERE group_id=$1',
1442 array ($this->getID())) ;
1447 $res = db_query_params ('DELETE FROM doc_data WHERE group_id=$1',
1448 array ($this->getID())) ;
1449 //echo 'doc_data'.db_error();
1450 $res = db_query_params ('DELETE FROM doc_groups WHERE group_id=$1',
1451 array ($this->getID())) ;
1452 //echo 'doc_groups'.db_error();
1454 // Delete group history
1456 $res = db_query_params ('DELETE FROM group_history WHERE group_id=$1',
1457 array ($this->getID())) ;
1458 //echo 'group_history'.db_error();
1460 // Delete group plugins
1462 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1',
1463 array ($this->getID())) ;
1464 //echo 'group_plugin'.db_error();
1466 // Delete group cvs stats
1468 $res = db_query_params ('DELETE FROM stats_cvs_group WHERE group_id=$1',
1469 array ($this->getID())) ;
1470 //echo 'stats_cvs_group'.db_error();
1474 $sf = new SurveyFactory($this);
1475 $s_arr =& $sf->getSurveys();
1476 for ($i=0; $i<count($s_arr); $i++) {
1477 if (!is_object($s_arr[$i])) {
1478 printf (_("Not Object: Survey: %d"),$i);
1481 $s_arr[$i]->delete();
1482 //echo 'SurveyFactory'.db_error();
1485 // Delete SurveyQuestions
1487 $sqf = new SurveyQuestionFactory($this);
1488 $sq_arr =& $sqf->getSurveyQuestions();
1489 for ($i=0; $i<count($sq_arr); $i++) {
1490 if (!is_object($sq_arr[$i])) {
1491 printf (_("Not Object: SurveyQuestion: %d"),$i);
1494 $sq_arr[$i]->delete();
1495 //echo 'SurveyQuestionFactory'.db_error();
1498 // Delete Mailing List Factory
1500 $mlf = new MailingListFactory($this);
1501 $ml_arr =& $mlf->getMailingLists();
1502 for ($i=0; $i<count($ml_arr); $i++) {
1503 if (!is_object($ml_arr[$i])) {
1504 printf (_("Not Object: MailingList: %d"),$i);
1507 if (!$ml_arr[$i]->delete(1,1)) {
1508 $this->setError(_('Could not properly delete the mailing list'));
1510 //echo 'MailingListFactory'.db_error();
1515 $res = db_query_params ('DELETE FROM trove_group_link WHERE group_id=$1',
1516 array ($this->getID())) ;
1517 $res = db_query_params ('DELETE FROM trove_agg WHERE group_id=$1',
1518 array ($this->getID())) ;
1522 $res = db_query_params ('DELETE FROM project_sums_agg WHERE group_id=$1',
1523 array ($this->getID())) ;
1524 //echo 'project_sums_agg'.db_error();
1525 $res = db_query_params ('INSERT INTO deleted_groups (unix_group_name,delete_date,isdeleted) VALUES ($1, $2, $3)',
1526 array ($this->getUnixName(),
1529 //echo 'InsertIntoDeleteQueue'.db_error();
1530 $res = db_query_params ('DELETE FROM groups WHERE group_id=$1',
1531 array ($this->getID())) ;
1532 //echo 'DeleteGroup'.db_error();
1538 $hook_params = array ();
1539 $hook_params['group'] = $this;
1540 $hook_params['group_id'] = $this->getID();
1541 plugin_hook ("group_delete", $hook_params);
1543 if (isset($GLOBALS['sys_upload_dir']) && $this->getUnixName()) {
1544 exec('/bin/rm -rf '.$GLOBALS['sys_upload_dir'].'/'.$this->getUnixName().'/');
1546 if (isset($GLOBALS['sys_ftp_upload_dir']) && $this->getUnixName()) {
1547 exec('/bin/rm -rf '.$GLOBALS['sys_ftp_upload_dir'].'/'.$this->getUnixName().'/');
1552 $res = db_query_params ('DELETE FROM rep_group_act_monthly WHERE group_id=$1',
1553 array ($this->getID())) ;
1554 //echo 'rep_group_act_monthly'.db_error();
1555 $res = db_query_params ('DELETE FROM rep_group_act_weekly WHERE group_id=$1',
1556 array ($this->getID())) ;
1557 //echo 'rep_group_act_weekly'.db_error();
1558 $res = db_query_params ('DELETE FROM rep_group_act_daily WHERE group_id=$1',
1559 array ($this->getID())) ;
1560 //echo 'rep_group_act_daily'.db_error();
1561 unset($this->data_array);
1569 Basic functions to add/remove users to/from a group
1570 and update their permissions
1576 * addUser - controls adding a user to a group.
1578 * @param string Unix name of the user to add OR integer user_id.
1579 * @param int The role_id this user should have.
1580 * @return boolean success.
1583 function addUser($user_identifier,$role_id) {
1586 Admins can add users to groups
1589 $perm =& $this->getPermission( session_get_user() );
1590 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1591 $this->setPermissionDeniedError();
1597 get user id for this user's unix_name
1599 if (is_int ($user_identifier)) { // user_id or user_name
1600 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array ($user_identifier)) ;
1602 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array ($user_identifier)) ;
1604 if (db_numrows($res_newuser) > 0) {
1606 // make sure user is active
1608 if (db_result($res_newuser,0,'status') != 'A') {
1609 $this->setError(_('User is not active. Only active users can be added.'));
1615 // user was found - set new user_id var
1617 $user_id = db_result($res_newuser,0,'user_id');
1620 // if not already a member, add them
1622 $res_member = db_query_params ('SELECT user_id
1624 WHERE user_id=$1 AND group_id=$2',
1625 array ($user_id, $this->getID())) ;
1627 if (db_numrows($res_member) < 1) {
1629 // Create this user's row in the user_group table
1631 $res = db_query_params ('INSERT INTO user_group
1632 (user_id,group_id,admin_flags,forum_flags,project_flags,
1633 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
1634 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)',
1646 //verify the insert worked
1647 if (!$res || db_affected_rows($res) < 1) {
1648 $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
1653 // check and create if group doesn't exists
1655 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
1656 if (!$SYS->sysCheckCreateGroup($this->getID())){
1657 $this->setError($SYS->getErrorMessage());
1662 // check and create if user doesn't exists
1664 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1665 if (!$SYS->sysCheckCreateUser($user_id)) {
1666 $this->setError($SYS->getErrorMessage());
1673 $role = new Role($this,$role_id);
1674 if (!$role || !is_object($role)) {
1675 $this->setError(_('Error Getting Role Object'));
1678 } elseif ($role->isError()) {
1679 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1683 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
1684 if (!$role->setUser($user_id)) {
1685 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1691 // user was already a member
1692 // make sure they are set up
1694 $user=&user_get_object($user_id,$res_newuser);
1695 $user->fetchData($user->getID());
1696 $role = new Role($this,$role_id);
1697 if (!$role || !is_object($role)) {
1698 $this->setError(_('Error Getting Role Object'));
1701 } elseif ($role->isError()) {
1702 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1706 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
1707 if (!$role->setUser($user_id)) {
1708 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1713 // set up their system info
1715 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1716 if (!$SYS->sysCheckCreateUser($user_id)) {
1717 $this->setError($SYS->getErrorMessage());
1726 // user doesn't exist
1728 $this->setError(_('ERROR: User does not exist'));
1733 $hook_params['group'] = $this;
1734 $hook_params['group_id'] = $this->getID();
1735 $hook_params['user'] = &user_get_object($user_id);
1736 $hook_params['user_id'] = $user_id;
1737 plugin_hook ("group_adduser", $hook_params);
1742 $this->addHistory('Added User',$user_identifier);
1748 * removeUser - controls removing a user from a group.
1750 * Users can remove themselves.
1752 * @param int The ID of the user to remove.
1753 * @return boolean success.
1755 function removeUser($user_id) {
1756 global $SYS,$sys_database_type;
1758 if ($user_id==user_getid()) {
1759 //users can remove themselves
1760 //everyone else must be a project admin
1762 $perm =& $this->getPermission( session_get_user() );
1764 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1765 $this->setPermissionDeniedError();
1771 $res = db_query_params ('DELETE FROM user_group WHERE group_id=$1 AND user_id=$2',
1772 array ($this->getID(),
1774 if (!$res || db_affected_rows($res) < 1) {
1775 $this->setError(sprintf(_('ERROR: User not removed: %s'),db_error()));
1780 // reassign open artifacts to id=100
1782 $res = db_query_params ('UPDATE artifact SET assigned_to=100
1783 WHERE group_artifact_id
1784 IN (SELECT group_artifact_id
1785 FROM artifact_group_list
1786 WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
1787 array ($this->getID(),
1790 $this->setError(sprintf(_('ERROR: DB: artifact: %s'),db_error()));
1796 // reassign open tasks to id=100
1797 // first have to purge any assignments that would cause
1798 // conflict with existing assignment to 100
1800 if ($sys_database_type == 'mysql') {
1802 SELECT pt.project_task_id
1803 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1804 WHERE pt.group_project_id = pgl.group_project_id
1805 AND pat.project_task_id=pt.project_task_id
1806 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."'
1807 AND pat.assigned_to_id='$user_id' INTO @task_list;
1808 DELETE FROM project_assigned_to WHERE project_task_id IN ( @task_list ) AND assigned_to_id='100'");
1810 $res = db_next_result();
1813 $res = db_query_params ('DELETE FROM project_assigned_to
1814 WHERE project_task_id IN (SELECT pt.project_task_id
1815 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1816 WHERE pt.group_project_id = pgl.group_project_id
1817 AND pat.project_task_id=pt.project_task_id
1818 AND pt.status_id=1 AND pgl.group_id=$1,
1819 AND pat.assigned_to_id=$2)
1820 AND assigned_to_id=100',
1821 array ($this->getID(),
1825 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),1,db_error()));
1829 $res = db_query_params ('UPDATE project_assigned_to SET assigned_to_id=100
1830 WHERE project_task_id IN (SELECT pt.project_task_id
1831 FROM project_task pt, project_group_list pgl
1832 WHERE pt.group_project_id = pgl.group_project_id
1833 AND pt.status_id=1 AND pgl.group_id=$1)
1834 AND assigned_to_id=$2',
1835 array ($this->getID(),
1838 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),2,db_error()));
1844 // Remove user from system
1846 //echo "<h2>Group::addUser SYS->sysGroupRemoveUser(".$this->getID().",$user_id)</h2>";
1847 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
1848 $this->setError($SYS->getErrorMessage());
1853 $hook_params['group'] = $this;
1854 $hook_params['group_id'] = $this->getID();
1855 $hook_params['user'] = &user_get_object($user_id);
1856 $hook_params['user_id'] = $user_id;
1857 plugin_hook ("group_removeuser", $hook_params);
1860 $this->addHistory('Removed User',$user_id);
1867 * updateUser - controls updating a user's role in this group.
1869 * @param int The ID of the user.
1870 * @param int The role_id to set this user to.
1871 * @return boolean success.
1873 function updateUser($user_id,$role_id) {
1876 $perm =& $this->getPermission( session_get_user() );
1877 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1878 $this->setPermissionDeniedError();
1882 $role = new Role($this,$role_id);
1883 if (!$role || !is_object($role)) {
1884 $this->setError(_('Could Not Get Role'));
1886 } elseif ($role->isError()) {
1887 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1890 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
1891 if (!$role->setUser($user_id)) {
1892 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1897 $this->addHistory('Updated User',$user_id);
1902 * addHistory - Makes an audit trail entry for this project.
1904 * @param string The name of the field.
1905 * @param string The Old Value for this $field_name.
1906 * @return database result handle.
1909 function addHistory($field_name, $old_value) {
1910 return db_query_params ('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
1911 VALUES ($1,$2,$3,$4,$5)',
1912 array ($this->getID(),
1920 * activateUsers - Make sure that group members have unix accounts.
1922 * Setup unix accounts for group members. Can be called even
1923 * if members are already active.
1927 function activateUsers() {
1930 Activate member(s) of the project
1933 $member_res = db_query_params ('SELECT user_id, role_id FROM user_group WHERE group_id=$1',
1934 array ($this->getID())) ;
1936 $rows = db_numrows($member_res);
1940 for ($i=0; $i<$rows; $i++) {
1942 $member =& user_get_object(db_result($member_res,$i,'user_id'));
1943 $roleId = db_result($member_res,$i,'role_id');
1945 if (!$member || !is_object($member)) {
1946 $this->setError(_('Error getting member object'));
1948 } else if ($member->isError()) {
1949 $this->setError(sprintf(_('Error getting member object: %s'),$member->getErrorMessage()));
1953 if (!$this->addUser($member->getUnixName(),$roleId)) {
1964 * getMembers - returns array of User objects for this project
1966 * @return array of User objects for this group.
1968 function &getMembers() {
1969 if (!isset($this->membersArr)) {
1970 $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',
1971 array ($this->getID())) ;
1972 while ($arr =& db_fetch_array($res)) {
1973 $this->membersArr[] =& new GFUser($arr['user_id'],$arr);
1976 return $this->membersArr;
1980 * approve - Approve pending project.
1982 * @param object The User object who is doing the updating.
1985 function approve(&$user) {
1987 if ($this->getStatus()=='A') {
1988 $this->setError(_("Group already active"));
1994 // Step 1: Activate group and create LDAP entries
1995 if (!$this->setStatus($user, 'A')) {
2000 // Switch to system language for item creation
2001 setup_gettext_from_sys_lang ();
2006 // Tracker Integration
2009 $ats = new ArtifactTypes($this);
2010 if (!$ats || !is_object($ats)) {
2011 $this->setError(_('Error creating ArtifactTypes object'));
2013 setup_gettext_from_context();
2015 } else if ($ats->isError()) {
2016 $this->setError(sprintf (_('ATS%d: %s'), 1, $ats->getErrorMessage()));
2018 setup_gettext_from_context();
2021 if (!$ats->createTrackers()) {
2022 $this->setError(sprintf (_('ATS%d: %s'), 2, $ats->getErrorMessage()));
2024 setup_gettext_from_context();
2030 // Forum Integration
2033 $f = new Forum($this);
2034 if (!$f->create(_('Open-Discussion'),_('General Discussion'),1,'',1,0)) {
2035 $this->setError(sprintf (_('F%d: %s'), 1, $f->getErrorMessage()));
2037 setup_gettext_from_context();
2040 $f = new Forum($this);
2041 if (!$f->create(_('Help'),_('Get Public Help'),1,'',1,0)) {
2042 $this->setError(sprintf (_('F%d: %s'), 2, $f->getErrorMessage()));
2044 setup_gettext_from_context();
2047 $f = new Forum($this);
2048 if (!$f->create(_('Developers'),_('Project Developer Discussion'),0,'',1,0)) {
2049 $this->setError(sprintf (_('F%d: %s'), 3, $f->getErrorMessage()));
2051 setup_gettext_from_context();
2057 // Doc Mgr Integration
2060 $dg = new DocumentGroup($this);
2061 if (!$dg->create(_('Uncategorized Submissions'))) {
2062 $this->setError(sprintf(_('DG: %s'),$dg->getErrorMessage()));
2064 setup_gettext_from_context();
2073 $frs = new FRSPackage($this);
2074 if (!$frs->create($this->getUnixName())) {
2075 $this->setError(sprintf(_('FRSP: %s'),$frs->getErrorMessage()));
2077 setup_gettext_from_context();
2086 $pg = new ProjectGroup($this);
2087 if (!$pg->create(_('To Do'),_('Things We Have To Do'),1)) {
2088 $this->setError(sprintf(_('PG%d: %s'),1,$pg->getErrorMessage()));
2090 setup_gettext_from_context();
2093 $pg = new ProjectGroup($this);
2094 if (!$pg->create(_('Next Release'),_('Items For Our Next Release'),1)) {
2095 $this->setError(sprintf(_('PG%d: %s'),2,$pg->getErrorMessage()));
2097 setup_gettext_from_context();
2103 // Set Default Roles
2107 $admin_group = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1 AND admin_flags=$2',
2108 array ($this->getID(),
2110 if (db_numrows($admin_group) > 0) {
2111 $idadmin_group = db_result($admin_group,0,'user_id');
2116 $role = new Role($this);
2117 $todo = array_keys($role->defaults);
2118 for ($c=0; $c<count($todo); $c++) {
2119 $role = new Role($this);
2120 if (! ($role_id = $role->createDefault($todo[$c]))) {
2121 $this->setError(sprintf(_('R%d: %s'),$c,$role->getErrorMessage()));
2123 setup_gettext_from_context();
2126 $role = new Role($this, $role_id);
2127 if ($role->getVal('projectadmin',0)=='A') {
2128 $role->setUser($idadmin_group);
2135 // Create MailingList
2138 if ($GLOBALS['sys_use_mail']) {
2139 $mlist = new MailingList($this);
2140 if (!$mlist->create('commits',_('Commits'),1,$idadmin_group)) {
2141 $this->setError(sprintf(_('ML: %s'),$mlist->getErrorMessage()));
2143 setup_gettext_from_context();
2148 // Switch back to user preference
2149 setup_gettext_from_context();
2153 $this->sendApprovalEmail();
2154 $this->addHistory('Approved', 'x');
2157 //change assistant for webcal
2159 $params[0] = $idadmin_group ;
2160 $params[1] = $this->getID();
2161 plugin_hook('change_cal_permission_default',$params);
2169 * sendApprovalEmail - Send new project email.
2171 * @return boolean success.
2174 function sendApprovalEmail() {
2175 $res_admins = db_query_params ('
2176 SELECT users.user_name,users.email,users.language,users.user_id
2177 FROM users,user_group
2178 WHERE users.user_id=user_group.user_id
2179 AND user_group.group_id=$1
2180 AND user_group.admin_flags=$2',
2181 array ($this->getID(),
2184 if (db_numrows($res_admins) < 1) {
2185 $this->setError(_("Group does not have any administrators."));
2189 // send one email per admin
2190 while ($row_admins = db_fetch_array($res_admins)) {
2191 $admin =& user_get_object($row_admins['user_id']);
2192 setup_gettext_for_user ($admin) ;
2194 $message=stripcslashes(sprintf(_('Your project registration for %4$s has been approved.
2196 Project Full Name: %1$s
2197 Project Unix Name: %2$s
2199 Your DNS will take up to a day to become active on our site.
2200 Your web site is accessible through your shell account. Please read
2201 site documentation (see link below) about intended usage, available
2202 services, and directory layout of the account.
2205 own project page in %4$s while logged in, you will find
2206 additional menu functions to your left labeled \'Project Admin\'.
2208 We highly suggest that you now visit %4$s and create a public
2209 description for your project. This can be done by visiting your project
2210 page while logged in, and selecting \'Project Admin\' from the menus
2211 on the left (or by visiting %3$s
2214 Your project will also not appear in the Trove Software Map (primary
2215 list of projects hosted on %4$s which offers great flexibility in
2216 browsing and search) until you categorize it in the project administration
2217 screens. So that people can find your project, you should do this now.
2218 Visit your project while logged in, and select \'Project Admin\' from the
2221 Enjoy the system, and please tell others about %4$s. Let us know
2222 if there is anything we can do to help you.
2225 $this->getPublicName(),
2226 $this->getUnixName(),
2227 util_make_url ('/project/admin/?group_id='.$this->getID()),
2228 $GLOBALS['sys_name']));
2230 util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), $GLOBALS['sys_name']), $message);
2232 setup_gettext_from_context();
2240 * sendRejectionEmail - Send project rejection email.
2242 * This function sends out a rejection message to a user who
2243 * registered a project.
2245 * @param int The id of the response to use.
2246 * @param string The rejection message.
2247 * @return completion status.
2250 function sendRejectionEmail($response_id, $message="zxcv") {
2251 $res_admins = db_query_params ('
2252 SELECT u.email, u.language, u.user_id
2253 FROM users u, user_group ug
2254 WHERE ug.group_id=$1
2255 AND u.user_id=ug.user_id',
2256 array ($this->getID())) ;
2257 if (db_numrows($res_admins) < 1) {
2258 $this->setError(_("Group does not have any administrators."));
2262 while ($row_admins = db_fetch_array($res_admins)) {
2263 $admin =& user_get_object($row_admins['user_id']);
2264 setup_gettext_for_user ($admin) ;
2266 $response=stripcslashes(sprintf(_('Your project registration for %3$s has been denied.
2268 Project Full Name: %1$s
2269 Project Unix Name: %2$s
2271 Reasons for negative decision:
2273 '), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name']));
2275 // Check to see if they want to send a custom rejection response
2276 if ($response_id == 0) {
2277 $response .= stripcslashes($message);
2279 $response .= db_result (
2280 db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array ($response_id)),
2285 util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), $GLOBALS['sys_name']), $response);
2286 setup_gettext_from_context();
2293 * sendNewProjectNotificationEmail - Send new project notification email.
2295 * This function sends out a notification email to the
2296 * SourceForge admin user when a new project is
2299 * @return boolean success.
2302 function sendNewProjectNotificationEmail() {
2303 // Get the user who wants to register the project
2304 $res = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1',
2305 array ($this->getID())) ;
2307 if (db_numrows($res) < 1) {
2308 $this->setError(_("Could not find user who has submitted the project."));
2312 $submitter =& user_get_object(db_result($res,0,'user_id'));
2315 $res = db_query_params ('SELECT users.email, users.language, users.user_id
2316 FROM users, user_group
2318 AND user_group.admin_flags=$1
2319 AND users.user_id=user_group.user_id',
2322 if (db_numrows($res) < 1) {
2323 $this->setError(_("There is no administrator to send the mail."));
2327 for ($i=0; $i<db_numrows($res) ; $i++) {
2328 $admin_email = db_result($res,$i,'email') ;
2329 $admin =& user_get_object(db_result($res,$i,'user_id'));
2330 setup_gettext_for_user ($admin) ;
2332 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2334 Project Full Name: %2$s
2335 Submitted Description: %3$s
2336 Submitter: %5$s (%6$s)
2338 Please visit the following URL to approve or reject this project:
2340 $GLOBALS['sys_name'],
2341 $this->getPublicName(),
2342 util_unconvert_htmlspecialchars($this->getRegistrationPurpose()),
2343 util_make_url ('/admin/approve-pending.php'),
2344 $submitter->getRealName(),
2345 $submitter->getUnixName()));
2346 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2347 setup_gettext_from_context();
2351 $email = $submitter->getEmail() ;
2352 setup_gettext_for_user ($submitter) ;
2354 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2356 Project Full Name: %2$s
2357 Submitted Description: %3$s
2359 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']));
2361 util_send_message($email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2362 setup_gettext_from_context();
2371 * validateGroupName - Validate the group name
2373 * @param string Group name.
2375 * @return an error false and set an error is the group name is invalide otherwise return true
2377 function validateGroupName($group_name) {
2378 if (strlen($group_name)<3) {
2379 $this->setError(_('Group name is too short'));
2381 } else if (strlen(htmlspecialchars($group_name))>50) {
2382 $this->setError(_('Group name is too long'));
2384 } else if ($group=group_get_object_by_publicname($group_name)) {
2385 $this->setError(_('Group name already taken'));
2397 * group_getname() - get the group name
2399 * @param int The group ID
2403 function group_getname ($group_id = 0) {
2404 $grp = &group_get_object($group_id);
2406 return $grp->getPublicName();
2413 * group_getunixname() - get the unixname for a group
2415 * @param int The group ID
2419 function group_getunixname ($group_id) {
2420 $grp = &group_get_object($group_id);
2422 return $grp->getUnixName();
2429 * group_get_result() - Get the group object result ID.
2431 * @param int The group ID
2435 function &group_get_result($group_id=0) {
2436 $grp = &group_get_object($group_id);
2438 return $grp->getData();
2445 * getUnixStatus - Status of activation of unix account.
2447 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2449 function getUnixStatus() {
2450 return $this->data_array['unix_status'];
2454 * setUnixStatus - Sets status of activation of unix account.
2456 * @param string The unix status.
2462 * @return boolean success.
2464 function setUnixStatus($status) {
2467 $res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
2472 $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
2476 if ($status == 'A') {
2477 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2478 $this->setError($SYS->getErrorMessage());
2483 if ($SYS->sysCheckGroup($this->getID())) {
2484 if (!$SYS->sysRemoveGroup($this->getID())) {
2485 $this->setError($SYS->getErrorMessage());
2492 $this->data_array['unix_status']=$status;
2500 // c-file-style: "bsd"