<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");
include($_SERVER['DOCUMENT_ROOT'] .'/script/HeaderInc.php');
if('XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH'] && true === isset($_SESSION['SessionAuth']['id']) && 0 < $_SESSION['SessionAuth']['id']) {
  $ObjIpMod = new IpMod($MS_SP);
  $ArrB = explode(".", $_POST['ip_name_b']);
  if(true === isset($_POST['ip_name_e']) && '' != $_POST['ip_name_e']){
    $ArrE = explode(".", $_POST['ip_name_e']);
  }
  else{
    $ArrE = $ArrB;
  }
  if(true === is_array($ArrE) && 4 == count($ArrE) && true === is_array($ArrE) && 4 == count($ArrE)){
    $VarB0 = $ArrB[0];
    $VarE0 = $ArrE[0];
    while ($VarB0 <= $VarE0) {
      $Arr[0] = $VarB0;
      $VarE1 = 254;
      if($VarB0 == $VarE0){
        $VarE1 = $ArrE[1];
      }
      $VarB1 = 0;
      if($ArrB[0] == $VarB0){
        $VarB1 = $ArrB[1];
      }
      while ($VarB1 <= $VarE1) {
        $Arr[1] = $VarB1;
        $VarE2 = 254;
        if($VarB1 == $VarE1){
          $VarE2 = $ArrE[2];
        }
        $VarB2 = 0;
        if($ArrB[1] == $VarB1){
          $VarB2 = $ArrB[2];
        }
        while ($VarB2 <= $VarE2) {
          //echo $ArrB[2]." = ". $VarB2 ."<=". $VarE2 ."<br />";
          $Arr[2] = $VarB2;
          $VarE3 = 254;
          if($VarB2 == $VarE2){
            $VarE3 = $ArrE[3];
          }
          $VarB3 = 1;
          if($ArrB[2] == $VarB2){
            $VarB3 = $ArrB[3];
          }
          while ($VarB3 <= $VarE3) {
            $Arr[3] = $VarB3;
            $VarIpName = implode('.', $Arr);
            $values['ip_name'] = $VarIpName;
            $VarIpId = $ObjIpMod->Add($values);
            $VarB3++;
          }
          $VarB2++;
        }
        $VarB1++;
      }
      $VarB0++;
    }    
    if (true === is_numeric($VarIpId)){
      $ArrReturn = array('message' => $MS_SP->Sp_LangMessage['message']['MessRecordAddSuccess']);
    }
    else{
      $ArrReturn = $VarIpId;
    }
  }
  else{
    $ArrReturn = array('error' => $MS_SP->Sp_LangMessage['error']['ErrSettingWrong']);
  }
}
else{
  $ArrReturn = array('error' => $MS_SP->Sp_LangMessage['error']['ErrFuncAccessDenied']);
}
echo json_encode($ArrReturn);
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>