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') {
287 // $user is ignored - anyone can create pending group
289 if ($this->getID()!=0) {
290 $this->setError("Group::create: Group object already exists");
292 } else if (strlen($full_name)<3) {
293 $this->setError(_('Invalid full name'));
295 } else if (!account_groupnamevalid($unix_name)) {
296 $this->setError(_('Invalid unix name'));
298 } else if (db_numrows(db_query("SELECT group_id FROM groups WHERE unix_group_name='$unix_name'")) > 0) {
299 $this->setError(_('Unix name already taken'));
301 } else if (strlen($purpose)<10) {
302 $this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
304 } else if (strlen($purpose)>1500) {
305 $this->setError(_('The Registration Purpose text is too long. Please make it smaller than 1500 bytes.'));
307 } else if (strlen($description)<10) {
308 $this->setError(_('Describe in a more comprehensive manner your project.'));
310 } else if (strlen($description)>255) {
311 $this->setError(_('Your project description is too long. Please make it smaller than 256 bytes.'));
313 } else if (!$license) {
314 $this->setError(_('You do not have chosen a license'));
316 } else if ($license!=GROUP_LICENSE_OTHER && $license_other) {
317 $this->setError(_('Conflicting licenses choice'));
319 } else if ($license==GROUP_LICENSE_OTHER && strlen($license_other)<50) {
320 $this->setError(_('Please give more comprehensive licensing description'));
324 srand((double)microtime()*1000000);
325 $random_num = rand(0,1000000);
347 '".htmlspecialchars($full_name)."',
350 '".htmlspecialchars($description)."',
351 '$unix_name.".$GLOBALS['sys_default_domain']."',
352 '$unix_name.".$GLOBALS['sys_default_domain']."',
357 '".htmlspecialchars($purpose)."',
359 '".htmlspecialchars($license_other)."',
360 '".md5($random_num)."'
364 if (!$res || db_affected_rows($res) < 1) {
365 $this->setError('ERROR: Could not create group: '.db_error());
370 $id = db_insertid($res, 'groups', 'group_id');
372 $this->setError('ERROR: Could not get group id: '.db_error());
378 // Now, make the user an admin
380 $sql="INSERT INTO user_group ( user_id, group_id, admin_flags,
381 cvs_flags, artifact_flags, forum_flags, role_id)
382 VALUES ( ".$user->getID().", '$id', 'A', 1, 2, 2, 1)";
385 if (!$res || db_affected_rows($res) < 1) {
386 $this->setError('ERROR: Could not add admin to newly created group: '.db_error());
391 if (!$this->fetchData($id)) {
396 $this->sendNewProjectNotificationEmail();
403 * updateAdmin - Update core properties of group object.
405 * This function require site admin privilege.
407 * @param object User requesting operation (for access control).
408 * @param bool Whether group is publicly accessible (0/1).
409 * @param string Project's license (string ident).
410 * @param int Group type (1-project, 2-foundry).
411 * @param string Machine on which group's home directory located.
412 * @param string Domain which serves group's WWW.
416 function updateAdmin(&$user, $is_public, $license, $type_id, $unix_box, $http_domain) {
417 $perm =& $this->getPermission($user);
419 if (!$perm || !is_object($perm)) {
420 $this->setError(_('Could not get permission.'));
424 if (!$perm->isSuperUser()) {
425 $this->setError(_('Permission denied.'));
433 SET is_public='$is_public',
434 license='$license',type_id='$type_id',
435 unix_box='$unix_box',http_domain='$http_domain'
436 WHERE group_id='".$this->getID()."'
439 if (!$res || db_affected_rows($res) < 1) {
440 $this->setError('ERROR: DB: Could not change group properties: '.db_error());
445 // Log the audit trail
446 if ($is_public != $this->isPublic()) {
447 $this->addHistory('is_public', $this->isPublic());
449 if ($license != $this->data_array['license']) {
450 $this->addHistory('license', $this->data_array['license']);
452 if ($type_id != $this->data_array['type_id']) {
453 $this->addHistory('type_id', $this->data_array['type_id']);
455 if ($unix_box != $this->data_array['unix_box']) {
456 $this->addHistory('unix_box', $this->data_array['unix_box']);
458 if ($http_domain != $this->data_array['http_domain']) {
459 $this->addHistory('http_domain', $this->data_array['http_domain']);
462 if (!$this->fetchData($this->getID())) {
471 * update - Update number of common properties.
473 * Unlike updateAdmin(), this function accessible to project admin.
475 * @param object User requesting operation (for access control).
476 * @param bool Whether group is publicly accessible (0/1).
477 * @param string Project's license (string ident).
478 * @param int Group type (1-project, 2-foundry).
479 * @param string Machine on which group's home directory located.
480 * @param string Domain which serves group's WWW.
481 * @return int status.
484 function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,
485 $use_pm,$use_pm_depend_box,$use_scm,$use_news,$use_docman,
486 $new_doc_address,$send_all_docs,$logo_image_id,
487 $enable_pserver,$enable_anonscm,
488 $use_ftp,$use_tracker,$use_frs,$use_stats) {
490 $perm =& $this->getPermission($user);
492 if (!$perm || !is_object($perm)) {
493 $this->setError(_('Could not get permission.'));
497 if (!$perm->isAdmin()) {
498 $this->setError(_('Permission denied.'));
502 // Validate some values
504 $this->setError('Invalid Group Name');
508 if ($new_doc_address) {
509 $invalid_mails = validate_emails($new_doc_address);
510 if (count($invalid_mails) > 0) {
511 $this->setError('New Doc Address(es) Appeared Invalid: '.implode(',',$invalid_mails));
516 // in the database, these all default to '1',
517 // so we have to explicity set 0
530 if (!$use_pm_depend_box) {
531 $use_pm_depend_box=0;
554 if (!$send_all_docs) {
559 $homepage=$GLOBALS['sys_default_domain'].'/projects/'.$this->getUnixName().'/';
562 if (strlen($short_description)>255) {
563 $this->setError('Error updating project information: Maximum length for Project Description is 255 chars.');
569 //XXX not yet actived logo_image_id='$logo_image_id',
573 group_name='".htmlspecialchars($group_name)."',
574 homepage='$homepage',
575 short_description='".htmlspecialchars($short_description)."',
576 use_mail='$use_mail',
577 use_survey='$use_survey',
578 use_forum='$use_forum',
580 use_pm_depend_box='$use_pm_depend_box',
582 use_news='$use_news',
583 use_docman='$use_docman',
584 new_doc_address='$new_doc_address',
585 send_all_docs='$send_all_docs',
587 if ($enable_pserver != '') {
589 enable_pserver='$enable_pserver',
592 if ($enable_anonscm != '') {
594 enable_anonscm='$enable_anonscm',
599 use_tracker='$use_tracker',
601 use_stats='$use_stats'
602 WHERE group_id='".$this->getID()."'
604 $res = db_query($sql);
607 $this->setError('Error updating project information: '.db_error());
612 // Log the audit trail
613 $this->addHistory('Changed Public Info', '');
615 if (!$this->fetchData($this->getID())) {
624 * getID - Simply return the group_id for this object.
626 * @return int group_id.
629 return $this->data_array['group_id'];
633 * getType() - Foundry, project, etc.
635 * @return int The type flag from the database.
638 return $this->data_array['type_id'];
643 * getStatus - the status code.
645 * Statuses char include I,H,A,D.
647 function getStatus() {
648 return $this->data_array['status'];
652 * setStatus - set the status code.
654 * Statuses include I,H,A,D.
656 * @param object User requesting operation (for access control).
657 * @param string Status value.
658 * @return boolean success.
661 function setStatus(&$user, $status) {
664 $perm =& $this->getPermission($user);
665 if (!$perm || !is_object($perm)) {
666 $this->setPermissionDeniedError();
668 } elseif (!$perm->isSuperUser()) {
669 $this->setPermissionDeniedError();
673 // Projects in 'A' status can only go to 'H' or 'D'
674 // Projects in 'D' status can only go to 'A'
675 // Projects in 'P' status can only go to 'A' OR 'D'
676 // Projects in 'I' status can only go to 'P'
677 // Projects in 'H' status can only go to 'A' OR 'D'
678 $allowed_status_changes = array(
679 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
680 'IP'=>1,'HA'=>1,'HD'=>1
683 // Check that status transition is valid
684 if ($this->getStatus() != $status
685 && !$allowed_status_changes[$this->getStatus().$status]) {
686 $this->setError('Invalid Status Change');
692 $res = db_query("UPDATE groups
694 WHERE group_id='". $this->getID()."'");
696 if (!$res || db_affected_rows($res) < 1) {
697 $this->setError('ERROR: DB: Could not change group status: '.db_error());
703 // Activate system group, if not yet
704 if (!$SYS->sysCheckGroup($this->getID())) {
705 if (!$SYS->sysCreateGroup($this->getID())) {
706 $this->setError($SYS->getErrorMessage());
711 if (!$this->activateUsers()) {
716 /* Otherwise, the group is not active, and make sure that
717 System group is not active either */
718 } else if ($SYS->sysCheckGroup($this->getID())) {
719 if (!$SYS->sysRemoveGroup($this->getID())) {
720 $this->setError($SYS->getErrorMessage());
728 // Log the audit trail
729 if ($status != $this->getStatus()) {
730 $this->addHistory('status', $this->getStatus());
733 $this->data_array['status'] = $status;
738 * isProject - Simple boolean test to see if it's a project or not.
740 * @return boolean is_project.
742 function isProject() {
743 if ($this->getType()==1) {
751 * isPublic - Simply returns the is_public flag from the database.
753 * @return boolean is_public.
755 function isPublic() {
756 return $this->data_array['is_public'];
760 * isActive - Database field status of 'A' returns true.
762 * @return boolean is_active.
764 function isActive() {
765 if ($this->getStatus()=='A') {
773 * getUnixName - the unix_name
775 * @return string unix_name.
777 function getUnixName() {
778 return strtolower($this->data_array['unix_group_name']);
782 * getPublicName - the full-length public name.
784 * @return string The group_name.
786 function getPublicName() {
787 return $this->data_array['group_name'];
791 * getRegisterPurpose - the text description of the purpose of this project.
793 * @return string The description.
795 function getRegisterPurpose() {
796 return $this->data_array['register_purpose'];
800 * getDescription - the text description of this project.
802 * @return string The description.
804 function getDescription() {
805 return $this->data_array['short_description'];
809 * getStartDate - the unix time this project was registered.
811 * @return int (unix time) of registration.
813 function getStartDate() {
814 return $this->data_array['register_time'];
818 * getLogoImageID - the id of the logo in the database for this project.
820 * @return int The ID of logo image in db_images table (or 100 if none).
822 function getLogoImageID() {
823 return $this->data_array['logo_image_id'];
827 * getUnixBox - the hostname of the unix box where this project is located.
829 * @return string The name of the unix machine for the group.
831 function getUnixBox() {
832 return $this->data_array['unix_box'];
836 * getSCMBox - the hostname of the scm box where this project is located.
838 * @return string The name of the unix machine for the group.
840 function getSCMBox() {
841 return $this->data_array['scm_box'];
844 * setSCMBox - the hostname of the scm box where this project is located.
846 * @param string The name of the new SCM_BOX
848 function setSCMBox($scm_box) {
851 $sql = "UPDATE groups SET scm_box = '$scm_box' WHERE group_id = ".$this->getID();
852 $res = db_query($sql);
854 $this->addHistory('scm_box', $this->data_array['scm_box']);
855 $this->data_array['scm_box']=$scm_box;
860 $this->setError('Couldn\'t insert SCM_BOX to database');
864 $this->setError(_('SCM Box can\'t be empty'));
870 * getDomain - the hostname.domain where their web page is located.
872 * @return string The name of the group [web] domain.
874 function getDomain() {
875 return $this->data_array['http_domain'];
879 * getLicense - the license they chose.
881 * @return int ident of group license.
883 function getLicense() {
884 return $this->data_array['license'];
888 * getLicenseName - the name of the license
890 * @return string license name
892 function getLicenseName() {
893 $licenses =& group_get_licenses();
894 if(isset($licenses[$this->data_array['license']])) {
895 return $licenses[$this->data_array['license']];
902 * getLicenseOther - optional string describing license.
904 * @return string The custom license.
906 function getLicenseOther() {
907 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
908 return $this->data_array['license_other'];
915 * getRegistrationPurpose - the text description of the purpose of this project.
917 * @return string The application for project hosting.
919 function getRegistrationPurpose() {
920 return $this->data_array['register_purpose'];
925 * getAdmins() - Get array of Admin user objects.
927 * @return array Array of User objects.
929 function &getAdmins() {
930 // this function gets all group admins in order to send Jabber and mail messages
931 $q = "SELECT user_id FROM user_group WHERE admin_flags = 'A' AND group_id = ".$this->getID();
933 $user_ids=util_result_column_to_array($res);
934 return user_get_objects($user_ids);
939 Common Group preferences for tools
944 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
946 * @return boolean enable_scm.
948 function enableAnonSCM() {
949 if ($this->isPublic() && $this->usesSCM()) {
950 return $this->data_array['enable_anonscm'];
956 function SetUsesAnonSCM ($booleanparam) {
958 $booleanparam = $booleanparam ? 1 : 0 ;
959 $sql = "UPDATE groups SET enable_anonscm = $booleanparam WHERE group_id = ".$this->getID() ;
960 $res = db_query($sql);
962 $this->data_array['enable_anonscm']=$booleanparam;
971 * enablePserver - whether or not this group has opted to enable Pserver.
973 * @return boolean enable_pserver.
975 function enablePserver() {
976 if ($this->usesSCM()) {
977 return $this->data_array['enable_pserver'];
983 function SetUsesPserver ($booleanparam) {
985 $booleanparam = $booleanparam ? 1 : 0 ;
986 $sql = "UPDATE groups SET enable_pserver = $booleanparam WHERE group_id = ".$this->getID() ;
987 $res = db_query($sql);
989 $this->data_array['enable_pserver']=$booleanparam;
998 * usesSCM - whether or not this group has opted to use SCM.
1000 * @return boolean uses_scm.
1002 function usesSCM() {
1003 global $sys_use_scm;
1005 return $this->data_array['use_scm'];
1012 * usesMail - whether or not this group has opted to use mailing lists.
1014 * @return boolean uses_mail.
1016 function usesMail() {
1017 global $sys_use_mail;
1018 if ($sys_use_mail) {
1019 return $this->data_array['use_mail'];
1026 * usesNews - whether or not this group has opted to use news.
1028 * @return boolean uses_news.
1030 function usesNews() {
1031 global $sys_use_news;
1032 if ($sys_use_news) {
1033 return $this->data_array['use_news'];
1040 * usesForum - whether or not this group has opted to use discussion forums.
1042 * @return boolean uses_forum.
1044 function usesForum() {
1045 global $sys_use_forum;
1046 if ($sys_use_forum) {
1047 return $this->data_array['use_forum'];
1054 * usesStats - whether or not this group has opted to use stats.
1056 * @return boolean uses_stats.
1058 function usesStats() {
1059 return $this->data_array['use_stats'];
1063 * usesFRS - whether or not this group has opted to use file release system.
1065 * @return boolean uses_frs.
1067 function usesFRS() {
1068 global $sys_use_frs;
1070 return $this->data_array['use_frs'];
1077 * usesTracker - whether or not this group has opted to use tracker.
1079 * @return boolean uses_tracker.
1081 function usesTracker() {
1082 global $sys_use_tracker;
1083 if ($sys_use_tracker) {
1084 return $this->data_array['use_tracker'];
1091 * usesDocman - whether or not this group has opted to use docman.
1093 * @return boolean uses_docman.
1095 function usesDocman() {
1096 global $sys_use_docman;
1097 if ($sys_use_docman) {
1098 return $this->data_array['use_docman'];
1105 * usesFTP - whether or not this group has opted to use FTP.
1107 * @return boolean uses_ftp.
1109 function usesFTP() {
1110 global $sys_use_ftp;
1112 return $this->data_array['use_ftp'];
1119 * usesSurvey - whether or not this group has opted to use surveys.
1121 * @return boolean uses_survey.
1123 function usesSurvey() {
1124 global $sys_use_survey;
1125 if ($sys_use_survey) {
1126 return $this->data_array['use_survey'];
1133 * usesPM - whether or not this group has opted to Project Manager.
1135 * @return boolean uses_projman.
1140 return $this->data_array['use_pm'];
1147 * getPlugins - get a list of all available group plugins
1149 * @return array array containing plugin_id => plugin_name
1151 function getPlugins() {
1152 if (!isset($this->plugins_data)) {
1153 $this->plugins_data = array () ;
1154 $sql="SELECT group_plugin.plugin_id, plugins.plugin_name
1155 FROM group_plugin, plugins
1156 WHERE group_plugin.group_id=".$this->getID()."
1157 AND group_plugin.plugin_id = plugins.plugin_id" ;
1158 $res=db_query($sql);
1159 $rows = db_numrows($res);
1161 for ($i=0; $i<$rows; $i++) {
1162 $plugin_id = db_result($res,$i,'plugin_id');
1163 $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
1166 return $this->plugins_data ;
1170 * usesPlugin - returns true if the group uses a particular plugin
1172 * @param string name of the plugin
1173 * @return boolean whether plugin is being used or not
1175 function usesPlugin($pluginname) {
1176 $plugins_data = $this->getPlugins() ;
1177 foreach ($plugins_data as $p_id => $p_name) {
1178 if ($p_name == $pluginname) {
1186 * setPluginUse - enables/disables plugins for the group
1188 * @param string name of the plugin
1189 * @param boolean the new state
1190 * @return string database result
1192 function setPluginUse($pluginname, $val=true) {
1193 if ($val == $this->usesPlugin($pluginname)) {
1194 // State is already good, returning
1197 $sql="SELECT plugin_id
1199 WHERE plugin_name = '" . $pluginname . "'" ;
1200 $res=db_query($sql);
1201 $rows = db_numrows($res);
1203 // Error: no plugin by that name
1206 $plugin_id = db_result($res,0,'plugin_id');
1208 unset ($this->plugins_data) ;
1210 $sql="INSERT INTO group_plugin (group_id, plugin_id)
1211 VALUES (". $this->getID() . ", ". $plugin_id .")" ;
1212 $res=db_query($sql);
1215 $sql="DELETE FROM group_plugin
1216 WHERE group_id = ". $this->getID() . "
1217 AND plugin_id = ". $plugin_id ;
1218 $res=db_query($sql);
1224 * getDocEmailAddress - get email address(es) to send doc notifications to.
1226 * @return string email address.
1228 function getDocEmailAddress() {
1229 return $this->data_array['new_doc_address'];
1233 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1235 * @return boolean email_on_all_doc_updates.
1237 function docEmailAll() {
1238 return $this->data_array['send_all_docs'];
1243 * getHomePage - The URL for this project's home page.
1245 * @return string homepage URL.
1247 function getHomePage() {
1248 return $this->data_array['homepage'];
1252 * getPermission - Return a Permission for this Group and the specified User.
1254 * @param object The user you wish to get permission for (usually the logged in user).
1255 * @return object The Permission.
1257 function &getPermission(&$_user) {
1258 return permission_get_object($this, $_user);
1263 * userIsAdmin - Return if for this Group the User is admin.
1265 * @return boolean is_admin.
1267 function userIsAdmin() {
1268 $perm =& $this->getPermission( session_get_user() );
1269 if (!$perm || !is_object($perm)) {
1271 } elseif ($perm->isError()) {
1274 return $perm->isAdmin();
1277 function delete($sure,$really_sure,$really_really_sure) {
1278 if (!$sure || !$really_sure || !$really_really_sure) {
1279 $this->setMissingParamsError();
1282 if ($this->getID() == $GLOBALS['sys_news_group'] ||
1283 $this->getID() == 1 ||
1284 $this->getID() == $GLOBALS['sys_stats_group'] ||
1285 $this->getID() == $GLOBALS['sys_peer_rating_group']) {
1286 $this->setError('Cannot Delete System Group');
1289 $perm =& $this->getPermission( session_get_user() );
1290 if (!$perm || !is_object($perm)) {
1291 $this->setPermissionDeniedError();
1293 } elseif ($perm->isError()) {
1294 $this->setPermissionDeniedError();
1296 } elseif (!$perm->isSuperUser()) {
1297 $this->setPermissionDeniedError();
1303 // Remove all the members
1305 $members =& $this->getMembers();
1306 for ($i=0; $i<count($members); $i++) {
1307 $this->removeUser($members[$i]->getID());
1308 //echo 'RemoveMembers'.db_error();
1313 $atf = new ArtifactTypeFactory($this);
1314 $at_arr =& $atf->getArtifactTypes();
1315 for ($i=0; $i<count($at_arr); $i++) {
1316 if (!is_object($at_arr[$i])) {
1317 echo "Not Object: ArtifactType: ".$i;
1320 $at_arr[$i]->delete(1,1);
1321 //echo 'ArtifactTypeFactory'.db_error();
1326 $ff = new ForumFactory($this);
1327 $f_arr =& $ff->getForums();
1328 for ($i=0; $i<count($f_arr); $i++) {
1329 if (!is_object($f_arr[$i])) {
1330 echo "Not Object: Forum: ".$i;
1333 $f_arr[$i]->delete(1,1);
1334 //echo 'ForumFactory'.db_error();
1337 // Delete Subprojects
1339 $pgf = new ProjectGroupFactory($this);
1340 $pg_arr =& $pgf->getProjectGroups();
1341 for ($i=0; $i<count($pg_arr); $i++) {
1342 if (!is_object($pg_arr[$i])) {
1343 echo "Not Object: ProjectGroup: ".$i;
1346 $pg_arr[$i]->delete(1,1);
1347 //echo 'ProjectGroupFactory'.db_error();
1350 // Delete FRS Packages
1352 //$frspf = new FRSPackageFactory($this);
1353 $res=db_query("SELECT * FROM frs_package WHERE group_id='".$this->getID()."'");
1354 //echo 'frs_package'.db_error();
1355 //$frsp_arr =& $frspf->getPackages();
1356 while ($arr = db_fetch_array($res)) {
1357 //if (!is_object($pg_arr[$i])) {
1358 // echo "Not Object: ProjectGroup: ".$i;
1361 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1367 $news_group=&group_get_object($GLOBALS['sys_news_group']);
1368 $res=db_query("SELECT forum_id FROM news_bytes WHERE group_id='".$this->getID()."'");
1369 for ($i=0; $i<db_numrows($res); $i++) {
1370 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1371 if (!$Forum->delete(1,1)) {
1372 echo "Could Not Delete News Forum: ".$Forum->getID();
1375 $res=db_query("DELETE FROM news_bytes WHERE group_id='".$this->getID()."'");
1380 $res=db_query("DELETE FROM doc_data WHERE group_id='".$this->getID()."'");
1381 //echo 'doc_data'.db_error();
1382 $res=db_query("DELETE FROM doc_groups WHERE group_id='".$this->getID()."'");
1383 //echo 'doc_groups'.db_error();
1385 // Delete group history
1387 $res=db_query("DELETE FROM group_history WHERE group_id='".$this->getID()."'");
1388 //echo 'group_history'.db_error();
1390 // Delete group plugins
1392 $res=db_query("DELETE FROM group_plugin WHERE group_id='".$this->getID()."'");
1393 //echo 'group_plugin'.db_error();
1395 // Delete group cvs stats
1397 $res=db_query("DELETE FROM stats_cvs_group WHERE group_id='".$this->getID()."'");
1398 //echo 'stats_cvs_group'.db_error();
1402 $sf = new SurveyFactory($this);
1403 $s_arr =& $sf->getSurveys();
1404 for ($i=0; $i<count($s_arr); $i++) {
1405 if (!is_object($s_arr[$i])) {
1406 echo "Not Object: Survey: ".$i;
1409 $s_arr[$i]->delete();
1410 //echo 'SurveyFactory'.db_error();
1413 // Delete SurveyQuestions
1415 $sqf = new SurveyQuestionFactory($this);
1416 $sq_arr =& $sqf->getSurveyQuestions();
1417 for ($i=0; $i<count($sq_arr); $i++) {
1418 if (!is_object($sq_arr[$i])) {
1419 echo "Not Object: SurveyQuestion: ".$i;
1422 $sq_arr[$i]->delete();
1423 //echo 'SurveyQuestionFactory'.db_error();
1426 // Delete Mailing List Factory
1428 $mlf = new MailingListFactory($this);
1429 $ml_arr =& $mlf->getMailingLists();
1430 for ($i=0; $i<count($ml_arr); $i++) {
1431 if (!is_object($ml_arr[$i])) {
1432 echo "Not Object: MailingList: ".$i;
1435 if (!$ml_arr[$i]->delete(1,1)) {
1436 $this->setError(_('Could not delete properly the mailing list'));
1438 //echo 'MailingListFactory'.db_error();
1443 $res=db_query("DELETE FROM trove_group_link WHERE group_id='".$this->getID()."'");
1444 $res=db_query("DELETE FROM trove_agg WHERE group_id='".$this->getID()."'");
1448 $res=db_query("DELETE FROM project_sums_agg WHERE group_id='".$this->getID()."'");
1449 //echo 'project_sums_agg'.db_error();
1450 $res=db_query("INSERT INTO deleted_groups (
1451 unix_group_name,delete_date,isdeleted) VALUES
1452 ('".$this->getUnixName()."','".time()."','0')");
1453 //echo 'InsertIntoDeleteQueue'.db_error();
1454 $res=db_query("DELETE FROM groups WHERE group_id='".$this->getID()."'");
1455 //echo 'DeleteGroup'.db_error();
1460 if (isset($GLOBALS['sys_upload_dir']) && $this->getUnixName()) {
1461 exec('/bin/rm -rf '.$GLOBALS['sys_upload_dir'].'/'.$this->getUnixName().'/');
1463 if (isset($GLOBALS['sys_ftp_upload_dir']) && $this->getUnixName()) {
1464 exec('/bin/rm -rf '.$GLOBALS['sys_ftp_upload_dir'].'/'.$this->getUnixName().'/');
1469 $res=db_query("DELETE FROM rep_group_act_weekly WHERE group_id='".$this->getID()."'");
1470 //echo 'rep_group_act_weekly'.db_error();
1471 $res=db_query("DELETE FROM rep_group_act_monthly WHERE group_id='".$this->getID()."'");
1472 //echo 'rep_group_act_monthly'.db_error();
1473 $res=db_query("DELETE FROM rep_group_act_daily WHERE group_id='".$this->getID()."'");
1474 //echo 'rep_group_act_daily'.db_error();
1475 unset($this->data_array);
1483 Basic functions to add/remove users to/from a group
1484 and update their permissions
1490 * addUser - controls adding a user to a group.
1492 * @param string Unix name of the user to add OR integer user_id.
1493 * @param int The role_id this user should have.
1494 * @return boolean success.
1497 function addUser($user_unix_name,$role_id) {
1500 Admins can add users to groups
1503 $perm =& $this->getPermission( session_get_user() );
1504 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1505 $this->setPermissionDeniedError();
1511 get user id for this user's unix_name
1513 if (eregi('[^0-9]',$user_unix_name)) {
1514 $res_newuser = db_query("SELECT * FROM users WHERE user_name='". strtolower($user_unix_name) ."'");
1516 $res_newuser = db_query("SELECT * FROM users WHERE user_id='". intval($user_unix_name) ."'");
1518 if (db_numrows($res_newuser) > 0) {
1520 // make sure user is active
1522 if (db_result($res_newuser,0,'status') != 'A') {
1523 $this->setError('User is not active. Only active users can be added.');
1529 // user was found - set new user_id var
1531 $user_id = db_result($res_newuser,0,'user_id');
1534 // if not already a member, add them
1536 $res_member = db_query("SELECT user_id
1538 WHERE user_id='$user_id' AND group_id='". $this->getID() ."'");
1540 if (db_numrows($res_member) < 1) {
1542 // Create this user's row in the user_group table
1544 $res=db_query("INSERT INTO user_group
1545 (user_id,group_id,admin_flags,forum_flags,project_flags,
1546 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
1547 VALUES ('$user_id','". $this->getID() ."','','0','0','0','1','100','0','0')");
1549 //verify the insert worked
1550 if (!$res || db_affected_rows($res) < 1) {
1551 $this->setError('ERROR: Could Not Add User To Group: '.db_error());
1556 // check and create if group doesn't exists
1558 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
1559 if (!$SYS->sysCheckCreateGroup($this->getID())){
1560 $this->setError($SYS->getErrorMessage());
1565 // check and create if user doesn't exists
1567 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1568 if (!$SYS->sysCheckCreateUser($user_id)) {
1569 $this->setError($SYS->getErrorMessage());
1576 $role = new Role($this,$role_id);
1577 if (!$role || !is_object($role)) {
1578 $this->setError('Error Getting Role Object');
1581 } elseif ($role->isError()) {
1582 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1586 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
1587 if (!$role->setUser($user_id)) {
1588 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1594 // user was already a member
1595 // make sure they are set up
1597 $user=&user_get_object($user_id,$res_newuser);
1598 $user->fetchData($user->getID());
1599 $role = new Role($this,$role_id);
1600 if (!$role || !is_object($role)) {
1601 $this->setError('Error Getting Role Object');
1604 } elseif ($role->isError()) {
1605 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1609 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
1610 if (!$role->setUser($user_id)) {
1611 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1616 // set up their system info
1618 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1619 if (!$SYS->sysCheckCreateUser($user_id)) {
1620 $this->setError($SYS->getErrorMessage());
1629 // user doesn't exist
1631 $this->setError('ERROR: User does not exist');
1638 $this->addHistory('Added User',$user_unix_name);
1644 * removeUser - controls removing a user from a group.
1646 * Users can remove themselves.
1648 * @param int The ID of the user to remove.
1649 * @return boolean success.
1651 function removeUser($user_id) {
1652 global $SYS,$sys_database_type;
1654 if ($user_id==user_getid()) {
1655 //users can remove themselves
1656 //everyone else must be a project admin
1658 $perm =& $this->getPermission( session_get_user() );
1660 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1661 $this->setPermissionDeniedError();
1667 $res=db_query("DELETE FROM user_group
1668 WHERE group_id='".$this->getID()."'
1669 AND user_id='$user_id'");
1670 if (!$res || db_affected_rows($res) < 1) {
1671 $this->setError('ERROR: DB: User not removed.'.db_error());
1676 // reassign open artifacts to id=100
1678 $res=db_query("UPDATE artifact SET assigned_to='100'
1679 WHERE group_artifact_id
1680 IN (SELECT group_artifact_id
1681 FROM artifact_group_list
1682 WHERE group_id='".$this->getID()."')
1683 AND status_id='1' AND assigned_to='$user_id'");
1685 $this->setError('ERROR: DB: artifact.'.db_error());
1691 // reassign open tasks to id=100
1692 // first have to purge any assignments that would cause
1693 // conflict with existing assignment to 100
1695 if ($sys_database_type == 'mysql') {
1697 SELECT pt.project_task_id
1698 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1699 WHERE pt.group_project_id = pgl.group_project_id
1700 AND pat.project_task_id=pt.project_task_id
1701 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."'
1702 AND pat.assigned_to_id='$user_id' INTO @task_list;
1703 DELETE FROM project_assigned_to WHERE project_task_id IN ( @task_list ) AND assigned_to_id='100'");
1705 $res = db_next_result();
1708 $res=db_query("DELETE FROM project_assigned_to
1709 WHERE project_task_id IN (SELECT pt.project_task_id
1710 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1711 WHERE pt.group_project_id = pgl.group_project_id
1712 AND pat.project_task_id=pt.project_task_id
1713 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."'
1714 AND pat.assigned_to_id='$user_id')
1715 AND assigned_to_id='100'");
1718 $this->setError('ERROR: DB: project_assigned_to 1 - '.db_error());
1722 $res=db_query("UPDATE project_assigned_to SET assigned_to_id='100'
1723 WHERE project_task_id IN (SELECT pt.project_task_id
1724 FROM project_task pt, project_group_list pgl
1725 WHERE pt.group_project_id = pgl.group_project_id
1726 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."')
1727 AND assigned_to_id='$user_id'");
1729 $this->setError('ERROR: DB: project_assigned_to 2 - '.db_error());
1735 // Remove user from system
1737 //echo "<h2>Group::addUser SYS->sysGroupRemoveUser(".$this->getID().",$user_id)</h2>";
1738 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
1739 $this->setError($SYS->getErrorMessage());
1744 $this->addHistory('removed user',$user_id);
1751 * updateUser - controls updating a user's role in this group.
1753 * @param int The ID of the user.
1754 * @param int The role_id to set this user to.
1755 * @return boolean success.
1757 function updateUser($user_id,$role_id) {
1760 $perm =& $this->getPermission( session_get_user() );
1761 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1762 $this->setPermissionDeniedError();
1766 $role = new Role($this,$role_id);
1767 if (!$role || !is_object($role)) {
1768 $this->setError('Could Not Get Role');
1770 } elseif ($role->isError()) {
1771 $this->setError('Role: '.$role->getErrorMessage());
1774 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
1775 if (!$role->setUser($user_id)) {
1776 $this->setError('Role: '.$role->getErrorMessage());
1779 $this->addHistory('updated user',$user_id);
1784 * addHistory - Makes an audit trail entry for this project.
1786 * @param string The name of the field.
1787 * @param string The Old Value for this $field_name.
1788 * @return database result handle.
1791 function addHistory($field_name, $old_value) {
1793 INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
1794 VALUES ('". $this->getID() ."','$field_name','$old_value','". user_getid() ."','".time()."')
1796 return db_query($sql);
1800 * activateUsers - Make sure that group members have unix accounts.
1802 * Setup unix accounts for group members. Can be called even
1803 * if members are already active.
1807 function activateUsers() {
1810 Activate member(s) of the project
1813 $member_res = db_query("SELECT user_id, role_id
1815 WHERE group_id='".$this->getID()."'");
1817 $rows = db_numrows($member_res);
1821 for ($i=0; $i<$rows; $i++) {
1823 $member =& user_get_object(db_result($member_res,$i,'user_id'));
1824 $roleId = db_result($member_res,$i,'role_id');
1826 if (!$member || !is_object($member)) {
1827 $this->setError('Error getting member object');
1829 } else if ($member->isError()) {
1830 $this->setError('Error getting member object: '.$member->getErrorMessage());
1834 if (!$this->addUser($member->getUnixName(),$roleId)) {
1845 * getMembers - returns array of User objects for this project
1847 * @return array of User objects for this group.
1849 function &getMembers() {
1850 if (!isset($this->membersArr)) {
1851 $res=db_query("SELECT users.* FROM users
1852 INNER JOIN user_group ON users.user_id=user_group.user_id
1853 WHERE user_group.group_id='".$this->getID()."'");
1854 while ($arr =& db_fetch_array($res)) {
1855 $this->membersArr[] =& new User($arr['user_id'],$arr);
1858 return $this->membersArr;
1862 * approve - Approve pending project.
1864 * @param object The User object who is doing the updating.
1867 function approve(&$user) {
1869 if ($this->getStatus()=='A') {
1870 $this->setError("Group already active");
1876 // Step 1: Activate group and create LDAP entries
1877 if (!$this->setStatus($user, 'A')) {
1884 // Tracker Integration
1887 $ats = new ArtifactTypes($this);
1888 if (!$ats || !is_object($ats)) {
1889 $this->setError('Error creating ArtifactTypes object');
1892 } else if ($ats->isError()) {
1893 $this->setError('ATS1 '.$ats->getErrorMessage());
1897 if (!$ats->createTrackers()) {
1898 $this->setError('ATS2 '.$ats->getErrorMessage());
1905 // Forum Integration
1908 $f = new Forum($this);
1909 if (!$f->create('Open-Discussion','General Discussion',1,'',1,0)) {
1910 $this->setError('F1 '.$f->getErrorMessage());
1914 $f = new Forum($this);
1915 if (!$f->create('Help','Get Public Help',1,'',1,0)) {
1916 $this->setError('F2 '.$f->getErrorMessage());
1920 $f = new Forum($this);
1921 if (!$f->create('Developers','Project Developer Discussion',0,'',1,0)) {
1922 $this->setError('F3 '.$f->getErrorMessage());
1929 // Doc Mgr Integration
1932 $dg = new DocumentGroup($this);
1933 if (!$dg->create('Uncategorized Submissions')) {
1934 $this->setError('DG1 '.$dg->getErrorMessage());
1944 $frs = new FRSPackage($this);
1945 if (!$frs->create($this->getUnixName())) {
1946 $this->setError('FRSP '.$frs->getErrorMessage());
1956 $pg = new ProjectGroup($this);
1957 if (!$pg->create('To Do','Things We Have To Do',1)) {
1958 $this->setError('PG1 '.$pg->getErrorMessage());
1962 $pg = new ProjectGroup($this);
1963 if (!$pg->create('Next Release','Items For Our Next Release',1)) {
1964 $this->setError('PG2 '.$pg->getErrorMessage());
1971 // Set Default Roles
1974 $role = new Role($this);
1975 $todo = array_keys($role->defaults);
1976 for ($c=0; $c<count($todo); $c++) {
1977 $role = new Role($this);
1978 if (!$role->createDefault($todo[$c])) {
1979 $this->setError('R'.$c.' '.$role->getErrorMessage());
1987 // Create MailingList
1990 $mlist = new MailingList($this);
1991 $admin_group = db_query("SELECT user_id FROM user_group
1992 WHERE group_id=".$this->getID()." AND admin_flags='A'");
1993 if (db_numrows($admin_group) > 0) {
1994 $idadmin_group = db_result($admin_group,0,'user_id');
1996 if (!$mlist->create('commits','cvs commits',1,$idadmin_group)) {
1997 $this->setError('MailingList: '.$mlist->getErrorMessage());
2004 $this->sendApprovalEmail();
2005 $this->addHistory('approved', 'x');
2008 //change assistant for webcal
2010 $params[0] = $idadmin_group ;
2011 $params[1] = $this->getID();
2012 plugin_hook('change_cal_permission_default',$params);
2020 * sendApprovalEmail - Send new project email.
2022 * @return boolean success.
2025 function sendApprovalEmail() {
2026 $res_admins = db_query("
2027 SELECT users.user_name,users.email,users.language,users.user_id
2028 FROM users,user_group
2029 WHERE users.user_id=user_group.user_id
2030 AND user_group.group_id='".$this->getID()."'
2031 AND user_group.admin_flags='A'
2034 if (db_numrows($res_admins) < 1) {
2035 $this->setError("Group does not have any administrators.");
2039 // send one email per admin
2040 while ($row_admins = db_fetch_array($res_admins)) {
2041 $admin =& user_get_object($row_admins['user_id']);
2042 setup_gettext_for_user ($admin) ;
2044 // $2 $2 $3 $4 $5 $6
2045 $message=stripcslashes(sprintf(_('Your project registration for %7$s has been approved.
2047 Project Full Name: %1$s
2048 Project Unix Name: %2$s
2050 Your DNS will take up to a day to become active on our site.
2051 Your web site is accessible through your shell account. Please read
2052 site documentation (see link below) about intended usage, available
2053 services, and directory layout of the account.
2056 own project page in %7$s while logged in, you will find
2057 additional menu functions to your left labeled \'Project Admin\'.
2059 We highly suggest that you now visit %7$s and create a public
2060 description for your project. This can be done by visiting your project
2061 page while logged in, and selecting \'Project Admin\' from the menus
2062 on the left (or by visiting http://%3$s/project/admin/?group_id=%6$s
2065 Your project will also not appear in the Trove Software Map (primary
2066 list of projects hosted on %7$s which offers great flexibility in
2067 browsing and search) until you categorize it in the project administration
2068 screens. So that people can find your project, you should do this now.
2069 Visit your project while logged in, and select \'Project Admin\' from the
2072 Enjoy the system, and please tell others about %7$s. Let us know
2073 if there is anything we can do to help you.
2075 -- 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']));
2077 util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), $GLOBALS['sys_name']), $message);
2079 setup_gettext_from_browser () ;
2087 * sendRejectionEmail - Send project rejection email.
2089 * This function sends out a rejection message to a user who
2090 * registered a project.
2092 * @param int The id of the response to use.
2093 * @param string The rejection message.
2094 * @return completion status.
2097 function sendRejectionEmail($response_id, $message="zxcv") {
2098 $res_admins = db_query("
2099 SELECT u.email, u.language, u.user_id
2100 FROM users u, user_group ug
2101 WHERE ug.group_id='".$this->getID()."'
2102 AND u.user_id=ug.user_id;
2105 if (db_numrows($res_admins) < 1) {
2106 $this->setError("Group does not have any administrators.");
2110 while ($row_admins = db_fetch_array($res_admins)) {
2111 $admin =& user_get_object($row_admins['user_id']);
2112 setup_gettext_for_user ($admin) ;
2114 $response=stripcslashes(sprintf(_('Your project registration for %3$s has been denied.
2116 Project Full Name: %1$s
2117 Project Unix Name: %2$s
2119 Reasons for negative decision:
2121 '), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name']));
2123 // Check to see if they want to send a custom rejection response
2124 if ($response_id == 0) {
2125 $response .= stripcslashes($message);
2127 $response .= db_result(db_query("
2128 SELECT response_text
2129 FROM canned_responses
2130 WHERE response_id='$response_id'
2131 "), 0, "response_text");
2134 util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), $GLOBALS['sys_name']), $response);
2135 setup_gettext_from_browser () ;
2142 * sendNewProjectNotificationEmail - Send new project notification email.
2144 * This function sends out a notification email to the
2145 * SourceForge admin user when a new project is
2148 * @return boolean success.
2151 function sendNewProjectNotificationEmail() {
2153 $res = db_query("SELECT users.email, users.language, users.user_id
2154 FROM users,user_group
2156 AND user_group.admin_flags='A'
2157 AND users.user_id=user_group.user_id;");
2159 if (db_numrows($res) < 1) {
2160 $this->setError("There is no administrator to send the mail.");
2163 for ($i=0; $i<db_numrows($res) ; $i++) {
2164 $admin_email = db_result($res,$i,'email') ;
2165 $admin =& user_get_object(db_result($res,$i,'user_id'));
2166 setup_gettext_for_user ($admin) ;
2168 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2170 Project Full Name: %2$s
2171 Submitted Description: %3$s
2174 Please visit the following URL to approve or reject this project:
2175 http://%5$s/admin/approve-pending.php'), $GLOBALS['sys_name'], $this->getPublicName(), util_unconvert_htmlspecialchars($this->getRegistrationPurpose()), $this->getLicenseName(), $GLOBALS['sys_default_domain']));
2176 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2177 setup_gettext_from_browser () ;
2181 // Get the email of the user who wants to register the project
2182 $res = db_query("SELECT u.email, u.language, u.user_id
2183 FROM users u, user_group ug
2184 WHERE ug.group_id='".$this->getID()."' AND u.user_id=ug.user_id;");
2186 if (db_numrows($res) < 1) {
2187 $this->setError("Cound not find user who has submitted the project.");
2190 for ($i=0; $i<db_numrows($res) ; $i++) {
2191 $email = db_result($res, $i, 'email');
2192 $user =& user_get_object(db_result($res,$i,'user_id'));
2193 setup_gettext_for_user ($user) ;
2195 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2197 Project Full Name: %2$s
2198 Submitted Description: %3$s
2201 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']));
2203 util_send_message($email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2204 setup_gettext_from_browser () ;
2214 * group_getname() - get the group name
2216 * @param int The group ID
2220 function group_getname ($group_id = 0) {
2221 $grp = &group_get_object($group_id);
2223 return $grp->getPublicName();
2230 * group_getunixname() - get the unixname for a group
2232 * @param int The group ID
2236 function group_getunixname ($group_id) {
2237 $grp = &group_get_object($group_id);
2239 return $grp->getUnixName();
2246 * group_get_result() - Get the group object result ID.
2248 * @param int The group ID
2252 function &group_get_result($group_id=0) {
2253 $grp = &group_get_object($group_id);
2255 return $grp->getData();
2262 * getUnixStatus - Status of activation of unix account.
2264 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2266 function getUnixStatus() {
2267 return $this->data_array['unix_status'];
2271 * setUnixStatus - Sets status of activation of unix account.
2273 * @param string The unix status.
2279 * @return boolean success.
2281 function setUnixStatus($status) {
2286 SET unix_status='$status'
2287 WHERE group_id='". $this->getID()."'
2291 $this->setError('ERROR - Could Not Update Group Unix Status: '.db_error());
2295 if ($status == 'A') {
2296 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2297 $this->setError($SYS->getErrorMessage());
2302 if ($SYS->sysCheckGroup($this->getID())) {
2303 if (!$SYS->sysRemoveGroup($this->getID())) {
2304 $this->setError($SYS->getErrorMessage());
2311 $this->data_array['unix_status']=$status;
2319 // c-file-style: "bsd"