function getDatasForTemplate($event, $options = array())
 {
     global $CFG_GLPI;
     if ($event == 'AlertNotValidatedTypology') {
         $this->datas['##typology.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']);
         $this->datas['##lang.typology.entity##'] = __('Entity');
         $this->datas['##typology.action##'] = __('Elements not match with the typology', 'typology');
         $this->datas['##lang.typology.name##'] = PluginTypologyTypology::getTypeName(1);
         $this->datas['##lang.typology.itemtype##'] = __('Type');
         $this->datas['##lang.typology.items_id##'] = __('Name');
         $this->datas['##lang.typology.error##'] = __('Error');
         $this->datas['##lang.typology.url##'] = __('Link to the typology', 'typology');
         $this->datas['##lang.typology.itemurl##'] = __('Link to the element', 'typology');
         $this->datas['##lang.typology.itemuser##'] = __('User');
         $this->datas['##lang.typology.itemlocation##'] = __('Location');
         foreach ($options['items'] as $id => $item) {
             $tmp = array();
             $tmp['##typology.name##'] = $item['name'];
             $itemtype = new $item['itemtype']();
             $itemtype->getFromDB($item["items_id"]);
             $tmp['##typology.itemtype##'] = $itemtype->getTypeName();
             $tmp['##typology.items_id##'] = $itemtype->getName();
             $tmp['##typology.error##'] = PluginTypologyTypology_Item::displayErrors($item['error'], false);
             $tmp['##typology.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=plugin_typology_" . $item['plugin_typology_typologies_id']);
             $tmp['##typology.itemurl##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=" . Toolbox::strtolower($item['itemtype']) . "_" . $item["items_id"]);
             $tmp['##typology.itemuser##'] = getUserName($itemtype->fields["users_id"]);
             $tmp['##typology.itemlocation##'] = Dropdown::getDropdownName("glpi_locations", $itemtype->fields['locations_id']);
             $this->datas['typologyitems'][] = $tmp;
         }
     }
 }
Beispiel #2
0
 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';
PluginTypologyProfile::checkRight('typology', 'w');
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
$typo = new PluginTypologyTypology();
$typo_item = new PluginTypologyTypology_Item();
if (isset($_POST["add"])) {
    $typo->check(-1, 'w');
    $newID = $typo->add($_POST);
    Html::back();
} else {
    if (isset($_POST["delete"])) {
        $typo->check($_POST["id"], 'w');
        $typo->delete($_POST);
        $typo->redirectToList();
    } else {
        if (isset($_POST["update"])) {
            $typo->check($_POST["id"], 'w');
            $typo->update($_POST);
            Html::back();
        } else {
Beispiel #3
0
 $resultComputer = $DB->query($queryComputer);
 $computeOK = 0;
 $computeNOTOK = 0;
 while ($dataComputer = $DB->fetch_array($resultComputer)) {
     $link = Toolbox::getItemTypeFormURL("Computer");
     $computerName = "<a href='" . $link . "?id=" . $dataComputer["items_id"] . "' target='_blank'>" . Dropdown::getDropdownName("glpi_computers", $dataComputer["items_id"]) . "</a>";
     $computer = new Computer();
     $computer->getFromDB($dataComputer["items_id"]);
     $userName = getUserName($computer->fields["users_id"]);
     if ($dataComputer["is_validated"] > 0) {
         $critTypOK = __('Yes');
         $computeOK++;
     } else {
         $critTypOK = "<font color='red'>" . __('No') . " " . __('for the criteria', 'typology') . " ";
         $i = 0;
         $critTypOK .= PluginTypologyTypology_Item::displayErrors($dataComputer["error"]);
         $critTypOK .= "</font>";
         $computeNOTOK++;
     }
     $row_num++;
     $num = 1;
     echo Search::showNewLine($output_type);
     echo Search::showItem($output_type, '', $num, $row_num);
     echo Search::showItem($output_type, $computerName, $num, $row_num);
     echo Search::showItem($output_type, $userName, $num, $row_num);
     echo Search::showItem($output_type, $critTypOK, $num, $row_num);
     echo Search::showEndLine($output_type);
 }
 $row_num++;
 $num = 1;
 $message = "<b><font color='green'>" . __('Responding', 'typology') . " " . $computeOK . " / " . $dataService["COUNT"] . "</font>" . ", " . "<font color='red'>" . __('Not responding', 'typology') . " " . $computeNOTOK . " / " . $dataService["COUNT"] . "</font></b>";
 /**
  * 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);
     $typo_item = new PluginTypologyTypology_Item();
     switch ($input['action']) {
         case "delete_item":
             if ($input['itemtype'] == 'PluginTypologyTypology_Item') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val != 0) {
                         $typo_item->getFromDB($key);
                         if ($typo_item->delete(array('id' => $key))) {
                             $values = array('plugin_typology_typologies_id' => $input['plugin_typology_typologies_id'], 'items_id' => $typo_item->fields['items_id'], 'itemtype' => $typo_item->fields['itemtype']);
                             PluginTypologyTypology_Item::addLog($values, PluginTypologyTypology_Item::LOG_DELETE);
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             }
             break;
         case "update_allitem":
             if ($input['itemtype'] == 'PluginTypologyTypology_Item') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val != 0) {
                         $typo_item->getFromDB($key);
                         $result = PluginTypologyTypology_Item::checkValidated(array('items_id' => $typo_item->fields['items_id'], 'plugin_typology_typologies_id' => $typo_item->fields['plugin_typology_typologies_id'], 'id' => $typo_item->fields['id']));
                         if ($typo_item->update($result)) {
                             $values = array('plugin_typology_typologies_id' => $typo_item->fields['plugin_typology_typologies_id'], 'items_id' => $typo_item->fields['items_id'], 'itemtype' => $typo_item->fields['itemtype']);
                             PluginTypologyTypology_Item::addLog($values, PluginTypologyTypology_Item::LOG_UPDATE);
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
     }
     return $res;
 }
Beispiel #5
0
function plugin_typology_giveItem($type, $ID, $data, $num)
{
    $searchopt =& Search::getOptions($type);
    $table = $searchopt[$ID]["table"];
    $field = $searchopt[$ID]["field"];
    switch ($type) {
        case 'Computer':
            switch ($table . '.' . $field) {
                case "glpi_plugin_typology_typologies_items.is_validated":
                    if (empty($data["ITEM_{$num}"])) {
                        $out = '';
                    } else {
                        $validated = explode("\$\$", $data["ITEM_{$num}"]);
                        $out = Dropdown::getYesNo($validated[0]);
                    }
                    return $out;
                    break;
                case "glpi_plugin_typology_typologies_items.error":
                    //               if (empty($data["ITEM_$num"])) {
                    //                  $out = __('No error','typology');
                    //               } else {
                    $list = explode("\$\$", $data["ITEM_{$num}"]);
                    $out = PluginTypologyTypology_Item::displayErrors($list[0]);
                    //               }
                    return $out;
                    break;
            }
            break;
    }
    return "";
}
Beispiel #6
0
 /**
  * Cron action on tasks : UpdateTypology
  *
  * @param $task for log, if NULL display
  *
  **/
 static function cronUpdateTypology($task = NULL)
 {
     global $DB;
     $cron_status = 0;
     $message = array();
     $typo = new self();
     $query_items = $typo->queryUpdateTypology();
     $querys = array(Alert::END => $query_items);
     $task_infos = array();
     $task_messages = array();
     foreach ($querys as $type => $query) {
         $task_infos[$type] = array();
         foreach ($DB->request($query) as $data) {
             //update all linked item to a typology
             if (isset($data['id'])) {
                 $input = PluginTypologyTypology_Item::checkValidated($data);
             }
             if ($data['error'] != $input['error']) {
                 $typo_item = new PluginTypologyTypology_Item();
                 $typo_item->getFromDB($data['id']);
                 $values = array('id' => $data['id'], 'is_validated' => $input['is_validated'], 'error' => $input['error']);
                 $typo_item->update($input);
                 $typo->getFromDB($data['plugin_typology_typologies_id']);
                 $entity = $typo->fields['entities_id'];
                 if (!isset($message[$entity])) {
                     $message = array($entity => '');
                 }
                 $task_infos[$type][$entity][] = $data;
                 if (!isset($tasks_infos[$type][$entity])) {
                     $task_messages[$type][$entity] = __('Typology of the linked elements is updated.', 'typology') . "<br />";
                 }
                 $task_messages[$type][$entity] .= $message[$entity];
             }
         }
     }
     foreach ($querys as $type => $query) {
         foreach ($task_infos[$type] as $entity => $items) {
             Plugin::loadLang('typology');
             $message = $task_messages[$type][$entity];
             $cron_status = 1;
             if ($task) {
                 $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}\n");
                 $task->addVolume(count($items));
             } else {
                 Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}");
             }
         }
     }
     return $cron_status;
 }