0) { $resstring = sqlite_fetch_single($res); if (strlen($resstring) > 0) { $string = $resstring; } } sqlite_close($dbh); return $string; } /** * ENABLE/DISABLE GROUPS IN MAP */ function setGroups($map, $groups, $scale, $setLabelItem, $query=false) { // APPLY ON LAYERS DEFINED IN MAP FILE //$grouplist = $_SESSION["grouplist"]; //$grouplist = array_unique($_SESSION["grouplist"]); // does NOT work with PHP4 $grouplist = array_unique_key($_SESSION["grouplist"]); foreach ($grouplist as $grp){ $glayerList = $grp->getLayers(); if (in_array($grp->groupName, $groups, TRUE)) { $activeGroups[] = $grp; foreach ($glayerList as $glayer) { $layer = $map->getLayer($glayer->getLayerIdx()); $layerType = $layer->type; // if defined use only layers visible at current scale (useful for queries) if ($scale > 0) { if (checkScale($map, $layer, $scale) == 1) { $querylayers[] = $layer; $layer->set("status", MS_ON); // set labelitem if defined if ($setLabelItem) { if ($glayer->getLabelItem()) { $layer->set("labelitem", $glayer->getLabelItem()); } } // Layer Transparency $layer->set("transparency", $glayer->getTransparency()); } else { $layer->set("status", MS_OFF); } } else { $layer->set("status", MS_ON); // set labelitem if defined if ($setLabelItem) { if ($glayer->getLabelItem()) { $layer->set("labelitem", $glayer->getLabelItem()); } } $layer->set("transparency", $glayer->getTransparency()); } } } else { foreach ($glayerList as $glayer) { $layer = $map->getLayer($glayer->getLayerIdx()); $layer->set("status", MS_OFF); } } } } /** * Removes duplicate keys from an array */ function array_unique_key($array) { $result = array(); foreach (array_unique(array_keys($array)) as $tvalue) { $result[$tvalue] = $array[$tvalue]; } return $result; } /** * CHECK IF LAYER IS IN VALID SCALE DIMENSION (USED FOR QUERIES) * Based on a script by CHIP HANKLEY found on MapServer Wiki */ function checkScale($map, $qLayer, $scale) { if ($qLayer->maxscale == -1 && $qLayer->minscale == -1) { return 1; } elseif ($scale > $qLayer->maxscale AND $qLayer->maxscale != -1) { return 0; } elseif ($scale < $qLayer->minscale AND $qLayer->minscale != -1) { return 0; } else { return 1; } } /** * Get the group to which a glayer belongs */ function returnGroupGlayer($layname) { $grouplist = $_SESSION["grouplist"]; foreach ($grouplist as $grp) { $glayerList = $grp->getLayers(); foreach ($glayerList as $gl) { $glayername = $gl->getLayerName(); if ($layname == $glayername) { return array($grp, $gl); } } } } /** * Print out debug info (including arrays) */ function printDebug($dbgstr0) { ob_start(); print_r($dbgstr0); $dbgstr = ob_get_contents(); ob_end_clean(); $outMapFN = str_replace('\\', '/', dirname(ini_get("error_log"))) . "/debug.txt"; $fpOut = fopen($outMapFN, "a+"); fwrite($fpOut, "\n$dbgstr"); fclose($fpOut); } /** * Workaround for Mapscript bug and temp image file names */ function mapSaveWebImage($map, $mapImg, $refImg=false) { $now = (string)microtime(); $now = explode(' ', $now); $microsec = $now[1].str_replace('.', '', $now[0]); unset($now); $imgFormat = $refImg ? substr(strtolower(trim($map->reference->image)), -3) : $map->outputformat->extension; $tmpImgBaseName = session_id() . $microsec . "." . $imgFormat; $tmpFileNameAbs = str_replace('\\', '/', $map->web->imagepath) . $tmpImgBaseName ; $imgURL = $map->web->imageurl . $tmpImgBaseName ; $mapImg->saveImage($tmpFileNameAbs, $map); return $imgURL; } /** * Parses a JSON (www.json.org) string * using if available the PHP-JSON extension * or else the json.php parser by Michal Migurski * default action is decoding */ function parseJSON($input, $action="decode") { if (!extension_loaded('json')) { @dl("php_json." . PHP_SHLIB_SUFFIX); } if (extension_loaded('json')) { if ($action == "decode") { return json_decode($input); } else { return json_encode($input); } } else { require_once($_SESSION['PM_INCPHP'] . "/extlib/json.php"); $json = new Services_JSON(); if ($action == "decode") { return $json->decode($input); } else { return $json->encode($input); } } } /** * Log errors for PEAR DB connections/queries */ function db_logErrors($db) { $err .= "===== P.MAPPER: DB ERROR =====\n"; $err .= 'Standard Message: ' . $db->getMessage() . "\n"; //$err .= 'Standard Code: ' . $db->getCode() . "\n"; //$err .= 'DBMS/User Message: ' . $db->getUserInfo() . "\n"; $err .= 'DBMS/Debug Message: ' . $db->getDebugInfo() . "\n"; error_log($err); } /** * Scan a dir for files with a certain extension */ function scandirByExt($dir, $extension) { $dh = opendir($dir); while (false !== ($filename = readdir($dh))) { if (substr(strrchr($filename, "."), 1) == $extension) { $files[] = $filename; } } return $files; } ?>