File: Group.class

package info (click to toggle)
gforge 3.1-31sarge5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 9,148 kB
  • ctags: 11,865
  • sloc: sql: 27,860; php: 25,574; perl: 7,124; xml: 3,152; sh: 2,586; ansic: 315; makefile: 143
file content (1689 lines) | stat: -rw-r--r-- 41,572 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
<?php   
/**
 *	Group object
 *
 *	Sets up database results and preferences for a group and abstracts this info.
 *
 *	Foundry.class and Project.class call this.
 *
 *	Project.class contains all the deprecated API from the old group.php file
 *
 *	DEPENDS on user.php being present and setup properly
 *
 *	GENERALLY YOU SHOULD NEVER INSTANTIATE THIS OBJECT DIRECTLY
 *	USE group_get_object() to instantiate properly
 *
 * @version   $Id: Group.class,v 1.33 2003/11/04 20:52:52 lo-lan-do Exp $
 * @author Tim Perdue <tperdue@valinux.com>
 * @date 2000-08-28
 *
 * This file is part of GForge.
 *
 * GForge is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * GForge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GForge; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

require_once('common/tracker/ArtifactTypes.class');
require_once('common/forum/Forum.class');
require_once('common/frs/FRSPackage.class');
require_once('common/docman/DocumentGroup.class');
require_once('www/include/BaseLanguage.class');

$GROUP_OBJ=array();

/**
 *  group_get_object() - Get the group object.
 *
 *  group_get_object() is useful so you can pool group objects/save database queries
 *  You should always use this instead of instantiating the object directly.
 *
 *  You can now optionally pass in a db result handle. If you do, it re-uses that query
 *  to instantiate the objects.
 *
 *  IMPORTANT! That db result must contain all fields
 *  from groups table or you will have problems
 *
 *  @param		int		Required
 *  @param		int		Result set handle ("SELECT * FROM groups WHERE group_id=xx")
 *  @return a group object or false on failure
 */
function &group_get_object($group_id,$res=false) {
	//create a common set of group objects
	//saves a little wear on the database

	//automatically checks group_type and 
	//returns appropriate object
	
	global $GROUP_OBJ;
	if (!isset($GROUP_OBJ["_".$group_id."_"])) {
		if ($res) {
			//the db result handle was passed in
		} else {
			$res=db_query("SELECT * FROM groups WHERE group_id='$group_id'");
		}
		if (!$res || db_numrows($res) < 1) {
			$GROUP_OBJ["_".$group_id."_"]=false;
		} else {
			/*
				check group type and set up object
			*/
			if (db_result($res,0,'type')==1) {
				//project
				$GROUP_OBJ["_".$group_id."_"]= new Group($group_id,$res);
			} else {
				//invalid
				$GROUP_OBJ["_".$group_id."_"]=false;
			}
		}
	}
	return $GROUP_OBJ["_".$group_id."_"];
}

function &group_get_object_by_name($groupname) {
	$res=db_query("SELECT * FROM groups WHERE unix_group_name='$groupname'");
	return group_get_object(db_result($res,0,'group_id'),$res);
}

class Group extends Error {
	/**
	 * Associative array of data from db.
	 * 
	 * @var array $data_array.
	 */
	var $data_array;

	/**
	 * Permissions data row from db.
	 * 
	 * @var array $perm_data_array.
	 */
	var $perm_data_array;

	/**
	 * Whether the use is an admin/super user of this project.
	 *
	 * @var bool $is_admin.
	 */
	var $is_admin;

	/**
	 * Artifact types result handle.
	 * 
	 * @var int $types_res.
	 */
	var $types_res;

	/**
	 * Associative array of data for plugins.
	 * 
	 * @var array $plugins_array.
	 */
	var $plugins_array;

	/**
	 *	Group - Group object constructor - use group_get_object() to instantiate.
	 *
	 *	@param	int		Required - group_id of the group you want to instantiate.
	 *	@param	int		Database result from select query.
	 */
	function Group($id=false, $res=false) {
		$this->Error();
		if (!$id) {
			//setting up an empty object
			//probably going to call create()
			return true;
		}
		if (!$res) {
			if (!$this->fetchData($id)) {
				return false;
			}
		} else {
			if (db_numrows($res) < 1) {
				//function in class we extended
				$this->setError('Group Not Found');
				$this->data_array=array();
				return false;
			} else {
				//set up an associative array for use by other functions
				db_reset_result($res);
				$this->data_array =& db_fetch_array($res);
			}
		}
//
//	Need to add a check if this is not public, verify user is logged in and isMember
//
		return true;
	}

	/**
	 *	fetchData - May need to refresh database fields if an update occurred.
	 *
	 *	@param	int	The group_id.
	 */
	function fetchData($group_id) {
		$res = db_query("SELECT * FROM groups WHERE group_id='$group_id'");
		if (!$res || db_numrows($res) < 1) {
			$this->setError('fetchData():: '.db_error());
			return false;
		}
		$this->data_array =& db_fetch_array($res);
		return true;
	}

	/**
	 *	create - Create new group.
	 *
	 *	This method should be called on empty Group object.
	 *  
	 *  @param	object	The User object.
	 *  @param	string	The full name of the user.
	 *  @param	string	The Unix name of the user.
	 *  @param	string	The new group description.
	 *  @param	int	The ID of the license to use.
	 *  @param	string	The 'other' license to use if any.
	 *  @param	string	The purpose of the group.
	 */
	function create(&$user, $full_name, $unix_name, $description, $license, $license_other, $purpose, $unix_box='shell1', $cvs_box='cvs1') {

		// $user is ignored - anyone can create pending group

		if ($this->getID()!=0) {
			$this->setError("Group::create: Group object already exists");
			return false;
		}

		srand((double)microtime()*1000000);
		$random_num = rand(0,1000000);

		db_begin();

		$res = db_query("
			INSERT INTO groups (
				group_name,
				is_public,
				unix_group_name,
				short_description,
				http_domain,
				homepage,
				status,
				unix_box,
				cvs_box,
				license,
				register_purpose,
				register_time,
				license_other,
				rand_hash
			)
			VALUES (
				'".htmlspecialchars($full_name)."',
				1,
				'$unix_name',
				'".htmlspecialchars($description)."',
				'$unix_name.".$GLOBALS['sys_default_domain']."',
				'$unix_name.".$GLOBALS['sys_default_domain']."',
				'P',
				'$unix_box',
				'$cvs_box',
				'$license',
				'".htmlspecialchars($purpose)."',
				".time().",
				'".htmlspecialchars($license_other)."',
				'".md5($random_num)."'
			)
		");

		if (!$res || db_affected_rows($res) < 1) {
			$this->setError('ERROR: Could not create group: '.db_error());
			db_rollback();
			return false;
		}

		$id = db_insertid($res, 'groups', 'group_id');

		//
		// Now, make the user an admin
		//
		$res = db_query("
			INSERT INTO user_group (
				user_id,
				group_id,
				admin_flags,
				cvs_flags,
				artifact_flags,
				forum_flags
			)
			VALUES (
				".$user->getID().",
				'$id',
				'A',
				1,
				2,
				2
			)
		");

		if (!$res || db_affected_rows($res) < 1) {
			$this->setError('ERROR: Could not add admin to newly created group: '.db_error());
			db_rollback();
			return false;
		}

		if (!$this->fetchData($id)) {
			db_rollback();
			return false;
		}
		db_commit();
		$this->sendNewProjectNotificationEmail();
		return true;
	}


	/**
	 *	updateAdmin - Update core properties of group object.
	 *
	 *	This function require site admin privilege.
	 *
	 *	@param	object	User requesting operation (for access control).
	 *	@param	bool	Whether group is publicly accessible (0/1).
	 *	@param	string	Project's license (string ident).
	 *	@param	int		Group type (1-project, 2-foundry).
	 *	@param	string	Machine on which group's home directory located.
	 *	@param	string	Domain which serves group's WWW.
	 *	@return status.
	 *	@access public.
	 */
	function updateAdmin(&$user, $is_public, $license, $type, $unix_box, $http_domain) {
		global $Language;

		$perm =& $this->getPermission($user);

		if (!$perm || !is_object($perm)) {
			$this->setError($Language->getText('general','permnotget'));
			return false;
		}

		if (!$perm->isSuperUser()) {
			$this->setError($Language->getText('general','permdenied'));
			return false;
		}

		db_begin();

		$res = db_query("
			UPDATE groups
			SET is_public='$is_public',
				license='$license',type='$type',
				unix_box='$unix_box',http_domain='$http_domain'
			WHERE group_id='".$this->getID()."'
		");

		if (!$res || db_affected_rows($res) < 1) {
			$this->setError('ERROR: DB: Could not change group properties: '.db_error());
			db_rollback();
			return false;
		}

		// Log the audit trail
		if ($is_public != $this->isPublic()) {
			$this->addHistory('is_public', $this->isPublic());
		}
		if ($license != $this->data_array['license']) {
			$this->addHistory('license', $this->data_array['license']);
		}
		if ($type != $this->data_array['type']) {
			$this->addHistory('type', $this->data_array['type']);
		}
		if ($unix_box != $this->data_array['unix_box']) {
			$this->addHistory('unix_box', $this->data_array['unix_box']);
		}
		if ($http_domain != $this->data_array['http_domain']) {
			$this->addHistory('http_domain', $this->data_array['http_domain']);
		}

		if (!$this->fetchData($this->getID())) {
			db_rollback();
			return false;
		}
		db_commit();
		return true;
	}

	/**
	 *	update - Update number of common properties.
	 *
	 *	Unlike updateAdmin(), this function accessible to project admin.
	 *
	 *	@param	object	User requesting operation (for access control).
	 *	@param	bool	Whether group is publicly accessible (0/1).
	 *	@param	string	Project's license (string ident).
	 *	@param	int		Group type (1-project, 2-foundry).
	 *	@param	string	Machine on which group's home directory located.
	 *	@param	string	Domain which serves group's WWW.
	 *	@return int	status.
	 *	@access public.
	 */
	function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,
		$use_pm,$use_pm_depend_box,$use_cvs,$use_news,$use_docman,
		$new_doc_address,$send_all_docs,$logo_image_id,
		$enable_pserver,$enable_anoncvs,
		$use_ftp,$use_tracker,$use_frs,$use_stats) {
		global $Language;

		$perm =& $this->getPermission($user);

		if (!$perm || !is_object($perm)) {
			$this->setError($Language->getText('general','permnotget'));
			return false;
		}

		if (!$perm->isAdmin()) {
			$this->setError($Language->getText('general','permdenied'));
			return false;
		}

		// Validate some values
		if (!$group_name) {
			$this->setError('Invalid Group Name');
			return false;
		}

		if ($new_doc_address && !validate_email($new_doc_address)) {
			$this->setError('New Doc Address Appeared Invalid');
			return false;
		}

		// in the database, these all default to '1',
		// so we have to explicity set 0
		if (!$use_mail) {
			$use_mail=0;
		}
		if (!$use_survey) {
			$use_survey=0;
		}
		if (!$use_forum) {
			$use_forum=0;
		}
		if (!$use_pm) {
			$use_pm=0;
		}
		if (!$use_pm_depend) {
			$use_pm_depend=0;
		}
		if (!$use_cvs) {
			$use_cvs=0;
		}
		if (!$use_news) {
			$use_news=0;
		}
		if (!$use_docman) {
			$use_docman=0;
		}
		if (!$send_all_tasks) {
			$send_all_tasks=0;
		}
		if (!$enable_pserver) {
			$enable_pserver=0;
		}
		if (!$enable_anoncvs) {
			$enable_anoncvs=0;
		}
		if (!$use_ftp) {
			$use_ftp=0;
		}
		if (!$use_tracker) {
			$use_tracker=0;
		}
		if (!$use_frs) {
			$use_frs=0;
		}
		if (!$use_stats) {
			$use_stats=0;
		}
		if (!$send_all_docs) {
			$send_all_docs=0;
		}

		if (!$homepage) {
			$homepage='http://'.$GLOBALS['sys_default_domain'].'/projects/'.$this->getUnixName().'/';
		}

		if (strlen($short_description)>255) {
			$this->setError('Error updating project information: Maximum length for Project Description is 255 chars.');
			return false;
		}

		db_begin();

		//XXX not yet actived logo_image_id='$logo_image_id', 
		$sql = "
			UPDATE groups
			SET 
				group_name='".htmlspecialchars($group_name)."',
				homepage='$homepage',
				short_description='".htmlspecialchars($short_description)."',
				use_mail='$use_mail',
				use_survey='$use_survey',
				use_forum='$use_forum',
				use_pm='$use_pm',
				use_pm_depend_box='$use_pm_depend_box',
				use_cvs='$use_cvs',
				use_news='$use_news',
				use_docman='$use_docman',
				new_doc_address='$new_doc_address',
				send_all_docs='$send_all_docs',
				enable_pserver='$enable_pserver',
				enable_anoncvs='$enable_anoncvs',
				use_ftp='$use_ftp',
				use_tracker='$use_tracker',
				use_frs='$use_frs',
				use_stats='$use_stats'
			WHERE group_id='".$this->getID()."'
		";
		$res = db_query($sql);

		if (!$res || db_affected_rows($res) < 1) {
			$this->setError('Error updating project information: '.db_error());
			db_rollback();
			return false;
		}

		// Log the audit trail
		$this->addHistory('Changed Public Info', '');

		if (!$this->fetchData($this->getID())) {
			db_rollback();
			return false;
		}
		db_commit();
		return true;
	}

	/**
	 *	getID - Simply return the group_id for this object.
	 *
	 *	@return int group_id.
	 */
	function getID() {
		return $this->data_array['group_id'];
	}

	/**
	 *	getType() - Foundry, project, etc.
	 *
	 *	@return	int	The type flag from the database.
	 */
	function getType() {
		return $this->data_array['type'];
	}


	/**
	 *	getStatus - the status code.
	 *
	 *	Statuses	char	include I,H,A,D.
	 */
	function getStatus() {
		return $this->data_array['status'];
	}

	/**
	 *	setStatus - set the status code.
	 *
	 *	Statuses include I,H,A,D.
	 *
	 *	@param	object	User requesting operation (for access control).
	 *	@param	string	Status value.
	 *	@return	boolean	success.
	 *	@access public.
	 */
	function setStatus(&$user, $status) {
		global $Language;

		$perm =& $this->getPermission($user);

		if (!$perm || !is_object($perm)) {
			$this->setError($Language->getText('general','permnotget'));
			return false;
		}

		if (!$perm->isSuperUser()) {
			$this->setError($Language->getText('general','permdenied'));
			return false;
		}

		//	Projects in 'A' status can only go to 'H' or 'D'
		//	Projects in 'D' status can only go to 'A'
		//	Projects in 'P' status can only go to 'A' OR 'D'
		//	Projects in 'I' status can only go to 'P'
		//	Projects in 'H' status can only go to 'A' OR 'D'
		$allowed_status_changes = array(
			'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
			'IP'=>1,'HA'=>1,'HD'=>1
		);			  

		// Check that status transition is valid
		if ($this->getStatus() != $status
			&& !$allowed_status_changes[$this->getStatus().$status]) {
			$this->setError('Invalid Status Change');
			return false;
		}

		db_begin();

		$res = db_query("
			UPDATE groups
			SET status='$status'
			WHERE group_id='". $this->getID()."'
		");

		if (!$res || db_affected_rows($res) < 1) {
			$this->setError('ERROR: DB: Could not change group status: '.db_error());
			db_rollback();
			return false;
		}

		if ($status=='A') {
			// Activate LDAP group, if not yet
			if (!sf_ldap_check_group($this->getID())) {

				if (!sf_ldap_create_group($this->getID())) {
					$this->setError(sf_ldap_get_error_msg());
					db_rollback();
					return false;
				}

				if (!$this->activateUsers()) {
					db_rollback();
					return false;
				}
			}

		/* Otherwise, the group is not active, and make sure that
		   LDAP group is not active either */
		} else if (sf_ldap_check_group($this->getID())) {

			if (!sf_ldap_remove_group($this->getID())) {
				$this->setError(sf_ldap_get_error_msg());
				db_rollback();
				return false;
			}

		}

		// Make sure that active group have default trackers
		if ($status=='A') {
			$ats = new ArtifactTypes($this);
			if (!$ats || !is_object($ats)) {
				$this->setError('Error creating ArtifactTypes object');
				db_rollback();
				return false;
			} else if ($ats->isError()) {
				$this->setError($ats->getErrorMessage());
				db_rollback();
				return false;
			}
			if (!$ats->createTrackers()) {
				$this->setError($ats->getErrorMessage());
				db_rollback();
				return false;
			}
		}

		db_commit();

		// Log the audit trail
		if ($status != $this->getStatus()) {
			$this->addHistory('status', $this->getStatus());
		}

		$this->data_array['status'] = $status;
		return true;
	}

	/**
	 *	isProject - Simple boolean test to see if it's a project or not.
	 *
	 *	@return	boolean is_project.
	 */
	function isProject() {
		if ($this->getType()==1) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 *	isPublic - Simply returns the is_public flag from the database.
	 *
	 *	@return	boolean	is_public.
	 */
	function isPublic() {
		return $this->data_array['is_public'];
	}

	/**
	 *	isActive - Database field status of 'A' returns true.
	 *
	 *	@return	boolean	is_active.
	 */
	function isActive() {
		if ($this->getStatus()=='A') {
			return true;
		} else {
			return false;
		}
	}

	/**
	 *  getUnixName - the unix_name
	 *
	 *  @return	string	unix_name.
	 */
	function getUnixName() {
		return strtolower($this->data_array['unix_group_name']);
	}

	/**
	 *  getPublicName - the full-length public name.
	 *
	 *  @return	string	The group_name.
	 */
	function getPublicName() {
		return htmlspecialchars($this->data_array['group_name']);
	}

	/**
	 *  getRegisterPurpose - the text description of the purpose of this project.
	 *
	 *  @return	string	The description.
	 */
	function getRegisterPurpose() {
		return $this->data_array['register_purpose'];
	}

	/**
	 *  getDescription	- the text description of this project.
	 *
	 *  @return	string	The description.
	 */
	function getDescription() {
		return $this->data_array['short_description'];
	}

	/**
	 *  getStartDate - the unix time this project was registered.
	 *
	 *  @return int (unix time) of registration.
	 */
	function getStartDate() {
		return $this->data_array['register_time'];
	}

	/**
	 *  getLogoImageID - the id of the logo in the database for this project.
	 *
	 *  @return	int	The ID of logo image in db_images table (or 100 if none).
	 */
	function getLogoImageID() {
		return $this->data_array['logo_image_id'];
	}

	/**
	 *  getUnixBox - the hostname of the unix box where this project is located.
	 *
	 *  @return	string	The name of the unix machine for the group.
	 */
	function getUnixBox() {
		return $this->data_array['unix_box'];
	}

	/**
	 *  getDomain - the hostname.domain where their web page is located.
	 *
	 *  @return	string	The name of the group [web] domain.
	 */
	function getDomain() {
		return $this->data_array['http_domain'];
	}

	/**
	 *  getLicense	- the license they chose.
	 *
	 *  @return	string	ident of group license.
	 */
	function getLicense() {
		return $this->data_array['license'];
	}

	/**
	 *  getLicenseOther - optional string describing license.
	 *
	 *  @return	string	The custom license.
	 */
	function getLicenseOther() {
		if ($this->getLicense() == 'other') {
			return $this->data_array['license_other'];
		} else {
			return '';
		}
	}

	/**
	 *  getRegistrationPurpose - the text description of the purpose of this project.
	 *
	 *  @return	string	The application for project hosting.
	 */
	function getRegistrationPurpose() {
		return $this->data_array['register_purpose'];
	}


	/**
	 * getGroupAdmins() - Get group admin list
	 *
	 */
	function getGroupAdmins() {
		    // this function gets all group admins in order to send Jabber and mail messages
		    $q = "SELECT user_id FROM user_group WHERE admin_flags = 'A' AND group_id = ".$this->getID();
		    //echo($q."<br/>");
		    $res = db_query($q);
		    $users = array();
		    for($i=0;$i<db_numrows($res);$i++)
			array_push($users,db_result($res,$i,'user_id'));
		    return implode(",",$users);
	}
		
	/**
	 * getMemberRole() - Get member role
	 *
	 * @param	   int	 The user ID
	 *
	 */
	function getMemberRole($user_id) {
		    $q = "SELECT member_role FROM user_group WHERE user_id = $user_id AND group_id = ".$this->getID();
		    $res = db_query($q);
		    if(db_numrows($res))
		    {
			return db_result($res,0,'member_role');
		    }
		    return 0;
	}
		
	/*

		Common Group preferences for tools

	*/

	/**
	 *	enableAnonCVS - whether or not this group has opted to enable Anonymous CVS.
	 *
	 *	@return boolean enable_cvs.
	 */
	function enableAnonCVS() {
		return $this->data_array['enable_anoncvs'];
	}

	/**
	 *	enablePserver - whether or not this group has opted to enable Pserver.
	 *
	 *	@return boolean	enable_pserver.
	 */
	function enablePserver() {
		return $this->data_array['enable_pserver'];
	}

	/**
	 *	usesCVS - whether or not this group has opted to use CVS.
	 *
	 *	@return	boolean	uses_cvs.
	 */
	function usesCVS() {
		return $this->data_array['use_cvs'];
	}

	/**
	 *	usesMail - whether or not this group has opted to use mailing lists.
	 *
	 *	@return	boolean uses_mail.
	 */
	function usesMail() {
		return $this->data_array['use_mail'];
	}

	/**
	 * 	usesNews - whether or not this group has opted to use news.
	 *
	 *	@return	boolean	uses_news.
	 */
	function usesNews() {
		return $this->data_array['use_news'];
	}

	/**
	 *	usesForum - whether or not this group has opted to use discussion forums.
	 *
	 *  @return	boolean	uses_forum.
	 */
	function usesForum() {
		return $this->data_array['use_forum'];
	}	   

	/**
	 *  usesStats - whether or not this group has opted to use stats.
	 *
	 *  @return	boolean	uses_stats.
	 */
	function usesStats() {
		return $this->data_array['use_stats'];
	}

	/**
	 *  usesFRS - whether or not this group has opted to use file release system.
	 *
	 *  @return	boolean	uses_frs.
	 */
	function usesFRS() {
		return $this->data_array['use_frs'];
	}

	/**
	 *  usesTracker - whether or not this group has opted to use tracker.
	 *
	 *  @return	boolean	uses_tracker.
	 */
	function usesTracker() {
		return $this->data_array['use_tracker'];
	}

	/**
	 *  usesDocman - whether or not this group has opted to use docman.
	 *
	 *  @return	boolean	uses_docman.
	 */
	function usesDocman() {
		return $this->data_array['use_docman'];
	}

	/**
	 *  usesFTP - whether or not this group has opted to use FTP.
	 *
	 *  @return	boolean	uses_ftp.
	 */
	function usesFTP() {
		return $this->data_array['use_ftp'];
	}

	/**
	 *  usesSurvey - whether or not this group has opted to use surveys.
	 *
	 *  @return	boolean	uses_survey.
	 */
	function usesSurvey() {
		return $this->data_array['use_survey'];
	}	   

	/**
	 *  usesPM - whether or not this group has opted to Project Manager.
	 *
	 *  @return	boolean	uses_projman.
	 */
	function usesPM() {
		return $this->data_array['use_pm'];
	}

	function getPlugins() {
		if (!isset($this->plugins_data)) {
			$this->plugins_data = array () ;
			$sql="SELECT group_plugin.plugin_id, plugins.plugin_name
							  FROM group_plugin, plugins
				  WHERE group_plugin.group_id=".$this->getID()."
								AND group_plugin.plugin_id = plugins.plugin_id" ;
			$res=db_query($sql);
			$rows = db_numrows($res);

			for ($i=0; $i<$rows; $i++) {
				$plugin_id = db_result($res,$i,'plugin_id');
				$this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
			}
		}
		return $this->plugins_data ;
	}

	function usesPlugin($pluginname) {
		$plugins_data = $this->getPlugins() ;
		foreach ($plugins_data as $p_id => $p_name) {
			if ($p_name == $pluginname) {
				return true ;
			}
		}
		return false ;
	}

	function setPluginUse($pluginname, $val=true) {
		if ($val == $this->usesPlugin($pluginname)) {
			// State is already good, returning
			return true ;
		}
		$sql="SELECT plugin_id
			  FROM plugins
			  WHERE plugin_name = '" . $pluginname . "'" ;
		$res=db_query($sql);
		$rows = db_numrows($res);
		if ($rows == 0) {
			// Error: no plugin by that name
			return false ;
		}
		$plugin_id = db_result($res,0,'plugin_id');
		// Invalidate cache
		unset ($this->plugins_data) ;
		if ($val) {
			$sql="INSERT INTO group_plugin (group_id, plugin_id)
							  VALUES (". $this->getID() . ", ". $plugin_id .")" ;
			$res=db_query($sql);
			return $res ;
		} else {
			$sql="DELETE FROM group_plugin
							  WHERE group_id = ". $this->getID() . "
								AND plugin_id = ". $plugin_id ;
			$res=db_query($sql);
			return $res ;
		}
	}

	/**
	 *  getDocEmailAddress - get email address to send doc notifications to.
	 *
	 *  @return	string	email address.
	 */
	function getDocEmailAddress() {
		return $this->data_array['new_doc_address'];
	}

	/**
	 *  DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
	 *
	 *  @return	boolean	email_on_all_doc_updates.
	 */
	function docEmailAll() {
		return $this->data_array['send_all_docs'];
	}


	/**
	 *	getHomePage - The URL for this project's home page.
	 *
	 *	@return	string	homepage URL.
	 */
	function getHomePage() {
		return $this->data_array['homepage'];
	}

	/**
	 *	getPermission - Return a Permission for this Group and the specified User.
	 *
	 *	@param	object	The user you wish to get permission for (usually the logged in user).
	 *	@return	object	The Permission.
	 */
	function &getPermission(&$_user) {
		return permission_get_object(&$this, &$_user);
	}


	/**
	 *	userIsAdmin - Return if for this Group the User is admin.
	 *
	 *	@return boolean	is_admin.
	 */
	function userIsAdmin() {
		$perm =& $this->getPermission( session_get_user() );
		return $perm->isAdmin();
	}

	/*


		Basic functions to add/remove users to/from a group
		and update their permissions


	*/

	/**
	 *	addUser - controls adding a user to a group.
	 *  
	 *  @param	string	Unix name of the user to add.
	 *	@return	boolean	success.
	 *	@access public.
	 */
	function addUser($user_unix_name) {
		/*
			Admins can add users to groups
		*/

		$perm =& $this->getPermission( session_get_user() );

		if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
			$this->setError('You Are Not An Admin For This Group');
			return false;
		}

		db_begin();
		
		/*
			get user id for this user's unix_name
		*/
		$res_newuser = db_query("SELECT * FROM users WHERE user_name='" . strtolower($user_unix_name) . "'");

		if (db_numrows($res_newuser) > 0) {
			//
			//	make sure user is active
			//
			if (db_result($res_newuser,0,'status') != 'A') {
				$this->setError('User is not active. Only active users can be added.');
				db_rollback();
				return false;
			}

			//
			//	user was found - set new user_id var
			//
			$form_newuid = db_result($res_newuser,0,'user_id');

			//
			//	if not already a member, add them
			//
			$res_member = db_query("SELECT user_id FROM user_group ".
				"WHERE user_id='$form_newuid' AND group_id='". $this->getID() ."'");

			if (db_numrows($res_member) < 1) {
				//
				//	user was not already a member
				//
				//	if no unix account, give them a unix_uid
				//
				if ( !db_result($res_newuser,0,'unix_uid') ) {
					$user=&user_get_object($form_newuid,$res_newuser);
					if (!$user->setUpUnixUID()) {
						$this->setError('ERROR: Cannot assign UNIX uid to the user');
						db_rollback();
						return false;
					}
					if (!sf_ldap_create_user($form_newuid)) {
						$this->setError(sf_ldap_get_error_msg());
						db_rollback();
						return false;
					}
				} else {
					//
					//	User already had unix account
					//
					if (!sf_ldap_check_create_user($form_newuid)) {
						$this->setError(sf_ldap_get_error_msg());
						db_rollback();
						return false;
					}
				}
				//
				//	Create this user's row in the user_group table
				//
				$res=db_query("INSERT INTO user_group 
					(user_id,group_id,admin_flags,forum_flags,project_flags,
					doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
					VALUES ('$form_newuid','". $this->getID() ."','','0','0','0','1','100','0','0')");

				//verify the insert worked
				if (!$res || db_affected_rows($res) < 1) {
					$this->setError('ERROR: Could Not Add User To Group');
					db_rollback();
					return false;
				}
				//
				//	set up their ldap info
				//
				if (!sf_ldap_group_add_user($this->getID(),$form_newuid)) {
					$this->setError(sf_ldap_get_error_msg());
					db_rollback();
					return false;
				}

			} else {
				//
				//	user was already a member
				//	make sure they are set up with a unix_uid,
				//	LDAP entry and membership
				//
				$user=&user_get_object($form_newuid,$res_newuser);
				if (!$user->setUpUnixUID()) {
					$this->setError('ERROR: could not set up unix_uid for user: '.$user->getErrorMessage());
					db_rollback();
					return false;
				} else {
					$user->fetchData($user->getID());
					if (!sf_ldap_check_create_user($form_newuid)) {
						$this->setError(sf_ldap_get_error_msg());
						db_rollback();
						return false;
					}
						if (!sf_ldap_group_add_user($this->getID(),$form_newuid)) {
						$this->setError(sf_ldap_get_error_msg());
						db_rollback();
						return false;
					}
					db_commit();
					return true;
				}
			}
		} else {
			//
			//	user doesn't exist
			//
			$this->setError('ERROR: User does not exist on SourceForge');
			db_rollback();
			return false;
		}
		//
		//	audit trail
		//
		$this->addHistory('Added User',$user_unix_name);
		db_commit();
		return true;
	}

	/**
	 *  removeUser - controls removing a user from a group.
	 * 
	 *  Users can remove themselves.
	 *
	 *  @param	int		The ID of the user to remove.
	 *	@return	boolean	success.
	 */ 
	function removeUser($user_id) {

		if ($user_id==user_getid()) {
			//users can remove themselves
			//everyone else must be a project admin
		} else {
			$perm =& $this->getPermission( session_get_user() );

			if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
				$this->setError('You Are Not An Admin For This Group');
				return false;
			}
		}
		
		$res=db_query("SELECT * FROM user_group ".
			"WHERE group_id='".$this->getID()."' AND user_id='$user_id' AND admin_flags = 'A'");
		if (db_numrows($res) > 0) {
			$this->setError('Cannot remove admin');
			return false;
		}

		db_begin();
		$res=db_query("DELETE FROM user_group ".
			"WHERE group_id='".$this->getID()."' AND user_id='$user_id' AND admin_flags <> 'A'");
		if (!$res || db_affected_rows($res) < 1) {
			$this->setError('ERROR: DB: User not removed.');
			db_rollback();
			return false;
		} else {
			//
			//	remove them from artifact types
			//
			db_query("DELETE FROM artifact_perm 
				WHERE group_artifact_id 
				IN (SELECT group_artifact_id 
				FROM artifact_group_list 
				WHERE group_id='".$this->getID()."') 
				AND user_id='$user_id'");

			if (!sf_ldap_group_remove_user($this->getID(),$user_id)) {
				$this->setError(sf_ldap_get_error_msg());
				db_rollback();
				return false;
			}

			//audit trail
			$this->addHistory('removed user',$user_id);
		}
		db_commit();
		return true;
	}

	/**	 
	 *  updateUser - controls updating a user's perms in this group.
	 *
	 *  @param	int		The ID of the user.
	 *  @param	string	The admin flag for the user.
	 *  @param	int		The forum flag for the user.
	 *  @param	int		The project flag for the user.
	 *  @param	int		The doc flag for the user.
	 *  @param	int		The CVS flag for the user.
	 *  @param	int		The release flag for the user.
	 *	@param	int		The member role for the user.
	 *	@param	int		The artifact flags for the user.
	 *	@return	boolean	success.
	 */	 
	function updateUser($user_id,$admin_flags='',$forum_flags=0,$project_flags=1,$doc_flags=0,$cvs_flags=1,$release_flags=1,$member_role=100,$artifact_flags=0) {

	$perm =& $this->getPermission( session_get_user() );

	if (!$perm || !is_object($perm) || !$perm->isAdmin()) {
			$this->setError('You Are Not An Admin For This Group');
			return false;
		}

		if (user_getid() == $user_id) {
			$admin_flags='A';
		}
		$release_flags = ((!$release_flags) ? "0" : $release_flags);

		db_begin();
		$res = db_query("UPDATE user_group SET
			admin_flags='$admin_flags',
			forum_flags='$forum_flags',
			project_flags='$project_flags', 
			doc_flags='$doc_flags', 
			cvs_flags='$cvs_flags', 
			release_flags='$release_flags', 
			artifact_flags='$artifact_flags', 
			member_role='$member_role' 
			WHERE user_id='$user_id' AND group_id='". $this->getID() ."'");

		if (!$res || db_affected_rows($res) < 1) {
			$this->setError('ERROR: Could Not Change Member Permissions: '.db_error());
			db_rollback();
			return false;
		}

		//
		//	If user acquired admin access to CVS,
		//	one to be given normal shell on CVS machine,
		//	else - restricted.
		//
		if ($cvs_flags>1) {
			if (!sf_ldap_user_set_attribute($user_id,"debGforgeCvsShell","/bin/bash")) {
				$this->setError(sf_ldap_get_error_msg());
				db_rollback();
				return false;
			}
		} else {
			if (!sf_ldap_user_set_attribute($user_id,"debGforgeCvsShell","/bin/cvssh")) {
				$this->setError(sf_ldap_get_error_msg());
				db_rollback();
				return false;
			}
		}

		//
		//	If user acquired at least commit access to CVS,
		//	one to be promoted to CVS group, else, demoted.
		//
		if ($cvs_flags>0) {
			if (!sf_ldap_group_add_user($this->getID(),$user_id,1)) {
				$this->setError(sf_ldap_get_error_msg());
				db_rollback();
				return false;
			}
		} else {
			if (!sf_ldap_group_remove_user($this->getID(),$user_id,1)) {
				$this->setError(sf_ldap_get_error_msg());
				db_rollback();
				return false;
			}
		}


		db_commit();
		return true;
	}

	/**
	 *	addHistory - Makes an audit trail entry for this project.
	 *
	 *  @param	string	The name of the field.
	 *  @param	string	The Old Value for this $field_name.
	 *	@return database result handle.
	 *	@access public.
	 */
	function addHistory($field_name, $old_value) {
		$sql="
			INSERT INTO group_history(group_id,field_name,old_value,mod_by,date) 
			VALUES ('". $this->getID() ."','$field_name','$old_value','". user_getid() ."','".time()."')
		";
		return db_query($sql);
	}		  

	/**
	 *	activateUsers - Make sure that group members have unix accounts.
	 *
	 *	Setup unix accounts for group members. Can be called even
	 *	if members are already active. 
	 *
	 *	@access private.
	 */
	function activateUsers() {

		/*
			Activate member(s) of the project
		*/

		$member_res = db_query("
			SELECT *
			FROM users,user_group
			WHERE user_group.group_id='".$this->getID()."'
			AND users.user_id=user_group.user_id
		");

		$rows = db_numrows($member_res);

		if ($rows > 0) {

			for ($i=0; $i<$rows; $i++) {

				$member =& user_get_object(db_result($member_res,$i,'user_id'));

				if (!$member || !is_object($member)) {
					$this->setError('Error getting member object');
					return false;
				} else if ($member->isError()) {
					$this->setError('Error getting member object: '.$member->getErrorMessage());
					return false;
				}

				if (!$this->addUser($member->getUnixName())) {
					return false;
				}
			}

		 }

		 return true;
	}

	/**
	 *	approve - Approve pending project.
	 *
	 *	@param	object	The User object who is doing the updating.
	 *	@access public
	 */
	function approve(&$user) {

		if ($this->getStatus()=='A') {
			$this->setError("Group already active");
			return false;
		}

		db_begin();

		// Step 1: Activate group and create LDAP entries
		if (!$this->setStatus($user, 'A')) {
			db_rollback();
			return false;
		}

		//
		//
		//	Forum Integration
		//
		//
		// Step 2: Setup forums for this group
		$f = new Forum($this);
		if (!$f->create('Open Discussion','General Discussion',1,'',1,0)) {
			$this->setError($f->getErrorMessage());
			db_rollback();
			return false;
		}
		$f = new Forum($this);
		if (!$f->create('Help','Get Public Help',1,'',1,0)) {
			$this->setError($f->getErrorMessage());
			db_rollback();
			return false;
		}
		$f = new Forum($this);
		if (!$f->create('Developers','Project Developer Discussion',0,'',1,0)) {
			$this->setError($f->getErrorMessage());
			db_rollback();
			return false;
		}

		//
		//
		//	Doc Mgr Integration
		//
		//
		$dg = new DocumentGroup($this);
		if (!$dg->create('Uncategorized Submissions')) {
			$this->setError($dg->getErrorMessage());
			db_rollback();
			return false;
		}

		//
		//
		//	FRS integration
		//
		//
		// Step 4: Setup default filerelease package
		$frs = new FRSPackage($this);
		if (!$frs->create($this->getUnixName())) {
			$this->setError($frs->getErrorMessage());
			db_rollback();
			return false;
		}

		db_commit();

		$this->sendApprovalEmail();
		$this->addHistory('approved', 'x');

		return true;
	}



	/**
	 *	sendApprovalEmail - Send new project email.
	 *
	 *	@return	boolean	success.
	 *	@access public.
	 */
	function sendApprovalEmail() {
		$res_admins = db_query("
			SELECT users.user_name,users.email,users.language
			FROM users,user_group
			WHERE users.user_id=user_group.user_id
			AND user_group.group_id='".$this->getID()."'
			AND user_group.admin_flags='A'
		");

		if (db_numrows($res_admins) < 1) {
			$this->setError("Group does not have any administrators.");
			return false;
		}

		// send one email per admin
		while ($row_admins = db_fetch_array($res_admins)) {
			$l = new BaseLanguage () ;
			$l->loadLanguageID($row_admins['language']);

			//																			   $1					  $2					$3							  $4						  $5						$6
			$message=stripcslashes($l->getText('classgroup', 'acceptedproject', array($this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_default_domain'], $GLOBALS['sys_shell_host'], $GLOBALS['sys_cvs_host'], $this->getID(), $GLOBALS['sys_name'])));
	
			util_send_message($row_admins['email'], $l->getText('classgroup', 'acceptedprojecttitle', array($GLOBALS['sys_name'])), $message);
		}

		return true;
	}


	/**
	 *	sendRejectionEmail - Send project rejection email.
	 *
	 *	This function sends out a rejection message to a user who
	 *	registered a project.
	 *
	 *	@param	int	The id of the response to use.
	 *	@param	string	The rejection message.
	 *	@return completion status.
	 *	@access public.
	 */
	function sendRejectionEmail($response_id, $message="zxcv") {
		$res_admins = db_query("
			SELECT u.email, u.language
			FROM users u, user_group ug
			WHERE ug.group_id='".$this->getID()."'
			AND u.user_id=ug.user_id;
		");

		if (db_numrows($res_admins) < 1) {
			$this->setError("Group does not have any administrators.");
			return false;
		}
		
		while ($row_admins = db_fetch_array($res_admins)) {
			$l = new BaseLanguage () ;
			$l->loadLanguageID($row_admins['language']);

			$response=stripcslashes($l->getText('classgroup', 'rejectedproject', array($this->getPublicName(), $this->getUnixName(), $GLOBALS['sys_name'])));

			// Check to see if they want to send a custom rejection response
			if ($response_id == 0) {
				$response .= stripcslashes($message);
			} else {
				$response .= db_result(db_query("
				SELECT response_text
				FROM canned_responses
				WHERE response_id='$response_id'
			"), 0, "response_text");
			}

			util_send_message($row_admins['email'], $l->getText('classgroup', 'rejectedprojecttitle', array($GLOBALS['sys_name'])), $response);
		}

		return true;
	}

	/**
	 *	sendNewProjectNotificationEmail - Send new project notification email.
	 *
	 *	This function sends out a notification email to the
	 *	SourceForge admin user when a new project is
	 *	submitted.
	 *
	 *	@return	boolean	success.
	 *	@access public.
	 */
	function sendNewProjectNotificationEmail() {

		$res = db_query("SELECT users.email, users.language
	 			FROM users,user_group
				WHERE group_id=1 
				AND user_group.admin_flags='A'
				AND users.user_id=user_group.user_id;");
		
		if (db_numrows($res) < 1) {
			$this->setError("There is no administrator to send the mail.");
			return false;
		} else {
			for ($i=0; $i<db_numrows($res) ; $i++) {
				$admin_email = db_result($res,$i,'email') ;
				$l = new BaseLanguage () ;
				$l->loadLanguageID(db_result($res,$i,'language'));
				
				$message=stripcslashes($l->getText('classgroup', 'newprojectnotification', array($GLOBALS['sys_name'], $this->getPublicName(), $this->getRegistrationPurpose(), $this->getLicense(), $GLOBALS['sys_default_domain'])));
				util_send_message($admin_email, $l->getText('classgroup', 'newprojectnotificationtitle', array($GLOBALS['sys_name'])), $message);
			}
		}
		
		// Get the email of the user who wants to register the project
		$res = db_query("SELECT u.email, u.language
				 FROM users u, user_group ug
				 WHERE ug.group_id='".$this->getID()."' AND u.user_id=ug.user_id;");

		if (db_numrows($res) < 1) {
			$this->setError("Cound not find user who has submitted the project.");
			return false;
		} else {
			for ($i=0; $i<db_numrows($res) ; $i++) {
				$email = db_result($res, $i, 'email');
				$l = new BaseLanguage () ;
				$l->loadLanguageID(db_result($res,$i,'language'));
				
				$message=stripcslashes($l->getText('classgroup', 'newprojectnotification_submitter', array($GLOBALS['sys_name'], $this->getPublicName(), $this->getRegistrationPurpose(), $this->getLicense(), $GLOBALS['sys_default_domain'])));
				
				util_send_message($email, $l->getText('classgroup', 'newprojectnotificationtitle', array($GLOBALS['sys_name'])), $message);
			}
		}
		

	  return true;
	}
}

/**
 * group_getname() - get the group name
 *
 * @param	   int	 The group ID
 * @deprecated
 *
 */
function group_getname ($group_id = 0) {
	$grp = &group_get_object($group_id);
	if ($grp) {
		return $grp->getPublicName();
	} else {
		return 'Invalid';
	}
}

/**
 * group_getunixname() - get the unixname for a group
 *
 * @param	   int	 The group ID
 * @deprecated
 *
 */
function group_getunixname ($group_id) {
	$grp = &group_get_object($group_id);
	if ($grp) {
		return $grp->getUnixName();
	} else {
		return 'Invalid';
	}
}

/**
 * group_get_result() - Get the group object result ID.
 *
 * @param	   int	 The group ID
 * @deprecated
 *
 */
function &group_get_result($group_id=0) {
	$grp = &group_get_object($group_id);
	if ($grp) {
		return $grp->getData();
	} else {
		return 0;
	}
}

// Local Variables:
// mode: php
// c-file-style: "bsd"
// End:

?>