Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/InfotelGLPI/typology
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmr committed Dec 22, 2016
2 parents bd0b32b + a323f48 commit e27716f
Show file tree
Hide file tree
Showing 20 changed files with 510 additions and 521 deletions.
10 changes: 10 additions & 0 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Dear GLPi user.

For bug reports, you can open an issue here, provide us :
- The version of the plugin.
- The version of your GLPI.
- The steps to reproduce your issue.

Delete this text to submit your issue.

The Plugin team.
2 changes: 1 addition & 1 deletion hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function plugin_typology_MassiveActions($type) {
if (in_array($type, PluginTypologyTypology::getTypes(true))) {
return array(
'PluginTypologyTypology_Item'.MassiveAction::CLASS_ACTION_SEPARATOR.'add_item' => __('Assign a typology to this material','typology'),
'PluginTypologyTypology_Item'.MassiveAction::CLASS_ACTION_SEPARATOR.'delete_item' => __('Delete the typology of this material'),
'PluginTypologyTypology_Item'.MassiveAction::CLASS_ACTION_SEPARATOR.'delete_item' => __('Delete the typology of this material','typology'),
'PluginTypologyTypology_Item'.MassiveAction::CLASS_ACTION_SEPARATOR.'update_allitem' => __('Recalculate typology for the elements','typology'));
}
break;
Expand Down
80 changes: 43 additions & 37 deletions inc/typology.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ static function cronUpdateTypology($task=NULL) {
$message=array($entity=>'');
}
$task_infos[$type][$entity][] = $data;
if (!isset($tasks_infos[$type][$entity])) {
if (!isset($task_messages[$type][$entity])) {
$task_messages[$type][$entity] = __('Typology of the linked elements is updated.','typology')."<br />";
}
$task_messages[$type][$entity] .= $message[$entity];
Expand Down Expand Up @@ -423,16 +423,19 @@ static function cronNotValidated($task=NULL) {
// Get items entity
$item = getItemForItemtype($data['itemtype']);
$item->getFromDB($data['items_id']);
$entity = $item->fields['entities_id'];

$message = $data["name"].": ".
$data["error"]."<br>\n";
$task_infos[$type][$entity][] = $data;

if (!isset($tasks_infos[$type][$entity])) {
$task_messages[$type][$entity] = __('Elements not match with the typology','typology')."<br />";
if (!$item->fields['is_deleted']) {
$entity = $item->fields['entities_id'];

$message = $data["name"] . ": " .
$data["error"] . "<br>\n";
$task_infos[$type][$entity][] = $data;

if (!isset($tasks_infos[$type][$entity])) {
$task_messages[$type][$entity] = __('Elements not match with the typology', 'typology') . "<br />";
}
$task_messages[$type][$entity] .= $message;
}
$task_messages[$type][$entity] .= $message;
}
}

Expand Down Expand Up @@ -586,45 +589,48 @@ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBT

case 'duplicate':
$input = $ma->getInput();
foreach ($ids as $key) {
if ($item->getType() == 'PluginTypologyTypology') {
foreach ($ids as $key) {

$this->getFromDB($key);
$item->getFromDB($key);

$restrict = "`plugin_typology_typologies_id` = '".$key."'";
$crits = getAllDatasFromTable("glpi_plugin_typology_typologycriterias", $restrict);
$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);
unset($item->fields["id"]);
$item->fields["name"] = addslashes($item->fields["name"] . " Copy");
$item->fields["comment"] = addslashes($item->fields["comment"]);
//TODO duplicate notes
// $item->fields["notepad"] = addslashes($item->fields["notepad"]);
$newIDtypo = $item->add($item->fields);

if (!empty($crits)) {
foreach ($crits as $crit) {
if (!empty($crits)) {
foreach ($crits as $crit) {

$criteria->getFromDB($crit["id"]);
$criteria->getFromDB($crit["id"]);

$condition = "`plugin_typology_typologycriterias_id` = '".$crit["id"]."'";
$defs = getAllDatasFromTable("glpi_plugin_typology_typologycriteriadefinitions", $condition);
$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);
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) {
if (!empty($defs)) {
foreach ($defs as $def) {

$definition->getFromDB($def["id"]);
$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);
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);

}
}
}
}
Expand Down
46 changes: 31 additions & 15 deletions inc/typologycriteriadefinition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,23 @@ function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
if (!$withtemplate) {
switch ($item->getType()) {
case 'PluginTypologyTypologyCriteria' :
return self::getTypeName();
$nb = self::countForItem($item->fields['id']);
return array(self::createTabEntry(self::getTypeName(), $nb));
}
}
return '';
}

/**
* Count of definitions
* @param type $item
* @return type
*/
static function countForItem($id){
$typoCritDef = new PluginTypologyTypologyCriteriaDefinition();
$datas = $typoCritDef->find("`plugin_typology_typologycriterias_id` = ".$id);
return count($datas);
}

/**
* display tab's content for each typologycriteria
Expand Down Expand Up @@ -398,7 +410,7 @@ static function getUnallowedFields($itemclass) {
'groups_id_tech',
'comment',
'date_mod',
'os_license_number',
// 'os_license_number',
'os_licenseid',
'autoupdatesystems_id',
// 'locations_id',
Expand Down Expand Up @@ -1032,9 +1044,11 @@ static function getRealValue($pcID, $valueFromDef){
switch ($itemtype){
case "Computer":
$queryReal .= " FROM `glpi_computers`";
$queryReal .= " INNER JOIN `".$searchOption['table']."`";
$fk = getForeignKeyFieldForTable($searchOption['table']);
$queryReal .= " ON (`glpi_computers`.`".$fk."`= `".$searchOption['table']."`.`id`)";
if($searchOption['table'] != 'glpi_computers') {
$queryReal .= " INNER JOIN `" . $searchOption['table'] . "`";
$fk = getForeignKeyFieldForTable($searchOption['table']);
$queryReal .= " ON (`glpi_computers`.`" . $fk . "`= `" . $searchOption['table'] . "`.`id`)";
}
$queryReal .= " WHERE `glpi_computers`.`id` = '$pcID'";
break;
case "Monitor":
Expand Down Expand Up @@ -1376,10 +1390,12 @@ static function getComputeResultByDef($valueFromDef,$pcID){
switch ($itemtype){
case "Computer":
$queryConsole .= " FROM `glpi_computers`";
$queryConsole .= " INNER JOIN `".$searchOption['table']."`";
$fk = getForeignKeyFieldForTable($searchOption['table']);
$queryConsole .= " ON (`glpi_computers`.`".$fk.
"`= `".$searchOption['table']."`.`id`)";
if($searchOption['table'] != 'glpi_computers') {
$queryConsole .= " INNER JOIN `" . $searchOption['table'] . "`";
$fk = getForeignKeyFieldForTable($searchOption['table']);
$queryConsole .= " ON (`glpi_computers`.`" . $fk .
"`= `" . $searchOption['table'] . "`.`id`)";
}
$queryConsole .= " WHERE `glpi_computers`.`id` = '$pcID'";
break;
case "Monitor":
Expand Down Expand Up @@ -1531,7 +1547,7 @@ static function getComputeResultByDef($valueFromDef,$pcID){
case "string" :
if ($def['action_type'] == 'contains') {
$queryConsole .= " AND `".$searchOption['table']."`.`".$searchOption['field']."`".
" LIKE '%".$def["value"]."%'";
" LIKE '%".Toolbox::addslashes_deep($def["value"])."%'";
} else if ($def['action_type'] == 'notcontains') {
$queryConsole .= " AND `".$searchOption['table']."`.`".$searchOption['field']."`".
" LIKE '%".$def["value"]."%'";
Expand All @@ -1549,10 +1565,10 @@ static function getComputeResultByDef($valueFromDef,$pcID){
case "glpi_users":
if ($def['action_type'] == 'contains') {
$queryConsole .= " AND `".$searchOption['table']."`.`".$searchOption['field']."`".
" LIKE '%".$def["value"]."%'";
" LIKE '%".Toolbox::addslashes_deep($def["value"])."%'";
} else if ($def['action_type'] == 'notcontains') {
$queryConsole .= " AND `".$searchOption['table']."`.`".$searchOption['field']."`".
" LIKE '%".$def["value"]."%'";
" LIKE '%".Toolbox::addslashes_deep($def["value"])."%'";
} else if ($def['action_type'] == 'equals') {
$queryConsole .= " AND `".$searchOption['table']."`.`".$searchOption['field']."`".
" = '".getUserName($def["value"])."'";
Expand All @@ -1573,14 +1589,14 @@ static function getComputeResultByDef($valueFromDef,$pcID){
default :
if ($def['action_type'] == 'contains' || $def['action_type'] == 'notcontains') {
$queryConsole .= " AND `".$searchOption['table']."`.`".$searchOption['field']."`".
" LIKE '%".$def["value"]."%'";
" LIKE '%".Toolbox::addslashes_deep($def["value"])."%'";
} else if ($def['action_type'] == 'equals') {
$queryConsole .= " AND `".$searchOption['table']."`.`".$searchOption['field']."`";
if ($item instanceof CommonDevice) {
$item->getFromDB($def["value"]);
$queryConsole.= " = '".$item->getName()."'";
$queryConsole.= " = '".Toolbox::addslashes_deep($item->getName())."'";
} else {
$queryConsole.=" = '".Dropdown::getDropdownName($searchOption['table'],$def["value"])."'";
$queryConsole.=" = '".Toolbox::addslashes_deep(Dropdown::getDropdownName($searchOption['table'],$def["value"]))."'";
}
} else if ($def['action_type'] == 'notequals') {
$queryConsole .= " AND `".$searchOption['table']."`.`".$searchOption['field']."`";
Expand Down
Binary file modified locales/en_GB.mo
Binary file not shown.
Loading

0 comments on commit e27716f

Please sign in to comment.