3 * FusionForge project manager
5 * Copyright 1999-2000, Tim Perdue/Sourceforge
6 * Copyright 2002, Tim Perdue/GForge, LLC
7 * Copyright 2009, Roland Mas
9 * This file is part of FusionForge.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published
13 * by the Free Software Foundation; either version 2 of the License,
14 * or (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with FusionForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 require_once $gfcommon.'include/Error.class.php';
30 * Fetches a ProjectGroup object from the database
32 * @param group_project_id the projectgroup id
33 * @param data whether or not the db result handle is passed in
34 * @return the ProjectGroup object
36 function &projectgroup_get_object($group_project_id,$data=false) {
37 global $PROJECTGROUP_OBJ;
38 if (!isset($PROJECTGROUP_OBJ["_".$group_project_id."_"])) {
40 //the db result handle was passed in
42 $res = db_query_params ('SELECT * FROM project_group_list_vw WHERE group_project_id=$1',
43 array ($group_project_id)) ;
44 if (db_numrows($res) <1 ) {
45 $PROJECTGROUP_OBJ["_".$group_project_id."_"]=false;
48 $data = db_fetch_array($res);
50 $Group =& group_get_object($data["group_id"]);
51 $PROJECTGROUP_OBJ["_".$group_project_id."_"]= new ProjectGroup($Group,$group_project_id,$data);
53 return $PROJECTGROUP_OBJ["_".$group_project_id."_"];
56 function projectgroup_get_groupid ($group_project_id) {
57 global $PROJECTGROUP_OBJ;
58 if (isset($PROJECTGROUP_OBJ["_".$group_project_id."_"])) {
59 return $PROJECTGROUP_OBJ["_".$group_project_id."_"]->Group->getID() ;
62 $res = db_query_params ('SELECT group_id FROM project_group_list WHERE group_project_id=$1',
63 array ($group_project_id)) ;
64 if (!$res || db_numrows($res) < 1) {
67 $arr = db_fetch_array ($res);
68 return $arr['group_id'] ;
71 class ProjectGroup extends Error {
74 * Associative array of data from db.
76 * @var array $data_array.
93 * @param object The Group object to which this forum is associated.
94 * @param int The group_project_id.
95 * @param array The associative array of data.
96 * @return boolean success.
98 function ProjectGroup(&$Group, $group_project_id=false, $arr=false) {
100 if (!$Group || !is_object($Group)) {
101 $this->setError('ProjectGroup:: No Valid Group Object');
104 if ($Group->isError()) {
105 $this->setError('ProjectGroup:: '.$Group->getErrorMessage());
108 $this->Group =& $Group;
110 if ($group_project_id) {
111 if (!$arr || !is_array($arr)) {
112 if (!$this->fetchData($group_project_id)) {
116 $this->data_array =& $arr;
117 if ($this->data_array['group_id'] != $this->Group->getID()) {
118 $this->setError('Group_id in db result does not match Group Object');
123 // Make sure they can even access this object
125 if (!forge_check_perm ('pm', $this->getID(), 'read')) {
126 $this->setPermissionDeniedError();
127 $this->data_array = null;
135 * create - create a new ProjectGroup in the database.
137 * @param string The project name.
138 * @param string The project description.
139 * @param int Whether it is (1) public or (0) private .
140 * @param string The email address to send new notifications to.
141 * @return boolean success.
143 function create($project_name,$description,$is_public=1,$send_all_posts_to='') {
144 if (strlen($project_name) < 3) {
145 $this->setError(_('Title Must Be At Least 5 Characters'));
148 if (strlen($description) < 10) {
149 $this->setError(_('Document Description Must Be At Least 10 Characters'));
152 if ($send_all_posts_to) {
153 $invalid_mails = validate_emails($send_all_posts_to);
154 if (count($invalid_mails) > 0) {
155 $this->setInvalidEmailError();
160 if (!forge_check_perm ('pm_admin', $this->Group->getID())) {
161 $this->setPermissionDeniedError();
166 $result = db_query_params ('INSERT INTO project_group_list (group_id,project_name,is_public,description,send_all_posts_to) VALUES ($1,$2,$3,$4,$5)',
167 array ($this->Group->getId(),
168 htmlspecialchars($project_name),
170 htmlspecialchars($description),
171 $send_all_posts_to)) ;
173 $this->setError('Error Adding ProjectGroup: '.db_error());
177 $this->group_project_id=db_insertid($result,'project_group_list','group_project_id');
178 $this->fetchData($this->group_project_id);
182 $this->Group->normalizeAllRoles () ;
188 * fetchData - re-fetch the data for this ProjectGroup from the database.
190 * @param int The project group ID.
191 * @return boolean success.
193 function fetchData($group_project_id) {
194 $res = db_query_params ('SELECT * FROM project_group_list_vw WHERE group_project_id=$1 AND group_id=$2',
195 array ($group_project_id,
196 $this->Group->getID())) ;
197 if (!$res || db_numrows($res) < 1) {
198 $this->setError('ProjectGroup:: Invalid group_project_id');
201 $this->data_array = db_fetch_array($res);
202 db_free_result($res);
207 * getGroup - get the Group object this ProjectGroup is associated with.
209 * @return object The Group object.
211 function &getGroup() {
216 * getID - get this GroupProjectID.
218 * @return int The group_project_id #.
221 return $this->data_array['group_project_id'];
225 * getOpenCount - get the count of open tracker items in this tracker type.
227 * @return int The count.
229 function getOpenCount() {
230 return $this->data_array['open_count'];
234 * getTotalCount - get the total number of tracker items in this tracker type.
236 * @return int The total count.
238 function getTotalCount() {
239 return $this->data_array['count'];
243 * isPublic - Is this projectGroup open to the general public.
245 * @return boolean allow.
247 function isPublic() {
248 return $this->data_array['is_public'];
252 * getName - get the name of this projectGroup.
254 * @return string The name of this projectGroup.
257 return $this->data_array['project_name'];
261 * getSendAllPostsTo - an optional email address to send all task updates to.
263 * @return string The email address.
265 function getSendAllPostsTo() {
266 return $this->data_array['send_all_posts_to'];
270 * getDescription - the description of this ProjectGroup.
272 * @return string The description.
274 function getDescription() {
275 return $this->data_array['description'];
279 * getStatuses - Return result set of statuses.
281 * @returns Database result set.
283 function getStatuses () {
284 if (!$this->statuses) {
285 $this->statuses = db_query_params ('SELECT * FROM project_status',
288 return $this->statuses;
292 * getCategories - Return result set of categories.
294 * @returns Database result set.
296 function getCategories () {
297 if (!$this->categories) {
298 $this->categories = db_query_params ('SELECT category_id,category_name FROM project_category WHERE group_project_id=$1',
299 array ($this->getID()));
301 return $this->categories;
305 * getCategoryObjects - Array of ProjectCategory objects set up for this artifact type.
307 * @return array Of ProjectCategory objects.
309 function &getCategoryObjects() {
310 $res = $this->getCategories();
312 while ($arr = db_fetch_array($res)) {
313 $cats[] = new ProjectCategory($this,$arr);
319 * update - update a ProjectGroup in the database.
321 * @param string The project name.
322 * @param string The project description.
323 * @param string The email address to send new notifications to.
324 * @return boolean success.
326 function update($project_name,$description,$send_all_posts_to='') {
327 if (strlen($project_name) < 3) {
328 $this->setError(_('Title Must Be At Least 5 Characters'));
331 if (strlen($description) < 10) {
332 $this->setError(_('Document Description Must Be At Least 10 Characters'));
336 if ($send_all_posts_to) {
337 $invalid_mails = validate_emails($send_all_posts_to);
338 if (count($invalid_mails) > 0) {
339 $this->setInvalidEmailError();
344 if (!forge_check_perm ('pm', $this->getID(), 'manager')) {
345 $this->setPermissionDeniedError();
349 $res = db_query_params ('UPDATE project_group_list SET project_name=$1,
350 description=$2, send_all_posts_to=$3
351 WHERE group_id=$4 AND group_project_id=$5',
352 array (htmlspecialchars($project_name),
353 htmlspecialchars($description),
355 $this->Group->getID(),
358 if (!$res || db_affected_rows($res) < 1) {
359 $this->setError('Error On Update: '.db_error().$sql);
366 * delete - delete this subproject and all its related data.
368 * @param bool I'm Sure.
369 * @param bool I'm REALLY sure.
370 * @return bool true/false;
372 function delete($sure, $really_sure) {
373 if (!$sure || !$really_sure) {
374 $this->setMissingParamsError();
377 if (!forge_check_perm ('pm', $this->getID(), 'manager')) {
378 $this->setPermissionDeniedError();
384 $res = db_query_params ('DELETE FROM project_assigned_to
385 WHERE EXISTS (SELECT project_task_id FROM project_task
386 WHERE group_project_id=$1
387 AND project_task.project_task_id=project_assigned_to.project_task_id)',
388 array ($this->getID())) ;
392 $this->setError('DATABASE '.db_error());
396 $res = db_query_params ('DELETE FROM project_dependencies
397 WHERE EXISTS (SELECT project_task_id FROM project_task
398 WHERE group_project_id=$1
399 AND project_task.project_task_id=project_dependencies.project_task_id)',
400 array ($this->getID())) ;
404 $this->setError('DATABASE '.db_error());
408 $res = db_query_params ('DELETE FROM project_history
409 WHERE EXISTS (SELECT project_task_id FROM project_task
410 WHERE group_project_id=$1
411 AND project_task.project_task_id=project_history.project_task_id)',
412 array ($this->getID())) ;
416 $this->setError('DATABASE '.db_error());
420 $res = db_query_params ('DELETE FROM project_messages
421 WHERE EXISTS (SELECT project_task_id FROM project_task
422 WHERE group_project_id=$1
423 AND project_task.project_task_id=project_messages.project_task_id)',
424 array ($this->getID())) ;
428 $this->setError('DATABASE '.db_error());
432 $res = db_query_params ('DELETE FROM project_task_artifact
433 WHERE EXISTS (SELECT project_task_id FROM project_task
434 WHERE group_project_id=$1
435 AND project_task.project_task_id=project_task_artifact.project_task_id)',
436 array ($this->getID())) ;
440 $this->setError('DATABASE '.db_error());
444 $res = db_query_params ('DELETE FROM rep_time_tracking
445 WHERE EXISTS (SELECT project_task_id FROM project_task
446 WHERE group_project_id=$1
447 AND project_task.project_task_id=rep_time_tracking.project_task_id)',
448 array ($this->getID())) ;
452 $this->setError('DATABASE '.db_error());
456 $res = db_query_params ('DELETE FROM project_task
457 WHERE group_project_id=$1',
458 array ($this->getID())) ;
462 $this->setError('DATABASE '.db_error());
466 $res = db_query_params ('DELETE FROM project_category WHERE group_project_id=$1',
467 array ($this->getID())) ;
471 $this->setError('DATABASE '.db_error());
475 $res = db_query_params ('DELETE FROM project_group_list WHERE group_project_id=$1',
476 array ($this->getID())) ;
480 $this->setError('DATABASE '.db_error());
484 $res = db_query_params ('DELETE FROM project_counts_agg WHERE group_project_id=$1',
485 array ($this->getID())) ;
489 $this->setError('DATABASE '.db_error());
495 $this->Group->normalizeAllRoles () ;
503 // c-file-style: "bsd"