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 $this->setError(_('Permission denied'), ERROR__PERMISSION_DENIED_ERROR);
258 * fetchData - May need to refresh database fields if an update occurred.
260 * @param int The group_id.
262 function fetchData($group_id) {
263 $res = db_query("SELECT * FROM groups WHERE group_id='$group_id'");
264 if (!$res || db_numrows($res) < 1) {
265 $this->setError(sprintf(_('fetchData():: %s'),db_error()));
268 $this->data_array =& db_fetch_array($res);
273 * create - Create new group.
275 * This method should be called on empty Group object.
277 * @param object The User object.
278 * @param string The full name of the user.
279 * @param string The Unix name of the user.
280 * @param string The new group description.
281 * @param int The ID of the license to use.
282 * @param string The 'other' license to use if any.
283 * @param string The purpose of the group.
285 function create(&$user, $full_name, $unix_name, $description, $license, $license_other, $purpose, $unix_box='shell1', $scm_box='cvs1') {
286 // $user is ignored - anyone can create pending group
288 if ($this->getID()!=0) {
289 $this->setError(_('Group::create: Group object already exists'));
291 } else if (strlen($full_name)<3) {
292 $this->setError(_('Invalid full name'));
294 } else if (!account_groupnamevalid($unix_name)) {
295 $this->setError(_('Invalid Unix name'));
297 } else if (db_numrows(db_query("SELECT group_id FROM groups WHERE unix_group_name='$unix_name'")) > 0) {
298 $this->setError(_('Unix name already taken'));
300 } else if (strlen($purpose)<10) {
301 $this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
303 } else if (strlen($purpose)>1500) {
304 $this->setError(_('The Registration Purpose text is too long. Please make it smaller than 1500 bytes.'));
306 } else if (strlen($description)<10) {
307 $this->setError(_('Describe in a more comprehensive manner your project.'));
309 } else if (strlen($description)>255) {
310 $this->setError(_('Your project description is too long. Please make it smaller than 256 bytes.'));
312 } else if (!$license) {
313 $this->setError(_('You have not chosen a license'));
315 } else if ($license!=GROUP_LICENSE_OTHER && $license_other) {
316 $this->setError(_('Conflicting licenses choice'));
318 } else if ($license==GROUP_LICENSE_OTHER && strlen($license_other)<50) {
319 $this->setError(_('Please give more comprehensive licensing description'));
323 srand((double)microtime()*1000000);
324 $random_num = rand(0,1000000);
346 '".htmlspecialchars($full_name)."',
349 '".htmlspecialchars($description)."',
350 '$unix_name.".$GLOBALS['sys_default_domain']."',
351 '$unix_name.".$GLOBALS['sys_default_domain']."',
356 '".htmlspecialchars($purpose)."',
358 '".htmlspecialchars($license_other)."',
359 '".md5($random_num)."'
363 if (!$res || db_affected_rows($res) < 1) {
364 $this->setError(sprintf(_('ERROR: Could not create group: %s'),db_error()));
369 $id = db_insertid($res, 'groups', 'group_id');
371 $this->setError(sprintf(_('ERROR: Could not get group id: %s'),db_error()));
377 // Now, make the user an admin
379 $sql="INSERT INTO user_group ( user_id, group_id, admin_flags,
380 cvs_flags, artifact_flags, forum_flags, role_id)
381 VALUES ( ".$user->getID().", '$id', 'A', 1, 2, 2, 1)";
384 if (!$res || db_affected_rows($res) < 1) {
385 $this->setError(sprintf(_('ERROR: Could not add admin to newly created group: %s'),db_error()));
390 if (!$this->fetchData($id)) {
395 $this->sendNewProjectNotificationEmail();
402 * updateAdmin - Update core properties of group object.
404 * This function require site admin privilege.
406 * @param object User requesting operation (for access control).
407 * @param bool Whether group is publicly accessible (0/1).
408 * @param string Project's license (string ident).
409 * @param int Group type (1-project, 2-foundry).
410 * @param string Machine on which group's home directory located.
411 * @param string Domain which serves group's WWW.
415 function updateAdmin(&$user, $is_public, $license, $type_id, $unix_box, $http_domain) {
416 $perm =& $this->getPermission($user);
418 if (!$perm || !is_object($perm)) {
419 $this->setError(_('Could not get permission.'));
423 if (!$perm->isSuperUser()) {
424 $this->setError(_('Permission denied.'));
432 SET is_public='$is_public',
433 license='$license',type_id='$type_id',
434 unix_box='$unix_box',http_domain='$http_domain'
435 WHERE group_id='".$this->getID()."'
438 if (!$res || db_affected_rows($res) < 1) {
439 $this->setError(_('ERROR: DB: Could not change group properties: %s'),db_error()));
444 // Log the audit trail
445 if ($is_public != $this->isPublic()) {
446 $this->addHistory('is_public', $this->isPublic());
448 if ($license != $this->data_array['license']) {
449 $this->addHistory('license', $this->data_array['license']);
451 if ($type_id != $this->data_array['type_id']) {
452 $this->addHistory('type_id', $this->data_array['type_id']);
454 if ($unix_box != $this->data_array['unix_box']) {
455 $this->addHistory('unix_box', $this->data_array['unix_box']);
457 if ($http_domain != $this->data_array['http_domain']) {
458 $this->addHistory('http_domain', $this->data_array['http_domain']);
461 if (!$this->fetchData($this->getID())) {
470 * update - Update number of common properties.
472 * Unlike updateAdmin(), this function accessible to project admin.
474 * @param object User requesting operation (for access control).
475 * @param bool Whether group is publicly accessible (0/1).
476 * @param string Project's license (string ident).
477 * @param int Group type (1-project, 2-foundry).
478 * @param string Machine on which group's home directory located.
479 * @param string Domain which serves group's WWW.
480 * @return int status.
483 function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,
484 $use_pm,$use_pm_depend_box,$use_scm,$use_news,$use_docman,
485 $new_doc_address,$send_all_docs,$logo_image_id,
486 $enable_pserver,$enable_anonscm,
487 $use_ftp,$use_tracker,$use_frs,$use_stats) {
489 $perm =& $this->getPermission($user);
491 if (!$perm || !is_object($perm)) {
492 $this->setError(_('Could not get permission.'));
496 if (!$perm->isAdmin()) {
497 $this->setError(_('Permission denied.'));
501 // Validate some values
503 $this->setError(_('Invalid Group Name'));
507 if ($new_doc_address) {
508 $invalid_mails = validate_emails($new_doc_address);
509 if (count($invalid_mails) > 0) {
510 $this->setError(sprintf (ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
515 // in the database, these all default to '1',
516 // so we have to explicity set 0
529 if (!$use_pm_depend_box) {
530 $use_pm_depend_box=0;
553 if (!$send_all_docs) {
558 $homepage=$GLOBALS['sys_default_domain'].'/projects/'.$this->getUnixName().'/';
561 if (strlen($short_description)>255) {
562 $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
568 //XXX not yet actived logo_image_id='$logo_image_id',
572 group_name='".htmlspecialchars($group_name)."',
573 homepage='$homepage',
574 short_description='".htmlspecialchars($short_description)."',
575 use_mail='$use_mail',
576 use_survey='$use_survey',
577 use_forum='$use_forum',
579 use_pm_depend_box='$use_pm_depend_box',
581 use_news='$use_news',
582 use_docman='$use_docman',
583 new_doc_address='$new_doc_address',
584 send_all_docs='$send_all_docs',
586 if ($enable_pserver != '') {
588 enable_pserver='$enable_pserver',
591 if ($enable_anonscm != '') {
593 enable_anonscm='$enable_anonscm',
598 use_tracker='$use_tracker',
600 use_stats='$use_stats'
601 WHERE group_id='".$this->getID()."'
603 $res = db_query($sql);
606 $this->setError(sprintf(_('Error updating project information: %s'), db_error()));
611 // Log the audit trail
612 $this->addHistory('Changed Public Info', '');
614 if (!$this->fetchData($this->getID())) {
623 * getID - Simply return the group_id for this object.
625 * @return int group_id.
628 return $this->data_array['group_id'];
632 * getType() - Foundry, project, etc.
634 * @return int The type flag from the database.
637 return $this->data_array['type_id'];
642 * getStatus - the status code.
644 * Statuses char include I,H,A,D.
646 function getStatus() {
647 return $this->data_array['status'];
651 * setStatus - set the status code.
653 * Statuses include I,H,A,D.
655 * @param object User requesting operation (for access control).
656 * @param string Status value.
657 * @return boolean success.
660 function setStatus(&$user, $status) {
663 $perm =& $this->getPermission($user);
664 if (!$perm || !is_object($perm)) {
665 $this->setPermissionDeniedError();
667 } elseif (!$perm->isSuperUser()) {
668 $this->setPermissionDeniedError();
672 // Projects in 'A' status can only go to 'H' or 'D'
673 // Projects in 'D' status can only go to 'A'
674 // Projects in 'P' status can only go to 'A' OR 'D'
675 // Projects in 'I' status can only go to 'P'
676 // Projects in 'H' status can only go to 'A' OR 'D'
677 $allowed_status_changes = array(
678 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
679 'IP'=>1,'HA'=>1,'HD'=>1
682 // Check that status transition is valid
683 if ($this->getStatus() != $status
684 && !$allowed_status_changes[$this->getStatus().$status]) {
685 $this->setError(_('Invalid Status Change'));
691 $res = db_query("UPDATE groups
693 WHERE group_id='". $this->getID()."'");
695 if (!$res || db_affected_rows($res) < 1) {
696 $this->setError(sprintf(_('ERROR: DB: Could not change group status: %s'),db_error()));
702 // Activate system group, if not yet
703 if (!$SYS->sysCheckGroup($this->getID())) {
704 if (!$SYS->sysCreateGroup($this->getID())) {
705 $this->setError($SYS->getErrorMessage());
710 if (!$this->activateUsers()) {
715 /* Otherwise, the group is not active, and make sure that
716 System group is not active either */
717 } else if ($SYS->sysCheckGroup($this->getID())) {
718 if (!$SYS->sysRemoveGroup($this->getID())) {
719 $this->setError($SYS->getErrorMessage());
727 // Log the audit trail
728 if ($status != $this->getStatus()) {
729 $this->addHistory('Status', $this->getStatus());
732 $this->data_array['status'] = $status;
737 * isProject - Simple boolean test to see if it's a project or not.
739 * @return boolean is_project.
741 function isProject() {
742 if ($this->getType()==1) {
750 * isPublic - Simply returns the is_public flag from the database.
752 * @return boolean is_public.
754 function isPublic() {
755 return $this->data_array['is_public'];
759 * isActive - Database field status of 'A' returns true.
761 * @return boolean is_active.
763 function isActive() {
764 if ($this->getStatus()=='A') {
772 * getUnixName - the unix_name
774 * @return string unix_name.
776 function getUnixName() {
777 return strtolower($this->data_array['unix_group_name']);
781 * getPublicName - the full-length public name.
783 * @return string The group_name.
785 function getPublicName() {
786 return $this->data_array['group_name'];
790 * getRegisterPurpose - the text description of the purpose of this project.
792 * @return string The description.
794 function getRegisterPurpose() {
795 return $this->data_array['register_purpose'];
799 * getDescription - the text description of this project.
801 * @return string The description.
803 function getDescription() {
804 return $this->data_array['short_description'];
808 * getStartDate - the unix time this project was registered.
810 * @return int (unix time) of registration.
812 function getStartDate() {
813 return $this->data_array['register_time'];
817 * getLogoImageID - the id of the logo in the database for this project.
819 * @return int The ID of logo image in db_images table (or 100 if none).
821 function getLogoImageID() {
822 return $this->data_array['logo_image_id'];
826 * getUnixBox - the hostname of the unix box where this project is located.
828 * @return string The name of the unix machine for the group.
830 function getUnixBox() {
831 return $this->data_array['unix_box'];
835 * getSCMBox - the hostname of the scm box where this project is located.
837 * @return string The name of the unix machine for the group.
839 function getSCMBox() {
840 return $this->data_array['scm_box'];
843 * setSCMBox - the hostname of the scm box where this project is located.
845 * @param string The name of the new SCM_BOX
847 function setSCMBox($scm_box) {
850 $sql = "UPDATE groups SET scm_box = '$scm_box' WHERE group_id = ".$this->getID();
851 $res = db_query($sql);
853 $this->addHistory('scm_box', $this->data_array['scm_box']);
854 $this->data_array['scm_box']=$scm_box;
859 $this->setError(_("Couldn't insert SCM_BOX to database"));
863 $this->setError(_("SCM Box can't be empty"));
869 * getDomain - the hostname.domain where their web page is located.
871 * @return string The name of the group [web] domain.
873 function getDomain() {
874 return $this->data_array['http_domain'];
878 * getLicense - the license they chose.
880 * @return int ident of group license.
882 function getLicense() {
883 return $this->data_array['license'];
887 * getLicenseName - the name of the license
889 * @return string license name
891 function getLicenseName() {
892 $licenses =& group_get_licenses();
893 if(isset($licenses[$this->data_array['license']])) {
894 return $licenses[$this->data_array['license']];
901 * getLicenseOther - optional string describing license.
903 * @return string The custom license.
905 function getLicenseOther() {
906 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
907 return $this->data_array['license_other'];
914 * getRegistrationPurpose - the text description of the purpose of this project.
916 * @return string The application for project hosting.
918 function getRegistrationPurpose() {
919 return $this->data_array['register_purpose'];
924 * getAdmins() - Get array of Admin user objects.
926 * @return array Array of User objects.
928 function &getAdmins() {
929 // this function gets all group admins in order to send Jabber and mail messages
930 $q = "SELECT user_id FROM user_group WHERE admin_flags = 'A' AND group_id = ".$this->getID();
932 $user_ids=util_result_column_to_array($res);
933 return user_get_objects($user_ids);
938 Common Group preferences for tools
943 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
945 * @return boolean enable_scm.
947 function enableAnonSCM() {
948 if ($this->isPublic() && $this->usesSCM()) {
949 return $this->data_array['enable_anonscm'];
955 function SetUsesAnonSCM ($booleanparam) {
957 $booleanparam = $booleanparam ? 1 : 0 ;
958 $sql = "UPDATE groups SET enable_anonscm = $booleanparam WHERE group_id = ".$this->getID() ;
959 $res = db_query($sql);
961 $this->data_array['enable_anonscm']=$booleanparam;
970 * enablePserver - whether or not this group has opted to enable Pserver.
972 * @return boolean enable_pserver.
974 function enablePserver() {
975 if ($this->usesSCM()) {
976 return $this->data_array['enable_pserver'];
982 function SetUsesPserver ($booleanparam) {
984 $booleanparam = $booleanparam ? 1 : 0 ;
985 $sql = "UPDATE groups SET enable_pserver = $booleanparam WHERE group_id = ".$this->getID() ;
986 $res = db_query($sql);
988 $this->data_array['enable_pserver']=$booleanparam;
997 * usesSCM - whether or not this group has opted to use SCM.
999 * @return boolean uses_scm.
1001 function usesSCM() {
1002 global $sys_use_scm;
1004 return $this->data_array['use_scm'];
1011 * usesMail - whether or not this group has opted to use mailing lists.
1013 * @return boolean uses_mail.
1015 function usesMail() {
1016 global $sys_use_mail;
1017 if ($sys_use_mail) {
1018 return $this->data_array['use_mail'];
1025 * usesNews - whether or not this group has opted to use news.
1027 * @return boolean uses_news.
1029 function usesNews() {
1030 global $sys_use_news;
1031 if ($sys_use_news) {
1032 return $this->data_array['use_news'];
1039 * usesForum - whether or not this group has opted to use discussion forums.
1041 * @return boolean uses_forum.
1043 function usesForum() {
1044 global $sys_use_forum;
1045 if ($sys_use_forum) {
1046 return $this->data_array['use_forum'];
1053 * usesStats - whether or not this group has opted to use stats.
1055 * @return boolean uses_stats.
1057 function usesStats() {
1058 return $this->data_array['use_stats'];
1062 * usesFRS - whether or not this group has opted to use file release system.
1064 * @return boolean uses_frs.
1066 function usesFRS() {
1067 global $sys_use_frs;
1069 return $this->data_array['use_frs'];
1076 * usesTracker - whether or not this group has opted to use tracker.
1078 * @return boolean uses_tracker.
1080 function usesTracker() {
1081 global $sys_use_tracker;
1082 if ($sys_use_tracker) {
1083 return $this->data_array['use_tracker'];
1090 * usesDocman - whether or not this group has opted to use docman.
1092 * @return boolean uses_docman.
1094 function usesDocman() {
1095 global $sys_use_docman;
1096 if ($sys_use_docman) {
1097 return $this->data_array['use_docman'];
1104 * usesFTP - whether or not this group has opted to use FTP.
1106 * @return boolean uses_ftp.
1108 function usesFTP() {
1109 global $sys_use_ftp;
1111 return $this->data_array['use_ftp'];
1118 * usesSurvey - whether or not this group has opted to use surveys.
1120 * @return boolean uses_survey.
1122 function usesSurvey() {
1123 global $sys_use_survey;
1124 if ($sys_use_survey) {
1125 return $this->data_array['use_survey'];
1132 * usesPM - whether or not this group has opted to Project Manager.
1134 * @return boolean uses_projman.
1139 return $this->data_array['use_pm'];
1146 * getPlugins - get a list of all available group plugins
1148 * @return array array containing plugin_id => plugin_name
1150 function getPlugins() {
1151 if (!isset($this->plugins_data)) {
1152 $this->plugins_data = array () ;
1153 $sql="SELECT group_plugin.plugin_id, plugins.plugin_name
1154 FROM group_plugin, plugins
1155 WHERE group_plugin.group_id=".$this->getID()."
1156 AND group_plugin.plugin_id = plugins.plugin_id" ;
1157 $res=db_query($sql);
1158 $rows = db_numrows($res);
1160 for ($i=0; $i<$rows; $i++) {
1161 $plugin_id = db_result($res,$i,'plugin_id');
1162 $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
1165 return $this->plugins_data ;
1169 * usesPlugin - returns true if the group uses a particular plugin
1171 * @param string name of the plugin
1172 * @return boolean whether plugin is being used or not
1174 function usesPlugin($pluginname) {
1175 $plugins_data = $this->getPlugins() ;
1176 foreach ($plugins_data as $p_id => $p_name) {
1177 if ($p_name == $pluginname) {
1185 * setPluginUse - enables/disables plugins for the group
1187 * @param string name of the plugin
1188 * @param boolean the new state
1189 * @return string database result
1191 function setPluginUse($pluginname, $val=true) {
1192 if ($val == $this->usesPlugin($pluginname)) {
1193 // State is already good, returning
1196 $sql="SELECT plugin_id
1198 WHERE plugin_name = '" . $pluginname . "'" ;
1199 $res=db_query($sql);
1200 $rows = db_numrows($res);
1202 // Error: no plugin by that name
1205 $plugin_id = db_result($res,0,'plugin_id');
1207 unset ($this->plugins_data) ;
1209 $sql="INSERT INTO group_plugin (group_id, plugin_id)
1210 VALUES (". $this->getID() . ", ". $plugin_id .")" ;
1211 $res=db_query($sql);
1214 $sql="DELETE FROM group_plugin
1215 WHERE group_id = ". $this->getID() . "
1216 AND plugin_id = ". $plugin_id ;
1217 $res=db_query($sql);
1223 * getDocEmailAddress - get email address(es) to send doc notifications to.
1225 * @return string email address.
1227 function getDocEmailAddress() {
1228 return $this->data_array['new_doc_address'];
1232 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1234 * @return boolean email_on_all_doc_updates.
1236 function docEmailAll() {
1237 return $this->data_array['send_all_docs'];
1242 * getHomePage - The URL for this project's home page.
1244 * @return string homepage URL.
1246 function getHomePage() {
1247 return $this->data_array['homepage'];
1251 * getPermission - Return a Permission for this Group and the specified User.
1253 * @param object The user you wish to get permission for (usually the logged in user).
1254 * @return object The Permission.
1256 function &getPermission(&$_user) {
1257 return permission_get_object($this, $_user);
1262 * userIsAdmin - Return if for this Group the User is admin.
1264 * @return boolean is_admin.
1266 function userIsAdmin() {
1267 $perm =& $this->getPermission( session_get_user() );
1268 if (!$perm || !is_object($perm)) {
1270 } elseif ($perm->isError()) {
1273 return $perm->isAdmin();
1276 function delete($sure,$really_sure,$really_really_sure) {
1277 if (!$sure || !$really_sure || !$really_really_sure) {
1278 $this->setMissingParamsError();
1281 if ($this->getID() == $GLOBALS['sys_news_group'] ||
1282 $this->getID() == 1 ||
1283 $this->getID() == $GLOBALS['sys_stats_group'] ||
1284 $this->getID() == $GLOBALS['sys_peer_rating_group']) {
1285 $this->setError(_('Cannot Delete System Group'));
1288 $perm =& $this->getPermission( session_get_user() );
1289 if (!$perm || !is_object($perm)) {
1290 $this->setPermissionDeniedError();
1292 } elseif ($perm->isError()) {
1293 $this->setPermissionDeniedError();
1295 } elseif (!$perm->isSuperUser()) {
1296 $this->setPermissionDeniedError();
1302 // Remove all the members
1304 $members =& $this->getMembers();
1305 for ($i=0; $i<count($members); $i++) {
1306 $this->removeUser($members[$i]->getID());
1311 $atf = new ArtifactTypeFactory($this);
1312 $at_arr =& $atf->getArtifactTypes();
1313 for ($i=0; $i<count($at_arr); $i++) {
1314 if (!is_object($at_arr[$i])) {
1315 printf (_("Not Object: ArtifactType: %d"),$i);
1318 $at_arr[$i]->delete(1,1);
1323 $ff = new ForumFactory($this);
1324 $f_arr =& $ff->getForums();
1325 for ($i=0; $i<count($f_arr); $i++) {
1326 if (!is_object($f_arr[$i])) {
1327 printf (_("Not Object: Forum: %d"),$i);
1330 $f_arr[$i]->delete(1,1);
1331 //echo 'ForumFactory'.db_error();
1334 // Delete Subprojects
1336 $pgf = new ProjectGroupFactory($this);
1337 $pg_arr =& $pgf->getProjectGroups();
1338 for ($i=0; $i<count($pg_arr); $i++) {
1339 if (!is_object($pg_arr[$i])) {
1340 printf (_("Not Object: ProjectGroup: %d"),$i);
1343 $pg_arr[$i]->delete(1,1);
1344 //echo 'ProjectGroupFactory'.db_error();
1347 // Delete FRS Packages
1349 //$frspf = new FRSPackageFactory($this);
1350 $res=db_query("SELECT * FROM frs_package WHERE group_id='".$this->getID()."'");
1351 //echo 'frs_package'.db_error();
1352 //$frsp_arr =& $frspf->getPackages();
1353 while ($arr = db_fetch_array($res)) {
1354 //if (!is_object($pg_arr[$i])) {
1355 // echo "Not Object: ProjectGroup: ".$i;
1358 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1364 $news_group=&group_get_object($GLOBALS['sys_news_group']);
1365 $res=db_query("SELECT forum_id FROM news_bytes WHERE group_id='".$this->getID()."'");
1366 for ($i=0; $i<db_numrows($res); $i++) {
1367 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1368 if (!$Forum->delete(1,1)) {
1369 printf (_("Could Not Delete News Forum: %d"),$Forum->getID());
1372 $res=db_query("DELETE FROM news_bytes WHERE group_id='".$this->getID()."'");
1377 $res=db_query("DELETE FROM doc_data WHERE group_id='".$this->getID()."'");
1378 //echo 'doc_data'.db_error();
1379 $res=db_query("DELETE FROM doc_groups WHERE group_id='".$this->getID()."'");
1380 //echo 'doc_groups'.db_error();
1382 // Delete group history
1384 $res=db_query("DELETE FROM group_history WHERE group_id='".$this->getID()."'");
1385 //echo 'group_history'.db_error();
1387 // Delete group plugins
1389 $res=db_query("DELETE FROM group_plugin WHERE group_id='".$this->getID()."'");
1390 //echo 'group_plugin'.db_error();
1392 // Delete group cvs stats
1394 $res=db_query("DELETE FROM stats_cvs_group WHERE group_id='".$this->getID()."'");
1395 //echo 'stats_cvs_group'.db_error();
1399 $sf = new SurveyFactory($this);
1400 $s_arr =& $sf->getSurveys();
1401 for ($i=0; $i<count($s_arr); $i++) {
1402 if (!is_object($s_arr[$i])) {
1403 printf (_("Not Object: Survey: %d"),$i);
1406 $s_arr[$i]->delete();
1407 //echo 'SurveyFactory'.db_error();
1410 // Delete SurveyQuestions
1412 $sqf = new SurveyQuestionFactory($this);
1413 $sq_arr =& $sqf->getSurveyQuestions();
1414 for ($i=0; $i<count($sq_arr); $i++) {
1415 if (!is_object($sq_arr[$i])) {
1416 printf (_("Not Object: SurveyQuestion: %d"),$i);
1419 $sq_arr[$i]->delete();
1420 //echo 'SurveyQuestionFactory'.db_error();
1423 // Delete Mailing List Factory
1425 $mlf = new MailingListFactory($this);
1426 $ml_arr =& $mlf->getMailingLists();
1427 for ($i=0; $i<count($ml_arr); $i++) {
1428 if (!is_object($ml_arr[$i])) {
1429 printf (_("Not Object: MailingList: %d"),$i);
1432 if (!$ml_arr[$i]->delete(1,1)) {
1433 $this->setError(_('Could not properly delete the mailing list'));
1435 //echo 'MailingListFactory'.db_error();
1440 $res=db_query("DELETE FROM trove_group_link WHERE group_id='".$this->getID()."'");
1441 $res=db_query("DELETE FROM trove_agg WHERE group_id='".$this->getID()."'");
1445 $res=db_query("DELETE FROM project_sums_agg WHERE group_id='".$this->getID()."'");
1446 //echo 'project_sums_agg'.db_error();
1447 $res=db_query("INSERT INTO deleted_groups (
1448 unix_group_name,delete_date,isdeleted) VALUES
1449 ('".$this->getUnixName()."','".time()."','0')");
1450 //echo 'InsertIntoDeleteQueue'.db_error();
1451 $res=db_query("DELETE FROM groups WHERE group_id='".$this->getID()."'");
1452 //echo 'DeleteGroup'.db_error();
1457 if (isset($GLOBALS['sys_upload_dir']) && $this->getUnixName()) {
1458 exec('/bin/rm -rf '.$GLOBALS['sys_upload_dir'].'/'.$this->getUnixName().'/');
1460 if (isset($GLOBALS['sys_ftp_upload_dir']) && $this->getUnixName()) {
1461 exec('/bin/rm -rf '.$GLOBALS['sys_ftp_upload_dir'].'/'.$this->getUnixName().'/');
1466 $res=db_query("DELETE FROM rep_group_act_weekly WHERE group_id='".$this->getID()."'");
1467 //echo 'rep_group_act_weekly'.db_error();
1468 $res=db_query("DELETE FROM rep_group_act_monthly WHERE group_id='".$this->getID()."'");
1469 //echo 'rep_group_act_monthly'.db_error();
1470 $res=db_query("DELETE FROM rep_group_act_daily WHERE group_id='".$this->getID()."'");
1471 //echo 'rep_group_act_daily'.db_error();
1472 unset($this->data_array);
1480 Basic functions to add/remove users to/from a group
1481 and update their permissions
1487 * addUser - controls adding a user to a group.
1489 * @param string Unix name of the user to add OR integer user_id.
1490 * @param int The role_id this user should have.
1491 * @return boolean success.
1494 function addUser($user_unix_name,$role_id) {
1497 Admins can add users to groups
1500 $perm =& $this->getPermission( session_get_user() );
1501 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1502 $this->setPermissionDeniedError();
1508 get user id for this user's unix_name
1510 if (eregi('[^0-9]',$user_unix_name)) {
1511 $res_newuser = db_query("SELECT * FROM users WHERE user_name='". strtolower($user_unix_name) ."'");
1513 $res_newuser = db_query("SELECT * FROM users WHERE user_id='". intval($user_unix_name) ."'");
1515 if (db_numrows($res_newuser) > 0) {
1517 // make sure user is active
1519 if (db_result($res_newuser,0,'status') != 'A') {
1520 $this->setError(_('User is not active. Only active users can be added.'));
1526 // user was found - set new user_id var
1528 $user_id = db_result($res_newuser,0,'user_id');
1531 // if not already a member, add them
1533 $res_member = db_query("SELECT user_id
1535 WHERE user_id='$user_id' AND group_id='". $this->getID() ."'");
1537 if (db_numrows($res_member) < 1) {
1539 // Create this user's row in the user_group table
1541 $res=db_query("INSERT INTO user_group
1542 (user_id,group_id,admin_flags,forum_flags,project_flags,
1543 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
1544 VALUES ('$user_id','". $this->getID() ."','','0','0','0','1','100','0','0')");
1546 //verify the insert worked
1547 if (!$res || db_affected_rows($res) < 1) {
1548 $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
1553 // check and create if group doesn't exists
1555 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
1556 if (!$SYS->sysCheckCreateGroup($this->getID())){
1557 $this->setError($SYS->getErrorMessage());
1562 // check and create if user doesn't exists
1564 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1565 if (!$SYS->sysCheckCreateUser($user_id)) {
1566 $this->setError($SYS->getErrorMessage());
1573 $role = new Role($this,$role_id);
1574 if (!$role || !is_object($role)) {
1575 $this->setError(_('Error Getting Role Object'));
1578 } elseif ($role->isError()) {
1579 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1583 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
1584 if (!$role->setUser($user_id)) {
1585 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1591 // user was already a member
1592 // make sure they are set up
1594 $user=&user_get_object($user_id,$res_newuser);
1595 $user->fetchData($user->getID());
1596 $role = new Role($this,$role_id);
1597 if (!$role || !is_object($role)) {
1598 $this->setError(_('Error Getting Role Object'));
1601 } elseif ($role->isError()) {
1602 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1606 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
1607 if (!$role->setUser($user_id)) {
1608 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1613 // set up their system info
1615 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1616 if (!$SYS->sysCheckCreateUser($user_id)) {
1617 $this->setError($SYS->getErrorMessage());
1626 // user doesn't exist
1628 $this->setError(_('ERROR: User does not exist'));
1635 $this->addHistory('Added User',$user_unix_name);
1641 * removeUser - controls removing a user from a group.
1643 * Users can remove themselves.
1645 * @param int The ID of the user to remove.
1646 * @return boolean success.
1648 function removeUser($user_id) {
1649 global $SYS,$sys_database_type;
1651 if ($user_id==user_getid()) {
1652 //users can remove themselves
1653 //everyone else must be a project admin
1655 $perm =& $this->getPermission( session_get_user() );
1657 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1658 $this->setPermissionDeniedError();
1664 $res=db_query("DELETE FROM user_group
1665 WHERE group_id='".$this->getID()."'
1666 AND user_id='$user_id'");
1667 if (!$res || db_affected_rows($res) < 1) {
1668 $this->setError(sprintf(_('ERROR: User not removed: %s'),db_error()));
1673 // reassign open artifacts to id=100
1675 $res=db_query("UPDATE artifact SET assigned_to='100'
1676 WHERE group_artifact_id
1677 IN (SELECT group_artifact_id
1678 FROM artifact_group_list
1679 WHERE group_id='".$this->getID()."')
1680 AND status_id='1' AND assigned_to='$user_id'");
1682 $this->setError(sprintf(_('ERROR: DB: artifact: %s'),db_error()));
1688 // reassign open tasks to id=100
1689 // first have to purge any assignments that would cause
1690 // conflict with existing assignment to 100
1692 if ($sys_database_type == 'mysql') {
1694 SELECT pt.project_task_id
1695 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1696 WHERE pt.group_project_id = pgl.group_project_id
1697 AND pat.project_task_id=pt.project_task_id
1698 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."'
1699 AND pat.assigned_to_id='$user_id' INTO @task_list;
1700 DELETE FROM project_assigned_to WHERE project_task_id IN ( @task_list ) AND assigned_to_id='100'");
1702 $res = db_next_result();
1705 $res=db_query("DELETE FROM project_assigned_to
1706 WHERE project_task_id IN (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')
1712 AND assigned_to_id='100'");
1715 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),1,db_error()));
1719 $res=db_query("UPDATE project_assigned_to SET assigned_to_id='100'
1720 WHERE project_task_id IN (SELECT pt.project_task_id
1721 FROM project_task pt, project_group_list pgl
1722 WHERE pt.group_project_id = pgl.group_project_id
1723 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."')
1724 AND assigned_to_id='$user_id'");
1726 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),2,db_error()));
1732 // Remove user from system
1734 //echo "<h2>Group::addUser SYS->sysGroupRemoveUser(".$this->getID().",$user_id)</h2>";
1735 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
1736 $this->setError($SYS->getErrorMessage());
1741 $this->addHistory('Removed User',$user_id);
1748 * updateUser - controls updating a user's role in this group.
1750 * @param int The ID of the user.
1751 * @param int The role_id to set this user to.
1752 * @return boolean success.
1754 function updateUser($user_id,$role_id) {
1757 $perm =& $this->getPermission( session_get_user() );
1758 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1759 $this->setPermissionDeniedError();
1763 $role = new Role($this,$role_id);
1764 if (!$role || !is_object($role)) {
1765 $this->setError(_('Could Not Get Role'));
1767 } elseif ($role->isError()) {
1768 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1771 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
1772 if (!$role->setUser($user_id)) {
1773 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1776 $this->addHistory('Updated User',$user_id);
1781 * addHistory - Makes an audit trail entry for this project.
1783 * @param string The name of the field.
1784 * @param string The Old Value for this $field_name.
1785 * @return database result handle.
1788 function addHistory($field_name, $old_value) {
1790 INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
1791 VALUES ('". $this->getID() ."','$field_name','$old_value','". user_getid() ."','".time()."')
1793 return db_query($sql);
1797 * activateUsers - Make sure that group members have unix accounts.
1799 * Setup unix accounts for group members. Can be called even
1800 * if members are already active.
1804 function activateUsers() {
1807 Activate member(s) of the project
1810 $member_res = db_query("SELECT user_id, role_id
1812 WHERE group_id='".$this->getID()."'");
1814 $rows = db_numrows($member_res);
1818 for ($i=0; $i<$rows; $i++) {
1820 $member =& user_get_object(db_result($member_res,$i,'user_id'));
1821 $roleId = db_result($member_res,$i,'role_id');
1823 if (!$member || !is_object($member)) {
1824 $this->setError(_('Error getting member object'));
1826 } else if ($member->isError()) {
1827 $this->setError(sprintf(_('Error getting member object: %s'),$member->getErrorMessage()));
1831 if (!$this->addUser($member->getUnixName(),$roleId)) {
1842 * getMembers - returns array of User objects for this project
1844 * @return array of User objects for this group.
1846 function &getMembers() {
1847 if (!isset($this->membersArr)) {
1848 $res=db_query("SELECT users.* FROM users
1849 INNER JOIN user_group ON users.user_id=user_group.user_id
1850 WHERE user_group.group_id='".$this->getID()."'");
1851 while ($arr =& db_fetch_array($res)) {
1852 $this->membersArr[] =& new User($arr['user_id'],$arr);
1855 return $this->membersArr;
1859 * approve - Approve pending project.
1861 * @param object The User object who is doing the updating.
1864 function approve(&$user) {
1866 if ($this->getStatus()=='A') {
1867 $this->setError(_("Group already active"));
1873 // Step 1: Activate group and create LDAP entries
1874 if (!$this->setStatus($user, 'A')) {
1881 // Tracker Integration
1884 $ats = new ArtifactTypes($this);
1885 if (!$ats || !is_object($ats)) {
1886 $this->setError(_('Error creating ArtifactTypes object'));
1889 } else if ($ats->isError()) {
1890 $this->setError(sprintf (_('ATS%d: %s'), 1, $ats->getErrorMessage());
1894 if (!$ats->createTrackers()) {
1895 $this->setError(sprintf (_('ATS%d: %s'), 2, $ats->getErrorMessage());
1902 // Forum Integration
1905 $f = new Forum($this);
1906 if (!$f->create('Open-Discussion','General Discussion',1,'',1,0)) {
1907 $this->setError(sprintf (_('F%d: %s'), 1, $f->getErrorMessage());
1911 $f = new Forum($this);
1912 if (!$f->create('Help','Get Public Help',1,'',1,0)) {
1913 $this->setError(sprintf (_('F%d: %s'), 2, $f->getErrorMessage());
1917 $f = new Forum($this);
1918 if (!$f->create('Developers','Project Developer Discussion',0,'',1,0)) {
1919 $this->setError(sprintf (_('F%d: %s'), 3, $f->getErrorMessage());
1926 // Doc Mgr Integration
1929 $dg = new DocumentGroup($this);
1930 if (!$dg->create('Uncategorized Submissions')) {
1931 $this->setError(sprintf(_('DG: %s'),$dg->getErrorMessage()));
1941 $frs = new FRSPackage($this);
1942 if (!$frs->create($this->getUnixName())) {
1943 $this->setError(sprintf(_('FRSP: %s'),$frs->getErrorMessage()));
1953 $pg = new ProjectGroup($this);
1954 if (!$pg->create('To Do','Things We Have To Do',1)) {
1955 $this->setError(sprintf(_('PG%d: %s'),1,$pg->getErrorMessage()));
1959 $pg = new ProjectGroup($this);
1960 if (!$pg->create('Next Release','Items For Our Next Release',1)) {
1961 $this->setError(sprintf(_('PG%d: %s'),2,$pg->getErrorMessage()));
1968 // Set Default Roles
1971 $role = new Role($this);
1972 $todo = array_keys($role->defaults);
1973 for ($c=0; $c<count($todo); $c++) {
1974 $role = new Role($this);
1975 if (!$role->createDefault($todo[$c])) {
1976 $this->setError(sprintf(_('R%d: %s'),$c,$role->getErrorMessage()));
1984 // Create MailingList
1987 $mlist = new MailingList($this);
1988 $admin_group = db_query("SELECT user_id FROM user_group
1989 WHERE group_id=".$this->getID()." AND admin_flags='A'");
1990 if (db_numrows($admin_group) > 0) {
1991 $idadmin_group = db_result($admin_group,0,'user_id');
1993 if (!$mlist->create('commits','Commits',1,$idadmin_group)) {
1994 $this->setError(sprintf(_('ML: %s'),$mlist->getErrorMessage()));
2001 $this->sendApprovalEmail();
2002 $this->addHistory('Approved', 'x');
2005 //change assistant for webcal
2007 $params[0] = $idadmin_group ;
2008 $params[1] = $this->getID();
2009 plugin_hook('change_cal_permission_default',$params);
2017 * sendApprovalEmail - Send new project email.
2019 * @return boolean success.
2022 function sendApprovalEmail() {
2023 $res_admins = db_query("
2024 SELECT users.user_name,users.email,users.language,users.user_id
2025 FROM users,user_group
2026 WHERE users.user_id=user_group.user_id
2027 AND user_group.group_id='".$this->getID()."'
2028 AND user_group.admin_flags='A'
2031 if (db_numrows($res_admins) < 1) {
2032 $this->setError(_("Group does not have any administrators."));
2036 // send one email per admin
2037 while ($row_admins = db_fetch_array($res_admins)) {
2038 $admin =& user_get_object($row_admins['user_id']);
2039 setup_gettext_for_user ($admin) ;
2041 // $2 $2 $3 $4 $5 $6
2042 $message=stripcslashes(sprintf(_('Your project registration for %7$s has been approved.
2044 Project Full Name: %1$s
2045 Project Unix Name: %2$s
2047 Your DNS will take up to a day to become active on our site.
2048 Your web site is accessible through your shell account. Please read
2049 site documentation (see link below) about intended usage, available
2050 services, and directory layout of the account.
2053 own project page in %7$s while logged in, you will find
2054 additional menu functions to your left labeled \'Project Admin\'.
2056 We highly suggest that you now visit %7$s and create a public
2057 description for your project. This can be done by visiting your project
2058 page while logged in, and selecting \'Project Admin\' from the menus
2059 on the left (or by visiting http://%3$s/project/admin/?group_id=%6$s
2062 Your project will also not appear in the Trove Software Map (primary
2063 list of projects hosted on %7$s which offers great flexibility in
2064 browsing and search) until you categorize it in the project administration
2065 screens. So that people can find your project, you should do this now.
2066 Visit your project while logged in, and select \'Project Admin\' from the
2069 Enjoy the system, and please tell others about %7$s. Let us know
2070 if there is anything we can do to help you.
2072 -- 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']));
2074 util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), $GLOBALS['sys_name']), $message);
2076 setup_gettext_from_browser () ;
2084 * sendRejectionEmail - Send project rejection email.
2086 * This function sends out a rejection message to a user who
2087 * registered a project.
2089 * @param int The id of the response to use.
2090 * @param string The rejection message.
2091 * @return completion status.
2094 function sendRejectionEmail($response_id, $message="zxcv") {
2095 $res_admins = db_query("
2096 SELECT u.email, u.language, u.user_id
2097 FROM users u, user_group ug
2098 WHERE ug.group_id='".$this->getID()."'
2099 AND u.user_id=ug.user_id;
2102 if (db_numrows($res_admins) < 1) {
2103 $this->setError(_("Group does not have any administrators."));
2107 while ($row_admins = db_fetch_array($res_admins)) {
2108 $admin =& user_get_object($row_admins['user_id']);
2109 setup_gettext_for_user ($admin) ;
2111 $response=stripcslashes(sprintf(_('Your project registration for %3$s has been denied.
2113 Project Full Name: %1$s
2114 Project Unix Name: %2$s
2116 Reasons for negative decision:
2118 '), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name']));
2120 // Check to see if they want to send a custom rejection response
2121 if ($response_id == 0) {
2122 $response .= stripcslashes($message);
2124 $response .= db_result(db_query("
2125 SELECT response_text
2126 FROM canned_responses
2127 WHERE response_id='$response_id'
2128 "), 0, "response_text");
2131 util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), $GLOBALS['sys_name']), $response);
2132 setup_gettext_from_browser () ;
2139 * sendNewProjectNotificationEmail - Send new project notification email.
2141 * This function sends out a notification email to the
2142 * SourceForge admin user when a new project is
2145 * @return boolean success.
2148 function sendNewProjectNotificationEmail() {
2150 $res = db_query("SELECT users.email, users.language, users.user_id
2151 FROM users,user_group
2153 AND user_group.admin_flags='A'
2154 AND users.user_id=user_group.user_id;");
2156 if (db_numrows($res) < 1) {
2157 $this->setError(_("There is no administrator to send the mail."));
2160 for ($i=0; $i<db_numrows($res) ; $i++) {
2161 $admin_email = db_result($res,$i,'email') ;
2162 $admin =& user_get_object(db_result($res,$i,'user_id'));
2163 setup_gettext_for_user ($admin) ;
2165 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2167 Project Full Name: %2$s
2168 Submitted Description: %3$s
2171 Please visit the following URL to approve or reject this project:
2172 http://%5$s/admin/approve-pending.php'), $GLOBALS['sys_name'], $this->getPublicName(), util_unconvert_htmlspecialchars($this->getRegistrationPurpose()), $this->getLicenseName(), $GLOBALS['sys_default_domain']));
2173 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2174 setup_gettext_from_browser () ;
2178 // Get the email of the user who wants to register the project
2179 $res = db_query("SELECT u.email, u.language, u.user_id
2180 FROM users u, user_group ug
2181 WHERE ug.group_id='".$this->getID()."' AND u.user_id=ug.user_id;");
2183 if (db_numrows($res) < 1) {
2184 $this->setError(_("Cound not find user who has submitted the project."));
2187 for ($i=0; $i<db_numrows($res) ; $i++) {
2188 $email = db_result($res, $i, 'email');
2189 $user =& user_get_object(db_result($res,$i,'user_id'));
2190 setup_gettext_for_user ($user) ;
2192 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2194 Project Full Name: %2$s
2195 Submitted Description: %3$s
2198 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']));
2200 util_send_message($email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2201 setup_gettext_from_browser () ;
2211 * group_getname() - get the group name
2213 * @param int The group ID
2217 function group_getname ($group_id = 0) {
2218 $grp = &group_get_object($group_id);
2220 return $grp->getPublicName();
2227 * group_getunixname() - get the unixname for a group
2229 * @param int The group ID
2233 function group_getunixname ($group_id) {
2234 $grp = &group_get_object($group_id);
2236 return $grp->getUnixName();
2243 * group_get_result() - Get the group object result ID.
2245 * @param int The group ID
2249 function &group_get_result($group_id=0) {
2250 $grp = &group_get_object($group_id);
2252 return $grp->getData();
2259 * getUnixStatus - Status of activation of unix account.
2261 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2263 function getUnixStatus() {
2264 return $this->data_array['unix_status'];
2268 * setUnixStatus - Sets status of activation of unix account.
2270 * @param string The unix status.
2276 * @return boolean success.
2278 function setUnixStatus($status) {
2283 SET unix_status='$status'
2284 WHERE group_id='". $this->getID()."'
2288 $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
2292 if ($status == 'A') {
2293 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2294 $this->setError($SYS->getErrorMessage());
2299 if ($SYS->sysCheckGroup($this->getID())) {
2300 if (!$SYS->sysRemoveGroup($this->getID())) {
2301 $this->setError($SYS->getErrorMessage());
2308 $this->data_array['unix_status']=$status;
2316 // c-file-style: "bsd"