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(_('Subproject 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);
177 $this->Group->normalizeAllRoles () ;
185 * fetchData - re-fetch the data for this ProjectGroup from the database.
187 * @param int The project group ID.
188 * @return boolean success.
190 function fetchData($group_project_id) {
191 $res = db_query_params ('SELECT * FROM project_group_list_vw WHERE group_project_id=$1 AND group_id=$2',
192 array ($group_project_id,
193 $this->Group->getID())) ;
194 if (!$res || db_numrows($res) < 1) {
195 $this->setError('ProjectGroup:: Invalid group_project_id');
198 $this->data_array = db_fetch_array($res);
199 db_free_result($res);
204 * getGroup - get the Group object this ProjectGroup is associated with.
206 * @return object The Group object.
208 function &getGroup() {
213 * getID - get this GroupProjectID.
215 * @return int The group_project_id #.
218 return $this->data_array['group_project_id'];
222 * getOpenCount - get the count of open tracker items in this tracker type.
224 * @return int The count.
226 function getOpenCount() {
227 return $this->data_array['open_count'];
231 * getTotalCount - get the total number of tracker items in this tracker type.
233 * @return int The total count.
235 function getTotalCount() {
236 return $this->data_array['count'];
240 * isPublic - Is this projectGroup open to the general public.
242 * @return boolean allow.
244 function isPublic() {
245 return $this->data_array['is_public'];
249 * getName - get the name of this projectGroup.
251 * @return string The name of this projectGroup.
254 return $this->data_array['project_name'];
258 * getSendAllPostsTo - an optional email address to send all task updates to.
260 * @return string The email address.
262 function getSendAllPostsTo() {
263 return $this->data_array['send_all_posts_to'];
267 * getDescription - the description of this ProjectGroup.
269 * @return string The description.
271 function getDescription() {
272 return $this->data_array['description'];
276 * getStatuses - Return result set of statuses.
278 * @return object Database result set.
280 function getStatuses() {
281 if (!$this->statuses) {
282 $this->statuses = db_query_params('SELECT * FROM project_status',
285 return $this->statuses;
289 * getCategories - Return result set of categories.
291 * @return object Database result set.
293 function getCategories () {
294 if (!$this->categories) {
295 $this->categories = db_query_params('SELECT category_id,category_name FROM project_category WHERE group_project_id=$1',
296 array($this->getID()));
298 return $this->categories;
302 * getCategoryObjects - Array of ProjectCategory objects set up for this artifact type.
304 * @return array Of ProjectCategory objects.
306 function &getCategoryObjects() {
307 $res = $this->getCategories();
309 while ($arr = db_fetch_array($res)) {
310 $cats[] = new ProjectCategory($this,$arr);
316 * update - update a ProjectGroup in the database.
318 * @param string The project name.
319 * @param string The project description.
320 * @param string The email address to send new notifications to.
321 * @return boolean success.
323 function update($project_name, $description, $send_all_posts_to = '') {
324 if (strlen($project_name) < 3) {
325 $this->setError(_('Title Must Be At Least 5 Characters'));
328 if (strlen($description) < 10) {
329 $this->setError(_('Subproject Description Must Be At Least 10 Characters'));
333 if ($send_all_posts_to) {
334 $invalid_mails = validate_emails($send_all_posts_to);
335 if (count($invalid_mails) > 0) {
336 $this->setInvalidEmailError($send_all_posts_to);
341 if (!forge_check_perm ('pm', $this->getID(), 'manager')) {
342 $this->setPermissionDeniedError();
346 $res = db_query_params('UPDATE project_group_list SET project_name=$1,
347 description=$2, send_all_posts_to=$3
348 WHERE group_id=$4 AND group_project_id=$5',
349 array(htmlspecialchars($project_name),
350 htmlspecialchars($description),
352 $this->Group->getID(),
355 if (!$res || db_affected_rows($res) < 1) {
356 $this->setError('Error On Update: '.db_error().$sql);
363 * delete - delete this subproject and all its related data.
365 * @param bool I'm Sure.
366 * @param bool I'm REALLY sure.
367 * @return bool true/false;
369 function delete($sure, $really_sure) {
370 if (!$sure || !$really_sure) {
371 $this->setMissingParamsError(_('Please tick all checkboxes.'));
374 if (!forge_check_perm('pm', $this->getID(), 'manager')) {
375 $this->setPermissionDeniedError();
381 $res = db_query_params('DELETE FROM project_assigned_to
382 WHERE EXISTS (SELECT project_task_id FROM project_task
383 WHERE group_project_id=$1
384 AND project_task.project_task_id=project_assigned_to.project_task_id)',
385 array($this->getID()));
388 $this->setError('DATABASE '.db_error());
392 $res = db_query_params('DELETE FROM project_dependencies
393 WHERE EXISTS (SELECT project_task_id FROM project_task
394 WHERE group_project_id=$1
395 AND project_task.project_task_id=project_dependencies.project_task_id)',
396 array($this->getID()));
399 $this->setError('DATABASE '.db_error());
403 $res = db_query_params('DELETE FROM project_history
404 WHERE EXISTS (SELECT project_task_id FROM project_task
405 WHERE group_project_id=$1
406 AND project_task.project_task_id=project_history.project_task_id)',
407 array($this->getID()));
410 $this->setError('DATABASE '.db_error());
414 $res = db_query_params('DELETE FROM project_messages
415 WHERE EXISTS (SELECT project_task_id FROM project_task
416 WHERE group_project_id=$1
417 AND project_task.project_task_id=project_messages.project_task_id)',
418 array($this->getID()));
421 $this->setError('DATABASE '.db_error());
425 $res = db_query_params('DELETE FROM project_task_artifact
426 WHERE EXISTS (SELECT project_task_id FROM project_task
427 WHERE group_project_id=$1
428 AND project_task.project_task_id=project_task_artifact.project_task_id)',
429 array($this->getID()));
432 $this->setError('DATABASE '.db_error());
436 $res = db_query_params('DELETE FROM rep_time_tracking
437 WHERE EXISTS (SELECT project_task_id FROM project_task
438 WHERE group_project_id=$1
439 AND project_task.project_task_id=rep_time_tracking.project_task_id)',
440 array($this->getID()));
443 $this->setError('DATABASE '.db_error());
447 $res = db_query_params ('DELETE FROM project_task
448 WHERE group_project_id=$1',
449 array ($this->getID()));
452 $this->setError('DATABASE '.db_error());
456 $res = db_query_params ('DELETE FROM project_category WHERE group_project_id=$1',
457 array ($this->getID()));
460 $this->setError('DATABASE '.db_error());
464 $res = db_query_params ('DELETE FROM project_group_list WHERE group_project_id=$1',
465 array ($this->getID()));
468 $this->setError('DATABASE '.db_error());
472 $res = db_query_params ('DELETE FROM project_counts_agg WHERE group_project_id=$1',
473 array ($this->getID()));
476 $this->setError('DATABASE '.db_error());
482 $this->Group->normalizeAllRoles();
490 // c-file-style: "bsd"