You are here

function pImage::replaceImageMapTitle in Visitors 7

Same name and namespace in other branches
  1. 7.2 pChart/class/pImage.class.php \pImage::replaceImageMapTitle()

File

pChart/class/pImage.class.php, line 330

Class

pImage

Code

function replaceImageMapTitle($OldTitle, $NewTitle) {
  if ($this->ImageMapStorageMode == NULL) {
    return -1;
  }
  if (is_array($NewTitle)) {
    $NewTitle = $this
      ->removeVOIDFromArray($OldTitle, $NewTitle);
  }
  if ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION) {
    if (!isset($_SESSION)) {
      return -1;
    }
    if (is_array($NewTitle)) {
      $ID = 0;
      foreach ($_SESSION[$this->ImageMapIndex] as $Key => $Settings) {
        if ($Settings[3] == $OldTitle && isset($NewTitle[$ID])) {
          $_SESSION[$this->ImageMapIndex][$Key][3] = $NewTitle[$ID];
          $ID++;
        }
      }
    }
    else {
      foreach ($_SESSION[$this->ImageMapIndex] as $Key => $Settings) {
        if ($Settings[3] == $OldTitle) {
          $_SESSION[$this->ImageMapIndex][$Key][3] = $NewTitle;
        }
      }
    }
  }
  elseif ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE) {
    $TempArray = "";
    $Handle = @fopen($this->ImageMapStorageFolder . "/" . $this->ImageMapFileName . ".map", "r");
    if ($Handle) {
      while (($Buffer = fgets($Handle, 4096)) !== false) {
        $Fields = preg_split("/" . IMAGE_MAP_DELIMITER . "/", str_replace(array(
          chr(10),
          chr(13),
        ), "", $Buffer));
        $TempArray[] = array(
          $Fields[0],
          $Fields[1],
          $Fields[2],
          $Fields[3],
          $Fields[4],
        );
      }
      fclose($Handle);
      if (is_array($NewTitle)) {
        $ID = 0;
        foreach ($TempArray as $Key => $Settings) {
          if ($Settings[3] == $OldTitle && isset($NewTitle[$ID])) {
            $TempArray[$Key][3] = $NewTitle[$ID];
            $ID++;
          }
        }
      }
      else {
        foreach ($TempArray as $Key => $Settings) {
          if ($Settings[3] == $OldTitle) {
            $TempArray[$Key][3] = $NewTitle;
          }
        }
      }
      $Handle = fopen($this->ImageMapStorageFolder . "/" . $this->ImageMapFileName . ".map", 'w');
      foreach ($TempArray as $Key => $Settings) {
        fwrite($Handle, $Settings[0] . IMAGE_MAP_DELIMITER . $Settings[1] . IMAGE_MAP_DELIMITER . $Settings[2] . IMAGE_MAP_DELIMITER . $Settings[3] . IMAGE_MAP_DELIMITER . $Settings[4] . "\r\n");
      }
      fclose($Handle);
    }
  }
}