function getLogicalChecksList($packageID) { $conditions = array('PackageCheck.package_id' => $packageID, 'PackageCheck.type' => CHECK_TYPE_LOGICAL); $this->unbindModel(array('belongsTo' => array('Package')), false); $this->belongsTo['Parentcheck']['fields'] = array('Parentcheck.condition', 'Parentcheck.id'); $logicalChecks = $this->generatetreelist($conditions, '{n}.PackageCheck.id', '{n}.PackageCheck.condition', '-', 0); foreach ($logicalChecks as $k => $v) { if (($logicalType = constValToLCSingle('check_condition_logical', $v)) == null) { $logicalType = "Unknown"; } $logicalChecks[$k] = str_replace($v, "", $logicalChecks[$k]); $logicalChecks[$k] .= "-Logical " . ucwords($logicalType); } $logicalChecks = array(0 => 'Root Node') + $logicalChecks; return $logicalChecks; }
function refExists($data) { $field = array_shift(array_keys($data)); $typeName = constValToLCSingle('VARIABLE_TYPE_', $this->data['Variable']['ref_type'], false, false, false); return $typeName != null && ClassRegistry::init(ucwords($typeName))->find('count', array('conditions' => array(ucwords($typeName) . '.id' => $data[$field]))) > 0; }
function edit($type = null, $id = null) { if ($type && (!ctype_alpha($type) && $id || ctype_alpha($type) && $id == null)) { $this->Session->setFlash('Invalid Internal Command.'); $this->redirect(array('action' => 'index')); } else { if ($type == null) { $this->Session->setFlash('Invalid id.'); $this->redirect(array('action' => 'index')); } else { if (ctype_digit($type) && $id == null) { $id = $type; $type = null; } $which = strtolower($type); if (!empty($this->data)) { $success = false; switch ($which) { case null: // saving a modified existing package $this->Package->id = $this->data['Package']['id'] = $id; $success = $this->Package->save($this->data); $pkgId = $id; $which = "package"; break; case "action": $this->data["PackageAction"]["id"] = $id; $success = $this->Package->PackageAction->save($this->data); $pkgId = $this->Package->PackageAction->field('package_id', array('PackageAction.id' => $id)); $which = "package action"; break; case "check": $this->Package->PackageCheck->id = $id; $prevParent = $this->Package->PackageCheck->field('parent_id'); $pkgId = $this->Package->PackageCheck->field('package_id'); $this->data['PackageCheck']['id'] = $id; if ($this->data['PackageCheck']['parent_id'] == 0) { $this->data['PackageCheck']['parent_id'] = null; } $success = $this->Package->PackageCheck->save($this->data); if ($success && $prevParent != $this->data['PackageCheck']['parent_id']) { $this->moveup("check", $id, 1); } $which = "package check"; break; case "exitcode": $this->Package->PackageAction->ExitCode->id = $id; $success = $this->Package->PackageAction->ExitCode->save($this->data); $pkgActId = $this->Package->PackageAction->ExitCode->field('package_action_id', array('ExitCode.id' => $id)); $url = array('action' => 'view', 'action', $pkgActId); $which = "exit code"; break; default: $this->Session->setFlash('An Error Occurred While Processing Your Input.'); $this->redirect(array('action' => 'index')); } if ($success) { $this->Session->setFlash('The ' . ucwords($which) . ' has been saved.'); if (!isset($url)) { $url = array('action' => 'view', $pkgId); } $this->redirect($url); } else { $this->Session->setFlash('The ' . ucwords($which) . ' could not be saved. Please, try again.'); } } switch ($which) { case null: // for packages // for packages case "package": $this->data = isset($success) ? $this->data : $this->Package->get($id, true); $this->set('packageDependencies', $this->Package->getAllBut($id)); break; case "action": case "package action": $this->data = isset($success) ? $this->data : $this->Package->PackageAction->get($id, true); $pkgId = isset($pkgId) ? $pkgId : $this->data['Package']['id']; $this->set('pkgName', $this->Package->field('name', array('Package.id' => $pkgId))); $this->set('pkgId', $pkgId); $this->set('pkgActId', $this->data['PackageAction']['id']); $this->autoRender = false; $this->render(null, "main", "action-edit"); break; case "check": case "package check": $this->data = isset($success) ? $this->data : $this->Package->PackageCheck->get($id); if (!isset($this->passedArgs['type'])) { $this->passedArgs['type'] = $this->data["PackageCheck"]["type"]; } $checkTypeCond = isset($this->passedArgs['cond']) ? $this->passedArgs['cond'] : $this->data["PackageCheck"]["condition"]; if (isset($this->passedArgs['type'])) { $strCheckType = constValToLCSingle('check_type', $this->passedArgs['type'], true); if ($strCheckType == null) { $strCheckType = "uninstall"; } // default check type if invalid one passed in } else { $strCheckType = "uninstall"; } // default check type if one wasn't passed in // The list of conditions to be shown in the condition combo box $checkCond = constsToWords('check_condition_' . $strCheckType); // The selected check type in the type combo box $checkType = constant('CHECK_TYPE_' . strtoupper($strCheckType)); // Bounds checking on the selected check condition $keys = array_keys($checkCond); if ($checkTypeCond < min($keys) || $checkTypeCond > max($keys)) { $checkTypeCond = min($keys); } // default check condition if invalid one passed in // A hierarchy of logical checks for this package id for the parent check combo box if ($this->passedArgs['type'] != CHECK_TYPE_LOGICAL || $this->data["PackageCheck"]["type"] != CHECK_TYPE_LOGICAL) { $logicalChecks = $this->Package->PackageCheck->getLogicalChecksList($this->data['Package']['id']); } $this->set('pkgName', $this->data['Package']['name']); $this->set('pkgId', $this->data['Package']['id']); $this->set('pkgChkId', $this->data['PackageCheck']['id']); $this->set(compact('checkType', 'checkTypeCond', 'checkCond', 'logicalChecks')); $this->autoRender = false; $this->render(null, "main", "check-edit"); break; case "exitcode": case "exit code": $this->data = isset($success) ? $this->data : $this->Package->PackageAction->ExitCode->get($id); $actType = ucwords(constValToLCSingle('action_type', $this->data['PackageAction']['type'])); $this->set('pkgActType', ucwords($actType)); $this->set('pkgActId', $this->data['ExitCode']['package_action_id']); $this->set('pkgActCmd', $this->data['PackageAction']['command']); $this->autoRender = false; $this->render(null, "main", "exitcode-edit"); break; default: $this->Session->setFlash('An Error Occurred While Processing Your Input.'); $this->redirect(array('action' => 'index')); } } } }
function delete($id = null) { if (!ctype_digit($id)) { $this->_showCritError('Invalid id for Variable'); } $var = $this->Variable->find('first', array('conditions' => array('Variable.id' => $id), 'fields' => array('Variable.ref_type', 'Variable.ref_id'))); if ($var && $this->Variable->del($id)) { $type = constValToLCSingle('VARIABLE_TYPE_', $var['Variable']['ref_type']); $recordId = $var['Variable']['ref_id']; if ($this->RequestHandler->isAjax()) { $this->set('variables', $this->Variable->getAllFor($type, $recordId)); $this->render('/elements/variables', 'plain'); } else { $this->Session->setFlash('Variable deleted'); $this->redirect(array('action' => 'view', $type, $recordId)); } } else { $this->_showCritError('Invalid id for Variable'); } }