示例#1
0
     $task_false_value = '';
     if ($taskID != null) {
         $sql = "Select nf_templateDataToFalse FROM {$_TABLES['nf_templatedatanextstep']} WHERE nf_templateDataFrom={$taskID} ";
         $sql .= "ORDER BY nf_templateDataToFalse ";
         $tempvar = DB_query($sql);
         $numTasks = DB_numRows($tempvar);
         if ($numTasks > 0) {
             for ($tasksCntr = 0; $tasksCntr < $numTasks; $tasksCntr++) {
                 if ($tasksCntr > 0) {
                     if ($X[0] != 0) {
                         $task_false_value .= ',';
                     }
                 }
                 $X = DB_fetchArray($tempvar);
                 if ($X[0] != 0) {
                     $task_false_value .= nfidtolid($X[0]);
                 }
             }
         }
     }
     $p->set_var('if_taskfalse_value', $task_false_value);
 } else {
     $logical_taskid = getnextlid($templateID);
     $p->set_var('logical_task_id', $logical_taskid);
     $p->set_var('steptype_options', COM_optionList($_TABLES['nf_steptype'], 'id,stepType', '', 0));
     $p->set_var('form_options', COM_optionList($_TABLES['nxform_definitions'], 'id,name'));
     $p->set_var('task_handler_selection', nf_makeDropDown("id", "handler", $_TABLES['nf_handlers']));
     $p->set_var('next_tasks', '');
     $userOptions = COM_optionList($_TABLES['users'], 'uid,fullname', '', 1, "fullname <> '' AND uid > 1");
     $p->set_var('available_userOptions', $userOptions);
     $variableOptions = nf_makeDropDownWithSelected("id", "variableName", $_TABLES['nf_templatevariables'], $taskRec['dynamicFormVariableID'], '', 1);
示例#2
0
function nf_copyTemplate($templateID)
{
    global $_TABLES;
    $templateID = NXCOM_filterInt($templateID);
    $sql = "SELECT * FROM {$_TABLES['nf_template']} WHERE id='{$templateID}'";
    $A = DB_fetchArray(DB_Query($sql));
    DB_query("INSERT INTO {$_TABLES['nf_template']}(templateName,useProject,AppGroup) values('{$A['templateName']}-copy',{$A['AppGroup']},{$A['useProject']})");
    $newTemplateId = DB_insertID();
    // Need to copy all the Template Data records
    $sql = "SELECT * FROM {$_TABLES['nf_templatedata']} WHERE nf_templateID='{$templateID}'";
    $q1 = DB_Query($sql);
    $fields = 'nf_templateID, logicalID, nf_stepType, nf_handlerId, firstTask, taskname, ';
    $fields .= 'assignedByVariable, argumentVariable, argumentProcess, operator, ifValue, regenerate,';
    $fields .= 'regenAllLiveTasks, isDynamicForm, dynamicFormVariableID, isDynamicTaskName, dynamicTaskNameVariableID, ';
    $fields .= 'function, formid, optionalParm ';
    /* Need to update fields that are linked to template variables */
    while ($A = DB_fetchArray($q1)) {
        $values = "{$newTemplateId}, {$A['logicalID']}, {$A['nf_stepType']}, ";
        $values .= "{$A['nf_handlerId']}, {$A['firstTask']}, '{$A['taskname']}', {$A['assignedByVariable']}, ";
        $values .= "'{$A['argumentVariable']}', '{$A['argumentProcess']}', '{$A['operator']}', ";
        $values .= "'{$A['ifValue']}', {$A['regenerate']}, {$A['regenAllLiveTasks']},{$A['isDynamicForm']},";
        $values .= "{$A['dynamicFormVariableID']}, {$A['isDynamicTaskName']}, {$A['dynamicTaskNameVariableID']},";
        $values .= "'{$A['function']}', {$A['formid']}, '{$A['optionalParm']}'";
        $sql = "INSERT INTO {$_TABLES['nf_templatedata']} ({$fields}) VALUES ({$values}) ";
        DB_Query($sql);
        $newTemplateDataId = DB_insertID();
        // Need to copy all the Template DataNextStep record matching the source templateData record
        $sql = "SELECT * FROM {$_TABLES['nf_templatedatanextstep']} WHERE nf_templateDataFrom='{$A['id']}'";
        $q2 = DB_Query($sql);
        if (DB_numRows($q2) > 0) {
            $B = DB_fetchArray($q2);
            if ($newTemplateDataId != 0) {
                $sql = "INSERT INTO {$_TABLES['nf_templatedatanextstep']} (nf_templateDataFrom) VALUES ('{$newTemplateDataId}') ";
                DB_query($sql);
            }
        }
    }
    // Now we can cycle thru these tasks again and update the values for the fields linking the tasks
    $sql = "SELECT a.id, a.logicalID, b.nf_templateDataTo, b.nf_templateDataToFalse FROM {$_TABLES['nf_templatedata']} a ";
    $sql .= "INNER JOIN {$_TABLES['nf_templatedatanextstep']} b on a.id = b.nf_templateDataFrom ";
    $sql .= "WHERE nf_templateID='{$templateID}'";
    $q2 = DB_Query($sql);
    $test = DB_numRows($q2);
    while (list($sourceTaskid, $sourceLogicalID, $sourceToTaskid, $sourceFalseTaskid) = DB_fetchArray($q2)) {
        // Get the ID of the matching source logical task in the new template
        $newFromTaskid = DB_getItem($_TABLES['nf_templatedata'], 'id', "logicalID={$sourceLogicalID} AND nf_templateID={$newTemplateId}");
        // Get the ID of the matching source logical task in the new template
        $targetLogicalId = nfidtolid($sourceToTaskid);
        $test = nfidtolid($sourceToTaskid);
        // DB_getItem($_TABLES['nf_templatedata'],'logicalID', "id=$sourceToTaskid");
        $newToTaskid = DB_getItem($_TABLES['nf_templatedata'], 'id', "logicalID={$targetLogicalId} AND nf_templateID={$newTemplateId}");
        // Update the record field nf_templateTo for the new template
        DB_query("UPDATE {$_TABLES['nf_templatedatanextstep']} SET nf_templateDataTo={$newToTaskid} WHERE nf_templateDataFrom={$newFromTaskid}");
        if ($sourceFalseTaskid > 0) {
            $targetFalseLogicalId = nfidtolid($sourceFalseTaskid);
            //DB_getItem($_TABLES['nf_templatedata'],'logicalID', "id=$sourceFalseTaskid");
            $newFalseTaskid = DB_getItem($_TABLES['nf_templatedata'], 'id', "logicalID={$targetFalseLogicalId} AND nf_templateID={$newTemplateId}");
            DB_query("UPDATE {$_TABLES['nf_templatedatanextstep']} SET nf_templateDataToFalse={$newFalseTaskid} WHERE nf_templateDataFrom={$newFromTaskid}");
        }
    }
    // Need to now copy and update the template Variable records
    $query = DB_query("SELECT id, nf_variableTypeID, variableName, variableValue FROM {$_TABLES['nf_templatevariables']} WHERE nf_templateID={$templateID}");
    $templateVariableMap = array();
    while (list($variableID, $variableTypeID, $variableName, $variableValue) = DB_fetchArray($query)) {
        $sql = "INSERT INTO {$_TABLES['nf_templatevariables']} (nf_templateID,nf_variableTypeID,variableName,variableValue) ";
        $sql .= "VALUES ({$newTemplateId}, {$variableTypeID},'{$variableName}','{$variableValue}')";
        DB_query($sql);
        $newVariableID = DB_insertID();
        $sql = "UPDATE {$_TABLES['nf_templatedata']} SET dynamicTaskNameVariableID={$newVariableID} ";
        $sql .= "WHERE id={$newFromTaskid} AND dynamicTaskNameVariableID={$variableID}";
        DB_query($sql);
        // Create a mapping of the original to new template variable ID's so we can update the template task records
        $templateVariableMap[$variableID] = $newVariableID;
    }
    // Retrieve the assignment records for the interactive tasks and insert / update for the copied template
    $sql = "SELECT a.id,a.logicalID,b.uid,b.gid,b.nf_processVariable,b.nf_prenotifyVariable,b.nf_postnotifyVariable,b.nf_remindernotifyVariable ";
    $sql .= "FROM {$_TABLES['nf_templatedata']} a INNER JOIN {$_TABLES['nf_templateassignment']} b on a.id=b.nf_templateDataID ";
    $sql .= "WHERE a.nf_templateID = {$templateID} ";
    $query = DB_query($sql);
    $fields = 'nf_templateDataID,uid,gid,nf_processVariable,nf_prenotifyVariable,nf_postnotifyVariable,nf_remindernotifyVariable';
    while ($A = DB_fetchArray($query)) {
        // Determine the matching taskid in the new template
        $newTaskid = DB_getItem($_TABLES['nf_templatedata'], 'id', "logicalID={$A['logicalID']} AND nf_templateID={$newTemplateId}");
        $sql = "INSERT INTO {$_TABLES['nf_templateassignment']} ({$fields}) VALUES ";
        $sql .= "( {$newTaskid},{$A['uid']},{$A['gid']},{$A['nf_processVariable']},{$A['nf_prenotifyVariable']},";
        $sql .= "{$A['nf_postnotifyVariable']},{$A['nf_remindernotifyVariable']} )";
        DB_query($sql);
        $newAssignmentRecord = DB_insertID();
        // Update field with matching template variable ID
        if ($A['nf_processVariable'] > 0) {
            $variableID = $templateVariableMap[$A['nf_processVariable']];
            DB_query("UPDATE {$_TABLES['nf_templateassignment']} SET nf_processVariable={$variableID} WHERE id={$newAssignmentRecord}");
        }
    }
}