Exemple #1
0
function prj_moveProjectDown($projectId)
{
    global $_TABLES;
    $plist = prj_getProjectIds();
    $sql = "SELECT pid, lhs, rhs, parent_id FROM {$_TABLES['prj_projects']} WHERE pid='{$projectId}'";
    $res = DB_query($sql);
    list($thisPID, $thisLHS, $thisRHS, $thisParentID) = DB_fetchArray($res);
    if ($thisParentID != '0') {
        $sql = "SELECT lhs, rhs FROM {$_TABLES['prj_projects']} WHERE pid='{$thisParentID}'";
        $res = DB_query($sql);
        list($parentLHS, $parentRHS) = DB_fetchArray($res);
        $sql = "SELECT pid, lhs, rhs FROM {$_TABLES['prj_projects']} WHERE  lhs > '{$thisRHS}' AND pid in ({$plist}) AND lhs between '{$parentLHS}' AND '{$parentRHS}' ORDER BY lhs ASC LIMIT 1";
    } else {
        //parent task is 0.. moving a full container
        $sql = "SELECT pid, lhs, rhs FROM {$_TABLES['prj_projects']} WHERE  lhs > '{$thisRHS}' AND pid in ({$plist}) ORDER BY lhs ASC LIMIT 1";
    }
    $res = DB_query($sql);
    $nrows = DB_numRows($res);
    if ($nrows > 0) {
        list($swapTID, $swapLHS, $swapRHS) = DB_fetchArray($res);
        $sql = "SELECT * FROM {$_TABLES['prj_projects']} WHERE lhs > '{$thisLHS}' AND rhs < '{$thisRHS}'";
        $thisSubs = DB_query($sql);
        $sql = "SELECT * FROM {$_TABLES['prj_projects']} WHERE lhs > '{$swapLHS}' AND rhs < '{$swapRHS}'";
        $swapSubs = DB_query($sql);
        //thissubs and swapsubs now hold all the children for the swapping members.
        //now swap the two parent lhs and rhs values
        $sql = "UPDATE {$_TABLES['prj_projects']} SET ";
        $sql .= "lhs='{$swapLHS}',";
        $sql .= "rhs='{$swapRHS}' ";
        $sql .= "WHERE pid='{$thisPID}'";
        DB_query($sql);
        $sql = "UPDATE {$_TABLES['prj_projects']} SET ";
        $sql .= "lhs='{$thisLHS}',";
        $sql .= "rhs='{$thisRHS}' ";
        $sql .= "WHERE pid='{$swapTID}'";
        DB_query($sql);
        //now just insert all the children back in...
        //first THIS tid's children
        $nrows = DB_numRows($thisSubs);
        for ($cntr = 0; $cntr < $nrows; $cntr++) {
            $A = DB_fetchArray($thisSubs);
            $lastInsert = 0;
            $lastInsert = prj_insertProject($A['parent_id']);
            $sql = "SELECT lhs, rhs FROM {$_TABLES['prj_projects']} WHERE pid={$lastInsert}";
            $res = DB_query($sql);
            list($newLHS, $newRHS) = DB_fetchArray($res);
            $sql = "DELETE FROM {$_TABLES['prj_projects']} WHERE pid='{$lastInsert}'";
            DB_query($sql);
            $sql = "UPDATE {$_TABLES['prj_projects']} SET lhs='{$newLHS}', rhs='{$newRHS}' WHERE pid='{$A['pid']}'";
            DB_query($sql);
        }
        $nrows = DB_numRows($swapSubs);
        for ($cntr = 0; $cntr < $nrows; $cntr++) {
            //we're doing a blind insert here
            $A = DB_fetchArray($swapSubs);
            $lastInsert = 0;
            $lastInsert = prj_insertProject($A['parent_id']);
            $sql = "SELECT lhs, rhs FROM {$_TABLES['prj_projects']} WHERE pid='{$lastInsert}'";
            $res = DB_query($sql);
            list($newLHS, $newRHS) = DB_fetchArray($res);
            $sql = "DELETE FROM {$_TABLES['prj_projects']} WHERE pid='{$lastInsert}'";
            DB_query($sql);
            $sql = "UPDATE {$_TABLES['prj_projects']} SET lhs='{$newLHS}', rhs='{$newRHS}' WHERE pid='{$A['pid']}'";
            DB_query($sql);
        }
    } else {
        //nothing to swap to
        //here just incase you want to catch this condition
    }
}
Exemple #2
0
 if ($_CLEAN['actual_end_date'] < $_CLEAN['startdate']) {
     $_CLEAN['actual_end_date'] = $_CLEAN['startdate'] + 604800;
     //add 1 week to the start date...
 }
 if ($_CLEAN['estimateddate'] < $_CLEAN['startdate']) {
     $_CLEAN['estimateddate'] = $_CLEAN['startdate'] + 604800;
     //add 1 week to the start date...
 }
 $_CLEAN['document'] = $_CLEAN['document'] == 'Y' ? 'Y' : 'N';
 $_CLEAN['forum'] = $_CLEAN['forum'] == 'Y' ? 'Y' : 'N';
 //randy's comments:
 //we're inserting a new blank project with the appropriate Parent ID
 //in order to retrieve back the next useful LHS and RHS values.
 //If there is a parent, then the LHS and RHS need to have valid values
 //that fall between the parent's LHS and RHS values.
 $lastInsert = prj_insertProject($A['parent_id']);
 $sql = "SELECT lhs, rhs FROM {$_TABLES['prj_projects']} WHERE pid='{$lastInsert}'";
 $res = DB_query($sql);
 list($newLHS, $newRHS) = DB_fetchArray($res);
 $sql = "DELETE FROM {$_TABLES['prj_projects']} WHERE pid='{$lastInsert}'";
 DB_query($sql);
 // Setup Insert SQL Statement
 $fields = 'name, description, is_using_docmgmt_flag, is_using_forum_flag, is_private_project_flag,';
 $fields .= 'is_template_project_flag, keywords, priority_id, status_id, objective_id,';
 $fields .= 'progress_id, create_date, start_date, estimated_end_date, planned_end_date,';
 $fields .= 'actual_end_date, percent_completion, last_updated_date, notification_enabled_flag, lhs, rhs';
 $values = "'{$_CLEAN['name']}','{$_CLEAN['description']}','{$_CLEAN['document']}','{$_CLEAN['forum']}',";
 $values .= "'{$_CLEAN['private']}','{$_CLEAN['template']}','{$_CLEAN['keywords']}',{$_CLEAN['priority']},";
 $values .= "{$_CLEAN['status']},{$_CLEAN['objective']},{$_CLEAN['progress']},{$_CLEAN['createdate']},";
 $values .= "{$_CLEAN['startdate']},{$_CLEAN['estimateddate']},{$_CLEAN['estimateddate']},{$_CLEAN['actual_end_date']},";
 $values .= "'{$_CLEAN['percent']}',{$_CLEAN['createdate']},'{$_CLEAN['notification']}', '{$newLHS}','{$newRHS}'";