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 $gfcommon.'tracker/ArtifactTypes.class.php';
38 require_once $gfcommon.'tracker/ArtifactTypeFactory.class.php';
39 require_once $gfcommon.'forum/Forum.class.php';
40 require_once $gfcommon.'forum/ForumFactory.class.php';
41 require_once $gfcommon.'pm/ProjectGroup.class.php';
42 require_once $gfcommon.'pm/ProjectGroupFactory.class.php';
43 require_once $gfcommon.'include/Role.class.php';
44 require_once $gfcommon.'frs/FRSPackage.class.php';
45 require_once $gfcommon.'docman/DocumentGroup.class.php';
46 require_once $gfcommon.'mail/MailingList.class.php';
47 require_once $gfcommon.'mail/MailingListFactory.class.php';
48 require_once $gfcommon.'survey/SurveyFactory.class.php';
49 require_once $gfcommon.'survey/SurveyQuestionFactory.class.php';
50 require_once $gfcommon.'include/gettext.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', $is_public=1) {
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);
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)."',
361 '".md5($random_num)."'
365 if (!$res || db_affected_rows($res) < 1) {
366 $this->setError(sprintf(_('ERROR: Could not create group: %s'),db_error()));
371 $id = db_insertid($res, 'groups', 'group_id');
373 $this->setError(sprintf(_('ERROR: Could not get group id: %s'),db_error()));
379 // Now, make the user an admin
381 $sql="INSERT INTO user_group ( user_id, group_id, admin_flags,
382 cvs_flags, artifact_flags, forum_flags, role_id)
383 VALUES ( ".$user->getID().", '$id', 'A', 1, 2, 2, 1)";
386 if (!$res || db_affected_rows($res) < 1) {
387 $this->setError(sprintf(_('ERROR: Could not add admin to newly created group: %s'),db_error()));
392 if (!$this->fetchData($id)) {
397 $hook_params = array ();
398 $hook_params['group'] = $this;
399 $hook_params['group_id'] = $this->getID();
400 $hook_params['group_name'] = $full_name;
401 $hook_params['unix_group_name'] = $unix_name;
402 plugin_hook ("group_create", $hook_params);
405 $this->sendNewProjectNotificationEmail();
412 * updateAdmin - Update core properties of group object.
414 * This function require site admin privilege.
416 * @param object User requesting operation (for access control).
417 * @param bool Whether group is publicly accessible (0/1).
418 * @param string Project's license (string ident).
419 * @param int Group type (1-project, 2-foundry).
420 * @param string Machine on which group's home directory located.
421 * @param string Domain which serves group's WWW.
425 function updateAdmin(&$user, $is_public, $license, $type_id, $unix_box, $http_domain) {
426 $perm =& $this->getPermission($user);
428 if (!$perm || !is_object($perm)) {
429 $this->setError(_('Could not get permission.'));
433 if (!$perm->isSuperUser()) {
434 $this->setError(_('Permission denied.'));
442 SET is_public='$is_public',
443 license='$license',type_id='$type_id',
444 unix_box='$unix_box',http_domain='$http_domain'
445 WHERE group_id='".$this->getID()."'
448 if (!$res || db_affected_rows($res) < 1) {
449 $this->setError(_('ERROR: DB: Could not change group properties: %s'),db_error());
454 // Log the audit trail
455 if ($is_public != $this->isPublic()) {
456 $this->addHistory('is_public', $this->isPublic());
458 if ($license != $this->data_array['license']) {
459 $this->addHistory('license', $this->data_array['license']);
461 if ($type_id != $this->data_array['type_id']) {
462 $this->addHistory('type_id', $this->data_array['type_id']);
464 if ($unix_box != $this->data_array['unix_box']) {
465 $this->addHistory('unix_box', $this->data_array['unix_box']);
467 if ($http_domain != $this->data_array['http_domain']) {
468 $this->addHistory('http_domain', $this->data_array['http_domain']);
471 if (!$this->fetchData($this->getID())) {
480 * update - Update number of common properties.
482 * Unlike updateAdmin(), this function accessible to project admin.
484 * @param object User requesting operation (for access control).
485 * @param bool Whether group is publicly accessible (0/1).
486 * @param string Project's license (string ident).
487 * @param int Group type (1-project, 2-foundry).
488 * @param string Machine on which group's home directory located.
489 * @param string Domain which serves group's WWW.
490 * @return int status.
493 function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,
494 $use_pm,$use_pm_depend_box,$use_scm,$use_news,$use_docman,
495 $new_doc_address,$send_all_docs,$logo_image_id,
496 $enable_pserver,$enable_anonscm,
497 $use_ftp,$use_tracker,$use_frs,$use_stats,$is_public) {
499 $perm =& $this->getPermission($user);
501 if (!$perm || !is_object($perm)) {
502 $this->setError(_('Could not get permission.'));
506 if (!$perm->isAdmin()) {
507 $this->setError(_('Permission denied.'));
511 // Validate some values
513 $this->setError(_('Invalid Group Name'));
517 if ($new_doc_address) {
518 $invalid_mails = validate_emails($new_doc_address);
519 if (count($invalid_mails) > 0) {
520 $this->setError(sprintf (ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
525 // in the database, these all default to '1',
526 // so we have to explicity set 0
539 if (!$use_pm_depend_box) {
540 $use_pm_depend_box=0;
563 if (!$send_all_docs) {
568 $homepage=$GLOBALS['sys_default_domain'].'/projects/'.$this->getUnixName().'/';
571 if (strlen($short_description)>255) {
572 $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
578 //XXX not yet actived logo_image_id='$logo_image_id',
582 group_name='".htmlspecialchars($group_name)."',
583 homepage='$homepage',
584 short_description='".htmlspecialchars($short_description)."',
585 use_mail='$use_mail',
586 use_survey='$use_survey',
587 use_forum='$use_forum',
589 use_pm_depend_box='$use_pm_depend_box',
591 use_news='$use_news',
592 use_docman='$use_docman',
593 is_public='$is_public',
594 new_doc_address='$new_doc_address',
595 send_all_docs='$send_all_docs',
597 if ($enable_pserver != '') {
599 enable_pserver='$enable_pserver',
602 if ($enable_anonscm != '') {
604 enable_anonscm='$enable_anonscm',
609 use_tracker='$use_tracker',
611 use_stats='$use_stats'
612 WHERE group_id='".$this->getID()."'
614 $res = db_query($sql);
617 $this->setError(sprintf(_('Error updating project information: %s'), db_error()));
622 $hook_params = array ();
623 $hook_params['group'] = $this;
624 $hook_params['group_id'] = $this->getID();
625 $hook_params['group_homepage'] = $homepage;
626 $hook_params['group_name'] = htmlspecialchars($group_name);
627 $hook_params['group_description'] = htmlspecialchars($short_description);
628 plugin_hook ("group_update", $hook_params);
630 // Log the audit trail
631 $this->addHistory('Changed Public Info', '');
633 if (!$this->fetchData($this->getID())) {
642 * getID - Simply return the group_id for this object.
644 * @return int group_id.
647 return $this->data_array['group_id'];
651 * getType() - Foundry, project, etc.
653 * @return int The type flag from the database.
656 return $this->data_array['type_id'];
661 * getStatus - the status code.
663 * Statuses char include I,H,A,D.
665 function getStatus() {
666 return $this->data_array['status'];
670 * setStatus - set the status code.
672 * Statuses include I,H,A,D.
674 * @param object User requesting operation (for access control).
675 * @param string Status value.
676 * @return boolean success.
679 function setStatus(&$user, $status) {
682 $perm =& $this->getPermission($user);
683 if (!$perm || !is_object($perm)) {
684 $this->setPermissionDeniedError();
686 } elseif (!$perm->isSuperUser()) {
687 $this->setPermissionDeniedError();
691 // Projects in 'A' status can only go to 'H' or 'D'
692 // Projects in 'D' status can only go to 'A'
693 // Projects in 'P' status can only go to 'A' OR 'D'
694 // Projects in 'I' status can only go to 'P'
695 // Projects in 'H' status can only go to 'A' OR 'D'
696 $allowed_status_changes = array(
697 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
698 'IP'=>1,'HA'=>1,'HD'=>1
701 // Check that status transition is valid
702 if ($this->getStatus() != $status
703 && !$allowed_status_changes[$this->getStatus().$status]) {
704 $this->setError(_('Invalid Status Change'));
710 $res = db_query("UPDATE groups
712 WHERE group_id='". $this->getID()."'");
714 if (!$res || db_affected_rows($res) < 1) {
715 $this->setError(sprintf(_('ERROR: DB: Could not change group status: %s'),db_error()));
721 // Activate system group, if not yet
722 if (!$SYS->sysCheckGroup($this->getID())) {
723 if (!$SYS->sysCreateGroup($this->getID())) {
724 $this->setError($SYS->getErrorMessage());
729 if (!$this->activateUsers()) {
734 /* Otherwise, the group is not active, and make sure that
735 System group is not active either */
736 } else if ($SYS->sysCheckGroup($this->getID())) {
737 if (!$SYS->sysRemoveGroup($this->getID())) {
738 $this->setError($SYS->getErrorMessage());
744 $hook_params = array ();
745 $hook_params['group'] = $this;
746 $hook_params['group_id'] = $this->getID();
747 $hook_params['status'] = $status;
748 plugin_hook ("group_setstatus", $hook_params);
752 // Log the audit trail
753 if ($status != $this->getStatus()) {
754 $this->addHistory('Status', $this->getStatus());
757 $this->data_array['status'] = $status;
762 * isProject - Simple boolean test to see if it's a project or not.
764 * @return boolean is_project.
766 function isProject() {
767 if ($this->getType()==1) {
775 * isPublic - Simply returns the is_public flag from the database.
777 * @return boolean is_public.
779 function isPublic() {
780 return $this->data_array['is_public'];
784 * isActive - Database field status of 'A' returns true.
786 * @return boolean is_active.
788 function isActive() {
789 if ($this->getStatus()=='A') {
797 * getUnixName - the unix_name
799 * @return string unix_name.
801 function getUnixName() {
802 return strtolower($this->data_array['unix_group_name']);
806 * getPublicName - the full-length public name.
808 * @return string The group_name.
810 function getPublicName() {
811 return $this->data_array['group_name'];
815 * getRegisterPurpose - the text description of the purpose of this project.
817 * @return string The description.
819 function getRegisterPurpose() {
820 return $this->data_array['register_purpose'];
824 * getDescription - the text description of this project.
826 * @return string The description.
828 function getDescription() {
829 return $this->data_array['short_description'];
833 * getStartDate - the unix time this project was registered.
835 * @return int (unix time) of registration.
837 function getStartDate() {
838 return $this->data_array['register_time'];
842 * getLogoImageID - the id of the logo in the database for this project.
844 * @return int The ID of logo image in db_images table (or 100 if none).
846 function getLogoImageID() {
847 return $this->data_array['logo_image_id'];
851 * getUnixBox - the hostname of the unix box where this project is located.
853 * @return string The name of the unix machine for the group.
855 function getUnixBox() {
856 return $this->data_array['unix_box'];
860 * getSCMBox - the hostname of the scm box where this project is located.
862 * @return string The name of the unix machine for the group.
864 function getSCMBox() {
865 return $this->data_array['scm_box'];
868 * setSCMBox - the hostname of the scm box where this project is located.
870 * @param string The name of the new SCM_BOX
872 function setSCMBox($scm_box) {
875 $sql = "UPDATE groups SET scm_box = '$scm_box' WHERE group_id = ".$this->getID();
876 $res = db_query($sql);
878 $this->addHistory('scm_box', $this->data_array['scm_box']);
879 $this->data_array['scm_box']=$scm_box;
884 $this->setError(_("Couldn't insert SCM_BOX to database"));
888 $this->setError(_("SCM Box can't be empty"));
894 * getDomain - the hostname.domain where their web page is located.
896 * @return string The name of the group [web] domain.
898 function getDomain() {
899 return $this->data_array['http_domain'];
903 * getLicense - the license they chose.
905 * @return int ident of group license.
907 function getLicense() {
908 return $this->data_array['license'];
912 * getLicenseName - the name of the license
914 * @return string license name
916 function getLicenseName() {
917 $licenses =& group_get_licenses();
918 if(isset($licenses[$this->data_array['license']])) {
919 return $licenses[$this->data_array['license']];
926 * getLicenseOther - optional string describing license.
928 * @return string The custom license.
930 function getLicenseOther() {
931 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
932 return $this->data_array['license_other'];
939 * getRegistrationPurpose - the text description of the purpose of this project.
941 * @return string The application for project hosting.
943 function getRegistrationPurpose() {
944 return $this->data_array['register_purpose'];
949 * getAdmins() - Get array of Admin user objects.
951 * @return array Array of User objects.
953 function &getAdmins() {
954 // this function gets all group admins in order to send Jabber and mail messages
955 $q = "SELECT user_id FROM user_group WHERE admin_flags = 'A' AND group_id = ".$this->getID();
957 $user_ids=util_result_column_to_array($res);
958 return user_get_objects($user_ids);
963 Common Group preferences for tools
968 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
970 * @return boolean enable_scm.
972 function enableAnonSCM() {
973 if ($this->isPublic() && $this->usesSCM()) {
974 return $this->data_array['enable_anonscm'];
980 function SetUsesAnonSCM ($booleanparam) {
982 $booleanparam = $booleanparam ? 1 : 0 ;
983 $sql = "UPDATE groups SET enable_anonscm = $booleanparam WHERE group_id = ".$this->getID() ;
984 $res = db_query($sql);
986 $this->data_array['enable_anonscm']=$booleanparam;
995 * enablePserver - whether or not this group has opted to enable Pserver.
997 * @return boolean enable_pserver.
999 function enablePserver() {
1000 if ($this->usesSCM()) {
1001 return $this->data_array['enable_pserver'];
1007 function SetUsesPserver ($booleanparam) {
1009 $booleanparam = $booleanparam ? 1 : 0 ;
1010 $sql = "UPDATE groups SET enable_pserver = $booleanparam WHERE group_id = ".$this->getID() ;
1011 $res = db_query($sql);
1013 $this->data_array['enable_pserver']=$booleanparam;
1022 * usesSCM - whether or not this group has opted to use SCM.
1024 * @return boolean uses_scm.
1026 function usesSCM() {
1027 global $sys_use_scm;
1029 return $this->data_array['use_scm'];
1036 * usesMail - whether or not this group has opted to use mailing lists.
1038 * @return boolean uses_mail.
1040 function usesMail() {
1041 global $sys_use_mail;
1042 if ($sys_use_mail) {
1043 return $this->data_array['use_mail'];
1050 * usesNews - whether or not this group has opted to use news.
1052 * @return boolean uses_news.
1054 function usesNews() {
1055 global $sys_use_news;
1056 if ($sys_use_news) {
1057 return $this->data_array['use_news'];
1064 * usesForum - whether or not this group has opted to use discussion forums.
1066 * @return boolean uses_forum.
1068 function usesForum() {
1069 global $sys_use_forum;
1070 if ($sys_use_forum) {
1071 return $this->data_array['use_forum'];
1078 * usesStats - whether or not this group has opted to use stats.
1080 * @return boolean uses_stats.
1082 function usesStats() {
1083 return $this->data_array['use_stats'];
1087 * usesFRS - whether or not this group has opted to use file release system.
1089 * @return boolean uses_frs.
1091 function usesFRS() {
1092 global $sys_use_frs;
1094 return $this->data_array['use_frs'];
1101 * usesTracker - whether or not this group has opted to use tracker.
1103 * @return boolean uses_tracker.
1105 function usesTracker() {
1106 global $sys_use_tracker;
1107 if ($sys_use_tracker) {
1108 return $this->data_array['use_tracker'];
1115 * usesDocman - whether or not this group has opted to use docman.
1117 * @return boolean uses_docman.
1119 function usesDocman() {
1120 global $sys_use_docman;
1121 if ($sys_use_docman) {
1122 return $this->data_array['use_docman'];
1129 * usesFTP - whether or not this group has opted to use FTP.
1131 * @return boolean uses_ftp.
1133 function usesFTP() {
1134 global $sys_use_ftp;
1136 return $this->data_array['use_ftp'];
1143 * usesSurvey - whether or not this group has opted to use surveys.
1145 * @return boolean uses_survey.
1147 function usesSurvey() {
1148 global $sys_use_survey;
1149 if ($sys_use_survey) {
1150 return $this->data_array['use_survey'];
1157 * usesPM - whether or not this group has opted to Project Manager.
1159 * @return boolean uses_projman.
1164 return $this->data_array['use_pm'];
1171 * getPlugins - get a list of all available group plugins
1173 * @return array array containing plugin_id => plugin_name
1175 function getPlugins() {
1176 if (!isset($this->plugins_data)) {
1177 $this->plugins_data = array () ;
1178 $sql="SELECT group_plugin.plugin_id, plugins.plugin_name
1179 FROM group_plugin, plugins
1180 WHERE group_plugin.group_id=".$this->getID()."
1181 AND group_plugin.plugin_id = plugins.plugin_id" ;
1182 $res=db_query($sql);
1183 $rows = db_numrows($res);
1185 for ($i=0; $i<$rows; $i++) {
1186 $plugin_id = db_result($res,$i,'plugin_id');
1187 $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
1190 return $this->plugins_data ;
1194 * usesPlugin - returns true if the group uses a particular plugin
1196 * @param string name of the plugin
1197 * @return boolean whether plugin is being used or not
1199 function usesPlugin($pluginname) {
1200 $plugins_data = $this->getPlugins() ;
1201 foreach ($plugins_data as $p_id => $p_name) {
1202 if ($p_name == $pluginname) {
1210 * setPluginUse - enables/disables plugins for the group
1212 * @param string name of the plugin
1213 * @param boolean the new state
1214 * @return string database result
1216 function setPluginUse($pluginname, $val=true) {
1217 if ($val == $this->usesPlugin($pluginname)) {
1218 // State is already good, returning
1221 $sql="SELECT plugin_id
1223 WHERE plugin_name = '" . $pluginname . "'" ;
1224 $res=db_query($sql);
1225 $rows = db_numrows($res);
1227 // Error: no plugin by that name
1230 $plugin_id = db_result($res,0,'plugin_id');
1232 unset ($this->plugins_data) ;
1234 $sql="INSERT INTO group_plugin (group_id, plugin_id)
1235 VALUES (". $this->getID() . ", ". $plugin_id .")" ;
1236 $res=db_query($sql);
1239 $sql="DELETE FROM group_plugin
1240 WHERE group_id = ". $this->getID() . "
1241 AND plugin_id = ". $plugin_id ;
1242 $res=db_query($sql);
1248 * getDocEmailAddress - get email address(es) to send doc notifications to.
1250 * @return string email address.
1252 function getDocEmailAddress() {
1253 return $this->data_array['new_doc_address'];
1257 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1259 * @return boolean email_on_all_doc_updates.
1261 function docEmailAll() {
1262 return $this->data_array['send_all_docs'];
1267 * getHomePage - The URL for this project's home page.
1269 * @return string homepage URL.
1271 function getHomePage() {
1272 return $this->data_array['homepage'];
1276 * getPermission - Return a Permission for this Group and the specified User.
1278 * @param object The user you wish to get permission for (usually the logged in user).
1279 * @return object The Permission.
1281 function &getPermission(&$_user) {
1282 return permission_get_object($this, $_user);
1287 * userIsAdmin - Return if for this Group the User is admin.
1289 * @return boolean is_admin.
1291 function userIsAdmin() {
1292 $perm =& $this->getPermission( session_get_user() );
1293 if (!$perm || !is_object($perm)) {
1295 } elseif ($perm->isError()) {
1298 return $perm->isAdmin();
1301 function delete($sure,$really_sure,$really_really_sure) {
1302 if (!$sure || !$really_sure || !$really_really_sure) {
1303 $this->setMissingParamsError();
1306 if ($this->getID() == $GLOBALS['sys_news_group'] ||
1307 $this->getID() == 1 ||
1308 $this->getID() == $GLOBALS['sys_stats_group'] ||
1309 $this->getID() == $GLOBALS['sys_peer_rating_group']) {
1310 $this->setError(_('Cannot Delete System Group'));
1313 $perm =& $this->getPermission( session_get_user() );
1314 if (!$perm || !is_object($perm)) {
1315 $this->setPermissionDeniedError();
1317 } elseif ($perm->isError()) {
1318 $this->setPermissionDeniedError();
1320 } elseif (!$perm->isSuperUser()) {
1321 $this->setPermissionDeniedError();
1327 // Remove all the members
1329 $members =& $this->getMembers();
1330 for ($i=0; $i<count($members); $i++) {
1331 $this->removeUser($members[$i]->getID());
1336 $atf = new ArtifactTypeFactory($this);
1337 $at_arr =& $atf->getArtifactTypes();
1338 for ($i=0; $i<count($at_arr); $i++) {
1339 if (!is_object($at_arr[$i])) {
1340 printf (_("Not Object: ArtifactType: %d"),$i);
1343 $at_arr[$i]->delete(1,1);
1348 $ff = new ForumFactory($this);
1349 $f_arr =& $ff->getForums();
1350 for ($i=0; $i<count($f_arr); $i++) {
1351 if (!is_object($f_arr[$i])) {
1352 printf (_("Not Object: Forum: %d"),$i);
1355 $f_arr[$i]->delete(1,1);
1356 //echo 'ForumFactory'.db_error();
1359 // Delete Subprojects
1361 $pgf = new ProjectGroupFactory($this);
1362 $pg_arr =& $pgf->getProjectGroups();
1363 for ($i=0; $i<count($pg_arr); $i++) {
1364 if (!is_object($pg_arr[$i])) {
1365 printf (_("Not Object: ProjectGroup: %d"),$i);
1368 $pg_arr[$i]->delete(1,1);
1369 //echo 'ProjectGroupFactory'.db_error();
1372 // Delete FRS Packages
1374 //$frspf = new FRSPackageFactory($this);
1375 $res=db_query("SELECT * FROM frs_package WHERE group_id='".$this->getID()."'");
1376 //echo 'frs_package'.db_error();
1377 //$frsp_arr =& $frspf->getPackages();
1378 while ($arr = db_fetch_array($res)) {
1379 //if (!is_object($pg_arr[$i])) {
1380 // echo "Not Object: ProjectGroup: ".$i;
1383 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1389 $news_group=&group_get_object($GLOBALS['sys_news_group']);
1390 $res=db_query("SELECT forum_id FROM news_bytes WHERE group_id='".$this->getID()."'");
1391 for ($i=0; $i<db_numrows($res); $i++) {
1392 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1393 if (!$Forum->delete(1,1)) {
1394 printf (_("Could Not Delete News Forum: %d"),$Forum->getID());
1397 $res=db_query("DELETE FROM news_bytes WHERE group_id='".$this->getID()."'");
1402 $res=db_query("DELETE FROM doc_data WHERE group_id='".$this->getID()."'");
1403 //echo 'doc_data'.db_error();
1404 $res=db_query("DELETE FROM doc_groups WHERE group_id='".$this->getID()."'");
1405 //echo 'doc_groups'.db_error();
1407 // Delete group history
1409 $res=db_query("DELETE FROM group_history WHERE group_id='".$this->getID()."'");
1410 //echo 'group_history'.db_error();
1412 // Delete group plugins
1414 $res=db_query("DELETE FROM group_plugin WHERE group_id='".$this->getID()."'");
1415 //echo 'group_plugin'.db_error();
1417 // Delete group cvs stats
1419 $res=db_query("DELETE FROM stats_cvs_group WHERE group_id='".$this->getID()."'");
1420 //echo 'stats_cvs_group'.db_error();
1424 $sf = new SurveyFactory($this);
1425 $s_arr =& $sf->getSurveys();
1426 for ($i=0; $i<count($s_arr); $i++) {
1427 if (!is_object($s_arr[$i])) {
1428 printf (_("Not Object: Survey: %d"),$i);
1431 $s_arr[$i]->delete();
1432 //echo 'SurveyFactory'.db_error();
1435 // Delete SurveyQuestions
1437 $sqf = new SurveyQuestionFactory($this);
1438 $sq_arr =& $sqf->getSurveyQuestions();
1439 for ($i=0; $i<count($sq_arr); $i++) {
1440 if (!is_object($sq_arr[$i])) {
1441 printf (_("Not Object: SurveyQuestion: %d"),$i);
1444 $sq_arr[$i]->delete();
1445 //echo 'SurveyQuestionFactory'.db_error();
1448 // Delete Mailing List Factory
1450 $mlf = new MailingListFactory($this);
1451 $ml_arr =& $mlf->getMailingLists();
1452 for ($i=0; $i<count($ml_arr); $i++) {
1453 if (!is_object($ml_arr[$i])) {
1454 printf (_("Not Object: MailingList: %d"),$i);
1457 if (!$ml_arr[$i]->delete(1,1)) {
1458 $this->setError(_('Could not properly delete the mailing list'));
1460 //echo 'MailingListFactory'.db_error();
1465 $res=db_query("DELETE FROM trove_group_link WHERE group_id='".$this->getID()."'");
1466 $res=db_query("DELETE FROM trove_agg WHERE group_id='".$this->getID()."'");
1470 $res=db_query("DELETE FROM project_sums_agg WHERE group_id='".$this->getID()."'");
1471 //echo 'project_sums_agg'.db_error();
1472 $res=db_query("INSERT INTO deleted_groups (
1473 unix_group_name,delete_date,isdeleted) VALUES
1474 ('".$this->getUnixName()."','".time()."','0')");
1475 //echo 'InsertIntoDeleteQueue'.db_error();
1476 $res=db_query("DELETE FROM groups WHERE group_id='".$this->getID()."'");
1477 //echo 'DeleteGroup'.db_error();
1483 $hook_params = array ();
1484 $hook_params['group'] = $this;
1485 $hook_params['group_id'] = $this->getID();
1486 plugin_hook ("group_delete", $hook_params);
1488 if (isset($GLOBALS['sys_upload_dir']) && $this->getUnixName()) {
1489 exec('/bin/rm -rf '.$GLOBALS['sys_upload_dir'].'/'.$this->getUnixName().'/');
1491 if (isset($GLOBALS['sys_ftp_upload_dir']) && $this->getUnixName()) {
1492 exec('/bin/rm -rf '.$GLOBALS['sys_ftp_upload_dir'].'/'.$this->getUnixName().'/');
1497 $res=db_query("DELETE FROM rep_group_act_weekly WHERE group_id='".$this->getID()."'");
1498 //echo 'rep_group_act_weekly'.db_error();
1499 $res=db_query("DELETE FROM rep_group_act_monthly WHERE group_id='".$this->getID()."'");
1500 //echo 'rep_group_act_monthly'.db_error();
1501 $res=db_query("DELETE FROM rep_group_act_daily WHERE group_id='".$this->getID()."'");
1502 //echo 'rep_group_act_daily'.db_error();
1503 unset($this->data_array);
1511 Basic functions to add/remove users to/from a group
1512 and update their permissions
1518 * addUser - controls adding a user to a group.
1520 * @param string Unix name of the user to add OR integer user_id.
1521 * @param int The role_id this user should have.
1522 * @return boolean success.
1525 function addUser($user_unix_name,$role_id) {
1528 Admins can add users to groups
1531 $perm =& $this->getPermission( session_get_user() );
1532 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1533 $this->setPermissionDeniedError();
1539 get user id for this user's unix_name
1541 if (eregi('[^0-9]',$user_unix_name)) {
1542 $res_newuser = db_query("SELECT * FROM users WHERE user_name='". strtolower($user_unix_name) ."'");
1544 $res_newuser = db_query("SELECT * FROM users WHERE user_id='". intval($user_unix_name) ."'");
1546 if (db_numrows($res_newuser) > 0) {
1548 // make sure user is active
1550 if (db_result($res_newuser,0,'status') != 'A') {
1551 $this->setError(_('User is not active. Only active users can be added.'));
1557 // user was found - set new user_id var
1559 $user_id = db_result($res_newuser,0,'user_id');
1562 // if not already a member, add them
1564 $res_member = db_query("SELECT user_id
1566 WHERE user_id='$user_id' AND group_id='". $this->getID() ."'");
1568 if (db_numrows($res_member) < 1) {
1570 // Create this user's row in the user_group table
1572 $res=db_query("INSERT INTO user_group
1573 (user_id,group_id,admin_flags,forum_flags,project_flags,
1574 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
1575 VALUES ('$user_id','". $this->getID() ."','','0','0','0','1','100','0','0')");
1577 //verify the insert worked
1578 if (!$res || db_affected_rows($res) < 1) {
1579 $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
1584 // check and create if group doesn't exists
1586 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
1587 if (!$SYS->sysCheckCreateGroup($this->getID())){
1588 $this->setError($SYS->getErrorMessage());
1593 // check and create if user doesn't exists
1595 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1596 if (!$SYS->sysCheckCreateUser($user_id)) {
1597 $this->setError($SYS->getErrorMessage());
1604 $role = new Role($this,$role_id);
1605 if (!$role || !is_object($role)) {
1606 $this->setError(_('Error Getting Role Object'));
1609 } elseif ($role->isError()) {
1610 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1614 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
1615 if (!$role->setUser($user_id)) {
1616 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1622 // user was already a member
1623 // make sure they are set up
1625 $user=&user_get_object($user_id,$res_newuser);
1626 $user->fetchData($user->getID());
1627 $role = new Role($this,$role_id);
1628 if (!$role || !is_object($role)) {
1629 $this->setError(_('Error Getting Role Object'));
1632 } elseif ($role->isError()) {
1633 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1637 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
1638 if (!$role->setUser($user_id)) {
1639 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1644 // set up their system info
1646 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1647 if (!$SYS->sysCheckCreateUser($user_id)) {
1648 $this->setError($SYS->getErrorMessage());
1657 // user doesn't exist
1659 $this->setError(_('ERROR: User does not exist'));
1664 $hook_params['group'] = $this;
1665 $hook_params['group_id'] = $this->getID();
1666 $hook_params['user'] = &user_get_object($user_id);
1667 $hook_params['user_id'] = $user_id;
1668 plugin_hook ("group_adduser", $hook_params);
1673 $this->addHistory('Added User',$user_unix_name);
1679 * removeUser - controls removing a user from a group.
1681 * Users can remove themselves.
1683 * @param int The ID of the user to remove.
1684 * @return boolean success.
1686 function removeUser($user_id) {
1687 global $SYS,$sys_database_type;
1689 if ($user_id==user_getid()) {
1690 //users can remove themselves
1691 //everyone else must be a project admin
1693 $perm =& $this->getPermission( session_get_user() );
1695 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1696 $this->setPermissionDeniedError();
1702 $res=db_query("DELETE FROM user_group
1703 WHERE group_id='".$this->getID()."'
1704 AND user_id='$user_id'");
1705 if (!$res || db_affected_rows($res) < 1) {
1706 $this->setError(sprintf(_('ERROR: User not removed: %s'),db_error()));
1711 // reassign open artifacts to id=100
1713 $res=db_query("UPDATE artifact SET assigned_to='100'
1714 WHERE group_artifact_id
1715 IN (SELECT group_artifact_id
1716 FROM artifact_group_list
1717 WHERE group_id='".$this->getID()."')
1718 AND status_id='1' AND assigned_to='$user_id'");
1720 $this->setError(sprintf(_('ERROR: DB: artifact: %s'),db_error()));
1726 // reassign open tasks to id=100
1727 // first have to purge any assignments that would cause
1728 // conflict with existing assignment to 100
1730 if ($sys_database_type == 'mysql') {
1732 SELECT pt.project_task_id
1733 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1734 WHERE pt.group_project_id = pgl.group_project_id
1735 AND pat.project_task_id=pt.project_task_id
1736 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."'
1737 AND pat.assigned_to_id='$user_id' INTO @task_list;
1738 DELETE FROM project_assigned_to WHERE project_task_id IN ( @task_list ) AND assigned_to_id='100'");
1740 $res = db_next_result();
1743 $res=db_query("DELETE FROM project_assigned_to
1744 WHERE project_task_id IN (SELECT pt.project_task_id
1745 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1746 WHERE pt.group_project_id = pgl.group_project_id
1747 AND pat.project_task_id=pt.project_task_id
1748 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."'
1749 AND pat.assigned_to_id='$user_id')
1750 AND assigned_to_id='100'");
1753 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),1,db_error()));
1757 $res=db_query("UPDATE project_assigned_to SET assigned_to_id='100'
1758 WHERE project_task_id IN (SELECT pt.project_task_id
1759 FROM project_task pt, project_group_list pgl
1760 WHERE pt.group_project_id = pgl.group_project_id
1761 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."')
1762 AND assigned_to_id='$user_id'");
1764 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),2,db_error()));
1770 // Remove user from system
1772 //echo "<h2>Group::addUser SYS->sysGroupRemoveUser(".$this->getID().",$user_id)</h2>";
1773 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
1774 $this->setError($SYS->getErrorMessage());
1779 $this->addHistory('Removed User',$user_id);
1786 * updateUser - controls updating a user's role in this group.
1788 * @param int The ID of the user.
1789 * @param int The role_id to set this user to.
1790 * @return boolean success.
1792 function updateUser($user_id,$role_id) {
1795 $perm =& $this->getPermission( session_get_user() );
1796 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1797 $this->setPermissionDeniedError();
1801 $role = new Role($this,$role_id);
1802 if (!$role || !is_object($role)) {
1803 $this->setError(_('Could Not Get Role'));
1805 } elseif ($role->isError()) {
1806 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1809 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
1810 if (!$role->setUser($user_id)) {
1811 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1815 $hook_params['group'] = $this;
1816 $hook_params['group_id'] = $this->getID();
1817 $hook_params['user'] = &user_get_object($user_id);
1818 $hook_params['user_id'] = $user_id;
1819 plugin_hook ("group_removeuser", $hook_params);
1821 $this->addHistory('Updated User',$user_id);
1826 * addHistory - Makes an audit trail entry for this project.
1828 * @param string The name of the field.
1829 * @param string The Old Value for this $field_name.
1830 * @return database result handle.
1833 function addHistory($field_name, $old_value) {
1835 INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
1836 VALUES ('". $this->getID() ."','$field_name','$old_value','". user_getid() ."','".time()."')
1838 return db_query($sql);
1842 * activateUsers - Make sure that group members have unix accounts.
1844 * Setup unix accounts for group members. Can be called even
1845 * if members are already active.
1849 function activateUsers() {
1852 Activate member(s) of the project
1855 $member_res = db_query("SELECT user_id, role_id
1857 WHERE group_id='".$this->getID()."'");
1859 $rows = db_numrows($member_res);
1863 for ($i=0; $i<$rows; $i++) {
1865 $member =& user_get_object(db_result($member_res,$i,'user_id'));
1866 $roleId = db_result($member_res,$i,'role_id');
1868 if (!$member || !is_object($member)) {
1869 $this->setError(_('Error getting member object'));
1871 } else if ($member->isError()) {
1872 $this->setError(sprintf(_('Error getting member object: %s'),$member->getErrorMessage()));
1876 if (!$this->addUser($member->getUnixName(),$roleId)) {
1887 * getMembers - returns array of User objects for this project
1889 * @return array of User objects for this group.
1891 function &getMembers() {
1892 if (!isset($this->membersArr)) {
1893 $res=db_query("SELECT users.* FROM users
1894 INNER JOIN user_group ON users.user_id=user_group.user_id
1895 WHERE user_group.group_id='".$this->getID()."'");
1896 while ($arr =& db_fetch_array($res)) {
1897 $this->membersArr[] =& new GFUser($arr['user_id'],$arr);
1900 return $this->membersArr;
1904 * approve - Approve pending project.
1906 * @param object The User object who is doing the updating.
1909 function approve(&$user) {
1911 if ($this->getStatus()=='A') {
1912 $this->setError(_("Group already active"));
1918 // Step 1: Activate group and create LDAP entries
1919 if (!$this->setStatus($user, 'A')) {
1926 // Tracker Integration
1929 $ats = new ArtifactTypes($this);
1930 if (!$ats || !is_object($ats)) {
1931 $this->setError(_('Error creating ArtifactTypes object'));
1934 } else if ($ats->isError()) {
1935 $this->setError(sprintf (_('ATS%d: %s'), 1, $ats->getErrorMessage()));
1939 if (!$ats->createTrackers()) {
1940 $this->setError(sprintf (_('ATS%d: %s'), 2, $ats->getErrorMessage()));
1947 // Forum Integration
1950 $f = new Forum($this);
1951 if (!$f->create('Open-Discussion','General Discussion',1,'',1,0)) {
1952 $this->setError(sprintf (_('F%d: %s'), 1, $f->getErrorMessage()));
1956 $f = new Forum($this);
1957 if (!$f->create('Help','Get Public Help',1,'',1,0)) {
1958 $this->setError(sprintf (_('F%d: %s'), 2, $f->getErrorMessage()));
1962 $f = new Forum($this);
1963 if (!$f->create('Developers','Project Developer Discussion',0,'',1,0)) {
1964 $this->setError(sprintf (_('F%d: %s'), 3, $f->getErrorMessage()));
1971 // Doc Mgr Integration
1974 $dg = new DocumentGroup($this);
1975 if (!$dg->create('Uncategorized Submissions')) {
1976 $this->setError(sprintf(_('DG: %s'),$dg->getErrorMessage()));
1986 $frs = new FRSPackage($this);
1987 if (!$frs->create($this->getUnixName())) {
1988 $this->setError(sprintf(_('FRSP: %s'),$frs->getErrorMessage()));
1998 $pg = new ProjectGroup($this);
1999 if (!$pg->create('To Do','Things We Have To Do',1)) {
2000 $this->setError(sprintf(_('PG%d: %s'),1,$pg->getErrorMessage()));
2004 $pg = new ProjectGroup($this);
2005 if (!$pg->create('Next Release','Items For Our Next Release',1)) {
2006 $this->setError(sprintf(_('PG%d: %s'),2,$pg->getErrorMessage()));
2013 // Set Default Roles
2016 $role = new Role($this);
2017 $todo = array_keys($role->defaults);
2018 for ($c=0; $c<count($todo); $c++) {
2019 $role = new Role($this);
2020 if (!$role->createDefault($todo[$c])) {
2021 $this->setError(sprintf(_('R%d: %s'),$c,$role->getErrorMessage()));
2027 $admin_group = db_query("SELECT user_id FROM user_group
2028 WHERE group_id=".$this->getID()." AND admin_flags='A'");
2029 if (db_numrows($admin_group) > 0) {
2030 $idadmin_group = db_result($admin_group,0,'user_id');
2037 // Create MailingList
2040 if ($GLOBALS['sys_use_mail']) {
2041 $mlist = new MailingList($this);
2042 if (!$mlist->create('commits','Commits',1,$idadmin_group)) {
2043 $this->setError(sprintf(_('ML: %s'),$mlist->getErrorMessage()));
2051 $this->sendApprovalEmail();
2052 $this->addHistory('Approved', 'x');
2055 //change assistant for webcal
2057 $params[0] = $idadmin_group ;
2058 $params[1] = $this->getID();
2059 plugin_hook('change_cal_permission_default',$params);
2067 * sendApprovalEmail - Send new project email.
2069 * @return boolean success.
2072 function sendApprovalEmail() {
2073 $res_admins = db_query("
2074 SELECT users.user_name,users.email,users.language,users.user_id
2075 FROM users,user_group
2076 WHERE users.user_id=user_group.user_id
2077 AND user_group.group_id='".$this->getID()."'
2078 AND user_group.admin_flags='A'
2081 if (db_numrows($res_admins) < 1) {
2082 $this->setError(_("Group does not have any administrators."));
2086 // send one email per admin
2087 while ($row_admins = db_fetch_array($res_admins)) {
2088 $admin =& user_get_object($row_admins['user_id']);
2089 setup_gettext_for_user ($admin) ;
2091 $message=stripcslashes(sprintf(_('Your project registration for %4$s has been approved.
2093 Project Full Name: %1$s
2094 Project Unix Name: %2$s
2096 Your DNS will take up to a day to become active on our site.
2097 Your web site is accessible through your shell account. Please read
2098 site documentation (see link below) about intended usage, available
2099 services, and directory layout of the account.
2102 own project page in %4$s while logged in, you will find
2103 additional menu functions to your left labeled \'Project Admin\'.
2105 We highly suggest that you now visit %4$s and create a public
2106 description for your project. This can be done by visiting your project
2107 page while logged in, and selecting \'Project Admin\' from the menus
2108 on the left (or by visiting %3$s
2111 Your project will also not appear in the Trove Software Map (primary
2112 list of projects hosted on %4$s which offers great flexibility in
2113 browsing and search) until you categorize it in the project administration
2114 screens. So that people can find your project, you should do this now.
2115 Visit your project while logged in, and select \'Project Admin\' from the
2118 Enjoy the system, and please tell others about %4$s. Let us know
2119 if there is anything we can do to help you.
2122 $this->getPublicName(),
2123 $this->getUnixName(),
2124 util_make_url ('/project/admin/?group_id='.$this->getID()),
2125 $GLOBALS['sys_name']));
2127 util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), $GLOBALS['sys_name']), $message);
2129 setup_gettext_from_browser () ;
2137 * sendRejectionEmail - Send project rejection email.
2139 * This function sends out a rejection message to a user who
2140 * registered a project.
2142 * @param int The id of the response to use.
2143 * @param string The rejection message.
2144 * @return completion status.
2147 function sendRejectionEmail($response_id, $message="zxcv") {
2148 $res_admins = db_query("
2149 SELECT u.email, u.language, u.user_id
2150 FROM users u, user_group ug
2151 WHERE ug.group_id='".$this->getID()."'
2152 AND u.user_id=ug.user_id;
2155 if (db_numrows($res_admins) < 1) {
2156 $this->setError(_("Group does not have any administrators."));
2160 while ($row_admins = db_fetch_array($res_admins)) {
2161 $admin =& user_get_object($row_admins['user_id']);
2162 setup_gettext_for_user ($admin) ;
2164 $response=stripcslashes(sprintf(_('Your project registration for %3$s has been denied.
2166 Project Full Name: %1$s
2167 Project Unix Name: %2$s
2169 Reasons for negative decision:
2171 '), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name']));
2173 // Check to see if they want to send a custom rejection response
2174 if ($response_id == 0) {
2175 $response .= stripcslashes($message);
2177 $response .= db_result(db_query("
2178 SELECT response_text
2179 FROM canned_responses
2180 WHERE response_id='$response_id'
2181 "), 0, "response_text");
2184 util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), $GLOBALS['sys_name']), $response);
2185 setup_gettext_from_browser () ;
2192 * sendNewProjectNotificationEmail - Send new project notification email.
2194 * This function sends out a notification email to the
2195 * SourceForge admin user when a new project is
2198 * @return boolean success.
2201 function sendNewProjectNotificationEmail() {
2202 // Get the user who wants to register the project
2203 $res = db_query("SELECT u.user_id
2204 FROM users u, user_group ug
2205 WHERE ug.group_id='".$this->getID()."' AND u.user_id=ug.user_id;");
2207 if (db_numrows($res) < 1) {
2208 $this->setError(_("Could not find user who has submitted the project."));
2212 $submitter =& user_get_object(db_result($res,0,'user_id'));
2215 $res = db_query("SELECT users.email, users.language, users.user_id
2216 FROM users,user_group
2218 AND user_group.admin_flags='A'
2219 AND users.user_id=user_group.user_id;");
2221 if (db_numrows($res) < 1) {
2222 $this->setError(_("There is no administrator to send the mail."));
2226 for ($i=0; $i<db_numrows($res) ; $i++) {
2227 $admin_email = db_result($res,$i,'email') ;
2228 $admin =& user_get_object(db_result($res,$i,'user_id'));
2229 setup_gettext_for_user ($admin) ;
2231 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2233 Project Full Name: %2$s
2234 Submitted Description: %3$s
2236 Submitter: %6$s (%7$s)
2238 Please visit the following URL to approve or reject this project:
2240 $GLOBALS['sys_name'],
2241 $this->getPublicName(),
2242 util_unconvert_htmlspecialchars($this->getRegistrationPurpose()),
2243 $this->getLicenseName(),
2244 util_make_url ('/admin/approve-pending.php'),
2245 $submitter->getRealName(),
2246 $submitter->getUnixName()));
2247 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2248 setup_gettext_from_browser () ;
2252 $email = $submitter->getEmail() ;
2253 setup_gettext_for_user ($submitter) ;
2255 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2257 Project Full Name: %2$s
2258 Submitted Description: %3$s
2261 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']));
2263 util_send_message($email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2264 setup_gettext_from_browser () ;
2271 * group_getname() - get the group name
2273 * @param int The group ID
2277 function group_getname ($group_id = 0) {
2278 $grp = &group_get_object($group_id);
2280 return $grp->getPublicName();
2287 * group_getunixname() - get the unixname for a group
2289 * @param int The group ID
2293 function group_getunixname ($group_id) {
2294 $grp = &group_get_object($group_id);
2296 return $grp->getUnixName();
2303 * group_get_result() - Get the group object result ID.
2305 * @param int The group ID
2309 function &group_get_result($group_id=0) {
2310 $grp = &group_get_object($group_id);
2312 return $grp->getData();
2319 * getUnixStatus - Status of activation of unix account.
2321 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2323 function getUnixStatus() {
2324 return $this->data_array['unix_status'];
2328 * setUnixStatus - Sets status of activation of unix account.
2330 * @param string The unix status.
2336 * @return boolean success.
2338 function setUnixStatus($status) {
2343 SET unix_status='$status'
2344 WHERE group_id='". $this->getID()."'
2348 $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
2352 if ($status == 'A') {
2353 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2354 $this->setError($SYS->getErrorMessage());
2359 if ($SYS->sysCheckGroup($this->getID())) {
2360 if (!$SYS->sysRemoveGroup($this->getID())) {
2361 $this->setError($SYS->getErrorMessage());
2368 $this->data_array['unix_status']=$status;
2376 // c-file-style: "bsd"