/** * Handle the AJAX request for setting value for a single variable * * @return void */ public function setValueAction() { $value = $_REQUEST['varValue']; $matches = array(); if (isset($this->variable_doc_links[$_REQUEST['varName']][3]) && $this->variable_doc_links[$_REQUEST['varName']][3] == 'byte' && preg_match('/^\\s*(\\d+(\\.\\d+)?)\\s*(mb|kb|mib|kib|gb|gib)\\s*$/i', $value, $matches)) { $exp = array('kb' => 1, 'kib' => 1, 'mb' => 2, 'mib' => 2, 'gb' => 3, 'gib' => 3); $value = floatval($matches[1]) * Util::pow(1024, $exp[mb_strtolower($matches[3])]); } else { $value = Util::sqlAddSlashes($value); } if (!is_numeric($value)) { $value = "'" . $value . "'"; } if (!preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName']) && $this->dbi->query('SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value)) { // Some values are rounded down etc. $varValue = $this->dbi->fetchSingleRow('SHOW GLOBAL VARIABLES WHERE Variable_name="' . Util::sqlAddSlashes($_REQUEST['varName']) . '";', 'NUM'); $this->response->addJSON('variable', htmlspecialchars($this->_formatVariable($_REQUEST['varName'], $varValue[1]))); } else { $this->response->setRequestStatus(false); $this->response->addJSON('error', __('Setting variable failed')); } }
/** * Returns a point that is guaranteed to be on the surface of the ring. * (for simple closed rings) * * @param array $ring array of points forming the ring * * @return array|void a point on the surface of the ring * @access public * @static */ public static function getPointOnSurface($ring) { // Find two consecutive distinct points. for ($i = 0, $nb = count($ring) - 1; $i < $nb; $i++) { if ($ring[$i]['y'] != $ring[$i + 1]['y']) { $x0 = $ring[$i]['x']; $x1 = $ring[$i + 1]['x']; $y0 = $ring[$i]['y']; $y1 = $ring[$i + 1]['y']; break; } } if (!isset($x0)) { return false; } // Find the mid point $x2 = ($x0 + $x1) / 2; $y2 = ($y0 + $y1) / 2; // Always keep $epsilon < 1 to go with the reduction logic down here $epsilon = 0.1; $denominator = sqrt(Util::pow($y1 - $y0, 2) + Util::pow($x0 - $x1, 2)); $pointA = array(); $pointB = array(); while (true) { // Get the points on either sides of the line // with a distance of epsilon to the mid point $pointA['x'] = $x2 + $epsilon * ($y1 - $y0) / $denominator; $pointA['y'] = $y2 + ($pointA['x'] - $x2) * ($x0 - $x1) / ($y1 - $y0); $pointB['x'] = $x2 + $epsilon * ($y1 - $y0) / (0 - $denominator); $pointB['y'] = $y2 + ($pointB['x'] - $x2) * ($x0 - $x1) / ($y1 - $y0); // One of the points should be inside the polygon, // unless epsilon chosen is too large if (GISPolygon::isPointInsidePolygon($pointA, $ring)) { return $pointA; } if (GISPolygon::isPointInsidePolygon($pointB, $ring)) { return $pointB; } //If both are outside the polygon reduce the epsilon and //recalculate the points(reduce exponentially for faster convergence) $epsilon = Util::pow($epsilon, 2); if ($epsilon == 0) { return false; } } }
/** * Returns the column number based on the Excel name. * So "A" = 1, "Z" = 26, "AA" = 27, etc. * * Basically this is a base26 (A-Z) to base10 (0-9) conversion. * It iterates through all characters in the column name and * calculates the corresponding value, based on character value * (A = 1, ..., Z = 26) and position in the string. * * @param string $name column name(i.e. "A", or "BC", etc.) * * @return int The column number * @access public */ function PMA_getColumnNumberFromName($name) { if (empty($name)) { return 0; } $name = mb_strtoupper($name); $num_chars = mb_strlen($name); $column_number = 0; for ($i = 0; $i < $num_chars; ++$i) { // read string from back to front $char_pos = $num_chars - 1 - $i; // convert capital character to ASCII value // and subtract 64 to get corresponding decimal value // ASCII value of "A" is 65, "B" is 66, etc. // Decimal equivalent of "A" is 1, "B" is 2, etc. $number = (int) (mb_ord($name[$char_pos]) - 64); // base26 to base10 conversion : multiply each number // with corresponding value of the position, in this case // $i=0 : 1; $i=1 : 26; $i=2 : 676; ... $column_number += $number * PMA\libraries\Util::pow(26, $i); } return $column_number; }