
12-05-2005, 11:55 AM
|
|
Web Hosting Evangelist
|
|
Join Date: Dec 2001
Posts: 506
|
|
need an easy piece of mysql / php code - $5 via paypal
I have an opensource piece of project management software (webcollab). It is coded in php and connects to a mysql database.
You can have a project, then unlimited tasks (and sub tasks) under each project. So, you can have project A, then under Project A you can have task A, then under task A you can have task A1, then under task A1 you can have task A11. It's easy to relate these subtasks to a folder tree, where you can have unlimited sub folders under each folder.
I'd like to limit each task to haveing only one subtask (even better if I can choose the number of sub tasks).
In the database there is a field labeled "parent", which will tell you who the parent is. The main project will have a parent of 0, so I'm assuming that you'll have to have a while statement that looks to see how many parents you have to go back to get to the main project.
I'll pay the first person to do this $5 via paypal
Thanks
Here is the task_add.php file that is called when you go to add new tasks or subtasks. I believe the code to check the number of subs can be called here, and produce a warning if you are too deep.
Code:
<?php
/*
$Id: task_add.php,v 1.60 2005/09/22 05:44:34 andrewsimpson Exp $
(c) 2002 -2005 Andrew Simpson <andrew.simpson at paradise.net.nz>
WebCollab
---------------------------------------
Based on CoreAPM by Dennis Fleurbaaij 2001/2002
This program 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.
This program 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 this
program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA.
Function:
---------
Add a task or a project (parentless task) to the task-list
*/
//security check
if(! defined('UID' ) ) {
die('Direct file access not permitted' );
}
require_once(BASE.'includes/admin_config.php' );
include_once(BASE.'includes/time.php' );
//secure vars
$content = '';
$javascript = '';
$allowed = array();
if(GUEST ) {
warning($lang['access_denied'], $lang['not_owner'] );
}
//get list of common users in private usergroups that this user can view
$q = db_query('SELECT '.PRE.'usergroups_users.usergroupid AS usergroupid,
'.PRE.'usergroups_users.userid AS userid
FROM '.PRE.'usergroups_users
LEFT JOIN '.PRE.'usergroups ON ('.PRE.'usergroups.id='.PRE.'usergroups_users.usergroupid)
WHERE '.PRE.'usergroups.private=1');
for( $i=0 ; $row = @db_fetch_num($q, $i ) ; ++$i ) {
if(in_array($row[0], (array)$GID ) && ! in_array($row[1], (array)$allowed ) ) {
$allowed[] = $row[1];
}
}
//shows a priority-select box
$priority_select_box = "<tr><td>".$lang['priority'].":</td> <td>\n".
"<select name=\"priority\">\n".
"<option value=\"0\">".$task_state['dontdo']."</option>\n".
"<option value=\"1\">".$task_state['low']."</option>\n".
"<option value=\"2\" selected=\"selected\">".$task_state['normal']."</option>\n".
"<option value=\"3\">".$task_state['high']."</option>\n".
"<option value=\"4\">".$task_state['yesterday']."</option>\n".
"</select>\n</td></tr>\n";
$content .= "<form method=\"post\" action=\"tasks.php\" onsubmit=\"return dateCheck()\" >\n";
$content .= "<fieldset><input type=\"hidden\" name=\"x\" value=\"".$x."\" />\n ";
$content .= "<input type=\"hidden\" name=\"action\" value=\"submit_insert\" />\n ";
//this is split up in 2 parts for readabilities' sake
// add a new TASK
if( @safe_integer($_GET['parentid']) ) {
$parentid = $_GET['parentid'];
//get info about the parent of this task
$q = db_query('SELECT name, deadline, status, owner, parent, projectid, usergroupid, globalaccess, taskgroupid
FROM '.PRE.'tasks WHERE id='.$parentid );
if( ! $parent_row = db_fetch_array($q, 0 ) ) {
error('Task add', 'No parent for taskid' );
}
//add the project deadline (plus GMT offset) for the javascript
$project_deadline = db_result(db_query('SELECT '.$epoch.'deadline) FROM '.PRE.'tasks WHERE id='.$parent_row['projectid'] ) ) + TZ_OFFSET;
$content .= "<input id=\"projectDate\" type=\"hidden\" name=\"projectDate\" value=\"".$project_deadline."\" />\n";
$content .= "<input type=\"hidden\" name=\"parentid\" value=\"".$parentid."\" />\n".
"<input type=\"hidden\" name=\"projectid\" value=\"".$parent_row['projectid']."\" /></fieldset>\n".
"<table class=\"celldata\">\n";
//show project name
if( $parent_row['projectid'] == $parentid) {
$project = $parent_row['name'];
}
else {
$project = db_result(db_query('SELECT name FROM '.PRE.'tasks WHERE id='.$parent_row['projectid'] ), 0, 0 );
}
$content .= "<tr><td>".$lang['project'] .":</td> <td><a href=\"tasks.php?x=".$x."&action=show&taskid=".$parent_row['projectid']."\">".$project."</a></td></tr>\n";
//check if task has a parent task
if( $parent_row['parent'] != 0 ) {
$content .= "<tr><td>".$lang['parent_task'].":</td> <td><a href=\"tasks.php?x=".$x."&action=show&taskid=".$parent_row['parent']."\">".$parent_row['name']."</a></td> </tr>\n";
}
$content .= "<tr><td>".$lang['creation_time'].":</td> <td>".nicetime(time(), 1 )."</td> </tr>\n".
"<tr><td>".$lang['task_name'].":</td> <td><input id=\"name\" type=\"text\" name=\"name\" size=\"30\" /></td> </tr>\n".
"<tr><td>".$lang['deadline'].":</td> <td>".date_select_from_timestamp( $parent_row['deadline'] ).
" <small><i>".$lang['taken_from_parent']."</i></small></td></tr>\n";
//priority
$content .= $priority_select_box;
//status
$content .= "<tr><td>".$lang['status'].":</td> <td>\n".
"<select name=\"status\">\n".
"<option value=\"created\" selected=\"selected\" >".$task_state['new']."</option>\n".
"<option value=\"notactive\" >".$task_state['planned']."</option>\n".
"<option value=\"active\" >".$task_state['active']."</option>\n".
"<option value=\"cantcomplete\" >".$task_state['cantcomplete']."</option>\n".
"<option value=\"done\" >".$task_state['completed']."</option>\n".
"</select></td></tr>";
//get all users in order to show a task owner
$q = db_query('SELECT id, fullname, private FROM '.PRE.'users WHERE deleted=\'f\' AND guest=0 ORDER BY fullname');
//owner box
$content .= "<tr><td>".$lang['task_owner'].":</td><td><select name=\"owner\">\n".
"<option value=\"0\">".$lang['nobody']."</option>\n";
for( $i=0 ; $user_row = @db_fetch_array($q, $i ) ; ++$i) {
//user test for privacy
if($user_row['private'] && ($user_row['id'] != UID ) && ( ! ADMIN ) && ( ! in_array($user_row['id'], (array)$allowed ) ) ) {
continue;
}
$content .= "<option value=\"".$user_row['id']."\"";
//default owner is present user
if($user_row['id'] == UID )
$content .= " selected=\"selected\"";
$content .= ">".$user_row['fullname']."</option>\n";
}
$content .= "</select></td></tr>\n";
//get all taskgroups in order to show a task owner
$q = db_query('SELECT id, name FROM '.PRE.'taskgroups ORDER BY name');
$content .= "<tr> <td><a href=\"help/help_language.php?item=taskgroup&type=help\" onclick=\"window.open('help/help_language.php?item=taskgroup&type=help'); return false\">".$lang['taskgroup']."</a>: </td> <td><select name=\"taskgroupid\">\n";
$content .= "<option value=\"0\">".$lang['no_group']."</option>\n";
for( $i=0 ; $taskgroup_row = @db_fetch_array($q, $i ) ; ++$i) {
//inherit taskgroup from parent
if($parent_row['taskgroupid'] == $taskgroup_row['id'] ) {
$content .= "<option value=\"".$taskgroup_row['id']."\" selected=\"selected\">".$taskgroup_row['name']."</option>\n";
}
else {
$content .= "<option value=\"".$taskgroup_row['id']."\">".$taskgroup_row['name']."</option>\n";
}
}
$content .= "</select></td></tr>\n";
//show all the groups
$q = db_query( 'SELECT id, name, private FROM '.PRE.'usergroups ORDER BY name' );
$content .= "<tr><td><a href=\"help/help_language.php?item=usergroup&type=help\" onclick=\"window.open('help/help_language.php?item=usergroup&type=help'); return false\">".$lang['usergroup']."</a>: </td> <td><select name=\"usergroupid\">\n";
$content .= "<option value=\"0\">".$lang['all_groups']."</option>\n";
for( $i=0 ; $usergroup_row = @db_fetch_array($q, $i ) ; ++$i ) {
//usergroup test for privacy
if( (! ADMIN ) && ($usergroup_row['private'] ) && ( ! in_array($usergroup_row['id'], (array)$GID ) ) ) {
continue;
}
//inherit usergroup from parent, if parent is private
if(($parent_row['globalaccess'] == 'f' ) && ( $parent_row['usergroupid'] == $usergroup_row['id'] ) ) {
$content .= "<option value=\"".$usergroup_row['id']."\" selected=\"selected\">".$usergroup_row['name']."</option>\n";
}
else {
$content .= "<option value=\"".$usergroup_row['id']."\">".$usergroup_row['name']."</option>\n";
}
}
//new task inherits globaccess from parent
if($parent_row['globalaccess'] == 'f' ) {
//set private
$globalaccess = "";
}
else {
//use defaults
$globalaccess = DEFAULT_ACCESS;
}
$content .= "</select></td></tr>\n".
"<tr><td><a href=\"help/help_language.php?item=globalaccess&type=help\" onclick=\"window.open('help/help_language.php?item=globalaccess&type=help'); return false\">".$lang['all_users_view']."</a> </td><td><input type=\"checkbox\" name=\"globalaccess\" ".$globalaccess." /></td></tr>\n".
"<tr><td><a href=\"help/help_language.php?item=groupaccess&type=help\" onclick=\"window.open('help/help_language.php?item=groupaccess&type=help'); return false\">".$lang['group_edit']."</a> </td><td><input type=\"checkbox\" name=\"groupaccess\" ".DEFAULT_EDIT." /></td></tr>\n".
"<tr> <td>".$lang['task_description']."</td> <td><textarea name=\"text\" rows=\"10\" cols=\"60\"></textarea></td> </tr>\n".
//do we need to email ?
"<tr><td><label for=\"mailowner\">".$lang['email_owner']."</label></td><td><input type=\"checkbox\" name=\"mailowner\" id=\"mailowner\" ".DEFAULT_OWNER." /></td></tr>\n".
"<tr><td><label for=\"maillist\">".$lang['email_group']."</label></td><td><input type=\"checkbox\" name=\"maillist\" id=\"maillist\" ".DEFAULT_GROUP." /></td></tr>\n".
"</table>\n".
"<p><input type=\"submit\" value=\"".$lang['add_task']."\" onclick=\"return fieldCheck()\" /></p>".
"</form>\n";
new_box( $lang['add_task'], $content );
}
// ADD A NEW PROJECT
else {
$content .= "<input type=\"hidden\" name=\"parentid\" value=\"0\" />\n".
"<input type=\"hidden\" name=\"projectid\" value=\"0\" />\n".
"<input id=\"projectDate\" type=\"hidden\" name=\"projectDate\" value=\"-1\" />\n".
//taskgroup - we don't have this for projects
"<input type=\"hidden\" name=\"taskgroupid\" value=\"0\" /></fieldset>\n".
"<table class=\"celldata\">\n".
"<tr><td>".$lang['creation_time'].":</td><td>".nicetime(time(), 1 )."</td></tr>\n".
"<tr><td>".$lang['project_name'].":</td> <td><input id=\"name\" type=\"text\" name=\"name\" size=\"30\" /></td> </tr>\n".
//deadline
"<tr><td>".$lang['deadline'].":</td> <td>".date_select()."</td></tr>\n";
//priority
$content .= $priority_select_box;
//status
$content .= "<tr> <td>".$lang['status'].":</td> <td>\n".
"<select name=\"status\">\n".
"<option value=\"notactive\" >".$task_state['planned_project']."</option>\n".
"<option value=\"nolimit\" >".$task_state['no_deadline_project']."</option>\n".
"<option value=\"active\" selected=\"selected\" >".$task_state['active_project']."</option>\n".
"<option value=\"cantcomplete\" >".$task_state['cantcomplete']."</option>\n".
"</select></td></tr>";
//get all users in order to show a task owner
$q = db_query('SELECT id, fullname, private FROM '.PRE.'users WHERE deleted=\'f\' AND guest=0 ORDER BY fullname');
//owner
$content .= "<tr><td>".$lang['project_owner'].":</td><td><select name=\"owner\">\n";
for( $i=0 ; $user_row = @db_fetch_array($q, $i) ; ++$i) {
//user test for privacy
if($user_row['private'] && ($user_row['id'] != UID ) && ( ! ADMIN ) && ( ! in_array($user_row['id'], (array)$allowed ) ) ){
continue;
}
$content .= "<option value=\"".$user_row['id']."\"";
//owner is user
if( $user_row['id'] == UID ) {
$content .= " selected=\"selected\"";
}
$content .= ">".$user_row['fullname']."</option>\n";
}
$content .= "</select></td></tr>\n";
//show all the groups
$q = db_query( 'SELECT id, name, private FROM '.PRE.'usergroups ORDER BY name' );
$content .= "<tr> <td><a href=\"help/help_language.php?item=usergroup&type=help\" onclick=\"window.open('help/help_language.php?item=usergroup&type=help'); return false\">".$lang['usergroup']."</a>: </td> <td><select name=\"usergroupid\">\n".
"<option value=\"0\">".$lang['all_groups']."</option>\n";
for( $i=0 ; $usergroup_row = @db_fetch_array($q, $i ) ; ++$i ) {
//usergroup test for privacy
if( (! ADMIN ) && ($usergroup_row['private'] ) && ( ! in_array($usergroup_row['id'], (array)$GID ) ) ) {
continue;
}
$content .= "<option value=\"".$usergroup_row['id']."\">".$usergroup_row['name']."</option>\n";
}
$content .= "</select></td></tr>\n".
"<tr><td><a href=\"help/help_language.php?item=globalaccess&type=help\" onclick=\"window.open('help/help_language.php?item=globalaccess&type=help'); return false\">".$lang['all_users_view']."</a> </td><td><input type=\"checkbox\" name=\"globalaccess\" ".DEFAULT_ACCESS." /></td></tr>\n".
"<tr><td><a href=\"help/help_language.php?item=groupaccess&type=help\" onclick=\"window.open('help/help_language.php?item=groupaccess&type=help'); return false\">".$lang['group_edit']."</a> </td><td><input type=\"checkbox\" name=\"groupaccess\" ".DEFAULT_EDIT." /></td></tr>\n".
"<tr> <td>".$lang['project_description']."</td> <td><textarea name=\"text\" rows=\"10\" cols=\"60\"></textarea></td> </tr>\n".
//do we need to email ?
"<tr><td><label for=\"mailowner\">".$lang['email_owner']."</label></td><td><input type=\"checkbox\" name=\"mailowner\" id=\"mailowner\" ".DEFAULT_OWNER." /></td></tr>\n".
"<tr><td><label for=\"maillist\">".$lang['email_group']."</label></td><td><input type=\"checkbox\" name=\"maillist\" id=\"maillist\" ".DEFAULT_GROUP." /></td></tr>\n".
"</table>\n".
"<p><input type=\"submit\" value=\"".$lang['add_project']."\" onclick=\"return fieldCheck()\" /></p>".
"</form>\n";
new_box( $lang['add_new_project'], $content );
}
?>
And here is a copy of the tasks database table
Code:
-- phpMyAdmin SQL Dump
-- version 2.6.4-pl4
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Dec 05, 2005 at 10:54 AM
-- Server version: 3.23.58
-- PHP Version: 4.3.9
--
-- Database: `projects`
--
-- --------------------------------------------------------
--
-- Table structure for table `tasks`
--
CREATE TABLE `tasks` (
`id` int(10) unsigned NOT NULL auto_increment,
`parent` int(10) unsigned NOT NULL default '0',
`name` varchar(255) NOT NULL default '',
`text` text,
`created` datetime NOT NULL default '0000-00-00 00:00:00',
`edited` datetime NOT NULL default '0000-00-00 00:00:00',
`owner` int(10) unsigned NOT NULL default '0',
`creator` int(10) unsigned NOT NULL default '0',
`finished_time` datetime NOT NULL default '0000-00-00 00:00:00',
`projectid` int(10) unsigned NOT NULL default '0',
`deadline` datetime NOT NULL default '0000-00-00 00:00:00',
`priority` tinyint(4) NOT NULL default '2',
`status` varchar(20) NOT NULL default 'created',
`taskgroupid` int(10) unsigned NOT NULL default '0',
`lastforumpost` datetime NOT NULL default '0000-00-00 00:00:00',
`usergroupid` int(10) unsigned NOT NULL default '0',
`globalaccess` varchar(5) NOT NULL default 't',
`groupaccess` varchar(5) NOT NULL default 'f',
`lastfileupload` datetime NOT NULL default '0000-00-00 00:00:00',
`completed` tinyint(4) NOT NULL default '0',
`completion_time` datetime NOT NULL default '0000-00-00 00:00:00',
`archive` tinyint(4) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `owner` (`owner`),
KEY `parent` (`parent`),
KEY `name` (`name`(10)),
KEY `projectid` (`projectid`),
KEY `taskgroupid` (`taskgroupid`),
KEY `deadline` (`deadline`),
KEY `status` (`status`)
) TYPE=MyISAM AUTO_INCREMENT=58 ;
--
-- Dumping data for table `tasks`
--
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (42, 33, 'dude's name', '', '2005-12-02 09:41:32', '2005-12-02 14:01:42', 7, 1, '2005-12-02 14:01:42', 33, '2005-12-07 00:00:00', 2, 'created', 0, '2005-12-02 09:41:32', 3, 't', 't', '2005-12-02 09:41:32', 0, '2005-12-02 09:41:32', 0);
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (43, 33, 'dude's name', '', '2005-12-02 09:42:03', '2005-12-02 09:42:03', 5, 1, '2005-12-02 09:42:03', 33, '2005-12-07 00:00:00', 2, 'created', 0, '2005-12-02 09:42:03', 4, 't', 't', '2005-12-02 09:42:03', 0, '2005-12-02 09:42:03', 0);
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (44, 33, 'dude's name', '', '2005-12-02 09:42:54', '2005-12-02 09:42:54', 8, 1, '2005-12-02 09:42:54', 33, '2005-12-07 00:00:00', 2, 'created', 0, '2005-12-02 09:42:54', 6, 't', 't', '2005-12-02 09:42:54', 0, '2005-12-02 09:42:54', 0);
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (45, 33, 'dude's name', '', '2005-12-02 09:43:50', '2005-12-02 09:43:50', 4, 1, '2005-12-02 09:43:50', 33, '2005-12-07 00:00:00', 2, 'created', 0, '2005-12-02 09:43:50', 14, 't', 't', '2005-12-02 09:43:50', 0, '2005-12-02 09:43:50', 0);
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (46, 42, 'Call customer', '', '2005-12-02 09:45:45', '2005-12-02 09:45:45', 7, 1, '2005-12-02 09:45:45', 33, '2005-12-07 00:00:00', 2, 'created', 0, '2005-12-02 09:45:45', 3, 'f', 'f', '2005-12-02 09:45:45', 0, '2005-12-02 09:45:45', 0);
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (33, 0, 'place', '', '2005-12-01 18:32:25', '2005-12-02 09:43:25', 4, 4, '2005-12-02 09:43:25', 33, '2005-12-07 00:00:00', 3, 'nolimit', 0, '2005-12-01 18:32:25', 13, 't', 'f', '2005-12-01 18:32:25', 0, '2005-12-01 18:32:25', 0);
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (53, 51, 'test for parent 36', '', '2005-12-02 14:16:12', '2005-12-02 14:16:12', 1, 1, '2005-12-02 14:16:12', 33, '2005-12-07 00:00:00', 2, 'created', 0, '2005-12-02 14:16:12', 3, 'f', 't', '2005-12-02 14:16:12', 0, '2005-12-02 14:16:12', 0);
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (49, 46, 'Find the customer phone number', '', '2005-12-02 12:02:58', '2005-12-02 13:33:26', 1, 1, '2005-12-02 13:33:26', 33, '2005-12-04 00:00:00', 2, 'created', 0, '2005-12-02 12:02:58', 3, 'f', 't', '2005-12-02 12:02:58', 0, '2005-12-02 12:02:58', 0);
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (41, 33, 'dude's name', '', '2005-12-02 09:40:59', '2005-12-02 09:40:59', 6, 1, '2005-12-02 09:40:59', 33, '2006-12-01 00:00:00', 2, 'created', 0, '2005-12-02 09:40:59', 8, 'f', 't', '2005-12-02 09:40:59', 0, '2005-12-02 09:40:59', 0);
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (51, 46, 'Hang up the phone', '', '2005-12-02 12:39:40', '2005-12-02 13:24:06', 1, 1, '2005-12-02 13:24:06', 33, '2005-12-07 00:00:00', 2, 'created', 0, '2005-12-02 12:39:40', 3, 'f', 't', '2005-12-02 12:39:40', 0, '2005-12-02 12:39:40', 0);
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (54, 42, 'task 1', '', '2005-12-02 16:13:07', '2005-12-02 16:13:07', 2, 2, '2005-12-02 16:13:07', 33, '2005-12-07 00:00:00', 2, 'created', 0, '2005-12-02 16:13:37', 0, 'f', 't', '2005-12-02 16:13:07', 0, '2005-12-02 16:13:07', 0);
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (55, 54, 'task 2', '', '2005-12-02 16:13:14', '2005-12-02 16:13:14', 2, 2, '2005-12-02 16:13:14', 33, '2005-12-07 00:00:00', 2, 'created', 0, '2005-12-02 16:13:14', 0, 'f', 't', '2005-12-02 16:13:14', 0, '2005-12-02 16:13:14', 0);
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (56, 0, 'test project', '', '2005-12-02 16:31:03', '2005-12-02 16:31:03', 1, 1, '2005-12-02 16:31:03', 56, '2005-12-02 00:00:00', 2, 'active', 0, '2005-12-02 16:31:03', 0, 'f', 't', '2005-12-02 16:31:03', 0, '2005-12-02 16:31:03', 0);
INSERT INTO `tasks` (`id`, `parent`, `name`, `text`, `created`, `edited`, `owner`, `creator`, `finished_time`, `projectid`, `deadline`, `priority`, `status`, `taskgroupid`, `lastforumpost`, `usergroupid`, `globalaccess`, `groupaccess`, `lastfileupload`, `completed`, `completion_time`, `archive`) VALUES (57, 56, 'test project 2 task', '', '2005-12-02 16:31:14', '2005-12-02 16:31:14', 1, 1, '2005-12-02 16:31:14', 56, '2005-12-02 00:00:00', 2, 'created', 0, '2005-12-02 16:31:14', 0, 'f', 't', '2005-12-02 16:31:14', 0, '2005-12-02 16:31:14', 0);
Last edited by DSD; 12-05-2005 at 11:59 AM.
|

12-05-2005, 03:50 PM
|
|
Community Liaison 2.0
|
|
Join Date: May 2004
Location: Akron/Canton, Ohio (USA)
Posts: 11,114
|
|
Moved to Employment Offers and Requests
Me? I would have asked for someone to do it for free!
__________________
Studio1337___̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡ ̡͌l̡̡̡̡.__Web Design
|

12-05-2005, 04:08 PM
|
|
Web Hosting Evangelist
|
|
Join Date: Dec 2001
Posts: 506
|
|
It's one of those - "Terry I'm going to need this fixed as soon as possible" and me wondering what they heck a database query is. I'm desperate for some coding...
|

12-06-2005, 05:27 AM
|
|
Web Hosting Guru
|
|
Join Date: Aug 2002
Posts: 261
|
|
I don't have time to do this for you but the best way to go about this is to create a function with 3 different variables.
PHP Code:
function check ($parent_id, $subs, $limit = 1) { // query here $project = db_result(db_query('SELECT projectid FROM '.PRE.'tasks WHERE id='.$parent_id ), 0, 0 ); if ($project['projectid']) { check ($project['projectid'], $subs++, $limit); } else { if ($subs > $limit) { // too many subs return false; } else { // it's fine return true; } } }
That's not going to work exactly how you want it but anyone who wants to earn $5 can modify it for you.
|

12-06-2005, 10:41 AM
|
|
Web Hosting Evangelist
|
|
Join Date: Dec 2001
Posts: 506
|
|
Thank you very much creativeLogic. I'd be happy to give you $10 to finish it off and get it working. I haven't had many takers, and while I can normally edit stuff fine, I haven't a clue in this case.
|

12-06-2005, 10:49 AM
|
|
Web Hosting Evangelist
|
|
Join Date: Dec 2001
Posts: 506
|
|
I received this answer from the author:
----
To limit the total number of tasks to a project with id=4:
'SELECT COUNT(*) FROM tasks WHERE projectid=4'
The project and it's tasks will all share the projectid
equal to the project's id.
-----
To limit the number of tasks levels below a project:
'SELECT DISTINCT parent FROM tasks WHERE projectid=4'
Then count the number of (distinct) rows with db_numrows() -
a WebCollab function. Each row is a layer of tasks.
Could probably use 'DISTINCT COUNT(parent)' to count
directly. I'd have to check if the SQL is legal...
|

12-07-2005, 09:25 AM
|
|
WHT Addict
|
|
Join Date: Apr 2004
Location: Port St Lucie, FL
Posts: 117
|
|
Are you looking to limit the number of child levels for tasks, or just the number of children each task can have? In other words, it's fairly easy to limit the number of children each task can have, but if you want to limit the total number of descendants that's another story..
|

12-07-2005, 09:35 AM
|
|
Web Hosting Evangelist
|
|
Join Date: Dec 2001
Posts: 506
|
|
I'd like to limit the number of descendants (I belive). I would like a main project to be able to have 100 tasks under it, and I would like those 100 tasks to have 100 sub tasks, but I don't want the tree to go any further.
Right now you could make 100 levels of tasks and subtasks.
|

12-07-2005, 09:43 AM
|
|
WHT Addict
|
|
Join Date: Apr 2004
Location: Port St Lucie, FL
Posts: 117
|
|
Okay, I got it now - you want to limit the number of descendant levels, not the number of descendants per level. I've got a meeting this morning but I'll try to have something for you in the next few hours.
|

12-07-2005, 09:54 AM
|
|
Web Hosting Evangelist
|
|
Join Date: Dec 2001
Posts: 506
|
|
right. If I could get a variable at the top of the page like $decendant_levels = "3" that would rule.
Thank you!
|

12-07-2005, 02:31 PM
|
|
WHT Addict
|
|
Join Date: Apr 2004
Location: Port St Lucie, FL
Posts: 117
|
|
Okay, I think I got it.
At the top of the file, after your includes, put this function definition..
PHP Code:
function check_parentage ($id_to_check, $subs, $limit = 2) { if ($subs > $limit) { // Too Many Subs.. return false; } else { $project = db_result(db_query('SELECT parent FROM '.PRE.'tasks WHERE id='.$id_to_check ), 0, 0 ); if ($project['parent']) { return check_parentage ($project['parent'], $subs++, $limit); } else { return true; } } }
And, after this line:
PHP Code:
if( ! $parent_row = db_fetch_array($q, 0 ) ) { error('Task add', 'No parent for taskid' ); }
Add this line..
PHP Code:
if ( ! check_parentage($parent_row['parent'], 1) ) { error('Task add', 'Too many levels' ); }
The $limit in the function is the number of "parent" levels it'll allow before erroring out.
Last edited by stormraven; 12-07-2005 at 02:45 PM.
|

12-07-2005, 03:04 PM
|
|
Web Hosting Evangelist
|
|
Join Date: Dec 2001
Posts: 506
|
|
stormraven - thank you very much, I think we're close!
The changes didn't seem to do anything, so I changed your function to this:
Code:
function check_parentage ($id_to_check, $subs, $limit = 2)
{
echo "<hr>starting to run<hr>";
if ($subs > $limit)
{
// Too Many Subs..
return false;
echo "<hr>too many subs<hr>";
}
else
{
$project = db_result(db_query('SELECT parent FROM '.PRE.'tasks WHERE id='.$id_to_check ), 0, 0 );
if ($project['parent'])
{
return check_parentage ($project['parent'], $subs++, $limit);
echo "<hr>running<hr>";
}
else
{
return true;
echo "<hr>true<hr>";
}
}
}
and when I run task_add now, I see this at the top of my screen:
------
starting to run
------
starting to run
------
but it lets me add as many levels of tasks as I'd like
|

12-07-2005, 03:51 PM
|
|
WHT Addict
|
|
Join Date: Apr 2004
Location: Port St Lucie, FL
Posts: 117
|
|
Move the echoes before the return statements; that should at least show you what's going on.
|

12-07-2005, 03:58 PM
|
|
Web Hosting Evangelist
|
|
Join Date: Dec 2001
Posts: 506
|
|
new function:
Code:
function check_parentage ($id_to_check, $subs, $limit = 2)
{
echo "<hr>starting to run";
if ($subs > $limit)
{
// Too Many Subs..
echo "<hr>too many subs";
return false;
}
else
{
$project = db_result(db_query('SELECT parent FROM '.PRE.'tasks WHERE id='.$id_to_check ), 0, 0 );
if ($project['parent'])
{
echo "<hr>subs equal";
echo $subs;
echo "<hr>limit equals";
echo $limit;
return check_parentage ($project['parent'], $subs++, $limit);
}
else
{
echo "<hr>true";
return true;
}
}
}
new result:
starting to run
subs equal1
limit equals2
starting to run
true
|

12-08-2005, 08:14 PM
|
|
WHT Addict
|
|
Join Date: Apr 2004
Location: Port St Lucie, FL
Posts: 117
|
|
Try this.. it should show you the rows that are being checked.
You can also email me (in my sig) if you want to take this offline.
PHP Code:
function check_parentage ($id_to_check, $subs, $limit = 2)
{
echo "<hr>starting to run - checking $id_to_check, subs = $subs, limit = $limit <br />";
if ($subs > $limit)
{
// Too Many Subs..
echo "<hr>too many subs";
return false;
}
else
{
$project = db_result(db_query('SELECT parent FROM '.PRE.'tasks WHERE id='.$id_to_check ), 0, 0 );
if ($project['parent'])
{
echo "<hr>subs equal";
echo $subs;
echo "<hr>limit equals";
echo $limit;
return check_parentage ($project['parent'], $subs++, $limit);
}
else
{
echo "<hr>true";
return true;
}
}
}
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|