5 * Copyright 1999-2001, VA Linux Systems, Inc.
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 require_once $gfcommon.'tracker/ArtifactTypes.class.php';
26 require_once $gfcommon.'tracker/ArtifactTypeFactory.class.php';
27 require_once $gfcommon.'forum/Forum.class.php';
28 require_once $gfcommon.'forum/ForumFactory.class.php';
29 require_once $gfcommon.'pm/ProjectGroup.class.php';
30 require_once $gfcommon.'pm/ProjectGroupFactory.class.php';
31 require_once $gfcommon.'include/Role.class.php';
32 require_once $gfcommon.'frs/FRSPackage.class.php';
33 require_once $gfcommon.'docman/DocumentGroup.class.php';
34 require_once $gfcommon.'mail/MailingList.class.php';
35 require_once $gfcommon.'mail/MailingListFactory.class.php';
36 require_once $gfcommon.'survey/SurveyFactory.class.php';
37 require_once $gfcommon.'survey/SurveyQuestionFactory.class.php';
38 require_once $gfcommon.'include/gettext.php';
40 //the license_id of "Other/proprietary" license
41 define('GROUP_LICENSE_OTHER',126);
43 $LICENSE_NAMES=array();
46 * group_get_licences() - get the licenses list
48 * @return array list of licenses
50 function & group_get_licenses() {
51 global $LICENSE_NAMES;
52 if(empty($LICENSE_NAMES)) {
53 $result = db_query('select * from licenses');
54 while($data = db_fetch_array($result)) {
55 $LICENSE_NAMES[$data['license_id']] = $data['license_name'];
58 return $LICENSE_NAMES;
64 * group_get_object() - Get the group object.
66 * group_get_object() is useful so you can pool group objects/save database queries
67 * You should always use this instead of instantiating the object directly.
69 * You can now optionally pass in a db result handle. If you do, it re-uses that query
70 * to instantiate the objects.
72 * IMPORTANT! That db result must contain all fields
73 * from groups table or you will have problems
76 * @param int Result set handle ("SELECT * FROM groups WHERE group_id=xx")
77 * @return a group object or false on failure
79 function &group_get_object($group_id,$res=false) {
80 //create a common set of group objects
81 //saves a little wear on the database
83 //automatically checks group_type and
84 //returns appropriate object
87 if (!isset($GROUP_OBJ["_".$group_id."_"])) {
89 //the db result handle was passed in
91 $res=db_query("SELECT * FROM groups WHERE group_id='$group_id'");
93 if (!$res || db_numrows($res) < 1) {
94 $GROUP_OBJ["_".$group_id."_"]=false;
97 check group type and set up object
99 if (db_result($res,0,'type_id')==1) {
101 $GROUP_OBJ["_".$group_id."_"]= new Group($group_id,$res);
104 $GROUP_OBJ["_".$group_id."_"]=false;
108 return $GROUP_OBJ["_".$group_id."_"];
111 function &group_get_objects($id_arr) {
114 // Note: if we don't do this, the result may be corrupted
118 for ($i=0; $i<count($id_arr); $i++) {
120 // See if this ID already has been fetched in the cache
125 if (!isset($GROUP_OBJ["_".$id_arr[$i]."_"])) {
126 $fetch[]=$id_arr[$i];
128 $return[] =& $GROUP_OBJ["_".$id_arr[$i]."_"];
131 if (count($fetch) > 0) {
132 $res=db_query("SELECT * FROM groups WHERE group_id IN ('".implode($fetch,'\',\'') ."')");
133 while ($arr =& db_fetch_array($res)) {
134 $GROUP_OBJ["_".$arr['group_id']."_"] = new Group($arr['group_id'],$arr);
135 $return[] =& $GROUP_OBJ["_".$arr['group_id']."_"];
141 function &group_get_object_by_name($groupname) {
142 $res=db_query("SELECT * FROM groups WHERE unix_group_name='$groupname'");
143 return group_get_object(db_result($res,0,'group_id'),$res);
146 function &group_get_objects_by_name($groupname_arr) {
147 $sql="SELECT group_id FROM groups WHERE unix_group_name IN ('".implode($groupname_arr,'\',\'')."')";
149 $arr =& util_result_column_to_array($res,0);
150 return group_get_objects($arr);
153 class Group extends Error {
155 * Associative array of data from db.
157 * @var array $data_array.
162 * array of User objects.
164 * @var array $membersArr.
169 * Permissions data row from db.
171 * @var array $perm_data_array.
173 var $perm_data_array;
176 * Whether the use is an admin/super user of this project.
178 * @var bool $is_admin.
183 * Artifact types result handle.
185 * @var int $types_res.
190 * Associative array of data for plugins.
192 * @var array $plugins_array.
197 * Group - Group object constructor - use group_get_object() to instantiate.
199 * @param int Required - group_id of the group you want to instantiate.
200 * @param int Database result from select query OR associative array of all columns.
202 function Group($id=false, $res=false) {
205 //setting up an empty object
206 //probably going to call create()
210 if (!$this->fetchData($id)) {
215 // Assoc array was passed in
217 if (is_array($res)) {
218 $this->data_array =& $res;
220 if (db_numrows($res) < 1) {
221 //function in class we extended
222 $this->setError(_('Group Not Found'));
223 $this->data_array=array();
226 //set up an associative array for use by other functions
227 db_reset_result($res);
228 $this->data_array = db_fetch_array($res);
233 $systemGroups = array(GROUP_IS_NEWS, GROUP_IS_STATS, GROUP_IS_PEER_RATINGS);
234 if(!$this->isPublic() && !in_array($id, $systemGroups)) {
235 $perm =& $this->getPermission(session_get_user());
237 if (!$perm || !is_object($perm) || !$perm->isMember()) {
238 $this->setError(_('Permission denied'), ERROR__PERMISSION_DENIED_ERROR);
246 * fetchData - May need to refresh database fields if an update occurred.
248 * @param int The group_id.
250 function fetchData($group_id) {
251 $res = db_query("SELECT * FROM groups WHERE group_id='$group_id'");
252 if (!$res || db_numrows($res) < 1) {
253 $this->setError(sprintf(_('fetchData():: %s'),db_error()));
256 $this->data_array =& db_fetch_array($res);
261 * create - Create new group.
263 * This method should be called on empty Group object.
265 * @param object The User object.
266 * @param string The full name of the user.
267 * @param string The Unix name of the user.
268 * @param string The new group description.
269 * @param int The ID of the license to use.
270 * @param string The 'other' license to use if any.
271 * @param string The purpose of the group.
273 function create(&$user, $full_name, $unix_name, $description, $license, $license_other, $purpose, $unix_box='shell1', $scm_box='cvs1', $is_public=1) {
274 // $user is ignored - anyone can create pending group
276 if ($this->getID()!=0) {
277 $this->setError(_('Group::create: Group object already exists'));
279 } else if (strlen($full_name)<3) {
280 $this->setError(_('Invalid full name'));
282 } else if (!account_groupnamevalid($unix_name)) {
283 $this->setError(_('Invalid Unix name'));
285 } else if (db_numrows(db_query("SELECT group_id FROM groups WHERE unix_group_name='$unix_name'")) > 0) {
286 $this->setError(_('Unix name already taken'));
288 } else if (strlen($purpose)<10) {
289 $this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
291 } else if (strlen($purpose)>1500) {
292 $this->setError(_('The Registration Purpose text is too long. Please make it smaller than 1500 bytes.'));
294 } else if (strlen($description)<10) {
295 $this->setError(_('Describe in a more comprehensive manner your project.'));
297 } else if (strlen($description)>255) {
298 $this->setError(_('Your project description is too long. Please make it smaller than 256 bytes.'));
300 } else if (!$license) {
301 $this->setError(_('You have not chosen a license'));
303 } else if ($license!=GROUP_LICENSE_OTHER && $license_other) {
304 $this->setError(_('Conflicting licenses choice'));
306 } else if ($license==GROUP_LICENSE_OTHER && strlen($license_other)<50) {
307 $this->setError(_('Please give more comprehensive licensing description'));
311 srand((double)microtime()*1000000);
312 $random_num = rand(0,1000000);
335 '".htmlspecialchars($full_name)."',
338 '".htmlspecialchars($description)."',
339 '$unix_name.".$GLOBALS['sys_default_domain']."',
340 '$unix_name.".$GLOBALS['sys_default_domain']."',
345 '".htmlspecialchars($purpose)."',
347 '".htmlspecialchars($license_other)."',
349 '".md5($random_num)."'
353 if (!$res || db_affected_rows($res) < 1) {
354 $this->setError(sprintf(_('ERROR: Could not create group: %s'),db_error()));
359 $id = db_insertid($res, 'groups', 'group_id');
361 $this->setError(sprintf(_('ERROR: Could not get group id: %s'),db_error()));
367 // Now, make the user an admin
369 $sql="INSERT INTO user_group ( user_id, group_id, admin_flags,
370 cvs_flags, artifact_flags, forum_flags, role_id)
371 VALUES ( ".$user->getID().", '$id', 'A', 1, 2, 2, 1)";
374 if (!$res || db_affected_rows($res) < 1) {
375 $this->setError(sprintf(_('ERROR: Could not add admin to newly created group: %s'),db_error()));
380 if (!$this->fetchData($id)) {
385 $hook_params = array ();
386 $hook_params['group'] = $this;
387 $hook_params['group_id'] = $this->getID();
388 $hook_params['group_name'] = $full_name;
389 $hook_params['unix_group_name'] = $unix_name;
390 plugin_hook ("group_create", $hook_params);
393 $this->sendNewProjectNotificationEmail();
400 * updateAdmin - Update core properties of group object.
402 * This function require site admin privilege.
404 * @param object User requesting operation (for access control).
405 * @param bool Whether group is publicly accessible (0/1).
406 * @param string Project's license (string ident).
407 * @param int Group type (1-project, 2-foundry).
408 * @param string Machine on which group's home directory located.
409 * @param string Domain which serves group's WWW.
413 function updateAdmin(&$user, $is_public, $license, $type_id, $unix_box, $http_domain) {
414 $perm =& $this->getPermission($user);
416 if (!$perm || !is_object($perm)) {
417 $this->setError(_('Could not get permission.'));
421 if (!$perm->isSuperUser()) {
422 $this->setError(_('Permission denied.'));
430 SET is_public='$is_public',
431 license='$license',type_id='$type_id',
432 unix_box='$unix_box',http_domain='$http_domain'
433 WHERE group_id='".$this->getID()."'
436 if (!$res || db_affected_rows($res) < 1) {
437 $this->setError(_('ERROR: DB: Could not change group properties: %s'),db_error());
442 // Log the audit trail
443 if ($is_public != $this->isPublic()) {
444 $this->addHistory('is_public', $this->isPublic());
446 if ($license != $this->data_array['license']) {
447 $this->addHistory('license', $this->data_array['license']);
449 if ($type_id != $this->data_array['type_id']) {
450 $this->addHistory('type_id', $this->data_array['type_id']);
452 if ($unix_box != $this->data_array['unix_box']) {
453 $this->addHistory('unix_box', $this->data_array['unix_box']);
455 if ($http_domain != $this->data_array['http_domain']) {
456 $this->addHistory('http_domain', $this->data_array['http_domain']);
459 if (!$this->fetchData($this->getID())) {
468 * update - Update number of common properties.
470 * Unlike updateAdmin(), this function accessible to project admin.
472 * @param object User requesting operation (for access control).
473 * @param bool Whether group is publicly accessible (0/1).
474 * @param string Project's license (string ident).
475 * @param int Group type (1-project, 2-foundry).
476 * @param string Machine on which group's home directory located.
477 * @param string Domain which serves group's WWW.
478 * @return int status.
481 function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,
482 $use_pm,$use_pm_depend_box,$use_scm,$use_news,$use_docman,
483 $new_doc_address,$send_all_docs,$logo_image_id,
484 $enable_pserver,$enable_anonscm,
485 $use_ftp,$use_tracker,$use_frs,$use_stats,$is_public) {
487 $perm =& $this->getPermission($user);
489 if (!$perm || !is_object($perm)) {
490 $this->setError(_('Could not get permission.'));
494 if (!$perm->isAdmin()) {
495 $this->setError(_('Permission denied.'));
499 // Validate some values
501 $this->setError(_('Invalid Group Name'));
505 if ($new_doc_address) {
506 $invalid_mails = validate_emails($new_doc_address);
507 if (count($invalid_mails) > 0) {
508 $this->setError(sprintf (ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
513 // in the database, these all default to '1',
514 // so we have to explicity set 0
527 if (!$use_pm_depend_box) {
528 $use_pm_depend_box=0;
551 if (!$send_all_docs) {
556 $homepage=$GLOBALS['sys_default_domain'].'/projects/'.$this->getUnixName().'/';
559 if (strlen($short_description)>255) {
560 $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
566 //XXX not yet actived logo_image_id='$logo_image_id',
570 group_name='".htmlspecialchars($group_name)."',
571 homepage='$homepage',
572 short_description='".htmlspecialchars($short_description)."',
573 use_mail='$use_mail',
574 use_survey='$use_survey',
575 use_forum='$use_forum',
577 use_pm_depend_box='$use_pm_depend_box',
579 use_news='$use_news',
580 use_docman='$use_docman',
581 is_public='$is_public',
582 new_doc_address='$new_doc_address',
583 send_all_docs='$send_all_docs',
585 if ($enable_pserver != '') {
587 enable_pserver='$enable_pserver',
590 if ($enable_anonscm != '') {
592 enable_anonscm='$enable_anonscm',
597 use_tracker='$use_tracker',
599 use_stats='$use_stats'
600 WHERE group_id='".$this->getID()."'
602 $res = db_query($sql);
605 $this->setError(sprintf(_('Error updating project information: %s'), db_error()));
610 $hook_params = array ();
611 $hook_params['group'] = $this;
612 $hook_params['group_id'] = $this->getID();
613 $hook_params['group_homepage'] = $homepage;
614 $hook_params['group_name'] = htmlspecialchars($group_name);
615 $hook_params['group_description'] = htmlspecialchars($short_description);
616 plugin_hook ("group_update", $hook_params);
618 // Log the audit trail
619 $this->addHistory('Changed Public Info', '');
621 if (!$this->fetchData($this->getID())) {
630 * getID - Simply return the group_id for this object.
632 * @return int group_id.
635 return $this->data_array['group_id'];
639 * getType() - Foundry, project, etc.
641 * @return int The type flag from the database.
644 return $this->data_array['type_id'];
649 * getStatus - the status code.
651 * Statuses char include I,H,A,D.
653 function getStatus() {
654 return $this->data_array['status'];
658 * setStatus - set the status code.
660 * Statuses include I,H,A,D.
662 * @param object User requesting operation (for access control).
663 * @param string Status value.
664 * @return boolean success.
667 function setStatus(&$user, $status) {
670 $perm =& $this->getPermission($user);
671 if (!$perm || !is_object($perm)) {
672 $this->setPermissionDeniedError();
674 } elseif (!$perm->isSuperUser()) {
675 $this->setPermissionDeniedError();
679 // Projects in 'A' status can only go to 'H' or 'D'
680 // Projects in 'D' status can only go to 'A'
681 // Projects in 'P' status can only go to 'A' OR 'D'
682 // Projects in 'I' status can only go to 'P'
683 // Projects in 'H' status can only go to 'A' OR 'D'
684 $allowed_status_changes = array(
685 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
686 'IP'=>1,'HA'=>1,'HD'=>1
689 // Check that status transition is valid
690 if ($this->getStatus() != $status
691 && !$allowed_status_changes[$this->getStatus().$status]) {
692 $this->setError(_('Invalid Status Change'));
698 $res = db_query("UPDATE groups
700 WHERE group_id='". $this->getID()."'");
702 if (!$res || db_affected_rows($res) < 1) {
703 $this->setError(sprintf(_('ERROR: DB: Could not change group status: %s'),db_error()));
709 // Activate system group, if not yet
710 if (!$SYS->sysCheckGroup($this->getID())) {
711 if (!$SYS->sysCreateGroup($this->getID())) {
712 $this->setError($SYS->getErrorMessage());
717 if (!$this->activateUsers()) {
722 /* Otherwise, the group is not active, and make sure that
723 System group is not active either */
724 } else if ($SYS->sysCheckGroup($this->getID())) {
725 if (!$SYS->sysRemoveGroup($this->getID())) {
726 $this->setError($SYS->getErrorMessage());
732 $hook_params = array ();
733 $hook_params['group'] = $this;
734 $hook_params['group_id'] = $this->getID();
735 $hook_params['status'] = $status;
736 plugin_hook ("group_setstatus", $hook_params);
740 // Log the audit trail
741 if ($status != $this->getStatus()) {
742 $this->addHistory('Status', $this->getStatus());
745 $this->data_array['status'] = $status;
750 * isProject - Simple boolean test to see if it's a project or not.
752 * @return boolean is_project.
754 function isProject() {
755 if ($this->getType()==1) {
763 * isPublic - Simply returns the is_public flag from the database.
765 * @return boolean is_public.
767 function isPublic() {
768 return $this->data_array['is_public'];
772 * isActive - Database field status of 'A' returns true.
774 * @return boolean is_active.
776 function isActive() {
777 if ($this->getStatus()=='A') {
785 * getUnixName - the unix_name
787 * @return string unix_name.
789 function getUnixName() {
790 return strtolower($this->data_array['unix_group_name']);
794 * getPublicName - the full-length public name.
796 * @return string The group_name.
798 function getPublicName() {
799 return $this->data_array['group_name'];
803 * getRegisterPurpose - the text description of the purpose of this project.
805 * @return string The description.
807 function getRegisterPurpose() {
808 return $this->data_array['register_purpose'];
812 * getDescription - the text description of this project.
814 * @return string The description.
816 function getDescription() {
817 return $this->data_array['short_description'];
821 * getStartDate - the unix time this project was registered.
823 * @return int (unix time) of registration.
825 function getStartDate() {
826 return $this->data_array['register_time'];
830 * getLogoImageID - the id of the logo in the database for this project.
832 * @return int The ID of logo image in db_images table (or 100 if none).
834 function getLogoImageID() {
835 return $this->data_array['logo_image_id'];
839 * getUnixBox - the hostname of the unix box where this project is located.
841 * @return string The name of the unix machine for the group.
843 function getUnixBox() {
844 return $this->data_array['unix_box'];
848 * getSCMBox - the hostname of the scm box where this project is located.
850 * @return string The name of the unix machine for the group.
852 function getSCMBox() {
853 return $this->data_array['scm_box'];
856 * setSCMBox - the hostname of the scm box where this project is located.
858 * @param string The name of the new SCM_BOX
860 function setSCMBox($scm_box) {
863 $sql = "UPDATE groups SET scm_box = '$scm_box' WHERE group_id = ".$this->getID();
864 $res = db_query($sql);
866 $this->addHistory('scm_box', $this->data_array['scm_box']);
867 $this->data_array['scm_box']=$scm_box;
872 $this->setError(_("Couldn't insert SCM_BOX to database"));
876 $this->setError(_("SCM Box can't be empty"));
882 * getDomain - the hostname.domain where their web page is located.
884 * @return string The name of the group [web] domain.
886 function getDomain() {
887 return $this->data_array['http_domain'];
891 * getLicense - the license they chose.
893 * @return int ident of group license.
895 function getLicense() {
896 return $this->data_array['license'];
900 * getLicenseName - the name of the license
902 * @return string license name
904 function getLicenseName() {
905 $licenses =& group_get_licenses();
906 if(isset($licenses[$this->data_array['license']])) {
907 return $licenses[$this->data_array['license']];
914 * getLicenseOther - optional string describing license.
916 * @return string The custom license.
918 function getLicenseOther() {
919 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
920 return $this->data_array['license_other'];
927 * getRegistrationPurpose - the text description of the purpose of this project.
929 * @return string The application for project hosting.
931 function getRegistrationPurpose() {
932 return $this->data_array['register_purpose'];
937 * getAdmins() - Get array of Admin user objects.
939 * @return array Array of User objects.
941 function &getAdmins() {
942 // this function gets all group admins in order to send Jabber and mail messages
943 $q = "SELECT user_id FROM user_group WHERE admin_flags = 'A' AND group_id = ".$this->getID();
945 $user_ids=util_result_column_to_array($res);
946 return user_get_objects($user_ids);
951 Common Group preferences for tools
956 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
958 * @return boolean enable_scm.
960 function enableAnonSCM() {
961 if ($this->isPublic() && $this->usesSCM()) {
962 return $this->data_array['enable_anonscm'];
968 function SetUsesAnonSCM ($booleanparam) {
970 $booleanparam = $booleanparam ? 1 : 0 ;
971 $sql = "UPDATE groups SET enable_anonscm = $booleanparam WHERE group_id = ".$this->getID() ;
972 $res = db_query($sql);
974 $this->data_array['enable_anonscm']=$booleanparam;
983 * enablePserver - whether or not this group has opted to enable Pserver.
985 * @return boolean enable_pserver.
987 function enablePserver() {
988 if ($this->usesSCM()) {
989 return $this->data_array['enable_pserver'];
995 function SetUsesPserver ($booleanparam) {
997 $booleanparam = $booleanparam ? 1 : 0 ;
998 $sql = "UPDATE groups SET enable_pserver = $booleanparam WHERE group_id = ".$this->getID() ;
999 $res = db_query($sql);
1001 $this->data_array['enable_pserver']=$booleanparam;
1010 * usesSCM - whether or not this group has opted to use SCM.
1012 * @return boolean uses_scm.
1014 function usesSCM() {
1015 global $sys_use_scm;
1017 return $this->data_array['use_scm'];
1024 * usesMail - whether or not this group has opted to use mailing lists.
1026 * @return boolean uses_mail.
1028 function usesMail() {
1029 global $sys_use_mail;
1030 if ($sys_use_mail) {
1031 return $this->data_array['use_mail'];
1038 * usesNews - whether or not this group has opted to use news.
1040 * @return boolean uses_news.
1042 function usesNews() {
1043 global $sys_use_news;
1044 if ($sys_use_news) {
1045 return $this->data_array['use_news'];
1052 * usesForum - whether or not this group has opted to use discussion forums.
1054 * @return boolean uses_forum.
1056 function usesForum() {
1057 global $sys_use_forum;
1058 if ($sys_use_forum) {
1059 return $this->data_array['use_forum'];
1066 * usesStats - whether or not this group has opted to use stats.
1068 * @return boolean uses_stats.
1070 function usesStats() {
1071 return $this->data_array['use_stats'];
1075 * usesFRS - whether or not this group has opted to use file release system.
1077 * @return boolean uses_frs.
1079 function usesFRS() {
1080 global $sys_use_frs;
1082 return $this->data_array['use_frs'];
1089 * usesTracker - whether or not this group has opted to use tracker.
1091 * @return boolean uses_tracker.
1093 function usesTracker() {
1094 global $sys_use_tracker;
1095 if ($sys_use_tracker) {
1096 return $this->data_array['use_tracker'];
1103 * usesDocman - whether or not this group has opted to use docman.
1105 * @return boolean uses_docman.
1107 function usesDocman() {
1108 global $sys_use_docman;
1109 if ($sys_use_docman) {
1110 return $this->data_array['use_docman'];
1117 * usesFTP - whether or not this group has opted to use FTP.
1119 * @return boolean uses_ftp.
1121 function usesFTP() {
1122 global $sys_use_ftp;
1124 return $this->data_array['use_ftp'];
1131 * usesSurvey - whether or not this group has opted to use surveys.
1133 * @return boolean uses_survey.
1135 function usesSurvey() {
1136 global $sys_use_survey;
1137 if ($sys_use_survey) {
1138 return $this->data_array['use_survey'];
1145 * usesPM - whether or not this group has opted to Project Manager.
1147 * @return boolean uses_projman.
1152 return $this->data_array['use_pm'];
1159 * getPlugins - get a list of all available group plugins
1161 * @return array array containing plugin_id => plugin_name
1163 function getPlugins() {
1164 if (!isset($this->plugins_data)) {
1165 $this->plugins_data = array () ;
1166 $sql="SELECT group_plugin.plugin_id, plugins.plugin_name
1167 FROM group_plugin, plugins
1168 WHERE group_plugin.group_id=".$this->getID()."
1169 AND group_plugin.plugin_id = plugins.plugin_id" ;
1170 $res=db_query($sql);
1171 $rows = db_numrows($res);
1173 for ($i=0; $i<$rows; $i++) {
1174 $plugin_id = db_result($res,$i,'plugin_id');
1175 $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
1178 return $this->plugins_data ;
1182 * usesPlugin - returns true if the group uses a particular plugin
1184 * @param string name of the plugin
1185 * @return boolean whether plugin is being used or not
1187 function usesPlugin($pluginname) {
1188 $plugins_data = $this->getPlugins() ;
1189 foreach ($plugins_data as $p_id => $p_name) {
1190 if ($p_name == $pluginname) {
1198 * setPluginUse - enables/disables plugins for the group
1200 * @param string name of the plugin
1201 * @param boolean the new state
1202 * @return string database result
1204 function setPluginUse($pluginname, $val=true) {
1205 if ($val == $this->usesPlugin($pluginname)) {
1206 // State is already good, returning
1209 $sql="SELECT plugin_id
1211 WHERE plugin_name = '" . $pluginname . "'" ;
1212 $res=db_query($sql);
1213 $rows = db_numrows($res);
1215 // Error: no plugin by that name
1218 $plugin_id = db_result($res,0,'plugin_id');
1220 unset ($this->plugins_data) ;
1222 $sql="INSERT INTO group_plugin (group_id, plugin_id)
1223 VALUES (". $this->getID() . ", ". $plugin_id .")" ;
1224 $res=db_query($sql);
1227 $sql="DELETE FROM group_plugin
1228 WHERE group_id = ". $this->getID() . "
1229 AND plugin_id = ". $plugin_id ;
1230 $res=db_query($sql);
1236 * getDocEmailAddress - get email address(es) to send doc notifications to.
1238 * @return string email address.
1240 function getDocEmailAddress() {
1241 return $this->data_array['new_doc_address'];
1245 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1247 * @return boolean email_on_all_doc_updates.
1249 function docEmailAll() {
1250 return $this->data_array['send_all_docs'];
1255 * getHomePage - The URL for this project's home page.
1257 * @return string homepage URL.
1259 function getHomePage() {
1260 return $this->data_array['homepage'];
1264 * getPermission - Return a Permission for this Group and the specified User.
1266 * @param object The user you wish to get permission for (usually the logged in user).
1267 * @return object The Permission.
1269 function &getPermission(&$_user) {
1270 return permission_get_object($this, $_user);
1275 * userIsAdmin - Return if for this Group the User is admin.
1277 * @return boolean is_admin.
1279 function userIsAdmin() {
1280 $perm =& $this->getPermission( session_get_user() );
1281 if (!$perm || !is_object($perm)) {
1283 } elseif ($perm->isError()) {
1286 return $perm->isAdmin();
1289 function delete($sure,$really_sure,$really_really_sure) {
1290 if (!$sure || !$really_sure || !$really_really_sure) {
1291 $this->setMissingParamsError();
1294 if ($this->getID() == $GLOBALS['sys_news_group'] ||
1295 $this->getID() == 1 ||
1296 $this->getID() == $GLOBALS['sys_stats_group'] ||
1297 $this->getID() == $GLOBALS['sys_peer_rating_group']) {
1298 $this->setError(_('Cannot Delete System Group'));
1301 $perm =& $this->getPermission( session_get_user() );
1302 if (!$perm || !is_object($perm)) {
1303 $this->setPermissionDeniedError();
1305 } elseif ($perm->isError()) {
1306 $this->setPermissionDeniedError();
1308 } elseif (!$perm->isSuperUser()) {
1309 $this->setPermissionDeniedError();
1315 // Remove all the members
1317 $members =& $this->getMembers();
1318 for ($i=0; $i<count($members); $i++) {
1319 $this->removeUser($members[$i]->getID());
1324 $atf = new ArtifactTypeFactory($this);
1325 $at_arr =& $atf->getArtifactTypes();
1326 for ($i=0; $i<count($at_arr); $i++) {
1327 if (!is_object($at_arr[$i])) {
1328 printf (_("Not Object: ArtifactType: %d"),$i);
1331 $at_arr[$i]->delete(1,1);
1336 $ff = new ForumFactory($this);
1337 $f_arr =& $ff->getForums();
1338 for ($i=0; $i<count($f_arr); $i++) {
1339 if (!is_object($f_arr[$i])) {
1340 printf (_("Not Object: Forum: %d"),$i);
1343 $f_arr[$i]->delete(1,1);
1344 //echo 'ForumFactory'.db_error();
1347 // Delete Subprojects
1349 $pgf = new ProjectGroupFactory($this);
1350 $pg_arr =& $pgf->getProjectGroups();
1351 for ($i=0; $i<count($pg_arr); $i++) {
1352 if (!is_object($pg_arr[$i])) {
1353 printf (_("Not Object: ProjectGroup: %d"),$i);
1356 $pg_arr[$i]->delete(1,1);
1357 //echo 'ProjectGroupFactory'.db_error();
1360 // Delete FRS Packages
1362 //$frspf = new FRSPackageFactory($this);
1363 $res=db_query("SELECT * FROM frs_package WHERE group_id='".$this->getID()."'");
1364 //echo 'frs_package'.db_error();
1365 //$frsp_arr =& $frspf->getPackages();
1366 while ($arr = db_fetch_array($res)) {
1367 //if (!is_object($pg_arr[$i])) {
1368 // echo "Not Object: ProjectGroup: ".$i;
1371 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1377 $news_group=&group_get_object($GLOBALS['sys_news_group']);
1378 $res=db_query("SELECT forum_id FROM news_bytes WHERE group_id='".$this->getID()."'");
1379 for ($i=0; $i<db_numrows($res); $i++) {
1380 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1381 if (!$Forum->delete(1,1)) {
1382 printf (_("Could Not Delete News Forum: %d"),$Forum->getID());
1385 $res=db_query("DELETE FROM news_bytes WHERE group_id='".$this->getID()."'");
1390 $res=db_query("DELETE FROM doc_data WHERE group_id='".$this->getID()."'");
1391 //echo 'doc_data'.db_error();
1392 $res=db_query("DELETE FROM doc_groups WHERE group_id='".$this->getID()."'");
1393 //echo 'doc_groups'.db_error();
1395 // Delete group history
1397 $res=db_query("DELETE FROM group_history WHERE group_id='".$this->getID()."'");
1398 //echo 'group_history'.db_error();
1400 // Delete group plugins
1402 $res=db_query("DELETE FROM group_plugin WHERE group_id='".$this->getID()."'");
1403 //echo 'group_plugin'.db_error();
1405 // Delete group cvs stats
1407 $res=db_query("DELETE FROM stats_cvs_group WHERE group_id='".$this->getID()."'");
1408 //echo 'stats_cvs_group'.db_error();
1412 $sf = new SurveyFactory($this);
1413 $s_arr =& $sf->getSurveys();
1414 for ($i=0; $i<count($s_arr); $i++) {
1415 if (!is_object($s_arr[$i])) {
1416 printf (_("Not Object: Survey: %d"),$i);
1419 $s_arr[$i]->delete();
1420 //echo 'SurveyFactory'.db_error();
1423 // Delete SurveyQuestions
1425 $sqf = new SurveyQuestionFactory($this);
1426 $sq_arr =& $sqf->getSurveyQuestions();
1427 for ($i=0; $i<count($sq_arr); $i++) {
1428 if (!is_object($sq_arr[$i])) {
1429 printf (_("Not Object: SurveyQuestion: %d"),$i);
1432 $sq_arr[$i]->delete();
1433 //echo 'SurveyQuestionFactory'.db_error();
1436 // Delete Mailing List Factory
1438 $mlf = new MailingListFactory($this);
1439 $ml_arr =& $mlf->getMailingLists();
1440 for ($i=0; $i<count($ml_arr); $i++) {
1441 if (!is_object($ml_arr[$i])) {
1442 printf (_("Not Object: MailingList: %d"),$i);
1445 if (!$ml_arr[$i]->delete(1,1)) {
1446 $this->setError(_('Could not properly delete the mailing list'));
1448 //echo 'MailingListFactory'.db_error();
1453 $res=db_query("DELETE FROM trove_group_link WHERE group_id='".$this->getID()."'");
1454 $res=db_query("DELETE FROM trove_agg WHERE group_id='".$this->getID()."'");
1458 $res=db_query("DELETE FROM project_sums_agg WHERE group_id='".$this->getID()."'");
1459 //echo 'project_sums_agg'.db_error();
1460 $res=db_query("INSERT INTO deleted_groups (
1461 unix_group_name,delete_date,isdeleted) VALUES
1462 ('".$this->getUnixName()."','".time()."','0')");
1463 //echo 'InsertIntoDeleteQueue'.db_error();
1464 $res=db_query("DELETE FROM groups WHERE group_id='".$this->getID()."'");
1465 //echo 'DeleteGroup'.db_error();
1471 $hook_params = array ();
1472 $hook_params['group'] = $this;
1473 $hook_params['group_id'] = $this->getID();
1474 plugin_hook ("group_delete", $hook_params);
1476 if (isset($GLOBALS['sys_upload_dir']) && $this->getUnixName()) {
1477 exec('/bin/rm -rf '.$GLOBALS['sys_upload_dir'].'/'.$this->getUnixName().'/');
1479 if (isset($GLOBALS['sys_ftp_upload_dir']) && $this->getUnixName()) {
1480 exec('/bin/rm -rf '.$GLOBALS['sys_ftp_upload_dir'].'/'.$this->getUnixName().'/');
1485 $res=db_query("DELETE FROM rep_group_act_weekly WHERE group_id='".$this->getID()."'");
1486 //echo 'rep_group_act_weekly'.db_error();
1487 $res=db_query("DELETE FROM rep_group_act_monthly WHERE group_id='".$this->getID()."'");
1488 //echo 'rep_group_act_monthly'.db_error();
1489 $res=db_query("DELETE FROM rep_group_act_daily WHERE group_id='".$this->getID()."'");
1490 //echo 'rep_group_act_daily'.db_error();
1491 unset($this->data_array);
1499 Basic functions to add/remove users to/from a group
1500 and update their permissions
1506 * addUser - controls adding a user to a group.
1508 * @param string Unix name of the user to add OR integer user_id.
1509 * @param int The role_id this user should have.
1510 * @return boolean success.
1513 function addUser($user_unix_name,$role_id) {
1516 Admins can add users to groups
1519 $perm =& $this->getPermission( session_get_user() );
1520 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1521 $this->setPermissionDeniedError();
1527 get user id for this user's unix_name
1529 if (eregi('[^0-9]',$user_unix_name)) {
1530 $res_newuser = db_query("SELECT * FROM users WHERE user_name='". strtolower($user_unix_name) ."'");
1532 $res_newuser = db_query("SELECT * FROM users WHERE user_id='". intval($user_unix_name) ."'");
1534 if (db_numrows($res_newuser) > 0) {
1536 // make sure user is active
1538 if (db_result($res_newuser,0,'status') != 'A') {
1539 $this->setError(_('User is not active. Only active users can be added.'));
1545 // user was found - set new user_id var
1547 $user_id = db_result($res_newuser,0,'user_id');
1550 // if not already a member, add them
1552 $res_member = db_query("SELECT user_id
1554 WHERE user_id='$user_id' AND group_id='". $this->getID() ."'");
1556 if (db_numrows($res_member) < 1) {
1558 // Create this user's row in the user_group table
1560 $res=db_query("INSERT INTO user_group
1561 (user_id,group_id,admin_flags,forum_flags,project_flags,
1562 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
1563 VALUES ('$user_id','". $this->getID() ."','','0','0','0','1','100','0','0')");
1565 //verify the insert worked
1566 if (!$res || db_affected_rows($res) < 1) {
1567 $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
1572 // check and create if group doesn't exists
1574 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
1575 if (!$SYS->sysCheckCreateGroup($this->getID())){
1576 $this->setError($SYS->getErrorMessage());
1581 // check and create if user doesn't exists
1583 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1584 if (!$SYS->sysCheckCreateUser($user_id)) {
1585 $this->setError($SYS->getErrorMessage());
1592 $role = new Role($this,$role_id);
1593 if (!$role || !is_object($role)) {
1594 $this->setError(_('Error Getting Role Object'));
1597 } elseif ($role->isError()) {
1598 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1602 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
1603 if (!$role->setUser($user_id)) {
1604 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1610 // user was already a member
1611 // make sure they are set up
1613 $user=&user_get_object($user_id,$res_newuser);
1614 $user->fetchData($user->getID());
1615 $role = new Role($this,$role_id);
1616 if (!$role || !is_object($role)) {
1617 $this->setError(_('Error Getting Role Object'));
1620 } elseif ($role->isError()) {
1621 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1625 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
1626 if (!$role->setUser($user_id)) {
1627 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
1632 // set up their system info
1634 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
1635 if (!$SYS->sysCheckCreateUser($user_id)) {
1636 $this->setError($SYS->getErrorMessage());
1645 // user doesn't exist
1647 $this->setError(_('ERROR: User does not exist'));
1652 $hook_params['group'] = $this;
1653 $hook_params['group_id'] = $this->getID();
1654 $hook_params['user'] = &user_get_object($user_id);
1655 $hook_params['user_id'] = $user_id;
1656 plugin_hook ("group_adduser", $hook_params);
1661 $this->addHistory('Added User',$user_unix_name);
1667 * removeUser - controls removing a user from a group.
1669 * Users can remove themselves.
1671 * @param int The ID of the user to remove.
1672 * @return boolean success.
1674 function removeUser($user_id) {
1675 global $SYS,$sys_database_type;
1677 if ($user_id==user_getid()) {
1678 //users can remove themselves
1679 //everyone else must be a project admin
1681 $perm =& $this->getPermission( session_get_user() );
1683 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1684 $this->setPermissionDeniedError();
1690 $res=db_query("DELETE FROM user_group
1691 WHERE group_id='".$this->getID()."'
1692 AND user_id='$user_id'");
1693 if (!$res || db_affected_rows($res) < 1) {
1694 $this->setError(sprintf(_('ERROR: User not removed: %s'),db_error()));
1699 // reassign open artifacts to id=100
1701 $res=db_query("UPDATE artifact SET assigned_to='100'
1702 WHERE group_artifact_id
1703 IN (SELECT group_artifact_id
1704 FROM artifact_group_list
1705 WHERE group_id='".$this->getID()."')
1706 AND status_id='1' AND assigned_to='$user_id'");
1708 $this->setError(sprintf(_('ERROR: DB: artifact: %s'),db_error()));
1714 // reassign open tasks to id=100
1715 // first have to purge any assignments that would cause
1716 // conflict with existing assignment to 100
1718 if ($sys_database_type == 'mysql') {
1720 SELECT pt.project_task_id
1721 FROM project_task pt, project_group_list pgl, project_assigned_to pat
1722 WHERE pt.group_project_id = pgl.group_project_id
1723 AND pat.project_task_id=pt.project_task_id
1724 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."'
1725 AND pat.assigned_to_id='$user_id' INTO @task_list;
1726 DELETE FROM project_assigned_to WHERE project_task_id IN ( @task_list ) AND assigned_to_id='100'");
1728 $res = db_next_result();
1731 $res=db_query("DELETE FROM project_assigned_to
1732 WHERE project_task_id IN (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')
1738 AND assigned_to_id='100'");
1741 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),1,db_error()));
1745 $res=db_query("UPDATE project_assigned_to SET assigned_to_id='100'
1746 WHERE project_task_id IN (SELECT pt.project_task_id
1747 FROM project_task pt, project_group_list pgl
1748 WHERE pt.group_project_id = pgl.group_project_id
1749 AND pt.status_id='1' AND pgl.group_id='".$this->getID()."')
1750 AND assigned_to_id='$user_id'");
1752 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),2,db_error()));
1758 // Remove user from system
1760 //echo "<h2>Group::addUser SYS->sysGroupRemoveUser(".$this->getID().",$user_id)</h2>";
1761 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
1762 $this->setError($SYS->getErrorMessage());
1767 $this->addHistory('Removed User',$user_id);
1774 * updateUser - controls updating a user's role in this group.
1776 * @param int The ID of the user.
1777 * @param int The role_id to set this user to.
1778 * @return boolean success.
1780 function updateUser($user_id,$role_id) {
1783 $perm =& $this->getPermission( session_get_user() );
1784 if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
1785 $this->setPermissionDeniedError();
1789 $role = new Role($this,$role_id);
1790 if (!$role || !is_object($role)) {
1791 $this->setError(_('Could Not Get Role'));
1793 } elseif ($role->isError()) {
1794 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1797 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
1798 if (!$role->setUser($user_id)) {
1799 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
1803 $hook_params['group'] = $this;
1804 $hook_params['group_id'] = $this->getID();
1805 $hook_params['user'] = &user_get_object($user_id);
1806 $hook_params['user_id'] = $user_id;
1807 plugin_hook ("group_removeuser", $hook_params);
1809 $this->addHistory('Updated User',$user_id);
1814 * addHistory - Makes an audit trail entry for this project.
1816 * @param string The name of the field.
1817 * @param string The Old Value for this $field_name.
1818 * @return database result handle.
1821 function addHistory($field_name, $old_value) {
1823 INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
1824 VALUES ('". $this->getID() ."','$field_name','$old_value','". user_getid() ."','".time()."')
1826 return db_query($sql);
1830 * activateUsers - Make sure that group members have unix accounts.
1832 * Setup unix accounts for group members. Can be called even
1833 * if members are already active.
1837 function activateUsers() {
1840 Activate member(s) of the project
1843 $member_res = db_query("SELECT user_id, role_id
1845 WHERE group_id='".$this->getID()."'");
1847 $rows = db_numrows($member_res);
1851 for ($i=0; $i<$rows; $i++) {
1853 $member =& user_get_object(db_result($member_res,$i,'user_id'));
1854 $roleId = db_result($member_res,$i,'role_id');
1856 if (!$member || !is_object($member)) {
1857 $this->setError(_('Error getting member object'));
1859 } else if ($member->isError()) {
1860 $this->setError(sprintf(_('Error getting member object: %s'),$member->getErrorMessage()));
1864 if (!$this->addUser($member->getUnixName(),$roleId)) {
1875 * getMembers - returns array of User objects for this project
1877 * @return array of User objects for this group.
1879 function &getMembers() {
1880 if (!isset($this->membersArr)) {
1881 $res=db_query("SELECT users.* FROM users
1882 INNER JOIN user_group ON users.user_id=user_group.user_id
1883 WHERE user_group.group_id='".$this->getID()."'");
1884 while ($arr =& db_fetch_array($res)) {
1885 $this->membersArr[] =& new GFUser($arr['user_id'],$arr);
1888 return $this->membersArr;
1892 * approve - Approve pending project.
1894 * @param object The User object who is doing the updating.
1897 function approve(&$user) {
1899 if ($this->getStatus()=='A') {
1900 $this->setError(_("Group already active"));
1906 // Step 1: Activate group and create LDAP entries
1907 if (!$this->setStatus($user, 'A')) {
1914 // Tracker Integration
1917 $ats = new ArtifactTypes($this);
1918 if (!$ats || !is_object($ats)) {
1919 $this->setError(_('Error creating ArtifactTypes object'));
1922 } else if ($ats->isError()) {
1923 $this->setError(sprintf (_('ATS%d: %s'), 1, $ats->getErrorMessage()));
1927 if (!$ats->createTrackers()) {
1928 $this->setError(sprintf (_('ATS%d: %s'), 2, $ats->getErrorMessage()));
1935 // Forum Integration
1938 $f = new Forum($this);
1939 if (!$f->create('Open-Discussion','General Discussion',1,'',1,0)) {
1940 $this->setError(sprintf (_('F%d: %s'), 1, $f->getErrorMessage()));
1944 $f = new Forum($this);
1945 if (!$f->create('Help','Get Public Help',1,'',1,0)) {
1946 $this->setError(sprintf (_('F%d: %s'), 2, $f->getErrorMessage()));
1950 $f = new Forum($this);
1951 if (!$f->create('Developers','Project Developer Discussion',0,'',1,0)) {
1952 $this->setError(sprintf (_('F%d: %s'), 3, $f->getErrorMessage()));
1959 // Doc Mgr Integration
1962 $dg = new DocumentGroup($this);
1963 if (!$dg->create('Uncategorized Submissions')) {
1964 $this->setError(sprintf(_('DG: %s'),$dg->getErrorMessage()));
1974 $frs = new FRSPackage($this);
1975 if (!$frs->create($this->getUnixName())) {
1976 $this->setError(sprintf(_('FRSP: %s'),$frs->getErrorMessage()));
1986 $pg = new ProjectGroup($this);
1987 if (!$pg->create('To Do','Things We Have To Do',1)) {
1988 $this->setError(sprintf(_('PG%d: %s'),1,$pg->getErrorMessage()));
1992 $pg = new ProjectGroup($this);
1993 if (!$pg->create('Next Release','Items For Our Next Release',1)) {
1994 $this->setError(sprintf(_('PG%d: %s'),2,$pg->getErrorMessage()));
2001 // Set Default Roles
2004 $role = new Role($this);
2005 $todo = array_keys($role->defaults);
2006 for ($c=0; $c<count($todo); $c++) {
2007 $role = new Role($this);
2008 if (!$role->createDefault($todo[$c])) {
2009 $this->setError(sprintf(_('R%d: %s'),$c,$role->getErrorMessage()));
2015 $admin_group = db_query("SELECT user_id FROM user_group
2016 WHERE group_id=".$this->getID()." AND admin_flags='A'");
2017 if (db_numrows($admin_group) > 0) {
2018 $idadmin_group = db_result($admin_group,0,'user_id');
2025 // Create MailingList
2028 if ($GLOBALS['sys_use_mail']) {
2029 $mlist = new MailingList($this);
2030 if (!$mlist->create('commits','Commits',1,$idadmin_group)) {
2031 $this->setError(sprintf(_('ML: %s'),$mlist->getErrorMessage()));
2039 $this->sendApprovalEmail();
2040 $this->addHistory('Approved', 'x');
2043 //change assistant for webcal
2045 $params[0] = $idadmin_group ;
2046 $params[1] = $this->getID();
2047 plugin_hook('change_cal_permission_default',$params);
2055 * sendApprovalEmail - Send new project email.
2057 * @return boolean success.
2060 function sendApprovalEmail() {
2061 $res_admins = db_query("
2062 SELECT users.user_name,users.email,users.language,users.user_id
2063 FROM users,user_group
2064 WHERE users.user_id=user_group.user_id
2065 AND user_group.group_id='".$this->getID()."'
2066 AND user_group.admin_flags='A'
2069 if (db_numrows($res_admins) < 1) {
2070 $this->setError(_("Group does not have any administrators."));
2074 // send one email per admin
2075 while ($row_admins = db_fetch_array($res_admins)) {
2076 $admin =& user_get_object($row_admins['user_id']);
2077 setup_gettext_for_user ($admin) ;
2079 $message=stripcslashes(sprintf(_('Your project registration for %4$s has been approved.
2081 Project Full Name: %1$s
2082 Project Unix Name: %2$s
2084 Your DNS will take up to a day to become active on our site.
2085 Your web site is accessible through your shell account. Please read
2086 site documentation (see link below) about intended usage, available
2087 services, and directory layout of the account.
2090 own project page in %4$s while logged in, you will find
2091 additional menu functions to your left labeled \'Project Admin\'.
2093 We highly suggest that you now visit %4$s and create a public
2094 description for your project. This can be done by visiting your project
2095 page while logged in, and selecting \'Project Admin\' from the menus
2096 on the left (or by visiting %3$s
2099 Your project will also not appear in the Trove Software Map (primary
2100 list of projects hosted on %4$s which offers great flexibility in
2101 browsing and search) until you categorize it in the project administration
2102 screens. So that people can find your project, you should do this now.
2103 Visit your project while logged in, and select \'Project Admin\' from the
2106 Enjoy the system, and please tell others about %4$s. Let us know
2107 if there is anything we can do to help you.
2110 $this->getPublicName(),
2111 $this->getUnixName(),
2112 util_make_url ('/project/admin/?group_id='.$this->getID()),
2113 $GLOBALS['sys_name']));
2115 util_send_message($row_admins['email'], sprintf(_('%1$s Project Approved'), $GLOBALS['sys_name']), $message);
2117 setup_gettext_from_browser () ;
2125 * sendRejectionEmail - Send project rejection email.
2127 * This function sends out a rejection message to a user who
2128 * registered a project.
2130 * @param int The id of the response to use.
2131 * @param string The rejection message.
2132 * @return completion status.
2135 function sendRejectionEmail($response_id, $message="zxcv") {
2136 $res_admins = db_query("
2137 SELECT u.email, u.language, u.user_id
2138 FROM users u, user_group ug
2139 WHERE ug.group_id='".$this->getID()."'
2140 AND u.user_id=ug.user_id;
2143 if (db_numrows($res_admins) < 1) {
2144 $this->setError(_("Group does not have any administrators."));
2148 while ($row_admins = db_fetch_array($res_admins)) {
2149 $admin =& user_get_object($row_admins['user_id']);
2150 setup_gettext_for_user ($admin) ;
2152 $response=stripcslashes(sprintf(_('Your project registration for %3$s has been denied.
2154 Project Full Name: %1$s
2155 Project Unix Name: %2$s
2157 Reasons for negative decision:
2159 '), $this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name']));
2161 // Check to see if they want to send a custom rejection response
2162 if ($response_id == 0) {
2163 $response .= stripcslashes($message);
2165 $response .= db_result(db_query("
2166 SELECT response_text
2167 FROM canned_responses
2168 WHERE response_id='$response_id'
2169 "), 0, "response_text");
2172 util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), $GLOBALS['sys_name']), $response);
2173 setup_gettext_from_browser () ;
2180 * sendNewProjectNotificationEmail - Send new project notification email.
2182 * This function sends out a notification email to the
2183 * SourceForge admin user when a new project is
2186 * @return boolean success.
2189 function sendNewProjectNotificationEmail() {
2190 // Get the user who wants to register the project
2191 $res = db_query("SELECT u.user_id
2192 FROM users u, user_group ug
2193 WHERE ug.group_id='".$this->getID()."' AND u.user_id=ug.user_id;");
2195 if (db_numrows($res) < 1) {
2196 $this->setError(_("Could not find user who has submitted the project."));
2200 $submitter =& user_get_object(db_result($res,0,'user_id'));
2203 $res = db_query("SELECT users.email, users.language, users.user_id
2204 FROM users,user_group
2206 AND user_group.admin_flags='A'
2207 AND users.user_id=user_group.user_id;");
2209 if (db_numrows($res) < 1) {
2210 $this->setError(_("There is no administrator to send the mail."));
2214 for ($i=0; $i<db_numrows($res) ; $i++) {
2215 $admin_email = db_result($res,$i,'email') ;
2216 $admin =& user_get_object(db_result($res,$i,'user_id'));
2217 setup_gettext_for_user ($admin) ;
2219 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2221 Project Full Name: %2$s
2222 Submitted Description: %3$s
2224 Submitter: %6$s (%7$s)
2226 Please visit the following URL to approve or reject this project:
2228 $GLOBALS['sys_name'],
2229 $this->getPublicName(),
2230 util_unconvert_htmlspecialchars($this->getRegistrationPurpose()),
2231 $this->getLicenseName(),
2232 util_make_url ('/admin/approve-pending.php'),
2233 $submitter->getRealName(),
2234 $submitter->getUnixName()));
2235 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2236 setup_gettext_from_browser () ;
2240 $email = $submitter->getEmail() ;
2241 setup_gettext_for_user ($submitter) ;
2243 $message=stripcslashes(sprintf(_('New %1$s Project Submitted
2245 Project Full Name: %2$s
2246 Submitted Description: %3$s
2249 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']));
2251 util_send_message($email, sprintf(_('New %1$s Project Submitted'), $GLOBALS['sys_name']), $message);
2252 setup_gettext_from_browser () ;
2259 * group_getname() - get the group name
2261 * @param int The group ID
2265 function group_getname ($group_id = 0) {
2266 $grp = &group_get_object($group_id);
2268 return $grp->getPublicName();
2275 * group_getunixname() - get the unixname for a group
2277 * @param int The group ID
2281 function group_getunixname ($group_id) {
2282 $grp = &group_get_object($group_id);
2284 return $grp->getUnixName();
2291 * group_get_result() - Get the group object result ID.
2293 * @param int The group ID
2297 function &group_get_result($group_id=0) {
2298 $grp = &group_get_object($group_id);
2300 return $grp->getData();
2307 * getUnixStatus - Status of activation of unix account.
2309 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2311 function getUnixStatus() {
2312 return $this->data_array['unix_status'];
2316 * setUnixStatus - Sets status of activation of unix account.
2318 * @param string The unix status.
2324 * @return boolean success.
2326 function setUnixStatus($status) {
2331 SET unix_status='$status'
2332 WHERE group_id='". $this->getID()."'
2336 $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
2340 if ($status == 'A') {
2341 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2342 $this->setError($SYS->getErrorMessage());
2347 if ($SYS->sysCheckGroup($this->getID())) {
2348 if (!$SYS->sysRemoveGroup($this->getID())) {
2349 $this->setError($SYS->getErrorMessage());
2356 $this->data_array['unix_status']=$status;
2364 // c-file-style: "bsd"