コード例 #1
0
(at your option) any later version.

GLPI 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 GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
if (strpos($_SERVER['PHP_SELF'], "dropdownValuesBlacklist.php")) {
    include '../inc/includes.php';
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
Session::checkRight("config", UPDATE);
if (isset($_POST['itemtype']) && isset($_POST['id_field'])) {
    $blacklist = new Fieldblacklist();
    if (isset($_POST['id']) && $_POST['id'] > 0) {
        $blacklist->getFromDB($_POST['id']);
    } else {
        $blacklist->getEmpty();
    }
    $blacklist->fields['field'] = $_POST['id_field'];
    $blacklist->fields['itemtype'] = $_POST['itemtype'];
    $blacklist->selectValues($_POST['id_field']);
}
コード例 #2
0
GLPI is free software; you can redistribute it and/or modify
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.

GLPI 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 GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
if (strpos($_SERVER['PHP_SELF'], "dropdownFieldsBlacklist.php")) {
    include '../inc/includes.php';
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
Session::checkRight("config", UPDATE);
$field = new Fieldblacklist();
if ($_POST['id'] > 0) {
    $field->getFromDB($_POST['id']);
} else {
    $field->getEmpty();
    $field->fields['itemtype'] = $_POST['itemtype'];
}
$field->selectCriterias($field);
コード例 #3
0
 /**
  * Check field unicity before insert or update
  *
  * @param add true for insert, false for update
  * @param $options array
  *
  * @return true if item can be written in DB, false if not
  **/
 function checkUnicity($add = false, $options = array())
 {
     global $LANG, $DB, $CFG_GLPI;
     $p['unicity_error_message'] = true;
     $p['add_event_on_duplicate'] = true;
     $p['disable_unicity_check'] = false;
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $value) {
             $p[$key] = $value;
         }
     }
     $result = true;
     //Do not check unicity when creating infocoms or if checking is expliclty disabled
     if ($p['disable_unicity_check']) {
         return $result;
     }
     //Get all checks for this itemtype and this entity
     if (in_array(get_class($this), $CFG_GLPI["unicity_types"])) {
         // Get input entities if set / else get object one
         if (isset($this->input['entities_id'])) {
             $entities_id = $this->input['entities_id'];
         } else {
             $entities_id = $this->fields['entities_id'];
         }
         $all_fields = FieldUnicity::getUnicityFieldsConfig(get_class($this), $entities_id);
         foreach ($all_fields as $key => $fields) {
             //If there's fields to check
             if (!empty($fields) && !empty($fields['fields'])) {
                 $where = "";
                 $continue = true;
                 foreach (explode(',', $fields['fields']) as $field) {
                     if (isset($this->input[$field]) && (getTableNameForForeignKeyField($field) == '' && $this->input[$field] != '' || getTableNameForForeignKeyField($field) != '' && $this->input[$field] > 0) && !Fieldblacklist::isFieldBlacklisted(get_class($this), $entities_id, $field, $this->input[$field])) {
                         $where .= " AND `" . $this->getTable() . "`.`{$field}` = '" . $this->input[$field] . "'";
                     } else {
                         $continue = false;
                     }
                 }
                 if ($continue && $where != '') {
                     $entities = $fields['entities_id'];
                     if ($fields['is_recursive']) {
                         $entities = getSonsOf('glpi_entities', $fields['entities_id']);
                     }
                     $where_global = getEntitiesRestrictRequest(" AND", $this->getTable(), '', $entities);
                     //If update, exclude ID of the current object
                     if (!$add) {
                         $where .= " AND `" . $this->getTable() . "`.`id` NOT IN (" . $this->input['id'] . ") ";
                     }
                     if (countElementsInTable($this->table, "1 {$where} {$where_global}") > 0) {
                         if ($p['unicity_error_message'] || $p['add_event_on_duplicate']) {
                             $message = array();
                             foreach (explode(',', $fields['fields']) as $field) {
                                 $table = getTableNameForForeignKeyField($field);
                                 if ($table != '') {
                                     $searchOption = $this->getSearchOptionByField('field', 'name', $table);
                                 } else {
                                     $searchOption = $this->getSearchOptionByField('field', $field);
                                 }
                                 $message[] = $searchOption['name'] . '=' . $this->input[$field];
                             }
                             $doubles = getAllDatasFromTable($this->table, "1 {$where} {$where_global}");
                             $message_text = $this->getUncityErrorMessage($message, $fields, $doubles);
                             if ($p['unicity_error_message']) {
                                 if (!$fields['action_refuse']) {
                                     $show_other_messages = $fields['action_refuse'] ? true : false;
                                 } else {
                                     $show_other_messages = true;
                                 }
                                 addMessageAfterRedirect($message_text, true, $show_other_messages, $show_other_messages);
                             }
                             if ($p['add_event_on_duplicate']) {
                                 Event::log(!$add ? $this->fields['id'] : 0, get_class($this), 4, 'inventory', $_SESSION["glpiname"] . " " . $LANG['log'][123] . ' : ' . $message_text);
                             }
                         }
                         if ($fields['action_refuse']) {
                             $result = false;
                         }
                         if ($fields['action_notify']) {
                             $params = array('message' => html_clean($message_text), 'action_type' => $add, 'action_user' => getUserName(getLoginUserID()), 'entities_id' => $entities_id, 'itemtype' => get_class($this), 'date' => $_SESSION['glpi_currenttime'], 'refuse' => $fields['action_refuse']);
                             NotificationEvent::raiseEvent('refuse', new FieldUnicity(), $params);
                         }
                     }
                 }
             }
         }
     }
     return $result;
 }