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 int the projectgroup id
33 * @param array whether or not the db result handle is passed in
34 * @return object 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($send_all_posts_to);
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);
186 * fetchData - re-fetch the data for this ProjectGroup from the database.
188 * @param int The project group ID.
189 * @return boolean success.
191 function fetchData($group_project_id) {
192 $res = db_query_params ('SELECT * FROM project_group_list_vw WHERE group_project_id=$1 AND group_id=$2',
193 array ($group_project_id,
194 $this->Group->getID())) ;
195 if (!$res || db_numrows($res) < 1) {
196 $this->setError('ProjectGroup:: Invalid group_project_id');
199 $this->data_array = db_fetch_array($res);
200 db_free_result($res);
205 * getGroup - get the Group object this ProjectGroup is associated with.
207 * @return object The Group object.
209 function &getGroup() {
214 * getID - get this GroupProjectID.
216 * @return int The group_project_id #.
219 return $this->data_array['group_project_id'];
223 * getOpenCount - get the count of open tracker items in this tracker type.
225 * @return int The count.
227 function getOpenCount() {
228 return $this->data_array['open_count'];
232 * getTotalCount - get the total number of tracker items in this tracker type.
234 * @return int The total count.
236 function getTotalCount() {
237 return $this->data_array['count'];
241 * isPublic - Is this projectGroup open to the general public.
243 * @return boolean allow.
245 function isPublic() {
246 return $this->data_array['is_public'];
250 * getName - get the name of this projectGroup.
252 * @return string The name of this projectGroup.
255 return $this->data_array['project_name'];
259 * getSendAllPostsTo - an optional email address to send all task updates to.
261 * @return string The email address.
263 function getSendAllPostsTo() {
264 return $this->data_array['send_all_posts_to'];
268 * getDescription - the description of this ProjectGroup.
270 * @return string The description.
272 function getDescription() {
273 return $this->data_array['description'];
277 * getStatuses - Return result set of statuses.
279 * @return object Database result set.
281 function getStatuses() {
282 if (!$this->statuses) {
283 $this->statuses = db_query_params('SELECT * FROM project_status',
286 return $this->statuses;
290 * getCategories - Return result set of categories.
292 * @return object Database result set.
294 function getCategories () {
295 if (!$this->categories) {
296 $this->categories = db_query_params('SELECT category_id,category_name FROM project_category WHERE group_project_id=$1',
297 array($this->getID()));
299 return $this->categories;
303 * getCategoryObjects - Array of ProjectCategory objects set up for this artifact type.
305 * @return array Of ProjectCategory objects.
307 function &getCategoryObjects() {
308 $res = $this->getCategories();
310 while ($arr = db_fetch_array($res)) {
311 $cats[] = new ProjectCategory($this,$arr);
317 * update - update a ProjectGroup in the database.
319 * @param string The project name.
320 * @param string The project description.
321 * @param string The email address to send new notifications to.
322 * @return boolean success.
324 function update($project_name, $description, $send_all_posts_to = '') {
325 if (strlen($project_name) < 3) {
326 $this->setError(_('Title Must Be At Least 5 Characters'));
329 if (strlen($description) < 10) {
330 $this->setError(_('Document Description Must Be At Least 10 Characters'));
334 if ($send_all_posts_to) {
335 $invalid_mails = validate_emails($send_all_posts_to);
336 if (count($invalid_mails) > 0) {
337 $this->setInvalidEmailError($send_all_posts_to);
342 if (!forge_check_perm ('pm', $this->getID(), 'manager')) {
343 $this->setPermissionDeniedError();
347 $res = db_query_params('UPDATE project_group_list SET project_name=$1,
348 description=$2, send_all_posts_to=$3
349 WHERE group_id=$4 AND group_project_id=$5',
350 array(htmlspecialchars($project_name),
351 htmlspecialchars($description),
353 $this->Group->getID(),
356 if (!$res || db_affected_rows($res) < 1) {
357 $this->setError('Error On Update: '.db_error().$sql);
364 * delete - delete this subproject and all its related data.
366 * @param bool I'm Sure.
367 * @param bool I'm REALLY sure.
368 * @return bool true/false;
370 function delete($sure, $really_sure) {
371 if (!$sure || !$really_sure) {
372 $this->setMissingParamsError(_('Please tick all checkboxes.'));
375 if (!forge_check_perm('pm', $this->getID(), 'manager')) {
376 $this->setPermissionDeniedError();
382 $res = db_query_params('DELETE FROM project_assigned_to
383 WHERE EXISTS (SELECT project_task_id FROM project_task
384 WHERE group_project_id=$1
385 AND project_task.project_task_id=project_assigned_to.project_task_id)',
386 array($this->getID()));
389 $this->setError('DATABASE '.db_error());
393 $res = db_query_params('DELETE FROM project_dependencies
394 WHERE EXISTS (SELECT project_task_id FROM project_task
395 WHERE group_project_id=$1
396 AND project_task.project_task_id=project_dependencies.project_task_id)',
397 array($this->getID()));
400 $this->setError('DATABASE '.db_error());
404 $res = db_query_params('DELETE FROM project_history
405 WHERE EXISTS (SELECT project_task_id FROM project_task
406 WHERE group_project_id=$1
407 AND project_task.project_task_id=project_history.project_task_id)',
408 array($this->getID()));
411 $this->setError('DATABASE '.db_error());
415 $res = db_query_params('DELETE FROM project_messages
416 WHERE EXISTS (SELECT project_task_id FROM project_task
417 WHERE group_project_id=$1
418 AND project_task.project_task_id=project_messages.project_task_id)',
419 array($this->getID()));
422 $this->setError('DATABASE '.db_error());
426 $res = db_query_params('DELETE FROM project_task_artifact
427 WHERE EXISTS (SELECT project_task_id FROM project_task
428 WHERE group_project_id=$1
429 AND project_task.project_task_id=project_task_artifact.project_task_id)',
430 array($this->getID()));
433 $this->setError('DATABASE '.db_error());
437 $res = db_query_params('DELETE FROM rep_time_tracking
438 WHERE EXISTS (SELECT project_task_id FROM project_task
439 WHERE group_project_id=$1
440 AND project_task.project_task_id=rep_time_tracking.project_task_id)',
441 array($this->getID()));
444 $this->setError('DATABASE '.db_error());
448 $res = db_query_params ('DELETE FROM project_task
449 WHERE group_project_id=$1',
450 array ($this->getID()));
453 $this->setError('DATABASE '.db_error());
457 $res = db_query_params ('DELETE FROM project_category WHERE group_project_id=$1',
458 array ($this->getID()));
461 $this->setError('DATABASE '.db_error());
465 $res = db_query_params ('DELETE FROM project_group_list WHERE group_project_id=$1',
466 array ($this->getID()));
469 $this->setError('DATABASE '.db_error());
473 $res = db_query_params ('DELETE FROM project_counts_agg WHERE group_project_id=$1',
474 array ($this->getID()));
477 $this->setError('DATABASE '.db_error());
483 $this->Group->normalizeAllRoles();
491 // c-file-style: "bsd"