5 * Sets up database results and preferences for a group and abstracts this info.
7 * Foundry.class.php and Project.class.php call this.
9 * Project.class.php contains all the deprecated API from the old group.php file
11 * DEPENDS on user.php being present and setup properly
13 * GENERALLY YOU SHOULD NEVER INSTANTIATE THIS OBJECT DIRECTLY
14 * USE group_get_object() to instantiate properly
17 * @author Tim Perdue <tperdue@valinux.com>
20 * This file is part of GForge.
22 * GForge is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
27 * GForge is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with GForge; if not, write to the Free Software
34 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 require_once('common/tracker/ArtifactTypes.class.php');
38 require_once('common/tracker/ArtifactTypeFactory.class.php');
39 require_once('common/forum/Forum.class.php');
40 require_once('common/forum/ForumFactory.class.php');
41 require_once('common/pm/ProjectGroup.class.php');
42 require_once('common/pm/ProjectGroupFactory.class.php');
43 require_once('common/include/Role.class.php');
44 require_once('common/frs/FRSPackage.class.php');
45 require_once('common/docman/DocumentGroup.class.php');
46 require_once('common/mail/MailingList.class.php');
47 require_once('common/mail/MailingListFactory.class.php');
48 require_once('common/survey/SurveyFactory.class.php');
49 require_once('common/survey/SurveyQuestionFactory.class.php');
50 require_once('www/include/BaseLanguage.class.php');
52 //the license_id of "Other/proprietary" license
53 define('GROUP_LICENSE_OTHER',126);
55 $LICENSE_NAMES=array();
58 * group_get_licences() - get the licenses list
60 * @return array list of licenses
62 function & group_get_licenses() {
63 global $LICENSE_NAMES;
64 if(empty($LICENSE_NAMES)) {
65 $result = db_query('select * from licenses');
66 while($data = db_fetch_array($result)) {
67 $LICENSE_NAMES[$data['license_id']] = $data['license_name'];
70 return $LICENSE_NAMES;
76 * group_get_object() - Get the group object.
78 * group_get_object() is useful so you can pool group objects/save database queries
79 * You should always use this instead of instantiating the object directly.
81 * You can now optionally pass in a db result handle. If you do, it re-uses that query
82 * to instantiate the objects.
84 * IMPORTANT! That db result must contain all fields
85 * from groups table or you will have problems
88 * @param int Result set handle ("SELECT * FROM groups WHERE group_id=xx")
89 * @return a group object or false on failure
91 function &group_get_object($group_id,$res=false) {
92 //create a common set of group objects
93 //saves a little wear on the database
95 //automatically checks group_type and
96 //returns appropriate object
99 if (!isset($GROUP_OBJ["_".$group_id."_"])) {
101 //the db result handle was passed in
103 $res=db_query("SELECT * FROM groups WHERE group_id='$group_id'");
105 if (!$res || db_numrows($res) < 1) {
106 $GROUP_OBJ["_".$group_id."_"]=false;
109 check group type and set up object
111 if (db_result($res,0,'type_id')==1) {
113 $GROUP_OBJ["_".$group_id."_"]= new Group($group_id,$res);
116 $GROUP_OBJ["_".$group_id."_"]=false;
120 return $GROUP_OBJ["_".$group_id."_"];
123 function &group_get_objects($id_arr) {
126 // Note: if we don't do this, the result may be corrupted
130 for ($i=0; $i<count($id_arr); $i++) {
132 // See if this ID already has been fetched in the cache
137 if (!isset($GROUP_OBJ["_".$id_arr[$i]."_"])) {
138 $fetch[]=$id_arr[$i];
140 $return[] =& $GROUP_OBJ["_".$id_arr[$i]."_"];
143 if (count($fetch) > 0) {
144 $res=db_query("SELECT * FROM groups WHERE group_id IN ('".implode($fetch,'\',\'') ."')");
145 while ($arr =& db_fetch_array($res)) {
146 $GROUP_OBJ["_".$arr['group_id']."_"] = new Group($arr['group_id'],$arr);
147 $return[] =& $GROUP_OBJ["_".$arr['group_id']."_"];
153 function &group_get_object_by_name($groupname) {
154 $res=db_query("SELECT * FROM groups WHERE unix_group_name='$groupname'");
155 return group_get_object(db_result($res,0,'group_id'),$res);
158 function &group_get_objects_by_name($groupname_arr) {
159 $sql="SELECT group_id FROM groups WHERE unix_group_name IN ('".implode($groupname_arr,'\',\'')."')";
161 $arr =& util_result_column_to_array($res,0);
162 return group_get_objects($arr);
165 class Group extends Error {
167 * Associative array of data from db.
169 * @var array $data_array.
174 * array of User objects.
176 * @var array $membersArr.
181 * Permissions data row from db.
183 * @var array $perm_data_array.
185 var $perm_data_array;
188 * Whether the use is an admin/super user of this project.
190 * @var bool $is_admin.
195 * Artifact types result handle.
197 * @var int $types_res.
202 * Associative array of data for plugins.
204 * @var array $plugins_array.
209 * Group - Group object constructor - use group_get_object() to instantiate.
211 * @param int Required - group_id of the group you want to instantiate.
212 * @param int Database result from select query OR associative array of all columns.
214 function Group($id=false, $res=false) {
217 //setting up an empty object
218 //probably going to call create()
222 if (!$this->fetchData($id)) {
227 // Assoc array was passed in
229 if (is_array($res)) {
230 $this->data_array =& $res;
232 if (db_numrows($res) < 1) {
233 //function in class we extended
234 $this->setError('Group Not Found');
235 $this->data_array=array();
238 //set up an associative array for use by other functions
239 db_reset_result($res);
240 $this->data_array = db_fetch_array($res);
245 $systemGroups = array(GROUP_IS_NEWS, GROUP_IS_STATS, GROUP_IS_PEER_RATINGS);
246 if(!$this->isPublic() && !in_array($id, $systemGroups)) {
247 $perm =& $this->getPermission(session_get_user());
249 if (!$perm || !is_object($perm) || !$perm->isMember()) {
250 // cannot use $Language as it is not created yet
251 $this->setError('Permission denied', ERROR__PERMISSION_DENIED_ERROR);
259 * fetchData - May need to refresh database fields if an update occurred.
261 * @param int The group_id.
263 function fetchData($group_id) {
264 $res = db_query("SELECT * FROM groups WHERE group_id='$group_id'");
265 if (!$res || db_numrows($res) < 1) {
266 $this->setError('fetchData():: '.db_error());
269 $this->data_array =& db_fetch_array($res);
274 * create - Create new group.
276 * This method should be called on empty Group object.
278 * @param object The User object.
279 * @param string The full name of the user.
280 * @param string The Unix name of the user.
281 * @param string The new group description.
282 * @param int The ID of the license to use.
283 * @param string The 'other' license to use if any.
284 * @param string The purpose of the group.
286 function create(&$user, $full_name, $unix_name, $description, $license, $license_other, $purpose, $unix_box='shell1', $scm_box='cvs1') {
289 // $user is ignored - anyone can create pending group
291 if ($this->getID()!=0) {
292 $this->setError("Group::create: Group object already exists");
294 } else if (strlen($full_name)<3) {
295 $this->setError(_('Invalid full name'));
297 } else if (!account_groupnamevalid($unix_name)) {
298 $this->setError(_('Invalid unix name'));
300 } else if (db_numrows(db_query("SELECT group_id FROM groups WHERE unix_group_name='$unix_name'")) > 0) {
301 $this->setError(_('Unix name already taken'));
303 } else if (strlen($purpose)<10) {
304 $this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
306 } else if (strlen($purpose)>1500) {
307 $this->setError(_('The Registration Purpose text is too long. Please make it smaller than 1500 bytes.'));
309 } else if (strlen($description)<10) {
310 $this->setError(_('Describe in a more comprehensive manner your project.'));
312 } else if (strlen($description)>255) {
313 $this->setError(_('Your project description is too long. Please make it smaller than 256 bytes.'));
315 } else if (!$license) {
316 $this->setError(_('You do not have chosen a license'));
318 } else if ($license!=GROUP_LICENSE_OTHER && $license_other) {
319 $this->setError(_('Conflicting licenses choice'));
321 } else if ($license==GROUP_LICENSE_OTHER && strlen($license_other)<50) {
322 $this->setError(_('Please give more comprehensive licensing description'));
326 srand((double)microtime()*1000000);
327 $random_num = rand(0,1000000);
349 '".htmlspecialchars($full_name)."',
352 '".htmlspecialchars($description)."',
353 '$unix_name.".$GLOBALS['sys_default_domain']."',
354 '$unix_name.".$GLOBALS['sys_default_domain']."',
359 '".htmlspecialchars($purpose)."',
361 '".htmlspecialchars($license_other)."',
362 '".md5($random_num)."'
366 if (!$res || db_affected_rows($res) < 1) {
367 $this->setError('ERROR: Could not create group: '.db_error());
372 $id = db_insertid($res, 'groups', 'group_id');
374 $this->setError('ERROR: Could not get group id: '.db_error());
380 // Now, make the user an admin
382 $sql="INSERT INTO user_group ( user_id, group_id, admin_flags,
383 cvs_flags, artifact_flags, forum_flags, role_id)
384 VALUES ( ".$user->getID().", '$id', 'A', 1, 2, 2, 1)";
387 if (!$res || db_affected_rows($res) < 1) {
388 $this->setError('ERROR: Could not add admin to newly created group: '.db_error());
393 if (!$this->fetchData($id)) {
398 $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 string Project's license (string ident).
412 * @param int Group type (1-project, 2-foundry).
413 * @param string Machine on which group's home directory located.
414 * @param string Domain which serves group's WWW.
418 function updateAdmin(&$user, $is_public, $license, $type_id, $unix_box, $http_domain) {
421 $perm =& $this->getPermission($user);
423 if (!$perm || !is_object($perm)) {
424 $this->setError(_('Could not get permission.'));
428 if (!$perm->isSuperUser()) {
429 $this->setError(_('Permission denied.'));
437 SET is_public='$is_public',
438 license='$license',type_id='$type_id',
439 unix_box='$unix_box',http_domain='$http_domain'
440 WHERE group_id='".$this->getID()."'
443 if (!$res || db_affected_rows($res) < 1) {
444 $this->setError('ERROR: DB: Could not change group properties: '.db_error());
449 // Log the audit trail
450 if ($is_public != $this->isPublic()) {
451 $this->addHistory('is_public', $this->isPublic());
453 if ($license != $this->data_array['license']) {
454 $this->addHistory('license', $this->data_array['license']);
456 if ($type_id != $this->data_array['type_id']) {
457 $this->addHistory('type_id', $this->data_array['type_id']);
459 if ($unix_box != $this->data_array['unix_box']) {
460 $this->addHistory('unix_box', $this->data_array['unix_box']);
462 if ($http_domain != $this->data_array['http_domain']) {
463 $this->addHistory('http_domain', $this->data_array['http_domain']);
466 if (!$this->fetchData($this->getID())) {
475 * update - Update number of common properties.
477 * Unlike updateAdmin(), this function accessible to project admin.
479 * @param object User requesting operation (for access control).
480 * @param bool Whether group is publicly accessible (0/1).
481 * @param string Project's license (string ident).
482 * @param int Group type (1-project, 2-foundry).
483 * @param string Machine on which group's home directory located.
484 * @param string Domain which serves group's WWW.
485 * @return int status.
488 function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,
489 $use_pm,$use_pm_depend_box,$use_scm,$use_news,$use_docman,
490 $new_doc_address,$send_all_docs,$logo_image_id,
491 $enable_pserver,$enable_anonscm,
492 $use_ftp,$use_tracker,$use_frs,$use_stats) {
495 $perm =& $this->getPermission($user);
497 if (!$perm || !is_object($perm)) {
498 $this->setError(_('Could not get permission.'));
502 if (!$perm->isAdmin()) {
503 $this->setError(_('Permission denied.'));
507 // Validate some values
509 $this->setError('Invalid Group Name');
513 if ($new_doc_address) {
514 $invalid_mails = validate_emails($new_doc_address);
515 if (count($invalid_mails) > 0) {
516 $this->setError('New Doc Address(es) Appeared Invalid: '.implode(',',$invalid_mails));
521 // in the database, these all default to '1',
522 // so we have to explicity set 0
535 if (!$use_pm_depend_box) {
536 $use_pm_depend_box=0;
559 if (!$send_all_docs) {
564 $homepage=$GLOBALS['sys_default_domain'].'/projects/'.$this->getUnixName().'/';
567 if (strlen($short_description)>255) {
568 $this->setError('Error updating project information: Maximum length for Project Description is 255 chars.');
574 //XXX not yet actived logo_image_id='$logo_image_id',
578 group_name='".htmlspecialchars($group_name)."',
579 homepage='$homepage',
580 short_description='".htmlspecialchars($short_description)."',
581 use_mail='$use_mail',
582 use_survey='$use_survey',
583 use_forum='$use_forum',
585 use_pm_depend_box='$use_pm_depend_box',
587 use_news='$use_news',
588 use_docman='$use_docman',
589 new_doc_address='$new_doc_address',
590 send_all_docs='$send_all_docs',
592 if ($enable_pserver != '') {
594 enable_pserver='$enable_pserver',
597 if ($enable_anonscm != '') {
599 enable_anonscm='$enable_anonscm',
604 use_tracker='$use_tracker',
606 use_stats='$use_stats'
607 WHERE group_id='".$this->getID()."'
609 $res = db_query($sql);
612 $this->setError('Error updating project information: '.db_error());
617 // Log the audit trail
618 $this->addHistory('Changed Public Info', '');
620 if (!$this->fetchData($this->getID())) {
629 * getID - Simply return the group_id for this object.
631 * @return int group_id.
634 return $this->data_array['group_id'];
638 * getType() - Foundry, project, etc.
640 * @return int The type flag from the database.
643 return $this->data_array['type_id'];
648 * getStatus - the status code.
650 * Statuses char include I,H,A,D.
652 function getStatus() {
653 return $this->data_array['status'];
657 * setStatus - set the status code.
659 * Statuses include I,H,A,D.
661 * @param object User requesting operation (for access control).
662 * @param string Status value.
663 * @return boolean success.
666 function setStatus(&$user, $status) {
667 global $Language,$SYS;
669 $perm =& $this->getPermission($user);
670 if (!$perm || !is_object($perm)) {
671 $this->setPermissionDeniedError();
673 } elseif (!$perm->isSuperUser()) {
674 $this->setPermissionDeniedError();
678 // Projects in 'A' status can only go to 'H' or 'D'
679 // Projects in 'D' status can only go to 'A'
680 // Projects in 'P' status can only go to 'A' OR 'D'
681 // Projects in 'I' status can only go to 'P'
682 // Projects in 'H' status can only go to 'A' OR 'D'
683 $allowed_status_changes = array(
684 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
685 'IP'=>1,'HA'=>1,'HD'=>1
688 // Check that status transition is valid
689 if ($this->getStatus() != $status
690 && !$allowed_status_changes[$this->getStatus().$status]) {
691 $this->setError('Invalid Status Change');
697 $res = db_query("UPDATE groups
699 WHERE group_id='". $this->getID()."'");
701 if (!$res || db_affected_rows($res) < 1) {
702 $this->setError('ERROR: DB: Could not change group status: '.db_error());
708 // Activate system group, if not yet
709 if (!$SYS->sysCheckGroup($this->getID())) {
710 if (!$SYS->sysCreateGroup($this->getID())) {
711 $this->setError($SYS->getErrorMessage());
716 if (!$this->activateUsers()) {
721 /* Otherwise, the group is not active, and make sure that
722 System group is not active either */
723 } else if ($SYS->sysCheckGroup($this->getID())) {
724 if (!$SYS->sysRemoveGroup($this->getID())) {
725 $this->setError($SYS->getErrorMessage());
733 // Log the audit trail
734 if ($status != $this->getStatus()) {
735 $this->addHistory('status', $this->getStatus());
738 $this->data_array['status'] = $status;
743 * isProject - Simple boolean test to see if it's a project or not.
745 * @return boolean is_project.
747 function isProject() {
748 if ($this->getType()==1) {
756 * isPublic - Simply returns the is_public flag from the database.
758 * @return boolean is_public.
760 function isPublic() {
761 return $this->data_array['is_public'];
765 * isActive - Database field status of 'A' returns true.
767 * @return boolean is_active.
769 function isActive() {
770 if ($this->getStatus()=='A') {
778 * getUnixName - the unix_name
780 * @return string unix_name.
782 function getUnixName() {
783 return strtolower($this->data_array['unix_group_name']);
787 * getPublicName - the full-length public name.
789 * @return string The group_name.
791 function getPublicName() {
792 return $this->data_array['group_name'];
796 * getRegisterPurpose - the text description of the purpose of this project.
798 * @return string The description.
800 function getRegisterPurpose() {
801 return $this->data_array['register_purpose'];
805 * getDescription - the text description of this project.
807 * @return string The description.
809 function getDescription() {
810 return $this->data_array['short_description'];
814 * getStartDate - the unix time this project was registered.
816 * @return int (unix time) of registration.
818 function getStartDate() {
819 return $this->data_array['register_time'];
823 * getLogoImageID - the id of the logo in the database for this project.
825 * @return int The ID of logo image in db_images table (or 100 if none).
827 function getLogoImageID() {
828 return $this->data_array['logo_image_id'];
832 * getUnixBox - the hostname of the unix box where this project is located.
834 * @return string The name of the unix machine for the group.
836 function getUnixBox() {
837 return $this->data_array['unix_box'];
841 * getSCMBox - the hostname of the scm box where this project is located.
843 * @return string The name of the unix machine for the group.
845 function getSCMBox() {
846 return $this->data_array['scm_box'];
849 * setSCMBox - the hostname of the scm box where this project is located.
851 * @param string The name of the new SCM_BOX
853 function setSCMBox($scm_box) {
858 $sql = "UPDATE groups SET scm_box = '$scm_box' WHERE group_id = ".$this->getID();
859 $res = db_query($sql);
861 $this->addHistory('scm_box', $this->data_array['scm_box']);
862 $this->data_array['scm_box']=$scm_box;
867 $this->setError('Couldn\'t insert SCM_BOX to database');
871 $this->setError(_('SCM Box can\'t be empty'));
877 * getDomain - the hostname.domain where their web page is located.
879 * @return string The name of the group [web] domain.
881 function getDomain() {
882 return $this->data_array['http_domain'];
886 * getLicense - the license they chose.
888 * @return int ident of group license.
890 function getLicense() {
891 return $this->data_array['license'];
895 * getLicenseName - the name of the license
897 * @return string license name
899 function getLicenseName() {
900 $licenses =& group_get_licenses();
901 if(isset($licenses[$this->data_array['license']])) {
902 return $licenses[$this->data_array['license']];
909 * getLicenseOther - optional string describing license.
911 * @return string The custom license.
913 function getLicenseOther() {
914 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
915 return $this->data_array['license_other'];
922 * getRegistrationPurpose - the text description of the purpose of this project.
924 * @return string The application for project hosting.
926 function getRegistrationPurpose() {
927 return $this->data_array['register_purpose'];
932 * getAdmins() - Get array of Admin user objects.
934 * @return array Array of User objects.
936 function &getAdmins() {
937 // this function gets all group admins in order to send Jabber and mail messages
938 $q = "SELECT user_id FROM user_group WHERE admin_flags = 'A' AND group_id = ".$this->getID();
940 $user_ids=util_result_column_to_array($res);
941 return user_get_objects($user_ids);
946 Common Group preferences for tools
951 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
953 * @return boolean enable_scm.
955 function enableAnonSCM() {
956 if ($this->isPublic() && $this->usesSCM()) {
957 return $this->data_array['enable_anonscm'];
963 function SetUsesAnonSCM ($booleanparam) {
965 $booleanparam = $booleanparam ? 1 : 0 ;
966 $sql = "UPDATE groups SET enable_anonscm = $booleanparam WHERE group_id = ".$this->getID() ;
967 $res = db_query($sql);
969 $this->data_array['enable_anonscm']=$booleanparam;
978 * enablePserver - whether or not this group has opted to enable Pserver.
980 * @return boolean enable_pserver.
982 function enablePserver() {
983 if ($this->usesSCM()) {
984 return $this->data_array['enable_pserver'];
990 function SetUsesPserver ($booleanparam) {
992 $booleanparam = $booleanparam ? 1 : 0 ;
993 $sql = "UPDATE groups SET enable_pserver = $booleanparam WHERE group_id = ".$this->getID() ;
994 $res = db_query($sql);
996 $this->data_array['enable_pserver']=$booleanparam;
1005 * usesSCM - whether or not this group has opted to use SCM.
1007 * @return boolean uses_scm.
1009 function usesSCM() {
1010 global $sys_use_scm;
1012 return $this->data_array['use_scm'];
1019 * usesMail - whether or not this group has opted to use mailing lists.
1021 * @return boolean uses_mail.
1023 function usesMail() {
1024 global $sys_use_mail;
1025 if ($sys_use_mail) {
1026 return $this->data_array['use_mail'];
1033 * usesNews - whether or not this group has opted to use news.
1035 * @return boolean uses_news.
1037 function usesNews() {
1038 global $sys_use_news;
1039 if ($sys_use_news) {
1040 return $this->data_array['use_news'];
1047 * usesForum - whether or not this group has opted to use discussion forums.
1049 * @return boolean uses_forum.
1051 function usesForum() {
1052 global $sys_use_forum;
1053 if ($sys_use_forum) {
1054 return $this->data_array['use_forum'];
1061 * usesStats - whether or not this group has opted to use stats.
1063 * @return boolean uses_stats.
1065 function usesStats() {
1066 return $this->data_array['use_stats'];
1070 * usesFRS - whether or not this group has opted to use file release system.
1072 * @return boolean uses_frs.
1074 function usesFRS() {
1075 global $sys_use_frs;
1077 return $this->data_array['use_frs'];
1084 * usesTracker - whether or not this group has opted to use tracker.
1086 * @return boolean uses_tracker.
1088 function usesTracker() {
1089 global $sys_use_tracker;
1090 if ($sys_use_tracker) {
1091 return $this->data_array['use_tracker'];
1098 * usesDocman - whether or not this group has opted to use docman.
1100 * @return boolean uses_docman.
1102 function usesDocman() {
1103 global $sys_use_docman;
1104 if ($sys_use_docman) {
1105 return $this->data_array['use_docman'];
1112 * usesFTP - whether or not this group has opted to use FTP.
1114 * @return boolean uses_ftp.
1116 function usesFTP() {
1117 global $sys_use_ftp;
1119 return $this->data_array['use_ftp'];
1126 * usesSurvey - whether or not this group has opted to use surveys.
1128 * @return boolean uses_survey.
1130 function usesSurvey() {
1131 global $sys_use_survey;
1132 if ($sys_use_survey) {
1133 return $this->data_array['use_survey'];
1140 * usesPM - whether or not this group has opted to Project Manager.
1142 * @return boolean uses_projman.
1147 return $this->data_array['use_pm'];
1154 * getPlugins - get a list of all available group plugins
1156 * @return array array containing plugin_id => plugin_name
1158 function getPlugins() {
1159 if (!isset($this->plugins_data)) {
1160 $this->plugins_data = array () ;
1161 $sql="SELECT group_plugin.plugin_id, plugins.plugin_name
1162 FROM group_plugin, plugins
1163 WHERE group_plugin.group_id=".$this->getID()."
1164 AND group_plugin.plugin_id = plugins.plugin_id" ;
1165 $res=db_query($sql);
1166 $rows = db_numrows($res);
1168 for ($i=0; $i<$rows; $i++) {
1169 $plugin_id = db_result($res,$i,'plugin_id');
1170 $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
1173 return $this->plugins_data ;
1177 * usesPlugin - returns true if the group uses a particular plugin
1179 * @param string name of the plugin
1180 * @return boolean whether plugin is being used or not
1182 function usesPlugin($pluginname) {
1183 $plugins_data = $this->getPlugins() ;
1184 foreach ($plugins_data as $p_id => $p_name) {
1185 if ($p_name == $pluginname) {
1193 * setPluginUse - enables/disables plugins for the group
1195 * @param string name of the plugin
1196 * @param boolean the new state
1197 * @return string database result
1199 function setPluginUse($pluginname, $val=true) {
1200 if ($val == $this->usesPlugin($pluginname)) {
1201 // State is already good, returning
1204 $sql="SELECT plugin_id
1206 WHERE plugin_name = '" . $pluginname . "'" ;
1207 $res=db_query($sql);
1208 $rows = db_numrows($res);
1210 // Error: no plugin by that name
1213 $plugin_id = db_result($res,0,'plugin_id');
1215 unset ($this->plugins_data) ;
1217 $sql="INSERT INTO group_plugin (group_id, plugin_id)
1218 VALUES (". $this->getID() . ", ". $plugin_id .")" ;
1219 $res=db_query($sql);
1222 $sql="DELETE FROM group_plugin
1223 WHERE group_id = ". $this->getID() . "
1224 AND plugin_id = ". $plugin_id ;
1225 $res=db_query($sql);
1231 * getDocEmailAddress - get email address(es) to send doc notifications to.
1233 * @return string email address.
1235 function getDocEmailAddress() {
1236 return $this->data_array['new_doc_address'];
1240 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1242 * @return boolean email_on_all_doc_updates.
1244 function docEmailAll() {
1245 return $this->data_array['send_all_docs'];
1250 * getHomePage - The URL for this project's home page.
1252 * @return string homepage URL.
1254 function getHomePage() {
1255 return $this->data_array['homepage'];
1259 * getPermission - Return a Permission for this Group and the specified User.
1261 * @param object The user you wish to get permission for (usually the logged in user).
1262 * @return object The Permission.
1264 function &getPermission(&$_user) {
1265 return permission_get_object($this, $_user);
1270 * userIsAdmin - Return if for this Group the User is admin.
1272 * @return boolean is_admin.
1274 function userIsAdmin() {
1275 $perm =& $this->getPermission( session_get_user() );
1276 if (!$perm || !is_object($perm)) {
1278 } elseif ($perm->isError()) {
1281 return $perm->isAdmin();
1284 function delete($sure,$really_sure,$really_really_sure) {
1287 if (!$sure || !$really_sure || !$really_really_sure) {
1288 $this->setMissingParamsError();
1291 if ($this->getID() == $GLOBALS['sys_news_group'] ||
1292 $this->getID() == 1 ||
1293 $this->getID() == $GLOBALS['sys_stats_group'] ||
1294 $this->getID() == $GLOBALS['sys_peer_rating_group']) {
1295 $this->setError('Cannot Delete System Group');
1298 $perm =& $this->getPermission( session_get_user() );
1299 if (!$perm || !is_object($perm)) {
1300 $this->setPermissionDeniedError();
1302 } elseif ($perm->isError()) {
1303 $this->setPermissionDeniedError();
1305 } elseif (!$perm->isSuperUser()) {
1306 $this->setPermissionDeniedError();
1312 // Remove all the members
1314 $members =& $this->getMembers();
1315 for ($i=0; $i<count($members); $i++) {
1316 $this->removeUser($members[$i]->getID());
1317 //echo 'RemoveMembers'.db_error();
1322 $atf = new ArtifactTypeFactory($this);
1323 $at_arr =& $atf->getArtifactTypes();
1324 for ($i=0; $i<count($at_arr); $i++) {
1325 if (!is_object($at_arr[$i])) {
1326 echo "Not Object: ArtifactType: ".$i;
1329 $at_arr[$i]->delete(1,1);
1330 //echo 'ArtifactTypeFactory'.db_error();
1335 $ff = new ForumFactory($this);
1336 $f_arr =& $ff->getForums();
1337 for ($i=0; $i<count($f_arr); $i++) {
1338 if (!is_object($f_arr[$i])) {
1339 echo "Not Object: Forum: ".$i;
1342 $f_arr[$i]->delete(1,1);
1343 //echo 'ForumFactory'.db_error();
1346 // Delete Subprojects
1348 $pgf = new ProjectGroupFactory($this);
1349 $pg_arr =& $pgf->getProjectGroups();
1350 for ($i=0; $i<count($pg_arr); $i++) {
1351 if (!is_object($pg_arr[$i])) {
1352 echo "Not Object: ProjectGroup: ".$i;
1355 $pg_arr[$i]->delete(1,1);
1356 //echo 'ProjectGroupFactory'.db_error();
1359 // Delete FRS Packages
1361 //$frspf = new FRSPackageFactory($this);
1362 $res=db_query("SELECT * FROM frs_package WHERE group_id='".$this->getID()."'");
1363 //echo 'frs_package'.db_error();
1364 //$frsp_arr =& $frspf->getPackages();
1365 while ($arr = db_fetch_array($res)) {
1366 //if (!is_object($pg_arr[$i])) {
1367 // echo "Not Object: ProjectGroup: ".$i;
1370 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1376 $news_group=&group_get_object($GLOBALS['sys_news_group']);
1377 $res=db_query("SELECT forum_id FROM news_bytes WHERE group_id='".$this->getID()."'");
1378 for ($i=0; $i<db_numrows($res); $i++) {
1379 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1380 if (!$Forum->delete(1,1)) {
1381 echo "Could Not Delete News Forum: ".$Forum->getID();
1384 $res=db_query("DELETE FROM news_bytes WHERE group_id='".$this->getID()."'");
1389 $res=db_query("DELETE FROM doc_data WHERE group_id='".$this->getID()."'");
1390 //echo 'doc_data'.db_error();
1391 $res=db_query("DELETE FROM doc_groups WHERE group_id='".$this->getID()."'");
1392 //echo 'doc_groups'.db_error();
1394 // Delete group history
1396 $res=db_query("DELETE FROM group_history WHERE group_id='".$this->getID()."'");
1397 //echo 'group_history'.db_error();
1399 // Delete group plugins
1401 $res=db_query("DELETE FROM group_plugin WHERE group_id='".$this->getID()."'");
1402 //echo 'group_plugin'.db_error();
1404 // Delete group cvs stats
1406 $res=db_query("DELETE FROM stats_cvs_group WHERE group_id='".$this->getID()."'");
1407 //echo 'stats_cvs_group'.db_error();
1411 $sf = new SurveyFactory($this);
1412 $s_arr =& $sf->getSurveys();
1413 for ($i=0; $i<count($s_arr); $i++) {
1414 if (!is_object($s_arr[$i])) {
1415 echo "Not Object: Survey: ".$i;
1418 $s_arr[$i]->delete();
1419 //echo 'SurveyFactory'.db_error();
1422 // Delete SurveyQuestions
1424 $sqf = new SurveyQuestionFactory($this);
1425 $sq_arr =& $sqf->getSurveyQuestions();
1426 for ($i=0; $i<count($sq_arr); $i++) {
1427 if (!is_object($sq_arr[$i])) {
1428 echo "Not Object: SurveyQuestion: ".$i;
1431 $sq_arr[$i]->delete();
1432 //echo 'SurveyQuestionFactory'.db_error();
1435 // Delete Mailing List Factory
1437 $mlf = new MailingListFactory($this);
1438 $ml_arr =& $mlf->getMailingLists();
1439 for ($i=0; $i<count($ml_arr); $i++) {
1440 if (!is_object($ml_arr[$i])) {
1441 echo "Not Object: MailingList: ".$i;
1444 if (!$ml_arr[$i]->delete(1,1)) {
1445 $this->setError(_('Could not delete properly the mailing list'));
1447 //echo 'MailingListFactory'.db_error();
1452 $res=db_query("DELETE FROM trove_group_link WHERE group_id='".$this->getID()."'");
1453 $res=db_query("DELETE FROM trove_agg WHERE group_id='".$this->getID()."'");
1457 $res=db_query("DELETE FROM project_sums_agg WHERE group_id='".$this->getID()."'");
1458 //echo 'project_sums_agg'.db_error();
1459 $res=db_query("INSERT INTO deleted_groups (
1460 unix_group_name,delete_date,isdeleted) VALUES
1461 ('".$this->getUnixName()."','".time()."','0')");
1462 //echo 'InsertIntoDeleteQueue'.db_error();
1463 $res=db_query("DELETE FROM groups WHERE group_id='".$this->getID()."'");
1464 //echo 'DeleteGroup'.db_error();
1469 if (isset($GLOBALS['sys_upload_dir']) && $this->getUnixName()) {
1470 exec('/bin/rm -rf '.$GLOBALS['sys_upload_dir'].'/'.$this->getUnixName().'/');
1472 if (isset($GLOBALS['sys_ftp_upload_dir']) && $this->getUnixName()) {
1473 exec('/bin/rm -rf '.$GLOBALS['sys_ftp_upload_dir'].'/'.$this->getUnixName().'/');
1478 $res=db_query("DELETE FROM rep_group_act_weekly WHERE group_id='".$this->getID()."'");
1479 //echo 'rep_group_act_weekly'.db_error();
1480 $res=db_query("DELETE FROM rep_group_act_monthly WHERE group_id='".$this->getID()."'");
1481 //echo 'rep_group_act_monthly'.db_error();
1482 $res=db_query("DELETE FROM rep_group_act_daily WHERE group_id='".$this->getID()."'");
1483 //echo 'rep_group_act_daily'.db_error();
1484 unset($this->data_array);
1492 Basic functions to add/remove users to/from a group
1493 and update their permissions
1499 * addUser - controls adding a user to a group.
1501 * @param string Unix name of the user to add OR integer user_id.
1502 * @param int The role_id this user should have.
1503 * @return boolean success.
1506 function addUser($user_unix_name,$role_id) {
1507 global $Language,$SYS;
1509 Admins can add users to groups
1512 $perm =& $this->getPermission( session_get_user() );
1513 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1514 $this->setPermissionDeniedError();
1520 get user id for this user's unix_name
1522 if (eregi('[^0-9]',$user_unix_name)) {
1523 $res_newuser = db_query("SELECT * FROM users WHERE user_name='". strtolower($user_unix_name) ."'");
1525 $res_newuser = db_query("SELECT * FROM users WHERE user_id='". intval($user_unix_name) ."'");
1527 if (db_numrows($res_newuser) > 0) {
1529 // make sure user is active
1531 if (db_result($res_newuser,0,'status') != 'A') {
1532 $this->setError('User is not active. Only active users can be added.');
1538 // user was found - set new user_id var
1540 $user_id = db_result($res_newuser,0,'user_id');
1543 // if not already a member, add them
1545 $res_member = db_query("SELECT user_id
1547 WHERE user_id='$user_id' AND group_id='". $this->getID() ."'");
1549 if (db_numrows($res_member) < 1) {
1551 // Create this user's row in the user_group table
1553 $res=db_query("INSERT INTO user_group
1554 (user_id,group_id,admin_flags,forum_flags,project_flags,
1555 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
1556 VALUES ('$user_id','". $this->getID() ."','','0','0','0','1','100','0','0')");
1558 //verify the insert worked
1559 if (!$res || db_affected_rows($res) < 1) {
1560 $this->setError('ERROR: Could Not Add User To Group: '.db_error());
1565 // check and create if group doesn't exists
1567 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
1568 if (!$SYS->sysCheckCreateGroup($this->getID())){
1569 $this->setError($SYS->getErrorMessage());
1574 // check and create if user doesn't exists
1576 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1577 if (!$SYS->sysCheckCreateUser($user_id)) {
1578 $this->setError($SYS->getErrorMessage());
1585 $role = new Role($this,$role_id);
1586 if (!$role || !is_object($role)) {
1587 $this->setError('Error Getting Role Object');
1590 } elseif ($role->isError()) {
1591 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1595 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
1596 if (!$role->setUser($user_id)) {
1597 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1603 // user was already a member
1604 // make sure they are set up
1606 $user=&user_get_object($user_id,$res_newuser);
1607 $user->fetchData($user->getID());
1608 $role = new Role($this,$role_id);
1609 if (!$role || !is_object($role)) {
1610 $this->setError('Error Getting Role Object');
1613 } elseif ($role->isError()) {
1614 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1618 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
1619 if (!$role->setUser($user_id)) {
1620 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1625 // set up their system info
1627 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1628 if (!$SYS->sysCheckCreateUser($user_id)) {
1629 $this->setError($SYS->getErrorMessage());
1638 // user doesn't exist
1640 $this->setError('ERROR: User does not exist');
1647 $this->addHistory('Added User',$user_unix_name);
1653 * removeUser - controls removing a user from a group.
1655 * Users can remove themselves.
1657 * @param int The ID of the user to remove.
1658 * @return boolean success.
1660 function removeUser($user_id) {
1661 global $Language,$SYS,$sys_database_type;
1663 if ($user_id==user_getid()) {
1664 //users can remove themselves
1665 //everyone else must be a project admin
1667 $perm =& $this->getPermission( session_get_user() );
1669 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1670 $this->setPermissionDeniedError();
1676 $res=db_query("DELETE FROM user_group
1677 WHERE group_id='".$this->getID()."'
1678 AND user_id='$user_id'");
1679 if (!$res || db_affected_rows($res) < 1) {
1680 $this->setError('ERROR: DB: User not removed.'.db_error());
1685 // reassign open artifacts to id=100
1687 $res=db_query("UPDATE artifact SET assigned_to='100'
1688 WHERE group_artifact_id
1689 IN (SELECT group_artifact_id
1690 FROM artifact_group_list
1691 WHERE group_id='".$this->getID()."')
1692 AND status_id='1' AND assigned_to='$user_id'");
1694 $this->setError('ERROR: DB: artifact.'.db_error());
1700 // reassign open tasks to id=100
1701 // first have to purge any assignments that would cause
1702 // conflict with existing assignment to 100
1704 if ($sys_database_type == 'mysql') {
1706 SELECT pt.project_task_id
1707 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1708 WHERE pt.group_project_id = pgl.group_project_id
1709 AND pat.project_task_id=pt.project_task_id
1710 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."'
1711 AND pat.assigned_to_id='$user_id' INTO @task_list;
1712 DELETE FROM project_assigned_to WHERE project_task_id IN ( @task_list ) AND assigned_to_id='100'");
1714 $res = db_next_result();
1717 $res=db_query("DELETE FROM project_assigned_to
1718 WHERE project_task_id IN (SELECT pt.project_task_id
1719 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1720 WHERE pt.group_project_id = pgl.group_project_id
1721 AND pat.project_task_id=pt.project_task_id
1722 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."'
1723 AND pat.assigned_to_id='$user_id')
1724 AND assigned_to_id='100'");
1727 $this->setError('ERROR: DB: project_assigned_to 1 - '.db_error());
1731 $res=db_query("UPDATE project_assigned_to SET assigned_to_id='100'
1732 WHERE project_task_id IN (SELECT pt.project_task_id
1733 FROM project_task pt, project_group_list pgl
1734 WHERE pt.group_project_id = pgl.group_project_id
1735 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."')
1736 AND assigned_to_id='$user_id'");
1738 $this->setError('ERROR: DB: project_assigned_to 2 - '.db_error());
1744 // Remove user from system
1746 //echo "<h2>Group::addUser SYS->sysGroupRemoveUser(".$this->getID().",$user_id)</h2>";
1747 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
1748 $this->setError($SYS->getErrorMessage());
1753 $this->addHistory('removed user',$user_id);
1760 * updateUser - controls updating a user's role in this group.
1762 * @param int The ID of the user.
1763 * @param int The role_id to set this user to.
1764 * @return boolean success.
1766 function updateUser($user_id,$role_id) {
1767 global $Language,$SYS;
1769 $perm =& $this->getPermission( session_get_user() );
1770 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1771 $this->setPermissionDeniedError();
1775 $role = new Role($this,$role_id);
1776 if (!$role || !is_object($role)) {
1777 $this->setError('Could Not Get Role');
1779 } elseif ($role->isError()) {
1780 $this->setError('Role: '.$role->getErrorMessage());
1783 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
1784 if (!$role->setUser($user_id)) {
1785 $this->setError('Role: '.$role->getErrorMessage());
1788 $this->addHistory('updated user',$user_id);
1793 * addHistory - Makes an audit trail entry for this project.
1795 * @param string The name of the field.
1796 * @param string The Old Value for this $field_name.
1797 * @return database result handle.
1800 function addHistory($field_name, $old_value) {
1802 INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
1803 VALUES ('". $this->getID() ."','$field_name','$old_value','". user_getid() ."','".time()."')
1805 return db_query($sql);
1809 * activateUsers - Make sure that group members have unix accounts.
1811 * Setup unix accounts for group members. Can be called even
1812 * if members are already active.
1816 function activateUsers() {
1819 Activate member(s) of the project
1822 $member_res = db_query("SELECT user_id, role_id
1824 WHERE group_id='".$this->getID()."'");
1826 $rows = db_numrows($member_res);
1830 for ($i=0; $i<$rows; $i++) {
1832 $member =& user_get_object(db_result($member_res,$i,'user_id'));
1833 $roleId = db_result($member_res,$i,'role_id');
1835 if (!$member || !is_object($member)) {
1836 $this->setError('Error getting member object');
1838 } else if ($member->isError()) {
1839 $this->setError('Error getting member object: '.$member->getErrorMessage());
1843 if (!$this->addUser($member->getUnixName(),$roleId)) {
1854 * getMembers - returns array of User objects for this project
1856 * @return array of User objects for this group.
1858 function &getMembers() {
1859 if (!isset($this->membersArr)) {
1860 $res=db_query("SELECT users.* FROM users
1861 INNER JOIN user_group ON users.user_id=user_group.user_id
1862 WHERE user_group.group_id='".$this->getID()."'");
1863 while ($arr =& db_fetch_array($res)) {
1864 $this->membersArr[] =& new User($arr['user_id'],$arr);
1867 return $this->membersArr;
1871 * approve - Approve pending project.
1873 * @param object The User object who is doing the updating.
1876 function approve(&$user) {
1878 if ($this->getStatus()=='A') {
1879 $this->setError("Group already active");
1885 // Step 1: Activate group and create LDAP entries
1886 if (!$this->setStatus($user, 'A')) {
1893 // Tracker Integration
1896 $ats = new ArtifactTypes($this);
1897 if (!$ats || !is_object($ats)) {
1898 $this->setError('Error creating ArtifactTypes object');
1901 } else if ($ats->isError()) {
1902 $this->setError('ATS1 '.$ats->getErrorMessage());
1906 if (!$ats->createTrackers()) {
1907 $this->setError('ATS2 '.$ats->getErrorMessage());
1914 // Forum Integration
1917 $f = new Forum($this);
1918 if (!$f->create('Open-Discussion','General Discussion',1,'',1,0)) {
1919 $this->setError('F1 '.$f->getErrorMessage());
1923 $f = new Forum($this);
1924 if (!$f->create('Help','Get Public Help',1,'',1,0)) {
1925 $this->setError('F2 '.$f->getErrorMessage());
1929 $f = new Forum($this);
1930 if (!$f->create('Developers','Project Developer Discussion',0,'',1,0)) {
1931 $this->setError('F3 '.$f->getErrorMessage());
1938 // Doc Mgr Integration
1941 $dg = new DocumentGroup($this);
1942 if (!$dg->create('Uncategorized Submissions')) {
1943 $this->setError('DG1 '.$dg->getErrorMessage());
1953 $frs = new FRSPackage($this);
1954 if (!$frs->create($this->getUnixName())) {
1955 $this->setError('FRSP '.$frs->getErrorMessage());
1965 $pg = new ProjectGroup($this);
1966 if (!$pg->create('To Do','Things We Have To Do',1)) {
1967 $this->setError('PG1 '.$pg->getErrorMessage());
1971 $pg = new ProjectGroup($this);
1972 if (!$pg->create('Next Release','Items For Our Next Release',1)) {
1973 $this->setError('PG2 '.$pg->getErrorMessage());
1980 // Set Default Roles
1983 $role = new Role($this);
1984 $todo = array_keys($role->defaults);
1985 for ($c=0; $c<count($todo); $c++) {
1986 $role = new Role($this);
1987 if (!$role->createDefault($todo[$c])) {
1988 $this->setError('R'.$c.' '.$role->getErrorMessage());
1996 // Create MailingList
1999 $mlist = new MailingList($this);
2000 $admin_group = db_query("SELECT user_id FROM user_group
2001 WHERE group_id=".$this->getID()." AND admin_flags='A'");
2002 if (db_numrows($admin_group) > 0) {
2003 $idadmin_group = db_result($admin_group,0,'user_id');
2005 if (!$mlist->create('commits','cvs commits',1,$idadmin_group)) {
2006 $this->setError('MailingList: '.$mlist->getErrorMessage());
2013 $this->sendApprovalEmail();
2014 $this->addHistory('approved', 'x');
2017 //change assistant for webcal
2019 $params[0] = $idadmin_group ;
2020 $params[1] = $this->getID();
2021 plugin_hook('change_cal_permission_default',$params);
2029 * sendApprovalEmail - Send new project email.
2031 * @return boolean success.
2034 function sendApprovalEmail() {
2035 $res_admins = db_query("
2036 SELECT users.user_name,users.email,users.language,users.user_id
2037 FROM users,user_group
2038 WHERE users.user_id=user_group.user_id
2039 AND user_group.group_id='".$this->getID()."'
2040 AND user_group.admin_flags='A'
2043 if (db_numrows($res_admins) < 1) {
2044 $this->setError("Group does not have any administrators.");
2048 // send one email per admin
2049 while ($row_admins = db_fetch_array($res_admins)) {
2050 $admin =& user_get_object($row_admins['user_id']);
2051 setup_gettext_for_user ($admin) ;
2053 // $2 $2 $3 $4 $5 $6
2054 $message=stripcslashes(sprintf(_('Your project registration for %7$s has been approved.
2056 Project Full Name: %1$s
2057 Project Unix Name: %2$s
2059 Your DNS will take up to a day to become active on our site.
2060 Your web site is accessible through your shell account. Please read
2061 site documentation (see link below) about intended usage, available
2062 services, and directory layout of the account.
2065 own project page in %7$s while logged in, you will find
2066 additional menu functions to your left labeled \'Project Admin\'.
2068 We highly suggest that you now visit %7$s and create a public
2069 description for your project. This can be done by visiting your project
2070 page while logged in, and selecting \'Project Admin\' from the menus
2071 on the left (or by visiting http://%3$s/project/admin/?group_id=%6$s
2074 Your project will also not appear in the Trove Software Map (primary
2075 list of projects hosted on %7$s which offers great flexibility in
2076 browsing and search) until you categorize it in the project administration
2077 screens. So that people can find your project, you should do this now.
2078 Visit your project while logged in, and select \'Project Admin\' from the
2081 Enjoy the system, and please tell others about %7$s. Let us know
2082 if there is anything we can do to help you.
2084 -- the %7$s crew'), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_default_domain'], $GLOBALS['sys_shell_host'], $GLOBALS['sys_scm_host'], $this->getID(), $GLOBALS['sys_name']));
2086 util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), $GLOBALS['sys_name']), $message);
2088 setup_gettext_from_browser () ;
2096 * sendRejectionEmail - Send project rejection email.
2098 * This function sends out a rejection message to a user who
2099 * registered a project.
2101 * @param int The id of the response to use.
2102 * @param string The rejection message.
2103 * @return completion status.
2106 function sendRejectionEmail($response_id, $message="zxcv") {
2107 $res_admins = db_query("
2108 SELECT u.email, u.language, u.user_id
2109 FROM users u, user_group ug
2110 WHERE ug.group_id='".$this->getID()."'
2111 AND u.user_id=ug.user_id;
2114 if (db_numrows($res_admins) < 1) {
2115 $this->setError("Group does not have any administrators.");
2119 while ($row_admins = db_fetch_array($res_admins)) {
2120 $admin =& user_get_object($row_admins['user_id']);
2121 setup_gettext_for_user ($admin) ;
2123 $response=stripcslashes(sprintf(_('Your project registration for %3$s has been denied.
2125 Project Full Name: %1$s
2126 Project Unix Name: %2$s
2128 Reasons for negative decision:
2130 '), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name']));
2132 // Check to see if they want to send a custom rejection response
2133 if ($response_id == 0) {
2134 $response .= stripcslashes($message);
2136 $response .= db_result(db_query("
2137 SELECT response_text
2138 FROM canned_responses
2139 WHERE response_id='$response_id'
2140 "), 0, "response_text");
2143 util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), $GLOBALS['sys_name']), $response);
2144 setup_gettext_from_browser () ;
2151 * sendNewProjectNotificationEmail - Send new project notification email.
2153 * This function sends out a notification email to the
2154 * SourceForge admin user when a new project is
2157 * @return boolean success.
2160 function sendNewProjectNotificationEmail() {
2162 $res = db_query("SELECT users.email, users.language, users.user_id
2163 FROM users,user_group
2165 AND user_group.admin_flags='A'
2166 AND users.user_id=user_group.user_id;");
2168 if (db_numrows($res) < 1) {
2169 $this->setError("There is no administrator to send the mail.");
2172 for ($i=0; $i<db_numrows($res) ; $i++) {
2173 $admin_email = db_result($res,$i,'email') ;
2174 $admin =& user_get_object(db_result($res,$i,'user_id'));
2175 setup_gettext_for_user ($admin) ;
2177 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2179 Project Full Name: %2$s
2180 Submitted Description: %3$s
2183 Please visit the following URL to approve or reject this project:
2184 http://%5$s/admin/approve-pending.php'), $GLOBALS['sys_name'], $this->getPublicName(), util_unconvert_htmlspecialchars($this->getRegistrationPurpose()), $this->getLicenseName(), $GLOBALS['sys_default_domain']));
2185 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2186 setup_gettext_from_browser () ;
2190 // Get the email of the user who wants to register the project
2191 $res = db_query("SELECT u.email, u.language, u.user_id
2192 FROM users u, user_group ug
2193 WHERE ug.group_id='".$this->getID()."' AND u.user_id=ug.user_id;");
2195 if (db_numrows($res) < 1) {
2196 $this->setError("Cound not find user who has submitted the project.");
2199 for ($i=0; $i<db_numrows($res) ; $i++) {
2200 $email = db_result($res, $i, 'email');
2201 $user =& user_get_object(db_result($res,$i,'user_id'));
2202 setup_gettext_for_user ($user) ;
2204 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2206 Project Full Name: %2$s
2207 Submitted Description: %3$s
2210 The %1$s admin team will now examine your project submission. You will be notified of their decision.'), $GLOBALS['sys_name'], $this->getPublicName(), util_unconvert_htmlspecialchars($this->getRegistrationPurpose()), $this->getLicenseName(), $GLOBALS['sys_default_domain']));
2212 util_send_message($email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2213 setup_gettext_from_browser () ;
2223 * group_getname() - get the group name
2225 * @param int The group ID
2229 function group_getname ($group_id = 0) {
2230 $grp = &group_get_object($group_id);
2232 return $grp->getPublicName();
2239 * group_getunixname() - get the unixname for a group
2241 * @param int The group ID
2245 function group_getunixname ($group_id) {
2246 $grp = &group_get_object($group_id);
2248 return $grp->getUnixName();
2255 * group_get_result() - Get the group object result ID.
2257 * @param int The group ID
2261 function &group_get_result($group_id=0) {
2262 $grp = &group_get_object($group_id);
2264 return $grp->getData();
2271 * getUnixStatus - Status of activation of unix account.
2273 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2275 function getUnixStatus() {
2276 return $this->data_array['unix_status'];
2280 * setUnixStatus - Sets status of activation of unix account.
2282 * @param string The unix status.
2288 * @return boolean success.
2290 function setUnixStatus($status) {
2291 global $Language,$SYS;
2295 SET unix_status='$status'
2296 WHERE group_id='". $this->getID()."'
2300 $this->setError('ERROR - Could Not Update Group Unix Status: '.db_error());
2304 if ($status == 'A') {
2305 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2306 $this->setError($SYS->getErrorMessage());
2311 if ($SYS->sysCheckGroup($this->getID())) {
2312 if (!$SYS->sysRemoveGroup($this->getID())) {
2313 $this->setError($SYS->getErrorMessage());
2320 $this->data_array['unix_status']=$status;
2328 // c-file-style: "bsd"