function scan_css($sid = 0) { global $_CONF, $_TABLES, $LANG_NS02, $_USER; $retval = ''; $retval .= COM_startBlock($LANG_NS02['css_scanner']); if ($sid == 0) { $css_files_to_scan = $_REQUEST['css_files']; $file_types = $_REQUEST['file_types']; $scan_dir_text = str_replace('\\', '/', $_REQUEST['scan_dirs']); $orphans_only = $_REQUEST['orphans_only'] != '' ? $_REQUEST['orphans_only'] : 0; $fuzzy_filter = $_REQUEST['fuzzy_filter'] != '' ? $_REQUEST['fuzzy_filter'] : 0; $name = $_REQUEST['scan_name']; if (!is_array($css_files_to_scan) || !is_array($file_types) || $scan_dir_text == '') { $retval .= COM_startBlock($LANG_NS02['error']); $retval .= $LANG_NS02['missing_parameters']; $retval .= COM_endBlock(); return $retval; } $scan_dirs = explode("\r\n", $scan_dir_text); //now scan each directory foreach ($file_types as $key => $type) { $file_types[$key] = $type; } $scan_id = DB_getItem($_TABLES['nxscan_options'], 'scan_id', "1=1 ORDER BY scan_id DESC LIMIT 1") + 1; $file_filter = addslashes(serialize($file_types)); $directories_to_scan = addslashes(serialize($scan_dirs)); $css_files_to_scan = addslashes(serialize($css_files_to_scan)); $name = NXCOM_filterText($name); DB_query("INSERT INTO {$_TABLES['nxscan_options']} (scan_id, user_id, name, css_files_to_scan,\r\n directories_to_scan, file_filter, only_show_unused, fuzzy_filter) VALUES\r\n ({$scan_id}, {$_USER['uid']}, '{$name}', '{$css_files_to_scan}', '{$directories_to_scan}', '{$file_filter}',\r\n {$orphans_only}, {$fuzzy_filter})"); } else { $scan_id = $sid; DB_query("DELETE FROM {$_TABLES['nxscan_cssscan']} WHERE scan_id={$scan_id}"); } //now generate the report $p = new Template($_CONF['path'] . 'plugins/nexscan/templates'); $p->set_file('css_scanner_report', 'css_scanner_report.thtml'); NXCOM_set_common_vars($p); NXCOM_set_language_vars($p, $LANG_NS02); $p->set_var('scan_id', $scan_id); $p->parse('output', 'css_scanner_report'); $retval .= $p->finish($p->get_var('output')); $retval .= COM_endBlock(); return $retval; }
//batch function case 7: //interative function $function = NXCOM_filterText($_POST['task_function']); $sql .= "function='{$function}', "; break; case 8: //nexform $formid = intval($_POST['formid']); $sql .= "formid={$formid}, "; break; case 11: //set process variable $formid = intval($_POST['formValue']); $fieldid = intval($_POST['fieldValue']); $varValue = NXCOM_filterText($_POST['varValue']); $varToSet = intval($_POST['varToSet']); $incValue = intval($_POST['incValue']); $sql .= "formid={$formid}, "; $sql .= "fieldid={$fieldid}, "; $sql .= "varValue='{$varValue}', "; $sql .= "varToSet={$varToSet}, "; $sql .= "incValue={$incValue}, "; break; } //and finish it off with the conditions $sql .= "last_updated=NOW() WHERE id={$taskid}"; DB_query($sql); $retval .= "<taskid>{$taskid}</taskid>\n"; $retval .= "<retval>{$taskname}</retval>\n"; break;
function clean_queue() { global $_TABLES, $_CONF; $processTaskList = array("id" => array(), "processid" => array()); $processTaskListcount = 0; $this->private_sendTaskAssignmentNotifications(); $this->private_sendTaskReminders(); $sql = "SELECT distinct a.id, a.status,a.nf_templateDataID, c.nf_templateID, c.nf_stepType, c.nf_handlerid, "; $sql .= "c.function, e.templateName, f.handler, b.id AS processId, h.steptype "; $sql .= "FROM {$_TABLES['nf_queue']} a inner join {$_TABLES['nf_process']} b on a.nf_processId = b.id "; $sql .= "inner join {$_TABLES['nf_templatedata']} c on a.nf_templateDataId = c.id "; $sql .= "inner join {$_TABLES['nf_template']} e on b.nf_templateId = e.id "; $sql .= "inner join {$_TABLES['nf_steptype']} h on c.nf_steptype = h.id "; $sql .= "left outer join {$_TABLES['nf_handlers']} f on c.nf_handlerId = f.id "; $sql .= "left outer join {$_TABLES['nf_templateassignment']} g on g.nf_templateDataid = c.id "; $sql .= "WHERE ((a.status <>0 AND a.status IS NOT NULL and a.status<>2 and (h.id=1 OR h.id=7 OR h.id=8)) "; $sql .= "OR ((a.status=0 or a.status=3 or a.status=4) and (h.id=2 or h.id=3 or h.id=4 or h.id=5 or h.id=6 or h.id=9 or h.id=10 or h.id=11)) ) "; $sql .= "AND (a.archived <> 1 OR a.archived IS NULL OR a.archived =0 ) and (b.complete=0)"; $result = DB_query($sql); $nrows = DB_numRows($result); if ($this->_debug) { COM_errorLog("nexflow: Number of processes in queue: {$nrows}"); } switch ($nrows) { case 0: if ($this->_debug) { echo "clean_queue - 0 rows returned. Nothing in queue.<BR>"; } break; default: // there is one or more queue items to fuss over. if ($this->_debug) { echo "clean_queue - {$nrows} rows returned.<BR>"; } for ($i = 0; $i < $nrows; $i++) { $A = DB_fetchArray($result); $stepType = $A['steptype']; $processID = NXCOM_filterInt($A['processId']); $queueID = NXCOM_filterInt($A['id']); $handler = $A['handler']; $templateName = $A['templateName']; $templateDataID = $A['nf_templateDataID']; // this switch is used to determine what task type it is. // in the event its a manual web task, we'll just go ahead and clean it up.. // however, in the event that its an AND task, we have to be careful that // we check the preceeding queue elements to ensure that they're all done before completing // the and task and then also entering the next queue item. if ($this->_debug) { COM_errorLog("Process: {$A['processId']} , Step Type: {$stepType}"); } switch (strtolower($stepType)) { case 'start': case 'end': $this->private_nfNextStep($queueID, $processID); break; case 'and': // have processid and tempatedataid // first determine how many tasks must be and-ed together // then determine how many are in wms_nf_queueFrom which are pointing to me // if the first and 2nd numbers are equal, then we're good to test.. // otherwise, skip it. $numComplete = 0; $numIncomplete = 0; $sql = "SELECT count( a.id ) AS templateCount FROM {$_TABLES['nf_queue']} a "; $sql .= "INNER JOIN {$_TABLES['nf_templatedatanextstep']} b "; $sql .= "ON (a.nf_templateDataID = b.nf_templateDataTo "; $sql .= "OR a.nf_templateDataID = b.nf_templateDataToFalse) "; $sql .= "WHERE a.ID ='{$queueID}'"; $templateCountResult = DB_fetchArray(DB_query($sql)); $numComplete = $templateCountResult[0]; $sql = "SELECT count( a.id ) AS processCount FROM {$_TABLES['nf_queuefrom']} a "; $sql .= "INNER JOIN {$_TABLES['nf_queue']} b on a.FromQueueID=b.id "; $sql .= "WHERE (a.queueid = '{$queueID}' or a.queueid=0) "; $sql .= "AND b.nf_processid='{$processID}'"; $processCountResult = DB_fetchArray(DB_query($sql)); $numIncomplete = $processCountResult[0]; if ($this->_debug) { COM_errorLog("Template Count: {$numComplete} and Process Count: {$numIncomplete}"); } // sounds confusing, but if the processCount is greater than the completed ones, we're ok too if ($numIncomplete == $numComplete || $numIncomplete > $numComplete) { // we have all of the incoming items done for this AND // we can now carry out updating this queue item's information $this->private_nfNextStep($queueID, $processID); } else { // not all the incomings for the AND are done // just here for troubleshooting purposes } break; case 'or': break; case 'batch': // since this is an automated task, we need to say that it has not succeeded until the handler's code executes // and resets this variable back to true. $success = false; // Run the batch task's php code, checking to see if it exists first if (file_exists($_CONF['path_html'] . $A['handler'])) { require $_CONF['path_html'] . $A['handler']; } elseif (file_exists($A['handler'])) { // Check in current directory include $A['handler']; } if ($success) { $this->private_nfNextStep($queueID, $processID); } break; //end batch task //end batch task case 'batch function': // since this is an automated task, we need to say that it has not succeeded until the handler's code executes // and resets this variable back to true. $success = false; // Run the batch task's php code, checking to see if it's a function exists if ($A['function'] != '') { if ($this->_debug) { COM_errorLog("Batch Function: {$A['function']}"); } if (function_exists($A['function'])) { $success = $A['function']($queueID, $processID); } } if ($success) { $this->complete_task($queueID); $this->private_nfNextStep($queueID, $processID); } break; //end batch task //end batch task case 'set process variable': $spvRes = DB_query("SELECT formid, fieldid, varValue, incValue, varToSet FROM {$_TABLES['nf_templatedata']} WHERE id={$templateDataID}"); list($formid, $fieldid, $varvalue, $incvalue, $vartoset) = DB_fetchArray($spvRes); if ($vartoset > 0) { //needs to be valid variable to set if ($varvalue != '') { //set by input $setvalue = NXCOM_filterText($varvalue); DB_query("UPDATE {$_TABLES['nf_processvariables']} SET variableValue='{$setvalue}' WHERE nf_processID={$processID} AND nf_templateVariableID={$vartoset}"); } else { if ($formid > 0 && $fieldid > 0) { //set by form result //have to find the form result //first get the project id $spvSql = "SELECT a.variableValue FROM {$_TABLES['nf_processvariables']} a "; $spvSql .= "LEFT JOIN {$_TABLES['nf_templatevariables']} b ON b.id=a.nf_templateVariableID "; $spvSql .= "WHERE b.variableName='PID' AND a.nf_processID={$processID}"; $spvRes = DB_query($spvSql); list($pid) = DB_fetchArray($spvRes); $pid = intval($pid); //now get the form result id $resid = intval(DB_getItem($_TABLES['nf_projectforms'], 'results_id', "project_id={$pid} AND form_id={$formid}")); //now get the result from the field id $setvalue = DB_getItem($_TABLES['nxform_resdata'], 'field_data', "result_id={$resid} AND field_id={$fieldid}"); DB_query("UPDATE {$_TABLES['nf_processvariables']} SET variableValue='{$setvalue}' WHERE nf_processID={$processID} AND nf_templateVariableID={$vartoset}"); } else { if ($incvalue != 0) { //set by increment $curvalue = intval(DB_getItem($_TABLES['nf_processvariables'], 'variableValue', "nf_processID={$processID} AND nf_templateVariableID={$vartoset}")); $setvalue = $curvalue + $incvalue; DB_query("UPDATE {$_TABLES['nf_processvariables']} SET variableValue='{$setvalue}' WHERE nf_processID={$processID} AND nf_templateVariableID={$vartoset}"); } } } } $this->private_nfNextStep($queueID, $processID); break; case 'if': // if task is a conditional task that looks for a single expression to evaluate // a true and false branch is required for this task type. // 1st determine what the argument is $sql = "SELECT a.ifValue,b.variableName, b.id as variableID, c.logicalEntry, d.operator "; $sql .= "FROM {$_TABLES['nf_templatedata']} a "; $sql .= "LEFT OUTER JOIN {$_TABLES['nf_templatevariables']} b on a.argumentVariable=b.id "; $sql .= "LEFT OUTER JOIN {$_TABLES['nf_ifprocessarguments']} c on a.argumentProcess=c.id "; $sql .= "LEFT OUTER JOIN {$_TABLES['nf_ifoperators']} d on a.operator=d.id "; $sql .= "WHERE a.id='{$templateDataID}' limit 0,1 "; $nextTaskResult = DB_query($sql); $nextTaskRows = DB_numRows($nextTaskResult); // holding the template's data in the result set now. should only be 1 row. if ($nextTaskRows > 0) { $C = DB_fetchArray($nextTaskResult); $templateVariableID = $C['variableID']; $operator = $C['operator']; $ifValue = $C['ifValue']; if ($C['variableID'] == null or $C['variableID'] == '') { // logical entry it is // using the logical entry, lets switch the logicalEntry value and determine what it is we should be comparing to // no matter how you slice it, we're going to need the last task's status. // get the last task's TemplateDataID, then query the queue for this process with the newly sourced templateDataID $sql = "SELECT b.status FROM {$_TABLES['nf_queuefrom']} a "; $sql .= "LEFT OUTER JOIN {$_TABLES['nf_queue']} b on b.id=a.fromqueueid "; $sql .= "WHERE a.queueid={$queueID} "; $statusResult = DB_query($sql); $D = DB_fetchArray($statusResult); $lastStatus = $D[0]; // $lastStatus now holds the value $whichBranch = null; // status // 0-ready //1-complete //2-on hold //3-aborted //4-if Condition False switch (strtolower($C['logicalEntry'])) { case 'lasttasksuccess': if ($lastStatus == 0 or $lastStatus == 1) { $whichBranch = 1; } else { $whichBranch = 0; } break; case 'lasttaskcancel': if ($lastStatus == 3) { $whichBranch = 1; } else { $whichBranch = 0; } break; case 'lasttaskhold': if ($lastStatus == 2) { $whichBranch = 1; } else { $whichBranch = 0; } break; case 'lasttaskaborted': if ($lastStatus == 3) { $whichBranch = 1; } else { $whichBranch = 0; } break; } //end switch if ($this->_debug) { COM_errorLog("NEXFLOW cleanqueue: Task: {$queueID}, IF Task => laststatus: {$lastStatus}, Branch: {$whichBranch}"); } } else { // variableID it is // need to perform a variable to value operation based on the selected operation! // $templateVariableID ,$operator ,$ifValue, $processID // need to select the process variable using the ID from the current process $sql = "SELECT variableValue FROM {$_TABLES['nf_processvariables']} "; $sql .= "WHERE nf_processID={$processID} AND nf_templateVariableID={$templateVariableID}"; $ifQuery = DB_query($sql); $ifQueryNumRows = DB_numRows($ifQuery); if ($ifQueryNumRows > 0) { // should have a variable Value here. $ifArray = DB_fetchArray($ifQuery); $variableValue = $ifArray[0]; if ($this->_debug) { COM_errorLog("IF COMPARE => Operator: {$operator} and compare {$variableValue} to {$ifValue}"); } switch ($operator) { case '=': if ($variableValue == $ifValue) { $whichBranch = 1; } else { $whichBranch = 0; } break; case '<': if ($variableValue < $ifValue) { $whichBranch = 1; } else { $whichBranch = 0; } break; case '>': if ($variableValue > $ifValue) { $whichBranch = 1; } else { $whichBranch = 0; } break; case '!=': if ($variableValue != $ifValue) { $whichBranch = 1; } else { $whichBranch = 0; } break; } //end switch($operator) } else { // force the branch to the false side since the variable dosent exist... // can't be true if it dosent exist!!! $whichBranch = 0; } } //end else variableID // here we have common code for both the logical or the variable driven IF // create new queue items dependent upon the $whichBranch variable if ($whichBranch == 1) { // complete this task and create queue items that point to the true branch $sql = "SELECT c.nf_templateDataTo FROM {$_TABLES['nf_queue']} a, {$_TABLES['nf_templatedatanextstep']} c "; $sql .= "WHERE a.nf_templateDataid=c.nf_templateDataFrom "; $sql .= "AND a.nf_processID={$processID} AND a.id={$queueID}"; $statusToinsert = 1; } else { // complete this task and create queue items that point to the false branch $sql = "SELECT c.nf_templateDataToFalse FROM {$_TABLES['nf_queue']} a, {$_TABLES['nf_templatedatanextstep']} c "; $sql .= "WHERE a.nf_templateDataid=c.nf_templateDataFrom "; $sql .= "AND a.nf_processID={$processID} AND a.id={$queueID}"; $statusToinsert = 4; } $nextTaskResult = DB_query($sql); $nextTaskRows = DB_numRows($nextTaskResult); if ($nextTaskRows == 0) { // if there are no rows for this specific QueueID and nothing for this processID, there's no next task $this->archive_task($queueID, $statusToinsert); $sql = "UPDATE {$_TABLES['nf_process']} set complete=1 where id={$processID}"; $updateQuery = DB_query($sql); //if there is a project, update that status $sql = "UPDATE {$_TABLES['nf_projects']} set status=1 where wf_process_id={$processID}"; DB_query($sql); } else { // we've got tasks for ($nextStepCntr = 0; $nextStepCntr < $nextTaskRows; $nextStepCntr++) { $C = DB_fetchArray($nextTaskResult); if ($C[0] == null or $C[0] == '') { // the process is done, Archive the queue item adn set process to complete $this->archive_task($queueID, $statusToinsert); $updateQuery = DB_query("UPDATE {$_TABLES['nf_process']} set complete=1 where id={$processID}"); } else { // we have a next step, thus we can archive the queue item and also insert a // new queue item with the next step populated as the next templatestepid // echo "next step available"; $sql = "SELECT * FROM {$_TABLES['nf_queue']} a "; $sql .= "WHERE a.nf_processid='{$processID}' AND a.nf_templateDataid='{$C[0]}'"; $updateQuery = DB_query($sql); $updateQueryRows = DB_numRows($updateQuery); $retrieveQueryArray = DB_fetchArray($updateQuery); if ($this->_debug) { COM_errorLog("If Task - Queue records Number: {$updateQueryRows}"); } if ($updateQueryRows == 0) { // we have the situation here where we have no next item.. this means we // can create the next queue item.. $thisDate = date('Y-m-d H:i:s'); $sql = "INSERT INTO {$_TABLES['nf_queue']} (nf_processID, nf_templateDataID, status,createdDate) "; $sql .= "VALUES ('{$processID}','{$C[0]}',0,'{$thisDate}')"; $updateQuery = DB_query($sql); $newTaskid = DB_insertID(); if ($this->_debug) { $logmsg = "Nexflow: New queue id (2) : {$newTaskid} - Template Taskid: {$C[0]} - "; $logmsg .= "Assigned to: " . COM_getDisplayName(nf_getTaskOwner($C[0], $processID)); nf_notificationLog($logmsg); } // Add a new records to the queueFrom table now as well for this new queue record $sql = "INSERT INTO {$_TABLES['nf_queuefrom']} (queueID,fromQueueID) values ('{$newTaskid}','{$queueID}')"; DB_query($sql); // Insert new assignment records for this new task - if an interactive task $newTaskAssignedUsers = $this->private_getAssignedUID($newTaskid); if (is_array($newTaskAssignedUsers) and count($newTaskAssignedUsers) > 0) { $this->assign_task($newTaskid, $newTaskAssignedUsers); } // Determine if task has a reminder set and if so then update the nextReminderTime field in the new queue record $reminderInterval = DB_getItem($_TABLES['nf_templatedata'], 'reminderInterval', "id='{$C[0]}'"); if ($reminderInterval > 0) { $sql = "UPDATE {$_TABLES['nf_queue']} SET nextReminderTime=DATE_ADD( NOW(), "; $sql .= "INTERVAL {$reminderInterval} DAY) where id='{$newTaskid}'"; DB_query($sql); } // Check if notification has been defined for new task assignment $this->private_sendTaskAssignmentNotifications(); $this->archive_task($queueID, $statusToinsert); } else { // we have a situation here where the next item already exists. // need to determine if the next item has a regeneration flag. // if there is a regeneration flag, then create a new process starting with that regeneration flagged item $sql = "SELECT * FROM {$_TABLES['nf_templatedata']} a WHERE a.id={$C[0]}"; $regenResult = DB_query($sql); $regenCount = DB_numRows($regenResult); $regenArray = DB_fetchArray($regenResult); $toRegenerate = $regenArray['regenerate']; $template = $regenArray['nf_templateID']; if ($toRegenerate) { // regenerate the same process starting at the next step // set the current process' complete status to 2.. 0 is active, 1 is done, 2 is has children $this->newprocess($template, $C[0], $processID); $this->archive_task($queueID, $statusToinsert); $newTaskid = DB_getItem($_TABLES['nf_queue'], 'id', "nf_processID='{$this->_nfProcessId}'"); if ($this->_debug) { COM_errorLog("Regenerate Task QueueID: {$toQueueID}"); } } else { // no regeneration we're done $this->archive_task($queueID); } // Add a new records to the queueFrom table for this matching queue record $sql = "INSERT INTO {$_TABLES['nf_queuefrom']} (queueID,fromQueueID) "; $sql .= "VALUES ({$retrieveQueryArray['id']},{$queueID})"; DB_query($sql); $this->archive_task($queueID, $statusToinsert); } //end else } //end else } //end for $nextstep } //end else portion for nextStepTest=0 } //end if($nextTaskRows) break; default: // all other task types that just should be processed $this->private_nfNextStep($queueID, $processID); break; } //end switch steptype } //end for $i=0 break; } //end switch $nrows }