/** * See typology errors * * @param $error list * * @return nothing **/ static function displayErrors($error, $withlink = true) { global $CFG_GLPI; $items = explode(",", $error); $i = 0; $display = ""; if ($items[0] != NULL) { foreach ($items as $critID) { $crit = new PluginTypologyTypologyCriteria(); if ($crit->getFromDB($critID)) { if ($i == 0) { $display .= " "; $i++; } else { $display .= ", "; } $itemtype = $crit->fields["itemtype"]; $criteria = ""; if ($withlink) { $criteria = "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/typology/front/typologycriteria.form.php?id=" . $crit->fields["id"] . "' target='_blank'>"; } $criteria .= $crit->fields["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($crit->fields["name"])) { $criteria .= " (" . $crit->fields["id"] . ")"; } if ($withlink) { $criteria .= "</a>"; } $criteria .= " (" . $itemtype::getTypeName(0) . ")"; $display .= $criteria; } } } return $display; }
it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Typology is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Typology. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include '../../../inc/includes.php'; $typo = new PluginTypologyTypology(); $criteria = new PluginTypologyTypologyCriteria(); if (isset($_POST["update"])) { $criteria->check($_POST["id"], 'w'); $criteria->update($_POST); Html::back(); } else { if (isset($_POST["add"])) { $criteria->check(-1, 'w', $_POST); $newID = $criteria->add($_POST); Html::redirect($CFG_GLPI["root_doc"] . "/plugins/typology/front/typologycriteria.form.php?id={$newID}"); } else { if (isset($_POST["delete"])) { /*if (isset($_POST["item"]) && count($_POST["item"])) { foreach ($_POST["item"] as $key => $val) { if ($val == 1) { if ($criteria->can($key, 'w')) {
/** * Do the specific massive actions * * @since version 0.84 * * @param $input array of input datas * * @return an array of results (nbok, nbko, nbnoright counts) **/ function doSpecificMassiveActions($input = array()) { $res = array('ok' => 0, 'ko' => 0, 'noright' => 0); $criteria = new PluginTypologyTypologyCriteria(); $definition = new PluginTypologyTypologyCriteriaDefinition(); switch ($input['action']) { case "Transfert": if ($input['itemtype'] == 'PluginTypologyTypology') { foreach ($input["item"] as $key => $val) { if ($val == 1) { $this->getFromDB($key); $restrict = "`plugin_typology_typologies_id` = '" . $key . "'"; $crits = getAllDatasFromTable("glpi_plugin_typology_typologycriterias", $restrict); if (!empty($crits)) { foreach ($crits as $crit) { $criteria->getFromDB($crit["id"]); $condition = "`plugin_typology_typologycriterias_id` = '" . $crit["id"] . "'"; $defs = getAllDatasFromTable("glpi_plugin_typology_typologycriteriadefinitions", $condition); if (!empty($defs)) { foreach ($defs as $def) { $definition->getFromDB($def["id"]); unset($values); $values["id"] = $def["id"]; $values["entities_id"] = $input['entities_id']; $definition->update($values); } } unset($values); $values["id"] = $crit["id"]; $values["entities_id"] = $input['entities_id']; $criteria->update($values); } } unset($values); $values["id"] = $key; $values["entities_id"] = $input['entities_id']; if ($this->update($values)) { $res['ok']++; } else { $res['ko']++; } } } } break; case "Duplicate": if ($input['itemtype'] == 'PluginTypologyTypology') { foreach ($input["item"] as $key => $val) { if ($val == 1) { $this->getFromDB($key); $restrict = "`plugin_typology_typologies_id` = '" . $key . "'"; $crits = getAllDatasFromTable("glpi_plugin_typology_typologycriterias", $restrict); unset($this->fields["id"]); $this->fields["name"] = addslashes($this->fields["name"] . " Copy"); $this->fields["comment"] = addslashes($this->fields["comment"]); $this->fields["notepad"] = addslashes($this->fields["notepad"]); $newIDtypo = $this->add($this->fields); if ($newIDtypo) { $res['ok']++; } else { $res['ko']++; } if (!empty($crits)) { foreach ($crits as $crit) { $criteria->getFromDB($crit["id"]); $condition = "`plugin_typology_typologycriterias_id` = '" . $crit["id"] . "'"; $defs = getAllDatasFromTable("glpi_plugin_typology_typologycriteriadefinitions", $condition); unset($criteria->fields["id"]); $criteria->fields["name"] = addslashes($criteria->fields["name"]); $criteria->fields["plugin_typology_typologies_id"] = $newIDtypo; $criteria->fields["itemtype"] = addslashes($criteria->fields["itemtype"]); $newIDcrit = $criteria->add($criteria->fields); if (!empty($defs)) { foreach ($defs as $def) { $definition->getFromDB($def["id"]); unset($definition->fields["id"]); $definition->fields["plugin_typology_typologycriterias_id"] = $newIDcrit; $definition->fields["field"] = addslashes($definition->fields["field"]); $definition->fields["action_type"] = addslashes($definition->fields["action_type"]); $definition->fields["value"] = addslashes($definition->fields["value"]); $definition->add($definition->fields); } } } } } } } break; default: return parent::doSpecificMassiveActions($input); } return $res; }
/** * Do the specific massive actions * * @since version 0.84 * * @param $input array of input datas * * @return an array of results (nbok, nbko, nbnoright counts) **/ function doSpecificMassiveActions($input = array()) { $res = array('ok' => 0, 'ko' => 0, 'noright' => 0); $criteria = new PluginTypologyTypologyCriteria(); switch ($input['action']) { case "deleteAll": if ($input['itemtype'] == 'PluginTypologyTypologyCriteria') { foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($criteria->can($key, 'w')) { if ($criteria->delete(array('id' => $key))) { $res['ok']++; } else { $res['ko']++; } } } } } break; case "updateAll": if ($input['itemtype'] == 'PluginTypologyTypologyCriteria') { foreach ($input["item"] as $key => $val) { if ($val == 1) { $values = array('id' => $key, 'is_active' => $input['is_active']); if ($criteria->update($values)) { $res['ok']++; } else { $res['ko']++; } } } } break; default: return parent::doSpecificMassiveActions($input); } return $res; }
/** * Display all values available depending on field selected * * @static * @param $options * @param int $value */ static function dropdownValues($options, $value = 0) { $itemtype = $options['itemtype']; $typocrit_id = $options['typocrit_id']; $field = $options['field']; $action = $options['action_type']; $item = new $itemtype(); $test = explode(";", $field); $itemField = $test[0]; $itemTable = $test[1]; $itemDataType = $test[2]; $typoCritDef = new PluginTypologyTypologyCriteriaDefinition(); $typoCritDef->fields['plugin_typology_typologycriterias_id'] = $typocrit_id; $typoCritDef->fields['field'] = $field; $typoCrit = new PluginTypologyTypologyCriteria(); $typoCrit->getFromDB($typocrit_id); if ($action == 'contains' || $action == 'notcontains' || $action == 'regex_match' || $action == 'regex_not_match') { Html::autocompletionTextField($typoCritDef, "value"); } else { switch ($itemDataType) { case "bool": Dropdown::showYesNo('value'); break; case "number": Html::autocompletionTextField($typoCritDef, "value"); if ($itemField == 'size') { echo "\""; } break; case "string": Html::autocompletionTextField($typoCritDef, "value"); break; case "text": Html::autocompletionTextField($typoCritDef, "value"); if ($itemtype == 'DeviceHardDrive') { echo " " . __('Mio'); } else { if ($itemField == 'frequence') { echo " " . __('MHz'); } else { if ($itemtype == 'DeviceMemory' && $itemField == 'specif_default') { echo " " . __('Mio'); } else { if ($itemtype == 'DeviceProcessor' && $itemField == 'specif_default') { echo " " . __('MHz'); } } } } break; // case "ip" : // Html::autocompletionTextField($typoCritDef, "value"); // break; // case "ip" : // Html::autocompletionTextField($typoCritDef, "value"); // break; default: switch ($itemTable) { case "glpi_users": User::dropdown(array('right' => 'all', 'name' => 'value')); break; case "glpi_softwareversions": Software::dropdownSoftwareToInstall("value", $typoCrit->fields['entities_id']); break; default: $itemclass = getItemTypeForTable($itemTable); Dropdown::show($itemclass, array('name' => 'value', 'entity' => $typoCrit->fields['entities_id'])); break; } break; } } echo "</span></td>"; }