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. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'include/Error.class.php';
28 * Fetches a ProjectGroup object from the database
30 * @param int the projectgroup id
31 * @param array whether or not the db result handle is passed in
32 * @return object the ProjectGroup object
34 function &projectgroup_get_object($group_project_id, $data = false) {
35 global $PROJECTGROUP_OBJ;
36 if (!isset($PROJECTGROUP_OBJ["_".$group_project_id."_"])) {
38 //the db result handle was passed in
40 $res = db_query_params('SELECT * FROM project_group_list_vw WHERE group_project_id=$1',
41 array($group_project_id));
42 if (db_numrows($res) <1 ) {
43 $PROJECTGROUP_OBJ["_".$group_project_id."_"]=false;
46 $data = db_fetch_array($res);
48 $Group = group_get_object($data["group_id"]);
49 $PROJECTGROUP_OBJ["_".$group_project_id."_"]= new ProjectGroup($Group,$group_project_id,$data);
51 return $PROJECTGROUP_OBJ["_".$group_project_id."_"];
54 function projectgroup_get_groupid($group_project_id) {
55 global $PROJECTGROUP_OBJ;
56 if (isset($PROJECTGROUP_OBJ["_".$group_project_id."_"])) {
57 return $PROJECTGROUP_OBJ["_".$group_project_id."_"]->Group->getID() ;
60 $res = db_query_params('SELECT group_id FROM project_group_list WHERE group_project_id=$1',
61 array($group_project_id));
62 if (!$res || db_numrows($res) < 1) {
65 $arr = db_fetch_array($res);
66 return $arr['group_id'];
69 class ProjectGroup extends Error {
72 * Associative array of data from db.
74 * @var array $data_array.
91 * @param object The Group object to which this forum is associated.
92 * @param int The group_project_id.
93 * @param array The associative array of data.
94 * @return boolean success.
96 function ProjectGroup(&$Group, $group_project_id = false, $arr = false) {
98 if (!$Group || !is_object($Group)) {
99 $this->setError('ProjectGroup:: No Valid Group Object');
102 if ($Group->isError()) {
103 $this->setError('ProjectGroup:: '.$Group->getErrorMessage());
106 $this->Group =& $Group;
108 if ($group_project_id) {
109 if (!$arr || !is_array($arr)) {
110 if (!$this->fetchData($group_project_id)) {
114 $this->data_array =& $arr;
115 if ($this->data_array['group_id'] != $this->Group->getID()) {
116 $this->setError('Group_id in db result does not match Group Object');
121 // Make sure they can even access this object
123 if (!forge_check_perm ('pm', $this->getID(), 'read')) {
124 $this->setPermissionDeniedError();
125 $this->data_array = null;
133 * create - create a new ProjectGroup in the database.
135 * @param string The project name.
136 * @param string The project description.
137 * @param int Whether it is (1) public or (0) private .
138 * @param string The email address to send new notifications to.
139 * @return boolean success.
141 function create($project_name,$description,$is_public=1,$send_all_posts_to='') {
142 if (strlen($project_name) < 3) {
143 $this->setError(_('Title Must Be At Least 5 Characters'));
146 if (strlen($description) < 10) {
147 $this->setError(_('Document Description Must Be At Least 10 Characters'));
150 if ($send_all_posts_to) {
151 $invalid_mails = validate_emails($send_all_posts_to);
152 if (count($invalid_mails) > 0) {
153 $this->setInvalidEmailError($send_all_posts_to);
158 if (!forge_check_perm ('pm_admin', $this->Group->getID())) {
159 $this->setPermissionDeniedError();
164 $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)',
165 array($this->Group->getId(),
166 htmlspecialchars($project_name),
168 htmlspecialchars($description),
169 $send_all_posts_to));
171 $this->setError('Error Adding ProjectGroup: '.db_error());
175 $this->group_project_id=db_insertid($result,'project_group_list','group_project_id');
176 $this->fetchData($this->group_project_id);
184 * fetchData - re-fetch the data for this ProjectGroup from the database.
186 * @param int The project group ID.
187 * @return boolean success.
189 function fetchData($group_project_id) {
190 $res = db_query_params ('SELECT * FROM project_group_list_vw WHERE group_project_id=$1 AND group_id=$2',
191 array ($group_project_id,
192 $this->Group->getID())) ;
193 if (!$res || db_numrows($res) < 1) {
194 $this->setError('ProjectGroup:: Invalid group_project_id');
197 $this->data_array = db_fetch_array($res);
198 db_free_result($res);
203 * getGroup - get the Group object this ProjectGroup is associated with.
205 * @return object The Group object.
207 function &getGroup() {
212 * getID - get this GroupProjectID.
214 * @return int The group_project_id #.
217 return $this->data_array['group_project_id'];
221 * getOpenCount - get the count of open tracker items in this tracker type.
223 * @return int The count.
225 function getOpenCount() {
226 return $this->data_array['open_count'];
230 * getTotalCount - get the total number of tracker items in this tracker type.
232 * @return int The total count.
234 function getTotalCount() {
235 return $this->data_array['count'];
239 * isPublic - Is this projectGroup open to the general public.
241 * @return boolean allow.
243 function isPublic() {
244 return $this->data_array['is_public'];
248 * getName - get the name of this projectGroup.
250 * @return string The name of this projectGroup.
253 return $this->data_array['project_name'];
257 * getSendAllPostsTo - an optional email address to send all task updates to.
259 * @return string The email address.
261 function getSendAllPostsTo() {
262 return $this->data_array['send_all_posts_to'];
266 * getDescription - the description of this ProjectGroup.
268 * @return string The description.
270 function getDescription() {
271 return $this->data_array['description'];
275 * getStatuses - Return result set of statuses.
277 * @return object Database result set.
279 function getStatuses() {
280 if (!$this->statuses) {
281 $this->statuses = db_query_params('SELECT * FROM project_status',
284 return $this->statuses;
288 * getCategories - Return result set of categories.
290 * @return object Database result set.
292 function getCategories () {
293 if (!$this->categories) {
294 $this->categories = db_query_params('SELECT category_id,category_name FROM project_category WHERE group_project_id=$1',
295 array($this->getID()));
297 return $this->categories;
301 * getCategoryObjects - Array of ProjectCategory objects set up for this artifact type.
303 * @return array Of ProjectCategory objects.
305 function &getCategoryObjects() {
306 $res = $this->getCategories();
308 while ($arr = db_fetch_array($res)) {
309 $cats[] = new ProjectCategory($this,$arr);
315 * update - update a ProjectGroup in the database.
317 * @param string The project name.
318 * @param string The project description.
319 * @param string The email address to send new notifications to.
320 * @return boolean success.
322 function update($project_name, $description, $send_all_posts_to = '') {
323 if (strlen($project_name) < 3) {
324 $this->setError(_('Title Must Be At Least 5 Characters'));
327 if (strlen($description) < 10) {
328 $this->setError(_('Document Description Must Be At Least 10 Characters'));
332 if ($send_all_posts_to) {
333 $invalid_mails = validate_emails($send_all_posts_to);
334 if (count($invalid_mails) > 0) {
335 $this->setInvalidEmailError($send_all_posts_to);
340 if (!forge_check_perm ('pm', $this->getID(), 'manager')) {
341 $this->setPermissionDeniedError();
345 $res = db_query_params('UPDATE project_group_list SET project_name=$1,
346 description=$2, send_all_posts_to=$3
347 WHERE group_id=$4 AND group_project_id=$5',
348 array(htmlspecialchars($project_name),
349 htmlspecialchars($description),
351 $this->Group->getID(),
354 if (!$res || db_affected_rows($res) < 1) {
355 $this->setError('Error On Update: '.db_error().$sql);
362 * delete - delete this subproject and all its related data.
364 * @param bool I'm Sure.
365 * @param bool I'm REALLY sure.
366 * @return bool true/false;
368 function delete($sure, $really_sure) {
369 if (!$sure || !$really_sure) {
370 $this->setMissingParamsError(_('Please tick all checkboxes.'));
373 if (!forge_check_perm('pm', $this->getID(), 'manager')) {
374 $this->setPermissionDeniedError();
380 $res = db_query_params('DELETE FROM project_assigned_to
381 WHERE EXISTS (SELECT project_task_id FROM project_task
382 WHERE group_project_id=$1
383 AND project_task.project_task_id=project_assigned_to.project_task_id)',
384 array($this->getID()));
387 $this->setError('DATABASE '.db_error());
391 $res = db_query_params('DELETE FROM project_dependencies
392 WHERE EXISTS (SELECT project_task_id FROM project_task
393 WHERE group_project_id=$1
394 AND project_task.project_task_id=project_dependencies.project_task_id)',
395 array($this->getID()));
398 $this->setError('DATABASE '.db_error());
402 $res = db_query_params('DELETE FROM project_history
403 WHERE EXISTS (SELECT project_task_id FROM project_task
404 WHERE group_project_id=$1
405 AND project_task.project_task_id=project_history.project_task_id)',
406 array($this->getID()));
409 $this->setError('DATABASE '.db_error());
413 $res = db_query_params('DELETE FROM project_messages
414 WHERE EXISTS (SELECT project_task_id FROM project_task
415 WHERE group_project_id=$1
416 AND project_task.project_task_id=project_messages.project_task_id)',
417 array($this->getID()));
420 $this->setError('DATABASE '.db_error());
424 $res = db_query_params('DELETE FROM project_task_artifact
425 WHERE EXISTS (SELECT project_task_id FROM project_task
426 WHERE group_project_id=$1
427 AND project_task.project_task_id=project_task_artifact.project_task_id)',
428 array($this->getID()));
431 $this->setError('DATABASE '.db_error());
435 $res = db_query_params('DELETE FROM rep_time_tracking
436 WHERE EXISTS (SELECT project_task_id FROM project_task
437 WHERE group_project_id=$1
438 AND project_task.project_task_id=rep_time_tracking.project_task_id)',
439 array($this->getID()));
442 $this->setError('DATABASE '.db_error());
446 $res = db_query_params ('DELETE FROM project_task
447 WHERE group_project_id=$1',
448 array ($this->getID()));
451 $this->setError('DATABASE '.db_error());
455 $res = db_query_params ('DELETE FROM project_category WHERE group_project_id=$1',
456 array ($this->getID()));
459 $this->setError('DATABASE '.db_error());
463 $res = db_query_params ('DELETE FROM project_group_list WHERE group_project_id=$1',
464 array ($this->getID()));
467 $this->setError('DATABASE '.db_error());
471 $res = db_query_params ('DELETE FROM project_counts_agg WHERE group_project_id=$1',
472 array ($this->getID()));
475 $this->setError('DATABASE '.db_error());
481 $this->Group->normalizeAllRoles();
489 // c-file-style: "bsd"