예제 #1
0
 /**
  * @param $input
  **/
 function prepareInput($input)
 {
     // If $input['name'] does not exists, then, don't check anything !
     if (isset($input['name'])) {
         // WARNING: we must in every case, because, sometimes, fields are partially feels
         // If previous value differs from current one, then check it !
         $this->setAddressFromString($input['name']);
         if (!$this->is_valid()) {
             if (isset($input['is_dynamic']) && $input['is_dynamic']) {
                 // We allow invalid IPs that are dynamics !
                 $input['version'] = 0;
                 $input['binary_0'] = 0;
                 $input['binary_1'] = 0;
                 $input['binary_2'] = 0;
                 $input['binary_3'] = 0;
                 return $input;
             }
             //TRANS: %s is the invalid address
             $msg = sprintf(__('%1$s: %2$s'), __('Invalid IP address'), $input['name']);
             Session::addMessageAfterRedirect($msg, false, ERROR);
             return false;
         }
     }
     if (isset($input['itemtype']) && isset($input['items_id'])) {
         $input['mainitemtype'] = 'NULL';
         $input['mainitems_id'] = 0;
         if ($input['itemtype'] == 'NetworkName') {
             $name = new NetworkName();
             if ($name->getFromDB($input['items_id'])) {
                 if ($port = getItemForItemtype($name->getField('itemtype'))) {
                     if ($port->getFromDB($name->getField('items_id'))) {
                         if (isset($port->fields['itemtype']) && isset($port->fields['items_id'])) {
                             $input['mainitemtype'] = $port->fields['itemtype'];
                             $input['mainitems_id'] = $port->fields['items_id'];
                         }
                     }
                 }
             }
         }
     }
     return array_merge($input, $this->setArrayFromAddress($input, "version", "name", "binary"));
 }