From 2f09a7a94f5d101ae6569b3a34251135e8a5f875 Mon Sep 17 00:00:00 2001 From: nbm Date: Thu, 8 Dec 2005 14:02:19 +0000 Subject: [PATCH] Move administration pages into the core plugin. --- plugins/ktcore/admin/ajaxComplexConditionals.php | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/ajaxSimpleConditionals.php | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/archivedDocuments.php | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/conditions.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/deletedDocuments.php | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/documentCheckout.php | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/documentFields.php | 534 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/documentLinks.php | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/documentTypes.php | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/groupManagement.php | 390 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/manageCleanup.php | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/manageConditionals.php | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/manageLookupTrees.php | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/managePermissions.php | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/orgManagement.php | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/roleManagement.php | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/savedSearch.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/unitManagement.php | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/userManagement.php | 442 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/ktcore/admin/workflows.php | 492 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ presentation/lookAndFeel/knowledgeTree/administration/doccheckoutmanagement/documentCheckout.php | 128 -------------------------------------------------------------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxComplexConditionals.php | 196 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxSimpleConditionals.php | 141 --------------------------------------------------------------------------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/manageConditionals.php | 116 -------------------------------------------------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/documentFields.php | 534 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/manageLookupTrees.php | 246 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ presentation/lookAndFeel/knowledgeTree/administration/doclinkmanagement/documentLinks.php | 161 ----------------------------------------------------------------------------------------------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/doctypemanagement/documentTypes.php | 146 -------------------------------------------------------------------------------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/archivedDocuments.php | 101 ----------------------------------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/deletedDocuments.php | 108 ------------------------------------------------------------------------------------------------------------ presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageCleanup.php | 166 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/groupmanagement/groupManagement.php | 390 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ presentation/lookAndFeel/knowledgeTree/administration/orgmanagement/orgManagement.php | 73 ------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/permissions/managePermissions.php | 68 -------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/rolemanagement/roleManagement.php | 126 ------------------------------------------------------------------------------------------------------------------------------ presentation/lookAndFeel/knowledgeTree/administration/searches/conditions.php | 80 -------------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/searches/savedSearch.php | 74 -------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/unitmanagement/unitManagement.php | 79 ------------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/usermanagement/userManagement.php | 442 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/administration/workflow/workflows.php | 492 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 40 files changed, 3867 insertions(+), 3867 deletions(-) create mode 100755 plugins/ktcore/admin/ajaxComplexConditionals.php create mode 100755 plugins/ktcore/admin/ajaxSimpleConditionals.php create mode 100755 plugins/ktcore/admin/archivedDocuments.php create mode 100755 plugins/ktcore/admin/conditions.php create mode 100755 plugins/ktcore/admin/deletedDocuments.php create mode 100644 plugins/ktcore/admin/documentCheckout.php create mode 100755 plugins/ktcore/admin/documentFields.php create mode 100644 plugins/ktcore/admin/documentLinks.php create mode 100755 plugins/ktcore/admin/documentTypes.php create mode 100755 plugins/ktcore/admin/groupManagement.php create mode 100755 plugins/ktcore/admin/manageCleanup.php create mode 100755 plugins/ktcore/admin/manageConditionals.php create mode 100755 plugins/ktcore/admin/manageLookupTrees.php create mode 100755 plugins/ktcore/admin/managePermissions.php create mode 100755 plugins/ktcore/admin/orgManagement.php create mode 100644 plugins/ktcore/admin/roleManagement.php create mode 100755 plugins/ktcore/admin/savedSearch.php create mode 100755 plugins/ktcore/admin/unitManagement.php create mode 100755 plugins/ktcore/admin/userManagement.php create mode 100755 plugins/ktcore/admin/workflows.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/doccheckoutmanagement/documentCheckout.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxComplexConditionals.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxSimpleConditionals.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/manageConditionals.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/documentFields.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/manageLookupTrees.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/doclinkmanagement/documentLinks.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/doctypemanagement/documentTypes.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/archivedDocuments.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/deletedDocuments.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageCleanup.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/groupmanagement/groupManagement.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/orgmanagement/orgManagement.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/permissions/managePermissions.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/rolemanagement/roleManagement.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/searches/conditions.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/searches/savedSearch.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/unitmanagement/unitManagement.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/usermanagement/userManagement.php delete mode 100644 presentation/lookAndFeel/knowledgeTree/administration/workflow/workflows.php diff --git a/plugins/ktcore/admin/ajaxComplexConditionals.php b/plugins/ktcore/admin/ajaxComplexConditionals.php new file mode 100755 index 0000000..69404aa --- /dev/null +++ b/plugins/ktcore/admin/ajaxComplexConditionals.php @@ -0,0 +1,196 @@ +oValidator->validateFieldset(KTUtil::arrayGet($_REQUEST, 'fieldset_id')); + $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); + $oField =& $this->oValidator->validateField(KTUtil::arrayGet($_REQUEST, 'field_id')); + + header('Content-type: application/xml'); + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_get_item_list'); + + $aValues = array(); + foreach ($oField->getValues() as $oValue) { + if (empty($parent_behaviour)) { + $oInstance = KTValueInstance::getByLookupSingle($oValue); + if (empty($oInstance)) { + $aValues[$oValue->getId()] = $oValue->getName(); + } + // No parent behaviour (thus master column), so any + // instance will do to prevent showing this value + continue; + } + + $iInstanceId = KTValueInstance::getByLookupAndParentBehaviour($oValue, $parent_behaviour, array('ids' => true)); + if (empty($iInstanceId)) { + $aValues[$oValue->getId()] = $oValue->getName(); + } + } + $aData = array( + 'values' => $aValues, + ); + $oTemplate->setData($aData); + + return $oTemplate->render(); + } + + function do_getBehaviourList() { + $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour'); + $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); + $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); + + $aBehaviours =& KTFieldBehaviour::getByField($field_id); + + header('Content-type: application/xml'); + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_get_behaviour_list'); + $oTemplate->setData(array( + 'aBehaviours' => $aBehaviours, + )); + return $oTemplate->render(); + } + + function do_getActiveFields() { + $GLOBALS['default']->log->error(print_r($_REQUEST, true)); + $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour'); + // $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); // + $oFieldset =& $this->oValidator->validateFieldset(KTUtil::arrayGet($_REQUEST, 'fieldset_id')); + + if (empty($parent_behaviour)) { + $aFieldIds = array($oFieldset->getMasterFieldId()); + } else { + $oBehaviour =& $this->oValidator->validateBehaviour($parent_behaviour); + $iActiveFieldId = $oBehaviour->getFieldId(); + $aFieldIds = KTMetadataUtil::getChildFieldIds($iActiveFieldId); + } + + $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/conditional/ajax_complex_get_active_fields'); + $oTemplate->setData(array( + 'aFieldIds' => $aFieldIds, + )); + $GLOBALS['default']->log->error(print_r(KTMetadataUtil::getChildFieldIds($iActiveFieldId), true)); + + header('Content-type: application/xml'); + /// header('Content-type: text/plain'); + return $oTemplate->render(); + } + + /** storage methods */ + function do_createBehaviourAndAssign() { + $GLOBALS['default']->log->error(print_r($_REQUEST, true)); + $GLOBALS['default']->log->error(print_r($_SESSION, true)); + $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour'); + $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); + $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); + $behaviour_name = KTUtil::arrayGet($_REQUEST, 'behaviour_name'); + $lookups_to_assign = KTUtil::arrayGet($_REQUEST, 'lookups_to_assign'); // array + + $oBehaviour =& KTFieldBehaviour::createFromArray(array( + 'name' => $behaviour_name, + 'humanname' => $behaviour_name, + 'fieldid' => $field_id, + )); + + $aValueInstanceIds = array(); + foreach ($lookups_to_assign as $iLookupId) { + $res = $oValueInstance =& KTValueInstance::createFromArray(array( + 'fieldid' => $field_id, + 'behaviourid' => $oBehaviour->getId(), + 'fieldvalueid' => abs($iLookupId), + )); + $aValueInstanceIds[] = $res->getId(); + } + + if ($parent_behaviour) { + $oParentBehaviour =& $this->oValidator->validateBehaviour($parent_behaviour); + $sTable = KTUtil::getTableName('field_behaviour_options'); + $aOptions = array('noid' => true); + foreach ($aValueInstanceIds as $iId) { + $res = DBUtil::autoInsert($sTable, array( + 'behaviour_id' => $oParentBehaviour->getId(), + 'field_id' => $field_id, + 'instance_id' => $iId, + ), $aOptions); + } + } + + header('Content-type: application/xml'); + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_create_behaviour_and_assign'); + return $oTemplate->render(); + } + + function do_useBehaviourAndAssign() { + $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour'); + $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); + $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); + $behaviour_id = KTUtil::arrayGet($_REQUEST, 'behaviour_id'); + $lookups_to_assign = KTUtil::arrayGet($_REQUEST, 'lookups_to_assign'); // array + + $oBehaviour =& $this->oValidator->validateBehaviour($behaviour_id); + + $aValueInstanceIds = array(); + foreach ($lookups_to_assign as $iLookupId) { + $res = $oValueInstance =& KTValueInstance::createFromArray(array( + 'fieldid' => $field_id, + 'behaviourid' => $oBehaviour->getId(), + 'fieldvalueid' => abs($iLookupId), + )); + $aValueInstanceIds[] = $res->getId(); + } + + if ($parent_behaviour) { + $oParentBehaviour =& $this->oValidator->validateBehaviour($parent_behaviour); + $sTable = KTUtil::getTableName('field_behaviour_options'); + $aOptions = array('noid' => true); + foreach ($aValueInstanceIds as $iId) { + $res = DBUtil::autoInsert($sTable, array( + 'behaviour_id' => $oParentBehaviour->getId(), + 'field_id' => $field_id, + 'instance_id' => $iId, + ), $aOptions); + } + } + + header('Content-type: application/xml'); + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_use_behaviour_and_assign'); + return $oTemplate->render(); + } + + +} + +$oDispatcher = new AjaxConditionalAdminDispatcher(); +$oDispatcher->dispatch(); + +?> diff --git a/plugins/ktcore/admin/ajaxSimpleConditionals.php b/plugins/ktcore/admin/ajaxSimpleConditionals.php new file mode 100755 index 0000000..056354f --- /dev/null +++ b/plugins/ktcore/admin/ajaxSimpleConditionals.php @@ -0,0 +1,141 @@ +log->error(http_build_query($_REQUEST)); + $iFieldsetId = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); + $parent_field = KTUtil::arrayGet($_REQUEST, 'parent_field'); + $parent_lookup = KTUtil::arrayGet($_REQUEST, 'parent_lookup'); + $child_lookups = KTUtil::arrayGet($_REQUEST, 'child_lookups'); + + // child lookups is a nested array. in python it would be: + // child_lookups = + // { + // field_id:[lookup_id, lookup_id], + // field_id:[lookup_id, lookup_id], + // } + + $oFieldset =& KTFieldset::get($iFieldsetId); + $oFieldset->setIsComplete(false); + $oFieldset->update(); + + $oParentInstance = KTMetadataUtil::getOrCreateValueInstanceForLookup($parent_lookup); + $iBehaviourId = $oParentInstance->getBehaviourId(); + $oParentMetadata =& MetaData::get($oParentInstance->getFieldValueId()); + if (is_null($iBehaviourId)) { + $oBehaviour =& KTFieldBehaviour::createFromArray(array( + 'name' => 'autoinstance' . $oParentInstance->getId(), + 'humanname' => 'Auto instance' . $oParentMetadata->getName(), + 'fieldid' => $oParentInstance->getFieldId(), + )); + } else { + $oBehaviour =& KTFieldBehaviour::get($iBehaviourId); + } + if (PEAR::isError($oBehaviour)) { + var_dump($oBehaviour); + return $oBehaviour; + } + $iBehaviourId = $oBehaviour->getId(); + $oParentInstance->setBehaviourId($iBehaviourId); + $oParentInstance->update(); + + $sTable = KTUtil::getTableName('field_behaviour_options'); + $aOptions = array('noid' => true); + + $aQuery = array( + "DELETE FROM $sTable WHERE behaviour_id = ?", + array($iBehaviourId), + ); + $res = DBUtil::runQuery($aQuery); + + foreach ($child_lookups as $iFieldId => $aLookups) { + foreach ($aLookups as $iLookupId) { + $oValueInstance =& KTMetadataUtil::getOrCreateValueInstanceForLookup($iLookupId); + if (PEAR::isError($oValueInstance)) { + var_dump($oValueInstance); + return $oValueInstance; + } + $res = DBUtil::autoInsert($sTable, array( + 'behaviour_id' => $iBehaviourId, + 'field_id' => $iFieldId, + 'instance_id' => $oValueInstance->getId(), + ), $aOptions); + if (PEAR::isError($res)) { + var_dump($res); + return $res; + } + } + } + } + + // do you want the fieldset_id here? + function do_updateActiveFields() { + global $default; + $default->log->error(http_build_query($_REQUEST)); + $active_field = KTUtil::arrayGet($_REQUEST, 'active_field'); // field which is "active". + $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); + + // REMEMBER TO SET CONTENT-TYPE application/xml + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_simple_update_active_fields'); + $oTemplate->setData(array( + 'aFieldIds' => KTMetadataUtil::getChildFieldIds($active_field), + )); + header("Content-Type: application/xml"); + print $oTemplate->render(); + exit(0); + } + + // do you want the fieldset_id here? + function do_updateActiveLookups() { + global $default; + $default->log->error(http_build_query($_REQUEST)); + $active_field = KTUtil::arrayGet($_REQUEST, 'active_field'); // field which is "active". + $selected_lookup = KTUtil::arrayGet($_REQUEST, 'selected_lookup'); // selected value in said field. + + // REMEMBER TO SET CONTENT-TYPE application/xml + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_simple_update_active_lookups'); + + $aFieldLookups = KTMetadataUtil::getNextValuesForLookup($selected_lookup); + + $oTemplate->setData(array( + 'aFieldLookups' => $aFieldLookups, + )); + + header("Content-Type: application/xml"); + print $oTemplate->render(); + exit(0); + } + +} + +$oDispatcher = new AjaxConditionalAdminDispatcher(); +$oDispatcher->dispatch(); + +?> diff --git a/plugins/ktcore/admin/archivedDocuments.php b/plugins/ktcore/admin/archivedDocuments.php new file mode 100755 index 0000000..fc5ea90 --- /dev/null +++ b/plugins/ktcore/admin/archivedDocuments.php @@ -0,0 +1,101 @@ +aBreadcrumbs[] = array('action' => 'archivedDocuments', 'name' => _('Archived Documents')); + + $this->oPage->setBreadcrumbDetails(_('list')); + + $aDocuments =& Document::getList("status_id=" . ARCHIVED); + + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/archivedlist'); + $oTemplate->setData(array( + 'context' => $this, + 'documents' => $aDocuments, + )); + return $oTemplate; + } + + function do_confirm_restore() { + $this->aBreadcrumbs[] = array('action' => 'archivedDocuments', 'name' => _('Archived Documents')); + + $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); + + $this->oPage->setTitle(sprintf(_('Confirm Restore of %d documents'), count($selected_docs))); + + $this->oPage->setBreadcrumbDetails(sprintf(_('confirm restore of %d documents'), count($selected_docs))); + + $aDocuments = array(); + foreach ($selected_docs as $doc_id) { + $oDoc =& Document::get($doc_id); + if (PEAR::isError($oDoc) || ($oDoc === false)) { + $this->errorRedirectToMain(_('Invalid document id specified. Aborting restore.')); + } else if ($oDoc->getStatusId() != ARCHIVED) { + $this->errorRedirectToMain(sprintf(_('%s is not an archived document. Aborting restore.'), $oDoc->getName())); + } + $aDocuments[] = $oDoc; + } + + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/dearchiveconfirmlist'); + $oTemplate->setData(array( + 'context' => $this, + 'documents' => $aDocuments, + )); + return $oTemplate; + } + + function do_finish_restore() { + + + $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); + + $aDocuments = array(); + foreach ($selected_docs as $doc_id) { + $oDoc =& Document::get($doc_id); + if (PEAR::isError($oDoc) || ($oDoc === false)) { + $this->errorRedirectToMain(_('Invalid document id specified. Aborting restore.')); + } else if ($oDoc->getStatusId() != ARCHIVED) { + $this->errorRedirectToMain(sprintf(_('%s is not an archived document. Aborting restore.'), $oDoc->getName())); + } + $aDocuments[] = $oDoc; + } + + $this->startTransaction(); + + foreach ($aDocuments as $oDoc) { + // FIXME find de-archival source. + // FIXME purge old notifications. + // FIXME create de-archival notices to those who sent in old notifications. + $oDoc->setStatusId(LIVE); + $res = $oDoc->update(); + if (PEAR::isError($res) || ($res == false)) { + $this->errorRedirectToMain(sprintf(_('%s could not be made "live".'), $oDoc->getName)); + } + } + $this->commitTransaction(); + $msg = sprintf(_('%d documents made active.'), count($aDocuments)); + $this->successRedirectToMain($msg); + } +} + +//$d =& new DeletedDocumentsDispatcher; +//$d->dispatch(); + +?> diff --git a/plugins/ktcore/admin/conditions.php b/plugins/ktcore/admin/conditions.php new file mode 100755 index 0000000..12b0435 --- /dev/null +++ b/plugins/ktcore/admin/conditions.php @@ -0,0 +1,80 @@ +oValidator->validateTemplate('ktcore/search/administration/conditions'); + $oTemplate->setData(array( + 'conditions' => KTSavedSearch::getConditions(), + )); + return $oTemplate->render(); + } + + function do_new() { + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search"); + + $aCriteria = Criteria::getAllCriteria(); + + $aTemplateData = array( + "title" => _("Create a new condition"), + "sNameTitle" => _("Name of condition"), + "aCriteria" => $aCriteria, + "searchButton" => _("Save"), + ); + return $oTemplate->render($aTemplateData); + } + + function do_view() { + + } + + // XXX: Rename to do_save + function do_performSearch() { + $datavars = KTUtil::arrayGet($_REQUEST, 'boolean_search'); + if (!is_array($datavars)) { + $datavars = unserialize($datavars); + } + + if (empty($datavars)) { + $this->errorRedirectToMain(_('You need to have at least 1 condition.')); + } + + $sName = $_REQUEST['name']; + $sNamespace = KTUtil::nameToLocalNamespace('Saved searches', $sName); + + $oSearch = KTSavedSearch::createFromArray(array( + 'name' => $sName, + 'namespace' => $sNamespace, + 'iscondition' => true, + 'iscomplete' => true, + 'userid' => null, + 'search' => $datavars, + )); + + $this->oValidator->notError($oSearch, array( + 'redirect_to' => 'main', + 'message' => _('Search not saved'), + )); + $this->successRedirectToMain(_('Search saved')); + } +} + +$oDispatcher = new KTConditionDispatcher(); +$oDispatcher->dispatch(); + +?> diff --git a/plugins/ktcore/admin/deletedDocuments.php b/plugins/ktcore/admin/deletedDocuments.php new file mode 100755 index 0000000..5798d2e --- /dev/null +++ b/plugins/ktcore/admin/deletedDocuments.php @@ -0,0 +1,108 @@ +aBreadcrumbs[] = array('action' => 'deletedDocuments', 'name' => _('Deleted Documents')); + + $this->oPage->setBreadcrumbDetails(_('view')); + + $aDocuments =& Document::getList("status_id=" . DELETED); + + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/deletedlist'); + $oTemplate->setData(array( + 'context' => $this, + 'documents' => $aDocuments, + )); + return $oTemplate; + } + + function do_confirm_expunge() { + $this->aBreadcrumbs[] = array('action' => 'deletedDocuments', 'name' => _('Deleted Documents')); + + $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); + + $this->oPage->setTitle(sprintf(_('Confirm Expunge of %d documents'), count($selected_docs))); + + $this->oPage->setBreadcrumbDetails(sprintf(_('confirm expunge of %d documents'), count($selected_docs))); + + $aDocuments = array(); + foreach ($selected_docs as $doc_id) { + $oDoc =& Document::get($doc_id); + if (PEAR::isError($oDoc) || ($oDoc === false)) { + $this->errorRedirectToMain(_('Invalid document id specified. Aborting expunge')); + } else if ($oDoc->getStatusId() != DELETED) { + $this->errorRedirectToMain(sprintf(_('%s is not a deleted document. Aborting expunge'), $oDoc->getName())); + } + $aDocuments[] = $oDoc; + } + + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/expungeconfirmlist'); + $oTemplate->setData(array( + 'context' => $this, + 'documents' => $aDocuments, + )); + return $oTemplate; + } + + function do_finish_expunge() { + + + $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); + + $aDocuments = array(); + foreach ($selected_docs as $doc_id) { + $oDoc =& Document::get($doc_id); + if (PEAR::isError($oDoc) || ($oDoc === false)) { + $this->errorRedirectToMain(_('Invalid document id specified. Aborting expunge')); + } else if ($oDoc->getStatusId() != DELETED) { + $this->errorRedirectToMain(sprintf(_('%s is not a deleted document. Aborting expunge'), $oDoc->getName())); + } + $aDocuments[] = $oDoc; + } + + $this->startTransaction(); + $aErrorDocuments = array(); + $aSuccessDocuments = array(); + + foreach ($aDocuments as $oDoc) { + if (!PhysicalDocumentManager::expunge($oDoc)) { $aErrorDocuments[] = $oDoc->getDisplayPath(); } + else { + $oDocumentTransaction = & new DocumentTransaction($oDoc->getId(), "Document expunged", EXPUNGE); + $oDocumentTransaction->create(); + + // delete this from the db now + if (!$oDoc->delete()) { $aErrorDocuments[] = $oDoc->getId(); } + else { + // removed succesfully + $aSuccessDocuments[] = $oDoc->getDisplayPath(); + + // remove any document data + $oDoc->cleanupDocumentData($oDoc->getId()); // silly - why the redundancy? + } + } + } + $this->commitTransaction(); + $msg = sprintf(_('%d documents expunged.'), count($aSuccessDocuments)); + if (count($aErrorDocuments) != 0) { $msg .= _('Failed to expunge') . ': ' . join(', ', $aErrorDocuments); } + $this->successRedirectToMain($msg); + } +} + +//$d =& new DeletedDocumentsDispatcher; +//$d->dispatch(); + +?> diff --git a/plugins/ktcore/admin/documentCheckout.php b/plugins/ktcore/admin/documentCheckout.php new file mode 100644 index 0000000..d83b14b --- /dev/null +++ b/plugins/ktcore/admin/documentCheckout.php @@ -0,0 +1,128 @@ +, Jam Warehouse (Pty) Ltd, South Africa + * @package documentmanagement + */ + +/* boilerplate */ + + +require_once(KT_LIB_DIR . '/dispatcher.inc.php'); +require_once(KT_LIB_DIR . '/templating/kt3template.inc.php'); + + +class KTCheckoutAdminDispatcher extends KTAdminDispatcher { + + function check() { + return true; + } + + function do_main() { + $this->aBreadcrumbs[] = array('name' => _('Document Checkout')); + $this->oPage->setBreadcrumbDetails(_("list checked out documents")); + + $aDocuments = Document::getList("is_checked_out = 1"); + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/checkoutlisting'); + $oTemplate->setData(array( + "context" => $this, + "documents" => $aDocuments, + )); + return $oTemplate; + } + + + function do_confirm() { + $this->aBreadcrumbs[] = array('name' => _('Document Checkout')); + $this->oPage->setBreadcrumbDetails(_("confirm forced check-in")); + + $document_id = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); + if (empty($document_id)) { + return $this->errorRedirectToMain(_('You must select a document to check in first.')); + } + + $oDocument = Document::get($document_id); + if (PEAR::isError($oDocument)) { + return $this->errorRedirectToMain(_('The document you specified appears to be invalid.')); + } + + $oUser = User::get($oDocument->getCheckedOutUserID()); + // unusually, we could well have an error here: the user may have checked out and then + // been deleted. + if (PEAR::isError($oUser) || ($oUser === false)) { + $oUser = null; + } + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/force_checkin_confirm'); + $oTemplate->setData(array( + "context" => $this, + "document" => $oDocument, + "checkout_user" => $oUser, + )); + return $oTemplate; + + } + + function do_checkin() { + global $default; + + $document_id = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); + if (empty($document_id)) { + return $this->errorRedirectToMain(_('You must select a document to check in first.')); + } + + $oDocument = Document::get($document_id); + if (PEAR::isError($oDocument)) { + return $this->errorRedirectToMain(_('The document you specified appears to be invalid.')); + } + + $this->startTransaction(); + // actually do the checkin. + $oDocument->setIsCheckedOut(0); + $oDocument->setCheckedOutUserID(-1); + if (!$oDocument->update()) { + $this->rollbackTransaction(); + return $this->errorRedirectToMain(_("Failed to force the document's checkin.")); + } + + // checkout cancelled transaction + $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), "Document checked out cancelled", FORCE_CHECKIN); + if ($oDocumentTransaction->create()) { + $default->log->debug("editDocCheckoutBL.php created forced checkin document transaction for document ID=" . $oDocument->getID()); + } else { + $default->log->error("editDocCheckoutBL.php couldn't create create document transaction for document ID=" . $oDocument->getID()); + } + $this->commitTransaction(); // FIXME do we want to do this if we can't created the document-transaction? + return $this->successRedirectToMain(sprintf(_('Successfully forced "%s" to be checked in.'), $oDocument->getName())); + } + + +} + +// use the new admin framework. +//$d = new KTCheckoutAdminDispatcher(); +//$d->dispatch(); + +?> diff --git a/plugins/ktcore/admin/documentFields.php b/plugins/ktcore/admin/documentFields.php new file mode 100755 index 0000000..a0311bd --- /dev/null +++ b/plugins/ktcore/admin/documentFields.php @@ -0,0 +1,534 @@ +aBreadcrumbs[] = array('action' => 'docfield', 'name' => _('Document Field Management')); + $this->oPage->setBreadcrumbDetails(_("view fieldsets")); + + // function KTBaseWidget($sLabel, $sDescription, $sName, $value, $oPage, $bRequired = false, $sId = null, $aErrors = null, $aOptions = null) { + // use widgets for the create form. + $createFields = array(); + $createFields[] = new KTStringWidget('Name', _('A human-readable name, used in add and edit forms.'), 'name', null, $this->oPage, true); + $createFields[] = new KTCheckboxWidget('Generic', _('A generic fieldset is one that is available for every document by default. These fieldsets will be available for users to edit and add for every document in the document management system.'), 'generic', false, $this->oPage, false); + $createFields[] = new KTCheckboxWidget('System', + _('A system fieldset is one that is never displayed to a user, and is used only by the document management system.'), 'generic', false, $this->oPage, false); + + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/listFieldsets'); + $oTemplate->setData(array( + 'fieldsets' => KTFieldset::getList(), + 'creation_fields' => $createFields, + )); + return $oTemplate; + } + // }}} + + // {{{ do_edit + function do_edit() { + $this->oPage->setBreadcrumbDetails("edit"); + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/editFieldset'); + $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); + + $editFieldset = array(); + $editFieldset[] = new KTStringWidget('Name', _('A human-readable name, used in add and edit forms.'), 'name',$oFieldset->getName(), $this->oPage, true); + $editFieldset[] = new KTStringWidget('Namespace',_('Every fieldset needs to have a system name (used internally by the document management system). For fieldsets which you create, this is automatically created by the system, but for fieldsets created by plugins, this controls how the fieldset works.'), 'namespace', $oFieldset->getNamespace(), $this->oPage, true); + + $createFields = array(); + $createFields[] = new KTStringWidget('Name', _('A human-readable name, used in add and edit forms.'), 'name',null, $this->oPage, true); + + // type is a little more complex. + $vocab = array(); + if (!$oFieldset->getIsConditional()) { + $vocab["normal"] = 'Normal'; + } + $vocab['lookup'] = 'Lookup'; + $vocab['tree'] = 'Tree'; + $typeOptions = array("vocab" => $vocab); + $createFields[] =& new KTLookupWidget('Type',_('Different field types can have different properties.'), + 'type', null, $this->oPage, true, null, null, $typeOptions); + + + $this->aBreadcrumbs[] = array( + 'action' => 'docfield', + 'query' => 'action=edit&fFieldsetId=' . $_REQUEST['fFieldsetId'], + 'name' => 'Fieldset ' . $oFieldset->getName() + ); + $oTemplate->setData(array( + 'oFieldset' => $oFieldset, + 'edit_fieldset_fields' => $editFieldset, + 'create_field_fields' => $createFields, + )); + return $oTemplate; + } + // }}} + + // {{{ edit_object + function do_editobject() { + + $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); + $oFieldset->setName($_REQUEST['name']); + $oFieldset->setNamespace($_REQUEST['namespace']); + $res = $oFieldset->update(); + if (PEAR::isError($res) || ($res === false)) { + $this->errorRedirectTo('edit', _('Could not save fieldset changes'), 'fFieldsetId=' . $oFieldset->getId()); + exit(0); + } + $this->successRedirectTo('edit', _('Changes saved'), 'fFieldsetId=' . $oFieldset->getId()); + exit(0); + } + // }}} + + // {{{ do_new + function do_new() { + $bIsGeneric = false; + $bIsSystem = false; + + if (KTUtil::arrayGet($_REQUEST, 'generic')) { + $bIsGeneric = true; + } + + if (KTUtil::arrayGet($_REQUEST, 'system')) { + $bIsSystem = true; + // Can't be a system fieldset and a generic fieldset... + $bIsGeneric = false; + } + $sName = KTUtil::arrayGet($_REQUEST, 'name'); + $sName = $this->oValidator->notEmpty($sName); + $sNamespace = KTUtil::arrayGet($_REQUEST, 'namespace'); + if (empty($sNamespace)) { + $sNamespace = KTUtil::nameToLocalNamespace('fieldsets', $sName); + } + $res = KTFieldset::createFromArray(array( + 'name' => $sName, + 'namespace' => $sNamespace, + 'mandatory' => false, + 'isconditional' => false, + 'isgeneric' => $bIsGeneric, + 'issystem' => $bIsSystem, + )); + if (PEAR::isError($res) || ($res === false)) { + $this->errorRedirectToMain('Could not create fieldset'); + exit(0); + } + $this->successRedirectTo('edit', _('Fieldset created') . ': '.$sName, 'fFieldsetId=' . $res->getId()); + exit(0); + } + // }}} + + // {{{ do_newfield + function do_newfield() { + $is_lookup = false; + $is_tree = false; + if ($_REQUEST['type'] === "lookup") { + $is_lookup = true; + } + if ($_REQUEST['type'] === "tree") { + $is_lookup = true; + $is_tree = true; + } + $oFieldset = KTFieldset::get($_REQUEST['fFieldsetId']); + $oField =& DocumentField::createFromArray(array( + 'name' => $_REQUEST['name'], + 'datatype' => 'STRING', + 'haslookup' => $is_lookup, + 'haslookuptree' => $is_tree, + 'parentfieldset' => $oFieldset->getId(), + )); + if (PEAR::isError($res) || ($res === false)) { + $this->errorRedirectTo('edit', _('Could not create field') . ': '.$_REQUEST['name'], 'fFieldsetId=' . $oFieldset->getId()); + exit(0); + } + if ($is_lookup) { + $this->successRedirectTo('editField', _('Field created') . ': '.$_REQUEST['name'], 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); + } else { + $this->successRedirectTo('edit', _('Field created') . ': ' . $_REQUEST['name'], 'fFieldsetId=' . $oFieldset->getId()); + } + exit(0); + } + // }}} + + // {{{ do_editField + function do_editField() { + $this->oPage->setBreadcrumbDetails(_("edit field")); + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/editField'); + $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); + $oField =& DocumentField::get($_REQUEST['fFieldId']); + + $this->aBreadcrumbs[] = array( + 'action' => 'docfield', + 'query' => 'action=edit&fFieldsetId=' . $_REQUEST['fFieldsetId'], + 'name' => $oFieldset->getName() + ); + $this->aBreadcrumbs[] = array( + 'name' => $oField->getName() + ); + $this->oPage->setBreadcrumbDetails(_('edit field')); + + $oTemplate->setData(array( + 'oFieldset' => $oFieldset, + 'oField' => $oField, + )); + return $oTemplate; + } + // }}} + + // {{{ do_editFieldObject + function do_editFieldObject() { + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/editField'); + $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); + $oField =& DocumentField::get($_REQUEST['fFieldId']); + + $oField->setName($_REQUEST['name']); + $res = $oField->update(); + if (PEAR::isError($res) || ($res === false)) { + $this->errorRedirectTo('editField', _('Could not save field changes'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); + exit(0); + } + $this->successRedirectTo('editField', _('Changes saved'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); + exit(0); + } + // }}} + + // {{{ do_addLookups + function do_addLookups() { + $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); + $oField =& DocumentField::get($_REQUEST['fFieldId']); + if (empty($_REQUEST['value'])) { + $this->errorRedirectTo('editField', _('Empty lookup not added'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); + } + $oMetaData =& MetaData::createFromArray(array( + 'name' => $_REQUEST['value'], + 'docfieldid' => $oField->getId(), + )); + $this->successRedirectTo('editField', _('Lookup added'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); + exit(0); + } + // }}} + + // {{{ do_metadataMultiAction + function do_metadataMultiAction() { + $subaction = array_keys(KTUtil::arrayGet($_REQUEST, 'submit', array())); + $this->oValidator->notEmpty($subaction, array("message" => _("No action specified"))); + $subaction = $subaction[0]; + $method = null; + if (method_exists($this, 'lookup_' . $subaction)) { + $method = 'lookup_' . $subaction; + } + $this->oValidator->notEmpty($method, array("message" => _("Unknown action specified"))); + return $this->$method(); + } + // }}} + + // {{{ lookup_remove + function lookup_remove() { + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); + $oField =& DocumentField::get($_REQUEST['fFieldId']); + $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata'); + if (empty($aMetadata)) { + $this->errorRedirectTo('editField', _('No lookups selected'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); + } + foreach ($_REQUEST['metadata'] as $iMetaDataId) { + $oMetaData =& MetaData::get($iMetaDataId); + $oMetaData->delete(); + } + $this->successRedirectTo('editField', _('Lookups removed'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); + exit(0); + } + // }}} + + // {{{ lookup_disable + function lookup_disable() { + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); + $oField =& DocumentField::get($_REQUEST['fFieldId']); + $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata'); + if (empty($aMetadata)) { + $this->errorRedirectTo('editField', _('No lookups selected'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); + } + foreach ($_REQUEST['metadata'] as $iMetaDataId) { + $oMetaData =& MetaData::get($iMetaDataId); + $oMetaData->setDisabled(true); + $oMetaData->update(); + } + $this->successRedirectTo('editField', _('Lookups disabled'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); + exit(0); + } + // }}} + + // {{{ lookup_enable + function lookup_enable() { + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); + $oField =& DocumentField::get($_REQUEST['fFieldId']); + $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata'); + if (empty($aMetadata)) { + $this->errorRedirectTo('editField', _('No lookups selected'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); + } + foreach ($_REQUEST['metadata'] as $iMetaDataId) { + $oMetaData =& MetaData::get($iMetaDataId); + $oMetaData->setDisabled(false); + $oMetaData->update(); + } + $this->successRedirectTo('editField', _('Lookups enabled'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); + exit(0); + } + // }}} + + // {{{ lookup_togglestickiness + function lookup_togglestickiness() { + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); + $oField =& DocumentField::get($_REQUEST['fFieldId']); + $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata'); + if (empty($aMetadata)) { + $this->errorRedirectTo('editField', _('No lookups selected'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); + } + foreach ($_REQUEST['metadata'] as $iMetaDataId) { + $oMetaData =& MetaData::get($iMetaDataId); + $bStuck = (boolean)$oMetaData->getIsStuck(); + $oMetaData->setIsStuck(!$bStuck); + $oMetaData->update(); + } + $this->successRedirectTo('editField', _('Lookup stickiness toggled'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); + exit(0); + } + // }}} + + // {{{ do_becomeconditional + function do_becomeconditional() { + $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); + $oFieldset->setIsConditional(true); + $oFieldset->setIsComplete(false); + $res = $oFieldset->update(); + if (PEAR::isError($res) || ($res === false)) { + $this->errorRedirectTo('edit', _('Could not become conditional'), 'fFieldsetId=' . $oFieldset->getId()); + exit(0); + } + $this->successRedirectTo('edit', _('Became conditional'), 'fFieldsetId=' . $oFieldset->getId()); + exit(0); + } + // }}} + + // {{{ do_removeconditional + function do_removeconditional() { + $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); + $oFieldset->setIsConditional(false); + $oFieldset->setIsComplete(true); + $res = $oFieldset->update(); + if (PEAR::isError($res) || ($res === false)) { + $this->errorRedirectTo('edit', _('Could not stop being conditional'), 'fFieldsetId=' . $oFieldset->getId()); + exit(0); + } + $this->successRedirectTo('edit', _('Became no longer conditional'), 'fFieldsetId=' . $oFieldset->getId()); + exit(0); + } + // }}} + + // {{{ do_removeFields + function do_removeFields() { + $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); + foreach ($_REQUEST['fields'] as $iFieldId) { + $oField =& DocumentField::get($iFieldId); + $oField->delete(); + } + $this->successRedirectTo('edit', _('Fields removed'), 'fFieldsetId=' . $oFieldset->getId()); + exit(0); + } + // }}} + + // {{{ do_manageConditional + function do_manageConditional () { + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/manageConditional'); + $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); + $iMasterFieldId = $oFieldset->getMasterFieldId(); + if (!empty($iMasterFieldId)) { + $oMasterField =& DocumentField::get($iMasterFieldId); + if (PEAR::isError($oMasterField)) { + $oMasterField = null; + } + } else { + $oMasterField = null; + } + $sTable = KTUtil::getTableName('field_orders'); + $aQuery = array( + "SELECT parent_field_id, child_field_id FROM $sTable WHERE fieldset_id = ?", + array($oFieldset->getId()) + ); + $aFieldOrders = DBUtil::getResultArray($aQuery); + $aFields = $oFieldset->getFields(); + + $aFreeFieldIds = array(); + foreach ($aFields as $oField) { + $aFreeFieldIds[] = $oField->getId(); + } + if ($oMasterField) { + $aParentFieldIds = array($oMasterField->getId()); + foreach ($aFieldOrders as $aRow) { + $aParentFieldIds[] = $aRow['child_field_id']; + } + $aParentFields = array(); + foreach (array_unique($aParentFieldIds) as $iId) { + $aParentFields[] =& DocumentField::get($iId); + } + $aFreeFields = array(); + foreach ($aFreeFieldIds as $iId) { + if (in_array($iId, $aParentFieldIds)) { + continue; + } + $aFreeFields[] =& DocumentField::get($iId); + } + } + $res = KTMetadataUtil::checkConditionalFieldsetCompleteness($oFieldset); + if (PEAR::isError($res)) { + $sIncomplete = $res->getMessage(); + } else { + $sIncomplete = null; + } + $this->aBreadcrumbs[] = array( + 'action' => 'docfield', + 'query' => 'action=edit&fFieldsetId=' . $_REQUEST['fFieldsetId'], + 'name' => $oFieldset->getName() + ); + $this->aBreadcrumbs[] = array( + 'action' => 'docfield', + 'query' => 'action=manageConditional&fFieldsetId=' . $_REQUEST['fFieldsetId'], + 'name' => _('Manage conditional field'), + ); + $oTemplate->setData(array( + 'oFieldset' => $oFieldset, + 'free_fields' => $aFreeFields, + 'parent_fields' => $aParentFields, + 'aFieldOrders' => $aFieldOrders, + 'oMasterField' => $oMasterField, + 'sIncomplete' => $sIncomplete, + )); + return $oTemplate; + } + // }}} + + // {{{ do_orderFields + function do_orderFields() { + $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); + $aFreeFieldIds = $_REQUEST['fFreeFieldIds']; + if (empty($aFreeFieldIds)) { + $this->errorRedirectTo('manageConditional', 'No children fields selected', 'fFieldsetId=' . $oFieldset->getId()); + } + $iParentFieldId = $_REQUEST['fParentFieldId']; + if (in_array($aParentFieldId, $aFreeFieldIds)) { + $this->errorRedirectTo('manageConditional', _('Field cannot be its own parent field'), 'fFieldsetId=' . $oFieldset->getId()); + } + foreach ($aFreeFieldIds as $iChildFieldId) { + $res = KTMetadataUtil::addFieldOrder($iParentFieldId, $iChildFieldId, $oFieldset); + $this->oValidator->notError($res, array( + 'redirect_to' => array('manageConditional', 'fFieldsetId=' . $oFieldset->getId()), + 'message' => _('Error adding Fields'), + )); + } + $this->successRedirectTo('manageConditional', _('Fields ordered'), 'fFieldsetId=' . $oFieldset->getId()); + exit(0); + } + // }}} + + // {{{ do_setMasterField + function do_setMasterField() { + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); + $oField =& $this->oValidator->validateField($_REQUEST['fFieldId']); + + $res = KTMetadataUtil::removeFieldOrdering($oFieldset); + $oFieldset->setMasterFieldId($oField->getId()); + $res = $oFieldset->update(); + + $this->oValidator->notError($res, array( + 'redirect_to' => array('manageConditional', 'fFieldsetId=' . $oFieldset->getId()), + 'message' => _('Error setting master field'), + )); + $this->successRedirectTo('manageConditional', _('Master field set'), 'fFieldsetId=' . $oFieldset->getId()); + exit(0); + } + // }}} + + // {{{ do_checkComplete + /** + * Checks whether the fieldset is complete, and if it is, sets it to + * be complete in the database. Otherwise, set it to not be + * complete in the database (just in case), and set the error + * messages as to why it isn't. + */ + function do_checkComplete() { + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); + $res = KTMetadataUtil::checkConditionalFieldsetCompleteness($oFieldset); + if ($res === true) { + $oFieldset->setIsComplete(true); + $oFieldset->update(); + $this->successRedirectTo('manageConditional', _('Set to complete'), 'fFieldsetId=' . $oFieldset->getId()); + } + $oFieldset->setIsComplete(false); + $oFieldset->update(); + // Success, as we want to save the incompleteness to the + // database... + $this->successRedirectTo('manageConditional', _('Could not to complete'), 'fFieldsetId=' . $oFieldset->getId()); + } + // }}} + + // {{{ do_changeToSimple + function do_changeToSimple() { + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); + $oFieldset->setIsComplex(false); + $res = $oFieldset->update(); + $this->oValidator->notError($res, array( + 'redirect_to' => array('manageConditional', 'fFieldsetId=' . $oFieldset->getId()), + 'message' => _('Error changing to simple'), + )); + $this->successRedirectTo('manageConditional', _('Changed to simple'), 'fFieldsetId=' . $oFieldset->getId()); + } + // }}} + + // {{{ do_changeToComplex + function do_changeToComplex() { + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); + $oFieldset->setIsComplex(true); + $res = $oFieldset->update(); + $this->oValidator->notError($res, array( + 'redirect_to' => array('manageConditional', 'fFieldsetId=' . $oFieldset->getId()), + 'message' => _('Error changing to complex'), + )); + $this->successRedirectTo('manageConditional', _('Changed to complex'), 'fFieldsetId=' . $oFieldset->getId()); + } + // }}} + + // {{{ do_delete + function do_delete() { + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); + $res = $oFieldset->delete(); + $this->oValidator->notErrorFalse($res, array( + 'redirect_to' => array('main', ''), + 'message' => _('Could not delete fieldset'), + )); + $this->successRedirectToMain(_('Fieldset deleted')); + } + // }}} +} + +// use the admin dispatch mechanisms. +//$d =& new KTDocumentFieldDispatcher; +//$d->dispatch(); + +?> diff --git a/plugins/ktcore/admin/documentLinks.php b/plugins/ktcore/admin/documentLinks.php new file mode 100644 index 0000000..7a4152d --- /dev/null +++ b/plugins/ktcore/admin/documentLinks.php @@ -0,0 +1,161 @@ +, Jam Warehouse (Pty) Ltd, South Africa + * @package documentmanagement + */ + +/* boilerplate */ +//require_once('../../../../../config/dmsDefaults.php'); + +require_once(KT_LIB_DIR . '/dispatcher.inc.php'); +require_once(KT_LIB_DIR . '/templating/kt3template.inc.php'); + +require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php'); + +require_once(KT_LIB_DIR . '/documentmanagement/LinkType.inc'); // a horrible piece of work. + +class KTDocLinkAdminDispatcher extends KTAdminDispatcher { + + // Breadcrumbs base - added to in methods + function check() { + return true; + } + + function do_main() { + $this->aBreadcrumbs[] = array('name' => _('Document Links')); + $this->oPage->setBreadcrumbDetails(_("view")); + + $aLinkTypes =& LinkType::getList('id > 0'); + + $addLinkForm = array(); + // KTBaseWidget($sLabel, $sDescription, $sName, $value, $oPage, $bRequired = false, $sId = null, $aErrors = null, $aOptions = null) + $addLinkForm[] = new KTStringWidget('Name',_('A short, human-readable name for the link type.'), 'fName', null, $this->oPage, true); + $addLinkForm[] = new KTStringWidget('Description',_('A short brief description of the relationship implied by this link type.'), 'fDescription', null, $this->oPage, true); + + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/linktypesadmin'); + $oTemplate->setData(array( + "context" => $this, + "add_form" => $addLinkForm, + "links" => $aLinkTypes, + )); + return $oTemplate; + } + + function do_edit() { + $link_id = KTUtil::arrayGet($_REQUEST, 'fLinkTypeId', null, false); + if ($link_id === null) { + $this->errorRedirectToMain(_("Please specify a link type to edit.")); + } + + $oLinkType =& LinkType::get($link_id); + + $this->aBreadcrumbs[] = array('name' => _('Document Links')); + $this->oPage->setBreadcrumbDetails(_("view")); + + $aLinkTypes =& LinkType::getList('id > 0'); + + $editLinkForm = array(); + // KTBaseWidget($sLabel, $sDescription, $sName, $value, $oPage, $bRequired = false, $sId = null, $aErrors = null, $aOptions = null) + $editLinkForm[] = new KTStringWidget('Name',_('A short, human-readable name for the link type.'), 'fName', $oLinkType->getName(), $this->oPage, true); + $editLinkForm[] = new KTStringWidget('Description',_('A short brief description of the relationship implied by this link type.'), 'fDescription', $oLinkType->getDescription(), $this->oPage, true); + + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/linktypesadmin'); + $oTemplate->setData(array( + "context" => $this, + "edit_form" => $editLinkForm, + "old_link" => $oLinkType, + "links" => $aLinkTypes, + )); + return $oTemplate; + } + + + function do_update() { + $link_id = KTUtil::arrayGet($_REQUEST, 'fLinkTypeId', null, false); + if ($link_id === null) { + $this->errorRedirectToMain(_("Please specify a link type to update.")); + } + + $name = KTUtil::arrayGet($_REQUEST, 'fName'); + $description = KTUtil::arrayGet($_REQUEST, 'fDescription'); + + if (empty($name) || empty($description)) { // for bonus points, make this go to edit, and edit catch it. + $this->errorRedirectToMain(_('Please enter information for all fields.')); + } + + $oLinkType =& LinkType::get($link_id); + + $oLinkType->setName($name); + $oLinkType->setDescription($description); + $oLinkType->update(); + + $this->successRedirectToMain(_("Link Type updated.")); + } + + function do_add() { + $name = KTUtil::arrayGet($_REQUEST, 'fName'); + $description = KTUtil::arrayGet($_REQUEST, 'fDescription'); + + if (empty($name) || empty($description)) { + $this->errorRedirectToMain(_('Please enter information for all fields.')); + } + + $oLinkType = new LinkType($name, $description); + $oLinkType->create(); + + //$oLinkType =& LinkType::createFromArray(array("sName" => $name, "sDescription" => $description)); + + $this->successRedirectToMain(_("Link Type created.")); + } + + function do_delete() { + $types_to_delete = KTUtil::arrayGet($_REQUEST, 'fLinksToDelete'); // is an array. + + if (empty($types_to_delete)) { + $this->errorRedirectToMain(_('Please select one or more link types to delete.')); + } + + $count = 0; + foreach ($types_to_delete as $link_id) { + $oLinkType = LinkType::get($link_id); + $oLinkType->delete(); // technically, this is a bad thing + $count += 1; + } + + //$oLinkType =& LinkType::createFromArray(array("sName" => $name, "sDescription" => $description)); + + $this->successRedirectToMain($count . " " . _("Link types deleted.")); + } + + +} + +// use the new admin framework. +//$d = new KTDocLinkAdminDispatcher(); +//$d->dispatch(); + +?> diff --git a/plugins/ktcore/admin/documentTypes.php b/plugins/ktcore/admin/documentTypes.php new file mode 100755 index 0000000..e415336 --- /dev/null +++ b/plugins/ktcore/admin/documentTypes.php @@ -0,0 +1,146 @@ +aBreadcrumbs[] = array('action' => 'doctype', 'name' => _('Document Type Management')); + + $this->oPage->setBreadcrumbDetails('view types'); + + $addFields = array(); + $addFields[] = new KTStringWidget(_('Name'),_('A short, human-readable name for the document type.'), 'name', null, $this->oPage, true); + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate('ktcore/documenttypes/list'); + $oTemplate->setData(array( + 'document_types' => DocumentType::getList(), + 'add_fields' => $addFields, + )); + return $oTemplate; + } + + function do_new() { + + + + $sName = $_REQUEST['name']; + $oDocumentType =& DocumentType::createFromArray(array( + 'name' => $sName, + )); + if (PEAR::isError($oDocumentType)) { + $this->errorRedirectToMain(_('Could not create document type')); + exit(0); + } + $this->successRedirectTo('edit', _('Document type created'), 'fDocumentTypeId=' . $oDocumentType->getId()); + exit(0); + } + + function do_delete() { + $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']); + if ($oDocumentType->isUsed()) { + $this->errorRedirectToMain(_('Document type still in use, could not be deleted')); + exit(0); + } + $res = $oDocumentType->delete(); + if (PEAR::isError($res) || ($res === false)) { + $this->errorRedirectToMain(_('Document type could not be deleted')); + exit(0); + } + + $this->successRedirectToMain(_('Document type deleted')); + exit(0); + } + + function do_edit() { + + $this->aBreadcrumbs[] = array('action' => 'doctype', 'name' => _('Document Type Management')); + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate('ktcore/documenttypes/edit'); + $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']); + + + $aCurrentFieldsets =& KTFieldset::getForDocumentType($oDocumentType); + $aAvailableFieldsets =& KTFieldset::getNonGenericFieldsets(); + $aAvailableFieldsets = array_diff($aAvailableFieldsets, $aCurrentFieldsets); + + + $vocab = array(); + foreach ($aAvailableFieldsets as $oFieldset) { + $vocab[$oFieldset->getId()] = $oFieldset->getName(); + } + $aOptions = array(); + $aOptions['vocab'] = $vocab; + $aOptions['multi'] = true; + $aOptions['size'] = 5; + $availableTypesWidget =& new KTLookupWidget(_('Available Fieldsets'),_('Select the fieldsets which you wish to associate with this document type'), 'fieldsetid', null, $this->oPage, true, + null, null, $aOptions); + + $this->aBreadcrumbs[] = array( + 'name' => $oDocumentType->getName(), + ); + $this->oPage->setBreadcrumbDetails(_('edit')); + + $oTemplate->setData(array( + 'oDocumentType' => $oDocumentType, + 'aCurrentFieldsets' => $aCurrentFieldsets, + 'aAvailableFieldsets' => $aAvailableFieldsets, + 'availableWidget' => $availableTypesWidget, + )); + return $oTemplate; + } + + function do_editobject() { + $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']); + $oDocumentType->setName($_REQUEST['name']); + $res = $oDocumentType->update(); + if (PEAR::isError($res) || ($res === false)) { + $this->errorRedirectTo('edit', _('Could not save document type changes'), 'fDocumentTypeId=' . $oDocumentType->getId()); + exit(0); + } + $this->successRedirectTo('edit', _('Name changed.'), 'fDocumentTypeId=' . $oDocumentType->getId()); + exit(0); + } + + function do_removefieldsets() { + $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']); + $res = KTMetadataUtil::removeSetsFromDocumentType($oDocumentType, $_REQUEST['fieldsetid']); + if (PEAR::isError($res)) { + var_dump($res); + $this->errorRedirectTo('edit', _('Changes not saved'), 'fDocumentTypeId=' . $oDocumentType->getId()); + exit(0); + } + $this->successRedirectTo('edit', _('Fieldsets removed.'), 'fDocumentTypeId=' . $oDocumentType->getId()); + exit(0); + } + + function do_addfieldsets() { + $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']); + $res = KTMetadataUtil::addSetsToDocumentType($oDocumentType, $_REQUEST['fieldsetid']); + if (PEAR::isError($res)) { + var_dump($res); + $this->errorRedirectTo('edit', _('Changes not saved'), 'fDocumentTypeId=' . $oDocumentType->getId()); + exit(0); + } + $this->successRedirectTo('edit', _('Fieldsets associated.'), 'fDocumentTypeId=' . $oDocumentType->getId()); + exit(0); + } +} + +//$d =& new KTDocumentTypeDispatcher; +//$d->dispatch(); + +?> diff --git a/plugins/ktcore/admin/groupManagement.php b/plugins/ktcore/admin/groupManagement.php new file mode 100755 index 0000000..3167d2e --- /dev/null +++ b/plugins/ktcore/admin/groupManagement.php @@ -0,0 +1,390 @@ +aBreadcrumbs[] = array('action' => 'groupManagement', 'name' => _('Group Management')); + $this->oPage->setBreadcrumbDetails(_('select a group')); + $this->oPage->setTitle(_("Group Management")); + + + $name = KTUtil::arrayGet($_REQUEST, 'name'); + $show_all = KTUtil::arrayGet($_REQUEST, 'show_all', false); + $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); + + + $search_fields = array(); + $search_fields[] = new KTStringWidget(_('Group Name'),_("Enter part of the group's name. e.g. ad will match administrators."), 'name', $name, $this->oPage, true); + + if (!empty($name)) { + $search_results =& Group::getList('WHERE name LIKE "%' . DBUtil::escapeSimple($name) . '%"'); + } else if ($show_all !== false) { + $search_results =& Group::getList(); + } + + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/groupadmin"); + $aTemplateData = array( + "context" => $this, + "search_fields" => $search_fields, + "search_results" => $search_results, + ); + return $oTemplate->render($aTemplateData); + } + + + + function do_editGroup() { + $this->aBreadcrumbs[] = array('action' => 'groupManagement', 'name' => _('Group Management')); + $this->oPage->setBreadcrumbDetails(_('edit group')); + + $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); + $oGroup = Group::get($group_id); + if (PEAR::isError($oGroup) || $oGroup == false) { + $this->errorRedirectToMain(_('Please select a valid group.')); + } + + $this->oPage->setTitle(sprintf(_("Edit Group (%s)"), $oGroup->getName())); + + $edit_fields = array(); + $edit_fields[] = new KTStringWidget(_('Group Name'),_('A short name for the group. e.g. administrators.'), 'group_name', $oGroup->getName(), $this->oPage, true); + $edit_fields[] = new KTCheckboxWidget(_('Unit Administrators'),_('Should all the members of this group be given unit administration privilidges?'), 'is_unitadmin', $oGroup->getUnitAdmin(), $this->oPage, false); + $edit_fields[] = new KTCheckboxWidget(_('System Administrators'),_('Should all the members of this group be given system administration privilidges?'), 'is_sysadmin', $oGroup->getSysAdmin(), $this->oPage, false); + + // grab all units. + $unit = $oGroup->getUnit(); + if ($unit == null) { $unitId = 0; } + else { $unitId = $unit->getID(); } + + + $oUnits = Unit::getList(); + $vocab = array(); + $vocab[0] = _('No Unit'); + foreach ($oUnits as $oUnit) { $vocab[$oUnit->getID()] = $oUnit->getName(); } + $aOptions = array('vocab' => $vocab); + + $edit_fields[] = new KTLookupWidget(_('Unit'),_('Which Unit is this group part of?'), 'unit_id', $unitId, $this->oPage, false, null, null, $aOptions); + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/editgroup"); + $aTemplateData = array( + "context" => $this, + "edit_fields" => $edit_fields, + "edit_group" => $oGroup, + ); + return $oTemplate->render($aTemplateData); + } + + function do_saveGroup() { + $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); + $oGroup = Group::get($group_id); + if (PEAR::isError($oGroup) || $oGroup == false) { + $this->errorRedirectToMain(_('Please select a valid group.')); + } + $group_name = KTUtil::arrayGet($_REQUEST, 'group_name'); + if (empty($group_name)) { $this->errorRedirectToMain(_('Please specify a name for the group.')); } + $is_unitadmin = KTUtil::arrayGet($_REQUEST, 'is_unitadmin', false); + if ($is_unitadmin !== false) { $is_unitadmin = true; } + $is_sysadmin = KTUtil::arrayGet($_REQUEST, 'is_sysadmin', false); + if ($is_sysadmin !== false) { $is_sysadmin = true; } + + $this->startTransaction(); + + $oGroup->setName($group_name); + $oGroup->setUnitAdmin($is_unitadmin); + $oGroup->setSysAdmin($is_sysadmin); + + $unit_id = KTUtil::arrayGet($_REQUEST, 'unit_id', 0); + if ($unit_id == 0) { // not set, or set to 0. + $oGroup->clearUnit(); // safe. + } else { + $oGroup->setUnit($unit_id); + } + + $res = $oGroup->update(); + if (($res == false) || (PEAR::isError($res))) { return $this->errorRedirectToMain(_('Failed to set group details.')); } + + $this->commitTransaction(); + $this->successRedirectToMain(_('Group details updated.')); + } + + + function do_manageusers() { + $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); + $oGroup = Group::get($group_id); + if ((PEAR::isError($oGroup)) || ($oGroup === false)) { + $this->errorRedirectToMain(_('No such group.')); + } + + $this->aBreadcrumbs[] = array('name' => $oGroup->getName()); + $this->oPage->setBreadcrumbDetails(_('manage members')); + $this->oPage->setTitle(sprintf(_('Manage members of group %s'), $oGroup->getName())); + + + // FIXME replace OptionTransfer.js. me no-likey. + + // FIXME this is hideous. refactor the transfer list stuff completely. + $initJS = 'var optGroup = new OptionTransfer("userSelect","chosenUsers"); ' . + 'function startTrans() { var f = getElement("usergroupform"); ' . + ' optGroup.saveAddedRightOptions("userAdded"); ' . + ' optGroup.saveRemovedRightOptions("userRemoved"); ' . + ' optGroup.init(f); }; ' . + ' addLoadEvent(startTrans); '; + $this->oPage->requireJSStandalone($initJS); + + $aInitialUsers = $oGroup->getMembers(); + $aAllUsers = User::getList(); + + + // FIXME this is massively non-performant for large userbases.. + $aGroupUsers = array(); + $aFreeUsers = array(); + foreach ($aInitialUsers as $oUser) { + $aGroupUsers[$oUser->getId()] = $oUser; + } + foreach ($aAllUsers as $oUser) { + if (!array_key_exists($oUser->getId(), $aGroupUsers)) { + $aFreeUsers[$oUser->getId()] = $oUser; + } + } + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/groups_manageusers"); + $aTemplateData = array( + "context" => $this, + "edit_group" => $oGroup, + 'unused_users' => $aFreeUsers, + 'group_users' => $aGroupUsers, + ); + return $oTemplate->render($aTemplateData); + } + + + function do_updateUserMembers() { + $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); + $oGroup = Group::get($group_id); + if ((PEAR::isError($oGroup)) || ($oGroup === false)) { + $this->errorRedirectToMain(_('No such group.')); + } + + $userAdded = KTUtil::arrayGet($_REQUEST, 'userAdded',''); + $userRemoved = KTUtil::arrayGet($_REQUEST, 'userRemoved',''); + + + $aUserToAddIDs = explode(",", $userAdded); + $aUserToRemoveIDs = explode(",", $userRemoved); + + $this->startTransaction(); + $usersAdded = array(); + $usersRemoved = array(); + + foreach ($aUserToAddIDs as $iUserId ) { + if ($iUserId > 0) { + $oUser= User::Get($iUserId); + $res = $oGroup->addMember($oUser); + if (PEAR::isError($res) || $res == false) { + $this->errorRedirectToMain(sprintf(_('Unable to add user "%s" to group "%s"'), $oUser->getName(), $oGroup->getName())); + } else { $usersAdded[] = $oUser->getName(); } + } + } + + // Remove groups + foreach ($aUserToRemoveIDs as $iUserId ) { + if ($iUserId > 0) { + $oUser = User::get($iUserId); + $res = $oGroup->removeMember($oUser); + if (PEAR::isError($res) || $res == false) { + $this->errorRedirectToMain(sprintf(_('Unable to remove user "%s" from group "%s"'), $oUser->getName(), $oGroup->getName())); + } else { $usersRemoved[] = $oUser->getName(); } + } + } + + $msg = ''; + if (!empty($usersAdded)) { $msg .= ' ' . _('Added') . ': ' . join(', ', $usersAdded) . ',
'; } + if (!empty($usersRemoved)) { $msg .= ' ' . _('Removed') . ': ' . join(', ',$usersRemoved) . '.'; } + + $this->commitTransaction(); + $this->successRedirectToMain($msg); + } + + + // FIXME copy-paste ... + function do_managesubgroups() { + $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); + $oGroup = Group::get($group_id); + if ((PEAR::isError($oGroup)) || ($oGroup === false)) { + $this->errorRedirectToMain(_('No such group.')); + } + + $this->aBreadcrumbs[] = array('name' => $oGroup->getName()); + $this->oPage->setBreadcrumbDetails(_('manage members')); + $this->oPage->setTitle(sprintf(_('Manage members of %s'), $oGroup->getName())); + + + // FIXME replace OptionTransfer.js. me no-likey. + + // FIXME this is hideous. refactor the transfer list stuff completely. + $initJS = 'var optGroup = new OptionTransfer("groupSelect","chosenGroups"); ' . + 'function startTrans() { var f = getElement("usergroupform"); ' . + ' optGroup.saveAddedRightOptions("groupAdded"); ' . + ' optGroup.saveRemovedRightOptions("groupRemoved"); ' . + ' optGroup.init(f); }; ' . + ' addLoadEvent(startTrans); '; + $this->oPage->requireJSStandalone($initJS); + + $aMemberGroupsUnkeyed = $oGroup->getMemberGroups(); + $aMemberGroups = array(); + $aMemberIDs = array(); + foreach ($aMemberGroupsUnkeyed as $oMemberGroup) { + $aMemberIDs[] = $oMemberGroup->getID(); + $aMemberGroups[$oMemberGroup->getID()] = $oMemberGroup; + } + + $aGroupArray = GroupUtil::buildGroupArray(); + $aAllowedGroupIDs = GroupUtil::filterCyclicalGroups($oGroup->getID(), $aGroupArray); + $aAllowedGroupIDs = array_diff($aAllowedGroupIDs, $aMemberIDs); + $aAllowedGroups = array(); + foreach ($aAllowedGroupIDs as $iAllowedGroupID) { + $aAllowedGroups[$iAllowedGroupID] =& Group::get($iAllowedGroupID); + } + + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/groups_managesubgroups"); + $aTemplateData = array( + "context" => $this, + "edit_group" => $oGroup, + 'unused_groups' => $aAllowedGroups, + 'group_members' => $aMemberGroups, + ); + return $oTemplate->render($aTemplateData); + } + + function _getUnitName($oGroup) { + $u = $oGroup->getUnit(); + + return $u->getName(); + } + + // FIXME copy-paste ... + function do_updateGroupMembers() { + $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); + $oGroup = Group::get($group_id); + if ((PEAR::isError($oGroup)) || ($oGroup === false)) { + $this->errorRedirectToMain('No such group.'); + } + + $groupAdded = KTUtil::arrayGet($_REQUEST, 'groupAdded',''); + $groupRemoved = KTUtil::arrayGet($_REQUEST, 'groupRemoved',''); + + + $aGroupToAddIDs = explode(",", $groupAdded); + $aGroupToRemoveIDs = explode(",", $groupRemoved); + + $this->startTransaction(); + $groupsAdded = array(); + $groupsRemoved = array(); + + + foreach ($aGroupToAddIDs as $iMemberGroupID ) { + if ($iMemberGroupID > 0) { + $oMemberGroup = Group::get($iMemberGroupID); + $res = $oGroup->addMemberGroup($oMemberGroup); + if (PEAR::isError($res)) { + $this->errorRedirectToMain(sprintf(_("Failed to add %s to %s"), $oMemberGroup->getName(), $oGroup->getName())); + exit(0); + } else { $groupsAdded[] = $oMemberGroup->getName(); } + } + } + + foreach ($aGroupToRemoveIDs as $iMemberGroupID ) { + if ($iMemberGroupID > 0) { + $oMemberGroup = Group::get($iMemberGroupID); + $res = $oGroup->removeMemberGroup($oMemberGroup); + if (PEAR::isError($res)) { + $this->errorRedirectToMain(sprintf(_("Failed to remove %s from %s"), $oMemberGroup->getName(), $oGroup->getName())); + exit(0); + } else { $groupsRemoved[] = $oMemberGroup->getName(); } + } + } + + $msg = ''; + if (!empty($groupsAdded)) { $msg .= ' ' . _('Added') . ': ' . join(', ', $groupsAdded) . ',
'; } + if (!empty($groupsRemoved)) { $msg .= ' '. _('Removed'). ': ' . join(', ',$groupsRemoved) . '.'; } + + $this->commitTransaction(); + + $this->successRedirectToMain($msg); + } + + + function do_addGroup() { + $this->aBreadcrumbs[] = array('action' => 'groupManagement', 'name' => _('Group Management')); + $this->oPage->setBreadcrumbDetails(_('create new group')); + + + $this->oPage->setTitle(_("Create New Group")); + + $edit_fields = array(); + $add_fields[] = new KTStringWidget(_('Group Name'),_('A short name for the group. e.g. administrators.'), 'group_name', null, $this->oPage, true); + $add_fields[] = new KTCheckboxWidget(_('Unit Administrators'),_('Should all the members of this group be given unit administration privilidges?'), 'is_unitadmin', false, $this->oPage, false); + $add_fields[] = new KTCheckboxWidget(_('System Administrators'),_('Should all the members of this group be given system administration privilidges?'), 'is_sysadmin', false, $this->oPage, false); + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/addgroup"); + $aTemplateData = array( + "context" => $this, + "add_fields" => $add_fields, + ); + return $oTemplate->render($aTemplateData); + } + + function do_createGroup() { + + $group_name = KTUtil::arrayGet($_REQUEST, 'group_name'); + if (empty($group_name)) { $this->errorRedirectToMain(_('Please specify a name for the group.')); } + $is_unitadmin = KTUtil::arrayGet($_REQUEST, 'is_unitadmin', false); + if ($is_unitadmin !== false) { $is_unitadmin = true; } + $is_sysadmin = KTUtil::arrayGet($_REQUEST, 'is_sysadmin', false); + if ($is_sysadmin !== false) { $is_sysadmin = true; } + + $this->startTransaction(); + + $oGroup =& Group::createFromArray(array( + 'sName' => $group_name, + 'bIsUnitAdmin' => $is_unitadmin, + 'bIsSysAdmin' => $is_sysadmin, + )); + //$res = $oGroup->create(); + //if (($res == false) || (PEAR::isError($res))) { return $this->errorRedirectToMain('Failed to create group "' . $group_name . '"'); } + // do i need to "create" + $this->commitTransaction(); + $this->successRedirectToMain(sprintf(_('Group "%s" created.'), $group_name)); + } + + function do_deleteGroup() { + $aErrorOptions = array( + 'redirect_to' => array('main'), + ); + $oGroup = $this->oValidator->validateGroup($_REQUEST['group_id'], $aErrorOptions); + $sGroupName = $oGroup->getName(); + $res = $oGroup->delete(); + $this->oValidator->notError($res, $aErrorOptions); + $this->successRedirectToMain(sprintf(_('Group "%s" deleted.'), $sGroupName)); + } + +} + +?> diff --git a/plugins/ktcore/admin/manageCleanup.php b/plugins/ktcore/admin/manageCleanup.php new file mode 100755 index 0000000..e9e0872 --- /dev/null +++ b/plugins/ktcore/admin/manageCleanup.php @@ -0,0 +1,166 @@ +get('urls/documentRoot'); + +$aIgnore = array( + '.', '..', + 'CVS', + '.empty', + '.htaccess', + '.cvsignore', +); + +$aFoldersToRemove = array(); +$aFilesToRemove = array(); +$aRepoDocumentProblems = array(); +$aRepoFolderProblems = array(); +$aRepoVersionProblems = array(); + +function checkFileVersion($path, $version) { + $fod = KTBrowseUtil::folderOrDocument($path); + if ($fod === false) { + // No document by that name, so no point checking version + // information. + return; + } + return true; +} + +function checkFile($path, $first = true) { + $pattern = "/^(.*)-((?:\d+)\.(?:\d+))$/"; + if (preg_match($pattern, $path, $matches)) { + if (checkFileVersion($matches[1], $matches[2])) { + // If it's a version, then don't check for full path + // below... + return; + } + } + $fod = KTBrowseUtil::folderOrDocument($path); + if ($fod === false) { + $GLOBALS["aFilesToRemove"][] = $path; + return; + } +} + +function checkDirectory($path) { + global $fsPath, $aIgnore; + $fullpath = sprintf("%s/%s", $fsPath, $path); + + if (!is_dir($fullpath)) { + print "Not a directory: $fullpath\n"; + } + + if ($path === '/Deleted') { + // Deleted files handled separately. + return; + } + + if (!empty($path)) { + $fod = KTBrowseUtil::folderOrDocument($path); + if ($fod === false) { + $GLOBALS["aFoldersToRemove"][] = $path; + return; + } + } + + $dh = @opendir($fullpath); + if ($dh === false) { + print "Could not open directory: $fullpath\n"; + } + while (($filename = readdir($dh)) !== false) { + if (in_array($filename, $aIgnore)) { continue; } + $subrelpath = sprintf("%s/%s", $path, $filename); + $subfullpath = sprintf("%s/%s", $fsPath, $subrelpath); + if (is_dir($subfullpath)) { + checkDirectory($subrelpath); + } + if (is_file($subfullpath)) { + checkFile($subrelpath); + } + } +} + +function checkRepoFolder($oFolder) { + global $fsPath, $aRepoFolderProblems; + $sFolderPath = sprintf("%s/%s", $oFolder->getFullPath(), $oFolder->getName()); + $sFullPath = sprintf("%s/%s", $fsPath, $sFolderPath); + if (!is_dir($sFullPath)) { + $aRepoFolderProblems[] = $sFolderPath; + } +} + +function checkRepoDocument($oDocument) { + global $fsPath, $aRepoDocumentProblems; + $sDocumentPath = $oDocument->getStoragePath(); + $sFullPath = sprintf("%s/%s", $fsPath, $sDocumentPath); + if (!is_file($sFullPath)) { + $aRepoDocumentProblems[] = $sDocumentPath; + } + checkRepoVersions($oDocument); +} + +function checkRepoVersions($oDocument) { + global $fsPath, $aRepoVersionProblems; + $table = "document_transactions"; + $aVersions = DBUtil::getResultArrayKey(array("SELECT DISTINCT version FROM $table WHERE document_id = ?", array($oDocument->getID())), "version"); foreach($aVersions as $sVersion) { + if ($sVersion == $oDocument->getVersion()) { + continue; + } + $sDocumentPath = $oDocument->getStoragePath(); + $sFullPath = sprintf("%s/%s-%s", $fsPath, $sDocumentPath, $sVersion); + if (!is_file($sFullPath)) { + $aRepoVersionProblems[] = array($sDocumentPath, $sVersion); + continue; + } + } +} + +class ManageCleanupDispatcher extends KTAdminDispatcher { + function do_main() { + global $aFoldersToRemove; + global $aFilesToRemove; + global $aRepoDocumentProblems; + global $aRepoFolderProblems; + global $aRepoVersionProblems; + + checkDirectory(""); + $aFolders =& Folder::getList(); + foreach ($aFolders as $oFolder) { + checkRepoFolder($oFolder); + } + $aDocuments =& Document::getList(array("status_id = ?", array(LIVE))); + foreach ($aDocuments as $oDocument) { + checkRepoDocument($oDocument); + } + $oTemplate =& $this->oValidator->validateTemplate('ktcore/document/cleanup'); + $oTemplate->setData(array( + 'aFoldersToRemove' => $aFoldersToRemove, + 'aFilesToRemove' => $aFilesToRemove, + 'aRepoDocumentProblems' => $aRepoDocumentProblems, + 'aRepoFolderProblems' => $aRepoFolderProblems, + 'aRepoVersionProblems' => $aRepoVersionProblems, + )); + return $oTemplate->render(); + } +} + +$oDispatcher = new ManageCleanupDispatcher(); +$oDispatcher->dispatch(); + +?> diff --git a/plugins/ktcore/admin/manageConditionals.php b/plugins/ktcore/admin/manageConditionals.php new file mode 100755 index 0000000..6a70269 --- /dev/null +++ b/plugins/ktcore/admin/manageConditionals.php @@ -0,0 +1,116 @@ +aBreadcrumbs[] = array('action' => 'docfield', 'name' => _('Document Field Management')); + + + } + + function do_main() { + + $aFieldsets = KTFieldset::getList("is_conditional = 1"); + $oTemplating = new KTTemplating; + + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/conditional/select_fieldset"); + $aTemplateData = array( + "context" => &$this, + "available_fieldsets" => $aFieldsets, + ); + return $oTemplate->render($aTemplateData); + } + + // FIXME refactor this into do_editSimple(fieldset_id); + function do_editFieldset() { + $fieldset_id = KTUtil::arrayGet($_REQUEST, "fieldset_id"); + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/conditional/editsimple"); + /* alright: to "do" this we need at least: + * 1. the list of all the columns (id, name) and their available values. + * 2. the fieldset_id. + * we can then render in/out. Everything "intelligent" happens + * in AJAX (doing it with submits sucks arse. + * + * FIXME we fake it here with nested arrays... + */ + $oFieldset =& KTFieldset::get($fieldset_id); + $aFields =& $oFieldset->getFields(); + + $this->aBreadcrumbs[] = array( + 'action' => 'docfield', + 'query' => 'action=edit&fFieldsetId=' . $oFieldset->getId(), + 'name' => $oFieldset->getName() + ); + $this->aBreadcrumbs[] = array( + 'action' => 'docfield', + 'query' => 'action=manageConditional&fFieldsetId=' . $oFieldset->getId(), + 'name' => _('Manage conditional fieldset'), + ); + $this->aBreadcrumbs[] = array( + 'name' => _('Manage simple conditional'), + ); + + $aTemplateData = array( + "context" => &$this, + "fieldset_id" => $fieldset_id, + "aFields" => $aFields, + "iMasterFieldId" => $aFields[0]->getId(), + ); + return $oTemplate->render($aTemplateData); + } + + // FIXME refactor this into do_editSimple(fieldset_id); + function do_editComplexFieldset() { + $fieldset_id = KTUtil::arrayGet($_REQUEST, "fieldset_id"); + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/conditional/editcomplex"); + /* alright: to "do" this we need at least: + * 1. the list of all the columns (id, name) and their available values. + * 2. the fieldset_id. + * we can then render in/out. Everything "intelligent" happens + * in AJAX (doing it with submits sucks arse. + * + * FIXME we fake it here with nested arrays... + */ + $oFieldset =& KTFieldset::get($fieldset_id); + $aFields =& $oFieldset->getFields(); + $this->aBreadcrumbs[] = array( + 'action' => 'docfield', + 'query' => 'action=edit&fFieldsetId=' . $oFieldset->getId(), + 'name' => $oFieldset->getName() + ); + $this->aBreadcrumbs[] = array( + 'action' => 'docfield', + 'query' => 'action=manageConditional&fFieldsetId=' . $oFieldset->getId(), + 'name' => _('Manage conditional fieldset'), + ); + $this->aBreadcrumbs[] = array( + 'name' => _('Manage complex conditional'), + ); + $aTemplateData = array( + "context" => &$this, + "fieldset_id" => $fieldset_id, + "aFields" => $aFields, + "iMasterFieldId" => $aFields[0]->getId(), + ); + return $oTemplate->render($aTemplateData); + } +} + +$oDispatcher = new ManageConditionalDispatcher(); +$oDispatcher->dispatch(); + +?> diff --git a/plugins/ktcore/admin/manageLookupTrees.php b/plugins/ktcore/admin/manageLookupTrees.php new file mode 100755 index 0000000..9317c66 --- /dev/null +++ b/plugins/ktcore/admin/manageLookupTrees.php @@ -0,0 +1,246 @@ +loadTemplate("ktcore/manage_lookuptrees"); + $aTemplateData = array( + "treefields" => $aTreeFields, + "lookupfields" => $aLookupFields, + ); + return $oTemplate->render($aTemplateData); + } + + function do_createTree() { + // extract. + $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); + + // validate + if (empty($field_id)) { return $this->errorRedirectToMain(_("Must select a field to convert.")); } + $oField =& DocumentField::get($field_id); + if (PEAR::isError($oField)) { return $this->errorRedirectToMain(_("Invalid field.")); } + + // set as a metadata tree. + $oField->setHasLookupTree(1); + $oField->update(); + $this->errorRedirectToMain(sprintf(_("Converted %s to a tree."), $oField->getName())); + } + + + // create and display the tree editing form. + function do_editTree() { + global $default; + // extract. + $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); + $current_node = KTUtil::arrayGet($_REQUEST, 'current_node', 0); + $subaction = KTUtil::arrayGet($_REQUEST, 'subaction'); + + // validate + if (empty($field_id)) { return $this->errorRedirectToMain(_("Must select a field to edit.")); } + $oField =& DocumentField::get($field_id); + if (PEAR::isError($oField)) { return $this->errorRedirectToMain(_("Invalid field.")); } + + // under here we do the subaction rendering. + // we do this so we don't have to do _very_ strange things with multiple actions. + //$default->log->debug("Subaction: " . $subaction); + $fieldTree =& new MDTree(); + $fieldTree->buildForField($oField->getId()); + + if ($subaction !== null) { + $target = 'editTree'; + $msg = _('Changes saved.'); + if ($subaction === "addCategory") { + $new_category = KTUtil::arrayGet($_REQUEST, 'category_name'); + if (empty($new_category)) { return $this->errorRedirectTo("editTree", _("Must enter a name for the new category."), array("field_id" => $field_id)); } + else { $this->subact_addCategory($field_id, $current_node, $new_category, $fieldTree);} + $msg = _('Category added'). ': ' . $new_category; + } + if ($subaction === "deleteCategory") { + $this->subact_deleteCategory($fieldTree, $current_node); + $current_node = 0; // clear out, and don't try and render the newly deleted category. + $msg = _('Category removed.'); + } + if ($subaction === "linkKeywords") { + $keywords = KTUtil::arrayGet($_REQUEST, 'keywordsToAdd'); + $this->subact_linkKeywords($fieldTree, $current_node, $keywords); + $current_node = 0; // clear out, and don't try and render the newly deleted category. + $msg = _('Keywords added to category.'); + } + if ($subaction === "unlinkKeyword") { + $keyword = KTUtil::arrayGet($_REQUEST, 'keyword_id'); + $this->subact_unlinkKeyword($fieldTree, $keyword); + $msg = _('Keyword moved to base of tree.'); + } + // now redirect + $query = 'field_id=' . $field_id; + return $this->successRedirectTo($target, $msg, $query); + } + + if ($fieldTree->root === null) { + return $this->errorRedirectToMain(_("Error building tree. Is this a valid tree-lookup field?")); + } + + // FIXME extract this from MDTree (helper method?) + $free_metadata = MetaData::getList('document_field_id = '.$oField->getId().' AND (treeorg_parent = 0 OR treeorg_parent IS NULL)'); + + // render edit template. + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/edit_lookuptrees"); + $renderedTree = $this->_evilTreeRenderer($fieldTree); + + $this->oPage->setTitle(_('Edit Lookup Tree')); + + //$this->oPage->requireJSResource('thirdparty/js/MochiKit/Base.js'); + + $aTemplateData = array( + "field" => $oField, + "tree" => $fieldTree, + "renderedTree" => $renderedTree, + "currentNode" => $current_node, + "freechildren" => $free_metadata, + "context" => $this, + ); + return $oTemplate->render($aTemplateData); + } + + function subact_addCategory($field_id, $current_node, $new_category, &$constructedTree) { + $newCategory = MDTreeNode::createFromArray(array ( + "iFieldId" => $field_id, + "sName" => $new_category, + "iParentNode" => $current_node, + )); + if (PEAR::isError($newCategory)) + { + return false; + } + $constructedTree->addNode($newCategory); + return true; + } + + function subact_deleteCategory(&$constructedTree, $current_node) { + $constructedTree->deleteNode($current_node); + return true; + } + + function subact_unlinkKeyword(&$constructedTree, $keyword) { + $oKW = MetaData::get($keyword); + $constructedTree->reparentKeyword($oKW->getId(), 0); + return true; + } + + + function subact_linkKeywords(&$constructedTree, $current_node, $keywords) { + foreach ($keywords as $md_id) + { + $constructedTree->reparentKeyword($md_id, $current_node); + } + return true; + } + + /* ----------------------- EVIL HACK -------------------------- + * + * This whole thing needs to replaced, as soon as I work out how + * to non-sucking Smarty recursion. + */ + + function _evilTreeRecursion($subnode, $treeToRender) + { + $treeStr = "'; + return $treeStr; + + } + + // I can't seem to do recursion in smarty, and recursive templates seems a bad solution. + // Come up with a better way to do this (? NBM) + function _evilTreeRenderer($treeToRender) { + //global $default; + $treeStr = ""; + $stack = array(); + $exitstack = array(); + + // since the root is virtual, we need to fake it here. + // the inner section is generised. + $treeStr .= ''; + + return $treeStr; + } + + // don't hate me. + function _evilActionHelper($iFieldId, $bIsKeyword, $current_node) { + $actionStr = " ("; + if ($bIsKeyword === true) { + $actionStr .= 'unlink'; + } + else + { + $actionStr .= 'add items '; + $actionStr .= '| delete'; + } + $actionStr .= ")"; + return $actionStr; + } + +} + +$oDispatcher = new ManageLookupTreeDispatcher(); +$oDispatcher->dispatch(); + +?> diff --git a/plugins/ktcore/admin/managePermissions.php b/plugins/ktcore/admin/managePermissions.php new file mode 100755 index 0000000..9a0ada8 --- /dev/null +++ b/plugins/ktcore/admin/managePermissions.php @@ -0,0 +1,68 @@ +oPage->setTitle(_('Manage Permissions')); + $this->aBreadcrumbs[] = array('action' => 'managePermissions', 'name' => _('Manage Permissions')); + + $add_fields = array(); + $add_fields[] = new KTStringWidget(_('System Name'),_('The internal name used for the permission. This should never be changed.'), 'name', null, $this->oPage, true); + $add_fields[] = new KTStringWidget(_('Display Name'),_('A short name that is shown to users whenever permissions must be assigned.'), 'human_name', null, $this->oPage, true); + + $oTemplating = new KTTemplating; + $aPermissions =& KTPermission::getList(); + $oTemplate = $oTemplating->loadTemplate("ktcore/manage_permissions"); + $aTemplateData = array( + 'context' => $this, + "permissions" => $aPermissions, + 'add_fields' => $add_fields, + ); + return $oTemplate->render($aTemplateData); + } + + function do_newPermission() { + $name = KTUtil::arrayGet($_REQUEST, 'name'); + $human_name = KTUtil::arrayGet($_REQUEST, 'human_name'); + if (empty($name) || empty($human_name)) { + return $this->errorRedirectToMain(_("Both names not given")); + } + $oPerm = KTPermission::createFromArray(array( + 'name' => $name, + 'humanname' => $human_name, + )); + if (PEAR::isError($oPerm)) { + return $this->errorRedirectToMain(_("Error creating permission")); + } + return $this->successRedirectToMain(_("Permission created")); + } + + function do_deletePermission() { + $id = KTUtil::arrayGet($_REQUEST, 'id'); + if (empty($id)) { + return $this->errorRedirectToMain(_("Both names not given")); + } + $oPerm = KTPermission::get($id); + if (PEAR::isError($oPerm)) { + return $this->errorRedirectToMain(_("Error finding permission")); + } + if ($oPerm->getBuiltIn() === true) { + return $this->errorRedirectToMain(_("Can't delete built-in permission")); + } + $res = $oPerm->delete(); + if (PEAR::isError($res)) { + return $this->errorRedirectToMain(_("Error deleting permission")); + } + return $this->successRedirectToMain(_("Permission deleted")); + } +} + +//$oDispatcher = new ManagePermissionsDispatcher(); +//$oDispatcher->dispatch(); + +?> diff --git a/plugins/ktcore/admin/orgManagement.php b/plugins/ktcore/admin/orgManagement.php new file mode 100755 index 0000000..c3d3181 --- /dev/null +++ b/plugins/ktcore/admin/orgManagement.php @@ -0,0 +1,73 @@ +aBreadcrumbs[] = array('action' => 'orgManagement', 'name' => _('Organisation Management')); + $this->oPage->setBreadcrumbDetails(_('select a organisation')); + $this->oPage->setTitle(_("Organisation Management")); + + $org_id= KTUtil::arrayGet($_REQUEST, 'org_id', null); + if ($org_id === null) { $for_edit = false; } + else { $for_edit = true; } + + $org_list =& Organisation::getList(); + + $edit_fields = array(); + $edit_org = null; + if ($for_edit === true) { + $oOrg = Organisation::get($org_id); + if (PEAR::isError($oOrg) || ($oOrg == false)) { $this->errorRedirectToMain(_('Invalid Organisation')); } + $edit_fields[] = new KTStringWidget(_('Organisation Name'),_("The organisation's visible name. e.g. Tech Support"), 'name', $oOrg->getName(), $this->oPage, true); + } + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/orgadmin"); + $aTemplateData = array( + "context" => $this, + "for_edit" => $for_edit, + "edit_fields" => $edit_fields, + "edit_org" => $oOrg, + "org_list" => $org_list, + ); + return $oTemplate->render($aTemplateData); + } + + function do_updateOrg() { + $org_id = KTUtil::arrayGet($_REQUEST, 'org_id'); + $oOrg = Organisation::get($org_id); + if (PEAR::isError($oOrg) || ($oOrg == false)) { + $this->errorRedirectToMain(_('Please specify an organisation.')); + exit(0); + } + + $org_name = KTUtil::arrayGet($_REQUEST, 'name', null); + if (empty($org_name)) { + $this->errorRedirectToMain(_('Please specify an org name.')); + exit(0); + } + + $this->startTransaction(); + $oOrg->setName($org_name); + $res = $oOrg->update(); + if (PEAR::isError($res)) { + $this->errorRedirectToMain(_('Failed to update org name.')); + exit(0); + } + + $this->commitTransaction(); + $this->successRedirectToMain(_('Org name changed to') . ': "' . $org_name . '"'); + } + +} + + +?> diff --git a/plugins/ktcore/admin/roleManagement.php b/plugins/ktcore/admin/roleManagement.php new file mode 100644 index 0000000..d36c3fa --- /dev/null +++ b/plugins/ktcore/admin/roleManagement.php @@ -0,0 +1,126 @@ +, Jam Warehouse (Pty) Ltd, South Africa + * @package documentmanagement + */ + +require_once(KT_LIB_DIR . '/dispatcher.inc.php'); +require_once(KT_LIB_DIR . '/templating/kt3template.inc.php'); + +require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php'); +require_once(KT_LIB_DIR . "/roles/Role.inc"); + +class RoleAdminDispatcher extends KTAdminDispatcher { + function check() { + return true; + } + + function do_main() { + $this->aBreadcrumbs[] = array('action' => 'roleManagement', 'name' => _('Role Management')); + + $this->oPage->setTitle(_('Role Management')); + + $edit_fields = array(); + $role_id = KTUtil::arrayGet($_REQUEST, 'role_id', null); + $oRole = Role::get($role_id); + if (PEAR::isError($oRole) || ($oRole == false)) { $for_edit = false; } + else { + $for_edit = true; + $edit_fields[] = new KTStringWidget(_('Name'),_('A short, human-readable name for the role.'), 'name', $oRole->getName(), $this->oPage, true); + } + + $aRoles =& Role::getList('id > 0'); + + $add_fields = array(); + $add_fields[] = new KTStringWidget(_('Name'),_('A short, human-readable name for the role.'), 'name', null, $this->oPage, true); + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate = $oTemplating->loadTemplate('ktcore/principals/roleadmin'); + $oTemplate->setData(array( + "context" => $this, + "add_fields" => $add_fields, + "for_edit" => $for_edit, + 'edit_role' => $oRole, + 'edit_fields' => $edit_fields, + 'roles' => $aRoles, + )); + return $oTemplate; + } + + function do_createRole() { + $name = KTUtil::arrayGet($_REQUEST, 'name', null); + if ($name === null) { + $this->errorRedirectToMain(_('Please give the role a name.')); + } + + $this->startTransaction(); + $oRole = new Role($name); + $res = $oRole->create(); + if (PEAR::isError($res) || ($res == false)) { + $this->errorRedirectToMain(_('Unable to create role.')); + } + + $this->successRedirectToMain(sprintf(_('Role "%s" created.'), $name)); + } + + function do_updateRole() { + $role_id = KTUtil::arrayGet($_REQUEST, 'role_id'); + $oRole = Role::get($role_id); + if (PEAR::isError($oRole) || ($oRole == false)) { + $this->errorRedirectToMain(_('Please select a valid role first.')); + } + + $name = KTUtil::arrayGet($_REQUEST, 'name', null); + if ($name === null) { + $this->errorRedirectToMain(_('Please give the role a name.')); + } + + $this->startTransaction(); + $oRole->setName($name); + $res = $oRole->update(); + if (PEAR::isError($res) || ($res == false)) { + $this->errorRedirectToMain(_('Unable to update role.')); + } + + $this->successRedirectToMain(sprintf(_('Role "%s" updated.'), $name)); + } + + function do_deleteRole() { + $role_id = KTUtil::arrayGet($_REQUEST, 'role_id'); + $oRole = Role::get($role_id); + if (PEAR::isError($oRole) || ($oRole == false)) { + $this->errorRedirectToMain(_('Please select a valid role first.')); + } + $name = $oRole->getName(); + + $this->startTransaction(); + $res = $oRole->delete(); + if (PEAR::isError($res) || ($res == false)) { + $this->errorRedirectToMain(_('Unable to delete the role.') . ' ' . _('Possible cause') . ': ' . $_SESSION['errorMessage']); + } + + $this->successRedirectToMain(sprintf(_('Role "%s" deleted. '), $name)); + } + +} + diff --git a/plugins/ktcore/admin/savedSearch.php b/plugins/ktcore/admin/savedSearch.php new file mode 100755 index 0000000..b00482d --- /dev/null +++ b/plugins/ktcore/admin/savedSearch.php @@ -0,0 +1,74 @@ +oValidator->validateTemplate('ktcore/search/administration/savedsearches'); + $oTemplate->setData(array( + 'saved_searches' => KTSavedSearch::getList(), + )); + return $oTemplate->render(); + } + + function do_new() { + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search"); + + $aCriteria = Criteria::getAllCriteria(); + + $aTemplateData = array( + "title" => _("Create a new condition"), + "aCriteria" => $aCriteria, + "searchButton" => _("Save"), + ); + return $oTemplate->render($aTemplateData); + } + + function do_view() { + + } + + // XXX: Rename to do_save + function do_performSearch() { + $datavars = KTUtil::arrayGet($_REQUEST, 'boolean_search'); + if (!is_array($datavars)) { + $datavars = unserialize($datavars); + } + + if (empty($datavars)) { + $this->errorRedirectToMain(_('You need to have at least 1 condition.')); + } + + $sName = "Neil's saved search"; + $sNamespace = KTUtil::nameToLocalNamespace('Saved searches', $sName); + + $oSearch = KTSavedSearch::createFromArray(array( + 'name' => $sName, + 'namespace' => $sNamespace, + 'iscondition' => false, + 'iscomplete' => true, + 'userid' => null, + 'search' => $datavars, + )); + + $this->oValidator->notError($oSearch, array( + 'redirect_to' => 'main', + 'message' => _('Search not saved'), + )); + $this->successRedirectToMain(_('Search saved')); + } +} + +$oDispatcher = new KTSavedSearchDispatcher(); +$oDispatcher->dispatch(); + +?> diff --git a/plugins/ktcore/admin/unitManagement.php b/plugins/ktcore/admin/unitManagement.php new file mode 100755 index 0000000..d8f4af6 --- /dev/null +++ b/plugins/ktcore/admin/unitManagement.php @@ -0,0 +1,79 @@ +aBreadcrumbs[] = array('action' => 'unitManagement', 'name' => _('Unit Management')); + $this->oPage->setBreadcrumbDetails(_('select a unit')); + $this->oPage->setTitle(_("Unit Management")); + + $unit_id= KTUtil::arrayGet($_REQUEST, 'unit_id', null); + if ($unit_id === null) { $for_edit = false; } + else { $for_edit = true; } + + + $add_fields = array(); + $add_fields[] = new KTStringWidget(_('Unit Name'),_("The unit's visible name. e.g. Tech Support"), 'name', null, $this->oPage, true); + + $unit_list =& Unit::getList(); + + $edit_fields = array(); + $edit_unit = null; + if ($for_edit === true) { + $oUnit = Unit::get($unit_id); + $edit_fields[] = new KTStringWidget(_('Unit Name'),_("The unit's visible name. e.g. Tech Support"), 'name', $oUnit->getName(), $this->oPage, true); + } + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/unitadmin"); + $aTemplateData = array( + "context" => $this, + "add_fields" => $add_fields, + "for_edit" => $for_edit, + "edit_fields" => $edit_fields, + "edit_unit" => $oUnit, + "unit_list" => $unit_list, + ); + return $oTemplate->render($aTemplateData); + } + + function do_updateUnit() { + $unit_id = KTUtil::arrayGet($_REQUEST, 'unit_id'); + $oUnit = Unit::get($unit_id); + if (PEAR::isError($oUnit) || ($oUnit == false)) { + $this->errorRedirectToMain(_('Please specify a unit.')); + exit(0); + } + + $unit_name = KTUtil::arrayGet($_REQUEST, 'name', null); + if (empty($unit_name)) { + $this->errorRedirectToMain(_('Please specify a unit name.')); + exit(0); + } + + $this->startTransaction(); + $oUnit->setName($unit_name); + $res = $oUnit->update(); + if (PEAR::isError($res)) { + $this->errorRedirectToMain(_('Failed to update unit name.')); + exit(0); + } + + $this->commitTransaction(); + $this->successRedirectToMain(sprintf(_('Unit name changed to "%s"'), $unit_name)); + } + +} + + +?> diff --git a/plugins/ktcore/admin/userManagement.php b/plugins/ktcore/admin/userManagement.php new file mode 100755 index 0000000..519f8af --- /dev/null +++ b/plugins/ktcore/admin/userManagement.php @@ -0,0 +1,442 @@ +aBreadcrumbs[] = array('action' => 'userManagement', 'name' => _('User Management')); + $this->oPage->setBreadcrumbDetails(_('select a user')); + $this->oPage->setTitle(_("User Management")); + + $name = KTUtil::arrayGet($_REQUEST, 'name'); + $show_all = KTUtil::arrayGet($_REQUEST, 'show_all', false); + $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); + + + $search_fields = array(); + $search_fields[] = new KTStringWidget(_('Username'),_("Enter part of the person's username. e.g. ra will match brad."), 'name', $name, $this->oPage, true); + + // FIXME handle group search stuff. + $search_results = null; + if (!empty($name)) { + $search_results =& User::getList('WHERE username LIKE "%' . DBUtil::escapeSimple($name) . '%"'); + } else if ($show_all !== false) { + $search_results =& User::getList(); + } + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/useradmin"); + $aTemplateData = array( + "context" => $this, + "search_fields" => $search_fields, + "search_results" => $search_results, + ); + return $oTemplate->render($aTemplateData); + } + + + function do_addUser() { + $this->aBreadcrumbs[] = array('action' => 'userManagement', 'name' => _('User Management')); + $this->oPage->setBreadcrumbDetails(_('add a new user')); + $this->oPage->setTitle(_("Modify User Details")); + + $name = KTUtil::arrayGet($_REQUEST, 'name'); + $show_all = KTUtil::arrayGet($_REQUEST, 'show_all', false); + $add_user = KTUtil::arrayGet($_REQUEST, 'add_user', false); + if ($add_user !== false) { $add_user = true; } + $edit_user = KTUtil::arrayGet($_REQUEST, 'edit_user', false); + + + $add_fields = array(); + $add_fields[] = new KTStringWidget(_('Username'),_('The username the user will enter to gain access to the KnowledgeTree. e.g. jsmith'), 'username', null, $this->oPage, true); + $add_fields[] = new KTStringWidget(_('Name'),_('The full name of the user. This is shown in reports and listings. e.g. John Smith'), 'name', null, $this->oPage, true); + $add_fields[] = new KTStringWidget(_('Email Address'), _('The email address of the user. Notifications and alerts are mailed to this address if email notifications is set below. e.g. jsmith@acme.com'), 'email_address', null, $this->oPage, false); + $add_fields[] = new KTCheckboxWidget(_('Email Notifications'), _("If this is specified then the user will have notifications sent to the email address entered above. If it isn't set, then the user will only see notifications on the Dashboard"), 'email_notifications', true, $this->oPage, false); + $add_fields[] = new KTPasswordWidget(_('Password'), _('Specify an initial password for the user.'), 'password', null, $this->oPage, true); + $add_fields[] = new KTPasswordWidget(_('Confirm Password'), _('Confirm the password specified above.'), 'confirm_password', null, $this->oPage, true); + // nice, easy bits. + $add_fields[] = new KTStringWidget(_('Mobile Number'), _("The mobile phone number of the user. If the system is configured to send notifications to cellphones, then this number will be SMS'd with notifications. e.g. 999 9999 999"), 'mobile_number', null, $this->oPage, false); + $add_fields[] = new KTStringWidget(_('Maximum Sessions'), _('As a safety precaution, it is useful to limit the number of times a given account can log in, before logging out. This prevents a single account being used by many different people.'), 'max_sessions', '3', $this->oPage, true); + + $aAuthenticationSources =& KTAuthenticationSource::getList(); + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/adduser"); + $aTemplateData = array( + "context" => &$this, + "add_fields" => $add_fields, + "authentication_sources" => $aAuthenticationSources, + ); + return $oTemplate->render($aTemplateData); + } + + function do_addUserFromSource() { + $oSource =& KTAuthenticationSource::get($_REQUEST['source_id']); + $sProvider = $oSource->getAuthenticationProvider(); + $oRegistry =& KTAuthenticationProviderRegistry::getSingleton(); + $oProvider =& $oRegistry->getAuthenticationProvider($sProvider); + + $this->aBreadcrumbs[] = array('action' => 'userManagement', 'name' => _('User Management')); + $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'] . '?action=addUser', 'name' => _('add a new user')); + $oProvider->aBreadcrumbs = $this->aBreadcrumbs; + $oProvider->oPage->setBreadcrumbDetails($oSource->getName()); + $oProvider->oPage->setTitle(_("Modify User Details")); + + $oProvider->dispatch(); + exit(0); + } + + function do_editUser() { + $this->aBreadcrumbs[] = array('action' => 'userManagement', 'name' => _('User Management')); + $this->oPage->setBreadcrumbDetails(_('modify user details')); + $this->oPage->setTitle(_("Modify User Details")); + + $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); + $oUser =& User::get($user_id); + + if (PEAR::isError($oUser) || $oUser == false) { + $this->errorRedirectToMain(_('Please select a user first.')); + exit(0); + } + + $this->aBreadcrumbs[] = array('name' => $oUser->getName()); + + $edit_fields = array(); + $edit_fields[] = new KTStringWidget(_('Username'),_('The username the user will enter to gain access to the KnowledgeTree. e.g. jsmith'), 'username', $oUser->getUsername(), $this->oPage, true); + $edit_fields[] = new KTStringWidget(_('Name'), _('The full name of the user. This is shown in reports and listings. e.g. John Smith'), 'name', $oUser->getName(), $this->oPage, true); + $edit_fields[] = new KTStringWidget(_('Email Address'),_('The email address of the user. Notifications and alerts are mailed to this address if email notifications is set below. e.g. jsmith@acme.com'), 'email_address', $oUser->getEmail(), $this->oPage, false); + $edit_fields[] = new KTCheckboxWidget(_('Email Notifications'), _('If this is specified then the user will have notifications sent to the email address entered above. If it is not set, then the user will only see notifications on the Dashboard'), 'email_notifications', $oUser->getEmailNotification(), $this->oPage, false); + $edit_fields[] = new KTStringWidget(_('Mobile Number'),_("The mobile phone number of the user. If the system is configured to send notifications to cellphones, then this number will be SMS'd with notifications. e.g. 999 9999 999"), 'mobile_number', $oUser->getMobile(), $this->oPage, false); + $edit_fields[] = new KTStringWidget(_('Maximum Sessions'), _('As a safety precaution, it is useful to limit the number of times a given account can log in, before logging out. This prevents a single account being used by many different people.'), 'max_sessions', $oUser->getMaxSessions(), $this->oPage, true); + + $oAuthenticationSource = KTAuthenticationSource::getForUser($oUser); + if (is_null($oAuthenticationSource)) { + $oProvider =& new KTBuiltinAuthenticationProvider; + } else { + $sProvider = $oAuthenticationSource->getAuthenticationProvider(); + $oRegistry =& KTAuthenticationProviderRegistry::getSingleton(); + $oProvider = $oRegistry->getAuthenticationProvider($sProvider); + } + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/edituser"); + $aTemplateData = array( + "context" => $this, + "edit_fields" => $edit_fields, + "edit_user" => $oUser, + "provider" => $oProvider, + "source" => $oAuthenticationSource, + ); + return $oTemplate->render($aTemplateData); + } + + + function do_setPassword() { + $this->aBreadcrumbs[] = array('action' => 'userManagement', 'name' => _('User Management')); + $this->oPage->setBreadcrumbDetails(_('change user password')); + $this->oPage->setTitle(_("Change User Password")); + + $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); + $oUser =& User::get($user_id); + + if (PEAR::isError($oUser) || $oUser == false) { + $this->errorRedirectToMain(_('Please select a user first.')); + exit(0); + } + + $this->aBreadcrumbs[] = array('name' => $oUser->getName()); + + $edit_fields = array(); + $edit_fields[] = new KTPasswordWidget(_('Password'),_('Specify an initial password for the user.'), 'password', null, $this->oPage, true); + $edit_fields[] = new KTPasswordWidget(_('Confirm Password'),_('Confirm the password specified above.'), 'confirm_password', null, $this->oPage, true); + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/updatepassword"); + $aTemplateData = array( + "context" => $this, + "edit_fields" => $edit_fields, + "edit_user" => $oUser, + ); + return $oTemplate->render($aTemplateData); + } + + function do_updatePassword() { + $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); + + $password = KTUtil::arrayGet($_REQUEST, 'password'); + $confirm_password = KTUtil::arrayGet($_REQUEST, 'confirm_password'); + + if (empty($password)) { + $this->errorRedirectToMain(_("You must specify a password for the user.")); + } else if ($password !== $confirm_password) { + $this->errorRedirectToMain(_("The passwords you specified do not match.")); + } + // FIXME more validation would be useful. + // validated and ready.. + $this->startTransaction(); + + $oUser =& User::get($user_id); + if (PEAR::isError($oUser) || $oUser == false) { + $this->errorRedirectToMain(_("Please select a user to modify first.")); + } + + + // FIXME this almost certainly has side-effects. do we _really_ want + $oUser->setPassword(md5($password)); // + + $res = $oUser->update(); + //$res = $oUser->doLimitedUpdate(); // ignores a fix blacklist of items. + + + if (PEAR::isError($res) || ($res == false)) { + $this->errorRedirectoToMain(_('Failed to update user.')); + } + + $this->commitTransaction(); + $this->successRedirectToMain(_('User information updated.')); + + } + + function do_editUserSource() { + $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); + $oUser =& $this->oValidator->validateUser($user_id); + $this->aBreadcrumbs[] = array('name' => $oUser->getName()); + + $oAuthenticationSource = KTAuthenticationSource::getForUser($oUser); + if (is_null($oAuthenticationSource)) { + $oProvider =& new KTBuiltinAuthenticationProvider; + } else { + $sProvider = $oAuthenticationSource->getAuthenticationProvider(); + $oRegistry =& KTAuthenticationProviderRegistry::getSingleton(); + $oProvider = $oRegistry->getAuthenticationProvider($sProvider); + } + + $oProvider->dispatch(); + exit(); + } + + function do_editgroups() { + $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); + $oUser = User::get($user_id); + if ((PEAR::isError($oUser)) || ($oUser === false)) { + $this->errorRedirectToMain(_('No such user.')); + } + + $this->aBreadcrumbs[] = array('name' => $oUser->getName()); + $this->oPage->setBreadcrumbDetails(_('edit groups')); + $this->oPage->setTitle(sprintf(_("Edit %s's groups"), $oUser->getName())); + // generate a list of groups this user is authorised to assign. + + /* FIXME there is a nasty side-effect: if a user cannot assign a group + * to a user, and that user _had_ that group pre-edit, + * then their privilidges are revoked. + * is there _any_ way to fix that? + */ + + // FIXME move this to a transfer widget + // FIXME replace OptionTransfer.js. me no-likey. + + // FIXME this is hideous. refactor the transfer list stuff completely. + $initJS = 'var optGroup = new OptionTransfer("groupSelect[]","chosenGroups[]"); ' . + 'function startTrans() { var f = getElement("usergroupform"); ' . + ' optGroup.saveAddedRightOptions("groupAdded"); ' . + ' optGroup.saveRemovedRightOptions("groupRemoved"); ' . + ' optGroup.init(f); }; ' . + ' addLoadEvent(startTrans); '; + $this->oPage->requireJSStandalone($initJS); + + $aInitialGroups = GroupUtil::listGroupsForUser($oUser); + $aAllGroups = GroupUtil::listGroups(); + + $aUserGroups = array(); + $aFreeGroups = array(); + foreach ($aInitialGroups as $oGroup) { + $aUserGroups[$oGroup->getId()] = $oGroup; + } + foreach ($aAllGroups as $oGroup) { + if (!array_key_exists($oGroup->getId(), $aUserGroups)) { + $aFreeGroups[$oGroup->getId()] = $oGroup; + } + } + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/principals/usergroups"); + $aTemplateData = array( + "context" => $this, + "unused_groups" => $aFreeGroups, + "user_groups" => $aUserGroups, + "edit_user" => $oUser, + ); + return $oTemplate->render($aTemplateData); + } + + function do_saveUser() { + $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); + + $name = KTUtil::arrayGet($_REQUEST, 'name'); + $username = KTUtil::arrayGet($_REQUEST, 'username'); + $email_address = KTUtil::arrayGet($_REQUEST, 'email_address'); + $email_notifications = KTUtil::arrayGet($_REQUEST, 'email_notifications', false); + if ($email_notifications !== false) $email_notifications = true; + $mobile_number = KTUtil::arrayGet($_REQUEST, 'mobile_number'); + $max_sessions = KTUtil::arrayGet($_REQUEST, 'max_sessions', '3'); + // FIXME more validation would be useful. + // validated and ready.. + $this->startTransaction(); + + $oUser =& User::get($user_id); + if (PEAR::isError($oUser) || $oUser == false) { + $this->errorRedirectToMain(_("Please select a user to modify first.")); + } + + $oUser->setName($name); + $oUser->setUsername($username); // ? + $oUser->setEmail($email_address); + $oUser->setEmailNotification($email_notifications); + $oUser->setMobile($mobile_number); + $oUser->setMaxSessions($max_sessions); + + // old system used the very evil store.php. + // here we need to _force_ a limited update of the object, via a db statement. + // + // $res = $oUser->update(); + $res = $oUser->doLimitedUpdate(); // ignores a fix blacklist of items. + + + + if (PEAR::isError($res) || ($res == false)) { + $this->errorRedirectoToMain(_('Failed to update user.')); + } + + $this->commitTransaction(); + $this->successRedirectToMain(_('User information updated.')); + } + + function do_createUser() { + // FIXME generate and pass the error stack to adduser. + + $name = KTUtil::arrayGet($_REQUEST, 'name'); + if (empty($name)) { $this->errorRedirectToMain(_('You must specify a name for the user.')); } + $username = KTUtil::arrayGet($_REQUEST, 'username'); + if (empty($name)) { $this->errorRedirectToMain(_('You must specify a new username.')); } + // FIXME check for non-clashing usernames. + + $email_address = KTUtil::arrayGet($_REQUEST, 'email_address'); + $email_notifications = KTUtil::arrayGet($_REQUEST, 'email_notifications', false); + if ($email_notifications !== false) $email_notifications = true; + $mobile_number = KTUtil::arrayGet($_REQUEST, 'mobile_number'); + $max_sessions = KTUtil::arrayGet($_REQUEST, 'max_sessions', '3'); + // FIXME check for numeric max_sessions... db-error else? + $password = KTUtil::arrayGet($_REQUEST, 'password'); + $confirm_password = KTUtil::arrayGet($_REQUEST, 'confirm_password'); + + if (empty($password)) { + $this->errorRedirectToMain(_("You must specify a password for the user.")); + } else if ($password !== $confirm_password) { + $this->errorRedirectToMain(_("The passwords you specified do not match.")); + } + + $oUser =& User::createFromArray(array( + "sUsername" => $username, + "sName" => $name, + "sPassword" => md5($password), + "iQuotaMax" => 0, + "iQuotaCurrent" => 0, + "sEmail" => $email_address, + "bEmailNotification" => $email_notifications, + "bSmsNotification" => false, // FIXME do we auto-act if the user has a mobile? + "iMaxSessions" => $max_sessions, + )); + + if (PEAR::isError($oUser) || ($oUser == false)) { + $this->errorRedirectToMain(_("failed to create user.")); + exit(0); + } + + $oUser->create(); + + $this->successRedirectToMain(_('Created new user') . ': "' . $oUser->getUsername() . '"'); + } + + function do_deleteUser() { + $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); + $oUser = User::get($user_id); + if ((PEAR::isError($oUser)) || ($oUser === false)) { + $this->errorRedirectToMain(_('Please select a user first.')); + } + $oUser->delete(); + + $this->successRedirectToMain(_('User deleted') . ': ' . $oUser->getName()); + } + + function do_updateGroups() { + $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); + $oUser = User::get($user_id); + if ((PEAR::isError($oUser)) || ($oUser === false)) { + $this->errorRedirectToMain(_('Please select a user first.')); + } + $groupAdded = KTUtil::arrayGet($_REQUEST, 'groupAdded',''); + $groupRemoved = KTUtil::arrayGet($_REQUEST, 'groupRemoved',''); + + + $aGroupToAddIDs = explode(",", $groupAdded); + $aGroupToRemoveIDs = explode(",", $groupRemoved); + + // FIXME we need to ensure that only groups which are allocatable by the admin are added here. + + // FIXME what groups are _allocatable_? + + $this->startTransaction(); + $groupsAdded = array(); + $groupsRemoved = array(); + + foreach ($aGroupToAddIDs as $iGroupID ) { + if ($iGroupID > 0) { + $oGroup = Group::get($iGroupID); + $res = $oGroup->addMember($oUser); + if (PEAR::isError($res) || $res == false) { + $this->errorRedirectToMain(sprintf(_('Unable to add user to group "%s"'), $oGroup->getName())); + } else { $groupsAdded[] = $oGroup->getName(); } + } + } + + // Remove groups + foreach ($aGroupToRemoveIDs as $iGroupID ) { + if ($iGroupID > 0) { + $oGroup = Group::get($iGroupID); + $res = $oGroup->removeMember($oUser); + if (PEAR::isError($res) || $res == false) { + $this->errorRedirectToMain(sprintf(_('Unable to remove user from group "%s"'), $oGroup->getName())); + } else { $groupsRemoved[] = $oGroup->getName(); } + } + } + + $msg = ''; + if (!empty($groupsAdded)) { $msg .= ' ' . _('Added to groups') . ': ' . join(', ', $groupsAdded) . ',
'; } + if (!empty($groupsRemoved)) { $msg .= ' ' . _('Removed from groups') . ': ' . join(', ',$groupsRemoved) . '.'; } + + $this->commitTransaction(); + $this->successRedirectToMain($msg); + } + +} + +//$oDispatcher = new KTUserAdminDispatcher (); +//$oDispatcher->dispatch(); + +?> diff --git a/plugins/ktcore/admin/workflows.php b/plugins/ktcore/admin/workflows.php new file mode 100755 index 0000000..03b1112 --- /dev/null +++ b/plugins/ktcore/admin/workflows.php @@ -0,0 +1,492 @@ +aBreadcrumbs[] = array( + 'action' => 'manageWorkflows', + 'name' => _('Workflows'), + ); + + $add_fields = array(); + $add_fields[] = new KTStringWidget(_('Name'),_('A human-readable name for the workflow.'), 'fName', null, $this->oPage, true); + + $oTemplating =& KTTemplating::getSingleton(); + $oTemplate =& $oTemplating->loadTemplate('ktcore/workflow/listWorkflows'); + $oTemplate->setData(array( + 'context' => $this, + 'aWorkflow' => KTWorkflow::getList(), + 'add_fields' => $add_fields, + )); + return $oTemplate; + } + // }}} + + // {{{ do_editWorkflow + function do_editWorkflow() { + + $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/editWorkflow'); + $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); + + $aStates = KTWorkflowState::getByWorkflow($oWorkflow); + $aPermissions = KTPermission::getList(); + + $edit_fields = array(); + $edit_fields[] = new KTStringWidget(_('Name'), _('A human-readable name for the workflow.'), 'fName', $oWorkflow->getName(), $this->oPage, true); + $aOptions = array(); + $vocab = array(); + $vocab[0] = 'None'; + foreach($aStates as $state) { + $vocab[$state->getId()] = $state->getName(); + } + $aOptions['vocab'] = $vocab; + $edit_fields[] = new KTLookupWidget(_('Starting State'), _('When a document has this workflow applied to it, to which state should it initially be set'), 'fStartStateId', $oWorkflow->getStartStateId(), $this->oPage, false, null, null, $aOptions); + + $add_state_fields = array(); + $add_state_fields[] = new KTStringWidget(_('Name'), _('A human-readable name for the state.'), 'fName', null, $this->oPage, true); + + + $add_transition_fields = array(); + $add_transition_fields[] = new KTStringWidget(_('Name'), _('A human-readable name for the state.'), 'fName', null, $this->oPage, true); + $aOptions = array(); + $vocab = array(); + foreach($aStates as $state) { + $vocab[$state->getId()] = $state->getName(); + } + $aOptions['vocab'] = $vocab; + $add_transition_fields[] = new KTLookupWidget(_('Destination State'), _('Once this transition is complete, which state should the document be in?'), 'fTargetStateId', $oWorkflow->getStartStateId(), $this->oPage, true, null, null, $aOptions); + $aOptions = array(); + $vocab = array(); + foreach($aPermissions as $permission) { + $vocab[$permission->getId()] = $permission->getHumanName(); + } + $aOptions['vocab'] = $vocab; + $add_transition_fields[] = new KTLookupWidget(_('Guard Permission.'), _('Which permission must the user have in order to follow this transition?'), 'fPermissionId', $oWorkflow->getStartStateId(), $this->oPage, true, null, null, $aOptions); + + $this->aBreadcrumbs[] = array( + 'action' => 'manageWorkflows', + 'name' => _('Workflows'), + ); + $this->aBreadcrumbs[] = array( + 'action' => 'manageWorkflows', + 'query' => 'action=editWorkflow&fWorkflowId=' . $oWorkflow->getId(), + 'name' => $oWorkflow->getName(), + ); + $oTemplate->setData(array( + 'oWorkflow' => $oWorkflow, + 'aStates' => $aStates, + 'aTransitions' => KTWorkflowTransition::getByWorkflow($oWorkflow), + 'aPermissions' => $aPermissions, + 'aActions' => KTDocumentActionUtil::getAllDocumentActions(), + 'aActionsSelected' => KTWorkflowUtil::getControlledActionsForWorkflow($oWorkflow), + + // fields + 'edit_fields' => $edit_fields, + 'add_state_fields' => $add_state_fields, + 'add_transition_fields' => $add_transition_fields, + )); + return $oTemplate; + } + // }}} + + // {{{ do_saveWorkflow + function do_saveWorkflow() { + $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); + $aOptions = array( + 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()), + ); + $oWorkflow->setName($_REQUEST['fName']); + $oWorkflow->setHumanName($_REQUEST['fName']); + if (!empty($_REQUEST['fStartStateId'])) { + $oWorkflow->setStartStateId($_REQUEST['fStartStateId']); + } else { + $oWorkflow->setStartStateId(null); + } + $res = $oWorkflow->update(); + $this->oValidator->notErrorFalse($res, array( + 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()), + 'message' => _('Error saving workflow'), + )); + $this->successRedirectTo('editWorkflow', _('Changes saved'), 'fWorkflowId=' . $oWorkflow->getId()); + exit(0); + } + // }}} + + // {{{ do_newWorkflow + function do_newWorkflow() { + $res = KTWorkflow::createFromArray(array( + 'name' => $_REQUEST['fName'], + 'humanname' => $_REQUEST['fName'], + )); + $this->oValidator->notError($res, array( + 'redirect_to' => array('main'), + 'message' => _('Could not create workflow'), + )); + $this->successRedirectTo('editWorkflow', _('Workflow created'), 'fWorkflowId=' . $res->getId()); + exit(0); + } + // }}} + + // {{{ do_setWorkflowActions + function do_setWorkflowActions() { + $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); + $res = KTWorkflowUtil::setControlledActionsForWorkflow($oWorkflow, $_REQUEST['fActions']); + $this->oValidator->notErrorFalse($res, array( + 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()), + 'message' => _('Error saving workflow controlled actions'), + )); + $this->successRedirectTo('editWorkflow', _('Changes saved'), 'fWorkflowId=' . $oWorkflow->getId()); + exit(0); + } + // }}} + + // }}} + + // {{{ STATE HANDLING + // + // {{{ do_newState + function do_newState() { + $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); + $oState = KTWorkflowState::createFromArray(array( + 'workflowid' => $oWorkflow->getId(), + 'name' => $_REQUEST['fName'], + 'humanname' => $_REQUEST['fName'], + )); + $this->oValidator->notError($oState, array( + 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()), + 'message' => _('Could not create workflow state'), + )); + $this->successRedirectTo('editState', _('Workflow state created'), 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()); + exit(0); + } + // }}} + + // {{{ do_editState + function do_editState() { + $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/editState'); + $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); + $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fStateId']); + $aTransitionsTo =& KTWorkflowTransition::getByTargetState($oState); + $aTransitionIdsTo = array(); + foreach ($aTransitionsTo as $oTransition) { + $aTransitionIdsTo[] = $oTransition->getId(); + } + $aAllTransitions =& KTWorkflowTransition::getByWorkflow($oWorkflow); + $aTransitions = array(); + foreach ($aAllTransitions as $oTransition) { + if (!in_array($oTransition->getId(), $aTransitionIdsTo)) { + $aTransitions[] = $oTransition; + } + } + $aTransitionsSelected = KTWorkflowUtil::getTransitionsFrom($oState, array('ids' => true)); + $this->aBreadcrumbs[] = array( + 'action' => 'manageWorkflows', + 'name' => _('Workflows'), + ); + $this->aBreadcrumbs[] = array( + 'action' => 'manageWorkflows', + 'query' => 'action=editWorkflow&fWorkflowId=' . $oWorkflow->getId(), + 'name' => $oWorkflow->getName(), + ); + $this->oPage->setBreadcrumbDetails(_('state') . ': ' . $oState->getName()); + + $aInformed = KTWorkflowUtil::getInformedForState($oState); + $oTemplate->setData(array( + 'oWorkflow' => $oWorkflow, + 'oState' => $oState, + 'oNotifyRole' => $oRole, + 'aTransitionsTo' => $aTransitionsTo, + 'aTransitions' => $aTransitions, + 'aTransitionsSelected' => $aTransitionsSelected, + 'aActions' => KTDocumentActionUtil::getDocumentActionsByNames(KTWorkflowUtil::getControlledActionsForWorkflow($oWorkflow)), + 'aActionsSelected' => KTWorkflowUtil::getEnabledActionsForState($oState), + 'aGroups' => Group::getList(), + 'aRoles' => Role::getList(), + 'aUsers' => User::getList(), + 'aInformed' => $aInformed, + )); + return $oTemplate; + } + // }}} + + // {{{ do_saveState + function do_saveState() { + $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); + $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fStateId']); + $oState->setName($_REQUEST['fName']); + $oState->setHumanName($_REQUEST['fName']); + $res = $oState->update(); + $this->oValidator->notErrorFalse($res, array( + 'redirect_to' => array('editState', 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()), + 'message' => _('Error saving state'), + )); + $this->successRedirectTo('editState', _('Changes saved'), 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()); + exit(0); + } + // }}} + + // {{{ do_saveTransitions + function do_saveTransitions() { + $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); + $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fStateId']); + $res = KTWorkflowUtil::saveTransitionsFrom($oState, $_REQUEST['fTransitionIds']); + $this->oValidator->notErrorFalse($res, array( + 'redirect_to' => array('editState', 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()), + 'message' => _('Error saving transitions'), + )); + $this->successRedirectTo('editState', _('Changes saved'), 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()); + exit(0); + } + // }}} + + // {{{ do_setStateActions + function do_setStateActions() { + $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); + $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fStateId']); + $res = KTWorkflowUtil::setEnabledActionsForState($oState, $_REQUEST['fActions']); + $this->oValidator->notErrorFalse($res, array( + 'redirect_to' => array('editState', 'fWorkflowId=' . $oWorkflow->getId(), '&fStateId=' . $oState->getId()), + 'message' => _('Error saving state enabled actions'), + )); + $this->successRedirectTo('editState', _('Actions set'), 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()); + exit(0); + } + // }}} + + // {{{ do_saveInform + function do_saveInform() { + $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); + $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fStateId']); + $sTargetAction = 'editState'; + $sTargetParams = 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId(); + $aRoleIds = KTUtil::arrayGet($_REQUEST, 'fRoleIds'); + if (empty($aRoleIds)) { + $aRoleIds = array(); + } + if (!is_array($aRoleIds)) { + $this->errorRedirectTo($sTargetAction, _('Invalid roles specified'), $sTargetParams); + } + $aGroupIds = KTUtil::arrayGet($_REQUEST, 'fGroupIds'); + if (empty($aGroupIds)) { + $aGroupIds = array(); + } + if (!is_array($aGroupIds)) { + $this->errorRedirectTo($sTargetAction, _('Invalid groups specified'), $sTargetParams); + } + $aUserIds = KTUtil::arrayGet($_REQUEST, 'fUserIds'); + if (empty($aUserIds)) { + $aUserIds = array(); + } + if (!is_array($aUserIds)) { + $this->errorRedirectTo($sTargetAction, _('Invalid users specified'), $sTargetParams); + } + $aAllowed = array( + 'role' => $aRoleIds, + 'group' => $aGroupIds, + 'user' => $aUserIds, + ); + KTWorkflowUtil::setInformedForState($oState, $aAllowed); + $this->successRedirectTo($sTargetAction, _('Changes saved'), $sTargetParams); + } + // }}} + + // }}} + + // {{{ TRANSITION HANDLING + // + // {{{ do_newTransition + function do_newTransition() { + $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); + $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fTargetStateId']); + $iPermissionId = KTUtil::arrayGet($_REQUEST, 'fPermissionId'); + $iGroupId = KTUtil::arrayGet($_REQUEST, 'fGroupId'); + $iRoleId = KTUtil::arrayGet($_REQUEST, 'fRoleId'); + if ($iPermissionId) { + $this->oValidator->validatePermission($_REQUEST['fPermissionId']); + } + if ($iGroupId) { + $this->oValidator->validateGroup($_REQUEST['fGroupId']); + } + if ($iRoleId) { + $this->oValidator->validateRole($_REQUEST['fRoleId']); + } + $res = KTWorkflowTransition::createFromArray(array( + 'workflowid' => $oWorkflow->getId(), + 'name' => $_REQUEST['fName'], + 'humanname' => $_REQUEST['fName'], + 'targetstateid' => $oState->getId(), + 'guardpermissionid' => $iPermissionId, + 'guardgroupid' => $iGroupId, + 'guardroleid' => $iRoleId, + )); + $this->oValidator->notError($res, array( + 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()), + 'message' => _('Could not create workflow transition'), + )); + $this->successRedirectTo('editWorkflow', _('Workflow transition created'), 'fWorkflowId=' . $oWorkflow->getId()); + exit(0); + } + // }}} + + // {{{ do_editTransition + function do_editTransition() { + $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/editTransition'); + $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); + $oTransition =& $this->oValidator->validateWorkflowTransition($_REQUEST['fTransitionId']); + + $aStates = KTWorkflowState::getByWorkflow($oWorkflow); + $aPermissions = KTPermission::getList(); + $aGroups = Group::getList(); + $aRoles = Role::getList(); + $aConditions = KTSavedSearch::getConditions(); + + $edit_fields = array(); + $edit_fields[] = new KTStringWidget(_('Name'), _('A human-readable name for the state.'), 'fName', $oTransition->getName(), $this->oPage, true); + $aOptions = array(); + $vocab = array(); + foreach($aStates as $state) { + $vocab[$state->getId()] = $state->getName(); + } + $aOptions['vocab'] = $vocab; + $edit_fields[] = new KTLookupWidget(_('Destination State'), _('Once this transition is complete, which state should the document be in?'), 'fTargetStateId', $oTransition->getTargetStateId(), $this->oPage, true, null, null, $aOptions); + $aOptions = array(); + $vocab = array(); + $vocab[0] = 'None'; + foreach($aPermissions as $permission) { + $vocab[$permission->getId()] = $permission->getHumanName(); + } + $aOptions['vocab'] = $vocab; + $edit_fields[] = new KTLookupWidget(_('Guard Permission.'), _('Which permission must the user have in order to follow this transition?'), 'fPermissionId', $oTransition->getGuardPermissionId(), $this->oPage, true, null, null, $aOptions); + $aOptions = array(); + $vocab = array(); + $vocab[0] = 'None'; + foreach($aGroups as $group) { + $vocab[$group->getId()] = $group->getName(); + } + $aOptions['vocab'] = $vocab; + $edit_fields[] = new KTLookupWidget(_('Guard Group.'), _('Which group must the user belong to in order to follow this transition?'), 'fGroupId', $oTransition->getGuardGroupId(), $this->oPage, false, null, null, $aOptions); + $aOptions = array(); + $vocab = array(); + $vocab[0] = 'None'; + foreach($aRoles as $role) { + $vocab[$role->getId()] = $role->getName(); + } + $aOptions['vocab'] = $vocab; + $edit_fields[] = new KTLookupWidget(_('Guard Role.'), _('Which role must the user have in order to follow this transition?'), 'fRoleId', $oTransition->getGuardRoleId(), $this->oPage, false, null, null, $aOptions); + + if (!empty($aConditions)) { + $aOptions = array(); + $vocab = array(); + $vocab[0] = 'None'; + foreach($aConditions as $condition) { + $vocab[$condition->getId()] = $condition->getName(); + } + $aOptions['vocab'] = $vocab; + $edit_fields[] = new KTLookupWidget(_('Guard Condition.'), _('Which condition (stored search) must be satisfied before the transition can take place?'), 'fConditionId', $oTransition->getGuardConditionId(), $this->oPage, false, null, null, $aOptions); + } + + $this->aBreadcrumbs[] = array( + 'action' => 'manageWorkflows', + 'name' => _('Workflows'), + ); + $this->aBreadcrumbs[] = array( + 'action' => 'manageWorkflows', + 'query' => 'action=editWorkflow&fWorkflowId=' . $oWorkflow->getId(), + 'name' => $oWorkflow->getName(), + ); + $this->aBreadcrumbs[] = array( + 'action' => 'manageWorkflows', + 'query' => 'action=editTransition&fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId(), + 'name' => $oTransition->getName(), + ); + $oTemplate->setData(array( + 'oWorkflow' => $oWorkflow, + 'oTransition' => $oTransition, + 'aStates' => $aStates, + 'aPermissions' => $aPermissions, + 'aGroups' => $aGroups, + 'aRoles' => $aRoles, + 'aConditions' => $aConditions, + + // fields + + 'edit_fields' => $edit_fields, + )); + return $oTemplate; + } + // }}} + + // {{{ do_saveTransition + function do_saveTransition() { + $aRequest = $this->oValidator->validateDict($_REQUEST, array( + 'fWorkflowId' => array('type' => 'workflow'), + 'fTransitionId' => array('type' => 'workflowtransition'), + )); + $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); + $oTransition =& $this->oValidator->validateWorkflowTransition($_REQUEST['fTransitionId']); + $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fTargetStateId']); + $iPermissionId = KTUtil::arrayGet($_REQUEST, 'fPermissionId', null); + $iGroupId = KTUtil::arrayGet($_REQUEST, 'fGroupId', null); + $iRoleId = KTUtil::arrayGet($_REQUEST, 'fRoleId', null); + $iConditionId = KTUtil::arrayGet($_REQUEST, 'fConditionId', null); + if ($iPermissionId) { + $this->oValidator->validatePermission($_REQUEST['fPermissionId']); + } + if ($iGroupId) { + $this->oValidator->validateGroup($_REQUEST['fGroupId']); + } + if ($iRoleId) { + $this->oValidator->validateRole($_REQUEST['fRoleId']); + } + if ($iConditionId) { + $this->oValidator->validateCondition($_REQUEST['fConditionId']); + } + $oTransition->updateFromArray(array( + 'workflowid' => $oWorkflow->getId(), + 'name' => $_REQUEST['fName'], + 'humanname' => $_REQUEST['fName'], + 'targetstateid' => $oState->getId(), + 'guardpermissionid' => $iPermissionId, + 'guardgroupid' => $iGroupId, + 'guardroleid' => $iRoleId, + 'guardconditionid' => $iConditionId, + )); + $res = $oTransition->update(); + $this->oValidator->notErrorFalse($res, array( + 'redirect_to' => array('editTransition', 'fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId()), + 'message' => _('Error saving transition'), + )); + $this->successRedirectTo('editTransition', _('Changes saved'), 'fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId()); + exit(0); + } + // }}} + + // }}} + +} + +//$d =& new KTWorkflowDispatcher; +//$d->dispatch(); + +?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/doccheckoutmanagement/documentCheckout.php b/presentation/lookAndFeel/knowledgeTree/administration/doccheckoutmanagement/documentCheckout.php deleted file mode 100644 index d83b14b..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/doccheckoutmanagement/documentCheckout.php +++ /dev/null @@ -1,128 +0,0 @@ -, Jam Warehouse (Pty) Ltd, South Africa - * @package documentmanagement - */ - -/* boilerplate */ - - -require_once(KT_LIB_DIR . '/dispatcher.inc.php'); -require_once(KT_LIB_DIR . '/templating/kt3template.inc.php'); - - -class KTCheckoutAdminDispatcher extends KTAdminDispatcher { - - function check() { - return true; - } - - function do_main() { - $this->aBreadcrumbs[] = array('name' => _('Document Checkout')); - $this->oPage->setBreadcrumbDetails(_("list checked out documents")); - - $aDocuments = Document::getList("is_checked_out = 1"); - - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/checkoutlisting'); - $oTemplate->setData(array( - "context" => $this, - "documents" => $aDocuments, - )); - return $oTemplate; - } - - - function do_confirm() { - $this->aBreadcrumbs[] = array('name' => _('Document Checkout')); - $this->oPage->setBreadcrumbDetails(_("confirm forced check-in")); - - $document_id = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); - if (empty($document_id)) { - return $this->errorRedirectToMain(_('You must select a document to check in first.')); - } - - $oDocument = Document::get($document_id); - if (PEAR::isError($oDocument)) { - return $this->errorRedirectToMain(_('The document you specified appears to be invalid.')); - } - - $oUser = User::get($oDocument->getCheckedOutUserID()); - // unusually, we could well have an error here: the user may have checked out and then - // been deleted. - if (PEAR::isError($oUser) || ($oUser === false)) { - $oUser = null; - } - - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/force_checkin_confirm'); - $oTemplate->setData(array( - "context" => $this, - "document" => $oDocument, - "checkout_user" => $oUser, - )); - return $oTemplate; - - } - - function do_checkin() { - global $default; - - $document_id = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); - if (empty($document_id)) { - return $this->errorRedirectToMain(_('You must select a document to check in first.')); - } - - $oDocument = Document::get($document_id); - if (PEAR::isError($oDocument)) { - return $this->errorRedirectToMain(_('The document you specified appears to be invalid.')); - } - - $this->startTransaction(); - // actually do the checkin. - $oDocument->setIsCheckedOut(0); - $oDocument->setCheckedOutUserID(-1); - if (!$oDocument->update()) { - $this->rollbackTransaction(); - return $this->errorRedirectToMain(_("Failed to force the document's checkin.")); - } - - // checkout cancelled transaction - $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), "Document checked out cancelled", FORCE_CHECKIN); - if ($oDocumentTransaction->create()) { - $default->log->debug("editDocCheckoutBL.php created forced checkin document transaction for document ID=" . $oDocument->getID()); - } else { - $default->log->error("editDocCheckoutBL.php couldn't create create document transaction for document ID=" . $oDocument->getID()); - } - $this->commitTransaction(); // FIXME do we want to do this if we can't created the document-transaction? - return $this->successRedirectToMain(sprintf(_('Successfully forced "%s" to be checked in.'), $oDocument->getName())); - } - - -} - -// use the new admin framework. -//$d = new KTCheckoutAdminDispatcher(); -//$d->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxComplexConditionals.php b/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxComplexConditionals.php deleted file mode 100644 index 69404aa..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxComplexConditionals.php +++ /dev/null @@ -1,196 +0,0 @@ -oValidator->validateFieldset(KTUtil::arrayGet($_REQUEST, 'fieldset_id')); - $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); - $oField =& $this->oValidator->validateField(KTUtil::arrayGet($_REQUEST, 'field_id')); - - header('Content-type: application/xml'); - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_get_item_list'); - - $aValues = array(); - foreach ($oField->getValues() as $oValue) { - if (empty($parent_behaviour)) { - $oInstance = KTValueInstance::getByLookupSingle($oValue); - if (empty($oInstance)) { - $aValues[$oValue->getId()] = $oValue->getName(); - } - // No parent behaviour (thus master column), so any - // instance will do to prevent showing this value - continue; - } - - $iInstanceId = KTValueInstance::getByLookupAndParentBehaviour($oValue, $parent_behaviour, array('ids' => true)); - if (empty($iInstanceId)) { - $aValues[$oValue->getId()] = $oValue->getName(); - } - } - $aData = array( - 'values' => $aValues, - ); - $oTemplate->setData($aData); - - return $oTemplate->render(); - } - - function do_getBehaviourList() { - $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour'); - $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); - $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); - - $aBehaviours =& KTFieldBehaviour::getByField($field_id); - - header('Content-type: application/xml'); - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_get_behaviour_list'); - $oTemplate->setData(array( - 'aBehaviours' => $aBehaviours, - )); - return $oTemplate->render(); - } - - function do_getActiveFields() { - $GLOBALS['default']->log->error(print_r($_REQUEST, true)); - $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour'); - // $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); // - $oFieldset =& $this->oValidator->validateFieldset(KTUtil::arrayGet($_REQUEST, 'fieldset_id')); - - if (empty($parent_behaviour)) { - $aFieldIds = array($oFieldset->getMasterFieldId()); - } else { - $oBehaviour =& $this->oValidator->validateBehaviour($parent_behaviour); - $iActiveFieldId = $oBehaviour->getFieldId(); - $aFieldIds = KTMetadataUtil::getChildFieldIds($iActiveFieldId); - } - - $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/conditional/ajax_complex_get_active_fields'); - $oTemplate->setData(array( - 'aFieldIds' => $aFieldIds, - )); - $GLOBALS['default']->log->error(print_r(KTMetadataUtil::getChildFieldIds($iActiveFieldId), true)); - - header('Content-type: application/xml'); - /// header('Content-type: text/plain'); - return $oTemplate->render(); - } - - /** storage methods */ - function do_createBehaviourAndAssign() { - $GLOBALS['default']->log->error(print_r($_REQUEST, true)); - $GLOBALS['default']->log->error(print_r($_SESSION, true)); - $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour'); - $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); - $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); - $behaviour_name = KTUtil::arrayGet($_REQUEST, 'behaviour_name'); - $lookups_to_assign = KTUtil::arrayGet($_REQUEST, 'lookups_to_assign'); // array - - $oBehaviour =& KTFieldBehaviour::createFromArray(array( - 'name' => $behaviour_name, - 'humanname' => $behaviour_name, - 'fieldid' => $field_id, - )); - - $aValueInstanceIds = array(); - foreach ($lookups_to_assign as $iLookupId) { - $res = $oValueInstance =& KTValueInstance::createFromArray(array( - 'fieldid' => $field_id, - 'behaviourid' => $oBehaviour->getId(), - 'fieldvalueid' => abs($iLookupId), - )); - $aValueInstanceIds[] = $res->getId(); - } - - if ($parent_behaviour) { - $oParentBehaviour =& $this->oValidator->validateBehaviour($parent_behaviour); - $sTable = KTUtil::getTableName('field_behaviour_options'); - $aOptions = array('noid' => true); - foreach ($aValueInstanceIds as $iId) { - $res = DBUtil::autoInsert($sTable, array( - 'behaviour_id' => $oParentBehaviour->getId(), - 'field_id' => $field_id, - 'instance_id' => $iId, - ), $aOptions); - } - } - - header('Content-type: application/xml'); - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_create_behaviour_and_assign'); - return $oTemplate->render(); - } - - function do_useBehaviourAndAssign() { - $parent_behaviour = KTUtil::arrayGet($_REQUEST, 'parent_behaviour'); - $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); - $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); - $behaviour_id = KTUtil::arrayGet($_REQUEST, 'behaviour_id'); - $lookups_to_assign = KTUtil::arrayGet($_REQUEST, 'lookups_to_assign'); // array - - $oBehaviour =& $this->oValidator->validateBehaviour($behaviour_id); - - $aValueInstanceIds = array(); - foreach ($lookups_to_assign as $iLookupId) { - $res = $oValueInstance =& KTValueInstance::createFromArray(array( - 'fieldid' => $field_id, - 'behaviourid' => $oBehaviour->getId(), - 'fieldvalueid' => abs($iLookupId), - )); - $aValueInstanceIds[] = $res->getId(); - } - - if ($parent_behaviour) { - $oParentBehaviour =& $this->oValidator->validateBehaviour($parent_behaviour); - $sTable = KTUtil::getTableName('field_behaviour_options'); - $aOptions = array('noid' => true); - foreach ($aValueInstanceIds as $iId) { - $res = DBUtil::autoInsert($sTable, array( - 'behaviour_id' => $oParentBehaviour->getId(), - 'field_id' => $field_id, - 'instance_id' => $iId, - ), $aOptions); - } - } - - header('Content-type: application/xml'); - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_complex_use_behaviour_and_assign'); - return $oTemplate->render(); - } - - -} - -$oDispatcher = new AjaxConditionalAdminDispatcher(); -$oDispatcher->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxSimpleConditionals.php b/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxSimpleConditionals.php deleted file mode 100644 index 056354f..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/ajaxSimpleConditionals.php +++ /dev/null @@ -1,141 +0,0 @@ -log->error(http_build_query($_REQUEST)); - $iFieldsetId = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); - $parent_field = KTUtil::arrayGet($_REQUEST, 'parent_field'); - $parent_lookup = KTUtil::arrayGet($_REQUEST, 'parent_lookup'); - $child_lookups = KTUtil::arrayGet($_REQUEST, 'child_lookups'); - - // child lookups is a nested array. in python it would be: - // child_lookups = - // { - // field_id:[lookup_id, lookup_id], - // field_id:[lookup_id, lookup_id], - // } - - $oFieldset =& KTFieldset::get($iFieldsetId); - $oFieldset->setIsComplete(false); - $oFieldset->update(); - - $oParentInstance = KTMetadataUtil::getOrCreateValueInstanceForLookup($parent_lookup); - $iBehaviourId = $oParentInstance->getBehaviourId(); - $oParentMetadata =& MetaData::get($oParentInstance->getFieldValueId()); - if (is_null($iBehaviourId)) { - $oBehaviour =& KTFieldBehaviour::createFromArray(array( - 'name' => 'autoinstance' . $oParentInstance->getId(), - 'humanname' => 'Auto instance' . $oParentMetadata->getName(), - 'fieldid' => $oParentInstance->getFieldId(), - )); - } else { - $oBehaviour =& KTFieldBehaviour::get($iBehaviourId); - } - if (PEAR::isError($oBehaviour)) { - var_dump($oBehaviour); - return $oBehaviour; - } - $iBehaviourId = $oBehaviour->getId(); - $oParentInstance->setBehaviourId($iBehaviourId); - $oParentInstance->update(); - - $sTable = KTUtil::getTableName('field_behaviour_options'); - $aOptions = array('noid' => true); - - $aQuery = array( - "DELETE FROM $sTable WHERE behaviour_id = ?", - array($iBehaviourId), - ); - $res = DBUtil::runQuery($aQuery); - - foreach ($child_lookups as $iFieldId => $aLookups) { - foreach ($aLookups as $iLookupId) { - $oValueInstance =& KTMetadataUtil::getOrCreateValueInstanceForLookup($iLookupId); - if (PEAR::isError($oValueInstance)) { - var_dump($oValueInstance); - return $oValueInstance; - } - $res = DBUtil::autoInsert($sTable, array( - 'behaviour_id' => $iBehaviourId, - 'field_id' => $iFieldId, - 'instance_id' => $oValueInstance->getId(), - ), $aOptions); - if (PEAR::isError($res)) { - var_dump($res); - return $res; - } - } - } - } - - // do you want the fieldset_id here? - function do_updateActiveFields() { - global $default; - $default->log->error(http_build_query($_REQUEST)); - $active_field = KTUtil::arrayGet($_REQUEST, 'active_field'); // field which is "active". - $fieldset_id = KTUtil::arrayGet($_REQUEST, 'fieldset_id'); - - // REMEMBER TO SET CONTENT-TYPE application/xml - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_simple_update_active_fields'); - $oTemplate->setData(array( - 'aFieldIds' => KTMetadataUtil::getChildFieldIds($active_field), - )); - header("Content-Type: application/xml"); - print $oTemplate->render(); - exit(0); - } - - // do you want the fieldset_id here? - function do_updateActiveLookups() { - global $default; - $default->log->error(http_build_query($_REQUEST)); - $active_field = KTUtil::arrayGet($_REQUEST, 'active_field'); // field which is "active". - $selected_lookup = KTUtil::arrayGet($_REQUEST, 'selected_lookup'); // selected value in said field. - - // REMEMBER TO SET CONTENT-TYPE application/xml - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/ajax_simple_update_active_lookups'); - - $aFieldLookups = KTMetadataUtil::getNextValuesForLookup($selected_lookup); - - $oTemplate->setData(array( - 'aFieldLookups' => $aFieldLookups, - )); - - header("Content-Type: application/xml"); - print $oTemplate->render(); - exit(0); - } - -} - -$oDispatcher = new AjaxConditionalAdminDispatcher(); -$oDispatcher->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/manageConditionals.php b/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/manageConditionals.php deleted file mode 100644 index 6a70269..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/conditional/manageConditionals.php +++ /dev/null @@ -1,116 +0,0 @@ -aBreadcrumbs[] = array('action' => 'docfield', 'name' => _('Document Field Management')); - - - } - - function do_main() { - - $aFieldsets = KTFieldset::getList("is_conditional = 1"); - $oTemplating = new KTTemplating; - - $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/conditional/select_fieldset"); - $aTemplateData = array( - "context" => &$this, - "available_fieldsets" => $aFieldsets, - ); - return $oTemplate->render($aTemplateData); - } - - // FIXME refactor this into do_editSimple(fieldset_id); - function do_editFieldset() { - $fieldset_id = KTUtil::arrayGet($_REQUEST, "fieldset_id"); - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/conditional/editsimple"); - /* alright: to "do" this we need at least: - * 1. the list of all the columns (id, name) and their available values. - * 2. the fieldset_id. - * we can then render in/out. Everything "intelligent" happens - * in AJAX (doing it with submits sucks arse. - * - * FIXME we fake it here with nested arrays... - */ - $oFieldset =& KTFieldset::get($fieldset_id); - $aFields =& $oFieldset->getFields(); - - $this->aBreadcrumbs[] = array( - 'action' => 'docfield', - 'query' => 'action=edit&fFieldsetId=' . $oFieldset->getId(), - 'name' => $oFieldset->getName() - ); - $this->aBreadcrumbs[] = array( - 'action' => 'docfield', - 'query' => 'action=manageConditional&fFieldsetId=' . $oFieldset->getId(), - 'name' => _('Manage conditional fieldset'), - ); - $this->aBreadcrumbs[] = array( - 'name' => _('Manage simple conditional'), - ); - - $aTemplateData = array( - "context" => &$this, - "fieldset_id" => $fieldset_id, - "aFields" => $aFields, - "iMasterFieldId" => $aFields[0]->getId(), - ); - return $oTemplate->render($aTemplateData); - } - - // FIXME refactor this into do_editSimple(fieldset_id); - function do_editComplexFieldset() { - $fieldset_id = KTUtil::arrayGet($_REQUEST, "fieldset_id"); - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/conditional/editcomplex"); - /* alright: to "do" this we need at least: - * 1. the list of all the columns (id, name) and their available values. - * 2. the fieldset_id. - * we can then render in/out. Everything "intelligent" happens - * in AJAX (doing it with submits sucks arse. - * - * FIXME we fake it here with nested arrays... - */ - $oFieldset =& KTFieldset::get($fieldset_id); - $aFields =& $oFieldset->getFields(); - $this->aBreadcrumbs[] = array( - 'action' => 'docfield', - 'query' => 'action=edit&fFieldsetId=' . $oFieldset->getId(), - 'name' => $oFieldset->getName() - ); - $this->aBreadcrumbs[] = array( - 'action' => 'docfield', - 'query' => 'action=manageConditional&fFieldsetId=' . $oFieldset->getId(), - 'name' => _('Manage conditional fieldset'), - ); - $this->aBreadcrumbs[] = array( - 'name' => _('Manage complex conditional'), - ); - $aTemplateData = array( - "context" => &$this, - "fieldset_id" => $fieldset_id, - "aFields" => $aFields, - "iMasterFieldId" => $aFields[0]->getId(), - ); - return $oTemplate->render($aTemplateData); - } -} - -$oDispatcher = new ManageConditionalDispatcher(); -$oDispatcher->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/documentFields.php b/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/documentFields.php deleted file mode 100644 index a0311bd..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/documentFields.php +++ /dev/null @@ -1,534 +0,0 @@ -aBreadcrumbs[] = array('action' => 'docfield', 'name' => _('Document Field Management')); - $this->oPage->setBreadcrumbDetails(_("view fieldsets")); - - // function KTBaseWidget($sLabel, $sDescription, $sName, $value, $oPage, $bRequired = false, $sId = null, $aErrors = null, $aOptions = null) { - // use widgets for the create form. - $createFields = array(); - $createFields[] = new KTStringWidget('Name', _('A human-readable name, used in add and edit forms.'), 'name', null, $this->oPage, true); - $createFields[] = new KTCheckboxWidget('Generic', _('A generic fieldset is one that is available for every document by default. These fieldsets will be available for users to edit and add for every document in the document management system.'), 'generic', false, $this->oPage, false); - $createFields[] = new KTCheckboxWidget('System', - _('A system fieldset is one that is never displayed to a user, and is used only by the document management system.'), 'generic', false, $this->oPage, false); - - - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/listFieldsets'); - $oTemplate->setData(array( - 'fieldsets' => KTFieldset::getList(), - 'creation_fields' => $createFields, - )); - return $oTemplate; - } - // }}} - - // {{{ do_edit - function do_edit() { - $this->oPage->setBreadcrumbDetails("edit"); - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/editFieldset'); - $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); - - $editFieldset = array(); - $editFieldset[] = new KTStringWidget('Name', _('A human-readable name, used in add and edit forms.'), 'name',$oFieldset->getName(), $this->oPage, true); - $editFieldset[] = new KTStringWidget('Namespace',_('Every fieldset needs to have a system name (used internally by the document management system). For fieldsets which you create, this is automatically created by the system, but for fieldsets created by plugins, this controls how the fieldset works.'), 'namespace', $oFieldset->getNamespace(), $this->oPage, true); - - $createFields = array(); - $createFields[] = new KTStringWidget('Name', _('A human-readable name, used in add and edit forms.'), 'name',null, $this->oPage, true); - - // type is a little more complex. - $vocab = array(); - if (!$oFieldset->getIsConditional()) { - $vocab["normal"] = 'Normal'; - } - $vocab['lookup'] = 'Lookup'; - $vocab['tree'] = 'Tree'; - $typeOptions = array("vocab" => $vocab); - $createFields[] =& new KTLookupWidget('Type',_('Different field types can have different properties.'), - 'type', null, $this->oPage, true, null, null, $typeOptions); - - - $this->aBreadcrumbs[] = array( - 'action' => 'docfield', - 'query' => 'action=edit&fFieldsetId=' . $_REQUEST['fFieldsetId'], - 'name' => 'Fieldset ' . $oFieldset->getName() - ); - $oTemplate->setData(array( - 'oFieldset' => $oFieldset, - 'edit_fieldset_fields' => $editFieldset, - 'create_field_fields' => $createFields, - )); - return $oTemplate; - } - // }}} - - // {{{ edit_object - function do_editobject() { - - $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); - $oFieldset->setName($_REQUEST['name']); - $oFieldset->setNamespace($_REQUEST['namespace']); - $res = $oFieldset->update(); - if (PEAR::isError($res) || ($res === false)) { - $this->errorRedirectTo('edit', _('Could not save fieldset changes'), 'fFieldsetId=' . $oFieldset->getId()); - exit(0); - } - $this->successRedirectTo('edit', _('Changes saved'), 'fFieldsetId=' . $oFieldset->getId()); - exit(0); - } - // }}} - - // {{{ do_new - function do_new() { - $bIsGeneric = false; - $bIsSystem = false; - - if (KTUtil::arrayGet($_REQUEST, 'generic')) { - $bIsGeneric = true; - } - - if (KTUtil::arrayGet($_REQUEST, 'system')) { - $bIsSystem = true; - // Can't be a system fieldset and a generic fieldset... - $bIsGeneric = false; - } - $sName = KTUtil::arrayGet($_REQUEST, 'name'); - $sName = $this->oValidator->notEmpty($sName); - $sNamespace = KTUtil::arrayGet($_REQUEST, 'namespace'); - if (empty($sNamespace)) { - $sNamespace = KTUtil::nameToLocalNamespace('fieldsets', $sName); - } - $res = KTFieldset::createFromArray(array( - 'name' => $sName, - 'namespace' => $sNamespace, - 'mandatory' => false, - 'isconditional' => false, - 'isgeneric' => $bIsGeneric, - 'issystem' => $bIsSystem, - )); - if (PEAR::isError($res) || ($res === false)) { - $this->errorRedirectToMain('Could not create fieldset'); - exit(0); - } - $this->successRedirectTo('edit', _('Fieldset created') . ': '.$sName, 'fFieldsetId=' . $res->getId()); - exit(0); - } - // }}} - - // {{{ do_newfield - function do_newfield() { - $is_lookup = false; - $is_tree = false; - if ($_REQUEST['type'] === "lookup") { - $is_lookup = true; - } - if ($_REQUEST['type'] === "tree") { - $is_lookup = true; - $is_tree = true; - } - $oFieldset = KTFieldset::get($_REQUEST['fFieldsetId']); - $oField =& DocumentField::createFromArray(array( - 'name' => $_REQUEST['name'], - 'datatype' => 'STRING', - 'haslookup' => $is_lookup, - 'haslookuptree' => $is_tree, - 'parentfieldset' => $oFieldset->getId(), - )); - if (PEAR::isError($res) || ($res === false)) { - $this->errorRedirectTo('edit', _('Could not create field') . ': '.$_REQUEST['name'], 'fFieldsetId=' . $oFieldset->getId()); - exit(0); - } - if ($is_lookup) { - $this->successRedirectTo('editField', _('Field created') . ': '.$_REQUEST['name'], 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); - } else { - $this->successRedirectTo('edit', _('Field created') . ': ' . $_REQUEST['name'], 'fFieldsetId=' . $oFieldset->getId()); - } - exit(0); - } - // }}} - - // {{{ do_editField - function do_editField() { - $this->oPage->setBreadcrumbDetails(_("edit field")); - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/editField'); - $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); - $oField =& DocumentField::get($_REQUEST['fFieldId']); - - $this->aBreadcrumbs[] = array( - 'action' => 'docfield', - 'query' => 'action=edit&fFieldsetId=' . $_REQUEST['fFieldsetId'], - 'name' => $oFieldset->getName() - ); - $this->aBreadcrumbs[] = array( - 'name' => $oField->getName() - ); - $this->oPage->setBreadcrumbDetails(_('edit field')); - - $oTemplate->setData(array( - 'oFieldset' => $oFieldset, - 'oField' => $oField, - )); - return $oTemplate; - } - // }}} - - // {{{ do_editFieldObject - function do_editFieldObject() { - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/editField'); - $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); - $oField =& DocumentField::get($_REQUEST['fFieldId']); - - $oField->setName($_REQUEST['name']); - $res = $oField->update(); - if (PEAR::isError($res) || ($res === false)) { - $this->errorRedirectTo('editField', _('Could not save field changes'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); - exit(0); - } - $this->successRedirectTo('editField', _('Changes saved'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); - exit(0); - } - // }}} - - // {{{ do_addLookups - function do_addLookups() { - $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); - $oField =& DocumentField::get($_REQUEST['fFieldId']); - if (empty($_REQUEST['value'])) { - $this->errorRedirectTo('editField', _('Empty lookup not added'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); - } - $oMetaData =& MetaData::createFromArray(array( - 'name' => $_REQUEST['value'], - 'docfieldid' => $oField->getId(), - )); - $this->successRedirectTo('editField', _('Lookup added'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); - exit(0); - } - // }}} - - // {{{ do_metadataMultiAction - function do_metadataMultiAction() { - $subaction = array_keys(KTUtil::arrayGet($_REQUEST, 'submit', array())); - $this->oValidator->notEmpty($subaction, array("message" => _("No action specified"))); - $subaction = $subaction[0]; - $method = null; - if (method_exists($this, 'lookup_' . $subaction)) { - $method = 'lookup_' . $subaction; - } - $this->oValidator->notEmpty($method, array("message" => _("Unknown action specified"))); - return $this->$method(); - } - // }}} - - // {{{ lookup_remove - function lookup_remove() { - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); - $oField =& DocumentField::get($_REQUEST['fFieldId']); - $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata'); - if (empty($aMetadata)) { - $this->errorRedirectTo('editField', _('No lookups selected'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); - } - foreach ($_REQUEST['metadata'] as $iMetaDataId) { - $oMetaData =& MetaData::get($iMetaDataId); - $oMetaData->delete(); - } - $this->successRedirectTo('editField', _('Lookups removed'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); - exit(0); - } - // }}} - - // {{{ lookup_disable - function lookup_disable() { - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); - $oField =& DocumentField::get($_REQUEST['fFieldId']); - $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata'); - if (empty($aMetadata)) { - $this->errorRedirectTo('editField', _('No lookups selected'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); - } - foreach ($_REQUEST['metadata'] as $iMetaDataId) { - $oMetaData =& MetaData::get($iMetaDataId); - $oMetaData->setDisabled(true); - $oMetaData->update(); - } - $this->successRedirectTo('editField', _('Lookups disabled'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); - exit(0); - } - // }}} - - // {{{ lookup_enable - function lookup_enable() { - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); - $oField =& DocumentField::get($_REQUEST['fFieldId']); - $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata'); - if (empty($aMetadata)) { - $this->errorRedirectTo('editField', _('No lookups selected'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); - } - foreach ($_REQUEST['metadata'] as $iMetaDataId) { - $oMetaData =& MetaData::get($iMetaDataId); - $oMetaData->setDisabled(false); - $oMetaData->update(); - } - $this->successRedirectTo('editField', _('Lookups enabled'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); - exit(0); - } - // }}} - - // {{{ lookup_togglestickiness - function lookup_togglestickiness() { - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); - $oField =& DocumentField::get($_REQUEST['fFieldId']); - $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata'); - if (empty($aMetadata)) { - $this->errorRedirectTo('editField', _('No lookups selected'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); - } - foreach ($_REQUEST['metadata'] as $iMetaDataId) { - $oMetaData =& MetaData::get($iMetaDataId); - $bStuck = (boolean)$oMetaData->getIsStuck(); - $oMetaData->setIsStuck(!$bStuck); - $oMetaData->update(); - } - $this->successRedirectTo('editField', _('Lookup stickiness toggled'), 'fFieldsetId=' . $oFieldset->getId() . '&fFieldId=' . $oField->getId()); - exit(0); - } - // }}} - - // {{{ do_becomeconditional - function do_becomeconditional() { - $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); - $oFieldset->setIsConditional(true); - $oFieldset->setIsComplete(false); - $res = $oFieldset->update(); - if (PEAR::isError($res) || ($res === false)) { - $this->errorRedirectTo('edit', _('Could not become conditional'), 'fFieldsetId=' . $oFieldset->getId()); - exit(0); - } - $this->successRedirectTo('edit', _('Became conditional'), 'fFieldsetId=' . $oFieldset->getId()); - exit(0); - } - // }}} - - // {{{ do_removeconditional - function do_removeconditional() { - $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); - $oFieldset->setIsConditional(false); - $oFieldset->setIsComplete(true); - $res = $oFieldset->update(); - if (PEAR::isError($res) || ($res === false)) { - $this->errorRedirectTo('edit', _('Could not stop being conditional'), 'fFieldsetId=' . $oFieldset->getId()); - exit(0); - } - $this->successRedirectTo('edit', _('Became no longer conditional'), 'fFieldsetId=' . $oFieldset->getId()); - exit(0); - } - // }}} - - // {{{ do_removeFields - function do_removeFields() { - $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); - foreach ($_REQUEST['fields'] as $iFieldId) { - $oField =& DocumentField::get($iFieldId); - $oField->delete(); - } - $this->successRedirectTo('edit', _('Fields removed'), 'fFieldsetId=' . $oFieldset->getId()); - exit(0); - } - // }}} - - // {{{ do_manageConditional - function do_manageConditional () { - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/conditional/manageConditional'); - $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); - $iMasterFieldId = $oFieldset->getMasterFieldId(); - if (!empty($iMasterFieldId)) { - $oMasterField =& DocumentField::get($iMasterFieldId); - if (PEAR::isError($oMasterField)) { - $oMasterField = null; - } - } else { - $oMasterField = null; - } - $sTable = KTUtil::getTableName('field_orders'); - $aQuery = array( - "SELECT parent_field_id, child_field_id FROM $sTable WHERE fieldset_id = ?", - array($oFieldset->getId()) - ); - $aFieldOrders = DBUtil::getResultArray($aQuery); - $aFields = $oFieldset->getFields(); - - $aFreeFieldIds = array(); - foreach ($aFields as $oField) { - $aFreeFieldIds[] = $oField->getId(); - } - if ($oMasterField) { - $aParentFieldIds = array($oMasterField->getId()); - foreach ($aFieldOrders as $aRow) { - $aParentFieldIds[] = $aRow['child_field_id']; - } - $aParentFields = array(); - foreach (array_unique($aParentFieldIds) as $iId) { - $aParentFields[] =& DocumentField::get($iId); - } - $aFreeFields = array(); - foreach ($aFreeFieldIds as $iId) { - if (in_array($iId, $aParentFieldIds)) { - continue; - } - $aFreeFields[] =& DocumentField::get($iId); - } - } - $res = KTMetadataUtil::checkConditionalFieldsetCompleteness($oFieldset); - if (PEAR::isError($res)) { - $sIncomplete = $res->getMessage(); - } else { - $sIncomplete = null; - } - $this->aBreadcrumbs[] = array( - 'action' => 'docfield', - 'query' => 'action=edit&fFieldsetId=' . $_REQUEST['fFieldsetId'], - 'name' => $oFieldset->getName() - ); - $this->aBreadcrumbs[] = array( - 'action' => 'docfield', - 'query' => 'action=manageConditional&fFieldsetId=' . $_REQUEST['fFieldsetId'], - 'name' => _('Manage conditional field'), - ); - $oTemplate->setData(array( - 'oFieldset' => $oFieldset, - 'free_fields' => $aFreeFields, - 'parent_fields' => $aParentFields, - 'aFieldOrders' => $aFieldOrders, - 'oMasterField' => $oMasterField, - 'sIncomplete' => $sIncomplete, - )); - return $oTemplate; - } - // }}} - - // {{{ do_orderFields - function do_orderFields() { - $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']); - $aFreeFieldIds = $_REQUEST['fFreeFieldIds']; - if (empty($aFreeFieldIds)) { - $this->errorRedirectTo('manageConditional', 'No children fields selected', 'fFieldsetId=' . $oFieldset->getId()); - } - $iParentFieldId = $_REQUEST['fParentFieldId']; - if (in_array($aParentFieldId, $aFreeFieldIds)) { - $this->errorRedirectTo('manageConditional', _('Field cannot be its own parent field'), 'fFieldsetId=' . $oFieldset->getId()); - } - foreach ($aFreeFieldIds as $iChildFieldId) { - $res = KTMetadataUtil::addFieldOrder($iParentFieldId, $iChildFieldId, $oFieldset); - $this->oValidator->notError($res, array( - 'redirect_to' => array('manageConditional', 'fFieldsetId=' . $oFieldset->getId()), - 'message' => _('Error adding Fields'), - )); - } - $this->successRedirectTo('manageConditional', _('Fields ordered'), 'fFieldsetId=' . $oFieldset->getId()); - exit(0); - } - // }}} - - // {{{ do_setMasterField - function do_setMasterField() { - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); - $oField =& $this->oValidator->validateField($_REQUEST['fFieldId']); - - $res = KTMetadataUtil::removeFieldOrdering($oFieldset); - $oFieldset->setMasterFieldId($oField->getId()); - $res = $oFieldset->update(); - - $this->oValidator->notError($res, array( - 'redirect_to' => array('manageConditional', 'fFieldsetId=' . $oFieldset->getId()), - 'message' => _('Error setting master field'), - )); - $this->successRedirectTo('manageConditional', _('Master field set'), 'fFieldsetId=' . $oFieldset->getId()); - exit(0); - } - // }}} - - // {{{ do_checkComplete - /** - * Checks whether the fieldset is complete, and if it is, sets it to - * be complete in the database. Otherwise, set it to not be - * complete in the database (just in case), and set the error - * messages as to why it isn't. - */ - function do_checkComplete() { - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); - $res = KTMetadataUtil::checkConditionalFieldsetCompleteness($oFieldset); - if ($res === true) { - $oFieldset->setIsComplete(true); - $oFieldset->update(); - $this->successRedirectTo('manageConditional', _('Set to complete'), 'fFieldsetId=' . $oFieldset->getId()); - } - $oFieldset->setIsComplete(false); - $oFieldset->update(); - // Success, as we want to save the incompleteness to the - // database... - $this->successRedirectTo('manageConditional', _('Could not to complete'), 'fFieldsetId=' . $oFieldset->getId()); - } - // }}} - - // {{{ do_changeToSimple - function do_changeToSimple() { - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); - $oFieldset->setIsComplex(false); - $res = $oFieldset->update(); - $this->oValidator->notError($res, array( - 'redirect_to' => array('manageConditional', 'fFieldsetId=' . $oFieldset->getId()), - 'message' => _('Error changing to simple'), - )); - $this->successRedirectTo('manageConditional', _('Changed to simple'), 'fFieldsetId=' . $oFieldset->getId()); - } - // }}} - - // {{{ do_changeToComplex - function do_changeToComplex() { - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); - $oFieldset->setIsComplex(true); - $res = $oFieldset->update(); - $this->oValidator->notError($res, array( - 'redirect_to' => array('manageConditional', 'fFieldsetId=' . $oFieldset->getId()), - 'message' => _('Error changing to complex'), - )); - $this->successRedirectTo('manageConditional', _('Changed to complex'), 'fFieldsetId=' . $oFieldset->getId()); - } - // }}} - - // {{{ do_delete - function do_delete() { - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']); - $res = $oFieldset->delete(); - $this->oValidator->notErrorFalse($res, array( - 'redirect_to' => array('main', ''), - 'message' => _('Could not delete fieldset'), - )); - $this->successRedirectToMain(_('Fieldset deleted')); - } - // }}} -} - -// use the admin dispatch mechanisms. -//$d =& new KTDocumentFieldDispatcher; -//$d->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/manageLookupTrees.php b/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/manageLookupTrees.php deleted file mode 100644 index 9317c66..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/manageLookupTrees.php +++ /dev/null @@ -1,246 +0,0 @@ -loadTemplate("ktcore/manage_lookuptrees"); - $aTemplateData = array( - "treefields" => $aTreeFields, - "lookupfields" => $aLookupFields, - ); - return $oTemplate->render($aTemplateData); - } - - function do_createTree() { - // extract. - $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); - - // validate - if (empty($field_id)) { return $this->errorRedirectToMain(_("Must select a field to convert.")); } - $oField =& DocumentField::get($field_id); - if (PEAR::isError($oField)) { return $this->errorRedirectToMain(_("Invalid field.")); } - - // set as a metadata tree. - $oField->setHasLookupTree(1); - $oField->update(); - $this->errorRedirectToMain(sprintf(_("Converted %s to a tree."), $oField->getName())); - } - - - // create and display the tree editing form. - function do_editTree() { - global $default; - // extract. - $field_id = KTUtil::arrayGet($_REQUEST, 'field_id'); - $current_node = KTUtil::arrayGet($_REQUEST, 'current_node', 0); - $subaction = KTUtil::arrayGet($_REQUEST, 'subaction'); - - // validate - if (empty($field_id)) { return $this->errorRedirectToMain(_("Must select a field to edit.")); } - $oField =& DocumentField::get($field_id); - if (PEAR::isError($oField)) { return $this->errorRedirectToMain(_("Invalid field.")); } - - // under here we do the subaction rendering. - // we do this so we don't have to do _very_ strange things with multiple actions. - //$default->log->debug("Subaction: " . $subaction); - $fieldTree =& new MDTree(); - $fieldTree->buildForField($oField->getId()); - - if ($subaction !== null) { - $target = 'editTree'; - $msg = _('Changes saved.'); - if ($subaction === "addCategory") { - $new_category = KTUtil::arrayGet($_REQUEST, 'category_name'); - if (empty($new_category)) { return $this->errorRedirectTo("editTree", _("Must enter a name for the new category."), array("field_id" => $field_id)); } - else { $this->subact_addCategory($field_id, $current_node, $new_category, $fieldTree);} - $msg = _('Category added'). ': ' . $new_category; - } - if ($subaction === "deleteCategory") { - $this->subact_deleteCategory($fieldTree, $current_node); - $current_node = 0; // clear out, and don't try and render the newly deleted category. - $msg = _('Category removed.'); - } - if ($subaction === "linkKeywords") { - $keywords = KTUtil::arrayGet($_REQUEST, 'keywordsToAdd'); - $this->subact_linkKeywords($fieldTree, $current_node, $keywords); - $current_node = 0; // clear out, and don't try and render the newly deleted category. - $msg = _('Keywords added to category.'); - } - if ($subaction === "unlinkKeyword") { - $keyword = KTUtil::arrayGet($_REQUEST, 'keyword_id'); - $this->subact_unlinkKeyword($fieldTree, $keyword); - $msg = _('Keyword moved to base of tree.'); - } - // now redirect - $query = 'field_id=' . $field_id; - return $this->successRedirectTo($target, $msg, $query); - } - - if ($fieldTree->root === null) { - return $this->errorRedirectToMain(_("Error building tree. Is this a valid tree-lookup field?")); - } - - // FIXME extract this from MDTree (helper method?) - $free_metadata = MetaData::getList('document_field_id = '.$oField->getId().' AND (treeorg_parent = 0 OR treeorg_parent IS NULL)'); - - // render edit template. - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/edit_lookuptrees"); - $renderedTree = $this->_evilTreeRenderer($fieldTree); - - $this->oPage->setTitle(_('Edit Lookup Tree')); - - //$this->oPage->requireJSResource('thirdparty/js/MochiKit/Base.js'); - - $aTemplateData = array( - "field" => $oField, - "tree" => $fieldTree, - "renderedTree" => $renderedTree, - "currentNode" => $current_node, - "freechildren" => $free_metadata, - "context" => $this, - ); - return $oTemplate->render($aTemplateData); - } - - function subact_addCategory($field_id, $current_node, $new_category, &$constructedTree) { - $newCategory = MDTreeNode::createFromArray(array ( - "iFieldId" => $field_id, - "sName" => $new_category, - "iParentNode" => $current_node, - )); - if (PEAR::isError($newCategory)) - { - return false; - } - $constructedTree->addNode($newCategory); - return true; - } - - function subact_deleteCategory(&$constructedTree, $current_node) { - $constructedTree->deleteNode($current_node); - return true; - } - - function subact_unlinkKeyword(&$constructedTree, $keyword) { - $oKW = MetaData::get($keyword); - $constructedTree->reparentKeyword($oKW->getId(), 0); - return true; - } - - - function subact_linkKeywords(&$constructedTree, $current_node, $keywords) { - foreach ($keywords as $md_id) - { - $constructedTree->reparentKeyword($md_id, $current_node); - } - return true; - } - - /* ----------------------- EVIL HACK -------------------------- - * - * This whole thing needs to replaced, as soon as I work out how - * to non-sucking Smarty recursion. - */ - - function _evilTreeRecursion($subnode, $treeToRender) - { - $treeStr = "'; - return $treeStr; - - } - - // I can't seem to do recursion in smarty, and recursive templates seems a bad solution. - // Come up with a better way to do this (? NBM) - function _evilTreeRenderer($treeToRender) { - //global $default; - $treeStr = ""; - $stack = array(); - $exitstack = array(); - - // since the root is virtual, we need to fake it here. - // the inner section is generised. - $treeStr .= ''; - - return $treeStr; - } - - // don't hate me. - function _evilActionHelper($iFieldId, $bIsKeyword, $current_node) { - $actionStr = " ("; - if ($bIsKeyword === true) { - $actionStr .= 'unlink'; - } - else - { - $actionStr .= 'add items '; - $actionStr .= '| delete'; - } - $actionStr .= ")"; - return $actionStr; - } - -} - -$oDispatcher = new ManageLookupTreeDispatcher(); -$oDispatcher->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/doclinkmanagement/documentLinks.php b/presentation/lookAndFeel/knowledgeTree/administration/doclinkmanagement/documentLinks.php deleted file mode 100644 index 7a4152d..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/doclinkmanagement/documentLinks.php +++ /dev/null @@ -1,161 +0,0 @@ -, Jam Warehouse (Pty) Ltd, South Africa - * @package documentmanagement - */ - -/* boilerplate */ -//require_once('../../../../../config/dmsDefaults.php'); - -require_once(KT_LIB_DIR . '/dispatcher.inc.php'); -require_once(KT_LIB_DIR . '/templating/kt3template.inc.php'); - -require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php'); - -require_once(KT_LIB_DIR . '/documentmanagement/LinkType.inc'); // a horrible piece of work. - -class KTDocLinkAdminDispatcher extends KTAdminDispatcher { - - // Breadcrumbs base - added to in methods - function check() { - return true; - } - - function do_main() { - $this->aBreadcrumbs[] = array('name' => _('Document Links')); - $this->oPage->setBreadcrumbDetails(_("view")); - - $aLinkTypes =& LinkType::getList('id > 0'); - - $addLinkForm = array(); - // KTBaseWidget($sLabel, $sDescription, $sName, $value, $oPage, $bRequired = false, $sId = null, $aErrors = null, $aOptions = null) - $addLinkForm[] = new KTStringWidget('Name',_('A short, human-readable name for the link type.'), 'fName', null, $this->oPage, true); - $addLinkForm[] = new KTStringWidget('Description',_('A short brief description of the relationship implied by this link type.'), 'fDescription', null, $this->oPage, true); - - - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/linktypesadmin'); - $oTemplate->setData(array( - "context" => $this, - "add_form" => $addLinkForm, - "links" => $aLinkTypes, - )); - return $oTemplate; - } - - function do_edit() { - $link_id = KTUtil::arrayGet($_REQUEST, 'fLinkTypeId', null, false); - if ($link_id === null) { - $this->errorRedirectToMain(_("Please specify a link type to edit.")); - } - - $oLinkType =& LinkType::get($link_id); - - $this->aBreadcrumbs[] = array('name' => _('Document Links')); - $this->oPage->setBreadcrumbDetails(_("view")); - - $aLinkTypes =& LinkType::getList('id > 0'); - - $editLinkForm = array(); - // KTBaseWidget($sLabel, $sDescription, $sName, $value, $oPage, $bRequired = false, $sId = null, $aErrors = null, $aOptions = null) - $editLinkForm[] = new KTStringWidget('Name',_('A short, human-readable name for the link type.'), 'fName', $oLinkType->getName(), $this->oPage, true); - $editLinkForm[] = new KTStringWidget('Description',_('A short brief description of the relationship implied by this link type.'), 'fDescription', $oLinkType->getDescription(), $this->oPage, true); - - - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/linktypesadmin'); - $oTemplate->setData(array( - "context" => $this, - "edit_form" => $editLinkForm, - "old_link" => $oLinkType, - "links" => $aLinkTypes, - )); - return $oTemplate; - } - - - function do_update() { - $link_id = KTUtil::arrayGet($_REQUEST, 'fLinkTypeId', null, false); - if ($link_id === null) { - $this->errorRedirectToMain(_("Please specify a link type to update.")); - } - - $name = KTUtil::arrayGet($_REQUEST, 'fName'); - $description = KTUtil::arrayGet($_REQUEST, 'fDescription'); - - if (empty($name) || empty($description)) { // for bonus points, make this go to edit, and edit catch it. - $this->errorRedirectToMain(_('Please enter information for all fields.')); - } - - $oLinkType =& LinkType::get($link_id); - - $oLinkType->setName($name); - $oLinkType->setDescription($description); - $oLinkType->update(); - - $this->successRedirectToMain(_("Link Type updated.")); - } - - function do_add() { - $name = KTUtil::arrayGet($_REQUEST, 'fName'); - $description = KTUtil::arrayGet($_REQUEST, 'fDescription'); - - if (empty($name) || empty($description)) { - $this->errorRedirectToMain(_('Please enter information for all fields.')); - } - - $oLinkType = new LinkType($name, $description); - $oLinkType->create(); - - //$oLinkType =& LinkType::createFromArray(array("sName" => $name, "sDescription" => $description)); - - $this->successRedirectToMain(_("Link Type created.")); - } - - function do_delete() { - $types_to_delete = KTUtil::arrayGet($_REQUEST, 'fLinksToDelete'); // is an array. - - if (empty($types_to_delete)) { - $this->errorRedirectToMain(_('Please select one or more link types to delete.')); - } - - $count = 0; - foreach ($types_to_delete as $link_id) { - $oLinkType = LinkType::get($link_id); - $oLinkType->delete(); // technically, this is a bad thing - $count += 1; - } - - //$oLinkType =& LinkType::createFromArray(array("sName" => $name, "sDescription" => $description)); - - $this->successRedirectToMain($count . " " . _("Link types deleted.")); - } - - -} - -// use the new admin framework. -//$d = new KTDocLinkAdminDispatcher(); -//$d->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/doctypemanagement/documentTypes.php b/presentation/lookAndFeel/knowledgeTree/administration/doctypemanagement/documentTypes.php deleted file mode 100644 index e415336..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/doctypemanagement/documentTypes.php +++ /dev/null @@ -1,146 +0,0 @@ -aBreadcrumbs[] = array('action' => 'doctype', 'name' => _('Document Type Management')); - - $this->oPage->setBreadcrumbDetails('view types'); - - $addFields = array(); - $addFields[] = new KTStringWidget(_('Name'),_('A short, human-readable name for the document type.'), 'name', null, $this->oPage, true); - - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate = $oTemplating->loadTemplate('ktcore/documenttypes/list'); - $oTemplate->setData(array( - 'document_types' => DocumentType::getList(), - 'add_fields' => $addFields, - )); - return $oTemplate; - } - - function do_new() { - - - - $sName = $_REQUEST['name']; - $oDocumentType =& DocumentType::createFromArray(array( - 'name' => $sName, - )); - if (PEAR::isError($oDocumentType)) { - $this->errorRedirectToMain(_('Could not create document type')); - exit(0); - } - $this->successRedirectTo('edit', _('Document type created'), 'fDocumentTypeId=' . $oDocumentType->getId()); - exit(0); - } - - function do_delete() { - $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']); - if ($oDocumentType->isUsed()) { - $this->errorRedirectToMain(_('Document type still in use, could not be deleted')); - exit(0); - } - $res = $oDocumentType->delete(); - if (PEAR::isError($res) || ($res === false)) { - $this->errorRedirectToMain(_('Document type could not be deleted')); - exit(0); - } - - $this->successRedirectToMain(_('Document type deleted')); - exit(0); - } - - function do_edit() { - - $this->aBreadcrumbs[] = array('action' => 'doctype', 'name' => _('Document Type Management')); - - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate = $oTemplating->loadTemplate('ktcore/documenttypes/edit'); - $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']); - - - $aCurrentFieldsets =& KTFieldset::getForDocumentType($oDocumentType); - $aAvailableFieldsets =& KTFieldset::getNonGenericFieldsets(); - $aAvailableFieldsets = array_diff($aAvailableFieldsets, $aCurrentFieldsets); - - - $vocab = array(); - foreach ($aAvailableFieldsets as $oFieldset) { - $vocab[$oFieldset->getId()] = $oFieldset->getName(); - } - $aOptions = array(); - $aOptions['vocab'] = $vocab; - $aOptions['multi'] = true; - $aOptions['size'] = 5; - $availableTypesWidget =& new KTLookupWidget(_('Available Fieldsets'),_('Select the fieldsets which you wish to associate with this document type'), 'fieldsetid', null, $this->oPage, true, - null, null, $aOptions); - - $this->aBreadcrumbs[] = array( - 'name' => $oDocumentType->getName(), - ); - $this->oPage->setBreadcrumbDetails(_('edit')); - - $oTemplate->setData(array( - 'oDocumentType' => $oDocumentType, - 'aCurrentFieldsets' => $aCurrentFieldsets, - 'aAvailableFieldsets' => $aAvailableFieldsets, - 'availableWidget' => $availableTypesWidget, - )); - return $oTemplate; - } - - function do_editobject() { - $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']); - $oDocumentType->setName($_REQUEST['name']); - $res = $oDocumentType->update(); - if (PEAR::isError($res) || ($res === false)) { - $this->errorRedirectTo('edit', _('Could not save document type changes'), 'fDocumentTypeId=' . $oDocumentType->getId()); - exit(0); - } - $this->successRedirectTo('edit', _('Name changed.'), 'fDocumentTypeId=' . $oDocumentType->getId()); - exit(0); - } - - function do_removefieldsets() { - $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']); - $res = KTMetadataUtil::removeSetsFromDocumentType($oDocumentType, $_REQUEST['fieldsetid']); - if (PEAR::isError($res)) { - var_dump($res); - $this->errorRedirectTo('edit', _('Changes not saved'), 'fDocumentTypeId=' . $oDocumentType->getId()); - exit(0); - } - $this->successRedirectTo('edit', _('Fieldsets removed.'), 'fDocumentTypeId=' . $oDocumentType->getId()); - exit(0); - } - - function do_addfieldsets() { - $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']); - $res = KTMetadataUtil::addSetsToDocumentType($oDocumentType, $_REQUEST['fieldsetid']); - if (PEAR::isError($res)) { - var_dump($res); - $this->errorRedirectTo('edit', _('Changes not saved'), 'fDocumentTypeId=' . $oDocumentType->getId()); - exit(0); - } - $this->successRedirectTo('edit', _('Fieldsets associated.'), 'fDocumentTypeId=' . $oDocumentType->getId()); - exit(0); - } -} - -//$d =& new KTDocumentTypeDispatcher; -//$d->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/archivedDocuments.php b/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/archivedDocuments.php deleted file mode 100644 index fc5ea90..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/archivedDocuments.php +++ /dev/null @@ -1,101 +0,0 @@ -aBreadcrumbs[] = array('action' => 'archivedDocuments', 'name' => _('Archived Documents')); - - $this->oPage->setBreadcrumbDetails(_('list')); - - $aDocuments =& Document::getList("status_id=" . ARCHIVED); - - - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/archivedlist'); - $oTemplate->setData(array( - 'context' => $this, - 'documents' => $aDocuments, - )); - return $oTemplate; - } - - function do_confirm_restore() { - $this->aBreadcrumbs[] = array('action' => 'archivedDocuments', 'name' => _('Archived Documents')); - - $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); - - $this->oPage->setTitle(sprintf(_('Confirm Restore of %d documents'), count($selected_docs))); - - $this->oPage->setBreadcrumbDetails(sprintf(_('confirm restore of %d documents'), count($selected_docs))); - - $aDocuments = array(); - foreach ($selected_docs as $doc_id) { - $oDoc =& Document::get($doc_id); - if (PEAR::isError($oDoc) || ($oDoc === false)) { - $this->errorRedirectToMain(_('Invalid document id specified. Aborting restore.')); - } else if ($oDoc->getStatusId() != ARCHIVED) { - $this->errorRedirectToMain(sprintf(_('%s is not an archived document. Aborting restore.'), $oDoc->getName())); - } - $aDocuments[] = $oDoc; - } - - - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/dearchiveconfirmlist'); - $oTemplate->setData(array( - 'context' => $this, - 'documents' => $aDocuments, - )); - return $oTemplate; - } - - function do_finish_restore() { - - - $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); - - $aDocuments = array(); - foreach ($selected_docs as $doc_id) { - $oDoc =& Document::get($doc_id); - if (PEAR::isError($oDoc) || ($oDoc === false)) { - $this->errorRedirectToMain(_('Invalid document id specified. Aborting restore.')); - } else if ($oDoc->getStatusId() != ARCHIVED) { - $this->errorRedirectToMain(sprintf(_('%s is not an archived document. Aborting restore.'), $oDoc->getName())); - } - $aDocuments[] = $oDoc; - } - - $this->startTransaction(); - - foreach ($aDocuments as $oDoc) { - // FIXME find de-archival source. - // FIXME purge old notifications. - // FIXME create de-archival notices to those who sent in old notifications. - $oDoc->setStatusId(LIVE); - $res = $oDoc->update(); - if (PEAR::isError($res) || ($res == false)) { - $this->errorRedirectToMain(sprintf(_('%s could not be made "live".'), $oDoc->getName)); - } - } - $this->commitTransaction(); - $msg = sprintf(_('%d documents made active.'), count($aDocuments)); - $this->successRedirectToMain($msg); - } -} - -//$d =& new DeletedDocumentsDispatcher; -//$d->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/deletedDocuments.php b/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/deletedDocuments.php deleted file mode 100644 index 5798d2e..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/deletedDocuments.php +++ /dev/null @@ -1,108 +0,0 @@ -aBreadcrumbs[] = array('action' => 'deletedDocuments', 'name' => _('Deleted Documents')); - - $this->oPage->setBreadcrumbDetails(_('view')); - - $aDocuments =& Document::getList("status_id=" . DELETED); - - - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/deletedlist'); - $oTemplate->setData(array( - 'context' => $this, - 'documents' => $aDocuments, - )); - return $oTemplate; - } - - function do_confirm_expunge() { - $this->aBreadcrumbs[] = array('action' => 'deletedDocuments', 'name' => _('Deleted Documents')); - - $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); - - $this->oPage->setTitle(sprintf(_('Confirm Expunge of %d documents'), count($selected_docs))); - - $this->oPage->setBreadcrumbDetails(sprintf(_('confirm expunge of %d documents'), count($selected_docs))); - - $aDocuments = array(); - foreach ($selected_docs as $doc_id) { - $oDoc =& Document::get($doc_id); - if (PEAR::isError($oDoc) || ($oDoc === false)) { - $this->errorRedirectToMain(_('Invalid document id specified. Aborting expunge')); - } else if ($oDoc->getStatusId() != DELETED) { - $this->errorRedirectToMain(sprintf(_('%s is not a deleted document. Aborting expunge'), $oDoc->getName())); - } - $aDocuments[] = $oDoc; - } - - - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/expungeconfirmlist'); - $oTemplate->setData(array( - 'context' => $this, - 'documents' => $aDocuments, - )); - return $oTemplate; - } - - function do_finish_expunge() { - - - $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); - - $aDocuments = array(); - foreach ($selected_docs as $doc_id) { - $oDoc =& Document::get($doc_id); - if (PEAR::isError($oDoc) || ($oDoc === false)) { - $this->errorRedirectToMain(_('Invalid document id specified. Aborting expunge')); - } else if ($oDoc->getStatusId() != DELETED) { - $this->errorRedirectToMain(sprintf(_('%s is not a deleted document. Aborting expunge'), $oDoc->getName())); - } - $aDocuments[] = $oDoc; - } - - $this->startTransaction(); - $aErrorDocuments = array(); - $aSuccessDocuments = array(); - - foreach ($aDocuments as $oDoc) { - if (!PhysicalDocumentManager::expunge($oDoc)) { $aErrorDocuments[] = $oDoc->getDisplayPath(); } - else { - $oDocumentTransaction = & new DocumentTransaction($oDoc->getId(), "Document expunged", EXPUNGE); - $oDocumentTransaction->create(); - - // delete this from the db now - if (!$oDoc->delete()) { $aErrorDocuments[] = $oDoc->getId(); } - else { - // removed succesfully - $aSuccessDocuments[] = $oDoc->getDisplayPath(); - - // remove any document data - $oDoc->cleanupDocumentData($oDoc->getId()); // silly - why the redundancy? - } - } - } - $this->commitTransaction(); - $msg = sprintf(_('%d documents expunged.'), count($aSuccessDocuments)); - if (count($aErrorDocuments) != 0) { $msg .= _('Failed to expunge') . ': ' . join(', ', $aErrorDocuments); } - $this->successRedirectToMain($msg); - } -} - -//$d =& new DeletedDocumentsDispatcher; -//$d->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageCleanup.php b/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageCleanup.php deleted file mode 100644 index e9e0872..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageCleanup.php +++ /dev/null @@ -1,166 +0,0 @@ -get('urls/documentRoot'); - -$aIgnore = array( - '.', '..', - 'CVS', - '.empty', - '.htaccess', - '.cvsignore', -); - -$aFoldersToRemove = array(); -$aFilesToRemove = array(); -$aRepoDocumentProblems = array(); -$aRepoFolderProblems = array(); -$aRepoVersionProblems = array(); - -function checkFileVersion($path, $version) { - $fod = KTBrowseUtil::folderOrDocument($path); - if ($fod === false) { - // No document by that name, so no point checking version - // information. - return; - } - return true; -} - -function checkFile($path, $first = true) { - $pattern = "/^(.*)-((?:\d+)\.(?:\d+))$/"; - if (preg_match($pattern, $path, $matches)) { - if (checkFileVersion($matches[1], $matches[2])) { - // If it's a version, then don't check for full path - // below... - return; - } - } - $fod = KTBrowseUtil::folderOrDocument($path); - if ($fod === false) { - $GLOBALS["aFilesToRemove"][] = $path; - return; - } -} - -function checkDirectory($path) { - global $fsPath, $aIgnore; - $fullpath = sprintf("%s/%s", $fsPath, $path); - - if (!is_dir($fullpath)) { - print "Not a directory: $fullpath\n"; - } - - if ($path === '/Deleted') { - // Deleted files handled separately. - return; - } - - if (!empty($path)) { - $fod = KTBrowseUtil::folderOrDocument($path); - if ($fod === false) { - $GLOBALS["aFoldersToRemove"][] = $path; - return; - } - } - - $dh = @opendir($fullpath); - if ($dh === false) { - print "Could not open directory: $fullpath\n"; - } - while (($filename = readdir($dh)) !== false) { - if (in_array($filename, $aIgnore)) { continue; } - $subrelpath = sprintf("%s/%s", $path, $filename); - $subfullpath = sprintf("%s/%s", $fsPath, $subrelpath); - if (is_dir($subfullpath)) { - checkDirectory($subrelpath); - } - if (is_file($subfullpath)) { - checkFile($subrelpath); - } - } -} - -function checkRepoFolder($oFolder) { - global $fsPath, $aRepoFolderProblems; - $sFolderPath = sprintf("%s/%s", $oFolder->getFullPath(), $oFolder->getName()); - $sFullPath = sprintf("%s/%s", $fsPath, $sFolderPath); - if (!is_dir($sFullPath)) { - $aRepoFolderProblems[] = $sFolderPath; - } -} - -function checkRepoDocument($oDocument) { - global $fsPath, $aRepoDocumentProblems; - $sDocumentPath = $oDocument->getStoragePath(); - $sFullPath = sprintf("%s/%s", $fsPath, $sDocumentPath); - if (!is_file($sFullPath)) { - $aRepoDocumentProblems[] = $sDocumentPath; - } - checkRepoVersions($oDocument); -} - -function checkRepoVersions($oDocument) { - global $fsPath, $aRepoVersionProblems; - $table = "document_transactions"; - $aVersions = DBUtil::getResultArrayKey(array("SELECT DISTINCT version FROM $table WHERE document_id = ?", array($oDocument->getID())), "version"); foreach($aVersions as $sVersion) { - if ($sVersion == $oDocument->getVersion()) { - continue; - } - $sDocumentPath = $oDocument->getStoragePath(); - $sFullPath = sprintf("%s/%s-%s", $fsPath, $sDocumentPath, $sVersion); - if (!is_file($sFullPath)) { - $aRepoVersionProblems[] = array($sDocumentPath, $sVersion); - continue; - } - } -} - -class ManageCleanupDispatcher extends KTAdminDispatcher { - function do_main() { - global $aFoldersToRemove; - global $aFilesToRemove; - global $aRepoDocumentProblems; - global $aRepoFolderProblems; - global $aRepoVersionProblems; - - checkDirectory(""); - $aFolders =& Folder::getList(); - foreach ($aFolders as $oFolder) { - checkRepoFolder($oFolder); - } - $aDocuments =& Document::getList(array("status_id = ?", array(LIVE))); - foreach ($aDocuments as $oDocument) { - checkRepoDocument($oDocument); - } - $oTemplate =& $this->oValidator->validateTemplate('ktcore/document/cleanup'); - $oTemplate->setData(array( - 'aFoldersToRemove' => $aFoldersToRemove, - 'aFilesToRemove' => $aFilesToRemove, - 'aRepoDocumentProblems' => $aRepoDocumentProblems, - 'aRepoFolderProblems' => $aRepoFolderProblems, - 'aRepoVersionProblems' => $aRepoVersionProblems, - )); - return $oTemplate->render(); - } -} - -$oDispatcher = new ManageCleanupDispatcher(); -$oDispatcher->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/groupmanagement/groupManagement.php b/presentation/lookAndFeel/knowledgeTree/administration/groupmanagement/groupManagement.php deleted file mode 100644 index 3167d2e..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/groupmanagement/groupManagement.php +++ /dev/null @@ -1,390 +0,0 @@ -aBreadcrumbs[] = array('action' => 'groupManagement', 'name' => _('Group Management')); - $this->oPage->setBreadcrumbDetails(_('select a group')); - $this->oPage->setTitle(_("Group Management")); - - - $name = KTUtil::arrayGet($_REQUEST, 'name'); - $show_all = KTUtil::arrayGet($_REQUEST, 'show_all', false); - $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); - - - $search_fields = array(); - $search_fields[] = new KTStringWidget(_('Group Name'),_("Enter part of the group's name. e.g. ad will match administrators."), 'name', $name, $this->oPage, true); - - if (!empty($name)) { - $search_results =& Group::getList('WHERE name LIKE "%' . DBUtil::escapeSimple($name) . '%"'); - } else if ($show_all !== false) { - $search_results =& Group::getList(); - } - - - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/groupadmin"); - $aTemplateData = array( - "context" => $this, - "search_fields" => $search_fields, - "search_results" => $search_results, - ); - return $oTemplate->render($aTemplateData); - } - - - - function do_editGroup() { - $this->aBreadcrumbs[] = array('action' => 'groupManagement', 'name' => _('Group Management')); - $this->oPage->setBreadcrumbDetails(_('edit group')); - - $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); - $oGroup = Group::get($group_id); - if (PEAR::isError($oGroup) || $oGroup == false) { - $this->errorRedirectToMain(_('Please select a valid group.')); - } - - $this->oPage->setTitle(sprintf(_("Edit Group (%s)"), $oGroup->getName())); - - $edit_fields = array(); - $edit_fields[] = new KTStringWidget(_('Group Name'),_('A short name for the group. e.g. administrators.'), 'group_name', $oGroup->getName(), $this->oPage, true); - $edit_fields[] = new KTCheckboxWidget(_('Unit Administrators'),_('Should all the members of this group be given unit administration privilidges?'), 'is_unitadmin', $oGroup->getUnitAdmin(), $this->oPage, false); - $edit_fields[] = new KTCheckboxWidget(_('System Administrators'),_('Should all the members of this group be given system administration privilidges?'), 'is_sysadmin', $oGroup->getSysAdmin(), $this->oPage, false); - - // grab all units. - $unit = $oGroup->getUnit(); - if ($unit == null) { $unitId = 0; } - else { $unitId = $unit->getID(); } - - - $oUnits = Unit::getList(); - $vocab = array(); - $vocab[0] = _('No Unit'); - foreach ($oUnits as $oUnit) { $vocab[$oUnit->getID()] = $oUnit->getName(); } - $aOptions = array('vocab' => $vocab); - - $edit_fields[] = new KTLookupWidget(_('Unit'),_('Which Unit is this group part of?'), 'unit_id', $unitId, $this->oPage, false, null, null, $aOptions); - - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/editgroup"); - $aTemplateData = array( - "context" => $this, - "edit_fields" => $edit_fields, - "edit_group" => $oGroup, - ); - return $oTemplate->render($aTemplateData); - } - - function do_saveGroup() { - $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); - $oGroup = Group::get($group_id); - if (PEAR::isError($oGroup) || $oGroup == false) { - $this->errorRedirectToMain(_('Please select a valid group.')); - } - $group_name = KTUtil::arrayGet($_REQUEST, 'group_name'); - if (empty($group_name)) { $this->errorRedirectToMain(_('Please specify a name for the group.')); } - $is_unitadmin = KTUtil::arrayGet($_REQUEST, 'is_unitadmin', false); - if ($is_unitadmin !== false) { $is_unitadmin = true; } - $is_sysadmin = KTUtil::arrayGet($_REQUEST, 'is_sysadmin', false); - if ($is_sysadmin !== false) { $is_sysadmin = true; } - - $this->startTransaction(); - - $oGroup->setName($group_name); - $oGroup->setUnitAdmin($is_unitadmin); - $oGroup->setSysAdmin($is_sysadmin); - - $unit_id = KTUtil::arrayGet($_REQUEST, 'unit_id', 0); - if ($unit_id == 0) { // not set, or set to 0. - $oGroup->clearUnit(); // safe. - } else { - $oGroup->setUnit($unit_id); - } - - $res = $oGroup->update(); - if (($res == false) || (PEAR::isError($res))) { return $this->errorRedirectToMain(_('Failed to set group details.')); } - - $this->commitTransaction(); - $this->successRedirectToMain(_('Group details updated.')); - } - - - function do_manageusers() { - $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); - $oGroup = Group::get($group_id); - if ((PEAR::isError($oGroup)) || ($oGroup === false)) { - $this->errorRedirectToMain(_('No such group.')); - } - - $this->aBreadcrumbs[] = array('name' => $oGroup->getName()); - $this->oPage->setBreadcrumbDetails(_('manage members')); - $this->oPage->setTitle(sprintf(_('Manage members of group %s'), $oGroup->getName())); - - - // FIXME replace OptionTransfer.js. me no-likey. - - // FIXME this is hideous. refactor the transfer list stuff completely. - $initJS = 'var optGroup = new OptionTransfer("userSelect","chosenUsers"); ' . - 'function startTrans() { var f = getElement("usergroupform"); ' . - ' optGroup.saveAddedRightOptions("userAdded"); ' . - ' optGroup.saveRemovedRightOptions("userRemoved"); ' . - ' optGroup.init(f); }; ' . - ' addLoadEvent(startTrans); '; - $this->oPage->requireJSStandalone($initJS); - - $aInitialUsers = $oGroup->getMembers(); - $aAllUsers = User::getList(); - - - // FIXME this is massively non-performant for large userbases.. - $aGroupUsers = array(); - $aFreeUsers = array(); - foreach ($aInitialUsers as $oUser) { - $aGroupUsers[$oUser->getId()] = $oUser; - } - foreach ($aAllUsers as $oUser) { - if (!array_key_exists($oUser->getId(), $aGroupUsers)) { - $aFreeUsers[$oUser->getId()] = $oUser; - } - } - - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/groups_manageusers"); - $aTemplateData = array( - "context" => $this, - "edit_group" => $oGroup, - 'unused_users' => $aFreeUsers, - 'group_users' => $aGroupUsers, - ); - return $oTemplate->render($aTemplateData); - } - - - function do_updateUserMembers() { - $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); - $oGroup = Group::get($group_id); - if ((PEAR::isError($oGroup)) || ($oGroup === false)) { - $this->errorRedirectToMain(_('No such group.')); - } - - $userAdded = KTUtil::arrayGet($_REQUEST, 'userAdded',''); - $userRemoved = KTUtil::arrayGet($_REQUEST, 'userRemoved',''); - - - $aUserToAddIDs = explode(",", $userAdded); - $aUserToRemoveIDs = explode(",", $userRemoved); - - $this->startTransaction(); - $usersAdded = array(); - $usersRemoved = array(); - - foreach ($aUserToAddIDs as $iUserId ) { - if ($iUserId > 0) { - $oUser= User::Get($iUserId); - $res = $oGroup->addMember($oUser); - if (PEAR::isError($res) || $res == false) { - $this->errorRedirectToMain(sprintf(_('Unable to add user "%s" to group "%s"'), $oUser->getName(), $oGroup->getName())); - } else { $usersAdded[] = $oUser->getName(); } - } - } - - // Remove groups - foreach ($aUserToRemoveIDs as $iUserId ) { - if ($iUserId > 0) { - $oUser = User::get($iUserId); - $res = $oGroup->removeMember($oUser); - if (PEAR::isError($res) || $res == false) { - $this->errorRedirectToMain(sprintf(_('Unable to remove user "%s" from group "%s"'), $oUser->getName(), $oGroup->getName())); - } else { $usersRemoved[] = $oUser->getName(); } - } - } - - $msg = ''; - if (!empty($usersAdded)) { $msg .= ' ' . _('Added') . ': ' . join(', ', $usersAdded) . ',
'; } - if (!empty($usersRemoved)) { $msg .= ' ' . _('Removed') . ': ' . join(', ',$usersRemoved) . '.'; } - - $this->commitTransaction(); - $this->successRedirectToMain($msg); - } - - - // FIXME copy-paste ... - function do_managesubgroups() { - $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); - $oGroup = Group::get($group_id); - if ((PEAR::isError($oGroup)) || ($oGroup === false)) { - $this->errorRedirectToMain(_('No such group.')); - } - - $this->aBreadcrumbs[] = array('name' => $oGroup->getName()); - $this->oPage->setBreadcrumbDetails(_('manage members')); - $this->oPage->setTitle(sprintf(_('Manage members of %s'), $oGroup->getName())); - - - // FIXME replace OptionTransfer.js. me no-likey. - - // FIXME this is hideous. refactor the transfer list stuff completely. - $initJS = 'var optGroup = new OptionTransfer("groupSelect","chosenGroups"); ' . - 'function startTrans() { var f = getElement("usergroupform"); ' . - ' optGroup.saveAddedRightOptions("groupAdded"); ' . - ' optGroup.saveRemovedRightOptions("groupRemoved"); ' . - ' optGroup.init(f); }; ' . - ' addLoadEvent(startTrans); '; - $this->oPage->requireJSStandalone($initJS); - - $aMemberGroupsUnkeyed = $oGroup->getMemberGroups(); - $aMemberGroups = array(); - $aMemberIDs = array(); - foreach ($aMemberGroupsUnkeyed as $oMemberGroup) { - $aMemberIDs[] = $oMemberGroup->getID(); - $aMemberGroups[$oMemberGroup->getID()] = $oMemberGroup; - } - - $aGroupArray = GroupUtil::buildGroupArray(); - $aAllowedGroupIDs = GroupUtil::filterCyclicalGroups($oGroup->getID(), $aGroupArray); - $aAllowedGroupIDs = array_diff($aAllowedGroupIDs, $aMemberIDs); - $aAllowedGroups = array(); - foreach ($aAllowedGroupIDs as $iAllowedGroupID) { - $aAllowedGroups[$iAllowedGroupID] =& Group::get($iAllowedGroupID); - } - - - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/groups_managesubgroups"); - $aTemplateData = array( - "context" => $this, - "edit_group" => $oGroup, - 'unused_groups' => $aAllowedGroups, - 'group_members' => $aMemberGroups, - ); - return $oTemplate->render($aTemplateData); - } - - function _getUnitName($oGroup) { - $u = $oGroup->getUnit(); - - return $u->getName(); - } - - // FIXME copy-paste ... - function do_updateGroupMembers() { - $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); - $oGroup = Group::get($group_id); - if ((PEAR::isError($oGroup)) || ($oGroup === false)) { - $this->errorRedirectToMain('No such group.'); - } - - $groupAdded = KTUtil::arrayGet($_REQUEST, 'groupAdded',''); - $groupRemoved = KTUtil::arrayGet($_REQUEST, 'groupRemoved',''); - - - $aGroupToAddIDs = explode(",", $groupAdded); - $aGroupToRemoveIDs = explode(",", $groupRemoved); - - $this->startTransaction(); - $groupsAdded = array(); - $groupsRemoved = array(); - - - foreach ($aGroupToAddIDs as $iMemberGroupID ) { - if ($iMemberGroupID > 0) { - $oMemberGroup = Group::get($iMemberGroupID); - $res = $oGroup->addMemberGroup($oMemberGroup); - if (PEAR::isError($res)) { - $this->errorRedirectToMain(sprintf(_("Failed to add %s to %s"), $oMemberGroup->getName(), $oGroup->getName())); - exit(0); - } else { $groupsAdded[] = $oMemberGroup->getName(); } - } - } - - foreach ($aGroupToRemoveIDs as $iMemberGroupID ) { - if ($iMemberGroupID > 0) { - $oMemberGroup = Group::get($iMemberGroupID); - $res = $oGroup->removeMemberGroup($oMemberGroup); - if (PEAR::isError($res)) { - $this->errorRedirectToMain(sprintf(_("Failed to remove %s from %s"), $oMemberGroup->getName(), $oGroup->getName())); - exit(0); - } else { $groupsRemoved[] = $oMemberGroup->getName(); } - } - } - - $msg = ''; - if (!empty($groupsAdded)) { $msg .= ' ' . _('Added') . ': ' . join(', ', $groupsAdded) . ',
'; } - if (!empty($groupsRemoved)) { $msg .= ' '. _('Removed'). ': ' . join(', ',$groupsRemoved) . '.'; } - - $this->commitTransaction(); - - $this->successRedirectToMain($msg); - } - - - function do_addGroup() { - $this->aBreadcrumbs[] = array('action' => 'groupManagement', 'name' => _('Group Management')); - $this->oPage->setBreadcrumbDetails(_('create new group')); - - - $this->oPage->setTitle(_("Create New Group")); - - $edit_fields = array(); - $add_fields[] = new KTStringWidget(_('Group Name'),_('A short name for the group. e.g. administrators.'), 'group_name', null, $this->oPage, true); - $add_fields[] = new KTCheckboxWidget(_('Unit Administrators'),_('Should all the members of this group be given unit administration privilidges?'), 'is_unitadmin', false, $this->oPage, false); - $add_fields[] = new KTCheckboxWidget(_('System Administrators'),_('Should all the members of this group be given system administration privilidges?'), 'is_sysadmin', false, $this->oPage, false); - - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/addgroup"); - $aTemplateData = array( - "context" => $this, - "add_fields" => $add_fields, - ); - return $oTemplate->render($aTemplateData); - } - - function do_createGroup() { - - $group_name = KTUtil::arrayGet($_REQUEST, 'group_name'); - if (empty($group_name)) { $this->errorRedirectToMain(_('Please specify a name for the group.')); } - $is_unitadmin = KTUtil::arrayGet($_REQUEST, 'is_unitadmin', false); - if ($is_unitadmin !== false) { $is_unitadmin = true; } - $is_sysadmin = KTUtil::arrayGet($_REQUEST, 'is_sysadmin', false); - if ($is_sysadmin !== false) { $is_sysadmin = true; } - - $this->startTransaction(); - - $oGroup =& Group::createFromArray(array( - 'sName' => $group_name, - 'bIsUnitAdmin' => $is_unitadmin, - 'bIsSysAdmin' => $is_sysadmin, - )); - //$res = $oGroup->create(); - //if (($res == false) || (PEAR::isError($res))) { return $this->errorRedirectToMain('Failed to create group "' . $group_name . '"'); } - // do i need to "create" - $this->commitTransaction(); - $this->successRedirectToMain(sprintf(_('Group "%s" created.'), $group_name)); - } - - function do_deleteGroup() { - $aErrorOptions = array( - 'redirect_to' => array('main'), - ); - $oGroup = $this->oValidator->validateGroup($_REQUEST['group_id'], $aErrorOptions); - $sGroupName = $oGroup->getName(); - $res = $oGroup->delete(); - $this->oValidator->notError($res, $aErrorOptions); - $this->successRedirectToMain(sprintf(_('Group "%s" deleted.'), $sGroupName)); - } - -} - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/orgmanagement/orgManagement.php b/presentation/lookAndFeel/knowledgeTree/administration/orgmanagement/orgManagement.php deleted file mode 100644 index c3d3181..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/orgmanagement/orgManagement.php +++ /dev/null @@ -1,73 +0,0 @@ -aBreadcrumbs[] = array('action' => 'orgManagement', 'name' => _('Organisation Management')); - $this->oPage->setBreadcrumbDetails(_('select a organisation')); - $this->oPage->setTitle(_("Organisation Management")); - - $org_id= KTUtil::arrayGet($_REQUEST, 'org_id', null); - if ($org_id === null) { $for_edit = false; } - else { $for_edit = true; } - - $org_list =& Organisation::getList(); - - $edit_fields = array(); - $edit_org = null; - if ($for_edit === true) { - $oOrg = Organisation::get($org_id); - if (PEAR::isError($oOrg) || ($oOrg == false)) { $this->errorRedirectToMain(_('Invalid Organisation')); } - $edit_fields[] = new KTStringWidget(_('Organisation Name'),_("The organisation's visible name. e.g. Tech Support"), 'name', $oOrg->getName(), $this->oPage, true); - } - - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/orgadmin"); - $aTemplateData = array( - "context" => $this, - "for_edit" => $for_edit, - "edit_fields" => $edit_fields, - "edit_org" => $oOrg, - "org_list" => $org_list, - ); - return $oTemplate->render($aTemplateData); - } - - function do_updateOrg() { - $org_id = KTUtil::arrayGet($_REQUEST, 'org_id'); - $oOrg = Organisation::get($org_id); - if (PEAR::isError($oOrg) || ($oOrg == false)) { - $this->errorRedirectToMain(_('Please specify an organisation.')); - exit(0); - } - - $org_name = KTUtil::arrayGet($_REQUEST, 'name', null); - if (empty($org_name)) { - $this->errorRedirectToMain(_('Please specify an org name.')); - exit(0); - } - - $this->startTransaction(); - $oOrg->setName($org_name); - $res = $oOrg->update(); - if (PEAR::isError($res)) { - $this->errorRedirectToMain(_('Failed to update org name.')); - exit(0); - } - - $this->commitTransaction(); - $this->successRedirectToMain(_('Org name changed to') . ': "' . $org_name . '"'); - } - -} - - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/permissions/managePermissions.php b/presentation/lookAndFeel/knowledgeTree/administration/permissions/managePermissions.php deleted file mode 100644 index 9a0ada8..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/permissions/managePermissions.php +++ /dev/null @@ -1,68 +0,0 @@ -oPage->setTitle(_('Manage Permissions')); - $this->aBreadcrumbs[] = array('action' => 'managePermissions', 'name' => _('Manage Permissions')); - - $add_fields = array(); - $add_fields[] = new KTStringWidget(_('System Name'),_('The internal name used for the permission. This should never be changed.'), 'name', null, $this->oPage, true); - $add_fields[] = new KTStringWidget(_('Display Name'),_('A short name that is shown to users whenever permissions must be assigned.'), 'human_name', null, $this->oPage, true); - - $oTemplating = new KTTemplating; - $aPermissions =& KTPermission::getList(); - $oTemplate = $oTemplating->loadTemplate("ktcore/manage_permissions"); - $aTemplateData = array( - 'context' => $this, - "permissions" => $aPermissions, - 'add_fields' => $add_fields, - ); - return $oTemplate->render($aTemplateData); - } - - function do_newPermission() { - $name = KTUtil::arrayGet($_REQUEST, 'name'); - $human_name = KTUtil::arrayGet($_REQUEST, 'human_name'); - if (empty($name) || empty($human_name)) { - return $this->errorRedirectToMain(_("Both names not given")); - } - $oPerm = KTPermission::createFromArray(array( - 'name' => $name, - 'humanname' => $human_name, - )); - if (PEAR::isError($oPerm)) { - return $this->errorRedirectToMain(_("Error creating permission")); - } - return $this->successRedirectToMain(_("Permission created")); - } - - function do_deletePermission() { - $id = KTUtil::arrayGet($_REQUEST, 'id'); - if (empty($id)) { - return $this->errorRedirectToMain(_("Both names not given")); - } - $oPerm = KTPermission::get($id); - if (PEAR::isError($oPerm)) { - return $this->errorRedirectToMain(_("Error finding permission")); - } - if ($oPerm->getBuiltIn() === true) { - return $this->errorRedirectToMain(_("Can't delete built-in permission")); - } - $res = $oPerm->delete(); - if (PEAR::isError($res)) { - return $this->errorRedirectToMain(_("Error deleting permission")); - } - return $this->successRedirectToMain(_("Permission deleted")); - } -} - -//$oDispatcher = new ManagePermissionsDispatcher(); -//$oDispatcher->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/rolemanagement/roleManagement.php b/presentation/lookAndFeel/knowledgeTree/administration/rolemanagement/roleManagement.php deleted file mode 100644 index d36c3fa..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/rolemanagement/roleManagement.php +++ /dev/null @@ -1,126 +0,0 @@ -, Jam Warehouse (Pty) Ltd, South Africa - * @package documentmanagement - */ - -require_once(KT_LIB_DIR . '/dispatcher.inc.php'); -require_once(KT_LIB_DIR . '/templating/kt3template.inc.php'); - -require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php'); -require_once(KT_LIB_DIR . "/roles/Role.inc"); - -class RoleAdminDispatcher extends KTAdminDispatcher { - function check() { - return true; - } - - function do_main() { - $this->aBreadcrumbs[] = array('action' => 'roleManagement', 'name' => _('Role Management')); - - $this->oPage->setTitle(_('Role Management')); - - $edit_fields = array(); - $role_id = KTUtil::arrayGet($_REQUEST, 'role_id', null); - $oRole = Role::get($role_id); - if (PEAR::isError($oRole) || ($oRole == false)) { $for_edit = false; } - else { - $for_edit = true; - $edit_fields[] = new KTStringWidget(_('Name'),_('A short, human-readable name for the role.'), 'name', $oRole->getName(), $this->oPage, true); - } - - $aRoles =& Role::getList('id > 0'); - - $add_fields = array(); - $add_fields[] = new KTStringWidget(_('Name'),_('A short, human-readable name for the role.'), 'name', null, $this->oPage, true); - - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate = $oTemplating->loadTemplate('ktcore/principals/roleadmin'); - $oTemplate->setData(array( - "context" => $this, - "add_fields" => $add_fields, - "for_edit" => $for_edit, - 'edit_role' => $oRole, - 'edit_fields' => $edit_fields, - 'roles' => $aRoles, - )); - return $oTemplate; - } - - function do_createRole() { - $name = KTUtil::arrayGet($_REQUEST, 'name', null); - if ($name === null) { - $this->errorRedirectToMain(_('Please give the role a name.')); - } - - $this->startTransaction(); - $oRole = new Role($name); - $res = $oRole->create(); - if (PEAR::isError($res) || ($res == false)) { - $this->errorRedirectToMain(_('Unable to create role.')); - } - - $this->successRedirectToMain(sprintf(_('Role "%s" created.'), $name)); - } - - function do_updateRole() { - $role_id = KTUtil::arrayGet($_REQUEST, 'role_id'); - $oRole = Role::get($role_id); - if (PEAR::isError($oRole) || ($oRole == false)) { - $this->errorRedirectToMain(_('Please select a valid role first.')); - } - - $name = KTUtil::arrayGet($_REQUEST, 'name', null); - if ($name === null) { - $this->errorRedirectToMain(_('Please give the role a name.')); - } - - $this->startTransaction(); - $oRole->setName($name); - $res = $oRole->update(); - if (PEAR::isError($res) || ($res == false)) { - $this->errorRedirectToMain(_('Unable to update role.')); - } - - $this->successRedirectToMain(sprintf(_('Role "%s" updated.'), $name)); - } - - function do_deleteRole() { - $role_id = KTUtil::arrayGet($_REQUEST, 'role_id'); - $oRole = Role::get($role_id); - if (PEAR::isError($oRole) || ($oRole == false)) { - $this->errorRedirectToMain(_('Please select a valid role first.')); - } - $name = $oRole->getName(); - - $this->startTransaction(); - $res = $oRole->delete(); - if (PEAR::isError($res) || ($res == false)) { - $this->errorRedirectToMain(_('Unable to delete the role.') . ' ' . _('Possible cause') . ': ' . $_SESSION['errorMessage']); - } - - $this->successRedirectToMain(sprintf(_('Role "%s" deleted. '), $name)); - } - -} - diff --git a/presentation/lookAndFeel/knowledgeTree/administration/searches/conditions.php b/presentation/lookAndFeel/knowledgeTree/administration/searches/conditions.php deleted file mode 100644 index 12b0435..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/searches/conditions.php +++ /dev/null @@ -1,80 +0,0 @@ -oValidator->validateTemplate('ktcore/search/administration/conditions'); - $oTemplate->setData(array( - 'conditions' => KTSavedSearch::getConditions(), - )); - return $oTemplate->render(); - } - - function do_new() { - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search"); - - $aCriteria = Criteria::getAllCriteria(); - - $aTemplateData = array( - "title" => _("Create a new condition"), - "sNameTitle" => _("Name of condition"), - "aCriteria" => $aCriteria, - "searchButton" => _("Save"), - ); - return $oTemplate->render($aTemplateData); - } - - function do_view() { - - } - - // XXX: Rename to do_save - function do_performSearch() { - $datavars = KTUtil::arrayGet($_REQUEST, 'boolean_search'); - if (!is_array($datavars)) { - $datavars = unserialize($datavars); - } - - if (empty($datavars)) { - $this->errorRedirectToMain(_('You need to have at least 1 condition.')); - } - - $sName = $_REQUEST['name']; - $sNamespace = KTUtil::nameToLocalNamespace('Saved searches', $sName); - - $oSearch = KTSavedSearch::createFromArray(array( - 'name' => $sName, - 'namespace' => $sNamespace, - 'iscondition' => true, - 'iscomplete' => true, - 'userid' => null, - 'search' => $datavars, - )); - - $this->oValidator->notError($oSearch, array( - 'redirect_to' => 'main', - 'message' => _('Search not saved'), - )); - $this->successRedirectToMain(_('Search saved')); - } -} - -$oDispatcher = new KTConditionDispatcher(); -$oDispatcher->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/searches/savedSearch.php b/presentation/lookAndFeel/knowledgeTree/administration/searches/savedSearch.php deleted file mode 100644 index b00482d..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/searches/savedSearch.php +++ /dev/null @@ -1,74 +0,0 @@ -oValidator->validateTemplate('ktcore/search/administration/savedsearches'); - $oTemplate->setData(array( - 'saved_searches' => KTSavedSearch::getList(), - )); - return $oTemplate->render(); - } - - function do_new() { - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search"); - - $aCriteria = Criteria::getAllCriteria(); - - $aTemplateData = array( - "title" => _("Create a new condition"), - "aCriteria" => $aCriteria, - "searchButton" => _("Save"), - ); - return $oTemplate->render($aTemplateData); - } - - function do_view() { - - } - - // XXX: Rename to do_save - function do_performSearch() { - $datavars = KTUtil::arrayGet($_REQUEST, 'boolean_search'); - if (!is_array($datavars)) { - $datavars = unserialize($datavars); - } - - if (empty($datavars)) { - $this->errorRedirectToMain(_('You need to have at least 1 condition.')); - } - - $sName = "Neil's saved search"; - $sNamespace = KTUtil::nameToLocalNamespace('Saved searches', $sName); - - $oSearch = KTSavedSearch::createFromArray(array( - 'name' => $sName, - 'namespace' => $sNamespace, - 'iscondition' => false, - 'iscomplete' => true, - 'userid' => null, - 'search' => $datavars, - )); - - $this->oValidator->notError($oSearch, array( - 'redirect_to' => 'main', - 'message' => _('Search not saved'), - )); - $this->successRedirectToMain(_('Search saved')); - } -} - -$oDispatcher = new KTSavedSearchDispatcher(); -$oDispatcher->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/unitmanagement/unitManagement.php b/presentation/lookAndFeel/knowledgeTree/administration/unitmanagement/unitManagement.php deleted file mode 100644 index d8f4af6..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/unitmanagement/unitManagement.php +++ /dev/null @@ -1,79 +0,0 @@ -aBreadcrumbs[] = array('action' => 'unitManagement', 'name' => _('Unit Management')); - $this->oPage->setBreadcrumbDetails(_('select a unit')); - $this->oPage->setTitle(_("Unit Management")); - - $unit_id= KTUtil::arrayGet($_REQUEST, 'unit_id', null); - if ($unit_id === null) { $for_edit = false; } - else { $for_edit = true; } - - - $add_fields = array(); - $add_fields[] = new KTStringWidget(_('Unit Name'),_("The unit's visible name. e.g. Tech Support"), 'name', null, $this->oPage, true); - - $unit_list =& Unit::getList(); - - $edit_fields = array(); - $edit_unit = null; - if ($for_edit === true) { - $oUnit = Unit::get($unit_id); - $edit_fields[] = new KTStringWidget(_('Unit Name'),_("The unit's visible name. e.g. Tech Support"), 'name', $oUnit->getName(), $this->oPage, true); - } - - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/unitadmin"); - $aTemplateData = array( - "context" => $this, - "add_fields" => $add_fields, - "for_edit" => $for_edit, - "edit_fields" => $edit_fields, - "edit_unit" => $oUnit, - "unit_list" => $unit_list, - ); - return $oTemplate->render($aTemplateData); - } - - function do_updateUnit() { - $unit_id = KTUtil::arrayGet($_REQUEST, 'unit_id'); - $oUnit = Unit::get($unit_id); - if (PEAR::isError($oUnit) || ($oUnit == false)) { - $this->errorRedirectToMain(_('Please specify a unit.')); - exit(0); - } - - $unit_name = KTUtil::arrayGet($_REQUEST, 'name', null); - if (empty($unit_name)) { - $this->errorRedirectToMain(_('Please specify a unit name.')); - exit(0); - } - - $this->startTransaction(); - $oUnit->setName($unit_name); - $res = $oUnit->update(); - if (PEAR::isError($res)) { - $this->errorRedirectToMain(_('Failed to update unit name.')); - exit(0); - } - - $this->commitTransaction(); - $this->successRedirectToMain(sprintf(_('Unit name changed to "%s"'), $unit_name)); - } - -} - - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/usermanagement/userManagement.php b/presentation/lookAndFeel/knowledgeTree/administration/usermanagement/userManagement.php deleted file mode 100644 index 519f8af..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/usermanagement/userManagement.php +++ /dev/null @@ -1,442 +0,0 @@ -aBreadcrumbs[] = array('action' => 'userManagement', 'name' => _('User Management')); - $this->oPage->setBreadcrumbDetails(_('select a user')); - $this->oPage->setTitle(_("User Management")); - - $name = KTUtil::arrayGet($_REQUEST, 'name'); - $show_all = KTUtil::arrayGet($_REQUEST, 'show_all', false); - $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); - - - $search_fields = array(); - $search_fields[] = new KTStringWidget(_('Username'),_("Enter part of the person's username. e.g. ra will match brad."), 'name', $name, $this->oPage, true); - - // FIXME handle group search stuff. - $search_results = null; - if (!empty($name)) { - $search_results =& User::getList('WHERE username LIKE "%' . DBUtil::escapeSimple($name) . '%"'); - } else if ($show_all !== false) { - $search_results =& User::getList(); - } - - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/useradmin"); - $aTemplateData = array( - "context" => $this, - "search_fields" => $search_fields, - "search_results" => $search_results, - ); - return $oTemplate->render($aTemplateData); - } - - - function do_addUser() { - $this->aBreadcrumbs[] = array('action' => 'userManagement', 'name' => _('User Management')); - $this->oPage->setBreadcrumbDetails(_('add a new user')); - $this->oPage->setTitle(_("Modify User Details")); - - $name = KTUtil::arrayGet($_REQUEST, 'name'); - $show_all = KTUtil::arrayGet($_REQUEST, 'show_all', false); - $add_user = KTUtil::arrayGet($_REQUEST, 'add_user', false); - if ($add_user !== false) { $add_user = true; } - $edit_user = KTUtil::arrayGet($_REQUEST, 'edit_user', false); - - - $add_fields = array(); - $add_fields[] = new KTStringWidget(_('Username'),_('The username the user will enter to gain access to the KnowledgeTree. e.g. jsmith'), 'username', null, $this->oPage, true); - $add_fields[] = new KTStringWidget(_('Name'),_('The full name of the user. This is shown in reports and listings. e.g. John Smith'), 'name', null, $this->oPage, true); - $add_fields[] = new KTStringWidget(_('Email Address'), _('The email address of the user. Notifications and alerts are mailed to this address if email notifications is set below. e.g. jsmith@acme.com'), 'email_address', null, $this->oPage, false); - $add_fields[] = new KTCheckboxWidget(_('Email Notifications'), _("If this is specified then the user will have notifications sent to the email address entered above. If it isn't set, then the user will only see notifications on the Dashboard"), 'email_notifications', true, $this->oPage, false); - $add_fields[] = new KTPasswordWidget(_('Password'), _('Specify an initial password for the user.'), 'password', null, $this->oPage, true); - $add_fields[] = new KTPasswordWidget(_('Confirm Password'), _('Confirm the password specified above.'), 'confirm_password', null, $this->oPage, true); - // nice, easy bits. - $add_fields[] = new KTStringWidget(_('Mobile Number'), _("The mobile phone number of the user. If the system is configured to send notifications to cellphones, then this number will be SMS'd with notifications. e.g. 999 9999 999"), 'mobile_number', null, $this->oPage, false); - $add_fields[] = new KTStringWidget(_('Maximum Sessions'), _('As a safety precaution, it is useful to limit the number of times a given account can log in, before logging out. This prevents a single account being used by many different people.'), 'max_sessions', '3', $this->oPage, true); - - $aAuthenticationSources =& KTAuthenticationSource::getList(); - - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/adduser"); - $aTemplateData = array( - "context" => &$this, - "add_fields" => $add_fields, - "authentication_sources" => $aAuthenticationSources, - ); - return $oTemplate->render($aTemplateData); - } - - function do_addUserFromSource() { - $oSource =& KTAuthenticationSource::get($_REQUEST['source_id']); - $sProvider = $oSource->getAuthenticationProvider(); - $oRegistry =& KTAuthenticationProviderRegistry::getSingleton(); - $oProvider =& $oRegistry->getAuthenticationProvider($sProvider); - - $this->aBreadcrumbs[] = array('action' => 'userManagement', 'name' => _('User Management')); - $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'] . '?action=addUser', 'name' => _('add a new user')); - $oProvider->aBreadcrumbs = $this->aBreadcrumbs; - $oProvider->oPage->setBreadcrumbDetails($oSource->getName()); - $oProvider->oPage->setTitle(_("Modify User Details")); - - $oProvider->dispatch(); - exit(0); - } - - function do_editUser() { - $this->aBreadcrumbs[] = array('action' => 'userManagement', 'name' => _('User Management')); - $this->oPage->setBreadcrumbDetails(_('modify user details')); - $this->oPage->setTitle(_("Modify User Details")); - - $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); - $oUser =& User::get($user_id); - - if (PEAR::isError($oUser) || $oUser == false) { - $this->errorRedirectToMain(_('Please select a user first.')); - exit(0); - } - - $this->aBreadcrumbs[] = array('name' => $oUser->getName()); - - $edit_fields = array(); - $edit_fields[] = new KTStringWidget(_('Username'),_('The username the user will enter to gain access to the KnowledgeTree. e.g. jsmith'), 'username', $oUser->getUsername(), $this->oPage, true); - $edit_fields[] = new KTStringWidget(_('Name'), _('The full name of the user. This is shown in reports and listings. e.g. John Smith'), 'name', $oUser->getName(), $this->oPage, true); - $edit_fields[] = new KTStringWidget(_('Email Address'),_('The email address of the user. Notifications and alerts are mailed to this address if email notifications is set below. e.g. jsmith@acme.com'), 'email_address', $oUser->getEmail(), $this->oPage, false); - $edit_fields[] = new KTCheckboxWidget(_('Email Notifications'), _('If this is specified then the user will have notifications sent to the email address entered above. If it is not set, then the user will only see notifications on the Dashboard'), 'email_notifications', $oUser->getEmailNotification(), $this->oPage, false); - $edit_fields[] = new KTStringWidget(_('Mobile Number'),_("The mobile phone number of the user. If the system is configured to send notifications to cellphones, then this number will be SMS'd with notifications. e.g. 999 9999 999"), 'mobile_number', $oUser->getMobile(), $this->oPage, false); - $edit_fields[] = new KTStringWidget(_('Maximum Sessions'), _('As a safety precaution, it is useful to limit the number of times a given account can log in, before logging out. This prevents a single account being used by many different people.'), 'max_sessions', $oUser->getMaxSessions(), $this->oPage, true); - - $oAuthenticationSource = KTAuthenticationSource::getForUser($oUser); - if (is_null($oAuthenticationSource)) { - $oProvider =& new KTBuiltinAuthenticationProvider; - } else { - $sProvider = $oAuthenticationSource->getAuthenticationProvider(); - $oRegistry =& KTAuthenticationProviderRegistry::getSingleton(); - $oProvider = $oRegistry->getAuthenticationProvider($sProvider); - } - - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/edituser"); - $aTemplateData = array( - "context" => $this, - "edit_fields" => $edit_fields, - "edit_user" => $oUser, - "provider" => $oProvider, - "source" => $oAuthenticationSource, - ); - return $oTemplate->render($aTemplateData); - } - - - function do_setPassword() { - $this->aBreadcrumbs[] = array('action' => 'userManagement', 'name' => _('User Management')); - $this->oPage->setBreadcrumbDetails(_('change user password')); - $this->oPage->setTitle(_("Change User Password")); - - $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); - $oUser =& User::get($user_id); - - if (PEAR::isError($oUser) || $oUser == false) { - $this->errorRedirectToMain(_('Please select a user first.')); - exit(0); - } - - $this->aBreadcrumbs[] = array('name' => $oUser->getName()); - - $edit_fields = array(); - $edit_fields[] = new KTPasswordWidget(_('Password'),_('Specify an initial password for the user.'), 'password', null, $this->oPage, true); - $edit_fields[] = new KTPasswordWidget(_('Confirm Password'),_('Confirm the password specified above.'), 'confirm_password', null, $this->oPage, true); - - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/updatepassword"); - $aTemplateData = array( - "context" => $this, - "edit_fields" => $edit_fields, - "edit_user" => $oUser, - ); - return $oTemplate->render($aTemplateData); - } - - function do_updatePassword() { - $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); - - $password = KTUtil::arrayGet($_REQUEST, 'password'); - $confirm_password = KTUtil::arrayGet($_REQUEST, 'confirm_password'); - - if (empty($password)) { - $this->errorRedirectToMain(_("You must specify a password for the user.")); - } else if ($password !== $confirm_password) { - $this->errorRedirectToMain(_("The passwords you specified do not match.")); - } - // FIXME more validation would be useful. - // validated and ready.. - $this->startTransaction(); - - $oUser =& User::get($user_id); - if (PEAR::isError($oUser) || $oUser == false) { - $this->errorRedirectToMain(_("Please select a user to modify first.")); - } - - - // FIXME this almost certainly has side-effects. do we _really_ want - $oUser->setPassword(md5($password)); // - - $res = $oUser->update(); - //$res = $oUser->doLimitedUpdate(); // ignores a fix blacklist of items. - - - if (PEAR::isError($res) || ($res == false)) { - $this->errorRedirectoToMain(_('Failed to update user.')); - } - - $this->commitTransaction(); - $this->successRedirectToMain(_('User information updated.')); - - } - - function do_editUserSource() { - $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); - $oUser =& $this->oValidator->validateUser($user_id); - $this->aBreadcrumbs[] = array('name' => $oUser->getName()); - - $oAuthenticationSource = KTAuthenticationSource::getForUser($oUser); - if (is_null($oAuthenticationSource)) { - $oProvider =& new KTBuiltinAuthenticationProvider; - } else { - $sProvider = $oAuthenticationSource->getAuthenticationProvider(); - $oRegistry =& KTAuthenticationProviderRegistry::getSingleton(); - $oProvider = $oRegistry->getAuthenticationProvider($sProvider); - } - - $oProvider->dispatch(); - exit(); - } - - function do_editgroups() { - $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); - $oUser = User::get($user_id); - if ((PEAR::isError($oUser)) || ($oUser === false)) { - $this->errorRedirectToMain(_('No such user.')); - } - - $this->aBreadcrumbs[] = array('name' => $oUser->getName()); - $this->oPage->setBreadcrumbDetails(_('edit groups')); - $this->oPage->setTitle(sprintf(_("Edit %s's groups"), $oUser->getName())); - // generate a list of groups this user is authorised to assign. - - /* FIXME there is a nasty side-effect: if a user cannot assign a group - * to a user, and that user _had_ that group pre-edit, - * then their privilidges are revoked. - * is there _any_ way to fix that? - */ - - // FIXME move this to a transfer widget - // FIXME replace OptionTransfer.js. me no-likey. - - // FIXME this is hideous. refactor the transfer list stuff completely. - $initJS = 'var optGroup = new OptionTransfer("groupSelect[]","chosenGroups[]"); ' . - 'function startTrans() { var f = getElement("usergroupform"); ' . - ' optGroup.saveAddedRightOptions("groupAdded"); ' . - ' optGroup.saveRemovedRightOptions("groupRemoved"); ' . - ' optGroup.init(f); }; ' . - ' addLoadEvent(startTrans); '; - $this->oPage->requireJSStandalone($initJS); - - $aInitialGroups = GroupUtil::listGroupsForUser($oUser); - $aAllGroups = GroupUtil::listGroups(); - - $aUserGroups = array(); - $aFreeGroups = array(); - foreach ($aInitialGroups as $oGroup) { - $aUserGroups[$oGroup->getId()] = $oGroup; - } - foreach ($aAllGroups as $oGroup) { - if (!array_key_exists($oGroup->getId(), $aUserGroups)) { - $aFreeGroups[$oGroup->getId()] = $oGroup; - } - } - - $oTemplating = new KTTemplating; - $oTemplate = $oTemplating->loadTemplate("ktcore/principals/usergroups"); - $aTemplateData = array( - "context" => $this, - "unused_groups" => $aFreeGroups, - "user_groups" => $aUserGroups, - "edit_user" => $oUser, - ); - return $oTemplate->render($aTemplateData); - } - - function do_saveUser() { - $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); - - $name = KTUtil::arrayGet($_REQUEST, 'name'); - $username = KTUtil::arrayGet($_REQUEST, 'username'); - $email_address = KTUtil::arrayGet($_REQUEST, 'email_address'); - $email_notifications = KTUtil::arrayGet($_REQUEST, 'email_notifications', false); - if ($email_notifications !== false) $email_notifications = true; - $mobile_number = KTUtil::arrayGet($_REQUEST, 'mobile_number'); - $max_sessions = KTUtil::arrayGet($_REQUEST, 'max_sessions', '3'); - // FIXME more validation would be useful. - // validated and ready.. - $this->startTransaction(); - - $oUser =& User::get($user_id); - if (PEAR::isError($oUser) || $oUser == false) { - $this->errorRedirectToMain(_("Please select a user to modify first.")); - } - - $oUser->setName($name); - $oUser->setUsername($username); // ? - $oUser->setEmail($email_address); - $oUser->setEmailNotification($email_notifications); - $oUser->setMobile($mobile_number); - $oUser->setMaxSessions($max_sessions); - - // old system used the very evil store.php. - // here we need to _force_ a limited update of the object, via a db statement. - // - // $res = $oUser->update(); - $res = $oUser->doLimitedUpdate(); // ignores a fix blacklist of items. - - - - if (PEAR::isError($res) || ($res == false)) { - $this->errorRedirectoToMain(_('Failed to update user.')); - } - - $this->commitTransaction(); - $this->successRedirectToMain(_('User information updated.')); - } - - function do_createUser() { - // FIXME generate and pass the error stack to adduser. - - $name = KTUtil::arrayGet($_REQUEST, 'name'); - if (empty($name)) { $this->errorRedirectToMain(_('You must specify a name for the user.')); } - $username = KTUtil::arrayGet($_REQUEST, 'username'); - if (empty($name)) { $this->errorRedirectToMain(_('You must specify a new username.')); } - // FIXME check for non-clashing usernames. - - $email_address = KTUtil::arrayGet($_REQUEST, 'email_address'); - $email_notifications = KTUtil::arrayGet($_REQUEST, 'email_notifications', false); - if ($email_notifications !== false) $email_notifications = true; - $mobile_number = KTUtil::arrayGet($_REQUEST, 'mobile_number'); - $max_sessions = KTUtil::arrayGet($_REQUEST, 'max_sessions', '3'); - // FIXME check for numeric max_sessions... db-error else? - $password = KTUtil::arrayGet($_REQUEST, 'password'); - $confirm_password = KTUtil::arrayGet($_REQUEST, 'confirm_password'); - - if (empty($password)) { - $this->errorRedirectToMain(_("You must specify a password for the user.")); - } else if ($password !== $confirm_password) { - $this->errorRedirectToMain(_("The passwords you specified do not match.")); - } - - $oUser =& User::createFromArray(array( - "sUsername" => $username, - "sName" => $name, - "sPassword" => md5($password), - "iQuotaMax" => 0, - "iQuotaCurrent" => 0, - "sEmail" => $email_address, - "bEmailNotification" => $email_notifications, - "bSmsNotification" => false, // FIXME do we auto-act if the user has a mobile? - "iMaxSessions" => $max_sessions, - )); - - if (PEAR::isError($oUser) || ($oUser == false)) { - $this->errorRedirectToMain(_("failed to create user.")); - exit(0); - } - - $oUser->create(); - - $this->successRedirectToMain(_('Created new user') . ': "' . $oUser->getUsername() . '"'); - } - - function do_deleteUser() { - $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); - $oUser = User::get($user_id); - if ((PEAR::isError($oUser)) || ($oUser === false)) { - $this->errorRedirectToMain(_('Please select a user first.')); - } - $oUser->delete(); - - $this->successRedirectToMain(_('User deleted') . ': ' . $oUser->getName()); - } - - function do_updateGroups() { - $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); - $oUser = User::get($user_id); - if ((PEAR::isError($oUser)) || ($oUser === false)) { - $this->errorRedirectToMain(_('Please select a user first.')); - } - $groupAdded = KTUtil::arrayGet($_REQUEST, 'groupAdded',''); - $groupRemoved = KTUtil::arrayGet($_REQUEST, 'groupRemoved',''); - - - $aGroupToAddIDs = explode(",", $groupAdded); - $aGroupToRemoveIDs = explode(",", $groupRemoved); - - // FIXME we need to ensure that only groups which are allocatable by the admin are added here. - - // FIXME what groups are _allocatable_? - - $this->startTransaction(); - $groupsAdded = array(); - $groupsRemoved = array(); - - foreach ($aGroupToAddIDs as $iGroupID ) { - if ($iGroupID > 0) { - $oGroup = Group::get($iGroupID); - $res = $oGroup->addMember($oUser); - if (PEAR::isError($res) || $res == false) { - $this->errorRedirectToMain(sprintf(_('Unable to add user to group "%s"'), $oGroup->getName())); - } else { $groupsAdded[] = $oGroup->getName(); } - } - } - - // Remove groups - foreach ($aGroupToRemoveIDs as $iGroupID ) { - if ($iGroupID > 0) { - $oGroup = Group::get($iGroupID); - $res = $oGroup->removeMember($oUser); - if (PEAR::isError($res) || $res == false) { - $this->errorRedirectToMain(sprintf(_('Unable to remove user from group "%s"'), $oGroup->getName())); - } else { $groupsRemoved[] = $oGroup->getName(); } - } - } - - $msg = ''; - if (!empty($groupsAdded)) { $msg .= ' ' . _('Added to groups') . ': ' . join(', ', $groupsAdded) . ',
'; } - if (!empty($groupsRemoved)) { $msg .= ' ' . _('Removed from groups') . ': ' . join(', ',$groupsRemoved) . '.'; } - - $this->commitTransaction(); - $this->successRedirectToMain($msg); - } - -} - -//$oDispatcher = new KTUserAdminDispatcher (); -//$oDispatcher->dispatch(); - -?> diff --git a/presentation/lookAndFeel/knowledgeTree/administration/workflow/workflows.php b/presentation/lookAndFeel/knowledgeTree/administration/workflow/workflows.php deleted file mode 100644 index 03b1112..0000000 --- a/presentation/lookAndFeel/knowledgeTree/administration/workflow/workflows.php +++ /dev/null @@ -1,492 +0,0 @@ -aBreadcrumbs[] = array( - 'action' => 'manageWorkflows', - 'name' => _('Workflows'), - ); - - $add_fields = array(); - $add_fields[] = new KTStringWidget(_('Name'),_('A human-readable name for the workflow.'), 'fName', null, $this->oPage, true); - - $oTemplating =& KTTemplating::getSingleton(); - $oTemplate =& $oTemplating->loadTemplate('ktcore/workflow/listWorkflows'); - $oTemplate->setData(array( - 'context' => $this, - 'aWorkflow' => KTWorkflow::getList(), - 'add_fields' => $add_fields, - )); - return $oTemplate; - } - // }}} - - // {{{ do_editWorkflow - function do_editWorkflow() { - - $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/editWorkflow'); - $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); - - $aStates = KTWorkflowState::getByWorkflow($oWorkflow); - $aPermissions = KTPermission::getList(); - - $edit_fields = array(); - $edit_fields[] = new KTStringWidget(_('Name'), _('A human-readable name for the workflow.'), 'fName', $oWorkflow->getName(), $this->oPage, true); - $aOptions = array(); - $vocab = array(); - $vocab[0] = 'None'; - foreach($aStates as $state) { - $vocab[$state->getId()] = $state->getName(); - } - $aOptions['vocab'] = $vocab; - $edit_fields[] = new KTLookupWidget(_('Starting State'), _('When a document has this workflow applied to it, to which state should it initially be set'), 'fStartStateId', $oWorkflow->getStartStateId(), $this->oPage, false, null, null, $aOptions); - - $add_state_fields = array(); - $add_state_fields[] = new KTStringWidget(_('Name'), _('A human-readable name for the state.'), 'fName', null, $this->oPage, true); - - - $add_transition_fields = array(); - $add_transition_fields[] = new KTStringWidget(_('Name'), _('A human-readable name for the state.'), 'fName', null, $this->oPage, true); - $aOptions = array(); - $vocab = array(); - foreach($aStates as $state) { - $vocab[$state->getId()] = $state->getName(); - } - $aOptions['vocab'] = $vocab; - $add_transition_fields[] = new KTLookupWidget(_('Destination State'), _('Once this transition is complete, which state should the document be in?'), 'fTargetStateId', $oWorkflow->getStartStateId(), $this->oPage, true, null, null, $aOptions); - $aOptions = array(); - $vocab = array(); - foreach($aPermissions as $permission) { - $vocab[$permission->getId()] = $permission->getHumanName(); - } - $aOptions['vocab'] = $vocab; - $add_transition_fields[] = new KTLookupWidget(_('Guard Permission.'), _('Which permission must the user have in order to follow this transition?'), 'fPermissionId', $oWorkflow->getStartStateId(), $this->oPage, true, null, null, $aOptions); - - $this->aBreadcrumbs[] = array( - 'action' => 'manageWorkflows', - 'name' => _('Workflows'), - ); - $this->aBreadcrumbs[] = array( - 'action' => 'manageWorkflows', - 'query' => 'action=editWorkflow&fWorkflowId=' . $oWorkflow->getId(), - 'name' => $oWorkflow->getName(), - ); - $oTemplate->setData(array( - 'oWorkflow' => $oWorkflow, - 'aStates' => $aStates, - 'aTransitions' => KTWorkflowTransition::getByWorkflow($oWorkflow), - 'aPermissions' => $aPermissions, - 'aActions' => KTDocumentActionUtil::getAllDocumentActions(), - 'aActionsSelected' => KTWorkflowUtil::getControlledActionsForWorkflow($oWorkflow), - - // fields - 'edit_fields' => $edit_fields, - 'add_state_fields' => $add_state_fields, - 'add_transition_fields' => $add_transition_fields, - )); - return $oTemplate; - } - // }}} - - // {{{ do_saveWorkflow - function do_saveWorkflow() { - $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); - $aOptions = array( - 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()), - ); - $oWorkflow->setName($_REQUEST['fName']); - $oWorkflow->setHumanName($_REQUEST['fName']); - if (!empty($_REQUEST['fStartStateId'])) { - $oWorkflow->setStartStateId($_REQUEST['fStartStateId']); - } else { - $oWorkflow->setStartStateId(null); - } - $res = $oWorkflow->update(); - $this->oValidator->notErrorFalse($res, array( - 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()), - 'message' => _('Error saving workflow'), - )); - $this->successRedirectTo('editWorkflow', _('Changes saved'), 'fWorkflowId=' . $oWorkflow->getId()); - exit(0); - } - // }}} - - // {{{ do_newWorkflow - function do_newWorkflow() { - $res = KTWorkflow::createFromArray(array( - 'name' => $_REQUEST['fName'], - 'humanname' => $_REQUEST['fName'], - )); - $this->oValidator->notError($res, array( - 'redirect_to' => array('main'), - 'message' => _('Could not create workflow'), - )); - $this->successRedirectTo('editWorkflow', _('Workflow created'), 'fWorkflowId=' . $res->getId()); - exit(0); - } - // }}} - - // {{{ do_setWorkflowActions - function do_setWorkflowActions() { - $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); - $res = KTWorkflowUtil::setControlledActionsForWorkflow($oWorkflow, $_REQUEST['fActions']); - $this->oValidator->notErrorFalse($res, array( - 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()), - 'message' => _('Error saving workflow controlled actions'), - )); - $this->successRedirectTo('editWorkflow', _('Changes saved'), 'fWorkflowId=' . $oWorkflow->getId()); - exit(0); - } - // }}} - - // }}} - - // {{{ STATE HANDLING - // - // {{{ do_newState - function do_newState() { - $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); - $oState = KTWorkflowState::createFromArray(array( - 'workflowid' => $oWorkflow->getId(), - 'name' => $_REQUEST['fName'], - 'humanname' => $_REQUEST['fName'], - )); - $this->oValidator->notError($oState, array( - 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()), - 'message' => _('Could not create workflow state'), - )); - $this->successRedirectTo('editState', _('Workflow state created'), 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()); - exit(0); - } - // }}} - - // {{{ do_editState - function do_editState() { - $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/editState'); - $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); - $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fStateId']); - $aTransitionsTo =& KTWorkflowTransition::getByTargetState($oState); - $aTransitionIdsTo = array(); - foreach ($aTransitionsTo as $oTransition) { - $aTransitionIdsTo[] = $oTransition->getId(); - } - $aAllTransitions =& KTWorkflowTransition::getByWorkflow($oWorkflow); - $aTransitions = array(); - foreach ($aAllTransitions as $oTransition) { - if (!in_array($oTransition->getId(), $aTransitionIdsTo)) { - $aTransitions[] = $oTransition; - } - } - $aTransitionsSelected = KTWorkflowUtil::getTransitionsFrom($oState, array('ids' => true)); - $this->aBreadcrumbs[] = array( - 'action' => 'manageWorkflows', - 'name' => _('Workflows'), - ); - $this->aBreadcrumbs[] = array( - 'action' => 'manageWorkflows', - 'query' => 'action=editWorkflow&fWorkflowId=' . $oWorkflow->getId(), - 'name' => $oWorkflow->getName(), - ); - $this->oPage->setBreadcrumbDetails(_('state') . ': ' . $oState->getName()); - - $aInformed = KTWorkflowUtil::getInformedForState($oState); - $oTemplate->setData(array( - 'oWorkflow' => $oWorkflow, - 'oState' => $oState, - 'oNotifyRole' => $oRole, - 'aTransitionsTo' => $aTransitionsTo, - 'aTransitions' => $aTransitions, - 'aTransitionsSelected' => $aTransitionsSelected, - 'aActions' => KTDocumentActionUtil::getDocumentActionsByNames(KTWorkflowUtil::getControlledActionsForWorkflow($oWorkflow)), - 'aActionsSelected' => KTWorkflowUtil::getEnabledActionsForState($oState), - 'aGroups' => Group::getList(), - 'aRoles' => Role::getList(), - 'aUsers' => User::getList(), - 'aInformed' => $aInformed, - )); - return $oTemplate; - } - // }}} - - // {{{ do_saveState - function do_saveState() { - $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); - $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fStateId']); - $oState->setName($_REQUEST['fName']); - $oState->setHumanName($_REQUEST['fName']); - $res = $oState->update(); - $this->oValidator->notErrorFalse($res, array( - 'redirect_to' => array('editState', 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()), - 'message' => _('Error saving state'), - )); - $this->successRedirectTo('editState', _('Changes saved'), 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()); - exit(0); - } - // }}} - - // {{{ do_saveTransitions - function do_saveTransitions() { - $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); - $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fStateId']); - $res = KTWorkflowUtil::saveTransitionsFrom($oState, $_REQUEST['fTransitionIds']); - $this->oValidator->notErrorFalse($res, array( - 'redirect_to' => array('editState', 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()), - 'message' => _('Error saving transitions'), - )); - $this->successRedirectTo('editState', _('Changes saved'), 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()); - exit(0); - } - // }}} - - // {{{ do_setStateActions - function do_setStateActions() { - $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); - $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fStateId']); - $res = KTWorkflowUtil::setEnabledActionsForState($oState, $_REQUEST['fActions']); - $this->oValidator->notErrorFalse($res, array( - 'redirect_to' => array('editState', 'fWorkflowId=' . $oWorkflow->getId(), '&fStateId=' . $oState->getId()), - 'message' => _('Error saving state enabled actions'), - )); - $this->successRedirectTo('editState', _('Actions set'), 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()); - exit(0); - } - // }}} - - // {{{ do_saveInform - function do_saveInform() { - $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); - $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fStateId']); - $sTargetAction = 'editState'; - $sTargetParams = 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId(); - $aRoleIds = KTUtil::arrayGet($_REQUEST, 'fRoleIds'); - if (empty($aRoleIds)) { - $aRoleIds = array(); - } - if (!is_array($aRoleIds)) { - $this->errorRedirectTo($sTargetAction, _('Invalid roles specified'), $sTargetParams); - } - $aGroupIds = KTUtil::arrayGet($_REQUEST, 'fGroupIds'); - if (empty($aGroupIds)) { - $aGroupIds = array(); - } - if (!is_array($aGroupIds)) { - $this->errorRedirectTo($sTargetAction, _('Invalid groups specified'), $sTargetParams); - } - $aUserIds = KTUtil::arrayGet($_REQUEST, 'fUserIds'); - if (empty($aUserIds)) { - $aUserIds = array(); - } - if (!is_array($aUserIds)) { - $this->errorRedirectTo($sTargetAction, _('Invalid users specified'), $sTargetParams); - } - $aAllowed = array( - 'role' => $aRoleIds, - 'group' => $aGroupIds, - 'user' => $aUserIds, - ); - KTWorkflowUtil::setInformedForState($oState, $aAllowed); - $this->successRedirectTo($sTargetAction, _('Changes saved'), $sTargetParams); - } - // }}} - - // }}} - - // {{{ TRANSITION HANDLING - // - // {{{ do_newTransition - function do_newTransition() { - $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); - $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fTargetStateId']); - $iPermissionId = KTUtil::arrayGet($_REQUEST, 'fPermissionId'); - $iGroupId = KTUtil::arrayGet($_REQUEST, 'fGroupId'); - $iRoleId = KTUtil::arrayGet($_REQUEST, 'fRoleId'); - if ($iPermissionId) { - $this->oValidator->validatePermission($_REQUEST['fPermissionId']); - } - if ($iGroupId) { - $this->oValidator->validateGroup($_REQUEST['fGroupId']); - } - if ($iRoleId) { - $this->oValidator->validateRole($_REQUEST['fRoleId']); - } - $res = KTWorkflowTransition::createFromArray(array( - 'workflowid' => $oWorkflow->getId(), - 'name' => $_REQUEST['fName'], - 'humanname' => $_REQUEST['fName'], - 'targetstateid' => $oState->getId(), - 'guardpermissionid' => $iPermissionId, - 'guardgroupid' => $iGroupId, - 'guardroleid' => $iRoleId, - )); - $this->oValidator->notError($res, array( - 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()), - 'message' => _('Could not create workflow transition'), - )); - $this->successRedirectTo('editWorkflow', _('Workflow transition created'), 'fWorkflowId=' . $oWorkflow->getId()); - exit(0); - } - // }}} - - // {{{ do_editTransition - function do_editTransition() { - $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/editTransition'); - $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); - $oTransition =& $this->oValidator->validateWorkflowTransition($_REQUEST['fTransitionId']); - - $aStates = KTWorkflowState::getByWorkflow($oWorkflow); - $aPermissions = KTPermission::getList(); - $aGroups = Group::getList(); - $aRoles = Role::getList(); - $aConditions = KTSavedSearch::getConditions(); - - $edit_fields = array(); - $edit_fields[] = new KTStringWidget(_('Name'), _('A human-readable name for the state.'), 'fName', $oTransition->getName(), $this->oPage, true); - $aOptions = array(); - $vocab = array(); - foreach($aStates as $state) { - $vocab[$state->getId()] = $state->getName(); - } - $aOptions['vocab'] = $vocab; - $edit_fields[] = new KTLookupWidget(_('Destination State'), _('Once this transition is complete, which state should the document be in?'), 'fTargetStateId', $oTransition->getTargetStateId(), $this->oPage, true, null, null, $aOptions); - $aOptions = array(); - $vocab = array(); - $vocab[0] = 'None'; - foreach($aPermissions as $permission) { - $vocab[$permission->getId()] = $permission->getHumanName(); - } - $aOptions['vocab'] = $vocab; - $edit_fields[] = new KTLookupWidget(_('Guard Permission.'), _('Which permission must the user have in order to follow this transition?'), 'fPermissionId', $oTransition->getGuardPermissionId(), $this->oPage, true, null, null, $aOptions); - $aOptions = array(); - $vocab = array(); - $vocab[0] = 'None'; - foreach($aGroups as $group) { - $vocab[$group->getId()] = $group->getName(); - } - $aOptions['vocab'] = $vocab; - $edit_fields[] = new KTLookupWidget(_('Guard Group.'), _('Which group must the user belong to in order to follow this transition?'), 'fGroupId', $oTransition->getGuardGroupId(), $this->oPage, false, null, null, $aOptions); - $aOptions = array(); - $vocab = array(); - $vocab[0] = 'None'; - foreach($aRoles as $role) { - $vocab[$role->getId()] = $role->getName(); - } - $aOptions['vocab'] = $vocab; - $edit_fields[] = new KTLookupWidget(_('Guard Role.'), _('Which role must the user have in order to follow this transition?'), 'fRoleId', $oTransition->getGuardRoleId(), $this->oPage, false, null, null, $aOptions); - - if (!empty($aConditions)) { - $aOptions = array(); - $vocab = array(); - $vocab[0] = 'None'; - foreach($aConditions as $condition) { - $vocab[$condition->getId()] = $condition->getName(); - } - $aOptions['vocab'] = $vocab; - $edit_fields[] = new KTLookupWidget(_('Guard Condition.'), _('Which condition (stored search) must be satisfied before the transition can take place?'), 'fConditionId', $oTransition->getGuardConditionId(), $this->oPage, false, null, null, $aOptions); - } - - $this->aBreadcrumbs[] = array( - 'action' => 'manageWorkflows', - 'name' => _('Workflows'), - ); - $this->aBreadcrumbs[] = array( - 'action' => 'manageWorkflows', - 'query' => 'action=editWorkflow&fWorkflowId=' . $oWorkflow->getId(), - 'name' => $oWorkflow->getName(), - ); - $this->aBreadcrumbs[] = array( - 'action' => 'manageWorkflows', - 'query' => 'action=editTransition&fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId(), - 'name' => $oTransition->getName(), - ); - $oTemplate->setData(array( - 'oWorkflow' => $oWorkflow, - 'oTransition' => $oTransition, - 'aStates' => $aStates, - 'aPermissions' => $aPermissions, - 'aGroups' => $aGroups, - 'aRoles' => $aRoles, - 'aConditions' => $aConditions, - - // fields - - 'edit_fields' => $edit_fields, - )); - return $oTemplate; - } - // }}} - - // {{{ do_saveTransition - function do_saveTransition() { - $aRequest = $this->oValidator->validateDict($_REQUEST, array( - 'fWorkflowId' => array('type' => 'workflow'), - 'fTransitionId' => array('type' => 'workflowtransition'), - )); - $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']); - $oTransition =& $this->oValidator->validateWorkflowTransition($_REQUEST['fTransitionId']); - $oState =& $this->oValidator->validateWorkflowState($_REQUEST['fTargetStateId']); - $iPermissionId = KTUtil::arrayGet($_REQUEST, 'fPermissionId', null); - $iGroupId = KTUtil::arrayGet($_REQUEST, 'fGroupId', null); - $iRoleId = KTUtil::arrayGet($_REQUEST, 'fRoleId', null); - $iConditionId = KTUtil::arrayGet($_REQUEST, 'fConditionId', null); - if ($iPermissionId) { - $this->oValidator->validatePermission($_REQUEST['fPermissionId']); - } - if ($iGroupId) { - $this->oValidator->validateGroup($_REQUEST['fGroupId']); - } - if ($iRoleId) { - $this->oValidator->validateRole($_REQUEST['fRoleId']); - } - if ($iConditionId) { - $this->oValidator->validateCondition($_REQUEST['fConditionId']); - } - $oTransition->updateFromArray(array( - 'workflowid' => $oWorkflow->getId(), - 'name' => $_REQUEST['fName'], - 'humanname' => $_REQUEST['fName'], - 'targetstateid' => $oState->getId(), - 'guardpermissionid' => $iPermissionId, - 'guardgroupid' => $iGroupId, - 'guardroleid' => $iRoleId, - 'guardconditionid' => $iConditionId, - )); - $res = $oTransition->update(); - $this->oValidator->notErrorFalse($res, array( - 'redirect_to' => array('editTransition', 'fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId()), - 'message' => _('Error saving transition'), - )); - $this->successRedirectTo('editTransition', _('Changes saved'), 'fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId()); - exit(0); - } - // }}} - - // }}} - -} - -//$d =& new KTWorkflowDispatcher; -//$d->dispatch(); - -?> -- libgit2 0.21.4