*/ $query = "DELETE FROM `objective_organisation` WHERE `organisation_id` = " . $db->qstr($ORGANISATION_ID) . " AND `objective_id` = " . $db->qstr($objective["objective_id"]); if (!$db->Execute($query)) { application_log("Failed to remove entry from [objective_organisation], DB said: " . $db->ErrorMsg()); } /* * If $organisations has more than 1 entry the objective is active across multiple, and should not be deactivated in `global_lu_objectives` */ if (count($organisations) <= 1) { $query = "UPDATE `global_lu_objectives` SET `objective_active` = '0', `updated_date` = " . $db->qstr(time()) . ", `updated_by` = " . $db->qstr($ENTRADA_USER->getID()) . " WHERE `objective_id` = " . $db->qstr($objective["objective_id"]); if (!$db->Execute($query)) { application_log("Failed to update [global_lu_objectives], DB said: " . $db->ErrorMsg()); } } } deactivate_objective_children($OBJECTIVE_ID, $ORGANISATION_ID); echo json_encode(array("status" => "success")); } } else { echo json_encode(array("status" => "error")); } break; case 1: default: $query = "\tSELECT a.*, b.`organisation_id` FROM `global_lu_objectives` AS a\n\t\t\t\t\t\t\tLEFT JOIN `objective_organisation` AS b\n\t\t\t\t\t\t\tON a.`objective_id` = b.`objective_id`\n\t\t\t\t\t\t\tWHERE a.`objective_id` = " . $db->qstr($OBJECTIVE_ID) . "\n\t\t\t\t\t\t\tAND a.`objective_active` = '1'"; $objective = $db->GetRow($query); if ($objective) { ?> <div class="display-generic"> <p>You are about to delete the objective <strong><?php echo $objective["objective_name"];
function deactivate_objective_children($parent_id, $organisation_id, $i = 0) { if ($i > 99) { exit; } global $db, $ENTRADA_USER; $query = "\tSELECT a.*, GROUP_CONCAT(b.`organisation_id`) AS `organisations` FROM `global_lu_objectives` AS a\n\t\t\t\tJOIN `objective_organisation` AS b\n\t\t\t\tON a.`objective_id` = b.`objective_id`\n\t\t\t\tWHERE a.`objective_parent` = " . $db->qstr($parent_id) . "\n\t\t\t\tAND a.`objective_active` = '1'\n\t\t\t\tGROUP BY `objective_id`"; $objectives = $db->GetAll($query); if ($objectives) { $i = 0; foreach ($objectives as $objective) { $organisations = explode(",", $objective["organisations"]); /* * Remove the objective_organisation record. */ $query = "DELETE FROM `objective_organisation` WHERE `organisation_id` = " . $db->qstr($organisation_id) . " AND `objective_id` = " . $db->qstr($objective["objective_id"]); if (!$db->Execute($query)) { application_log("Failed to remove entry from [objective_organisation], DB said: " . $db->ErrorMsg()); echo $db->ErrorMsg(); } /* * If $organisations has more than 1 entry the objective is active across multiple, and should not be deactivated in `global_lu_objectives` */ if (count($organisations) <= 1) { $query = "UPDATE `global_lu_objectives` SET `objective_active` = '0', `updated_date` = " . $db->qstr(time()) . ", `updated_by` = " . $db->qstr($ENTRADA_USER->getID()) . " WHERE `objective_id` = " . $db->qstr($objective["objective_id"]); if ($db->Execute($query)) { deactivate_objective_children($objective["objective_id"], $organisation_id, $i); } } $i++; } return true; } else { return false; } }