diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index dd84ea7..6867cf8 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,38 +1,38 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: '' -assignees: '' - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] - -**Additional context** -Add any other context about the problem here. +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index bbcbbe7..72718d5 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,20 +1,20 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: '' -assignees: '' - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/ajax/asynchronousdatas.php b/ajax/asynchronousdatas.php index 5303fb2..879fe59 100644 --- a/ajax/asynchronousdatas.php +++ b/ajax/asynchronousdatas.php @@ -1,47 +1,47 @@ -getFromDB( $datas['id'] ) && $asyncdata->fields['state'] == PluginProcessmakerCrontaskaction::WAITING_DATA) { - $initialdatas = json_decode($asyncdata->fields['postdata'], true); - $initialdatas['form'] = array_merge( $initialdatas['form'], $datas['form'] ); - $postdata = json_encode($initialdatas, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE); - $asyncdata->update( [ 'id' => $datas['id'], 'state' => PluginProcessmakerCrontaskaction::DATA_READY, 'postdata' => $postdata ] ); - $ret = [ 'code' => '0', 'message' => 'Done' ]; - } else { - $ret = [ 'code' => '2', 'message' => 'Case is not existing, or state is not WAITING_DATA' ]; - } - - break; - default: - $ret = [ 'code' => '1', 'message' => 'Method '.$_SERVER['REQUEST_METHOD'].' not supported' ]; - } - - echo json_encode( $ret, JSON_HEX_APOS | JSON_HEX_QUOT ); - - } -} +getFromDB( $datas['id'] ) && $asyncdata->fields['state'] == PluginProcessmakerCrontaskaction::WAITING_DATA) { + $initialdatas = json_decode($asyncdata->fields['postdata'], true); + $initialdatas['form'] = array_merge( $initialdatas['form'], $datas['form'] ); + $postdata = json_encode($initialdatas, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE); + $asyncdata->update( [ 'id' => $datas['id'], 'state' => PluginProcessmakerCrontaskaction::DATA_READY, 'postdata' => $postdata ] ); + $ret = [ 'code' => '0', 'message' => 'Done' ]; + } else { + $ret = [ 'code' => '2', 'message' => 'Case is not existing, or state is not WAITING_DATA' ]; + } + + break; + default: + $ret = [ 'code' => '1', 'message' => 'Method '.$_SERVER['REQUEST_METHOD'].' not supported' ]; + } + + echo json_encode( $ret, JSON_HEX_APOS | JSON_HEX_QUOT ); + + } +} diff --git a/ajax/dropdownProcesses.php b/ajax/dropdownProcesses.php index c9c585e..05794a2 100644 --- a/ajax/dropdownProcesses.php +++ b/ajax/dropdownProcesses.php @@ -1,89 +1,89 @@ - 0, - 'text' => $_REQUEST['emptylabel']]); - } - } -} - -$processall = (isset($_REQUEST['specific_tags']['process_restrict']) && !$_REQUEST['specific_tags']['process_restrict']); -$count_cases_per_item = isset($_REQUEST['specific_tags']['count_cases_per_item']) ? $_REQUEST['specific_tags']['count_cases_per_item'] : []; - -$result = PluginProcessmakerProcess::getSqlSearchResult(false, $search); - -//if ($DB->numrows($result)) { -// while ($data = $DB->fetch_array($result)) { -//if ($result->numrows()) { - foreach ($result as $data) { - $process_entities = PluginProcessmakerProcess::getEntitiesForProfileByProcess($data["id"], $_SESSION['glpiactiveprofile']['id'], true); - $can_add = $data['max_cases_per_item'] == 0 || !isset($count_cases_per_item[$data["id"]]) || $count_cases_per_item[$data["id"]] < $data['max_cases_per_item']; - if ($processall - || ($data['maintenance'] != 1 - && in_array( $_REQUEST["entity_restrict"], $process_entities) - && $can_add) ) { - - array_push( $processes, ['id' => $data["id"], - 'text' => $data["name"] - ]); - $count++; - } - } -//} - -$ret['results'] = $processes; -$ret['count'] = $count; -echo json_encode($ret); + 0, + 'text' => $_REQUEST['emptylabel']]); + } + } +} + +$processall = (isset($_REQUEST['specific_tags']['process_restrict']) && !$_REQUEST['specific_tags']['process_restrict']); +$count_cases_per_item = isset($_REQUEST['specific_tags']['count_cases_per_item']) ? $_REQUEST['specific_tags']['count_cases_per_item'] : []; + +$result = PluginProcessmakerProcess::getSqlSearchResult(false, $search); + +//if ($DB->numrows($result)) { +// while ($data = $DB->fetch_array($result)) { +//if ($result->numrows()) { + foreach ($result as $data) { + $process_entities = PluginProcessmakerProcess::getEntitiesForProfileByProcess($data["id"], $_SESSION['glpiactiveprofile']['id'], true); + $can_add = $data['max_cases_per_item'] == 0 || !isset($count_cases_per_item[$data["id"]]) || $count_cases_per_item[$data["id"]] < $data['max_cases_per_item']; + if ($processall + || ($data['maintenance'] != 1 + && in_array( $_REQUEST["entity_restrict"], $process_entities) + && $can_add) ) { + + array_push( $processes, ['id' => $data["id"], + 'text' => $data["name"] + ]); + $count++; + } + } +//} + +$ret['results'] = $processes; +$ret['count'] = $count; +echo json_encode($ret); diff --git a/ajax/dropdownTaskcategories.php b/ajax/dropdownTaskcategories.php index 4fbd0dc..a854273 100644 --- a/ajax/dropdownTaskcategories.php +++ b/ajax/dropdownTaskcategories.php @@ -1,68 +1,68 @@ - 0, -// 'text' => $_REQUEST['emptylabel'])); -// } -// } -//} - -//$result = PluginProcessmakerTaskCategory::getSqlSearchResult(false, $search); - -//if ($DB->numrows($result)) { -// while ($data=$DB->fetch_array($result)) { -// array_push( $taskcategories, array( 'id' => $data["id"], -// 'text' => $data["name"] )); -// $count++; -// } -//} - -//$ret['results'] = $taskcategories; -//$ret['count'] = $count; -//echo json_encode($ret); + 0, +// 'text' => $_REQUEST['emptylabel'])); +// } +// } +//} + +//$result = PluginProcessmakerTaskCategory::getSqlSearchResult(false, $search); + +//if ($DB->numrows($result)) { +// while ($data=$DB->fetch_array($result)) { +// array_push( $taskcategories, array( 'id' => $data["id"], +// 'text' => $data["name"] )); +// $count++; +// } +//} + +//$ret['results'] = $taskcategories; +//$ret['count'] = $count; +//echo json_encode($ret); diff --git a/ajax/dropdownTicketCategories.php b/ajax/dropdownTicketCategories.php index 47d824a..aacf51e 100644 --- a/ajax/dropdownTicketCategories.php +++ b/ajax/dropdownTicketCategories.php @@ -1,40 +1,40 @@ -getFromDB($_POST['value']); - -if ($_POST["type"]) { - switch ($_POST['type']) { - case Ticket::INCIDENT_TYPE : - $opt['condition']['is_incident'] = '1'; - if ($currentcateg->getField('is_incident') == 1) { - $opt['value'] = $_POST['value']; - } - break; - - case Ticket::DEMAND_TYPE: - $opt['condition']['is_request'] = '1'; - if ($currentcateg->getField('is_request') == 1) { - $opt['value'] = $_POST['value']; - } - break; - } -} - -ITILCategory::dropdown($opt); +getFromDB($_POST['value']); + +if ($_POST["type"]) { + switch ($_POST['type']) { + case Ticket::INCIDENT_TYPE : + $opt['condition']['is_incident'] = '1'; + if ($currentcateg->getField('is_incident') == 1) { + $opt['value'] = $_POST['value']; + } + break; + + case Ticket::DEMAND_TYPE: + $opt['condition']['is_request'] = '1'; + if ($currentcateg->getField('is_request') == 1) { + $opt['value'] = $_POST['value']; + } + break; + } +} + +ITILCategory::dropdown($opt); diff --git a/ajax/selfservicedrafts.php b/ajax/selfservicedrafts.php index a4abe2d..ab4fa67 100644 --- a/ajax/selfservicedrafts.php +++ b/ajax/selfservicedrafts.php @@ -1,2 +1,2 @@ -config; - echo ""; -} - - -// check if it is from PM pages -if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'route' && isset( $_REQUEST['UID'] ) && isset( $_REQUEST['APP_UID'] ) && isset( $_REQUEST['__DynaformName__'] )) { - // then get item id from DB - if ($locCase->getFromGUID($_REQUEST['APP_UID'])) { - $PM_SOAP->derivateCase($locCase, $_REQUEST); - } - glpi_processmaker_case_reload_page(); - -} else if (isset($_REQUEST['purge'])) { - // delete case from case table, this will also delete the tasks - if ($locCase->getFromDB($_REQUEST['id']) && $locCase->deleteCase()) { - Session::addMessageAfterRedirect(__('Case has been deleted!', 'processmaker'), true, INFO); - } else { - Session::addMessageAfterRedirect(__('Unable to delete case!', 'processmaker'), true, ERROR); - } - // will redirect to item or to list if no item - $locCase->redirectToList(); - -} else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'cancel') { - // cancel case from PM - $locCase = new PluginProcessmakerCase; - $locCase->getFromDB($_POST['cases_id']); - $resultPM = $PM_SOAP->cancelCase($locCase->fields['case_guid']); - if ($resultPM->status_code === 0) { - if ($locCase->cancelCase()) { - Session::addMessageAfterRedirect(__('Case has been cancelled!', 'processmaker'), true, INFO); - } else { - Session::addMessageAfterRedirect(__('Unable to cancel case!', 'processmaker'), true, ERROR); - } - } else { - Session::addMessageAfterRedirect(__('Unable to cancel case!', 'processmaker'), true, ERROR); - } - Html::back(); -} else if (isset( $_REQUEST['form'] ) && isset( $_REQUEST['form']['BTN_CATCH'] ) && isset( $_REQUEST['form']['APP_UID'])) { - // Claim task management - // here we are in a Claim request - $myCase = new PluginProcessmakerCase; - if ($myCase->getFromGUID( $_REQUEST['form']['APP_UID'] )) { - - $pmClaimCase = $PM_SOAP->claimCase($myCase->fields['case_guid'], $_REQUEST['DEL_INDEX'] ); - - // now manage tasks associated with item - $PM_SOAP->claimTask($myCase->getID(), $_REQUEST['DEL_INDEX']); - } - glpi_processmaker_case_reload_page(); - -} else if (isset($_REQUEST['id']) && $_REQUEST['id'] > 0) { - - if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") { - Html::helpHeader(__('Process cases', 'processmaker'), '', $_SESSION["glpiname"]); - } else { - Html::header(__('Process cases', 'processmaker'), $_SERVER['PHP_SELF'], "helpdesk", "PluginProcessmakerCase", "cases"); - } - - if (!$PM_SOAP->config->fields['maintenance']) { - if ($locCase->getFromDB($_REQUEST['id'])) { - $locCase->display($_REQUEST); - } - } else { - PluginProcessmakerProcessmaker::showUnderMaintenance(); - } - - Html::footer(); -} - - - +config; + echo ""; +} + + +// check if it is from PM pages +if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'route' && isset( $_REQUEST['UID'] ) && isset( $_REQUEST['APP_UID'] ) && isset( $_REQUEST['__DynaformName__'] )) { + // then get item id from DB + if ($locCase->getFromGUID($_REQUEST['APP_UID'])) { + $PM_SOAP->derivateCase($locCase, $_REQUEST); + } + glpi_processmaker_case_reload_page(); + +} else if (isset($_REQUEST['purge'])) { + // delete case from case table, this will also delete the tasks + if ($locCase->getFromDB($_REQUEST['id']) && $locCase->deleteCase()) { + Session::addMessageAfterRedirect(__('Case has been deleted!', 'processmaker'), true, INFO); + } else { + Session::addMessageAfterRedirect(__('Unable to delete case!', 'processmaker'), true, ERROR); + } + // will redirect to item or to list if no item + $locCase->redirectToList(); + +} else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'cancel') { + // cancel case from PM + $locCase = new PluginProcessmakerCase; + $locCase->getFromDB($_POST['cases_id']); + $resultPM = $PM_SOAP->cancelCase($locCase->fields['case_guid']); + if ($resultPM->status_code === 0) { + if ($locCase->cancelCase()) { + Session::addMessageAfterRedirect(__('Case has been cancelled!', 'processmaker'), true, INFO); + } else { + Session::addMessageAfterRedirect(__('Unable to cancel case!', 'processmaker'), true, ERROR); + } + } else { + Session::addMessageAfterRedirect(__('Unable to cancel case!', 'processmaker'), true, ERROR); + } + Html::back(); +} else if (isset( $_REQUEST['form'] ) && isset( $_REQUEST['form']['BTN_CATCH'] ) && isset( $_REQUEST['form']['APP_UID'])) { + // Claim task management + // here we are in a Claim request + $myCase = new PluginProcessmakerCase; + if ($myCase->getFromGUID( $_REQUEST['form']['APP_UID'] )) { + + $pmClaimCase = $PM_SOAP->claimCase($myCase->fields['case_guid'], $_REQUEST['DEL_INDEX'] ); + + // now manage tasks associated with item + $PM_SOAP->claimTask($myCase->getID(), $_REQUEST['DEL_INDEX']); + } + glpi_processmaker_case_reload_page(); + +} else if (isset($_REQUEST['id']) && $_REQUEST['id'] > 0) { + + if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") { + Html::helpHeader(__('Process cases', 'processmaker'), '', $_SESSION["glpiname"]); + } else { + Html::header(__('Process cases', 'processmaker'), $_SERVER['PHP_SELF'], "helpdesk", "PluginProcessmakerCase", "cases"); + } + + if (!$PM_SOAP->config->fields['maintenance']) { + if ($locCase->getFromDB($_REQUEST['id'])) { + $locCase->display($_REQUEST); + } + } else { + PluginProcessmakerProcessmaker::showUnderMaintenance(); + } + + Html::footer(); +} + + + diff --git a/front/caselink.form.php b/front/caselink.form.php index 775daac..e91f50b 100644 --- a/front/caselink.form.php +++ b/front/caselink.form.php @@ -1,34 +1,34 @@ -check($_REQUEST['id'], UPDATE); - $PluginCaselink->update($_REQUEST); - Html::back(); -} else if (isset($_REQUEST['add'])) { - $PluginCaselink->check($_REQUEST['id'], UPDATE); - $PluginCaselink->add($_REQUEST); - Html::back(); -} else if (isset($_REQUEST['purge'])) { - $PluginCaselink->check($_REQUEST['id'], PURGE); - $PluginCaselink->delete($_REQUEST, true); - $PluginCaselink->redirectToList(); -} else { - - Html::header(__('ProcessMaker', 'processmaker'), $_SERVER['PHP_SELF'], "tools", "PluginProcessmakerMenu", "caselinks"); - - $PluginCaselink->display($_REQUEST); - - Html::footer(); -} +check($_REQUEST['id'], UPDATE); + $PluginCaselink->update($_REQUEST); + Html::back(); +} else if (isset($_REQUEST['add'])) { + $PluginCaselink->check($_REQUEST['id'], UPDATE); + $PluginCaselink->add($_REQUEST); + Html::back(); +} else if (isset($_REQUEST['purge'])) { + $PluginCaselink->check($_REQUEST['id'], PURGE); + $PluginCaselink->delete($_REQUEST, true); + $PluginCaselink->redirectToList(); +} else { + + Html::header(__('ProcessMaker', 'processmaker'), $_SERVER['PHP_SELF'], "tools", "PluginProcessmakerMenu", "caselinks"); + + $PluginCaselink->display($_REQUEST); + + Html::footer(); +} diff --git a/front/caselink.php b/front/caselink.php index fb11f5c..99390f4 100644 --- a/front/caselink.php +++ b/front/caselink.php @@ -1,15 +1,15 @@ -check($_POST['id'], UPDATE); - - // save - $config->update($_POST); - - - Html::back(); - -} else if (isset($_POST["refresh"])) { - $config->refresh($_POST); // used to refresh process list, task category list - Html::back(); -} - -Html::redirect($CFG_GLPI["root_doc"]."/front/config.form.php?forcetab=". - urlencode('PluginProcessmakerConfig$1')); +check($_POST['id'], UPDATE); + + // save + $config->update($_POST); + + + Html::back(); + +} else if (isset($_POST["refresh"])) { + $config->refresh($_POST); // used to refresh process list, task category list + Html::back(); +} + +Html::redirect($CFG_GLPI["root_doc"]."/front/config.form.php?forcetab=". + urlencode('PluginProcessmakerConfig$1')); diff --git a/front/process.form.php b/front/process.form.php index 26dc7a7..f015fdf 100644 --- a/front/process.form.php +++ b/front/process.form.php @@ -1,32 +1,32 @@ -check($_REQUEST['id'], UPDATE); - $PluginProcess->update($_REQUEST); - Html::back(); - -} else if (isset($_REQUEST["refreshtask"])) { - $PluginProcess->check($_REQUEST['id'], UPDATE); - $PluginProcess->refreshTasks($_REQUEST); - Html::back(); - -} else { - - Html::header(__('ProcessMaker', 'processmaker'), $_SERVER['PHP_SELF'], "tools", "PluginProcessmakerMenu", "processes"); - - $PluginProcess->display($_REQUEST); - - Html::footer(); -} +check($_REQUEST['id'], UPDATE); + $PluginProcess->update($_REQUEST); + Html::back(); + +} else if (isset($_REQUEST["refreshtask"])) { + $PluginProcess->check($_REQUEST['id'], UPDATE); + $PluginProcess->refreshTasks($_REQUEST); + Html::back(); + +} else { + + Html::header(__('ProcessMaker', 'processmaker'), $_SERVER['PHP_SELF'], "tools", "PluginProcessmakerMenu", "processes"); + + $PluginProcess->display($_REQUEST); + + Html::footer(); +} diff --git a/front/process.php b/front/process.php index 4b8a84a..83eec43 100644 --- a/front/process.php +++ b/front/process.php @@ -1,23 +1,23 @@ -refresh(); - Html::back(); - } - - $process->title(); - - Search::show('PluginProcessmakerProcess'); - -} else { - Html::displayRightError(); -} -Html::footer(); - +refresh(); + Html::back(); + } + + $process->title(); + + Search::show('PluginProcessmakerProcess'); + +} else { + Html::displayRightError(); +} +Html::footer(); + diff --git a/front/process_profile.form.php b/front/process_profile.form.php index 18d0460..95081f1 100644 --- a/front/process_profile.form.php +++ b/front/process_profile.form.php @@ -1,16 +1,16 @@ -check(-1, UPDATE, $_POST); - $right->add($_POST); - Html::back(); -} - -Html::displayErrorAndDie("lost"); +check(-1, UPDATE, $_POST); + $right->add($_POST); + Html::back(); +} + +Html::displayErrorAndDie("lost"); diff --git a/inc/casechangelog.class.php b/inc/casechangelog.class.php index 34c73e9..89029b0 100644 --- a/inc/casechangelog.class.php +++ b/inc/casechangelog.class.php @@ -1,38 +1,38 @@ -serverURL."/cases/ajaxListener?action=changeLogHistory&rand=$rand"; - - $PM_SOAP->echoDomain(); - echo ""; //?rand=$rand' - - $iframe = ""; - - $PM_SOAP->initCaseAndShowTab(['APP_UID' => $case->fields['case_guid'], 'DEL_INDEX' => 1], $iframe, $rand); - - } - - function getTabNameForItem(CommonGLPI $case, $withtemplate = 0) { - return __('Change log', 'processmaker'); - } -} +serverURL."/cases/ajaxListener?action=changeLogHistory&rand=$rand"; + + $PM_SOAP->echoDomain(); + echo ""; //?rand=$rand' + + $iframe = ""; + + $PM_SOAP->initCaseAndShowTab(['APP_UID' => $case->fields['case_guid'], 'DEL_INDEX' => 1], $iframe, $rand); + + } + + function getTabNameForItem(CommonGLPI $case, $withtemplate = 0) { + return __('Change log', 'processmaker'); + } +} diff --git a/inc/casedynaform.class.php b/inc/casedynaform.class.php index 29d5a24..46c5b7e 100644 --- a/inc/casedynaform.class.php +++ b/inc/casedynaform.class.php @@ -1,86 +1,86 @@ -config; - $rand = rand(); - - $proj = new PluginProcessmakerProcess; - $proj->getFromDB($case->fields['plugin_processmaker_processes_id']); - - $PM_SOAP->echoDomain(); - echo ""; //?rand=$rand' - - echo ""; - - $caseURL = $PM_SOAP->serverURL."/cases/casesHistoryDynaformPage_Ajax?actionAjax=historyDynaformPage&rand=$rand"; - - $iframe = ""; - - $PM_SOAP->initCaseAndShowTab(['APP_UID' => $case->fields['case_guid'], 'DEL_INDEX' => 1], $iframe, $rand); - - } - - function getTabNameForItem(CommonGLPI $case, $withtemplate = 0) { - return __('Dynaforms', 'processmaker'); - } - -} +config; + $rand = rand(); + + $proj = new PluginProcessmakerProcess; + $proj->getFromDB($case->fields['plugin_processmaker_processes_id']); + + $PM_SOAP->echoDomain(); + echo ""; //?rand=$rand' + + echo ""; + + $caseURL = $PM_SOAP->serverURL."/cases/casesHistoryDynaformPage_Ajax?actionAjax=historyDynaformPage&rand=$rand"; + + $iframe = ""; + + $PM_SOAP->initCaseAndShowTab(['APP_UID' => $case->fields['case_guid'], 'DEL_INDEX' => 1], $iframe, $rand); + + } + + function getTabNameForItem(CommonGLPI $case, $withtemplate = 0) { + return __('Dynaforms', 'processmaker'); + } + +} diff --git a/inc/casehistory.class.php b/inc/casehistory.class.php index de31e17..d660699 100644 --- a/inc/casehistory.class.php +++ b/inc/casehistory.class.php @@ -1,38 +1,38 @@ -serverURL - ."/cases/ajaxListener?action=caseHistory&rand=$rand"; - - $PM_SOAP->echoDomain(); - echo ""; - - $iframe = ""; - - $PM_SOAP->initCaseAndShowTab(['APP_UID' => $case->fields['case_guid'], 'DEL_INDEX' => 1], $iframe, $rand); - - } - - function getTabNameForItem(CommonGLPI $case, $withtemplate = 0) { - return __('History', 'processmaker'); - } -} +serverURL + ."/cases/ajaxListener?action=caseHistory&rand=$rand"; + + $PM_SOAP->echoDomain(); + echo ""; + + $iframe = ""; + + $PM_SOAP->initCaseAndShowTab(['APP_UID' => $case->fields['case_guid'], 'DEL_INDEX' => 1], $iframe, $rand); + + } + + function getTabNameForItem(CommonGLPI $case, $withtemplate = 0) { + return __('History', 'processmaker'); + } +} diff --git a/inc/caselink.class.php b/inc/caselink.class.php index 5f13fe1..36dd20d 100644 --- a/inc/caselink.class.php +++ b/inc/caselink.class.php @@ -1,285 +1,285 @@ -1) { - return __('Case-links', 'processmaker'); - } - return __('Case-link', 'processmaker'); - } - - function showForm ($ID, $options = ['candel'=>false]) { - global $DB, $CFG_GLPI; - - $options['candel'] = true; - - $this->initForm($ID, $options); - $this->showFormHeader($options); - - echo ""; - echo "".__('Name').""; - echo ""; - echo ""; - - echo ""; - echo "".__('Active').""; - Dropdown::showYesNo("is_active", $this->fields["is_active"]); - echo ""; - - echo ""; - echo "".__('Synchronous', 'processmaker').""; - Dropdown::showYesNo("is_synchronous", $this->fields["is_synchronous"]); - echo ""; - - echo ""; - echo "".__('External data', 'processmaker').""; - Dropdown::showYesNo("is_externaldata", $this->fields["is_externaldata"]); - echo ""; - - echo ""; - echo "".__('Self', 'processmaker').""; - Dropdown::showYesNo("is_self", $this->fields["is_self"]); - echo ""; - - echo ""; - echo "".__('Source task GUID', 'processmaker').""; - //PluginProcessmakerTaskCategory::dropdown(array('name' => 'plugin_processmaker_taskcategories_id_source', - // 'display_emptychoice' => false, - // 'value' => $this->fields['plugin_processmaker_taskcategories_id_source'])); - echo ""; - echo ""; - - echo ""; - echo "".__('Target task GUID', 'processmaker').""; - //PluginProcessmakerTaskCategory::dropdown(array('name' => 'plugin_processmaker_taskcategories_id_target', - // 'display_emptychoice' => false, - // 'value' => $this->fields['plugin_processmaker_taskcategories_id_target'])); - echo ""; - echo ""; - - echo ""; - echo "".__('Target process GUID', 'processmaker').""; - //Dropdown::show( 'PluginProcessmakerProcess', array('name' => 'plugin_processmaker_processes_id', - // 'display_emptychoice' => true, - // 'value' => $this->fields['plugin_processmaker_processes_id'], - // 'condition' => 'is_active = 1')); - echo ""; - echo ""; - - echo ""; - echo "".__('Target dynaform GUID', 'processmaker').""; - echo ""; - echo ""; - - echo ""; - echo "".__('Source condition', 'processmaker').""; - //echo ""; - echo ""; - echo ""; - - echo ""; - echo "".__('Claim target task', 'processmaker').""; - Dropdown::showYesNo("is_targettoclaim", $this->fields["is_targettoclaim"]); - echo ""; - - //echo ""; - //echo "".__('Reassign target task', 'processmaker').""; - //Dropdown::showYesNo("is_targettoreassign", $this->fields["is_targettoreassign"]); - //echo ""; - - echo ""; - echo "".__('Impersonate target task user', 'processmaker').""; - Dropdown::showYesNo("is_targettoimpersonate", $this->fields["is_targettoimpersonate"]); - echo ""; - - echo ""; - echo "".__('External application JSON config', 'processmaker').""; - echo ""; - echo ""; - - $this->showFormButtons($options ); - - } - - - /** - * Summary of rawSearchOptions - * @return mixed - */ - function rawSearchOptions() { - $tab = []; - - $tab[] = [ - 'id' => 'common', - 'name' => __('ProcessMaker', 'processmaker') - ]; - - $tab[] = [ - 'id' => '1', - 'table' => $this->getTable(), - 'field' => 'name', - 'name' => __('Name'), - 'datatype' => 'itemlink', - 'itemlink_type' => 'PluginProcessmakerCaselink', - 'massiveaction' => false - ]; - - $tab[] = [ - 'id' => '8', - 'table' => $this->getTable(), - 'field' => 'is_active', - 'name' => __('Active'), - 'massiveaction' => true, - 'datatype' => 'bool' - ]; - - $tab[] = [ - 'id' => '9', - 'table' => $this->getTable(), - 'field' => 'date_mod', - 'name' => __('Last update'), - 'massiveaction' => false, - 'datatype' => 'datetime' - ]; - - $tab[] = [ - 'id' => '10', - 'table' => $this->getTable(), - 'field' => 'is_externaldata', - 'name' => __('External data', 'processmaker'), - 'massiveaction' => false, - 'datatype' => 'bool' - ]; - - $tab[] = [ - 'id' => '11', - 'table' => $this->getTable(), - 'field' => 'is_self', - 'name' => __('Self', 'processmaker'), - 'massiveaction' => false, - 'datatype' => 'bool' - ]; - - $tab[] = [ - 'id' => '12', - 'table' => $this->getTable(), - 'field' => 'is_targettoclaim', - 'name' => __('Claim target task', 'processmaker'), - 'massiveaction' => false, - 'datatype' => 'bool' - ]; - - $tab[] = [ - 'id' => '13', - 'table' => $this->getTable(), - 'field' => 'externalapplication', - 'name' => __('External application JSON config', 'processmaker'), - 'massiveaction' => false, - 'datatype' => 'text' - ]; - - $tab[] = [ - 'id' => '14', - 'table' => $this->getTable(), - 'field' => 'sourcetask_guid', - 'name' => __('Source task GUID', 'processmaker'), - 'massiveaction' => false, - 'datatype' => 'text' - ]; - - $tab[] = [ - 'id' => '15', - 'table' => $this->getTable(), - 'field' => 'targettask_guid', - 'name' => __('Target task GUID', 'processmaker'), - 'massiveaction' => false, - 'datatype' => 'text' - ]; - - $tab[] = [ - 'id' => '16', - 'table' => $this->getTable(), - 'field' => 'targetdynaform_guid', - 'name' => __('Target dynaform GUID', 'processmaker'), - 'massiveaction' => false, - 'datatype' => 'text' - ]; - - $tab[] = [ - 'id' => '17', - 'table' => $this->getTable(), - 'field' => 'targetprocess_guid', - 'name' => __('Target process GUID', 'processmaker'), - 'massiveaction' => false, - 'datatype' => 'text' - ]; - - $tab[] = [ - 'id' => '18', - 'table' => $this->getTable(), - 'field' => 'sourcecondition', - 'name' => __('Source condition', 'processmaker'), - 'massiveaction' => false, - 'datatype' => 'text' - ]; - - return $tab; - } - - - function prepareInputForUpdate($input) { - return Toolbox::unclean_cross_side_scripting_deep($input); - } - - - function prepareInputForAdd($input) { - return Toolbox::unclean_cross_side_scripting_deep($input); - } - - -} +1) { + return __('Case-links', 'processmaker'); + } + return __('Case-link', 'processmaker'); + } + + function showForm ($ID, $options = ['candel'=>false]) { + global $DB, $CFG_GLPI; + + $options['candel'] = true; + + $this->initForm($ID, $options); + $this->showFormHeader($options); + + echo ""; + echo "".__('Name').""; + echo ""; + echo ""; + + echo ""; + echo "".__('Active').""; + Dropdown::showYesNo("is_active", $this->fields["is_active"]); + echo ""; + + echo ""; + echo "".__('Synchronous', 'processmaker').""; + Dropdown::showYesNo("is_synchronous", $this->fields["is_synchronous"]); + echo ""; + + echo ""; + echo "".__('External data', 'processmaker').""; + Dropdown::showYesNo("is_externaldata", $this->fields["is_externaldata"]); + echo ""; + + echo ""; + echo "".__('Self', 'processmaker').""; + Dropdown::showYesNo("is_self", $this->fields["is_self"]); + echo ""; + + echo ""; + echo "".__('Source task GUID', 'processmaker').""; + //PluginProcessmakerTaskCategory::dropdown(array('name' => 'plugin_processmaker_taskcategories_id_source', + // 'display_emptychoice' => false, + // 'value' => $this->fields['plugin_processmaker_taskcategories_id_source'])); + echo ""; + echo ""; + + echo ""; + echo "".__('Target task GUID', 'processmaker').""; + //PluginProcessmakerTaskCategory::dropdown(array('name' => 'plugin_processmaker_taskcategories_id_target', + // 'display_emptychoice' => false, + // 'value' => $this->fields['plugin_processmaker_taskcategories_id_target'])); + echo ""; + echo ""; + + echo ""; + echo "".__('Target process GUID', 'processmaker').""; + //Dropdown::show( 'PluginProcessmakerProcess', array('name' => 'plugin_processmaker_processes_id', + // 'display_emptychoice' => true, + // 'value' => $this->fields['plugin_processmaker_processes_id'], + // 'condition' => 'is_active = 1')); + echo ""; + echo ""; + + echo ""; + echo "".__('Target dynaform GUID', 'processmaker').""; + echo ""; + echo ""; + + echo ""; + echo "".__('Source condition', 'processmaker').""; + //echo ""; + echo ""; + echo ""; + + echo ""; + echo "".__('Claim target task', 'processmaker').""; + Dropdown::showYesNo("is_targettoclaim", $this->fields["is_targettoclaim"]); + echo ""; + + //echo ""; + //echo "".__('Reassign target task', 'processmaker').""; + //Dropdown::showYesNo("is_targettoreassign", $this->fields["is_targettoreassign"]); + //echo ""; + + echo ""; + echo "".__('Impersonate target task user', 'processmaker').""; + Dropdown::showYesNo("is_targettoimpersonate", $this->fields["is_targettoimpersonate"]); + echo ""; + + echo ""; + echo "".__('External application JSON config', 'processmaker').""; + echo ""; + echo ""; + + $this->showFormButtons($options ); + + } + + + /** + * Summary of rawSearchOptions + * @return mixed + */ + function rawSearchOptions() { + $tab = []; + + $tab[] = [ + 'id' => 'common', + 'name' => __('ProcessMaker', 'processmaker') + ]; + + $tab[] = [ + 'id' => '1', + 'table' => $this->getTable(), + 'field' => 'name', + 'name' => __('Name'), + 'datatype' => 'itemlink', + 'itemlink_type' => 'PluginProcessmakerCaselink', + 'massiveaction' => false + ]; + + $tab[] = [ + 'id' => '8', + 'table' => $this->getTable(), + 'field' => 'is_active', + 'name' => __('Active'), + 'massiveaction' => true, + 'datatype' => 'bool' + ]; + + $tab[] = [ + 'id' => '9', + 'table' => $this->getTable(), + 'field' => 'date_mod', + 'name' => __('Last update'), + 'massiveaction' => false, + 'datatype' => 'datetime' + ]; + + $tab[] = [ + 'id' => '10', + 'table' => $this->getTable(), + 'field' => 'is_externaldata', + 'name' => __('External data', 'processmaker'), + 'massiveaction' => false, + 'datatype' => 'bool' + ]; + + $tab[] = [ + 'id' => '11', + 'table' => $this->getTable(), + 'field' => 'is_self', + 'name' => __('Self', 'processmaker'), + 'massiveaction' => false, + 'datatype' => 'bool' + ]; + + $tab[] = [ + 'id' => '12', + 'table' => $this->getTable(), + 'field' => 'is_targettoclaim', + 'name' => __('Claim target task', 'processmaker'), + 'massiveaction' => false, + 'datatype' => 'bool' + ]; + + $tab[] = [ + 'id' => '13', + 'table' => $this->getTable(), + 'field' => 'externalapplication', + 'name' => __('External application JSON config', 'processmaker'), + 'massiveaction' => false, + 'datatype' => 'text' + ]; + + $tab[] = [ + 'id' => '14', + 'table' => $this->getTable(), + 'field' => 'sourcetask_guid', + 'name' => __('Source task GUID', 'processmaker'), + 'massiveaction' => false, + 'datatype' => 'text' + ]; + + $tab[] = [ + 'id' => '15', + 'table' => $this->getTable(), + 'field' => 'targettask_guid', + 'name' => __('Target task GUID', 'processmaker'), + 'massiveaction' => false, + 'datatype' => 'text' + ]; + + $tab[] = [ + 'id' => '16', + 'table' => $this->getTable(), + 'field' => 'targetdynaform_guid', + 'name' => __('Target dynaform GUID', 'processmaker'), + 'massiveaction' => false, + 'datatype' => 'text' + ]; + + $tab[] = [ + 'id' => '17', + 'table' => $this->getTable(), + 'field' => 'targetprocess_guid', + 'name' => __('Target process GUID', 'processmaker'), + 'massiveaction' => false, + 'datatype' => 'text' + ]; + + $tab[] = [ + 'id' => '18', + 'table' => $this->getTable(), + 'field' => 'sourcecondition', + 'name' => __('Source condition', 'processmaker'), + 'massiveaction' => false, + 'datatype' => 'text' + ]; + + return $tab; + } + + + function prepareInputForUpdate($input) { + return Toolbox::unclean_cross_side_scripting_deep($input); + } + + + function prepareInputForAdd($input) { + return Toolbox::unclean_cross_side_scripting_deep($input); + } + + +} diff --git a/inc/caselinkaction.class.php b/inc/caselinkaction.class.php index 60f0eb8..2488be3 100644 --- a/inc/caselinkaction.class.php +++ b/inc/caselinkaction.class.php @@ -1,12 +1,12 @@ -getFromDB($case->fields['plugin_processmaker_processes_id']); - $project_type = $proj->fields['project_type']; - - $caseMapUrl = $PM_SOAP->serverURL.( - $project_type=='bpmn' ? - "/designer?prj_uid=".$proj->fields['process_guid']."&prj_readonly=true&app_uid=".$case->fields['case_guid'] - : - "/cases/ajaxListener?action=processMap" - )."&rand=$rand"; - - $PM_SOAP->echoDomain(); - echo ""; //?rand=$rand' - - $iframe = ""; - - $PM_SOAP->initCaseAndShowTab(['APP_UID' => $case->fields['case_guid'], 'DEL_INDEX' => 1], $iframe, $rand); - - } - - function getTabNameForItem(CommonGLPI $case, $withtemplate = 0) { - return __('Map', 'processmaker'); - } - -} +getFromDB($case->fields['plugin_processmaker_processes_id']); + $project_type = $proj->fields['project_type']; + + $caseMapUrl = $PM_SOAP->serverURL.( + $project_type=='bpmn' ? + "/designer?prj_uid=".$proj->fields['process_guid']."&prj_readonly=true&app_uid=".$case->fields['case_guid'] + : + "/cases/ajaxListener?action=processMap" + )."&rand=$rand"; + + $PM_SOAP->echoDomain(); + echo ""; //?rand=$rand' + + $iframe = ""; + + $PM_SOAP->initCaseAndShowTab(['APP_UID' => $case->fields['case_guid'], 'DEL_INDEX' => 1], $iframe, $rand); + + } + + function getTabNameForItem(CommonGLPI $case, $withtemplate = 0) { + return __('Map', 'processmaker'); + } + +} diff --git a/inc/glpikey.class.php b/inc/glpikey.class.php index b1b8b60..e6c581b 100644 --- a/inc/glpikey.class.php +++ b/inc/glpikey.class.php @@ -1,20 +1,20 @@ -fields; - } - - + } + + /** * Generate GLPI security key used for decryptable passwords * and update values in DB if necessary. @@ -43,6 +43,6 @@ class PluginProcessmakerGlpikey extends GLPIKey { return false; } - - + + } \ No newline at end of file diff --git a/inc/profile.class.php b/inc/profile.class.php index a53a16c..7458283 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -1,133 +1,133 @@ - 'PluginProcessmakerConfig', - 'label' => __('Process configuration', 'processmaker'), - 'field' => 'plugin_processmaker_config', - 'rights' => [READ => __('Read'), UPDATE => __('Update')]], - ['itemtype' => 'PluginProcessmakerConfig', - 'label' => __('Cases', 'processmaker'), - 'field' => 'plugin_processmaker_case', - 'rights' => [READ => __('Read'), CANCEL => __('Cancel', 'processmaker'), DELETE => __('Delete'), ADHOC_REASSIGN => __('Ad Hoc user re-assign', 'processmaker')]] - ]; - - return $rights; - } - - - /** - * Summary of showForm - * @param mixed $ID - * @param mixed $openform - * @param mixed $closeform - * @return bool - */ - function showForm($ID = 0, $openform = true, $closeform = true) { - - if (!Session::haveRight("profile", READ)) { - return false; - } - - $canedit = Session::haveRight("profile", UPDATE); - $prof = new Profile(); - if ($ID) { - $prof->getFromDB($ID); - } - echo "
"; - $rights = $this->getAllRights(); - $prof->displayRightsChoiceMatrix($rights, ['canedit' => $canedit, - 'default_class' => 'tab_bg_2', - 'title' => __('ProcessMaker', 'processmaker')]); - - if ($canedit && $closeform) { - echo "
"; - echo Html::hidden('id', ['value' => $ID]); - echo Html::submit(_sx('button', 'Save'), - ['name' => 'update']); - echo "
\n"; - } - - Html::closeForm(); - - return true; - } - - /** - * Summary of createAdminAccess - * @param mixed $ID - */ - static function createAdminAccess($ID) { - self::addDefaultProfileInfos($ID, ['plugin_processmaker_config' => READ + UPDATE, 'plugin_processmaker_case' => READ + DELETE + CANCEL + ADHOC_REASSIGN], true); - } - - /** - * Summary of getTabNameForItem - * @param CommonGLPI $item - * @param mixed $withtemplate - * @return string|string[] - */ - function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - if ($item->getType()=='Profile') { - return __('ProcessMaker', 'processmaker'); - } - return ''; - } - - /** - * Summary of displayTabContentForItem - * @param CommonGLPI $item - * @param mixed $tabnum - * @param mixed $withtemplate - * @return bool - */ - static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - global $CFG_GLPI; - - if ($item->getType()=='Profile') { - $ID = $item->getID(); - $prof = new self(); - self::addDefaultProfileInfos($ID, - ['plugin_processmaker_config' => 0, - 'plugin_processmaker_case' => 0 - ]); - - $prof->showForm($ID); - } - return true; - } - - /** - * @param $profile - **/ - static function addDefaultProfileInfos($profiles_id, $rights, $drop_existing = false) { - global $DB; - $dbu = new DbUtils; - $profileRight = new ProfileRight(); - foreach ($rights as $right => $value) { - if ($dbu->countElementsInTable('glpi_profilerights', ['AND' => ['profiles_id' => $profiles_id, 'name' => $right]]) && $drop_existing) { - $profileRight->deleteByCriteria(['profiles_id' => $profiles_id, 'name' => $right]); - } - if (!$dbu->countElementsInTable('glpi_profilerights', ['AND' => ['profiles_id' => $profiles_id, 'name' => $right]])) { - $myright['profiles_id'] = $profiles_id; - $myright['name'] = $right; - $myright['rights'] = $value; - $profileRight->add($myright); - - //Add right to the current session - $_SESSION['glpiactiveprofile'][$right] = $value; - } - } - } -} + 'PluginProcessmakerConfig', + 'label' => __('Process configuration', 'processmaker'), + 'field' => 'plugin_processmaker_config', + 'rights' => [READ => __('Read'), UPDATE => __('Update')]], + ['itemtype' => 'PluginProcessmakerConfig', + 'label' => __('Cases', 'processmaker'), + 'field' => 'plugin_processmaker_case', + 'rights' => [READ => __('Read'), CANCEL => __('Cancel', 'processmaker'), DELETE => __('Delete'), ADHOC_REASSIGN => __('Ad Hoc user re-assign', 'processmaker')]] + ]; + + return $rights; + } + + + /** + * Summary of showForm + * @param mixed $ID + * @param mixed $openform + * @param mixed $closeform + * @return bool + */ + function showForm($ID = 0, $openform = true, $closeform = true) { + + if (!Session::haveRight("profile", READ)) { + return false; + } + + $canedit = Session::haveRight("profile", UPDATE); + $prof = new Profile(); + if ($ID) { + $prof->getFromDB($ID); + } + echo ""; + $rights = $this->getAllRights(); + $prof->displayRightsChoiceMatrix($rights, ['canedit' => $canedit, + 'default_class' => 'tab_bg_2', + 'title' => __('ProcessMaker', 'processmaker')]); + + if ($canedit && $closeform) { + echo "
"; + echo Html::hidden('id', ['value' => $ID]); + echo Html::submit(_sx('button', 'Save'), + ['name' => 'update']); + echo "
\n"; + } + + Html::closeForm(); + + return true; + } + + /** + * Summary of createAdminAccess + * @param mixed $ID + */ + static function createAdminAccess($ID) { + self::addDefaultProfileInfos($ID, ['plugin_processmaker_config' => READ + UPDATE, 'plugin_processmaker_case' => READ + DELETE + CANCEL + ADHOC_REASSIGN], true); + } + + /** + * Summary of getTabNameForItem + * @param CommonGLPI $item + * @param mixed $withtemplate + * @return string|string[] + */ + function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { + if ($item->getType()=='Profile') { + return __('ProcessMaker', 'processmaker'); + } + return ''; + } + + /** + * Summary of displayTabContentForItem + * @param CommonGLPI $item + * @param mixed $tabnum + * @param mixed $withtemplate + * @return bool + */ + static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { + global $CFG_GLPI; + + if ($item->getType()=='Profile') { + $ID = $item->getID(); + $prof = new self(); + self::addDefaultProfileInfos($ID, + ['plugin_processmaker_config' => 0, + 'plugin_processmaker_case' => 0 + ]); + + $prof->showForm($ID); + } + return true; + } + + /** + * @param $profile + **/ + static function addDefaultProfileInfos($profiles_id, $rights, $drop_existing = false) { + global $DB; + $dbu = new DbUtils; + $profileRight = new ProfileRight(); + foreach ($rights as $right => $value) { + if ($dbu->countElementsInTable('glpi_profilerights', ['AND' => ['profiles_id' => $profiles_id, 'name' => $right]]) && $drop_existing) { + $profileRight->deleteByCriteria(['profiles_id' => $profiles_id, 'name' => $right]); + } + if (!$dbu->countElementsInTable('glpi_profilerights', ['AND' => ['profiles_id' => $profiles_id, 'name' => $right]])) { + $myright['profiles_id'] = $profiles_id; + $myright['name'] = $right; + $myright['rights'] = $value; + $profileRight->add($myright); + + //Add right to the current session + $_SESSION['glpiactiveprofile'][$right] = $value; + } + } + } +} diff --git a/inc/selfservicedraft.class.php b/inc/selfservicedraft.class.php index df45378..d9d2a97 100644 --- a/inc/selfservicedraft.class.php +++ b/inc/selfservicedraft.class.php @@ -1,13 +1,13 @@ -runFile(GLPI_ROOT . "/plugins/processmaker/install/mysql/processmaker-empty.sql"); - - // add configuration singleton - $query = "INSERT INTO `glpi_plugin_processmaker_configs` (`id`) VALUES (1);"; - $DB->query( $query ) or die("error creating default record in glpi_plugin_processmaker_configs" . $DB->error()); - -} +runFile(GLPI_ROOT . "/plugins/processmaker/install/mysql/processmaker-empty.sql"); + + // add configuration singleton + $query = "INSERT INTO `glpi_plugin_processmaker_configs` (`id`) VALUES (1);"; + $DB->query( $query ) or die("error creating default record in glpi_plugin_processmaker_configs" . $DB->error()); + +} diff --git a/install/update_3_2_8_to_3_2_9.php b/install/update_3_2_8_to_3_2_9.php index f851cf0..7d19845 100644 --- a/install/update_3_2_8_to_3_2_9.php +++ b/install/update_3_2_8_to_3_2_9.php @@ -1,14 +1,14 @@ -fieldExists("glpi_plugin_processmaker_configs", "db_version")) { - $query = "ALTER TABLE `glpi_plugin_processmaker_configs` - ADD COLUMN `db_version` VARCHAR(10) NULL;"; - $DB->query($query) or die("error adding db_version field to glpi_plugin_processmaker_configs" . $DB->error()); - } - - return '3.2.9'; - -} +fieldExists("glpi_plugin_processmaker_configs", "db_version")) { + $query = "ALTER TABLE `glpi_plugin_processmaker_configs` + ADD COLUMN `db_version` VARCHAR(10) NULL;"; + $DB->query($query) or die("error adding db_version field to glpi_plugin_processmaker_configs" . $DB->error()); + } + + return '3.2.9'; + +} diff --git a/install/update_3_2_9_to_3_3_0.php b/install/update_3_2_9_to_3_3_0.php index d1cc9f9..b5b05b7 100644 --- a/install/update_3_2_9_to_3_3_0.php +++ b/install/update_3_2_9_to_3_3_0.php @@ -1,199 +1,199 @@ -fieldExists("glpi_plugin_processmaker_cases", "plugin_processmaker_processes_id" )) { - $query = "ALTER TABLE `glpi_plugin_processmaker_cases` - ALTER `id` DROP DEFAULT;"; - $DB->query($query) or die("error normalizing glpi_plugin_processmaker_cases table step 1" . $DB->error()); - - $query = "ALTER TABLE `glpi_plugin_processmaker_cases` - CHANGE COLUMN `id` `case_guid` VARCHAR(32) NOT NULL AFTER `items_id`;"; - $DB->query($query) or die("error normalizing glpi_plugin_processmaker_cases table step 2" . $DB->error()); - - $query = "ALTER TABLE `glpi_plugin_processmaker_cases` - CHANGE COLUMN `case_num` `id` INT(11) NOT NULL FIRST, - CHANGE COLUMN `itemtype` `itemtype` VARCHAR(10) NOT NULL DEFAULT 'Ticket' AFTER `id`, - ADD COLUMN `entities_id` INT(11) NOT NULL DEFAULT '0' AFTER `items_id`, - ADD COLUMN `name` MEDIUMTEXT NOT NULL DEFAULT '' AFTER `entities_id`, - CHANGE COLUMN `processes_id` `plugin_processmaker_processes_id` INT(11) NULL DEFAULT NULL AFTER `case_status`, - ADD COLUMN `plugin_processmaker_cases_id` INT(11) NOT NULL DEFAULT '0' AFTER `plugin_processmaker_processes_id`, - DROP INDEX `items`, - ADD INDEX `items` (`itemtype`, `items_id`), - ADD PRIMARY KEY (`id`), - ADD UNIQUE INDEX `case_guid` (`case_guid`), - ADD INDEX `plugin_processmaker_cases_id` (`plugin_processmaker_cases_id`), - ADD INDEX `plugin_processmaker_processes_id` (`plugin_processmaker_processes_id`);"; - - $DB->query($query) or die("error normalizing glpi_plugin_processmaker_cases table step 3 " . $DB->error()); - - // needs to set entities_id and name fields - // for this needs to browse all cases and do a getCaseInfo for each and to get entities_id from itemtype(items_id) - foreach ($DB->request(PluginProcessmakerCase::getTable()) as $row) { - $tmp = new $row['itemtype']; - $entities_id = 0; - if ($tmp->getFromDB($row['items_id'])) { - $entities_id = $tmp->fields['entities_id']; - } - foreach ($PM_DB->request("SELECT CON_VALUE FROM CONTENT WHERE CON_CATEGORY='APP_TITLE' AND CON_LANG='en' AND CON_ID='{$row['case_guid']}'") as $name) { - // there is only one record :) - $name = $PM_DB->escape($name['CON_VALUE']); - $query = "UPDATE ".PluginProcessmakerCase::getTable()." SET `name` = '{$name}', `entities_id` = $entities_id WHERE `id` = {$row['id']};"; - $DB->query($query) or die("error normalizing glpi_plugin_processmaker_cases table step 4 " . $DB->error()); - } - } - } - - if (!$DB->fieldExists("glpi_plugin_processmaker_processes_profiles", "plugin_processmaker_processes_id")) { - $query = "ALTER TABLE `glpi_plugin_processmaker_processes_profiles` - CHANGE COLUMN `processes_id` `plugin_processmaker_processes_id` INT(11) NOT NULL DEFAULT '0' AFTER `id`, - DROP INDEX `processes_id`, - ADD INDEX `plugin_processmaker_processes_id` (`plugin_processmaker_processes_id`);"; - $DB->query($query) or die("error on glpi_plugin_processmaker_processes_profiles table when renaming processes_id into plugin_processmaker_processes_id " . $DB->error()); - - // must clean the table in case there would be duplicate entries for a process - $query = "SELECT gpp.id, gpp.plugin_processmaker_processes_id, gpp.profiles_id, gpp.entities_id, MAX(gpp.is_recursive) AS is_recursive - FROM glpi_plugin_processmaker_processes_profiles AS gpp - GROUP BY gpp.plugin_processmaker_processes_id, gpp.profiles_id, gpp.entities_id - HAVING COUNT(id) > 1;"; - - foreach ($DB->request($query) as $rec) { - // there we have one rec per duplicates - // so we may delete all records in the table, and a new one - $del_query = "DELETE FROM glpi_plugin_processmaker_processes_profiles WHERE plugin_processmaker_processes_id=".$rec['plugin_processmaker_processes_id']." - AND profiles_id = ".$rec['profiles_id']." - AND entities_id = ".$rec['entities_id'].";"; - $DB->query($del_query) or die("error when deleting duplicated process_profiles in glpi_plugin_processmaker_processes_profiles table ". $DB->error()); - - $add_query = "INSERT INTO `glpi_plugin_processmaker_processes_profiles` (`id`, `plugin_processmaker_processes_id`, `profiles_id`, `entities_id`, `is_recursive`) - VALUES (".$rec['id'].", ".$rec['plugin_processmaker_processes_id'].", ".$rec['profiles_id'].", ".$rec['entities_id'].", ".$rec['is_recursive'].");"; - $DB->query($add_query) or die("error when inserting singletons of duplicated process_profiles in glpi_plugin_processmaker_processes_profiles table ". $DB->error()); - } - - $query = "ALTER TABLE `glpi_plugin_processmaker_processes_profiles` - ADD UNIQUE INDEX `plugin_processmaker_processes_id_profiles_id_entities_id` (`plugin_processmaker_processes_id`, `profiles_id`, `entities_id`);"; - $DB->query($query) or die("error when adding new index on glpi_plugin_processmaker_processes_profiles table " . $DB->error()); - } - - if (!$DB->fieldExists("glpi_plugin_processmaker_tasks", "plugin_processmaker_cases_id" )) { - $query = "ALTER TABLE `glpi_plugin_processmaker_tasks` - ALTER `itemtype` DROP DEFAULT;"; - $DB->query($query) or die("error normalizing glpi_plugin_processmaker_tasks table step 1" . $DB->error()); - - $query = "ALTER TABLE `glpi_plugin_processmaker_tasks` - CHANGE COLUMN `itemtype` `itemtype` VARCHAR(32) NOT NULL AFTER `id`, - ADD COLUMN `plugin_processmaker_cases_id` INT(11) NULL AFTER `case_id`, - ADD COLUMN `plugin_processmaker_taskcategories_id` INT(11) NULL AFTER `plugin_processmaker_cases_id`, - ADD COLUMN `del_thread` INT(11) NOT NULL AFTER `del_index`, - ADD COLUMN `del_thread_status` VARCHAR(32) NOT NULL DEFAULT 'OPEN' AFTER `del_thread`, - DROP INDEX `case_id`, - ADD UNIQUE INDEX `tasks` (`plugin_processmaker_cases_id`, `del_index`), - ADD INDEX `del_thread_status` (`del_thread_status`);"; - $DB->query($query) or die("error normalizing glpi_plugin_processmaker_tasks table step 2" . $DB->error()); - - // transform case_id (=GUID) into plugin_processmaker_cases_id - $query = "UPDATE `glpi_plugin_processmaker_tasks` - LEFT JOIN `glpi_plugin_processmaker_cases` ON `glpi_plugin_processmaker_cases`.`case_guid` = `glpi_plugin_processmaker_tasks`.`case_id` - SET `glpi_plugin_processmaker_tasks`.`plugin_processmaker_cases_id` = `glpi_plugin_processmaker_cases`.`id`;"; - $DB->query($query) or die("error transforming case_id into plugin_processmaker_cases_id in glpi_plugin_processmaker_tasks table" . $DB->error()); - - $query = "ALTER TABLE `glpi_plugin_processmaker_tasks` - DROP COLUMN `case_id`;"; - $DB->query($query) or die("error deleting case_id column in glpi_plugin_processmaker_tasks table" . $DB->error()); - - // set real thread status get it from APP_DELEGATION - $query = "SELECT APP_UID, DEL_INDEX, DEL_THREAD, DEL_THREAD_STATUS FROM APP_DELEGATION WHERE DEL_THREAD_STATUS = 'CLOSED';"; - $locThreads = []; - foreach ($PM_DB->request($query) as $thread) { - $locThreads[$thread['APP_UID']][] = $thread; - } - $locCase = new PluginProcessmakerCase; - foreach ($locThreads as $key => $threads) { - // get GLPI case id - $locCase->getFromGUID($key); - $del_indexes = []; - foreach ($threads as $thread) { - $del_indexes[] = $thread['DEL_INDEX']; - } - $del_indexes = implode(", ", $del_indexes); - $query = "UPDATE glpi_plugin_processmaker_tasks SET del_thread_status = 'CLOSED' WHERE plugin_processmaker_cases_id = {$locCase->getID()} AND del_index IN ($del_indexes)"; - $DB->query($query) or die("error updating del_thread_status in glpi_plugin_processmaker_tasks table" . $DB->error()); - } - - // set the plugin_processmaker_taskcategories_id - $app_delegation = []; - $query = "SELECT CONCAT(APPLICATION.APP_NUMBER, '-', APP_DELEGATION.DEL_INDEX) AS 'key', APP_DELEGATION.TAS_UID FROM APP_DELEGATION - LEFT JOIN APPLICATION ON APPLICATION.APP_UID=APP_DELEGATION.APP_UID"; - foreach ($PM_DB->request($query) as $row) { - $app_delegation[$row['key']]=$row['TAS_UID']; - } - - $taskcats = []; - $query = "SELECT * FROM glpi_plugin_processmaker_taskcategories"; - foreach ($DB->request($query) as $row) { - $taskcats[$row['pm_task_guid']] = $row['id']; - } - - $query = "SELECT * FROM glpi_plugin_processmaker_tasks"; - foreach ($DB->request($query) as $row) { - $key = $row['plugin_processmaker_cases_id']."-".$row['del_index']; - if (isset($app_delegation[$key]) && isset($taskcats[$app_delegation[$key]])) { - $DB->query("UPDATE glpi_plugin_processmaker_tasks SET plugin_processmaker_taskcategories_id={$taskcats[$app_delegation[$key]]} WHERE id={$row['id']}") or - die("error updating plugin_processmaker_taskcategories_id in glpi_plugin_processmaker_tasks table" . $DB->error()); - } - } - - $query = "UPDATE `glpi_tickettasks` SET `glpi_tickettasks`.`content` = REPLACE(`glpi_tickettasks`.`content`, '##ticket.url##_PluginProcessmakerCase\$processmakercases', '##processmakercase.url##') - WHERE `glpi_tickettasks`.`content` LIKE '%##ticket.url##_PluginProcessmakerCase\$processmakercases%'"; - $DB->query($query) or die("error updating content field in glpi_tickettasks" . $DB->error()); - - } - - if (!$DB->fieldExists("glpi_plugin_processmaker_taskcategories", "is_subprocess" )) { - $query = "ALTER TABLE `glpi_plugin_processmaker_taskcategories` - ALTER `processes_id` DROP DEFAULT;"; - $DB->query($query) or die("error normalizing glpi_plugin_processmaker_taskcategories step 1" . $DB->error()); - - $query = "ALTER TABLE `glpi_plugin_processmaker_taskcategories` - CHANGE COLUMN `processes_id` `plugin_processmaker_processes_id` INT(11) NOT NULL AFTER `id`, - CHANGE COLUMN `start` `is_start` TINYINT(1) NOT NULL DEFAULT '0' AFTER `taskcategories_id`, - ADD COLUMN `is_subprocess` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_active`, - DROP INDEX `processes_id`, - ADD INDEX `plugin_processmaker_processes_id` (`plugin_processmaker_processes_id`);"; - $DB->query($query) or die("error normalizing glpi_plugin_processmaker_taskcategories step 2" . $DB->error()); - } - - if ($DB->fieldExists("glpi_plugin_processmaker_users", "password" )) { - $query = "ALTER TABLE `glpi_plugin_processmaker_users` - DROP COLUMN `password`; - "; - $DB->query($query) or die("error deleting password col from glpi_plugin_processmaker_users" . $DB->error()); - } - - if (!$DB->fieldExists("glpi_plugin_processmaker_crontaskactions", "plugin_processmaker_cases_id" )) { - $query = "ALTER TABLE `glpi_plugin_processmaker_crontaskactions` - ADD COLUMN `plugin_processmaker_cases_id` INT(11) DEFAULT '0' AFTER `plugin_processmaker_caselinks_id`;"; - $DB->query($query) or die("error adding plugin_processmaker_cases_id col into glpi_plugin_processmaker_crontaskactions" . $DB->error()); - - // data migration - // before the 3.3.0 release there was one and only one case per item - $query ="UPDATE `glpi_plugin_processmaker_crontaskactions` - LEFT JOIN `glpi_plugin_processmaker_cases` ON `glpi_plugin_processmaker_cases`.`itemtype` = `glpi_plugin_processmaker_crontaskactions`.`itemtype` - AND `glpi_plugin_processmaker_cases`.`items_id` = `glpi_plugin_processmaker_crontaskactions`.`items_id` - SET `glpi_plugin_processmaker_crontaskactions`.`plugin_processmaker_cases_id` = `glpi_plugin_processmaker_cases`.`id`;"; - $DB->query($query) or die("error migrating itemtype and items_id into a plugin_processmaker_cases_id col in glpi_plugin_processmaker_crontaskactions" . $DB->error()); - // end of migration - - $query = "ALTER TABLE `glpi_plugin_processmaker_crontaskactions` - DROP COLUMN `itemtype`, - DROP COLUMN `items_id`;"; - $DB->query($query) or die("error deleting adding itemtype and items_id cols from glpi_plugin_processmaker_crontaskactions" . $DB->error()); - } - - return '3.3.0'; -} +fieldExists("glpi_plugin_processmaker_cases", "plugin_processmaker_processes_id" )) { + $query = "ALTER TABLE `glpi_plugin_processmaker_cases` + ALTER `id` DROP DEFAULT;"; + $DB->query($query) or die("error normalizing glpi_plugin_processmaker_cases table step 1" . $DB->error()); + + $query = "ALTER TABLE `glpi_plugin_processmaker_cases` + CHANGE COLUMN `id` `case_guid` VARCHAR(32) NOT NULL AFTER `items_id`;"; + $DB->query($query) or die("error normalizing glpi_plugin_processmaker_cases table step 2" . $DB->error()); + + $query = "ALTER TABLE `glpi_plugin_processmaker_cases` + CHANGE COLUMN `case_num` `id` INT(11) NOT NULL FIRST, + CHANGE COLUMN `itemtype` `itemtype` VARCHAR(10) NOT NULL DEFAULT 'Ticket' AFTER `id`, + ADD COLUMN `entities_id` INT(11) NOT NULL DEFAULT '0' AFTER `items_id`, + ADD COLUMN `name` MEDIUMTEXT NOT NULL DEFAULT '' AFTER `entities_id`, + CHANGE COLUMN `processes_id` `plugin_processmaker_processes_id` INT(11) NULL DEFAULT NULL AFTER `case_status`, + ADD COLUMN `plugin_processmaker_cases_id` INT(11) NOT NULL DEFAULT '0' AFTER `plugin_processmaker_processes_id`, + DROP INDEX `items`, + ADD INDEX `items` (`itemtype`, `items_id`), + ADD PRIMARY KEY (`id`), + ADD UNIQUE INDEX `case_guid` (`case_guid`), + ADD INDEX `plugin_processmaker_cases_id` (`plugin_processmaker_cases_id`), + ADD INDEX `plugin_processmaker_processes_id` (`plugin_processmaker_processes_id`);"; + + $DB->query($query) or die("error normalizing glpi_plugin_processmaker_cases table step 3 " . $DB->error()); + + // needs to set entities_id and name fields + // for this needs to browse all cases and do a getCaseInfo for each and to get entities_id from itemtype(items_id) + foreach ($DB->request(PluginProcessmakerCase::getTable()) as $row) { + $tmp = new $row['itemtype']; + $entities_id = 0; + if ($tmp->getFromDB($row['items_id'])) { + $entities_id = $tmp->fields['entities_id']; + } + foreach ($PM_DB->request("SELECT CON_VALUE FROM CONTENT WHERE CON_CATEGORY='APP_TITLE' AND CON_LANG='en' AND CON_ID='{$row['case_guid']}'") as $name) { + // there is only one record :) + $name = $PM_DB->escape($name['CON_VALUE']); + $query = "UPDATE ".PluginProcessmakerCase::getTable()." SET `name` = '{$name}', `entities_id` = $entities_id WHERE `id` = {$row['id']};"; + $DB->query($query) or die("error normalizing glpi_plugin_processmaker_cases table step 4 " . $DB->error()); + } + } + } + + if (!$DB->fieldExists("glpi_plugin_processmaker_processes_profiles", "plugin_processmaker_processes_id")) { + $query = "ALTER TABLE `glpi_plugin_processmaker_processes_profiles` + CHANGE COLUMN `processes_id` `plugin_processmaker_processes_id` INT(11) NOT NULL DEFAULT '0' AFTER `id`, + DROP INDEX `processes_id`, + ADD INDEX `plugin_processmaker_processes_id` (`plugin_processmaker_processes_id`);"; + $DB->query($query) or die("error on glpi_plugin_processmaker_processes_profiles table when renaming processes_id into plugin_processmaker_processes_id " . $DB->error()); + + // must clean the table in case there would be duplicate entries for a process + $query = "SELECT gpp.id, gpp.plugin_processmaker_processes_id, gpp.profiles_id, gpp.entities_id, MAX(gpp.is_recursive) AS is_recursive + FROM glpi_plugin_processmaker_processes_profiles AS gpp + GROUP BY gpp.plugin_processmaker_processes_id, gpp.profiles_id, gpp.entities_id + HAVING COUNT(id) > 1;"; + + foreach ($DB->request($query) as $rec) { + // there we have one rec per duplicates + // so we may delete all records in the table, and a new one + $del_query = "DELETE FROM glpi_plugin_processmaker_processes_profiles WHERE plugin_processmaker_processes_id=".$rec['plugin_processmaker_processes_id']." + AND profiles_id = ".$rec['profiles_id']." + AND entities_id = ".$rec['entities_id'].";"; + $DB->query($del_query) or die("error when deleting duplicated process_profiles in glpi_plugin_processmaker_processes_profiles table ". $DB->error()); + + $add_query = "INSERT INTO `glpi_plugin_processmaker_processes_profiles` (`id`, `plugin_processmaker_processes_id`, `profiles_id`, `entities_id`, `is_recursive`) + VALUES (".$rec['id'].", ".$rec['plugin_processmaker_processes_id'].", ".$rec['profiles_id'].", ".$rec['entities_id'].", ".$rec['is_recursive'].");"; + $DB->query($add_query) or die("error when inserting singletons of duplicated process_profiles in glpi_plugin_processmaker_processes_profiles table ". $DB->error()); + } + + $query = "ALTER TABLE `glpi_plugin_processmaker_processes_profiles` + ADD UNIQUE INDEX `plugin_processmaker_processes_id_profiles_id_entities_id` (`plugin_processmaker_processes_id`, `profiles_id`, `entities_id`);"; + $DB->query($query) or die("error when adding new index on glpi_plugin_processmaker_processes_profiles table " . $DB->error()); + } + + if (!$DB->fieldExists("glpi_plugin_processmaker_tasks", "plugin_processmaker_cases_id" )) { + $query = "ALTER TABLE `glpi_plugin_processmaker_tasks` + ALTER `itemtype` DROP DEFAULT;"; + $DB->query($query) or die("error normalizing glpi_plugin_processmaker_tasks table step 1" . $DB->error()); + + $query = "ALTER TABLE `glpi_plugin_processmaker_tasks` + CHANGE COLUMN `itemtype` `itemtype` VARCHAR(32) NOT NULL AFTER `id`, + ADD COLUMN `plugin_processmaker_cases_id` INT(11) NULL AFTER `case_id`, + ADD COLUMN `plugin_processmaker_taskcategories_id` INT(11) NULL AFTER `plugin_processmaker_cases_id`, + ADD COLUMN `del_thread` INT(11) NOT NULL AFTER `del_index`, + ADD COLUMN `del_thread_status` VARCHAR(32) NOT NULL DEFAULT 'OPEN' AFTER `del_thread`, + DROP INDEX `case_id`, + ADD UNIQUE INDEX `tasks` (`plugin_processmaker_cases_id`, `del_index`), + ADD INDEX `del_thread_status` (`del_thread_status`);"; + $DB->query($query) or die("error normalizing glpi_plugin_processmaker_tasks table step 2" . $DB->error()); + + // transform case_id (=GUID) into plugin_processmaker_cases_id + $query = "UPDATE `glpi_plugin_processmaker_tasks` + LEFT JOIN `glpi_plugin_processmaker_cases` ON `glpi_plugin_processmaker_cases`.`case_guid` = `glpi_plugin_processmaker_tasks`.`case_id` + SET `glpi_plugin_processmaker_tasks`.`plugin_processmaker_cases_id` = `glpi_plugin_processmaker_cases`.`id`;"; + $DB->query($query) or die("error transforming case_id into plugin_processmaker_cases_id in glpi_plugin_processmaker_tasks table" . $DB->error()); + + $query = "ALTER TABLE `glpi_plugin_processmaker_tasks` + DROP COLUMN `case_id`;"; + $DB->query($query) or die("error deleting case_id column in glpi_plugin_processmaker_tasks table" . $DB->error()); + + // set real thread status get it from APP_DELEGATION + $query = "SELECT APP_UID, DEL_INDEX, DEL_THREAD, DEL_THREAD_STATUS FROM APP_DELEGATION WHERE DEL_THREAD_STATUS = 'CLOSED';"; + $locThreads = []; + foreach ($PM_DB->request($query) as $thread) { + $locThreads[$thread['APP_UID']][] = $thread; + } + $locCase = new PluginProcessmakerCase; + foreach ($locThreads as $key => $threads) { + // get GLPI case id + $locCase->getFromGUID($key); + $del_indexes = []; + foreach ($threads as $thread) { + $del_indexes[] = $thread['DEL_INDEX']; + } + $del_indexes = implode(", ", $del_indexes); + $query = "UPDATE glpi_plugin_processmaker_tasks SET del_thread_status = 'CLOSED' WHERE plugin_processmaker_cases_id = {$locCase->getID()} AND del_index IN ($del_indexes)"; + $DB->query($query) or die("error updating del_thread_status in glpi_plugin_processmaker_tasks table" . $DB->error()); + } + + // set the plugin_processmaker_taskcategories_id + $app_delegation = []; + $query = "SELECT CONCAT(APPLICATION.APP_NUMBER, '-', APP_DELEGATION.DEL_INDEX) AS 'key', APP_DELEGATION.TAS_UID FROM APP_DELEGATION + LEFT JOIN APPLICATION ON APPLICATION.APP_UID=APP_DELEGATION.APP_UID"; + foreach ($PM_DB->request($query) as $row) { + $app_delegation[$row['key']]=$row['TAS_UID']; + } + + $taskcats = []; + $query = "SELECT * FROM glpi_plugin_processmaker_taskcategories"; + foreach ($DB->request($query) as $row) { + $taskcats[$row['pm_task_guid']] = $row['id']; + } + + $query = "SELECT * FROM glpi_plugin_processmaker_tasks"; + foreach ($DB->request($query) as $row) { + $key = $row['plugin_processmaker_cases_id']."-".$row['del_index']; + if (isset($app_delegation[$key]) && isset($taskcats[$app_delegation[$key]])) { + $DB->query("UPDATE glpi_plugin_processmaker_tasks SET plugin_processmaker_taskcategories_id={$taskcats[$app_delegation[$key]]} WHERE id={$row['id']}") or + die("error updating plugin_processmaker_taskcategories_id in glpi_plugin_processmaker_tasks table" . $DB->error()); + } + } + + $query = "UPDATE `glpi_tickettasks` SET `glpi_tickettasks`.`content` = REPLACE(`glpi_tickettasks`.`content`, '##ticket.url##_PluginProcessmakerCase\$processmakercases', '##processmakercase.url##') + WHERE `glpi_tickettasks`.`content` LIKE '%##ticket.url##_PluginProcessmakerCase\$processmakercases%'"; + $DB->query($query) or die("error updating content field in glpi_tickettasks" . $DB->error()); + + } + + if (!$DB->fieldExists("glpi_plugin_processmaker_taskcategories", "is_subprocess" )) { + $query = "ALTER TABLE `glpi_plugin_processmaker_taskcategories` + ALTER `processes_id` DROP DEFAULT;"; + $DB->query($query) or die("error normalizing glpi_plugin_processmaker_taskcategories step 1" . $DB->error()); + + $query = "ALTER TABLE `glpi_plugin_processmaker_taskcategories` + CHANGE COLUMN `processes_id` `plugin_processmaker_processes_id` INT(11) NOT NULL AFTER `id`, + CHANGE COLUMN `start` `is_start` TINYINT(1) NOT NULL DEFAULT '0' AFTER `taskcategories_id`, + ADD COLUMN `is_subprocess` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_active`, + DROP INDEX `processes_id`, + ADD INDEX `plugin_processmaker_processes_id` (`plugin_processmaker_processes_id`);"; + $DB->query($query) or die("error normalizing glpi_plugin_processmaker_taskcategories step 2" . $DB->error()); + } + + if ($DB->fieldExists("glpi_plugin_processmaker_users", "password" )) { + $query = "ALTER TABLE `glpi_plugin_processmaker_users` + DROP COLUMN `password`; + "; + $DB->query($query) or die("error deleting password col from glpi_plugin_processmaker_users" . $DB->error()); + } + + if (!$DB->fieldExists("glpi_plugin_processmaker_crontaskactions", "plugin_processmaker_cases_id" )) { + $query = "ALTER TABLE `glpi_plugin_processmaker_crontaskactions` + ADD COLUMN `plugin_processmaker_cases_id` INT(11) DEFAULT '0' AFTER `plugin_processmaker_caselinks_id`;"; + $DB->query($query) or die("error adding plugin_processmaker_cases_id col into glpi_plugin_processmaker_crontaskactions" . $DB->error()); + + // data migration + // before the 3.3.0 release there was one and only one case per item + $query ="UPDATE `glpi_plugin_processmaker_crontaskactions` + LEFT JOIN `glpi_plugin_processmaker_cases` ON `glpi_plugin_processmaker_cases`.`itemtype` = `glpi_plugin_processmaker_crontaskactions`.`itemtype` + AND `glpi_plugin_processmaker_cases`.`items_id` = `glpi_plugin_processmaker_crontaskactions`.`items_id` + SET `glpi_plugin_processmaker_crontaskactions`.`plugin_processmaker_cases_id` = `glpi_plugin_processmaker_cases`.`id`;"; + $DB->query($query) or die("error migrating itemtype and items_id into a plugin_processmaker_cases_id col in glpi_plugin_processmaker_crontaskactions" . $DB->error()); + // end of migration + + $query = "ALTER TABLE `glpi_plugin_processmaker_crontaskactions` + DROP COLUMN `itemtype`, + DROP COLUMN `items_id`;"; + $DB->query($query) or die("error deleting adding itemtype and items_id cols from glpi_plugin_processmaker_crontaskactions" . $DB->error()); + } + + return '3.3.0'; +} diff --git a/install/update_3_3_0_to_3_3_1.php b/install/update_3_3_0_to_3_3_1.php index 6ec7346..f1dfe97 100644 --- a/install/update_3_3_0_to_3_3_1.php +++ b/install/update_3_3_0_to_3_3_1.php @@ -1,30 +1,30 @@ -fieldExists("glpi_plugin_processmaker_processes", "is_change" )) { - $query = "ALTER TABLE `glpi_plugin_processmaker_processes` - ADD COLUMN `is_change` TINYINT(1) NOT NULL DEFAULT '0' AFTER `project_type`, - ADD COLUMN `is_problem` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_change`, - ADD COLUMN `is_incident` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_problem`, - ADD COLUMN `is_request` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_incident`;"; - - $DB->query($query) or die("error adding is_change, etc... to glpi_plugin_processmaker_processes table" . $DB->error()); - - } - - // Alter table glpi_plugin_processmaker_caselinks - if (!$DB->fieldExists("glpi_plugin_processmaker_caselinks", "is_targettoreassign" )) { - $query = "ALTER TABLE `glpi_plugin_processmaker_caselinks` - ADD COLUMN `is_targettoreassign` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_targettoclaim`, - ADD COLUMN `is_targettoimpersonate` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_targettoreassign`, - ADD COLUMN `is_synchronous` TINYINT(1) NOT NULL DEFAULT '0' AFTER `externalapplication`;"; - - $DB->query($query) or die("error adding is_targettoreassign, etc... to glpi_plugin_processmaker_caselinks table" . $DB->error()); - - } - - return '3.3.1'; -} +fieldExists("glpi_plugin_processmaker_processes", "is_change" )) { + $query = "ALTER TABLE `glpi_plugin_processmaker_processes` + ADD COLUMN `is_change` TINYINT(1) NOT NULL DEFAULT '0' AFTER `project_type`, + ADD COLUMN `is_problem` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_change`, + ADD COLUMN `is_incident` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_problem`, + ADD COLUMN `is_request` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_incident`;"; + + $DB->query($query) or die("error adding is_change, etc... to glpi_plugin_processmaker_processes table" . $DB->error()); + + } + + // Alter table glpi_plugin_processmaker_caselinks + if (!$DB->fieldExists("glpi_plugin_processmaker_caselinks", "is_targettoreassign" )) { + $query = "ALTER TABLE `glpi_plugin_processmaker_caselinks` + ADD COLUMN `is_targettoreassign` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_targettoclaim`, + ADD COLUMN `is_targettoimpersonate` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_targettoreassign`, + ADD COLUMN `is_synchronous` TINYINT(1) NOT NULL DEFAULT '0' AFTER `externalapplication`;"; + + $DB->query($query) or die("error adding is_targettoreassign, etc... to glpi_plugin_processmaker_caselinks table" . $DB->error()); + + } + + return '3.3.1'; +} diff --git a/install/update_3_3_1_to_3_3_8.php b/install/update_3_3_1_to_3_3_8.php index 1a4e4f7..b792f80 100644 --- a/install/update_3_3_1_to_3_3_8.php +++ b/install/update_3_3_1_to_3_3_8.php @@ -1,15 +1,15 @@ -fieldExists("glpi_plugin_processmaker_configs", "ssl_verify" )) { - $query = "ALTER TABLE `glpi_plugin_processmaker_configs` - ADD COLUMN `ssl_verify` TINYINT(1) NOT NULL DEFAULT '0' AFTER `maintenance`;"; - - $DB->query($query) or die("error adding ssl_verify to glpi_plugin_processmaker_configs table" . $DB->error()); - } - - return '3.3.8'; +fieldExists("glpi_plugin_processmaker_configs", "ssl_verify" )) { + $query = "ALTER TABLE `glpi_plugin_processmaker_configs` + ADD COLUMN `ssl_verify` TINYINT(1) NOT NULL DEFAULT '0' AFTER `maintenance`;"; + + $DB->query($query) or die("error adding ssl_verify to glpi_plugin_processmaker_configs table" . $DB->error()); + } + + return '3.3.8'; } \ No newline at end of file diff --git a/install/update_3_3_8_to_3_4_9.php b/install/update_3_3_8_to_3_4_9.php index 6ce86c3..2a02b9d 100644 --- a/install/update_3_3_8_to_3_4_9.php +++ b/install/update_3_3_8_to_3_4_9.php @@ -1,30 +1,30 @@ -fieldExists("glpi_plugin_processmaker_configs", "max_cases_per_item" )) { - $query = "ALTER TABLE `glpi_plugin_processmaker_configs` - ADD COLUMN `max_cases_per_item` INT(11) NOT NULL DEFAULT '0' AFTER `db_version`;"; - - $DB->query($query) or die("error adding max_cases_per_item to glpi_plugin_processmaker_configs table" . $DB->error()); - } - - // Alter table glpi_plugin_processmaker_processes - if (!$DB->fieldExists("glpi_plugin_processmaker_processes", "maintenance" )) { - $query = "ALTER TABLE `glpi_plugin_processmaker_processes` - ADD COLUMN `maintenance` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_request`;"; - - $DB->query($query) or die("error adding maintenance to glpi_plugin_processmaker_processes table" . $DB->error()); - } - // Alter table glpi_plugin_processmaker_processes - if (!$DB->fieldExists("glpi_plugin_processmaker_processes", "max_cases_per_item" )) { - $query = "ALTER TABLE `glpi_plugin_processmaker_processes` - ADD COLUMN `max_cases_per_item` INT(11) NOT NULL DEFAULT '0' AFTER `maintenance`;"; - - $DB->query($query) or die("error adding max_cases_per_item to glpi_plugin_processmaker_processes table" . $DB->error()); - } - - return '3.4.9'; +fieldExists("glpi_plugin_processmaker_configs", "max_cases_per_item" )) { + $query = "ALTER TABLE `glpi_plugin_processmaker_configs` + ADD COLUMN `max_cases_per_item` INT(11) NOT NULL DEFAULT '0' AFTER `db_version`;"; + + $DB->query($query) or die("error adding max_cases_per_item to glpi_plugin_processmaker_configs table" . $DB->error()); + } + + // Alter table glpi_plugin_processmaker_processes + if (!$DB->fieldExists("glpi_plugin_processmaker_processes", "maintenance" )) { + $query = "ALTER TABLE `glpi_plugin_processmaker_processes` + ADD COLUMN `maintenance` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_request`;"; + + $DB->query($query) or die("error adding maintenance to glpi_plugin_processmaker_processes table" . $DB->error()); + } + // Alter table glpi_plugin_processmaker_processes + if (!$DB->fieldExists("glpi_plugin_processmaker_processes", "max_cases_per_item" )) { + $query = "ALTER TABLE `glpi_plugin_processmaker_processes` + ADD COLUMN `max_cases_per_item` INT(11) NOT NULL DEFAULT '0' AFTER `maintenance`;"; + + $DB->query($query) or die("error adding max_cases_per_item to glpi_plugin_processmaker_processes table" . $DB->error()); + } + + return '3.4.9'; } \ No newline at end of file diff --git a/install/update_3_4_10_to_4_0_0.php b/install/update_3_4_10_to_4_0_0.php index 3c4ec05..9406c23 100644 --- a/install/update_3_4_10_to_4_0_0.php +++ b/install/update_3_4_10_to_4_0_0.php @@ -1,14 +1,14 @@ -migratePasswords()) { - return '4.0.0'; - } - - return false; +migratePasswords()) { + return '4.0.0'; + } + + return false; } \ No newline at end of file diff --git a/install/update_3_4_9_to_3_4_10.php b/install/update_3_4_9_to_3_4_10.php index 365cbc1..2e45f07 100644 --- a/install/update_3_4_9_to_3_4_10.php +++ b/install/update_3_4_9_to_3_4_10.php @@ -1,12 +1,12 @@ -query($query) or die("error when updating event field in glpi_notifications" . $DB->error()); - - return '3.4.10'; +query($query) or die("error when updating event field in glpi_notifications" . $DB->error()); + + return '3.4.10'; } \ No newline at end of file diff --git a/js/cases.helpdesk.js b/js/cases.helpdesk.js index 40c1f1d..43fc60e 100644 --- a/js/cases.helpdesk.js +++ b/js/cases.helpdesk.js @@ -1,121 +1,121 @@ - -var oldHandler; -var submitButton; -var caseIFrame; - -function onClickContinue(obj) { - //debugger; - contentDocument = caseIFrame.contentDocument; - var txtAreaUserRequestSumUp = contentDocument.getElementById('form[UserRequestSumUp]'); - if ($("textarea[name='content']").val() == '') { - if (txtAreaUserRequestSumUp) { - tinymce.activeEditor.setContent($(txtAreaUserRequestSumUp).val().replace(/(\r\n)|(\r)|(\n)/g, '
')); - } else { - tinymce.activeEditor.setContent('_'); - } - } - - // call old handler if any - //debugger; - if (obj != undefined && oldHandler) { - oldHandler(obj.target); - } - // hide the iFrame - caseIFrame.style.visibility = 'hidden'; - - // trigger a click on the 'add' button of the ticket - submitButton.click(); -} - - -// used to find an element in a list and to hide it! -function bGLPIHideElement(eltList, attribute, value) { - var ret = false; - for (var i = 0; i < eltList.length; i++) { - var node = eltList[i]; - if (node.getAttribute(attribute) == value) { - // hide the link - node.style.display = 'none'; - ret = true; - } - } - return ret; -} - -function onLoadFrame( evt, caseId, delIndex, caseNumber, processName ) { - var caseTimerCounter = 0; - var redimIFrame = false; - var bButtonContinue = false; - var caseTimer = window.setInterval(function () { - //debugger ; - // look for caseiframe iFrame - - caseIFrame = document.getElementById('caseiframe'); - - var contentDocument; - try { - contentDocument = caseIFrame.contentDocument; - } catch (ex) { - contentDocument = false; - } - if (caseIFrame != undefined && contentDocument) { - var buttonContinue = contentDocument.getElementById('form[btnGLPISendRequest]'); - var linkList = contentDocument.getElementsByTagName('a'); - - if (!bButtonContinue && buttonContinue != undefined && linkList != undefined && linkList.length > 0) { - bButtonContinue = true; //window.clearInterval(caseTimer); // to be sure that it will be done only one time - // change action for the attached form and add some parameters - //debugger; - - bGLPIHideElement(linkList, 'href', 'cases_Step?TYPE=ASSIGN_TASK&UID=-1&POSITION=10000&ACTION=ASSIGN'); - - oldHandler = buttonContinue.onclick; - buttonContinue.onclick = onClickContinue; - - submitButton = $("input[name='add'][type=submit]")[0]; - submitButton.insertAdjacentHTML('beforebegin', ""); - submitButton.insertAdjacentHTML('beforebegin', ""); - submitButton.insertAdjacentHTML('beforebegin', ""); - submitButton.insertAdjacentHTML('beforebegin', ""); - - $("input[name='name'][type=text]")[0].value = processName; - - } - - // try to redim caseIFrame - if (!redimIFrame) { - redimIFrame = true; // to prevent several timer creation - - // redim one time - redimTaskFrame(caseIFrame); - - // redim each second - var redimFrameTimer = window.setInterval(function () { - redimTaskFrame(caseIFrame); - }, 1000); - } - } - - if ( caseTimerCounter > 3000 ) { - window.clearInterval(caseTimer); - } else { - caseTimerCounter = caseTimerCounter + 1; - } - - }, 10); -} - -function redimTaskFrame(taskFrame) { - var newHeight; - try { - //var locElt = locContentDocument.getElementsByTagName("table")[0]; - var locElt = taskFrame.contentDocument.getElementsByTagName("html")[0]; - newHeight = parseInt(getComputedStyle(locElt, null).getPropertyValue('height'), 10); - if (newHeight < 400) { - newHeight = 400; - } - - taskFrame.height = newHeight; - } catch (e) { - } -} + +var oldHandler; +var submitButton; +var caseIFrame; + +function onClickContinue(obj) { + //debugger; + contentDocument = caseIFrame.contentDocument; + var txtAreaUserRequestSumUp = contentDocument.getElementById('form[UserRequestSumUp]'); + if ($("textarea[name='content']").val() == '') { + if (txtAreaUserRequestSumUp) { + tinymce.activeEditor.setContent($(txtAreaUserRequestSumUp).val().replace(/(\r\n)|(\r)|(\n)/g, '
')); + } else { + tinymce.activeEditor.setContent('_'); + } + } + + // call old handler if any + //debugger; + if (obj != undefined && oldHandler) { + oldHandler(obj.target); + } + // hide the iFrame + caseIFrame.style.visibility = 'hidden'; + + // trigger a click on the 'add' button of the ticket + submitButton.click(); +} + + +// used to find an element in a list and to hide it! +function bGLPIHideElement(eltList, attribute, value) { + var ret = false; + for (var i = 0; i < eltList.length; i++) { + var node = eltList[i]; + if (node.getAttribute(attribute) == value) { + // hide the link + node.style.display = 'none'; + ret = true; + } + } + return ret; +} + +function onLoadFrame( evt, caseId, delIndex, caseNumber, processName ) { + var caseTimerCounter = 0; + var redimIFrame = false; + var bButtonContinue = false; + var caseTimer = window.setInterval(function () { + //debugger ; + // look for caseiframe iFrame + + caseIFrame = document.getElementById('caseiframe'); + + var contentDocument; + try { + contentDocument = caseIFrame.contentDocument; + } catch (ex) { + contentDocument = false; + } + if (caseIFrame != undefined && contentDocument) { + var buttonContinue = contentDocument.getElementById('form[btnGLPISendRequest]'); + var linkList = contentDocument.getElementsByTagName('a'); + + if (!bButtonContinue && buttonContinue != undefined && linkList != undefined && linkList.length > 0) { + bButtonContinue = true; //window.clearInterval(caseTimer); // to be sure that it will be done only one time + // change action for the attached form and add some parameters + //debugger; + + bGLPIHideElement(linkList, 'href', 'cases_Step?TYPE=ASSIGN_TASK&UID=-1&POSITION=10000&ACTION=ASSIGN'); + + oldHandler = buttonContinue.onclick; + buttonContinue.onclick = onClickContinue; + + submitButton = $("input[name='add'][type=submit]")[0]; + submitButton.insertAdjacentHTML('beforebegin', ""); + submitButton.insertAdjacentHTML('beforebegin', ""); + submitButton.insertAdjacentHTML('beforebegin', ""); + submitButton.insertAdjacentHTML('beforebegin', ""); + + $("input[name='name'][type=text]")[0].value = processName; + + } + + // try to redim caseIFrame + if (!redimIFrame) { + redimIFrame = true; // to prevent several timer creation + + // redim one time + redimTaskFrame(caseIFrame); + + // redim each second + var redimFrameTimer = window.setInterval(function () { + redimTaskFrame(caseIFrame); + }, 1000); + } + } + + if ( caseTimerCounter > 3000 ) { + window.clearInterval(caseTimer); + } else { + caseTimerCounter = caseTimerCounter + 1; + } + + }, 10); +} + +function redimTaskFrame(taskFrame) { + var newHeight; + try { + //var locElt = locContentDocument.getElementsByTagName("table")[0]; + var locElt = taskFrame.contentDocument.getElementsByTagName("html")[0]; + newHeight = parseInt(getComputedStyle(locElt, null).getPropertyValue('height'), 10); + if (newHeight < 400) { + newHeight = 400; + } + + taskFrame.height = newHeight; + } catch (e) { + } +} diff --git a/js/cases.js b/js/cases.js index d4b93ef..9a727a1 100644 --- a/js/cases.js +++ b/js/cases.js @@ -1,312 +1,312 @@ -//debugger; -// To manage submits to case.front.php -var GLPI_HTTP_CASE_FORM = window.location.href.replace(window.location.search, ''); //window.location.href.split('/', loc_split.length - 2).join('/') + '/plugins/processmaker/front/case.front.php'; // http://hostname/glpi/... -// to manage reloads -var GLPI_RELOAD_PARENT = window; //.location; -var GLPI_DURING_RELOAD = false; - -// used to find an element in a list and to hide it! -function bGLPIHideElement(eltList, attribute, value) { - var ret = false; - for (var i = 0; i < eltList.length && !ret; i++) { - var node = eltList[i]; - if (node.getAttribute(attribute) == value) { - // hide the link - node.style.display = 'none'; - ret = true; - } - } - return ret; -} - - -function displayOverlay() { - //debugger; - // don't use displayOverlay when submit input open new tab or update parent ( example: pdf generation ) - if (!($(this).is('input[type=submit]') - && $(this).parents('form').length > 0 - && ($(this).parents('form').first().attr('target') == '_blank' || $(this).parents('form').first().attr('target') == '_parent'))) { - $("
").appendTo("body"); - - var timer = window.setInterval(function () { - var count = $('.ui-widget-overlay.ui-front').length; - if (count == 2) { - $($('.ui-widget-overlay.ui-front')[1]).remove(); - window.clearInterval(timer); - } - - }, 10); - } -} - - -function onTaskFrameLoad(event, delIndex, hideClaimButton, csrf) { - //alert("Loaded frame " + delIndex); - //debugger; - var taskFrameId = event.target.id; //"caseiframe-" + delIndex; - var bShowHideNextStep = false; // not done yet! - var bHideClaimCancelButton = false; // To manage 'Claim' button - var taskFrameTimerCounter = 0; - var redimIFrame = false; - //debugger; - var taskFrameTimer = window.setInterval(function () { - try { - var locContentDocument; - var taskFrame = document.getElementById(taskFrameId); - try { - locContentDocument = taskFrame.contentDocument; - } catch (ex) { - locContentDocument = false; - } - if (taskFrame != undefined && locContentDocument != undefined) { - // here we've caught the content of the iframe - - // if task resumé, then hide the form part - //debugger; - //var form_resume = locContentDocument.getElementsByName('cases_Resume'); - //if (form_resume.length > 0 && form_resume[0].style.display != 'none') { - // form_resume[0].style.display = 'none'; - //} - - // then look if btnGLPISendRequest exists, - var locElt = locContentDocument.getElementById('form[btnGLPISendRequest]'); - if (!bShowHideNextStep && locElt != undefined ) { - var linkList = locContentDocument.getElementsByTagName('a'); - if (bGLPIHideElement(linkList, 'href', 'cases_Step?TYPE=ASSIGN_TASK&UID=-1&POSITION=10000&ACTION=ASSIGN')) { - // the next step link is hidden - - // if yes then change the link behind the button itself - locElt.type = 'submit'; - locElt.onclick = null; // in order to force use of the action of form POST - var formList = locContentDocument.getElementsByTagName('form'); - - // if yes then change the action of the form POST - var node = formList[0]; // must have one element in list: in a dynaform there is one and only one HTML form - node.setAttribute('actionBackup', node.action); - var action = node.action.split('?'); - node.action = GLPI_HTTP_CASE_FORM + '?' + action[1] + '&DEL_INDEX=' + delIndex + '&action=route'; - - // add an element that will be the csrf data code for the POST - //debugger; - var csrfElt = document.createElement("input"); - csrfElt.setAttribute("type", "hidden"); - csrfElt.setAttribute("name", "_glpi_csrf_token"); - csrfElt.setAttribute("value", csrf); - node.appendChild(csrfElt); - } else { - // then hide the button itself - locElt.style.display = 'none'; - } - - bShowHideNextStep = true; - } - - // Hide 'Cancel' button on 'Claim' form - var cancelButton = locContentDocument.getElementById('form[BTN_CANCEL]'); - if (cancelButton != undefined && !bHideClaimCancelButton) { - //debugger; - cancelButton.style.display = 'none'; - // hides claim button if asked for - if (hideClaimButton) { - claimButton = locContentDocument.getElementById('form[BTN_CATCH]'); - claimButton.style.display = 'none'; - } - // to manage Claim - var formList = locContentDocument.getElementsByTagName('form'); - var node = formList[0]; // must have one element in list: in a dynaform there is one and only one HTML form - node.setAttribute('actionBackup', node.action); - - var action = node.action.split('?'); - //debugger; - node.action = GLPI_HTTP_CASE_FORM + '?' + (action[1]?action[1]+'&':'') + 'DEL_INDEX=' + delIndex; - // add an element that will be the csrf data code for the POST - //debugger; - var csrfElt = document.createElement("input"); - csrfElt.setAttribute("type", "hidden"); - csrfElt.setAttribute("name", "_glpi_csrf_token"); - csrfElt.setAttribute("value", csrf); - node.appendChild(csrfElt); - - bHideClaimCancelButton = true; - // TODO - //node.addEventListener('submit', showMask); - } - - // to force immediate reload of GLPI item form - var forcedReload = locContentDocument.getElementById('GLPI_FORCE_RELOAD'); - if (forcedReload != undefined && !GLPI_DURING_RELOAD) { - //showMask(); - GLPI_DURING_RELOAD = true; // to prevent double reload - window.clearInterval(taskFrameTimer); // stop timer - GLPI_RELOAD_PARENT.location.reload(); - } - - // try to redim caseIFrame - if (!redimIFrame) { - redimTaskFrame(taskFrame, delIndex); - var redimFrameTimer = window.setInterval(function () { - redimTaskFrame(taskFrame, delIndex); - }, 1000); - - redimIFrame = true; - } - } - - taskFrameTimerCounter = taskFrameTimerCounter + 1; - - if (taskFrameTimerCounter > 3000 || bShowHideNextStep || bHideClaimCancelButton) { // either timeout or hiding is done - window.clearInterval(taskFrameTimer); - } - - } catch (evt) { - // nothing to do here for the moment - } - - }, 10); - -} - -function redimTaskFrame(taskFrame, delIndex) { - var newHeight; - try { - //var locElt = locContentDocument.getElementsByTagName("table")[0]; - var locElt = taskFrame.contentDocument.getElementsByTagName("html")[0]; - newHeight = parseInt(getComputedStyle(locElt, null).getPropertyValue('height'), 10); - if (newHeight < 500) { - newHeight = 500; - } - - taskFrame.height = newHeight; - } catch (e) { - } -} - -//function onTaskFrameActivation(delIndex) { -// var taskFrameId = "caseiframe-" + delIndex; -// var taskFrameTimerCounter = 0; -// var redimIFrame = false; - -// var taskFrameTimer = window.setInterval(function () { -// try { -// var locContentDocument; -// var taskFrame = document.getElementById(taskFrameId); - -// if (taskFrame != undefined && taskFrame.contentDocument != undefined) { -// // here we've caught the content of the iframe -// locContentDocument = taskFrame.contentDocument; - -// // try to redim caseIFrame -// if (!redimIFrame) { -// var newHeight; -// var locElt = locContentDocument.getElementsByTagName("html")[0]; -// newHeight = parseInt(getComputedStyle(locElt, null).getPropertyValue('height'), 10); - -// tabs.getItem('task-' + delIndex).setHeight(newHeight); -// taskFrame.height = newHeight; -// redimIFrame = true; -// } -// } - -// taskFrameTimerCounter = taskFrameTimerCounter + 1; - -// if (taskFrameTimerCounter > 3000 || redimIFrame) { // timeout -// window.clearInterval(taskFrameTimer); -// } - -// } catch (evt) { -// // nothing to do here for the moment -// } - -// }, 10); -//} -function clearClass(lociFrame) { - - try { - var locElt = lociFrame.contentDocument.getElementsByTagName('body')[0]; - if (locElt != undefined && locElt.className != '') { - //debugger; - locElt.className = ''; - - } - } catch (ev) { - - } -} - -function onOtherFrameLoad(tabPanelName, frameName, eltTagName, isMap3) { - var otherFrameId = frameName; - var otherFrameTimerCounter = 0; - var redimIFrame = false; - //debugger; - if (isMap3 == undefined) { - isMap3 = false; - } - - var otherFrameTimer = window.setInterval(function () { - try { - - var locContentDocument; - var otherFrame = document.getElementById(otherFrameId); - - if (otherFrame != undefined && otherFrame.contentDocument != undefined) { - // here we've caught the content of the iframe - clearClass(otherFrame); - - locContentDocument = otherFrame.contentDocument; - - // try to redim otherFrame - // and tabPanel - if (!redimIFrame) { - var locElt; - // isMap3 == true - // map is bpmn - // must look at div with special CSS class name to get newHeight and should change offset and size of parent div - if (!isMap3) { - if (tabPanelName == 'caseMap') { - // locElt = locContentDocument.querySelectorAll('div.panel_content___processmaker')[0]; - locElt = locContentDocument.querySelectorAll('div.panel_containerWindow___processmaker')[0]; - locElt2 = locContentDocument.getElementById('pm_target'); - locElt2.style.height = locElt.clientHeight + 'px'; - } else { - locElt = locContentDocument.getElementsByTagName(eltTagName)[0]; - } - } else { - locElt = locContentDocument.querySelectorAll('div.pmui-pmpool')[0]; - } - if (locElt != undefined) { - var newHeight; - if (isMap3) { - locElt.offsetParent.style.top = 0; - locElt.offsetParent.style.width = locElt.offsetWidth + 10 + locElt.offsetLeft + 'px'; - locElt.offsetParent.style.height = locElt.offsetHeight + locElt.offsetTop + 'px'; - newHeight = (locElt.offsetHeight < 500 ? 500 : locElt.offsetHeight) + locElt.offsetParent.offsetTop + 30; - } else { - newHeight = (locElt.offsetHeight < 500 ? 500 : locElt.offsetHeight); - } - if (tabPanelName == 'caseMap') { - // trick to force scrollbar to be shown - locElt.offsetParent.style.overflow = 'visible'; - locElt.offsetParent.style.overflow = 'hidden'; - } - if (locElt.scrollHeight && locElt.scrollHeight > newHeight) { - newHeight = locElt.scrollHeight; - } - //NOT NEEDED WITH jQuery: tabs.getItem(tabPanelName).setHeight(newHeight); - otherFrame.height = newHeight; - redimIFrame = true; - } - } - } - - otherFrameTimerCounter = otherFrameTimerCounter + 1; - - if (otherFrameTimerCounter > 3000 || redimIFrame) { - window.clearInterval(otherFrameTimer); - } - - } catch (ev) { - // nothing to do here for the moment - } - }, 10); - -} +//debugger; +// To manage submits to case.front.php +var GLPI_HTTP_CASE_FORM = window.location.href.replace(window.location.search, ''); //window.location.href.split('/', loc_split.length - 2).join('/') + '/plugins/processmaker/front/case.front.php'; // http://hostname/glpi/... +// to manage reloads +var GLPI_RELOAD_PARENT = window; //.location; +var GLPI_DURING_RELOAD = false; + +// used to find an element in a list and to hide it! +function bGLPIHideElement(eltList, attribute, value) { + var ret = false; + for (var i = 0; i < eltList.length && !ret; i++) { + var node = eltList[i]; + if (node.getAttribute(attribute) == value) { + // hide the link + node.style.display = 'none'; + ret = true; + } + } + return ret; +} + + +function displayOverlay() { + //debugger; + // don't use displayOverlay when submit input open new tab or update parent ( example: pdf generation ) + if (!($(this).is('input[type=submit]') + && $(this).parents('form').length > 0 + && ($(this).parents('form').first().attr('target') == '_blank' || $(this).parents('form').first().attr('target') == '_parent'))) { + $("
").appendTo("body"); + + var timer = window.setInterval(function () { + var count = $('.ui-widget-overlay.ui-front').length; + if (count == 2) { + $($('.ui-widget-overlay.ui-front')[1]).remove(); + window.clearInterval(timer); + } + + }, 10); + } +} + + +function onTaskFrameLoad(event, delIndex, hideClaimButton, csrf) { + //alert("Loaded frame " + delIndex); + //debugger; + var taskFrameId = event.target.id; //"caseiframe-" + delIndex; + var bShowHideNextStep = false; // not done yet! + var bHideClaimCancelButton = false; // To manage 'Claim' button + var taskFrameTimerCounter = 0; + var redimIFrame = false; + //debugger; + var taskFrameTimer = window.setInterval(function () { + try { + var locContentDocument; + var taskFrame = document.getElementById(taskFrameId); + try { + locContentDocument = taskFrame.contentDocument; + } catch (ex) { + locContentDocument = false; + } + if (taskFrame != undefined && locContentDocument != undefined) { + // here we've caught the content of the iframe + + // if task resumé, then hide the form part + //debugger; + //var form_resume = locContentDocument.getElementsByName('cases_Resume'); + //if (form_resume.length > 0 && form_resume[0].style.display != 'none') { + // form_resume[0].style.display = 'none'; + //} + + // then look if btnGLPISendRequest exists, + var locElt = locContentDocument.getElementById('form[btnGLPISendRequest]'); + if (!bShowHideNextStep && locElt != undefined ) { + var linkList = locContentDocument.getElementsByTagName('a'); + if (bGLPIHideElement(linkList, 'href', 'cases_Step?TYPE=ASSIGN_TASK&UID=-1&POSITION=10000&ACTION=ASSIGN')) { + // the next step link is hidden + + // if yes then change the link behind the button itself + locElt.type = 'submit'; + locElt.onclick = null; // in order to force use of the action of form POST + var formList = locContentDocument.getElementsByTagName('form'); + + // if yes then change the action of the form POST + var node = formList[0]; // must have one element in list: in a dynaform there is one and only one HTML form + node.setAttribute('actionBackup', node.action); + var action = node.action.split('?'); + node.action = GLPI_HTTP_CASE_FORM + '?' + action[1] + '&DEL_INDEX=' + delIndex + '&action=route'; + + // add an element that will be the csrf data code for the POST + //debugger; + var csrfElt = document.createElement("input"); + csrfElt.setAttribute("type", "hidden"); + csrfElt.setAttribute("name", "_glpi_csrf_token"); + csrfElt.setAttribute("value", csrf); + node.appendChild(csrfElt); + } else { + // then hide the button itself + locElt.style.display = 'none'; + } + + bShowHideNextStep = true; + } + + // Hide 'Cancel' button on 'Claim' form + var cancelButton = locContentDocument.getElementById('form[BTN_CANCEL]'); + if (cancelButton != undefined && !bHideClaimCancelButton) { + //debugger; + cancelButton.style.display = 'none'; + // hides claim button if asked for + if (hideClaimButton) { + claimButton = locContentDocument.getElementById('form[BTN_CATCH]'); + claimButton.style.display = 'none'; + } + // to manage Claim + var formList = locContentDocument.getElementsByTagName('form'); + var node = formList[0]; // must have one element in list: in a dynaform there is one and only one HTML form + node.setAttribute('actionBackup', node.action); + + var action = node.action.split('?'); + //debugger; + node.action = GLPI_HTTP_CASE_FORM + '?' + (action[1]?action[1]+'&':'') + 'DEL_INDEX=' + delIndex; + // add an element that will be the csrf data code for the POST + //debugger; + var csrfElt = document.createElement("input"); + csrfElt.setAttribute("type", "hidden"); + csrfElt.setAttribute("name", "_glpi_csrf_token"); + csrfElt.setAttribute("value", csrf); + node.appendChild(csrfElt); + + bHideClaimCancelButton = true; + // TODO + //node.addEventListener('submit', showMask); + } + + // to force immediate reload of GLPI item form + var forcedReload = locContentDocument.getElementById('GLPI_FORCE_RELOAD'); + if (forcedReload != undefined && !GLPI_DURING_RELOAD) { + //showMask(); + GLPI_DURING_RELOAD = true; // to prevent double reload + window.clearInterval(taskFrameTimer); // stop timer + GLPI_RELOAD_PARENT.location.reload(); + } + + // try to redim caseIFrame + if (!redimIFrame) { + redimTaskFrame(taskFrame, delIndex); + var redimFrameTimer = window.setInterval(function () { + redimTaskFrame(taskFrame, delIndex); + }, 1000); + + redimIFrame = true; + } + } + + taskFrameTimerCounter = taskFrameTimerCounter + 1; + + if (taskFrameTimerCounter > 3000 || bShowHideNextStep || bHideClaimCancelButton) { // either timeout or hiding is done + window.clearInterval(taskFrameTimer); + } + + } catch (evt) { + // nothing to do here for the moment + } + + }, 10); + +} + +function redimTaskFrame(taskFrame, delIndex) { + var newHeight; + try { + //var locElt = locContentDocument.getElementsByTagName("table")[0]; + var locElt = taskFrame.contentDocument.getElementsByTagName("html")[0]; + newHeight = parseInt(getComputedStyle(locElt, null).getPropertyValue('height'), 10); + if (newHeight < 500) { + newHeight = 500; + } + + taskFrame.height = newHeight; + } catch (e) { + } +} + +//function onTaskFrameActivation(delIndex) { +// var taskFrameId = "caseiframe-" + delIndex; +// var taskFrameTimerCounter = 0; +// var redimIFrame = false; + +// var taskFrameTimer = window.setInterval(function () { +// try { +// var locContentDocument; +// var taskFrame = document.getElementById(taskFrameId); + +// if (taskFrame != undefined && taskFrame.contentDocument != undefined) { +// // here we've caught the content of the iframe +// locContentDocument = taskFrame.contentDocument; + +// // try to redim caseIFrame +// if (!redimIFrame) { +// var newHeight; +// var locElt = locContentDocument.getElementsByTagName("html")[0]; +// newHeight = parseInt(getComputedStyle(locElt, null).getPropertyValue('height'), 10); + +// tabs.getItem('task-' + delIndex).setHeight(newHeight); +// taskFrame.height = newHeight; +// redimIFrame = true; +// } +// } + +// taskFrameTimerCounter = taskFrameTimerCounter + 1; + +// if (taskFrameTimerCounter > 3000 || redimIFrame) { // timeout +// window.clearInterval(taskFrameTimer); +// } + +// } catch (evt) { +// // nothing to do here for the moment +// } + +// }, 10); +//} +function clearClass(lociFrame) { + + try { + var locElt = lociFrame.contentDocument.getElementsByTagName('body')[0]; + if (locElt != undefined && locElt.className != '') { + //debugger; + locElt.className = ''; + + } + } catch (ev) { + + } +} + +function onOtherFrameLoad(tabPanelName, frameName, eltTagName, isMap3) { + var otherFrameId = frameName; + var otherFrameTimerCounter = 0; + var redimIFrame = false; + //debugger; + if (isMap3 == undefined) { + isMap3 = false; + } + + var otherFrameTimer = window.setInterval(function () { + try { + + var locContentDocument; + var otherFrame = document.getElementById(otherFrameId); + + if (otherFrame != undefined && otherFrame.contentDocument != undefined) { + // here we've caught the content of the iframe + clearClass(otherFrame); + + locContentDocument = otherFrame.contentDocument; + + // try to redim otherFrame + // and tabPanel + if (!redimIFrame) { + var locElt; + // isMap3 == true + // map is bpmn + // must look at div with special CSS class name to get newHeight and should change offset and size of parent div + if (!isMap3) { + if (tabPanelName == 'caseMap') { + // locElt = locContentDocument.querySelectorAll('div.panel_content___processmaker')[0]; + locElt = locContentDocument.querySelectorAll('div.panel_containerWindow___processmaker')[0]; + locElt2 = locContentDocument.getElementById('pm_target'); + locElt2.style.height = locElt.clientHeight + 'px'; + } else { + locElt = locContentDocument.getElementsByTagName(eltTagName)[0]; + } + } else { + locElt = locContentDocument.querySelectorAll('div.pmui-pmpool')[0]; + } + if (locElt != undefined) { + var newHeight; + if (isMap3) { + locElt.offsetParent.style.top = 0; + locElt.offsetParent.style.width = locElt.offsetWidth + 10 + locElt.offsetLeft + 'px'; + locElt.offsetParent.style.height = locElt.offsetHeight + locElt.offsetTop + 'px'; + newHeight = (locElt.offsetHeight < 500 ? 500 : locElt.offsetHeight) + locElt.offsetParent.offsetTop + 30; + } else { + newHeight = (locElt.offsetHeight < 500 ? 500 : locElt.offsetHeight); + } + if (tabPanelName == 'caseMap') { + // trick to force scrollbar to be shown + locElt.offsetParent.style.overflow = 'visible'; + locElt.offsetParent.style.overflow = 'hidden'; + } + if (locElt.scrollHeight && locElt.scrollHeight > newHeight) { + newHeight = locElt.scrollHeight; + } + //NOT NEEDED WITH jQuery: tabs.getItem(tabPanelName).setHeight(newHeight); + otherFrame.height = newHeight; + redimIFrame = true; + } + } + } + + otherFrameTimerCounter = otherFrameTimerCounter + 1; + + if (otherFrameTimerCounter > 3000 || redimIFrame) { + window.clearInterval(otherFrameTimer); + } + + } catch (ev) { + // nothing to do here for the moment + } + }, 10); + +} diff --git a/js/central.js b/js/central.js index fe4b7eb..82f996f 100644 --- a/js/central.js +++ b/js/central.js @@ -1,20 +1,20 @@ -$(function () { - $(document).ajaxComplete(function (event, jqXHR, ajaxOptions) { - //debugger; - var pattern = /##processmaker.*(##|...)/g; - - $('tr.tab_bg_2 td a').each(function (index) { - - var textToChange = $(this).text(); - var matches = textToChange.match(pattern); - if (matches) { - textToChange = textToChange.replace(pattern, ''); - if (!textToChange.trim().length>0) { - var title = $(this).parent().prev().text(); - textToChange = title; - } - $(this).text(textToChange); - } - }); - }); -}); +$(function () { + $(document).ajaxComplete(function (event, jqXHR, ajaxOptions) { + //debugger; + var pattern = /##processmaker.*(##|...)/g; + + $('tr.tab_bg_2 td a').each(function (index) { + + var textToChange = $(this).text(); + var matches = textToChange.match(pattern); + if (matches) { + textToChange = textToChange.replace(pattern, ''); + if (!textToChange.trim().length>0) { + var title = $(this).parent().prev().text(); + textToChange = title; + } + $(this).text(textToChange); + } + }); + }); +}); diff --git a/js/helpdesk.public.js.php b/js/helpdesk.public.js.php index 6d2bd5d..bf32519 100644 --- a/js/helpdesk.public.js.php +++ b/js/helpdesk.public.js.php @@ -1,26 +1,26 @@ -fields['maintenance']) { - echo "$(function () { - // look if name='helpdeskform' is present. If yes replace the form.location - var ahrefTI = '".$CFG_GLPI["root_doc"]."/plugins/processmaker/front/tracking.injector.php'; - var formLink = $(\"form[name='helpdeskform']\")[0]; - if (formLink != undefined) { - formLink.action = ahrefTI; - } - }); - "; // end of echo -} +fields['maintenance']) { + echo "$(function () { + // look if name='helpdeskform' is present. If yes replace the form.location + var ahrefTI = '".$CFG_GLPI["root_doc"]."/plugins/processmaker/front/tracking.injector.php'; + var formLink = $(\"form[name='helpdeskform']\")[0]; + if (formLink != undefined) { + formLink.action = ahrefTI; + } + }); + "; // end of echo +} diff --git a/js/planning.js b/js/planning.js index a0c8be9..e4a7c47 100644 --- a/js/planning.js +++ b/js/planning.js @@ -1,9 +1,9 @@ -$(function () { - $(document).ajaxComplete(function (event, jqXHR, ajaxOptions) { - //debugger; - if (!$('input[type="checkbox"][value="PluginProcessmakerTask"]').is(':checked')) { - $('input[type="checkbox"][value="PluginProcessmakerTask"]').trigger('click'); - } - $('input[type="checkbox"][value="PluginProcessmakerTask"]').parents('li').first().hide(); - }); +$(function () { + $(document).ajaxComplete(function (event, jqXHR, ajaxOptions) { + //debugger; + if (!$('input[type="checkbox"][value="PluginProcessmakerTask"]').is(':checked')) { + $('input[type="checkbox"][value="PluginProcessmakerTask"]').trigger('click'); + } + $('input[type="checkbox"][value="PluginProcessmakerTask"]').parents('li').first().hide(); + }); }); \ No newline at end of file