You are here

function pImage::replaceImageMapValues in Visitors 7

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

File

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

Class

pImage

Code

function replaceImageMapValues($Title, $Values) {
  if ($this->ImageMapStorageMode == NULL) {
    return -1;
  }
  $Values = $this
    ->removeVOIDFromArray($Title, $Values);
  $ID = 0;
  if ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION) {
    if (!isset($_SESSION)) {
      return -1;
    }
    foreach ($_SESSION[$this->ImageMapIndex] as $Key => $Settings) {
      if ($Settings[3] == $Title) {
        if (isset($Values[$ID])) {
          $_SESSION[$this->ImageMapIndex][$Key][4] = $Values[$ID];
        }
        $ID++;
      }
    }
  }
  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);
      foreach ($TempArray as $Key => $Settings) {
        if ($Settings[3] == $Title) {
          if (isset($Values[$ID])) {
            $TempArray[$Key][4] = $Values[$ID];
          }
          $ID++;
        }
      }
      $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);
    }
  }
}